aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/pcf857x.c
diff options
context:
space:
mode:
authorDavid Brownell <dbrownell@users.sourceforge.net>2008-07-21 17:21:34 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-22 12:59:41 -0400
commit1673ad52bd9a3c747e596a76e65c55981ea651e3 (patch)
tree9e018b1d511a96f745fc870bfdf8bf53759c25ae /drivers/gpio/pcf857x.c
parent0c36ec31473593aa937ff04f3b3b630e81512734 (diff)
gpio: pcf857x: add lock and handle more chips
Two small updates to the pcf857x driver: (a) the max732[89] chips are also second sources for the pcf8574/a, and (b) add a mutex to prevent trashing the cached state. Adding the lock is effectively a bugfix, although it seems unlikely that anyone would have run into the issue it protects against. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/gpio/pcf857x.c')
-rw-r--r--drivers/gpio/pcf857x.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/drivers/gpio/pcf857x.c b/drivers/gpio/pcf857x.c
index aa6cc8b2a2bc..d25d356c4f20 100644
--- a/drivers/gpio/pcf857x.c
+++ b/drivers/gpio/pcf857x.c
@@ -37,6 +37,8 @@ static const struct i2c_device_id pcf857x_id[] = {
37 { "pca9671", 16 }, 37 { "pca9671", 16 },
38 { "pca9673", 16 }, 38 { "pca9673", 16 },
39 { "pca9675", 16 }, 39 { "pca9675", 16 },
40 { "max7328", 8 },
41 { "max7329", 8 },
40 { } 42 { }
41}; 43};
42MODULE_DEVICE_TABLE(i2c, pcf857x_id); 44MODULE_DEVICE_TABLE(i2c, pcf857x_id);
@@ -56,6 +58,7 @@ MODULE_DEVICE_TABLE(i2c, pcf857x_id);
56struct pcf857x { 58struct pcf857x {
57 struct gpio_chip chip; 59 struct gpio_chip chip;
58 struct i2c_client *client; 60 struct i2c_client *client;
61 struct mutex lock; /* protect 'out' */
59 unsigned out; /* software latch */ 62 unsigned out; /* software latch */
60}; 63};
61 64
@@ -66,9 +69,14 @@ struct pcf857x {
66static int pcf857x_input8(struct gpio_chip *chip, unsigned offset) 69static int pcf857x_input8(struct gpio_chip *chip, unsigned offset)
67{ 70{
68 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 71 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip);
72 int status;
69 73
74 mutex_lock(&gpio->lock);
70 gpio->out |= (1 << offset); 75 gpio->out |= (1 << offset);
71 return i2c_smbus_write_byte(gpio->client, gpio->out); 76 status = i2c_smbus_write_byte(gpio->client, gpio->out);
77 mutex_unlock(&gpio->lock);
78
79 return status;
72} 80}
73 81
74static int pcf857x_get8(struct gpio_chip *chip, unsigned offset) 82static int pcf857x_get8(struct gpio_chip *chip, unsigned offset)
@@ -84,12 +92,17 @@ static int pcf857x_output8(struct gpio_chip *chip, unsigned offset, int value)
84{ 92{
85 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 93 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip);
86 unsigned bit = 1 << offset; 94 unsigned bit = 1 << offset;
95 int status;
87 96
97 mutex_lock(&gpio->lock);
88 if (value) 98 if (value)
89 gpio->out |= bit; 99 gpio->out |= bit;
90 else 100 else
91 gpio->out &= ~bit; 101 gpio->out &= ~bit;
92 return i2c_smbus_write_byte(gpio->client, gpio->out); 102 status = i2c_smbus_write_byte(gpio->client, gpio->out);
103 mutex_unlock(&gpio->lock);
104
105 return status;
93} 106}
94 107
95static void pcf857x_set8(struct gpio_chip *chip, unsigned offset, int value) 108static void pcf857x_set8(struct gpio_chip *chip, unsigned offset, int value)
@@ -124,9 +137,14 @@ static int i2c_read_le16(struct i2c_client *client)
124static int pcf857x_input16(struct gpio_chip *chip, unsigned offset) 137static int pcf857x_input16(struct gpio_chip *chip, unsigned offset)
125{ 138{
126 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 139 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip);
140 int status;
127 141
142 mutex_lock(&gpio->lock);
128 gpio->out |= (1 << offset); 143 gpio->out |= (1 << offset);
129 return i2c_write_le16(gpio->client, gpio->out); 144 status = i2c_write_le16(gpio->client, gpio->out);
145 mutex_unlock(&gpio->lock);
146
147 return status;
130} 148}
131 149
132static int pcf857x_get16(struct gpio_chip *chip, unsigned offset) 150static int pcf857x_get16(struct gpio_chip *chip, unsigned offset)
@@ -142,12 +160,17 @@ static int pcf857x_output16(struct gpio_chip *chip, unsigned offset, int value)
142{ 160{
143 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); 161 struct pcf857x *gpio = container_of(chip, struct pcf857x, chip);
144 unsigned bit = 1 << offset; 162 unsigned bit = 1 << offset;
163 int status;
145 164
165 mutex_lock(&gpio->lock);
146 if (value) 166 if (value)
147 gpio->out |= bit; 167 gpio->out |= bit;
148 else 168 else
149 gpio->out &= ~bit; 169 gpio->out &= ~bit;
150 return i2c_write_le16(gpio->client, gpio->out); 170 status = i2c_write_le16(gpio->client, gpio->out);
171 mutex_unlock(&gpio->lock);
172
173 return status;
151} 174}
152 175
153static void pcf857x_set16(struct gpio_chip *chip, unsigned offset, int value) 176static void pcf857x_set16(struct gpio_chip *chip, unsigned offset, int value)
@@ -173,6 +196,8 @@ static int pcf857x_probe(struct i2c_client *client,
173 if (!gpio) 196 if (!gpio)
174 return -ENOMEM; 197 return -ENOMEM;
175 198
199 mutex_init(&gpio->lock);
200
176 gpio->chip.base = pdata->gpio_base; 201 gpio->chip.base = pdata->gpio_base;
177 gpio->chip.can_sleep = 1; 202 gpio->chip.can_sleep = 1;
178 gpio->chip.owner = THIS_MODULE; 203 gpio->chip.owner = THIS_MODULE;