Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: cpsw: Add am33xx MACID readout

This patch adds a function to get the MACIDs from the am33xx SoC
control module registers which hold unique vendor MACIDs. This is only
used if of_get_mac_address() fails to get a valid mac address.

Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
Reviewed-by: Wolfram Sang <wsa@the-dreams.de>
Tested-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Markus Pargmann and committed by
David S. Miller
0ba517b1 56fdb2e0

+47 -1
+4
Documentation/devicetree/bindings/net/cpsw.txt
··· 24 24 - ti,hwmods : Must be "cpgmac0" 25 25 - no_bd_ram : Must be 0 or 1 26 26 - dual_emac : Specifies Switch to act as Dual EMAC 27 + - syscon : Phandle to the system control device node, which is 28 + the control module device of the am33x 27 29 28 30 Slave Properties: 29 31 Required properties: ··· 59 57 active_slave = <0>; 60 58 cpts_clock_mult = <0x80000000>; 61 59 cpts_clock_shift = <29>; 60 + syscon = <&cm>; 62 61 cpsw_emac0: slave@0 { 63 62 phy_id = <&davinci_mdio>, <0>; 64 63 phy-mode = "rgmii-txid"; ··· 88 85 active_slave = <0>; 89 86 cpts_clock_mult = <0x80000000>; 90 87 cpts_clock_shift = <29>; 88 + syscon = <&cm>; 91 89 cpsw_emac0: slave@0 { 92 90 phy_id = <&davinci_mdio>, <0>; 93 91 phy-mode = "rgmii-txid";
+2
drivers/net/ethernet/ti/Kconfig
··· 62 62 select TI_DAVINCI_CPDMA 63 63 select TI_DAVINCI_MDIO 64 64 select TI_CPSW_PHY_SEL 65 + select MFD_SYSCON 66 + select REGMAP 65 67 ---help--- 66 68 This driver supports TI's CPSW Ethernet Switch. 67 69
+41 -1
drivers/net/ethernet/ti/cpsw.c
··· 33 33 #include <linux/of_net.h> 34 34 #include <linux/of_device.h> 35 35 #include <linux/if_vlan.h> 36 + #include <linux/mfd/syscon.h> 37 + #include <linux/regmap.h> 36 38 37 39 #include <linux/pinctrl/consumer.h> 38 40 ··· 1878 1876 slave->port_vlan = data->dual_emac_res_vlan; 1879 1877 } 1880 1878 1879 + #define AM33XX_CTRL_MAC_LO_REG(id) (0x630 + 0x8 * id) 1880 + #define AM33XX_CTRL_MAC_HI_REG(id) (0x630 + 0x8 * id + 0x4) 1881 + 1882 + static int cpsw_am33xx_cm_get_macid(struct device *dev, int slave, 1883 + u8 *mac_addr) 1884 + { 1885 + u32 macid_lo; 1886 + u32 macid_hi; 1887 + struct regmap *syscon; 1888 + 1889 + syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon"); 1890 + if (IS_ERR(syscon)) { 1891 + if (PTR_ERR(syscon) == -ENODEV) 1892 + return 0; 1893 + return PTR_ERR(syscon); 1894 + } 1895 + 1896 + regmap_read(syscon, AM33XX_CTRL_MAC_LO_REG(slave), &macid_lo); 1897 + regmap_read(syscon, AM33XX_CTRL_MAC_HI_REG(slave), &macid_hi); 1898 + 1899 + mac_addr[5] = (macid_lo >> 8) & 0xff; 1900 + mac_addr[4] = macid_lo & 0xff; 1901 + mac_addr[3] = (macid_hi >> 24) & 0xff; 1902 + mac_addr[2] = (macid_hi >> 16) & 0xff; 1903 + mac_addr[1] = (macid_hi >> 8) & 0xff; 1904 + mac_addr[0] = macid_hi & 0xff; 1905 + 1906 + return 0; 1907 + } 1908 + 1881 1909 static int cpsw_probe_dt(struct cpsw_platform_data *data, 1882 1910 struct platform_device *pdev) 1883 1911 { ··· 2020 1988 PHY_ID_FMT, mdio->name, phyid); 2021 1989 2022 1990 mac_addr = of_get_mac_address(slave_node); 2023 - if (mac_addr) 1991 + if (mac_addr) { 2024 1992 memcpy(slave_data->mac_addr, mac_addr, ETH_ALEN); 1993 + } else { 1994 + if (of_machine_is_compatible("ti,am33xx")) { 1995 + ret = cpsw_am33xx_cm_get_macid(&pdev->dev, i, 1996 + slave_data->mac_addr); 1997 + if (ret) 1998 + return ret; 1999 + } 2000 + } 2025 2001 2026 2002 slave_data->phy_if = of_get_phy_mode(slave_node); 2027 2003 if (slave_data->phy_if < 0) {