[ patch .24-rc0 5/5 ] SuperIO locks coordinator - use in other hwmon/*.c

2007-10-14 Thread Jim Cromie

05 - use superio-locks in rest of drivers/hwmon/*.c

this patch is compile-tested only, please review for sanity before you 
try running them.  Things to look for - missing superio_release(),

opportunities to use superio_devid(), superio_inw(), etc.


Signed-off-by:  Jim Cromie <[EMAIL PROTECTED]>
---
hwmon-superio-others
Kconfig  |6 +++
f71805f.c|   86 +++---
it87.c   |   80 +++---
smsc47b397.c |   63 -
smsc47m1.c   |   69 +
vt1211.c |   70 +
w83627ehf.c  |  110 +--
7 files changed, 188 insertions(+), 296 deletions(-)

diff -ruNp -X dontdiff -X exclude-diffs 
hwmon-fan-push-offset/drivers/hwmon/f71805f.c 
hwmon-superio.old/drivers/hwmon/f71805f.c
--- hwmon-fan-push-offset/drivers/hwmon/f71805f.c   2007-10-14 
13:00:24.0 -0600
+++ hwmon-superio.old/drivers/hwmon/f71805f.c   2007-10-14 17:22:23.0 
-0600
@@ -39,6 +39,7 @@
#include 
#include 
#include 
+#include 
#include 

static struct platform_device *pdev;
@@ -52,8 +53,6 @@ enum kinds { f71805f, f71872f };

#define F71805F_LD_HWM  0x04

-#define SIO_REG_LDSEL  0x07/* Logical device select */
-#define SIO_REG_DEVID  0x20/* Device ID (2 bytes) */
#define SIO_REG_DEVREV  0x22/* Device revision */
#define SIO_REG_MANID   0x23/* Fintek ID (2 bytes) */
#define SIO_REG_FNSEL1  0x29/* Multi Function Select 1 (F71872F) */
@@ -64,43 +63,15 @@ enum kinds { f71805f, f71872f };
#define SIO_F71805F_ID  0x0406
#define SIO_F71872F_ID  0x0341

-static inline int
-superio_inb(int base, int reg)
-{
-   outb(reg, base);
-   return inb(base + 1);
-}
-
-static int
-superio_inw(int base, int reg)
-{
-   int val;
-   outb(reg++, base);
-   val = inb(base + 1) << 8;
-   outb(reg, base);
-   val |= inb(base + 1);
-   return val;
-}
+static struct superio* gate;

-static inline void
-superio_select(int base, int ld)
-{
-   outb(SIO_REG_LDSEL, base);
-   outb(ld, base + 1);
-}
-
-static inline void
-superio_enter(int base)
-{
-   outb(0x87, base);
-   outb(0x87, base);
-}
-
-static inline void
-superio_exit(int base)
-{
-   outb(0xaa, base);
-}
+static __devinit struct superio_search where = {
+   .cmdreg_addrs = { 0x2e, 0x4e },
+   .device_ids   = { SIO_F71805F_ID, SIO_F71872F_ID, 0 },
+   .devid_word   = 1,
+   .enter_seq= { 0x87, 0x87 },
+   .exit_seq = { 0xAA }
+};

/*
 * ISA constants
@@ -1480,31 +1451,33 @@ exit:
return err;
}

-static int __init f71805f_find(int sioaddr, unsigned short *address,
-  struct f71805f_sio_data *sio_data)
+static int __init f71805f_find(struct f71805f_sio_data *sio_data)
{
int err = -ENODEV;
-   u16 devid;
+   u16 devid, address;

static const char *names[] = {
"F71805F/FG",
"F71872F/FG or F71806F/FG",
};
-
-   superio_enter(sioaddr);
-
-   devid = superio_inw(sioaddr, SIO_REG_MANID);
+   gate = superio_find();
+   if (!gate) {
+   printk(KERN_WARNING "pc87360: superio port not detected, "
+  "module not intalled.\n");
+   return -ENODEV;
+   }
+   superio_enter(gate);
+   devid = superio_inw(gate, SIO_REG_MANID);
if (devid != SIO_FINTEK_ID)
goto exit;

-   devid = superio_inw(sioaddr, SIO_REG_DEVID);
switch (devid) {
case SIO_F71805F_ID:
sio_data->kind = f71805f;
break;
case SIO_F71872F_ID:
sio_data->kind = f71872f;
-   sio_data->fnsel1 = superio_inb(sioaddr, SIO_REG_FNSEL1);
+   sio_data->fnsel1 = superio_inb(gate, SIO_REG_FNSEL1);
break;
default:
printk(KERN_INFO DRVNAME ": Unsupported Fintek device, "
@@ -1512,28 +1485,28 @@ static int __init f71805f_find(int sioad
goto exit;
}

-   superio_select(sioaddr, F71805F_LD_HWM);
-   if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
+   superio_select(gate, F71805F_LD_HWM);
+   if (!(superio_inb(gate, SIO_REG_ENABLE) & 0x01)) {
printk(KERN_WARNING DRVNAME ": Device not activated, "
   "skipping\n");
goto exit;
}

-   *address = superio_inw(sioaddr, SIO_REG_ADDR);
-   if (*address == 0) {
+   address = superio_inw(gate, SIO_REG_ADDR);
+   if (address == 0) {
printk(KERN_WARNING DRVNAME ": Base address not set, "
   "skipping\n");
goto exit;
}
-   *address &= ~(REGION_LENGTH - 1);   /* Ignore 3 LSB */
+   address &= ~(REGION_LENGTH - 1);/* Ignore 3 

[ patch .24-rc0 5/5 ] SuperIO locks coordinator - use in other hwmon/*.c

2007-10-14 Thread Jim Cromie

05 - use superio-locks in rest of drivers/hwmon/*.c

this patch is compile-tested only, please review for sanity before you 
try running them.  Things to look for - missing superio_release(),

opportunities to use superio_devid(), superio_inw(), etc.


Signed-off-by:  Jim Cromie [EMAIL PROTECTED]
---
hwmon-superio-others
Kconfig  |6 +++
f71805f.c|   86 +++---
it87.c   |   80 +++---
smsc47b397.c |   63 -
smsc47m1.c   |   69 +
vt1211.c |   70 +
w83627ehf.c  |  110 +--
7 files changed, 188 insertions(+), 296 deletions(-)

diff -ruNp -X dontdiff -X exclude-diffs 
hwmon-fan-push-offset/drivers/hwmon/f71805f.c 
hwmon-superio.old/drivers/hwmon/f71805f.c
--- hwmon-fan-push-offset/drivers/hwmon/f71805f.c   2007-10-14 
13:00:24.0 -0600
+++ hwmon-superio.old/drivers/hwmon/f71805f.c   2007-10-14 17:22:23.0 
-0600
@@ -39,6 +39,7 @@
#include linux/mutex.h
#include linux/sysfs.h
#include linux/ioport.h
+#include linux/superio-locks.h
#include asm/io.h

static struct platform_device *pdev;
@@ -52,8 +53,6 @@ enum kinds { f71805f, f71872f };

#define F71805F_LD_HWM  0x04

-#define SIO_REG_LDSEL  0x07/* Logical device select */
-#define SIO_REG_DEVID  0x20/* Device ID (2 bytes) */
#define SIO_REG_DEVREV  0x22/* Device revision */
#define SIO_REG_MANID   0x23/* Fintek ID (2 bytes) */
#define SIO_REG_FNSEL1  0x29/* Multi Function Select 1 (F71872F) */
@@ -64,43 +63,15 @@ enum kinds { f71805f, f71872f };
#define SIO_F71805F_ID  0x0406
#define SIO_F71872F_ID  0x0341

