7f1cd7ffe807f400d05590e86d4c0a2ecb331a16
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk29 / board-rk29phonepadsdk.c
1 /* arch/arm/mach-rk29/board-rk29.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/android_pmem.h>
26 #include <linux/usb/android_composite.h>
27
28 #include <mach/hardware.h>
29 #include <asm/setup.h>
30 #include <asm/mach-types.h>
31 #include <asm/mach/arch.h>
32 #include <asm/mach/map.h>
33 #include <asm/mach/flash.h>
34 #include <asm/hardware/gic.h>
35
36 #include <mach/iomux.h>
37 #include <mach/gpio.h>
38 #include <mach/irqs.h>
39 #include <mach/rk29_iomap.h>
40 #include <mach/board.h>
41 #include <mach/rk29_nand.h>
42 #include <mach/rk29_camera.h>                          /* ddl@rock-chips.com : camera support */
43 #include <media/soc_camera.h>                               /* ddl@rock-chips.com : camera support */
44 #include <mach/vpu_mem.h>
45 #include <mach/sram.h>
46 #include <mach/ddr.h>
47
48 #include <linux/regulator/rk29-pwm-regulator.h>
49 #include <linux/regulator/machine.h>
50
51 #include <linux/mtd/nand.h>
52 #include <linux/mtd/partitions.h>
53
54 #include "devices.h"
55 #include "../../../drivers/input/touchscreen/xpt2046_cbn_ts.h"
56
57 #ifdef CONFIG_VIDEO_RK29
58 /*---------------- Camera Sensor Macro Define Begin  ------------------------*/
59 /*---------------- Camera Sensor Configuration Macro Begin ------------------------*/
60 #define CONFIG_SENSOR_0 RK29_CAM_SENSOR_OV5642                      /* back camera sensor */
61 #define CONFIG_SENSOR_IIC_ADDR_0            0x78
62 #define CONFIG_SENSOR_IIC_ADAPTER_ID_0    1
63 #define CONFIG_SENSOR_POWER_PIN_0         INVALID_GPIO
64 #define CONFIG_SENSOR_RESET_PIN_0         INVALID_GPIO
65 #define CONFIG_SENSOR_POWERDN_PIN_0       RK29_PIN6_PB7
66 #define CONFIG_SENSOR_FALSH_PIN_0         INVALID_GPIO
67 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_0 RK29_CAM_POWERACTIVE_L
68 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_0 RK29_CAM_RESETACTIVE_L
69 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_0 RK29_CAM_POWERDNACTIVE_H
70 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_0 RK29_CAM_FLASHACTIVE_L
71
72 #define CONFIG_SENSOR_1 RK29_CAM_SENSOR_OV2659                      /* front camera sensor */
73 #define CONFIG_SENSOR_IIC_ADDR_1            0x60
74 #define CONFIG_SENSOR_IIC_ADAPTER_ID_1    1
75 #define CONFIG_SENSOR_POWER_PIN_1         INVALID_GPIO
76 #define CONFIG_SENSOR_RESET_PIN_1         INVALID_GPIO
77 #define CONFIG_SENSOR_POWERDN_PIN_1       RK29_PIN5_PD7
78 #define CONFIG_SENSOR_FALSH_PIN_1         INVALID_GPIO
79 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_1 RK29_CAM_POWERACTIVE_L
80 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_1 RK29_CAM_RESETACTIVE_L
81 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_1 RK29_CAM_POWERDNACTIVE_H
82 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_1 RK29_CAM_FLASHACTIVE_L
83 /*---------------- Camera Sensor Configuration Macro End------------------------*/
84 #include "../../../drivers/media/video/rk29_camera.c"
85 /*---------------- Camera Sensor Macro Define End  ------------------------*/
86 #endif  //#ifdef CONFIG_VIDEO_RK29
87
88 /* Set memory size of pmem */
89 #ifdef CONFIG_RK29_MEM_SIZE_M
90 #define SDRAM_SIZE          (CONFIG_RK29_MEM_SIZE_M * SZ_1M)
91 #else
92 #define SDRAM_SIZE          SZ_512M
93 #endif
94 #define PMEM_GPU_SIZE       SZ_64M
95 #define PMEM_UI_SIZE        SZ_32M
96 #define PMEM_VPU_SIZE       SZ_64M
97 #define PMEM_CAM_SIZE       PMEM_CAM_NECESSARY
98 #ifdef CONFIG_VIDEO_RK29_WORK_IPP
99 #define MEM_CAMIPP_SIZE     SZ_4M
100 #else
101 #define MEM_CAMIPP_SIZE     0
102 #endif
103 #define MEM_FB_SIZE         (3*SZ_2M)
104 #ifdef CONFIG_FB_WORK_IPP
105 #define MEM_FBIPP_SIZE      SZ_8M   //1920 x 1080 x 2 x 2  //RGB565 = x2;RGB888 = x4
106 #else
107 #define MEM_FBIPP_SIZE      0
108 #endif
109 #define PMEM_GPU_BASE       ((u32)RK29_SDRAM_PHYS + SDRAM_SIZE - PMEM_GPU_SIZE)
110 #define PMEM_UI_BASE        (PMEM_GPU_BASE - PMEM_UI_SIZE)
111 #define PMEM_VPU_BASE       (PMEM_UI_BASE - PMEM_VPU_SIZE)
112 #define PMEM_CAM_BASE       (PMEM_VPU_BASE - PMEM_CAM_SIZE)
113 #define MEM_CAMIPP_BASE     (PMEM_CAM_BASE - MEM_CAMIPP_SIZE)
114 #define MEM_FB_BASE         (MEM_CAMIPP_BASE - MEM_FB_SIZE)
115 #define MEM_FBIPP_BASE      (MEM_FB_BASE - MEM_FBIPP_SIZE)
116 #define LINUX_SIZE          (MEM_FBIPP_BASE - RK29_SDRAM_PHYS)
117
118 #define PREALLOC_WLAN_SEC_NUM           4
119 #define PREALLOC_WLAN_BUF_NUM           160
120 #define PREALLOC_WLAN_SECTION_HEADER    24
121
122 #define WLAN_SECTION_SIZE_0     (PREALLOC_WLAN_BUF_NUM * 128)
123 #define WLAN_SECTION_SIZE_1     (PREALLOC_WLAN_BUF_NUM * 128)
124 #define WLAN_SECTION_SIZE_2     (PREALLOC_WLAN_BUF_NUM * 512)
125 #define WLAN_SECTION_SIZE_3     (PREALLOC_WLAN_BUF_NUM * 1024)
126
127 #define WLAN_SKB_BUF_NUM        16
128
129 static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM];
130
131 struct wifi_mem_prealloc {
132         void *mem_ptr;
133         unsigned long size;
134 };
135
136 extern struct sys_timer rk29_timer;
137
138 static int rk29_nand_io_init(void)
139 {
140     return 0;
141 }
142
143 struct rk29_nand_platform_data rk29_nand_data = {
144     .width      = 1,     /* data bus width in bytes */
145     .hw_ecc     = 1,     /* hw ecc 0: soft ecc */
146     .num_flash    = 1,
147     .io_init   = rk29_nand_io_init,
148 };
149
150 #ifdef CONFIG_FB_RK29
151 /*****************************************************************************************
152  * lcd  devices
153  * author: zyw@rock-chips.com
154  *****************************************************************************************/
155 //#ifdef  CONFIG_LCD_TD043MGEA1
156 #define LCD_TXD_PIN          INVALID_GPIO
157 #define LCD_CLK_PIN          INVALID_GPIO
158 #define LCD_CS_PIN           INVALID_GPIO
159 /*****************************************************************************************
160 * frame buffe  devices
161 * author: zyw@rock-chips.com
162 *****************************************************************************************/
163 #define FB_ID                       0
164 #define FB_DISPLAY_ON_PIN           RK29_PIN6_PD0
165 #define FB_LCD_STANDBY_PIN          RK29_PIN6_PD1
166 #define FB_LCD_CABC_EN_PIN          RK29_PIN6_PD2
167 #define FB_MCU_FMK_PIN              INVALID_GPIO
168
169 #define FB_DISPLAY_ON_VALUE         GPIO_HIGH
170 #define FB_LCD_STANDBY_VALUE        GPIO_HIGH
171
172 //#endif
173 /*****************************************************************************************
174 * touch screen devices
175 * author: cf@rock-chips.com
176 *****************************************************************************************/
177 #define TOUCH_SCREEN_STANDBY_PIN          INVALID_GPIO
178 #define TOUCH_SCREEN_STANDBY_VALUE        GPIO_HIGH
179 #define TOUCH_SCREEN_DISPLAY_PIN          INVALID_GPIO
180 #define TOUCH_SCREEN_DISPLAY_VALUE        GPIO_HIGH
181
182 static int rk29_lcd_io_init(void)
183 {
184     int ret = 0;
185     return ret;
186 }
187
188 static int rk29_lcd_io_deinit(void)
189 {
190     int ret = 0;
191     return ret;
192 }
193
194 static struct rk29lcd_info rk29_lcd_info = {
195     .txd_pin  = LCD_TXD_PIN,
196     .clk_pin = LCD_CLK_PIN,
197     .cs_pin = LCD_CS_PIN,
198     .io_init   = rk29_lcd_io_init,
199     .io_deinit = rk29_lcd_io_deinit,
200 };
201
202
203 static int rk29_fb_io_init(struct rk29_fb_setting_info *fb_setting)
204 {
205     int ret = 0;
206     if(fb_setting->mcu_fmk_en && (FB_MCU_FMK_PIN != INVALID_GPIO))
207     {
208         ret = gpio_request(FB_MCU_FMK_PIN, NULL);
209         if(ret != 0)
210         {
211             gpio_free(FB_MCU_FMK_PIN);
212             printk(">>>>>> FB_MCU_FMK_PIN gpio_request err \n ");
213         }
214         gpio_direction_input(FB_MCU_FMK_PIN);
215     }
216     if(fb_setting->disp_on_en)
217     {
218         if(FB_DISPLAY_ON_PIN != INVALID_GPIO)
219         {
220             ret = gpio_request(FB_DISPLAY_ON_PIN, NULL);
221             if(ret != 0)
222             {
223                 gpio_free(FB_DISPLAY_ON_PIN);
224                 printk(">>>>>> FB_DISPLAY_ON_PIN gpio_request err \n ");
225             }
226         }
227         else
228         {
229              ret = gpio_request(TOUCH_SCREEN_DISPLAY_PIN, NULL);
230              if(ret != 0)
231              {
232                  gpio_free(TOUCH_SCREEN_DISPLAY_PIN);
233                  printk(">>>>>> TOUCH_SCREEN_DISPLAY_PIN gpio_request err \n ");
234              }
235              gpio_direction_output(TOUCH_SCREEN_DISPLAY_PIN, 0);
236              gpio_set_value(TOUCH_SCREEN_DISPLAY_PIN, TOUCH_SCREEN_DISPLAY_VALUE);
237         }
238     }
239
240     if(fb_setting->disp_on_en)
241     {
242         if(FB_LCD_STANDBY_PIN != INVALID_GPIO)
243         {
244              ret = gpio_request(FB_LCD_STANDBY_PIN, NULL);
245              if(ret != 0)
246              {
247                  gpio_free(FB_LCD_STANDBY_PIN);
248                  printk(">>>>>> FB_LCD_STANDBY_PIN gpio_request err \n ");
249              }
250         }
251         else
252         {
253              ret = gpio_request(TOUCH_SCREEN_STANDBY_PIN, NULL);
254              if(ret != 0)
255              {
256                  gpio_free(TOUCH_SCREEN_STANDBY_PIN);
257                  printk(">>>>>> TOUCH_SCREEN_STANDBY_PIN gpio_request err \n ");
258              }
259              gpio_direction_output(TOUCH_SCREEN_STANDBY_PIN, 0);
260              gpio_set_value(TOUCH_SCREEN_STANDBY_PIN, TOUCH_SCREEN_STANDBY_VALUE);
261          }
262     }
263
264     if(FB_LCD_CABC_EN_PIN != INVALID_GPIO)
265     {
266         ret = gpio_request(FB_LCD_CABC_EN_PIN, NULL);
267         if(ret != 0)
268         {
269             gpio_free(FB_LCD_CABC_EN_PIN);
270             printk(">>>>>> FB_LCD_CABC_EN_PIN gpio_request err \n ");
271         }
272         gpio_direction_output(FB_LCD_CABC_EN_PIN, 0);
273         gpio_set_value(FB_LCD_CABC_EN_PIN, GPIO_LOW);
274     }
275
276     return ret;
277 }
278
279 static struct rk29fb_info rk29_fb_info = {
280     .fb_id   = FB_ID,
281     .disp_on_pin = FB_DISPLAY_ON_PIN,
282     .disp_on_value = FB_DISPLAY_ON_VALUE,
283     .standby_pin = FB_LCD_STANDBY_PIN,
284     .standby_value = FB_LCD_STANDBY_VALUE,
285     .mcu_fmk_pin = FB_MCU_FMK_PIN,
286     .lcd_info = &rk29_lcd_info,
287     .io_init   = rk29_fb_io_init,
288 };
289
290 /* rk29 fb resource */
291 static struct resource rk29_fb_resource[] = {
292         [0] = {
293         .name  = "lcdc reg",
294                 .start = RK29_LCDC_PHYS,
295                 .end   = RK29_LCDC_PHYS + RK29_LCDC_SIZE - 1,
296                 .flags = IORESOURCE_MEM,
297         },
298         [1] = {
299             .name  = "lcdc irq",
300                 .start = IRQ_LCDC,
301                 .end   = IRQ_LCDC,
302                 .flags = IORESOURCE_IRQ,
303         },
304         [2] = {
305             .name   = "win1 buf",
306         .start  = MEM_FB_BASE,
307         .end    = MEM_FB_BASE + MEM_FB_SIZE - 1,
308         .flags  = IORESOURCE_MEM,
309     },
310     #ifdef CONFIG_FB_WORK_IPP
311     [3] = {
312             .name   = "win1 ipp buf",
313         .start  = MEM_FBIPP_BASE,
314         .end    = MEM_FBIPP_BASE + MEM_FBIPP_SIZE - 1,
315         .flags  = IORESOURCE_MEM,
316     },
317     #endif
318 };
319
320 /*platform_device*/
321 struct platform_device rk29_device_fb = {
322         .name             = "rk29-fb",
323         .id               = 4,
324         .num_resources    = ARRAY_SIZE(rk29_fb_resource),
325         .resource         = rk29_fb_resource,
326         .dev            = {
327                 .platform_data  = &rk29_fb_info,
328         }
329 };
330
331 struct platform_device rk29_device_dma_cpy = {
332         .name             = "dma_memcpy",
333         .id               = 4,
334
335 };
336
337 #endif
338
339 static struct android_pmem_platform_data android_pmem_pdata = {
340         .name           = "pmem",
341         .start          = PMEM_UI_BASE,
342         .size           = PMEM_UI_SIZE,
343         .no_allocator   = 0,
344         .cached         = 1,
345 };
346
347 static struct platform_device android_pmem_device = {
348         .name           = "android_pmem",
349         .id             = 0,
350         .dev            = {
351                 .platform_data = &android_pmem_pdata,
352         },
353 };
354
355 static struct vpu_mem_platform_data vpu_mem_pdata = {
356         .name           = "vpu_mem",
357         .start          = PMEM_VPU_BASE,
358         .size           = PMEM_VPU_SIZE,
359         .cached         = 1,
360 };
361
362 static struct platform_device rk29_vpu_mem_device = {
363         .name           = "vpu_mem",
364         .id                 = 2,
365         .dev            = {
366         .platform_data = &vpu_mem_pdata,
367         },
368 };
369
370 static struct platform_device rk29_v4l2_output_devce = {
371         .name           = "rk29_vout",
372 };
373
374 /*HANNSTAR_P1003 touch*/
375 #if defined (CONFIG_HANNSTAR_P1003)
376 #define TOUCH_RESET_PIN RK29_PIN6_PC3
377 #define TOUCH_INT_PIN   RK29_PIN0_PA2
378
379 int p1003_init_platform_hw(void)
380 {
381     if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
382       gpio_free(TOUCH_RESET_PIN);
383       printk("p1003_init_platform_hw gpio_request error\n");
384       return -EIO;
385     }
386
387     if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
388       gpio_free(TOUCH_INT_PIN);
389       printk("p1003_init_platform_hw gpio_request error\n");
390       return -EIO;
391     }
392     gpio_pull_updown(TOUCH_INT_PIN, 1);
393     gpio_direction_output(TOUCH_RESET_PIN, 0);
394     msleep(500);
395     gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
396     msleep(500);
397     gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
398
399     return 0;
400 }
401
402
403 struct p1003_platform_data p1003_info = {
404   .model= 1003,
405   .init_platform_hw= p1003_init_platform_hw,
406
407 };
408 #endif
409 #if defined (CONFIG_EETI_EGALAX)
410 #define TOUCH_RESET_PIN RK29_PIN6_PC3
411 #define TOUCH_INT_PIN   RK29_PIN0_PA2
412
413 static int EETI_EGALAX_init_platform_hw(void)
414 {
415     if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
416       gpio_free(TOUCH_RESET_PIN);
417       printk("p1003_init_platform_hw gpio_request error\n");
418       return -EIO;
419     }
420
421     if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
422       gpio_free(TOUCH_INT_PIN);
423       printk("p1003_init_platform_hw gpio_request error\n");
424       return -EIO;
425     }
426     gpio_pull_updown(TOUCH_INT_PIN, 1);
427     gpio_direction_output(TOUCH_RESET_PIN, 0);
428     msleep(500);
429     gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
430     msleep(500);
431     gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
432
433     return 0;
434 }
435
436
437 static struct eeti_egalax_platform_data eeti_egalax_info = {
438   .model= 1003,
439   .init_platform_hw= EETI_EGALAX_init_platform_hw,
440   .standby_pin = TOUCH_SCREEN_STANDBY_PIN,
441   .standby_value = TOUCH_SCREEN_STANDBY_VALUE,
442   .disp_on_pin = TOUCH_SCREEN_DISPLAY_PIN,
443   .disp_on_value = TOUCH_SCREEN_DISPLAY_VALUE,
444 };
445 #endif
446 /*MMA8452 gsensor*/
447 #if defined (CONFIG_GS_MMA8452)
448 #define MMA8452_INT_PIN   RK29_PIN0_PA3
449
450 static int mma8452_init_platform_hw(void)
451 {
452
453     if(gpio_request(MMA8452_INT_PIN,NULL) != 0){
454       gpio_free(MMA8452_INT_PIN);
455       printk("mma8452_init_platform_hw gpio_request error\n");
456       return -EIO;
457     }
458     gpio_pull_updown(MMA8452_INT_PIN, 1);
459     return 0;
460 }
461
462
463 static struct mma8452_platform_data mma8452_info = {
464   .model= 8452,
465   .swap_xy = 0,
466   .init_platform_hw= mma8452_init_platform_hw,
467
468 };
469 #endif
470
471 #if defined (CONFIG_BATTERY_BQ27510)
472 #define DC_CHECK_PIN    RK29_PIN4_PA1
473 #define LI_LION_BAT_NUM 2
474 static int bq27510_init_dc_check_pin(void){     
475         if(gpio_request(DC_CHECK_PIN,"dc_check") != 0){      
476                 gpio_free(DC_CHECK_PIN);      
477                 printk("bq27510 init dc check pin request error\n");      
478                 return -EIO;    
479         }       
480         gpio_direction_input(DC_CHECK_PIN);     
481         return 0;
482 }
483
484 struct bq27510_platform_data bq27510_info = {   
485         .init_dc_check_pin = bq27510_init_dc_check_pin, 
486         .dc_check_pin =  DC_CHECK_PIN,          
487         .bat_num = LI_LION_BAT_NUM,
488 };
489 #endif
490
491
492 /*****************************************************************************************
493  * i2c devices
494  * author: kfx@rock-chips.com
495 *****************************************************************************************/
496 static int rk29_i2c0_io_init(void)
497 {
498         rk29_mux_api_set(GPIO2B7_I2C0SCL_NAME, GPIO2L_I2C0_SCL);
499         rk29_mux_api_set(GPIO2B6_I2C0SDA_NAME, GPIO2L_I2C0_SDA);
500         return 0;
501 }
502
503 static int rk29_i2c1_io_init(void)
504 {
505         rk29_mux_api_set(GPIO1A7_I2C1SCL_NAME, GPIO1L_I2C1_SCL);
506         rk29_mux_api_set(GPIO1A6_I2C1SDA_NAME, GPIO1L_I2C1_SDA);
507         return 0;
508 }
509 static int rk29_i2c2_io_init(void)
510 {
511         rk29_mux_api_set(GPIO5D4_I2C2SCL_NAME, GPIO5H_I2C2_SCL);
512         rk29_mux_api_set(GPIO5D3_I2C2SDA_NAME, GPIO5H_I2C2_SDA);
513         return 0;
514 }
515
516 static int rk29_i2c3_io_init(void)
517 {
518         rk29_mux_api_set(GPIO2B5_UART3RTSN_I2C3SCL_NAME, GPIO2L_I2C3_SCL);
519         rk29_mux_api_set(GPIO2B4_UART3CTSN_I2C3SDA_NAME, GPIO2L_I2C3_SDA);
520         return 0;
521 }
522
523 struct rk29_i2c_platform_data default_i2c0_data = {
524         .bus_num    = 0,
525         .flags      = 0,
526         .slave_addr = 0xff,
527         .scl_rate  = 400*1000,
528         .mode           = I2C_MODE_IRQ,
529         .io_init = rk29_i2c0_io_init,
530 };
531
532 struct rk29_i2c_platform_data default_i2c1_data = {
533         .bus_num    = 1,
534         .flags      = 0,
535         .slave_addr = 0xff,
536         .scl_rate  = 400*1000,
537         .mode           = I2C_MODE_IRQ,
538         .io_init = rk29_i2c1_io_init,
539 };
540
541 struct rk29_i2c_platform_data default_i2c2_data = {
542         .bus_num    = 2,
543         .flags      = 0,
544         .slave_addr = 0xff,
545         .scl_rate  = 400*1000,
546         .mode           = I2C_MODE_IRQ,
547         .io_init = rk29_i2c2_io_init,
548 };
549
550 struct rk29_i2c_platform_data default_i2c3_data = {
551         .bus_num    = 3,
552         .flags      = 0,
553         .slave_addr = 0xff,
554         .scl_rate  = 400*1000,
555         .mode           = I2C_MODE_IRQ,
556         .io_init = rk29_i2c3_io_init,
557 };
558
559 #ifdef CONFIG_I2C0_RK29
560 static struct i2c_board_info __initdata board_i2c0_devices[] = {
561 #if defined (CONFIG_RK1000_CONTROL)
562         {
563                 .type                   = "rk1000_control",
564                 .addr           = 0x40,
565                 .flags                  = 0,
566         },
567 #endif
568 #if defined (CONFIG_SND_SOC_alc5621)
569         {
570                 .type                   = "ALC5621",
571                 .addr                   = 0x1a,
572                 .flags                  = 0,
573         },
574 #endif
575 #if defined (CONFIG_SND_SOC_alc5631)
576         {
577                 .type                   = "rt5631",
578                 .addr                   = 0x1a,
579                 .flags                  = 0,
580         },
581 #endif
582
583 #if defined (CONFIG_SND_SOC_RT5625)
584         {
585                 .type                   = "rt5625",
586                 .addr                   = 0x1e,         //need check A1 pin,A1 pin is low,addr=0x1e,A1 pin is high,addr=0x1f.
587                 .flags                  = 0,
588         },
589 #endif
590
591 #if defined (CONFIG_SND_SOC_RK1000)
592         {
593                 .type                   = "rk1000_i2c_codec",
594                 .addr           = 0x60,
595                 .flags                  = 0,
596         },
597 #endif
598 #if defined (CONFIG_SND_SOC_WM8900)
599         {
600                 .type                   = "wm8900",
601                 .addr           = 0x1A,
602                 .flags                  = 0,
603         },
604 #endif
605 #if defined (CONFIG_BATTERY_STC3100)
606         {
607                 .type                   = "stc3100",
608                 .addr           = 0x70,
609                 .flags                  = 0,
610         },
611 #endif
612 #if defined (CONFIG_BATTERY_BQ27510)
613         {
614                 .type                   = "bq27510",
615                 .addr           = 0x55,
616                 .flags                  = 0,
617                 .platform_data  = &bq27510_info,
618         },
619 #endif
620 #if defined (CONFIG_RTC_HYM8563)
621         {
622                 .type                   = "rtc_hym8563",
623                 .addr           = 0x51,
624                 .flags                  = 0,
625                 .irq            = RK29_PIN0_PA1,
626         },
627 #endif
628 #if defined (CONFIG_GS_MMA8452)
629     {
630       .type           = "gs_mma8452",
631       .addr           = 0x1c,
632       .flags          = 0,
633       .irq            = MMA8452_INT_PIN,
634       .platform_data  = &mma8452_info,
635     },
636 #endif
637 #if defined (CONFIG_COMPASS_AK8973)
638         {
639                 .type                   = "ak8973",
640                 .addr           = 0x1d,
641                 .flags                  = 0,
642                 .irq                    = RK29_PIN0_PA4,
643         },
644 #endif
645 #if defined (CONFIG_COMPASS_AK8975)
646         {
647                 .type                   = "ak8975",
648                 .addr           = 0x0d,
649                 .flags                  = 0,
650                 .irq                    = RK29_PIN0_PA4,
651         },
652 #endif
653 };
654 #endif
655
656 #ifdef CONFIG_I2C1_RK29
657 static struct i2c_board_info __initdata board_i2c1_devices[] = {
658 #if defined (CONFIG_RK1000_CONTROL1)
659         {
660                 .type                   = "rk1000_control",
661                 .addr                   = 0x40,
662                 .flags                  = 0,
663         },
664 #endif
665 #if defined (CONFIG_ANX7150) || defined (CONFIG_ANX7150_NEW)
666     {
667                 .type           = "anx7150",
668         .addr           = 0x39,             //0x39, 0x3d
669         .flags          = 0,
670         .irq            = RK29_PIN1_PD7,
671     },
672 #endif
673
674 };
675 #endif
676
677 #ifdef CONFIG_I2C2_RK29
678 static struct i2c_board_info __initdata board_i2c2_devices[] = {
679 #if defined (CONFIG_HANNSTAR_P1003)
680     {
681       .type           = "p1003_touch",
682       .addr           = 0x04,
683       .flags          = 0, //I2C_M_NEED_DELAY
684       .irq            = RK29_PIN0_PA2,
685       .platform_data  = &p1003_info,
686       //.udelay           = 100
687     },
688 #endif
689 #if defined (CONFIG_EETI_EGALAX)
690     {
691       .type           = "egalax_i2c",
692       .addr           = 0x04,
693       .flags          = 0,
694       .irq            = RK29_PIN0_PA2,
695       .platform_data  = &eeti_egalax_info,
696     },
697 #endif
698 };
699 #endif
700
701 #ifdef CONFIG_I2C3_RK29
702 static struct i2c_board_info __initdata board_i2c3_devices[] = {
703 };
704 #endif
705
706 /*****************************************************************************************
707  * camera  devices
708  * author: ddl@rock-chips.com
709  *****************************************************************************************/
710 #define CONFIG_SENSOR_POWER_IOCTL_USR      0
711 #define CONFIG_SENSOR_RESET_IOCTL_USR      0
712 #define CONFIG_SENSOR_POWERDOWN_IOCTL_USR      0
713 #define CONFIG_SENSOR_FLASH_IOCTL_USR      0
714
715 #if CONFIG_SENSOR_POWER_IOCTL_USR
716 static int sensor_power_usr_cb (struct rk29camera_gpio_res *res,int on)
717 {
718     #error "CONFIG_SENSOR_POWER_IOCTL_USR is 1, sensor_power_usr_cb function must be writed!!";
719 }
720 #endif
721
722 #if CONFIG_SENSOR_RESET_IOCTL_USR
723 static int sensor_reset_usr_cb (struct rk29camera_gpio_res *res,int on)
724 {
725     #error "CONFIG_SENSOR_RESET_IOCTL_USR is 1, sensor_reset_usr_cb function must be writed!!";
726 }
727 #endif
728
729 #if CONFIG_SENSOR_POWERDOWN_IOCTL_USR
730 static int sensor_powerdown_usr_cb (struct rk29camera_gpio_res *res,int on)
731 {
732     #error "CONFIG_SENSOR_POWERDOWN_IOCTL_USR is 1, sensor_powerdown_usr_cb function must be writed!!";
733 }
734 #endif
735
736 #if CONFIG_SENSOR_FLASH_IOCTL_USR
737 static int sensor_flash_usr_cb (struct rk29camera_gpio_res *res,int on)
738 {
739     #error "CONFIG_SENSOR_FLASH_IOCTL_USR is 1, sensor_flash_usr_cb function must be writed!!";
740 }
741 #endif
742
743 static struct rk29camera_platform_ioctl_cb  sensor_ioctl_cb = {
744     #if CONFIG_SENSOR_POWER_IOCTL_USR
745     .sensor_power_cb = sensor_power_usr_cb,
746     #else
747     .sensor_power_cb = NULL,
748     #endif
749
750     #if CONFIG_SENSOR_RESET_IOCTL_USR
751     .sensor_reset_cb = sensor_reset_usr_cb,
752     #else
753     .sensor_reset_cb = NULL,
754     #endif
755
756     #if CONFIG_SENSOR_POWERDOWN_IOCTL_USR
757     .sensor_powerdown_cb = sensor_powerdown_usr_cb,
758     #else
759     .sensor_powerdown_cb = NULL,
760     #endif
761
762     #if CONFIG_SENSOR_FLASH_IOCTL_USR
763     .sensor_flash_cb = sensor_flash_usr_cb,
764     #else
765     .sensor_flash_cb = NULL,
766     #endif
767 };
768 #include "../../../drivers/media/video/rk29_camera.c"
769
770 /*****************************************************************************************
771  * backlight  devices
772  * author: nzy@rock-chips.com
773  *****************************************************************************************/
774 #ifdef CONFIG_BACKLIGHT_RK29_BL
775  /*
776  GPIO1B5_PWM0_NAME,       GPIO1L_PWM0
777  GPIO5D2_PWM1_UART1SIRIN_NAME,  GPIO5H_PWM1
778  GPIO2A3_SDMMC0WRITEPRT_PWM2_NAME,   GPIO2L_PWM2
779  GPIO1A5_EMMCPWREN_PWM3_NAME,     GPIO1L_PWM3
780  */
781
782 #define PWM_ID            0
783 #define PWM_MUX_NAME      GPIO1B5_PWM0_NAME
784 #define PWM_MUX_MODE      GPIO1L_PWM0
785 #define PWM_MUX_MODE_GPIO GPIO1L_GPIO1B5
786 #define PWM_GPIO RK29_PIN1_PB5
787 #define PWM_EFFECT_VALUE  1
788
789 //#define LCD_DISP_ON_PIN
790
791 #ifdef  LCD_DISP_ON_PIN
792 #define BL_EN_MUX_NAME    GPIOF34_UART3_SEL_NAME
793 #define BL_EN_MUX_MODE    IOMUXB_GPIO1_B34
794
795 #define BL_EN_PIN         GPIO0L_GPIO0A5
796 #define BL_EN_VALUE       GPIO_HIGH
797 #endif
798 static int rk29_backlight_io_init(void)
799 {
800     int ret = 0;
801
802     rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
803         #ifdef  LCD_DISP_ON_PIN
804     rk29_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
805
806     ret = gpio_request(BL_EN_PIN, NULL);
807     if(ret != 0)
808     {
809         gpio_free(BL_EN_PIN);
810     }
811
812     gpio_direction_output(BL_EN_PIN, 0);
813     gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
814         #endif
815     return ret;
816 }
817
818 static int rk29_backlight_io_deinit(void)
819 {
820     int ret = 0;
821     #ifdef  LCD_DISP_ON_PIN
822     gpio_free(BL_EN_PIN);
823     #endif
824     rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
825     return ret;
826 }
827
828 static int rk29_backlight_pwm_suspend(void)
829 {
830         int ret = 0;
831         rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
832         if (ret = gpio_request(PWM_GPIO, NULL)) {
833                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
834                 return -1;
835         }
836         gpio_direction_output(PWM_GPIO, GPIO_LOW);
837         return ret;
838 }
839
840 static int rk29_backlight_pwm_resume(void)
841 {
842         gpio_free(PWM_GPIO);
843         rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
844         return 0;
845 }
846
847 struct rk29_bl_info rk29_bl_info = {
848     .pwm_id   = PWM_ID,
849     .bl_ref   = PWM_EFFECT_VALUE,
850     .io_init   = rk29_backlight_io_init,
851     .io_deinit = rk29_backlight_io_deinit,
852     .pwm_suspend = rk29_backlight_pwm_suspend,
853     .pwm_resume = rk29_backlight_pwm_resume,
854 };
855 #endif
856 /*****************************************************************************************
857 * pwm voltage regulator devices
858 ******************************************************************************************/
859 #if defined (CONFIG_RK29_PWM_REGULATOR)
860
861 #define REGULATOR_PWM_ID                                        2
862 #define REGULATOR_PWM_MUX_NAME                  GPIO2A3_SDMMC0WRITEPRT_PWM2_NAME
863 #define REGULATOR_PWM_MUX_MODE                                          GPIO2L_PWM2
864 #define REGULATOR_PWM_MUX_MODE_GPIO                             GPIO2L_GPIO2A3
865 #define REGULATOR_PWM_GPIO                              RK29_PIN2_PA3
866
867 static struct regulator_consumer_supply pwm_consumers[] = {
868         {
869                 .supply = "vcore",
870         }
871 };
872
873 static struct regulator_init_data rk29_pwm_regulator_data = {
874         .constraints = {
875                 .name = "PWM2",
876                 .min_uV =  950000,
877                 .max_uV = 1400000,
878                 .apply_uV = 1,
879                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
880         },
881         .num_consumer_supplies = ARRAY_SIZE(pwm_consumers),
882         .consumer_supplies = pwm_consumers,
883 };
884
885 static struct pwm_platform_data rk29_regulator_pwm_platform_data = {
886         .pwm_id = REGULATOR_PWM_ID,
887         .pwm_gpio = REGULATOR_PWM_GPIO,
888         //.pwm_iomux_name[] = REGULATOR_PWM_MUX_NAME;
889         .pwm_iomux_name = REGULATOR_PWM_MUX_NAME,
890         .pwm_iomux_pwm = REGULATOR_PWM_MUX_MODE,
891         .pwm_iomux_gpio = REGULATOR_PWM_MUX_MODE_GPIO,
892         .init_data  = &rk29_pwm_regulator_data,
893 };
894
895 static struct platform_device rk29_device_pwm_regulator = {
896         .name = "pwm-voltage-regulator",
897         .id   = -1,
898         .dev  = {
899                 .platform_data = &rk29_regulator_pwm_platform_data,
900         },
901 };
902
903 #endif
904
905 /*****************************************************************************************
906  * SDMMC devices
907 *****************************************************************************************/
908 #ifdef CONFIG_SDMMC0_RK29
909 static int rk29_sdmmc0_cfg_gpio(void)
910 {
911         rk29_mux_api_set(GPIO1D1_SDMMC0CMD_NAME, GPIO1H_SDMMC0_CMD);
912         rk29_mux_api_set(GPIO1D0_SDMMC0CLKOUT_NAME, GPIO1H_SDMMC0_CLKOUT);
913         rk29_mux_api_set(GPIO1D2_SDMMC0DATA0_NAME, GPIO1H_SDMMC0_DATA0);
914         rk29_mux_api_set(GPIO1D3_SDMMC0DATA1_NAME, GPIO1H_SDMMC0_DATA1);
915         rk29_mux_api_set(GPIO1D4_SDMMC0DATA2_NAME, GPIO1H_SDMMC0_DATA2);
916         rk29_mux_api_set(GPIO1D5_SDMMC0DATA3_NAME, GPIO1H_SDMMC0_DATA3);
917         rk29_mux_api_set(GPIO2A2_SDMMC0DETECTN_NAME, GPIO2L_GPIO2A2);
918         rk29_mux_api_set(GPIO5D5_SDMMC0PWREN_NAME, GPIO5H_GPIO5D5);   ///GPIO5H_SDMMC0_PWR_EN);  ///GPIO5H_GPIO5D5);
919         gpio_request(RK29_PIN5_PD5,"sdmmc");
920 #if 0
921         gpio_set_value(RK29_PIN5_PD5,GPIO_HIGH);
922         mdelay(100);
923         gpio_set_value(RK29_PIN5_PD5,GPIO_LOW);
924 #else
925         gpio_direction_output(RK29_PIN5_PD5,GPIO_LOW);
926 #endif
927         return 0;
928 }
929
930 #define CONFIG_SDMMC0_USE_DMA
931 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
932         .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
933                                            MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33|
934                                            MMC_VDD_33_34|MMC_VDD_34_35| MMC_VDD_35_36),
935         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
936         .io_init = rk29_sdmmc0_cfg_gpio,
937         .dma_name = "sd_mmc",
938 #ifdef CONFIG_SDMMC0_USE_DMA
939         .use_dma  = 1,
940 #else
941         .use_dma = 0,
942 #endif
943         .detect_irq = RK29_PIN2_PA2, // INVALID_GPIO
944         .enable_sd_wakeup = 0,
945 };
946 #endif
947 #ifdef CONFIG_SDMMC1_RK29
948 #define CONFIG_SDMMC1_USE_DMA
949 static int rk29_sdmmc1_cfg_gpio(void)
950 {
951         rk29_mux_api_set(GPIO1C2_SDMMC1CMD_NAME, GPIO1H_SDMMC1_CMD);
952         rk29_mux_api_set(GPIO1C7_SDMMC1CLKOUT_NAME, GPIO1H_SDMMC1_CLKOUT);
953         rk29_mux_api_set(GPIO1C3_SDMMC1DATA0_NAME, GPIO1H_SDMMC1_DATA0);
954         rk29_mux_api_set(GPIO1C4_SDMMC1DATA1_NAME, GPIO1H_SDMMC1_DATA1);
955         rk29_mux_api_set(GPIO1C5_SDMMC1DATA2_NAME, GPIO1H_SDMMC1_DATA2);
956         rk29_mux_api_set(GPIO1C6_SDMMC1DATA3_NAME, GPIO1H_SDMMC1_DATA3);
957         //rk29_mux_api_set(GPIO1C0_UART0CTSN_SDMMC1DETECTN_NAME, GPIO1H_SDMMC1_DETECT_N);
958         return 0;
959 }
960
961 #ifdef CONFIG_WIFI_CONTROL_FUNC
962 static int rk29sdk_wifi_status(struct device *dev);
963 static int rk29sdk_wifi_status_register(void (*callback)(int card_presend, void *dev_id), void *dev_id);
964 #endif
965
966 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N    RK29_PIN1_PD6
967
968 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
969         .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|
970                                            MMC_VDD_29_30|MMC_VDD_30_31|MMC_VDD_31_32|
971                                            MMC_VDD_32_33|MMC_VDD_33_34),
972         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_SDIO_IRQ|
973                                    MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
974         .io_init = rk29_sdmmc1_cfg_gpio,
975         .dma_name = "sdio",
976 #ifdef CONFIG_SDMMC1_USE_DMA
977         .use_dma  = 1,
978 #else
979         .use_dma = 0,
980 #endif
981 #ifdef CONFIG_WIFI_CONTROL_FUNC
982         .status = rk29sdk_wifi_status,
983         .register_status_notify = rk29sdk_wifi_status_register,
984 #endif
985 #if 0
986         .detect_irq = RK29SDK_WIFI_SDIO_CARD_DETECT_N,
987 #endif
988 };
989 #endif
990
991 #ifdef CONFIG_WIFI_CONTROL_FUNC
992 #define RK29SDK_WIFI_BT_GPIO_POWER_N       RK29_PIN5_PD6
993 #define RK29SDK_WIFI_GPIO_RESET_N          RK29_PIN6_PC0
994 #define RK29SDK_BT_GPIO_RESET_N            RK29_PIN6_PC4
995
996 static int rk29sdk_wifi_cd = 0;   /* wifi virtual 'card detect' status */
997 static void (*wifi_status_cb)(int card_present, void *dev_id);
998 static void *wifi_status_cb_devid;
999 int rk29sdk_wifi_power_state = 0;
1000 int rk29sdk_bt_power_state = 0;
1001
1002 static int rk29sdk_wifi_status(struct device *dev)
1003 {
1004         return rk29sdk_wifi_cd;
1005 }
1006
1007 static int rk29sdk_wifi_status_register(void (*callback)(int card_present, void *dev_id), void *dev_id)
1008 {
1009         if(wifi_status_cb)
1010                 return -EAGAIN;
1011         wifi_status_cb = callback;
1012         wifi_status_cb_devid = dev_id;
1013         return 0;
1014 }
1015
1016 static int rk29sdk_wifi_bt_gpio_control_init(void)
1017 {
1018     if (gpio_request(RK29SDK_WIFI_BT_GPIO_POWER_N, "wifi_bt_power")) {
1019            pr_info("%s: request wifi_bt power gpio failed\n", __func__);
1020            return -1;
1021     }
1022
1023     if (gpio_request(RK29SDK_WIFI_GPIO_RESET_N, "wifi reset")) {
1024            pr_info("%s: request wifi reset gpio failed\n", __func__);
1025            gpio_free(RK29SDK_WIFI_BT_GPIO_POWER_N);
1026            return -1;
1027     }
1028
1029     if (gpio_request(RK29SDK_BT_GPIO_RESET_N, "bt reset")) {
1030           pr_info("%s: request bt reset gpio failed\n", __func__);
1031           gpio_free(RK29SDK_WIFI_GPIO_RESET_N);
1032           return -1;
1033     }
1034
1035     gpio_direction_output(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
1036     gpio_direction_output(RK29SDK_WIFI_GPIO_RESET_N,    GPIO_LOW);
1037     gpio_direction_output(RK29SDK_BT_GPIO_RESET_N,      GPIO_LOW);
1038
1039     pr_info("%s: init finished\n",__func__);
1040
1041     return 0;
1042 }
1043
1044 static int rk29sdk_wifi_power(int on)
1045 {
1046         pr_info("%s: %d\n", __func__, on);
1047         if (on){
1048                 gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_HIGH);
1049                 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_HIGH);
1050                 mdelay(100);
1051                 pr_info("wifi turn on power\n");
1052         }else{
1053                 if (!rk29sdk_bt_power_state){
1054                         gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
1055                         mdelay(100);
1056                         pr_info("wifi shut off power\n");
1057                 }else
1058                 {
1059                         pr_info("wifi shouldn't shut off power, bt is using it!\n");
1060                 }
1061                 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_LOW);
1062
1063         }
1064
1065         rk29sdk_wifi_power_state = on;
1066         return 0;
1067 }
1068
1069 static int rk29sdk_wifi_reset_state;
1070 static int rk29sdk_wifi_reset(int on)
1071 {
1072         pr_info("%s: %d\n", __func__, on);
1073         gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, on);
1074         mdelay(100);
1075         rk29sdk_wifi_reset_state = on;
1076         return 0;
1077 }
1078
1079 int rk29sdk_wifi_set_carddetect(int val)
1080 {
1081         pr_info("%s:%d\n", __func__, val);
1082         rk29sdk_wifi_cd = val;
1083         if (wifi_status_cb){
1084                 wifi_status_cb(val, wifi_status_cb_devid);
1085         }else {
1086                 pr_warning("%s, nobody to notify\n", __func__);
1087         }
1088         return 0;
1089 }
1090 EXPORT_SYMBOL(rk29sdk_wifi_set_carddetect);
1091
1092 static struct wifi_mem_prealloc wifi_mem_array[PREALLOC_WLAN_SEC_NUM] = {
1093         {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
1094         {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
1095         {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
1096         {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)}
1097 };
1098
1099 static void *rk29sdk_mem_prealloc(int section, unsigned long size)
1100 {
1101         if (section == PREALLOC_WLAN_SEC_NUM)
1102                 return wlan_static_skb;
1103
1104         if ((section < 0) || (section > PREALLOC_WLAN_SEC_NUM))
1105                 return NULL;
1106
1107         if (wifi_mem_array[section].size < size)
1108                 return NULL;
1109
1110         return wifi_mem_array[section].mem_ptr;
1111 }
1112
1113 int __init rk29sdk_init_wifi_mem(void)
1114 {
1115         int i;
1116         int j;
1117
1118         for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
1119                 wlan_static_skb[i] = dev_alloc_skb(
1120                                 ((i < (WLAN_SKB_BUF_NUM / 2)) ? 4096 : 8192));
1121
1122                 if (!wlan_static_skb[i])
1123                         goto err_skb_alloc;
1124         }
1125
1126         for (i = 0 ; i < PREALLOC_WLAN_SEC_NUM ; i++) {
1127                 wifi_mem_array[i].mem_ptr =
1128                                 kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
1129
1130                 if (!wifi_mem_array[i].mem_ptr)
1131                         goto err_mem_alloc;
1132         }
1133         return 0;
1134
1135 err_mem_alloc:
1136         pr_err("Failed to mem_alloc for WLAN\n");
1137         for (j = 0 ; j < i ; j++)
1138                kfree(wifi_mem_array[j].mem_ptr);
1139
1140         i = WLAN_SKB_BUF_NUM;
1141
1142 err_skb_alloc:
1143         pr_err("Failed to skb_alloc for WLAN\n");
1144         for (j = 0 ; j < i ; j++)
1145                 dev_kfree_skb(wlan_static_skb[j]);
1146
1147         return -ENOMEM;
1148 }
1149
1150 static struct wifi_platform_data rk29sdk_wifi_control = {
1151         .set_power = rk29sdk_wifi_power,
1152         .set_reset = rk29sdk_wifi_reset,
1153         .set_carddetect = rk29sdk_wifi_set_carddetect,
1154         .mem_prealloc   = rk29sdk_mem_prealloc,
1155 };
1156 static struct platform_device rk29sdk_wifi_device = {
1157         .name = "bcm4329_wlan",
1158         .id = 1,
1159         .dev = {
1160                 .platform_data = &rk29sdk_wifi_control,
1161          },
1162 };
1163 #endif
1164
1165
1166 /* bluetooth rfkill device */
1167 static struct platform_device rk29sdk_rfkill = {
1168         .name = "rk29sdk_rfkill",
1169         .id = -1,
1170 };
1171
1172
1173 #ifdef CONFIG_VIVANTE
1174 static struct resource resources_gpu[] = {
1175     [0] = {
1176                 .name   = "gpu_irq",
1177         .start  = IRQ_GPU,
1178         .end    = IRQ_GPU,
1179         .flags  = IORESOURCE_IRQ,
1180     },
1181     [1] = {
1182                 .name = "gpu_base",
1183         .start  = RK29_GPU_PHYS,
1184         .end    = RK29_GPU_PHYS + RK29_GPU_SIZE,
1185         .flags  = IORESOURCE_MEM,
1186     },
1187     [2] = {
1188                 .name = "gpu_mem",
1189         .start  = PMEM_GPU_BASE,
1190         .end    = PMEM_GPU_BASE + PMEM_GPU_SIZE,
1191         .flags  = IORESOURCE_MEM,
1192     },
1193 };
1194 static struct platform_device rk29_device_gpu = {
1195     .name             = "galcore",
1196     .id               = 0,
1197     .num_resources    = ARRAY_SIZE(resources_gpu),
1198     .resource         = resources_gpu,
1199 };
1200 #endif
1201 #ifdef CONFIG_KEYS_RK29
1202 extern struct rk29_keys_platform_data rk29_keys_pdata;
1203 static struct platform_device rk29_device_keys = {
1204         .name           = "rk29-keypad",
1205         .id             = -1,
1206         .dev            = {
1207                 .platform_data  = &rk29_keys_pdata,
1208         },
1209 };
1210 #endif
1211
1212 static void __init rk29_board_iomux_init(void)
1213 {
1214         #ifdef CONFIG_RK29_PWM_REGULATOR
1215         rk29_mux_api_set(REGULATOR_PWM_MUX_NAME,REGULATOR_PWM_MUX_MODE);
1216         #endif
1217 }
1218
1219 static struct platform_device *devices[] __initdata = {
1220 #ifdef CONFIG_UART1_RK29
1221         &rk29_device_uart1,
1222 #endif
1223 #ifdef CONFIG_UART0_RK29
1224         &rk29_device_uart0,
1225 #endif
1226 #ifdef CONFIG_UART2_RK29
1227         &rk29_device_uart2,
1228 #endif
1229 #ifdef CONFIG_UART3_RK29
1230         &rk29_device_uart3,
1231 #endif
1232
1233 #ifdef CONFIG_RK29_PWM_REGULATOR
1234         &rk29_device_pwm_regulator,
1235 #endif
1236 #ifdef CONFIG_SPIM0_RK29
1237     &rk29xx_device_spi0m,
1238 #endif
1239 #ifdef CONFIG_SPIM1_RK29
1240     &rk29xx_device_spi1m,
1241 #endif
1242 #ifdef CONFIG_ADC_RK29
1243         &rk29_device_adc,
1244 #endif
1245 #ifdef CONFIG_I2C0_RK29
1246         &rk29_device_i2c0,
1247 #endif
1248 #ifdef CONFIG_I2C1_RK29
1249         &rk29_device_i2c1,
1250 #endif
1251 #ifdef CONFIG_I2C2_RK29
1252         &rk29_device_i2c2,
1253 #endif
1254 #ifdef CONFIG_I2C3_RK29
1255         &rk29_device_i2c3,
1256 #endif
1257
1258 #ifdef CONFIG_SND_RK29_SOC_I2S_2CH
1259         &rk29_device_iis_2ch,
1260 #endif
1261 #ifdef CONFIG_SND_RK29_SOC_I2S_8CH
1262         &rk29_device_iis_8ch,
1263 #endif
1264
1265 #ifdef CONFIG_KEYS_RK29
1266         &rk29_device_keys,
1267 #endif
1268 #ifdef CONFIG_SDMMC0_RK29
1269         &rk29_device_sdmmc0,
1270 #endif
1271 #ifdef CONFIG_SDMMC1_RK29
1272         &rk29_device_sdmmc1,
1273 #endif
1274
1275 #ifdef CONFIG_MTD_NAND_RK29XX
1276         &rk29xx_device_nand,
1277 #endif
1278
1279 #ifdef CONFIG_WIFI_CONTROL_FUNC
1280         &rk29sdk_wifi_device,
1281 #endif
1282
1283 #ifdef CONFIG_BT
1284         &rk29sdk_rfkill,
1285 #endif
1286
1287 #ifdef CONFIG_MTD_NAND_RK29
1288         &rk29_device_nand,
1289 #endif
1290
1291 #ifdef CONFIG_FB_RK29
1292         &rk29_device_fb,
1293         &rk29_device_dma_cpy,
1294 #endif
1295 #ifdef CONFIG_BACKLIGHT_RK29_BL
1296         &rk29_device_backlight,
1297 #endif
1298 #ifdef CONFIG_RK29_VMAC
1299         &rk29_device_vmac,
1300 #endif
1301 #ifdef CONFIG_VIVANTE
1302         &rk29_device_gpu,
1303 #endif
1304 #ifdef CONFIG_VIDEO_RK29
1305         &rk29_device_camera,      /* ddl@rock-chips.com : camera support  */
1306         #if (CONFIG_SENSOR_IIC_ADDR_0 != 0x00)
1307         &rk29_soc_camera_pdrv_0,
1308         #endif
1309         &rk29_soc_camera_pdrv_1,
1310         &android_pmem_cam_device,
1311 #endif
1312         &android_pmem_device,
1313         &rk29_vpu_mem_device,
1314 #ifdef CONFIG_USB20_OTG
1315         &rk29_device_usb20_otg,
1316 #endif
1317 #ifdef CONFIG_USB20_HOST
1318         &rk29_device_usb20_host,
1319 #endif
1320 #ifdef CONFIG_USB11_HOST
1321         &rk29_device_usb11_host,
1322 #endif
1323 #ifdef CONFIG_USB_ANDROID
1324         &android_usb_device,
1325         &usb_mass_storage_device,
1326 #endif
1327 #ifdef CONFIG_RK29_IPP
1328         &rk29_device_ipp,
1329 #endif
1330 #ifdef CONFIG_VIDEO_RK29XX_VOUT
1331         &rk29_v4l2_output_devce,
1332 #endif
1333 };
1334
1335 /*****************************************************************************************
1336  * spi devices
1337  * author: cmc@rock-chips.com
1338  *****************************************************************************************/
1339 static int rk29_vmac_register_set(void)
1340 {
1341         //config rk29 vmac as rmii, 100MHz
1342         u32 value= readl(RK29_GRF_BASE + 0xbc);
1343         value = (value & 0xfff7ff) | (0x400);
1344         writel(value, RK29_GRF_BASE + 0xbc);
1345         return 0;
1346 }
1347
1348 static int rk29_rmii_io_init(void)
1349 {
1350         int err;
1351
1352         //phy power gpio
1353         err = gpio_request(RK29_PIN6_PB0, "phy_power_en");
1354         if (err) {
1355                 gpio_free(RK29_PIN6_PB0);
1356                 printk("-------request RK29_PIN6_PB0 fail--------\n");
1357                 return -1;
1358         }
1359         //phy power down
1360         gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1361         gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
1362
1363         return 0;
1364 }
1365
1366 static int rk29_rmii_io_deinit(void)
1367 {
1368         //phy power down
1369         gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1370         gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
1371         //free
1372         gpio_free(RK29_PIN6_PB0);
1373         return 0;
1374 }
1375
1376 static int rk29_rmii_power_control(int enable)
1377 {
1378         if (enable) {
1379                 //enable phy power
1380                 gpio_direction_output(RK29_PIN6_PB0, GPIO_HIGH);
1381                 gpio_set_value(RK29_PIN6_PB0, GPIO_HIGH);
1382         }
1383         else {
1384                 gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
1385                 gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
1386         }
1387         return 0;
1388 }
1389
1390 struct rk29_vmac_platform_data rk29_vmac_pdata = {
1391         .vmac_register_set = rk29_vmac_register_set,
1392         .rmii_io_init = rk29_rmii_io_init,
1393         .rmii_io_deinit = rk29_rmii_io_deinit,
1394         .rmii_power_control = rk29_rmii_power_control,
1395 };
1396
1397 /*****************************************************************************************
1398  * spi devices
1399  * author: cmc@rock-chips.com
1400  *****************************************************************************************/
1401 #define SPI_CHIPSELECT_NUM 2
1402 static struct spi_cs_gpio rk29xx_spi0_cs_gpios[SPI_CHIPSELECT_NUM] = {
1403     {
1404                 .name = "spi0 cs0",
1405                 .cs_gpio = RK29_PIN2_PC1,
1406                 .cs_iomux_name = GPIO2C1_SPI0CSN0_NAME,
1407                 .cs_iomux_mode = GPIO2H_SPI0_CSN0,
1408         },
1409         {
1410                 .name = "spi0 cs1",
1411                 .cs_gpio = RK29_PIN1_PA4,
1412                 .cs_iomux_name = GPIO1A4_EMMCWRITEPRT_SPI0CS1_NAME,//if no iomux,set it NULL
1413                 .cs_iomux_mode = GPIO1L_SPI0_CSN1,
1414         }
1415 };
1416
1417 static struct spi_cs_gpio rk29xx_spi1_cs_gpios[SPI_CHIPSELECT_NUM] = {
1418     {
1419                 .name = "spi1 cs0",
1420                 .cs_gpio = RK29_PIN2_PC5,
1421                 .cs_iomux_name = GPIO2C5_SPI1CSN0_NAME,
1422                 .cs_iomux_mode = GPIO2H_SPI1_CSN0,
1423         },
1424         {
1425                 .name = "spi1 cs1",
1426                 .cs_gpio = RK29_PIN1_PA3,
1427                 .cs_iomux_name = GPIO1A3_EMMCDETECTN_SPI1CS1_NAME,//if no iomux,set it NULL
1428                 .cs_iomux_mode = GPIO1L_SPI1_CSN1,
1429         }
1430 };
1431
1432 static int spi_io_init(struct spi_cs_gpio *cs_gpios, int cs_num)
1433 {
1434 #if 1
1435         int i;
1436         if (cs_gpios) {
1437                 for (i=0; i<cs_num; i++) {
1438                         rk29_mux_api_set(cs_gpios[i].cs_iomux_name, cs_gpios[i].cs_iomux_mode);
1439                 }
1440         }
1441 #endif
1442         return 0;
1443 }
1444
1445 static int spi_io_deinit(struct spi_cs_gpio *cs_gpios, int cs_num)
1446 {
1447         return 0;
1448 }
1449
1450 static int spi_io_fix_leakage_bug(void)
1451 {
1452 #if 0
1453         gpio_direction_output(RK29_PIN2_PC1, GPIO_LOW);
1454 #endif
1455         return 0;
1456 }
1457
1458 static int spi_io_resume_leakage_bug(void)
1459 {
1460 #if 0
1461         gpio_direction_output(RK29_PIN2_PC1, GPIO_HIGH);
1462 #endif
1463         return 0;
1464 }
1465
1466 struct rk29xx_spi_platform_data rk29xx_spi0_platdata = {
1467         .num_chipselect = SPI_CHIPSELECT_NUM,
1468         .chipselect_gpios = rk29xx_spi0_cs_gpios,
1469         .io_init = spi_io_init,
1470         .io_deinit = spi_io_deinit,
1471         .io_fix_leakage_bug = spi_io_fix_leakage_bug,
1472         .io_resume_leakage_bug = spi_io_resume_leakage_bug,
1473 };
1474
1475 struct rk29xx_spi_platform_data rk29xx_spi1_platdata = {
1476         .num_chipselect = SPI_CHIPSELECT_NUM,
1477         .chipselect_gpios = rk29xx_spi1_cs_gpios,
1478         .io_init = spi_io_init,
1479         .io_deinit = spi_io_deinit,
1480         .io_fix_leakage_bug = spi_io_fix_leakage_bug,
1481         .io_resume_leakage_bug = spi_io_resume_leakage_bug,
1482 };
1483
1484 /*****************************************************************************************
1485  * xpt2046 touch panel
1486  * author: cmc@rock-chips.com
1487  *****************************************************************************************/
1488 #define XPT2046_GPIO_INT           RK29_PIN0_PA3
1489 #define DEBOUNCE_REPTIME  3
1490
1491 #if defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_SPI)
1492 static struct xpt2046_platform_data xpt2046_info = {
1493         .model                  = 2046,
1494         .keep_vref_on   = 1,
1495         .swap_xy                = 0,
1496         .x_min                  = 0,
1497         .x_max                  = 320,
1498         .y_min                  = 0,
1499         .y_max                  = 480,
1500         .debounce_max           = 7,
1501         .debounce_rep           = DEBOUNCE_REPTIME,
1502         .debounce_tol           = 20,
1503         .gpio_pendown           = XPT2046_GPIO_INT,
1504         .penirq_recheck_delay_usecs = 1,
1505 };
1506 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)
1507 static struct xpt2046_platform_data xpt2046_info = {
1508         .model                  = 2046,
1509         .keep_vref_on   = 1,
1510         .swap_xy                = 0,
1511         .x_min                  = 0,
1512         .x_max                  = 320,
1513         .y_min                  = 0,
1514         .y_max                  = 480,
1515         .debounce_max           = 7,
1516         .debounce_rep           = DEBOUNCE_REPTIME,
1517         .debounce_tol           = 20,
1518         .gpio_pendown           = XPT2046_GPIO_INT,
1519         .penirq_recheck_delay_usecs = 1,
1520 };
1521 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
1522 static struct xpt2046_platform_data xpt2046_info = {
1523         .model                  = 2046,
1524         .keep_vref_on   = 1,
1525         .swap_xy                = 1,
1526         .x_min                  = 0,
1527         .x_max                  = 800,
1528         .y_min                  = 0,
1529         .y_max                  = 480,
1530         .debounce_max           = 7,
1531         .debounce_rep           = DEBOUNCE_REPTIME,
1532         .debounce_tol           = 20,
1533         .gpio_pendown           = XPT2046_GPIO_INT,
1534
1535         .penirq_recheck_delay_usecs = 1,
1536 };
1537 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
1538 static struct xpt2046_platform_data xpt2046_info = {
1539         .model                  = 2046,
1540         .keep_vref_on   = 1,
1541         .swap_xy                = 1,
1542         .x_min                  = 0,
1543         .x_max                  = 800,
1544         .y_min                  = 0,
1545         .y_max                  = 480,
1546         .debounce_max           = 7,
1547         .debounce_rep           = DEBOUNCE_REPTIME,
1548         .debounce_tol           = 20,
1549         .gpio_pendown           = XPT2046_GPIO_INT,
1550
1551         .penirq_recheck_delay_usecs = 1,
1552 };
1553 #endif
1554
1555 static struct spi_board_info board_spi_devices[] = {
1556 #if defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)\
1557     ||defined(CONFIG_TOUCHSCREEN_XPT2046_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
1558         {
1559                 .modalias       = "xpt2046_ts",
1560                 .chip_select    = 0,
1561                 .max_speed_hz   = 125 * 1000 * 26,/* (max sample rate @ 3V) * (cmd + data + overhead) */
1562                 .bus_num        = 0,
1563                 .irq = XPT2046_GPIO_INT,
1564                 .platform_data = &xpt2046_info,
1565         },
1566 #endif
1567 };
1568
1569
1570 static void __init rk29_gic_init_irq(void)
1571 {
1572         gic_dist_init(0, (void __iomem *)RK29_GICPERI_BASE, 32);
1573         gic_cpu_init(0, (void __iomem *)RK29_GICCPU_BASE);
1574 }
1575
1576 static void __init machine_rk29_init_irq(void)
1577 {
1578         rk29_gic_init_irq();
1579         rk29_gpio_init();
1580 }
1581
1582 static void __init machine_rk29_board_init(void)
1583 {
1584         rk29_board_iomux_init();
1585
1586         board_power_init();
1587
1588                 platform_add_devices(devices, ARRAY_SIZE(devices));
1589 #ifdef CONFIG_I2C0_RK29
1590         i2c_register_board_info(default_i2c0_data.bus_num, board_i2c0_devices,
1591                         ARRAY_SIZE(board_i2c0_devices));
1592 #endif
1593 #ifdef CONFIG_I2C1_RK29
1594         i2c_register_board_info(default_i2c1_data.bus_num, board_i2c1_devices,
1595                         ARRAY_SIZE(board_i2c1_devices));
1596 #endif
1597 #ifdef CONFIG_I2C2_RK29
1598         i2c_register_board_info(default_i2c2_data.bus_num, board_i2c2_devices,
1599                         ARRAY_SIZE(board_i2c2_devices));
1600 #endif
1601 #ifdef CONFIG_I2C3_RK29
1602         i2c_register_board_info(default_i2c3_data.bus_num, board_i2c3_devices,
1603                         ARRAY_SIZE(board_i2c3_devices));
1604 #endif
1605
1606         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1607         
1608 #ifdef CONFIG_WIFI_CONTROL_FUNC
1609         rk29sdk_wifi_bt_gpio_control_init();
1610         rk29sdk_init_wifi_mem();
1611 #endif
1612
1613         board_usb_detect_init(RK29_PIN0_PA0);
1614 }
1615
1616 static void __init machine_rk29_fixup(struct machine_desc *desc, struct tag *tags,
1617                                         char **cmdline, struct meminfo *mi)
1618 {
1619         mi->nr_banks = 1;
1620         mi->bank[0].start = RK29_SDRAM_PHYS;
1621         mi->bank[0].node = PHYS_TO_NID(RK29_SDRAM_PHYS);
1622         mi->bank[0].size = LINUX_SIZE;
1623 }
1624
1625 static void __init machine_rk29_mapio(void)
1626 {
1627         rk29_map_common_io();
1628         rk29_setup_early_printk();
1629         rk29_sram_init();
1630         rk29_clock_init(periph_pll_288mhz);
1631         rk29_iomux_init();
1632     ddr_init(DDR_TYPE,DDR_FREQ);  // DDR3_1333H, 400
1633 }
1634
1635 MACHINE_START(RK29, "RK29board")
1636         /* UART for LL DEBUG */
1637         .phys_io        = RK29_UART1_PHYS,
1638         .io_pg_offst    = ((RK29_UART1_BASE) >> 18) & 0xfffc,
1639         .boot_params    = RK29_SDRAM_PHYS + 0x88000,
1640         .fixup          = machine_rk29_fixup,
1641         .map_io         = machine_rk29_mapio,
1642         .init_irq       = machine_rk29_init_irq,
1643         .init_machine   = machine_rk29_board_init,
1644         .timer          = &rk29_timer,
1645 MACHINE_END