1 diff -urN linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/Config.in linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/Config.in
2 --- linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/Config.in 2004-12-13 18:03:18.000000000 +0100
3 +++ linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/Config.in 2004-12-13 18:11:02.000000000 +0100
5 int ' GPIO pin used for SCL' CONFIG_SCx200_I2C_SCL 12
6 int ' GPIO pin used for SDA' CONFIG_SCx200_I2C_SDA 13
8 + dep_tristate ' I2C using Au1x00 GPIO pins' CONFIG_I2C_AU1X00GPIO $CONFIG_I2C_ALGOBIT
9 + if [ "$CONFIG_I2C_AU1X00GPIO" != "n" ]; then
10 + int ' GPIO pin used for SCL' CONFIG_I2C_AU1X00GPIO_SCL 206
11 + int ' GPIO pin used for SDA' CONFIG_I2C_AU1X00GPIO_SDA 207
15 dep_tristate 'NatSemi SCx200 ACCESS.bus' CONFIG_SCx200_ACB $CONFIG_I2C
16 diff -urN linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/i2c-au1x00gpio.c linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/i2c-au1x00gpio.c
17 --- linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/i2c-au1x00gpio.c 1970-01-01 01:00:00.000000000 +0100
18 +++ linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/i2c-au1x00gpio.c 2004-12-13 18:12:50.000000000 +0100
20 +/* ------------------------------------------------------------------------- */
21 +/* i2c-au1x00gpio.c i2c-hw access for Au1x00 GPIO pins. */
22 +/* ------------------------------------------------------------------------- */
23 +/* Copyright (C) 1995-2000 Michael Stickel
25 + This program is free software; you can redistribute it and/or modify
26 + it under the terms of the GNU General Public License as published by
27 + the Free Software Foundation; either version 2 of the License, or
28 + (at your option) any later version.
30 + This program is distributed in the hope that it will be useful,
31 + but WITHOUT ANY WARRANTY; without even the implied warranty of
32 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 + GNU General Public License for more details.
35 + You should have received a copy of the GNU General Public License
36 + along with this program; if not, write to the Free Software
37 + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
38 +/* ------------------------------------------------------------------------- */
40 +/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
41 + Frodo Looijaard <frodol@dds.nl>
45 +/* $Id: i2c-au1x00gpio.c,v 1.1.1.2 2004/01/22 15:35:47 br1 Exp $ */
47 +#include <linux/module.h>
48 +#include <linux/config.h>
49 +#include <linux/types.h>
50 +#include <linux/kernel.h>
51 +#include <linux/init.h>
52 +#include <linux/stddef.h>
53 +#include <linux/ioport.h>
54 +#include <asm/uaccess.h>
56 +#include <asm/au1000.h>
57 +#include <asm/au1000_gpio.h>
59 +#include <linux/slab.h>
60 +#include <linux/mm.h>
62 +#include <linux/i2c.h>
63 +#include <linux/i2c-algo-bit.h>
66 +#define __exit __init
70 +struct i2c_au1x00gpio
72 + struct i2c_au1x00gpio *next;
77 + unsigned long scl_mask;
78 + unsigned long sda_mask;
80 + struct i2c_adapter adapter;
81 + struct i2c_algo_bit_data bit_au1x00gpio_data;
84 +static struct i2c_au1x00gpio *adapter_list;
88 +/* ----- global defines ----------------------------------------------- */
89 +#define DEB(x) /* should be reasonable open, close &c. */
90 +#define DEB2(x) /* low level debugging - very slow */
91 +#define DEBE(x) x /* error messages */
93 +/* ----- printer port defines ------------------------------------------*/
95 +/* ----- local functions ---------------------------------------------- */
99 +static void bit_au1x00gpio_setscl(void *data, int state)
101 + struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
103 + au_writel(adapter->scl_mask, SYS_TRIOUTCLR); // Disable Driver: Switch off Transistor => 1
105 + au_writel(adapter->scl_mask, SYS_OUTPUTCLR); // Clear Output and switch on Transistor => 0
109 +static void bit_au1x00gpio_setsda(void *data, int state)
111 + struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
113 + au_writel(adapter->sda_mask, SYS_TRIOUTCLR);
115 + au_writel(adapter->sda_mask, SYS_OUTPUTCLR);
119 +static int bit_au1x00gpio_getscl(void *data)
121 + struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
122 + return (au_readl(SYS_PINSTATERD) & adapter->scl_mask) ? 1 : 0;
126 +static int bit_au1x00gpio_getsda(void *data)
128 + struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
129 + return (au_readl(SYS_PINSTATERD) & adapter->sda_mask) ? 1 : 0;
136 + *-- Functions for accessing GPIO-2
139 +static void bit_au1x00gpio2_setscl(void *data, int state)
141 + struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
144 + au_writel(au_readl(GPIO2_DIR) & ~adapter->scl_mask, GPIO2_DIR);
148 + au_writel(au_readl(GPIO2_OUTPUT) & ~adapter->scl_mask, GPIO2_OUTPUT);
149 + au_writel(au_readl(GPIO2_DIR) | adapter->scl_mask, GPIO2_DIR);
153 +static void bit_au1x00gpio2_setsda(void *data, int state)
155 + struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
158 + au_writel(au_readl(GPIO2_DIR) & ~adapter->sda_mask, GPIO2_DIR);
162 + au_writel(au_readl(GPIO2_OUTPUT) & ~adapter->sda_mask, GPIO2_OUTPUT);
163 + au_writel(au_readl(GPIO2_DIR) | adapter->sda_mask, GPIO2_DIR);
167 +static int bit_au1x00gpio2_getscl(void *data)
169 + struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
170 + return (au_readl(GPIO2_PINSTATE) & adapter->scl_mask) ? 1 : 0;
173 +static int bit_au1x00gpio2_getsda(void *data)
175 + struct i2c_au1x00gpio * adapter = (struct i2c_au1x00gpio *)data;
176 + return (au_readl(GPIO2_PINSTATE) & adapter->sda_mask) ? 1 : 0;
181 +static int check_i2c_au1x00gpio_adapter(struct i2c_au1x00gpio *adapter)
185 + adapter->bit_au1x00gpio_data.setsda (adapter, 1);
186 + adapter->bit_au1x00gpio_data.setscl (adapter, 1);
188 + if (adapter->bit_au1x00gpio_data.getsda(adapter)==0)
190 + printk ("i2c-au1x00gpio: sda line should read 1 but reads 0\n");
193 + if (adapter->bit_au1x00gpio_data.getscl(adapter)==0)
195 + printk ("i2c-au1x00gpio: scl line should read 1 but reads 0\n");
200 + adapter->bit_au1x00gpio_data.setsda (adapter, 0);
201 + adapter->bit_au1x00gpio_data.setscl (adapter, 0);
203 + if (adapter->bit_au1x00gpio_data.getsda(adapter)==1)
205 + printk ("i2c-au1x00gpio: sda line should read 0 but reads 1\n");
208 + if (adapter->bit_au1x00gpio_data.getscl(adapter)==1)
210 + printk ("i2c-au1x00gpio: scl line should read 0 but reads 1\n");
215 + printk ("i2c-au1x00gpio: adapter with scl=GPIO%d,sda=GPIO%d is working\n",
216 + adapter->scl_gpio, adapter->sda_gpio
224 +static int bit_au1x00gpio_reg(struct i2c_client *client)
229 +static int bit_au1x00gpio_unreg(struct i2c_client *client)
234 +static void bit_au1x00gpio_inc_use(struct i2c_adapter *adap)
239 +static void bit_au1x00gpio_dec_use(struct i2c_adapter *adap)
247 +static struct i2c_algo_bit_data bit_au1x00gpio_data = {
248 + .setsda = bit_au1x00gpio_setsda,
249 + .setscl = bit_au1x00gpio_setscl,
250 + .getsda = bit_au1x00gpio_getsda,
251 + .getscl = bit_au1x00gpio_getscl,
258 +static struct i2c_adapter bit_au1x00gpio_ops = {
259 + .owner = THIS_MODULE,
260 + .name = "Au1x00 GPIO I2C adapter",
261 + .id = I2C_HW_B_AU1x00GPIO,
268 + * 0..31 for primary GPIO's
269 + * 200..215 for secondary GPIO's
272 + * 0..31 for primary GPIO's
273 + * 200..215 for secondary GPIO's
275 + * You can even mix primary and secondary GPIO's.
276 + * E.g.: i2c_au1x00gpio_create(4,206);
279 +static int i2c_au1x00gpio_create (int scl_gpio, int sda_gpio)
281 + if ((scl_gpio < 32 || (scl_gpio >= 200 && scl_gpio <= 215)) &&
282 + (scl_gpio < 32 || (scl_gpio >= 200 && scl_gpio <= 215)))
284 + struct i2c_au1x00gpio *adapter = kmalloc(sizeof(struct i2c_au1x00gpio),
287 + printk(KERN_ERR "i2c-au1x00-gpio: Unable to malloc.\n");
291 + printk(KERN_DEBUG "i2c-au1x00-gpio.o: attaching to SCL=GPIO%d, SDA=GPIO%d\n",
292 + scl_gpio, sda_gpio);
294 + memset (adapter, 0, sizeof(struct i2c_au1x00gpio));
296 + adapter->adapter = bit_au1x00gpio_ops;
298 + adapter->adapter.algo_data = &adapter->bit_au1x00gpio_data;
299 + adapter->bit_au1x00gpio_data = bit_au1x00gpio_data;
300 + adapter->bit_au1x00gpio_data.data = adapter;
302 + adapter->bit_au1x00gpio_data.data = adapter;
304 + adapter->scl_gpio = scl_gpio;
305 + adapter->sda_gpio = sda_gpio;
309 + adapter->bit_au1x00gpio_data.setsda = bit_au1x00gpio_setsda;
310 + adapter->bit_au1x00gpio_data.getsda = bit_au1x00gpio_getsda;
311 + adapter->sda_mask = 1<<sda_gpio;
313 + else if (sda_gpio >= 200 && sda_gpio <= 215)
315 + adapter->bit_au1x00gpio_data.setsda = bit_au1x00gpio2_setsda;
316 + adapter->bit_au1x00gpio_data.getsda = bit_au1x00gpio2_getsda;
317 + adapter->sda_mask = 1<<(sda_gpio-200);
323 + adapter->bit_au1x00gpio_data.setscl = bit_au1x00gpio_setscl;
324 + adapter->bit_au1x00gpio_data.getscl = bit_au1x00gpio_getscl;
325 + adapter->scl_mask = 1<<scl_gpio;
327 + else if (scl_gpio >= 200 && scl_gpio <= 215)
329 + adapter->bit_au1x00gpio_data.setscl = bit_au1x00gpio2_setscl;
330 + adapter->bit_au1x00gpio_data.getscl = bit_au1x00gpio2_getscl;
331 + adapter->scl_mask = 1<<(scl_gpio-200);
334 + au_writel(0L, SYS_PININPUTEN);
335 + if (check_i2c_au1x00gpio_adapter(adapter)==0)
337 + adapter->bit_au1x00gpio_data.setsda (adapter, 1);
338 + adapter->bit_au1x00gpio_data.setscl (adapter, 1);
340 + if (i2c_bit_add_bus(&adapter->adapter) < 0)
342 + printk(KERN_ERR "i2c-au1x00-gpio: Unable to register with I2C.\n");
344 + return -1; /* No good */
347 + adapter->next = adapter_list;
348 + adapter_list = adapter;
353 + printk(KERN_ERR "i2c-au1x00-gpio: Invalid argument scl_gpio=%d, sda_gpio=%d.\n", scl_gpio, sda_gpio);
359 +static void i2c_au1x00gpio_delete (int scl_gpio, int sda_gpio)
361 + struct i2c_au1x00gpio *adapter, *prev = NULL;
363 + for (adapter = adapter_list; adapter; adapter = adapter->next)
365 + if (adapter->scl_gpio == scl_gpio &&
366 + adapter->sda_gpio == sda_gpio)
368 + i2c_bit_del_bus(&adapter->adapter);
370 + prev->next = adapter->next;
372 + adapter_list = adapter->next;
384 +#ifndef CONFIG_I2C_AU1X00GPIO_SCL
385 +#define CONFIG_I2C_AU1X00GPIO_SCL (216)
388 +#ifndef CONFIG_I2C_AU1X00GPIO_SDA
389 +#define CONFIG_I2C_AU1X00GPIO_SDA (217)
392 +static int au1x00gpiopin_scl = CONFIG_I2C_AU1X00GPIO_SCL;
393 +static int au1x00gpiopin_sda = CONFIG_I2C_AU1X00GPIO_SDA;
397 +int __init i2c_bit_au1x00gpio_init(void)
399 + printk(KERN_INFO "i2c-au1x00gpio.o: i2c Au1x00 GPIO adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
401 + if (i2c_au1x00gpio_create (au1x00gpiopin_scl, au1x00gpiopin_sda) == 0)
403 + printk(KERN_INFO "i2c-au1x00gpio.o: registered I2C-Bus for GPIO%d,GPIO%d\n",
404 + au1x00gpiopin_scl, au1x00gpiopin_sda
408 + printk(KERN_INFO "i2c-au1x00gpio.o: failed to register I2C-Bus for GPIO%d,GPIO%d\n",
409 + au1x00gpiopin_scl, au1x00gpiopin_sda
415 +void __exit i2c_bit_au1x00gpio_exit(void)
417 + i2c_au1x00gpio_delete (au1x00gpiopin_scl, au1x00gpiopin_sda);
424 +MODULE_PARM(au1x00gpiopin_scl, "i");
425 +MODULE_PARM_DESC(au1x00gpiopin_scl, "GPIO pin number used for SCL pin.");
427 +MODULE_PARM(au1x00gpiopin_sda, "i");
428 +MODULE_PARM_DESC(au1x00gpiopin_sda, "GPIO pin number used for SDA pin.");
430 +MODULE_AUTHOR("Michael Stickel <michael@cubic.org>");
431 +MODULE_DESCRIPTION("I2C-Bus adapter routines for Au1x00 GPIO adapter.");
432 +MODULE_LICENSE("GPL");
436 +int init_module(void)
438 + return i2c_bit_au1x00gpio_init();
441 +void cleanup_module(void)
443 + i2c_bit_au1x00gpio_exit();
446 diff -urN linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/Makefile linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/Makefile
447 --- linux-2.4.27-mtx1-lm_sensors-2.8.8/drivers/i2c/Makefile 2004-12-13 18:03:18.000000000 +0100
448 +++ linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/drivers/i2c/Makefile 2004-12-13 18:11:59.000000000 +0100
450 obj-$(CONFIG_I2C_ALGO_SIBYTE) += i2c-algo-sibyte.o i2c-sibyte.o
451 obj-$(CONFIG_I2C_MAX1617) += i2c-max1617.o
452 obj-$(CONFIG_I2C_ALGO_SGI) += i2c-algo-sgi.o
453 +obj-$(CONFIG_I2C_AU1X00GPIO) += i2c-au1x00gpio.o
454 obj-$(CONFIG_I2C_ALGO_AU1550) += i2c-algo-au1550.o i2c-au1550.o
456 # This is needed for automatic patch generation: sensors code starts here
457 --- linux-2.4.27-mtx1-lm_sensors-2.8.8/include/linux/i2c-id.h 2004-12-13 21:09:52.000000000 +0100
458 +++ linux-2.4.27-mtx1-lm_sensors-2.8.8-i2cau1x00gpio/include/linux/i2c-id.h 2004-12-13 21:36:14.000000000 +0100
460 #define I2C_HW_B_S3VIA 0x18 /* S3Via ProSavage adapter */
461 #define I2C_HW_B_ZR36067 0x19 /* Zoran-36057/36067 based boards */
462 #define I2C_HW_B_PCILYNX 0x1a /* TI PCILynx I2C adapter */
463 +#define I2C_HW_B_AU1x00GPIO 0x1b /* Au1x00 GPIO adapter */
465 /* --- PCF 8584 based algorithms */
466 #define I2C_HW_P_LP 0x00 /* Parallel port interface */