rk:move pmic_type to board.h
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk30 / board-rk3066b-m701.c
index 94ba8c63dff22c017d53c0e08c3a4432a43da44c..7735e9e08860ac9d17c53f4ab44ed409161af513 100755 (executable)
 #include <linux/sensor-dev.h>
 #include <linux/mfd/tps65910.h>
 #include <linux/regulator/rk29-pwm-regulator.h>
+
+#if defined(CONFIG_MFD_RK610)
+#include <linux/mfd/rk610_core.h>
+#endif
+
 #if defined(CONFIG_HDMI_RK30)
        #include "../../../drivers/video/rockchip/hdmi/rk_hdmi.h"
 #endif
@@ -181,11 +186,7 @@ int ft5306_platform_wakeup(void)
 {
        printk("ft5606_platform_wakeup\n");
        gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
-       mdelay(20);
-       gpio_direction_output(TOUCH_RESET_PIN,GPIO_LOW);
-       mdelay(300);
-       gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
-       mdelay(200);
+       msleep(300);
        return 0;
 }
 
@@ -241,9 +242,13 @@ static int rk29_backlight_io_deinit(void)
 {
        int ret = 0;
 #ifdef  LCD_DISP_ON_PIN
+       gpio_direction_output(BL_EN_PIN, 0);
+       gpio_set_value(BL_EN_PIN, !BL_EN_VALUE);
        gpio_free(BL_EN_PIN);
 #endif
        rk30_mux_api_set(PWM_MUX_NAME, PWM_MUX_MODE_GPIO);
+       gpio_request(PWM_GPIO, NULL);
+       gpio_direction_output(PWM_GPIO, GPIO_LOW);
        return ret;
 }
 
@@ -280,6 +285,8 @@ static struct rk29_bl_info rk29_bl_info = {
        .bl_ref = PWM_EFFECT_VALUE,
        .io_init = rk29_backlight_io_init,
        .io_deinit = rk29_backlight_io_deinit,
+       .min_brightness = 48,
+       .delay_ms = 0,
        .pwm_suspend = rk29_backlight_pwm_suspend,
        .pwm_resume = rk29_backlight_pwm_resume,
 };
@@ -598,6 +605,22 @@ static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
 {
        int ret = 0;
 
+       if(LCD_STB_PIN !=INVALID_GPIO)
+        {
+                ret = gpio_request(LCD_STB_PIN, NULL);
+                if (ret != 0)
+                {
+                        gpio_free(LCD_STB_PIN);
+                        printk(KERN_ERR "request lcd en pin fail!\n");
+                        return -1;
+                }
+                else
+                {
+                        gpio_direction_output(LCD_STB_PIN, LCD_STB_VALUE);
+                }
+        }
+
+       msleep(100);
        if(LCD_CS_PIN !=INVALID_GPIO)
        {
                ret = gpio_request(LCD_CS_PIN, NULL);
@@ -628,25 +651,16 @@ static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
                }
        }
 
