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