Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [PATCH] AU1100 I2C support
@ 2006-07-19 18:02 Rodolfo Giometti
  2006-07-22  9:13 ` Daniel Mack
  0 siblings, 1 reply; 6+ messages in thread
From: Rodolfo Giometti @ 2006-07-19 18:02 UTC (permalink / raw)
  To: i2c; +Cc: linux-mips

[-- Attachment #1: Type: text/plain, Size: 431 bytes --]

Hello,

here a patch to add I2C support to AU1100 processors by using two
GPIOs.

Ciao,

Rodolfo

Signed-off-by: Rodolfo Giometti <giometti@linux.it>

-- 

GNU/Linux Solutions                  e-mail:    giometti@enneenne.com
Linux Device Driver                             giometti@gnudd.com
Embedded Systems                     		giometti@linux.it
UNIX programming                     phone:     +39 349 2432127

[-- Attachment #2: patch-i2c-gpio-support --]
[-- Type: text/plain, Size: 5106 bytes --]

diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 884320e..222c7fc 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -419,6 +419,18 @@ config SCx200_ACB
 	  This support is also available as a module.  If so, the module 
 	  will be called scx200_acb.
 
+config AU1100_I2C
+	tristate "Au1100 I2C using GPIO pins"
+	depends on SOC_AU1100
+	select I2C_ALGOBIT
+	help
+	  Enable the use of two GPIO pins of a Au1100 processor as an I2C bus.
+
+	  If you don't know what to do here, say N.
+
+	  This support is also available as a module.  If so, the module 
+	  will be called i2c-au1100.
+
 config I2C_SIS5595
 	tristate "SiS 5595"
 	depends on I2C && PCI
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index ac56df5..adb7576 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -43,6 +43,7 @@ obj-$(CONFIG_I2C_VIAPRO)	+= i2c-viapro.o
 obj-$(CONFIG_I2C_VOODOO3)	+= i2c-voodoo3.o
 obj-$(CONFIG_SCx200_ACB)	+= scx200_acb.o
 obj-$(CONFIG_SCx200_I2C)	+= scx200_i2c.o
+obj-$(CONFIG_AU1100_I2C)	+= i2c-au1100.o
 
 ifeq ($(CONFIG_I2C_DEBUG_BUS),y)
 EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/i2c/busses/i2c-au1100.c b/drivers/i2c/busses/i2c-au1100.c
new file mode 100644
index 0000000..e010cf8
--- /dev/null
+++ b/drivers/i2c/busses/i2c-au1100.c
@@ -0,0 +1,139 @@
+/* 
+   i2c-au1100.c - I2C support for Au1100
+
+   Copyright (c) 2006 Rodolfo Giometti <giometti@linux.it>
+   Copyright (c) 2006 Eurotech S.p.A. <info@eurotech.it>
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.		     
+*/
+
+#include <linux/config.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <linux/i2c-algo-bit.h>
+#include <asm/io.h>
+
+#include <asm/mach-au1x00/au1000.h>
+
+#define NAME "au1100_i2c"
+
+#if 0
+	/* put here the per-board settings */
+#else
+/* The default GPIOs */
+static int scl = 31;
+static int sda = 30;
+#endif
+
+module_param(scl, int, 0);
+MODULE_PARM_DESC(scl, "GPIO line for SCL");
+module_param(sda, int, 0);
+MODULE_PARM_DESC(sda, "GPIO line for SDA");
+
+/* --- Local functions ----------------------------------------------------- */
+
+static inline void au1100_gpio_set(int gpio, int state)
+{
+	if (state)
+		au_writel(1<<gpio, SYS_OUTPUTSET);
+	else
+		au_writel(1<<gpio, SYS_OUTPUTCLR);
+	au_sync();
+}
+
+static inline int au1100_gpio_get(int gpio)
+{
+	au_writel(1<<gpio, SYS_PININPUTEN);
+	udelay(100);
+	return au_readl(SYS_PINSTATERD)&(1<<gpio) ? 1 : 0;
+}
+
+/* --- I2C operations ------------------------------------------------------ */
+
+static void au1100_i2c_setscl(void *data, int state)
+{
+	au1100_gpio_set(scl, state);
+}
+
+static void au1100_i2c_setsda(void *data, int state)
+{
+	au1100_gpio_set(sda, state);
+} 
+
+static int au1100_i2c_getscl(void *data)
+{
+	return au1100_gpio_get(scl);
+}
+
+static int au1100_i2c_getsda(void *data)
+{
+	return au1100_gpio_get(sda);
+}
+
+static struct i2c_algo_bit_data au1100_i2c_data = {
+	NULL,
+	au1100_i2c_setsda,
+	au1100_i2c_setscl,
+	au1100_i2c_getsda,
+	au1100_i2c_getscl,
+	10, 10, 100,		/* waits, timeout */
+};
+
+static struct i2c_adapter au1100_i2c_ops = {
+	.owner		= THIS_MODULE,
+	.algo_data	= &au1100_i2c_data,
+	.name		= "Au1100 I2C",
+};
+
+/* --- Module stuff -------------------------------------------------------- */
+
+static int au1100_i2c_init(void)
+{
+	pr_debug(NAME ": SCL=GPIO%02u, SDA=GPIO%02u\n", scl, sda);
+
+	if (scl < 0 || sda < 0 || scl > 31 || sda > 31 || scl == sda) {
+		printk(KERN_ERR NAME ": invalid \"scl\" and \"sda\" values\n");
+		return -EINVAL;
+	}
+
+	/* Configure GPIOs as outputs */
+	au1100_gpio_set(scl, 1);
+	au1100_gpio_set(sda, 1);
+
+	if (i2c_bit_add_bus(&au1100_i2c_ops) < 0) {
+		printk(KERN_ERR NAME ": adapter \"%s\" registration failed\n", 
+		       au1100_i2c_ops.name);
+		return -ENODEV;
+	}
+
+	pr_info(NAME ": Au1100 I2C Driver enabled\n");
+	
+	return 0;
+}
+
+static void au1100_i2c_cleanup(void)
+{
+	i2c_bit_del_bus(&au1100_i2c_ops);
+}
+
+module_init(au1100_i2c_init);
+module_exit(au1100_i2c_cleanup);
+
+MODULE_AUTHOR("Rodolfo Giometti <giometti@linux.it>");
+MODULE_DESCRIPTION("Au1100 I2C Driver");
+MODULE_LICENSE("GPL");

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

* Re: [PATCH] AU1100 I2C support
  2006-07-19 18:02 [PATCH] AU1100 I2C support Rodolfo Giometti
@ 2006-07-22  9:13 ` Daniel Mack
  2006-07-22 12:32   ` Rodolfo Giometti
  0 siblings, 1 reply; 6+ messages in thread
From: Daniel Mack @ 2006-07-22  9:13 UTC (permalink / raw)
  To: Rodolfo Giometti; +Cc: i2c, linux-mips

Hi,

On Wed, Jul 19, 2006 at 08:02:04PM +0200, Rodolfo Giometti wrote:
> here a patch to add I2C support to AU1100 processors by using two
> GPIOs.

Is there any reason why it is limited to this very processor and
should not work with all au1xxx types?

Daniel

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

* Re: [PATCH] AU1100 I2C support
  2006-07-22  9:13 ` Daniel Mack
