linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
To: Alex Deucher <alexdeucher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: Using algo-bit in another i2c algo
Date: Wed, 10 Mar 2010 10:44:01 +0100	[thread overview]
Message-ID: <20100310104401.57fc43b2@hyperion.delvare> (raw)
In-Reply-To: <a728f9f91001111413t1a733e0rbc0352ddd2d9de7c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>

Hi Alex,

Sorry for the late answer.

On Mon, 11 Jan 2010 17:13:50 -0500, Alex Deucher wrote:
> Hi,
> 
>     I'm adding support for the i2c controllers on radeon hardware and
> I have a few questions.  I have a radeon-algo that encapsulates all
> the various hw i2c controller functionality, however, it uses a
> bit-algo bus internally for cases where you have to use bit-banging
> rather than the hardware i2c engines.  Also, for bit banging to work
> properly, you need to do some things before the bit-algo transaction
> (basically masking the gpios for software use).

There used to be a patch floating around that added pre- and post-xfer
hooks to i2c-algo-bit... I couldn't find it again, so I rewrote it:

From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
Subject: 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.

Signed-off-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
---
 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	2009-06-10 05:05:27.000000000 +0200
+++ linux-2.6.34-rc1/drivers/i2c/algos/i2c-algo-bit.c	2010-03-09 18:52:50.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, adap->data);
+		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, adap->data);
 	return ret;
 }
 
--- linux-2.6.34-rc1.orig/include/linux/i2c-algo-bit.h	2009-06-10 05:05:27.000000000 +0200
+++ linux-2.6.34-rc1/include/linux/i2c-algo-bit.h	2010-03-09 18:53:06.000000000 +0100
@@ -32,6 +32,8 @@
  */
 struct i2c_algo_bit_data {
 	void *data;		/* private data for lowlevel routines */
+	int  (*pre_xfer)  (struct i2c_adapter *i2c_adap, void *data);
+	void (*post_xfer) (struct i2c_adapter *i2c_adap, void *data);
 	void (*setsda) (void *data, int state);
 	void (*setscl) (void *data, int state);
 	int  (*getsda) (void *data);

Would it help?

> Right now we use
> bit-algo i2c for the ddc buses, but they won't work externally to the
> driver without the proper gpio masking prior to using them.  In the
> radeon-algo patches, I use bit algo internally when I cannot use the
> hardware i2c engines, or in cases where I haven't implemented support
> yet for the hardware engine (as most gpios can be driven by sw or the
> hw engine).  The problem is, this exposes the i2c bit-algo buses as
> well as the radeon-algo buses.

This is bad, as it defeats the slave address uniqueness mechanism. Bad
things could happen. Would the patch above be sufficient to solve your
case?

> Is there a way to not expose the bit-algo buses that are used
> internally?

No, this is not possible at the time being. That being said, it
shouldn't be difficult, if the need exists. Looking at i2c-algo-bit,
the registration part is split into a preparation step and the actual
registration with i2c-core. The preparation step if done by
i2c_bit_prepare_bus(). If we exported this function, then you could
easily call it to create an internal i2c-algo-bit-based adapter, which
you wouldn't have to register if you don't want to:

From: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
Subject: i2c-algo-bit: Export i2c_bit_prepare_bus

This lets drivers make use of the i2c-algo-bit implementation without
actually registering the i2c adapter in question. This is useful to
drivers which need more than the i2c-algo-bit driver offers.

Signed-off-by: Jean Delvare <khali-PUYAD+kWke1g9hUCZPvPmw@public.gmane.org>
---
 drivers/i2c/algos/i2c-algo-bit.c |    3 ++-
 include/linux/i2c-algo-bit.h     |    1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

--- linux-2.6.34-rc1.orig/drivers/i2c/algos/i2c-algo-bit.c	2010-03-10 08:09:03.000000000 +0100
+++ linux-2.6.34-rc1/drivers/i2c/algos/i2c-algo-bit.c	2010-03-10 10:23:51.000000000 +0100
@@ -601,7 +601,7 @@ static const struct i2c_algorithm i2c_bi
 /*
  * registering functions to load algorithms at runtime
  */
-static int i2c_bit_prepare_bus(struct i2c_adapter *adap)
+int i2c_bit_prepare_bus(struct i2c_adapter *adap)
 {
 	struct i2c_algo_bit_data *bit_adap = adap->algo_data;
 
@@ -617,6 +617,7 @@ static int i2c_bit_prepare_bus(struct i2
 
 	return 0;
 }
+EXPORT_SYMBOL(i2c_bit_prepare_bus);
 
 int i2c_bit_add_bus(struct i2c_adapter *adap)
 {
--- linux-2.6.34-rc1.orig/include/linux/i2c-algo-bit.h	2010-03-10 08:09:03.000000000 +0100
+++ linux-2.6.34-rc1/include/linux/i2c-algo-bit.h	2010-03-10 10:24:03.000000000 +0100
@@ -47,6 +47,7 @@ struct i2c_algo_bit_data {
 	int timeout;		/* in jiffies */
 };
 
+int i2c_bit_prepare_bus(struct i2c_adapter *);
 int i2c_bit_add_bus(struct i2c_adapter *);
 int i2c_bit_add_numbered_bus(struct i2c_adapter *);
 

With this possibility, I guess you wouldn't even need the first patch
any longer? If both are needed, that's fine with me, but if only one is
needed, that's even better.

> I've attached the patches for reference.

Please let me know if either or both of my 2 proposals above fit your
needs.

-- 
Jean Delvare

  parent reply	other threads:[~2010-03-10  9:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-11 22:13 Using algo-bit in another i2c algo Alex Deucher
     [not found] ` <a728f9f91001111413t1a733e0rbc0352ddd2d9de7c-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-03-10  9:44   ` Jean Delvare [this message]
     [not found]     ` <20100310104401.57fc43b2-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-03-10 16:58       ` Alex Deucher
2010-03-10 19:16       ` Alex Deucher
     [not found]         ` <a728f9f91003101116l422374d2vceb1e5dddfdf44d8-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-03-10 21:49           ` Jean Delvare
     [not found]             ` <20100310224936.0d4f8a65-ig7AzVSIIG7kN2dkZ6Wm7A@public.gmane.org>
2010-03-10 22:56               ` Alex Deucher
2010-03-10 20:47       ` Alex Deucher

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=20100310104401.57fc43b2@hyperion.delvare \
    --to=khali-puyad+kwke1g9huczpvpmw@public.gmane.org \
    --cc=alexdeucher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.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).