From: Josh Wu <josh.wu@atmel.com>
To: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: linux-media@vger.kernel.org, m.chehab@samsung.com,
linux-arm-kernel@lists.infradead.org, g.liakhovetski@gmx.de,
devicetree@vger.kernel.org
Subject: Re: [PATCH 3/5] media: ov2640: add primary dt support
Date: Tue, 9 Dec 2014 11:10:01 +0800 [thread overview]
Message-ID: <54866809.7020402@atmel.com> (raw)
In-Reply-To: <13013762.Jqm1jQRnFM@avalon>
Hi, Laurent
On 12/9/2014 2:39 AM, Laurent Pinchart wrote:
> Hi Josh,
>
> Thank you for the patch.
>
> On Monday 08 December 2014 19:29:05 Josh Wu wrote:
>> Add device tree support for ov2640.
>>
>> Cc: devicetree@vger.kernel.org
>> Signed-off-by: Josh Wu <josh.wu@atmel.com>
>> ---
>> v1 -> v2:
>> 1. use gpiod APIs.
>> 2. change the gpio pin's name according to datasheet.
>> 3. reduce the delay for .reset() function.
>>
>> drivers/media/i2c/soc_camera/ov2640.c | 86 +++++++++++++++++++++++++++++---
>> 1 file changed, 80 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/media/i2c/soc_camera/ov2640.c
>> b/drivers/media/i2c/soc_camera/ov2640.c index 9ee910d..2a57979 100644
>> --- a/drivers/media/i2c/soc_camera/ov2640.c
>> +++ b/drivers/media/i2c/soc_camera/ov2640.c
>> @@ -18,6 +18,8 @@
>> #include <linux/i2c.h>
>> #include <linux/slab.h>
>> #include <linux/delay.h>
>> +#include <linux/gpio.h>
>> +#include <linux/of_gpio.h>
>> #include <linux/v4l2-mediabus.h>
>> #include <linux/videodev2.h>
>>
>> @@ -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;
>> + struct gpio_desc *resetb_gpio;
>> + struct gpio_desc *pwdn_gpio;
>> };
>>
>> /*
>> @@ -1047,6 +1053,61 @@ 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");
>> +
>> + if (priv->pwdn_gpio && !IS_ERR(priv->pwdn_gpio))
> No need to test for IS_ERR, as the probe function would have failed in that
> case.
right. I'll change it.
>
>> + gpiod_direction_output(priv->pwdn_gpio, !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 */
>> + if (priv->resetb_gpio && !IS_ERR(priv->resetb_gpio)) {
> Same here.
ditto.
>
>> + gpiod_direction_output(priv->resetb_gpio, 0);
> Given that your DT should specify the active low GPIO flag, and that the gpiod
> API inverts the value in that case, you should set the value to 1 here.
Thanks for the information. I'll fix it.
>
>> + usleep_range(3000, 5000);
>> + gpiod_direction_output(priv->resetb_gpio, 1);
> And to 0 here.
yes.
>
>> + }
>> +
>> + return 0;
>> +}
>> +
>> +static int ov2640_probe_dt(struct i2c_client *client,
>> + struct ov2640_priv *priv)
>> +{
>> + priv->resetb_gpio = devm_gpiod_get_optional(&client->dev, "resetb",
>> + GPIOD_OUT_HIGH);
>> + if (!priv->resetb_gpio)
>> + dev_warn(&client->dev, "resetb gpio not found!\n");
> No need to warn here, it's perfectly fine if the reset signal isn't connected
> to a GPIO.
I want to print some information if no GPIO is assigned. So I'd like use
dev_dbg() here.
What do you feel?
>
>> + else if (IS_ERR(priv->resetb_gpio))
>> + return -EINVAL;
>> +
>> + priv->pwdn_gpio = devm_gpiod_get_optional(&client->dev, "pwdn",
>> + GPIOD_OUT_HIGH);
>> + if (!priv->pwdn_gpio)
>> + dev_warn(&client->dev, "pwdn gpio not found!\n");
> Same here.
ditto.
>
>> + else if (IS_ERR(priv->pwdn_gpio))
>> + return -EINVAL;
>> +
>> + /* 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 +1119,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 +1132,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;
>> + }
> I would test for !client->dev.of_node and return the error, you could then get
> rid of the else and lower the indentation level for the call to
> ov2640_probe_dt().
Okay. I'll change it in next version.
Best Regards,
Josh Wu
>
>> + }
>> +
>> 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 +1190,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 = "ovti,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,
next prev parent reply other threads:[~2014-12-09 3:10 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1418038147-13221-1-git-send-email-josh.wu@atmel.com>
2014-12-08 11:29 ` [PATCH 3/5] media: ov2640: add primary dt support Josh Wu
2014-12-08 18:39 ` Laurent Pinchart
2014-12-09 3:10 ` Josh Wu [this message]
[not found] ` <54866809.7020402-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
2014-12-09 8:07 ` Laurent Pinchart
2014-12-08 11:29 ` [PATCH 4/5] media: ov2640: add a master clock for sensor Josh Wu
2014-12-08 15:10 ` Fabio Estevam
2014-12-09 3:03 ` Josh Wu
2014-12-08 11:29 ` [PATCH 5/5] media: ov2640: dt: add the device tree binding document Josh Wu
2014-12-08 18:59 ` Laurent Pinchart
2014-12-09 3:19 ` Josh Wu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54866809.7020402@atmel.com \
--to=josh.wu@atmel.com \
--cc=devicetree@vger.kernel.org \
--cc=g.liakhovetski@gmx.de \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-media@vger.kernel.org \
--cc=m.chehab@samsung.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).