rk:move pmic_type to board.h
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk2928 / board-rk2928-a720.c
index c5f0284fab63d95a9b57f221e579e442a3b82309..41803c13fdababcc575ad25d5a8e0123765e0dbf 100755 (executable)
@@ -45,6 +45,7 @@
 #include <linux/rfkill-rk.h>
 #include <linux/sensor-dev.h>
 #include <linux/mfd/tps65910.h>
+#include <linux/regulator/act8931.h>
 #include <linux/regulator/rk29-pwm-regulator.h>
 #if defined(CONFIG_HDMI_RK30)
        #include "../../../drivers/video/rockchip/hdmi/rk_hdmi.h"
@@ -63,6 +64,8 @@
 #define RK30_FB0_MEM_SIZE 8*SZ_1M
 #endif
 
+int __sramdata g_pmic_type =  0;
+
 static struct spi_board_info board_spi_devices[] = {
 };
 
@@ -77,7 +80,11 @@ static struct spi_board_info board_spi_devices[] = {
 #define PWM_GPIO         RK2928_PIN0_PD2
 #define PWM_EFFECT_VALUE  0
 
+#if defined(CONFIG_MACH_RK2926_M713)
+//#define LCD_DISP_ON_PIN
+#else
 #define LCD_DISP_ON_PIN
+#endif
 
 #ifdef  LCD_DISP_ON_PIN
 
@@ -121,7 +128,18 @@ static int rk29_backlight_pwm_suspend(void)
                printk("func %s, line %d: request gpio fail\n", __FUNCTION__, __LINE__);
                return -1;
        }
-       gpio_direction_output(PWM_GPIO, GPIO_LOW);
+       #if defined(CONFIG_MFD_TPS65910)        
+       if(pmic_is_tps65910())
+       {
+               gpio_direction_output(PWM_GPIO, GPIO_LOW);
+       }
+       #endif
+       #if defined(CONFIG_REGULATOR_ACT8931)
+       if(pmic_is_act8931())
+       {
+               gpio_direction_output(PWM_GPIO, GPIO_HIGH);
+       }
+       #endif
 #ifdef  LCD_DISP_ON_PIN
        gpio_direction_output(BL_EN_PIN, 0);
        gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
@@ -167,7 +185,11 @@ static struct platform_device rk29_device_backlight = {
 #define LCD_MUX_NAME  GPIO0C2_UART0_RTSN_NAME
 #define LCD_GPIO_MODE GPIO0C_GPIO0C2
 
+#ifdef CONFIG_MACH_RK2926_M713
+#define LCD_EN        RK2928_PIN1_PB3
+#else
 #define LCD_EN        RK2928_PIN0_PC2
+#endif
 #define LCD_EN_VALUE  GPIO_LOW
 
 static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
@@ -191,11 +213,34 @@ static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
 }
 static int rk_fb_io_disable(void)
 {
+
+       #if 0//defined(CONFIG_REGULATOR_ACT8931)
+       if(pmic_is_act8931())
+       {
+               struct regulator *ldo;
+               ldo = regulator_get(NULL, "act_ldo4");   //vcc_lcd
+               regulator_disable(ldo);
+               regulator_put(ldo);
+               udelay(100);
+       }
+       #endif
         gpio_set_value(LCD_EN, !LCD_EN_VALUE);
        return 0;
 }
 static int rk_fb_io_enable(void)
 {
+       #if 0//defined(CONFIG_REGULATOR_ACT8931)
+       if(pmic_is_act8931())
+       {
+               struct regulator *ldo;
+               ldo = regulator_get(NULL, "act_ldo4");   //vcc_lcd
+               regulator_enable(ldo);
+               regulator_put(ldo);
+               udelay(100);
+               msleep(300);    // wait for powering on LED circuit
+       }
+       #endif
+
         gpio_set_value(LCD_EN, LCD_EN_VALUE);
        return 0;
 }
