Merge commit 'origin/develop' into develop
[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
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 <linux/dm9000.h>
31 #include <mach/gpio.h>
32 #include <mach/rk2818_nand.h>
33 static struct resource resources_sdmmc0[] = {
34         {
35                 .start  = IRQ_NR_SDMMC0,
36                 .end    = IRQ_NR_SDMMC0,
37                 .flags  = IORESOURCE_IRQ,
38         },
39         {
40                 .start  = RK2818_SDMMC0_PHYS,
41                 .end    = RK2818_SDMMC0_PHYS + SZ_8K -1,
42                 .flags  = IORESOURCE_MEM,
43         }
44 };
45 static struct resource resources_sdmmc1[] = {
46         {
47                 .start  = IRQ_NR_SDMMC1,
48                 .end    = IRQ_NR_SDMMC1,
49                 .flags  = IORESOURCE_IRQ,
50         },
51         {
52                 .start  = RK2818_SDMMC1_PHYS,
53                 .end    = RK2818_SDMMC1_PHYS + SZ_8K -1,
54                 .flags  = IORESOURCE_MEM,
55         }
56 };
57
58
59 static struct resource resources_i2c0[] = {
60         {
61                 .start  = IRQ_NR_I2C0,
62                 .end    = IRQ_NR_I2C0,
63                 .flags  = IORESOURCE_IRQ,
64         },
65         {
66                 .start  = RK2818_I2C0_PHYS,
67                 .end    = RK2818_I2C0_PHYS + SZ_4K - 1,
68                 .flags  = IORESOURCE_MEM,
69         },
70 };
71 static struct resource resources_i2c1[] = {
72         {
73                 .start  = IRQ_NR_I2C1,
74                 .end    = IRQ_NR_I2C1,
75                 .flags  = IORESOURCE_IRQ,
76         },
77         {
78                 .start  = RK2818_I2C1_PHYS,
79                 .end    = RK2818_I2C1_PHYS + SZ_4K - 1,
80                 .flags  = IORESOURCE_MEM,
81         },
82 };
83 /*
84  * rk2818 4 uarts device
85  */
86 static struct resource resources_uart0[] = {
87         {
88                 .start  = IRQ_NR_UART0,
89                 .end    = IRQ_NR_UART0,
90                 .flags  = IORESOURCE_IRQ,
91         },
92         {
93                 .start  = RK2818_UART0_PHYS,
94                 .end    = RK2818_UART0_PHYS + SZ_1K - 1,
95                 .flags  = IORESOURCE_MEM,
96         },
97 };
98 static struct resource resources_uart1[] = {
99         {
100                 .start  = IRQ_NR_UART1,
101                 .end    = IRQ_NR_UART1,
102                 .flags  = IORESOURCE_IRQ,
103         },
104         {
105                 .start  = RK2818_UART1_PHYS,
106                 .end    = RK2818_UART1_PHYS + SZ_1K - 1,
107                 .flags  = IORESOURCE_MEM,
108         },
109 };
110 static struct resource resources_uart2[] = {
111         {
112                 .start  = IRQ_NR_UART2,
113                 .end    = IRQ_NR_UART2,
114                 .flags  = IORESOURCE_IRQ,
115         },
116         {
117                 .start  = RK2818_UART2_PHYS,
118                 .end    = RK2818_UART2_PHYS + SZ_1K - 1,
119                 .flags  = IORESOURCE_MEM,
120         },
121 };
122 static struct resource resources_uart3[] = {
123         {
124                 .start  = IRQ_NR_UART3,
125                 .end    = IRQ_NR_UART3,
126                 .flags  = IORESOURCE_IRQ,
127         },
128         {
129                 .start  = RK2818_UART3_PHYS,
130                 .end    = RK2818_UART3_PHYS + SZ_1K - 1,
131                 .flags  = IORESOURCE_MEM,
132         },
133 };
134 /* sdmmc */
135 struct platform_device rk2818_device_sdmmc0 = {
136         .name                   = "rk2818_sdmmc",
137         .id                             = 0,
138         .num_resources  = ARRAY_SIZE(resources_sdmmc0),
139         .resource               = resources_sdmmc0,
140         .dev                    = {
141                 .platform_data = &default_sdmmc0_data,
142         },
143 };
144 struct platform_device rk2818_device_sdmmc1 = {
145         .name                   = "rk2818_sdmmc",
146         .id                             = 1,
147         .num_resources  = ARRAY_SIZE(resources_sdmmc1),
148         .resource               = resources_sdmmc1,
149         .dev                    = {
150                 .platform_data = &default_sdmmc1_data,
151         },
152 };
153
154 struct platform_device rk2818_device_i2c0 = {
155         .name   = "rk2818_i2c",
156         .id     = 0,
157         .num_resources  = ARRAY_SIZE(resources_i2c0),
158         .resource       = resources_i2c0,
159         .dev                    = {
160                 .platform_data = &default_i2c0_data,
161         },
162 };
163 struct platform_device rk2818_device_i2c1 = {
164         .name   = "rk2818_i2c",
165         .id     = 1,
166         .num_resources  = ARRAY_SIZE(resources_i2c1),
167         .resource       = resources_i2c1,
168         .dev                    = {
169                 .platform_data = &default_i2c1_data,
170         },
171 };
172 struct platform_device rk2818_device_i2c2 = {
173         .name   = "fpga_i2c",
174         .id     = 2,    
175         .dev                    = {
176                 .platform_data = &default_i2c2_data,
177         },
178 };
179 struct platform_device rk2818_device_i2c3 = {
180         .name   = "fpga_i2c",
181         .id     = 3,    
182         .dev                    = {
183                 .platform_data = &default_i2c3_data,
184         },
185 };
186 struct platform_device rk2818_device_uart0 = {
187         .name   = "rk2818_serial",
188         .id     = 0,
189         .num_resources  = ARRAY_SIZE(resources_uart0),
190         .resource       = resources_uart0,
191 };
192 struct platform_device rk2818_device_uart1 = {
193         .name   = "rk2818_serial",
194         .id     = 1,
195         .num_resources  = ARRAY_SIZE(resources_uart1),
196         .resource       = resources_uart1,
197 };
198 struct platform_device rk2818_device_uart2 = {
199         .name   = "rk2818_serial",
200         .id     = 2,
201         .num_resources  = ARRAY_SIZE(resources_uart2),
202         .resource       = resources_uart2,
203 };
204 struct platform_device rk2818_device_uart3 = {
205         .name   = "rk2818_serial",
206         .id     = 3,
207         .num_resources  = ARRAY_SIZE(resources_uart3),
208         .resource       = resources_uart3,
209 };
210
211 /*
212  * rk2818 spi master device
213  */
214 static struct resource resources_spim[] = {
215         {
216                 .start  = IRQ_NR_SPIM,
217                 .end    = IRQ_NR_SPIM,
218                 .flags  = IORESOURCE_IRQ,
219         },
220         {
221                 .start  = RK2818_SPIMASTER_PHYS,
222                 .end    = RK2818_SPIMASTER_PHYS + SZ_4K - 1,
223                 .flags  = IORESOURCE_MEM,
224         },
225 };
226 struct platform_device rk2818_device_spim = {
227         .name   = "rk2818_spim",
228         .id     = 0,
229         .num_resources  = ARRAY_SIZE(resources_spim),
230         .resource       = resources_spim,
231 };
232
233 /* rk2818 fb resource */
234 static struct resource rk2818_fb_resource[] = {
235         [0] = {
236                 .start = RK2818_LCDC_PHYS,
237                 .end   = RK2818_LCDC_PHYS + RK2818_LCDC_SIZE - 1,
238                 .flags = IORESOURCE_MEM,
239         },
240         [1] = {
241                 .start = IRQ_NR_LCDC,
242                 .end   = IRQ_NR_LCDC,
243                 .flags = IORESOURCE_IRQ,
244         },      
245 };
246
247 /*platform_device*/
248 extern struct rk2818_fb_mach_info rk2818_fb_mach_info;
249
250 struct platform_device rk2818_device_fb = {
251         .name             = "rk2818-fb",
252         .id               = 4,
253         .num_resources    = ARRAY_SIZE(rk2818_fb_resource),
254         .resource         = rk2818_fb_resource,
255         .dev            = {
256                 .platform_data  = &rk2818_fb_mach_info,
257         }
258 };
259
260 /***********************************************************
261 *         backlight
262 *       author :nzy zhongyw
263 *       data:2010-05-18
264 ***************************************************************/
265 extern struct rk2818bl_info rk2818_bl_info;
266
267 struct platform_device rk2818_device_backlight = {
268                 .name   = "rk2818_backlight",
269                 .id     = -1,
270         .dev    = {
271            .platform_data  = &rk2818_bl_info,
272         }
273 };
274
275 //net device
276 /* DM9000 */
277 #ifdef CONFIG_DM9000
278 static struct resource dm9k_resource[] = {
279         [0] = {
280                 .start = RK2818_NANDC_PHYS + 0x800 + (1*0x100 + 0x8),    //nand_cs1+nand_cmd
281                 .end   = RK2818_NANDC_PHYS + 0x800 + (1*0x100 + 0x8) + 3,
282                 .flags = IORESOURCE_MEM,
283         },
284         [1] = {
285                 .start = RK2818_NANDC_PHYS + 0x800 + (1*0x100 + 0x4),   //nand_cs1+nand_data
286                 .end   = RK2818_NANDC_PHYS + 0x800 + (1*0x100 + 0x4) + 3,
287                 .flags = IORESOURCE_MEM,
288         },
289         [2] = {
290                 .start = RK2818_PIN_PE2,        //use pe2 as interrupt
291                 .end   = RK2818_PIN_PE2,
292                 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
293         }
294
295 };
296
297 /* for the moment we limit ourselves to 8bit IO until some
298  * better IO routines can be written and tested
299 */
300
301 static struct dm9000_plat_data dm9k_platdata = {
302         .flags          = DM9000_PLATF_8BITONLY,
303 };
304
305 struct platform_device rk2818_device_dm9k = {
306         .name           = "dm9000",
307         .id             = 0,
308         .num_resources  = ARRAY_SIZE(dm9k_resource),
309         .resource       = dm9k_resource,
310         .dev            = {
311                 .platform_data = &dm9k_platdata,
312         }
313 };
314 #endif
315
316 /*ADC*/
317 static struct resource rk2818_adc_resource[] = {
318         {
319                 .start = IRQ_NR_ADC,
320                 .end   = IRQ_NR_ADC,
321                 .flags = IORESOURCE_IRQ,
322         },
323         {
324                 .start = RK2818_ADC_PHYS,
325                 .end   = RK2818_ADC_PHYS + RK2818_ADC_SIZE - 1,
326                 .flags = IORESOURCE_MEM,
327         },
328
329 };
330
331 struct platform_device rk2818_device_adc = {
332         .name             = "rk2818-adc",
333         .id               = -1,
334         .num_resources    = ARRAY_SIZE(rk2818_adc_resource),
335         .resource         = rk2818_adc_resource,
336 };
337
338
339 struct platform_device rk2818_device_adckey = {
340         .name           = "rk2818-adckey",
341         .id             = -1,
342         .dev.parent     = &rk2818_device_adc.dev,
343 };
344 /*
345  *rk2818 i2s
346  */
347 static struct resource resources_i2s[] = {
348         {
349                 .start  = IRQ_NR_I2S,
350                 .end    = IRQ_NR_I2S,
351                 .flags  = IORESOURCE_IRQ,
352         },
353         {
354                 .start  = RK2818_I2S_PHYS,
355                 .end    = RK2818_I2S_PHYS + SZ_8K - 1,
356                 .flags  = IORESOURCE_MEM,
357         },
358 };
359 struct platform_device rk2818_device_i2s = {
360         .name   = "rk2818_i2s",
361         .id     = 0,
362         .num_resources  = ARRAY_SIZE(resources_i2s),
363         .resource       = resources_i2s,
364 };
365
366 struct platform_device rk2818_device_battery = {
367                 .name   = "rk2818-battery",
368                 .id     = -1,
369 };
370
371 /*
372  * rk2818 dsp device
373  */
374  static struct resource resources_dsp[] = {
375         [0] = {
376                 .start = RK2818_DSP_PHYS,
377                 .end   = RK2818_DSP_PHYS + 0x5fffff,
378                 .flags = IORESOURCE_DMA,
379         },
380         [1] = {
381                 .start  = IRQ_NR_PIUCMD,
382                 .end    = IRQ_NR_PIUCMD,
383                 .flags  = IORESOURCE_IRQ,
384         },
385         [2] = {
386                 .start  = IRQ_NR_DSPSWI,
387                 .end    = IRQ_NR_DSPSWI,
388                 .flags  = IORESOURCE_IRQ,
389         },
390 };
391 static u64 rk2818_device_dsp_dmamask = 0xffffffffUL;
392 struct platform_device rk2818_device_dsp = {
393         .name             = "rk28-dsp",
394         .id               = 0,
395         .num_resources    = ARRAY_SIZE(resources_dsp),
396         .resource         = resources_dsp,
397         .dev              = {
398                 .dma_mask = &rk2818_device_dsp_dmamask,
399                 .coherent_dma_mask = 0xffffffffUL
400         }
401 };
402
403
404
405 #if defined(CONFIG_ANDROID_PMEM)
406
407 static struct android_pmem_platform_data pmem_pdata = {
408         .name = "pmem",
409         .no_allocator = 1,
410         .cached = 0,
411         .start = 0x6f000000,
412         .size =  0x1000000,
413 };
414
415 static struct android_pmem_platform_data pmem_pdata_dsp = {
416         .name = "pmem-dsp",
417         .no_allocator = 1,
418         .cached = 0,
419     .start = 0x6db00000,
420         .size =  0x1500000,
421 };
422
423 struct platform_device rk2818_device_pmem = {
424         .name = "android_pmem",
425         .id = 0,
426         .dev = { .platform_data = &pmem_pdata },
427 };
428
429 struct platform_device rk2818_device_pmem_dsp = {
430         .name = "android_pmem",
431         .id = 1,
432         .dev = { .platform_data = &pmem_pdata_dsp },
433 };
434
435 #endif
436 #if defined(CONFIG_MTD_NAND_RK2818)  
437 static struct resource nand_resources[] = {
438         {
439                 .start  = RK2818_NANDC_PHYS,
440                 .end    =       RK2818_NANDC_PHYS+RK2818_NANDC_SIZE -1,
441                 .flags  = IORESOURCE_MEM,
442         }
443 };
444 static struct rk2818_nand_platform_data rk2818_nand_data = {
445         .width          = 1,     /* data bus width in bytes */
446         .hw_ecc         = 1,     /* hw ecc 0: soft ecc */
447          .num_flash    = 1,
448 };
449 struct platform_device rk2818_nand_device = {
450         .name   = "rk2818-nand",
451         .id             =  -1, 
452         .resource       = nand_resources,
453         .num_resources= ARRAY_SIZE(nand_resources),
454         .dev    = {
455                 .platform_data= &rk2818_nand_data,
456         },
457         
458 };
459
460 #endif
461 /*DWC_OTG*/
462 static struct resource dwc_otg_resource[] = {
463         {
464                 .start = IRQ_NR_OTG,
465                 .end   = IRQ_NR_OTG,
466                 .flags = IORESOURCE_IRQ,
467         },
468         {
469                 .start = RK2818_USBOTG_PHYS,
470                 .end   = RK2818_USBOTG_PHYS + RK2818_USBOTG_SIZE - 1,
471                 .flags = IORESOURCE_MEM,
472         },
473
474 };
475
476 struct platform_device rk2818_device_dwc_otg = {
477         .name             = "dwc_otg",
478         .id               = -1,
479         .num_resources    = ARRAY_SIZE(dwc_otg_resource),
480         .resource         = dwc_otg_resource,
481 };
482 #ifdef CONFIG_RK2818_HOST11
483 static struct resource rk2818_host11_resource[] = {
484         {
485                 .start = IRQ_NR_USB_HOST,
486                 .end   = IRQ_NR_USB_HOST,
487                 .flags = IORESOURCE_IRQ,
488         },
489         {
490                 .start = RK2818_USBHOST_PHYS,
491                 .end   = RK2818_USBHOST_PHYS + RK2818_USBHOST_SIZE - 1,
492                 .flags = IORESOURCE_MEM,
493         },
494
495 };
496
497 struct platform_device rk2818_device_host11 = {
498         .name             = "rk2818_host11",
499         .id               = -1,
500         .num_resources    = ARRAY_SIZE(rk2818_host11_resource),
501         .resource         = rk2818_host11_resource,
502 };
503 #endif
504 static char *usb_functions_rockchip[] = {
505         "usb_mass_storage",
506 };
507
508 static char *usb_functions_rockchip_adb[] = {
509         "usb_mass_storage",
510         "adb",
511 };
512
513 static char *usb_functions_rndis_rockchip[] = {
514         "rndis",
515         "usb_mass_storage",
516 };
517
518 static char *usb_functions_rndis_rockchip_adb[] = {
519         "rndis",
520         "usb_mass_storage",
521         "adb",
522 };
523
524 #ifdef CONFIG_USB_ANDROID_DIAG
525 static char *usb_functions_adb_diag[] = {
526         "usb_mass_storage",
527         "adb",
528         "diag",
529 };
530 #endif
531
532 static char *usb_functions_all[] = {
533 #ifdef CONFIG_USB_ANDROID_RNDIS
534         "rndis",
535 #endif
536         "usb_mass_storage",
537 #ifdef CONFIG_USB_ANDROID_ADB
538         "adb",
539 #endif
540 #ifdef CONFIG_USB_ANDROID_ACM
541         "acm",
542 #endif
543 #ifdef CONFIG_USB_ANDROID_DIAG
544         "diag",
545 #endif
546 };
547
548 static struct android_usb_product usb_products[] = {
549         {
550                 .product_id     = 0x2810,//0x0c02,//0x4e11,
551                 .num_functions  = ARRAY_SIZE(usb_functions_rockchip),
552                 .functions      = usb_functions_rockchip,
553         },
554         {
555                 .product_id     = 0x4e12,
556                 .num_functions  = ARRAY_SIZE(usb_functions_rockchip_adb),
557                 .functions      = usb_functions_rockchip_adb,
558         },
559         {
560                 .product_id     = 0x4e13,
561                 .num_functions  = ARRAY_SIZE(usb_functions_rndis_rockchip),
562                 .functions      = usb_functions_rndis_rockchip,
563         },
564         {
565                 .product_id     = 0x4e14,
566                 .num_functions  = ARRAY_SIZE(usb_functions_rndis_rockchip_adb),
567                 .functions      = usb_functions_rndis_rockchip_adb,
568         },
569 #ifdef CONFIG_USB_ANDROID_DIAG
570         {
571                 .product_id     = 0x4e17,
572                 .num_functions  = ARRAY_SIZE(usb_functions_adb_diag),
573                 .functions      = usb_functions_adb_diag,
574         },
575 #endif
576 };
577
578 static struct android_usb_platform_data android_usb_pdata = {
579         .vendor_id      = 0x2207,//0x0bb4,//0x18d1,
580         .product_id     = 0x2810,//0x4e11,
581         .version        = 0x0100,
582         .product_name           = "rk2818 sdk",
583         .manufacturer_name      = "RockChip",
584         .num_products = ARRAY_SIZE(usb_products),
585         .products = usb_products,
586         .num_functions = ARRAY_SIZE(usb_functions_all),
587         .functions = usb_functions_all,
588 };
589
590 //static 
591 struct platform_device android_usb_device = {
592         .name   = "android_usb",
593         .id             = -1,
594         .dev            = {
595                 .platform_data = &android_usb_pdata,
596         },
597 };
598
599 static struct usb_mass_storage_platform_data mass_storage_pdata = {
600         .nluns          = 2,
601         .vendor         = "RockChip",
602         .product        = "rk2818 sdk",
603         .release        = 0x0100,
604 };
605
606 //static 
607 struct platform_device usb_mass_storage_device = {
608         .name   = "usb_mass_storage",
609         .id     = -1,
610         .dev    = {
611                 .platform_data = &mass_storage_pdata,
612         },
613 };
614
615