Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[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>

authored by

Steve Longerbeam and committed by
Mauro Carvalho Chehab
65d9e14a ce5d6290

+33 -1
+5
Documentation/devicetree/bindings/media/i2c/adv7180.txt
··· 15 15 "adi,adv7282" 16 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 23 Example: 19 24 20 25 i2c0@1c22000 {
+1 -1
drivers/media/i2c/Kconfig
··· 187 187 188 188 config VIDEO_ADV7180 189 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 191 ---help--- 192 192 Support for the Analog Devices ADV7180 video decoder. 193 193
+27
drivers/media/i2c/adv7180.c
··· 26 26 #include <linux/i2c.h> 27 27 #include <linux/slab.h> 28 28 #include <linux/of.h> 29 + #include <linux/gpio/consumer.h> 29 30 #include <linux/videodev2.h> 30 31 #include <media/v4l2-ioctl.h> 31 32 #include <media/v4l2-event.h> ··· 214 213 struct media_pad pad; 215 214 struct mutex mutex; /* mutual excl. when accessing chip */ 216 215 int irq; 216 + struct gpio_desc *pwdn_gpio; 217 217 v4l2_std_id curr_norm; 218 218 bool powered; 219 219 bool streaming; ··· 463 461 *norm = state->curr_norm; 464 462 465 463 return 0; 464 + } 465 + 466 + static void adv7180_set_power_pin(struct adv7180_state *state, bool on) 467 + { 468 + if (!state->pwdn_gpio) 469 + return; 470 + 471 + if (on) { 472 + gpiod_set_value_cansleep(state->pwdn_gpio, 0); 473 + usleep_range(5000, 10000); 474 + } else { 475 + gpiod_set_value_cansleep(state->pwdn_gpio, 1); 476 + } 466 477 } 467 478 468 479 static int adv7180_set_power(struct adv7180_state *state, bool on) ··· 1225 1210 1226 1211 mutex_lock(&state->mutex); 1227 1212 1213 + adv7180_set_power_pin(state, true); 1214 + 1228 1215 adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES); 1229 1216 usleep_range(5000, 10000); 1230 1217 ··· 1295 1278 state->client = client; 1296 1279 state->field = V4L2_FIELD_INTERLACED; 1297 1280 state->chip_info = (struct adv7180_chip_info *)id->driver_data; 1281 + 1282 + state->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "powerdown", 1283 + GPIOD_OUT_HIGH); 1284 + if (IS_ERR(state->pwdn_gpio)) { 1285 + ret = PTR_ERR(state->pwdn_gpio); 1286 + v4l_err(client, "request for power pin failed: %d\n", ret); 1287 + return ret; 1288 + } 1298 1289 1299 1290 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) { 1300 1291 state->csi_client = i2c_new_dummy(client->adapter, ··· 1394 1369 i2c_unregister_device(state->vpp_client); 1395 1370 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) 1396 1371 i2c_unregister_device(state->csi_client); 1372 + 1373 + adv7180_set_power_pin(state, false); 1397 1374 1398 1375 mutex_destroy(&state->mutex); 1399 1376