Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / net / ethernet / ti / cpsw-common.c
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 AM33XX_CTRL_MAC_LO_REG(offset, id) ((offset) + 0x8 * (id))
23 #define AM33XX_CTRL_MAC_HI_REG(offset, id) ((offset) + 0x8 * (id) + 0x4)
24
25 int cpsw_am33xx_cm_get_macid(struct device *dev, u16 offset, int slave,
26                              u8 *mac_addr)
27 {
28         u32 macid_lo;
29         u32 macid_hi;
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, AM33XX_CTRL_MAC_LO_REG(offset, slave),
40                     &macid_lo);
41         regmap_read(syscon, AM33XX_CTRL_MAC_HI_REG(offset, slave),
42                     &macid_hi);
43
44         mac_addr[5] = (macid_lo >> 8) & 0xff;
45         mac_addr[4] = macid_lo & 0xff;
46         mac_addr[3] = (macid_hi >> 24) & 0xff;
47         mac_addr[2] = (macid_hi >> 16) & 0xff;
48         mac_addr[1] = (macid_hi >> 8) & 0xff;
49         mac_addr[0] = macid_hi & 0xff;
50
51         return 0;
52 }
53 EXPORT_SYMBOL_GPL(cpsw_am33xx_cm_get_macid);
54
55 MODULE_LICENSE("GPL");