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