ARM: tegra: cardhu: sensor: support for rear right camera
Prayas Mohanty [Wed, 13 Apr 2011 07:00:56 +0000 (12:00 +0530)]
- Add support for camera-B.
- Have separate power on/off handler for each camera sensor.
- Remove invidual query for boardId, and bookkeeping boardId information
in a static variable during cardhu_sensors_init.

bug: 787214
bug: 786928

Original-Change-Id: Icc15a4cd6f113dd54adf197498f3b214595a53fd
Reviewed-on: http://git-master/r/27023
Reviewed-by: Varun Colbert <vcolbert@nvidia.com>
Tested-by: Varun Colbert <vcolbert@nvidia.com>
Original-Change-Id: Ie5c06897a4f5c446aeeda168769e80d1a717e479

Rebase-Id: Rb8d7f9a68b90f224d6225962ca75b9da18b27e51

arch/arm/mach-tegra/board-cardhu-sensors.c
arch/arm/mach-tegra/board-cardhu.h

index f7ede6d..2b56ed4 100644 (file)
 #include "board-cardhu.h"
 
 static struct regulator *cardhu_1v8_cam1 = NULL;
+static struct regulator *cardhu_1v8_cam2 = NULL;
 static struct regulator *cardhu_1v8_cam3 = NULL;
 static struct regulator *cardhu_avdd_dsi_csi = NULL;
 static struct regulator *cardhu_vdd_2v8_cam1 = NULL;
+static struct regulator *cardhu_vdd_2v8_cam2 = NULL;
 static struct regulator *cardhu_vdd_cam3 = NULL;
 
+static struct board_info board_info;
+
 #ifdef CONFIG_I2C_MUX_PCA954x
 static struct pca954x_platform_mode cardhu_pca954x_modes[] = {
        { .adap_id = PCA954x_I2C_BUS0, },
@@ -61,9 +65,7 @@ static struct pca954x_platform_data cardhu_pca954x_data = {
 static int cardhu_camera_init(void)
 {
        int ret;
-       struct board_info board_info;
 
-       tegra_get_board_info(&board_info);
        /* Boards E1198 and E1291 are of Cardhu personality
         * and donot have TCA6416 exp for camera */
        if ((board_info.board_id == BOARD_E1198) ||
@@ -73,13 +75,18 @@ static int cardhu_camera_init(void)
                if (ret < 0)
                        pr_err("%s: gpio_request failed for gpio %s\n",
                                __func__, "CAM1_POWER_DWN_GPIO");
-
-               tegra_gpio_enable(CAM3_POWER_DWN_GPIO);
+                               tegra_gpio_enable(CAM3_POWER_DWN_GPIO);
                ret = gpio_request(CAM3_POWER_DWN_GPIO, "cam3_power_en");
                if (ret < 0)
                        pr_err("%s: gpio_request failed for gpio %s\n",
                                __func__, "CAM3_POWER_DWN_GPIO");
 
+               tegra_gpio_enable(CAM2_POWER_DWN_GPIO);
+               ret = gpio_request(CAM2_POWER_DWN_GPIO, "camera2_power_en");
+               if (ret < 0)
+                       pr_err("%s: gpio_request failed for gpio %s\n",
+                               __func__, "CAM2_POWER_DWN_GPIO");
+
                tegra_gpio_enable(OV5650_RESETN_GPIO);
                ret = gpio_request(OV5650_RESETN_GPIO, "camera_reset");
                if (ret < 0)
@@ -88,6 +95,7 @@ static int cardhu_camera_init(void)
 
                gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
                gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
+               gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
                mdelay(10);
 
                gpio_direction_output(OV5650_RESETN_GPIO, 1);
@@ -96,7 +104,6 @@ static int cardhu_camera_init(void)
                mdelay(5);
                gpio_direction_output(OV5650_RESETN_GPIO, 1);
                mdelay(5);
-
        }
 
        /* To select the CSIB MUX either for cam2 or cam3 */
@@ -111,16 +118,13 @@ static int cardhu_camera_init(void)
        return 0;
 }
 
-static int cardhu_ov5650_power_on(void)
+static int cardhu_left_ov5650_power_on(void)
 {
-       struct board_info board_info;
-       tegra_get_board_info(&board_info);
        /* Boards E1198 and E1291 are of Cardhu personality
         * and donot have TCA6416 exp for camera */
        if ((board_info.board_id == BOARD_E1198) ||
                (board_info.board_id == BOARD_E1291)) {
 
-               gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
                gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
                mdelay(10);
 
@@ -133,28 +137,6 @@ static int cardhu_ov5650_power_on(void)
                        }
                }
                regulator_enable(cardhu_vdd_2v8_cam1);
-
-               if (cardhu_vdd_cam3 == NULL) {
-                       cardhu_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
-                       if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
-                               pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
-                                       __func__, PTR_ERR(cardhu_vdd_cam3));
-                               goto reg_alloc_fail;
-                       }
-               }
-               regulator_enable(cardhu_vdd_cam3);
-
-               /* Enable VDD_1V8_Cam3 */
-               if (cardhu_1v8_cam3 == NULL) {
-                       cardhu_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
-                       if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
-                               pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
-                                       __func__, PTR_ERR(cardhu_1v8_cam3));
-                               goto reg_alloc_fail;
-                       }
-               }
-               regulator_enable(cardhu_1v8_cam3);
-
                mdelay(5);
        }
 
