linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c-algo-bit: Add pre- and post-xfer hooks
@ 2010-03-13 16:47 Jean Delvare
       [not found] ` <20100313174757.4a9f40d7-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
  0 siblings, 1 reply; 2+ messages in thread
From: Jean Delvare @ 2010-03-13 16:47 UTC (permalink / raw)
  To: Linux I2C; +Cc: Alex Deucher, Michael Krufky

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.

Signed-off-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
Cc: Alex Deucher <alexdeucher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Michael Krufky <mkrufky-dJidKbW2IEtAfugRpC6u6w@public.gmane.org>
---
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(+)

--- linux-2.6.34-rc1.orig/drivers/i2c/algos/i2c-algo-bit.c	2010-03-13 16:26:30.000000000 +0100
+++ linux-2.6.34-rc1/drivers/i2c/algos/i2c-algo-bit.c	2010-03-13 16:41:05.000000000 +0100
@@ -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;
 }
 
--- linux-2.6.34-rc1.orig/include/linux/i2c-algo-bit.h	2010-03-13 16:26:30.000000000 +0100
+++ linux-2.6.34-rc1/include/linux/i2c-algo-bit.h	2010-03-13 17:23:03.000000000 +0100
@@ -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

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

* Re: [PATCH] i2c-algo-bit: Add pre- and post-xfer hooks
       [not found] ` <20100313174757.4a9f40d7-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
@ 2010-03-13 16:52   ` Alex Deucher
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Deucher @ 2010-03-13 16:52 UTC (permalink / raw)
  To: Jean Delvare; +Cc: Linux I2C, Michael Krufky

On Sat, Mar 13, 2010 at 11:47 AM, Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org> wrote:
> 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.
>
> Signed-off-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
> Cc: Alex Deucher <alexdeucher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> Cc: Michael Krufky <mkrufky-dJidKbW2IEtAfugRpC6u6w@public.gmane.org>
> ---
> 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

>
> 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(+)
>
> --- linux-2.6.34-rc1.orig/drivers/i2c/algos/i2c-algo-bit.c      2010-03-13 16:26:30.000000000 +0100
> +++ linux-2.6.34-rc1/drivers/i2c/algos/i2c-algo-bit.c   2010-03-13 16:41:05.000000000 +0100
> @@ -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;
>  }
>
> --- linux-2.6.34-rc1.orig/include/linux/i2c-algo-bit.h  2010-03-13 16:26:30.000000000 +0100
> +++ linux-2.6.34-rc1/include/linux/i2c-algo-bit.h       2010-03-13 17:23:03.000000000 +0100
> @@ -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
>

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

end of thread, other threads:[~2010-03-13 16:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-13 16:47 [PATCH] i2c-algo-bit: Add pre- and post-xfer hooks Jean Delvare
     [not found] ` <20100313174757.4a9f40d7-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-03-13 16:52   ` Alex Deucher

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