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