diff options
author | Steve Longerbeam <slongerbeam@gmail.com> | 2016-07-19 20:03:32 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2016-08-24 08:43:40 -0400 |
commit | 65d9e14a659520c554feea8ef17ee3109bd67ebd (patch) | |
tree | f74c2cb3ccb07deccaf27f2c8e22a85a8b5c526d | |
parent | ce5d6290df665bc4931ad01c38bbd4431318eec3 (diff) |
[media] media: adv7180: add power pin control
Some targets control the ADV7180 power pin via a gpio, so add
optional support for "powerdown" pin control.
Signed-off-by: Steve Longerbeam <steve_longerbeam@mentor.com>
Tested-by: Tim Harvey <tharvey@gateworks.com>
Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
-rw-r--r-- | Documentation/devicetree/bindings/media/i2c/adv7180.txt | 5 | ||||
-rw-r--r-- | drivers/media/i2c/Kconfig | 2 | ||||
-rw-r--r-- | drivers/media/i2c/adv7180.c | 27 |
3 files changed, 33 insertions, 1 deletions
diff --git a/Documentation/devicetree/bindings/media/i2c/adv7180.txt b/Documentation/devicetree/bindings/media/i2c/adv7180.txt index 0d501154dfb2..4da486f96ff6 100644 --- a/Documentation/devicetree/bindings/media/i2c/adv7180.txt +++ b/Documentation/devicetree/bindings/media/i2c/adv7180.txt | |||
@@ -15,6 +15,11 @@ Required Properties : | |||
15 | "adi,adv7282" | 15 | "adi,adv7282" |
16 | "adi,adv7282-m" | 16 | "adi,adv7282-m" |
17 | 17 | ||
18 | Optional Properties : | ||
19 | - powerdown-gpios: reference to the GPIO connected to the powerdown pin, | ||
20 | if any. | ||
21 | |||
22 | |||
18 | Example: | 23 | Example: |
19 | 24 | ||
20 | i2c0@1c22000 { | 25 | i2c0@1c22000 { |
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index c4df15a43d61..92cc54401339 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig | |||
@@ -187,7 +187,7 @@ comment "Video decoders" | |||
187 | 187 | ||
188 | config VIDEO_ADV7180 | 188 | config VIDEO_ADV7180 |
189 | tristate "Analog Devices ADV7180 decoder" | 189 | tristate "Analog Devices ADV7180 decoder" |
190 | depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API | 190 | depends on GPIOLIB && VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API |
191 | ---help--- | 191 | ---help--- |
192 | Support for the Analog Devices ADV7180 video decoder. | 192 | Support for the Analog Devices ADV7180 video decoder. |
193 | 193 | ||
diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c index cb83ebbe5131..c367ad6f6327 100644 --- a/drivers/media/i2c/adv7180.c +++ b/drivers/media/i2c/adv7180.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/i2c.h> | 26 | #include <linux/i2c.h> |
27 | #include <linux/slab.h> | 27 | #include <linux/slab.h> |
28 | #include <linux/of.h> | 28 | #include <linux/of.h> |
29 | #include <linux/gpio/consumer.h> | ||
29 | #include <linux/videodev2.h> | 30 | #include <linux/videodev2.h> |
30 | #include <media/v4l2-ioctl.h> | 31 | #include <media/v4l2-ioctl.h> |
31 | #include <media/v4l2-event.h> | 32 | #include <media/v4l2-event.h> |
@@ -213,6 +214,7 @@ struct adv7180_state { | |||
213 | struct media_pad pad; | 214 | struct media_pad pad; |
214 | struct mutex mutex; /* mutual excl. when accessing chip */ | 215 | struct mutex mutex; /* mutual excl. when accessing chip */ |
215 | int irq; | 216 | int irq; |
217 | struct gpio_desc *pwdn_gpio; | ||
216 | v4l2_std_id curr_norm; | 218 | v4l2_std_id curr_norm; |
217 | bool powered; | 219 | bool powered; |
218 | bool streaming; | 220 | bool streaming; |
@@ -463,6 +465,19 @@ static int adv7180_g_std(struct v4l2_subdev *sd, v4l2_std_id *norm) | |||
463 | return 0; | 465 | return 0; |
464 | } | 466 | } |
465 | 467 | ||
468 | static void adv7180_set_power_pin(struct adv7180_state *state, bool on) | ||
469 | { | ||
470 | if (!state->pwdn_gpio) | ||
471 | return; | ||
472 | |||
473 | if (on) { | ||
474 | gpiod_set_value_cansleep(state->pwdn_gpio, 0); | ||
475 | usleep_range(5000, 10000); | ||
476 | } else { | ||
477 | gpiod_set_value_cansleep(state->pwdn_gpio, 1); | ||
478 | } | ||
479 | } | ||
480 | |||
466 | static int adv7180_set_power(struct adv7180_state *state, bool on) | 481 | static int adv7180_set_power(struct adv7180_state *state, bool on) |
467 | { | 482 | { |
468 | u8 val; | 483 | u8 val; |
@@ -1210,6 +1225,8 @@ static int init_device(struct adv7180_state *state) | |||
1210 | 1225 | ||
1211 | mutex_lock(&state->mutex); | 1226 | mutex_lock(&state->mutex); |
1212 | 1227 | ||
1228 | adv7180_set_power_pin(state, true); | ||
1229 | |||
1213 | adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES); | 1230 | adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES); |
1214 | usleep_range(5000, 10000); | 1231 | usleep_range(5000, 10000); |
1215 | 1232 | ||
@@ -1279,6 +1296,14 @@ static int adv7180_probe(struct i2c_client *client, | |||
1279 | state->field = V4L2_FIELD_INTERLACED; | 1296 | state->field = V4L2_FIELD_INTERLACED; |
1280 | state->chip_info = (struct adv7180_chip_info *)id->driver_data; | 1297 | state->chip_info = (struct adv7180_chip_info *)id->driver_data; |
1281 | 1298 | ||
1299 | state->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", | ||
1300 | GPIOD_OUT_HIGH); | ||
1301 | if (IS_ERR(state->pwdn_gpio)) { | ||
1302 | ret = PTR_ERR(state->pwdn_gpio); | ||
1303 | v4l_err(client, "request for power pin failed: %d\n", ret); | ||
1304 | return ret; | ||
1305 | } | ||
1306 | |||
1282 | if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) { | 1307 | if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) { |
1283 | state->csi_client = i2c_new_dummy(client->adapter, | 1308 | state->csi_client = i2c_new_dummy(client->adapter, |
1284 | ADV7180_DEFAULT_CSI_I2C_ADDR); | 1309 | ADV7180_DEFAULT_CSI_I2C_ADDR); |
@@ -1370,6 +1395,8 @@ static int adv7180_remove(struct i2c_client *client) | |||
1370 | if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) | 1395 | if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) |
1371 | i2c_unregister_device(state->csi_client); | 1396 | i2c_unregister_device(state->csi_client); |
1372 | 1397 | ||
1398 | adv7180_set_power_pin(state, false); | ||
1399 | |||
1373 | mutex_destroy(&state->mutex); | 1400 | mutex_destroy(&state->mutex); |
1374 | 1401 | ||
1375 | return 0; | 1402 | return 0; |