ARM: tegra: ad5816 power/gpio programming changes
Sudhir Vyas [Tue, 30 Oct 2012 13:33:30 +0000 (18:33 +0530)]
* Reorganise power sequence.
* Add support for dalmore focuser.

Bug 1156996

Change-Id: I63a7b133f18922061f2bca96dbaf6f39172f3749
Signed-off-by: Sudhir Vyas <svyas@nvidia.com>
Reviewed-on: http://git-master/r/159880
Reviewed-by: Rohan Somvanshi <rsomvanshi@nvidia.com>
Tested-by: Rohan Somvanshi <rsomvanshi@nvidia.com>
Reviewed-by: Automatic_Commit_Validation_User

arch/arm/mach-tegra/board-cardhu-sensors.c
arch/arm/mach-tegra/board-dalmore-sensors.c
arch/arm/mach-tegra/board-pluto-sensors.c

index d90802d..dc54148 100644 (file)
@@ -50,7 +50,6 @@
 #include "board.h"
 #include <linux/mpu.h>
 #include <media/sh532u.h>
-#include <media/ad5816.h>
 #include <linux/bq27x00.h>
 #include <mach/edp.h>
 #include <linux/therm_est.h>
@@ -613,55 +612,6 @@ static struct sh532u_platform_data pm269_sh532u_right_pdata = {
        .gpio           = pm269_sh532u_right_gpio_pdata,
 };
 
-static struct nvc_gpio_pdata ad5816_gpio_pdata[] = {
-       { AD5816_GPIO_RESET, TEGRA_GPIO_PBB0, false, 0, },
-};
-
-static struct ad5816_platform_data ad5816_left_pdata = {
-       .cfg            = 0,
-       .num            = 1,
-       .sync           = 2,
-       .dev_name       = "focuser",
-       .gpio_count     = ARRAY_SIZE(ad5816_gpio_pdata),
-       .gpio           = ad5816_gpio_pdata,
-};
-
-static struct ad5816_platform_data ad5816_right_pdata = {
-       .cfg            = 0,
-       .num            = 2,
-       .sync           = 1,
-       .dev_name       = "focuser",
-       .gpio_count     = ARRAY_SIZE(ad5816_gpio_pdata),
-       .gpio           = ad5816_gpio_pdata,
-};
-
-static struct nvc_gpio_pdata pm269_ad5816_left_gpio_pdata[] = {
-       { AD5816_GPIO_RESET, CAM1_RST_L_GPIO, false, 0, },
-};
-
-static struct ad5816_platform_data pm269_ad5816_left_pdata = {
-       .cfg            = NVC_CFG_NODEV,
-       .num            = 1,
-       .sync           = 2,
-       .dev_name       = "focuser",
-       .gpio_count     = ARRAY_SIZE(pm269_ad5816_left_gpio_pdata),
-       .gpio           = pm269_ad5816_left_gpio_pdata,
-};
-
-static struct nvc_gpio_pdata pm269_ad5816_right_gpio_pdata[] = {
-       { AD5816_GPIO_RESET, CAM2_RST_L_GPIO, false, 0, },
-};
-
-static struct ad5816_platform_data pm269_ad5816_right_pdata = {
-       .cfg            = NVC_CFG_NODEV,
-       .num            = 2,
-       .sync           = 1,
-       .dev_name       = "focuser",
-       .gpio_count     = ARRAY_SIZE(pm269_ad5816_right_gpio_pdata),
-       .gpio           = pm269_ad5816_right_gpio_pdata,
-};
-
-
 static struct nvc_torch_pin_state cardhu_tps61050_pinstate = {
        .mask           = 0x0008, /*VGP3*/
        .values         = 0x0008,
@@ -688,10 +638,6 @@ static struct i2c_board_info cardhu_i2c6_board_info[] = {
                I2C_BOARD_INFO("sh532u", 0x72),
                .platform_data = &sh532u_left_pdata,
        },
-       {
-               I2C_BOARD_INFO("ad5816", 0x0E),
-               .platform_data = &ad5816_left_pdata,
-       },
 };
 
 static struct i2c_board_info cardhu_i2c7_board_info[] = {
@@ -703,10 +649,6 @@ static struct i2c_board_info cardhu_i2c7_board_info[] = {
                I2C_BOARD_INFO("sh532u", 0x72),
                .platform_data = &sh532u_right_pdata,
        },
-       {
-               I2C_BOARD_INFO("ad5816", 0x0E),
-               .platform_data = &ad5816_right_pdata,
-       },
 };
 
 static struct i2c_board_info pm269_i2c6_board_info[] = {
@@ -718,10 +660,6 @@ static struct i2c_board_info pm269_i2c6_board_info[] = {
                I2C_BOARD_INFO("sh532u", 0x72),
                .platform_data = &pm269_sh532u_left_pdata,
        },
-       {
-               I2C_BOARD_INFO("ad5816", 0x0E),
-               .platform_data = &pm269_ad5816_left_pdata,
-       },
 };
 
 static struct i2c_board_info pm269_i2c7_board_info[] = {
@@ -733,10 +671,6 @@ static struct i2c_board_info pm269_i2c7_board_info[] = {
                I2C_BOARD_INFO("sh532u", 0x72),
                .platform_data = &pm269_sh532u_right_pdata,
        },
-       {
-               I2C_BOARD_INFO("ad5816", 0x0E),
-               .platform_data = &pm269_ad5816_right_pdata,
-       },
 };
 
 static struct i2c_board_info cardhu_i2c8_board_info[] = {
index cc9ee53..c5f7247 100644 (file)
@@ -36,6 +36,7 @@
 #include <linux/therm_est.h>
 #include <linux/nct1008.h>
 #include <mach/edp.h>
+
 #include <mach/gpio-tegra.h>
 #include <mach/pinmux-t11.h>
 #include <mach/pinmux.h>
@@ -114,7 +115,44 @@ static struct i2c_board_info dalmore_i2c4_nct1008_board_info[] = {
                .lock           = TEGRA_PIN_LOCK_##_lock,       \
                .od             = TEGRA_PIN_OD_DEFAULT,         \
                .ioreset        = TEGRA_PIN_IO_RESET_##_ioreset \
-       }
+}
+
+static int dalmore_focuser_power_on(struct ad5816_power_rail *pw)
+{
+       int err;
+
+       if (unlikely(WARN_ON(!pw || !pw->vdd || !pw->vdd_i2c)))
+               return -EFAULT;
+
+       err = regulator_enable(pw->vdd_i2c);
+       if (unlikely(err))
+               goto ad5816_vdd_i2c_fail;
+
+       err = regulator_enable(pw->vdd);
+       if (unlikely(err))
+               goto ad5816_vdd_fail;
+
+       return 0;
+
+ad5816_vdd_fail:
+       regulator_disable(pw->vdd_i2c);
+
+ad5816_vdd_i2c_fail:
+       pr_err("%s FAILED\n", __func__);
+
+       return -ENODEV;
+}
+
+static int dalmore_focuser_power_off(struct ad5816_power_rail *pw)
+{
+       if (unlikely(WARN_ON(!pw || !pw->vdd || !pw->vdd_i2c)))
+               return -EFAULT;
+
+       regulator_disable(pw->vdd);
+       regulator_disable(pw->vdd_i2c);
+
+       return 0;
+}
 
 static struct tegra_pingroup_config mclk_disable =
        VI_PINMUX(CAM_MCLK, VI, NORMAL, NORMAL, OUTPUT, DEFAULT, DEFAULT);
