rk29 gpu :
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk29 / board-rk29-ddr3sdk.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/skbuff.h>
24 #include <linux/spi/spi.h>
25 #include <linux/mmc/host.h>
26 #include <linux/android_pmem.h>
27 #ifdef CONFIG_USB_ANDROID
28 #include <linux/usb/android_composite.h>
29 #endif
30 #include <linux/ion.h>
31
32 #include <mach/hardware.h>
33 #include <asm/setup.h>
34 #include <asm/mach-types.h>
35 #include <asm/mach/arch.h>
36 #include <asm/mach/map.h>
37 #include <asm/mach/flash.h>
38 #include <asm/hardware/gic.h>
39
40 #include <mach/iomux.h>
41 #include <mach/gpio.h>
42 #include <mach/irqs.h>
43 #include <mach/rk29_iomap.h>
44 #include <mach/board.h>
45 #include <mach/rk29_nand.h>
46 #include <mach/rk29_camera.h>                          /* ddl@rock-chips.com : camera support */
47 #include <media/soc_camera.h>                               /* ddl@rock-chips.com : camera support */
48 #include <mach/vpu_mem.h>
49 #include <mach/sram.h>
50 #include <mach/ddr.h>
51 #include <mach/cpufreq.h>
52 #include <mach/rk29_smc.h>
53
54 #include <linux/regulator/rk29-pwm-regulator.h>
55 #include <linux/regulator/machine.h>
56
57 #include <linux/regulator/act8891.h>
58
59 #include <linux/mtd/nand.h>
60 #include <linux/mtd/partitions.h>
61 #include <linux/i2c-gpio.h>
62 #include <linux/mpu.h>
63 #include "devices.h"
64 #include "../../../drivers/input/touchscreen/xpt2046_cbn_ts.h"
65
66 #ifdef CONFIG_BU92747GUW_CIR
67 #include "../../../drivers/cir/bu92747guw_cir.h"
68 #endif
69 #ifdef CONFIG_VIDEO_RK29
70 /*---------------- Camera Sensor Macro Define Begin  ------------------------*/
71 /*---------------- Camera Sensor Configuration Macro Begin ------------------------*/
72 #define CONFIG_SENSOR_0 RK29_CAM_SENSOR_OV5642                      /* back camera sensor 0 */
73 #define CONFIG_SENSOR_IIC_ADDR_0            0x78
74 #define CONFIG_SENSOR_IIC_ADAPTER_ID_0    1
75 #define CONFIG_SENSOR_ORIENTATION_0       90
76 #define CONFIG_SENSOR_POWER_PIN_0         INVALID_GPIO
77 #define CONFIG_SENSOR_RESET_PIN_0         INVALID_GPIO
78 #define CONFIG_SENSOR_POWERDN_PIN_0       RK29_PIN6_PB7
79 #define CONFIG_SENSOR_FALSH_PIN_0         INVALID_GPIO
80 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_0 RK29_CAM_POWERACTIVE_L
81 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_0 RK29_CAM_RESETACTIVE_L
82 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_0 RK29_CAM_POWERDNACTIVE_H
83 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_0 RK29_CAM_FLASHACTIVE_L
84
85 #define CONFIG_SENSOR_QCIF_FPS_FIXED_0      15000
86 #define CONFIG_SENSOR_240X160_FPS_FIXED_0   15000
87 #define CONFIG_SENSOR_QVGA_FPS_FIXED_0      15000
88 #define CONFIG_SENSOR_CIF_FPS_FIXED_0       15000
89 #define CONFIG_SENSOR_VGA_FPS_FIXED_0       15000
90 #define CONFIG_SENSOR_480P_FPS_FIXED_0      15000
91 #define CONFIG_SENSOR_SVGA_FPS_FIXED_0      15000
92 #define CONFIG_SENSOR_720P_FPS_FIXED_0      30000
93
94 #define CONFIG_SENSOR_01  RK29_CAM_SENSOR_OV5642                   /* back camera sensor 1 */
95 #define CONFIG_SENSOR_IIC_ADDR_01           0x00
96 #define CONFIG_SENSOR_IIC_ADAPTER_ID_01    1
97 #define CONFIG_SENSOR_ORIENTATION_01       90
98 #define CONFIG_SENSOR_POWER_PIN_01         INVALID_GPIO
99 #define CONFIG_SENSOR_RESET_PIN_01         INVALID_GPIO
100 #define CONFIG_SENSOR_POWERDN_PIN_01       RK29_PIN6_PB7
101 #define CONFIG_SENSOR_FALSH_PIN_01         INVALID_GPIO
102 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_01 RK29_CAM_POWERACTIVE_L
103 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_01 RK29_CAM_RESETACTIVE_L
104 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_01 RK29_CAM_POWERDNACTIVE_H
105 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_01 RK29_CAM_FLASHACTIVE_L
106
107 #define CONFIG_SENSOR_QCIF_FPS_FIXED_01      15000
108 #define CONFIG_SENSOR_240X160_FPS_FIXED_01   15000
109 #define CONFIG_SENSOR_QVGA_FPS_FIXED_01      15000
110 #define CONFIG_SENSOR_CIF_FPS_FIXED_01       15000
111 #define CONFIG_SENSOR_VGA_FPS_FIXED_01       15000
112 #define CONFIG_SENSOR_480P_FPS_FIXED_01      15000
113 #define CONFIG_SENSOR_SVGA_FPS_FIXED_01      15000
114 #define CONFIG_SENSOR_720P_FPS_FIXED_01     30000
115
116 #define CONFIG_SENSOR_02 RK29_CAM_SENSOR_OV5640                      /* back camera sensor 2 */
117 #define CONFIG_SENSOR_IIC_ADDR_02           0x00
118 #define CONFIG_SENSOR_IIC_ADAPTER_ID_02    1
119 #define CONFIG_SENSOR_ORIENTATION_02       90
120 #define CONFIG_SENSOR_POWER_PIN_02         INVALID_GPIO
121 #define CONFIG_SENSOR_RESET_PIN_02         INVALID_GPIO
122 #define CONFIG_SENSOR_POWERDN_PIN_02       RK29_PIN6_PB7
123 #define CONFIG_SENSOR_FALSH_PIN_02         INVALID_GPIO
124 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_02 RK29_CAM_POWERACTIVE_L
125 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_02 RK29_CAM_RESETACTIVE_L
126 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_02 RK29_CAM_POWERDNACTIVE_H
127 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_02 RK29_CAM_FLASHACTIVE_L
128
129 #define CONFIG_SENSOR_QCIF_FPS_FIXED_02      15000
130 #define CONFIG_SENSOR_240X160_FPS_FIXED_02   15000
131 #define CONFIG_SENSOR_QVGA_FPS_FIXED_02      15000
132 #define CONFIG_SENSOR_CIF_FPS_FIXED_02       15000
133 #define CONFIG_SENSOR_VGA_FPS_FIXED_02       15000
134 #define CONFIG_SENSOR_480P_FPS_FIXED_02      15000
135 #define CONFIG_SENSOR_SVGA_FPS_FIXED_02      15000
136 #define CONFIG_SENSOR_720P_FPS_FIXED_02      30000
137
138 #define CONFIG_SENSOR_1 RK29_CAM_SENSOR_OV2659                      /* front camera sensor 0 */
139 #define CONFIG_SENSOR_IIC_ADDR_1            0x60
140 #define CONFIG_SENSOR_IIC_ADAPTER_ID_1    1
141 #define CONFIG_SENSOR_ORIENTATION_1       270
142 #define CONFIG_SENSOR_POWER_PIN_1         INVALID_GPIO
143 #define CONFIG_SENSOR_RESET_PIN_1         INVALID_GPIO
144 #define CONFIG_SENSOR_POWERDN_PIN_1       RK29_PIN5_PD7
145 #define CONFIG_SENSOR_FALSH_PIN_1         INVALID_GPIO
146 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_1 RK29_CAM_POWERACTIVE_L
147 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_1 RK29_CAM_RESETACTIVE_L
148 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_1 RK29_CAM_POWERDNACTIVE_H
149 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_1 RK29_CAM_FLASHACTIVE_L
150
151 #define CONFIG_SENSOR_QCIF_FPS_FIXED_1      15000
152 #define CONFIG_SENSOR_240X160_FPS_FIXED_1   15000
153 #define CONFIG_SENSOR_QVGA_FPS_FIXED_1      15000
154 #define CONFIG_SENSOR_CIF_FPS_FIXED_1       15000
155 #define CONFIG_SENSOR_VGA_FPS_FIXED_1       15000
156 #define CONFIG_SENSOR_480P_FPS_FIXED_1      15000
157 #define CONFIG_SENSOR_SVGA_FPS_FIXED_1      15000
158 #define CONFIG_SENSOR_720P_FPS_FIXED_1      30000
159
160 #define CONFIG_SENSOR_11 RK29_CAM_SENSOR_OV2659                      /* front camera sensor 1 */
161 #define CONFIG_SENSOR_IIC_ADDR_11           0x00
162 #define CONFIG_SENSOR_IIC_ADAPTER_ID_11    1
163 #define CONFIG_SENSOR_ORIENTATION_11       270
164 #define CONFIG_SENSOR_POWER_PIN_11         INVALID_GPIO
165 #define CONFIG_SENSOR_RESET_PIN_11         INVALID_GPIO
166 #define CONFIG_SENSOR_POWERDN_PIN_11       RK29_PIN5_PD7
167 #define CONFIG_SENSOR_FALSH_PIN_11         INVALID_GPIO
168 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_11 RK29_CAM_POWERACTIVE_L
169 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_11 RK29_CAM_RESETACTIVE_L
170 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_11 RK29_CAM_POWERDNACTIVE_H
171 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_11 RK29_CAM_FLASHACTIVE_L
172
173 #define CONFIG_SENSOR_QCIF_FPS_FIXED_11      15000
174 #define CONFIG_SENSOR_240X160_FPS_FIXED_11   15000
175 #define CONFIG_SENSOR_QVGA_FPS_FIXED_11      15000
176 #define CONFIG_SENSOR_CIF_FPS_FIXED_11       15000
177 #define CONFIG_SENSOR_VGA_FPS_FIXED_11       15000
178 #define CONFIG_SENSOR_480P_FPS_FIXED_11      15000
179 #define CONFIG_SENSOR_SVGA_FPS_FIXED_11      15000
180 #define CONFIG_SENSOR_720P_FPS_FIXED_11      30000
181
182 #define CONFIG_SENSOR_12 RK29_CAM_SENSOR_OV2655                      /* front camera sensor 2 */
183 #define CONFIG_SENSOR_IIC_ADDR_12           0x00
184 #define CONFIG_SENSOR_IIC_ADAPTER_ID_12    1
185 #define CONFIG_SENSOR_ORIENTATION_12       270
186 #define CONFIG_SENSOR_POWER_PIN_12         INVALID_GPIO
187 #define CONFIG_SENSOR_RESET_PIN_12         INVALID_GPIO
188 #define CONFIG_SENSOR_POWERDN_PIN_12       RK29_PIN5_PD7
189 #define CONFIG_SENSOR_FALSH_PIN_12         INVALID_GPIO
190 #define CONFIG_SENSOR_POWERACTIVE_LEVEL_12 RK29_CAM_POWERACTIVE_L
191 #define CONFIG_SENSOR_RESETACTIVE_LEVEL_12 RK29_CAM_RESETACTIVE_L
192 #define CONFIG_SENSOR_POWERDNACTIVE_LEVEL_12 RK29_CAM_POWERDNACTIVE_H
193 #define CONFIG_SENSOR_FLASHACTIVE_LEVEL_12 RK29_CAM_FLASHACTIVE_L
194
195 #define CONFIG_SENSOR_QCIF_FPS_FIXED_12      15000
196 #define CONFIG_SENSOR_240X160_FPS_FIXED_12   15000
197 #define CONFIG_SENSOR_QVGA_FPS_FIXED_12      15000
198 #define CONFIG_SENSOR_CIF_FPS_FIXED_12       15000
199 #define CONFIG_SENSOR_VGA_FPS_FIXED_12       15000
200 #define CONFIG_SENSOR_480P_FPS_FIXED_12      15000
201 #define CONFIG_SENSOR_SVGA_FPS_FIXED_12      15000
202 #define CONFIG_SENSOR_720P_FPS_FIXED_12      30000
203
204
205 #endif  //#ifdef CONFIG_VIDEO_RK29
206 /*---------------- Camera Sensor Configuration Macro End------------------------*/
207 #include "../../../drivers/media/video/rk29_camera.c"
208 /*---------------- Camera Sensor Macro Define End  ------------------------*/
209
210
211 /* Set memory size of pmem */
212 #ifdef CONFIG_RK29_MEM_SIZE_M
213 #define SDRAM_SIZE          (CONFIG_RK29_MEM_SIZE_M * SZ_1M)
214 #else
215 #define SDRAM_SIZE          SZ_512M
216 #endif
217 #define PMEM_GPU_SIZE       SZ_64M
218 #define PMEM_UI_SIZE        (48 * SZ_1M) /* 1280x800: 64M 1024x768: 48M ... */
219 #define PMEM_VPU_SIZE       SZ_64M
220 #define PMEM_SKYPE_SIZE     0
221 #define PMEM_CAM_SIZE       PMEM_CAM_NECESSARY
222 #ifdef CONFIG_VIDEO_RK29_WORK_IPP
223 #define MEM_CAMIPP_SIZE     PMEM_CAMIPP_NECESSARY
224 #else
225 #define MEM_CAMIPP_SIZE     0
226 #endif
227 #define MEM_FB_SIZE         (9*SZ_1M)
228 #ifdef CONFIG_FB_WORK_IPP
229 #ifdef CONFIG_FB_SCALING_OSD_1080P
230 #define MEM_FBIPP_SIZE      SZ_16M   //1920 x 1080 x 2 x 2  //RGB565 = x2;RGB888 = x4
231 #else
232 #define MEM_FBIPP_SIZE      SZ_8M   //1920 x 1080 x 2 x 2  //RGB565 = x2;RGB888 = x4
233 #endif
234 #else
235 #define MEM_FBIPP_SIZE      0
236 #endif
237 #if SDRAM_SIZE > SZ_512M
238 #define PMEM_GPU_BASE       (RK29_SDRAM_PHYS + SZ_512M - PMEM_GPU_SIZE)
239 #else
240 #define PMEM_GPU_BASE       (RK29_SDRAM_PHYS + SDRAM_SIZE - PMEM_GPU_SIZE)
241 #endif
242 #define PMEM_UI_BASE        (PMEM_GPU_BASE - PMEM_UI_SIZE)
243 #define PMEM_VPU_BASE       (PMEM_UI_BASE - PMEM_VPU_SIZE)
244 #define PMEM_CAM_BASE       (PMEM_VPU_BASE - PMEM_CAM_SIZE)
245 #define MEM_CAMIPP_BASE     (PMEM_CAM_BASE - MEM_CAMIPP_SIZE)
246 #define MEM_FB_BASE         (MEM_CAMIPP_BASE - MEM_FB_SIZE)
247 #define MEM_FBIPP_BASE      (MEM_FB_BASE - MEM_FBIPP_SIZE)
248 #define PMEM_SKYPE_BASE     (MEM_FBIPP_BASE - PMEM_SKYPE_SIZE)
249 #define LINUX_SIZE          (PMEM_SKYPE_BASE - RK29_SDRAM_PHYS)
250
251 #define PREALLOC_WLAN_SEC_NUM           4
252 #define PREALLOC_WLAN_BUF_NUM           160
253 #define PREALLOC_WLAN_SECTION_HEADER    24
254
255 #define WLAN_SECTION_SIZE_0     (PREALLOC_WLAN_BUF_NUM * 128)
256 #define WLAN_SECTION_SIZE_1     (PREALLOC_WLAN_BUF_NUM * 128)
257 #define WLAN_SECTION_SIZE_2     (PREALLOC_WLAN_BUF_NUM * 512)
258 #define WLAN_SECTION_SIZE_3     (PREALLOC_WLAN_BUF_NUM * 1024)
259
260 #define WLAN_SKB_BUF_NUM        16
261
262 static struct sk_buff *wlan_static_skb[WLAN_SKB_BUF_NUM];
263
264 struct wifi_mem_prealloc {
265         void *mem_ptr;
266         unsigned long size;
267 };
268
269 extern struct sys_timer rk29_timer;
270
271 static int rk29_nand_io_init(void)
272 {
273     return 0;
274 }
275
276 struct rk29_nand_platform_data rk29_nand_data = {
277     .width      = 1,     /* data bus width in bytes */
278     .hw_ecc     = 1,     /* hw ecc 0: soft ecc */
279     .num_flash    = 1,
280     .io_init   = rk29_nand_io_init,
281 };
282
283 #define TOUCH_SCREEN_STANDBY_PIN          RK29_PIN6_PD1
284 #define TOUCH_SCREEN_STANDBY_VALUE        GPIO_HIGH
285 #define TOUCH_SCREEN_DISPLAY_PIN          INVALID_GPIO
286 #define TOUCH_SCREEN_DISPLAY_VALUE        GPIO_HIGH
287
288 #ifdef CONFIG_FB_RK29
289 /*****************************************************************************************
290  * lcd  devices
291  * author: zyw@rock-chips.com
292  *****************************************************************************************/
293 //#ifdef  CONFIG_LCD_TD043MGEA1
294 #define LCD_TXD_PIN          INVALID_GPIO
295 #define LCD_CLK_PIN          INVALID_GPIO
296 #define LCD_CS_PIN           INVALID_GPIO
297 /*****************************************************************************************
298 * frame buffe  devices
299 * author: zyw@rock-chips.com
300 *****************************************************************************************/
301 #define FB_ID                       0
302 #define FB_DISPLAY_ON_PIN           INVALID_GPIO// RK29_PIN6_PD0
303 #define FB_LCD_STANDBY_PIN          INVALID_GPIO
304 #define FB_LCD_CABC_EN_PIN          RK29_PIN6_PD2
305 #define FB_MCU_FMK_PIN              INVALID_GPIO
306
307 #define FB_DISPLAY_ON_VALUE         GPIO_HIGH
308 #define FB_LCD_STANDBY_VALUE        GPIO_HIGH
309
310 static int rk29_lcd_io_init(void)
311 {
312     int ret = 0;
313     return ret;
314 }
315
316 static int rk29_lcd_io_deinit(void)
317 {
318     int ret = 0;
319     return ret;
320 }
321
322 static struct rk29lcd_info rk29_lcd_info = {
323     .txd_pin  = LCD_TXD_PIN,
324     .clk_pin = LCD_CLK_PIN,
325     .cs_pin = LCD_CS_PIN,
326     .io_init   = rk29_lcd_io_init,
327     .io_deinit = rk29_lcd_io_deinit,
328 };
329
330 int rk29_fb_io_enable(void)
331 {
332     if(FB_DISPLAY_ON_PIN != INVALID_GPIO)
333     {
334         gpio_direction_output(FB_DISPLAY_ON_PIN, 0);
335         gpio_set_value(FB_DISPLAY_ON_PIN, FB_DISPLAY_ON_VALUE);              
336     }
337     if(FB_LCD_STANDBY_PIN != INVALID_GPIO)
338     {
339         gpio_direction_output(FB_LCD_STANDBY_PIN, 0);
340         gpio_set_value(FB_LCD_STANDBY_PIN, FB_LCD_STANDBY_VALUE);             
341     }
342     return 0;
343 }
344
345 int rk29_fb_io_disable(void)
346 {
347     if(FB_DISPLAY_ON_PIN != INVALID_GPIO)
348     {
349         gpio_direction_output(FB_DISPLAY_ON_PIN, 0);
350         gpio_set_value(FB_DISPLAY_ON_PIN, !FB_DISPLAY_ON_VALUE);              
351     }
352     if(FB_LCD_STANDBY_PIN != INVALID_GPIO)
353     {
354         gpio_direction_output(FB_LCD_STANDBY_PIN, 0);
355         gpio_set_value(FB_LCD_STANDBY_PIN, !FB_LCD_STANDBY_VALUE);             
356     }
357     return 0;
358 }
359
360 static int rk29_fb_io_init(struct rk29_fb_setting_info *fb_setting)
361 {
362     int ret = 0;
363     if(fb_setting->mcu_fmk_en && (FB_MCU_FMK_PIN != INVALID_GPIO))
364     {
365         ret = gpio_request(FB_MCU_FMK_PIN, NULL);
366         if(ret != 0)
367         {
368             gpio_free(FB_MCU_FMK_PIN);
369             printk(">>>>>> FB_MCU_FMK_PIN gpio_request err \n ");
370         }
371         gpio_direction_input(FB_MCU_FMK_PIN);
372     }
373     if(fb_setting->disp_on_en)
374     {
375         if(FB_DISPLAY_ON_PIN != INVALID_GPIO)
376         {
377             ret = gpio_request(FB_DISPLAY_ON_PIN, NULL);
378             if(ret != 0)
379             {
380                 gpio_free(FB_DISPLAY_ON_PIN);
381                 printk(">>>>>> FB_DISPLAY_ON_PIN gpio_request err \n ");
382             }
383         }
384         else if (TOUCH_SCREEN_DISPLAY_PIN != INVALID_GPIO)
385         {
386              ret = gpio_request(TOUCH_SCREEN_DISPLAY_PIN, NULL);
387              if(ret != 0)
388              {
389                  gpio_free(TOUCH_SCREEN_DISPLAY_PIN);
390                  printk(">>>>>> TOUCH_SCREEN_DISPLAY_PIN gpio_request err \n ");
391              }
392              gpio_direction_output(TOUCH_SCREEN_DISPLAY_PIN, 0);
393              gpio_set_value(TOUCH_SCREEN_DISPLAY_PIN, TOUCH_SCREEN_DISPLAY_VALUE);
394         }
395     }
396
397     if(fb_setting->disp_on_en)
398     {
399         if(FB_LCD_STANDBY_PIN != INVALID_GPIO)
400         {
401              ret = gpio_request(FB_LCD_STANDBY_PIN, NULL);
402              if(ret != 0)
403              {
404                  gpio_free(FB_LCD_STANDBY_PIN);
405                  printk(">>>>>> FB_LCD_STANDBY_PIN gpio_request err \n ");
406              }
407         }
408         else if (TOUCH_SCREEN_STANDBY_PIN != INVALID_GPIO)
409         {
410              ret = gpio_request(TOUCH_SCREEN_STANDBY_PIN, NULL);
411              if(ret != 0)
412              {
413                  gpio_free(TOUCH_SCREEN_STANDBY_PIN);
414                  printk(">>>>>> TOUCH_SCREEN_STANDBY_PIN gpio_request err \n ");
415              }
416              gpio_direction_output(TOUCH_SCREEN_STANDBY_PIN, 0);
417              gpio_set_value(TOUCH_SCREEN_STANDBY_PIN, TOUCH_SCREEN_STANDBY_VALUE);
418          }
419     }
420
421     if(FB_LCD_CABC_EN_PIN != INVALID_GPIO)
422     {
423         ret = gpio_request(FB_LCD_CABC_EN_PIN, NULL);
424         if(ret != 0)
425         {
426             gpio_free(FB_LCD_CABC_EN_PIN);
427             printk(">>>>>> FB_LCD_CABC_EN_PIN gpio_request err \n ");
428         }
429         gpio_direction_output(FB_LCD_CABC_EN_PIN, 0);
430         gpio_set_value(FB_LCD_CABC_EN_PIN, GPIO_LOW);
431     }
432     
433     rk29_fb_io_enable();   //enable it
434
435     return ret;
436 }
437
438
439 static struct rk29fb_info rk29_fb_info = {
440     .fb_id   = FB_ID,
441     .mcu_fmk_pin = FB_MCU_FMK_PIN,
442     .lcd_info = &rk29_lcd_info,
443     .io_init   = rk29_fb_io_init,
444     .io_enable = rk29_fb_io_enable,
445     .io_disable = rk29_fb_io_disable,
446 };
447
448 /* rk29 fb resource */
449 static struct resource rk29_fb_resource[] = {
450         [0] = {
451         .name  = "lcdc reg",
452                 .start = RK29_LCDC_PHYS,
453                 .end   = RK29_LCDC_PHYS + RK29_LCDC_SIZE - 1,
454                 .flags = IORESOURCE_MEM,
455         },
456         [1] = {
457             .name  = "lcdc irq",
458                 .start = IRQ_LCDC,
459                 .end   = IRQ_LCDC,
460                 .flags = IORESOURCE_IRQ,
461         },
462         [2] = {
463             .name   = "win1 buf",
464         .start  = MEM_FB_BASE,
465         .end    = MEM_FB_BASE + MEM_FB_SIZE - 1,
466         .flags  = IORESOURCE_MEM,
467     },
468     #ifdef CONFIG_FB_WORK_IPP
469     [3] = {
470             .name   = "win1 ipp buf",
471         .start  = MEM_FBIPP_BASE,
472         .end    = MEM_FBIPP_BASE + MEM_FBIPP_SIZE - 1,
473         .flags  = IORESOURCE_MEM,
474     },
475     #endif
476 };
477
478 /*platform_device*/
479 struct platform_device rk29_device_fb = {
480         .name             = "rk29-fb",
481         .id               = 4,
482         .num_resources    = ARRAY_SIZE(rk29_fb_resource),
483         .resource         = rk29_fb_resource,
484         .dev            = {
485                 .platform_data  = &rk29_fb_info,
486         }
487 };
488
489 struct platform_device rk29_device_dma_cpy = {
490         .name             = "dma_memcpy",
491         .id               = 4,
492
493 };
494
495 #endif
496
497 #if defined(CONFIG_RK29_GPIO_SUSPEND)
498 static void key_gpio_pullupdown_enable(void)
499 {
500         gpio_pull_updown(RK29_PIN6_PA0, 0);
501         gpio_pull_updown(RK29_PIN6_PA1, 0);
502         gpio_pull_updown(RK29_PIN6_PA2, 0);
503         gpio_pull_updown(RK29_PIN6_PA3, 0);
504         gpio_pull_updown(RK29_PIN6_PA4, 0);
505         gpio_pull_updown(RK29_PIN6_PA5, 0);
506         gpio_pull_updown(RK29_PIN6_PA6, 0);
507 }
508
509 static void key_gpio_pullupdown_disable(void)
510 {
511         gpio_pull_updown(RK29_PIN6_PA0, 1);
512         gpio_pull_updown(RK29_PIN6_PA1, 1);
513         gpio_pull_updown(RK29_PIN6_PA2, 1);
514         gpio_pull_updown(RK29_PIN6_PA3, 1);
515         gpio_pull_updown(RK29_PIN6_PA4, 1);
516         gpio_pull_updown(RK29_PIN6_PA5, 1);
517         gpio_pull_updown(RK29_PIN6_PA6, 1);
518 }
519
520 void rk29_setgpio_suspend_board(void)
521 {
522         key_gpio_pullupdown_enable();
523 }
524
525 void rk29_setgpio_resume_board(void)
526 {
527         key_gpio_pullupdown_disable();
528 }
529 #endif
530
531 #if defined(CONFIG_RK_IRDA) || defined(CONFIG_BU92747GUW_CIR)
532 #define BU92747GUW_RESET_PIN         RK29_PIN3_PD4// INVALID_GPIO //
533 #define BU92747GUW_RESET_MUX_NAME    GPIO3D4_HOSTWRN_NAME//NULL //
534 #define BU92747GUW_RESET_MUX_MODE    GPIO3H_GPIO3D4//NULL //
535
536 #define BU92747GUW_PWDN_PIN          RK29_PIN3_PD3//RK29_PIN5_PA7 //
537 #define BU92747GUW_PWDN_MUX_NAME     GPIO3D3_HOSTRDN_NAME//GPIO5A7_HSADCDATA2_NAME //
538 #define BU92747GUW_PWDN_MUX_MODE     GPIO3H_GPIO3D3//GPIO5L_GPIO5A7  //
539
540 static int bu92747guw_io_init(void)
541 {
542         int ret;
543         
544         //reset pin
545     if(BU92747GUW_RESET_MUX_NAME != NULL)
546     {
547         rk29_mux_api_set(BU92747GUW_RESET_MUX_NAME, BU92747GUW_RESET_MUX_MODE);
548     }
549         ret = gpio_request(BU92747GUW_RESET_PIN, NULL);
550         if(ret != 0)
551         {
552                 gpio_free(BU92747GUW_RESET_PIN);
553                 printk(">>>>>> BU92747GUW_RESET_PIN gpio_request err \n ");
554         }
555         gpio_direction_output(BU92747GUW_RESET_PIN, GPIO_HIGH);
556
557         //power down pin
558     if(BU92747GUW_PWDN_MUX_NAME != NULL)
559     {
560         rk29_mux_api_set(BU92747GUW_PWDN_MUX_NAME, BU92747GUW_PWDN_MUX_MODE);
561     }
562         ret = gpio_request(BU92747GUW_PWDN_PIN, NULL);
563         if(ret != 0)
564         {
565                 gpio_free(BU92747GUW_PWDN_PIN);
566                 printk(">>>>>> BU92747GUW_PWDN_PIN gpio_request err \n ");
567         }
568
569         //power down as default
570         gpio_direction_output(BU92747GUW_PWDN_PIN, GPIO_LOW);
571         
572         return 0;
573 }
574
575
576 static int bu92747guw_io_deinit(void)
577 {
578         gpio_free(BU92747GUW_PWDN_PIN);
579         gpio_free(BU92747GUW_RESET_PIN);
580         return 0;
581 }
582
583 //power ctl func is share with irda and remote
584 static int nPowerOnCount = 0;
585 static DEFINE_MUTEX(bu92747_power_mutex);
586
587 //1---power on;  0---power off
588 static int bu92747guw_power_ctl(int enable)
589 {
590     printk("%s \n",__FUNCTION__);
591
592         mutex_lock(&bu92747_power_mutex);
593         if (enable) {
594                 nPowerOnCount++;
595                 if (nPowerOnCount == 1) {//power on first       
596                         //smc0_init(NULL);
597                         gpio_set_value(BU92747GUW_PWDN_PIN, GPIO_HIGH);
598                         gpio_set_value(BU92747GUW_RESET_PIN, GPIO_LOW);
599                         mdelay(5);
600                         gpio_set_value(BU92747GUW_RESET_PIN, GPIO_HIGH);
601                         mdelay(5);
602                 }
603         }
604         else {
605                 nPowerOnCount--;
606                 if (nPowerOnCount <= 0) {//power down final
607                         nPowerOnCount = 0;
608                         //smc0_exit();
609                         gpio_set_value(BU92747GUW_PWDN_PIN, GPIO_LOW);
610                 }
611         }
612         mutex_unlock(&bu92747_power_mutex);
613         return 0;
614 }
615 #endif
616
617 #ifdef CONFIG_RK_IRDA
618 #define IRDA_IRQ_PIN           RK29_PIN5_PB2
619 #define IRDA_IRQ_MUX_NAME      GPIO5B2_HSADCDATA5_NAME
620 #define IRDA_IRQ_MUX_MODE      GPIO5L_GPIO5B2
621
622 int irda_iomux_init(void)
623 {
624     int ret = 0;
625
626         //irda irq pin
627     if(IRDA_IRQ_MUX_NAME != NULL)
628     {
629         rk29_mux_api_set(IRDA_IRQ_MUX_NAME, IRDA_IRQ_MUX_MODE);
630     }
631         ret = gpio_request(IRDA_IRQ_PIN, NULL);
632         if(ret != 0)
633         {
634                 gpio_free(IRDA_IRQ_PIN);
635                 printk(">>>>>> IRDA_IRQ_PIN gpio_request err \n ");
636         }
637         gpio_pull_updown(IRDA_IRQ_PIN, GPIO_HIGH);
638         gpio_direction_input(IRDA_IRQ_PIN);
639
640     return 0;
641 }
642
643 int irda_iomux_deinit(void)
644 {
645         gpio_free(IRDA_IRQ_PIN);
646         return 0;
647 }
648
649 static struct irda_info rk29_irda_info = {
650     .intr_pin = IRDA_IRQ_PIN,
651     .iomux_init = irda_iomux_init,
652     .iomux_deinit = irda_iomux_deinit,
653         .irda_pwr_ctl = bu92747guw_power_ctl,
654 };
655
656 static struct platform_device irda_device = {
657 #ifdef CONFIG_RK_IRDA_NET
658                         .name   = "rk_irda",
659 #else
660                         .name = "bu92747_irda",
661 #endif
662     .id           = -1,
663         .dev            = {
664                 .platform_data  = &rk29_irda_info,
665         }
666 };
667 #endif
668
669 #ifdef CONFIG_BU92747GUW_CIR
670 #define BU92747_CIR_IRQ_PIN RK29_PIN5_PB0
671 #define CIR_IRQ_PIN_IOMUX_NAME GPIO5B0_HSADCDATA3_NAME
672 #define CIR_IRQ_PIN_IOMUX_VALUE GPIO5L_GPIO5B0
673 static int cir_iomux_init(void)
674 {
675         if (CIR_IRQ_PIN_IOMUX_NAME)
676                 rk29_mux_api_set(CIR_IRQ_PIN_IOMUX_NAME, CIR_IRQ_PIN_IOMUX_VALUE);
677         rk29_mux_api_set(GPIO5A7_HSADCDATA2_NAME, GPIO5L_GPIO5A7);
678         return 0;
679 }
680
681 static struct  bu92747guw_platform_data bu92747guw_pdata = {
682         .intr_pin = BU92747_CIR_IRQ_PIN,
683         .iomux_init = cir_iomux_init,
684         .iomux_deinit = NULL,
685         .cir_pwr_ctl = bu92747guw_power_ctl,
686 };  
687 #endif
688 #ifdef CONFIG_RK29_NEWTON
689 struct rk29_newton_data rk29_newton_info = {    
690 };
691 struct platform_device rk29_device_newton = {
692         .name          = "rk29_newton",
693         .id            = -1,            
694         .dev               = {
695         .platform_data = &rk29_newton_info,     
696                 }           
697         };
698 #endif
699 #if defined (CONFIG_TOUCHSCREEN_FT5406)
700 #define TOUCH_RESET_PIN RK29_PIN6_PC3
701 #define TOUCH_INT_PIN   RK29_PIN0_PA2
702 int ft5406_init_platform_hw(void)
703 {
704         printk("ft5406_init_platform_hw\n");
705     if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
706       gpio_free(TOUCH_RESET_PIN);
707       printk("ft5406_init_platform_hw gpio_request error\n");
708       return -EIO;
709     }
710
711     if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
712       gpio_free(TOUCH_INT_PIN);
713       printk("ift5406_init_platform_hw gpio_request error\n");
714       return -EIO;
715     }
716
717         gpio_direction_output(TOUCH_RESET_PIN, 0);
718         gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
719         mdelay(10);
720         gpio_direction_input(TOUCH_INT_PIN);
721         mdelay(10);
722         gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
723         msleep(300);
724     return 0;
725 }
726
727 void ft5406_exit_platform_hw(void)
728 {
729         printk("ft5406_exit_platform_hw\n");
730         gpio_free(TOUCH_RESET_PIN);
731         gpio_free(TOUCH_INT_PIN);
732 }
733
734 int ft5406_platform_sleep(void)
735 {
736         printk("ft5406_platform_sleep\n");
737         gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
738         return 0;
739 }
740
741 int ft5406_platform_wakeup(void)
742 {
743         printk("ft5406_platform_wakeup\n");
744         gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
745         msleep(300);
746         return 0;
747 }
748
749 struct ft5406_platform_data ft5406_info = {
750
751   .init_platform_hw= ft5406_init_platform_hw,
752   .exit_platform_hw= ft5406_exit_platform_hw,
753   .platform_sleep  = ft5406_platform_sleep,
754   .platform_wakeup = ft5406_platform_wakeup,
755
756 };
757 #endif
758
759 #if defined(CONFIG_TOUCHSCREEN_GT819)
760 #define TOUCH_RESET_PIN RK29_PIN6_PC3
761 #define TOUCH_INT_PIN   RK29_PIN0_PA2
762 int gt819_init_platform_hw(void)
763 {
764         printk("gt819_init_platform_hw\n");
765     if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
766       gpio_free(TOUCH_RESET_PIN);
767       printk("gt819_init_platform_hw gpio_request error\n");
768       return -EIO;
769     }
770
771     if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
772       gpio_free(TOUCH_INT_PIN);
773       printk("gt819_init_platform_hw gpio_request error\n");
774       return -EIO;
775     }
776         gpio_direction_output(TOUCH_RESET_PIN, 0);
777         gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
778         mdelay(10);
779 //      gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
780 //      mdelay(10);
781 //      gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
782         gpio_direction_input(TOUCH_INT_PIN);
783 //      mdelay(10);
784         gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
785         msleep(300);
786     return 0;
787 }
788
789
790 void gt819_exit_platform_hw(void)
791 {
792         printk("gt819_exit_platform_hw\n");
793         gpio_free(TOUCH_RESET_PIN);
794         gpio_free(TOUCH_INT_PIN);
795 }
796
797 int gt819_platform_sleep(void)
798 {
799         printk("gt819_platform_sleep\n");
800         gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
801         return 0;
802 }
803
804 int gt819_platform_wakeup(void)
805 {
806         printk("gt819_platform_wakeup\n");
807         gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
808         //msleep(5);
809         //gpio_set_value(TOUCH_INT_PIN, GPIO_LOW); 
810         //msleep(20);
811         //gpio_set_value(TOUCH_INT_PIN, GPIO_HIGH);
812         return 0;
813 }
814 struct goodix_platform_data goodix_info = {
815
816   .init_platform_hw= gt819_init_platform_hw,
817   .exit_platform_hw= gt819_exit_platform_hw,
818   .platform_sleep  = gt819_platform_sleep,
819   .platform_wakeup = gt819_platform_wakeup,
820
821 };
822 #endif
823
824
825 #if defined (CONFIG_SND_SOC_CS42L52)
826
827 int cs42l52_init_platform_hw()
828 {
829         printk("cs42l52_init_platform_hw\n");
830     if(gpio_request(RK29_PIN6_PB6,NULL) != 0){
831       gpio_free(RK29_PIN6_PB6);
832       printk("cs42l52_init_platform_hw gpio_request error\n");
833       return -EIO;
834     }
835     gpio_direction_output(RK29_PIN6_PB6, 0);
836         gpio_set_value(RK29_PIN6_PB6,GPIO_HIGH);
837         return 0;
838 }
839 struct cs42l52_platform_data cs42l52_info = {
840
841   .init_platform_hw= cs42l52_init_platform_hw,
842
843 };
844 #endif
845 #if defined (CONFIG_BATTERY_BQ27541)
846 #define DC_CHECK_PIN    RK29_PIN4_PA1
847 #define LI_LION_BAT_NUM 1
848 #define CHG_OK RK29_PIN4_PA3
849 #define BAT_LOW RK29_PIN4_PA2
850
851 static int bq27541_init_dc_check_pin(void){     
852         if(gpio_request(DC_CHECK_PIN,"dc_check") != 0){      
853                 gpio_free(DC_CHECK_PIN);      
854                 printk("bq27541 init dc check pin request error\n");      
855                 return -EIO;    
856         }       
857         gpio_direction_input(DC_CHECK_PIN);     
858         return 0;
859 }
860
861 struct bq27541_platform_data bq27541_info = {   
862         .init_dc_check_pin = bq27541_init_dc_check_pin, 
863         .dc_check_pin =  DC_CHECK_PIN,          
864         .bat_num = LI_LION_BAT_NUM,
865         .chgok_check_pin =  CHG_OK,
866         .bat_check_pin =  BAT_LOW,
867 };
868 #endif
869
870 #ifdef CONFIG_BATTERY_RK29_ADC
871 static struct rk29_adc_battery_platform_data rk29_adc_battery_platdata = {
872         .dc_det_pin      = RK29_PIN4_PA1,
873         .batt_low_pin    = RK29_PIN4_PA2,
874         .charge_set_pin  = INVALID_GPIO,
875         .charge_ok_pin   = RK29_PIN4_PA3,
876
877         .dc_det_level    = GPIO_LOW,
878         .charge_ok_level = GPIO_HIGH,
879 };
880
881 static struct platform_device rk29_device_adc_battery = {
882         .name   = "rk2918-battery",
883         .id     = -1,
884         .dev = {
885                 .platform_data = &rk29_adc_battery_platdata,
886         },
887 };
888 #endif
889
890 static struct android_pmem_platform_data android_pmem_pdata = {
891         .name           = "pmem",
892         .start          = PMEM_UI_BASE,
893         .size           = PMEM_UI_SIZE,
894         .no_allocator   = 1,
895         .cached         = 1,
896 };
897
898 static struct platform_device android_pmem_device = {
899         .name           = "android_pmem",
900         .id             = 0,
901         .dev            = {
902                 .platform_data = &android_pmem_pdata,
903         },
904 };
905
906
907 static struct vpu_mem_platform_data vpu_mem_pdata = {
908         .name           = "vpu_mem",
909         .start          = PMEM_VPU_BASE,
910         .size           = PMEM_VPU_SIZE,
911         .cached         = 1,
912 };
913
914 static struct platform_device rk29_vpu_mem_device = {
915         .name           = "vpu_mem",
916         .id                 = 2,
917         .dev            = {
918         .platform_data = &vpu_mem_pdata,
919         },
920 };
921
922 #if PMEM_SKYPE_SIZE > 0
923 static struct android_pmem_platform_data android_pmem_skype_pdata = {
924         .name           = "pmem_skype",
925         .start          = PMEM_SKYPE_BASE,
926         .size           = PMEM_SKYPE_SIZE,
927         .no_allocator   = 0,
928         .cached         = 0,
929 };
930
931 static struct platform_device android_pmem_skype_device = {
932         .name           = "android_pmem",
933         .id             = 3,
934         .dev            = {
935                 .platform_data = &android_pmem_skype_pdata,
936         },
937 };
938 #endif
939
940 #ifdef CONFIG_ION
941 static struct ion_platform_data rk29_ion_pdata = {
942         .nr = 1,
943         .heaps = {
944                 {
945                         .type = ION_HEAP_TYPE_CARVEOUT,
946                         .id = 0,
947                         .name = "ui",
948                         .base = PMEM_UI_BASE,
949                         .size = PMEM_UI_SIZE,
950                 }
951         },
952 };
953
954 static struct platform_device rk29_ion_device = {
955         .name = "ion-rockchip",
956         .id = 0,
957         .dev = {
958                 .platform_data = &rk29_ion_pdata,
959         },
960 };
961 #endif
962
963 #ifdef CONFIG_VIDEO_RK29XX_VOUT
964 static struct platform_device rk29_v4l2_output_devce = {
965         .name           = "rk29_vout",
966 };
967 #endif
968 /*HANNSTAR_P1003 touch*/
969 #if defined (CONFIG_HANNSTAR_P1003)
970 #define TOUCH_RESET_PIN RK29_PIN6_PC3
971 #define TOUCH_INT_PIN   RK29_PIN0_PA2
972
973 int p1003_init_platform_hw(void)
974 {
975     if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
976       gpio_free(TOUCH_RESET_PIN);
977       printk("p1003_init_platform_hw gpio_request error\n");
978       return -EIO;
979     }
980
981     if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
982       gpio_free(TOUCH_INT_PIN);
983       printk("p1003_init_platform_hw gpio_request error\n");
984       return -EIO;
985     }
986     gpio_pull_updown(TOUCH_INT_PIN, 1);
987     gpio_direction_output(TOUCH_RESET_PIN, 0);
988     msleep(500);
989     gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
990     msleep(500);
991     gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
992
993     return 0;
994 }
995
996
997 struct p1003_platform_data p1003_info = {
998   .model= 1003,
999   .init_platform_hw= p1003_init_platform_hw,
1000
1001 };
1002 #endif
1003 #if defined (CONFIG_EETI_EGALAX)
1004 #define TOUCH_RESET_PIN RK29_PIN6_PC3
1005 #define TOUCH_INT_PIN   RK29_PIN0_PA2
1006
1007 static int EETI_EGALAX_init_platform_hw(void)
1008 {
1009     if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
1010       gpio_free(TOUCH_RESET_PIN);
1011       printk("p1003_init_platform_hw gpio_request error\n");
1012       return -EIO;
1013     }
1014
1015     if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
1016       gpio_free(TOUCH_INT_PIN);
1017       printk("p1003_init_platform_hw gpio_request error\n");
1018       return -EIO;
1019     }
1020     gpio_pull_updown(TOUCH_INT_PIN, 1);
1021     gpio_direction_output(TOUCH_RESET_PIN, 0);
1022     msleep(500);
1023     gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
1024     msleep(500);
1025     gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
1026
1027     return 0;
1028 }
1029
1030
1031 static struct eeti_egalax_platform_data eeti_egalax_info = {
1032   .model= 1003,
1033   .init_platform_hw= EETI_EGALAX_init_platform_hw,
1034   .standby_pin = TOUCH_SCREEN_STANDBY_PIN,
1035   .standby_value = TOUCH_SCREEN_STANDBY_VALUE,
1036   .disp_on_pin = TOUCH_SCREEN_DISPLAY_PIN,
1037   .disp_on_value = TOUCH_SCREEN_DISPLAY_VALUE,
1038 };
1039 #endif
1040
1041 #ifdef CONFIG_GS_KXTF9
1042 #include <linux/kxtf9.h>
1043 #define KXTF9_DEVICE_MAP 1
1044 #define KXTF9_MAP_X (KXTF9_DEVICE_MAP-1)%2
1045 #define KXTF9_MAP_Y KXTF9_DEVICE_MAP%2
1046 #define KXTF9_NEG_X (KXTF9_DEVICE_MAP/2)%2
1047 #define KXTF9_NEG_Y (KXTF9_DEVICE_MAP+1)/4
1048 #define KXTF9_NEG_Z (KXTF9_DEVICE_MAP-1)/4
1049 struct kxtf9_platform_data kxtf9_pdata = {
1050         .min_interval = 1,
1051         .poll_interval = 20,
1052         .g_range = KXTF9_G_2G,
1053         .axis_map_x = KXTF9_MAP_X,
1054         .axis_map_y = KXTF9_MAP_Y,
1055         .axis_map_z = 2,
1056         .negate_x = KXTF9_NEG_X,
1057         .negate_y = KXTF9_NEG_Y,
1058         .negate_z = KXTF9_NEG_Z,
1059         //.ctrl_regc_init = KXTF9_G_2G | ODR50F,
1060         //.ctrl_regb_init = ENABLE,
1061 };
1062 #endif /* CONFIG_GS_KXTF9 */
1063
1064
1065 /*MMA8452 gsensor*/
1066 #if defined (CONFIG_GS_MMA8452)
1067 #define MMA8452_INT_PIN   RK29_PIN0_PA3
1068
1069 static int mma8452_init_platform_hw(void)
1070 {
1071
1072     if(gpio_request(MMA8452_INT_PIN,NULL) != 0){
1073       gpio_free(MMA8452_INT_PIN);
1074       printk("mma8452_init_platform_hw gpio_request error\n");
1075       return -EIO;
1076     }
1077     gpio_pull_updown(MMA8452_INT_PIN, 1);
1078     return 0;
1079 }
1080
1081
1082 static struct mma8452_platform_data mma8452_info = {
1083   .model= 8452,
1084   .swap_xy = 0,
1085   .swap_xyz = 1,
1086   .init_platform_hw= mma8452_init_platform_hw,
1087   .orientation = { -1, 0, 0, 0, 0, 1, 0, -1, 0},
1088 };
1089 #endif
1090 /*mpu3050*/
1091 #if defined (CONFIG_MPU_SENSORS_MPU3050)
1092 static struct mpu_platform_data mpu3050_data = {
1093         .int_config = 0x10,
1094         .orientation = { 1, 0, 0,0, 1, 0, 0, 0, 1 },
1095 };
1096 #endif
1097
1098 /* accel */
1099 #if defined (CONFIG_MPU_SENSORS_KXTF9)
1100 static struct ext_slave_platform_data inv_mpu_kxtf9_data = {
1101         .bus         = EXT_SLAVE_BUS_SECONDARY,
1102         .adapt_num = 0,
1103         .orientation = {1, 0, 0, 0, 1, 0, 0, 0, 1},
1104 };
1105 #endif
1106
1107 /* compass */
1108 #if defined (CONFIG_MPU_SENSORS_AK8975)
1109 static struct ext_slave_platform_data inv_mpu_ak8975_data = {
1110         .bus         = EXT_SLAVE_BUS_PRIMARY,
1111         .adapt_num = 0,
1112         .orientation = {0, 1, 0, -1, 0, 0, 0, 0, 1},
1113 };
1114 #endif
1115
1116 #if defined (CONFIG_BATTERY_BQ27510)
1117 #define DC_CHECK_PIN    RK29_PIN4_PA1
1118 #define LI_LION_BAT_NUM 2
1119 static int bq27510_init_dc_check_pin(void){     
1120         if(gpio_request(DC_CHECK_PIN,"dc_check") != 0){      
1121                 gpio_free(DC_CHECK_PIN);      
1122                 printk("bq27510 init dc check pin request error\n");      
1123                 return -EIO;    
1124         }       
1125         gpio_direction_input(DC_CHECK_PIN);     
1126         return 0;
1127 }
1128
1129 struct bq27510_platform_data bq27510_info = {   
1130         .init_dc_check_pin = bq27510_init_dc_check_pin, 
1131         .dc_check_pin =  DC_CHECK_PIN,          
1132         .bat_num = LI_LION_BAT_NUM,
1133 };
1134 #endif
1135
1136 /*************************************PMU ACT8891****************************************/
1137
1138 #if defined (CONFIG_REGULATOR_ACT8891) 
1139                 /*dcdc mode*/
1140 /*act8891 in REGULATOR_MODE_STANDBY mode is said DCDC is in PMF mode is can save power,when in REGULATOR_MODE_NORMAL 
1141 mode is said DCDC is in PWM mode , General default is in REGULATOR_MODE_STANDBY mode*/
1142                 /*ldo mode */
1143 /*act8891 in REGULATOR_MODE_STANDBY mode is said LDO is in low power mode is can save power,when in REGULATOR_MODE_NORMAL 
1144 mode is said DCDC is in nomal mode , General default is in REGULATOR_MODE_STANDBY mode*/
1145 /*set dcdc and ldo voltage by regulator_set_voltage()*/
1146 static struct act8891 *act8891;
1147 int act8891_set_init(struct act8891 *act8891)
1148 {
1149         int tmp = 0;
1150         struct regulator *act_ldo1,*act_ldo2,*act_ldo3,*act_ldo4;
1151         struct regulator *act_dcdc1,*act_dcdc2,*act_dcdc3;
1152
1153         /*init ldo1*/
1154         act_ldo1 = regulator_get(NULL, "act_ldo1");
1155         regulator_enable(act_ldo1); 
1156         regulator_set_voltage(act_ldo1,1800000,1800000);
1157         tmp = regulator_get_voltage(act_ldo1);
1158         regulator_set_mode(act_ldo1,REGULATOR_MODE_STANDBY);
1159         //regulator_set_mode(act_ldo1,REGULATOR_MODE_NORMAL);
1160         printk("***regulator_set_init: ldo1 vcc =%d\n",tmp);
1161         regulator_put(act_ldo1);
1162          
1163         /*init ldo2*/
1164         act_ldo2 = regulator_get(NULL, "act_ldo2");
1165         regulator_enable(act_ldo2);
1166         regulator_set_voltage(act_ldo2,1200000,1200000);
1167         tmp = regulator_get_voltage(act_ldo2);
1168         regulator_set_mode(act_ldo2,REGULATOR_MODE_STANDBY);
1169         //regulator_set_mode(act_ldo2,REGULATOR_MODE_NORMAL);
1170         printk("***regulator_set_init: ldo2 vcc =%d\n",tmp);
1171         regulator_put(act_ldo2);
1172
1173         /*init ldo3*/
1174         act_ldo3 = regulator_get(NULL, "act_ldo3");
1175         regulator_enable(act_ldo3);
1176         regulator_set_voltage(act_ldo3,3300000,3300000);
1177         tmp = regulator_get_voltage(act_ldo3);
1178         regulator_set_mode(act_ldo3,REGULATOR_MODE_STANDBY);
1179         //regulator_set_mode(act_ldo3,REGULATOR_MODE_NORMAL);
1180         printk("***regulator_set_init: ldo3 vcc =%d\n",tmp);
1181         regulator_put(act_ldo3);
1182
1183         /*init ldo4*/
1184         act_ldo4 = regulator_get(NULL, "act_ldo4");
1185         regulator_enable(act_ldo4);
1186         regulator_set_voltage(act_ldo4,2500000,2500000);
1187         tmp = regulator_get_voltage(act_ldo4);
1188         regulator_set_mode(act_ldo4,REGULATOR_MODE_STANDBY);
1189         //regulator_set_mode(act_ldo4,REGULATOR_MODE_NORMAL);
1190         printk("***regulator_set_init: ldo4 vcc =%d\n",tmp);
1191         regulator_put(act_ldo4);
1192
1193         /*init dcdc1*/
1194         act_dcdc1 = regulator_get(NULL, "act_dcdc1");
1195         regulator_enable(act_dcdc1);
1196         regulator_set_voltage(act_dcdc1,3000000,3000000);
1197         tmp = regulator_get_voltage(act_dcdc1);
1198         regulator_set_mode(act_dcdc1,REGULATOR_MODE_STANDBY);
1199         //regulator_set_mode(act_dcdc1,REGULATOR_MODE_NORMAL);
1200         printk("***regulator_set_init: dcdc1 vcc =%d\n",tmp); 
1201         regulator_put(act_dcdc1);
1202
1203         /*init dcdc2*/
1204         act_dcdc2 = regulator_get(NULL, "act_dcdc2");
1205         regulator_enable(act_dcdc2);
1206         regulator_set_voltage(act_dcdc2,1500000,1500000);
1207         tmp = regulator_get_voltage(act_dcdc2);
1208         regulator_set_mode(act_dcdc2,REGULATOR_MODE_STANDBY);
1209         //regulator_set_mode(act_dcdc2,REGULATOR_MODE_NORMAL);
1210         printk("***regulator_set_init: dcdc2 vcc =%d\n",tmp);
1211         regulator_put(act_dcdc2);
1212
1213                 /*init dcdc3*/
1214         act_dcdc3 = regulator_get(NULL, "act_dcdc3");
1215         regulator_enable(act_dcdc3);
1216         regulator_set_voltage(act_dcdc3,1200000,1200000);
1217         tmp = regulator_get_voltage(act_dcdc3);
1218         regulator_set_mode(act_dcdc3,REGULATOR_MODE_STANDBY);
1219         //regulator_set_mode(act_dcdc3,REGULATOR_MODE_NORMAL);
1220         printk("***regulator_set_init: dcdc3 vcc =%d\n",tmp);
1221         regulator_put(act_dcdc3);
1222
1223         return(0);
1224 }
1225
1226 static struct regulator_consumer_supply act8891_ldo1_consumers[] = {
1227         {
1228                 .supply = "act_ldo1",
1229         }
1230 };
1231
1232 static struct regulator_init_data act8891_ldo1_data = {
1233         .constraints = {
1234                 .name = "ACT_LDO1",
1235                 .min_uV = 600000,
1236                 .max_uV = 3900000,
1237                 .apply_uV = 1,          
1238                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
1239                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
1240         },
1241         .num_consumer_supplies = ARRAY_SIZE(act8891_ldo1_consumers),
1242         .consumer_supplies = act8891_ldo1_consumers,
1243 };
1244
1245 /**/
1246 static struct regulator_consumer_supply act8891_ldo2_consumers[] = {
1247         {
1248                 .supply = "act_ldo2",
1249         }
1250 };
1251
1252 static struct regulator_init_data act8891_ldo2_data = {
1253         .constraints = {
1254                 .name = "ACT_LDO2",
1255                 .min_uV = 600000,
1256                 .max_uV = 3900000,
1257                 .apply_uV = 1,
1258                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,   
1259                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
1260         },
1261         .num_consumer_supplies = ARRAY_SIZE(act8891_ldo2_consumers),
1262         .consumer_supplies = act8891_ldo2_consumers,
1263 };
1264
1265 /*ldo3 VCC_NAND WIFI/BT/FM_BCM4325*/
1266 static struct regulator_consumer_supply act8891_ldo3_consumers[] = {
1267         {
1268                 .supply = "act_ldo3",
1269         }
1270 };
1271
1272 static struct regulator_init_data act8891_ldo3_data = {
1273         .constraints = {
1274                 .name = "ACT_LDO3",
1275                 .min_uV = 600000,
1276                 .max_uV = 3900000,
1277                 .apply_uV = 1,
1278                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
1279                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
1280         },
1281         .num_consumer_supplies = ARRAY_SIZE(act8891_ldo3_consumers),
1282         .consumer_supplies = act8891_ldo3_consumers,
1283 };
1284
1285 /*ldo4 VCCA CODEC_WM8994*/
1286 static struct regulator_consumer_supply act8891_ldo4_consumers[] = {
1287         {
1288                 .supply = "act_ldo4",
1289         }
1290 };
1291
1292 static struct regulator_init_data act8891_ldo4_data = {
1293         .constraints = {
1294                 .name = "ACT_LDO4",
1295                 .min_uV = 600000,
1296                 .max_uV = 3900000,
1297                 .apply_uV = 1,
1298                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
1299                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
1300         },
1301         .num_consumer_supplies = ARRAY_SIZE(act8891_ldo4_consumers),
1302         .consumer_supplies = act8891_ldo4_consumers,
1303 };
1304 /*buck1 vcc Core*/
1305 static struct regulator_consumer_supply act8891_dcdc1_consumers[] = {
1306         {
1307                 .supply = "act_dcdc1",
1308         }
1309 };
1310
1311 static struct regulator_init_data act8891_dcdc1_data = {
1312         .constraints = {
1313                 .name = "ACT_DCDC1",
1314                 .min_uV = 600000,
1315                 .max_uV = 3900000,
1316                 .apply_uV = 1,
1317                 //.always_on = 1,
1318                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
1319                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
1320         },
1321         .num_consumer_supplies = ARRAY_SIZE(act8891_dcdc1_consumers),
1322         .consumer_supplies = act8891_dcdc1_consumers
1323 };
1324
1325 /*buck2 VDDDR MobileDDR VCC*/
1326 static struct regulator_consumer_supply act8891_dcdc2_consumers[] = {
1327         {
1328                 .supply = "act_dcdc2",
1329         }
1330 };
1331
1332 static struct regulator_init_data act8891_dcdc2_data = {
1333         .constraints = {
1334                 .name = "ACT_DCDC2",
1335                 .min_uV = 600000,
1336                 .max_uV = 3900000,
1337                 .apply_uV = 1,
1338                 //.always_on = 1,
1339                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
1340                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
1341         },
1342         .num_consumer_supplies = ARRAY_SIZE(act8891_dcdc2_consumers),
1343         .consumer_supplies = act8891_dcdc2_consumers
1344 };
1345
1346 /*buck3 vdd Core*/
1347 static struct regulator_consumer_supply act8891_dcdc3_consumers[] = {
1348         {
1349                 .supply = "act_dcdc3",
1350         }
1351 };
1352
1353 static struct regulator_init_data act8891_dcdc3_data = {
1354         .constraints = {
1355                 .name = "ACT_DCDC3",
1356                 .min_uV = 600000,
1357                 .max_uV = 3900000,
1358                 .apply_uV = 1,
1359                 //.always_on = 1,
1360                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE | REGULATOR_CHANGE_MODE,
1361                 .valid_modes_mask = REGULATOR_MODE_STANDBY | REGULATOR_MODE_NORMAL,
1362         },
1363         .num_consumer_supplies = ARRAY_SIZE(act8891_dcdc3_consumers),
1364         .consumer_supplies = act8891_dcdc3_consumers
1365 };
1366
1367 struct act8891_regulator_subdev act8891_regulator_subdev_id[] = {
1368         {
1369                 .id=0,
1370                 .initdata=&act8891_ldo1_data,           
1371          },
1372
1373         {
1374                 .id=1,
1375                 .initdata=&act8891_ldo2_data,           
1376          },
1377
1378         {
1379                 .id=2,
1380                 .initdata=&act8891_ldo3_data,           
1381          },
1382
1383         {
1384                 .id=3,
1385                 .initdata=&act8891_ldo4_data,           
1386          },
1387
1388         {
1389                 .id=4,
1390                 .initdata=&act8891_dcdc1_data,          
1391          },
1392
1393         {
1394                 .id=5,
1395                 .initdata=&act8891_dcdc2_data,          
1396          },
1397         {
1398                 .id=6,
1399                 .initdata=&act8891_dcdc3_data,          
1400          },
1401
1402 };
1403
1404 struct act8891_platform_data act8891_data={
1405         .set_init=act8891_set_init,
1406         .num_regulators=7,
1407         .regulators=act8891_regulator_subdev_id,
1408         
1409 };
1410 #endif
1411
1412 /*****************************************************************************************
1413  * i2c devices
1414  * author: kfx@rock-chips.com
1415 *****************************************************************************************/
1416 static int rk29_i2c0_io_init(void)
1417 {
1418 #ifdef CONFIG_RK29_I2C0_CONTROLLER
1419         rk29_mux_api_set(GPIO2B7_I2C0SCL_NAME, GPIO2L_I2C0_SCL);
1420         rk29_mux_api_set(GPIO2B6_I2C0SDA_NAME, GPIO2L_I2C0_SDA);
1421 #else
1422         rk29_mux_api_set(GPIO2B7_I2C0SCL_NAME, GPIO2L_GPIO2B7);
1423         rk29_mux_api_set(GPIO2B6_I2C0SDA_NAME, GPIO2L_GPIO2B6);
1424 #endif
1425         return 0;
1426 }
1427
1428 static int rk29_i2c1_io_init(void)
1429 {
1430 #ifdef CONFIG_RK29_I2C1_CONTROLLER
1431         rk29_mux_api_set(GPIO1A7_I2C1SCL_NAME, GPIO1L_I2C1_SCL);
1432         rk29_mux_api_set(GPIO1A6_I2C1SDA_NAME, GPIO1L_I2C1_SDA);
1433 #else
1434         rk29_mux_api_set(GPIO1A7_I2C1SCL_NAME, GPIO1L_GPIO1A7);
1435         rk29_mux_api_set(GPIO1A6_I2C1SDA_NAME, GPIO1L_GPIO1A6);
1436 #endif
1437         return 0;
1438 }
1439 static int rk29_i2c2_io_init(void)
1440 {
1441 #ifdef CONFIG_RK29_I2C2_CONTROLLER
1442         rk29_mux_api_set(GPIO5D4_I2C2SCL_NAME, GPIO5H_I2C2_SCL);
1443         rk29_mux_api_set(GPIO5D3_I2C2SDA_NAME, GPIO5H_I2C2_SDA);
1444 #else
1445         rk29_mux_api_set(GPIO5D4_I2C2SCL_NAME, GPIO5H_GPIO5D4);
1446         rk29_mux_api_set(GPIO5D3_I2C2SDA_NAME, GPIO5H_GPIO5D3);
1447 #endif
1448         return 0;
1449 }
1450
1451 static int rk29_i2c3_io_init(void)
1452 {
1453 #ifdef CONFIG_RK29_I2C3_CONTROLLER
1454         rk29_mux_api_set(GPIO2B5_UART3RTSN_I2C3SCL_NAME, GPIO2L_I2C3_SCL);
1455         rk29_mux_api_set(GPIO2B4_UART3CTSN_I2C3SDA_NAME, GPIO2L_I2C3_SDA);
1456 #else
1457         rk29_mux_api_set(GPIO2B5_UART3RTSN_I2C3SCL_NAME, GPIO2L_GPIO2B5);
1458         rk29_mux_api_set(GPIO2B4_UART3CTSN_I2C3SDA_NAME, GPIO2L_GPIO2B4);
1459 #endif
1460         return 0;
1461 }
1462 #ifdef CONFIG_RK29_I2C0_CONTROLLER
1463 struct rk29_i2c_platform_data default_i2c0_data = {
1464         .bus_num    = 0,
1465         .flags      = 0,
1466         .slave_addr = 0xff,
1467         .scl_rate  = 400*1000,
1468         .mode           = I2C_MODE_IRQ,
1469         .io_init = rk29_i2c0_io_init,
1470 };
1471 #else
1472 struct i2c_gpio_platform_data default_i2c0_data = {
1473        .sda_pin = RK29_PIN2_PB6,
1474        .scl_pin = RK29_PIN2_PB7,
1475        .udelay = 5, // clk = 500/udelay = 100Khz
1476        .timeout = 100,//msecs_to_jiffies(200),
1477        .bus_num    = 0,
1478        .io_init = rk29_i2c0_io_init,
1479 };
1480 #endif
1481 #ifdef CONFIG_RK29_I2C1_CONTROLLER
1482 struct rk29_i2c_platform_data default_i2c1_data = {
1483         .bus_num    = 1,
1484         .flags      = 0,
1485         .slave_addr = 0xff,
1486         .scl_rate  = 400*1000,
1487         .mode           = I2C_MODE_IRQ,
1488         .io_init = rk29_i2c1_io_init,
1489 };
1490 #else
1491 struct i2c_gpio_platform_data default_i2c1_data = {
1492        .sda_pin = RK29_PIN1_PA6,
1493        .scl_pin = RK29_PIN1_PA7,
1494        .udelay = 5, // clk = 500/udelay = 100Khz
1495        .timeout = 100,//msecs_to_jiffies(200),
1496        .bus_num    = 1,
1497        .io_init = rk29_i2c1_io_init,
1498 };
1499 #endif
1500 #ifdef CONFIG_RK29_I2C2_CONTROLLER
1501 struct rk29_i2c_platform_data default_i2c2_data = {
1502         .bus_num    = 2,
1503         .flags      = 0,
1504         .slave_addr = 0xff,
1505         .scl_rate  = 400*1000,
1506         .mode           = I2C_MODE_IRQ,
1507         .io_init = rk29_i2c2_io_init,
1508 };
1509 #else
1510 struct i2c_gpio_platform_data default_i2c2_data = {
1511        .sda_pin = RK29_PIN5_PD3,
1512        .scl_pin = RK29_PIN5_PD4,
1513        .udelay = 5, // clk = 500/udelay = 100Khz
1514        .timeout = 100,//msecs_to_jiffies(200),
1515        .bus_num    = 2,
1516        .io_init = rk29_i2c2_io_init,
1517 };
1518 #endif
1519 #ifdef CONFIG_RK29_I2C3_CONTROLLER
1520 struct rk29_i2c_platform_data default_i2c3_data = {
1521         .bus_num    = 3,
1522         .flags      = 0,
1523         .slave_addr = 0xff,
1524         .scl_rate  = 400*1000,
1525         .mode           = I2C_MODE_IRQ,
1526         .io_init = rk29_i2c3_io_init,
1527 };
1528 #else
1529 struct i2c_gpio_platform_data default_i2c3_data = {
1530        .sda_pin = RK29_PIN5_PB5,
1531        .scl_pin = RK29_PIN5_PB4,
1532        .udelay = 5, // clk = 500/udelay = 100Khz
1533        .timeout = 100,//msecs_to_jiffies(200),
1534        .bus_num    = 3,
1535        .io_init = rk29_i2c3_io_init,
1536 };
1537 #endif
1538 #ifdef CONFIG_I2C0_RK29
1539 static struct i2c_board_info __initdata board_i2c0_devices[] = {
1540 #if defined (CONFIG_RK1000_CONTROL)
1541         {
1542                 .type                   = "rk1000_control",
1543                 .addr           = 0x40,
1544                 .flags                  = 0,
1545         },
1546 #endif
1547 #if defined (CONFIG_SND_SOC_RT5621)
1548         {
1549                 .type                   = "rt5621",
1550                 .addr                   = 0x1a,
1551                 .flags                  = 0,
1552         },
1553 #endif
1554 #if defined (CONFIG_SND_SOC_RT5631)
1555         {
1556                 .type                   = "rt5631",
1557                 .addr                   = 0x1a,
1558                 .flags                  = 0,
1559         },
1560 #endif
1561 #if defined (CONFIG_SND_SOC_RK1000)
1562         {
1563                 .type                   = "rk1000_i2c_codec",
1564                 .addr           = 0x60,
1565                 .flags                  = 0,
1566         },
1567 #endif
1568 #if defined (CONFIG_SND_SOC_WM8988)
1569         {
1570                 .type                   = "wm8988",
1571                 .addr           = 0x1A,
1572                 .flags                  = 0,
1573         },
1574 #endif
1575 #if defined (CONFIG_SND_SOC_WM8900)
1576         {
1577                 .type                   = "wm8900",
1578                 .addr           = 0x1A,
1579                 .flags                  = 0,
1580         },
1581 #endif
1582 #if defined (CONFIG_BATTERY_STC3100)
1583         {
1584                 .type                   = "stc3100",
1585                 .addr           = 0x70,
1586                 .flags                  = 0,
1587         },
1588 #endif
1589 #if defined (CONFIG_BATTERY_BQ27510)
1590         {
1591                 .type                   = "bq27510",
1592                 .addr           = 0x55,
1593                 .flags                  = 0,
1594                 .platform_data  = &bq27510_info,
1595         },
1596 #endif
1597 #if defined (CONFIG_RTC_HYM8563)
1598         {
1599                 .type                   = "rtc_hym8563",
1600                 .addr           = 0x51,
1601                 .flags                  = 0,
1602                 .irq            = RK29_PIN0_PA1,
1603         },
1604 #endif
1605 #if defined (CONFIG_GS_MMA8452)
1606     {
1607       .type           = "gs_mma8452",
1608       .addr           = 0x1c,
1609       .flags          = 0,
1610       .irq            = MMA8452_INT_PIN,
1611       .platform_data  = &mma8452_info,
1612     },
1613 #endif
1614 #if defined (CONFIG_COMPASS_AK8973)
1615         {
1616                 .type                   = "ak8973",
1617                 .addr           = 0x1d,
1618                 .flags                  = 0,
1619                 .irq                    = RK29_PIN0_PA4,
1620         },
1621 #endif
1622 #if defined (CONFIG_COMPASS_AK8975)
1623         {
1624                 .type                   = "ak8975",
1625                 .addr           = 0x0d,
1626                 .flags                  = 0,
1627                 .irq                    = RK29_PIN0_PA4,
1628         },
1629 #endif
1630 #if defined (CONFIG_MPU_SENSORS_MPU3050) 
1631         {
1632                 .type                   = "mpu3050",
1633                 .addr                   = 0x68,
1634                 .flags                  = 0,
1635                 .irq                    = RK29_PIN4_PC4,
1636                 .platform_data  = &mpu3050_data,
1637         },
1638 #endif
1639 #if defined (CONFIG_MPU_SENSORS_KXTF9)
1640         {
1641                 .type                   = "kxtf9",
1642                 .addr           = 0x0f,
1643                 .flags                  = 0,    
1644                 //.irq                  = RK29_PIN6_PC4,
1645                 .platform_data = &inv_mpu_kxtf9_data,
1646         },
1647 #endif
1648 #if defined (CONFIG_MPU_SENSORS_AK8975)
1649         {
1650                 .type                   = "ak8975",
1651                 .addr                   = 0x0d,
1652                 .flags                  = 0,    
1653                 //.irq                  = RK29_PIN6_PC5,
1654                 .platform_data = &inv_mpu_ak8975_data,
1655         },
1656 #endif
1657
1658 #if defined (CONFIG_SND_SOC_CS42L52)
1659         {
1660                 .type                   = "cs42l52",
1661                 .addr           = 0x4A,
1662                 .flags                  = 0,
1663                 .platform_data  = &cs42l52_info,
1664         },
1665 #endif
1666 #if defined (CONFIG_RTC_M41T66)
1667         {
1668                 .type           = "rtc-M41T66",
1669                 .addr           = 0x68,
1670                 .flags          = 0,
1671                 .irq            = RK29_PIN0_PA1,
1672         },
1673 #endif
1674 };
1675 #endif
1676 #if defined (CONFIG_ANX7150)
1677 struct hdmi_platform_data anx7150_data = {
1678        //.io_init = anx7150_io_init,
1679 };
1680 #endif
1681 #ifdef CONFIG_I2C1_RK29
1682 static struct i2c_board_info __initdata board_i2c1_devices[] = {
1683 #if defined (CONFIG_RK1000_CONTROL1)
1684         {
1685                 .type                   = "rk1000_control",
1686                 .addr                   = 0x40,
1687                 .flags                  = 0,
1688         },
1689 #endif
1690 #if defined (CONFIG_ANX7150)
1691     {
1692                 .type           = "anx7150",
1693         .addr           = 0x39,             //0x39, 0x3d
1694         .flags          = 0,
1695         .irq            = RK29_PIN1_PD7,
1696                 .platform_data  = &anx7150_data,
1697     },
1698 #endif
1699 #ifdef CONFIG_BU92747GUW_CIR
1700     {
1701         .type   ="bu92747_cir",
1702         .addr   = 0x77,    
1703         .flags      =0,
1704         .irq            = BU92747_CIR_IRQ_PIN,
1705         .platform_data = &bu92747guw_pdata,
1706     },
1707 #endif
1708
1709 };
1710 #endif
1711
1712 #ifdef CONFIG_I2C2_RK29
1713 static struct i2c_board_info __initdata board_i2c2_devices[] = {
1714 #if defined (CONFIG_HANNSTAR_P1003)
1715     {
1716       .type           = "p1003_touch",
1717       .addr           = 0x04,
1718       .flags          = 0, //I2C_M_NEED_DELAY
1719       .irq            = RK29_PIN0_PA2,
1720       .platform_data  = &p1003_info,
1721       //.udelay           = 100
1722     },
1723 #endif
1724 #if defined (CONFIG_EETI_EGALAX)
1725     {
1726       .type           = "egalax_i2c",
1727       .addr           = 0x04,
1728       .flags          = 0,
1729       .irq            = RK29_PIN0_PA2,
1730       .platform_data  = &eeti_egalax_info,
1731     },
1732 #endif
1733 #if defined (CONFIG_TOUCHSCREEN_GT819)
1734     {
1735                 .type   = "Goodix-TS",
1736                 .addr   = 0x55,
1737                 .flags      =0,
1738                 .irq            =RK29_PIN0_PA2,
1739                 .platform_data = &goodix_info,
1740     },
1741 #endif
1742 #if defined (CONFIG_TOUCHSCREEN_FT5406)
1743     {
1744                 .type   ="ft5x0x_ts",
1745                 .addr   = 0x38,    //0x70,
1746                 .flags      =0,
1747                 .irq            =RK29_PIN0_PA2, // support goodix tp detect, 20110706
1748                 .platform_data = &ft5406_info,
1749     },
1750 #endif
1751 };
1752 #endif
1753
1754 #ifdef CONFIG_I2C3_RK29
1755 static struct i2c_board_info __initdata board_i2c3_devices[] = {
1756 #if defined (CONFIG_BATTERY_BQ27541)
1757         {
1758                 .type                   = "bq27541",
1759                 .addr           = 0x55,
1760                 .flags                  = 0,
1761                 .platform_data  = &bq27541_info,
1762         },
1763 #endif
1764 #if defined (CONFIG_REGULATOR_ACT8891)
1765         {
1766                 .type                   = "act8891",
1767                 .addr           = 0x5b, 
1768                 .flags                  = 0,
1769                 .platform_data=&act8891_data,
1770         },
1771 #endif
1772
1773 };
1774 #endif
1775
1776 /*****************************************************************************************
1777  * camera  devices
1778  * author: ddl@rock-chips.com
1779  *****************************************************************************************/
1780 #ifdef CONFIG_VIDEO_RK29
1781 #define CONFIG_SENSOR_POWER_IOCTL_USR      0
1782 #define CONFIG_SENSOR_RESET_IOCTL_USR      0
1783 #define CONFIG_SENSOR_POWERDOWN_IOCTL_USR      0
1784 #define CONFIG_SENSOR_FLASH_IOCTL_USR      0
1785
1786 #if CONFIG_SENSOR_POWER_IOCTL_USR
1787 static int sensor_power_usr_cb (struct rk29camera_gpio_res *res,int on)
1788 {
1789     #error "CONFIG_SENSOR_POWER_IOCTL_USR is 1, sensor_power_usr_cb function must be writed!!";
1790 }
1791 #endif
1792
1793 #if CONFIG_SENSOR_RESET_IOCTL_USR
1794 static int sensor_reset_usr_cb (struct rk29camera_gpio_res *res,int on)
1795 {
1796     #error "CONFIG_SENSOR_RESET_IOCTL_USR is 1, sensor_reset_usr_cb function must be writed!!";
1797 }
1798 #endif
1799
1800 #if CONFIG_SENSOR_POWERDOWN_IOCTL_USR
1801 static int sensor_powerdown_usr_cb (struct rk29camera_gpio_res *res,int on)
1802 {
1803     #error "CONFIG_SENSOR_POWERDOWN_IOCTL_USR is 1, sensor_powerdown_usr_cb function must be writed!!";
1804 }
1805 #endif
1806
1807 #if CONFIG_SENSOR_FLASH_IOCTL_USR
1808 static int sensor_flash_usr_cb (struct rk29camera_gpio_res *res,int on)
1809 {
1810     #error "CONFIG_SENSOR_FLASH_IOCTL_USR is 1, sensor_flash_usr_cb function must be writed!!";
1811 }
1812 #endif
1813
1814 static struct rk29camera_platform_ioctl_cb  sensor_ioctl_cb = {
1815     #if CONFIG_SENSOR_POWER_IOCTL_USR
1816     .sensor_power_cb = sensor_power_usr_cb,
1817     #else
1818     .sensor_power_cb = NULL,
1819     #endif
1820
1821     #if CONFIG_SENSOR_RESET_IOCTL_USR
1822     .sensor_reset_cb = sensor_reset_usr_cb,
1823     #else
1824     .sensor_reset_cb = NULL,
1825     #endif
1826
1827     #if CONFIG_SENSOR_POWERDOWN_IOCTL_USR
1828     .sensor_powerdown_cb = sensor_powerdown_usr_cb,
1829     #else
1830     .sensor_powerdown_cb = NULL,
1831     #endif
1832
1833     #if CONFIG_SENSOR_FLASH_IOCTL_USR
1834     .sensor_flash_cb = sensor_flash_usr_cb,
1835     #else
1836     .sensor_flash_cb = NULL,
1837     #endif
1838 };
1839 #include "../../../drivers/media/video/rk29_camera.c"
1840 #endif
1841 /*****************************************************************************************
1842  * backlight  devices
1843  * author: nzy@rock-chips.com
1844  *****************************************************************************************/
1845 #ifdef CONFIG_BACKLIGHT_RK29_BL
1846  /*
1847  GPIO1B5_PWM0_NAME,       GPIO1L_PWM0
1848  GPIO5D2_PWM1_UART1SIRIN_NAME,  GPIO5H_PWM1
1849  GPIO2A3_SDMMC0WRITEPRT_PWM2_NAME,   GPIO2L_PWM2
1850  GPIO1A5_EMMCPWREN_PWM3_NAME,     GPIO1L_PWM3
1851  */
1852
1853 #define PWM_ID            0
1854 #define PWM_MUX_NAME      GPIO1B5_PWM0_NAME
1855 #define PWM_MUX_MODE      GPIO1L_PWM0
1856 #define PWM_MUX_MODE_GPIO GPIO1L_GPIO1B5
1857 #define PWM_GPIO RK29_PIN1_PB5
1858 #define PWM_EFFECT_VALUE  1
1859
1860 #define LCD_DISP_ON_PIN
1861
1862 #ifdef  LCD_DISP_ON_PIN
1863 //#define BL_EN_MUX_NAME    GPIOF34_UART3_SEL_NAME
1864 //#define BL_EN_MUX_MODE    IOMUXB_GPIO1_B34
1865
1866 #define BL_EN_PIN         RK29_PIN6_PD0
1867 #define BL_EN_VALUE       GPIO_HIGH
1868 #endif
1869 static int rk29_backlight_io_init(void)
1870 {
1871     int ret = 0;
1872
1873     rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
1874         #ifdef  LCD_DISP_ON_PIN
1875    // rk29_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
1876
1877     ret = gpio_request(BL_EN_PIN, NULL);
1878     if(ret != 0)
1879     {
1880         gpio_free(BL_EN_PIN);
1881     }
1882
1883     gpio_direction_output(BL_EN_PIN, 0);
1884     gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
1885         #endif
1886     return ret;
1887 }
1888
1889 static int rk29_backlight_io_deinit(void)
1890 {
1891     int ret = 0;
1892     #ifdef  LCD_DISP_ON_PIN
1893     gpio_free(BL_EN_PIN);
1894     #endif
1895     rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
1896     
1897     return ret;
1898 }
1899
1900 static int rk29_backlight_pwm_suspend(void)
1901 {
1902         int ret = 0;
1903         rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
1904         if (gpio_request(PWM_GPIO, NULL)) {
1905                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
1906                 return -1;
1907         }
1908         gpio_direction_output(PWM_GPIO, GPIO_LOW);
1909    #ifdef  LCD_DISP_ON_PIN
1910     gpio_direction_output(BL_EN_PIN, 0);
1911     gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
1912    #endif
1913         return ret;
1914 }
1915
1916 static int rk29_backlight_pwm_resume(void)
1917 {
1918         gpio_free(PWM_GPIO);
1919         rk29_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
1920
1921     #ifdef  LCD_DISP_ON_PIN
1922     msleep(30);
1923     gpio_direction_output(BL_EN_PIN, 1);
1924     gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
1925     #endif
1926         return 0;
1927 }
1928
1929 struct rk29_bl_info rk29_bl_info = {
1930     .pwm_id   = PWM_ID,
1931     .bl_ref   = PWM_EFFECT_VALUE,
1932     .io_init   = rk29_backlight_io_init,
1933     .io_deinit = rk29_backlight_io_deinit,
1934     .pwm_suspend = rk29_backlight_pwm_suspend,
1935     .pwm_resume = rk29_backlight_pwm_resume,
1936 };
1937 #endif
1938 /*****************************************************************************************
1939 * pwm voltage regulator devices
1940 ******************************************************************************************/
1941 #if defined (CONFIG_RK29_PWM_REGULATOR)
1942
1943 #define REGULATOR_PWM_ID                                        2
1944 #define REGULATOR_PWM_MUX_NAME                  GPIO2A3_SDMMC0WRITEPRT_PWM2_NAME
1945 #define REGULATOR_PWM_MUX_MODE                                          GPIO2L_PWM2
1946 #define REGULATOR_PWM_MUX_MODE_GPIO                             GPIO2L_GPIO2A3
1947 #define REGULATOR_PWM_GPIO                              RK29_PIN2_PA3
1948
1949 static struct regulator_consumer_supply pwm_consumers[] = {
1950         {
1951                 .supply = "vcore",
1952         }
1953 };
1954
1955 static struct regulator_init_data rk29_pwm_regulator_data = {
1956         .constraints = {
1957                 .name = "PWM2",
1958                 .min_uV =  950000,
1959                 .max_uV = 1400000,
1960                 .apply_uV = 1,
1961                 .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
1962         },
1963         .num_consumer_supplies = ARRAY_SIZE(pwm_consumers),
1964         .consumer_supplies = pwm_consumers,
1965 };
1966
1967 static struct pwm_platform_data rk29_regulator_pwm_platform_data = {
1968         .pwm_id = REGULATOR_PWM_ID,
1969         .pwm_gpio = REGULATOR_PWM_GPIO,
1970         //.pwm_iomux_name[] = REGULATOR_PWM_MUX_NAME;
1971         .pwm_iomux_name = REGULATOR_PWM_MUX_NAME,
1972         .pwm_iomux_pwm = REGULATOR_PWM_MUX_MODE,
1973         .pwm_iomux_gpio = REGULATOR_PWM_MUX_MODE_GPIO,
1974         .init_data  = &rk29_pwm_regulator_data,
1975 };
1976
1977 static struct platform_device rk29_device_pwm_regulator = {
1978         .name = "pwm-voltage-regulator",
1979         .id   = -1,
1980         .dev  = {
1981                 .platform_data = &rk29_regulator_pwm_platform_data,
1982         },
1983 };
1984
1985 #endif
1986
1987 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
1988 #define SDMMC0_WRITE_PROTECT_PIN                RK29_PIN6_PB0 //According to your own project to set the value of write-protect-pin.
1989 #endif
1990
1991
1992 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
1993 #define SDMMC1_WRITE_PROTECT_PIN                RK29_PIN6_PB0 //According to your own project to set the value of write-protect-pin.
1994 #endif
1995
1996 /*****************************************************************************************
1997  * SDMMC devices
1998 *****************************************************************************************/
1999 #if !defined(CONFIG_SDMMC_RK29_OLD)     
2000 static void rk29_sdmmc_gpio_open(int device_id, int on)
2001 {
2002     switch(device_id)
2003     {
2004         case 0://mmc0
2005         {
2006             #ifdef CONFIG_SDMMC0_RK29
2007             if(on)
2008             {
2009                 gpio_direction_output(RK29_PIN1_PD0,GPIO_HIGH);//set mmc0-clk to high
2010                 gpio_direction_output(RK29_PIN1_PD1,GPIO_HIGH);//set mmc0-cmd to high.
2011                 gpio_direction_output(RK29_PIN1_PD2,GPIO_HIGH);//set mmc0-data0 to high.
2012                 gpio_direction_output(RK29_PIN1_PD3,GPIO_HIGH);//set mmc0-data1 to high.
2013                 gpio_direction_output(RK29_PIN1_PD4,GPIO_HIGH);//set mmc0-data2 to high.
2014                 gpio_direction_output(RK29_PIN1_PD5,GPIO_HIGH);//set mmc0-data3 to high.
2015
2016                 mdelay(30);
2017             }
2018             else
2019             {
2020                 rk29_mux_api_set(GPIO1D0_SDMMC0CLKOUT_NAME, GPIO1H_GPIO1_D0);
2021                 gpio_request(RK29_PIN1_PD0, "mmc0-clk");
2022                 gpio_direction_output(RK29_PIN1_PD0,GPIO_LOW);//set mmc0-clk to low.
2023
2024                 rk29_mux_api_set(GPIO1D1_SDMMC0CMD_NAME, GPIO1H_GPIO1_D1);
2025                 gpio_request(RK29_PIN1_PD1, "mmc0-cmd");
2026                 gpio_direction_output(RK29_PIN1_PD1,GPIO_LOW);//set mmc0-cmd to low.
2027
2028                 rk29_mux_api_set(GPIO1D2_SDMMC0DATA0_NAME, GPIO1H_GPIO1D2);
2029                 gpio_request(RK29_PIN1_PD2, "mmc0-data0");
2030                 gpio_direction_output(RK29_PIN1_PD2,GPIO_LOW);//set mmc0-data0 to low.
2031
2032                 rk29_mux_api_set(GPIO1D3_SDMMC0DATA1_NAME, GPIO1H_GPIO1D3);
2033                 gpio_request(RK29_PIN1_PD3, "mmc0-data1");
2034                 gpio_direction_output(RK29_PIN1_PD3,GPIO_LOW);//set mmc0-data1 to low.
2035
2036                 rk29_mux_api_set(GPIO1D4_SDMMC0DATA2_NAME, GPIO1H_GPIO1D4);
2037                 gpio_request(RK29_PIN1_PD4, "mmc0-data2");
2038                 gpio_direction_output(RK29_PIN1_PD4,GPIO_LOW);//set mmc0-data2 to low.
2039
2040                 rk29_mux_api_set(GPIO1D5_SDMMC0DATA3_NAME, GPIO1H_GPIO1D5);
2041                 gpio_request(RK29_PIN1_PD5, "mmc0-data3");
2042                 gpio_direction_output(RK29_PIN1_PD5,GPIO_LOW);//set mmc0-data3 to low.
2043
2044                 mdelay(30);
2045             }
2046             #endif
2047         }
2048         break;
2049         
2050         case 1://mmc1
2051         {
2052             #ifdef CONFIG_SDMMC1_RK29
2053             if(on)
2054             {
2055                 gpio_direction_output(RK29_PIN1_PC7,GPIO_HIGH);//set mmc1-clk to high
2056                 gpio_direction_output(RK29_PIN1_PC2,GPIO_HIGH);//set mmc1-cmd to high.
2057                 gpio_direction_output(RK29_PIN1_PC3,GPIO_HIGH);//set mmc1-data0 to high.
2058                 gpio_direction_output(RK29_PIN1_PC4,GPIO_HIGH);//set mmc1-data1 to high.
2059                 gpio_direction_output(RK29_PIN1_PC5,GPIO_HIGH);//set mmc1-data2 to high.
2060                 gpio_direction_output(RK29_PIN1_PC6,GPIO_HIGH);//set mmc1-data3 to high.
2061                 mdelay(100);
2062             }
2063             else
2064             {
2065                 rk29_mux_api_set(GPIO1C7_SDMMC1CLKOUT_NAME, GPIO1H_GPIO1C7);
2066                 gpio_request(RK29_PIN1_PC7, "mmc1-clk");
2067                 gpio_direction_output(RK29_PIN1_PC7,GPIO_LOW);//set mmc1-clk to low.
2068
2069                 rk29_mux_api_set(GPIO1C2_SDMMC1CMD_NAME, GPIO1H_GPIO1C2);
2070                 gpio_request(RK29_PIN1_PC2, "mmc1-cmd");
2071                 gpio_direction_output(RK29_PIN1_PC2,GPIO_LOW);//set mmc1-cmd to low.
2072
2073                 rk29_mux_api_set(GPIO1C3_SDMMC1DATA0_NAME, GPIO1H_GPIO1C3);
2074                 gpio_request(RK29_PIN1_PC3, "mmc1-data0");
2075                 gpio_direction_output(RK29_PIN1_PC3,GPIO_LOW);//set mmc1-data0 to low.
2076
2077                 mdelay(100);
2078             }
2079             #endif
2080         }
2081         break; 
2082         
2083         case 2: //mmc2
2084         break;
2085         
2086         default:
2087         break;
2088     }
2089 }
2090
2091 static void rk29_sdmmc_set_iomux_mmc0(unsigned int bus_width)
2092 {
2093     switch (bus_width)
2094     {
2095         
2096         case 1://SDMMC_CTYPE_4BIT:
2097         {
2098                 rk29_mux_api_set(GPIO1D3_SDMMC0DATA1_NAME, GPIO1H_SDMMC0_DATA1);
2099                 rk29_mux_api_set(GPIO1D4_SDMMC0DATA2_NAME, GPIO1H_SDMMC0_DATA2);
2100                 rk29_mux_api_set(GPIO1D5_SDMMC0DATA3_NAME, GPIO1H_SDMMC0_DATA3);
2101         }
2102         break;
2103
2104         case 0x10000://SDMMC_CTYPE_8BIT:
2105             break;
2106         case 0xFFFF: //gpio_reset
2107         {
2108             rk29_mux_api_set(GPIO5D5_SDMMC0PWREN_NAME, GPIO5H_GPIO5D5);   
2109             gpio_request(RK29_PIN5_PD5,"sdmmc-power");
2110             gpio_direction_output(RK29_PIN5_PD5,GPIO_HIGH); //power-off
2111
2112             rk29_sdmmc_gpio_open(0, 0);
2113
2114             gpio_direction_output(RK29_PIN5_PD5,GPIO_LOW); //power-on
2115
2116             rk29_sdmmc_gpio_open(0, 1);
2117         }
2118         break;
2119
2120         default: //case 0://SDMMC_CTYPE_1BIT:
2121         {
2122                 rk29_mux_api_set(GPIO1D1_SDMMC0CMD_NAME, GPIO1H_SDMMC0_CMD);
2123                 rk29_mux_api_set(GPIO1D0_SDMMC0CLKOUT_NAME, GPIO1H_SDMMC0_CLKOUT);
2124                 rk29_mux_api_set(GPIO1D2_SDMMC0DATA0_NAME, GPIO1H_SDMMC0_DATA0);
2125
2126                 rk29_mux_api_set(GPIO1D3_SDMMC0DATA1_NAME, GPIO1H_GPIO1D3);
2127                 gpio_request(RK29_PIN1_PD3, "mmc0-data1");
2128                 gpio_direction_output(RK29_PIN1_PD3,GPIO_HIGH);
2129
2130                 rk29_mux_api_set(GPIO1D4_SDMMC0DATA2_NAME, GPIO1H_GPIO1D4);
2131                 gpio_request(RK29_PIN1_PD4, "mmc0-data2");
2132                 gpio_direction_output(RK29_PIN1_PD4,GPIO_HIGH);
2133                 
2134             rk29_mux_api_set(GPIO1D5_SDMMC0DATA3_NAME, GPIO1H_GPIO1D5);
2135             gpio_request(RK29_PIN1_PD5, "mmc0-data3");
2136                 gpio_direction_output(RK29_PIN1_PD5,GPIO_HIGH);
2137         }
2138         break;
2139         }
2140 }
2141
2142 static void rk29_sdmmc_set_iomux_mmc1(unsigned int bus_width)
2143 {
2144 #if 0
2145     switch (bus_width)
2146     {
2147         
2148         case 1://SDMMC_CTYPE_4BIT:
2149         {
2150             rk29_mux_api_set(GPIO1C2_SDMMC1CMD_NAME, GPIO1H_SDMMC1_CMD);
2151             rk29_mux_api_set(GPIO1C7_SDMMC1CLKOUT_NAME, GPIO1H_SDMMC1_CLKOUT);
2152             rk29_mux_api_set(GPIO1C3_SDMMC1DATA0_NAME, GPIO1H_SDMMC1_DATA0);
2153             rk29_mux_api_set(GPIO1C4_SDMMC1DATA1_NAME, GPIO1H_SDMMC1_DATA1);
2154             rk29_mux_api_set(GPIO1C5_SDMMC1DATA2_NAME, GPIO1H_SDMMC1_DATA2);
2155             rk29_mux_api_set(GPIO1C6_SDMMC1DATA3_NAME, GPIO1H_SDMMC1_DATA3);
2156         }
2157         break;
2158
2159         case 0x10000://SDMMC_CTYPE_8BIT:
2160             break;
2161         case 0xFFFF:
2162         {
2163            rk29_sdmmc_gpio_open(1, 0); 
2164            rk29_sdmmc_gpio_open(1, 1);
2165         }
2166         break;
2167
2168         default: //case 0://SDMMC_CTYPE_1BIT:
2169         {
2170             rk29_mux_api_set(GPIO1C2_SDMMC1CMD_NAME, GPIO1H_SDMMC1_CMD);
2171                 rk29_mux_api_set(GPIO1C7_SDMMC1CLKOUT_NAME, GPIO1H_SDMMC1_CLKOUT);
2172                 rk29_mux_api_set(GPIO1C3_SDMMC1DATA0_NAME, GPIO1H_SDMMC1_DATA0);
2173
2174             rk29_mux_api_set(GPIO1C4_SDMMC1DATA1_NAME, GPIO1H_GPIO1C4);
2175             gpio_request(RK29_PIN1_PC4, "mmc1-data1");
2176                 gpio_direction_output(RK29_PIN1_PC4,GPIO_HIGH);
2177                 
2178             rk29_mux_api_set(GPIO1C5_SDMMC1DATA2_NAME, GPIO1H_GPIO1C5);
2179             gpio_request(RK29_PIN1_PC5, "mmc1-data2");
2180                 gpio_direction_output(RK29_PIN1_PC5,GPIO_HIGH);
2181
2182             rk29_mux_api_set(GPIO1C6_SDMMC1DATA3_NAME, GPIO1H_GPIO1C6);
2183             gpio_request(RK29_PIN1_PC6, "mmc1-data3");
2184                 gpio_direction_output(RK29_PIN1_PC6,GPIO_HIGH);
2185
2186         }
2187         break;
2188         }
2189 #else
2190     rk29_mux_api_set(GPIO1C2_SDMMC1CMD_NAME, GPIO1H_SDMMC1_CMD);
2191     rk29_mux_api_set(GPIO1C7_SDMMC1CLKOUT_NAME, GPIO1H_SDMMC1_CLKOUT);
2192     rk29_mux_api_set(GPIO1C3_SDMMC1DATA0_NAME, GPIO1H_SDMMC1_DATA0);
2193     rk29_mux_api_set(GPIO1C4_SDMMC1DATA1_NAME, GPIO1H_SDMMC1_DATA1);
2194     rk29_mux_api_set(GPIO1C5_SDMMC1DATA2_NAME, GPIO1H_SDMMC1_DATA2);
2195     rk29_mux_api_set(GPIO1C6_SDMMC1DATA3_NAME, GPIO1H_SDMMC1_DATA3);
2196
2197 #endif
2198 }
2199
2200 static void rk29_sdmmc_set_iomux_mmc2(unsigned int bus_width)
2201 {
2202     ;//
2203 }
2204
2205
2206 static void rk29_sdmmc_set_iomux(int device_id, unsigned int bus_width)
2207 {
2208     switch(device_id)
2209     {
2210         case 0:
2211             #ifdef CONFIG_SDMMC0_RK29
2212             rk29_sdmmc_set_iomux_mmc0(bus_width);
2213             #endif
2214             break;
2215         case 1:
2216             #ifdef CONFIG_SDMMC1_RK29
2217             rk29_sdmmc_set_iomux_mmc1(bus_width);
2218             #endif
2219             break;
2220         case 2:
2221             rk29_sdmmc_set_iomux_mmc2(bus_width);
2222             break;
2223         default:
2224             break;
2225     }    
2226 }
2227
2228 #endif
2229
2230 #ifdef CONFIG_WIFI_CONTROL_FUNC
2231 static int rk29sdk_wifi_status(struct device *dev);
2232 static int rk29sdk_wifi_status_register(void (*callback)(int card_presend, void *dev_id), void *dev_id);
2233 #endif
2234
2235 #ifdef CONFIG_SDMMC0_RK29
2236 static int rk29_sdmmc0_cfg_gpio(void)
2237 {
2238 #ifdef CONFIG_SDMMC_RK29_OLD    
2239     rk29_mux_api_set(GPIO1D1_SDMMC0CMD_NAME, GPIO1H_SDMMC0_CMD);
2240         rk29_mux_api_set(GPIO1D0_SDMMC0CLKOUT_NAME, GPIO1H_SDMMC0_CLKOUT);
2241         rk29_mux_api_set(GPIO1D2_SDMMC0DATA0_NAME, GPIO1H_SDMMC0_DATA0);
2242         rk29_mux_api_set(GPIO1D3_SDMMC0DATA1_NAME, GPIO1H_SDMMC0_DATA1);
2243         rk29_mux_api_set(GPIO1D4_SDMMC0DATA2_NAME, GPIO1H_SDMMC0_DATA2);
2244         rk29_mux_api_set(GPIO1D5_SDMMC0DATA3_NAME, GPIO1H_SDMMC0_DATA3);
2245         
2246         rk29_mux_api_set(GPIO2A2_SDMMC0DETECTN_NAME, GPIO2L_GPIO2A2);
2247
2248     rk29_mux_api_set(GPIO5D5_SDMMC0PWREN_NAME, GPIO5H_GPIO5D5);   ///GPIO5H_SDMMC0_PWR_EN);  ///GPIO5H_GPIO5D5);
2249         gpio_request(RK29_PIN5_PD5,"sdmmc");
2250 #if 0
2251         gpio_set_value(RK29_PIN5_PD5,GPIO_HIGH);
2252         mdelay(100);
2253         gpio_set_value(RK29_PIN5_PD5,GPIO_LOW);
2254 #else
2255         gpio_direction_output(RK29_PIN5_PD5,GPIO_LOW);
2256 #endif
2257
2258 #else
2259     rk29_sdmmc_set_iomux(0, 0xFFFF);
2260     
2261         rk29_mux_api_set(GPIO2A2_SDMMC0DETECTN_NAME, GPIO2L_SDMMC0_DETECT_N);//Modifyed by xbw.
2262
2263         #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
2264     gpio_request(SDMMC0_WRITE_PROTECT_PIN,"sdmmc-wp");
2265     gpio_direction_input(SDMMC0_WRITE_PROTECT_PIN);         
2266     #endif
2267
2268 #endif
2269
2270         return 0;
2271 }
2272
2273 #define CONFIG_SDMMC0_USE_DMA
2274 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
2275         .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|MMC_VDD_29_30|
2276                                            MMC_VDD_30_31|MMC_VDD_31_32|MMC_VDD_32_33|
2277                                            MMC_VDD_33_34|MMC_VDD_34_35| MMC_VDD_35_36),
2278         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
2279         .io_init = rk29_sdmmc0_cfg_gpio,
2280         
2281 #if !defined(CONFIG_SDMMC_RK29_OLD)             
2282         .set_iomux = rk29_sdmmc_set_iomux,
2283 #endif
2284
2285         .dma_name = "sd_mmc",
2286 #ifdef CONFIG_SDMMC0_USE_DMA
2287         .use_dma  = 1,
2288 #else
2289         .use_dma = 0,
2290 #endif
2291         .detect_irq = RK29_PIN2_PA2, // INVALID_GPIO
2292         .enable_sd_wakeup = 0,
2293
2294 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
2295     .write_prt = SDMMC0_WRITE_PROTECT_PIN,
2296 #else
2297     .write_prt = INVALID_GPIO,
2298 #endif
2299 };
2300 #endif
2301 #ifdef CONFIG_SDMMC1_RK29
2302 #define CONFIG_SDMMC1_USE_DMA
2303 static int rk29_sdmmc1_cfg_gpio(void)
2304 {
2305 #if defined(CONFIG_SDMMC_RK29_OLD)
2306         rk29_mux_api_set(GPIO1C2_SDMMC1CMD_NAME, GPIO1H_SDMMC1_CMD);
2307         rk29_mux_api_set(GPIO1C7_SDMMC1CLKOUT_NAME, GPIO1H_SDMMC1_CLKOUT);
2308         rk29_mux_api_set(GPIO1C3_SDMMC1DATA0_NAME, GPIO1H_SDMMC1_DATA0);
2309         rk29_mux_api_set(GPIO1C4_SDMMC1DATA1_NAME, GPIO1H_SDMMC1_DATA1);
2310         rk29_mux_api_set(GPIO1C5_SDMMC1DATA2_NAME, GPIO1H_SDMMC1_DATA2);
2311         rk29_mux_api_set(GPIO1C6_SDMMC1DATA3_NAME, GPIO1H_SDMMC1_DATA3);
2312         //rk29_mux_api_set(GPIO1C0_UART0CTSN_SDMMC1DETECTN_NAME, GPIO1H_SDMMC1_DETECT_N);
2313
2314 #else
2315
2316 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
2317     gpio_request(SDMMC1_WRITE_PROTECT_PIN,"sdio-wp");
2318     gpio_direction_input(SDMMC1_WRITE_PROTECT_PIN);         
2319 #endif
2320
2321 #endif
2322
2323         return 0;
2324 }
2325
2326
2327
2328 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N    RK29_PIN1_PD6
2329
2330 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
2331         .host_ocr_avail = (MMC_VDD_25_26|MMC_VDD_26_27|MMC_VDD_27_28|MMC_VDD_28_29|
2332                                            MMC_VDD_29_30|MMC_VDD_30_31|MMC_VDD_31_32|
2333                                            MMC_VDD_32_33|MMC_VDD_33_34),
2334
2335 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)                                     
2336         .host_caps      = (MMC_CAP_4_BIT_DATA|MMC_CAP_SDIO_IRQ|
2337                                    MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
2338 #else
2339     .host_caps  = (MMC_CAP_4_BIT_DATA|MMC_CAP_MMC_HIGHSPEED|MMC_CAP_SD_HIGHSPEED),
2340 #endif
2341
2342         .io_init = rk29_sdmmc1_cfg_gpio,
2343         
2344 #if !defined(CONFIG_SDMMC_RK29_OLD)             
2345         .set_iomux = rk29_sdmmc_set_iomux,
2346 #endif  
2347
2348         .dma_name = "sdio",
2349 #ifdef CONFIG_SDMMC1_USE_DMA
2350         .use_dma  = 1,
2351 #else
2352         .use_dma = 0,
2353 #endif
2354
2355 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
2356 #ifdef CONFIG_WIFI_CONTROL_FUNC
2357         .status = rk29sdk_wifi_status,
2358         .register_status_notify = rk29sdk_wifi_status_register,
2359 #endif
2360 #if 0
2361         .detect_irq = RK29SDK_WIFI_SDIO_CARD_DETECT_N,
2362 #endif
2363
2364 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
2365     .write_prt = SDMMC1_WRITE_PROTECT_PIN,
2366 #else
2367     .write_prt = INVALID_GPIO, 
2368 #endif  
2369
2370 #else
2371 //for wifi develop board
2372     .detect_irq = INVALID_GPIO,
2373     .enable_sd_wakeup = 0,
2374 #endif
2375
2376 };
2377 #endif ////endif--#ifdef CONFIG_SDMMC1_RK29
2378
2379
2380 int rk29sdk_wifi_power_state = 0;
2381 int rk29sdk_bt_power_state = 0;
2382
2383 #ifdef CONFIG_WIFI_CONTROL_FUNC
2384 #define RK29SDK_WIFI_BT_GPIO_POWER_N       RK29_PIN5_PD6
2385 #define RK29SDK_WIFI_GPIO_RESET_N          RK29_PIN6_PC0
2386 #define RK29SDK_BT_GPIO_RESET_N            RK29_PIN6_PC4
2387
2388 static int rk29sdk_wifi_cd = 0;   /* wifi virtual 'card detect' status */
2389 static void (*wifi_status_cb)(int card_present, void *dev_id);
2390 static void *wifi_status_cb_devid;
2391
2392 static int rk29sdk_wifi_status(struct device *dev)
2393 {
2394         return rk29sdk_wifi_cd;
2395 }
2396
2397 static int rk29sdk_wifi_status_register(void (*callback)(int card_present, void *dev_id), void *dev_id)
2398 {
2399         if(wifi_status_cb)
2400                 return -EAGAIN;
2401         wifi_status_cb = callback;
2402         wifi_status_cb_devid = dev_id;
2403         return 0;
2404 }
2405
2406 static int rk29sdk_wifi_bt_gpio_control_init(void)
2407 {
2408     if (gpio_request(RK29SDK_WIFI_BT_GPIO_POWER_N, "wifi_bt_power")) {
2409            pr_info("%s: request wifi_bt power gpio failed\n", __func__);
2410            return -1;
2411     }
2412
2413     if (gpio_request(RK29SDK_WIFI_GPIO_RESET_N, "wifi reset")) {
2414            pr_info("%s: request wifi reset gpio failed\n", __func__);
2415            gpio_free(RK29SDK_WIFI_BT_GPIO_POWER_N);
2416            return -1;
2417     }
2418
2419     if (gpio_request(RK29SDK_BT_GPIO_RESET_N, "bt reset")) {
2420           pr_info("%s: request bt reset gpio failed\n", __func__);
2421           gpio_free(RK29SDK_WIFI_GPIO_RESET_N);
2422           return -1;
2423     }
2424
2425     gpio_direction_output(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
2426     gpio_direction_output(RK29SDK_WIFI_GPIO_RESET_N,    GPIO_LOW);
2427     gpio_direction_output(RK29SDK_BT_GPIO_RESET_N,      GPIO_LOW);
2428
2429     #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)
2430     
2431     rk29_mux_api_set(GPIO1C4_SDMMC1DATA1_NAME, GPIO1H_GPIO1C4);
2432     gpio_request(RK29_PIN1_PC4, "mmc1-data1");
2433     gpio_direction_output(RK29_PIN1_PC4,GPIO_LOW);//set mmc1-data1 to low.
2434
2435     rk29_mux_api_set(GPIO1C5_SDMMC1DATA2_NAME, GPIO1H_GPIO1C5);
2436     gpio_request(RK29_PIN1_PC5, "mmc1-data2");
2437     gpio_direction_output(RK29_PIN1_PC5,GPIO_LOW);//set mmc1-data2 to low.
2438
2439     rk29_mux_api_set(GPIO1C6_SDMMC1DATA3_NAME, GPIO1H_GPIO1C6);
2440     gpio_request(RK29_PIN1_PC6, "mmc1-data3");
2441     gpio_direction_output(RK29_PIN1_PC6,GPIO_LOW);//set mmc1-data3 to low.
2442     
2443     rk29_sdmmc_gpio_open(1, 0); //added by xbw at 2011-10-13
2444     #endif    
2445     pr_info("%s: init finished\n",__func__);
2446
2447     return 0;
2448 }
2449
2450 static int rk29sdk_wifi_power(int on)
2451 {
2452         pr_info("%s: %d\n", __func__, on);
2453         if (on){
2454                 gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_HIGH);
2455
2456                 #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)      
2457                 rk29_sdmmc_gpio_open(1, 1); //added by xbw at 2011-10-13
2458                 #endif
2459
2460                 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_HIGH);
2461                 mdelay(100);
2462                 pr_info("wifi turn on power\n");
2463         }else{
2464                 if (!rk29sdk_bt_power_state){
2465                         gpio_set_value(RK29SDK_WIFI_BT_GPIO_POWER_N, GPIO_LOW);
2466
2467                         #if defined(CONFIG_SDMMC1_RK29) && !defined(CONFIG_SDMMC_RK29_OLD)      
2468                         rk29_sdmmc_gpio_open(1, 0); //added by xbw at 2011-10-13
2469                         #endif
2470                         
2471                         mdelay(100);
2472                         pr_info("wifi shut off power\n");
2473                 }else
2474                 {
2475                         pr_info("wifi shouldn't shut off power, bt is using it!\n");
2476                 }
2477                 gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, GPIO_LOW);
2478
2479         }
2480
2481         rk29sdk_wifi_power_state = on;
2482         return 0;
2483 }
2484
2485 static int rk29sdk_wifi_reset_state;
2486 static int rk29sdk_wifi_reset(int on)
2487 {
2488         pr_info("%s: %d\n", __func__, on);
2489         gpio_set_value(RK29SDK_WIFI_GPIO_RESET_N, on);
2490         mdelay(100);
2491         rk29sdk_wifi_reset_state = on;
2492         return 0;
2493 }
2494
2495 int rk29sdk_wifi_set_carddetect(int val)
2496 {
2497         pr_info("%s:%d\n", __func__, val);
2498         rk29sdk_wifi_cd = val;
2499         if (wifi_status_cb){
2500                 wifi_status_cb(val, wifi_status_cb_devid);
2501         }else {
2502                 pr_warning("%s, nobody to notify\n", __func__);
2503         }
2504         return 0;
2505 }
2506 EXPORT_SYMBOL(rk29sdk_wifi_set_carddetect);
2507
2508 static struct wifi_mem_prealloc wifi_mem_array[PREALLOC_WLAN_SEC_NUM] = {
2509         {NULL, (WLAN_SECTION_SIZE_0 + PREALLOC_WLAN_SECTION_HEADER)},
2510         {NULL, (WLAN_SECTION_SIZE_1 + PREALLOC_WLAN_SECTION_HEADER)},
2511         {NULL, (WLAN_SECTION_SIZE_2 + PREALLOC_WLAN_SECTION_HEADER)},
2512         {NULL, (WLAN_SECTION_SIZE_3 + PREALLOC_WLAN_SECTION_HEADER)}
2513 };
2514
2515 static void *rk29sdk_mem_prealloc(int section, unsigned long size)
2516 {
2517         if (section == PREALLOC_WLAN_SEC_NUM)
2518                 return wlan_static_skb;
2519
2520         if ((section < 0) || (section > PREALLOC_WLAN_SEC_NUM))
2521                 return NULL;
2522
2523         if (wifi_mem_array[section].size < size)
2524                 return NULL;
2525
2526         return wifi_mem_array[section].mem_ptr;
2527 }
2528
2529 int __init rk29sdk_init_wifi_mem(void)
2530 {
2531         int i;
2532         int j;
2533
2534         for (i = 0 ; i < WLAN_SKB_BUF_NUM ; i++) {
2535                 wlan_static_skb[i] = dev_alloc_skb(
2536                                 ((i < (WLAN_SKB_BUF_NUM / 2)) ? 4096 : 8192));
2537
2538                 if (!wlan_static_skb[i])
2539                         goto err_skb_alloc;
2540         }
2541
2542         for (i = 0 ; i < PREALLOC_WLAN_SEC_NUM ; i++) {
2543                 wifi_mem_array[i].mem_ptr =
2544                                 kmalloc(wifi_mem_array[i].size, GFP_KERNEL);
2545
2546                 if (!wifi_mem_array[i].mem_ptr)
2547                         goto err_mem_alloc;
2548         }
2549         return 0;
2550
2551 err_mem_alloc:
2552         pr_err("Failed to mem_alloc for WLAN\n");
2553         for (j = 0 ; j < i ; j++)
2554                kfree(wifi_mem_array[j].mem_ptr);
2555
2556         i = WLAN_SKB_BUF_NUM;
2557
2558 err_skb_alloc:
2559         pr_err("Failed to skb_alloc for WLAN\n");
2560         for (j = 0 ; j < i ; j++)
2561                 dev_kfree_skb(wlan_static_skb[j]);
2562
2563         return -ENOMEM;
2564 }
2565
2566 static struct wifi_platform_data rk29sdk_wifi_control = {
2567         .set_power = rk29sdk_wifi_power,
2568         .set_reset = rk29sdk_wifi_reset,
2569         .set_carddetect = rk29sdk_wifi_set_carddetect,
2570         .mem_prealloc   = rk29sdk_mem_prealloc,
2571 };
2572 static struct platform_device rk29sdk_wifi_device = {
2573         .name = "bcm4329_wlan",
2574         .id = 1,
2575         .dev = {
2576                 .platform_data = &rk29sdk_wifi_control,
2577          },
2578 };
2579 #endif
2580
2581
2582 /* bluetooth rfkill device */
2583 static struct platform_device rk29sdk_rfkill = {
2584         .name = "rk29sdk_rfkill",
2585         .id = -1,
2586 };
2587
2588
2589 //#ifdef CONFIG_VIVANTE
2590 #define GPU_HIGH_CLOCK        552
2591 #define GPU_LOW_CLOCK         (periph_pll_default / 1000000) /* same as general pll clock rate below */
2592 static struct resource resources_gpu[] = {
2593     [0] = {
2594                 .name   = "gpu_irq",
2595         .start  = IRQ_GPU,
2596         .end    = IRQ_GPU,
2597         .flags  = IORESOURCE_IRQ,
2598     },
2599     [1] = {
2600                 .name   = "gpu_base",
2601         .start  = RK29_GPU_PHYS,
2602         .end    = RK29_GPU_PHYS + RK29_GPU_SIZE - 1,
2603         .flags  = IORESOURCE_MEM,
2604     },
2605     [2] = {
2606                 .name   = "gpu_mem",
2607         .start  = PMEM_GPU_BASE,
2608         .end    = PMEM_GPU_BASE + PMEM_GPU_SIZE - 1,
2609         .flags  = IORESOURCE_MEM,
2610     },
2611     [3] = {
2612                 .name   = "gpu_clk",
2613         .start  = GPU_LOW_CLOCK,
2614         .end    = GPU_HIGH_CLOCK,
2615         .flags  = IORESOURCE_IO,
2616     },
2617 };
2618 static struct platform_device rk29_device_gpu = {
2619     .name             = "galcore",
2620     .id               = 0,
2621     .num_resources    = ARRAY_SIZE(resources_gpu),
2622     .resource         = resources_gpu,
2623 };
2624 //#endif
2625
2626 #ifdef CONFIG_KEYS_RK29
2627 extern struct rk29_keys_platform_data rk29_keys_pdata;
2628 static struct platform_device rk29_device_keys = {
2629         .name           = "rk29-keypad",
2630         .id             = -1,
2631         .dev            = {
2632                 .platform_data  = &rk29_keys_pdata,
2633         },
2634 };
2635 #endif
2636
2637 #ifdef CONFIG_LEDS_GPIO_PLATFORM
2638 struct gpio_led rk29_leds[] = {
2639                 {
2640                         .name = "rk29_red_led",
2641                         .gpio = RK29_PIN4_PB2,
2642                         .default_trigger = "timer",
2643                         .active_low = 0,
2644                         .retain_state_suspended = 1,
2645                         .default_state = LEDS_GPIO_DEFSTATE_OFF,
2646                 },
2647                 {
2648                         .name = "rk29_green_led",
2649                         .gpio = RK29_PIN4_PB1,
2650                         .default_trigger = "timer",
2651                         .active_low = 0,
2652                         .retain_state_suspended = 1,
2653                         .default_state = LEDS_GPIO_DEFSTATE_OFF,
2654                 },
2655                 {
2656                         .name = "rk29_blue_led",
2657                         .gpio = RK29_PIN4_PB0,
2658                         .default_trigger = "timer",
2659                         .active_low = 0,
2660                         .retain_state_suspended = 1,
2661                         .default_state = LEDS_GPIO_DEFSTATE_OFF,
2662                 },
2663 };
2664
2665 struct gpio_led_platform_data rk29_leds_pdata = {
2666         .leds = &rk29_leds,
2667         .num_leds       = ARRAY_SIZE(rk29_leds),
2668 };
2669
2670 struct platform_device rk29_device_gpio_leds = {
2671         .name   = "leds-gpio",
2672         .id     = -1,
2673         .dev    = {
2674            .platform_data  = &rk29_leds_pdata,
2675         },
2676 };
2677 #endif
2678
2679 #ifdef CONFIG_LEDS_NEWTON_PWM
2680 static struct led_newton_pwm rk29_pwm_leds[] = {
2681                 {
2682                         .name = "power_led",
2683                         .pwm_id = 1,
2684                         .pwm_gpio = RK29_PIN5_PD2,
2685                         .pwm_iomux_name = GPIO5D2_PWM1_UART1SIRIN_NAME,
2686                         .pwm_iomux_pwm = GPIO5H_PWM1,
2687                         .pwm_iomux_gpio = GPIO5H_GPIO5D2,
2688                         .freq = 1000,
2689                         .period = 255,
2690                 },
2691 };
2692
2693 static struct led_newton_pwm_platform_data rk29_pwm_leds_pdata = {
2694         .leds = &rk29_pwm_leds,
2695         .num_leds       = ARRAY_SIZE(rk29_pwm_leds),
2696 };
2697
2698 static struct platform_device rk29_device_pwm_leds = {
2699         .name   = "leds_newton_pwm",
2700         .id     = -1,
2701         .dev    = {
2702            .platform_data  = &rk29_pwm_leds_pdata,
2703         },
2704 };
2705
2706 #endif
2707 static void __init rk29_board_iomux_init(void)
2708 {
2709         #ifdef CONFIG_RK29_PWM_REGULATOR
2710         rk29_mux_api_set(REGULATOR_PWM_MUX_NAME,REGULATOR_PWM_MUX_MODE);
2711         #endif
2712 }
2713
2714 static struct platform_device *devices[] __initdata = {
2715
2716 #ifdef CONFIG_RK29_WATCHDOG
2717         &rk29_device_wdt,
2718 #endif
2719
2720 #ifdef CONFIG_UART1_RK29
2721         &rk29_device_uart1,
2722 #endif
2723 #ifdef CONFIG_UART0_RK29
2724         &rk29_device_uart0,
2725 #endif
2726 #ifdef CONFIG_UART2_RK29
2727         &rk29_device_uart2,
2728 #endif
2729 #ifdef CONFIG_UART3_RK29
2730         &rk29_device_uart3,
2731 #endif
2732
2733 #ifdef CONFIG_RK29_PWM_REGULATOR
2734         &rk29_device_pwm_regulator,
2735 #endif
2736 #ifdef CONFIG_SPIM0_RK29
2737     &rk29xx_device_spi0m,
2738 #endif
2739 #ifdef CONFIG_SPIM1_RK29
2740     &rk29xx_device_spi1m,
2741 #endif
2742 #ifdef CONFIG_ADC_RK29
2743         &rk29_device_adc,
2744 #endif
2745 #ifdef CONFIG_BATTERY_RK29_ADC
2746         &rk29_device_adc_battery,
2747 #endif
2748 #ifdef CONFIG_I2C0_RK29
2749         &rk29_device_i2c0,
2750 #endif
2751 #ifdef CONFIG_I2C1_RK29
2752         &rk29_device_i2c1,
2753 #endif
2754 #ifdef CONFIG_I2C2_RK29
2755         &rk29_device_i2c2,
2756 #endif
2757 #ifdef CONFIG_I2C3_RK29
2758         &rk29_device_i2c3,
2759 #endif
2760
2761 #ifdef CONFIG_SND_RK29_SOC_I2S_2CH
2762         &rk29_device_iis_2ch,
2763 #endif
2764 #ifdef CONFIG_SND_RK29_SOC_I2S_8CH
2765         &rk29_device_iis_8ch,
2766 #endif
2767
2768 #ifdef CONFIG_KEYS_RK29
2769         &rk29_device_keys,
2770 #endif
2771 #ifdef CONFIG_KEYS_RK29_NEWTON
2772         &rk29_device_keys,
2773 #endif
2774 #ifdef CONFIG_SDMMC0_RK29
2775         &rk29_device_sdmmc0,
2776 #endif
2777 #ifdef CONFIG_SDMMC1_RK29
2778         &rk29_device_sdmmc1,
2779 #endif
2780
2781 #ifdef CONFIG_MTD_NAND_RK29XX
2782         &rk29xx_device_nand,
2783 #endif
2784
2785 #ifdef CONFIG_WIFI_CONTROL_FUNC
2786         &rk29sdk_wifi_device,
2787 #endif
2788
2789 #ifdef CONFIG_BT
2790         &rk29sdk_rfkill,
2791 #endif
2792
2793 #ifdef CONFIG_MTD_NAND_RK29
2794         &rk29_device_nand,
2795 #endif
2796
2797 #ifdef CONFIG_FB_RK29
2798         &rk29_device_fb,
2799         &rk29_device_dma_cpy,
2800 #endif
2801 #ifdef CONFIG_BACKLIGHT_RK29_BL
2802         &rk29_device_backlight,
2803 #endif
2804 #ifdef CONFIG_BACKLIGHT_RK29_NEWTON_BL
2805         &rk29_device_backlight,
2806 #endif
2807 #ifdef CONFIG_RK29_VMAC
2808         &rk29_device_vmac,
2809 #endif
2810 //#ifdef CONFIG_VIVANTE
2811         &rk29_device_gpu,
2812 //#endif
2813 #ifdef CONFIG_VIDEO_RK29
2814         &rk29_device_camera,      /* ddl@rock-chips.com : camera support  */
2815         #if (CONFIG_SENSOR_IIC_ADDR_0 != 0x00)
2816         &rk29_soc_camera_pdrv_0,
2817         #endif
2818     #if (CONFIG_SENSOR_IIC_ADDR_1 != 0x00)
2819         &rk29_soc_camera_pdrv_1,
2820         #endif
2821     #if (PMEM_CAM_SIZE > 0)
2822         &android_pmem_cam_device,
2823         #endif
2824 #endif
2825 #if PMEM_SKYPE_SIZE > 0
2826         &android_pmem_skype_device,
2827 #endif
2828 #ifdef CONFIG_ION
2829         &rk29_ion_device,
2830 #endif
2831         &android_pmem_device,
2832         &rk29_vpu_mem_device,
2833 #ifdef CONFIG_USB20_OTG
2834         &rk29_device_usb20_otg,
2835 #endif
2836 #ifdef CONFIG_USB20_HOST
2837         &rk29_device_usb20_host,
2838 #endif
2839 #ifdef CONFIG_USB11_HOST
2840         &rk29_device_usb11_host,
2841 #endif
2842 #ifdef CONFIG_USB_ANDROID
2843         &android_usb_device,
2844         &usb_mass_storage_device,
2845 #endif
2846 #ifdef CONFIG_USB_ANDROID_RNDIS
2847     &rk29_device_rndis,
2848 #endif
2849 #ifdef CONFIG_RK29_IPP
2850         &rk29_device_ipp,
2851 #endif
2852 #ifdef CONFIG_VIDEO_RK29XX_VOUT
2853         &rk29_v4l2_output_devce,
2854 #endif
2855 #ifdef CONFIG_RK29_NEWTON
2856         &rk29_device_newton,
2857 #endif
2858 #ifdef CONFIG_RK_IRDA
2859     &irda_device,
2860 #endif
2861 #ifdef CONFIG_LEDS_GPIO_PLATFORM
2862         &rk29_device_gpio_leds,
2863 #endif
2864 #ifdef CONFIG_LEDS_NEWTON_PWM
2865         &rk29_device_pwm_leds,
2866 #endif
2867 #ifdef CONFIG_SND_RK29_SOC_CS42L52
2868         &rk29_cs42l52_device,
2869 #endif
2870 };
2871
2872 /*****************************************************************************************
2873  * spi devices
2874  * author: cmc@rock-chips.com
2875  *****************************************************************************************/
2876 static int rk29_vmac_register_set(void)
2877 {
2878         //config rk29 vmac as rmii, 100MHz
2879         u32 value= readl(RK29_GRF_BASE + 0xbc);
2880         value = (value & 0xfff7ff) | (0x400);
2881         writel(value, RK29_GRF_BASE + 0xbc);
2882         return 0;
2883 }
2884
2885 static int rk29_rmii_io_init(void)
2886 {
2887         int err;
2888
2889         //phy power gpio
2890         err = gpio_request(RK29_PIN6_PB0, "phy_power_en");
2891         if (err) {
2892                 gpio_free(RK29_PIN6_PB0);
2893                 printk("-------request RK29_PIN6_PB0 fail--------\n");
2894                 return -1;
2895         }
2896         //phy power down
2897         gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
2898         gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
2899
2900         return 0;
2901 }
2902
2903 static int rk29_rmii_io_deinit(void)
2904 {
2905         //phy power down
2906         gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
2907         gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
2908         //free
2909         gpio_free(RK29_PIN6_PB0);
2910         return 0;
2911 }
2912
2913 static int rk29_rmii_power_control(int enable)
2914 {
2915         if (enable) {
2916                 //enable phy power
2917                 gpio_direction_output(RK29_PIN6_PB0, GPIO_HIGH);
2918                 gpio_set_value(RK29_PIN6_PB0, GPIO_HIGH);
2919         }
2920         else {
2921                 gpio_direction_output(RK29_PIN6_PB0, GPIO_LOW);
2922                 gpio_set_value(RK29_PIN6_PB0, GPIO_LOW);
2923         }
2924         return 0;
2925 }
2926
2927 struct rk29_vmac_platform_data rk29_vmac_pdata = {
2928         .vmac_register_set = rk29_vmac_register_set,
2929         .rmii_io_init = rk29_rmii_io_init,
2930         .rmii_io_deinit = rk29_rmii_io_deinit,
2931         .rmii_power_control = rk29_rmii_power_control,
2932 };
2933
2934 /*****************************************************************************************
2935  * spi devices
2936  * author: cmc@rock-chips.com
2937  *****************************************************************************************/
2938 #define SPI_CHIPSELECT_NUM 2
2939 static struct spi_cs_gpio rk29xx_spi0_cs_gpios[SPI_CHIPSELECT_NUM] = {
2940     {
2941                 .name = "spi0 cs0",
2942                 .cs_gpio = RK29_PIN2_PC1,
2943                 .cs_iomux_name = GPIO2C1_SPI0CSN0_NAME,
2944                 .cs_iomux_mode = GPIO2H_SPI0_CSN0,
2945         },
2946         {
2947                 .name = "spi0 cs1",
2948                 .cs_gpio = RK29_PIN1_PA4,
2949                 .cs_iomux_name = GPIO1A4_EMMCWRITEPRT_SPI0CS1_NAME,//if no iomux,set it NULL
2950                 .cs_iomux_mode = GPIO1L_SPI0_CSN1,
2951         }
2952 };
2953
2954 static struct spi_cs_gpio rk29xx_spi1_cs_gpios[SPI_CHIPSELECT_NUM] = {
2955     {
2956                 .name = "spi1 cs0",
2957                 .cs_gpio = RK29_PIN2_PC5,
2958                 .cs_iomux_name = GPIO2C5_SPI1CSN0_NAME,
2959                 .cs_iomux_mode = GPIO2H_SPI1_CSN0,
2960         },
2961         {
2962                 .name = "spi1 cs1",
2963                 .cs_gpio = RK29_PIN1_PA3,
2964                 .cs_iomux_name = GPIO1A3_EMMCDETECTN_SPI1CS1_NAME,//if no iomux,set it NULL
2965                 .cs_iomux_mode = GPIO1L_SPI1_CSN1,
2966         }
2967 };
2968
2969 static int spi_io_init(struct spi_cs_gpio *cs_gpios, int cs_num)
2970 {
2971 #if 1
2972         int i;
2973         if (cs_gpios) {
2974                 for (i=0; i<cs_num; i++) {
2975                         rk29_mux_api_set(cs_gpios[i].cs_iomux_name, cs_gpios[i].cs_iomux_mode);
2976                 }
2977         }
2978 #endif
2979         return 0;
2980 }
2981
2982 static int spi_io_deinit(struct spi_cs_gpio *cs_gpios, int cs_num)
2983 {
2984         return 0;
2985 }
2986
2987 static int spi_io_fix_leakage_bug(void)
2988 {
2989 #if 0
2990         gpio_direction_output(RK29_PIN2_PC1, GPIO_LOW);
2991 #endif
2992         return 0;
2993 }
2994
2995 static int spi_io_resume_leakage_bug(void)
2996 {
2997 #if 0
2998         gpio_direction_output(RK29_PIN2_PC1, GPIO_HIGH);
2999 #endif
3000         return 0;
3001 }
3002
3003 struct rk29xx_spi_platform_data rk29xx_spi0_platdata = {
3004         .num_chipselect = SPI_CHIPSELECT_NUM,
3005         .chipselect_gpios = rk29xx_spi0_cs_gpios,
3006         .io_init = spi_io_init,
3007         .io_deinit = spi_io_deinit,
3008         .io_fix_leakage_bug = spi_io_fix_leakage_bug,
3009         .io_resume_leakage_bug = spi_io_resume_leakage_bug,
3010 };
3011
3012 struct rk29xx_spi_platform_data rk29xx_spi1_platdata = {
3013         .num_chipselect = SPI_CHIPSELECT_NUM,
3014         .chipselect_gpios = rk29xx_spi1_cs_gpios,
3015         .io_init = spi_io_init,
3016         .io_deinit = spi_io_deinit,
3017         .io_fix_leakage_bug = spi_io_fix_leakage_bug,
3018         .io_resume_leakage_bug = spi_io_resume_leakage_bug,
3019 };
3020
3021 /*****************************************************************************************
3022  * xpt2046 touch panel
3023  * author: cmc@rock-chips.com
3024  *****************************************************************************************/
3025 #define XPT2046_GPIO_INT           RK29_PIN0_PA3
3026 #define DEBOUNCE_REPTIME  3
3027
3028 #if defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_SPI)
3029 static struct xpt2046_platform_data xpt2046_info = {
3030         .model                  = 2046,
3031         .keep_vref_on   = 1,
3032         .swap_xy                = 0,
3033         .x_min                  = 0,
3034         .x_max                  = 320,
3035         .y_min                  = 0,
3036         .y_max                  = 480,
3037         .debounce_max           = 7,
3038         .debounce_rep           = DEBOUNCE_REPTIME,
3039         .debounce_tol           = 20,
3040         .gpio_pendown           = XPT2046_GPIO_INT,
3041         .penirq_recheck_delay_usecs = 1,
3042 };
3043 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)
3044 static struct xpt2046_platform_data xpt2046_info = {
3045         .model                  = 2046,
3046         .keep_vref_on   = 1,
3047         .swap_xy                = 0,
3048         .x_min                  = 0,
3049         .x_max                  = 320,
3050         .y_min                  = 0,
3051         .y_max                  = 480,
3052         .debounce_max           = 7,
3053         .debounce_rep           = DEBOUNCE_REPTIME,
3054         .debounce_tol           = 20,
3055         .gpio_pendown           = XPT2046_GPIO_INT,
3056         .penirq_recheck_delay_usecs = 1,
3057 };
3058 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_SPI)
3059 static struct xpt2046_platform_data xpt2046_info = {
3060         .model                  = 2046,
3061         .keep_vref_on   = 1,
3062         .swap_xy                = 1,
3063         .x_min                  = 0,
3064         .x_max                  = 800,
3065         .y_min                  = 0,
3066         .y_max                  = 480,
3067         .debounce_max           = 7,
3068         .debounce_rep           = DEBOUNCE_REPTIME,
3069         .debounce_tol           = 20,
3070         .gpio_pendown           = XPT2046_GPIO_INT,
3071
3072         .penirq_recheck_delay_usecs = 1,
3073 };
3074 #elif defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
3075 static struct xpt2046_platform_data xpt2046_info = {
3076         .model                  = 2046,
3077         .keep_vref_on   = 1,
3078         .swap_xy                = 1,
3079         .x_min                  = 0,
3080         .x_max                  = 800,
3081         .y_min                  = 0,
3082         .y_max                  = 480,
3083         .debounce_max           = 7,
3084         .debounce_rep           = DEBOUNCE_REPTIME,
3085         .debounce_tol           = 20,
3086         .gpio_pendown           = XPT2046_GPIO_INT,
3087
3088         .penirq_recheck_delay_usecs = 1,
3089 };
3090 #endif
3091
3092 static struct spi_board_info board_spi_devices[] = {
3093 #if defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_320X480_CBN_SPI)\
3094     ||defined(CONFIG_TOUCHSCREEN_XPT2046_SPI) || defined(CONFIG_TOUCHSCREEN_XPT2046_CBN_SPI)
3095         {
3096                 .modalias       = "xpt2046_ts",
3097                 .chip_select    = 0,
3098                 .max_speed_hz   = 125 * 1000 * 26,/* (max sample rate @ 3V) * (cmd + data + overhead) */
3099                 .bus_num        = 0,
3100                 .irq = XPT2046_GPIO_INT,
3101                 .platform_data = &xpt2046_info,
3102         },
3103 #endif
3104 };
3105
3106
3107 static void __init rk29_gic_init_irq(void)
3108 {
3109 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
3110         gic_init(0, 32, (void __iomem *)RK29_GICPERI_BASE, (void __iomem *)RK29_GICCPU_BASE);
3111 #else
3112         gic_dist_init(0, (void __iomem *)RK29_GICPERI_BASE, 32);
3113         gic_cpu_init(0, (void __iomem *)RK29_GICCPU_BASE);
3114 #endif
3115 }
3116
3117 static void __init machine_rk29_init_irq(void)
3118 {
3119         rk29_gic_init_irq();
3120         rk29_gpio_init();
3121 }
3122
3123 static struct cpufreq_frequency_table freq_table[] = {
3124         { .index = 1200000, .frequency =  408000 },
3125         { .index = 1200000, .frequency =  816000 },
3126         { .index = 1300000, .frequency = 1008000 },
3127         { .frequency = CPUFREQ_TABLE_END },
3128 };
3129
3130 static void __init machine_rk29_board_init(void)
3131 {
3132         rk29_board_iomux_init();
3133
3134         board_power_init();
3135         board_update_cpufreq_table(freq_table);
3136
3137                 platform_add_devices(devices, ARRAY_SIZE(devices));
3138 #ifdef CONFIG_I2C0_RK29
3139         i2c_register_board_info(default_i2c0_data.bus_num, board_i2c0_devices,
3140                         ARRAY_SIZE(board_i2c0_devices));
3141 #endif
3142 #ifdef CONFIG_I2C1_RK29
3143         i2c_register_board_info(default_i2c1_data.bus_num, board_i2c1_devices,
3144                         ARRAY_SIZE(board_i2c1_devices));
3145 #endif
3146 #ifdef CONFIG_I2C2_RK29
3147         i2c_register_board_info(default_i2c2_data.bus_num, board_i2c2_devices,
3148                         ARRAY_SIZE(board_i2c2_devices));
3149 #endif
3150 #ifdef CONFIG_I2C3_RK29
3151         i2c_register_board_info(default_i2c3_data.bus_num, board_i2c3_devices,
3152                         ARRAY_SIZE(board_i2c3_devices));
3153 #endif
3154
3155         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
3156         
3157 #ifdef CONFIG_WIFI_CONTROL_FUNC
3158         rk29sdk_wifi_bt_gpio_control_init();
3159         rk29sdk_init_wifi_mem();
3160 #endif
3161
3162         board_usb_detect_init(RK29_PIN0_PA0);
3163 #if defined(CONFIG_RK_IRDA) || defined(CONFIG_BU92747GUW_CIR)
3164         smc0_init(NULL);
3165         bu92747guw_io_init();
3166 #endif
3167
3168 }
3169
3170 static void __init machine_rk29_fixup(struct machine_desc *desc, struct tag *tags,
3171                                         char **cmdline, struct meminfo *mi)
3172 {
3173         mi->nr_banks = 1;
3174         mi->bank[0].start = RK29_SDRAM_PHYS;
3175         mi->bank[0].size = LINUX_SIZE;
3176 #if SDRAM_SIZE > SZ_512M
3177         mi->nr_banks = 2;
3178         mi->bank[1].start = RK29_SDRAM_PHYS + SZ_512M;
3179         mi->bank[1].size = SDRAM_SIZE - SZ_512M;
3180 #endif
3181 }
3182
3183 static void __init machine_rk29_mapio(void)
3184 {
3185         rk29_map_common_io();
3186         rk29_setup_early_printk();
3187         rk29_sram_init();
3188         rk29_clock_init(periph_pll_default);
3189         rk29_iomux_init();
3190         ddr_init(DDR_TYPE, DDR_FREQ);
3191 }
3192
3193 MACHINE_START(RK29, "RK29board")
3194 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 37))
3195         /* UART for LL DEBUG */
3196         .phys_io        = RK29_UART1_PHYS & 0xfff00000,
3197         .io_pg_offst    = ((RK29_UART1_BASE) >> 18) & 0xfffc,
3198 #endif
3199         .boot_params    = RK29_SDRAM_PHYS + 0x88000,
3200         .fixup          = machine_rk29_fixup,
3201         .map_io         = machine_rk29_mapio,
3202         .init_irq       = machine_rk29_init_irq,
3203         .init_machine   = machine_rk29_board_init,
3204         .timer          = &rk29_timer,
3205 MACHINE_END