blob: 745031870ce4bb1e6641aec7394bcb294ba9ad33 [file] [log] [blame]
Tony Lindgren7c38cf02005-09-08 23:07:38 +01001/*
2 * linux/arch/arm/mach-omap1/devices.c
3 *
4 * OMAP1 platform device setup/initialization
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
Janusz Krzysztofik1a96edd2010-10-01 16:37:00 -070012#include <linux/dma-mapping.h>
Russell King2f8163b2011-07-26 10:53:52 +010013#include <linux/gpio.h>
Tony Lindgren7c38cf02005-09-08 23:07:38 +010014#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
Russell Kingd052d1b2005-10-29 19:07:23 +010017#include <linux/platform_device.h>
Cory Maccarronec5c4dce2010-01-08 10:29:05 -080018#include <linux/spi/spi.h>
Tony Lindgren7c38cf02005-09-08 23:07:38 +010019
Paul Walmsley37c67d02012-10-29 20:49:44 -060020#include <linux/platform_data/omap-wd-timer.h>
21
Tony Lindgren7c38cf02005-09-08 23:07:38 +010022#include <asm/mach/map.h>
23
Tony Lindgren54b693d2012-10-02 13:39:28 -070024#include <mach/tc.h>
Tony Lindgren70c494c2012-09-19 10:46:56 -070025#include <mach/mux.h>
Tony Lindgren7c38cf02005-09-08 23:07:38 +010026
Tony Lindgren68cb7002012-08-31 17:04:35 -070027#include <mach/omap7xx.h>
Tony Lindgren2e3ee9f2012-02-24 10:34:34 -080028#include <mach/camera.h>
29#include <mach/hardware.h>
30
Tony Lindgren622297f2012-10-02 14:19:52 -070031#include "../plat-omap/sram.h"
32
Tony Lindgren2e3ee9f2012-02-24 10:34:34 -080033#include "common.h"
Tony Lindgrene9b70862011-11-11 10:15:11 -080034#include "clock.h"
Lokesh Vutla8c4cc002012-10-15 14:01:01 -070035#include "dma.h"
Tony Lindgren68f39e72012-10-15 12:09:43 -070036#include "mmc.h"
Tony Lindgrene9b70862011-11-11 10:15:11 -080037
Tony Lindgrenfcc76a82012-05-09 09:59:25 -070038#if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
39
40static struct platform_device omap_pcm = {
41 .name = "omap-pcm-audio",
42 .id = -1,
43};
44
45static void omap_init_audio(void)
46{
47 platform_device_register(&omap_pcm);
48}
49
50#else
51static inline void omap_init_audio(void) {}
52#endif
53
Tony Lindgren7c38cf02005-09-08 23:07:38 +010054/*-------------------------------------------------------------------------*/
55
David Brownelldb68b182006-12-06 20:38:36 -080056#if defined(CONFIG_RTC_DRV_OMAP) || defined(CONFIG_RTC_DRV_OMAP_MODULE)
Tony Lindgren7c38cf02005-09-08 23:07:38 +010057
58#define OMAP_RTC_BASE 0xfffb4800
59
60static struct resource rtc_resources[] = {
61 {
62 .start = OMAP_RTC_BASE,
63 .end = OMAP_RTC_BASE + 0x5f,
64 .flags = IORESOURCE_MEM,
65 },
66 {
67 .start = INT_RTC_TIMER,
68 .flags = IORESOURCE_IRQ,
69 },
70 {
71 .start = INT_RTC_ALARM,
72 .flags = IORESOURCE_IRQ,
73 },
74};
75
76static struct platform_device omap_rtc_device = {
77 .name = "omap_rtc",
78 .id = -1,
Tony Lindgren7c38cf02005-09-08 23:07:38 +010079 .num_resources = ARRAY_SIZE(rtc_resources),
80 .resource = rtc_resources,
81};
82
83static void omap_init_rtc(void)
84{
85 (void) platform_device_register(&omap_rtc_device);
86}
87#else
88static inline void omap_init_rtc(void) {}
89#endif
90
Tony Lindgrenc40fae952006-12-07 13:58:10 -080091static inline void omap_init_mbox(void) { }
Tony Lindgrenc40fae952006-12-07 13:58:10 -080092
Tony Lindgrend8874662008-12-10 17:37:16 -080093/*-------------------------------------------------------------------------*/
94
95#if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
96
97static inline void omap1_mmc_mux(struct omap_mmc_platform_data *mmc_controller,
98 int controller_nr)
99{
100 if (controller_nr == 0) {
Cory Maccarrone490a5662009-11-22 10:10:50 -0800101 if (cpu_is_omap7xx()) {
102 omap_cfg_reg(MMC_7XX_CMD);
103 omap_cfg_reg(MMC_7XX_CLK);
104 omap_cfg_reg(MMC_7XX_DAT0);
105 } else {
106 omap_cfg_reg(MMC_CMD);
107 omap_cfg_reg(MMC_CLK);
108 omap_cfg_reg(MMC_DAT0);
109 }
110
Tony Lindgrend8874662008-12-10 17:37:16 -0800111 if (cpu_is_omap1710()) {
112 omap_cfg_reg(M15_1710_MMC_CLKI);
113 omap_cfg_reg(P19_1710_MMC_CMDDIR);
114 omap_cfg_reg(P20_1710_MMC_DATDIR0);
115 }
Cory Maccarrone490a5662009-11-22 10:10:50 -0800116 if (mmc_controller->slots[0].wires == 4 && !cpu_is_omap7xx()) {
Tony Lindgrend8874662008-12-10 17:37:16 -0800117 omap_cfg_reg(MMC_DAT1);
118 /* NOTE: DAT2 can be on W10 (here) or M15 */
119 if (!mmc_controller->slots[0].nomux)
120 omap_cfg_reg(MMC_DAT2);
121 omap_cfg_reg(MMC_DAT3);
122 }
123 }
124
125 /* Block 2 is on newer chips, and has many pinout options */
126 if (cpu_is_omap16xx() && controller_nr == 1) {
127 if (!mmc_controller->slots[1].nomux) {
128 omap_cfg_reg(Y8_1610_MMC2_CMD);
129 omap_cfg_reg(Y10_1610_MMC2_CLK);
130 omap_cfg_reg(R18_1610_MMC2_CLKIN);
131 omap_cfg_reg(W8_1610_MMC2_DAT0);
Tony Lindgren90c62bf2008-12-10 17:37:17 -0800132 if (mmc_controller->slots[1].wires == 4) {
Tony Lindgrend8874662008-12-10 17:37:16 -0800133 omap_cfg_reg(V8_1610_MMC2_DAT1);
134 omap_cfg_reg(W15_1610_MMC2_DAT2);
135 omap_cfg_reg(R10_1610_MMC2_DAT3);
136 }
137
138 /* These are needed for the level shifter */
139 omap_cfg_reg(V9_1610_MMC2_CMDDIR);
140 omap_cfg_reg(V5_1610_MMC2_DATDIR0);
141 omap_cfg_reg(W19_1610_MMC2_DATDIR1);
142 }
143
144 /* Feedback clock must be set on OMAP-1710 MMC2 */
145 if (cpu_is_omap1710())
146 omap_writel(omap_readl(MOD_CONF_CTRL_1) | (1 << 24),
147 MOD_CONF_CTRL_1);
148 }
149}
150
Tony Lindgren6c432f72012-04-23 15:56:37 -0700151#define OMAP_MMC_NR_RES 4
Tony Lindgren5ff391d2012-04-23 15:56:36 -0700152
153/*
154 * Register MMC devices.
155 */
156static int __init omap_mmc_add(const char *name, int id, unsigned long base,
157 unsigned long size, unsigned int irq,
Tony Lindgren6c432f72012-04-23 15:56:37 -0700158 unsigned rx_req, unsigned tx_req,
Tony Lindgren5ff391d2012-04-23 15:56:36 -0700159 struct omap_mmc_platform_data *data)
160{
161 struct platform_device *pdev;
162 struct resource res[OMAP_MMC_NR_RES];
163 int ret;
164
165 pdev = platform_device_alloc(name, id);
166 if (!pdev)
167 return -ENOMEM;
168
169 memset(res, 0, OMAP_MMC_NR_RES * sizeof(struct resource));
170 res[0].start = base;
171 res[0].end = base + size - 1;
172 res[0].flags = IORESOURCE_MEM;
173 res[1].start = res[1].end = irq;
174 res[1].flags = IORESOURCE_IRQ;
Tony Lindgren6c432f72012-04-23 15:56:37 -0700175 res[2].start = rx_req;
176 res[2].name = "rx";
177 res[2].flags = IORESOURCE_DMA;
178 res[3].start = tx_req;
179 res[3].name = "tx";
180 res[3].flags = IORESOURCE_DMA;
Tony Lindgren5ff391d2012-04-23 15:56:36 -0700181
Tony Lindgren53db20d2012-10-15 12:10:33 -0700182 if (cpu_is_omap7xx())
183 data->slots[0].features = MMC_OMAP7XX;
184 if (cpu_is_omap15xx())
185 data->slots[0].features = MMC_OMAP15XX;
186 if (cpu_is_omap16xx())
187 data->slots[0].features = MMC_OMAP16XX;
188
Tony Lindgren5ff391d2012-04-23 15:56:36 -0700189 ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
190 if (ret == 0)
191 ret = platform_device_add_data(pdev, data, sizeof(*data));
192 if (ret)
193 goto fail;
194
195 ret = platform_device_add(pdev);
196 if (ret)
197 goto fail;
198
199 /* return device handle to board setup code */
200 data->dev = &pdev->dev;
201 return 0;
202
203fail:
204 platform_device_put(pdev);
205 return ret;
206}
207
Tony Lindgrend8874662008-12-10 17:37:16 -0800208void __init omap1_init_mmc(struct omap_mmc_platform_data **mmc_data,
209 int nr_controllers)
210{
211 int i;
212
213 for (i = 0; i < nr_controllers; i++) {
214 unsigned long base, size;
Tony Lindgren6c432f72012-04-23 15:56:37 -0700215 unsigned rx_req, tx_req;
Tony Lindgrend8874662008-12-10 17:37:16 -0800216 unsigned int irq = 0;
217
218 if (!mmc_data[i])
219 continue;
220
221 omap1_mmc_mux(mmc_data[i], i);
222
223 switch (i) {
224 case 0:
225 base = OMAP1_MMC1_BASE;
226 irq = INT_MMC;
Tony Lindgren6c432f72012-04-23 15:56:37 -0700227 rx_req = OMAP_DMA_MMC_RX;
228 tx_req = OMAP_DMA_MMC_TX;
Tony Lindgrend8874662008-12-10 17:37:16 -0800229 break;
230 case 1:
231 if (!cpu_is_omap16xx())
232 return;
233 base = OMAP1_MMC2_BASE;
234 irq = INT_1610_MMC2;
Tony Lindgren6c432f72012-04-23 15:56:37 -0700235 rx_req = OMAP_DMA_MMC2_RX;
236 tx_req = OMAP_DMA_MMC2_TX;
Tony Lindgrend8874662008-12-10 17:37:16 -0800237 break;
238 default:
239 continue;
240 }
241 size = OMAP1_MMC_SIZE;
242
Tony Lindgren6c432f72012-04-23 15:56:37 -0700243 omap_mmc_add("mmci-omap", i, base, size, irq,
244 rx_req, tx_req, mmc_data[i]);
Peter Senna Tschudin11eff272012-09-18 18:36:10 +0200245 }
Tony Lindgrend8874662008-12-10 17:37:16 -0800246}
247
248#endif
249
250/*-------------------------------------------------------------------------*/
251
Cory Maccarronec5c4dce2010-01-08 10:29:05 -0800252/* OMAP7xx SPI support */
253#if defined(CONFIG_SPI_OMAP_100K) || defined(CONFIG_SPI_OMAP_100K_MODULE)
254
255struct platform_device omap_spi1 = {
256 .name = "omap1_spi100k",
257 .id = 1,
258};
259
260struct platform_device omap_spi2 = {
261 .name = "omap1_spi100k",
262 .id = 2,
263};
264
265static void omap_init_spi100k(void)
266{
267 omap_spi1.dev.platform_data = ioremap(OMAP7XX_SPI1_BASE, 0x7ff);
268 if (omap_spi1.dev.platform_data)
269 platform_device_register(&omap_spi1);
270
271 omap_spi2.dev.platform_data = ioremap(OMAP7XX_SPI2_BASE, 0x7ff);
272 if (omap_spi2.dev.platform_data)
273 platform_device_register(&omap_spi2);
274}
275
276#else
277static inline void omap_init_spi100k(void)
278{
279}
280#endif
281
Janusz Krzysztofik1a96edd2010-10-01 16:37:00 -0700282
283#define OMAP1_CAMERA_BASE 0xfffb6800
284#define OMAP1_CAMERA_IOSIZE 0x1c
285
286static struct resource omap1_camera_resources[] = {
287 [0] = {
288 .start = OMAP1_CAMERA_BASE,
289 .end = OMAP1_CAMERA_BASE + OMAP1_CAMERA_IOSIZE - 1,
290 .flags = IORESOURCE_MEM,
291 },
292 [1] = {
293 .start = INT_CAMERA,
294 .flags = IORESOURCE_IRQ,
295 },
296};
297
298static u64 omap1_camera_dma_mask = DMA_BIT_MASK(32);
299
300static struct platform_device omap1_camera_device = {
301 .name = "omap1-camera",
302 .id = 0, /* This is used to put cameras on this interface */
303 .dev = {
304 .dma_mask = &omap1_camera_dma_mask,
305 .coherent_dma_mask = DMA_BIT_MASK(32),
306 },
307 .num_resources = ARRAY_SIZE(omap1_camera_resources),
308 .resource = omap1_camera_resources,
309};
310
311void __init omap1_camera_init(void *info)
312{
313 struct platform_device *dev = &omap1_camera_device;
314 int ret;
315
316 dev->dev.platform_data = info;
317
318 ret = platform_device_register(dev);
319 if (ret)
320 dev_err(&dev->dev, "unable to register device: %d\n", ret);
321}
322
323
Cory Maccarronec5c4dce2010-01-08 10:29:05 -0800324/*-------------------------------------------------------------------------*/
325
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100326static inline void omap_init_sti(void) {}
Tony Lindgren7c38cf02005-09-08 23:07:38 +0100327
Tony Lindgren49b1a612012-05-09 09:59:25 -0700328/* Numbering for the SPI-capable controllers when used for SPI:
329 * spi = 1
330 * uwire = 2
331 * mmc1..2 = 3..4
332 * mcbsp1..3 = 5..7
333 */
334
335#if defined(CONFIG_SPI_OMAP_UWIRE) || defined(CONFIG_SPI_OMAP_UWIRE_MODULE)
336
337#define OMAP_UWIRE_BASE 0xfffb3000
338
339static struct resource uwire_resources[] = {
340 {
341 .start = OMAP_UWIRE_BASE,
342 .end = OMAP_UWIRE_BASE + 0x20,
343 .flags = IORESOURCE_MEM,
344 },
345};
346
347static struct platform_device omap_uwire_device = {
348 .name = "omap_uwire",
349 .id = -1,
350 .num_resources = ARRAY_SIZE(uwire_resources),
351 .resource = uwire_resources,
352};
353
354static void omap_init_uwire(void)
355{
356 /* FIXME define and use a boot tag; not all boards will be hooking
357 * up devices to the microwire controller, and multi-board configs
358 * mean that CONFIG_SPI_OMAP_UWIRE may be configured anyway...
359 */
360
361 /* board-specific code must configure chipselects (only a few
362 * are normally used) and SCLK/SDI/SDO (each has two choices).
363 */
364 (void) platform_device_register(&omap_uwire_device);
365}
366#else
367static inline void omap_init_uwire(void) {}
368#endif
369
370
Paul Walmsley4848d462012-09-23 17:28:27 -0600371#define OMAP1_RNG_BASE 0xfffe5000
372
373static struct resource omap1_rng_resources[] = {
374 {
375 .start = OMAP1_RNG_BASE,
376 .end = OMAP1_RNG_BASE + 0x4f,
377 .flags = IORESOURCE_MEM,
378 },
379};
380
381static struct platform_device omap1_rng_device = {
382 .name = "omap_rng",
383 .id = -1,
384 .num_resources = ARRAY_SIZE(omap1_rng_resources),
385 .resource = omap1_rng_resources,
386};
387
388static void omap1_init_rng(void)
389{
Paul Walmsleyfe47c582012-09-23 17:28:27 -0600390 if (!cpu_is_omap16xx())
391 return;
392
Paul Walmsley4848d462012-09-23 17:28:27 -0600393 (void) platform_device_register(&omap1_rng_device);
394}
395
396/*-------------------------------------------------------------------------*/
397
Tony Lindgren7c38cf02005-09-08 23:07:38 +0100398/*
399 * This gets called after board-specific INIT_MACHINE, and initializes most
400 * on-chip peripherals accessible on this board (except for few like USB):
401 *
402 * (a) Does any "standard config" pin muxing needed. Board-specific
403 * code will have muxed GPIO pins and done "nonstandard" setup;
404 * that code could live in the boot loader.
405 * (b) Populating board-specific platform_data with the data drivers
406 * rely on to handle wiring variations.
407 * (c) Creating platform devices as meaningful on this board and
408 * with this kernel configuration.
409 *
410 * Claiming GPIOs, and setting their direction and initial values, is the
411 * responsibility of the device drivers. So is responding to probe().
412 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300413 * Board-specific knowledge like creating devices or pin setup is to be
Tony Lindgren7c38cf02005-09-08 23:07:38 +0100414 * kept out of drivers as much as possible. In particular, pin setup
415 * may be handled by the boot loader, and drivers should expect it will
416 * normally have been done by the time they're probed.
417 */
Tony Lindgren3179a012005-11-10 14:26:48 +0000418static int __init omap1_init_devices(void)
Tony Lindgren7c38cf02005-09-08 23:07:38 +0100419{
Tony Lindgren7f9187c2010-12-10 09:46:24 -0800420 if (!cpu_class_is_omap1())
421 return -ENODEV;
422
Tony Lindgrena66cb342011-10-04 13:52:57 -0700423 omap_sram_init();
Tony Lindgrene9b70862011-11-11 10:15:11 -0800424 omap1_clk_late_init();
Tony Lindgrena66cb342011-10-04 13:52:57 -0700425
Tony Lindgren7c38cf02005-09-08 23:07:38 +0100426 /* please keep these calls, and their implementations above,
427 * in alphabetical order so they're easier to sort through.
428 */
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800429
Tony Lindgrenfcc76a82012-05-09 09:59:25 -0700430 omap_init_audio();
Tony Lindgrenc40fae952006-12-07 13:58:10 -0800431 omap_init_mbox();
Tony Lindgren7c38cf02005-09-08 23:07:38 +0100432 omap_init_rtc();
Cory Maccarronec5c4dce2010-01-08 10:29:05 -0800433 omap_init_spi100k();
Tony Lindgren9b6553c2006-04-02 17:46:30 +0100434 omap_init_sti();
Tony Lindgren49b1a612012-05-09 09:59:25 -0700435 omap_init_uwire();
Paul Walmsley4848d462012-09-23 17:28:27 -0600436 omap1_init_rng();
Tony Lindgren7c38cf02005-09-08 23:07:38 +0100437
438 return 0;
439}
Tony Lindgren3179a012005-11-10 14:26:48 +0000440arch_initcall(omap1_init_devices);
Tony Lindgren7c38cf02005-09-08 23:07:38 +0100441
Varadarajan, Charulathaf2ce6232010-09-23 20:02:42 +0530442#if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
443
444static struct resource wdt_resources[] = {
445 {
446 .start = 0xfffeb000,
447 .end = 0xfffeb07F,
448 .flags = IORESOURCE_MEM,
449 },
450};
451
452static struct platform_device omap_wdt_device = {
Paul Walmsley37c67d02012-10-29 20:49:44 -0600453 .name = "omap_wdt",
454 .id = -1,
Varadarajan, Charulathaf2ce6232010-09-23 20:02:42 +0530455 .num_resources = ARRAY_SIZE(wdt_resources),
456 .resource = wdt_resources,
457};
458
459static int __init omap_init_wdt(void)
460{
Paul Walmsley37c67d02012-10-29 20:49:44 -0600461 struct omap_wd_timer_platform_data pdata;
462 int ret;
463
Varadarajan, Charulathaf2ce6232010-09-23 20:02:42 +0530464 if (!cpu_is_omap16xx())
Felipe Balbidfcccd32010-11-08 06:48:00 +0000465 return -ENODEV;
Varadarajan, Charulathaf2ce6232010-09-23 20:02:42 +0530466
Paul Walmsley37c67d02012-10-29 20:49:44 -0600467 pdata.read_reset_sources = omap1_get_reset_sources;
468
469 ret = platform_device_register(&omap_wdt_device);
470 if (!ret) {
471 ret = platform_device_add_data(&omap_wdt_device, &pdata,
472 sizeof(pdata));
473 if (ret)
474 platform_device_del(&omap_wdt_device);
475 }
476
477 return ret;
Varadarajan, Charulathaf2ce6232010-09-23 20:02:42 +0530478}
479subsys_initcall(omap_init_wdt);
480#endif