@ 2006-07-22 12:32   ` Rodolfo Giometti
  2006-07-24 10:30     ` Daniel Mack
  0 siblings, 1 reply; 6+ messages in thread
From: Rodolfo Giometti @ 2006-07-22 12:32 UTC (permalink / raw)
  To: Daniel Mack; +Cc: i2c, linux-mips

[-- Attachment #1: Type: text/plain, Size: 627 bytes --]

On Sat, Jul 22, 2006 at 11:13:42AM +0200, Daniel Mack wrote:
> 
> Is there any reason why it is limited to this very processor and
> should not work with all au1xxx types?

To be honest I don't know exacly... I don't know so well other
processors in this family. However I think at least au1000 and au1200
should be compatible.

Ciao,

Rodolfo

-- 

GNU/Linux Solutions                  e-mail:    giometti@enneenne.com
Linux Device Driver                             giometti@gnudd.com
Embedded Systems                     		giometti@linux.it
UNIX programming                     phone:     +39 349 2432127

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [PATCH] AU1100 I2C support
  2006-07-22 12:32   ` Rodolfo Giometti
@ 2006-07-24 10:30     ` Daniel Mack
  2006-07-24 10:35       ` Rodolfo Giometti
  2006-07-24 13:31       ` Sergei Shtylyov
  0 siblings, 2 replies; 6+ messages in thread
From: Daniel Mack @ 2006-07-24 10:30 UTC (permalink / raw)
  To: Rodolfo Giometti; +Cc: i2c, linux-mips


On Jul 22, 2006, at 2:32 PM, Rodolfo Giometti wrote:

> On Sat, Jul 22, 2006 at 11:13:42AM +0200, Daniel Mack wrote:
>>
>> Is there any reason why it is limited to this very processor and
>> should not work with all au1xxx types?
>
> To be honest I don't know exacly... I don't know so well other
> processors in this family. However I think at least au1000 and au1200
> should be compatible.

I think so, too. Since you only call the generic au_* functions for
the GPIO access, all members of this processor family should be
supported. I propose to change the patch accordingly.

Daniel

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

* Re: [PATCH] AU1100 I2C support
  2006-07-24 10:30     ` Daniel Mack
@ 2006-07-24 10:35       ` Rodolfo Giometti
  2006-07-24 13:31       ` Sergei Shtylyov
  1 sibling, 0 replies; 6+ messages in thread
From: Rodolfo Giometti @ 2006-07-24 10:35 UTC (permalink / raw)
  To: Daniel Mack; +Cc: i2c, linux-mips

[-- Attachment #1: Type: text/plain, Size: 730 bytes --]

On Mon, Jul 24, 2006 at 12:30:42PM +0200, Daniel Mack wrote:
> 
> I think so, too. Since you only call the generic au_* functions for
> the GPIO access, all members of this processor family should be
> supported. I propose to change the patch accordingly.

Do you think I should change strings (functions' name, etc.) from
"au1100" to "au1xxx"?

If so, do you prefere a new patch or I can just send you a
patch-to-the-patch? :D

Ciao,

Rodolfo

-- 

GNU/Linux Solutions                  e-mail:    giometti@enneenne.com
Linux Device Driver                             giometti@gnudd.com
Embedded Systems                     		giometti@linux.it
UNIX programming                     phone:     +39 349 2432127

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [PATCH] AU1100 I2C support
  2006-07-24 10:30     ` Daniel Mack
  2006-07-24 10:35       ` Rodolfo Giometti
@ 2006-07-24 13:31       ` Sergei Shtylyov
  1 sibling, 0 replies; 6+ messages in thread
From: Sergei Shtylyov @ 2006-07-24 13:31 UTC (permalink / raw)
  To: Daniel Mack; +Cc: giometti, i2c, linux-mips

Hello.

Daniel Mack wrote:

>> On Sat, Jul 22, 2006 at 11:13:42AM +0200, Daniel Mack wrote:

>>> Is there any reason why it is limited to this very processor and
>>> should not work with all au1xxx types?

>> To be honest I don't know exacly... I don't know so well other
>> processors in this family. However I think at least au1000 and au1200
>> should be compatible.

> I think so, too. Since you only call the generic au_* functions for
> the GPIO access, all members of this processor family should be
> supported. I propose to change the patch accordingly.

    Actually, Au1550/1200 have dedicated SMBus contoller and an existing I2C 
driver for it, so there''s probably no need for another bit-banging driver for 
them.

> Daniel

WBR, Sergei

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

end of thread, other threads:[~2006-07-24 13:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-07-19 18:02 [PATCH] AU1100 I2C support Rodolfo Giometti
2006-07-22  9:13 ` Daniel Mack
2006-07-22 12:32   ` Rodolfo Giometti
2006-07-24 10:30     ` Daniel Mack
2006-07-24 10:35       ` Rodolfo Giometti
2006-07-24 13:31       ` Sergei Shtylyov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox