touchscreen && spi
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk2818 / board-infosdk.c
1 /* linux/arch/arm/mach-rk2818/board-phonesdk.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/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/input.h>
20 #include <linux/io.h>
21 #include <linux/delay.h>
22 #include <linux/i2c.h>
23 #include <linux/spi/spi.h>
24 #include <linux/mmc/host.h>
25
26 #include <mach/hardware.h>
27 #include <asm/mach-types.h>
28 #include <asm/mach/arch.h>
29 #include <asm/mach/map.h>
30 #include <asm/mach/flash.h>
31
32 #include <mach/irqs.h>
33 #include <mach/board.h>
34 #include <mach/rk2818_iomap.h>
35 #include <mach/iomux.h>
36 #include <mach/gpio.h>
37 #include <mach/rk2818_camera.h>                          /* ddl@rock-chips.com : camera support */
38 #include <mach/rk2818_nand.h>
39
40 #include <linux/mtd/nand.h>
41 #include <linux/mtd/partitions.h>
42 #include <linux/dm9000.h>
43
44 #include <media/soc_camera.h>                               /* ddl@rock-chips.com : camera support */
45
46 #include "devices.h"
47
48 #include "../../../drivers/spi/rk2818_spim.h"
49 #include "../../../drivers/input/touchscreen/xpt2046_ts.h"
50 #include "../../../drivers/staging/android/timed_gpio.h"
51 #include "../../../sound/soc/codecs/wm8994.h"
52
53 /* --------------------------------------------------------------------
54  *  ÉùÃ÷ÁËrk2818_gpioBankÊý×飬²¢¶¨ÒåÁËGPIO¼Ä´æÆ÷×éIDºÍ¼Ä´æÆ÷»ùµØÖ·¡£
55  * -------------------------------------------------------------------- */
56
57 static struct rk2818_gpio_bank rk2818_gpioBank[] = {
58                 {
59                 .id             = RK2818_ID_PIOA,
60                 .offset         = RK2818_GPIO0_BASE,
61                 .clock          = NULL,
62         }, 
63                 {
64                 .id             = RK2818_ID_PIOB,
65                 .offset         = RK2818_GPIO0_BASE,
66                 .clock          = NULL,
67         }, 
68                 {
69                 .id             = RK2818_ID_PIOC,
70                 .offset         = RK2818_GPIO0_BASE,
71                 .clock          = NULL,
72         }, 
73                 {
74                 .id             = RK2818_ID_PIOD,
75                 .offset         = RK2818_GPIO0_BASE,
76                 .clock          = NULL,
77         },
78                 {
79                 .id             = RK2818_ID_PIOE,
80                 .offset         = RK2818_GPIO1_BASE,
81                 .clock          = NULL,
82         },
83                 {
84                 .id             = RK2818_ID_PIOF,
85                 .offset         = RK2818_GPIO1_BASE,
86                 .clock          = NULL,
87         },
88                 {
89                 .id             = RK2818_ID_PIOG,
90                 .offset         = RK2818_GPIO1_BASE,
91                 .clock          = NULL,
92         },
93                 {
94                 .id             = RK2818_ID_PIOH,
95                 .offset         = RK2818_GPIO1_BASE,
96                 .clock          = NULL,
97         }
98 };
99
100 //IOÓ³É䷽ʽÃèÊö £¬Ã¿¸öΪһ¶ÎÏßÐÔÁ¬ÐøÓ³Éä
101 static struct map_desc rk2818_io_desc[] __initdata = {
102
103         {
104                 .virtual        = RK2818_MCDMA_BASE,                                    //ÐéÄâµØÖ·
105                 .pfn            = __phys_to_pfn(RK2818_MCDMA_PHYS),    //ÎïÀíµØÖ·£¬ÐëÓëÒ³±í¶ÔÆë
106                 .length         = RK2818_MCDMA_SIZE,                                                    //³¤¶È
107                 .type           = MT_DEVICE                                                     //Ó³É䷽ʽ
108         },
109         
110         {
111                 .virtual        = RK2818_DWDMA_BASE,                                    
112                 .pfn            = __phys_to_pfn(RK2818_DWDMA_PHYS),    
113                 .length         = RK2818_DWDMA_SIZE,                                            
114                 .type           = MT_DEVICE                                                     
115         },
116         
117         {
118                 .virtual        = RK2818_INTC_BASE,                                     
119                 .pfn            = __phys_to_pfn(RK2818_INTC_PHYS),   
120                 .length         = RK2818_INTC_SIZE,                                     
121                 .type           = MT_DEVICE                                             
122         },
123
124         {
125                 .virtual        = RK2818_NANDC_BASE,                            
126                 .pfn            = __phys_to_pfn(RK2818_NANDC_PHYS),      
127                 .length         = RK2818_NANDC_SIZE,                            
128                 .type           = MT_DEVICE                                     
129         },
130
131         {
132                 .virtual        = RK2818_SDRAMC_BASE,
133                 .pfn            = __phys_to_pfn(RK2818_SDRAMC_PHYS),
134                 .length         = RK2818_SDRAMC_SIZE,
135                 .type           = MT_DEVICE
136         },
137
138         {
139                 .virtual        = RK2818_ARMDARBITER_BASE,                                      
140                 .pfn            = __phys_to_pfn(RK2818_ARMDARBITER_PHYS),    
141                 .length         = RK2818_ARMDARBITER_SIZE,                                              
142                 .type           = MT_DEVICE                                                     
143         },
144         
145         {
146                 .virtual        = RK2818_APB_BASE,
147                 .pfn            = __phys_to_pfn(RK2818_APB_PHYS),
148                 .length         = 0xa0000,                     
149                 .type           = MT_DEVICE
150         },
151         
152         {
153                 .virtual        = RK2818_WDT_BASE,
154                 .pfn            = __phys_to_pfn(RK2818_WDT_PHYS),
155                 .length         = 0xa0000,                      ///apb bus i2s i2c spi no map in this
156                 .type           = MT_DEVICE
157         },
158 };
159 /*****************************************************************************************
160  * SDMMC devices
161  *author: kfx
162 *****************************************************************************************/
163 static int rk2818_sdmmc0_io_init(void)
164 {
165         rk2818_mux_api_set(GPIOF3_APWM1_MMC0DETN_NAME, IOMUXA_SDMMC1_DETECT_N);
166         rk2818_mux_api_set(GPIOH_MMC0D_SEL_NAME, IOMUXA_SDMMC0_DATA123);
167         rk2818_mux_api_set(GPIOH_MMC0_SEL_NAME, IOMUXA_SDMMC0_CMD_DATA0_CLKOUT);
168     return 0;
169 }
170
171 static int rk2818_sdmmc1_io_init(void)
172 {
173         rk2818_mux_api_set(GPIOG_MMC1_SEL_NAME, IOMUXA_SDMMC1_CMD_DATA0_CLKOUT);
174         rk2818_mux_api_set(GPIOG_MMC1D_SEL_NAME, IOMUXA_SDMMC1_DATA123);
175
176     return 0;
177 }
178 #define CONFIG_SDMMC0_USE_DMA
179 #define CONFIG_SDMMC1_USE_DMA
180 struct rk2818_sdmmc_platform_data default_sdmmc0_data = {
181         .host_ocr_avail = (MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
182                                            MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33| 
183                                            MMC_VDD_33_34|MMC_VDD_34_35| MMC_VDD_35_36),
184         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
185         .io_init = rk2818_sdmmc0_io_init,
186         .no_detect = 0,
187         .dma_name = "sd_mmc",
188 #ifdef CONFIG_SDMMC0_USE_DMA
189         .use_dma  = 1,
190 #else
191         .use_dma = 0,
192 #endif
193 };
194 struct rk2818_sdmmc_platform_data default_sdmmc1_data = {
195         .host_ocr_avail = (MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|
196                                            MMC_VDD_29_30|MMC_VDD_30_31|MMC_VDD_31_32|
197                                            MMC_VDD_32_33|MMC_VDD_33_34),
198         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_SDIO_IRQ|
199                                    MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
200         .io_init = rk2818_sdmmc1_io_init,
201         .no_detect = 1,
202         .dma_name = "sdio",
203 #ifdef CONFIG_SDMMC1_USE_DMA
204         .use_dma  = 1,
205 #else
206         .use_dma = 0,
207 #endif
208 };
209
210 /*****************************************************************************************
211  * extern gpio devices
212  *author: xxx
213  *****************************************************************************************/
214 #if defined (CONFIG_GPIO_PCA9554)
215 struct rk2818_gpio_expander_info  extern_gpio_settinginfo[] = {
216         {
217                 .gpio_num               =RK2818_PIN_PI0,
218                 .pin_type           = GPIO_IN,
219                 //.pin_value                    =GPIO_HIGH,
220          },
221
222         {
223                 .gpio_num               =RK2818_PIN_PI4,// tp3
224                 .pin_type           = GPIO_IN,
225                 //.pin_value                    =GPIO_HIGH,
226          },
227          
228          {
229                 .gpio_num               =RK2818_PIN_PI5,//tp4
230                 .pin_type           = GPIO_IN,
231                 //.pin_value                    =GPIO_HIGH,
232          },
233          {
234                 .gpio_num               =RK2818_PIN_PI6,//tp2
235                 .pin_type           = GPIO_OUT,
236                 //.pin_value                    =GPIO_HIGH,
237          },
238          {
239                 .gpio_num               =RK2818_PIN_PI7,//tp1
240                 .pin_type           = GPIO_OUT,
241                 .pin_value                      =GPIO_HIGH,
242          },
243
244
245                 
246 };
247
248 struct pca9554_platform_data rk2818_pca9554_data={
249         .gpio_base=GPIO_EXPANDER_BASE,
250         .gpio_pin_num=CONFIG_EXPANDED_GPIO_NUM,
251         .gpio_irq_start=NR_AIC_IRQS + 2*NUM_GROUP,
252         .irq_pin_num=CONFIG_EXPANDED_GPIO_IRQ_NUM,
253         .pca9954_irq_pin=RK2818_PIN_PE2,
254         .settinginfo=extern_gpio_settinginfo,
255         .settinginfolen=ARRAY_SIZE(extern_gpio_settinginfo),
256         .names="pca9554",
257 };
258 #endif
259
260 #if defined (CONFIG_IOEXTEND_TCA6424)
261 struct rk2818_gpio_expander_info  extgpio_tca6424_settinginfo[] = {
262
263         {
264                 .gpio_num               = TCA6424_P01,
265                 .pin_type           = GPIO_OUT,
266                 .pin_value              = GPIO_LOW,
267         },
268
269         {
270                 .gpio_num               = TCA6424_P02,// tp3
271                 .pin_type           = GPIO_OUT,
272                 .pin_value                      = GPIO_LOW,
273          },
274          {
275                 .gpio_num               = TCA6424_P03,
276                 .pin_type           = GPIO_OUT,
277                 .pin_value                      = GPIO_LOW,
278          },
279
280         {
281                 .gpio_num               = TCA6424_P04,// tp3
282                 .pin_type           = GPIO_OUT,
283                 .pin_value                      = GPIO_LOW,
284          },
285          {
286                 .gpio_num               = TCA6424_P05,
287                 .pin_type           = GPIO_OUT,
288                 .pin_value                      = GPIO_LOW,
289          }, 
290          {
291                 .gpio_num               = TCA6424_P12,
292                 .pin_type           = GPIO_IN,
293                 //.pin_value                    =GPIO_HIGH,
294          },
295
296         {
297                 .gpio_num               = TCA6424_P13,// tp3
298                 .pin_type           = GPIO_IN,
299                 //.pin_value                    =GPIO_HIGH,
300          },
301          {
302                 .gpio_num               = TCA6424_P14,
303                 .pin_type           = GPIO_IN,
304                 //.pin_value                    =GPIO_HIGH,
305          },
306
307          {
308                 .gpio_num               = TCA6424_P15,// tp3
309                 .pin_type           = GPIO_IN,
310                 //.pin_value                    =GPIO_HIGH,
311          },
312          {
313                 .gpio_num               = TCA6424_P17,// 3G PowerOn
314                 .pin_type               = GPIO_OUT,
315                 .pin_value              =GPIO_HIGH,
316          },
317 };
318
319 void tca6424_reset_itr(void)
320 {
321                 rk2818_mux_api_set(GPIOE_U1IR_I2C1_NAME, IOMUXA_GPIO1_A67);
322                 gpio_request(RK2818_PIN_PE6,NULL);
323                 gpio_request(RK2818_PIN_PE7,NULL);
324
325                 gpio_direction_output(RK2818_PIN_PE6,GPIO_HIGH);
326                 gpio_direction_output(RK2818_PIN_PE7,GPIO_LOW);
327                 udelay(3);
328                 gpio_set_value(RK2818_PIN_PE7,GPIO_HIGH);
329                 udelay(1);
330                 
331                 gpio_free(RK2818_PIN_PE6);
332                 gpio_free(RK2818_PIN_PE7);
333                 rk2818_mux_api_set(GPIOE_U1IR_I2C1_NAME, IOMUXA_I2C1);
334 }
335
336 struct tca6424_platform_data rk2818_tca6424_data={
337         .gpio_base=GPIO_EXPANDER_BASE,
338         .gpio_pin_num=CONFIG_EXPANDED_GPIO_NUM,
339         .gpio_irq_start=NR_AIC_IRQS + 2*NUM_GROUP + CONFIG_SPI_FPGA_GPIO_IRQ_NUM,
340         .irq_pin_num=CONFIG_EXPANDED_GPIO_IRQ_NUM,
341         .tca6424_irq_pin=RK2818_PIN_PA1,
342         .settinginfo=extgpio_tca6424_settinginfo,
343         .settinginfolen=ARRAY_SIZE(extgpio_tca6424_settinginfo),
344         .names="extend_gpio_tca6424",
345         .reseti2cpin = tca6424_reset_itr,
346 };
347 #endif
348
349 /*****************************************************************************************
350  * gsensor devices
351 *****************************************************************************************/
352 #define GS_IRQ_PIN RK2818_PIN_PE0
353
354 struct rk2818_gs_platform_data rk2818_gs_platdata = {
355         .gsensor_irq_pin = GS_IRQ_PIN,
356 };
357
358 /*****************************************************************************************
359  * wm8994  codec
360  * author: cjq@rock-chips.com
361  *****************************************************************************************/
362 static struct wm8994_platform_data wm8994_data = {
363     .mic_input = 0,
364     .micBase_vcc = 0,
365     .bb_input = 0, 
366     .bb_output = 0,
367     .frequence = 0,
368     .enable_pin = 0,
369     .headset_pin = 0,
370     .headset_call_vol = 0,
371     .speaker_call_vol = 0,
372     .earpiece_call_vol = 0,
373     .bt_call_vol = 0,
374 };// must initialize 
375
376 /*****************************************************************************************
377  * i2c devices
378  * author: kfx@rock-chips.com
379 *****************************************************************************************/
380 static void rk2818_i2c0_io_init(void)
381 {
382         rk2818_mux_api_set(GPIOE_I2C0_SEL_NAME, IOMUXA_I2C0);
383 }
384
385 static void rk2818_i2c1_io_init(void)
386 {
387         rk2818_mux_api_set(GPIOE_U1IR_I2C1_NAME, IOMUXA_I2C1);
388 }
389 struct rk2818_i2c_platform_data default_i2c0_data = { 
390         .bus_num    = 0,
391         .flags      = 0,
392         .slave_addr = 0xff,
393         .scl_rate  = 400*1000,
394         .mode           = I2C_MODE_IRQ,
395         .io_init = rk2818_i2c0_io_init,
396 };
397 struct rk2818_i2c_platform_data default_i2c1_data = { 
398 #ifdef CONFIG_I2C0_RK2818
399         .bus_num    = 1,
400 #else
401         .bus_num        = 0,
402 #endif
403         .flags      = 0,
404         .slave_addr = 0xff,
405         .scl_rate  = 400*1000,
406         .mode           = I2C_MODE_IRQ,
407         .io_init = rk2818_i2c1_io_init,
408 };
409
410 struct rk2818_i2c_spi_data default_i2c2_data = { 
411         .bus_num    = 2,
412         .flags      = 0,
413         .slave_addr = 0xff,
414         .scl_rate  = 400*1000,
415         
416 };
417 struct rk2818_i2c_spi_data default_i2c3_data = { 
418
419         .bus_num    = 3,
420         .flags      = 0,
421         .slave_addr = 0xff,
422         .scl_rate  = 400*1000,
423         
424 };
425 static struct i2c_board_info __initdata board_i2c0_devices[] = {
426 #if defined (CONFIG_RK1000_CONTROL)
427         {
428                 .type                   = "rk1000_control",
429                 .addr           = 0x40,
430                 .flags                  = 0,
431         },
432 #endif
433
434 #if defined (CONFIG_RK1000_TVOUT)
435         {
436                 .type                   = "rk1000_tvout",
437                 .addr           = 0x42,
438                 .flags                  = 0,
439         },
440 #endif
441 #if defined (CONFIG_SND_SOC_RK1000)
442         {
443                 .type                   = "rk1000_i2c_codec",
444                 .addr           = 0x60,
445                 .flags                  = 0,
446         },
447 #endif
448 #if defined (CONFIG_SND_SOC_WM8988)
449         {
450                 .type                   = "wm8988",
451                 .addr           = 0x1a,
452                 .flags                  = 0,
453         }
454 #endif  
455 #if defined (CONFIG_SND_SOC_WM8994)
456         {
457                 .type                   = "wm8994",
458                 .addr           = 0x1a,
459                 .flags                  = 0,
460                 .platform_data  = &wm8994_data,
461         },
462 #endif
463 };
464 static struct i2c_board_info __initdata board_i2c1_devices[] = {
465 #if defined (CONFIG_RTC_HYM8563)
466         {
467                 .type                   = "rtc_hym8563",
468                 .addr           = 0x51,
469                 .flags                  = 0,
470         },
471 #endif
472 #if defined (CONFIG_FM_QN8006)
473         {
474                 .type                   = "fm_qn8006",
475                 .addr           = 0x2b, 
476                 .flags                  = 0,
477         },
478 #endif
479 #if defined (CONFIG_GPIO_PCA9554)
480         {
481                 .type                   = "extend_gpio_pca9554",
482                 .addr           = 0x3c, 
483                 .flags                  = 0,
484                 .platform_data=&rk2818_pca9554_data.gpio_base,
485         },
486 #endif
487 #if defined (CONFIG_IOEXTEND_TCA6424)
488         {
489                 .type                   = "extend_gpio_tca6424",
490                 .addr           = 0x23, 
491                 .flags                  = 0,
492                 .platform_data=&rk2818_tca6424_data.gpio_base,
493         },
494 #endif
495
496 #if defined (CONFIG_RK2818_REGULATOR_LP8725)
497         {
498                 .type                   = "lp8725",
499                 .addr           = 0x79, 
500                 .flags                  = 0,
501                 .platform_data=&rk2818_lp8725_data,
502         },
503 #endif
504 #if defined (CONFIG_GS_MMA7660)
505     {
506         .type           = "gs_mma7660",
507         .addr           = 0x4c,
508         .flags          = 0,
509         .irq            = GS_IRQ_PIN,
510                 .platform_data = &rk2818_gs_platdata,
511     },
512 #endif
513         {},
514 };
515
516 static struct i2c_board_info __initdata board_i2c2_devices[] = {
517
518 };
519 static struct i2c_board_info __initdata board_i2c3_devices[] = {
520
521 };      
522
523 /*****************************************************************************************
524  * camera  devices
525  * author: ddl@rock-chips.com
526  *****************************************************************************************/
527 #ifdef CONFIG_VIDEO_RK2818
528
529 #define RK2818_CAM_POWER_PIN    TCA6424_P16
530 #define RK2818_CAM_RESET_PIN    INVALID_GPIO
531
532 static int rk28_sensor_io_init(void);
533 static int rk28_sensor_io_deinit(void);
534
535 struct rk28camera_platform_data rk28_camera_platform_data = {
536     .io_init = rk28_sensor_io_init,
537     .io_deinit = rk28_sensor_io_deinit,
538     .gpio_res = {
539         {
540             .gpio_reset = RK2818_CAM_RESET_PIN,
541             .gpio_power = RK2818_CAM_POWER_PIN,
542             .dev_name = "ov2655"
543         }, {
544             .gpio_reset = INVALID_GPIO,
545             .gpio_power = INVALID_GPIO,
546             .dev_name = NULL
547         }
548     }
549 };
550
551 static int rk28_sensor_io_init(void)
552 {
553     int ret = 0, i;
554     unsigned int camera_reset = INVALID_GPIO, camera_power = INVALID_GPIO;
555
556     printk("\n%s....%d    ******** ddl *********\n",__FUNCTION__,__LINE__);
557
558     for (i=0; i<2; i++) {
559         camera_reset = rk28_camera_platform_data.gpio_res[i].gpio_reset;
560         camera_power = rk28_camera_platform_data.gpio_res[i].gpio_power;
561
562         if (camera_power != INVALID_GPIO) {
563             ret = gpio_request(camera_power, "camera power");
564             if (ret)
565                 continue;
566
567             gpio_set_value(camera_reset, 1);
568             gpio_direction_output(camera_power, 0);
569         }
570
571         if (camera_reset != INVALID_GPIO) {
572             ret = gpio_request(camera_reset, "camera reset");
573             if (ret) {
574                 if (camera_power != INVALID_GPIO)
575                     gpio_free(camera_power);
576
577                 continue;
578             }
579
580             gpio_set_value(camera_reset, 0);
581             gpio_direction_output(camera_reset, 0);
582         }
583     }
584
585     return 0;
586 }
587
588 static int rk28_sensor_io_deinit(void)
589 {
590     unsigned int i;
591     unsigned int camera_reset = INVALID_GPIO, camera_power = INVALID_GPIO;
592
593     printk("\n%s....%d    ******** ddl *********\n",__FUNCTION__,__LINE__);
594
595     for (i=0; i<2; i++) {
596         camera_reset = rk28_camera_platform_data.gpio_res[i].gpio_reset;
597         camera_power = rk28_camera_platform_data.gpio_res[i].gpio_power;
598
599         if (camera_power != INVALID_GPIO){
600             gpio_direction_input(camera_power);
601             gpio_free(camera_power);
602         }
603
604         if (camera_reset != INVALID_GPIO)  {
605             gpio_direction_input(camera_reset);
606             gpio_free(camera_reset);
607         }
608     }
609
610     return 0;
611 }
612
613
614 static int rk28_sensor_power(struct device *dev, int on)
615 {
616     unsigned int camera_reset = INVALID_GPIO, camera_power = INVALID_GPIO;
617
618     if(rk28_camera_platform_data.gpio_res[0].dev_name &&  (strcmp(rk28_camera_platform_data.gpio_res[0].dev_name, dev_name(dev)) == 0)) {
619         camera_reset = rk28_camera_platform_data.gpio_res[0].gpio_reset;
620         camera_power = rk28_camera_platform_data.gpio_res[0].gpio_power;
621     } else if (rk28_camera_platform_data.gpio_res[1].dev_name && (strcmp(rk28_camera_platform_data.gpio_res[1].dev_name, dev_name(dev)) == 0)) {
622         camera_reset = rk28_camera_platform_data.gpio_res[1].gpio_reset;
623         camera_power = rk28_camera_platform_data.gpio_res[1].gpio_power;
624     }
625
626     if (camera_reset != INVALID_GPIO) {
627         gpio_set_value(camera_reset, !on);
628         //printk("\n%s..%s..ResetPin=%d ..PinLevel = %x   ******** ddl *********\n",__FUNCTION__,dev_name(dev),camera_reset, on);
629     }
630     if (camera_power != INVALID_GPIO)  {
631         gpio_set_value(camera_power, !on);
632         printk("\n%s..%s..PowerPin=%d ..PinLevel = %x   ******** ddl *********\n",__FUNCTION__,dev_name(dev), camera_power, !on);
633     }
634     if (camera_reset != INVALID_GPIO) {
635         msleep(3);          /* delay 3 ms */
636         gpio_set_value(camera_reset,on);
637         printk("\n%s..%s..ResetPin= %d..PinLevel = %x   ******** ddl *********\n",__FUNCTION__,dev_name(dev), camera_reset, on);
638     }
639     return 0;
640 }
641
642
643 #define OV2655_IIC_ADDR             0x60
644 static struct i2c_board_info rk2818_i2c_cam_info[] = {
645 #ifdef CONFIG_SOC_CAMERA_OV2655
646         {
647                 I2C_BOARD_INFO("ov2655", OV2655_IIC_ADDR>>1)
648         },
649 #endif
650 };
651
652 struct soc_camera_link rk2818_iclink = {
653         .bus_id         = RK28_CAM_PLATFORM_DEV_ID,
654         .power          = rk28_sensor_power,
655         .board_info     = &rk2818_i2c_cam_info[0],
656         .i2c_adapter_id = 1,
657 #ifdef CONFIG_SOC_CAMERA_OV2655
658         .module_name    = "ov2655",
659 #endif
660 };
661 #endif
662
663 /*****************************************************************************************
664  * battery  devices
665  * author: lw@rock-chips.com
666  *****************************************************************************************/
667 #define CHARGEOK_PIN    RK2818_PIN_PA4
668 struct rk2818_battery_platform_data rk2818_battery_platdata = {
669         .charge_ok_pin = CHARGEOK_PIN,
670 };
671 /*****************************************************************************************
672  * serial devices
673  * author: lhh@rock-chips.com
674  *****************************************************************************************/
675 static int serial_io_init(void)
676 {
677         int ret;
678 #if 1   
679         //cz@rock-chips.com
680         //20100808 
681         //UART0µÄËĸö¹Ü½ÅÏÈIOMUX³ÉGPIO
682         //È»ºó·Ö±ðÉèÖÃÊäÈëÊä³ö/À­¸ßÀ­µÍ´¦Àí
683         //×îºóÔÙIOMUX³ÉUART
684         //·ÀÖ¹Ö±½ÓIOMUX³ÉUARTºóËĸö¹Ü½ÅµÄ״̬²»¶Ôʱ
685         //²Ù×÷UARTµ¼ÖÂUART_USR_BUSYʼÖÕΪ1Ôì³ÉÈçÏÂËÀÑ­»·
686         //while(rk2818_uart_read(port,UART_USR)&UART_USR_BUSY)
687         //UARTËĸö¹Ü½ÅÔÚδ´«ÊäʱÕý³£×´Ì¬Ó¦¸ÃΪ£º
688         //RX/TX£ºHIGH
689         //CTS/RTS£ºLOW
690         //×¢Ò⣺CTS/RTSΪµÍÓÐЧ£¬Ó²¼þÉϲ»Ó¦¸ÃÇ¿ÐÐ×öÉÏÀ­
691                 rk2818_mux_api_set(GPIOG1_UART0_MMC1WPT_NAME, IOMUXA_GPIO1_C1 /*IOMUXA_UART0_SOUT*/);  
692                 rk2818_mux_api_set(GPIOG0_UART0_MMC1DET_NAME, IOMUXA_GPIO1_C0 /*IOMUXA_UART0_SIN*/);
693                 
694                 ret = gpio_request(RK2818_PIN_PG0, NULL); 
695                 if(ret != 0)
696                 {
697                   gpio_free(RK2818_PIN_PG0);
698                 }
699                 gpio_direction_output(RK2818_PIN_PG0,GPIO_HIGH); 
700         
701                 
702                 ret = gpio_request(RK2818_PIN_PG1, NULL); 
703                 if(ret != 0)
704                 {
705                   gpio_free(RK2818_PIN_PG1);
706                 }
707                 gpio_direction_output(RK2818_PIN_PG1,GPIO_HIGH); 
708         
709                 gpio_pull_updown(RK2818_PIN_PG1,GPIOPullUp);
710                 gpio_pull_updown(RK2818_PIN_PG0,GPIOPullUp);
711         
712                 rk2818_mux_api_set(GPIOG1_UART0_MMC1WPT_NAME, IOMUXA_UART0_SOUT);  
713                 rk2818_mux_api_set(GPIOG0_UART0_MMC1DET_NAME, IOMUXA_UART0_SIN);
714         
715                 rk2818_mux_api_set(GPIOB2_U0CTSN_SEL_NAME, IOMUXB_GPIO0_B2/*IOMUXB_UART0_CTS_N*/);
716                 rk2818_mux_api_set(GPIOB3_U0RTSN_SEL_NAME, IOMUXB_GPIO0_B3/*IOMUXB_UART0_RTS_N*/);
717         
718                 ret = gpio_request(RK2818_PIN_PB2, NULL); 
719                 if(ret != 0)
720                 {
721                   gpio_free(RK2818_PIN_PB2);
722                 }
723                 gpio_direction_input(RK2818_PIN_PB2); 
724         //        gpio_direction_output(RK2818_PIN_PB2,GPIO_LOW); 
725                 
726                 ret = gpio_request(RK2818_PIN_PB3, NULL); 
727                 if(ret != 0)
728                 {
729                   gpio_free(RK2818_PIN_PB3);
730                 }
731                 gpio_direction_output(RK2818_PIN_PB3,GPIO_LOW); 
732 #endif
733
734         rk2818_mux_api_set(GPIOB2_U0CTSN_SEL_NAME, IOMUXB_UART0_CTS_N);
735         rk2818_mux_api_set(GPIOB3_U0RTSN_SEL_NAME, IOMUXB_UART0_RTS_N);
736
737         return 0;
738 }
739
740 struct rk2818_serial_platform_data rk2818_serial0_platdata = {
741         .io_init = serial_io_init,
742 };
743
744 /*****************************************************************************************
745  * i2s devices
746  * author: lhhrock-chips.com
747  *****************************************************************************************/
748 static int i2s_io_init(void)
749 {
750     /* Configure the I2S pins in correct mode */
751     rk2818_mux_api_set(CXGPIO_I2S_SEL_NAME,IOMUXB_I2S_INTERFACE);
752         return 0;
753 }
754
755 struct rk2818_i2s_platform_data rk2818_i2s_platdata = {
756         .io_init = i2s_io_init,
757 };
758 /*****************************************************************************************
759  * spi devices
760  * author: lhhrock-chips.com
761  *****************************************************************************************/
762 #define SPI_CHIPSELECT_NUM 2
763 struct spi_cs_gpio rk2818_spi_cs_gpios[SPI_CHIPSELECT_NUM] = {
764         {
765                 .name = "spi cs0",
766                 .cs_gpio = RK2818_PIN_PB4,
767                 .cs_iomux_name = GPIOB4_SPI0CS0_MMC0D4_NAME,//if no iomux,set it NULL
768                 .cs_iomux_mode = IOMUXA_GPIO0_B4,
769         },
770         {
771                 .name = "spi cs1",
772                 .cs_gpio = RK2818_PIN_PB0,
773                 .cs_iomux_name = GPIOB0_SPI0CSN1_MMC1PCA_NAME,
774                 .cs_iomux_mode = IOMUXA_GPIO0_B0,
775         }
776
777 };
778
779 static int spi_io_init(struct spi_cs_gpio *cs_gpios, int cs_num)
780 {       
781         int i,j,ret;
782         //clk
783         rk2818_mux_api_set(GPIOB_SPI0_MMC0_NAME, IOMUXA_SPI0);
784         //cs
785         if (cs_gpios) {
786                 for (i=0; i<cs_num; i++) {
787                         rk2818_mux_api_set(cs_gpios[i].cs_iomux_name, cs_gpios[i].cs_iomux_mode);
788                         ret = gpio_request(cs_gpios[i].cs_gpio, cs_gpios[i].name);
789                         if (ret) {
790                                 for (j=0;j<i;j++) {
791                                         gpio_free(cs_gpios[j].cs_gpio);
792                                         rk2818_mux_api_mode_resume(cs_gpios[j].cs_iomux_name);
793                                 }
794                                 printk("[fun:%s, line:%d], gpio request err\n", __func__, __LINE__);
795                                 return -1;
796                         }
797                 }
798         }
799         return 0;
800 }
801
802 static int spi_io_deinit(struct spi_cs_gpio *cs_gpios, int cs_num)
803 {
804         int i;
805         rk2818_mux_api_mode_resume(GPIOB_SPI0_MMC0_NAME);       
806         
807         if (cs_gpios) {
808                 for (i=0; i<cs_num; i++) {
809                         gpio_free(cs_gpios[i].cs_gpio);
810                         rk2818_mux_api_mode_resume(cs_gpios[i].cs_iomux_name);
811                 }
812         }
813         
814         return 0;
815 }
816
817 struct rk2818_spi_platform_data rk2818_spi_platdata = {
818         .num_chipselect = SPI_CHIPSELECT_NUM,//raho ´ó°åÐèÒªÖ§³Ö3¸öƬѡ dxj
819         .chipselect_gpios = rk2818_spi_cs_gpios,
820         .io_init = spi_io_init,
821         .io_deinit = spi_io_deinit,
822 };
823 /*****************************************************************************************
824  * xpt2046 touch panel
825  * author: dxjrock-chips.com
826  *****************************************************************************************/
827 #define XPT2046_GPIO_INT           RK2818_PIN_PE3
828 #define DEBOUNCE_REPTIME  3
829
830 #if defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_SPI) 
831 static struct xpt2046_platform_data xpt2046_info = {
832         .model                  = 2046,
833         .keep_vref_on   = 1,
834         .swap_xy                = 0,
835         .x_min                  = 0,
836         .x_max                  = 320,
837         .y_min                  = 0,
838         .y_max                  = 480,
839         .debounce_max           = 7,
840         .debounce_rep           = DEBOUNCE_REPTIME,
841         .debounce_tol           = 20,
842         .gpio_pendown           = XPT2046_GPIO_INT,
843         .penirq_recheck_delay_usecs = 1,
844 };
845 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)
846 static struct xpt2046_platform_data xpt2046_info = {
847         .model                  = 2046,
848         .keep_vref_on   = 1,
849         .swap_xy                = 0,
850         .x_min                  = 0,
851         .x_max                  = 320,
852         .y_min                  = 0,
853         .y_max                  = 480,
854         .debounce_max           = 7,
855         .debounce_rep           = DEBOUNCE_REPTIME,
856         .debounce_tol           = 20,
857         .gpio_pendown           = XPT2046_GPIO_INT,
858         .penirq_recheck_delay_usecs = 1,
859 };
860 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_SPI) 
861 static struct xpt2046_platform_data xpt2046_info = {
862         .model                  = 2046,
863         .keep_vref_on   = 1,
864         .swap_xy                = 1,
865         .x_min                  = 0,
866         .x_max                  = 800,
867         .y_min                  = 0,
868         .y_max                  = 480,
869         .debounce_max           = 7,
870         .debounce_rep           = DEBOUNCE_REPTIME,
871         .debounce_tol           = 20,
872         .gpio_pendown           = XPT2046_GPIO_INT,
873
874         .penirq_recheck_delay_usecs = 1,
875 };
876 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
877 static struct xpt2046_platform_data xpt2046_info = {
878         .model                  = 2046,
879         .keep_vref_on   = 1,
880         .swap_xy                = 1,
881         .x_min                  = 0,
882         .x_max                  = 800,
883         .y_min                  = 0,
884         .y_max                  = 480,
885         .debounce_max           = 7,
886         .debounce_rep           = DEBOUNCE_REPTIME,
887         .debounce_tol           = 20,
888         .gpio_pendown           = XPT2046_GPIO_INT,
889         
890         .penirq_recheck_delay_usecs = 1,
891 };
892 #endif
893 static struct spi_board_info board_spi_devices[] = {
894 #if defined(CONFIG_SPI_FPGA)
895         {       /* fpga ice65l08xx */
896                 .modalias       = "spi_fpga",
897                 .chip_select    = 1,
898                 .max_speed_hz   = 8 * 1000 * 1000,
899                 .bus_num        = 0,
900                 .mode   = SPI_MODE_0,
901         },
902 #endif
903 #if defined(CONFIG_ENC28J60)    
904         {       /* net chip */
905                 .modalias       = "enc28j60",
906                 .chip_select    = 1,
907                 .max_speed_hz   = 12 * 1000 * 1000,
908                 .bus_num        = 0,
909                 .mode   = SPI_MODE_0,
910         },
911 #endif  
912 #if defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)\
913     ||defined(CONFIG_TOUCHSCREEN_XPT2046_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
914         {
915                 .modalias       = "xpt2046_ts",
916                 .chip_select    = 0,
917                 .max_speed_hz   = 125 * 1000 * 26,/* (max sample rate @ 3V) * (cmd + data + overhead) */
918                 .bus_num        = 0,
919                 .irq = XPT2046_GPIO_INT,
920                 .platform_data = &xpt2046_info,
921         },
922 #endif
923 }; 
924
925 /*rk2818_fb gpio information*/
926 static struct rk2818_fb_gpio rk2818_fb_gpio_info = {
927     .display_on = (GPIO_LOW<<16)|RK2818_PIN_PB1,
928     .lcd_standby = 0,
929     .mcu_fmk_pin = 0,
930 };
931
932 /*rk2818_fb iomux information*/
933 static struct rk2818_fb_iomux rk2818_fb_iomux_info = {
934     .data16     = GPIOC_LCDC16BIT_SEL_NAME,
935     .data18     = GPIOC_LCDC18BIT_SEL_NAME,
936     .data24     = GPIOC_LCDC24BIT_SEL_NAME,
937     .den        = CXGPIO_LCDDEN_SEL_NAME,
938     .vsync      = CXGPIO_LCDVSYNC_SEL_NAME,
939     .mcu_fmk    = 0,
940 };
941 /*rk2818_fb*/
942 struct rk2818_fb_mach_info rk2818_fb_mach_info = {
943     .gpio = &rk2818_fb_gpio_info,
944     .iomux = &rk2818_fb_iomux_info,
945 };
946
947 /*****************************************************************************************
948  * backlight  devices
949  * author: nzy@rock-chips.com
950  *****************************************************************************************/
951  /*
952  GPIOF2_APWM0_SEL_NAME,       IOMUXB_PWM0
953  GPIOF3_APWM1_MMC0DETN_NAME,  IOMUXA_PWM1
954  GPIOF4_APWM2_MMC0WPT_NAME,   IOMUXA_PWM2
955  GPIOF5_APWM3_DPWM3_NAME,     IOMUXB_PWM3
956  */
957  
958 #define PWM_ID            0  
959 #define PWM_MUX_NAME      GPIOF2_APWM0_SEL_NAME
960 #define PWM_MUX_MODE      IOMUXB_PWM0
961 #define PWM_EFFECT_VALUE  0
962
963
964 #define BL_EN_MUX_NAME    GPIOF34_UART3_SEL_NAME
965 #define BL_EN_MUX_MODE    IOMUXB_GPIO1_B34
966
967 #define BL_EN_PIN         RK2818_PIN_PF3
968 #define BL_EN_VALUE       GPIO_HIGH
969
970
971
972 static int rk2818_backlight_io_init(void)
973 {
974     int ret = 0;
975     
976     rk2818_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
977
978     rk2818_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE); 
979
980     ret = gpio_request(BL_EN_PIN, NULL); 
981     if(ret != 0)
982     {
983         gpio_free(BL_EN_PIN);
984         printk(KERN_ERR ">>>>>> lcd_cs gpio_request err \n ");        
985     }
986     
987     gpio_direction_output(BL_EN_PIN, 0);
988     gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
989
990     return ret;
991 }
992
993 static int rk2818_backlight_io_deinit(void)
994 {
995     int ret = 0;
996     
997     gpio_free(BL_EN_PIN);
998     
999     rk2818_mux_api_mode_resume(PWM_MUX_NAME);
1000
1001     rk2818_mux_api_mode_resume(BL_EN_MUX_NAME);
1002
1003     return ret;
1004 }
1005 struct rk2818_bl_info rk2818_bl_info = {
1006     .pwm_id   = PWM_ID,
1007     .bl_ref   = PWM_EFFECT_VALUE,
1008     .io_init   = rk2818_backlight_io_init,
1009     .io_deinit = rk2818_backlight_io_deinit, 
1010 };
1011
1012 /********************************************************
1013 *                               dm9000 net work devices
1014 *                               author:lyx
1015 ********************************************************/
1016 #ifdef CONFIG_DM9000
1017 /*
1018 GPIOA5_FLASHCS1_SEL_NAME     IOMUXB_FLASH_CS1
1019 GPIOA6_FLASHCS2_SEL_NAME     IOMUXB_FLASH_CS2
1020 GPIOA7_FLASHCS3_SEL_NAME     IOMUXB_FLASH_CS3
1021 GPIOE_SPI1_FLASH_SEL1_NAME   IOMUXA_FLASH_CS45
1022 GPIOE_SPI1_FLASH_SEL_NAME    IOMUXA_FLASH_CS67
1023 */
1024 #define DM9000_USE_NAND_CS 1     //cs can be 1,2,3,4,5,6 or 7
1025 #define DM9000_CS_IOMUX_NAME GPIOA5_FLASHCS1_SEL_NAME
1026 #define DM9000_CS_IOMUX_MODE IOMUXB_FLASH_CS1
1027 #define DM9000_NET_INT_PIN RK2818_PIN_PA3
1028 #define DM9000_INT_IOMUX_NAME GPIOA23_UART2_SEL_NAME
1029 #define DM9000_INT_IOMUX_MODE IOMUXB_GPIO0_A23
1030 #define DM9000_INT_INIT_VALUE GPIOPullDown
1031 #define DM9000_IRQ IRQF_TRIGGER_HIGH
1032 #define DM9000_IO_ADDR (RK2818_NANDC_PHYS + 0x800 + DM9000_USE_NAND_CS*0x100 + 0x8)
1033 #define DM9000_DATA_ADDR (RK2818_NANDC_PHYS + 0x800 + DM9000_USE_NAND_CS*0x100 + 0x4)
1034
1035 static int dm9k_gpio_set(void)
1036 {
1037         //cs
1038         rk2818_mux_api_set(DM9000_CS_IOMUX_NAME, DM9000_CS_IOMUX_MODE);
1039         //int
1040         rk2818_mux_api_set(DM9000_INT_IOMUX_NAME, DM9000_INT_IOMUX_MODE);
1041                 
1042         return 0;
1043 }
1044 static int dm9k_gpio_free(void)
1045 {
1046         rk2818_mux_api_mode_resume(DM9000_INT_IOMUX_NAME);
1047         rk2818_mux_api_mode_resume(DM9000_CS_IOMUX_NAME);
1048         return 0;
1049 }
1050
1051 static struct resource dm9k_resource[] = {
1052         [0] = {
1053                 .start = DM9000_IO_ADDR,    
1054                 .end   = DM9000_IO_ADDR + 3,
1055                 .flags = IORESOURCE_MEM,
1056         },
1057         [1] = {
1058                 .start = DM9000_DATA_ADDR,      
1059                 .end   = DM9000_DATA_ADDR + 3,
1060                 .flags = IORESOURCE_MEM,
1061         },
1062         [2] = {
1063                 .start = DM9000_NET_INT_PIN,
1064                 .end   = DM9000_NET_INT_PIN,
1065                 .flags = IORESOURCE_IRQ | DM9000_IRQ,
1066         }
1067
1068 };
1069
1070 /* for the moment we limit ourselves to 8bit IO until some
1071  * better IO routines can be written and tested
1072 */
1073 struct dm9000_plat_data dm9k_platdata = {       
1074         .flags = DM9000_PLATF_8BITONLY,
1075         .irq_pin = DM9000_NET_INT_PIN,
1076         .irq_pin_value = DM9000_INT_INIT_VALUE,
1077         .io_init = dm9k_gpio_set,
1078         .io_deinit = dm9k_gpio_free,
1079 };
1080
1081 struct platform_device rk2818_device_dm9k = {
1082         .name           = "dm9000",
1083         .id             = 0,
1084         .num_resources  = ARRAY_SIZE(dm9k_resource),
1085         .resource       = dm9k_resource,
1086         .dev            = {
1087                 .platform_data = &dm9k_platdata,
1088         }
1089 };
1090 #endif
1091
1092
1093 /*****************************************************************************************
1094  * nand flash devices
1095  * author: hxy@rock-chips.com
1096  *****************************************************************************************/
1097 /*
1098 GPIOA5_FLASHCS1_SEL_NAME,   IOMUXB_FLASH_CS1
1099 GPIOA6_FLASHCS2_SEL_NAME,   IOMUXB_FLASH_CS2
1100 GPIOA7_FLASHCS3_SEL_NAME,   IOMUXB_FLASH_CS3
1101 GPIOE_SPI1_FLASH_SEL1_NAME, IOMUXA_FLASH_CS45  
1102 GPIOE_SPI1_FLASH_SEL_NAME,  IOMUXA_FLASH_CS67  
1103 */
1104
1105 #define NAND_CS_MAX_NUM     1  /*form 0 to 8, it is 0 when no nand flash */
1106
1107 int rk2818_nand_io_init(void)
1108 {
1109 #if (NAND_CS_MAX_NUM == 2)
1110     rk2818_mux_api_set(GPIOA5_FLASHCS1_SEL_NAME, IOMUXB_FLASH_CS1);
1111 #elif (NAND_CS_MAX_NUM == 3)
1112     rk2818_mux_api_set(GPIOA5_FLASHCS1_SEL_NAME, IOMUXB_FLASH_CS1);
1113     rk2818_mux_api_set(GPIOA6_FLASHCS2_SEL_NAME, IOMUXB_FLASH_CS2);
1114 #elif (NAND_CS_MAX_NUM == 4)
1115     rk2818_mux_api_set(GPIOA5_FLASHCS1_SEL_NAME, IOMUXB_FLASH_CS1);
1116     rk2818_mux_api_set(GPIOA6_FLASHCS2_SEL_NAME, IOMUXB_FLASH_CS2);
1117     rk2818_mux_api_set(GPIOA7_FLASHCS3_SEL_NAME, IOMUXB_FLASH_CS3);
1118 #elif ((NAND_CS_MAX_NUM == 5) || (NAND_CS_MAX_NUM == 6))
1119     rk2818_mux_api_set(GPIOA5_FLASHCS1_SEL_NAME, IOMUXB_FLASH_CS1);
1120     rk2818_mux_api_set(GPIOA6_FLASHCS2_SEL_NAME, IOMUXB_FLASH_CS2);
1121     rk2818_mux_api_set(GPIOA7_FLASHCS3_SEL_NAME, IOMUXB_FLASH_CS3);
1122     rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL1_NAME, IOMUXA_FLASH_CS45);  
1123 #elif ((NAND_CS_MAX_NUM == 7) || (NAND_CS_MAX_NUM == 8))
1124     rk2818_mux_api_set(GPIOA5_FLASHCS1_SEL_NAME, IOMUXB_FLASH_CS1);
1125     rk2818_mux_api_set(GPIOA6_FLASHCS2_SEL_NAME, IOMUXB_FLASH_CS2);
1126     rk2818_mux_api_set(GPIOA7_FLASHCS3_SEL_NAME, IOMUXB_FLASH_CS3);
1127     rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL1_NAME, IOMUXA_FLASH_CS45);  
1128     rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL_NAME, IOMUXA_FLASH_CS67);  
1129 #endif
1130     return 0;
1131 }
1132
1133 struct rk2818_nand_platform_data rk2818_nand_data = {
1134     .width      = 1,     /* data bus width in bytes */
1135     .hw_ecc     = 1,     /* hw ecc 0: soft ecc */
1136     .num_flash    = 1,
1137     .io_init   = rk2818_nand_io_init,
1138 };
1139
1140
1141 /*****************************************/
1142
1143 static struct platform_device *devices[] __initdata = {
1144         &rk2818_device_uart1,
1145 #ifdef CONFIG_I2C0_RK2818
1146         &rk2818_device_i2c0,
1147 #endif
1148 #ifdef CONFIG_I2C1_RK2818
1149         &rk2818_device_i2c1,
1150 #endif
1151 #ifdef CONFIG_SDMMC0_RK2818     
1152         &rk2818_device_sdmmc0,
1153 #endif
1154 #ifdef CONFIG_SDMMC1_RK2818
1155         &rk2818_device_sdmmc1,
1156 #endif
1157         &rk2818_device_spim,
1158         &rk2818_device_i2s,
1159 #if defined(CONFIG_ANDROID_PMEM)
1160         &rk2818_device_pmem,
1161         &rk2818_device_pmem_dsp,
1162 #endif
1163         &rk2818_device_adc,
1164         &rk2818_device_adckey,
1165         &rk2818_device_battery,
1166     &rk2818_device_fb,    
1167     &rk2818_device_backlight,
1168         &rk2818_device_dsp,
1169 #ifdef CONFIG_VIDEO_RK2818
1170         &rk2818_device_camera,      /* ddl@rock-chips.com : camera support  */
1171         &rk2818_soc_camera_pdrv,
1172 #endif
1173 #ifdef CONFIG_MTD_NAND_RK2818
1174         &rk2818_nand_device,
1175 #endif
1176 #ifdef CONFIG_DM9000
1177         &rk2818_device_dm9k,
1178 #endif
1179
1180 #ifdef CONFIG_DWC_OTG
1181         &rk2818_device_dwc_otg,
1182 #endif
1183 #ifdef CONFIG_RK2818_HOST11
1184         &rk2818_device_host11,
1185 #endif
1186 #ifdef CONFIG_USB_ANDROID
1187         &android_usb_device,
1188         &usb_mass_storage_device,
1189 #endif
1190
1191 };
1192
1193 extern struct sys_timer rk2818_timer;
1194 #define POWER_PIN       RK2818_PIN_PH7
1195 static void rk2818_power_on(void)
1196 {
1197         int ret;
1198         ret = gpio_request(POWER_PIN, NULL);
1199         if (ret) {
1200                 printk("failed to request power_off gpio\n");
1201                 goto err_free_gpio;
1202         }
1203
1204         gpio_pull_updown(POWER_PIN, GPIOPullUp);
1205         ret = gpio_direction_output(POWER_PIN, GPIO_HIGH);
1206         if (ret) {
1207                 printk("failed to set power_off gpio output\n");
1208                 goto err_free_gpio;
1209         }
1210
1211         gpio_set_value(POWER_PIN, 1);/*power on*/
1212         
1213 err_free_gpio:
1214         gpio_free(POWER_PIN);
1215 }
1216
1217 static void rk2818_power_off(void)
1218 {
1219         printk("shut down system now ...\n");
1220         gpio_set_value(POWER_PIN, 0);/*power down*/
1221 }
1222
1223 void lcd_set_iomux(u8 enable)
1224 {
1225     int ret=-1;
1226     
1227     if(enable)
1228     {
1229         rk2818_mux_api_set(GPIOH6_IQ_SEL_NAME, 0);
1230         ret = gpio_request(RK2818_PIN_PH6, NULL);
1231         if(0)//(ret != 0)
1232         {
1233             gpio_free(RK2818_PIN_PH6);
1234             printk(">>>>>> lcd cs gpio_request err \n ");           
1235             goto pin_err;
1236         }  
1237         
1238         rk2818_mux_api_set(GPIOE_U1IR_I2C1_NAME, 0);    
1239
1240         ret = gpio_request(RK2818_PIN_PE7, NULL); 
1241         if(0)//(ret != 0)
1242         {
1243             gpio_free(RK2818_PIN_PE7);
1244             printk(">>>>>> lcd clk gpio_request err \n "); 
1245             goto pin_err;
1246         }  
1247         
1248         ret = gpio_request(RK2818_PIN_PE6, NULL); 
1249         if(0)//(ret != 0)
1250         {
1251             gpio_free(RK2818_PIN_PE6);
1252             printk(">>>>>> lcd txd gpio_request err \n "); 
1253             goto pin_err;
1254         }        
1255     }
1256     else
1257     {
1258          gpio_free(RK2818_PIN_PH6);
1259          rk2818_mux_api_mode_resume(GPIOH6_IQ_SEL_NAME);
1260
1261          gpio_free(RK2818_PIN_PE7);   
1262          gpio_free(RK2818_PIN_PE6); 
1263          rk2818_mux_api_mode_resume(GPIOE_U1IR_I2C1_NAME);
1264     }
1265     return ;
1266 pin_err:
1267     return ;
1268
1269 }
1270
1271 struct lcd_td043mgea1_data lcd_td043mgea1 = {
1272     .pin_txd    = RK2818_PIN_PE6,
1273     .pin_clk    = RK2818_PIN_PE7,
1274     .pin_cs     = RK2818_PIN_PH6,
1275     .screen_set_iomux = lcd_set_iomux,
1276 };
1277
1278 //      adc      ---> key       
1279 #define PLAY_ON_PIN RK2818_PIN_PE1
1280 #define PLAY_ON_LEVEL 1
1281 static  ADC_keyst gAdcValueTab[] = 
1282 {
1283         {95,  AD2KEY1},///VOLUME_DOWN
1284         {249, AD2KEY2},///VOLUME_UP
1285         {408, AD2KEY3},///MENU
1286         {560, AD2KEY4},///HOME
1287         {725, AD2KEY5},///BACK
1288         {816, AD2KEY6},///CALL
1289         {0,0}
1290 };
1291
1292 static unsigned char gInitKeyCode[] = 
1293 {
1294         AD2KEY1,AD2KEY2,AD2KEY3,AD2KEY4,AD2KEY5,AD2KEY6,
1295         ENDCALL,KEYSTART,KEY_WAKEUP,
1296 };
1297
1298 struct adc_key_data rk2818_adc_key = {
1299     .pin_playon     = PLAY_ON_PIN,
1300     .playon_level   = PLAY_ON_LEVEL,
1301     .adc_empty      = 900,
1302     .adc_invalid    = 20,
1303     .adc_drift      = 50,
1304     .adc_chn        = 1,
1305     .adc_key_table  = gAdcValueTab,
1306     .initKeyCode    = gInitKeyCode,
1307     .adc_key_cnt    = 7,
1308 };
1309 struct rk2818_adckey_platform_data rk2818_adckey_platdata = {
1310         .adc_key = &rk2818_adc_key,
1311 };
1312 #if CONFIG_ANDROID_TIMED_GPIO
1313 struct timed_gpio_platform_data rk28_vibrator_info = {
1314         .num_gpios = 0,
1315 };
1316 #endif
1317
1318 static void __init machine_rk2818_init_irq(void)
1319 {
1320         rk2818_init_irq();
1321         rk2818_gpio_init(rk2818_gpioBank, 8);
1322         rk2818_gpio_irq_setup();
1323 }
1324
1325 static void __init machine_rk2818_board_init(void)
1326 {       
1327         rk2818_power_on();
1328         pm_power_off = rk2818_power_off;
1329 #ifdef CONFIG_I2C0_RK2818
1330         i2c_register_board_info(default_i2c0_data.bus_num, board_i2c0_devices,
1331                         ARRAY_SIZE(board_i2c0_devices));
1332 #endif
1333 #ifdef CONFIG_I2C1_RK2818
1334         i2c_register_board_info(default_i2c1_data.bus_num, board_i2c1_devices,
1335                         ARRAY_SIZE(board_i2c1_devices));
1336 #endif
1337 #ifdef CONFIG_SPI_FPGA_I2C
1338         i2c_register_board_info(default_i2c2_data.bus_num, board_i2c2_devices,
1339                         ARRAY_SIZE(board_i2c2_devices));
1340         i2c_register_board_info(default_i2c3_data.bus_num, board_i2c3_devices,
1341                         ARRAY_SIZE(board_i2c3_devices));
1342 #endif
1343         platform_add_devices(devices, ARRAY_SIZE(devices));     
1344         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1345         //rk2818_mux_api_set(GPIOB4_SPI0CS0_MMC0D4_NAME,IOMUXA_GPIO0_B4); //IOMUXA_SPI0_CSN0);//use for gpio SPI CS0
1346         //rk2818_mux_api_set(GPIOB0_SPI0CSN1_MMC1PCA_NAME,IOMUXA_GPIO0_B0); //IOMUXA_SPI0_CSN1);//use for gpio SPI CS1
1347         //rk2818_mux_api_set(GPIOB_SPI0_MMC0_NAME,IOMUXA_SPI0);//use for SPI CLK SDI SDO
1348 }
1349
1350 static void __init machine_rk2818_mapio(void)
1351 {
1352         iotable_init(rk2818_io_desc, ARRAY_SIZE(rk2818_io_desc));
1353         rk2818_clock_init();
1354         rk2818_iomux_init();    
1355 }
1356
1357 MACHINE_START(RK2818, "RK28board")
1358
1359 /* UART for LL DEBUG */
1360         .phys_io        = 0x18002000,
1361         .io_pg_offst    = ((0xFF100000) >> 18) & 0xfffc,
1362         .boot_params    = RK2818_SDRAM_PHYS + 0x88000,
1363         .map_io         = machine_rk2818_mapio,
1364         .init_irq       = machine_rk2818_init_irq,
1365         .init_machine   = machine_rk2818_board_init,
1366         .timer          = &rk2818_timer,
1367 MACHINE_END
1368