From 0f4630f3720e7e6e921bf525c8357fea7ef3dbab Mon Sep 17 00:00:00 2001 From: Linus Walleij Date: Fri, 4 Dec 2015 14:02:58 +0100 Subject: gpio: generic: factor into gpio_chip struct The separate struct bgpio_chip has been a pain to handle, both by being confusingly similar in name to struct gpio_chip and for being contained inside a struct so that struct gpio_chip is contained in a struct contained in a struct, making several steps of dereferencing necessary. Make things simpler: include the fields directly into , #ifdef:ed for CONFIG_GENERIC_GPIO, and get rid of the altogether. Prefix some of the member variables with bgpio_* and add proper kerneldoc while we're at it. Modify all users to handle the change and use a struct gpio_chip directly. And while we're at it: replace all container_of() dereferencing by gpiochip_get_data() and registering the gpio_chip with gpiochip_add_data(). Cc: arm@kernel.org Cc: Alexander Shiyan Cc: Shawn Guo Cc: Sascha Hauer Cc: Kukjin Kim Cc: Alexandre Courbot Cc: Brian Norris Cc: Florian Fainelli Cc: Sudeep Holla Cc: Lorenzo Pieralisi Cc: Nicolas Pitre Cc: Olof Johansson Cc: Vladimir Zapolskiy Cc: Rabin Vincent Cc: linux-arm-kernel@lists.infradead.org Cc: linux-omap@vger.kernel.org Cc: linux-samsung-soc@vger.kernel.org Cc: bcm-kernel-feedback-list@broadcom.com Acked-by: Gregory Fong Acked-by: Liviu Dudau Acked-by: H Hartley Sweeten Acked-by: Tony Lindgren Acked-by: Krzysztof Kozlowski Acked-by: Lee Jones Signed-off-by: Linus Walleij --- drivers/gpio/gpio-xgene-sb.c | 40 ++++++++++++++++------------------------ 1 file changed, 16 insertions(+), 24 deletions(-) (limited to 'drivers/gpio/gpio-xgene-sb.c') diff --git a/drivers/gpio/gpio-xgene-sb.c b/drivers/gpio/gpio-xgene-sb.c index d57068b9083e..282004deb5d4 100644 --- a/drivers/gpio/gpio-xgene-sb.c +++ b/drivers/gpio/gpio-xgene-sb.c @@ -23,10 +23,8 @@ #include #include #include -#include #include #include -#include #include "gpiolib.h" @@ -43,38 +41,31 @@ /** * struct xgene_gpio_sb - GPIO-Standby private data structure. - * @bgc: memory-mapped GPIO controllers. + * @gc: memory-mapped GPIO controllers. * @irq: Mapping GPIO pins and interrupt number * nirq: Number of GPIO pins that supports interrupt */ struct xgene_gpio_sb { - struct bgpio_chip bgc; + struct gpio_chip gc; u32 *irq; u32 nirq; }; -static inline struct xgene_gpio_sb *to_xgene_gpio_sb(struct gpio_chip *gc) -{ - struct bgpio_chip *bgc = to_bgpio_chip(gc); - - return container_of(bgc, struct xgene_gpio_sb, bgc); -} - -static void xgene_gpio_set_bit(struct bgpio_chip *bgc, void __iomem *reg, u32 gpio, int val) +static void xgene_gpio_set_bit(struct gpio_chip *gc, void __iomem *reg, u32 gpio, int val) { u32 data; - data = bgc->read_reg(reg); + data = gc->read_reg(reg); if (val) data |= GPIO_MASK(gpio); else data &= ~GPIO_MASK(gpio); - bgc->write_reg(reg, data); + gc->write_reg(reg, data); } static int apm_gpio_sb_to_irq(struct gpio_chip *gc, u32 gpio) { - struct xgene_gpio_sb *priv = to_xgene_gpio_sb(gc); + struct xgene_gpio_sb *priv = gpiochip_get_data(gc); if (priv->irq[gpio]) return priv->irq[gpio]; @@ -99,15 +90,15 @@ static int xgene_gpio_sb_probe(struct platform_device *pdev) if (IS_ERR(regs)) return PTR_ERR(regs); - ret = bgpio_init(&priv->bgc, &pdev->dev, 4, + ret = bgpio_init(&priv->gc, &pdev->dev, 4, regs + MPA_GPIO_IN_ADDR, regs + MPA_GPIO_OUT_ADDR, NULL, regs + MPA_GPIO_OE_ADDR, NULL, 0); if (ret) return ret; - priv->bgc.gc.to_irq = apm_gpio_sb_to_irq; - priv->bgc.gc.ngpio = XGENE_MAX_GPIO_DS; + priv->gc.to_irq = apm_gpio_sb_to_irq; + priv->gc.ngpio = XGENE_MAX_GPIO_DS; priv->nirq = XGENE_MAX_GPIO_DS_IRQ; @@ -118,14 +109,14 @@ static int xgene_gpio_sb_probe(struct platform_device *pdev) for (i = 0; i < priv->nirq; i++) { priv->irq[default_lines[i]] = platform_get_irq(pdev, i); - xgene_gpio_set_bit(&priv->bgc, regs + MPA_GPIO_SEL_LO, + xgene_gpio_set_bit(&priv->gc, regs + MPA_GPIO_SEL_LO, default_lines[i] * 2, 1); - xgene_gpio_set_bit(&priv->bgc, regs + MPA_GPIO_INT_LVL, i, 1); + xgene_gpio_set_bit(&priv->gc, regs + MPA_GPIO_INT_LVL, i, 1); } platform_set_drvdata(pdev, priv); - ret = gpiochip_add(&priv->bgc.gc); + ret = gpiochip_add_data(&priv->gc, priv); if (ret) dev_err(&pdev->dev, "failed to register X-Gene GPIO Standby driver\n"); else @@ -133,7 +124,7 @@ static int xgene_gpio_sb_probe(struct platform_device *pdev) if (priv->nirq > 0) { /* Register interrupt handlers for gpio signaled acpi events */ - acpi_gpiochip_request_interrupts(&priv->bgc.gc); + acpi_gpiochip_request_interrupts(&priv->gc); } return ret; @@ -144,10 +135,11 @@ static int xgene_gpio_sb_remove(struct platform_device *pdev) struct xgene_gpio_sb *priv = platform_get_drvdata(pdev); if (priv->nirq > 0) { - acpi_gpiochip_free_interrupts(&priv->bgc.gc); + acpi_gpiochip_free_interrupts(&priv->gc); } - return bgpio_remove(&priv->bgc); + gpiochip_remove(&priv->gc); + return 0; } static const struct of_device_id xgene_gpio_sb_of_match[] = { -- cgit v1.2.3-70-g09d2