rk2928phonepad:
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk2928 / board-rk2928-phonepad.c
1 /* arch/arm/mach-rk2928/board-rk2928-fpga.c
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
30 #include <asm/setup.h>
31 #include <asm/mach-types.h>
32 #include <asm/mach/arch.h>
33 #include <asm/mach/map.h>
34 #include <asm/mach/flash.h>
35 #include <asm/hardware/gic.h>
36 #include <mach/dvfs.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_MODEM_SOUND)
50 #include "../../../drivers/misc/modem_sound.h"
51 #endif
52 #if defined(CONFIG_HDMI_RK30)
53         #include "../../../drivers/video/rockchip/hdmi/rk_hdmi.h"
54 #endif
55 #include "../../../drivers/headset_observe/rk_headset.h"
56
57 #if defined(CONFIG_SPIM_RK29)
58 #include "../../../drivers/spi/rk29_spim.h"
59 #endif
60
61 #if defined(CONFIG_SC6610)
62 #include <linux/mu509.h>
63 #endif
64
65 #include "board-rk2928-phonepad-camera.c" 
66 #include "board-rk2928-phonepad-key.c"
67
68 #ifdef  CONFIG_THREE_FB_BUFFER
69 #define RK30_FB0_MEM_SIZE 12*SZ_1M
70 #else
71 #define RK30_FB0_MEM_SIZE 8*SZ_1M
72 #endif
73
74 static struct spi_board_info board_spi_devices[] = {
75 };
76
77 /***********************************************************
78 *       rk30  backlight
79 ************************************************************/
80 #ifdef CONFIG_BACKLIGHT_RK29_BL
81 #define PWM_ID            0
82 #define PWM_MUX_NAME      GPIO0D2_PWM_0_NAME
83 #define PWM_MUX_MODE      GPIO0D_PWM_0
84 #define PWM_MUX_MODE_GPIO GPIO0D_GPIO0D2
85 #define PWM_GPIO          RK2928_PIN0_PD2
86 #define PWM_EFFECT_VALUE  1
87
88 //#define LCD_DISP_ON_PIN
89
90 #ifdef  LCD_DISP_ON_PIN
91
92 #define BL_EN_PIN         RK2928_PIN1_PB0
93 #define BL_EN_VALUE       GPIO_HIGH
94 #endif
95 static int rk29_backlight_io_init(void)
96 {
97         int ret = 0;
98         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
99 #ifdef  LCD_DISP_ON_PIN
100         // rk30_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
101
102         ret = gpio_request(BL_EN_PIN, NULL);
103         if (ret != 0) {
104                 gpio_free(BL_EN_PIN);
105         }
106
107         gpio_direction_output(BL_EN_PIN, 0);
108         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
109 #endif
110         return ret;
111 }
112
113 static int rk29_backlight_io_deinit(void)
114 {
115         int ret = 0;
116 #ifdef  LCD_DISP_ON_PIN
117         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
118         gpio_free(BL_EN_PIN);
119 #endif
120         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
121         return ret;
122 }
123
124 static int rk29_backlight_pwm_suspend(void)
125 {
126         int ret = 0;
127         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
128         if (gpio_request(PWM_GPIO, NULL)) {
129                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
130                 return -1;
131         }
132         gpio_direction_output(PWM_GPIO, GPIO_LOW);
133 #ifdef  LCD_DISP_ON_PIN
134         gpio_direction_output(BL_EN_PIN, 0);
135         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
136 #endif
137
138         return ret;
139 }
140
141 static int rk29_backlight_pwm_resume(void)
142 {
143         gpio_free(PWM_GPIO);
144         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
145 #ifdef  LCD_DISP_ON_PIN
146         msleep(30);
147         gpio_direction_output(BL_EN_PIN, 1);
148         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
149 #endif
150         return 0;
151 }
152
153 static struct rk29_bl_info rk29_bl_info = {
154         .pwm_id = PWM_ID,
155         .min_brightness = 80,
156         .bl_ref = PWM_EFFECT_VALUE,
157         .io_init = rk29_backlight_io_init,
158         .io_deinit = rk29_backlight_io_deinit,
159         .pwm_suspend = rk29_backlight_pwm_suspend,
160         .pwm_resume = rk29_backlight_pwm_resume,
161 };
162
163 static struct platform_device rk29_device_backlight = {
164         .name   = "rk29_backlight",
165         .id     = -1,
166         .dev    = {
167                 .platform_data  = &rk29_bl_info,
168         }
169 };
170
171 #endif
172
173 #ifdef CONFIG_FB_ROCKCHIP
174
175 #define LCD_MUX_NAME  GPIO0C3_UART0_CTSN_NAME
176 #define LCD_GPIO_MODE GPIO0C_GPIO0C3
177
178 #define LCD_EN        RK2928_PIN0_PC3
179 #define LCD_EN_VALUE  GPIO_LOW
180
181 static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
182 {
183         int ret = 0;
184
185     rk30_mux_api_set(LCD_MUX_NAME, LCD_GPIO_MODE);
186         ret = gpio_request(LCD_EN, NULL);
187         if (ret != 0)
188         {
189                 gpio_free(LCD_EN);
190                 printk(KERN_ERR "request lcd en pin fail!\n");
191                 return -1;
192         }
193         else
194         {
195                 gpio_direction_output(LCD_EN, LCD_EN_VALUE); //disable
196         }
197         return 0;
198 }
199 static int rk_fb_io_disable(void)
200 {
201     gpio_set_value(LCD_EN, !LCD_EN_VALUE);
202         return 0;
203 }
204 static int rk_fb_io_enable(void)
205 {
206     gpio_set_value(LCD_EN, LCD_EN_VALUE);
207         return 0;
208 }
209
210 #if defined(CONFIG_LCDC_RK2928)
211 struct rk29fb_info lcdc_screen_info = {
212         .prop      = PRMRY,             //primary display device
213         .io_init   = rk_fb_io_init,
214         .io_disable = rk_fb_io_disable,
215         .io_enable = rk_fb_io_enable,
216         .set_screen_info = set_lcd_info,
217 };
218 #endif
219
220 static struct resource resource_fb[] = {
221         [0] = {
222                 .name  = "fb0 buf",
223                 .start = 0,
224                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
225                 .flags = IORESOURCE_MEM,
226         },
227         [1] = {
228                 .name  = "ipp buf",  //for rotate
229                 .start = 0,
230                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
231                 .flags = IORESOURCE_MEM,
232         },
233         [2] = {
234                 .name  = "fb2 buf",
235                 .start = 0,
236                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
237                 .flags = IORESOURCE_MEM,
238         },
239 };
240
241 static struct platform_device device_fb = {
242         .name           = "rk-fb",
243         .id             = -1,
244         .num_resources  = ARRAY_SIZE(resource_fb),
245         .resource       = resource_fb,
246 };
247 #endif
248
249 //LCDC
250 #ifdef CONFIG_LCDC_RK2928
251 static struct resource resource_lcdc[] = {
252         [0] = {
253                 .name  = "lcdc reg",
254                 .start = RK2928_LCDC_PHYS,
255                 .end   = RK2928_LCDC_PHYS + RK2928_LCDC_SIZE - 1,
256                 .flags = IORESOURCE_MEM,
257         },
258         
259         [1] = {
260                 .name  = "lcdc irq",
261                 .start = IRQ_LCDC,
262                 .end   = IRQ_LCDC,
263                 .flags = IORESOURCE_IRQ,
264         },
265 };
266
267 static struct platform_device device_lcdc = {
268         .name             = "rk2928-lcdc",
269         .id               = 0,
270         .num_resources    = ARRAY_SIZE(resource_lcdc),
271         .resource         = resource_lcdc,
272         .dev            = {
273                 .platform_data = &lcdc_screen_info,
274         },
275 };
276 #endif
277
278 #ifdef CONFIG_ION
279 #define ION_RESERVE_SIZE        (80 * SZ_1M)
280 static struct ion_platform_data rk30_ion_pdata = {
281         .nr = 1,
282         .heaps = {
283                 {
284                         .type = ION_HEAP_TYPE_CARVEOUT,
285                         .id = ION_NOR_HEAP_ID,
286                         .name = "norheap",
287                         .size = ION_RESERVE_SIZE,
288                 }
289         },
290 };
291
292 static struct platform_device device_ion = {
293         .name = "ion-rockchip",
294         .id = 0,
295         .dev = {
296                 .platform_data = &rk30_ion_pdata,
297         },
298 };
299 #endif
300
301
302 #if defined (CONFIG_TOUCHSCREEN_I30)
303 #define TOUCH_RESET_PIN RK2928_PIN3_PD5
304 #define TOUCH_INT_PIN   RK2928_PIN3_PC7
305 int ft5306_init_platform_hw(void)
306 {
307         struct regulator *ldo;
308 //      printk("ft5306_init_platform_hw\n");
309
310         ldo = regulator_get(NULL, "vaux33");
311         regulator_disable(ldo);
312         
313         if(gpio_request(TOUCH_RESET_PIN,NULL) != 0)
314         {
315                 gpio_free(TOUCH_RESET_PIN);
316                 printk("ft5306_init_platform_hw TOUCH_RESET_PIN error\n");
317                 return -EIO;
318         }
319
320         if(gpio_request(TOUCH_INT_PIN,NULL) != 0)
321         {
322                 gpio_free(TOUCH_INT_PIN);
323                 printk("ift5306_init_platform_hw TOUCH_INT_PIN error\n");
324                 return -EIO;
325         }
326         gpio_direction_input(TOUCH_INT_PIN);
327         gpio_direction_output(TOUCH_RESET_PIN, 1);
328         gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
329         msleep(50);
330         regulator_enable(ldo);
331         regulator_put(ldo);
332         msleep(300);
333         return 0;
334         
335 }
336
337 void ft5306_exit_platform_hw(void)
338 {
339 //      printk("ft5306_exit_platform_hw\n");
340         gpio_free(TOUCH_RESET_PIN);
341         gpio_free(TOUCH_INT_PIN);
342 }
343
344 int ft5306_platform_sleep(void)
345 {
346 #if 0
347         struct regulator *ldo;
348         ldo = regulator_get(NULL, "ldo9");
349         regulator_disable(ldo);
350         regulator_put(ldo);
351
352         printk("ft5306_platform_sleep\n");
353 #endif
354         gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
355         return 0;
356 }
357
358 int ft5306_platform_wakeup(void)
359 {
360 #if 0
361         struct regulator *ldo;
362         ldo = regulator_get(NULL, "ldo9");
363         regulator_set_voltage(ldo, 3300000, 3300000);
364         regulator_enable(ldo);
365         regulator_put(ldo);
366
367         printk("ft5306_platform_wakeup\n");
368 #endif
369         gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
370         msleep(300);
371         return 0;
372 }
373
374 struct ft5306_platform_data ft5306_info = {
375   .irq_pin = TOUCH_INT_PIN,
376   .rest_pin = TOUCH_RESET_PIN,
377   .init_platform_hw= ft5306_init_platform_hw,
378   .exit_platform_hw= ft5306_exit_platform_hw,
379   .platform_sleep  = ft5306_platform_sleep,
380   .platform_wakeup = ft5306_platform_wakeup,
381
382 };
383 #endif
384
385 #if defined(CONFIG_TOUCHSCREEN_BYD693X)
386
387 #define TOUCH_RESET_PIN RK2928_PIN3_PD5
388 #define TOUCH_INT_PIN   RK2928_PIN3_PC7
389 struct byd_platform_data byd693x_info = {
390         .int_pin = TOUCH_INT_PIN,
391         .rst_pin = TOUCH_RESET_PIN,
392         .screen_max_x = 800,
393         .screen_max_y = 480,
394         .xpol = -1,
395 };
396 #endif
397
398 /*MMA7660 gsensor*/
399 #if defined (CONFIG_GS_MMA7660)
400 #define MMA7660_INT_PIN   RK2928_PIN1_PB1
401
402 static int mma7660_init_platform_hw(void)
403 {
404         rk30_mux_api_set(GPIO1B1_SPI_TXD_UART1_SOUT_NAME, GPIO1B_GPIO1B1);
405
406         return 0;
407 }
408
409 static struct sensor_platform_data mma7660_info = {
410         .type = SENSOR_TYPE_ACCEL,
411         .irq_enable = 1,
412         .poll_delay_ms = 30,
413         .init_platform_hw = mma7660_init_platform_hw,
414         .orientation = {-1, 0, 0, 0, 0, -1, 0, 1, 0},
415 };
416 #endif
417
418
419 #if defined (CONFIG_GS_KXTIK)
420 #define KXTIK_INT_PIN         RK2928_PIN3_PD1
421 #if 0
422
423 static int kxtik_init_hw(void)
424 {
425         int ret = 0;
426         
427         ret = gpio_request(KXTIK_INT_PIN,"kxtik_irq");
428         if(ret){
429                 printk("kxtik gpio request fail!\n");
430                 return ret;
431         }
432         else{
433                 gpio_direction_input(KXTIK_INT_PIN);
434         }
435         return ret;
436 }
437 static void kxtik_exit_hw(void)
438 {
439         gpio_free(KXTIK_INT_PIN);
440 }
441
442 static struct gsensor_platform_data kxtik_pdata = {
443         .swap_xy = 0,
444         .swap_xyz = 1,
445         .init_platform_hw = kxtik_init_hw,
446         .exit_platform_hw = kxtik_exit_hw,
447         .orientation = {-1, 0, 0, 0, 0, -1, 0, 1, 0},
448 };
449
450 #endif
451 static int kxtik_init_platform_hw(void)
452 {
453         printk("%s: >>>>>>>>>>>>>>>>\n\n\n", __func__);
454         return 0;
455 }
456
457 static struct sensor_platform_data kxtik_pdata = {
458         .type = SENSOR_TYPE_ACCEL,
459         .irq_enable = 1,
460         .poll_delay_ms = 30,
461         .init_platform_hw = kxtik_init_platform_hw,
462         .orientation = {-1, 0, 0, 0, 0, -1, 0, 1, 0},
463         //.orientation = {0, 1, 0, 0, 0, -1, 1, 0, 0},
464 };
465
466 #endif /* CONFIG_GS_KXTIK*/
467
468 #ifdef CONFIG_INPUT_AP321XX
469 #define AP321XX_INT_PIN         RK2928_PIN0_PC6
470
471 static int AP321XX_init_hw(void)
472 {
473         int ret = 0;
474         ret = gpio_request(AP321XX_INT_PIN, NULL);
475         if (ret != 0)
476         {
477                 gpio_free(AP321XX_INT_PIN);
478                 printk(KERN_ERR "request AP321XX_INT_PIN fail!\n");
479                 return -1;
480         }
481         else
482         {
483                 gpio_direction_input(AP321XX_INT_PIN);
484         }
485         return 0;
486 }
487
488 static void AP321XX_exit_hw(void)
489 {
490         gpio_free(AP321XX_INT_PIN);
491         return;
492 }
493
494 static struct ap321xx_platform_data ap321xx_info = {
495         .init_platform_hw = AP321XX_init_hw,
496         .exit_platform_hw = AP321XX_exit_hw,
497 };
498
499 #endif
500
501 #if defined(CONFIG_BATTERY_RK30_ADC)||defined(CONFIG_BATTERY_RK30_ADC_FAC)
502 static struct rk30_adc_battery_platform_data rk30_adc_battery_platdata = {
503         .dc_det_pin      = RK2928_PIN1_PA5,
504         .batt_low_pin    = INVALID_GPIO,
505         .charge_set_pin  = INVALID_GPIO,
506         .charge_ok_pin   = RK2928_PIN1_PA0,
507         .dc_det_level    = GPIO_HIGH,  //
508         .charge_ok_level = GPIO_HIGH,
509 };
510
511 static struct platform_device rk30_device_adc_battery = {
512         .name   = "rk30-battery",
513         .id     = -1,
514         .dev = {
515                 .platform_data = &rk30_adc_battery_platdata,
516         },
517 };
518 #endif
519
520
521 #if CONFIG_RK30_PWM_REGULATOR
522 const static int pwm_voltage_map[] = {
523         1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000, 1375000, 1400000
524 };
525
526 static struct regulator_consumer_supply pwm_dcdc1_consumers[] = {
527         {
528                 .supply = "vdd_core",
529         }
530 };
531
532 struct regulator_init_data pwm_regulator_init_dcdc[1] =
533 {
534         {
535                 .constraints = {
536                         .name = "PWM_DCDC1",
537                         .min_uV = 600000,
538                         .max_uV = 1800000,      //0.6-1.8V
539                         .apply_uV = true,
540                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
541                 },
542                 .num_consumer_supplies = ARRAY_SIZE(pwm_dcdc1_consumers),
543                 .consumer_supplies = pwm_dcdc1_consumers,
544         },
545 };
546
547 static struct pwm_platform_data pwm_regulator_info[1] = {
548         {
549                 .pwm_id = 2,
550                 .pwm_gpio = RK2928_PIN0_PD4,
551                 .pwm_iomux_name = GPIO0D4_PWM_2_NAME,
552                 .pwm_iomux_pwm = GPIO0D_PWM_2, 
553                 .pwm_iomux_gpio = GPIO0D_GPIO0D4,
554                 .pwm_voltage = 1200000,
555                 .suspend_voltage = 1050000,
556                 .min_uV = 1000000,
557                 .max_uV = 1400000,
558                 .coefficient = 455,     //45.5%
559                 .pwm_voltage_map = pwm_voltage_map,
560                 .init_data      = &pwm_regulator_init_dcdc[0],
561         },
562 };
563
564 struct platform_device pwm_regulator_device[1] = {
565         {
566                 .name = "pwm-voltage-regulator",
567                 .id = 0,
568                 .dev            = {
569                         .platform_data = &pwm_regulator_info[0],
570                 }
571         },
572 };
573 #endif
574
575 #if defined(CONFIG_MODEM_SOUND)
576
577 struct modem_sound_data modem_sound_info = {
578         .spkctl_io = RK2928_PIN3_PD4,
579         .spkctl_active = GPIO_HIGH,
580 };
581
582 struct platform_device modem_sound_device = {
583         .name = "modem_sound",
584         .id = -1,
585         .dev            = {
586         .platform_data = &modem_sound_info,
587                 }
588         };
589 #endif
590 /**************************************************************************************************
591  * SDMMC devices,  include the module of SD,MMC,and sdio.noted by xbw at 2012-03-05
592 **************************************************************************************************/
593 #ifdef CONFIG_SDMMC_RK29
594 #include "board-rk2928-phonepad-sdmmc.c"
595
596 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
597 #define SDMMC0_WRITE_PROTECT_PIN        RK2928_PIN1_PA7 //According to your own project to set the value of write-protect-pin.
598 #endif
599
600 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
601 #define SDMMC1_WRITE_PROTECT_PIN        RK2928_PIN0_PD5 //According to your own project to set the value of write-protect-pin.
602 #endif
603
604 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N    RK2928_PIN0_PB2
605
606 #endif //endif ---#ifdef CONFIG_SDMMC_RK29
607
608 #ifdef CONFIG_SDMMC0_RK29
609 static int rk29_sdmmc0_cfg_gpio(void)
610 {
611         rk29_sdmmc_set_iomux(0, 0xFFFF);
612
613         rk30_mux_api_set(GPIO1C1_MMC0_DETN_NAME, GPIO1C_MMC0_DETN);
614
615 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
616         gpio_request(SDMMC0_WRITE_PROTECT_PIN, "sdmmc-wp");
617         gpio_direction_input(SDMMC0_WRITE_PROTECT_PIN);
618 #endif
619
620         return 0;
621 }
622
623 #define CONFIG_SDMMC0_USE_DMA
624 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
625         .host_ocr_avail =
626             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
627              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
628              MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36),
629         .host_caps =
630             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
631         .io_init = rk29_sdmmc0_cfg_gpio,
632
633 #if !defined(CONFIG_SDMMC_RK29_OLD)
634         .set_iomux = rk29_sdmmc_set_iomux,
635 #endif
636
637         .dma_name = "sd_mmc",
638 #ifdef CONFIG_SDMMC0_USE_DMA
639         .use_dma = 1,
640 #else
641         .use_dma = 0,
642 #endif
643         .detect_irq =  INVALID_GPIO,
644         .enable_sd_wakeup = 0,
645
646 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
647         .write_prt = SDMMC0_WRITE_PROTECT_PIN,
648 #else
649         .write_prt = INVALID_GPIO,
650 #endif
651 };
652 #endif // CONFIG_SDMMC0_RK29
653 #ifdef CONFIG_SDMMC1_RK29
654 #define CONFIG_SDMMC1_USE_DMA
655 static int rk29_sdmmc1_cfg_gpio(void)
656 {
657 #if defined(CONFIG_SDMMC_RK29_OLD)
658         rk30_mux_api_set(GPIO0B0_MMC1_CMD_NAME, GPIO0B_MMC1_CMD);
659         rk30_mux_api_set(GPIO0B1_MMC1_CLKOUT_NAME, GPIO0B_MMC1_CLKOUT);
660         rk30_mux_api_set(GPIO0B3_MMC1_D0_NAME, GPIO0B_MMC1_D0);
661         rk30_mux_api_set(GPIO0B4_MMC1_D1_NAME, GPIO0B_MMC1_D1);
662         rk30_mux_api_set(GPIO0B5_MMC1_D2_NAME, GPIO0B_MMC1_D2);
663         rk30_mux_api_set(GPIO0B6_MMC1_D3_NAME, GPIO0B_MMC1_D3);
664         //rk30_mux_api_set(GPIO0B2_MMC1_DETN_NAME, GPIO0B_MMC1_DETN);
665
666 #else
667
668 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
669         gpio_request(SDMMC1_WRITE_PROTECT_PIN, "sdio-wp");
670         gpio_direction_input(SDMMC1_WRITE_PROTECT_PIN);
671 #endif
672
673 #endif
674
675         return 0;
676 }
677
678 struct rk29_sdmmc_platform_data default_sdmmc1_data = {
679         .host_ocr_avail =
680             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
681              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
682              MMC_VDD_33_34),
683
684 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
685         .host_caps = (MMC_CAP_4_BIT_DATA | MMC_CAP_SDIO_IRQ |
686                       MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
687 #else
688         .host_caps =
689             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
690 #endif
691
692         .io_init = rk29_sdmmc1_cfg_gpio,
693
694 #if !defined(CONFIG_SDMMC_RK29_OLD)
695         .set_iomux = rk29_sdmmc_set_iomux,
696 #endif
697
698         .dma_name = "sdio",
699 #ifdef CONFIG_SDMMC1_USE_DMA
700         .use_dma = 1,
701 #else
702         .use_dma = 0,
703 #endif
704
705 #if !defined(CONFIG_USE_SDMMC1_FOR_WIFI_DEVELOP_BOARD)
706 #ifdef CONFIG_WIFI_CONTROL_FUNC
707         .status = rk29sdk_wifi_status,
708         .register_status_notify = rk29sdk_wifi_status_register,
709 #endif
710 #if 1
711         .detect_irq = INVALID_GPIO,//RK29SDK_WIFI_SDIO_CARD_DETECT_N,
712 #endif
713
714 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
715         .write_prt = SDMMC1_WRITE_PROTECT_PIN,
716 #else
717         .write_prt = INVALID_GPIO,
718 #endif
719
720 #else
721         .detect_irq = INVALID_GPIO,
722         .enable_sd_wakeup = 0,
723 #endif
724
725 };
726 #endif //endif--#ifdef CONFIG_SDMMC1_RK29
727
728 #if defined(CONFIG_SC6610)
729 static int sc6610_io_init(void)
730 {
731         
732         return 0;
733 }
734
735 static int sc6610_io_deinit(void)
736 {
737         
738
739         return 0;
740 }
741
742 struct rk29_mu509_data rk29_sc6610_info = {
743         .io_init = sc6610_io_init,
744         .io_deinit = sc6610_io_deinit,
745         .bp_power = RK2928_PIN3_PC2,//RK29_PIN0_PB4,
746         .bp_reset = NULL,//RK29_PIN0_PB3,
747         .bp_wakeup_ap = RK2928_PIN3_PC3,//RK29_PIN0_PC2,
748         .ap_wakeup_bp = RK2928_PIN3_PC4,//RK29_PIN0_PB0, 
749         .modem_assert = RK2928_PIN3_PC5,
750 };
751 struct platform_device rk29_device_sc6610 = {
752         .name = "SC6610",
753         .id = -1,
754         .dev            = {
755                 .platform_data = &rk29_sc6610_info,
756         }
757     };
758 #endif
759 #if defined (CONFIG_RK_HEADSET_DET) || defined (CONFIG_RK_HEADSET_IRQ_HOOK_ADC_DET)
760 static int rk_headset_io_init(int gpio, char *iomux_name, int iomux_mode)
761 {
762         int ret;
763         ret = gpio_request(gpio, "headset_io");
764         if(ret) 
765                 return ret;
766
767         rk30_mux_api_set(iomux_name, iomux_mode);
768         gpio_pull_updown(gpio, PullDisable);
769         gpio_direction_input(gpio);
770         mdelay(50);
771         return 0;
772 };
773
774 static int rk_hook_io_init(int gpio, char *iomux_name, int iomux_mode)
775 {
776         int ret;
777         ret = gpio_request(gpio, "hook_io");
778         if(ret) 
779                 return ret;
780
781         rk30_mux_api_set(iomux_name, iomux_mode);
782         gpio_pull_updown(gpio, PullDisable);
783         gpio_direction_input(gpio);
784         mdelay(50);
785         return 0;
786 };
787
788 struct rk_headset_pdata rk_headset_info = {
789                 .Headset_gpio           = RK2928_PIN1_PB4,
790                 .Hook_gpio  = RK2928_PIN0_PD1,
791                 .headset_in_type = HEADSET_IN_HIGH,
792                 .hook_key_code = KEY_MEDIA,
793                 .headset_gpio_info = {GPIO1B4_SPI_CSN1_NAME, GPIO1B_GPIO1B4},
794                 .headset_io_init = rk_headset_io_init,
795                 .hook_gpio_info = {GPIO0D1_UART2_CTSN_NAME, GPIO0D_GPIO0D1},
796                 .hook_io_init = rk_hook_io_init,
797 };
798 struct platform_device rk_device_headset = {
799                 .name   = "rk_headsetdet",
800                 .id     = 0,
801                 .dev    = {
802                             .platform_data = &rk_headset_info,
803                 }
804 };
805 #endif
806 #ifdef CONFIG_SND_SOC_RK2928
807 static struct resource resources_acodec[] = {
808         {
809                 .start  = RK2928_ACODEC_PHYS,
810                 .end    = RK2928_ACODEC_PHYS + RK2928_ACODEC_SIZE - 1,
811                 .flags  = IORESOURCE_MEM,
812         },
813         {
814                 .start  = RK2928_PIN3_PD4,
815                 .end    = RK2928_PIN3_PD4,
816                 .flags  = IORESOURCE_IO,
817         },
818 };
819
820 static struct platform_device device_acodec = {
821         .name   = "rk2928-codec",
822         .id             = -1,
823         .num_resources  = ARRAY_SIZE(resources_acodec),
824         .resource       = resources_acodec,
825 };
826 #endif
827
828 static struct platform_device *devices[] __initdata = {
829 #ifdef CONFIG_FB_ROCKCHIP
830         &device_fb,
831 #endif
832 #ifdef CONFIG_LCDC_RK2928
833         &device_lcdc,
834 #endif
835 #ifdef CONFIG_BACKLIGHT_RK29_BL
836         &rk29_device_backlight,
837 #endif
838 #ifdef CONFIG_ION
839         &device_ion,
840 #endif
841 #ifdef CONFIG_SND_SOC_RK2928
842         &device_acodec,
843 #endif
844
845 #if defined(CONFIG_BATTERY_RK30_ADC)||defined(CONFIG_BATTERY_RK30_ADC_FAC)
846         &rk30_device_adc_battery,
847 #endif
848 #if defined(CONFIG_SC6610)
849         &rk29_device_sc6610,
850
851 #endif
852 #if defined (CONFIG_RK_HEADSET_DET) ||  defined (CONFIG_RK_HEADSET_IRQ_HOOK_ADC_DET)
853         &rk_device_headset,
854 #endif
855 #if defined (CONFIG_MODEM_SOUND)
856  &modem_sound_device,
857 #endif
858 };
859 //i2c
860 #ifdef CONFIG_I2C0_RK30
861 #ifdef CONFIG_MFD_TPS65910
862 #define TPS65910_HOST_IRQ        RK2928_PIN3_PC6
863 #include "board-rk2928-phonepad-tps65910.c"
864 #endif
865 #ifdef CONFIG_REGULATOR_ACT8931
866 #include "board-rk2928-sdk-act8931.c"
867 #endif
868
869 static struct i2c_board_info __initdata i2c0_info[] = {
870 #if defined (CONFIG_MFD_TPS65910)
871         {
872         .type           = "tps65910",
873         .addr           = TPS65910_I2C_ID0,
874         .flags          = 0,
875         .irq            = TPS65910_HOST_IRQ,
876         .platform_data = &tps65910_data,
877         },
878 #endif
879 #if defined (CONFIG_REGULATOR_ACT8931)
880         {
881                 .type                   = "act8931",
882                 .addr           = 0x5b, 
883                 .flags                  = 0,
884                 .platform_data=&act8931_data,
885         },
886 #endif
887 };
888 #endif
889 #ifdef CONFIG_I2C1_RK30
890 static struct i2c_board_info __initdata i2c1_info[] = {
891 #if defined (CONFIG_GS_MMA7660)
892                 {
893                         .type           = "gs_mma7660",
894                         .addr           = 0x4c,
895                         .flags          = 0,
896                         .irq            = MMA7660_INT_PIN,
897                         .platform_data = &mma7660_info,
898                 },
899 #endif
900
901
902 #if defined (CONFIG_GS_KXTIK)
903                 {
904                                 .type           = "gs_kxtik",
905                                 .addr           = 0x0F,
906                                 .flags          = 0,
907                                 .platform_data = &kxtik_pdata,
908                                 .irq = KXTIK_INT_PIN, // Replace with appropriate GPIO setup
909                 },
910 #endif
911
912 #ifdef CONFIG_INPUT_AP321XX
913         {
914                 .type                   = "ap321xx",
915                 .addr                   = 0x1E,
916                 .flags                  = 0,
917                 .irq                     = AP321XX_INT_PIN,
918                 .platform_data = &ap321xx_info
919         },
920 #endif
921 #ifdef CONFIG_RDA5990
922 #define RDA_WIFI_CORE_ADDR (0x13)
923 #define RDA_WIFI_RF_ADDR (0x14) //correct add is 0x14
924 #define RDA_BT_CORE_ADDR (0x15)
925 #define RDA_BT_RF_ADDR (0x16)
926
927 #define RDA_WIFI_RF_I2C_DEVNAME "rda_wifi_rf_i2c"
928 #define RDA_WIFI_CORE_I2C_DEVNAME "rda_wifi_core_i2c"
929 #define RDA_BT_RF_I2C_DEVNAME "rda_bt_rf_i2c"
930 #define RDA_BT_CORE_I2C_DEVNAME "rda_bt_core_i2c"
931                 {
932                         .type          = RDA_WIFI_CORE_I2C_DEVNAME,
933                         .addr          = RDA_WIFI_CORE_ADDR,
934                         .flags         = 0,
935
936                 },
937
938                 {
939                         .type          = RDA_WIFI_RF_I2C_DEVNAME,
940                         .addr          = RDA_WIFI_RF_ADDR,
941                         .flags         = 0,
942
943                 },
944                 {
945                         .type          = RDA_BT_CORE_I2C_DEVNAME,
946                         .addr          = RDA_BT_CORE_ADDR,
947                         .flags         = 0,
948
949                 },
950                 {
951                         .type          = RDA_BT_RF_I2C_DEVNAME,
952                         .addr          = RDA_BT_RF_ADDR,
953                         .flags         = 0,
954
955                 },
956 #endif
957
958 };
959 #endif
960 #ifdef CONFIG_I2C2_RK30
961 static struct i2c_board_info __initdata i2c2_info[] = {
962 #if defined (CONFIG_TOUCHSCREEN_I30)
963         {
964                 .type          = "ft5x0x_ts",
965                 .addr          = 0x38,
966                 .flags         = 0,
967                 .irq           = TOUCH_INT_PIN,
968                 .platform_data = &ft5306_info,
969         },
970 #endif
971 #if defined(CONFIG_TOUCHSCREEN_BYD693X)
972         {
973                 .type          = "byd693x-ts",
974                 .addr          = 0x52,
975                 .flags         = 0,
976                 .irq           = TOUCH_INT_PIN,
977                 .platform_data = &byd693x_info,
978         },
979 #endif
980 };
981 #endif
982 #ifdef CONFIG_I2C3_RK30
983 static struct i2c_board_info __initdata i2c3_info[] = {
984 };
985 #endif
986 #ifdef CONFIG_I2C_GPIO_RK30
987 #define I2C_SDA_PIN     INVALID_GPIO   //set sda_pin here
988 #define I2C_SCL_PIN     INVALID_GPIO   //set scl_pin here
989 static int rk30_i2c_io_init(void)
990 {
991         //set iomux (gpio) here
992
993         return 0;
994 }
995 struct i2c_gpio_platform_data default_i2c_gpio_data = {
996        .sda_pin = I2C_SDA_PIN,
997        .scl_pin = I2C_SCL_PIN,
998        .udelay = 5, // clk = 500/udelay = 100Khz
999        .timeout = 100,//msecs_to_jiffies(100),
1000        .bus_num    = 5,
1001        .io_init = rk30_i2c_io_init,
1002 };
1003 static struct i2c_board_info __initdata i2c_gpio_info[] = {
1004 };
1005 #endif
1006 static void __init rk30_i2c_register_board_info(void)
1007 {
1008 #ifdef CONFIG_I2C0_RK30
1009         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
1010 #endif
1011 #ifdef CONFIG_I2C1_RK30
1012         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
1013 #endif
1014 #ifdef CONFIG_I2C2_RK30
1015         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
1016 #endif
1017 #ifdef CONFIG_I2C3_RK30
1018         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
1019 #endif
1020 #ifdef CONFIG_I2C_GPIO_RK30
1021         i2c_register_board_info(4, i2c_gpio_info, ARRAY_SIZE(i2c_gpio_info));
1022 #endif
1023 }
1024 //end of i2c
1025
1026 #define POWER_ON_PIN RK2928_PIN1_PA2   //power_hold
1027 static void rk2928_pm_power_off(void)
1028 {
1029         printk(KERN_ERR "rk2928_pm_power_off start...\n");
1030         
1031         #if defined(CONFIG_MFD_TPS65910)
1032                 tps65910_device_shutdown();//tps65910 shutdown
1033         #endif
1034         gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
1035         
1036 };
1037
1038 static void __init rk2928_board_init(void)
1039 {
1040         gpio_request(POWER_ON_PIN, "poweronpin");
1041         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
1042         gpio_free(POWER_ON_PIN);
1043         
1044         pm_power_off = rk2928_pm_power_off;
1045         
1046         rk30_i2c_register_board_info();
1047         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
1048         platform_add_devices(devices, ARRAY_SIZE(devices));
1049
1050 }
1051
1052 static void __init rk2928_reserve(void)
1053 {
1054 #ifdef CONFIG_ION
1055         rk30_ion_pdata.heaps[0].base = board_mem_reserve_add("ion", ION_RESERVE_SIZE);
1056 #endif
1057 #ifdef CONFIG_FB_ROCKCHIP
1058         resource_fb[0].start = board_mem_reserve_add("fb0", RK30_FB0_MEM_SIZE);
1059         resource_fb[0].end = resource_fb[0].start + RK30_FB0_MEM_SIZE - 1;
1060 #endif
1061 #ifdef CONFIG_VIDEO_RK29
1062         rk30_camera_request_reserve_mem();
1063 #endif
1064         board_mem_reserved();
1065 }
1066 /**
1067  * dvfs_cpu_logic_table: table for arm and logic dvfs 
1068  * @frequency   : arm frequency
1069  * @cpu_volt    : arm voltage depend on frequency
1070  * @logic_volt  : logic voltage arm requests depend on frequency
1071  * comments     : min arm/logic voltage
1072  */
1073 static struct dvfs_arm_table dvfs_cpu_logic_table[] = {
1074         {.frequency = 216 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},
1075         {.frequency = 312 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},
1076         {.frequency = 408 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},
1077         {.frequency = 504 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},
1078         {.frequency = 600 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},
1079         {.frequency = 696 * 1000,       .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
1080         {.frequency = 816 * 1000,       .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
1081         //{.frequency = 912 * 1000,     .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
1082         //{.frequency = 1008 * 1000,    .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
1083 #if 0
1084         {.frequency = 1104 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
1085         {.frequency = 1200 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
1086         {.frequency = 1104 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
1087         {.frequency = 1248 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
1088 #endif
1089         //{.frequency = 1000 * 1000,    .cpu_volt = 1225 * 1000,        .logic_volt = 1200 * 1000},
1090         {.frequency = CPUFREQ_TABLE_END},
1091 };
1092
1093 static struct cpufreq_frequency_table dvfs_gpu_table[] = {
1094         {.frequency = 266 * 1000,       .index = 1050 * 1000},
1095         {.frequency = 400 * 1000,       .index = 1275 * 1000},
1096         {.frequency = CPUFREQ_TABLE_END},
1097 };
1098
1099 static struct cpufreq_frequency_table dvfs_ddr_table[] = {
1100         {.frequency = 300 * 1000,       .index = 1050 * 1000},
1101         {.frequency = 400 * 1000,       .index = 1125 * 1000},
1102         {.frequency = CPUFREQ_TABLE_END},
1103 };
1104
1105 #define DVFS_CPU_TABLE_SIZE     (ARRAY_SIZE(dvfs_cpu_logic_table))
1106 static struct cpufreq_frequency_table cpu_dvfs_table[DVFS_CPU_TABLE_SIZE];
1107 static struct cpufreq_frequency_table dep_cpu2core_table[DVFS_CPU_TABLE_SIZE];
1108
1109 void __init board_clock_init(void)
1110 {
1111         rk2928_clock_data_init(periph_pll_default, codec_pll_default, RK30_CLOCKS_DEFAULT_FLAGS);
1112         dvfs_set_arm_logic_volt(dvfs_cpu_logic_table, cpu_dvfs_table, dep_cpu2core_table);
1113         dvfs_set_freq_volt_table(clk_get(NULL, "gpu"), dvfs_gpu_table);
1114         //dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
1115         printk("%s end\n", __func__);
1116 }
1117
1118
1119 MACHINE_START(RK2928, "RK2928board")
1120         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
1121         .fixup          = rk2928_fixup,
1122         .reserve        = &rk2928_reserve,
1123         .map_io         = rk2928_map_io,
1124         .init_irq       = rk2928_init_irq,
1125         .timer          = &rk2928_timer,
1126         .init_machine   = rk2928_board_init,
1127 MACHINE_END