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