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-phonesdk.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
38 #include <linux/mtd/nand.h>
39 #include <linux/mtd/partitions.h>
40 #include <linux/dm9000.h>
41
42 #include "devices.h"
43
44
45 /* --------------------------------------------------------------------
46  *  ÉùÃ÷ÁËrk2818_gpioBankÊý×飬²¢¶¨ÒåÁËGPIO¼Ä´æÆ÷×éIDºÍ¼Ä´æÆ÷»ùµØÖ·¡£
47  * -------------------------------------------------------------------- */
48
49 static struct rk2818_gpio_bank rk2818_gpioBank[] = {
50                 {
51                 .id             = RK2818_ID_PIOA,
52                 .offset         = RK2818_GPIO0_BASE,
53                 .clock          = NULL,
54         }, 
55                 {
56                 .id             = RK2818_ID_PIOB,
57                 .offset         = RK2818_GPIO0_BASE,
58                 .clock          = NULL,
59         }, 
60                 {
61                 .id             = RK2818_ID_PIOC,
62                 .offset         = RK2818_GPIO0_BASE,
63                 .clock          = NULL,
64         }, 
65                 {
66                 .id             = RK2818_ID_PIOD,
67                 .offset         = RK2818_GPIO0_BASE,
68                 .clock          = NULL,
69         },
70                 {
71                 .id             = RK2818_ID_PIOE,
72                 .offset         = RK2818_GPIO1_BASE,
73                 .clock          = NULL,
74         },
75                 {
76                 .id             = RK2818_ID_PIOF,
77                 .offset         = RK2818_GPIO1_BASE,
78                 .clock          = NULL,
79         },
80                 {
81                 .id             = RK2818_ID_PIOG,
82                 .offset         = RK2818_GPIO1_BASE,
83                 .clock          = NULL,
84         },
85                 {
86                 .id             = RK2818_ID_PIOH,
87                 .offset         = RK2818_GPIO1_BASE,
88                 .clock          = NULL,
89         }
90 };
91
92 //IOÓ³É䷽ʽÃèÊö £¬Ã¿¸öΪһ¶ÎÏßÐÔÁ¬ÐøÓ³Éä
93 static struct map_desc rk2818_io_desc[] __initdata = {
94
95         {
96                 .virtual        = RK2818_MCDMA_BASE,                                    //ÐéÄâµØÖ·
97                 .pfn            = __phys_to_pfn(RK2818_MCDMA_PHYS),    //ÎïÀíµØÖ·£¬ÐëÓëÒ³±í¶ÔÆë
98                 .length         = RK2818_MCDMA_SIZE,                                                    //³¤¶È
99                 .type           = MT_DEVICE                                                     //Ó³É䷽ʽ
100         },
101         
102         {
103                 .virtual        = RK2818_DWDMA_BASE,                                    
104                 .pfn            = __phys_to_pfn(RK2818_DWDMA_PHYS),    
105                 .length         = RK2818_DWDMA_SIZE,                                            
106                 .type           = MT_DEVICE                                                     
107         },
108         
109         {
110                 .virtual        = RK2818_INTC_BASE,                                     
111                 .pfn            = __phys_to_pfn(RK2818_INTC_PHYS),   
112                 .length         = RK2818_INTC_SIZE,                                     
113                 .type           = MT_DEVICE                                             
114         },
115
116         {
117                 .virtual        = RK2818_NANDC_BASE,                            
118                 .pfn            = __phys_to_pfn(RK2818_NANDC_PHYS),      
119                 .length         = RK2818_NANDC_SIZE,                            
120                 .type           = MT_DEVICE                                     
121         },
122
123         {
124                 .virtual        = RK2818_SDRAMC_BASE,
125                 .pfn            = __phys_to_pfn(RK2818_SDRAMC_PHYS),
126                 .length         = RK2818_SDRAMC_SIZE,
127                 .type           = MT_DEVICE
128         },
129
130         {
131                 .virtual        = RK2818_ARMDARBITER_BASE,                                      
132                 .pfn            = __phys_to_pfn(RK2818_ARMDARBITER_PHYS),    
133                 .length         = RK2818_ARMDARBITER_SIZE,                                              
134                 .type           = MT_DEVICE                                                     
135         },
136         
137         {
138                 .virtual        = RK2818_APB_BASE,
139                 .pfn            = __phys_to_pfn(RK2818_APB_PHYS),
140                 .length         = 0xa0000,                     
141                 .type           = MT_DEVICE
142         },
143         
144         {
145                 .virtual        = RK2818_WDT_BASE,
146                 .pfn            = __phys_to_pfn(RK2818_WDT_PHYS),
147                 .length         = 0xa0000,                      ///apb bus i2s i2c spi no map in this
148                 .type           = MT_DEVICE
149         },
150 };
151 /*****************************************************************************************
152  * SDMMC devices
153  *author: kfx
154 *****************************************************************************************/
155  void rk2818_sdmmc0_cfg_gpio(struct platform_device *dev)
156 {
157         rk2818_mux_api_set(GPIOF3_APWM1_MMC0DETN_NAME, IOMUXA_SDMMC1_DETECT_N);
158         rk2818_mux_api_set(GPIOH_MMC0D_SEL_NAME, IOMUXA_SDMMC0_DATA123);
159         rk2818_mux_api_set(GPIOH_MMC0_SEL_NAME, IOMUXA_SDMMC0_CMD_DATA0_CLKOUT);
160 }
161
162 void rk2818_sdmmc1_cfg_gpio(struct platform_device *dev)
163 {
164         rk2818_mux_api_set(GPIOG_MMC1_SEL_NAME, IOMUXA_SDMMC1_CMD_DATA0_CLKOUT);
165         rk2818_mux_api_set(GPIOG_MMC1D_SEL_NAME, IOMUXA_SDMMC1_DATA123);
166 #if 0
167         /* wifi power up (gpio control) */
168         rk2818_mux_api_set(GPIOH7_HSADCCLK_SEL_NAME,IOMUXB_GPIO1_D7);
169         rk2818_mux_api_set(GPIOF5_APWM3_DPWM3_NAME,IOMUXB_GPIO1_B5);
170         gpio_request(RK2818_PIN_PH7, "sdio");
171         gpio_direction_output(RK2818_PIN_PH7,GPIO_HIGH);
172 #endif
173
174 }
175 #define CONFIG_SDMMC0_USE_DMA
176 #define CONFIG_SDMMC1_USE_DMA
177 struct rk2818_sdmmc_platform_data default_sdmmc0_data = {
178         .host_ocr_avail = (MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
179                                            MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33| 
180                                            MMC_VDD_33_34|MMC_VDD_34_35| MMC_VDD_35_36),
181         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
182         .cfg_gpio = rk2818_sdmmc0_cfg_gpio,
183         .no_detect = 0,
184         .dma_name = "sd_mmc",
185 #ifdef CONFIG_SDMMC0_USE_DMA
186         .use_dma  = 1,
187 #else
188         .use_dma = 0,
189 #endif
190 };
191 struct rk2818_sdmmc_platform_data default_sdmmc1_data = {
192         .host_ocr_avail = (MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|
193                                            MMC_VDD_29_30|MMC_VDD_30_31|MMC_VDD_31_32|
194                                            MMC_VDD_32_33|MMC_VDD_33_34),
195         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_SDIO_IRQ|
196                                    MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
197         .cfg_gpio = rk2818_sdmmc1_cfg_gpio,
198         .no_detect = 1,
199         .dma_name = "sdio",
200 #ifdef CONFIG_SDMMC1_USE_DMA
201         .use_dma  = 1,
202 #else
203         .use_dma = 0,
204 #endif
205 };
206
207 /*****************************************************************************************
208  * extern gpio devices
209  *author: xxx
210  *****************************************************************************************/
211 #if defined (CONFIG_GPIO_PCA9554)
212 struct rk2818_gpio_expander_info  extern_gpio_settinginfo[] = {
213         {
214                 .gpio_num               =RK2818_PIN_PI0,
215                 .pin_type           = GPIO_IN,
216                 //.pin_value                    =GPIO_HIGH,
217          },
218
219         {
220                 .gpio_num               =RK2818_PIN_PI4,// tp3
221                 .pin_type           = GPIO_IN,
222                 //.pin_value                    =GPIO_HIGH,
223          },
224          
225          {
226                 .gpio_num               =RK2818_PIN_PI5,//tp4
227                 .pin_type           = GPIO_IN,
228                 //.pin_value                    =GPIO_HIGH,
229          },
230          {
231                 .gpio_num               =RK2818_PIN_PI6,//tp2
232                 .pin_type           = GPIO_OUT,
233                 //.pin_value                    =GPIO_HIGH,
234          },
235          {
236                 .gpio_num               =RK2818_PIN_PI7,//tp1
237                 .pin_type           = GPIO_OUT,
238                 .pin_value                      =GPIO_HIGH,
239          },
240
241
242                 
243 };
244
245 struct pca9554_platform_data rk2818_pca9554_data={
246         .gpio_base=GPIOS_EXPANDER_BASE,
247         .gpio_pin_num=CONFIG_EXPANDED_GPIO_NUM,
248         .gpio_irq_start=NR_AIC_IRQS + 2*NUM_GROUP,
249         .irq_pin_num=CONFIG_EXPANDED_GPIO_IRQ_NUM,
250         .pca9954_irq_pin=RK2818_PIN_PE2,
251         .settinginfo=extern_gpio_settinginfo,
252         .settinginfolen=ARRAY_SIZE(extern_gpio_settinginfo),
253         .names="pca9554",
254 };
255 #endif
256
257 /*****************************************************************************************
258  * I2C devices
259  *author: kfx
260 *****************************************************************************************/
261  void rk2818_i2c0_cfg_gpio(struct platform_device *dev)
262 {
263         rk2818_mux_api_set(GPIOE_I2C0_SEL_NAME, IOMUXA_I2C0);
264 }
265
266 void rk2818_i2c1_cfg_gpio(struct platform_device *dev)
267 {
268         rk2818_mux_api_set(GPIOE_U1IR_I2C1_NAME, IOMUXA_I2C1);
269 }
270 struct rk2818_i2c_platform_data default_i2c0_data = { 
271         .bus_num    = 0,
272         .flags      = 0,
273         .slave_addr = 0xff,
274         .scl_rate  = 400*1000,
275         .cfg_gpio = rk2818_i2c0_cfg_gpio,
276 };
277 struct rk2818_i2c_platform_data default_i2c1_data = { 
278 #ifdef CONFIG_I2C0_RK2818
279         .bus_num    = 1,
280 #else
281         .bus_num        = 0,
282 #endif
283         .flags      = 0,
284         .slave_addr = 0xff,
285         .scl_rate  = 400*1000,
286         .cfg_gpio = rk2818_i2c1_cfg_gpio,
287 };
288
289 struct rk2818_i2c_spi_data default_i2c2_data = { 
290         .bus_num    = 2,
291         .flags      = 0,
292         .slave_addr = 0xff,
293         .scl_rate  = 400*1000,
294         
295 };
296 struct rk2818_i2c_spi_data default_i2c3_data = { 
297
298         .bus_num    = 3,
299         .flags      = 0,
300         .slave_addr = 0xff,
301         .scl_rate  = 400*1000,
302         
303 };
304 static struct i2c_board_info __initdata board_i2c0_devices[] = {
305 #if defined (CONFIG_RK1000_CONTROL)
306         {
307                 .type                   = "rk1000_control",
308                 .addr           = 0x40,
309                 .flags                  = 0,
310         },
311 #endif
312
313 #if defined (CONFIG_RK1000_TVOUT)
314         {
315                 .type                   = "rk1000_tvout",
316                 .addr           = 0x42,
317                 .flags                  = 0,
318         },
319 #endif
320 #if defined (CONFIG_SND_SOC_RK1000)
321         {
322                 .type                   = "rk1000_i2c_codec",
323                 .addr           = 0x60,
324                 .flags                  = 0,
325         },
326 #endif
327 #if defined (CONFIG_SND_SOC_WM8988)
328         {
329                 .type                   = "wm8988",
330                 .addr           = 0x1a,
331                 .flags                  = 0,
332         }
333 #endif  
334 };
335 static struct i2c_board_info __initdata board_i2c1_devices[] = {
336 #if defined (CONFIG_RTC_HYM8563)
337         {
338                 .type                   = "rtc_hym8563",
339                 .addr           = 0x51,
340                 .flags                  = 0,
341         },
342 #endif
343 #if defined (CONFIG_FM_QN8006)
344         {
345                 .type                   = "fm_qn8006",
346                 .addr           = 0x2b, 
347                 .flags                  = 0,
348         },
349 #endif
350 #if defined (CONFIG_GPIO_PCA9554)
351         {
352                 .type                   = "extend_gpio_pca9554",
353                 .addr           = 0x3c, 
354                 .flags                  = 0,
355                 .platform_data=&rk2818_pca9554_data.gpio_base,
356         },
357 #endif
358 #if defined (CONFIG_PMIC_LP8725)
359         {
360                 .type                   = "lp8725",
361                 .addr           = 0x79, 
362                 .flags                  = 0,
363         },
364 #endif
365 #if defined (CONFIG_GS_MMA7660)
366     {
367         .type           = "gs_mma7660",
368         .addr           = 0x4c,
369         .flags          = 0,
370         .irq            = RK2818_PIN_PE3,
371     },
372 #endif
373         {},
374 };
375
376 static struct i2c_board_info __initdata board_i2c2_devices[] = {
377
378 };
379 static struct i2c_board_info __initdata board_i2c3_devices[] = {
380 #if defined (CONFIG_SND_SOC_WM8994)
381         {
382                 .type                   = "wm8994",
383                 .addr           = 0x1a,
384                 .flags                  = 0,
385         },
386 #endif
387 };      
388
389 /*****************************************************************************************
390  * SPI devices
391  *author: lhh
392  *****************************************************************************************/
393 static struct spi_board_info board_spi_devices[] = {
394 #if defined(CONFIG_SPI_FPGA)
395         {       /* fpga ice65l08xx */
396                 .modalias       = "spi_fpga",
397                 .chip_select    = 1,
398                 .max_speed_hz   = 8 * 1000 * 1000,
399                 .bus_num        = 0,
400                 .mode   = SPI_MODE_0,
401         },
402 #endif
403 #if defined(CONFIG_ENC28J60)    
404         {       /* net chip */
405                 .modalias       = "enc28j60",
406                 .chip_select    = 1,
407                 .max_speed_hz   = 12 * 1000 * 1000,
408                 .bus_num        = 0,
409                 .mode   = SPI_MODE_0,
410         },
411 #endif  
412 #if defined(CONFIG_TOUCHSCREEN_XPT2046_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
413         {
414                 .modalias       = "xpt2046_ts",
415                 .chip_select    = 0,
416                 .max_speed_hz   = 125 * 1000 * 26,/* (max sample rate @ 3V) * (cmd + data + overhead) */
417                 .bus_num        = 0,
418                 .irq            = RK2818_PIN_PE3,
419         },
420 #endif
421 }; 
422
423 /*rk2818_fb gpio information*/
424 static struct rk2818_fb_gpio rk2818_fb_gpio_info = {
425     .display_on = (GPIO_LOW<<16)|RK2818_PIN_PA2,
426     .lcd_standby = 0,
427     .mcu_fmk_pin = 0,
428 };
429
430 /*rk2818_fb iomux information*/
431 static struct rk2818_fb_iomux rk2818_fb_iomux_info = {
432     .data16     = GPIOC_LCDC16BIT_SEL_NAME,
433     .data18     = GPIOC_LCDC18BIT_SEL_NAME,
434     .data24     = GPIOC_LCDC24BIT_SEL_NAME,
435     .den        = CXGPIO_LCDDEN_SEL_NAME,
436     .vsync      = CXGPIO_LCDVSYNC_SEL_NAME,
437     .mcu_fmk    = 0,
438 };
439 /*rk2818_fb*/
440 struct rk2818_fb_mach_info rk2818_fb_mach_info = {
441     .gpio = &rk2818_fb_gpio_info,
442     .iomux = &rk2818_fb_iomux_info,
443 };
444
445 struct rk2818bl_info rk2818_bl_info = {
446         .pwm_id   = 0,
447         .pw_pin   = GPIO_HIGH | (RK2818_PIN_PF4<< 8) ,
448         .bl_ref   = 0,
449         .pw_iomux = GPIOF34_UART3_SEL_NAME,
450 };
451
452 #ifdef CONFIG_DM9000
453 #define NET_INT_PIN RK2818_PIN_PA1
454 /*dm9000 gpio set*/
455 int dm9k_gpio_set(void)
456 {
457         //cs
458 #ifdef CONFIG_DM9000_CHIP_SELECT
459                 switch (CONFIG_DM9000_CHIP_SELECT) {
460                 case 1:
461                         rk2818_mux_api_set(GPIOA5_FLASHCS1_SEL_NAME, IOMUXB_FLASH_CS1);
462                         break;
463                 case 2:
464                         rk2818_mux_api_set(GPIOA6_FLASHCS2_SEL_NAME, IOMUXB_FLASH_CS2);
465                         break;
466                 case 3:
467                         rk2818_mux_api_set(GPIOA7_FLASHCS3_SEL_NAME, IOMUXB_FLASH_CS3);
468                         break;
469                 case 4:
470                 case 5:
471                         rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL1_NAME, IOMUXA_FLASH_CS45);      
472                         break;
473                 case 6:
474                 case 7:
475                         rk2818_mux_api_set(GPIOE_SPI1_FLASH_SEL_NAME, IOMUXA_FLASH_CS67);  
476                         break;
477                 default:
478                         break;
479                 }
480 #endif
481
482         //int
483         rk2818_mux_api_set(GPIOA1_HOSTDATA17_SEL_NAME, IOMUXB_GPIO0_A1);
484         if (gpio_request(NET_INT_PIN, "dm9000 interrupt")) {
485                 gpio_free(NET_INT_PIN);
486                 rk2818_mux_api_mode_resume(GPIOA1_HOSTDATA17_SEL_NAME);         
487                 printk("[fun:%s line:%d], request gpio for net interrupt fail\n", __func__,__LINE__);
488                 goto err;
489         }       
490         gpio_pull_updown(NET_INT_PIN, GPIOPullDown);
491         gpio_direction_input(NET_INT_PIN);
492         return 0;
493
494 err:            
495 #ifdef CONFIG_DM9000_CHIP_SELECT
496         switch (CONFIG_DM9000_CHIP_SELECT) {
497         case 1:
498                 rk2818_mux_api_mode_resume(GPIOA5_FLASHCS1_SEL_NAME);
499                 break;
500         case 2:
501                 rk2818_mux_api_mode_resume(GPIOA6_FLASHCS2_SEL_NAME);
502                 break;
503         case 3:
504                 rk2818_mux_api_mode_resume(GPIOA7_FLASHCS3_SEL_NAME);
505                 break;
506         case 4:
507         case 5:
508                 rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL1_NAME); 
509                 break;
510         case 6:
511         case 7:
512                 rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL_NAME);  
513                 break;
514         default:
515                 break;
516         }
517 #endif
518         return -1;
519 }
520 void dm9k_gpio_free(void)
521 {
522         gpio_free(NET_INT_PIN);
523         rk2818_mux_api_mode_resume(GPIOA1_HOSTDATA17_SEL_NAME);
524 #ifdef CONFIG_DM9000_CHIP_SELECT
525                 switch (CONFIG_DM9000_CHIP_SELECT) {
526                 case 1:
527                         rk2818_mux_api_mode_resume(GPIOA5_FLASHCS1_SEL_NAME);
528                         break;
529                 case 2:
530                         rk2818_mux_api_mode_resume(GPIOA6_FLASHCS2_SEL_NAME);
531                         break;
532                 case 3:
533                         rk2818_mux_api_mode_resume(GPIOA7_FLASHCS3_SEL_NAME);
534                         break;
535                 case 4:
536                 case 5:
537                         rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL1_NAME); 
538                         break;
539                 case 6:
540                 case 7:
541                         rk2818_mux_api_mode_resume(GPIOE_SPI1_FLASH_SEL_NAME);  
542                         break;
543                 default:
544                         break;
545                 }
546 #endif  
547 }
548
549 struct dm9000_plat_data dm9k_platdata = {       
550         .flags = DM9000_PLATF_8BITONLY,
551         .pin_int = NET_INT_PIN,
552         .net_gpio_set = dm9k_gpio_set,
553         .net_gpio_free = dm9k_gpio_free,
554 };
555 #endif
556
557 static struct platform_device *devices[] __initdata = {
558         &rk2818_device_uart1,
559 #ifdef CONFIG_I2C0_RK2818
560         &rk2818_device_i2c0,
561 #endif
562 #ifdef CONFIG_I2C1_RK2818
563         &rk2818_device_i2c1,
564 #endif
565 #ifdef CONFIG_SDMMC0_RK2818     
566         &rk2818_device_sdmmc0,
567 #endif
568 #ifdef CONFIG_SDMMC1_RK2818
569         &rk2818_device_sdmmc1,
570 #endif
571         &rk2818_device_spim,
572         &rk2818_device_i2s,
573 #if defined(CONFIG_ANDROID_PMEM)
574         &rk2818_device_pmem,
575         &rk2818_device_pmem_dsp,
576 #endif
577         &rk2818_device_adc,
578         &rk2818_device_adckey,
579         &rk2818_device_battery,
580     &rk2818_device_fb,    
581     &rk2818_device_backlight,
582         &rk2818_device_dsp,
583 #ifdef CONFIG_MTD_NAND_RK2818
584         &rk2818_nand_device,
585 #endif
586 #ifdef CONFIG_DM9000
587         &rk2818_device_dm9k,
588 #endif
589
590 #ifdef CONFIG_DWC_OTG
591         &rk2818_device_dwc_otg,
592 #endif
593 #ifdef CONFIG_RK2818_HOST11
594         &rk2818_device_host11,
595 #endif
596 #ifdef CONFIG_USB_ANDROID
597         &android_usb_device,
598         &usb_mass_storage_device,
599 #endif
600
601 };
602
603 extern struct sys_timer rk2818_timer;
604 #define POWER_PIN       RK2818_PIN_PB1
605 static void rk2818_power_on(void)
606 {
607         int ret;
608         ret = gpio_request(POWER_PIN, NULL);
609         if (ret) {
610                 printk("failed to request power_off gpio\n");
611                 goto err_free_gpio;
612         }
613
614         gpio_pull_updown(POWER_PIN, GPIOPullUp);
615         ret = gpio_direction_output(POWER_PIN, GPIO_HIGH);
616         if (ret) {
617                 printk("failed to set power_off gpio output\n");
618                 goto err_free_gpio;
619         }
620
621         gpio_set_value(POWER_PIN, 1);/*power on*/
622         
623 err_free_gpio:
624         gpio_free(POWER_PIN);
625 }
626
627 static void rk2818_power_off(void)
628 {
629         printk("shut down system now ...\n");
630         gpio_set_value(POWER_PIN, 0);/*power down*/
631 }
632
633 void lcd_set_iomux(u8 enable)
634 {
635     int ret=-1;
636     
637     if(enable)
638     {
639         rk2818_mux_api_set(CXGPIO_HSADC_SEL_NAME, 0);
640         ret = gpio_request(RK2818_PIN_PA4, NULL); 
641         if(0)//(ret != 0)
642         {
643             gpio_free(RK2818_PIN_PA4);
644             printk(">>>>>> lcd cs gpio_request err \n ");           
645             goto pin_err;
646         }  
647         
648         rk2818_mux_api_set(GPIOE_U1IR_I2C1_NAME, 0);    
649
650         ret = gpio_request(RK2818_PIN_PE7, NULL); 
651         if(0)//(ret != 0)
652         {
653             gpio_free(RK2818_PIN_PE7);
654             printk(">>>>>> lcd clk gpio_request err \n "); 
655             goto pin_err;
656         }  
657         
658         ret = gpio_request(RK2818_PIN_PE6, NULL); 
659         if(0)//(ret != 0)
660         {
661             gpio_free(RK2818_PIN_PE6);
662             printk(">>>>>> lcd txd gpio_request err \n "); 
663             goto pin_err;
664         }        
665     }
666     else
667     {
668          gpio_free(RK2818_PIN_PA4); 
669          //rk2818_mux_api_set(CXGPIO_HSADC_SEL_NAME, 1);
670          rk2818_mux_api_mode_resume(CXGPIO_HSADC_SEL_NAME);
671
672          gpio_free(RK2818_PIN_PE7);   
673          gpio_free(RK2818_PIN_PE6); 
674          //rk2818_mux_api_set(GPIOE_U1IR_I2C1_NAME, 2);
675          rk2818_mux_api_mode_resume(GPIOE_U1IR_I2C1_NAME);
676     }
677     return ;
678 pin_err:
679     return ;
680
681 }
682
683 struct lcd_td043mgea1_data lcd_td043mgea1 = {
684     .pin_txd    = RK2818_PIN_PE6,
685     .pin_clk    = RK2818_PIN_PE7,
686     .pin_cs     = RK2818_PIN_PA4,
687     .screen_set_iomux = lcd_set_iomux,
688 };
689
690 //      adc      ---> key       
691 static  ADC_keyst gAdcValueTab[] = 
692 {
693         {95,  AD2KEY1},///VOLUME_DOWN
694         {192, AD2KEY2},///VOLUME_UP
695         {280, AD2KEY3},///MENU
696         {376, AD2KEY4},///HOME
697         {467, AD2KEY5},///BACK
698         {560, AD2KEY6},///CALL
699         {0,0}
700 };
701
702 static unsigned char gInitKeyCode[] = 
703 {
704         AD2KEY1,AD2KEY2,AD2KEY3,AD2KEY4,AD2KEY5,AD2KEY6,
705         ENDCALL,KEYSTART,KEY_WAKEUP,
706 };
707
708 struct adc_key_data rk2818_adc_key = {
709     .pin_playon     = RK2818_PIN_PA3,
710     .playon_level   = 1,
711     .adc_empty      = 900,
712     .adc_invalid    = 20,
713     .adc_drift      = 50,
714     .adc_chn        = 1,
715     .adc_key_table  = gAdcValueTab,
716     .initKeyCode    = gInitKeyCode,
717     .adc_key_cnt    = 9,
718 };
719
720 static void __init machine_rk2818_init_irq(void)
721 {
722         rk2818_init_irq();
723         rk2818_gpio_init(rk2818_gpioBank, 8);
724         rk2818_gpio_irq_setup();
725 }
726
727 static void __init machine_rk2818_board_init(void)
728 {       
729         rk2818_power_on();
730         pm_power_off = rk2818_power_off;
731 #ifdef CONFIG_I2C0_RK2818
732         i2c_register_board_info(default_i2c0_data.bus_num, board_i2c0_devices,
733                         ARRAY_SIZE(board_i2c0_devices));
734 #endif
735 #ifdef CONFIG_I2C1_RK2818
736         i2c_register_board_info(default_i2c1_data.bus_num, board_i2c1_devices,
737                         ARRAY_SIZE(board_i2c1_devices));
738 #endif
739 #ifdef CONFIG_SPI_I2C
740         i2c_register_board_info(default_i2c2_data.bus_num, board_i2c2_devices,
741                         ARRAY_SIZE(board_i2c2_devices));
742         i2c_register_board_info(default_i2c3_data.bus_num, board_i2c3_devices,
743                         ARRAY_SIZE(board_i2c3_devices));
744 #endif
745         platform_add_devices(devices, ARRAY_SIZE(devices));     
746         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
747         rk2818_mux_api_set(GPIOB4_SPI0CS0_MMC0D4_NAME,IOMUXA_GPIO0_B4); //IOMUXA_SPI0_CSN0);//use for gpio SPI CS0
748         rk2818_mux_api_set(GPIOB0_SPI0CSN1_MMC1PCA_NAME,IOMUXA_GPIO0_B0); //IOMUXA_SPI0_CSN1);//use for gpio SPI CS1
749         rk2818_mux_api_set(GPIOB_SPI0_MMC0_NAME,IOMUXA_SPI0);//use for SPI CLK SDI SDO
750 }
751
752 static void __init machine_rk2818_mapio(void)
753 {
754         iotable_init(rk2818_io_desc, ARRAY_SIZE(rk2818_io_desc));
755         rk2818_clock_init();
756         rk2818_iomux_init();    
757 }
758
759 MACHINE_START(RK2818, "RK28board")
760
761 /* UART for LL DEBUG */
762         .phys_io        = 0x18002000,
763         .io_pg_offst    = ((0xFF100000) >> 18) & 0xfffc,
764         .boot_params    = RK2818_SDRAM_PHYS + 0xf8000,
765         .map_io         = machine_rk2818_mapio,
766         .init_irq       = machine_rk2818_init_irq,
767         .init_machine   = machine_rk2818_board_init,
768         .timer          = &rk2818_timer,
769 MACHINE_END
770