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