-       if(LCD_STB_PIN !=INVALID_GPIO)
-        {
-                ret = gpio_request(LCD_STB_PIN, NULL);
-                if (ret != 0)
-                {
-                        gpio_free(LCD_STB_PIN);
-                        printk(KERN_ERR "request lcd en pin fail!\n");
-                        return -1;
-                }
-                else
-                {
-                        gpio_direction_output(LCD_STB_PIN, LCD_STB_VALUE);
-                }
-        }
 
        return 0;
 }
 static int rk_fb_io_disable(void)
 {
+       if(LCD_STB_PIN !=INVALID_GPIO)
+       {
+               gpio_set_value(LCD_STB_PIN, !LCD_STB_VALUE);
+       }
+       msleep(50);
        if(LCD_CS_PIN !=INVALID_GPIO)
        {
                gpio_set_value(LCD_CS_PIN, !LCD_CS_VALUE);
@@ -655,10 +669,16 @@ static int rk_fb_io_disable(void)
        {
                gpio_set_value(LCD_EN_PIN, !LCD_EN_VALUE);
        }
+
        return 0;
 }
 static int rk_fb_io_enable(void)
 {
+       if(LCD_STB_PIN !=INVALID_GPIO)
+       {
+               gpio_set_value(LCD_STB_PIN, LCD_STB_VALUE);
+       }
+       msleep(50);
        if(LCD_CS_PIN !=INVALID_GPIO)
        {
                gpio_set_value(LCD_CS_PIN, LCD_CS_VALUE);
@@ -773,6 +793,41 @@ static struct platform_device device_lcdc1 = {
 };
 #endif
 
+#if defined(CONFIG_MFD_RK610)
+#define RK610_RST_PIN_MUX_NAME         GPIO2C5_LCDC1DATA21_SMCADDR5_NAME 
+#define RK610_RST_PIN_MUX_MODE         GPIO2C_GPIO2C5
+#define RK610_RST_PIN                  RK30_PIN2_PC5
+static int rk610_power_on_init(void)
+{
+       int ret;
+       if(RK610_RST_PIN != INVALID_GPIO)
+       {
+               rk30_mux_api_set(RK610_RST_PIN_MUX_NAME,RK610_RST_PIN_MUX_MODE);
+               ret = gpio_request(RK610_RST_PIN, "rk610 reset");
+               if (ret)
+               {
+                       printk(KERN_ERR "rk610_control_probe request gpio fail\n");
+               }
+               else 
+               {
+                       gpio_direction_output(RK610_RST_PIN, GPIO_HIGH);
+                       msleep(100);
+                       gpio_direction_output(RK610_RST_PIN, GPIO_LOW);
+                       msleep(100);
+                       gpio_set_value(RK610_RST_PIN, GPIO_HIGH);
+               }
+       }
+
+       return 0;
+       
+}
+
+
+static struct rk610_ctl_platform_data rk610_ctl_pdata = {
+       .rk610_power_on_init = rk610_power_on_init,
+};
+#endif
+
 #ifdef CONFIG_ANDROID_TIMED_GPIO
 static struct timed_gpio timed_gpios[] = {
        {
@@ -1057,10 +1112,11 @@ struct rk29_sdmmc_platform_data default_sdmmc1_data = {
 static struct rk30_adc_battery_platform_data rk30_adc_battery_platdata = {
         .dc_det_pin      = RK30_PIN0_PB2,
         .batt_low_pin    = RK30_PIN0_PB1, 
-        .charge_set_pin  = INVALID_GPIO,
+        .charge_set_pin  = RK30_PIN2_PA7,
         .charge_ok_pin   = RK30_PIN0_PA6,
         .dc_det_level    = GPIO_LOW,
         .charge_ok_level = GPIO_HIGH,
+               .charge_set_level = GPIO_HIGH,
 };
 
 static struct platform_device rk30_device_adc_battery = {
@@ -1324,6 +1380,7 @@ static struct i2c_board_info __initdata i2c0_info[] = {
                        .type                   = "rk610_ctl",
                        .addr                   = 0x40,
                        .flags                  = 0,
+                       .platform_data          = &rk610_ctl_pdata,
                },
 #ifdef CONFIG_RK610_TVOUT
                {
@@ -1352,8 +1409,6 @@ static struct i2c_board_info __initdata i2c0_info[] = {
 };
 #endif
 
-#define PMIC_TYPE_WM8326       1
-#define PMIC_TYPE_TPS65910     2
 int __sramdata g_pmic_type =  0;
 #ifdef CONFIG_I2C1_RK30
 #ifdef CONFIG_MFD_WM831X_I2C
@@ -1389,11 +1444,11 @@ static struct i2c_board_info __initdata i2c1_info[] = {
 void __sramfunc board_pmu_suspend(void)
 {      
        #if defined (CONFIG_MFD_WM831X_I2C)
-       if(g_pmic_type == PMIC_TYPE_WM8326)
+       if(pmic_is_wm8326())
        board_pmu_wm8326_suspend();
        #endif
        #if defined (CONFIG_MFD_TPS65910)
-       if(g_pmic_type == PMIC_TYPE_TPS65910)
+       if(pmic_is_tps65910())
        board_pmu_tps65910_suspend(); 
     #endif   
 }
@@ -1401,11 +1456,11 @@ void __sramfunc board_pmu_suspend(void)
 void __sramfunc board_pmu_resume(void)
 {      
        #if defined (CONFIG_MFD_WM831X_I2C)
-       if(g_pmic_type == PMIC_TYPE_WM8326)
+       if(pmic_is_wm8326())
        board_pmu_wm8326_resume();
        #endif
        #if defined (CONFIG_MFD_TPS65910)
-       if(g_pmic_type == PMIC_TYPE_TPS65910)
+       if(pmic_is_tps65910())
        board_pmu_tps65910_resume(); 
        #endif
 }
@@ -1544,10 +1599,34 @@ static void __init rk30_i2c_register_board_info(void)
 }
 //end of i2c
 
+#define POWEROFF_CHARGING_ANIMATION            (1)
 #define POWER_ON_PIN RK30_PIN0_PA0   //power_hold
 static void rk30_pm_power_off(void)
 {
-       printk(KERN_ERR "rk30_pm_power_off start...\n");
+#if POWEROFF_CHARGING_ANIMATION
+       int pwr_cnt = 0;
+       struct rk30_adc_battery_platform_data *batt_plat_data = &rk30_adc_battery_platdata;
+       if (gpio_get_value (batt_plat_data->dc_det_pin)  ==
+               batt_plat_data->dc_det_level) {
+               printk("AC Charging, try to restart...\n");
+               while (1) {
+                        if (gpio_get_value (batt_plat_data->dc_det_pin) !=
+                               batt_plat_data->dc_det_level ) {
+                               pwr_cnt = 0;
+                               break;
+                        }
+                        if (pwr_cnt++ > 40)
+                               break;
+                        mdelay(50);
+               }
+               if (pwr_cnt > 40)  {
+                       printk("AC Charging, will restart system...\n");
+                       arm_pm_restart(0, NULL);
+               }
+       }
+#endif
+
+       printk("rk30_pm_power_off start...\n");
        gpio_direction_output(POWER_ON_PIN, GPIO_LOW);
 #if defined(CONFIG_MFD_WM831X)
        wm831x_set_bits(Wm831x,WM831X_GPIO_LEVEL,0x0001,0x0000);  //set sys_pwr 0
@@ -1608,17 +1687,17 @@ static void __init rk30_reserve(void)
  */
 static struct dvfs_arm_table dvfs_cpu_logic_table[] = {
 #if 0
-       {.frequency = 252 * 1000,       .cpu_volt = 1075 * 1000,        .logic_volt = 1125 * 1000},//0.975V/1.000V
+       {.frequency = 252 * 1000,       .cpu_volt = 1075 * 1000,        .logic_volt = 1125 * 1000},
 #endif
-       {.frequency = 504 * 1000,       .cpu_volt = 1100 * 1000,                .logic_volt = 1100 * 1000},//0.975V/1.000V
-       {.frequency = 816 * 1000,       .cpu_volt = 1100 * 1000,        .logic_volt = 1100 * 1000},//1.000V/1.025V
-       {.frequency = 1200 * 1000,      .cpu_volt = 1100 * 1000,        .logic_volt = 1100 * 1000},//1.100V/1.050V
+       {.frequency = 504 * 1000,       .cpu_volt = 1100 * 1000,        .logic_volt = 1100 * 1000},
+       {.frequency = 816 * 1000,       .cpu_volt = 1100 * 1000,        .logic_volt = 1100 * 1000},
+       {.frequency = 1200 * 1000,      .cpu_volt = 1100 * 1000,        .logic_volt = 1100 * 1000},
 #if 0
-       {.frequency = 1008 * 1000,      .cpu_volt = 1125 * 1000,        .logic_volt = 1150 * 1000},//1.025V/1.050V
-       {.frequency = 1272 * 1000,      .cpu_volt = 1225 * 1000,        .logic_volt = 1200 * 1000},//1.150V/1.100V
-       {.frequency = 1416 * 1000,      .cpu_volt = 1300 * 1000,        .logic_volt = 1200 * 1000},//1.225V/1.100V
-       {.frequency = 1512 * 1000,      .cpu_volt = 1350 * 1000,        .logic_volt = 1250 * 1000},//1.300V/1.150V
-       {.frequency = 1608 * 1000,      .cpu_volt = 1425 * 1000,        .logic_volt = 1300 * 1000},//1.325V/1.175V
+       {.frequency = 1008 * 1000,      .cpu_volt = 1125 * 1000,        .logic_volt = 1150 * 1000},
+       {.frequency = 1272 * 1000,      .cpu_volt = 1225 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 1416 * 1000,      .cpu_volt = 1300 * 1000,        .logic_volt = 1200 * 1000},
+       {.frequency = 1512 * 1000,      .cpu_volt = 1350 * 1000,        .logic_volt = 1250 * 1000},
+       {.frequency = 1608 * 1000,      .cpu_volt = 1425 * 1000,        .logic_volt = 1300 * 1000},
 #endif
        {.frequency = CPUFREQ_TABLE_END},
 };
@@ -1626,6 +1705,7 @@ static struct dvfs_arm_table dvfs_cpu_logic_table[] = {
 static struct cpufreq_frequency_table dvfs_gpu_table[] = {
        {.frequency = 266 * 1000,       .index = 1000 * 1000},
        {.frequency = 400 * 1000,       .index = 1000 * 1000},
+       {.frequency = 600 * 1000,       .index = 1200 * 1000},
        {.frequency = CPUFREQ_TABLE_END},
 };