| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* ------------------------------------------------------------------------- */ | 
 | 2 | /* i2c-elektor.c i2c-hw access for PCF8584 style isa bus adaptes             */ | 
 | 3 | /* ------------------------------------------------------------------------- */ | 
 | 4 | /*   Copyright (C) 1995-97 Simon G. Vogl | 
 | 5 |                    1998-99 Hans Berglund | 
 | 6 |  | 
 | 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. | 
 | 11 |  | 
 | 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. | 
 | 16 |  | 
 | 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 | /* ------------------------------------------------------------------------- */ | 
 | 21 |  | 
| Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 22 | /* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 |    Frodo Looijaard <frodol@dds.nl> */ | 
 | 24 |  | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 25 | /* Partialy rewriten by Oleg I. Vdovikin for mmapped support of | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 |    for Alpha Processor Inc. UP-2000(+) boards */ | 
 | 27 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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/init.h> | 
 | 34 | #include <linux/interrupt.h> | 
 | 35 | #include <linux/pci.h> | 
 | 36 | #include <linux/wait.h> | 
 | 37 |  | 
| Jean Delvare | 4a5d303 | 2007-05-01 23:26:30 +0200 | [diff] [blame] | 38 | #include <linux/isa.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/i2c.h> | 
 | 40 | #include <linux/i2c-algo-pcf.h> | 
 | 41 |  | 
 | 42 | #include <asm/io.h> | 
 | 43 | #include <asm/irq.h> | 
 | 44 |  | 
 | 45 | #include "../algos/i2c-algo-pcf.h" | 
 | 46 |  | 
 | 47 | #define DEFAULT_BASE 0x330 | 
 | 48 |  | 
 | 49 | static int base; | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 50 | static u8 __iomem *base_iomem; | 
 | 51 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | static int irq; | 
 | 53 | static int clock  = 0x1c; | 
 | 54 | static int own    = 0x55; | 
 | 55 | static int mmapped; | 
 | 56 |  | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 57 | /* vdovikin: removed static struct i2c_pcf_isa gpi; code - | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 |   this module in real supports only one device, due to missing arguments | 
 | 59 |   in some functions, called from the algo-pcf module. Sometimes it's | 
 | 60 |   need to be rewriten - but for now just remove this for simpler reading */ | 
 | 61 |  | 
 | 62 | static wait_queue_head_t pcf_wait; | 
 | 63 | static int pcf_pending; | 
 | 64 | static spinlock_t lock; | 
 | 65 |  | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 66 | static struct i2c_adapter pcf_isa_ops; | 
 | 67 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* ----- local functions ----------------------------------------------	*/ | 
 | 69 |  | 
 | 70 | static void pcf_isa_setbyte(void *data, int ctl, int val) | 
 | 71 | { | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 72 | 	u8 __iomem *address = ctl ? (base_iomem + 1) : base_iomem; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 |  | 
 | 74 | 	/* enable irq if any specified for serial operation */ | 
 | 75 | 	if (ctl && irq && (val & I2C_PCF_ESO)) { | 
 | 76 | 		val |= I2C_PCF_ENI; | 
 | 77 | 	} | 
 | 78 |  | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 79 | 	pr_debug("%s: Write %p 0x%02X\n", pcf_isa_ops.name, address, val); | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 80 | 	iowrite8(val, address); | 
 | 81 | #ifdef __alpha__ | 
 | 82 | 	/* API UP2000 needs some hardware fudging to make the write stick */ | 
 | 83 | 	iowrite8(val, address); | 
 | 84 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } | 
 | 86 |  | 
 | 87 | static int pcf_isa_getbyte(void *data, int ctl) | 
 | 88 | { | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 89 | 	u8 __iomem *address = ctl ? (base_iomem + 1) : base_iomem; | 
 | 90 | 	int val = ioread8(address); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 |  | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 92 | 	pr_debug("%s: Read %p 0x%02X\n", pcf_isa_ops.name, address, val); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | 	return (val); | 
 | 94 | } | 
 | 95 |  | 
 | 96 | static int pcf_isa_getown(void *data) | 
 | 97 | { | 
 | 98 | 	return (own); | 
 | 99 | } | 
 | 100 |  | 
 | 101 |  | 
 | 102 | static int pcf_isa_getclock(void *data) | 
 | 103 | { | 
 | 104 | 	return (clock); | 
 | 105 | } | 
 | 106 |  | 
