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