X-Git-Url: http://pilppa.org/gitweb/?a=blobdiff_plain;f=drivers%2Fgpio%2Fpcf857x.c;h=fc9c6ae739ee74f8f77b8836bd5e7894001e5d9d;hb=673c0c00382ed807f09d94e806f3519ddeeb4f70;hp=aa6cc8b2a2bc88afbeca4dec1b67bc75c05288a0;hpb=2a5f2e3e6cd1ce9fb3f8b186b6bc9aa1f1497a92;p=linux-2.6-omap-h63xx.git diff --git a/drivers/gpio/pcf857x.c b/drivers/gpio/pcf857x.c index aa6cc8b2a2b..fc9c6ae739e 100644 --- a/drivers/gpio/pcf857x.c +++ b/drivers/gpio/pcf857x.c @@ -37,6 +37,8 @@ static const struct i2c_device_id pcf857x_id[] = { { "pca9671", 16 }, { "pca9673", 16 }, { "pca9675", 16 }, + { "max7328", 8 }, + { "max7329", 8 }, { } }; MODULE_DEVICE_TABLE(i2c, pcf857x_id); @@ -56,6 +58,7 @@ MODULE_DEVICE_TABLE(i2c, pcf857x_id); struct pcf857x { struct gpio_chip chip; struct i2c_client *client; + struct mutex lock; /* protect 'out' */ unsigned out; /* software latch */ }; @@ -66,9 +69,14 @@ struct pcf857x { static int pcf857x_input8(struct gpio_chip *chip, unsigned offset) { struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); + int status; + mutex_lock(&gpio->lock); gpio->out |= (1 << offset); - return i2c_smbus_write_byte(gpio->client, gpio->out); + status = i2c_smbus_write_byte(gpio->client, gpio->out); + mutex_unlock(&gpio->lock); + + return status; } static 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) { struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); unsigned bit = 1 << offset; + int status; + mutex_lock(&gpio->lock); if (value) gpio->out |= bit; else gpio->out &= ~bit; - return i2c_smbus_write_byte(gpio->client, gpio->out); + status = i2c_smbus_write_byte(gpio->client, gpio->out); + mutex_unlock(&gpio->lock); + + return status; } static void pcf857x_set8(struct gpio_chip *chip, unsigned offset, int value) @@ -124,9 +137,14 @@ static int i2c_read_le16(struct i2c_client *client) static int pcf857x_input16(struct gpio_chip *chip, unsigned offset) { struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); + int status; + mutex_lock(&gpio->lock); gpio->out |= (1 << offset); - return i2c_write_le16(gpio->client, gpio->out); + status = i2c_write_le16(gpio->client, gpio->out); + mutex_unlock(&gpio->lock); + + return status; } static 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) { struct pcf857x *gpio = container_of(chip, struct pcf857x, chip); unsigned bit = 1 << offset; + int status; + mutex_lock(&gpio->lock); if (value) gpio->out |= bit; else gpio->out &= ~bit; - return i2c_write_le16(gpio->client, gpio->out); + status = i2c_write_le16(gpio->client, gpio->out); + mutex_unlock(&gpio->lock); + + return status; } static void pcf857x_set16(struct gpio_chip *chip, unsigned offset, int value) @@ -173,8 +196,11 @@ static int pcf857x_probe(struct i2c_client *client, if (!gpio) return -ENOMEM; + mutex_init(&gpio->lock); + gpio->chip.base = pdata->gpio_base; gpio->chip.can_sleep = 1; + gpio->chip.dev = &client->dev; gpio->chip.owner = THIS_MODULE; /* NOTE: the OnSemi jlc1562b is also largely compatible with