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