From: Rodolfo Giometti <giometti@linux.it>
To: i2c@lm-sensors.org
Cc: linux-mips@linux-mips.org
Subject: [PATCH] AU1100 I2C support
Date: Wed, 19 Jul 2006 20:02:04 +0200 [thread overview]
Message-ID: <20060719180204.GK25330@enneenne.com> (raw)
[-- 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");
next reply other threads:[~2006-07-19 18:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-19 18:02 Rodolfo Giometti [this message]
2006-07-22 9:13 ` [PATCH] AU1100 I2C support 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
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=20060719180204.GK25330@enneenne.com \
--to=giometti@linux.it \
--cc=i2c@lm-sensors.org \
--cc=linux-mips@linux-mips.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