From patchwork Fri Mar 14 10:12:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Wu X-Patchwork-Id: 3832161 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 266709F2BB for ; Fri, 14 Mar 2014 10:23:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4201D20295 for ; Fri, 14 Mar 2014 10:23:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5806C20204 for ; Fri, 14 Mar 2014 10:23:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753276AbaCNKWq (ORCPT ); Fri, 14 Mar 2014 06:22:46 -0400 Received: from nasmtp01.atmel.com ([192.199.1.245]:31691 "EHLO DVREDG01.corp.atmel.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752788AbaCNKWp (ORCPT ); Fri, 14 Mar 2014 06:22:45 -0400 X-Greylist: delayed 309 seconds by postgrey-1.27 at vger.kernel.org; Fri, 14 Mar 2014 06:22:45 EDT Received: from apsmtp01.atmel.com (10.168.254.30) by DVREDG01.corp.atmel.com (10.42.103.30) with Microsoft SMTP Server (TLS) id 14.2.347.0; Fri, 14 Mar 2014 04:17:27 -0600 Received: from shaarm01.corp.atmel.com (10.168.254.13) by apsmtp01.corp.atmel.com (10.168.254.30) with Microsoft SMTP Server id 14.2.347.0; Fri, 14 Mar 2014 18:24:47 +0800 From: Josh Wu To: CC: , , , Josh Wu Subject: [PATCH] [media] ov2640: add support for async device registration Date: Fri, 14 Mar 2014 18:12:31 +0800 Message-ID: <1394791952-12941-1-git-send-email-josh.wu@atmel.com> X-Mailer: git-send-email 1.7.9.5 MIME-Version: 1.0 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move the clock detection code to the beginning of the probe(). If we meet any error in the clock detecting, then defer the probe. Signed-off-by: Josh Wu --- drivers/media/i2c/soc_camera/ov2640.c | 43 +++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/drivers/media/i2c/soc_camera/ov2640.c b/drivers/media/i2c/soc_camera/ov2640.c index 6c6b1c3..fb9b6e9 100644 --- a/drivers/media/i2c/soc_camera/ov2640.c +++ b/drivers/media/i2c/soc_camera/ov2640.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -1069,6 +1070,7 @@ static int ov2640_probe(struct i2c_client *client, struct ov2640_priv *priv; struct soc_camera_subdev_desc *ssdd = soc_camera_i2c_to_desc(client); struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); + struct v4l2_clk *clk; int ret; if (!ssdd) { @@ -1083,13 +1085,20 @@ static int ov2640_probe(struct i2c_client *client, return -EIO; } + clk = v4l2_clk_get(&client->dev, "mclk"); + if (IS_ERR(clk)) + return -EPROBE_DEFER; + priv = devm_kzalloc(&client->dev, sizeof(struct ov2640_priv), GFP_KERNEL); if (!priv) { dev_err(&adapter->dev, "Failed to allocate memory for private data!\n"); - return -ENOMEM; + ret = -ENOMEM; + goto err_kzalloc; } + priv->clk = clk; + 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, @@ -1097,23 +1106,26 @@ 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_kzalloc; } 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) + goto err_probe; + + ret = v4l2_async_register_subdev(&priv->subdev); + if (ret) + goto err_probe; + + dev_info(&adapter->dev, "OV2640 Probed\n"); + return 0; + +err_probe: + v4l2_ctrl_handler_free(&priv->hdl); +err_kzalloc: + v4l2_clk_put(clk); return ret; } @@ -1122,6 +1134,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);