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