Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-23 Thread Jean Delvare
Lennart,

On Sun, 22 Apr 2007 11:41:51 -0400, Lennart Sorensen wrote:
> On Fri, Apr 20, 2007 at 07:49:33PM +0200, Jean Delvare wrote:
> > The scx200_acb driver was heavily modified in 2.6.17 and 2.6.18, not
> > much since then. I am not familiar with the hardware so I can't comment
> > on which chips are supposed to work and which aren't.
> 
> Well 2.6.18's scx200_acb works on the geode LX module I have, but no on
> the geode sc1200 module (where scx200_i2c does work).
> 
> scx200_acb doesn't detect any device that it can drive (nothing in dmesg
> at all when loaded) on the sc1200.

On the SCx200, the scx200_acb driver doesn't actually detect the
device. It uses arbitrary I/O addresses and hopes for the best. By
default, two buses are created, at 0x820 and 0x840. This might simply
not be the right addresses for your board. See
Documentation/i2c/busses/scx200_acb.

You should enable CONFIG_I2C_DEBUG_BUS and see what the driver says
when being loaded.

I seem to remember there has been a patch floating around to
auto-detect the right ports back in June 2006, but it seems to have
been lost somehow. Jordan, do you remember?

> I believe the main changes that
> happened to scx200_acb was adding support for the newer CS chipsets,
> such as the one used with the geode LX (which does work now).

Not only. There was also a log of bug fixing.

-- 
Jean Delvare
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-23 Thread Jean Delvare
Lennart,

On Sun, 22 Apr 2007 11:41:51 -0400, Lennart Sorensen wrote:
 On Fri, Apr 20, 2007 at 07:49:33PM +0200, Jean Delvare wrote:
  The scx200_acb driver was heavily modified in 2.6.17 and 2.6.18, not
  much since then. I am not familiar with the hardware so I can't comment
  on which chips are supposed to work and which aren't.
 
 Well 2.6.18's scx200_acb works on the geode LX module I have, but no on
 the geode sc1200 module (where scx200_i2c does work).
 
 scx200_acb doesn't detect any device that it can drive (nothing in dmesg
 at all when loaded) on the sc1200.

On the SCx200, the scx200_acb driver doesn't actually detect the
device. It uses arbitrary I/O addresses and hopes for the best. By
default, two buses are created, at 0x820 and 0x840. This might simply
not be the right addresses for your board. See
Documentation/i2c/busses/scx200_acb.

You should enable CONFIG_I2C_DEBUG_BUS and see what the driver says
when being loaded.

I seem to remember there has been a patch floating around to
auto-detect the right ports back in June 2006, but it seems to have
been lost somehow. Jordan, do you remember?

 I believe the main changes that
 happened to scx200_acb was adding support for the newer CS chipsets,
 such as the one used with the geode LX (which does work now).

Not only. There was also a log of bug fixing.

-- 
Jean Delvare
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-22 Thread Lennart Sorensen
On Fri, Apr 20, 2007 at 07:49:33PM +0200, Jean Delvare wrote:
> The scx200_acb driver was heavily modified in 2.6.17 and 2.6.18, not
> much since then. I am not familiar with the hardware so I can't comment
> on which chips are supposed to work and which aren't.

Well 2.6.18's scx200_acb works on the geode LX module I have, but no on
the geode sc1200 module (where scx200_i2c does work).

scx200_acb doesn't detect any device that it can drive (nothing in dmesg
at all when loaded) on the sc1200.  I believe the main changes that
happened to scx200_acb was adding support for the newer CS chipsets,
such as the one used with the geode LX (which does work now).

--
Len Sorensen
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-22 Thread Lennart Sorensen
On Fri, Apr 20, 2007 at 07:49:33PM +0200, Jean Delvare wrote:
 The scx200_acb driver was heavily modified in 2.6.17 and 2.6.18, not
 much since then. I am not familiar with the hardware so I can't comment
 on which chips are supposed to work and which aren't.

Well 2.6.18's scx200_acb works on the geode LX module I have, but no on
the geode sc1200 module (where scx200_i2c does work).

scx200_acb doesn't detect any device that it can drive (nothing in dmesg
at all when loaded) on the sc1200.  I believe the main changes that
happened to scx200_acb was adding support for the newer CS chipsets,
such as the one used with the geode LX (which does work now).

