rk:move pmic_type to board.h
[firefly-linux-kernel-4.4.55.git] / arch / arm / mach-rk30 / board-rk3066b-m701.c
index 401cf4829502cb58cfaba19d0ba425c8f19bf016..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
@@ -75,7 +80,7 @@
 #define RK30_FB0_MEM_SIZE 8*SZ_1M
 #endif
 
-#include "board-rk3066b-sdk-camera.c"
+#include "board-rk3066b-m701-camera.c"
 #include "board-rk3066b-m701-key.c"
 
 #if defined(CONFIG_TOUCHSCREEN_GT8XX)
@@ -126,29 +131,30 @@ struct goodix_platform_data goodix_info = {
 };
 #endif
 
-#if defined (CONFIG_TOUCHSCREEN_FT5306)
+#if defined (CONFIG_TOUCHSCREEN_FT5306_AV)
 
 #define TOUCH_RESET_PIN  RK30_PIN2_PC0
 #define TOUCH_INT_PIN   RK30_PIN0_PD4
 #define TOUCH_PWR_PIN    RK30_PIN2_PB4
 
-static int ft5x0x_init_platform_hw(void)
+static int ft5306_init_platform_hw(void)
 {
 
        rk30_mux_api_set(GPIO2C0_LCDC1DATA16_SMCADDR0_TRACECLK_NAME, GPIO2C_GPIO2C0);
+       rk30_mux_api_set(GPIO0D4_SPI1RXD_NAME, GPIO0D_GPIO0D4);
         rk30_mux_api_set(GPIO2B4_LCDC1DATA12_SMCDATA12_TRACEDATA12_NAME, GPIO2B_GPIO2B4);
        //printk("%s:0x%x,0x%x\n",__func__,rk30_mux_api_get(GPIO2C0_LCDC1DATA16_SMCADDR0_TRACECLK_NAME),rk30_mux_api_get(GPIO2B4_LCDC1DATA12_SMCDATA12_TRACEDATA12_NAME));
 
-       printk("==ft5x0x_init_platform_hw =\n");
+       printk("ft5306_init_platform_hw \n");
        if(gpio_request(TOUCH_RESET_PIN,NULL) != 0){
          gpio_free(TOUCH_RESET_PIN);
-         printk("ft5606_init_platform_hw gpio_request error\n");
+         printk("ft5306_init_platform_hw gpio_request error\n");
          return -EIO;
        }
 
        if(gpio_request(TOUCH_INT_PIN,NULL) != 0){
          gpio_free(TOUCH_INT_PIN);
-         printk("ift5606_init_platform_hw gpio_request error\n");
+         printk("ift5306_init_platform_hw gpio_request error\n");
          return -EIO;
        }
 
@@ -162,21 +168,21 @@ static int ft5x0x_init_platform_hw(void)
        return 0;
 }
 
-void ft5x0x_exit_platform_hw(void)
+void ft5306_exit_platform_hw(void)
 {
        printk("ft5606_exit_platform_hw\n");
        gpio_free(TOUCH_RESET_PIN);
        gpio_free(TOUCH_INT_PIN);
 }
 
-int ft5x0x_platform_sleep(void)
+int ft5306_platform_sleep(void)
 {
        printk("ft5606_platform_sleep\n");
        gpio_set_value(TOUCH_RESET_PIN,GPIO_LOW);
        return 0;
 }
 
-int ft5x0x_platform_wakeup(void)
+int ft5306_platform_wakeup(void)
 {
        printk("ft5606_platform_wakeup\n");
        gpio_set_value(TOUCH_RESET_PIN,GPIO_HIGH);
@@ -184,11 +190,12 @@ int ft5x0x_platform_wakeup(void)
        return 0;
 }
 
-static struct ft5606_platform_data ft5x0x_info = {
-       .init_platform_hw= ft5x0x_init_platform_hw,
-       .exit_platform_hw= ft5x0x_exit_platform_hw,
-       .platform_sleep  = ft5x0x_platform_sleep,
-       .platform_wakeup = ft5x0x_platform_wakeup,
+struct ft5606_platform_data ft5306_info = {
+
+  .init_platform_hw= ft5306_init_platform_hw,
+  .exit_platform_hw= ft5306_exit_platform_hw,
+  .platform_sleep= ft5306_platform_sleep,
+  .platform_wakeup= ft5306_platform_wakeup,
 };
 #endif
 
@@ -235,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;
 }
 
@@ -274,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,
 };
