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