]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
[media] media: ov2640: add async probe function
authorJosh Wu <josh.wu@atmel.com>
Mon, 2 Mar 2015 01:52:38 +0000 (22:52 -0300)
committerMauro Carvalho Chehab <mchehab@osg.samsung.com>
Thu, 2 Apr 2015 21:34:42 +0000 (18:34 -0300)
In async probe, there is a case that ov2640 is probed before the
host device which provided 'mclk'.
To support this async probe, we will get 'mclk' at first in the probe(),
if failed it will return -EPROBE_DEFER. That will let ov2640 wait for
the host device probed.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
drivers/media/i2c/soc_camera/ov2640.c

index 1fdce2f6f880bdbac3cd8d389f0b4c91cb7e333a..16adbccdfa6ce35ea04e12c948147c749ecd4ec6 100644 (file)
@@ -1068,6 +1068,10 @@ static int ov2640_probe(struct i2c_client *client,
                return -ENOMEM;
        }
 
+       priv->clk = v4l2_clk_get(&client->dev, "mclk");
+       if (IS_ERR(priv->clk))
+               return -EPROBE_DEFER;
+
        v4l2_i2c_subdev_init(&priv->subdev, client, &ov2640_subdev_ops);
        v4l2_ctrl_handler_init(&priv->hdl, 2);
        v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
@@ -1075,24 +1079,27 @@ static int ov2640_probe(struct i2c_client *client,
        v4l2_ctrl_new_std(&priv->hdl, &ov2640_ctrl_ops,
                        V4L2_CID_HFLIP, 0, 1, 1, 0);
        priv->subdev.ctrl_handler = &priv->hdl;
-       if (priv->hdl.error)
-               return priv->hdl.error;
-
-       priv->clk = v4l2_clk_get(&client->dev, "mclk");
-       if (IS_ERR(priv->clk)) {
-               ret = PTR_ERR(priv->clk);
-               goto eclkget;
+       if (priv->hdl.error) {
+               ret = priv->hdl.error;
+               goto err_clk;
        }
 
        ret = ov2640_video_probe(client);
-       if (ret) {
-               v4l2_clk_put(priv->clk);
-eclkget:
-               v4l2_ctrl_handler_free(&priv->hdl);
-       } else {
-               dev_info(&adapter->dev, "OV2640 Probed\n");
-       }
+       if (ret < 0)
+               goto err_videoprobe;
 
+       ret = v4l2_async_register_subdev(&priv->subdev);
+       if (ret < 0)
+               goto err_videoprobe;
+
+       dev_info(&adapter->dev, "OV2640 Probed\n");
+
+       return 0;
+
+err_videoprobe:
+       v4l2_ctrl_handler_free(&priv->hdl);
+err_clk:
+       v4l2_clk_put(priv->clk);
        return ret;
 }
 
@@ -1100,6 +1107,7 @@ static int ov2640_remove(struct i2c_client *client)
 {
        struct ov2640_priv       *priv = to_ov2640(client);
 
+       v4l2_async_unregister_subdev(&priv->subdev);
        v4l2_clk_put(priv->clk);
        v4l2_device_unregister_subdev(&priv->subdev);
        v4l2_ctrl_handler_free(&priv->hdl);