| David Miller | 08e5338 | 2008-10-22 20:21:29 +0200 | [diff] [blame] | 107 | static void pcf_isa_waitforpin(void *data) | 
 | 108 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | 	DEFINE_WAIT(wait); | 
 | 110 | 	int timeout = 2; | 
 | 111 | 	unsigned long flags; | 
 | 112 |  | 
 | 113 | 	if (irq > 0) { | 
 | 114 | 		spin_lock_irqsave(&lock, flags); | 
 | 115 | 		if (pcf_pending == 0) { | 
 | 116 | 			spin_unlock_irqrestore(&lock, flags); | 
 | 117 | 			prepare_to_wait(&pcf_wait, &wait, TASK_INTERRUPTIBLE); | 
 | 118 | 			if (schedule_timeout(timeout*HZ)) { | 
 | 119 | 				spin_lock_irqsave(&lock, flags); | 
 | 120 | 				if (pcf_pending == 1) { | 
 | 121 | 					pcf_pending = 0; | 
 | 122 | 				} | 
 | 123 | 				spin_unlock_irqrestore(&lock, flags); | 
 | 124 | 			} | 
 | 125 | 			finish_wait(&pcf_wait, &wait); | 
 | 126 | 		} else { | 
 | 127 | 			pcf_pending = 0; | 
 | 128 | 			spin_unlock_irqrestore(&lock, flags); | 
 | 129 | 		} | 
 | 130 | 	} else { | 
 | 131 | 		udelay(100); | 
 | 132 | 	} | 
 | 133 | } | 
 | 134 |  | 
 | 135 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 136 | static irqreturn_t pcf_isa_handler(int this_irq, void *dev_id) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | 	spin_lock(&lock); | 
 | 138 | 	pcf_pending = 1; | 
 | 139 | 	spin_unlock(&lock); | 
 | 140 | 	wake_up_interruptible(&pcf_wait); | 
 | 141 | 	return IRQ_HANDLED; | 
 | 142 | } | 
 | 143 |  | 
 | 144 |  | 
 | 145 | static int pcf_isa_init(void) | 
 | 146 | { | 
 | 147 | 	spin_lock_init(&lock); | 
 | 148 | 	if (!mmapped) { | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 149 | 		if (!request_region(base, 2, pcf_isa_ops.name)) { | 
 | 150 | 			printk(KERN_ERR "%s: requested I/O region (%#x:2) is " | 
 | 151 | 			       "in use\n", pcf_isa_ops.name, base); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | 			return -ENODEV; | 
 | 153 | 		} | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 154 | 		base_iomem = ioport_map(base, 2); | 
 | 155 | 		if (!base_iomem) { | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 156 | 			printk(KERN_ERR "%s: remap of I/O region %#x failed\n", | 
 | 157 | 			       pcf_isa_ops.name, base); | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 158 | 			release_region(base, 2); | 
 | 159 | 			return -ENODEV; | 
 | 160 | 		} | 
 | 161 | 	} else { | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 162 | 		if (!request_mem_region(base, 2, pcf_isa_ops.name)) { | 
 | 163 | 			printk(KERN_ERR "%s: requested memory region (%#x:2) " | 
 | 164 | 			       "is in use\n", pcf_isa_ops.name, base); | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 165 | 			return -ENODEV; | 
 | 166 | 		} | 
 | 167 | 		base_iomem = ioremap(base, 2); | 
 | 168 | 		if (base_iomem == NULL) { | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 169 | 			printk(KERN_ERR "%s: remap of memory region %#x " | 
 | 170 | 			       "failed\n", pcf_isa_ops.name, base); | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 171 | 			release_mem_region(base, 2); | 
 | 172 | 			return -ENODEV; | 
 | 173 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | 	} | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 175 | 	pr_debug("%s: registers %#x remapped to %p\n", pcf_isa_ops.name, base, | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 176 | 		 base_iomem); | 
 | 177 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | 	if (irq > 0) { | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 179 | 		if (request_irq(irq, pcf_isa_handler, 0, pcf_isa_ops.name, | 
 | 180 | 				NULL) < 0) { | 
 | 181 | 			printk(KERN_ERR "%s: Request irq%d failed\n", | 
 | 182 | 			       pcf_isa_ops.name, irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | 			irq = 0; | 
 | 184 | 		} else | 
 | 185 | 			enable_irq(irq); | 
 | 186 | 	} | 
 | 187 | 	return 0; | 
 | 188 | } | 
 | 189 |  | 
 | 190 | /* ------------------------------------------------------------------------ | 
 | 191 |  * Encapsulate the above functions in the correct operations structure. | 
 | 192 |  * This is only done when more than one hardware adapter is supported. | 
 | 193 |  */ | 
 | 194 | static struct i2c_algo_pcf_data pcf_isa_data = { | 
 | 195 | 	.setpcf	    = pcf_isa_setbyte, | 
 | 196 | 	.getpcf	    = pcf_isa_getbyte, | 
 | 197 | 	.getown	    = pcf_isa_getown, | 
 | 198 | 	.getclock   = pcf_isa_getclock, | 
 | 199 | 	.waitforpin = pcf_isa_waitforpin, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | }; | 
 | 201 |  | 
 | 202 | static struct i2c_adapter pcf_isa_ops = { | 
 | 203 | 	.owner		= THIS_MODULE, | 
| Jean Delvare | 3401b2f | 2008-07-14 22:38:29 +0200 | [diff] [blame] | 204 | 	.class		= I2C_CLASS_HWMON | I2C_CLASS_SPD, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | 	.id		= I2C_HW_P_ELEK, | 
 | 206 | 	.algo_data	= &pcf_isa_data, | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 207 | 	.name		= "i2c-elektor", | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | }; | 
 | 209 |  | 
| Jean Delvare | 4a5d303 | 2007-05-01 23:26:30 +0200 | [diff] [blame] | 210 | static int __devinit elektor_match(struct device *dev, unsigned int id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { | 
 | 212 | #ifdef __alpha__ | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 213 | 	/* check to see we have memory mapped PCF8584 connected to the | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | 	Cypress cy82c693 PCI-ISA bridge as on UP2000 board */ | 
 | 215 | 	if (base == 0) { | 
 | 216 | 		struct pci_dev *cy693_dev; | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 217 |  | 
 | 218 | 		cy693_dev = pci_get_device(PCI_VENDOR_ID_CONTAQ, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | 					   PCI_DEVICE_ID_CONTAQ_82C693, NULL); | 
 | 220 | 		if (cy693_dev) { | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 221 | 			unsigned char config; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | 			/* yeap, we've found cypress, let's check config */ | 
 | 223 | 			if (!pci_read_config_byte(cy693_dev, 0x47, &config)) { | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 224 |  | 
| Jean Delvare | 4a5d303 | 2007-05-01 23:26:30 +0200 | [diff] [blame] | 225 | 				dev_dbg(dev, "found cy82c693, config " | 
 | 226 | 					"register 0x47 = 0x%02x\n", config); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 |  | 
 | 228 | 				/* UP2000 board has this register set to 0xe1, | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 229 | 				   but the most significant bit as seems can be | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | 				   reset during the proper initialisation | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 231 | 				   sequence if guys from API decides to do that | 
 | 232 | 				   (so, we can even enable Tsunami Pchip | 
 | 233 | 				   window for the upper 1 Gb) */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 |  | 
 | 235 | 				/* so just check for ROMCS at 0xe0000, | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 236 | 				   ROMCS enabled for writes | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | 				   and external XD Bus buffer in use. */ | 
 | 238 | 				if ((config & 0x7f) == 0x61) { | 
 | 239 | 					/* seems to be UP2000 like board */ | 
 | 240 | 					base = 0xe0000; | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 241 | 					mmapped = 1; | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 242 | 					/* UP2000 drives ISA with | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | 					   8.25 MHz (PCI/4) clock | 
 | 244 | 					   (this can be read from cypress) */ | 
 | 245 | 					clock = I2C_PCF_CLK | I2C_PCF_TRNS90; | 
| Jean Delvare | 4a5d303 | 2007-05-01 23:26:30 +0200 | [diff] [blame] | 246 | 					dev_info(dev, "found API UP2000 like " | 
 | 247 | 						 "board, will probe PCF8584 " | 
 | 248 | 						 "later\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | 				} | 
 | 250 | 			} | 
 | 251 | 			pci_dev_put(cy693_dev); | 
 | 252 | 		} | 
 | 253 | 	} | 
 | 254 | #endif | 
 | 255 |  | 
 | 256 | 	/* sanity checks for mmapped I/O */ | 
 | 257 | 	if (mmapped && base < 0xc8000) { | 
| Jean Delvare | 4a5d303 | 2007-05-01 23:26:30 +0200 | [diff] [blame] | 258 | 		dev_err(dev, "incorrect base address (%#x) specified " | 
 | 259 | 		       "for mmapped I/O\n", base); | 
 | 260 | 		return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | 	} | 
 | 262 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | 	if (base == 0) { | 
 | 264 | 		base = DEFAULT_BASE; | 
 | 265 | 	} | 
| Jean Delvare | 4a5d303 | 2007-05-01 23:26:30 +0200 | [diff] [blame] | 266 | 	return 1; | 
 | 267 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 |  | 
| Jean Delvare | 4a5d303 | 2007-05-01 23:26:30 +0200 | [diff] [blame] | 269 | static int __devinit elektor_probe(struct device *dev, unsigned int id) | 
 | 270 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | 	init_waitqueue_head(&pcf_wait); | 
 | 272 | 	if (pcf_isa_init()) | 
 | 273 | 		return -ENODEV; | 
| Jean Delvare | 4a5d303 | 2007-05-01 23:26:30 +0200 | [diff] [blame] | 274 | 	pcf_isa_ops.dev.parent = dev; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | 	if (i2c_pcf_add_bus(&pcf_isa_ops) < 0) | 
 | 276 | 		goto fail; | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 277 |  | 
| Jean Delvare | 4a5d303 | 2007-05-01 23:26:30 +0200 | [diff] [blame] | 278 | 	dev_info(dev, "found device at %#x\n", base); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 |  | 
 | 280 | 	return 0; | 
 | 281 |  | 
 | 282 |  fail: | 
 | 283 | 	if (irq > 0) { | 
 | 284 | 		disable_irq(irq); | 
 | 285 | 		free_irq(irq, NULL); | 
 | 286 | 	} | 
 | 287 |  | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 288 | 	if (!mmapped) { | 
 | 289 | 		ioport_unmap(base_iomem); | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 290 | 		release_region(base, 2); | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 291 | 	} else { | 
 | 292 | 		iounmap(base_iomem); | 
 | 293 | 		release_mem_region(base, 2); | 
 | 294 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | 	return -ENODEV; | 
 | 296 | } | 
 | 297 |  | 
| Jean Delvare | 4a5d303 | 2007-05-01 23:26:30 +0200 | [diff] [blame] | 298 | static int __devexit elektor_remove(struct device *dev, unsigned int id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | { | 
| Jean Delvare | 3269711 | 2006-12-10 21:21:33 +0100 | [diff] [blame] | 300 | 	i2c_del_adapter(&pcf_isa_ops); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 |  | 
 | 302 | 	if (irq > 0) { | 
 | 303 | 		disable_irq(irq); | 
 | 304 | 		free_irq(irq, NULL); | 
 | 305 | 	} | 
 | 306 |  | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 307 | 	if (!mmapped) { | 
 | 308 | 		ioport_unmap(base_iomem); | 
| Stig Telfer | fe3d6a9 | 2005-10-08 00:23:27 +0200 | [diff] [blame] | 309 | 		release_region(base, 2); | 
| Stig Telfer | 3634ff6 | 2005-10-08 00:21:48 +0200 | [diff] [blame] | 310 | 	} else { | 
 | 311 | 		iounmap(base_iomem); | 
 | 312 | 		release_mem_region(base, 2); | 
 | 313 | 	} | 
| Jean Delvare | 4a5d303 | 2007-05-01 23:26:30 +0200 | [diff] [blame] | 314 |  | 
 | 315 | 	return 0; | 
 | 316 | } | 
 | 317 |  | 
 | 318 | static struct isa_driver i2c_elektor_driver = { | 
 | 319 | 	.match		= elektor_match, | 
 | 320 | 	.probe		= elektor_probe, | 
 | 321 | 	.remove		= __devexit_p(elektor_remove), | 
 | 322 | 	.driver = { | 
 | 323 | 		.owner	= THIS_MODULE, | 
 | 324 | 		.name	= "i2c-elektor", | 
 | 325 | 	}, | 
 | 326 | }; | 
 | 327 |  | 
 | 328 | static int __init i2c_pcfisa_init(void) | 
 | 329 | { | 
 | 330 | 	return isa_register_driver(&i2c_elektor_driver, 1); | 
 | 331 | } | 
 | 332 |  | 
 | 333 | static void __exit i2c_pcfisa_exit(void) | 
 | 334 | { | 
 | 335 | 	isa_unregister_driver(&i2c_elektor_driver); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | } | 
 | 337 |  | 
 | 338 | MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>"); | 
 | 339 | MODULE_DESCRIPTION("I2C-Bus adapter routines for PCF8584 ISA bus adapter"); | 
 | 340 | MODULE_LICENSE("GPL"); | 
 | 341 |  | 
 | 342 | module_param(base, int, 0); | 
 | 343 | module_param(irq, int, 0); | 
 | 344 | module_param(clock, int, 0); | 
 | 345 | module_param(own, int, 0); | 
 | 346 | module_param(mmapped, int, 0); | 
 | 347 |  | 
 | 348 | module_init(i2c_pcfisa_init); | 
 | 349 | module_exit(i2c_pcfisa_exit); |