]> Pileus Git - ~andy/linux/blob - arch/arm/mach-mxs/mach-mxs.c
ARM: mxs: Add Crystalfontz CFA-10036 DTS
[~andy/linux] / arch / arm / mach-mxs / mach-mxs.c
1 /*
2  * Copyright 2012 Freescale Semiconductor, Inc.
3  * Copyright 2012 Linaro Ltd.
4  *
5  * The code contained herein is licensed under the GNU General Public
6  * License. You may obtain a copy of the GNU General Public License
7  * Version 2 or later at the following locations:
8  *
9  * http://www.opensource.org/licenses/gpl-license.html
10  * http://www.gnu.org/copyleft/gpl.html
11  */
12
13 #include <linux/clk.h>
14 #include <linux/clkdev.h>
15 #include <linux/err.h>
16 #include <linux/init.h>
17 #include <linux/init.h>
18 #include <linux/irqdomain.h>
19 #include <linux/of_irq.h>
20 #include <linux/of_platform.h>
21 #include <asm/mach/arch.h>
22 #include <asm/mach/time.h>
23 #include <mach/common.h>
24
25 static int __init mxs_icoll_add_irq_domain(struct device_node *np,
26                                 struct device_node *interrupt_parent)
27 {
28         irq_domain_add_legacy(np, 128, 0, 0, &irq_domain_simple_ops, NULL);
29
30         return 0;
31 }
32
33 static int __init mxs_gpio_add_irq_domain(struct device_node *np,
34                                 struct device_node *interrupt_parent)
35 {
36         static int gpio_irq_base = MXS_GPIO_IRQ_START;
37
38         irq_domain_add_legacy(np, 32, gpio_irq_base, 0, &irq_domain_simple_ops, NULL);
39         gpio_irq_base += 32;
40
41         return 0;
42 }
43
44 static const struct of_device_id mxs_irq_match[] __initconst = {
45         { .compatible = "fsl,mxs-icoll", .data = mxs_icoll_add_irq_domain, },
46         { .compatible = "fsl,mxs-gpio", .data = mxs_gpio_add_irq_domain, },
47         { /* sentinel */ }
48 };
49
50 static void __init mxs_dt_init_irq(void)
51 {
52         icoll_init_irq();
53         of_irq_init(mxs_irq_match);
54 }
55
56 static void __init imx23_timer_init(void)
57 {
58         mx23_clocks_init();
59 }
60
61 static struct sys_timer imx23_timer = {
62         .init = imx23_timer_init,
63 };
64
65 static void __init imx28_timer_init(void)
66 {
67         mx28_clocks_init();
68 }
69
70 static struct sys_timer imx28_timer = {
71         .init = imx28_timer_init,
72 };
73
74 enum mac_oui {
75         OUI_FSL,
76         OUI_DENX,
77 };
78
79 static 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
136 static void __init imx28_evk_init(void)
137 {
138         struct clk *clk;
139
140         /* Enable fec phy clock */
141         clk = clk_get_sys("enet_out", NULL);
142         if (!IS_ERR(clk))
143                 clk_prepare_enable(clk);
144
145         update_fec_mac_prop(OUI_FSL);
146 }
147
148 static void __init mxs_machine_init(void)
149 {
150         if (of_machine_is_compatible("fsl,imx28-evk"))
151                 imx28_evk_init();
152
153         of_platform_populate(NULL, of_default_bus_match_table,
154                                 NULL, NULL);
155 }
156
157 static const char *imx23_dt_compat[] __initdata = {
158         "fsl,imx23-evk",
159         "fsl,imx23",
160         NULL,
161 };
162
163 static const char *imx28_dt_compat[] __initdata = {
164         "crystalfontz,cfa10036",
165         "fsl,imx28-evk",
166         "fsl,imx28",
167         NULL,
168 };
169
170 DT_MACHINE_START(IMX23, "Freescale i.MX23 (Device Tree)")
171         .map_io         = mx23_map_io,
172         .init_irq       = mxs_dt_init_irq,
173         .timer          = &imx23_timer,
174         .init_machine   = mxs_machine_init,
175         .dt_compat      = imx23_dt_compat,
176         .restart        = mxs_restart,
177 MACHINE_END
178
179 DT_MACHINE_START(IMX28, "Freescale i.MX28 (Device Tree)")
180         .map_io         = mx28_map_io,
181         .init_irq       = mxs_dt_init_irq,
182         .timer          = &imx28_timer,
183         .init_machine   = mxs_machine_init,
184         .dt_compat      = imx28_dt_compat,
185         .restart        = mxs_restart,
186 MACHINE_END