@@ -179,6 +161,7 @@ static int cardhu_ov5650_power_on(void)
                }
        }
        regulator_enable(cardhu_avdd_dsi_csi);
+
        mdelay(5);
        return 0;
 
@@ -187,10 +170,6 @@ reg_alloc_fail:
                regulator_put(cardhu_1v8_cam1);
                cardhu_1v8_cam1 = NULL;
        }
-       if (cardhu_1v8_cam3) {
-               regulator_put(cardhu_1v8_cam3);
-               cardhu_1v8_cam3 = NULL;
-       }
        if (cardhu_avdd_dsi_csi) {
                regulator_put(cardhu_avdd_dsi_csi);
                cardhu_avdd_dsi_csi = NULL;
@@ -199,23 +178,20 @@ reg_alloc_fail:
                regulator_put(cardhu_vdd_2v8_cam1);
                cardhu_vdd_2v8_cam1 = NULL;
        }
-       if (cardhu_vdd_cam3) {
-               regulator_put(cardhu_vdd_cam3);
-               cardhu_vdd_cam3 = NULL;
-       }
+
        return -ENODEV;
 
 }
 
-static int cardhu_ov5650_power_off(void)
+static int cardhu_left_ov5650_power_off(void)
 {
-       struct board_info board_info;
-       tegra_get_board_info(&board_info);
        /* Boards E1198 and E1291 are of Cardhu personality
         * and donot have TCA6416 exp for camera */
        if ((board_info.board_id == BOARD_E1198) ||
                (board_info.board_id == BOARD_E1291)) {
                gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
+               gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
+               gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
        }
        if (cardhu_1v8_cam1)
                regulator_disable(cardhu_1v8_cam1);
@@ -227,21 +203,191 @@ static int cardhu_ov5650_power_off(void)
        return 0;
 }
 
