Commit | Line | Data |
---|---|---|
1a8bfa1e TL |
1 | /* |
2 | * linux/arch/arm/plat-omap/devices.c | |
3 | * | |
4 | * Common platform device setup/initialization for OMAP1 and OMAP2 | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | */ | |
11 | ||
1a8bfa1e TL |
12 | #include <linux/module.h> |
13 | #include <linux/kernel.h> | |
14 | #include <linux/init.h> | |
15 | #include <linux/platform_device.h> | |
fced80c7 | 16 | #include <linux/io.h> |
1a8bfa1e | 17 | |
a09e64fb | 18 | #include <mach/hardware.h> |
1a8bfa1e TL |
19 | #include <asm/mach-types.h> |
20 | #include <asm/mach/map.h> | |
21 | ||
ce491cf8 TL |
22 | #include <plat/tc.h> |
23 | #include <plat/control.h> | |
24 | #include <plat/board.h> | |
25 | #include <plat/mmc.h> | |
26 | #include <plat/mux.h> | |
a09e64fb | 27 | #include <mach/gpio.h> |
ce491cf8 TL |
28 | #include <plat/menelaus.h> |
29 | #include <plat/mcbsp.h> | |
30 | #include <plat/dsp_common.h> | |
d6a2d9b8 | 31 | #include <plat/omap44xx.h> |
1a8bfa1e | 32 | |
c40fae95 TL |
33 | #if defined(CONFIG_OMAP_DSP) || defined(CONFIG_OMAP_DSP_MODULE) |
34 | ||
c40fae95 TL |
35 | static struct dsp_platform_data dsp_pdata = { |
36 | .kdev_list = LIST_HEAD_INIT(dsp_pdata.kdev_list), | |
37 | }; | |
38 | ||
39 | static struct resource omap_dsp_resources[] = { | |
40 | { | |
41 | .name = "dsp_mmu", | |
42 | .start = -1, | |
43 | .flags = IORESOURCE_IRQ, | |
44 | }, | |
45 | }; | |
46 | ||
47 | static struct platform_device omap_dsp_device = { | |
48 | .name = "dsp", | |
49 | .id = -1, | |
50 | .num_resources = ARRAY_SIZE(omap_dsp_resources), | |
51 | .resource = omap_dsp_resources, | |
52 | .dev = { | |
53 | .platform_data = &dsp_pdata, | |
54 | }, | |
55 | }; | |
56 | ||
57 | static inline void omap_init_dsp(void) | |
58 | { | |
59 | struct resource *res; | |
60 | int irq; | |
61 | ||
62 | if (cpu_is_omap15xx()) | |
63 | irq = INT_1510_DSP_MMU; | |
64 | else if (cpu_is_omap16xx()) | |
65 | irq = INT_1610_DSP_MMU; | |
66 | else if (cpu_is_omap24xx()) | |
67 | irq = INT_24XX_DSP_MMU; | |
68 | ||
69 | res = platform_get_resource_byname(&omap_dsp_device, | |
70 | IORESOURCE_IRQ, "dsp_mmu"); | |
71 | res->start = irq; | |
72 | ||
73 | platform_device_register(&omap_dsp_device); | |
74 | } | |
75 | ||
76 | int dsp_kfunc_device_register(struct dsp_kfunc_device *kdev) | |
77 | { | |
78 | static DEFINE_MUTEX(dsp_pdata_lock); | |
79 | ||
646e3ed1 | 80 | spin_lock_init(&kdev->lock); |
c40fae95 TL |
81 | |
82 | mutex_lock(&dsp_pdata_lock); | |
83 | list_add_tail(&kdev->entry, &dsp_pdata.kdev_list); | |
84 | mutex_unlock(&dsp_pdata_lock); | |
85 | ||
86 | return 0; | |
87 | } | |
88 | EXPORT_SYMBOL(dsp_kfunc_device_register); | |
89 | ||
90 | #else | |
91 | static inline void omap_init_dsp(void) { } | |
92 | #endif /* CONFIG_OMAP_DSP */ | |
93 | ||
9b6553cd TL |
94 | /*-------------------------------------------------------------------------*/ |
95 | #if defined(CONFIG_KEYBOARD_OMAP) || defined(CONFIG_KEYBOARD_OMAP_MODULE) | |
96 | ||
97 | static void omap_init_kp(void) | |
98 | { | |
cc26b3b0 SMK |
99 | /* 2430 and 34xx keypad is on TWL4030 */ |
100 | if (cpu_is_omap2430() || cpu_is_omap34xx()) | |
101 | return; | |
102 | ||
9b6553cd TL |
103 | if (machine_is_omap_h2() || machine_is_omap_h3()) { |
104 | omap_cfg_reg(F18_1610_KBC0); | |
105 | omap_cfg_reg(D20_1610_KBC1); | |
106 | omap_cfg_reg(D19_1610_KBC2); | |
107 | omap_cfg_reg(E18_1610_KBC3); | |
108 | omap_cfg_reg(C21_1610_KBC4); | |
109 | ||
110 | omap_cfg_reg(G18_1610_KBR0); | |
111 | omap_cfg_reg(F19_1610_KBR1); | |
112 | omap_cfg_reg(H14_1610_KBR2); | |
113 | omap_cfg_reg(E20_1610_KBR3); | |
114 | omap_cfg_reg(E19_1610_KBR4); | |
115 | omap_cfg_reg(N19_1610_KBR5); | |
495f71db | 116 | } else if (machine_is_omap_perseus2() || machine_is_omap_fsample()) { |
7c006926 AB |
117 | omap_cfg_reg(E2_7XX_KBR0); |
118 | omap_cfg_reg(J7_7XX_KBR1); | |
119 | omap_cfg_reg(E1_7XX_KBR2); | |
120 | omap_cfg_reg(F3_7XX_KBR3); | |
121 | omap_cfg_reg(D2_7XX_KBR4); | |
122 | ||
123 | omap_cfg_reg(C2_7XX_KBC0); | |
124 | omap_cfg_reg(D3_7XX_KBC1); | |
125 | omap_cfg_reg(E4_7XX_KBC2); | |
126 | omap_cfg_reg(F4_7XX_KBC3); | |
127 | omap_cfg_reg(E3_7XX_KBC4); | |
9b6553cd TL |
128 | } else if (machine_is_omap_h4()) { |
129 | omap_cfg_reg(T19_24XX_KBR0); | |
130 | omap_cfg_reg(R19_24XX_KBR1); | |
131 | omap_cfg_reg(V18_24XX_KBR2); | |
132 | omap_cfg_reg(M21_24XX_KBR3); | |
133 | omap_cfg_reg(E5__24XX_KBR4); | |
134 | if (omap_has_menelaus()) { | |
135 | omap_cfg_reg(B3__24XX_KBR5); | |
136 | omap_cfg_reg(AA4_24XX_KBC2); | |
137 | omap_cfg_reg(B13_24XX_KBC6); | |
138 | } else { | |
139 | omap_cfg_reg(M18_24XX_KBR5); | |
140 | omap_cfg_reg(H19_24XX_KBC2); | |
141 | omap_cfg_reg(N19_24XX_KBC6); | |
142 | } | |
143 | omap_cfg_reg(R20_24XX_KBC0); | |
144 | omap_cfg_reg(M14_24XX_KBC1); | |
145 | omap_cfg_reg(V17_24XX_KBC3); | |
146 | omap_cfg_reg(P21_24XX_KBC4); | |
147 | omap_cfg_reg(L14_24XX_KBC5); | |
148 | } | |
149 | } | |
150 | #else | |
151 | static inline void omap_init_kp(void) {} | |
152 | #endif | |
153 | ||
bc5d0c89 EV |
154 | /*-------------------------------------------------------------------------*/ |
155 | #if defined(CONFIG_OMAP_MCBSP) || defined(CONFIG_OMAP_MCBSP_MODULE) | |
156 | ||
157 | static struct platform_device **omap_mcbsp_devices; | |
158 | ||
159 | void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config, | |
160 | int size) | |
161 | { | |
162 | int i; | |
163 | ||
bc5d0c89 EV |
164 | omap_mcbsp_devices = kzalloc(size * sizeof(struct platform_device *), |
165 | GFP_KERNEL); | |
166 | if (!omap_mcbsp_devices) { | |
167 | printk(KERN_ERR "Could not register McBSP devices\n"); | |
168 | return; | |
169 | } | |
170 | ||
171 | for (i = 0; i < size; i++) { | |
172 | struct platform_device *new_mcbsp; | |
173 | int ret; | |
174 | ||
175 | new_mcbsp = platform_device_alloc("omap-mcbsp", i + 1); | |
176 | if (!new_mcbsp) | |
177 | continue; | |
178 | new_mcbsp->dev.platform_data = &config[i]; | |
179 | ret = platform_device_add(new_mcbsp); | |
180 | if (ret) { | |
181 | platform_device_put(new_mcbsp); | |
182 | continue; | |
183 | } | |
184 | omap_mcbsp_devices[i] = new_mcbsp; | |
185 | } | |
186 | } | |
187 | ||
188 | #else | |
189 | void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config, | |
190 | int size) | |
191 | { } | |
192 | #endif | |
193 | ||
1a8bfa1e TL |
194 | /*-------------------------------------------------------------------------*/ |
195 | ||
d6a2d9b8 JEC |
196 | #if defined(CONFIG_SND_OMAP_SOC_MCPDM) || \ |
197 | defined(CONFIG_SND_OMAP_SOC_MCPDM_MODULE) | |
198 | ||
199 | static struct resource mcpdm_resources[] = { | |
200 | { | |
201 | .name = "mcpdm_mem", | |
202 | .start = OMAP44XX_MCPDM_BASE, | |
203 | .end = OMAP44XX_MCPDM_BASE + SZ_4K, | |
204 | .flags = IORESOURCE_MEM, | |
205 | }, | |
206 | { | |
207 | .name = "mcpdm_irq", | |
5772ca7d SS |
208 | .start = OMAP44XX_IRQ_MCPDM, |
209 | .end = OMAP44XX_IRQ_MCPDM, | |
d6a2d9b8 JEC |
210 | .flags = IORESOURCE_IRQ, |
211 | }, | |
212 | }; | |
213 | ||
214 | static struct platform_device omap_mcpdm_device = { | |
215 | .name = "omap-mcpdm", | |
216 | .id = -1, | |
217 | .num_resources = ARRAY_SIZE(mcpdm_resources), | |
218 | .resource = mcpdm_resources, | |
219 | }; | |
220 | ||
221 | static void omap_init_mcpdm(void) | |
222 | { | |
223 | (void) platform_device_register(&omap_mcpdm_device); | |
224 | } | |
225 | #else | |
226 | static inline void omap_init_mcpdm(void) {} | |
227 | #endif | |
228 | ||
229 | /*-------------------------------------------------------------------------*/ | |
230 | ||
d8874665 | 231 | #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE) || \ |
7736c09c | 232 | defined(CONFIG_MMC_OMAP_HS) || defined(CONFIG_MMC_OMAP_HS_MODULE) |
1a8bfa1e | 233 | |
d8874665 | 234 | #define OMAP_MMC_NR_RES 2 |
7736c09c | 235 | |
d8874665 TL |
236 | /* |
237 | * Register MMC devices. Called from mach-omap1 and mach-omap2 device init. | |
238 | */ | |
0dffb5c5 TL |
239 | int __init omap_mmc_add(const char *name, int id, unsigned long base, |
240 | unsigned long size, unsigned int irq, | |
241 | struct omap_mmc_platform_data *data) | |
7736c09c | 242 | { |
d8874665 TL |
243 | struct platform_device *pdev; |
244 | struct resource res[OMAP_MMC_NR_RES]; | |
245 | int ret; | |
246 | ||
0dffb5c5 | 247 | pdev = platform_device_alloc(name, id); |
d8874665 TL |
248 | if (!pdev) |
249 | return -ENOMEM; | |
250 | ||
251 | memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource)); | |
252 | res[0].start = base; | |
253 | res[0].end = base + size - 1; | |
254 | res[0].flags = IORESOURCE_MEM; | |
255 | res[1].start = res[1].end = irq; | |
256 | res[1].flags = IORESOURCE_IRQ; | |
257 | ||
258 | ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res)); | |
259 | if (ret == 0) | |
260 | ret = platform_device_add_data(pdev, data, sizeof(*data)); | |
261 | if (ret) | |
262 | goto fail; | |
263 | ||
264 | ret = platform_device_add(pdev); | |
265 | if (ret) | |
266 | goto fail; | |
01971f65 DB |
267 | |
268 | /* return device handle to board setup code */ | |
269 | data->dev = &pdev->dev; | |
d8874665 | 270 | return 0; |
7736c09c | 271 | |
d8874665 TL |
272 | fail: |
273 | platform_device_put(pdev); | |
274 | return ret; | |
7736c09c RK |
275 | } |
276 | ||
1a8bfa1e TL |
277 | #endif |
278 | ||
9b6553cd TL |
279 | /*-------------------------------------------------------------------------*/ |
280 | ||
3bfe8971 LM |
281 | #if defined(CONFIG_HW_RANDOM_OMAP) || defined(CONFIG_HW_RANDOM_OMAP_MODULE) |
282 | ||
088ef950 | 283 | #ifdef CONFIG_ARCH_OMAP2 |
3bfe8971 LM |
284 | #define OMAP_RNG_BASE 0x480A0000 |
285 | #else | |
286 | #define OMAP_RNG_BASE 0xfffe5000 | |
287 | #endif | |
288 | ||
289 | static struct resource rng_resources[] = { | |
290 | { | |
291 | .start = OMAP_RNG_BASE, | |
292 | .end = OMAP_RNG_BASE + 0x4f, | |
293 | .flags = IORESOURCE_MEM, | |
294 | }, | |
295 | }; | |
296 | ||
297 | static struct platform_device omap_rng_device = { | |
298 | .name = "omap_rng", | |
299 | .id = -1, | |
300 | .num_resources = ARRAY_SIZE(rng_resources), | |
301 | .resource = rng_resources, | |
302 | }; | |
303 | ||
304 | static void omap_init_rng(void) | |
305 | { | |
306 | (void) platform_device_register(&omap_rng_device); | |
307 | } | |
308 | #else | |
309 | static inline void omap_init_rng(void) {} | |
310 | #endif | |
311 | ||
312 | /*-------------------------------------------------------------------------*/ | |
313 | ||
9b6553cd TL |
314 | /* Numbering for the SPI-capable controllers when used for SPI: |
315 | * spi = 1 | |
316 | * uwire = 2 | |
317 | * mmc1..2 = 3..4 | |
318 | * mcbsp1..3 = 5..7 | |
319 | */ | |
320 | ||
321 | #if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE) | |
322 | ||
323 | #define OMAP_UWIRE_BASE 0xfffb3000 | |
324 | ||
325 | static struct resource uwire_resources[] = { | |
326 | { | |
327 | .start = OMAP_UWIRE_BASE, | |
328 | .end = OMAP_UWIRE_BASE + 0x20, | |
329 | .flags = IORESOURCE_MEM, | |
330 | }, | |
331 | }; | |
332 | ||
333 | static struct platform_device omap_uwire_device = { | |
334 | .name = "omap_uwire", | |
335 | .id = -1, | |
9b6553cd TL |
336 | .num_resources = ARRAY_SIZE(uwire_resources), |
337 | .resource = uwire_resources, | |
338 | }; | |
339 | ||
340 | static void omap_init_uwire(void) | |
341 | { | |
342 | /* FIXME define and use a boot tag; not all boards will be hooking | |
343 | * up devices to the microwire controller, and multi-board configs | |
344 | * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway... | |
345 | */ | |
346 | ||
347 | /* board-specific code must configure chipselects (only a few | |
348 | * are normally used) and SCLK/SDI/SDO (each has two choices). | |
349 | */ | |
350 | (void) platform_device_register(&omap_uwire_device); | |
351 | } | |
352 | #else | |
353 | static inline void omap_init_uwire(void) {} | |
354 | #endif | |
355 | ||
356 | /*-------------------------------------------------------------------------*/ | |
357 | ||
1a8bfa1e TL |
358 | #if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE) |
359 | ||
1a8bfa1e TL |
360 | static struct resource wdt_resources[] = { |
361 | { | |
1a8bfa1e TL |
362 | .flags = IORESOURCE_MEM, |
363 | }, | |
364 | }; | |
365 | ||
366 | static struct platform_device omap_wdt_device = { | |
367 | .name = "omap_wdt", | |
368 | .id = -1, | |
1a8bfa1e TL |
369 | .num_resources = ARRAY_SIZE(wdt_resources), |
370 | .resource = wdt_resources, | |
371 | }; | |
372 | ||
373 | static void omap_init_wdt(void) | |
374 | { | |
2817142f FB |
375 | if (cpu_is_omap16xx()) |
376 | wdt_resources[0].start = 0xfffeb000; | |
377 | else if (cpu_is_omap2420()) | |
378 | wdt_resources[0].start = 0x48022000; /* WDT2 */ | |
379 | else if (cpu_is_omap2430()) | |
380 | wdt_resources[0].start = 0x49016000; /* WDT2 */ | |
381 | else if (cpu_is_omap343x()) | |
382 | wdt_resources[0].start = 0x48314000; /* WDT2 */ | |
44169075 SS |
383 | else if (cpu_is_omap44xx()) |
384 | wdt_resources[0].start = 0x4a314000; | |
2817142f FB |
385 | else |
386 | return; | |
387 | ||
388 | wdt_resources[0].end = wdt_resources[0].start + 0x4f; | |
389 | ||
1a8bfa1e TL |
390 | (void) platform_device_register(&omap_wdt_device); |
391 | } | |
392 | #else | |
393 | static inline void omap_init_wdt(void) {} | |
394 | #endif | |
395 | ||
1a8bfa1e TL |
396 | /* |
397 | * This gets called after board-specific INIT_MACHINE, and initializes most | |
398 | * on-chip peripherals accessible on this board (except for few like USB): | |
399 | * | |
400 | * (a) Does any "standard config" pin muxing needed. Board-specific | |
401 | * code will have muxed GPIO pins and done "nonstandard" setup; | |
402 | * that code could live in the boot loader. | |
403 | * (b) Populating board-specific platform_data with the data drivers | |
404 | * rely on to handle wiring variations. | |
405 | * (c) Creating platform devices as meaningful on this board and | |
406 | * with this kernel configuration. | |
407 | * | |
408 | * Claiming GPIOs, and setting their direction and initial values, is the | |
409 | * responsibility of the device drivers. So is responding to probe(). | |
410 | * | |
411 | * Board-specific knowlege like creating devices or pin setup is to be | |
412 | * kept out of drivers as much as possible. In particular, pin setup | |
413 | * may be handled by the boot loader, and drivers should expect it will | |
414 | * normally have been done by the time they're probed. | |
415 | */ | |
416 | static int __init omap_init_devices(void) | |
417 | { | |
418 | /* please keep these calls, and their implementations above, | |
419 | * in alphabetical order so they're easier to sort through. | |
420 | */ | |
c40fae95 | 421 | omap_init_dsp(); |
9b6553cd | 422 | omap_init_kp(); |
3bfe8971 | 423 | omap_init_rng(); |
d6a2d9b8 | 424 | omap_init_mcpdm(); |
9b6553cd | 425 | omap_init_uwire(); |
1a8bfa1e | 426 | omap_init_wdt(); |
1a8bfa1e TL |
427 | return 0; |
428 | } | |
429 | arch_initcall(omap_init_devices); |