Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965968AbcCPJ4G (ORCPT ); Wed, 16 Mar 2016 05:56:06 -0400 Received: from mail-ob0-f170.google.com ([209.85.214.170]:35047 "EHLO mail-ob0-f170.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S964968AbcCPJ4D (ORCPT ); Wed, 16 Mar 2016 05:56:03 -0400 MIME-Version: 1.0 In-Reply-To: <1457520614-32239-2-git-send-email-maxime.ripard@free-electrons.com> References: <1457520614-32239-1-git-send-email-maxime.ripard@free-electrons.com> <1457520614-32239-2-git-send-email-maxime.ripard@free-electrons.com> Date: Wed, 16 Mar 2016 10:56:02 +0100 Message-ID: Subject: Re: [PATCH 1/4] gpio: Add AXP209 GPIO driver From: Linus Walleij To: Maxime Ripard Cc: Alexandre Courbot , Lee Jones , Chen-Yu Tsai , "devicetree@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-gpio@vger.kernel.org" , "linux-kernel@vger.kernel.org" , linux-sunxi , Hans de Goede Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4131 Lines: 148 On Wed, Mar 9, 2016 at 11:50 AM, Maxime Ripard wrote: > The AXP209 PMIC has a bunch of GPIOs accessible, that are usually used to > control LEDs or backlight. > > Add a driver for them > > Signed-off-by: Maxime Ripard OK... > +++ b/Documentation/devicetree/bindings/gpio/gpio-axp209.txt Some people insist that bindings be sent separately from the drivers but I don't care. Especially not for this simple binding. > +AXP209 GPIO controller Write something more about the hardware here. For example the quite obvious fact that it is part of an bigger MFD device. In some cases people put all the bindings inside a single file in bindings/mfd/*, follow Lee's recommendation here, I have no strong opinion. > +axp209: pmic@34 { > + compatible = "x-powers,axp209"; Doesn't this need "simple-mfd" if the GPIO subdriver shall probe properly? > + reg = <0x34>; > + interrupt-parent = <&nmi_intc>; > + interrupts = <0 IRQ_TYPE_LEVEL_LOW>; > + interrupt-controller; > + #interrupt-cells = <1>; > + > + axp_gpio: gpio { > + compatible = "x-powers,axp209-gpio"; > + gpio-controller; > + #gpio-cells = <2>; > + }; > +}; (...) > +++ b/drivers/gpio/gpio-axp209.c (...) > +#include > +#include Should only need > +struct axp20x_gpio *to_axp20x_gpio(struct gpio_chip *chip) > +{ > + return container_of(chip, struct axp20x_gpio, chip); > +} No. Use devm_gpiochip_add_data() and gpiochip_get_data() to get the pointer back. > +static int axp20x_gpio_get_reg(unsigned offset) > +{ > + switch (offset) { > + case 0: > + return AXP20X_GPIO0_CTRL; > + case 1: > + return AXP20X_GPIO1_CTRL; > + case 2: > + return AXP20X_GPIO2_CTRL; > + } > + > + return -EINVAL; > +} Can't you just: static u8 regs[] = {AXP20X_GPIO0_CTRL, AXP20X_GPIO1_CTRL, AXP20X_GPIO2_CTRL}; static int axp20x_gpio_get_reg(unsigned offset) { if (offset >= ARRAY_SIZE(regs)) return -EINVAL; return regs[offset]; } > +static int axp20x_gpio_get(struct gpio_chip *chip, unsigned offset) > +{ > + struct axp20x_gpio *gpio = to_axp20x_gpio(chip); > + unsigned int val; > + int reg, ret; > + > + reg = axp20x_gpio_get_reg(offset); > + if (reg < 0) > + return reg; > + > + ret = regmap_read(gpio->regmap, reg, &val); > + if (ret) > + return ret; > + > + return val & (1 << (offset + 4)); This doesn't clamp to [0,1]. Please do this instead: #include return !!(val & BIT(offset+4)); > +static int axp20x_gpio_probe(struct platform_device *pdev) > +{ > + struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); > + struct axp20x_gpio *gpio; > + int ret; > + > + if (!of_device_is_available(pdev->dev.of_node)) > + return -ENODEV; > + > + if (!axp20x) { > + dev_err(&pdev->dev, "Parent drvdata not set\n"); > + return -EINVAL; > + } > + > + gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL); > + if (!gpio) > + return -ENOMEM; > + > + gpio->chip.base = -1; > + gpio->chip.can_sleep = true; > + gpio->chip.dev = &pdev->dev; This is renamed .parent upstream, ick use latest kernel as base for your patches ;) > + gpio->chip.label = dev_name(&pdev->dev); > + gpio->chip.owner = THIS_MODULE; > + gpio->chip.get = axp20x_gpio_get; > + gpio->chip.set = axp20x_gpio_set; > + gpio->chip.direction_input = axp20x_gpio_input; > + gpio->chip.direction_output = axp20x_gpio_output; > + gpio->chip.ngpio = 3; > + > + gpio->regmap = axp20x->regmap; > + > + ret = gpiochip_add(&gpio->chip); devm_gpiochip_add_data() as mentioned. Yours, Linus Walleij