-struct ov5650_platform_data cardhu_ov5650_data = {
-       .power_on = cardhu_ov5650_power_on,
-       .power_off = cardhu_ov5650_power_off,
+struct ov5650_platform_data cardhu_left_ov5650_data = {
+       .power_on = cardhu_left_ov5650_power_on,
+       .power_off = cardhu_left_ov5650_power_off,
+};
+
+static int cardhu_right_ov5650_power_on(void)
+{
+       /* Boards E1198 and E1291 are of Cardhu personality
+        * and donot have TCA6416 exp for camera */
+       if ((board_info.board_id == BOARD_E1198) ||
+               (board_info.board_id == BOARD_E1291)) {
+
+               gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
+               gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
+               mdelay(10);
+
+               if (cardhu_vdd_2v8_cam2 == NULL) {
+                       cardhu_vdd_2v8_cam2 = regulator_get(NULL, "vdd_2v8_cam2");
+                       if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam2))) {
+                               pr_err("%s: couldn't get regulator vdd_2v8_cam2: %ld\n",
+                                       __func__, PTR_ERR(cardhu_vdd_2v8_cam2));
+                               goto reg_alloc_fail;
+                       }
+               }
+               regulator_enable(cardhu_vdd_2v8_cam2);
+               mdelay(5);
+       }
+
+       /* Enable VDD_1V8_Cam2 */
+       if (cardhu_1v8_cam2 == NULL) {
+               cardhu_1v8_cam2 = regulator_get(NULL, "vdd_1v8_cam2");
+               if (WARN_ON(IS_ERR(cardhu_1v8_cam2))) {
+                       pr_err("%s: couldn't get regulator vdd_1v8_cam2: %ld\n",
+                               __func__, PTR_ERR(cardhu_1v8_cam2));
+                       goto reg_alloc_fail;
+               }
+       }
+       regulator_enable(cardhu_1v8_cam2);
+
+       /* Enable AVDD_CSI_DSI */
+       if (cardhu_avdd_dsi_csi == NULL) {
+               cardhu_avdd_dsi_csi = regulator_get(NULL, "avdd_dsi_csi");
+               if (WARN_ON(IS_ERR(cardhu_avdd_dsi_csi))) {
+                       pr_err("%s: couldn't get regulator avdd_dsi_csi: %ld\n",
+                               __func__, PTR_ERR(cardhu_avdd_dsi_csi));
+                       goto reg_alloc_fail;
+               }
+       }
+       regulator_enable(cardhu_avdd_dsi_csi);
+
+       mdelay(5);
+       return 0;
+
+reg_alloc_fail:
+       if (cardhu_1v8_cam2) {
+               regulator_put(cardhu_1v8_cam2);
+               cardhu_1v8_cam2 = NULL;
+       }
+       if (cardhu_avdd_dsi_csi) {
+               regulator_put(cardhu_avdd_dsi_csi);
+               cardhu_avdd_dsi_csi = NULL;
+       }
+       if (cardhu_vdd_2v8_cam2) {
+               regulator_put(cardhu_vdd_2v8_cam2);
+               cardhu_vdd_2v8_cam2 = NULL;
+       }
+
+       return -ENODEV;
+
+}
+
+static int cardhu_right_ov5650_power_off(void)
+{
+       /* Boards E1198 and E1291 are of Cardhu personality
+        * and donot have TCA6416 exp for camera */
+       if ((board_info.board_id == BOARD_E1198) ||
+               (board_info.board_id == BOARD_E1291)) {
+               gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
+               gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
+       }
+
+       if (cardhu_1v8_cam2)
+               regulator_disable(cardhu_1v8_cam2);
+       if (cardhu_avdd_dsi_csi)
+               regulator_disable(cardhu_avdd_dsi_csi);
+       if (cardhu_vdd_2v8_cam2)
+               regulator_disable(cardhu_vdd_2v8_cam2);
+
+       return 0;
+}
+
+
+struct ov5650_platform_data cardhu_right_ov5650_data = {
+       .power_on = cardhu_right_ov5650_power_on,
+       .power_off = cardhu_right_ov5650_power_off,
 };
 
 static int cardhu_ov2710_power_on(void)
 {
-       cardhu_ov5650_power_on();
+       /* CSI-B and front sensor are muxed on verbier */
        gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
+
+       /* Boards E1198 and E1291 are of Cardhu personality
+        * and donot have TCA6416 exp for camera */
+       if ((board_info.board_id == BOARD_E1198) ||
+               (board_info.board_id == BOARD_E1291)) {
+
+               gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
+               gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
+               gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
+               mdelay(10);
+
+               if (cardhu_vdd_cam3 == NULL) {
+                       cardhu_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
+                       if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
+                               pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
+                                       __func__, PTR_ERR(cardhu_vdd_cam3));
+                               goto reg_alloc_fail;
+                       }
+               }
+               regulator_enable(cardhu_vdd_cam3);
+       }
+
+       /* Enable VDD_1V8_Cam3 */
+       if (cardhu_1v8_cam3 == NULL) {
+               cardhu_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
+               if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
+                       pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
+                               __func__, PTR_ERR(cardhu_1v8_cam3));
+                       goto reg_alloc_fail;
+               }
+       }
+       regulator_enable(cardhu_1v8_cam3);
+
+       /* Enable AVDD_CSI_DSI */
+       if (cardhu_avdd_dsi_csi == NULL) {
+               cardhu_avdd_dsi_csi = regulator_get(NULL, "avdd_dsi_csi");
+               if (WARN_ON(IS_ERR(cardhu_avdd_dsi_csi))) {
+                       pr_err("%s: couldn't get regulator avdd_dsi_csi: %ld\n",
+                               __func__, PTR_ERR(cardhu_avdd_dsi_csi));
+                       goto reg_alloc_fail;
+               }
+       }
+       regulator_enable(cardhu_avdd_dsi_csi);
+       mdelay(5);
+
        return 0;
