rk:move pmic_type to board.h
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk2928 / board-rk2926-sdk.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/act8931.h>
49 #include <linux/regulator/rk29-pwm-regulator.h>
50 #if defined(CONFIG_HDMI_RK30)
51         #include "../../../drivers/video/rockchip/hdmi/rk_hdmi.h"
52 #endif
53
54 #if defined(CONFIG_SPIM_RK29)
55 #include "../../../drivers/spi/rk29_spim.h"
56 #endif
57
58 #include "board-rk2928-sdk-camera.c" 
59 #include "board-rk2928-sdk-key.c"
60
61 #ifdef  CONFIG_THREE_FB_BUFFER
62 #define RK30_FB0_MEM_SIZE 12*SZ_1M
63 #else
64 #define RK30_FB0_MEM_SIZE 8*SZ_1M
65 #endif
66
67 int __sramdata g_pmic_type =  0;
68
69 static struct spi_board_info board_spi_devices[] = {
70 };
71
72 /***********************************************************
73 *       rk30  backlight
74 ************************************************************/
75 #ifdef CONFIG_BACKLIGHT_RK29_BL
76 #define PWM_ID            0
77 #define PWM_MUX_NAME      GPIO0D2_PWM_0_NAME
78 #define PWM_MUX_MODE      GPIO0D_PWM_0
79 #define PWM_MUX_MODE_GPIO GPIO0D_GPIO0D2
80 #define PWM_GPIO          RK2928_PIN0_PD2
81 #define PWM_EFFECT_VALUE  0
82
83 //#define LCD_DISP_ON_PIN
84
85 #ifdef  LCD_DISP_ON_PIN
86
87 #define BL_EN_PIN         RK2928_PIN1_PB0
88 #define BL_EN_VALUE       GPIO_HIGH
89 #endif
90 static int rk29_backlight_io_init(void)
91 {
92         int ret = 0;
93         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
94 #ifdef  LCD_DISP_ON_PIN
95         // rk30_mux_api_set(BL_EN_MUX_NAME, BL_EN_MUX_MODE);
96
97         ret = gpio_request(BL_EN_PIN, NULL);
98         if (ret != 0) {
99                 gpio_free(BL_EN_PIN);
100         }
101
102         gpio_direction_output(BL_EN_PIN, 0);
103         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
104 #endif
105         return ret;
106 }
107
108 static int rk29_backlight_io_deinit(void)
109 {
110         int ret = 0;
111 #ifdef  LCD_DISP_ON_PIN
112         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
113         gpio_free(BL_EN_PIN);
114 #endif
115         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
116         return ret;
117 }
118
119 static int rk29_backlight_pwm_suspend(void)
120 {
121         int ret = 0;
122         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
123         if (gpio_request(PWM_GPIO, NULL)) {
124                 printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
125                 return -1;
126         }
127         #if defined(CONFIG_MFD_TPS65910)        
128          if (pmic_is_tps65910() )
129            gpio_direction_output(PWM_GPIO, GPIO_LOW);
130         #endif
131         #if defined(CONFIG_REGULATOR_ACT8931)
132          if (pmic_is_act8931() )
133            gpio_direction_output(PWM_GPIO, GPIO_HIGH);
134         #endif
135 #ifdef  LCD_DISP_ON_PIN
136         gpio_direction_output(BL_EN_PIN, 0);
137         gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
138 #endif
139
140         return ret;
141 }
142
143 static int rk29_backlight_pwm_resume(void)
144 {
145         gpio_free(PWM_GPIO);
146         rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE);
147 #ifdef  LCD_DISP_ON_PIN
148         msleep(30);
149         gpio_direction_output(BL_EN_PIN, 1);
150         gpio_set_value(BL_EN_PIN, BL_EN_VALUE);
151 #endif
152         return 0;
153 }
154
155 static struct rk29_bl_info rk29_bl_info = {
156         .pwm_id = PWM_ID,
157         .min_brightness = 80,
158         .bl_ref = PWM_EFFECT_VALUE,
159         .io_init = rk29_backlight_io_init,
160         .io_deinit = rk29_backlight_io_deinit,
161         .pwm_suspend = rk29_backlight_pwm_suspend,
162         .pwm_resume = rk29_backlight_pwm_resume,
163 };
164
165 static struct platform_device rk29_device_backlight = {
166         .name   = "rk29_backlight",
167         .id     = -1,
168         .dev    = {
169                 .platform_data  = &rk29_bl_info,
170         }
171 };
172
173 #endif
174
175 #ifdef CONFIG_FB_ROCKCHIP
176
177 #define LCD_MUX_NAME  GPIO0C2_UART0_RTSN_NAME
178 #define LCD_GPIO_MODE GPIO0C_GPIO0C2
179
180 #define LCD_EN        RK2928_PIN1_PB3
181 #define LCD_EN_VALUE  GPIO_LOW
182
183 static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
184 {
185         int ret = 0;
186
187         rk30_mux_api_set(LCD_MUX_NAME, LCD_GPIO_MODE);
188
189         ret = gpio_request(LCD_EN, NULL);
190         if (ret != 0)
191         {
192                 gpio_free(LCD_EN);
193                 printk(KERN_ERR "request lcd en pin fail!\n");
194                 return -1;
195         }
196         else
197         {
198                 gpio_direction_output(LCD_EN, LCD_EN_VALUE); //disable
199         }
200         return 0;
201 }
202 static int rk_fb_io_disable(void)
203 {
204
205         #if 0//defined(CONFIG_REGULATOR_ACT8931)
206         if (pmic_is_act8931() ){
207                 struct regulator *ldo;
208                 ldo = regulator_get(NULL, "act_ldo4");   //vcc_lcd
209                 regulator_disable(ldo);
210                 regulator_put(ldo);
211                 udelay(100);
212         }
213         #endif
214         gpio_set_value(LCD_EN, !LCD_EN_VALUE);
215         return 0;
216 }
217 static int rk_fb_io_enable(void)
218 {
219         #if 0//defined(CONFIG_REGULATOR_ACT8931)
220         if (pmic_is_act8931() ){
221                 struct regulator *ldo;
222                 ldo = regulator_get(NULL, "act_ldo4");   //vcc_lcd
223                 regulator_enable(ldo);
224                 regulator_put(ldo);
225                 udelay(100);
226                 msleep(300);    // wait for powering on LED circuit
227         }
228         #endif
229
230         gpio_set_value(LCD_EN, LCD_EN_VALUE);
231         return 0;
232 }
233
234 #if defined(CONFIG_LCDC_RK2928)
235 struct rk29fb_info lcdc_screen_info = {
236         .prop      = PRMRY,             //primary display device
237         .io_init   = rk_fb_io_init,
238         .io_disable = rk_fb_io_disable,
239         .io_enable = rk_fb_io_enable,
240         .set_screen_info = set_lcd_info,
241 };
242 #endif
243
244 static struct resource resource_fb[] = {
245         [0] = {
246                 .name  = "fb0 buf",
247                 .start = 0,
248                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
249                 .flags = IORESOURCE_MEM,
250         },
251         [1] = {
252                 .name  = "ipp buf",  //for rotate
253                 .start = 0,
254                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
255                 .flags = IORESOURCE_MEM,
256         },
257         [2] = {
258                 .name  = "fb2 buf",
259                 .start = 0,
260                 .end   = 0,//RK30_FB0_MEM_SIZE - 1,
261                 .flags = IORESOURCE_MEM,
262         },
263 };
264
265 static struct platform_device device_fb = {
266         .name           = "rk-fb",
267         .id             = -1,
268         .num_resources  = ARRAY_SIZE(resource_fb),
269         .resource       = resource_fb,
270 };
271 #endif
272
273 //LCDC
274 #ifdef CONFIG_LCDC_RK2928
275 static struct resource resource_lcdc[] = {
276         [0] = {
277                 .name  = "lcdc reg",
278                 .start = RK2928_LCDC_PHYS,
279                 .end   = RK2928_LCDC_PHYS + RK2928_LCDC_SIZE - 1,
280                 .flags = IORESOURCE_MEM,
281         },
282         
283         [1] = {
284                 .name  = "lcdc irq",
285                 .start = IRQ_LCDC,
286                 .end   = IRQ_LCDC,
287                 .flags = IORESOURCE_IRQ,
288         },
289 };
290
291 static struct platform_device device_lcdc = {
292         .name             = "rk2928-lcdc",
293         .id               = 0,
294         .num_resources    = ARRAY_SIZE(resource_lcdc),
295         .resource         = resource_lcdc,
296         .dev            = {
297                 .platform_data = &lcdc_screen_info,
298         },
299 };
300 #endif
301
302 #ifdef CONFIG_ION
303 #define ION_RESERVE_SIZE        (80 * SZ_1M)
304 static struct ion_platform_data rk30_ion_pdata = {
305         .nr = 1,
306         .heaps = {
307                 {
308                         .type = ION_HEAP_TYPE_CARVEOUT,
309                         .id = ION_NOR_HEAP_ID,
310                         .name = "norheap",
311                         .size = ION_RESERVE_SIZE,
312                 }
313         },
314 };
315
316 static struct platform_device device_ion = {
317         .name = "ion-rockchip",
318         .id = 0,
319         .dev = {
320                 .platform_data = &rk30_ion_pdata,
321         },
322 };
323 #endif
324
325
326 #if defined(CONFIG_TOUCHSCREEN_SITRONIX_A720)
327
328 #define TOUCH_RESET_PIN  RK2928_PIN1_PA3
329 #define TOUCH_INT_PIN    RK2928_PIN1_PB0
330 #endif
331 int ft5306_init_platform_hw(void)
332 {
333
334         //printk("ft5306_init_platform_hw\n");
335         if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
336                 gpio_free(TOUCH_RESET_PIN);
337                 printk("ft5306_init_platform_hw gpio_request error\n");
338                 return -EIO;
339         }
340
341         if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
342                 gpio_free(TOUCH_INT_PIN);
343                 printk("ift5306_init_platform_hw gpio_request error\n");
344                 return -EIO;
345         }
346         gpio_direction_output(TOUCH_RESET_PIN, GPIO_HIGH);
347         mdelay(10);
348         gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
349         mdelay(10);
350         gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
351         msleep(300);
352         return 0;
353
354 }
355
356 struct ft5x0x_platform_data sitronix_info = {
357         .model = 5007,
358         .init_platform_hw= ft5306_init_platform_hw,
359 };
360
361
362 /*MMA7660 gsensor*/
363 #if defined (CONFIG_GS_MMA7660)
364 #define MMA7660_INT_PIN   RK2928_PIN1_PB2
365
366 static int mma7660_init_platform_hw(void)
367 {
368         rk30_mux_api_set(GPIO1B2_SPI_RXD_UART1_SIN_NAME, GPIO1B_GPIO1B2);
369
370         return 0;
371 }
372
373 static struct sensor_platform_data mma7660_info = {
374         .type = SENSOR_TYPE_ACCEL,
375         .irq_enable = 1,
376         .poll_delay_ms = 30,
377         .init_platform_hw = mma7660_init_platform_hw,
378         .orientation = {-1, 0, 0, 0, 0, -1, 0, 1, 0},
379 };
380 #endif
381
382
383 #if CONFIG_RK30_PWM_REGULATOR
384 static int pwm_voltage_map[] = {
385         1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000, 1375000, 1400000
386 };
387
388 static struct regulator_consumer_supply pwm_dcdc1_consumers[] = {
389         {
390                 .supply = "vdd_core",
391         }
392 };
393
394 struct regulator_init_data pwm_regulator_init_dcdc[1] =
395 {
396         {
397                 .constraints = {
398                         .name = "PWM_DCDC1",
399                         .min_uV = 600000,
400                         .max_uV = 1800000,      //0.6-1.8V
401                         .apply_uV = true,
402                         .valid_ops_mask = REGULATOR_CHANGE_STATUS | REGULATOR_CHANGE_VOLTAGE,
403                 },
404                 .num_consumer_supplies = ARRAY_SIZE(pwm_dcdc1_consumers),
405                 .consumer_supplies = pwm_dcdc1_consumers,
406         },
407 };
408
409 static struct pwm_platform_data pwm_regulator_info[1] = {
410         {
411                 .pwm_id = 1,
412                 .pwm_gpio = RK2928_PIN0_PD3,
413                 .pwm_iomux_name = GPIO0D3_PWM_1_NAME,
414                 .pwm_iomux_pwm = GPIO0D_PWM_1, 
415                 .pwm_iomux_gpio = GPIO0D_GPIO0D3,
416                 .pwm_voltage = 1200000,
417                 .suspend_voltage = 1050000,
418                 .min_uV = 1000000,
419                 .max_uV = 1400000,
420                 .coefficient = 455,     //45.5%
421                 .pwm_voltage_map = pwm_voltage_map,
422                 .init_data      = &pwm_regulator_init_dcdc[0],
423         },
424 };
425
426 struct platform_device pwm_regulator_device[1] = {
427         {
428                 .name = "pwm-voltage-regulator",
429                 .id = 0,
430                 .dev            = {
431                         .platform_data = &pwm_regulator_info[0],
432                 }
433         },
434 };
435 #endif
436
437 /***********************************************************
438 *       usb wifi
439 ************************************************************/
440 #if defined(CONFIG_RTL8192CU) || defined(CONFIG_RTL8188EU) 
441
442 static void rkusb_wifi_power(int on) {
443         struct regulator *ldo = NULL;
444         
445 #if defined(CONFIG_MFD_TPS65910)        
446         if (pmic_is_tps65910() )
447                 ldo = regulator_get(NULL, "vmmc");  //vccio_wl
448 #endif
449 #if defined(CONFIG_REGULATOR_ACT8931)
450         if(pmic_is_act8931() )
451                 ldo = regulator_get(NULL, "act_ldo4");  //vccio_wl
452 #endif  
453         
454         if(on) {
455                 regulator_enable(ldo);
456                 printk("%s: vccio_wl enable\n", __func__);
457         } else {
458                 printk("%s: vccio_wl disable\n", __func__);
459                 regulator_disable(ldo);
460         }
461         
462         regulator_put(ldo);
463         udelay(100);
464 }
465
466 #endif
467
468 /**************************************************************************************************
469  * SDMMC devices,  include the module of SD,MMC,and sdio.noted by xbw at 2012-03-05
470 **************************************************************************************************/
471 #ifdef CONFIG_SDMMC_RK29
472 #include "board-rk2928-sdk-sdmmc.c"
473
474 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
475 #define SDMMC0_WRITE_PROTECT_PIN        RK2928_PIN1_PA7 //According to your own project to set the value of write-protect-pin.
476 #endif
477
478 #if defined(CONFIG_SDMMC1_RK29_WRITE_PROTECT)
479 #define SDMMC1_WRITE_PROTECT_PIN        RK2928_PIN0_PD5 //According to your own project to set the value of write-protect-pin.
480 #endif
481
482 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N    RK2928_PIN0_PB2
483
484 #define RK29SDK_SD_CARD_DETECT_N        RK2928_PIN2_PA7  //According to your own project to set the value of card-detect-pin.
485 #define RK29SDK_SD_CARD_INSERT_LEVEL    GPIO_LOW         // set the voltage of insert-card. Please pay attention to the default setting.
486
487
488 #endif //endif ---#ifdef CONFIG_SDMMC_RK29
489
490 #ifdef CONFIG_SDMMC0_RK29
491 static int rk29_sdmmc0_cfg_gpio(void)
492 {
493         rk29_sdmmc_set_iomux(0, 0xFFFF);
494
495 #if defined(CONFIG_SDMMC0_RK29_SDCARD_DET_FROM_GPIO)
496     rk30_mux_api_set(GPIO1C1_MMC0_DETN_NAME, GPIO1C_GPIO1C1);
497    // gpio_request(RK29SDK_SD_CARD_DETECT_N, "sd-detect");
498    // gpio_direction_output(RK29SDK_SD_CARD_DETECT_N,GPIO_HIGH);//set mmc0-data1 to high.
499 #else
500         rk30_mux_api_set(GPIO1C1_MMC0_DETN_NAME, GPIO1C_MMC0_DETN);
501 #endif  
502
503 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
504         gpio_request(SDMMC0_WRITE_PROTECT_PIN, "sdmmc-wp");
505         gpio_direction_input(SDMMC0_WRITE_PROTECT_PIN);
506 #endif
507
508         return 0;
509 }
510
511 #define CONFIG_SDMMC0_USE_DMA
512 struct rk29_sdmmc_platform_data default_sdmmc0_data = {
513         .host_ocr_avail =
514             (MMC_VDD_25_26 | MMC_VDD_26_27 | MMC_VDD_27_28 | MMC_VDD_28_29 |
515              MMC_VDD_29_30 | MMC_VDD_30_31 | MMC_VDD_31_32 | MMC_VDD_32_33 |
516              MMC_VDD_33_34 | MMC_VDD_34_35 | MMC_VDD_35_36),
517         .host_caps =
518             (MMC_CAP_4_BIT_DATA | MMC_CAP_MMC_HIGHSPEED | MMC_CAP_SD_HIGHSPEED),
519         .io_init = rk29_sdmmc0_cfg_gpio,
520
521 #if !defined(CONFIG_SDMMC_RK29_OLD)
522         .set_iomux = rk29_sdmmc_set_iomux,
523 #endif
524
525         .dma_name = "sd_mmc",
526 #ifdef CONFIG_SDMMC0_USE_DMA
527         .use_dma = 1,
528 #else
529         .use_dma = 0,
530 #endif
531
532 #if defined(CONFIG_SDMMC0_RK29_SDCARD_DET_FROM_GPIO)
533     .detect_irq = RK29SDK_SD_CARD_DETECT_N,
534     .insert_card_level = RK29SDK_SD_CARD_INSERT_LEVEL,
535 #else
536         .detect_irq = INVALID_GPIO,
537 #endif
538
539         .enable_sd_wakeup = 0,
540
541 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
542         .write_prt = SDMMC0_WRITE_PROTECT_PIN,
543 #else
544         .write_prt = INVALID_GPIO,
545 #endif
546 };
547 #endif // CONFIG_SDMMC0_RK29
548
549 #ifdef CONFIG_SND_SOC_RK2928
550 static struct resource resources_acodec[] = {
551         {
552                 .start  = RK2928_ACODEC_PHYS,
553                 .end    = RK2928_ACODEC_PHYS + RK2928_ACODEC_SIZE - 1,
554                 .flags  = IORESOURCE_MEM,
555         },
556         {
557                 .start  = RK2928_PIN1_PA0,
558                 .end    = RK2928_PIN1_PA0,
559                 .flags  = IORESOURCE_IO,
560         },
561 };
562
563 static struct platform_device device_acodec = {
564         .name   = "rk2928-codec",
565         .id             = -1,
566         .num_resources  = ARRAY_SIZE(resources_acodec),
567         .resource       = resources_acodec,
568 };
569 #endif
570
571 #ifdef CONFIG_BATTERY_RK30_ADC_FAC
572 static struct rk30_adc_battery_platform_data rk30_adc_battery_platdata = {
573         .dc_det_pin      = INVALID_GPIO,
574         .batt_low_pin    = INVALID_GPIO,
575         .charge_set_pin  = INVALID_GPIO,
576         .charge_ok_pin   = INVALID_GPIO,
577 };
578
579 static struct platform_device rk30_device_adc_battery = {
580         .name   = "rk30-battery",
581         .id     = -1,
582         .dev = {
583                 .platform_data = &rk30_adc_battery_platdata,
584         },
585 };
586 #endif
587
588 static struct platform_device *devices[] __initdata = {
589 #ifdef CONFIG_FB_ROCKCHIP
590         &device_fb,
591 #endif
592 #ifdef CONFIG_LCDC_RK2928
593         &device_lcdc,
594 #endif
595 #ifdef CONFIG_BACKLIGHT_RK29_BL
596         &rk29_device_backlight,
597 #endif
598 #ifdef CONFIG_ION
599         &device_ion,
600 #endif
601 #ifdef CONFIG_SND_SOC_RK2928
602         &device_acodec,
603 #endif
604 #ifdef CONFIG_BATTERY_RK30_ADC_FAC
605         &rk30_device_adc_battery,
606 #endif
607 };
608 //i2c
609 #ifdef CONFIG_I2C0_RK30
610 #ifdef CONFIG_MFD_TPS65910
611 #define TPS65910_HOST_IRQ        RK2928_PIN1_PB2
612 #include "board-rk2928-sdk-tps65910.c"
613 #endif
614 #ifdef CONFIG_REGULATOR_ACT8931
615 #define ACT8931_HOST_IRQ                RK2928_PIN1_PB1
616 #include "board-rk2928-sdk-act8931.c"
617 #endif
618
619 static struct i2c_board_info __initdata i2c0_info[] = {
620 #if defined (CONFIG_MFD_TPS65910)
621         {
622         .type           = "tps65910",
623         .addr           = TPS65910_I2C_ID0,
624         .flags          = 0,
625         .irq            = TPS65910_HOST_IRQ,
626         .platform_data = &tps65910_data,
627         },
628 #endif
629 #if defined (CONFIG_REGULATOR_ACT8931)
630         {
631                 .type                   = "act8931",
632                 .addr           = 0x5b, 
633                 .flags                  = 0,
634                 .irq            = ACT8931_HOST_IRQ,
635                 .platform_data=&act8931_data,
636         },
637 #endif
638 #if defined (CONFIG_RTC_HYM8563)
639         {
640                 .type                   = "rtc_hym8563",
641                 .addr           = 0x51,
642                 .flags                  = 0,
643                 .irq            = RK2928_PIN1_PA5,
644         },
645 #endif
646 };
647 #endif
648
649 int __sramdata gpio0d3_iomux,gpio0d3_do,gpio0d3_dir;
650
651 #define gpio0_readl(offset)     readl_relaxed(RK2928_GPIO0_BASE + offset)
652 #define gpio0_writel(v, offset) do { writel_relaxed(v, RK2928_GPIO0_BASE + offset); dsb(); } while (0)
653
654 void __sramfunc rk30_pwm_logic_suspend_voltage(void)
655 {
656 #ifdef CONFIG_RK30_PWM_REGULATOR
657
658         sram_udelay(10000);
659         gpio0d3_iomux = readl_relaxed(GRF_GPIO0D_IOMUX);
660         gpio0d3_do = gpio0_readl(GPIO_SWPORTA_DR);
661         gpio0d3_dir = gpio0_readl(GPIO_SWPORTA_DDR);
662
663         writel_relaxed((gpio0d3_iomux |(1<<22)) & (~(1<<6)), GRF_GPIO0D_IOMUX);
664         gpio0_writel(gpio0d3_dir |(1<<27), GPIO_SWPORTA_DDR);
665         gpio0_writel(gpio0d3_do |(1<<27), GPIO_SWPORTA_DR);
666 #endif 
667 }
668 void __sramfunc rk30_pwm_logic_resume_voltage(void)
669 {
670 #ifdef CONFIG_RK30_PWM_REGULATOR
671         writel_relaxed((1<<22)|gpio0d3_iomux, GRF_GPIO0D_IOMUX);
672         gpio0_writel(gpio0d3_dir, GPIO_SWPORTA_DDR);
673         gpio0_writel(gpio0d3_do, GPIO_SWPORTA_DR);
674         sram_udelay(10000);
675
676 #endif
677
678 }
679 extern void pwm_suspend_voltage(void);
680 extern void pwm_resume_voltage(void);
681 void  rk30_pwm_suspend_voltage_set(void)
682 {
683 #ifdef CONFIG_RK30_PWM_REGULATOR
684         pwm_suspend_voltage();
685 #endif
686 }
687 void  rk30_pwm_resume_voltage_set(void)
688 {
689 #ifdef CONFIG_RK30_PWM_REGULATOR
690         pwm_resume_voltage();
691 #endif
692 }
693
694 void __sramfunc board_pmu_suspend(void)
695 {      
696         #if defined (CONFIG_MFD_TPS65910)
697         if(pmic_is_tps65910() )
698         board_pmu_tps65910_suspend(); 
699         #endif   
700 }
701 void __sramfunc board_pmu_resume(void)
702 {      
703         #if defined (CONFIG_MFD_TPS65910)
704         if(pmic_is_tps65910() )
705         board_pmu_tps65910_resume(); 
706         #endif
707 }
708
709 #ifdef CONFIG_I2C1_RK30
710 static struct i2c_board_info __initdata i2c1_info[] = {
711 #if defined (CONFIG_GS_MMA7660)
712                 {
713                         .type           = "gs_mma7660",
714                         .addr           = 0x4c,
715                         .flags          = 0,
716                         .irq            = MMA7660_INT_PIN,
717                         .platform_data = &mma7660_info,
718                 },
719 #endif
720
721 };
722 #endif
723 #ifdef CONFIG_I2C2_RK30
724 static struct i2c_board_info __initdata i2c2_info[] = {
725 #if defined (CONFIG_TOUCHSCREEN_SITRONIX_A720)
726 {
727         .type           ="sitronix",
728         .addr           = 0x60,
729         .flags          = 0,
730         .irq            = TOUCH_INT_PIN,
731         .platform_data = &sitronix_info,
732 },
733 #endif
734 };
735 #endif
736 #ifdef CONFIG_I2C3_RK30
737 static struct i2c_board_info __initdata i2c3_info[] = {
738 };
739 #endif
740 #ifdef CONFIG_I2C_GPIO_RK30
741 #define I2C_SDA_PIN     INVALID_GPIO   //set sda_pin here
742 #define I2C_SCL_PIN     INVALID_GPIO   //set scl_pin here
743 static int rk30_i2c_io_init(void)
744 {
745         //set iomux (gpio) here
746
747         return 0;
748 }
749 struct i2c_gpio_platform_data default_i2c_gpio_data = {
750        .sda_pin = I2C_SDA_PIN,
751        .scl_pin = I2C_SCL_PIN,
752        .udelay = 5, // clk = 500/udelay = 100Khz
753        .timeout = 100,//msecs_to_jiffies(100),
754        .bus_num    = 5,
755        .io_init = rk30_i2c_io_init,
756 };
757 static struct i2c_board_info __initdata i2c_gpio_info[] = {
758 };
759 #endif
760 static void __init rk30_i2c_register_board_info(void)
761 {
762 #ifdef CONFIG_I2C0_RK30
763         i2c_register_board_info(0, i2c0_info, ARRAY_SIZE(i2c0_info));
764 #endif
765 #ifdef CONFIG_I2C1_RK30
766         i2c_register_board_info(1, i2c1_info, ARRAY_SIZE(i2c1_info));
767 #endif
768 #ifdef CONFIG_I2C2_RK30
769         i2c_register_board_info(2, i2c2_info, ARRAY_SIZE(i2c2_info));
770 #endif
771 #ifdef CONFIG_I2C3_RK30
772         i2c_register_board_info(3, i2c3_info, ARRAY_SIZE(i2c3_info));
773 #endif
774 #ifdef CONFIG_I2C_GPIO_RK30
775         i2c_register_board_info(4, i2c_gpio_info, ARRAY_SIZE(i2c_gpio_info));
776 #endif
777 }
778 //end of i2c
779
780 #define POWER_ON_PIN RK2928_PIN1_PA2   //power_hold
781 #if defined(CONFIG_REGULATOR_ACT8931)
782 extern  int act8931_charge_det ;
783 #endif
784 static void rk2928_pm_power_off(void)
785 {
786         printk(KERN_ERR "rk2928_pm_power_off start...\n");
787         
788         #if defined(CONFIG_REGULATOR_ACT8931)
789          if (pmic_is_act8931() ){
790               if(act8931_charge_det)
791                    arm_pm_restart(0, NULL);
792          }
793         #endif
794         
795         #if defined(CONFIG_MFD_TPS65910)        
796          if(pmic_is_tps65910() )
797                 tps65910_device_shutdown();//tps65910 shutdown
798         #endif
799         gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
800         
801 };
802
803 static void __init rk2928_board_init(void)
804 {
805         gpio_request(POWER_ON_PIN, "poweronpin");
806         gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
807  
808         pm_power_off = rk2928_pm_power_off;
809         
810         rk30_i2c_register_board_info();
811         spi_register_board_info(board_spi_devices, ARRAY_SIZE(board_spi_devices));
812         platform_add_devices(devices, ARRAY_SIZE(devices));
813
814 }
815
816 static void __init rk2928_reserve(void)
817 {
818 #ifdef CONFIG_ION
819         rk30_ion_pdata.heaps[0].base = board_mem_reserve_add("ion", ION_RESERVE_SIZE);
820 #endif
821 #ifdef CONFIG_FB_ROCKCHIP
822         resource_fb[0].start = board_mem_reserve_add("fb0", RK30_FB0_MEM_SIZE);
823         resource_fb[0].end = resource_fb[0].start + RK30_FB0_MEM_SIZE - 1;
824 #endif
825 #ifdef CONFIG_VIDEO_RK29
826         rk30_camera_request_reserve_mem();
827 #endif
828         board_mem_reserved();
829 }
830 /**
831  * dvfs_cpu_logic_table: table for arm and logic dvfs 
832  * @frequency   : arm frequency
833  * @cpu_volt    : arm voltage depend on frequency
834  * @logic_volt  : logic voltage arm requests depend on frequency
835  * comments     : min arm/logic voltage
836  */
837 static struct dvfs_arm_table dvfs_cpu_logic_table[] = {
838         {.frequency = 216 * 1000,       .cpu_volt =  850 * 1000,        .logic_volt = 1200 * 1000},
839         {.frequency = 312 * 1000,       .cpu_volt =  900 * 1000,        .logic_volt = 1200 * 1000},
840         {.frequency = 408 * 1000,       .cpu_volt =  950 * 1000,        .logic_volt = 1200 * 1000},
841         {.frequency = 504 * 1000,       .cpu_volt = 1000 * 1000,        .logic_volt = 1200 * 1000},
842         {.frequency = 600 * 1000,       .cpu_volt = 1100 * 1000,        .logic_volt = 1200 * 1000},
843         {.frequency = 696 * 1000,       .cpu_volt = 1175 * 1000,        .logic_volt = 1200 * 1000},
844         {.frequency = 816 * 1000,       .cpu_volt = 1250 * 1000,        .logic_volt = 1200 * 1000},
845         {.frequency = 912 * 1000,       .cpu_volt = 1350 * 1000,        .logic_volt = 1200 * 1000},
846         {.frequency = 1008 * 1000,      .cpu_volt = 1450 * 1000,        .logic_volt = 1200 * 1000},
847 #if 0
848         {.frequency = 1104 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
849         {.frequency = 1200 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
850         {.frequency = 1104 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
851         {.frequency = 1248 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
852 #endif
853         {.frequency = CPUFREQ_TABLE_END},
854 };
855
856 static struct cpufreq_frequency_table dvfs_gpu_table[] = {
857         {.frequency = 266 * 1000,       .index = 1050 * 1000},
858         {.frequency = 400 * 1000,       .index = 1275 * 1000},
859         {.frequency = CPUFREQ_TABLE_END},
860 };
861
862 static struct cpufreq_frequency_table dvfs_ddr_table[] = {
863         {.frequency = 300 * 1000,       .index = 1050 * 1000},
864         {.frequency = 400 * 1000,       .index = 1125 * 1000},
865         {.frequency = CPUFREQ_TABLE_END},
866 };
867
868 #define DVFS_CPU_TABLE_SIZE     (ARRAY_SIZE(dvfs_cpu_logic_table))
869 static struct cpufreq_frequency_table cpu_dvfs_table[DVFS_CPU_TABLE_SIZE];
870 static struct cpufreq_frequency_table dep_cpu2core_table[DVFS_CPU_TABLE_SIZE];
871
872 void __init board_clock_init(void)
873 {
874         rk2928_clock_data_init(periph_pll_default, codec_pll_default, RK30_CLOCKS_DEFAULT_FLAGS);
875         dvfs_set_arm_logic_volt(dvfs_cpu_logic_table, cpu_dvfs_table, dep_cpu2core_table);
876         dvfs_set_freq_volt_table(clk_get(NULL, "gpu"), dvfs_gpu_table);
877         //dvfs_set_freq_volt_table(clk_get(NULL, "ddr"), dvfs_ddr_table);
878         printk("%s end\n", __func__);
879 }
880
881
882 MACHINE_START(RK2928, "RK2928board")
883         .boot_params    = PLAT_PHYS_OFFSET + 0x800,
884         .fixup          = rk2928_fixup,
885         .reserve        = &rk2928_reserve,
886         .map_io         = rk2928_map_io,
887         .init_irq       = rk2928_init_irq,
888         .timer          = &rk2928_timer,
889         .init_machine   = rk2928_board_init,
890 MACHINE_END