* [PATCH] I2C Part 1 - Remove some redundancy from the i2c-core.c file
@ 2005-03-23 15:28 Corey Minyard
2005-03-23 21:44 ` Jean Delvare
0 siblings, 1 reply; 3+ messages in thread
From: Corey Minyard @ 2005-03-23 15:28 UTC (permalink / raw)
To: Greg KH, lkml, Sensors
[-- Attachment #1: Type: text/plain, Size: 208 bytes --]
This is a series of patches to add a non-blocking interface to the I2C
driver. Hopefully it is broken into small enough functional changes.
I'm not posting the whole series right now, just the first few.
[-- Attachment #2: i2c_remove_redundant_check.diff --]
[-- Type: text/x-patch, Size: 3065 bytes --]
Call i2c_transfer() from i2c_master_send() and i2c_master_recv()
to avoid the redundant code that was in all three functions.
This is important for the non-blocking interfaces because they
will have to handle a non-blocking interface in this area. Having
it in one place greatly simplifies the changes.
Signed-off-by: Corey Minyard <minyard@acm.org>
Index: linux-2.6.11-rc4/drivers/i2c/i2c-core.c
===================================================================
--- linux-2.6.11-rc4.orig/drivers/i2c/i2c-core.c
+++ linux-2.6.11-rc4/drivers/i2c/i2c-core.c
@@ -606,27 +606,20 @@
struct i2c_adapter *adap=client->adapter;
struct i2c_msg msg;
- if (client->adapter->algo->master_xfer) {
- msg.addr = client->addr;
- msg.flags = client->flags & I2C_M_TEN;
- msg.len = count;
- msg.buf = (char *)buf;
+ msg.addr = client->addr;
+ msg.flags = client->flags & I2C_M_TEN;
+ msg.len = count;
+ msg.buf = (char *)buf;
- dev_dbg(&client->adapter->dev, "master_send: writing %d bytes.\n",
- count);
-
- down(&adap->bus_lock);
- ret = adap->algo->master_xfer(adap,&msg,1);
- up(&adap->bus_lock);
+ dev_dbg(&client->adapter->dev, "master_send: writing %d bytes.\n",
+ count);
- /* if everything went ok (i.e. 1 msg transmitted), return #bytes
- * transmitted, else error code.
- */
- return (ret == 1 )? count : ret;
- } else {
- dev_err(&client->adapter->dev, "I2C level transfers not supported\n");
- return -ENOSYS;
- }
+ ret = i2c_transfer(adap, &msg, 1);
+
+ /* if everything went ok (i.e. 1 msg transmitted), return #bytes
+ * transmitted, else error code.
+ */
+ return (ret == 1 )? count : ret;
}
int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
@@ -634,31 +627,25 @@
struct i2c_adapter *adap=client->adapter;
struct i2c_msg msg;
int ret;
- if (client->adapter->algo->master_xfer) {
- msg.addr = client->addr;
- msg.flags = client->flags & I2C_M_TEN;
- msg.flags |= I2C_M_RD;
- msg.len = count;
- msg.buf = buf;
- dev_dbg(&client->adapter->dev, "master_recv: reading %d bytes.\n",
- count);
-
- down(&adap->bus_lock);
- ret = adap->algo->master_xfer(adap,&msg,1);
- up(&adap->bus_lock);
+ msg.addr = client->addr;
+ msg.flags = client->flags & I2C_M_TEN;
+ msg.flags |= I2C_M_RD;
+ msg.len = count;
+ msg.buf = buf;
+
+ dev_dbg(&client->adapter->dev, "master_recv: reading %d bytes.\n",
+ count);
- dev_dbg(&client->adapter->dev, "master_recv: return:%d (count:%d, addr:0x%02x)\n",
- ret, count, client->addr);
+ ret = i2c_transfer(adap, &msg, 1);
+
+ dev_dbg(&client->adapter->dev, "master_recv: return:%d (count:%d, addr:0x%02x)\n",
+ ret, count, client->addr);
- /* if everything went ok (i.e. 1 msg transmitted), return #bytes
- * transmitted, else error code.
- */
- return (ret == 1 )? count : ret;
- } else {
- dev_err(&client->adapter->dev, "I2C level transfers not supported\n");
- return -ENOSYS;
- }
+ /* if everything went ok (i.e. 1 msg transmitted), return #bytes
+ * transmitted, else error code.
+ */
+ return (ret == 1 )? count : ret;
}
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] I2C Part 1 - Remove some redundancy from the i2c-core.c file
2005-03-23 15:28 [PATCH] I2C Part 1 - Remove some redundancy from the i2c-core.c file Corey Minyard
@ 2005-03-23 21:44 ` Jean Delvare
2005-03-31 22:03 ` Corey Minyard
0 siblings, 1 reply; 3+ messages in thread
From: Jean Delvare @ 2005-03-23 21:44 UTC (permalink / raw)
To: Corey Minyard; +Cc: LKML, LM Sensors, Greg KH
Hi Corey,
> Call i2c_transfer() from i2c_master_send() and i2c_master_recv()
> to avoid the redundant code that was in all three functions.
I like this. You're right, there is code duplication here, which we can
get rid of, so let's do so. I'd only have one comments about your patch:
You can get rid of the dev_dbg calls in i2c_master_send() and
i2c_master_recv() altogether IMHO. I recently updated i2c_transfer() to
make it more verbose in debug mode [1], so the debug messages in
i2c_master_send() and i2c_master_recv() are mostly redundant now as far
as I can see.
[1] http://archives.andrew.net.au/lm-sensors/msg29859.html
Thanks,
--
Jean Delvare
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] I2C Part 1 - Remove some redundancy from the i2c-core.c file
2005-03-23 21:44 ` Jean Delvare
@ 2005-03-31 22:03 ` Corey Minyard
0 siblings, 0 replies; 3+ messages in thread
From: Corey Minyard @ 2005-03-31 22:03 UTC (permalink / raw)
To: LM Sensors, LKML; +Cc: Greg KH
[-- Attachment #1: Type: text/plain, Size: 876 bytes --]
Ok, I have taken some time from suffering (packaging perl modules) to
get back to this.
Here's a new patch with the debug calls removed, as you requested.
Thanks,
-Corey
Jean Delvare wrote:
>Hi Corey,
>
>
>
>>Call i2c_transfer() from i2c_master_send() and i2c_master_recv()
>>to avoid the redundant code that was in all three functions.
>>
>>
>
>I like this. You're right, there is code duplication here, which we can
>get rid of, so let's do so. I'd only have one comments about your patch:
>
>You can get rid of the dev_dbg calls in i2c_master_send() and
>i2c_master_recv() altogether IMHO. I recently updated i2c_transfer() to
>make it more verbose in debug mode [1], so the debug messages in
>i2c_master_send() and i2c_master_recv() are mostly redundant now as far
>as I can see.
>
>[1] http://archives.andrew.net.au/lm-sensors/msg29859.html
>
>Thanks,
>
>
[-- Attachment #2: i2c_remove_redundant_check.diff --]
[-- Type: text/x-patch, Size: 2866 bytes --]
Call i2c_transfer() from i2c_master_send() and i2c_master_recv()
to avoid the redundant code that was in all three functions. It
also removes unnecessary debug statements as suggested by Jean
Delvare.
This is important for the non-blocking interfaces because they
will have to handle a non-blocking interface in this area. Having
it in one place greatly simplifies the changes.
Signed-off-by: Corey Minyard <minyard@acm.org>
Index: linux-2.6.12-rc1/drivers/i2c/i2c-core.c
===================================================================
--- linux-2.6.12-rc1.orig/drivers/i2c/i2c-core.c
+++ linux-2.6.12-rc1/drivers/i2c/i2c-core.c
@@ -612,27 +612,17 @@
struct i2c_adapter *adap=client->adapter;
struct i2c_msg msg;
- if (client->adapter->algo->master_xfer) {
- msg.addr = client->addr;
- msg.flags = client->flags & I2C_M_TEN;
- msg.len = count;
- msg.buf = (char *)buf;
+ msg.addr = client->addr;
+ msg.flags = client->flags & I2C_M_TEN;
+ msg.len = count;
+ msg.buf = (char *)buf;
- dev_dbg(&client->adapter->dev, "master_send: writing %d bytes.\n",
- count);
-
- down(&adap->bus_lock);
- ret = adap->algo->master_xfer(adap,&msg,1);
- up(&adap->bus_lock);
-
- /* if everything went ok (i.e. 1 msg transmitted), return #bytes
- * transmitted, else error code.
- */
- return (ret == 1 )? count : ret;
- } else {
- dev_err(&client->adapter->dev, "I2C level transfers not supported\n");
- return -ENOSYS;
- }
+ ret = i2c_transfer(adap, &msg, 1);
+
+ /* if everything went ok (i.e. 1 msg transmitted), return #bytes
+ * transmitted, else error code.
+ */
+ return (ret == 1 )? count : ret;
}
int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
@@ -640,31 +630,19 @@
struct i2c_adapter *adap=client->adapter;
struct i2c_msg msg;
int ret;
- if (client->adapter->algo->master_xfer) {
- msg.addr = client->addr;
- msg.flags = client->flags & I2C_M_TEN;
- msg.flags |= I2C_M_RD;
- msg.len = count;
- msg.buf = buf;
- dev_dbg(&client->adapter->dev, "master_recv: reading %d bytes.\n",
- count);
-
- down(&adap->bus_lock);
- ret = adap->algo->master_xfer(adap,&msg,1);
- up(&adap->bus_lock);
-
- dev_dbg(&client->adapter->dev, "master_recv: return:%d (count:%d, addr:0x%02x)\n",
- ret, count, client->addr);
-
- /* if everything went ok (i.e. 1 msg transmitted), return #bytes
- * transmitted, else error code.
- */
- return (ret == 1 )? count : ret;
- } else {
- dev_err(&client->adapter->dev, "I2C level transfers not supported\n");
- return -ENOSYS;
- }
+ msg.addr = client->addr;
+ msg.flags = client->flags & I2C_M_TEN;
+ msg.flags |= I2C_M_RD;
+ msg.len = count;
+ msg.buf = buf;
+
+ ret = i2c_transfer(adap, &msg, 1);
+
+ /* if everything went ok (i.e. 1 msg transmitted), return #bytes
+ * transmitted, else error code.
+ */
+ return (ret == 1 )? count : ret;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-03-31 22:04 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-03-23 15:28 [PATCH] I2C Part 1 - Remove some redundancy from the i2c-core.c file Corey Minyard
2005-03-23 21:44 ` Jean Delvare
2005-03-31 22:03 ` Corey Minyard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox