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