Commit 3634ff6a authored by Stig Telfer's avatar Stig Telfer Committed by Greg Kroah-Hartman

[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: default avatarStig Telfer <stig@lizardlogic.co.uk>
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 00bffb6e
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
#define DEFAULT_BASE 0x330 #define DEFAULT_BASE 0x330
static int base; static int base;
static u8 __iomem *base_iomem;
static int irq; static int irq;
static int clock = 0x1c; static int clock = 0x1c;
static int own = 0x55; static int own = 0x55;
...@@ -64,36 +66,27 @@ static spinlock_t lock; ...@@ -64,36 +66,27 @@ static spinlock_t lock;
static void pcf_isa_setbyte(void *data, int ctl, int val) static void pcf_isa_setbyte(void *data, int ctl, int val)
{ {
int address = ctl ? (base + 1) : base; u8 __iomem *address = ctl ? (base_iomem + 1) : base_iomem;
/* enable irq if any specified for serial operation */ /* enable irq if any specified for serial operation */
if (ctl && irq && (val & I2C_PCF_ESO)) { if (ctl && irq && (val & I2C_PCF_ESO)) {
val |= I2C_PCF_ENI; val |= I2C_PCF_ENI;
} }
pr_debug("i2c-elektor: Write 0x%X 0x%02X\n", address, val & 255); pr_debug("i2c-elektor: Write %p 0x%02X\n", address, val);
iowrite8(val, address);
switch (mmapped) { #ifdef __alpha__
case 0: /* regular I/O */ /* API UP2000 needs some hardware fudging to make the write stick */
outb(val, address); iowrite8(val, address);
break; #endif
case 2: /* double mapped I/O needed for UP2000 board,
I don't know why this... */
writeb(val, (void *)address);
/* fall */
case 1: /* memory mapped I/O */
writeb(val, (void *)address);
break;
}
} }
static int pcf_isa_getbyte(void *data, int ctl) static int pcf_isa_getbyte(void *data, int ctl)
{ {
int address = ctl ? (base + 1) : base; u8 __iomem *address = ctl ? (base_iomem + 1) : base_iomem;
int val = mmapped ? readb((void *)address) : inb(address); int val = ioread8(address);
pr_debug("i2c-elektor: Read 0x%X 0x%02X\n", address, val);
pr_debug("i2c-elektor: Read %p 0x%02X\n", address, val);
return (val); return (val);
} }
...@@ -155,7 +148,30 @@ static int pcf_isa_init(void) ...@@ -155,7 +148,30 @@ static int pcf_isa_init(void)
"is in use.\n", base); "is in use.\n", base);
return -ENODEV; return -ENODEV;
} }
base_iomem = ioport_map(base, 2);
if (!base_iomem) {
printk(KERN_ERR "i2c-elektor: remap of I/O region "
"%#x failed\n", base);
release_region(base, 2);
return -ENODEV;
} }
} else {
if (!request_mem_region(base, 2, "i2c-elektor")) {
printk(KERN_ERR "i2c-elektor: requested memory region "
"(%#x:2) is in use\n", base);
return -ENODEV;
}
base_iomem = ioremap(base, 2);
if (base_iomem == NULL) {
printk(KERN_ERR "i2c-elektor: remap of memory region "
"%#x failed\n", base);
release_mem_region(base, 2);
return -ENODEV;
}
}
pr_debug("i2c-elektor: registers %#x remapped to %p\n", base,
base_iomem);
if (irq > 0) { if (irq > 0) {
if (request_irq(irq, pcf_isa_handler, 0, "PCF8584", NULL) < 0) { if (request_irq(irq, pcf_isa_handler, 0, "PCF8584", NULL) < 0) {
printk(KERN_ERR "i2c-elektor: Request irq%d failed\n", irq); printk(KERN_ERR "i2c-elektor: Request irq%d failed\n", irq);
...@@ -200,7 +216,7 @@ static int __init i2c_pcfisa_init(void) ...@@ -200,7 +216,7 @@ static int __init i2c_pcfisa_init(void)
cy693_dev = pci_get_device(PCI_VENDOR_ID_CONTAQ, cy693_dev = pci_get_device(PCI_VENDOR_ID_CONTAQ,
PCI_DEVICE_ID_CONTAQ_82C693, NULL); PCI_DEVICE_ID_CONTAQ_82C693, NULL);
if (cy693_dev) { if (cy693_dev) {
char config; unsigned char config;
/* yeap, we've found cypress, let's check config */ /* yeap, we've found cypress, let's check config */
if (!pci_read_config_byte(cy693_dev, 0x47, &config)) { if (!pci_read_config_byte(cy693_dev, 0x47, &config)) {
...@@ -219,9 +235,7 @@ static int __init i2c_pcfisa_init(void) ...@@ -219,9 +235,7 @@ static int __init i2c_pcfisa_init(void)
if ((config & 0x7f) == 0x61) { if ((config & 0x7f) == 0x61) {
/* seems to be UP2000 like board */ /* seems to be UP2000 like board */
base = 0xe0000; base = 0xe0000;
/* I don't know why we need to mmapped = 1;
write twice */
mmapped = 2;
/* UP2000 drives ISA with /* UP2000 drives ISA with
8.25 MHz (PCI/4) clock 8.25 MHz (PCI/4) clock
(this can be read from cypress) */ (this can be read from cypress) */
...@@ -262,8 +276,13 @@ static int __init i2c_pcfisa_init(void) ...@@ -262,8 +276,13 @@ static int __init i2c_pcfisa_init(void)
free_irq(irq, NULL); free_irq(irq, NULL);
} }
if (!mmapped) if (!mmapped) {
ioport_unmap(base_iomem);
release_region(base , 2); release_region(base , 2);
} else {
iounmap(base_iomem);
release_mem_region(base, 2);
}
return -ENODEV; return -ENODEV;
} }
...@@ -276,8 +295,13 @@ static void i2c_pcfisa_exit(void) ...@@ -276,8 +295,13 @@ static void i2c_pcfisa_exit(void)
free_irq(irq, NULL); free_irq(irq, NULL);
} }
if (!mmapped) if (!mmapped) {
ioport_unmap(base_iomem);
release_region(base , 2); release_region(base , 2);
} else {
iounmap(base_iomem);
release_mem_region(base, 2);
}
} }
MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>"); MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment