NUC900 LCD Controller Driver
[linux-2.6.git] / arch / arm / mach-w90x900 / dev.c
1 /*
2  * linux/arch/arm/mach-w90x900/dev.c
3  *
4  * Copyright (C) 2009 Nuvoton corporation.
5  *
6  * Wan ZongShun <mcuos.com@gmail.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation;version 2 of the License.
11  *
12  */
13
14 #include <linux/kernel.h>
15 #include <linux/types.h>
16 #include <linux/interrupt.h>
17 #include <linux/list.h>
18 #include <linux/timer.h>
19 #include <linux/init.h>
20 #include <linux/platform_device.h>
21
22 #include <linux/mtd/physmap.h>
23 #include <linux/mtd/mtd.h>
24 #include <linux/mtd/partitions.h>
25
26 #include <linux/spi/spi.h>
27 #include <linux/spi/flash.h>
28
29 #include <asm/mach/arch.h>
30 #include <asm/mach/map.h>
31 #include <asm/mach/irq.h>
32 #include <asm/mach-types.h>
33
34 #include <mach/regs-serial.h>
35 #include <mach/nuc900_spi.h>
36 #include <mach/map.h>
37 #include <mach/fb.h>
38
39 #include "cpu.h"
40
41 /*NUC900 evb norflash driver data */
42
43 #define NUC900_FLASH_BASE       0xA0000000
44 #define NUC900_FLASH_SIZE       0x400000
45 #define SPIOFFSET               0x200
46 #define SPIOREG_SIZE            0x100
47
48 static struct mtd_partition nuc900_flash_partitions[] = {
49         {
50                 .name   =       "NOR Partition 1 for kernel (960K)",
51                 .size   =       0xF0000,
52                 .offset =       0x10000,
53         },
54         {
55                 .name   =       "NOR Partition 2 for image (1M)",
56                 .size   =       0x100000,
57                 .offset =       0x100000,
58         },
59         {
60                 .name   =       "NOR Partition 3 for user (2M)",
61                 .size   =       0x200000,
62                 .offset =       0x00200000,
63         }
64 };
65
66 static struct physmap_flash_data nuc900_flash_data = {
67         .width          =       2,
68         .parts          =       nuc900_flash_partitions,
69         .nr_parts       =       ARRAY_SIZE(nuc900_flash_partitions),
70 };
71
72 static struct resource nuc900_flash_resources[] = {
73         {
74                 .start  =       NUC900_FLASH_BASE,
75                 .end    =       NUC900_FLASH_BASE + NUC900_FLASH_SIZE - 1,
76                 .flags  =       IORESOURCE_MEM,
77         }
78 };
79
80 static struct platform_device nuc900_flash_device = {
81         .name           =       "physmap-flash",
82         .id             =       0,
83         .dev            = {
84                                 .platform_data = &nuc900_flash_data,
85                         },
86         .resource       =       nuc900_flash_resources,
87         .num_resources  =       ARRAY_SIZE(nuc900_flash_resources),
88 };
89
90 /* USB EHCI Host Controller */
91
92 static struct resource nuc900_usb_ehci_resource[] = {
93         [0] = {
94                 .start = W90X900_PA_USBEHCIHOST,
95                 .end   = W90X900_PA_USBEHCIHOST + W90X900_SZ_USBEHCIHOST - 1,
96                 .flags = IORESOURCE_MEM,
97         },
98         [1] = {
99                 .start = IRQ_USBH,
100                 .end   = IRQ_USBH,
101                 .flags = IORESOURCE_IRQ,
102         }
103 };
104
105 static u64 nuc900_device_usb_ehci_dmamask = 0xffffffffUL;
106
107 static struct platform_device nuc900_device_usb_ehci = {
108         .name             = "nuc900-ehci",
109         .id               = -1,
110         .num_resources    = ARRAY_SIZE(nuc900_usb_ehci_resource),
111         .resource         = nuc900_usb_ehci_resource,
112         .dev              = {
113                 .dma_mask = &nuc900_device_usb_ehci_dmamask,
114                 .coherent_dma_mask = 0xffffffffUL
115         }
116 };
117
118 /* USB OHCI Host Controller */
119
120 static struct resource nuc900_usb_ohci_resource[] = {
121         [0] = {
122                 .start = W90X900_PA_USBOHCIHOST,
123                 .end   = W90X900_PA_USBOHCIHOST + W90X900_SZ_USBOHCIHOST - 1,
124                 .flags = IORESOURCE_MEM,
125         },
126         [1] = {
127                 .start = IRQ_USBH,
128                 .end   = IRQ_USBH,
129                 .flags = IORESOURCE_IRQ,
130         }
131 };
132
133 static u64 nuc900_device_usb_ohci_dmamask = 0xffffffffUL;
134 static struct platform_device nuc900_device_usb_ohci = {
135         .name             = "nuc900-ohci",
136         .id               = -1,
137         .num_resources    = ARRAY_SIZE(nuc900_usb_ohci_resource),
138         .resource         = nuc900_usb_ohci_resource,
139         .dev              = {
140                 .dma_mask = &nuc900_device_usb_ohci_dmamask,
141                 .coherent_dma_mask = 0xffffffffUL
142         }
143 };
144
145 /* USB Device (Gadget)*/
146
147 static struct resource nuc900_usbgadget_resource[] = {
148         [0] = {
149                 .start = W90X900_PA_USBDEV,
150                 .end   = W90X900_PA_USBDEV + W90X900_SZ_USBDEV - 1,
151                 .flags = IORESOURCE_MEM,
152         },
153         [1] = {
154                 .start = IRQ_USBD,
155                 .end   = IRQ_USBD,
156                 .flags = IORESOURCE_IRQ,
157         }
158 };
159
160 static struct platform_device nuc900_device_usbgadget = {
161         .name           = "nuc900-usbgadget",
162         .id             = -1,
163         .num_resources  = ARRAY_SIZE(nuc900_usbgadget_resource),
164         .resource       = nuc900_usbgadget_resource,
165 };
166
167 /* MAC device */
168
169 static struct resource nuc900_emc_resource[] = {
170         [0] = {
171                 .start = W90X900_PA_EMC,
172                 .end   = W90X900_PA_EMC + W90X900_SZ_EMC - 1,
173                 .flags = IORESOURCE_MEM,
174         },
175         [1] = {
176                 .start = IRQ_EMCTX,
177                 .end   = IRQ_EMCTX,
178                 .flags = IORESOURCE_IRQ,
179         },
180         [2] = {
181                 .start = IRQ_EMCRX,
182                 .end   = IRQ_EMCRX,
183                 .flags = IORESOURCE_IRQ,
184         }
185 };
186
187 static u64 nuc900_device_emc_dmamask = 0xffffffffUL;
188 static struct platform_device nuc900_device_emc = {
189         .name           = "nuc900-emc",
190         .id             = -1,
191         .num_resources  = ARRAY_SIZE(nuc900_emc_resource),
192         .resource       = nuc900_emc_resource,
193         .dev              = {
194                 .dma_mask = &nuc900_device_emc_dmamask,
195                 .coherent_dma_mask = 0xffffffffUL
196         }
197 };
198
199 /* SPI device */
200
201 static struct nuc900_spi_info nuc900_spiflash_data = {
202         .num_cs         = 1,
203         .lsb            = 0,
204         .txneg          = 1,
205         .rxneg          = 0,
206         .divider        = 24,
207         .sleep          = 0,
208         .txnum          = 0,
209         .txbitlen       = 1,
210         .bus_num        = 0,
211 };
212
213 static struct resource nuc900_spi_resource[] = {
214         [0] = {
215                 .start = W90X900_PA_I2C + SPIOFFSET,
216                 .end   = W90X900_PA_I2C + SPIOFFSET + SPIOREG_SIZE - 1,
217                 .flags = IORESOURCE_MEM,
218         },
219         [1] = {
220                 .start = IRQ_SSP,
221                 .end   = IRQ_SSP,
222                 .flags = IORESOURCE_IRQ,
223         }
224 };
225
226 static struct platform_device nuc900_device_spi = {
227         .name           = "nuc900-spi",
228         .id             = -1,
229         .num_resources  = ARRAY_SIZE(nuc900_spi_resource),
230         .resource       = nuc900_spi_resource,
231         .dev            = {
232                                 .platform_data = &nuc900_spiflash_data,
233                         }
234 };
235
236 /* spi device, spi flash info */
237
238 static struct mtd_partition nuc900_spi_flash_partitions[] = {
239         {
240                 .name = "bootloader(spi)",
241                 .size = 0x0100000,
242                 .offset = 0,
243         },
244 };
245
246 static struct flash_platform_data nuc900_spi_flash_data = {
247         .name = "m25p80",
248         .parts =  nuc900_spi_flash_partitions,
249         .nr_parts = ARRAY_SIZE(nuc900_spi_flash_partitions),
250         .type = "w25x16",
251 };
252
253 static struct spi_board_info nuc900_spi_board_info[] __initdata = {
254         {
255                 .modalias = "m25p80",
256                 .max_speed_hz = 20000000,
257                 .bus_num = 0,
258                 .chip_select = 1,
259                 .platform_data = &nuc900_spi_flash_data,
260                 .mode = SPI_MODE_0,
261         },
262 };
263
264 /* WDT Device */
265
266 static struct resource nuc900_wdt_resource[] = {
267         [0] = {
268                 .start = W90X900_PA_TIMER,
269                 .end   = W90X900_PA_TIMER + W90X900_SZ_TIMER - 1,
270                 .flags = IORESOURCE_MEM,
271         },
272         [1] = {
273                 .start = IRQ_WDT,
274                 .end   = IRQ_WDT,
275                 .flags = IORESOURCE_IRQ,
276         }
277 };
278
279 static struct platform_device nuc900_device_wdt = {
280         .name           = "nuc900-wdt",
281         .id             = -1,
282         .num_resources  = ARRAY_SIZE(nuc900_wdt_resource),
283         .resource       = nuc900_wdt_resource,
284 };
285
286 /*
287  * public device definition between 910 and 920, or 910
288  * and 950 or 950 and 960...,their dev platform register
289  * should be in specific file such as nuc950, nuc960 c
290  * files rather than the public dev.c file here. so the
291  * corresponding platform_device definition should not be
292  * static.
293 */
294
295 /* RTC controller*/
296
297 static struct resource nuc900_rtc_resource[] = {
298         [0] = {
299                 .start = W90X900_PA_RTC,
300                 .end   = W90X900_PA_RTC + 0xff,
301                 .flags = IORESOURCE_MEM,
302         },
303         [1] = {
304                 .start = IRQ_RTC,
305                 .end   = IRQ_RTC,
306                 .flags = IORESOURCE_IRQ,
307         },
308 };
309
310 struct platform_device nuc900_device_rtc = {
311         .name           = "nuc900-rtc",
312         .id             = -1,
313         .num_resources  = ARRAY_SIZE(nuc900_rtc_resource),
314         .resource       = nuc900_rtc_resource,
315 };
316
317 /*TouchScreen controller*/
318
319 static struct resource nuc900_ts_resource[] = {
320         [0] = {
321                 .start = W90X900_PA_ADC,
322                 .end   = W90X900_PA_ADC + W90X900_SZ_ADC-1,
323                 .flags = IORESOURCE_MEM,
324         },
325         [1] = {
326                 .start = IRQ_ADC,
327                 .end   = IRQ_ADC,
328                 .flags = IORESOURCE_IRQ,
329         },
330 };
331
332 struct platform_device nuc900_device_ts = {
333         .name           = "nuc900-ts",
334         .id             = -1,
335         .resource       = nuc900_ts_resource,
336         .num_resources  = ARRAY_SIZE(nuc900_ts_resource),
337 };
338
339 /* FMI Device */
340
341 static struct resource nuc900_fmi_resource[] = {
342         [0] = {
343                 .start = W90X900_PA_FMI,
344                 .end   = W90X900_PA_FMI + W90X900_SZ_FMI - 1,
345                 .flags = IORESOURCE_MEM,
346         },
347         [1] = {
348                 .start = IRQ_FMI,
349                 .end   = IRQ_FMI,
350                 .flags = IORESOURCE_IRQ,
351         }
352 };
353
354 struct platform_device nuc900_device_fmi = {
355         .name           = "nuc900-fmi",
356         .id             = -1,
357         .num_resources  = ARRAY_SIZE(nuc900_fmi_resource),
358         .resource       = nuc900_fmi_resource,
359 };
360
361 /* KPI controller*/
362
363 static struct resource nuc900_kpi_resource[] = {
364         [0] = {
365                 .start = W90X900_PA_KPI,
366                 .end   = W90X900_PA_KPI + W90X900_SZ_KPI - 1,
367                 .flags = IORESOURCE_MEM,
368         },
369         [1] = {
370                 .start = IRQ_KPI,
371                 .end   = IRQ_KPI,
372                 .flags = IORESOURCE_IRQ,
373         }
374
375 };
376
377 struct platform_device nuc900_device_kpi = {
378         .name           = "nuc900-kpi",
379         .id             = -1,
380         .num_resources  = ARRAY_SIZE(nuc900_kpi_resource),
381         .resource       = nuc900_kpi_resource,
382 };
383
384 #ifdef CONFIG_FB_NUC900
385
386 static struct resource nuc900_lcd_resource[] = {
387         [0] = {
388                 .start = W90X900_PA_LCD,
389                 .end   = W90X900_PA_LCD + W90X900_SZ_LCD - 1,
390                 .flags = IORESOURCE_MEM,
391         },
392         [1] = {
393                 .start = IRQ_LCD,
394                 .end   = IRQ_LCD,
395                 .flags = IORESOURCE_IRQ,
396         }
397 };
398
399 static u64 nuc900_device_lcd_dmamask = -1;
400 struct platform_device nuc900_device_lcd = {
401         .name             = "nuc900-lcd",
402         .id               = -1,
403         .num_resources    = ARRAY_SIZE(nuc900_lcd_resource),
404         .resource         = nuc900_lcd_resource,
405         .dev              = {
406                 .dma_mask               = &nuc900_device_lcd_dmamask,
407                 .coherent_dma_mask      = -1,
408         }
409 };
410
411 void  nuc900_fb_set_platdata(struct nuc900fb_mach_info *pd)
412 {
413         struct nuc900fb_mach_info *npd;
414
415         npd = kmalloc(sizeof(*npd), GFP_KERNEL);
416         if (npd) {
417                 memcpy(npd, pd, sizeof(*npd));
418                 nuc900_device_lcd.dev.platform_data = npd;
419         } else {
420                 printk(KERN_ERR "no memory for LCD platform data\n");
421         }
422 }
423 #endif
424
425 /*Here should be your evb resourse,such as LCD*/
426
427 static struct platform_device *nuc900_public_dev[] __initdata = {
428         &nuc900_serial_device,
429         &nuc900_flash_device,
430         &nuc900_device_usb_ehci,
431         &nuc900_device_usb_ohci,
432         &nuc900_device_usbgadget,
433         &nuc900_device_emc,
434         &nuc900_device_spi,
435         &nuc900_device_wdt,
436 };
437
438 /* Provide adding specific CPU platform devices API */
439
440 void __init nuc900_board_init(struct platform_device **device, int size)
441 {
442         platform_add_devices(device, size);
443         platform_add_devices(nuc900_public_dev, ARRAY_SIZE(nuc900_public_dev));
444         spi_register_board_info(nuc900_spi_board_info,
445                                         ARRAY_SIZE(nuc900_spi_board_info));
446 }
447