linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] at24: extend driver to allow writing via i2c_smbus_write_byte_data
@ 2012-12-19 16:07 Christian Gmeiner
       [not found] ` <1355933229-25865-1-git-send-email-christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Christian Gmeiner @ 2012-12-19 16:07 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	c.gmeiner-qzos7lGCgFkk+I/owrrOrA
  Cc: Christian Gmeiner

I have a at24 EEPROM connected via i2c bus provided by ISCH i2c
bus driver. This bus driver does not support
I2C_FUNC_SMBUS_WRITE_I2C_BLOCK and so I was looking for a way
to be able to write the eeprom. This patch adds support for
I2C_SMBUS_BYTE_DATA writing via i2c_smbus_write_byte_data.
It is quite slow, but it works.

Signed-off-by: Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/misc/eeprom/at24.c | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index 2baeec5..723b411 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -56,6 +56,7 @@ struct at24_data {
 	struct at24_platform_data chip;
 	struct memory_accessor macc;
 	int use_smbus;
+	int use_smbuse_write;
 
 	/*
 	 * Lock protects against activities from other Linux tasks,
@@ -324,7 +325,7 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
 {
 	struct i2c_client *client;
 	struct i2c_msg msg;
-	ssize_t status;
+	ssize_t status = 0;
 	unsigned long timeout, write_time;
 	unsigned next_page;
 
@@ -365,9 +366,18 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
 	timeout = jiffies + msecs_to_jiffies(write_timeout);
 	do {
 		write_time = jiffies;
-		if (at24->use_smbus) {
-			status = i2c_smbus_write_i2c_block_data(client,
-					offset, count, buf);
+		if (at24->use_smbuse_write) {
+			switch (at24->use_smbuse_write) {
+			case I2C_SMBUS_I2C_BLOCK_DATA:
+				status = i2c_smbus_write_i2c_block_data(client,
+						offset, count, buf);
+				break;
+			case I2C_SMBUS_BYTE_DATA:
+				status = i2c_smbus_write_byte_data(client,
+						offset, buf[0]);
+				break;
+			}
+
 			if (status == 0)
 				status = count;
 		} else {
@@ -484,6 +494,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	struct at24_platform_data chip;
 	bool writable;
 	int use_smbus = 0;
+	int use_smbus_write = 0;
 	struct at24_data *at24;
 	int err;
 	unsigned i, num_addresses;
@@ -547,6 +558,18 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		}
 	}
 
+	/* Use I2C operations unless we're stuck with SMBus extensions. */
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
+		if (!i2c_check_functionality(client->adapter,
+				I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
+			use_smbus_write = I2C_SMBUS_I2C_BLOCK_DATA;
+		} else if (i2c_check_functionality(client->adapter,
+				I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) {
+			use_smbus_write = I2C_SMBUS_BYTE_DATA;
+			chip.page_size = 1;
+		}
+	}
+
 	if (chip.flags & AT24_FLAG_TAKE8ADDR)
 		num_addresses = 8;
 	else
@@ -562,6 +585,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
 	mutex_init(&at24->lock);
 	at24->use_smbus = use_smbus;
+	at24->use_smbuse_write = use_smbus_write;
 	at24->chip = chip;
 	at24->num_addresses = num_addresses;
 
@@ -579,8 +603,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
 	writable = !(chip.flags & AT24_FLAG_READONLY);
 	if (writable) {
-		if (!use_smbus || i2c_check_functionality(client->adapter,
-				I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
+		if (!use_smbus || use_smbus_write) {
 
 			unsigned write_max = chip.page_size;
 
-- 
1.7.12.2.421.g261b511

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] at24: extend driver to allow writing via i2c_smbus_write_byte_data
       [not found] ` <1355933229-25865-1-git-send-email-christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2013-01-06 18:11   ` Christian Gmeiner
  2013-01-24 14:07   ` Wolfram Sang
  1 sibling, 0 replies; 12+ messages in thread
From: Christian Gmeiner @ 2013-01-06 18:11 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA, LKML, Christian Gmeiner
  Cc: Christian Gmeiner

ping
--
Christian Gmeiner, MSc


