Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 
0003 #include <linux/kernel.h>
0004 #include <linux/module.h>
0005 #include <linux/of.h>
0006 #include <linux/of_device.h>
0007 #include <linux/regmap.h>
0008 #include <linux/mfd/syscon.h>
0009 
0010 #include "cpsw.h"
0011 
0012 #define CTRL_MAC_LO_REG(offset, id) ((offset) + 0x8 * (id))
0013 #define CTRL_MAC_HI_REG(offset, id) ((offset) + 0x8 * (id) + 0x4)
0014 
0015 static int davinci_emac_3517_get_macid(struct device *dev, u16 offset,
0016                        int slave, u8 *mac_addr)
0017 {
0018     u32 macid_lsb;
0019     u32 macid_msb;
0020     struct regmap *syscon;
0021 
0022     syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
0023     if (IS_ERR(syscon)) {
0024         if (PTR_ERR(syscon) == -ENODEV)
0025             return 0;
0026         return PTR_ERR(syscon);
0027     }
0028 
0029     regmap_read(syscon, CTRL_MAC_LO_REG(offset, slave), &macid_lsb);
0030     regmap_read(syscon, CTRL_MAC_HI_REG(offset, slave), &macid_msb);
0031 
0032     mac_addr[0] = (macid_msb >> 16) & 0xff;
0033     mac_addr[1] = (macid_msb >> 8)  & 0xff;
0034     mac_addr[2] = macid_msb & 0xff;
0035     mac_addr[3] = (macid_lsb >> 16) & 0xff;
0036     mac_addr[4] = (macid_lsb >> 8)  & 0xff;
0037     mac_addr[5] = macid_lsb & 0xff;
0038 
0039     return 0;
0040 }
0041 
0042 static int cpsw_am33xx_cm_get_macid(struct device *dev, u16 offset, int slave,
0043                     u8 *mac_addr)
0044 {
0045     u32 macid_lo;
0046     u32 macid_hi;
0047     struct regmap *syscon;
0048 
0049     syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
0050     if (IS_ERR(syscon)) {
0051         if (PTR_ERR(syscon) == -ENODEV)
0052             return 0;
0053         return PTR_ERR(syscon);
0054     }
0055 
0056     regmap_read(syscon, CTRL_MAC_LO_REG(offset, slave), &macid_lo);
0057     regmap_read(syscon, CTRL_MAC_HI_REG(offset, slave), &macid_hi);
0058 
0059     mac_addr[5] = (macid_lo >> 8) & 0xff;
0060     mac_addr[4] = macid_lo & 0xff;
0061     mac_addr[3] = (macid_hi >> 24) & 0xff;
0062     mac_addr[2] = (macid_hi >> 16) & 0xff;
0063     mac_addr[1] = (macid_hi >> 8) & 0xff;
0064     mac_addr[0] = macid_hi & 0xff;
0065 
0066     return 0;
0067 }
0068 
0069 int ti_cm_get_macid(struct device *dev, int slave, u8 *mac_addr)
0070 {
0071     if (of_machine_is_compatible("ti,dm8148"))
0072         return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
0073 
0074     if (of_machine_is_compatible("ti,am33xx"))
0075         return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
0076 
0077     if (of_device_is_compatible(dev->of_node, "ti,am3517-emac"))
0078         return davinci_emac_3517_get_macid(dev, 0x110, slave, mac_addr);
0079 
0080     if (of_device_is_compatible(dev->of_node, "ti,dm816-emac"))
0081         return cpsw_am33xx_cm_get_macid(dev, 0x30, slave, mac_addr);
0082 
0083     if (of_machine_is_compatible("ti,am43"))
0084         return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
0085 
0086     if (of_machine_is_compatible("ti,dra7"))
0087         return davinci_emac_3517_get_macid(dev, 0x514, slave, mac_addr);
0088 
0089     dev_info(dev, "incompatible machine/device type for reading mac address\n");
0090     return -ENOENT;
0091 }
0092 EXPORT_SYMBOL_GPL(ti_cm_get_macid);
0093 
0094 MODULE_LICENSE("GPL");