diff mbox series

[2/5] gpio: pca953x: Name the gpiochip after the I2C address

Message ID 20171124093045.5961-3-linus.walleij@linaro.org
State New
Headers show
Series Make gpio_keys accept board descriptors | expand

Commit Message

Linus Walleij Nov. 24, 2017, 9:30 a.m. UTC
Just putting the name of the I2C device as name for the
GPIO chip (label) is ambigous, and makes it hard for us
to use GPIO descriptor tables on systems such as DaVinci
DA850EVM which has two chips but on I2C address 0x20 and 0x21.

Instead, append "-XX" to the GPIOchip name using the I2C
address so we get a unique chip name that can be used
in descriptor tables, such as "tca6416-20" and
"tca6416-21" on the DaVinci DA850EVM.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

---
 drivers/gpio/gpio-pca953x.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

-- 
2.14.3

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Andrew Lunn Nov. 24, 2017, 2:26 p.m. UTC | #1
On Fri, Nov 24, 2017 at 10:30:42AM +0100, Linus Walleij wrote:
> Just putting the name of the I2C device as name for the

> GPIO chip (label) is ambigous, and makes it hard for us

> to use GPIO descriptor tables on systems such as DaVinci

> DA850EVM which has two chips but on I2C address 0x20 and 0x21.

> 

> Instead, append "-XX" to the GPIOchip name using the I2C

> address so we get a unique chip name that can be used

> in descriptor tables, such as "tca6416-20" and

> "tca6416-21" on the DaVinci DA850EVM.


Hi Linus

Are you making the assumption that there are not two devices at the
same address but on different I2C busses?

How safe is that assumption? Can you include the adapter ID in the
string?

	Andrew
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Linus Walleij Nov. 30, 2017, 2:45 p.m. UTC | #2
On Fri, Nov 24, 2017 at 3:26 PM, Andrew Lunn <andrew@lunn.ch> wrote:
> On Fri, Nov 24, 2017 at 10:30:42AM +0100, Linus Walleij wrote:

>> Just putting the name of the I2C device as name for the

>> GPIO chip (label) is ambigous, and makes it hard for us

>> to use GPIO descriptor tables on systems such as DaVinci

>> DA850EVM which has two chips but on I2C address 0x20 and 0x21.

>>

>> Instead, append "-XX" to the GPIOchip name using the I2C

>> address so we get a unique chip name that can be used

>> in descriptor tables, such as "tca6416-20" and

>> "tca6416-21" on the DaVinci DA850EVM.

>

> Hi Linus

>

> Are you making the assumption that there are not two devices at the

> same address but on different I2C busses?


Yes.

> How safe is that assumption? Can you include the adapter ID in the

> string?


Sure, I just had to come up with something.

The universe of board files is not very big, so the number of
potentially clashing things is not eternal. This is just a transient
"contain and deprecate" thing so I think it's unlikely that they
clash but usually when I say something like that the next day
it happens...

So I can add the adapter number :)

I am waiting for more feedback on the series before resending.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index babb7bd2ba59..bab09f1a6bc9 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -413,10 +413,17 @@  static void pca953x_gpio_set_multiple(struct gpio_chip *gc,
 	mutex_unlock(&chip->i2c_lock);
 }
 
-static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios)
+static int pca953x_setup_gpio(struct pca953x_chip *chip, int gpios)
 {
+	struct i2c_client *client = chip->client;
 	struct gpio_chip *gc;
+	static char *chipname;
 
+	/* Gives a chip name from the chip name and I2C address */
+	chipname = devm_kasprintf(&client->dev, GFP_KERNEL, "%s-%02x",
+				  client->name, client->addr);
+	if (!chipname)
+		return -ENOMEM;
 	gc = &chip->gpio_chip;
 
 	gc->direction_input  = pca953x_gpio_direction_input;
@@ -429,10 +436,12 @@  static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios)
 
 	gc->base = chip->gpio_start;
 	gc->ngpio = gpios;
-	gc->label = chip->client->name;
+	gc->label = chipname;
 	gc->parent = &chip->client->dev;
 	gc->owner = THIS_MODULE;
 	gc->names = chip->names;
+
+	return 0;
 }
 
 #ifdef CONFIG_GPIO_PCA953X_IRQ
@@ -848,7 +857,9 @@  static int pca953x_probe(struct i2c_client *client,
 	/* initialize cached registers from their original values.
 	 * we can't share this chip with another i2c master.
 	 */
-	pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK);
+	ret = pca953x_setup_gpio(chip, chip->driver_data & PCA_GPIO_MASK);
+	if (ret)
+		goto err_exit;
 
 	if (chip->gpio_chip.ngpio <= 8) {
 		chip->write_regs = pca953x_write_regs_8;