--
Len Sorensen
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-20 Thread Jean Delvare
Hi Lennart,

On Thu, 19 Apr 2007 16:59:42 -0400, Lennart Sorensen wrote:
> On Thu, Apr 19, 2007 at 08:54:13AM +0200, Jean Delvare wrote:
> > The major difference is that the implementation in scx200_i2c is
> > hardware-specific, while the i2c-gpio driver is a generic one, so it's
> > a lot better.
> > 
> > What this means is that i2c-gpio obsoletes scx200_i2c, so I am inclined
> > to delete scx200_i2c right away. I'm not even sure anyone still uses it
> > now that scx200_acb has been fixed and is reported to work very well.
> > If anyone really needs to do I2C over GPIO pins on SCx200, this should
> > be reimplemented on top of i2c-gpio.
> 
> I use scx200_i2c.  The SBC I am using doesn't work with the scx200_acb
> (different pins on the cpu after all).  I would love to see it
> reimplemented using the generic interface, since there isn't that many
> lines of code involved as far as I can tell.  Well scx200_acb works fine
> on a Geode LX board, but not on a Geode SC1200 board.  Unless it has
> been fixed since 2.6.18, then it still doesn't work, but scx200_i2c
> works perfectly fine.

The scx200_acb driver was heavily modified in 2.6.17 and 2.6.18, not
much since then. I am not familiar with the hardware so I can't comment
on which chips are supposed to work and which aren't.

-- 
Jean Delvare
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-20 Thread Jean Delvare
Hi Lennart,

On Thu, 19 Apr 2007 16:59:42 -0400, Lennart Sorensen wrote:
 On Thu, Apr 19, 2007 at 08:54:13AM +0200, Jean Delvare wrote:
  The major difference is that the implementation in scx200_i2c is
  hardware-specific, while the i2c-gpio driver is a generic one, so it's
  a lot better.
  
  What this means is that i2c-gpio obsoletes scx200_i2c, so I am inclined
  to delete scx200_i2c right away. I'm not even sure anyone still uses it
  now that scx200_acb has been fixed and is reported to work very well.
  If anyone really needs to do I2C over GPIO pins on SCx200, this should
  be reimplemented on top of i2c-gpio.
 
 I use scx200_i2c.  The SBC I am using doesn't work with the scx200_acb
 (different pins on the cpu after all).  I would love to see it
 reimplemented using the generic interface, since there isn't that many
 lines of code involved as far as I can tell.  Well scx200_acb works fine
 on a Geode LX board, but not on a Geode SC1200 board.  Unless it has
 been fixed since 2.6.18, then it still doesn't work, but scx200_i2c
 works perfectly fine.

The scx200_acb driver was heavily modified in 2.6.17 and 2.6.18, not
much since then. I am not familiar with the hardware so I can't comment
on which chips are supposed to work and which aren't.

-- 
Jean Delvare
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-19 Thread Lennart Sorensen
On Thu, Apr 19, 2007 at 08:54:13AM +0200, Jean Delvare wrote:
> The major difference is that the implementation in scx200_i2c is
> hardware-specific, while the i2c-gpio driver is a generic one, so it's
> a lot better.
> 
> What this means is that i2c-gpio obsoletes scx200_i2c, so I am inclined
> to delete scx200_i2c right away. I'm not even sure anyone still uses it
> now that scx200_acb has been fixed and is reported to work very well.
> If anyone really needs to do I2C over GPIO pins on SCx200, this should
> be reimplemented on top of i2c-gpio.

I use scx200_i2c.  The SBC I am using doesn't work with the scx200_acb
(different pins on the cpu after all).  I would love to see it
reimplemented using the generic interface, since there isn't that many
lines of code involved as far as I can tell.  Well scx200_acb works fine
on a Geode LX board, but not on a Geode SC1200 board.  Unless it has
been fixed since 2.6.18, then it still doesn't work, but scx200_i2c
works perfectly fine.

> It also looks to me like i2c-ixp2000 and i2c-ixp4xx are obsoleted by
> i2c-gpio. Deepak, can you please try using i2c-gpio instead and confirm
> that i2c-ixp2000 and i2c-ixp4xx can be deleted?

--
Len Sorensen
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-19 Thread Jean Delvare
Hi Len,

