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