+
+reg_alloc_fail:
+       if (cardhu_1v8_cam3) {
+               regulator_put(cardhu_1v8_cam3);
+               cardhu_1v8_cam3 = NULL;
+       }
+       if (cardhu_avdd_dsi_csi) {
+               regulator_put(cardhu_avdd_dsi_csi);
+               cardhu_avdd_dsi_csi = NULL;
+       }
+       if (cardhu_vdd_cam3) {
+               regulator_put(cardhu_vdd_cam3);
+               cardhu_vdd_cam3 = NULL;
+       }
+
+       return -ENODEV;
 }
 
 static int cardhu_ov2710_power_off(void)
 {
-       cardhu_ov5650_power_off();
+       gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
+
+       /* Boards E1198 and E1291 are of Cardhu personality
+        * and donot have TCA6416 exp for camera */
+       if ((board_info.board_id == BOARD_E1198) ||
+               (board_info.board_id == BOARD_E1291)) {
+               gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
+               gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
+               gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
+       }
+
+       if (cardhu_1v8_cam3)
+               regulator_disable(cardhu_1v8_cam3);
+       if (cardhu_avdd_dsi_csi)
+               regulator_disable(cardhu_avdd_dsi_csi);
+       if (cardhu_vdd_cam3)
+               regulator_disable(cardhu_vdd_cam3);
+
        return 0;
 }
 
@@ -260,14 +406,21 @@ static const struct i2c_board_info cardhu_i2c3_board_info[] = {
 };
 static struct i2c_board_info cardhu_i2c6_board_info[] = {
        {
-               I2C_BOARD_INFO("ov5650", 0x36),
-               .platform_data = &cardhu_ov5650_data,
+               I2C_BOARD_INFO("ov5650L", 0x36),
+               .platform_data = &cardhu_left_ov5650_data,
        },
        {
                I2C_BOARD_INFO("sh532u", 0x72),
        },
 };
 