On Wed, 18 Apr 2007 13:42:56 -0400, Lennart Sorensen wrote:
> On Sat, Apr 14, 2007 at 07:28:07PM +0200, Jean Delvare wrote:
> > Otherwise it looks OK to me, I take the patch. If others have comments
> > or objections, just speak up and submit incremental patches as needed.
> > 
> > Now I would like to see platform code actually using this.
> 
> Any idea how similar this new driver is to the scx200_i2c driver?  As
> far as I can tell that driver is already a bit banged i2c over gpio
> lines.

The major difference is that the implementation in scx200_i2c is
hardware-specific, while the i2c-gpio driver is a generic one, so it's
a lot better.

What this means is that i2c-gpio obsoletes scx200_i2c, so I am inclined
to delete scx200_i2c right away. I'm not even sure anyone still uses it
now that scx200_acb has been fixed and is reported to work very well.
If anyone really needs to do I2C over GPIO pins on SCx200, this should
be reimplemented on top of i2c-gpio.

It also looks to me like i2c-ixp2000 and i2c-ixp4xx are obsoleted by
i2c-gpio. Deepak, can you please try using i2c-gpio instead and confirm
that i2c-ixp2000 and i2c-ixp4xx can be deleted?

Thanks,
-- 
Jean Delvare
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-19 Thread Jean Delvare
Hi Len,

On Wed, 18 Apr 2007 13:42:56 -0400, Lennart Sorensen wrote:
 On Sat, Apr 14, 2007 at 07:28:07PM +0200, Jean Delvare wrote:
  Otherwise it looks OK to me, I take the patch. If others have comments
  or objections, just speak up and submit incremental patches as needed.
  
  Now I would like to see platform code actually using this.
 
 Any idea how similar this new driver is to the scx200_i2c driver?  As
 far as I can tell that driver is already a bit banged i2c over gpio
 lines.

The major difference is that the implementation in scx200_i2c is
hardware-specific, while the i2c-gpio driver is a generic one, so it's
a lot better.

What this means is that i2c-gpio obsoletes scx200_i2c, so I am inclined
to delete scx200_i2c right away. I'm not even sure anyone still uses it
now that scx200_acb has been fixed and is reported to work very well.
If anyone really needs to do I2C over GPIO pins on SCx200, this should
be reimplemented on top of i2c-gpio.

It also looks to me like i2c-ixp2000 and i2c-ixp4xx are obsoleted by
i2c-gpio. Deepak, can you please try using i2c-gpio instead and confirm
that i2c-ixp2000 and i2c-ixp4xx can be deleted?

Thanks,
-- 
Jean Delvare
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-19 Thread Lennart Sorensen
On Thu, Apr 19, 2007 at 08:54:13AM +0200, Jean Delvare wrote:
 The major difference is that the implementation in scx200_i2c is
 hardware-specific, while the i2c-gpio driver is a generic one, so it's
 a lot better.
 
 What this means is that i2c-gpio obsoletes scx200_i2c, so I am inclined
 to delete scx200_i2c right away. I'm not even sure anyone still uses it
 now that scx200_acb has been fixed and is reported to work very well.
 If anyone really needs to do I2C over GPIO pins on SCx200, this should
 be reimplemented on top of i2c-gpio.

I use scx200_i2c.  The SBC I am using doesn't work with the scx200_acb
(different pins on the cpu after all).  I would love to see it
reimplemented using the generic interface, since there isn't that many
lines of code involved as far as I can tell.  Well scx200_acb works fine
on a Geode LX board, but not on a Geode SC1200 board.  Unless it has
been fixed since 2.6.18, then it still doesn't work, but scx200_i2c
works perfectly fine.

 It also looks to me like i2c-ixp2000 and i2c-ixp4xx are obsoleted by
 i2c-gpio. Deepak, can you please try using i2c-gpio instead and confirm
 that i2c-ixp2000 and i2c-ixp4xx can be deleted?

--
Len Sorensen
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-18 Thread Lennart Sorensen
On Sat, Apr 14, 2007 at 07:28:07PM +0200, Jean Delvare wrote:
> Otherwise it looks OK to me, I take the patch. If others have comments
> or objections, just speak up and submit incremental patches as needed.
> 
> Now I would like to see platform code actually using this.

