linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Machek <pavel@ucw.cz>
To: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Cc: sakari.ailus@iki.fi, sre@kernel.org, pali.rohar@gmail.com,
	linux-media@vger.kernel.org
Subject: Re: [PATCH] [media]: Driver for Toshiba et8ek8 5MP sensor
Date: Tue, 24 May 2016 13:19:01 +0200	[thread overview]
Message-ID: <20160524111901.GB18307@amd> (raw)
In-Reply-To: <1462287004-21099-1-git-send-email-ivo.g.dimitrov.75@gmail.com>

Hi!

> The sensor is found in Nokia N900 main camera
> 
> Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>

> +/*
> + * A buffered write method that puts the wanted register write
> + * commands in a message list and passes the list to the i2c framework
> + */
> +static int et8ek8_i2c_buffered_write_regs(struct i2c_client *client,
> +					  const struct et8ek8_reg *wnext,
> +					  int cnt)
> +{
> +	/* FIXME: check how big cnt is */
> +	struct i2c_msg msg[cnt];
> +	unsigned char data[cnt][6];

Uff, no, variable length arrays in the kernel. No, I don't think that
should be done. Rather allocate maximum length here and then check its
> cnt?

> +/*
> + * Write a list of registers to i2c device.
> + *
> + * The list of registers is terminated by ET8EK8_REG_TERM.
> + * Returns zero if successful, or non-zero otherwise.
> + */
> +static int et8ek8_i2c_write_regs(struct i2c_client *client,
> +				 const struct et8ek8_reg reglist[])
> +{
> +	int r, cnt = 0;
> +	const struct et8ek8_reg *next, *wnext;
> +
> +	if (!client->adapter)
> +		return -ENODEV;
> +
> +	if (reglist == NULL)

(!reglist) ? :-). Actually, you can keep your preffered style there,
but maybe ammount of if (something that can not happen) return
... should be reduced. Noone should ever call this without valid
reglist or client->adapter, right?

> +		return -EINVAL;
> +
> +	/* Initialize list pointers to the start of the list */
> +	next = wnext = reglist;
> +
> +	do {
> +		/*
> +		 * We have to go through the list to figure out how
> +		 * many regular writes we have in a row
> +		 */
> +		while (next->type != ET8EK8_REG_TERM
> +		       && next->type != ET8EK8_REG_DELAY) {
> +			/*
> +			 * Here we check that the actual length fields
> +			 * are valid
> +			 */
> +			if (next->type != ET8EK8_REG_8BIT
> +			    &&  next->type != ET8EK8_REG_16BIT) {

Extra space after &&

> +				dev_err(&client->dev,
> +					"Invalid value on entry %d 0x%x\n",
> +					cnt, next->type);
> +				return -EINVAL;
> +			}

And maybe this could be just BUG_ON(). 

> +static struct et8ek8_reglist *et8ek8_reglist_find_mode_fmt(
> +		struct et8ek8_meta_reglist *meta,
> +		struct v4l2_mbus_framefmt *fmt)
> +{
> +	struct et8ek8_reglist **list = et8ek8_reglist_first(meta);
> +	struct et8ek8_reglist *best_match = NULL;
> +	struct et8ek8_reglist *best_other = NULL;
> +	struct v4l2_mbus_framefmt format;
> +	unsigned int max_dist_match = (unsigned int)-1;
> +	unsigned int max_dist_other = (unsigned int)-1;
> +
> +	/* Find the mode with the closest image size. The distance between
> +	 * image sizes is the size in pixels of the non-overlapping regions

You may want to run checkpatch. I guess it will complain. I doubt it
matters much :-).

> +	while (meta->reglist[nlists].ptr != NULL)
> +		nlists++;

...!= NULL) can be removed. ... here and in other places.

> +
> +	rval = et8ek8_i2c_write_reg(client, ET8EK8_REG_8BIT, 0x111B,
> +				    tp_mode << 4);
> +	if (rval)
> +		goto out;
> +
> +	rval = et8ek8_i2c_write_reg(client, ET8EK8_REG_8BIT, 0x1121,
> +				    cbh_mode << 7);
> +	if (rval)
> +		goto out;
> +
> +	rval = et8ek8_i2c_write_reg(client, ET8EK8_REG_8BIT, 0x1124,
> +				    cbv_mode << 7);
> +	if (rval)
> +		goto out;
> +
> +	rval = et8ek8_i2c_write_reg(client, ET8EK8_REG_8BIT, 0x112C, din_sw);
> +	if (rval)
> +		goto out;
> +
> +	rval = et8ek8_i2c_write_reg(client, ET8EK8_REG_8BIT, 0x1420, r1420);
> +	if (rval)
> +		goto out;
> +
> +out:
> +	return rval;
> +}

Goto out when all out does is return is a bit of overkill.

> +static int et8ek8_get_ctrl(struct v4l2_ctrl *ctrl)
> +{
> +	struct et8ek8_sensor *sensor =
> +		container_of(ctrl->handler, struct et8ek8_sensor, ctrl_handler);
> +	const struct et8ek8_mode *mode = &sensor->current_reglist->mode;
> +
> +	switch (ctrl->id) {
> +	case ET8EK8_CID_USER_FRAME_WIDTH:
> +		ctrl->cur.val = mode->width;
> +		break;
> +	case ET8EK8_CID_USER_FRAME_HEIGHT:
> +		ctrl->cur.val = mode->height;
> +		break;
> +	case ET8EK8_CID_USER_VISIBLE_WIDTH:
> +		ctrl->cur.val = mode->window_width;
> +		break;
> +	case ET8EK8_CID_USER_VISIBLE_HEIGHT:
> +		ctrl->cur.val = mode->window_height;
> +		break;
> +	case ET8EK8_CID_USER_SENSITIVITY:
> +		ctrl->cur.val = mode->sensitivity;
> +		break;
> +	}

default: return -EINVAL ?

> +	/*
> +	 * Calculate average pixel clock per line. Assume buffers can spread
> +	 * the data over horizontal blanking time. Rounding upwards.
> +	 * Formula taken from stock Nokia N900 kernel
> +	 */

"kernel."  ?

> +static int et8ek8_power_off(struct et8ek8_sensor *sensor)
> +{
> +	int rval;
> +
> +	gpiod_set_value(sensor->reset, 0);
> +	udelay(1);
> +
> +	clk_disable_unprepare(sensor->ext_clk);
> +
> +	rval = regulator_disable(sensor->vana);
> +	return rval;
> +}

get rid of rval, return directly?

> +	udelay(10); /* I wish this is a good value */

Me too ;-).

> +static int et8ek8_g_priv_mem(struct v4l2_subdev *subdev)
> +{
> +	struct et8ek8_sensor *sensor = to_et8ek8_sensor(subdev);
> +	struct i2c_client *client = v4l2_get_subdevdata(subdev);
> +	unsigned int length = ET8EK8_PRIV_MEM_SIZE;
> +	unsigned int offset = 0;
> +	u8 *ptr  = sensor->priv_mem;
> +	int rval = 0;
> +
> +	/* Read the EEPROM window-by-window, each window 8 bytes */
> +	do {
> +		u8 buffer[PRIV_MEM_WIN_SIZE];
> +		struct i2c_msg msg;
> +		int bytes, i;
> +		int ofs;
> +
> +		/* Set the current window */
> +		rval = et8ek8_i2c_write_reg(client, ET8EK8_REG_8BIT, 0x0001,
> +					    0xe0 | (offset >> 3));
> +		if (rval < 0)
> +			goto out;

out: only does return, cleaning it up here will help readability.

> +		/* Wait for status bit */
> +		for (i = 0; i < 1000; ++i) {
> +			u32 status;
> +
> +			rval = et8ek8_i2c_read_reg(client, ET8EK8_REG_8BIT,
> +						   0x0003, &status);
> +			if (rval < 0)
> +				goto out;
> +			if ((status & 0x08) == 0)
> +				break;
> +			usleep_range(1000, 2000);
> +		};
> +
> +		if (i == 1000) {
> +			rval = -EIO;
> +			goto out;
> +		}

Especially here.

> +		if (rval < 0)
> +			goto out;
> +		rval = 0;

And here.


> +#ifndef ET8EK8REGS_H
> +#define ET8EK8REGS_H
> +
> +#include <linux/i2c.h>
> +#include <linux/types.h>
> +#include <linux/videodev2.h>
> +#include <linux/v4l2-subdev.h>
> +
> +struct v4l2_mbus_framefmt;
> +struct v4l2_subdev_pad_mbus_code_enum;
> +
> +#define ET8EK8_MAGIC			0x531A0002
> +
> +struct et8ek8_mode {
> +	/* Physical sensor resolution and current image window */
> +	__u16 sensor_width;
> +	__u16 sensor_height;

Is this exported to userspace?

Thanks,
									Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

  parent reply	other threads:[~2016-05-24 11:19 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20160420081427.GZ32125@valkosipuli.retiisi.org.uk>
2016-04-24 21:08 ` [RFC PATCH 00/24] Make Nokia N900 cameras working Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 01/24] V4L fixes Ivaylo Dimitrov
2016-04-24 22:05     ` Pavel Machek
2016-04-25  7:29     ` Hans Verkuil
2016-04-25 13:25     ` Sakari Ailus
2016-04-25 16:32       ` Ivaylo Dimitrov
2016-04-29  7:41         ` Sakari Ailus
2016-04-24 21:08   ` [RFC PATCH 02/24] smiaregs: Generic i2c register writing Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 03/24] et8ek8: Toshiba 5MP sensor driver Ivaylo Dimitrov
2016-05-01 10:44     ` Sakari Ailus
2016-05-01 12:31       ` Ivaylo Dimitrov
2016-05-01 12:32         ` Ivaylo Dimitrov
2016-05-01 12:50       ` Ivaylo Dimitrov
2016-05-01 13:41         ` Sakari Ailus
2016-05-03 14:50           ` [PATCH] [media]: Driver for Toshiba et8ek8 5MP sensor Ivaylo Dimitrov
2016-05-22 10:07             ` Ivaylo Dimitrov
2016-05-24 11:19             ` Pavel Machek [this message]
2016-06-04 19:16               ` Ivaylo Dimitrov
2016-06-06  9:04               ` Sylwester Nawrocki
2016-05-25 21:45             ` Sakari Ailus
2016-06-04 19:54               ` Ivaylo Dimitrov
2016-06-09 23:13                 ` Sakari Ailus
2016-04-24 21:08   ` [RFC PATCH 04/24] smiapp-pll: Take existing divisor into account in minimum divisor check Ivaylo Dimitrov
2016-05-01 10:45     ` Sakari Ailus
2016-05-03 18:25       ` Ivaylo Dimitrov
2016-05-24  9:09       ` Pali Rohár
2016-05-24 10:17     ` Pavel Machek
2016-04-24 21:08   ` [RFC PATCH 05/24] smiapp: Add smiapp_has_quirk() to tell whether a quirk is implemented Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 06/24] smiapp: Add quirk control support Ivaylo Dimitrov
2016-05-01 10:46     ` Sakari Ailus
2016-05-03 18:32       ` Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 07/24] v4l: of: Call CSI2 bus csi2, not csi Ivaylo Dimitrov
2016-04-29 13:22     ` Pavel Machek
2016-04-24 21:08   ` [RFC PATCH 08/24] v4l: of: Obtain data bus type from bus-type property Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 09/24] v4l: Add CSI1 and CCP2 bus type to enum v4l2_mbus_type Ivaylo Dimitrov
2016-04-29 13:27     ` Pavel Machek
2016-04-24 21:08   ` [RFC PATCH 10/24] v4l: of: Separate lane parsing from CSI-2 bus parameter parsing Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 11/24] dt: bindings: v4l: Add bus-type video interface property Ivaylo Dimitrov
2016-04-29 13:28     ` Pavel Machek
2016-04-24 21:08   ` [RFC PATCH 12/24] dt: bindings: Add CSI1/CCP2 related properties to video-interfaces.txt Ivaylo Dimitrov
2016-04-29 13:39     ` Pavel Machek
2016-04-24 21:08   ` [RFC PATCH 13/24] v4l: of: Support CSI-1 and CCP2 busses Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 14/24] media: et8ek8: add device tree binding document Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 15/24] media: add subdev type for bus switch Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 16/24] media: video-bus-switch: new driver Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 17/24] smiapp: add CCP2 support Ivaylo Dimitrov
2016-05-01 10:57     ` Sakari Ailus
2016-04-24 21:08   ` [RFC PATCH 18/24] v4l2-async: per notifier locking Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 19/24] v4l2_device_register_subdev_nodes: allow calling multiple times Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 20/24] ARM: dts: omap3-n900: enable cameras Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 21/24] omap3isp: dt: Add support for CSI1/CCP2 busses Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 22/24] [media] omap3isp: Correctly set IO_OUT_SEL and VP_CLK_POL for CCP2 mode Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 23/24] [media] omap3isp: Make sure CSI1 interface is enabled in CPP2 mode Ivaylo Dimitrov
2016-04-24 21:08   ` [RFC PATCH 24/24] ARM: dts: omap3-n900: enable cameras - remove invalid entry Ivaylo Dimitrov
2016-04-24 21:55   ` [RFC PATCH 00/24] Make Nokia N900 cameras working Pavel Machek
2016-04-25  6:33     ` Ivaylo Dimitrov
2016-04-25 17:09       ` Pavel Machek
2016-04-25 17:21         ` Ivaylo Dimitrov
2016-04-27 21:07           ` Pavel Machek
2016-04-25 10:40   ` Pali Rohár
2016-04-25 14:06     ` Pavel Machek
2016-04-25 14:09       ` Hans Verkuil
2016-04-27 21:09         ` Pavel Machek
2016-04-25 14:14       ` Pali Rohár
2016-04-25 17:14         ` Pali Rohár
2016-04-25 16:58   ` Pavel Machek
2016-04-25 17:17     ` Ivaylo Dimitrov
2016-04-25 18:40       ` Pavel Machek
2016-04-25 19:17         ` Ivaylo Dimitrov
2016-04-25 20:41           ` Pavel Machek
2016-04-25 20:53             ` Ivaylo Dimitrov
2016-04-25 22:07               ` Pavel Machek
2016-04-26  4:21                 ` Ivaylo Dimitrov
2016-04-27  8:30                   ` Pavel Machek
2016-04-27  3:08   ` Sebastian Reichel
2016-04-27  5:05     ` Ivaylo Dimitrov
2016-04-27  6:57       ` Ivaylo Dimitrov
2016-04-27 16:42         ` Sebastian Reichel
2016-04-27 16:45           ` Pavel Machek
2016-04-27 16:59             ` Sebastian Reichel
2016-05-02  7:06               ` Pavel Machek
2016-04-27 17:12           ` Ивайло Димитров
2016-04-27 19:05             ` Pavel Machek
2016-04-29  0:05             ` Sebastian Reichel
2016-04-29 17:45               ` Sebastian Reichel
2016-04-29 18:44                 ` Ivaylo Dimitrov
2016-05-01 10:37                   ` Sakari Ailus
2016-05-01  9:03                 ` Pavel Machek
2016-04-27 20:30           ` Pavel Machek
2016-06-17 16:42     ` Nokia N900 cameras -- pipeline setup in python (was Re: [RFC PATCH 00/24] Make Nokia N900 cameras working) Pavel Machek
2016-06-17 17:12       ` Pavel Machek
2016-06-20 17:00         ` Pavel Machek
2016-06-20 20:59         ` Sakari Ailus
2016-06-21 18:05           ` Pavel Machek
2016-06-22  7:22             ` Sakari Ailus
2016-06-22 11:18           ` Pavel Machek
2016-07-01  7:31           ` square-only image on Nokia N900 camera " Pavel Machek
2016-07-01  8:50             ` Pavel Machek
2016-07-01 11:01               ` Pavel Machek
2016-07-01 19:40                 ` Pavel Machek
2016-06-24 16:21   ` [RFC PATCH 00/24] Make Nokia N900 cameras working Pavel Machek
2016-08-27 13:48   ` fcam-dev support for new kernels -- " 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=20160524111901.GB18307@amd \
    --to=pavel@ucw.cz \
    --cc=ivo.g.dimitrov.75@gmail.com \
    --cc=linux-media@vger.kernel.org \
    --cc=pali.rohar@gmail.com \
    --cc=sakari.ailus@iki.fi \
    --cc=sre@kernel.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).