GNU Linux-libre 4.19.264-gnu1
[releases.git] / arch / arm / mach-davinci / devices.c
1 /*
2  * mach-davinci/devices.c
3  *
4  * DaVinci 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/init.h>
13 #include <linux/platform_device.h>
14 #include <linux/dma-mapping.h>
15 #include <linux/io.h>
16 #include <linux/reboot.h>
17
18 #include <mach/hardware.h>
19 #include <linux/platform_data/i2c-davinci.h>
20 #include <mach/irqs.h>
21 #include <mach/cputype.h>
22 #include <mach/mux.h>
23 #include <linux/platform_data/mmc-davinci.h>
24 #include <mach/time.h>
25 #include <linux/platform_data/edma.h>
26
27
28 #include "davinci.h"
29
30 #define DAVINCI_I2C_BASE             0x01C21000
31 #define DAVINCI_ATA_BASE             0x01C66000
32 #define DAVINCI_MMCSD0_BASE          0x01E10000
33 #define DM355_MMCSD0_BASE            0x01E11000
34 #define DM355_MMCSD1_BASE            0x01E00000
35 #define DM365_MMCSD0_BASE            0x01D11000
36 #define DM365_MMCSD1_BASE            0x01D00000
37
38 void __iomem  *davinci_sysmod_base;
39
40 void davinci_map_sysmod(void)
41 {
42         davinci_sysmod_base = ioremap_nocache(DAVINCI_SYSTEM_MODULE_BASE,
43                                               0x800);
44         /*
45          * Throw a bug since a lot of board initialization code depends
46          * on system module availability. ioremap() failing this early
47          * need careful looking into anyway.
48          */
49         BUG_ON(!davinci_sysmod_base);
50 }
51
52 static struct resource i2c_resources[] = {
53         {
54                 .start          = DAVINCI_I2C_BASE,
55                 .end            = DAVINCI_I2C_BASE + 0x40,
56                 .flags          = IORESOURCE_MEM,
57         },
58         {
59                 .start          = IRQ_I2C,
60                 .flags          = IORESOURCE_IRQ,
61         },
62 };
63
64 static struct platform_device davinci_i2c_device = {
65         .name           = "i2c_davinci",
66         .id             = 1,
67         .num_resources  = ARRAY_SIZE(i2c_resources),
68         .resource       = i2c_resources,
69 };
70
71 void __init davinci_init_i2c(struct davinci_i2c_platform_data *pdata)
72 {
73         if (cpu_is_davinci_dm644x())
74                 davinci_cfg_reg(DM644X_I2C);
75
76         davinci_i2c_device.dev.platform_data = pdata;
77         (void) platform_device_register(&davinci_i2c_device);
78 }
79
80 static struct resource ide_resources[] = {
81         {
82                 .start          = DAVINCI_ATA_BASE,
83                 .end            = DAVINCI_ATA_BASE + 0x7ff,
84                 .flags          = IORESOURCE_MEM,
85         },
86         {
87                 .start          = IRQ_IDE,
88                 .end            = IRQ_IDE,
89                 .flags          = IORESOURCE_IRQ,
90         },
91 };
92
93 static u64 ide_dma_mask = DMA_BIT_MASK(32);
94
95 static struct platform_device ide_device = {
96         .name           = "palm_bk3710",
97         .id             = -1,
98         .resource       = ide_resources,
99         .num_resources  = ARRAY_SIZE(ide_resources),
100         .dev = {
101                 .dma_mask               = &ide_dma_mask,
102                 .coherent_dma_mask      = DMA_BIT_MASK(32),
103         },
104 };
105
106 void __init davinci_init_ide(void)
107 {
108         if (cpu_is_davinci_dm644x()) {
109                 davinci_cfg_reg(DM644X_HPIEN_DISABLE);
110                 davinci_cfg_reg(DM644X_ATAEN);
111                 davinci_cfg_reg(DM644X_HDIREN);
112         } else if (cpu_is_davinci_dm646x()) {
113                 /* IRQ_DM646X_IDE is the same as IRQ_IDE */
114                 davinci_cfg_reg(DM646X_ATAEN);
115         } else {
116                 WARN_ON(1);
117                 return;
118         }
119
120         platform_device_register(&ide_device);
121 }
122
123 #if IS_ENABLED(CONFIG_MMC_DAVINCI)
124
125 static u64 mmcsd0_dma_mask = DMA_BIT_MASK(32);
126
127 static struct resource mmcsd0_resources[] = {
128         {
129                 /* different on dm355 */
130                 .start = DAVINCI_MMCSD0_BASE,
131                 .end   = DAVINCI_MMCSD0_BASE + SZ_4K - 1,
132                 .flags = IORESOURCE_MEM,
133         },
134         /* IRQs:  MMC/SD, then SDIO */
135         {
136                 .start = IRQ_MMCINT,
137                 .flags = IORESOURCE_IRQ,
138         }, {
139                 /* different on dm355 */
140                 .start = IRQ_SDIOINT,
141                 .flags = IORESOURCE_IRQ,
142         },
143 };
144
145 static struct platform_device davinci_mmcsd0_device = {
146         .name = "dm6441-mmc",
147         .id = 0,
148         .dev = {
149                 .dma_mask = &mmcsd0_dma_mask,
150                 .coherent_dma_mask = DMA_BIT_MASK(32),
151         },
152         .num_resources = ARRAY_SIZE(mmcsd0_resources),
153         .resource = mmcsd0_resources,
154 };
155
156 static u64 mmcsd1_dma_mask = DMA_BIT_MASK(32);
157
158 static struct resource mmcsd1_resources[] = {
159         {
160                 .start = DM355_MMCSD1_BASE,
161                 .end   = DM355_MMCSD1_BASE + SZ_4K - 1,
162                 .flags = IORESOURCE_MEM,
163         },
164         /* IRQs:  MMC/SD, then SDIO */
165         {
166                 .start = IRQ_DM355_MMCINT1,
167                 .flags = IORESOURCE_IRQ,
168         }, {
169                 .start = IRQ_DM355_SDIOINT1,
170                 .flags = IORESOURCE_IRQ,
171         },
172 };
173
174 static struct platform_device davinci_mmcsd1_device = {
175         .name = "dm6441-mmc",
176         .id = 1,
177         .dev = {
178                 .dma_mask = &mmcsd1_dma_mask,
179                 .coherent_dma_mask = DMA_BIT_MASK(32),
180         },
181         .num_resources = ARRAY_SIZE(mmcsd1_resources),
182         .resource = mmcsd1_resources,
183 };
184
185
186 void __init davinci_setup_mmc(int module, struct davinci_mmc_config *config)
187 {
188         struct platform_device  *pdev = NULL;
189
190         if (WARN_ON(cpu_is_davinci_dm646x()))
191                 return;
192
193         /* REVISIT: update PINMUX, ARM_IRQMUX, and EDMA_EVTMUX here too;
194          * for example if MMCSD1 is used for SDIO, maybe DAT2 is unused.
195          *
196          * FIXME dm6441 (no MMC/SD), dm357 (one), and dm335 (two) are
197          * not handled right here ...
198          */
199         switch (module) {
200         case 1:
201                 if (cpu_is_davinci_dm355()) {
202                         /* REVISIT we may not need all these pins if e.g. this
203                          * is a hard-wired SDIO device...
204                          */
205                         davinci_cfg_reg(DM355_SD1_CMD);
206                         davinci_cfg_reg(DM355_SD1_CLK);
207                         davinci_cfg_reg(DM355_SD1_DATA0);
208                         davinci_cfg_reg(DM355_SD1_DATA1);
209                         davinci_cfg_reg(DM355_SD1_DATA2);
210                         davinci_cfg_reg(DM355_SD1_DATA3);
211                 } else if (cpu_is_davinci_dm365()) {
212                         /* Configure pull down control */
213                         unsigned v;
214
215                         v = __raw_readl(DAVINCI_SYSMOD_VIRT(SYSMOD_PUPDCTL1));
216                         __raw_writel(v & ~0xfc0,
217                                         DAVINCI_SYSMOD_VIRT(SYSMOD_PUPDCTL1));
218
219                         mmcsd1_resources[0].start = DM365_MMCSD1_BASE;
220                         mmcsd1_resources[0].end = DM365_MMCSD1_BASE +
221                                                         SZ_4K - 1;
222                         mmcsd1_resources[2].start = IRQ_DM365_SDIOINT1;
223                         davinci_mmcsd1_device.name = "da830-mmc";
224                 } else
225                         break;
226
227                 pdev = &davinci_mmcsd1_device;
228                 break;
229         case 0:
230                 if (cpu_is_davinci_dm355()) {
231                         mmcsd0_resources[0].start = DM355_MMCSD0_BASE;
232                         mmcsd0_resources[0].end = DM355_MMCSD0_BASE + SZ_4K - 1;
233                         mmcsd0_resources[2].start = IRQ_DM355_SDIOINT0;
234
235                         /* expose all 6 MMC0 signals:  CLK, CMD, DATA[0..3] */
236                         davinci_cfg_reg(DM355_MMCSD0);
237
238                         /* enable RX EDMA */
239                         davinci_cfg_reg(DM355_EVT26_MMC0_RX);
240                 } else if (cpu_is_davinci_dm365()) {
241                         mmcsd0_resources[0].start = DM365_MMCSD0_BASE;
242                         mmcsd0_resources[0].end = DM365_MMCSD0_BASE +
243                                                         SZ_4K - 1;
244                         mmcsd0_resources[2].start = IRQ_DM365_SDIOINT0;
245                         davinci_mmcsd0_device.name = "da830-mmc";
246                 } else if (cpu_is_davinci_dm644x()) {
247                         /* REVISIT: should this be in board-init code? */
248                         /* Power-on 3.3V IO cells */
249                         __raw_writel(0,
250                                 DAVINCI_SYSMOD_VIRT(SYSMOD_VDD3P3VPWDN));
251                         /*Set up the pull regiter for MMC */
252                         davinci_cfg_reg(DM644X_MSTK);
253                 }
254
255                 pdev = &davinci_mmcsd0_device;
256                 break;
257         }
258
259         if (WARN_ON(!pdev))
260                 return;
261
262         pdev->dev.platform_data = config;
263         platform_device_register(pdev);
264 }
265
266 #else
267
268 void __init davinci_setup_mmc(int module, struct davinci_mmc_config *config)
269 {
270 }
271
272 #endif
273
274 /*-------------------------------------------------------------------------*/
275
276 static struct resource wdt_resources[] = {
277         {
278                 .start  = DAVINCI_WDOG_BASE,
279                 .end    = DAVINCI_WDOG_BASE + SZ_1K - 1,
280                 .flags  = IORESOURCE_MEM,
281         },
282 };
283
284 static struct platform_device davinci_wdt_device = {
285         .name           = "davinci-wdt",
286         .id             = -1,
287         .num_resources  = ARRAY_SIZE(wdt_resources),
288         .resource       = wdt_resources,
289 };
290
291 int davinci_init_wdt(void)
292 {
293         return platform_device_register(&davinci_wdt_device);
294 }
295
296 static struct platform_device davinci_gpio_device = {
297         .name   = "davinci_gpio",
298         .id     = -1,
299 };
300
301 int davinci_gpio_register(struct resource *res, int size, void *pdata)
302 {
303         davinci_gpio_device.resource = res;
304         davinci_gpio_device.num_resources = size;
305         davinci_gpio_device.dev.platform_data = pdata;
306         return platform_device_register(&davinci_gpio_device);
307 }
308
309 /*-------------------------------------------------------------------------*/
310
311 /*-------------------------------------------------------------------------*/
312
313 struct davinci_timer_instance davinci_timer_instance[2] = {
314         {
315                 .base           = DAVINCI_TIMER0_BASE,
316                 .bottom_irq     = IRQ_TINT0_TINT12,
317                 .top_irq        = IRQ_TINT0_TINT34,
318         },
319         {
320                 .base           = DAVINCI_TIMER1_BASE,
321                 .bottom_irq     = IRQ_TINT1_TINT12,
322                 .top_irq        = IRQ_TINT1_TINT34,
323         },
324 };
325