From 01f9a85e0a17f4137dd8981cc444c11f7385c564 Mon Sep 17 00:00:00 2001 From: Pritesh Raithatha Date: Tue, 24 Jan 2012 17:43:58 +0530 Subject: arm: tegra: ventana: use fixed regulator instead of direct gpios Bug 925547 Change-Id: Id4aaec9a847034ff16022123993433c9ce4754c3 Signed-off-by: Pritesh Raithatha Reviewed-on: http://git-master/r/76997 Reviewed-by: Simone Willett Tested-by: Simone Willett --- arch/arm/mach-tegra/board-ventana-power.c | 57 +++++++++++++++++++++++++ arch/arm/mach-tegra/board-ventana-sensors.c | 64 +++++++++++++++++++++-------- arch/arm/mach-tegra/board-ventana.h | 1 + 3 files changed, 104 insertions(+), 18 deletions(-) diff --git a/arch/arm/mach-tegra/board-ventana-power.c b/arch/arm/mach-tegra/board-ventana-power.c index 50482a11be4c..3ab178d8ebf8 100644 --- a/arch/arm/mach-tegra/board-ventana-power.c +++ b/arch/arm/mach-tegra/board-ventana-power.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -317,4 +318,60 @@ fail: return ret; } +#define ADD_FIXED_VOLTAGE_REG(_name) (&_name##_fixed_voltage_device) + +/* Macro for defining fixed voltage regulator */ +#define FIXED_VOLTAGE_REG_INIT(_id, _name, _microvolts, _gpio, \ + _startup_delay, _enable_high, _enabled_at_boot, \ + _valid_ops_mask, _always_on) \ + static struct regulator_init_data _name##_initdata = { \ + .consumer_supplies = _name##_consumer_supply, \ + .num_consumer_supplies = \ + ARRAY_SIZE(_name##_consumer_supply), \ + .constraints = { \ + .valid_ops_mask = _valid_ops_mask , \ + .always_on = _always_on, \ + }, \ + }; \ + static struct fixed_voltage_config _name##_config = { \ + .supply_name = #_name, \ + .microvolts = _microvolts, \ + .gpio = _gpio, \ + .startup_delay = _startup_delay, \ + .enable_high = _enable_high, \ + .enabled_at_boot = _enabled_at_boot, \ + .init_data = &_name##_initdata, \ + }; \ + static struct platform_device _name##_fixed_voltage_device = { \ + .name = "reg-fixed-voltage", \ + .id = _id, \ + .dev = { \ + .platform_data = &_name##_config, \ + }, \ + } + +static struct regulator_consumer_supply cam1_2v8_consumer_supply[] = { + REGULATOR_SUPPLY("cam1_2v8", NULL), +}; + +static struct regulator_consumer_supply cam2_2v8_consumer_supply[] = { + REGULATOR_SUPPLY("cam2_2v8", NULL), +}; + +FIXED_VOLTAGE_REG_INIT(0, cam1_2v8, 2800000, CAM1_LDO_SHUTDN_L_GPIO, + 0, 1, 0, REGULATOR_CHANGE_STATUS, 0); +FIXED_VOLTAGE_REG_INIT(1, cam2_2v8, 2800000, CAM2_LDO_SHUTDN_L_GPIO, + 0, 1, 0, REGULATOR_CHANGE_STATUS, 0); + +static struct platform_device *fixed_voltage_regulators[] __initdata = { + ADD_FIXED_VOLTAGE_REG(cam1_2v8), + ADD_FIXED_VOLTAGE_REG(cam2_2v8), +}; + +int __init ventana_gpio_fixed_voltage_regulator_init(void) +{ + return platform_add_devices(fixed_voltage_regulators, + ARRAY_SIZE(fixed_voltage_regulators)); +} + late_initcall(ventana_pcie_init); diff --git a/arch/arm/mach-tegra/board-ventana-sensors.c b/arch/arm/mach-tegra/board-ventana-sensors.c index 0bed64b01d21..6a5549cba56b 100644 --- a/arch/arm/mach-tegra/board-ventana-sensors.c +++ b/arch/arm/mach-tegra/board-ventana-sensors.c @@ -53,12 +53,14 @@ #include "board-ventana.h" #include "cpu-tegra.h" +static struct regulator *cam1_2v8, *cam2_2v8; + /* left ov5650 is CAM2 which is on csi_a */ static int ventana_left_ov5650_power_on(void) { gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0); gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 1); - gpio_direction_output(CAM2_LDO_SHUTDN_L_GPIO, 1); + regulator_enable(cam2_2v8); mdelay(5); gpio_direction_output(CAM2_PWR_DN_GPIO, 0); mdelay(5); @@ -74,7 +76,7 @@ static int ventana_left_ov5650_power_off(void) gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 0); gpio_direction_output(CAM2_RST_L_GPIO, 0); gpio_direction_output(CAM2_PWR_DN_GPIO, 1); - gpio_direction_output(CAM2_LDO_SHUTDN_L_GPIO, 0); + regulator_disable(cam2_2v8); return 0; } @@ -87,7 +89,7 @@ struct ov5650_platform_data ventana_left_ov5650_data = { static int ventana_right_ov5650_power_on(void) { gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 1); - gpio_direction_output(CAM1_LDO_SHUTDN_L_GPIO, 1); + regulator_enable(cam1_2v8); mdelay(5); gpio_direction_output(CAM1_PWR_DN_GPIO, 0); mdelay(5); @@ -103,7 +105,7 @@ static int ventana_right_ov5650_power_off(void) gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 0); gpio_direction_output(CAM1_RST_L_GPIO, 0); gpio_direction_output(CAM1_PWR_DN_GPIO, 1); - gpio_direction_output(CAM1_LDO_SHUTDN_L_GPIO, 0); + regulator_disable(cam1_2v8); return 0; } @@ -471,19 +473,17 @@ static struct tegra_camera_gpios ventana_camera_gpio_keys[] = { [3] = TEGRA_CAMERA_GPIO("en_avdd_csi", AVDD_DSI_CSI_ENB_GPIO, false, 1), [4] = TEGRA_CAMERA_GPIO("cam_i2c_mux_rst_lo", CAM_I2C_MUX_RST_GPIO, false, 1), - [5] = TEGRA_CAMERA_GPIO("cam2_ldo_shdn_lo", CAM2_LDO_SHUTDN_L_GPIO, false, 0), - [6] = TEGRA_CAMERA_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, false, 0), - [7] = TEGRA_CAMERA_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, false, 0), - [8] = TEGRA_CAMERA_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, false, 1), + [5] = TEGRA_CAMERA_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, false, 0), + [6] = TEGRA_CAMERA_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, false, 0), + [7] = TEGRA_CAMERA_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, false, 1), - [9] = TEGRA_CAMERA_GPIO("cam3_af_pwdn_lo", CAM3_AF_PWR_DN_L_GPIO, false, 0), - [10] = TEGRA_CAMERA_GPIO("cam3_pwdn", CAM3_PWR_DN_GPIO, false, 0), - [11] = TEGRA_CAMERA_GPIO("cam3_rst_lo", CAM3_RST_L_GPIO, false, 1), + [8] = TEGRA_CAMERA_GPIO("cam3_af_pwdn_lo", CAM3_AF_PWR_DN_L_GPIO, false, 0), + [9] = TEGRA_CAMERA_GPIO("cam3_pwdn", CAM3_PWR_DN_GPIO, false, 0), + [10] = TEGRA_CAMERA_GPIO("cam3_rst_lo", CAM3_RST_L_GPIO, false, 1), - [12] = TEGRA_CAMERA_GPIO("cam1_ldo_shdn_lo", CAM1_LDO_SHUTDN_L_GPIO, false, 0), - [13] = TEGRA_CAMERA_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, false, 0), - [14] = TEGRA_CAMERA_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, false, 0), - [15] = TEGRA_CAMERA_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, false, 1), + [11] = TEGRA_CAMERA_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, false, 0), + [12] = TEGRA_CAMERA_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, false, 0), + [13] = TEGRA_CAMERA_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, false, 1), }; int __init ventana_camera_late_init(void) @@ -504,7 +504,7 @@ int __init ventana_camera_late_init(void) ret = regulator_enable(cam_ldo6); if (ret){ pr_err("%s: Failed to enable ldo6\n", __func__); - goto fail_put_regulator; + goto fail_put_regulator_ldo6; } i2c_new_device(i2c_get_adapter(3), ventana_i2c3_board_info_tca6416); @@ -528,6 +528,28 @@ int __init ventana_camera_late_init(void) gpio_export(ventana_camera_gpio_keys[i].gpio, false); } + ventana_gpio_fixed_voltage_regulator_init(); + + cam1_2v8 = regulator_get(NULL, "cam1_2v8"); + if (WARN_ON(IS_ERR(cam1_2v8))) { + pr_err("%s: couldn't get regulator cam1_2v8: %ld\n", + __func__, PTR_ERR(cam1_2v8)); + ret = PTR_ERR(cam1_2v8); + goto fail_free_gpio; + } else { + regulator_enable(cam1_2v8); + } + + cam2_2v8 = regulator_get(NULL, "cam2_2v8"); + if (WARN_ON(IS_ERR(cam2_2v8))) { + pr_err("%s: couldn't get regulator cam2_2v8: %ld\n", + __func__, PTR_ERR(cam2_2v8)); + ret = PTR_ERR(cam2_2v8); + goto fail_put_regulator_cam1_2v8; + } else { + regulator_enable(cam2_2v8); + } + i2c_new_device(i2c_get_adapter(3), ventana_i2c3_board_info_pca9546); ventana_ov2710_power_off(); @@ -537,17 +559,23 @@ int __init ventana_camera_late_init(void) ret = regulator_disable(cam_ldo6); if (ret){ pr_err("%s: Failed to disable ldo6\n", __func__); - goto fail_free_gpio; + goto fail_put_regulator_cam2_2v8; } regulator_put(cam_ldo6); return 0; +fail_put_regulator_cam2_2v8: + regulator_put(cam2_2v8); + +fail_put_regulator_cam1_2v8: + regulator_put(cam1_2v8); + fail_free_gpio: while (i--) gpio_free(ventana_camera_gpio_keys[i].gpio); -fail_put_regulator: +fail_put_regulator_ldo6: regulator_put(cam_ldo6); return ret; } diff --git a/arch/arm/mach-tegra/board-ventana.h b/arch/arm/mach-tegra/board-ventana.h index 284fa43be229..443556213975 100644 --- a/arch/arm/mach-tegra/board-ventana.h +++ b/arch/arm/mach-tegra/board-ventana.h @@ -26,6 +26,7 @@ int ventana_sensors_init(void); int ventana_kbc_init(void); int ventana_emc_init(void); int ventana_charger_init(void); +int ventana_gpio_fixed_voltage_regulator_init(void); /* PCA954x I2C bus expander bus addresses */ #define PCA954x_I2C_BUS_BASE 6 -- cgit v1.2.3