From d5d51a827bb86103d4874a864f72674b281408ac Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Fri, 23 Jan 2015 12:52:26 -0300 Subject: [PATCH] [media] adv7180: Add media controller support Add media controller support to the adv7180 driver by registering a media entity instance for it as well as implementing pad ops for configuring the format. As there currently don't seem to be any users of the video ops format operations those are removed as well in this patch. Also set the V4L2_SUBDEV_FL_HAS_DEVNODE flag for the subdevice so it is possible to create a subdevice device node. Since the driver now depends on VIDEO_V4L2_SUBDEV_API all drivers which select the driver need to depend on that symbol as well. Signed-off-by: Lars-Peter Clausen Acked-by: Federico Vaga Acked-by: Hans Verkuil Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/i2c/Kconfig | 2 +- drivers/media/i2c/adv7180.c | 50 ++++++++++++++++++++++++------- drivers/media/pci/sta2x11/Kconfig | 1 + drivers/media/platform/Kconfig | 2 +- 4 files changed, 43 insertions(+), 12 deletions(-) diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig index 0828b6b28fa4..da58c9bb67c2 100644 --- a/drivers/media/i2c/Kconfig +++ b/drivers/media/i2c/Kconfig @@ -177,7 +177,7 @@ comment "Video decoders" config VIDEO_ADV7180 tristate "Analog Devices ADV7180 decoder" - depends on VIDEO_V4L2 && I2C + depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API ---help--- Support for the Analog Devices ADV7180 video decoder. diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c index 44a2832d8d11..5193596b68ff 100644 --- a/drivers/media/i2c/adv7180.c +++ b/drivers/media/i2c/adv7180.c @@ -124,6 +124,7 @@ struct adv7180_state { struct v4l2_ctrl_handler ctrl_hdl; struct v4l2_subdev sd; + struct media_pad pad; struct mutex mutex; /* mutual excl. when accessing chip */ int irq; v4l2_std_id curr_norm; @@ -441,13 +442,14 @@ static void adv7180_exit_controls(struct adv7180_state *state) v4l2_ctrl_handler_free(&state->ctrl_hdl); } -static int adv7180_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned int index, - u32 *code) +static int adv7180_enum_mbus_code(struct v4l2_subdev *sd, + struct v4l2_subdev_fh *fh, + struct v4l2_subdev_mbus_code_enum *code) { - if (index > 0) + if (code->index != 0) return -EINVAL; - *code = MEDIA_BUS_FMT_YUYV8_2X8; + code->code = MEDIA_BUS_FMT_YUYV8_2X8; return 0; } @@ -466,6 +468,20 @@ static int adv7180_mbus_fmt(struct v4l2_subdev *sd, return 0; } +static int adv7180_get_pad_format(struct v4l2_subdev *sd, + struct v4l2_subdev_fh *fh, + struct v4l2_subdev_format *format) +{ + return adv7180_mbus_fmt(sd, &format->format); +} + +static int adv7180_set_pad_format(struct v4l2_subdev *sd, + struct v4l2_subdev_fh *fh, + struct v4l2_subdev_format *format) +{ + return adv7180_mbus_fmt(sd, &format->format); +} + static int adv7180_g_mbus_config(struct v4l2_subdev *sd, struct v4l2_mbus_config *cfg) { @@ -485,10 +501,6 @@ static const struct v4l2_subdev_video_ops adv7180_video_ops = { .querystd = adv7180_querystd, .g_input_status = adv7180_g_input_status, .s_routing = adv7180_s_routing, - .enum_mbus_fmt = adv7180_enum_mbus_fmt, - .try_mbus_fmt = adv7180_mbus_fmt, - .g_mbus_fmt = adv7180_mbus_fmt, - .s_mbus_fmt = adv7180_mbus_fmt, .g_mbus_config = adv7180_g_mbus_config, }; @@ -496,9 +508,16 @@ static const struct v4l2_subdev_core_ops adv7180_core_ops = { .s_power = adv7180_s_power, }; +static const struct v4l2_subdev_pad_ops adv7180_pad_ops = { + .enum_mbus_code = adv7180_enum_mbus_code, + .set_fmt = adv7180_set_pad_format, + .get_fmt = adv7180_get_pad_format, +}; + static const struct v4l2_subdev_ops adv7180_ops = { .core = &adv7180_core_ops, .video = &adv7180_video_ops, + .pad = &adv7180_pad_ops, }; static irqreturn_t adv7180_irq(int irq, void *devid) @@ -627,20 +646,28 @@ static int adv7180_probe(struct i2c_client *client, state->input = 0; sd = &state->sd; v4l2_i2c_subdev_init(sd, client, &adv7180_ops); + sd->flags = V4L2_SUBDEV_FL_HAS_DEVNODE; ret = adv7180_init_controls(state); if (ret) goto err_unreg_subdev; - ret = init_device(state); + + state->pad.flags = MEDIA_PAD_FL_SOURCE; + sd->entity.flags |= MEDIA_ENT_T_V4L2_SUBDEV_DECODER; + ret = media_entity_init(&sd->entity, 1, &state->pad, 0); if (ret) goto err_free_ctrl; + ret = init_device(state); + if (ret) + goto err_media_entity_cleanup; + if (state->irq) { ret = request_threaded_irq(client->irq, NULL, adv7180_irq, IRQF_ONESHOT | IRQF_TRIGGER_FALLING, KBUILD_MODNAME, state); if (ret) - goto err_free_ctrl; + goto err_media_entity_cleanup; } ret = v4l2_async_register_subdev(sd); @@ -652,6 +679,8 @@ static int adv7180_probe(struct i2c_client *client, err_free_irq: if (state->irq > 0) free_irq(client->irq, state); +err_media_entity_cleanup: + media_entity_cleanup(&sd->entity); err_free_ctrl: adv7180_exit_controls(state); err_unreg_subdev: @@ -669,6 +698,7 @@ static int adv7180_remove(struct i2c_client *client) if (state->irq > 0) free_irq(client->irq, state); + media_entity_cleanup(&sd->entity); adv7180_exit_controls(state); mutex_destroy(&state->mutex); return 0; diff --git a/drivers/media/pci/sta2x11/Kconfig b/drivers/media/pci/sta2x11/Kconfig index f6f30abc088b..e03587b1af71 100644 --- a/drivers/media/pci/sta2x11/Kconfig +++ b/drivers/media/pci/sta2x11/Kconfig @@ -5,6 +5,7 @@ config STA2X11_VIP select VIDEO_ADV7180 if MEDIA_SUBDRV_AUTOSELECT select VIDEOBUF2_DMA_CONTIG depends on PCI && VIDEO_V4L2 && VIRT_TO_BUS + depends on VIDEO_V4L2_SUBDEV_API depends on I2C help Say Y for support for STA2X11 VIP (Video Input Port) capture diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig index 663f7580a5da..d9b872b9285a 100644 --- a/drivers/media/platform/Kconfig +++ b/drivers/media/platform/Kconfig @@ -56,7 +56,7 @@ config VIDEO_VIU config VIDEO_TIMBERDALE tristate "Support for timberdale Video In/LogiWIN" - depends on VIDEO_V4L2 && I2C + depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API depends on (MFD_TIMBERDALE && TIMB_DMA) || COMPILE_TEST select VIDEO_ADV7180 select VIDEOBUF_DMA_CONTIG -- 2.30.2