linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@cam.ac.uk>
To: Ben Gardner  <public-gardner.ben-Re5JQEeQqe8AvxtiuMwx3w@plane.gmane.org>
Cc: public-linux-i2c-u79uwXL29TY76Z2rM5mHXA@plane.gmane.org,
	public-linux-kernel-u79uwXL29TY76Z2rM5mHXA@plane.gmane.org
Subject: Re: [PATCH] rtc-isl1208: Use SMBus functions if I2C isn't available
Date: Wed, 26 Oct 2011 09:40:34 +0100	[thread overview]
Message-ID: <4EA7C782.205@cam.ac.uk> (raw)
In-Reply-To: <1319596228-23318-1-git-send-email-gardner.ben@gmail.com>



On 10/26/11 03:30, Ben Gardner wrote:
> The rtc-isl1208 driver currently depends on raw I2C functionality.
> This patch adds a fall-back to SMBus functions so that the driver can be 
> used on a SMBus-only platforms, such as i2c-isch.
> 
Perhaps a summary of how bad things would be if smbus were all that is used?
Afterall it is emulated on i2c buses if they don't support it directly.

> Signed-off-by: Ben Gardner <gardner.ben-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
>  drivers/rtc/rtc-isl1208.c |   68 +++++++++++++++++++++++++++++++-------------
>  1 files changed, 48 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/rtc/rtc-isl1208.c b/drivers/rtc/rtc-isl1208.c
> index ea10736..c553c7b 100644
> --- a/drivers/rtc/rtc-isl1208.c
> +++ b/drivers/rtc/rtc-isl1208.c
> @@ -66,20 +66,35 @@ static int
>  isl1208_i2c_read_regs(struct i2c_client *client, u8 reg, u8 buf[],
>  		      unsigned len)
>  {
> -	u8 reg_addr[1] = { reg };
> -	struct i2c_msg msgs[2] = {
> -		{client->addr, 0, sizeof(reg_addr), reg_addr}
> -		,
> -		{client->addr, I2C_M_RD, len, buf}
> -	};
>  	int ret;
>  
>  	BUG_ON(reg > ISL1208_REG_USR2);
>  	BUG_ON(reg + len > ISL1208_REG_USR2 + 1);
>  
> -	ret = i2c_transfer(client->adapter, msgs, 2);
> -	if (ret > 0)
> -		ret = 0;
It's a bit early in the morning, but at least at first glance I think
this is an i2c_smbus_i2c_read_block_data reimplementation?

> +	if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
> +		u8 reg_addr[1] = { reg };
> +		struct i2c_msg msgs[2] = {
> +			{client->addr, 0, sizeof(reg_addr), reg_addr}
> +			,
Odd spacing.
> +			{client->addr, I2C_M_RD, len, buf}
> +		};
> +
> +		ret = i2c_transfer(client->adapter, msgs, 2);
> +		if (ret > 0)
> +			ret = 0;
> +	} else {
> +		int idx;
> +		ret = i2c_smbus_read_byte_data(client, reg);
> +		if (ret < 0)
> +			return ret;
> +		buf[0] = ret;
> +		for (idx = 1; idx < len; idx++) {
> +			ret = i2c_smbus_read_byte(client);
> +			if (ret < 0)
> +				return ret;
> +			buf[idx] = ret;
> +		}
> +	}
>  	return ret;
>  }
>  
> @@ -88,21 +103,32 @@ static int
>  isl1208_i2c_set_regs(struct i2c_client *client, u8 reg, u8 const buf[],
>  		     unsigned len)
>  {
> -	u8 i2c_buf[ISL1208_REG_USR2 + 2];
> -	struct i2c_msg msgs[1] = {
> -		{client->addr, 0, len + 1, i2c_buf}
> -	};
> -	int ret;
> +	int ret = 0;
>  
>  	BUG_ON(reg > ISL1208_REG_USR2);
>  	BUG_ON(reg + len > ISL1208_REG_USR2 + 1);
>  
> -	i2c_buf[0] = reg;
> -	memcpy(&i2c_buf[1], &buf[0], len);
> +	if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
> +		u8 i2c_buf[ISL1208_REG_USR2 + 2];
> +		struct i2c_msg msgs[1] = {
> +			{client->addr, 0, len + 1, i2c_buf}
> +		};
> +
> +		i2c_buf[0] = reg;
> +		memcpy(&i2c_buf[1], &buf[0], len);
>  
> -	ret = i2c_transfer(client->adapter, msgs, 1);
> -	if (ret > 0)
> -		ret = 0;
> +		ret = i2c_transfer(client->adapter, msgs, 1);
> +		if (ret > 0)
> +			ret = 0;
> +	} else {
> +		int idx;
> +		for (idx = 0; idx < len; idx++) {
> +			ret = i2c_smbus_write_byte_data(client, reg + idx,
> +							buf[idx]);
> +			if (ret < 0)
> +				return ret;
> +		}
> +	}
>  	return ret;
>  }
>  
> @@ -622,7 +648,9 @@ isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id)
>  	int rc = 0;
>  	struct rtc_device *rtc;
>  
> -	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
> +	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C) &&
> +	    !i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE |
> +				     I2C_FUNC_SMBUS_BYTE_DATA))
>  		return -ENODEV;
>  
>  	if (isl1208_i2c_validate_client(client) < 0)



  reply	other threads:[~2011-10-26  8:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-26  2:30 [PATCH] rtc-isl1208: Use SMBus functions if I2C isn't available Ben Gardner
2011-10-26  8:40 ` Jonathan Cameron [this message]
2011-10-26 12:55   ` Ben Gardner

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=4EA7C782.205@cam.ac.uk \
    --to=jic23@cam.ac.uk \
    --cc=public-gardner.ben-Re5JQEeQqe8AvxtiuMwx3w@plane.gmane.org \
    --cc=public-linux-i2c-u79uwXL29TY76Z2rM5mHXA@plane.gmane.org \
    --cc=public-linux-kernel-u79uwXL29TY76Z2rM5mHXA@plane.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).