From patchwork Fri Nov 28 10:28:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josh Wu X-Patchwork-Id: 5402701 Return-Path: X-Original-To: patchwork-linux-arm@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 5A5DD9F47A for ; Fri, 28 Nov 2014 10:33:54 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6309620142 for ; Fri, 28 Nov 2014 10:33:53 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7B1B6200C6 for ; Fri, 28 Nov 2014 10:33:52 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XuIp4-0002CG-Bw; Fri, 28 Nov 2014 10:30:46 +0000 Received: from eusmtp01.atmel.com ([212.144.249.242]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XuIoX-0000dk-Qy for linux-arm-kernel@lists.infradead.org; Fri, 28 Nov 2014 10:30:15 +0000 Received: from apsmtp01.atmel.com (10.168.254.31) by eusmtp01.atmel.com (10.161.101.30) with Microsoft SMTP Server id 14.2.347.0; Fri, 28 Nov 2014 11:29:44 +0100 Received: from melon.corp.atmel.com (10.168.254.13) by apsmtp01.atmel.com (10.168.254.31) with Microsoft SMTP Server id 14.2.347.0; Fri, 28 Nov 2014 18:30:14 +0800 From: Josh Wu To: Subject: [PATCH 2/4] media: ov2640: add primary dt support Date: Fri, 28 Nov 2014 18:28:25 +0800 Message-ID: <1417170507-11172-3-git-send-email-josh.wu@atmel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1417170507-11172-1-git-send-email-josh.wu@atmel.com> References: <1417170507-11172-1-git-send-email-josh.wu@atmel.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141128_023014_306587_6D5A95BD X-CRM114-Status: GOOD ( 15.27 ) X-Spam-Score: -0.0 (/) Cc: devicetree@vger.kernel.org, Josh Wu , laurent.pinchart@ideasonboard.com, g.liakhovetski@gmx.de, linux-arm-kernel@lists.infradead.org, m.chehab@samsung.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 Add device tree support for ov2640. Cc: devicetree@vger.kernel.org Signed-off-by: Josh Wu --- drivers/media/i2c/soc_camera/ov2640.c | 95 ++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 6 deletions(-) diff --git a/drivers/media/i2c/soc_camera/ov2640.c b/drivers/media/i2c/soc_camera/ov2640.c index 9ee910d..6506126 100644 --- a/drivers/media/i2c/soc_camera/ov2640.c +++ b/drivers/media/i2c/soc_camera/ov2640.c @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include #include @@ -283,6 +285,10 @@ struct ov2640_priv { u32 cfmt_code; struct v4l2_clk *clk; const struct ov2640_win_size *win; + + struct soc_camera_subdev_desc ssdd_dt; + int reset_pin; + int pwr_down_pin; }; /* @@ -1047,6 +1053,70 @@ static struct v4l2_subdev_ops ov2640_subdev_ops = { .video = &ov2640_subdev_video_ops, }; +/* OF probe functions */ +static int ov2640_hw_power(struct device *dev, int on) +{ + struct i2c_client *client = to_i2c_client(dev); + struct ov2640_priv *priv = to_ov2640(client); + + dev_dbg(&client->dev, "%s: %s the camera\n", + __func__, on ? "ENABLE" : "DISABLE"); + + /* enable or disable the camera */ + gpio_direction_output(priv->pwr_down_pin, !on); + + return 0; +} + +static int ov2640_hw_reset(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct ov2640_priv *priv = to_ov2640(client); + + /* If enabled, give a reset impulse */ + gpio_direction_output(priv->reset_pin, 0); + msleep(20); + gpio_direction_output(priv->reset_pin, 1); + msleep(100); + + return 0; +} + +static int ov2640_probe_dt(struct i2c_client *client, + struct ov2640_priv *priv) +{ + struct device_node *np = client->dev.of_node; + int ret; + + priv->reset_pin = of_get_named_gpio(np, "reset-gpio", 0); + priv->pwr_down_pin = of_get_named_gpio(np, "power-down-gpio", 0); + if (!gpio_is_valid(priv->reset_pin) || + !gpio_is_valid(priv->pwr_down_pin)) + return -EINVAL; + + ret = devm_gpio_request(&client->dev, priv->pwr_down_pin, + "power-down-pin"); + if (ret < 0) { + dev_err(&client->dev, "request gpio pin %d failed\n", + priv->pwr_down_pin); + return ret; + } + + ret = devm_gpio_request(&client->dev, priv->reset_pin, "reset_pin"); + if (ret < 0) { + dev_err(&client->dev, "request gpio pin %d failed\n", + priv->reset_pin); + return ret; + } + + /* Initialize the soc_camera_subdev_desc */ + priv->ssdd_dt.power = ov2640_hw_power; + priv->ssdd_dt.reset = ov2640_hw_reset; + client->dev.platform_data = &priv->ssdd_dt; + + return 0; +} + /* * i2c_driver functions */ @@ -1058,12 +1128,6 @@ static int ov2640_probe(struct i2c_client *client, struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); int ret; - if (!ssdd) { - dev_err(&adapter->dev, - "OV2640: Missing platform_data for driver\n"); - return -EINVAL; - } - if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { dev_err(&adapter->dev, "OV2640: I2C-Adapter doesn't support SMBUS\n"); @@ -1077,6 +1141,18 @@ static int ov2640_probe(struct i2c_client *client, return -ENOMEM; } + if (!ssdd) { + if (client->dev.of_node) { + ret = ov2640_probe_dt(client, priv); + if (ret) + return ret; + } else { + dev_err(&client->dev, + "Missing platform_data for driver\n"); + return -EINVAL; + } + } + 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, @@ -1123,9 +1199,16 @@ static const struct i2c_device_id ov2640_id[] = { }; MODULE_DEVICE_TABLE(i2c, ov2640_id); +static const struct of_device_id ov2640_of_match[] = { + {.compatible = "omnivision,ov2640", }, + {}, +}; +MODULE_DEVICE_TABLE(of, ov2640_of_match); + static struct i2c_driver ov2640_i2c_driver = { .driver = { .name = "ov2640", + .of_match_table = of_match_ptr(ov2640_of_match), }, .probe = ov2640_probe, .remove = ov2640_remove,