@@ -295,7 +340,11 @@ static struct platform_device device_ion = {
 #if defined(CONFIG_TOUCHSCREEN_SITRONIX_A720)
 
 #define TOUCH_RESET_PIN         RK2928_PIN1_PA3
+#ifdef CONFIG_MACH_RK2926_M713
+#define TOUCH_INT_PIN   RK2928_PIN1_PB0
+#else
 #define TOUCH_INT_PIN   RK2928_PIN1_PB3
+#endif
 int ft5306_init_platform_hw(void)
 {
 
@@ -331,11 +380,19 @@ struct ft5x0x_platform_data sitronix_info = {
 
 /*MMA7660 gsensor*/
 #if defined (CONFIG_GS_MMA7660)
+#ifdef CONFIG_MACH_RK2926_M713
+#define MMA7660_INT_PIN   RK2928_PIN1_PB2
+#else
 #define MMA7660_INT_PIN   RK2928_PIN1_PB1
+#endif
 
 static int mma7660_init_platform_hw(void)
 {
+#ifdef CONFIG_MACH_RK2926_M713
+       rk30_mux_api_set(GPIO1B2_SPI_RXD_UART1_SIN_NAME, GPIO1B_GPIO1B2);
+#else
        rk30_mux_api_set(GPIO1B1_SPI_TXD_UART1_SOUT_NAME, GPIO1B_GPIO1B1);
+#endif
 
        return 0;
 }
@@ -351,7 +408,7 @@ static struct sensor_platform_data mma7660_info = {
 
 
 #if CONFIG_RK30_PWM_REGULATOR
-const static int pwm_voltage_map[] = {
+static int pwm_voltage_map[] = {
        1000000, 1025000, 1050000, 1075000, 1100000, 1125000, 1150000, 1175000, 1200000, 1225000, 1250000, 1275000, 1300000, 1325000, 1350000, 1375000, 1400000
 };
 
@@ -378,11 +435,19 @@ struct regulator_init_data pwm_regulator_init_dcdc[1] =
 
 static struct pwm_platform_data pwm_regulator_info[1] = {
        {
+#ifdef CONFIG_MACH_RK2926_M713
+               .pwm_id = 1,
+               .pwm_gpio = RK2928_PIN0_PD3,
+               .pwm_iomux_name = GPIO0D3_PWM_1_NAME,
+               .pwm_iomux_pwm = GPIO0D_PWM_1, 
+               .pwm_iomux_gpio = GPIO0D_GPIO0D3,
+#else
                .pwm_id = 2,
                .pwm_gpio = RK2928_PIN0_PD4,
                .pwm_iomux_name = GPIO0D4_PWM_2_NAME,
                .pwm_iomux_pwm = GPIO0D_PWM_2, 
                .pwm_iomux_gpio = GPIO0D_GPIO0D4,
+#endif
                .pwm_voltage = 1200000,
                .suspend_voltage = 1050000,
                .min_uV = 1000000,
@@ -403,6 +468,40 @@ struct platform_device pwm_regulator_device[1] = {
        },
 };
 #endif
+
+/***********************************************************
+*      usb wifi
+************************************************************/
+#if defined(CONFIG_RTL8192CU) || defined(CONFIG_RTL8188EU) 
+
+static void rkusb_wifi_power(int on) {
+       struct regulator *ldo = NULL;
+       
+#if defined(CONFIG_MFD_TPS65910)       
+       if(pmic_is_tps65910()) {
+               ldo = regulator_get(NULL, "vmmc");  //vccio_wl
+       }
+#endif
+#if defined(CONFIG_REGULATOR_ACT8931)
+       if(pmic_is_act8931()) {
+               ldo = regulator_get(NULL, "act_ldo4");  //vccio_wl
+       }
+#endif 
+       
+       if(on) {
+               regulator_enable(ldo);
+               printk("%s: vccio_wl enable\n", __func__);
+       } else {
+               printk("%s: vccio_wl disable\n", __func__);
+               regulator_disable(ldo);
+       }
+       
+       regulator_put(ldo);
+       udelay(100);
+}
+
+#endif
+
 /**************************************************************************************************
  * SDMMC devices,  include the module of SD,MMC,and sdio.noted by xbw at 2012-03-05
 **************************************************************************************************/
@@ -419,6 +518,10 @@ struct platform_device pwm_regulator_device[1] = {
 
 #define RK29SDK_WIFI_SDIO_CARD_DETECT_N    RK2928_PIN0_PB2
 
+#define RK29SDK_SD_CARD_DETECT_N        RK2928_PIN2_PA7  //According to your own project to set the value of card-detect-pin.
+#define RK29SDK_SD_CARD_INSERT_LEVEL    GPIO_LOW         // set the voltage of insert-card. Please pay attention to the default setting.
+
+
 #endif //endif ---#ifdef CONFIG_SDMMC_RK29
 
 #ifdef CONFIG_SDMMC0_RK29
@@ -426,7 +529,13 @@ static int rk29_sdmmc0_cfg_gpio(void)
 {
        rk29_sdmmc_set_iomux(0, 0xFFFF);
 
+#if defined(CONFIG_SDMMC0_RK29_SDCARD_DET_FROM_GPIO)
+    rk30_mux_api_set(GPIO1C1_MMC0_DETN_NAME, GPIO1C_GPIO1C1);
+   // gpio_request(RK29SDK_SD_CARD_DETECT_N, "sd-detect");
+   // gpio_direction_output(RK29SDK_SD_CARD_DETECT_N,GPIO_HIGH);//set mmc0-data1 to high.
+#else
        rk30_mux_api_set(GPIO1C1_MMC0_DETN_NAME, GPIO1C_MMC0_DETN);
+#endif 
 
 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
        gpio_request(SDMMC0_WRITE_PROTECT_PIN, "sdmmc-wp");
@@ -456,7 +565,14 @@ struct rk29_sdmmc_platform_data default_sdmmc0_data = {
 #else
        .use_dma = 0,
 #endif
-       .detect_irq = RK2928_PIN1_PC1,  // INVALID_GPIO
+
+#if defined(CONFIG_SDMMC0_RK29_SDCARD_DET_FROM_GPIO)
+    .detect_irq = RK29SDK_SD_CARD_DETECT_N,
+    .insert_card_level = RK29SDK_SD_CARD_INSERT_LEVEL,
+#else
+       .detect_irq = INVALID_GPIO,
+#endif
+
        .enable_sd_wakeup = 0,
 
 #if defined(CONFIG_SDMMC0_RK29_WRITE_PROTECT)
@@ -489,6 +605,23 @@ static struct platform_device device_acodec = {
 };
 #endif
 
+#ifdef CONFIG_BATTERY_RK30_ADC_FAC
+static struct rk30_adc_battery_platform_data rk30_adc_battery_platdata = {
+        .dc_det_pin      = INVALID_GPIO,
+        .batt_low_pin    = INVALID_GPIO,
+        .charge_set_pin  = INVALID_GPIO,
+        .charge_ok_pin   = INVALID_GPIO,
+};
+
+static struct platform_device rk30_device_adc_battery = {
+        .name   = "rk30-battery",
+        .id     = -1,
+        .dev = {
+                .platform_data = &rk30_adc_battery_platdata,
+        },
+};
+#endif
+
 static struct platform_device *devices[] __initdata = {
 #ifdef CONFIG_FB_ROCKCHIP
        &device_fb,
@@ -505,6 +638,9 @@ static struct platform_device *devices[] __initdata = {
 #ifdef CONFIG_SND_SOC_RK2928
        &device_acodec,
 #endif
+#ifdef CONFIG_BATTERY_RK30_ADC_FAC
+       &rk30_device_adc_battery,
+#endif
 };
 //i2c
 #ifdef CONFIG_I2C0_RK30
@@ -513,6 +649,11 @@ static struct platform_device *devices[] __initdata = {
 #include "board-rk2928-a720-tps65910.c"
 #endif
 #ifdef CONFIG_REGULATOR_ACT8931
+#ifdef CONFIG_MACH_RK2926_M713
+#define ACT8931_HOST_IRQ               RK2928_PIN1_PB1
+#else
+#define ACT8931_HOST_IRQ               RK2928_PIN1_PB2
+#endif
 #include "board-rk2928-sdk-act8931.c"
 #endif
 
@@ -531,41 +672,73 @@ static struct i2c_board_info __initdata i2c0_info[] = {
                .type                   = "act8931",
                .addr           = 0x5b, 
                .flags                  = 0,
+               .irq            = ACT8931_HOST_IRQ,
                .platform_data=&act8931_data,
        },
 #endif
-
+#ifdef CONFIG_MACH_RK2926_M713
+#if defined (CONFIG_RTC_HYM8563)
+       {
+               .type                   = "rtc_hym8563",
+               .addr           = 0x51,
+               .flags                  = 0,
+               .irq            = RK2928_PIN1_PA5,
+       },
+#endif
+#endif
 };
 #endif
 
+#ifdef CONFIG_MACH_RK2926_M713
+int __sramdata gpio0d3_iomux,gpio0d3_do,gpio0d3_dir;
+#else
 int __sramdata gpio0d4_iomux,gpio0d4_do,gpio0d4_dir;
+#endif
 
-#define gpio_readl(offset)     readl_relaxed(RK2928_GPIO0_BASE + offset)
-#define gpio_writel(v, offset) do { writel_relaxed(v, RK2928_GPIO0_BASE + offset); dsb(); } while (0)
+#define gpio0_readl(offset)    readl_relaxed(RK2928_GPIO0_BASE + offset)
+#define gpio0_writel(v, offset)        do { writel_relaxed(v, RK2928_GPIO0_BASE + offset); dsb(); } while (0)
 
 void __sramfunc rk30_pwm_logic_suspend_voltage(void)
 {
 #ifdef CONFIG_RK30_PWM_REGULATOR
 
+#ifdef CONFIG_MACH_RK2926_M713
+       sram_udelay(10000);
+       gpio0d3_iomux = readl_relaxed(GRF_GPIO0D_IOMUX);
+       gpio0d3_do = gpio0_readl(GPIO_SWPORTA_DR);
+       gpio0d3_dir = gpio0_readl(GPIO_SWPORTA_DDR);
+
+       writel_relaxed((gpio0d3_iomux |(1<<22)) & (~(1<<6)), GRF_GPIO0D_IOMUX);
+       gpio0_writel(gpio0d3_dir |(1<<27), GPIO_SWPORTA_DDR);
+       gpio0_writel(gpio0d3_do |(1<<27), GPIO_SWPORTA_DR);
+#else
 //     int gpio0d7_iomux,gpio0d7_do,gpio0d7_dir,gpio0d7_en;
        sram_udelay(10000);
        gpio0d4_iomux = readl_relaxed(GRF_GPIO0D_IOMUX);
-       gpio0d4_do = gpio_readl(GPIO_SWPORTA_DR);
-       gpio0d4_dir = gpio_readl(GPIO_SWPORTA_DDR);
+       gpio0d4_do = gpio0_readl(GPIO_SWPORTA_DR);
+       gpio0d4_dir = gpio0_readl(GPIO_SWPORTA_DDR);
 
        writel_relaxed((gpio0d4_iomux |(1<<24)) & (~(1<<8)), GRF_GPIO0D_IOMUX);
-       gpio_writel(gpio0d4_dir |(1<<28), GPIO_SWPORTA_DDR);
-       gpio_writel(gpio0d4_do |(1<<28), GPIO_SWPORTA_DR);
+       gpio0_writel(gpio0d4_dir |(1<<28), GPIO_SWPORTA_DDR);
+       gpio0_writel(gpio0d4_do |(1<<28), GPIO_SWPORTA_DR);
+#endif
        
 #endif 
 }
 void __sramfunc rk30_pwm_logic_resume_voltage(void)
 {
 #ifdef CONFIG_RK30_PWM_REGULATOR
+#ifdef CONFIG_MACH_RK2926_M713
+       writel_relaxed((1<<22)|gpio0d3_iomux, GRF_GPIO0D_IOMUX);
+       gpio0_writel(gpio0d3_dir, GPIO_SWPORTA_DDR);
+       gpio0_writel(gpio0d3_do, GPIO_SWPORTA_DR);
+       sram_udelay(10000);
+#else
        writel_relaxed((1<<24)|gpio0d4_iomux, GRF_GPIO0D_IOMUX);
-       gpio_writel(gpio0d4_dir, GPIO_SWPORTA_DDR);
-       gpio_writel(gpio0d4_do, GPIO_SWPORTA_DR);
+       gpio0_writel(gpio0d4_dir, GPIO_SWPORTA_DDR);
+       gpio0_writel(gpio0d4_do, GPIO_SWPORTA_DR);
        sram_udelay(10000);
+#endif
 
 #endif
 
@@ -585,6 +758,21 @@ void  rk30_pwm_resume_voltage_set(void)
 #endif
 }
 
+void __sramfunc board_pmu_suspend(void)
+{      
+       #if defined (CONFIG_MFD_TPS65910)
+       if(pmic_is_tps65910())
+       board_pmu_tps65910_suspend(); 
+       #endif   
+}
+void __sramfunc board_pmu_resume(void)
+{      
+       #if defined (CONFIG_MFD_TPS65910)
+       if(pmic_is_tps65910())
+       board_pmu_tps65910_resume(); 
+       #endif
+}
+
 #ifdef CONFIG_I2C1_RK30
 static struct i2c_board_info __initdata i2c1_info[] = {
 #if defined (CONFIG_GS_MMA7660)
@@ -604,7 +792,11 @@ static struct i2c_board_info __initdata i2c2_info[] = {
 #if defined (CONFIG_TOUCHSCREEN_SITRONIX_A720)
 {
         .type          ="sitronix",
+#ifdef CONFIG_MACH_RK2926_M713
+       .addr           = 0x60,
+#else
        .addr           = 0x38,
+#endif
        .flags          = 0,
        .irq            = TOUCH_INT_PIN,
        .platform_data = &sitronix_info,
@@ -657,12 +849,26 @@ static void __init rk30_i2c_register_board_info(void)
 //end of i2c
 
 #define POWER_ON_PIN RK2928_PIN1_PA2   //power_hold
+#if defined(CONFIG_REGULATOR_ACT8931)
+extern  int act8931_charge_det ;
+#endif
 static void rk2928_pm_power_off(void)
 {
        printk(KERN_ERR "rk2928_pm_power_off start...\n");
+        
+        #if defined(CONFIG_REGULATOR_ACT8931)
+        if(pmic_is_act8931())
+        {
+              if(act8931_charge_det)
+                   arm_pm_restart(0, NULL);
+        }
+        #endif
        
-       #if defined(CONFIG_MFD_TPS65910)
+       #if defined(CONFIG_MFD_TPS65910)        
+       if(pmic_is_tps65910())
+       {
                tps65910_device_shutdown();//tps65910 shutdown
+       }
        #endif
        gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
        
@@ -672,8 +878,7 @@ static void __init rk2928_board_init(void)
 {
        gpio_request(POWER_ON_PIN, "poweronpin");
        gpio_direction_output(POWER_ON_PIN, GPIO_HIGH);
-        gpio_free(POWER_ON_PIN);
-       
        pm_power_off = rk2928_pm_power_off;
        
        rk30_i2c_register_board_info();
@@ -704,22 +909,33 @@ static void __init rk2928_reserve(void)
  * comments    : min arm/logic voltage
  */
 static struct dvfs_arm_table dvfs_cpu_logic_table[] = {
-       {.frequency = 216 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},//0.975V/1.000V
-       {.frequency = 312 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},//0.975V/1.000V
-       {.frequency = 408 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},//1.000V/1.025V
-       {.frequency = 504 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},//1.000V/1.025V
-       {.frequency = 600 * 1000,       .cpu_volt = 1200 * 1000,        .logic_volt = 1200 * 1000},//1.025V/1.050V
-       {.frequency = 696 * 1000,       .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.000V/1.025V
-       {.frequency = 816 * 1000,       .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
-       //{.frequency = 912 * 1000,     .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
-       //{.frequency = 1008 * 1000,    .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
+#if defined(CONFIG_MACH_RK2926_M713)
+       {.frequency = 216 * 1000,       .cpu_volt =  850 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 312 * 1000,       .cpu_volt =  900 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 408 * 1000,       .cpu_volt =  950 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 504 * 1000,       .cpu_volt = 1000 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 600 * 1000,       .cpu_volt = 1100 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 696 * 1000,       .cpu_volt = 1175 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 816 * 1000,       .cpu_volt = 1250 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 912 * 1000,       .cpu_volt = 1350 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 1008 * 1000,      .cpu_volt = 1450 * 1000,        .logic_volt = 1200 * 1000},
+#else
+       {.frequency = 216 * 1000,       .cpu_volt =  850 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 312 * 1000,       .cpu_volt =  900 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 408 * 1000,       .cpu_volt =  975 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 504 * 1000,       .cpu_volt = 1050 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 600 * 1000,       .cpu_volt = 1150 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 696 * 1000,       .cpu_volt = 1225 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 816 * 1000,       .cpu_volt = 1325 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 912 * 1000,       .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 1008 * 1000,      .cpu_volt = 1475 * 1000,        .logic_volt = 1200 * 1000},
+#endif
 #if 0
-       {.frequency = 1104 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
-       {.frequency = 1200 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
-       {.frequency = 1104 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
-       {.frequency = 1248 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},//1.100V/1.050V
+       {.frequency = 1104 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 1200 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 1104 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 1248 * 1000,      .cpu_volt = 1400 * 1000,        .logic_volt = 1200 * 1000},
 #endif
-       //{.frequency = 1000 * 1000,    .cpu_volt = 1225 * 1000,        .logic_volt = 1200 * 1000},//1.150V/1.100V
        {.frequency = CPUFREQ_TABLE_END},
 };