rk3026: i2s add several attempts to double confirm i2s frac effect
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk3188 / board-rk3188-ac.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 <plat/efuse.h>
50 #include <linux/regulator/rk29-pwm-regulator.h>
51 #if defined(CONFIG_CT36X_TS)
52 #include <linux/ct36x.h>
53 #endif
54 #if defined(CONFIG_MFD_RK610)
55 #include <linux/mfd/rk610_core.h>
56 #endif
57
58 #if defined(CONFIG_RK_HDMI)
59         #include "../../../drivers/video/rockchip/hdmi/rk_hdmi.h"
60 #endif
61
62 #if defined(CONFIG_SPIM_RK29)
63 #include "../../../drivers/spi/rk29_spim.h"
64 #endif
65 #if defined(CONFIG_MT6229)
66 #include <linux/mt6229.h>
67 #endif
68 #if defined(CONFIG_GPS_RK)
69 #include "../../../drivers/misc/gps/rk_gps/rk_gps.h"
70 #endif
71
72 #if defined(CONFIG_MT6620)
73 #include <linux/gps.h>
74 #endif
75 #ifdef CONFIG_RK_REMOTECTL
76 #include <mach/remotectl.h>
77 #endif
78
79 #include "../mach-rk30/board-rk3168-ds1006h-camera.c"
80 #include <plat/key.h>
81 #include <linux/scaler-core.h>
82
83 static struct rk29_keys_button key_button[] = {
84         {
85                 .desc   = "play",
86                 .code   = KEY_POWER,
87                 .gpio   = RK30_PIN0_PA4, 
88                 .active_low = PRESS_LEV_LOW,
89                 .wakeup = 1,
90         },
91 /*      
92         {
93                 .desc   = "esc",
94                 .code   = KEY_BACK,
95                 .adc_value      = 1,
96                 .gpio = INVALID_GPIO,
97                 .active_low = PRESS_LEV_LOW,
98         },
99         */
100         {
101                 .desc   = "mode_switch",
102                 .code   = 248,
103                 //.desc   = "vol+",
104                 //.code   = KEY_VOLUMEUP,
105                 
106                 .adc_value      = 1,
107                 .gpio = INVALID_GPIO,
108                 .active_low = PRESS_LEV_LOW,
109                .wakeup = 1
110         },
111         
112 };
113 struct rk29_keys_platform_data rk29_keys_pdata = {
114         .buttons        = key_button,
115         .nbuttons       = ARRAY_SIZE(key_button),
116         .chn    = 1,  //chn: 0-7, if do not use ADC,set 'chn' -1
117 };
118
119 /*
120      v1.0 :     ignore
121      v1.1 :      rk610 lvds + rk610 codec + MT5931_MT6622 + light photoresistor + adc/cw2015
122      v1.2 :      lvds       + rt5631      + M500          + us5151              + adc
123 */
124 #define DS1006H_V1_2_SUPPORT  1
125 int get_harware_version()
126 {
127     #if DS1006H_V1_2_SUPPORT
128         return 2;
129     #else
130         return 1;
131     #endif
132 }
133 EXPORT_SYMBOL_GPL(get_harware_version);
134
135 #if defined(CONFIG_CT36X_TS)
136
137 #define TOUCH_MODEL             363
138 #define TOUCH_MAX_X             1280
139 #define TOUCH_MAX_y             800
140 #define TOUCH_RESET_PIN         RK30_PIN0_PB6
141 #define TOUCH_INT_PIN           RK30_PIN1_PB7
142
143 static struct ct36x_platform_data ct36x_info = {
144         .model   = TOUCH_MODEL,
145         .x_max   = TOUCH_MAX_X,
146         .y_max   = TOUCH_MAX_y,
147
148         .rst_io = {
149                 .gpio = TOUCH_RESET_PIN,
150                 .active_low = 1,
151         },
152         .irq_io = {
153                 .gpio = TOUCH_INT_PIN,
154                 .active_low = 1,
155         },
156         .orientation = {1, 0, 0, 1},
157 };
158 #endif
159 static struct spi_board_info board_spi_devices[] = {
160 };
161
162 /***********************************************************
163 *       rk30  backlight
164 ************************************************************/
165 #ifdef CONFIG_BACKLIGHT_RK29_BL
166 #define PWM_ID            3
167 #define PWM_MODE          PWM3
168 #define PWM_EFFECT_VALUE  1
169
170 #define LCD_DISP_ON_PIN
171
172 #ifdef  LCD_DISP_ON_PIN
173 #define BL_EN_PIN         RK30_PIN0_PA2
174 #define BL_EN_VALUE       GPIO_HIGH
175 #endif
176 static int rk29_backlight_io_init(void)
177 {
178         int ret = 0;
179
180         iomux_set(PWM_MODE);
181 #ifdef  LCD_DISP_ON_PIN
182         ret = gpio_request(BL_EN_PIN, NULL);
183         if (ret != 0) {
184                 gpio_free(BL_EN_PIN);
185         }
186
187         gpio_direction_output(BL_EN_PIN, 0);
188         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
189 #endif
190
191         return ret;
192 }
193
194 static int rk29_backlight_io_deinit(void)
195 {
196         int ret = 0, pwm_gpio;
197
198 #ifdef  LCD_DISP_ON_PIN
199         gpio_free(BL_EN_PIN);
200 #endif
201
202         pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
203         gpio_request(pwm_gpio, NULL);
204         gpio_direction_output(pwm_gpio, GPIO_LOW);
205         return ret;
206 }
207
208 static int rk29_backlight_pwm_suspend(void)
209 {
210         int ret = 0, pwm_gpio;
211
212         pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
213         if (gpio_request(pwm_gpio, NULL)) {
214                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
215                 return -1;
216         }
217         gpio_direction_output(pwm_gpio, GPIO_LOW);
218 #ifdef  LCD_DISP_ON_PIN
219         gpio_direction_output(BL_EN_PIN, 0);
220         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
221 #endif
222         return ret;
223 }
224
225 static int rk29_backlight_pwm_resume(void)
226 {
227         int pwm_gpio = iomux_mode_to_gpio(PWM_MODE);
228
229         gpio_free(pwm_gpio);
230         iomux_set(PWM_MODE);
231 #ifdef  LCD_DISP_ON_PIN
232         msleep(30);
233         gpio_direction_output(BL_EN_PIN, 1);
234         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
235 #endif
236         return 0;
237 }
238
239 static struct rk29_bl_info rk29_bl_info = {
240         .min_brightness = 65,
241         .max_brightness = 150,
242         .brightness_mode =BRIGHTNESS_MODE_CONIC,
243         .pre_div = 30 * 1000,  // pwm output clk: 30k;
244         .pwm_id = PWM_ID,
245         .bl_ref = PWM_EFFECT_VALUE,
246         .io_init = rk29_backlight_io_init,
247         .io_deinit = rk29_backlight_io_deinit,
248         .pwm_suspend = rk29_backlight_pwm_suspend,
249         .pwm_resume = rk29_backlight_pwm_resume,
250 };
251
252 static struct platform_device rk29_device_backlight = {
253         .name   = "rk29_backlight",
254         .id     = -1,
255         .dev    = {
256                 .platform_data  = &rk29_bl_info,
257         }
258 };
259
260 #endif
261 #ifdef CONFIG_RK_REMOTECTL
262
263 void rk30_remotectl_iomux(void)
264 {
265         ;
266 }
267
268 struct RKxx_remotectl_platform_data rk30_remotectl_pdata = {
269     .gpio       =   RK30_PIN0_PA3,
270     .wakeup     = 1,
271     .rep    = 0,
272     .set_iomux = rk30_remotectl_iomux,
273 };
274
275 static struct platform_device rk30_device_remotectl = {
276         .name           = "rkxx-remotectl",
277         .id             = -1,
278         .dev            = {
279                 .platform_data  = &rk30_remotectl_pdata,
280         },
281 };
282 #endif
283
284 /*MMA8452 gsensor*/
285 #if defined (CONFIG_GS_MMA8452)
286 #define MMA8452_INT_PIN   RK30_PIN0_PB7
287
288 static int mma8452_init_platform_hw(void)
289 {
290         return 0;
291 }
292
293 static struct sensor_platform_data mma8452_info = {
294         .type = SENSOR_TYPE_ACCEL,
295         .irq_enable = 1,
296         .poll_delay_ms = 30,
297         .init_platform_hw = mma8452_init_platform_hw,
298         .orientation = {-1, 0, 0, 0, 0, -1, 0, 1, 0},
299 };
300 #endif
301 #if defined (CONFIG_GS_LIS3DH)
302 #define LIS3DH_INT_PIN   RK30_PIN0_PB7
303
304 static int lis3dh_init_platform_hw(void)
305 {
306
307         return 0;
308 }
309
310 static struct sensor_platform_data lis3dh_info = {
311         .type = SENSOR_TYPE_ACCEL,
312         .irq_enable = 1,
313         .poll_delay_ms = 30,
314         .init_platform_hw = lis3dh_init_platform_hw,
315         .orientation = {-1, 0, 0, 0, 1, 0, 0, 0, -1},
316 };
317 #endif
318
319 #if defined (CONFIG_COMPASS_AK8963)
320 static struct sensor_platform_data akm8963_info =
321 {
322        .type = SENSOR_TYPE_COMPASS,
323        .irq_enable = 1,
324        .poll_delay_ms = 30,
325        .m_layout = 
326        {
327                {
328                        {0, 1, 0},
329                        {1, 0, 0},
330                        {0, 0, -1},
331                },
332
333                {
334                        {1, 0, 0},
335                        {0, 1, 0},
336                        {0, 0, 1},
337                },
338
339                {
340                        {0, -1, 0},
341                        {-1, 0, 0},
342                        {0, 0, -1},
343                },
344
345                {
346                        {1, 0, 0},
347                        {0, 1, 0},
348                        {0, 0, 1},
349                },
350        }
351 };
352
353 #endif
354
355 #if defined(CONFIG_LS_PHOTORESISTOR)
356 static struct sensor_platform_data light_photoresistor_info = {
357         .type = SENSOR_TYPE_LIGHT,
358         .irq_enable = 0,
359         .address = 2   ,
360         .poll_delay_ms = 200,
361 };
362 #endif
363
364 #if defined (CONFIG_COMPASS_AK8975)
365 static struct sensor_platform_data akm8975_info =
366 {
367         .type = SENSOR_TYPE_COMPASS,
368         .irq_enable = 1,
369         .poll_delay_ms = 30,
370         .m_layout = 
371         {
372                 {
373                         {1, 0, 0},
374                         {0, 1, 0},
375                         {0, 0, 1},
376                 },
377
378                 {
379                         {1, 0, 0},
380                         {0, 1, 0},
381                         {0, 0, 1},
382                 },
383
384                 {
385                         {1, 0, 0},
386                         {0, 1, 0},
387                         {0, 0, 1},
388                 },
389
390                 {
391                         {1, 0, 0},
392                         {0, 1, 0},
393                         {0, 0, 1},
394                 },
395         }
396 };
397
398 #endif
399
400 #if defined(CONFIG_MT6229)
401 static int mt6229_io_init(void)
402 {
403       #if 0
404         rk30_mux_api_set(GPIO2B6_LCDC1DATA14_SMCADDR18_TSSYNC_NAME, GPIO2B_GPIO2B6);
405       k30_mux_api_set(GPIO4D2_SMCDATA10_TRACEDATA10_NAME, GPIO4D_GPIO4D2);
406         rk30_mux_api_set(GPIO2B7_LCDC1DATA15_SMCADDR19_HSADCDATA7_NAME, GPIO2B_GPIO2B7);
407         rk30_mux_api_set(GPIO2C0_LCDCDATA16_GPSCLK_HSADCCLKOUT_NAME, GPIO2C_GPIO2C0);
408         rk30_mux_api_set(GPIO2C1_LCDC1DATA17_SMCBLSN0_HSADCDATA6_NAME, GPIO2C_GPIO2C1);
409         rk30_mux_api_set(GPIO2C1_LCDC1DATA17_SMCBLSN0_HSADCDATA6_NAME, GPIO2C_GPIO2C1);
410       #endif
411          return 0;
412 }
413
414 static int mt6229_io_deinit(void)
415 {
416         
417         return 0;
418 }
419  
420 struct rk29_mt6229_data rk29_mt6229_info = {
421         .io_init = mt6229_io_init,
422         .io_deinit = mt6229_io_deinit,
423         .modem_power_en = RK30_PIN0_PC6,
424         .bp_power = RK30_PIN2_PD5,
425         .modem_usb_en = RK30_PIN0_PC7,
426         .modem_uart_en = RK30_PIN2_PD4,
427         .bp_wakeup_ap = RK30_PIN0_PC5,
428         .ap_ready = RK30_PIN0_PC4,
429
430 };
431 struct platform_device rk29_device_mt6229 = {   
432         .name = "mt6229",       
433         .id = -1,       
434         .dev            = {
435                 .platform_data = &rk29_mt6229_info,
436         }       
437     };
438 #endif
439
440 #if defined(CONFIG_GYRO_L3G4200D)
441
442 #include <linux/l3g4200d.h>
443 #define L3G4200D_INT_PIN  RK30_PIN0_PB4
444
445 static int l3g4200d_init_platform_hw(void)
446 {
447         return 0;
448 }
449
450 static struct sensor_platform_data l3g4200d_info = {
451         .type = SENSOR_TYPE_GYROSCOPE,
452         .irq_enable = 1,
453         .poll_delay_ms = 0,
454         .orientation = {1, 0, 0 , 0 , -1, 0, 0, 0, -1},
455         .init_platform_hw = l3g4200d_init_platform_hw,
456         .x_min = 40,//x_min,y_min,z_min = (0-100) according to hardware
457         .y_min = 40,
458         .z_min = 20,
459 };
460
461 #endif
462
463 #ifdef CONFIG_LS_CM3217
464 static struct sensor_platform_data cm3217_info = {
465         .type = SENSOR_TYPE_LIGHT,
466         .irq_enable = 0,
467         .poll_delay_ms = 500,
468 };
469
470 #endif
471
472 #ifdef CONFIG_FB_ROCKCHIP
473
474 #if DS1006H_V1_2_SUPPORT
475 #define LCD_CS_PIN         RK30_PIN0_PB0
476 #else
477 #define LCD_CS_PIN         INVALID_GPIO
478 #endif
479 #define LCD_CS_VALUE       GPIO_HIGH
480
481 #if DS1006H_V1_2_SUPPORT
482 #define LCD_EN_PIN         RK30_PIN0_PB1
483 #else
484 #define LCD_EN_PIN         RK30_PIN0_PB0
485 #endif
486 #define LCD_EN_VALUE       GPIO_LOW
487
488 static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
489 {
490         int ret = 0;
491
492         if(LCD_CS_PIN !=INVALID_GPIO)
493         {
494                 ret = gpio_request(LCD_CS_PIN, NULL);
495                 if (ret != 0)
496                 {
497                         gpio_free(LCD_CS_PIN);
498                         printk(KERN_ERR "request lcd cs pin fail!\n");
499                         return -1;
500                 }
501                 else
502                 {
503                         gpio_direction_output(LCD_CS_PIN, LCD_CS_VALUE);
504                 }
505         }
506
507         if(LCD_EN_PIN !=INVALID_GPIO)
508         {
509                 ret = gpio_request(LCD_EN_PIN, NULL);
510                 if (ret != 0)
511                 {
512                         gpio_free(LCD_EN_PIN);
513                         printk(KERN_ERR "request lcd en pin fail!\n");
514                         return -1;
515                 }
516                 else
517                 {
518                         gpio_direction_output(LCD_EN_PIN, LCD_EN_VALUE);
519                 }
520         }
521         return 0;
522 }
523 static int rk_fb_io_disable(void)
524 {
525         if(LCD_CS_PIN !=INVALID_GPIO)
526         {
527                 gpio_set_value(LCD_CS_PIN, !LCD_CS_VALUE);
528         }
529         if(LCD_EN_PIN !=INVALID_GPIO)
530         {
531                 gpio_set_value(LCD_EN_PIN, !LCD_EN_VALUE);
532         }
533         return 0;
534 }
535 static int rk_fb_io_enable(void)
536 {
537         if(LCD_CS_PIN !=INVALID_GPIO)
538         {
539                 gpio_set_value(LCD_CS_PIN, LCD_CS_VALUE);
540         }
541         if(LCD_EN_PIN !=INVALID_GPIO)
542         {
543                 gpio_set_value(LCD_EN_PIN, LCD_EN_VALUE);
544         }
545         return 0;
546 }
547
548 #if defined(CONFIG_LCDC1_RK3188)
549 struct rk29fb_info lcdc1_screen_info = {
550            .prop           = EXTEND,       //extend display device
551        .lcd_info  = NULL,
552        .set_screen_info = hdmi_init_lcdc,
553
554 };
555 #endif
556 extern void set_vga_lcd_info(struct rk29fb_screen *screen, struct rk29lcd_info *lcd_info);
557
558 #if defined(CONFIG_LCDC0_RK3188)
559 struct rk29fb_info lcdc0_screen_info = {
560         .prop      = PRMRY,             //primary display device
561         .io_init   = rk_fb_io_init,
562         .io_disable = rk_fb_io_disable,
563         .io_enable = rk_fb_io_enable,
564         //.set_screen_info = set_lcd_info,
565         .set_screen_info = set_vga_lcd_info,
566         
567 };
568 #endif
569
570 static struct resource resource_fb[] = {
571         [0] = {
572                 .name  = "fb0 buf",
573                 .start = 0,
574                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
575                 .flags = IORESOURCE_MEM,
576         },
577         [1] = {
578                 .name  = "ipp buf",  //for rotate
579                 .start = 0,
580                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
581                 .flags = IORESOURCE_MEM,
582         },
583         [2] = {
584                 .name  = "fb2 buf",
585                 .start = 0,
586                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
587                 .flags = IORESOURCE_MEM,
588         },
589 };
590
591 static struct platform_device device_fb = {
592         .name           = "rk-fb",
593         .id             = -1,
594         .num_resources  = ARRAY_SIZE(resource_fb),
595         .resource       = resource_fb,
596 };
597 #endif
598
599 #if defined(CONFIG_ARCH_RK3188)
600 static struct resource resource_mali[] = {
601         [0] = {
602         .name  = "ump buf",
603         .start = 0,
604         .end   = 0,
605         .flags = IORESOURCE_MEM,
606         },
607
608 };
609
610 static struct platform_device device_mali= {
611         .name           = "mali400_ump",
612         .id             = -1,
613         .num_resources  = ARRAY_SIZE(resource_mali),
614         .resource       = resource_mali,
615 };
616 #endif
617
618 #if defined(CONFIG_LCDC0_RK3188)
619 static struct resource resource_lcdc0[] = {
620         [0] = {
621                 .name  = "lcdc0 reg",
622                 .start = RK30_LCDC0_PHYS,
623                 .end   = RK30_LCDC0_PHYS + RK30_LCDC0_SIZE - 1,
624                 .flags = IORESOURCE_MEM,
625         },
626         
627         [1] = {
628                 .name  = "lcdc0 irq",
629                 .start = IRQ_LCDC0,
630                 .end   = IRQ_LCDC0,
631                 .flags = IORESOURCE_IRQ,
632         },
633 };
634
635 static struct platform_device device_lcdc0 = {
636         .name             = "rk30-lcdc",
637         .id               = 0,
638         .num_resources    = ARRAY_SIZE(resource_lcdc0),
639         .resource         = resource_lcdc0,
640         .dev            = {
641                 .platform_data = &lcdc0_screen_info,
642         },
643 };
644 #endif
645 #if defined(CONFIG_LCDC1_RK3188) 
646 static struct resource resource_lcdc1[] = {
647         [0] = {
648                 .name  = "lcdc1 reg",
649                 .start = RK30_LCDC1_PHYS,
650                 .end   = RK30_LCDC1_PHYS + RK30_LCDC1_SIZE - 1,
651                 .flags = IORESOURCE_MEM,
652         },
653         [1] = {
654                 .name  = "lcdc1 irq",
655                 .start = IRQ_LCDC1,
656                 .end   = IRQ_LCDC1,
657                 .flags = IORESOURCE_IRQ,
658         },
659 };
660
661 static struct platform_device device_lcdc1 = {
662         .name             = "rk30-lcdc",
663         .id               = 1,
664         .num_resources    = ARRAY_SIZE(resource_lcdc1),
665         .resource         = resource_lcdc1,
666         .dev            = {
667                 .platform_data = &lcdc1_screen_info,
668         },
669 };
670 #endif
671
672 #if defined(CONFIG_MFD_RK610)
673 #define RK610_RST_PIN                   RK30_PIN3_PB2
674 static int rk610_power_on_init(void)
675 {
676         int ret;
677         if(RK610_RST_PIN != INVALID_GPIO)
678         {
679                 ret = gpio_request(RK610_RST_PIN, "rk610 reset");
680                 if (ret)
681                 {
682                         printk(KERN_ERR "rk610_control_probe request gpio fail\n");
683                 }
684                 else 
685                 {
686                         gpio_direction_output(RK610_RST_PIN, GPIO_HIGH);
687                         msleep(100);
688                         gpio_direction_output(RK610_RST_PIN, GPIO_LOW);
689                         msleep(100);
690                         gpio_set_value(RK610_RST_PIN, GPIO_HIGH);
691                 }
692         }
693
694         return 0;
695         
696 }
697
698
699 static struct rk610_ctl_platform_data rk610_ctl_pdata = {
700         .rk610_power_on_init = rk610_power_on_init,
701 };
702 #endif
703
704 #ifdef CONFIG_SND_SOC_RK610
705 static int rk610_codec_io_init(void)
706 {
707 //if need iomux.
708 //Must not gpio_request
709         return 0;
710 }
711
712 static struct rk610_codec_platform_data rk610_codec_pdata = {
713         .spk_ctl_io = RK30_PIN2_PD7,
714         .io_init = rk610_codec_io_init,
715         .boot_depop = 1,
716 };
717 #endif
718
719 #ifdef CONFIG_RK_HDMI
720 #define RK_HDMI_RST_PIN                         RK30_PIN3_PB2
721 static int rk_hdmi_power_init(void)
722 {
723         int ret;
724
725         if(RK_HDMI_RST_PIN != INVALID_GPIO)
726         {
727                 if (gpio_request(RK_HDMI_RST_PIN, NULL)) {
728                         printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
729                         return -1;
730                 }
731                 gpio_direction_output(RK_HDMI_RST_PIN, GPIO_LOW);
732                 gpio_set_value(RK_HDMI_RST_PIN, GPIO_LOW);
733                 msleep(100);
734                 gpio_set_value(RK_HDMI_RST_PIN, GPIO_HIGH);
735                 msleep(50);
736         }
737         return 0;
738 }
739 static struct rk_hdmi_platform_data rk_hdmi_pdata = {
740         //.io_init = rk_hdmi_power_init,
741 };
742 #endif
743 #ifdef CONFIG_ION
744 #define ION_RESERVE_SIZE        (80 * SZ_1M)
745 static struct ion_platform_data rk30_ion_pdata = {
746         .nr = 1,
747         .heaps = {
748                 {
749                         .type = ION_HEAP_TYPE_CARVEOUT,
750                         .id = ION_NOR_HEAP_ID,
751                         .name = "norheap",
752                         .size = ION_RESERVE_SIZE,
753                 }
754         },
755 };
756
757 static struct platform_device device_ion = {
758         .name = "ion-rockchip",
759         .id = 0,
760         .dev = {
761                 .platform_data = &rk30_ion_pdata,
762         },
763 };
764 #endif
765
766 /**************************************************************************************************
767  * SDMMC devices,  include the module of SD,MMC,and sdio.noted by xbw at 2012-03-05
768 **************************************************************************************************/
769 #ifdef CONFIG_SDMMC_RK29
770 #include "board-rk3188-ac-sdmmc-config.c"
771 #include "../plat-rk/rk-sdmmc-ops.c"
772 #include "../plat-rk/rk-sdmmc-wifi.c"
773 #endif //endif ---#ifdef CONFIG_SDMMC_RK29
774
775 #ifdef CONFIG_SDMMC0_RK29
776 static int rk29_sdmmc0_cfg_gpio(void)
777 {
778 #ifdef CONFIG_SDMMC_RK29_OLD
779         iomux_set(MMC0_CMD);
780         iomux_set(MMC0_CLKOUT);
781         iomux_set(MMC0_D0);
782         iomux_set(MMC0_D1);
783         iomux_set(MMC0_D2);
784         iomux_set(MMC0_D3);
785
786         iomux_set_gpio_mode(iomux_mode_to_gpio(MMC0_DETN));
787
788         gpio_request(RK30_PIN3_PA7, "sdmmc-power");
789         gpio_direction_output(RK30_PIN3_PA7, GPIO_LOW);
790
791 #else
792         rk29_sdmmc_set_iomux(0, 0xFFFF);
793
794     #if defined(CONFIG_SDMMC0_RK29_SDCARD_DET_FROM_GPIO)
795         #if SDMMC_USE_NEW_IOMUX_API
796         iomux_set_gpio_mode(iomux_gpio_to_mode(RK29SDK_SD_CARD_DETECT_N));
797         #else
798         rk30_mux_api_set(RK29SDK_SD_CARD_DETECT_PIN_NAME, RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO);
799         #endif
800     #else
801         #if SDMMC_USE_NEW_IOMUX_API       
802         iomux_set(MMC0_DETN);
803         #else
804         rk30_mux_api_set(RK29SDK_SD_CARD_DETECT_PIN_NAME, RK29SDK_SD_CARD_DETECT_IOMUX_FMUX);
805         #endif
806     #endif      
807
808 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
809         gpio_request(SDMMC0_WRITE_PROTECT_PIN, "sdmmc-wp");
810         gpio_direction_input(SDMMC0_WRITE_PROTECT_PIN);
811 #endif
812
813 #endif
814
815         return 0;
816 }
817
818 #define CONFIG_SDMMC0_USE_DMA
819 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
820         .host_ocr_avail =
821             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
822              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
823              MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36),
824         .host_caps =
825             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
826         .io_init = rk29_sdmmc0_cfg_gpio,
827
828 #if !defined(CONFIG_SDMMC_RK29_OLD)
829         .set_iomux = rk29_sdmmc_set_iomux,
830 #endif
831
832         .dma_name = "sd_mmc",
833 #ifdef CONFIG_SDMMC0_USE_DMA
834         .use_dma = 1,
835 #else
836         .use_dma = 0,
837 #endif
838
839 #if defined(CONFIG_USE_SDMMC0_FOR_WIFI_DEVELOP_BOARD)
840     .status = rk29sdk_wifi_mmc0_status,
841     .register_status_notify = rk29sdk_wifi_mmc0_status_register,
842 #endif
843
844 #if defined(RK29SDK_SD_CARD_PWR_EN) || (INVALID_GPIO != RK29SDK_SD_CARD_PWR_EN)
845     .power_en = RK29SDK_SD_CARD_PWR_EN,
846     .power_en_level = RK29SDK_SD_CARD_PWR_EN_LEVEL,
847 #else
848     .power_en = INVALID_GPIO,
849     .power_en_level = GPIO_LOW,
850 #endif    
851         .enable_sd_wakeup = 0,
852
853 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
854         .write_prt = SDMMC0_WRITE_PROTECT_PIN,
855         .write_prt_enalbe_level = SDMMC0_WRITE_PROTECT_ENABLE_VALUE;
856 #else
857         .write_prt = INVALID_GPIO,
858 #endif
859
860     .det_pin_info = {    
861     #if defined(RK29SDK_SD_CARD_DETECT_N) || (INVALID_GPIO != RK29SDK_SD_CARD_DETECT_N)  
862         .io             = RK29SDK_SD_CARD_DETECT_N, //INVALID_GPIO,
863         .enable         = RK29SDK_SD_CARD_INSERT_LEVEL,
864         #ifdef RK29SDK_SD_CARD_DETECT_PIN_NAME
865         .iomux          = {
866             .name       = RK29SDK_SD_CARD_DETECT_PIN_NAME,
867             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO
868             .fgpio      = RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO,
869             #endif
870             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FMUX
871             .fmux       = RK29SDK_SD_CARD_DETECT_IOMUX_FMUX,
872             #endif
873         },
874         #endif
875     #else
876         .io             = INVALID_GPIO,
877         .enable         = GPIO_LOW,
878     #endif    
879     }, 
880
881 };
882 #endif // CONFIG_SDMMC0_RK29
883
884 #ifdef CONFIG_SDMMC1_RK29
885 #define CONFIG_SDMMC1_USE_DMA
886 static int rk29_sdmmc1_cfg_gpio(void)
887 {
888 #if defined(CONFIG_SDMMC_RK29_OLD)
889         iomux_set(MMC1_CMD);
890         iomux_set(MMC1_CLKOUT);
891         iomux_set(MMC1_D0);
892         iomux_set(MMC1_D1);
893         iomux_set(MMC1_D2);
894         iomux_set(MMC1_D3);
895 #else
896
897 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
898         gpio_request(SDMMC1_WRITE_PROTECT_PIN, "sdio-wp");
899         gpio_direction_input(SDMMC1_WRITE_PROTECT_PIN);
900 #endif
901
902 #endif
903
904         return 0;
905 }
906
907 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
908         .host_ocr_avail =
909             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
910              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
911              MMC_VDD_33_34),
912
913 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
914         .host_caps = (MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ |
915                       MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
916 #else
917         .host_caps =
918             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
919 #endif
920
921         .io_init = rk29_sdmmc1_cfg_gpio,
922
923 #if !defined(CONFIG_SDMMC_RK29_OLD)
924         .set_iomux = rk29_sdmmc_set_iomux,
925 #endif
926
927         .dma_name = "sdio",
928 #ifdef CONFIG_SDMMC1_USE_DMA
929         .use_dma = 1,
930 #else
931         .use_dma = 0,
932 #endif
933
934 #if defined(CONFIG_WIFI_CONTROL_FUNC) || defined(CONFIG_WIFI_COMBO_MODULE_CONTROL_FUNC)
935     .status = rk29sdk_wifi_status,
936     .register_status_notify = rk29sdk_wifi_status_register,
937 #endif
938
939 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
940         .write_prt = SDMMC1_WRITE_PROTECT_PIN,
941             .write_prt_enalbe_level = SDMMC1_WRITE_PROTECT_ENABLE_VALUE;
942 #else
943         .write_prt = INVALID_GPIO,
944 #endif
945
946     #if defined(CONFIG_RK29_SDIO_IRQ_FROM_GPIO)
947         .sdio_INT_gpio = RK29SDK_WIFI_SDIO_CARD_INT,
948     #endif
949
950     .det_pin_info = {    
951 #if defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
952      #if defined(RK29SDK_SD_CARD_DETECT_N) || (INVALID_GPIO != RK29SDK_SD_CARD_DETECT_N)  
953         .io             = RK29SDK_SD_CARD_DETECT_N,
954      #else
955          .io             = INVALID_GPIO,
956      #endif   
957
958         .enable         = RK29SDK_SD_CARD_INSERT_LEVEL,
959         #ifdef RK29SDK_SD_CARD_DETECT_PIN_NAME
960         .iomux          = {
961             .name       = RK29SDK_SD_CARD_DETECT_PIN_NAME,
962             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO
963             .fgpio      = RK29SDK_SD_CARD_DETECT_IOMUX_FGPIO,
964             #endif
965             #ifdef RK29SDK_SD_CARD_DETECT_IOMUX_FMUX
966             .fmux       = RK29SDK_SD_CARD_DETECT_IOMUX_FMUX,
967             #endif
968         },
969         #endif
970  #else
971         .io             = INVALID_GPIO,
972         .enable         = GPIO_LOW,
973 #endif
974     },
975    
976         .enable_sd_wakeup = 0,
977 };
978 #endif //endif--#ifdef CONFIG_SDMMC1_RK29
979
980 /**************************************************************************************************
981  * the end of setting for SDMMC devices
982 **************************************************************************************************/
983
984 #ifdef CONFIG_BATTERY_RK30_ADC_FAC
985 static int ac_current = -1;
986 #define CHARING_CURRENT_500MA 0
987 #define CHARING_CURRENT_1000MA 1
988
989 #define   DC_CUR_SET_PIN RK30_PIN0_PB0
990 #define   CHARGE_OK_PIN  RK30_PIN0_PA6
991 #define   DC_DET_PIN     RK30_PIN0_PB2
992 static int rk30_battery_adc_io_init(void)
993 {
994         int ret = 0;
995         printk("charging:  set charging current 500ma \n");
996         ac_current = CHARING_CURRENT_500MA;
997         //dc charge detect pin
998         ret = gpio_request(DC_DET_PIN, NULL);
999         if (ret) {
1000              printk("failed to request dc_det gpio\n");
1001              return ret ;
1002         }
1003
1004         gpio_pull_updown(DC_DET_PIN, 1);//important
1005         ret = gpio_direction_input(DC_DET_PIN);
1006         if (ret) {
1007                 printk("failed to set gpio dc_det input\n");
1008                 return ret ;
1009         }
1010
1011         //charge ok pin
1012         ret = gpio_request(CHARGE_OK_PIN, NULL);
1013         if (ret) {
1014                 printk("failed to request charge_ok gpio\n");
1015                 return ret ;
1016         }
1017
1018         gpio_pull_updown(CHARGE_OK_PIN, 1);//important
1019         ret = gpio_direction_input(CHARGE_OK_PIN);
1020         if (ret) {
1021                 printk("failed to set gpio charge_ok input\n");
1022                 return ret ;
1023         }
1024         //charge current set pin
1025         ret = gpio_request(DC_CUR_SET_PIN, NULL);
1026         if (ret) {
1027                 printk("failed to request DC_CUR_SET_PIN gpio\n");
1028                 return ret ;
1029         }
1030
1031         ret = gpio_direction_output(DC_CUR_SET_PIN, GPIO_LOW);//500ma
1032         if (ret) {
1033                 printk("failed to set gpio DC_CUR_SET_PIN output\n");
1034                 return ret ;
1035         }
1036
1037         return 0;
1038
1039 }
1040
1041 static int set_usb_charging_current(int mode)
1042 {
1043 #if 0
1044     if ( (ac_current==CHARING_CURRENT_1000MA) && (mode == PC_MODE) ) {
1045                 gpio_set_value(DC_CUR_SET_PIN, GPIO_LOW);
1046                 ac_current = CHARING_CURRENT_500MA;
1047      }
1048      else if ((mode == ADAPT_MODE) && (ac_current==CHARING_CURRENT_500MA))
1049      {
1050                 gpio_set_value(DC_CUR_SET_PIN, GPIO_HIGH);
1051                ac_current = CHARING_CURRENT_1000MA;
1052
1053       }
1054 #endif
1055        gpio_set_value(DC_CUR_SET_PIN, GPIO_LOW);
1056        ac_current = CHARING_CURRENT_500MA;
1057 }
1058
1059
1060 static struct rk30_adc_battery_platform_data rk30_adc_battery_platdata = {
1061         .dc_det_pin      = RK30_PIN0_PB2,
1062         .batt_low_pin    = INVALID_GPIO, 
1063         .charge_set_pin  = INVALID_GPIO,
1064         .charge_ok_pin   = RK30_PIN0_PA6,
1065          .usb_det_pin = INVALID_GPIO,
1066         .dc_det_level    = GPIO_LOW,
1067         .charge_ok_level = GPIO_HIGH,
1068
1069         .reference_voltage = 1800, // the rK2928 is 3300;RK3066 and rk29 are 2500;rk3066B is 1800;
1070        .pull_up_res = 200,     //divider resistance ,  pull-up resistor
1071        .pull_down_res = 120, //divider resistance , pull-down resistor
1072
1073         .is_reboot_charging = 1,
1074         .save_capacity   = 1 ,
1075         .low_voltage_protection = 3600,   
1076         .io_init = rk30_battery_adc_io_init,
1077         .control_usb_charging= set_usb_charging_current, 
1078 };
1079
1080 static struct platform_device rk30_device_adc_battery = {
1081         .name   = "rk30-battery",
1082         .id     = -1,
1083         .dev = {
1084                 .platform_data = &rk30_adc_battery_platdata,
1085         },
1086 };
1087 #endif
1088 #ifdef CONFIG_RK30_PWM_REGULATOR
1089 static int pwm_voltage_map[] = {
1090         800000,825000,850000, 875000,900000, 925000 ,950000, 975000,1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000,1375000
1091 };
1092
1093 static struct regulator_consumer_supply pwm_dcdc1_consumers[] = {
1094         {
1095                 .supply = "vdd_cpu",
1096         }
1097 };
1098
1099 struct regulator_init_data pwm_regulator_init_dcdc[1] =
1100 {
1101         {
1102                 .constraints = {
1103                         .name = "PWM_DCDC1",
1104                         .min_uV = 600000,
1105                         .max_uV = 1800000,      //0.6-1.8V
1106                         .apply_uV = true,
1107                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
1108                 },
1109                 .num_consumer_supplies = ARRAY_SIZE(pwm_dcdc1_consumers),
1110                 .consumer_supplies = pwm_dcdc1_consumers,
1111         },
1112 };
1113
1114 static struct pwm_platform_data pwm_regulator_info[1] = {
1115         {
1116                 .pwm_id = 1,
1117                 .pwm_gpio = RK30_PIN3_PD4,
1118                 .pwm_iomux_pwm = PWM1,
1119                 .pwm_iomux_gpio = GPIO3_D4,
1120                 .pwm_voltage = 1100000,
1121                 .suspend_voltage = 1000000,
1122                 .min_uV = 800000,
1123                 .max_uV = 1375000,
1124                 .coefficient = 575,     //57.5%
1125                 .pwm_voltage_map = pwm_voltage_map,
1126                 .init_data      = &pwm_regulator_init_dcdc[0],
1127         },
1128 };
1129
1130 struct platform_device pwm_regulator_device[1] = {
1131         {
1132                 .name = "pwm-voltage-regulator",
1133                 .id = 0,
1134                 .dev            = {
1135                         .platform_data = &pwm_regulator_info[0],
1136                 }
1137         },
1138 };
1139 #endif
1140
1141 #ifdef CONFIG_RK29_VMAC
1142 #define PHY_PWR_EN_GPIO  INVALID_GPIO
1143 #define PHY_PWR_EN_IOMUX GPIO3_D2 
1144 #define PHY_PWR_EN_VALUE GPIO_HIGH
1145 #define RMII_EXT_CLK
1146 #include "../mach-rk30/board-rk31-sdk-vmac.c"
1147 #endif
1148
1149 #ifdef CONFIG_RFKILL_RK
1150 // bluetooth rfkill device, its driver in net/rfkill/rfkill-rk.c
1151 static struct rfkill_rk_platform_data rfkill_rk_platdata = {
1152     .type               = RFKILL_TYPE_BLUETOOTH,
1153
1154     .poweron_gpio       = { // BT_REG_ON
1155         .io             = INVALID_GPIO, //RK30_PIN3_PC7,
1156         .enable         = GPIO_HIGH,
1157         .iomux          = {
1158             .name       = "bt_poweron",
1159             .fgpio      = GPIO3_C7,
1160         },
1161     },
1162
1163     .reset_gpio         = { // BT_RST
1164         .io             = RK30_PIN3_PA0, // set io to INVALID_GPIO for disable it
1165         .enable         = GPIO_LOW,
1166         .iomux          = {
1167             .name       = "bt_reset",
1168             .fgpio      = GPIO3_A0,
1169        },
1170    }, 
1171
1172     .wake_gpio          = { // BT_WAKE, use to control bt's sleep and wakeup
1173         .io             = RK30_PIN3_PB0, // set io to INVALID_GPIO for disable it
1174         .enable         = GPIO_HIGH,
1175         .iomux          = {
1176             .name       = "bt_wake",
1177             .fgpio      = GPIO3_B0,
1178         },
1179     },
1180
1181     .wake_host_irq      = { // BT_HOST_WAKE, for bt wakeup host when it is in deep sleep
1182         .gpio           = {
1183             .io         = RK30_PIN3_PB1, // set io to INVALID_GPIO for disable it
1184             .enable     = GPIO_LOW,      // set GPIO_LOW for falling, set 0 for rising
1185             .iomux      = {
1186                 .name   = NULL,
1187             },
1188         },
1189     },
1190
1191     .rts_gpio           = { // UART_RTS, enable or disable BT's data coming
1192         .io             = RK30_PIN1_PA3, // set io to INVALID_GPIO for disable it
1193         .enable         = GPIO_LOW,
1194         .iomux          = {
1195             .name       = "bt_rts",
1196             .fgpio      = GPIO1_A3,
1197             .fmux       = UART0_RTSN,
1198         },
1199     },
1200 };
1201
1202 static struct platform_device device_rfkill_rk = {
1203     .name   = "rfkill_rk",
1204     .id     = -1,
1205     .dev    = {
1206         .platform_data = &rfkill_rk_platdata,
1207     },
1208 };
1209 #endif
1210
1211 #if defined(CONFIG_GPS_RK)
1212 int rk_gps_io_init(void)
1213 {
1214         printk("%s \n", __FUNCTION__);
1215         
1216         rk30_mux_api_set(GPIO1B5_UART3RTSN_NAME, GPIO1B_GPIO1B5);//VCC_EN
1217         gpio_request(RK30_PIN1_PB5, NULL);
1218         gpio_direction_output(RK30_PIN1_PB5, GPIO_LOW);
1219
1220         rk30_mux_api_set(GPIO1B4_UART3CTSN_GPSRFCLK_NAME, GPIO1B_GPSRFCLK);//GPS_CLK
1221         rk30_mux_api_set(GPIO1B2_UART3SIN_GPSMAG_NAME, GPIO1B_GPSMAG);//GPS_MAG
1222         rk30_mux_api_set(GPIO1B3_UART3SOUT_GPSSIG_NAME, GPIO1B_GPSSIG);//GPS_SIGN
1223
1224         rk30_mux_api_set(GPIO1A6_UART1CTSN_SPI0CLK_NAME, GPIO1A_GPIO1A6);//SPI_CLK
1225         gpio_request(RK30_PIN1_PA6, NULL);
1226         gpio_direction_output(RK30_PIN1_PA6, GPIO_LOW);
1227
1228         rk30_mux_api_set(GPIO1A5_UART1SOUT_SPI0TXD_NAME, GPIO1A_GPIO1A5);//SPI_MOSI
1229         gpio_request(RK30_PIN1_PA5, NULL);
1230         gpio_direction_output(RK30_PIN1_PA5, GPIO_LOW); 
1231
1232         rk30_mux_api_set(GPIO1A7_UART1RTSN_SPI0CSN0_NAME, GPIO1A_GPIO1A7);//SPI_CS
1233         gpio_request(RK30_PIN1_PA7, NULL);
1234         gpio_direction_output(RK30_PIN1_PA7, GPIO_LOW);         
1235         return 0;
1236 }
1237 int rk_gps_power_up(void)
1238 {
1239         printk("%s \n", __FUNCTION__);
1240
1241         return 0;
1242 }
1243
1244 int rk_gps_power_down(void)
1245 {
1246         printk("%s \n", __FUNCTION__);
1247
1248         return 0;
1249 }
1250
1251 int rk_gps_reset_set(int level)
1252 {
1253         return 0;
1254 }
1255 int rk_enable_hclk_gps(void)
1256 {
1257         printk("%s \n", __FUNCTION__);
1258         clk_enable(clk_get(NULL, "hclk_gps"));
1259         return 0;
1260 }
1261 int rk_disable_hclk_gps(void)
1262 {
1263         printk("%s \n", __FUNCTION__);
1264         clk_disable(clk_get(NULL, "hclk_gps"));
1265         return 0;
1266 }
1267 struct rk_gps_data rk_gps_info = {
1268         .io_init = rk_gps_io_init,
1269         .power_up = rk_gps_power_up,
1270         .power_down = rk_gps_power_down,
1271         .reset = rk_gps_reset_set,
1272         .enable_hclk_gps = rk_enable_hclk_gps,
1273         .disable_hclk_gps = rk_disable_hclk_gps,
1274         .GpsSign = RK30_PIN1_PB3,
1275         .GpsMag = RK30_PIN1_PB2,        //GPIO index
1276         .GpsClk = RK30_PIN1_PB4,        //GPIO index
1277         .GpsVCCEn = RK30_PIN1_PB5,     //GPIO index
1278         .GpsSpi_CSO = RK30_PIN1_PA4,    //GPIO index
1279         .GpsSpiClk = RK30_PIN1_PA5,     //GPIO index
1280         .GpsSpiMOSI = RK30_PIN1_PA7,      //GPIO index
1281         .GpsIrq = IRQ_GPS,
1282         .GpsSpiEn = 0,
1283         .GpsAdcCh = 2,
1284         .u32GpsPhyAddr = RK30_GPS_PHYS,
1285         .u32GpsPhySize = RK30_GPS_SIZE,
1286 };
1287
1288 struct platform_device rk_device_gps = {
1289         .name = "gps_hv5820b",
1290         .id = -1,
1291         .dev            = {
1292         .platform_data = &rk_gps_info,
1293                 }
1294         };
1295 #endif
1296
1297 #if defined(CONFIG_MT5931_MT6622)
1298 static struct mt6622_platform_data mt6622_platdata = {
1299                     .power_gpio         = { // BT_REG_ON
1300                       #if DS1006H_V1_2_SUPPORT
1301                     .io             = RK30_PIN3_PC7, // set io to INVALID_GPIO for disable it
1302                       #else
1303                         .io             = RK30_PIN3_PD5, // set io to INVALID_GPIO for disable it
1304                         #endif
1305                             .enable         = GPIO_HIGH,
1306                             .iomux          = {
1307                                     .name       = NULL,
1308                                 },
1309                     },
1310
1311                     .reset_gpio         = { // BT_RST
1312                         #if DS1006H_V1_2_SUPPORT
1313                     .io             = RK30_PIN3_PD1,
1314                         #else
1315                         .io             = RK30_PIN0_PD7,
1316                         #endif
1317                         .enable         = GPIO_HIGH,
1318                         .iomux          = {
1319                             .name       = NULL,
1320                         },
1321                     },
1322
1323                     .irq_gpio           = {
1324                           #if DS1006H_V1_2_SUPPORT
1325                        .io             = RK30_PIN0_PA5,
1326                           #else
1327                             .io             = RK30_PIN3_PD2,
1328                             #endif
1329                             .enable         = GPIO_HIGH,
1330                             .iomux          = {
1331                                     .name       = NULL,
1332                                 },
1333                     }
1334 };
1335
1336 static struct platform_device device_mt6622 = {
1337                     .name   = "mt6622",
1338                         .id     = -1,
1339                         .dev    = {
1340                                .platform_data = &mt6622_platdata,
1341                         },
1342 };      
1343 #endif
1344
1345 #if defined CONFIG_TCC_BT_DEV
1346 static struct tcc_bt_platform_data tcc_bt_platdata = {
1347
1348     .power_gpio   = { // ldoon
1349         .io             =  RK2928_PIN3_PC0,
1350         .enable         = GPIO_HIGH,
1351         .iomux          = {
1352             .name       = NULL,
1353             },
1354         },
1355
1356     .wake_host_gpio  = { // BT_HOST_WAKE, for bt wakeup host when it is in deep sleep
1357         .io         = RK2928_PIN0_PC5, // set io to INVALID_GPIO for disable it
1358         .enable     = IRQF_TRIGGER_RISING,// set IRQF_TRIGGER_FALLING for falling, set IRQF_TRIGGER_RISING for rising
1359         .iomux      = {
1360             .name       = NULL,
1361         },
1362     },
1363 };
1364
1365 static struct platform_device device_tcc_bt = {
1366     .name   = "tcc_bt_dev",
1367     .id     = -1,
1368     .dev    = {
1369         .platform_data = &tcc_bt_platdata,
1370         },
1371 };
1372 #endif
1373
1374 #if defined(CONFIG_AC_USB_SWITCH)
1375 static struct ac_usb_switch_platform_data  ac_usb_switch_platdata= {
1376         .usb_switch_pin = RK30_PIN3_PB2,
1377         .pc_state_pin = INVALID_GPIO,
1378 };
1379 static struct platform_device device_ac_usb_switch = {
1380         .name   = "ac_usb_switch",
1381         .id     = -1,
1382         .dev    = {
1383         .platform_data = &ac_usb_switch_platdata,
1384         },
1385 };
1386 #endif
1387
1388 static struct platform_device *devices[] __initdata = {
1389
1390 #ifdef CONFIG_ION
1391         &device_ion,
1392 #endif
1393 #ifdef CONFIG_WIFI_CONTROL_FUNC
1394         &rk29sdk_wifi_device,
1395 #endif
1396
1397 #if defined(CONFIG_MT6620)
1398             &mt3326_device_gps,
1399 #endif
1400
1401 #ifdef CONFIG_BATTERY_RK30_ADC_FAC
1402         &rk30_device_adc_battery,
1403 #endif
1404 #ifdef CONFIG_RFKILL_RK
1405         &device_rfkill_rk,
1406 #endif
1407 #ifdef CONFIG_GPS_RK
1408         &rk_device_gps,
1409 #endif
1410 #ifdef CONFIG_MT5931_MT6622
1411         &device_mt6622,
1412 #endif
1413 #if defined(CONFIG_MT6229)
1414         &rk29_device_mt6229,
1415 #endif
1416 #if defined(CONFIG_ARCH_RK3188)
1417         &device_mali,
1418 #endif
1419
1420 #ifdef CONFIG_TCC_BT_DEV
1421         &device_tcc_bt,
1422 #endif
1423 #if defined(CONFIG_AC_USB_SWITCH)
1424         &device_ac_usb_switch,
1425 #endif
1426 #ifdef CONFIG_RK_REMOTECTL      
1427     &rk30_device_remotectl,
1428 #endif
1429
1430 };
1431
1432
1433 static int rk_platform_add_display_devices(void)
1434 {
1435         struct platform_device *fb = NULL;  //fb
1436         struct platform_device *lcdc0 = NULL; //lcdc0
1437         struct platform_device *lcdc1 = NULL; //lcdc1
1438         struct platform_device *bl = NULL; //backlight
1439 #ifdef CONFIG_FB_ROCKCHIP
1440         fb = &device_fb;
1441 #endif
1442
1443 #if defined(CONFIG_LCDC0_RK3188)
1444         lcdc0 = &device_lcdc0,
1445 #endif
1446
1447 #if defined(CONFIG_LCDC1_RK3188)
1448         lcdc1 = &device_lcdc1,
1449 #endif
1450
1451 #ifdef CONFIG_BACKLIGHT_RK29_BL
1452         bl = &rk29_device_backlight,
1453 #endif
1454         __rk_platform_add_display_devices(fb,lcdc0,lcdc1,bl);
1455
1456         return 0;
1457         
1458 }
1459
1460 // i2c
1461 #ifdef CONFIG_I2C0_RK30
1462 static struct i2c_board_info __initdata i2c0_info[] = {
1463 #if defined (CONFIG_GS_MMA8452)
1464         {
1465                 .type           = "gs_mma8452",
1466                 .addr           = 0x1d,
1467                 .flags          = 0,
1468                 .irq            = MMA8452_INT_PIN,
1469                 .platform_data = &mma8452_info,
1470         },
1471 #endif
1472
1473 #if defined (CONFIG_GS_LIS3DH)
1474         {
1475                 .type           = "gs_lis3dh",
1476                 .addr           = 0x19,   //0x19(SA0-->VCC), 0x18(SA0-->GND)
1477                 .flags          = 0,
1478                 .irq            = LIS3DH_INT_PIN,
1479                 .platform_data = &lis3dh_info,
1480         },
1481 #endif
1482 #if defined (CONFIG_COMPASS_AK8963)
1483         {
1484                 .type          = "ak8963",
1485                 .addr          = 0x0d,
1486                 .flags         = 0,
1487                 .irq           = RK30_PIN3_PD7, 
1488                 .platform_data = &akm8963_info,
1489         },
1490 #endif
1491
1492 #if defined (CONFIG_LS_PHOTORESISTOR)
1493         {
1494                 .type           = "ls_photoresistor",
1495                 .addr           = 0x5e,            
1496                 .flags          = 0,
1497                 .irq            = INVALID_GPIO, 
1498                 .platform_data = &light_photoresistor_info,
1499         },
1500 #endif
1501
1502 #if defined (CONFIG_COMPASS_AK8975)
1503         {
1504                 .type          = "ak8975",
1505                 .addr          = 0x0d,
1506                 .flags         = 0,
1507                 .irq           = RK30_PIN3_PD7, 
1508                 .platform_data = &akm8975_info,
1509                 .irq           = RK30_PIN3_PD7, 
1510                 .platform_data = &akm8975_info,
1511         },
1512 #endif
1513 #if defined (CONFIG_GYRO_L3G4200D)
1514         {
1515                 .type          = "l3g4200d_gryo",
1516                 .addr          = 0x69,
1517                 .flags         = 0,
1518                 .irq           = L3G4200D_INT_PIN,
1519                 .platform_data = &l3g4200d_info,
1520         },
1521 #endif
1522 #if defined (CONFIG_SND_SOC_RK1000)
1523         {
1524                 .type          = "rk1000_i2c_codec",
1525                 .addr          = 0x60,
1526                 .flags         = 0,
1527         },
1528         {
1529                 .type          = "rk1000_control",
1530                 .addr          = 0x40,
1531                 .flags         = 0,
1532         },
1533 #endif
1534 #if defined (CONFIG_SND_SOC_CX2070X)
1535         {
1536                 .type                   = "cx2070x",
1537                 .addr                   = 0x14,
1538                 .flags                  = 0,
1539         },
1540 #endif
1541 };
1542 #endif
1543
1544 int __sramdata g_pmic_type =  0;
1545 #ifdef CONFIG_I2C1_RK30
1546 #ifdef CONFIG_REGULATOR_ACT8846
1547 #define PMU_POWER_SLEEP RK30_PIN0_PD1
1548 #define PMU_VSEL RK30_PIN3_PD3
1549 #define ACT8846_HOST_IRQ                RK30_PIN0_PB3
1550
1551 static struct pmu_info  act8846_dcdc_info[] = {
1552         {
1553                 .name          = "act_dcdc1",   //ddr
1554                 .min_uv          = 1200000,
1555                 .max_uv         = 1200000,
1556                 .suspend_vol  =   1200000,
1557         },
1558         {
1559                 .name          = "vdd_core",    //logic
1560                 .min_uv          = 1000000,
1561                 .max_uv         = 1000000,
1562                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1563                 .suspend_vol  =  1200000,
1564                 #else
1565                 .suspend_vol  =  900000,
1566                 #endif
1567         },
1568         {
1569                 .name          = "vdd_cpu",   //arm
1570                 .min_uv          = 1000000,
1571                 .max_uv         = 1000000,
1572                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1573                 .suspend_vol  =  1200000,
1574                 #else
1575                 .suspend_vol  =  900000,
1576                 #endif
1577         },
1578         {
1579                 .name          = "act_dcdc4",   //vccio
1580                 .min_uv          = 3000000,
1581                 .max_uv         = 3000000,
1582                 #ifdef CONFIG_ACT8846_SUPPORT_RESET
1583                 .suspend_vol  =  3000000,
1584                 #else
1585                 .suspend_vol  =  2800000,
1586                 #endif
1587         },
1588         
1589 };
1590 static  struct pmu_info  act8846_ldo_info[] = {
1591         {
1592                 .name          = "act_ldo1",   //vdd10
1593                 .min_uv          = 1000000,
1594                 .max_uv         = 1000000,
1595         },
1596         {
1597                 .name          = "act_ldo2",    //vdd12
1598                 .min_uv          = 1200000,
1599                 .max_uv         = 1200000,
1600         },
1601         {
1602                 .name          = "act_ldo3",   //vcc18_cif
1603                 .min_uv          = 1800000,
1604                 .max_uv         = 1800000,
1605         },
1606         {
1607                 .name          = "act_ldo4",   //vcca33
1608                 .min_uv          = 3300000,
1609                 .max_uv         = 3300000,
1610         },
1611         {
1612                 .name          = "act_ldo5",   //vcctp
1613                 .min_uv          = 3300000,
1614                 .max_uv         = 3300000,
1615         },
1616         {
1617                 .name          = "act_ldo6",   //vcc_jetta
1618                 .min_uv          = 3300000,
1619                 .max_uv         = 3300000,
1620         },
1621         {
1622                 .name          = "act_ldo7",   //vcc18
1623                 .min_uv          = 1800000,
1624                 .max_uv         = 1800000,
1625         },
1626         {
1627                 .name          = "act_ldo8",   //vcc28_cif
1628                 .min_uv          = 2800000,
1629                 .max_uv         = 2800000,
1630         },
1631  };
1632
1633 #include "../mach-rk30/board-pmu-act8846.c"
1634 #endif
1635
1636 #ifdef CONFIG_MFD_WM831X_I2C
1637 #define PMU_POWER_SLEEP                 RK30_PIN0_PA1 
1638
1639 static struct pmu_info  wm8326_dcdc_info[] = {
1640         {
1641                 .name          = "vdd_core",   //logic
1642                 .min_uv          = 1000000,
1643                 .max_uv         = 1000000,
1644                 .suspend_vol  =  950000,
1645         },
1646         {
1647                 .name          = "vdd_cpu",    //arm
1648                 .min_uv          = 1000000,
1649                 .max_uv         = 1000000,
1650                 .suspend_vol  =  950000,
1651         },
1652         {
1653                 .name          = "dcdc3",   //ddr
1654                 .min_uv          = 1150000,
1655                 .max_uv         = 1150000,
1656                 .suspend_vol  =  1150000,
1657         },
1658         #ifdef CONFIG_MACH_RK3066_SDK
1659         {
1660                 .name          = "dcdc4",   //vcc_io
1661                 .min_uv          = 3300000,
1662                 .max_uv         = 3300000,
1663                 .suspend_vol  =  3000000,
1664         },
1665         #else
1666         {
1667                 .name          = "dcdc4",   //vcc_io
1668                 .min_uv          = 3000000,
1669                 .max_uv         = 3000000,
1670                 .suspend_vol  =  2800000,
1671         },
1672         #endif
1673 };
1674
1675 static struct pmu_info  wm8326_ldo_info[] = {
1676         {
1677                 .name          = "ldo1",   //vcc18_cif
1678                 .min_uv          = 1800000,
1679                 .max_uv         = 1800000,
1680                 .suspend_vol  =  1800000,
1681         },
1682         {
1683                 .name          = "ldo2",    //vccio_wl
1684                 .min_uv          = 1800000,
1685                 .max_uv         = 1800000,
1686                 .suspend_vol  =  1800000,
1687         },
1688         {
1689                 .name          = "ldo3",   //
1690                 .min_uv          = 1100000,
1691                 .max_uv         = 1100000,
1692                 .suspend_vol  =  1100000,
1693         },
1694         {
1695                 .name          = "ldo4",   //vdd11
1696                 .min_uv          = 1000000,
1697                 .max_uv         = 1000000,
1698                 .suspend_vol  =  1000000,
1699         },
1700         {
1701                 .name          = "ldo5",   //vcc25
1702                 .min_uv          = 1800000,
1703                 .max_uv         = 1800000,
1704                 .suspend_vol  =  1800000,
1705         },
1706         {
1707                 .name          = "ldo6",   //vcc33
1708                 .min_uv          = 3300000,
1709                 .max_uv         = 3300000,
1710                 .suspend_vol  =  3300000,
1711         },
1712         {
1713                 .name          = "ldo7",   //vcc28_cif
1714                 .min_uv          = 2800000,
1715                 .max_uv         = 2800000,
1716                 .suspend_vol  =  2800000,
1717         },
1718         {
1719                 .name          = "ldo8",   //vcca33
1720                 .min_uv          = 3300000,
1721                 .max_uv         = 3300000,
1722                 .suspend_vol  =  3300000,
1723         },
1724         {
1725                 .name          = "ldo9",   //vcc_tp
1726                 .min_uv          = 3300000,
1727                 .max_uv         = 3300000,
1728                 .suspend_vol  =  3300000,
1729         },
1730         {
1731                 .name          = "ldo10",   //flash_io
1732                 .min_uv          = 1800000,
1733                 .max_uv         = 1800000,
1734                 .suspend_vol  =  1800000,
1735         },
1736 };
1737
1738 #include "../mach-rk30/board-pmu-wm8326.c"
1739 #endif
1740
1741 #ifdef CONFIG_MFD_TPS65910
1742 #ifdef CONFIG_ARCH_RK3188
1743 #define TPS65910_HOST_IRQ        RK30_PIN0_PB3
1744 #else
1745 #define TPS65910_HOST_IRQ        RK30_PIN6_PA4
1746 #endif
1747
1748 #define PMU_POWER_SLEEP RK30_PIN0_PA1
1749
1750 static struct pmu_info  tps65910_dcdc_info[] = {
1751         {
1752                 .name          = "vdd_core",   //logic
1753                 .min_uv          = 1100000,
1754                 .max_uv         = 1100000,
1755         },
1756         {
1757                 .name          = "vdd2",    //ddr
1758                 .min_uv          = 1200000,
1759                 .max_uv         = 1200000,
1760         },
1761         {
1762                 .name          = "vio",   //vcc_io
1763                 .min_uv          = 2500000,
1764                 .max_uv         = 2500000,
1765         },
1766         
1767 };
1768 static  struct pmu_info  tps65910_ldo_info[] = {
1769         {
1770                 .name          = "vpll",   //vdd10
1771                 .min_uv          = 1000000,
1772                 .max_uv         = 1000000,
1773         },
1774         {
1775                 .name          = "vdig1",    //vcc18_cif
1776                 .min_uv          = 1800000,
1777                 .max_uv         = 1800000,
1778         },
1779         {
1780                 .name          = "vdig2",   //vdd_jetta
1781                 .min_uv          = 1200000,
1782                 .max_uv         = 1200000,
1783         },
1784         {
1785                 .name          = "vaux1",   //vcc28_cif
1786                 .min_uv          = 2800000,
1787                 .max_uv         = 2800000,
1788         },
1789         {
1790                 .name          = "vaux2",   //vcca33
1791                 .min_uv          = 3300000,
1792                 .max_uv         = 3300000,
1793         },
1794         {
1795                 .name          = "vaux33",   //vcc_tp
1796                 .min_uv          = 3300000,
1797                 .max_uv         = 3300000,
1798         },
1799         {
1800                 .name          = "vmmc",   //vcc30
1801                 .min_uv          = 3000000,
1802                 .max_uv         = 3000000,
1803         },
1804         {
1805                 .name          = "vdac",   //vcc18
1806                 .min_uv          = 1800000,
1807                 .max_uv         = 1800000,
1808         },
1809  };
1810
1811 #include "../mach-rk30/board-pmu-tps65910.c"
1812 #endif
1813
1814 #if defined(CONFIG_SCALER_TV5735)
1815 struct scaler_output_port tv_oports[] ={
1816         {
1817                 .led_gpio = INVALID_GPIO,
1818                 .type = SCALER_OUT_VGA,
1819         },
1820 };
1821
1822 struct scaler_input_port tv_iports[] = {
1823         {//rk
1824                 .led_gpio = RK30_PIN0_PD4,
1825                 .type = SCALER_IN_RGB,
1826         },
1827         {//pc
1828                 .led_gpio = RK30_PIN0_PD5,
1829                 .type = SCALER_IN_VGA,
1830         }
1831 };
1832
1833 struct scaler_platform_data tv5735_data = {
1834         .func_type     = SCALER_FUNC_FULL,
1835
1836         .iports        = tv_iports,
1837         .iport_size    = ARRAY_SIZE(tv_iports),
1838
1839         .oports        = tv_oports,
1840         .oport_size    = ARRAY_SIZE(tv_oports),
1841
1842         .power_gpio    = RK30_PIN2_PD7,
1843         .power_level   = GPIO_HIGH,
1844         .vga5v_gpio    = RK30_PIN3_PD7,
1845         .vga5v_level   = GPIO_HIGH,
1846         .ddc_sel_gpio  = RK30_PIN0_PB4,
1847         .ddc_sel_level = GPIO_HIGH, //set default input port 
1848         .vga_hsync_gpio= RK30_PIN0_PA1,
1849         .vga_vsync_gpio= RK30_PIN0_PA5,
1850 };
1851 #endif
1852
1853 #if defined(CONFIG_SCALER_TEST) 
1854 //the fisrt port is default 
1855 struct scaler_output_port tst_oports[] ={
1856         {
1857                 .led_gpio = INVALID_GPIO,
1858                 .type = SCALER_OUT_VGA,
1859         },
1860 };
1861
1862 //the fisrt port is default 
1863 struct scaler_input_port tst_iports[] = {
1864         {
1865                 //RK
1866                 .led_gpio = RK30_PIN0_PD4,
1867                 .type = SCALER_IN_VGA,
1868         },
1869         {
1870                 //pc
1871                 .led_gpio = RK30_PIN0_PD5,
1872                 .type = SCALER_IN_VGA,
1873         },
1874 };
1875
1876 static void test_init_hw(void)
1877 {
1878         //xn223
1879         if (!gpio_request(RK30_PIN1_PD6, NULL))
1880                 gpio_direction_output(RK30_PIN1_PD6, GPIO_HIGH); 
1881         else
1882                 printk("%s: request XNN223_PWN gpio failed\n", __func__);
1883 }
1884
1885 struct scaler_platform_data test_data = {
1886         .func_type     = SCALER_FUNC_SWITCH,
1887
1888         .iports        = tst_iports,
1889         .iport_size    = ARRAY_SIZE(tst_iports),
1890         .oports        = tst_oports,
1891         .oport_size    = ARRAY_SIZE(tst_oports),
1892
1893         .power_gpio    = RK30_PIN2_PD7,
1894         .power_level   = GPIO_HIGH,
1895         .vga5v_gpio    = RK30_PIN3_PD7,
1896         .vga5v_level   = GPIO_HIGH,
1897         .ddc_sel_gpio  = RK30_PIN0_PB4,
1898         .ddc_sel_level = GPIO_HIGH,
1899         //func
1900         .init_hw       = test_init_hw,
1901 };
1902 #endif
1903
1904 static struct i2c_board_info __initdata i2c1_info[] = {
1905 #if defined(CONFIG_SCALER_TEST) 
1906         {
1907                 .type           = "aswitch",
1908                 .addr           = 0x57,
1909                 .flags          = 0,
1910                 .platform_data = &test_data,
1911         },
1912 #endif
1913 #if defined (CONFIG_REGULATOR_ACT8846)
1914         {
1915                 .type                   = "act8846",
1916                 .addr           = 0x5a, 
1917                 .flags                  = 0,
1918                 .irq            = ACT8846_HOST_IRQ,
1919                 .platform_data=&act8846_data,
1920         },
1921 #endif
1922 #if defined (CONFIG_RTC_HYM8563)
1923         {
1924                 .type                   = "rtc_hym8563",
1925                 .addr           = 0x51,
1926                 .flags                  = 0,
1927                 .irq            = RK30_PIN0_PB5,
1928         },
1929 #endif
1930 #if defined (CONFIG_MFD_WM831X_I2C)
1931         {
1932                 .type          = "wm8326",
1933                 .addr          = 0x34,
1934                 .flags         = 0,
1935                 .irq           = RK30_PIN0_PB3,
1936                 .platform_data = &wm831x_platdata,
1937         },
1938 #endif
1939 #if defined (CONFIG_MFD_TPS65910)
1940         {
1941         .type           = "tps65910",
1942         .addr           = TPS65910_I2C_ID0,
1943         .flags          = 0,
1944         .irq            = TPS65910_HOST_IRQ,
1945         .platform_data = &tps65910_data,
1946         },
1947 #endif
1948 };
1949 #endif
1950
1951 void __sramfunc board_pmu_suspend(void)
1952 {      
1953         #if defined (CONFIG_REGULATOR_ACT8846)
1954        if(pmic_is_act8846())
1955        board_pmu_act8846_suspend(); 
1956        #endif
1957         #if defined (CONFIG_MFD_WM831X_I2C)
1958        if(pmic_is_wm8326())
1959        board_pmu_wm8326_suspend();
1960         #endif
1961         #if defined (CONFIG_MFD_TPS65910)
1962        if(pmic_is_tps65910())
1963        board_pmu_tps65910_suspend(); 
1964     #endif   
1965 }
1966
1967 void __sramfunc board_pmu_resume(void)
1968 {      
1969         #if defined (CONFIG_REGULATOR_ACT8846)
1970        if(pmic_is_act8846())
1971        board_pmu_act8846_resume(); 
1972        #endif
1973         #if defined (CONFIG_MFD_WM831X_I2C)
1974        if(pmic_is_wm8326())
1975        board_pmu_wm8326_resume();
1976         #endif
1977         #if defined (CONFIG_MFD_TPS65910)
1978        if(pmic_is_tps65910())
1979        board_pmu_tps65910_resume(); 
1980         #endif
1981 }
1982
1983  int __sramdata gpio3d6_iomux,gpio3d6_do,gpio3d6_dir,gpio3d6_en;
1984
1985 #define grf_readl(offset)       readl_relaxed(RK30_GRF_BASE + offset)
1986 #define grf_writel(v, offset)   do { writel_relaxed(v, RK30_GRF_BASE + offset); dsb(); } while (0)
1987  
1988 void __sramfunc rk30_pwm_logic_suspend_voltage(void)
1989 {
1990 #ifdef CONFIG_RK30_PWM_REGULATOR
1991
1992 //      int gpio0d7_iomux,gpio0d7_do,gpio0d7_dir,gpio0d7_en;
1993         sram_udelay(10000);
1994         gpio3d6_iomux = grf_readl(GRF_GPIO3D_IOMUX);
1995         gpio3d6_do = grf_readl(GRF_GPIO3H_DO);
1996         gpio3d6_dir = grf_readl(GRF_GPIO3H_DIR);
1997         gpio3d6_en = grf_readl(GRF_GPIO3H_EN);
1998
1999         grf_writel((1<<28), GRF_GPIO3D_IOMUX);
2000         grf_writel((1<<30)|(1<<14), GRF_GPIO3H_DIR);
2001         grf_writel((1<<30)|(1<<14), GRF_GPIO3H_DO);
2002         grf_writel((1<<30)|(1<<14), GRF_GPIO3H_EN);
2003 #endif 
2004 }
2005 void __sramfunc rk30_pwm_logic_resume_voltage(void)
2006 {
2007 #ifdef CONFIG_RK30_PWM_REGULATOR
2008         grf_writel((1<<28)|gpio3d6_iomux, GRF_GPIO3D_IOMUX);
2009         grf_writel((1<<30)|gpio3d6_en, GRF_GPIO3H_EN);
2010         grf_writel((1<<30)|gpio3d6_dir, GRF_GPIO3H_DIR);
2011         grf_writel((1<<30)|gpio3d6_do, GRF_GPIO3H_DO);
2012         sram_udelay(10000);
2013
2014 #endif
2015
2016 }
2017 extern void pwm_suspend_voltage(void);
2018 extern void pwm_resume_voltage(void);
2019 void  rk30_pwm_suspend_voltage_set(void)
2020 {
2021 #ifdef CONFIG_RK30_PWM_REGULATOR
2022         pwm_suspend_voltage();
2023 #endif
2024 }
2025 void  rk30_pwm_resume_voltage_set(void)
2026 {
2027 #ifdef CONFIG_RK30_PWM_REGULATOR
2028         pwm_resume_voltage();
2029 #endif
2030 }
2031
2032
2033 #ifdef CONFIG_I2C2_RK30
2034 static struct i2c_board_info __initdata i2c2_info[] = {
2035 #if defined(CONFIG_SCALER_TV5735) 
2036         {
2037                 .type           = "tv5735",
2038                 .addr           = 0x57,
2039                 .flags          = 0,
2040                 .platform_data = &tv5735_data,
2041         },
2042 #endif
2043 #if defined(CONFIG_SCALER_DEVICE_DDC) 
2044         {
2045                 .type           = "scaler_ddc",
2046                 .addr           = 0x50,
2047                 .flags          = 0,
2048         },
2049 #endif
2050 #if defined (CONFIG_CT36X_TS)
2051         {
2052                 .type          = CT36X_NAME,
2053                 .addr          = 0x01,
2054                 .flags         = 0,
2055                 .platform_data = &ct36x_info,
2056         },
2057 #endif
2058 #if defined (CONFIG_LS_CM3217)
2059         {
2060                 .type          = "lightsensor",
2061                 .addr          = 0x10,
2062                 .flags         = 0,
2063                 .platform_data = &cm3217_info,
2064         },
2065 #endif
2066 #if defined (CONFIG_LS_US5151)
2067         {    
2068                 .type           = "us5151",
2069                 .addr           = 0x10,
2070                 .flags          = 0, 
2071         },   
2072 #endif
2073
2074 #if defined(CONFIG_HDMI_CAT66121)
2075         {
2076                 .type           = "cat66121_hdmi",
2077                 .addr           = 0x4c,
2078                 .flags          = 0,
2079                 .irq            = RK30_PIN2_PD6,
2080                 .platform_data  = &rk_hdmi_pdata,
2081         },
2082 #endif
2083 };
2084 #endif
2085
2086 #ifdef CONFIG_I2C3_RK30
2087 static struct i2c_board_info __initdata i2c3_info[] = {
2088 };
2089 #endif
2090
2091 #ifdef CONFIG_I2C4_RK30
2092 static struct i2c_board_info __initdata i2c4_info[] = {
2093 #ifdef CONFIG_MFD_RK610
2094                 {
2095                         .type                   = "rk610_ctl",
2096                         .addr                   = 0x40,
2097                         .flags                  = 0,
2098                         .platform_data          = &rk610_ctl_pdata,
2099                 },
2100 #ifdef CONFIG_RK610_TVOUT
2101                 {
2102                         .type                   = "rk610_tvout",
2103                         .addr                   = 0x42,
2104                         .flags                  = 0,
2105                 },
2106 #endif
2107 #ifdef CONFIG_HDMI_RK610
2108                 {
2109                         .type                   = "rk610_hdmi",
2110                         .addr                   = 0x46,
2111                         .flags                  = 0,
2112                         .irq                    = INVALID_GPIO,
2113                 },
2114 #endif
2115 #ifdef CONFIG_SND_SOC_RK610
2116                 {//RK610_CODEC addr  from 0x60 to 0x80 (0x60~0x80)
2117                         .type                   = "rk610_i2c_codec",
2118                         .addr                   = 0x60,
2119                         .flags                  = 0,
2120                         .platform_data          = &rk610_codec_pdata,                   
2121                 },
2122 #endif
2123 #endif
2124
2125 #if defined (CONFIG_SND_SOC_RT5631)
2126         {
2127                 .type                   = "rt5631",
2128                 .addr                   = 0x1a,
2129                 .flags                  = 0,
2130         },
2131 #endif
2132
2133 };
2134 #endif
2135
2136 #ifdef CONFIG_I2C_GPIO_RK30
2137 #define I2C_SDA_PIN     INVALID_GPIO// RK30_PIN2_PD6   //set sda_pin here
2138 #define I2C_SCL_PIN     INVALID_GPIO//RK30_PIN2_PD7   //set scl_pin here
2139 static int rk30_i2c_io_init(void)
2140 {
2141         //set iomux (gpio) here
2142         //rk30_mux_api_set(GPIO2D7_I2C1SCL_NAME, GPIO2D_GPIO2D7);
2143         //rk30_mux_api_set(GPIO2D6_I2C1SDA_NAME, GPIO2D_GPIO2D6);
2144
2145         return 0;
2146 }
2147 struct i2c_gpio_platform_data default_i2c_gpio_data = {
2148        .sda_pin = I2C_SDA_PIN,
2149        .scl_pin = I2C_SCL_PIN,
2150        .udelay = 5, // clk = 500/udelay = 100Khz
2151        .timeout = 100,//msecs_to_jiffies(100),
2152        .bus_num    = 5,
2153        .io_init = rk30_i2c_io_init,
2154 };
2155 static struct i2c_board_info __initdata i2c_gpio_info[] = {
2156 };
2157 #endif
2158
2159 static void __init rk30_i2c_register_board_info(void)
2160 {
2161 #ifdef CONFIG_I2C0_RK30
2162         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
2163 #endif
2164 #ifdef CONFIG_I2C1_RK30
2165         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
2166 #endif
2167 #ifdef CONFIG_I2C2_RK30
2168         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
2169 #endif
2170 #ifdef CONFIG_I2C3_RK30
2171         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
2172 #endif
2173 #ifdef CONFIG_I2C4_RK30
2174         i2c_register_board_info(4, i2c4_info, ARRAY_SIZE(i2c4_info));
2175 #endif
2176 #ifdef CONFIG_I2C_GPIO_RK30
2177         i2c_register_board_info(5, i2c_gpio_info, ARRAY_SIZE(i2c_gpio_info));
2178 #endif
2179 }
2180 //end of i2c
2181
2182 #define POWER_ON_PIN RK30_PIN0_PA0   //power_hold
2183 static void rk30_pm_power_off(void)
2184 {
2185         printk(KERN_ERR "rk30_pm_power_off start...\n");
2186 #if defined(CONFIG_MFD_WM831X)
2187         wm831x_set_bits(Wm831x,WM831X_GPIO_LEVEL,0x0001,0x0000);  //set sys_pwr 0
2188         wm831x_device_shutdown(Wm831x);//wm8326 shutdown
2189 #endif
2190 #if defined(CONFIG_REGULATOR_ACT8846)
2191        if (pmic_is_act8846()) {
2192                printk("enter dcdet===========\n");
2193                if(gpio_get_value (RK30_PIN0_PB2) == GPIO_LOW)
2194                {
2195                        printk("enter restart===========\n");
2196                        arm_pm_restart(0, "charge");
2197                }
2198                 /** code here may cause tablet cannot boot when shutdown without charger pluged in
2199                   * and then plug in charger. -- Cody Xie
2200                else
2201                 {
2202                         act8846_device_shutdown();
2203                 }
2204                   */
2205        }
2206 #endif
2207         gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
2208         while (1);
2209 }
2210
2211 static void __init machine_rk30_board_init(void)
2212 {
2213         //avs_init();
2214         gpio_request(POWER_ON_PIN, "poweronpin");
2215         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
2216         
2217         pm_power_off = rk30_pm_power_off;
2218         
2219         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
2220
2221
2222         rk30_i2c_register_board_info();
2223         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
2224         platform_add_devices(devices, ARRAY_SIZE(devices));
2225         rk_platform_add_display_devices();
2226         //board_usb_detect_init(RK30_PIN0_PA7);
2227
2228 #ifdef CONFIG_WIFI_CONTROL_FUNC
2229         rk29sdk_wifi_bt_gpio_control_init();
2230 #endif
2231
2232 #if defined(CONFIG_MT6620)
2233             clk_set_rate(clk_get_sys("rk_serial.1", "uart"), 48*1000000);
2234 #endif
2235
2236 #if defined(CONFIG_MT5931_MT6622)
2237                 clk_set_rate(clk_get_sys("rk_serial.0", "uart"), 24*1000000);
2238 #endif          
2239 }
2240
2241 #define HD_SCREEN_SIZE 1920UL*1200UL*4*3
2242 static void __init rk30_reserve(void)
2243 {
2244 #if defined(CONFIG_ARCH_RK3188)
2245         /*if lcd resolution great than or equal to 1920*1200,reserve the ump memory */
2246         if(!(get_fb_size() < ALIGN(HD_SCREEN_SIZE,SZ_1M)))
2247         {
2248                 int ump_mem_phy_size=512UL*1024UL*1024UL; 
2249                 resource_mali[0].start = board_mem_reserve_add("ump buf", ump_mem_phy_size); 
2250                 resource_mali[0].end = resource_mali[0].start + ump_mem_phy_size -1;
2251         }
2252 #endif
2253 #ifdef CONFIG_ION
2254         rk30_ion_pdata.heaps[0].base = board_mem_reserve_add("ion", ION_RESERVE_SIZE);
2255 #endif
2256
2257 #ifdef CONFIG_FB_ROCKCHIP
2258         resource_fb[0].start = board_mem_reserve_add("fb0 buf", get_fb_size());
2259         resource_fb[0].end = resource_fb[0].start + get_fb_size()- 1;
2260 #if 0
2261         resource_fb[1].start = board_mem_reserve_add("ipp buf", RK30_FB0_MEM_SIZE);
2262         resource_fb[1].end = resource_fb[1].start + RK30_FB0_MEM_SIZE - 1;
2263 #endif
2264
2265 #if defined(CONFIG_FB_ROTATE) || !defined(CONFIG_THREE_FB_BUFFER)
2266         resource_fb[2].start = board_mem_reserve_add("fb2 buf",get_fb_size());
2267         resource_fb[2].end = resource_fb[2].start + get_fb_size() - 1;
2268 #endif
2269 #endif
2270
2271
2272 #ifdef CONFIG_VIDEO_RK29
2273         rk30_camera_request_reserve_mem();
2274 #endif
2275         
2276 #ifdef CONFIG_GPS_RK
2277         //it must be more than 8MB
2278         rk_gps_info.u32MemoryPhyAddr = board_mem_reserve_add("gps", SZ_8M);
2279 #endif
2280         board_mem_reserved();
2281 }
2282 /******************************** arm dvfs frequency volt table **********************************/
2283 /**
2284  * dvfs_cpu_logic_table: table for arm and logic dvfs 
2285  * @frequency   : arm frequency
2286  * @cpu_volt    : arm voltage depend on frequency
2287  */
2288
2289 //sdk
2290 static struct cpufreq_frequency_table dvfs_arm_table_volt_level0[] = {
2291         {.frequency = 312 * 1000,       .index = 850 * 1000},
2292         {.frequency = 504 * 1000,       .index = 900 * 1000},
2293         {.frequency = 816 * 1000,       .index = 950 * 1000},
2294         {.frequency = 1008 * 1000,      .index = 1025 * 1000},
2295         {.frequency = 1200 * 1000,      .index = 1100 * 1000},
2296         {.frequency = 1416 * 1000,      .index = 1200 * 1000},
2297         {.frequency = 1608 * 1000,      .index = 1300 * 1000},
2298         {.frequency = CPUFREQ_TABLE_END},
2299 };
2300 //default
2301 static struct cpufreq_frequency_table dvfs_arm_table_volt_level1[] = {
2302         {.frequency = 312 * 1000,       .index = 875 * 1000},
2303         {.frequency = 504 * 1000,       .index = 925 * 1000},
2304         {.frequency = 816 * 1000,       .index = 975 * 1000},
2305         {.frequency = 1008 * 1000,      .index = 1075 * 1000},
2306         {.frequency = 1200 * 1000,      .index = 1150 * 1000},
2307         {.frequency = 1416 * 1000,      .index = 1250 * 1000},
2308         {.frequency = 1608 * 1000,      .index = 1350 * 1000},
2309         {.frequency = CPUFREQ_TABLE_END},
2310 };
2311 // ds1006h 10'
2312 static struct cpufreq_frequency_table dvfs_arm_table_volt_level2[] = {
2313         {.frequency = 312 * 1000,       .index = 900 * 1000},
2314         {.frequency = 504 * 1000,       .index = 925 * 1000},
2315         {.frequency = 816 * 1000,       .index = 1000 * 1000},
2316         {.frequency = 1008 * 1000,      .index = 1075 * 1000},
2317         {.frequency = 1200 * 1000,      .index = 1200 * 1000},
2318         {.frequency = 1416 * 1000,      .index = 1250 * 1000},
2319         {.frequency = 1608 * 1000,      .index = 1350 * 1000},
2320         {.frequency = CPUFREQ_TABLE_END},
2321 };
2322 //if you board is good for volt quality,select dvfs_arm_table_volt_level0
2323 #define dvfs_arm_table dvfs_arm_table_volt_level2
2324
2325 /******************************** gpu dvfs frequency volt table **********************************/
2326 //sdk
2327 static struct cpufreq_frequency_table dvfs_gpu_table_volt_level0[] = {  
2328         {.frequency = 133 * 1000,       .index = 975 * 1000},//the mininum rate is limited 133M for rk3188
2329         {.frequency = 200 * 1000,       .index = 975 * 1000},
2330         {.frequency = 266 * 1000,       .index = 1000 * 1000},
2331         {.frequency = 300 * 1000,       .index = 1050 * 1000},
2332         {.frequency = 400 * 1000,       .index = 1100 * 1000},
2333         {.frequency = 600 * 1000,       .index = 1200 * 1000},
2334         {.frequency = CPUFREQ_TABLE_END},
2335 };
2336 //ds1006h 10'
2337 static struct cpufreq_frequency_table dvfs_gpu_table_volt_level1[] = {  
2338        {.frequency = 133 * 1000,       .index = 975 * 1000},
2339         {.frequency = 200 * 1000,       .index = 1000 * 1000},
2340         {.frequency = 266 * 1000,       .index = 1025 * 1000},
2341         {.frequency = 300 * 1000,       .index = 1050 * 1000},
2342         {.frequency = 400 * 1000,       .index = 1100 * 1000},
2343         {.frequency = 600 * 1000,       .index = 1250 * 1000},
2344         {.frequency = CPUFREQ_TABLE_END},
2345 };
2346
2347 #define dvfs_gpu_table dvfs_gpu_table_volt_level1
2348
2349 /******************************** ddr dvfs frequency volt table **********************************/
2350 static struct cpufreq_frequency_table dvfs_ddr_table_volt_level0[] = {
2351         {.frequency = 200 * 1000 + DDR_FREQ_SUSPEND,    .index = 950 * 1000},
2352         {.frequency = 300 * 1000 + DDR_FREQ_VIDEO,      .index = 1000 * 1000},
2353         //{.frequency = 396 * 1000 + DDR_FREQ_NORMAL,     .index = 1100 * 1000},
2354         {.frequency = 666 * 1000 + DDR_FREQ_NORMAL,     .index = 1250 * 1000},
2355         {.frequency = 666 * 1000 + DDR_FREQ_DUALVIEW,     .index = 1250 * 1000},
2356         //{.frequency = 528 * 1000 + DDR_FREQ_NORMAL,     .index = 1200 * 1000},
2357         {.frequency = CPUFREQ_TABLE_END},
2358 };
2359
2360 static struct cpufreq_frequency_table dvfs_ddr_table_t[] = {
2361         {.frequency = 200 * 1000 + DDR_FREQ_SUSPEND,    .index = 950 * 1000},
2362         //{.frequency = 460 * 1000 + DDR_FREQ_NORMAL,     .index = 1150 * 1000},
2363         {.frequency = 666 * 1000 + DDR_FREQ_NORMAL,     .index = 1250 * 1000},
2364         {.frequency = CPUFREQ_TABLE_END},
2365 };
2366 #define dvfs_ddr_table dvfs_ddr_table_volt_level0
2367
2368 /******************************** arm dvfs frequency volt table end **********************************/
2369
2370
2371
2372 //#define DVFS_CPU_TABLE_SIZE   (ARRAY_SIZE(dvfs_cpu_logic_table))
2373 //static struct cpufreq_frequency_table cpu_dvfs_table[DVFS_CPU_TABLE_SIZE];
2374 //static struct cpufreq_frequency_table dep_cpu2core_table[DVFS_CPU_TABLE_SIZE];
2375 int get_max_freq(struct cpufreq_frequency_table *table)
2376 {
2377         int i,temp=0;
2378         
2379         for(i=0;table[i].frequency!= CPUFREQ_TABLE_END;i++)
2380         {
2381                 if(temp<table[i].frequency)
2382                         temp=table[i].frequency;
2383         }       
2384         printk("get_max_freq=%d\n",temp);
2385         return temp;
2386 }
2387
2388 void __init board_clock_init(void)
2389 {
2390         u32 flags=RK30_CLOCKS_DEFAULT_FLAGS;
2391 #if !defined(CONFIG_ARCH_RK3188)
2392         if(get_max_freq(dvfs_gpu_table)<=(400*1000))
2393         {       
2394                 flags=RK30_CLOCKS_DEFAULT_FLAGS|CLK_GPU_GPLL;
2395         }
2396         else
2397                 flags=RK30_CLOCKS_DEFAULT_FLAGS|CLK_GPU_CPLL;
2398 #endif  
2399         rk30_clock_data_init(periph_pll_default, codec_pll_default, flags);
2400         //dvfs_set_arm_logic_volt(dvfs_cpu_logic_table, cpu_dvfs_table, dep_cpu2core_table);    
2401         dvfs_set_freq_volt_table(clk_get(NULL, "cpu"), dvfs_arm_table);
2402         dvfs_set_freq_volt_table(clk_get(NULL, "gpu"), dvfs_gpu_table);
2403 #if defined(CONFIG_ARCH_RK3188)
2404         if (rk_pll_flag() == 0)
2405                 dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
2406         else
2407                 dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table_t);
2408 #else
2409         dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
2410 #endif
2411 }
2412
2413 MACHINE_START(RK30, "RK30board")
2414         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
2415         .fixup          = rk30_fixup,
2416         .reserve        = &rk30_reserve,
2417         .map_io         = rk30_map_io,
2418         .init_irq       = rk30_init_irq,
2419         .timer          = &rk30_timer,
2420         .init_machine   = machine_rk30_board_init,
2421 MACHINE_END