2012/12/19 Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:
> I have a at24 EEPROM connected via i2c bus provided by ISCH i2c
> bus driver. This bus driver does not support
> I2C_FUNC_SMBUS_WRITE_I2C_BLOCK and so I was looking for a way
> to be able to write the eeprom. This patch adds support for
> I2C_SMBUS_BYTE_DATA writing via i2c_smbus_write_byte_data.
> It is quite slow, but it works.
>
> Signed-off-by: Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
>  drivers/misc/eeprom/at24.c | 35 +++++++++++++++++++++++++++++------
>  1 file changed, 29 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
> index 2baeec5..723b411 100644
> --- a/drivers/misc/eeprom/at24.c
> +++ b/drivers/misc/eeprom/at24.c
> @@ -56,6 +56,7 @@ struct at24_data {
>         struct at24_platform_data chip;
>         struct memory_accessor macc;
>         int use_smbus;
> +       int use_smbuse_write;
>
>         /*
>          * Lock protects against activities from other Linux tasks,
> @@ -324,7 +325,7 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
>  {
>         struct i2c_client *client;
>         struct i2c_msg msg;
> -       ssize_t status;
> +       ssize_t status = 0;
>         unsigned long timeout, write_time;
>         unsigned next_page;
>
> @@ -365,9 +366,18 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
>         timeout = jiffies + msecs_to_jiffies(write_timeout);
>         do {
>                 write_time = jiffies;
> -               if (at24->use_smbus) {
> -                       status = i2c_smbus_write_i2c_block_data(client,
> -                                       offset, count, buf);
> +               if (at24->use_smbuse_write) {
> +                       switch (at24->use_smbuse_write) {
> +                       case I2C_SMBUS_I2C_BLOCK_DATA:
> +                               status = i2c_smbus_write_i2c_block_data(client,
> +                                               offset, count, buf);
> +                               break;
> +                       case I2C_SMBUS_BYTE_DATA:
> +                               status = i2c_smbus_write_byte_data(client,
> +                                               offset, buf[0]);
> +                               break;
> +                       }
> +
>                         if (status == 0)
>                                 status = count;
>                 } else {
> @@ -484,6 +494,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>         struct at24_platform_data chip;
>         bool writable;
>         int use_smbus = 0;
> +       int use_smbus_write = 0;
>         struct at24_data *at24;
>         int err;
>         unsigned i, num_addresses;
> @@ -547,6 +558,18 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>                 }
>         }
>
> +       /* Use I2C operations unless we're stuck with SMBus extensions. */
> +       if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
> +               if (!i2c_check_functionality(client->adapter,
> +                               I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
> +                       use_smbus_write = I2C_SMBUS_I2C_BLOCK_DATA;
> +               } else if (i2c_check_functionality(client->adapter,
> +                               I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) {
> +                       use_smbus_write = I2C_SMBUS_BYTE_DATA;
> +                       chip.page_size = 1;
> +               }
> +       }
> +
>         if (chip.flags & AT24_FLAG_TAKE8ADDR)
>                 num_addresses = 8;
>         else
> @@ -562,6 +585,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>
>         mutex_init(&at24->lock);
>         at24->use_smbus = use_smbus;
> +       at24->use_smbuse_write = use_smbus_write;
>         at24->chip = chip;
>         at24->num_addresses = num_addresses;
>
> @@ -579,8 +603,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>
>         writable = !(chip.flags & AT24_FLAG_READONLY);
>         if (writable) {
> -               if (!use_smbus || i2c_check_functionality(client->adapter,
> -                               I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
> +               if (!use_smbus || use_smbus_write) {
>
>                         unsigned write_max = chip.page_size;
>
> --
> 1.7.12.2.421.g261b511
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] at24: extend driver to allow writing via i2c_smbus_write_byte_data
       [not found] ` <1355933229-25865-1-git-send-email-christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2013-01-06 18:11   ` Christian Gmeiner
@ 2013-01-24 14:07   ` Wolfram Sang
       [not found]     ` <20130124140746.GI12933-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
  1 sibling, 1 reply; 12+ messages in thread
From: Wolfram Sang @ 2013-01-24 14:07 UTC (permalink / raw)
  To: Christian Gmeiner
  Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA,
	c.gmeiner-qzos7lGCgFkk+I/owrrOrA

[-- Attachment #1: Type: text/plain, Size: 1266 bytes --]

On Wed, Dec 19, 2012 at 05:07:09PM +0100, Christian Gmeiner wrote:
> I have a at24 EEPROM connected via i2c bus provided by ISCH i2c
> bus driver. This bus driver does not support
> I2C_FUNC_SMBUS_WRITE_I2C_BLOCK and so I was looking for a way
> to be able to write the eeprom. This patch adds support for
> I2C_SMBUS_BYTE_DATA writing via i2c_smbus_write_byte_data.
> It is quite slow, but it works.
> 
> Signed-off-by: Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
>  drivers/misc/eeprom/at24.c | 35 +++++++++++++++++++++++++++++------
>  1 file changed, 29 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
> index 2baeec5..723b411 100644
> --- a/drivers/misc/eeprom/at24.c
> +++ b/drivers/misc/eeprom/at24.c
> @@ -56,6 +56,7 @@ struct at24_data {
>  	struct at24_platform_data chip;
>  	struct memory_accessor macc;
>  	int use_smbus;
> +	int use_smbuse_write;

Can't you use the same 'use_smbus' variable and do a similar switch-case
as in the read function?

Regards,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] at24: extend driver to allow writing via i2c_smbus_write_byte_data
       [not found]     ` <20130124140746.GI12933-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
@ 2013-03-27 12:27       ` Christian Gmeiner
       [not found]         ` <CAH9NwWeKFaZEWwK9Dio39pkVqcRUfVi=dxvoXT71csJLA13qzQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Christian Gmeiner @ 2013-03-27 12:27 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, LKML, Christian Gmeiner

2013/1/24 Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>:
> On Wed, Dec 19, 2012 at 05:07:09PM +0100, Christian Gmeiner wrote:
>> I have a at24 EEPROM connected via i2c bus provided by ISCH i2c
>> bus driver. This bus driver does not support
>> I2C_FUNC_SMBUS_WRITE_I2C_BLOCK and so I was looking for a way
>> to be able to write the eeprom. This patch adds support for
>> I2C_SMBUS_BYTE_DATA writing via i2c_smbus_write_byte_data.
>> It is quite slow, but it works.
>>
>> Signed-off-by: Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> ---
>>  drivers/misc/eeprom/at24.c | 35 +++++++++++++++++++++++++++++------
>>  1 file changed, 29 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
>> index 2baeec5..723b411 100644
>> --- a/drivers/misc/eeprom/at24.c
>> +++ b/drivers/misc/eeprom/at24.c
>> @@ -56,6 +56,7 @@ struct at24_data {
>>       struct at24_platform_data chip;
>>       struct memory_accessor macc;
>>       int use_smbus;
>> +     int use_smbuse_write;
>
> Can't you use the same 'use_smbus' variable and do a similar switch-case
> as in the read function?
>

Sorry for the really late answer.

I am not sure if there exits some i2c buses which have different
access methods for read and write.
E.g. I2C_FUNC_SMBUS_WRITE_I2C_BLOCK and I2C_FUNC_SMBUS_READ_BYTE_DATA

If there will never be such a combination then I can reuse the same
'use_smbus' variable.

--
Christian Gmeiner, MSc

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] at24: extend driver to allow writing via i2c_smbus_write_byte_data
       [not found]         ` <CAH9NwWeKFaZEWwK9Dio39pkVqcRUfVi=dxvoXT71csJLA13qzQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2013-04-08  6:56           ` Christian Gmeiner
       [not found]             ` <CAH9NwWcpXAD7Hm=+ateYXz2bHVbFmJGOH7sRsEh02eeYNyD36w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Christian Gmeiner @ 2013-04-08  6:56 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA, LKML, Christian Gmeiner

Using the new mail address of wolfram sang - got the following error:


Delivery to the following recipient failed permanently:

     w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org

Technical details of permanent failure:
Google tried to deliver your message, but it was rejected by the
server for the recipient domainpengutronix.de by mail.pengutronix.de.
[2001:6f8:1178:4:290:27ff:fe1d:cc33].

The error that the other server returned was:
550 Account closed - please contact info-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org instead


2013/3/27 Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:
> 2013/1/24 Wolfram Sang <w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>:
>> On Wed, Dec 19, 2012 at 05:07:09PM +0100, Christian Gmeiner wrote:
>>> I have a at24 EEPROM connected via i2c bus provided by ISCH i2c
>>> bus driver. This bus driver does not support
>>> I2C_FUNC_SMBUS_WRITE_I2C_BLOCK and so I was looking for a way
>>> to be able to write the eeprom. This patch adds support for
>>> I2C_SMBUS_BYTE_DATA writing via i2c_smbus_write_byte_data.
>>> It is quite slow, but it works.
>>>
>>> Signed-off-by: Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>>> ---
>>>  drivers/misc/eeprom/at24.c | 35 +++++++++++++++++++++++++++++------
>>>  1 file changed, 29 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
>>> index 2baeec5..723b411 100644
>>> --- a/drivers/misc/eeprom/at24.c
>>> +++ b/drivers/misc/eeprom/at24.c
>>> @@ -56,6 +56,7 @@ struct at24_data {
>>>       struct at24_platform_data chip;
>>>       struct memory_accessor macc;
>>>       int use_smbus;
>>> +     int use_smbuse_write;
>>
>> Can't you use the same 'use_smbus' variable and do a similar switch-case
>> as in the read function?
>>
>
> Sorry for the really late answer.
>
> I am not sure if there exits some i2c buses which have different
> access methods for read and write.
> E.g. I2C_FUNC_SMBUS_WRITE_I2C_BLOCK and I2C_FUNC_SMBUS_READ_BYTE_DATA
>
> If there will never be such a combination then I can reuse the same
> 'use_smbus' variable.
>

--
Christian Gmeiner, MSc

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] at24: extend driver to allow writing via i2c_smbus_write_byte_data
       [not found]             ` <CAH9NwWcpXAD7Hm=+ateYXz2bHVbFmJGOH7sRsEh02eeYNyD36w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2013-04-08  9:41               ` Robert Schwebel
  0 siblings, 0 replies; 12+ messages in thread
From: Robert Schwebel @ 2013-04-08  9:41 UTC (permalink / raw)
  To: Christian Gmeiner
  Cc: Wolfram Sang, linux-i2c-u79uwXL29TY76Z2rM5mHXA, LKML,
	Christian Gmeiner

Hi Christian,

On Mon, Apr 08, 2013 at 08:56:03AM +0200, Christian Gmeiner wrote:
> Using the new mail address of wolfram sang - got the following error:
> 
> 
> Delivery to the following recipient failed permanently:
> 
>      w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org
> 
> Technical details of permanent failure:
> Google tried to deliver your message, but it was rejected by the
> server for the recipient domainpengutronix.de by mail.pengutronix.de.
> [2001:6f8:1178:4:290:27ff:fe1d:cc33].
> 
> The error that the other server returned was:
> 550 Account closed - please contact info-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org instead

Using wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org is correct. Mainline is already up to date.

rsc <- info-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org
-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] at24: extend driver to allow writing via i2c_smbus_write_byte_data
@ 2014-10-09  9:07 Christian Gmeiner
       [not found] ` <1412845678-18933-1-git-send-email-christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 12+ messages in thread
From: Christian Gmeiner @ 2014-10-09  9:07 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA
  Cc: wsa-z923LK4zBo2bacvFa/9K2g, Christian Gmeiner

I have a at24 EEPROM connected via i2c bus provided by ISCH i2c
bus driver. This bus driver does not support
I2C_FUNC_SMBUS_WRITE_I2C_BLOCK and so I was looking for a way
to be able to write the eeprom. This patch adds support for
I2C_SMBUS_BYTE_DATA writing via i2c_smbus_write_byte_data.
It is quite slow, but it works.

Signed-off-by: Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/misc/eeprom/at24.c | 35 +++++++++++++++++++++++++++++------
 1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
index d87f77f..f51daac 100644
--- a/drivers/misc/eeprom/at24.c
+++ b/drivers/misc/eeprom/at24.c
@@ -56,6 +56,7 @@ struct at24_data {
 	struct at24_platform_data chip;
 	struct memory_accessor macc;
 	int use_smbus;
+	int use_smbuse_write;
 
 	/*
 	 * Lock protects against activities from other Linux tasks,
@@ -324,7 +325,7 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
 {
 	struct i2c_client *client;
 	struct i2c_msg msg;
-	ssize_t status;
+	ssize_t status = 0;
 	unsigned long timeout, write_time;
 	unsigned next_page;
 
@@ -365,9 +366,18 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
 	timeout = jiffies + msecs_to_jiffies(write_timeout);
 	do {
 		write_time = jiffies;
-		if (at24->use_smbus) {
-			status = i2c_smbus_write_i2c_block_data(client,
-					offset, count, buf);
+		if (at24->use_smbuse_write) {
+			switch (at24->use_smbuse_write) {
+			case I2C_SMBUS_I2C_BLOCK_DATA:
+				status = i2c_smbus_write_i2c_block_data(client,
+						offset, count, buf);
+				break;
+			case I2C_SMBUS_BYTE_DATA:
+				status = i2c_smbus_write_byte_data(client,
+						offset, buf[0]);
+				break;
+			}
+
 			if (status == 0)
 				status = count;
 		} else {
@@ -487,6 +497,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
 	struct at24_platform_data chip;
 	bool writable;
 	int use_smbus = 0;
+	int use_smbus_write = 0;
 	struct at24_data *at24;
 	int err;
 	unsigned i, num_addresses;
@@ -546,6 +557,18 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
 		}
 	}
 
+	/* Use I2C operations unless we're stuck with SMBus extensions. */
+	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
+		if (i2c_check_functionality(client->adapter,
+				I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
+			use_smbus_write = I2C_SMBUS_I2C_BLOCK_DATA;
+		} else if (i2c_check_functionality(client->adapter,
+				I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) {
+			use_smbus_write = I2C_SMBUS_BYTE_DATA;
+			chip.page_size = 1;
+		}
+	}
+
 	if (chip.flags & AT24_FLAG_TAKE8ADDR)
 		num_addresses = 8;
 	else
@@ -559,6 +582,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
 	mutex_init(&at24->lock);
 	at24->use_smbus = use_smbus;
+	at24->use_smbuse_write = use_smbus_write;
 	at24->chip = chip;
 	at24->num_addresses = num_addresses;
 
@@ -576,8 +600,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
 
 	writable = !(chip.flags & AT24_FLAG_READONLY);
 	if (writable) {
-		if (!use_smbus || i2c_check_functionality(client->adapter,
-				I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
+		if (!use_smbus || use_smbus_write) {
 
 			unsigned write_max = chip.page_size;
 
-- 
1.9.3

^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] at24: extend driver to allow writing via i2c_smbus_write_byte_data
       [not found] ` <1412845678-18933-1-git-send-email-christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2014-10-28 16:51   ` Christian Gmeiner
       [not found]     ` <CAH9NwWeJ2nwdWFL1u=cOrjEWYnp9jeyQ4_7OQtkD_1_4AYhdpA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  2014-11-13  0:16   ` Wolfram Sang
  1 sibling, 1 reply; 12+ messages in thread
From: Christian Gmeiner @ 2014-10-28 16:51 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA; +Cc: Wolfram Sang, Christian Gmeiner

ping
--
Christian Gmeiner, MSc

https://soundcloud.com/christian-gmeiner


2014-10-09 11:07 GMT+02:00 Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:
> I have a at24 EEPROM connected via i2c bus provided by ISCH i2c
> bus driver. This bus driver does not support
> I2C_FUNC_SMBUS_WRITE_I2C_BLOCK and so I was looking for a way
> to be able to write the eeprom. This patch adds support for
> I2C_SMBUS_BYTE_DATA writing via i2c_smbus_write_byte_data.
> It is quite slow, but it works.
>
> Signed-off-by: Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> ---
>  drivers/misc/eeprom/at24.c | 35 +++++++++++++++++++++++++++++------
>  1 file changed, 29 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
> index d87f77f..f51daac 100644
> --- a/drivers/misc/eeprom/at24.c
> +++ b/drivers/misc/eeprom/at24.c
> @@ -56,6 +56,7 @@ struct at24_data {
>         struct at24_platform_data chip;
>         struct memory_accessor macc;
>         int use_smbus;
> +       int use_smbuse_write;
>
>         /*
>          * Lock protects against activities from other Linux tasks,
> @@ -324,7 +325,7 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
>  {
>         struct i2c_client *client;
>         struct i2c_msg msg;
> -       ssize_t status;
> +       ssize_t status = 0;
>         unsigned long timeout, write_time;
>         unsigned next_page;
>
> @@ -365,9 +366,18 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
>         timeout = jiffies + msecs_to_jiffies(write_timeout);
>         do {
>                 write_time = jiffies;
> -               if (at24->use_smbus) {
> -                       status = i2c_smbus_write_i2c_block_data(client,
> -                                       offset, count, buf);
> +               if (at24->use_smbuse_write) {
> +                       switch (at24->use_smbuse_write) {
> +                       case I2C_SMBUS_I2C_BLOCK_DATA:
> +                               status = i2c_smbus_write_i2c_block_data(client,
> +                                               offset, count, buf);
> +                               break;
> +                       case I2C_SMBUS_BYTE_DATA:
> +                               status = i2c_smbus_write_byte_data(client,
> +                                               offset, buf[0]);
> +                               break;
> +                       }
> +
>                         if (status == 0)
>                                 status = count;
>                 } else {
> @@ -487,6 +497,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>         struct at24_platform_data chip;
>         bool writable;
>         int use_smbus = 0;
> +       int use_smbus_write = 0;
>         struct at24_data *at24;
>         int err;
>         unsigned i, num_addresses;
> @@ -546,6 +557,18 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>                 }
>         }
>
> +       /* Use I2C operations unless we're stuck with SMBus extensions. */
> +       if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
> +               if (i2c_check_functionality(client->adapter,
> +                               I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
> +                       use_smbus_write = I2C_SMBUS_I2C_BLOCK_DATA;
> +               } else if (i2c_check_functionality(client->adapter,
> +                               I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) {
> +                       use_smbus_write = I2C_SMBUS_BYTE_DATA;
> +                       chip.page_size = 1;
> +               }
> +       }
> +
>         if (chip.flags & AT24_FLAG_TAKE8ADDR)
>                 num_addresses = 8;
>         else
> @@ -559,6 +582,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>
>         mutex_init(&at24->lock);
>         at24->use_smbus = use_smbus;
> +       at24->use_smbuse_write = use_smbus_write;
>         at24->chip = chip;
>         at24->num_addresses = num_addresses;
>
> @@ -576,8 +600,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>
>         writable = !(chip.flags & AT24_FLAG_READONLY);
>         if (writable) {
> -               if (!use_smbus || i2c_check_functionality(client->adapter,
> -                               I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
> +               if (!use_smbus || use_smbus_write) {
>
>                         unsigned write_max = chip.page_size;
>
> --
> 1.9.3
>

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] at24: extend driver to allow writing via i2c_smbus_write_byte_data
       [not found]     ` <CAH9NwWeJ2nwdWFL1u=cOrjEWYnp9jeyQ4_7OQtkD_1_4AYhdpA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-11-10 11:43       ` Christian Gmeiner
  0 siblings, 0 replies; 12+ messages in thread
From: Christian Gmeiner @ 2014-11-10 11:43 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA; +Cc: Wolfram Sang, Christian Gmeiner

ping

2014-10-28 17:51 GMT+01:00 Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:
> ping
> --
> Christian Gmeiner, MSc
>
> https://soundcloud.com/christian-gmeiner
>
>
> 2014-10-09 11:07 GMT+02:00 Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:
>> I have a at24 EEPROM connected via i2c bus provided by ISCH i2c
>> bus driver. This bus driver does not support
>> I2C_FUNC_SMBUS_WRITE_I2C_BLOCK and so I was looking for a way
>> to be able to write the eeprom. This patch adds support for
>> I2C_SMBUS_BYTE_DATA writing via i2c_smbus_write_byte_data.
>> It is quite slow, but it works.
>>
>> Signed-off-by: Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>> ---
>>  drivers/misc/eeprom/at24.c | 35 +++++++++++++++++++++++++++++------
>>  1 file changed, 29 insertions(+), 6 deletions(-)
>>
>> diff --git a/drivers/misc/eeprom/at24.c b/drivers/misc/eeprom/at24.c
>> index d87f77f..f51daac 100644
>> --- a/drivers/misc/eeprom/at24.c
>> +++ b/drivers/misc/eeprom/at24.c
>> @@ -56,6 +56,7 @@ struct at24_data {
>>         struct at24_platform_data chip;
>>         struct memory_accessor macc;
>>         int use_smbus;
>> +       int use_smbuse_write;
>>
>>         /*
>>          * Lock protects against activities from other Linux tasks,
>> @@ -324,7 +325,7 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
>>  {
>>         struct i2c_client *client;
>>         struct i2c_msg msg;
>> -       ssize_t status;
>> +       ssize_t status = 0;
>>         unsigned long timeout, write_time;
>>         unsigned next_page;
>>
>> @@ -365,9 +366,18 @@ static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf,
>>         timeout = jiffies + msecs_to_jiffies(write_timeout);
>>         do {
>>                 write_time = jiffies;
>> -               if (at24->use_smbus) {
>> -                       status = i2c_smbus_write_i2c_block_data(client,
>> -                                       offset, count, buf);
>> +               if (at24->use_smbuse_write) {
>> +                       switch (at24->use_smbuse_write) {
>> +                       case I2C_SMBUS_I2C_BLOCK_DATA:
>> +                               status = i2c_smbus_write_i2c_block_data(client,
>> +                                               offset, count, buf);
>> +                               break;
>> +                       case I2C_SMBUS_BYTE_DATA:
>> +                               status = i2c_smbus_write_byte_data(client,
>> +                                               offset, buf[0]);
>> +                               break;
>> +                       }
>> +
>>                         if (status == 0)
>>                                 status = count;
>>                 } else {
>> @@ -487,6 +497,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>>         struct at24_platform_data chip;
>>         bool writable;
>>         int use_smbus = 0;
>> +       int use_smbus_write = 0;
>>         struct at24_data *at24;
>>         int err;
>>         unsigned i, num_addresses;
>> @@ -546,6 +557,18 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>>                 }
>>         }
>>
>> +       /* Use I2C operations unless we're stuck with SMBus extensions. */
>> +       if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
>> +               if (i2c_check_functionality(client->adapter,
>> +                               I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
>> +                       use_smbus_write = I2C_SMBUS_I2C_BLOCK_DATA;
>> +               } else if (i2c_check_functionality(client->adapter,
>> +                               I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) {
>> +                       use_smbus_write = I2C_SMBUS_BYTE_DATA;
>> +                       chip.page_size = 1;
>> +               }
>> +       }
>> +
>>         if (chip.flags & AT24_FLAG_TAKE8ADDR)
>>                 num_addresses = 8;
>>         else
>> @@ -559,6 +582,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>>
>>         mutex_init(&at24->lock);
>>         at24->use_smbus = use_smbus;
>> +       at24->use_smbuse_write = use_smbus_write;
>>         at24->chip = chip;
>>         at24->num_addresses = num_addresses;
>>
>> @@ -576,8 +600,7 @@ static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
>>
>>         writable = !(chip.flags & AT24_FLAG_READONLY);
>>         if (writable) {
>> -               if (!use_smbus || i2c_check_functionality(client->adapter,
>> -                               I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
>> +               if (!use_smbus || use_smbus_write) {
>>
>>                         unsigned write_max = chip.page_size;
>>
>> --
>> 1.9.3
>>

--
Christian Gmeiner, MSc

https://soundcloud.com/christian-gmeiner

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] at24: extend driver to allow writing via i2c_smbus_write_byte_data
       [not found] ` <1412845678-18933-1-git-send-email-christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2014-10-28 16:51   ` Christian Gmeiner
@ 2014-11-13  0:16   ` Wolfram Sang
  2014-11-13 17:42     ` Wolfram Sang
  1 sibling, 1 reply; 12+ messages in thread
From: Wolfram Sang @ 2014-11-13  0:16 UTC (permalink / raw)
  To: Christian Gmeiner; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 542 bytes --]

On Thu, Oct 09, 2014 at 11:07:58AM +0200, Christian Gmeiner wrote:
> I have a at24 EEPROM connected via i2c bus provided by ISCH i2c
> bus driver. This bus driver does not support
> I2C_FUNC_SMBUS_WRITE_I2C_BLOCK and so I was looking for a way
> to be able to write the eeprom. This patch adds support for
> I2C_SMBUS_BYTE_DATA writing via i2c_smbus_write_byte_data.
> It is quite slow, but it works.
> 
> Signed-off-by: Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

Applied to for-next, thanks!


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] at24: extend driver to allow writing via i2c_smbus_write_byte_data
  2014-11-13  0:16   ` Wolfram Sang
@ 2014-11-13 17:42     ` Wolfram Sang
  2014-11-17  7:40       ` Christian Gmeiner
  0 siblings, 1 reply; 12+ messages in thread
From: Wolfram Sang @ 2014-11-13 17:42 UTC (permalink / raw)
  To: Christian Gmeiner; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA

[-- Attachment #1: Type: text/plain, Size: 719 bytes --]

On Thu, Nov 13, 2014 at 01:16:28AM +0100, Wolfram Sang wrote:
> On Thu, Oct 09, 2014 at 11:07:58AM +0200, Christian Gmeiner wrote:
> > I have a at24 EEPROM connected via i2c bus provided by ISCH i2c
> > bus driver. This bus driver does not support
> > I2C_FUNC_SMBUS_WRITE_I2C_BLOCK and so I was looking for a way
> > to be able to write the eeprom. This patch adds support for
> > I2C_SMBUS_BYTE_DATA writing via i2c_smbus_write_byte_data.
> > It is quite slow, but it works.
> > 
> > Signed-off-by: Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> 
> Applied to for-next, thanks!

Since I haven't pushed out yet, I did
s/use_smbuse_write/use_smbus_write/g on the file.


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] at24: extend driver to allow writing via i2c_smbus_write_byte_data
  2014-11-13 17:42     ` Wolfram Sang
@ 2014-11-17  7:40       ` Christian Gmeiner
  0 siblings, 0 replies; 12+ messages in thread
From: Christian Gmeiner @ 2014-11-17  7:40 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA

Hi Wolfram

Thanks a lot!

2014-11-13 18:42 GMT+01:00 Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>:
> On Thu, Nov 13, 2014 at 01:16:28AM +0100, Wolfram Sang wrote:
>> On Thu, Oct 09, 2014 at 11:07:58AM +0200, Christian Gmeiner wrote:
>> > I have a at24 EEPROM connected via i2c bus provided by ISCH i2c
>> > bus driver. This bus driver does not support
>> > I2C_FUNC_SMBUS_WRITE_I2C_BLOCK and so I was looking for a way
>> > to be able to write the eeprom. This patch adds support for
>> > I2C_SMBUS_BYTE_DATA writing via i2c_smbus_write_byte_data.
>> > It is quite slow, but it works.
>> >
>> > Signed-off-by: Christian Gmeiner <christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
>>
>> Applied to for-next, thanks!
>
> Since I haven't pushed out yet, I did
> s/use_smbuse_write/use_smbus_write/g on the file.
>
--
Christian Gmeiner, MSc

https://soundcloud.com/christian-gmeiner

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2014-11-17  7:40 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-19 16:07 [PATCH] at24: extend driver to allow writing via i2c_smbus_write_byte_data Christian Gmeiner
     [not found] ` <1355933229-25865-1-git-send-email-christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2013-01-06 18:11   ` Christian Gmeiner
2013-01-24 14:07   ` Wolfram Sang
     [not found]     ` <20130124140746.GI12933-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org>
2013-03-27 12:27       ` Christian Gmeiner
     [not found]         ` <CAH9NwWeKFaZEWwK9Dio39pkVqcRUfVi=dxvoXT71csJLA13qzQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-04-08  6:56           ` Christian Gmeiner
     [not found]             ` <CAH9NwWcpXAD7Hm=+ateYXz2bHVbFmJGOH7sRsEh02eeYNyD36w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-04-08  9:41               ` Robert Schwebel
  -- strict thread matches above, loose matches on Subject: below --
2014-10-09  9:07 Christian Gmeiner
     [not found] ` <1412845678-18933-1-git-send-email-christian.gmeiner-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2014-10-28 16:51   ` Christian Gmeiner
     [not found]     ` <CAH9NwWeJ2nwdWFL1u=cOrjEWYnp9jeyQ4_7OQtkD_1_4AYhdpA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-11-10 11:43       ` Christian Gmeiner
2014-11-13  0:16   ` Wolfram Sang
2014-11-13 17:42     ` Wolfram Sang
2014-11-17  7:40       ` Christian Gmeiner

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).