[media] adv7180: Add media controller support
authorLars-Peter Clausen <lars@metafoo.de>
Fri, 23 Jan 2015 15:52:26 +0000 (12:52 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Mon, 2 Feb 2015 13:45:35 +0000 (11:45 -0200)
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 <lars@metafoo.de>
Acked-by: Federico Vaga <federico.vaga@gmail.com>
Acked-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/i2c/Kconfig
drivers/media/i2c/adv7180.c
drivers/media/pci/sta2x11/Kconfig
drivers/media/platform/Kconfig

index 0828b6b28fa4126ef247a954fc19818495dae7e4..da58c9bb67c2d2c39094c8dff003aa742c502d76 100644 (file)
@@ -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.
 
index 44a2832d8d1175cb5d31d902e51fa14d2683e792..5193596b68ff815878d37c3b097bc0dade71fa74 100644 (file)
 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;
index f6f30abc088ba26e4ce547b7f2cf9bac12122be7..e03587b1af7141996595cda7005eb2c08fdc0bb4 100644 (file)
@@ -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
index 663f7580a5da7c42e7a4180b30b66aed63d9b8c8..d9b872b9285a3460579b62df17ad88a75e64ce26 100644 (file)
@@ -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