Skip to contentSkip to conversation

i2c-algo-bit: Add pre- and post-xfer hooks

PATCH In review Jean Delvare 2 participants 2 messages Mar 13, 2010 1 message not in the archive I2C subsystem host drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i2c-algo-bit: Add pre- and post-xfer hooks

Drivers might have to do random things before and/or after I2C transfers. Add hooks to the i2c-algo-bit implementation to let them do so.

Cc Alex Deucher <[email protected]>
Cc Michael Krufky <[email protected]>

---
Alex, compared to the first version I sent, I have removed the second parameter of the hooks. You did not use it, I'm not really sure why anybody would, and if one really needs the private data, it can be reached from the i2c_adapter struct itself. So I'd rather start simple, and add parameters only if a clear need appears over time. You'll have to update your patch to the radeon driver accordingly.

Michael, I seem to recall you wanted something like that a couple years ago?

 drivers/i2c/algos/i2c-algo-bit.c |    9 +++++++++
 include/linux/i2c-algo-bit.h     |    2 ++
 2 files changed, 11 insertions(+)
drivers/i2c/algos/i2c-algo-bit.c +9 -0
@@ -522,6 +522,12 @@ static int bit_xfer(struct i2c_adapter *
 	int i, ret;
 	unsigned short nak_ok;
 
+	if (adap->pre_xfer) {
+		ret = adap->pre_xfer(i2c_adap);
+		if (ret < 0)
+			return ret;
+	}
+
 	bit_dbg(3, &i2c_adap->dev, "emitting start condition\n");
 	i2c_start(adap);
 	for (i = 0; i < num; i++) {
@@ -570,6 +576,9 @@ static int bit_xfer(struct i2c_adapter *
 bailout:
 	bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n");
 	i2c_stop(adap);
+
+	if (adap->post_xfer)
+		adap->post_xfer(i2c_adap);
 	return ret;
 }
 
include/linux/i2c-algo-bit.h +2 -0
@@ -36,6 +36,8 @@ struct i2c_algo_bit_data {
 	void (*setscl) (void *data, int state);
 	int  (*getsda) (void *data);
 	int  (*getscl) (void *data);
+	int  (*pre_xfer)  (struct i2c_adapter *);
+	void (*post_xfer) (struct i2c_adapter *);
 
 	/* local settings */
 	int udelay;		/* half clock cycle time in us,
Signature · 1 line
Jean Delvare

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 7 lines · Jean Delvare

Drivers might have to do random things before and/or after I2C transfers. Add hooks to the i2c-algo-bit implementation to let them do so.

Cc Alex Deucher <[email protected]>
Cc Michael Krufky <[email protected]>
Quoted 7 lines

---
Alex, compared to the first version I sent, I have removed the second parameter of the hooks. You did not use it, I'm not really sure why anybody would, and if one really needs the private data, it can be reached from the i2c_adapter struct itself. So I'd rather start simple, and add parameters only if a clear need appears over time. You'll have to update your patch to the radeon driver accordingly.

No problem. I'll update my radeon patches next week.

Alex

Quoted 49 lines

Michael, I seem to recall you wanted something like that a couple years ago?

 drivers/i2c/algos/i2c-algo-bit.c |    9 +++++++++ include/linux/i2c-algo-bit.h     |    2 ++

 2 files changed, 11 insertions(+)
drivers/i2c/algos/i2c-algo-bit.c   2010-03-13 16:41:05.000000000 +0100 renamed from drivers/i2c/algos/i2c-algo-bit.c      2010-03-13 16:26:30.000000000 +0100 +6 -0
@@ -522,6 +522,12 @@ static int bit_xfer(struct i2c_adapter *
        int i, ret;
        unsigned short nak_ok;
 
+       if (adap->pre_xfer) {
+               ret = adap->pre_xfer(i2c_adap);
+               if (ret < 0)
+                       return ret;
+       }
+
        bit_dbg(3, &i2c_adap->dev, "emitting start condition\n");
        i2c_start(adap);
        for (i = 0; i < num; i++) {
@@ -570,6 +576,9 @@ static int bit_xfer(struct i2c_adapter *

 bailout:
       bit_dbg(3, &i2c_adap->dev, "emitting stop condition\n"); i2c_stop(adap);
+
+       if (adap->post_xfer)
+               adap->post_xfer(i2c_adap);
       return ret;
 }

include/linux/i2c-algo-bit.h       2010-03-13 17:23:03.000000000 +0100 renamed from include/linux/i2c-algo-bit.h  2010-03-13 16:26:30.000000000 +0100 +2 -1
@@ -36,6 +36,8 @@ struct i2c_algo_bit_data {
        void (*setscl) (void *data, int state);
        int  (*getsda) (void *data);
        int  (*getscl) (void *data);
+       int  (*pre_xfer)  (struct i2c_adapter *);
+       void (*post_xfer) (struct i2c_adapter *);
 
        /* local settings */
        int udelay;             /* half clock cycle time in us,
 
 
--

Jean Delvare