add cs select for dm9000 and move io set function to board-XXXX.c file
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk2818 / board-raho.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 #include <linux/circ_buf.h>
26 #include <linux/miscdevice.h>
27
28 #include <mach/hardware.h>
29 #include <asm/mach-types.h>
30 #include <asm/mach/arch.h>
31 #include <asm/mach/map.h>
32 #include <asm/mach/flash.h>
33
34 #include <mach/irqs.h>
35 #include <mach/board.h>
36 #include <mach/rk2818_iomap.h>
37 #include <mach/iomux.h>
38 #include <mach/gpio.h>
39 #include <mach/spi_fpga.h>
40 #include <mach/rk2818_camera.h>                          /* ddl@rock-chips.com : camera support */
41
42 #include <linux/mtd/nand.h>
43 #include <linux/mtd/partitions.h>
44 #include <linux/dm9000.h>
45
46 #include <media/soc_camera.h>                               /* ddl@rock-chips.com : camera support */
47
48
49 #include "devices.h"
50
51 #include "../../../drivers/spi/rk2818_spim.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  void rk2818_sdmmc0_cfg_gpio(struct platform_device *dev)
164 {
165     rk2818_mux_api_set(GPIOH_MMC0D_SEL_NAME, IOMUXA_SDMMC0_DATA123);
166         rk2818_mux_api_set(GPIOH_MMC0_SEL_NAME, IOMUXA_SDMMC0_CMD_DATA0_CLKOUT);
167 #if 0
168         rk2818_mux_api_set(GPIOF3_APWM1_MMC0DETN_NAME, IOMUXA_SDMMC1_DETECT_N);
169 #endif  
170 }
171
172 void rk2818_sdmmc1_cfg_gpio(struct platform_device *dev)
173 {
174         rk2818_mux_api_set(GPIOG_MMC1_SEL_NAME, IOMUXA_SDMMC1_CMD_DATA0_CLKOUT);
175         rk2818_mux_api_set(GPIOG_MMC1D_SEL_NAME, IOMUXA_SDMMC1_DATA123);
176 #if 0
177         /* wifi power up (gpio control) */
178         rk2818_mux_api_set(GPIOH7_HSADCCLK_SEL_NAME,IOMUXB_GPIO1_D7);
179         rk2818_mux_api_set(GPIOF5_APWM3_DPWM3_NAME,IOMUXB_GPIO1_B5);
180         gpio_request(RK2818_PIN_PH7, "sdio");
181         gpio_direction_output(RK2818_PIN_PH7,GPIO_HIGH);
182 #endif
183
184 }
185 #define CONFIG_SDMMC0_USE_DMA
186 #define CONFIG_SDMMC1_USE_DMA
187 struct rk2818_sdmmc_platform_data default_sdmmc0_data = {
188         .host_ocr_avail = (MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
189                                            MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33| 
190                                            MMC_VDD_33_34|MMC_VDD_34_35| MMC_VDD_35_36),
191         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
192         .cfg_gpio = rk2818_sdmmc0_cfg_gpio,
193         .no_detect = 0,
194         .dma_name = "sd_mmc",
195 #ifdef CONFIG_SDMMC0_USE_DMA
196         .use_dma  = 1,
197 #else
198         .use_dma = 0,
199 #endif
200 };
201 struct rk2818_sdmmc_platform_data default_sdmmc1_data = {
202         .host_ocr_avail = (MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|
203                                            MMC_VDD_29_30|MMC_VDD_30_31|MMC_VDD_31_32|
204                                            MMC_VDD_32_33|MMC_VDD_33_34),
205         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_SDIO_IRQ|
206                                    MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
207         .cfg_gpio = rk2818_sdmmc1_cfg_gpio,
208         .no_detect = 1,
209         .dma_name = "sdio",
210 #ifdef CONFIG_SDMMC1_USE_DMA
211         .use_dma  = 1,
212 #else
213         .use_dma = 0,
214 #endif
215 };
216
217 /*****************************************************************************************
218  * extern gpio devices
219  *author: xxx
220  *****************************************************************************************/
221 #if defined (CONFIG_GPIO_PCA9554)
222 struct rk2818_gpio_expander_info  extern_gpio_settinginfo[] = {
223         {
224                 .gpio_num               =RK2818_PIN_PI0,
225                 .pin_type           = GPIO_IN,
226                 //.pin_value                    =GPIO_HIGH,
227          },
228
229         {
230                 .gpio_num               =RK2818_PIN_PI4,// tp3
231                 .pin_type           = GPIO_IN,
232                 //.pin_value                    =GPIO_HIGH,
233          },
234          
235          {
236                 .gpio_num               =RK2818_PIN_PI5,//tp4
237                 .pin_type           = GPIO_IN,
238                 //.pin_value                    =GPIO_HIGH,
239          },
240          {
241                 .gpio_num               =RK2818_PIN_PI6,//tp2
242                 .pin_type           = GPIO_OUT,
243                 //.pin_value                    =GPIO_HIGH,
244          },
245          {
246                 .gpio_num               =RK2818_PIN_PI7,//tp1
247                 .pin_type           = GPIO_OUT,
248                 .pin_value                      =GPIO_HIGH,
249          },
250
251
252                 
253 };
254
255 struct pca9554_platform_data rk2818_pca9554_data={
256         .gpio_base=GPIOS_EXPANDER_BASE,
257         .gpio_pin_num=CONFIG_EXPANDED_GPIO_NUM,
258         .gpio_irq_start=NR_AIC_IRQS + 2*NUM_GROUP,
259         .irq_pin_num=CONFIG_EXPANDED_GPIO_IRQ_NUM,
260         .pca9954_irq_pin=RK2818_PIN_PE2,
261         .settinginfo=extern_gpio_settinginfo,
262         .settinginfolen=ARRAY_SIZE(extern_gpio_settinginfo),
263         .names="pca9554",
264 };
265 #endif
266
267 /*****************************************************************************************
268  * I2C devices
269  *author: kfx
270 *****************************************************************************************/
271  void rk2818_i2c0_cfg_gpio(struct platform_device *dev)
272 {
273         rk2818_mux_api_set(GPIOE_I2C0_SEL_NAME, IOMUXA_I2C0);
274 }
275
276 void rk2818_i2c1_cfg_gpio(struct platform_device *dev)
277 {
278         rk2818_mux_api_set(GPIOE_U1IR_I2C1_NAME, IOMUXA_I2C1);
279 }
280 struct rk2818_i2c_platform_data default_i2c0_data = { 
281         .bus_num    = 0,
282         .flags      = 0,
283         .slave_addr = 0xff,
284         .scl_rate  = 400*1000,
285         .cfg_gpio = rk2818_i2c0_cfg_gpio,
286 };
287 struct rk2818_i2c_platform_data default_i2c1_data = { 
288 #ifdef CONFIG_I2C0_RK2818
289         .bus_num    = 1,
290 #else
291         .bus_num        = 0,
292 #endif
293         .flags      = 0,
294         .slave_addr = 0xff,
295         .scl_rate  = 400*1000,
296         .cfg_gpio = rk2818_i2c1_cfg_gpio,
297 };
298
299 struct rk2818_i2c_spi_data default_i2c2_data = { 
300         .bus_num    = 2,
301         .flags      = 0,
302         .slave_addr = 0xff,
303         .scl_rate  = 400*1000,
304         
305 };
306 struct rk2818_i2c_spi_data default_i2c3_data = { 
307
308         .bus_num    = 3,
309         .flags      = 0,
310         .slave_addr = 0xff,
311         .scl_rate  = 400*1000,
312         
313 };
314 static struct i2c_board_info __initdata board_i2c0_devices[] = {
315 #if defined (CONFIG_RK1000_CONTROL)
316         {
317                 .type                   = "rk1000_control",
318                 .addr           = 0x40,
319                 .flags                  = 0,
320         },
321 #endif
322
323 #if defined (CONFIG_RK1000_TVOUT)
324         {
325                 .type                   = "rk1000_tvout",
326                 .addr           = 0x42,
327                 .flags                  = 0,
328         },
329 #endif
330 #if defined (CONFIG_SND_SOC_RK1000)
331         {
332                 .type                   = "rk1000_i2c_codec",
333                 .addr           = 0x60,
334                 .flags                  = 0,
335         },
336 #endif
337 #if defined (CONFIG_SND_SOC_WM8988)
338         {
339                 .type                   = "wm8988",
340                 .addr           = 0x1a,
341                 .flags                  = 0,
342         }
343 #endif  
344 };
345 static struct i2c_board_info __initdata board_i2c1_devices[] = {
346 #if defined (CONFIG_RTC_HYM8563)
347         {
348                 .type                   = "rtc_hym8563",
349                 .addr           = 0x51,
350                 .flags                  = 0,
351         },
352 #endif
353 #if defined (CONFIG_FM_QN8006)
354         {
355                 .type                   = "fm_qn8006",
356                 .addr           = 0x2b, 
357                 .flags                  = 0,
358         },
359 #endif
360 #if defined (CONFIG_GPIO_PCA9554)
361         {
362                 .type                   = "extend_gpio_pca9554",
363                 .addr           = 0x3c, 
364                 .flags                  = 0,
365                 .platform_data=&rk2818_pca9554_data.gpio_base,
366         },
367 #endif
368 #if defined (CONFIG_PMIC_LP8725)
369         {
370                 .type                   = "lp8725",
371                 .addr           = 0x79, 
372                 .flags                  = 0,
373         },
374 #endif
375 #if defined (CONFIG_GS_MMA7660)
376     {
377         .type           = "gs_mma7660",
378         .addr           = 0x4c,
379         .flags          = 0,
380         .irq            = RK2818_PIN_PE3,
381     },
382 #endif
383         {},
384 };
385
386 static struct i2c_board_info __initdata board_i2c2_devices[] = {
387
388 };
389 static struct i2c_board_info __initdata board_i2c3_devices[] = {
390 #if defined (CONFIG_SND_SOC_WM8994)
391         {
392                 .type                   = "wm8994",
393                 .addr           = 0x1a,
394                 .flags                  = 0,
395         },
396 #endif
397 };      
398
399 static void spi_xpt2046_cs_control(u32 command)
400 {
401         if(command == 3)        
402             {
403             gpio_direction_output(RK2818_PIN_PF5, GPIO_LOW);
404             }
405         if(command == 0)
406             {
407             gpio_direction_output(RK2818_PIN_PF5, GPIO_HIGH);
408             }
409 }
410
411 struct rk2818_spi_chip spi_xpt2046_info = {
412         .cs_control = spi_xpt2046_cs_control,
413 };
414
415
416 /*****************************************************************************************
417  * camera  devices
418  *author: ddl@rock-chips.com
419  *****************************************************************************************/ 
420 #define RK2818_CAM_POWER_PIN    FPGA_PIO1_05//SPI_GPIO_P1_05
421 #define RK2818_CAM_RESET_PIN    FPGA_PIO1_14//SPI_GPIO_P1_14    
422
423 static int rk28_sensor_init(void);
424 static int rk28_sensor_deinit(void);
425
426 struct rk28camera_platform_data rk28_camera_platform_data = {
427     .init = rk28_sensor_init,
428     .deinit = rk28_sensor_deinit,
429     .gpio_res = {
430         {
431             .gpio_reset = RK2818_CAM_RESET_PIN,
432             .gpio_power = RK2818_CAM_POWER_PIN,
433             .dev_name = "ov2655"
434         }, {
435             .gpio_reset = 0xFFFFFFFF,
436             .gpio_power = 0xFFFFFFFF,
437             .dev_name = NULL
438         }
439     }
440 };
441
442 static int rk28_sensor_init(void)
443 {
444     int ret = 0, i;
445     unsigned int camera_reset=0xffffffff,camera_power=0xffffffff;
446
447     printk("\n%s....%d    ******** ddl *********\n",__FUNCTION__,__LINE__);
448     
449     for (i=0; i<2; i++) { 
450         camera_reset = rk28_camera_platform_data.gpio_res[i].gpio_reset;
451         camera_power = rk28_camera_platform_data.gpio_res[i].gpio_power; 
452         
453         if (camera_power != 0xffffffff) {            
454             ret = gpio_request(camera_power, "camera power");
455             if (ret)
456                 continue;
457                 
458             gpio_set_value(camera_reset, 1);
459             gpio_direction_output(camera_power, 0);   
460         }
461         
462         if (camera_reset != 0xffffffff) {
463             ret = gpio_request(camera_reset, "camera reset");
464             if (ret) {
465                 if (camera_power != 0xffffffff) 
466                     gpio_free(camera_power);    
467
468                 continue;
469             }
470
471             gpio_set_value(camera_reset, 0);
472             gpio_direction_output(camera_reset, 0);            
473         }
474     }
475     
476     return 0;
477 }
478
479 static int rk28_sensor_deinit(void)
480 {
481     unsigned int i;
482     unsigned int camera_reset=0xffffffff,camera_power=0xffffffff;
483
484     printk("\n%s....%d    ******** ddl *********\n",__FUNCTION__,__LINE__); 
485    
486     for (i=0; i<2; i++) { 
487         camera_reset = rk28_camera_platform_data.gpio_res[i].gpio_reset;
488         camera_power = rk28_camera_platform_data.gpio_res[i].gpio_power; 
489         
490         if (camera_power != 0xffffffff){
491             gpio_direction_input(camera_power);
492             gpio_free(camera_power);    
493         }
494         
495         if (camera_reset != 0xffffffff)  {
496             gpio_direction_input(camera_reset);
497             gpio_free(camera_reset);    
498         }
499     }
500
501     return 0;
502 }
503
504
505 static int rk28_sensor_power(struct device *dev, int on)
506 {
507     unsigned int camera_reset=0xffffffff,camera_power=0xffffffff;
508     
509     if(rk28_camera_platform_data.gpio_res[0].dev_name &&  (strcmp(rk28_camera_platform_data.gpio_res[0].dev_name, dev_name(dev)) == 0)) {
510         camera_reset = rk28_camera_platform_data.gpio_res[0].gpio_reset;
511         camera_power = rk28_camera_platform_data.gpio_res[0].gpio_power;
512     } 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)) {
513         camera_reset = rk28_camera_platform_data.gpio_res[1].gpio_reset;
514         camera_power = rk28_camera_platform_data.gpio_res[1].gpio_power;
515     }
516
517     if (camera_reset != 0xffffffff) {
518         gpio_set_value(camera_reset, !on);
519         //printk("\n%s..%s..ResetPin=%d ..PinLevel = %x   ******** ddl *********\n",__FUNCTION__,dev_name(dev),camera_reset, on);
520     }
521     if (camera_power != 0xffffffff)  {       
522         gpio_set_value(camera_power, !on);
523         printk("\n%s..%s..PowerPin=%d ..PinLevel = %x   ******** ddl *********\n",__FUNCTION__,dev_name(dev), camera_power, !on);
524     }
525     if (camera_reset != 0xffffffff) {
526         msleep(3);          /* delay 3 ms */
527         gpio_set_value(camera_reset,on);
528         printk("\n%s..%s..ResetPin= %d..PinLevel = %x   ******** ddl *********\n",__FUNCTION__,dev_name(dev), camera_reset, on);
529     }      
530     return 0;
531 }
532
533  
534 #define OV2655_IIC_ADDR             0x60
535 static struct i2c_board_info rk2818_i2c_cam_info[] = {
536 #ifdef CONFIG_SOC_CAMERA_OV2655
537         {
538                 I2C_BOARD_INFO("ov2655", OV2655_IIC_ADDR>>1)
539         },
540 #endif  
541 };
542
543 struct soc_camera_link rk2818_iclink = {
544         .bus_id         = RK28_CAM_PLATFORM_DEV_ID,
545         .power          = rk28_sensor_power,
546         .board_info     = &rk2818_i2c_cam_info[0],
547         .i2c_adapter_id = 2,
548 #ifdef CONFIG_SOC_CAMERA_OV2655 
549         .module_name    = "ov2655",
550 #endif  
551 };
552
553
554 /*****************************************************************************************
555  * SPI devices
556  *author: lhh
557  *****************************************************************************************/
558 static struct spi_board_info board_spi_devices[] = {
559 #if defined(CONFIG_SPI_FPGA)
560         {       /* fpga ice65l08xx */
561                 .modalias       = "spi_fpga",
562                 .chip_select    = 1,
563                 .max_speed_hz   = 8 * 1000 * 1000,
564                 .bus_num        = 0,
565                 .mode   = SPI_MODE_0,
566         },
567 #endif
568 #if defined(CONFIG_ENC28J60)    
569         {       /* net chip */
570                 .modalias       = "enc28j60",
571                 .chip_select    = 1,
572                 .max_speed_hz   = 12 * 1000 * 1000,
573                 .bus_num        = 0,
574                 .mode   = SPI_MODE_0,
575         },
576 #endif  
577 #if defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)\
578     ||defined(CONFIG_TOUCHSCREEN_XPT2046_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
579         {
580                 .modalias       = "xpt2046_ts",
581                 .chip_select    = 2,
582                 .max_speed_hz   = 125 * 1000 * 26,/* (max sample rate @ 3V) * (cmd + data + overhead) */
583                 .bus_num        = 0,
584                 .controller_data = &spi_xpt2046_info,
585                 .irq = RK2818_PIN_PE1,
586         },
587 #endif
588 }; 
589
590 /*rk2818_fb gpio information*/
591 static struct rk2818_fb_gpio rk2818_fb_gpio_info = {
592     .display_on = (GPIO_LOW<<16)|RK2818_PIN_PA2,
593     .lcd_standby = 0,
594     .mcu_fmk_pin = 0,
595 };
596
597 /*rk2818_fb iomux information*/
598 static struct rk2818_fb_iomux rk2818_fb_iomux_info = {
599     .data16     = GPIOC_LCDC16BIT_SEL_NAME,
600     .data18     = GPIOC_LCDC18BIT_SEL_NAME,
601     .data24     = GPIOC_LCDC24BIT_SEL_NAME,
602     .den        = CXGPIO_LCDDEN_SEL_NAME,
603     .vsync      = CXGPIO_LCDVSYNC_SEL_NAME,
604     .mcu_fmk    = 0,
605 };
606 /*rk2818_fb*/
607 struct rk2818_fb_mach_info rk2818_fb_mach_info = {
608     .gpio = &rk2818_fb_gpio_info,
609     .iomux = &rk2818_fb_iomux_info,
610 };
611
612 struct rk2818bl_info rk2818_bl_info = {
613         .pwm_id   = 0,
614         .pw_pin   = GPIO_HIGH | (RK2818_PIN_PF3<< 8) ,
615         .bl_ref   = 0,
616         .pw_iomux = GPIOF34_UART3_SEL_NAME,
617 };
618
619 #ifdef CONFIG_DM9000
620 #define NET_INT_PIN RK2818_PIN_PA1
621 /*dm9000 gpio set*/
622 int dm9k_gpio_set(void)
623 {
624         //cs
625 #ifdef CONFIG_DM9000_CHIP_SELECT
626         switch (CONFIG_DM9000_CHIP_SELECT) {
627         case 1:
628                 rk2818_mux_api_set(GPIOA5_FLASHCS1_SEL_NAME, IOMUXB_FLASH_CS1);
629                 break;
630         case 2:
631                 rk2818_mux_api_set(GPIOA6_FLASHCS2_SEL_NAME, IOMUXB_FLASH_CS2);
632                 break;
633         case 3:
634                 rk2818_mux_api_set(GPIOA7_FLASHCS3_SEL_NAME, IOMUXB_FLASH_CS3);
635                 break;
636         case 4:
637         case 5:
638                 rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL1_NAME, IOMUXA_FLASH_CS45);      
639                 break;
640         case 6:
641         case 7:
642                 rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL_NAME, IOMUXA_FLASH_CS67);  
643                 break;
644         default:
645                 break;
646         }
647 #endif
648
649         //int
650         rk2818_mux_api_set(GPIOA1_HOSTDATA17_SEL_NAME, IOMUXB_GPIO0_A1);
651         if (gpio_request(NET_INT_PIN, "dm9000 interrupt")) {
652                 gpio_free(NET_INT_PIN);         
653                 rk2818_mux_api_mode_resume(GPIOA1_HOSTDATA17_SEL_NAME);
654                 printk("[fun:%s line:%d], request gpio for net interrupt fail\n", __func__,__LINE__);
655                 goto err;
656         }       
657         gpio_pull_updown(NET_INT_PIN, GPIOPullDown);
658         gpio_direction_input(NET_INT_PIN);
659         return 0;
660 err:
661         
662 #ifdef CONFIG_DM9000_CHIP_SELECT
663         switch (CONFIG_DM9000_CHIP_SELECT) {
664         case 1:
665                 rk2818_mux_api_mode_resume(GPIOA5_FLASHCS1_SEL_NAME);
666                 break;
667         case 2:
668                 rk2818_mux_api_mode_resume(GPIOA6_FLASHCS2_SEL_NAME);
669                 break;
670         case 3:
671                 rk2818_mux_api_mode_resume(GPIOA7_FLASHCS3_SEL_NAME);
672                 break;
673         case 4:
674         case 5:
675                 rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL1_NAME); 
676                 break;
677         case 6:
678         case 7:
679                 rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL_NAME);  
680                 break;
681         default:
682                 break;
683         }
684 #endif
685         return -1;
686 }
687 void dm9k_gpio_free(void)
688 {
689         gpio_free(NET_INT_PIN);
690         rk2818_mux_api_mode_resume(GPIOA1_HOSTDATA17_SEL_NAME);
691 #ifdef CONFIG_DM9000_CHIP_SELECT
692         switch (CONFIG_DM9000_CHIP_SELECT) {
693         case 1:
694                 rk2818_mux_api_mode_resume(GPIOA5_FLASHCS1_SEL_NAME);
695                 break;
696         case 2:
697                 rk2818_mux_api_mode_resume(GPIOA6_FLASHCS2_SEL_NAME);
698                 break;
699         case 3:
700                 rk2818_mux_api_mode_resume(GPIOA7_FLASHCS3_SEL_NAME);
701                 break;
702         case 4:
703         case 5:
704                 rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL1_NAME); 
705                 break;
706         case 6:
707         case 7:
708                 rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL_NAME);  
709                 break;
710         default:
711                 break;
712         }
713 #endif
714 }
715
716 struct dm9000_plat_data dm9k_platdata = {       
717         .flags = DM9000_PLATF_8BITONLY,
718         .pin_int = NET_INT_PIN,
719         .net_gpio_set = dm9k_gpio_set,
720         .net_gpio_free = dm9k_gpio_free,
721 };
722 #endif
723
724 static struct platform_device *devices[] __initdata = {
725         &rk2818_device_uart1,
726 #ifdef CONFIG_I2C0_RK2818
727         &rk2818_device_i2c0,
728 #endif
729 #ifdef CONFIG_I2C1_RK2818
730         &rk2818_device_i2c1,
731 #endif
732 #ifdef CONFIG_SDMMC0_RK2818     
733         &rk2818_device_sdmmc0,
734 #endif
735 #ifdef CONFIG_SDMMC1_RK2818
736         &rk2818_device_sdmmc1,
737 #endif
738         &rk2818_device_spim,
739         &rk2818_device_i2s,
740 #if defined(CONFIG_ANDROID_PMEM)
741         &rk2818_device_pmem,
742         &rk2818_device_pmem_dsp,
743 #endif
744         &rk2818_device_adc,
745         &rk2818_device_adckey,
746         &rk2818_device_battery,
747     &rk2818_device_fb,    
748     &rk2818_device_backlight,
749         &rk2818_device_dsp,
750
751 #ifdef CONFIG_VIDEO_RK2818
752         &rk2818_device_camera,      /* ddl@rock-chips.com : camera support  */
753         &rk2818_soc_camera_pdrv,
754  #endif
755  
756 #ifdef CONFIG_MTD_NAND_RK2818
757         &rk2818_nand_device,
758 #endif
759 #ifdef CONFIG_DM9000
760         &rk2818_device_dm9k,
761 #endif
762
763 #ifdef CONFIG_DWC_OTG
764         &rk2818_device_dwc_otg,
765 #endif
766 #ifdef CONFIG_RK2818_HOST11
767         &rk2818_device_host11,
768 #endif
769 #ifdef CONFIG_USB_ANDROID
770         &android_usb_device,
771         &usb_mass_storage_device,
772 #endif
773 #ifdef CONFIG_ANDROID_TIMED_GPIO
774         &rk28_device_vibrator,
775 #endif
776 };
777
778 extern struct sys_timer rk2818_timer;
779 #define POWER_PIN       RK2818_PIN_PB1
780 static void rk2818_power_on(void)
781 {
782         int ret;
783         ret = gpio_request(POWER_PIN, NULL);
784         if (ret) {
785                 printk("failed to request power_off gpio\n");
786                 goto err_free_gpio;
787         }
788
789         gpio_pull_updown(POWER_PIN, GPIOPullUp);
790         ret = gpio_direction_output(POWER_PIN, GPIO_HIGH);
791         if (ret) {
792                 printk("failed to set power_off gpio output\n");
793                 goto err_free_gpio;
794         }
795
796         gpio_set_value(POWER_PIN, 1);/*power on*/
797         
798 err_free_gpio:
799         gpio_free(POWER_PIN);
800 }
801
802 static void rk2818_power_off(void)
803 {
804         printk("shut down system now ...\n");
805         gpio_set_value(POWER_PIN, 0);/*power down*/
806 }
807
808 void lcd_set_iomux(u8 enable)
809 {
810     int ret=-1;
811
812     if(enable)
813     {
814         rk2818_mux_api_set(GPIOH6_IQ_SEL_NAME, 0);
815         ret = gpio_request(RK2818_PIN_PH6, NULL); 
816         if(ret != 0)
817         {
818             gpio_free(RK2818_PIN_PH6);
819             printk(">>>>>> lcd cs gpio_request err \n ");           
820             goto pin_err;
821         }  
822         
823         rk2818_mux_api_set(GPIOE_I2C0_SEL_NAME, 1);    
824
825         ret = gpio_request(RK2818_PIN_PE4, NULL); 
826         if(ret != 0)
827         {
828             gpio_free(RK2818_PIN_PE4);
829             printk(">>>>>> lcd clk gpio_request err \n "); 
830             goto pin_err;
831         }  
832         
833         ret = gpio_request(RK2818_PIN_PE5, NULL); 
834         if(ret != 0)
835         {
836             gpio_free(RK2818_PIN_PE5);
837             printk(">>>>>> lcd txd gpio_request err \n "); 
838             goto pin_err;
839         }        
840     }
841     else
842     {
843          gpio_free(RK2818_PIN_PH6); 
844          //rk2818_mux_api_set(GPIOH6_IQ_SEL_NAME, 1);
845          rk2818_mux_api_mode_resume(GPIOH6_IQ_SEL_NAME);
846
847          gpio_free(RK2818_PIN_PE4);   
848          gpio_free(RK2818_PIN_PE5); 
849          //rk2818_mux_api_set(GPIOE_I2C0_SEL_NAME, 0);
850          rk2818_mux_api_mode_resume(GPIOE_I2C0_SEL_NAME);
851     }
852     return ;
853 pin_err:
854     return ;
855
856 }
857
858 struct lcd_td043mgea1_data lcd_td043mgea1 = {
859     .pin_txd    = RK2818_PIN_PE4,
860     .pin_clk    = RK2818_PIN_PE5,
861     .pin_cs     = RK2818_PIN_PH6,
862     .screen_set_iomux = lcd_set_iomux,
863 };
864
865 //      adc      ---> key       
866 static  ADC_keyst gAdcValueTab[] = 
867 {
868         {0x5c,  AD2KEY1},///VOLUME_DOWN
869         {0xbf,  AD2KEY2},///VOLUME_UP
870         {0x115, AD2KEY3},///MENU
871         {0x177, AD2KEY4},///HOME
872         {0x1d3, AD2KEY5},///BACK
873         {0x290, AD2KEY6},///CALL
874         {0x230, AD2KEY7},///SEARCH
875         {0,     0}///table end
876 };
877
878 static unsigned char gInitKeyCode[] = 
879 {
880         AD2KEY1,AD2KEY2,AD2KEY3,AD2KEY4,AD2KEY5,AD2KEY6,AD2KEY7,
881         ENDCALL,KEYSTART,KEY_WAKEUP,
882 };
883
884 struct adc_key_data rk2818_adc_key = {
885     .pin_playon     = RK2818_PIN_PA3,
886     .playon_level   = 1,
887     .adc_empty      = 900,
888     .adc_invalid    = 20,
889     .adc_drift      = 50,
890     .adc_chn        = 1,
891     .adc_key_table  = gAdcValueTab,
892     .initKeyCode    = gInitKeyCode,
893     .adc_key_cnt    = 10,
894 };
895
896 static void __init machine_rk2818_init_irq(void)
897 {
898         rk2818_init_irq();
899         rk2818_gpio_init(rk2818_gpioBank, 8);
900         rk2818_gpio_irq_setup();
901 }
902
903 static void __init machine_rk2818_board_init(void)
904 {       
905         rk2818_power_on();
906         pm_power_off = rk2818_power_off;
907 #ifdef CONFIG_I2C0_RK2818
908         i2c_register_board_info(default_i2c0_data.bus_num, board_i2c0_devices,
909                         ARRAY_SIZE(board_i2c0_devices));
910 #endif
911 #ifdef CONFIG_I2C1_RK2818
912         i2c_register_board_info(default_i2c1_data.bus_num, board_i2c1_devices,
913                         ARRAY_SIZE(board_i2c1_devices));
914 #endif
915 #ifdef CONFIG_SPI_I2C
916         i2c_register_board_info(default_i2c2_data.bus_num, board_i2c2_devices,
917                         ARRAY_SIZE(board_i2c2_devices));
918         i2c_register_board_info(default_i2c3_data.bus_num, board_i2c3_devices,
919                         ARRAY_SIZE(board_i2c3_devices));
920 #endif
921         platform_add_devices(devices, ARRAY_SIZE(devices));     
922         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
923         rk2818_mux_api_set(GPIOB4_SPI0CS0_MMC0D4_NAME,IOMUXA_GPIO0_B4); //IOMUXA_SPI0_CSN0);//use for gpio SPI CS0
924         rk2818_mux_api_set(GPIOB0_SPI0CSN1_MMC1PCA_NAME,IOMUXA_GPIO0_B0); //IOMUXA_SPI0_CSN1);//use for gpio SPI CS1
925         rk2818_mux_api_set(GPIOB_SPI0_MMC0_NAME,IOMUXA_SPI0);//use for SPI CLK SDI SDO
926
927         rk2818_mux_api_set(GPIOF5_APWM3_DPWM3_NAME,IOMUXB_GPIO1_B5);
928         if(0 != gpio_request(RK2818_PIN_PF5, NULL))
929     {
930         gpio_free(RK2818_PIN_PF5);
931         printk(">>>>>> RK2818_PIN_PF5 gpio_request err \n "); 
932     } 
933 }
934
935 static void __init machine_rk2818_mapio(void)
936 {
937         iotable_init(rk2818_io_desc, ARRAY_SIZE(rk2818_io_desc));
938         rk2818_clock_init();
939         rk2818_iomux_init();    
940 }
941
942 MACHINE_START(RK2818, "RK28board")
943
944 /* UART for LL DEBUG */
945         .phys_io        = 0x18002000,
946         .io_pg_offst    = ((0xFF100000) >> 18) & 0xfffc,
947         .boot_params    = RK2818_SDRAM_PHYS + 0xf8000,
948         .map_io         = machine_rk2818_mapio,
949         .init_irq       = machine_rk2818_init_irq,
950         .init_machine   = machine_rk2818_board_init,
951         .timer          = &rk2818_timer,
952 MACHINE_END
953