Loading...
1// SPDX-License-Identifier: GPL-2.0+
2
3#include <linux/kernel.h>
4#include <linux/module.h>
5#include <linux/of.h>
6#include <linux/regmap.h>
7#include <linux/mfd/syscon.h>
8
9#include "cpsw.h"
10
11#define CTRL_MAC_LO_REG(offset, id) ((offset) + 0x8 * (id))
12#define CTRL_MAC_HI_REG(offset, id) ((offset) + 0x8 * (id) + 0x4)
13
14static int davinci_emac_3517_get_macid(struct device *dev, u16 offset,
15 int slave, u8 *mac_addr)
16{
17 u32 macid_lsb;
18 u32 macid_msb;
19 struct regmap *syscon;
20
21 syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
22 if (IS_ERR(syscon)) {
23 if (PTR_ERR(syscon) == -ENODEV)
24 return 0;
25 return PTR_ERR(syscon);
26 }
27
28 regmap_read(syscon, CTRL_MAC_LO_REG(offset, slave), &macid_lsb);
29 regmap_read(syscon, CTRL_MAC_HI_REG(offset, slave), &macid_msb);
30
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;
37
38 return 0;
39}
40
41static int cpsw_am33xx_cm_get_macid(struct device *dev, u16 offset, int slave,
42 u8 *mac_addr)
43{
44 u32 macid_lo;
45 u32 macid_hi;
46 struct regmap *syscon;
47
48 syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
49 if (IS_ERR(syscon)) {
50 if (PTR_ERR(syscon) == -ENODEV)
51 return 0;
52 return PTR_ERR(syscon);
53 }
54
55 regmap_read(syscon, CTRL_MAC_LO_REG(offset, slave), &macid_lo);
56 regmap_read(syscon, CTRL_MAC_HI_REG(offset, slave), &macid_hi);
57
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;
64
65 return 0;
66}
67
68int ti_cm_get_macid(struct device *dev, int slave, u8 *mac_addr)
69{
70 if (of_machine_is_compatible("ti,dm8148"))
71 return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
72
73 if (of_machine_is_compatible("ti,am33xx"))
74 return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
75
76 if (of_device_is_compatible(dev->of_node, "ti,am3517-emac"))
77 return davinci_emac_3517_get_macid(dev, 0x110, slave, mac_addr);
78
79 if (of_device_is_compatible(dev->of_node, "ti,dm816-emac"))
80 return cpsw_am33xx_cm_get_macid(dev, 0x30, slave, mac_addr);
81
82 if (of_machine_is_compatible("ti,am43"))
83 return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
84
85 if (of_machine_is_compatible("ti,dra7"))
86 return davinci_emac_3517_get_macid(dev, 0x514, slave, mac_addr);
87
88 dev_info(dev, "incompatible machine/device type for reading mac address\n");
89 return -ENOENT;
90}
91EXPORT_SYMBOL_GPL(ti_cm_get_macid);
92
93MODULE_DESCRIPTION("TI CPSW Switch common module");
94MODULE_LICENSE("GPL");
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#include "cpsw.h"
21
22#define CTRL_MAC_LO_REG(offset, id) ((offset) + 0x8 * (id))
23#define CTRL_MAC_HI_REG(offset, id) ((offset) + 0x8 * (id) + 0x4)
24
25static int davinci_emac_3517_get_macid(struct device *dev, u16 offset,
26 int slave, u8 *mac_addr)
27{
28 u32 macid_lsb;
29 u32 macid_msb;
30 struct regmap *syscon;
31
32 syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
33 if (IS_ERR(syscon)) {
34 if (PTR_ERR(syscon) == -ENODEV)
35 return 0;
36 return PTR_ERR(syscon);
37 }
38
39 regmap_read(syscon, CTRL_MAC_LO_REG(offset, slave), &macid_lsb);
40 regmap_read(syscon, CTRL_MAC_HI_REG(offset, slave), &macid_msb);
41
42 mac_addr[0] = (macid_msb >> 16) & 0xff;
43 mac_addr[1] = (macid_msb >> 8) & 0xff;
44 mac_addr[2] = macid_msb & 0xff;
45 mac_addr[3] = (macid_lsb >> 16) & 0xff;
46 mac_addr[4] = (macid_lsb >> 8) & 0xff;
47 mac_addr[5] = macid_lsb & 0xff;
48
49 return 0;
50}
51
52static int cpsw_am33xx_cm_get_macid(struct device *dev, u16 offset, int slave,
53 u8 *mac_addr)
54{
55 u32 macid_lo;
56 u32 macid_hi;
57 struct regmap *syscon;
58
59 syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
60 if (IS_ERR(syscon)) {
61 if (PTR_ERR(syscon) == -ENODEV)
62 return 0;
63 return PTR_ERR(syscon);
64 }
65
66 regmap_read(syscon, CTRL_MAC_LO_REG(offset, slave), &macid_lo);
67 regmap_read(syscon, CTRL_MAC_HI_REG(offset, slave), &macid_hi);
68
69 mac_addr[5] = (macid_lo >> 8) & 0xff;
70 mac_addr[4] = macid_lo & 0xff;
71 mac_addr[3] = (macid_hi >> 24) & 0xff;
72 mac_addr[2] = (macid_hi >> 16) & 0xff;
73 mac_addr[1] = (macid_hi >> 8) & 0xff;
74 mac_addr[0] = macid_hi & 0xff;
75
76 return 0;
77}
78
79int ti_cm_get_macid(struct device *dev, int slave, u8 *mac_addr)
80{
81 if (of_machine_is_compatible("ti,dm8148"))
82 return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
83
84 if (of_machine_is_compatible("ti,am33xx"))
85 return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
86
87 if (of_device_is_compatible(dev->of_node, "ti,am3517-emac"))
88 return davinci_emac_3517_get_macid(dev, 0x110, slave, mac_addr);
89
90 if (of_device_is_compatible(dev->of_node, "ti,dm816-emac"))
91 return cpsw_am33xx_cm_get_macid(dev, 0x30, slave, mac_addr);
92
93 if (of_machine_is_compatible("ti,am4372"))
94 return cpsw_am33xx_cm_get_macid(dev, 0x630, slave, mac_addr);
95
96 if (of_machine_is_compatible("ti,dra7"))
97 return davinci_emac_3517_get_macid(dev, 0x514, slave, mac_addr);
98
99 dev_err(dev, "incompatible machine/device type for reading mac address\n");
100 return -ENOENT;
101}
102EXPORT_SYMBOL_GPL(ti_cm_get_macid);
103
104MODULE_LICENSE("GPL");