Linux on ARM based TI OMAP SoCs
 help / color / mirror / Atom feed
From: David Brownell <david-b@pacbell.net>
To: hvaibhav@ti.com
Cc: video4linux-list@redhat.com,
	davinci-linux-open-source-bounces@linux.davincidsp.com,
	linux-omap@vger.kernel.org, Brijesh Jadav <brijesh.j@ti.com>,
	Hardik Shah <hardik.shah@ti.com>, Manjunath Hadli <mrh@ti.com>,
	R Sivaraj <sivaraj@ti.com>,
	Karicheri Muralidharan <m-karicheri2@ti.com>
Subject: Re: [PATCH 2/2] TVP514x Driver with Review comments fixed
Date: Fri, 28 Nov 2008 08:26:42 -0800	[thread overview]
Message-ID: <200811280826.43017.david-b@pacbell.net> (raw)
In-Reply-To: <1227876228-16553-1-git-send-email-hvaibhav@ti.com>

On Friday 28 November 2008, hvaibhav@ti.com wrote:
> +static int tvp514x_read_reg(struct i2c_client *client, u8 reg, u8 *val)
> +{
> +       int err;
> +       struct i2c_msg msg[2];
> +       u8 data;
> +
> +       if (!client->adapter)
> +               return -ENODEV;
> +
> +       /* [MSG1] fill the register address data */
> +       data = reg;
> +       msg[0].addr = client->addr;
> +       msg[0].len = 1;
> +       msg[0].flags = 0;
> +       msg[0].buf = &data;
> +
> +       /* [MSG2] fill the data rx buffer */
> +       msg[1].addr = client->addr;
> +       msg[1].len = 1;         /* only 1 byte */
> +       msg[1].flags = I2C_M_RD;        /* Read the register values */
> +       msg[1].buf = val;
> +       err = i2c_transfer(client->adapter, msg, 2);

Better:

	err = i2c_smbus_read_byte_data(client, reg);
	if (err >= 0) {
		*val = err;
		err = 0;
	}
	return err;

Though maybe the calling convention should be simplified,
And of course, probe() should verify that the adapter can
support the SMBus byte_data operations.


> +       if (err >= 0)
> +               return 0;
> +
> +       v4l_dbg(1, debug, client,
> +               "read from device 0x%.2x, offset 0x%.2x error %d\n",
> +               client->addr, reg, err);
> +
> +       return err;
> +}
> +
> +/*
> + * Write a value to a register in an TVP5146/47 decoder device.
> + * Returns zero if successful, or non-zero otherwise.
> + */
> +static int tvp514x_write_reg(struct i2c_client *client, u8 reg, u8 val)
> +{
> +       int err;
> +       int retry = 0;
> +       struct i2c_msg msg[1];
> +       u8 data[2];
> +
> +       if (!client->adapter)
> +               return -ENODEV;
> +
> +again:
> +       data[0] = reg;          /* Register offset */
> +       data[1] = val;          /* Register value */
> +       msg->addr = client->addr;
> +       msg->len = 2;
> +       msg->flags = 0;         /* write operation */
> +       msg->buf = data;
> +
> +       err = i2c_transfer(client->adapter, msg, 1);
> +       if (err >= 0)
> +               return 0;

Likewise:

again:
	err = i2c_smbus_write_byte_data(client, reg, val);
	if (err == 0)
		return 0;
	/* else retry */

By the way, while I applaud actually *having* fault handling in
I2C driver code -- faults can happen, and pathetically few Linux
drivers tolerate them from I2C -- I'm curious why only the write
path handles them, not the read path.


> +
> +       v4l_dbg(1, debug, client,
> +               "wrote 0x%.2x to offset 0x%.2x error %d\n", val, reg, err);
> +       if (retry <= I2C_RETRY_COUNT) {
> +               v4l_warn(client, "retry ... %d\n", retry);
> +               retry++;
> +               schedule_timeout(msecs_to_jiffies(20));
> +               goto again;
> +       }
> +       return err;
> +}


--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2008-11-28 16:26 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-28 12:43 [PATCH 2/2] TVP514x Driver with Review comments fixed hvaibhav
2008-11-28 16:26 ` David Brownell [this message]
2008-11-28 16:33 ` David Brownell
2008-11-28 18:34   ` Hiremath, Vaibhav
2008-11-28 16:52 ` David Brownell
2008-11-28 18:51   ` Hiremath, Vaibhav
2008-11-28 19:50     ` David Brownell
2008-11-28 19:54       ` David Brownell
2008-12-02  5:39         ` Hiremath, Vaibhav
2008-12-02  6:38           ` David Brownell
2008-12-02  6:49             ` Hiremath, Vaibhav
2008-12-02  8:26               ` David Brownell
2008-12-02  8:34             ` David Brownell
2008-12-02  8:40               ` Hiremath, Vaibhav
     [not found] <hvaibhav@ti.com>
2008-11-26 17:05 ` hvaibhav
2008-11-26 17:48   ` Hans Verkuil

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=200811280826.43017.david-b@pacbell.net \
    --to=david-b@pacbell.net \
    --cc=brijesh.j@ti.com \
    --cc=davinci-linux-open-source-bounces@linux.davincidsp.com \
    --cc=hardik.shah@ti.com \
    --cc=hvaibhav@ti.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=m-karicheri2@ti.com \
    --cc=mrh@ti.com \
    --cc=sivaraj@ti.com \
    --cc=video4linux-list@redhat.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