ARM: OMAP2: Fix compillation error in cm_common
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-omap1 / devices.c
1 /*
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
12 #include <linux/dma-mapping.h>
13 #include <linux/gpio.h>
14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/init.h>
17 #include <linux/platform_device.h>
18 #include <linux/spi/spi.h>
19
20 #include <linux/platform_data/omap-wd-timer.h>
21
22 #include <asm/mach/map.h>
23
24 #include <mach/tc.h>
25 #include <mach/mux.h>
26
27 #include <mach/omap7xx.h>
28 #include <mach/camera.h>
29 #include <mach/hardware.h>
30
31 #include "../plat-omap/sram.h"
32
33 #include "common.h"
34 #include "clock.h"
35 #include "dma.h"
36 #include "mmc.h"
37
38 #if defined(CONFIG_SND_SOC) || defined(CONFIG_SND_SOC_MODULE)
39
40 static struct platform_device omap_pcm = {
41         .name   = "omap-pcm-audio",
42         .id     = -1,
43 };
44
45 static void omap_init_audio(void)
46 {
47         platform_device_register(&omap_pcm);
48 }
49
50 #else
51 static inline void omap_init_audio(void) {}
52 #endif
53
54 /*-------------------------------------------------------------------------*/
55
56 #if defined(CONFIG_RTC_DRV_OMAP) || defined(CONFIG_RTC_DRV_OMAP_MODULE)
57
58 #define OMAP_RTC_BASE           0xfffb4800
59
60 static 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
76 static struct platform_device omap_rtc_device = {
77         .name           = "omap_rtc",
78         .id             = -1,
79         .num_resources  = ARRAY_SIZE(rtc_resources),
80         .resource       = rtc_resources,
81 };
82
83 static void omap_init_rtc(void)
84 {
85         (void) platform_device_register(&omap_rtc_device);
86 }
87 #else
88 static inline void omap_init_rtc(void) {}
89 #endif
90
91 static inline void omap_init_mbox(void) { }
92
93 /*-------------------------------------------------------------------------*/
94
95 #if defined(CONFIG_MMC_OMAP) || defined(CONFIG_MMC_OMAP_MODULE)
96
97 static inline void omap1_mmc_mux(struct omap_mmc_platform_data *mmc_controller,
98                         int controller_nr)
99 {
100         if (controller_nr == 0) {
101                 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
111                 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                 }
116                 if (mmc_controller->slots[0].wires == 4 && !cpu_is_omap7xx()) {
117                         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);
132                         if (mmc_controller->slots[1].wires == 4) {
133                                 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
151 #define OMAP_MMC_NR_RES         4
152
153 /*
154  * Register MMC devices.
155  */
156 static int __init omap_mmc_add(const char *name, int id, unsigned long base,
157                                 unsigned long size, unsigned int irq,
158                                 unsigned rx_req, unsigned tx_req,
159                                 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;
175         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;
181
182         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
189         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
203 fail:
204         platform_device_put(pdev);
205         return ret;
206 }
207
208 void __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;
215                 unsigned rx_req, tx_req;
216                 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;
227                         rx_req = OMAP_DMA_MMC_RX;
228                         tx_req = OMAP_DMA_MMC_TX;
229                         break;
230                 case 1:
231                         if (!cpu_is_omap16xx())
232                                 return;
233                         base = OMAP1_MMC2_BASE;
234                         irq = INT_1610_MMC2;
235                         rx_req = OMAP_DMA_MMC2_RX;
236                         tx_req = OMAP_DMA_MMC2_TX;
237                         break;
238                 default:
239                         continue;
240                 }
241                 size = OMAP1_MMC_SIZE;
242
243                 omap_mmc_add("mmci-omap", i, base, size, irq,
244                                 rx_req, tx_req, mmc_data[i]);
245         }
246 }
247
248 #endif
249
250 /*-------------------------------------------------------------------------*/
251
252 /* OMAP7xx SPI support */
253 #if defined(CONFIG_SPI_OMAP_100K) || defined(CONFIG_SPI_OMAP_100K_MODULE)
254
255 struct platform_device omap_spi1 = {
256         .name           = "omap1_spi100k",
257         .id             = 1,
258 };
259
260 struct platform_device omap_spi2 = {
261         .name           = "omap1_spi100k",
262         .id             = 2,
263 };
264
265 static 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
277 static inline void omap_init_spi100k(void)
278 {
279 }
280 #endif
281
282
283 #define OMAP1_CAMERA_BASE       0xfffb6800
284 #define OMAP1_CAMERA_IOSIZE     0x1c
285
286 static 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
298 static u64 omap1_camera_dma_mask = DMA_BIT_MASK(32);
299
300 static 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
311 void __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
324 /*-------------------------------------------------------------------------*/
325
326 static inline void omap_init_sti(void) {}
327
328 /* 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
339 static struct resource uwire_resources[] = {
340         {
341                 .start          = OMAP_UWIRE_BASE,
342                 .end            = OMAP_UWIRE_BASE + 0x20,
343                 .flags          = IORESOURCE_MEM,
344         },
345 };
346
347 static 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
354 static 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
367 static inline void omap_init_uwire(void) {}
368 #endif
369
370
371 #define OMAP1_RNG_BASE          0xfffe5000
372
373 static struct resource omap1_rng_resources[] = {
374         {
375                 .start          = OMAP1_RNG_BASE,
376                 .end            = OMAP1_RNG_BASE + 0x4f,
377                 .flags          = IORESOURCE_MEM,
378         },
379 };
380
381 static 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
388 static void omap1_init_rng(void)
389 {
390         if (!cpu_is_omap16xx())
391                 return;
392
393         (void) platform_device_register(&omap1_rng_device);
394 }
395
396 /*-------------------------------------------------------------------------*/
397
398 /*
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  *
413  * Board-specific knowledge like creating devices or pin setup is to be
414  * 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  */
418 static int __init omap1_init_devices(void)
419 {
420         if (!cpu_class_is_omap1())
421                 return -ENODEV;
422
423         omap_sram_init();
424         omap1_clk_late_init();
425
426         /* please keep these calls, and their implementations above,
427          * in alphabetical order so they're easier to sort through.
428          */
429
430         omap_init_audio();
431         omap_init_mbox();
432         omap_init_rtc();
433         omap_init_spi100k();
434         omap_init_sti();
435         omap_init_uwire();
436         omap1_init_rng();
437
438         return 0;
439 }
440 arch_initcall(omap1_init_devices);
441
442 #if defined(CONFIG_OMAP_WATCHDOG) || defined(CONFIG_OMAP_WATCHDOG_MODULE)
443
444 static struct resource wdt_resources[] = {
445         {
446                 .start          = 0xfffeb000,
447                 .end            = 0xfffeb07F,
448                 .flags          = IORESOURCE_MEM,
449         },
450 };
451
452 static struct platform_device omap_wdt_device = {
453         .name           = "omap_wdt",
454         .id             = -1,
455         .num_resources  = ARRAY_SIZE(wdt_resources),
456         .resource       = wdt_resources,
457 };
458
459 static int __init omap_init_wdt(void)
460 {
461         struct omap_wd_timer_platform_data pdata;
462         int ret;
463
464         if (!cpu_is_omap16xx())
465                 return -ENODEV;
466
467         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;
478 }
479 subsys_initcall(omap_init_wdt);
480 #endif