1 /* ------------------------------------------------------------------------- */
2 /* i2c-elv.c i2c-hw access for philips style parallel port adapters */
3 /* ------------------------------------------------------------------------- */
4 /* Copyright (C) 1995-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 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
22 Frodo Looijaard <frodol@dds.nl> */
24 /* $Id: i2c-elv.c,v 1.1.1.1 2005/04/11 02:50:21 jack Exp $ */
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/delay.h>
29 #include <linux/slab.h>
30 #include <linux/version.h>
31 #include <linux/init.h>
33 #include <asm/uaccess.h>
35 #include <linux/ioport.h>
37 #include <linux/errno.h>
38 #include <linux/i2c.h>
39 #include <linux/i2c-algo-bit.h>
41 #define DEFAULT_BASE 0x378
43 static unsigned char PortData = 0;
45 /* ----- global defines ----------------------------------------------- */
46 #define DEB(x) /* should be reasonable open, close &c. */
47 #define DEB2(x) /* low level debugging - very slow */
48 #define DEBE(x) x /* error messages */
49 #define DEBINIT(x) x /* detection status messages */
51 /* --- Convenience defines for the parallel port: */
52 #define BASE (unsigned int)(data)
53 #define DATA BASE /* Centronics data port */
54 #define STAT (BASE+1) /* Centronics status port */
55 #define CTRL (BASE+2) /* Centronics control port */
58 /* ----- local functions ---------------------------------------------- */
61 static void bit_elv_setscl(void *data, int state)
71 static void bit_elv_setsda(void *data, int state)
81 static int bit_elv_getscl(void *data)
83 return ( 0 == ( (inb_p(STAT)) & 0x08 ) );
86 static int bit_elv_getsda(void *data)
88 return ( 0 == ( (inb_p(STAT)) & 0x40 ) );
91 static int bit_elv_init(void)
93 if (check_region(base,(base == 0x3bc)? 3 : 8) < 0 ) {
96 /* test for ELV adap. */
97 if (inb(base+1) & 0x80) { /* BUSY should be high */
98 DEBINIT(printk("i2c-elv.o: Busy was low.\n"));
101 outb(0x0c,base+2); /* SLCT auf low */
103 if ( !(inb(base+1) && 0x10) ) {
105 DEBINIT(printk("i2c-elv.o: Select was high.\n"));
109 request_region(base,(base == 0x3bc)? 3 : 8,
110 "i2c (ELV adapter)");
112 bit_elv_setsda((void*)base,1);
113 bit_elv_setscl((void*)base,1);
118 static void __exit bit_elv_exit(void)
120 release_region( base , (base == 0x3bc)? 3 : 8 );
123 static int bit_elv_reg(struct i2c_client *client)
128 static int bit_elv_unreg(struct i2c_client *client)
133 static void bit_elv_inc_use(struct i2c_adapter *adap)
140 static void bit_elv_dec_use(struct i2c_adapter *adap)
147 /* ------------------------------------------------------------------------
148 * Encapsulate the above functions in the correct operations structure.
149 * This is only done when more than one hardware adapter is supported.
151 static struct i2c_algo_bit_data bit_elv_data = {
157 80, 80, 100, /* waits, timeout */
160 static struct i2c_adapter bit_elv_ops = {
161 "ELV Parallel port adaptor",
171 int __init i2c_bitelv_init(void)
173 printk("i2c-elv.o: i2c ELV parallel port adapter module\n");
175 /* probe some values */
177 bit_elv_data.data=(void*)DEFAULT_BASE;
178 if (bit_elv_init()==0) {
179 if(i2c_bit_add_bus(&bit_elv_ops) < 0)
185 bit_elv_ops.data=(void*)base;
186 if (bit_elv_init()==0) {
187 if(i2c_bit_add_bus(&bit_elv_ops) < 0)
193 printk("i2c-elv.o: found device at %#x.\n",base);
201 MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>");
202 MODULE_DESCRIPTION("I2C-Bus adapter routines for ELV parallel port adapter");
203 MODULE_LICENSE("GPL");
206 MODULE_PARM(base, "i");
208 int init_module(void)
210 return i2c_bitelv_init();
213 void cleanup_module(void)
215 i2c_bit_del_bus(&bit_elv_ops);