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