1 /* ------------------------------------------------------------------------- */
2 /* i2c-velleman.c i2c-hw access for Velleman K9000 adapters */
3 /* ------------------------------------------------------------------------- */
4 /* Copyright (C) 1995-96, 2000 Simon G. Vogl
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19 /* ------------------------------------------------------------------------- */
21 /* $Id: i2c-velleman.c,v 1.29 2003/01/21 08:08:16 kmalkki Exp $ */
23 #include <linux/kernel.h>
24 #include <linux/ioport.h>
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/i2c.h>
29 #include <linux/i2c-algo-bit.h>
32 /* ----- global defines ----------------------------------------------- */
33 #define DEB(x) /* should be reasonable open, close &c. */
34 #define DEB2(x) /* low level debugging - very slow */
35 #define DEBE(x) x /* error messages */
37 /* Pin Port Inverted name */
38 #define I2C_SDA 0x02 /* ctrl bit 1 (inv) */
39 #define I2C_SCL 0x08 /* ctrl bit 3 (inv) */
41 #define I2C_SDAIN 0x10 /* stat bit 4 */
42 #define I2C_SCLIN 0x08 /* ctrl bit 3 (inv)(reads own output)*/
44 #define I2C_DMASK 0xfd
45 #define I2C_CMASK 0xf7
48 /* --- Convenience defines for the parallel port: */
49 #define BASE (unsigned int)(data)
50 #define DATA BASE /* Centronics data port */
51 #define STAT (BASE+1) /* Centronics status port */
52 #define CTRL (BASE+2) /* Centronics control port */
54 #define DEFAULT_BASE 0x378
57 /* ----- local functions --------------------------------------------------- */
59 static void bit_velle_setscl(void *data, int state)
62 outb(inb(CTRL) & I2C_CMASK, CTRL);
64 outb(inb(CTRL) | I2C_SCL, CTRL);
69 static void bit_velle_setsda(void *data, int state)
72 outb(inb(CTRL) & I2C_DMASK , CTRL);
74 outb(inb(CTRL) | I2C_SDA, CTRL);
79 static int bit_velle_getscl(void *data)
81 return ( 0 == ( (inb(CTRL)) & I2C_SCLIN ) );
84 static int bit_velle_getsda(void *data)
86 return ( 0 != ( (inb(STAT)) & I2C_SDAIN ) );
89 static int bit_velle_init(void)
91 if (!request_region(base, (base == 0x3bc) ? 3 : 8,
92 "i2c (Vellemann adapter)"))
95 bit_velle_setsda((void*)base,1);
96 bit_velle_setscl((void*)base,1);
100 /* ------------------------------------------------------------------------
101 * Encapsulate the above functions in the correct operations structure.
102 * This is only done when more than one hardware adapter is supported.
105 static struct i2c_algo_bit_data bit_velle_data = {
106 .setsda = bit_velle_setsda,
107 .setscl = bit_velle_setscl,
108 .getsda = bit_velle_getsda,
109 .getscl = bit_velle_getscl,
115 static struct i2c_adapter bit_velle_ops = {
116 .owner = THIS_MODULE,
117 .id = I2C_HW_B_VELLE,
118 .algo_data = &bit_velle_data,
119 .name = "Velleman K8000",
122 static int __init i2c_bitvelle_init(void)
124 printk(KERN_INFO "i2c-velleman.o: i2c Velleman K8000 adapter module version %s (%s)\n", I2C_VERSION, I2C_DATE);
126 /* probe some values */
128 bit_velle_data.data=(void*)DEFAULT_BASE;
129 if (bit_velle_init()==0) {
130 if(i2c_bit_add_bus(&bit_velle_ops) < 0)
136 bit_velle_data.data=(void*)base;
137 if (bit_velle_init()==0) {
138 if(i2c_bit_add_bus(&bit_velle_ops) < 0)
144 printk(KERN_DEBUG "i2c-velleman.o: found device at %#x.\n",base);
148 static void __exit i2c_bitvelle_exit(void)
150 i2c_bit_del_bus(&bit_velle_ops);
151 release_region(base, (base == 0x3bc) ? 3 : 8);
154 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
155 MODULE_DESCRIPTION("I2C-Bus adapter routines for Velleman K8000 adapter");
156 MODULE_LICENSE("GPL");
158 MODULE_PARM(base, "i");
160 module_init(i2c_bitvelle_init);
161 module_exit(i2c_bitvelle_exit);