Skip to content

Commit 79317ba

Browse files
committed
media: atomisp: place all gpio parsing together
Instead of parsing GPIO for two exceptions inside the logic which would be trying to use the GPIO, move the init code to the routine which adds a new gmin device. Move the notes to it too, as this helps to identify where those two GPIO settings are used, explaining why they're defaulting to -1 when not found. Tested-by: Andy Shevchenko <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 2b5b322 commit 79317ba

File tree

1 file changed

+40
-46
lines changed

1 file changed

+40
-46
lines changed

drivers/staging/media/atomisp/pci/atomisp_gmin_platform.c

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ struct gmin_subdev {
8383
bool v1p2_on;
8484
bool v2p8_vcm_on;
8585

86+
int v1p8_gpio;
87+
int v2p8_gpio;
88+
8689
u8 pwm_i2c_addr;
8790

8891
/* For PMIC AXP */
@@ -122,24 +125,6 @@ static const struct atomisp_platform_data pdata = {
122125
.subdevs = pdata_subdevs,
123126
};
124127

125-
/*
126-
* Something of a hack. The ECS E7 board drives camera 2.8v from an
127-
* external regulator instead of the PMIC. There's a gmin_CamV2P8
128-
* config variable that specifies the GPIO to handle this particular
129-
* case, but this needs a broader architecture for handling camera
130-
* power.
131-
*/
132-
enum { V2P8_GPIO_UNSET = -2, V2P8_GPIO_NONE = -1 };
133-
static int v2p8_gpio = V2P8_GPIO_UNSET;
134-
135-
/*
136-
* Something of a hack. The CHT RVP board drives camera 1.8v from an
137-
* external regulator instead of the PMIC just like ECS E7 board, see the
138-
* comments above.
139-
*/
140-
enum { V1P8_GPIO_UNSET = -2, V1P8_GPIO_NONE = -1 };
141-
static int v1p8_gpio = V1P8_GPIO_UNSET;
142-
143128
static LIST_HEAD(vcm_devices);
144129
static DEFINE_MUTEX(vcm_lock);
145130

@@ -548,6 +533,23 @@ static struct gmin_subdev *gmin_subdev_add(struct v4l2_subdev *subdev)
548533
else
549534
dev_info(dev, "will handle gpio1 via ACPI\n");
550535

536+
/*
537+
* Those are used only when there is an external regulator apart
538+
* from the PMIC that would be providing power supply, like on the
539+
* two cases below:
540+
*
541+
* The ECS E7 board drives camera 2.8v from an external regulator
542+
* instead of the PMIC. There's a gmin_CamV2P8 config variable
543+
* that specifies the GPIO to handle this particular case,
544+
* but this needs a broader architecture for handling camera power.
545+
*
546+
* The CHT RVP board drives camera 1.8v from an* external regulator
547+
* instead of the PMIC just like ECS E7 board.
548+
*/
549+
550+
gs->v1p8_gpio = gmin_get_var_int(dev, true, "V1P8GPIO", -1);
551+
gs->v2p8_gpio = gmin_get_var_int(dev, true, "V2P8GPIO", -1);
552+
551553
/*
552554
* FIXME:
553555
*
@@ -830,26 +832,22 @@ static int gmin_v1p8_ctrl(struct v4l2_subdev *subdev, int on)
830832

831833
dev = &client->dev;
832834

833-
if (v1p8_gpio == V1P8_GPIO_UNSET) {
834-
v1p8_gpio = gmin_get_var_int(dev, true,
835-
"V1P8GPIO", V1P8_GPIO_NONE);
836-
if (v1p8_gpio != V1P8_GPIO_NONE) {
837-
pr_info("atomisp_gmin_platform: 1.8v power on GPIO %d\n",
838-
v1p8_gpio);
839-
ret = gpio_request(v1p8_gpio, "camera_v1p8_en");
840-
if (!ret)
841-
ret = gpio_direction_output(v1p8_gpio, 0);
842-
if (ret)
843-
pr_err("V1P8 GPIO initialization failed\n");
844-
}
835+
if (gs->v1p8_gpio >= 0) {
836+
pr_info("atomisp_gmin_platform: 1.8v power on GPIO %d\n",
837+
gs->v1p8_gpio);
838+
ret = gpio_request(gs->v1p8_gpio, "camera_v1p8_en");
839+
if (!ret)
840+
ret = gpio_direction_output(gs->v1p8_gpio, 0);
841+
if (ret)
842+
pr_err("V1P8 GPIO initialization failed\n");
845843
}
846844

847845
if (!gs || gs->v1p8_on == on)
848846
return 0;
849847
gs->v1p8_on = on;
850848

851-
if (v1p8_gpio >= 0)
852-
gpio_set_value(v1p8_gpio, on);
849+
if (gs->v1p8_gpio >= 0)
850+
gpio_set_value(gs->v1p8_gpio, on);
853851

854852
if (gs->v1p8_reg) {
855853
regulator_set_voltage(gs->v1p8_reg, 1800000, 1800000);
@@ -892,26 +890,22 @@ static int gmin_v2p8_ctrl(struct v4l2_subdev *subdev, int on)
892890

893891
dev = &client->dev;
894892

895-
if (v2p8_gpio == V2P8_GPIO_UNSET) {
896-
v2p8_gpio = gmin_get_var_int(dev, true,
897-
"V2P8GPIO", V2P8_GPIO_NONE);
898-
if (v2p8_gpio != V2P8_GPIO_NONE) {
899-
pr_info("atomisp_gmin_platform: 2.8v power on GPIO %d\n",
900-
v2p8_gpio);
901-
ret = gpio_request(v2p8_gpio, "camera_v2p8");
902-
if (!ret)
903-
ret = gpio_direction_output(v2p8_gpio, 0);
904-
if (ret)
905-
pr_err("V2P8 GPIO initialization failed\n");
906-
}
893+
if (gs->v2p8_gpio >= 0) {
894+
pr_info("atomisp_gmin_platform: 2.8v power on GPIO %d\n",
895+
gs->v2p8_gpio);
896+
ret = gpio_request(gs->v2p8_gpio, "camera_v2p8");
897+
if (!ret)
898+
ret = gpio_direction_output(gs->v2p8_gpio, 0);
899+
if (ret)
900+
pr_err("V2P8 GPIO initialization failed\n");
907901
}
908902

909903
if (!gs || gs->v2p8_on == on)
910904
return 0;
911905
gs->v2p8_on = on;
912906

913-
if (v2p8_gpio >= 0)
914-
gpio_set_value(v2p8_gpio, on);
907+
if (gs->v2p8_gpio >= 0)
908+
gpio_set_value(gs->v2p8_gpio, on);
915909

916910
if (gs->v2p8_reg) {
917911
regulator_set_voltage(gs->v2p8_reg, 2900000, 2900000);

0 commit comments

Comments
 (0)