1 // SPDX-License-Identifier: GPL-2.0+
3 #include <linux/kernel.h>
4 #include <linux/module.h>
6 #include <linux/regmap.h>
7 #include <linux/mfd/syscon.h>
11 #define CTRL_MAC_LO_REG(offset, id) ((offset) + 0x8 * (id))
12 #define CTRL_MAC_HI_REG(offset, id) ((offset) + 0x8 * (id) + 0x4)
14 static int davinci_emac_3517_get_macid(struct device
*dev
, u16 offset
,
15 int slave
, u8
*mac_addr
)
19 struct regmap
*syscon
;
21 syscon
= syscon_regmap_lookup_by_phandle(dev
->of_node
, "syscon");
23 if (PTR_ERR(syscon
) == -ENODEV
)
25 return PTR_ERR(syscon
);
28 regmap_read(syscon
, CTRL_MAC_LO_REG(offset
, slave
), &macid_lsb
);
29 regmap_read(syscon
, CTRL_MAC_HI_REG(offset
, slave
), &macid_msb
);
31 mac_addr
[0] = (macid_msb
>> 16) & 0xff;
32 mac_addr
[1] = (macid_msb
>> 8) & 0xff;
33 mac_addr
[2] = macid_msb
& 0xff;
34 mac_addr
[3] = (macid_lsb
>> 16) & 0xff;
35 mac_addr
[4] = (macid_lsb
>> 8) & 0xff;
36 mac_addr
[5] = macid_lsb
& 0xff;
41 static int cpsw_am33xx_cm_get_macid(struct device
*dev
, u16 offset
, int slave
,
46 struct regmap
*syscon
;
48 syscon
= syscon_regmap_lookup_by_phandle(dev
->of_node
, "syscon");
50 if (PTR_ERR(syscon
) == -ENODEV
)
52 return PTR_ERR(syscon
);
55 regmap_read(syscon
, CTRL_MAC_LO_REG(offset
, slave
), &macid_lo
);
56 regmap_read(syscon
, CTRL_MAC_HI_REG(offset
, slave
), &macid_hi
);
58 mac_addr
[5] = (macid_lo
>> 8) & 0xff;
59 mac_addr
[4] = macid_lo
& 0xff;
60 mac_addr
[3] = (macid_hi
>> 24) & 0xff;
61 mac_addr
[2] = (macid_hi
>> 16) & 0xff;
62 mac_addr
[1] = (macid_hi
>> 8) & 0xff;
63 mac_addr
[0] = macid_hi
& 0xff;
68 int ti_cm_get_macid(struct device
*dev
, int slave
, u8
*mac_addr
)
70 if (of_machine_is_compatible("ti,dm8148"))
71 return cpsw_am33xx_cm_get_macid(dev
, 0x630, slave
, mac_addr
);
73 if (of_machine_is_compatible("ti,am33xx"))
74 return cpsw_am33xx_cm_get_macid(dev
, 0x630, slave
, mac_addr
);
76 if (of_device_is_compatible(dev
->of_node
, "ti,am3517-emac"))
77 return davinci_emac_3517_get_macid(dev
, 0x110, slave
, mac_addr
);
79 if (of_device_is_compatible(dev
->of_node
, "ti,dm816-emac"))
80 return cpsw_am33xx_cm_get_macid(dev
, 0x30, slave
, mac_addr
);
82 if (of_machine_is_compatible("ti,am43"))
83 return cpsw_am33xx_cm_get_macid(dev
, 0x630, slave
, mac_addr
);
85 if (of_machine_is_compatible("ti,dra7"))
86 return davinci_emac_3517_get_macid(dev
, 0x514, slave
, mac_addr
);
88 dev_info(dev
, "incompatible machine/device type for reading mac address\n");
91 EXPORT_SYMBOL_GPL(ti_cm_get_macid
);
93 MODULE_DESCRIPTION("TI CPSW Switch common module");
94 MODULE_LICENSE("GPL");