-static inline int
-superio_inb(int base, int reg)
-{
-   outb(reg, base);
-   return inb(base + 1);
-}
-
-static int
-superio_inw(int base, int reg)
-{
-   int val;
-   outb(reg++, base);
-   val = inb(base + 1)  8;
-   outb(reg, base);
-   val |= inb(base + 1);
-   return val;
-}
+static struct superio* gate;

-static inline void
-superio_select(int base, int ld)
-{
-   outb(SIO_REG_LDSEL, base);
-   outb(ld, base + 1);
-}
-
-static inline void
-superio_enter(int base)
-{
-   outb(0x87, base);
-   outb(0x87, base);
-}
-
-static inline void
-superio_exit(int base)
-{
-   outb(0xaa, base);
-}
+static __devinit struct superio_search where = {
+   .cmdreg_addrs = { 0x2e, 0x4e },
+   .device_ids   = { SIO_F71805F_ID, SIO_F71872F_ID, 0 },
+   .devid_word   = 1,
+   .enter_seq= { 0x87, 0x87 },
+   .exit_seq = { 0xAA }
+};

/*
 * ISA constants
@@ -1480,31 +1451,33 @@ exit:
return err;
}

-static int __init f71805f_find(int sioaddr, unsigned short *address,
-  struct f71805f_sio_data *sio_data)
+static int __init f71805f_find(struct f71805f_sio_data *sio_data)
{
int err = -ENODEV;
-   u16 devid;
+   u16 devid, address;

static const char *names[] = {
F71805F/FG,
F71872F/FG or F71806F/FG,
};
-
-   superio_enter(sioaddr);
-
-   devid = superio_inw(sioaddr, SIO_REG_MANID);
+   gate = superio_find(where);
+   if (!gate) {
+   printk(KERN_WARNING pc87360: superio port not detected, 
+  module not intalled.\n);
+   return -ENODEV;
+   }
+   superio_enter(gate);
+   devid = superio_inw(gate, SIO_REG_MANID);
if (devid != SIO_FINTEK_ID)
goto exit;

-   devid = superio_inw(sioaddr, SIO_REG_DEVID);
switch (devid) {
case SIO_F71805F_ID:
sio_data-kind = f71805f;
break;
case SIO_F71872F_ID:
sio_data-kind = f71872f;
-   sio_data-fnsel1 = superio_inb(sioaddr, SIO_REG_FNSEL1);
+   sio_data-fnsel1 = superio_inb(gate, SIO_REG_FNSEL1);
break;
default:
printk(KERN_INFO DRVNAME : Unsupported Fintek device, 
@@ -1512,28 +1485,28 @@ static int __init f71805f_find(int sioad
goto exit;
}

-   superio_select(sioaddr, F71805F_LD_HWM);
-   if (!(superio_inb(sioaddr, SIO_REG_ENABLE)  0x01)) {
+   superio_select(gate, F71805F_LD_HWM);
+   if (!(superio_inb(gate, SIO_REG_ENABLE)  0x01)) {
printk(KERN_WARNING DRVNAME : Device not activated, 
   skipping\n);
goto exit;
}

-   *address = superio_inw(sioaddr, SIO_REG_ADDR);
-   if (*address == 0) {
+   address = superio_inw(gate, SIO_REG_ADDR);
+   if (address == 0) {
printk(KERN_WARNING DRVNAME : Base address not set, 
   skipping\n);
goto exit;
}
-   *address = ~(REGION_LENGTH - 1);   /* Ignore 3 LSB */
+