@@ -376,11 +414,13 @@ static struct as364x_platform_data dalmore_as3648_pdata = {
        .power_off_callback = dalmore_as3648_power_off,
 };
 
-static struct ad5816_platform_data pluto_ad5816_pdata = {
-       .cfg            = 0,
-       .num            = 0,
-       .sync           = 0,
-       .dev_name       = "focuser",
+static struct ad5816_platform_data dalmore_ad5816_pdata = {
+       .cfg = 0,
+       .num = 0,
+       .sync = 0,
+       .dev_name = "focuser",
+       .power_on = dalmore_focuser_power_on,
+       .power_off = dalmore_focuser_power_off,
 };
 
 static struct i2c_board_info dalmore_i2c_board_info_e1625[] = {
@@ -398,7 +438,7 @@ static struct i2c_board_info dalmore_i2c_board_info_e1625[] = {
        },
        {
                I2C_BOARD_INFO("ad5816", 0x0E),
-               .platform_data = &pluto_ad5816_pdata,
+               .platform_data = &dalmore_ad5816_pdata,
        },
 };
 
index 0a6ae64..1c30720 100644 (file)
@@ -268,7 +268,44 @@ static struct i2c_board_info pluto_i2c4_nct1008_board_info[] = {
                .lock           = TEGRA_PIN_LOCK_##_lock,       \
                .od             = TEGRA_PIN_OD_DEFAULT,         \
                .ioreset        = TEGRA_PIN_IO_RESET_##_ioreset \
-       }
+}
+
+static int pluto_focuser_power_on(struct ad5816_power_rail *pw)
+{
+       int err;
+
+       if (unlikely(WARN_ON(!pw || !pw->vdd || !pw->vdd_i2c)))
+               return -EFAULT;
+
+       err = regulator_enable(pw->vdd_i2c);
+       if (unlikely(err))
+               goto ad5816_vdd_i2c_fail;
+
+       err = regulator_enable(pw->vdd);
+       if (unlikely(err))
+               goto ad5816_vdd_fail;
+
+       return 0;
+
+ad5816_vdd_fail:
+       regulator_disable(pw->vdd_i2c);
+
+ad5816_vdd_i2c_fail:
+       pr_err("%s FAILED\n", __func__);
+
+       return -ENODEV;
+}
+
+static int pluto_focuser_power_off(struct ad5816_power_rail *pw)
+{
+       if (unlikely(WARN_ON(!pw || !pw->vdd || !pw->vdd_i2c)))
+               return -EFAULT;
+
+       regulator_disable(pw->vdd);
+       regulator_disable(pw->vdd_i2c);
+
+       return 0;
+}
 
 static struct tegra_pingroup_config mclk_disable =
        VI_PINMUX(CAM_MCLK, VI, NORMAL, NORMAL, OUTPUT, DEFAULT, DEFAULT);
@@ -532,6 +569,8 @@ static struct ad5816_platform_data pluto_ad5816_pdata = {
        .num            = 0,
        .sync           = 0,
        .dev_name       = "focuser",
+       .power_on       = pluto_focuser_power_on,
+       .power_off      = pluto_focuser_power_off,
 };
 
 static struct i2c_board_info pluto_i2c_board_info_e1625[] = {