@@ -450,26 +463,27 @@ struct platform_device rk30_device_sew868 = {
 #endif
 
 
+/*MMA7660 gsensor*/
 #if defined (CONFIG_GS_MMA7660)
-#define MMA7660_INT_PIN                        RK30_PIN4_PC0
-static int gs_init_platform_hw(void)
+#define MMA7660_INT_PIN   RK30_PIN3_PD7
+
+static int mma7660_init_platform_hw(void)
 {
-       rk30_mux_api_set(GPIO4C0_SMCDATA0_TRACEDATA0_NAME, GPIO4C_GPIO4C0);
-    if(gpio_request(MMA7660_INT_PIN, NULL) != 0){
+      if(gpio_request(MMA7660_INT_PIN, NULL) != 0){
       gpio_free(MMA7660_INT_PIN);
       printk("gsensor gpio_request error\n");
       return -EIO;
     }
-       //gpio_direction_input(MMA7660_INT_PIN);
-    gpio_pull_updown(MMA7660_INT_PIN, 1);
-    return 0;
+      //gpio_direction_input(MMA7660_INT_PIN);
+      return 0;
 }
 
-
-static struct gs_platform_data mma7660_info = {
-  .model= 7660,
-  .swap_xy = 0,
-  .init_platform_hw= gs_init_platform_hw,
+static struct sensor_platform_data mma7660_info = {
+        .type = SENSOR_TYPE_ACCEL,
+        .irq_enable = 1,
+        .poll_delay_ms = 30,
+        .init_platform_hw = mma7660_init_platform_hw,
+        .orientation = {0, 1, 0, 0, 0, -1, 1, 0, 0},
 };
 #endif
 
@@ -578,16 +592,35 @@ static struct sensor_platform_data cm3217_info = {
 
 #ifdef CONFIG_FB_ROCKCHIP
 
-#define LCD_CS_PIN         INVALID_GPIO
+#define LCD_CS_PIN         RK30_PIN2_PB6
 #define LCD_CS_VALUE       GPIO_HIGH
 
 #define LCD_EN_PIN         RK30_PIN0_PB0
-#define LCD_EN_VALUE       GPIO_HIGH
+#define LCD_EN_VALUE       GPIO_LOW
+
+#define LCD_STB_PIN       RK30_PIN2_PB3
+#define LCD_STB_VALUE     GPIO_HIGH
 
 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);
@@ -617,10 +650,17 @@ static int rk_fb_io_init(struct rk29_fb_setting_info *fb_setting)
                        gpio_direction_output(LCD_EN_PIN, LCD_EN_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);
@@ -629,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);
@@ -747,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[] = {
        {
@@ -1031,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 = {
@@ -1298,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
                {
@@ -1326,15 +1409,13 @@ 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
 #include "board-rk3066b-sdk-wm8326.c"
 #endif
 #ifdef CONFIG_MFD_TPS65910
-#define TPS65910_HOST_IRQ        RK30_PIN6_PA4
+#define TPS65910_HOST_IRQ        RK30_PIN0_PB3
 #include "board-rk3066b-sdk-tps65910.c"
 #endif
 
@@ -1363,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   
 }
@@ -1375,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
 }
@@ -1442,13 +1523,13 @@ static struct i2c_board_info __initdata i2c2_info[] = {
                .platform_data = &goodix_info,
        },
 #endif
-#if defined (CONFIG_TOUCHSCREEN_FT5306)
+#if defined (CONFIG_TOUCHSCREEN_FT5306_AV)
                {
                        .type                   = "ft5x0x_ts",
                        .addr                   = 0x38,
                        .flags                  = 0,
                        .irq                    = RK30_PIN0_PD4,
-                       .platform_data  = &ft5x0x_info,
+                       .platform_data  = &ft5306_info,
                },
 #endif
 #if defined (CONFIG_LS_CM3217)
@@ -1518,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
@@ -1546,6 +1651,10 @@ static void __init machine_rk30_board_init(void)
 #ifdef CONFIG_WIFI_CONTROL_FUNC
        rk29sdk_wifi_bt_gpio_control_init();
 #endif
+
+       // spk and ear switch
+       gpio_request(RK30_PIN2_PB1, NULL);
+        gpio_direction_output(RK30_PIN2_PB1, GPIO_HIGH);
 }
 
 static void __init rk30_reserve(void)
@@ -1578,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 = 975 * 1000,         .logic_volt = 1000 * 1000},//0.975V/1.000V
-       {.frequency = 816 * 1000,       .cpu_volt = 1000 * 1000,        .logic_volt = 1000 * 1000},//1.000V/1.025V
-       {.frequency = 1200 * 1000,      .cpu_volt = 1025 * 1000,        .logic_volt = 1000 * 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},
 };
@@ -1596,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},
 };