adapt all kind of board
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk2818 / devices.c
1 /* arch/arm/mach-rk2818/devices.c
2  *
3  * Copyright (C) 2010 ROCKCHIP, Inc.
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15
16 #include <linux/fs.h>
17 #include <linux/kernel.h>
18 #include <linux/platform_device.h>
19 #include <linux/android_pmem.h>
20 #include <linux/usb/android_composite.h>
21 #include <linux/delay.h>
22 #include <mach/irqs.h>
23 #include <mach/rk2818_iomap.h>
24 #include "devices.h"
25
26 #include <asm/mach/flash.h>
27 #include <linux/mtd/nand.h>
28 #include <linux/mtd/partitions.h>
29
30 #include <mach/gpio.h>
31 #include <mach/rk2818_nand.h>
32 #include <mach/iomux.h>
33 #include <mach/rk2818_camera.h>                          /* ddl@rock-chips.com : camera support */
34 #include <linux/i2c.h>  
35 #include <linux/miscdevice.h>
36 #include <linux/circ_buf.h>
37 #include <mach/spi_fpga.h>                                    
38 #include <media/soc_camera.h>
39 #include "../../../drivers/staging/android/timed_gpio.h"
40 static struct resource resources_sdmmc0[] = {
41         {
42                 .start  = IRQ_NR_SDMMC0,
43                 .end    = IRQ_NR_SDMMC0,
44                 .flags  = IORESOURCE_IRQ,
45         },
46         {
47                 .start  = RK2818_SDMMC0_PHYS,
48                 .end    = RK2818_SDMMC0_PHYS + SZ_8K -1,
49                 .flags  = IORESOURCE_MEM,
50         }
51 };
52 static struct resource resources_sdmmc1[] = {
53         {
54                 .start  = IRQ_NR_SDMMC1,
55                 .end    = IRQ_NR_SDMMC1,
56                 .flags  = IORESOURCE_IRQ,
57         },
58         {
59                 .start  = RK2818_SDMMC1_PHYS,
60                 .end    = RK2818_SDMMC1_PHYS + SZ_8K -1,
61                 .flags  = IORESOURCE_MEM,
62         }
63 };
64
65
66 static struct resource resources_i2c0[] = {
67         {
68                 .start  = IRQ_NR_I2C0,
69                 .end    = IRQ_NR_I2C0,
70                 .flags  = IORESOURCE_IRQ,
71         },
72         {
73                 .start  = RK2818_I2C0_PHYS,
74                 .end    = RK2818_I2C0_PHYS + SZ_4K - 1,
75                 .flags  = IORESOURCE_MEM,
76         },
77 };
78 static struct resource resources_i2c1[] = {
79         {
80                 .start  = IRQ_NR_I2C1,
81                 .end    = IRQ_NR_I2C1,
82                 .flags  = IORESOURCE_IRQ,
83         },
84         {
85                 .start  = RK2818_I2C1_PHYS,
86                 .end    = RK2818_I2C1_PHYS + SZ_4K - 1,
87                 .flags  = IORESOURCE_MEM,
88         },
89 };
90 /*
91  * rk2818 4 uarts device
92  */
93 static struct resource resources_uart0[] = {
94         {
95                 .start  = IRQ_NR_UART0,
96                 .end    = IRQ_NR_UART0,
97                 .flags  = IORESOURCE_IRQ,
98         },
99         {
100                 .start  = RK2818_UART0_PHYS,
101                 .end    = RK2818_UART0_PHYS + SZ_1K - 1,
102                 .flags  = IORESOURCE_MEM,
103         },
104 };
105 static struct resource resources_uart1[] = {
106         {
107                 .start  = IRQ_NR_UART1,
108                 .end    = IRQ_NR_UART1,
109                 .flags  = IORESOURCE_IRQ,
110         },
111         {
112                 .start  = RK2818_UART1_PHYS,
113                 .end    = RK2818_UART1_PHYS + SZ_1K - 1,
114                 .flags  = IORESOURCE_MEM,
115         },
116 };
117 static struct resource resources_uart2[] = {
118         {
119                 .start  = IRQ_NR_UART2,
120                 .end    = IRQ_NR_UART2,
121                 .flags  = IORESOURCE_IRQ,
122         },
123         {
124                 .start  = RK2818_UART2_PHYS,
125                 .end    = RK2818_UART2_PHYS + SZ_1K - 1,
126                 .flags  = IORESOURCE_MEM,
127         },
128 };
129 static struct resource resources_uart3[] = {
130         {
131                 .start  = IRQ_NR_UART3,
132                 .end    = IRQ_NR_UART3,
133                 .flags  = IORESOURCE_IRQ,
134         },
135         {
136                 .start  = RK2818_UART3_PHYS,
137                 .end    = RK2818_UART3_PHYS + SZ_1K - 1,
138                 .flags  = IORESOURCE_MEM,
139         },
140 };
141 /* sdmmc */
142 struct platform_device rk2818_device_sdmmc0 = {
143         .name                   = "rk2818_sdmmc",
144         .id                             = 0,
145         .num_resources  = ARRAY_SIZE(resources_sdmmc0),
146         .resource               = resources_sdmmc0,
147         .dev                    = {
148                 .platform_data = &default_sdmmc0_data,
149         },
150 };
151 struct platform_device rk2818_device_sdmmc1 = {
152         .name                   = "rk2818_sdmmc",
153         .id                             = 1,
154         .num_resources  = ARRAY_SIZE(resources_sdmmc1),
155         .resource               = resources_sdmmc1,
156         .dev                    = {
157                 .platform_data = &default_sdmmc1_data,
158         },
159 };
160
161 struct platform_device rk2818_device_i2c0 = {
162         .name   = "rk2818_i2c",
163         .id     = 0,
164         .num_resources  = ARRAY_SIZE(resources_i2c0),
165         .resource       = resources_i2c0,
166         .dev                    = {
167                 .platform_data = &default_i2c0_data,
168         },
169 };
170 struct platform_device rk2818_device_i2c1 = {
171         .name   = "rk2818_i2c",
172         .id     = 1,
173         .num_resources  = ARRAY_SIZE(resources_i2c1),
174         .resource       = resources_i2c1,
175         .dev                    = {
176                 .platform_data = &default_i2c1_data,
177         },
178 };
179 struct platform_device rk2818_device_i2c2 = {
180         .name   = "fpga_i2c",
181         .id     = 2,    
182         .dev                    = {
183                 .platform_data = &default_i2c2_data,
184         },
185 };
186 struct platform_device rk2818_device_i2c3 = {
187         .name   = "fpga_i2c",
188         .id     = 3,    
189         .dev                    = {
190                 .platform_data = &default_i2c3_data,
191         },
192 };
193 struct platform_device rk2818_device_uart0 = {
194         .name   = "rk2818_serial",
195         .id     = 0,
196         .num_resources  = ARRAY_SIZE(resources_uart0),
197         .resource       = resources_uart0,
198         .dev = {
199                 .platform_data = &rk2818_serial0_platdata,
200         },
201 };
202 struct platform_device rk2818_device_uart1 = {
203         .name   = "rk2818_serial",
204         .id     = 1,
205         .num_resources  = ARRAY_SIZE(resources_uart1),
206         .resource       = resources_uart1,
207 };
208 struct platform_device rk2818_device_uart2 = {
209         .name   = "rk2818_serial",
210         .id     = 2,
211         .num_resources  = ARRAY_SIZE(resources_uart2),
212         .resource       = resources_uart2,
213 };
214 struct platform_device rk2818_device_uart3 = {
215         .name   = "rk2818_serial",
216         .id     = 3,
217         .num_resources  = ARRAY_SIZE(resources_uart3),
218         .resource       = resources_uart3,
219 };
220
221 /*
222  * rk2818 spi master device
223  */
224 static struct resource resources_spim[] = {
225         {
226                 .start  = IRQ_NR_SPIM,
227                 .end    = IRQ_NR_SPIM,
228                 .flags  = IORESOURCE_IRQ,
229         },
230         {
231                 .start  = RK2818_SPIMASTER_PHYS,
232                 .end    = RK2818_SPIMASTER_PHYS + SZ_4K - 1,
233                 .flags  = IORESOURCE_MEM,
234         },
235 };
236 struct platform_device rk2818_device_spim = {
237         .name   = "rk2818_spim",
238         .id     = 0,
239         .num_resources  = ARRAY_SIZE(resources_spim),
240         .resource       = resources_spim,
241         .dev                    = {
242                 .platform_data  = &rk2818_spi_platdata,
243         },
244 };
245
246 /* rk2818 fb resource */
247 static struct resource rk2818_fb_resource[] = {
248         [0] = {
249                 .start = RK2818_LCDC_PHYS,
250                 .end   = RK2818_LCDC_PHYS + RK2818_LCDC_SIZE - 1,
251                 .flags = IORESOURCE_MEM,
252         },
253         [1] = {
254                 .start = IRQ_NR_LCDC,
255                 .end   = IRQ_NR_LCDC,
256                 .flags = IORESOURCE_IRQ,
257         },      
258 };
259
260 /*platform_device*/
261 extern struct rk2818_fb_mach_info rk2818_fb_mach_info;
262
263 struct platform_device rk2818_device_fb = {
264         .name             = "rk2818-fb",
265         .id               = 4,
266         .num_resources    = ARRAY_SIZE(rk2818_fb_resource),
267         .resource         = rk2818_fb_resource,
268         .dev            = {
269                 .platform_data  = &rk2818_fb_mach_info,
270         }
271 };
272
273 /***********************************************************
274 *         backlight
275 *       author :nzy zhongyw
276 *       data:2010-05-18
277 ***************************************************************/
278 struct platform_device rk2818_device_backlight = {
279                 .name   = "rk2818_backlight",
280                 .id     = -1,
281         .dev    = {
282            .platform_data  = &rk2818_bl_info,
283         }
284 };
285
286 /* RK2818 Camera :  ddl@rock-chips.com  */
287 #ifdef CONFIG_VIDEO_RK2818
288
289 static struct resource rk2818_camera_resource[] = {
290         [0] = {
291                 .start = RK2818_VIP_PHYS,
292                 .end   = RK2818_VIP_PHYS + RK2818_VIP_SIZE - 1,
293                 .flags = IORESOURCE_MEM,
294         },
295         [1] = {
296                 .start = IRQ_NR_VIP,
297                 .end   = IRQ_NR_VIP,
298                 .flags = IORESOURCE_IRQ,
299         },
300 };
301
302 static u64 rockchip_device_camera_dmamask = 0xffffffffUL;
303
304 /*platform_device : */
305 struct platform_device rk2818_device_camera = {
306         .name             = RK28_CAM_DRV_NAME,
307         .id               = RK28_CAM_PLATFORM_DEV_ID,               /* This is used to put cameras on this interface */
308         .num_resources    = ARRAY_SIZE(rk2818_camera_resource),
309         .resource         = rk2818_camera_resource,
310         .dev            = {
311                 .dma_mask = &rockchip_device_camera_dmamask,
312                 .coherent_dma_mask = 0xffffffffUL,
313                 .platform_data  = &rk28_camera_platform_data,
314         }
315 };
316
317 /*platform_device : soc-camera need  */
318 struct platform_device rk2818_soc_camera_pdrv = {
319         .name   = "soc-camera-pdrv",
320         .id     = -1,
321         .dev    = {
322                 .init_name = "ov2655",
323                 .platform_data = &rk2818_iclink,
324         },
325 };
326 #endif 
327
328 /*ADC*/
329 static struct resource rk2818_adc_resource[] = {
330         {
331                 .start = IRQ_NR_ADC,
332                 .end   = IRQ_NR_ADC,
333                 .flags = IORESOURCE_IRQ,
334         },
335         {
336                 .start = RK2818_ADC_PHYS,
337                 .end   = RK2818_ADC_PHYS + RK2818_ADC_SIZE - 1,
338                 .flags = IORESOURCE_MEM,
339         },
340
341 };
342
343 struct platform_device rk2818_device_adc = {
344         .name             = "rk2818-adc",
345         .id               = -1,
346         .num_resources    = ARRAY_SIZE(rk2818_adc_resource),
347         .resource         = rk2818_adc_resource,
348 };
349
350
351 struct platform_device rk2818_device_adckey = {
352         .name           = "rk2818-adckey",
353         .id             = -1,
354         .dev.parent     = &rk2818_device_adc.dev,
355         .dev.platform_data = &rk2818_adckey_platdata,
356 };
357
358 /*
359  *rk2818 i2s
360  */
361 static struct resource resources_i2s[] = {
362         {
363                 .start  = IRQ_NR_I2S,
364                 .end    = IRQ_NR_I2S,
365                 .flags  = IORESOURCE_IRQ,
366         },
367         {
368                 .start  = RK2818_I2S_PHYS,
369                 .end    = RK2818_I2S_PHYS + SZ_8K - 1,
370                 .flags  = IORESOURCE_MEM,
371         },
372 };
373 struct platform_device rk2818_device_i2s = {
374         .name   = "rk2818_i2s",
375         .id     = 0,
376         .num_resources  = ARRAY_SIZE(resources_i2s),
377         .resource       = resources_i2s,
378         .dev = {
379                 .platform_data = &rk2818_i2s_platdata,
380         },
381 };
382
383 struct platform_device rk2818_device_battery = {
384                 .name   = "rk2818-battery",
385                 .id     = -1,
386                 .dev = {
387                         .platform_data = &rk2818_battery_platdata,
388                 },
389 };
390
391 /*
392  * rk2818 dsp device
393  */
394  static struct resource resources_dsp[] = {
395         [0] = {
396                 .start = RK2818_DSP_PHYS,
397                 .end   = RK2818_DSP_PHYS + 0x5fffff,
398                 .flags = IORESOURCE_DMA,
399         },
400         [1] = {
401                 .start  = IRQ_NR_PIUCMD,
402                 .end    = IRQ_NR_PIUCMD,
403                 .flags  = IORESOURCE_IRQ,
404         },
405         [2] = {
406                 .start  = IRQ_NR_DSPSWI,
407                 .end    = IRQ_NR_DSPSWI,
408                 .flags  = IORESOURCE_IRQ,
409         },
410 };
411 static u64 rk2818_device_dsp_dmamask = 0xffffffffUL;
412 struct platform_device rk2818_device_dsp = {
413         .name             = "rk28-dsp",
414         .id               = 0,
415         .num_resources    = ARRAY_SIZE(resources_dsp),
416         .resource         = resources_dsp,
417         .dev              = {
418                 .dma_mask = &rk2818_device_dsp_dmamask,
419                 .coherent_dma_mask = 0xffffffffUL
420         }
421 };
422
423 #ifdef CONFIG_BT
424 struct platform_device rk2818_device_rfkill = {
425         .name = "rkbt_rfkill",
426         .id = -1,
427 };
428 #endif
429
430 #if defined(CONFIG_ANDROID_PMEM)
431
432 static struct android_pmem_platform_data pmem_pdata = {
433         .name = "pmem",
434         .no_allocator = 1,
435         .cached = 0,
436         .start = 0x6f000000,
437         .size =  0x1000000,
438 };
439
440 static struct android_pmem_platform_data pmem_pdata_dsp = {
441         .name = "pmem-dsp",
442         .no_allocator = 0,                  
443         .cached = 0,
444     .start = 0x6db00000,
445         .size =  0x1500000,
446 };
447
448 struct platform_device rk2818_device_pmem = {
449         .name = "android_pmem",
450         .id = 0,
451         .dev = { .platform_data = &pmem_pdata },
452 };
453
454 struct platform_device rk2818_device_pmem_dsp = {
455         .name = "android_pmem",
456         .id = 1,
457         .dev = { .platform_data = &pmem_pdata_dsp },
458 };
459
460 #endif
461 #if defined(CONFIG_MTD_NAND_RK2818)  
462 static struct resource nand_resources[] = {
463         {
464                 .start  = RK2818_NANDC_PHYS,
465                 .end    =       RK2818_NANDC_PHYS+RK2818_NANDC_SIZE -1,
466                 .flags  = IORESOURCE_MEM,
467         }
468 };
469
470 struct platform_device rk2818_nand_device = {
471         .name   = "rk2818-nand",
472         .id             =  -1, 
473         .resource       = nand_resources,
474         .num_resources= ARRAY_SIZE(nand_resources),
475         .dev    = {
476                 .platform_data= &rk2818_nand_data,
477         },
478         
479 };
480
481 #endif
482 /*DWC_OTG*/
483 static struct resource dwc_otg_resource[] = {
484         {
485                 .start = IRQ_NR_OTG,
486                 .end   = IRQ_NR_OTG,
487                 .flags = IORESOURCE_IRQ,
488         },
489         {
490                 .start = RK2818_USBOTG_PHYS,
491                 .end   = RK2818_USBOTG_PHYS + RK2818_USBOTG_SIZE - 1,
492                 .flags = IORESOURCE_MEM,
493         },
494
495 };
496
497 struct platform_device rk2818_device_dwc_otg = {
498         .name             = "dwc_otg",
499         .id               = -1,
500         .num_resources    = ARRAY_SIZE(dwc_otg_resource),
501         .resource         = dwc_otg_resource,
502 };
503 #ifdef CONFIG_RK2818_HOST11
504 static struct resource rk2818_host11_resource[] = {
505         {
506                 .start = IRQ_NR_USB_HOST,
507                 .end   = IRQ_NR_USB_HOST,
508                 .flags = IORESOURCE_IRQ,
509         },
510         {
511                 .start = RK2818_USBHOST_PHYS,
512                 .end   = RK2818_USBHOST_PHYS + RK2818_USBHOST_SIZE - 1,
513                 .flags = IORESOURCE_MEM,
514         },
515
516 };
517
518 struct platform_device rk2818_device_host11 = {
519         .name             = "rk2818_host11",
520         .id               = -1,
521         .num_resources    = ARRAY_SIZE(rk2818_host11_resource),
522         .resource         = rk2818_host11_resource,
523 };
524 #endif
525 static char *usb_functions_rockchip[] = {
526         "usb_mass_storage",
527 };
528
529 static char *usb_functions_rockchip_adb[] = {
530         "usb_mass_storage",
531         "adb",
532 };
533
534 static char *usb_functions_rndis_rockchip[] = {
535         "rndis",
536         "usb_mass_storage",
537 };
538
539 static char *usb_functions_rndis_rockchip_adb[] = {
540         "rndis",
541         "usb_mass_storage",
542         "adb",
543 };
544
545 #ifdef CONFIG_USB_ANDROID_DIAG
546 static char *usb_functions_adb_diag[] = {
547         "usb_mass_storage",
548         "adb",
549         "diag",
550 };
551 #endif
552
553 static char *usb_functions_all[] = {
554 #ifdef CONFIG_USB_ANDROID_RNDIS
555         "rndis",
556 #endif
557         "usb_mass_storage",
558 #ifdef CONFIG_USB_ANDROID_ADB
559         "adb",
560 #endif
561 #ifdef CONFIG_USB_ANDROID_ACM
562         "acm",
563 #endif
564 #ifdef CONFIG_USB_ANDROID_DIAG
565         "diag",
566 #endif
567 };
568
569 static struct android_usb_product usb_products[] = {
570         {
571                 .product_id     = 0x2810,//0x0c02,//0x4e11,
572                 .num_functions  = ARRAY_SIZE(usb_functions_rockchip),
573                 .functions      = usb_functions_rockchip,
574         },
575         {
576                 .product_id     = 0x4e12,
577                 .num_functions  = ARRAY_SIZE(usb_functions_rockchip_adb),
578                 .functions      = usb_functions_rockchip_adb,
579         },
580         {
581                 .product_id     = 0x4e13,
582                 .num_functions  = ARRAY_SIZE(usb_functions_rndis_rockchip),
583                 .functions      = usb_functions_rndis_rockchip,
584         },
585         {
586                 .product_id     = 0x4e14,
587                 .num_functions  = ARRAY_SIZE(usb_functions_rndis_rockchip_adb),
588                 .functions      = usb_functions_rndis_rockchip_adb,
589         },
590 #ifdef CONFIG_USB_ANDROID_DIAG
591         {
592                 .product_id     = 0x4e17,
593                 .num_functions  = ARRAY_SIZE(usb_functions_adb_diag),
594                 .functions      = usb_functions_adb_diag,
595         },
596 #endif
597 };
598
599 static struct android_usb_platform_data android_usb_pdata = {
600         .vendor_id      = 0x2207,//0x0bb4,//0x18d1,
601         .product_id     = 0x2810,//0x4e11,
602         .version        = 0x0100,
603         .product_name           = "rk2818 sdk",
604         .manufacturer_name      = "RockChip",
605         .num_products = ARRAY_SIZE(usb_products),
606         .products = usb_products,
607         .num_functions = ARRAY_SIZE(usb_functions_all),
608         .functions = usb_functions_all,
609 };
610
611 //static 
612 struct platform_device android_usb_device = {
613         .name   = "android_usb",
614         .id             = -1,
615         .dev            = {
616                 .platform_data = &android_usb_pdata,
617         },
618 };
619
620 static struct usb_mass_storage_platform_data mass_storage_pdata = {
621         .nluns          = 2,
622         .vendor         = "RockChip",
623         .product        = "rk2818 sdk",
624         .release        = 0x0100,
625 };
626
627 //static 
628 struct platform_device usb_mass_storage_device = {
629         .name   = "usb_mass_storage",
630         .id     = -1,
631         .dev    = {
632                 .platform_data = &mass_storage_pdata,
633         },
634 };
635
636 #if CONFIG_ANDROID_TIMED_GPIO
637 struct platform_device rk28_device_vibrator ={
638         .name = "timed-gpio",
639         .id = -1,
640         .dev = {
641                 .platform_data = &rk28_vibrator_info,
642                 },
643
644 };
645 #endif 
646