Merge branch 'develop-3.0' of ssh://10.10.10.29/rk/kernel into develop-3.0
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk30 / board-rk3066b-m701.c
1 /*
2  *
3  * Copyright (C) 2012 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/ion.h>
27 #include <linux/cpufreq.h>
28 #include <linux/clk.h>
29 #include <mach/dvfs.h>
30
31 #include <asm/setup.h>
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35 #include <asm/mach/flash.h>
36 #include <asm/hardware/gic.h>
37
38 #include <mach/board.h>
39 #include <mach/hardware.h>
40 #include <mach/io.h>
41 #include <mach/gpio.h>
42 #include <mach/iomux.h>
43 #include <linux/fb.h>
44 #include <linux/regulator/machine.h>
45 #include <linux/rfkill-rk.h>
46 #include <linux/sensor-dev.h>
47 #include <linux/mfd/tps65910.h>
48 #include <linux/regulator/rk29-pwm-regulator.h>
49 #if defined(CONFIG_HDMI_RK30)
50         #include "../../../drivers/video/rockchip/hdmi/rk_hdmi.h"
51 #endif
52
53 #if defined(CONFIG_SPIM_RK29)
54 #include "../../../drivers/spi/rk29_spim.h"
55 #endif
56 #if defined(CONFIG_MU509)
57 #include <linux/mu509.h>
58 #endif
59 #if defined(CONFIG_MW100)
60 #include <linux/mw100.h>
61 #endif
62 #if defined(CONFIG_MT6229)
63 #include <linux/mt6229.h>
64 #endif
65 #if defined(CONFIG_SEW868)
66 #include <linux/sew868.h>
67 #endif
68 #if defined(CONFIG_ANDROID_TIMED_GPIO)
69 #include "../../../drivers/staging/android/timed_gpio.h"
70 #endif
71
72 #ifdef  CONFIG_THREE_FB_BUFFER
73 #define RK30_FB0_MEM_SIZE 12*SZ_1M
74 #else
75 #define RK30_FB0_MEM_SIZE 8*SZ_1M
76 #endif
77
78 #include "board-rk3066b-m701-camera.c"
79 #include "board-rk3066b-m701-key.c"
80
81 #if defined(CONFIG_TOUCHSCREEN_GT8XX)
82 #define TOUCH_RESET_PIN  RK30_PIN2_PC0
83 #define TOUCH_PWR_PIN    RK30_PIN2_PB4
84 static int goodix_init_platform_hw(void)
85 {
86         int ret;
87         
88         rk30_mux_api_set(GPIO2C0_LCDC1DATA16_SMCADDR0_TRACECLK_NAME, GPIO2C_GPIO2C0);
89         rk30_mux_api_set(GPIO2B4_LCDC1DATA12_SMCDATA12_TRACEDATA12_NAME, GPIO2B_GPIO2B4);
90         printk("%s:0x%x,0x%x\n",__func__,rk30_mux_api_get(GPIO2C0_LCDC1DATA16_SMCADDR0_TRACECLK_NAME),rk30_mux_api_get(GPIO2B4_LCDC1DATA12_SMCDATA12_TRACEDATA12_NAME));
91
92         if (TOUCH_PWR_PIN != INVALID_GPIO) {
93                 ret = gpio_request(TOUCH_PWR_PIN, "goodix power pin");
94                 if (ret != 0) {
95                         gpio_free(TOUCH_PWR_PIN);
96                         printk("goodix power error\n");
97                         return -EIO;
98                 }
99                 gpio_direction_output(TOUCH_PWR_PIN, 0);
100                 gpio_set_value(TOUCH_PWR_PIN, GPIO_LOW);
101                 msleep(100);
102         }
103
104         if (TOUCH_RESET_PIN != INVALID_GPIO) {
105                 ret = gpio_request(TOUCH_RESET_PIN, "goodix reset pin");
106                 if (ret != 0) {
107                         gpio_free(TOUCH_RESET_PIN);
108                         printk("goodix gpio_request error\n");
109                         return -EIO;
110                 }
111                 gpio_direction_output(TOUCH_RESET_PIN, 1);
112                 msleep(100);
113                 //gpio_set_value(TOUCH_RESET_PIN, GPIO_LOW);
114                 //msleep(100);
115                 //gpio_set_value(TOUCH_RESET_PIN, GPIO_HIGH);
116                 //msleep(500);
117         }
118         return 0;
119 }
120
121 struct goodix_platform_data goodix_info = {
122         .model = 8105,
123         .irq_pin = RK30_PIN0_PD4,
124         .rest_pin = TOUCH_RESET_PIN,
125         .init_platform_hw = goodix_init_platform_hw,
126 };
127 #endif
128
129 #if defined (CONFIG_TOUCHSCREEN_FT5306_AV)
130
131 #define TOUCH_RESET_PIN  RK30_PIN2_PC0
132 #define TOUCH_INT_PIN    RK30_PIN0_PD4
133 #define TOUCH_PWR_PIN    RK30_PIN2_PB4
134
135 static int ft5306_init_platform_hw(void)
136 {
137
138         rk30_mux_api_set(GPIO2C0_LCDC1DATA16_SMCADDR0_TRACECLK_NAME, GPIO2C_GPIO2C0);
139         rk30_mux_api_set(GPIO0D4_SPI1RXD_NAME, GPIO0D_GPIO0D4);
140         rk30_mux_api_set(GPIO2B4_LCDC1DATA12_SMCDATA12_TRACEDATA12_NAME, GPIO2B_GPIO2B4);
141        //printk("%s:0x%x,0x%x\n",__func__,rk30_mux_api_get(GPIO2C0_LCDC1DATA16_SMCADDR0_TRACECLK_NAME),rk30_mux_api_get(GPIO2B4_LCDC1DATA12_SMCDATA12_TRACEDATA12_NAME));
142
143         printk("ft5306_init_platform_hw \n");
144         if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
145           gpio_free(TOUCH_RESET_PIN);
146           printk("ft5306_init_platform_hw gpio_request error\n");
147           return -EIO;
148         }
149
150         if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
151           gpio_free(TOUCH_INT_PIN);
152           printk("ift5306_init_platform_hw gpio_request error\n");
153           return -EIO;
154         }
155
156         gpio_direction_output(TOUCH_RESET_PIN, 0);
157         gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
158         mdelay(50);
159         gpio_direction_input(TOUCH_INT_PIN);
160         mdelay(10);
161         gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
162         msleep(300);
163         return 0;
164 }
165
166 void ft5306_exit_platform_hw(void)
167 {
168         printk("ft5606_exit_platform_hw\n");
169         gpio_free(TOUCH_RESET_PIN);
170         gpio_free(TOUCH_INT_PIN);
171 }
172
173 int ft5306_platform_sleep(void)
174 {
175         printk("ft5606_platform_sleep\n");
176         gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
177         return 0;
178 }
179
180 int ft5306_platform_wakeup(void)
181 {
182         printk("ft5606_platform_wakeup\n");
183         gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
184         mdelay(20);
185         gpio_direction_output(TOUCH_RESET_PIN,GPIO_LOW);
186         mdelay(300);
187         gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
188         mdelay(200);
189         return 0;
190 }
191
192 struct ft5606_platform_data ft5306_info = {
193
194   .init_platform_hw= ft5306_init_platform_hw,
195   .exit_platform_hw= ft5306_exit_platform_hw,
196   .platform_sleep= ft5306_platform_sleep,
197   .platform_wakeup= ft5306_platform_wakeup,
198 };
199 #endif
200
201
202 static struct spi_board_info board_spi_devices[] = {
203 };
204
205 /***********************************************************
206 *       rk30  backlight
207 ************************************************************/
208 #ifdef CONFIG_BACKLIGHT_RK29_BL
209 #define PWM_ID            2
210 #define PWM_MUX_NAME      GPIO3D5_PWM2_JTAGTCK_OTGDRVVBUS_NAME
211 #define PWM_MUX_MODE      GPIO3D_PWM2
212 #define PWM_MUX_MODE_GPIO GPIO3D_GPIO3D5
213 #define PWM_GPIO          RK30_PIN3_PD5
214 #define PWM_EFFECT_VALUE  0
215
216 #define LCD_DISP_ON_PIN
217
218 #ifdef  LCD_DISP_ON_PIN
219 #define BL_EN_PIN         RK30_PIN0_PA2
220 #define BL_EN_VALUE       GPIO_HIGH
221 #endif
222 static int rk29_backlight_io_init(void)
223 {
224         int ret = 0;
225         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
226 #ifdef  LCD_DISP_ON_PIN
227         // rk30_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
228
229         ret = gpio_request(BL_EN_PIN, NULL);
230         if (ret != 0) {
231                 gpio_free(BL_EN_PIN);
232         }
233
234         gpio_direction_output(BL_EN_PIN, 0);
235         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
236 #endif
237         return ret;
238 }
239
240 static int rk29_backlight_io_deinit(void)
241 {
242         int ret = 0;
243 #ifdef  LCD_DISP_ON_PIN
244         gpio_free(BL_EN_PIN);
245 #endif
246         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
247         return ret;
248 }
249
250 static int rk29_backlight_pwm_suspend(void)
251 {
252         int ret = 0;
253         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
254         if (gpio_request(PWM_GPIO, NULL)) {
255                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
256                 return -1;
257         }
258         gpio_direction_output(PWM_GPIO, GPIO_LOW);
259 #ifdef  LCD_DISP_ON_PIN
260         gpio_direction_output(BL_EN_PIN, 0);
261         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
262 #endif
263         return ret;
264 }
265
266 static int rk29_backlight_pwm_resume(void)
267 {
268         gpio_free(PWM_GPIO);
269         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
270 #ifdef  LCD_DISP_ON_PIN
271         msleep(30);
272         gpio_direction_output(BL_EN_PIN, 1);
273         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
274 #endif
275         return 0;
276 }
277
278 static struct rk29_bl_info rk29_bl_info = {
279         .pwm_id = PWM_ID,
280         .bl_ref = PWM_EFFECT_VALUE,
281         .io_init = rk29_backlight_io_init,
282         .io_deinit = rk29_backlight_io_deinit,
283         .pwm_suspend = rk29_backlight_pwm_suspend,
284         .pwm_resume = rk29_backlight_pwm_resume,
285 };
286
287 static struct platform_device rk29_device_backlight = {
288         .name   = "rk29_backlight",
289         .id     = -1,
290         .dev    = {
291                 .platform_data  = &rk29_bl_info,
292         }
293 };
294
295 #endif
296
297 #ifdef CONFIG_RK29_SUPPORT_MODEM
298
299 #define RK30_MODEM_POWER        RK30_PIN2_PB0
300 #define RK30_MODEM_POWER_IOMUX  rk29_mux_api_set(GPIO2B0_LCDC1DATA8_SMCDATA8_TRACEDATA8_NAME, GPIO2B_GPIO2B0)
301
302 static int rk30_modem_io_init(void)
303 {
304     printk("%s\n", __FUNCTION__);
305     RK30_MODEM_POWER_IOMUX;
306
307         return 0;
308 }
309
310 static struct rk29_io_t rk30_modem_io = {
311     .io_addr    = RK30_MODEM_POWER,
312     .enable     = GPIO_HIGH,
313     .disable    = GPIO_LOW,
314     .io_init    = rk30_modem_io_init,
315 };
316
317 static struct platform_device rk30_device_modem = {
318         .name   = "rk30_modem",
319         .id     = -1,
320         .dev    = {
321                 .platform_data  = &rk30_modem_io,
322         }
323 };
324 #endif
325 #if defined(CONFIG_MU509)
326 static int mu509_io_init(void)
327 {
328
329         rk30_mux_api_set(GPIO2B0_LCDC1DATA8_SMCDATA8_TRACEDATA8_NAME, GPIO2B_GPIO2B0);
330        rk30_mux_api_set(GPIO2D1_LCDC1DEN_SMCWEN_NAME, GPIO2D_GPIO2D1);
331         rk30_mux_api_set(GPIO2B7_LCDC1DATA15_SMCADDR19_HSADCDATA7_NAME, GPIO2B_GPIO2B7);
332         rk30_mux_api_set(GPIO2C0_LCDCDATA16_GPSCLK_HSADCCLKOUT_NAME, GPIO2C_GPIO2C0);
333         return 0;
334 }
335
336 static int mu509_io_deinit(void)
337 {
338         
339         return 0;
340 }
341  
342 struct rk29_mu509_data rk29_mu509_info = {
343         .io_init = mu509_io_init,
344         .io_deinit = mu509_io_deinit,
345         .modem_power_en = RK30_PIN2_PB0,
346         .bp_power = RK30_PIN2_PB0,
347         .bp_reset = RK30_PIN2_PD1,
348         .ap_wakeup_bp = RK30_PIN2_PB7,
349         .bp_wakeup_ap = RK30_PIN6_PA0, 
350 };
351 struct platform_device rk29_device_mu509 = {    
352         .name = "mu509",        
353         .id = -1,       
354         .dev            = {
355                 .platform_data = &rk29_mu509_info,
356         }       
357     };
358 #endif
359 #if defined(CONFIG_MW100)
360 static int mw100_io_init(void)
361 {
362          rk30_mux_api_set(GPIO2B0_LCDC1DATA8_SMCDATA8_TRACEDATA8_NAME, GPIO2B_GPIO2B0);
363          rk30_mux_api_set(GPIO2D1_LCDC1DEN_SMCWEN_NAME, GPIO2D_GPIO2D1);
364          rk30_mux_api_set(GPIO2B7_LCDC1DATA15_SMCADDR19_HSADCDATA7_NAME, GPIO2B_GPIO2B7);
365          rk30_mux_api_set(GPIO2C0_LCDCDATA16_GPSCLK_HSADCCLKOUT_NAME, GPIO2C_GPIO2C0);
366         return 0;
367 }
368
369 static int mw100_io_deinit(void)
370 {
371         
372         return 0;
373 }
374  
375 struct rk29_mw100_data rk29_mw100_info = {
376         .io_init = mw100_io_init,
377         .io_deinit = mw100_io_deinit,
378         .modem_power_en = RK30_PIN6_PB0,
379         .bp_power = RK30_PIN2_PB0,
380         .bp_reset = RK30_PIN2_PD1,
381         .ap_wakeup_bp = RK30_PIN2_PB7,
382         .bp_wakeup_ap = RK30_PIN6_PA0,
383 };
384 struct platform_device rk29_device_mw100 = {    
385         .name = "mw100",        
386         .id = -1,       
387         .dev            = {
388                 .platform_data = &rk29_mw100_info,
389         }       
390     };
391 #endif
392 #if defined(CONFIG_MT6229)
393 static int mt6229_io_init(void)
394 {
395          rk30_mux_api_set(GPIO2B0_LCDC1DATA8_SMCDATA8_TRACEDATA8_NAME, GPIO2B_GPIO2B0);
396          rk30_mux_api_set(GPIO2D1_LCDC1DEN_SMCWEN_NAME, GPIO2D_GPIO2D1);
397          rk30_mux_api_set(GPIO2B7_LCDC1DATA15_SMCADDR19_HSADCDATA7_NAME, GPIO2B_GPIO2B7);
398          rk30_mux_api_set(GPIO2C0_LCDCDATA16_GPSCLK_HSADCCLKOUT_NAME, GPIO2C_GPIO2C0);
399         return 0;
400 }
401
402 static int mt6229_io_deinit(void)
403 {
404         
405         return 0;
406 }
407  
408 struct rk29_mt6229_data rk29_mt6229_info = {
409         .io_init = mt6229_io_init,
410         .io_deinit = mt6229_io_deinit,
411         .modem_power_en = RK30_PIN2_PB0,
412         .bp_power = RK30_PIN2_PB0,//RK30_PIN2_PB6,
413         .bp_reset = RK30_PIN2_PD1,
414         .ap_wakeup_bp = RK30_PIN2_PC0,
415         .bp_wakeup_ap = RK30_PIN6_PA0,
416 };
417 struct platform_device rk29_device_mt6229 = {   
418         .name = "mt6229",       
419         .id = -1,       
420         .dev            = {
421                 .platform_data = &rk29_mt6229_info,
422         }       
423     };
424 #endif
425 #if defined(CONFIG_SEW868)
426 static int sew868_io_init(void)
427 {
428         rk30_mux_api_set(GPIO2B6_LCDC1DATA14_SMCADDR18_TSSYNC_NAME, GPIO2B_GPIO2B6);
429     rk30_mux_api_set(GPIO4D2_SMCDATA10_TRACEDATA10_NAME, GPIO4D_GPIO4D2);
430         rk30_mux_api_set(GPIO4D4_SMCDATA12_TRACEDATA12_NAME, GPIO4D_GPIO4D4);
431         return 0;
432 }
433 static int sew868_io_deinit(void)
434 {
435         return 0;
436 }
437 struct rk30_sew868_data rk30_sew868_info = {
438         .io_init = sew868_io_init,
439         .io_deinit = sew868_io_deinit,
440         .bp_power = RK30_PIN6_PB2, 
441         .bp_power_active_low = 1,
442         .bp_sys = RK30_PIN2_PB6, 
443         .bp_reset = RK30_PIN4_PD2, 
444         .bp_reset_active_low = 1,
445         .bp_wakeup_ap = RK30_PIN4_PD4, 
446         .ap_wakeup_bp = NULL,
447 };
448
449 struct platform_device rk30_device_sew868 = {   
450         .name = "sew868",       
451         .id = -1,       
452         .dev            = {
453                 .platform_data = &rk30_sew868_info,
454         }       
455     };
456 #endif
457
458
459 /*MMA7660 gsensor*/
460 #if defined (CONFIG_GS_MMA7660)
461 #define MMA7660_INT_PIN   RK30_PIN3_PD7
462
463 static int mma7660_init_platform_hw(void)
464 {
465       if(gpio_request(MMA7660_INT_PIN, NULL) != 0){
466       gpio_free(MMA7660_INT_PIN);
467       printk("gsensor gpio_request error\n");
468       return -EIO;
469     }
470       //gpio_direction_input(MMA7660_INT_PIN);
471       return 0;
472 }
473
474 static struct sensor_platform_data mma7660_info = {
475         .type = SENSOR_TYPE_ACCEL,
476         .irq_enable = 1,
477         .poll_delay_ms = 30,
478         .init_platform_hw = mma7660_init_platform_hw,
479         .orientation = {0, 1, 0, 0, 0, -1, 1, 0, 0},
480 };
481 #endif
482
483
484 /*MMA8452 gsensor*/
485 #if defined (CONFIG_GS_MMA8452)
486 #define MMA8452_INT_PIN   RK30_PIN3_PD7
487
488 static int mma8452_init_platform_hw(void)
489 {
490         return 0;
491 }
492
493 static struct sensor_platform_data mma8452_info = {
494         .type = SENSOR_TYPE_ACCEL,
495         .irq_enable = 1,
496         .poll_delay_ms = 30,
497         .init_platform_hw = mma8452_init_platform_hw,
498         .orientation = {-1, 0, 0, 0, 0, 1, 0, -1, 0},
499 };
500 #endif
501 #if defined (CONFIG_GS_LIS3DH)
502 #define LIS3DH_INT_PIN   RK30_PIN3_PD7
503
504 static int lis3dh_init_platform_hw(void)
505 {
506
507         return 0;
508 }
509
510 static struct sensor_platform_data lis3dh_info = {
511         .type = SENSOR_TYPE_ACCEL,
512         .irq_enable = 1,
513         .poll_delay_ms = 30,
514         .init_platform_hw = lis3dh_init_platform_hw,
515         .orientation = {-1, 0, 0, 0, 0, 1, 0, -1, 0},
516 };
517 #endif
518 #if defined (CONFIG_COMPASS_AK8975)
519 static struct sensor_platform_data akm8975_info =
520 {
521         .type = SENSOR_TYPE_COMPASS,
522         .irq_enable = 1,
523         .poll_delay_ms = 30,
524         .m_layout = 
525         {
526                 {
527                         {1, 0, 0},
528                         {0, 1, 0},
529                         {0, 0, 1},
530                 },
531
532                 {
533                         {1, 0, 0},
534                         {0, 1, 0},
535                         {0, 0, 1},
536                 },
537
538                 {
539                         {1, 0, 0},
540                         {0, 1, 0},
541                         {0, 0, 1},
542                 },
543
544                 {
545                         {1, 0, 0},
546                         {0, 1, 0},
547                         {0, 0, 1},
548                 },
549         }
550 };
551
552 #endif
553
554 #if defined(CONFIG_GYRO_L3G4200D)
555
556 #include <linux/l3g4200d.h>
557 #define L3G4200D_INT_PIN  RK30_PIN0_PB4
558
559 static int l3g4200d_init_platform_hw(void)
560 {
561         return 0;
562 }
563
564 static struct sensor_platform_data l3g4200d_info = {
565         .type = SENSOR_TYPE_GYROSCOPE,
566         .irq_enable = 1,
567         .poll_delay_ms = 30,
568         .orientation = {0, 1, 0, -1, 0, 0, 0, 0, 1},
569         .init_platform_hw = l3g4200d_init_platform_hw,
570         .x_min = 40,//x_min,y_min,z_min = (0-100) according to hardware
571         .y_min = 40,
572         .z_min = 20,
573 };
574
575 #endif
576
577 #ifdef CONFIG_LS_CM3217
578 static struct sensor_platform_data cm3217_info = {
579         .type = SENSOR_TYPE_LIGHT,
580         .irq_enable = 0,
581         .poll_delay_ms = 500,
582 };
583
584 #endif
585
586 #ifdef CONFIG_FB_ROCKCHIP
587
588 #define LCD_CS_PIN         RK30_PIN2_PB6
589 #define LCD_CS_VALUE       GPIO_HIGH
590
591 #define LCD_EN_PIN         RK30_PIN0_PB0
592 #define LCD_EN_VALUE       GPIO_LOW
593
594 #define LCD_STB_PIN        RK30_PIN2_PB3
595 #define LCD_STB_VALUE      GPIO_HIGH
596
597 static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
598 {
599         int ret = 0;
600
601         if(LCD_CS_PIN !=INVALID_GPIO)
602         {
603                 ret = gpio_request(LCD_CS_PIN, NULL);
604                 if (ret != 0)
605                 {
606                         gpio_free(LCD_CS_PIN);
607                         printk(KERN_ERR "request lcd cs pin fail!\n");
608                         return -1;
609                 }
610                 else
611                 {
612                         gpio_direction_output(LCD_CS_PIN, LCD_CS_VALUE);
613                 }
614         }
615
616         if(LCD_EN_PIN !=INVALID_GPIO)
617         {
618                 ret = gpio_request(LCD_EN_PIN, NULL);
619                 if (ret != 0)
620                 {
621                         gpio_free(LCD_EN_PIN);
622                         printk(KERN_ERR "request lcd en pin fail!\n");
623                         return -1;
624                 }
625                 else
626                 {
627                         gpio_direction_output(LCD_EN_PIN, LCD_EN_VALUE);
628                 }
629         }
630
631         if(LCD_STB_PIN !=INVALID_GPIO)
632         {
633                 ret = gpio_request(LCD_STB_PIN, NULL);
634                 if (ret != 0)
635                 {
636                         gpio_free(LCD_STB_PIN);
637                         printk(KERN_ERR "request lcd en pin fail!\n");
638                         return -1;
639                 }
640                 else
641                 {
642                         gpio_direction_output(LCD_STB_PIN, LCD_STB_VALUE);
643                 }
644         }
645
646         return 0;
647 }
648 static int rk_fb_io_disable(void)
649 {
650         if(LCD_CS_PIN !=INVALID_GPIO)
651         {
652                 gpio_set_value(LCD_CS_PIN, !LCD_CS_VALUE);
653         }
654         if(LCD_EN_PIN !=INVALID_GPIO)
655         {
656                 gpio_set_value(LCD_EN_PIN, !LCD_EN_VALUE);
657         }
658         return 0;
659 }
660 static int rk_fb_io_enable(void)
661 {
662         if(LCD_CS_PIN !=INVALID_GPIO)
663         {
664                 gpio_set_value(LCD_CS_PIN, LCD_CS_VALUE);
665         }
666         if(LCD_EN_PIN !=INVALID_GPIO)
667         {
668                 gpio_set_value(LCD_EN_PIN, LCD_EN_VALUE);
669         }
670         return 0;
671 }
672
673 #if defined(CONFIG_LCDC0_RK3066B)
674 struct rk29fb_info lcdc0_screen_info = {
675         .prop      = PRMRY,             //primary display device
676         .io_init   = rk_fb_io_init,
677         .io_disable = rk_fb_io_disable,
678         .io_enable = rk_fb_io_enable,
679         .set_screen_info = set_lcd_info,
680 };
681 #endif
682
683 #if defined(CONFIG_LCDC1_RK3066B)
684 struct rk29fb_info lcdc1_screen_info = {
685         #if defined(CONFIG_HDMI_RK30)
686         .prop           = EXTEND,       //extend display device
687         .lcd_info  = NULL,
688         .set_screen_info = hdmi_init_lcdc,
689         #endif
690 };
691 #endif
692
693 static struct resource resource_fb[] = {
694         [0] = {
695                 .name  = "fb0 buf",
696                 .start = 0,
697                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
698                 .flags = IORESOURCE_MEM,
699         },
700         [1] = {
701                 .name  = "ipp buf",  //for rotate
702                 .start = 0,
703                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
704                 .flags = IORESOURCE_MEM,
705         },
706         [2] = {
707                 .name  = "fb2 buf",
708                 .start = 0,
709                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
710                 .flags = IORESOURCE_MEM,
711         },
712 };
713
714 static struct platform_device device_fb = {
715         .name           = "rk-fb",
716         .id             = -1,
717         .num_resources  = ARRAY_SIZE(resource_fb),
718         .resource       = resource_fb,
719 };
720 #endif
721
722 #if defined(CONFIG_LCDC0_RK3066B)
723 static struct resource resource_lcdc0[] = {
724         [0] = {
725                 .name  = "lcdc0 reg",
726                 .start = RK30_LCDC0_PHYS,
727                 .end   = RK30_LCDC0_PHYS + RK30_LCDC0_SIZE - 1,
728                 .flags = IORESOURCE_MEM,
729         },
730         
731         [1] = {
732                 .name  = "lcdc0 irq",
733                 .start = IRQ_LCDC0,
734                 .end   = IRQ_LCDC0,
735                 .flags = IORESOURCE_IRQ,
736         },
737 };
738
739 static struct platform_device device_lcdc0 = {
740         .name             = "rk30-lcdc",
741         .id               = 0,
742         .num_resources    = ARRAY_SIZE(resource_lcdc0),
743         .resource         = resource_lcdc0,
744         .dev            = {
745                 .platform_data = &lcdc0_screen_info,
746         },
747 };
748 #endif
749 #if defined(CONFIG_LCDC1_RK3066B) 
750 static struct resource resource_lcdc1[] = {
751         [0] = {
752                 .name  = "lcdc1 reg",
753                 .start = RK30_LCDC1_PHYS,
754                 .end   = RK30_LCDC1_PHYS + RK30_LCDC1_SIZE - 1,
755                 .flags = IORESOURCE_MEM,
756         },
757         [1] = {
758                 .name  = "lcdc1 irq",
759                 .start = IRQ_LCDC1,
760                 .end   = IRQ_LCDC1,
761                 .flags = IORESOURCE_IRQ,
762         },
763 };
764
765 static struct platform_device device_lcdc1 = {
766         .name             = "rk30-lcdc",
767         .id               = 1,
768         .num_resources    = ARRAY_SIZE(resource_lcdc1),
769         .resource         = resource_lcdc1,
770         .dev            = {
771                 .platform_data = &lcdc1_screen_info,
772         },
773 };
774 #endif
775
776 #ifdef CONFIG_ANDROID_TIMED_GPIO
777 static struct timed_gpio timed_gpios[] = {
778         {
779                 .name = "vibrator",
780                 .gpio = RK30_PIN3_PD3,
781                 .max_timeout = 1000,
782                 .active_low = 0,
783                 .adjust_time =20,      //adjust for diff product
784         },
785 };
786
787 static struct timed_gpio_platform_data rk29_vibrator_info = {
788         .num_gpios = 1,
789         .gpios = timed_gpios,
790 };
791
792 static struct platform_device rk29_device_vibrator = {
793         .name = "timed-gpio",
794         .id = -1,
795         .dev = {
796                 .platform_data = &rk29_vibrator_info,
797         },
798
799 };
800 #endif
801
802 #ifdef CONFIG_LEDS_GPIO_PLATFORM
803 static struct gpio_led rk29_leds[] = {
804         {
805                 .name = "button-backlight",
806                 .gpio = RK30_PIN2_PB3,
807                 .default_trigger = "timer",
808                 .active_low = 0,
809                 .retain_state_suspended = 0,
810                 .default_state = LEDS_GPIO_DEFSTATE_OFF,
811         },
812 };
813
814 static struct gpio_led_platform_data rk29_leds_pdata = {
815         .leds = rk29_leds,
816         .num_leds = ARRAY_SIZE(rk29_leds),
817 };
818
819 static struct platform_device rk29_device_gpio_leds = {
820         .name   = "leds-gpio",
821         .id     = -1,
822         .dev    = {
823                 .platform_data  = &rk29_leds_pdata,
824         },
825 };
826 #endif
827
828 #ifdef CONFIG_RK_IRDA
829 #define IRDA_IRQ_PIN           RK30_PIN0_PA3
830
831 static int irda_iomux_init(void)
832 {
833         int ret = 0;
834
835         //irda irq pin
836         ret = gpio_request(IRDA_IRQ_PIN, NULL);
837         if (ret != 0) {
838                 gpio_free(IRDA_IRQ_PIN);
839                 printk(">>>>>> IRDA_IRQ_PIN gpio_request err \n ");
840         }
841         gpio_pull_updown(IRDA_IRQ_PIN, PullDisable);
842         gpio_direction_input(IRDA_IRQ_PIN);
843
844         return 0;
845 }
846
847 static int irda_iomux_deinit(void)
848 {
849         gpio_free(IRDA_IRQ_PIN);
850         return 0;
851 }
852
853 static struct irda_info rk29_irda_info = {
854         .intr_pin = IRDA_IRQ_PIN,
855         .iomux_init = irda_iomux_init,
856         .iomux_deinit = irda_iomux_deinit,
857         //.irda_pwr_ctl = bu92747guw_power_ctl,
858 };
859
860 static struct platform_device irda_device = {
861 #ifdef CONFIG_RK_IRDA_NET
862         .name = "rk_irda",
863 #else
864         .name = "bu92747_irda",
865 #endif
866         .id = -1,
867         .dev = {
868                 .platform_data = &rk29_irda_info,
869         }
870 };
871 #endif
872
873 #ifdef CONFIG_ION
874 #define ION_RESERVE_SIZE        (80 * SZ_1M)
875 static struct ion_platform_data rk30_ion_pdata = {
876         .nr = 1,
877         .heaps = {
878                 {
879                         .type = ION_HEAP_TYPE_CARVEOUT,
880                         .id = ION_NOR_HEAP_ID,
881                         .name = "norheap",
882                         .size = ION_RESERVE_SIZE,
883                 }
884         },
885 };
886
887 static struct platform_device device_ion = {
888         .name = "ion-rockchip",
889         .id = 0,
890         .dev = {
891                 .platform_data = &rk30_ion_pdata,
892         },
893 };
894 #endif
895
896 /**************************************************************************************************
897  * SDMMC devices,  include the module of SD,MMC,and sdio.noted by xbw at 2012-03-05
898 **************************************************************************************************/
899 #ifdef CONFIG_SDMMC_RK29
900 #include "board-rk3066b-sdk-sdmmc.c"
901
902 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
903 #define SDMMC0_WRITE_PROTECT_PIN        RK30_PIN3_PB7   //According to your own project to set the value of write-protect-pin.
904 #endif
905
906 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
907 #define SDMMC1_WRITE_PROTECT_PIN        RK30_PIN3_PC7   //According to your own project to set the value of write-protect-pin.
908 #endif
909
910 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N    RK30_PIN6_PB2
911
912 #endif //endif ---#ifdef CONFIG_SDMMC_RK29
913
914 #ifdef CONFIG_SDMMC0_RK29
915 static int rk29_sdmmc0_cfg_gpio(void)
916 {
917 #ifdef CONFIG_SDMMC_RK29_OLD
918         rk30_mux_api_set(GPIO3B1_SDMMC0CMD_NAME, GPIO3B_SDMMC0_CMD);
919         rk30_mux_api_set(GPIO3B0_SDMMC0CLKOUT_NAME, GPIO3B_SDMMC0_CLKOUT);
920         rk30_mux_api_set(GPIO3B2_SDMMC0DATA0_NAME, GPIO3B_SDMMC0_DATA0);
921         rk30_mux_api_set(GPIO3B3_SDMMC0DATA1_NAME, GPIO3B_SDMMC0_DATA1);
922         rk30_mux_api_set(GPIO3B4_SDMMC0DATA2_NAME, GPIO3B_SDMMC0_DATA2);
923         rk30_mux_api_set(GPIO3B5_SDMMC0DATA3_NAME, GPIO3B_SDMMC0_DATA3);
924
925         rk30_mux_api_set(GPIO3B6_SDMMC0DETECTN_NAME, GPIO3B_GPIO3B6);
926
927         rk30_mux_api_set(GPIO3A7_SDMMC0PWREN_NAME, GPIO3A_GPIO3A7);
928         gpio_request(RK30_PIN3_PA7, "sdmmc-power");
929         gpio_direction_output(RK30_PIN3_PA7, GPIO_LOW);
930
931 #else
932         rk29_sdmmc_set_iomux(0, 0xFFFF);
933
934         rk30_mux_api_set(GPIO3B0_SDMMC0DETECTN_NAME, GPIO3B_SDMMC0DETECTN);
935
936 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
937         gpio_request(SDMMC0_WRITE_PROTECT_PIN, "sdmmc-wp");
938         gpio_direction_input(SDMMC0_WRITE_PROTECT_PIN);
939 #endif
940
941 #endif
942
943         return 0;
944 }
945
946 #define CONFIG_SDMMC0_USE_DMA
947 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
948         .host_ocr_avail =
949             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
950              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
951              MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36),
952         .host_caps =
953             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
954         .io_init = rk29_sdmmc0_cfg_gpio,
955
956 #if !defined(CONFIG_SDMMC_RK29_OLD)
957         .set_iomux = rk29_sdmmc_set_iomux,
958 #endif
959
960         .dma_name = "sd_mmc",
961 #ifdef CONFIG_SDMMC0_USE_DMA
962         .use_dma = 1,
963 #else
964         .use_dma = 0,
965 #endif
966         .detect_irq = RK30_PIN3_PB6,    // INVALID_GPIO
967         .enable_sd_wakeup = 0,
968
969 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
970         .write_prt = SDMMC0_WRITE_PROTECT_PIN,
971 #else
972         .write_prt = INVALID_GPIO,
973 #endif
974 };
975 #endif // CONFIG_SDMMC0_RK29
976
977 #ifdef CONFIG_SDMMC1_RK29
978 #define CONFIG_SDMMC1_USE_DMA
979 static int rk29_sdmmc1_cfg_gpio(void)
980 {
981 #if defined(CONFIG_SDMMC_RK29_OLD)
982         rk30_mux_api_set(GPIO3C0_SMMC1CMD_NAME, GPIO3C_SMMC1_CMD);
983         rk30_mux_api_set(GPIO3C5_SDMMC1CLKOUT_NAME, GPIO3C_SDMMC1_CLKOUT);
984         rk30_mux_api_set(GPIO3C1_SDMMC1DATA0_NAME, GPIO3C_SDMMC1_DATA0);
985         rk30_mux_api_set(GPIO3C2_SDMMC1DATA1_NAME, GPIO3C_SDMMC1_DATA1);
986         rk30_mux_api_set(GPIO3C3_SDMMC1DATA2_NAME, GPIO3C_SDMMC1_DATA2);
987         rk30_mux_api_set(GPIO3C4_SDMMC1DATA3_NAME, GPIO3C_SDMMC1_DATA3);
988         //rk30_mux_api_set(GPIO3C6_SDMMC1DETECTN_NAME, GPIO3C_SDMMC1_DETECT_N);
989
990 #else
991
992 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
993         gpio_request(SDMMC1_WRITE_PROTECT_PIN, "sdio-wp");
994         gpio_direction_input(SDMMC1_WRITE_PROTECT_PIN);
995 #endif
996
997 #endif
998
999         return 0;
1000 }
1001
1002 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
1003         .host_ocr_avail =
1004             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
1005              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
1006              MMC_VDD_33_34),
1007
1008 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
1009         .host_caps = (MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ |
1010                       MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
1011 #else
1012         .host_caps =
1013             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
1014 #endif
1015
1016         .io_init = rk29_sdmmc1_cfg_gpio,
1017
1018 #if !defined(CONFIG_SDMMC_RK29_OLD)
1019         .set_iomux = rk29_sdmmc_set_iomux,
1020 #endif
1021
1022         .dma_name = "sdio",
1023 #ifdef CONFIG_SDMMC1_USE_DMA
1024         .use_dma = 1,
1025 #else
1026         .use_dma = 0,
1027 #endif
1028
1029 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
1030 #ifdef CONFIG_WIFI_CONTROL_FUNC
1031         .status = rk29sdk_wifi_status,
1032         .register_status_notify = rk29sdk_wifi_status_register,
1033 #endif
1034 #if 0
1035         .detect_irq = RK29SDK_WIFI_SDIO_CARD_DETECT_N,
1036 #endif
1037
1038 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
1039         .write_prt = SDMMC1_WRITE_PROTECT_PIN,
1040 #else
1041         .write_prt = INVALID_GPIO,
1042 #endif
1043
1044 #else
1045         .detect_irq = INVALID_GPIO,
1046         .enable_sd_wakeup = 0,
1047 #endif
1048
1049 };
1050 #endif //endif--#ifdef CONFIG_SDMMC1_RK29
1051
1052 /**************************************************************************************************
1053  * the end of setting for SDMMC devices
1054 **************************************************************************************************/
1055
1056 #ifdef CONFIG_BATTERY_RK30_ADC
1057 static struct rk30_adc_battery_platform_data rk30_adc_battery_platdata = {
1058         .dc_det_pin      = RK30_PIN0_PB2,
1059         .batt_low_pin    = RK30_PIN0_PB1, 
1060         .charge_set_pin  = INVALID_GPIO,
1061         .charge_ok_pin   = RK30_PIN0_PA6,
1062         .dc_det_level    = GPIO_LOW,
1063         .charge_ok_level = GPIO_HIGH,
1064 };
1065
1066 static struct platform_device rk30_device_adc_battery = {
1067         .name   = "rk30-battery",
1068         .id     = -1,
1069         .dev = {
1070                 .platform_data = &rk30_adc_battery_platdata,
1071         },
1072 };
1073 #endif
1074 #ifdef CONFIG_RK30_PWM_REGULATOR
1075 const static int pwm_voltage_map[] = {
1076         1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000, 1375000, 1400000
1077 };
1078
1079 static struct regulator_consumer_supply pwm_dcdc1_consumers[] = {
1080         {
1081                 .supply = "vdd_core",
1082         }
1083 };
1084
1085 struct regulator_init_data pwm_regulator_init_dcdc[1] =
1086 {
1087         {
1088                 .constraints = {
1089                         .name = "PWM_DCDC1",
1090                         .min_uV = 600000,
1091                         .max_uV = 1800000,      //0.6-1.8V
1092                         .apply_uV = true,
1093                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
1094                 },
1095                 .num_consumer_supplies = ARRAY_SIZE(pwm_dcdc1_consumers),
1096                 .consumer_supplies = pwm_dcdc1_consumers,
1097         },
1098 };
1099
1100 static struct pwm_platform_data pwm_regulator_info[1] = {
1101         {
1102                 .pwm_id = 3,
1103                 .pwm_gpio = RK30_PIN3_PD6,
1104                 .pwm_iomux_name = GPIO3D6_PWM3_JTAGTMS_HOSTDRVVBUS_NAME,
1105                 .pwm_iomux_pwm = GPIO3D_PWM3,
1106                 .pwm_iomux_gpio = GPIO3D_GPIO3D6,
1107                 .pwm_voltage = 1000000,
1108                 .suspend_voltage = 1050000,
1109                 .min_uV = 1000000,
1110                 .max_uV = 1400000,
1111                 .coefficient = 455,     //45.5%
1112                 .pwm_voltage_map = pwm_voltage_map,
1113                 .init_data      = &pwm_regulator_init_dcdc[0],
1114         },
1115 };
1116
1117 struct platform_device pwm_regulator_device[1] = {
1118         {
1119                 .name = "pwm-voltage-regulator",
1120                 .id = 0,
1121                 .dev            = {
1122                         .platform_data = &pwm_regulator_info[0],
1123                 }
1124         },
1125 };
1126 #endif
1127
1128 #ifdef CONFIG_RK29_VMAC
1129 #define PHY_PWR_EN_GPIO RK30_PIN1_PD6
1130 #include "board-rk30-sdk-vmac.c"
1131 #endif
1132
1133 #ifdef CONFIG_RFKILL_RK
1134 // bluetooth rfkill device, its driver in net/rfkill/rfkill-rk.c
1135 static struct rfkill_rk_platform_data rfkill_rk_platdata = {
1136     .type               = RFKILL_TYPE_BLUETOOTH,
1137
1138     .poweron_gpio       = { // BT_REG_ON
1139         .io             = RK30_PIN3_PC7,
1140         .enable         = GPIO_HIGH,
1141         .iomux          = {
1142             .name       = GPIO3C7_SDMMC1WRITEPRT_RMIICRS_NAME,
1143             .fgpio      = GPIO3C_GPIO3C7,
1144         },
1145     },
1146
1147     .reset_gpio         = { // BT_RST
1148         .io             = RK30_PIN3_PD1, // set io to INVALID_GPIO for disable it
1149         .enable         = GPIO_LOW,
1150         .iomux          = {
1151             .name       = GPIO3D1_SDMMC1BACKENDPWR_MIIMDCLK_NAME,
1152             .fgpio      = GPIO3D_GPIO3D1,
1153        },
1154    }, 
1155
1156     .wake_gpio          = { // BT_WAKE, use to control bt's sleep and wakeup
1157         .io             = RK30_PIN3_PC6, // set io to INVALID_GPIO for disable it
1158         .enable         = GPIO_HIGH,
1159         .iomux          = {
1160             .name       = GPIO3C6_SDMMC1DETECTN_RMIIRXERR_NAME,
1161             .fgpio      = GPIO3C_GPIO3C6,
1162         },
1163     },
1164
1165     .wake_host_irq      = { // BT_HOST_WAKE, for bt wakeup host when it is in deep sleep
1166         .gpio           = {
1167             .io         = RK30_PIN0_PA5, // set io to INVALID_GPIO for disable it
1168             .enable     = GPIO_LOW,      // set GPIO_LOW for falling, set 0 for rising
1169             .iomux      = {
1170                 .name   = NULL,
1171             },
1172         },
1173     },
1174
1175     .rts_gpio           = { // UART_RTS, enable or disable BT's data coming
1176         .io             = RK30_PIN1_PA3, // set io to INVALID_GPIO for disable it
1177         .enable         = GPIO_LOW,
1178         .iomux          = {
1179             .name       = GPIO1A3_UART0RTSN_NAME,
1180             .fgpio      = GPIO1A_GPIO1A3,
1181             .fmux       = GPIO1A_UART0RTSN,
1182         },
1183     },
1184 };
1185
1186 static struct platform_device device_rfkill_rk = {
1187     .name   = "rfkill_rk",
1188     .id     = -1,
1189     .dev    = {
1190         .platform_data = &rfkill_rk_platdata,
1191     },
1192 };
1193 #endif
1194
1195 static struct platform_device *devices[] __initdata = {
1196 #ifdef CONFIG_FB_ROCKCHIP
1197         &device_fb,
1198 #endif
1199 #if defined(CONFIG_LCDC0_RK3066B)
1200         &device_lcdc0,
1201 #endif
1202 #if defined(CONFIG_LCDC1_RK3066B)
1203         &device_lcdc1,
1204 #endif
1205                 
1206 #ifdef CONFIG_BACKLIGHT_RK29_BL
1207         &rk29_device_backlight,
1208 #endif
1209
1210 #ifdef CONFIG_ION
1211         &device_ion,
1212 #endif
1213 #ifdef CONFIG_ANDROID_TIMED_GPIO
1214         &rk29_device_vibrator,
1215 #endif
1216 #ifdef CONFIG_LEDS_GPIO_PLATFORM
1217         &rk29_device_gpio_leds,
1218 #endif
1219 #ifdef CONFIG_RK_IRDA
1220         &irda_device,
1221 #endif
1222 #ifdef CONFIG_WIFI_CONTROL_FUNC
1223         &rk29sdk_wifi_device,
1224 #endif
1225 #ifdef CONFIG_RK29_SUPPORT_MODEM
1226         &rk30_device_modem,
1227 #endif
1228 #if defined(CONFIG_MU509)
1229         &rk29_device_mu509,
1230 #endif
1231 #if defined(CONFIG_MW100)
1232         &rk29_device_mw100,
1233 #endif
1234 #if defined(CONFIG_MT6229)
1235         &rk29_device_mt6229,
1236 #endif
1237 #if defined(CONFIG_SEW868)
1238         &rk30_device_sew868,
1239 #endif
1240 #ifdef CONFIG_BATTERY_RK30_ADC
1241         &rk30_device_adc_battery,
1242 #endif
1243 #ifdef CONFIG_RFKILL_RK
1244         &device_rfkill_rk,
1245 #endif
1246 };
1247
1248 // i2c
1249 #ifdef CONFIG_I2C0_RK30
1250 static struct i2c_board_info __initdata i2c0_info[] = {
1251 #if defined (CONFIG_GS_MMA7660)
1252         {
1253           .type                   = "gs_mma7660",
1254           .addr                   = 0x4c,
1255           .flags                  = 0,
1256           .irq                    = MMA7660_INT_PIN,
1257           .platform_data  = &mma7660_info,
1258         },
1259 #endif
1260 #if defined (CONFIG_GS_MMA8452)
1261         {
1262                 .type           = "gs_mma8452",
1263                 .addr           = 0x1d,
1264                 .flags          = 0,
1265                 .irq            = MMA8452_INT_PIN,
1266                 .platform_data = &mma8452_info,
1267         },
1268 #endif
1269 #if defined (CONFIG_GS_LIS3DH)
1270         {
1271                 .type           = "gs_lis3dh",
1272                 .addr           = 0x19,   //0x19(SA0-->VCC), 0x18(SA0-->GND)
1273                 .flags          = 0,
1274                 .irq            = LIS3DH_INT_PIN,
1275                 .platform_data = &lis3dh_info,
1276         },
1277 #endif
1278 #if defined (CONFIG_COMPASS_AK8975)
1279         {
1280                 .type          = "ak8975",
1281                 .addr          = 0x0d,
1282                 .flags         = 0,
1283                 .irq           = RK30_PIN0_PD5,
1284                 .platform_data = &akm8975_info,
1285         },
1286 #endif
1287 #if defined (CONFIG_GYRO_L3G4200D)
1288         {
1289                 .type          = "l3g4200d_gryo",
1290                 .addr          = 0x69,
1291                 .flags         = 0,
1292                 .irq           = L3G4200D_INT_PIN,
1293                 .platform_data = &l3g4200d_info,
1294         },
1295 #endif
1296 #if defined (CONFIG_SND_SOC_RK1000)
1297         {
1298                 .type          = "rk1000_i2c_codec",
1299                 .addr          = 0x60,
1300                 .flags         = 0,
1301         },
1302         {
1303                 .type          = "rk1000_control",
1304                 .addr          = 0x40,
1305                 .flags         = 0,
1306         },
1307 #endif
1308 #if defined (CONFIG_SND_SOC_RT5631)
1309         {
1310                 .type                   = "rt5631",
1311                 .addr                   = 0x1a,
1312                 .flags                  = 0,
1313         },
1314 #endif
1315 #if defined (CONFIG_SND_SOC_ES8323)
1316         {
1317                 .type                   = "es8323",
1318                 .addr                   = 0x10,
1319                 .flags                  = 0,
1320         },
1321 #endif
1322 #ifdef CONFIG_MFD_RK610
1323                 {
1324                         .type                   = "rk610_ctl",
1325                         .addr                   = 0x40,
1326                         .flags                  = 0,
1327                 },
1328 #ifdef CONFIG_RK610_TVOUT
1329                 {
1330                         .type                   = "rk610_tvout",
1331                         .addr                   = 0x42,
1332                         .flags                  = 0,
1333                 },
1334 #endif
1335 #ifdef CONFIG_HDMI_RK610
1336                 {
1337                         .type                   = "rk610_hdmi",
1338                         .addr                   = 0x46,
1339                         .flags                  = 0,
1340                         .irq                    = RK30_PIN0_PB6,
1341                 },
1342 #endif
1343 #ifdef CONFIG_SND_SOC_RK610
1344                 {//RK610_CODEC addr  from 0x60 to 0x80 (0x60~0x80)
1345                         .type                   = "rk610_i2c_codec",
1346                         .addr                   = 0x60,
1347                         .flags                  = 0,
1348                 },
1349 #endif
1350 #endif
1351
1352 };
1353 #endif
1354
1355 #define PMIC_TYPE_WM8326        1
1356 #define PMIC_TYPE_TPS65910      2
1357 int __sramdata g_pmic_type =  0;
1358 #ifdef CONFIG_I2C1_RK30
1359 #ifdef CONFIG_MFD_WM831X_I2C
1360 #include "board-rk3066b-sdk-wm8326.c"
1361 #endif
1362 #ifdef CONFIG_MFD_TPS65910
1363 #define TPS65910_HOST_IRQ        RK30_PIN0_PB3
1364 #include "board-rk3066b-sdk-tps65910.c"
1365 #endif
1366
1367 static struct i2c_board_info __initdata i2c1_info[] = {
1368 #if defined (CONFIG_MFD_WM831X_I2C)
1369         {
1370                 .type          = "wm8326",
1371                 .addr          = 0x34,
1372                 .flags         = 0,
1373                 .irq           = RK30_PIN0_PB3,
1374                 .platform_data = &wm831x_platdata,
1375         },
1376 #endif
1377 #if defined (CONFIG_MFD_TPS65910)
1378         {
1379         .type           = "tps65910",
1380         .addr           = TPS65910_I2C_ID0,
1381         .flags          = 0,
1382         .irq            = TPS65910_HOST_IRQ,
1383         .platform_data = &tps65910_data,
1384         },
1385 #endif
1386 };
1387 #endif
1388
1389 void __sramfunc board_pmu_suspend(void)
1390 {      
1391         #if defined (CONFIG_MFD_WM831X_I2C)
1392        if(g_pmic_type == PMIC_TYPE_WM8326)
1393        board_pmu_wm8326_suspend();
1394         #endif
1395         #if defined (CONFIG_MFD_TPS65910)
1396        if(g_pmic_type == PMIC_TYPE_TPS65910)
1397        board_pmu_tps65910_suspend(); 
1398     #endif   
1399 }
1400
1401 void __sramfunc board_pmu_resume(void)
1402 {      
1403         #if defined (CONFIG_MFD_WM831X_I2C)
1404        if(g_pmic_type == PMIC_TYPE_WM8326)
1405        board_pmu_wm8326_resume();
1406         #endif
1407         #if defined (CONFIG_MFD_TPS65910)
1408        if(g_pmic_type == PMIC_TYPE_TPS65910)
1409        board_pmu_tps65910_resume(); 
1410         #endif
1411 }
1412
1413  int __sramdata gpio0d7_iomux,gpio0d7_do,gpio0d7_dir,gpio0d7_en;
1414
1415 void __sramfunc rk30_pwm_logic_suspend_voltage(void)
1416 {
1417 #ifdef CONFIG_RK30_PWM_REGULATOR
1418
1419 //      int gpio0d7_iomux,gpio0d7_do,gpio0d7_dir,gpio0d7_en;
1420         sram_udelay(10000);
1421         gpio0d7_iomux = readl_relaxed(GRF_GPIO0D_IOMUX);
1422         gpio0d7_do = grf_readl(GRF_GPIO0H_DO);
1423         gpio0d7_dir = grf_readl(GRF_GPIO0H_DIR);
1424         gpio0d7_en = grf_readl(GRF_GPIO0H_EN);
1425
1426         writel_relaxed((1<<30), GRF_GPIO0D_IOMUX);
1427         grf_writel((1<<31)|(1<<15), GRF_GPIO0H_DIR);
1428         grf_writel((1<<31)|(1<<15), GRF_GPIO0H_DO);
1429         grf_writel((1<<31)|(1<<15), GRF_GPIO0H_EN);
1430 #endif 
1431 }
1432 void __sramfunc rk30_pwm_logic_resume_voltage(void)
1433 {
1434 #ifdef CONFIG_RK30_PWM_REGULATOR
1435         writel_relaxed((1<<30)|gpio0d7_iomux, GRF_GPIO0D_IOMUX);
1436         grf_writel((1<<31)|gpio0d7_en, GRF_GPIO0H_EN);
1437         grf_writel((1<<31)|gpio0d7_dir, GRF_GPIO0H_DIR);
1438         grf_writel((1<<31)|gpio0d7_do, GRF_GPIO0H_DO);
1439         sram_udelay(10000);
1440
1441 #endif
1442
1443 }
1444 extern void pwm_suspend_voltage(void);
1445 extern void pwm_resume_voltage(void);
1446 void  rk30_pwm_suspend_voltage_set(void)
1447 {
1448 #ifdef CONFIG_RK30_PWM_REGULATOR
1449         pwm_suspend_voltage();
1450 #endif
1451 }
1452 void  rk30_pwm_resume_voltage_set(void)
1453 {
1454 #ifdef CONFIG_RK30_PWM_REGULATOR
1455         pwm_resume_voltage();
1456 #endif
1457 }
1458
1459
1460 #ifdef CONFIG_I2C2_RK30
1461 static struct i2c_board_info __initdata i2c2_info[] = {
1462 #if defined (CONFIG_TOUCHSCREEN_GT8XX)
1463         {
1464                 .type          = "Goodix-TS",
1465                 .addr          = 0x55,
1466                 .flags         = 0,
1467                 .irq           = RK30_PIN0_PD4,
1468                 .platform_data = &goodix_info,
1469         },
1470 #endif
1471 #if defined (CONFIG_TOUCHSCREEN_FT5306_AV)
1472                 {
1473                         .type                   = "ft5x0x_ts",
1474                         .addr                   = 0x38,
1475                         .flags                  = 0,
1476                         .irq                    = RK30_PIN0_PD4,
1477                         .platform_data  = &ft5306_info,
1478                 },
1479 #endif
1480 #if defined (CONFIG_LS_CM3217)
1481         {
1482                 .type          = "lightsensor",
1483                 .addr          = 0x10,
1484                 .flags         = 0,
1485                 .platform_data = &cm3217_info,
1486         },
1487 #endif
1488 };
1489 #endif
1490
1491 #ifdef CONFIG_I2C3_RK30
1492 static struct i2c_board_info __initdata i2c3_info[] = {
1493 };
1494 #endif
1495
1496 #ifdef CONFIG_I2C4_RK30
1497 static struct i2c_board_info __initdata i2c4_info[] = {
1498 };
1499 #endif
1500
1501 #ifdef CONFIG_I2C_GPIO_RK30
1502 #define I2C_SDA_PIN     INVALID_GPIO// RK30_PIN2_PD6   //set sda_pin here
1503 #define I2C_SCL_PIN     INVALID_GPIO//RK30_PIN2_PD7   //set scl_pin here
1504 static int rk30_i2c_io_init(void)
1505 {
1506         //set iomux (gpio) here
1507         //rk30_mux_api_set(GPIO2D7_I2C1SCL_NAME, GPIO2D_GPIO2D7);
1508         //rk30_mux_api_set(GPIO2D6_I2C1SDA_NAME, GPIO2D_GPIO2D6);
1509
1510         return 0;
1511 }
1512 struct i2c_gpio_platform_data default_i2c_gpio_data = {
1513        .sda_pin = I2C_SDA_PIN,
1514        .scl_pin = I2C_SCL_PIN,
1515        .udelay = 5, // clk = 500/udelay = 100Khz
1516        .timeout = 100,//msecs_to_jiffies(100),
1517        .bus_num    = 5,
1518        .io_init = rk30_i2c_io_init,
1519 };
1520 static struct i2c_board_info __initdata i2c_gpio_info[] = {
1521 };
1522 #endif
1523
1524 static void __init rk30_i2c_register_board_info(void)
1525 {
1526 #ifdef CONFIG_I2C0_RK30
1527         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
1528 #endif
1529 #ifdef CONFIG_I2C1_RK30
1530         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
1531 #endif
1532 #ifdef CONFIG_I2C2_RK30
1533         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
1534 #endif
1535 #ifdef CONFIG_I2C3_RK30
1536         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
1537 #endif
1538 #ifdef CONFIG_I2C4_RK30
1539         i2c_register_board_info(4, i2c4_info, ARRAY_SIZE(i2c4_info));
1540 #endif
1541 #ifdef CONFIG_I2C_GPIO_RK30
1542         i2c_register_board_info(5, i2c_gpio_info, ARRAY_SIZE(i2c_gpio_info));
1543 #endif
1544 }
1545 //end of i2c
1546
1547 #define POWER_ON_PIN RK30_PIN0_PA0   //power_hold
1548 static void rk30_pm_power_off(void)
1549 {
1550         printk(KERN_ERR "rk30_pm_power_off start...\n");
1551         gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
1552 #if defined(CONFIG_MFD_WM831X)
1553         wm831x_set_bits(Wm831x,WM831X_GPIO_LEVEL,0x0001,0x0000);  //set sys_pwr 0
1554         wm831x_device_shutdown(Wm831x);//wm8326 shutdown
1555 #endif
1556         while (1);
1557 }
1558
1559 static void __init machine_rk30_board_init(void)
1560 {
1561         //avs_init();
1562         gpio_request(POWER_ON_PIN, "poweronpin");
1563         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
1564         
1565         pm_power_off = rk30_pm_power_off;
1566         
1567         rk30_i2c_register_board_info();
1568         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1569         platform_add_devices(devices, ARRAY_SIZE(devices));
1570         board_usb_detect_init(RK30_PIN0_PA7);
1571
1572 #ifdef CONFIG_WIFI_CONTROL_FUNC
1573         rk29sdk_wifi_bt_gpio_control_init();
1574 #endif
1575
1576         // spk and ear switch
1577         gpio_request(RK30_PIN2_PB1, NULL);
1578         gpio_direction_output(RK30_PIN2_PB1, GPIO_HIGH);
1579 }
1580
1581 static void __init rk30_reserve(void)
1582 {
1583 #ifdef CONFIG_ION
1584         rk30_ion_pdata.heaps[0].base = board_mem_reserve_add("ion", ION_RESERVE_SIZE);
1585 #endif
1586 #ifdef CONFIG_FB_ROCKCHIP
1587         resource_fb[0].start = board_mem_reserve_add("fb0", RK30_FB0_MEM_SIZE);
1588         resource_fb[0].end = resource_fb[0].start + RK30_FB0_MEM_SIZE - 1;
1589         #if 0
1590         resource_fb[1].start = board_mem_reserve_add("ipp buf", RK30_FB0_MEM_SIZE);
1591         resource_fb[1].end = resource_fb[1].start + RK30_FB0_MEM_SIZE - 1;
1592         resource_fb[2].start = board_mem_reserve_add("fb2", RK30_FB0_MEM_SIZE);
1593         resource_fb[2].end = resource_fb[2].start + RK30_FB0_MEM_SIZE - 1;
1594         #endif
1595 #endif
1596 #ifdef CONFIG_VIDEO_RK29
1597         rk30_camera_request_reserve_mem();
1598 #endif
1599         board_mem_reserved();
1600 }
1601
1602 /**
1603  * dvfs_cpu_logic_table: table for arm and logic dvfs 
1604  * @frequency   : arm frequency
1605  * @cpu_volt    : arm voltage depend on frequency
1606  * @logic_volt  : logic voltage arm requests depend on frequency
1607  * comments     : min arm/logic voltage
1608  */
1609 static struct dvfs_arm_table dvfs_cpu_logic_table[] = {
1610 #if 0
1611         {.frequency = 252 * 1000,       .cpu_volt = 1075 * 1000,        .logic_volt = 1125 * 1000},//0.975V/1.000V
1612 #endif
1613         {.frequency = 504 * 1000,       .cpu_volt = 1100 * 1000,                .logic_volt = 1100 * 1000},//0.975V/1.000V
1614         {.frequency = 816 * 1000,       .cpu_volt = 1100 * 1000,        .logic_volt = 1100 * 1000},//1.000V/1.025V
1615         {.frequency = 1200 * 1000,      .cpu_volt = 1100 * 1000,        .logic_volt = 1100 * 1000},//1.100V/1.050V
1616 #if 0
1617         {.frequency = 1008 * 1000,      .cpu_volt = 1125 * 1000,        .logic_volt = 1150 * 1000},//1.025V/1.050V
1618         {.frequency = 1272 * 1000,      .cpu_volt = 1225 * 1000,        .logic_volt = 1200 * 1000},//1.150V/1.100V
1619         {.frequency = 1416 * 1000,      .cpu_volt = 1300 * 1000,        .logic_volt = 1200 * 1000},//1.225V/1.100V
1620         {.frequency = 1512 * 1000,      .cpu_volt = 1350 * 1000,        .logic_volt = 1250 * 1000},//1.300V/1.150V
1621         {.frequency = 1608 * 1000,      .cpu_volt = 1425 * 1000,        .logic_volt = 1300 * 1000},//1.325V/1.175V
1622 #endif
1623         {.frequency = CPUFREQ_TABLE_END},
1624 };
1625
1626 static struct cpufreq_frequency_table dvfs_gpu_table[] = {
1627         {.frequency = 266 * 1000,       .index = 1000 * 1000},
1628         {.frequency = 400 * 1000,       .index = 1000 * 1000},
1629         {.frequency = CPUFREQ_TABLE_END},
1630 };
1631
1632 static struct cpufreq_frequency_table dvfs_ddr_table[] = {
1633         {.frequency = 300 * 1000,       .index = 1000 * 1000},
1634         {.frequency = 400 * 1000,       .index = 1000 * 1000},
1635         {.frequency = CPUFREQ_TABLE_END},
1636 };
1637
1638 #define DVFS_CPU_TABLE_SIZE     (ARRAY_SIZE(dvfs_cpu_logic_table))
1639 static struct cpufreq_frequency_table cpu_dvfs_table[DVFS_CPU_TABLE_SIZE];
1640 static struct cpufreq_frequency_table dep_cpu2core_table[DVFS_CPU_TABLE_SIZE];
1641
1642 void __init board_clock_init(void)
1643 {
1644         rk30_clock_data_init(periph_pll_default, codec_pll_default, RK30_CLOCKS_DEFAULT_FLAGS);
1645         dvfs_set_arm_logic_volt(dvfs_cpu_logic_table, cpu_dvfs_table, dep_cpu2core_table);
1646         dvfs_set_freq_volt_table(clk_get(NULL, "gpu"), dvfs_gpu_table);
1647         dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
1648 }
1649
1650 MACHINE_START(RK30, "RK30board")
1651         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
1652         .fixup          = rk30_fixup,
1653         .reserve        = &rk30_reserve,
1654         .map_io         = rk30_map_io,
1655         .init_irq       = rk30_init_irq,
1656         .timer          = &rk30_timer,
1657         .init_machine   = machine_rk30_board_init,
1658 MACHINE_END