Any idea how similar this new driver is to the scx200_i2c driver?  As
far as I can tell that driver is already a bit banged i2c over gpio
lines.

--
Len Sorensen
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-18 Thread Lennart Sorensen
On Sat, Apr 14, 2007 at 07:28:07PM +0200, Jean Delvare wrote:
 Otherwise it looks OK to me, I take the patch. If others have comments
 or objections, just speak up and submit incremental patches as needed.
 
 Now I would like to see platform code actually using this.

Any idea how similar this new driver is to the scx200_i2c driver?  As
far as I can tell that driver is already a bit banged i2c over gpio
lines.

--
Len Sorensen
-
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-14 Thread Jean Delvare
Hi Haavard,

On Sat, 14 Apr 2007 16:34:18 +0200, Haavard Skinnemoen wrote:
> On Sat, 14 Apr 2007 14:56:47 +0200
> Haavard Skinnemoen <[EMAIL PROTECTED]> wrote:
> 
> >   o Default to a very low SCL frequency (6.6 kHz) if clock stretching
> > isn't supported
> 
> This would have been true if I had remembered to save before generating
> the patch...
> 
> Updated patch below. Sorry about the mess.
> 
> Haavard
> 
> ===[cut here]==
> From: Haavard Skinnemoen <[EMAIL PROTECTED]>
> Subject: [PATCH] Bitbanging i2c bus driver using the GPIO API
> 
> This is a very simple bitbanging i2c bus driver utilizing the new
> arch-neutral GPIO API. Useful for chips that don't have a built-in
> i2c controller, additional i2c busses, or testing purposes.
> 
> To use, include something similar to the following in the
> board-specific setup code:
> 
>   #include 
> 
>   static struct i2c_gpio_platform_data i2c_gpio_data = {
>   .sda_pin= GPIO_PIN_FOO,
>   .scl_pin= GPIO_PIN_BAR,
>   };
>   static struct platform_device i2c_gpio_device = {
>   .name   = "i2c-gpio",
>   .id = 0,
>   .dev= {
>   .platform_data  = _gpio_data,
>   },
>   };
> 
> Register this platform_device, set up the i2c pins as GPIO if
> required and you're ready to go. This will use default values for
> udelay and timeout, and will work with GPIO hardware that does not
> support open drain mode, but allows sensing of the SDA and SCL lines
> even when they are being driven.
> 
> Signed-off-by: Haavard Skinnemoen <[EMAIL PROTECTED]>
> ---
>  MAINTAINERS   |5 +
>  drivers/i2c/busses/Kconfig|8 ++
>  drivers/i2c/busses/Makefile   |1 +
>  drivers/i2c/busses/i2c-gpio.c |  215 
> +
>  include/linux/i2c-gpio.h  |   38 +++
>  5 files changed, 267 insertions(+), 0 deletions(-)

Random comments:

> diff --git a/MAINTAINERS b/MAINTAINERS
> index ef84419..fdecda4 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -1429,6 +1429,11 @@ L: [EMAIL PROTECTED]
>  W:   http://www.icp-vortex.com/
>  S:   Supported
>  
> +GENERIC GPIO I2C DRIVER
> +P:   Haavard Skinnemoen
> +M:   [EMAIL PROTECTED]
> +S:   Supported
> +
>  GENERIC HDLC DRIVER, N2, C101, PCI200SYN and WANXL DRIVERS
>  P:   Krzysztof Halasa
>  M:   [EMAIL PROTECTED]
> diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
> index fb19dbb..52f79d1 100644
> --- a/drivers/i2c/busses/Kconfig
> +++ b/drivers/i2c/busses/Kconfig
> @@ -102,6 +102,14 @@ config I2C_ELEKTOR
> This support is also available as a module.  If so, the module 
> will be called i2c-elektor.
>  
> +config I2C_GPIO
> + tristate "GPIO-based bitbanging i2c driver"

I removed "driver" from the option name.

> + depends on I2C && GENERIC_GPIO

I removed I2C, in accordance with Jan Engelhardt's patch:
http://lkml.org/lkml/2007/4/11/153

