09709ba14ca010c2691433260ac9b4f69ac6f4a5
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk30 / board-rk3168-tb.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/rk_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/act8846.h>
49 #include <linux/mfd/rk808.h>
50 #include <linux/mfd/ricoh619.h>
51 #include <linux/regulator/rk29-pwm-regulator.h>
52 #ifdef CONFIG_MFD_RT5025
53 #include <linux/mfd/rt5025.h>
54 #endif
55 #include <plat/efuse.h>
56
57 #ifdef CONFIG_CW2015_BATTERY
58 #include <linux/power/cw2015_battery.h>
59 #endif
60 #if defined(CONFIG_MFD_RK610)
61 #include <linux/mfd/rk610_core.h>
62 #endif
63
64 #if defined(CONFIG_MFD_RK616)
65 #include <linux/mfd/rk616.h>
66 #endif
67
68
69 #if defined(CONFIG_RK_HDMI)
70         #include "../../../drivers/video/rockchip/hdmi/rk_hdmi.h"
71 #endif
72
73 #if defined(CONFIG_SPIM_RK29)
74 #include "../../../drivers/spi/rk29_spim.h"
75 #endif
76 #if defined(CONFIG_GPS_RK)
77 #include "../../../drivers/misc/gps/rk_gps/rk_gps.h"
78 #endif
79 #if defined(CONFIG_MU509)
80 #include <linux/mu509.h>
81 #endif
82 #if defined(CONFIG_MW100)
83 #include <linux/mw100.h>
84 #endif
85 #if defined(CONFIG_MT6229)
86 #include <linux/mt6229.h>
87 #endif
88 #if defined(CONFIG_ANDROID_TIMED_GPIO)
89 #include "../../../drivers/staging/android/timed_gpio.h"
90 #endif
91
92 #if defined(CONFIG_MT6620)
93 #include <linux/gps.h>
94 #endif
95 #include "board-rk3168-tb-camera.c"
96
97 #if defined(CONFIG_TOUCHSCREEN_GT8XX)
98 #define TOUCH_RESET_PIN  RK30_PIN0_PB6
99 #define TOUCH_PWR_PIN    RK30_PIN0_PC5   // need to fly line by hardware engineer
100
101 /* Android Parameter */
102 static int ap_mdm = 0;
103 module_param(ap_mdm, int, 0644);
104 static int ap_has_alsa = 0;
105 module_param(ap_has_alsa, int, 0644);
106 static int ap_data_only = 2;
107 module_param(ap_data_only, int, 0644);
108 static int ap_has_earphone = 0;
109 module_param(ap_has_earphone, int, 0644);
110
111
112 static int goodix_init_platform_hw(void)
113 {
114         int ret;
115         
116         if (TOUCH_PWR_PIN != INVALID_GPIO) {
117                 ret = gpio_request(TOUCH_PWR_PIN, "goodix power pin");
118                 if (ret != 0) {
119                         gpio_free(TOUCH_PWR_PIN);
120                         printk("goodix power error\n");
121                         return -EIO;
122                 }
123                 gpio_direction_output(TOUCH_PWR_PIN, 0);
124                 gpio_set_value(TOUCH_PWR_PIN, GPIO_LOW);
125                 msleep(100);
126         }
127
128         if (TOUCH_RESET_PIN != INVALID_GPIO) {
129                 ret = gpio_request(TOUCH_RESET_PIN, "goodix reset pin");
130                 if (ret != 0) {
131                         gpio_free(TOUCH_RESET_PIN);
132                         printk("goodix gpio_request error\n");
133                         return -EIO;
134                 }
135                 gpio_direction_output(TOUCH_RESET_PIN, 1);
136                 msleep(100);
137                 //gpio_set_value(TOUCH_RESET_PIN, GPIO_LOW);
138                 //msleep(100);
139                 //gpio_set_value(TOUCH_RESET_PIN, GPIO_HIGH);
140                 //msleep(500);
141         }
142         return 0;
143 }
144
145 struct goodix_platform_data goodix_info = {
146         .model = 8105,
147         .irq_pin = RK30_PIN1_PB7,
148         .rest_pin = TOUCH_RESET_PIN,
149         .init_platform_hw = goodix_init_platform_hw,
150 };
151 #endif
152
153 static struct spi_board_info board_spi_devices[] = {
154 };
155
156 /***********************************************************
157 *       rk30  backlight
158 ************************************************************/
159 #ifdef CONFIG_BACKLIGHT_RK29_BL
160 #define PWM_ID            3
161 #define PWM_MODE          PWM3
162 #define PWM_EFFECT_VALUE  1
163
164 #define LCD_DISP_ON_PIN
165
166 #ifdef  LCD_DISP_ON_PIN
167 #define BL_EN_PIN         RK30_PIN0_PA2
168 #define BL_EN_VALUE       GPIO_HIGH
169 #endif
170 static int rk29_backlight_io_init(void)
171 {
172         int ret = 0;
173
174         iomux_set(PWM_MODE);
175 #ifdef  LCD_DISP_ON_PIN
176         ret = gpio_request(BL_EN_PIN, "bl_en");
177         if (ret == 0) {
178                 gpio_direction_output(BL_EN_PIN, BL_EN_VALUE);
179         }
180 #endif
181         return ret;
182 }
183
184 static int rk29_backlight_io_deinit(void)
185 {
186         int ret = 0, pwm_gpio;
187 #ifdef  LCD_DISP_ON_PIN
188         gpio_free(BL_EN_PIN);
189 #endif
190         pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
191         gpio_request(pwm_gpio, "bl_pwm");
192         gpio_direction_output(pwm_gpio, GPIO_LOW);
193         return ret;
194 }
195
196 static int rk29_backlight_pwm_suspend(void)
197 {
198         int ret, pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
199
200         ret = gpio_request(pwm_gpio, "bl_pwm");
201         if (ret) {
202                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
203                 return ret;
204         }
205         gpio_direction_output(pwm_gpio, GPIO_LOW);
206 #ifdef  LCD_DISP_ON_PIN
207         gpio_direction_output(BL_EN_PIN, !BL_EN_VALUE);
208 #endif
209         return ret;
210 }
211
212 static int rk29_backlight_pwm_resume(void)
213 {
214         int pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
215
216         gpio_free(pwm_gpio);
217         iomux_set(PWM_MODE);
218 #ifdef  LCD_DISP_ON_PIN
219         msleep(30);
220         gpio_direction_output(BL_EN_PIN, BL_EN_VALUE);
221 #endif
222         return 0;
223 }
224
225 static struct rk29_bl_info rk29_bl_info = {
226         .pwm_id = PWM_ID,
227         .min_brightness=20,
228         .max_brightness=255,
229         .brightness_mode =BRIGHTNESS_MODE_CONIC,
230         .bl_ref = PWM_EFFECT_VALUE,
231         .io_init = rk29_backlight_io_init,
232         .io_deinit = rk29_backlight_io_deinit,
233         .pwm_suspend = rk29_backlight_pwm_suspend,
234         .pwm_resume = rk29_backlight_pwm_resume,
235 };
236
237 static struct platform_device rk29_device_backlight = {
238         .name   = "rk29_backlight",
239         .id     = -1,
240         .dev    = {
241                 .platform_data  = &rk29_bl_info,
242         }
243 };
244
245 #endif
246
247 #ifdef CONFIG_RK29_SUPPORT_MODEM
248
249 #define RK30_MODEM_POWER        RK30_PIN0_PC6
250 #define RK30_MODEM_POWER_IOMUX  iomux_set(GPIO0_C6)
251
252 static int rk30_modem_io_init(void)
253 {
254     printk("%s\n", __FUNCTION__);
255     RK30_MODEM_POWER_IOMUX;
256
257         return 0;
258 }
259
260 static struct rk29_io_t rk30_modem_io = {
261     .io_addr    = RK30_MODEM_POWER,
262     .enable     = GPIO_HIGH,
263     .disable    = GPIO_LOW,
264     .io_init    = rk30_modem_io_init,
265 };
266
267 static struct platform_device rk30_device_modem = {
268         .name   = "rk30_modem",
269         .id     = -1,
270         .dev    = {
271                 .platform_data  = &rk30_modem_io,
272         }
273 };
274 #endif
275 #if defined(CONFIG_MU509)
276 static int mu509_io_init(void)
277 {
278
279         iomux_set(GPIO2_D5);
280         iomux_set(GPIO0_C6);
281         iomux_set(GPIO2_D4);
282         iomux_set(GPIO0_C4);
283         iomux_set(GPIO0_C5);
284         return 0;
285 }
286
287 static int mu509_io_deinit(void)
288 {
289         
290         return 0;
291 }
292  
293 struct rk29_mu509_data rk29_mu509_info = {
294         .io_init = mu509_io_init,
295         .io_deinit = mu509_io_deinit,
296         .modem_power_en = RK30_PIN2_PD5,   
297         .bp_power = RK30_PIN0_PC6,              
298         .bp_reset = RK30_PIN2_PD4,              
299         .ap_wakeup_bp = RK30_PIN0_PC4,  
300         .bp_wakeup_ap = RK30_PIN0_PC5,  
301 };
302 struct platform_device rk29_device_mu509 = {    
303         .name = "mu509",        
304         .id = -1,       
305         .dev            = {
306                 .platform_data = &rk29_mu509_info,
307         }       
308     };
309 #endif
310 #if defined(CONFIG_MW100)
311 static int mw100_io_init(void)
312 {
313         iomux_set(GPIO2_D5);
314         iomux_set(GPIO0_C6);
315         iomux_set(GPIO2_D4);
316         iomux_set(GPIO0_C4);
317         iomux_set(GPIO0_C5);
318         return 0;
319 }
320
321 static int mw100_io_deinit(void)
322 {
323         
324         return 0;
325 }
326  
327 struct rk29_mw100_data rk29_mw100_info = {
328         .io_init = mw100_io_init,
329         .io_deinit = mw100_io_deinit,
330         .modem_power_en = RK30_PIN2_PD5,
331         .bp_power = RK30_PIN0_PC6,
332         .bp_reset = RK30_PIN2_PD4,
333         .ap_wakeup_bp = RK30_PIN0_PC4,
334         .bp_wakeup_ap = RK30_PIN0_PC5,
335 };
336 struct platform_device rk29_device_mw100 = {    
337         .name = "mw100",        
338         .id = -1,       
339         .dev            = {
340                 .platform_data = &rk29_mw100_info,
341         }       
342     };
343 #endif
344 #if defined(CONFIG_MT6229)
345 static int mt6229_io_init(void)
346 {
347         iomux_set(GPIO2_D5);
348         iomux_set(GPIO0_C6);
349         iomux_set(GPIO2_D4);
350         iomux_set(GPIO0_C4);
351         iomux_set(GPIO0_C5);
352         return 0;
353 }
354
355 static int mt6229_io_deinit(void)
356 {
357         
358         return 0;
359 }
360  
361 struct rk29_mt6229_data rk29_mt6229_info = {
362         .io_init = mt6229_io_init,
363         .io_deinit = mt6229_io_deinit,
364         .modem_power_en = RK30_PIN2_PD5,
365         .bp_power = RK30_PIN0_PC6,
366         .bp_reset = RK30_PIN2_PD4,
367         .ap_wakeup_bp = RK30_PIN0_PC4,
368         .bp_wakeup_ap = RK30_PIN0_PC5,
369 };
370 struct platform_device rk29_device_mt6229 = {   
371         .name = "mt6229",       
372         .id = -1,       
373         .dev            = {
374                 .platform_data = &rk29_mt6229_info,
375         }       
376     };
377 #endif
378
379 /*MMA8452 gsensor*/
380 #if defined (CONFIG_GS_MMA8452)
381 #define MMA8452_INT_PIN   RK30_PIN0_PB7
382
383 static int mma8452_init_platform_hw(void)
384 {
385         return 0;
386 }
387
388 static struct sensor_platform_data mma8452_info = {
389         .type = SENSOR_TYPE_ACCEL,
390         .irq_enable = 1,
391         .poll_delay_ms = 30,
392         .init_platform_hw = mma8452_init_platform_hw,
393         .orientation = {-1, 0, 0, 0, -1, 0, 0, 0, 1},
394 };
395 #endif
396 #if defined (CONFIG_GS_LIS3DH)
397 #define LIS3DH_INT_PIN   RK30_PIN0_PB7
398
399 static int lis3dh_init_platform_hw(void)
400 {
401
402         return 0;
403 }
404
405 static struct sensor_platform_data lis3dh_info = {
406         .type = SENSOR_TYPE_ACCEL,
407         .irq_enable = 1,
408         .poll_delay_ms = 30,
409         .init_platform_hw = lis3dh_init_platform_hw,
410         .orientation = {-1, 0, 0, 0, -1, 0, 0, 0, 1},
411 };
412 #endif
413 #if defined (CONFIG_COMPASS_AK8975)
414 static struct sensor_platform_data akm8975_info =
415 {
416         .type = SENSOR_TYPE_COMPASS,
417         .irq_enable = 1,
418         .poll_delay_ms = 30,
419         .m_layout = 
420         {
421                 {
422                         {1, 0, 0},
423                         {0, 1, 0},
424                         {0, 0, 1},
425                 },
426
427                 {
428                         {1, 0, 0},
429                         {0, 1, 0},
430                         {0, 0, 1},
431                 },
432
433                 {
434                         {1, 0, 0},
435                         {0, 1, 0},
436                         {0, 0, 1},
437                 },
438
439                 {
440                         {1, 0, 0},
441                         {0, 1, 0},
442                         {0, 0, 1},
443                 },
444         }
445 };
446
447 #endif
448
449 #if defined(CONFIG_GYRO_L3G4200D)
450
451 #include <linux/l3g4200d.h>
452 #define L3G4200D_INT_PIN  RK30_PIN0_PB4
453
454 static int l3g4200d_init_platform_hw(void)
455 {
456         return 0;
457 }
458
459 static struct sensor_platform_data l3g4200d_info = {
460         .type = SENSOR_TYPE_GYROSCOPE,
461         .irq_enable = 1,
462         .poll_delay_ms = 30,
463         .orientation = {0, 1, 0, -1, 0, 0, 0, 0, 1},
464         .init_platform_hw = l3g4200d_init_platform_hw,
465         .x_min = 40,//x_min,y_min,z_min = (0-100) according to hardware
466         .y_min = 40,
467         .z_min = 20,
468 };
469
470 #endif
471
472 #ifdef CONFIG_LS_CM3217
473 static struct sensor_platform_data cm3217_info = {
474         .type = SENSOR_TYPE_LIGHT,
475         .irq_enable = 0,
476         .poll_delay_ms = 500,
477 };
478
479 #endif
480
481 #ifdef CONFIG_FB_ROCKCHIP
482
483 #define LCD_CS_PIN         INVALID_GPIO
484 #define LCD_CS_VALUE       GPIO_HIGH
485
486 #define LCD_EN_PIN         RK30_PIN0_PB0
487 #define MIPI_LCD_RST_PIN   RK30_PIN0_PC3   //mipi lcd's reset pin, if no reset pin, set's  INVALID_GPIO
488 #define LCD_EN_VALUE       GPIO_HIGH
489
490 static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
491 {
492         int ret = 0;
493
494         if(LCD_CS_PIN !=INVALID_GPIO)
495         {
496                 ret = gpio_request(LCD_CS_PIN, NULL);
497                 if (ret != 0)
498                 {
499                         gpio_free(LCD_CS_PIN);
500                         printk(KERN_ERR "request lcd cs pin fail!\n");
501                         return -1;
502                 }
503                 else
504                 {
505                         gpio_direction_output(LCD_CS_PIN, LCD_CS_VALUE);
506                 }
507         }
508
509         if(LCD_EN_PIN !=INVALID_GPIO)
510         {
511                 ret = gpio_request(LCD_EN_PIN, NULL);
512                 if (ret != 0)
513                 {
514                         gpio_free(LCD_EN_PIN);
515                         printk(KERN_ERR "request lcd en pin fail!\n");
516                         return -1;
517                 }
518                 else
519                 {
520                         gpio_direction_output(LCD_EN_PIN, LCD_EN_VALUE);
521                 }
522         }
523
524     if(MIPI_LCD_RST_PIN !=INVALID_GPIO)
525         {
526                 ret = gpio_request(MIPI_LCD_RST_PIN, NULL);
527                 if (ret != 0)
528                 {
529                         gpio_free(MIPI_LCD_RST_PIN);
530                         printk(KERN_ERR "request mipi lcd rst pin fail!\n");
531                         return -1;
532                 }
533         
534                 else
535                 {
536             gpio_set_value(MIPI_LCD_RST_PIN, !GPIO_LOW);
537             msleep(20);
538                 }
539         }
540         return 0;
541 }
542 static int rk_fb_io_disable(void)
543 {
544         if(LCD_CS_PIN !=INVALID_GPIO)
545         {
546                 gpio_set_value(LCD_CS_PIN, !LCD_CS_VALUE);
547         }
548         if(LCD_EN_PIN !=INVALID_GPIO)
549         {
550                 gpio_set_value(LCD_EN_PIN, !LCD_EN_VALUE);
551         }
552
553     if(MIPI_LCD_RST_PIN !=INVALID_GPIO)
554         {
555                 gpio_set_value(MIPI_LCD_RST_PIN, GPIO_LOW);
556         msleep(10);
557         }
558         return 0;
559 }
560 static int rk_fb_io_enable(void)
561 {
562         if(LCD_CS_PIN !=INVALID_GPIO)
563         {
564                 gpio_set_value(LCD_CS_PIN, LCD_CS_VALUE);
565         }
566         if(LCD_EN_PIN !=INVALID_GPIO)
567         {
568                 gpio_set_value(LCD_EN_PIN, LCD_EN_VALUE);
569         }
570
571     if(MIPI_LCD_RST_PIN !=INVALID_GPIO)
572         {
573         gpio_set_value(MIPI_LCD_RST_PIN, !GPIO_LOW);
574         msleep(10);
575         }
576         return 0;
577 }
578
579 #if defined(CONFIG_LCDC0_RK3066B) || defined(CONFIG_LCDC0_RK3188)
580 struct rk29fb_info lcdc0_screen_info = {
581 #if defined(CONFIG_RK_HDMI) && defined(CONFIG_HDMI_SOURCE_LCDC0) && defined(CONFIG_DUAL_LCDC_DUAL_DISP_IN_KERNEL)
582         .prop      = EXTEND,    //extend display device
583         .io_init    = NULL,
584         .io_disable = NULL,
585         .io_enable = NULL,
586         .set_screen_info = hdmi_init_lcdc,
587 #else
588         .prop      = PRMRY,             //primary display device
589         .io_init   = rk_fb_io_init,
590         .io_disable = rk_fb_io_disable,
591         .io_enable = rk_fb_io_enable,
592         .set_screen_info = set_lcd_info,
593 #endif
594 };
595 #endif
596
597 #if defined(CONFIG_LCDC1_RK3066B) || defined(CONFIG_LCDC1_RK3188)
598 struct rk29fb_info lcdc1_screen_info = {
599 #if defined(CONFIG_RK_HDMI) && defined(CONFIG_HDMI_SOURCE_LCDC1) && defined(CONFIG_DUAL_LCDC_DUAL_DISP_IN_KERNEL)
600         .prop      = EXTEND,    //extend display device
601         .io_init    = NULL,
602         .io_disable = NULL,
603         .io_enable = NULL,
604         .set_screen_info = hdmi_init_lcdc,
605 #else
606         .prop      = PRMRY,             //primary display device
607         .io_init   = rk_fb_io_init,
608         .io_disable = rk_fb_io_disable,
609         .io_enable = rk_fb_io_enable,
610         .set_screen_info = set_lcd_info,
611 #endif
612 };
613 #endif
614
615 static struct resource resource_fb[] = {
616         [0] = {
617                 .name  = "fb0 buf",
618                 .start = 0,
619                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
620                 .flags = IORESOURCE_MEM,
621         },
622         [1] = {
623                 .name  = "ipp buf",  //for rotate
624                 .start = 0,
625                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
626                 .flags = IORESOURCE_MEM,
627         },
628         [2] = {
629                 .name  = "fb2 buf",
630                 .start = 0,
631                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
632                 .flags = IORESOURCE_MEM,
633         },
634 };
635
636 static struct platform_device device_fb = {
637         .name           = "rk-fb",
638         .id             = -1,
639         .num_resources  = ARRAY_SIZE(resource_fb),
640         .resource       = resource_fb,
641 };
642 #endif
643 #if defined(CONFIG_ARCH_RK3188)
644 static struct resource resource_mali[] = {
645         [0] = {
646         .name  = "ump buf",
647         .start = 0,
648         .end   = 0,
649         .flags = IORESOURCE_MEM,
650         },
651
652 };
653
654 static struct platform_device device_mali= {
655         .name           = "mali400_ump",
656         .id             = -1,
657         .num_resources  = ARRAY_SIZE(resource_mali),
658         .resource       = resource_mali,
659 };
660 #endif
661
662 #if defined(CONFIG_LCDC0_RK3066B) || defined(CONFIG_LCDC0_RK3188)
663 static struct resource resource_lcdc0[] = {
664         [0] = {
665                 .name  = "lcdc0 reg",
666                 .start = RK30_LCDC0_PHYS,
667                 .end   = RK30_LCDC0_PHYS + RK30_LCDC0_SIZE - 1,
668                 .flags = IORESOURCE_MEM,
669         },
670         
671         [1] = {
672                 .name  = "lcdc0 irq",
673                 .start = IRQ_LCDC0,
674                 .end   = IRQ_LCDC0,
675                 .flags = IORESOURCE_IRQ,
676         },
677 };
678
679 static struct platform_device device_lcdc0 = {
680         .name             = "rk30-lcdc",
681         .id               = 0,
682         .num_resources    = ARRAY_SIZE(resource_lcdc0),
683         .resource         = resource_lcdc0,
684         .dev            = {
685                 .platform_data = &lcdc0_screen_info,
686         },
687 };
688 #endif
689 #if defined(CONFIG_LCDC1_RK3066B) || defined(CONFIG_LCDC1_RK3188)
690 static struct resource resource_lcdc1[] = {
691         [0] = {
692                 .name  = "lcdc1 reg",
693                 .start = RK30_LCDC1_PHYS,
694                 .end   = RK30_LCDC1_PHYS + RK30_LCDC1_SIZE - 1,
695                 .flags = IORESOURCE_MEM,
696         },
697         [1] = {
698                 .name  = "lcdc1 irq",
699                 .start = IRQ_LCDC1,
700                 .end   = IRQ_LCDC1,
701                 .flags = IORESOURCE_IRQ,
702         },
703 };
704
705 static struct platform_device device_lcdc1 = {
706         .name             = "rk30-lcdc",
707         .id               = 1,
708         .num_resources    = ARRAY_SIZE(resource_lcdc1),
709         .resource         = resource_lcdc1,
710         .dev            = {
711                 .platform_data = &lcdc1_screen_info,
712         },
713 };
714 #endif
715
716 #if defined(CONFIG_MFD_RK610)
717 #define RK610_RST_PIN                   RK30_PIN2_PC5
718 static int rk610_power_on_init(void)
719 {
720         int ret;
721         if(RK610_RST_PIN != INVALID_GPIO)
722         {
723                 ret = gpio_request(RK610_RST_PIN, "rk610 reset");
724                 if (ret)
725                 {
726                         printk(KERN_ERR "rk610_control_probe request gpio fail\n");
727                 }
728                 else 
729                 {
730                         gpio_direction_output(RK610_RST_PIN, GPIO_HIGH);
731                         msleep(100);
732                         gpio_direction_output(RK610_RST_PIN, GPIO_LOW);
733                         msleep(100);
734                         gpio_set_value(RK610_RST_PIN, GPIO_HIGH);
735                 }
736         }
737
738         return 0;
739         
740 }
741
742
743 static struct rk610_ctl_platform_data rk610_ctl_pdata = {
744         .rk610_power_on_init = rk610_power_on_init,
745 };
746 #endif
747
748 #if defined(CONFIG_MFD_RK616)
749 #define RK616_RST_PIN                   RK30_PIN3_PB2
750 #define RK616_PWREN_PIN                 RK30_PIN0_PA3
751 #define RK616_SCL_RATE                  (100*1000)   //i2c scl rate
752 static int rk616_power_on_init(void)
753 {
754         int ret;
755
756         if(RK616_PWREN_PIN != INVALID_GPIO)
757         {
758                 ret = gpio_request(RK616_PWREN_PIN, "rk616 pwren");
759                 if (ret)
760                 {
761                         printk(KERN_ERR "rk616 pwren gpio request fail\n");
762                 }
763                 else 
764                 {
765                         gpio_direction_output(RK616_PWREN_PIN,GPIO_HIGH);
766                 }
767         }
768         
769         if(RK616_RST_PIN != INVALID_GPIO)
770         {
771                 ret = gpio_request(RK616_RST_PIN, "rk616 reset");
772                 if (ret)
773                 {
774                         printk(KERN_ERR "rk616 reset gpio request fail\n");
775                 }
776                 else 
777                 {
778                         gpio_direction_output(RK616_RST_PIN, GPIO_HIGH);
779                         msleep(2);
780                         gpio_direction_output(RK616_RST_PIN, GPIO_LOW);
781                         msleep(10);
782                         gpio_set_value(RK616_RST_PIN, GPIO_HIGH);
783                 }
784         }
785
786         return 0;
787         
788 }
789
790
791 static int rk616_power_deinit(void)
792 {
793         gpio_set_value(RK616_PWREN_PIN,GPIO_LOW);
794         gpio_set_value(RK616_RST_PIN,GPIO_LOW);
795         gpio_free(RK616_PWREN_PIN);
796         gpio_free(RK616_RST_PIN);
797         
798         return 0;
799 }
800
801 static struct rk616_platform_data rk616_pdata = {
802         .power_init = rk616_power_on_init,
803         .power_deinit = rk616_power_deinit,
804         .scl_rate   = RK616_SCL_RATE,
805         .lcd0_func = INPUT,             //port lcd0 as input
806         .lcd1_func = INPUT,             //port lcd1 as input
807         .lvds_ch_nr = 1,                //the number of used lvds channel  
808         .hdmi_irq = RK30_PIN2_PD6,
809         .spk_ctl_gpio = RK30_PIN2_PD7,
810         .hp_ctl_gpio = RK30_PIN2_PD7,
811 };
812 #endif
813
814
815 #ifdef CONFIG_SND_SOC_RK610
816 static int rk610_codec_io_init(void)
817 {
818 //if need iomux.
819 //Must not gpio_request
820         return 0;
821 }
822
823 static struct rk610_codec_platform_data rk610_codec_pdata = {
824         .spk_ctl_io = RK30_PIN2_PD7,
825         .io_init = rk610_codec_io_init,
826 };
827 #endif
828
829 #ifdef CONFIG_ANDROID_TIMED_GPIO
830 static struct timed_gpio timed_gpios[] = {
831         {
832                 .name = "vibrator",
833                 .gpio = INVALID_GPIO,
834                 .max_timeout = 1000,
835                 .active_low = 0,
836                 .adjust_time =20,      //adjust for diff product
837         },
838 };
839
840 static struct timed_gpio_platform_data rk29_vibrator_info = {
841         .num_gpios = 1,
842         .gpios = timed_gpios,
843 };
844
845 static struct platform_device rk29_device_vibrator = {
846         .name = "timed-gpio",
847         .id = -1,
848         .dev = {
849                 .platform_data = &rk29_vibrator_info,
850         },
851
852 };
853 #endif
854
855 #ifdef CONFIG_LEDS_GPIO_PLATFORM
856 static struct gpio_led rk29_leds[] = {
857         {
858                 .name = "button-backlight",
859                 .gpio = INVALID_GPIO,
860                 .default_trigger = "timer",
861                 .active_low = 0,
862                 .retain_state_suspended = 0,
863                 .default_state = LEDS_GPIO_DEFSTATE_OFF,
864         },
865 };
866
867 static struct gpio_led_platform_data rk29_leds_pdata = {
868         .leds = rk29_leds,
869         .num_leds = ARRAY_SIZE(rk29_leds),
870 };
871
872 static struct platform_device rk29_device_gpio_leds = {
873         .name   = "leds-gpio",
874         .id     = -1,
875         .dev    = {
876                 .platform_data  = &rk29_leds_pdata,
877         },
878 };
879 #endif
880
881 #ifdef CONFIG_RK_IRDA
882 #define IRDA_IRQ_PIN           INVALID_GPIO //RK30_PIN0_PA3
883
884 static int irda_iomux_init(void)
885 {
886         int ret = 0;
887
888         //irda irq pin
889         ret = gpio_request(IRDA_IRQ_PIN, NULL);
890         if (ret != 0) {
891                 gpio_free(IRDA_IRQ_PIN);
892                 printk(">>>>>> IRDA_IRQ_PIN gpio_request err \n ");
893         }
894         gpio_pull_updown(IRDA_IRQ_PIN, PullDisable);
895         gpio_direction_input(IRDA_IRQ_PIN);
896
897         return 0;
898 }
899
900 static int irda_iomux_deinit(void)
901 {
902         gpio_free(IRDA_IRQ_PIN);
903         return 0;
904 }
905
906 static struct irda_info rk29_irda_info = {
907         .intr_pin = IRDA_IRQ_PIN,
908         .iomux_init = irda_iomux_init,
909         .iomux_deinit = irda_iomux_deinit,
910         //.irda_pwr_ctl = bu92747guw_power_ctl,
911 };
912
913 static struct platform_device irda_device = {
914 #ifdef CONFIG_RK_IRDA_NET
915         .name = "rk_irda",
916 #else
917         .name = "bu92747_irda",
918 #endif
919         .id = -1,
920         .dev = {
921                 .platform_data = &rk29_irda_info,
922         }
923 };
924 #endif
925
926 #ifdef CONFIG_ION
927 #define ION_RESERVE_SIZE        (80 * SZ_1M)
928 static struct ion_platform_data rk30_ion_pdata = {
929         .nr = 1,
930         .heaps = {
931                 {
932                         .type = ION_HEAP_TYPE_CARVEOUT,
933                         .id = ION_NOR_HEAP_ID,
934                         .name = "norheap",
935                         .size = ION_RESERVE_SIZE,
936                 }
937         },
938 };
939
940 static struct platform_device device_ion = {
941         .name = "ion-rockchip",
942         .id = 0,
943         .dev = {
944                 .platform_data = &rk30_ion_pdata,
945         },
946 };
947 #endif
948
949 /**************************************************************************************************
950  * SDMMC devices,  include the module of SD,MMC,and sdio.noted by xbw at 2012-03-05
951 **************************************************************************************************/
952 #ifdef CONFIG_SDMMC_RK29
953 #include "board-rk3168-tb-sdmmc-conifg.c"
954 #include "../plat-rk/rk-sdmmc-ops.c"
955 #include "../plat-rk/rk-sdmmc-wifi.c"
956 #endif //endif ---#ifdef CONFIG_SDMMC_RK29
957
958 #ifdef CONFIG_SDMMC0_RK29
959 static int rk29_sdmmc0_cfg_gpio(void)
960 {
961 #ifdef CONFIG_SDMMC_RK29_OLD
962         iomux_set(MMC0_CMD);
963         iomux_set(MMC0_CLKOUT);
964         iomux_set(MMC0_D0);
965         iomux_set(MMC0_D1);
966         iomux_set(MMC0_D2);
967         iomux_set(MMC0_D3);
968
969         iomux_set_gpio_mode(iomux_mode_to_gpio(MMC0_DETN));
970
971         gpio_request(RK30_PIN3_PA7, "sdmmc-power");
972         gpio_direction_output(RK30_PIN3_PA7, GPIO_LOW);
973
974 #else
975         rk29_sdmmc_set_iomux(0, 0xFFFF);
976
977     #if defined(CONFIG_SDMMC0_RK29_SDCARD_DET_FROM_GPIO)
978         #if SDMMC_USE_NEW_IOMUX_API
979         iomux_set_gpio_mode(iomux_gpio_to_mode(RK29SDK_SD_CARD_DETECT_N));
980         #else
981         rk30_mux_api_set(RK29SDK_SD_CARD_DETECT_PIN_NAME, RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO);
982         #endif
983     #else
984         #if SDMMC_USE_NEW_IOMUX_API       
985         iomux_set(MMC0_DETN);
986         #else
987         rk30_mux_api_set(RK29SDK_SD_CARD_DETECT_PIN_NAME, RK29SDK_SD_CARD_DETECT_IOMUX_FMUX);
988         #endif
989     #endif      
990
991 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
992         gpio_request(SDMMC0_WRITE_PROTECT_PIN, "sdmmc-wp");
993         gpio_direction_input(SDMMC0_WRITE_PROTECT_PIN);
994 #endif
995
996 #endif
997
998         return 0;
999 }
1000
1001 #define CONFIG_SDMMC0_USE_DMA
1002 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
1003         .host_ocr_avail =
1004             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
1005              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
1006              MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36),
1007         .host_caps =
1008             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
1009         .io_init = rk29_sdmmc0_cfg_gpio,
1010
1011 #if !defined(CONFIG_SDMMC_RK29_OLD)
1012         .set_iomux = rk29_sdmmc_set_iomux,
1013 #endif
1014
1015         .dma_name = "sd_mmc",
1016 #ifdef CONFIG_SDMMC0_USE_DMA
1017         .use_dma = 1,
1018 #else
1019         .use_dma = 0,
1020 #endif
1021
1022 #if defined(CONFIG_WIFI_COMBO_MODULE_CONTROL_FUNC) && defined(CONFIG_USE_SDMMC0_FOR_WIFI_DEVELOP_BOARD)
1023     .status = rk29sdk_wifi_mmc0_status,
1024     .register_status_notify = rk29sdk_wifi_mmc0_status_register,
1025 #endif
1026
1027 #if defined(RK29SDK_SD_CARD_PWR_EN) || (INVALID_GPIO != RK29SDK_SD_CARD_PWR_EN)
1028     .power_en = RK29SDK_SD_CARD_PWR_EN,
1029     .power_en_level = RK29SDK_SD_CARD_PWR_EN_LEVEL,
1030 #else
1031     .power_en = INVALID_GPIO,
1032     .power_en_level = GPIO_LOW,
1033 #endif    
1034         .enable_sd_wakeup = 0,
1035
1036 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
1037         .write_prt = SDMMC0_WRITE_PROTECT_PIN,
1038         .write_prt_enalbe_level = SDMMC0_WRITE_PROTECT_ENABLE_VALUE;
1039 #else
1040         .write_prt = INVALID_GPIO,
1041 #endif
1042
1043     .det_pin_info = {    
1044     #if defined(RK29SDK_SD_CARD_DETECT_N) || (INVALID_GPIO != RK29SDK_SD_CARD_DETECT_N)  
1045         .io             = RK29SDK_SD_CARD_DETECT_N, //INVALID_GPIO,
1046         .enable         = RK29SDK_SD_CARD_INSERT_LEVEL,
1047         #ifdef RK29SDK_SD_CARD_DETECT_PIN_NAME
1048         .iomux          = {
1049             .name       = RK29SDK_SD_CARD_DETECT_PIN_NAME,
1050             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO
1051             .fgpio      = RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO,
1052             #endif
1053             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FMUX
1054             .fmux       = RK29SDK_SD_CARD_DETECT_IOMUX_FMUX,
1055             #endif
1056         },
1057         #endif
1058     #else
1059         .io             = INVALID_GPIO,
1060         .enable         = GPIO_LOW,
1061     #endif    
1062     }, 
1063
1064 };
1065 #endif // CONFIG_SDMMC0_RK29
1066
1067 #ifdef CONFIG_SDMMC1_RK29
1068 #define CONFIG_SDMMC1_USE_DMA
1069 static int rk29_sdmmc1_cfg_gpio(void)
1070 {
1071 #if defined(CONFIG_SDMMC_RK29_OLD)
1072         iomux_set(MMC1_CMD);
1073         iomux_set(MMC1_CLKOUT);
1074         iomux_set(MMC1_D0);
1075         iomux_set(MMC1_D1);
1076         iomux_set(MMC1_D2);
1077         iomux_set(MMC1_D3);
1078 #else
1079
1080 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
1081         gpio_request(SDMMC1_WRITE_PROTECT_PIN, "sdio-wp");
1082         gpio_direction_input(SDMMC1_WRITE_PROTECT_PIN);
1083 #endif
1084
1085 #endif
1086
1087         return 0;
1088 }
1089
1090 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
1091         .host_ocr_avail =
1092             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
1093              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
1094              MMC_VDD_33_34),
1095
1096 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
1097         .host_caps = (MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ |
1098                       MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
1099 #else
1100         .host_caps =
1101             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
1102 #endif
1103
1104         .io_init = rk29_sdmmc1_cfg_gpio,
1105
1106 #if !defined(CONFIG_SDMMC_RK29_OLD)
1107         .set_iomux = rk29_sdmmc_set_iomux,
1108 #endif
1109
1110         .dma_name = "sdio",
1111 #ifdef CONFIG_SDMMC1_USE_DMA
1112         .use_dma = 1,
1113 #else
1114         .use_dma = 0,
1115 #endif
1116
1117 #if defined(CONFIG_WIFI_CONTROL_FUNC) || defined(CONFIG_WIFI_COMBO_MODULE_CONTROL_FUNC)
1118     .status = rk29sdk_wifi_status,
1119     .register_status_notify = rk29sdk_wifi_status_register,
1120 #endif
1121
1122 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
1123         .write_prt = SDMMC1_WRITE_PROTECT_PIN,
1124             .write_prt_enalbe_level = SDMMC1_WRITE_PROTECT_ENABLE_VALUE;
1125 #else
1126         .write_prt = INVALID_GPIO,
1127 #endif
1128
1129     #if defined(CONFIG_RK29_SDIO_IRQ_FROM_GPIO)
1130         .sdio_INT_gpio = RK29SDK_WIFI_SDIO_CARD_INT,
1131     #endif
1132
1133     .det_pin_info = {    
1134 #if defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
1135      #if defined(RK29SDK_SD_CARD_DETECT_N) || (INVALID_GPIO != RK29SDK_SD_CARD_DETECT_N)  
1136         .io             = RK29SDK_SD_CARD_DETECT_N,
1137      #else
1138          .io             = INVALID_GPIO,
1139      #endif   
1140
1141         .enable         = RK29SDK_SD_CARD_INSERT_LEVEL,
1142         #ifdef RK29SDK_SD_CARD_DETECT_PIN_NAME
1143         .iomux          = {
1144             .name       = RK29SDK_SD_CARD_DETECT_PIN_NAME,
1145             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO
1146             .fgpio      = RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO,
1147             #endif
1148             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FMUX
1149             .fmux       = RK29SDK_SD_CARD_DETECT_IOMUX_FMUX,
1150             #endif
1151         },
1152         #endif
1153  #else
1154         .io             = INVALID_GPIO,
1155         .enable         = GPIO_LOW,
1156 #endif
1157     },
1158    
1159         .enable_sd_wakeup = 0,
1160 };
1161 #endif //endif--#ifdef CONFIG_SDMMC1_RK29
1162
1163 /**************************************************************************************************
1164  * the end of setting for SDMMC devices
1165 **************************************************************************************************/
1166
1167 #ifdef CONFIG_BATTERY_RK30_ADC
1168 static struct rk30_adc_battery_platform_data rk30_adc_battery_platdata = {
1169         .dc_det_pin      = RK30_PIN0_PB2,
1170         .batt_low_pin    = RK30_PIN0_PB1, 
1171         .charge_set_pin  = INVALID_GPIO,
1172         .charge_ok_pin   = RK30_PIN0_PA6,
1173         .dc_det_level    = GPIO_LOW,
1174         .charge_ok_level = GPIO_HIGH,
1175 };
1176
1177 static struct platform_device rk30_device_adc_battery = {
1178         .name   = "rk30-battery",
1179         .id     = -1,
1180         .dev = {
1181                 .platform_data = &rk30_adc_battery_platdata,
1182         },
1183 };
1184 #endif
1185 #ifdef CONFIG_CW2015_BATTERY
1186 /*
1187    note the follow array must set depend on the battery that you use
1188    you must send the battery to cellwise-semi the contact information:
1189    name: chen gan; tel:13416876079; E-mail: ben.chen@cellwise-semi.com
1190  */
1191 static u8 config_info[SIZE_BATINFO] = {
1192         0x15, 0x42, 0x60, 0x59, 0x52,
1193         0x58, 0x4D, 0x48, 0x48, 0x44,
1194         0x44, 0x46, 0x49, 0x48, 0x32,
1195         0x24, 0x20, 0x17, 0x13, 0x0F,
1196         0x19, 0x3E, 0x51, 0x45, 0x08,
1197         0x76, 0x0B, 0x85, 0x0E, 0x1C,
1198         0x2E, 0x3E, 0x4D, 0x52, 0x52,
1199         0x57, 0x3D, 0x1B, 0x6A, 0x2D,
1200         0x25, 0x43, 0x52, 0x87, 0x8F,
1201         0x91, 0x94, 0x52, 0x82, 0x8C,
1202         0x92, 0x96, 0xFF, 0x7B, 0xBB,
1203         0xCB, 0x2F, 0x7D, 0x72, 0xA5,
1204         0xB5, 0xC1, 0x46, 0xAE
1205 };
1206
1207 static struct cw_bat_platform_data cw_bat_platdata = {
1208         .dc_det_pin      = RK30_PIN0_PB2,
1209         .dc_det_level    = GPIO_LOW,
1210
1211         .bat_low_pin    = RK30_PIN0_PB1,
1212         .bat_low_level  = GPIO_LOW,   
1213         .chg_ok_pin   = INVALID_GPIO,
1214         .chg_ok_level = GPIO_HIGH,
1215
1216         .is_usb_charge = 0,
1217         .chg_mode_sel_pin = INVALID_GPIO,
1218         .chg_mode_sel_level = GPIO_HIGH,
1219
1220         .cw_bat_config_info     = config_info,
1221
1222 };
1223
1224 #endif
1225 #ifdef CONFIG_RK30_PWM_REGULATOR
1226 static int pwm_voltage_map[] = {
1227         800000,825000,850000, 875000,900000, 925000 ,950000, 975000,1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000,1375000
1228 };
1229 static struct regulator_consumer_supply pwm_dcdc1_consumers[] = {
1230         {
1231                 .supply = "vdd_cpu",
1232         }
1233 };
1234
1235 struct regulator_init_data pwm_regulator_init_dcdc[1] =
1236 {
1237         {
1238                 .constraints = {
1239                         .name = "PWM_DCDC1",
1240                         .min_uV = 600000,
1241                         .max_uV = 1800000,      //0.6-1.8V
1242                         .apply_uV = true,
1243                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
1244                 },
1245                 .num_consumer_supplies = ARRAY_SIZE(pwm_dcdc1_consumers),
1246                 .consumer_supplies = pwm_dcdc1_consumers,
1247         },
1248 };
1249
1250 static struct pwm_platform_data pwm_regulator_info[1] = {
1251         {
1252                 .pwm_id = 1,
1253                 .pwm_gpio = RK30_PIN3_PD4,
1254                 .pwm_iomux_pwm = PWM1,
1255                 .pwm_iomux_gpio = GPIO3_D4,
1256                 .pwm_voltage = 1100000,
1257                 .suspend_voltage = 1000000,
1258                 .min_uV = 800000,
1259                 .max_uV = 1375000,
1260                 .coefficient = 575,     //57.5%
1261                 .pwm_voltage_map = pwm_voltage_map,
1262                 .init_data      = &pwm_regulator_init_dcdc[0],
1263         },
1264 };
1265
1266 struct platform_device pwm_regulator_device[1] = {
1267         {
1268                 .name = "pwm-voltage-regulator",
1269                 .id = 0,
1270                 .dev            = {
1271                         .platform_data = &pwm_regulator_info[0],
1272                 }
1273         },
1274 };
1275 #endif
1276
1277 #ifdef CONFIG_RK29_VMAC
1278 #define PHY_PWR_EN_GPIO RK30_PIN1_PD6
1279 #include "board-rk30-sdk-vmac.c"
1280 #endif
1281
1282 #ifdef CONFIG_RFKILL_RK
1283 // bluetooth rfkill device, its driver in net/rfkill/rfkill-rk.c
1284 static struct rfkill_rk_platform_data rfkill_rk_platdata = {
1285     .type               = RFKILL_TYPE_BLUETOOTH,
1286
1287     .poweron_gpio       = { // BT_REG_ON
1288         .io             = INVALID_GPIO, //RK30_PIN3_PC7,
1289         .enable         = GPIO_HIGH,
1290         .iomux          = {
1291             .name       = "bt_poweron",
1292             .fgpio      = GPIO3_C7,
1293         },
1294     },
1295
1296     .reset_gpio         = { // BT_RST
1297         .io             = RK30_PIN3_PC7, // set io to INVALID_GPIO for disable it
1298         .enable         = GPIO_LOW,
1299         .iomux          = {
1300             .name       = "bt_reset",
1301             .fgpio      = GPIO3_C7,
1302        },
1303    }, 
1304
1305     .wake_gpio          = { // BT_WAKE, use to control bt's sleep and wakeup
1306         .io             = RK30_PIN3_PC6, // set io to INVALID_GPIO for disable it
1307         .enable         = GPIO_HIGH,
1308         .iomux          = {
1309             .name       = "bt_wake",
1310             .fgpio      = GPIO3_C6,
1311         },
1312     },
1313
1314     .wake_host_irq      = { // BT_HOST_WAKE, for bt wakeup host when it is in deep sleep
1315         .gpio           = {
1316             .io         = RK30_PIN0_PA5, // set io to INVALID_GPIO for disable it
1317             .enable     = GPIO_LOW,      // set GPIO_LOW for falling, set 0 for rising
1318             .iomux      = {
1319                 .name   = NULL,
1320             },
1321         },
1322     },
1323
1324     .rts_gpio           = { // UART_RTS, enable or disable BT's data coming
1325         .io             = RK30_PIN1_PA3, // set io to INVALID_GPIO for disable it
1326         .enable         = GPIO_LOW,
1327         .iomux          = {
1328             .name       = "bt_rts",
1329             .fgpio      = GPIO1_A3,
1330             .fmux       = UART0_RTSN,
1331         },
1332     },
1333 };
1334
1335 static struct platform_device device_rfkill_rk = {
1336     .name   = "rfkill_rk",
1337     .id     = -1,
1338     .dev    = {
1339         .platform_data = &rfkill_rk_platdata,
1340     },
1341 };
1342 #endif
1343
1344 #if defined(CONFIG_GPS_RK)
1345 int rk_gps_io_init(void)
1346 {
1347         printk("%s \n", __FUNCTION__);
1348         
1349         gpio_request(RK30_PIN1_PB5, NULL);
1350         gpio_direction_output(RK30_PIN1_PB5, GPIO_LOW);
1351
1352         iomux_set(GPS_RFCLK);//GPS_CLK
1353         iomux_set(GPS_MAG);//GPS_MAG
1354         iomux_set(GPS_SIG);//GPS_SIGN
1355
1356         gpio_request(RK30_PIN1_PA6, NULL);
1357         gpio_direction_output(RK30_PIN1_PA6, GPIO_LOW);
1358
1359         gpio_request(RK30_PIN1_PA5, NULL);
1360         gpio_direction_output(RK30_PIN1_PA5, GPIO_LOW); 
1361
1362         gpio_request(RK30_PIN1_PA7, NULL);
1363         gpio_direction_output(RK30_PIN1_PA7, GPIO_LOW);         
1364         return 0;
1365 }
1366 int rk_gps_power_up(void)
1367 {
1368         printk("%s \n", __FUNCTION__);
1369
1370         return 0;
1371 }
1372
1373 int rk_gps_power_down(void)
1374 {
1375         printk("%s \n", __FUNCTION__);
1376
1377         return 0;
1378 }
1379
1380 int rk_gps_reset_set(int level)
1381 {
1382         return 0;
1383 }
1384 int rk_enable_hclk_gps(void)
1385 {
1386         struct clk *gps_aclk = NULL;
1387         gps_aclk = clk_get(NULL, "aclk_gps");
1388         if(gps_aclk) {
1389                 clk_enable(gps_aclk);
1390                 clk_put(gps_aclk);
1391                 printk("%s \n", __FUNCTION__);
1392         }
1393         else
1394                 printk("get gps aclk fail\n");
1395         return 0;
1396 }
1397 int rk_disable_hclk_gps(void)
1398 {
1399         struct clk *gps_aclk = NULL;
1400         gps_aclk = clk_get(NULL, "aclk_gps");
1401         if(gps_aclk) {
1402                 //TO wait long enough until GPS ISR is finished.
1403                 msleep(5);
1404                 clk_disable(gps_aclk);
1405                 clk_put(gps_aclk);
1406                 printk("%s \n", __FUNCTION__);
1407         }       
1408         else
1409                 printk("get gps aclk fail\n");
1410         return 0;
1411 }
1412 struct rk_gps_data rk_gps_info = {
1413         .io_init = rk_gps_io_init,
1414         .power_up = rk_gps_power_up,
1415         .power_down = rk_gps_power_down,
1416         .reset = rk_gps_reset_set,
1417         .enable_hclk_gps = rk_enable_hclk_gps,
1418         .disable_hclk_gps = rk_disable_hclk_gps,
1419         .GpsSign = RK30_PIN1_PB3,
1420         .GpsMag = RK30_PIN1_PB2,        //GPIO index
1421         .GpsClk = RK30_PIN1_PB4,        //GPIO index
1422         .GpsVCCEn = RK30_PIN1_PB5,     //GPIO index
1423         .GpsSpi_CSO = RK30_PIN1_PA4,    //GPIO index
1424         .GpsSpiClk = RK30_PIN1_PA5,     //GPIO index
1425         .GpsSpiMOSI = RK30_PIN1_PA7,      //GPIO index
1426         .GpsIrq = IRQ_GPS,
1427         .GpsSpiEn = 0,
1428         .GpsAdcCh = 2,
1429         .u32GpsPhyAddr = RK30_GPS_PHYS,
1430         .u32GpsPhySize = RK30_GPS_SIZE,
1431 };
1432
1433 struct platform_device rk_device_gps = {
1434         .name = "gps_hv5820b",
1435         .id = -1,
1436         .dev            = {
1437         .platform_data = &rk_gps_info,
1438                 }
1439         };
1440 #endif
1441
1442 #if defined(CONFIG_MT5931_MT6622)
1443 static struct mt6622_platform_data mt6622_platdata = {
1444                     .power_gpio         = { // BT_REG_ON
1445                         .io             = RK30_PIN3_PD5, // set io to INVALID_GPIO for disable it
1446                             .enable         = GPIO_HIGH,
1447                             .iomux          = {
1448                                     .name       = NULL,
1449                                 },
1450                     },
1451
1452                     .reset_gpio         = { // BT_RST
1453                         .io             = RK30_PIN0_PD7,
1454                         .enable         = GPIO_HIGH,
1455                         .iomux          = {
1456                             .name       = NULL,
1457                         },
1458                     },
1459
1460                     .irq_gpio           = {
1461                             .io             = RK30_PIN3_PD2,
1462                             .enable         = GPIO_HIGH,
1463                             .iomux          = {
1464                                     .name       = NULL,
1465                                 },
1466                     },
1467
1468                     .rts_gpio           = { // UART_RTS
1469                             .io             = RK30_PIN1_PA3,
1470                             .enable         = GPIO_LOW,
1471                                     .iomux          = {
1472                                     .name       = "bt_rts",
1473                                     .fgpio      = GPIO1_A3,
1474                                     .fmux       = UART0_RTSN,
1475                             },
1476                     },
1477 };
1478
1479 static struct platform_device device_mt6622 = {
1480                     .name   = "mt6622",
1481                         .id     = -1,
1482                         .dev    = {
1483                                .platform_data = &mt6622_platdata,
1484                         },
1485 };      
1486 #endif
1487
1488 static struct platform_device *devices[] __initdata = {
1489 #ifdef CONFIG_ION
1490         &device_ion,
1491 #endif
1492 #ifdef CONFIG_ANDROID_TIMED_GPIO
1493         &rk29_device_vibrator,
1494 #endif
1495 #ifdef CONFIG_LEDS_GPIO_PLATFORM
1496         &rk29_device_gpio_leds,
1497 #endif
1498 #ifdef CONFIG_RK_IRDA
1499         &irda_device,
1500 #endif
1501 #if defined(CONFIG_WIFI_CONTROL_FUNC)||defined(CONFIG_WIFI_COMBO_MODULE_CONTROL_FUNC)
1502         &rk29sdk_wifi_device,
1503 #endif
1504
1505 #if defined(CONFIG_MT6620)
1506     &mt3326_device_gps,
1507 #endif   
1508
1509 #ifdef CONFIG_RK29_SUPPORT_MODEM
1510         &rk30_device_modem,
1511 #endif
1512 #if defined(CONFIG_MU509)
1513         &rk29_device_mu509,
1514 #endif
1515 #if defined(CONFIG_MW100)
1516         &rk29_device_mw100,
1517 #endif
1518 #if defined(CONFIG_MT6229)
1519         &rk29_device_mt6229,
1520 #endif
1521 #ifdef CONFIG_BATTERY_RK30_ADC
1522         &rk30_device_adc_battery,
1523 #endif
1524 #ifdef CONFIG_RFKILL_RK
1525         &device_rfkill_rk,
1526 #endif
1527 #ifdef CONFIG_GPS_RK
1528         &rk_device_gps,
1529 #endif
1530 #if defined(CONFIG_ARCH_RK3188)
1531         &device_mali,
1532 #endif
1533 #ifdef CONFIG_MT5931_MT6622
1534         &device_mt6622,
1535 #endif
1536 };
1537
1538 static int rk_platform_add_display_devices(void)
1539 {
1540         struct platform_device *fb = NULL;  //fb
1541         struct platform_device *lcdc0 = NULL; //lcdc0
1542         struct platform_device *lcdc1 = NULL; //lcdc1
1543         struct platform_device *bl = NULL; //backlight
1544 #ifdef CONFIG_FB_ROCKCHIP
1545         fb = &device_fb;
1546 #endif
1547
1548 #if defined(CONFIG_LCDC0_RK3066B) || defined(CONFIG_LCDC0_RK3188)
1549         lcdc0 = &device_lcdc0,
1550 #endif
1551
1552 #if defined(CONFIG_LCDC1_RK3066B) || defined(CONFIG_LCDC1_RK3188)
1553         lcdc1 = &device_lcdc1,
1554 #endif
1555
1556 #ifdef CONFIG_BACKLIGHT_RK29_BL
1557         bl = &rk29_device_backlight,
1558 #endif
1559         __rk_platform_add_display_devices(fb,lcdc0,lcdc1,bl);
1560
1561         return 0;
1562         
1563 }
1564
1565 // i2c
1566 #ifdef CONFIG_I2C0_RK30
1567 static struct i2c_board_info __initdata i2c0_info[] = {
1568 #if defined (CONFIG_GS_MMA8452)
1569         {
1570                 .type           = "gs_mma8452",
1571                 .addr           = 0x1d,
1572                 .flags          = 0,
1573                 .irq            = MMA8452_INT_PIN,
1574                 .platform_data = &mma8452_info,
1575         },
1576 #endif
1577 #if defined (CONFIG_GS_LIS3DH)
1578         {
1579                 .type           = "gs_lis3dh",
1580                 .addr           = 0x19,   //0x19(SA0-->VCC), 0x18(SA0-->GND)
1581                 .flags          = 0,
1582                 .irq            = LIS3DH_INT_PIN,
1583                 .platform_data = &lis3dh_info,
1584         },
1585 #endif
1586 #if defined (CONFIG_COMPASS_AK8975)
1587         {
1588                 .type          = "ak8975",
1589                 .addr          = 0x0d,
1590                 .flags         = 0,
1591                 .irq           = RK30_PIN3_PD7, 
1592                 .platform_data = &akm8975_info,
1593         },
1594 #endif
1595 #if defined (CONFIG_GYRO_L3G4200D)
1596         {
1597                 .type          = "l3g4200d_gryo",
1598                 .addr          = 0x69,
1599                 .flags         = 0,
1600                 .irq           = L3G4200D_INT_PIN,
1601                 .platform_data = &l3g4200d_info,
1602         },
1603 #endif
1604 #if defined (CONFIG_SND_SOC_RK1000)
1605         {
1606                 .type          = "rk1000_i2c_codec",
1607                 .addr          = 0x60,
1608                 .flags         = 0,
1609         },
1610         {
1611                 .type          = "rk1000_control",
1612                 .addr          = 0x40,
1613                 .flags         = 0,
1614         },
1615 #endif
1616
1617 #if defined (CONFIG_SND_SOC_RT5631)
1618         {
1619                 .type                   = "rt5631",
1620                 .addr                   = 0x1a,
1621                 .flags                  = 0,
1622         },
1623 #endif
1624
1625 #if defined (CONFIG_SND_SOC_RT5512)
1626         {
1627                 .type                   = "rt5512",
1628                 .addr                   = 0x18,
1629                 .flags                  = 0,
1630         },
1631 #endif
1632
1633 #if defined (CONFIG_SND_SOC_CX2070X)
1634         {
1635                 .type                   = "cx2070x",
1636                 .addr                   = 0x14,
1637                 .flags                  = 0,
1638         },
1639 #endif
1640
1641 #if defined (CONFIG_SND_SOC_RT5640) 
1642             {
1643                         .type                   = "rt5640",
1644                         .addr                   = 0x1c,
1645                         .flags                  = 0,
1646                 },
1647 #endif
1648
1649 #ifdef CONFIG_MFD_RK610
1650                 {
1651                         .type                   = "rk610_ctl",
1652                         .addr                   = 0x40,
1653                         .flags                  = 0,
1654                         .platform_data          = &rk610_ctl_pdata,
1655                 },
1656 #ifdef CONFIG_RK610_TVOUT
1657                 {
1658                         .type                   = "rk610_tvout",
1659                         .addr                   = 0x42,
1660                         .flags                  = 0,
1661                 },
1662 #endif
1663 #ifdef CONFIG_HDMI_RK610
1664                 {
1665                         .type                   = "rk610_hdmi",
1666                         .addr                   = 0x46,
1667                         .flags                  = 0,
1668                         .irq                    = INVALID_GPIO,
1669                 },
1670 #endif
1671 #ifdef CONFIG_SND_SOC_RK610
1672                 {//RK610_CODEC addr  from 0x60 to 0x80 (0x60~0x80)
1673                         .type                   = "rk610_i2c_codec",
1674                         .addr                   = 0x60,
1675                         .flags                  = 0,
1676                         .platform_data          = &rk610_codec_pdata,                                   
1677                 },
1678 #endif
1679 #endif
1680
1681 };
1682 #endif
1683
1684 int __sramdata g_pmic_type =  0;
1685 #ifdef CONFIG_I2C1_RK30
1686 #ifdef CONFIG_MFD_WM831X_I2C
1687 #define PMU_POWER_SLEEP                 RK30_PIN0_PA1 
1688
1689 static struct pmu_info  wm8326_dcdc_info[] = {
1690         {
1691                 .name          = "vdd_core",   //logic
1692                 .min_uv          = 1000000,
1693                 .max_uv         = 1000000,
1694                 .suspend_vol  =  950000,
1695         },
1696         {
1697                 .name          = "vdd_cpu",    //arm
1698                 .min_uv          = 1000000,
1699                 .max_uv         = 1000000,
1700                 .suspend_vol  =  950000,
1701         },
1702         {
1703                 .name          = "dcdc3",   //ddr
1704                 .min_uv          = 1150000,
1705                 .max_uv         = 1150000,
1706                 .suspend_vol  =  1150000,
1707         },
1708         #ifdef CONFIG_MACH_RK3066_SDK
1709         {
1710                 .name          = "dcdc4",   //vcc_io
1711                 .min_uv          = 3300000,
1712                 .max_uv         = 3300000,
1713                 .suspend_vol  =  3000000,
1714         },
1715         #else
1716         {
1717                 .name          = "dcdc4",   //vcc_io
1718                 .min_uv          = 3000000,
1719                 .max_uv         = 3000000,
1720                 .suspend_vol  =  2800000,
1721         },
1722         #endif
1723 };
1724
1725 static struct pmu_info  wm8326_ldo_info[] = {
1726         {
1727                 .name          = "ldo1",   //vcc18_cif
1728                 .min_uv          = 1800000,
1729                 .max_uv         = 1800000,
1730                 .suspend_vol  =  1800000,
1731         },
1732         {
1733                 .name          = "ldo2",    //vccio_wl
1734                 .min_uv          = 1800000,
1735                 .max_uv         = 1800000,
1736                 .suspend_vol  =  1800000,
1737         },
1738         {
1739                 .name          = "ldo3",   //
1740                 .min_uv          = 1100000,
1741                 .max_uv         = 1100000,
1742                 .suspend_vol  =  1100000,
1743         },
1744         {
1745                 .name          = "ldo4",   //vdd11
1746                 .min_uv          = 1000000,
1747                 .max_uv         = 1000000,
1748                 .suspend_vol  =  1000000,
1749         },
1750         {
1751                 .name          = "ldo5",   //vcc25
1752                 .min_uv          = 1800000,
1753                 .max_uv         = 1800000,
1754                 .suspend_vol  =  1800000,
1755         },
1756         {
1757                 .name          = "ldo6",   //vcc33
1758                 .min_uv          = 3300000,
1759                 .max_uv         = 3300000,
1760                 .suspend_vol  =  3300000,
1761         },
1762         {
1763                 .name          = "ldo7",   //vcc28_cif
1764                 .min_uv          = 2800000,
1765                 .max_uv         = 2800000,
1766                 .suspend_vol  =  2800000,
1767         },
1768         {
1769                 .name          = "ldo8",   //vcca33
1770                 .min_uv          = 3300000,
1771                 .max_uv         = 3300000,
1772                 .suspend_vol  =  3300000,
1773         },
1774         {
1775                 .name          = "ldo9",   //vcc_tp
1776                 .min_uv          = 3300000,
1777                 .max_uv         = 3300000,
1778                 .suspend_vol  =  3300000,
1779         },
1780         {
1781                 .name          = "ldo10",   //flash_io
1782                 .min_uv          = 1800000,
1783                 .max_uv         = 1800000,
1784                 .suspend_vol  =  1800000,
1785         },
1786 };
1787
1788 #include "board-pmu-wm8326.c"
1789 #endif
1790
1791 #ifdef CONFIG_MFD_TPS65910
1792 #define TPS65910_HOST_IRQ        RK30_PIN0_PB3
1793
1794 #define PMU_POWER_SLEEP RK30_PIN0_PA1
1795
1796 static struct pmu_info  tps65910_dcdc_info[] = {
1797         {
1798                 .name          = "vdd_core",   //logic
1799                 .min_uv          = 1200000,
1800                 .max_uv         = 1200000,
1801         },
1802         {
1803                 .name          = "vdd2",    //ddr
1804                 .min_uv          = 1200000,
1805                 .max_uv         = 1200000,
1806         },
1807         {
1808                 .name          = "vio",   //vcc_io
1809                 .min_uv          = 2500000,
1810                 .max_uv         = 2500000,
1811         },
1812         
1813 };
1814 static  struct pmu_info  tps65910_ldo_info[] = {
1815         {
1816                 .name          = "vpll",   //vdd10
1817                 .min_uv          = 1000000,
1818                 .max_uv         = 1000000,
1819         },
1820         {
1821                 .name          = "vdig1",    //vcc18_cif
1822                 .min_uv          = 1800000,
1823                 .max_uv         = 1800000,
1824         },
1825         {
1826                 .name          = "vdig2",   //vdd_jetta
1827                 .min_uv          = 1200000,
1828                 .max_uv         = 1200000,
1829         },
1830         {
1831                 .name          = "vaux1",   //vcc28_cif
1832                 .min_uv          = 2800000,
1833                 .max_uv         = 2800000,
1834         },
1835         {
1836                 .name          = "vaux2",   //vcca33
1837                 .min_uv          = 3300000,
1838                 .max_uv         = 3300000,
1839         },
1840         {
1841                 .name          = "vaux33",   //vcc_tp
1842                 .min_uv          = 3300000,
1843                 .max_uv         = 3300000,
1844         },
1845         {
1846                 .name          = "vmmc",   //vcc30
1847                 .min_uv          = 3000000,
1848                 .max_uv         = 3000000,
1849         },
1850         {
1851                 .name          = "vdac",   //vcc18
1852                 .min_uv          = 1800000,
1853                 .max_uv         = 1800000,
1854         },
1855  };
1856
1857 #include "board-pmu-tps65910.c"
1858 #endif
1859
1860 #ifdef CONFIG_REGULATOR_ACT8846
1861 #define PMU_POWER_SLEEP RK30_PIN0_PA1
1862 #define PMU_VSEL RK30_PIN3_PD3
1863 static struct pmu_info  act8846_dcdc_info[] = {
1864         {
1865                 .name          = "act_dcdc1",   //ddr
1866                 .min_uv          = 1200000,
1867                 .max_uv         = 1200000,
1868                 .suspend_vol  =  1200000,
1869         },
1870         {
1871                 .name          = "vdd_core",    //logic
1872                 .min_uv          = 1000000,
1873                 .max_uv         = 1000000,
1874                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1875                 .suspend_vol  =  1200000,
1876                 #else
1877                 .suspend_vol  =  900000,
1878                 #endif
1879
1880         },
1881         {
1882                 .name          = "vdd_cpu",   //arm
1883                 .min_uv          = 1000000,
1884                 .max_uv         = 1000000,
1885                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1886                 .suspend_vol  =  1200000,
1887                 #else
1888                 .suspend_vol  =  900000,
1889                 #endif
1890
1891         },
1892         {
1893                 .name          = "act_dcdc4",   //vccio
1894                 .min_uv          = 3000000,
1895                 .max_uv         = 3000000,
1896                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1897                 .suspend_vol  =  3000000,
1898                 #else
1899                 .suspend_vol  =  2800000,
1900                 #endif
1901
1902         },
1903         
1904 };
1905 static  struct pmu_info  act8846_ldo_info[] = {
1906         {
1907                 .name          = "act_ldo1",   //vdd11
1908                 .min_uv          = 1000000,
1909                 .max_uv         = 1000000,
1910         },
1911         {
1912                 .name          = "act_ldo2",    //vdd12
1913                 .min_uv          = 1200000,
1914                 .max_uv         = 1200000,
1915         },
1916         {
1917                 .name          = "act_ldo3",   //vcc18_cif
1918                 .min_uv          = 1800000,
1919                 .max_uv         = 1800000,
1920         },
1921         {
1922                 .name          = "act_ldo4",   //vcca33
1923                 .min_uv          = 3300000,
1924                 .max_uv         = 3300000,
1925         },
1926         {
1927                 .name          = "act_ldo5",   //vcctp
1928                 .min_uv          = 3300000,
1929                 .max_uv         = 3300000,
1930         },
1931         {
1932                 .name          = "act_ldo6",   //vcc33
1933                 .min_uv          = 3300000,
1934                 .max_uv         = 3300000,
1935         },
1936         {
1937                 .name          = "act_ldo7",   //vccio_wl
1938                 .min_uv          = 1800000,
1939                 .max_uv         = 1800000,
1940         },
1941         {
1942                 .name          = "act_ldo8",   //vcc28_cif
1943                 .min_uv          = 2800000,
1944                 .max_uv         = 2800000,
1945         },
1946  };
1947
1948 #include "board-pmu-act8846.c"
1949 #endif
1950
1951 #ifdef CONFIG_MFD_RK808
1952 #define PMU_POWER_SLEEP RK30_PIN0_PA1
1953 #define RK808_HOST_IRQ        RK30_PIN0_PB3
1954
1955 static struct pmu_info  rk808_dcdc_info[] = {
1956         {
1957                 .name          = "vdd_cpu",   //arm
1958                 .min_uv          = 1000000,
1959                 .max_uv         = 1000000,
1960                 .suspend_vol  =  900000,
1961         },
1962         {
1963                 .name          = "vdd_core",    //logic
1964                 .min_uv          = 1000000,
1965                 .max_uv         = 1000000,
1966                 .suspend_vol  =  900000,
1967         },
1968         {
1969                 .name          = "rk_dcdc3",   //ddr
1970                 .min_uv          = 1200000,
1971                 .max_uv         = 1200000,
1972                 .suspend_vol  =  1200000,
1973         },
1974         {
1975                 .name          = "rk_dcdc4",   //vccio
1976                 .min_uv          = 3300000,
1977                 .max_uv         = 3300000,
1978                 .suspend_vol  =  3000000,
1979         },
1980         
1981 };
1982 static  struct pmu_info  rk808_ldo_info[] = {
1983         {
1984                 .name          = "rk_ldo1",   //vcc33
1985                 .min_uv          = 3300000,
1986                 .max_uv         = 3300000,
1987                 .suspend_vol   = 3300000,
1988         },
1989         {
1990                 .name          = "rk_ldo2",    //vcctp
1991                 .min_uv          = 3300000,
1992                 .max_uv         = 3300000,
1993                  .suspend_vol   = 3300000,
1994
1995         },
1996         {
1997                 .name          = "rk_ldo3",   //vdd10
1998                 .min_uv          = 1000000,
1999                 .max_uv         = 1000000,
2000                  .suspend_vol   = 1000000,
2001         },
2002         {
2003                 .name          = "rk_ldo4",   //vcc18
2004                 .min_uv          = 1800000,
2005                 .max_uv         = 1800000,
2006                  .suspend_vol   = 1800000,
2007         },
2008         {
2009                 .name          = "rk_ldo5",   //vcc28_cif
2010                 .min_uv          = 2800000,
2011                 .max_uv         = 2800000,
2012                  .suspend_vol   = 2800000,
2013         },
2014         {
2015                 .name          = "rk_ldo6",   //vdd12
2016                 .min_uv          = 1200000,
2017                 .max_uv         = 1200000,
2018                  .suspend_vol   = 1200000,
2019         },
2020         {
2021                 .name          = "rk_ldo7",   //vcc18_cif
2022                 .min_uv          = 1800000,
2023                 .max_uv         = 1800000,
2024                  .suspend_vol   = 1800000,
2025         },
2026         {
2027                 .name          = "rk_ldo8",   //vcca_33
2028                 .min_uv          = 3300000,
2029                 .max_uv         = 3300000,
2030                  .suspend_vol   = 3300000,
2031         },
2032  };
2033
2034 #include "board-pmu-rk808.c"
2035 #endif
2036 #ifdef CONFIG_MFD_RICOH619
2037 #define PMU_POWER_SLEEP RK30_PIN0_PA1
2038 #define RICOH619_HOST_IRQ        RK30_PIN0_PB3
2039
2040 static struct pmu_info  ricoh619_dcdc_info[] = {
2041         {
2042                 .name          = "vdd_cpu",   //arm
2043                 .min_uv          = 1000000,
2044                 .max_uv         = 1000000,
2045                 .suspend_vol  =  900000,
2046         },
2047         {
2048                 .name          = "vdd_core",    //logic
2049                 .min_uv          = 1000000,
2050                 .max_uv         = 1000000,
2051                 .suspend_vol  =  900000,
2052         },
2053         
2054         {
2055                 .name          = "ricoh_dc3",   //vcc18
2056                 .min_uv          = 1800000,
2057                 .max_uv         = 1800000,
2058                 .suspend_vol  =  1800000,
2059         },
2060         
2061         {
2062                 .name          = "ricoh_dc4",   //vccio
2063                 .min_uv          = 3300000,
2064                 .max_uv         = 3300000,
2065                 .suspend_vol  =  3300000,
2066         },
2067
2068         {
2069                 .name          = "ricoh_dc5",   //ddr
2070                 .min_uv          = 1200000,
2071                 .max_uv         = 1200000,
2072                 .suspend_vol  =  1200000,
2073         },
2074         
2075 };
2076 static  struct pmu_info  ricoh619_ldo_info[] = {
2077         {
2078                 .name          = "ricoh_ldo1",   //vcc30
2079                 .min_uv          = 3000000,
2080                 .max_uv         = 3000000,
2081         },
2082         {
2083                 .name          = "ricoh_ldo2",    //vcca33
2084                 .min_uv          = 3300000,
2085                 .max_uv         = 3300000,
2086         },
2087         {
2088                 .name          = "ricoh_ldo3",   //vcctp
2089                 .min_uv          = 3300000,
2090                 .max_uv         = 3300000,
2091         },
2092         {
2093                 .name          = "ricoh_ldo4",   //vccsd
2094                 .min_uv          = 3300000,
2095                 .max_uv         = 3300000,
2096         },
2097         {
2098                 .name          = "ricoh_ldo5",   //vcc18_cif
2099                 .min_uv          = 1800000,
2100                 .max_uv         = 1800000,
2101         },
2102         {
2103                 .name          = "ricoh_ldo6",   //vdd12
2104                 .min_uv          = 1200000,
2105                 .max_uv         = 1200000,
2106         },
2107         {
2108                 .name          = "ricoh_ldo7",   //vcc28_cif
2109                 .min_uv          = 2800000,
2110                 .max_uv         = 2800000,
2111         },
2112         {
2113                 .name          = "ricoh_ldo8",   //vcc25
2114                 .min_uv          = 2500000,
2115                 .max_uv         = 2500000,
2116         },
2117         {
2118                 .name          = "ricoh_ldo9",   //vdd10
2119                 .min_uv          = 1000000,
2120                 .max_uv         = 1000000,
2121         },
2122         {
2123                 .name          = "ricoh_ldo10",   //vcca18
2124                 .min_uv          = 1800000,
2125                 .max_uv         = 1800000,
2126         },      
2127         
2128  };
2129
2130 #include "board-pmu-ricoh619.c"
2131 #endif
2132
2133 #ifdef CONFIG_MFD_RT5025
2134 #define RT5025_HOST_IRQ        RK30_PIN0_PB3
2135
2136 static struct pmu_info  rt5025_dcdc_info[] = {
2137         {
2138                 .name          = "vdd_cpu",   //arm
2139                 .min_uv          = 1000000,
2140                 .max_uv         = 1000000,
2141         },
2142         {
2143                 .name          = "vdd_core",    //logic
2144                 .min_uv          = 1000000,
2145                 .max_uv         = 1000000,
2146         },
2147         
2148         {
2149                 .name          = "rt5025-dcdc3",   //vccio
2150                 .min_uv          = 3300000,
2151                 .max_uv         = 3300000,
2152         },
2153         
2154         {
2155                 .name          = "rt5025-dcdc4",   //vccio
2156                 .min_uv         = 5000000,
2157                 .max_uv         = 5000000,
2158         },
2159         
2160 };
2161 static  struct pmu_info  rt5025_ldo_info[] = {
2162         {
2163                 .name          = "rt5025-ldo1",   //vcc18
2164                 .min_uv          = 1800000,
2165                 .max_uv         = 1800000,
2166         },
2167         {
2168                 .name          = "rt5025-ldo2",    //vddjetta
2169                 .min_uv          = 1200000,
2170                 .max_uv         = 1200000,
2171         },
2172         {
2173                 .name          = "rt5025-ldo3",   //vdd10
2174                 .min_uv          = 1000000,
2175                 .max_uv         = 1000000,
2176         },
2177         {
2178                 .name          = "rt5025-ldo4",   //vccjetta
2179                 .min_uv          = 3300000,
2180                 .max_uv         = 3300000,
2181         },
2182         {
2183                 .name          = "rt5025-ldo5",   //vccio_wl
2184                 .min_uv          = 1800000,
2185                 .max_uv         = 1800000,
2186         },
2187         {
2188                 .name          = "rt5025-ldo6",   //vcc_tp
2189                 .min_uv          = 3300000,
2190                 .max_uv         = 3300000,
2191         },      
2192         
2193  };
2194
2195 #include "board-pmu-rt5025.c"
2196 #endif
2197
2198
2199
2200 static struct i2c_board_info __initdata i2c1_info[] = {
2201 #if defined (CONFIG_MFD_WM831X_I2C)
2202         {
2203                 .type          = "wm8326",
2204                 .addr          = 0x34,
2205                 .flags         = 0,
2206                 .irq           = RK30_PIN0_PB3,
2207                 .platform_data = &wm831x_platdata,
2208         },
2209 #endif
2210 #if defined (CONFIG_MFD_TPS65910)
2211         {
2212         .type           = "tps65910",
2213         .addr           = TPS65910_I2C_ID0,
2214         .flags          = 0,
2215         .irq            = TPS65910_HOST_IRQ,
2216         .platform_data = &tps65910_data,
2217         },
2218 #endif
2219
2220 #if defined (CONFIG_REGULATOR_ACT8846)
2221         {
2222                 .type                   = "act8846",
2223                 .addr           = 0x5a, 
2224                 .flags                  = 0,
2225         //      .irq            = ACT8846_HOST_IRQ,
2226                 .platform_data=&act8846_data,
2227         },
2228 #endif
2229 #if defined (CONFIG_MFD_RK808)
2230         {
2231                 .type                   = "rk808",
2232                 .addr           = 0x1b, 
2233                 .flags                  = 0,
2234         //      .irq            = ACT8846_HOST_IRQ,
2235                 .platform_data=&rk808_data,
2236         },
2237 #endif
2238
2239 #if defined (CONFIG_MFD_RICOH619)
2240         {
2241                 .type                   = "ricoh619",
2242                 .addr           = 0x32,
2243                 .flags                  = 0,
2244                .irq            = RICOH619_HOST_IRQ,
2245                .platform_data=&ricoh619_data,
2246         },
2247 #endif
2248
2249 #if defined (CONFIG_MFD_RT5025)
2250         {
2251                 .type                   = "RT5025",
2252                 .addr           = 0x35,
2253                 .flags                  = 0,
2254                .irq            = RT5025_HOST_IRQ,
2255                .platform_data=&rt5025_data,
2256         },
2257 #endif
2258
2259 #if defined (CONFIG_RTC_HYM8563)
2260         {
2261                 .type                   = "rtc_hym8563",
2262                 .addr           = 0x51,
2263                 .flags                  = 0,
2264                 .irq            = RK30_PIN1_PA4,
2265         },
2266 #if defined (CONFIG_CW2015_BATTERY)
2267         {
2268                 .type           = "cw201x",
2269                 .addr           = 0x62,
2270                 .flags          = 0,
2271                 .platform_data  = &cw_bat_platdata,
2272         },
2273 #endif
2274 #endif
2275
2276 };
2277 #endif
2278
2279 void __sramfunc board_pmu_suspend(void)
2280 {      
2281 #if defined (CONFIG_MFD_WM831X_I2C)
2282         if(pmic_is_wm8326())
2283         board_pmu_wm8326_suspend();
2284 #endif
2285 #if defined (CONFIG_MFD_TPS65910)
2286         if(pmic_is_tps65910())
2287         board_pmu_tps65910_suspend(); 
2288 #endif   
2289 #if defined (CONFIG_REGULATOR_ACT8846)
2290         if(pmic_is_act8846())
2291         board_pmu_act8846_suspend(); 
2292 #endif   
2293 #if defined (CONFIG_MFD_RK808)
2294         if(pmic_is_rk808())
2295         board_pmu_rk808_suspend();
2296 #endif
2297 #if defined (CONFIG_MFD_RICOH619)
2298         if(pmic_is_ricoh619())
2299         board_pmu_ricoh619_suspend(); 
2300 #endif 
2301
2302 }
2303
2304 void __sramfunc board_pmu_resume(void)
2305 {      
2306 #if defined (CONFIG_MFD_WM831X_I2C)
2307         if(pmic_is_wm8326())
2308         board_pmu_wm8326_resume();
2309 #endif
2310 #if defined (CONFIG_MFD_TPS65910)
2311         if(pmic_is_tps65910())
2312         board_pmu_tps65910_resume(); 
2313 #endif
2314 #if defined (CONFIG_REGULATOR_ACT8846)
2315         if(pmic_is_act8846())
2316         board_pmu_act8846_resume(); 
2317 #endif 
2318 #if defined (CONFIG_MFD_RK808)
2319         if(pmic_is_rk808())
2320         board_pmu_rk808_resume();
2321 #endif
2322 #if defined (CONFIG_MFD_RICOH619)
2323         if(pmic_is_ricoh619())
2324         board_pmu_ricoh619_resume(); 
2325 #endif  
2326   
2327 }
2328
2329  int __sramdata gpio3d6_iomux,gpio3d6_do,gpio3d6_dir,gpio3d6_en;
2330
2331 #define grf_readl(offset)       readl_relaxed(RK30_GRF_BASE + offset)
2332 #define grf_writel(v, offset)   do { writel_relaxed(v, RK30_GRF_BASE + offset); dsb(); } while (0)
2333  
2334 void __sramfunc rk30_pwm_logic_suspend_voltage(void)
2335 {
2336 #ifdef CONFIG_RK30_PWM_REGULATOR
2337
2338 //      int gpio0d7_iomux,gpio0d7_do,gpio0d7_dir,gpio0d7_en;
2339         sram_udelay(10000);
2340         gpio3d6_iomux = grf_readl(GRF_GPIO3D_IOMUX);
2341         gpio3d6_do = grf_readl(GRF_GPIO3H_DO);
2342         gpio3d6_dir = grf_readl(GRF_GPIO3H_DIR);
2343         gpio3d6_en = grf_readl(GRF_GPIO3H_EN);
2344
2345         grf_writel((0x03000300), GRF_GPIO3D_IOMUX);
2346         grf_writel((1<<28)|(1<<12), GRF_GPIO3H_DIR);
2347         grf_writel((1<<28)|(1<<12), GRF_GPIO3H_DO);
2348         grf_writel((1<<28)|(1<<12), GRF_GPIO3H_EN);
2349 #endif 
2350 }
2351 void __sramfunc rk30_pwm_logic_resume_voltage(void)
2352 {
2353 #ifdef CONFIG_RK30_PWM_REGULATOR
2354         grf_writel((1<<28)|gpio3d6_iomux, GRF_GPIO3D_IOMUX);
2355         grf_writel((1<<30)|gpio3d6_en, GRF_GPIO3H_EN);
2356         grf_writel((1<<30)|gpio3d6_dir, GRF_GPIO3H_DIR);
2357         grf_writel((1<<30)|gpio3d6_do, GRF_GPIO3H_DO);
2358         sram_udelay(10000);
2359
2360 #endif
2361
2362 }
2363 extern void pwm_suspend_voltage(void);
2364 extern void pwm_resume_voltage(void);
2365 void  rk30_pwm_suspend_voltage_set(void)
2366 {
2367 #ifdef CONFIG_RK30_PWM_REGULATOR
2368         pwm_suspend_voltage();
2369 #endif
2370 }
2371 void  rk30_pwm_resume_voltage_set(void)
2372 {
2373 #ifdef CONFIG_RK30_PWM_REGULATOR
2374         pwm_resume_voltage();
2375 #endif
2376 }
2377
2378
2379 #ifdef CONFIG_I2C2_RK30
2380 static struct i2c_board_info __initdata i2c2_info[] = {
2381 #if defined (CONFIG_TOUCHSCREEN_GT8XX)
2382         {
2383                 .type          = "Goodix-TS",
2384                 .addr          = 0x55,
2385                 .flags         = 0,
2386                 .irq           = RK30_PIN1_PB7,
2387                 .platform_data = &goodix_info,
2388         },
2389 #endif
2390 #if defined (CONFIG_LS_CM3217)
2391         {
2392                 .type          = "lightsensor",
2393                 .addr          = 0x10,
2394                 .flags         = 0,
2395                 .platform_data = &cm3217_info,
2396         },
2397 #endif
2398 };
2399 #endif
2400
2401 #ifdef CONFIG_I2C3_RK30
2402 static struct i2c_board_info __initdata i2c3_info[] = {
2403 };
2404 #endif
2405
2406 #ifdef CONFIG_I2C4_RK30
2407 static struct i2c_board_info __initdata i2c4_info[] = {
2408 #if defined (CONFIG_MFD_RK616)
2409         {
2410                 .type          = "rk616",
2411                 .addr          = 0x50,
2412                 .flags         = 0,
2413                 .platform_data = &rk616_pdata,
2414         },
2415 #endif
2416
2417 };
2418 #endif
2419
2420 #ifdef CONFIG_I2C_GPIO_RK30
2421 #define I2C_SDA_PIN     INVALID_GPIO// RK30_PIN2_PD6   //set sda_pin here
2422 #define I2C_SCL_PIN     INVALID_GPIO//RK30_PIN2_PD7   //set scl_pin here
2423 static int rk30_i2c_io_init(void)
2424 {
2425         //set iomux (gpio) here
2426         //rk30_mux_api_set(GPIO2D7_I2C1SCL_NAME, GPIO2D_GPIO2D7);
2427         //rk30_mux_api_set(GPIO2D6_I2C1SDA_NAME, GPIO2D_GPIO2D6);
2428
2429         return 0;
2430 }
2431 struct i2c_gpio_platform_data default_i2c_gpio_data = {
2432        .sda_pin = I2C_SDA_PIN,
2433        .scl_pin = I2C_SCL_PIN,
2434        .udelay = 5, // clk = 500/udelay = 100Khz
2435        .timeout = 100,//msecs_to_jiffies(100),
2436        .bus_num    = 5,
2437        .io_init = rk30_i2c_io_init,
2438 };
2439 static struct i2c_board_info __initdata i2c_gpio_info[] = {
2440 };
2441 #endif
2442
2443 static void __init rk30_i2c_register_board_info(void)
2444 {
2445 #ifdef CONFIG_I2C0_RK30
2446         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
2447 #endif
2448 #ifdef CONFIG_I2C1_RK30
2449         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
2450 #endif
2451 #ifdef CONFIG_I2C2_RK30
2452         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
2453 #endif
2454 #ifdef CONFIG_I2C3_RK30
2455         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
2456 #endif
2457 #ifdef CONFIG_I2C4_RK30
2458         i2c_register_board_info(4, i2c4_info, ARRAY_SIZE(i2c4_info));
2459 #endif
2460 #ifdef CONFIG_I2C_GPIO_RK30
2461         i2c_register_board_info(5, i2c_gpio_info, ARRAY_SIZE(i2c_gpio_info));
2462 #endif
2463 }
2464 //end of i2c
2465
2466 // ========== Begin of rk3168 top board keypad defination ============
2467
2468 #include <plat/key.h>
2469
2470 static struct rk29_keys_button key_button[] = {
2471         {
2472                 .desc   = "vol-",
2473                 .code   = KEY_VOLUMEDOWN,
2474                 .adc_value      = 900,
2475                 .gpio   = INVALID_GPIO,
2476                 .active_low = PRESS_LEV_LOW,
2477         },
2478         {
2479                 .desc   = "play",
2480                 .code   = KEY_POWER,
2481                 .gpio   = RK30_PIN0_PA4,
2482                 .active_low = PRESS_LEV_LOW,
2483                 .wakeup = 1,
2484         },
2485         {
2486                 .desc   = "vol+",
2487                 .code   = KEY_VOLUMEUP,
2488                 .adc_value      = 1,
2489                 .gpio = INVALID_GPIO,
2490                 .active_low = PRESS_LEV_LOW,
2491         },
2492         {
2493                 .desc   = "menu",
2494                 .code   = EV_MENU,
2495                 .adc_value      = 133,
2496                 .gpio = INVALID_GPIO,
2497                 .active_low = PRESS_LEV_LOW,
2498         },
2499         {
2500                 .desc   = "home",
2501                 .code   = KEY_HOME,
2502                 .adc_value      = 550,
2503                 .gpio = INVALID_GPIO,
2504                 .active_low = PRESS_LEV_LOW,
2505         },
2506         {
2507                 .desc   = "esc",
2508                 .code   = KEY_BACK,
2509                 .adc_value      = 333,
2510                 .gpio = INVALID_GPIO,
2511                 .active_low = PRESS_LEV_LOW,
2512         },
2513         {
2514                 .desc   = "camera",
2515                 .code   = KEY_CAMERA,
2516                 .adc_value      = 742,
2517                 .gpio = INVALID_GPIO,
2518                 .active_low = PRESS_LEV_LOW,
2519         },
2520 };
2521 struct rk29_keys_platform_data rk29_keys_pdata = {
2522         .buttons        = key_button,
2523         .nbuttons       = ARRAY_SIZE(key_button),
2524         .chn    = 1,  //chn: 0-7, if do not use ADC,set 'chn' -1
2525 };
2526
2527 // =========== End of rk3168 top board keypad defination  =============
2528
2529
2530 #define POWER_ON_PIN RK30_PIN0_PA0   //power_hold
2531 static void rk30_pm_power_off(void)
2532 {
2533         printk(KERN_ERR "rk30_pm_power_off start...\n");
2534         #if defined(CONFIG_MFD_WM831X)
2535         if(pmic_is_wm8326()){
2536                 wm831x_set_bits(Wm831x,WM831X_GPIO_LEVEL,0x0001,0x0000);  //set sys_pwr 0
2537                 wm831x_device_shutdown(Wm831x);//wm8326 shutdown
2538          }
2539         #endif
2540
2541         #if defined(CONFIG_REGULATOR_ACT8846)
2542         if(pmic_is_act8846())
2543         {
2544                act8846_device_shutdown();
2545         }
2546         #endif
2547         
2548         #if defined(CONFIG_MFD_TPS65910)        
2549         if(pmic_is_tps65910())
2550         {
2551                 tps65910_device_shutdown();//tps65910 shutdown
2552         }
2553         #endif
2554         
2555          #if defined(CONFIG_MFD_RK808)        
2556         if(pmic_is_rk808())
2557        {
2558                 rk808_device_shutdown();//rk808 shutdown
2559         }
2560         #endif
2561          #if defined(CONFIG_MFD_RICOH619) 
2562          if(pmic_is_ricoh619()){
2563         ricoh619_power_off();    //ricoh619 shutdown
2564         }
2565         #endif
2566
2567         #if defined(CONFIG_MFD_RT5025) 
2568         if(pmic_is_rt5025()){
2569         rt5025_power_off();    //rt5025 shutdown
2570         }
2571         #endif
2572
2573         gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
2574         while (1);
2575 }
2576
2577 static void __init machine_rk30_board_init(void)
2578 {
2579         avs_init();
2580         gpio_request(POWER_ON_PIN, "poweronpin");
2581         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
2582         
2583         pm_power_off = rk30_pm_power_off;
2584         
2585         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
2586
2587
2588         rk30_i2c_register_board_info();
2589         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
2590         platform_add_devices(devices, ARRAY_SIZE(devices));
2591         rk_platform_add_display_devices();
2592         board_usb_detect_init(RK30_PIN0_PA7);
2593
2594 #if defined(CONFIG_WIFI_CONTROL_FUNC)
2595         rk29sdk_wifi_bt_gpio_control_init();
2596 #elif defined(CONFIG_WIFI_COMBO_MODULE_CONTROL_FUNC)
2597     rk29sdk_wifi_combo_module_gpio_init();
2598 #endif
2599
2600 #if defined(CONFIG_MT6620)
2601     clk_set_rate(clk_get_sys("rk_serial.0", "uart"), 48*1000000);
2602 #endif
2603
2604 #if defined(CONFIG_MT5931_MT6622)
2605                 clk_set_rate(clk_get_sys("rk_serial.0", "uart"), 24*1000000);
2606 #endif          
2607 }
2608 #define HD_SCREEN_SIZE 1920UL*1200UL*4*3
2609 static void __init rk30_reserve(void)
2610 {
2611 #if defined(CONFIG_ARCH_RK3188)
2612         /*if lcd resolution great than or equal to 1920*1200,reserve the ump memory */
2613         if(!(get_fb_size() < ALIGN(HD_SCREEN_SIZE,SZ_1M)))
2614         {
2615                 int ump_mem_phy_size=512UL*1024UL*1024UL; 
2616                 resource_mali[0].start = board_mem_reserve_add("ump buf", ump_mem_phy_size); 
2617                 resource_mali[0].end = resource_mali[0].start + ump_mem_phy_size -1;
2618         }
2619 #endif
2620 #ifdef CONFIG_ION
2621         rk30_ion_pdata.heaps[0].base = board_mem_reserve_add("ion", ION_RESERVE_SIZE);
2622 #endif
2623 #ifdef CONFIG_FB_ROCKCHIP
2624         resource_fb[0].start = board_mem_reserve_add("fb0 buf", get_fb_size());
2625         resource_fb[0].end = resource_fb[0].start + get_fb_size()- 1;
2626 #if 0
2627         resource_fb[1].start = board_mem_reserve_add("ipp buf", RK30_FB0_MEM_SIZE);
2628         resource_fb[1].end = resource_fb[1].start + RK30_FB0_MEM_SIZE - 1;
2629 #endif
2630
2631 #if defined(CONFIG_FB_ROTATE) || !defined(CONFIG_THREE_FB_BUFFER)
2632         resource_fb[2].start = board_mem_reserve_add("fb2 buf",get_fb_size());
2633         resource_fb[2].end = resource_fb[2].start + get_fb_size() - 1;
2634 #endif
2635 #endif
2636
2637 #ifdef CONFIG_VIDEO_RK29
2638         rk30_camera_request_reserve_mem();
2639 #endif
2640         
2641 #ifdef CONFIG_GPS_RK
2642         //it must be more than 8MB
2643         rk_gps_info.u32MemoryPhyAddr = board_mem_reserve_add("gps", SZ_8M);
2644 #endif
2645         board_mem_reserved();
2646 }
2647 /******************************** arm dvfs frequency volt table **********************************/
2648 /**
2649  * dvfs_cpu_logic_table: table for arm and logic dvfs 
2650  * @frequency   : arm frequency
2651  * @cpu_volt    : arm voltage depend on frequency
2652  */
2653
2654 #if defined(CONFIG_ARCH_RK3188)
2655 #if 0
2656 //sdk
2657 static struct cpufreq_frequency_table dvfs_arm_table_volt_level0[] = {
2658         {.frequency = 312 * 1000,       .index = 850 * 1000},
2659         {.frequency = 504 * 1000,       .index = 900 * 1000},
2660         {.frequency = 816 * 1000,       .index = 950 * 1000},
2661         {.frequency = 1008 * 1000,      .index = 1025 * 1000},
2662         {.frequency = 1200 * 1000,      .index = 1100 * 1000},
2663         {.frequency = 1416 * 1000,      .index = 1200 * 1000},
2664         {.frequency = 1608 * 1000,      .index = 1300 * 1000},
2665         {.frequency = CPUFREQ_TABLE_END},
2666 };
2667 //default for rk sdk testing
2668 static struct cpufreq_frequency_table dvfs_arm_table_volt_level1[] = {
2669         {.frequency = 312 * 1000,       .index = 875 * 1000},
2670         {.frequency = 504 * 1000,       .index = 925 * 1000},
2671         {.frequency = 816 * 1000,       .index = 975 * 1000},
2672         {.frequency = 1008 * 1000,      .index = 1075 * 1000},
2673         {.frequency = 1200 * 1000,      .index = 1150 * 1000},
2674         {.frequency = 1416 * 1000,      .index = 1250 * 1000},
2675         {.frequency = 1608 * 1000,      .index = 1350 * 1000},
2676         {.frequency = CPUFREQ_TABLE_END},
2677 };
2678 #endif
2679 // for production , fixed: 2013.9.13
2680 static struct cpufreq_frequency_table dvfs_arm_table_volt_level2[] = {
2681         {.frequency = 312 * 1000,       .index = 925 * 1000},
2682         {.frequency = 504 * 1000,       .index = 950 * 1000},
2683         {.frequency = 816 * 1000,       .index = 1000 * 1000},
2684         {.frequency = 1008 * 1000,      .index = 1075 * 1000},
2685         {.frequency = 1200 * 1000,      .index = 1200 * 1000},
2686         {.frequency = 1416 * 1000,      .index = 1250 * 1000},
2687         {.frequency = 1608 * 1000,      .index = 1350 * 1000},
2688         {.frequency = CPUFREQ_TABLE_END},
2689 };
2690
2691 /******************************** gpu dvfs frequency volt table **********************************/
2692 //sdk
2693 static struct cpufreq_frequency_table dvfs_gpu_table_volt_level0[] = {  
2694         {.frequency = 133 * 1000,       .index = 975 * 1000},//the mininum rate is limited 133M for rk3188
2695         {.frequency = 200 * 1000,       .index = 975 * 1000},
2696         {.frequency = 266 * 1000,       .index = 1000 * 1000},
2697         {.frequency = 300 * 1000,       .index = 1050 * 1000},
2698         {.frequency = 400 * 1000,       .index = 1100 * 1000},
2699         {.frequency = 600 * 1000,       .index = 1200 * 1000},
2700         {.frequency = CPUFREQ_TABLE_END},
2701 };
2702 //cube 10'
2703 static struct cpufreq_frequency_table dvfs_gpu_table_volt_level1[] = {  
2704         {.frequency = 133 * 1000,       .index = 975 * 1000},//the mininum rate is limited 133M for rk3188
2705         {.frequency = 200 * 1000,       .index = 1000 * 1000},
2706         {.frequency = 266 * 1000,       .index = 1025 * 1000},
2707         {.frequency = 300 * 1000,       .index = 1050 * 1000},
2708         {.frequency = 400 * 1000,       .index = 1100 * 1000},
2709         {.frequency = 600 * 1000,       .index = 1250 * 1000},
2710         {.frequency = CPUFREQ_TABLE_END},
2711 };
2712
2713 /******************************** ddr dvfs frequency volt table **********************************/
2714 static struct cpufreq_frequency_table dvfs_ddr_table_volt_level0[] = {
2715         {.frequency = 200 * 1000 + DDR_FREQ_SUSPEND,    .index = 950 * 1000},
2716         {.frequency = 300 * 1000 + DDR_FREQ_VIDEO,      .index = 1000 * 1000},
2717         {.frequency = 396 * 1000 + DDR_FREQ_NORMAL,     .index = 1100 * 1000},
2718         {.frequency = 460 * 1000 + DDR_FREQ_DUALVIEW,     .index = 1150 * 1000},
2719         //{.frequency = 528 * 1000 + DDR_FREQ_NORMAL,     .index = 1200 * 1000},
2720         {.frequency = CPUFREQ_TABLE_END},
2721 };
2722
2723 static struct cpufreq_frequency_table dvfs_ddr_table_t[] = {
2724         {.frequency = 200 * 1000 + DDR_FREQ_SUSPEND,    .index = 950 * 1000},
2725         {.frequency = 460 * 1000 + DDR_FREQ_NORMAL,     .index = 1150 * 1000},
2726         {.frequency = CPUFREQ_TABLE_END},
2727 };
2728
2729 //if you board is good for volt quality,select dvfs_arm_table_volt_level0
2730 #define dvfs_arm_table dvfs_arm_table_volt_level2
2731 #define dvfs_gpu_table dvfs_gpu_table_volt_level1
2732 #define dvfs_ddr_table dvfs_ddr_table_volt_level0
2733
2734 #else
2735 //for RK3168 && RK3066B
2736 static struct cpufreq_frequency_table dvfs_arm_table[] = {
2737         {.frequency = 312 * 1000,       .index = 950 * 1000},
2738         {.frequency = 504 * 1000,       .index = 1000 * 1000},
2739         {.frequency = 816 * 1000,       .index = 1050 * 1000},
2740         {.frequency = 1008 * 1000,      .index = 1125 * 1000},
2741         {.frequency = 1200 * 1000,      .index = 1200 * 1000},
2742         //{.frequency = 1416 * 1000,      .index = 1250 * 1000},
2743         //{.frequency = 1608 * 1000,      .index = 1300 * 1000},
2744         {.frequency = CPUFREQ_TABLE_END},
2745 };
2746
2747 static struct cpufreq_frequency_table dvfs_gpu_table[] = {
2748         {.frequency = 100 * 1000,       .index = 1000 * 1000},
2749         {.frequency = 200 * 1000,       .index = 1000 * 1000},
2750         {.frequency = 266 * 1000,       .index = 1050 * 1000},
2751         //{.frequency = 300 * 1000,       .index = 1050 * 1000},
2752         {.frequency = 400 * 1000,       .index = 1125 * 1000},
2753         {.frequency = CPUFREQ_TABLE_END},
2754 };
2755
2756 static struct cpufreq_frequency_table dvfs_ddr_table[] = {
2757         {.frequency = 200 * 1000 + DDR_FREQ_SUSPEND,    .index = 1000 * 1000},
2758         {.frequency = 300 * 1000 + DDR_FREQ_VIDEO,      .index = 1050 * 1000},
2759         {.frequency = 400 * 1000 + DDR_FREQ_NORMAL,     .index = 1100 * 1000},
2760         {.frequency = 450 * 1000,                       .index = 1150 * 1000},
2761         {.frequency = CPUFREQ_TABLE_END},
2762 };
2763 #endif
2764 /******************************** arm dvfs frequency volt table end **********************************/
2765 //#define DVFS_CPU_TABLE_SIZE   (ARRAY_SIZE(dvfs_cpu_logic_table))
2766 //static struct cpufreq_frequency_table cpu_dvfs_table[DVFS_CPU_TABLE_SIZE];
2767 //static struct cpufreq_frequency_table dep_cpu2core_table[DVFS_CPU_TABLE_SIZE];
2768 int get_max_freq(struct cpufreq_frequency_table *table)
2769 {
2770         int i,temp=0;
2771         
2772         for(i=0;table[i].frequency!= CPUFREQ_TABLE_END;i++)
2773         {
2774                 if(temp<table[i].frequency)
2775                         temp=table[i].frequency;
2776         }       
2777         printk("get_max_freq=%d\n",temp);
2778         return temp;
2779 }
2780
2781 void __init board_clock_init(void)
2782 {
2783         u32 flags=RK30_CLOCKS_DEFAULT_FLAGS;
2784 #if !defined(CONFIG_ARCH_RK3188)
2785         if(get_max_freq(dvfs_gpu_table)<=(400*1000))
2786         {       
2787                 flags=RK30_CLOCKS_DEFAULT_FLAGS|CLK_GPU_GPLL;
2788         }
2789         else
2790                 flags=RK30_CLOCKS_DEFAULT_FLAGS|CLK_GPU_CPLL;
2791 #endif  
2792         rk30_clock_data_init(periph_pll_default, codec_pll_default, flags);
2793         //dvfs_set_arm_logic_volt(dvfs_cpu_logic_table, cpu_dvfs_table, dep_cpu2core_table);    
2794         dvfs_set_freq_volt_table(clk_get(NULL, "cpu"), dvfs_arm_table);
2795         dvfs_set_freq_volt_table(clk_get(NULL, "gpu"), dvfs_gpu_table);
2796 #if defined(CONFIG_ARCH_RK3188)
2797         if (rk_pll_flag() == 0)
2798                 dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
2799         else
2800                 dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table_t);
2801 #else
2802         dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
2803 #endif
2804 }
2805
2806 MACHINE_START(RK30, "RK30board")
2807         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
2808         .fixup          = rk30_fixup,
2809         .reserve        = &rk30_reserve,
2810         .map_io         = rk30_map_io,
2811         .init_irq       = rk30_init_irq,
2812         .timer          = &rk30_timer,
2813         .init_machine   = machine_rk30_board_init,
2814 MACHINE_END