From 96b70641b937e99c1579cb6ebbcdb7b0af98cdd0 Mon Sep 17 00:00:00 2001 From: Andreas Schallenberg Date: Mon, 21 May 2012 09:52:43 +0200 Subject: gpio/tca6424: merge I2C transactions, remove cast This is a follow-up to ae79c1904 "[PATCH v2] Add support for TCA6424" merged in the v3.5 merge window. It fixes comments made when the patch was merged. - Use 3 byte transfers instead of two separate transfers (2+1 byte) - An unnecessary cast removed Signed-off-by: Andreas Schallenberg Signed-off-by: Grant Likely --- drivers/gpio/gpio-pca953x.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'drivers/gpio/gpio-pca953x.c') diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 1c313c710be3..de24af202447 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -98,12 +98,11 @@ static int pca953x_write_reg(struct pca953x_chip *chip, int reg, u32 val) if (chip->gpio_chip.ngpio <= 8) ret = i2c_smbus_write_byte_data(chip->client, reg, val); else if (chip->gpio_chip.ngpio == 24) { - ret = i2c_smbus_write_word_data(chip->client, + cpu_to_le32s(&val); + ret = i2c_smbus_write_i2c_block_data(chip->client, (reg << 2) | REG_ADDR_AI, - val & 0xffff); - ret = i2c_smbus_write_byte_data(chip->client, - (reg << 2) + 2, - (val & 0xff0000) >> 16); + 3, + (u8 *) &val); } else { switch (chip->chip_type) { @@ -135,22 +134,27 @@ static int pca953x_read_reg(struct pca953x_chip *chip, int reg, u32 *val) { int ret; - if (chip->gpio_chip.ngpio <= 8) + if (chip->gpio_chip.ngpio <= 8) { ret = i2c_smbus_read_byte_data(chip->client, reg); - else if (chip->gpio_chip.ngpio == 24) { - ret = i2c_smbus_read_word_data(chip->client, reg << 2); - ret |= (i2c_smbus_read_byte_data(chip->client, - (reg << 2) + 2)<<16); + *val = ret; } - else + else if (chip->gpio_chip.ngpio == 24) { + *val = 0; + ret = i2c_smbus_read_i2c_block_data(chip->client, + (reg << 2) | REG_ADDR_AI, + 3, + (u8 *) val); + le32_to_cpus(val); + } else { ret = i2c_smbus_read_word_data(chip->client, reg << 1); + *val = ret; + } if (ret < 0) { dev_err(&chip->client->dev, "failed reading register\n"); return ret; } - *val = (u32)ret; return 0; } -- cgit v1.2.3-59-g8ed1b From 6a7b36aa4b0afbe7a9798feac16de47ad856f358 Mon Sep 17 00:00:00 2001 From: Chandrabhanu Mahapatra Date: Tue, 10 Jul 2012 19:05:37 +0530 Subject: GPIO: PCA953X: Increase size of invert variable to support 24 bit TCA6424 is a low voltage 24 bit I2C and SMBus I/O expander of pca953x family similar to its 16 bit predecessor TCA6416. It comes with three 8-bit active Input, Output, Polarity Inversion and Configuration registers each. The polarity of Input ports can be reversed by setting the appropiate bit in Polarity Inversion registers. The variables corresponding to Input, Output and Configuration registers have already been updated to support 24 bit values. This patch thus updates the invert variable of PCA953X platform data to support 24 bit. Signed-off-by: Chandrabhanu Mahapatra Signed-off-by: Linus Walleij --- drivers/gpio/gpio-pca953x.c | 11 ++++++----- include/linux/i2c/pca953x.h | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'drivers/gpio/gpio-pca953x.c') diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index de24af202447..266b910de43b 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -568,7 +568,7 @@ static void pca953x_irq_teardown(struct pca953x_chip *chip) * WARNING: This is DEPRECATED and will be removed eventually! */ static void -pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, int *invert) +pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, u32 *invert) { struct device_node *node; const __be32 *val; @@ -596,13 +596,13 @@ pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, int *invert) } #else static void -pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, int *invert) +pca953x_get_alt_pdata(struct i2c_client *client, int *gpio_base, u32 *invert) { *gpio_base = -1; } #endif -static int __devinit device_pca953x_init(struct pca953x_chip *chip, int invert) +static int __devinit device_pca953x_init(struct pca953x_chip *chip, u32 invert) { int ret; @@ -621,7 +621,7 @@ out: return ret; } -static int __devinit device_pca957x_init(struct pca953x_chip *chip, int invert) +static int __devinit device_pca957x_init(struct pca953x_chip *chip, u32 invert) { int ret; u32 val = 0; @@ -657,8 +657,9 @@ static int __devinit pca953x_probe(struct i2c_client *client, { struct pca953x_platform_data *pdata; struct pca953x_chip *chip; - int irq_base=0, invert=0; + int irq_base = 0; int ret; + u32 invert = 0; chip = kzalloc(sizeof(struct pca953x_chip), GFP_KERNEL); if (chip == NULL) diff --git a/include/linux/i2c/pca953x.h b/include/linux/i2c/pca953x.h index 139ba52667c8..3c98dd4f901f 100644 --- a/include/linux/i2c/pca953x.h +++ b/include/linux/i2c/pca953x.h @@ -11,7 +11,7 @@ struct pca953x_platform_data { unsigned gpio_base; /* initial polarity inversion setting */ - uint16_t invert; + u32 invert; /* interrupt base */ int irq_base; -- cgit v1.2.3-59-g8ed1b From ca3ffe910f9935d24e02bb5628a8cbcab119fd9a Mon Sep 17 00:00:00 2001 From: Leed Aguilar Date: Tue, 10 Jul 2012 19:05:53 +0530 Subject: gpio/pca953x: increase variables size to support 24 bit of data Increase variable size from u16 to u32 to allocate 24 bit of data required for the TCA6424 I/O expander device type. Signed-off-by: Leed Aguilar Signed-off-by: Chandrabhanu Mahapatra Signed-off-by: Linus Walleij --- drivers/gpio/gpio-pca953x.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'drivers/gpio/gpio-pca953x.c') diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c index 266b910de43b..9c693ae17956 100644 --- a/drivers/gpio/gpio-pca953x.c +++ b/drivers/gpio/gpio-pca953x.c @@ -78,10 +78,10 @@ struct pca953x_chip { #ifdef CONFIG_GPIO_PCA953X_IRQ struct mutex irq_lock; - uint16_t irq_mask; - uint16_t irq_stat; - uint16_t irq_trig_raise; - uint16_t irq_trig_fall; + u32 irq_mask; + u32 irq_stat; + u32 irq_trig_raise; + u32 irq_trig_fall; int irq_base; #endif @@ -353,8 +353,8 @@ static void pca953x_irq_bus_lock(struct irq_data *d) static void pca953x_irq_bus_sync_unlock(struct irq_data *d) { struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); - uint16_t new_irqs; - uint16_t level; + u32 new_irqs; + u32 level; /* Look for any newly setup interrupt */ new_irqs = chip->irq_trig_fall | chip->irq_trig_raise; @@ -372,8 +372,8 @@ static void pca953x_irq_bus_sync_unlock(struct irq_data *d) static int pca953x_irq_set_type(struct irq_data *d, unsigned int type) { struct pca953x_chip *chip = irq_data_get_irq_chip_data(d); - uint16_t level = d->irq - chip->irq_base; - uint16_t mask = 1 << level; + u32 level = d->irq - chip->irq_base; + u32 mask = 1 << level; if (!(type & IRQ_TYPE_EDGE_BOTH)) { dev_err(&chip->client->dev, "irq %d: unsupported type %d\n", @@ -403,12 +403,12 @@ static struct irq_chip pca953x_irq_chip = { .irq_set_type = pca953x_irq_set_type, }; -static uint16_t pca953x_irq_pending(struct pca953x_chip *chip) +static u32 pca953x_irq_pending(struct pca953x_chip *chip) { u32 cur_stat; - uint16_t old_stat; - uint16_t pending; - uint16_t trigger; + u32 old_stat; + u32 pending; + u32 trigger; int ret, offset = 0; switch (chip->chip_type) { @@ -444,8 +444,8 @@ static uint16_t pca953x_irq_pending(struct pca953x_chip *chip) static irqreturn_t pca953x_irq_handler(int irq, void *devid) { struct pca953x_chip *chip = devid; - uint16_t pending; - uint16_t level; + u32 pending; + u32 level; pending = pca953x_irq_pending(chip); -- cgit v1.2.3-59-g8ed1b