diff options
author | Tony Lindgren <tony@atomide.com> | 2015-01-28 14:33:04 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-01-30 20:42:01 -0500 |
commit | e5a49c1e3b189c744770e04d2b46ec7ca37d604c (patch) | |
tree | 4ffcdc2a900aa73de29b3bfceba7f72dcf3beb0c /drivers/net/ethernet/ti | |
parent | 4c72c53be5e3c8cf319a020ea671ab0fc32ec96f (diff) |
net: cpsw: Add a minimal cpsw-common module for shared code
Looks like davinci_emac and cpsw can share some code although the
device registers have a different layout.
At least the code for getting the MAC address using syscon can
be shared by passing the register offset. Let's start with that
and set up a minimal shared cpsw-shared.c.
Cc: Brian Hutchinson <b.hutchman@gmail.com>
Cc: Felipe Balbi <balbi@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/ethernet/ti')
-rw-r--r-- | drivers/net/ethernet/ti/Makefile | 3 | ||||
-rw-r--r-- | drivers/net/ethernet/ti/cpsw-common.c | 53 | ||||
-rw-r--r-- | drivers/net/ethernet/ti/cpsw.c | 35 | ||||
-rw-r--r-- | drivers/net/ethernet/ti/cpsw.h | 2 |
4 files changed, 60 insertions, 33 deletions
diff --git a/drivers/net/ethernet/ti/Makefile b/drivers/net/ethernet/ti/Makefile index 0a9813bc0451..5475cf60fa2d 100644 --- a/drivers/net/ethernet/ti/Makefile +++ b/drivers/net/ethernet/ti/Makefile | |||
@@ -2,6 +2,9 @@ | |||
2 | # Makefile for the TI network device drivers. | 2 | # Makefile for the TI network device drivers. |
3 | # | 3 | # |
4 | 4 | ||
5 | obj-$(CONFIG_TI_CPSW) += cpsw-common.o | ||
6 | obj-$(CONFIG_TI_DAVINCI_EMAC) += cpsw-common.o | ||
7 | |||
5 | obj-$(CONFIG_TLAN) += tlan.o | 8 | obj-$(CONFIG_TLAN) += tlan.o |
6 | obj-$(CONFIG_CPMAC) += cpmac.o | 9 | obj-$(CONFIG_CPMAC) += cpmac.o |
7 | obj-$(CONFIG_TI_DAVINCI_EMAC) += davinci_emac.o | 10 | obj-$(CONFIG_TI_DAVINCI_EMAC) += davinci_emac.o |
diff --git a/drivers/net/ethernet/ti/cpsw-common.c b/drivers/net/ethernet/ti/cpsw-common.c new file mode 100644 index 000000000000..763ada18ad3d --- /dev/null +++ b/drivers/net/ethernet/ti/cpsw-common.c | |||
@@ -0,0 +1,53 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify | ||
3 | * it under the terms of the GNU General Public License as published by | ||
4 | * the Free Software Foundation; either version 2 of the License, or | ||
5 | * (at your option) any later version. | ||
6 | * | ||
7 | * This program is distributed in the hope that it will be useful, | ||
8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
10 | * GNU General Public License for more details. | ||
11 | */ | ||
12 | |||
13 | #include <linux/kernel.h> | ||
14 | #include <linux/module.h> | ||
15 | #include <linux/of.h> | ||
16 | #include <linux/of_device.h> | ||
17 | #include <linux/regmap.h> | ||
18 | #include <linux/mfd/syscon.h> | ||
19 | |||
20 | #define AM33XX_CTRL_MAC_LO_REG(offset, id) ((offset) + 0x8 * (id)) | ||
21 | #define AM33XX_CTRL_MAC_HI_REG(offset, id) ((offset) + 0x8 * (id) + 0x4) | ||
22 | |||
23 | int cpsw_am33xx_cm_get_macid(struct device *dev, u16 offset, int slave, | ||
24 | u8 *mac_addr) | ||
25 | { | ||
26 | u32 macid_lo; | ||
27 | u32 macid_hi; | ||
28 | struct regmap *syscon; | ||
29 | |||
30 | syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon"); | ||
31 | if (IS_ERR(syscon)) { | ||
32 | if (PTR_ERR(syscon) == -ENODEV) | ||
33 | return 0; | ||
34 | return PTR_ERR(syscon); | ||
35 | } | ||
36 | |||
37 | regmap_read(syscon, AM33XX_CTRL_MAC_LO_REG(offset, slave), | ||
38 | &macid_lo); | ||
39 | regmap_read(syscon, AM33XX_CTRL_MAC_HI_REG(offset, slave), | ||
40 | &macid_hi); | ||
41 | |||
42 | mac_addr[5] = (macid_lo >> 8) & 0xff; | ||
43 | mac_addr[4] = macid_lo & 0xff; | ||
44 | mac_addr[3] = (macid_hi >> 24) & 0xff; | ||
45 | mac_addr[2] = (macid_hi >> 16) & 0xff; | ||
46 | mac_addr[1] = (macid_hi >> 8) & 0xff; | ||
47 | mac_addr[0] = macid_hi & 0xff; | ||
48 | |||
49 | return 0; | ||
50 | } | ||
51 | EXPORT_SYMBOL_GPL(cpsw_am33xx_cm_get_macid); | ||
52 | |||
53 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/net/ethernet/ti/cpsw.c b/drivers/net/ethernet/ti/cpsw.c index 2b9d404f8586..7d8dd0d2182e 100644 --- a/drivers/net/ethernet/ti/cpsw.c +++ b/drivers/net/ethernet/ti/cpsw.c | |||
@@ -33,8 +33,6 @@ | |||
33 | #include <linux/of_net.h> | 33 | #include <linux/of_net.h> |
34 | #include <linux/of_device.h> | 34 | #include <linux/of_device.h> |
35 | #include <linux/if_vlan.h> | 35 | #include <linux/if_vlan.h> |
36 | #include <linux/mfd/syscon.h> | ||
37 | #include <linux/regmap.h> | ||
38 | 36 | ||
39 | #include <linux/pinctrl/consumer.h> | 37 | #include <linux/pinctrl/consumer.h> |
40 | 38 | ||
@@ -1936,36 +1934,6 @@ static void cpsw_slave_init(struct cpsw_slave *slave, struct cpsw_priv *priv, | |||
1936 | slave->port_vlan = data->dual_emac_res_vlan; | 1934 | slave->port_vlan = data->dual_emac_res_vlan; |
1937 | } | 1935 | } |
1938 | 1936 | ||
1939 | #define AM33XX_CTRL_MAC_LO_REG(id) (0x630 + 0x8 * id) | ||
1940 | #define AM33XX_CTRL_MAC_HI_REG(id) (0x630 + 0x8 * id + 0x4) | ||
1941 | |||
1942 | static int cpsw_am33xx_cm_get_macid(struct device *dev, int slave, | ||
1943 | u8 *mac_addr) | ||
1944 | { | ||
1945 | u32 macid_lo; | ||
1946 | u32 macid_hi; | ||
1947 | struct regmap *syscon; | ||
1948 | |||
1949 | syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon"); | ||
1950 | if (IS_ERR(syscon)) { | ||
1951 | if (PTR_ERR(syscon) == -ENODEV) | ||
1952 | return 0; | ||
1953 | return PTR_ERR(syscon); | ||
1954 | } | ||
1955 | |||
1956 | regmap_read(syscon, AM33XX_CTRL_MAC_LO_REG(slave), &macid_lo); | ||
1957 | regmap_read(syscon, AM33XX_CTRL_MAC_HI_REG(slave), &macid_hi); | ||
1958 | |||
1959 | mac_addr[5] = (macid_lo >> 8) & 0xff; | ||
1960 | mac_addr[4] = macid_lo & 0xff; | ||
1961 | mac_addr[3] = (macid_hi >> 24) & 0xff; | ||
1962 | mac_addr[2] = (macid_hi >> 16) & 0xff; | ||
1963 | mac_addr[1] = (macid_hi >> 8) & 0xff; | ||
1964 | mac_addr[0] = macid_hi & 0xff; | ||
1965 | |||
1966 | return 0; | ||
1967 | } | ||
1968 | |||
1969 | static int cpsw_probe_dt(struct cpsw_platform_data *data, | 1937 | static int cpsw_probe_dt(struct cpsw_platform_data *data, |
1970 | struct platform_device *pdev) | 1938 | struct platform_device *pdev) |
1971 | { | 1939 | { |
@@ -2090,7 +2058,8 @@ no_phy_slave: | |||
2090 | memcpy(slave_data->mac_addr, mac_addr, ETH_ALEN); | 2058 | memcpy(slave_data->mac_addr, mac_addr, ETH_ALEN); |
2091 | } else { | 2059 | } else { |
2092 | if (of_machine_is_compatible("ti,am33xx")) { | 2060 | if (of_machine_is_compatible("ti,am33xx")) { |
2093 | ret = cpsw_am33xx_cm_get_macid(&pdev->dev, i, | 2061 | ret = cpsw_am33xx_cm_get_macid(&pdev->dev, |
2062 | 0x630, i, | ||
2094 | slave_data->mac_addr); | 2063 | slave_data->mac_addr); |
2095 | if (ret) | 2064 | if (ret) |
2096 | return ret; | 2065 | return ret; |
diff --git a/drivers/net/ethernet/ti/cpsw.h b/drivers/net/ethernet/ti/cpsw.h index 1b710674630c..ca90efafd156 100644 --- a/drivers/net/ethernet/ti/cpsw.h +++ b/drivers/net/ethernet/ti/cpsw.h | |||
@@ -41,5 +41,7 @@ struct cpsw_platform_data { | |||
41 | }; | 41 | }; |
42 | 42 | ||
43 | void cpsw_phy_sel(struct device *dev, phy_interface_t phy_mode, int slave); | 43 | void cpsw_phy_sel(struct device *dev, phy_interface_t phy_mode, int slave); |
44 | int cpsw_am33xx_cm_get_macid(struct device *dev, u16 offset, int slave, | ||
45 | u8 *mac_addr); | ||
44 | 46 | ||
45 | #endif /* __CPSW_H__ */ | 47 | #endif /* __CPSW_H__ */ |