Commit 015744f5 authored by Linus Torvalds's avatar Linus Torvalds

Merge bk://kernel.bkbits.net/gregkh/linux/i2c-2.5

into home.transmeta.com:/home/torvalds/v2.5/linux
parents 8a80abf7 fdc47311
...@@ -177,17 +177,18 @@ static int ali15x3_setup(struct pci_dev *ALI15X3_dev) ...@@ -177,17 +177,18 @@ static int ali15x3_setup(struct pci_dev *ALI15X3_dev)
if(force_addr) { if(force_addr) {
dev_info(&ALI15X3_dev->dev, "forcing ISA address 0x%04X\n", dev_info(&ALI15X3_dev->dev, "forcing ISA address 0x%04X\n",
ali15x3_smba); ali15x3_smba);
if (PCIBIOS_SUCCESSFUL != if (PCIBIOS_SUCCESSFUL != pci_write_config_word(ALI15X3_dev,
pci_write_config_word(ALI15X3_dev, SMBBA, ali15x3_smba)) SMBBA,
return -ENODEV; ali15x3_smba))
if (PCIBIOS_SUCCESSFUL != goto error;
pci_read_config_word(ALI15X3_dev, SMBBA, &a)) if (PCIBIOS_SUCCESSFUL != pci_read_config_word(ALI15X3_dev,
return -ENODEV; SMBBA, &a))
goto error;
if ((a & ~(ALI15X3_SMB_IOSIZE - 1)) != ali15x3_smba) { if ((a & ~(ALI15X3_SMB_IOSIZE - 1)) != ali15x3_smba) {
/* make sure it works */ /* make sure it works */
dev_err(&ALI15X3_dev->dev, dev_err(&ALI15X3_dev->dev,
"force address failed - not supported?\n"); "force address failed - not supported?\n");
return -ENODEV; goto error;
} }
} }
/* check if whole device is enabled */ /* check if whole device is enabled */
...@@ -219,6 +220,9 @@ static int ali15x3_setup(struct pci_dev *ALI15X3_dev) ...@@ -219,6 +220,9 @@ static int ali15x3_setup(struct pci_dev *ALI15X3_dev)
dev_dbg(&ALI15X3_dev->dev, "iALI15X3_smba = 0x%X\n", ali15x3_smba); dev_dbg(&ALI15X3_dev->dev, "iALI15X3_smba = 0x%X\n", ali15x3_smba);
return 0; return 0;
error:
release_region(ali15x3_smba, ALI15X3_SMB_IOSIZE);
return -ENODEV;
} }
/* Internally used pause function */ /* Internally used pause function */
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
82801BA 2443 82801BA 2443
82801CA/CAM 2483 82801CA/CAM 2483
82801DB 24C3 (HW PEC supported, 32 byte buffer not supported) 82801DB 24C3 (HW PEC supported, 32 byte buffer not supported)
82801EB 24D3 (HW PEC supported, 32 byte buffer not supported)
This driver supports several versions of Intel's I/O Controller Hubs (ICH). This driver supports several versions of Intel's I/O Controller Hubs (ICH).
For SMBus support, they are similar to the PIIX4 and are part For SMBus support, they are similar to the PIIX4 and are part
...@@ -121,7 +122,8 @@ static int i801_setup(struct pci_dev *dev) ...@@ -121,7 +122,8 @@ static int i801_setup(struct pci_dev *dev)
return -ENODEV; return -ENODEV;
I801_dev = dev; I801_dev = dev;
if (dev->device == PCI_DEVICE_ID_INTEL_82801DB_3) if ((dev->device == PCI_DEVICE_ID_INTEL_82801DB_3) ||
(dev->device == PCI_DEVICE_ID_INTEL_82801EB_3))
isich4 = 1; isich4 = 1;
else else
isich4 = 0; isich4 = 0;
...@@ -585,6 +587,12 @@ static struct pci_device_id i801_ids[] __devinitdata = { ...@@ -585,6 +587,12 @@ static struct pci_device_id i801_ids[] __devinitdata = {
.subvendor = PCI_ANY_ID, .subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID, .subdevice = PCI_ANY_ID,
}, },
{
.vendor = PCI_VENDOR_ID_INTEL,
.device = PCI_DEVICE_ID_INTEL_82801EB_3,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
},
{ 0, } { 0, }
}; };
......
...@@ -62,6 +62,20 @@ config SENSORS_LM85 ...@@ -62,6 +62,20 @@ config SENSORS_LM85
in the lm_sensors package, which you can download at in the lm_sensors package, which you can download at
http://www.lm-sensors.nu http://www.lm-sensors.nu
config SENSORS_LM78
tristate " National Semiconductors LM78 and compatibles"
depends on I2C && EXPERIMENTAL
help
If you say yes here you get support for National Semiconductor LM78,
LM78-J and LM79. This can also be built as a module which can be
inserted and removed while the kernel is running.
The module will be called lm78.
You will also need the latest user-space utilties: you can find them
in the lm_sensors package, which you can download at
http://www.lm-sensors.nu
config SENSORS_VIA686A config SENSORS_VIA686A
tristate " VIA686A" tristate " VIA686A"
depends on I2C && EXPERIMENTAL depends on I2C && EXPERIMENTAL
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o obj-$(CONFIG_SENSORS_ADM1021) += adm1021.o
obj-$(CONFIG_SENSORS_IT87) += it87.o obj-$(CONFIG_SENSORS_IT87) += it87.o
obj-$(CONFIG_SENSORS_LM75) += lm75.o obj-$(CONFIG_SENSORS_LM75) += lm75.o
obj-$(CONFIG_SENSORS_LM78) += lm78.o
obj-$(CONFIG_SENSORS_LM85) += lm85.o obj-$(CONFIG_SENSORS_LM85) += lm85.o
obj-$(CONFIG_SENSORS_VIA686A) += via686a.o obj-$(CONFIG_SENSORS_VIA686A) += via686a.o
obj-$(CONFIG_SENSORS_W83781D) += w83781d.o obj-$(CONFIG_SENSORS_W83781D) += w83781d.o
...@@ -88,8 +88,8 @@ SENSORS_INSMOD_8(adm1021, adm1023, max1617, max1617a, thmc10, lm84, gl523sm, mc1 ...@@ -88,8 +88,8 @@ SENSORS_INSMOD_8(adm1021, adm1023, max1617, max1617a, thmc10, lm84, gl523sm, mc1
these macros are called: arguments may be evaluated more than once. these macros are called: arguments may be evaluated more than once.
Fixing this is just not worth it. */ Fixing this is just not worth it. */
/* Conversions note: 1021 uses normal integer signed-byte format*/ /* Conversions note: 1021 uses normal integer signed-byte format*/
#define TEMP_FROM_REG(val) (val > 127 ? val-256 : val) #define TEMP_FROM_REG(val) (val > 127 ? (val-256)*1000 : val*1000)
#define TEMP_TO_REG(val) (SENSORS_LIMIT((val < 0 ? val+256 : val),0,255)) #define TEMP_TO_REG(val) (SENSORS_LIMIT((val < 0 ? (val/1000)+256 : val/1000),0,255))
/* Initial values */ /* Initial values */
...@@ -172,8 +172,18 @@ show(temp_input); ...@@ -172,8 +172,18 @@ show(temp_input);
show(remote_temp_max); show(remote_temp_max);
show(remote_temp_hyst); show(remote_temp_hyst);
show(remote_temp_input); show(remote_temp_input);
show(alarms);
show(die_code); #define show2(value) \
static ssize_t show_##value(struct device *dev, char *buf) \
{ \
struct i2c_client *client = to_i2c_client(dev); \
struct adm1021_data *data = i2c_get_clientdata(client); \
\
adm1021_update_client(client); \
return sprintf(buf, "%d\n", data->value); \
}
show2(alarms);
show2(die_code);
#define set(value, reg) \ #define set(value, reg) \
static ssize_t set_##value(struct device *dev, const char *buf, size_t count) \ static ssize_t set_##value(struct device *dev, const char *buf, size_t count) \
......
/*
lm78.c - Part of lm_sensors, Linux kernel modules for hardware
monitoring
Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/i2c.h>
#include <linux/i2c-sensor.h>
#include <asm/io.h>
/* Addresses to scan */
static unsigned short normal_i2c[] = { I2C_CLIENT_END };
static unsigned short normal_i2c_range[] = { 0x20, 0x2f, I2C_CLIENT_END };
static unsigned int normal_isa[] = { 0x0290, I2C_CLIENT_ISA_END };
static unsigned int normal_isa_range[] = { I2C_CLIENT_ISA_END };
/* Insmod parameters */
SENSORS_INSMOD_3(lm78, lm78j, lm79);
/* Many LM78 constants specified below */
/* Length of ISA address segment */
#define LM78_EXTENT 8
/* Where are the ISA address/data registers relative to the base address */
#define LM78_ADDR_REG_OFFSET 5
#define LM78_DATA_REG_OFFSET 6
/* The LM78 registers */
#define LM78_REG_IN_MAX(nr) (0x2b + (nr) * 2)
#define LM78_REG_IN_MIN(nr) (0x2c + (nr) * 2)
#define LM78_REG_IN(nr) (0x20 + (nr))
#define LM78_REG_FAN_MIN(nr) (0x3b + (nr))
#define LM78_REG_FAN(nr) (0x28 + (nr))
#define LM78_REG_TEMP 0x27
#define LM78_REG_TEMP_OVER 0x39
#define LM78_REG_TEMP_HYST 0x3a
#define LM78_REG_ALARM1 0x41
#define LM78_REG_ALARM2 0x42
#define LM78_REG_VID_FANDIV 0x47
#define LM78_REG_CONFIG 0x40
#define LM78_REG_CHIPID 0x49
#define LM78_REG_I2C_ADDR 0x48
/* Conversions. Rounding and limit checking is only done on the TO_REG
variants. */
/* IN: mV, (0V to 4.08V)
REG: 16mV/bit */
static inline u8 IN_TO_REG(unsigned long val)
{
unsigned long nval = SENSORS_LIMIT(val, 0, 4080);
return (nval + 8) / 16;
}
#define IN_FROM_REG(val) ((val) * 16)
static 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);
}
static inline int FAN_FROM_REG(u8 val, int div)
{
return val==0 ? -1 : val==255 ? 0 : 1350000/(val*div);
}
/* TEMP: mC (-128C to +127C)
REG: 1C/bit, two's complement */
static inline u8 TEMP_TO_REG(int val)
{
int nval = SENSORS_LIMIT(val, -128000, 127000) ;
return nval<0 ? (nval-500)/1000+0x100 : (nval+500)/1000;
}
static inline int TEMP_FROM_REG(u8 val)
{
return (val>=0x80 ? val-0x100 : val) * 1000;
}
/* VID: mV
REG: (see doc/vid) */
static inline int VID_FROM_REG(u8 val)
{
return val==0x1f ? 0 : val>=0x10 ? 5100-val*100 : 2050-val*50;
}
/* ALARMS: chip-specific bitmask
REG: (same) */
#define ALARMS_FROM_REG(val) (val)
/* FAN DIV: 1, 2, 4, or 8 (defaults to 2)
REG: 0, 1, 2, or 3 (respectively) (defaults to 1) */
static inline u8 DIV_TO_REG(int val)
{
return val==8 ? 3 : val==4 ? 2 : val==1 ? 0 : 1;
}
#define DIV_FROM_REG(val) (1 << (val))
/* Initial limits. To keep them sane, we use the 'standard' translation as
specified in the LM78 sheet. Use the config file to set better limits. */
#define LM78_INIT_IN_0(vid) ((vid)==3500 ? 2800 : (vid))
#define LM78_INIT_IN_1(vid) ((vid)==3500 ? 2800 : (vid))
#define LM78_INIT_IN_2 3300
#define LM78_INIT_IN_3 (((5000) * 100)/168)
#define LM78_INIT_IN_4 (((12000) * 10)/38)
#define LM78_INIT_IN_5 (((-12000) * -604)/2100)
#define LM78_INIT_IN_6 (((-5000) * -604)/909)
#define LM78_INIT_IN_PERCENTAGE 10
#define LM78_INIT_IN_MIN_0(vid) (LM78_INIT_IN_0(vid) - \
LM78_INIT_IN_0(vid) * LM78_INIT_IN_PERCENTAGE / 100)
#define LM78_INIT_IN_MAX_0(vid) (LM78_INIT_IN_0(vid) + \
LM78_INIT_IN_0(vid) * LM78_INIT_IN_PERCENTAGE / 100)
#define LM78_INIT_IN_MIN_1(vid) (LM78_INIT_IN_1(vid) - \
LM78_INIT_IN_1(vid) * LM78_INIT_IN_PERCENTAGE / 100)
#define LM78_INIT_IN_MAX_1(vid) (LM78_INIT_IN_1(vid) + \
LM78_INIT_IN_1(vid) * LM78_INIT_IN_PERCENTAGE / 100)
#define LM78_INIT_IN_MIN_2 \
(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)
#define LM78_INIT_IN_MIN_3 \
(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)
#define LM78_INIT_IN_MIN_4 \
(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)
#define LM78_INIT_IN_MIN_5 \
(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)
#define LM78_INIT_IN_MIN_6 \
(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)
#define LM78_INIT_FAN_MIN_1 3000
#define LM78_INIT_FAN_MIN_2 3000
#define LM78_INIT_FAN_MIN_3 3000
#define LM78_INIT_TEMP_OVER 60000
#define LM78_INIT_TEMP_HYST 50000
/* 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
those cases separately at some places. Second, there might be several
LM78 chips available (well, actually, that is probably never done; but
it is a clean illustration of how to handle a case like that). Finally,
a specific chip may be attached to *both* ISA and SMBus, and we would
not like to detect it double. Fortunately, in the case of the LM78 at
least, a register tells us what SMBus address we are on, so that helps
a bit - except if there could be more than one SMBus. Groan. No solution
for this yet. */
/* 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
some corners. */
/* For each registered LM78, we need to keep some data in memory. That
data is pointed to by lm78_list[NR]->data. The structure itself is
dynamically allocated, at the same time when a new lm78 client is
allocated. */
struct lm78_data {
struct semaphore lock;
enum chips type;
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 */
};
static int lm78_attach_adapter(struct i2c_adapter *adapter);
static int lm78_detect(struct i2c_adapter *adapter, int address, int kind);
static int lm78_detach_client(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 void lm78_update_client(struct i2c_client *client);
static void lm78_init_client(struct i2c_client *client);
static struct i2c_driver lm78_driver = {
.owner = THIS_MODULE,
.name = "lm78",
.id = I2C_DRIVERID_LM78,
.flags = I2C_DF_NOTIFY,
.attach_adapter = lm78_attach_adapter,
.detach_client = lm78_detach_client,
};
/* 7 Voltages */
static ssize_t show_in(struct device *dev, char *buf, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
}
static ssize_t show_in_min(struct device *dev, char *buf, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
}
static ssize_t show_in_max(struct device *dev, char *buf, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
}
static ssize_t set_in_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10);
data->in_min[nr] = IN_TO_REG(val);
lm78_write_value(client, LM78_REG_IN_MIN(nr), data->in_min[nr]);
return count;
}
static ssize_t set_in_max(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10);
data->in_max[nr] = IN_TO_REG(val);
lm78_write_value(client, LM78_REG_IN_MAX(nr), data->in_max[nr]);
return count;
}
#define show_in_offset(offset) \
static ssize_t \
show_in##offset (struct device *dev, char *buf) \
{ \
return show_in(dev, buf, 0x##offset); \
} \
static DEVICE_ATTR(in_input##offset, S_IRUGO, \
show_in##offset, NULL) \
static ssize_t \
show_in##offset##_min (struct device *dev, char *buf) \
{ \
return show_in_min(dev, buf, 0x##offset); \
} \
static ssize_t \
show_in##offset##_max (struct device *dev, char *buf) \
{ \
return show_in_max(dev, buf, 0x##offset); \
} \
static ssize_t set_in##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_min(dev, buf, count, 0x##offset); \
} \
static ssize_t set_in##offset##_max (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_in_max(dev, buf, count, 0x##offset); \
} \
static DEVICE_ATTR(in_min##offset, S_IRUGO | S_IWUSR, \
show_in##offset##_min, set_in##offset##_min) \
static DEVICE_ATTR(in_max##offset, S_IRUGO | S_IWUSR, \
show_in##offset##_max, set_in##offset##_max)
show_in_offset(0);
show_in_offset(1);
show_in_offset(2);
show_in_offset(3);
show_in_offset(4);
show_in_offset(5);
show_in_offset(6);
/* Temperature */
static ssize_t show_temp(struct device *dev, char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp));
}
static ssize_t show_temp_over(struct device *dev, char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_over));
}
static ssize_t set_temp_over(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10);
data->temp_over = TEMP_TO_REG(val);
lm78_write_value(client, LM78_REG_TEMP_OVER, data->temp_over);
return count;
}
static ssize_t show_temp_hyst(struct device *dev, char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_hyst));
}
static ssize_t set_temp_hyst(struct device *dev, const char *buf, size_t count)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10);
data->temp_hyst = TEMP_TO_REG(val);
lm78_write_value(client, LM78_REG_TEMP_HYST, data->temp_hyst);
return count;
}
static DEVICE_ATTR(temp_input, S_IRUGO, show_temp, NULL)
static DEVICE_ATTR(temp_max, S_IRUGO | S_IWUSR,
show_temp_over, set_temp_over)
static DEVICE_ATTR(temp_min, S_IRUGO | S_IWUSR,
show_temp_hyst, set_temp_hyst)
/* 3 Fans */
static ssize_t show_fan(struct device *dev, char *buf, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
DIV_FROM_REG(data->fan_div[nr])) );
}
static ssize_t show_fan_min(struct device *dev, char *buf, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan_min[nr],
DIV_FROM_REG(data->fan_div[nr])) );
}
static ssize_t set_fan_min(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
unsigned long val = simple_strtoul(buf, NULL, 10);
data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]);
return count;
}
static ssize_t show_fan_div(struct device *dev, char *buf, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]) );
}
/* Note: we save and restore the fan minimum here, because its value is
determined in part by the fan divisor. This follows the principle of
least suprise; the user doesn't expect the fan minimum to change just
because the divisor changed. */
static ssize_t set_fan_div(struct device *dev, const char *buf,
size_t count, int nr)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
unsigned long min = FAN_FROM_REG(data->fan_min[nr],
DIV_FROM_REG(data->fan_div[nr]));
unsigned long val = simple_strtoul(buf, NULL, 10);
int reg = lm78_read_value(client, LM78_REG_VID_FANDIV);
data->fan_div[nr] = DIV_TO_REG(val);
switch (nr) {
case 0:
reg = (reg & 0xcf) | (data->fan_div[nr] << 4);
break;
case 1:
reg = (reg & 0x3f) | (data->fan_div[nr] << 6);
break;
}
lm78_write_value(client, LM78_REG_VID_FANDIV, reg);
data->fan_min[nr] =
FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
lm78_write_value(client, LM78_REG_FAN_MIN(nr), data->fan_min[nr]);
return count;
}
#define show_fan_offset(offset) \
static ssize_t show_fan_##offset (struct device *dev, char *buf) \
{ \
return show_fan(dev, buf, 0x##offset - 1); \
} \
static ssize_t show_fan_##offset##_min (struct device *dev, char *buf) \
{ \
return show_fan_min(dev, buf, 0x##offset - 1); \
} \
static ssize_t show_fan_##offset##_div (struct device *dev, char *buf) \
{ \
return show_fan_div(dev, buf, 0x##offset - 1); \
} \
static ssize_t set_fan_##offset##_min (struct device *dev, \
const char *buf, size_t count) \
{ \
return set_fan_min(dev, buf, count, 0x##offset - 1); \
} \
static DEVICE_ATTR(fan_input##offset, S_IRUGO, show_fan_##offset, NULL) \
static DEVICE_ATTR(fan_min##offset, S_IRUGO | S_IWUSR, \
show_fan_##offset##_min, set_fan_##offset##_min)
static ssize_t set_fan_1_div(struct device *dev, const char *buf,
size_t count)
{
return set_fan_div(dev, buf, count, 0) ;
}
static ssize_t set_fan_2_div(struct device *dev, const char *buf,
size_t count)
{
return set_fan_div(dev, buf, count, 1) ;
}
show_fan_offset(1);
show_fan_offset(2);
show_fan_offset(3);
/* Fan 3 divisor is locked in H/W */
static DEVICE_ATTR(fan_div1, S_IRUGO | S_IWUSR,
show_fan_1_div, set_fan_1_div)
static DEVICE_ATTR(fan_div2, S_IRUGO | S_IWUSR,
show_fan_2_div, set_fan_2_div)
static DEVICE_ATTR(fan_div3, S_IRUGO, show_fan_3_div, NULL)
/* VID */
static ssize_t show_vid(struct device *dev, char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", VID_FROM_REG(data->vid));
}
static DEVICE_ATTR(vid, S_IRUGO, show_vid, NULL);
/* Alarms */
static ssize_t show_alarms(struct device *dev, char *buf)
{
struct i2c_client *client = to_i2c_client(dev);
struct lm78_data *data = i2c_get_clientdata(client);
lm78_update_client(client);
return sprintf(buf, "%d\n", ALARMS_FROM_REG(data->alarms));
}
static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
/* This function is called when:
* lm78_driver is inserted (when this module is loaded), for each
available adapter
* when a new adapter is inserted (and lm78_driver is still present) */
static int lm78_attach_adapter(struct i2c_adapter *adapter)
{
if (!(adapter->class & I2C_ADAP_CLASS_SMBUS))
return 0;
return i2c_detect(adapter, &addr_data, lm78_detect);
}
/* This function is called by i2c_detect */
int lm78_detect(struct i2c_adapter *adapter, int address, int kind)
{
int i, err;
struct i2c_client *new_client;
struct lm78_data *data;
const char *client_name = "";
int is_isa = i2c_is_isa_adapter(adapter);
if (!is_isa &&
!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
err = -ENODEV;
goto ERROR0;
}
/* Reserve the ISA region */
if (is_isa)
if (!request_region(address, LM78_EXTENT, "lm78")) {
err = -EBUSY;
goto ERROR0;
}
/* 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) {
err = -ENODEV;
goto ERROR1;
}
if (inb_p(address + 3) != i) {
err = -ENODEV;
goto ERROR1;
}
if (inb_p(address + 7) != i) {
err = -ENODEV;
goto ERROR1;
}
#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);
err = -ENODEV;
goto ERROR1;
}
}
}
/* 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. */
if (!(new_client = kmalloc((sizeof(struct i2c_client)) +
sizeof(struct lm78_data),
GFP_KERNEL))) {
err = -ENOMEM;
goto ERROR1;
}
memset(new_client, 0, sizeof(struct i2c_client) +
sizeof(struct lm78_data));
data = (struct lm78_data *) (new_client + 1);
if (is_isa)
init_MUTEX(&data->lock);
i2c_set_clientdata(new_client, data);
new_client->addr = address;
new_client->adapter = adapter;
new_client->driver = &lm78_driver;
new_client->flags = 0;
/* Now, we do the remaining detection. */
if (kind < 0) {
if (lm78_read_value(new_client, LM78_REG_CONFIG) & 0x80) {
err = -ENODEV;
goto ERROR2;
}
if (!is_isa && (lm78_read_value(
new_client, LM78_REG_I2C_ADDR) != address)) {
err = -ENODEV;
goto ERROR2;
}
}
/* Determine the chip type. */
if (kind <= 0) {
i = lm78_read_value(new_client, LM78_REG_CHIPID);
if (i == 0x00 || i == 0x20)
kind = lm78;
else if (i == 0x40)
kind = lm78j;
else if ((i & 0xfe) == 0xc0)
kind = lm79;
else {
if (kind == 0)
printk(KERN_WARNING "lm78.o: Ignoring 'force' "
"parameter for unknown chip at "
"adapter %d, address 0x%02x\n",
i2c_adapter_id(adapter), address);
err = -ENODEV;
goto ERROR2;
}
}
if (kind == lm78) {
client_name = "LM78 chip";
} else if (kind == lm78j) {
client_name = "LM78-J chip";
} else if (kind == lm79) {
client_name = "LM79 chip";
} else {
dev_dbg(&adapter->dev, "Internal error: unknown kind (%d)?!?",
kind);
err = -ENODEV;
goto ERROR2;
}
/* Fill in the remaining client fields and put into the global list */
strlcpy(new_client->dev.name, client_name, DEVICE_NAME_SIZE);
data->type = kind;
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 ERROR2;
/* register sysfs hooks */
device_create_file(&new_client->dev, &dev_attr_in_input0);
device_create_file(&new_client->dev, &dev_attr_in_min0);
device_create_file(&new_client->dev, &dev_attr_in_max0);
device_create_file(&new_client->dev, &dev_attr_in_input1);
device_create_file(&new_client->dev, &dev_attr_in_min1);
device_create_file(&new_client->dev, &dev_attr_in_max1);
device_create_file(&new_client->dev, &dev_attr_in_input2);
device_create_file(&new_client->dev, &dev_attr_in_min2);
device_create_file(&new_client->dev, &dev_attr_in_max2);
device_create_file(&new_client->dev, &dev_attr_in_input3);
device_create_file(&new_client->dev, &dev_attr_in_min3);
device_create_file(&new_client->dev, &dev_attr_in_max3);
device_create_file(&new_client->dev, &dev_attr_in_input4);
device_create_file(&new_client->dev, &dev_attr_in_min4);
device_create_file(&new_client->dev, &dev_attr_in_max4);
device_create_file(&new_client->dev, &dev_attr_in_input5);
device_create_file(&new_client->dev, &dev_attr_in_min5);
device_create_file(&new_client->dev, &dev_attr_in_max5);
device_create_file(&new_client->dev, &dev_attr_in_input6);
device_create_file(&new_client->dev, &dev_attr_in_min6);
device_create_file(&new_client->dev, &dev_attr_in_max6);
device_create_file(&new_client->dev, &dev_attr_temp_input);
device_create_file(&new_client->dev, &dev_attr_temp_min);
device_create_file(&new_client->dev, &dev_attr_temp_max);
device_create_file(&new_client->dev, &dev_attr_fan_input1);
device_create_file(&new_client->dev, &dev_attr_fan_min1);
device_create_file(&new_client->dev, &dev_attr_fan_div1);
device_create_file(&new_client->dev, &dev_attr_fan_input2);
device_create_file(&new_client->dev, &dev_attr_fan_min2);
device_create_file(&new_client->dev, &dev_attr_fan_div2);
device_create_file(&new_client->dev, &dev_attr_fan_input3);
device_create_file(&new_client->dev, &dev_attr_fan_min3);
device_create_file(&new_client->dev, &dev_attr_fan_div3);
device_create_file(&new_client->dev, &dev_attr_alarms);
device_create_file(&new_client->dev, &dev_attr_vid);
/* Initialize the LM78 chip */
lm78_init_client(new_client);
return 0;
ERROR2:
kfree(new_client);
ERROR1:
if (is_isa)
release_region(address, LM78_EXTENT);
ERROR0:
return err;
}
static int lm78_detach_client(struct i2c_client *client)
{
int err;
/* release ISA region first */
if(i2c_is_isa_client(client))
release_region(client->addr, LM78_EXTENT);
/* now it's safe to scrap the rest */
if ((err = i2c_detach_client(client))) {
dev_err(&client->dev,
"Client deregistration failed, client not detached.\n");
return err;
}
kfree(client);
return 0;
}
/* 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
separately.
We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks,
would slow down the LM78 access and should not be necessary.
There are some ugly typecasts here, but the good new is - they should
nowhere else be necessary! */
static int lm78_read_value(struct i2c_client *client, u8 reg)
{
int res;
if (i2c_is_isa_client(client)) {
struct lm78_data *data = i2c_get_clientdata(client);
down(&data->lock);
outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET);
res = inb_p(client->addr + LM78_DATA_REG_OFFSET);
up(&data->lock);
return res;
} else
return i2c_smbus_read_byte_data(client, reg);
}
/* The SMBus locks itself, but ISA access muse be locked explicitely!
We don't want to lock the whole ISA bus, so we lock each client
separately.
We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks,
would slow down the LM78 access and should not be necessary.
There are some ugly typecasts here, but the good new is - they should
nowhere else be necessary! */
static int lm78_write_value(struct i2c_client *client, u8 reg, u8 value)
{
if (i2c_is_isa_client(client)) {
struct lm78_data *data = i2c_get_clientdata(client);
down(&data->lock);
outb_p(reg, client->addr + LM78_ADDR_REG_OFFSET);
outb_p(value, client->addr + LM78_DATA_REG_OFFSET);
up(&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. */
static void lm78_init_client(struct i2c_client *client)
{
struct lm78_data *data = i2c_get_clientdata(client);
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);
vid = lm78_read_value(client, LM78_REG_VID_FANDIV) & 0x0f;
if (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(vid)));
lm78_write_value(client, LM78_REG_IN_MAX(0),
IN_TO_REG(LM78_INIT_IN_MAX_0(vid)));
lm78_write_value(client, LM78_REG_IN_MIN(1),
IN_TO_REG(LM78_INIT_IN_MIN_1(vid)));
lm78_write_value(client, LM78_REG_IN_MAX(1),
IN_TO_REG(LM78_INIT_IN_MAX_1(vid)));
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(0),
FAN_TO_REG(LM78_INIT_FAN_MIN_1, 2));
lm78_write_value(client, LM78_REG_FAN_MIN(1),
FAN_TO_REG(LM78_INIT_FAN_MIN_2, 2));
lm78_write_value(client, LM78_REG_FAN_MIN(2),
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);
}
static void lm78_update_client(struct i2c_client *client)
{
struct lm78_data *data = i2c_get_clientdata(client);
int i;
down(&data->update_lock);
if ((jiffies - data->last_updated > HZ + HZ / 2) ||
(jiffies < data->last_updated) || !data->valid) {
dev_dbg(&client->dev, "Starting lm78 update\n");
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 = 0; i < 3; i++) {
data->fan[i] =
lm78_read_value(client, LM78_REG_FAN(i));
data->fan_min[i] =
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;
}
up(&data->update_lock);
}
static int __init sm_lm78_init(void)
{
return i2c_add_driver(&lm78_driver);
}
static void __exit sm_lm78_exit(void)
{
i2c_del_driver(&lm78_driver);
}
MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>");
MODULE_DESCRIPTION("LM78, LM78-J and LM79 driver");
MODULE_LICENSE("GPL");
module_init(sm_lm78_init);
module_exit(sm_lm78_exit);
...@@ -148,20 +148,17 @@ static int lm85_scaling[] = { /* .001 Volts */ ...@@ -148,20 +148,17 @@ static int lm85_scaling[] = { /* .001 Volts */
#define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from)) #define SCALE(val,from,to) (((val)*(to) + ((from)/2))/(from))
#define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,lm85_scaling[n],192),0,255)) #define INS_TO_REG(n,val) (SENSORS_LIMIT(SCALE(val,lm85_scaling[n],192),0,255))
#define INSEXT_FROM_REG(n,val,ext) (SCALE((val)*4 + (ext),192*4,lm85_scaling[n])) #define INSEXT_FROM_REG(n,val,ext) (SCALE((val)*4 + (ext),192*4,lm85_scaling[n]))
/*
#define INS_FROM_REG(n,val) (INSEXT_FROM_REG(n,val,0)) #define INS_FROM_REG(n,val) (INSEXT_FROM_REG(n,val,0))
*/
#define INS_FROM_REG(n,val) ( ( (val*4*lm85_scaling[n]) + (192*4/2) ) / (192*4) )
/* FAN speed is measured using 90kHz clock */ /* FAN speed is measured using 90kHz clock */
#define FAN_TO_REG(val) (SENSORS_LIMIT( (val)<=0?0: 5400000/(val),0,65534)) #define FAN_TO_REG(val) (SENSORS_LIMIT( (val)<=0?0: 5400000/(val),0,65534))
#define FAN_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:5400000/(val)) #define FAN_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:5400000/(val))
/* Temperature is reported in .01 degC increments */ /* Temperature is reported in .001 degC increments */
#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+50)/100,-127,127)) #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)+500)/1000,-127,127))
#define TEMPEXT_FROM_REG(val,ext) ((val)*100 + (ext)*25) #define TEMPEXT_FROM_REG(val,ext) ((val)*1000 + (ext)*250)
#define TEMP_FROM_REG(val) (TEMPEXT_FROM_REG(val,0)) #define TEMP_FROM_REG(val) (TEMPEXT_FROM_REG(val,0))
#define EXTTEMP_TO_REG(val) (SENSORS_LIMIT((val)/25,-127,127)) #define EXTTEMP_TO_REG(val) (SENSORS_LIMIT((val)/250,-127,127))
#define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255)) #define PWM_TO_REG(val) (SENSORS_LIMIT(val,0,255))
#define PWM_FROM_REG(val) (val) #define PWM_FROM_REG(val) (val)
...@@ -437,10 +434,13 @@ static ssize_t set_fan_min(struct device *dev, const char *buf, ...@@ -437,10 +434,13 @@ static ssize_t set_fan_min(struct device *dev, const char *buf,
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
int val;
int val = simple_strtol(buf, NULL, 10); down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->fan_min[nr] = FAN_TO_REG(val); data->fan_min[nr] = FAN_TO_REG(val);
lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]); lm85_write_value(client, LM85_REG_FAN_MIN(nr), data->fan_min[nr]);
up(&data->update_lock);
return count; return count;
} }
...@@ -528,10 +528,13 @@ static ssize_t set_pwm(struct device *dev, const char *buf, ...@@ -528,10 +528,13 @@ static ssize_t set_pwm(struct device *dev, const char *buf,
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
int val;
int val = simple_strtol(buf, NULL, 10); down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->pwm[nr] = PWM_TO_REG(val); data->pwm[nr] = PWM_TO_REG(val);
lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]); lm85_write_value(client, LM85_REG_PWM(nr), data->pwm[nr]);
up(&data->update_lock);
return count; return count;
} }
static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr) static ssize_t show_pwm_enable(struct device *dev, char *buf, int nr)
...@@ -590,10 +593,13 @@ static ssize_t set_in_min(struct device *dev, const char *buf, ...@@ -590,10 +593,13 @@ static ssize_t set_in_min(struct device *dev, const char *buf,
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
int val;
int val = simple_strtol(buf, NULL, 10); down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_min[nr] = INS_TO_REG(nr, val); data->in_min[nr] = INS_TO_REG(nr, val);
lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]); lm85_write_value(client, LM85_REG_IN_MIN(nr), data->in_min[nr]);
up(&data->update_lock);
return count; return count;
} }
static ssize_t show_in_max(struct device *dev, char *buf, int nr) static ssize_t show_in_max(struct device *dev, char *buf, int nr)
...@@ -609,10 +615,13 @@ static ssize_t set_in_max(struct device *dev, const char *buf, ...@@ -609,10 +615,13 @@ static ssize_t set_in_max(struct device *dev, const char *buf,
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
int val;
int val = simple_strtol(buf, NULL, 10); down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->in_max[nr] = INS_TO_REG(nr, val); data->in_max[nr] = INS_TO_REG(nr, val);
lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]); lm85_write_value(client, LM85_REG_IN_MAX(nr), data->in_max[nr]);
up(&data->update_lock);
return count; return count;
} }
#define show_in_reg(offset) \ #define show_in_reg(offset) \
...@@ -673,10 +682,13 @@ static ssize_t set_temp_min(struct device *dev, const char *buf, ...@@ -673,10 +682,13 @@ static ssize_t set_temp_min(struct device *dev, const char *buf,
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
int val;
int val = simple_strtol(buf, NULL, 10); down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_min[nr] = TEMP_TO_REG(val); data->temp_min[nr] = TEMP_TO_REG(val);
lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]); lm85_write_value(client, LM85_REG_TEMP_MIN(nr), data->temp_min[nr]);
up(&data->update_lock);
return count; return count;
} }
static ssize_t show_temp_max(struct device *dev, char *buf, int nr) static ssize_t show_temp_max(struct device *dev, char *buf, int nr)
...@@ -692,10 +704,13 @@ static ssize_t set_temp_max(struct device *dev, const char *buf, ...@@ -692,10 +704,13 @@ static ssize_t set_temp_max(struct device *dev, const char *buf,
{ {
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm85_data *data = i2c_get_clientdata(client); struct lm85_data *data = i2c_get_clientdata(client);
int val;
int val = simple_strtol(buf, NULL, 10); down(&data->update_lock);
val = simple_strtol(buf, NULL, 10);
data->temp_max[nr] = TEMP_TO_REG(val); data->temp_max[nr] = TEMP_TO_REG(val);
lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]); lm85_write_value(client, LM85_REG_TEMP_MAX(nr), data->temp_max[nr]);
up(&data->update_lock);
return count; return count;
} }
#define show_temp_reg(offset) \ #define show_temp_reg(offset) \
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
asb100 "bach" (type_name = as99127f) 0x30 0x0694 yes no asb100 "bach" (type_name = as99127f) 0x30 0x0694 yes no
w83781d 7 3 0 3 0x10 0x5ca3 yes yes w83781d 7 3 0 3 0x10 0x5ca3 yes yes
w83627hf 9 3 2 3 0x20 0x5ca3 yes yes(LPC) w83627hf 9 3 2 3 0x20 0x5ca3 yes yes(LPC)
w83627thf 9 3 2 3 0x90 0x5ca3 no yes(LPC)
w83782d 9 3 2-4 3 0x30 0x5ca3 yes yes w83782d 9 3 2-4 3 0x30 0x5ca3 yes yes
w83783s 5-6 3 2 1-2 0x40 0x5ca3 yes no w83783s 5-6 3 2 1-2 0x40 0x5ca3 yes no
w83697hf 8 2 2 2 0x60 0x5ca3 no yes(LPC) w83697hf 8 2 2 2 0x60 0x5ca3 no yes(LPC)
...@@ -299,8 +300,8 @@ struct w83781d_data { ...@@ -299,8 +300,8 @@ struct w83781d_data {
char valid; /* !=0 if following fields are valid */ char valid; /* !=0 if following fields are valid */
unsigned long last_updated; /* In jiffies */ unsigned long last_updated; /* In jiffies */
struct i2c_client *lm75; /* for secondary I2C addresses */ struct i2c_client *lm75[2]; /* for secondary I2C addresses */
/* pointer to array of 2 subclients */ /* array of 2 pointers to subclients */
u8 in[9]; /* Register value - 8 & 9 for 782D only */ u8 in[9]; /* Register value - 8 & 9 for 782D only */
u8 in_max[9]; /* Register value - 8 & 9 for 782D only */ u8 in_max[9]; /* Register value - 8 & 9 for 782D only */
...@@ -1043,12 +1044,12 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, ...@@ -1043,12 +1044,12 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
const char *client_name; const char *client_name;
struct w83781d_data *data = i2c_get_clientdata(new_client); struct w83781d_data *data = i2c_get_clientdata(new_client);
if (!(data->lm75 = kmalloc(2 * sizeof (struct i2c_client), data->lm75[0] = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
GFP_KERNEL))) { if (!(data->lm75[0])) {
err = -ENOMEM; err = -ENOMEM;
goto ERROR_SC_0; goto ERROR_SC_0;
} }
memset(data->lm75, 0x00, 2 * sizeof (struct i2c_client)); memset(data->lm75[0], 0x00, sizeof (struct i2c_client));
id = i2c_adapter_id(adapter); id = i2c_adapter_id(adapter);
...@@ -1066,25 +1067,33 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, ...@@ -1066,25 +1067,33 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
w83781d_write_value(new_client, W83781D_REG_I2C_SUBADDR, w83781d_write_value(new_client, W83781D_REG_I2C_SUBADDR,
(force_subclients[2] & 0x07) | (force_subclients[2] & 0x07) |
((force_subclients[3] & 0x07) << 4)); ((force_subclients[3] & 0x07) << 4));
data->lm75[0].addr = force_subclients[2]; data->lm75[0]->addr = force_subclients[2];
} else { } else {
val1 = w83781d_read_value(new_client, W83781D_REG_I2C_SUBADDR); val1 = w83781d_read_value(new_client, W83781D_REG_I2C_SUBADDR);
data->lm75[0].addr = 0x48 + (val1 & 0x07); data->lm75[0]->addr = 0x48 + (val1 & 0x07);
} }
if (kind != w83783s) { if (kind != w83783s) {
data->lm75[1] = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
if (!(data->lm75[1])) {
err = -ENOMEM;
goto ERROR_SC_1;
}
memset(data->lm75[1], 0x0, sizeof(struct i2c_client));
if (force_subclients[0] == id && if (force_subclients[0] == id &&
force_subclients[1] == address) { force_subclients[1] == address) {
data->lm75[1].addr = force_subclients[3]; data->lm75[1]->addr = force_subclients[3];
} else { } else {
data->lm75[1].addr = 0x48 + ((val1 >> 4) & 0x07); data->lm75[1]->addr = 0x48 + ((val1 >> 4) & 0x07);
} }
if (data->lm75[0].addr == data->lm75[1].addr) { if (data->lm75[0]->addr == data->lm75[1]->addr) {
dev_err(&new_client->dev, dev_err(&new_client->dev,
"Duplicate addresses 0x%x for subclients.\n", "Duplicate addresses 0x%x for subclients.\n",
data->lm75[0].addr); data->lm75[0]->addr);
err = -EBUSY; err = -EBUSY;
goto ERROR_SC_1; goto ERROR_SC_2;
} }
} }
...@@ -1103,19 +1112,19 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, ...@@ -1103,19 +1112,19 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
for (i = 0; i <= 1; i++) { for (i = 0; i <= 1; i++) {
/* store all data in w83781d */ /* store all data in w83781d */
i2c_set_clientdata(&data->lm75[i], NULL); i2c_set_clientdata(data->lm75[i], NULL);
data->lm75[i].adapter = adapter; data->lm75[i]->adapter = adapter;
data->lm75[i].driver = &w83781d_driver; data->lm75[i]->driver = &w83781d_driver;
data->lm75[i].flags = 0; data->lm75[i]->flags = 0;
strlcpy(data->lm75[i].dev.name, client_name, strlcpy(data->lm75[i]->dev.name, client_name,
DEVICE_NAME_SIZE); DEVICE_NAME_SIZE);
if ((err = i2c_attach_client(&(data->lm75[i])))) { if ((err = i2c_attach_client(data->lm75[i]))) {
dev_err(&new_client->dev, "Subclient %d " dev_err(&new_client->dev, "Subclient %d "
"registration at address 0x%x " "registration at address 0x%x "
"failed.\n", i, data->lm75[i].addr); "failed.\n", i, data->lm75[i]->addr);
if (i == 1) if (i == 1)
goto ERROR_SC_3;
goto ERROR_SC_2; goto ERROR_SC_2;
goto ERROR_SC_1;
} }
if (kind == w83783s) if (kind == w83783s)
break; break;
...@@ -1124,10 +1133,14 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind, ...@@ -1124,10 +1133,14 @@ w83781d_detect_subclients(struct i2c_adapter *adapter, int address, int kind,
return 0; return 0;
/* Undo inits in case of errors */ /* Undo inits in case of errors */
ERROR_SC_3:
i2c_detach_client(data->lm75[0]);
ERROR_SC_2: ERROR_SC_2:
i2c_detach_client(&(data->lm75[0])); if (NULL != data->lm75[1])
kfree(data->lm75[1]);
ERROR_SC_1: ERROR_SC_1:
kfree(data->lm75); if (NULL != data->lm75[0])
kfree(data->lm75[0]);
ERROR_SC_0: ERROR_SC_0:
return err; return err;
} }
...@@ -1273,7 +1286,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -1273,7 +1286,7 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
kind = w83782d; kind = w83782d;
else if (val1 == 0x40 && vendid == winbond && !is_isa) else if (val1 == 0x40 && vendid == winbond && !is_isa)
kind = w83783s; kind = w83783s;
else if (val1 == 0x20 && vendid == winbond) else if ((val1 == 0x20 || val1 == 0x90) && vendid == winbond)
kind = w83627hf; kind = w83627hf;
else if (val1 == 0x30 && vendid == asus && !is_isa) else if (val1 == 0x30 && vendid == asus && !is_isa)
kind = as99127f; kind = as99127f;
...@@ -1297,6 +1310,9 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -1297,6 +1310,9 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
} else if (kind == w83783s) { } else if (kind == w83783s) {
client_name = "W83783S chip"; client_name = "W83783S chip";
} else if (kind == w83627hf) { } else if (kind == w83627hf) {
if (val1 == 0x90)
client_name = "W83627THF chip";
else
client_name = "W83627HF chip"; client_name = "W83627HF chip";
} else if (kind == as99127f) { } else if (kind == as99127f) {
client_name = "AS99127F chip"; client_name = "AS99127F chip";
...@@ -1326,7 +1342,8 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -1326,7 +1342,8 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
kind, new_client))) kind, new_client)))
goto ERROR3; goto ERROR3;
} else { } else {
data->lm75 = NULL; data->lm75[0] = NULL;
data->lm75[1] = NULL;
} }
device_create_file_in(new_client, 0); device_create_file_in(new_client, 0);
...@@ -1409,20 +1426,11 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind) ...@@ -1409,20 +1426,11 @@ w83781d_detect(struct i2c_adapter *adapter, int address, int kind)
static int static int
w83781d_detach_client(struct i2c_client *client) w83781d_detach_client(struct i2c_client *client)
{ {
struct w83781d_data *data = i2c_get_clientdata(client);
int err; int err;
/* release ISA region or I2C subclients first */ if (i2c_is_isa_client(client))
if (i2c_is_isa_client(client)) {
release_region(client->addr, W83781D_EXTENT); release_region(client->addr, W83781D_EXTENT);
} else {
i2c_detach_client(&data->lm75[0]);
if (data->type != w83783s)
i2c_detach_client(&data->lm75[1]);
kfree(data->lm75);
}
/* now it's safe to scrap the rest */
if ((err = i2c_detach_client(client))) { if ((err = i2c_detach_client(client))) {
dev_err(&client->dev, dev_err(&client->dev,
"Client deregistration failed, client not detached.\n"); "Client deregistration failed, client not detached.\n");
...@@ -1484,7 +1492,7 @@ w83781d_read_value(struct i2c_client *client, u16 reg) ...@@ -1484,7 +1492,7 @@ w83781d_read_value(struct i2c_client *client, u16 reg)
res = i2c_smbus_read_byte_data(client, reg & 0xff); res = i2c_smbus_read_byte_data(client, reg & 0xff);
} else { } else {
/* switch to subclient */ /* switch to subclient */
cl = &data->lm75[bank - 1]; cl = data->lm75[bank - 1];
/* convert from ISA to LM75 I2C addresses */ /* convert from ISA to LM75 I2C addresses */
switch (reg & 0xff) { switch (reg & 0xff) {
case 0x50: /* TEMP */ case 0x50: /* TEMP */
...@@ -1555,7 +1563,7 @@ w83781d_write_value(struct i2c_client *client, u16 reg, u16 value) ...@@ -1555,7 +1563,7 @@ w83781d_write_value(struct i2c_client *client, u16 reg, u16 value)
value & 0xff); value & 0xff);
} else { } else {
/* switch to subclient */ /* switch to subclient */
cl = &data->lm75[bank - 1]; cl = data->lm75[bank - 1];
/* convert from ISA to LM75 I2C addresses */ /* convert from ISA to LM75 I2C addresses */
switch (reg & 0xff) { switch (reg & 0xff) {
case 0x52: /* CONFIG */ case 0x52: /* CONFIG */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment