Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 104635
b: refs/heads/master
c: 1673ad5
h: refs/heads/master
i:
  104633: 9c962d7
  104631: c12c66d
v: v3
  • Loading branch information
David Brownell authored and Linus Torvalds committed Jul 22, 2008
1 parent 5eb73f1 commit 295401f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 0c36ec31473593aa937ff04f3b3b630e81512734
refs/heads/master: 1673ad52bd9a3c747e596a76e65c55981ea651e3
5 changes: 3 additions & 2 deletions trunk/drivers/gpio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ config GPIO_PCA953X
will be called pca953x.

config GPIO_PCF857X
tristate "PCF857x, PCA857x, and PCA967x I2C GPIO expanders"
tristate "PCF857x, PCA{85,96}7x, and MAX732[89] I2C GPIO expanders"
depends on I2C
help
Say yes here to provide access to most "quasi-bidirectional" I2C
Expand All @@ -54,7 +54,8 @@ config GPIO_PCF857X
some of them. Compatible models include:

8 bits: pcf8574, pcf8574a, pca8574, pca8574a,
pca9670, pca9672, pca9674, pca9674a
pca9670, pca9672, pca9674, pca9674a,
max7328, max7329

16 bits: pcf8575, pcf8575c, pca8575,
pca9671, pca9673, pca9675
Expand Down
33 changes: 29 additions & 4 deletions trunk/drivers/gpio/pcf857x.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 */
};

Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -173,6 +196,8 @@ 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.owner = THIS_MODULE;
Expand Down

0 comments on commit 295401f

Please sign in to comment.