Re: [PATCH v1 2/3] gpio: Add support for TPS68470 GPIOs
From: Linus Walleij <hidden>
Date: 2017-06-09 11:15:26
Also in:
linux-acpi, lkml
On Tue, Jun 6, 2017 at 1:55 PM, Rajmohan Mani [off-list ref] wrote:
This patch adds support for TPS68470 GPIOs. There are 7 GPIOs and a few sensor related GPIOs. These GPIOs can be requested and configured as appropriate. Signed-off-by: Rajmohan Mani <redacted>
Same comments as Andy already sent, plus:
+static inline struct tps68470_gpio_data *to_gpio_data(struct gpio_chip *gpiochp)
+{
+ return container_of(gpiochp, struct tps68470_gpio_data, gc);
+}Please use the data pointe inside gpio_chip. struct tps68470_gpio_data *foo = gpiochip_get_data(gc);
+ ret = tps68470_reg_read(tps, reg, &val);
(...)
+ tps68470_update_bits(tps, reg, BIT(offset), value ? BIT(offset) : 0);
(...)
+ return tps68470_update_bits(tps, TPS68470_GPIO_CTL_REG_A(offset), + TPS68470_GPIO_MODE_MASK, + TPS68470_GPIO_MODE_OUT_CMOS);
(...)
+ return tps68470_update_bits(tps, TPS68470_GPIO_CTL_REG_A(offset), + TPS68470_GPIO_MODE_MASK, 0x00);
This looks like a reimplementation of regmap. Is it not possible to create a regmap in the MFD driver and pass that around instead?
+struct gpiod_lookup_table gpios_table = {
+ .dev_id = NULL,
+ .table = {
+ GPIO_LOOKUP("tps68470-gpio", 0, "gpio.0", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("tps68470-gpio", 1, "gpio.1", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("tps68470-gpio", 2, "gpio.2", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("tps68470-gpio", 3, "gpio.3", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("tps68470-gpio", 4, "gpio.4", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("tps68470-gpio", 5, "gpio.5", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("tps68470-gpio", 6, "gpio.6", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("tps68470-gpio", 7, "s_enable", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("tps68470-gpio", 8, "s_idle", GPIO_ACTIVE_HIGH),
+ GPIO_LOOKUP("tps68470-gpio", 9, "s_resetn", GPIO_ACTIVE_HIGH),
+ {},
+ },
+};Hm that's why you include <linux/gpio/machine.h> I guess. This warrants a big comment above it explaining why this is done like that and what the use is inside any system with this chip mounted.
+ tps68470_gpio->gc.label = "tps68470-gpio"; + tps68470_gpio->gc.owner = THIS_MODULE; + tps68470_gpio->gc.direction_input = tps68470_gpio_input; + tps68470_gpio->gc.direction_output = tps68470_gpio_output;
Please implement .get_direction()
+ tps68470_gpio->gc.get = tps68470_gpio_get; + tps68470_gpio->gc.set = tps68470_gpio_set; + tps68470_gpio->gc.can_sleep = true; + tps68470_gpio->gc.ngpio = TPS68470_N_GPIO; + tps68470_gpio->gc.base = -1; + tps68470_gpio->gc.parent = &pdev->dev;
Consider assigning the .names() array some sensible line names.
+static int tps68470_gpio_remove(struct platform_device *pdev)
+{
+ struct tps68470_gpio_data *tps68470_gpio = platform_get_drvdata(pdev);
+
+ gpiod_remove_lookup_table(&gpios_table);
+ gpiochip_remove(&tps68470_gpio->gc);You can't use devm_gpiochip_add()? Yours, Linus Walleij