1e5a49c1eSTony Lindgren /* 2e5a49c1eSTony Lindgren * This program is free software; you can redistribute it and/or modify 3e5a49c1eSTony Lindgren * it under the terms of the GNU General Public License as published by 4e5a49c1eSTony Lindgren * the Free Software Foundation; either version 2 of the License, or 5e5a49c1eSTony Lindgren * (at your option) any later version. 6e5a49c1eSTony Lindgren * 7e5a49c1eSTony Lindgren * This program is distributed in the hope that it will be useful, 8e5a49c1eSTony Lindgren * but WITHOUT ANY WARRANTY; without even the implied warranty of 9e5a49c1eSTony Lindgren * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10e5a49c1eSTony Lindgren * GNU General Public License for more details. 11e5a49c1eSTony Lindgren */ 12e5a49c1eSTony Lindgren 13e5a49c1eSTony Lindgren #include <linux/kernel.h> 14e5a49c1eSTony Lindgren #include <linux/module.h> 15e5a49c1eSTony Lindgren #include <linux/of.h> 16e5a49c1eSTony Lindgren #include <linux/of_device.h> 17e5a49c1eSTony Lindgren #include <linux/regmap.h> 18e5a49c1eSTony Lindgren #include <linux/mfd/syscon.h> 19e5a49c1eSTony Lindgren 20e5a49c1eSTony Lindgren #define AM33XX_CTRL_MAC_LO_REG(offset, id) ((offset) + 0x8 * (id)) 21e5a49c1eSTony Lindgren #define AM33XX_CTRL_MAC_HI_REG(offset, id) ((offset) + 0x8 * (id) + 0x4) 22e5a49c1eSTony Lindgren 23e5a49c1eSTony Lindgren int cpsw_am33xx_cm_get_macid(struct device *dev, u16 offset, int slave, 24e5a49c1eSTony Lindgren u8 *mac_addr) 25e5a49c1eSTony Lindgren { 26e5a49c1eSTony Lindgren u32 macid_lo; 27e5a49c1eSTony Lindgren u32 macid_hi; 28e5a49c1eSTony Lindgren struct regmap *syscon; 29e5a49c1eSTony Lindgren 30e5a49c1eSTony Lindgren syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon"); 31e5a49c1eSTony Lindgren if (IS_ERR(syscon)) { 32e5a49c1eSTony Lindgren if (PTR_ERR(syscon) == -ENODEV) 33e5a49c1eSTony Lindgren return 0; 34e5a49c1eSTony Lindgren return PTR_ERR(syscon); 35e5a49c1eSTony Lindgren } 36e5a49c1eSTony Lindgren 37e5a49c1eSTony Lindgren regmap_read(syscon, AM33XX_CTRL_MAC_LO_REG(offset, slave), 38e5a49c1eSTony Lindgren &macid_lo); 39e5a49c1eSTony Lindgren regmap_read(syscon, AM33XX_CTRL_MAC_HI_REG(offset, slave), 40e5a49c1eSTony Lindgren &macid_hi); 41e5a49c1eSTony Lindgren 42e5a49c1eSTony Lindgren mac_addr[5] = (macid_lo >> 8) & 0xff; 43e5a49c1eSTony Lindgren mac_addr[4] = macid_lo & 0xff; 44e5a49c1eSTony Lindgren mac_addr[3] = (macid_hi >> 24) & 0xff; 45e5a49c1eSTony Lindgren mac_addr[2] = (macid_hi >> 16) & 0xff; 46e5a49c1eSTony Lindgren mac_addr[1] = (macid_hi >> 8) & 0xff; 47e5a49c1eSTony Lindgren mac_addr[0] = macid_hi & 0xff; 48e5a49c1eSTony Lindgren 49e5a49c1eSTony Lindgren return 0; 50e5a49c1eSTony Lindgren } 51e5a49c1eSTony Lindgren EXPORT_SYMBOL_GPL(cpsw_am33xx_cm_get_macid); 52e5a49c1eSTony Lindgren 53e5a49c1eSTony Lindgren MODULE_LICENSE("GPL"); 54