From: Pavel Machek <pavel-+ZI9xUNit7I@public.gmane.org>
To: Ramiro Oliveira
<Ramiro.Oliveira-HKixBCOQz3hWk0Htik3J/w@public.gmane.org>
Cc: linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
mark.rutland-5wv7dgnIgG8@public.gmane.org,
mchehab-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org,
geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org,
akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org,
kvalo-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org,
linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org,
hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org,
lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org,
robert.jarzmik-GANU6spQydw@public.gmane.org,
slongerbeam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
dheitmueller-eb9eJ82Ua7k9XoPSrs7Ehg@public.gmane.org,
pali.rohar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
CARLOS.PALMINHA-HKixBCOQz3hWk0Htik3J/w@public.gmane.org
Subject: Re: [PATCH v3 2/2] Add support for Omnivision OV5647
Date: Tue, 18 Oct 2016 20:31:33 +0200 [thread overview]
Message-ID: <20161018183133.GA26548@amd> (raw)
In-Reply-To: <17092ffede9eb8aff0d6a7f54ca771e81712b18e.1476286687.git.roliveir-HKixBCOQz3hWk0Htik3J/w@public.gmane.org>
[-- Attachment #1: Type: text/plain, Size: 4933 bytes --]
Hi!
> +/*
> + * A V4L2 driver for OmniVision OV5647 cameras.
> + *
> + * Based on Samsung S5K6AAFX SXGA 1/6" 1.3M CMOS Image Sensor driver
> + * Copyright (C) 2011 Sylwester Nawrocki <s.nawrocki-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>
> + *
> + * Based on Omnivision OV7670 Camera Driver
> + * Copyright (C) 2006-7 Jonathan Corbet <corbet-T1hC0tSOHrs@public.gmane.org>
> + *
> + * Copyright (C) 2016, Synopsys, Inc.
> + *
> + */
If you do copyrights, you should also specify license.
> +static bool debug;
> +module_param(debug, bool, 0644);
> +MODULE_PARM_DESC(debug, "Debug level (0-1)");
Please remove, we have generic infrastructure for debugging.
> +/*
> + * The ov5647 sits on i2c with ID 0x6c
> + */
> +#define OV5647_I2C_ADDR 0x6c
> +#define SENSOR_NAME "ov5647"
> +
> +#define OV5647_REG_CHIPID_H 0x300A
> +#define OV5647_REG_CHIPID_L 0x300B
> +
> +#define REG_TERM 0xfffe
> +#define VAL_TERM 0xfe
> +#define REG_DLY 0xffff
> +
> +/*define the voltage level of control signal*/
"/* ", " */".
> +#define CSI_STBY_ON 1
> +#define CSI_STBY_OFF 0
> +#define CSI_RST_ON 0
> +#define CSI_RST_OFF 1
> +#define CSI_PWR_ON 1
> +#define CSI_PWR_OFF 0
> +#define CSI_AF_PWR_ON 1
> +#define CSI_AF_PWR_OFF 0
...
> +enum power_seq_cmd {
> + CSI_SUBDEV_PWR_OFF = 0x00,
> + CSI_SUBDEV_PWR_ON = 0x01,
> +};
Pick one style for defines/enums?
> +struct regval_list {
> + uint16_t addr;
> + uint8_t data;
> +};
u8/u16?
> +/**
> +* @short I2C Write operation
> +* @param[in] i2c_client I2C client
> +* @param[in] reg register address
> +* @param[in] val value to write
> +* @return Error code
> +*/
" *"?
> +static int ov5647_write(struct v4l2_subdev *sd, uint16_t reg, uint8_t val)
> +{
> + int ret;
> + unsigned char data[3] = { reg >> 8, reg & 0xff, val};
" }".
> +static int ov5647_write_array(struct v4l2_subdev *subdev,
> + struct regval_list *regs, int array_size)
> +{
> + int i = 0;
> + int ret = 0;
> +
> + if (!regs)
> + return -EINVAL;
> +
> + while (i < array_size) {
> + if (regs->addr == REG_DLY)
> + mdelay(regs->data);
> + else
> + ret = ov5647_write(subdev, regs->addr, regs->data);
The "REG_DLY" is never used AFAICT? Remove?
> + if (ret == -EIO)
> + return ret;
> +
ov5647_write() can return errors other then EIO. Are they handled correctly?
> +/**
> + * @short Set SW standby
> + * @param[in] subdev v4l2 subdev
> + * @param[in] on_off standby on or off
> + * @return Error code
> + */
> +static int sensor_s_sw_stby(struct v4l2_subdev *subdev, int on_off)
> +{
> + int ret;
> + unsigned char rdval;
> +
> + ret = ov5647_read(subdev, 0x0100, &rdval);
> + if (ret != 0)
> + return ret;
> +
> + if (on_off == CSI_STBY_ON)
> + ret = ov5647_write(subdev, 0x0100, rdval&0xfe);
> +
> + else
> + ret = ov5647_write(subdev, 0x0100, rdval|0x01);
I'd get rid of CSI_STBY_ON, and convert arg to bool, as you don't
really handle other values. Plus, naming it "set_sw_standby()" would
make core slightly more readable. Also kill the empty line before
else.
> +/**
> +* @short Initialize sensor
> +* @param[in] subdev v4l2 subdev
> +* @param[in] val not used
> +* @return Error code
> +*/
> +static int __sensor_init(struct v4l2_subdev *subdev)
> +{
> + int ret;
> + uint8_t resetval;
> + unsigned char rdval;
u8 for both?
> + ov5647_read(subdev, 0x0100, &resetval);
> + if (!resetval&0x01) {
> + v4l2_dbg(1, debug, subdev,
> + "DEVICE WAS IN SOFTWARE STANDBY");
No shouting please? If it is important maybe it should have higher
priority?
> +static int sensor_power(struct v4l2_subdev *subdev, int on)
> +{
> + int ret;
> + struct ov5647 *ov5647 = to_state(subdev);
> +
> + ret = 0;
> + mutex_lock(&ov5647->lock);
> +
> + switch (on) {
> + case CSI_SUBDEV_PWR_OFF:
...
> + case CSI_SUBDEV_PWR_ON:
...
> + default:
> + return -EINVAL;
> + }
> +
> + mutex_unlock(&ov5647->lock);
I'd really convert this to bool. Note how it returns with lock held?
> +int ov5647_detect(struct v4l2_subdev *sd)
> +{
> + unsigned char v;
> + int ret;
> +
> + ret = sensor_power(sd, 1);
> + if (ret < 0)
> + return ret;
> + ret = ov5647_read(sd, OV5647_REG_CHIPID_H, &v);
> + if (ret < 0)
> + return ret;
> + if (v != 0x56) /* OV manuf. id. */
> + return -ENODEV;
> + ret = ov5647_read(sd, OV5647_REG_CHIPID_L, &v);
> + if (ret < 0)
> + return ret;
> + if (v != 0x47)
> + return -ENODEV;
I guess invalid chipid deserves a printk?
> +* Refer to Linux errors.
Useful?
> +/**
> +* @short of_device_id structure
> +*/
> +static const struct i2c_device_id ov5647_id[] = {
Umm. The comment looks useless and wrong.
Best regards,
Pavel
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]
next prev parent reply other threads:[~2016-10-18 18:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-12 16:02 [PATCH v3 0/2] OV5647 Sensor driver Ramiro Oliveira
2016-10-12 16:02 ` [PATCH v3 1/2] Add OV5647 device tree documentation Ramiro Oliveira
2016-10-18 13:14 ` Rob Herring
2016-10-18 13:38 ` Ramiro Oliveira
[not found] ` <cover.1476286687.git.roliveir-HKixBCOQz3hWk0Htik3J/w@public.gmane.org>
2016-10-12 16:02 ` [PATCH v3 2/2] Add support for Omnivision OV5647 Ramiro Oliveira
[not found] ` <17092ffede9eb8aff0d6a7f54ca771e81712b18e.1476286687.git.roliveir-HKixBCOQz3hWk0Htik3J/w@public.gmane.org>
2016-10-18 18:31 ` Pavel Machek [this message]
2016-10-19 11:12 ` Ramiro Oliveira
2016-10-19 11:15 ` Pavel Machek
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=20161018183133.GA26548@amd \
--to=pavel-+zi9xunit7i@public.gmane.org \
--cc=CARLOS.PALMINHA-HKixBCOQz3hWk0Htik3J/w@public.gmane.org \
--cc=Ramiro.Oliveira-HKixBCOQz3hWk0Htik3J/w@public.gmane.org \
--cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=dheitmueller-eb9eJ82Ua7k9XoPSrs7Ehg@public.gmane.org \
--cc=geert-Td1EMuHUCqxL1ZNQvxDV9g@public.gmane.org \
--cc=hverkuil-qWit8jRvyhVmR6Xm/wNWPw@public.gmane.org \
--cc=kvalo-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
--cc=lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org \
--cc=linux-0h96xk9xTtrk1uMJSBkQmQ@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-media-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=mchehab-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=pali.rohar-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=robert.jarzmik-GANU6spQydw@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=slongerbeam-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
/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).