> + select I2C_ALGOBIT
> + help
> +   This is a very simple bitbanging i2c driver utilizing the
> +   arch-neutral GPIO API to control the SCL and SDA lines.
> +
>  config I2C_HYDRA
>   tristate "CHRP Apple Hydra Mac I/O I2C interface"
>   depends on I2C && PCI && PPC_CHRP && EXPERIMENTAL
> diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
> index 290b540..68f2b05 100644
> --- a/drivers/i2c/busses/Makefile
> +++ b/drivers/i2c/busses/Makefile
> @@ -11,6 +11,7 @@ obj-$(CONFIG_I2C_AMD8111)   += i2c-amd8111.o
>  obj-$(CONFIG_I2C_AT91)   += i2c-at91.o
>  obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
>  obj-$(CONFIG_I2C_ELEKTOR)+= i2c-elektor.o
> +obj-$(CONFIG_I2C_GPIO)   += i2c-gpio.o
>  obj-$(CONFIG_I2C_HYDRA)  += i2c-hydra.o
>  obj-$(CONFIG_I2C_I801)   += i2c-i801.o
>  obj-$(CONFIG_I2C_I810)   += i2c-i810.o
> diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
> new file mode 100644
> index 000..e427bfb
> --- /dev/null
> +++ b/drivers/i2c/busses/i2c-gpio.c
> @@ -0,0 +1,215 @@
> +/*
> + * Bitbanging i2c bus driver using the GPIO API
> + *
> + * Copyright (C) 2007 Atmel Corporation
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include 
> +
> +/* Toggle SDA by changing the direction of the pin */
> +static void i2c_gpio_setsda_dir(void *data, int state)
> +{
> + struct i2c_gpio_platform_data *pdata = data;
> +
> + if (state)
> + gpio_direction_input(pdata->sda_pin);
> + else
> + gpio_direction_output(pdata->sda_pin, 0);
> +}
> +
> +/*
> + * Toggle SDA by changing the output value of the pin. This is only
> + * valid for pins configured as open drain (i.e. setting the value
> + * 

Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-14 Thread Haavard Skinnemoen
On Sat, 14 Apr 2007 14:56:47 +0200
Haavard Skinnemoen <[EMAIL PROTECTED]> wrote:

>   o Default to a very low SCL frequency (6.6 kHz) if clock stretching
> isn't supported

This would have been true if I had remembered to save before generating
the patch...

Updated patch below. Sorry about the mess.

Haavard

===[cut here]==
From: Haavard Skinnemoen <[EMAIL PROTECTED]>
Subject: [PATCH] Bitbanging i2c bus driver using the GPIO API

This is a very simple bitbanging i2c bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
i2c controller, additional i2c busses, or testing purposes.

To use, include something similar to the following in the
board-specific setup code:

  #include 

  static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin= GPIO_PIN_FOO,
.scl_pin= GPIO_PIN_BAR,
  };
  static struct platform_device i2c_gpio_device = {
.name   = "i2c-gpio",
.id = 0,
.dev= {
.platform_data  = _gpio_data,
},
  };

Register this platform_device, set up the i2c pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.

Signed-off-by: Haavard Skinnemoen <[EMAIL PROTECTED]>
---
 MAINTAINERS   |5 +
 drivers/i2c/busses/Kconfig|8 ++
 drivers/i2c/busses/Makefile   |1 +
 drivers/i2c/busses/i2c-gpio.c |  215 +
 include/linux/i2c-gpio.h  |   38 +++
 5 files changed, 267 insertions(+), 0 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index ef84419..fdecda4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1429,6 +1429,11 @@ L:   [EMAIL PROTECTED]
 W: http://www.icp-vortex.com/
 S: Supported
 
+GENERIC GPIO I2C DRIVER
+P: Haavard Skinnemoen
+M: [EMAIL PROTECTED]
+S: Supported
+
 GENERIC HDLC DRIVER, N2, C101, PCI200SYN and WANXL DRIVERS
 P: Krzysztof Halasa
 M: [EMAIL PROTECTED]
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index fb19dbb..52f79d1 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -102,6 +102,14 @@ config I2C_ELEKTOR
  This support is also available as a module.  If so, the module 
  will be called i2c-elektor.
 
+config I2C_GPIO
+   tristate "GPIO-based bitbanging i2c driver"
+   depends on I2C && GENERIC_GPIO
+   select I2C_ALGOBIT
+   help
+ This is a very simple bitbanging i2c driver utilizing the
+ arch-neutral GPIO API to control the SCL and SDA lines.
+
 config I2C_HYDRA
tristate "CHRP Apple Hydra Mac I/O I2C interface"
depends on I2C && PCI && PPC_CHRP && EXPERIMENTAL
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 290b540..68f2b05 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o
 obj-$(CONFIG_I2C_AT91) += i2c-at91.o
 obj-$(CONFIG_I2C_AU1550)   += i2c-au1550.o
 obj-$(CONFIG_I2C_ELEKTOR)  += i2c-elektor.o
+obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o
 obj-$(CONFIG_I2C_HYDRA)+= i2c-hydra.o
 obj-$(CONFIG_I2C_I801) += i2c-i801.o
 obj-$(CONFIG_I2C_I810) += i2c-i810.o
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
new file mode 100644
index 000..e427bfb
--- /dev/null
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -0,0 +1,215 @@
+/*
+ * Bitbanging i2c bus driver using the GPIO API
+ *
+ * Copyright (C) 2007 Atmel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/* Toggle SDA by changing the direction of the pin */
+static void i2c_gpio_setsda_dir(void *data, int state)
+{
+   struct i2c_gpio_platform_data *pdata = data;
+
+   if (state)
+   gpio_direction_input(pdata->sda_pin);
+   else
+   gpio_direction_output(pdata->sda_pin, 0);
+}
+
+/*
+ * Toggle SDA by changing the output value of the pin. This is only
+ * valid for pins configured as open drain (i.e. setting the value
+ * high effectively turns off the output driver.)
+ */
+static void i2c_gpio_setsda_val(void *data, int state)
+{
+   struct i2c_gpio_platform_data *pdata = data;
+
+   gpio_set_value(pdata->sda_pin, state);
+}
+
+/* Toggle SCL by changing the direction of the pin. */
+static void i2c_gpio_setscl_dir(void *data, int state)
+{
+   struct i2c_gpio_platform_data *pdata = data;
+
+   if (state)
+   gpio_direction_input(pdata->scl_pin);
+  

Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-14 Thread Haavard Skinnemoen
On Sat, 14 Apr 2007 14:56:47 +0200
Haavard Skinnemoen [EMAIL PROTECTED] wrote:

   o Default to a very low SCL frequency (6.6 kHz) if clock stretching
 isn't supported

This would have been true if I had remembered to save before generating
the patch...

Updated patch below. Sorry about the mess.

Haavard

===[cut here]==
From: Haavard Skinnemoen [EMAIL PROTECTED]
Subject: [PATCH] Bitbanging i2c bus driver using the GPIO API

This is a very simple bitbanging i2c bus driver utilizing the new
arch-neutral GPIO API. Useful for chips that don't have a built-in
i2c controller, additional i2c busses, or testing purposes.

To use, include something similar to the following in the
board-specific setup code:

  #include linux/i2c-gpio.h

  static struct i2c_gpio_platform_data i2c_gpio_data = {
.sda_pin= GPIO_PIN_FOO,
.scl_pin= GPIO_PIN_BAR,
  };
  static struct platform_device i2c_gpio_device = {
.name   = i2c-gpio,
.id = 0,
.dev= {
.platform_data  = i2c_gpio_data,
},
  };

Register this platform_device, set up the i2c pins as GPIO if
required and you're ready to go. This will use default values for
udelay and timeout, and will work with GPIO hardware that does not
support open drain mode, but allows sensing of the SDA and SCL lines
even when they are being driven.

Signed-off-by: Haavard Skinnemoen [EMAIL PROTECTED]
---
 MAINTAINERS   |5 +
 drivers/i2c/busses/Kconfig|8 ++
 drivers/i2c/busses/Makefile   |1 +
 drivers/i2c/busses/i2c-gpio.c |  215 +
 include/linux/i2c-gpio.h  |   38 +++
 5 files changed, 267 insertions(+), 0 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index ef84419..fdecda4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1429,6 +1429,11 @@ L:   [EMAIL PROTECTED]
 W: http://www.icp-vortex.com/
 S: Supported
 
+GENERIC GPIO I2C DRIVER
+P: Haavard Skinnemoen
+M: [EMAIL PROTECTED]
+S: Supported
+
 GENERIC HDLC DRIVER, N2, C101, PCI200SYN and WANXL DRIVERS
 P: Krzysztof Halasa
 M: [EMAIL PROTECTED]
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index fb19dbb..52f79d1 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -102,6 +102,14 @@ config I2C_ELEKTOR
  This support is also available as a module.  If so, the module 
  will be called i2c-elektor.
 
+config I2C_GPIO
+   tristate GPIO-based bitbanging i2c driver
+   depends on I2C  GENERIC_GPIO
+   select I2C_ALGOBIT
+   help
+ This is a very simple bitbanging i2c driver utilizing the
+ arch-neutral GPIO API to control the SCL and SDA lines.
+
 config I2C_HYDRA
tristate CHRP Apple Hydra Mac I/O I2C interface
depends on I2C  PCI  PPC_CHRP  EXPERIMENTAL
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 290b540..68f2b05 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o
 obj-$(CONFIG_I2C_AT91) += i2c-at91.o
 obj-$(CONFIG_I2C_AU1550)   += i2c-au1550.o
 obj-$(CONFIG_I2C_ELEKTOR)  += i2c-elektor.o
+obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o
 obj-$(CONFIG_I2C_HYDRA)+= i2c-hydra.o
 obj-$(CONFIG_I2C_I801) += i2c-i801.o
 obj-$(CONFIG_I2C_I810) += i2c-i810.o
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
new file mode 100644
index 000..e427bfb
--- /dev/null
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -0,0 +1,215 @@
+/*
+ * Bitbanging i2c bus driver using the GPIO API
+ *
+ * Copyright (C) 2007 Atmel Corporation
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include linux/i2c.h
+#include linux/i2c-algo-bit.h
+#include linux/i2c-gpio.h
+#include linux/init.h
+#include linux/module.h
+#include linux/platform_device.h
+
+#include asm/gpio.h
+
+/* Toggle SDA by changing the direction of the pin */
+static void i2c_gpio_setsda_dir(void *data, int state)
+{
+   struct i2c_gpio_platform_data *pdata = data;
+
+   if (state)
+   gpio_direction_input(pdata-sda_pin);
+   else
+   gpio_direction_output(pdata-sda_pin, 0);
+}
+
+/*
+ * Toggle SDA by changing the output value of the pin. This is only
+ * valid for pins configured as open drain (i.e. setting the value
+ * high effectively turns off the output driver.)
+ */
+static void i2c_gpio_setsda_val(void *data, int state)
+{
+   struct i2c_gpio_platform_data *pdata = data;
+
+   gpio_set_value(pdata-sda_pin, state);
+}
+
+/* Toggle SCL by changing the direction of the pin. */
+static void i2c_gpio_setscl_dir(void *data, int state)
+{
+   struct 

Re: [PATCH v3] Bitbanging i2c bus driver using the GPIO API

2007-04-14 Thread Jean Delvare
Hi Haavard,

On Sat, 14 Apr 2007 16:34:18 +0200, Haavard Skinnemoen wrote:
 On Sat, 14 Apr 2007 14:56:47 +0200
 Haavard Skinnemoen [EMAIL PROTECTED] wrote:
 
o Default to a very low SCL frequency (6.6 kHz) if clock stretching
  isn't supported
 
 This would have been true if I had remembered to save before generating
 the patch...
 
 Updated patch below. Sorry about the mess.
 
 Haavard
 
 ===[cut here]==
 From: Haavard Skinnemoen [EMAIL PROTECTED]
 Subject: [PATCH] Bitbanging i2c bus driver using the GPIO API
 
 This is a very simple bitbanging i2c bus driver utilizing the new
 arch-neutral GPIO API. Useful for chips that don't have a built-in
 i2c controller, additional i2c busses, or testing purposes.
 
 To use, include something similar to the following in the
 board-specific setup code:
 
   #include linux/i2c-gpio.h
 
   static struct i2c_gpio_platform_data i2c_gpio_data = {
   .sda_pin= GPIO_PIN_FOO,
   .scl_pin= GPIO_PIN_BAR,
   };
   static struct platform_device i2c_gpio_device = {
   .name   = i2c-gpio,
   .id = 0,
   .dev= {
   .platform_data  = i2c_gpio_data,
   },
   };
 
 Register this platform_device, set up the i2c pins as GPIO if
 required and you're ready to go. This will use default values for
 udelay and timeout, and will work with GPIO hardware that does not
 support open drain mode, but allows sensing of the SDA and SCL lines
 even when they are being driven.
 
 Signed-off-by: Haavard Skinnemoen [EMAIL PROTECTED]
 ---
  MAINTAINERS   |5 +
  drivers/i2c/busses/Kconfig|8 ++
  drivers/i2c/busses/Makefile   |1 +
  drivers/i2c/busses/i2c-gpio.c |  215 
 +
  include/linux/i2c-gpio.h  |   38 +++
  5 files changed, 267 insertions(+), 0 deletions(-)

Random comments:

 diff --git a/MAINTAINERS b/MAINTAINERS
 index ef84419..fdecda4 100644
 --- a/MAINTAINERS
 +++ b/MAINTAINERS
 @@ -1429,6 +1429,11 @@ L: [EMAIL PROTECTED]
  W:   http://www.icp-vortex.com/
  S:   Supported
  
 +GENERIC GPIO I2C DRIVER
 +P:   Haavard Skinnemoen
 +M:   [EMAIL PROTECTED]
 +S:   Supported
 +
  GENERIC HDLC DRIVER, N2, C101, PCI200SYN and WANXL DRIVERS
  P:   Krzysztof Halasa
  M:   [EMAIL PROTECTED]
 diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
 index fb19dbb..52f79d1 100644
 --- a/drivers/i2c/busses/Kconfig
 +++ b/drivers/i2c/busses/Kconfig
 @@ -102,6 +102,14 @@ config I2C_ELEKTOR
 This support is also available as a module.  If so, the module 
 will be called i2c-elektor.
  
 +config I2C_GPIO
 + tristate GPIO-based bitbanging i2c driver

I removed driver from the option name.

 + depends on I2C  GENERIC_GPIO

I removed I2C, in accordance with Jan Engelhardt's patch:
http://lkml.org/lkml/2007/4/11/153

 + select I2C_ALGOBIT
 + help
 +   This is a very simple bitbanging i2c driver utilizing the
 +   arch-neutral GPIO API to control the SCL and SDA lines.
 +
  config I2C_HYDRA
   tristate CHRP Apple Hydra Mac I/O I2C interface
   depends on I2C  PCI  PPC_CHRP  EXPERIMENTAL
 diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
 index 290b540..68f2b05 100644
 --- a/drivers/i2c/busses/Makefile
 +++ b/drivers/i2c/busses/Makefile
 @@ -11,6 +11,7 @@ obj-$(CONFIG_I2C_AMD8111)   += i2c-amd8111.o
  obj-$(CONFIG_I2C_AT91)   += i2c-at91.o
  obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
  obj-$(CONFIG_I2C_ELEKTOR)+= i2c-elektor.o
 +obj-$(CONFIG_I2C_GPIO)   += i2c-gpio.o
  obj-$(CONFIG_I2C_HYDRA)  += i2c-hydra.o
  obj-$(CONFIG_I2C_I801)   += i2c-i801.o
  obj-$(CONFIG_I2C_I810)   += i2c-i810.o
 diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
 new file mode 100644
 index 000..e427bfb
 --- /dev/null
 +++ b/drivers/i2c/busses/i2c-gpio.c
 @@ -0,0 +1,215 @@
 +/*
 + * Bitbanging i2c bus driver using the GPIO API
 + *
 + * Copyright (C) 2007 Atmel Corporation
 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License version 2 as
 + * published by the Free Software Foundation.
 + */
 +#include linux/i2c.h
 +#include linux/i2c-algo-bit.h
 +#include linux/i2c-gpio.h
 +#include linux/init.h
 +#include linux/module.h
 +#include linux/platform_device.h
 +
 +#include asm/gpio.h
 +
 +/* Toggle SDA by changing the direction of the pin */
 +static void i2c_gpio_setsda_dir(void *data, int state)
 +{
 + struct i2c_gpio_platform_data *pdata = data;
 +
 + if (state)
 + gpio_direction_input(pdata-sda_pin);
 + else
 + gpio_direction_output(pdata-sda_pin, 0);
 +}
 +
 +/*
 + * Toggle SDA by changing the output value of the pin. This is only
 + * valid for pins configured as open drain (i.e. setting the value
 + * high effectively turns off the output