From 6a2c82b4919c470f530709160cdfe6154eb40d1b Mon Sep 17 00:00:00 2001 From: Frodo Looijaard Date: Mon, 24 Jan 2000 20:37:01 +0000 Subject: [PATCH] `indent -kr -i8' on all kernel sources git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@707 7894878c-1315-0410-8ee3-d5d059ff63e0 --- kernel/busses/i2c-ali15x3.c | 633 ++++----- kernel/busses/i2c-amd756.c | 548 ++++---- kernel/busses/i2c-hydra.c | 58 +- kernel/busses/i2c-i801.c | 759 +++++------ kernel/busses/i2c-isa.c | 110 +- kernel/busses/i2c-piix4.c | 574 +++++---- kernel/busses/i2c-sis5595.c | 447 ++++--- kernel/busses/i2c-via.c | 89 +- kernel/busses/i2c-viapro.c | 595 +++++---- kernel/busses/i2c-voodoo3.c | 1136 ++++++++-------- kernel/chips/adm1021.c | 614 ++++----- kernel/chips/adm9240.c | 899 +++++++------ kernel/chips/bt869.c | 666 +++++----- kernel/chips/eeprom.c | 455 +++---- kernel/chips/gl518sm.c | 1364 ++++++++++---------- kernel/chips/gl520sm.c | 1101 ++++++++-------- kernel/chips/icspll.c | 342 ++--- kernel/chips/lm75.c | 404 +++--- kernel/chips/lm78.c | 953 +++++++------- kernel/chips/lm80.c | 816 ++++++------ kernel/chips/ltc1710.c | 365 +++--- kernel/chips/matorb.c | 322 ++--- kernel/chips/maxilife.c | 853 ++++++------ kernel/chips/sis5595.c | 816 ++++++------ kernel/chips/thmc50.c | 600 +++++---- kernel/chips/w83781d.c | 2437 +++++++++++++++++++---------------- kernel/include/i2c-isa.h | 6 +- kernel/include/sensors.h | 229 ++-- kernel/sensors.c | 1181 +++++++++-------- 29 files changed, 10217 insertions(+), 9155 deletions(-) diff --git a/kernel/busses/i2c-ali15x3.c b/kernel/busses/i2c-ali15x3.c index ee98dc7c..de351a29 100644 --- a/kernel/busses/i2c-ali15x3.c +++ b/kernel/busses/i2c-ali15x3.c @@ -86,7 +86,7 @@ #define SMBBLKDAT (6 + ali15x3_smba) /* PCI Address Constants */ -#define SMBCOM 0x004 +#define SMBCOM 0x004 #define SMBBA 0x014 #define SMBATPC 0x05B /* used to unlock xxxBA registers */ #define SMBHSTCFG 0x0E0 @@ -118,9 +118,9 @@ #define ALI15X3_BLOCK_CLR 0x80 /* ALI15X3 status register bits */ -#define ALI15X3_STS_IDLE 0x04 -#define ALI15X3_STS_BUSY 0x08 -#define ALI15X3_STS_DONE 0x10 +#define ALI15X3_STS_IDLE 0x04 +#define ALI15X3_STS_BUSY 0x08 +#define ALI15X3_STS_DONE 0x10 #define ALI15X3_STS_DEV 0x20 /* device error */ #define ALI15X3_STS_COLL 0x40 /* collision or no response */ #define ALI15X3_STS_TERM 0x80 /* terminated by abort */ @@ -132,13 +132,14 @@ static #else extern #endif - int __init i2c_ali15x3_init(void); +int __init i2c_ali15x3_init(void); static int __init ali15x3_cleanup(void); static int ali15x3_setup(void); -static s32 ali15x3_access(struct i2c_adapter *adap, u16 addr, - unsigned short flags,char read_write, - u8 command, int size, union i2c_smbus_data * data); -static void ali15x3_do_pause( unsigned int amount ); +static s32 ali15x3_access(struct i2c_adapter *adap, u16 addr, + unsigned short flags, char read_write, + u8 command, int size, + union i2c_smbus_data *data); +static void ali15x3_do_pause(unsigned int amount); static int ali15x3_transaction(void); static void ali15x3_inc(struct i2c_adapter *adapter); static void ali15x3_dec(struct i2c_adapter *adapter); @@ -147,28 +148,28 @@ static u32 ali15x3_func(struct i2c_adapter *adapter); #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ static struct i2c_algorithm smbus_algorithm = { - /* name */ "Non-I2C SMBus adapter", - /* id */ I2C_ALGO_SMBUS, - /* master_xfer */ NULL, - /* smbus_access */ ali15x3_access, - /* slave_send */ NULL, - /* slave_rcv */ NULL, - /* algo_control */ NULL, - /* functionality */ ali15x3_func, + /* name */ "Non-I2C SMBus adapter", + /* id */ I2C_ALGO_SMBUS, + /* master_xfer */ NULL, + /* smbus_access */ ali15x3_access, + /* slave_send */ NULL, + /* slave_rcv */ NULL, + /* algo_control */ NULL, + /* functionality */ ali15x3_func, }; static struct i2c_adapter ali15x3_adapter = { - "unset", - I2C_ALGO_SMBUS | I2C_HW_SMBUS_ALI15X3, - &smbus_algorithm, - NULL, - ali15x3_inc, - ali15x3_dec, - NULL, - NULL, + "unset", + I2C_ALGO_SMBUS | I2C_HW_SMBUS_ALI15X3, + &smbus_algorithm, + NULL, + ali15x3_inc, + ali15x3_dec, + NULL, + NULL, }; static int __initdata ali15x3_initialized; @@ -181,27 +182,27 @@ static unsigned short ali15x3_smba = 0; defined to make the transition easier. */ int ali15x3_setup(void) { - int error_return=0; - unsigned char temp; + int error_return = 0; + unsigned char temp; - struct pci_dev *ALI15X3_dev; + struct pci_dev *ALI15X3_dev; - /* First check whether we can access PCI at all */ - if (pci_present() == 0) { - printk("i2c-ali15x3.o: Error: No PCI-bus found!\n"); - error_return=-ENODEV; - goto END; - } + /* First check whether we can access PCI at all */ + if (pci_present() == 0) { + printk("i2c-ali15x3.o: Error: No PCI-bus found!\n"); + error_return = -ENODEV; + goto END; + } - /* Look for the ALI15X3, M7101 device */ - ALI15X3_dev = NULL; - ALI15X3_dev = pci_find_device(PCI_VENDOR_ID_AL, - PCI_DEVICE_ID_AL_M7101, ALI15X3_dev); - if(ALI15X3_dev == NULL) { - printk("i2c-ali15x3.o: Error: Can't detect ali15x3!\n"); - error_return=-ENODEV; - goto END; - } + /* Look for the ALI15X3, M7101 device */ + ALI15X3_dev = NULL; + ALI15X3_dev = pci_find_device(PCI_VENDOR_ID_AL, + PCI_DEVICE_ID_AL_M7101, ALI15X3_dev); + if (ALI15X3_dev == NULL) { + printk("i2c-ali15x3.o: Error: Can't detect ali15x3!\n"); + error_return = -ENODEV; + goto END; + } /* Check the following things: - SMB I/O address is initialized @@ -214,66 +215,71 @@ int ali15x3_setup(void) if the lock bits are 1, but in fact the address registers are zero unless you clear the lock bits. */ - pci_read_config_byte(ALI15X3_dev, SMBATPC, &temp); - if(temp & ALI15X3_LOCK) - { - temp &= ~ALI15X3_LOCK; - pci_write_config_byte(ALI15X3_dev, SMBATPC, temp); - } + pci_read_config_byte(ALI15X3_dev, SMBATPC, &temp); + if (temp & ALI15X3_LOCK) { + temp &= ~ALI15X3_LOCK; + pci_write_config_byte(ALI15X3_dev, SMBATPC, temp); + } /* Determine the address of the SMBus area */ - pci_read_config_word(ALI15X3_dev, SMBBA,&ali15x3_smba); - ali15x3_smba &= (0xffff & ~ (ALI15X3_SMB_IOSIZE - 1)); - if(ali15x3_smba == 0) { - printk("i2c-ali15x3.o: ALI15X3_smb region uninitialized - upgrade BIOS?\n"); - error_return=-ENODEV; - } + pci_read_config_word(ALI15X3_dev, SMBBA, &ali15x3_smba); + ali15x3_smba &= (0xffff & ~(ALI15X3_SMB_IOSIZE - 1)); + if (ali15x3_smba == 0) { + printk + ("i2c-ali15x3.o: ALI15X3_smb region uninitialized - upgrade BIOS?\n"); + error_return = -ENODEV; + } - if(error_return == -ENODEV) - goto END; + if (error_return == -ENODEV) + goto END; - if (check_region(ali15x3_smba, ALI15X3_SMB_IOSIZE)) { - printk("i2c-ali15x3.o: ALI15X3_smb region 0x%x already in use!\n", ali15x3_smba); - error_return=-ENODEV; - } + if (check_region(ali15x3_smba, ALI15X3_SMB_IOSIZE)) { + printk + ("i2c-ali15x3.o: ALI15X3_smb region 0x%x already in use!\n", + ali15x3_smba); + error_return = -ENODEV; + } - if(error_return == -ENODEV) - goto END; + if (error_return == -ENODEV) + goto END; /* check if whole device is enabled */ - pci_read_config_byte(ALI15X3_dev, SMBCOM, &temp); - if ((temp & 1) == 0) { - printk("SMBUS: Error: SMB device not enabled - upgrade BIOS?\n"); - error_return=-ENODEV; - goto END; - } + pci_read_config_byte(ALI15X3_dev, SMBCOM, &temp); + if ((temp & 1) == 0) { + printk + ("SMBUS: Error: SMB device not enabled - upgrade BIOS?\n"); + error_return = -ENODEV; + goto END; + } /* Is SMB Host controller enabled? */ - pci_read_config_byte(ALI15X3_dev, SMBHSTCFG, &temp); + pci_read_config_byte(ALI15X3_dev, SMBHSTCFG, &temp); #ifdef FORCE_ALI15X3_ENABLE /* This should never need to be done. NOTE: This assumes I/O space and other allocations WERE done by the Bios! Don't complain if your hardware does weird things after enabling this. :') Check for Bios updates before resorting to this. */ - if ((temp & 1) == 0) { - pci_write_config_byte(ALI15X3_dev, SMBHSTCFG, temp | 1); - printk("i2c-ali15x3.o: WARNING: ALI15X3 SMBus interface has been FORCEFULLY " - "ENABLED!!\n"); - } -#else /* FORCE_ALI15X3_ENABLE */ - if ((temp & 1) == 0) { - printk("SMBUS: Error: Host SMBus controller not enabled - upgrade BIOS?\n"); - error_return=-ENODEV; - goto END; - } -#endif /* FORCE_ALI15X3_ENABLE */ + if ((temp & 1) == 0) { + pci_write_config_byte(ALI15X3_dev, SMBHSTCFG, temp | 1); + printk + ("i2c-ali15x3.o: WARNING: ALI15X3 SMBus interface has been FORCEFULLY " + "ENABLED!!\n"); + } +#else /* FORCE_ALI15X3_ENABLE */ + if ((temp & 1) == 0) { + printk + ("SMBUS: Error: Host SMBus controller not enabled - upgrade BIOS?\n"); + error_return = -ENODEV; + goto END; + } +#endif /* FORCE_ALI15X3_ENABLE */ /* set SMB clock to 74KHz as recommended in data sheet */ - pci_write_config_byte(ALI15X3_dev, SMBCLK, 0x20); + pci_write_config_byte(ALI15X3_dev, SMBCLK, 0x20); - /* Everything is happy, let's grab the memory and set things up. */ - request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE, "ali15x3-smb"); + /* Everything is happy, let's grab the memory and set things up. */ + request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE, "ali15x3-smb"); #ifdef DEBUG /* @@ -283,43 +289,44 @@ int ali15x3_setup(void) if ((....... & 0x0F) == 1) printk("i2c-ali15x3.o: ALI15X3 using Interrupt 9 for SMBus.\n"); */ - pci_read_config_byte(ALI15X3_dev, SMBREV, &temp); - printk("i2c-ali15x3.o: SMBREV = 0x%X\n",temp); - printk("i2c-ali15x3.o: ALI15X3_smba = 0x%X\n",ali15x3_smba); -#endif /* DEBUG */ + pci_read_config_byte(ALI15X3_dev, SMBREV, &temp); + printk("i2c-ali15x3.o: SMBREV = 0x%X\n", temp); + printk("i2c-ali15x3.o: ALI15X3_smba = 0x%X\n", ali15x3_smba); +#endif /* DEBUG */ -END: - return error_return; + END: + return error_return; } /* Internally used pause function */ -void ali15x3_do_pause( unsigned int amount ) +void ali15x3_do_pause(unsigned int amount) { - current->state = TASK_INTERRUPTIBLE; - schedule_timeout(amount); + current->state = TASK_INTERRUPTIBLE; + schedule_timeout(amount); } /* Another internally used function */ -int ali15x3_transaction(void) +int ali15x3_transaction(void) { - int temp; - int result=0; - int timeout=0; + int temp; + int result = 0; + int timeout = 0; #ifdef DEBUG - printk("i2c-ali15x3.o: Transaction (pre): STS=%02x, CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, " - "DAT1=%02x\n", - inb_p(SMBHSTSTS), inb_p(SMBHSTCNT),inb_p(SMBHSTCMD),inb_p(SMBHSTADD),inb_p(SMBHSTDAT0), - inb_p(SMBHSTDAT1)); + printk + ("i2c-ali15x3.o: Transaction (pre): STS=%02x, CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, " + "DAT1=%02x\n", inb_p(SMBHSTSTS), inb_p(SMBHSTCNT), + inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), + inb_p(SMBHSTDAT1)); #endif - /* get status */ - temp = inb_p(SMBHSTSTS); + /* get status */ + temp = inb_p(SMBHSTSTS); - /* Make sure the SMBus host is ready to start transmitting */ - /* Check the busy bit first */ - if (temp & ALI15X3_STS_BUSY) { + /* Make sure the SMBus host is ready to start transmitting */ + /* Check the busy bit first */ + if (temp & ALI15X3_STS_BUSY) { /* If the host controller is still busy, it may have timed out in the previous transaction, resulting in a "SMBus Timeout" printk. @@ -341,61 +348,67 @@ int ali15x3_transaction(void) temp = inb_p(SMBHSTSTS); if (temp & ALI15X3_STS_BUSY) { */ - + /* Try resetting entire SMB bus, including other devices - This may not work either - it clears the BUSY bit but then the BUSY bit may come back on when you try and use the chip again. If that's the case you are stuck. */ - printk("i2c-ali15x3.o: Resetting entire SMB Bus to clear busy condition (%02x)\n",temp); - outb_p(ALI15X3_T_OUT, SMBHSTCNT); - temp = inb_p(SMBHSTSTS); - } + printk + ("i2c-ali15x3.o: Resetting entire SMB Bus to clear busy condition (%02x)\n", + temp); + outb_p(ALI15X3_T_OUT, SMBHSTCNT); + temp = inb_p(SMBHSTSTS); + } /* } */ - /* now check the error bits and the busy bit */ - if (temp & (ALI15X3_STS_ERR | ALI15X3_STS_BUSY)) { - /* do a clear-on-write */ - outb_p(0xFF, SMBHSTSTS); - if ((temp = inb_p(SMBHSTSTS)) & (ALI15X3_STS_ERR | ALI15X3_STS_BUSY)) { - /* this is probably going to be correctable only by a power reset - as one of the bits now appears to be stuck */ - /* This may be a bus or device with electrical problems. */ - printk("i2c-ali15x3.o: SMBus reset failed! (0x%02x) - controller or device on bus is probably hung\n",temp); - return -1; - } - } else { - /* check and clear done bit */ - if (temp & ALI15X3_STS_DONE) { - outb_p(temp, SMBHSTSTS); - } - } + /* now check the error bits and the busy bit */ + if (temp & (ALI15X3_STS_ERR | ALI15X3_STS_BUSY)) { + /* do a clear-on-write */ + outb_p(0xFF, SMBHSTSTS); + if ((temp = inb_p(SMBHSTSTS)) & + (ALI15X3_STS_ERR | ALI15X3_STS_BUSY)) { + /* this is probably going to be correctable only by a power reset + as one of the bits now appears to be stuck */ + /* This may be a bus or device with electrical problems. */ + printk + ("i2c-ali15x3.o: SMBus reset failed! (0x%02x) - controller or device on bus is probably hung\n", + temp); + return -1; + } + } else { + /* check and clear done bit */ + if (temp & ALI15X3_STS_DONE) { + outb_p(temp, SMBHSTSTS); + } + } - /* start the transaction by writing anything to the start register */ - outb_p(0xFF, SMBHSTSTART); + /* start the transaction by writing anything to the start register */ + outb_p(0xFF, SMBHSTSTART); - /* We will always wait for a fraction of a second! */ - timeout = 0; - do { - ali15x3_do_pause(1); - temp=inb_p(SMBHSTSTS); - } while ((!(temp & (ALI15X3_STS_ERR | ALI15X3_STS_DONE))) && (timeout++ < MAX_TIMEOUT)); + /* We will always wait for a fraction of a second! */ + timeout = 0; + do { + ali15x3_do_pause(1); + temp = inb_p(SMBHSTSTS); + } while ((!(temp & (ALI15X3_STS_ERR | ALI15X3_STS_DONE))) + && (timeout++ < MAX_TIMEOUT)); - /* If the SMBus is still busy, we give up */ - if (timeout >= MAX_TIMEOUT) { - result = -1; - printk("i2c-ali15x3.o: SMBus Timeout!\n"); - } + /* If the SMBus is still busy, we give up */ + if (timeout >= MAX_TIMEOUT) { + result = -1; + printk("i2c-ali15x3.o: SMBus Timeout!\n"); + } - if (temp & ALI15X3_STS_TERM) { - result = -1; + if (temp & ALI15X3_STS_TERM) { + result = -1; #ifdef DEBUG - printk("i2c-ali15x3.o: Error: Failed bus transaction\n"); + printk("i2c-ali15x3.o: Error: Failed bus transaction\n"); #endif - } + } /* Unfortunately the ALI SMB controller maps "no response" and "bus collision" @@ -403,136 +416,148 @@ int ali15x3_transaction(void) do a printk. This means that bus collisions go unreported. */ - if (temp & ALI15X3_STS_COLL) { - result = -1; + if (temp & ALI15X3_STS_COLL) { + result = -1; #ifdef DEBUG - printk("i2c-ali15x3.o: Error: no response or bus collision ADD=%02x\n", inb_p(SMBHSTADD)); + printk + ("i2c-ali15x3.o: Error: no response or bus collision ADD=%02x\n", + inb_p(SMBHSTADD)); #endif - } + } /* haven't ever seen this */ - if (temp & ALI15X3_STS_DEV) { - result = -1; - printk("i2c-ali15x3.o: Error: device error\n"); - } - + if (temp & ALI15X3_STS_DEV) { + result = -1; + printk("i2c-ali15x3.o: Error: device error\n"); + } #ifdef DEBUG - printk("i2c-ali15x3.o: Transaction (post): STS=%02x, CNT=%02x, CMD=%02x, ADD=%02x, " - "DAT0=%02x, DAT1=%02x\n", - inb_p(SMBHSTSTS), inb_p(SMBHSTCNT),inb_p(SMBHSTCMD),inb_p(SMBHSTADD),inb_p(SMBHSTDAT0), - inb_p(SMBHSTDAT1)); + printk + ("i2c-ali15x3.o: Transaction (post): STS=%02x, CNT=%02x, CMD=%02x, ADD=%02x, " + "DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTSTS), inb_p(SMBHSTCNT), + inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), + inb_p(SMBHSTDAT1)); #endif - return result; + return result; } /* Return -1 on error. See smbus.h for more information */ -s32 ali15x3_access(struct i2c_adapter *adap, u16 addr, unsigned short flags, - char read_write, u8 command, int size, - union i2c_smbus_data * data) +s32 ali15x3_access(struct i2c_adapter * adap, u16 addr, + unsigned short flags, char read_write, u8 command, + int size, union i2c_smbus_data * data) { - int i,len; - int temp; - int timeout; + int i, len; + int temp; + int timeout; /* clear all the bits (clear-on-write) */ - outb_p(0xFF, SMBHSTSTS); + outb_p(0xFF, SMBHSTSTS); /* make sure SMBus is idle */ - temp = inb_p(SMBHSTSTS); - for(timeout = 0; (timeout < MAX_TIMEOUT) && !(temp & ALI15X3_STS_IDLE); timeout++) - { - ali15x3_do_pause(1); - temp=inb_p(SMBHSTSTS); - } - if (timeout >= MAX_TIMEOUT) { - printk("i2c-ali15x3.o: Idle wait Timeout! STS=0x%02x\n", temp); - } + temp = inb_p(SMBHSTSTS); + for (timeout = 0; + (timeout < MAX_TIMEOUT) && !(temp & ALI15X3_STS_IDLE); + timeout++) { + ali15x3_do_pause(1); + temp = inb_p(SMBHSTSTS); + } + if (timeout >= MAX_TIMEOUT) { + printk("i2c-ali15x3.o: Idle wait Timeout! STS=0x%02x\n", + temp); + } - switch(size) { - case I2C_SMBUS_PROC_CALL: - printk("i2c-ali15x3.o: I2C_SMBUS_PROC_CALL not supported!\n"); - return -1; - case I2C_SMBUS_QUICK: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - size = ALI15X3_QUICK; - break; - case I2C_SMBUS_BYTE: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - if (read_write == I2C_SMBUS_WRITE) - outb_p(command, SMBHSTCMD); - size = ALI15X3_BYTE; - break; - case I2C_SMBUS_BYTE_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - outb_p(command, SMBHSTCMD); - if (read_write == I2C_SMBUS_WRITE) - outb_p(data->byte,SMBHSTDAT0); - size = ALI15X3_BYTE_DATA; - break; - case I2C_SMBUS_WORD_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - outb_p(command, SMBHSTCMD); - if (read_write == I2C_SMBUS_WRITE) { - outb_p(data->word & 0xff,SMBHSTDAT0); - outb_p((data->word & 0xff00) >> 8,SMBHSTDAT1); - } - size = ALI15X3_WORD_DATA; - break; - case I2C_SMBUS_BLOCK_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - outb_p(command, SMBHSTCMD); - if (read_write == I2C_SMBUS_WRITE) { - len = data->block[0]; - if (len < 0) { - len = 0; - data->block[0] = len; - } - if (len > 32) { - len = 32; - data->block[0] = len; - } - outb_p(len,SMBHSTDAT0); - outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); /* Reset SMBBLKDAT */ - for (i = 1; i <= len; i++) - outb_p(data->block[i],SMBBLKDAT); - } - size = ALI15X3_BLOCK_DATA; - break; - } + switch (size) { + case I2C_SMBUS_PROC_CALL: + printk + ("i2c-ali15x3.o: I2C_SMBUS_PROC_CALL not supported!\n"); + return -1; + case I2C_SMBUS_QUICK: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + size = ALI15X3_QUICK; + break; + case I2C_SMBUS_BYTE: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + if (read_write == I2C_SMBUS_WRITE) + outb_p(command, SMBHSTCMD); + size = ALI15X3_BYTE; + break; + case I2C_SMBUS_BYTE_DATA: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + outb_p(command, SMBHSTCMD); + if (read_write == I2C_SMBUS_WRITE) + outb_p(data->byte, SMBHSTDAT0); + size = ALI15X3_BYTE_DATA; + break; + case I2C_SMBUS_WORD_DATA: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + outb_p(command, SMBHSTCMD); + if (read_write == I2C_SMBUS_WRITE) { + outb_p(data->word & 0xff, SMBHSTDAT0); + outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); + } + size = ALI15X3_WORD_DATA; + break; + case I2C_SMBUS_BLOCK_DATA: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + outb_p(command, SMBHSTCMD); + if (read_write == I2C_SMBUS_WRITE) { + len = data->block[0]; + if (len < 0) { + len = 0; + data->block[0] = len; + } + if (len > 32) { + len = 32; + data->block[0] = len; + } + outb_p(len, SMBHSTDAT0); + outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); /* Reset SMBBLKDAT */ + for (i = 1; i <= len; i++) + outb_p(data->block[i], SMBBLKDAT); + } + size = ALI15X3_BLOCK_DATA; + break; + } - outb_p(size, SMBHSTCNT); /* output command */ + outb_p(size, SMBHSTCNT); /* output command */ - if (ali15x3_transaction()) /* Error in transaction */ - return -1; - - if ((read_write == I2C_SMBUS_WRITE) || (size == ALI15X3_QUICK)) - return 0; - + if (ali15x3_transaction()) /* Error in transaction */ + return -1; - switch(size) { - case ALI15X3_BYTE: /* Result put in SMBHSTDAT0 */ - data->byte = inb_p(SMBHSTDAT0); - break; - case ALI15X3_BYTE_DATA: - data->byte = inb_p(SMBHSTDAT0); - break; - case ALI15X3_WORD_DATA: - data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); - break; - case ALI15X3_BLOCK_DATA: - len = inb_p(SMBHSTDAT0); - if(len > 32) - len = 32; - data->block[0] = len; - outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); /* Reset SMBBLKDAT */ - for (i = 1; i <= data->block[0]; i++) { - data->block[i] = inb_p(SMBBLKDAT); + if ((read_write == I2C_SMBUS_WRITE) || (size == ALI15X3_QUICK)) + return 0; + + + switch (size) { + case ALI15X3_BYTE: /* Result put in SMBHSTDAT0 */ + data->byte = inb_p(SMBHSTDAT0); + break; + case ALI15X3_BYTE_DATA: + data->byte = inb_p(SMBHSTDAT0); + break; + case ALI15X3_WORD_DATA: + data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); + break; + case ALI15X3_BLOCK_DATA: + len = inb_p(SMBHSTDAT0); + if (len > 32) + len = 32; + data->block[0] = len; + outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); /* Reset SMBBLKDAT */ + for (i = 1; i <= data->block[0]; i++) { + data->block[i] = inb_p(SMBBLKDAT); #ifdef DEBUG - printk("i2c-ali15x3.o: Blk: len=%d, i=%d, data=%02x\n", len, i, data->block[i]); -#endif DEBUG - } - break; - } - return 0; + printk + ("i2c-ali15x3.o: Blk: len=%d, i=%d, data=%02x\n", + len, i, data->block[i]); +#endif /* DEBUG */ + } + break; + } + return 0; } void ali15x3_inc(struct i2c_adapter *adapter) @@ -549,72 +574,78 @@ void ali15x3_dec(struct i2c_adapter *adapter) u32 ali15x3_func(struct i2c_adapter *adapter) { return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | - I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | - I2C_FUNC_SMBUS_BLOCK_DATA; + I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | + I2C_FUNC_SMBUS_BLOCK_DATA; } int __init i2c_ali15x3_init(void) { - int res; - printk("ali15x3.o version %s (%s)\n",LM_VERSION,LM_DATE); + int res; + printk("ali15x3.o version %s (%s)\n", LM_VERSION, LM_DATE); #ifdef DEBUG /* PE- It might be good to make this a permanent part of the code! */ - if (ali15x3_initialized) { - printk("i2c-ali15x3.o: Oops, ali15x3_init called a second time!\n"); - return -EBUSY; - } + if (ali15x3_initialized) { + printk + ("i2c-ali15x3.o: Oops, ali15x3_init called a second time!\n"); + return -EBUSY; + } #endif - ali15x3_initialized = 0; - if ((res = ali15x3_setup())) { - printk("i2c-ali15x3.o: ALI15X3 not detected, module not inserted.\n"); - ali15x3_cleanup(); - return res; - } - ali15x3_initialized ++; - sprintf(ali15x3_adapter.name,"SMBus ALI15X3 adapter at %04x",ali15x3_smba); - if ((res = i2c_add_adapter(&ali15x3_adapter))) { - printk("i2c-ali15x3.o: Adapter registration failed, module not inserted.\n"); - ali15x3_cleanup(); - return res; - } - ali15x3_initialized++; - printk("i2c-ali15x3.o: ALI15X3 SMBus Controller detected and initialized\n"); - return 0; + ali15x3_initialized = 0; + if ((res = ali15x3_setup())) { + printk + ("i2c-ali15x3.o: ALI15X3 not detected, module not inserted.\n"); + ali15x3_cleanup(); + return res; + } + ali15x3_initialized++; + sprintf(ali15x3_adapter.name, "SMBus ALI15X3 adapter at %04x", + ali15x3_smba); + if ((res = i2c_add_adapter(&ali15x3_adapter))) { + printk + ("i2c-ali15x3.o: Adapter registration failed, module not inserted.\n"); + ali15x3_cleanup(); + return res; + } + ali15x3_initialized++; + printk + ("i2c-ali15x3.o: ALI15X3 SMBus Controller detected and initialized\n"); + return 0; } int __init ali15x3_cleanup(void) { - int res; - if (ali15x3_initialized >= 2) - { - if ((res = i2c_del_adapter(&ali15x3_adapter))) { - printk("i2c-ali15x3.o: i2c_del_adapter failed, module not removed\n"); - return res; - } else - ali15x3_initialized--; - } - if (ali15x3_initialized >= 1) { - release_region(ali15x3_smba, ALI15X3_SMB_IOSIZE); - ali15x3_initialized--; - } - return 0; + int res; + if (ali15x3_initialized >= 2) { + if ((res = i2c_del_adapter(&ali15x3_adapter))) { + printk + ("i2c-ali15x3.o: i2c_del_adapter failed, module not removed\n"); + return res; + } else + ali15x3_initialized--; + } + if (ali15x3_initialized >= 1) { + release_region(ali15x3_smba, ALI15X3_SMB_IOSIZE); + ali15x3_initialized--; + } + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard , Philip Edelbrock , and Mark D. Studebaker "); +MODULE_AUTHOR + ("Frodo Looijaard , Philip Edelbrock , and Mark D. Studebaker "); MODULE_DESCRIPTION("ALI15X3 SMBus driver"); int init_module(void) { - return i2c_ali15x3_init(); + return i2c_ali15x3_init(); } int cleanup_module(void) { - return ali15x3_cleanup(); + return ali15x3_cleanup(); } -#endif /* MODULE */ +#endif /* MODULE */ diff --git a/kernel/busses/i2c-amd756.c b/kernel/busses/i2c-amd756.c index caa8f3e5..793b9c71 100644 --- a/kernel/busses/i2c-amd756.c +++ b/kernel/busses/i2c-amd756.c @@ -54,10 +54,10 @@ /* PCI Address Constants */ /* address of I/O space */ -#define SMBBA 0x058 /* mh */ +#define SMBBA 0x058 /* mh */ /* general configuration */ -#define SMBGCFG 0x041 /* mh */ +#define SMBGCFG 0x041 /* mh */ /* silicon revision code */ #define SMBREV 0x008 @@ -80,13 +80,13 @@ static #else extern #endif - int __init i2c_amd756_init(void); +int __init i2c_amd756_init(void); static int __init amd756_cleanup(void); static int amd756_setup(void); -static s32 amd756_access(struct i2c_adapter *adap, u16 addr, - unsigned short flags, char read_write, - u8 command, int size, union i2c_smbus_data * data); -static void amd756_do_pause( unsigned int amount ); +static s32 amd756_access(struct i2c_adapter *adap, u16 addr, + unsigned short flags, char read_write, + u8 command, int size, union i2c_smbus_data *data); +static void amd756_do_pause(unsigned int amount); static int amd756_transaction(void); static void amd756_inc(struct i2c_adapter *adapter); static void amd756_dec(struct i2c_adapter *adapter); @@ -95,28 +95,28 @@ static u32 amd756_func(struct i2c_adapter *adapter); #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ static struct i2c_algorithm smbus_algorithm = { - /* name */ "Non-I2C SMBus adapter", - /* id */ I2C_ALGO_SMBUS, - /* master_xfer */ NULL, - /* smbus_access */ amd756_access, - /* slave_send */ NULL, - /* slave_rcv */ NULL, - /* algo_control */ NULL, - /* functionality */ amd756_func, + /* name */ "Non-I2C SMBus adapter", + /* id */ I2C_ALGO_SMBUS, + /* master_xfer */ NULL, + /* smbus_access */ amd756_access, + /* slave_send */ NULL, + /* slave_rcv */ NULL, + /* algo_control */ NULL, + /* functionality */ amd756_func, }; static struct i2c_adapter amd756_adapter = { - "unset", - I2C_ALGO_SMBUS | I2C_HW_SMBUS_AMD756, - &smbus_algorithm, - NULL, - amd756_inc, - amd756_dec, - NULL, - NULL, + "unset", + I2C_ALGO_SMBUS | I2C_HW_SMBUS_AMD756, + &smbus_algorithm, + NULL, + amd756_inc, + amd756_dec, + NULL, + NULL, }; static int __initdata amd756_initialized; @@ -131,72 +131,77 @@ static unsigned short amd756_smba = 0; defined to make the transition easier. */ int amd756_setup(void) { - int error_return=0; - unsigned char temp; + int error_return = 0; + unsigned char temp; - struct pci_dev *AMD756_dev; + struct pci_dev *AMD756_dev; - /* First check whether we can access PCI at all */ - if (pci_present() == 0) { - printk("i2c-amd756.o: Error: No PCI-bus found!\n"); - error_return=-ENODEV; - goto END; - } + /* First check whether we can access PCI at all */ + if (pci_present() == 0) { + printk("i2c-amd756.o: Error: No PCI-bus found!\n"); + error_return = -ENODEV; + goto END; + } - /* Look for the AMD756, function 3 */ - /* Note: we keep on searching until we have found 'function 3' */ - AMD756_dev = NULL; - do - AMD756_dev = pci_find_device(PCI_VENDOR_ID_AMD, - PCI_DEVICE_ID_AMD_756, AMD756_dev); - while (AMD756_dev && (PCI_FUNC(AMD756_dev->devfn) != 3)); - if(AMD756_dev == NULL) { - printk("i2c-amd756.o: Error: Can't detect AMD756, function 3!\n"); - error_return=-ENODEV; - goto END; - } + /* Look for the AMD756, function 3 */ + /* Note: we keep on searching until we have found 'function 3' */ + AMD756_dev = NULL; + do + AMD756_dev = pci_find_device(PCI_VENDOR_ID_AMD, + PCI_DEVICE_ID_AMD_756, + AMD756_dev); + while (AMD756_dev && (PCI_FUNC(AMD756_dev->devfn) != 3)); + if (AMD756_dev == NULL) { + printk + ("i2c-amd756.o: Error: Can't detect AMD756, function 3!\n"); + error_return = -ENODEV; + goto END; + } /* Determine the address of the SMBus areas */ - /* Technically it is a dword but... */ - pci_read_config_word(AMD756_dev, SMBBA, &amd756_smba); - amd756_smba &= 0xfff0; + /* Technically it is a dword but... */ + pci_read_config_word(AMD756_dev, SMBBA, &amd756_smba); + amd756_smba &= 0xfff0; - if (check_region(amd756_smba, 8)) { - printk("i2c-amd756.o: AMD756_smb region 0x%x already in use!\n", amd756_smba); - error_return=-ENODEV; - goto END; - } + if (check_region(amd756_smba, 8)) { + printk + ("i2c-amd756.o: AMD756_smb region 0x%x already in use!\n", + amd756_smba); + error_return = -ENODEV; + goto END; + } - pci_read_config_byte(AMD756_dev, SMBGCFG, &temp); + pci_read_config_byte(AMD756_dev, SMBGCFG, &temp); - if ((temp & 128) == 0) { - printk("SMBUS: Error: Host SMBus controller I/O not enabled!\n"); - error_return=-ENODEV; - goto END; - } + if ((temp & 128) == 0) { + printk + ("SMBUS: Error: Host SMBus controller I/O not enabled!\n"); + error_return = -ENODEV; + goto END; + } - /* Everything is happy, let's grab the memory and set things up. */ - request_region(amd756_smba, 8, "amd756-smbus"); + /* Everything is happy, let's grab the memory and set things up. */ + request_region(amd756_smba, 8, "amd756-smbus"); #ifdef DEBUG - /* - if ((temp & 0x0E) == 8) - printk("i2c-amd756.o: AMD756 using Interrupt 9 for SMBus.\n"); - else if ((temp & 0x0E) == 0) - printk("i2c-amd756.o: AMD756 using Interrupt SMI# for SMBus.\n"); - else - printk("i2c-amd756.o: AMD756: Illegal Interrupt configuration (or code out " - "of date)!\n"); - */ + /* + if ((temp & 0x0E) == 8) + printk("i2c-amd756.o: AMD756 using Interrupt 9 for SMBus.\n"); + else if ((temp & 0x0E) == 0) + printk("i2c-amd756.o: AMD756 using Interrupt SMI# for SMBus.\n"); + else + printk("i2c-amd756.o: AMD756: Illegal Interrupt configuration (or code out " + "of date)!\n"); + */ - pci_read_config_byte(AMD756_dev, SMBREV, &temp); - printk("i2c-amd756.o: SMBREV = 0x%X\n",temp); - printk("i2c-amd756.o: AMD756_smba = 0x%X\n",amd756_smba); -#endif /* DEBUG */ + pci_read_config_byte(AMD756_dev, SMBREV, &temp); + printk("i2c-amd756.o: SMBREV = 0x%X\n", temp); + printk("i2c-amd756.o: AMD756_smba = 0x%X\n", amd756_smba); +#endif /* DEBUG */ -END: - return error_return; + END: + return error_return; } /* @@ -206,13 +211,13 @@ END: */ /* Internally used pause function */ -void amd756_do_pause( unsigned int amount ) +void amd756_do_pause(unsigned int amount) { - current->state = TASK_INTERRUPTIBLE; - schedule_timeout(amount); + current->state = TASK_INTERRUPTIBLE; + schedule_timeout(amount); } -#define GS_ABRT_STS (1 << 0) +#define GS_ABRT_STS (1 << 0) #define GS_COL_STS (1 << 1) #define GS_PRERR_STS (1 << 2) #define GS_HST_STS (1 << 3) @@ -222,186 +227,200 @@ void amd756_do_pause( unsigned int amount ) #define GS_CLEAR_STS (GS_ABRT_STS | GS_COL_STS | GS_PRERR_STS | \ GS_HCYC_STS | GS_TO_STS ) -#define GE_CYC_TYPE_MASK (7) -#define GE_HOST_STC (1 << 3) - +#define GE_CYC_TYPE_MASK (7) +#define GE_HOST_STC (1 << 3) + /* Another internally used function */ -int amd756_transaction(void) +int amd756_transaction(void) { - int temp; - int result=0; - int timeout=0; + int temp; + int result = 0; + int timeout = 0; #ifdef DEBUG - printk("i2c-amd756.o: Transaction (pre): GS=%04x, GE=%04x, ADD=%04x, DAT=%04x\n", - inw_p(SMB_GLOBAL_STATUS),inw_p(SMB_GLOBAL_ENABLE),inw_p(SMB_HOST_ADDRESS),inb_p(SMB_HOST_DATA)); + printk + ("i2c-amd756.o: Transaction (pre): GS=%04x, GE=%04x, ADD=%04x, DAT=%04x\n", + inw_p(SMB_GLOBAL_STATUS), inw_p(SMB_GLOBAL_ENABLE), + inw_p(SMB_HOST_ADDRESS), inb_p(SMB_HOST_DATA)); #endif - /* Make sure the SMBus host is ready to start transmitting */ - /* TODO: What about SM_BSY? */ - if (((temp = inw_p(SMB_GLOBAL_STATUS)) & GS_HST_STS) != 0x00) { + /* Make sure the SMBus host is ready to start transmitting */ + /* TODO: What about SM_BSY? */ + if (((temp = inw_p(SMB_GLOBAL_STATUS)) & GS_HST_STS) != 0x00) { #ifdef DEBUG - printk("i2c-amd756.o: SMBus busy (%04x). Resetting (NOT)... \n",temp); + printk + ("i2c-amd756.o: SMBus busy (%04x). Resetting (NOT)... \n", + temp); #endif - /* TODO: How to reset the AMD? - outb_p(temp, SMBHSTSTS); - */ - if (((temp = inw_p(SMB_GLOBAL_STATUS)) & GS_HST_STS) != 0x00) { + /* TODO: How to reset the AMD? + outb_p(temp, SMBHSTSTS); + */ + if (((temp = inw_p(SMB_GLOBAL_STATUS)) & GS_HST_STS) != + 0x00) { #ifdef DEBUG - printk("i2c-amd756.o: Failed! (%04x)\n",temp); + printk("i2c-amd756.o: Failed! (%04x)\n", temp); #endif - return -1; - } else { + return -1; + } else { #ifdef DEBUG - printk("i2c-amd756.o: Successfull!\n"); + printk("i2c-amd756.o: Successfull!\n"); #endif - } - } + } + } - /* start the transaction by setting bit 6 */ - outw_p(inw(SMB_GLOBAL_ENABLE) | GE_HOST_STC, SMB_GLOBAL_ENABLE); + /* start the transaction by setting bit 6 */ + outw_p(inw(SMB_GLOBAL_ENABLE) | GE_HOST_STC, SMB_GLOBAL_ENABLE); - /* We will always wait for a fraction of a second! */ - do { - amd756_do_pause(1); - temp=inw_p(SMB_GLOBAL_STATUS); - } while ((temp & GS_HST_STS) && (timeout++ < MAX_TIMEOUT)); + /* We will always wait for a fraction of a second! */ + do { + amd756_do_pause(1); + temp = inw_p(SMB_GLOBAL_STATUS); + } while ((temp & GS_HST_STS) && (timeout++ < MAX_TIMEOUT)); - /* If the SMBus is still busy, we give up */ - if (timeout >= MAX_TIMEOUT) { + /* If the SMBus is still busy, we give up */ + if (timeout >= MAX_TIMEOUT) { #ifdef DEBUG - printk("i2c-amd756.o: SMBus explicit timeout!\n"); - result = -1; + printk("i2c-amd756.o: SMBus explicit timeout!\n"); + result = -1; #endif - } + } - if (temp & GS_PRERR_STS) { - result = -1; + if (temp & GS_PRERR_STS) { + result = -1; #ifdef DEBUG - printk("i2c-amd756.o: SMBus Protocol error!\n"); + printk("i2c-amd756.o: SMBus Protocol error!\n"); #endif - } + } - if (temp & GS_COL_STS) { - result = -1; - printk("i2c-amd756.o: SMBus collision!\n"); - /* TODO: Clear Collision Status with a 1 */ - } + if (temp & GS_COL_STS) { + result = -1; + printk("i2c-amd756.o: SMBus collision!\n"); + /* TODO: Clear Collision Status with a 1 */ + } - if (temp & GS_TO_STS) { - result = -1; + if (temp & GS_TO_STS) { + result = -1; #ifdef DEBUG - printk("i2c-amd756.o: SMBus protocol timeout!\n"); + printk("i2c-amd756.o: SMBus protocol timeout!\n"); #endif - } - + } #ifdef DEBUG - if (temp & GS_HCYC_STS) { - printk("i2c-amd756.o: SMBus protocol success!\n"); - } + if (temp & GS_HCYC_STS) { + printk("i2c-amd756.o: SMBus protocol success!\n"); + } #endif - outw_p (GS_CLEAR_STS, SMB_GLOBAL_STATUS); + outw_p(GS_CLEAR_STS, SMB_GLOBAL_STATUS); - if (((temp = inw_p (SMB_GLOBAL_STATUS)) & GS_CLEAR_STS) != 0x00) { + if (((temp = inw_p(SMB_GLOBAL_STATUS)) & GS_CLEAR_STS) != 0x00) { #ifdef DEBUG - printk("i2c-amd756.o: Failed reset at end of transaction (%04x)\n",temp); + printk + ("i2c-amd756.o: Failed reset at end of transaction (%04x)\n", + temp); #endif - } - + } #ifdef DEBUG - printk("i2c-amd756.o: Transaction (post): GS=%04x, GE=%04x, ADD=%04x, DAT=%04x\n", - inw_p(SMB_GLOBAL_STATUS),inw_p(SMB_GLOBAL_ENABLE),inw_p(SMB_HOST_ADDRESS),inb_p(SMB_HOST_DATA)); + printk + ("i2c-amd756.o: Transaction (post): GS=%04x, GE=%04x, ADD=%04x, DAT=%04x\n", + inw_p(SMB_GLOBAL_STATUS), inw_p(SMB_GLOBAL_ENABLE), + inw_p(SMB_HOST_ADDRESS), inb_p(SMB_HOST_DATA)); #endif - - return result; + + return result; } /* Return -1 on error. See smbus.h for more information */ -s32 amd756_access(struct i2c_adapter *adap, u16 addr, - unsigned short flags, char read_write, - u8 command, int size, union i2c_smbus_data * data) +s32 amd756_access(struct i2c_adapter * adap, u16 addr, + unsigned short flags, char read_write, + u8 command, int size, union i2c_smbus_data * data) { - int i,len; - + int i, len; + /** TODO: Should I supporte the 10-bit transfers? */ - switch(size) { - case I2C_SMBUS_PROC_CALL: - printk("i2c-amd756.o: I2C_SMBUS_PROC_CALL not supported!\n"); - /* TODO: Well... It is supported, I'm just not sure what to do here... */ - return -1; - case I2C_SMBUS_QUICK: - outw_p (((addr & 0x7f) << 1) | (read_write & 0x01), SMB_HOST_ADDRESS); - size = AMD756_QUICK; - break; - case I2C_SMBUS_BYTE: - outw_p (((addr & 0x7f) << 1) | (read_write & 0x01), SMB_HOST_ADDRESS); - /* TODO: Why only during write? */ - if (read_write == I2C_SMBUS_WRITE) - outb_p (command, SMB_HOST_COMMAND); - size = AMD756_BYTE; - break; - case I2C_SMBUS_BYTE_DATA: - outw_p (((addr & 0x7f) << 1) | (read_write & 0x01), SMB_HOST_ADDRESS); - outb_p (command, SMB_HOST_COMMAND); - if (read_write == I2C_SMBUS_WRITE) - outw_p(data->byte, SMB_HOST_DATA); - size = AMD756_BYTE_DATA; - break; - case I2C_SMBUS_WORD_DATA: - outw_p (((addr & 0x7f) << 1) | (read_write & 0x01), SMB_HOST_ADDRESS); - outb_p (command, SMB_HOST_COMMAND); - if (read_write == I2C_SMBUS_WRITE) - outw_p (data->word, SMB_HOST_DATA); /* TODO: endian???? */ - size = AMD756_WORD_DATA; - break; - case I2C_SMBUS_BLOCK_DATA: - outw_p (((addr & 0x7f) << 1) | (read_write & 0x01), SMB_HOST_ADDRESS); - outb_p (command, SMB_HOST_COMMAND); - if (read_write == I2C_SMBUS_WRITE) { - len = data->block[0]; - if (len < 0) - len = 0; - if (len > 32) - len = 32; - outw_p (len, SMB_HOST_DATA); - /* i = inw_p(SMBHSTCNT); Reset SMBBLKDAT */ - for (i = 1; i <= len; i ++) - outb_p (data->block[i], SMB_HOST_BLOCK_DATA); - } - size = AMD756_BLOCK_DATA; - break; - } + switch (size) { + case I2C_SMBUS_PROC_CALL: + printk + ("i2c-amd756.o: I2C_SMBUS_PROC_CALL not supported!\n"); + /* TODO: Well... It is supported, I'm just not sure what to do here... */ + return -1; + case I2C_SMBUS_QUICK: + outw_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMB_HOST_ADDRESS); + size = AMD756_QUICK; + break; + case I2C_SMBUS_BYTE: + outw_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMB_HOST_ADDRESS); + /* TODO: Why only during write? */ + if (read_write == I2C_SMBUS_WRITE) + outb_p(command, SMB_HOST_COMMAND); + size = AMD756_BYTE; + break; + case I2C_SMBUS_BYTE_DATA: + outw_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMB_HOST_ADDRESS); + outb_p(command, SMB_HOST_COMMAND); + if (read_write == I2C_SMBUS_WRITE) + outw_p(data->byte, SMB_HOST_DATA); + size = AMD756_BYTE_DATA; + break; + case I2C_SMBUS_WORD_DATA: + outw_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMB_HOST_ADDRESS); + outb_p(command, SMB_HOST_COMMAND); + if (read_write == I2C_SMBUS_WRITE) + outw_p(data->word, SMB_HOST_DATA); /* TODO: endian???? */ + size = AMD756_WORD_DATA; + break; + case I2C_SMBUS_BLOCK_DATA: + outw_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMB_HOST_ADDRESS); + outb_p(command, SMB_HOST_COMMAND); + if (read_write == I2C_SMBUS_WRITE) { + len = data->block[0]; + if (len < 0) + len = 0; + if (len > 32) + len = 32; + outw_p(len, SMB_HOST_DATA); + /* i = inw_p(SMBHSTCNT); Reset SMBBLKDAT */ + for (i = 1; i <= len; i++) + outb_p(data->block[i], + SMB_HOST_BLOCK_DATA); + } + size = AMD756_BLOCK_DATA; + break; + } - /* How about enabling interrupts... */ - outw_p (size & GE_CYC_TYPE_MASK, SMB_GLOBAL_ENABLE); + /* How about enabling interrupts... */ + outw_p(size & GE_CYC_TYPE_MASK, SMB_GLOBAL_ENABLE); - if (amd756_transaction()) /* Error in transaction */ - return -1; - - if ((read_write == I2C_SMBUS_WRITE) || (size == AMD756_QUICK)) - return 0; - + if (amd756_transaction()) /* Error in transaction */ + return -1; - switch(size) { - case AMD756_BYTE: - data->byte = inw_p (SMB_HOST_DATA); - break; - case AMD756_BYTE_DATA: - data->byte = inw_p (SMB_HOST_DATA); - break; - case AMD756_WORD_DATA: - data->word = inw_p (SMB_HOST_DATA); /* TODO: endian???? */ - break; - case AMD756_BLOCK_DATA: - data->block[0] = inw_p (SMB_HOST_DATA & 63); - /* i = inw_p(SMBHSTCNT); Reset SMBBLKDAT */ - for (i = 1; i <= data->block[0]; i++) - data->block[i] = inb_p (SMB_HOST_BLOCK_DATA); - break; - } - - return 0; + if ((read_write == I2C_SMBUS_WRITE) || (size == AMD756_QUICK)) + return 0; + + + switch (size) { + case AMD756_BYTE: + data->byte = inw_p(SMB_HOST_DATA); + break; + case AMD756_BYTE_DATA: + data->byte = inw_p(SMB_HOST_DATA); + break; + case AMD756_WORD_DATA: + data->word = inw_p(SMB_HOST_DATA); /* TODO: endian???? */ + break; + case AMD756_BLOCK_DATA: + data->block[0] = inw_p(SMB_HOST_DATA & 63); + /* i = inw_p(SMBHSTCNT); Reset SMBBLKDAT */ + for (i = 1; i <= data->block[0]; i++) + data->block[i] = inb_p(SMB_HOST_BLOCK_DATA); + break; + } + + return 0; } void amd756_inc(struct i2c_adapter *adapter) @@ -417,56 +436,60 @@ void amd756_dec(struct i2c_adapter *adapter) u32 amd756_func(struct i2c_adapter *adapter) { - return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | - I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | - I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL; + return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | + I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | + I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL; } int __init i2c_amd756_init(void) { - int res; - printk("amd756.o version %s (%s)\n",LM_VERSION,LM_DATE); + int res; + printk("amd756.o version %s (%s)\n", LM_VERSION, LM_DATE); #ifdef DEBUG /* PE- It might be good to make this a permanent part of the code! */ - if (amd756_initialized) { - printk("i2c-amd756.o: Oops, amd756_init called a second time!\n"); - return -EBUSY; - } + if (amd756_initialized) { + printk + ("i2c-amd756.o: Oops, amd756_init called a second time!\n"); + return -EBUSY; + } #endif - amd756_initialized = 0; - if ((res = amd756_setup())) { - printk("i2c-amd756.o: AMD756 not detected, module not inserted.\n"); - amd756_cleanup(); - return res; - } - amd756_initialized ++; - sprintf(amd756_adapter.name,"SMBus AMD756 adapter at %04x",amd756_smba); - if ((res = i2c_add_adapter(&amd756_adapter))) { - printk("i2c-amd756.o: Adapter registration failed, module not inserted.\n"); - amd756_cleanup(); - return res; - } - amd756_initialized++; - printk("i2c-amd756.o: AMD756 bus detected and initialized\n"); - return 0; + amd756_initialized = 0; + if ((res = amd756_setup())) { + printk + ("i2c-amd756.o: AMD756 not detected, module not inserted.\n"); + amd756_cleanup(); + return res; + } + amd756_initialized++; + sprintf(amd756_adapter.name, "SMBus AMD756 adapter at %04x", + amd756_smba); + if ((res = i2c_add_adapter(&amd756_adapter))) { + printk + ("i2c-amd756.o: Adapter registration failed, module not inserted.\n"); + amd756_cleanup(); + return res; + } + amd756_initialized++; + printk("i2c-amd756.o: AMD756 bus detected and initialized\n"); + return 0; } int __init amd756_cleanup(void) { - int res; - if (amd756_initialized >= 2) - { - if ((res = i2c_del_adapter(&amd756_adapter))) { - printk("i2c-amd756.o: i2c_del_adapter failed, module not removed\n"); - return res; - } else - amd756_initialized--; - } - if (amd756_initialized >= 1) { - release_region(amd756_smba, 8); - amd756_initialized--; - } - return 0; + int res; + if (amd756_initialized >= 2) { + if ((res = i2c_del_adapter(&amd756_adapter))) { + printk + ("i2c-amd756.o: i2c_del_adapter failed, module not removed\n"); + return res; + } else + amd756_initialized--; + } + if (amd756_initialized >= 1) { + release_region(amd756_smba, 8); + amd756_initialized--; + } + return 0; } EXPORT_NO_SYMBOLS; @@ -478,13 +501,12 @@ MODULE_DESCRIPTION("AMD756 SMBus driver"); int init_module(void) { - return i2c_amd756_init(); + return i2c_amd756_init(); } int cleanup_module(void) { - return amd756_cleanup(); + return amd756_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/busses/i2c-hydra.c b/kernel/busses/i2c-hydra.c index e4ab7b74..3baae1d2 100644 --- a/kernel/busses/i2c-hydra.c +++ b/kernel/busses/i2c-hydra.c @@ -57,37 +57,37 @@ static unsigned long hydra_base; static inline void pdregw(u32 val) { - writel(val, hydra_base+HYDRA_CACHE_PD); + writel(val, hydra_base + HYDRA_CACHE_PD); } static inline u32 pdregr(void) { - u32 val = readl(hydra_base+HYDRA_CACHE_PD); + u32 val = readl(hydra_base + HYDRA_CACHE_PD); return val; } static void bit_hydra_setscl(void *data, int state) { - u32 val = pdregr(); - if (state) - val &= ~ HYDRA_SCLK_OE; - else { - val &= ~HYDRA_SCLK; - val |= HYDRA_SCLK_OE; - } - pdregw(val); + u32 val = pdregr(); + if (state) + val &= ~HYDRA_SCLK_OE; + else { + val &= ~HYDRA_SCLK; + val |= HYDRA_SCLK_OE; + } + pdregw(val); } static void bit_hydra_setsda(void *data, int state) { - u32 val = pdregr(); - if (state) - val &= ~ HYDRA_SDAT_OE; - else { - val &= ~HYDRA_SDAT; - val |= HYDRA_SDAT_OE; - } - pdregw(val); + u32 val = pdregr(); + if (state) + val &= ~HYDRA_SDAT_OE; + else { + val &= ~HYDRA_SDAT; + val |= HYDRA_SDAT_OE; + } + pdregw(val); } static int bit_hydra_getscl(void *data) @@ -118,7 +118,7 @@ struct i2c_algo_bit_data bit_hydra_data = { bit_hydra_setscl, bit_hydra_getsda, bit_hydra_getscl, - 5, 5, 100, /*waits, timeout */ + 5, 5, 100, /*waits, timeout */ }; struct i2c_adapter bit_hydra_ops = { @@ -140,20 +140,19 @@ static int find_hydra(void) if (!pci_present()) return -ENODEV; - + dev = pci_find_device(VENDOR, DEVICE, NULL); if (!dev) { printk("Hydra not found\n"); return -ENODEV; } - #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,13) base_addr = dev->resource[0].start; #else base_addr = dev->base_address[0]; #endif - hydra_base = (unsigned long)ioremap(base_addr, 0x100); + hydra_base = (unsigned long) ioremap(base_addr, 0x100); return 0; } @@ -163,21 +162,22 @@ static #else extern #endif - int __init i2c_hydra_init(void) +int __init i2c_hydra_init(void) { if (find_hydra() < 0) { printk("Error while reading PCI configuration\n"); return -ENODEV; } - pdregw(0); /* clear SCLK_OE and SDAT_OE */ + pdregw(0); /* clear SCLK_OE and SDAT_OE */ if (i2c_bit_add_bus(&bit_hydra_ops) == 0) { printk("Hydra i2c: Module succesfully loaded\n"); return 0; } else { - iounmap((void *)hydra_base); - printk("Hydra i2c: Algo-bit error, couldn't register bus\n"); + iounmap((void *) hydra_base); + printk + ("Hydra i2c: Algo-bit error, couldn't register bus\n"); return -ENODEV; } } @@ -188,17 +188,17 @@ EXPORT_NO_SYMBOLS; MODULE_AUTHOR("Geert Uytterhoeven "); MODULE_DESCRIPTION("i2c for Apple Hydra Mac I/O"); -int init_module(void) +int init_module(void) { return i2c_hydra_init(); } -void cleanup_module(void) +void cleanup_module(void) { i2c_bit_del_bus(&bit_hydra_ops); if (hydra_base) { pdregw(0); /* clear SCLK_OE and SDAT_OE */ - iounmap((void *)hydra_base); + iounmap((void *) hydra_base); } } #endif diff --git a/kernel/busses/i2c-i801.c b/kernel/busses/i2c-i801.c index 0d387fe6..ff86c3dc 100644 --- a/kernel/busses/i2c-i801.c +++ b/kernel/busses/i2c-i801.c @@ -23,7 +23,7 @@ This driver supports the Intel 82801AA and 82801AB I/O Controller Hubs (ICH). They are similar to the PIIX4 and are part of Intel's '810' chipset. See the doc/busses/i2c-i801 file for details. -*/ +*/ /* Note: we assume there can only be one I801, with one SMBus interface */ @@ -79,24 +79,26 @@ /* If force is set to anything different from 0, we forcibly enable the I801. DANGEROUS! */ static int force = 0; -MODULE_PARM(force,"i"); -MODULE_PARM_DESC(force,"Forcibly enable the I801. DANGEROUS!"); +MODULE_PARM(force, "i"); +MODULE_PARM_DESC(force, "Forcibly enable the I801. DANGEROUS!"); /* If force_addr is set to anything different from 0, we forcibly enable the I801 at the given address. VERY DANGEROUS! */ static int force_addr = 0; -MODULE_PARM(force_addr,"i"); -MODULE_PARM_DESC(force_addr,"Forcibly enable the I801 at the given address. " - "EXTREMELY DANGEROUS!"); +MODULE_PARM(force_addr, "i"); +MODULE_PARM_DESC(force_addr, + "Forcibly enable the I801 at the given address. " + "EXTREMELY DANGEROUS!"); static int __init i801_cleanup(void); static int i801_setup(void); -static s32 i801_access(struct i2c_adapter *adap, u16 addr, - unsigned short flags, char read_write, - u8 command, int size, union i2c_smbus_data * data); -static void i801_do_pause( unsigned int amount ); +static s32 i801_access(struct i2c_adapter *adap, u16 addr, + unsigned short flags, char read_write, + u8 command, int size, union i2c_smbus_data *data); +static void i801_do_pause(unsigned int amount); static int i801_transaction(void); -static int i801_block_transaction(union i2c_smbus_data *data, char read_write); +static int i801_block_transaction(union i2c_smbus_data *data, + char read_write); static void i801_inc(struct i2c_adapter *adapter); static void i801_dec(struct i2c_adapter *adapter); static u32 i801_func(struct i2c_adapter *adapter); @@ -104,28 +106,28 @@ static u32 i801_func(struct i2c_adapter *adapter); #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ static struct i2c_algorithm smbus_algorithm = { - /* name */ "Non-I2C SMBus adapter", - /* id */ I2C_ALGO_SMBUS, - /* master_xfer */ NULL, - /* smbus_access */ i801_access, - /* slave_send */ NULL, - /* slave_rcv */ NULL, - /* algo_control */ NULL, - /* functionality */ i801_func, + /* name */ "Non-I2C SMBus adapter", + /* id */ I2C_ALGO_SMBUS, + /* master_xfer */ NULL, + /* smbus_access */ i801_access, + /* slave_send */ NULL, + /* slave_rcv */ NULL, + /* algo_control */ NULL, + /* functionality */ i801_func, }; static struct i2c_adapter i801_adapter = { - "unset", - I2C_ALGO_SMBUS | I2C_HW_SMBUS_I801, - &smbus_algorithm, - NULL, - i801_inc, - i801_dec, - NULL, - NULL, + "unset", + I2C_ALGO_SMBUS | I2C_HW_SMBUS_I801, + &smbus_algorithm, + NULL, + i801_inc, + i801_dec, + NULL, + NULL, }; static int __initdata i801_initialized; @@ -138,393 +140,424 @@ static unsigned short i801_smba = 0; defined to make the transition easier. */ int i801_setup(void) { - int error_return=0; - unsigned char temp; + int error_return = 0; + unsigned char temp; - struct pci_dev *I801_dev; + struct pci_dev *I801_dev; - /* First check whether we can access PCI at all */ - if (pci_present() == 0) { - printk("i2c-i801.o: Error: No PCI-bus found!\n"); - error_return=-ENODEV; - goto END; - } + /* First check whether we can access PCI at all */ + if (pci_present() == 0) { + printk("i2c-i801.o: Error: No PCI-bus found!\n"); + error_return = -ENODEV; + goto END; + } - /* Look for the I801, function 3 */ - /* Have to check for both the 82801AA and 82801AB */ - /* Note: we keep on searching until we have found 'function 3' */ - I801_dev = NULL; - do - I801_dev = pci_find_device(PCI_VENDOR_ID_INTEL, - PCI_DEVICE_ID_INTEL_82801AA_3, I801_dev); - while(I801_dev && (PCI_FUNC(I801_dev->devfn) != 3)); - if(I801_dev == NULL) { - do - I801_dev = pci_find_device(PCI_VENDOR_ID_INTEL, - PCI_DEVICE_ID_INTEL_82801AB_3, I801_dev); - while(I801_dev && (PCI_FUNC(I801_dev->devfn) != 3)); - } - if(I801_dev == NULL) { - printk("i2c-i801.o: Error: Can't detect I801, function 3!\n"); - error_return=-ENODEV; - goto END; - } + /* Look for the I801, function 3 */ + /* Have to check for both the 82801AA and 82801AB */ + /* Note: we keep on searching until we have found 'function 3' */ + I801_dev = NULL; + do + I801_dev = pci_find_device(PCI_VENDOR_ID_INTEL, + PCI_DEVICE_ID_INTEL_82801AA_3, + I801_dev); + while (I801_dev && (PCI_FUNC(I801_dev->devfn) != 3)); + if (I801_dev == NULL) { + do + I801_dev = pci_find_device(PCI_VENDOR_ID_INTEL, + PCI_DEVICE_ID_INTEL_82801AB_3, + I801_dev); + while (I801_dev && (PCI_FUNC(I801_dev->devfn) != 3)); + } + if (I801_dev == NULL) { + printk + ("i2c-i801.o: Error: Can't detect I801, function 3!\n"); + error_return = -ENODEV; + goto END; + } /* Determine the address of the SMBus areas */ - if (force_addr) { - i801_smba = force_addr & 0xfff0; - force = 0; - } else { - pci_read_config_word(I801_dev, SMBBA,&i801_smba); - i801_smba &= 0xfff0; - } + if (force_addr) { + i801_smba = force_addr & 0xfff0; + force = 0; + } else { + pci_read_config_word(I801_dev, SMBBA, &i801_smba); + i801_smba &= 0xfff0; + } - if (check_region(i801_smba, 8)) { - printk("i2c-i801.o: I801_smb region 0x%x already in use!\n", i801_smba); - error_return=-ENODEV; - goto END; - } + if (check_region(i801_smba, 8)) { + printk + ("i2c-i801.o: I801_smb region 0x%x already in use!\n", + i801_smba); + error_return = -ENODEV; + goto END; + } - pci_read_config_byte(I801_dev, SMBHSTCFG, &temp); + pci_read_config_byte(I801_dev, SMBHSTCFG, &temp); /* If force_addr is set, we program the new address here. Just to make sure, we disable the I801 first. */ - if (force_addr) { - pci_write_config_byte(I801_dev, SMBHSTCFG, temp & 0xfe); - pci_write_config_word(I801_dev, SMBBA,i801_smba); - pci_write_config_byte(I801_dev, SMBHSTCFG, temp | 0x01); - printk("i2c-i801.o: WARNING: I801 SMBus interface set to new " - "address %04x!\n",i801_smba); - } else if ((temp & 1) == 0) { - if (force) { + if (force_addr) { + pci_write_config_byte(I801_dev, SMBHSTCFG, temp & 0xfe); + pci_write_config_word(I801_dev, SMBBA, i801_smba); + pci_write_config_byte(I801_dev, SMBHSTCFG, temp | 0x01); + printk + ("i2c-i801.o: WARNING: I801 SMBus interface set to new " + "address %04x!\n", i801_smba); + } else if ((temp & 1) == 0) { + if (force) { /* This should never need to be done, but has been noted that many Dell machines have the SMBus interface on the PIIX4 disabled!? NOTE: This assumes I/O space and other allocations WERE done by the Bios! Don't complain if your hardware does weird things after enabling this. :') Check for Bios updates before resorting to this. */ - pci_write_config_byte(I801_dev, SMBHSTCFG, temp | 1); - printk("i2c-i801.o: WARNING: I801 SMBus interface has been FORCEFULLY " - "ENABLED!\n"); - } else { - printk("SMBUS: Error: Host SMBus controller not enabled!\n"); - error_return=-ENODEV; - goto END; - } - } + pci_write_config_byte(I801_dev, SMBHSTCFG, + temp | 1); + printk + ("i2c-i801.o: WARNING: I801 SMBus interface has been FORCEFULLY " + "ENABLED!\n"); + } else { + printk + ("SMBUS: Error: Host SMBus controller not enabled!\n"); + error_return = -ENODEV; + goto END; + } + } - /* note: we assumed that the BIOS picked SMBus or I2C Bus timing - appropriately (bit 2 in SMBHSTCFG) */ - /* Everything is happy, let's grab the memory and set things up. */ - request_region(i801_smba, 8, "i801-smbus"); + /* note: we assumed that the BIOS picked SMBus or I2C Bus timing + appropriately (bit 2 in SMBHSTCFG) */ + /* Everything is happy, let's grab the memory and set things up. */ + request_region(i801_smba, 8, "i801-smbus"); #ifdef DEBUG - if (temp & 0x02) - printk("i2c-i801.o: I801 using Interrupt SMI# for SMBus.\n"); - else - printk("i2c-i801.o: I801 using PCI Interrupt for SMBus.\n"); + if (temp & 0x02) + printk + ("i2c-i801.o: I801 using Interrupt SMI# for SMBus.\n"); + else + printk + ("i2c-i801.o: I801 using PCI Interrupt for SMBus.\n"); - pci_read_config_byte(I801_dev, SMBREV, &temp); - printk("i2c-i801.o: SMBREV = 0x%X\n",temp); - printk("i2c-i801.o: I801_smba = 0x%X\n",i801_smba); -#endif /* DEBUG */ + pci_read_config_byte(I801_dev, SMBREV, &temp); + printk("i2c-i801.o: SMBREV = 0x%X\n", temp); + printk("i2c-i801.o: I801_smba = 0x%X\n", i801_smba); +#endif /* DEBUG */ -END: - return error_return; + END: + return error_return; } /* Internally used pause function */ -void i801_do_pause( unsigned int amount ) +void i801_do_pause(unsigned int amount) { - current->state = TASK_INTERRUPTIBLE; - schedule_timeout(amount); + current->state = TASK_INTERRUPTIBLE; + schedule_timeout(amount); } /* Another internally used function */ -int i801_transaction(void) +int i801_transaction(void) { - int temp; - int result=0; - int timeout=0; + int temp; + int result = 0; + int timeout = 0; #ifdef DEBUG - printk("i2c-i801.o: Transaction (pre): CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, " - "DAT1=%02x\n", - inb_p(SMBHSTCNT),inb_p(SMBHSTCMD),inb_p(SMBHSTADD),inb_p(SMBHSTDAT0), - inb_p(SMBHSTDAT1)); + printk + ("i2c-i801.o: Transaction (pre): CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, " + "DAT1=%02x\n", inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), + inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1)); #endif - /* Make sure the SMBus host is ready to start transmitting */ - /* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */ - if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { + /* Make sure the SMBus host is ready to start transmitting */ + /* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */ + if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { #ifdef DEBUG - printk("i2c-i801.o: SMBus busy (%02x). Resetting... \n",temp); + printk("i2c-i801.o: SMBus busy (%02x). Resetting... \n", + temp); #endif - outb_p(temp, SMBHSTSTS); - if ((temp = inb_p(SMBHSTSTS)) != 0x00) { + outb_p(temp, SMBHSTSTS); + if ((temp = inb_p(SMBHSTSTS)) != 0x00) { #ifdef DEBUG - printk("i2c-i801.o: Failed! (%02x)\n",temp); + printk("i2c-i801.o: Failed! (%02x)\n", temp); #endif - return -1; - } else { + return -1; + } else { #ifdef DEBUG - printk("i2c-i801.o: Successfull!\n"); + printk("i2c-i801.o: Successfull!\n"); #endif - } - } + } + } - /* start the transaction by setting bit 6 */ - outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); + /* start the transaction by setting bit 6 */ + outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); - /* We will always wait for a fraction of a second! */ - do { - i801_do_pause(1); - temp=inb_p(SMBHSTSTS); - } while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT)); + /* We will always wait for a fraction of a second! */ + do { + i801_do_pause(1); + temp = inb_p(SMBHSTSTS); + } while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT)); - /* If the SMBus is still busy, we give up */ - if (timeout >= MAX_TIMEOUT) { + /* If the SMBus is still busy, we give up */ + if (timeout >= MAX_TIMEOUT) { #ifdef DEBUG - printk("i2c-i801.o: SMBus Timeout!\n"); - result = -1; + printk("i2c-i801.o: SMBus Timeout!\n"); + result = -1; #endif - } + } - if (temp & 0x10) { - result = -1; + if (temp & 0x10) { + result = -1; #ifdef DEBUG - printk("i2c-i801.o: Error: Failed bus transaction\n"); + printk("i2c-i801.o: Error: Failed bus transaction\n"); #endif - } + } - if (temp & 0x08) { - result = -1; - printk("i2c-i801.o: Bus collision! SMBus may be locked until next hard - reset. (sorry!)\n"); - /* Clock stops and slave is stuck in mid-transmission */ - } + if (temp & 0x08) { + result = -1; + printk + ("i2c-i801.o: Bus collision! SMBus may be locked until next hard\n" + "reset. (sorry!)\n"); + /* Clock stops and slave is stuck in mid-transmission */ + } - if (temp & 0x04) { - result = -1; + if (temp & 0x04) { + result = -1; #ifdef DEBUG - printk("i2c-i801.o: Error: no response!\n"); + printk("i2c-i801.o: Error: no response!\n"); #endif - } + } - if ((inb_p(SMBHSTSTS) & 0x1f) != 0x00) - outb_p( inb(SMBHSTSTS), SMBHSTSTS); + if ((inb_p(SMBHSTSTS) & 0x1f) != 0x00) + outb_p(inb(SMBHSTSTS), SMBHSTSTS); - if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { + if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { #ifdef DEBUG - printk("i2c-i801.o: Failed reset at end of transaction (%02x)\n",temp); + printk + ("i2c-i801.o: Failed reset at end of transaction (%02x)\n", + temp); #endif - } + } #ifdef DEBUG - printk("i2c-i801.o: Transaction (post): CNT=%02x, CMD=%02x, ADD=%02x, " - "DAT0=%02x, DAT1=%02x\n", - inb_p(SMBHSTCNT),inb_p(SMBHSTCMD),inb_p(SMBHSTADD),inb_p(SMBHSTDAT0), - inb_p(SMBHSTDAT1)); + printk + ("i2c-i801.o: Transaction (post): CNT=%02x, CMD=%02x, ADD=%02x, " + "DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), + inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1)); #endif - return result; + return result; } /* All-inclusive block transaction function */ int i801_block_transaction(union i2c_smbus_data *data, char read_write) { - int i, len; - int smbcmd; - int temp; - int result=0; - int timeout=0; + int i, len; + int smbcmd; + int temp; + int result = 0; + int timeout = 0; - if (read_write == I2C_SMBUS_WRITE) { - len = data->block[0]; - if (len < 1) - len = 1; - if (len > 32) - len = 32; - outb_p(len,SMBHSTDAT0); - outb_p(data->block[1],SMBBLKDAT); - } else { - len = 32; /* max for reads */ - } + if (read_write == I2C_SMBUS_WRITE) { + len = data->block[0]; + if (len < 1) + len = 1; + if (len > 32) + len = 32; + outb_p(len, SMBHSTDAT0); + outb_p(data->block[1], SMBBLKDAT); + } else { + len = 32; /* max for reads */ + } - for(i = 1; i <= len; i++) - { - if(i == len && read_write == I2C_SMBUS_READ) - smbcmd = I801_BLOCK_LAST; - else - smbcmd = I801_BLOCK_DATA; - if (read_write == I2C_SMBUS_WRITE) - outb_p(data->block[i],SMBBLKDAT); - outb_p((smbcmd & 0x3C) + (ENABLE_INT9 & 1), SMBHSTCNT); + for (i = 1; i <= len; i++) { + if (i == len && read_write == I2C_SMBUS_READ) + smbcmd = I801_BLOCK_LAST; + else + smbcmd = I801_BLOCK_DATA; + if (read_write == I2C_SMBUS_WRITE) + outb_p(data->block[i], SMBBLKDAT); + outb_p((smbcmd & 0x3C) + (ENABLE_INT9 & 1), SMBHSTCNT); #ifdef DEBUG - printk("i2c-i801.o: Transaction (pre): CNT=%02x, CMD=%02x, ADD=%02x, " - "DAT0=%02x, DAT1=%02x\n", - inb_p(SMBHSTCNT),inb_p(SMBHSTCMD),inb_p(SMBHSTADD),inb_p(SMBHSTDAT0), - inb_p(SMBHSTDAT1)); + printk + ("i2c-i801.o: Transaction (pre): CNT=%02x, CMD=%02x, ADD=%02x, " + "DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), + inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), + inb_p(SMBHSTDAT1)); #endif - /* Make sure the SMBus host is ready to start transmitting */ - /* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */ - /* 0x9e = Byte_Done, Failed, Bus_Err, Dev_Err, Intr */ - temp = inb_p(SMBHSTSTS); - if (((i == 1) && ((temp & 0x1f) != 0x00)) || - ((i != 1) && ((temp & 0x9e) != 0x00))) - { + /* Make sure the SMBus host is ready to start transmitting */ + /* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */ + /* 0x9e = Byte_Done, Failed, Bus_Err, Dev_Err, Intr */ + temp = inb_p(SMBHSTSTS); + if (((i == 1) && ((temp & 0x1f) != 0x00)) || + ((i != 1) && ((temp & 0x9e) != 0x00))) { #ifdef DEBUG - printk("i2c-i801.o: SMBus busy (%02x). Resetting... \n",temp); + printk + ("i2c-i801.o: SMBus busy (%02x). Resetting... \n", + temp); #endif - outb_p(temp, SMBHSTSTS); - if (((temp = inb_p(SMBHSTSTS)) & 0x9f) != 0x00) - { - printk("i2c-i801.o: Reset failed! (%02x)\n",temp); - return -1; - } - if(i != 1) - return -1; /* if die in middle of block transaction, fail */ - } + outb_p(temp, SMBHSTSTS); + if (((temp = inb_p(SMBHSTSTS)) & 0x9f) != 0x00) { + printk + ("i2c-i801.o: Reset failed! (%02x)\n", + temp); + return -1; + } + if (i != 1) + return -1; /* if die in middle of block transaction, fail */ + } - /* start the transaction by setting bit 6 */ - outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); + /* start the transaction by setting bit 6 */ + outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); - /* We will always wait for a fraction of a second! */ - do { - i801_do_pause(1); - temp=inb_p(SMBHSTSTS); - } while ((((i >= len) && (temp & 0x01)) || ((i < len) && (temp & 0x80))) - && (timeout++ < MAX_TIMEOUT)); + /* We will always wait for a fraction of a second! */ + do { + i801_do_pause(1); + temp = inb_p(SMBHSTSTS); + } + while ( + (((i >= len) && (temp & 0x01)) + || ((i < len) && (temp & 0x80))) + && (timeout++ < MAX_TIMEOUT)); - /* If the SMBus is still busy, we give up */ - if (timeout >= MAX_TIMEOUT) { - result = -1; + /* If the SMBus is still busy, we give up */ + if (timeout >= MAX_TIMEOUT) { + result = -1; #ifdef DEBUG - printk("i2c-i801.o: SMBus Timeout!\n"); + printk("i2c-i801.o: SMBus Timeout!\n"); #endif - } + } - if (temp & 0x10) { - result = -1; + if (temp & 0x10) { + result = -1; #ifdef DEBUG - printk("i2c-i801.o: Error: Failed bus transaction\n"); + printk + ("i2c-i801.o: Error: Failed bus transaction\n"); #endif - } else if (temp & 0x08) { - result = -1; - printk("i2c-i801.o: Bus collision! SMBus may be locked until next hard" - " reset. (sorry!)\n"); - /* Clock stops and slave is stuck in mid-transmission */ - } else if (temp & 0x04) { - result = -1; + } else if (temp & 0x08) { + result = -1; + printk + ("i2c-i801.o: Bus collision! SMBus may be locked until next hard" + " reset. (sorry!)\n"); + /* Clock stops and slave is stuck in mid-transmission */ + } else if (temp & 0x04) { + result = -1; #ifdef DEBUG - printk("i2c-i801.o: Error: no response!\n"); + printk("i2c-i801.o: Error: no response!\n"); #endif - } else if (temp & 0x80) { - result = -1; + } else if (temp & 0x80) { + result = -1; #ifdef DEBUG - printk("i2c-i801.o: Error: Failed in middle of block!\n"); + printk + ("i2c-i801.o: Error: Failed in middle of block!\n"); #endif - } + } - if ((temp & 0x9f) != 0x00) - outb_p(temp, SMBHSTSTS); + if ((temp & 0x9f) != 0x00) + outb_p(temp, SMBHSTSTS); - if ((temp = (0x9f & inb_p(SMBHSTSTS))) != 0x00) { + if ((temp = (0x9f & inb_p(SMBHSTSTS))) != 0x00) { #ifdef DEBUG - printk("i2c-i801.o: Failed reset at end of transaction (%02x)\n",temp); + printk + ("i2c-i801.o: Failed reset at end of transaction (%02x)\n", + temp); #endif - } + } #ifdef DEBUG - printk("i2c-i801.o: Transaction (post): CNT=%02x, CMD=%02x, ADD=%02x, " - "DAT0=%02x, DAT1=%02x\n", - inb_p(SMBHSTCNT),inb_p(SMBHSTCMD),inb_p(SMBHSTADD),inb_p(SMBHSTDAT0), - inb_p(SMBHSTDAT1)); + printk + ("i2c-i801.o: Transaction (post): CNT=%02x, CMD=%02x, ADD=%02x, " + "DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), + inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), + inb_p(SMBHSTDAT1)); #endif - if (i == 1 && read_write == I2C_SMBUS_READ) { - len = inb_p(SMBHSTDAT0); - if (len < 1) - len = 1; - if (len > 32) - len = 32; - data->block[0] = len; - } - if (read_write == I2C_SMBUS_READ) - data->block[i] = inb_p(SMBBLKDAT); + if (i == 1 && read_write == I2C_SMBUS_READ) { + len = inb_p(SMBHSTDAT0); + if (len < 1) + len = 1; + if (len > 32) + len = 32; + data->block[0] = len; + } + if (read_write == I2C_SMBUS_READ) + data->block[i] = inb_p(SMBBLKDAT); - if(result < 0) - return(result); - } - return(0); + if (result < 0) + return (result); + } + return (0); } /* Return -1 on error. See smbus.h for more information */ -s32 i801_access(struct i2c_adapter *adap, u16 addr, unsigned short flags, - char read_write, u8 command, int size, - union i2c_smbus_data * data) +s32 i801_access(struct i2c_adapter * adap, u16 addr, unsigned short flags, + char read_write, u8 command, int size, + union i2c_smbus_data * data) { - switch(size) { - case I2C_SMBUS_PROC_CALL: - printk("i2c-i801.o: I2C_SMBUS_PROC_CALL not supported!\n"); - return -1; - case I2C_SMBUS_QUICK: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - size = I801_QUICK; - break; - case I2C_SMBUS_BYTE: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - if (read_write == I2C_SMBUS_WRITE) - outb_p(command, SMBHSTCMD); - size = I801_BYTE; - break; - case I2C_SMBUS_BYTE_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - outb_p(command, SMBHSTCMD); - if (read_write == I2C_SMBUS_WRITE) - outb_p(data->byte,SMBHSTDAT0); - size = I801_BYTE_DATA; - break; - case I2C_SMBUS_WORD_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - outb_p(command, SMBHSTCMD); - if (read_write == I2C_SMBUS_WRITE) { - outb_p(data->word & 0xff,SMBHSTDAT0); - outb_p((data->word & 0xff00) >> 8,SMBHSTDAT1); - } - size = I801_WORD_DATA; - break; - case I2C_SMBUS_BLOCK_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - outb_p(command, SMBHSTCMD); - /* Block transactions are very different from piix4 block - and from the other i801 transactions. Handle in the - i801_block_transaction() routine. */ - return(i801_block_transaction(data, read_write)); - } + switch (size) { + case I2C_SMBUS_PROC_CALL: + printk("i2c-i801.o: I2C_SMBUS_PROC_CALL not supported!\n"); + return -1; + case I2C_SMBUS_QUICK: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + size = I801_QUICK; + break; + case I2C_SMBUS_BYTE: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + if (read_write == I2C_SMBUS_WRITE) + outb_p(command, SMBHSTCMD); + size = I801_BYTE; + break; + case I2C_SMBUS_BYTE_DATA: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + outb_p(command, SMBHSTCMD); + if (read_write == I2C_SMBUS_WRITE) + outb_p(data->byte, SMBHSTDAT0); + size = I801_BYTE_DATA; + break; + case I2C_SMBUS_WORD_DATA: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + outb_p(command, SMBHSTCMD); + if (read_write == I2C_SMBUS_WRITE) { + outb_p(data->word & 0xff, SMBHSTDAT0); + outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); + } + size = I801_WORD_DATA; + break; + case I2C_SMBUS_BLOCK_DATA: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + outb_p(command, SMBHSTCMD); + /* Block transactions are very different from piix4 block + and from the other i801 transactions. Handle in the + i801_block_transaction() routine. */ + return (i801_block_transaction(data, read_write)); + } - /* 'size' is really the transaction type */ - outb_p((size & 0x3C) + (ENABLE_INT9 & 1), SMBHSTCNT); + /* 'size' is really the transaction type */ + outb_p((size & 0x3C) + (ENABLE_INT9 & 1), SMBHSTCNT); - if (i801_transaction()) /* Error in transaction */ - return -1; - - if ((read_write == I2C_SMBUS_WRITE) || (size == I801_QUICK)) - return 0; - + if (i801_transaction()) /* Error in transaction */ + return -1; - switch(size) { - case I801_BYTE: /* Result put in SMBHSTDAT0 */ - data->byte = inb_p(SMBHSTDAT0); - break; - case I801_BYTE_DATA: - data->byte = inb_p(SMBHSTDAT0); - break; - case I801_WORD_DATA: - data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); - break; - } - return 0; + if ((read_write == I2C_SMBUS_WRITE) || (size == I801_QUICK)) + return 0; + + + switch (size) { + case I801_BYTE: /* Result put in SMBHSTDAT0 */ + data->byte = inb_p(SMBHSTDAT0); + break; + case I801_BYTE_DATA: + data->byte = inb_p(SMBHSTDAT0); + break; + case I801_WORD_DATA: + data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); + break; + } + return 0; } void i801_inc(struct i2c_adapter *adapter) @@ -539,74 +572,78 @@ void i801_dec(struct i2c_adapter *adapter) u32 i801_func(struct i2c_adapter *adapter) { - return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | - I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | - I2C_FUNC_SMBUS_BLOCK_DATA; + return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | + I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | + I2C_FUNC_SMBUS_BLOCK_DATA; } int __init i2c_i801_init(void) { - int res; - printk("i801.o version %s (%s)\n",LM_VERSION,LM_DATE); + int res; + printk("i801.o version %s (%s)\n", LM_VERSION, LM_DATE); #ifdef DEBUG /* PE- It might be good to make this a permanent part of the code! */ - if (i801_initialized) { - printk("i2c-i801.o: Oops, i801_init called a second time!\n"); - return -EBUSY; - } + if (i801_initialized) { + printk + ("i2c-i801.o: Oops, i801_init called a second time!\n"); + return -EBUSY; + } #endif - i801_initialized = 0; - if ((res = i801_setup())) { - printk("i2c-i801.o: I801 not detected, module not inserted.\n"); - i801_cleanup(); - return res; - } - i801_initialized ++; - sprintf(i801_adapter.name,"SMBus I801 adapter at %04x",i801_smba); - if ((res = i2c_add_adapter(&i801_adapter))) { - printk("i2c-i801.o: Adapter registration failed, module not inserted.\n"); - i801_cleanup(); - return res; - } - i801_initialized++; - printk("i2c-i801.o: I801 bus detected and initialized\n"); - return 0; + i801_initialized = 0; + if ((res = i801_setup())) { + printk + ("i2c-i801.o: I801 not detected, module not inserted.\n"); + i801_cleanup(); + return res; + } + i801_initialized++; + sprintf(i801_adapter.name, "SMBus I801 adapter at %04x", + i801_smba); + if ((res = i2c_add_adapter(&i801_adapter))) { + printk + ("i2c-i801.o: Adapter registration failed, module not inserted.\n"); + i801_cleanup(); + return res; + } + i801_initialized++; + printk("i2c-i801.o: I801 bus detected and initialized\n"); + return 0; } int __init i801_cleanup(void) { - int res; - if (i801_initialized >= 2) - { - if ((res = i2c_del_adapter(&i801_adapter))) { - printk("i2c-i801.o: i2c_del_adapter failed, module not removed\n"); - return res; - } else - i801_initialized--; - } - if (i801_initialized >= 1) { - release_region(i801_smba, 8); - i801_initialized--; - } - return 0; + int res; + if (i801_initialized >= 2) { + if ((res = i2c_del_adapter(&i801_adapter))) { + printk + ("i2c-i801.o: i2c_del_adapter failed, module not removed\n"); + return res; + } else + i801_initialized--; + } + if (i801_initialized >= 1) { + release_region(i801_smba, 8); + i801_initialized--; + } + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard , Philip Edelbrock , and Mark D. Studebaker "); +MODULE_AUTHOR + ("Frodo Looijaard , Philip Edelbrock , and Mark D. Studebaker "); MODULE_DESCRIPTION("I801 SMBus driver"); int init_module(void) { - return i2c_i801_init(); + return i2c_i801_init(); } int cleanup_module(void) { - return i801_cleanup(); + return i801_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/busses/i2c-isa.c b/kernel/busses/i2c-isa.c index f46cd049..18d044de 100644 --- a/kernel/busses/i2c-isa.c +++ b/kernel/busses/i2c-isa.c @@ -36,8 +36,8 @@ #include "version.h" #include "i2c-isa.h" -static void isa_inc_use (struct i2c_adapter *adapter); -static void isa_dec_use (struct i2c_adapter *adapter); +static void isa_inc_use(struct i2c_adapter *adapter); +static void isa_dec_use(struct i2c_adapter *adapter); static u32 isa_func(struct i2c_adapter *adapter); #ifdef MODULE @@ -45,95 +45,96 @@ static #else extern #endif - int __init i2c_isa_init(void); +int __init i2c_isa_init(void); static int __init isa_cleanup(void); #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ /* This is the actual algorithm we define */ static struct i2c_algorithm isa_algorithm = { - /* name */ "ISA bus algorithm", - /* id */ I2C_ALGO_ISA, - /* master_xfer */ NULL, - /* smbus_access */ NULL, - /* slave_send */ NULL, - /* slave_rcv */ NULL, - /* algo_control */ NULL, - /* functionality */ &isa_func, + /* name */ "ISA bus algorithm", + /* id */ I2C_ALGO_ISA, + /* master_xfer */ NULL, + /* smbus_access */ NULL, + /* slave_send */ NULL, + /* slave_rcv */ NULL, + /* algo_control */ NULL, + /* functionality */ &isa_func, }; /* There can only be one... */ static struct i2c_adapter isa_adapter = { - /* name */ "ISA main adapter", - /* id */ I2C_ALGO_ISA | I2C_HW_ISA, - /* algorithm */ &isa_algorithm, - /* algo_data */ NULL, - /* inc_use */ &isa_inc_use, - /* dec_use */ &isa_dec_use, - /* data */ NULL, - /* Other fields not initialized */ + /* name */ "ISA main adapter", + /* id */ I2C_ALGO_ISA | I2C_HW_ISA, + /* algorithm */ &isa_algorithm, + /* algo_data */ NULL, + /* inc_use */ &isa_inc_use, + /* dec_use */ &isa_dec_use, + /* data */ NULL, + /* Other fields not initialized */ }; /* Used in isa_init/cleanup */ static int __initdata isa_initialized; -void isa_inc_use (struct i2c_adapter *adapter) +void isa_inc_use(struct i2c_adapter *adapter) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } -void isa_dec_use (struct i2c_adapter *adapter) +void isa_dec_use(struct i2c_adapter *adapter) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } /* We can't do a thing... */ static u32 isa_func(struct i2c_adapter *adapter) { - return 0; + return 0; } int __init i2c_isa_init(void) { - int res; - printk("i2c-isa.o version %s (%s)\n",LM_VERSION,LM_DATE); + int res; + printk("i2c-isa.o version %s (%s)\n", LM_VERSION, LM_DATE); #ifdef DEBUG - if (isa_initialized) { - printk("i2c-isa.o: Oops, isa_init called a second time!\n"); - return -EBUSY; - } + if (isa_initialized) { + printk + ("i2c-isa.o: Oops, isa_init called a second time!\n"); + return -EBUSY; + } #endif - isa_initialized = 0; - if ((res = i2c_add_adapter(&isa_adapter))) { - printk("i2c-isa.o: Adapter registration failed, " - "module i2c-isa.o is not inserted\n."); - isa_cleanup(); - return res; - } - isa_initialized++; - printk("i2c-isa.o: ISA bus access for i2c modules initialized.\n"); - return 0; + isa_initialized = 0; + if ((res = i2c_add_adapter(&isa_adapter))) { + printk("i2c-isa.o: Adapter registration failed, " + "module i2c-isa.o is not inserted\n."); + isa_cleanup(); + return res; + } + isa_initialized++; + printk("i2c-isa.o: ISA bus access for i2c modules initialized.\n"); + return 0; } int __init isa_cleanup(void) { - int res; - if (isa_initialized >= 1) - { - if ((res = i2c_del_adapter(&isa_adapter))) { - printk("i2c-isa.o: Adapter deregistration failed, module not removed.\n"); - return res; - } else - isa_initialized--; - } - return 0; + int res; + if (isa_initialized >= 1) { + if ((res = i2c_del_adapter(&isa_adapter))) { + printk + ("i2c-isa.o: Adapter deregistration failed, module not removed.\n"); + return res; + } else + isa_initialized--; + } + return 0; } EXPORT_NO_SYMBOLS; @@ -145,13 +146,12 @@ MODULE_DESCRIPTION("ISA bus access through i2c"); int init_module(void) { - return i2c_isa_init(); + return i2c_isa_init(); } int cleanup_module(void) { - return isa_cleanup(); + return isa_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/busses/i2c-piix4.c b/kernel/busses/i2c-piix4.c index 0527f817..ff996925 100644 --- a/kernel/busses/i2c-piix4.c +++ b/kernel/busses/i2c-piix4.c @@ -72,28 +72,29 @@ /* If force is set to anything different from 0, we forcibly enable the PIIX4. DANGEROUS! */ static int force = 0; -MODULE_PARM(force,"i"); -MODULE_PARM_DESC(force,"Forcibly enable the PIIX4. DANGEROUS!"); +MODULE_PARM(force, "i"); +MODULE_PARM_DESC(force, "Forcibly enable the PIIX4. DANGEROUS!"); /* If force_addr is set to anything different from 0, we forcibly enable the PIIX4 at the given address. VERY DANGEROUS! */ static int force_addr = 0; -MODULE_PARM(force_addr,"i"); -MODULE_PARM_DESC(force_addr,"Forcibly enable the PIIX4 at the given address. " - "EXTREMELY DANGEROUS!"); +MODULE_PARM(force_addr, "i"); +MODULE_PARM_DESC(force_addr, + "Forcibly enable the PIIX4 at the given address. " + "EXTREMELY DANGEROUS!"); #ifdef MODULE static #else extern #endif - int __init i2c_piix4_init(void); +int __init i2c_piix4_init(void); static int __init piix4_cleanup(void); static int piix4_setup(void); -static s32 piix4_access(struct i2c_adapter *adap, u16 addr, - unsigned short flags, char read_write, - u8 command, int size, union i2c_smbus_data * data); -static void piix4_do_pause( unsigned int amount ); +static s32 piix4_access(struct i2c_adapter *adap, u16 addr, + unsigned short flags, char read_write, + u8 command, int size, union i2c_smbus_data *data); +static void piix4_do_pause(unsigned int amount); static int piix4_transaction(void); static void piix4_inc(struct i2c_adapter *adapter); static void piix4_dec(struct i2c_adapter *adapter); @@ -102,28 +103,28 @@ static u32 piix4_func(struct i2c_adapter *adapter); #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ static struct i2c_algorithm smbus_algorithm = { - /* name */ "Non-I2C SMBus adapter", - /* id */ I2C_ALGO_SMBUS, - /* master_xfer */ NULL, - /* smbus_access */ piix4_access, - /* slave_send */ NULL, - /* slave_rcv */ NULL, - /* algo_control */ NULL, - /* functionality */ piix4_func, + /* name */ "Non-I2C SMBus adapter", + /* id */ I2C_ALGO_SMBUS, + /* master_xfer */ NULL, + /* smbus_access */ piix4_access, + /* slave_send */ NULL, + /* slave_rcv */ NULL, + /* algo_control */ NULL, + /* functionality */ piix4_func, }; static struct i2c_adapter piix4_adapter = { - "unset", - I2C_ALGO_SMBUS | I2C_HW_SMBUS_PIIX4, - &smbus_algorithm, - NULL, - piix4_inc, - piix4_dec, - NULL, - NULL, + "unset", + I2C_ALGO_SMBUS | I2C_HW_SMBUS_PIIX4, + &smbus_algorithm, + NULL, + piix4_inc, + piix4_dec, + NULL, + NULL, }; static int __initdata piix4_initialized; @@ -136,275 +137,296 @@ static unsigned short piix4_smba = 0; defined to make the transition easier. */ int piix4_setup(void) { - int error_return=0; - unsigned char temp; + int error_return = 0; + unsigned char temp; - struct pci_dev *PIIX4_dev; + struct pci_dev *PIIX4_dev; - /* First check whether we can access PCI at all */ - if (pci_present() == 0) { - printk("i2c-piix4.o: Error: No PCI-bus found!\n"); - error_return=-ENODEV; - goto END; - } + /* First check whether we can access PCI at all */ + if (pci_present() == 0) { + printk("i2c-piix4.o: Error: No PCI-bus found!\n"); + error_return = -ENODEV; + goto END; + } - /* Look for the PIIX4, function 3 */ - /* Note: we keep on searching until we have found 'function 3' */ - PIIX4_dev = NULL; - do - PIIX4_dev = pci_find_device(PCI_VENDOR_ID_INTEL, - PCI_DEVICE_ID_INTEL_82371AB_3, PIIX4_dev); - while(PIIX4_dev && (PCI_FUNC(PIIX4_dev->devfn) != 3)); - if(PIIX4_dev == NULL) { - printk("i2c-piix4.o: Error: Can't detect PIIX4, function 3!\n"); - error_return=-ENODEV; - goto END; - } + /* Look for the PIIX4, function 3 */ + /* Note: we keep on searching until we have found 'function 3' */ + PIIX4_dev = NULL; + do + PIIX4_dev = pci_find_device(PCI_VENDOR_ID_INTEL, + PCI_DEVICE_ID_INTEL_82371AB_3, + PIIX4_dev); + while (PIIX4_dev && (PCI_FUNC(PIIX4_dev->devfn) != 3)); + if (PIIX4_dev == NULL) { + printk + ("i2c-piix4.o: Error: Can't detect PIIX4, function 3!\n"); + error_return = -ENODEV; + goto END; + } /* Determine the address of the SMBus areas */ - if (force_addr) { - piix4_smba = force_addr & 0xfff0; - force = 0; - } else { + if (force_addr) { + piix4_smba = force_addr & 0xfff0; + force = 0; + } else { - pci_read_config_word(PIIX4_dev, SMBBA,&piix4_smba); - piix4_smba &= 0xfff0; - } + pci_read_config_word(PIIX4_dev, SMBBA, &piix4_smba); + piix4_smba &= 0xfff0; + } - if (check_region(piix4_smba, 8)) { - printk("i2c-piix4.o: PIIX4_smb region 0x%x already in use!\n", piix4_smba); - error_return=-ENODEV; - goto END; - } + if (check_region(piix4_smba, 8)) { + printk + ("i2c-piix4.o: PIIX4_smb region 0x%x already in use!\n", + piix4_smba); + error_return = -ENODEV; + goto END; + } - pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp); + pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp); /* If force_addr is set, we program the new address here. Just to make sure, we disable the PIIX4 first. */ - if (force_addr) { - pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp & 0xfe); - pci_write_config_word(PIIX4_dev, SMBBA,piix4_smba); - pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp | 0x01); - printk("i2c-piix4.o: WARNING: PIIX4 SMBus interface set to new " - "address %04x!\n",piix4_smba); - } else if ((temp & 1) == 0) { - if (force) { + if (force_addr) { + pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp & 0xfe); + pci_write_config_word(PIIX4_dev, SMBBA, piix4_smba); + pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp | 0x01); + printk + ("i2c-piix4.o: WARNING: PIIX4 SMBus interface set to new " + "address %04x!\n", piix4_smba); + } else if ((temp & 1) == 0) { + if (force) { /* This should never need to be done, but has been noted that many Dell machines have the SMBus interface on the PIIX4 disabled!? NOTE: This assumes I/O space and other allocations WERE done by the Bios! Don't complain if your hardware does weird things after enabling this. :') Check for Bios updates before resorting to this. */ - pci_write_config_byte(PIIX4_dev, SMBHSTCFG, temp | 1); - printk("i2c-piix4.o: WARNING: PIIX4 SMBus interface has been FORCEFULLY " - "ENABLED!\n"); - } else { - printk("SMBUS: Error: Host SMBus controller not enabled!\n"); - error_return=-ENODEV; - goto END; - } - } + pci_write_config_byte(PIIX4_dev, SMBHSTCFG, + temp | 1); + printk + ("i2c-piix4.o: WARNING: PIIX4 SMBus interface has been FORCEFULLY " + "ENABLED!\n"); + } else { + printk + ("SMBUS: Error: Host SMBus controller not enabled!\n"); + error_return = -ENODEV; + goto END; + } + } - /* Everything is happy, let's grab the memory and set things up. */ - request_region(piix4_smba, 8, "piix4-smbus"); + /* Everything is happy, let's grab the memory and set things up. */ + request_region(piix4_smba, 8, "piix4-smbus"); #ifdef DEBUG - if ((temp & 0x0E) == 8) - printk("i2c-piix4.o: PIIX4 using Interrupt 9 for SMBus.\n"); - else if ((temp & 0x0E) == 0) - printk("i2c-piix4.o: PIIX4 using Interrupt SMI# for SMBus.\n"); - else - printk("i2c-piix4.o: PIIX4: Illegal Interrupt configuration (or code out " - "of date)!\n"); + if ((temp & 0x0E) == 8) + printk + ("i2c-piix4.o: PIIX4 using Interrupt 9 for SMBus.\n"); + else if ((temp & 0x0E) == 0) + printk + ("i2c-piix4.o: PIIX4 using Interrupt SMI# for SMBus.\n"); + else + printk + ("i2c-piix4.o: PIIX4: Illegal Interrupt configuration (or code out " + "of date)!\n"); - pci_read_config_byte(PIIX4_dev, SMBREV, &temp); - printk("i2c-piix4.o: SMBREV = 0x%X\n",temp); - printk("i2c-piix4.o: PIIX4_smba = 0x%X\n",piix4_smba); -#endif /* DEBUG */ + pci_read_config_byte(PIIX4_dev, SMBREV, &temp); + printk("i2c-piix4.o: SMBREV = 0x%X\n", temp); + printk("i2c-piix4.o: PIIX4_smba = 0x%X\n", piix4_smba); +#endif /* DEBUG */ -END: - return error_return; + END: + return error_return; } /* Internally used pause function */ -void piix4_do_pause( unsigned int amount ) +void piix4_do_pause(unsigned int amount) { - current->state = TASK_INTERRUPTIBLE; - schedule_timeout(amount); + current->state = TASK_INTERRUPTIBLE; + schedule_timeout(amount); } /* Another internally used function */ -int piix4_transaction(void) +int piix4_transaction(void) { - int temp; - int result=0; - int timeout=0; + int temp; + int result = 0; + int timeout = 0; #ifdef DEBUG - printk("i2c-piix4.o: Transaction (pre): CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, " - "DAT1=%02x\n", - inb_p(SMBHSTCNT),inb_p(SMBHSTCMD),inb_p(SMBHSTADD),inb_p(SMBHSTDAT0), - inb_p(SMBHSTDAT1)); + printk + ("i2c-piix4.o: Transaction (pre): CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, " + "DAT1=%02x\n", inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), + inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1)); #endif - /* Make sure the SMBus host is ready to start transmitting */ - if ((temp = inb_p(SMBHSTSTS)) != 0x00) { + /* Make sure the SMBus host is ready to start transmitting */ + if ((temp = inb_p(SMBHSTSTS)) != 0x00) { #ifdef DEBUG - printk("i2c-piix4.o: SMBus busy (%02x). Resetting... \n",temp); + printk("i2c-piix4.o: SMBus busy (%02x). Resetting... \n", + temp); #endif - outb_p(temp, SMBHSTSTS); - if ((temp = inb_p(SMBHSTSTS)) != 0x00) { + outb_p(temp, SMBHSTSTS); + if ((temp = inb_p(SMBHSTSTS)) != 0x00) { #ifdef DEBUG - printk("i2c-piix4.o: Failed! (%02x)\n",temp); + printk("i2c-piix4.o: Failed! (%02x)\n", temp); #endif - return -1; - } else { + return -1; + } else { #ifdef DEBUG - printk("i2c-piix4.o: Successfull!\n"); + printk("i2c-piix4.o: Successfull!\n"); #endif - } - } + } + } - /* start the transaction by setting bit 6 */ - outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); + /* start the transaction by setting bit 6 */ + outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); - /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */ - do { - piix4_do_pause(1); - temp=inb_p(SMBHSTSTS); - } while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT)); + /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */ + do { + piix4_do_pause(1); + temp = inb_p(SMBHSTSTS); + } while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT)); - /* If the SMBus is still busy, we give up */ - if (timeout >= MAX_TIMEOUT) { + /* If the SMBus is still busy, we give up */ + if (timeout >= MAX_TIMEOUT) { #ifdef DEBUG - printk("i2c-piix4.o: SMBus Timeout!\n"); - result = -1; + printk("i2c-piix4.o: SMBus Timeout!\n"); + result = -1; #endif - } + } - if (temp & 0x10) { - result = -1; + if (temp & 0x10) { + result = -1; #ifdef DEBUG - printk("i2c-piix4.o: Error: Failed bus transaction\n"); + printk("i2c-piix4.o: Error: Failed bus transaction\n"); #endif - } + } - if (temp & 0x08) { - result = -1; - printk("i2c-piix4.o: Bus collision! SMBus may be locked until next hard - reset. (sorry!)\n"); - /* Clock stops and slave is stuck in mid-transmission */ - } + if (temp & 0x08) { + result = -1; + printk + ("i2c-piix4.o: Bus collision! SMBus may be locked until next hard\n" + "reset. (sorry!)\n"); + /* Clock stops and slave is stuck in mid-transmission */ + } - if (temp & 0x04) { - result = -1; + if (temp & 0x04) { + result = -1; #ifdef DEBUG - printk("i2c-piix4.o: Error: no response!\n"); + printk("i2c-piix4.o: Error: no response!\n"); #endif - } + } - if (inb_p(SMBHSTSTS) != 0x00) - outb_p( inb(SMBHSTSTS), SMBHSTSTS); + if (inb_p(SMBHSTSTS) != 0x00) + outb_p(inb(SMBHSTSTS), SMBHSTSTS); - if ((temp = inb_p(SMBHSTSTS)) != 0x00) { + if ((temp = inb_p(SMBHSTSTS)) != 0x00) { #ifdef DEBUG - printk("i2c-piix4.o: Failed reset at end of transaction (%02x)\n",temp); + printk + ("i2c-piix4.o: Failed reset at end of transaction (%02x)\n", + temp); #endif - } + } #ifdef DEBUG - printk("i2c-piix4.o: Transaction (post): CNT=%02x, CMD=%02x, ADD=%02x, " - "DAT0=%02x, DAT1=%02x\n", - inb_p(SMBHSTCNT),inb_p(SMBHSTCMD),inb_p(SMBHSTADD),inb_p(SMBHSTDAT0), - inb_p(SMBHSTDAT1)); + printk + ("i2c-piix4.o: Transaction (post): CNT=%02x, CMD=%02x, ADD=%02x, " + "DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), + inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1)); #endif - return result; + return result; } /* Return -1 on error. See smbus.h for more information */ -s32 piix4_access(struct i2c_adapter *adap, u16 addr, - unsigned short flags, char read_write, - u8 command, int size, union i2c_smbus_data * data) +s32 piix4_access(struct i2c_adapter * adap, u16 addr, + unsigned short flags, char read_write, + u8 command, int size, union i2c_smbus_data * data) { - int i,len; + int i, len; - switch(size) { - case I2C_SMBUS_PROC_CALL: - printk("i2c-piix4.o: I2C_SMBUS_PROC_CALL not supported!\n"); - return -1; - case I2C_SMBUS_QUICK: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - size = PIIX4_QUICK; - break; - case I2C_SMBUS_BYTE: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - if (read_write == I2C_SMBUS_WRITE) - outb_p(command, SMBHSTCMD); - size = PIIX4_BYTE; - break; - case I2C_SMBUS_BYTE_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - outb_p(command, SMBHSTCMD); - if (read_write == I2C_SMBUS_WRITE) - outb_p(data->byte,SMBHSTDAT0); - size = PIIX4_BYTE_DATA; - break; - case I2C_SMBUS_WORD_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - outb_p(command, SMBHSTCMD); - if (read_write == I2C_SMBUS_WRITE) { - outb_p(data->word & 0xff,SMBHSTDAT0); - outb_p((data->word & 0xff00) >> 8,SMBHSTDAT1); - } - size = PIIX4_WORD_DATA; - break; - case I2C_SMBUS_BLOCK_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - outb_p(command, SMBHSTCMD); - if (read_write == I2C_SMBUS_WRITE) { - len = data->block[0]; - if (len < 0) - len = 0; - if (len > 32) - len = 32; - outb_p(len,SMBHSTDAT0); - i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ - for (i = 1; i <= len; i ++) - outb_p(data->block[i],SMBBLKDAT); - } - size = PIIX4_BLOCK_DATA; - break; - } + switch (size) { + case I2C_SMBUS_PROC_CALL: + printk + ("i2c-piix4.o: I2C_SMBUS_PROC_CALL not supported!\n"); + return -1; + case I2C_SMBUS_QUICK: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + size = PIIX4_QUICK; + break; + case I2C_SMBUS_BYTE: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + if (read_write == I2C_SMBUS_WRITE) + outb_p(command, SMBHSTCMD); + size = PIIX4_BYTE; + break; + case I2C_SMBUS_BYTE_DATA: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + outb_p(command, SMBHSTCMD); + if (read_write == I2C_SMBUS_WRITE) + outb_p(data->byte, SMBHSTDAT0); + size = PIIX4_BYTE_DATA; + break; + case I2C_SMBUS_WORD_DATA: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + outb_p(command, SMBHSTCMD); + if (read_write == I2C_SMBUS_WRITE) { + outb_p(data->word & 0xff, SMBHSTDAT0); + outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); + } + size = PIIX4_WORD_DATA; + break; + case I2C_SMBUS_BLOCK_DATA: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + outb_p(command, SMBHSTCMD); + if (read_write == I2C_SMBUS_WRITE) { + len = data->block[0]; + if (len < 0) + len = 0; + if (len > 32) + len = 32; + outb_p(len, SMBHSTDAT0); + i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ + for (i = 1; i <= len; i++) + outb_p(data->block[i], SMBBLKDAT); + } + size = PIIX4_BLOCK_DATA; + break; + } - outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); + outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); - if (piix4_transaction()) /* Error in transaction */ - return -1; - - if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK)) - return 0; - + if (piix4_transaction()) /* Error in transaction */ + return -1; - switch(size) { - case PIIX4_BYTE: /* Where is the result put? I assume here it is in - SMBHSTDAT0 but it might just as well be in the - SMBHSTCMD. No clue in the docs */ - - data->byte = inb_p(SMBHSTDAT0); - break; - case PIIX4_BYTE_DATA: - data->byte = inb_p(SMBHSTDAT0); - break; - case PIIX4_WORD_DATA: - data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); - break; - case PIIX4_BLOCK_DATA: - data->block[0] = inb_p(SMBHSTDAT0); - i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ - for (i = 1; i <= data->block[0]; i++) - data->block[i] = inb_p(SMBBLKDAT); - break; - } - return 0; + if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK)) + return 0; + + + switch (size) { + case PIIX4_BYTE: /* Where is the result put? I assume here it is in + SMBHSTDAT0 but it might just as well be in the + SMBHSTCMD. No clue in the docs */ + + data->byte = inb_p(SMBHSTDAT0); + break; + case PIIX4_BYTE_DATA: + data->byte = inb_p(SMBHSTDAT0); + break; + case PIIX4_WORD_DATA: + data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); + break; + case PIIX4_BLOCK_DATA: + data->block[0] = inb_p(SMBHSTDAT0); + i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ + for (i = 1; i <= data->block[0]; i++) + data->block[i] = inb_p(SMBBLKDAT); + break; + } + return 0; } void piix4_inc(struct i2c_adapter *adapter) @@ -420,74 +442,78 @@ void piix4_dec(struct i2c_adapter *adapter) u32 piix4_func(struct i2c_adapter *adapter) { - return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | - I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | - I2C_FUNC_SMBUS_BLOCK_DATA; + return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | + I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | + I2C_FUNC_SMBUS_BLOCK_DATA; } int __init i2c_piix4_init(void) { - int res; - printk("piix4.o version %s (%s)\n",LM_VERSION,LM_DATE); + int res; + printk("piix4.o version %s (%s)\n", LM_VERSION, LM_DATE); #ifdef DEBUG /* PE- It might be good to make this a permanent part of the code! */ - if (piix4_initialized) { - printk("i2c-piix4.o: Oops, piix4_init called a second time!\n"); - return -EBUSY; - } + if (piix4_initialized) { + printk + ("i2c-piix4.o: Oops, piix4_init called a second time!\n"); + return -EBUSY; + } #endif - piix4_initialized = 0; - if ((res = piix4_setup())) { - printk("i2c-piix4.o: PIIX4 not detected, module not inserted.\n"); - piix4_cleanup(); - return res; - } - piix4_initialized ++; - sprintf(piix4_adapter.name,"SMBus PIIX4 adapter at %04x",piix4_smba); - if ((res = i2c_add_adapter(&piix4_adapter))) { - printk("i2c-piix4.o: Adapter registration failed, module not inserted.\n"); - piix4_cleanup(); - return res; - } - piix4_initialized++; - printk("i2c-piix4.o: PIIX4 bus detected and initialized\n"); - return 0; + piix4_initialized = 0; + if ((res = piix4_setup())) { + printk + ("i2c-piix4.o: PIIX4 not detected, module not inserted.\n"); + piix4_cleanup(); + return res; + } + piix4_initialized++; + sprintf(piix4_adapter.name, "SMBus PIIX4 adapter at %04x", + piix4_smba); + if ((res = i2c_add_adapter(&piix4_adapter))) { + printk + ("i2c-piix4.o: Adapter registration failed, module not inserted.\n"); + piix4_cleanup(); + return res; + } + piix4_initialized++; + printk("i2c-piix4.o: PIIX4 bus detected and initialized\n"); + return 0; } int __init piix4_cleanup(void) { - int res; - if (piix4_initialized >= 2) - { - if ((res = i2c_del_adapter(&piix4_adapter))) { - printk("i2c-piix4.o: i2c_del_adapter failed, module not removed\n"); - return res; - } else - piix4_initialized--; - } - if (piix4_initialized >= 1) { - release_region(piix4_smba, 8); - piix4_initialized--; - } - return 0; + int res; + if (piix4_initialized >= 2) { + if ((res = i2c_del_adapter(&piix4_adapter))) { + printk + ("i2c-piix4.o: i2c_del_adapter failed, module not removed\n"); + return res; + } else + piix4_initialized--; + } + if (piix4_initialized >= 1) { + release_region(piix4_smba, 8); + piix4_initialized--; + } + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard and Philip Edelbrock "); +MODULE_AUTHOR + ("Frodo Looijaard and Philip Edelbrock "); MODULE_DESCRIPTION("PIIX4 SMBus driver"); int init_module(void) { - return i2c_piix4_init(); + return i2c_piix4_init(); } int cleanup_module(void) { - return piix4_cleanup(); + return piix4_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/busses/i2c-sis5595.c b/kernel/busses/i2c-sis5595.c index 3e80e203..158090e0 100644 --- a/kernel/busses/i2c-sis5595.c +++ b/kernel/busses/i2c-sis5595.c @@ -77,13 +77,14 @@ static #else extern #endif - int __init i2c_sis5595_init(void); +int __init i2c_sis5595_init(void); static int __init sis5595_cleanup(void); static int sis5595_setup(void); -static s32 sis5595_access(struct i2c_adapter *adap, u16 addr, - unsigned short flags, char read_write, - u8 command, int size, union i2c_smbus_data * data); -static void sis5595_do_pause( unsigned int amount ); +static s32 sis5595_access(struct i2c_adapter *adap, u16 addr, + unsigned short flags, char read_write, + u8 command, int size, + union i2c_smbus_data *data); +static void sis5595_do_pause(unsigned int amount); static int sis5595_transaction(void); static void sis5595_inc(struct i2c_adapter *adapter); static void sis5595_dec(struct i2c_adapter *adapter); @@ -92,28 +93,28 @@ static u32 sis5595_func(struct i2c_adapter *adapter); #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ static struct i2c_algorithm smbus_algorithm = { - /* name */ "Non-I2C SMBus adapter", - /* id */ I2C_ALGO_SMBUS, - /* master_xfer */ NULL, - /* smbus_access */ sis5595_access, - /* slave_send */ NULL, - /* slave_rcv */ NULL, - /* algo_control */ NULL, - /* functionality */ sis5595_func, + /* name */ "Non-I2C SMBus adapter", + /* id */ I2C_ALGO_SMBUS, + /* master_xfer */ NULL, + /* smbus_access */ sis5595_access, + /* slave_send */ NULL, + /* slave_rcv */ NULL, + /* algo_control */ NULL, + /* functionality */ sis5595_func, }; static struct i2c_adapter sis5595_adapter = { - "unset", - I2C_ALGO_SMBUS | I2C_HW_SMBUS_SIS5595, - &smbus_algorithm, - NULL, - sis5595_inc, - sis5595_dec, - NULL, - NULL, + "unset", + I2C_ALGO_SMBUS | I2C_HW_SMBUS_SIS5595, + &smbus_algorithm, + NULL, + sis5595_inc, + sis5595_dec, + NULL, + NULL, }; static int __initdata sis5595_initialized; @@ -121,14 +122,14 @@ static unsigned short sis5595_base = 0; static u8 sis5595_read(u8 reg) { - outb(reg,sis5595_base+SMB_INDEX); - return inb(sis5595_base+SMB_DAT); + outb(reg, sis5595_base + SMB_INDEX); + return inb(sis5595_base + SMB_DAT); } static void sis5595_write(u8 reg, u8 data) { - outb(reg,sis5595_base+SMB_INDEX); - outb(data,sis5595_base+SMB_DAT); + outb(reg, sis5595_base + SMB_INDEX); + outb(data, sis5595_base + SMB_DAT); } @@ -138,192 +139,217 @@ static void sis5595_write(u8 reg, u8 data) defined to make the transition easier. */ int sis5595_setup(void) { - int error_return=0; + int error_return = 0; - struct pci_dev *SIS5595_dev; + struct pci_dev *SIS5595_dev; - /* First check whether we can access PCI at all */ - if (pci_present() == 0) { - printk("i2c-sis5595.o: Error: No PCI-bus found!\n"); - error_return=-ENODEV; - goto END; - } + /* First check whether we can access PCI at all */ + if (pci_present() == 0) { + printk("i2c-sis5595.o: Error: No PCI-bus found!\n"); + error_return = -ENODEV; + goto END; + } - /* Look for the SIS5595, function 3 */ - SIS5595_dev = NULL; - if (!(SIS5595_dev = pci_find_device(PCI_VENDOR_ID_SI, - PCI_DEVICE_ID_SI_503, SIS5595_dev))) { - printk("i2c-sis5595.o: Error: Can't detect SIS5595!\n"); - error_return=-ENODEV; - goto END; - } + /* Look for the SIS5595, function 3 */ + SIS5595_dev = NULL; + if (!(SIS5595_dev = pci_find_device(PCI_VENDOR_ID_SI, + PCI_DEVICE_ID_SI_503, + SIS5595_dev))) { + printk("i2c-sis5595.o: Error: Can't detect SIS5595!\n"); + error_return = -ENODEV; + goto END; + } /* Determine the address of the SMBus areas */ - pci_read_config_word(SIS5595_dev, ACPI_BASE,&sis5595_base); + pci_read_config_word(SIS5595_dev, ACPI_BASE, &sis5595_base); #ifdef DEBUG - printk("ACPI Base address: %04x\n",sis5595_base); + printk("ACPI Base address: %04x\n", sis5595_base); #endif - /* NB: We grab just the two SMBus registers here, but this may still - * interfere with ACPI :-( */ - if (check_region(sis5595_base + SMB_INDEX, 2)) { - printk("i2c-sis5595.o: SMBus registers 0x%4x-0x%4x already in use!\n", - sis5595_base + SMB_INDEX,sis5595_base + SMB_INDEX+1); - error_return=-ENODEV; - goto END; - } + /* NB: We grab just the two SMBus registers here, but this may still + * interfere with ACPI :-( */ + if (check_region(sis5595_base + SMB_INDEX, 2)) { + printk + ("i2c-sis5595.o: SMBus registers 0x%4x-0x%4x already in use!\n", + sis5595_base + SMB_INDEX, + sis5595_base + SMB_INDEX + 1); + error_return = -ENODEV; + goto END; + } - /* Everything is happy, let's grab the memory and set things up. */ - request_region(sis5595_base + SMB_INDEX, 2, "sis5595-smbus"); + /* Everything is happy, let's grab the memory and set things up. */ + request_region(sis5595_base + SMB_INDEX, 2, "sis5595-smbus"); -END: - return error_return; + END: + return error_return; } /* Internally used pause function */ -void sis5595_do_pause( unsigned int amount ) +void sis5595_do_pause(unsigned int amount) { - current->state = TASK_INTERRUPTIBLE; - schedule_timeout(amount); + current->state = TASK_INTERRUPTIBLE; + schedule_timeout(amount); } /* Another internally used function */ -int sis5595_transaction(void) +int sis5595_transaction(void) { - int temp; - int result=0; - int timeout=0; + int temp; + int result = 0; + int timeout = 0; - /* Make sure the SMBus host is ready to start transmitting */ - if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) - != 0x00) { + /* Make sure the SMBus host is ready to start transmitting */ + if ( + (temp = + sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) != + 0x00) { #ifdef DEBUG - printk("i2c-sis5595.o: SMBus busy (%04x). Resetting... \n",temp); + printk("i2c-sis5595.o: SMBus busy (%04x). Resetting... \n", + temp); #endif - sis5595_write(SMB_STS_LO,temp & 0xff); - sis5595_write(SMB_STS_HI,temp >> 8); - if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) - != 0x00) { + sis5595_write(SMB_STS_LO, temp & 0xff); + sis5595_write(SMB_STS_HI, temp >> 8); + if ( + (temp = + sis5595_read(SMB_STS_LO) + + (sis5595_read(SMB_STS_HI) << 8)) != 0x00) { #ifdef DEBUG - printk("i2c-sis5595.o: Failed! (%02x)\n",temp); + printk("i2c-sis5595.o: Failed! (%02x)\n", temp); #endif - return -1; - } else { + return -1; + } else { #ifdef DEBUG - printk("i2c-sis5595.o: Successfull!\n"); + printk("i2c-sis5595.o: Successfull!\n"); #endif - } - } + } + } - /* start the transaction by setting bit 4 */ - sis5595_write(SMB_CTL_LO,sis5595_read(SMB_CTL_LO)|0x10); + /* start the transaction by setting bit 4 */ + sis5595_write(SMB_CTL_LO, sis5595_read(SMB_CTL_LO) | 0x10); - /* We will always wait for a fraction of a second! */ - do { - sis5595_do_pause(1); - temp=sis5595_read(SMB_STS_LO); - } while (!(temp & 0x40) && (timeout++ < MAX_TIMEOUT)); + /* We will always wait for a fraction of a second! */ + do { + sis5595_do_pause(1); + temp = sis5595_read(SMB_STS_LO); + } while (!(temp & 0x40) && (timeout++ < MAX_TIMEOUT)); - /* If the SMBus is still busy, we give up */ - if (timeout >= MAX_TIMEOUT) { + /* If the SMBus is still busy, we give up */ + if (timeout >= MAX_TIMEOUT) { #ifdef DEBUG - printk("i2c-sis5595.o: SMBus Timeout!\n"); + printk("i2c-sis5595.o: SMBus Timeout!\n"); #endif - result = -1; - } + result = -1; + } - if (temp & 0x10) { - result = -1; + if (temp & 0x10) { + result = -1; #ifdef DEBUG - printk("i2c-sis5595.o: Error: Failed bus transaction\n"); + printk("i2c-sis5595.o: Error: Failed bus transaction\n"); #endif - } + } - if (temp & 0x20) { - result = -1; - printk("i2c-sis5595.o: Bus collision! SMBus may be locked until next hard - reset (or not...)\n"); - /* Clock stops and slave is stuck in mid-transmission */ - } + if (temp & 0x20) { + result = -1; + printk + ("i2c-sis5595.o: Bus collision! SMBus may be locked until next hard\n" + "reset (or not...)\n"); + /* Clock stops and slave is stuck in mid-transmission */ + } - if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) - != 0x00) { - sis5595_write(SMB_STS_LO,temp & 0xff); - sis5595_write(SMB_STS_HI,temp >> 8); - } + if ( + (temp = + sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) != + 0x00) { + sis5595_write(SMB_STS_LO, temp & 0xff); + sis5595_write(SMB_STS_HI, temp >> 8); + } - if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) - != 0x00) { + if ( + (temp = + sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) != + 0x00) { #ifdef DEBUG - printk("i2c-sis5595.o: Failed reset at end of transaction (%02x)\n",temp); + printk + ("i2c-sis5595.o: Failed reset at end of transaction (%02x)\n", + temp); #endif - } - return result; + } + return result; } /* Return -1 on error. See smbus.h for more information */ -s32 sis5595_access(struct i2c_adapter *adap, u16 addr, - unsigned short flags, char read_write, - u8 command, int size, union i2c_smbus_data * data) +s32 sis5595_access(struct i2c_adapter * adap, u16 addr, + unsigned short flags, char read_write, + u8 command, int size, union i2c_smbus_data * data) { - switch(size) { - case I2C_SMBUS_QUICK: - sis5595_write(SMB_ADDR,((addr & 0x7f) << 1) | (read_write & 0x01)); - size = SIS5595_QUICK; - break; - case I2C_SMBUS_BYTE: - sis5595_write(SMB_ADDR,((addr & 0x7f) << 1) | (read_write & 0x01)); - if (read_write == I2C_SMBUS_WRITE) - sis5595_write(SMB_CMD,command); - size = SIS5595_BYTE; - break; - case I2C_SMBUS_BYTE_DATA: - sis5595_write(SMB_ADDR,((addr & 0x7f) << 1) | (read_write & 0x01)); - sis5595_write(SMB_CMD,command); - if (read_write == I2C_SMBUS_WRITE) - sis5595_write(SMB_BYTE,data->byte); - size = SIS5595_BYTE_DATA; - break; - case I2C_SMBUS_PROC_CALL: - case I2C_SMBUS_WORD_DATA: - sis5595_write(SMB_ADDR,((addr & 0x7f) << 1) | (read_write & 0x01)); - sis5595_write(SMB_CMD,command); - if (read_write == I2C_SMBUS_WRITE) { - sis5595_write(SMB_BYTE,data->word & 0xff); - sis5595_write(SMB_BYTE+1,(data->word & 0xff00) >> 8); - } - size = (size==I2C_SMBUS_PROC_CALL)?SIS5595_PROC_CALL:SIS5595_WORD_DATA; - break; - case I2C_SMBUS_BLOCK_DATA: - printk("sis5595.o: Block data not yet implemented!\n"); - return -1; - break; - } + switch (size) { + case I2C_SMBUS_QUICK: + sis5595_write(SMB_ADDR, + ((addr & 0x7f) << 1) | (read_write & 0x01)); + size = SIS5595_QUICK; + break; + case I2C_SMBUS_BYTE: + sis5595_write(SMB_ADDR, + ((addr & 0x7f) << 1) | (read_write & 0x01)); + if (read_write == I2C_SMBUS_WRITE) + sis5595_write(SMB_CMD, command); + size = SIS5595_BYTE; + break; + case I2C_SMBUS_BYTE_DATA: + sis5595_write(SMB_ADDR, + ((addr & 0x7f) << 1) | (read_write & 0x01)); + sis5595_write(SMB_CMD, command); + if (read_write == I2C_SMBUS_WRITE) + sis5595_write(SMB_BYTE, data->byte); + size = SIS5595_BYTE_DATA; + break; + case I2C_SMBUS_PROC_CALL: + case I2C_SMBUS_WORD_DATA: + sis5595_write(SMB_ADDR, + ((addr & 0x7f) << 1) | (read_write & 0x01)); + sis5595_write(SMB_CMD, command); + if (read_write == I2C_SMBUS_WRITE) { + sis5595_write(SMB_BYTE, data->word & 0xff); + sis5595_write(SMB_BYTE + 1, + (data->word & 0xff00) >> 8); + } + size = + (size == + I2C_SMBUS_PROC_CALL) ? SIS5595_PROC_CALL : + SIS5595_WORD_DATA; + break; + case I2C_SMBUS_BLOCK_DATA: + printk("sis5595.o: Block data not yet implemented!\n"); + return -1; + break; + } - sis5595_write(SMB_CTL_LO,((size & 0x0E))); + sis5595_write(SMB_CTL_LO, ((size & 0x0E))); - if (sis5595_transaction()) /* Error in transaction */ - return -1; - - if ((size != SIS5595_PROC_CALL) && - ((read_write == I2C_SMBUS_WRITE) || (size == SIS5595_QUICK))) - return 0; - + if (sis5595_transaction()) /* Error in transaction */ + return -1; - switch(size) { - case SIS5595_BYTE: /* Where is the result put? I assume here it is in - SMB_DATA but it might just as well be in the - SMB_CMD. No clue in the docs */ - case SIS5595_BYTE_DATA: - data->byte = sis5595_read(SMB_BYTE); - break; - case SIS5595_WORD_DATA: - case SIS5595_PROC_CALL: - data->word = sis5595_read(SMB_BYTE) + (sis5595_read(SMB_BYTE+1) << 8); - break; - } - return 0; + if ((size != SIS5595_PROC_CALL) && + ((read_write == I2C_SMBUS_WRITE) || (size == SIS5595_QUICK))) + return 0; + + + switch (size) { + case SIS5595_BYTE: /* Where is the result put? I assume here it is in + SMB_DATA but it might just as well be in the + SMB_CMD. No clue in the docs */ + case SIS5595_BYTE_DATA: + data->byte = sis5595_read(SMB_BYTE); + break; + case SIS5595_WORD_DATA: + case SIS5595_PROC_CALL: + data->word = + sis5595_read(SMB_BYTE) + + (sis5595_read(SMB_BYTE + 1) << 8); + break; + } + return 0; } void sis5595_inc(struct i2c_adapter *adapter) @@ -339,56 +365,60 @@ void sis5595_dec(struct i2c_adapter *adapter) u32 sis5595_func(struct i2c_adapter *adapter) { - return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | - I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | - I2C_FUNC_SMBUS_PROC_CALL; + return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | + I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | + I2C_FUNC_SMBUS_PROC_CALL; } int __init i2c_sis5595_init(void) { - int res; - printk("sis5595.o version %s (%s)\n",LM_VERSION,LM_DATE); + int res; + printk("sis5595.o version %s (%s)\n", LM_VERSION, LM_DATE); #ifdef DEBUG /* PE- It might be good to make this a permanent part of the code! */ - if (sis5595_initialized) { - printk("i2c-sis5595.o: Oops, sis5595_init called a second time!\n"); - return -EBUSY; - } + if (sis5595_initialized) { + printk + ("i2c-sis5595.o: Oops, sis5595_init called a second time!\n"); + return -EBUSY; + } #endif - sis5595_initialized = 0; - if ((res = sis5595_setup())) { - printk("i2c-sis5595.o: SIS5595 not detected, module not inserted.\n"); - sis5595_cleanup(); - return res; - } - sis5595_initialized ++; - sprintf(sis5595_adapter.name,"SMBus SIS5595 adapter at %04x",sis5595_base + SMB_INDEX); - if ((res = i2c_add_adapter(&sis5595_adapter))) { - printk("i2c-sis5595.o: Adapter registration failed, module not inserted.\n"); - sis5595_cleanup(); - return res; - } - sis5595_initialized++; - printk("i2c-sis5595.o: SIS5595 bus detected and initialized\n"); - return 0; + sis5595_initialized = 0; + if ((res = sis5595_setup())) { + printk + ("i2c-sis5595.o: SIS5595 not detected, module not inserted.\n"); + sis5595_cleanup(); + return res; + } + sis5595_initialized++; + sprintf(sis5595_adapter.name, "SMBus SIS5595 adapter at %04x", + sis5595_base + SMB_INDEX); + if ((res = i2c_add_adapter(&sis5595_adapter))) { + printk + ("i2c-sis5595.o: Adapter registration failed, module not inserted.\n"); + sis5595_cleanup(); + return res; + } + sis5595_initialized++; + printk("i2c-sis5595.o: SIS5595 bus detected and initialized\n"); + return 0; } int __init sis5595_cleanup(void) { - int res; - if (sis5595_initialized >= 2) - { - if ((res = i2c_del_adapter(&sis5595_adapter))) { - printk("i2c-sis5595.o: i2c_del_adapter failed, module not removed\n"); - return res; - } else - sis5595_initialized--; - } - if (sis5595_initialized >= 1) { - release_region(sis5595_base + SMB_INDEX, 2); - sis5595_initialized--; - } - return 0; + int res; + if (sis5595_initialized >= 2) { + if ((res = i2c_del_adapter(&sis5595_adapter))) { + printk + ("i2c-sis5595.o: i2c_del_adapter failed, module not removed\n"); + return res; + } else + sis5595_initialized--; + } + if (sis5595_initialized >= 1) { + release_region(sis5595_base + SMB_INDEX, 2); + sis5595_initialized--; + } + return 0; } EXPORT_NO_SYMBOLS; @@ -400,13 +430,12 @@ MODULE_DESCRIPTION("SIS5595 SMBus driver"); int init_module(void) { - return i2c_sis5595_init(); + return i2c_sis5595_init(); } int cleanup_module(void) { - return sis5595_cleanup(); + return sis5595_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/busses/i2c-via.c b/kernel/busses/i2c-via.c index b598cc11..a55066c2 100644 --- a/kernel/busses/i2c-via.c +++ b/kernel/busses/i2c-via.c @@ -40,14 +40,14 @@ /* Power management registers */ -#define PM_CFG_REVID 0x08 /* silicon revision code */ +#define PM_CFG_REVID 0x08 /* silicon revision code */ #define PM_CFG_IOBASE0 0x20 #define PM_CFG_IOBASE1 0x48 #define I2C_DIR (pm_io_base+0x40) #define I2C_OUT (pm_io_base+0x42) #define I2C_IN (pm_io_base+0x44) -#define I2C_SCL 0x02 /* clock bit in DIR/OUT/IN register */ +#define I2C_SCL 0x02 /* clock bit in DIR/OUT/IN register */ #define I2C_SDA 0x04 /* io-region reservation */ @@ -55,9 +55,9 @@ #define IOTEXT "via-i2c" /* ----- global defines ----------------------------------------------- */ -#define DEB(x) x /* silicon revision, io addresses */ -#define DEB2(x) x /* line status */ -#define DEBE(x) /* */ +#define DEB(x) x /* silicon revision, io addresses */ +#define DEB2(x) x /* line status */ +#define DEBE(x) /* */ /* ----- local functions ---------------------------------------------- */ @@ -65,22 +65,24 @@ static u16 pm_io_base; static void bit_via_setscl(void *data, int state) { - outb(state ? inb(I2C_OUT)|I2C_SCL : inb(I2C_OUT)&~I2C_SCL, I2C_OUT); + outb(state ? inb(I2C_OUT) | I2C_SCL : inb(I2C_OUT) & ~I2C_SCL, + I2C_OUT); } static void bit_via_setsda(void *data, int state) { - outb(state ? inb(I2C_OUT)|I2C_SDA : inb(I2C_OUT)&~I2C_SDA, I2C_OUT); + outb(state ? inb(I2C_OUT) | I2C_SDA : inb(I2C_OUT) & ~I2C_SDA, + I2C_OUT); } static int bit_via_getscl(void *data) { - return (0 != (inb(I2C_IN) & I2C_SCL) ); + return (0 != (inb(I2C_IN) & I2C_SCL)); } static int bit_via_getsda(void *data) { - return (0 != (inb(I2C_IN) & I2C_SDA) ); + return (0 != (inb(I2C_IN) & I2C_SDA)); } static void bit_via_inc(struct i2c_adapter *adapter) @@ -101,7 +103,7 @@ static struct i2c_algo_bit_data bit_data = { bit_via_setscl, bit_via_getsda, bit_via_getscl, - 5, 5, 100, /*waits, timeout */ + 5, 5, 100, /*waits, timeout */ }; static struct i2c_adapter bit_via_ops = { @@ -122,38 +124,40 @@ static int find_via(void) struct pci_dev *s_bridge; u16 base; u8 rev; - - if (! pci_present()) + + if (!pci_present()) return -ENODEV; - + s_bridge = pci_find_device(VENDOR, DEVICE, NULL); - - if (! s_bridge) { + + if (!s_bridge) { printk("vt82c586b not found\n"); return -ENODEV; } - if ( PCIBIOS_SUCCESSFUL != - pci_read_config_byte(s_bridge, PM_CFG_REVID, &rev)) + if (PCIBIOS_SUCCESSFUL != + pci_read_config_byte(s_bridge, PM_CFG_REVID, &rev)) return -ENODEV; - switch(rev) - { - case 0x00: base = PM_CFG_IOBASE0; - break; - case 0x01: - case 0x10: base = PM_CFG_IOBASE1; - break; - - default : base = PM_CFG_IOBASE1; - /* later revision */ - } + switch (rev) { + case 0x00: + base = PM_CFG_IOBASE0; + break; + case 0x01: + case 0x10: + base = PM_CFG_IOBASE1; + break; - if ( PCIBIOS_SUCCESSFUL != - pci_read_config_word(s_bridge, base, &pm_io_base)) - return -ENODEV; - - pm_io_base &= (0xff<<8); + default: + base = PM_CFG_IOBASE1; + /* later revision */ + } + + if (PCIBIOS_SUCCESSFUL != + pci_read_config_word(s_bridge, base, &pm_io_base)) + return -ENODEV; + + pm_io_base &= (0xff << 8); return 0; } @@ -162,30 +166,31 @@ static #else extern #endif - int __init i2c_via_init(void) +int __init i2c_via_init(void) { if (find_via() < 0) { printk("Error while reading PCI configuration\n"); return -ENODEV; } - if ( check_region(I2C_DIR, IOSPACE) < 0) { + if (check_region(I2C_DIR, IOSPACE) < 0) { printk("IO 0x%x-0x%x already in use\n", - I2C_DIR, I2C_DIR+IOSPACE); + I2C_DIR, I2C_DIR + IOSPACE); return -EBUSY; } else { request_region(I2C_DIR, IOSPACE, IOTEXT); outb(inb(I2C_DIR) | I2C_SDA | I2C_SCL, I2C_DIR); - outb(inb(I2C_OUT) | I2C_SDA | I2C_SCL, I2C_OUT); + outb(inb(I2C_OUT) | I2C_SDA | I2C_SCL, I2C_OUT); } - + if (i2c_bit_add_bus(&bit_via_ops) == 0) { printk("i2c-via.o: Module succesfully loaded\n"); return 0; } else { - outb(inb(I2C_DIR)&~(I2C_SDA|I2C_SCL), I2C_DIR); + outb(inb(I2C_DIR) & ~(I2C_SDA | I2C_SCL), I2C_DIR); release_region(I2C_DIR, IOSPACE); - printk("i2c-via.o: Algo-bit error, couldn't register bus\n"); + printk + ("i2c-via.o: Algo-bit error, couldn't register bus\n"); return -ENODEV; } } @@ -196,12 +201,12 @@ EXPORT_NO_SYMBOLS; MODULE_AUTHOR("Kyösti Mälkki "); MODULE_DESCRIPTION("i2c for Via vt82c586b southbridge"); -int init_module(void) +int init_module(void) { return i2c_via_init(); } -void cleanup_module(void) +void cleanup_module(void) { i2c_bit_del_bus(&bit_via_ops); release_region(I2C_DIR, IOSPACE); diff --git a/kernel/busses/i2c-viapro.c b/kernel/busses/i2c-viapro.c index 58d21e7d..07df55a3 100644 --- a/kernel/busses/i2c-viapro.c +++ b/kernel/busses/i2c-viapro.c @@ -88,28 +88,29 @@ static unsigned short smb_cf_hstcfg; /* If force is set to anything different from 0, we forcibly enable the VT596. DANGEROUS! */ static int force = 0; -MODULE_PARM(force,"i"); -MODULE_PARM_DESC(force,"Forcibly enable the VT82C596 SMBus. DANGEROUS!"); +MODULE_PARM(force, "i"); +MODULE_PARM_DESC(force, "Forcibly enable the VT82C596 SMBus. DANGEROUS!"); /* If force_addr is set to anything different from 0, we forcibly enable the VT596 at the given address. VERY DANGEROUS! */ static int force_addr = 0; -MODULE_PARM(force_addr,"i"); -MODULE_PARM_DESC(force_addr,"Forcibly enable the VT82C596 SMBus at the given address. " - "EXTREMELY DANGEROUS!"); +MODULE_PARM(force_addr, "i"); +MODULE_PARM_DESC(force_addr, + "Forcibly enable the VT82C596 SMBus at the given address. " + "EXTREMELY DANGEROUS!"); #ifdef MODULE static #else extern #endif - int __init i2c_vt596_init(void); +int __init i2c_vt596_init(void); static int __init vt596_cleanup(void); static int vt596_setup(void); -static s32 vt596_access(struct i2c_adapter *adap, u16 addr, - unsigned short flags,char read_write, - u8 command, int size, union i2c_smbus_data * data); -static void vt596_do_pause( unsigned int amount ); +static s32 vt596_access(struct i2c_adapter *adap, u16 addr, + unsigned short flags, char read_write, + u8 command, int size, union i2c_smbus_data *data); +static void vt596_do_pause(unsigned int amount); static int vt596_transaction(void); static void vt596_inc(struct i2c_adapter *adapter); static void vt596_dec(struct i2c_adapter *adapter); @@ -118,28 +119,28 @@ static u32 vt596_func(struct i2c_adapter *adapter); #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ static struct i2c_algorithm smbus_algorithm = { - /* name */ "Non-I2C SMBus adapter", - /* id */ I2C_ALGO_SMBUS, - /* master_xfer */ NULL, - /* smbus_access */ vt596_access, - /* slave_send */ NULL, - /* slave_rcv */ NULL, - /* algo_control */ NULL, - /* functionality */ vt596_func, + /* name */ "Non-I2C SMBus adapter", + /* id */ I2C_ALGO_SMBUS, + /* master_xfer */ NULL, + /* smbus_access */ vt596_access, + /* slave_send */ NULL, + /* slave_rcv */ NULL, + /* algo_control */ NULL, + /* functionality */ vt596_func, }; static struct i2c_adapter vt596_adapter = { - "unset", - I2C_ALGO_SMBUS | I2C_HW_SMBUS_VIA2, - &smbus_algorithm, - NULL, - vt596_inc, - vt596_dec, - NULL, - NULL, + "unset", + I2C_ALGO_SMBUS | I2C_HW_SMBUS_VIA2, + &smbus_algorithm, + NULL, + vt596_inc, + vt596_dec, + NULL, + NULL, }; static int __initdata vt596_initialized; @@ -152,286 +153,308 @@ static unsigned short vt596_smba = 0; defined to make the transition easier. */ int vt596_setup(void) { - int error_return=0; - unsigned char temp; + int error_return = 0; + unsigned char temp; - struct pci_dev *VT596_dev; + struct pci_dev *VT596_dev; - /* First check whether we can access PCI at all */ - if (pci_present() == 0) { - printk("i2c-viapro.o: Error: No PCI-bus found!\n"); - error_return=-ENODEV; - goto END; - } + /* First check whether we can access PCI at all */ + if (pci_present() == 0) { + printk("i2c-viapro.o: Error: No PCI-bus found!\n"); + error_return = -ENODEV; + goto END; + } - /* Look for the VT596 function 3 _or_ VT686 function 4 */ - VT596_dev = NULL; - VT596_dev = pci_find_device(PCI_VENDOR_ID_VIA, - PCI_DEVICE_ID_VIA_82C596_3, VT596_dev); - if (VT596_dev == NULL) - VT596_dev = pci_find_device(PCI_VENDOR_ID_VIA, - PCI_DEVICE_ID_VIA_82C686_4, VT596_dev); + /* Look for the VT596 function 3 _or_ VT686 function 4 */ + VT596_dev = NULL; + VT596_dev = pci_find_device(PCI_VENDOR_ID_VIA, + PCI_DEVICE_ID_VIA_82C596_3, VT596_dev); + if (VT596_dev == NULL) + VT596_dev = pci_find_device(PCI_VENDOR_ID_VIA, + PCI_DEVICE_ID_VIA_82C686_4, + VT596_dev); - if (VT596_dev == NULL) { - printk("i2c-viapro.o: Error: Can't detect vt82c596 or vt82c686"); - error_return=-ENODEV; - goto END; - } + if (VT596_dev == NULL) { + printk + ("i2c-viapro.o: Error: Can't detect vt82c596 or vt82c686"); + error_return = -ENODEV; + goto END; + } /* Determine the configuration space registers for the SMBus areas */ - if ((! pci_read_config_word(VT596_dev, SMBBA1, &vt596_smba)) && (vt596_smba & 0x1)) { - smb_cf_base = SMBBA1; - smb_cf_hstcfg = 0xD2; - } else if ((! pci_read_config_word(VT596_dev, SMBBA2, &vt596_smba)) && (vt596_smba & 0x1)) { - smb_cf_base = SMBBA2; - smb_cf_hstcfg = 0x84; - } else { - printk("i2c-viapro.o: Cannot configure SMBus I/O Base address\n"); - error_return=-ENODEV; - goto END; - } + if ((!pci_read_config_word(VT596_dev, SMBBA1, &vt596_smba)) + && (vt596_smba & 0x1)) { + smb_cf_base = SMBBA1; + smb_cf_hstcfg = 0xD2; + } else if ((!pci_read_config_word(VT596_dev, SMBBA2, &vt596_smba)) + && (vt596_smba & 0x1)) { + smb_cf_base = SMBBA2; + smb_cf_hstcfg = 0x84; + } else { + printk + ("i2c-viapro.o: Cannot configure SMBus I/O Base address\n"); + error_return = -ENODEV; + goto END; + } /* Determine the address of the SMBus areas */ - if (force_addr) { - vt596_smba = force_addr & 0xfff0; - force = 0; - } else { - vt596_smba &= 0xfff0; - } + if (force_addr) { + vt596_smba = force_addr & 0xfff0; + force = 0; + } else { + vt596_smba &= 0xfff0; + } - if (check_region(vt596_smba, 8)) { - printk("i2c-viapro.o: vt82c596_smb region 0x%x already in use!\n", vt596_smba); - error_return=-ENODEV; - goto END; - } + if (check_region(vt596_smba, 8)) { + printk + ("i2c-viapro.o: vt82c596_smb region 0x%x already in use!\n", + vt596_smba); + error_return = -ENODEV; + goto END; + } - pci_read_config_byte(VT596_dev, SMBHSTCFG, &temp); + pci_read_config_byte(VT596_dev, SMBHSTCFG, &temp); /* If force_addr is set, we program the new address here. Just to make sure, we disable the VT596 first. */ - if (force_addr) { - pci_write_config_byte(VT596_dev, SMBHSTCFG, temp & 0xfe); - pci_write_config_word(VT596_dev, SMBBA,vt596_smba); - pci_write_config_byte(VT596_dev, SMBHSTCFG, temp | 0x01); - printk("i2c-viapro.o: WARNING: VT596 SMBus interface set to new " - "address %04x!\n",vt596_smba); - } else if ((temp & 1) == 0) { - if (force) { + if (force_addr) { + pci_write_config_byte(VT596_dev, SMBHSTCFG, temp & 0xfe); + pci_write_config_word(VT596_dev, SMBBA, vt596_smba); + pci_write_config_byte(VT596_dev, SMBHSTCFG, temp | 0x01); + printk + ("i2c-viapro.o: WARNING: VT596 SMBus interface set to new " + "address %04x!\n", vt596_smba); + } else if ((temp & 1) == 0) { + if (force) { /* NOTE: This assumes I/O space and other allocations WERE done by the Bios! Don't complain if your hardware does weird things after enabling this. :') Check for Bios updates before resorting to this. */ - pci_write_config_byte(VT596_dev, SMBHSTCFG, temp | 1); - printk("i2c-viapro.o: WARNING: SMBus interface has been FORCEFULLY " - "ENABLED!\n"); - } else { - printk("SMBUS: Error: Host SMBus controller not enabled!\n"); - error_return=-ENODEV; - goto END; - } - } + pci_write_config_byte(VT596_dev, SMBHSTCFG, + temp | 1); + printk + ("i2c-viapro.o: WARNING: SMBus interface has been FORCEFULLY " + "ENABLED!\n"); + } else { + printk + ("SMBUS: Error: Host SMBus controller not enabled!\n"); + error_return = -ENODEV; + goto END; + } + } - /* Everything is happy, let's grab the memory and set things up. */ - request_region(vt596_smba, 8, "via2-smbus"); + /* Everything is happy, let's grab the memory and set things up. */ + request_region(vt596_smba, 8, "via2-smbus"); #ifdef DEBUG - if ((temp & 0x0E) == 8) - printk("i2c-viapro.o: using Interrupt 9 for SMBus.\n"); - else if ((temp & 0x0E) == 0) - printk("i2c-viapro.o: using Interrupt SMI# for SMBus.\n"); - else - printk("i2c-viapro.o: Illegal Interrupt configuration (or code out " - "of date)!\n"); + if ((temp & 0x0E) == 8) + printk("i2c-viapro.o: using Interrupt 9 for SMBus.\n"); + else if ((temp & 0x0E) == 0) + printk("i2c-viapro.o: using Interrupt SMI# for SMBus.\n"); + else + printk + ("i2c-viapro.o: Illegal Interrupt configuration (or code out " + "of date)!\n"); - pci_read_config_byte(VT596_dev, SMBREV, &temp); - printk("i2c-viapro.o: SMBREV = 0x%X\n",temp); - printk("i2c-viapro.o: VT596_smba = 0x%X\n",vt596_smba); -#endif /* DEBUG */ + pci_read_config_byte(VT596_dev, SMBREV, &temp); + printk("i2c-viapro.o: SMBREV = 0x%X\n", temp); + printk("i2c-viapro.o: VT596_smba = 0x%X\n", vt596_smba); +#endif /* DEBUG */ -END: - return error_return; + END: + return error_return; } /* Internally used pause function */ -void vt596_do_pause( unsigned int amount ) +void vt596_do_pause(unsigned int amount) { - current->state = TASK_INTERRUPTIBLE; - schedule_timeout(amount); + current->state = TASK_INTERRUPTIBLE; + schedule_timeout(amount); } /* Another internally used function */ -int vt596_transaction(void) +int vt596_transaction(void) { - int temp; - int result=0; - int timeout=0; + int temp; + int result = 0; + int timeout = 0; #ifdef DEBUG - printk("i2c-viapro.o: Transaction (pre): CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, " - "DAT1=%02x\n", - inb_p(SMBHSTCNT),inb_p(SMBHSTCMD),inb_p(SMBHSTADD),inb_p(SMBHSTDAT0), - inb_p(SMBHSTDAT1)); + printk + ("i2c-viapro.o: Transaction (pre): CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, " + "DAT1=%02x\n", inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), + inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1)); #endif - /* Make sure the SMBus host is ready to start transmitting */ - if ((temp = inb_p(SMBHSTSTS)) != 0x00) { + /* Make sure the SMBus host is ready to start transmitting */ + if ((temp = inb_p(SMBHSTSTS)) != 0x00) { #ifdef DEBUG - printk("i2c-viapro.o: SMBus busy (%02x). Resetting... \n",temp); + printk("i2c-viapro.o: SMBus busy (%02x). Resetting... \n", + temp); #endif - outb_p(temp, SMBHSTSTS); - if ((temp = inb_p(SMBHSTSTS)) != 0x00) { + outb_p(temp, SMBHSTSTS); + if ((temp = inb_p(SMBHSTSTS)) != 0x00) { #ifdef DEBUG - printk("i2c-viapro.o: Failed! (%02x)\n",temp); + printk("i2c-viapro.o: Failed! (%02x)\n", temp); #endif - return -1; - } else { + return -1; + } else { #ifdef DEBUG - printk("i2c-viapro.o: Successfull!\n"); + printk("i2c-viapro.o: Successfull!\n"); #endif - } - } + } + } - /* start the transaction by setting bit 6 */ - outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); + /* start the transaction by setting bit 6 */ + outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); - /* We will always wait for a fraction of a second! - I don't know if VIA needs this, Intel did */ - do { - vt596_do_pause(1); - temp=inb_p(SMBHSTSTS); - } while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT)); + /* We will always wait for a fraction of a second! + I don't know if VIA needs this, Intel did */ + do { + vt596_do_pause(1); + temp = inb_p(SMBHSTSTS); + } while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT)); - /* If the SMBus is still busy, we give up */ - if (timeout >= MAX_TIMEOUT) { + /* If the SMBus is still busy, we give up */ + if (timeout >= MAX_TIMEOUT) { #ifdef DEBUG - printk("i2c-viapro.o: SMBus Timeout!\n"); - result = -1; + printk("i2c-viapro.o: SMBus Timeout!\n"); + result = -1; #endif - } + } - if (temp & 0x10) { - result = -1; + if (temp & 0x10) { + result = -1; #ifdef DEBUG - printk("i2c-viapro.o: Error: Failed bus transaction\n"); + printk("i2c-viapro.o: Error: Failed bus transaction\n"); #endif - } + } - if (temp & 0x08) { - result = -1; - printk("i2c-viapro.o: Bus collision! SMBus may be locked until next hard - reset. (sorry!)\n"); - /* Clock stops and slave is stuck in mid-transmission */ - } + if (temp & 0x08) { + result = -1; + printk + ("i2c-viapro.o: Bus collision! SMBus may be locked until next hard\n" + "reset. (sorry!)\n"); + /* Clock stops and slave is stuck in mid-transmission */ + } - if (temp & 0x04) { - result = -1; + if (temp & 0x04) { + result = -1; #ifdef DEBUG - printk("i2c-viapro.o: Error: no response!\n"); + printk("i2c-viapro.o: Error: no response!\n"); #endif - } + } - if (inb_p(SMBHSTSTS) != 0x00) - outb_p( inb(SMBHSTSTS), SMBHSTSTS); + if (inb_p(SMBHSTSTS) != 0x00) + outb_p(inb(SMBHSTSTS), SMBHSTSTS); - if ((temp = inb_p(SMBHSTSTS)) != 0x00) { + if ((temp = inb_p(SMBHSTSTS)) != 0x00) { #ifdef DEBUG - printk("i2c-viapro.o: Failed reset at end of transaction (%02x)\n",temp); + printk + ("i2c-viapro.o: Failed reset at end of transaction (%02x)\n", + temp); #endif - } + } #ifdef DEBUG - printk("i2c-viapro.o: Transaction (post): CNT=%02x, CMD=%02x, ADD=%02x, " - "DAT0=%02x, DAT1=%02x\n", - inb_p(SMBHSTCNT),inb_p(SMBHSTCMD),inb_p(SMBHSTADD),inb_p(SMBHSTDAT0), - inb_p(SMBHSTDAT1)); + printk + ("i2c-viapro.o: Transaction (post): CNT=%02x, CMD=%02x, ADD=%02x, " + "DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), + inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1)); #endif - return result; + return result; } /* Return -1 on error. See smbus.h for more information */ -s32 vt596_access(struct i2c_adapter *adap, u16 addr, unsigned short flags, - char read_write, - u8 command, int size, union i2c_smbus_data * data) +s32 vt596_access(struct i2c_adapter * adap, u16 addr, unsigned short flags, + char read_write, + u8 command, int size, union i2c_smbus_data * data) { - int i,len; + int i, len; - switch(size) { - case I2C_SMBUS_PROC_CALL: - printk("i2c-viapro.o: I2C_SMBUS_PROC_CALL not supported!\n"); - return -1; - case I2C_SMBUS_QUICK: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - size = VT596_QUICK; - break; - case I2C_SMBUS_BYTE: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - if (read_write == I2C_SMBUS_WRITE) - outb_p(command, SMBHSTCMD); - size = VT596_BYTE; - break; - case I2C_SMBUS_BYTE_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - outb_p(command, SMBHSTCMD); - if (read_write == I2C_SMBUS_WRITE) - outb_p(data->byte,SMBHSTDAT0); - size = VT596_BYTE_DATA; - break; - case I2C_SMBUS_WORD_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - outb_p(command, SMBHSTCMD); - if (read_write == I2C_SMBUS_WRITE) { - outb_p(data->word & 0xff,SMBHSTDAT0); - outb_p((data->word & 0xff00) >> 8,SMBHSTDAT1); - } - size = VT596_WORD_DATA; - break; - case I2C_SMBUS_BLOCK_DATA: - outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), SMBHSTADD); - outb_p(command, SMBHSTCMD); - if (read_write == I2C_SMBUS_WRITE) { - len = data->block[0]; - if (len < 0) - len = 0; - if (len > 32) - len = 32; - outb_p(len,SMBHSTDAT0); - i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ - for (i = 1; i <= len; i ++) - outb_p(data->block[i],SMBBLKDAT); - } - size = VT596_BLOCK_DATA; - break; - } + switch (size) { + case I2C_SMBUS_PROC_CALL: + printk + ("i2c-viapro.o: I2C_SMBUS_PROC_CALL not supported!\n"); + return -1; + case I2C_SMBUS_QUICK: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + size = VT596_QUICK; + break; + case I2C_SMBUS_BYTE: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + if (read_write == I2C_SMBUS_WRITE) + outb_p(command, SMBHSTCMD); + size = VT596_BYTE; + break; + case I2C_SMBUS_BYTE_DATA: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + outb_p(command, SMBHSTCMD); + if (read_write == I2C_SMBUS_WRITE) + outb_p(data->byte, SMBHSTDAT0); + size = VT596_BYTE_DATA; + break; + case I2C_SMBUS_WORD_DATA: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + outb_p(command, SMBHSTCMD); + if (read_write == I2C_SMBUS_WRITE) { + outb_p(data->word & 0xff, SMBHSTDAT0); + outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1); + } + size = VT596_WORD_DATA; + break; + case I2C_SMBUS_BLOCK_DATA: + outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), + SMBHSTADD); + outb_p(command, SMBHSTCMD); + if (read_write == I2C_SMBUS_WRITE) { + len = data->block[0]; + if (len < 0) + len = 0; + if (len > 32) + len = 32; + outb_p(len, SMBHSTDAT0); + i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ + for (i = 1; i <= len; i++) + outb_p(data->block[i], SMBBLKDAT); + } + size = VT596_BLOCK_DATA; + break; + } - outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); + outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); - if (vt596_transaction()) /* Error in transaction */ - return -1; - - if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK)) - return 0; - + if (vt596_transaction()) /* Error in transaction */ + return -1; - switch(size) { - case VT596_BYTE: /* Where is the result put? I assume here it is in - SMBHSTDAT0 but it might just as well be in the - SMBHSTCMD. No clue in the docs */ - - data->byte = inb_p(SMBHSTDAT0); - break; - case VT596_BYTE_DATA: - data->byte = inb_p(SMBHSTDAT0); - break; - case VT596_WORD_DATA: - data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); - break; - case VT596_BLOCK_DATA: - data->block[0] = inb_p(SMBHSTDAT0); - i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ - for (i = 1; i <= data->block[0]; i++) - data->block[i] = inb_p(SMBBLKDAT); - break; - } - return 0; + if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK)) + return 0; + + + switch (size) { + case VT596_BYTE: /* Where is the result put? I assume here it is in + SMBHSTDAT0 but it might just as well be in the + SMBHSTCMD. No clue in the docs */ + + data->byte = inb_p(SMBHSTDAT0); + break; + case VT596_BYTE_DATA: + data->byte = inb_p(SMBHSTDAT0); + break; + case VT596_WORD_DATA: + data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); + break; + case VT596_BLOCK_DATA: + data->block[0] = inb_p(SMBHSTDAT0); + i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ + for (i = 1; i <= data->block[0]; i++) + data->block[i] = inb_p(SMBBLKDAT); + break; + } + return 0; } void vt596_inc(struct i2c_adapter *adapter) @@ -448,74 +471,78 @@ void vt596_dec(struct i2c_adapter *adapter) u32 vt596_func(struct i2c_adapter *adapter) { return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | - I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | - I2C_FUNC_SMBUS_BLOCK_DATA; + I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | + I2C_FUNC_SMBUS_BLOCK_DATA; } int __init i2c_vt596_init(void) { - int res; - printk("via2.o version %s (%s)\n",LM_VERSION,LM_DATE); + int res; + printk("via2.o version %s (%s)\n", LM_VERSION, LM_DATE); #ifdef DEBUG /* PE- It might be good to make this a permanent part of the code! */ - if (vt596_initialized) { - printk("i2c-viapro.o: Oops, vt596_init called a second time!\n"); - return -EBUSY; - } + if (vt596_initialized) { + printk + ("i2c-viapro.o: Oops, vt596_init called a second time!\n"); + return -EBUSY; + } #endif - vt596_initialized = 0; - if ((res = vt596_setup())) { - printk("i2c-viapro.o: vt82c596 not detected, module not inserted.\n"); - vt596_cleanup(); - return res; - } - vt596_initialized ++; - sprintf(vt596_adapter.name,"SMBus vt82c596 adapter at %04x",vt596_smba); - if ((res = i2c_add_adapter(&vt596_adapter))) { - printk("i2c-viapro.o: Adapter registration failed, module not inserted.\n"); - vt596_cleanup(); - return res; - } - vt596_initialized++; - printk("i2c-viapro.o: vt82c596 bus detected and initialized\n"); - return 0; + vt596_initialized = 0; + if ((res = vt596_setup())) { + printk + ("i2c-viapro.o: vt82c596 not detected, module not inserted.\n"); + vt596_cleanup(); + return res; + } + vt596_initialized++; + sprintf(vt596_adapter.name, "SMBus vt82c596 adapter at %04x", + vt596_smba); + if ((res = i2c_add_adapter(&vt596_adapter))) { + printk + ("i2c-viapro.o: Adapter registration failed, module not inserted.\n"); + vt596_cleanup(); + return res; + } + vt596_initialized++; + printk("i2c-viapro.o: vt82c596 bus detected and initialized\n"); + return 0; } int __init vt596_cleanup(void) { - int res; - if (vt596_initialized >= 2) - { - if ((res = i2c_del_adapter(&vt596_adapter))) { - printk("i2c-viapro.o: i2c_del_adapter failed, module not removed\n"); - return res; - } else - vt596_initialized--; - } - if (vt596_initialized >= 1) { - release_region(vt596_smba, 8); - vt596_initialized--; - } - return 0; + int res; + if (vt596_initialized >= 2) { + if ((res = i2c_del_adapter(&vt596_adapter))) { + printk + ("i2c-viapro.o: i2c_del_adapter failed, module not removed\n"); + return res; + } else + vt596_initialized--; + } + if (vt596_initialized >= 1) { + release_region(vt596_smba, 8); + vt596_initialized--; + } + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard and Philip Edelbrock "); +MODULE_AUTHOR + ("Frodo Looijaard and Philip Edelbrock "); MODULE_DESCRIPTION("vt82c596 SMBus driver"); int init_module(void) { - return i2c_vt596_init(); + return i2c_vt596_init(); } int cleanup_module(void) { - return vt596_cleanup(); + return vt596_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/busses/i2c-voodoo3.c b/kernel/busses/i2c-voodoo3.c index e347a987..b04d1d2b 100644 --- a/kernel/busses/i2c-voodoo3.c +++ b/kernel/busses/i2c-voodoo3.c @@ -53,12 +53,13 @@ static #else extern #endif - int __init i2c_voodoo3_init(void); +int __init i2c_voodoo3_init(void); static int __init voodoo3_cleanup(void); static int voodoo3_setup(void); -static s32 voodoo3_access(struct i2c_adapter *adap, u16 addr, - unsigned short flags, char read_write, - u8 command, int size, union i2c_smbus_data * data); +static s32 voodoo3_access(struct i2c_adapter *adap, u16 addr, + unsigned short flags, char read_write, + u8 command, int size, + union i2c_smbus_data *data); static void Voodoo3_I2CStart(void); static void Voodoo3_I2CStop(void); static int Voodoo3_I2CAck(int ackit); @@ -66,14 +67,15 @@ static int Voodoo3_I2CReadByte(int ackit); static int Voodoo3_I2CSendByte(unsigned char data); static int Voodoo3_BusCheck(void); static int Voodoo3_I2CRead_byte(int addr); -static int Voodoo3_I2CRead_byte_data(int addr,int command); -static int Voodoo3_I2CRead_word(int addr,int command); -static int Voodoo3_I2CWrite_byte(int addr,int command); -static int Voodoo3_I2CWrite_byte_data(int addr,int command,int data); -static int Voodoo3_I2CWrite_word(int addr,int command,long data); -static s32 voodoo3_ddc_access(struct i2c_adapter *adap, u16 addr, - unsigned short flags, char read_write, - u8 command, int size, union i2c_smbus_data * data); +static int Voodoo3_I2CRead_byte_data(int addr, int command); +static int Voodoo3_I2CRead_word(int addr, int command); +static int Voodoo3_I2CWrite_byte(int addr, int command); +static int Voodoo3_I2CWrite_byte_data(int addr, int command, int data); +static int Voodoo3_I2CWrite_word(int addr, int command, long data); +static s32 voodoo3_ddc_access(struct i2c_adapter *adap, u16 addr, + unsigned short flags, char read_write, + u8 command, int size, + union i2c_smbus_data *data); static void Voodoo3_DDCStart(void); static void Voodoo3_DDCStop(void); static int Voodoo3_DDCAck(int ackit); @@ -81,11 +83,11 @@ static int Voodoo3_DDCReadByte(int ackit); static int Voodoo3_DDCSendByte(unsigned char data); static int Voodoo3_DDCBusCheck(void); static int Voodoo3_DDCRead_byte(int addr); -static int Voodoo3_DDCRead_byte_data(int addr,int command); -static int Voodoo3_DDCRead_word(int addr,int command); -static int Voodoo3_DDCWrite_byte(int addr,int command); -static int Voodoo3_DDCWrite_byte_data(int addr,int command,int data); -static int Voodoo3_DDCWrite_word(int addr,int command,long data); +static int Voodoo3_DDCRead_byte_data(int addr, int command); +static int Voodoo3_DDCRead_word(int addr, int command); +static int Voodoo3_DDCWrite_byte(int addr, int command); +static int Voodoo3_DDCWrite_byte_data(int addr, int command, int data); +static int Voodoo3_DDCWrite_word(int addr, int command, long data); static void config_v3(struct pci_dev *dev); static void voodoo3_inc(struct i2c_adapter *adapter); static void voodoo3_dec(struct i2c_adapter *adapter); @@ -94,466 +96,524 @@ static u32 voodoo3_func(struct i2c_adapter *adapter); #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ static struct i2c_algorithm smbus_algorithm = { - /* name */ "Non-I2C SMBus adapter", - /* id */ I2C_ALGO_SMBUS, - /* master_xfer */ NULL, - /* smbus_access */ &voodoo3_access, - /* slave_send */ NULL, - /* slave_rcv */ NULL, - /* algo_control */ NULL, - /* functionality */ voodoo3_func, + /* name */ "Non-I2C SMBus adapter", + /* id */ I2C_ALGO_SMBUS, + /* master_xfer */ NULL, + /* smbus_access */ &voodoo3_access, + /* slave_send */ NULL, + /* slave_rcv */ NULL, + /* algo_control */ NULL, + /* functionality */ voodoo3_func, }; static struct i2c_adapter voodoo3_i2c_adapter = { - "unset", - I2C_ALGO_SMBUS | I2C_HW_SMBUS_VOODOO3, - &smbus_algorithm, - NULL, - voodoo3_inc, - voodoo3_dec, - NULL, - NULL, + "unset", + I2C_ALGO_SMBUS | I2C_HW_SMBUS_VOODOO3, + &smbus_algorithm, + NULL, + voodoo3_inc, + voodoo3_dec, + NULL, + NULL, }; static struct i2c_algorithm ddc_algorithm = { - /* name */ "DDC I2C adapter", - /* id */ I2C_ALGO_SMBUS, - /* master_xfer */ NULL, - /* smbus_access */ &voodoo3_ddc_access, - /* slave_send */ NULL, - /* slave_rcv */ NULL, - /* algo_control */ NULL, - /* functionality */ voodoo3_func, + /* name */ "DDC I2C adapter", + /* id */ I2C_ALGO_SMBUS, + /* master_xfer */ NULL, + /* smbus_access */ &voodoo3_ddc_access, + /* slave_send */ NULL, + /* slave_rcv */ NULL, + /* algo_control */ NULL, + /* functionality */ voodoo3_func, }; static struct i2c_adapter voodoo3_ddc_adapter = { - "unset", - I2C_ALGO_SMBUS | I2C_HW_SMBUS_VOODOO3, - &ddc_algorithm, - NULL, - voodoo3_inc, - voodoo3_dec, - NULL, - NULL, + "unset", + I2C_ALGO_SMBUS | I2C_HW_SMBUS_VOODOO3, + &ddc_algorithm, + NULL, + voodoo3_inc, + voodoo3_dec, + NULL, + NULL, }; static int __initdata voodoo3_initialized; static unsigned short voodoo3_smba = 0; -static unsigned int state=0xcffc0020; +static unsigned int state = 0xcffc0020; static unsigned char *mem; static int v3_num; -extern inline void outlong(int off,unsigned int dat) +extern inline void outlong(int off, unsigned int dat) { - *((unsigned int*)(mem+off))=dat; + *((unsigned int *) (mem + off)) = dat; } extern inline unsigned int readlong(int off) { - return *((unsigned int*)(mem+off)); + return *((unsigned int *) (mem + off)); } extern inline void out(void) { - outlong(0x78,state); - udelay(10); + outlong(0x78, state); + udelay(10); } /* For I2C BUS */ extern inline void dat(int data) { - state&=~(1<<25); - if (data) - state|=(1<<25); + state &= ~(1 << 25); + if (data) + state |= (1 << 25); } extern inline void clkon(void) { - state|=(1<<24); + state |= (1 << 24); } extern inline void clkoff(void) { - state&=~(1<<24); + state &= ~(1 << 24); } extern inline int rdat(void) { - dat(1); - out(); - return((readlong(0x78)&(1<<27) )!=0 ); + dat(1); + out(); + return ((readlong(0x78) & (1 << 27)) != 0); } /* For DDC BUS */ extern inline void ddc_dat(int data) { - state&=~(1<<20); - if (data) - state|=(1<<20); + state &= ~(1 << 20); + if (data) + state |= (1 << 20); } extern inline void ddc_clkon(void) { - state|=(1<<19); + state |= (1 << 19); } extern inline void ddc_clkoff(void) { - state&=~(1<<19); + state &= ~(1 << 19); } extern inline int ddc_rdat(void) { - ddc_dat(1); - out(); - return((readlong(0x78)&(1<<22) )!=0 ); + ddc_dat(1); + out(); + return ((readlong(0x78) & (1 << 22)) != 0); } /* For I2C BUS */ /* Changing the Data line while clock is 'on' (high) is a no-no, except for a start or stop. */ - + void Voodoo3_I2CStart(void) { - clkon(); /* in theory, clk is already on */ - out(); - out(); - out(); - out(); - dat(0); - out(); - clkoff(); - out(); + clkon(); /* in theory, clk is already on */ + out(); + out(); + out(); + out(); + dat(0); + out(); + clkoff(); + out(); } void Voodoo3_I2CStop(void) { - dat(0); - out(); - clkon(); - out(); - dat(1); - out(); - clkoff(); - out(); - out(); - clkon(); - out(); + dat(0); + out(); + clkon(); + out(); + dat(1); + out(); + clkoff(); + out(); + out(); + clkon(); + out(); } int Voodoo3_I2CAck(int ackit) { -int ack=0; + int ack = 0; - out(); - clkon(); - if (!ackit) { - ack=rdat(); - } else { dat(0); } - out(); - clkoff(); - out(); - return ack; + out(); + clkon(); + if (!ackit) { + ack = rdat(); + } else { + dat(0); + } + out(); + clkoff(); + out(); + return ack; } int Voodoo3_I2CReadByte(int ackit) { - int i,temp; - unsigned char data=0; + int i, temp; + unsigned char data = 0; - for (i=7; i>=0; i--) { - out(); - clkon(); - data|=(rdat()<= 0; i--) { + out(); + clkon(); + data |= (rdat() << i); + out(); + clkoff(); + out(); + } + temp = Voodoo3_I2CAck(ackit); #ifdef DEBUG - printk("i2c-voodoo3: Readbyte ack -->0x%X, read result -->0x%X\n",temp,data); + printk("i2c-voodoo3: Readbyte ack -->0x%X, read result -->0x%X\n", + temp, data); #endif - return data; + return data; } int Voodoo3_I2CSendByte(unsigned char data) { - int i,temp; + int i, temp; - for (i=7; i>=0; i--) { - dat(temp=data&(1<= 0; i--) { + dat(temp = data & (1 << i)); + out(); + clkon(); + out(); // dat(temp); - out(); - clkoff(); - out(); - } - temp=Voodoo3_I2CAck(0); + out(); + clkoff(); + out(); + } + temp = Voodoo3_I2CAck(0); #ifdef DEBUG - printk("i2c-voodoo3: Writebyte ack -->0x%X\n",temp); + printk("i2c-voodoo3: Writebyte ack -->0x%X\n", temp); #endif - return temp; + return temp; } -int Voodoo3_BusCheck(void) { +int Voodoo3_BusCheck(void) +{ /* Check the bus to see if it is in use */ - if (! rdat()) { - printk("i2c-voodoo3: I2C bus in use or hung! Try again later.\n"); - return 1; - } - return 0; + if (!rdat()) { + printk + ("i2c-voodoo3: I2C bus in use or hung! Try again later.\n"); + return 1; + } + return 0; } /* For DDC BUS */ void Voodoo3_DDCStart(void) { - ddc_clkon(); /* in theory, clk is already on */ - out(); - out(); - out(); - out(); - ddc_dat(0); - out(); - ddc_clkoff(); - out(); + ddc_clkon(); /* in theory, clk is already on */ + out(); + out(); + out(); + out(); + ddc_dat(0); + out(); + ddc_clkoff(); + out(); } void Voodoo3_DDCStop(void) { - ddc_dat(0); - out(); - ddc_clkon(); - out(); - ddc_dat(1); - out(); - ddc_clkoff(); - out(); - out(); - ddc_clkon(); - out(); + ddc_dat(0); + out(); + ddc_clkon(); + out(); + ddc_dat(1); + out(); + ddc_clkoff(); + out(); + out(); + ddc_clkon(); + out(); } int Voodoo3_DDCAck(int ackit) { -int ack=0; + int ack = 0; - out(); - ddc_clkon(); - if (!ackit) { - ack=ddc_rdat(); - } else { ddc_dat(0); } - out(); - ddc_clkoff(); - out(); - return ack; + out(); + ddc_clkon(); + if (!ackit) { + ack = ddc_rdat(); + } else { + ddc_dat(0); + } + out(); + ddc_clkoff(); + out(); + return ack; } int Voodoo3_DDCReadByte(int ackit) { - int i,temp; - unsigned char data=0; + int i, temp; + unsigned char data = 0; - for (i=7; i>=0; i--) { - out(); - ddc_clkon(); - data|=(ddc_rdat()<= 0; i--) { + out(); + ddc_clkon(); + data |= (ddc_rdat() << i); + out(); + ddc_clkoff(); + out(); + } + temp = Voodoo3_DDCAck(ackit); + return data; } int Voodoo3_DDCSendByte(unsigned char data) { - int i,temp; + int i, temp; - for (i=7; i>=0; i--) { - ddc_dat(temp=data&(1<= 0; i--) { + ddc_dat(temp = data & (1 << i)); + out(); + ddc_clkon(); + out(); + out(); + ddc_clkoff(); + out(); + } + temp = Voodoo3_DDCAck(0); + return temp; } -int Voodoo3_DDCBusCheck(void) { +int Voodoo3_DDCBusCheck(void) +{ /* Check the bus to see if it is in use */ - if (! ddc_rdat()) { - printk("i2c-voodoo3: I2C bus in use or hung! Try again later.\n"); - return 1; - } - return 0; + if (!ddc_rdat()) { + printk + ("i2c-voodoo3: I2C bus in use or hung! Try again later.\n"); + return 1; + } + return 0; } /* For I2C Bus */ int Voodoo3_I2CRead_byte(int addr) { - int this_dat=0; + int this_dat = 0; - Voodoo3_I2CStart(); - if (Voodoo3_I2CSendByte(addr)) { + Voodoo3_I2CStart(); + if (Voodoo3_I2CSendByte(addr)) { #ifdef DEBUG - printk("i2c-voodoo3: No Ack on addr WriteByte to addr 0x%X\n",addr); + printk + ("i2c-voodoo3: No Ack on addr WriteByte to addr 0x%X\n", + addr); #endif - this_dat=-1; - goto ENDREAD1; } - this_dat=Voodoo3_I2CReadByte(0); -ENDREAD1: Voodoo3_I2CStop(); + this_dat = -1; + goto ENDREAD1; + } + this_dat = Voodoo3_I2CReadByte(0); + ENDREAD1:Voodoo3_I2CStop(); #ifdef DEBUG - printk("i2c-voodoo3: Byte read at addr:0x%X result:0x%X\n",addr,this_dat); + printk("i2c-voodoo3: Byte read at addr:0x%X result:0x%X\n", addr, + this_dat); #endif - return this_dat; + return this_dat; } -int Voodoo3_I2CRead_byte_data(int addr,int command) +int Voodoo3_I2CRead_byte_data(int addr, int command) { - int this_dat=0; + int this_dat = 0; - Voodoo3_I2CStart(); - if (Voodoo3_I2CSendByte(addr)) { + Voodoo3_I2CStart(); + if (Voodoo3_I2CSendByte(addr)) { #ifdef DEBUG - printk("i2c-voodoo3: No Ack on addr WriteByte to addr 0x%X\n",addr); + printk + ("i2c-voodoo3: No Ack on addr WriteByte to addr 0x%X\n", + addr); #endif - this_dat=-1; - goto ENDREAD2; } - if (!Voodoo3_I2CSendByte(command)) { + this_dat = -1; + goto ENDREAD2; + } + if (!Voodoo3_I2CSendByte(command)) { #ifdef DEBUG - printk("i2c-voodoo3: No Ack on cmd WriteByte to addr 0x%X\n",addr); + printk + ("i2c-voodoo3: No Ack on cmd WriteByte to addr 0x%X\n", + addr); #endif - this_dat=-1; - goto ENDREAD2; } - this_dat=Voodoo3_I2CReadByte(0); -ENDREAD2: Voodoo3_I2CStop(); + this_dat = -1; + goto ENDREAD2; + } + this_dat = Voodoo3_I2CReadByte(0); + ENDREAD2:Voodoo3_I2CStop(); #ifdef DEBUG - printk("i2c-voodoo3: Byte read at addr:0x%X (command:0x%X) result:0x%X\n",addr,command,this_dat); + printk + ("i2c-voodoo3: Byte read at addr:0x%X (command:0x%X) result:0x%X\n", + addr, command, this_dat); #endif - return this_dat; + return this_dat; } -int Voodoo3_I2CRead_word(int addr,int command) +int Voodoo3_I2CRead_word(int addr, int command) { - int this_dat=0; + int this_dat = 0; - Voodoo3_I2CStart(); - if (Voodoo3_I2CSendByte(addr)) { + Voodoo3_I2CStart(); + if (Voodoo3_I2CSendByte(addr)) { #ifdef DEBUG - printk("i2c-voodoo3: No Ack on addr WriteByte to addr 0x%X\n",addr); + printk + ("i2c-voodoo3: No Ack on addr WriteByte to addr 0x%X\n", + addr); #endif - this_dat=-1; - goto ENDREAD3; } - this_dat=Voodoo3_I2CReadByte(1); - this_dat|=(Voodoo3_I2CReadByte(0)<<8); -ENDREAD3: Voodoo3_I2CStop(); + this_dat = -1; + goto ENDREAD3; + } + this_dat = Voodoo3_I2CReadByte(1); + this_dat |= (Voodoo3_I2CReadByte(0) << 8); + ENDREAD3:Voodoo3_I2CStop(); #ifdef DEBUG - printk("i2c-voodoo3: Word read at addr:0x%X (command:0x%X) result:0x%X\n",addr,command,this_dat); + printk + ("i2c-voodoo3: Word read at addr:0x%X (command:0x%X) result:0x%X\n", + addr, command, this_dat); #endif - return this_dat; + return this_dat; } -int Voodoo3_I2CWrite_byte(int addr,int command) +int Voodoo3_I2CWrite_byte(int addr, int command) { -int result=0; + int result = 0; - Voodoo3_I2CStart(); - if (Voodoo3_I2CSendByte(addr)) { + Voodoo3_I2CStart(); + if (Voodoo3_I2CSendByte(addr)) { #ifdef DEBUG - printk("i2c-voodoo3: No Ack on addr WriteByte to addr 0x%X\n",addr); + printk + ("i2c-voodoo3: No Ack on addr WriteByte to addr 0x%X\n", + addr); #endif - result=-1; - goto ENDWRITE1; } - if (Voodoo3_I2CSendByte(command)) { + result = -1; + goto ENDWRITE1; + } + if (Voodoo3_I2CSendByte(command)) { #ifdef DEBUG - printk("i2c-voodoo3: No Ack on command WriteByte to addr 0x%X\n",addr); + printk + ("i2c-voodoo3: No Ack on command WriteByte to addr 0x%X\n", + addr); #endif - result=-1; } -ENDWRITE1: Voodoo3_I2CStop(); + result = -1; + } + ENDWRITE1:Voodoo3_I2CStop(); #ifdef DEBUG - printk("i2c-voodoo3: Byte write at addr:0x%X command:0x%X\n",addr,command); + printk("i2c-voodoo3: Byte write at addr:0x%X command:0x%X\n", addr, + command); #endif return result; } -int Voodoo3_I2CWrite_byte_data(int addr,int command,int data) +int Voodoo3_I2CWrite_byte_data(int addr, int command, int data) { -int result=0; + int result = 0; - Voodoo3_I2CStart(); - if (Voodoo3_I2CSendByte(addr)) { + Voodoo3_I2CStart(); + if (Voodoo3_I2CSendByte(addr)) { #ifdef DEBUG - printk("i2c-voodoo3: No Ack on addr WriteByte to addr 0x%X\n",addr); + printk + ("i2c-voodoo3: No Ack on addr WriteByte to addr 0x%X\n", + addr); #endif - result=-1; - goto ENDWRITE2; } - if (Voodoo3_I2CSendByte(command)) { + result = -1; + goto ENDWRITE2; + } + if (Voodoo3_I2CSendByte(command)) { #ifdef DEBUG - printk("i2c-voodoo3: No Ack on command WriteByte to addr 0x%X\n",addr); + printk + ("i2c-voodoo3: No Ack on command WriteByte to addr 0x%X\n", + addr); #endif - result=-1; - goto ENDWRITE2; } - if (Voodoo3_I2CSendByte(data)) { + result = -1; + goto ENDWRITE2; + } + if (Voodoo3_I2CSendByte(data)) { #ifdef DEBUG - printk("i2c-voodoo3: No Ack on data WriteByte to addr 0x%X\n",addr); + printk + ("i2c-voodoo3: No Ack on data WriteByte to addr 0x%X\n", + addr); #endif - result=-1; } -ENDWRITE2: Voodoo3_I2CStop(); + result = -1; + } + ENDWRITE2:Voodoo3_I2CStop(); #ifdef DEBUG - printk("i2c-voodoo3: Byte write at addr:0x%X command:0x%X data:0x%X\n",addr,command,data); + printk + ("i2c-voodoo3: Byte write at addr:0x%X command:0x%X data:0x%X\n", + addr, command, data); #endif return result; } -int Voodoo3_I2CWrite_word(int addr,int command,long data) +int Voodoo3_I2CWrite_word(int addr, int command, long data) { -int result=0; + int result = 0; - Voodoo3_I2CStart(); - if (Voodoo3_I2CSendByte(addr)) { + Voodoo3_I2CStart(); + if (Voodoo3_I2CSendByte(addr)) { #ifdef DEBUG - printk("i2c-voodoo3: No Ack on addr WriteByte to addr 0x%X\n",addr); + printk + ("i2c-voodoo3: No Ack on addr WriteByte to addr 0x%X\n", + addr); #endif - result=-1; - goto ENDWRITE3; } - if (Voodoo3_I2CSendByte(command)) { + result = -1; + goto ENDWRITE3; + } + if (Voodoo3_I2CSendByte(command)) { #ifdef DEBUG - printk("i2c-voodoo3: No Ack on command WriteByte to addr 0x%X\n",addr); + printk + ("i2c-voodoo3: No Ack on command WriteByte to addr 0x%X\n", + addr); #endif - result=-1; - goto ENDWRITE3; } - if (Voodoo3_I2CSendByte(data & 0x0FF)) { + result = -1; + goto ENDWRITE3; + } + if (Voodoo3_I2CSendByte(data & 0x0FF)) { #ifdef DEBUG - printk("i2c-voodoo3: No Ack on data WriteByte to addr 0x%X\n",addr); + printk + ("i2c-voodoo3: No Ack on data WriteByte to addr 0x%X\n", + addr); #endif - result=-1; - goto ENDWRITE3; } - if (Voodoo3_I2CSendByte((data &0x0FF00)>>8)) { + result = -1; + goto ENDWRITE3; + } + if (Voodoo3_I2CSendByte((data & 0x0FF00) >> 8)) { #ifdef DEBUG - printk("i2c-voodoo3: No Ack on data byte 2 WriteByte to addr 0x%X\n",addr); + printk + ("i2c-voodoo3: No Ack on data byte 2 WriteByte to addr 0x%X\n", + addr); #endif - result=-1; } -ENDWRITE3: Voodoo3_I2CStop(); + result = -1; + } + ENDWRITE3:Voodoo3_I2CStop(); #ifdef DEBUG - printk("i2c-voodoo3: Word write at addr:0x%X command:0x%X data:0x%lX\n",addr,command,data); + printk + ("i2c-voodoo3: Word write at addr:0x%X command:0x%X data:0x%lX\n", + addr, command, data); #endif return result; } @@ -562,96 +622,109 @@ ENDWRITE3: Voodoo3_I2CStop(); int Voodoo3_DDCRead_byte(int addr) { - int this_dat=0; + int this_dat = 0; - Voodoo3_DDCStart(); - if (Voodoo3_DDCSendByte(addr)) { - this_dat=-1; - goto ENDREAD1; } - this_dat=Voodoo3_DDCReadByte(0); -ENDREAD1: Voodoo3_DDCStop(); - return this_dat; + Voodoo3_DDCStart(); + if (Voodoo3_DDCSendByte(addr)) { + this_dat = -1; + goto ENDREAD1; + } + this_dat = Voodoo3_DDCReadByte(0); + ENDREAD1:Voodoo3_DDCStop(); + return this_dat; } -int Voodoo3_DDCRead_byte_data(int addr,int command) +int Voodoo3_DDCRead_byte_data(int addr, int command) { - int this_dat=0; + int this_dat = 0; - Voodoo3_DDCStart(); - if (Voodoo3_DDCSendByte(addr)) { - this_dat=-1; - goto ENDREAD2; } - if (!Voodoo3_DDCSendByte(command)) { - this_dat=-1; - goto ENDREAD2; } - this_dat=Voodoo3_DDCReadByte(0); -ENDREAD2: Voodoo3_DDCStop(); - return this_dat; + Voodoo3_DDCStart(); + if (Voodoo3_DDCSendByte(addr)) { + this_dat = -1; + goto ENDREAD2; + } + if (!Voodoo3_DDCSendByte(command)) { + this_dat = -1; + goto ENDREAD2; + } + this_dat = Voodoo3_DDCReadByte(0); + ENDREAD2:Voodoo3_DDCStop(); + return this_dat; } -int Voodoo3_DDCRead_word(int addr,int command) +int Voodoo3_DDCRead_word(int addr, int command) { - int this_dat=0; + int this_dat = 0; - Voodoo3_DDCStart(); - if (Voodoo3_DDCSendByte(addr)) { - this_dat=-1; - goto ENDREAD3; } - this_dat=Voodoo3_DDCReadByte(1); - this_dat|=(Voodoo3_DDCReadByte(0)<<8); -ENDREAD3: Voodoo3_DDCStop(); - return this_dat; + Voodoo3_DDCStart(); + if (Voodoo3_DDCSendByte(addr)) { + this_dat = -1; + goto ENDREAD3; + } + this_dat = Voodoo3_DDCReadByte(1); + this_dat |= (Voodoo3_DDCReadByte(0) << 8); + ENDREAD3:Voodoo3_DDCStop(); + return this_dat; } -int Voodoo3_DDCWrite_byte(int addr,int command) +int Voodoo3_DDCWrite_byte(int addr, int command) { -int result=0; + int result = 0; - Voodoo3_DDCStart(); - if (Voodoo3_DDCSendByte(addr)) { - result=-1; - goto ENDWRITE1; } - if (Voodoo3_DDCSendByte(command)) { - result=-1; } -ENDWRITE1: Voodoo3_DDCStop(); + Voodoo3_DDCStart(); + if (Voodoo3_DDCSendByte(addr)) { + result = -1; + goto ENDWRITE1; + } + if (Voodoo3_DDCSendByte(command)) { + result = -1; + } + ENDWRITE1:Voodoo3_DDCStop(); return result; } -int Voodoo3_DDCWrite_byte_data(int addr,int command,int data) +int Voodoo3_DDCWrite_byte_data(int addr, int command, int data) { -int result=0; + int result = 0; - Voodoo3_DDCStart(); - if (Voodoo3_DDCSendByte(addr)) { - result=-1; - goto ENDWRITE2; } - if (Voodoo3_DDCSendByte(command)) { - result=-1; - goto ENDWRITE2; } - if (Voodoo3_DDCSendByte(data)) { - result=-1; } -ENDWRITE2: Voodoo3_DDCStop(); + Voodoo3_DDCStart(); + if (Voodoo3_DDCSendByte(addr)) { + result = -1; + goto ENDWRITE2; + } + if (Voodoo3_DDCSendByte(command)) { + result = -1; + goto ENDWRITE2; + } + if (Voodoo3_DDCSendByte(data)) { + result = -1; + } + ENDWRITE2:Voodoo3_DDCStop(); return result; } -int Voodoo3_DDCWrite_word(int addr,int command,long data) +int Voodoo3_DDCWrite_word(int addr, int command, long data) { -int result=0; + int result = 0; - Voodoo3_DDCStart(); - if (Voodoo3_DDCSendByte(addr)) { - result=-1; - goto ENDWRITE3; } - if (Voodoo3_DDCSendByte(command)) { - result=-1; - goto ENDWRITE3; } - if (Voodoo3_DDCSendByte(data & 0x0FF)) { - result=-1; - goto ENDWRITE3; } - if (Voodoo3_DDCSendByte((data &0x0FF00)>>8)) { - result=-1; } -ENDWRITE3: Voodoo3_DDCStop(); + Voodoo3_DDCStart(); + if (Voodoo3_DDCSendByte(addr)) { + result = -1; + goto ENDWRITE3; + } + if (Voodoo3_DDCSendByte(command)) { + result = -1; + goto ENDWRITE3; + } + if (Voodoo3_DDCSendByte(data & 0x0FF)) { + result = -1; + goto ENDWRITE3; + } + if (Voodoo3_DDCSendByte((data & 0x0FF00) >> 8)) { + result = -1; + } + ENDWRITE3:Voodoo3_DDCStop(); return result; } @@ -659,20 +732,20 @@ ENDWRITE3: Voodoo3_DDCStop(); void config_v3(struct pci_dev *dev) { - unsigned int cadr; + unsigned int cadr; - /* map Voodoo3 memory */ + /* map Voodoo3 memory */ #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,13) - cadr = dev->resource[0].start; + cadr = dev->resource[0].start; #else - cadr = dev->base_address[0]; + cadr = dev->base_address[0]; #endif - cadr&=PCI_BASE_ADDRESS_MEM_MASK; - mem=ioremap(cadr, 0x1000); - - *((unsigned int *)(mem+0x70))=0x8160; - *((unsigned int *)(mem+0x78))=0xcffc0020; - printk("i2c-voodoo3: Using Banshee/Voodoo3 at 0x%p\n",mem); + cadr &= PCI_BASE_ADDRESS_MEM_MASK; + mem = ioremap(cadr, 0x1000); + + *((unsigned int *) (mem + 0x70)) = 0x8160; + *((unsigned int *) (mem + 0x78)) = 0xcffc0020; + printk("i2c-voodoo3: Using Banshee/Voodoo3 at 0x%p\n", mem); } @@ -683,136 +756,180 @@ void config_v3(struct pci_dev *dev) defined to make the transition easier. */ static int voodoo3_setup(void) { - struct pci_dev *dev; + struct pci_dev *dev; - v3_num=0; + v3_num = 0; dev = NULL; do { - if((dev = pci_find_device(PCI_VENDOR_ID_3DFX, - PCI_DEVICE_ID_3DFX_VOODOO3,dev))) { - if(!v3_num) + if ((dev = pci_find_device(PCI_VENDOR_ID_3DFX, + PCI_DEVICE_ID_3DFX_VOODOO3, + dev))) { + if (!v3_num) config_v3(dev); v3_num++; } - } while(dev); + } while (dev); dev = NULL; do { - if((dev = pci_find_device(PCI_VENDOR_ID_3DFX, - PCI_DEVICE_ID_3DFX_BANSHEE,dev))) { - if(!v3_num) + if ((dev = pci_find_device(PCI_VENDOR_ID_3DFX, + PCI_DEVICE_ID_3DFX_BANSHEE, + dev))) { + if (!v3_num) config_v3(dev); v3_num++; } - } while(dev); + } while (dev); - if(v3_num > 0) { - printk(KERN_INFO "i2c-voodoo3: %d Banshee/Voodoo3(s) found.\n", v3_num); + if (v3_num > 0) { + printk(KERN_INFO + "i2c-voodoo3: %d Banshee/Voodoo3(s) found.\n", + v3_num); return 0; - } else { - printk(KERN_INFO "i2c-voodoo3: No Voodoo3 found.\n"); - return -ENODEV; + } else { + printk(KERN_INFO "i2c-voodoo3: No Voodoo3 found.\n"); + return -ENODEV; } } /* For I2C BUS */ /* Return -1 on error. See smbus.h for more information */ -s32 voodoo3_access(struct i2c_adapter *adap, u16 addr, - unsigned short flags, char read_write, - u8 command, int size, union i2c_smbus_data * data) +s32 voodoo3_access(struct i2c_adapter * adap, u16 addr, + unsigned short flags, char read_write, + u8 command, int size, union i2c_smbus_data * data) { - int temp=0; + int temp = 0; - if (Voodoo3_BusCheck()) return -1; + if (Voodoo3_BusCheck()) + return -1; - if ((read_write != I2C_SMBUS_READ) && (read_write != I2C_SMBUS_WRITE)) { - printk("i2c-voodoo3: Unknown read_write command! (0x%X)\n",read_write); - return -1; - } - addr=((addr & 0x7f) << 1) | (read_write & 0x01); - switch(size) { - case I2C_SMBUS_QUICK: - Voodoo3_I2CStart(); - if (Voodoo3_I2CSendByte(addr)) { + if ((read_write != I2C_SMBUS_READ) + && (read_write != I2C_SMBUS_WRITE)) { + printk("i2c-voodoo3: Unknown read_write command! (0x%X)\n", + read_write); + return -1; + } + addr = ((addr & 0x7f) << 1) | (read_write & 0x01); + switch (size) { + case I2C_SMBUS_QUICK: + Voodoo3_I2CStart(); + if (Voodoo3_I2CSendByte(addr)) { #ifdef DEBUG - printk("i2c-voodoo3: No Ack on addr WriteByte to addr 0x%X\n",addr); + printk + ("i2c-voodoo3: No Ack on addr WriteByte to addr 0x%X\n", + addr); #endif - return -1; } - case I2C_SMBUS_BYTE: - if (read_write == I2C_SMBUS_READ) { temp=Voodoo3_I2CRead_byte(addr); data->byte=temp; - } else { temp=Voodoo3_I2CWrite_byte(addr,command); } - goto TESTACK; - case I2C_SMBUS_BYTE_DATA: - if (read_write == I2C_SMBUS_READ) { temp=Voodoo3_I2CRead_byte_data(addr,command); data->byte=temp; - } else { temp=Voodoo3_I2CWrite_byte_data(addr,command,data->byte); } - goto TESTACK; - case I2C_SMBUS_WORD_DATA: - if (read_write == I2C_SMBUS_READ) { temp=Voodoo3_I2CRead_word(addr,command); data->word=temp; - } else { temp=Voodoo3_I2CWrite_word(addr,command,data->word); } - goto TESTACK; - case I2C_SMBUS_PROC_CALL: - printk("i2c-voodoo3: Proc call not supported.\n"); - return -1; - case I2C_SMBUS_BLOCK_DATA: - printk("i2c-voodoo3: Block transfers not supported yet.\n"); - return -1; - } + return -1; + } + case I2C_SMBUS_BYTE: + if (read_write == I2C_SMBUS_READ) { + temp = Voodoo3_I2CRead_byte(addr); + data->byte = temp; + } else { + temp = Voodoo3_I2CWrite_byte(addr, command); + } + goto TESTACK; + case I2C_SMBUS_BYTE_DATA: + if (read_write == I2C_SMBUS_READ) { + temp = Voodoo3_I2CRead_byte_data(addr, command); + data->byte = temp; + } else { + temp = + Voodoo3_I2CWrite_byte_data(addr, command, + data->byte);} + goto TESTACK; + case I2C_SMBUS_WORD_DATA: + if (read_write == I2C_SMBUS_READ) { + temp = Voodoo3_I2CRead_word(addr, command); + data->word = temp; + } else { + temp = + Voodoo3_I2CWrite_word(addr, command, + data->word);} + goto TESTACK; + case I2C_SMBUS_PROC_CALL: + printk("i2c-voodoo3: Proc call not supported.\n"); + return -1; + case I2C_SMBUS_BLOCK_DATA: + printk + ("i2c-voodoo3: Block transfers not supported yet.\n"); + return -1; + } -TESTACK: if (temp < 0) { + TESTACK:if (temp < 0) { #ifdef DEBUG - printk("i2c-voodoo3: no device at 0x%X\n",addr); + printk("i2c-voodoo3: no device at 0x%X\n", addr); #endif return -1; - } + } return 0; } /* For DDC BUS */ /* Return -1 on error. See smbus.h for more information */ -s32 voodoo3_ddc_access(struct i2c_adapter *adap, u16 addr, - unsigned short flags, char read_write, - u8 command, int size, union i2c_smbus_data * data) +s32 voodoo3_ddc_access(struct i2c_adapter * adap, u16 addr, + unsigned short flags, char read_write, + u8 command, int size, union i2c_smbus_data * data) { - int temp=0; + int temp = 0; - if (Voodoo3_DDCBusCheck()) return -1; - - if ((read_write != I2C_SMBUS_READ) && (read_write != I2C_SMBUS_WRITE)) { - printk("i2c-voodoo3: Unknown read_write command! (0x%X)\n",read_write); - return -1; - } - addr=((addr & 0x7f) << 1) | (read_write & 0x01); - switch(size) { - case I2C_SMBUS_QUICK: - Voodoo3_DDCStart(); - if (Voodoo3_DDCSendByte(addr)) { - return -1; } - case I2C_SMBUS_BYTE: - if (read_write == I2C_SMBUS_READ) { temp=Voodoo3_DDCRead_byte(addr); data->byte=temp; - } else { temp=Voodoo3_DDCWrite_byte(addr,command); } - goto TESTACK; - case I2C_SMBUS_BYTE_DATA: - if (read_write == I2C_SMBUS_READ) { temp=Voodoo3_DDCRead_byte_data(addr,command); data->byte=temp; - } else { temp=Voodoo3_DDCWrite_byte_data(addr,command,data->byte); } - goto TESTACK; - case I2C_SMBUS_WORD_DATA: - if (read_write == I2C_SMBUS_READ) { temp=Voodoo3_DDCRead_word(addr,command); data->word=temp; - } else { temp=Voodoo3_DDCWrite_word(addr,command,data->word); } - goto TESTACK; - case I2C_SMBUS_PROC_CALL: - printk("i2c-voodoo3: Proc call not supported.\n"); - return -1; - case I2C_SMBUS_BLOCK_DATA: - printk("i2c-voodoo3: Block transfers not supported yet.\n"); - return -1; - } - -TESTACK: if (temp < 0) { + if (Voodoo3_DDCBusCheck()) return -1; - } + + if ((read_write != I2C_SMBUS_READ) + && (read_write != I2C_SMBUS_WRITE)) { + printk("i2c-voodoo3: Unknown read_write command! (0x%X)\n", + read_write); + return -1; + } + addr = ((addr & 0x7f) << 1) | (read_write & 0x01); + switch (size) { + case I2C_SMBUS_QUICK: + Voodoo3_DDCStart(); + if (Voodoo3_DDCSendByte(addr)) { + return -1; + } + case I2C_SMBUS_BYTE: + if (read_write == I2C_SMBUS_READ) { + temp = Voodoo3_DDCRead_byte(addr); + data->byte = temp; + } else { + temp = Voodoo3_DDCWrite_byte(addr, command); + } + goto TESTACK; + case I2C_SMBUS_BYTE_DATA: + if (read_write == I2C_SMBUS_READ) { + temp = Voodoo3_DDCRead_byte_data(addr, command); + data->byte = temp; + } else { + temp = + Voodoo3_DDCWrite_byte_data(addr, command, + data->byte);} + goto TESTACK; + case I2C_SMBUS_WORD_DATA: + if (read_write == I2C_SMBUS_READ) { + temp = Voodoo3_DDCRead_word(addr, command); + data->word = temp; + } else { + temp = + Voodoo3_DDCWrite_word(addr, command, + data->word);} + goto TESTACK; + case I2C_SMBUS_PROC_CALL: + printk("i2c-voodoo3: Proc call not supported.\n"); + return -1; + case I2C_SMBUS_BLOCK_DATA: + printk + ("i2c-voodoo3: Block transfers not supported yet.\n"); + return -1; + } + + TESTACK:if (temp < 0) { + return -1; + } return 0; } @@ -829,90 +946,97 @@ void voodoo3_dec(struct i2c_adapter *adapter) u32 voodoo3_func(struct i2c_adapter *adapter) { - return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | - I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA; + return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | + I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA; } int __init i2c_voodoo3_init(void) { - int res; - printk("i2c-voodoo3.o version %s (%s)\n",LM_VERSION,LM_DATE); + int res; + printk("i2c-voodoo3.o version %s (%s)\n", LM_VERSION, LM_DATE); #ifdef DEBUG /* PE- It might be good to make this a permanent part of the code! */ - if (voodoo3_initialized) { - printk("i2c-voodoo3.o: Oops, voodoo3_init called a second time!\n"); - return -EBUSY; - } + if (voodoo3_initialized) { + printk + ("i2c-voodoo3.o: Oops, voodoo3_init called a second time!\n"); + return -EBUSY; + } #endif - voodoo3_initialized = 0; - if ((res = voodoo3_setup())) { - printk("i2c-voodoo3.o: Voodoo3 not detected, module not inserted.\n"); - voodoo3_cleanup(); - return res; - } - voodoo3_initialized ++; - sprintf(voodoo3_i2c_adapter.name,"SMBus Voodoo3 adapter at %04x",voodoo3_smba); - if ((res = i2c_add_adapter(&voodoo3_i2c_adapter))) { - printk("i2c-voodoo3.o: Adapter registration failed, module not inserted.\n"); - voodoo3_cleanup(); - return res; - } - voodoo3_initialized ++; - sprintf(voodoo3_ddc_adapter.name,"DDC Voodoo3 adapter at %04x",voodoo3_smba); - if ((res = i2c_add_adapter(&voodoo3_ddc_adapter))) { - printk("i2c-voodoo3.o: Adapter registration failed, module not inserted.\n"); - voodoo3_cleanup(); - return res; - } - voodoo3_initialized++; - printk("i2c-voodoo3.o: Voodoo3 I2C and DDC busses detected and initialized\n"); - return 0; + voodoo3_initialized = 0; + if ((res = voodoo3_setup())) { + printk + ("i2c-voodoo3.o: Voodoo3 not detected, module not inserted.\n"); + voodoo3_cleanup(); + return res; + } + voodoo3_initialized++; + sprintf(voodoo3_i2c_adapter.name, "SMBus Voodoo3 adapter at %04x", + voodoo3_smba); + if ((res = i2c_add_adapter(&voodoo3_i2c_adapter))) { + printk + ("i2c-voodoo3.o: Adapter registration failed, module not inserted.\n"); + voodoo3_cleanup(); + return res; + } + voodoo3_initialized++; + sprintf(voodoo3_ddc_adapter.name, "DDC Voodoo3 adapter at %04x", + voodoo3_smba); + if ((res = i2c_add_adapter(&voodoo3_ddc_adapter))) { + printk + ("i2c-voodoo3.o: Adapter registration failed, module not inserted.\n"); + voodoo3_cleanup(); + return res; + } + voodoo3_initialized++; + printk + ("i2c-voodoo3.o: Voodoo3 I2C and DDC busses detected and initialized\n"); + return 0; } int __init voodoo3_cleanup(void) { - int res; - - iounmap(mem); - if (voodoo3_initialized >= 3) - { - if ((res = i2c_del_adapter(&voodoo3_ddc_adapter))) { - printk("i2c-voodoo3.o: i2c_del_adapter failed, module not removed\n"); - return res; - } else - voodoo3_initialized--; - } - if (voodoo3_initialized >= 2) - { - if ((res = i2c_del_adapter(&voodoo3_i2c_adapter))) { - printk("i2c-voodoo3.o: i2c_del_adapter failed, module not removed\n"); - return res; - } else - voodoo3_initialized--; - } - if (voodoo3_initialized >= 1) { - voodoo3_initialized--; - } - return 0; + int res; + + iounmap(mem); + if (voodoo3_initialized >= 3) { + if ((res = i2c_del_adapter(&voodoo3_ddc_adapter))) { + printk + ("i2c-voodoo3.o: i2c_del_adapter failed, module not removed\n"); + return res; + } else + voodoo3_initialized--; + } + if (voodoo3_initialized >= 2) { + if ((res = i2c_del_adapter(&voodoo3_i2c_adapter))) { + printk + ("i2c-voodoo3.o: i2c_del_adapter failed, module not removed\n"); + return res; + } else + voodoo3_initialized--; + } + if (voodoo3_initialized >= 1) { + voodoo3_initialized--; + } + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard , Philip Edelbrock , Ralph Metzler , and Mark D. Studebaker "); +MODULE_AUTHOR + ("Frodo Looijaard , Philip Edelbrock , Ralph Metzler , and Mark D. Studebaker "); MODULE_DESCRIPTION("Voodoo3 I2C/SMBus driver"); int init_module(void) { - return i2c_voodoo3_init(); + return i2c_voodoo3_init(); } int cleanup_module(void) { - return voodoo3_cleanup(); + return voodoo3_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/adm1021.c b/kernel/chips/adm1021.c index 93bd80a7..dd76cef7 100644 --- a/kernel/chips/adm1021.c +++ b/kernel/chips/adm1021.c @@ -38,14 +38,15 @@ #endif /* Addresses to scan */ -static unsigned short normal_i2c[] = {SENSORS_I2C_END}; -static unsigned short normal_i2c_range[] = {0x18,0x1a,0x29,0x2b, - 0x4c,0x4e,SENSORS_I2C_END}; -static unsigned int normal_isa[] = {SENSORS_ISA_END}; -static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; +static unsigned short normal_i2c[] = { SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { 0x18, 0x1a, 0x29, 0x2b, + 0x4c, 0x4e, SENSORS_I2C_END +}; +static unsigned int normal_isa[] = { SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_6(adm1021,max1617,max1617a,thmc10,lm84,gl523sm); +SENSORS_INSMOD_6(adm1021, max1617, max1617a, thmc10, lm84, gl523sm); /* adm1021 constants specified below */ @@ -54,9 +55,9 @@ SENSORS_INSMOD_6(adm1021,max1617,max1617a,thmc10,lm84,gl523sm); #define ADM1021_REG_TEMP 0x00 #define ADM1021_REG_REMOTE_TEMP 0x01 #define ADM1021_REG_STATUS 0x02 -#define ADM1021_REG_MAN_ID 0x0FE /* 0x41 = AMD, 0x49 = TI, 0x4D = Maxim, 0x23 = Genesys */ -#define ADM1021_REG_DEV_ID 0x0FF /* ADM1021 */ -#define ADM1021_REG_DIE_CODE 0x0FF /* MAX1617A */ +#define ADM1021_REG_MAN_ID 0x0FE /* 0x41 = AMD, 0x49 = TI, 0x4D = Maxim, 0x23 = Genesys */ +#define ADM1021_REG_DEV_ID 0x0FF /* ADM1021 */ +#define ADM1021_REG_DIE_CODE 0x0FF /* MAX1617A */ /* These use different addresses for reading/writing */ #define ADM1021_REG_CONFIG_R 0x03 #define ADM1021_REG_CONFIG_W 0x09 @@ -95,61 +96,63 @@ clearing it. Weird, ey? --Phil */ /* Each client has this additional data */ struct adm1021_data { - int sysctl_id; - enum chips type; + int sysctl_id; + enum chips type; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ - u8 temp,temp_os,temp_hyst; /* Register values */ - u8 remote_temp,remote_temp_os,remote_temp_hyst,alarms,die_code; + u8 temp, temp_os, temp_hyst; /* Register values */ + u8 remote_temp, remote_temp_os, remote_temp_hyst, alarms, die_code; }; #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ #ifdef MODULE static #else extern #endif - int __init sensors_adm1021_init(void); +int __init sensors_adm1021_init(void); static int __init adm1021_cleanup(void); static int adm1021_attach_adapter(struct i2c_adapter *adapter); -static int adm1021_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind); +static int adm1021_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); static void adm1021_init_client(struct i2c_client *client); static int adm1021_detach_client(struct i2c_client *client); static int adm1021_command(struct i2c_client *client, unsigned int cmd, - void *arg); -static void adm1021_inc_use (struct i2c_client *client); -static void adm1021_dec_use (struct i2c_client *client); + void *arg); +static void adm1021_inc_use(struct i2c_client *client); +static void adm1021_dec_use(struct i2c_client *client); static int adm1021_read_value(struct i2c_client *client, u8 reg); -static int adm1021_write_value(struct i2c_client *client, u8 reg, u16 value); -static void adm1021_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void adm1021_remote_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void adm1021_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void adm1021_die_code(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); +static int adm1021_write_value(struct i2c_client *client, u8 reg, + u16 value); +static void adm1021_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void adm1021_remote_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, + long *results); +static void adm1021_alarms(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void adm1021_die_code(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static void adm1021_update_client(struct i2c_client *client); /* This is the driver that will be inserted */ static struct i2c_driver adm1021_driver = { - /* name */ "ADM1021, MAX1617 sensor driver", - /* id */ I2C_DRIVERID_ADM1021, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &adm1021_attach_adapter, - /* detach_client */ &adm1021_detach_client, - /* command */ &adm1021_command, - /* inc_use */ &adm1021_inc_use, - /* dec_use */ &adm1021_dec_use + /* name */ "ADM1021, MAX1617 sensor driver", + /* id */ I2C_DRIVERID_ADM1021, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &adm1021_attach_adapter, + /* detach_client */ &adm1021_detach_client, + /* command */ &adm1021_command, + /* inc_use */ &adm1021_inc_use, + /* dec_use */ &adm1021_dec_use }; /* These files are created for each detected adm1021. This is just a template; @@ -158,25 +161,25 @@ static struct i2c_driver adm1021_driver = { is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table adm1021_dir_table_template[] = { - { ADM1021_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm1021_temp }, - {ADM1021_SYSCTL_REMOTE_TEMP, "remote_temp", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm1021_remote_temp }, - {ADM1021_SYSCTL_DIE_CODE, "die_code", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm1021_die_code }, - {ADM1021_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm1021_alarms }, - { 0 } + {ADM1021_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1021_temp}, + {ADM1021_SYSCTL_REMOTE_TEMP, "remote_temp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1021_remote_temp}, + {ADM1021_SYSCTL_DIE_CODE, "die_code", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1021_die_code}, + {ADM1021_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1021_alarms}, + {0} }; static ctl_table adm1021_max_dir_table_template[] = { - { ADM1021_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm1021_temp }, - {ADM1021_SYSCTL_REMOTE_TEMP, "remote_temp", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm1021_remote_temp }, - {ADM1021_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm1021_alarms }, - { 0 } + {ADM1021_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1021_temp}, + {ADM1021_SYSCTL_REMOTE_TEMP, "remote_temp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1021_remote_temp}, + {ADM1021_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm1021_alarms}, + {0} }; @@ -190,166 +193,177 @@ static int adm1021_id = 0; int adm1021_attach_adapter(struct i2c_adapter *adapter) { - return sensors_detect(adapter,&addr_data,adm1021_detect); + return sensors_detect(adapter, &addr_data, adm1021_detect); } -static int adm1021_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind) -{ - int i; - struct i2c_client *new_client; - struct adm1021_data *data; - int err=0; - const char *type_name = ""; - const char *client_name = ""; +static int adm1021_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) +{ + int i; + struct i2c_client *new_client; + struct adm1021_data *data; + int err = 0; + const char *type_name = ""; + const char *client_name = ""; - /* Make sure we aren't probing the ISA bus!! This is just a safety check - at this moment; sensors_detect really won't call us. */ + /* Make sure we aren't probing the ISA bus!! This is just a safety check + at this moment; sensors_detect really won't call us. */ #ifdef DEBUG - if (i2c_is_isa_adapter(adapter)) { - printk("adm1021.o: adm1021_detect called for an ISA bus adapter?!?\n"); - return 0; - } + if (i2c_is_isa_adapter(adapter)) { + printk + ("adm1021.o: adm1021_detect called for an ISA bus adapter?!?\n"); + return 0; + } #endif - if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_BYTE_DATA)) - goto ERROR0; + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) + goto ERROR0; - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access adm1021_{read,write}_value. */ + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access adm1021_{read,write}_value. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct adm1021_data), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR0; - } + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct adm1021_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } - data = (struct adm1021_data *) (new_client + 1); - new_client->addr = address; - new_client->data = data; - new_client->adapter = adapter; - new_client->driver = &adm1021_driver; - new_client->flags = 0; + data = (struct adm1021_data *) (new_client + 1); + new_client->addr = address; + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &adm1021_driver; + new_client->flags = 0; - /* Now, we do the remaining detection. */ + /* Now, we do the remaining detection. */ - if (kind < 0) { - if ((adm1021_read_value(new_client,ADM1021_REG_STATUS) & 0x03) != 0x00) - goto ERROR1; - } + if (kind < 0) { + if ( + (adm1021_read_value(new_client, ADM1021_REG_STATUS) & + 0x03) != 0x00) + goto ERROR1; + } - /* Determine the chip type. */ - - if (kind <= 0) { - i = adm1021_read_value(new_client,ADM1021_REG_MAN_ID); - if (i == 0x41) - kind = adm1021; - else if (i == 0x49) - kind = thmc10; - else if (i == 0x23) - kind = gl523sm; - else if ((i== 0x4d) && - (adm1021_read_value(new_client,ADM1021_REG_DEV_ID) == 0x01)) - kind = max1617a; - /* LM84 Mfr ID in a different place */ - else if (adm1021_read_value(new_client,ADM1021_REG_CONV_RATE_R) == 0x00) - kind = lm84; - else - kind = max1617; - } + /* Determine the chip type. */ - if (kind == max1617) { - type_name = "max1617"; - client_name = "MAX1617 chip"; - } else if (kind == max1617a) { - type_name = "max1617a"; - client_name = "MAX1617A chip"; - } else if (kind == adm1021) { - type_name = "adm1021"; - client_name = "ADM1021 chip"; - } else if (kind == thmc10) { - type_name = "thmc10"; - client_name = "THMC10 chip"; - } else { + if (kind <= 0) { + i = adm1021_read_value(new_client, ADM1021_REG_MAN_ID); + if (i == 0x41) + kind = adm1021; + else if (i == 0x49) + kind = thmc10; + else if (i == 0x23) + kind = gl523sm; + else if ((i == 0x4d) && + (adm1021_read_value + (new_client, ADM1021_REG_DEV_ID) == 0x01)) + kind = max1617a; + /* LM84 Mfr ID in a different place */ + else + if (adm1021_read_value + (new_client, ADM1021_REG_CONV_RATE_R) == 0x00) + kind = lm84; + else + kind = max1617; + } + + if (kind == max1617) { + type_name = "max1617"; + client_name = "MAX1617 chip"; + } else if (kind == max1617a) { + type_name = "max1617a"; + client_name = "MAX1617A chip"; + } else if (kind == adm1021) { + type_name = "adm1021"; + client_name = "ADM1021 chip"; + } else if (kind == thmc10) { + type_name = "thmc10"; + client_name = "THMC10 chip"; + } else { #ifdef DEBUG - printk("adm1021.o: Internal error: unknown kind (%d)?!?",kind); + printk("adm1021.o: Internal error: unknown kind (%d)?!?", + kind); #endif - goto ERROR1; - } + goto ERROR1; + } - /* Fill in the remaining client fields and put it into the global list */ - strcpy(new_client->name,client_name); - data->type = kind; + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); + data->type = kind; - new_client->id = adm1021_id++; - data->valid = 0; - init_MUTEX(&data->update_lock); + new_client->id = adm1021_id++; + data->valid = 0; + init_MUTEX(&data->update_lock); - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; - /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry(new_client, - type_name, - data->type==adm1021?adm1021_dir_table_template: - adm1021_max_dir_table_template, - THIS_MODULE)) < 0) { - err = i; - goto ERROR4; - } - data->sysctl_id = i; + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry(new_client, + type_name, + data->type == + adm1021 ? + adm1021_dir_table_template : + adm1021_max_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; - /* Initialize the ADM1021 chip */ - adm1021_init_client(new_client); - return 0; + /* Initialize the ADM1021 chip */ + adm1021_init_client(new_client); + return 0; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR4: - i2c_detach_client(new_client); -ERROR3: -ERROR1: - kfree(new_client); -ERROR0: - return err; + ERROR4: + i2c_detach_client(new_client); + ERROR3: + ERROR1: + kfree(new_client); + ERROR0: + return err; } void adm1021_init_client(struct i2c_client *client) { - /* Initialize the adm1021 chip */ - adm1021_write_value(client,ADM1021_REG_TOS_W, - TEMP_TO_REG(adm1021_INIT_TOS)); - adm1021_write_value(client,ADM1021_REG_THYST_W, - TEMP_TO_REG(adm1021_INIT_THYST)); - adm1021_write_value(client,ADM1021_REG_REMOTE_TOS_W, - TEMP_TO_REG(adm1021_INIT_REMOTE_TOS)); - adm1021_write_value(client,ADM1021_REG_REMOTE_THYST_W, - TEMP_TO_REG(adm1021_INIT_REMOTE_THYST)); - /* Enable ADC and disable suspend mode */ - adm1021_write_value(client,ADM1021_REG_CONFIG_W,0); - /* Set Conversion rate to 1/sec (this can be tinkered with) */ - adm1021_write_value(client,ADM1021_REG_CONV_RATE_W,0x04); + /* Initialize the adm1021 chip */ + adm1021_write_value(client, ADM1021_REG_TOS_W, + TEMP_TO_REG(adm1021_INIT_TOS)); + adm1021_write_value(client, ADM1021_REG_THYST_W, + TEMP_TO_REG(adm1021_INIT_THYST)); + adm1021_write_value(client, ADM1021_REG_REMOTE_TOS_W, + TEMP_TO_REG(adm1021_INIT_REMOTE_TOS)); + adm1021_write_value(client, ADM1021_REG_REMOTE_THYST_W, + TEMP_TO_REG(adm1021_INIT_REMOTE_THYST)); + /* Enable ADC and disable suspend mode */ + adm1021_write_value(client, ADM1021_REG_CONFIG_W, 0); + /* Set Conversion rate to 1/sec (this can be tinkered with) */ + adm1021_write_value(client, ADM1021_REG_CONV_RATE_W, 0x04); } int adm1021_detach_client(struct i2c_client *client) { - int err; + int err; - sensors_deregister_entry(((struct adm1021_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct adm1021_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("adm1021.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("adm1021.o: Client deregistration failed, client not detached.\n"); + return err; + } - kfree(client); + kfree(client); - return 0; + return 0; } @@ -357,188 +371,204 @@ int adm1021_detach_client(struct i2c_client *client) /* No commands defined yet */ int adm1021_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } -void adm1021_inc_use (struct i2c_client *client) +void adm1021_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } -void adm1021_dec_use (struct i2c_client *client) +void adm1021_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } /* All registers are byte-sized */ int adm1021_read_value(struct i2c_client *client, u8 reg) { - return i2c_smbus_read_byte_data(client,reg); + return i2c_smbus_read_byte_data(client, reg); } int adm1021_write_value(struct i2c_client *client, u8 reg, u16 value) { - return i2c_smbus_write_byte_data(client,reg,value); + return i2c_smbus_write_byte_data(client, reg, value); } void adm1021_update_client(struct i2c_client *client) { - struct adm1021_data *data = client->data; + struct adm1021_data *data = client->data; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > HZ+HZ/2 ) || - (jiffies < data->last_updated) || ! data->valid) { + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("Starting adm1021 update\n"); + printk("Starting adm1021 update\n"); #endif - data->temp = adm1021_read_value(client,ADM1021_REG_TEMP); - data->temp_os = adm1021_read_value(client,ADM1021_REG_TOS_R); - data->temp_hyst = adm1021_read_value(client,ADM1021_REG_THYST_R); - data->remote_temp = adm1021_read_value(client,ADM1021_REG_REMOTE_TEMP); - data->remote_temp_os = adm1021_read_value(client,ADM1021_REG_REMOTE_TOS_R); - data->remote_temp_hyst = adm1021_read_value(client,ADM1021_REG_REMOTE_THYST_R); - data->alarms = adm1021_read_value(client,ADM1021_REG_STATUS) & 0xec; - if (data->type == adm1021) - data->die_code = adm1021_read_value(client,ADM1021_REG_DIE_CODE); - data->last_updated = jiffies; - data->valid = 1; - } + data->temp = adm1021_read_value(client, ADM1021_REG_TEMP); + data->temp_os = + adm1021_read_value(client, ADM1021_REG_TOS_R); + data->temp_hyst = + adm1021_read_value(client, ADM1021_REG_THYST_R); + data->remote_temp = + adm1021_read_value(client, ADM1021_REG_REMOTE_TEMP); + data->remote_temp_os = + adm1021_read_value(client, ADM1021_REG_REMOTE_TOS_R); + data->remote_temp_hyst = + adm1021_read_value(client, ADM1021_REG_REMOTE_THYST_R); + data->alarms = + adm1021_read_value(client, ADM1021_REG_STATUS) & 0xec; + if (data->type == adm1021) + data->die_code = + adm1021_read_value(client, + ADM1021_REG_DIE_CODE); + data->last_updated = jiffies; + data->valid = 1; + } - up(&data->update_lock); + up(&data->update_lock); } void adm1021_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct adm1021_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - adm1021_update_client(client); - results[0] = TEMP_FROM_REG(data->temp_os); - results[1] = TEMP_FROM_REG(data->temp_hyst); - results[2] = TEMP_FROM_REG(data->temp); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->temp_os = TEMP_TO_REG(results[0]); - adm1021_write_value(client,ADM1021_REG_TOS_W,data->temp_os); - } - if (*nrels_mag >= 2) { - data->temp_hyst = TEMP_TO_REG(results[1]); - adm1021_write_value(client,ADM1021_REG_THYST_W,data->temp_hyst); - } - } + struct adm1021_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + adm1021_update_client(client); + results[0] = TEMP_FROM_REG(data->temp_os); + results[1] = TEMP_FROM_REG(data->temp_hyst); + results[2] = TEMP_FROM_REG(data->temp); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->temp_os = TEMP_TO_REG(results[0]); + adm1021_write_value(client, ADM1021_REG_TOS_W, + data->temp_os); + } + if (*nrels_mag >= 2) { + data->temp_hyst = TEMP_TO_REG(results[1]); + adm1021_write_value(client, ADM1021_REG_THYST_W, + data->temp_hyst); + } + } } -void adm1021_remote_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void adm1021_remote_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - struct adm1021_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - adm1021_update_client(client); - results[0] = TEMP_FROM_REG(data->remote_temp_os); - results[1] = TEMP_FROM_REG(data->remote_temp_hyst); - results[2] = TEMP_FROM_REG(data->remote_temp); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->remote_temp_os = TEMP_TO_REG(results[0]); - adm1021_write_value(client,ADM1021_REG_REMOTE_TOS_W,data->remote_temp_os); - } - if (*nrels_mag >= 2) { - data->remote_temp_hyst = TEMP_TO_REG(results[1]); - adm1021_write_value(client,ADM1021_REG_REMOTE_THYST_W,data->remote_temp_hyst); - } - } + struct adm1021_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + adm1021_update_client(client); + results[0] = TEMP_FROM_REG(data->remote_temp_os); + results[1] = TEMP_FROM_REG(data->remote_temp_hyst); + results[2] = TEMP_FROM_REG(data->remote_temp); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->remote_temp_os = TEMP_TO_REG(results[0]); + adm1021_write_value(client, + ADM1021_REG_REMOTE_TOS_W, + data->remote_temp_os); + } + if (*nrels_mag >= 2) { + data->remote_temp_hyst = TEMP_TO_REG(results[1]); + adm1021_write_value(client, + ADM1021_REG_REMOTE_THYST_W, + data->remote_temp_hyst); + } + } } -void adm1021_die_code(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void adm1021_die_code(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - struct adm1021_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - adm1021_update_client(client); - results[0] = data->die_code; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - /* Can't write to it */ - } + struct adm1021_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + adm1021_update_client(client); + results[0] = data->die_code; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + /* Can't write to it */ + } } void adm1021_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct adm1021_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - adm1021_update_client(client); - results[0] = data->alarms; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - /* Can't write to it */ - } + struct adm1021_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + adm1021_update_client(client); + results[0] = data->alarms; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + /* Can't write to it */ + } } int __init sensors_adm1021_init(void) { - int res; + int res; - printk("adm1021.o version %s (%s)\n",LM_VERSION,LM_DATE); - adm1021_initialized = 0; - if ((res = i2c_add_driver(&adm1021_driver))) { - printk("adm1021.o: Driver registration failed, module not inserted.\n"); - adm1021_cleanup(); - return res; - } - adm1021_initialized ++; - return 0; + printk("adm1021.o version %s (%s)\n", LM_VERSION, LM_DATE); + adm1021_initialized = 0; + if ((res = i2c_add_driver(&adm1021_driver))) { + printk + ("adm1021.o: Driver registration failed, module not inserted.\n"); + adm1021_cleanup(); + return res; + } + adm1021_initialized++; + return 0; } int __init adm1021_cleanup(void) { - int res; + int res; - if (adm1021_initialized >= 1) { - if ((res = i2c_del_driver(&adm1021_driver))) { - printk("adm1021.o: Driver deregistration failed, module not removed.\n"); - return res; - } - adm1021_initialized --; - } + if (adm1021_initialized >= 1) { + if ((res = i2c_del_driver(&adm1021_driver))) { + printk + ("adm1021.o: Driver deregistration failed, module not removed.\n"); + return res; + } + adm1021_initialized--; + } - return 0; + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard and Philip Edelbrock "); +MODULE_AUTHOR + ("Frodo Looijaard and Philip Edelbrock "); MODULE_DESCRIPTION("adm1021 driver"); int init_module(void) { - return sensors_adm1021_init(); + return sensors_adm1021_init(); } int cleanup_module(void) { - return adm1021_cleanup(); + return adm1021_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/adm9240.c b/kernel/chips/adm9240.c index e82ce3f3..b4f5d41c 100644 --- a/kernel/chips/adm9240.c +++ b/kernel/chips/adm9240.c @@ -72,13 +72,13 @@ #endif /* Addresses to scan */ -static unsigned short normal_i2c[] = {SENSORS_I2C_END}; -static unsigned short normal_i2c_range[] = {0x2c,0x2f,SENSORS_I2C_END}; -static unsigned int normal_isa[] = {SENSORS_ISA_END}; -static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; +static unsigned short normal_i2c[] = { SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { 0x2c, 0x2f, SENSORS_I2C_END }; +static unsigned int normal_isa[] = { SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_3(adm9240,ds1780,lm81); +SENSORS_INSMOD_3(adm9240, ds1780, lm81); /* Many ADM9240 constants specified below */ @@ -99,8 +99,8 @@ SENSORS_INSMOD_3(adm9240,ds1780,lm81); #define ADM9240_REG_TEMP 0x27 #define ADM9240_REG_FAN1 0x28 #define ADM9240_REG_FAN2 0x29 -#define ADM9240_REG_COMPANY_ID 0x3E /* 0x23 for ADM9240; 0xDA for DS1780 */ - /* 0x01 for LM81 */ +#define ADM9240_REG_COMPANY_ID 0x3E /* 0x23 for ADM9240; 0xDA for DS1780 */ + /* 0x01 for LM81 */ #define ADM9240_REG_DIE_REV 0x3F /* These are read/write */ #define ADM9240_REG_2_5V_HIGH 0x2B @@ -115,8 +115,8 @@ SENSORS_INSMOD_3(adm9240,ds1780,lm81); #define ADM9240_REG_12V_LOW 0x34 #define ADM9240_REG_VCCP2_HIGH 0x35 #define ADM9240_REG_VCCP2_LOW 0x36 -#define ADM9240_REG_TCRIT_LIMIT 0x37 /* LM81 only - not supported */ -#define ADM9240_REG_LOW_LIMIT 0x38 /* LM81 only - not supported */ +#define ADM9240_REG_TCRIT_LIMIT 0x37 /* LM81 only - not supported */ +#define ADM9240_REG_LOW_LIMIT 0x38 /* LM81 only - not supported */ #define ADM9240_REG_TOS 0x39 #define ADM9240_REG_THYST 0x3A #define ADM9240_REG_FAN1_MIN 0x3B @@ -128,14 +128,14 @@ SENSORS_INSMOD_3(adm9240,ds1780,lm81); #define ADM9240_REG_INT1_MASK 0x43 #define ADM9240_REG_INT2_MASK 0x44 -#define ADM9240_REG_COMPAT 0x45 /* dummy compat. register for other drivers? */ +#define ADM9240_REG_COMPAT 0x45 /* dummy compat. register for other drivers? */ #define ADM9240_REG_CHASSIS_CLEAR 0x46 #define ADM9240_REG_VID_FAN_DIV 0x47 #define ADM9240_REG_I2C_ADDR 0x48 #define ADM9240_REG_VID4 0x49 #define ADM9240_REG_TEMP_CONFIG 0x4B -#define ADM9240_REG_EXTMODE1 0x4C /* LM81 only - not supported */ -#define ADM9240_REG_EXTMODE2 0x4D /* LM81 only - not supported */ +#define ADM9240_REG_EXTMODE1 0x4C /* LM81 only - not supported */ +#define ADM9240_REG_EXTMODE2 0x4D /* LM81 only - not supported */ /* Conversions. Rounding and limit checking is only done on the TO_REG variants. Note that you should be a bit careful with which arguments @@ -146,10 +146,11 @@ SENSORS_INSMOD_3(adm9240,ds1780,lm81); extern inline u8 FAN_TO_REG(long rpm, int div) { - if (rpm == 0) - return 255; - rpm = SENSORS_LIMIT(rpm,1,1000000); - return SENSORS_LIMIT((1350000 + rpm*div/2) / (rpm*div),1,254); + if (rpm == 0) + return 255; + rpm = SENSORS_LIMIT(rpm, 1, 1000000); + return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, + 254); } #define FAN_FROM_REG(val,div) ((val)==0?-1:\ @@ -165,7 +166,7 @@ extern inline u8 FAN_TO_REG(long rpm, int div) ((val)+5)/10), \ 0,255) -#define ALARMS_FROM_REG(val) (val) +#define ALARMS_FROM_REG(val) (val) #define DIV_FROM_REG(val) (1 << (val)) #define DIV_TO_REG(val) ((val)==1?0:((val)==8?3:((val)==4?2:1))) @@ -184,29 +185,29 @@ extern inline u8 FAN_TO_REG(long rpm, int div) #define ADM9240_INIT_IN_PERCENTAGE 10 #define ADM9240_INIT_IN_MIN_0 \ - (ADM9240_INIT_IN_0 - ADM9240_INIT_IN_0 * ADM9240_INIT_IN_PERCENTAGE / 100) + (ADM9240_INIT_IN_0 - ADM9240_INIT_IN_0 * ADM9240_INIT_IN_PERCENTAGE / 100) #define ADM9240_INIT_IN_MAX_0 \ - (ADM9240_INIT_IN_0 + ADM9240_INIT_IN_0 * ADM9240_INIT_IN_PERCENTAGE / 100) + (ADM9240_INIT_IN_0 + ADM9240_INIT_IN_0 * ADM9240_INIT_IN_PERCENTAGE / 100) #define ADM9240_INIT_IN_MIN_1 \ - (ADM9240_INIT_IN_1 - ADM9240_INIT_IN_1 * ADM9240_INIT_IN_PERCENTAGE / 100) + (ADM9240_INIT_IN_1 - ADM9240_INIT_IN_1 * ADM9240_INIT_IN_PERCENTAGE / 100) #define ADM9240_INIT_IN_MAX_1 \ - (ADM9240_INIT_IN_1 + ADM9240_INIT_IN_1 * ADM9240_INIT_IN_PERCENTAGE / 100) + (ADM9240_INIT_IN_1 + ADM9240_INIT_IN_1 * ADM9240_INIT_IN_PERCENTAGE / 100) #define ADM9240_INIT_IN_MIN_2 \ - (ADM9240_INIT_IN_2 - ADM9240_INIT_IN_2 * ADM9240_INIT_IN_PERCENTAGE / 100) + (ADM9240_INIT_IN_2 - ADM9240_INIT_IN_2 * ADM9240_INIT_IN_PERCENTAGE / 100) #define ADM9240_INIT_IN_MAX_2 \ - (ADM9240_INIT_IN_2 + ADM9240_INIT_IN_2 * ADM9240_INIT_IN_PERCENTAGE / 100) + (ADM9240_INIT_IN_2 + ADM9240_INIT_IN_2 * ADM9240_INIT_IN_PERCENTAGE / 100) #define ADM9240_INIT_IN_MIN_3 \ - (ADM9240_INIT_IN_3 - ADM9240_INIT_IN_3 * ADM9240_INIT_IN_PERCENTAGE / 100) + (ADM9240_INIT_IN_3 - ADM9240_INIT_IN_3 * ADM9240_INIT_IN_PERCENTAGE / 100) #define ADM9240_INIT_IN_MAX_3 \ - (ADM9240_INIT_IN_3 + ADM9240_INIT_IN_3 * ADM9240_INIT_IN_PERCENTAGE / 100) + (ADM9240_INIT_IN_3 + ADM9240_INIT_IN_3 * ADM9240_INIT_IN_PERCENTAGE / 100) #define ADM9240_INIT_IN_MIN_4 \ - (ADM9240_INIT_IN_4 - ADM9240_INIT_IN_4 * ADM9240_INIT_IN_PERCENTAGE / 100) + (ADM9240_INIT_IN_4 - ADM9240_INIT_IN_4 * ADM9240_INIT_IN_PERCENTAGE / 100) #define ADM9240_INIT_IN_MAX_4 \ - (ADM9240_INIT_IN_4 + ADM9240_INIT_IN_4 * ADM9240_INIT_IN_PERCENTAGE / 100) + (ADM9240_INIT_IN_4 + ADM9240_INIT_IN_4 * ADM9240_INIT_IN_PERCENTAGE / 100) #define ADM9240_INIT_IN_MIN_5 \ - (ADM9240_INIT_IN_5 - ADM9240_INIT_IN_5 * ADM9240_INIT_IN_PERCENTAGE / 100) + (ADM9240_INIT_IN_5 - ADM9240_INIT_IN_5 * ADM9240_INIT_IN_PERCENTAGE / 100) #define ADM9240_INIT_IN_MAX_5 \ - (ADM9240_INIT_IN_5 + ADM9240_INIT_IN_5 * ADM9240_INIT_IN_PERCENTAGE / 100) + (ADM9240_INIT_IN_5 + ADM9240_INIT_IN_5 * ADM9240_INIT_IN_PERCENTAGE / 100) #define ADM9240_INIT_FAN_MIN_1 3000 #define ADM9240_INIT_FAN_MIN_2 3000 @@ -219,32 +220,32 @@ extern inline u8 FAN_TO_REG(long rpm, int div) #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ /* For each registered ADM9240, we need to keep some data in memory. That data is pointed to by adm9240_list[NR]->data. The structure itself is dynamically allocated, at the same time when a new adm9240 client is allocated. */ struct adm9240_data { - int sysctl_id; - enum chips type; + int sysctl_id; + enum chips type; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ - u8 in[6]; /* Register value */ - u8 in_max[6]; /* Register value */ - u8 in_min[6]; /* Register value */ - u8 fan[2]; /* Register value */ - u8 fan_min[2]; /* Register value */ - u8 fan_div[2]; /* Register encoding, shifted right */ - int temp; /* Temp, shifted right */ - u8 temp_os_max; /* Register value */ - u8 temp_os_hyst; /* Register value */ - u16 alarms; /* Register encoding, combined */ - u8 analog_out; /* Register value */ - u8 vid; /* Register value combined */ + u8 in[6]; /* Register value */ + u8 in_max[6]; /* Register value */ + u8 in_min[6]; /* Register value */ + u8 fan[2]; /* Register value */ + u8 fan_min[2]; /* Register value */ + u8 fan_div[2]; /* Register encoding, shifted right */ + int temp; /* Temp, shifted right */ + u8 temp_os_max; /* Register value */ + u8 temp_os_hyst; /* Register value */ + u16 alarms; /* Register encoding, combined */ + u8 analog_out; /* Register value */ + u8 vid; /* Register value combined */ }; @@ -253,38 +254,40 @@ static #else extern #endif - int __init sensors_adm9240_init(void); +int __init sensors_adm9240_init(void); static int __init adm9240_cleanup(void); static int adm9240_attach_adapter(struct i2c_adapter *adapter); -static int adm9240_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind); +static int adm9240_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); static int adm9240_detach_client(struct i2c_client *client); -static int adm9240_command(struct i2c_client *client, unsigned int cmd, - void *arg); -static void adm9240_inc_use (struct i2c_client *client); -static void adm9240_dec_use (struct i2c_client *client); +static int adm9240_command(struct i2c_client *client, unsigned int cmd, + void *arg); +static void adm9240_inc_use(struct i2c_client *client); +static void adm9240_dec_use(struct i2c_client *client); static int adm9240_read_value(struct i2c_client *client, u8 register); -static int adm9240_write_value(struct i2c_client *client, u8 register, u8 value); +static int adm9240_write_value(struct i2c_client *client, u8 register, + u8 value); static void adm9240_update_client(struct i2c_client *client); static void adm9240_init_client(struct i2c_client *client); -static void adm9240_in(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void adm9240_fan(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void adm9240_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void adm9240_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void adm9240_fan_div(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void adm9240_analog_out(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void adm9240_vid(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); +static void adm9240_in(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void adm9240_fan(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void adm9240_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void adm9240_alarms(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void adm9240_fan_div(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void adm9240_analog_out(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, + long *results); +static void adm9240_vid(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); /* I choose here for semi-static ADM9240 allocation. Complete dynamic allocation could also be used; the code needed for this would probably @@ -292,14 +295,14 @@ static void adm9240_vid(struct i2c_client *client, int operation, int ctl_name, static int adm9240_id = 0; static struct i2c_driver adm9240_driver = { - /* name */ "ADM9240 sensor driver", - /* id */ I2C_DRIVERID_ADM9240, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &adm9240_attach_adapter, - /* detach_client */ &adm9240_detach_client, - /* command */ &adm9240_command, - /* inc_use */ &adm9240_inc_use, - /* dec_use */ &adm9240_dec_use + /* name */ "ADM9240 sensor driver", + /* id */ I2C_DRIVERID_ADM9240, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &adm9240_attach_adapter, + /* detach_client */ &adm9240_detach_client, + /* command */ &adm9240_command, + /* inc_use */ &adm9240_inc_use, + /* dec_use */ &adm9240_dec_use }; /* Used by adm9240_init/cleanup */ @@ -312,279 +315,324 @@ static int __initdata adm9240_initialized = 0; is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table adm9240_dir_table_template[] = { - { ADM9240_SYSCTL_IN0, "2.5V", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm9240_in }, - { ADM9240_SYSCTL_IN1, "Vccp1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm9240_in }, - { ADM9240_SYSCTL_IN2, "3.3V", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm9240_in }, - { ADM9240_SYSCTL_IN3, "5V", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm9240_in }, - { ADM9240_SYSCTL_IN4, "12V", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm9240_in }, - { ADM9240_SYSCTL_IN5, "Vccp2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm9240_in }, - { ADM9240_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm9240_fan }, - { ADM9240_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm9240_fan }, - { ADM9240_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm9240_temp }, - { ADM9240_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm9240_fan_div }, - { ADM9240_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm9240_alarms }, - { ADM9240_SYSCTL_ANALOG_OUT, "analog_out", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm9240_analog_out }, - { ADM9240_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &adm9240_vid }, - { 0 } + {ADM9240_SYSCTL_IN0, "2.5V", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm9240_in}, + {ADM9240_SYSCTL_IN1, "Vccp1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm9240_in}, + {ADM9240_SYSCTL_IN2, "3.3V", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm9240_in}, + {ADM9240_SYSCTL_IN3, "5V", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm9240_in}, + {ADM9240_SYSCTL_IN4, "12V", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm9240_in}, + {ADM9240_SYSCTL_IN5, "Vccp2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm9240_in}, + {ADM9240_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm9240_fan}, + {ADM9240_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm9240_fan}, + {ADM9240_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm9240_temp}, + {ADM9240_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm9240_fan_div}, + {ADM9240_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm9240_alarms}, + {ADM9240_SYSCTL_ANALOG_OUT, "analog_out", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm9240_analog_out}, + {ADM9240_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &adm9240_vid}, + {0} }; int adm9240_attach_adapter(struct i2c_adapter *adapter) { - return sensors_detect(adapter,&addr_data,adm9240_detect); + return sensors_detect(adapter, &addr_data, adm9240_detect); } -static int adm9240_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind) +static int adm9240_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) { - int i; - struct i2c_client *new_client; - struct adm9240_data *data; - int err=0; - const char *type_name = ""; - const char *client_name = ""; + int i; + struct i2c_client *new_client; + struct adm9240_data *data; + int err = 0; + const char *type_name = ""; + const char *client_name = ""; - /* Make sure we aren't probing the ISA bus!! This is just a safety check - at this moment; sensors_detect really won't call us. */ + /* Make sure we aren't probing the ISA bus!! This is just a safety check + at this moment; sensors_detect really won't call us. */ #ifdef DEBUG - if (i2c_is_isa_adapter(adapter)) { - printk("adm9240.o: adm9240_detect called for an ISA bus adapter?!?\n"); - return 0; - } + if (i2c_is_isa_adapter(adapter)) { + printk + ("adm9240.o: adm9240_detect called for an ISA bus adapter?!?\n"); + return 0; + } #endif - if (!i2c_check_functionality(adapter,I2C_FUNC_SMBUS_BYTE_DATA)) - goto ERROR0; + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) + goto ERROR0; - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access adm9240_{read,write}_value. */ + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access adm9240_{read,write}_value. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct adm9240_data), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR0; - } + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct adm9240_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } - data = (struct adm9240_data *) (new_client + 1); - new_client->addr = address; - new_client->data = data; - new_client->adapter = adapter; - new_client->driver = &adm9240_driver; - new_client->flags = 0; + data = (struct adm9240_data *) (new_client + 1); + new_client->addr = address; + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &adm9240_driver; + new_client->flags = 0; - /* Now, we do the remaining detection. */ + /* Now, we do the remaining detection. */ - if (kind < 0) { - if (((adm9240_read_value(new_client,ADM9240_REG_CONFIG) & 0x80) != 0x00) || - (adm9240_read_value(new_client,ADM9240_REG_I2C_ADDR) != address)) - goto ERROR1; - } + if (kind < 0) { + if ( + ((adm9240_read_value + (new_client, ADM9240_REG_CONFIG) & 0x80) != 0x00) + || + (adm9240_read_value(new_client, ADM9240_REG_I2C_ADDR) + != address)) + goto ERROR1; + } - /* Determine the chip type. */ - if (kind <= 0) { - i = adm9240_read_value(new_client,ADM9240_REG_COMPANY_ID); - if (i == 0x23) - kind = adm9240; - else if (i == 0xda) - kind = ds1780; - else if (i == 0x01) - kind = lm81; - else { - if (kind == 0) - printk("adm9240.o: Ignoring 'force' parameter for unknown chip at " - "adapter %d, address 0x%02x\n",i2c_adapter_id(adapter),address); - goto ERROR1; - } - } + /* Determine the chip type. */ + if (kind <= 0) { + i = adm9240_read_value(new_client, ADM9240_REG_COMPANY_ID); + if (i == 0x23) + kind = adm9240; + else if (i == 0xda) + kind = ds1780; + else if (i == 0x01) + kind = lm81; + else { + if (kind == 0) + printk + ("adm9240.o: Ignoring 'force' parameter for unknown chip at " + "adapter %d, address 0x%02x\n", + i2c_adapter_id(adapter), address); + goto ERROR1; + } + } - if (kind == adm9240) { - type_name = "adm9240"; - client_name = "ADM9240 chip"; - } else if (kind == ds1780) { - type_name = "ds1780"; - client_name = "DS1780 chip"; - } else if (kind == lm81) { - type_name = "lm81"; - client_name = "LM81 chip"; - } else { + if (kind == adm9240) { + type_name = "adm9240"; + client_name = "ADM9240 chip"; + } else if (kind == ds1780) { + type_name = "ds1780"; + client_name = "DS1780 chip"; + } else if (kind == lm81) { + type_name = "lm81"; + client_name = "LM81 chip"; + } else { #ifdef DEBUG - printk("adm9240.o: Internal error: unknown kind (%d)?!?",kind); + printk("adm9240.o: Internal error: unknown kind (%d)?!?", + kind); #endif - goto ERROR1; - } + goto ERROR1; + } - /* Fill in the remaining client fields and put it into the global list */ - strcpy(new_client->name,client_name); - data->type = kind; + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); + data->type = kind; - new_client->id = adm9240_id ++; - data->valid = 0; - init_MUTEX(&data->update_lock); + new_client->id = adm9240_id++; + data->valid = 0; + init_MUTEX(&data->update_lock); - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; - /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry(new_client, - type_name, - adm9240_dir_table_template, - THIS_MODULE)) < 0) { - err = i; - goto ERROR4; - } - data->sysctl_id = i; + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry(new_client, + type_name, + adm9240_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; - /* Initialize the ADM9240 chip */ - adm9240_init_client(new_client); - return 0; + /* Initialize the ADM9240 chip */ + adm9240_init_client(new_client); + return 0; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR4: - i2c_detach_client(new_client); -ERROR3: -ERROR1: - kfree(new_client); -ERROR0: - return err; + ERROR4: + i2c_detach_client(new_client); + ERROR3: + ERROR1: + kfree(new_client); + ERROR0: + return err; } int adm9240_detach_client(struct i2c_client *client) { - int err; + int err; - sensors_deregister_entry(((struct adm9240_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct adm9240_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("adm9240.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("adm9240.o: Client deregistration failed, client not detached.\n"); + return err; + } - kfree(client); + kfree(client); - return 0; + return 0; } /* No commands defined yet */ int adm9240_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } -void adm9240_inc_use (struct i2c_client *client) +void adm9240_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } -void adm9240_dec_use (struct i2c_client *client) +void adm9240_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } - + int adm9240_read_value(struct i2c_client *client, u8 reg) { - return 0xFF & i2c_smbus_read_byte_data(client, reg); + return 0xFF & i2c_smbus_read_byte_data(client, reg); } int adm9240_write_value(struct i2c_client *client, u8 reg, u8 value) { - return i2c_smbus_write_byte_data(client, reg,value); + return i2c_smbus_write_byte_data(client, reg, value); } /* Called when we have found a new ADM9240. It should set limits, etc. */ void adm9240_init_client(struct i2c_client *client) { - /* Reset all except Watchdog values and last conversion values - This sets fan-divs to 2, among others. This makes most other - initializations unnecessary */ - adm9240_write_value(client,ADM9240_REG_CONFIG,0x80); + /* Reset all except Watchdog values and last conversion values + This sets fan-divs to 2, among others. This makes most other + initializations unnecessary */ + adm9240_write_value(client, ADM9240_REG_CONFIG, 0x80); - adm9240_write_value(client,ADM9240_REG_IN_MIN(0),IN_TO_REG(ADM9240_INIT_IN_MIN_0,0)); - adm9240_write_value(client,ADM9240_REG_IN_MAX(0),IN_TO_REG(ADM9240_INIT_IN_MAX_0,0)); - adm9240_write_value(client,ADM9240_REG_IN_MIN(1),IN_TO_REG(ADM9240_INIT_IN_MIN_1,1)); - adm9240_write_value(client,ADM9240_REG_IN_MAX(1),IN_TO_REG(ADM9240_INIT_IN_MAX_1,1)); - adm9240_write_value(client,ADM9240_REG_IN_MIN(2),IN_TO_REG(ADM9240_INIT_IN_MIN_2,2)); - adm9240_write_value(client,ADM9240_REG_IN_MAX(2),IN_TO_REG(ADM9240_INIT_IN_MAX_2,2)); - adm9240_write_value(client,ADM9240_REG_IN_MIN(3),IN_TO_REG(ADM9240_INIT_IN_MIN_3,3)); - adm9240_write_value(client,ADM9240_REG_IN_MAX(3),IN_TO_REG(ADM9240_INIT_IN_MAX_3,3)); - adm9240_write_value(client,ADM9240_REG_IN_MIN(4),IN_TO_REG(ADM9240_INIT_IN_MIN_4,4)); - adm9240_write_value(client,ADM9240_REG_IN_MAX(4),IN_TO_REG(ADM9240_INIT_IN_MAX_4,4)); - adm9240_write_value(client,ADM9240_REG_IN_MIN(5),IN_TO_REG(ADM9240_INIT_IN_MIN_5,5)); - adm9240_write_value(client,ADM9240_REG_IN_MAX(5),IN_TO_REG(ADM9240_INIT_IN_MAX_5,5)); - adm9240_write_value(client,ADM9240_REG_FAN1_MIN,FAN_TO_REG(ADM9240_INIT_FAN_MIN_1,2)); - adm9240_write_value(client,ADM9240_REG_FAN2_MIN,FAN_TO_REG(ADM9240_INIT_FAN_MIN_2,2)); - adm9240_write_value(client,ADM9240_REG_TOS, - TEMP_LIMIT_TO_REG(ADM9240_INIT_TEMP_OS_MAX)); - adm9240_write_value(client,ADM9240_REG_THYST, - TEMP_LIMIT_TO_REG(ADM9240_INIT_TEMP_OS_HYST)); - adm9240_write_value(client,ADM9240_REG_TEMP_CONFIG,0x00); + adm9240_write_value(client, ADM9240_REG_IN_MIN(0), + IN_TO_REG(ADM9240_INIT_IN_MIN_0, 0)); + adm9240_write_value(client, ADM9240_REG_IN_MAX(0), + IN_TO_REG(ADM9240_INIT_IN_MAX_0, 0)); + adm9240_write_value(client, ADM9240_REG_IN_MIN(1), + IN_TO_REG(ADM9240_INIT_IN_MIN_1, 1)); + adm9240_write_value(client, ADM9240_REG_IN_MAX(1), + IN_TO_REG(ADM9240_INIT_IN_MAX_1, 1)); + adm9240_write_value(client, ADM9240_REG_IN_MIN(2), + IN_TO_REG(ADM9240_INIT_IN_MIN_2, 2)); + adm9240_write_value(client, ADM9240_REG_IN_MAX(2), + IN_TO_REG(ADM9240_INIT_IN_MAX_2, 2)); + adm9240_write_value(client, ADM9240_REG_IN_MIN(3), + IN_TO_REG(ADM9240_INIT_IN_MIN_3, 3)); + adm9240_write_value(client, ADM9240_REG_IN_MAX(3), + IN_TO_REG(ADM9240_INIT_IN_MAX_3, 3)); + adm9240_write_value(client, ADM9240_REG_IN_MIN(4), + IN_TO_REG(ADM9240_INIT_IN_MIN_4, 4)); + adm9240_write_value(client, ADM9240_REG_IN_MAX(4), + IN_TO_REG(ADM9240_INIT_IN_MAX_4, 4)); + adm9240_write_value(client, ADM9240_REG_IN_MIN(5), + IN_TO_REG(ADM9240_INIT_IN_MIN_5, 5)); + adm9240_write_value(client, ADM9240_REG_IN_MAX(5), + IN_TO_REG(ADM9240_INIT_IN_MAX_5, 5)); + adm9240_write_value(client, ADM9240_REG_FAN1_MIN, + FAN_TO_REG(ADM9240_INIT_FAN_MIN_1, 2)); + adm9240_write_value(client, ADM9240_REG_FAN2_MIN, + FAN_TO_REG(ADM9240_INIT_FAN_MIN_2, 2)); + adm9240_write_value(client, ADM9240_REG_TOS, + TEMP_LIMIT_TO_REG(ADM9240_INIT_TEMP_OS_MAX)); + adm9240_write_value(client, ADM9240_REG_THYST, + TEMP_LIMIT_TO_REG(ADM9240_INIT_TEMP_OS_HYST)); + adm9240_write_value(client, ADM9240_REG_TEMP_CONFIG, 0x00); - /* Start monitoring */ - adm9240_write_value(client,ADM9240_REG_CONFIG,0x01); + /* Start monitoring */ + adm9240_write_value(client, ADM9240_REG_CONFIG, 0x01); } void adm9240_update_client(struct i2c_client *client) { - struct adm9240_data *data = client->data; - u8 i; + struct adm9240_data *data = client->data; + u8 i; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > (data->type == adm9240?HZ/2:HZ*2) ) || - (jiffies < data->last_updated) || ! data->valid) { + if ( + (jiffies - data->last_updated > + (data->type == adm9240 ? HZ / 2 : HZ * 2)) + || (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("Starting adm9240 update\n"); + printk("Starting adm9240 update\n"); #endif - for (i = 0; i <= 5; i++) { - data->in[i] = adm9240_read_value(client,ADM9240_REG_IN(i)); - data->in_min[i] = adm9240_read_value(client,ADM9240_REG_IN_MIN(i)); - data->in_max[i] = adm9240_read_value(client,ADM9240_REG_IN_MAX(i)); - } - data->fan[0] = adm9240_read_value(client,ADM9240_REG_FAN1); - data->fan_min[0] = adm9240_read_value(client,ADM9240_REG_FAN1_MIN); - data->fan[1] = adm9240_read_value(client,ADM9240_REG_FAN2); - data->fan_min[1] = adm9240_read_value(client,ADM9240_REG_FAN2_MIN); - data->temp = (adm9240_read_value(client,ADM9240_REG_TEMP) << 1) + - ((adm9240_read_value(client,ADM9240_REG_TEMP_CONFIG) & 0x80) >> 7); - data->temp_os_max = adm9240_read_value(client,ADM9240_REG_TOS); - data->temp_os_hyst = adm9240_read_value(client,ADM9240_REG_THYST); + for (i = 0; i <= 5; i++) { + data->in[i] = + adm9240_read_value(client, ADM9240_REG_IN(i)); + data->in_min[i] = + adm9240_read_value(client, + ADM9240_REG_IN_MIN(i)); + data->in_max[i] = + adm9240_read_value(client, + ADM9240_REG_IN_MAX(i)); + } + data->fan[0] = + adm9240_read_value(client, ADM9240_REG_FAN1); + data->fan_min[0] = + adm9240_read_value(client, ADM9240_REG_FAN1_MIN); + data->fan[1] = + adm9240_read_value(client, ADM9240_REG_FAN2); + data->fan_min[1] = + adm9240_read_value(client, ADM9240_REG_FAN2_MIN); + data->temp = + (adm9240_read_value(client, ADM9240_REG_TEMP) << 1) + + ((adm9240_read_value + (client, ADM9240_REG_TEMP_CONFIG) & 0x80) >> 7); + data->temp_os_max = + adm9240_read_value(client, ADM9240_REG_TOS); + data->temp_os_hyst = + adm9240_read_value(client, ADM9240_REG_THYST); - i = adm9240_read_value(client,ADM9240_REG_VID_FAN_DIV); - data->fan_div[0] = (i >> 4) & 0x03; - data->fan_div[1] = (i >> 6) & 0x03; - data->vid = i & 0x0f; - data->vid |= (adm9240_read_value(client,ADM9240_REG_VID4) & 0x01) << 4; + i = adm9240_read_value(client, ADM9240_REG_VID_FAN_DIV); + data->fan_div[0] = (i >> 4) & 0x03; + data->fan_div[1] = (i >> 6) & 0x03; + data->vid = i & 0x0f; + data->vid |= + (adm9240_read_value(client, ADM9240_REG_VID4) & 0x01) + << 4; - data->alarms = adm9240_read_value(client,ADM9240_REG_INT1_STAT) + - (adm9240_read_value(client,ADM9240_REG_INT2_STAT) << 8); - data->analog_out = adm9240_read_value(client,ADM9240_REG_ANALOG_OUT); - data->last_updated = jiffies; - data->valid = 1; - } + data->alarms = + adm9240_read_value(client, + ADM9240_REG_INT1_STAT) + + (adm9240_read_value(client, ADM9240_REG_INT2_STAT) << + 8); + data->analog_out = + adm9240_read_value(client, ADM9240_REG_ANALOG_OUT); + data->last_updated = jiffies; + data->valid = 1; + } - up(&data->update_lock); + up(&data->update_lock); } @@ -601,204 +649,225 @@ void adm9240_update_client(struct i2c_client *client) large enough (by checking the incoming value of *nrels). This is not very good practice, but as long as you put less than about 5 values in results, you can assume it is large enough. */ -void adm9240_in(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void adm9240_in(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - int scales[6]={250, 270, 330, 500, 1200, 270}; + int scales[6] = { 250, 270, 330, 500, 1200, 270 }; - struct adm9240_data *data = client->data; - int nr = ctl_name - ADM9240_SYSCTL_IN0; + struct adm9240_data *data = client->data; + int nr = ctl_name - ADM9240_SYSCTL_IN0; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 2; - else if (operation == SENSORS_PROC_REAL_READ) { - adm9240_update_client(client); - results[0] = IN_FROM_REG(data->in_min[nr],nr) * scales[nr] / 192; - results[1] = IN_FROM_REG(data->in_max[nr],nr) * scales[nr] / 192; - results[2] = IN_FROM_REG(data->in[nr],nr) * scales[nr] / 192; - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->in_min[nr] = IN_TO_REG((results[0]*192)/scales[nr],nr); - adm9240_write_value(client,ADM9240_REG_IN_MIN(nr),data->in_min[nr]); - } - if (*nrels_mag >= 2) { - data->in_max[nr] = IN_TO_REG((results[1]*192)/scales[nr],nr); - adm9240_write_value(client,ADM9240_REG_IN_MAX(nr),data->in_max[nr]); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + adm9240_update_client(client); + results[0] = + IN_FROM_REG(data->in_min[nr], nr) * scales[nr] / 192; + results[1] = + IN_FROM_REG(data->in_max[nr], nr) * scales[nr] / 192; + results[2] = + IN_FROM_REG(data->in[nr], nr) * scales[nr] / 192; + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->in_min[nr] = + IN_TO_REG((results[0] * 192) / scales[nr], nr); + adm9240_write_value(client, ADM9240_REG_IN_MIN(nr), + data->in_min[nr]); + } + if (*nrels_mag >= 2) { + data->in_max[nr] = + IN_TO_REG((results[1] * 192) / scales[nr], nr); + adm9240_write_value(client, ADM9240_REG_IN_MAX(nr), + data->in_max[nr]); + } + } } void adm9240_fan(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct adm9240_data *data = client->data; - int nr = ctl_name - ADM9240_SYSCTL_FAN1 + 1; + struct adm9240_data *data = client->data; + int nr = ctl_name - ADM9240_SYSCTL_FAN1 + 1; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - adm9240_update_client(client); - results[0] = FAN_FROM_REG(data->fan_min[nr-1], - DIV_FROM_REG(data->fan_div[nr-1])); - results[1] = FAN_FROM_REG(data->fan[nr-1], - DIV_FROM_REG(data->fan_div[nr-1])); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->fan_min[nr-1] = FAN_TO_REG(results[0], - DIV_FROM_REG(data->fan_div[nr-1])); - adm9240_write_value(client,nr==1?ADM9240_REG_FAN1_MIN:ADM9240_REG_FAN2_MIN, - data->fan_min[nr-1]); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + adm9240_update_client(client); + results[0] = FAN_FROM_REG(data->fan_min[nr - 1], + DIV_FROM_REG(data-> + fan_div[nr - 1])); + results[1] = + FAN_FROM_REG(data->fan[nr - 1], + DIV_FROM_REG(data->fan_div[nr - 1])); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->fan_min[nr - 1] = FAN_TO_REG(results[0], + DIV_FROM_REG + (data-> + fan_div[nr - + 1])); + adm9240_write_value(client, + nr == + 1 ? ADM9240_REG_FAN1_MIN : + ADM9240_REG_FAN2_MIN, + data->fan_min[nr - 1]); + } + } } void adm9240_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct adm9240_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 1; - else if (operation == SENSORS_PROC_REAL_READ) { - adm9240_update_client(client); - results[0] = TEMP_LIMIT_FROM_REG(data->temp_os_max); - results[1] = TEMP_LIMIT_FROM_REG(data->temp_os_hyst); - results[2] = TEMP_FROM_REG(data->temp); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->temp_os_max = TEMP_LIMIT_TO_REG(results[0]); - adm9240_write_value(client,ADM9240_REG_TOS,data->temp_os_max); - } - if (*nrels_mag >= 2) { - data->temp_os_hyst = TEMP_LIMIT_TO_REG(results[1]); - adm9240_write_value(client,ADM9240_REG_THYST,data->temp_os_hyst); - } - } + struct adm9240_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 1; + else if (operation == SENSORS_PROC_REAL_READ) { + adm9240_update_client(client); + results[0] = TEMP_LIMIT_FROM_REG(data->temp_os_max); + results[1] = TEMP_LIMIT_FROM_REG(data->temp_os_hyst); + results[2] = TEMP_FROM_REG(data->temp); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->temp_os_max = TEMP_LIMIT_TO_REG(results[0]); + adm9240_write_value(client, ADM9240_REG_TOS, + data->temp_os_max); + } + if (*nrels_mag >= 2) { + data->temp_os_hyst = TEMP_LIMIT_TO_REG(results[1]); + adm9240_write_value(client, ADM9240_REG_THYST, + data->temp_os_hyst); + } + } } void adm9240_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct adm9240_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - adm9240_update_client(client); - results[0] = ALARMS_FROM_REG(data->alarms); - *nrels_mag = 1; - } + struct adm9240_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + adm9240_update_client(client); + results[0] = ALARMS_FROM_REG(data->alarms); + *nrels_mag = 1; + } } -void adm9240_fan_div(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void adm9240_fan_div(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - struct adm9240_data *data = client->data; - int old; + struct adm9240_data *data = client->data; + int old; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - adm9240_update_client(client); - results[0] = DIV_FROM_REG(data->fan_div[0]); - results[1] = DIV_FROM_REG(data->fan_div[1]); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - old = adm9240_read_value(client,ADM9240_REG_VID_FAN_DIV); - if (*nrels_mag >= 2) { - data->fan_div[1] = DIV_TO_REG(results[1]); - old = (old & 0x3f) | (data->fan_div[1] << 6); - } - if (*nrels_mag >= 1) { - data->fan_div[0] = DIV_TO_REG(results[0]); - old = (old & 0xcf) | (data->fan_div[0] << 4); - adm9240_write_value(client,ADM9240_REG_VID_FAN_DIV,old); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + adm9240_update_client(client); + results[0] = DIV_FROM_REG(data->fan_div[0]); + results[1] = DIV_FROM_REG(data->fan_div[1]); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + old = adm9240_read_value(client, ADM9240_REG_VID_FAN_DIV); + if (*nrels_mag >= 2) { + data->fan_div[1] = DIV_TO_REG(results[1]); + old = (old & 0x3f) | (data->fan_div[1] << 6); + } + if (*nrels_mag >= 1) { + data->fan_div[0] = DIV_TO_REG(results[0]); + old = (old & 0xcf) | (data->fan_div[0] << 4); + adm9240_write_value(client, + ADM9240_REG_VID_FAN_DIV, old); + } + } } -void adm9240_analog_out(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void adm9240_analog_out(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - struct adm9240_data *data = client->data; + struct adm9240_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - adm9240_update_client(client); - results[0] = data->analog_out; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->analog_out = results[0]; - adm9240_write_value(client,ADM9240_REG_ANALOG_OUT,data->analog_out); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + adm9240_update_client(client); + results[0] = data->analog_out; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->analog_out = results[0]; + adm9240_write_value(client, ADM9240_REG_ANALOG_OUT, + data->analog_out); + } + } } void adm9240_vid(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct adm9240_data *data = client->data; - - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 2; - else if (operation == SENSORS_PROC_REAL_READ) { - adm9240_update_client(client); - results[0] = VID_FROM_REG(data->vid); - *nrels_mag = 1; - } + struct adm9240_data *data = client->data; + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + adm9240_update_client(client); + results[0] = VID_FROM_REG(data->vid); + *nrels_mag = 1; + } } int __init sensors_adm9240_init(void) { - int res; + int res; - printk("adm9240.o version %s (%s)\n",LM_VERSION,LM_DATE); - adm9240_initialized = 0; + printk("adm9240.o version %s (%s)\n", LM_VERSION, LM_DATE); + adm9240_initialized = 0; - if ((res =i2c_add_driver(&adm9240_driver))) { - printk("adm9240.o: Driver registration failed, module not inserted.\n"); - adm9240_cleanup(); - return res; - } - adm9240_initialized ++; - return 0; + if ((res = i2c_add_driver(&adm9240_driver))) { + printk + ("adm9240.o: Driver registration failed, module not inserted.\n"); + adm9240_cleanup(); + return res; + } + adm9240_initialized++; + return 0; } int __init adm9240_cleanup(void) { - int res; + int res; - if (adm9240_initialized >= 1) { - if ((res = i2c_del_driver(&adm9240_driver))) { - printk("adm9240.o: Driver deregistration failed, module not removed.\n"); - return res; - } - adm9240_initialized --; - } - return 0; + if (adm9240_initialized >= 1) { + if ((res = i2c_del_driver(&adm9240_driver))) { + printk + ("adm9240.o: Driver deregistration failed, module not removed.\n"); + return res; + } + adm9240_initialized--; + } + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard and Philip Edelbrock "); +MODULE_AUTHOR + ("Frodo Looijaard and Philip Edelbrock "); MODULE_DESCRIPTION("ADM9240 driver"); int init_module(void) { - return sensors_adm9240_init(); + return sensors_adm9240_init(); } int cleanup_module(void) { - return adm9240_cleanup(); + return adm9240_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/bt869.c b/kernel/chips/bt869.c index a0537b0a..e1547b74 100644 --- a/kernel/chips/bt869.c +++ b/kernel/chips/bt869.c @@ -40,12 +40,12 @@ /* Addresses to scan */ -static unsigned short normal_i2c[] = {SENSORS_I2C_END}; +static unsigned short normal_i2c[] = { SENSORS_I2C_END }; /* found only at 0x44 or 0x45 */ -static unsigned short normal_i2c_range[] = {0x44,0x45,SENSORS_I2C_END}; -static unsigned int normal_isa[] = {SENSORS_ISA_END}; -static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; +static unsigned short normal_i2c_range[] = { 0x44, 0x45, SENSORS_I2C_END }; +static unsigned int normal_isa[] = { SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; /* Insmod parameters */ SENSORS_INSMOD_1(bt869); @@ -59,76 +59,76 @@ SENSORS_INSMOD_1(bt869); variants. Note that you should be a bit careful with which arguments these macros are called: arguments may be evaluated more than once. Fixing this is just not worth it. */ - - /*none*/ + + /*none */ /* Initial values */ /*none*/ /* Each client has this additional data */ struct bt869_data { - int sysctl_id; + int sysctl_id; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ - u8 status[3]; /* Register values */ - u16 res[2]; /* Resolution XxY */ - u8 ntsc; /* 1=NTSC, 0=PAL */ - u8 half; /* go half res */ - u8 depth; /* screen depth */ - u8 colorbars; /* turn on/off colorbar calibration screen */ + u8 status[3]; /* Register values */ + u16 res[2]; /* Resolution XxY */ + u8 ntsc; /* 1=NTSC, 0=PAL */ + u8 half; /* go half res */ + u8 depth; /* screen depth */ + u8 colorbars; /* turn on/off colorbar calibration screen */ }; #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ #ifdef MODULE static #else extern #endif - int __init sensors_bt869_init(void); +int __init sensors_bt869_init(void); static int __init bt869_cleanup(void); static int bt869_attach_adapter(struct i2c_adapter *adapter); -static int bt869_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind); +static int bt869_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); static void bt869_init_client(struct i2c_client *client); static int bt869_detach_client(struct i2c_client *client); static int bt869_command(struct i2c_client *client, unsigned int cmd, - void *arg); -static void bt869_inc_use (struct i2c_client *client); -static void bt869_dec_use (struct i2c_client *client); + void *arg); +static void bt869_inc_use(struct i2c_client *client); +static void bt869_dec_use(struct i2c_client *client); static int bt869_read_value(struct i2c_client *client, u8 reg); static int bt869_write_value(struct i2c_client *client, u8 reg, u16 value); -static void bt869_status(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void bt869_ntsc(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void bt869_res(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void bt869_half(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void bt869_colorbars(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void bt869_depth(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); +static void bt869_status(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void bt869_ntsc(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void bt869_res(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void bt869_half(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void bt869_colorbars(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void bt869_depth(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static void bt869_update_client(struct i2c_client *client); /* This is the driver that will be inserted */ static struct i2c_driver bt869_driver = { - /* name */ "BT869 video-output chip driver", - /* id */ I2C_DRIVERID_BT869, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &bt869_attach_adapter, - /* detach_client */ &bt869_detach_client, - /* command */ &bt869_command, - /* inc_use */ &bt869_inc_use, - /* dec_use */ &bt869_dec_use + /* name */ "BT869 video-output chip driver", + /* id */ I2C_DRIVERID_BT869, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &bt869_attach_adapter, + /* detach_client */ &bt869_detach_client, + /* command */ &bt869_command, + /* inc_use */ &bt869_inc_use, + /* dec_use */ &bt869_dec_use }; /* These files are created for each detected bt869. This is just a template; @@ -137,19 +137,19 @@ static struct i2c_driver bt869_driver = { is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table bt869_dir_table_template[] = { - { BT869_SYSCTL_STATUS, "status", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &bt869_status }, - { BT869_SYSCTL_NTSC, "ntsc", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &bt869_ntsc }, - { BT869_SYSCTL_RES, "res", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &bt869_res }, - { BT869_SYSCTL_HALF, "half", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &bt869_half }, - { BT869_SYSCTL_COLORBARS, "colorbars", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &bt869_colorbars }, - { BT869_SYSCTL_DEPTH, "depth", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &bt869_depth }, - { 0 } + {BT869_SYSCTL_STATUS, "status", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &bt869_status}, + {BT869_SYSCTL_NTSC, "ntsc", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &bt869_ntsc}, + {BT869_SYSCTL_RES, "res", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &bt869_res}, + {BT869_SYSCTL_HALF, "half", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &bt869_half}, + {BT869_SYSCTL_COLORBARS, "colorbars", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &bt869_colorbars}, + {BT869_SYSCTL_DEPTH, "depth", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &bt869_depth}, + {0} }; /* Used by init/cleanup */ @@ -159,142 +159,146 @@ int bt869_id = 0; int bt869_attach_adapter(struct i2c_adapter *adapter) { - return sensors_detect(adapter,&addr_data,bt869_detect); + return sensors_detect(adapter, &addr_data, bt869_detect); } /* This function is called by sensors_detect */ -int bt869_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind) +int bt869_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) { - int i,cur; - struct i2c_client *new_client; - struct bt869_data *data; - int err=0; - const char *type_name,*client_name; + int i, cur; + struct i2c_client *new_client; + struct bt869_data *data; + int err = 0; + const char *type_name, *client_name; -printk("bt869.o: probing address %d .\n",address); - /* Make sure we aren't probing the ISA bus!! This is just a safety check - at this moment; sensors_detect really won't call us. */ + printk("bt869.o: probing address %d .\n", address); + /* Make sure we aren't probing the ISA bus!! This is just a safety check + at this moment; sensors_detect really won't call us. */ #ifdef DEBUG - if (i2c_is_isa_adapter(adapter)) { - printk("bt869.o: bt869_detect called for an ISA bus adapter?!?\n"); - return 0; - } + if (i2c_is_isa_adapter(adapter)) { + printk + ("bt869.o: bt869_detect called for an ISA bus adapter?!?\n"); + return 0; + } #endif - if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_READ_BYTE| - I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) - goto ERROR0; + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE | + I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) + goto ERROR0; - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access bt869_{read,write}_value. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct bt869_data), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR0; - } + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access bt869_{read,write}_value. */ + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct bt869_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } - data = (struct bt869_data *) (((struct i2c_client *) new_client) + 1); - new_client->addr = address; - new_client->data = data; - new_client->adapter = adapter; - new_client->driver = &bt869_driver; - new_client->flags = 0; + data = + (struct bt869_data *) (((struct i2c_client *) new_client) + 1); + new_client->addr = address; + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &bt869_driver; + new_client->flags = 0; - /* Now, we do the remaining detection. It is lousy. */ - i2c_smbus_write_byte_data(new_client,0xC4,0); /* set status bank 0 */ - cur = i2c_smbus_read_byte(new_client); - printk("bt869.o: address 0x%X testing-->0x%X\n",address,cur); - if ((cur & 0xE0) != 0x20) - goto ERROR1; - - /* Determine the chip type */ - kind = ((cur & 0x20)>>5); + /* Now, we do the remaining detection. It is lousy. */ + i2c_smbus_write_byte_data(new_client, 0xC4, 0); /* set status bank 0 */ + cur = i2c_smbus_read_byte(new_client); + printk("bt869.o: address 0x%X testing-->0x%X\n", address, cur); + if ((cur & 0xE0) != 0x20) + goto ERROR1; - if (kind) { - type_name = "bt869"; - client_name = "bt869 chip"; - printk("bt869.o: BT869 detected\n"); - } else { - type_name = "bt868"; - client_name = "bt868 chip"; - printk("bt869.o: BT868 detected\n"); - } - - /* Fill in the remaining client fields and put it into the global list */ - strcpy(new_client->name,client_name); + /* Determine the chip type */ + kind = ((cur & 0x20) >> 5); - new_client->id = bt869_id++; - data->valid = 0; - init_MUTEX(&data->update_lock); - - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + if (kind) { + type_name = "bt869"; + client_name = "bt869 chip"; + printk("bt869.o: BT869 detected\n"); + } else { + type_name = "bt868"; + client_name = "bt868 chip"; + printk("bt869.o: BT868 detected\n"); + } - /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry(new_client,type_name, - bt869_dir_table_template, - THIS_MODULE)) < 0) { - err = i; - goto ERROR4; - } - data->sysctl_id = i; + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); - bt869_init_client((struct i2c_client *) new_client); - return 0; + new_client->id = bt869_id++; + data->valid = 0; + init_MUTEX(&data->update_lock); + + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; + + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry(new_client, type_name, + bt869_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; + + bt869_init_client((struct i2c_client *) new_client); + return 0; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR4: - i2c_detach_client(new_client); -ERROR3: -ERROR1: - kfree(new_client); -ERROR0: - return err; + ERROR4: + i2c_detach_client(new_client); + ERROR3: + ERROR1: + kfree(new_client); + ERROR0: + return err; } int bt869_detach_client(struct i2c_client *client) { - int err; + int err; - sensors_deregister_entry(((struct bt869_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct bt869_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("bt869.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("bt869.o: Client deregistration failed, client not detached.\n"); + return err; + } - kfree(client); + kfree(client); - return 0; + return 0; } /* No commands defined yet */ int bt869_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } /* Nothing here yet */ -void bt869_inc_use (struct i2c_client *client) +void bt869_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } /* Nothing here yet */ -void bt869_dec_use (struct i2c_client *client) +void bt869_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } @@ -303,7 +307,7 @@ void bt869_dec_use (struct i2c_client *client) the usual practice. */ int bt869_read_value(struct i2c_client *client, u8 reg) { - return i2c_smbus_read_byte(client); + return i2c_smbus_read_byte(client); } /* All registers are byte-sized. @@ -311,249 +315,261 @@ int bt869_read_value(struct i2c_client *client, u8 reg) the usual practice. */ int bt869_write_value(struct i2c_client *client, u8 reg, u16 value) { - return i2c_smbus_write_byte_data(client,reg,value); + return i2c_smbus_write_byte_data(client, reg, value); } void bt869_init_client(struct i2c_client *client) { - struct bt869_data *data = client->data; - - /* Initialize the bt869 chip */ - bt869_write_value(client,0x0ba,0x80); - // bt869_write_value(client,0x0D6, 0x00); - /* Be a slave to the clock on the Voodoo3 */ - bt869_write_value(client,0xa0,0x80); - bt869_write_value(client,0xba,0x20); - /* depth =16bpp */ - bt869_write_value(client,0x0C6, 0x001); - bt869_write_value(client,0xC4,1); - /* Flicker free enable and config */ - bt869_write_value(client,0xC8,0); - data->res[0]=640; - data->res[1]=480; - data->ntsc=1; - data->half=0; - data->colorbars=0; - data->depth=16; - + struct bt869_data *data = client->data; + + /* Initialize the bt869 chip */ + bt869_write_value(client, 0x0ba, 0x80); + // bt869_write_value(client,0x0D6, 0x00); + /* Be a slave to the clock on the Voodoo3 */ + bt869_write_value(client, 0xa0, 0x80); + bt869_write_value(client, 0xba, 0x20); + /* depth =16bpp */ + bt869_write_value(client, 0x0C6, 0x001); + bt869_write_value(client, 0xC4, 1); + /* Flicker free enable and config */ + bt869_write_value(client, 0xC8, 0); + data->res[0] = 640; + data->res[1] = 480; + data->ntsc = 1; + data->half = 0; + data->colorbars = 0; + data->depth = 16; + } void bt869_update_client(struct i2c_client *client) { - struct bt869_data *data = client->data; + struct bt869_data *data = client->data; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > HZ+HZ/2 ) || - (jiffies < data->last_updated) || ! data->valid) { + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("Starting bt869 update\n"); + printk("Starting bt869 update\n"); #endif /* Set values of device */ - if ((data->res[0] == 640) && (data->res[1] == 480)) { - bt869_write_value(client,0xB8,(! data->ntsc)); - bt869_write_value(client,0xa0,0x80 + 0x0C); - printk("bt869.o: writing into config -->0x%X\n",(0 + (! data->ntsc))); - } else if ((data->res[0] == 800) && (data->res[1] == 600)) { - bt869_write_value(client,0xB8,(2 + (! data->ntsc))); - bt869_write_value(client,0xa0,0x80 + 0x11); - printk("bt869.o: writing into config -->0x%X\n",(2 + (! data->ntsc))); - } else { - bt869_write_value(client,0xB8,(! data->ntsc)); - bt869_write_value(client,0xa0,0x80 + 0x0C); - printk("bt869.o: writing into config -->0x%X\n",(0 + (! data->ntsc))); - printk("bt869.o: Warning: arbitrary resolutions not supported yet. Using 640x480.\n"); - data->res[0] = 640; - data->res[1] = 480; - } - if ((data->depth!=24) && (data->depth!=16)) - data->depth=16; - if (data->depth==16) - bt869_write_value(client,0x0C6, 0x001); - if (data->depth==24) - bt869_write_value(client,0x0C6, 0x000); - bt869_write_value(client,0xD4,data->half<<6); - /* Be a slave to the clock on the Voodoo3 */ - bt869_write_value(client,0xba,0x20); - /* depth =16bpp */ - bt869_write_value(client,0x0C6, 0x001); - bt869_write_value(client,0xC4,1); + if ((data->res[0] == 640) && (data->res[1] == 480)) { + bt869_write_value(client, 0xB8, (!data->ntsc)); + bt869_write_value(client, 0xa0, 0x80 + 0x0C); + printk("bt869.o: writing into config -->0x%X\n", + (0 + (!data->ntsc))); + } else if ((data->res[0] == 800) && (data->res[1] == 600)) { + bt869_write_value(client, 0xB8, + (2 + (!data->ntsc))); + bt869_write_value(client, 0xa0, 0x80 + 0x11); + printk("bt869.o: writing into config -->0x%X\n", + (2 + (!data->ntsc))); + } else { + bt869_write_value(client, 0xB8, (!data->ntsc)); + bt869_write_value(client, 0xa0, 0x80 + 0x0C); + printk("bt869.o: writing into config -->0x%X\n", + (0 + (!data->ntsc))); + printk + ("bt869.o: Warning: arbitrary resolutions not supported yet. Using 640x480.\n"); + data->res[0] = 640; + data->res[1] = 480; + } + if ((data->depth != 24) && (data->depth != 16)) + data->depth = 16; + if (data->depth == 16) + bt869_write_value(client, 0x0C6, 0x001); + if (data->depth == 24) + bt869_write_value(client, 0x0C6, 0x000); + bt869_write_value(client, 0xD4, data->half << 6); + /* Be a slave to the clock on the Voodoo3 */ + bt869_write_value(client, 0xba, 0x20); + /* depth =16bpp */ + bt869_write_value(client, 0x0C6, 0x001); + bt869_write_value(client, 0xC4, 1); /* Get status */ - bt869_write_value(client,0xC4,1 | (data->colorbars << 2)); - data->status[0] = bt869_read_value(client,1); - bt869_write_value(client,0xC4,0x41 | (data->colorbars << 2)); - data->status[1] = bt869_read_value(client,1); - bt869_write_value(client,0xC4,0x81 | (data->colorbars << 2)); - data->status[2] = bt869_read_value(client,1); - bt869_write_value(client,0xC4,0x0C1 | (data->colorbars << 2)); - data->last_updated = jiffies; - data->valid = 1; - } - up(&data->update_lock); + bt869_write_value(client, 0xC4, + 1 | (data->colorbars << 2)); + data->status[0] = bt869_read_value(client, 1); + bt869_write_value(client, 0xC4, + 0x41 | (data->colorbars << 2)); + data->status[1] = bt869_read_value(client, 1); + bt869_write_value(client, 0xC4, + 0x81 | (data->colorbars << 2)); + data->status[2] = bt869_read_value(client, 1); + bt869_write_value(client, 0xC4, + 0x0C1 | (data->colorbars << 2)); + data->last_updated = jiffies; + data->valid = 1; + } + up(&data->update_lock); } void bt869_status(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct bt869_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - bt869_update_client(client); - results[0] = data->status[0]; - results[1] = data->status[1]; - results[2] = data->status[2]; - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - printk("bt869.o: Warning: write was requested on read-only proc file: status\n"); - } + struct bt869_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + bt869_update_client(client); + results[0] = data->status[0]; + results[1] = data->status[1]; + results[2] = data->status[2]; + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + printk + ("bt869.o: Warning: write was requested on read-only proc file: status\n"); + } } void bt869_ntsc(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct bt869_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - bt869_update_client(client); - results[0] = data->ntsc; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->ntsc = (results[0] > 0); - } - bt869_update_client(client); - } + struct bt869_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + bt869_update_client(client); + results[0] = data->ntsc; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->ntsc = (results[0] > 0); + } + bt869_update_client(client); + } } void bt869_res(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct bt869_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - bt869_update_client(client); - results[0] = data->res[0]; - results[1] = data->res[1]; - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->res[0] = results[0]; - } - if (*nrels_mag >= 2) { - data->res[1] = results[1]; - } - bt869_update_client(client); - } + struct bt869_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + bt869_update_client(client); + results[0] = data->res[0]; + results[1] = data->res[1]; + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->res[0] = results[0]; + } + if (*nrels_mag >= 2) { + data->res[1] = results[1]; + } + bt869_update_client(client); + } } void bt869_half(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct bt869_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - bt869_update_client(client); - results[0] = data->half; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->half = (results[0] > 0); - bt869_update_client(client); - } - } + struct bt869_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + bt869_update_client(client); + results[0] = data->half; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->half = (results[0] > 0); + bt869_update_client(client); + } + } } -void bt869_colorbars(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void bt869_colorbars(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - struct bt869_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - bt869_update_client(client); - results[0] = data->colorbars; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->colorbars = (results[0] > 0); - bt869_update_client(client); - } - } + struct bt869_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + bt869_update_client(client); + results[0] = data->colorbars; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->colorbars = (results[0] > 0); + bt869_update_client(client); + } + } } void bt869_depth(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct bt869_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - bt869_update_client(client); - results[0] = data->depth; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->depth = results[0]; - bt869_update_client(client); - } - } + struct bt869_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + bt869_update_client(client); + results[0] = data->depth; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->depth = results[0]; + bt869_update_client(client); + } + } } int __init sensors_bt869_init(void) { - int res; + int res; - printk("bt869.o version %s (%s)\n",LM_VERSION,LM_DATE); - bt869_initialized = 0; - if ((res = i2c_add_driver(&bt869_driver))) { - printk("bt869.o: Driver registration failed, module not inserted.\n"); - bt869_cleanup(); - return res; - } - bt869_initialized ++; - return 0; + printk("bt869.o version %s (%s)\n", LM_VERSION, LM_DATE); + bt869_initialized = 0; + if ((res = i2c_add_driver(&bt869_driver))) { + printk + ("bt869.o: Driver registration failed, module not inserted.\n"); + bt869_cleanup(); + return res; + } + bt869_initialized++; + return 0; } int __init bt869_cleanup(void) { - int res; + int res; - if (bt869_initialized >= 1) { - if ((res = i2c_del_driver(&bt869_driver))) { - printk("bt869.o: Driver deregistration failed, module not removed.\n"); - return res; - } - bt869_initialized --; - } + if (bt869_initialized >= 1) { + if ((res = i2c_del_driver(&bt869_driver))) { + printk + ("bt869.o: Driver deregistration failed, module not removed.\n"); + return res; + } + bt869_initialized--; + } - return 0; + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard and Philip Edelbrock "); +MODULE_AUTHOR + ("Frodo Looijaard and Philip Edelbrock "); MODULE_DESCRIPTION("bt869 driver"); int init_module(void) { - return sensors_bt869_init(); + return sensors_bt869_init(); } int cleanup_module(void) { - return bt869_cleanup(); + return bt869_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/eeprom.c b/kernel/chips/eeprom.c index 4eda3091..8400fe12 100644 --- a/kernel/chips/eeprom.c +++ b/kernel/chips/eeprom.c @@ -38,17 +38,18 @@ #endif /* Addresses to scan */ -static unsigned short normal_i2c[] = {SENSORS_I2C_END}; -static unsigned short normal_i2c_range[] = {0x50,0x57,SENSORS_I2C_END}; -static unsigned int normal_isa[] = {SENSORS_ISA_END}; -static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; +static unsigned short normal_i2c[] = { SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { 0x50, 0x57, SENSORS_I2C_END }; +static unsigned int normal_isa[] = { SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; /* Insmod parameters */ SENSORS_INSMOD_1(eeprom); static int checksum = 0; -MODULE_PARM(checksum,"i"); -MODULE_PARM_DESC(checksum,"Only accept eeproms whose checksum is correct"); +MODULE_PARM(checksum, "i"); +MODULE_PARM_DESC(checksum, + "Only accept eeproms whose checksum is correct"); /* Many constants specified below */ @@ -69,58 +70,59 @@ MODULE_PARM_DESC(checksum,"Only accept eeproms whose checksum is correct"); /* Each client has this additional data */ struct eeprom_data { - int sysctl_id; + int sysctl_id; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ - u8 data[EEPROM_SIZE]; /* Register values */ - int memtype; + u8 data[EEPROM_SIZE]; /* Register values */ + int memtype; }; #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ #ifdef MODULE static #else extern #endif - int __init sensors_eeprom_init(void); +int __init sensors_eeprom_init(void); static int __init eeprom_cleanup(void); static int eeprom_attach_adapter(struct i2c_adapter *adapter); -static int eeprom_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind); +static int eeprom_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); static int eeprom_detach_client(struct i2c_client *client); static int eeprom_command(struct i2c_client *client, unsigned int cmd, - void *arg); - -static void eeprom_inc_use (struct i2c_client *client); -static void eeprom_dec_use (struct i2c_client *client); + void *arg); + +static void eeprom_inc_use(struct i2c_client *client); +static void eeprom_dec_use(struct i2c_client *client); #if 0 -static int eeprom_write_value(struct i2c_client *client, u8 reg, u16 value); +static int eeprom_write_value(struct i2c_client *client, u8 reg, + u16 value); #endif -static void eeprom_contents(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); +static void eeprom_contents(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static void eeprom_update_client(struct i2c_client *client); /* This is the driver that will be inserted */ static struct i2c_driver eeprom_driver = { - /* name */ "EEPROM READER", - /* id */ I2C_DRIVERID_EEPROM, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &eeprom_attach_adapter, - /* detach_client */ &eeprom_detach_client, - /* command */ &eeprom_command, - /* inc_use */ &eeprom_inc_use, - /* dec_use */ &eeprom_dec_use + /* name */ "EEPROM READER", + /* id */ I2C_DRIVERID_EEPROM, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &eeprom_attach_adapter, + /* detach_client */ &eeprom_detach_client, + /* command */ &eeprom_command, + /* inc_use */ &eeprom_inc_use, + /* dec_use */ &eeprom_dec_use }; /* These files are created for each detected EEPROM. This is just a template; @@ -129,23 +131,23 @@ static struct i2c_driver eeprom_driver = { is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table eeprom_dir_table_template[] = { - { EEPROM_SYSCTL1, "data0-15", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &eeprom_contents }, - { EEPROM_SYSCTL2, "data16-31", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &eeprom_contents }, - { EEPROM_SYSCTL3, "data32-47", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &eeprom_contents }, - { EEPROM_SYSCTL4, "data48-63", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &eeprom_contents }, - { EEPROM_SYSCTL5, "data64-79", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &eeprom_contents }, - { EEPROM_SYSCTL6, "data80-95", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &eeprom_contents }, - { EEPROM_SYSCTL7, "data96-111", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &eeprom_contents }, - { EEPROM_SYSCTL8, "data112-127", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &eeprom_contents }, - { 0 } + {EEPROM_SYSCTL1, "data0-15", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &eeprom_contents}, + {EEPROM_SYSCTL2, "data16-31", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &eeprom_contents}, + {EEPROM_SYSCTL3, "data32-47", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &eeprom_contents}, + {EEPROM_SYSCTL4, "data48-63", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &eeprom_contents}, + {EEPROM_SYSCTL5, "data64-79", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &eeprom_contents}, + {EEPROM_SYSCTL6, "data80-95", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &eeprom_contents}, + {EEPROM_SYSCTL7, "data96-111", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &eeprom_contents}, + {EEPROM_SYSCTL8, "data112-127", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &eeprom_contents}, + {0} }; /* Used by init/cleanup */ @@ -155,142 +157,147 @@ static int eeprom_id = 0; int eeprom_attach_adapter(struct i2c_adapter *adapter) { - return sensors_detect(adapter,&addr_data,eeprom_detect); + return sensors_detect(adapter, &addr_data, eeprom_detect); } /* This function is called by sensors_detect */ -int eeprom_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind) +int eeprom_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) { - int i,cs; - struct i2c_client *new_client; - struct eeprom_data *data; - int err=0; - const char *type_name,*client_name; + int i, cs; + struct i2c_client *new_client; + struct eeprom_data *data; + int err = 0; + const char *type_name, *client_name; - /* Make sure we aren't probing the ISA bus!! This is just a safety check - at this moment; sensors_detect really won't call us. */ + /* Make sure we aren't probing the ISA bus!! This is just a safety check + at this moment; sensors_detect really won't call us. */ #ifdef DEBUG - if (i2c_is_isa_adapter(adapter)) { - printk("eeprom.o: eeprom_detect called for an ISA bus adapter?!?\n"); - return 0; - } + if (i2c_is_isa_adapter(adapter)) { + printk + ("eeprom.o: eeprom_detect called for an ISA bus adapter?!?\n"); + return 0; + } #endif - if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_BYTE_DATA | - I2C_FUNC_SMBUS_WRITE_WORD_DATA)) - goto ERROR0; + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_SMBUS_WRITE_WORD_DATA)) + goto ERROR0; - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access eeprom_{read,write}_value. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct eeprom_data), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR0; - } + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access eeprom_{read,write}_value. */ + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct eeprom_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } - data = (struct eeprom_data *) (new_client + 1); - new_client->addr = address; - new_client->data = data; - new_client->adapter = adapter; - new_client->driver = &eeprom_driver; - new_client->flags = 0; + data = (struct eeprom_data *) (new_client + 1); + new_client->addr = address; + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &eeprom_driver; + new_client->flags = 0; - /* Now, we do the remaining detection. It is not there, unless you force - the checksum to work out. */ - if (checksum) { - cs = 0; - for (i = 0; i <= 0x3e; i++) - cs += i2c_smbus_read_byte_data(new_client,i); - cs &= 0xff; - if (i2c_smbus_read_byte_data(new_client,EEPROM_REG_CHECKSUM) != cs) - goto ERROR1; - } - - /* Determine the chip type - only one kind supported! */ - if (kind <= 0) - kind = eeprom; + /* Now, we do the remaining detection. It is not there, unless you force + the checksum to work out. */ + if (checksum) { + cs = 0; + for (i = 0; i <= 0x3e; i++) + cs += i2c_smbus_read_byte_data(new_client, i); + cs &= 0xff; + if (i2c_smbus_read_byte_data + (new_client, EEPROM_REG_CHECKSUM) != cs) + goto ERROR1; + } - if (kind == eeprom) { - type_name = "eeprom"; - client_name = "EEPROM chip"; - } else { + /* Determine the chip type - only one kind supported! */ + if (kind <= 0) + kind = eeprom; + + if (kind == eeprom) { + type_name = "eeprom"; + client_name = "EEPROM chip"; + } else { #ifdef DEBUG - printk("eeprom.o: Internal error: unknown kind (%d)?!?",kind); + printk("eeprom.o: Internal error: unknown kind (%d)?!?", + kind); #endif - goto ERROR1; - } + goto ERROR1; + } - /* Fill in the remaining client fields and put it into the global list */ - strcpy(new_client->name,client_name); + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); - new_client->id = eeprom_id++; - data->valid = 0; - init_MUTEX(&data->update_lock); + new_client->id = eeprom_id++; + data->valid = 0; + init_MUTEX(&data->update_lock); - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; - /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry(new_client,type_name, - eeprom_dir_table_template, - THIS_MODULE)) < 0) { - err = i; - goto ERROR4; - } - data->sysctl_id = i; + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry(new_client, type_name, + eeprom_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; - return 0; + return 0; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR4: - i2c_detach_client(new_client); -ERROR3: -ERROR1: - kfree(new_client); -ERROR0: - return err; + ERROR4: + i2c_detach_client(new_client); + ERROR3: + ERROR1: + kfree(new_client); + ERROR0: + return err; } int eeprom_detach_client(struct i2c_client *client) { - int err; + int err; - sensors_deregister_entry(((struct eeprom_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct eeprom_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("eeprom.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("eeprom.o: Client deregistration failed, client not detached.\n"); + return err; + } - kfree(client); + kfree(client); - return 0; + return 0; } /* No commands defined yet */ int eeprom_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } -void eeprom_inc_use (struct i2c_client *client) +void eeprom_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } -void eeprom_dec_use (struct i2c_client *client) +void eeprom_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } @@ -298,129 +305,145 @@ void eeprom_dec_use (struct i2c_client *client) /* No writes yet (PAE) */ int eeprom_write_value(struct i2c_client *client, u8 reg, u16 value) { - if (reg == EEPROM_REG_CONF) - return i2c_smbus_write_byte_data(client,reg,value); - else - return i2c_smbus_write_word_data(client,reg,value); */ - - return 0; + if (reg == EEPROM_REG_CONF) + return i2c_smbus_write_byte_data(client, reg, value); + else + return i2c_smbus_write_word_data(client, reg, value); + */return 0; } #endif void eeprom_update_client(struct i2c_client *client) { - struct eeprom_data *data = client->data; - int i; + struct eeprom_data *data = client->data; + int i; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > HZ+HZ/2 ) || - (jiffies < data->last_updated) || ! data->valid) { + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("Starting eeprom update\n"); + printk("Starting eeprom update\n"); #endif - if (i2c_smbus_write_byte(client,0)) { + if (i2c_smbus_write_byte(client, 0)) { #ifdef DEBUG - printk("eeprom read start has failed!\n"); -#endif - } - for (i=0;idata[i] = (u8)i2c_smbus_read_byte(client); - } - - data->last_updated = jiffies; - data->valid = 1; - } + printk("eeprom read start has failed!\n"); +#endif + } + for (i = 0; i < EEPROM_SIZE; i++) { + data->data[i] = (u8) i2c_smbus_read_byte(client); + } - up(&data->update_lock); + data->last_updated = jiffies; + data->valid = 1; + } + + up(&data->update_lock); } -void eeprom_contents(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void eeprom_contents(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - int i; - int base=0; - struct eeprom_data *data = client->data; - - if (ctl_name == EEPROM_SYSCTL2){ base=16; } - if (ctl_name == EEPROM_SYSCTL3){ base=32; } - if (ctl_name == EEPROM_SYSCTL4){ base=48; } - if (ctl_name == EEPROM_SYSCTL5){ base=64; } - if (ctl_name == EEPROM_SYSCTL6){ base=80; } - if (ctl_name == EEPROM_SYSCTL7){ base=96; } - if (ctl_name == EEPROM_SYSCTL8){ base=112; } - - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - eeprom_update_client(client); - for (i=0; i<16; i++) { - results[i]=data->data[i + base]; - } + int i; + int base = 0; + struct eeprom_data *data = client->data; + + if (ctl_name == EEPROM_SYSCTL2) { + base = 16; + } + if (ctl_name == EEPROM_SYSCTL3) { + base = 32; + } + if (ctl_name == EEPROM_SYSCTL4) { + base = 48; + } + if (ctl_name == EEPROM_SYSCTL5) { + base = 64; + } + if (ctl_name == EEPROM_SYSCTL6) { + base = 80; + } + if (ctl_name == EEPROM_SYSCTL7) { + base = 96; + } + if (ctl_name == EEPROM_SYSCTL8) { + base = 112; + } + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + eeprom_update_client(client); + for (i = 0; i < 16; i++) { + results[i] = data->data[i + base]; + } #ifdef DEBUG - printk("eeprom.o: 0x%X EEPROM Contents (base %d): ",client->addr,base); - for (i=0; i<16; i++) { - printk(" 0x%X",data->data[i + base]); - } - printk(" .\n"); + printk("eeprom.o: 0x%X EEPROM Contents (base %d): ", + client->addr, base); + for (i = 0; i < 16; i++) { + printk(" 0x%X", data->data[i + base]); + } + printk(" .\n"); #endif - *nrels_mag = 16; - } else if (operation == SENSORS_PROC_REAL_WRITE) { + *nrels_mag = 16; + } else if (operation == SENSORS_PROC_REAL_WRITE) { /* No writes to the EEPROM (yet, anyway) (PAE) */ - printk("eeprom.o: No writes to EEPROMs supported!\n"); - } + printk("eeprom.o: No writes to EEPROMs supported!\n"); + } } int __init sensors_eeprom_init(void) { - int res; + int res; - printk("eeprom.o version %s (%s)\n",LM_VERSION,LM_DATE); - eeprom_initialized = 0; - if ((res = i2c_add_driver(&eeprom_driver))) { - printk("eeprom.o: Driver registration failed, module not inserted.\n"); - eeprom_cleanup(); - return res; - } - eeprom_initialized ++; - return 0; + printk("eeprom.o version %s (%s)\n", LM_VERSION, LM_DATE); + eeprom_initialized = 0; + if ((res = i2c_add_driver(&eeprom_driver))) { + printk + ("eeprom.o: Driver registration failed, module not inserted.\n"); + eeprom_cleanup(); + return res; + } + eeprom_initialized++; + return 0; } int __init eeprom_cleanup(void) { - int res; + int res; - if (eeprom_initialized >= 1) { - if ((res = i2c_del_driver(&eeprom_driver))) { - printk("eeprom.o: Driver deregistration failed, module not removed.\n"); - return res; - } - } else - eeprom_initialized --; + if (eeprom_initialized >= 1) { + if ((res = i2c_del_driver(&eeprom_driver))) { + printk + ("eeprom.o: Driver deregistration failed, module not removed.\n"); + return res; + } + } else + eeprom_initialized--; - return 0; + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard and Philip Edelbrock "); +MODULE_AUTHOR + ("Frodo Looijaard and Philip Edelbrock "); MODULE_DESCRIPTION("EEPROM driver"); int init_module(void) { - return sensors_eeprom_init(); + return sensors_eeprom_init(); } int cleanup_module(void) { - return eeprom_cleanup(); + return eeprom_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/gl518sm.c b/kernel/chips/gl518sm.c index f7324df1..97a63278 100644 --- a/kernel/chips/gl518sm.c +++ b/kernel/chips/gl518sm.c @@ -43,13 +43,13 @@ #endif /* Addresses to scan */ -static unsigned short normal_i2c[] = {0x2c,0x2d,SENSORS_I2C_END}; -static unsigned short normal_i2c_range[] = {SENSORS_I2C_END}; -static unsigned int normal_isa[] = {SENSORS_ISA_END}; -static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; +static unsigned short normal_i2c[] = { 0x2c, 0x2d, SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { SENSORS_I2C_END }; +static unsigned int normal_isa[] = { SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_2(gl518sm_r00,gl518sm_r80); +SENSORS_INSMOD_2(gl518sm_r00, gl518sm_r80); /* Defining this will enable debug messages for the voltage iteration code used with rev 0 ICs */ @@ -92,10 +92,11 @@ SENSORS_INSMOD_2(gl518sm_r00,gl518sm_r80); extern inline u8 FAN_TO_REG(long rpm, int div) { - if (rpm == 0) - return 255; - rpm = SENSORS_LIMIT(rpm,1,1000000); - return SENSORS_LIMIT((960000 + rpm*div/2) / (rpm*div),1,254); + if (rpm == 0) + return 255; + rpm = SENSORS_LIMIT(rpm, 1, 1000000); + return SENSORS_LIMIT((960000 + rpm * div / 2) / (rpm * div), 1, + 254); } #define FAN_FROM_REG(val,div) \ @@ -133,80 +134,80 @@ extern inline u8 FAN_TO_REG(long rpm, int div) #define GL518_INIT_PERCENTAGE 10 #define GL518_INIT_VIN_MIN_1 \ - (GL518_INIT_VIN_1 - GL518_INIT_VIN_1 * GL518_INIT_PERCENTAGE / 100) + (GL518_INIT_VIN_1 - GL518_INIT_VIN_1 * GL518_INIT_PERCENTAGE / 100) #define GL518_INIT_VIN_MAX_1 \ - (GL518_INIT_VIN_1 + GL518_INIT_VIN_1 * GL518_INIT_PERCENTAGE / 100) + (GL518_INIT_VIN_1 + GL518_INIT_VIN_1 * GL518_INIT_PERCENTAGE / 100) #define GL518_INIT_VIN_MIN_2 \ - (GL518_INIT_VIN_2 - GL518_INIT_VIN_2 * GL518_INIT_PERCENTAGE / 100) + (GL518_INIT_VIN_2 - GL518_INIT_VIN_2 * GL518_INIT_PERCENTAGE / 100) #define GL518_INIT_VIN_MAX_2 \ - (GL518_INIT_VIN_2 + GL518_INIT_VIN_2 * GL518_INIT_PERCENTAGE / 100) + (GL518_INIT_VIN_2 + GL518_INIT_VIN_2 * GL518_INIT_PERCENTAGE / 100) #define GL518_INIT_VIN_MIN_3 \ - (GL518_INIT_VIN_3 - GL518_INIT_VIN_3 * GL518_INIT_PERCENTAGE / 100) + (GL518_INIT_VIN_3 - GL518_INIT_VIN_3 * GL518_INIT_PERCENTAGE / 100) #define GL518_INIT_VIN_MAX_3 \ - (GL518_INIT_VIN_3 + GL518_INIT_VIN_3 * GL518_INIT_PERCENTAGE / 100) + (GL518_INIT_VIN_3 + GL518_INIT_VIN_3 * GL518_INIT_PERCENTAGE / 100) #define GL518_INIT_VDD_MIN \ - (GL518_INIT_VDD - GL518_INIT_VDD * GL518_INIT_PERCENTAGE / 100) + (GL518_INIT_VDD - GL518_INIT_VDD * GL518_INIT_PERCENTAGE / 100) #define GL518_INIT_VDD_MAX \ - (GL518_INIT_VDD + GL518_INIT_VDD * GL518_INIT_PERCENTAGE / 100) + (GL518_INIT_VDD + GL518_INIT_VDD * GL518_INIT_PERCENTAGE / 100) /* Each client has this additional data */ struct gl518_data { - int sysctl_id; - enum chips type; + int sysctl_id; + enum chips type; - struct semaphore update_lock; + struct semaphore update_lock; - int iterate_lock; - int quit_thread; - struct task_struct *thread; + int iterate_lock; + int quit_thread; + struct task_struct *thread; #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1) - wait_queue_head_t wq; + wait_queue_head_t wq; #else - struct wait_queue *wq; + struct wait_queue *wq; #endif - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ - unsigned long last_updated_v00; - /* In jiffies (used only by rev00 chips) */ + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ + unsigned long last_updated_v00; + /* In jiffies (used only by rev00 chips) */ - u8 voltage[4]; /* Register values; [0] = VDD */ - u8 voltage_min[4]; /* Register values; [0] = VDD */ - u8 voltage_max[4]; /* Register values; [0] = VDD */ - u8 iter_voltage[4]; /* Register values; [0] = VDD */ - u8 fan[2]; - u8 fan_min[2]; - u8 temp; /* Register values */ - u8 temp_over; /* Register values */ - u8 temp_hyst; /* Register values */ - u8 alarms,beeps; /* Register value */ - u8 alarm_mask; /* Register value */ - u8 fan_div[2]; /* Register encoding, shifted right */ - u8 beep_enable; /* Boolean */ - u8 iterate; /* Voltage iteration mode */ + u8 voltage[4]; /* Register values; [0] = VDD */ + u8 voltage_min[4]; /* Register values; [0] = VDD */ + u8 voltage_max[4]; /* Register values; [0] = VDD */ + u8 iter_voltage[4]; /* Register values; [0] = VDD */ + u8 fan[2]; + u8 fan_min[2]; + u8 temp; /* Register values */ + u8 temp_over; /* Register values */ + u8 temp_hyst; /* Register values */ + u8 alarms, beeps; /* Register value */ + u8 alarm_mask; /* Register value */ + u8 fan_div[2]; /* Register encoding, shifted right */ + u8 beep_enable; /* Boolean */ + u8 iterate; /* Voltage iteration mode */ }; #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ #ifdef MODULE static #else extern #endif - int __init sensors_gl518sm_init(void); +int __init sensors_gl518sm_init(void); static int __init gl518_cleanup(void); static int gl518_attach_adapter(struct i2c_adapter *adapter); -static int gl518_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind); +static int gl518_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); static void gl518_init_client(struct i2c_client *client); static int gl518_detach_client(struct i2c_client *client); static int gl518_command(struct i2c_client *client, unsigned int cmd, - void *arg); -static void gl518_inc_use (struct i2c_client *client); -static void gl518_dec_use (struct i2c_client *client); + void *arg); +static void gl518_inc_use(struct i2c_client *client); +static void gl518_dec_use(struct i2c_client *client); static u16 swap_bytes(u16 val); static int gl518_read_value(struct i2c_client *client, u8 reg); static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value); @@ -218,33 +219,33 @@ static int gl518_update_thread(void *data); #endif static void gl518_update_iterate(struct i2c_client *client); -static void gl518_vin(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); -static void gl518_fan(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); -static void gl518_temp(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); -static void gl518_fan_div(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); -static void gl518_alarms(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); -static void gl518_beep(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); +static void gl518_vin(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void gl518_fan(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void gl518_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void gl518_fan_div(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void gl518_alarms(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void gl518_beep(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static void gl518_fan1off(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); + int ctl_name, int *nrels_mag, long *results); static void gl518_iterate(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); + int ctl_name, int *nrels_mag, long *results); /* This is the driver that will be inserted */ static struct i2c_driver gl518_driver = { - /* name */ "GL518SM sensor chip driver", - /* id */ I2C_DRIVERID_GL518, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &gl518_attach_adapter, - /* detach_client */ &gl518_detach_client, - /* command */ &gl518_command, - /* inc_use */ &gl518_inc_use, - /* dec_use */ &gl518_dec_use + /* name */ "GL518SM sensor chip driver", + /* id */ I2C_DRIVERID_GL518, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &gl518_attach_adapter, + /* detach_client */ &gl518_detach_client, + /* command */ &gl518_command, + /* inc_use */ &gl518_inc_use, + /* dec_use */ &gl518_dec_use }; /* These files are created for each detected GL518. This is just a template; @@ -253,31 +254,31 @@ static struct i2c_driver gl518_driver = { is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table gl518_dir_table_template[] = { - { GL518_SYSCTL_VIN1, "vin1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl518_vin }, - { GL518_SYSCTL_VIN2, "vin2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl518_vin }, - { GL518_SYSCTL_VIN3, "vin3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl518_vin }, - { GL518_SYSCTL_VDD, "vdd", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl518_vin }, - { GL518_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl518_fan }, - { GL518_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl518_fan }, - { GL518_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl518_temp }, - { GL518_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl518_fan_div }, - { GL518_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl518_alarms }, - { GL518_SYSCTL_BEEP, "beep", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl518_beep }, - { GL518_SYSCTL_FAN1OFF, "fan1off", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl518_fan1off }, - { GL518_SYSCTL_ITERATE, "iterate", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl518_iterate }, - { 0 } + {GL518_SYSCTL_VIN1, "vin1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl518_vin}, + {GL518_SYSCTL_VIN2, "vin2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl518_vin}, + {GL518_SYSCTL_VIN3, "vin3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl518_vin}, + {GL518_SYSCTL_VDD, "vdd", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl518_vin}, + {GL518_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl518_fan}, + {GL518_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl518_fan}, + {GL518_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl518_temp}, + {GL518_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl518_fan_div}, + {GL518_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl518_alarms}, + {GL518_SYSCTL_BEEP, "beep", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl518_beep}, + {GL518_SYSCTL_FAN1OFF, "fan1off", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl518_fan1off}, + {GL518_SYSCTL_ITERATE, "iterate", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl518_iterate}, + {0} }; /* Used by init/cleanup */ @@ -291,241 +292,250 @@ static struct i2c_client *gl518_list[MAX_GL518_NR]; int gl518_attach_adapter(struct i2c_adapter *adapter) { - return sensors_detect(adapter,&addr_data,gl518_detect); + return sensors_detect(adapter, &addr_data, gl518_detect); } -static int gl518_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind) -{ - int i; - struct i2c_client *new_client; - struct gl518_data *data; - int err=0; - const char *type_name = ""; - const char *client_name = ""; +static int gl518_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) +{ + int i; + struct i2c_client *new_client; + struct gl518_data *data; + int err = 0; + const char *type_name = ""; + const char *client_name = ""; - /* Make sure we aren't probing the ISA bus!! This is just a safety check - at this moment; sensors_detect really won't call us. */ + /* Make sure we aren't probing the ISA bus!! This is just a safety check + at this moment; sensors_detect really won't call us. */ #ifdef DEBUG - if (i2c_is_isa_adapter(adapter)) { - printk("gl518sm.o: gl518_detect called for an ISA bus adapter?!?\n"); - return 0; - } + if (i2c_is_isa_adapter(adapter)) { + printk + ("gl518sm.o: gl518_detect called for an ISA bus adapter?!?\n"); + return 0; + } #endif - if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_BYTE_DATA | - I2C_FUNC_SMBUS_WORD_DATA)) - goto ERROR0; + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_SMBUS_WORD_DATA)) + goto ERROR0; - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access gl518_{read,write}_value. */ + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access gl518_{read,write}_value. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct gl518_data), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR0; - } + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct gl518_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } - data = (struct gl518_data *) (new_client + 1); - new_client->addr = address; - new_client->data = data; - new_client->adapter = adapter; - new_client->driver = &gl518_driver; - new_client->flags = 0; + data = (struct gl518_data *) (new_client + 1); + new_client->addr = address; + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &gl518_driver; + new_client->flags = 0; - /* Now, we do the remaining detection. */ + /* Now, we do the remaining detection. */ - if (kind < 0) { - if ((gl518_read_value(new_client,GL518_REG_CHIP_ID) != 0x80) || - (gl518_read_value(new_client,GL518_REG_CONF) & 0x80)) - goto ERROR1; - } + if (kind < 0) { + if ( + (gl518_read_value(new_client, GL518_REG_CHIP_ID) != + 0x80) + || (gl518_read_value(new_client, GL518_REG_CONF) & + 0x80)) goto ERROR1; + } - /* Determine the chip type. */ - if (kind <= 0) { - i = gl518_read_value(new_client,GL518_REG_REVISION); - if (i == 0x00) - kind = gl518sm_r00; - else if (i == 0x80) - kind = gl518sm_r80; - else { - if (kind == 0) - printk("gl518sm.o: Ignoring 'force' parameter for unknown chip at " - "adapter %d, address 0x%02x\n",i2c_adapter_id(adapter),address); - goto ERROR1; - } - } + /* Determine the chip type. */ + if (kind <= 0) { + i = gl518_read_value(new_client, GL518_REG_REVISION); + if (i == 0x00) + kind = gl518sm_r00; + else if (i == 0x80) + kind = gl518sm_r80; + else { + if (kind == 0) + printk + ("gl518sm.o: Ignoring 'force' parameter for unknown chip at " + "adapter %d, address 0x%02x\n", + i2c_adapter_id(adapter), address); + goto ERROR1; + } + } - if (kind == gl518sm_r00) { - type_name = "gl518sm"; - client_name = "GL518SM Revision 0x00 chip"; - } else if (kind == gl518sm_r80) { - type_name = "gl518sm"; - client_name = "GL518SM Revision 0x80 chip"; - } else { + if (kind == gl518sm_r00) { + type_name = "gl518sm"; + client_name = "GL518SM Revision 0x00 chip"; + } else if (kind == gl518sm_r80) { + type_name = "gl518sm"; + client_name = "GL518SM Revision 0x80 chip"; + } else { #ifdef DEBUG - printk("gl518sm.o: Internal error: unknown kind (%d)?!?",kind); + printk("gl518sm.o: Internal error: unknown kind (%d)?!?", + kind); #endif - goto ERROR1; - } + goto ERROR1; + } - /* Fill in the remaining client fields and put it into the global list */ - strcpy(new_client->name,client_name); - data->type = kind; + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); + data->type = kind; - for(i = 0; i < MAX_GL518_NR; i++) - if (! gl518_list[i]) - break; - if (i == MAX_GL518_NR) { - printk("gl518sm.o: No empty slots left, recompile and heighten " - "MAX_GL518_NR!\n"); - err = -ENOMEM; - goto ERROR2; - } - gl518_list[i] = new_client; - new_client->id = i; - data->valid = 0; - init_MUTEX(&data->update_lock); + for (i = 0; i < MAX_GL518_NR; i++) + if (!gl518_list[i]) + break; + if (i == MAX_GL518_NR) { + printk + ("gl518sm.o: No empty slots left, recompile and heighten " + "MAX_GL518_NR!\n"); + err = -ENOMEM; + goto ERROR2; + } + gl518_list[i] = new_client; + new_client->id = i; + data->valid = 0; + init_MUTEX(&data->update_lock); - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; - /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry((struct i2c_client *) new_client, - type_name, - gl518_dir_table_template, - THIS_MODULE)) < 0) { - err = i; - goto ERROR4; - } - data->sysctl_id = i; + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry((struct i2c_client *) new_client, + type_name, + gl518_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; - /* Initialize the GL518SM chip */ - data->iterate = 0; - data->iterate_lock = 0; - data->quit_thread = 0; - data->thread = NULL; - data->alarm_mask = 0xff; - gl518_init_client((struct i2c_client *) new_client); - return 0; + /* Initialize the GL518SM chip */ + data->iterate = 0; + data->iterate_lock = 0; + data->quit_thread = 0; + data->thread = NULL; + data->alarm_mask = 0xff; + gl518_init_client((struct i2c_client *) new_client); + return 0; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR4: - i2c_detach_client(new_client); -ERROR3: - for (i = 0; i < MAX_GL518_NR; i++) - if (new_client == gl518_list[i]) - gl518_list[i] = NULL; -ERROR2: -ERROR1: - kfree(new_client); -ERROR0: - return err; + ERROR4: + i2c_detach_client(new_client); + ERROR3: + for (i = 0; i < MAX_GL518_NR; i++) + if (new_client == gl518_list[i]) + gl518_list[i] = NULL; + ERROR2: + ERROR1: + kfree(new_client); + ERROR0: + return err; } /* Called when we have found a new GL518SM. It should set limits, etc. */ void gl518_init_client(struct i2c_client *client) { - /* Power-on defaults (bit 7=1) */ - gl518_write_value(client,GL518_REG_CONF,0x80); + /* Power-on defaults (bit 7=1) */ + gl518_write_value(client, GL518_REG_CONF, 0x80); - /* No noisy output (bit 2=1), Comparator mode (bit 3=0), two fans (bit4=0), - standby mode (bit6=0) */ - gl518_write_value(client,GL518_REG_CONF,0x04); + /* No noisy output (bit 2=1), Comparator mode (bit 3=0), two fans (bit4=0), + standby mode (bit6=0) */ + gl518_write_value(client, GL518_REG_CONF, 0x04); - /* Never interrupts */ - gl518_write_value(client,GL518_REG_MASK,0x00); - - gl518_write_value(client,GL518_REG_TEMP_HYST, - TEMP_TO_REG(GL518_INIT_TEMP_HYST)); - gl518_write_value(client,GL518_REG_TEMP_OVER, - TEMP_TO_REG(GL518_INIT_TEMP_OVER)); - gl518_write_value(client,GL518_REG_MISC,(DIV_TO_REG(2) << 6) | - (DIV_TO_REG(2) << 4)); - gl518_write_value(client,GL518_REG_FAN_LIMIT, - (FAN_TO_REG(GL518_INIT_FAN_MIN_1,2) << 8) | - FAN_TO_REG(GL518_INIT_FAN_MIN_2,2)); - gl518_write_value(client,GL518_REG_VIN1_LIMIT, - (IN_TO_REG(GL518_INIT_VIN_MAX_1) << 8) | - IN_TO_REG(GL518_INIT_VIN_MIN_1)); - gl518_write_value(client,GL518_REG_VIN2_LIMIT, - (IN_TO_REG(GL518_INIT_VIN_MAX_2) << 8) | - IN_TO_REG(GL518_INIT_VIN_MIN_2)); - gl518_write_value(client,GL518_REG_VIN3_LIMIT, - (IN_TO_REG(GL518_INIT_VIN_MAX_3) << 8) | - IN_TO_REG(GL518_INIT_VIN_MIN_3)); - gl518_write_value(client,GL518_REG_VDD_LIMIT, - (VDD_TO_REG(GL518_INIT_VDD_MAX) << 8) | - VDD_TO_REG(GL518_INIT_VDD_MIN)); + /* Never interrupts */ + gl518_write_value(client, GL518_REG_MASK, 0x00); - /* Clear status register (bit 5=1), start (bit6=1) */ - gl518_write_value(client,GL518_REG_CONF,0x24); - gl518_write_value(client,GL518_REG_CONF,0x44); + gl518_write_value(client, GL518_REG_TEMP_HYST, + TEMP_TO_REG(GL518_INIT_TEMP_HYST)); + gl518_write_value(client, GL518_REG_TEMP_OVER, + TEMP_TO_REG(GL518_INIT_TEMP_OVER)); + gl518_write_value(client, GL518_REG_MISC, (DIV_TO_REG(2) << 6) | + (DIV_TO_REG(2) << 4)); + gl518_write_value(client, GL518_REG_FAN_LIMIT, + (FAN_TO_REG(GL518_INIT_FAN_MIN_1, 2) << 8) | + FAN_TO_REG(GL518_INIT_FAN_MIN_2, 2)); + gl518_write_value(client, GL518_REG_VIN1_LIMIT, + (IN_TO_REG(GL518_INIT_VIN_MAX_1) << 8) | + IN_TO_REG(GL518_INIT_VIN_MIN_1)); + gl518_write_value(client, GL518_REG_VIN2_LIMIT, + (IN_TO_REG(GL518_INIT_VIN_MAX_2) << 8) | + IN_TO_REG(GL518_INIT_VIN_MIN_2)); + gl518_write_value(client, GL518_REG_VIN3_LIMIT, + (IN_TO_REG(GL518_INIT_VIN_MAX_3) << 8) | + IN_TO_REG(GL518_INIT_VIN_MIN_3)); + gl518_write_value(client, GL518_REG_VDD_LIMIT, + (VDD_TO_REG(GL518_INIT_VDD_MAX) << 8) | + VDD_TO_REG(GL518_INIT_VDD_MIN)); + + /* Clear status register (bit 5=1), start (bit6=1) */ + gl518_write_value(client, GL518_REG_CONF, 0x24); + gl518_write_value(client, GL518_REG_CONF, 0x44); } int gl518_detach_client(struct i2c_client *client) { - int err,i; - struct gl518_data *data = client->data; + int err, i; + struct gl518_data *data = client->data; - sensors_deregister_entry(((struct gl518_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct gl518_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("gl518sm.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("gl518sm.o: Client deregistration failed, client not detached.\n"); + return err; + } - for (i = 0; i < MAX_GL518_NR; i++) - if (client == gl518_list[i]) - break; - if ((i == MAX_GL518_NR)) { - printk("gl518sm.o: Client to detach not found.\n"); - return -ENOENT; - } - gl518_list[i] = NULL; - - if (data->thread) { - data->quit_thread = 1; - wake_up_interruptible(&data->wq); - } + for (i = 0; i < MAX_GL518_NR; i++) + if (client == gl518_list[i]) + break; + if ((i == MAX_GL518_NR)) { + printk("gl518sm.o: Client to detach not found.\n"); + return -ENOENT; + } + gl518_list[i] = NULL; - kfree(client); + if (data->thread) { + data->quit_thread = 1; + wake_up_interruptible(&data->wq); + } - return 0; + kfree(client); + + return 0; } /* No commands defined yet */ int gl518_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } /* Nothing here yet */ -void gl518_inc_use (struct i2c_client *client) +void gl518_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } /* Nothing here yet */ -void gl518_dec_use (struct i2c_client *client) +void gl518_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } u16 swap_bytes(u16 val) { - return (val >> 8) | (val << 8); + return (val >> 8) | (val << 8); } /* Registers 0x07 to 0x0c are word-sized, others are byte-sized @@ -533,10 +543,10 @@ u16 swap_bytes(u16 val) the usual practice. */ int gl518_read_value(struct i2c_client *client, u8 reg) { - if ((reg >= 0x07) && (reg <= 0x0c)) - return swap_bytes(i2c_smbus_read_word_data(client,reg)); - else - return i2c_smbus_read_byte_data(client,reg); + if ((reg >= 0x07) && (reg <= 0x0c)) + return swap_bytes(i2c_smbus_read_word_data(client, reg)); + else + return i2c_smbus_read_byte_data(client, reg); } /* Registers 0x07 to 0x0c are word-sized, others are byte-sized @@ -544,80 +554,87 @@ int gl518_read_value(struct i2c_client *client, u8 reg) the usual practice. */ int gl518_write_value(struct i2c_client *client, u8 reg, u16 value) { - if ((reg >= 0x07) && (reg <= 0x0c)) - return i2c_smbus_write_word_data(client,reg, swap_bytes(value)); - else - return i2c_smbus_write_byte_data(client,reg,value); + if ((reg >= 0x07) && (reg <= 0x0c)) + return i2c_smbus_write_word_data(client, reg, + swap_bytes(value)); + else + return i2c_smbus_write_byte_data(client, reg, value); } void gl518_update_client(struct i2c_client *client) { - struct gl518_data *data = client->data; - int val; + struct gl518_data *data = client->data; + int val; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > HZ+HZ/2 ) || - (jiffies < data->last_updated) || ! data->valid) { + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("Starting gl518 update\n"); + printk("Starting gl518 update\n"); #endif - data->alarms = gl518_read_value(client,GL518_REG_INT); - data->beeps = gl518_read_value(client,GL518_REG_ALARM); + data->alarms = gl518_read_value(client, GL518_REG_INT); + data->beeps = gl518_read_value(client, GL518_REG_ALARM); - val = gl518_read_value(client,GL518_REG_VDD_LIMIT); - data->voltage_min[0] = val & 0xff; - data->voltage_max[0] = (val >> 8) & 0xff; - val = gl518_read_value(client,GL518_REG_VIN1_LIMIT); - data->voltage_min[1] = val & 0xff; - data->voltage_max[1] = (val >> 8) & 0xff; - val = gl518_read_value(client,GL518_REG_VIN2_LIMIT); - data->voltage_min[2] = val & 0xff; - data->voltage_max[2] = (val >> 8) & 0xff; - val = gl518_read_value(client,GL518_REG_VIN3_LIMIT); - data->voltage_min[3] = val & 0xff; - data->voltage_max[3] = (val >> 8) & 0xff; + val = gl518_read_value(client, GL518_REG_VDD_LIMIT); + data->voltage_min[0] = val & 0xff; + data->voltage_max[0] = (val >> 8) & 0xff; + val = gl518_read_value(client, GL518_REG_VIN1_LIMIT); + data->voltage_min[1] = val & 0xff; + data->voltage_max[1] = (val >> 8) & 0xff; + val = gl518_read_value(client, GL518_REG_VIN2_LIMIT); + data->voltage_min[2] = val & 0xff; + data->voltage_max[2] = (val >> 8) & 0xff; + val = gl518_read_value(client, GL518_REG_VIN3_LIMIT); + data->voltage_min[3] = val & 0xff; + data->voltage_max[3] = (val >> 8) & 0xff; - val = gl518_read_value(client,GL518_REG_FAN_COUNT); - data->fan[0] = (val >> 8) & 0xff; - data->fan[1] = val & 0xff; + val = gl518_read_value(client, GL518_REG_FAN_COUNT); + data->fan[0] = (val >> 8) & 0xff; + data->fan[1] = val & 0xff; - val = gl518_read_value(client,GL518_REG_FAN_LIMIT); - data->fan_min[0] = (val >> 8) & 0xff; - data->fan_min[1] = val & 0xff; + val = gl518_read_value(client, GL518_REG_FAN_LIMIT); + data->fan_min[0] = (val >> 8) & 0xff; + data->fan_min[1] = val & 0xff; - data->temp = gl518_read_value(client,GL518_REG_TEMP); - data->temp_over = gl518_read_value(client,GL518_REG_TEMP_OVER); - data->temp_hyst = gl518_read_value(client,GL518_REG_TEMP_HYST); + data->temp = gl518_read_value(client, GL518_REG_TEMP); + data->temp_over = + gl518_read_value(client, GL518_REG_TEMP_OVER); + data->temp_hyst = + gl518_read_value(client, GL518_REG_TEMP_HYST); - val = gl518_read_value(client,GL518_REG_MISC); - data->fan_div[0] = (val >> 6) & 0x03; - data->fan_div[1] = (val >> 4) & 0x03; + val = gl518_read_value(client, GL518_REG_MISC); + data->fan_div[0] = (val >> 6) & 0x03; + data->fan_div[1] = (val >> 4) & 0x03; - data->alarms &= data->alarm_mask; - - val = gl518_read_value(client, GL518_REG_CONF); - data->beep_enable = (val >> 2) & 1; + data->alarms &= data->alarm_mask; -#ifndef DEBUG_VIN - if (data->type != gl518sm_r00) { - data->voltage[0] = gl518_read_value(client,GL518_REG_VDD); - data->voltage[1] = gl518_read_value(client,GL518_REG_VIN1); - data->voltage[2] = gl518_read_value(client,GL518_REG_VIN2); - data->voltage[3] = gl518_read_value(client,GL518_REG_VIN3); - } else - gl518_update_client_rev00(client); + val = gl518_read_value(client, GL518_REG_CONF); + data->beep_enable = (val >> 2) & 1; + +#ifndef DEBUG_VIN + if (data->type != gl518sm_r00) { + data->voltage[0] = + gl518_read_value(client, GL518_REG_VDD); + data->voltage[1] = + gl518_read_value(client, GL518_REG_VIN1); + data->voltage[2] = + gl518_read_value(client, GL518_REG_VIN2); + data->voltage[3] = + gl518_read_value(client, GL518_REG_VIN3); + } else + gl518_update_client_rev00(client); #else - gl518_update_client_rev00(client); + gl518_update_client_rev00(client); #endif - data->last_updated = jiffies; - data->valid = 1; - } + data->last_updated = jiffies; + data->valid = 1; + } - up(&data->update_lock); + up(&data->update_lock); } /* Here we decide how to run the iteration code. @@ -625,33 +642,36 @@ void gl518_update_client(struct i2c_client *client) measured voltage. No delay for user apps */ void gl518_update_client_rev00(struct i2c_client *client) { - struct gl518_data *data = client->data; - int i; + struct gl518_data *data = client->data; + int i; - if (data->iterate == 1) { /* 10 sec delay */ - /* as that update is slow, we consider the data valid for 30 seconds */ - if (((jiffies - data->last_updated_v00 > 30*HZ) || (data->alarms & 7) - || (! data->valid)) && (! data->iterate_lock)) { - data->iterate_lock=1; - gl518_update_iterate(client); - data->iterate_lock=0; - } - for (i=0; i<4; i++) - data->voltage[i]=data->iter_voltage[i]; - } else if (data->iterate == 2) { /* show results of last iteration */ - for (i=0; i<4; i++) - data->voltage[i]=data->iter_voltage[i]; - wake_up_interruptible(&data->wq); - } else { /* no iteration */ - data->voltage[3] = gl518_read_value(client,GL518_REG_VIN3); - } + if (data->iterate == 1) { /* 10 sec delay */ + /* as that update is slow, we consider the data valid for 30 seconds */ + if ( + ((jiffies - data->last_updated_v00 > 30 * HZ) + || (data->alarms & 7) + || (!data->valid)) && (!data->iterate_lock)) { + data->iterate_lock = 1; + gl518_update_iterate(client); + data->iterate_lock = 0; + } + for (i = 0; i < 4; i++) + data->voltage[i] = data->iter_voltage[i]; + } else if (data->iterate == 2) { /* show results of last iteration */ + for (i = 0; i < 4; i++) + data->voltage[i] = data->iter_voltage[i]; + wake_up_interruptible(&data->wq); + } else { /* no iteration */ + data->voltage[3] = + gl518_read_value(client, GL518_REG_VIN3); + } } int gl518_update_thread(void *c) { - struct i2c_client *client = c; - struct gl518_data *data = client->data; - + struct i2c_client *client = c; + struct gl518_data *data = client->data; + #ifdef __SMP__ lock_kernel(); #endif @@ -660,12 +680,12 @@ int gl518_update_thread(void *c) current->pgrp = 1; sigfillset(¤t->blocked); current->fs->umask = 0; - strcpy(current->comm,"gl518sm"); + strcpy(current->comm, "gl518sm"); #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1) init_waitqueue_head(&(data->wq)); #else - data->wq = NULL; + data->wq = NULL; #endif data->thread = current; @@ -673,21 +693,21 @@ int gl518_update_thread(void *c) unlock_kernel(); #endif - for (;;) { - if (! data->iterate_lock) { - data->iterate_lock=1; - gl518_update_iterate(client); - data->iterate_lock=0; - } + for (;;) { + if (!data->iterate_lock) { + data->iterate_lock = 1; + gl518_update_iterate(client); + data->iterate_lock = 0; + } - if ((data->quit_thread) || signal_pending(current)) - break; - interruptible_sleep_on(&data->wq); - } - - data->thread = NULL; - data->quit_thread = 0; - return 0; + if ((data->quit_thread) || signal_pending(current)) + break; + interruptible_sleep_on(&data->wq); + } + + data->thread = NULL; + data->quit_thread = 0; + return 0; } /* This updates vdd, vin1, vin2 values by doing slow and multiple @@ -696,370 +716,406 @@ int gl518_update_thread(void *c) void gl518_update_iterate(struct i2c_client *client) { - struct gl518_data *data = client->data; - int i, j, loop_more=1, min[3], max[3], delta[3]; - int alarm, beeps, irqs; + struct gl518_data *data = client->data; + int i, j, loop_more = 1, min[3], max[3], delta[3]; + int alarm, beeps, irqs; #define VIN_REG(c) c==0?GL518_REG_VDD_LIMIT:\ c==1?GL518_REG_VIN1_LIMIT:\ GL518_REG_VIN2_LIMIT - /* disable beeps & irqs for vin0-2*/ - beeps = gl518_read_value(client, GL518_REG_ALARM); - irqs = gl518_read_value(client, GL518_REG_MASK); - gl518_write_value(client,GL518_REG_ALARM, beeps &~ 0x7); - gl518_write_value(client,GL518_REG_MASK, irqs &~ 0x7); + /* disable beeps & irqs for vin0-2 */ + beeps = gl518_read_value(client, GL518_REG_ALARM); + irqs = gl518_read_value(client, GL518_REG_MASK); + gl518_write_value(client, GL518_REG_ALARM, beeps & ~0x7); + gl518_write_value(client, GL518_REG_MASK, irqs & ~0x7); - alarm = data->alarms; + alarm = data->alarms; - for (i=0; i<3; i++) { - if (alarm & (1<voltage_min[i]; - max[i] = (data->voltage_max[i]+data->voltage_min[i]) / 2; - } - delta[i] = (max[i] - min[i]) / 2; - } - - for (j=0; (j<10 && loop_more); j++) { - - for (i=0; i<3; i++) - gl518_write_value(client, VIN_REG(i), max[i] << 8 | min[i]); + for (i = 0; i < 3; i++) { + if (alarm & (1 << i)) { + min[i] = 0; + max[i] = 127; + } else { + min[i] = data->voltage_min[i]; + max[i] = + (data->voltage_max[i] + + data->voltage_min[i]) / 2; + } + delta[i] = (max[i] - min[i]) / 2; + } - if ((data->thread) && - ((data->quit_thread) || signal_pending(current))) - goto finish; + for (j = 0; (j < 10 && loop_more); j++) { - /* we wait now 1.5 seconds before comparing */ - current->state = TASK_INTERRUPTIBLE; - schedule_timeout(HZ + HZ/2); - - alarm = gl518_read_value(client,GL518_REG_INT); + for (i = 0; i < 3; i++) + gl518_write_value(client, VIN_REG(i), + max[i] << 8 | min[i]); -#ifdef DEBUG_VIN - printk("gl518sm: iteration %2d: %4d%c %4d%c %4d%c\n", j, - max[0], (alarm&1)?'!':' ', - max[1], (alarm&2)?'!':' ', - max[2], (alarm&4)?'!':' '); + if ((data->thread) && + ((data->quit_thread) || signal_pending(current))) + goto finish; + + /* we wait now 1.5 seconds before comparing */ + current->state = TASK_INTERRUPTIBLE; + schedule_timeout(HZ + HZ / 2); + + alarm = gl518_read_value(client, GL518_REG_INT); + +#ifdef DEBUG_VIN + printk("gl518sm: iteration %2d: %4d%c %4d%c %4d%c\n", j, + max[0], (alarm & 1) ? '!' : ' ', + max[1], (alarm & 2) ? '!' : ' ', + max[2], (alarm & 4) ? '!' : ' '); #endif - for (loop_more=0, i=0; i<3; i++) { - if (alarm & (1<>= 1; - } + if (delta[i]) + loop_more++; + delta[i] >>= 1; + } - } - - for (i=0; i<3; i++) - if (alarm & (1<voltage[0], - data->voltage[1], data->voltage[2]); + } + + for (i = 0; i < 3; i++) + if (alarm & (1 << i)) + max[i]++; + +#ifdef DEBUG_VIN + printk("gl518sm: final :%5d %5d %5d\n", max[0], max[1], + max[2]); + printk("gl518sm: meter :%5d %5d %5d\n", data->voltage[0], + data->voltage[1], data->voltage[2]); #endif - /* update values, including vin3 */ - for (i=0; i<3; i++) { - data->iter_voltage[i] = max[i]; - } - data->iter_voltage[3] = gl518_read_value(client,GL518_REG_VIN3); - data->last_updated_v00 = jiffies; + /* update values, including vin3 */ + for (i = 0; i < 3; i++) { + data->iter_voltage[i] = max[i]; + } + data->iter_voltage[3] = gl518_read_value(client, GL518_REG_VIN3); + data->last_updated_v00 = jiffies; -finish: - - /* reset values */ - for (i=0; i<3; i++) { - gl518_write_value(client, VIN_REG(i), - data->voltage_max[i] << 8 | data->voltage_min[i]); - } + finish: - gl518_write_value(client,GL518_REG_ALARM, beeps); - gl518_write_value(client,GL518_REG_MASK, irqs); + /* reset values */ + for (i = 0; i < 3; i++) { + gl518_write_value(client, VIN_REG(i), + data->voltage_max[i] << 8 | data-> + voltage_min[i]); + } + + gl518_write_value(client, GL518_REG_ALARM, beeps); + gl518_write_value(client, GL518_REG_MASK, irqs); #undef VIN_REG } void gl518_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct gl518_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 1; - else if (operation == SENSORS_PROC_REAL_READ) { - gl518_update_client(client); - results[0] = TEMP_FROM_REG(data->temp_over); - results[1] = TEMP_FROM_REG(data->temp_hyst); - results[2] = TEMP_FROM_REG(data->temp); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->temp_over = TEMP_TO_REG(results[0]); - gl518_write_value(client,GL518_REG_TEMP_OVER,data->temp_over); - } - if (*nrels_mag >= 2) { - data->temp_hyst = TEMP_TO_REG(results[1]); - gl518_write_value(client,GL518_REG_TEMP_HYST,data->temp_hyst); - } - } + struct gl518_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 1; + else if (operation == SENSORS_PROC_REAL_READ) { + gl518_update_client(client); + results[0] = TEMP_FROM_REG(data->temp_over); + results[1] = TEMP_FROM_REG(data->temp_hyst); + results[2] = TEMP_FROM_REG(data->temp); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->temp_over = TEMP_TO_REG(results[0]); + gl518_write_value(client, GL518_REG_TEMP_OVER, + data->temp_over); + } + if (*nrels_mag >= 2) { + data->temp_hyst = TEMP_TO_REG(results[1]); + gl518_write_value(client, GL518_REG_TEMP_HYST, + data->temp_hyst); + } + } } -void gl518_vin(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void gl518_vin(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - struct gl518_data *data = client->data; - int nr = ctl_name - GL518_SYSCTL_VDD; - int regnr,old=0; + struct gl518_data *data = client->data; + int nr = ctl_name - GL518_SYSCTL_VDD; + int regnr, old = 0; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 2; - else if (operation == SENSORS_PROC_REAL_READ) { - gl518_update_client(client); - results[0] = nr?IN_FROM_REG(data->voltage_min[nr]): - VDD_FROM_REG(data->voltage_min[nr]); - results[1] = nr?IN_FROM_REG(data->voltage_max[nr]): - VDD_FROM_REG(data->voltage_max[nr]); - results[2] = nr?IN_FROM_REG(data->voltage[nr]): - VDD_FROM_REG(data->voltage[nr]); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - regnr=nr==0?GL518_REG_VDD_LIMIT:nr==1?GL518_REG_VIN1_LIMIT:nr==2? - GL518_REG_VIN2_LIMIT:GL518_REG_VIN3_LIMIT; - if (*nrels_mag == 1) - old = gl518_read_value(client,regnr) & 0xff00; - if (*nrels_mag >= 2) { - data->voltage_max[nr] = nr?IN_TO_REG(results[1]):VDD_TO_REG(results[1]); - old = data->voltage_max[nr] << 8; - } - if (*nrels_mag >= 1) { - data->voltage_min[nr] = nr?IN_TO_REG(results[0]):VDD_TO_REG(results[0]); - old |= data->voltage_min[nr]; - gl518_write_value(client,regnr,old); - } - } -} - - -void gl518_fan(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) -{ - struct gl518_data *data = client->data; - int nr = ctl_name - GL518_SYSCTL_FAN1; - int old; - - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - gl518_update_client(client); - results[0] = FAN_FROM_REG(data->fan_min[nr], - DIV_FROM_REG(data->fan_div[nr])); - results[1] = FAN_FROM_REG(data->fan[nr],DIV_FROM_REG(data->fan_div[nr])); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->fan_min[nr] = FAN_TO_REG(results[0], - DIV_FROM_REG(data->fan_div[nr])); - old = gl518_read_value(client,GL518_REG_FAN_LIMIT); - - if (nr == 0) { - old = (old & 0x00ff) | (data->fan_min[0] << 8); - if (results[0]==0) - data->alarm_mask &= ~0x20; - else - data->alarm_mask |= 0x20; - } else { - old = (old & 0xff00) | data->fan_min[1]; - if (results[0]==0) - data->alarm_mask &= ~0x40; - else - data->alarm_mask |= 0x40; - } - gl518_write_value(client,GL518_REG_FAN_LIMIT,old); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + gl518_update_client(client); + results[0] = nr ? IN_FROM_REG(data->voltage_min[nr]) : + VDD_FROM_REG(data->voltage_min[nr]); + results[1] = nr ? IN_FROM_REG(data->voltage_max[nr]) : + VDD_FROM_REG(data->voltage_max[nr]); + results[2] = nr ? IN_FROM_REG(data->voltage[nr]) : + VDD_FROM_REG(data->voltage[nr]); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + regnr = + nr == 0 ? GL518_REG_VDD_LIMIT : nr == + 1 ? GL518_REG_VIN1_LIMIT : nr == + 2 ? GL518_REG_VIN2_LIMIT : GL518_REG_VIN3_LIMIT; + if (*nrels_mag == 1) + old = gl518_read_value(client, regnr) & 0xff00; + if (*nrels_mag >= 2) { + data->voltage_max[nr] = + nr ? IN_TO_REG(results[1]) : + VDD_TO_REG(results[1]); + old = data->voltage_max[nr] << 8; + } + if (*nrels_mag >= 1) { + data->voltage_min[nr] = + nr ? IN_TO_REG(results[0]) : + VDD_TO_REG(results[0]); + old |= data->voltage_min[nr]; + gl518_write_value(client, regnr, old); + } + } } -void gl518_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void gl518_fan(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - struct gl518_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - gl518_update_client(client); - results[0] = ALARMS_FROM_REG(data->alarms); - *nrels_mag = 1; - } + struct gl518_data *data = client->data; + int nr = ctl_name - GL518_SYSCTL_FAN1; + int old; + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + gl518_update_client(client); + results[0] = FAN_FROM_REG(data->fan_min[nr], + DIV_FROM_REG(data->fan_div[nr])); + results[1] = + FAN_FROM_REG(data->fan[nr], + DIV_FROM_REG(data->fan_div[nr])); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->fan_min[nr] = FAN_TO_REG(results[0], + DIV_FROM_REG(data-> + fan_div + [nr])); + old = + gl518_read_value(client, GL518_REG_FAN_LIMIT); + + if (nr == 0) { + old = + (old & 0x00ff) | (data-> + fan_min[0] << 8); + if (results[0] == 0) + data->alarm_mask &= ~0x20; + else + data->alarm_mask |= 0x20; + } else { + old = (old & 0xff00) | data->fan_min[1]; + if (results[0] == 0) + data->alarm_mask &= ~0x40; + else + data->alarm_mask |= 0x40; + } + gl518_write_value(client, GL518_REG_FAN_LIMIT, + old); + } + } } -void gl518_beep(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + +void gl518_alarms(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - struct gl518_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - gl518_update_client(client); - results[0] = BEEP_ENABLE_FROM_REG(data->beep_enable); - results[1] = BEEPS_FROM_REG(data->beeps); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->beep_enable = BEEP_ENABLE_TO_REG(results[0]); - gl518_write_value(client,GL518_REG_CONF, - (gl518_read_value(client,GL518_REG_CONF) & 0xfb) | - (data->beep_enable << 2)); - } - if (*nrels_mag >= 2) { - data->beeps = BEEPS_TO_REG(results[1]) & data->alarm_mask; - gl518_write_value(client,GL518_REG_ALARM,data->beeps); - } - } + struct gl518_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + gl518_update_client(client); + results[0] = ALARMS_FROM_REG(data->alarms); + *nrels_mag = 1; + } +} + +void gl518_beep(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) +{ + struct gl518_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + gl518_update_client(client); + results[0] = BEEP_ENABLE_FROM_REG(data->beep_enable); + results[1] = BEEPS_FROM_REG(data->beeps); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->beep_enable = BEEP_ENABLE_TO_REG(results[0]); + gl518_write_value(client, GL518_REG_CONF, + (gl518_read_value(client, + GL518_REG_CONF) + & 0xfb) | (data-> + beep_enable << 2)); + } + if (*nrels_mag >= 2) { + data->beeps = + BEEPS_TO_REG(results[1]) & data->alarm_mask; + gl518_write_value(client, GL518_REG_ALARM, + data->beeps); + } + } } void gl518_fan_div(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct gl518_data *data = client->data; - int old; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - gl518_update_client(client); - results[0] = DIV_FROM_REG(data->fan_div[0]); - results[1] = DIV_FROM_REG(data->fan_div[1]); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - old = gl518_read_value(client,GL518_REG_MISC); - if (*nrels_mag >= 2) { - data->fan_div[1] = DIV_TO_REG(results[1]); - old = (old & 0xcf) | (data->fan_div[1] << 4); - } - if (*nrels_mag >= 1) { - data->fan_div[0] = DIV_TO_REG(results[0]); - old = (old & 0x3f) | (data->fan_div[0] << 6); - } - gl518_write_value(client,GL518_REG_MISC,old); - } + struct gl518_data *data = client->data; + int old; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + gl518_update_client(client); + results[0] = DIV_FROM_REG(data->fan_div[0]); + results[1] = DIV_FROM_REG(data->fan_div[1]); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + old = gl518_read_value(client, GL518_REG_MISC); + if (*nrels_mag >= 2) { + data->fan_div[1] = DIV_TO_REG(results[1]); + old = (old & 0xcf) | (data->fan_div[1] << 4); + } + if (*nrels_mag >= 1) { + data->fan_div[0] = DIV_TO_REG(results[0]); + old = (old & 0x3f) | (data->fan_div[0] << 6); + } + gl518_write_value(client, GL518_REG_MISC, old); + } } -void gl518_fan1off(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void gl518_fan1off(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - int old; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - results[0] = ((gl518_read_value(client, GL518_REG_MISC) & 0x08) !=0); - results[1] = ((gl518_read_value(client, GL518_REG_CONF) & 0x10) !=0); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - old = gl518_read_value(client, GL518_REG_MISC) & 0xf7; - if (results[0]) - old |= 0x08; - gl518_write_value(client,GL518_REG_MISC,old); - } - if (*nrels_mag >= 2) { - old = gl518_read_value(client, GL518_REG_CONF) & 0xef; - if (results[1]) - old |= 0x10; - gl518_write_value(client,GL518_REG_CONF,old); - } - } + int old; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + results[0] = + ((gl518_read_value(client, GL518_REG_MISC) & 0x08) != + 0); + results[1] = + ((gl518_read_value(client, GL518_REG_CONF) & 0x10) != + 0); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + old = + gl518_read_value(client, + GL518_REG_MISC) & 0xf7; + if (results[0]) + old |= 0x08; + gl518_write_value(client, GL518_REG_MISC, old); + } + if (*nrels_mag >= 2) { + old = + gl518_read_value(client, + GL518_REG_CONF) & 0xef; + if (results[1]) + old |= 0x10; + gl518_write_value(client, GL518_REG_CONF, old); + } + } } -void gl518_iterate(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void gl518_iterate(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - struct gl518_data *data = client->data; - int i; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - results[0] = data->iterate; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if ((*nrels_mag >= 1) && (data->iterate!=results[0])) { - data->iterate=results[0]; - for (i=0; i<4; i++) { - data->voltage[i]=0; - data->iter_voltage[i]=0; - } - data->valid=0; - - if ((data->iterate != 2) && (data->thread)) { - data->quit_thread = 1; - wake_up_interruptible(&data->wq); - } else if ((data->iterate==2) && (! data->thread)) { + struct gl518_data *data = client->data; + int i; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + results[0] = data->iterate; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if ((*nrels_mag >= 1) && (data->iterate != results[0])) { + data->iterate = results[0]; + for (i = 0; i < 4; i++) { + data->voltage[i] = 0; + data->iter_voltage[i] = 0; + } + data->valid = 0; + + if ((data->iterate != 2) && (data->thread)) { + data->quit_thread = 1; + wake_up_interruptible(&data->wq); + } else if ((data->iterate == 2) && (!data->thread)) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1) - init_waitqueue_head(&(data->wq)); + init_waitqueue_head(&(data->wq)); #else - data->wq = NULL; + data->wq = NULL; #endif - kernel_thread(gl518_update_thread, (void*) client, 0); - } - } - } + kernel_thread(gl518_update_thread, + (void *) client, 0); + } + } + } } int __init sensors_gl518sm_init(void) { - int res; + int res; - printk("gl518sm.o version %s (%s)\n",LM_VERSION,LM_DATE); - gl518_initialized = 0; - if ((res = i2c_add_driver(&gl518_driver))) { - printk("gl518sm.o: Driver registration failed, module not inserted.\n"); - gl518_cleanup(); - return res; - } - gl518_initialized ++; - return 0; + printk("gl518sm.o version %s (%s)\n", LM_VERSION, LM_DATE); + gl518_initialized = 0; + if ((res = i2c_add_driver(&gl518_driver))) { + printk + ("gl518sm.o: Driver registration failed, module not inserted.\n"); + gl518_cleanup(); + return res; + } + gl518_initialized++; + return 0; } int __init gl518_cleanup(void) { - int res; + int res; - if (gl518_initialized >= 1) { - if ((res = i2c_del_driver(&gl518_driver))) { - printk("gl518.o: Driver deregistration failed, module not removed.\n"); - return res; - } - gl518_initialized --; - } + if (gl518_initialized >= 1) { + if ((res = i2c_del_driver(&gl518_driver))) { + printk + ("gl518.o: Driver deregistration failed, module not removed.\n"); + return res; + } + gl518_initialized--; + } - return 0; + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard and Kyösti Mälkki "); +MODULE_AUTHOR + ("Frodo Looijaard and Kyösti Mälkki "); MODULE_DESCRIPTION("GL518SM driver"); int init_module(void) { - return sensors_gl518sm_init(); + return sensors_gl518sm_init(); } int cleanup_module(void) { - return gl518_cleanup(); + return gl518_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/gl520sm.c b/kernel/chips/gl520sm.c index d42a89cc..73814cc0 100644 --- a/kernel/chips/gl520sm.c +++ b/kernel/chips/gl520sm.c @@ -38,10 +38,10 @@ #endif /* Addresses to scan */ -static unsigned short normal_i2c[] = {0x2c,0x2d,SENSORS_I2C_END}; -static unsigned short normal_i2c_range[] = {SENSORS_I2C_END}; -static unsigned int normal_isa[] = {SENSORS_ISA_END}; -static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; +static unsigned short normal_i2c[] = { 0x2c, 0x2d, SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { SENSORS_I2C_END }; +static unsigned int normal_isa[] = { SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; /* Insmod parameters */ SENSORS_INSMOD_1(gl520sm); @@ -92,10 +92,11 @@ That's why _TEMP2 and _VIN4 access the same register extern inline u8 FAN_TO_REG(long rpm, int div) { - if (rpm == 0) - return 255; - rpm = SENSORS_LIMIT(rpm,1,1000000); - return SENSORS_LIMIT((960000 + rpm*div/2) / (rpm*div),1,254); + if (rpm == 0) + return 255; + rpm = SENSORS_LIMIT(rpm, 1, 1000000); + return SENSORS_LIMIT((960000 + rpm * div / 2) / (rpm * div), 1, + 254); } #define FAN_FROM_REG(val,div) \ @@ -137,104 +138,104 @@ extern inline u8 FAN_TO_REG(long rpm, int div) #define GL520_INIT_PERCENTAGE 10 #define GL520_INIT_VIN_MIN_1 \ - (GL520_INIT_VIN_1 - GL520_INIT_VIN_1 * GL520_INIT_PERCENTAGE / 100) + (GL520_INIT_VIN_1 - GL520_INIT_VIN_1 * GL520_INIT_PERCENTAGE / 100) #define GL520_INIT_VIN_MAX_1 \ - (GL520_INIT_VIN_1 + GL520_INIT_VIN_1 * GL520_INIT_PERCENTAGE / 100) + (GL520_INIT_VIN_1 + GL520_INIT_VIN_1 * GL520_INIT_PERCENTAGE / 100) #define GL520_INIT_VIN_MIN_2 \ - (GL520_INIT_VIN_2 - GL520_INIT_VIN_2 * GL520_INIT_PERCENTAGE / 100) + (GL520_INIT_VIN_2 - GL520_INIT_VIN_2 * GL520_INIT_PERCENTAGE / 100) #define GL520_INIT_VIN_MAX_2 \ - (GL520_INIT_VIN_2 + GL520_INIT_VIN_2 * GL520_INIT_PERCENTAGE / 100) + (GL520_INIT_VIN_2 + GL520_INIT_VIN_2 * GL520_INIT_PERCENTAGE / 100) #define GL520_INIT_VIN_MIN_3 \ - (GL520_INIT_VIN_3 - GL520_INIT_VIN_3 * GL520_INIT_PERCENTAGE / 100) + (GL520_INIT_VIN_3 - GL520_INIT_VIN_3 * GL520_INIT_PERCENTAGE / 100) #define GL520_INIT_VIN_MAX_3 \ - (GL520_INIT_VIN_3 + GL520_INIT_VIN_3 * GL520_INIT_PERCENTAGE / 100) + (GL520_INIT_VIN_3 + GL520_INIT_VIN_3 * GL520_INIT_PERCENTAGE / 100) #define GL520_INIT_VDD_MIN \ - (GL520_INIT_VDD - GL520_INIT_VDD * GL520_INIT_PERCENTAGE / 100) + (GL520_INIT_VDD - GL520_INIT_VDD * GL520_INIT_PERCENTAGE / 100) #define GL520_INIT_VDD_MAX \ - (GL520_INIT_VDD + GL520_INIT_VDD * GL520_INIT_PERCENTAGE / 100) + (GL520_INIT_VDD + GL520_INIT_VDD * GL520_INIT_PERCENTAGE / 100) /* Each client has this additional data */ struct gl520_data { - int sysctl_id; - enum chips type; + int sysctl_id; + enum chips type; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ - unsigned long last_updated_v00; - /* In jiffies (used only by rev00 chips) */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ + unsigned long last_updated_v00; + /* In jiffies (used only by rev00 chips) */ - u8 voltage[5]; /* Register values; [0] = VDD */ - u8 voltage_min[5]; /* Register values; [0] = VDD */ - u8 voltage_max[5]; /* Register values; [0] = VDD */ - u8 fan[2]; - u8 fan_min[2]; - u8 temp[2]; /* Register values */ - u8 temp_over[2]; /* Register values */ - u8 temp_hyst[2]; /* Register values */ - u8 alarms,beeps,vid; /* Register value */ - u8 alarm_mask; /* Register value */ - u8 fan_div[2]; /* Register encoding, shifted right */ - u8 beep_enable; /* Boolean */ - u8 two_temps; /* Boolean */ + u8 voltage[5]; /* Register values; [0] = VDD */ + u8 voltage_min[5]; /* Register values; [0] = VDD */ + u8 voltage_max[5]; /* Register values; [0] = VDD */ + u8 fan[2]; + u8 fan_min[2]; + u8 temp[2]; /* Register values */ + u8 temp_over[2]; /* Register values */ + u8 temp_hyst[2]; /* Register values */ + u8 alarms, beeps, vid; /* Register value */ + u8 alarm_mask; /* Register value */ + u8 fan_div[2]; /* Register encoding, shifted right */ + u8 beep_enable; /* Boolean */ + u8 two_temps; /* Boolean */ }; #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ #ifdef MODULE static #else extern #endif - int __init sensors_gl520_init(void); +int __init sensors_gl520_init(void); static int __init gl520_cleanup(void); static int gl520_attach_adapter(struct i2c_adapter *adapter); -static int gl520_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind); +static int gl520_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); static void gl520_init_client(struct i2c_client *client); static int gl520_detach_client(struct i2c_client *client); static int gl520_command(struct i2c_client *client, unsigned int cmd, - void *arg); -static void gl520_inc_use (struct i2c_client *client); -static void gl520_dec_use (struct i2c_client *client); + void *arg); +static void gl520_inc_use(struct i2c_client *client); +static void gl520_dec_use(struct i2c_client *client); static u16 swap_bytes(u16 val); static int gl520_read_value(struct i2c_client *client, u8 reg); static int gl520_write_value(struct i2c_client *client, u8 reg, u16 value); static void gl520_update_client(struct i2c_client *client); -static void gl520_vin(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); -static void gl520_vid(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); -static void gl520_fan(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); -static void gl520_temp(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); -static void gl520_fan_div(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); -static void gl520_alarms(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); -static void gl520_beep(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); +static void gl520_vin(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void gl520_vid(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void gl520_fan(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void gl520_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void gl520_fan_div(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void gl520_alarms(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void gl520_beep(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static void gl520_fan1off(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); + int ctl_name, int *nrels_mag, long *results); static void gl520_config(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); + int ctl_name, int *nrels_mag, long *results); /* This is the driver that will be inserted */ static struct i2c_driver gl520_driver = { - /* name */ "GL520SM sensor chip driver", - /* id */ I2C_DRIVERID_GL520, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &gl520_attach_adapter, - /* detach_client */ &gl520_detach_client, - /* command */ &gl520_command, - /* inc_use */ &gl520_inc_use, - /* dec_use */ &gl520_dec_use + /* name */ "GL520SM sensor chip driver", + /* id */ I2C_DRIVERID_GL520, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &gl520_attach_adapter, + /* detach_client */ &gl520_detach_client, + /* command */ &gl520_command, + /* inc_use */ &gl520_inc_use, + /* dec_use */ &gl520_dec_use }; /* These files are created for each detected GL520. This is just a template; @@ -243,37 +244,37 @@ static struct i2c_driver gl520_driver = { is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table gl520_dir_table_template[] = { - { GL520_SYSCTL_VIN1, "vin1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_vin }, - { GL520_SYSCTL_VIN2, "vin2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_vin }, - { GL520_SYSCTL_VIN3, "vin3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_vin }, - { GL520_SYSCTL_VIN4, "vin4", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_vin }, - { GL520_SYSCTL_VDD, "vdd", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_vin }, - { GL520_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_vid }, - { GL520_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_fan }, - { GL520_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_fan }, - { GL520_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_temp }, - { GL520_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_temp }, - { GL520_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_fan_div }, - { GL520_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_alarms }, - { GL520_SYSCTL_BEEP, "beep", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_beep }, - { GL520_SYSCTL_FAN1OFF, "fan1off", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_fan1off }, - { GL520_SYSCTL_CONFIG, "config", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &gl520_config }, - { 0 } + {GL520_SYSCTL_VIN1, "vin1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_vin}, + {GL520_SYSCTL_VIN2, "vin2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_vin}, + {GL520_SYSCTL_VIN3, "vin3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_vin}, + {GL520_SYSCTL_VIN4, "vin4", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_vin}, + {GL520_SYSCTL_VDD, "vdd", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_vin}, + {GL520_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_vid}, + {GL520_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_fan}, + {GL520_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_fan}, + {GL520_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_temp}, + {GL520_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_temp}, + {GL520_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_fan_div}, + {GL520_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_alarms}, + {GL520_SYSCTL_BEEP, "beep", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_beep}, + {GL520_SYSCTL_FAN1OFF, "fan1off", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_fan1off}, + {GL520_SYSCTL_CONFIG, "config", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &gl520_config}, + {0} }; /* Used by init/cleanup */ @@ -286,202 +287,208 @@ static int gl520_id = 0; int gl520_attach_adapter(struct i2c_adapter *adapter) { - return sensors_detect(adapter,&addr_data,gl520_detect); + return sensors_detect(adapter, &addr_data, gl520_detect); } -static int gl520_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind) -{ - int i; - struct i2c_client *new_client; - struct gl520_data *data; - int err=0; - const char *type_name = ""; - char client_name[32]; +static int gl520_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) +{ + int i; + struct i2c_client *new_client; + struct gl520_data *data; + int err = 0; + const char *type_name = ""; + char client_name[32]; - /* Make sure we aren't probing the ISA bus!! This is just a safety check - at this moment; sensors_detect really won't call us. */ + /* Make sure we aren't probing the ISA bus!! This is just a safety check + at this moment; sensors_detect really won't call us. */ #ifdef DEBUG - if (i2c_is_isa_adapter(adapter)) { - printk("gl520sm.o: gl520_detect called for an ISA bus adapter?!?\n"); - return 0; - } + if (i2c_is_isa_adapter(adapter)) { + printk + ("gl520sm.o: gl520_detect called for an ISA bus adapter?!?\n"); + return 0; + } #endif - if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_BYTE_DATA| - I2C_FUNC_SMBUS_WORD_DATA)) - goto ERROR0; + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_SMBUS_WORD_DATA)) + goto ERROR0; - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access gl520_{read,write}_value. */ + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access gl520_{read,write}_value. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct gl520_data), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR0; - } + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct gl520_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } - data = (struct gl520_data *) (new_client + 1); - new_client->addr = address; - new_client->data = data; - new_client->adapter = adapter; - new_client->driver = &gl520_driver; - new_client->flags = 0; + data = (struct gl520_data *) (new_client + 1); + new_client->addr = address; + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &gl520_driver; + new_client->flags = 0; - /* Determine the chip type. */ + /* Determine the chip type. */ - if (gl520_read_value(new_client,GL520_REG_CHIP_ID) != 0x20) { - printk("gl520sm.o: Ignoring 'force' parameter for unknown chip at " - "adapter %d, address 0x%02x\n",i2c_adapter_id(adapter),address); - goto ERROR1; - } else { - kind = gl520sm; - } - - i = gl520_read_value(new_client,GL520_REG_REVISION); - if (kind == gl520sm) { - type_name = "gl520sm"; - sprintf(client_name, "GL520SM Revision %02x chip", i); - } else { + if (gl520_read_value(new_client, GL520_REG_CHIP_ID) != 0x20) { + printk + ("gl520sm.o: Ignoring 'force' parameter for unknown chip at " + "adapter %d, address 0x%02x\n", + i2c_adapter_id(adapter), address); + goto ERROR1; + } else { + kind = gl520sm; + } + + i = gl520_read_value(new_client, GL520_REG_REVISION); + if (kind == gl520sm) { + type_name = "gl520sm"; + sprintf(client_name, "GL520SM Revision %02x chip", i); + } else { #ifdef DEBUG - printk("gl520sm.o: Internal error: unknown kind (%d)?!?",kind); + printk("gl520sm.o: Internal error: unknown kind (%d)?!?", + kind); #endif - goto ERROR1; - } + goto ERROR1; + } - /* Fill in the remaining client fields and put it into the global list */ - strcpy(new_client->name,client_name); - data->type = kind; + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); + data->type = kind; - new_client->id = gl520_id++; - data->valid = 0; - init_MUTEX(&data->update_lock); + new_client->id = gl520_id++; + data->valid = 0; + init_MUTEX(&data->update_lock); - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; - /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry(new_client, - type_name, - gl520_dir_table_template, - THIS_MODULE)) < 0) { - err = i; - goto ERROR4; - } - data->sysctl_id = i; + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry(new_client, + type_name, + gl520_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; - /* Initialize the GL520SM chip */ - data->two_temps=1; - data->alarm_mask=0xff; - gl520_init_client(new_client); - return 0; + /* Initialize the GL520SM chip */ + data->two_temps = 1; + data->alarm_mask = 0xff; + gl520_init_client(new_client); + return 0; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR4: - i2c_detach_client(new_client); -ERROR3: -ERROR1: - kfree(new_client); -ERROR0: - return err; + ERROR4: + i2c_detach_client(new_client); + ERROR3: + ERROR1: + kfree(new_client); + ERROR0: + return err; } /* Called when we have found a new GL520SM. It should set limits, etc. */ void gl520_init_client(struct i2c_client *client) { - /* Power-on defaults (bit 7=1) */ - gl520_write_value(client,GL520_REG_CONF,0x80); + /* Power-on defaults (bit 7=1) */ + gl520_write_value(client, GL520_REG_CONF, 0x80); - /* No noisy output (bit 2=1), Comparator mode (bit 3=0), two fans (bit4=0), - standby mode (bit6=0) */ - gl520_write_value(client,GL520_REG_CONF,0x04); + /* No noisy output (bit 2=1), Comparator mode (bit 3=0), two fans (bit4=0), + standby mode (bit6=0) */ + gl520_write_value(client, GL520_REG_CONF, 0x04); - /* Never interrupts */ - gl520_write_value(client,GL520_REG_MASK,0x00); - - gl520_write_value(client,GL520_REG_TEMP1_HYST, - TEMP_TO_REG(GL520_INIT_TEMP_HYST)); - gl520_write_value(client,GL520_REG_TEMP1_OVER, - TEMP_TO_REG(GL520_INIT_TEMP_OVER)); + /* Never interrupts */ + gl520_write_value(client, GL520_REG_MASK, 0x00); - /* We set Temp2, but not Vin4. */ - gl520_write_value(client,GL520_REG_TEMP2_HYST, - TEMP_TO_REG(GL520_INIT_TEMP_HYST)); - gl520_write_value(client,GL520_REG_TEMP2_OVER, - TEMP_TO_REG(GL520_INIT_TEMP_OVER)); + gl520_write_value(client, GL520_REG_TEMP1_HYST, + TEMP_TO_REG(GL520_INIT_TEMP_HYST)); + gl520_write_value(client, GL520_REG_TEMP1_OVER, + TEMP_TO_REG(GL520_INIT_TEMP_OVER)); - gl520_write_value(client,GL520_REG_MISC,(DIV_TO_REG(2) << 6) | - (DIV_TO_REG(2) << 4)); - gl520_write_value(client,GL520_REG_FAN_LIMIT, - (FAN_TO_REG(GL520_INIT_FAN_MIN_1,2) << 8) | - FAN_TO_REG(GL520_INIT_FAN_MIN_2,2)); + /* We set Temp2, but not Vin4. */ + gl520_write_value(client, GL520_REG_TEMP2_HYST, + TEMP_TO_REG(GL520_INIT_TEMP_HYST)); + gl520_write_value(client, GL520_REG_TEMP2_OVER, + TEMP_TO_REG(GL520_INIT_TEMP_OVER)); - gl520_write_value(client,GL520_REG_VIN1_LIMIT, - (IN_TO_REG(GL520_INIT_VIN_MAX_1) << 8) | - IN_TO_REG(GL520_INIT_VIN_MIN_1)); - gl520_write_value(client,GL520_REG_VIN2_LIMIT, - (IN_TO_REG(GL520_INIT_VIN_MAX_2) << 8) | - IN_TO_REG(GL520_INIT_VIN_MIN_2)); - gl520_write_value(client,GL520_REG_VIN3_LIMIT, - (IN_TO_REG(GL520_INIT_VIN_MAX_3) << 8) | - IN_TO_REG(GL520_INIT_VIN_MIN_3)); - gl520_write_value(client,GL520_REG_VDD_LIMIT, - (VDD_TO_REG(GL520_INIT_VDD_MAX) << 8) | - VDD_TO_REG(GL520_INIT_VDD_MIN)); + gl520_write_value(client, GL520_REG_MISC, (DIV_TO_REG(2) << 6) | + (DIV_TO_REG(2) << 4)); + gl520_write_value(client, GL520_REG_FAN_LIMIT, + (FAN_TO_REG(GL520_INIT_FAN_MIN_1, 2) << 8) | + FAN_TO_REG(GL520_INIT_FAN_MIN_2, 2)); - /* Clear status register (bit 5=1), start (bit6=1) */ - gl520_write_value(client,GL520_REG_CONF,0x24); - gl520_write_value(client,GL520_REG_CONF,0x44); + gl520_write_value(client, GL520_REG_VIN1_LIMIT, + (IN_TO_REG(GL520_INIT_VIN_MAX_1) << 8) | + IN_TO_REG(GL520_INIT_VIN_MIN_1)); + gl520_write_value(client, GL520_REG_VIN2_LIMIT, + (IN_TO_REG(GL520_INIT_VIN_MAX_2) << 8) | + IN_TO_REG(GL520_INIT_VIN_MIN_2)); + gl520_write_value(client, GL520_REG_VIN3_LIMIT, + (IN_TO_REG(GL520_INIT_VIN_MAX_3) << 8) | + IN_TO_REG(GL520_INIT_VIN_MIN_3)); + gl520_write_value(client, GL520_REG_VDD_LIMIT, + (VDD_TO_REG(GL520_INIT_VDD_MAX) << 8) | + VDD_TO_REG(GL520_INIT_VDD_MIN)); + + /* Clear status register (bit 5=1), start (bit6=1) */ + gl520_write_value(client, GL520_REG_CONF, 0x24); + gl520_write_value(client, GL520_REG_CONF, 0x44); } int gl520_detach_client(struct i2c_client *client) { - int err; + int err; - sensors_deregister_entry(((struct gl520_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct gl520_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("gl520sm.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("gl520sm.o: Client deregistration failed, client not detached.\n"); + return err; + } - kfree(client); + kfree(client); - return 0; + return 0; } /* No commands defined yet */ int gl520_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } /* Nothing here yet */ -void gl520_inc_use (struct i2c_client *client) +void gl520_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } /* Nothing here yet */ -void gl520_dec_use (struct i2c_client *client) +void gl520_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } u16 swap_bytes(u16 val) { - return (val >> 8) | (val << 8); + return (val >> 8) | (val << 8); } /* Registers 0x07 to 0x0c are word-sized, others are byte-sized @@ -489,10 +496,10 @@ u16 swap_bytes(u16 val) the usual practice. */ int gl520_read_value(struct i2c_client *client, u8 reg) { - if ((reg >= 0x07) && (reg <= 0x0c)) - return swap_bytes(i2c_smbus_read_word_data(client,reg)); - else - return i2c_smbus_read_byte_data(client,reg); + if ((reg >= 0x07) && (reg <= 0x0c)) + return swap_bytes(i2c_smbus_read_word_data(client, reg)); + else + return i2c_smbus_read_byte_data(client, reg); } /* Registers 0x07 to 0x0c are word-sized, others are byte-sized @@ -500,367 +507,417 @@ int gl520_read_value(struct i2c_client *client, u8 reg) the usual practice. */ int gl520_write_value(struct i2c_client *client, u8 reg, u16 value) { - if ((reg >= 0x07) && (reg <= 0x0c)) - return i2c_smbus_write_word_data(client,reg, swap_bytes(value)); - else - return i2c_smbus_write_byte_data(client,reg,value); + if ((reg >= 0x07) && (reg <= 0x0c)) + return i2c_smbus_write_word_data(client, reg, + swap_bytes(value)); + else + return i2c_smbus_write_byte_data(client, reg, value); } void gl520_update_client(struct i2c_client *client) { - struct gl520_data *data = client->data; - int val; + struct gl520_data *data = client->data; + int val; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > HZ+HZ/2 ) || - (jiffies < data->last_updated) || ! data->valid) { + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("Starting gl520 update\n"); + printk("Starting gl520 update\n"); #endif - data->alarms = gl520_read_value(client,GL520_REG_INT); - data->beeps = gl520_read_value(client,GL520_REG_ALARM); - data->vid = gl520_read_value(client,GL520_REG_VID) & 0x1f; + data->alarms = gl520_read_value(client, GL520_REG_INT); + data->beeps = gl520_read_value(client, GL520_REG_ALARM); + data->vid = gl520_read_value(client, GL520_REG_VID) & 0x1f; - val = gl520_read_value(client,GL520_REG_VDD_LIMIT); - data->voltage_min[0] = val & 0xff; - data->voltage_max[0] = (val >> 8) & 0xff; - val = gl520_read_value(client,GL520_REG_VIN1_LIMIT); - data->voltage_min[1] = val & 0xff; - data->voltage_max[1] = (val >> 8) & 0xff; - val = gl520_read_value(client,GL520_REG_VIN2_LIMIT); - data->voltage_min[2] = val & 0xff; - data->voltage_max[2] = (val >> 8) & 0xff; - val = gl520_read_value(client,GL520_REG_VIN3_LIMIT); - data->voltage_min[3] = val & 0xff; - data->voltage_max[3] = (val >> 8) & 0xff; + val = gl520_read_value(client, GL520_REG_VDD_LIMIT); + data->voltage_min[0] = val & 0xff; + data->voltage_max[0] = (val >> 8) & 0xff; + val = gl520_read_value(client, GL520_REG_VIN1_LIMIT); + data->voltage_min[1] = val & 0xff; + data->voltage_max[1] = (val >> 8) & 0xff; + val = gl520_read_value(client, GL520_REG_VIN2_LIMIT); + data->voltage_min[2] = val & 0xff; + data->voltage_max[2] = (val >> 8) & 0xff; + val = gl520_read_value(client, GL520_REG_VIN3_LIMIT); + data->voltage_min[3] = val & 0xff; + data->voltage_max[3] = (val >> 8) & 0xff; - val = gl520_read_value(client,GL520_REG_FAN_COUNT); - data->fan[0] = (val >> 8) & 0xff; - data->fan[1] = val & 0xff; + val = gl520_read_value(client, GL520_REG_FAN_COUNT); + data->fan[0] = (val >> 8) & 0xff; + data->fan[1] = val & 0xff; - val = gl520_read_value(client,GL520_REG_FAN_LIMIT); - data->fan_min[0] = (val >> 8) & 0xff; - data->fan_min[1] = val & 0xff; - - data->temp[0] = gl520_read_value(client,GL520_REG_TEMP1); - data->temp_over[0] = gl520_read_value(client,GL520_REG_TEMP1_OVER); - data->temp_hyst[0] = gl520_read_value(client,GL520_REG_TEMP1_HYST); + val = gl520_read_value(client, GL520_REG_FAN_LIMIT); + data->fan_min[0] = (val >> 8) & 0xff; + data->fan_min[1] = val & 0xff; - val = gl520_read_value(client,GL520_REG_MISC); - data->fan_div[0] = (val >> 6) & 0x03; - data->fan_div[1] = (val >> 4) & 0x03; - - data->alarms &= data->alarm_mask; + data->temp[0] = gl520_read_value(client, GL520_REG_TEMP1); + data->temp_over[0] = + gl520_read_value(client, GL520_REG_TEMP1_OVER); + data->temp_hyst[0] = + gl520_read_value(client, GL520_REG_TEMP1_HYST); - val = gl520_read_value(client, GL520_REG_CONF); - data->beep_enable = (val >> 2) & 1; + val = gl520_read_value(client, GL520_REG_MISC); + data->fan_div[0] = (val >> 6) & 0x03; + data->fan_div[1] = (val >> 4) & 0x03; - data->voltage[0] = gl520_read_value(client,GL520_REG_VDD); - data->voltage[1] = gl520_read_value(client,GL520_REG_VIN1); - data->voltage[2] = gl520_read_value(client,GL520_REG_VIN2); - data->voltage[3] = gl520_read_value(client,GL520_REG_VIN3); + data->alarms &= data->alarm_mask; - /* Temp1 and Vin4 are the same input */ - data->temp[1] = gl520_read_value(client,GL520_REG_TEMP2); - data->temp_over[1] = gl520_read_value(client,GL520_REG_TEMP2_OVER); - data->temp_hyst[1] = gl520_read_value(client,GL520_REG_TEMP2_HYST); - - data->voltage[4] = gl520_read_value(client,GL520_REG_VIN4); - data->voltage_min[4] = gl520_read_value(client,GL520_REG_VIN4_MIN); - data->voltage_max[4] = gl520_read_value(client,GL520_REG_VIN4_MAX); + val = gl520_read_value(client, GL520_REG_CONF); + data->beep_enable = (val >> 2) & 1; - data->last_updated = jiffies; - data->valid = 1; - } + data->voltage[0] = gl520_read_value(client, GL520_REG_VDD); + data->voltage[1] = + gl520_read_value(client, GL520_REG_VIN1); + data->voltage[2] = + gl520_read_value(client, GL520_REG_VIN2); + data->voltage[3] = + gl520_read_value(client, GL520_REG_VIN3); - up(&data->update_lock); + /* Temp1 and Vin4 are the same input */ + data->temp[1] = gl520_read_value(client, GL520_REG_TEMP2); + data->temp_over[1] = + gl520_read_value(client, GL520_REG_TEMP2_OVER); + data->temp_hyst[1] = + gl520_read_value(client, GL520_REG_TEMP2_HYST); + + data->voltage[4] = + gl520_read_value(client, GL520_REG_VIN4); + data->voltage_min[4] = + gl520_read_value(client, GL520_REG_VIN4_MIN); + data->voltage_max[4] = + gl520_read_value(client, GL520_REG_VIN4_MAX); + + data->last_updated = jiffies; + data->valid = 1; + } + + up(&data->update_lock); } void gl520_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct gl520_data *data = client->data; - int nr = ctl_name - GL520_SYSCTL_TEMP1; - int regnr; - - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 1; - else if (operation == SENSORS_PROC_REAL_READ) { - gl520_update_client(client); - results[0] = TEMP_FROM_REG(data->temp_over[nr]); - results[1] = TEMP_FROM_REG(data->temp_hyst[nr]); - results[2] = TEMP_FROM_REG(data->temp[nr]); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if ((nr==0) && (! data->two_temps)) - return; - regnr=nr==0?GL520_REG_TEMP1_OVER:GL520_REG_TEMP2_OVER; - if (*nrels_mag >= 1) { - data->temp_over[nr] = TEMP_TO_REG(results[nr]); - gl520_write_value(client,regnr,data->temp_over[nr]); - } - regnr=nr==0?GL520_REG_TEMP1_HYST:GL520_REG_TEMP2_HYST; - if (*nrels_mag >= 2) { - data->temp_hyst[nr] = TEMP_TO_REG(results[nr]); - gl520_write_value(client,regnr,data->temp_hyst[nr]); - } - } + struct gl520_data *data = client->data; + int nr = ctl_name - GL520_SYSCTL_TEMP1; + int regnr; + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 1; + else if (operation == SENSORS_PROC_REAL_READ) { + gl520_update_client(client); + results[0] = TEMP_FROM_REG(data->temp_over[nr]); + results[1] = TEMP_FROM_REG(data->temp_hyst[nr]); + results[2] = TEMP_FROM_REG(data->temp[nr]); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if ((nr == 0) && (!data->two_temps)) + return; + regnr = + nr == 0 ? GL520_REG_TEMP1_OVER : GL520_REG_TEMP2_OVER; + if (*nrels_mag >= 1) { + data->temp_over[nr] = TEMP_TO_REG(results[nr]); + gl520_write_value(client, regnr, + data->temp_over[nr]); + } + regnr = + nr == 0 ? GL520_REG_TEMP1_HYST : GL520_REG_TEMP2_HYST; + if (*nrels_mag >= 2) { + data->temp_hyst[nr] = TEMP_TO_REG(results[nr]); + gl520_write_value(client, regnr, + data->temp_hyst[nr]); + } + } } -void gl520_vin(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void gl520_vin(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - struct gl520_data *data = client->data; - int nr = ctl_name - GL520_SYSCTL_VDD; - int regnr,old=0; + struct gl520_data *data = client->data; + int nr = ctl_name - GL520_SYSCTL_VDD; + int regnr, old = 0; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 2; - else if (operation == SENSORS_PROC_REAL_READ) { - gl520_update_client(client); - results[0] = nr?IN_FROM_REG(data->voltage_min[nr]): - VDD_FROM_REG(data->voltage_min[nr]); - results[1] = nr?IN_FROM_REG(data->voltage_max[nr]): - VDD_FROM_REG(data->voltage_max[nr]); - results[2] = nr?IN_FROM_REG(data->voltage[nr]): - VDD_FROM_REG(data->voltage[nr]); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (nr!=4) { - regnr=nr==0?GL520_REG_VDD_LIMIT:nr==1?GL520_REG_VIN1_LIMIT:nr==2? - GL520_REG_VIN2_LIMIT:GL520_REG_VIN3_LIMIT; - if (*nrels_mag == 1) - old = gl520_read_value(client,regnr) & 0xff00; - if (*nrels_mag >= 2) { - data->voltage_max[nr] = nr?IN_TO_REG(results[1]):VDD_TO_REG(results[1]); - old = data->voltage_max[nr] << 8; - } - if (*nrels_mag >= 1) { - data->voltage_min[nr] = nr?IN_TO_REG(results[0]):VDD_TO_REG(results[0]); - old |= data->voltage_min[nr]; - gl520_write_value(client,regnr,old); - } - } else if (! data->two_temps) { - if (*nrels_mag == 1) - gl520_write_value(client,GL520_REG_VIN4_MIN,IN_TO_REG(results[0])); - if (*nrels_mag >= 2) - gl520_write_value(client,GL520_REG_VIN4_MAX,IN_TO_REG(results[1])); - } - } -} - - -void gl520_fan(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) -{ - struct gl520_data *data = client->data; - int nr = ctl_name - GL520_SYSCTL_FAN1; - int old; - - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - gl520_update_client(client); - results[0] = FAN_FROM_REG(data->fan_min[nr], - DIV_FROM_REG(data->fan_div[nr])); - results[1] = FAN_FROM_REG(data->fan[nr],DIV_FROM_REG(data->fan_div[nr])); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->fan_min[nr] = FAN_TO_REG(results[0], - DIV_FROM_REG(data->fan_div[nr])); - old = gl520_read_value(client,GL520_REG_FAN_LIMIT); - - if (nr == 0) { - old = (old & 0x00ff) | (data->fan_min[nr] << 8); - if (results[0]==0) - data->alarm_mask &= ~0x20; - else - data->alarm_mask |= 0x20; - } else { - old = (old & 0xff00) | data->fan_min[nr]; - if (results[0]==0) - data->alarm_mask &= ~0x40; - else - data->alarm_mask |= 0x40; - } - gl520_write_value(client,GL520_REG_FAN_LIMIT,old); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + gl520_update_client(client); + results[0] = nr ? IN_FROM_REG(data->voltage_min[nr]) : + VDD_FROM_REG(data->voltage_min[nr]); + results[1] = nr ? IN_FROM_REG(data->voltage_max[nr]) : + VDD_FROM_REG(data->voltage_max[nr]); + results[2] = nr ? IN_FROM_REG(data->voltage[nr]) : + VDD_FROM_REG(data->voltage[nr]); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (nr != 4) { + regnr = + nr == 0 ? GL520_REG_VDD_LIMIT : nr == + 1 ? GL520_REG_VIN1_LIMIT : nr == + 2 ? GL520_REG_VIN2_LIMIT : + GL520_REG_VIN3_LIMIT; + if (*nrels_mag == 1) + old = + gl520_read_value(client, + regnr) & 0xff00; + if (*nrels_mag >= 2) { + data->voltage_max[nr] = + nr ? IN_TO_REG(results[1]) : + VDD_TO_REG(results[1]); + old = data->voltage_max[nr] << 8; + } + if (*nrels_mag >= 1) { + data->voltage_min[nr] = + nr ? IN_TO_REG(results[0]) : + VDD_TO_REG(results[0]); + old |= data->voltage_min[nr]; + gl520_write_value(client, regnr, old); + } + } else if (!data->two_temps) { + if (*nrels_mag == 1) + gl520_write_value(client, + GL520_REG_VIN4_MIN, + IN_TO_REG(results[0])); + if (*nrels_mag >= 2) + gl520_write_value(client, + GL520_REG_VIN4_MAX, + IN_TO_REG(results[1])); + } + } } -void gl520_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void gl520_fan(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - struct gl520_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - gl520_update_client(client); - results[0] = ALARMS_FROM_REG(data->alarms); - *nrels_mag = 1; - } + struct gl520_data *data = client->data; + int nr = ctl_name - GL520_SYSCTL_FAN1; + int old; + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + gl520_update_client(client); + results[0] = FAN_FROM_REG(data->fan_min[nr], + DIV_FROM_REG(data->fan_div[nr])); + results[1] = + FAN_FROM_REG(data->fan[nr], + DIV_FROM_REG(data->fan_div[nr])); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->fan_min[nr] = FAN_TO_REG(results[0], + DIV_FROM_REG(data-> + fan_div + [nr])); + old = + gl520_read_value(client, GL520_REG_FAN_LIMIT); + + if (nr == 0) { + old = + (old & 0x00ff) | (data-> + fan_min[nr] << 8); + if (results[0] == 0) + data->alarm_mask &= ~0x20; + else + data->alarm_mask |= 0x20; + } else { + old = (old & 0xff00) | data->fan_min[nr]; + if (results[0] == 0) + data->alarm_mask &= ~0x40; + else + data->alarm_mask |= 0x40; + } + gl520_write_value(client, GL520_REG_FAN_LIMIT, + old); + } + } } -void gl520_beep(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + +void gl520_alarms(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - struct gl520_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - gl520_update_client(client); - results[0] = BEEP_ENABLE_FROM_REG(data->beep_enable); - results[1] = BEEPS_FROM_REG(data->beeps); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->beep_enable = BEEP_ENABLE_TO_REG(results[0]); - gl520_write_value(client,GL520_REG_CONF, - (gl520_read_value(client,GL520_REG_CONF) & 0xfb) | - (data->beep_enable << 2)); - } - if (*nrels_mag >= 2) { - data->beeps = BEEPS_TO_REG(results[1]) & data->alarm_mask; - gl520_write_value(client,GL520_REG_ALARM,data->beeps); - } - } + struct gl520_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + gl520_update_client(client); + results[0] = ALARMS_FROM_REG(data->alarms); + *nrels_mag = 1; + } +} + +void gl520_beep(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) +{ + struct gl520_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + gl520_update_client(client); + results[0] = BEEP_ENABLE_FROM_REG(data->beep_enable); + results[1] = BEEPS_FROM_REG(data->beeps); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->beep_enable = BEEP_ENABLE_TO_REG(results[0]); + gl520_write_value(client, GL520_REG_CONF, + (gl520_read_value(client, + GL520_REG_CONF) + & 0xfb) | (data-> + beep_enable << 2)); + } + if (*nrels_mag >= 2) { + data->beeps = + BEEPS_TO_REG(results[1]) & data->alarm_mask; + gl520_write_value(client, GL520_REG_ALARM, + data->beeps); + } + } } void gl520_fan_div(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct gl520_data *data = client->data; - int old; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - gl520_update_client(client); - results[0] = DIV_FROM_REG(data->fan_div[0]); - results[1] = DIV_FROM_REG(data->fan_div[1]); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - old = gl520_read_value(client,GL520_REG_MISC); - if (*nrels_mag >= 2) { - data->fan_div[1] = DIV_TO_REG(results[1]); - old = (old & 0xcf) | (data->fan_div[1] << 4); - } - if (*nrels_mag >= 1) { - data->fan_div[0] = DIV_TO_REG(results[0]); - old = (old & 0x3f) | (data->fan_div[0] << 6); - } - gl520_write_value(client,GL520_REG_MISC,old); - } + struct gl520_data *data = client->data; + int old; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + gl520_update_client(client); + results[0] = DIV_FROM_REG(data->fan_div[0]); + results[1] = DIV_FROM_REG(data->fan_div[1]); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + old = gl520_read_value(client, GL520_REG_MISC); + if (*nrels_mag >= 2) { + data->fan_div[1] = DIV_TO_REG(results[1]); + old = (old & 0xcf) | (data->fan_div[1] << 4); + } + if (*nrels_mag >= 1) { + data->fan_div[0] = DIV_TO_REG(results[0]); + old = (old & 0x3f) | (data->fan_div[0] << 6); + } + gl520_write_value(client, GL520_REG_MISC, old); + } } void gl520_vid(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct gl520_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 2; - else if (operation == SENSORS_PROC_REAL_READ) { - gl520_update_client(client); - results[0] = VID_FROM_REG(data->vid); - *nrels_mag = 1; - } + struct gl520_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + gl520_update_client(client); + results[0] = VID_FROM_REG(data->vid); + *nrels_mag = 1; + } } -void gl520_fan1off(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void gl520_fan1off(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - int old; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - results[0] = ((gl520_read_value(client, GL520_REG_MISC) & 0x04) !=0); - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - old = gl520_read_value(client, GL520_REG_MISC) & 0xfb; - if (results[0]) - old |= 0x04; - gl520_write_value(client,GL520_REG_MISC,old); - } - } + int old; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + results[0] = + ((gl520_read_value(client, GL520_REG_MISC) & 0x04) != + 0); + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + old = + gl520_read_value(client, + GL520_REG_MISC) & 0xfb; + if (results[0]) + old |= 0x04; + gl520_write_value(client, GL520_REG_MISC, old); + } + } } -void gl520_config(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void gl520_config(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - struct gl520_data *data = client->data; - int old; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - results[0] = ((gl520_read_value(client, GL520_REG_CONF) & 0x10)==0); - data->two_temps = results[0]; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - old = gl520_read_value(client, GL520_REG_CONF) & 0xef; - if (! results[1]) { - old |= 0x10; - data->two_temps=0; - } else { - data->two_temps=1; - } - gl520_write_value(client,GL520_REG_CONF,old); - } - } + struct gl520_data *data = client->data; + int old; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + results[0] = + ((gl520_read_value(client, GL520_REG_CONF) & 0x10) == + 0); + data->two_temps = results[0]; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + old = + gl520_read_value(client, + GL520_REG_CONF) & 0xef; + if (!results[1]) { + old |= 0x10; + data->two_temps = 0; + } else { + data->two_temps = 1; + } + gl520_write_value(client, GL520_REG_CONF, old); + } + } } int __init sensors_gl520_init(void) { - int res; + int res; - printk("gl520sm.o version %s (%s)\n",LM_VERSION,LM_DATE); - gl520_initialized = 0; - if ((res = i2c_add_driver(&gl520_driver))) { - printk("gl520sm.o: Driver registration failed, module not inserted.\n"); - gl520_cleanup(); - return res; - } - gl520_initialized ++; - return 0; + printk("gl520sm.o version %s (%s)\n", LM_VERSION, LM_DATE); + gl520_initialized = 0; + if ((res = i2c_add_driver(&gl520_driver))) { + printk + ("gl520sm.o: Driver registration failed, module not inserted.\n"); + gl520_cleanup(); + return res; + } + gl520_initialized++; + return 0; } int __init gl520_cleanup(void) { - int res; + int res; - if (gl520_initialized >= 1) { - if ((res = i2c_del_driver(&gl520_driver))) { - printk("gl520.o: Driver deregistration failed, module not removed.\n"); - return res; - } - gl520_initialized --; - } + if (gl520_initialized >= 1) { + if ((res = i2c_del_driver(&gl520_driver))) { + printk + ("gl520.o: Driver deregistration failed, module not removed.\n"); + return res; + } + gl520_initialized--; + } - return 0; + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard and Kyösti Mälkki "); +MODULE_AUTHOR + ("Frodo Looijaard and Kyösti Mälkki "); MODULE_DESCRIPTION("GL520SM driver"); int init_module(void) { - return sensors_gl520_init(); + return sensors_gl520_init(); } int cleanup_module(void) { - return gl520_cleanup(); + return gl520_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/icspll.c b/kernel/chips/icspll.c index c01fa68a..eca7be2e 100644 --- a/kernel/chips/icspll.c +++ b/kernel/chips/icspll.c @@ -53,56 +53,57 @@ /* Each client has this additional data */ struct icspll_data { - int sysctl_id; + int sysctl_id; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ - u8 data[ICSPLL_SIZE]; /* Register values */ - int memtype; + u8 data[ICSPLL_SIZE]; /* Register values */ + int memtype; }; #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ #ifdef MODULE static #else extern #endif - int __init sensors_icspll_init(void); +int __init sensors_icspll_init(void); static int __init icspll_cleanup(void); static int icspll_attach_adapter(struct i2c_adapter *adapter); static int icspll_detach_client(struct i2c_client *client); static int icspll_command(struct i2c_client *client, unsigned int cmd, - void *arg); - -static void icspll_inc_use (struct i2c_client *client); -static void icspll_dec_use (struct i2c_client *client); + void *arg); + +static void icspll_inc_use(struct i2c_client *client); +static void icspll_dec_use(struct i2c_client *client); #if 0 -static int icspll_write_value(struct i2c_client *client, u8 reg, u16 value); +static int icspll_write_value(struct i2c_client *client, u8 reg, + u16 value); #endif -static void icspll_contents(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); +static void icspll_contents(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static void icspll_update_client(struct i2c_client *client); /* This is the driver that will be inserted */ static struct i2c_driver icspll_driver = { - /* name */ "ICS/PLL clock reader", - /* id */ I2C_DRIVERID_ICSPLL, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &icspll_attach_adapter, - /* detach_client */ &icspll_detach_client, - /* command */ &icspll_command, - /* inc_use */ &icspll_inc_use, - /* dec_use */ &icspll_dec_use + /* name */ "ICS/PLL clock reader", + /* id */ I2C_DRIVERID_ICSPLL, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &icspll_attach_adapter, + /* detach_client */ &icspll_detach_client, + /* command */ &icspll_command, + /* inc_use */ &icspll_inc_use, + /* dec_use */ &icspll_dec_use }; /* These files are created for each detected ICSPLL. This is just a template; @@ -111,9 +112,9 @@ static struct i2c_driver icspll_driver = { is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table icspll_dir_table_template[] = { - { ICSPLL_SYSCTL1, "reg0-6", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &icspll_contents }, - { 0 } + {ICSPLL_SYSCTL1, "reg0-6", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &icspll_contents}, + {0} }; /* holding place for data - block read could be as much as 32 */ @@ -125,119 +126,124 @@ static int __initdata icspll_initialized = 0; static int icspll_id = 0; int icspll_attach_adapter(struct i2c_adapter *adapter) { - int address,err,i; - struct i2c_client *new_client; - struct icspll_data *data; + int address, err, i; + struct i2c_client *new_client; + struct icspll_data *data; - err = 0; - /* Make sure we aren't probing the ISA bus!! */ - if (i2c_is_isa_adapter(adapter)) return 0; - - /* OK, this is no detection. I know. It will do for now, though. */ + err = 0; + /* Make sure we aren't probing the ISA bus!! */ + if (i2c_is_isa_adapter(adapter)) + return 0; - /* Set err only if a global error would make registering other clients - impossible too (like out-of-memory). */ - - /* ICS and PLL clock chips seem to all be at 0x69. - Don't know what is out there at 0x6A, don't scan that yet. */ + /* OK, this is no detection. I know. It will do for now, though. */ - for (address = 0x69; (! err) && (address <= 0x69); address ++) { + /* Set err only if a global error would make registering other clients + impossible too (like out-of-memory). */ - /* Later on, we will keep a list of registered addresses for each - adapter, and check whether they are used here */ - - /* these chips only support block transfers so use that for detection */ - if(i2c_smbus_read_block_data(adapter, address, 0x00, tempdata) < 0) { + /* ICS and PLL clock chips seem to all be at 0x69. + Don't know what is out there at 0x6A, don't scan that yet. */ + + for (address = 0x69; (!err) && (address <= 0x69); address++) { + + /* Later on, we will keep a list of registered addresses for each + adapter, and check whether they are used here */ + + /* these chips only support block transfers so use that for detection */ + if (i2c_smbus_read_block_data + (adapter, address, 0x00, tempdata) < 0) { #ifdef DEBUG - printk("icspll.o: No icspll found at: 0x%X\n",address); + printk("icspll.o: No icspll found at: 0x%X\n", + address); #endif - continue; - } + continue; + } - /* Real detection code goes here */ + /* Real detection code goes here */ - /* Allocate space for a new client structure */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct icspll_data), - GFP_KERNEL))) { - err = -ENOMEM; - continue; - } + /* Allocate space for a new client structure */ + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct icspll_data), + GFP_KERNEL))) { + err = -ENOMEM; + continue; + } - /* Fill the new client structure with data */ - data = (struct icspll_data *) (new_client + 1); - new_client->data = data; - new_client->id = icspll_id++; - new_client->addr = address; - new_client->adapter = adapter; - new_client->driver = &icspll_driver; - new_client->flags = 0; - strcpy(new_client->name,"ICSPLL chip"); - data->valid = 0; - init_MUTEX(&data->update_lock); + /* Fill the new client structure with data */ + data = (struct icspll_data *) (new_client + 1); + new_client->data = data; + new_client->id = icspll_id++; + new_client->addr = address; + new_client->adapter = adapter; + new_client->driver = &icspll_driver; + new_client->flags = 0; + strcpy(new_client->name, "ICSPLL chip"); + data->valid = 0; + init_MUTEX(&data->update_lock); /* fill data structure so unknown registers are 0xFF */ - data->data[0] = ICSPLL_SIZE; - for(i = 1; i <= ICSPLL_SIZE; i++) - data->data[i] = 0xFF; - - /* Tell i2c-core a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR2; - - /* Register a new directory entry with module sensors */ - if ((err = sensors_register_entry(new_client,"icspll", - icspll_dir_table_template - THIS_MODULE)) < 0) - goto ERROR3; - data->sysctl_id = err; - err = 0; + data->data[0] = ICSPLL_SIZE; + for (i = 1; i <= ICSPLL_SIZE; i++) + data->data[i] = 0xFF; - continue; + /* Tell i2c-core a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR2; + + /* Register a new directory entry with module sensors */ + if ((err = sensors_register_entry(new_client, "icspll", + icspll_dir_table_template + THIS_MODULE)) < 0) + goto ERROR3; + data->sysctl_id = err; + err = 0; + + continue; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR3: - i2c_detach_client(new_client); -ERROR2: -ERROR1: - kfree(new_client); - } - return err; + ERROR3: + i2c_detach_client(new_client); + ERROR2: + ERROR1: + kfree(new_client); + } + return err; } int icspll_detach_client(struct i2c_client *client) { - int err,i; + int err, i; - sensors_deregister_entry(((struct icspll_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct icspll_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("icspll.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("icspll.o: Client deregistration failed, client not detached.\n"); + return err; + } - kfree(client); - return 0; + kfree(client); + return 0; } /* No commands defined yet */ int icspll_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } -void icspll_inc_use (struct i2c_client *client) +void icspll_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } -void icspll_dec_use (struct i2c_client *client) +void icspll_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } @@ -245,111 +251,117 @@ void icspll_dec_use (struct i2c_client *client) /* No writes yet (PAE) */ int icspll_write_value(struct i2c_client *client, u8 reg, u16 value) { - return i2c_smbus_write_block_data(client->adapter,client->addr,reg,value); + return i2c_smbus_write_block_data(client->adapter, client->addr, + reg, value); } #endif void icspll_update_client(struct i2c_client *client) { - struct icspll_data *data = client->data; - int i, len; + struct icspll_data *data = client->data; + int i, len; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > HZ+HZ/2 ) || - (jiffies < data->last_updated) || ! data->valid) { + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { - len = i2c_smbus_read_block_data(client->adapter, client->addr, 0x00, tempdata); + len = + i2c_smbus_read_block_data(client->adapter, + client->addr, 0x00, + tempdata); #ifdef DEBUG - printk("icspll.o: read returned %d values\n", len); + printk("icspll.o: read returned %d values\n", len); #endif - if(len > ICSPLL_SIZE) - len = ICSPLL_SIZE; - for(i = 0; i < len; i++) - data->data[i] = tempdata[i]; - - data->last_updated = jiffies; - data->valid = 1; - } + if (len > ICSPLL_SIZE) + len = ICSPLL_SIZE; + for (i = 0; i < len; i++) + data->data[i] = tempdata[i]; - up(&data->update_lock); + data->last_updated = jiffies; + data->valid = 1; + } + + up(&data->update_lock); } -void icspll_contents(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void icspll_contents(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - int i; - struct icspll_data *data = client->data; - - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - icspll_update_client(client); - for (i=0; i< ICSPLL_SIZE; i++) { - results[i]=data->data[i]; - } + int i; + struct icspll_data *data = client->data; + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + icspll_update_client(client); + for (i = 0; i < ICSPLL_SIZE; i++) { + results[i] = data->data[i]; + } #ifdef DEBUG - printk("icspll.o: 0x%X ICSPLL Contents: ",client->addr); - for (i=0; i< ICSPLL_SIZE; i++) { - printk(" 0x%X",data->data[i]); - } - printk(" .\n"); + printk("icspll.o: 0x%X ICSPLL Contents: ", client->addr); + for (i = 0; i < ICSPLL_SIZE; i++) { + printk(" 0x%X", data->data[i]); + } + printk(" .\n"); #endif - *nrels_mag = ICSPLL_SIZE; - } else if (operation == SENSORS_PROC_REAL_WRITE) { + *nrels_mag = ICSPLL_SIZE; + } else if (operation == SENSORS_PROC_REAL_WRITE) { /* No writes to the ICSPLL (yet, anyway) (PAE) */ - printk("icspll.o: No writes to ICSPLLs supported!\n"); - } + printk("icspll.o: No writes to ICSPLLs supported!\n"); + } } int __init sensors_icspll_init(void) { - int res; + int res; - printk("icspll.o version %s (%s)\n",LM_VERSION,LM_DATE); - icspll_initialized = 0; - if ((res = i2c_add_driver(&icspll_driver))) { - printk("icspll.o: Driver registration failed, module not inserted.\n"); - icspll_cleanup(); - return res; - } - icspll_initialized ++; - return 0; + printk("icspll.o version %s (%s)\n", LM_VERSION, LM_DATE); + icspll_initialized = 0; + if ((res = i2c_add_driver(&icspll_driver))) { + printk + ("icspll.o: Driver registration failed, module not inserted.\n"); + icspll_cleanup(); + return res; + } + icspll_initialized++; + return 0; } int __init icspll_cleanup(void) { - int res; + int res; - if (icspll_initialized >= 1) { - if ((res = i2c_del_driver(&icspll_driver))) { - printk("icspll.o: Driver deregistration failed, module not removed.\n"); - return res; - } - } else - icspll_initialized --; + if (icspll_initialized >= 1) { + if ((res = i2c_del_driver(&icspll_driver))) { + printk + ("icspll.o: Driver deregistration failed, module not removed.\n"); + return res; + } + } else + icspll_initialized--; - return 0; + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard , Philip Edelbrock , and Mark Studebaker "); +MODULE_AUTHOR + ("Frodo Looijaard , Philip Edelbrock , and Mark Studebaker "); MODULE_DESCRIPTION("ICSPLL driver"); int init_module(void) { - return sensors_icspll_init(); + return sensors_icspll_init(); } int cleanup_module(void) { - return icspll_cleanup(); + return icspll_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/lm75.c b/kernel/chips/lm75.c index e517a3c4..6a484e33 100644 --- a/kernel/chips/lm75.c +++ b/kernel/chips/lm75.c @@ -37,10 +37,10 @@ #endif /* Addresses to scan */ -static unsigned short normal_i2c[] = {SENSORS_I2C_END}; -static unsigned short normal_i2c_range[] = {0x48,0x4f,SENSORS_I2C_END}; -static unsigned int normal_isa[] = {SENSORS_ISA_END}; -static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; +static unsigned short normal_i2c[] = { SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { 0x48, 0x4f, SENSORS_I2C_END }; +static unsigned int normal_isa[] = { SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; /* Insmod parameters */ SENSORS_INSMOD_1(lm75); @@ -66,54 +66,54 @@ SENSORS_INSMOD_1(lm75); /* Each client has this additional data */ struct lm75_data { - int sysctl_id; + int sysctl_id; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ - u16 temp,temp_os,temp_hyst; /* Register values */ + u16 temp, temp_os, temp_hyst; /* Register values */ }; #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ #ifdef MODULE static #else extern #endif - int __init sensors_lm75_init(void); +int __init sensors_lm75_init(void); static int __init lm75_cleanup(void); static int lm75_attach_adapter(struct i2c_adapter *adapter); -static int lm75_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind); +static int lm75_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); static void lm75_init_client(struct i2c_client *client); static int lm75_detach_client(struct i2c_client *client); static int lm75_command(struct i2c_client *client, unsigned int cmd, - void *arg); -static void lm75_inc_use (struct i2c_client *client); -static void lm75_dec_use (struct i2c_client *client); + void *arg); +static void lm75_inc_use(struct i2c_client *client); +static void lm75_dec_use(struct i2c_client *client); static u16 swap_bytes(u16 val); static int lm75_read_value(struct i2c_client *client, u8 reg); static int lm75_write_value(struct i2c_client *client, u8 reg, u16 value); -static void lm75_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); +static void lm75_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static void lm75_update_client(struct i2c_client *client); /* This is the driver that will be inserted */ static struct i2c_driver lm75_driver = { - /* name */ "LM75 sensor chip driver", - /* id */ I2C_DRIVERID_LM75, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &lm75_attach_adapter, - /* detach_client */ &lm75_detach_client, - /* command */ &lm75_command, - /* inc_use */ &lm75_inc_use, - /* dec_use */ &lm75_dec_use + /* name */ "LM75 sensor chip driver", + /* id */ I2C_DRIVERID_LM75, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &lm75_attach_adapter, + /* detach_client */ &lm75_detach_client, + /* command */ &lm75_command, + /* inc_use */ &lm75_inc_use, + /* dec_use */ &lm75_dec_use }; /* These files are created for each detected LM75. This is just a template; @@ -122,9 +122,9 @@ static struct i2c_driver lm75_driver = { is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table lm75_dir_table_template[] = { - { LM75_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm75_temp }, - { 0 } + {LM75_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm75_temp}, + {0} }; /* Used by init/cleanup */ @@ -134,153 +134,163 @@ static int lm75_id = 0; int lm75_attach_adapter(struct i2c_adapter *adapter) { - return sensors_detect(adapter,&addr_data,lm75_detect); + return sensors_detect(adapter, &addr_data, lm75_detect); } /* This function is called by sensors_detect */ -int lm75_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind) +int lm75_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) { - int i,cur,conf,hyst,os; - struct i2c_client *new_client; - struct lm75_data *data; - int err=0; - const char *type_name,*client_name; + int i, cur, conf, hyst, os; + struct i2c_client *new_client; + struct lm75_data *data; + int err = 0; + const char *type_name, *client_name; - /* Make sure we aren't probing the ISA bus!! This is just a safety check - at this moment; sensors_detect really won't call us. */ + /* Make sure we aren't probing the ISA bus!! This is just a safety check + at this moment; sensors_detect really won't call us. */ #ifdef DEBUG - if (i2c_is_isa_adapter(adapter)) { - printk("lm75.o: lm75_detect called for an ISA bus adapter?!?\n"); - return 0; - } + if (i2c_is_isa_adapter(adapter)) { + printk + ("lm75.o: lm75_detect called for an ISA bus adapter?!?\n"); + return 0; + } #endif - if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_BYTE_DATA | - I2C_FUNC_SMBUS_WORD_DATA)) - goto ERROR0; + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA | + I2C_FUNC_SMBUS_WORD_DATA)) + goto ERROR0; - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access lm75_{read,write}_value. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct lm75_data), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR0; - } + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access lm75_{read,write}_value. */ + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct lm75_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } - data = (struct lm75_data *) (new_client + 1); - new_client->addr = address; - new_client->data = data; - new_client->adapter = adapter; - new_client->driver = &lm75_driver; - new_client->flags = 0; + data = (struct lm75_data *) (new_client + 1); + new_client->addr = address; + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &lm75_driver; + new_client->flags = 0; - /* Now, we do the remaining detection. It is lousy. */ - if (kind < 0) { - cur = i2c_smbus_read_word_data(new_client,0); - conf = i2c_smbus_read_byte_data(new_client,1); - hyst = i2c_smbus_read_word_data(new_client,2); - os = i2c_smbus_read_word_data(new_client,3); - for (i = 0; i <= 0x1f; i++) - if ((i2c_smbus_read_byte_data(new_client,i*8+1) != conf) || - (i2c_smbus_read_word_data(new_client,i*8+2) != hyst) || - (i2c_smbus_read_word_data(new_client,i*8+3) != os)) - goto ERROR1; - } - - /* Determine the chip type - only one kind supported! */ - if (kind <= 0) - kind = lm75; + /* Now, we do the remaining detection. It is lousy. */ + if (kind < 0) { + cur = i2c_smbus_read_word_data(new_client, 0); + conf = i2c_smbus_read_byte_data(new_client, 1); + hyst = i2c_smbus_read_word_data(new_client, 2); + os = i2c_smbus_read_word_data(new_client, 3); + for (i = 0; i <= 0x1f; i++) + if ( + (i2c_smbus_read_byte_data + (new_client, i * 8 + 1) != conf) + || + (i2c_smbus_read_word_data + (new_client, i * 8 + 2) != hyst) + || + (i2c_smbus_read_word_data + (new_client, i * 8 + 3) != os)) + goto ERROR1; + } - if (kind == lm75) { - type_name = "lm75"; - client_name = "LM75 chip"; - } else { + /* Determine the chip type - only one kind supported! */ + if (kind <= 0) + kind = lm75; + + if (kind == lm75) { + type_name = "lm75"; + client_name = "LM75 chip"; + } else { #ifdef DEBUG - printk("lm75.o: Internal error: unknown kind (%d)?!?",kind); + printk("lm75.o: Internal error: unknown kind (%d)?!?", + kind); #endif - goto ERROR1; - } - - /* Fill in the remaining client fields and put it into the global list */ - strcpy(new_client->name,client_name); + goto ERROR1; + } - new_client->id = lm75_id++; - data->valid = 0; - init_MUTEX(&data->update_lock); - - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); - /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry(new_client,type_name, - lm75_dir_table_template, - THIS_MODULE)) < 0) { - err = i; - goto ERROR4; - } - data->sysctl_id = i; + new_client->id = lm75_id++; + data->valid = 0; + init_MUTEX(&data->update_lock); - lm75_init_client(new_client); - return 0; + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; + + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry(new_client, type_name, + lm75_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; + + lm75_init_client(new_client); + return 0; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR4: - i2c_detach_client(new_client); -ERROR3: -ERROR1: - kfree(new_client); -ERROR0: - return err; + ERROR4: + i2c_detach_client(new_client); + ERROR3: + ERROR1: + kfree(new_client); + ERROR0: + return err; } int lm75_detach_client(struct i2c_client *client) { - int err; + int err; - sensors_deregister_entry(((struct lm75_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct lm75_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("lm75.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("lm75.o: Client deregistration failed, client not detached.\n"); + return err; + } - kfree(client); + kfree(client); - return 0; + return 0; } /* No commands defined yet */ int lm75_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } /* Nothing here yet */ -void lm75_inc_use (struct i2c_client *client) +void lm75_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } /* Nothing here yet */ -void lm75_dec_use (struct i2c_client *client) +void lm75_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } u16 swap_bytes(u16 val) { - return (val >> 8) | (val << 8); + return (val >> 8) | (val << 8); } /* All registers are word-sized, except for the configuration register. @@ -288,10 +298,10 @@ u16 swap_bytes(u16 val) the usual practice. */ int lm75_read_value(struct i2c_client *client, u8 reg) { - if (reg == LM75_REG_CONF) - return i2c_smbus_read_byte_data(client,reg); - else - return swap_bytes(i2c_smbus_read_word_data(client,reg)); + if (reg == LM75_REG_CONF) + return i2c_smbus_read_byte_data(client, reg); + else + return swap_bytes(i2c_smbus_read_word_data(client, reg)); } /* All registers are word-sized, except for the configuration register. @@ -299,99 +309,104 @@ int lm75_read_value(struct i2c_client *client, u8 reg) the usual practice. */ int lm75_write_value(struct i2c_client *client, u8 reg, u16 value) { - if (reg == LM75_REG_CONF) - return i2c_smbus_write_byte_data(client,reg,value); - else - return i2c_smbus_write_word_data(client,reg, - swap_bytes(value)); + if (reg == LM75_REG_CONF) + return i2c_smbus_write_byte_data(client, reg, value); + else + return i2c_smbus_write_word_data(client, reg, + swap_bytes(value)); } void lm75_init_client(struct i2c_client *client) { - /* Initialize the LM75 chip */ - lm75_write_value(client,LM75_REG_TEMP_OS, - TEMP_TO_REG(LM75_INIT_TEMP_OS)); - lm75_write_value(client,LM75_REG_TEMP_HYST, - TEMP_TO_REG(LM75_INIT_TEMP_HYST)); - lm75_write_value(client,LM75_REG_CONF,0); + /* Initialize the LM75 chip */ + lm75_write_value(client, LM75_REG_TEMP_OS, + TEMP_TO_REG(LM75_INIT_TEMP_OS)); + lm75_write_value(client, LM75_REG_TEMP_HYST, + TEMP_TO_REG(LM75_INIT_TEMP_HYST)); + lm75_write_value(client, LM75_REG_CONF, 0); } void lm75_update_client(struct i2c_client *client) { - struct lm75_data *data = client->data; + struct lm75_data *data = client->data; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > HZ+HZ/2 ) || - (jiffies < data->last_updated) || ! data->valid) { + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("Starting lm75 update\n"); + printk("Starting lm75 update\n"); #endif - data->temp = lm75_read_value(client,LM75_REG_TEMP); - data->temp_os = lm75_read_value(client,LM75_REG_TEMP_OS); - data->temp_hyst = lm75_read_value(client,LM75_REG_TEMP_HYST); - data->last_updated = jiffies; - data->valid = 1; - } + data->temp = lm75_read_value(client, LM75_REG_TEMP); + data->temp_os = lm75_read_value(client, LM75_REG_TEMP_OS); + data->temp_hyst = + lm75_read_value(client, LM75_REG_TEMP_HYST); + data->last_updated = jiffies; + data->valid = 1; + } - up(&data->update_lock); + up(&data->update_lock); } void lm75_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct lm75_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 1; - else if (operation == SENSORS_PROC_REAL_READ) { - lm75_update_client(client); - results[0] = TEMP_FROM_REG(data->temp_os); - results[1] = TEMP_FROM_REG(data->temp_hyst); - results[2] = TEMP_FROM_REG(data->temp); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->temp_os = TEMP_TO_REG(results[0]); - lm75_write_value(client,LM75_REG_TEMP_OS,data->temp_os); - } - if (*nrels_mag >= 2) { - data->temp_hyst = TEMP_TO_REG(results[1]); - lm75_write_value(client,LM75_REG_TEMP_HYST,data->temp_hyst); - } - } + struct lm75_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 1; + else if (operation == SENSORS_PROC_REAL_READ) { + lm75_update_client(client); + results[0] = TEMP_FROM_REG(data->temp_os); + results[1] = TEMP_FROM_REG(data->temp_hyst); + results[2] = TEMP_FROM_REG(data->temp); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->temp_os = TEMP_TO_REG(results[0]); + lm75_write_value(client, LM75_REG_TEMP_OS, + data->temp_os); + } + if (*nrels_mag >= 2) { + data->temp_hyst = TEMP_TO_REG(results[1]); + lm75_write_value(client, LM75_REG_TEMP_HYST, + data->temp_hyst); + } + } } int __init sensors_lm75_init(void) { - int res; + int res; - printk("lm75.o version %s (%s)\n",LM_VERSION,LM_DATE); - lm75_initialized = 0; - if ((res = i2c_add_driver(&lm75_driver))) { - printk("lm75.o: Driver registration failed, module not inserted.\n"); - lm75_cleanup(); - return res; - } - lm75_initialized ++; - return 0; + printk("lm75.o version %s (%s)\n", LM_VERSION, LM_DATE); + lm75_initialized = 0; + if ((res = i2c_add_driver(&lm75_driver))) { + printk + ("lm75.o: Driver registration failed, module not inserted.\n"); + lm75_cleanup(); + return res; + } + lm75_initialized++; + return 0; } int __init lm75_cleanup(void) { - int res; + int res; - if (lm75_initialized >= 1) { - if ((res = i2c_del_driver(&lm75_driver))) { - printk("lm75.o: Driver deregistration failed, module not removed.\n"); - return res; - } - lm75_initialized --; - } + if (lm75_initialized >= 1) { + if ((res = i2c_del_driver(&lm75_driver))) { + printk + ("lm75.o: Driver deregistration failed, module not removed.\n"); + return res; + } + lm75_initialized--; + } - return 0; + return 0; } EXPORT_NO_SYMBOLS; @@ -403,13 +418,12 @@ MODULE_DESCRIPTION("LM75 driver"); int init_module(void) { - return sensors_lm75_init(); + return sensors_lm75_init(); } int cleanup_module(void) { - return lm75_cleanup(); + return lm75_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/lm78.c b/kernel/chips/lm78.c index 5afb81f8..f1e0ed09 100644 --- a/kernel/chips/lm78.c +++ b/kernel/chips/lm78.c @@ -42,13 +42,13 @@ #endif /* Addresses to scan */ -static unsigned short normal_i2c[] = {SENSORS_I2C_END}; -static unsigned short normal_i2c_range[] = {0x20,0x2f,SENSORS_I2C_END}; -static unsigned int normal_isa[] = {0x0290,SENSORS_ISA_END}; -static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; +static unsigned short normal_i2c[] = { SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { 0x20, 0x2f, SENSORS_I2C_END }; +static unsigned int normal_isa[] = { 0x0290, SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_3(lm78,lm78j,lm79); +SENSORS_INSMOD_3(lm78, lm78j, lm79); /* Many LM78 constants specified below */ @@ -90,10 +90,11 @@ SENSORS_INSMOD_3(lm78,lm78j,lm79); extern inline u8 FAN_TO_REG(long rpm, int div) { - if (rpm == 0) - return 255; - rpm = SENSORS_LIMIT(rpm,1,1000000); - return SENSORS_LIMIT((1350000 + rpm*div/2) / (rpm*div),1,254); + if (rpm == 0) + return 255; + rpm = SENSORS_LIMIT(rpm, 1, 1000000); + return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, + 254); } #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) @@ -122,33 +123,33 @@ extern inline u8 FAN_TO_REG(long rpm, int div) #define LM78_INIT_IN_PERCENTAGE 10 #define LM78_INIT_IN_MIN_0 \ - (LM78_INIT_IN_0 - LM78_INIT_IN_0 * LM78_INIT_IN_PERCENTAGE / 100) + (LM78_INIT_IN_0 - LM78_INIT_IN_0 * LM78_INIT_IN_PERCENTAGE / 100) #define LM78_INIT_IN_MAX_0 \ - (LM78_INIT_IN_0 + LM78_INIT_IN_0 * LM78_INIT_IN_PERCENTAGE / 100) + (LM78_INIT_IN_0 + LM78_INIT_IN_0 * LM78_INIT_IN_PERCENTAGE / 100) #define LM78_INIT_IN_MIN_1 \ - (LM78_INIT_IN_1 - LM78_INIT_IN_1 * LM78_INIT_IN_PERCENTAGE / 100) + (LM78_INIT_IN_1 - LM78_INIT_IN_1 * LM78_INIT_IN_PERCENTAGE / 100) #define LM78_INIT_IN_MAX_1 \ - (LM78_INIT_IN_1 + LM78_INIT_IN_1 * LM78_INIT_IN_PERCENTAGE / 100) + (LM78_INIT_IN_1 + LM78_INIT_IN_1 * LM78_INIT_IN_PERCENTAGE / 100) #define LM78_INIT_IN_MIN_2 \ - (LM78_INIT_IN_2 - LM78_INIT_IN_2 * LM78_INIT_IN_PERCENTAGE / 100) + (LM78_INIT_IN_2 - LM78_INIT_IN_2 * LM78_INIT_IN_PERCENTAGE / 100) #define LM78_INIT_IN_MAX_2 \ - (LM78_INIT_IN_2 + LM78_INIT_IN_2 * LM78_INIT_IN_PERCENTAGE / 100) + (LM78_INIT_IN_2 + LM78_INIT_IN_2 * LM78_INIT_IN_PERCENTAGE / 100) #define LM78_INIT_IN_MIN_3 \ - (LM78_INIT_IN_3 - LM78_INIT_IN_3 * LM78_INIT_IN_PERCENTAGE / 100) + (LM78_INIT_IN_3 - LM78_INIT_IN_3 * LM78_INIT_IN_PERCENTAGE / 100) #define LM78_INIT_IN_MAX_3 \ - (LM78_INIT_IN_3 + LM78_INIT_IN_3 * LM78_INIT_IN_PERCENTAGE / 100) + (LM78_INIT_IN_3 + LM78_INIT_IN_3 * LM78_INIT_IN_PERCENTAGE / 100) #define LM78_INIT_IN_MIN_4 \ - (LM78_INIT_IN_4 - LM78_INIT_IN_4 * LM78_INIT_IN_PERCENTAGE / 100) + (LM78_INIT_IN_4 - LM78_INIT_IN_4 * LM78_INIT_IN_PERCENTAGE / 100) #define LM78_INIT_IN_MAX_4 \ - (LM78_INIT_IN_4 + LM78_INIT_IN_4 * LM78_INIT_IN_PERCENTAGE / 100) + (LM78_INIT_IN_4 + LM78_INIT_IN_4 * LM78_INIT_IN_PERCENTAGE / 100) #define LM78_INIT_IN_MIN_5 \ - (LM78_INIT_IN_5 - LM78_INIT_IN_5 * LM78_INIT_IN_PERCENTAGE / 100) + (LM78_INIT_IN_5 - LM78_INIT_IN_5 * LM78_INIT_IN_PERCENTAGE / 100) #define LM78_INIT_IN_MAX_5 \ - (LM78_INIT_IN_5 + LM78_INIT_IN_5 * LM78_INIT_IN_PERCENTAGE / 100) + (LM78_INIT_IN_5 + LM78_INIT_IN_5 * LM78_INIT_IN_PERCENTAGE / 100) #define LM78_INIT_IN_MIN_6 \ - (LM78_INIT_IN_6 - LM78_INIT_IN_6 * LM78_INIT_IN_PERCENTAGE / 100) + (LM78_INIT_IN_6 - LM78_INIT_IN_6 * LM78_INIT_IN_PERCENTAGE / 100) #define LM78_INIT_IN_MAX_6 \ - (LM78_INIT_IN_6 + LM78_INIT_IN_6 * LM78_INIT_IN_PERCENTAGE / 100) + (LM78_INIT_IN_6 + LM78_INIT_IN_6 * LM78_INIT_IN_PERCENTAGE / 100) #define LM78_INIT_FAN_MIN_1 3000 #define LM78_INIT_FAN_MIN_2 3000 @@ -160,7 +161,7 @@ extern inline u8 FAN_TO_REG(long rpm, int div) #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ /* There are some complications in a module like this. First off, LM78 chips may be both present on the SMBus and the ISA bus, and we have to handle @@ -182,25 +183,25 @@ extern int cleanup_module(void); dynamically allocated, at the same time when a new lm78 client is allocated. */ struct lm78_data { - struct semaphore lock; - int sysctl_id; - enum chips type; + struct semaphore lock; + int sysctl_id; + enum chips type; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ - u8 in[7]; /* Register value */ - u8 in_max[7]; /* Register value */ - u8 in_min[7]; /* Register value */ - u8 fan[3]; /* Register value */ - u8 fan_min[3]; /* Register value */ - u8 temp; /* Register value */ - u8 temp_over; /* Register value */ - u8 temp_hyst; /* Register value */ - u8 fan_div[3]; /* Register encoding, shifted right */ - u8 vid; /* Register encoding, combined */ - u16 alarms; /* Register encoding, combined */ + u8 in[7]; /* Register value */ + u8 in_max[7]; /* Register value */ + u8 in_min[7]; /* Register value */ + u8 fan[3]; /* Register value */ + u8 fan_min[3]; /* Register value */ + u8 temp; /* Register value */ + u8 temp_over; /* Register value */ + u8 temp_hyst; /* Register value */ + u8 fan_div[3]; /* Register encoding, shifted right */ + u8 vid; /* Register encoding, combined */ + u16 alarms; /* Register encoding, combined */ }; @@ -209,46 +210,47 @@ static #else extern #endif - int __init sensors_lm78_init(void); +int __init sensors_lm78_init(void); static int __init lm78_cleanup(void); static int lm78_attach_adapter(struct i2c_adapter *adapter); -static int lm78_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind); +static int lm78_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); static int lm78_detach_client(struct i2c_client *client); -static int lm78_command(struct i2c_client *client, unsigned int cmd, - void *arg); -static void lm78_inc_use (struct i2c_client *client); -static void lm78_dec_use (struct i2c_client *client); +static int lm78_command(struct i2c_client *client, unsigned int cmd, + void *arg); +static void lm78_inc_use(struct i2c_client *client); +static void lm78_dec_use(struct i2c_client *client); static int lm78_read_value(struct i2c_client *client, u8 register); -static int lm78_write_value(struct i2c_client *client, u8 register, u8 value); +static int lm78_write_value(struct i2c_client *client, u8 register, + u8 value); static void lm78_update_client(struct i2c_client *client); static void lm78_init_client(struct i2c_client *client); static void lm78_in(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void lm78_fan(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void lm78_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void lm78_vid(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void lm78_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void lm78_fan_div(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); + int *nrels_mag, long *results); +static void lm78_fan(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void lm78_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void lm78_vid(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void lm78_alarms(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void lm78_fan_div(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static struct i2c_driver lm78_driver = { - /* name */ "LM78(-J) and LM79 sensor driver", - /* id */ I2C_DRIVERID_LM78, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &lm78_attach_adapter, - /* detach_client */ &lm78_detach_client, - /* command */ &lm78_command, - /* inc_use */ &lm78_inc_use, - /* dec_use */ &lm78_dec_use + /* name */ "LM78(-J) and LM79 sensor driver", + /* id */ I2C_DRIVERID_LM78, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &lm78_attach_adapter, + /* detach_client */ &lm78_detach_client, + /* command */ &lm78_command, + /* inc_use */ &lm78_inc_use, + /* dec_use */ &lm78_dec_use }; /* Used by lm78_init/cleanup */ @@ -263,35 +265,35 @@ static int lm78_id = 0; is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table lm78_dir_table_template[] = { - { LM78_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm78_in }, - { LM78_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm78_in }, - { LM78_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm78_in }, - { LM78_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm78_in }, - { LM78_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm78_in }, - { LM78_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm78_in }, - { LM78_SYSCTL_IN6, "in6", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm78_in }, - { LM78_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm78_fan }, - { LM78_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm78_fan }, - { LM78_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm78_fan }, - { LM78_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm78_temp }, - { LM78_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm78_vid }, - { LM78_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm78_fan_div }, - { LM78_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm78_alarms }, - { 0 } + {LM78_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm78_in}, + {LM78_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm78_in}, + {LM78_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm78_in}, + {LM78_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm78_in}, + {LM78_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm78_in}, + {LM78_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm78_in}, + {LM78_SYSCTL_IN6, "in6", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm78_in}, + {LM78_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm78_fan}, + {LM78_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm78_fan}, + {LM78_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm78_fan}, + {LM78_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm78_temp}, + {LM78_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm78_vid}, + {LM78_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm78_fan_div}, + {LM78_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm78_alarms}, + {0} }; @@ -301,202 +303,211 @@ static ctl_table lm78_dir_table_template[] = { * when a new adapter is inserted (and lm78_driver is still present) */ int lm78_attach_adapter(struct i2c_adapter *adapter) { - return sensors_detect(adapter,&addr_data,lm78_detect); + return sensors_detect(adapter, &addr_data, lm78_detect); } /* This function is called by sensors_detect */ -int lm78_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind) +int lm78_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) { - int i; - struct i2c_client *new_client; - struct lm78_data *data; - int err=0; - const char *type_name = ""; - const char *client_name = ""; - int is_isa = i2c_is_isa_adapter(adapter); + int i; + struct i2c_client *new_client; + struct lm78_data *data; + int err = 0; + const char *type_name = ""; + const char *client_name = ""; + int is_isa = i2c_is_isa_adapter(adapter); - if (!is_isa && ! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_BYTE_DATA)) - goto ERROR0; + if (!is_isa + && !i2c_check_functionality(adapter, + I2C_FUNC_SMBUS_BYTE_DATA)) goto + ERROR0; - if (is_isa) { - if (check_region(address,LM78_EXTENT)) - goto ERROR0; - } + if (is_isa) { + if (check_region(address, LM78_EXTENT)) + goto ERROR0; + } - /* Probe whether there is anything available on this address. Already - done for SMBus clients */ - if (kind < 0) { - if (is_isa) { + /* Probe whether there is anything available on this address. Already + done for SMBus clients */ + if (kind < 0) { + if (is_isa) { #define REALLY_SLOW_IO - /* We need the timeouts for at least some LM78-like chips. But only - if we read 'undefined' registers. */ - i = inb_p(address + 1); - if (inb_p(address + 2) != i) - goto ERROR0; - if (inb_p(address + 3) != i) - goto ERROR0; - if (inb_p(address + 7) != i) - goto ERROR0; + /* We need the timeouts for at least some LM78-like chips. But only + if we read 'undefined' registers. */ + i = inb_p(address + 1); + if (inb_p(address + 2) != i) + goto ERROR0; + if (inb_p(address + 3) != i) + goto ERROR0; + if (inb_p(address + 7) != i) + goto ERROR0; #undef REALLY_SLOW_IO - - /* Let's just hope nothing breaks here */ - i = inb_p(address + 5) & 0x7f; - outb_p(~i & 0x7f,address+5); - if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) { - outb_p(i,address+5); - return 0; - } - } - } - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access lm78_{read,write}_value. */ + /* Let's just hope nothing breaks here */ + i = inb_p(address + 5) & 0x7f; + outb_p(~i & 0x7f, address + 5); + if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) { + outb_p(i, address + 5); + return 0; + } + } + } - if (! (new_client = kmalloc((sizeof(struct i2c_client)) + - sizeof(struct lm78_data), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR0; - } + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access lm78_{read,write}_value. */ - data = (struct lm78_data *) (new_client + 1); - if (is_isa) - init_MUTEX(&data->lock); - new_client->addr = address; - new_client->data = data; - new_client->adapter = adapter; - new_client->driver = &lm78_driver; - new_client->flags = 0; - - /* Now, we do the remaining detection. */ + if (!(new_client = kmalloc((sizeof(struct i2c_client)) + + sizeof(struct lm78_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } - if (kind < 0) { - if (lm78_read_value(new_client,LM78_REG_CONFIG) & 0x80) - goto ERROR1; - if (!is_isa && (lm78_read_value(new_client,LM78_REG_I2C_ADDR) != address)) - goto ERROR1; - } - - /* Determine the chip type. */ - if (kind <= 0) { - i = lm78_read_value(new_client,LM78_REG_CHIPID); - if (i == 0x00) - kind = lm78; - else if (i == 0x40) - kind = lm78j; - else if ((i & 0xfe) == 0xc0) - kind = lm79; - else { - if (kind == 0) - printk("lm78.o: Ignoring 'force' parameter for unknown chip at " - "adapter %d, address 0x%02x\n",i2c_adapter_id(adapter),address); - goto ERROR1; - } - } + data = (struct lm78_data *) (new_client + 1); + if (is_isa) + init_MUTEX(&data->lock); + new_client->addr = address; + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &lm78_driver; + new_client->flags = 0; - if (kind == lm78) { - type_name = "lm78"; - client_name = "LM78 chip"; - } else if (kind == lm78j) { - type_name = "lm78-j"; - client_name = "LM78-J chip"; - } else if (kind == lm79) { - type_name = "lm79"; - client_name = "LM79 chip"; - } else { + /* Now, we do the remaining detection. */ + + if (kind < 0) { + if (lm78_read_value(new_client, LM78_REG_CONFIG) & 0x80) + goto ERROR1; + if (!is_isa + && (lm78_read_value(new_client, LM78_REG_I2C_ADDR) != + address)) goto ERROR1; + } + + /* Determine the chip type. */ + if (kind <= 0) { + i = lm78_read_value(new_client, LM78_REG_CHIPID); + if (i == 0x00) + kind = lm78; + else if (i == 0x40) + kind = lm78j; + else if ((i & 0xfe) == 0xc0) + kind = lm79; + else { + if (kind == 0) + printk + ("lm78.o: Ignoring 'force' parameter for unknown chip at " + "adapter %d, address 0x%02x\n", + i2c_adapter_id(adapter), address); + goto ERROR1; + } + } + + if (kind == lm78) { + type_name = "lm78"; + client_name = "LM78 chip"; + } else if (kind == lm78j) { + type_name = "lm78-j"; + client_name = "LM78-J chip"; + } else if (kind == lm79) { + type_name = "lm79"; + client_name = "LM79 chip"; + } else { #ifdef DEBUG - printk("lm78.o: Internal error: unknown kind (%d)?!?",kind); + printk("lm78.o: Internal error: unknown kind (%d)?!?", + kind); #endif - goto ERROR1; - } + goto ERROR1; + } - /* Reserve the ISA region */ - if (is_isa) - request_region(address, LM78_EXTENT, type_name); + /* Reserve the ISA region */ + if (is_isa) + request_region(address, LM78_EXTENT, type_name); - /* Fill in the remaining client fields and put it into the global list */ - strcpy(new_client->name,client_name); - data->type = kind; + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); + data->type = kind; - new_client->id = lm78_id ++; - data->valid = 0; - init_MUTEX(&data->update_lock); + new_client->id = lm78_id++; + data->valid = 0; + init_MUTEX(&data->update_lock); - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; - /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry(new_client, - type_name, - lm78_dir_table_template, - THIS_MODULE)) < 0) { - err = i; - goto ERROR4; - } - data->sysctl_id = i; + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry(new_client, + type_name, + lm78_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; - /* Initialize the LM78 chip */ - lm78_init_client(new_client); - return 0; + /* Initialize the LM78 chip */ + lm78_init_client(new_client); + return 0; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR4: - i2c_detach_client(new_client); -ERROR3: - if (is_isa) - release_region(address,LM78_EXTENT); -ERROR1: - kfree(new_client); -ERROR0: - return err; + ERROR4: + i2c_detach_client(new_client); + ERROR3: + if (is_isa) + release_region(address, LM78_EXTENT); + ERROR1: + kfree(new_client); + ERROR0: + return err; } int lm78_detach_client(struct i2c_client *client) { - int err; + int err; - sensors_deregister_entry(((struct lm78_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct lm78_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("lm78.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("lm78.o: Client deregistration failed, client not detached.\n"); + return err; + } - if i2c_is_isa_client(client) - release_region(client->addr,LM78_EXTENT); - kfree(client); + if i2c_is_isa_client + (client) + release_region(client->addr, LM78_EXTENT); + kfree(client); - return 0; + return 0; } /* No commands defined yet */ int lm78_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } /* Nothing here yet */ -void lm78_inc_use (struct i2c_client *client) +void lm78_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } /* Nothing here yet */ -void lm78_dec_use (struct i2c_client *client) +void lm78_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } - + /* The SMBus locks itself, but ISA access must be locked explicitely! We don't want to lock the whole ISA bus, so we lock each client @@ -507,17 +518,15 @@ void lm78_dec_use (struct i2c_client *client) nowhere else be necessary! */ int lm78_read_value(struct i2c_client *client, u8 reg) { - int res; - if (i2c_is_isa_client(client)) { - down(& (((struct lm78_data *) (client->data)) -> lock)); - outb_p(reg,client->addr + - LM78_ADDR_REG_OFFSET); - res = inb_p(client->addr + - LM78_DATA_REG_OFFSET); - up( & (((struct lm78_data *) (client->data)) -> lock)); - return res; - } else - return i2c_smbus_read_byte_data(client, reg); + int res; + if (i2c_is_isa_client(client)) { + down(&(((struct lm78_data *) (client->data))->lock)); + outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET); + res = inb_p(client->addr + LM78_DATA_REG_OFFSET); + up(&(((struct lm78_data *) (client->data))->lock)); + return res; + } else + return i2c_smbus_read_byte_data(client, reg); } /* The SMBus locks itself, but ISA access muse be locked explicitely! @@ -529,103 +538,130 @@ int lm78_read_value(struct i2c_client *client, u8 reg) nowhere else be necessary! */ int lm78_write_value(struct i2c_client *client, u8 reg, u8 value) { - if (i2c_is_isa_client(client)) { - down(&(((struct lm78_data *) (client->data)) -> lock)); - outb_p(reg,client->addr + LM78_ADDR_REG_OFFSET); - outb_p(value,client->addr + LM78_DATA_REG_OFFSET); - up(&(((struct lm78_data *) (client->data)) -> lock)); - return 0; - } else - return i2c_smbus_write_byte_data(client, reg,value); + if (i2c_is_isa_client(client)) { + down(&(((struct lm78_data *) (client->data))->lock)); + outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET); + outb_p(value, client->addr + LM78_DATA_REG_OFFSET); + up(&(((struct lm78_data *) (client->data))->lock)); + return 0; + } else + return i2c_smbus_write_byte_data(client, reg, value); } /* Called when we have found a new LM78. It should set limits, etc. */ void lm78_init_client(struct i2c_client *client) { - int vid; + int vid; - /* Reset all except Watchdog values and last conversion values - This sets fan-divs to 2, among others */ - lm78_write_value(client,LM78_REG_CONFIG,0x80); + /* Reset all except Watchdog values and last conversion values + This sets fan-divs to 2, among others */ + lm78_write_value(client, LM78_REG_CONFIG, 0x80); - vid = lm78_read_value(client,LM78_REG_VID_FANDIV) & 0x0f; - if (((struct lm78_data *) (client->data))->type == lm79) - vid |= (lm78_read_value(client,LM78_REG_CHIPID) & 0x01) << 4; - else - vid |= 0x10; - vid = VID_FROM_REG(vid); + vid = lm78_read_value(client, LM78_REG_VID_FANDIV) & 0x0f; + if (((struct lm78_data *) (client->data))->type == lm79) + vid |= + (lm78_read_value(client, LM78_REG_CHIPID) & 0x01) << 4; + else + vid |= 0x10; + vid = VID_FROM_REG(vid); - lm78_write_value(client,LM78_REG_IN_MIN(0),IN_TO_REG(LM78_INIT_IN_MIN_0)); - lm78_write_value(client,LM78_REG_IN_MAX(0),IN_TO_REG(LM78_INIT_IN_MAX_0)); - lm78_write_value(client,LM78_REG_IN_MIN(1),IN_TO_REG(LM78_INIT_IN_MIN_1)); - lm78_write_value(client,LM78_REG_IN_MAX(1),IN_TO_REG(LM78_INIT_IN_MAX_1)); - lm78_write_value(client,LM78_REG_IN_MIN(2),IN_TO_REG(LM78_INIT_IN_MIN_2)); - lm78_write_value(client,LM78_REG_IN_MAX(2),IN_TO_REG(LM78_INIT_IN_MAX_2)); - lm78_write_value(client,LM78_REG_IN_MIN(3),IN_TO_REG(LM78_INIT_IN_MIN_3)); - lm78_write_value(client,LM78_REG_IN_MAX(3),IN_TO_REG(LM78_INIT_IN_MAX_3)); - lm78_write_value(client,LM78_REG_IN_MIN(4),IN_TO_REG(LM78_INIT_IN_MIN_4)); - lm78_write_value(client,LM78_REG_IN_MAX(4),IN_TO_REG(LM78_INIT_IN_MAX_4)); - lm78_write_value(client,LM78_REG_IN_MIN(5),IN_TO_REG(LM78_INIT_IN_MIN_5)); - lm78_write_value(client,LM78_REG_IN_MAX(5),IN_TO_REG(LM78_INIT_IN_MAX_5)); - lm78_write_value(client,LM78_REG_IN_MIN(6),IN_TO_REG(LM78_INIT_IN_MIN_6)); - lm78_write_value(client,LM78_REG_IN_MAX(6),IN_TO_REG(LM78_INIT_IN_MAX_6)); - lm78_write_value(client,LM78_REG_FAN_MIN(1), - FAN_TO_REG(LM78_INIT_FAN_MIN_1,2)); - lm78_write_value(client,LM78_REG_FAN_MIN(2), - FAN_TO_REG(LM78_INIT_FAN_MIN_2,2)); - lm78_write_value(client,LM78_REG_FAN_MIN(3), - FAN_TO_REG(LM78_INIT_FAN_MIN_3,2)); - lm78_write_value(client,LM78_REG_TEMP_OVER,TEMP_TO_REG(LM78_INIT_TEMP_OVER)); - lm78_write_value(client,LM78_REG_TEMP_HYST,TEMP_TO_REG(LM78_INIT_TEMP_HYST)); + lm78_write_value(client, LM78_REG_IN_MIN(0), + IN_TO_REG(LM78_INIT_IN_MIN_0)); + lm78_write_value(client, LM78_REG_IN_MAX(0), + IN_TO_REG(LM78_INIT_IN_MAX_0)); + lm78_write_value(client, LM78_REG_IN_MIN(1), + IN_TO_REG(LM78_INIT_IN_MIN_1)); + lm78_write_value(client, LM78_REG_IN_MAX(1), + IN_TO_REG(LM78_INIT_IN_MAX_1)); + lm78_write_value(client, LM78_REG_IN_MIN(2), + IN_TO_REG(LM78_INIT_IN_MIN_2)); + lm78_write_value(client, LM78_REG_IN_MAX(2), + IN_TO_REG(LM78_INIT_IN_MAX_2)); + lm78_write_value(client, LM78_REG_IN_MIN(3), + IN_TO_REG(LM78_INIT_IN_MIN_3)); + lm78_write_value(client, LM78_REG_IN_MAX(3), + IN_TO_REG(LM78_INIT_IN_MAX_3)); + lm78_write_value(client, LM78_REG_IN_MIN(4), + IN_TO_REG(LM78_INIT_IN_MIN_4)); + lm78_write_value(client, LM78_REG_IN_MAX(4), + IN_TO_REG(LM78_INIT_IN_MAX_4)); + lm78_write_value(client, LM78_REG_IN_MIN(5), + IN_TO_REG(LM78_INIT_IN_MIN_5)); + lm78_write_value(client, LM78_REG_IN_MAX(5), + IN_TO_REG(LM78_INIT_IN_MAX_5)); + lm78_write_value(client, LM78_REG_IN_MIN(6), + IN_TO_REG(LM78_INIT_IN_MIN_6)); + lm78_write_value(client, LM78_REG_IN_MAX(6), + IN_TO_REG(LM78_INIT_IN_MAX_6)); + lm78_write_value(client, LM78_REG_FAN_MIN(1), + FAN_TO_REG(LM78_INIT_FAN_MIN_1, 2)); + lm78_write_value(client, LM78_REG_FAN_MIN(2), + FAN_TO_REG(LM78_INIT_FAN_MIN_2, 2)); + lm78_write_value(client, LM78_REG_FAN_MIN(3), + FAN_TO_REG(LM78_INIT_FAN_MIN_3, 2)); + lm78_write_value(client, LM78_REG_TEMP_OVER, + TEMP_TO_REG(LM78_INIT_TEMP_OVER)); + lm78_write_value(client, LM78_REG_TEMP_HYST, + TEMP_TO_REG(LM78_INIT_TEMP_HYST)); + + /* Start monitoring */ + lm78_write_value(client, LM78_REG_CONFIG, + (lm78_read_value(client, LM78_REG_CONFIG) & 0xf7) + | 0x01); - /* Start monitoring */ - lm78_write_value(client,LM78_REG_CONFIG, - (lm78_read_value(client,LM78_REG_CONFIG) & 0xf7) | 0x01); - } void lm78_update_client(struct i2c_client *client) { - struct lm78_data *data = client->data; - int i; + struct lm78_data *data = client->data; + int i; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > HZ+HZ/2 ) || - (jiffies < data->last_updated) || ! data->valid) { + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("Starting lm78 update\n"); + printk("Starting lm78 update\n"); #endif - for (i = 0; i <= 6; i++) { - data->in[i] = lm78_read_value(client,LM78_REG_IN(i)); - data->in_min[i] = lm78_read_value(client,LM78_REG_IN_MIN(i)); - data->in_max[i] = lm78_read_value(client,LM78_REG_IN_MAX(i)); - } - for (i = 1; i <= 3; i++) { - data->fan[i-1] = lm78_read_value(client,LM78_REG_FAN(i)); - data->fan_min[i-1] = lm78_read_value(client,LM78_REG_FAN_MIN(i)); - } - data->temp = lm78_read_value(client,LM78_REG_TEMP); - data->temp_over = lm78_read_value(client,LM78_REG_TEMP_OVER); - data->temp_hyst = lm78_read_value(client,LM78_REG_TEMP_HYST); - i = lm78_read_value(client,LM78_REG_VID_FANDIV); - data->vid = i & 0x0f; - if (data->type == lm79) - data->vid |= (lm78_read_value(client,LM78_REG_CHIPID) & 0x01) << 4; - else - data->vid |= 0x10; - data->fan_div[0] = (i >> 4) & 0x03; - data->fan_div[1] = i >> 6; - data->alarms = lm78_read_value(client,LM78_REG_ALARM1) + - (lm78_read_value(client,LM78_REG_ALARM2) << 8); - data->last_updated = jiffies; - data->valid = 1; + for (i = 0; i <= 6; i++) { + data->in[i] = + lm78_read_value(client, LM78_REG_IN(i)); + data->in_min[i] = + lm78_read_value(client, LM78_REG_IN_MIN(i)); + data->in_max[i] = + lm78_read_value(client, LM78_REG_IN_MAX(i)); + } + for (i = 1; i <= 3; i++) { + data->fan[i - 1] = + lm78_read_value(client, LM78_REG_FAN(i)); + data->fan_min[i - 1] = + lm78_read_value(client, LM78_REG_FAN_MIN(i)); + } + data->temp = lm78_read_value(client, LM78_REG_TEMP); + data->temp_over = + lm78_read_value(client, LM78_REG_TEMP_OVER); + data->temp_hyst = + lm78_read_value(client, LM78_REG_TEMP_HYST); + i = lm78_read_value(client, LM78_REG_VID_FANDIV); + data->vid = i & 0x0f; + if (data->type == lm79) + data->vid |= + (lm78_read_value(client, LM78_REG_CHIPID) & + 0x01) << 4; + else + data->vid |= 0x10; + data->fan_div[0] = (i >> 4) & 0x03; + data->fan_div[1] = i >> 6; + data->alarms = lm78_read_value(client, LM78_REG_ALARM1) + + (lm78_read_value(client, LM78_REG_ALARM2) << 8); + data->last_updated = jiffies; + data->valid = 1; - data->fan_div[2] = 1; - } + data->fan_div[2] = 1; + } - up(&data->update_lock); + up(&data->update_lock); } @@ -642,163 +678,175 @@ void lm78_update_client(struct i2c_client *client) large enough (by checking the incoming value of *nrels). This is not very good practice, but as long as you put less than about 5 values in results, you can assume it is large enough. */ -void lm78_in(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void lm78_in(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - struct lm78_data *data = client->data; - int nr = ctl_name - LM78_SYSCTL_IN0; + struct lm78_data *data = client->data; + int nr = ctl_name - LM78_SYSCTL_IN0; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 2; - else if (operation == SENSORS_PROC_REAL_READ) { - lm78_update_client(client); - results[0] = IN_FROM_REG(data->in_min[nr]); - results[1] = IN_FROM_REG(data->in_max[nr]); - results[2] = IN_FROM_REG(data->in[nr]); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->in_min[nr] = IN_TO_REG(results[0]); - lm78_write_value(client,LM78_REG_IN_MIN(nr),data->in_min[nr]); - } - if (*nrels_mag >= 2) { - data->in_max[nr] = IN_TO_REG(results[1]); - lm78_write_value(client,LM78_REG_IN_MAX(nr),data->in_max[nr]); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + lm78_update_client(client); + results[0] = IN_FROM_REG(data->in_min[nr]); + results[1] = IN_FROM_REG(data->in_max[nr]); + results[2] = IN_FROM_REG(data->in[nr]); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->in_min[nr] = IN_TO_REG(results[0]); + lm78_write_value(client, LM78_REG_IN_MIN(nr), + data->in_min[nr]); + } + if (*nrels_mag >= 2) { + data->in_max[nr] = IN_TO_REG(results[1]); + lm78_write_value(client, LM78_REG_IN_MAX(nr), + data->in_max[nr]); + } + } } void lm78_fan(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct lm78_data *data = client->data; - int nr = ctl_name - LM78_SYSCTL_FAN1 + 1; + struct lm78_data *data = client->data; + int nr = ctl_name - LM78_SYSCTL_FAN1 + 1; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - lm78_update_client(client); - results[0] = FAN_FROM_REG(data->fan_min[nr-1], - DIV_FROM_REG(data->fan_div[nr-1])); - results[1] = FAN_FROM_REG(data->fan[nr-1], - DIV_FROM_REG(data->fan_div[nr-1])); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->fan_min[nr-1] = FAN_TO_REG(results[0], - DIV_FROM_REG(data->fan_div[nr-1])); - lm78_write_value(client,LM78_REG_FAN_MIN(nr),data->fan_min[nr-1]); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + lm78_update_client(client); + results[0] = FAN_FROM_REG(data->fan_min[nr - 1], + DIV_FROM_REG(data-> + fan_div[nr - 1])); + results[1] = + FAN_FROM_REG(data->fan[nr - 1], + DIV_FROM_REG(data->fan_div[nr - 1])); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->fan_min[nr - 1] = FAN_TO_REG(results[0], + DIV_FROM_REG + (data-> + fan_div[nr - + 1])); + lm78_write_value(client, LM78_REG_FAN_MIN(nr), + data->fan_min[nr - 1]); + } + } } void lm78_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct lm78_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 1; - else if (operation == SENSORS_PROC_REAL_READ) { - lm78_update_client(client); - results[0] = TEMP_FROM_REG(data->temp_over); - results[1] = TEMP_FROM_REG(data->temp_hyst); - results[2] = TEMP_FROM_REG(data->temp); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->temp_over = TEMP_TO_REG(results[0]); - lm78_write_value(client,LM78_REG_TEMP_OVER,data->temp_over); - } - if (*nrels_mag >= 2) { - data->temp_hyst = TEMP_TO_REG(results[1]); - lm78_write_value(client,LM78_REG_TEMP_HYST,data->temp_hyst); - } - } + struct lm78_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 1; + else if (operation == SENSORS_PROC_REAL_READ) { + lm78_update_client(client); + results[0] = TEMP_FROM_REG(data->temp_over); + results[1] = TEMP_FROM_REG(data->temp_hyst); + results[2] = TEMP_FROM_REG(data->temp); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->temp_over = TEMP_TO_REG(results[0]); + lm78_write_value(client, LM78_REG_TEMP_OVER, + data->temp_over); + } + if (*nrels_mag >= 2) { + data->temp_hyst = TEMP_TO_REG(results[1]); + lm78_write_value(client, LM78_REG_TEMP_HYST, + data->temp_hyst); + } + } } void lm78_vid(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct lm78_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 2; - else if (operation == SENSORS_PROC_REAL_READ) { - lm78_update_client(client); - results[0] = VID_FROM_REG(data->vid); - *nrels_mag = 1; - } + struct lm78_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + lm78_update_client(client); + results[0] = VID_FROM_REG(data->vid); + *nrels_mag = 1; + } } void lm78_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct lm78_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - lm78_update_client(client); - results[0] = ALARMS_FROM_REG(data->alarms); - *nrels_mag = 1; - } + struct lm78_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + lm78_update_client(client); + results[0] = ALARMS_FROM_REG(data->alarms); + *nrels_mag = 1; + } } void lm78_fan_div(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct lm78_data *data = client->data; - int old; + struct lm78_data *data = client->data; + int old; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - lm78_update_client(client); - results[0] = DIV_FROM_REG(data->fan_div[0]); - results[1] = DIV_FROM_REG(data->fan_div[1]); - results[2] = 2; - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - old = lm78_read_value(client,LM78_REG_VID_FANDIV); - if (*nrels_mag >= 2) { - data->fan_div[1] = DIV_TO_REG(results[1]); - old = (old & 0x3f) | (data->fan_div[1] << 6); - } - if (*nrels_mag >= 1) { - data->fan_div[0] = DIV_TO_REG(results[0]); - old = (old & 0xcf) | (data->fan_div[0] << 4); - lm78_write_value(client,LM78_REG_VID_FANDIV,old); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + lm78_update_client(client); + results[0] = DIV_FROM_REG(data->fan_div[0]); + results[1] = DIV_FROM_REG(data->fan_div[1]); + results[2] = 2; + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + old = lm78_read_value(client, LM78_REG_VID_FANDIV); + if (*nrels_mag >= 2) { + data->fan_div[1] = DIV_TO_REG(results[1]); + old = (old & 0x3f) | (data->fan_div[1] << 6); + } + if (*nrels_mag >= 1) { + data->fan_div[0] = DIV_TO_REG(results[0]); + old = (old & 0xcf) | (data->fan_div[0] << 4); + lm78_write_value(client, LM78_REG_VID_FANDIV, old); + } + } } int __init sensors_lm78_init(void) { - int res; + int res; - printk("lm78.o version %s (%s)\n",LM_VERSION,LM_DATE); - lm78_initialized = 0; + printk("lm78.o version %s (%s)\n", LM_VERSION, LM_DATE); + lm78_initialized = 0; - if ((res =i2c_add_driver(&lm78_driver))) { - printk("lm78.o: Driver registration failed, module not inserted.\n"); - lm78_cleanup(); - return res; - } - lm78_initialized ++; - return 0; + if ((res = i2c_add_driver(&lm78_driver))) { + printk + ("lm78.o: Driver registration failed, module not inserted.\n"); + lm78_cleanup(); + return res; + } + lm78_initialized++; + return 0; } int __init lm78_cleanup(void) { - int res; + int res; - if (lm78_initialized >= 1) { - if ((res = i2c_del_driver(&lm78_driver))) { - printk("lm78.o: Driver deregistration failed, module not removed.\n"); - return res; - } - lm78_initialized --; - } - return 0; + if (lm78_initialized >= 1) { + if ((res = i2c_del_driver(&lm78_driver))) { + printk + ("lm78.o: Driver deregistration failed, module not removed.\n"); + return res; + } + lm78_initialized--; + } + return 0; } EXPORT_NO_SYMBOLS; @@ -810,13 +858,12 @@ MODULE_DESCRIPTION("LM78, LM78-J and LM79 driver"); int init_module(void) { - return sensors_lm78_init(); + return sensors_lm78_init(); } int cleanup_module(void) { - return lm78_cleanup(); + return lm78_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/lm80.c b/kernel/chips/lm80.c index 540ad065..aebf4319 100644 --- a/kernel/chips/lm80.c +++ b/kernel/chips/lm80.c @@ -43,10 +43,10 @@ #endif /* Addresses to scan */ -static unsigned short normal_i2c[] = {SENSORS_I2C_END}; -static unsigned short normal_i2c_range[] = {0x20,0x2f,SENSORS_I2C_END}; -static unsigned int normal_isa[] = {SENSORS_ISA_END}; -static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; +static unsigned short normal_i2c[] = { SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { 0x20, 0x2f, SENSORS_I2C_END }; +static unsigned int normal_isa[] = { SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; /* Insmod parameters */ SENSORS_INSMOD_1(lm80); @@ -86,28 +86,29 @@ SENSORS_INSMOD_1(lm80); #define IN_TO_REG(val,nr) (SENSORS_LIMIT((val),0,255)) #define IN_FROM_REG(val,nr) (val) -extern inline unsigned char -FAN_TO_REG (unsigned rpm, unsigned div) +extern inline unsigned char FAN_TO_REG(unsigned rpm, unsigned div) { - if (rpm == 0) - return 255; - rpm = SENSORS_LIMIT(rpm,1,1000000); - return SENSORS_LIMIT((1350000 + rpm*div/2) / (rpm*div),1,254); + if (rpm == 0) + return 255; + rpm = SENSORS_LIMIT(rpm, 1, 1000000); + return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, + 254); } + #define FAN_FROM_REG(val,div) ((val)==0?-1:\ (val)==255?0:1350000/((div)*(val))) extern inline long TEMP_FROM_REG(u16 temp) { - long res; + long res; - temp = temp >> 4; - if (temp < 0x0800) { - res = (625 * (long)temp); - } else { - res = ((long)temp - 0x01000) * 625; - } - return res / 100; + temp = temp >> 4; + if (temp < 0x0800) { + res = (625 * (long) temp); + } else { + res = ((long) temp - 0x01000) * 625; + } + return res / 100; } #define TEMP_LIMIT_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*100) @@ -116,7 +117,7 @@ extern inline long TEMP_FROM_REG(u16 temp) ((val)+50)/100), \ 0,255) -#define ALARMS_FROM_REG(val) (val) +#define ALARMS_FROM_REG(val) (val) #define DIV_FROM_REG(val) (1 << (val)) #define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1?0:1) @@ -133,33 +134,33 @@ extern inline long TEMP_FROM_REG(u16 temp) #define LM80_INIT_IN_PERCENTAGE 10 #define LM80_INIT_IN_MIN_0 \ - (LM80_INIT_IN_0 - LM80_INIT_IN_0 * LM80_INIT_IN_PERCENTAGE / 100) + (LM80_INIT_IN_0 - LM80_INIT_IN_0 * LM80_INIT_IN_PERCENTAGE / 100) #define LM80_INIT_IN_MAX_0 \ - (LM80_INIT_IN_0 + LM80_INIT_IN_0 * LM80_INIT_IN_PERCENTAGE / 100) + (LM80_INIT_IN_0 + LM80_INIT_IN_0 * LM80_INIT_IN_PERCENTAGE / 100) #define LM80_INIT_IN_MIN_1 \ - (LM80_INIT_IN_1 - LM80_INIT_IN_1 * LM80_INIT_IN_PERCENTAGE / 100) + (LM80_INIT_IN_1 - LM80_INIT_IN_1 * LM80_INIT_IN_PERCENTAGE / 100) #define LM80_INIT_IN_MAX_1 \ - (LM80_INIT_IN_1 + LM80_INIT_IN_1 * LM80_INIT_IN_PERCENTAGE / 100) + (LM80_INIT_IN_1 + LM80_INIT_IN_1 * LM80_INIT_IN_PERCENTAGE / 100) #define LM80_INIT_IN_MIN_2 \ - (LM80_INIT_IN_2 - LM80_INIT_IN_2 * LM80_INIT_IN_PERCENTAGE / 100) + (LM80_INIT_IN_2 - LM80_INIT_IN_2 * LM80_INIT_IN_PERCENTAGE / 100) #define LM80_INIT_IN_MAX_2 \ - (LM80_INIT_IN_2 + LM80_INIT_IN_2 * LM80_INIT_IN_PERCENTAGE / 100) + (LM80_INIT_IN_2 + LM80_INIT_IN_2 * LM80_INIT_IN_PERCENTAGE / 100) #define LM80_INIT_IN_MIN_3 \ - (LM80_INIT_IN_3 - LM80_INIT_IN_3 * LM80_INIT_IN_PERCENTAGE / 100) + (LM80_INIT_IN_3 - LM80_INIT_IN_3 * LM80_INIT_IN_PERCENTAGE / 100) #define LM80_INIT_IN_MAX_3 \ - (LM80_INIT_IN_3 + LM80_INIT_IN_3 * LM80_INIT_IN_PERCENTAGE / 100) + (LM80_INIT_IN_3 + LM80_INIT_IN_3 * LM80_INIT_IN_PERCENTAGE / 100) #define LM80_INIT_IN_MIN_4 \ - (LM80_INIT_IN_4 - LM80_INIT_IN_4 * LM80_INIT_IN_PERCENTAGE / 100) + (LM80_INIT_IN_4 - LM80_INIT_IN_4 * LM80_INIT_IN_PERCENTAGE / 100) #define LM80_INIT_IN_MAX_4 \ - (LM80_INIT_IN_4 + LM80_INIT_IN_4 * LM80_INIT_IN_PERCENTAGE / 100) + (LM80_INIT_IN_4 + LM80_INIT_IN_4 * LM80_INIT_IN_PERCENTAGE / 100) #define LM80_INIT_IN_MIN_5 \ - (LM80_INIT_IN_5 - LM80_INIT_IN_5 * LM80_INIT_IN_PERCENTAGE / 100) + (LM80_INIT_IN_5 - LM80_INIT_IN_5 * LM80_INIT_IN_PERCENTAGE / 100) #define LM80_INIT_IN_MAX_5 \ - (LM80_INIT_IN_5 + LM80_INIT_IN_5 * LM80_INIT_IN_PERCENTAGE / 100) + (LM80_INIT_IN_5 + LM80_INIT_IN_5 * LM80_INIT_IN_PERCENTAGE / 100) #define LM80_INIT_IN_MIN_6 \ - (LM80_INIT_IN_6 - LM80_INIT_IN_6 * LM80_INIT_IN_PERCENTAGE / 100) + (LM80_INIT_IN_6 - LM80_INIT_IN_6 * LM80_INIT_IN_PERCENTAGE / 100) #define LM80_INIT_IN_MAX_6 \ - (LM80_INIT_IN_6 + LM80_INIT_IN_6 * LM80_INIT_IN_PERCENTAGE / 100) + (LM80_INIT_IN_6 + LM80_INIT_IN_6 * LM80_INIT_IN_PERCENTAGE / 100) #define LM80_INIT_FAN_MIN_1 3000 #define LM80_INIT_FAN_MIN_2 3000 @@ -172,31 +173,31 @@ extern inline long TEMP_FROM_REG(u16 temp) #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ /* For each registered LM80, we need to keep some data in memory. That data is pointed to by lm80_list[NR]->data. The structure itself is dynamically allocated, at the same time when a new lm80 client is allocated. */ struct lm80_data { - int sysctl_id; + int sysctl_id; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ - u8 in[7]; /* Register value */ - u8 in_max[7]; /* Register value */ - u8 in_min[7]; /* Register value */ - u8 fan[2]; /* Register value */ - u8 fan_min[2]; /* Register value */ - u8 fan_div[2]; /* Register encoding, shifted right */ - u16 temp; /* Register values, shifted right */ - u8 temp_hot_max; /* Register value */ - u8 temp_hot_hyst; /* Register value */ - u8 temp_os_max; /* Register value */ - u8 temp_os_hyst; /* Register value */ - u16 alarms; /* Register encoding, combined */ + u8 in[7]; /* Register value */ + u8 in_max[7]; /* Register value */ + u8 in_min[7]; /* Register value */ + u8 fan[2]; /* Register value */ + u8 fan_min[2]; /* Register value */ + u8 fan_div[2]; /* Register encoding, shifted right */ + u16 temp; /* Register values, shifted right */ + u8 temp_hot_max; /* Register value */ + u8 temp_hot_hyst; /* Register value */ + u8 temp_os_max; /* Register value */ + u8 temp_os_hyst; /* Register value */ + u16 alarms; /* Register encoding, combined */ }; @@ -205,46 +206,47 @@ static #else extern #endif - int __init sensors_lm80_init(void); +int __init sensors_lm80_init(void); static int __init lm80_cleanup(void); static int lm80_attach_adapter(struct i2c_adapter *adapter); -static int lm80_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind); +static int lm80_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); static int lm80_detach_client(struct i2c_client *client); -static int lm80_command(struct i2c_client *client, unsigned int cmd, - void *arg); -static void lm80_inc_use (struct i2c_client *client); -static void lm80_dec_use (struct i2c_client *client); +static int lm80_command(struct i2c_client *client, unsigned int cmd, + void *arg); +static void lm80_inc_use(struct i2c_client *client); +static void lm80_dec_use(struct i2c_client *client); static int lm80_read_value(struct i2c_client *client, u8 register); -static int lm80_write_value(struct i2c_client *client, u8 register, u8 value); +static int lm80_write_value(struct i2c_client *client, u8 register, + u8 value); static void lm80_update_client(struct i2c_client *client); static void lm80_init_client(struct i2c_client *client); static void lm80_in(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void lm80_fan(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void lm80_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void lm80_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void lm80_fan_div(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); + int *nrels_mag, long *results); +static void lm80_fan(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void lm80_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void lm80_alarms(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void lm80_fan_div(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static int lm80_id = 0; static struct i2c_driver lm80_driver = { - /* name */ "LM80 sensor driver", - /* id */ I2C_DRIVERID_LM80, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &lm80_attach_adapter, - /* detach_client */ &lm80_detach_client, - /* command */ &lm80_command, - /* inc_use */ &lm80_inc_use, - /* dec_use */ &lm80_dec_use + /* name */ "LM80 sensor driver", + /* id */ I2C_DRIVERID_LM80, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &lm80_attach_adapter, + /* detach_client */ &lm80_detach_client, + /* command */ &lm80_command, + /* inc_use */ &lm80_inc_use, + /* dec_use */ &lm80_dec_use }; /* Used by lm80_init/cleanup */ @@ -257,261 +259,292 @@ static int __initdata lm80_initialized = 0; is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table lm80_dir_table_template[] = { - { LM80_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm80_in }, - { LM80_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm80_in }, - { LM80_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm80_in }, - { LM80_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm80_in }, - { LM80_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm80_in }, - { LM80_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm80_in }, - { LM80_SYSCTL_IN6, "in6", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm80_in }, - { LM80_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm80_fan }, - { LM80_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm80_fan }, - { LM80_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm80_temp }, - { LM80_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm80_fan_div }, - { LM80_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &lm80_alarms }, - { 0 } + {LM80_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm80_in}, + {LM80_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm80_in}, + {LM80_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm80_in}, + {LM80_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm80_in}, + {LM80_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm80_in}, + {LM80_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm80_in}, + {LM80_SYSCTL_IN6, "in6", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm80_in}, + {LM80_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm80_fan}, + {LM80_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm80_fan}, + {LM80_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm80_temp}, + {LM80_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm80_fan_div}, + {LM80_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &lm80_alarms}, + {0} }; int lm80_attach_adapter(struct i2c_adapter *adapter) { - return sensors_detect(adapter,&addr_data,lm80_detect); + return sensors_detect(adapter, &addr_data, lm80_detect); } -int lm80_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind) +int lm80_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) { - int i,cur; - struct i2c_client *new_client; - struct lm80_data *data; - int err=0; - const char *type_name,*client_name; + int i, cur; + struct i2c_client *new_client; + struct lm80_data *data; + int err = 0; + const char *type_name, *client_name; - /* Make sure we aren't probing the ISA bus!! This is just a safety check - at this moment; sensors_detect really won't call us. */ + /* Make sure we aren't probing the ISA bus!! This is just a safety check + at this moment; sensors_detect really won't call us. */ #ifdef DEBUG - if (i2c_is_isa_adapter(adapter)) { - printk("lm80.o: lm80_detect called for an ISA bus adapter?!?\n"); - return 0; - } + if (i2c_is_isa_adapter(adapter)) { + printk + ("lm80.o: lm80_detect called for an ISA bus adapter?!?\n"); + return 0; + } #endif - if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_BYTE_DATA)) - goto ERROR0; + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) + goto ERROR0; - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access lm80_{read,write}_value. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct lm80_data), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR0; - } + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access lm80_{read,write}_value. */ + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct lm80_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } - data = (struct lm80_data *) (new_client + 1); - new_client->addr = address; - new_client->data = data; - new_client->adapter = adapter; - new_client->driver = &lm80_driver; - new_client->flags = 0; + data = (struct lm80_data *) (new_client + 1); + new_client->addr = address; + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &lm80_driver; + new_client->flags = 0; - /* Now, we do the remaining detection. It is lousy. */ - if (lm80_read_value(new_client,LM80_REG_ALARM2) & 0xc0) - goto ERROR1; - for (i = 0x2a; i <= 0x3d; i++) { - cur = i2c_smbus_read_byte_data(new_client,i); - if ((i2c_smbus_read_byte_data(new_client,i+0x40) != cur) || - (i2c_smbus_read_byte_data(new_client,i+0x80) != cur) || - (i2c_smbus_read_byte_data(new_client,i+0xc0) != cur)) - goto ERROR1; - } + /* Now, we do the remaining detection. It is lousy. */ + if (lm80_read_value(new_client, LM80_REG_ALARM2) & 0xc0) + goto ERROR1; + for (i = 0x2a; i <= 0x3d; i++) { + cur = i2c_smbus_read_byte_data(new_client, i); + if ((i2c_smbus_read_byte_data(new_client, i + 0x40) != cur) + || (i2c_smbus_read_byte_data(new_client, i + 0x80) != + cur) + || (i2c_smbus_read_byte_data(new_client, i + 0xc0) != + cur)) goto ERROR1; + } - /* Determine the chip type - only one kind supported! */ - if (kind <= 0) - kind = lm80; + /* Determine the chip type - only one kind supported! */ + if (kind <= 0) + kind = lm80; - if (kind == lm80) { - type_name = "lm80"; - client_name = "LM80 chip"; - } else { + if (kind == lm80) { + type_name = "lm80"; + client_name = "LM80 chip"; + } else { #ifdef DEBUG - printk("lm80.o: Internal error: unknown kind (%d)?!?",kind); + printk("lm80.o: Internal error: unknown kind (%d)?!?", + kind); #endif - goto ERROR1; - } + goto ERROR1; + } - /* Fill in the remaining client fields and put it into the global list */ - strcpy(new_client->name,client_name); + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); - new_client->id = lm80_id++; - data->valid = 0; - init_MUTEX(&data->update_lock); + new_client->id = lm80_id++; + data->valid = 0; + init_MUTEX(&data->update_lock); - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; - /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry(new_client,type_name, - lm80_dir_table_template, - THIS_MODULE)) < 0) { - err = i; - goto ERROR4; - } - data->sysctl_id = i; + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry(new_client, type_name, + lm80_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; - lm80_init_client(new_client); - return 0; + lm80_init_client(new_client); + return 0; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR4: - i2c_detach_client(new_client); -ERROR3: -ERROR1: - kfree(new_client); -ERROR0: - return err; + ERROR4: + i2c_detach_client(new_client); + ERROR3: + ERROR1: + kfree(new_client); + ERROR0: + return err; } int lm80_detach_client(struct i2c_client *client) { - int err; + int err; - sensors_deregister_entry(((struct lm80_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct lm80_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("lm80.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("lm80.o: Client deregistration failed, client not detached.\n"); + return err; + } - kfree(client); + kfree(client); - return 0; + return 0; } /* No commands defined yet */ int lm80_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } -void lm80_inc_use (struct i2c_client *client) +void lm80_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } -void lm80_dec_use (struct i2c_client *client) +void lm80_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } - + int lm80_read_value(struct i2c_client *client, u8 reg) { - return i2c_smbus_read_byte_data(client, reg); + return i2c_smbus_read_byte_data(client, reg); } int lm80_write_value(struct i2c_client *client, u8 reg, u8 value) { - return i2c_smbus_write_byte_data(client, reg,value); + return i2c_smbus_write_byte_data(client, reg, value); } /* Called when we have found a new LM80. It should set limits, etc. */ void lm80_init_client(struct i2c_client *client) { - /* Reset all except Watchdog values and last conversion values - This sets fan-divs to 2, among others. This makes most other - initializations unnecessary */ - lm80_write_value(client,LM80_REG_CONFIG,0x80); - /* Set 11-bit temperature resolution */ - lm80_write_value(client,LM80_REG_RES,0x08); + /* Reset all except Watchdog values and last conversion values + This sets fan-divs to 2, among others. This makes most other + initializations unnecessary */ + lm80_write_value(client, LM80_REG_CONFIG, 0x80); + /* Set 11-bit temperature resolution */ + lm80_write_value(client, LM80_REG_RES, 0x08); - lm80_write_value(client,LM80_REG_IN_MIN(0),IN_TO_REG(LM80_INIT_IN_MIN_0,0)); - lm80_write_value(client,LM80_REG_IN_MAX(0),IN_TO_REG(LM80_INIT_IN_MAX_0,0)); - lm80_write_value(client,LM80_REG_IN_MIN(1),IN_TO_REG(LM80_INIT_IN_MIN_1,1)); - lm80_write_value(client,LM80_REG_IN_MAX(1),IN_TO_REG(LM80_INIT_IN_MAX_1,1)); - lm80_write_value(client,LM80_REG_IN_MIN(2),IN_TO_REG(LM80_INIT_IN_MIN_2,2)); - lm80_write_value(client,LM80_REG_IN_MAX(2),IN_TO_REG(LM80_INIT_IN_MAX_2,2)); - lm80_write_value(client,LM80_REG_IN_MIN(3),IN_TO_REG(LM80_INIT_IN_MIN_3,3)); - lm80_write_value(client,LM80_REG_IN_MAX(3),IN_TO_REG(LM80_INIT_IN_MAX_3,3)); - lm80_write_value(client,LM80_REG_IN_MIN(4),IN_TO_REG(LM80_INIT_IN_MIN_4,4)); - lm80_write_value(client,LM80_REG_IN_MAX(4),IN_TO_REG(LM80_INIT_IN_MAX_4,4)); - lm80_write_value(client,LM80_REG_IN_MIN(5),IN_TO_REG(LM80_INIT_IN_MIN_5,5)); - lm80_write_value(client,LM80_REG_IN_MAX(5),IN_TO_REG(LM80_INIT_IN_MAX_5,5)); - lm80_write_value(client,LM80_REG_IN_MIN(6),IN_TO_REG(LM80_INIT_IN_MIN_6,6)); - lm80_write_value(client,LM80_REG_IN_MAX(6),IN_TO_REG(LM80_INIT_IN_MAX_6,6)); - lm80_write_value(client,LM80_REG_FAN1_MIN,FAN_TO_REG(LM80_INIT_FAN_MIN_1,2)); - lm80_write_value(client,LM80_REG_FAN2_MIN,FAN_TO_REG(LM80_INIT_FAN_MIN_2,2)); - lm80_write_value(client,LM80_REG_TEMP_HOT_MAX, - TEMP_LIMIT_TO_REG(LM80_INIT_TEMP_OS_MAX)); - lm80_write_value(client,LM80_REG_TEMP_HOT_HYST, - TEMP_LIMIT_TO_REG(LM80_INIT_TEMP_OS_HYST)); - lm80_write_value(client,LM80_REG_TEMP_OS_MAX, - TEMP_LIMIT_TO_REG(LM80_INIT_TEMP_OS_MAX)); - lm80_write_value(client,LM80_REG_TEMP_OS_HYST, - TEMP_LIMIT_TO_REG(LM80_INIT_TEMP_OS_HYST)); + lm80_write_value(client, LM80_REG_IN_MIN(0), + IN_TO_REG(LM80_INIT_IN_MIN_0, 0)); + lm80_write_value(client, LM80_REG_IN_MAX(0), + IN_TO_REG(LM80_INIT_IN_MAX_0, 0)); + lm80_write_value(client, LM80_REG_IN_MIN(1), + IN_TO_REG(LM80_INIT_IN_MIN_1, 1)); + lm80_write_value(client, LM80_REG_IN_MAX(1), + IN_TO_REG(LM80_INIT_IN_MAX_1, 1)); + lm80_write_value(client, LM80_REG_IN_MIN(2), + IN_TO_REG(LM80_INIT_IN_MIN_2, 2)); + lm80_write_value(client, LM80_REG_IN_MAX(2), + IN_TO_REG(LM80_INIT_IN_MAX_2, 2)); + lm80_write_value(client, LM80_REG_IN_MIN(3), + IN_TO_REG(LM80_INIT_IN_MIN_3, 3)); + lm80_write_value(client, LM80_REG_IN_MAX(3), + IN_TO_REG(LM80_INIT_IN_MAX_3, 3)); + lm80_write_value(client, LM80_REG_IN_MIN(4), + IN_TO_REG(LM80_INIT_IN_MIN_4, 4)); + lm80_write_value(client, LM80_REG_IN_MAX(4), + IN_TO_REG(LM80_INIT_IN_MAX_4, 4)); + lm80_write_value(client, LM80_REG_IN_MIN(5), + IN_TO_REG(LM80_INIT_IN_MIN_5, 5)); + lm80_write_value(client, LM80_REG_IN_MAX(5), + IN_TO_REG(LM80_INIT_IN_MAX_5, 5)); + lm80_write_value(client, LM80_REG_IN_MIN(6), + IN_TO_REG(LM80_INIT_IN_MIN_6, 6)); + lm80_write_value(client, LM80_REG_IN_MAX(6), + IN_TO_REG(LM80_INIT_IN_MAX_6, 6)); + lm80_write_value(client, LM80_REG_FAN1_MIN, + FAN_TO_REG(LM80_INIT_FAN_MIN_1, 2)); + lm80_write_value(client, LM80_REG_FAN2_MIN, + FAN_TO_REG(LM80_INIT_FAN_MIN_2, 2)); + lm80_write_value(client, LM80_REG_TEMP_HOT_MAX, + TEMP_LIMIT_TO_REG(LM80_INIT_TEMP_OS_MAX)); + lm80_write_value(client, LM80_REG_TEMP_HOT_HYST, + TEMP_LIMIT_TO_REG(LM80_INIT_TEMP_OS_HYST)); + lm80_write_value(client, LM80_REG_TEMP_OS_MAX, + TEMP_LIMIT_TO_REG(LM80_INIT_TEMP_OS_MAX)); + lm80_write_value(client, LM80_REG_TEMP_OS_HYST, + TEMP_LIMIT_TO_REG(LM80_INIT_TEMP_OS_HYST)); - /* Start monitoring */ - lm80_write_value(client,LM80_REG_CONFIG,0x01); + /* Start monitoring */ + lm80_write_value(client, LM80_REG_CONFIG, 0x01); } void lm80_update_client(struct i2c_client *client) { - struct lm80_data *data = client->data; - int i; + struct lm80_data *data = client->data; + int i; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > 2*HZ ) || - (jiffies < data->last_updated) || ! data->valid) { + if ((jiffies - data->last_updated > 2 * HZ) || + (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("Starting lm80 update\n"); + printk("Starting lm80 update\n"); #endif - for (i = 0; i <= 6; i++) { - data->in[i] = lm80_read_value(client,LM80_REG_IN(i)); - data->in_min[i] = lm80_read_value(client,LM80_REG_IN_MIN(i)); - data->in_max[i] = lm80_read_value(client,LM80_REG_IN_MAX(i)); - } - data->fan[0] = lm80_read_value(client,LM80_REG_FAN1); - data->fan_min[0] = lm80_read_value(client,LM80_REG_FAN1_MIN); - data->fan[1] = lm80_read_value(client,LM80_REG_FAN2); - data->fan_min[1] = lm80_read_value(client,LM80_REG_FAN2_MIN); - - data->temp = (lm80_read_value(client,LM80_REG_TEMP) << 8) | - (lm80_read_value(client,LM80_REG_RES) & 0xf0); - data->temp_os_max = lm80_read_value(client,LM80_REG_TEMP_OS_MAX); - data->temp_os_hyst = lm80_read_value(client,LM80_REG_TEMP_OS_HYST); - data->temp_hot_max = lm80_read_value(client,LM80_REG_TEMP_HOT_MAX); - data->temp_hot_hyst = lm80_read_value(client,LM80_REG_TEMP_HOT_HYST); + for (i = 0; i <= 6; i++) { + data->in[i] = + lm80_read_value(client, LM80_REG_IN(i)); + data->in_min[i] = + lm80_read_value(client, LM80_REG_IN_MIN(i)); + data->in_max[i] = + lm80_read_value(client, LM80_REG_IN_MAX(i)); + } + data->fan[0] = lm80_read_value(client, LM80_REG_FAN1); + data->fan_min[0] = + lm80_read_value(client, LM80_REG_FAN1_MIN); + data->fan[1] = lm80_read_value(client, LM80_REG_FAN2); + data->fan_min[1] = + lm80_read_value(client, LM80_REG_FAN2_MIN); - i = lm80_read_value(client,LM80_REG_FANDIV); - data->fan_div[0] = (i >> 2) & 0x03; - data->fan_div[1] = (i >> 4) & 0x03; - data->alarms = lm80_read_value(client,LM80_REG_ALARM1) + - (lm80_read_value(client,LM80_REG_ALARM2) << 8); - data->last_updated = jiffies; - data->valid = 1; - } + data->temp = + (lm80_read_value(client, LM80_REG_TEMP) << 8) | + (lm80_read_value(client, LM80_REG_RES) & 0xf0); + data->temp_os_max = + lm80_read_value(client, LM80_REG_TEMP_OS_MAX); + data->temp_os_hyst = + lm80_read_value(client, LM80_REG_TEMP_OS_HYST); + data->temp_hot_max = + lm80_read_value(client, LM80_REG_TEMP_HOT_MAX); + data->temp_hot_hyst = + lm80_read_value(client, LM80_REG_TEMP_HOT_HYST); - up(&data->update_lock); + i = lm80_read_value(client, LM80_REG_FANDIV); + data->fan_div[0] = (i >> 2) & 0x03; + data->fan_div[1] = (i >> 4) & 0x03; + data->alarms = lm80_read_value(client, LM80_REG_ALARM1) + + (lm80_read_value(client, LM80_REG_ALARM2) << 8); + data->last_updated = jiffies; + data->valid = 1; + } + + up(&data->update_lock); } @@ -528,179 +561,196 @@ void lm80_update_client(struct i2c_client *client) large enough (by checking the incoming value of *nrels). This is not very good practice, but as long as you put less than about 5 values in results, you can assume it is large enough. */ -void lm80_in(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void lm80_in(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - struct lm80_data *data = client->data; - int nr = ctl_name - LM80_SYSCTL_IN0; + struct lm80_data *data = client->data; + int nr = ctl_name - LM80_SYSCTL_IN0; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 2; - else if (operation == SENSORS_PROC_REAL_READ) { - lm80_update_client(client); - results[0] = IN_FROM_REG(data->in_min[nr],nr); - results[1] = IN_FROM_REG(data->in_max[nr],nr); - results[2] = IN_FROM_REG(data->in[nr],nr); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->in_min[nr] = IN_TO_REG(results[0],nr); - lm80_write_value(client,LM80_REG_IN_MIN(nr),data->in_min[nr]); - } - if (*nrels_mag >= 2) { - data->in_max[nr] = IN_TO_REG(results[1],nr); - lm80_write_value(client,LM80_REG_IN_MAX(nr),data->in_max[nr]); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + lm80_update_client(client); + results[0] = IN_FROM_REG(data->in_min[nr], nr); + results[1] = IN_FROM_REG(data->in_max[nr], nr); + results[2] = IN_FROM_REG(data->in[nr], nr); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->in_min[nr] = IN_TO_REG(results[0], nr); + lm80_write_value(client, LM80_REG_IN_MIN(nr), + data->in_min[nr]); + } + if (*nrels_mag >= 2) { + data->in_max[nr] = IN_TO_REG(results[1], nr); + lm80_write_value(client, LM80_REG_IN_MAX(nr), + data->in_max[nr]); + } + } } void lm80_fan(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct lm80_data *data = client->data; - int nr = ctl_name - LM80_SYSCTL_FAN1 + 1; + struct lm80_data *data = client->data; + int nr = ctl_name - LM80_SYSCTL_FAN1 + 1; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - lm80_update_client(client); - results[0] = FAN_FROM_REG(data->fan_min[nr-1], - DIV_FROM_REG(data->fan_div[nr-1])); - results[1] = FAN_FROM_REG(data->fan[nr-1], - DIV_FROM_REG(data->fan_div[nr-1])); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->fan_min[nr-1] = FAN_TO_REG(results[0], - DIV_FROM_REG(data->fan_div[nr-1])); - lm80_write_value(client,nr==1?LM80_REG_FAN1_MIN:LM80_REG_FAN2_MIN, - data->fan_min[nr-1]); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + lm80_update_client(client); + results[0] = FAN_FROM_REG(data->fan_min[nr - 1], + DIV_FROM_REG(data-> + fan_div[nr - 1])); + results[1] = + FAN_FROM_REG(data->fan[nr - 1], + DIV_FROM_REG(data->fan_div[nr - 1])); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->fan_min[nr - 1] = FAN_TO_REG(results[0], + DIV_FROM_REG + (data-> + fan_div[nr - + 1])); + lm80_write_value(client, + nr == + 1 ? LM80_REG_FAN1_MIN : + LM80_REG_FAN2_MIN, + data->fan_min[nr - 1]); + } + } } void lm80_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct lm80_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 2; - else if (operation == SENSORS_PROC_REAL_READ) { - lm80_update_client(client); - results[0] = TEMP_LIMIT_FROM_REG(data->temp_hot_max); - results[1] = TEMP_LIMIT_FROM_REG(data->temp_hot_hyst); - results[2] = TEMP_LIMIT_FROM_REG(data->temp_os_max); - results[3] = TEMP_LIMIT_FROM_REG(data->temp_os_hyst); - results[4] = TEMP_FROM_REG(data->temp); - *nrels_mag = 5; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->temp_hot_max = TEMP_LIMIT_TO_REG(results[0]); - lm80_write_value(client,LM80_REG_TEMP_HOT_MAX,data->temp_hot_max); - } - if (*nrels_mag >= 2) { - data->temp_hot_hyst = TEMP_LIMIT_TO_REG(results[1]); - lm80_write_value(client,LM80_REG_TEMP_HOT_HYST,data->temp_hot_hyst); - } - if (*nrels_mag >= 3) { - data->temp_os_max = TEMP_LIMIT_TO_REG(results[2]); - lm80_write_value(client,LM80_REG_TEMP_OS_MAX,data->temp_os_max); - } - if (*nrels_mag >= 4) { - data->temp_os_hyst = TEMP_LIMIT_TO_REG(results[3]); - lm80_write_value(client,LM80_REG_TEMP_OS_HYST,data->temp_os_hyst); - } - } + struct lm80_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + lm80_update_client(client); + results[0] = TEMP_LIMIT_FROM_REG(data->temp_hot_max); + results[1] = TEMP_LIMIT_FROM_REG(data->temp_hot_hyst); + results[2] = TEMP_LIMIT_FROM_REG(data->temp_os_max); + results[3] = TEMP_LIMIT_FROM_REG(data->temp_os_hyst); + results[4] = TEMP_FROM_REG(data->temp); + *nrels_mag = 5; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->temp_hot_max = TEMP_LIMIT_TO_REG(results[0]); + lm80_write_value(client, LM80_REG_TEMP_HOT_MAX, + data->temp_hot_max); + } + if (*nrels_mag >= 2) { + data->temp_hot_hyst = + TEMP_LIMIT_TO_REG(results[1]); + lm80_write_value(client, LM80_REG_TEMP_HOT_HYST, + data->temp_hot_hyst); + } + if (*nrels_mag >= 3) { + data->temp_os_max = TEMP_LIMIT_TO_REG(results[2]); + lm80_write_value(client, LM80_REG_TEMP_OS_MAX, + data->temp_os_max); + } + if (*nrels_mag >= 4) { + data->temp_os_hyst = TEMP_LIMIT_TO_REG(results[3]); + lm80_write_value(client, LM80_REG_TEMP_OS_HYST, + data->temp_os_hyst); + } + } } void lm80_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct lm80_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - lm80_update_client(client); - results[0] = ALARMS_FROM_REG(data->alarms); - *nrels_mag = 1; - } + struct lm80_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + lm80_update_client(client); + results[0] = ALARMS_FROM_REG(data->alarms); + *nrels_mag = 1; + } } void lm80_fan_div(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct lm80_data *data = client->data; - int old; + struct lm80_data *data = client->data; + int old; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - lm80_update_client(client); - results[0] = DIV_FROM_REG(data->fan_div[0]); - results[1] = DIV_FROM_REG(data->fan_div[1]); - results[2] = 2; - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - old = lm80_read_value(client,LM80_REG_FANDIV); - if (*nrels_mag >= 2) { - data->fan_div[1] = DIV_TO_REG(results[1]); - old = (old & 0xcf) | (data->fan_div[1] << 4); - } - if (*nrels_mag >= 1) { - data->fan_div[0] = DIV_TO_REG(results[0]); - old = (old & 0xf3) | (data->fan_div[0] << 2); - lm80_write_value(client,LM80_REG_FANDIV,old); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + lm80_update_client(client); + results[0] = DIV_FROM_REG(data->fan_div[0]); + results[1] = DIV_FROM_REG(data->fan_div[1]); + results[2] = 2; + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + old = lm80_read_value(client, LM80_REG_FANDIV); + if (*nrels_mag >= 2) { + data->fan_div[1] = DIV_TO_REG(results[1]); + old = (old & 0xcf) | (data->fan_div[1] << 4); + } + if (*nrels_mag >= 1) { + data->fan_div[0] = DIV_TO_REG(results[0]); + old = (old & 0xf3) | (data->fan_div[0] << 2); + lm80_write_value(client, LM80_REG_FANDIV, old); + } + } } int __init sensors_lm80_init(void) { - int res; + int res; - printk("lm80.o version %s (%s)\n",LM_VERSION,LM_DATE); - lm80_initialized = 0; + printk("lm80.o version %s (%s)\n", LM_VERSION, LM_DATE); + lm80_initialized = 0; - if ((res =i2c_add_driver(&lm80_driver))) { - printk("lm80.o: Driver registration failed, module not inserted.\n"); - lm80_cleanup(); - return res; - } - lm80_initialized ++; - return 0; + if ((res = i2c_add_driver(&lm80_driver))) { + printk + ("lm80.o: Driver registration failed, module not inserted.\n"); + lm80_cleanup(); + return res; + } + lm80_initialized++; + return 0; } int __init lm80_cleanup(void) { - int res; + int res; - if (lm80_initialized >= 1) { - if ((res = i2c_del_driver(&lm80_driver))) { - printk("lm80.o: Driver deregistration failed, module not removed.\n"); - return res; - } - lm80_initialized --; - } - return 0; + if (lm80_initialized >= 1) { + if ((res = i2c_del_driver(&lm80_driver))) { + printk + ("lm80.o: Driver deregistration failed, module not removed.\n"); + return res; + } + lm80_initialized--; + } + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard and Philip Edelbrock "); +MODULE_AUTHOR + ("Frodo Looijaard and Philip Edelbrock "); MODULE_DESCRIPTION("LM80 driver"); int init_module(void) { - return sensors_lm80_init(); + return sensors_lm80_init(); } int cleanup_module(void) { - return lm80_cleanup(); + return lm80_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/ltc1710.c b/kernel/chips/ltc1710.c index d0b26805..44a3454b 100644 --- a/kernel/chips/ltc1710.c +++ b/kernel/chips/ltc1710.c @@ -60,10 +60,10 @@ #endif /* Addresses to scan */ -static unsigned short normal_i2c[] = {SENSORS_I2C_END}; -static unsigned short normal_i2c_range[] = {0x58,0x5a,SENSORS_I2C_END}; -static unsigned int normal_isa[] = {SENSORS_ISA_END}; -static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; +static unsigned short normal_i2c[] = { SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { 0x58, 0x5a, SENSORS_I2C_END }; +static unsigned int normal_isa[] = { SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; /* Insmod parameters */ SENSORS_INSMOD_1(ltc1710); @@ -73,56 +73,56 @@ SENSORS_INSMOD_1(ltc1710); /* (No registers. [Wow! This thing is SIMPLE!] ) */ /* Initial values */ -#define LTC1710_INIT 0 /* Both off */ +#define LTC1710_INIT 0 /* Both off */ /* Each client has this additional data */ struct ltc1710_data { - int sysctl_id; + int sysctl_id; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ - u8 status; /* Register values */ + u8 status; /* Register values */ }; #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ #ifdef MODULE static #else extern #endif - int __init sensors_ltc1710_init(void); +int __init sensors_ltc1710_init(void); static int __init ltc1710_cleanup(void); static int ltc1710_attach_adapter(struct i2c_adapter *adapter); -static int ltc1710_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind); +static int ltc1710_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); static int ltc1710_detach_client(struct i2c_client *client); static int ltc1710_command(struct i2c_client *client, unsigned int cmd, - void *arg); -static void ltc1710_inc_use (struct i2c_client *client); -static void ltc1710_dec_use (struct i2c_client *client); -static void ltc1710_switch1(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void ltc1710_switch2(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); + void *arg); +static void ltc1710_inc_use(struct i2c_client *client); +static void ltc1710_dec_use(struct i2c_client *client); +static void ltc1710_switch1(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void ltc1710_switch2(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static void ltc1710_update_client(struct i2c_client *client); /* This is the driver that will be inserted */ static struct i2c_driver ltc1710_driver = { - /* name */ "LTC1710 sensor chip driver", - /* id */ I2C_DRIVERID_LTC1710, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ <c1710_attach_adapter, - /* detach_client */ <c1710_detach_client, - /* command */ <c1710_command, - /* inc_use */ <c1710_inc_use, - /* dec_use */ <c1710_dec_use + /* name */ "LTC1710 sensor chip driver", + /* id */ I2C_DRIVERID_LTC1710, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ <c1710_attach_adapter, + /* detach_client */ <c1710_detach_client, + /* command */ <c1710_command, + /* inc_use */ <c1710_inc_use, + /* dec_use */ <c1710_dec_use }; /* These files are created for each detected LTC1710. This is just a template; @@ -131,11 +131,11 @@ static struct i2c_driver ltc1710_driver = { is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table ltc1710_dir_table_template[] = { - { LTC1710_SYSCTL_SWITCH_1, "switch1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, <c1710_switch1 }, - { LTC1710_SYSCTL_SWITCH_2, "switch2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, <c1710_switch2 }, - { 0 } + {LTC1710_SYSCTL_SWITCH_1, "switch1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, <c1710_switch1}, + {LTC1710_SYSCTL_SWITCH_2, "switch2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, <c1710_switch2}, + {0} }; /* Used by init/cleanup */ @@ -148,245 +148,252 @@ static int ltc1710_id = 0; int ltc1710_attach_adapter(struct i2c_adapter *adapter) { - return sensors_detect(adapter,&addr_data,ltc1710_detect); + return sensors_detect(adapter, &addr_data, ltc1710_detect); } /* This function is called by sensors_detect */ -int ltc1710_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind) +int ltc1710_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) { - int i; - struct i2c_client *new_client; - struct ltc1710_data *data; - int err=0; - const char *type_name,*client_name; + int i; + struct i2c_client *new_client; + struct ltc1710_data *data; + int err = 0; + const char *type_name, *client_name; - /* Make sure we aren't probing the ISA bus!! This is just a safety check - at this moment; sensors_detect really won't call us. */ + /* Make sure we aren't probing the ISA bus!! This is just a safety check + at this moment; sensors_detect really won't call us. */ #ifdef DEBUG - if (i2c_is_isa_adapter(adapter)) { - printk("ltc1710.o: ltc1710_detect called for an ISA bus adapter?!?\n"); - return 0; - } + if (i2c_is_isa_adapter(adapter)) { + printk + ("ltc1710.o: ltc1710_detect called for an ISA bus adapter?!?\n"); + return 0; + } #endif - if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_BYTE)) - goto ERROR0; + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) + goto ERROR0; - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access ltc1710_{read,write}_value. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct ltc1710_data), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR0; - } + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access ltc1710_{read,write}_value. */ + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct ltc1710_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } - data = (struct ltc1710_data *) (new_client + 1); - new_client->addr = address; - new_client->data = data; - new_client->adapter = adapter; - new_client->driver = <c1710_driver; - new_client->flags = 0; + data = (struct ltc1710_data *) (new_client + 1); + new_client->addr = address; + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = <c1710_driver; + new_client->flags = 0; - /* Now, we would do the remaining detection. But the LTC1710 is plainly - impossible to detect! Stupid chip. */ + /* Now, we would do the remaining detection. But the LTC1710 is plainly + impossible to detect! Stupid chip. */ - /* Determine the chip type - only one kind supported! */ - if (kind <= 0) - kind = ltc1710; + /* Determine the chip type - only one kind supported! */ + if (kind <= 0) + kind = ltc1710; - if (kind == ltc1710) { - type_name = "ltc1710"; - client_name = "LTC1710 chip"; - } else { + if (kind == ltc1710) { + type_name = "ltc1710"; + client_name = "LTC1710 chip"; + } else { #ifdef DEBUG - printk("ltc1710.o: Internal error: unknown kind (%d)?!?",kind); + printk("ltc1710.o: Internal error: unknown kind (%d)?!?", + kind); #endif - goto ERROR1; - } + goto ERROR1; + } - /* Fill in the remaining client fields and put it into the global list */ - strcpy(new_client->name,client_name); + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); - new_client->id = ltc1710_id++; - data->valid = 0; - init_MUTEX(&data->update_lock); + new_client->id = ltc1710_id++; + data->valid = 0; + init_MUTEX(&data->update_lock); - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; - /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry(new_client,type_name, - ltc1710_dir_table_template, - THIS_MODULE)) < 0) { - err = i; - goto ERROR4; - } - data->sysctl_id = i; + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry(new_client, type_name, + ltc1710_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; - return 0; + return 0; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR4: - i2c_detach_client(new_client); -ERROR3: -ERROR1: - kfree(new_client); -ERROR0: - return err; + ERROR4: + i2c_detach_client(new_client); + ERROR3: + ERROR1: + kfree(new_client); + ERROR0: + return err; } int ltc1710_detach_client(struct i2c_client *client) { - int err; + int err; - sensors_deregister_entry(((struct ltc1710_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct ltc1710_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("ltc1710.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("ltc1710.o: Client deregistration failed, client not detached.\n"); + return err; + } - kfree(client); + kfree(client); - return 0; + return 0; } /* No commands defined yet */ int ltc1710_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } /* Nothing here yet */ -void ltc1710_inc_use (struct i2c_client *client) +void ltc1710_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } /* Nothing here yet */ -void ltc1710_dec_use (struct i2c_client *client) +void ltc1710_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } void ltc1710_update_client(struct i2c_client *client) { - struct ltc1710_data *data = client->data; + struct ltc1710_data *data = client->data; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > HZ+HZ/2 ) || - (jiffies < data->last_updated) || ! data->valid) { + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("Starting ltc1710 update\n"); + printk("Starting ltc1710 update\n"); #endif - /* data->status = i2c_smbus_read_byte(client); - Unfortunately, reads always fail! */ - data->last_updated = jiffies; - data->valid = 1; - } + /* data->status = i2c_smbus_read_byte(client); + Unfortunately, reads always fail! */ + data->last_updated = jiffies; + data->valid = 1; + } - up(&data->update_lock); + up(&data->update_lock); } -void ltc1710_switch1(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void ltc1710_switch1(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - struct ltc1710_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - ltc1710_update_client(client); - results[0] = data->status & 1; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->status = (data->status & 2) | results[0]; - i2c_smbus_write_byte(client,data->status); - } - } + struct ltc1710_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + ltc1710_update_client(client); + results[0] = data->status & 1; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->status = (data->status & 2) | results[0]; + i2c_smbus_write_byte(client, data->status); + } + } } -void ltc1710_switch2(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void ltc1710_switch2(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - struct ltc1710_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - ltc1710_update_client(client); - results[0] = (data->status & 2) >> 1; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->status = (data->status & 1) | (results[0] << 1); - i2c_smbus_write_byte(client,data->status); - } - } + struct ltc1710_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + ltc1710_update_client(client); + results[0] = (data->status & 2) >> 1; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->status = + (data->status & 1) | (results[0] << 1); + i2c_smbus_write_byte(client, data->status); + } + } } int __init sensors_ltc1710_init(void) { - int res; + int res; - printk("ltc1710.o version %s (%s)\n",LM_VERSION,LM_DATE); - ltc1710_initialized = 0; - if ((res = i2c_add_driver(<c1710_driver))) { - printk("ltc1710.o: Driver registration failed, module not inserted.\n"); - ltc1710_cleanup(); - return res; - } - ltc1710_initialized ++; - return 0; + printk("ltc1710.o version %s (%s)\n", LM_VERSION, LM_DATE); + ltc1710_initialized = 0; + if ((res = i2c_add_driver(<c1710_driver))) { + printk + ("ltc1710.o: Driver registration failed, module not inserted.\n"); + ltc1710_cleanup(); + return res; + } + ltc1710_initialized++; + return 0; } int __init ltc1710_cleanup(void) { - int res; + int res; - if (ltc1710_initialized >= 1) { - if ((res = i2c_del_driver(<c1710_driver))) { - printk("ltc1710.o: Driver deregistration failed, module not removed.\n"); - return res; - } - ltc1710_initialized --; - } + if (ltc1710_initialized >= 1) { + if ((res = i2c_del_driver(<c1710_driver))) { + printk + ("ltc1710.o: Driver deregistration failed, module not removed.\n"); + return res; + } + ltc1710_initialized--; + } - return 0; + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard and Philip Edelbrock "); +MODULE_AUTHOR + ("Frodo Looijaard and Philip Edelbrock "); MODULE_DESCRIPTION("LTC1710 driver"); int init_module(void) { - return sensors_ltc1710_init(); + return sensors_ltc1710_init(); } int cleanup_module(void) { - return ltc1710_cleanup(); + return ltc1710_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/matorb.c b/kernel/chips/matorb.c index 30b7462b..e6f24a41 100644 --- a/kernel/chips/matorb.c +++ b/kernel/chips/matorb.c @@ -41,10 +41,10 @@ #endif /* Addresses to scan */ -static unsigned short normal_i2c[] = {0x2E,SENSORS_I2C_END}; -static unsigned short normal_i2c_range[] = {SENSORS_I2C_END}; -static unsigned int normal_isa[] = {SENSORS_ISA_END}; -static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; +static unsigned short normal_i2c[] = { 0x2E, SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { SENSORS_I2C_END }; +static unsigned int normal_isa[] = { SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; /* Insmod parameters */ SENSORS_INSMOD_1(matorb); @@ -54,51 +54,52 @@ SENSORS_INSMOD_1(matorb); /* Each client has this additional data */ struct matorb_data { - int sysctl_id; + int sysctl_id; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ }; #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ #ifdef MODULE static #else extern #endif - int __init sensors_matorb_init(void); +int __init sensors_matorb_init(void); static int __init matorb_cleanup(void); static int matorb_attach_adapter(struct i2c_adapter *adapter); -static int matorb_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind); +static int matorb_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); static void matorb_init_client(struct i2c_client *client); static int matorb_detach_client(struct i2c_client *client); static int matorb_command(struct i2c_client *client, unsigned int cmd, - void *arg); -static void matorb_inc_use (struct i2c_client *client); -static void matorb_dec_use (struct i2c_client *client); -static int matorb_write_value(struct i2c_client *client, u8 reg, u16 value); -static void matorb_disp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); + void *arg); +static void matorb_inc_use(struct i2c_client *client); +static void matorb_dec_use(struct i2c_client *client); +static int matorb_write_value(struct i2c_client *client, u8 reg, + u16 value); +static void matorb_disp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static void matorb_update_client(struct i2c_client *client); /* This is the driver that will be inserted */ static struct i2c_driver matorb_driver = { - /* name */ "Matrix Orbital LCD driver", - /* id */ I2C_DRIVERID_MATORB, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &matorb_attach_adapter, - /* detach_client */ &matorb_detach_client, - /* command */ &matorb_command, - /* inc_use */ &matorb_inc_use, - /* dec_use */ &matorb_dec_use + /* name */ "Matrix Orbital LCD driver", + /* id */ I2C_DRIVERID_MATORB, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &matorb_attach_adapter, + /* detach_client */ &matorb_detach_client, + /* command */ &matorb_command, + /* inc_use */ &matorb_inc_use, + /* dec_use */ &matorb_dec_use }; /* These files are created for each detected MATORB. This is just a template; @@ -107,9 +108,9 @@ static struct i2c_driver matorb_driver = { is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table matorb_dir_table_template[] = { - { MATORB_SYSCTL_DISP, "disp", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &matorb_disp }, - { 0 } + {MATORB_SYSCTL_DISP, "disp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &matorb_disp}, + {0} }; /* Used by init/cleanup */ @@ -119,126 +120,129 @@ static int matorb_id = 0; int matorb_attach_adapter(struct i2c_adapter *adapter) { - return sensors_detect(adapter,&addr_data,matorb_detect); + return sensors_detect(adapter, &addr_data, matorb_detect); } /* This function is called by sensors_detect */ -int matorb_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind) +int matorb_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) { - int i,cur; - struct i2c_client *new_client; - struct matorb_data *data; - int err=0; - const char *type_name="matorb"; - const char *client_name="matorb"; + int i, cur; + struct i2c_client *new_client; + struct matorb_data *data; + int err = 0; + const char *type_name = "matorb"; + const char *client_name = "matorb"; - /* Make sure we aren't probing the ISA bus!! This is just a safety check - at this moment; sensors_detect really won't call us. */ + /* Make sure we aren't probing the ISA bus!! This is just a safety check + at this moment; sensors_detect really won't call us. */ #ifdef DEBUG - if (i2c_is_isa_adapter(adapter)) { - printk("matorb.o: matorb_detect called for an ISA bus adapter?!?\n"); - return 0; - } + if (i2c_is_isa_adapter(adapter)) { + printk + ("matorb.o: matorb_detect called for an ISA bus adapter?!?\n"); + return 0; + } #endif - if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_WRITE_BYTE | - I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) - goto ERROR0; + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE | + I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) + goto ERROR0; - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access matorb_{read,write}_value. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct matorb_data), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR0; - } + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access matorb_{read,write}_value. */ + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct matorb_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } - data = (struct matorb_data *) (new_client + 1); - new_client->addr = address; - new_client->data = data; - new_client->adapter = adapter; - new_client->driver = &matorb_driver; - new_client->flags = 0; + data = (struct matorb_data *) (new_client + 1); + new_client->addr = address; + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &matorb_driver; + new_client->flags = 0; - /* Now, we do the remaining detection. It is lousy. */ - cur = i2c_smbus_write_byte_data(new_client,0x0FE, 0x58); /* clear screen */ - - printk("matorb.o: debug detect 0x%X\n",cur); - - /* Fill in the remaining client fields and put it into the global list */ - strcpy(new_client->name,client_name); + /* Now, we do the remaining detection. It is lousy. */ + cur = i2c_smbus_write_byte_data(new_client, 0x0FE, 0x58); /* clear screen */ - new_client->id = matorb_id ++; - data->valid = 0; - init_MUTEX(&data->update_lock); - - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + printk("matorb.o: debug detect 0x%X\n", cur); - /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry(new_client,type_name, - matorb_dir_table_template, - THIS_MODULE)) < 0) { - err = i; - goto ERROR4; - } - data->sysctl_id = i; + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); - matorb_init_client(new_client); - return 0; + new_client->id = matorb_id++; + data->valid = 0; + init_MUTEX(&data->update_lock); + + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; + + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry(new_client, type_name, + matorb_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; + + matorb_init_client(new_client); + return 0; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR4: - i2c_detach_client(new_client); -ERROR3: - kfree(new_client); -ERROR0: - return err; + ERROR4: + i2c_detach_client(new_client); + ERROR3: + kfree(new_client); + ERROR0: + return err; } int matorb_detach_client(struct i2c_client *client) { - int err; + int err; - sensors_deregister_entry(((struct matorb_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct matorb_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("matorb.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("matorb.o: Client deregistration failed, client not detached.\n"); + return err; + } - kfree(client); + kfree(client); - return 0; + return 0; } /* No commands defined yet */ int matorb_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } /* Nothing here yet */ -void matorb_inc_use (struct i2c_client *client) +void matorb_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } /* Nothing here yet */ -void matorb_dec_use (struct i2c_client *client) +void matorb_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } @@ -248,7 +252,7 @@ void matorb_dec_use (struct i2c_client *client) the usual practice. */ int matorb_read_value(struct i2c_client *client, u8 reg) { - return -1; /* Doesn't support reads */ + return -1; /* Doesn't support reads */ } #endif @@ -257,104 +261,106 @@ int matorb_read_value(struct i2c_client *client, u8 reg) the usual practice. */ int matorb_write_value(struct i2c_client *client, u8 reg, u16 value) { - if (reg==0) { - return i2c_smbus_write_byte(client,value); - } else { - return i2c_smbus_write_byte_data(client,reg,value); - } + if (reg == 0) { + return i2c_smbus_write_byte(client, value); + } else { + return i2c_smbus_write_byte_data(client, reg, value); + } } void matorb_init_client(struct i2c_client *client) { - /* Initialize the MATORB chip */ + /* Initialize the MATORB chip */ } void matorb_update_client(struct i2c_client *client) { - struct matorb_data *data = client->data; + struct matorb_data *data = client->data; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > HZ+HZ/2 ) || - (jiffies < data->last_updated) || ! data->valid) { + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("Starting matorb update\n"); + printk("Starting matorb update\n"); #endif /* nothing yet */ - data->last_updated = jiffies; - data->valid = 1; - } + data->last_updated = jiffies; + data->valid = 1; + } - up(&data->update_lock); + up(&data->update_lock); } void matorb_disp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { -int i; + int i; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - matorb_update_client(client); - results[0] = 0; - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - for (i=1; i<=*nrels_mag;i++) { - matorb_write_value(client,0,results[i-1]); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + matorb_update_client(client); + results[0] = 0; + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + for (i = 1; i <= *nrels_mag; i++) { + matorb_write_value(client, 0, results[i - 1]); + } + } } int __init sensors_matorb_init(void) { - int res; + int res; - printk("matorb.o version %s (%s)\n",LM_VERSION,LM_DATE); - matorb_initialized = 0; - if ((res = i2c_add_driver(&matorb_driver))) { - printk("matorb.o: Driver registration failed, module not inserted.\n"); - matorb_cleanup(); - return res; - } - matorb_initialized ++; - return 0; + printk("matorb.o version %s (%s)\n", LM_VERSION, LM_DATE); + matorb_initialized = 0; + if ((res = i2c_add_driver(&matorb_driver))) { + printk + ("matorb.o: Driver registration failed, module not inserted.\n"); + matorb_cleanup(); + return res; + } + matorb_initialized++; + return 0; } int __init matorb_cleanup(void) { - int res; + int res; - if (matorb_initialized >= 1) { - if ((res = i2c_del_driver(&matorb_driver))) { - printk("matorb.o: Driver deregistration failed, module not removed.\n"); - return res; - } - matorb_initialized --; - } + if (matorb_initialized >= 1) { + if ((res = i2c_del_driver(&matorb_driver))) { + printk + ("matorb.o: Driver deregistration failed, module not removed.\n"); + return res; + } + matorb_initialized--; + } - return 0; + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard and Philip Edelbrock "); +MODULE_AUTHOR + ("Frodo Looijaard and Philip Edelbrock "); MODULE_DESCRIPTION("MATORB driver"); int init_module(void) { - return sensors_matorb_init(); + return sensors_matorb_init(); } int cleanup_module(void) { - return matorb_cleanup(); + return matorb_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/maxilife.c b/kernel/chips/maxilife.c index 81c4b960..2d021cc8 100644 --- a/kernel/chips/maxilife.c +++ b/kernel/chips/maxilife.c @@ -63,8 +63,8 @@ static const char *version_str = "1.00 25/2/99 Fons Rademakers"; #endif -#undef AUTODETECT /* try to autodetect MaxiLife version */ -#define NOWRITE /* don't allow writing to MaxiLife registers */ +#undef AUTODETECT /* try to autodetect MaxiLife version */ +#define NOWRITE /* don't allow writing to MaxiLife registers */ /* The MaxiLife registers */ @@ -95,17 +95,17 @@ static const char *version_str = "1.00 25/2/99 Fons Rademakers"; these macros are called: arguments may be evaluated more than once. Fixing this is just not worth it. */ - /* 0xfe: fan off, 0xff: stopped (alarm) */ - /* 19531 / val * 60 == 1171860 / val */ + /* 0xfe: fan off, 0xff: stopped (alarm) */ + /* 19531 / val * 60 == 1171860 / val */ #define FAN_FROM_REG(val) ((val)==0xfe ? -1 : (val)==0xff ? 0 : \ (val)==0x00 ? -1 : (1171860 / (val))) extern inline u8 FAN_TO_REG(long rpm) { - if (rpm == 0) - return 255; - rpm = SENSORS_LIMIT(rpm,1,1000000); - return SENSORS_LIMIT((1171860 + rpm/2) / (rpm),1,254); + if (rpm == 0) + return 255; + rpm = SENSORS_LIMIT(rpm, 1, 1000000); + return SENSORS_LIMIT((1171860 + rpm / 2) / (rpm), 1, 254); } #define TEMP_FROM_REG(val) ((val) * 5) @@ -121,7 +121,7 @@ extern inline u8 FAN_TO_REG(long rpm) #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ /* The following product codenames apply: Cristal/Geronimo: HP KAYAK XU/XAs @@ -137,28 +137,28 @@ enum maxi_type { cristal, cognac, ashaki }; client is allocated. We assume MaxiLife will only be present on the SMBus and not on the ISA bus. */ struct maxi_data { - struct semaphore lock; - int sysctl_id; - enum maxi_type type; + struct semaphore lock; + int sysctl_id; + enum maxi_type type; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ - u8 fan[3]; /* Register value */ - u8 fan_min[3]; /* Register value */ - u8 fan_speed[3]; /* Register value */ - u8 fan_div[3]; /* Static value */ - u8 temp[5]; /* Register value */ - u8 temp_max[5]; /* Static value */ - u8 temp_hyst[5]; /* Static value */ - u8 pll; /* Register value */ - u8 pll_min; /* Register value */ - u8 pll_max; /* register value */ - u8 vid[4]; /* Register value */ - u8 vid_min[4]; /* Register value */ - u8 vid_max[4]; /* Register value */ - u16 alarms; /* Register encoding, combined */ + u8 fan[3]; /* Register value */ + u8 fan_min[3]; /* Register value */ + u8 fan_speed[3]; /* Register value */ + u8 fan_div[3]; /* Static value */ + u8 temp[5]; /* Register value */ + u8 temp_max[5]; /* Static value */ + u8 temp_hyst[5]; /* Static value */ + u8 pll; /* Register value */ + u8 pll_min; /* Register value */ + u8 pll_max; /* register value */ + u8 vid[4]; /* Register value */ + u8 vid_min[4]; /* Register value */ + u8 vid_max[4]; /* Register value */ + u16 alarms; /* Register encoding, combined */ }; @@ -167,38 +167,39 @@ static #else extern #endif - int __init sensors_maxi_init(void); +int __init sensors_maxi_init(void); static int __init maxi_cleanup(void); -static int maxi_attach_adapter(struct i2c_adapter *adapter); -static int maxi_detect_smbus(struct i2c_adapter *adapter); -static int maxi_detach_client(struct i2c_client *client); -static int maxi_detach_smbus(struct i2c_client *client); -static int maxi_new_client(struct i2c_adapter *adapter, - struct i2c_client *new_client); +static int maxi_attach_adapter(struct i2c_adapter *adapter); +static int maxi_detect_smbus(struct i2c_adapter *adapter); +static int maxi_detach_client(struct i2c_client *client); +static int maxi_detach_smbus(struct i2c_client *client); +static int maxi_new_client(struct i2c_adapter *adapter, + struct i2c_client *new_client); static void maxi_remove_client(struct i2c_client *client); -static int maxi_command(struct i2c_client *client, unsigned int cmd, - void *arg); -static void maxi_inc_use (struct i2c_client *client); -static void maxi_dec_use (struct i2c_client *client); +static int maxi_command(struct i2c_client *client, unsigned int cmd, + void *arg); +static void maxi_inc_use(struct i2c_client *client); +static void maxi_dec_use(struct i2c_client *client); -static int maxi_read_value(struct i2c_client *client, u8 register); +static int maxi_read_value(struct i2c_client *client, u8 register); #ifndef NOWRITE -static int maxi_write_value(struct i2c_client *client, u8 register, u8 value); +static int maxi_write_value(struct i2c_client *client, u8 register, + u8 value); #endif static void maxi_update_client(struct i2c_client *client); static void maxi_init_client(struct i2c_client *client); -static void maxi_fan(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void maxi_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void maxi_pll(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void maxi_vid(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void maxi_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); +static void maxi_fan(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void maxi_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void maxi_pll(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void maxi_vid(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void maxi_alarms(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static int maxi_id = 0; @@ -206,14 +207,14 @@ static int maxi_id = 0; /* The driver. I choose to use type i2c_driver, as at is identical to the smbus_driver. */ static struct i2c_driver maxi_driver = { - /* name */ "HP MaxiLife driver", - /* id */ I2C_DRIVERID_MAXILIFE, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &maxi_attach_adapter, - /* detach_client */ &maxi_detach_client, - /* command */ &maxi_command, - /* inc_use */ &maxi_inc_use, - /* dec_use */ &maxi_dec_use + /* name */ "HP MaxiLife driver", + /* id */ I2C_DRIVERID_MAXILIFE, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &maxi_attach_adapter, + /* detach_client */ &maxi_detach_client, + /* command */ &maxi_command, + /* inc_use */ &maxi_inc_use, + /* dec_use */ &maxi_dec_use }; /* Used by maxi_init/cleanup */ @@ -230,35 +231,35 @@ static int maxi_version = cristal; to the parent - which is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table maxi_dir_table_template[] = { - { MAXI_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &maxi_fan }, - { MAXI_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &maxi_fan }, - { MAXI_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &maxi_fan }, - { MAXI_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &maxi_temp }, - { MAXI_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &maxi_temp }, - { MAXI_SYSCTL_TEMP3, "temp3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &maxi_temp }, - { MAXI_SYSCTL_TEMP4, "temp4", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &maxi_temp }, - { MAXI_SYSCTL_TEMP5, "temp5", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &maxi_temp }, - { MAXI_SYSCTL_PLL, "pll", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &maxi_pll }, - { MAXI_SYSCTL_VID1, "vid1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &maxi_vid }, - { MAXI_SYSCTL_VID2, "vid2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &maxi_vid }, - { MAXI_SYSCTL_VID3, "vid3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &maxi_vid }, - { MAXI_SYSCTL_VID4, "vid4", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &maxi_vid }, - { MAXI_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &maxi_alarms }, - { 0 } + {MAXI_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &maxi_fan}, + {MAXI_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &maxi_fan}, + {MAXI_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &maxi_fan}, + {MAXI_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &maxi_temp}, + {MAXI_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &maxi_temp}, + {MAXI_SYSCTL_TEMP3, "temp3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &maxi_temp}, + {MAXI_SYSCTL_TEMP4, "temp4", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &maxi_temp}, + {MAXI_SYSCTL_TEMP5, "temp5", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &maxi_temp}, + {MAXI_SYSCTL_PLL, "pll", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &maxi_pll}, + {MAXI_SYSCTL_VID1, "vid1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &maxi_vid}, + {MAXI_SYSCTL_VID2, "vid2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &maxi_vid}, + {MAXI_SYSCTL_VID3, "vid3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &maxi_vid}, + {MAXI_SYSCTL_VID4, "vid4", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &maxi_vid}, + {MAXI_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &maxi_alarms}, + {0} }; /* This function is called when: @@ -267,10 +268,10 @@ static ctl_table maxi_dir_table_template[] = { - when a new adapter is inserted (and maxi_driver is still present) */ int maxi_attach_adapter(struct i2c_adapter *adapter) { - if (i2c_is_isa_adapter(adapter)) - return 0; - else - return maxi_detect_smbus(adapter); + if (i2c_is_isa_adapter(adapter)) + return 0; + else + return maxi_detect_smbus(adapter); } /* This function is called whenever a client should be removed: @@ -279,148 +280,161 @@ int maxi_attach_adapter(struct i2c_adapter *adapter) is still present). */ int maxi_detach_client(struct i2c_client *client) { - return maxi_detach_smbus(client); + return maxi_detach_smbus(client); } int maxi_detect_smbus(struct i2c_adapter *adapter) { #ifdef AUTODETECT - u8 biosctl; + u8 biosctl; #endif - int address, err; - struct i2c_client *new_client; - enum maxi_type type; - const char *type_name, *client_name; + int address, err; + struct i2c_client *new_client; + enum maxi_type type; + const char *type_name, *client_name; - /* OK, this is no detection. I know. It will do for now, though. */ - err = 0; + /* OK, this is no detection. I know. It will do for now, though. */ + err = 0; - if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_BYTE_DATA)) - goto ERROR0; + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) + goto ERROR0; - for (address = 0x10; (! err) && (address <= 0x14); address++) { + for (address = 0x10; (!err) && (address <= 0x14); address++) { - /* Later on, we will keep a list of registered addresses for each - adapter, and check whether they are used here */ + /* Later on, we will keep a list of registered addresses for each + adapter, and check whether they are used here */ - /* Allocate space for a new client structure. To counter memory - fragmentation somewhat, we only do one kmalloc. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct maxi_data), - GFP_KERNEL))) { - err = -ENOMEM; - continue; - } + /* Allocate space for a new client structure. To counter memory + fragmentation somewhat, we only do one kmalloc. */ + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct maxi_data), + GFP_KERNEL))) { + err = -ENOMEM; + continue; + } - /* Fill the new client structure with data */ - new_client->data = (struct maxi_data *) (new_client + 1); - new_client->addr = address; - new_client->flags = 0; + /* Fill the new client structure with data */ + new_client->data = (struct maxi_data *) (new_client + 1); + new_client->addr = address; + new_client->flags = 0; - if (i2c_smbus_read_byte_data(new_client, MAXI_REG_LED_STATE) < 0) - goto ERROR2; + if (i2c_smbus_read_byte_data + (new_client, MAXI_REG_LED_STATE) < 0) + goto ERROR2; #ifdef AUTODETECT - /* The right way to get the platform info is to read the firmware - revision from serial EEPROM (addr=0x54), at offset 0x0045. - This is a string as: - "CG 00.04" -> Cristal [XU] / Geronimo [XAs] - "CO 00.03" -> Cognac [XU] - "AS 00.01" -> Ashaki [XA] */ - biosctl = i2c_smbus_read_byte_data(new_client, MAXI_REG_BIOS_CTRL); - i2c_smbus_write_byte_data(new_client, MAXI_REG_BIOS_CTRL, biosctl|4); - err = eeprom_read_byte_data(adapter, 0x54, 0x45); - i2c_smbus_write_byte_data(new_client, MAXI_REG_BIOS_CTRL, biosctl); + /* The right way to get the platform info is to read the firmware + revision from serial EEPROM (addr=0x54), at offset 0x0045. + This is a string as: + "CG 00.04" -> Cristal [XU] / Geronimo [XAs] + "CO 00.03" -> Cognac [XU] + "AS 00.01" -> Ashaki [XA] */ + biosctl = + i2c_smbus_read_byte_data(new_client, + MAXI_REG_BIOS_CTRL); + i2c_smbus_write_byte_data(new_client, MAXI_REG_BIOS_CTRL, + biosctl | 4); + err = eeprom_read_byte_data(adapter, 0x54, 0x45); + i2c_smbus_write_byte_data(new_client, MAXI_REG_BIOS_CTRL, + biosctl); #endif - if (maxi_version == cristal) { - type = cristal; - type_name = "maxilife-cg"; - client_name = "HP MaxiLife Rev CG 00.04"; - printk("maxilife: HP KAYAK XU/XAs (Dual Pentium II Slot 1)\n"); - } else if (maxi_version == cognac) { - type = cognac; - type_name = "maxilife-co"; - client_name = "HP MaxiLife Rev CO 00.03"; - printk("maxilife: HP KAYAK XU (Dual Xeon Slot 2 400/450 Mhz)\n"); - } else if (maxi_version == ashaki) { - type = ashaki; - type_name = "maxilife-as"; - client_name = "HP MaxiLife Rev AS 00.01"; - printk("maxilife: HP KAYAK XA (Pentium II Slot 1, monoprocessor)\n"); - } else { + if (maxi_version == cristal) { + type = cristal; + type_name = "maxilife-cg"; + client_name = "HP MaxiLife Rev CG 00.04"; + printk + ("maxilife: HP KAYAK XU/XAs (Dual Pentium II Slot 1)\n"); + } else if (maxi_version == cognac) { + type = cognac; + type_name = "maxilife-co"; + client_name = "HP MaxiLife Rev CO 00.03"; + printk + ("maxilife: HP KAYAK XU (Dual Xeon Slot 2 400/450 Mhz)\n"); + } else if (maxi_version == ashaki) { + type = ashaki; + type_name = "maxilife-as"; + client_name = "HP MaxiLife Rev AS 00.01"; + printk + ("maxilife: HP KAYAK XA (Pentium II Slot 1, monoprocessor)\n"); + } else { #if AUTODETECT - printk("maxilife: Warning: probed non-maxilife chip?!? (%x)\n", err); + printk + ("maxilife: Warning: probed non-maxilife chip?!? (%x)\n", + err); #else - printk("maxilife: Error: specified wrong maxi_version (%d)\n", - maxi_version); + printk + ("maxilife: Error: specified wrong maxi_version (%d)\n", + maxi_version); #endif - goto ERROR2; - } + goto ERROR2; + } - strcpy(new_client->name, client_name); - ((struct maxi_data *) (new_client->data))->type = type; - if ((err = maxi_new_client(adapter, new_client))) - goto ERROR2; + strcpy(new_client->name, client_name); + ((struct maxi_data *) (new_client->data))->type = type; + if ((err = maxi_new_client(adapter, new_client))) + goto ERROR2; - /* Tell i2c-core a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + /* Tell i2c-core a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; - /* Register a new directory entry with module sensors */ - if ((err = sensors_register_entry(new_client, type_name, - maxi_dir_table_template, - THIS_MODULE)) < 0) - goto ERROR4; - ((struct maxi_data *) (new_client->data))->sysctl_id = err; - err = 0; + /* Register a new directory entry with module sensors */ + if ((err = sensors_register_entry(new_client, type_name, + maxi_dir_table_template, + THIS_MODULE)) < 0) + goto ERROR4; + ((struct maxi_data *) (new_client->data))->sysctl_id = err; + err = 0; - /* Initialize the MaxiLife chip */ - maxi_init_client(new_client); - continue; + /* Initialize the MaxiLife chip */ + maxi_init_client(new_client); + continue; - /* OK, this is not exactly good programming practice, usually. - But it is very code-efficient in this case. */ -ERROR4: - i2c_detach_client(new_client); -ERROR3: - maxi_remove_client(new_client); -ERROR2: - kfree(new_client); - } -ERROR0: - return err; + /* OK, this is not exactly good programming practice, usually. + But it is very code-efficient in this case. */ + ERROR4: + i2c_detach_client(new_client); + ERROR3: + maxi_remove_client(new_client); + ERROR2: + kfree(new_client); + } + ERROR0: + return err; } int maxi_detach_smbus(struct i2c_client *client) { - int err; + int err; - sensors_deregister_entry(((struct maxi_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct maxi_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("maxilife: Client deregistration failed, client not detached.\n"); - return err; - } - maxi_remove_client(client); - kfree(client); - return 0; + if ((err = i2c_detach_client(client))) { + printk + ("maxilife: Client deregistration failed, client not detached.\n"); + return err; + } + maxi_remove_client(client); + kfree(client); + return 0; } /* Find a free slot, and initialize most of the fields */ int maxi_new_client(struct i2c_adapter *adapter, - struct i2c_client *new_client) + struct i2c_client *new_client) { - struct maxi_data *data; + struct maxi_data *data; - new_client->id = maxi_id++; - new_client->adapter = adapter; - new_client->driver = &maxi_driver; - data = new_client->data; - data->valid = 0; - init_MUTEX(&data->lock); - init_MUTEX(&data->update_lock); - return 0; + new_client->id = maxi_id++; + new_client->adapter = adapter; + new_client->driver = &maxi_driver; + data = new_client->data; + data->valid = 0; + init_MUTEX(&data->lock); + init_MUTEX(&data->update_lock); + return 0; } /* Inverse of maxi_new_client */ @@ -431,22 +445,22 @@ void maxi_remove_client(struct i2c_client *client) /* No commands defined yet */ int maxi_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } /* Nothing here yet */ -void maxi_inc_use (struct i2c_client *client) +void maxi_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } /* Nothing here yet */ -void maxi_dec_use (struct i2c_client *client) +void maxi_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } @@ -454,134 +468,144 @@ void maxi_dec_use (struct i2c_client *client) /* Read byte from specified register. */ int maxi_read_value(struct i2c_client *client, u8 reg) { - return i2c_smbus_read_byte_data(client, reg); + return i2c_smbus_read_byte_data(client, reg); } #ifndef NOWRITE -/* Write byte to specified register. */ +/* Write byte to specified register. */ int maxi_write_value(struct i2c_client *client, u8 reg, u8 value) { - return i2c_smbus_write_byte_data(client, reg, value); + return i2c_smbus_write_byte_data(client, reg, value); } #endif /* Called when we have found a new MaxiLife. It should set limits, etc. */ void maxi_init_client(struct i2c_client *client) { - /* start with default settings */ + /* start with default settings */ } void maxi_update_client(struct i2c_client *client) { - struct maxi_data *data = client->data; - int i; + struct maxi_data *data = client->data; + int i; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > HZ+HZ/2 ) || - (jiffies < data->last_updated) || !data->valid) { + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("maxilife: Starting MaxiLife update\n"); + printk("maxilife: Starting MaxiLife update\n"); #endif - for (i = 0; i < 5; i++) - data->temp[i] = maxi_read_value(client, MAXI_REG_TEMP(i)); - switch (data->type) { - case cristal: - data->temp[0] = 0; /* not valid */ - data->temp_max[0] = 0; - data->temp_hyst[0] = 0; - data->temp_max[1] = 110; /* max PCI slot temp */ - data->temp_hyst[1] = 100; - data->temp_max[2] = 120; /* max BX chipset temp */ - data->temp_hyst[2] = 110; - data->temp_max[3] = 100; /* max HDD temp */ - data->temp_hyst[3] = 90; - data->temp_max[4] = 120; /* max CPU temp */ - data->temp_hyst[4] = 110; - break; - - case cognac: - data->temp_max[0] = 120; /* max CPU1 temp */ - data->temp_hyst[0] = 110; - data->temp_max[1] = 110; /* max PCI slot temp */ - data->temp_hyst[1] = 100; - data->temp_max[2] = 120; /* max CPU2 temp */ - data->temp_hyst[2] = 110; - data->temp_max[3] = 100; /* max HDD temp */ - data->temp_hyst[3] = 90; - data->temp_max[4] = 120; /* max reference CPU temp */ - data->temp_hyst[4] = 110; - break; - - case ashaki: - data->temp[0] = 0; /* not valid */ - data->temp_max[0] = 0; - data->temp_hyst[0] = 0; - data->temp_max[1] = 110; /* max PCI slot temp */ - data->temp_hyst[1] = 100; - data->temp[2] = 0; /* not valid */ - data->temp_max[2] = 0; - data->temp_hyst[2] = 0; - data->temp_max[3] = 100; /* max HDD temp */ - data->temp_hyst[3] = 90; - data->temp_max[4] = 120; /* max CPU temp */ - data->temp_hyst[4] = 110; - break; - - default: - printk("maxilife: Unknown MaxiLife chip\n"); - } + for (i = 0; i < 5; i++) + data->temp[i] = + maxi_read_value(client, MAXI_REG_TEMP(i)); + switch (data->type) { + case cristal: + data->temp[0] = 0; /* not valid */ + data->temp_max[0] = 0; + data->temp_hyst[0] = 0; + data->temp_max[1] = 110; /* max PCI slot temp */ + data->temp_hyst[1] = 100; + data->temp_max[2] = 120; /* max BX chipset temp */ + data->temp_hyst[2] = 110; + data->temp_max[3] = 100; /* max HDD temp */ + data->temp_hyst[3] = 90; + data->temp_max[4] = 120; /* max CPU temp */ + data->temp_hyst[4] = 110; + break; - for (i = 0; i < 3; i++) { - data->fan[i] = maxi_read_value(client, MAXI_REG_FAN(i)); - data->fan_speed[i] = maxi_read_value(client, MAXI_REG_FAN_SPEED(i)); - data->fan_div[i] = 4; - if (data->type == ashaki) - data->fan_min[i] = maxi_read_value(client, MAXI_REG_FAN_MINAS(i)); - else - data->fan_min[i] = maxi_read_value(client, MAXI_REG_FAN_MIN(i)); - } - - data->pll = maxi_read_value(client, MAXI_REG_PLL); - data->pll_min = maxi_read_value(client, MAXI_REG_PLL_MIN); - data->pll_max = maxi_read_value(client, MAXI_REG_PLL_MAX); + case cognac: + data->temp_max[0] = 120; /* max CPU1 temp */ + data->temp_hyst[0] = 110; + data->temp_max[1] = 110; /* max PCI slot temp */ + data->temp_hyst[1] = 100; + data->temp_max[2] = 120; /* max CPU2 temp */ + data->temp_hyst[2] = 110; + data->temp_max[3] = 100; /* max HDD temp */ + data->temp_hyst[3] = 90; + data->temp_max[4] = 120; /* max reference CPU temp */ + data->temp_hyst[4] = 110; + break; - for (i = 0; i < 4; i++) { - data->vid[i] = maxi_read_value(client, MAXI_REG_VID(i)); - data->vid_min[i] = maxi_read_value(client, MAXI_REG_VID_MIN(i)); - data->vid_max[i] = maxi_read_value(client, MAXI_REG_VID_MAX(i)); - } - switch (data->type) { - case cristal: - data->vid[3] = 0; /* no voltage cache L2 */ - data->vid_min[3] = 0; - data->vid_max[3] = 0; - break; + case ashaki: + data->temp[0] = 0; /* not valid */ + data->temp_max[0] = 0; + data->temp_hyst[0] = 0; + data->temp_max[1] = 110; /* max PCI slot temp */ + data->temp_hyst[1] = 100; + data->temp[2] = 0; /* not valid */ + data->temp_max[2] = 0; + data->temp_hyst[2] = 0; + data->temp_max[3] = 100; /* max HDD temp */ + data->temp_hyst[3] = 90; + data->temp_max[4] = 120; /* max CPU temp */ + data->temp_hyst[4] = 110; + break; - case cognac: - break; + default: + printk("maxilife: Unknown MaxiLife chip\n"); + } - case ashaki: - data->vid[1] = 0; /* no voltage CPU 2 */ - data->vid_min[1] = 0; - data->vid_max[1] = 0; - data->vid[3] = 0; /* no voltage cache L2 */ - data->vid_min[3] = 0; - data->vid_max[3] = 0; - break; + for (i = 0; i < 3; i++) { + data->fan[i] = + maxi_read_value(client, MAXI_REG_FAN(i)); + data->fan_speed[i] = + maxi_read_value(client, MAXI_REG_FAN_SPEED(i)); + data->fan_div[i] = 4; + if (data->type == ashaki) + data->fan_min[i] = + maxi_read_value(client, + MAXI_REG_FAN_MINAS(i)); + else + data->fan_min[i] = + maxi_read_value(client, + MAXI_REG_FAN_MIN(i)); + } - default: - printk("maxilife: Unknown MaxiLife chip\n"); - } + data->pll = maxi_read_value(client, MAXI_REG_PLL); + data->pll_min = maxi_read_value(client, MAXI_REG_PLL_MIN); + data->pll_max = maxi_read_value(client, MAXI_REG_PLL_MAX); - data->alarms = maxi_read_value(client, MAXI_REG_DIAG_RT1) + - (maxi_read_value(client, MAXI_REG_DIAG_RT2) << 8); - data->last_updated = jiffies; - data->valid = 1; - } + for (i = 0; i < 4; i++) { + data->vid[i] = + maxi_read_value(client, MAXI_REG_VID(i)); + data->vid_min[i] = + maxi_read_value(client, MAXI_REG_VID_MIN(i)); + data->vid_max[i] = + maxi_read_value(client, MAXI_REG_VID_MAX(i)); + } + switch (data->type) { + case cristal: + data->vid[3] = 0; /* no voltage cache L2 */ + data->vid_min[3] = 0; + data->vid_max[3] = 0; + break; - up(&data->update_lock); + case cognac: + break; + + case ashaki: + data->vid[1] = 0; /* no voltage CPU 2 */ + data->vid_min[1] = 0; + data->vid_max[1] = 0; + data->vid[3] = 0; /* no voltage cache L2 */ + data->vid_min[3] = 0; + data->vid_max[3] = 0; + break; + + default: + printk("maxilife: Unknown MaxiLife chip\n"); + } + + data->alarms = maxi_read_value(client, MAXI_REG_DIAG_RT1) + + (maxi_read_value(client, MAXI_REG_DIAG_RT2) << 8); + data->last_updated = jiffies; + data->valid = 1; + } + + up(&data->update_lock); } /* The next few functions are the call-back functions of the /proc/sys and @@ -598,146 +622,153 @@ void maxi_update_client(struct i2c_client *client) good practice, but as long as you put less than about 5 values in results, you can assume it is large enough. */ void maxi_fan(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct maxi_data *data = client->data; - int nr = ctl_name - MAXI_SYSCTL_FAN1 + 1; + struct maxi_data *data = client->data; + int nr = ctl_name - MAXI_SYSCTL_FAN1 + 1; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - maxi_update_client(client); - results[0] = FAN_FROM_REG(data->fan_min[nr-1]); - results[1] = data->fan_div[nr-1]; - results[2] = FAN_FROM_REG(data->fan[nr-1]); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + maxi_update_client(client); + results[0] = FAN_FROM_REG(data->fan_min[nr - 1]); + results[1] = data->fan_div[nr - 1]; + results[2] = FAN_FROM_REG(data->fan[nr - 1]); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { #ifndef NOWRITE - if (*nrels_mag >= 1) { - data->fan_min[nr-1] = FAN_TO_REG(results[0]); - maxi_write_value(client, MAXI_REG_FAN_MIN(nr), data->fan_min[nr-1]); - } + if (*nrels_mag >= 1) { + data->fan_min[nr - 1] = FAN_TO_REG(results[0]); + maxi_write_value(client, MAXI_REG_FAN_MIN(nr), + data->fan_min[nr - 1]); + } #endif - } + } } void maxi_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct maxi_data *data = client->data; - int nr = ctl_name - MAXI_SYSCTL_TEMP1 + 1; + struct maxi_data *data = client->data; + int nr = ctl_name - MAXI_SYSCTL_TEMP1 + 1; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 1; - else if (operation == SENSORS_PROC_REAL_READ) { - maxi_update_client(client); - results[0] = TEMP_FROM_REG(data->temp_max[nr-1]); - results[1] = TEMP_FROM_REG(data->temp_hyst[nr-1]); - results[2] = TEMP_FROM_REG(data->temp[nr-1]); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - /* temperature range can not be changed */ - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 1; + else if (operation == SENSORS_PROC_REAL_READ) { + maxi_update_client(client); + results[0] = TEMP_FROM_REG(data->temp_max[nr - 1]); + results[1] = TEMP_FROM_REG(data->temp_hyst[nr - 1]); + results[2] = TEMP_FROM_REG(data->temp[nr - 1]); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + /* temperature range can not be changed */ + } } void maxi_pll(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct maxi_data *data = client->data; - - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 2; - else if (operation == SENSORS_PROC_REAL_READ) { - maxi_update_client(client); - results[0] = PLL_FROM_REG(data->pll_min); - results[1] = PLL_FROM_REG(data->pll_max); - results[2] = PLL_FROM_REG(data->pll); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { + struct maxi_data *data = client->data; + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + maxi_update_client(client); + results[0] = PLL_FROM_REG(data->pll_min); + results[1] = PLL_FROM_REG(data->pll_max); + results[2] = PLL_FROM_REG(data->pll); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { #ifndef NOWRITE - if (*nrels_mag >= 1) { - data->pll_min = PLL_TO_REG(results[0]); - maxi_write_value(client, MAXI_REG_PLL_MIN, data->pll_min); - } - if (*nrels_mag >= 2) { - data->pll_max = PLL_TO_REG(results[1]); - maxi_write_value(client, MAXI_REG_PLL_MAX, data->pll_max); - } + if (*nrels_mag >= 1) { + data->pll_min = PLL_TO_REG(results[0]); + maxi_write_value(client, MAXI_REG_PLL_MIN, + data->pll_min); + } + if (*nrels_mag >= 2) { + data->pll_max = PLL_TO_REG(results[1]); + maxi_write_value(client, MAXI_REG_PLL_MAX, + data->pll_max); + } #endif - } + } } void maxi_vid(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct maxi_data *data = client->data; - int nr = ctl_name - MAXI_SYSCTL_VID1 + 1; + struct maxi_data *data = client->data; + int nr = ctl_name - MAXI_SYSCTL_VID1 + 1; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 4; - else if (operation == SENSORS_PROC_REAL_READ) { - maxi_update_client(client); - results[0] = VID_FROM_REG(data->vid_min[nr-1]); - results[1] = VID_FROM_REG(data->vid_max[nr-1]); - results[2] = VID_FROM_REG(data->vid[nr-1]); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 4; + else if (operation == SENSORS_PROC_REAL_READ) { + maxi_update_client(client); + results[0] = VID_FROM_REG(data->vid_min[nr - 1]); + results[1] = VID_FROM_REG(data->vid_max[nr - 1]); + results[2] = VID_FROM_REG(data->vid[nr - 1]); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { #ifndef NOWRITE - if (*nrels_mag >= 1) { - data->vid_min[nr-1] = VID_TO_REG(results[0]); - maxi_write_value(client, MAXI_REG_VID_MIN(nr), data->vid_min[nr-1]); - } - if (*nrels_mag >= 2) { - data->vid_max[nr-1] = VID_TO_REG(results[1]); - maxi_write_value(client, MAXI_REG_VID_MAX(nr), data->vid_max[nr-1]); - } + if (*nrels_mag >= 1) { + data->vid_min[nr - 1] = VID_TO_REG(results[0]); + maxi_write_value(client, MAXI_REG_VID_MIN(nr), + data->vid_min[nr - 1]); + } + if (*nrels_mag >= 2) { + data->vid_max[nr - 1] = VID_TO_REG(results[1]); + maxi_write_value(client, MAXI_REG_VID_MAX(nr), + data->vid_max[nr - 1]); + } #endif - } + } } void maxi_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct maxi_data *data = client->data; - - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - maxi_update_client(client); - results[0] = ALARMS_FROM_REG(data->alarms); - *nrels_mag = 1; - } + struct maxi_data *data = client->data; + + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + maxi_update_client(client); + results[0] = ALARMS_FROM_REG(data->alarms); + *nrels_mag = 1; + } } int __init sensors_maxi_init(void) { - int res; + int res; - printk("maxilife: Version %s (lm_sensors %s (%s))\n", version_str, - LM_VERSION, LM_DATE); - maxi_initialized = 0; + printk("maxilife: Version %s (lm_sensors %s (%s))\n", version_str, + LM_VERSION, LM_DATE); + maxi_initialized = 0; - if ((res = i2c_add_driver(&maxi_driver))) { - printk("maxilife: Driver registration failed, module not inserted.\n"); - maxi_cleanup(); - return res; - } - maxi_initialized++; - return 0; + if ((res = i2c_add_driver(&maxi_driver))) { + printk + ("maxilife: Driver registration failed, module not inserted.\n"); + maxi_cleanup(); + return res; + } + maxi_initialized++; + return 0; } int __init maxi_cleanup(void) { - int res; + int res; - if (maxi_initialized >= 1) { - if ((res = i2c_del_driver(&maxi_driver))) { - printk("maxilife: Driver deregistration failed, module not removed.\n"); - return res; - } - maxi_initialized--; - } - return 0; + if (maxi_initialized >= 1) { + if ((res = i2c_del_driver(&maxi_driver))) { + printk + ("maxilife: Driver deregistration failed, module not removed.\n"); + return res; + } + maxi_initialized--; + } + return 0; } EXPORT_NO_SYMBOLS; @@ -751,14 +782,12 @@ MODULE_PARM_DESC(maxi_version, "MaxiLife firmware version"); int init_module(void) { - return sensors_maxi_init(); + return sensors_maxi_init(); } int cleanup_module(void) { - return maxi_cleanup(); + return maxi_cleanup(); } -#endif /* MODULE */ - - +#endif /* MODULE */ diff --git a/kernel/chips/sis5595.c b/kernel/chips/sis5595.c index fb6a5af1..727c6bca 100644 --- a/kernel/chips/sis5595.c +++ b/kernel/chips/sis5595.c @@ -48,10 +48,10 @@ /* Addresses to scan. Note that we can't determine the ISA address until we have initialized our module */ -static unsigned short normal_i2c[] = {SENSORS_I2C_END}; -static unsigned short normal_i2c_range[] = {SENSORS_I2C_END}; -static unsigned int normal_isa[] = {0x0000,SENSORS_ISA_END}; -static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; +static unsigned short normal_i2c[] = { SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { SENSORS_I2C_END }; +static unsigned int normal_isa[] = { 0x0000, SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; /* Insmod parameters */ SENSORS_INSMOD_1(sis5595); @@ -99,10 +99,11 @@ SENSORS_INSMOD_1(sis5595); extern inline u8 FAN_TO_REG(long rpm, int div) { - if (rpm == 0) - return 255; - rpm = SENSORS_LIMIT(rpm,1,1000000); - return SENSORS_LIMIT((1350000 + rpm*div/2) / (rpm*div),1,254); + if (rpm == 0) + return 255; + rpm = SENSORS_LIMIT(rpm, 1, 1000000); + return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, + 254); } #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) @@ -126,21 +127,21 @@ extern inline u8 FAN_TO_REG(long rpm, int div) #define SIS5595_INIT_IN_PERCENTAGE 10 #define SIS5595_INIT_IN_MIN_0 \ - (SIS5595_INIT_IN_0 - SIS5595_INIT_IN_0 * SIS5595_INIT_IN_PERCENTAGE / 100) + (SIS5595_INIT_IN_0 - SIS5595_INIT_IN_0 * SIS5595_INIT_IN_PERCENTAGE / 100) #define SIS5595_INIT_IN_MAX_0 \ - (SIS5595_INIT_IN_0 + SIS5595_INIT_IN_0 * SIS5595_INIT_IN_PERCENTAGE / 100) + (SIS5595_INIT_IN_0 + SIS5595_INIT_IN_0 * SIS5595_INIT_IN_PERCENTAGE / 100) #define SIS5595_INIT_IN_MIN_1 \ - (SIS5595_INIT_IN_1 - SIS5595_INIT_IN_1 * SIS5595_INIT_IN_PERCENTAGE / 100) + (SIS5595_INIT_IN_1 - SIS5595_INIT_IN_1 * SIS5595_INIT_IN_PERCENTAGE / 100) #define SIS5595_INIT_IN_MAX_1 \ - (SIS5595_INIT_IN_1 + SIS5595_INIT_IN_1 * SIS5595_INIT_IN_PERCENTAGE / 100) + (SIS5595_INIT_IN_1 + SIS5595_INIT_IN_1 * SIS5595_INIT_IN_PERCENTAGE / 100) #define SIS5595_INIT_IN_MIN_2 \ - (SIS5595_INIT_IN_2 - SIS5595_INIT_IN_2 * SIS5595_INIT_IN_PERCENTAGE / 100) + (SIS5595_INIT_IN_2 - SIS5595_INIT_IN_2 * SIS5595_INIT_IN_PERCENTAGE / 100) #define SIS5595_INIT_IN_MAX_2 \ - (SIS5595_INIT_IN_2 + SIS5595_INIT_IN_2 * SIS5595_INIT_IN_PERCENTAGE / 100) + (SIS5595_INIT_IN_2 + SIS5595_INIT_IN_2 * SIS5595_INIT_IN_PERCENTAGE / 100) #define SIS5595_INIT_IN_MIN_3 \ - (SIS5595_INIT_IN_3 - SIS5595_INIT_IN_3 * SIS5595_INIT_IN_PERCENTAGE / 100) + (SIS5595_INIT_IN_3 - SIS5595_INIT_IN_3 * SIS5595_INIT_IN_PERCENTAGE / 100) #define SIS5595_INIT_IN_MAX_3 \ - (SIS5595_INIT_IN_3 + SIS5595_INIT_IN_3 * SIS5595_INIT_IN_PERCENTAGE / 100) + (SIS5595_INIT_IN_3 + SIS5595_INIT_IN_3 * SIS5595_INIT_IN_PERCENTAGE / 100) #define SIS5595_INIT_FAN_MIN_1 3000 #define SIS5595_INIT_FAN_MIN_2 3000 @@ -151,7 +152,7 @@ extern inline u8 FAN_TO_REG(long rpm, int div) #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ /* This module may seem overly long and complicated. In fact, it is not so bad. Quite a lot of bookkeeping is done. A real driver can often cut @@ -162,23 +163,23 @@ extern int cleanup_module(void); dynamically allocated, at the same time when a new sis5595 client is allocated. */ struct sis5595_data { - struct semaphore lock; - int sysctl_id; + struct semaphore lock; + int sysctl_id; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ - u8 in[4]; /* Register value */ - u8 in_max[4]; /* Register value */ - u8 in_min[4]; /* Register value */ - u8 fan[2]; /* Register value */ - u8 fan_min[2]; /* Register value */ - u8 temp; /* Register value */ - u8 temp_over; /* Register value */ - u8 temp_hyst; /* Register value */ - u8 fan_div[2]; /* Register encoding, shifted right */ - u8 alarms; /* Register encoding, combined */ + u8 in[4]; /* Register value */ + u8 in_max[4]; /* Register value */ + u8 in_min[4]; /* Register value */ + u8 fan[2]; /* Register value */ + u8 fan_min[2]; /* Register value */ + u8 temp; /* Register value */ + u8 temp_over; /* Register value */ + u8 temp_hyst; /* Register value */ + u8 fan_div[2]; /* Register encoding, shifted right */ + u8 alarms; /* Register encoding, combined */ }; @@ -187,49 +188,50 @@ static #else extern #endif - int __init sensors_sis5595_init(void); +int __init sensors_sis5595_init(void); static int __init sis5595_cleanup(void); static int sis5595_attach_adapter(struct i2c_adapter *adapter); -static int sis5595_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind); +static int sis5595_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); static int sis5595_detach_client(struct i2c_client *client); -static int sis5595_command(struct i2c_client *client, unsigned int cmd, - void *arg); -static void sis5595_inc_use (struct i2c_client *client); -static void sis5595_dec_use (struct i2c_client *client); +static int sis5595_command(struct i2c_client *client, unsigned int cmd, + void *arg); +static void sis5595_inc_use(struct i2c_client *client); +static void sis5595_dec_use(struct i2c_client *client); static int sis5595_read_value(struct i2c_client *client, u8 register); -static int sis5595_write_value(struct i2c_client *client, u8 register, u8 value); +static int sis5595_write_value(struct i2c_client *client, u8 register, + u8 value); static void sis5595_update_client(struct i2c_client *client); static void sis5595_init_client(struct i2c_client *client); static int sis5595_find_sis(int *address); -static void sis5595_in(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void sis5595_fan(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void sis5595_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void sis5595_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void sis5595_fan_div(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); +static void sis5595_in(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void sis5595_fan(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void sis5595_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void sis5595_alarms(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void sis5595_fan_div(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static int sis5595_id = 0; /* The driver. I choose to use type i2c_driver, as at is identical to both smbus_driver and isa_driver, and clients could be of either kind */ static struct i2c_driver sis5595_driver = { - /* name */ "SiS 5595", - /* id */ I2C_DRIVERID_SIS5595, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &sis5595_attach_adapter, - /* detach_client */ &sis5595_detach_client, - /* command */ &sis5595_command, - /* inc_use */ &sis5595_inc_use, - /* dec_use */ &sis5595_dec_use + /* name */ "SiS 5595", + /* id */ I2C_DRIVERID_SIS5595, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &sis5595_attach_adapter, + /* detach_client */ &sis5595_detach_client, + /* command */ &sis5595_command, + /* inc_use */ &sis5595_inc_use, + /* dec_use */ &sis5595_dec_use }; /* Used by sis5595_init/cleanup */ @@ -242,236 +244,242 @@ static int __initdata sis5595_initialized = 0; is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table sis5595_dir_table_template[] = { - { SIS5595_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &sis5595_in }, - { SIS5595_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &sis5595_in }, - { SIS5595_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &sis5595_in }, - { SIS5595_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &sis5595_in }, - { SIS5595_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &sis5595_fan }, - { SIS5595_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &sis5595_fan }, - { SIS5595_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &sis5595_temp }, - { SIS5595_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &sis5595_fan_div }, - { SIS5595_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &sis5595_alarms }, - { 0 } + {SIS5595_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &sis5595_in}, + {SIS5595_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &sis5595_in}, + {SIS5595_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &sis5595_in}, + {SIS5595_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &sis5595_in}, + {SIS5595_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &sis5595_fan}, + {SIS5595_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &sis5595_fan}, + {SIS5595_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &sis5595_temp}, + {SIS5595_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &sis5595_fan_div}, + {SIS5595_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &sis5595_alarms}, + {0} }; /* This is called when the module is loaded */ int sis5595_attach_adapter(struct i2c_adapter *adapter) { - return sensors_detect(adapter,&addr_data,sis5595_detect); + return sensors_detect(adapter, &addr_data, sis5595_detect); } /* Locate SiS bridge and correct base address for SIS5595 */ int sis5595_find_sis(int *address) { - struct pci_dev *s_bridge; - u16 val; + struct pci_dev *s_bridge; + u16 val; - if (! pci_present()) - return -ENODEV; + if (!pci_present()) + return -ENODEV; - if (! (s_bridge = pci_find_device( - PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, NULL))) - - return -ENODEV; + if (! + (s_bridge = + pci_find_device(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, + NULL))) + + return -ENODEV; - if ( PCIBIOS_SUCCESSFUL != - pci_read_config_word(s_bridge, SIS5595_BASE_REG, &val)) - return -ENODEV; - - *address = (val & 0xfff8); - return 0; + if (PCIBIOS_SUCCESSFUL != + pci_read_config_word(s_bridge, SIS5595_BASE_REG, &val)) + return -ENODEV; + + *address = (val & 0xfff8); + return 0; } -int sis5595_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind) +int sis5595_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) { - int i; - struct i2c_client *new_client; - struct sis5595_data *data; - int err=0; - const char *type_name = ""; - const char *client_name = ""; + int i; + struct i2c_client *new_client; + struct sis5595_data *data; + int err = 0; + const char *type_name = ""; + const char *client_name = ""; - /* Make sure we are probing the ISA bus!! */ - if (!i2c_is_isa_adapter(adapter)) { - printk("sis5595.o: sis5595_detect called for an I2C bus adapter?!?\n"); - return 0; - } + /* Make sure we are probing the ISA bus!! */ + if (!i2c_is_isa_adapter(adapter)) { + printk + ("sis5595.o: sis5595_detect called for an I2C bus adapter?!?\n"); + return 0; + } - if (check_region(address,SIS5595_EXTENT)) - goto ERROR0; + if (check_region(address, SIS5595_EXTENT)) + goto ERROR0; - /* If this is the address as indicated by the SIS5595 chipset, we don't - do any futher probing */ - if ((kind < 0) && (address == normal_isa[0])) - kind = 0; + /* If this is the address as indicated by the SIS5595 chipset, we don't + do any futher probing */ + if ((kind < 0) && (address == normal_isa[0])) + kind = 0; - /* Probe whether there is anything available on this address. */ - if (kind < 0) { + /* Probe whether there is anything available on this address. */ + if (kind < 0) { #define REALLY_SLOW_IO - /* We need the timeouts for at least some LM78-like chips. But only - if we read 'undefined' registers. */ - i = inb_p(address + 1); - if (inb_p(address + 2) != i) - goto ERROR0; - if (inb_p(address + 3) != i) - goto ERROR0; - if (inb_p(address + 7) != i) - goto ERROR0; + /* We need the timeouts for at least some LM78-like chips. But only + if we read 'undefined' registers. */ + i = inb_p(address + 1); + if (inb_p(address + 2) != i) + goto ERROR0; + if (inb_p(address + 3) != i) + goto ERROR0; + if (inb_p(address + 7) != i) + goto ERROR0; #undef REALLY_SLOW_IO - /* Let's just hope nothing breaks here */ - i = inb_p(address + 5) & 0x7f; - outb_p(~i & 0x7f,address+5); - if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) { - outb_p(i,address+5); - return 0; - } - } + /* Let's just hope nothing breaks here */ + i = inb_p(address + 5) & 0x7f; + outb_p(~i & 0x7f, address + 5); + if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) { + outb_p(i, address + 5); + return 0; + } + } - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access sis5595_{read,write}_value. */ + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access sis5595_{read,write}_value. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct sis5595_data), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR0; - } + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct sis5595_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } - data = (struct sis5595_data *) (new_client + 1); - new_client->addr = address; - init_MUTEX(&data->lock); - new_client->data = data; - new_client->adapter = adapter; - new_client->driver = &sis5595_driver; - new_client->flags = 0; + data = (struct sis5595_data *) (new_client + 1); + new_client->addr = address; + init_MUTEX(&data->lock); + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &sis5595_driver; + new_client->flags = 0; - /* Now, we do the remaining detection. */ + /* Now, we do the remaining detection. */ - if (kind < 0) { - if (sis5595_read_value(new_client,SIS5595_REG_CONFIG) & 0x80) - goto ERROR1; - } + if (kind < 0) { + if (sis5595_read_value(new_client, SIS5595_REG_CONFIG) & + 0x80) goto ERROR1; + } - /* Determine the chip type. */ - if (kind <= 0) - kind = sis5595; + /* Determine the chip type. */ + if (kind <= 0) + kind = sis5595; - if (kind == sis5595) { - type_name = "sis5595"; - client_name = "SIS5595 chip"; - } else { + if (kind == sis5595) { + type_name = "sis5595"; + client_name = "SIS5595 chip"; + } else { #ifdef DEBUG - printk("sis5595.o: Internal error: unknown kind (%d)?!?",kind); + printk("sis5595.o: Internal error: unknown kind (%d)?!?", + kind); #endif - goto ERROR1; - } + goto ERROR1; + } - /* Reserve the ISA region */ - request_region(address, SIS5595_EXTENT, type_name); + /* Reserve the ISA region */ + request_region(address, SIS5595_EXTENT, type_name); - /* Fill in the remaining client fields and put it into the global list */ - strcpy(new_client->name,client_name); + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); - new_client->id = sis5595_id++; - data->valid = 0; - init_MUTEX(&data->update_lock); + new_client->id = sis5595_id++; + data->valid = 0; + init_MUTEX(&data->update_lock); - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; - /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry((struct i2c_client *) new_client, - type_name, - sis5595_dir_table_template, - THIS_MODULE)) < 0) { - err = i; - goto ERROR4; - } - data->sysctl_id = i; + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry((struct i2c_client *) new_client, + type_name, + sis5595_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; - /* Initialize the SIS5595 chip */ - sis5595_init_client(new_client); - return 0; + /* Initialize the SIS5595 chip */ + sis5595_init_client(new_client); + return 0; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR4: - i2c_detach_client(new_client); -ERROR3: - release_region(address,SIS5595_EXTENT); -ERROR1: - kfree(new_client); -ERROR0: - return err; + ERROR4: + i2c_detach_client(new_client); + ERROR3: + release_region(address, SIS5595_EXTENT); + ERROR1: + kfree(new_client); + ERROR0: + return err; } int sis5595_detach_client(struct i2c_client *client) { - int err; + int err; - sensors_deregister_entry(((struct sis5595_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct sis5595_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("sis5595.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("sis5595.o: Client deregistration failed, client not detached.\n"); + return err; + } - release_region(client->addr,SIS5595_EXTENT); - kfree(client); + release_region(client->addr, SIS5595_EXTENT); + kfree(client); - return 0; + return 0; } /* No commands defined yet */ int sis5595_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } /* Nothing here yet */ -void sis5595_inc_use (struct i2c_client *client) +void sis5595_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } /* Nothing here yet */ -void sis5595_dec_use (struct i2c_client *client) +void sis5595_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } - + /* The SMBus locks itself, but ISA access must be locked explicitely! There are some ugly typecasts here, but the good new is - they should nowhere else be necessary! */ int sis5595_read_value(struct i2c_client *client, u8 reg) { - int res; - - down(& (((struct sis5595_data *) (client->data)) -> lock)); - outb_p(reg,client->addr + SIS5595_ADDR_REG_OFFSET); - res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET); - up( & (((struct sis5595_data *) (client->data)) -> lock)); - return res; + int res; + + down(&(((struct sis5595_data *) (client->data))->lock)); + outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); + res = inb_p(client->addr + SIS5595_DATA_REG_OFFSET); + up(&(((struct sis5595_data *) (client->data))->lock)); + return res; } /* The SMBus locks itself, but ISA access muse be locked explicitely! @@ -479,75 +487,97 @@ int sis5595_read_value(struct i2c_client *client, u8 reg) nowhere else be necessary! */ int sis5595_write_value(struct i2c_client *client, u8 reg, u8 value) { - down(& (((struct sis5595_data *) (client->data)) -> lock)); - outb_p(reg,client->addr + SIS5595_ADDR_REG_OFFSET); - outb_p(value,client->addr + SIS5595_DATA_REG_OFFSET); - up( & (((struct sis5595_data *) (client->data)) -> lock)); - return 0; + down(&(((struct sis5595_data *) (client->data))->lock)); + outb_p(reg, client->addr + SIS5595_ADDR_REG_OFFSET); + outb_p(value, client->addr + SIS5595_DATA_REG_OFFSET); + up(&(((struct sis5595_data *) (client->data))->lock)); + return 0; } /* Called when we have found a new SIS5595. It should set limits, etc. */ void sis5595_init_client(struct i2c_client *client) { - /* Reset all except Watchdog values and last conversion values - This sets fan-divs to 2, among others */ - sis5595_write_value(client,SIS5595_REG_CONFIG,0x80); + /* Reset all except Watchdog values and last conversion values + This sets fan-divs to 2, among others */ + sis5595_write_value(client, SIS5595_REG_CONFIG, 0x80); - sis5595_write_value(client,SIS5595_REG_IN_MIN(0),IN_TO_REG(SIS5595_INIT_IN_MIN_0)); - sis5595_write_value(client,SIS5595_REG_IN_MAX(0),IN_TO_REG(SIS5595_INIT_IN_MAX_0)); - sis5595_write_value(client,SIS5595_REG_IN_MIN(1),IN_TO_REG(SIS5595_INIT_IN_MIN_1)); - sis5595_write_value(client,SIS5595_REG_IN_MAX(1),IN_TO_REG(SIS5595_INIT_IN_MAX_1)); - sis5595_write_value(client,SIS5595_REG_IN_MIN(2),IN_TO_REG(SIS5595_INIT_IN_MIN_2)); - sis5595_write_value(client,SIS5595_REG_IN_MAX(2),IN_TO_REG(SIS5595_INIT_IN_MAX_2)); - sis5595_write_value(client,SIS5595_REG_IN_MIN(3),IN_TO_REG(SIS5595_INIT_IN_MIN_3)); - sis5595_write_value(client,SIS5595_REG_IN_MAX(3),IN_TO_REG(SIS5595_INIT_IN_MAX_3)); - sis5595_write_value(client,SIS5595_REG_FAN_MIN(1), - FAN_TO_REG(SIS5595_INIT_FAN_MIN_1,2)); - sis5595_write_value(client,SIS5595_REG_FAN_MIN(2), - FAN_TO_REG(SIS5595_INIT_FAN_MIN_2,2)); - sis5595_write_value(client,SIS5595_REG_TEMP_OVER,TEMP_TO_REG(SIS5595_INIT_TEMP_OVER)); - sis5595_write_value(client,SIS5595_REG_TEMP_HYST,TEMP_TO_REG(SIS5595_INIT_TEMP_HYST)); + sis5595_write_value(client, SIS5595_REG_IN_MIN(0), + IN_TO_REG(SIS5595_INIT_IN_MIN_0)); + sis5595_write_value(client, SIS5595_REG_IN_MAX(0), + IN_TO_REG(SIS5595_INIT_IN_MAX_0)); + sis5595_write_value(client, SIS5595_REG_IN_MIN(1), + IN_TO_REG(SIS5595_INIT_IN_MIN_1)); + sis5595_write_value(client, SIS5595_REG_IN_MAX(1), + IN_TO_REG(SIS5595_INIT_IN_MAX_1)); + sis5595_write_value(client, SIS5595_REG_IN_MIN(2), + IN_TO_REG(SIS5595_INIT_IN_MIN_2)); + sis5595_write_value(client, SIS5595_REG_IN_MAX(2), + IN_TO_REG(SIS5595_INIT_IN_MAX_2)); + sis5595_write_value(client, SIS5595_REG_IN_MIN(3), + IN_TO_REG(SIS5595_INIT_IN_MIN_3)); + sis5595_write_value(client, SIS5595_REG_IN_MAX(3), + IN_TO_REG(SIS5595_INIT_IN_MAX_3)); + sis5595_write_value(client, SIS5595_REG_FAN_MIN(1), + FAN_TO_REG(SIS5595_INIT_FAN_MIN_1, 2)); + sis5595_write_value(client, SIS5595_REG_FAN_MIN(2), + FAN_TO_REG(SIS5595_INIT_FAN_MIN_2, 2)); + sis5595_write_value(client, SIS5595_REG_TEMP_OVER, + TEMP_TO_REG(SIS5595_INIT_TEMP_OVER)); + sis5595_write_value(client, SIS5595_REG_TEMP_HYST, + TEMP_TO_REG(SIS5595_INIT_TEMP_HYST)); + + /* Start monitoring */ + sis5595_write_value(client, SIS5595_REG_CONFIG, + (sis5595_read_value(client, SIS5595_REG_CONFIG) + & 0xf7) | 0x01); - /* Start monitoring */ - sis5595_write_value(client,SIS5595_REG_CONFIG, - (sis5595_read_value(client,SIS5595_REG_CONFIG) & 0xf7) | 0x01); - } void sis5595_update_client(struct i2c_client *client) { - struct sis5595_data *data = client->data; - int i; + struct sis5595_data *data = client->data; + int i; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > HZ+HZ/2 ) || - (jiffies < data->last_updated) || ! data->valid) { + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("Starting sis5595 update\n"); + printk("Starting sis5595 update\n"); #endif - for (i = 0; i <= 3; i++) { - data->in[i] = sis5595_read_value(client,SIS5595_REG_IN(i)); - data->in_min[i] = sis5595_read_value(client,SIS5595_REG_IN_MIN(i)); - data->in_max[i] = sis5595_read_value(client,SIS5595_REG_IN_MAX(i)); - } - for (i = 1; i <= 2; i++) { - data->fan[i-1] = sis5595_read_value(client,SIS5595_REG_FAN(i)); - data->fan_min[i-1] = sis5595_read_value(client,SIS5595_REG_FAN_MIN(i)); - } - data->temp = sis5595_read_value(client,SIS5595_REG_TEMP); - data->temp_over = sis5595_read_value(client,SIS5595_REG_TEMP_OVER); - data->temp_hyst = sis5595_read_value(client,SIS5595_REG_TEMP_HYST); - i = sis5595_read_value(client,SIS5595_REG_FANDIV); - data->fan_div[0] = (i >> 4) & 0x03; - data->fan_div[1] = i >> 6; - data->alarms = sis5595_read_value(client,SIS5595_REG_ALARM1); - data->last_updated = jiffies; - data->valid = 1; - } + for (i = 0; i <= 3; i++) { + data->in[i] = + sis5595_read_value(client, SIS5595_REG_IN(i)); + data->in_min[i] = + sis5595_read_value(client, + SIS5595_REG_IN_MIN(i)); + data->in_max[i] = + sis5595_read_value(client, + SIS5595_REG_IN_MAX(i)); + } + for (i = 1; i <= 2; i++) { + data->fan[i - 1] = + sis5595_read_value(client, SIS5595_REG_FAN(i)); + data->fan_min[i - 1] = + sis5595_read_value(client, + SIS5595_REG_FAN_MIN(i)); + } + data->temp = sis5595_read_value(client, SIS5595_REG_TEMP); + data->temp_over = + sis5595_read_value(client, SIS5595_REG_TEMP_OVER); + data->temp_hyst = + sis5595_read_value(client, SIS5595_REG_TEMP_HYST); + i = sis5595_read_value(client, SIS5595_REG_FANDIV); + data->fan_div[0] = (i >> 4) & 0x03; + data->fan_div[1] = i >> 6; + data->alarms = + sis5595_read_value(client, SIS5595_REG_ALARM1); + data->last_updated = jiffies; + data->valid = 1; + } - up(&data->update_lock); + up(&data->update_lock); } @@ -564,155 +594,170 @@ void sis5595_update_client(struct i2c_client *client) large enough (by checking the incoming value of *nrels). This is not very good practice, but as long as you put less than about 5 values in results, you can assume it is large enough. */ -void sis5595_in(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void sis5595_in(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - struct sis5595_data *data = client->data; - int nr = ctl_name - SIS5595_SYSCTL_IN0; + struct sis5595_data *data = client->data; + int nr = ctl_name - SIS5595_SYSCTL_IN0; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 2; - else if (operation == SENSORS_PROC_REAL_READ) { - sis5595_update_client(client); - results[0] = IN_FROM_REG(data->in_min[nr]); - results[1] = IN_FROM_REG(data->in_max[nr]); - results[2] = IN_FROM_REG(data->in[nr]); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->in_min[nr] = IN_TO_REG(results[0]); - sis5595_write_value(client,SIS5595_REG_IN_MIN(nr),data->in_min[nr]); - } - if (*nrels_mag >= 2) { - data->in_max[nr] = IN_TO_REG(results[1]); - sis5595_write_value(client,SIS5595_REG_IN_MAX(nr),data->in_max[nr]); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + sis5595_update_client(client); + results[0] = IN_FROM_REG(data->in_min[nr]); + results[1] = IN_FROM_REG(data->in_max[nr]); + results[2] = IN_FROM_REG(data->in[nr]); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->in_min[nr] = IN_TO_REG(results[0]); + sis5595_write_value(client, SIS5595_REG_IN_MIN(nr), + data->in_min[nr]); + } + if (*nrels_mag >= 2) { + data->in_max[nr] = IN_TO_REG(results[1]); + sis5595_write_value(client, SIS5595_REG_IN_MAX(nr), + data->in_max[nr]); + } + } } void sis5595_fan(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct sis5595_data *data = client->data; - int nr = ctl_name - SIS5595_SYSCTL_FAN1 + 1; + struct sis5595_data *data = client->data; + int nr = ctl_name - SIS5595_SYSCTL_FAN1 + 1; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - sis5595_update_client(client); - results[0] = FAN_FROM_REG(data->fan_min[nr-1], - DIV_FROM_REG(data->fan_div[nr-1])); - results[1] = FAN_FROM_REG(data->fan[nr-1], - DIV_FROM_REG(data->fan_div[nr-1])); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->fan_min[nr-1] = FAN_TO_REG(results[0], - DIV_FROM_REG(data->fan_div[nr-1])); - sis5595_write_value(client,SIS5595_REG_FAN_MIN(nr),data->fan_min[nr-1]); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + sis5595_update_client(client); + results[0] = FAN_FROM_REG(data->fan_min[nr - 1], + DIV_FROM_REG(data-> + fan_div[nr - 1])); + results[1] = + FAN_FROM_REG(data->fan[nr - 1], + DIV_FROM_REG(data->fan_div[nr - 1])); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->fan_min[nr - 1] = FAN_TO_REG(results[0], + DIV_FROM_REG + (data-> + fan_div[nr - + 1])); + sis5595_write_value(client, + SIS5595_REG_FAN_MIN(nr), + data->fan_min[nr - 1]); + } + } } void sis5595_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct sis5595_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 1; - else if (operation == SENSORS_PROC_REAL_READ) { - sis5595_update_client(client); - results[0] = TEMP_FROM_REG(data->temp_over); - results[1] = TEMP_FROM_REG(data->temp_hyst); - results[2] = TEMP_FROM_REG(data->temp); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->temp_over = TEMP_TO_REG(results[0]); - sis5595_write_value(client,SIS5595_REG_TEMP_OVER,data->temp_over); - } - if (*nrels_mag >= 2) { - data->temp_hyst = TEMP_TO_REG(results[1]); - sis5595_write_value(client,SIS5595_REG_TEMP_HYST,data->temp_hyst); - } - } + struct sis5595_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 1; + else if (operation == SENSORS_PROC_REAL_READ) { + sis5595_update_client(client); + results[0] = TEMP_FROM_REG(data->temp_over); + results[1] = TEMP_FROM_REG(data->temp_hyst); + results[2] = TEMP_FROM_REG(data->temp); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->temp_over = TEMP_TO_REG(results[0]); + sis5595_write_value(client, SIS5595_REG_TEMP_OVER, + data->temp_over); + } + if (*nrels_mag >= 2) { + data->temp_hyst = TEMP_TO_REG(results[1]); + sis5595_write_value(client, SIS5595_REG_TEMP_HYST, + data->temp_hyst); + } + } } void sis5595_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct sis5595_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - sis5595_update_client(client); - results[0] = ALARMS_FROM_REG(data->alarms); - *nrels_mag = 1; - } + struct sis5595_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + sis5595_update_client(client); + results[0] = ALARMS_FROM_REG(data->alarms); + *nrels_mag = 1; + } } -void sis5595_fan_div(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void sis5595_fan_div(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - struct sis5595_data *data = client->data; - int old; + struct sis5595_data *data = client->data; + int old; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - sis5595_update_client(client); - results[0] = DIV_FROM_REG(data->fan_div[0]); - results[1] = DIV_FROM_REG(data->fan_div[1]); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - old = sis5595_read_value(client,SIS5595_REG_FANDIV); - if (*nrels_mag >= 2) { - data->fan_div[1] = DIV_TO_REG(results[1]); - old = (old & 0x3f) | (data->fan_div[1] << 6); - } - if (*nrels_mag >= 1) { - data->fan_div[0] = DIV_TO_REG(results[0]); - old = (old & 0xcf) | (data->fan_div[0] << 4); - sis5595_write_value(client,SIS5595_REG_FANDIV,old); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + sis5595_update_client(client); + results[0] = DIV_FROM_REG(data->fan_div[0]); + results[1] = DIV_FROM_REG(data->fan_div[1]); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + old = sis5595_read_value(client, SIS5595_REG_FANDIV); + if (*nrels_mag >= 2) { + data->fan_div[1] = DIV_TO_REG(results[1]); + old = (old & 0x3f) | (data->fan_div[1] << 6); + } + if (*nrels_mag >= 1) { + data->fan_div[0] = DIV_TO_REG(results[0]); + old = (old & 0xcf) | (data->fan_div[0] << 4); + sis5595_write_value(client, SIS5595_REG_FANDIV, + old); + } + } } int __init sensors_sis5595_init(void) { - int res,addr; + int res, addr; - printk("sis5595.o version %s (%s)\n",LM_VERSION,LM_DATE); - sis5595_initialized = 0; + printk("sis5595.o version %s (%s)\n", LM_VERSION, LM_DATE); + sis5595_initialized = 0; - if (sis5595_find_sis(&addr)) { - normal_isa[0] = SENSORS_ISA_END; - printk("sis5595.o: Warning: No SIS5595 southbridge found!\n"); - } else - normal_isa[0] = addr; + if (sis5595_find_sis(&addr)) { + normal_isa[0] = SENSORS_ISA_END; + printk + ("sis5595.o: Warning: No SIS5595 southbridge found!\n"); + } else + normal_isa[0] = addr; - if ((res =i2c_add_driver(&sis5595_driver))) { - printk("sis5595.o: Driver registration failed, module not inserted.\n"); - sis5595_cleanup(); - return res; - } - sis5595_initialized ++; - return 0; + if ((res = i2c_add_driver(&sis5595_driver))) { + printk + ("sis5595.o: Driver registration failed, module not inserted.\n"); + sis5595_cleanup(); + return res; + } + sis5595_initialized++; + return 0; } int __init sis5595_cleanup(void) { - int res; + int res; - if (sis5595_initialized >= 1) { - if ((res = i2c_del_driver(&sis5595_driver))) { - printk("sis5595.o: Driver deregistration failed, module not removed.\n"); - return res; - } - sis5595_initialized --; - } - return 0; + if (sis5595_initialized >= 1) { + if ((res = i2c_del_driver(&sis5595_driver))) { + printk + ("sis5595.o: Driver deregistration failed, module not removed.\n"); + return res; + } + sis5595_initialized--; + } + return 0; } EXPORT_NO_SYMBOLS; @@ -724,13 +769,12 @@ MODULE_DESCRIPTION("SiS 5595 Sensor device"); int init_module(void) { - return sensors_sis5595_init(); + return sensors_sis5595_init(); } int cleanup_module(void) { - return sis5595_cleanup(); + return sis5595_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/thmc50.c b/kernel/chips/thmc50.c index 1326e38a..31838668 100644 --- a/kernel/chips/thmc50.c +++ b/kernel/chips/thmc50.c @@ -39,10 +39,10 @@ #endif /* Addresses to scan */ -static unsigned short normal_i2c[] = {SENSORS_I2C_END}; -static unsigned short normal_i2c_range[] = {0x2D,0x2F,SENSORS_I2C_END}; -static unsigned int normal_isa[] = {SENSORS_ISA_END}; -static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; +static unsigned short normal_i2c[] = { SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { 0x2D, 0x2F, SENSORS_I2C_END }; +static unsigned int normal_isa[] = { SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; /* Insmod parameters */ SENSORS_INSMOD_1(thmc50); @@ -85,66 +85,68 @@ SENSORS_INSMOD_1(thmc50); /* Each client has this additional data */ struct thmc50_data { - int sysctl_id; + int sysctl_id; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ - u16 temp,temp_os,temp_hyst, - remote_temp,remote_temp_os,remote_temp_hyst, - inter, inter_mask, die_code, analog_out; /* Register values */ + u16 temp, temp_os, temp_hyst, + remote_temp, remote_temp_os, remote_temp_hyst, + inter, inter_mask, die_code, analog_out; /* Register values */ }; #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ #ifdef MODULE static #else extern #endif - int __init sensors_thmc50_init(void); +int __init sensors_thmc50_init(void); static int __init thmc50_cleanup(void); static int thmc50_attach_adapter(struct i2c_adapter *adapter); -static int thmc50_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind); +static int thmc50_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); static void thmc50_init_client(struct i2c_client *client); static int thmc50_detach_client(struct i2c_client *client); static int thmc50_command(struct i2c_client *client, unsigned int cmd, - void *arg); -static void thmc50_inc_use (struct i2c_client *client); -static void thmc50_dec_use (struct i2c_client *client); + void *arg); +static void thmc50_inc_use(struct i2c_client *client); +static void thmc50_dec_use(struct i2c_client *client); static u16 swap_bytes(u16 val); static int thmc50_read_value(struct i2c_client *client, u8 reg); -static int thmc50_write_value(struct i2c_client *client, u8 reg, u16 value); -static void thmc50_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void thmc50_remote_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void thmc50_inter(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void thmc50_inter_mask(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void thmc50_die_code(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void thmc50_analog_out(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); +static int thmc50_write_value(struct i2c_client *client, u8 reg, + u16 value); +static void thmc50_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void thmc50_remote_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, + long *results); +static void thmc50_inter(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void thmc50_inter_mask(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void thmc50_die_code(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void thmc50_analog_out(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static void thmc50_update_client(struct i2c_client *client); /* This is the driver that will be inserted */ static struct i2c_driver thmc50_driver = { - /* name */ "THMC50 sensor chip driver", - /* id */ I2C_DRIVERID_THMC50, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &thmc50_attach_adapter, - /* detach_client */ &thmc50_detach_client, - /* command */ &thmc50_command, - /* inc_use */ &thmc50_inc_use, - /* dec_use */ &thmc50_dec_use + /* name */ "THMC50 sensor chip driver", + /* id */ I2C_DRIVERID_THMC50, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &thmc50_attach_adapter, + /* detach_client */ &thmc50_detach_client, + /* command */ &thmc50_command, + /* inc_use */ &thmc50_inc_use, + /* dec_use */ &thmc50_dec_use }; /* These files are created for each detected THMC50. This is just a template; @@ -153,19 +155,19 @@ static struct i2c_driver thmc50_driver = { is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table thmc50_dir_table_template[] = { - { THMC50_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &thmc50_temp }, - { THMC50_SYSCTL_REMOTE_TEMP, "remote_temp", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &thmc50_remote_temp }, - { THMC50_SYSCTL_INTER, "inter", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &thmc50_inter }, - { THMC50_SYSCTL_INTER_MASK, "inter_mask", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &thmc50_inter_mask }, - { THMC50_SYSCTL_DIE_CODE, "die_code", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &thmc50_die_code }, - { THMC50_SYSCTL_ANALOG_OUT, "analog_out", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &thmc50_analog_out }, - { 0 } + {THMC50_SYSCTL_TEMP, "temp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &thmc50_temp}, + {THMC50_SYSCTL_REMOTE_TEMP, "remote_temp", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &thmc50_remote_temp}, + {THMC50_SYSCTL_INTER, "inter", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &thmc50_inter}, + {THMC50_SYSCTL_INTER_MASK, "inter_mask", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &thmc50_inter_mask}, + {THMC50_SYSCTL_DIE_CODE, "die_code", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &thmc50_die_code}, + {THMC50_SYSCTL_ANALOG_OUT, "analog_out", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &thmc50_analog_out}, + {0} }; /* Used by init/cleanup */ @@ -175,150 +177,160 @@ static int thmc50_id = 0; int thmc50_attach_adapter(struct i2c_adapter *adapter) { - return sensors_detect(adapter,&addr_data,thmc50_detect); + return sensors_detect(adapter, &addr_data, thmc50_detect); } /* This function is called by sensors_detect */ -int thmc50_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind) +int thmc50_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) { - int company,i; - struct i2c_client *new_client; - struct thmc50_data *data; - int err=0; - const char *type_name,*client_name; + int company, i; + struct i2c_client *new_client; + struct thmc50_data *data; + int err = 0; + const char *type_name, *client_name; #ifdef DEBUG - printk("thmc50.o: Probing for THMC50 at 0x%2X on bus %d\n",address,adapter->id); + printk("thmc50.o: Probing for THMC50 at 0x%2X on bus %d\n", + address, adapter->id); #endif - /* Make sure we aren't probing the ISA bus!! This is just a safety check - at this moment; sensors_detect really won't call us. */ + /* Make sure we aren't probing the ISA bus!! This is just a safety check + at this moment; sensors_detect really won't call us. */ #ifdef DEBUG - if (i2c_is_isa_adapter(adapter)) { - printk("thmc50.o: thmc50_detect called for an ISA bus adapter?!?\n"); - return 0; - } + if (i2c_is_isa_adapter(adapter)) { + printk + ("thmc50.o: thmc50_detect called for an ISA bus adapter?!?\n"); + return 0; + } #endif - if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_BYTE_DATA)) - goto ERROR0; + if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) + goto ERROR0; - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access thmc50_{read,write}_value. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct thmc50_data), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR0; - } + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access thmc50_{read,write}_value. */ + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct thmc50_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } - data = (struct thmc50_data *) (((struct i2c_client *) new_client) + 1); - new_client->addr = address; - new_client->data = data; - new_client->adapter = adapter; - new_client->driver = &thmc50_driver; - new_client->flags = 0; + data = + (struct thmc50_data *) (((struct i2c_client *) new_client) + + 1); + new_client->addr = address; + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &thmc50_driver; + new_client->flags = 0; - /* Now, we do the remaining detection. */ - company = i2c_smbus_read_byte_data(new_client,THMC50_REG_COMPANY_ID); + /* Now, we do the remaining detection. */ + company = + i2c_smbus_read_byte_data(new_client, THMC50_REG_COMPANY_ID); - if (company != 0x49) { + if (company != 0x49) { #ifdef DEBUG - printk("thmc50.o: Detect of THMC50 failed (reg 3E: 0x%X)\n",company); + printk + ("thmc50.o: Detect of THMC50 failed (reg 3E: 0x%X)\n", + company); #endif - goto ERROR1; - } + goto ERROR1; + } - /* Determine the chip type - only one kind supported! */ - kind = thmc50; + /* Determine the chip type - only one kind supported! */ + kind = thmc50; - if (kind == thmc50) { - type_name = "thmc50"; - client_name = "THMC50 chip"; - } else { + if (kind == thmc50) { + type_name = "thmc50"; + client_name = "THMC50 chip"; + } else { #ifdef DEBUG - printk("thmc50.o: Internal error: unknown kind (%d)?!?",kind); + printk("thmc50.o: Internal error: unknown kind (%d)?!?", + kind); #endif - goto ERROR1; - } - - /* Fill in the remaining client fields and put it into the global list */ - strcpy(new_client->name,client_name); + goto ERROR1; + } - new_client->id = thmc50_id++; - data->valid = 0; - init_MUTEX(&data->update_lock); - - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); - /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry(new_client,type_name, - thmc50_dir_table_template, - THIS_MODULE)) < 0) { - err = i; - goto ERROR4; - } - data->sysctl_id = i; + new_client->id = thmc50_id++; + data->valid = 0; + init_MUTEX(&data->update_lock); - thmc50_init_client(new_client); - return 0; + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; + + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry(new_client, type_name, + thmc50_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR4; + } + data->sysctl_id = i; + + thmc50_init_client(new_client); + return 0; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR4: - i2c_detach_client(new_client); -ERROR3: -ERROR1: - kfree(new_client); -ERROR0: - return err; + ERROR4: + i2c_detach_client(new_client); + ERROR3: + ERROR1: + kfree(new_client); + ERROR0: + return err; } int thmc50_detach_client(struct i2c_client *client) { - int err; + int err; - sensors_deregister_entry(((struct thmc50_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct thmc50_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("thmc50.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("thmc50.o: Client deregistration failed, client not detached.\n"); + return err; + } - kfree(client); + kfree(client); - return 0; + return 0; } /* No commands defined yet */ int thmc50_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } -void thmc50_inc_use (struct i2c_client *client) +void thmc50_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } -void thmc50_dec_use (struct i2c_client *client) +void thmc50_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } u16 swap_bytes(u16 val) { - return (val >> 8) | (val << 8); + return (val >> 8) | (val << 8); } /* All registers are word-sized, except for the configuration register. @@ -326,7 +338,7 @@ u16 swap_bytes(u16 val) the usual practice. */ int thmc50_read_value(struct i2c_client *client, u8 reg) { - return i2c_smbus_read_byte_data(client,reg); + return i2c_smbus_read_byte_data(client, reg); } /* All registers are word-sized, except for the configuration register. @@ -334,167 +346,183 @@ int thmc50_read_value(struct i2c_client *client, u8 reg) the usual practice. */ int thmc50_write_value(struct i2c_client *client, u8 reg, u16 value) { - return i2c_smbus_write_byte_data(client,reg,value); + return i2c_smbus_write_byte_data(client, reg, value); } void thmc50_init_client(struct i2c_client *client) { - /* Initialize the THMC50 chip */ - thmc50_write_value(client,THMC50_REG_TEMP_OS, - TEMP_TO_REG(THMC50_INIT_TEMP_OS)); - thmc50_write_value(client,THMC50_REG_TEMP_HYST, - TEMP_TO_REG(THMC50_INIT_TEMP_HYST)); - thmc50_write_value(client,THMC50_REG_CONF,1); + /* Initialize the THMC50 chip */ + thmc50_write_value(client, THMC50_REG_TEMP_OS, + TEMP_TO_REG(THMC50_INIT_TEMP_OS)); + thmc50_write_value(client, THMC50_REG_TEMP_HYST, + TEMP_TO_REG(THMC50_INIT_TEMP_HYST)); + thmc50_write_value(client, THMC50_REG_CONF, 1); } void thmc50_update_client(struct i2c_client *client) { - struct thmc50_data *data = client->data; + struct thmc50_data *data = client->data; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > HZ+HZ/2 ) || - (jiffies < data->last_updated) || ! data->valid) { + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("Starting thmc50 update\n"); + printk("Starting thmc50 update\n"); #endif - data->temp = thmc50_read_value(client,THMC50_REG_TEMP); - data->temp_os = thmc50_read_value(client,THMC50_REG_TEMP_OS); - data->temp_hyst = thmc50_read_value(client,THMC50_REG_TEMP_HYST); - data->remote_temp = thmc50_read_value(client,THMC50_REG_REMOTE_TEMP); - data->remote_temp_os = thmc50_read_value(client,THMC50_REG_REMOTE_TEMP_OS); - data->remote_temp_hyst = thmc50_read_value(client,THMC50_REG_REMOTE_TEMP_HYST); - data->inter = thmc50_read_value(client,THMC50_REG_INTER); - data->inter_mask = thmc50_read_value(client,THMC50_REG_INTER_MASK); - data->die_code = thmc50_read_value(client,THMC50_REG_DIE_CODE); - data->analog_out = thmc50_read_value(client,THMC50_REG_ANALOG_OUT); - data->last_updated = jiffies; - data->valid = 1; - } + data->temp = thmc50_read_value(client, THMC50_REG_TEMP); + data->temp_os = + thmc50_read_value(client, THMC50_REG_TEMP_OS); + data->temp_hyst = + thmc50_read_value(client, THMC50_REG_TEMP_HYST); + data->remote_temp = + thmc50_read_value(client, THMC50_REG_REMOTE_TEMP); + data->remote_temp_os = + thmc50_read_value(client, THMC50_REG_REMOTE_TEMP_OS); + data->remote_temp_hyst = + thmc50_read_value(client, THMC50_REG_REMOTE_TEMP_HYST); + data->inter = thmc50_read_value(client, THMC50_REG_INTER); + data->inter_mask = + thmc50_read_value(client, THMC50_REG_INTER_MASK); + data->die_code = + thmc50_read_value(client, THMC50_REG_DIE_CODE); + data->analog_out = + thmc50_read_value(client, THMC50_REG_ANALOG_OUT); + data->last_updated = jiffies; + data->valid = 1; + } - up(&data->update_lock); + up(&data->update_lock); } void thmc50_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct thmc50_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - thmc50_update_client(client); - results[0] = TEMP_FROM_REG(data->temp_os); - results[1] = TEMP_FROM_REG(data->temp_hyst); - results[2] = TEMP_FROM_REG(data->temp); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->temp_os = TEMP_TO_REG(results[0]); - thmc50_write_value(client,THMC50_REG_TEMP_OS,data->temp_os); - } - if (*nrels_mag >= 2) { - data->temp_hyst = TEMP_TO_REG(results[1]); - thmc50_write_value(client,THMC50_REG_TEMP_HYST,data->temp_hyst); - } - } + struct thmc50_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + thmc50_update_client(client); + results[0] = TEMP_FROM_REG(data->temp_os); + results[1] = TEMP_FROM_REG(data->temp_hyst); + results[2] = TEMP_FROM_REG(data->temp); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->temp_os = TEMP_TO_REG(results[0]); + thmc50_write_value(client, THMC50_REG_TEMP_OS, + data->temp_os); + } + if (*nrels_mag >= 2) { + data->temp_hyst = TEMP_TO_REG(results[1]); + thmc50_write_value(client, THMC50_REG_TEMP_HYST, + data->temp_hyst); + } + } } -void thmc50_remote_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void thmc50_remote_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - struct thmc50_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - thmc50_update_client(client); - results[0] = TEMP_FROM_REG(data->remote_temp_os); - results[1] = TEMP_FROM_REG(data->remote_temp_hyst); - results[2] = TEMP_FROM_REG(data->remote_temp); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->remote_temp_os = TEMP_TO_REG(results[0]); - thmc50_write_value(client,THMC50_REG_REMOTE_TEMP_OS,data->remote_temp_os); - } - if (*nrels_mag >= 2) { - data->remote_temp_hyst = TEMP_TO_REG(results[1]); - thmc50_write_value(client,THMC50_REG_REMOTE_TEMP_HYST,data->remote_temp_hyst); - } - } + struct thmc50_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + thmc50_update_client(client); + results[0] = TEMP_FROM_REG(data->remote_temp_os); + results[1] = TEMP_FROM_REG(data->remote_temp_hyst); + results[2] = TEMP_FROM_REG(data->remote_temp); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->remote_temp_os = TEMP_TO_REG(results[0]); + thmc50_write_value(client, + THMC50_REG_REMOTE_TEMP_OS, + data->remote_temp_os); + } + if (*nrels_mag >= 2) { + data->remote_temp_hyst = TEMP_TO_REG(results[1]); + thmc50_write_value(client, + THMC50_REG_REMOTE_TEMP_HYST, + data->remote_temp_hyst); + } + } } void thmc50_inter(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct thmc50_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - thmc50_update_client(client); - results[0] = data->inter; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - printk("thmc50.o: No writes to Interrupt register!\n"); - } + struct thmc50_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + thmc50_update_client(client); + results[0] = data->inter; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + printk("thmc50.o: No writes to Interrupt register!\n"); + } } -void thmc50_inter_mask(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void thmc50_inter_mask(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - struct thmc50_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - thmc50_update_client(client); - results[0] = data->inter_mask; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->inter_mask = results[0]; - thmc50_write_value(client,THMC50_REG_INTER_MASK,data->inter_mask); - } - } + struct thmc50_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + thmc50_update_client(client); + results[0] = data->inter_mask; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->inter_mask = results[0]; + thmc50_write_value(client, THMC50_REG_INTER_MASK, + data->inter_mask); + } + } } -void thmc50_die_code(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void thmc50_die_code(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - struct thmc50_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - thmc50_update_client(client); - results[0] = data->die_code; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - printk("thmc50.o: No writes to Die-Code register!\n"); - } + struct thmc50_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + thmc50_update_client(client); + results[0] = data->die_code; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + printk("thmc50.o: No writes to Die-Code register!\n"); + } } -void thmc50_analog_out(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void thmc50_analog_out(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - struct thmc50_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - thmc50_update_client(client); - results[0] = data->analog_out; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->analog_out = results[0]; - thmc50_write_value(client,THMC50_REG_ANALOG_OUT,data->analog_out); - } - } + struct thmc50_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + thmc50_update_client(client); + results[0] = data->analog_out; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->analog_out = results[0]; + thmc50_write_value(client, THMC50_REG_ANALOG_OUT, + data->analog_out); + } + } } @@ -502,50 +530,52 @@ void thmc50_analog_out(struct i2c_client *client, int operation, int ctl_name, int __init sensors_thmc50_init(void) { - int res; + int res; - printk("thmc50.o version %s (%s)\n",LM_VERSION,LM_DATE); - thmc50_initialized = 0; - if ((res = i2c_add_driver(&thmc50_driver))) { - printk("thmc50.o: Driver registration failed, module not inserted.\n"); - thmc50_cleanup(); - return res; - } - thmc50_initialized ++; - return 0; + printk("thmc50.o version %s (%s)\n", LM_VERSION, LM_DATE); + thmc50_initialized = 0; + if ((res = i2c_add_driver(&thmc50_driver))) { + printk + ("thmc50.o: Driver registration failed, module not inserted.\n"); + thmc50_cleanup(); + return res; + } + thmc50_initialized++; + return 0; } int __init thmc50_cleanup(void) { - int res; + int res; - if (thmc50_initialized >= 1) { - if ((res = i2c_del_driver(&thmc50_driver))) { - printk("thmc50.o: Driver deregistration failed, module not removed.\n"); - return res; - } - thmc50_initialized --; - } + if (thmc50_initialized >= 1) { + if ((res = i2c_del_driver(&thmc50_driver))) { + printk + ("thmc50.o: Driver deregistration failed, module not removed.\n"); + return res; + } + thmc50_initialized--; + } - return 0; + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard and Philip Edelbrock "); +MODULE_AUTHOR + ("Frodo Looijaard and Philip Edelbrock "); MODULE_DESCRIPTION("THMC50 driver"); int init_module(void) { - return sensors_thmc50_init(); + return sensors_thmc50_init(); } int cleanup_module(void) { - return thmc50_cleanup(); + return thmc50_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/chips/w83781d.c b/kernel/chips/w83781d.c index e11e00a6..496c7e05 100644 --- a/kernel/chips/w83781d.c +++ b/kernel/chips/w83781d.c @@ -59,13 +59,13 @@ #define W83781D_RT 1 /* Addresses to scan */ -static unsigned short normal_i2c[] = {SENSORS_I2C_END}; -static unsigned short normal_i2c_range[] = {0x20,0x2f,SENSORS_I2C_END}; -static unsigned int normal_isa[] = {0x0290,SENSORS_ISA_END}; -static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; +static unsigned short normal_i2c[] = { SENSORS_I2C_END }; +static unsigned short normal_i2c_range[] = { 0x20, 0x2f, SENSORS_I2C_END }; +static unsigned int normal_isa[] = { 0x0290, SENSORS_ISA_END }; +static unsigned int normal_isa_range[] = { SENSORS_ISA_END }; /* Insmod parameters */ -SENSORS_INSMOD_5(w83781d,w83782d,w83783s,w83627hf,as99127f); +SENSORS_INSMOD_5(w83781d, w83782d, w83783s, w83627hf, as99127f); /* Many W83781D constants specified below */ @@ -130,8 +130,9 @@ SENSORS_INSMOD_5(w83781d,w83782d,w83783s,w83627hf,as99127f); #define W83781D_REG_PWM4 0x5F #define W83781D_REG_PWMCLK12 0x5C #define W83781D_REG_PWMCLK34 0x45C -static const u8 regpwm[] = {W83781D_REG_PWM1, W83781D_REG_PWM2, - W83781D_REG_PWM3, W83781D_REG_PWM4}; +static const u8 regpwm[] = { W83781D_REG_PWM1, W83781D_REG_PWM2, + W83781D_REG_PWM3, W83781D_REG_PWM4 +}; #define W83781D_REG_PWM(nr) (regpwm[(nr) - 1]) #define W83781D_REG_I2C_ADDR 0x48 @@ -141,9 +142,9 @@ static const u8 regpwm[] = {W83781D_REG_PWM1, W83781D_REG_PWM2, received the information in an email from Winbond tech support */ /* Sensor selection 782D/783S only */ #define W83781D_REG_SCFG1 0x5D -static const u8 BIT_SCFG1[] = {0x02, 0x04, 0x08}; +static const u8 BIT_SCFG1[] = { 0x02, 0x04, 0x08 }; #define W83781D_REG_SCFG2 0x59 -static const u8 BIT_SCFG2[] = {0x10, 0x04, 0x08}; +static const u8 BIT_SCFG2[] = { 0x10, 0x04, 0x08 }; #define W83781D_DEFAULT_BETA 3435 /* RT Table registers */ @@ -159,10 +160,11 @@ static const u8 BIT_SCFG2[] = {0x10, 0x04, 0x08}; extern inline u8 FAN_TO_REG(long rpm, int div) { - if (rpm == 0) - return 255; - rpm = SENSORS_LIMIT(rpm,1,1000000); - return SENSORS_LIMIT((1350000 + rpm*div/2) / (rpm*div),1,254); + if (rpm == 0) + return 255; + rpm = SENSORS_LIMIT(rpm, 1, 1000000); + return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, + 254); } #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) @@ -194,15 +196,14 @@ extern inline u8 FAN_TO_REG(long rpm, int div) extern inline u8 DIV_TO_REG(long val, enum chips type) { - int i; - val = SENSORS_LIMIT(val,1,((type == w83781d) ? 8 : 128)) >> 1; - for(i = 0; i < 6; i++) - { - if(val == 0) - break; - val >>= 1; - } - return ((u8) i); + int i; + val = SENSORS_LIMIT(val, 1, ((type == w83781d) ? 8 : 128)) >> 1; + for (i = 0; i < 6; i++) { + if (val == 0) + break; + val >>= 1; + } + return ((u8) i); } /* Initial limits */ @@ -224,58 +225,58 @@ extern inline u8 DIV_TO_REG(long val, enum chips type) #define W83781D_INIT_IN_MIN_0 \ (W83781D_INIT_IN_0 - W83781D_INIT_IN_0 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MAX_0 \ (W83781D_INIT_IN_0 + W83781D_INIT_IN_0 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MIN_1 \ (W83781D_INIT_IN_1 - W83781D_INIT_IN_1 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MAX_1 \ (W83781D_INIT_IN_1 + W83781D_INIT_IN_1 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MIN_2 \ (W83781D_INIT_IN_2 - W83781D_INIT_IN_2 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MAX_2 \ (W83781D_INIT_IN_2 + W83781D_INIT_IN_2 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MIN_3 \ (W83781D_INIT_IN_3 - W83781D_INIT_IN_3 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MAX_3 \ (W83781D_INIT_IN_3 + W83781D_INIT_IN_3 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MIN_4 \ (W83781D_INIT_IN_4 - W83781D_INIT_IN_4 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MAX_4 \ (W83781D_INIT_IN_4 + W83781D_INIT_IN_4 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MIN_5 \ (W83781D_INIT_IN_5 - W83781D_INIT_IN_5 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MAX_5 \ (W83781D_INIT_IN_5 + W83781D_INIT_IN_5 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MIN_6 \ (W83781D_INIT_IN_6 - W83781D_INIT_IN_6 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MAX_6 \ (W83781D_INIT_IN_6 + W83781D_INIT_IN_6 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MIN_7 \ (W83781D_INIT_IN_7 - W83781D_INIT_IN_7 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MAX_7 \ (W83781D_INIT_IN_7 + W83781D_INIT_IN_7 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MIN_8 \ (W83781D_INIT_IN_8 - W83781D_INIT_IN_8 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) #define W83781D_INIT_IN_MAX_8 \ (W83781D_INIT_IN_8 + W83781D_INIT_IN_8 * W83781D_INIT_IN_PERCENTAGE \ - / 100) + / 100) /* Initial limits for 782d/783s negative voltages */ /* These aren't direct multiples because of level shift */ /* Beware going negative - check */ @@ -306,7 +307,7 @@ extern inline u8 DIV_TO_REG(long val, enum chips type) #ifdef MODULE extern int init_module(void); extern int cleanup_module(void); -#endif /* MODULE */ +#endif /* MODULE */ /* There are some complications in a module like this. First off, W83781D chips may be both present on the SMBus and the ISA bus, and we have to handle @@ -328,41 +329,41 @@ extern int cleanup_module(void); dynamically allocated, at the same time when a new w83781d client is allocated. */ struct w83781d_data { - struct semaphore lock; - int sysctl_id; - enum chips type; + struct semaphore lock; + int sysctl_id; + enum chips type; - struct semaphore update_lock; - char valid; /* !=0 if following fields are valid */ - unsigned long last_updated; /* In jiffies */ + struct semaphore update_lock; + char valid; /* !=0 if following fields are valid */ + unsigned long last_updated; /* In jiffies */ - struct i2c_client *lm75; /* for secondary I2C addresses */ - /* pointer to array of 2 subclients */ + struct i2c_client *lm75; /* for secondary I2C addresses */ + /* pointer to array of 2 subclients */ - u8 in[9]; /* Register value - 8 & 9 for 782D only */ - u8 in_max[9]; /* Register value - 8 & 9 for 782D only */ - u8 in_min[9]; /* Register value - 8 & 9 for 782D only */ - u8 fan[3]; /* Register value */ - u8 fan_min[3]; /* Register value */ - u8 temp; - u8 temp_over; /* Register value */ - u8 temp_hyst; /* Register value */ - u16 temp_add[2]; /* Register value */ - u16 temp_add_over[2]; /* Register value */ - u16 temp_add_hyst[2]; /* Register value */ - u8 fan_div[3]; /* Register encoding, shifted right */ - u8 vid; /* Register encoding, combined */ - u32 alarms; /* Register encoding, combined */ - u32 beeps; /* Register encoding, combined */ - u8 beep_enable; /* Boolean */ - u8 pwm[4]; /* Register value */ - u16 sens[3]; /* 782D/783S only. - 1 = pentium diode; 2 = 3904 diode; - 3000-5000 = thermistor beta. - Default = 3435. - Other Betas unimplemented */ + u8 in[9]; /* Register value - 8 & 9 for 782D only */ + u8 in_max[9]; /* Register value - 8 & 9 for 782D only */ + u8 in_min[9]; /* Register value - 8 & 9 for 782D only */ + u8 fan[3]; /* Register value */ + u8 fan_min[3]; /* Register value */ + u8 temp; + u8 temp_over; /* Register value */ + u8 temp_hyst; /* Register value */ + u16 temp_add[2]; /* Register value */ + u16 temp_add_over[2]; /* Register value */ + u16 temp_add_hyst[2]; /* Register value */ + u8 fan_div[3]; /* Register encoding, shifted right */ + u8 vid; /* Register encoding, combined */ + u32 alarms; /* Register encoding, combined */ + u32 beeps; /* Register encoding, combined */ + u8 beep_enable; /* Boolean */ + u8 pwm[4]; /* Register value */ + u16 sens[3]; /* 782D/783S only. + 1 = pentium diode; 2 = 3904 diode; + 3000-5000 = thermistor beta. + Default = 3435. + Other Betas unimplemented */ #ifdef W83781D_RT - u8 rt[3][32]; /* Register value */ + u8 rt[3][32]; /* Register value */ #endif }; @@ -372,62 +373,62 @@ static #else extern #endif - int __init sensors_w83781d_init(void); +int __init sensors_w83781d_init(void); static int __init w83781d_cleanup(void); static int w83781d_attach_adapter(struct i2c_adapter *adapter); -static int w83781d_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind); +static int w83781d_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind); static int w83781d_detach_client(struct i2c_client *client); -static int w83781d_command(struct i2c_client *client, unsigned int cmd, - void *arg); -static void w83781d_inc_use (struct i2c_client *client); -static void w83781d_dec_use (struct i2c_client *client); +static int w83781d_command(struct i2c_client *client, unsigned int cmd, + void *arg); +static void w83781d_inc_use(struct i2c_client *client); +static void w83781d_dec_use(struct i2c_client *client); static int w83781d_read_value(struct i2c_client *client, u16 register); -static int w83781d_write_value(struct i2c_client *client, u16 register, - u16 value); +static int w83781d_write_value(struct i2c_client *client, u16 register, + u16 value); static void w83781d_update_client(struct i2c_client *client); static void w83781d_init_client(struct i2c_client *client); -static void w83781d_in(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void w83781d_fan(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); -static void w83781d_temp(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); -static void w83781d_temp_add(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); -static void w83781d_vid(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); +static void w83781d_in(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void w83781d_fan(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void w83781d_temp(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void w83781d_temp_add(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); +static void w83781d_vid(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static void w83781d_alarms(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); -static void w83781d_beep(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results); + int ctl_name, int *nrels_mag, long *results); +static void w83781d_beep(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results); static void w83781d_fan_div(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); + int ctl_name, int *nrels_mag, long *results); static void w83781d_pwm(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); + int ctl_name, int *nrels_mag, long *results); static void w83781d_sens(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); + int ctl_name, int *nrels_mag, long *results); #ifdef W83781D_RT static void w83781d_rt(struct i2c_client *client, int operation, - int ctl_name, int *nrels_mag, long *results); + int ctl_name, int *nrels_mag, long *results); #endif static u16 swap_bytes(u16 val); static int w83781d_id = 0; static struct i2c_driver w83781d_driver = { - /* name */ "W83781D sensor driver", - /* id */ I2C_DRIVERID_W83781D, - /* flags */ I2C_DF_NOTIFY, - /* attach_adapter */ &w83781d_attach_adapter, - /* detach_client */ &w83781d_detach_client, - /* command */ &w83781d_command, - /* inc_use */ &w83781d_inc_use, - /* dec_use */ &w83781d_dec_use + /* name */ "W83781D sensor driver", + /* id */ I2C_DRIVERID_W83781D, + /* flags */ I2C_DF_NOTIFY, + /* attach_adapter */ &w83781d_attach_adapter, + /* detach_client */ &w83781d_detach_client, + /* command */ &w83781d_command, + /* inc_use */ &w83781d_inc_use, + /* dec_use */ &w83781d_dec_use }; /* Used by w83781d_init/cleanup */ @@ -440,202 +441,202 @@ static int __initdata w83781d_initialized = 0; is done through one of the 'extra' fields which are initialized when a new copy is allocated. */ static ctl_table w83781d_dir_table_template[] = { - { W83781D_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN6, "in6", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan }, - { W83781D_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan }, - { W83781D_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan }, - { W83781D_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_temp }, - { W83781D_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_temp_add }, - { W83781D_SYSCTL_TEMP3, "temp3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_temp_add }, - { W83781D_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_vid }, - { W83781D_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan_div }, - { W83781D_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_alarms }, - { W83781D_SYSCTL_BEEP, "beep", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_beep }, + {W83781D_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN6, "in6", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan}, + {W83781D_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan}, + {W83781D_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan}, + {W83781D_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_temp}, + {W83781D_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_temp_add}, + {W83781D_SYSCTL_TEMP3, "temp3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_temp_add}, + {W83781D_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_vid}, + {W83781D_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan_div}, + {W83781D_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_alarms}, + {W83781D_SYSCTL_BEEP, "beep", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_beep}, #ifdef W83781D_RT - { W83781D_SYSCTL_RT1, "rt1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_rt }, - { W83781D_SYSCTL_RT2, "rt2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_rt }, - { W83781D_SYSCTL_RT3, "rt3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_rt }, + {W83781D_SYSCTL_RT1, "rt1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_rt}, + {W83781D_SYSCTL_RT2, "rt2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_rt}, + {W83781D_SYSCTL_RT3, "rt3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_rt}, #endif - { 0 } + {0} }; /* without pwm3-4 */ static ctl_table w83782d_isa_dir_table_template[] = { - { W83781D_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN6, "in6", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN7, "in7", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN8, "in8", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan }, - { W83781D_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan }, - { W83781D_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan }, - { W83781D_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_temp }, - { W83781D_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_temp_add }, - { W83781D_SYSCTL_TEMP3, "temp3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_temp_add }, - { W83781D_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_vid }, - { W83781D_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan_div }, - { W83781D_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_alarms }, - { W83781D_SYSCTL_BEEP, "beep", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_beep }, - { W83781D_SYSCTL_PWM1, "pwm1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_pwm }, - { W83781D_SYSCTL_PWM2, "pwm2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_pwm }, - { W83781D_SYSCTL_SENS1, "sensor1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_sens }, - { W83781D_SYSCTL_SENS2, "sensor2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_sens }, - { W83781D_SYSCTL_SENS3, "sensor3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_sens }, - { 0 } + {W83781D_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN6, "in6", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN7, "in7", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN8, "in8", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan}, + {W83781D_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan}, + {W83781D_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan}, + {W83781D_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_temp}, + {W83781D_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_temp_add}, + {W83781D_SYSCTL_TEMP3, "temp3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_temp_add}, + {W83781D_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_vid}, + {W83781D_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan_div}, + {W83781D_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_alarms}, + {W83781D_SYSCTL_BEEP, "beep", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_beep}, + {W83781D_SYSCTL_PWM1, "pwm1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_pwm}, + {W83781D_SYSCTL_PWM2, "pwm2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_pwm}, + {W83781D_SYSCTL_SENS1, "sensor1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_sens}, + {W83781D_SYSCTL_SENS2, "sensor2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_sens}, + {W83781D_SYSCTL_SENS3, "sensor3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_sens}, + {0} }; /* with pwm3-4 */ static ctl_table w83782d_i2c_dir_table_template[] = { - { W83781D_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN6, "in6", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN7, "in7", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN8, "in8", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan }, - { W83781D_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan }, - { W83781D_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan }, - { W83781D_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_temp }, - { W83781D_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_temp_add }, - { W83781D_SYSCTL_TEMP3, "temp3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_temp_add }, - { W83781D_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_vid }, - { W83781D_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan_div }, - { W83781D_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_alarms }, - { W83781D_SYSCTL_BEEP, "beep", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_beep }, - { W83781D_SYSCTL_PWM1, "pwm1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_pwm }, - { W83781D_SYSCTL_PWM2, "pwm2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_pwm }, - { W83781D_SYSCTL_PWM3, "pwm3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_pwm }, - { W83781D_SYSCTL_PWM4, "pwm4", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_pwm }, - { W83781D_SYSCTL_SENS1, "sensor1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_sens }, - { W83781D_SYSCTL_SENS2, "sensor2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_sens }, - { W83781D_SYSCTL_SENS3, "sensor3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_sens }, - { 0 } + {W83781D_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN1, "in1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN6, "in6", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN7, "in7", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN8, "in8", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan}, + {W83781D_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan}, + {W83781D_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan}, + {W83781D_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_temp}, + {W83781D_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_temp_add}, + {W83781D_SYSCTL_TEMP3, "temp3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_temp_add}, + {W83781D_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_vid}, + {W83781D_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan_div}, + {W83781D_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_alarms}, + {W83781D_SYSCTL_BEEP, "beep", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_beep}, + {W83781D_SYSCTL_PWM1, "pwm1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_pwm}, + {W83781D_SYSCTL_PWM2, "pwm2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_pwm}, + {W83781D_SYSCTL_PWM3, "pwm3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_pwm}, + {W83781D_SYSCTL_PWM4, "pwm4", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_pwm}, + {W83781D_SYSCTL_SENS1, "sensor1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_sens}, + {W83781D_SYSCTL_SENS2, "sensor2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_sens}, + {W83781D_SYSCTL_SENS3, "sensor3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_sens}, + {0} }; static ctl_table w83783s_dir_table_template[] = { - { W83781D_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - /* no in1 to maintain compatibility with 781d and 782d. */ - { W83781D_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_IN6, "in6", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_in }, - { W83781D_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan }, - { W83781D_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan }, - { W83781D_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan }, - { W83781D_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_temp }, - { W83781D_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_temp_add }, - { W83781D_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_vid }, - { W83781D_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_fan_div }, - { W83781D_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_alarms }, - { W83781D_SYSCTL_BEEP, "beep", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_beep }, - { W83781D_SYSCTL_PWM1, "pwm1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_pwm }, - { W83781D_SYSCTL_PWM2, "pwm2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_pwm }, - { W83781D_SYSCTL_SENS1, "sensor1", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_sens }, - { W83781D_SYSCTL_SENS2, "sensor2", NULL, 0, 0644, NULL, &sensors_proc_real, - &sensors_sysctl_real, NULL, &w83781d_sens }, - { 0 } + {W83781D_SYSCTL_IN0, "in0", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + /* no in1 to maintain compatibility with 781d and 782d. */ + {W83781D_SYSCTL_IN2, "in2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN3, "in3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN4, "in4", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN5, "in5", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_IN6, "in6", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_in}, + {W83781D_SYSCTL_FAN1, "fan1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan}, + {W83781D_SYSCTL_FAN2, "fan2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan}, + {W83781D_SYSCTL_FAN3, "fan3", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan}, + {W83781D_SYSCTL_TEMP1, "temp1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_temp}, + {W83781D_SYSCTL_TEMP2, "temp2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_temp_add}, + {W83781D_SYSCTL_VID, "vid", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_vid}, + {W83781D_SYSCTL_FAN_DIV, "fan_div", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_fan_div}, + {W83781D_SYSCTL_ALARMS, "alarms", NULL, 0, 0444, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_alarms}, + {W83781D_SYSCTL_BEEP, "beep", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_beep}, + {W83781D_SYSCTL_PWM1, "pwm1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_pwm}, + {W83781D_SYSCTL_PWM2, "pwm2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_pwm}, + {W83781D_SYSCTL_SENS1, "sensor1", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_sens}, + {W83781D_SYSCTL_SENS2, "sensor2", NULL, 0, 0644, NULL, &sensors_proc_real, + &sensors_sysctl_real, NULL, &w83781d_sens}, + {0} }; @@ -645,297 +646,328 @@ static ctl_table w83783s_dir_table_template[] = { * when a new adapter is inserted (and w83781d_driver is still present) */ int w83781d_attach_adapter(struct i2c_adapter *adapter) { - return sensors_detect(adapter,&addr_data,w83781d_detect); + return sensors_detect(adapter, &addr_data, w83781d_detect); } -int w83781d_detect(struct i2c_adapter *adapter, int address, - unsigned short flags, int kind) +int w83781d_detect(struct i2c_adapter *adapter, int address, + unsigned short flags, int kind) { - int i,val1,val2; - struct i2c_client *new_client; - struct w83781d_data *data; - int err=0; - const char *type_name = ""; - const char *client_name = ""; - int is_isa = i2c_is_isa_adapter(adapter); - enum vendor {winbond, asus} vendid; + int i, val1, val2; + struct i2c_client *new_client; + struct w83781d_data *data; + int err = 0; + const char *type_name = ""; + const char *client_name = ""; + int is_isa = i2c_is_isa_adapter(adapter); + enum vendor { winbond, asus } vendid; - if (!is_isa && ! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_BYTE_DATA)) - goto ERROR0; + if (!is_isa + && !i2c_check_functionality(adapter, + I2C_FUNC_SMBUS_BYTE_DATA)) goto + ERROR0; - if (is_isa) { - if (check_region(address,W83781D_EXTENT)) - goto ERROR0; - } + if (is_isa) { + if (check_region(address, W83781D_EXTENT)) + goto ERROR0; + } - /* Probe whether there is anything available on this address. Already - done for SMBus clients */ - if (kind < 0) { - if (is_isa) { + /* Probe whether there is anything available on this address. Already + done for SMBus clients */ + if (kind < 0) { + if (is_isa) { #define REALLY_SLOW_IO - /* We need the timeouts for at least some LM78-like chips. But only - if we read 'undefined' registers. */ - i = inb_p(address + 1); - if (inb_p(address + 2) != i) - goto ERROR0; - if (inb_p(address + 3) != i) - goto ERROR0; - if (inb_p(address + 7) != i) - goto ERROR0; + /* We need the timeouts for at least some LM78-like chips. But only + if we read 'undefined' registers. */ + i = inb_p(address + 1); + if (inb_p(address + 2) != i) + goto ERROR0; + if (inb_p(address + 3) != i) + goto ERROR0; + if (inb_p(address + 7) != i) + goto ERROR0; #undef REALLY_SLOW_IO - /* Let's just hope nothing breaks here */ - i = inb_p(address + 5) & 0x7f; - outb_p(~i & 0x7f,address+5); - if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) { - outb_p(i,address+5); - return 0; - } - } - } + /* Let's just hope nothing breaks here */ + i = inb_p(address + 5) & 0x7f; + outb_p(~i & 0x7f, address + 5); + if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) { + outb_p(i, address + 5); + return 0; + } + } + } - /* OK. For now, we presume we have a valid client. We now create the - client structure, even though we cannot fill it completely yet. - But it allows us to access w83781d_{read,write}_value. */ + /* OK. For now, we presume we have a valid client. We now create the + client structure, even though we cannot fill it completely yet. + But it allows us to access w83781d_{read,write}_value. */ - if (! (new_client = kmalloc(sizeof(struct i2c_client) + - sizeof(struct w83781d_data), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR0; - } + if (!(new_client = kmalloc(sizeof(struct i2c_client) + + sizeof(struct w83781d_data), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR0; + } - data = (struct w83781d_data *) (new_client + 1); - new_client->addr = address; - init_MUTEX(&data->lock); - new_client->data = data; - new_client->adapter = adapter; - new_client->driver = &w83781d_driver; - new_client->flags = 0; + data = (struct w83781d_data *) (new_client + 1); + new_client->addr = address; + init_MUTEX(&data->lock); + new_client->data = data; + new_client->adapter = adapter; + new_client->driver = &w83781d_driver; + new_client->flags = 0; - /* Now, we do the remaining detection. */ + /* Now, we do the remaining detection. */ - /* The w8378?d may be stuck in some other bank than bank 0. This may - make reading other information impossible. Specify a force=... or - force_*=... parameter, and the Winbond will be reset to the right - bank. */ - if (kind < 0) { - if (w83781d_read_value(new_client,W83781D_REG_CONFIG) & 0x80) - goto ERROR1; - val1 = w83781d_read_value(new_client,W83781D_REG_BANK); - val2 = w83781d_read_value(new_client,W83781D_REG_CHIPMAN); - /* Check for Winbond or Asus ID if in bank 0 */ - if (!(val1 & 0x07) && - ((!(val1 & 0x80) && (val2 != 0xa3) && (val2 != 0xc3)) || - ((val1 & 0x80) && (val2 != 0x5c) && (val2 != 0x12)))) - goto ERROR1; - /* If Winbond SMBus, check address at 0x48. Asus doesn't support */ - if ((!is_isa) && ((!(val1 & 0x80) && (val2 == 0xa3)) || - ((val1 & 0x80) && (val2 == 0x5c)))) { - if (w83781d_read_value(new_client,W83781D_REG_I2C_ADDR) != address) - goto ERROR1; - } - } + /* The w8378?d may be stuck in some other bank than bank 0. This may + make reading other information impossible. Specify a force=... or + force_*=... parameter, and the Winbond will be reset to the right + bank. */ + if (kind < 0) { + if (w83781d_read_value(new_client, W83781D_REG_CONFIG) & + 0x80) goto ERROR1; + val1 = w83781d_read_value(new_client, W83781D_REG_BANK); + val2 = w83781d_read_value(new_client, W83781D_REG_CHIPMAN); + /* Check for Winbond or Asus ID if in bank 0 */ + if (!(val1 & 0x07) && + ((!(val1 & 0x80) && (val2 != 0xa3) && (val2 != 0xc3)) + || ((val1 & 0x80) && (val2 != 0x5c) + && (val2 != 0x12)))) goto ERROR1; + /* If Winbond SMBus, check address at 0x48. Asus doesn't support */ + if ((!is_isa) && ((!(val1 & 0x80) && (val2 == 0xa3)) || + ((val1 & 0x80) && (val2 == 0x5c)))) { + if (w83781d_read_value + (new_client, W83781D_REG_I2C_ADDR) != address) + goto ERROR1; + } + } - /* We have either had a force parameter, or we have already detected the - Winbond. Put it now into bank 0 and Vendor ID High Byte */ - w83781d_write_value(new_client,W83781D_REG_BANK, - (w83781d_read_value(new_client,W83781D_REG_BANK) & 0x78) | 0x80); + /* We have either had a force parameter, or we have already detected the + Winbond. Put it now into bank 0 and Vendor ID High Byte */ + w83781d_write_value(new_client, W83781D_REG_BANK, + (w83781d_read_value(new_client, + W83781D_REG_BANK) & 0x78) | + 0x80); - /* Determine the chip type. */ - if (kind <= 0) { - /* get vendor ID */ - val2 = w83781d_read_value(new_client,W83781D_REG_CHIPMAN); - if (val2 == 0x5c) - vendid = winbond; - else if (val2 == 0x12) - vendid = asus; - else - goto ERROR1; - /* mask off lower bit, not reliable */ - val1 = w83781d_read_value(new_client,W83781D_REG_WCHIPID) & 0xfe; - if (val1 == 0x10 && vendid == winbond) - kind = w83781d; - else if (val1 == 0x30 && vendid == winbond) - kind = w83782d; - else if (val1 == 0x40 && vendid == winbond && !is_isa) - kind = w83783s; - else if (val1 == 0x20 && vendid == winbond) - kind = w83627hf; - else if (val1 == 0x30 && vendid == asus && !is_isa) - kind = as99127f; - else { - if (kind == 0) - printk("w83781d.o: Ignoring 'force' parameter for unknown chip at" - "adapter %d, address 0x%02x\n",i2c_adapter_id(adapter),address); - goto ERROR1; - } - } + /* Determine the chip type. */ + if (kind <= 0) { + /* get vendor ID */ + val2 = w83781d_read_value(new_client, W83781D_REG_CHIPMAN); + if (val2 == 0x5c) + vendid = winbond; + else if (val2 == 0x12) + vendid = asus; + else + goto ERROR1; + /* mask off lower bit, not reliable */ + val1 = + w83781d_read_value(new_client, + W83781D_REG_WCHIPID) & 0xfe; + if (val1 == 0x10 && vendid == winbond) + kind = w83781d; + else if (val1 == 0x30 && vendid == winbond) + kind = w83782d; + else if (val1 == 0x40 && vendid == winbond && !is_isa) + kind = w83783s; + else if (val1 == 0x20 && vendid == winbond) + kind = w83627hf; + else if (val1 == 0x30 && vendid == asus && !is_isa) + kind = as99127f; + else { + if (kind == 0) + printk + ("w83781d.o: Ignoring 'force' parameter for unknown chip at" + "adapter %d, address 0x%02x\n", + i2c_adapter_id(adapter), address); + goto ERROR1; + } + } - if (kind == w83781d) { - type_name = "w83781d"; - client_name = "W83781D chip"; - } else if (kind == w83782d) { - type_name = "w83782d"; - client_name = "W83782D chip"; - } else if (kind == w83783s) { - type_name = "w83783s"; - client_name = "W83783S chip"; - } else if (kind == w83627hf) { - type_name = "w83627hf"; - client_name = "W83627HF chip"; - } else if (kind == as99127f) { - type_name = "as99127f"; - client_name = "AS99127F chip"; - } else { + if (kind == w83781d) { + type_name = "w83781d"; + client_name = "W83781D chip"; + } else if (kind == w83782d) { + type_name = "w83782d"; + client_name = "W83782D chip"; + } else if (kind == w83783s) { + type_name = "w83783s"; + client_name = "W83783S chip"; + } else if (kind == w83627hf) { + type_name = "w83627hf"; + client_name = "W83627HF chip"; + } else if (kind == as99127f) { + type_name = "as99127f"; + client_name = "AS99127F chip"; + } else { #ifdef DEBUG - printk("w83781d.o: Internal error: unknown kind (%d)?!?",kind); + printk("w83781d.o: Internal error: unknown kind (%d)?!?", + kind); #endif - goto ERROR1; - } + goto ERROR1; + } - /* Reserve the ISA region */ - if (is_isa) - request_region(address, W83781D_EXTENT, type_name); + /* Reserve the ISA region */ + if (is_isa) + request_region(address, W83781D_EXTENT, type_name); - /* Fill in the remaining client fields and put it into the global list */ - strcpy(new_client->name,client_name); - data->type = kind; + /* Fill in the remaining client fields and put it into the global list */ + strcpy(new_client->name, client_name); + data->type = kind; - new_client->id = w83781d_id++; - data->valid = 0; - init_MUTEX(&data->update_lock); + new_client->id = w83781d_id++; + data->valid = 0; + init_MUTEX(&data->update_lock); - /* Tell the I2C layer a new client has arrived */ - if ((err = i2c_attach_client(new_client))) - goto ERROR3; + /* Tell the I2C layer a new client has arrived */ + if ((err = i2c_attach_client(new_client))) + goto ERROR3; - /* attach secondary i2c lm75-like clients */ - if (!is_isa) { - if (! (data->lm75 = kmalloc(2 * sizeof(struct i2c_client), - GFP_KERNEL))) { - err = -ENOMEM; - goto ERROR4; - } - val1 = w83781d_read_value(new_client,W83781D_REG_I2C_SUBADDR); - data->lm75[0].addr = 0x48 + (val1 & 0x07); - data->lm75[1].addr = 0x48 + ((val1 >> 4) & 0x07); - if (kind == w83781d) - client_name = "W83781D subclient"; - else if (kind == w83782d) - client_name = "W83782D subclient"; - else if (kind == w83783s) - client_name = "W83783S subclient"; - else if (kind == w83627hf) - client_name = "W83627HF subclient"; - else if (kind == as99127f) - client_name = "AS99127F subclient"; + /* attach secondary i2c lm75-like clients */ + if (!is_isa) { + if (!(data->lm75 = kmalloc(2 * sizeof(struct i2c_client), + GFP_KERNEL))) { + err = -ENOMEM; + goto ERROR4; + } + val1 = + w83781d_read_value(new_client, + W83781D_REG_I2C_SUBADDR); + data->lm75[0].addr = 0x48 + (val1 & 0x07); + data->lm75[1].addr = 0x48 + ((val1 >> 4) & 0x07); + if (kind == w83781d) + client_name = "W83781D subclient"; + else if (kind == w83782d) + client_name = "W83782D subclient"; + else if (kind == w83783s) + client_name = "W83783S subclient"; + else if (kind == w83627hf) + client_name = "W83627HF subclient"; + else if (kind == as99127f) + client_name = "AS99127F subclient"; - for(i = 0; i <= 1; i++) { - data->lm75[i].data = NULL; /* store all data in w83781d */ - data->lm75[i].adapter = adapter; - data->lm75[i].driver = &w83781d_driver; - data->lm75[i].flags = 0; - strcpy(data->lm75[i].name,client_name); - data->lm75[i].id = w83781d_id++; - if ((err = i2c_attach_client(&(data->lm75[i])))) { - if(i == 1) - goto ERROR6; - else - goto ERROR5; - } - } - } else { - data->lm75 = NULL; - } + for (i = 0; i <= 1; i++) { + data->lm75[i].data = NULL; /* store all data in w83781d */ + data->lm75[i].adapter = adapter; + data->lm75[i].driver = &w83781d_driver; + data->lm75[i].flags = 0; + strcpy(data->lm75[i].name, client_name); + data->lm75[i].id = w83781d_id++; + if ((err = i2c_attach_client(&(data->lm75[i])))) { + if (i == 1) + goto ERROR6; + else + goto ERROR5; + } + } + } else { + data->lm75 = NULL; + } - /* Register a new directory entry with module sensors */ - if ((i = sensors_register_entry(new_client, - type_name, - kind == w83781d?w83781d_dir_table_template: - kind == w83783s?w83783s_dir_table_template: - is_isa?w83782d_isa_dir_table_template: - w83782d_i2c_dir_table_template, - THIS_MODULE)) < 0) { - err = i; - goto ERROR7; - } - data->sysctl_id = i; + /* Register a new directory entry with module sensors */ + if ((i = sensors_register_entry(new_client, + type_name, + kind == + w83781d ? + w83781d_dir_table_template : kind + == + w83783s ? + w83783s_dir_table_template : is_isa + ? w83782d_isa_dir_table_template : + w83782d_i2c_dir_table_template, + THIS_MODULE)) < 0) { + err = i; + goto ERROR7; + } + data->sysctl_id = i; - /* Initialize the Winbond chip */ - w83781d_init_client(new_client); - return 0; + /* Initialize the Winbond chip */ + w83781d_init_client(new_client); + return 0; /* OK, this is not exactly good programming practice, usually. But it is very code-efficient in this case. */ -ERROR7: - if (!is_isa) - i2c_detach_client(&(((struct w83781d_data *) (new_client->data))->lm75[1])); -ERROR6: - if (!is_isa) - i2c_detach_client(&(((struct w83781d_data *) (new_client->data))->lm75[0])); -ERROR5: - if (!is_isa) - kfree(((struct w83781d_data *) (new_client->data))->lm75); -ERROR4: - i2c_detach_client(new_client); -ERROR3: - if (is_isa) - release_region(address,W83781D_EXTENT); -ERROR1: - kfree(new_client); -ERROR0: - return err; + ERROR7: + if (!is_isa) + i2c_detach_client(& + (((struct + w83781d_data *) (new_client->data))-> + lm75[1])); + ERROR6: + if (!is_isa) + i2c_detach_client(& + (((struct + w83781d_data *) (new_client->data))-> + lm75[0])); + ERROR5: + if (!is_isa) + kfree(((struct w83781d_data *) (new_client->data))->lm75); + ERROR4: + i2c_detach_client(new_client); + ERROR3: + if (is_isa) + release_region(address, W83781D_EXTENT); + ERROR1: + kfree(new_client); + ERROR0: + return err; } int w83781d_detach_client(struct i2c_client *client) { - int err; + int err; - sensors_deregister_entry(((struct w83781d_data *)(client->data))->sysctl_id); + sensors_deregister_entry(((struct w83781d_data *) (client->data))-> + sysctl_id); - if ((err = i2c_detach_client(client))) { - printk("w83781d.o: Client deregistration failed, client not detached.\n"); - return err; - } + if ((err = i2c_detach_client(client))) { + printk + ("w83781d.o: Client deregistration failed, client not detached.\n"); + return err; + } - if i2c_is_isa_client(client) - release_region(client->addr,W83781D_EXTENT); - else { - i2c_detach_client(&(((struct w83781d_data *) (client->data))->lm75[0])); - i2c_detach_client(&(((struct w83781d_data *) (client->data))->lm75[1])); - kfree(((struct w83781d_data *) (client->data))->lm75); - } - kfree(client); + if i2c_is_isa_client + (client) + release_region(client->addr, W83781D_EXTENT); + else { + i2c_detach_client(& + (((struct + w83781d_data *) (client->data))-> + lm75[0])); + i2c_detach_client(& + (((struct + w83781d_data *) (client->data))-> + lm75[1])); + kfree(((struct w83781d_data *) (client->data))->lm75); + } + kfree(client); - return 0; + return 0; } /* No commands defined yet */ int w83781d_command(struct i2c_client *client, unsigned int cmd, void *arg) { - return 0; + return 0; } -void w83781d_inc_use (struct i2c_client *client) +void w83781d_inc_use(struct i2c_client *client) { #ifdef MODULE - MOD_INC_USE_COUNT; + MOD_INC_USE_COUNT; #endif } -void w83781d_dec_use (struct i2c_client *client) +void w83781d_dec_use(struct i2c_client *client) { #ifdef MODULE - MOD_DEC_USE_COUNT; + MOD_DEC_USE_COUNT; #endif } - + u16 swap_bytes(u16 val) { - return (val >> 8) | (val << 8); + return (val >> 8) | (val << 8); } /* The SMBus locks itself, usually, but nothing may access the Winbond between @@ -946,61 +978,78 @@ u16 swap_bytes(u16 val) nowhere else be necessary! */ int w83781d_read_value(struct i2c_client *client, u16 reg) { - int res,word_sized,bank; - struct i2c_client *cl; + int res, word_sized, bank; + struct i2c_client *cl; - down(& (((struct w83781d_data *) (client->data)) -> lock)); - if (i2c_is_isa_client(client)) { - word_sized = (((reg & 0xff00) == 0x100) || ((reg & 0xff00) == 0x200)) && - (((reg & 0x00ff) == 0x50) || - ((reg & 0x00ff) == 0x53) || - ((reg & 0x00ff) == 0x55)); - if (reg & 0xff00) { - outb_p(W83781D_REG_BANK,client->addr + W83781D_ADDR_REG_OFFSET); - outb_p(reg >> 8,client->addr + W83781D_DATA_REG_OFFSET); - } - outb_p(reg & 0xff,client->addr + W83781D_ADDR_REG_OFFSET); - res = inb_p(client->addr + W83781D_DATA_REG_OFFSET); - if (word_sized) { - outb_p((reg & 0xff)+1,client->addr + W83781D_ADDR_REG_OFFSET); - res = (res << 8) + inb_p(client->addr + W83781D_DATA_REG_OFFSET); - } - if (reg & 0xff00) { - outb_p(W83781D_REG_BANK,client->addr + W83781D_ADDR_REG_OFFSET); - outb_p(0,client->addr + W83781D_DATA_REG_OFFSET); - } - } else { - bank = (reg >> 8) & 0x0f; - if (bank > 2) - /* switch banks */ - i2c_smbus_write_byte_data(client,W83781D_REG_BANK, bank); - if(bank == 0 || bank > 2) { - res = i2c_smbus_read_byte_data(client, reg & 0xff); - } else { - /* switch to subclient */ - cl = &(((struct w83781d_data *) (client->data))->lm75[bank - 1]); - /* convert from ISA to LM75 I2C addresses */ - switch (reg & 0xff) { - case 0x50: - res = swap_bytes(i2c_smbus_read_word_data(cl, 0)); - break; - case 0x52: - res = i2c_smbus_read_byte_data(cl, 1); - break; - case 0x53: - res = swap_bytes(i2c_smbus_read_word_data(cl, 2)); - break; - case 0x55: - default: - res = swap_bytes(i2c_smbus_read_word_data(cl, 3)); - break; - } - } - if (bank > 2) - i2c_smbus_write_byte_data(client,W83781D_REG_BANK,0); - } - up( & (((struct w83781d_data *) (client->data)) -> lock)); - return res; + down(&(((struct w83781d_data *) (client->data))->lock)); + if (i2c_is_isa_client(client)) { + word_sized = (((reg & 0xff00) == 0x100) + || ((reg & 0xff00) == 0x200)) + && (((reg & 0x00ff) == 0x50) + || ((reg & 0x00ff) == 0x53) + || ((reg & 0x00ff) == 0x55)); + if (reg & 0xff00) { + outb_p(W83781D_REG_BANK, + client->addr + W83781D_ADDR_REG_OFFSET); + outb_p(reg >> 8, + client->addr + W83781D_DATA_REG_OFFSET); + } + outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET); + res = inb_p(client->addr + W83781D_DATA_REG_OFFSET); + if (word_sized) { + outb_p((reg & 0xff) + 1, + client->addr + W83781D_ADDR_REG_OFFSET); + res = + (res << 8) + inb_p(client->addr + + W83781D_DATA_REG_OFFSET); + } + if (reg & 0xff00) { + outb_p(W83781D_REG_BANK, + client->addr + W83781D_ADDR_REG_OFFSET); + outb_p(0, client->addr + W83781D_DATA_REG_OFFSET); + } + } else { + bank = (reg >> 8) & 0x0f; + if (bank > 2) + /* switch banks */ + i2c_smbus_write_byte_data(client, W83781D_REG_BANK, + bank); + if (bank == 0 || bank > 2) { + res = i2c_smbus_read_byte_data(client, reg & 0xff); + } else { + /* switch to subclient */ + cl = + &(((struct w83781d_data *) (client->data))-> + lm75[bank - 1]); + /* convert from ISA to LM75 I2C addresses */ + switch (reg & 0xff) { + case 0x50: + res = + swap_bytes(i2c_smbus_read_word_data + (cl, 0)); + break; + case 0x52: + res = i2c_smbus_read_byte_data(cl, 1); + break; + case 0x53: + res = + swap_bytes(i2c_smbus_read_word_data + (cl, 2)); + break; + case 0x55: + default: + res = + swap_bytes(i2c_smbus_read_word_data + (cl, 3)); + break; + } + } + if (bank > 2) + i2c_smbus_write_byte_data(client, W83781D_REG_BANK, + 0); + } + up(&(((struct w83781d_data *) (client->data))->lock)); + return res; } /* The SMBus locks itself, usually, but nothing may access the Winbond between @@ -1011,97 +1060,116 @@ int w83781d_read_value(struct i2c_client *client, u16 reg) nowhere else be necessary! */ int w83781d_write_value(struct i2c_client *client, u16 reg, u16 value) { - int word_sized,bank; - struct i2c_client *cl; + int word_sized, bank; + struct i2c_client *cl; - down( & (((struct w83781d_data *) (client->data)) -> lock)); - if (i2c_is_isa_client(client)) { - word_sized = (((reg & 0xff00) == 0x100) || ((reg & 0xff00) == 0x200)) && - (((reg & 0x00ff) == 0x53) || - ((reg & 0x00ff) == 0x55)); - if (reg & 0xff00) { - outb_p(W83781D_REG_BANK,client->addr + W83781D_ADDR_REG_OFFSET); - outb_p(reg >> 8,client->addr + W83781D_DATA_REG_OFFSET); - } - outb_p(reg & 0xff,client->addr + W83781D_ADDR_REG_OFFSET); - if (word_sized) { - outb_p(value >> 8,client->addr + W83781D_DATA_REG_OFFSET); - outb_p((reg & 0xff)+1,client->addr + W83781D_ADDR_REG_OFFSET); - } - outb_p(value &0xff,client->addr + W83781D_DATA_REG_OFFSET); - if (reg & 0xff00) { - outb_p(W83781D_REG_BANK,client->addr + W83781D_ADDR_REG_OFFSET); - outb_p(0,client->addr + W83781D_DATA_REG_OFFSET); - } - } else { - bank = (reg >> 8) & 0x0f; - if (bank > 2) - /* switch banks */ - i2c_smbus_write_byte_data(client,W83781D_REG_BANK, bank); - if(bank == 0 || bank > 2) { - i2c_smbus_write_byte_data(client, reg & 0xff, value & 0xff); - } else { - /* switch to subclient */ - cl = &(((struct w83781d_data *) (client->data))->lm75[bank - 1]); - /* convert from ISA to LM75 I2C addresses */ - switch (reg & 0xff) { - case 0x52: - i2c_smbus_write_byte_data(cl, 1, value & 0xff); - break; - case 0x53: - i2c_smbus_write_word_data(cl, 2, swap_bytes(value)); - break; - case 0x55: - i2c_smbus_write_word_data(cl, 3, swap_bytes(value)); - break; - } - } - if (bank > 2) - i2c_smbus_write_byte_data(client,W83781D_REG_BANK,0); - } - up( & (((struct w83781d_data *) (client->data)) -> lock)); - return 0; + down(&(((struct w83781d_data *) (client->data))->lock)); + if (i2c_is_isa_client(client)) { + word_sized = (((reg & 0xff00) == 0x100) + || ((reg & 0xff00) == 0x200)) + && (((reg & 0x00ff) == 0x53) + || ((reg & 0x00ff) == 0x55)); + if (reg & 0xff00) { + outb_p(W83781D_REG_BANK, + client->addr + W83781D_ADDR_REG_OFFSET); + outb_p(reg >> 8, + client->addr + W83781D_DATA_REG_OFFSET); + } + outb_p(reg & 0xff, client->addr + W83781D_ADDR_REG_OFFSET); + if (word_sized) { + outb_p(value >> 8, + client->addr + W83781D_DATA_REG_OFFSET); + outb_p((reg & 0xff) + 1, + client->addr + W83781D_ADDR_REG_OFFSET); + } + outb_p(value & 0xff, + client->addr + W83781D_DATA_REG_OFFSET); + if (reg & 0xff00) { + outb_p(W83781D_REG_BANK, + client->addr + W83781D_ADDR_REG_OFFSET); + outb_p(0, client->addr + W83781D_DATA_REG_OFFSET); + } + } else { + bank = (reg >> 8) & 0x0f; + if (bank > 2) + /* switch banks */ + i2c_smbus_write_byte_data(client, W83781D_REG_BANK, + bank); + if (bank == 0 || bank > 2) { + i2c_smbus_write_byte_data(client, reg & 0xff, + value & 0xff); + } else { + /* switch to subclient */ + cl = + &(((struct w83781d_data *) (client->data))-> + lm75[bank - 1]); + /* convert from ISA to LM75 I2C addresses */ + switch (reg & 0xff) { + case 0x52: + i2c_smbus_write_byte_data(cl, 1, + value & 0xff); + break; + case 0x53: + i2c_smbus_write_word_data(cl, 2, + swap_bytes + (value)); + break; + case 0x55: + i2c_smbus_write_word_data(cl, 3, + swap_bytes + (value)); + break; + } + } + if (bank > 2) + i2c_smbus_write_byte_data(client, W83781D_REG_BANK, + 0); + } + up(&(((struct w83781d_data *) (client->data))->lock)); + return 0; } /* Called when we have found a new W83781D. It should set limits, etc. */ void w83781d_init_client(struct i2c_client *client) { - struct w83781d_data *data = client->data; - int vid,i; - int type = data->type; - u8 tmp; + struct w83781d_data *data = client->data; + int vid, i; + int type = data->type; + u8 tmp; - /* Reset all except Watchdog values and last conversion values - This sets fan-divs to 2, among others */ - w83781d_write_value(client,W83781D_REG_CONFIG,0x80); - /* Disable power-on abnormal beep. BIOS should have already turned off but - not all do. Reset value is 0x15, write a 0x95. */ - w83781d_write_value(client,W83781D_REG_BEEP_CONFIG, 0x95); - /* Disable master beep-enable (reset turns it on). - Individual beeps should be reset to off but for some reason - disabling this bit helps some people not get beeped */ - w83781d_write_value(client,W83781D_REG_BEEP_INTS2,0); + /* Reset all except Watchdog values and last conversion values + This sets fan-divs to 2, among others */ + w83781d_write_value(client, W83781D_REG_CONFIG, 0x80); + /* Disable power-on abnormal beep. BIOS should have already turned off but + not all do. Reset value is 0x15, write a 0x95. */ + w83781d_write_value(client, W83781D_REG_BEEP_CONFIG, 0x95); + /* Disable master beep-enable (reset turns it on). + Individual beeps should be reset to off but for some reason + disabling this bit helps some people not get beeped */ + w83781d_write_value(client, W83781D_REG_BEEP_INTS2, 0); - vid = w83781d_read_value(client,W83781D_REG_VID_FANDIV) & 0x0f; - vid |= (w83781d_read_value(client,W83781D_REG_CHIPID) & 0x01) << 4; - vid = VID_FROM_REG(vid); - - if (type != w83781d) { - tmp = w83781d_read_value(client,W83781D_REG_SCFG1); - for (i = 1; i <= 3; i++) { - if(!(tmp & BIT_SCFG1[i-1])) { - data->sens[i-1] = W83781D_DEFAULT_BETA; - } else { - if(w83781d_read_value(client,W83781D_REG_SCFG2) & BIT_SCFG2[i-1]) - data->sens[i-1] = 1; - else - data->sens[i-1] = 2; - } - if((type == w83783s) && (i == 2)) - break; - } - } + vid = w83781d_read_value(client, W83781D_REG_VID_FANDIV) & 0x0f; + vid |= + (w83781d_read_value(client, W83781D_REG_CHIPID) & 0x01) << 4; + vid = VID_FROM_REG(vid); + if (type != w83781d) { + tmp = w83781d_read_value(client, W83781D_REG_SCFG1); + for (i = 1; i <= 3; i++) { + if (!(tmp & BIT_SCFG1[i - 1])) { + data->sens[i - 1] = W83781D_DEFAULT_BETA; + } else { + if (w83781d_read_value + (client, + W83781D_REG_SCFG2) & BIT_SCFG2[i - 1]) + data->sens[i - 1] = 1; + else + data->sens[i - 1] = 2; + } + if ((type == w83783s) && (i == 2)) + break; + } + } #ifdef W83781D_RT /* Fill up the RT Tables. @@ -1111,200 +1179,249 @@ void w83781d_init_client(struct i2c_client *client) that the 782D/783D support it as well.... */ - if(type == w83781d) { - u16 k = 0; + if (type == w83781d) { + u16 k = 0; /* Auto-indexing doesn't seem to work... w83781d_write_value(client,W83781D_REG_RT_IDX,0); */ - for (i = 0; i < 3; i++) { - int j; - for (j = 0; j < 32; j++) { - w83781d_write_value(client,W83781D_REG_RT_IDX,k++); - data->rt[i][j] = w83781d_read_value(client,W83781D_REG_RT_VAL); - } - } - } -#endif /* W83781D_RT */ + for (i = 0; i < 3; i++) { + int j; + for (j = 0; j < 32; j++) { + w83781d_write_value(client, + W83781D_REG_RT_IDX, + k++); + data->rt[i][j] = + w83781d_read_value(client, + W83781D_REG_RT_VAL); + } + } + } +#endif /* W83781D_RT */ - w83781d_write_value(client,W83781D_REG_IN_MIN(0), - IN_TO_REG(W83781D_INIT_IN_MIN_0)); - w83781d_write_value(client,W83781D_REG_IN_MAX(0), - IN_TO_REG(W83781D_INIT_IN_MAX_0)); - if(type != w83783s) { - w83781d_write_value(client,W83781D_REG_IN_MIN(1), - IN_TO_REG(W83781D_INIT_IN_MIN_1)); - w83781d_write_value(client,W83781D_REG_IN_MAX(1), - IN_TO_REG(W83781D_INIT_IN_MAX_1)); - } + w83781d_write_value(client, W83781D_REG_IN_MIN(0), + IN_TO_REG(W83781D_INIT_IN_MIN_0)); + w83781d_write_value(client, W83781D_REG_IN_MAX(0), + IN_TO_REG(W83781D_INIT_IN_MAX_0)); + if (type != w83783s) { + w83781d_write_value(client, W83781D_REG_IN_MIN(1), + IN_TO_REG(W83781D_INIT_IN_MIN_1)); + w83781d_write_value(client, W83781D_REG_IN_MAX(1), + IN_TO_REG(W83781D_INIT_IN_MAX_1)); + } - w83781d_write_value(client,W83781D_REG_IN_MIN(2), - IN_TO_REG(W83781D_INIT_IN_MIN_2)); - w83781d_write_value(client,W83781D_REG_IN_MAX(2), - IN_TO_REG(W83781D_INIT_IN_MAX_2)); - w83781d_write_value(client,W83781D_REG_IN_MIN(3), - IN_TO_REG(W83781D_INIT_IN_MIN_3)); - w83781d_write_value(client,W83781D_REG_IN_MAX(3), - IN_TO_REG(W83781D_INIT_IN_MAX_3)); - w83781d_write_value(client,W83781D_REG_IN_MIN(4), - IN_TO_REG(W83781D_INIT_IN_MIN_4)); - w83781d_write_value(client,W83781D_REG_IN_MAX(4), - IN_TO_REG(W83781D_INIT_IN_MAX_4)); - if (type == w83781d || type == as99127f) { - w83781d_write_value(client,W83781D_REG_IN_MIN(5), - IN_TO_REG(W83781D_INIT_IN_MIN_5)); - w83781d_write_value(client,W83781D_REG_IN_MAX(5), - IN_TO_REG(W83781D_INIT_IN_MAX_5)); - } else { - w83781d_write_value(client,W83781D_REG_IN_MIN(5), - IN_TO_REG(W83782D_INIT_IN_MIN_5)); - w83781d_write_value(client,W83781D_REG_IN_MAX(5), - IN_TO_REG(W83782D_INIT_IN_MAX_5)); - } - if (type == w83781d || type == as99127f) { - w83781d_write_value(client,W83781D_REG_IN_MIN(6), - IN_TO_REG(W83781D_INIT_IN_MIN_6)); - w83781d_write_value(client,W83781D_REG_IN_MAX(6), - IN_TO_REG(W83781D_INIT_IN_MAX_6)); - } else { - w83781d_write_value(client,W83781D_REG_IN_MIN(6), - IN_TO_REG(W83782D_INIT_IN_MIN_6)); - w83781d_write_value(client,W83781D_REG_IN_MAX(6), - IN_TO_REG(W83782D_INIT_IN_MAX_6)); - } - if ((type == w83782d) || (type == w83627hf) || (type == as99127f)) { - w83781d_write_value(client,W83781D_REG_IN_MIN(7), - IN_TO_REG(W83781D_INIT_IN_MIN_7)); - w83781d_write_value(client,W83781D_REG_IN_MAX(7), - IN_TO_REG(W83781D_INIT_IN_MAX_7)); - w83781d_write_value(client,W83781D_REG_IN_MIN(8), - IN_TO_REG(W83781D_INIT_IN_MIN_8)); - w83781d_write_value(client,W83781D_REG_IN_MAX(8), - IN_TO_REG(W83781D_INIT_IN_MAX_8)); - } - w83781d_write_value(client,W83781D_REG_FAN_MIN(1), - FAN_TO_REG(W83781D_INIT_FAN_MIN_1,2)); - w83781d_write_value(client,W83781D_REG_FAN_MIN(2), - FAN_TO_REG(W83781D_INIT_FAN_MIN_2,2)); - w83781d_write_value(client,W83781D_REG_FAN_MIN(3), - FAN_TO_REG(W83781D_INIT_FAN_MIN_3,2)); + w83781d_write_value(client, W83781D_REG_IN_MIN(2), + IN_TO_REG(W83781D_INIT_IN_MIN_2)); + w83781d_write_value(client, W83781D_REG_IN_MAX(2), + IN_TO_REG(W83781D_INIT_IN_MAX_2)); + w83781d_write_value(client, W83781D_REG_IN_MIN(3), + IN_TO_REG(W83781D_INIT_IN_MIN_3)); + w83781d_write_value(client, W83781D_REG_IN_MAX(3), + IN_TO_REG(W83781D_INIT_IN_MAX_3)); + w83781d_write_value(client, W83781D_REG_IN_MIN(4), + IN_TO_REG(W83781D_INIT_IN_MIN_4)); + w83781d_write_value(client, W83781D_REG_IN_MAX(4), + IN_TO_REG(W83781D_INIT_IN_MAX_4)); + if (type == w83781d || type == as99127f) { + w83781d_write_value(client, W83781D_REG_IN_MIN(5), + IN_TO_REG(W83781D_INIT_IN_MIN_5)); + w83781d_write_value(client, W83781D_REG_IN_MAX(5), + IN_TO_REG(W83781D_INIT_IN_MAX_5)); + } else { + w83781d_write_value(client, W83781D_REG_IN_MIN(5), + IN_TO_REG(W83782D_INIT_IN_MIN_5)); + w83781d_write_value(client, W83781D_REG_IN_MAX(5), + IN_TO_REG(W83782D_INIT_IN_MAX_5)); + } + if (type == w83781d || type == as99127f) { + w83781d_write_value(client, W83781D_REG_IN_MIN(6), + IN_TO_REG(W83781D_INIT_IN_MIN_6)); + w83781d_write_value(client, W83781D_REG_IN_MAX(6), + IN_TO_REG(W83781D_INIT_IN_MAX_6)); + } else { + w83781d_write_value(client, W83781D_REG_IN_MIN(6), + IN_TO_REG(W83782D_INIT_IN_MIN_6)); + w83781d_write_value(client, W83781D_REG_IN_MAX(6), + IN_TO_REG(W83782D_INIT_IN_MAX_6)); + } + if ((type == w83782d) || (type == w83627hf) || (type == as99127f)) { + w83781d_write_value(client, W83781D_REG_IN_MIN(7), + IN_TO_REG(W83781D_INIT_IN_MIN_7)); + w83781d_write_value(client, W83781D_REG_IN_MAX(7), + IN_TO_REG(W83781D_INIT_IN_MAX_7)); + w83781d_write_value(client, W83781D_REG_IN_MIN(8), + IN_TO_REG(W83781D_INIT_IN_MIN_8)); + w83781d_write_value(client, W83781D_REG_IN_MAX(8), + IN_TO_REG(W83781D_INIT_IN_MAX_8)); + } + w83781d_write_value(client, W83781D_REG_FAN_MIN(1), + FAN_TO_REG(W83781D_INIT_FAN_MIN_1, 2)); + w83781d_write_value(client, W83781D_REG_FAN_MIN(2), + FAN_TO_REG(W83781D_INIT_FAN_MIN_2, 2)); + w83781d_write_value(client, W83781D_REG_FAN_MIN(3), + FAN_TO_REG(W83781D_INIT_FAN_MIN_3, 2)); - w83781d_write_value(client,W83781D_REG_TEMP_OVER, - TEMP_TO_REG(W83781D_INIT_TEMP_OVER)); - w83781d_write_value(client,W83781D_REG_TEMP_HYST, - TEMP_TO_REG(W83781D_INIT_TEMP_HYST)); + w83781d_write_value(client, W83781D_REG_TEMP_OVER, + TEMP_TO_REG(W83781D_INIT_TEMP_OVER)); + w83781d_write_value(client, W83781D_REG_TEMP_HYST, + TEMP_TO_REG(W83781D_INIT_TEMP_HYST)); - if (type == as99127f) { - w83781d_write_value(client,W83781D_REG_TEMP2_OVER, - AS99127_TEMP_ADD_TO_REG(W83781D_INIT_TEMP2_OVER)); - w83781d_write_value(client,W83781D_REG_TEMP2_HYST, - AS99127_TEMP_ADD_TO_REG(W83781D_INIT_TEMP2_HYST)); - } else { - w83781d_write_value(client,W83781D_REG_TEMP2_OVER, - TEMP_ADD_TO_REG(W83781D_INIT_TEMP2_OVER)); - w83781d_write_value(client,W83781D_REG_TEMP2_HYST, - TEMP_ADD_TO_REG(W83781D_INIT_TEMP2_HYST)); - } - w83781d_write_value(client,W83781D_REG_TEMP2_CONFIG,0x00); + if (type == as99127f) { + w83781d_write_value(client, W83781D_REG_TEMP2_OVER, + AS99127_TEMP_ADD_TO_REG + (W83781D_INIT_TEMP2_OVER)); + w83781d_write_value(client, W83781D_REG_TEMP2_HYST, + AS99127_TEMP_ADD_TO_REG + (W83781D_INIT_TEMP2_HYST)); + } else { + w83781d_write_value(client, W83781D_REG_TEMP2_OVER, + TEMP_ADD_TO_REG + (W83781D_INIT_TEMP2_OVER)); + w83781d_write_value(client, W83781D_REG_TEMP2_HYST, + TEMP_ADD_TO_REG + (W83781D_INIT_TEMP2_HYST)); + } + w83781d_write_value(client, W83781D_REG_TEMP2_CONFIG, 0x00); - if (type == as99127f) { - w83781d_write_value(client,W83781D_REG_TEMP3_OVER, - AS99127_TEMP_ADD_TO_REG(W83781D_INIT_TEMP3_OVER)); - w83781d_write_value(client,W83781D_REG_TEMP3_HYST, - AS99127_TEMP_ADD_TO_REG(W83781D_INIT_TEMP3_HYST)); - } else if (type != w83783s) { - w83781d_write_value(client,W83781D_REG_TEMP3_OVER, - TEMP_ADD_TO_REG(W83781D_INIT_TEMP3_OVER)); - w83781d_write_value(client,W83781D_REG_TEMP3_HYST, - TEMP_ADD_TO_REG(W83781D_INIT_TEMP3_HYST)); - } - if (type != w83783s) { - w83781d_write_value(client,W83781D_REG_TEMP3_CONFIG,0x00); - } + if (type == as99127f) { + w83781d_write_value(client, W83781D_REG_TEMP3_OVER, + AS99127_TEMP_ADD_TO_REG + (W83781D_INIT_TEMP3_OVER)); + w83781d_write_value(client, W83781D_REG_TEMP3_HYST, + AS99127_TEMP_ADD_TO_REG + (W83781D_INIT_TEMP3_HYST)); + } else if (type != w83783s) { + w83781d_write_value(client, W83781D_REG_TEMP3_OVER, + TEMP_ADD_TO_REG + (W83781D_INIT_TEMP3_OVER)); + w83781d_write_value(client, W83781D_REG_TEMP3_HYST, + TEMP_ADD_TO_REG + (W83781D_INIT_TEMP3_HYST)); + } + if (type != w83783s) { + w83781d_write_value(client, W83781D_REG_TEMP3_CONFIG, + 0x00); + } - /* Start monitoring */ - w83781d_write_value(client,W83781D_REG_CONFIG, - (w83781d_read_value(client, - W83781D_REG_CONFIG) & 0xf7) | 0x01); + /* Start monitoring */ + w83781d_write_value(client, W83781D_REG_CONFIG, + (w83781d_read_value(client, + W83781D_REG_CONFIG) & 0xf7) + | 0x01); } void w83781d_update_client(struct i2c_client *client) { - struct w83781d_data *data = client->data; - int i; + struct w83781d_data *data = client->data; + int i; - down(&data->update_lock); + down(&data->update_lock); - if ((jiffies - data->last_updated > HZ+HZ/2 ) || - (jiffies < data->last_updated) || ! data->valid) { + if ((jiffies - data->last_updated > HZ + HZ / 2) || + (jiffies < data->last_updated) || !data->valid) { #ifdef DEBUG - printk("Starting w83781d update\n"); + printk("Starting w83781d update\n"); #endif - for (i = 0; i <= 8; i++) { - if((data->type == w83783s) && (i == 1)) - continue; /* 783S has no in1 */ - data->in[i] = w83781d_read_value(client,W83781D_REG_IN(i)); - data->in_min[i] = w83781d_read_value(client,W83781D_REG_IN_MIN(i)); - data->in_max[i] = w83781d_read_value(client,W83781D_REG_IN_MAX(i)); - if((data->type != w83782d) && (data->type != w83627hf) && - (data->type != as99127f) && (i == 6)) - break; - } - for (i = 1; i <= 3; i++) { - data->fan[i-1] = w83781d_read_value(client,W83781D_REG_FAN(i)); - data->fan_min[i-1] = w83781d_read_value(client,W83781D_REG_FAN_MIN(i)); - } - if(data->type != w83781d) { - for (i = 1; i <= 4; i++) { - data->pwm[i-1] = w83781d_read_value(client,W83781D_REG_PWM(i)); - if(((data->type == w83783s) || - (((data->type == w83782d) || (data->type == w83627hf) || - data->type == as99127f) && i2c_is_isa_client(client))) - && i == 2) - break; - } - } + for (i = 0; i <= 8; i++) { + if ((data->type == w83783s) && (i == 1)) + continue; /* 783S has no in1 */ + data->in[i] = + w83781d_read_value(client, W83781D_REG_IN(i)); + data->in_min[i] = + w83781d_read_value(client, + W83781D_REG_IN_MIN(i)); + data->in_max[i] = + w83781d_read_value(client, + W83781D_REG_IN_MAX(i)); + if ((data->type != w83782d) + && (data->type != w83627hf) + && (data->type != as99127f) && (i == 6)) + break; + } + for (i = 1; i <= 3; i++) { + data->fan[i - 1] = + w83781d_read_value(client, W83781D_REG_FAN(i)); + data->fan_min[i - 1] = + w83781d_read_value(client, + W83781D_REG_FAN_MIN(i)); + } + if (data->type != w83781d) { + for (i = 1; i <= 4; i++) { + data->pwm[i - 1] = + w83781d_read_value(client, + W83781D_REG_PWM(i)); + if ( + ((data->type == w83783s) + || + (((data-> + type == w83782d) + || (data->type == w83627hf) + || data->type == as99127f) + && i2c_is_isa_client(client))) + && i == 2) + break; + } + } - data->temp = w83781d_read_value(client,W83781D_REG_TEMP); - data->temp_over = w83781d_read_value(client,W83781D_REG_TEMP_OVER); - data->temp_hyst = w83781d_read_value(client,W83781D_REG_TEMP_HYST); - data->temp_add[0] = w83781d_read_value(client,W83781D_REG_TEMP2); - data->temp_add_over[0] = w83781d_read_value(client,W83781D_REG_TEMP2_OVER); - data->temp_add_hyst[0] = w83781d_read_value(client,W83781D_REG_TEMP2_HYST); - data->temp_add[1] = w83781d_read_value(client,W83781D_REG_TEMP3); - data->temp_add_over[1] = w83781d_read_value(client,W83781D_REG_TEMP3_OVER); - data->temp_add_hyst[1] = w83781d_read_value(client,W83781D_REG_TEMP3_HYST); - i = w83781d_read_value(client,W83781D_REG_VID_FANDIV); - data->vid = i & 0x0f; - data->vid |= (w83781d_read_value(client,W83781D_REG_CHIPID) & 0x01) << 4; - data->fan_div[0] = (i >> 4) & 0x03; - data->fan_div[1] = (i >> 6) & 0x03; - data->fan_div[2] = (w83781d_read_value(client, - W83781D_REG_PIN) >> 6) & 0x03; - if (data->type != w83781d) { - i = w83781d_read_value(client,W83781D_REG_VBAT); - data->fan_div[0] |= (i >> 3) & 0x04; - data->fan_div[1] |= (i >> 4) & 0x04; - data->fan_div[2] |= (i >> 5) & 0x04; - } - data->alarms = w83781d_read_value(client,W83781D_REG_ALARM1) + - (w83781d_read_value(client,W83781D_REG_ALARM2) << 8); - if ((data->type == w83782d) || (data->type == w83627hf) || data->type == as99127f) { - data->alarms |= w83781d_read_value(client,W83781D_REG_ALARM3) << 16; - } - i = w83781d_read_value(client,W83781D_REG_BEEP_INTS2); - data->beep_enable = i >> 7; - data->beeps = ((i & 0x7f) << 8) + - w83781d_read_value(client,W83781D_REG_BEEP_INTS1); - if (data->type != w83781d) { - data->beeps |= w83781d_read_value(client,W83781D_REG_BEEP_INTS3) << 16; - } - data->last_updated = jiffies; - data->valid = 1; - } + data->temp = w83781d_read_value(client, W83781D_REG_TEMP); + data->temp_over = + w83781d_read_value(client, W83781D_REG_TEMP_OVER); + data->temp_hyst = + w83781d_read_value(client, W83781D_REG_TEMP_HYST); + data->temp_add[0] = + w83781d_read_value(client, W83781D_REG_TEMP2); + data->temp_add_over[0] = + w83781d_read_value(client, W83781D_REG_TEMP2_OVER); + data->temp_add_hyst[0] = + w83781d_read_value(client, W83781D_REG_TEMP2_HYST); + data->temp_add[1] = + w83781d_read_value(client, W83781D_REG_TEMP3); + data->temp_add_over[1] = + w83781d_read_value(client, W83781D_REG_TEMP3_OVER); + data->temp_add_hyst[1] = + w83781d_read_value(client, W83781D_REG_TEMP3_HYST); + i = w83781d_read_value(client, W83781D_REG_VID_FANDIV); + data->vid = i & 0x0f; + data->vid |= + (w83781d_read_value(client, W83781D_REG_CHIPID) & 0x01) + << 4; + data->fan_div[0] = (i >> 4) & 0x03; + data->fan_div[1] = (i >> 6) & 0x03; + data->fan_div[2] = (w83781d_read_value(client, + W83781D_REG_PIN) >> + 6) & 0x03; + if (data->type != w83781d) { + i = w83781d_read_value(client, W83781D_REG_VBAT); + data->fan_div[0] |= (i >> 3) & 0x04; + data->fan_div[1] |= (i >> 4) & 0x04; + data->fan_div[2] |= (i >> 5) & 0x04; + } + data->alarms = + w83781d_read_value(client, + W83781D_REG_ALARM1) + + (w83781d_read_value(client, W83781D_REG_ALARM2) << 8); + if ((data->type == w83782d) || (data->type == w83627hf) + || data->type == as99127f) { + data->alarms |= + w83781d_read_value(client, + W83781D_REG_ALARM3) << 16; + } + i = w83781d_read_value(client, W83781D_REG_BEEP_INTS2); + data->beep_enable = i >> 7; + data->beeps = ((i & 0x7f) << 8) + + w83781d_read_value(client, W83781D_REG_BEEP_INTS1); + if (data->type != w83781d) { + data->beeps |= + w83781d_read_value(client, + W83781D_REG_BEEP_INTS3) << + 16; + } + data->last_updated = jiffies; + data->valid = 1; + } - up(&data->update_lock); + up(&data->update_lock); } @@ -1321,372 +1438,446 @@ void w83781d_update_client(struct i2c_client *client) large enough (by checking the incoming value of *nrels). This is not very good practice, but as long as you put less than about 5 values in results, you can assume it is large enough. */ -void w83781d_in(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void w83781d_in(struct i2c_client *client, int operation, int ctl_name, + int *nrels_mag, long *results) { - struct w83781d_data *data = client->data; - int nr = ctl_name - W83781D_SYSCTL_IN0; + struct w83781d_data *data = client->data; + int nr = ctl_name - W83781D_SYSCTL_IN0; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 2; - else if (operation == SENSORS_PROC_REAL_READ) { - w83781d_update_client(client); - results[0] = IN_FROM_REG(data->in_min[nr]); - results[1] = IN_FROM_REG(data->in_max[nr]); - results[2] = IN_FROM_REG(data->in[nr]); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->in_min[nr] = IN_TO_REG(results[0]); - w83781d_write_value(client,W83781D_REG_IN_MIN(nr),data->in_min[nr]); - } - if (*nrels_mag >= 2) { - data->in_max[nr] = IN_TO_REG(results[1]); - w83781d_write_value(client,W83781D_REG_IN_MAX(nr),data->in_max[nr]); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + w83781d_update_client(client); + results[0] = IN_FROM_REG(data->in_min[nr]); + results[1] = IN_FROM_REG(data->in_max[nr]); + results[2] = IN_FROM_REG(data->in[nr]); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->in_min[nr] = IN_TO_REG(results[0]); + w83781d_write_value(client, W83781D_REG_IN_MIN(nr), + data->in_min[nr]); + } + if (*nrels_mag >= 2) { + data->in_max[nr] = IN_TO_REG(results[1]); + w83781d_write_value(client, W83781D_REG_IN_MAX(nr), + data->in_max[nr]); + } + } } void w83781d_fan(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct w83781d_data *data = client->data; - int nr = ctl_name - W83781D_SYSCTL_FAN1 + 1; + struct w83781d_data *data = client->data; + int nr = ctl_name - W83781D_SYSCTL_FAN1 + 1; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - w83781d_update_client(client); - results[0] = FAN_FROM_REG(data->fan_min[nr-1], - DIV_FROM_REG(data->fan_div[nr-1])); - results[1] = FAN_FROM_REG(data->fan[nr-1], - DIV_FROM_REG(data->fan_div[nr-1])); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->fan_min[nr-1] = FAN_TO_REG(results[0], - DIV_FROM_REG(data->fan_div[nr-1])); - w83781d_write_value(client,W83781D_REG_FAN_MIN(nr),data->fan_min[nr-1]); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + w83781d_update_client(client); + results[0] = FAN_FROM_REG(data->fan_min[nr - 1], + DIV_FROM_REG(data-> + fan_div[nr - 1])); + results[1] = + FAN_FROM_REG(data->fan[nr - 1], + DIV_FROM_REG(data->fan_div[nr - 1])); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->fan_min[nr - 1] = FAN_TO_REG(results[0], + DIV_FROM_REG + (data-> + fan_div[nr - + 1])); + w83781d_write_value(client, + W83781D_REG_FAN_MIN(nr), + data->fan_min[nr - 1]); + } + } } void w83781d_temp(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct w83781d_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 1; - else if (operation == SENSORS_PROC_REAL_READ) { - w83781d_update_client(client); - results[0] = TEMP_FROM_REG(data->temp_over); - results[1] = TEMP_FROM_REG(data->temp_hyst); - results[2] = TEMP_FROM_REG(data->temp); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->temp_over = TEMP_TO_REG(results[0]); - w83781d_write_value(client,W83781D_REG_TEMP_OVER,data->temp_over); - } - if (*nrels_mag >= 2) { - data->temp_hyst = TEMP_TO_REG(results[1]); - w83781d_write_value(client,W83781D_REG_TEMP_HYST,data->temp_hyst); - } - } + struct w83781d_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 1; + else if (operation == SENSORS_PROC_REAL_READ) { + w83781d_update_client(client); + results[0] = TEMP_FROM_REG(data->temp_over); + results[1] = TEMP_FROM_REG(data->temp_hyst); + results[2] = TEMP_FROM_REG(data->temp); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->temp_over = TEMP_TO_REG(results[0]); + w83781d_write_value(client, W83781D_REG_TEMP_OVER, + data->temp_over); + } + if (*nrels_mag >= 2) { + data->temp_hyst = TEMP_TO_REG(results[1]); + w83781d_write_value(client, W83781D_REG_TEMP_HYST, + data->temp_hyst); + } + } } -void w83781d_temp_add(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void w83781d_temp_add(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - struct w83781d_data *data = client->data; - int nr = ctl_name - W83781D_SYSCTL_TEMP2; + struct w83781d_data *data = client->data; + int nr = ctl_name - W83781D_SYSCTL_TEMP2; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 1; - else if (operation == SENSORS_PROC_REAL_READ) { - w83781d_update_client(client); - if(data->type == as99127f) { - results[0] = AS99127_TEMP_ADD_FROM_REG(data->temp_add_over[nr]); - results[1] = AS99127_TEMP_ADD_FROM_REG(data->temp_add_hyst[nr]); - results[2] = AS99127_TEMP_ADD_FROM_REG(data->temp_add[nr]); - } else { - results[0] = TEMP_ADD_FROM_REG(data->temp_add_over[nr]); - results[1] = TEMP_ADD_FROM_REG(data->temp_add_hyst[nr]); - results[2] = TEMP_ADD_FROM_REG(data->temp_add[nr]); - } - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - if(data->type == as99127f) - data->temp_add_over[nr] = AS99127_TEMP_ADD_TO_REG(results[0]); - else - data->temp_add_over[nr] = TEMP_ADD_TO_REG(results[0]); - w83781d_write_value(client, - nr?W83781D_REG_TEMP3_OVER:W83781D_REG_TEMP2_OVER, - data->temp_add_over[nr]); - } - if (*nrels_mag >= 2) { - if(data->type == as99127f) - data->temp_add_hyst[nr] = AS99127_TEMP_ADD_TO_REG(results[1]); - else - data->temp_add_hyst[nr] = TEMP_ADD_TO_REG(results[1]); - w83781d_write_value(client, - nr?W83781D_REG_TEMP3_HYST:W83781D_REG_TEMP2_HYST, - data->temp_add_hyst[nr]); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 1; + else if (operation == SENSORS_PROC_REAL_READ) { + w83781d_update_client(client); + if (data->type == as99127f) { + results[0] = + AS99127_TEMP_ADD_FROM_REG(data-> + temp_add_over[nr]); + results[1] = + AS99127_TEMP_ADD_FROM_REG(data-> + temp_add_hyst[nr]); + results[2] = + AS99127_TEMP_ADD_FROM_REG(data->temp_add[nr]); + } else { + results[0] = + TEMP_ADD_FROM_REG(data->temp_add_over[nr]); + results[1] = + TEMP_ADD_FROM_REG(data->temp_add_hyst[nr]); + results[2] = TEMP_ADD_FROM_REG(data->temp_add[nr]); + } + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + if (data->type == as99127f) + data->temp_add_over[nr] = + AS99127_TEMP_ADD_TO_REG(results[0]); + else + data->temp_add_over[nr] = + TEMP_ADD_TO_REG(results[0]); + w83781d_write_value(client, + nr ? W83781D_REG_TEMP3_OVER : + W83781D_REG_TEMP2_OVER, + data->temp_add_over[nr]); + } + if (*nrels_mag >= 2) { + if (data->type == as99127f) + data->temp_add_hyst[nr] = + AS99127_TEMP_ADD_TO_REG(results[1]); + else + data->temp_add_hyst[nr] = + TEMP_ADD_TO_REG(results[1]); + w83781d_write_value(client, + nr ? W83781D_REG_TEMP3_HYST : + W83781D_REG_TEMP2_HYST, + data->temp_add_hyst[nr]); + } + } } void w83781d_vid(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct w83781d_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 2; - else if (operation == SENSORS_PROC_REAL_READ) { - w83781d_update_client(client); - results[0] = VID_FROM_REG(data->vid); - *nrels_mag = 1; - } + struct w83781d_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 2; + else if (operation == SENSORS_PROC_REAL_READ) { + w83781d_update_client(client); + results[0] = VID_FROM_REG(data->vid); + *nrels_mag = 1; + } } void w83781d_alarms(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct w83781d_data *data = client->data; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - w83781d_update_client(client); - results[0] = ALARMS_FROM_REG(data->alarms); - *nrels_mag = 1; - } + struct w83781d_data *data = client->data; + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + w83781d_update_client(client); + results[0] = ALARMS_FROM_REG(data->alarms); + *nrels_mag = 1; + } } void w83781d_beep(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct w83781d_data *data = client->data; - int val; + struct w83781d_data *data = client->data; + int val; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - w83781d_update_client(client); - results[0] = BEEP_ENABLE_FROM_REG(data->beep_enable); - results[1] = BEEPS_FROM_REG(data->beeps); - *nrels_mag = 2; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 2) { - data->beeps = BEEPS_TO_REG(results[1]); - w83781d_write_value(client,W83781D_REG_BEEP_INTS1,data->beeps & 0xff); - if(data->type != w83781d) - { - w83781d_write_value(client,W83781D_REG_BEEP_INTS3, - ((data->beeps) >> 16) & 0xff); - } - val = data->beeps >> 8; - } else if (*nrels_mag >= 1) - val = w83781d_read_value(client,W83781D_REG_BEEP_INTS1) & 0x7f; - if (*nrels_mag >= 1) { - data->beep_enable = BEEP_ENABLE_TO_REG(results[0]); - w83781d_write_value(client,W83781D_REG_BEEP_INTS2, - val | data->beep_enable << 7); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + w83781d_update_client(client); + results[0] = BEEP_ENABLE_FROM_REG(data->beep_enable); + results[1] = BEEPS_FROM_REG(data->beeps); + *nrels_mag = 2; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 2) { + data->beeps = BEEPS_TO_REG(results[1]); + w83781d_write_value(client, W83781D_REG_BEEP_INTS1, + data->beeps & 0xff); + if (data->type != w83781d) { + w83781d_write_value(client, + W83781D_REG_BEEP_INTS3, + ((data-> + beeps) >> 16) & + 0xff); + } + val = data->beeps >> 8; + } else if (*nrels_mag >= 1) + val = + w83781d_read_value(client, + W83781D_REG_BEEP_INTS1) & + 0x7f; + if (*nrels_mag >= 1) { + data->beep_enable = BEEP_ENABLE_TO_REG(results[0]); + w83781d_write_value(client, W83781D_REG_BEEP_INTS2, + val | data->beep_enable << 7); + } + } } -void w83781d_fan_div(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) +void w83781d_fan_div(struct i2c_client *client, int operation, + int ctl_name, int *nrels_mag, long *results) { - struct w83781d_data *data = client->data; - int old,old2,old3=0; + struct w83781d_data *data = client->data; + int old, old2, old3 = 0; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - w83781d_update_client(client); - results[0] = DIV_FROM_REG(data->fan_div[0]); - results[1] = DIV_FROM_REG(data->fan_div[1]); - results[2] = DIV_FROM_REG(data->fan_div[2]); - *nrels_mag = 3; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - old = w83781d_read_value(client,W83781D_REG_VID_FANDIV); - if(data->type != w83781d) - { - old3 = w83781d_read_value(client,W83781D_REG_VBAT); - } - if (*nrels_mag >= 3) { - data->fan_div[2] = DIV_TO_REG(results[2], data->type); - old2 = w83781d_read_value(client,W83781D_REG_PIN); - old2 = (old2 & 0x3f) | ((data->fan_div[2] & 0x03) << 6); - w83781d_write_value(client,W83781D_REG_PIN,old2); - if(data->type != w83781d) - { - old3 = (old3 & 0x7f) | ((data->fan_div[2] & 0x04) << 5); - } - } - if (*nrels_mag >= 2) { - data->fan_div[1] = DIV_TO_REG(results[1], data->type); - old = (old & 0x3f) | ((data->fan_div[1] & 0x03) << 6); - if(data->type != w83781d) - { - old3 = (old3 & 0xbf) | ((data->fan_div[1] & 0x04) << 4); - } - } - if (*nrels_mag >= 1) { - data->fan_div[0] = DIV_TO_REG(results[0], data->type); - old = (old & 0xcf) | ((data->fan_div[0] & 0x03) << 4); - w83781d_write_value(client,W83781D_REG_VID_FANDIV,old); - if(data->type != w83781d) - { - old3 = (old3 & 0xdf) | ((data->fan_div[0] & 0x04) << 3); - w83781d_write_value(client,W83781D_REG_VBAT,old3); - } - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + w83781d_update_client(client); + results[0] = DIV_FROM_REG(data->fan_div[0]); + results[1] = DIV_FROM_REG(data->fan_div[1]); + results[2] = DIV_FROM_REG(data->fan_div[2]); + *nrels_mag = 3; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + old = w83781d_read_value(client, W83781D_REG_VID_FANDIV); + if (data->type != w83781d) { + old3 = + w83781d_read_value(client, W83781D_REG_VBAT); + } + if (*nrels_mag >= 3) { + data->fan_div[2] = + DIV_TO_REG(results[2], data->type); + old2 = w83781d_read_value(client, W83781D_REG_PIN); + old2 = + (old2 & 0x3f) | ((data->fan_div[2] & 0x03) << + 6); + w83781d_write_value(client, W83781D_REG_PIN, old2); + if (data->type != w83781d) { + old3 = + (old3 & 0x7f) | + ((data->fan_div[2] & 0x04) << 5); + } + } + if (*nrels_mag >= 2) { + data->fan_div[1] = + DIV_TO_REG(results[1], data->type); + old = + (old & 0x3f) | ((data->fan_div[1] & 0x03) << + 6); + if (data->type != w83781d) { + old3 = + (old3 & 0xbf) | + ((data->fan_div[1] & 0x04) << 4); + } + } + if (*nrels_mag >= 1) { + data->fan_div[0] = + DIV_TO_REG(results[0], data->type); + old = + (old & 0xcf) | ((data->fan_div[0] & 0x03) << + 4); + w83781d_write_value(client, W83781D_REG_VID_FANDIV, + old); + if (data->type != w83781d) { + old3 = + (old3 & 0xdf) | + ((data->fan_div[0] & 0x04) << 3); + w83781d_write_value(client, + W83781D_REG_VBAT, + old3); + } + } + } } void w83781d_pwm(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct w83781d_data *data = client->data; - int nr = 1 + ctl_name - W83781D_SYSCTL_PWM1; + struct w83781d_data *data = client->data; + int nr = 1 + ctl_name - W83781D_SYSCTL_PWM1; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - w83781d_update_client(client); - results[0] = PWM_FROM_REG(data->pwm[nr-1]); - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - data->pwm[nr-1] = PWM_TO_REG(results[0]); - w83781d_write_value(client,W83781D_REG_PWM(nr),data->pwm[nr-1]); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + w83781d_update_client(client); + results[0] = PWM_FROM_REG(data->pwm[nr - 1]); + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + data->pwm[nr - 1] = PWM_TO_REG(results[0]); + w83781d_write_value(client, W83781D_REG_PWM(nr), + data->pwm[nr - 1]); + } + } } void w83781d_sens(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct w83781d_data *data = client->data; - int nr = 1 + ctl_name - W83781D_SYSCTL_SENS1; - u8 tmp; + struct w83781d_data *data = client->data; + int nr = 1 + ctl_name - W83781D_SYSCTL_SENS1; + u8 tmp; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - results[0] = data->sens[nr-1]; - *nrels_mag = 1; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if (*nrels_mag >= 1) { - switch(results[0]) { - case 1: /* PII/Celeron diode */ - tmp = w83781d_read_value(client,W83781D_REG_SCFG1); - w83781d_write_value(client,W83781D_REG_SCFG1, tmp | BIT_SCFG1[nr-1]); - tmp = w83781d_read_value(client,W83781D_REG_SCFG2); - w83781d_write_value(client,W83781D_REG_SCFG2, tmp | BIT_SCFG2[nr-1]); - data->sens[nr-1] = results[0]; - break; - case 2: /* 3904 */ - tmp = w83781d_read_value(client,W83781D_REG_SCFG1); - w83781d_write_value(client,W83781D_REG_SCFG1, tmp | BIT_SCFG1[nr-1]); - tmp = w83781d_read_value(client,W83781D_REG_SCFG2); - w83781d_write_value(client,W83781D_REG_SCFG2, - tmp & ~BIT_SCFG2[nr-1]); - data->sens[nr-1] = results[0]; - break; - case W83781D_DEFAULT_BETA: /* thermistor */ - tmp = w83781d_read_value(client,W83781D_REG_SCFG1); - w83781d_write_value(client,W83781D_REG_SCFG1, - tmp & ~BIT_SCFG1[nr-1]); - data->sens[nr-1] = results[0]; - break; - default: - printk("w83781d.o: Invalid sensor type %ld; must be 1, 2, or %d\n", - results[0], W83781D_DEFAULT_BETA); - break; - } - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + results[0] = data->sens[nr - 1]; + *nrels_mag = 1; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag >= 1) { + switch (results[0]) { + case 1: /* PII/Celeron diode */ + tmp = + w83781d_read_value(client, + W83781D_REG_SCFG1); + w83781d_write_value(client, + W83781D_REG_SCFG1, + tmp | BIT_SCFG1[nr - + 1]); + tmp = + w83781d_read_value(client, + W83781D_REG_SCFG2); + w83781d_write_value(client, + W83781D_REG_SCFG2, + tmp | BIT_SCFG2[nr - + 1]); + data->sens[nr - 1] = results[0]; + break; + case 2: /* 3904 */ + tmp = + w83781d_read_value(client, + W83781D_REG_SCFG1); + w83781d_write_value(client, + W83781D_REG_SCFG1, + tmp | BIT_SCFG1[nr - + 1]); + tmp = + w83781d_read_value(client, + W83781D_REG_SCFG2); + w83781d_write_value(client, + W83781D_REG_SCFG2, + tmp & ~BIT_SCFG2[nr - + 1]); + data->sens[nr - 1] = results[0]; + break; + case W83781D_DEFAULT_BETA: /* thermistor */ + tmp = + w83781d_read_value(client, + W83781D_REG_SCFG1); + w83781d_write_value(client, + W83781D_REG_SCFG1, + tmp & ~BIT_SCFG1[nr - + 1]); + data->sens[nr - 1] = results[0]; + break; + default: + printk + ("w83781d.o: Invalid sensor type %ld; must be 1, 2, or %d\n", + results[0], W83781D_DEFAULT_BETA); + break; + } + } + } } #ifdef W83781D_RT void w83781d_rt(struct i2c_client *client, int operation, int ctl_name, - int *nrels_mag, long *results) + int *nrels_mag, long *results) { - struct w83781d_data *data = client->data; - int nr = 1 + ctl_name - W83781D_SYSCTL_RT1; - int i; + struct w83781d_data *data = client->data; + int nr = 1 + ctl_name - W83781D_SYSCTL_RT1; + int i; - if (operation == SENSORS_PROC_REAL_INFO) - *nrels_mag = 0; - else if (operation == SENSORS_PROC_REAL_READ) { - for(i = 0; i < 32; i++) { - results[i] = data->rt[nr-1][i]; - } - *nrels_mag = 32; - } else if (operation == SENSORS_PROC_REAL_WRITE) { - if(*nrels_mag > 32) *nrels_mag = 32; - for(i = 0; i < *nrels_mag; i++) { - /* fixme: no bounds checking 0-255 */ - data->rt[nr-1][i] = results[i]; - w83781d_write_value(client,W83781D_REG_RT_IDX,i); - w83781d_write_value(client,W83781D_REG_RT_VAL,data->rt[nr-1][i]); - } - } + if (operation == SENSORS_PROC_REAL_INFO) + *nrels_mag = 0; + else if (operation == SENSORS_PROC_REAL_READ) { + for (i = 0; i < 32; i++) { + results[i] = data->rt[nr - 1][i]; + } + *nrels_mag = 32; + } else if (operation == SENSORS_PROC_REAL_WRITE) { + if (*nrels_mag > 32) + *nrels_mag = 32; + for (i = 0; i < *nrels_mag; i++) { + /* fixme: no bounds checking 0-255 */ + data->rt[nr - 1][i] = results[i]; + w83781d_write_value(client, W83781D_REG_RT_IDX, i); + w83781d_write_value(client, W83781D_REG_RT_VAL, + data->rt[nr - 1][i]); + } + } } #endif int __init sensors_w83781d_init(void) { - int res; + int res; - printk("w83781d.o version %s (%s)\n",LM_VERSION,LM_DATE); - w83781d_initialized = 0; + printk("w83781d.o version %s (%s)\n", LM_VERSION, LM_DATE); + w83781d_initialized = 0; - if ((res =i2c_add_driver(&w83781d_driver))) { - printk("w83781d.o: Driver registration failed, module not inserted.\n"); - w83781d_cleanup(); - return res; - } - w83781d_initialized ++; - return 0; + if ((res = i2c_add_driver(&w83781d_driver))) { + printk + ("w83781d.o: Driver registration failed, module not inserted.\n"); + w83781d_cleanup(); + return res; + } + w83781d_initialized++; + return 0; } int __init w83781d_cleanup(void) { - int res; + int res; - if (w83781d_initialized >= 1) { - if ((res = i2c_del_driver(&w83781d_driver))) { - printk("w83781d.o: Driver deregistration failed, module not removed.\n"); - return res; - } - w83781d_initialized --; - } - return 0; + if (w83781d_initialized >= 1) { + if ((res = i2c_del_driver(&w83781d_driver))) { + printk + ("w83781d.o: Driver deregistration failed, module not removed.\n"); + return res; + } + w83781d_initialized--; + } + return 0; } EXPORT_NO_SYMBOLS; #ifdef MODULE -MODULE_AUTHOR("Frodo Looijaard , Philip Edelbrock , and Mark Studebaker "); +MODULE_AUTHOR("Frodo Looijaard , " + "Philip Edelbrock , " + "and Mark Studebaker "); MODULE_DESCRIPTION("W83781D driver"); int init_module(void) { - return sensors_w83781d_init(); + return sensors_w83781d_init(); } int cleanup_module(void) { - return w83781d_cleanup(); + return w83781d_cleanup(); } -#endif /* MODULE */ - +#endif /* MODULE */ diff --git a/kernel/include/i2c-isa.h b/kernel/include/i2c-isa.h index bf64c4e4..70c4c304 100644 --- a/kernel/include/i2c-isa.h +++ b/kernel/include/i2c-isa.h @@ -24,7 +24,7 @@ #ifdef __KERNEL__ -#include +#include /* Detect whether we are on the isa bus. If this returns true, all i2c access will fail! */ @@ -33,6 +33,6 @@ #define i2c_is_isa_adapter(adapptr) \ ((adapptr)->algo->id == I2C_ALGO_ISA) -#endif /* def __KERNEL__ */ +#endif /* def __KERNEL__ */ -#endif /* ndef SENSORS_ISA_H */ +#endif /* ndef SENSORS_ISA_H */ diff --git a/kernel/include/sensors.h b/kernel/include/sensors.h index 0add55d8..6d6b8c4d 100644 --- a/kernel/include/sensors.h +++ b/kernel/include/sensors.h @@ -29,9 +29,9 @@ #include /* The type of callback functions used in sensors_{proc,sysctl}_real */ -typedef void (*sensors_real_callback) (struct i2c_client *client, - int operation, int ctl_name, - int *nrels_mag, long *results); +typedef void (*sensors_real_callback) (struct i2c_client * client, + int operation, int ctl_name, + int *nrels_mag, long *results); /* Values for the operation field in the above function type */ #define SENSORS_PROC_REAL_INFO 1 @@ -55,11 +55,12 @@ typedef void (*sensors_real_callback) (struct i2c_client *client, found. In all cases, client points to the client we wish to interact with, and ctl_name is the SYSCTL id of the file we are accessing. */ -extern int sensors_sysctl_real (ctl_table *table, int *name, int nlen, - void *oldval, size_t *oldlenp, void *newval, - size_t newlen, void **context); -extern int sensors_proc_real(ctl_table *ctl, int write, struct file * filp, - void *buffer, size_t *lenp); +extern int sensors_sysctl_real(ctl_table * table, int *name, int nlen, + void *oldval, size_t * oldlenp, + void *newval, size_t newlen, + void **context); +extern int sensors_proc_real(ctl_table * ctl, int write, struct file *filp, + void *buffer, size_t * lenp); @@ -70,10 +71,10 @@ extern int sensors_proc_real(ctl_table *ctl, int write, struct file * filp, copied in memory. The extra2 field of each file is set to point to client. If any driver wants subdirectories within the newly created directory, these functions must be updated! */ -extern int sensors_register_entry(struct i2c_client *client , - const char *prefix, - ctl_table *ctl_template, - struct module *controlling_mod); +extern int sensors_register_entry(struct i2c_client *client, + const char *prefix, + ctl_table * ctl_template, + struct module *controlling_mod); extern void sensors_deregister_entry(int id); @@ -91,8 +92,8 @@ extern void sensors_deregister_entry(int id); kind: The kind of chip. 0 equals any chip. */ struct sensors_force_data { - unsigned short *force; - unsigned short kind; + unsigned short *force; + unsigned short kind; }; /* A structure containing the detect information. @@ -135,15 +136,15 @@ struct sensors_force_data { the force field is NULL. */ struct sensors_address_data { - unsigned short *normal_i2c; - unsigned short *normal_i2c_range; - unsigned int *normal_isa; - unsigned int *normal_isa_range; - unsigned short *probe; - unsigned short *probe_range; - unsigned short *ignore; - unsigned short *ignore_range; - struct sensors_force_data *forces; + unsigned short *normal_i2c; + unsigned short *normal_i2c_range; + unsigned int *normal_isa; + unsigned int *normal_isa_range; + unsigned short *probe; + unsigned short *probe_range; + unsigned short *ignore; + unsigned short *ignore_range; + struct sensors_force_data *forces; }; /* Internal numbers to terminate lists */ @@ -194,7 +195,7 @@ struct sensors_address_data { SENSORS_MODULE_PARM(force_ ## name, \ "List of adapter,address pairs which are unquestionably" \ " assumed to contain a `" # name "' chip") - + /* This defines several insmod variables, and the addr_data structure */ #define SENSORS_INSMOD \ @@ -323,32 +324,32 @@ struct sensors_address_data { {NULL}}; \ SENSORS_INSMOD -typedef int sensors_found_addr_proc (struct i2c_adapter *adapter, - int addr, unsigned short flags, - int kind); +typedef int sensors_found_addr_proc(struct i2c_adapter *adapter, + int addr, unsigned short flags, + int kind); /* Detect function. It itterates over all possible addresses itself. For SMBus addresses, it will only call found_proc if some client is connected to the SMBus (unless a 'force' matched); for ISA detections, this is not done. */ extern int sensors_detect(struct i2c_adapter *adapter, - struct sensors_address_data *address_data, - sensors_found_addr_proc *found_proc); + struct sensors_address_data *address_data, + sensors_found_addr_proc * found_proc); /* This macro is used to scale user-input to sensible values in almost all chip drivers. */ extern inline int SENSORS_LIMIT(long value, long low, long high) { - if (value < low) - return low; - else if (value > high) - return high; - else - return value; + if (value < low) + return low; + else if (value > high) + return high; + else + return value; } -#endif /* def __KERNEL__ */ +#endif /* def __KERNEL__ */ /* The maximum length of the prefix */ @@ -376,31 +377,31 @@ extern inline int SENSORS_LIMIT(long value, long low, long high) /* Sysctl IDs */ #ifdef DEV_HWMON #define DEV_SENSORS DEV_HWMON -#else /* ndef DEV_HWMOM */ -#define DEV_SENSORS 2 /* The id of the lm_sensors directory within the - dev table */ -#endif /* def DEV_HWMON */ +#else /* ndef DEV_HWMOM */ +#define DEV_SENSORS 2 /* The id of the lm_sensors directory within the + dev table */ +#endif /* def DEV_HWMON */ #define SENSORS_CHIPS 1 struct sensors_chips_data { - int sysctl_id; - char name[SENSORS_PREFIX_MAX + 13]; + int sysctl_id; + char name[SENSORS_PREFIX_MAX + 13]; }; -#define LM78_SYSCTL_IN0 1000 /* Volts * 100 */ +#define LM78_SYSCTL_IN0 1000 /* Volts * 100 */ #define LM78_SYSCTL_IN1 1001 #define LM78_SYSCTL_IN2 1002 #define LM78_SYSCTL_IN3 1003 #define LM78_SYSCTL_IN4 1004 #define LM78_SYSCTL_IN5 1005 #define LM78_SYSCTL_IN6 1006 -#define LM78_SYSCTL_FAN1 1101 /* Rotations/min */ +#define LM78_SYSCTL_FAN1 1101 /* Rotations/min */ #define LM78_SYSCTL_FAN2 1102 #define LM78_SYSCTL_FAN3 1103 -#define LM78_SYSCTL_TEMP 1200 /* Degrees Celcius * 10 */ -#define LM78_SYSCTL_VID 1300 /* Volts * 100 */ -#define LM78_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ -#define LM78_SYSCTL_ALARMS 2001 /* bitvector */ +#define LM78_SYSCTL_TEMP 1200 /* Degrees Celcius * 10 */ +#define LM78_SYSCTL_VID 1300 /* Volts * 100 */ +#define LM78_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ +#define LM78_SYSCTL_ALARMS 2001 /* bitvector */ #define LM78_ALARM_IN0 0x0001 #define LM78_ALARM_IN1 0x0002 @@ -418,7 +419,7 @@ struct sensors_chips_data { #define LM78_ALARM_FIFO 0x2000 #define LM78_ALARM_SMI_IN 0x4000 -#define W83781D_SYSCTL_IN0 1000 /* Volts * 100 */ +#define W83781D_SYSCTL_IN0 1000 /* Volts * 100 */ #define W83781D_SYSCTL_IN1 1001 #define W83781D_SYSCTL_IN2 1002 #define W83781D_SYSCTL_IN3 1003 @@ -427,26 +428,26 @@ struct sensors_chips_data { #define W83781D_SYSCTL_IN6 1006 #define W83781D_SYSCTL_IN7 1007 #define W83781D_SYSCTL_IN8 1008 -#define W83781D_SYSCTL_FAN1 1101 /* Rotations/min */ +#define W83781D_SYSCTL_FAN1 1101 /* Rotations/min */ #define W83781D_SYSCTL_FAN2 1102 #define W83781D_SYSCTL_FAN3 1103 -#define W83781D_SYSCTL_TEMP1 1200 /* Degrees Celcius * 10 */ -#define W83781D_SYSCTL_TEMP2 1201 /* Degrees Celcius * 10 */ -#define W83781D_SYSCTL_TEMP3 1202 /* Degrees Celcius * 10 */ -#define W83781D_SYSCTL_VID 1300 /* Volts * 100 */ +#define W83781D_SYSCTL_TEMP1 1200 /* Degrees Celcius * 10 */ +#define W83781D_SYSCTL_TEMP2 1201 /* Degrees Celcius * 10 */ +#define W83781D_SYSCTL_TEMP3 1202 /* Degrees Celcius * 10 */ +#define W83781D_SYSCTL_VID 1300 /* Volts * 100 */ #define W83781D_SYSCTL_PWM1 1401 #define W83781D_SYSCTL_PWM2 1402 #define W83781D_SYSCTL_PWM3 1403 #define W83781D_SYSCTL_PWM4 1404 -#define W83781D_SYSCTL_SENS1 1501 /* 1, 2, or Beta (3000-5000) */ +#define W83781D_SYSCTL_SENS1 1501 /* 1, 2, or Beta (3000-5000) */ #define W83781D_SYSCTL_SENS2 1502 #define W83781D_SYSCTL_SENS3 1503 -#define W83781D_SYSCTL_RT1 1601 /* 32-entry table */ -#define W83781D_SYSCTL_RT2 1602 /* 32-entry table */ -#define W83781D_SYSCTL_RT3 1603 /* 32-entry table */ -#define W83781D_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ -#define W83781D_SYSCTL_ALARMS 2001 /* bitvector */ -#define W83781D_SYSCTL_BEEP 2002 /* bitvector */ +#define W83781D_SYSCTL_RT1 1601 /* 32-entry table */ +#define W83781D_SYSCTL_RT2 1602 /* 32-entry table */ +#define W83781D_SYSCTL_RT3 1603 /* 32-entry table */ +#define W83781D_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ +#define W83781D_SYSCTL_ALARMS 2001 /* bitvector */ +#define W83781D_SYSCTL_BEEP 2002 /* bitvector */ #define W83781D_ALARM_IN0 0x0001 #define W83781D_ALARM_IN1 0x0002 @@ -461,17 +462,17 @@ struct sensors_chips_data { #define W83781D_ALARM_FAN2 0x0080 #define W83781D_ALARM_FAN3 0x0800 #define W83781D_ALARM_TEMP1 0x0010 -#define W83781D_ALARM_TEMP23 0x0020 /* 781D only */ -#define W83781D_ALARM_TEMP2 0x0020 /* 782D/783S */ -#define W83781D_ALARM_TEMP3 0x2000 /* 782D only */ +#define W83781D_ALARM_TEMP23 0x0020 /* 781D only */ +#define W83781D_ALARM_TEMP2 0x0020 /* 782D/783S */ +#define W83781D_ALARM_TEMP3 0x2000 /* 782D only */ #define W83781D_ALARM_CHAS 0x1000 -#define LM75_SYSCTL_TEMP 1200 /* Degrees Celcius * 10 */ +#define LM75_SYSCTL_TEMP 1200 /* Degrees Celcius * 10 */ -#define ADM1021_SYSCTL_TEMP 1200 +#define ADM1021_SYSCTL_TEMP 1200 #define ADM1021_SYSCTL_REMOTE_TEMP 1201 -#define ADM1021_SYSCTL_DIE_CODE 1202 -#define ADM1021_SYSCTL_ALARMS 1203 +#define ADM1021_SYSCTL_DIE_CODE 1202 +#define ADM1021_SYSCTL_ALARMS 1203 #define ADM1021_ALARM_TEMP_HIGH 0x40 #define ADM1021_ALARM_TEMP_LOW 0x20 @@ -479,16 +480,16 @@ struct sensors_chips_data { #define ADM1021_ALARM_RTEMP_LOW 0x08 #define ADM1021_ALARM_RTEMP_NA 0x04 -#define GL518_SYSCTL_VDD 1000 /* Volts * 100 */ +#define GL518_SYSCTL_VDD 1000 /* Volts * 100 */ #define GL518_SYSCTL_VIN1 1001 #define GL518_SYSCTL_VIN2 1002 #define GL518_SYSCTL_VIN3 1003 -#define GL518_SYSCTL_FAN1 1101 /* RPM */ +#define GL518_SYSCTL_FAN1 1101 /* RPM */ #define GL518_SYSCTL_FAN2 1102 -#define GL518_SYSCTL_TEMP 1200 /* Degrees Celcius * 10 */ -#define GL518_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ -#define GL518_SYSCTL_ALARMS 2001 /* bitvector */ -#define GL518_SYSCTL_BEEP 2002 /* bitvector */ +#define GL518_SYSCTL_TEMP 1200 /* Degrees Celcius * 10 */ +#define GL518_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ +#define GL518_SYSCTL_ALARMS 2001 /* bitvector */ +#define GL518_SYSCTL_BEEP 2002 /* bitvector */ #define GL518_SYSCTL_FAN1OFF 2003 #define GL518_SYSCTL_ITERATE 2004 @@ -500,19 +501,19 @@ struct sensors_chips_data { #define GL518_ALARM_FAN1 0x20 #define GL518_ALARM_FAN2 0x40 -#define GL520_SYSCTL_VDD 1000 /* Volts * 100 */ +#define GL520_SYSCTL_VDD 1000 /* Volts * 100 */ #define GL520_SYSCTL_VIN1 1001 #define GL520_SYSCTL_VIN2 1002 #define GL520_SYSCTL_VIN3 1003 #define GL520_SYSCTL_VIN4 1004 -#define GL520_SYSCTL_FAN1 1101 /* RPM */ +#define GL520_SYSCTL_FAN1 1101 /* RPM */ #define GL520_SYSCTL_FAN2 1102 -#define GL520_SYSCTL_TEMP1 1200 /* Degrees Celcius * 10 */ -#define GL520_SYSCTL_TEMP2 1201 /* Degrees Celcius * 10 */ -#define GL520_SYSCTL_VID 1300 -#define GL520_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ -#define GL520_SYSCTL_ALARMS 2001 /* bitvector */ -#define GL520_SYSCTL_BEEP 2002 /* bitvector */ +#define GL520_SYSCTL_TEMP1 1200 /* Degrees Celcius * 10 */ +#define GL520_SYSCTL_TEMP2 1201 /* Degrees Celcius * 10 */ +#define GL520_SYSCTL_VID 1300 +#define GL520_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ +#define GL520_SYSCTL_ALARMS 2001 /* bitvector */ +#define GL520_SYSCTL_BEEP 2002 /* bitvector */ #define GL520_SYSCTL_FAN1OFF 2003 #define GL520_SYSCTL_CONFIG 2004 @@ -535,30 +536,30 @@ struct sensors_chips_data { #define EEPROM_SYSCTL7 1006 #define EEPROM_SYSCTL8 1007 -#define LM80_SYSCTL_IN0 1000 /* Volts * 100 */ +#define LM80_SYSCTL_IN0 1000 /* Volts * 100 */ #define LM80_SYSCTL_IN1 1001 #define LM80_SYSCTL_IN2 1002 #define LM80_SYSCTL_IN3 1003 #define LM80_SYSCTL_IN4 1004 #define LM80_SYSCTL_IN5 1005 #define LM80_SYSCTL_IN6 1006 -#define LM80_SYSCTL_FAN1 1101 /* Rotations/min */ +#define LM80_SYSCTL_FAN1 1101 /* Rotations/min */ #define LM80_SYSCTL_FAN2 1102 -#define LM80_SYSCTL_TEMP 1250 /* Degrees Celcius * 100 */ -#define LM80_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ -#define LM80_SYSCTL_ALARMS 2001 /* bitvector */ +#define LM80_SYSCTL_TEMP 1250 /* Degrees Celcius * 100 */ +#define LM80_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ +#define LM80_SYSCTL_ALARMS 2001 /* bitvector */ -#define ADM9240_SYSCTL_IN0 1000 /* Volts * 100 */ +#define ADM9240_SYSCTL_IN0 1000 /* Volts * 100 */ #define ADM9240_SYSCTL_IN1 1001 #define ADM9240_SYSCTL_IN2 1002 #define ADM9240_SYSCTL_IN3 1003 #define ADM9240_SYSCTL_IN4 1004 #define ADM9240_SYSCTL_IN5 1005 -#define ADM9240_SYSCTL_FAN1 1101 /* Rotations/min */ +#define ADM9240_SYSCTL_FAN1 1101 /* Rotations/min */ #define ADM9240_SYSCTL_FAN2 1102 -#define ADM9240_SYSCTL_TEMP 1250 /* Degrees Celcius * 100 */ -#define ADM9240_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ -#define ADM9240_SYSCTL_ALARMS 2001 /* bitvector */ +#define ADM9240_SYSCTL_TEMP 1250 /* Degrees Celcius * 100 */ +#define ADM9240_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ +#define ADM9240_SYSCTL_ALARMS 2001 /* bitvector */ #define ADM9240_SYSCTL_ANALOG_OUT 2002 #define ADM9240_SYSCTL_VID 2003 @@ -591,20 +592,20 @@ struct sensors_chips_data { #define LM80_ALARM_BTI 0x0200 #define LM80_ALARM_INT_IN 0x0080 -#define MAXI_SYSCTL_FAN1 1101 /* Rotations/min */ -#define MAXI_SYSCTL_FAN2 1102 /* Rotations/min */ -#define MAXI_SYSCTL_FAN3 1103 /* Rotations/min */ -#define MAXI_SYSCTL_TEMP1 1201 /* Degrees Celcius */ -#define MAXI_SYSCTL_TEMP2 1202 /* Degrees Celcius */ -#define MAXI_SYSCTL_TEMP3 1203 /* Degrees Celcius */ -#define MAXI_SYSCTL_TEMP4 1204 /* Degrees Celcius */ -#define MAXI_SYSCTL_TEMP5 1205 /* Degrees Celcius */ -#define MAXI_SYSCTL_PLL 1301 /* MHz */ -#define MAXI_SYSCTL_VID1 1401 /* Volts / 6.337 */ -#define MAXI_SYSCTL_VID2 1402 /* Volts */ -#define MAXI_SYSCTL_VID3 1403 /* Volts */ -#define MAXI_SYSCTL_VID4 1404 /* Volts */ -#define MAXI_SYSCTL_ALARMS 2001 /* Bitvector (see below) */ +#define MAXI_SYSCTL_FAN1 1101 /* Rotations/min */ +#define MAXI_SYSCTL_FAN2 1102 /* Rotations/min */ +#define MAXI_SYSCTL_FAN3 1103 /* Rotations/min */ +#define MAXI_SYSCTL_TEMP1 1201 /* Degrees Celcius */ +#define MAXI_SYSCTL_TEMP2 1202 /* Degrees Celcius */ +#define MAXI_SYSCTL_TEMP3 1203 /* Degrees Celcius */ +#define MAXI_SYSCTL_TEMP4 1204 /* Degrees Celcius */ +#define MAXI_SYSCTL_TEMP5 1205 /* Degrees Celcius */ +#define MAXI_SYSCTL_PLL 1301 /* MHz */ +#define MAXI_SYSCTL_VID1 1401 /* Volts / 6.337 */ +#define MAXI_SYSCTL_VID2 1402 /* Volts */ +#define MAXI_SYSCTL_VID3 1403 /* Volts */ +#define MAXI_SYSCTL_VID4 1404 /* Volts */ +#define MAXI_SYSCTL_ALARMS 2001 /* Bitvector (see below) */ #define MAXI_ALARM_VID4 0x0001 #define MAXI_ALARM_TEMP2 0x0002 @@ -618,15 +619,15 @@ struct sensors_chips_data { #define MAXI_ALARM_FAN2 0x2000 #define MAXI_ALARM_FAN3 0x4000 -#define SIS5595_SYSCTL_IN0 1000 /* Volts * 100 */ +#define SIS5595_SYSCTL_IN0 1000 /* Volts * 100 */ #define SIS5595_SYSCTL_IN1 1001 #define SIS5595_SYSCTL_IN2 1002 #define SIS5595_SYSCTL_IN3 1003 -#define SIS5595_SYSCTL_FAN1 1101 /* Rotations/min */ +#define SIS5595_SYSCTL_FAN1 1101 /* Rotations/min */ #define SIS5595_SYSCTL_FAN2 1102 -#define SIS5595_SYSCTL_TEMP 1200 /* Degrees Celcius * 10 */ -#define SIS5595_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ -#define SIS5595_SYSCTL_ALARMS 2001 /* bitvector */ +#define SIS5595_SYSCTL_TEMP 1200 /* Degrees Celcius * 10 */ +#define SIS5595_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ +#define SIS5595_SYSCTL_ALARMS 2001 /* bitvector */ #define SIS5595_ALARM_IN0 0x01 #define SIS5595_ALARM_IN1 0x02 @@ -648,12 +649,12 @@ struct sensors_chips_data { #define MATORB_SYSCTL_DISP 1000 -#define THMC50_SYSCTL_TEMP 1200 /* Degrees Celcius */ -#define THMC50_SYSCTL_REMOTE_TEMP 1201 /* Degrees Celcius */ +#define THMC50_SYSCTL_TEMP 1200 /* Degrees Celcius */ +#define THMC50_SYSCTL_REMOTE_TEMP 1201 /* Degrees Celcius */ #define THMC50_SYSCTL_INTER 1202 #define THMC50_SYSCTL_INTER_MASK 1203 #define THMC50_SYSCTL_DIE_CODE 1204 #define THMC50_SYSCTL_ANALOG_OUT 1205 -#endif /* def SENSORS_SENSORS_H */ +#endif /* def SENSORS_SENSORS_H */ diff --git a/kernel/sensors.c b/kernel/sensors.c index 92c9bca9..81545136 100644 --- a/kernel/sensors.c +++ b/kernel/sensors.c @@ -39,23 +39,25 @@ extern int init_module(void); extern int cleanup_module(void); static int sensors_cleanup(void); -#endif /* MODULE */ +#endif /* MODULE */ #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,13) #define THIS_MODULE NULL #endif static int sensors_create_name(char **name, const char *prefix, - struct i2c_adapter * adapter, int addr); + struct i2c_adapter *adapter, int addr); static void sensors_parse_reals(int *nrels, void *buffer, int bufsize, - long *results, int magnitude); -static void sensors_write_reals(int nrels,void *buffer,int *bufsize, - long *results, int magnitude); -static int sensors_proc_chips(ctl_table *ctl, int write, struct file * filp, - void *buffer, size_t *lenp); -static int sensors_sysctl_chips (ctl_table *table, int *name, int nlen, - void *oldval, size_t *oldlenp, void *newval, - size_t newlen, void **context); + long *results, int magnitude); +static void sensors_write_reals(int nrels, void *buffer, int *bufsize, + long *results, int magnitude); +static int sensors_proc_chips(ctl_table * ctl, int write, + struct file *filp, void *buffer, + size_t * lenp); +static int sensors_sysctl_chips(ctl_table * table, int *name, int nlen, + void *oldval, size_t * oldlenp, + void *newval, size_t newlen, + void **context); static int __init sensors_init(void); @@ -67,32 +69,32 @@ static unsigned short sensors_inodes[SENSORS_ENTRY_MAX]; #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1) static void sensors_fill_inode(struct inode *inode, int fill); static void sensors_dir_fill_inode(struct inode *inode, int fill); -#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1) */ +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,1) */ static ctl_table sysctl_table[] = { - { CTL_DEV, "dev", NULL, 0, 0555 }, - { 0 }, - { DEV_SENSORS, "sensors", NULL, 0, 0555 }, - { 0 }, - { 0, NULL, NULL, 0, 0555 }, - { 0 } + {CTL_DEV, "dev", NULL, 0, 0555}, + {0}, + {DEV_SENSORS, "sensors", NULL, 0, 0555}, + {0}, + {0, NULL, NULL, 0, 0555}, + {0} }; static ctl_table sensors_proc_dev_sensors[] = { - { SENSORS_CHIPS, "chips", NULL, 0, 0644, NULL, &sensors_proc_chips, - &sensors_sysctl_chips }, - { 0 } + {SENSORS_CHIPS, "chips", NULL, 0, 0644, NULL, &sensors_proc_chips, + &sensors_sysctl_chips}, + {0} }; static ctl_table sensors_proc_dev[] = { - { DEV_SENSORS, "sensors", NULL, 0, 0555, sensors_proc_dev_sensors }, - { 0 }, + {DEV_SENSORS, "sensors", NULL, 0, 0555, sensors_proc_dev_sensors}, + {0}, }; static ctl_table sensors_proc[] = { - { CTL_DEV, "dev", NULL, 0, 0555, sensors_proc_dev }, - { 0 } + {CTL_DEV, "dev", NULL, 0, 0555, sensors_proc_dev}, + {0} }; @@ -103,21 +105,21 @@ static int sensors_initialized; (for a LM78 chip on the ISA bus at port 0x310), or lm75-i2c-3-4e (for a LM75 chip on the third i2c bus at address 0x4e). name is allocated first. */ -int sensors_create_name(char **name, const char *prefix, - struct i2c_adapter * adapter, int addr) +int sensors_create_name(char **name, const char *prefix, + struct i2c_adapter *adapter, int addr) { - char name_buffer[50]; - int id; - if (i2c_is_isa_adapter(adapter)) - sprintf(name_buffer,"%s-isa-%04x",prefix,addr); - else { - if ((id = i2c_adapter_id(adapter)) < 0) - return -ENOENT; - sprintf(name_buffer,"%s-i2c-%d-%02x",prefix,id,addr); - } - *name = kmalloc(strlen(name_buffer)+1,GFP_KERNEL); - strcpy(*name,name_buffer); - return 0; + char name_buffer[50]; + int id; + if (i2c_is_isa_adapter(adapter)) + sprintf(name_buffer, "%s-isa-%04x", prefix, addr); + else { + if ((id = i2c_adapter_id(adapter)) < 0) + return -ENOENT; + sprintf(name_buffer, "%s-i2c-%d-%02x", prefix, id, addr); + } + *name = kmalloc(strlen(name_buffer) + 1, GFP_KERNEL); + strcpy(*name, name_buffer); + return 0; } /* This rather complex function must be called when you want to add an entry @@ -131,101 +133,103 @@ int sensors_create_name(char **name, const char *prefix, THIS_MODULE when calling. Note that this symbol is not defined in kernels before 2.3.13; define it to NULL in that case. We will not use it for anything older than 2.3.27 anyway. */ -int sensors_register_entry(struct i2c_client *client ,const char *prefix, - ctl_table *ctl_template, +int sensors_register_entry(struct i2c_client *client, const char *prefix, + ctl_table * ctl_template, struct module *controlling_mod) { - int i,res,len,id; - ctl_table *new_table; - char *name; - struct ctl_table_header *new_header; + int i, res, len, id; + ctl_table *new_table; + char *name; + struct ctl_table_header *new_header; - if ((res = sensors_create_name(&name,prefix,client->adapter, - client->addr))) - return res; + if ((res = sensors_create_name(&name, prefix, client->adapter, + client->addr))) return res; - for (id = 0; id < SENSORS_ENTRY_MAX; id++) - if (! sensors_entries[id]) { - break; - } - if (id == SENSORS_ENTRY_MAX) { - kfree(name); - return -ENOMEM; - } - id += 256; + for (id = 0; id < SENSORS_ENTRY_MAX; id++) + if (!sensors_entries[id]) { + break; + } + if (id == SENSORS_ENTRY_MAX) { + kfree(name); + return -ENOMEM; + } + id += 256; - len = 0; - while (ctl_template[len].procname) - len++; - len += 7; - if (! (new_table = kmalloc(sizeof(ctl_table) * len,GFP_KERNEL))) { - kfree(name); - return -ENOMEM; - } - - memcpy(new_table,sysctl_table,6 * sizeof(ctl_table)); - new_table[0].child = &new_table[2]; - new_table[2].child = &new_table[4]; - new_table[4].child = &new_table[6]; - new_table[4].procname = name; - new_table[4].ctl_name = id; - memcpy(new_table+6,ctl_template,(len-6) * sizeof(ctl_table)); - for (i = 6; i < len; i++) - new_table[i].extra2 = client; + len = 0; + while (ctl_template[len].procname) + len++; + len += 7; + if (!(new_table = kmalloc(sizeof(ctl_table) * len, GFP_KERNEL))) { + kfree(name); + return -ENOMEM; + } - if (! (new_header = register_sysctl_table(new_table,0))) { - kfree(new_table); - kfree(name); - return -ENOMEM; - } + memcpy(new_table, sysctl_table, 6 * sizeof(ctl_table)); + new_table[0].child = &new_table[2]; + new_table[2].child = &new_table[4]; + new_table[4].child = &new_table[6]; + new_table[4].procname = name; + new_table[4].ctl_name = id; + memcpy(new_table + 6, ctl_template, (len - 6) * sizeof(ctl_table)); + for (i = 6; i < len; i++) + new_table[i].extra2 = client; - sensors_entries[id-256] = new_header; + if (!(new_header = register_sysctl_table(new_table, 0))) { + kfree(new_table); + kfree(name); + return -ENOMEM; + } - sensors_clients[id-256] = client; + sensors_entries[id - 256] = new_header; + + sensors_clients[id - 256] = client; #ifdef DEBUG - if (!new_header || !new_header->ctl_table || - !new_header->ctl_table->child || - !new_header->ctl_table->child->child || - !new_header->ctl_table->child->child->de) { - printk("sensors.o: NULL pointer when trying to install fill_inode fix!\n"); - return id; - } -#endif /* DEBUG */ - sensors_inodes[id-256] = new_header->ctl_table->child->child->de->low_ino; + if (!new_header || !new_header->ctl_table || + !new_header->ctl_table->child || + !new_header->ctl_table->child->child || + !new_header->ctl_table->child->child->de) { + printk + ("sensors.o: NULL pointer when trying to install fill_inode fix!\n"); + return id; + } +#endif /* DEBUG */ + sensors_inodes[id - 256] = + new_header->ctl_table->child->child->de->low_ino; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) - new_header->ctl_table->child->child->de->owner = controlling_mod; + new_header->ctl_table->child->child->de->owner = controlling_mod; #else - new_header->ctl_table->child->child->de->fill_inode = &sensors_dir_fill_inode; -#endif (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) + new_header->ctl_table->child->child->de->fill_inode = + &sensors_dir_fill_inode; +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,27)) */ - return id; + return id; } void sensors_deregister_entry(int id) { - ctl_table *table; - char *temp; - id -= 256; - if (sensors_entries[id]) { - table = sensors_entries[id]->ctl_table; - unregister_sysctl_table(sensors_entries[id]); - /* Below two-step kfree is needed to keep gcc happy about const points */ - (const char *) temp = table[4].procname; - kfree(temp); - kfree(table); - sensors_entries[id] = NULL; - sensors_clients[id] = NULL; - } + ctl_table *table; + char *temp; + id -= 256; + if (sensors_entries[id]) { + table = sensors_entries[id]->ctl_table; + unregister_sysctl_table(sensors_entries[id]); + /* Below two-step kfree is needed to keep gcc happy about const points */ + (const char *) temp = table[4].procname; + kfree(temp); + kfree(table); + sensors_entries[id] = NULL; + sensors_clients[id] = NULL; + } } /* Monitor access for /proc/sys/dev/sensors; make unloading sensors.o impossible if some process still uses it or some file in it */ void sensors_fill_inode(struct inode *inode, int fill) { - if (fill) - MOD_INC_USE_COUNT; - else - MOD_DEC_USE_COUNT; + if (fill) + MOD_INC_USE_COUNT; + else + MOD_DEC_USE_COUNT; } /* Monitor access for /proc/sys/dev/sensors/ directories; make unloading @@ -233,92 +237,101 @@ void sensors_fill_inode(struct inode *inode, int fill) some file in it */ void sensors_dir_fill_inode(struct inode *inode, int fill) { - int i; - struct i2c_client *client; + int i; + struct i2c_client *client; #ifdef DEBUG - if (! inode) { - printk("sensors.o: Warning: inode NULL in fill_inode()\n"); - return; - } -#endif /* def DEBUG */ - - for (i = 0; i < SENSORS_ENTRY_MAX; i++) - if (sensors_clients[i] && (sensors_inodes[i] == inode->i_ino)) - break; + if (!inode) { + printk("sensors.o: Warning: inode NULL in fill_inode()\n"); + return; + } +#endif /* def DEBUG */ + + for (i = 0; i < SENSORS_ENTRY_MAX; i++) + if (sensors_clients[i] + && (sensors_inodes[i] == inode->i_ino)) break; #ifdef DEBUG - if (i == SENSORS_ENTRY_MAX) { - printk("sensors.o: Warning: inode (%ld) not found in fill_inode()\n", - inode->i_ino); - return; - } -#endif /* def DEBUG */ - client = sensors_clients[i]; - if (fill) - client->driver->inc_use(client); - else - client->driver->dec_use(client); + if (i == SENSORS_ENTRY_MAX) { + printk + ("sensors.o: Warning: inode (%ld) not found in fill_inode()\n", + inode->i_ino); + return; + } +#endif /* def DEBUG */ + client = sensors_clients[i]; + if (fill) + client->driver->inc_use(client); + else + client->driver->dec_use(client); } -int sensors_proc_chips(ctl_table *ctl, int write, struct file * filp, - void *buffer, size_t *lenp) +int sensors_proc_chips(ctl_table * ctl, int write, struct file *filp, + void *buffer, size_t * lenp) { - char BUF[SENSORS_PREFIX_MAX + 30]; - int buflen,curbufsize,i; - struct ctl_table *client_tbl; + char BUF[SENSORS_PREFIX_MAX + 30]; + int buflen, curbufsize, i; + struct ctl_table *client_tbl; - if (write) - return 0; + if (write) + return 0; - /* If buffer is size 0, or we try to read when not at the start, we - return nothing. Note that I think writing when not at the start - does not work either, but anyway, this is straight from the kernel - sources. */ - if (!*lenp || (filp->f_pos && !write)) { - *lenp = 0; - return 0; - } - curbufsize = 0; - for (i = 0; i < SENSORS_ENTRY_MAX; i ++) - if (sensors_entries[i]) { - client_tbl = sensors_entries[i]->ctl_table->child->child; - buflen = sprintf(BUF,"%d\t%s\n",client_tbl->ctl_name, - client_tbl->procname); - if (buflen + curbufsize > *lenp) - buflen=*lenp-curbufsize; - copy_to_user(buffer,BUF,buflen); - curbufsize += buflen; - (char *) buffer += buflen; - } - *lenp = curbufsize; - filp->f_pos += curbufsize; - return 0; + /* If buffer is size 0, or we try to read when not at the start, we + return nothing. Note that I think writing when not at the start + does not work either, but anyway, this is straight from the kernel + sources. */ + if (!*lenp || (filp->f_pos && !write)) { + *lenp = 0; + return 0; + } + curbufsize = 0; + for (i = 0; i < SENSORS_ENTRY_MAX; i++) + if (sensors_entries[i]) { + client_tbl = + sensors_entries[i]->ctl_table->child->child; + buflen = + sprintf(BUF, "%d\t%s\n", client_tbl->ctl_name, + client_tbl->procname); + if (buflen + curbufsize > *lenp) + buflen = *lenp - curbufsize; + copy_to_user(buffer, BUF, buflen); + curbufsize += buflen; + (char *) buffer += buflen; + } + *lenp = curbufsize; + filp->f_pos += curbufsize; + return 0; } -int sensors_sysctl_chips (ctl_table *table, int *name, int nlen, void *oldval, - size_t *oldlenp, void *newval, size_t newlen, - void **context) +int sensors_sysctl_chips(ctl_table * table, int *name, int nlen, + void *oldval, size_t * oldlenp, void *newval, + size_t newlen, void **context) { - struct sensors_chips_data data; - int i,oldlen,nrels,maxels; - struct ctl_table *client_tbl; + struct sensors_chips_data data; + int i, oldlen, nrels, maxels; + struct ctl_table *client_tbl; - if (oldval && oldlenp && ! get_user(oldlen,oldlenp) && oldlen) { - maxels = oldlen / sizeof(struct sensors_chips_data); - nrels = 0; - for (i = 0; (i < SENSORS_ENTRY_MAX) && (nrels < maxels); i++) - if (sensors_entries[i]) { - client_tbl = sensors_entries[i]->ctl_table->child->child; - data.sysctl_id = client_tbl->ctl_name; - strcpy(data.name,client_tbl->procname); - copy_to_user(oldval,&data,sizeof(struct sensors_chips_data)); - (char *) oldval += sizeof(struct sensors_chips_data); - nrels++; - } - oldlen = nrels * sizeof(struct sensors_chips_data); - put_user(oldlen,oldlenp); - } - return 0; + if (oldval && oldlenp && !get_user(oldlen, oldlenp) && oldlen) { + maxels = oldlen / sizeof(struct sensors_chips_data); + nrels = 0; + for (i = 0; (i < SENSORS_ENTRY_MAX) && (nrels < maxels); + i++) + if (sensors_entries[i]) { + client_tbl = + sensors_entries[i]->ctl_table->child-> + child; + data.sysctl_id = client_tbl->ctl_name; + strcpy(data.name, client_tbl->procname); + copy_to_user(oldval, &data, + sizeof(struct + sensors_chips_data)); + (char *) oldval += + sizeof(struct sensors_chips_data); + nrels++; + } + oldlen = nrels * sizeof(struct sensors_chips_data); + put_user(oldlen, oldlenp); + } + return 0; } @@ -339,85 +352,90 @@ int sensors_sysctl_chips (ctl_table *table, int *name, int nlen, void *oldval, found. In all cases, client points to the client we wish to interact with, and ctl_name is the SYSCTL id of the file we are accessing. */ -int sensors_proc_real(ctl_table *ctl, int write, struct file * filp, - void *buffer, size_t *lenp) +int sensors_proc_real(ctl_table * ctl, int write, struct file *filp, + void *buffer, size_t * lenp) { #define MAX_RESULTS 32 - int mag,nrels=MAX_RESULTS; - long results[MAX_RESULTS]; - sensors_real_callback callback = ctl -> extra1; - struct i2c_client *client = ctl -> extra2; + int mag, nrels = MAX_RESULTS; + long results[MAX_RESULTS]; + sensors_real_callback callback = ctl->extra1; + struct i2c_client *client = ctl->extra2; - /* If buffer is size 0, or we try to read when not at the start, we - return nothing. Note that I think writing when not at the start - does not work either, but anyway, this is straight from the kernel - sources. */ - if (!*lenp || (filp->f_pos && !write)) { - *lenp = 0; - return 0; - } + /* If buffer is size 0, or we try to read when not at the start, we + return nothing. Note that I think writing when not at the start + does not work either, but anyway, this is straight from the kernel + sources. */ + if (!*lenp || (filp->f_pos && !write)) { + *lenp = 0; + return 0; + } - /* Get the magnitude */ - callback(client,SENSORS_PROC_REAL_INFO,ctl->ctl_name,&mag,NULL); + /* Get the magnitude */ + callback(client, SENSORS_PROC_REAL_INFO, ctl->ctl_name, &mag, + NULL); - if (write) { - /* Read the complete input into results, converting to longs */ - sensors_parse_reals(&nrels,buffer,*lenp,results,mag); + if (write) { + /* Read the complete input into results, converting to longs */ + sensors_parse_reals(&nrels, buffer, *lenp, results, mag); - if (! nrels) - return 0; + if (!nrels) + return 0; - /* Now feed this information back to the client */ - callback(client,SENSORS_PROC_REAL_WRITE,ctl->ctl_name,&nrels,results); - - filp->f_pos += *lenp; - return 0; - } else { /* read */ - /* Get the information from the client into results */ - callback(client,SENSORS_PROC_REAL_READ,ctl->ctl_name,&nrels,results); + /* Now feed this information back to the client */ + callback(client, SENSORS_PROC_REAL_WRITE, ctl->ctl_name, + &nrels, results); - /* And write them to buffer, converting to reals */ - sensors_write_reals(nrels,buffer,lenp,results,mag); - filp->f_pos += *lenp; - return 0; - } + filp->f_pos += *lenp; + return 0; + } else { /* read */ + /* Get the information from the client into results */ + callback(client, SENSORS_PROC_REAL_READ, ctl->ctl_name, + &nrels, results); + + /* And write them to buffer, converting to reals */ + sensors_write_reals(nrels, buffer, lenp, results, mag); + filp->f_pos += *lenp; + return 0; + } } /* This function is equivalent to sensors_proc_real, only it interacts with the sysctl(2) syscall, and returns no reals, but integers */ -int sensors_sysctl_real (ctl_table *table, int *name, int nlen, void *oldval, - size_t *oldlenp, void *newval, size_t newlen, - void **context) +int sensors_sysctl_real(ctl_table * table, int *name, int nlen, + void *oldval, size_t * oldlenp, void *newval, + size_t newlen, void **context) { - long results[MAX_RESULTS]; - int oldlen,nrels=MAX_RESULTS; - sensors_real_callback callback = table -> extra1; - struct i2c_client *client = table -> extra2; + long results[MAX_RESULTS]; + int oldlen, nrels = MAX_RESULTS; + sensors_real_callback callback = table->extra1; + struct i2c_client *client = table->extra2; - /* Check if we need to output the old values */ - if (oldval && oldlenp && ! get_user(oldlen,oldlenp) && oldlen) { - callback(client,SENSORS_PROC_REAL_READ,table->ctl_name,&nrels,results); + /* Check if we need to output the old values */ + if (oldval && oldlenp && !get_user(oldlen, oldlenp) && oldlen) { + callback(client, SENSORS_PROC_REAL_READ, table->ctl_name, + &nrels, results); - /* Note the rounding factor! */ - if (nrels * sizeof(long) < oldlen) - oldlen = nrels * sizeof(long); - oldlen = (oldlen / sizeof(long)) * sizeof(long); - copy_to_user(oldval,results,oldlen); - put_user(oldlen,oldlenp); - } + /* Note the rounding factor! */ + if (nrels * sizeof(long) < oldlen) + oldlen = nrels * sizeof(long); + oldlen = (oldlen / sizeof(long)) * sizeof(long); + copy_to_user(oldval, results, oldlen); + put_user(oldlen, oldlenp); + } - if (newval && newlen) { - /* Note the rounding factor! */ - newlen -= newlen % sizeof(long); - nrels = newlen / sizeof(long); - copy_from_user(results,newval,newlen); - - /* Get the new values back to the client */ - callback(client,SENSORS_PROC_REAL_WRITE,table->ctl_name,&nrels,results); - } - return 0; + if (newval && newlen) { + /* Note the rounding factor! */ + newlen -= newlen % sizeof(long); + nrels = newlen / sizeof(long); + copy_from_user(results, newval, newlen); + + /* Get the new values back to the client */ + callback(client, SENSORS_PROC_REAL_WRITE, table->ctl_name, + &nrels, results); + } + return 0; } - + /* nrels contains initially the maximum number of elements which can be put in results, and finally the number of elements actually put there. @@ -435,345 +453,407 @@ int sensors_sysctl_real (ctl_table *table, int *name, int nlen, void *oldval, WARNING! This is tricky code. I have tested it, but there may still be hidden bugs in it, even leading to crashes and things! */ -void sensors_parse_reals(int *nrels, void *buffer, int bufsize, - long *results, int magnitude) +void sensors_parse_reals(int *nrels, void *buffer, int bufsize, + long *results, int magnitude) { - int maxels,min,mag; - long res; - char nextchar=0; + int maxels, min, mag; + long res; + char nextchar = 0; - maxels = *nrels; - *nrels = 0; + maxels = *nrels; + *nrels = 0; - while (bufsize && (*nrels < maxels)) { + while (bufsize && (*nrels < maxels)) { - /* Skip spaces at the start */ - while (bufsize && ! get_user(nextchar,(char *) buffer) && - isspace((int) nextchar)) { - bufsize --; - ((char *) buffer)++; - } + /* Skip spaces at the start */ + while (bufsize && !get_user(nextchar, (char *) buffer) && + isspace((int) nextchar)) { + bufsize--; + ((char *) buffer)++; + } - /* Well, we may be done now */ - if (! bufsize) - return; + /* Well, we may be done now */ + if (!bufsize) + return; - /* New defaults for our result */ - min = 0; - res = 0; - mag = magnitude; + /* New defaults for our result */ + min = 0; + res = 0; + mag = magnitude; - /* Check for a minus */ - if (! get_user(nextchar,(char *) buffer) && (nextchar == '-')) { - min=1; - bufsize--; - ((char *) buffer)++; - } + /* Check for a minus */ + if (!get_user(nextchar, (char *) buffer) + && (nextchar == '-')) { + min = 1; + bufsize--; + ((char *) buffer)++; + } - /* Digits before a decimal dot */ - while (bufsize && !get_user(nextchar,(char *) buffer) && - isdigit((int) nextchar)) { - res = res * 10 + nextchar - '0'; - bufsize--; - ((char *) buffer)++; - } + /* Digits before a decimal dot */ + while (bufsize && !get_user(nextchar, (char *) buffer) && + isdigit((int) nextchar)) { + res = res * 10 + nextchar - '0'; + bufsize--; + ((char *) buffer)++; + } - /* If mag < 0, we must actually divide here! */ - while (mag < 0) { - res = res / 10; - mag++; - } + /* If mag < 0, we must actually divide here! */ + while (mag < 0) { + res = res / 10; + mag++; + } - if (bufsize && (nextchar == '.')) { - /* Skip the dot */ - bufsize--; - ((char *) buffer)++; - - /* Read digits while they are significant */ - while(bufsize && (mag > 0) && - !get_user(nextchar,(char *) buffer) && - isdigit((int) nextchar)) { - res = res * 10 + nextchar - '0'; - mag--; - bufsize--; - ((char *) buffer)++; - } - } - /* If we are out of data, but mag > 0, we need to scale here */ - while (mag > 0) { - res = res * 10; - mag --; - } + if (bufsize && (nextchar == '.')) { + /* Skip the dot */ + bufsize--; + ((char *) buffer)++; - /* Skip everything until we hit whitespace */ - while(bufsize && !get_user(nextchar,(char *) buffer) && - isspace ((int) nextchar)) { - bufsize --; - ((char *) buffer) ++; - } + /* Read digits while they are significant */ + while (bufsize && (mag > 0) && + !get_user(nextchar, (char *) buffer) && + isdigit((int) nextchar)) { + res = res * 10 + nextchar - '0'; + mag--; + bufsize--; + ((char *) buffer)++; + } + } + /* If we are out of data, but mag > 0, we need to scale here */ + while (mag > 0) { + res = res * 10; + mag--; + } - /* Put res in results */ - results[*nrels] = (min?-1:1)*res; - (*nrels)++; - } - - /* Well, there may be more in the buffer, but we need no more data. - Ignore anything that is left. */ - return; + /* Skip everything until we hit whitespace */ + while (bufsize && !get_user(nextchar, (char *) buffer) && + isspace((int) nextchar)) { + bufsize--; + ((char *) buffer)++; + } + + /* Put res in results */ + results[*nrels] = (min ? -1 : 1) * res; + (*nrels)++; + } + + /* Well, there may be more in the buffer, but we need no more data. + Ignore anything that is left. */ + return; } - -void sensors_write_reals(int nrels,void *buffer,int *bufsize,long *results, - int magnitude) + +void sensors_write_reals(int nrels, void *buffer, int *bufsize, + long *results, int magnitude) { - #define BUFLEN 20 - char BUF[BUFLEN+1]; /* An individual representation should fit in here! */ - char printfstr[10]; - int nr=0; - int buflen,mag,times; - int curbufsize=0; +#define BUFLEN 20 + char BUF[BUFLEN + 1]; /* An individual representation should fit in here! */ + char printfstr[10]; + int nr = 0; + int buflen, mag, times; + int curbufsize = 0; - while ((nr < nrels) && (curbufsize < *bufsize)) { - mag=magnitude; + while ((nr < nrels) && (curbufsize < *bufsize)) { + mag = magnitude; - if (nr != 0) { - put_user(' ', (char *) buffer); - curbufsize ++; - ((char *) buffer) ++; - } + if (nr != 0) { + put_user(' ', (char *) buffer); + curbufsize++; + ((char *) buffer)++; + } - /* Fill BUF with the representation of the next string */ - if (mag <= 0) { + /* Fill BUF with the representation of the next string */ + if (mag <= 0) { - buflen=sprintf(BUF,"%ld",results[nr]); - if (buflen < 0) { /* Oops, a sprintf error! */ - *bufsize=0; - return; - } - while ((mag < 0) && (buflen < BUFLEN)) { - BUF[buflen++]='0'; - mag++; - } - BUF[buflen]=0; - } else { - times=1; - for (times=1; mag-- > 0; times *= 10); - if (results[nr] < 0) { - BUF[0] = '-'; - buflen = 1; - } else - buflen=0; - strcpy(printfstr,"%ld.%0Xld"); - printfstr[6]=magnitude+'0'; - buflen+=sprintf(BUF+buflen,printfstr,abs(results[nr])/times, - abs(results[nr])%times); - if (buflen < 0) { /* Oops, a sprintf error! */ - *bufsize=0; - return; - } - } + buflen = sprintf(BUF, "%ld", results[nr]); + if (buflen < 0) { /* Oops, a sprintf error! */ + *bufsize = 0; + return; + } + while ((mag < 0) && (buflen < BUFLEN)) { + BUF[buflen++] = '0'; + mag++; + } + BUF[buflen] = 0; + } else { + times = 1; + for (times = 1; mag-- > 0; times *= 10); + if (results[nr] < 0) { + BUF[0] = '-'; + buflen = 1; + } else + buflen = 0; + strcpy(printfstr, "%ld.%0Xld"); + printfstr[6] = magnitude + '0'; + buflen += + sprintf(BUF + buflen, printfstr, + abs(results[nr]) / times, + abs(results[nr]) % times); + if (buflen < 0) { /* Oops, a sprintf error! */ + *bufsize = 0; + return; + } + } - /* Now copy it to the user-space buffer */ - if (buflen + curbufsize > *bufsize) - buflen=*bufsize-curbufsize; - copy_to_user(buffer,BUF,buflen); - curbufsize += buflen; - (char *) buffer += buflen; + /* Now copy it to the user-space buffer */ + if (buflen + curbufsize > *bufsize) + buflen = *bufsize - curbufsize; + copy_to_user(buffer, BUF, buflen); + curbufsize += buflen; + (char *) buffer += buflen; - nr ++; - } - if (curbufsize < *bufsize) { - put_user('\n', (char *) buffer); - curbufsize ++; - } - *bufsize=curbufsize; + nr++; + } + if (curbufsize < *bufsize) { + put_user('\n', (char *) buffer); + curbufsize++; + } + *bufsize = curbufsize; } /* Very inefficient for ISA detects, and won't work for 10-bit addresses! */ int sensors_detect(struct i2c_adapter *adapter, - struct sensors_address_data *address_data, - sensors_found_addr_proc *found_proc) + struct sensors_address_data *address_data, + sensors_found_addr_proc * found_proc) { - int addr,i,found,j,err; - struct sensors_force_data *this_force; - int is_isa = i2c_is_isa_adapter(adapter); - int adapter_id = is_isa?SENSORS_ISA_BUS:i2c_adapter_id(adapter); + int addr, i, found, j, err; + struct sensors_force_data *this_force; + int is_isa = i2c_is_isa_adapter(adapter); + int adapter_id = + is_isa ? SENSORS_ISA_BUS : i2c_adapter_id(adapter); - /* Forget it if we can't probe using SMBUS_QUICK */ - if ((! is_isa) && ! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_QUICK)) - return -1; + /* Forget it if we can't probe using SMBUS_QUICK */ + if ((!is_isa) + && !i2c_check_functionality(adapter, + I2C_FUNC_SMBUS_QUICK)) return -1; - for (addr = 0x00; - addr <= (is_isa?0xffff:0x7f); - addr ++) { - if ((is_isa && check_region(addr,1)) || - (!is_isa && i2c_check_addr(adapter,addr))) - continue; + for (addr = 0x00; addr <= (is_isa ? 0xffff : 0x7f); addr++) { + if ((is_isa && check_region(addr, 1)) || + (!is_isa && i2c_check_addr(adapter, addr))) + continue; - /* If it is in one of the force entries, we don't do any detection - at all */ - found = 0; - for (i = 0; - !found && (this_force = address_data->forces+i, this_force->force); - i++) { - for (j = 0; - !found && (this_force->force[j] != SENSORS_I2C_END) ; - j += 2) { - if (((adapter_id == this_force->force[j]) || - ((this_force->force[j] == SENSORS_ANY_I2C_BUS) && !is_isa)) && - (addr == this_force->force[j+1])) { + /* If it is in one of the force entries, we don't do any detection + at all */ + found = 0; + for (i = 0; + !found + && (this_force = + address_data->forces + i, this_force->force); i++) { + for (j = 0; + !found + && (this_force->force[j] != SENSORS_I2C_END); + j += 2) { + if ( + ((adapter_id == this_force->force[j]) + || + ((this_force-> + force[j] == SENSORS_ANY_I2C_BUS) + && !is_isa)) + && (addr == this_force->force[j + 1])) { #ifdef DEBUG - printk("sensors.o: found force parameter for adapter %d, addr %04x\n", - adapter_id,addr); + printk + ("sensors.o: found force parameter for adapter %d, addr %04x\n", + adapter_id, addr); #endif - if ((err = found_proc(adapter,addr,0,this_force->kind))) - return err; - found = 1; - } - } - } - if (found) - continue; + if ( + (err = + found_proc(adapter, addr, 0, + this_force-> + kind))) return err; + found = 1; + } + } + } + if (found) + continue; - /* If this address is in one of the ignores, we can forget about it - right now */ - for (i = 0; - !found && (address_data->ignore[i] != SENSORS_I2C_END); - i += 2) { - if (((adapter_id == address_data->ignore[i]) || - ((address_data->ignore[i] == SENSORS_ANY_I2C_BUS) && !is_isa)) && - (addr == address_data->ignore[i+1])) { + /* If this address is in one of the ignores, we can forget about it + right now */ + for (i = 0; + !found + && (address_data->ignore[i] != SENSORS_I2C_END); + i += 2) { + if ( + ((adapter_id == address_data->ignore[i]) + || + ((address_data-> + ignore[i] == SENSORS_ANY_I2C_BUS) + && !is_isa)) + && (addr == address_data->ignore[i + 1])) { #ifdef DEBUG - printk("sensors.o: found ignore parameter for adapter %d, " - "addr %04x\n", adapter_id,addr); + printk + ("sensors.o: found ignore parameter for adapter %d, " + "addr %04x\n", adapter_id, addr); #endif - found = 1; - } - } - for (i = 0; - !found && (address_data->ignore_range[i] != SENSORS_I2C_END); - i += 3) { - if (((adapter_id == address_data->ignore_range[i]) || - ((address_data->ignore_range[i]==SENSORS_ANY_I2C_BUS) & !is_isa)) && - (addr >= address_data->ignore_range[i+1]) && - (addr <= address_data->ignore_range[i+2])) { + found = 1; + } + } + for (i = 0; + !found + && (address_data->ignore_range[i] != SENSORS_I2C_END); + i += 3) { + if ( + ((adapter_id == address_data->ignore_range[i]) + || + ((address_data-> + ignore_range[i] == + SENSORS_ANY_I2C_BUS) & !is_isa)) + && (addr >= address_data->ignore_range[i + 1]) + && (addr <= address_data->ignore_range[i + 2])) { #ifdef DEBUG - printk("sensors.o: found ignore_range parameter for adapter %d, " - "addr %04x\n", adapter_id,addr); + printk + ("sensors.o: found ignore_range parameter for adapter %d, " + "addr %04x\n", adapter_id, addr); #endif - found = 1; - } - } - if (found) - continue; + found = 1; + } + } + if (found) + continue; - /* Now, we will do a detection, but only if it is in the normal or - probe entries */ - if (is_isa) { - for (i = 0; - !found && (address_data->normal_isa[i] != SENSORS_ISA_END); - i += 1) { - if (addr == address_data->normal_isa[i]) { + /* Now, we will do a detection, but only if it is in the normal or + probe entries */ + if (is_isa) { + for (i = 0; + !found + && (address_data->normal_isa[i] != + SENSORS_ISA_END); i += 1) { + if (addr == address_data->normal_isa[i]) { #ifdef DEBUG - printk("sensors.o: found normal isa entry for adapter %d, " - "addr %04x\n", adapter_id,addr); + printk + ("sensors.o: found normal isa entry for adapter %d, " + "addr %04x\n", adapter_id, + addr); #endif - found = 1; - } - } - for (i = 0; - !found && (address_data->normal_isa_range[i] != SENSORS_ISA_END); - i += 3) { - if ((addr >= address_data->normal_isa_range[i]) && - (addr <= address_data->normal_isa_range[i+1]) && - ((addr - address_data->normal_isa_range[i]) % - address_data->normal_isa_range[i+2] == 0)) { + found = 1; + } + } + for (i = 0; + !found + && (address_data->normal_isa_range[i] != + SENSORS_ISA_END); i += 3) { + if ( + (addr >= + address_data->normal_isa_range[i]) + && (addr <= + address_data->normal_isa_range[i + + 1]) + && + ((addr + - + address_data->normal_isa_range[i]) % + address_data->normal_isa_range[i + + 2] == + 0)) { #ifdef DEBUG - printk("sensors.o: found normal isa_range entry for adapter %d, " - "addr %04x", adapter_id,addr); + printk + ("sensors.o: found normal isa_range entry for adapter %d, " + "addr %04x", adapter_id, + addr); #endif - found = 1; - } - } - } else { - for (i = 0; - !found && (address_data->normal_i2c[i] != SENSORS_I2C_END); - i += 1) { - if (addr == address_data->normal_i2c[i]) { - found = 1; + found = 1; + } + } + } else { + for (i = 0; + !found + && (address_data->normal_i2c[i] != + SENSORS_I2C_END); i += 1) { + if (addr == address_data->normal_i2c[i]) { + found = 1; #ifdef DEBUG - printk("sensors.o: found normal i2c entry for adapter %d, " - "addr %02x", adapter_id,addr); + printk + ("sensors.o: found normal i2c entry for adapter %d, " + "addr %02x", adapter_id, + addr); #endif - } - } - for (i = 0; - !found && (address_data->normal_i2c_range[i] != SENSORS_I2C_END); - i += 2) { - if ((addr >= address_data->normal_i2c_range[i]) && - (addr <= address_data->normal_i2c_range[i+1])) { + } + } + for (i = 0; + !found + && (address_data->normal_i2c_range[i] != + SENSORS_I2C_END); i += 2) { + if ( + (addr >= + address_data->normal_i2c_range[i]) + && (addr <= + address_data->normal_i2c_range[i + + 1])) + { #ifdef DEBUG - printk("sensors.o: found normal i2c_range entry for adapter %d, " - "addr %04x\n", adapter_id,addr); + printk + ("sensors.o: found normal i2c_range entry for adapter %d, " + "addr %04x\n", adapter_id, + addr); #endif - found = 1; - } - } - } + found = 1; + } + } + } - for (i = 0; - !found && (address_data->probe[i] != SENSORS_I2C_END); - i += 2) { - if (((adapter_id == address_data->probe[i]) || - ((address_data->probe[i] == SENSORS_ANY_I2C_BUS) & !is_isa)) && - (addr == address_data->probe[i+1])) { + for (i = 0; + !found && (address_data->probe[i] != SENSORS_I2C_END); + i += 2) { + if (((adapter_id == address_data->probe[i]) || + ((address_data-> + probe[i] == SENSORS_ANY_I2C_BUS) & !is_isa)) + && (addr == address_data->probe[i + 1])) { #ifdef DEBUG - printk("sensors.o: found probe parameter for adapter %d, " - "addr %04x\n", adapter_id,addr); + printk + ("sensors.o: found probe parameter for adapter %d, " + "addr %04x\n", adapter_id, addr); #endif - found = 1; - } - } - for (i = 0; - !found && (address_data->probe_range[i] != SENSORS_I2C_END); - i += 3) { - if (((adapter_id == address_data->probe_range[i]) || - ((address_data->probe_range[i] == SENSORS_ANY_I2C_BUS) & !is_isa)) && - (addr >= address_data->probe_range[i+1]) && - (addr <= address_data->probe_range[i+2])) { - found = 1; + found = 1; + } + } + for (i = 0; + !found + && (address_data->probe_range[i] != SENSORS_I2C_END); + i += 3) { + if ( + ((adapter_id == address_data->probe_range[i]) + || + ((address_data-> + probe_range[i] == + SENSORS_ANY_I2C_BUS) & !is_isa)) + && (addr >= address_data->probe_range[i + 1]) + && (addr <= address_data->probe_range[i + 2])) { + found = 1; #ifdef DEBUG - printk("sensors.o: found probe_range parameter for adapter %d, " - "addr %04x\n", adapter_id,addr); + printk + ("sensors.o: found probe_range parameter for adapter %d, " + "addr %04x\n", adapter_id, addr); #endif - } - } - if (!found) - continue; + } + } + if (!found) + continue; - /* OK, so we really should examine this address. First check - whether there is some client here at all! */ - if (is_isa || - (i2c_smbus_xfer(adapter,addr,0,0,0,I2C_SMBUS_QUICK,NULL) >= 0)) - if ((err = found_proc(adapter,addr,0,-1))) - return err; - } - return 0; + /* OK, so we really should examine this address. First check + whether there is some client here at all! */ + if (is_isa || + (i2c_smbus_xfer + (adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL) >= 0)) + if ((err = found_proc(adapter, addr, 0, -1))) + return err; + } + return 0; } - -int __init sensors_init(void) + +int __init sensors_init(void) { - printk("sensors.o version %s (%s)\n",LM_VERSION,LM_DATE); - sensors_initialized = 0; - if (! (sensors_proc_header = register_sysctl_table(sensors_proc,0))) - return -ENOMEM; + printk("sensors.o version %s (%s)\n", LM_VERSION, LM_DATE); + sensors_initialized = 0; + if (! + (sensors_proc_header = + register_sysctl_table(sensors_proc, 0))) return -ENOMEM; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1)) - sensors_proc_header->ctl_table->child->de->owner = THIS_MODULE; + sensors_proc_header->ctl_table->child->de->owner = THIS_MODULE; #else - sensors_proc_header->ctl_table->child->de->fill_inode = &sensors_fill_inode; -#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1)) */ - sensors_initialized ++; - return 0; + sensors_proc_header->ctl_table->child->de->fill_inode = + &sensors_fill_inode; +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,3,1)) */ + sensors_initialized++; + return 0; } EXPORT_SYMBOL(sensors_deregister_entry); @@ -789,54 +869,54 @@ MODULE_DESCRIPTION("LM78 driver"); int sensors_cleanup(void) { - if (sensors_initialized >= 1) { - unregister_sysctl_table(sensors_proc_header); - sensors_initialized --; - } - return 0; + if (sensors_initialized >= 1) { + unregister_sysctl_table(sensors_proc_header); + sensors_initialized--; + } + return 0; } int init_module(void) { - return sensors_init(); + return sensors_init(); } int cleanup_module(void) { - return sensors_cleanup(); + return sensors_cleanup(); } -#else /* ndef MODULE */ +#else /* ndef MODULE */ #ifdef CONFIG_SENSORS_ADM1021 - extern int sensors_adm1021_init(void); +extern int sensors_adm1021_init(void); #endif #ifdef CONFIG_SENSORS_ADM9024 - extern int sensors_adm9024_init(void); +extern int sensors_adm9024_init(void); #endif #ifdef CONFIG_SENSORS_GL518SM - extern int sensors_gl518sm_init(void); +extern int sensors_gl518sm_init(void); #endif #ifdef CONFIG_SENSORS_LM75 - extern int sensors_lm75_init(void); +extern int sensors_lm75_init(void); #endif #ifdef CONFIG_SENSORS_LM78 - extern int sensors_lm78_init(void); +extern int sensors_lm78_init(void); #endif #ifdef CONFIG_SENSORS_LM80 - extern int sensors_lm80_init(void); +extern int sensors_lm80_init(void); #endif #ifdef CONFIG_SENSORS_SIS5595 - extern int sensors_sis5595_init(void); +extern int sensors_sis5595_init(void); #endif #ifdef CONFIG_SENSORS_W83781D - extern int sensors_w83781d_init(void); +extern int sensors_w83781d_init(void); #endif #ifdef CONFIG_SENSORS_EEPROM - extern int sensors_eeprom_init(void); +extern int sensors_eeprom_init(void); #endif #ifdef CONFIG_SENSORS_LTC1710 - extern int sensors_ltc1710_init(void); +extern int sensors_ltc1710_init(void); #endif int __init sensors_init_all(void) @@ -875,5 +955,4 @@ int __init sensors_init_all(void) return 0; } -#endif /* MODULE */ - +#endif /* MODULE */