mirror of
https://github.com/torvalds/linux.git
synced 2024-12-05 02:23:16 +00:00
hwmon: Simplify the locking model of two drivers
Many hardware monitoring drivers use two different mutexes, one to protect their per-device data structure, and one to protect the access to the device registers. These mutexes are essentially redundant, as the drivers are transfering values between the device registers and the data cache, so they almost always end up holding both mutexes at the same time. Using a single mutex will make the code more simple and faster. I am changing only two of the affected drivers here, the authors of the other affected drivers are welcome to submit similar patches if they want. Signed-off-by: Jean Delvare <khali@linux-fr.org>
This commit is contained in:
parent
6a0b1013c6
commit
7f999aa726
@ -146,7 +146,6 @@ superio_exit(int base)
|
||||
struct f71805f_data {
|
||||
unsigned short addr;
|
||||
const char *name;
|
||||
struct mutex lock;
|
||||
struct class_device *class_dev;
|
||||
|
||||
struct mutex update_lock;
|
||||
@ -271,50 +270,42 @@ static inline u8 temp_to_reg(long val)
|
||||
* Device I/O access
|
||||
*/
|
||||
|
||||
/* Must be called with data->update_lock held, except during initialization */
|
||||
static u8 f71805f_read8(struct f71805f_data *data, u8 reg)
|
||||
{
|
||||
u8 val;
|
||||
|
||||
mutex_lock(&data->lock);
|
||||
outb(reg, data->addr + ADDR_REG_OFFSET);
|
||||
val = inb(data->addr + DATA_REG_OFFSET);
|
||||
mutex_unlock(&data->lock);
|
||||
|
||||
return val;
|
||||
return inb(data->addr + DATA_REG_OFFSET);
|
||||
}
|
||||
|
||||
/* Must be called with data->update_lock held, except during initialization */
|
||||
static void f71805f_write8(struct f71805f_data *data, u8 reg, u8 val)
|
||||
{
|
||||
mutex_lock(&data->lock);
|
||||
outb(reg, data->addr + ADDR_REG_OFFSET);
|
||||
outb(val, data->addr + DATA_REG_OFFSET);
|
||||
mutex_unlock(&data->lock);
|
||||
}
|
||||
|
||||
/* It is important to read the MSB first, because doing so latches the
|
||||
value of the LSB, so we are sure both bytes belong to the same value. */
|
||||
value of the LSB, so we are sure both bytes belong to the same value.
|
||||
Must be called with data->update_lock held, except during initialization */
|
||||
static u16 f71805f_read16(struct f71805f_data *data, u8 reg)
|
||||
{
|
||||
u16 val;
|
||||
|
||||
mutex_lock(&data->lock);
|
||||
outb(reg, data->addr + ADDR_REG_OFFSET);
|
||||
val = inb(data->addr + DATA_REG_OFFSET) << 8;
|
||||
outb(++reg, data->addr + ADDR_REG_OFFSET);
|
||||
val |= inb(data->addr + DATA_REG_OFFSET);
|
||||
mutex_unlock(&data->lock);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
/* Must be called with data->update_lock held, except during initialization */
|
||||
static void f71805f_write16(struct f71805f_data *data, u8 reg, u16 val)
|
||||
{
|
||||
mutex_lock(&data->lock);
|
||||
outb(reg, data->addr + ADDR_REG_OFFSET);
|
||||
outb(val >> 8, data->addr + DATA_REG_OFFSET);
|
||||
outb(++reg, data->addr + ADDR_REG_OFFSET);
|
||||
outb(val & 0xff, data->addr + DATA_REG_OFFSET);
|
||||
mutex_unlock(&data->lock);
|
||||
}
|
||||
|
||||
static struct f71805f_data *f71805f_update_device(struct device *dev)
|
||||
@ -1150,7 +1141,6 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
|
||||
|
||||
res = platform_get_resource(pdev, IORESOURCE_IO, 0);
|
||||
data->addr = res->start;
|
||||
mutex_init(&data->lock);
|
||||
data->name = names[sio_data->kind];
|
||||
mutex_init(&data->update_lock);
|
||||
|
||||
|
@ -221,7 +221,6 @@ static const unsigned int pwm_freq[8] = {
|
||||
struct it87_data {
|
||||
struct i2c_client client;
|
||||
struct class_device *class_dev;
|
||||
struct mutex lock;
|
||||
enum chips type;
|
||||
|
||||
struct mutex update_lock;
|
||||
@ -548,9 +547,10 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct it87_data *data = i2c_get_clientdata(client);
|
||||
int val = simple_strtol(buf, NULL, 10);
|
||||
u8 reg = it87_read_value(client, IT87_REG_FAN_DIV);
|
||||
u8 reg;
|
||||
|
||||
mutex_lock(&data->update_lock);
|
||||
reg = it87_read_value(client, IT87_REG_FAN_DIV);
|
||||
switch (nr) {
|
||||
case 0: data->fan_div[nr] = reg & 0x07; break;
|
||||
case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break;
|
||||
@ -949,7 +949,6 @@ static int it87_detect(struct i2c_adapter *adapter)
|
||||
}
|
||||
|
||||
new_client = &data->client;
|
||||
mutex_init(&data->lock);
|
||||
i2c_set_clientdata(new_client, data);
|
||||
new_client->addr = isa_address;
|
||||
new_client->adapter = adapter;
|
||||
@ -1127,33 +1126,22 @@ static int it87_detach_client(struct i2c_client *client)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ISA access must be locked explicitly!
|
||||
/* Must be called with data->update_lock held, except during initialization.
|
||||
We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
|
||||
would slow down the IT87 access and should not be necessary. */
|
||||
static int it87_read_value(struct i2c_client *client, u8 reg)
|
||||
{
|
||||
struct it87_data *data = i2c_get_clientdata(client);
|
||||
int res;
|
||||
|
||||
mutex_lock(&data->lock);
|
||||
outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
|
||||
res = inb_p(client->addr + IT87_DATA_REG_OFFSET);
|
||||
mutex_unlock(&data->lock);
|
||||
|
||||
return res;
|
||||
return inb_p(client->addr + IT87_DATA_REG_OFFSET);
|
||||
}
|
||||
|
||||
/* ISA access must be locked explicitly!
|
||||
/* Must be called with data->update_lock held, except during initialization.
|
||||
We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
|
||||
would slow down the IT87 access and should not be necessary. */
|
||||
static void it87_write_value(struct i2c_client *client, u8 reg, u8 value)
|
||||
{
|
||||
struct it87_data *data = i2c_get_clientdata(client);
|
||||
|
||||
mutex_lock(&data->lock);
|
||||
outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
|
||||
outb_p(value, client->addr + IT87_DATA_REG_OFFSET);
|
||||
mutex_unlock(&data->lock);
|
||||
}
|
||||
|
||||
/* Return 1 if and only if the PWM interface is safe to use */
|
||||
|
Loading…
Reference in New Issue
Block a user