aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-mxs/mach-mxs.c
diff options
context:
space:
mode:
authorShawn Guo <shawn.guo@linaro.org>2012-06-19 10:38:14 -0400
committerShawn Guo <shawn.guo@linaro.org>2012-07-03 01:22:35 -0400
commit5653acc24c13e8b272e16a194b26465330753118 (patch)
tree86eee0ae5345c6af0a33a68ab209ba37a370af9d /arch/arm/mach-mxs/mach-mxs.c
parent80d969e491b514f8179ef354b7cf8b372610d01b (diff)
ARM: mxs: store mac address read from OTP in device tree
The non-DT boot reads the mac from OTP and pass it to fec driver via platform data. The patch provides an equivalent support for device tree boot, with reading mac from OTP and store it in device tree, and fec driver can get the mac from device tree at its probe time. Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Diffstat (limited to 'arch/arm/mach-mxs/mach-mxs.c')
-rw-r--r--arch/arm/mach-mxs/mach-mxs.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/arch/arm/mach-mxs/mach-mxs.c b/arch/arm/mach-mxs/mach-mxs.c
index 8cac94b33020..167f64911e72 100644
--- a/arch/arm/mach-mxs/mach-mxs.c
+++ b/arch/arm/mach-mxs/mach-mxs.c
@@ -71,6 +71,68 @@ static struct sys_timer imx28_timer = {
71 .init = imx28_timer_init, 71 .init = imx28_timer_init,
72}; 72};
73 73
74enum mac_oui {
75 OUI_FSL,
76 OUI_DENX,
77};
78
79static void __init update_fec_mac_prop(enum mac_oui oui)
80{
81 struct device_node *np, *from = NULL;
82 struct property *oldmac, *newmac;
83 const u32 *ocotp = mxs_get_ocotp();
84 u8 *macaddr;
85 u32 val;
86 int i;
87
88 for (i = 0; i < 2; i++) {
89 np = of_find_compatible_node(from, NULL, "fsl,imx28-fec");
90 if (!np)
91 return;
92 from = np;
93
94 newmac = kzalloc(sizeof(*newmac) + 6, GFP_KERNEL);
95 if (!newmac)
96 return;
97 newmac->value = newmac + 1;
98 newmac->length = 6;
99
100 newmac->name = kstrdup("local-mac-address", GFP_KERNEL);
101 if (!newmac->name) {
102 kfree(newmac);
103 return;
104 }
105
106 /*
107 * OCOTP only stores the last 4 octets for each mac address,
108 * so hard-code OUI here.
109 */
110 macaddr = newmac->value;
111 switch (oui) {
112 case OUI_FSL:
113 macaddr[0] = 0x00;
114 macaddr[1] = 0x04;
115 macaddr[2] = 0x9f;
116 break;
117 case OUI_DENX:
118 macaddr[0] = 0xc0;
119 macaddr[1] = 0xe5;
120 macaddr[2] = 0x4e;
121 break;
122 }
123 val = ocotp[i];
124 macaddr[3] = (val >> 16) & 0xff;
125 macaddr[4] = (val >> 8) & 0xff;
126 macaddr[5] = (val >> 0) & 0xff;
127
128 oldmac = of_find_property(np, newmac->name, NULL);
129 if (oldmac)
130 prom_update_property(np, newmac, oldmac);
131 else
132 prom_add_property(np, newmac);
133 }
134}
135
74static void __init imx28_evk_init(void) 136static void __init imx28_evk_init(void)
75{ 137{
76 struct clk *clk; 138 struct clk *clk;
@@ -79,6 +141,8 @@ static void __init imx28_evk_init(void)
79 clk = clk_get_sys("enet_out", NULL); 141 clk = clk_get_sys("enet_out", NULL);
80 if (!IS_ERR(clk)) 142 if (!IS_ERR(clk))
81 clk_prepare_enable(clk); 143 clk_prepare_enable(clk);
144
145 update_fec_mac_prop(OUI_FSL);
82} 146}
83 147
84static void __init mxs_machine_init(void) 148static void __init mxs_machine_init(void)