correct bugs for 'cpu hclk and pclk is 1:1'
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk30 / board-rk3066b-sdk.c
1 /*
2  *
3  * Copyright (C) 2012 ROCKCHIP, Inc.
4  *
5  * This software is licensed under the terms of the GNU General Public
6  * License version 2, as published by the Free Software Foundation, and
7  * may be copied, distributed, and modified under those terms.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  */
15
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/platform_device.h>
19 #include <linux/input.h>
20 #include <linux/io.h>
21 #include <linux/delay.h>
22 #include <linux/i2c.h>
23 #include <linux/skbuff.h>
24 #include <linux/spi/spi.h>
25 #include <linux/mmc/host.h>
26 #include <linux/ion.h>
27 #include <linux/cpufreq.h>
28 #include <linux/clk.h>
29 #include <mach/dvfs.h>
30
31 #include <asm/setup.h>
32 #include <asm/mach-types.h>
33 #include <asm/mach/arch.h>
34 #include <asm/mach/map.h>
35 #include <asm/mach/flash.h>
36 #include <asm/hardware/gic.h>
37
38 #include <mach/board.h>
39 #include <mach/hardware.h>
40 #include <mach/io.h>
41 #include <mach/gpio.h>
42 #include <mach/iomux.h>
43 #include <linux/fb.h>
44 #include <linux/regulator/machine.h>
45 #include <linux/rfkill-rk.h>
46 #include <linux/sensor-dev.h>
47 #include <linux/mfd/tps65910.h>
48 #include <linux/regulator/rk29-pwm-regulator.h>
49 #if defined(CONFIG_HDMI_RK30)
50         #include "../../../drivers/video/rockchip/hdmi/rk_hdmi.h"
51 #endif
52
53 #if defined(CONFIG_SPIM_RK29)
54 #include "../../../drivers/spi/rk29_spim.h"
55 #endif
56 #if defined(CONFIG_MU509)
57 #include <linux/mu509.h>
58 #endif
59 #if defined(CONFIG_MW100)
60 #include <linux/mw100.h>
61 #endif
62 #if defined(CONFIG_MT6229)
63 #include <linux/mt6229.h>
64 #endif
65 #if defined(CONFIG_ANDROID_TIMED_GPIO)
66 #include "../../../drivers/staging/android/timed_gpio.h"
67 #endif
68
69 #ifdef  CONFIG_THREE_FB_BUFFER
70 #define RK30_FB0_MEM_SIZE 12*SZ_1M
71 #else
72 #define RK30_FB0_MEM_SIZE 8*SZ_1M
73 #endif
74
75 #include "board-rk3066b-sdk-camera.c"
76 #include "board-rk3066b-sdk-key.c"
77
78 #if defined(CONFIG_TOUCHSCREEN_GT8XX)
79 #define TOUCH_RESET_PIN  RK30_PIN2_PC0
80 #define TOUCH_PWR_PIN    RK30_PIN2_PB4
81 static int goodix_init_platform_hw(void)
82 {
83         int ret;
84         
85         rk30_mux_api_set(GPIO2C0_LCDC1DATA16_SMCADDR0_TRACECLK_NAME, GPIO2C_GPIO2C0);
86         rk30_mux_api_set(GPIO2B4_LCDC1DATA12_SMCDATA12_TRACEDATA12_NAME, GPIO2B_GPIO2B4);
87         printk("%s:0x%x,0x%x\n",__func__,rk30_mux_api_get(GPIO2C0_LCDC1DATA16_SMCADDR0_TRACECLK_NAME),rk30_mux_api_get(GPIO2B4_LCDC1DATA12_SMCDATA12_TRACEDATA12_NAME));
88
89         if (TOUCH_PWR_PIN != INVALID_GPIO) {
90                 ret = gpio_request(TOUCH_PWR_PIN, "goodix power pin");
91                 if (ret != 0) {
92                         gpio_free(TOUCH_PWR_PIN);
93                         printk("goodix power error\n");
94                         return -EIO;
95                 }
96                 gpio_direction_output(TOUCH_PWR_PIN, 0);
97                 gpio_set_value(TOUCH_PWR_PIN, GPIO_LOW);
98                 msleep(100);
99         }
100
101         if (TOUCH_RESET_PIN != INVALID_GPIO) {
102                 ret = gpio_request(TOUCH_RESET_PIN, "goodix reset pin");
103                 if (ret != 0) {
104                         gpio_free(TOUCH_RESET_PIN);
105                         printk("goodix gpio_request error\n");
106                         return -EIO;
107                 }
108                 gpio_direction_output(TOUCH_RESET_PIN, 1);
109                 msleep(100);
110                 //gpio_set_value(TOUCH_RESET_PIN, GPIO_LOW);
111                 //msleep(100);
112                 //gpio_set_value(TOUCH_RESET_PIN, GPIO_HIGH);
113                 //msleep(500);
114         }
115         return 0;
116 }
117
118 struct goodix_platform_data goodix_info = {
119         .model = 8105,
120         .irq_pin = RK30_PIN0_PD4,
121         .rest_pin = TOUCH_RESET_PIN,
122         .init_platform_hw = goodix_init_platform_hw,
123 };
124 #endif
125
126 static struct spi_board_info board_spi_devices[] = {
127 };
128
129 /***********************************************************
130 *       rk30  backlight
131 ************************************************************/
132 #ifdef CONFIG_BACKLIGHT_RK29_BL
133 #define PWM_ID            2
134 #define PWM_MUX_NAME      GPIO3D5_PWM2_JTAGTCK_OTGDRVVBUS_NAME
135 #define PWM_MUX_MODE      GPIO3D_PWM2
136 #define PWM_MUX_MODE_GPIO GPIO3D_GPIO3D5
137 #define PWM_GPIO          RK30_PIN3_PD5
138 #define PWM_EFFECT_VALUE  1
139
140 #define LCD_DISP_ON_PIN
141
142 #ifdef  LCD_DISP_ON_PIN
143 #define BL_EN_PIN         RK30_PIN0_PA2
144 #define BL_EN_VALUE       GPIO_HIGH
145 #endif
146 static int rk29_backlight_io_init(void)
147 {
148         int ret = 0;
149         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
150 #ifdef  LCD_DISP_ON_PIN
151         // rk30_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
152
153         ret = gpio_request(BL_EN_PIN, NULL);
154         if (ret != 0) {
155                 gpio_free(BL_EN_PIN);
156         }
157
158         gpio_direction_output(BL_EN_PIN, 0);
159         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
160 #endif
161         return ret;
162 }
163
164 static int rk29_backlight_io_deinit(void)
165 {
166         int ret = 0;
167 #ifdef  LCD_DISP_ON_PIN
168         gpio_free(BL_EN_PIN);
169 #endif
170         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
171         gpio_direction_output(PWM_GPIO, GPIO_LOW);
172         return ret;
173 }
174
175 static int rk29_backlight_pwm_suspend(void)
176 {
177         int ret = 0;
178         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
179         if (gpio_request(PWM_GPIO, NULL)) {
180                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
181                 return -1;
182         }
183         gpio_direction_output(PWM_GPIO, GPIO_LOW);
184 #ifdef  LCD_DISP_ON_PIN
185         gpio_direction_output(BL_EN_PIN, 0);
186         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
187 #endif
188         return ret;
189 }
190
191 static int rk29_backlight_pwm_resume(void)
192 {
193         gpio_free(PWM_GPIO);
194         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
195 #ifdef  LCD_DISP_ON_PIN
196         msleep(30);
197         gpio_direction_output(BL_EN_PIN, 1);
198         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
199 #endif
200         return 0;
201 }
202
203 static struct rk29_bl_info rk29_bl_info = {
204         .pwm_id = PWM_ID,
205         .bl_ref = PWM_EFFECT_VALUE,
206         .io_init = rk29_backlight_io_init,
207         .io_deinit = rk29_backlight_io_deinit,
208         .pwm_suspend = rk29_backlight_pwm_suspend,
209         .pwm_resume = rk29_backlight_pwm_resume,
210 };
211
212 static struct platform_device rk29_device_backlight = {
213         .name   = "rk29_backlight",
214         .id     = -1,
215         .dev    = {
216                 .platform_data  = &rk29_bl_info,
217         }
218 };
219
220 #endif
221
222 #ifdef CONFIG_RK29_SUPPORT_MODEM
223
224 #define RK30_MODEM_POWER        RK30_PIN2_PB0
225 #define RK30_MODEM_POWER_IOMUX  rk29_mux_api_set(GPIO2B0_LCDC1DATA8_SMCDATA8_TRACEDATA8_NAME, GPIO2B_GPIO2B0)
226
227 static int rk30_modem_io_init(void)
228 {
229     printk("%s\n", __FUNCTION__);
230     RK30_MODEM_POWER_IOMUX;
231
232         return 0;
233 }
234
235 static struct rk29_io_t rk30_modem_io = {
236     .io_addr    = RK30_MODEM_POWER,
237     .enable     = GPIO_HIGH,
238     .disable    = GPIO_LOW,
239     .io_init    = rk30_modem_io_init,
240 };
241
242 static struct platform_device rk30_device_modem = {
243         .name   = "rk30_modem",
244         .id     = -1,
245         .dev    = {
246                 .platform_data  = &rk30_modem_io,
247         }
248 };
249 #endif
250 #if defined(CONFIG_MU509)
251 static int mu509_io_init(void)
252 {
253
254         rk30_mux_api_set(GPIO2B0_LCDC1DATA8_SMCDATA8_TRACEDATA8_NAME, GPIO2B_GPIO2B0);
255        rk30_mux_api_set(GPIO2D1_LCDC1DEN_SMCWEN_NAME, GPIO2D_GPIO2D1);
256         rk30_mux_api_set(GPIO2B7_LCDC1DATA15_SMCADDR19_HSADCDATA7_NAME, GPIO2B_GPIO2B7);
257         rk30_mux_api_set(GPIO2C0_LCDCDATA16_GPSCLK_HSADCCLKOUT_NAME, GPIO2C_GPIO2C0);
258         return 0;
259 }
260
261 static int mu509_io_deinit(void)
262 {
263         
264         return 0;
265 }
266  
267 struct rk29_mu509_data rk29_mu509_info = {
268         .io_init = mu509_io_init,
269         .io_deinit = mu509_io_deinit,
270         .modem_power_en = RK30_PIN2_PB0,
271         .bp_power = RK30_PIN2_PB0,
272         .bp_reset = RK30_PIN2_PD1,
273         .ap_wakeup_bp = RK30_PIN2_PB7,
274         .bp_wakeup_ap = RK30_PIN6_PA0, 
275 };
276 struct platform_device rk29_device_mu509 = {    
277         .name = "mu509",        
278         .id = -1,       
279         .dev            = {
280                 .platform_data = &rk29_mu509_info,
281         }       
282     };
283 #endif
284 #if defined(CONFIG_MW100)
285 static int mw100_io_init(void)
286 {
287          rk30_mux_api_set(GPIO2B0_LCDC1DATA8_SMCDATA8_TRACEDATA8_NAME, GPIO2B_GPIO2B0);
288          rk30_mux_api_set(GPIO2D1_LCDC1DEN_SMCWEN_NAME, GPIO2D_GPIO2D1);
289          rk30_mux_api_set(GPIO2B7_LCDC1DATA15_SMCADDR19_HSADCDATA7_NAME, GPIO2B_GPIO2B7);
290          rk30_mux_api_set(GPIO2C0_LCDCDATA16_GPSCLK_HSADCCLKOUT_NAME, GPIO2C_GPIO2C0);
291         return 0;
292 }
293
294 static int mw100_io_deinit(void)
295 {
296         
297         return 0;
298 }
299  
300 struct rk29_mw100_data rk29_mw100_info = {
301         .io_init = mw100_io_init,
302         .io_deinit = mw100_io_deinit,
303         .modem_power_en = RK30_PIN6_PB0,
304         .bp_power = RK30_PIN2_PB0,
305         .bp_reset = RK30_PIN2_PD1,
306         .ap_wakeup_bp = RK30_PIN2_PB7,
307         .bp_wakeup_ap = RK30_PIN6_PA0,
308 };
309 struct platform_device rk29_device_mw100 = {    
310         .name = "mw100",        
311         .id = -1,       
312         .dev            = {
313                 .platform_data = &rk29_mw100_info,
314         }       
315     };
316 #endif
317 #if defined(CONFIG_MT6229)
318 static int mt6229_io_init(void)
319 {
320          rk30_mux_api_set(GPIO2B0_LCDC1DATA8_SMCDATA8_TRACEDATA8_NAME, GPIO2B_GPIO2B0);
321          rk30_mux_api_set(GPIO2D1_LCDC1DEN_SMCWEN_NAME, GPIO2D_GPIO2D1);
322          rk30_mux_api_set(GPIO2B7_LCDC1DATA15_SMCADDR19_HSADCDATA7_NAME, GPIO2B_GPIO2B7);
323          rk30_mux_api_set(GPIO2C0_LCDCDATA16_GPSCLK_HSADCCLKOUT_NAME, GPIO2C_GPIO2C0);
324         return 0;
325 }
326
327 static int mt6229_io_deinit(void)
328 {
329         
330         return 0;
331 }
332  
333 struct rk29_mt6229_data rk29_mt6229_info = {
334         .io_init = mt6229_io_init,
335         .io_deinit = mt6229_io_deinit,
336         .modem_power_en = RK30_PIN2_PB0,
337         .bp_power = RK30_PIN2_PB0,//RK30_PIN2_PB6,
338         .bp_reset = RK30_PIN2_PD1,
339         .ap_wakeup_bp = RK30_PIN2_PC0,
340         .bp_wakeup_ap = RK30_PIN6_PA0,
341 };
342 struct platform_device rk29_device_mt6229 = {   
343         .name = "mt6229",       
344         .id = -1,       
345         .dev            = {
346                 .platform_data = &rk29_mt6229_info,
347         }       
348     };
349 #endif
350
351 /*MMA8452 gsensor*/
352 #if defined (CONFIG_GS_MMA8452)
353 #define MMA8452_INT_PIN   RK30_PIN3_PD7
354
355 static int mma8452_init_platform_hw(void)
356 {
357         return 0;
358 }
359
360 static struct sensor_platform_data mma8452_info = {
361         .type = SENSOR_TYPE_ACCEL,
362         .irq_enable = 1,
363         .poll_delay_ms = 30,
364         .init_platform_hw = mma8452_init_platform_hw,
365         .orientation = {-1, 0, 0, 0, 0, 1, 0, -1, 0},
366 };
367 #endif
368 #if defined (CONFIG_GS_LIS3DH)
369 #define LIS3DH_INT_PIN   RK30_PIN3_PD7
370
371 static int lis3dh_init_platform_hw(void)
372 {
373
374         return 0;
375 }
376
377 static struct sensor_platform_data lis3dh_info = {
378         .type = SENSOR_TYPE_ACCEL,
379         .irq_enable = 1,
380         .poll_delay_ms = 30,
381         .init_platform_hw = lis3dh_init_platform_hw,
382         .orientation = {-1, 0, 0, 0, 0, 1, 0, -1, 0},
383 };
384 #endif
385 #if defined (CONFIG_COMPASS_AK8975)
386 static struct sensor_platform_data akm8975_info =
387 {
388         .type = SENSOR_TYPE_COMPASS,
389         .irq_enable = 1,
390         .poll_delay_ms = 30,
391         .m_layout = 
392         {
393                 {
394                         {1, 0, 0},
395                         {0, 1, 0},
396                         {0, 0, 1},
397                 },
398
399                 {
400                         {1, 0, 0},
401                         {0, 1, 0},
402                         {0, 0, 1},
403                 },
404
405                 {
406                         {1, 0, 0},
407                         {0, 1, 0},
408                         {0, 0, 1},
409                 },
410
411                 {
412                         {1, 0, 0},
413                         {0, 1, 0},
414                         {0, 0, 1},
415                 },
416         }
417 };
418
419 #endif
420
421 #if defined(CONFIG_GYRO_L3G4200D)
422
423 #include <linux/l3g4200d.h>
424 #define L3G4200D_INT_PIN  RK30_PIN0_PB4
425
426 static int l3g4200d_init_platform_hw(void)
427 {
428         return 0;
429 }
430
431 static struct sensor_platform_data l3g4200d_info = {
432         .type = SENSOR_TYPE_GYROSCOPE,
433         .irq_enable = 1,
434         .poll_delay_ms = 30,
435         .orientation = {0, 1, 0, -1, 0, 0, 0, 0, 1},
436         .init_platform_hw = l3g4200d_init_platform_hw,
437         .x_min = 40,//x_min,y_min,z_min = (0-100) according to hardware
438         .y_min = 40,
439         .z_min = 20,
440 };
441
442 #endif
443
444 #ifdef CONFIG_LS_CM3217
445 static struct sensor_platform_data cm3217_info = {
446         .type = SENSOR_TYPE_LIGHT,
447         .irq_enable = 0,
448         .poll_delay_ms = 500,
449 };
450
451 #endif
452
453 #ifdef CONFIG_FB_ROCKCHIP
454
455 #define LCD_CS_PIN         INVALID_GPIO
456 #define LCD_CS_VALUE       GPIO_HIGH
457
458 #define LCD_EN_PIN         RK30_PIN0_PB0
459 #define LCD_EN_VALUE       GPIO_HIGH
460
461 static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
462 {
463         int ret = 0;
464
465         if(LCD_CS_PIN !=INVALID_GPIO)
466         {
467                 ret = gpio_request(LCD_CS_PIN, NULL);
468                 if (ret != 0)
469                 {
470                         gpio_free(LCD_CS_PIN);
471                         printk(KERN_ERR "request lcd cs pin fail!\n");
472                         return -1;
473                 }
474                 else
475                 {
476                         gpio_direction_output(LCD_CS_PIN, LCD_CS_VALUE);
477                 }
478         }
479
480         if(LCD_EN_PIN !=INVALID_GPIO)
481         {
482                 ret = gpio_request(LCD_EN_PIN, NULL);
483                 if (ret != 0)
484                 {
485                         gpio_free(LCD_EN_PIN);
486                         printk(KERN_ERR "request lcd en pin fail!\n");
487                         return -1;
488                 }
489                 else
490                 {
491                         gpio_direction_output(LCD_EN_PIN, LCD_EN_VALUE);
492                 }
493         }
494         return 0;
495 }
496 static int rk_fb_io_disable(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 static int rk_fb_io_enable(void)
509 {
510         if(LCD_CS_PIN !=INVALID_GPIO)
511         {
512                 gpio_set_value(LCD_CS_PIN, LCD_CS_VALUE);
513         }
514         if(LCD_EN_PIN !=INVALID_GPIO)
515         {
516                 gpio_set_value(LCD_EN_PIN, LCD_EN_VALUE);
517         }
518         return 0;
519 }
520
521 #if defined(CONFIG_LCDC0_RK31)
522 struct rk29fb_info lcdc0_screen_info = {
523         .prop      = PRMRY,             //primary display device
524         .io_init   = rk_fb_io_init,
525         .io_disable = rk_fb_io_disable,
526         .io_enable = rk_fb_io_enable,
527         .set_screen_info = set_lcd_info,
528 };
529 #endif
530
531 #if defined(CONFIG_LCDC1_RK31)
532 struct rk29fb_info lcdc1_screen_info = {
533         #if defined(CONFIG_HDMI_RK30)
534         .prop           = EXTEND,       //extend display device
535         .lcd_info  = NULL,
536         .set_screen_info = hdmi_init_lcdc,
537         #endif
538 };
539 #endif
540
541 static struct resource resource_fb[] = {
542         [0] = {
543                 .name  = "fb0 buf",
544                 .start = 0,
545                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
546                 .flags = IORESOURCE_MEM,
547         },
548         [1] = {
549                 .name  = "ipp buf",  //for rotate
550                 .start = 0,
551                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
552                 .flags = IORESOURCE_MEM,
553         },
554         [2] = {
555                 .name  = "fb2 buf",
556                 .start = 0,
557                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
558                 .flags = IORESOURCE_MEM,
559         },
560 };
561
562 static struct platform_device device_fb = {
563         .name           = "rk-fb",
564         .id             = -1,
565         .num_resources  = ARRAY_SIZE(resource_fb),
566         .resource       = resource_fb,
567 };
568 #endif
569
570 #if defined(CONFIG_LCDC0_RK31)
571 static struct resource resource_lcdc0[] = {
572         [0] = {
573                 .name  = "lcdc0 reg",
574                 .start = RK30_LCDC0_PHYS,
575                 .end   = RK30_LCDC0_PHYS + RK30_LCDC0_SIZE - 1,
576                 .flags = IORESOURCE_MEM,
577         },
578         
579         [1] = {
580                 .name  = "lcdc0 irq",
581                 .start = IRQ_LCDC0,
582                 .end   = IRQ_LCDC0,
583                 .flags = IORESOURCE_IRQ,
584         },
585 };
586
587 static struct platform_device device_lcdc0 = {
588         .name             = "rk30-lcdc",
589         .id               = 0,
590         .num_resources    = ARRAY_SIZE(resource_lcdc0),
591         .resource         = resource_lcdc0,
592         .dev            = {
593                 .platform_data = &lcdc0_screen_info,
594         },
595 };
596 #endif
597 #if defined(CONFIG_LCDC1_RK31) 
598 static struct resource resource_lcdc1[] = {
599         [0] = {
600                 .name  = "lcdc1 reg",
601                 .start = RK30_LCDC1_PHYS,
602                 .end   = RK30_LCDC1_PHYS + RK30_LCDC1_SIZE - 1,
603                 .flags = IORESOURCE_MEM,
604         },
605         [1] = {
606                 .name  = "lcdc1 irq",
607                 .start = IRQ_LCDC1,
608                 .end   = IRQ_LCDC1,
609                 .flags = IORESOURCE_IRQ,
610         },
611 };
612
613 static struct platform_device device_lcdc1 = {
614         .name             = "rk30-lcdc",
615         .id               = 1,
616         .num_resources    = ARRAY_SIZE(resource_lcdc1),
617         .resource         = resource_lcdc1,
618         .dev            = {
619                 .platform_data = &lcdc1_screen_info,
620         },
621 };
622 #endif
623
624 #ifdef CONFIG_ANDROID_TIMED_GPIO
625 static struct timed_gpio timed_gpios[] = {
626         {
627                 .name = "vibrator",
628                 .gpio = RK30_PIN3_PD3,
629                 .max_timeout = 1000,
630                 .active_low = 0,
631                 .adjust_time =20,      //adjust for diff product
632         },
633 };
634
635 static struct timed_gpio_platform_data rk29_vibrator_info = {
636         .num_gpios = 1,
637         .gpios = timed_gpios,
638 };
639
640 static struct platform_device rk29_device_vibrator = {
641         .name = "timed-gpio",
642         .id = -1,
643         .dev = {
644                 .platform_data = &rk29_vibrator_info,
645         },
646
647 };
648 #endif
649
650 #ifdef CONFIG_LEDS_GPIO_PLATFORM
651 static struct gpio_led rk29_leds[] = {
652         {
653                 .name = "button-backlight",
654                 .gpio = RK30_PIN2_PB3,
655                 .default_trigger = "timer",
656                 .active_low = 0,
657                 .retain_state_suspended = 0,
658                 .default_state = LEDS_GPIO_DEFSTATE_OFF,
659         },
660 };
661
662 static struct gpio_led_platform_data rk29_leds_pdata = {
663         .leds = rk29_leds,
664         .num_leds = ARRAY_SIZE(rk29_leds),
665 };
666
667 static struct platform_device rk29_device_gpio_leds = {
668         .name   = "leds-gpio",
669         .id     = -1,
670         .dev    = {
671                 .platform_data  = &rk29_leds_pdata,
672         },
673 };
674 #endif
675
676 #ifdef CONFIG_RK_IRDA
677 #define IRDA_IRQ_PIN           RK30_PIN0_PA3
678
679 static int irda_iomux_init(void)
680 {
681         int ret = 0;
682
683         //irda irq pin
684         ret = gpio_request(IRDA_IRQ_PIN, NULL);
685         if (ret != 0) {
686                 gpio_free(IRDA_IRQ_PIN);
687                 printk(">>>>>> IRDA_IRQ_PIN gpio_request err \n ");
688         }
689         gpio_pull_updown(IRDA_IRQ_PIN, PullDisable);
690         gpio_direction_input(IRDA_IRQ_PIN);
691
692         return 0;
693 }
694
695 static int irda_iomux_deinit(void)
696 {
697         gpio_free(IRDA_IRQ_PIN);
698         return 0;
699 }
700
701 static struct irda_info rk29_irda_info = {
702         .intr_pin = IRDA_IRQ_PIN,
703         .iomux_init = irda_iomux_init,
704         .iomux_deinit = irda_iomux_deinit,
705         //.irda_pwr_ctl = bu92747guw_power_ctl,
706 };
707
708 static struct platform_device irda_device = {
709 #ifdef CONFIG_RK_IRDA_NET
710         .name = "rk_irda",
711 #else
712         .name = "bu92747_irda",
713 #endif
714         .id = -1,
715         .dev = {
716                 .platform_data = &rk29_irda_info,
717         }
718 };
719 #endif
720
721 #ifdef CONFIG_ION
722 #define ION_RESERVE_SIZE        (80 * SZ_1M)
723 static struct ion_platform_data rk30_ion_pdata = {
724         .nr = 1,
725         .heaps = {
726                 {
727                         .type = ION_HEAP_TYPE_CARVEOUT,
728                         .id = ION_NOR_HEAP_ID,
729                         .name = "norheap",
730                         .size = ION_RESERVE_SIZE,
731                 }
732         },
733 };
734
735 static struct platform_device device_ion = {
736         .name = "ion-rockchip",
737         .id = 0,
738         .dev = {
739                 .platform_data = &rk30_ion_pdata,
740         },
741 };
742 #endif
743
744 /**************************************************************************************************
745  * SDMMC devices,  include the module of SD,MMC,and sdio.noted by xbw at 2012-03-05
746 **************************************************************************************************/
747 #ifdef CONFIG_SDMMC_RK29
748 #include "board-rk3066b-sdk-sdmmc.c"
749
750 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
751 #define SDMMC0_WRITE_PROTECT_PIN        RK30_PIN3_PB7   //According to your own project to set the value of write-protect-pin.
752 #endif
753
754 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
755 #define SDMMC1_WRITE_PROTECT_PIN        RK30_PIN3_PC7   //According to your own project to set the value of write-protect-pin.
756 #endif
757
758 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N    RK30_PIN6_PB2
759
760 #endif //endif ---#ifdef CONFIG_SDMMC_RK29
761
762 #ifdef CONFIG_SDMMC0_RK29
763 static int rk29_sdmmc0_cfg_gpio(void)
764 {
765 #ifdef CONFIG_SDMMC_RK29_OLD
766         rk30_mux_api_set(GPIO3B1_SDMMC0CMD_NAME, GPIO3B_SDMMC0_CMD);
767         rk30_mux_api_set(GPIO3B0_SDMMC0CLKOUT_NAME, GPIO3B_SDMMC0_CLKOUT);
768         rk30_mux_api_set(GPIO3B2_SDMMC0DATA0_NAME, GPIO3B_SDMMC0_DATA0);
769         rk30_mux_api_set(GPIO3B3_SDMMC0DATA1_NAME, GPIO3B_SDMMC0_DATA1);
770         rk30_mux_api_set(GPIO3B4_SDMMC0DATA2_NAME, GPIO3B_SDMMC0_DATA2);
771         rk30_mux_api_set(GPIO3B5_SDMMC0DATA3_NAME, GPIO3B_SDMMC0_DATA3);
772
773         rk30_mux_api_set(GPIO3B6_SDMMC0DETECTN_NAME, GPIO3B_GPIO3B6);
774
775         rk30_mux_api_set(GPIO3A7_SDMMC0PWREN_NAME, GPIO3A_GPIO3A7);
776         gpio_request(RK30_PIN3_PA7, "sdmmc-power");
777         gpio_direction_output(RK30_PIN3_PA7, GPIO_LOW);
778
779 #else
780         rk29_sdmmc_set_iomux(0, 0xFFFF);
781
782         rk30_mux_api_set(GPIO3B0_SDMMC0DETECTN_NAME, GPIO3B_SDMMC0DETECTN);
783
784 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
785         gpio_request(SDMMC0_WRITE_PROTECT_PIN, "sdmmc-wp");
786         gpio_direction_input(SDMMC0_WRITE_PROTECT_PIN);
787 #endif
788
789 #endif
790
791         return 0;
792 }
793
794 #define CONFIG_SDMMC0_USE_DMA
795 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
796         .host_ocr_avail =
797             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
798              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
799              MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36),
800         .host_caps =
801             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
802         .io_init = rk29_sdmmc0_cfg_gpio,
803
804 #if !defined(CONFIG_SDMMC_RK29_OLD)
805         .set_iomux = rk29_sdmmc_set_iomux,
806 #endif
807
808         .dma_name = "sd_mmc",
809 #ifdef CONFIG_SDMMC0_USE_DMA
810         .use_dma = 1,
811 #else
812         .use_dma = 0,
813 #endif
814         .detect_irq = RK30_PIN3_PB6,    // INVALID_GPIO
815         .enable_sd_wakeup = 0,
816
817 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
818         .write_prt = SDMMC0_WRITE_PROTECT_PIN,
819 #else
820         .write_prt = INVALID_GPIO,
821 #endif
822 };
823 #endif // CONFIG_SDMMC0_RK29
824
825 #ifdef CONFIG_SDMMC1_RK29
826 #define CONFIG_SDMMC1_USE_DMA
827 static int rk29_sdmmc1_cfg_gpio(void)
828 {
829 #if defined(CONFIG_SDMMC_RK29_OLD)
830         rk30_mux_api_set(GPIO3C0_SMMC1CMD_NAME, GPIO3C_SMMC1_CMD);
831         rk30_mux_api_set(GPIO3C5_SDMMC1CLKOUT_NAME, GPIO3C_SDMMC1_CLKOUT);
832         rk30_mux_api_set(GPIO3C1_SDMMC1DATA0_NAME, GPIO3C_SDMMC1_DATA0);
833         rk30_mux_api_set(GPIO3C2_SDMMC1DATA1_NAME, GPIO3C_SDMMC1_DATA1);
834         rk30_mux_api_set(GPIO3C3_SDMMC1DATA2_NAME, GPIO3C_SDMMC1_DATA2);
835         rk30_mux_api_set(GPIO3C4_SDMMC1DATA3_NAME, GPIO3C_SDMMC1_DATA3);
836         //rk30_mux_api_set(GPIO3C6_SDMMC1DETECTN_NAME, GPIO3C_SDMMC1_DETECT_N);
837
838 #else
839
840 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
841         gpio_request(SDMMC1_WRITE_PROTECT_PIN, "sdio-wp");
842         gpio_direction_input(SDMMC1_WRITE_PROTECT_PIN);
843 #endif
844
845 #endif
846
847         return 0;
848 }
849
850 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
851         .host_ocr_avail =
852             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
853              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
854              MMC_VDD_33_34),
855
856 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
857         .host_caps = (MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ |
858                       MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
859 #else
860         .host_caps =
861             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
862 #endif
863
864         .io_init = rk29_sdmmc1_cfg_gpio,
865
866 #if !defined(CONFIG_SDMMC_RK29_OLD)
867         .set_iomux = rk29_sdmmc_set_iomux,
868 #endif
869
870         .dma_name = "sdio",
871 #ifdef CONFIG_SDMMC1_USE_DMA
872         .use_dma = 1,
873 #else
874         .use_dma = 0,
875 #endif
876
877 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
878 #ifdef CONFIG_WIFI_CONTROL_FUNC
879         .status = rk29sdk_wifi_status,
880         .register_status_notify = rk29sdk_wifi_status_register,
881 #endif
882 #if 0
883         .detect_irq = RK29SDK_WIFI_SDIO_CARD_DETECT_N,
884 #endif
885
886 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
887         .write_prt = SDMMC1_WRITE_PROTECT_PIN,
888 #else
889         .write_prt = INVALID_GPIO,
890 #endif
891
892 #else
893         .detect_irq = INVALID_GPIO,
894         .enable_sd_wakeup = 0,
895 #endif
896
897 };
898 #endif //endif--#ifdef CONFIG_SDMMC1_RK29
899
900 /**************************************************************************************************
901  * the end of setting for SDMMC devices
902 **************************************************************************************************/
903
904 #ifdef CONFIG_BATTERY_RK30_ADC
905 static struct rk30_adc_battery_platform_data rk30_adc_battery_platdata = {
906         .dc_det_pin      = RK30_PIN0_PB2,
907         .batt_low_pin    = RK30_PIN0_PB1, 
908         .charge_set_pin  = INVALID_GPIO,
909         .charge_ok_pin   = RK30_PIN0_PA6,
910         .dc_det_level    = GPIO_LOW,
911         .charge_ok_level = GPIO_HIGH,
912 };
913
914 static struct platform_device rk30_device_adc_battery = {
915         .name   = "rk30-battery",
916         .id     = -1,
917         .dev = {
918                 .platform_data = &rk30_adc_battery_platdata,
919         },
920 };
921 #endif
922 #ifdef CONFIG_RK30_PWM_REGULATOR
923 const static int pwm_voltage_map[] = {
924         1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000, 1375000, 1400000
925 };
926
927 static struct regulator_consumer_supply pwm_dcdc1_consumers[] = {
928         {
929                 .supply = "vdd_core",
930         }
931 };
932
933 struct regulator_init_data pwm_regulator_init_dcdc[1] =
934 {
935         {
936                 .constraints = {
937                         .name = "PWM_DCDC1",
938                         .min_uV = 600000,
939                         .max_uV = 1800000,      //0.6-1.8V
940                         .apply_uV = true,
941                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
942                 },
943                 .num_consumer_supplies = ARRAY_SIZE(pwm_dcdc1_consumers),
944                 .consumer_supplies = pwm_dcdc1_consumers,
945         },
946 };
947
948 static struct pwm_platform_data pwm_regulator_info[1] = {
949         {
950                 .pwm_id = 3,
951                 .pwm_gpio = RK30_PIN3_PD6,
952                 .pwm_iomux_name = GPIO3D6_PWM3_JTAGTMS_HOSTDRVVBUS_NAME,
953                 .pwm_iomux_pwm = GPIO3D_PWM3,
954                 .pwm_iomux_gpio = GPIO3D_GPIO3D6,
955                 .pwm_voltage = 1100000,
956                 .suspend_voltage = 1050000,
957                 .min_uV = 1000000,
958                 .max_uV = 1400000,
959                 .coefficient = 455,     //45.5%
960                 .pwm_voltage_map = pwm_voltage_map,
961                 .init_data      = &pwm_regulator_init_dcdc[0],
962         },
963 };
964
965 struct platform_device pwm_regulator_device[1] = {
966         {
967                 .name = "pwm-voltage-regulator",
968                 .id = 0,
969                 .dev            = {
970                         .platform_data = &pwm_regulator_info[0],
971                 }
972         },
973 };
974 #endif
975
976 #ifdef CONFIG_RK29_VMAC
977 #define PHY_PWR_EN_GPIO RK30_PIN1_PD6
978 #include "board-rk30-sdk-vmac.c"
979 #endif
980
981 #ifdef CONFIG_RFKILL_RK
982 // bluetooth rfkill device, its driver in net/rfkill/rfkill-rk.c
983 static struct rfkill_rk_platform_data rfkill_rk_platdata = {
984     .type               = RFKILL_TYPE_BLUETOOTH,
985
986     .poweron_gpio       = { // BT_REG_ON
987         .io             = INVALID_GPIO, //RK30_PIN3_PC7,
988         .enable         = GPIO_HIGH,
989         .iomux          = {
990             .name       = GPIO3C7_SDMMC1WRITEPRT_RMIICRS_NAME,
991             .fgpio      = GPIO3C_GPIO3C7,
992         },
993     },
994
995     .reset_gpio         = { // BT_RST
996         .io             = RK30_PIN3_PD1, // set io to INVALID_GPIO for disable it
997         .enable         = GPIO_LOW,
998         .iomux          = {
999             .name       = GPIO3D1_SDMMC1BACKENDPWR_MIIMDCLK_NAME,
1000             .fgpio      = GPIO3D_GPIO3D1,
1001        },
1002    }, 
1003
1004     .wake_gpio          = { // BT_WAKE, use to control bt's sleep and wakeup
1005         .io             = RK30_PIN3_PC6, // set io to INVALID_GPIO for disable it
1006         .enable         = GPIO_HIGH,
1007         .iomux          = {
1008             .name       = GPIO3C6_SDMMC1DETECTN_RMIIRXERR_NAME,
1009             .fgpio      = GPIO3C_GPIO3C6,
1010         },
1011     },
1012
1013     .wake_host_irq      = { // BT_HOST_WAKE, for bt wakeup host when it is in deep sleep
1014         .gpio           = {
1015             .io         = RK30_PIN0_PA5, // set io to INVALID_GPIO for disable it
1016             .enable     = GPIO_LOW,      // set GPIO_LOW for falling, set 0 for rising
1017             .iomux      = {
1018                 .name   = NULL,
1019             },
1020         },
1021     },
1022
1023     .rts_gpio           = { // UART_RTS, enable or disable BT's data coming
1024         .io             = RK30_PIN1_PA3, // set io to INVALID_GPIO for disable it
1025         .enable         = GPIO_LOW,
1026         .iomux          = {
1027             .name       = GPIO1A3_UART0RTSN_NAME,
1028             .fgpio      = GPIO1A_GPIO1A3,
1029             .fmux       = GPIO1A_UART0RTSN,
1030         },
1031     },
1032 };
1033
1034 static struct platform_device device_rfkill_rk = {
1035     .name   = "rfkill_rk",
1036     .id     = -1,
1037     .dev    = {
1038         .platform_data = &rfkill_rk_platdata,
1039     },
1040 };
1041 #endif
1042
1043 static struct platform_device *devices[] __initdata = {
1044 #ifdef CONFIG_FB_ROCKCHIP
1045         &device_fb,
1046 #endif
1047 #if defined(CONFIG_LCDC0_RK31)
1048         &device_lcdc0,
1049 #endif
1050 #if defined(CONFIG_LCDC1_RK31)
1051         &device_lcdc1,
1052 #endif
1053                 
1054 #ifdef CONFIG_BACKLIGHT_RK29_BL
1055         &rk29_device_backlight,
1056 #endif
1057
1058 #ifdef CONFIG_ION
1059         &device_ion,
1060 #endif
1061 #ifdef CONFIG_ANDROID_TIMED_GPIO
1062         &rk29_device_vibrator,
1063 #endif
1064 #ifdef CONFIG_LEDS_GPIO_PLATFORM
1065         &rk29_device_gpio_leds,
1066 #endif
1067 #ifdef CONFIG_RK_IRDA
1068         &irda_device,
1069 #endif
1070 #ifdef CONFIG_WIFI_CONTROL_FUNC
1071         &rk29sdk_wifi_device,
1072 #endif
1073 #ifdef CONFIG_RK29_SUPPORT_MODEM
1074         &rk30_device_modem,
1075 #endif
1076 #if defined(CONFIG_MU509)
1077         &rk29_device_mu509,
1078 #endif
1079 #if defined(CONFIG_MW100)
1080         &rk29_device_mw100,
1081 #endif
1082 #if defined(CONFIG_MT6229)
1083         &rk29_device_mt6229,
1084 #endif
1085 #ifdef CONFIG_BATTERY_RK30_ADC
1086         &rk30_device_adc_battery,
1087 #endif
1088 #ifdef CONFIG_RFKILL_RK
1089         &device_rfkill_rk,
1090 #endif
1091 };
1092
1093 // i2c
1094 #ifdef CONFIG_I2C0_RK30
1095 static struct i2c_board_info __initdata i2c0_info[] = {
1096 #if defined (CONFIG_GS_MMA8452)
1097         {
1098                 .type           = "gs_mma8452",
1099                 .addr           = 0x1d,
1100                 .flags          = 0,
1101                 .irq            = MMA8452_INT_PIN,
1102                 .platform_data = &mma8452_info,
1103         },
1104 #endif
1105 #if defined (CONFIG_GS_LIS3DH)
1106         {
1107                 .type           = "gs_lis3dh",
1108                 .addr           = 0x19,   //0x19(SA0-->VCC), 0x18(SA0-->GND)
1109                 .flags          = 0,
1110                 .irq            = LIS3DH_INT_PIN,
1111                 .platform_data = &lis3dh_info,
1112         },
1113 #endif
1114 #if defined (CONFIG_COMPASS_AK8975)
1115         {
1116                 .type          = "ak8975",
1117                 .addr          = 0x0d,
1118                 .flags         = 0,
1119                 .irq           = RK30_PIN0_PD5,
1120                 .platform_data = &akm8975_info,
1121         },
1122 #endif
1123 #if defined (CONFIG_GYRO_L3G4200D)
1124         {
1125                 .type          = "l3g4200d_gryo",
1126                 .addr          = 0x69,
1127                 .flags         = 0,
1128                 .irq           = L3G4200D_INT_PIN,
1129                 .platform_data = &l3g4200d_info,
1130         },
1131 #endif
1132 #if defined (CONFIG_SND_SOC_RK1000)
1133         {
1134                 .type          = "rk1000_i2c_codec",
1135                 .addr          = 0x60,
1136                 .flags         = 0,
1137         },
1138         {
1139                 .type          = "rk1000_control",
1140                 .addr          = 0x40,
1141                 .flags         = 0,
1142         },
1143 #endif
1144 #if defined (CONFIG_SND_SOC_RT5631)
1145         {
1146                 .type                   = "rt5631",
1147                 .addr                   = 0x1a,
1148                 .flags                  = 0,
1149         },
1150 #endif
1151
1152 #ifdef CONFIG_MFD_RK610
1153                 {
1154                         .type                   = "rk610_ctl",
1155                         .addr                   = 0x40,
1156                         .flags                  = 0,
1157                 },
1158 #ifdef CONFIG_RK610_TVOUT
1159                 {
1160                         .type                   = "rk610_tvout",
1161                         .addr                   = 0x42,
1162                         .flags                  = 0,
1163                 },
1164 #endif
1165 #ifdef CONFIG_RK610_HDMI
1166                 {
1167                         .type                   = "rk610_hdmi",
1168                         .addr                   = 0x46,
1169                         .flags                  = 0,
1170                         .irq                    = RK29_PIN5_PA2,
1171                 },
1172 #endif
1173 #ifdef CONFIG_SND_SOC_RK610
1174                 {//RK610_CODEC addr  from 0x60 to 0x80 (0x60~0x80)
1175                         .type                   = "rk610_i2c_codec",
1176                         .addr                   = 0x60,
1177                         .flags                  = 0,
1178                 },
1179 #endif
1180 #endif
1181
1182 };
1183 #endif
1184
1185 #define PMIC_TYPE_WM8326        1
1186 #define PMIC_TYPE_TPS65910      2
1187 int __sramdata g_pmic_type =  0;
1188 #ifdef CONFIG_I2C1_RK30
1189 #ifdef CONFIG_MFD_WM831X_I2C
1190 #include "board-rk3066b-sdk-wm8326.c"
1191 #endif
1192 #ifdef CONFIG_MFD_TPS65910
1193 #define TPS65910_HOST_IRQ        RK30_PIN6_PA4
1194 #include "board-rk3066b-sdk-tps65910.c"
1195 #endif
1196
1197 static struct i2c_board_info __initdata i2c1_info[] = {
1198 #if defined (CONFIG_MFD_WM831X_I2C)
1199         {
1200                 .type          = "wm8326",
1201                 .addr          = 0x34,
1202                 .flags         = 0,
1203                 .irq           = RK30_PIN0_PB3,
1204                 .platform_data = &wm831x_platdata,
1205         },
1206 #endif
1207 #if defined (CONFIG_MFD_TPS65910)
1208         {
1209         .type           = "tps65910",
1210         .addr           = TPS65910_I2C_ID0,
1211         .flags          = 0,
1212         .irq            = TPS65910_HOST_IRQ,
1213         .platform_data = &tps65910_data,
1214         },
1215 #endif
1216 };
1217 #endif
1218
1219 void __sramfunc board_pmu_suspend(void)
1220 {      
1221         #if defined (CONFIG_MFD_WM831X_I2C)
1222        if(g_pmic_type == PMIC_TYPE_WM8326)
1223        board_pmu_wm8326_suspend();
1224         #endif
1225         #if defined (CONFIG_MFD_TPS65910)
1226        if(g_pmic_type == PMIC_TYPE_TPS65910)
1227        board_pmu_tps65910_suspend(); 
1228     #endif   
1229 }
1230
1231 void __sramfunc board_pmu_resume(void)
1232 {      
1233         #if defined (CONFIG_MFD_WM831X_I2C)
1234        if(g_pmic_type == PMIC_TYPE_WM8326)
1235        board_pmu_wm8326_resume();
1236         #endif
1237         #if defined (CONFIG_MFD_TPS65910)
1238        if(g_pmic_type == PMIC_TYPE_TPS65910)
1239        board_pmu_tps65910_resume(); 
1240         #endif
1241 }
1242
1243  int __sramdata gpio0d7_iomux,gpio0d7_do,gpio0d7_dir,gpio0d7_en;
1244
1245 void __sramfunc rk30_pwm_logic_suspend_voltage(void)
1246 {
1247 #ifdef CONFIG_RK30_PWM_REGULATOR
1248
1249 //      int gpio0d7_iomux,gpio0d7_do,gpio0d7_dir,gpio0d7_en;
1250         sram_udelay(10000);
1251         gpio0d7_iomux = readl_relaxed(GRF_GPIO0D_IOMUX);
1252         gpio0d7_do = grf_readl(GRF_GPIO0H_DO);
1253         gpio0d7_dir = grf_readl(GRF_GPIO0H_DIR);
1254         gpio0d7_en = grf_readl(GRF_GPIO0H_EN);
1255
1256         writel_relaxed((1<<30), GRF_GPIO0D_IOMUX);
1257         grf_writel((1<<31)|(1<<15), GRF_GPIO0H_DIR);
1258         grf_writel((1<<31)|(1<<15), GRF_GPIO0H_DO);
1259         grf_writel((1<<31)|(1<<15), GRF_GPIO0H_EN);
1260 #endif 
1261 }
1262 void __sramfunc rk30_pwm_logic_resume_voltage(void)
1263 {
1264 #ifdef CONFIG_RK30_PWM_REGULATOR
1265         writel_relaxed((1<<30)|gpio0d7_iomux, GRF_GPIO0D_IOMUX);
1266         grf_writel((1<<31)|gpio0d7_en, GRF_GPIO0H_EN);
1267         grf_writel((1<<31)|gpio0d7_dir, GRF_GPIO0H_DIR);
1268         grf_writel((1<<31)|gpio0d7_do, GRF_GPIO0H_DO);
1269         sram_udelay(10000);
1270
1271 #endif
1272
1273 }
1274 extern void pwm_suspend_voltage(void);
1275 extern void pwm_resume_voltage(void);
1276 void  rk30_pwm_suspend_voltage_set(void)
1277 {
1278 #ifdef CONFIG_RK30_PWM_REGULATOR
1279         pwm_suspend_voltage();
1280 #endif
1281 }
1282 void  rk30_pwm_resume_voltage_set(void)
1283 {
1284 #ifdef CONFIG_RK30_PWM_REGULATOR
1285         pwm_resume_voltage();
1286 #endif
1287 }
1288
1289
1290 #ifdef CONFIG_I2C2_RK30
1291 static struct i2c_board_info __initdata i2c2_info[] = {
1292 #if defined (CONFIG_TOUCHSCREEN_GT8XX)
1293         {
1294                 .type          = "Goodix-TS",
1295                 .addr          = 0x55,
1296                 .flags         = 0,
1297                 .irq           = RK30_PIN0_PD4,
1298                 .platform_data = &goodix_info,
1299         },
1300 #endif
1301 #if defined (CONFIG_LS_CM3217)
1302         {
1303                 .type          = "lightsensor",
1304                 .addr          = 0x10,
1305                 .flags         = 0,
1306                 .platform_data = &cm3217_info,
1307         },
1308 #endif
1309 };
1310 #endif
1311
1312 #ifdef CONFIG_I2C3_RK30
1313 static struct i2c_board_info __initdata i2c3_info[] = {
1314 };
1315 #endif
1316
1317 #ifdef CONFIG_I2C4_RK30
1318 static struct i2c_board_info __initdata i2c4_info[] = {
1319 };
1320 #endif
1321
1322 #ifdef CONFIG_I2C_GPIO_RK30
1323 #define I2C_SDA_PIN     INVALID_GPIO// RK30_PIN2_PD6   //set sda_pin here
1324 #define I2C_SCL_PIN     INVALID_GPIO//RK30_PIN2_PD7   //set scl_pin here
1325 static int rk30_i2c_io_init(void)
1326 {
1327         //set iomux (gpio) here
1328         //rk30_mux_api_set(GPIO2D7_I2C1SCL_NAME, GPIO2D_GPIO2D7);
1329         //rk30_mux_api_set(GPIO2D6_I2C1SDA_NAME, GPIO2D_GPIO2D6);
1330
1331         return 0;
1332 }
1333 struct i2c_gpio_platform_data default_i2c_gpio_data = {
1334        .sda_pin = I2C_SDA_PIN,
1335        .scl_pin = I2C_SCL_PIN,
1336        .udelay = 5, // clk = 500/udelay = 100Khz
1337        .timeout = 100,//msecs_to_jiffies(100),
1338        .bus_num    = 5,
1339        .io_init = rk30_i2c_io_init,
1340 };
1341 static struct i2c_board_info __initdata i2c_gpio_info[] = {
1342 };
1343 #endif
1344
1345 static void __init rk30_i2c_register_board_info(void)
1346 {
1347 #ifdef CONFIG_I2C0_RK30
1348         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
1349 #endif
1350 #ifdef CONFIG_I2C1_RK30
1351         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
1352 #endif
1353 #ifdef CONFIG_I2C2_RK30
1354         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
1355 #endif
1356 #ifdef CONFIG_I2C3_RK30
1357         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
1358 #endif
1359 #ifdef CONFIG_I2C4_RK30
1360         i2c_register_board_info(4, i2c4_info, ARRAY_SIZE(i2c4_info));
1361 #endif
1362 #ifdef CONFIG_I2C_GPIO_RK30
1363         i2c_register_board_info(5, i2c_gpio_info, ARRAY_SIZE(i2c_gpio_info));
1364 #endif
1365 }
1366 //end of i2c
1367
1368 #define POWER_ON_PIN RK30_PIN0_PA0   //power_hold
1369 static void rk30_pm_power_off(void)
1370 {
1371         printk(KERN_ERR "rk30_pm_power_off start...\n");
1372         gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
1373 #if defined(CONFIG_MFD_WM831X)
1374         wm831x_set_bits(Wm831x,WM831X_GPIO_LEVEL,0x0001,0x0000);  //set sys_pwr 0
1375         wm831x_device_shutdown(Wm831x);//wm8326 shutdown
1376 #endif
1377         while (1);
1378 }
1379
1380 static void __init machine_rk30_board_init(void)
1381 {
1382         //avs_init();
1383         gpio_request(POWER_ON_PIN, "poweronpin");
1384         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
1385         
1386         pm_power_off = rk30_pm_power_off;
1387         
1388         rk30_i2c_register_board_info();
1389         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1390         platform_add_devices(devices, ARRAY_SIZE(devices));
1391         board_usb_detect_init(RK30_PIN0_PA7);
1392
1393 #ifdef CONFIG_WIFI_CONTROL_FUNC
1394         rk29sdk_wifi_bt_gpio_control_init();
1395 #endif
1396 }
1397
1398 static void __init rk30_reserve(void)
1399 {
1400 #ifdef CONFIG_ION
1401         rk30_ion_pdata.heaps[0].base = board_mem_reserve_add("ion", ION_RESERVE_SIZE);
1402 #endif
1403 #ifdef CONFIG_FB_ROCKCHIP
1404         resource_fb[0].start = board_mem_reserve_add("fb0", RK30_FB0_MEM_SIZE);
1405         resource_fb[0].end = resource_fb[0].start + RK30_FB0_MEM_SIZE - 1;
1406         #if 0
1407         resource_fb[1].start = board_mem_reserve_add("ipp buf", RK30_FB0_MEM_SIZE);
1408         resource_fb[1].end = resource_fb[1].start + RK30_FB0_MEM_SIZE - 1;
1409         resource_fb[2].start = board_mem_reserve_add("fb2", RK30_FB0_MEM_SIZE);
1410         resource_fb[2].end = resource_fb[2].start + RK30_FB0_MEM_SIZE - 1;
1411         #endif
1412 #endif
1413 #ifdef CONFIG_VIDEO_RK29
1414         rk30_camera_request_reserve_mem();
1415 #endif
1416         board_mem_reserved();
1417 }
1418
1419 /**
1420  * dvfs_cpu_logic_table: table for arm and logic dvfs 
1421  * @frequency   : arm frequency
1422  * @cpu_volt    : arm voltage depend on frequency
1423  * @logic_volt  : logic voltage arm requests depend on frequency
1424  * comments     : min arm/logic voltage
1425  */
1426 static struct dvfs_arm_table dvfs_cpu_logic_table[] = {
1427 #if 0
1428         {.frequency = 252 * 1000,       .cpu_volt = 1075 * 1000,        .logic_volt = 1125 * 1000},//0.975V/1.000V
1429 #endif
1430         {.frequency = 504 * 1000,       .cpu_volt = 975 * 1000,         .logic_volt = 1000 * 1000},//0.975V/1.000V
1431         {.frequency = 816 * 1000,       .cpu_volt = 1000 * 1000,        .logic_volt = 1000 * 1000},//1.000V/1.025V
1432         {.frequency = 1200 * 1000,      .cpu_volt = 1025 * 1000,        .logic_volt = 1000 * 1000},//1.100V/1.050V
1433 #if 0
1434         {.frequency = 1008 * 1000,      .cpu_volt = 1125 * 1000,        .logic_volt = 1150 * 1000},//1.025V/1.050V
1435         {.frequency = 1272 * 1000,      .cpu_volt = 1225 * 1000,        .logic_volt = 1200 * 1000},//1.150V/1.100V
1436         {.frequency = 1416 * 1000,      .cpu_volt = 1300 * 1000,        .logic_volt = 1200 * 1000},//1.225V/1.100V
1437         {.frequency = 1512 * 1000,      .cpu_volt = 1350 * 1000,        .logic_volt = 1250 * 1000},//1.300V/1.150V
1438         {.frequency = 1608 * 1000,      .cpu_volt = 1425 * 1000,        .logic_volt = 1300 * 1000},//1.325V/1.175V
1439 #endif
1440         {.frequency = CPUFREQ_TABLE_END},
1441 };
1442
1443 static struct cpufreq_frequency_table dvfs_gpu_table[] = {
1444         {.frequency = 266 * 1000,       .index = 1000 * 1000},
1445         {.frequency = 400 * 1000,       .index = 1000 * 1000},
1446         {.frequency = CPUFREQ_TABLE_END},
1447 };
1448
1449 static struct cpufreq_frequency_table dvfs_ddr_table[] = {
1450         {.frequency = 300 * 1000,       .index = 1000 * 1000},
1451         {.frequency = 400 * 1000,       .index = 1000 * 1000},
1452         {.frequency = CPUFREQ_TABLE_END},
1453 };
1454
1455 #define DVFS_CPU_TABLE_SIZE     (ARRAY_SIZE(dvfs_cpu_logic_table))
1456 static struct cpufreq_frequency_table cpu_dvfs_table[DVFS_CPU_TABLE_SIZE];
1457 static struct cpufreq_frequency_table dep_cpu2core_table[DVFS_CPU_TABLE_SIZE];
1458
1459 void __init board_clock_init(void)
1460 {
1461         rk30_clock_data_init(periph_pll_default, codec_pll_default, RK30_CLOCKS_DEFAULT_FLAGS);
1462         dvfs_set_arm_logic_volt(dvfs_cpu_logic_table, cpu_dvfs_table, dep_cpu2core_table);
1463         dvfs_set_freq_volt_table(clk_get(NULL, "gpu"), dvfs_gpu_table);
1464         dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
1465 }
1466
1467 MACHINE_START(RK30, "RK30board")
1468         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
1469         .fixup          = rk30_fixup,
1470         .reserve        = &rk30_reserve,
1471         .map_io         = rk30_map_io,
1472         .init_irq       = rk30_init_irq,
1473         .timer          = &rk30_timer,
1474         .init_machine   = machine_rk30_board_init,
1475 MACHINE_END