[i2c] [PATCH] AU1100 I2C support
Rodolfo Giometti
giometti at linux.it
Wed Jul 19 20:02:04 CEST 2006
Hello,
here a patch to add I2C support to AU1100 processors by using two
GPIOs.
Ciao,
Rodolfo
Signed-off-by: Rodolfo Giometti <giometti at linux.it>
--
GNU/Linux Solutions e-mail: giometti at enneenne.com
Linux Device Driver giometti at gnudd.com
Embedded Systems giometti at linux.it
UNIX programming phone: +39 349 2432127
-------------- next part --------------
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 at linux.it>
+ Copyright (c) 2006 Eurotech S.p.A. <info at 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 at linux.it>");
+MODULE_DESCRIPTION("Au1100 I2C Driver");
+MODULE_LICENSE("GPL");
More information about the i2c
mailing list