+static struct i2c_board_info cardhu_i2c7_board_info[] = {
+       {
+               I2C_BOARD_INFO("ov5650R", 0x36),
+               .platform_data = &cardhu_right_ov5650_data,
+       },
+};
+
 static struct i2c_board_info cardhu_i2c8_board_info[] = {
        {
                I2C_BOARD_INFO("ov2710", 0x36),
@@ -304,15 +457,13 @@ static struct i2c_board_info cardhu_i2c4_board_info[] = {
 static int cardhu_nct1008_init(void)
 {
        int nct1008_port = -1;
-       struct board_info BoardInfo;
        int ret;
 
-       tegra_get_board_info(&BoardInfo);
-       if ((BoardInfo.board_id == BOARD_E1198) ||
-               (BoardInfo.board_id == BOARD_E1291)) {
+       if ((board_info.board_id == BOARD_E1198) ||
+               (board_info.board_id == BOARD_E1291)) {
                nct1008_port = TEGRA_GPIO_PCC2;
-       } else if ((BoardInfo.board_id == BOARD_E1186) ||
-               (BoardInfo.board_id == BOARD_E1187)) {
+       } else if ((board_info.board_id == BOARD_E1186) ||
+               (board_info.board_id == BOARD_E1187)) {
                /* FIXME: seems to be conflicting with usb3 vbus on E1186 */
                /* nct1008_port = TEGRA_GPIO_PH7; */
        }
@@ -361,11 +512,9 @@ static const struct i2c_board_info cardhu_i2c2_board_info_tca6416[] = {
 
 static int __init pmu_tca6416_init(void)
 {
-       struct board_info board_info;
-       tegra_get_board_info(&board_info);
        if ((board_info.board_id == BOARD_E1198) ||
-                       (board_info.board_id == BOARD_E1291))
-               return 0;
+               (board_info.board_id == BOARD_E1291))
+                       return 0;
 
        pr_info("Registering pmu pca6416\n");
        i2c_register_board_info(4, cardhu_i2c4_board_info_tca6416,
@@ -375,8 +524,6 @@ static int __init pmu_tca6416_init(void)
 
 static int __init cam_tca6416_init(void)
 {
-       struct board_info board_info;
-       tegra_get_board_info(&board_info);
        /* Boards E1198 and E1291 are of Cardhu personality
         * and donot have TCA6416 exp for camera */
        if ((board_info.board_id == BOARD_E1198) ||
@@ -452,7 +599,7 @@ static struct i2c_board_info cardhu_i2c2_isl_board_info[] = {
 int __init cardhu_sensors_init(void)
 {
        int err;
-       struct board_info board_info;
+
        tegra_get_board_info(&board_info);
 
        cardhu_camera_init();
@@ -461,11 +608,14 @@ int __init cardhu_sensors_init(void)
        i2c_register_board_info(2, cardhu_i2c3_board_info,
                ARRAY_SIZE(cardhu_i2c3_board_info));
 
-       /* CAM-A is on BUS0 to set CAM-B need to change
-        * PCA954x_I2C_BUS0 to PCA954x_I2C_BUS1 */
+       /* Left  camera is on PCA954x's I2C BUS0, Right camera is on BUS1 &
+        * Front camera is on BUS2 */
        i2c_register_board_info(PCA954x_I2C_BUS0, cardhu_i2c6_board_info,
                ARRAY_SIZE(cardhu_i2c6_board_info));
 
+       i2c_register_board_info(PCA954x_I2C_BUS1, cardhu_i2c7_board_info,
+               ARRAY_SIZE(cardhu_i2c7_board_info));
+
        i2c_register_board_info(PCA954x_I2C_BUS2, cardhu_i2c8_board_info,
                ARRAY_SIZE(cardhu_i2c8_board_info));
 
@@ -538,6 +688,7 @@ int __init cardhu_ov5650_late_init(void)
        int ret;
        int i;
 
+       printk("%s: \n", __func__);
        for (i = 0; i < ARRAY_SIZE(ov5650_gpio_keys); i++) {
                ret = gpio_request(ov5650_gpio_keys[i].gpio,
                        ov5650_gpio_keys[i].name);
@@ -546,6 +697,7 @@ int __init cardhu_ov5650_late_init(void)
                                __func__, i);
                        goto fail;
                }
+               printk("%s: enable - %d\n", __func__, i);
                gpio_direction_output(ov5650_gpio_keys[i].gpio,
                        ov5650_gpio_keys[i].enabled);
                gpio_export(ov5650_gpio_keys[i].gpio, false);
index 80923b2..9e3a2e6 100644 (file)
 /* CAMERA RELATED GPIOs on CARDHU */
 #define OV5650_RESETN_GPIO                     TEGRA_GPIO_PBB0
 #define CAM1_POWER_DWN_GPIO                    TEGRA_GPIO_PBB5
+#define CAM2_POWER_DWN_GPIO                    TEGRA_GPIO_PBB6
 #define CAM3_POWER_DWN_GPIO                    TEGRA_GPIO_PBB7
 #define CAMERA_CSI_CAM_SEL_GPIO                TEGRA_GPIO_PBB4
 #define CAMERA_CSI_MUX_SEL_GPIO                TEGRA_GPIO_PCC1
 #define CAM1_LDO_EN_GPIO                       TEGRA_GPIO_PR6
+#define CAM2_LDO_EN_GPIO                       TEGRA_GPIO_PR7
 #define CAM3_LDO_EN_GPIO                       TEGRA_GPIO_PS0
 
 /* PCA954x I2C bus expander bus addresses */