1 /* ------------------------------------------------------------------------- */
2 /* i2c-elektor.c i2c-hw access for PCF8584 style isa bus adaptes */
3 /* ------------------------------------------------------------------------- */
4 /* Copyright (C) 1995-97 Simon G. Vogl
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* ------------------------------------------------------------------------- */
22 /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
23 Frodo Looijaard <frodol@dds.nl> */
25 /* Partialy rewriten by Oleg I. Vdovikin for mmapped support of
26 for Alpha Processor Inc. UP-2000(+) boards */
28 #include <linux/kernel.h>
29 #include <linux/ioport.h>
30 #include <linux/module.h>
31 #include <linux/delay.h>
32 #include <linux/slab.h>
33 #include <linux/version.h>
34 #include <linux/init.h>
35 #include <linux/pci.h>
39 #include <linux/i2c.h>
40 #include <linux/i2c-algo-pcf.h>
41 #include <linux/i2c-elektor.h>
42 #include "i2c-pcf8584.h"
44 #define DEFAULT_BASE 0x330
48 static int clock = 0x1c;
49 static int own = 0x55;
50 static int mmapped = 0;
51 static int i2c_debug = 0;
53 /* vdovikin: removed static struct i2c_pcf_isa gpi; code -
54 this module in real supports only one device, due to missing arguments
55 in some functions, called from the algo-pcf module. Sometimes it's
56 need to be rewriten - but for now just remove this for simpler reading */
58 #if (LINUX_VERSION_CODE < 0x020301)
59 static struct wait_queue *pcf_wait = NULL;
61 static wait_queue_head_t pcf_wait;
63 static int pcf_pending;
65 /* ----- global defines ----------------------------------------------- */
66 #define DEB(x) if (i2c_debug>=1) x
67 #define DEB2(x) if (i2c_debug>=2) x
68 #define DEB3(x) if (i2c_debug>=3) x
69 #define DEBE(x) x /* error messages */
71 /* ----- local functions ---------------------------------------------- */
73 static void pcf_isa_setbyte(void *data, int ctl, int val)
75 int address = ctl ? (base + 1) : base;
81 DEB3(printk("i2c-elektor.o: Write 0x%X 0x%02X\n", address, val & 255));
84 case 0: /* regular I/O */
87 case 2: /* double mapped I/O needed for UP2000 board,
88 I don't know why this... */
91 case 1: /* memory mapped I/O */
97 static int pcf_isa_getbyte(void *data, int ctl)
99 int address = ctl ? (base + 1) : base;
100 int val = mmapped ? readb(address) : inb(address);
102 DEB3(printk("i2c-elektor.o: Read 0x%X 0x%02X\n", address, val));
107 static int pcf_isa_getown(void *data)
113 static int pcf_isa_getclock(void *data)
118 static void pcf_isa_waitforpin(void) {
124 if (pcf_pending == 0) {
125 interruptible_sleep_on_timeout(&pcf_wait, timeout*HZ );
135 static void pcf_isa_handler(int this_irq, void *dev_id, struct pt_regs *regs) {
137 wake_up_interruptible(&pcf_wait);
141 static int pcf_isa_init(void)
144 if (check_region(base, 2) < 0 ) {
145 printk("i2c-elektor.o: requested I/O region (0x%X:2) is in use.\n", base);
148 request_region(base, 2, "i2c (isa bus adapter)");
152 if (request_irq(irq, pcf_isa_handler, 0, "PCF8584", 0) < 0) {
153 printk("i2c-elektor.o: Request irq%d failed\n", irq);
162 static void __exit pcf_isa_exit(void)
169 release_region(base , 2);
174 static int pcf_isa_reg(struct i2c_client *client)
180 static int pcf_isa_unreg(struct i2c_client *client)
185 static void pcf_isa_inc_use(struct i2c_adapter *adap)
192 static void pcf_isa_dec_use(struct i2c_adapter *adap)
200 /* ------------------------------------------------------------------------
201 * Encapsulate the above functions in the correct operations structure.
202 * This is only done when more than one hardware adapter is supported.
204 static struct i2c_algo_pcf_data pcf_isa_data = {
211 10, 10, 100, /* waits, timeout */
214 static struct i2c_adapter pcf_isa_ops = {
215 "PCF8584 ISA adapter",
225 int __init i2c_pcfisa_init(void)
228 /* check to see we have memory mapped PCF8584 connected to the
229 Cypress cy82c693 PCI-ISA bridge as on UP2000 board */
230 if ((base == 0) && pci_present()) {
232 struct pci_dev *cy693_dev =
233 pci_find_device(PCI_VENDOR_ID_CONTAQ,
234 PCI_DEVICE_ID_CONTAQ_82C693, NULL);
238 /* yeap, we've found cypress, let's check config */
239 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) {
241 DEB3(printk("i2c-elektor.o: found cy82c693, config register 0x47 = 0x%02x.\n", config));
243 /* UP2000 board has this register set to 0xe1,
244 but the most significant bit as seems can be
245 reset during the proper initialisation
246 sequence if guys from API decides to do that
247 (so, we can even enable Tsunami Pchip
248 window for the upper 1 Gb) */
250 /* so just check for ROMCS at 0xe0000,
251 ROMCS enabled for writes
252 and external XD Bus buffer in use. */
253 if ((config & 0x7f) == 0x61) {
254 /* seems to be UP2000 like board */
256 /* I don't know why we need to
259 /* UP2000 drives ISA with
260 8.25 MHz (PCI/4) clock
261 (this can be read from cypress) */
262 clock = I2C_PCF_CLK | I2C_PCF_TRNS90;
263 printk("i2c-elektor.o: found API UP2000 like board, will probe PCF8584 later.\n");
270 /* sanity checks for mmapped I/O */
271 if (mmapped && base < 0xc8000) {
272 printk("i2c-elektor.o: incorrect base address (0x%0X) specified for mmapped I/O.\n", base);
276 printk("i2c-elektor.o: i2c pcf8584-isa adapter module\n");
282 #if (LINUX_VERSION_CODE >= 0x020301)
283 init_waitqueue_head(&pcf_wait);
285 if (pcf_isa_init() == 0) {
286 if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
292 printk("i2c-elektor.o: found device at %#x.\n", base);
301 MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
302 MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 ISA bus adapter");
303 MODULE_LICENSE("GPL");
305 MODULE_PARM(base, "i");
306 MODULE_PARM(irq, "i");
307 MODULE_PARM(clock, "i");
308 MODULE_PARM(own, "i");
309 MODULE_PARM(mmapped, "i");
310 MODULE_PARM(i2c_debug, "i");
312 int init_module(void)
314 return i2c_pcfisa_init();
317 void cleanup_module(void)
319 i2c_pcf_del_bus(&pcf_isa_ops);