aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorStig Telfer <stig@lizardlogic.co.uk>2005-10-07 18:21:48 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2005-10-28 17:02:10 -0400
commit3634ff6a32e90d9db0ec19297e80059143c1aa7f (patch)
treec07cf34e839b70d9ab1c604b179943b199d542f3 /drivers/i2c
parent00bffb6e29c5ef12cea7904905f8b959187076c9 (diff)
[PATCH] i2c: Fix i2c-elektor on Alpha
This patch updates the i2c-elektor driver, enabling it to compile cleanly, load and run. The key change is that it uses the new __iomem/iowrite8/ioread8 functions to abstract the direct or memory-mapped variants of register access. Also, the original driver would crash on module load on the Alpha because the PCI memory region was not remapped into kernel memory. I have managed the following testing: * compiled and tested it on my Alpha UP2000+ system. * compiles cleanly for x86 but I don't have the hardware to test. Signed-off-by: Stig Telfer <stig@lizardlogic.co.uk> Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/i2c-elektor.c74
1 files changed, 49 insertions, 25 deletions
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index 6930b660e508..75b4b442a636 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -46,6 +46,8 @@
46#define DEFAULT_BASE 0x330 46#define DEFAULT_BASE 0x330
47 47
48static int base; 48static int base;
49static u8 __iomem *base_iomem;
50
49static int irq; 51static int irq;
50static int clock = 0x1c; 52static int clock = 0x1c;
51static int own = 0x55; 53static int own = 0x55;
@@ -64,36 +66,27 @@ static spinlock_t lock;
64 66
65static void pcf_isa_setbyte(void *data, int ctl, int val) 67static void pcf_isa_setbyte(void *data, int ctl, int val)
66{ 68{
67 int address = ctl ? (base + 1) : base; 69 u8 __iomem *address = ctl ? (base_iomem + 1) : base_iomem;
68 70
69 /* enable irq if any specified for serial operation */ 71 /* enable irq if any specified for serial operation */
70 if (ctl && irq && (val & I2C_PCF_ESO)) { 72 if (ctl && irq && (val & I2C_PCF_ESO)) {
71 val |= I2C_PCF_ENI; 73 val |= I2C_PCF_ENI;
72 } 74 }
73 75
74 pr_debug("i2c-elektor: Write 0x%X 0x%02X\n", address, val & 255); 76 pr_debug("i2c-elektor: Write %p 0x%02X\n", address, val);
75 77 iowrite8(val, address);
76 switch (mmapped) { 78#ifdef __alpha__
77 case 0: /* regular I/O */ 79 /* API UP2000 needs some hardware fudging to make the write stick */
78 outb(val, address); 80 iowrite8(val, address);
79 break; 81#endif
80 case 2: /* double mapped I/O needed for UP2000 board,
81 I don't know why this... */
82 writeb(val, (void *)address);
83 /* fall */
84 case 1: /* memory mapped I/O */
85 writeb(val, (void *)address);
86 break;
87 }
88} 82}
89 83
90static int pcf_isa_getbyte(void *data, int ctl) 84static int pcf_isa_getbyte(void *data, int ctl)
91{ 85{
92 int address = ctl ? (base + 1) : base; 86 u8 __iomem *address = ctl ? (base_iomem + 1) : base_iomem;
93 int val = mmapped ? readb((void *)address) : inb(address); 87 int val = ioread8(address);
94
95 pr_debug("i2c-elektor: Read 0x%X 0x%02X\n", address, val);
96 88
89 pr_debug("i2c-elektor: Read %p 0x%02X\n", address, val);
97 return (val); 90 return (val);
98} 91}
99 92
@@ -155,7 +148,30 @@ static int pcf_isa_init(void)
155 "is in use.\n", base); 148 "is in use.\n", base);
156 return -ENODEV; 149 return -ENODEV;
157 } 150 }
151 base_iomem = ioport_map(base, 2);
152 if (!base_iomem) {
153 printk(KERN_ERR "i2c-elektor: remap of I/O region "
154 "%#x failed\n", base);
155 release_region(base, 2);
156 return -ENODEV;
157 }
158 } else {
159 if (!request_mem_region(base, 2, "i2c-elektor")) {
160 printk(KERN_ERR "i2c-elektor: requested memory region "
161 "(%#x:2) is in use\n", base);
162 return -ENODEV;
163 }
164 base_iomem = ioremap(base, 2);
165 if (base_iomem == NULL) {
166 printk(KERN_ERR "i2c-elektor: remap of memory region "
167 "%#x failed\n", base);
168 release_mem_region(base, 2);
169 return -ENODEV;
170 }
158 } 171 }
172 pr_debug("i2c-elektor: registers %#x remapped to %p\n", base,
173 base_iomem);
174
159 if (irq > 0) { 175 if (irq > 0) {
160 if (request_irq(irq, pcf_isa_handler, 0, "PCF8584", NULL) < 0) { 176 if (request_irq(irq, pcf_isa_handler, 0, "PCF8584", NULL) < 0) {
161 printk(KERN_ERR "i2c-elektor: Request irq%d failed\n", irq); 177 printk(KERN_ERR "i2c-elektor: Request irq%d failed\n", irq);
@@ -200,7 +216,7 @@ static int __init i2c_pcfisa_init(void)
200 cy693_dev = pci_get_device(PCI_VENDOR_ID_CONTAQ, 216 cy693_dev = pci_get_device(PCI_VENDOR_ID_CONTAQ,
201 PCI_DEVICE_ID_CONTAQ_82C693, NULL); 217 PCI_DEVICE_ID_CONTAQ_82C693, NULL);
202 if (cy693_dev) { 218 if (cy693_dev) {
203 char config; 219 unsigned char config;
204 /* yeap, we've found cypress, let's check config */ 220 /* yeap, we've found cypress, let's check config */
205 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) { 221 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) {
206 222
@@ -219,9 +235,7 @@ static int __init i2c_pcfisa_init(void)
219 if ((config & 0x7f) == 0x61) { 235 if ((config & 0x7f) == 0x61) {
220 /* seems to be UP2000 like board */ 236 /* seems to be UP2000 like board */
221 base = 0xe0000; 237 base = 0xe0000;
222 /* I don't know why we need to 238 mmapped = 1;
223 write twice */
224 mmapped = 2;
225 /* UP2000 drives ISA with 239 /* UP2000 drives ISA with
226 8.25 MHz (PCI/4) clock 240 8.25 MHz (PCI/4) clock
227 (this can be read from cypress) */ 241 (this can be read from cypress) */
@@ -262,8 +276,13 @@ static int __init i2c_pcfisa_init(void)
262 free_irq(irq, NULL); 276 free_irq(irq, NULL);
263 } 277 }
264 278
265 if (!mmapped) 279 if (!mmapped) {
280 ioport_unmap(base_iomem);
266 release_region(base , 2); 281 release_region(base , 2);
282 } else {
283 iounmap(base_iomem);
284 release_mem_region(base, 2);
285 }
267 return -ENODEV; 286 return -ENODEV;
268} 287}
269 288
@@ -276,8 +295,13 @@ static void i2c_pcfisa_exit(void)
276 free_irq(irq, NULL); 295 free_irq(irq, NULL);
277 } 296 }
278 297
279 if (!mmapped) 298 if (!mmapped) {
299 ioport_unmap(base_iomem);
280 release_region(base , 2); 300 release_region(base , 2);
301 } else {
302 iounmap(base_iomem);
303 release_mem_region(base, 2);
304 }
281} 305}
282 306
283MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>"); 307MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");