aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/chips/pcf8591.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/chips/pcf8591.c')
-rw-r--r--drivers/i2c/chips/pcf8591.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c
index 36cff09c678d..925a6b371fd2 100644
--- a/drivers/i2c/chips/pcf8591.c
+++ b/drivers/i2c/chips/pcf8591.c
@@ -24,6 +24,7 @@
24#include <linux/init.h> 24#include <linux/init.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/mutex.h>
27 28
28/* Addresses to scan */ 29/* Addresses to scan */
29static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 30static unsigned short normal_i2c[] = { 0x48, 0x49, 0x4a, 0x4b, 0x4c,
@@ -74,7 +75,7 @@ MODULE_PARM_DESC(input_mode,
74 75
75struct pcf8591_data { 76struct pcf8591_data {
76 struct i2c_client client; 77 struct i2c_client client;
77 struct semaphore update_lock; 78 struct mutex update_lock;
78 79
79 u8 control; 80 u8 control;
80 u8 aout; 81 u8 aout;
@@ -144,13 +145,13 @@ static ssize_t set_out0_enable(struct device *dev, struct device_attribute *attr
144 struct pcf8591_data *data = i2c_get_clientdata(client); 145 struct pcf8591_data *data = i2c_get_clientdata(client);
145 unsigned long val = simple_strtoul(buf, NULL, 10); 146 unsigned long val = simple_strtoul(buf, NULL, 10);
146 147
147 down(&data->update_lock); 148 mutex_lock(&data->update_lock);
148 if (val) 149 if (val)
149 data->control |= PCF8591_CONTROL_AOEF; 150 data->control |= PCF8591_CONTROL_AOEF;
150 else 151 else
151 data->control &= ~PCF8591_CONTROL_AOEF; 152 data->control &= ~PCF8591_CONTROL_AOEF;
152 i2c_smbus_write_byte(client, data->control); 153 i2c_smbus_write_byte(client, data->control);
153 up(&data->update_lock); 154 mutex_unlock(&data->update_lock);
154 return count; 155 return count;
155} 156}
156 157
@@ -200,7 +201,7 @@ static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
200 /* Fill in the remaining client fields and put it into the global 201 /* Fill in the remaining client fields and put it into the global
201 list */ 202 list */
202 strlcpy(new_client->name, "pcf8591", I2C_NAME_SIZE); 203 strlcpy(new_client->name, "pcf8591", I2C_NAME_SIZE);
203 init_MUTEX(&data->update_lock); 204 mutex_init(&data->update_lock);
204 205
205 /* Tell the I2C layer a new client has arrived */ 206 /* Tell the I2C layer a new client has arrived */
206 if ((err = i2c_attach_client(new_client))) 207 if ((err = i2c_attach_client(new_client)))
@@ -265,7 +266,7 @@ static int pcf8591_read_channel(struct device *dev, int channel)
265 struct i2c_client *client = to_i2c_client(dev); 266 struct i2c_client *client = to_i2c_client(dev);
266 struct pcf8591_data *data = i2c_get_clientdata(client); 267 struct pcf8591_data *data = i2c_get_clientdata(client);
267 268
268 down(&data->update_lock); 269 mutex_lock(&data->update_lock);
269 270
270 if ((data->control & PCF8591_CONTROL_AICH_MASK) != channel) { 271 if ((data->control & PCF8591_CONTROL_AICH_MASK) != channel) {
271 data->control = (data->control & ~PCF8591_CONTROL_AICH_MASK) 272 data->control = (data->control & ~PCF8591_CONTROL_AICH_MASK)
@@ -278,7 +279,7 @@ static int pcf8591_read_channel(struct device *dev, int channel)
278 } 279 }
279 value = i2c_smbus_read_byte(client); 280 value = i2c_smbus_read_byte(client);
280 281
281 up(&data->update_lock); 282 mutex_unlock(&data->update_lock);
282 283
283 if ((channel == 2 && input_mode == 2) || 284 if ((channel == 2 && input_mode == 2) ||
284 (channel != 3 && (input_mode == 1 || input_mode == 3))) 285 (channel != 3 && (input_mode == 1 || input_mode == 3)))