From patchwork Tue Feb 19 16:22:19 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haojian Zhuang X-Patchwork-Id: 14990 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 207E623E24 for ; Tue, 19 Feb 2013 16:23:04 +0000 (UTC) Received: from mail-vc0-f181.google.com (mail-vc0-f181.google.com [209.85.220.181]) by fiordland.canonical.com (Postfix) with ESMTP id AA864A192AE for ; Tue, 19 Feb 2013 16:23:03 +0000 (UTC) Received: by mail-vc0-f181.google.com with SMTP id f13so1181661vcb.40 for ; Tue, 19 Feb 2013 08:23:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-received:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state; bh=AzIa3X6SJryDjK5rwcA0D860y5RJPbUuy6kDCRUv2YM=; b=UHYzCTg9047M3JPDaeZZY+FvVBV8tomJsWoGgR9cfohpPj1RZPcVMr9vLhWsQYHsRN 43EJnLWVhn2bsmmWMc5Kt97tAZJw6asa70cUcSMPgW7GENdbh5Go/e1M/m0XTK1JYav6 dvswlZjJTTdvxQ8tELII9WnzfQUFxRqM1YtP8w782hTGAU8QbQcmDo6WskOm/MA4oZDe Yrekp8/rODj4oEnThh+KFnbzWy+tPWZyAqPbJgAz9/N31coQtoyEWdgZIyh9BcqP0OFe hen/VV8D+HXu0C1NdQgPWaLGqUeIqJ1HRUVgkYaNxDiz+Z7eSvPihiAnfUABTgfLe/2T 8Vfw== X-Received: by 10.52.29.18 with SMTP id f18mr13941982vdh.57.1361290983188; Tue, 19 Feb 2013 08:23:03 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.58.145.101 with SMTP id st5csp150680veb; Tue, 19 Feb 2013 08:22:51 -0800 (PST) X-Received: by 10.66.85.161 with SMTP id i1mr46619049paz.67.1361290970993; Tue, 19 Feb 2013 08:22:50 -0800 (PST) Received: from mail-pa0-f45.google.com (mail-pa0-f45.google.com [209.85.220.45]) by mx.google.com with ESMTPS id o4si24578091paw.217.2013.02.19.08.22.50 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Feb 2013 08:22:50 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.45 is neither permitted nor denied by best guess record for domain of haojian.zhuang@linaro.org) client-ip=209.85.220.45; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.45 is neither permitted nor denied by best guess record for domain of haojian.zhuang@linaro.org) smtp.mail=haojian.zhuang@linaro.org Received: by mail-pa0-f45.google.com with SMTP id kl14so3446400pab.18 for ; Tue, 19 Feb 2013 08:22:50 -0800 (PST) X-Received: by 10.68.137.42 with SMTP id qf10mr10007311pbb.80.1361290970592; Tue, 19 Feb 2013 08:22:50 -0800 (PST) Received: from localhost.localdomain ([27.115.121.39]) by mx.google.com with ESMTPS id rn14sm18472714pbb.33.2013.02.19.08.22.45 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 19 Feb 2013 08:22:49 -0800 (PST) From: Haojian Zhuang To: grinberg@compulab.co.il, linus.walleij@linaro.org, linux@arm.linux.org.uk, marek.vasut@gmail.com, robert.jarzmik@free.fr, daniel@caiaq.de, linux-arm-kernel@lists.infradead.org, grant.likely@secretlab.ca, cxie4@marvell.com Cc: patches@linaro.org, Haojian Zhuang Subject: [PATCH v4 02/11] gpio: pxa: clean code with same variable name Date: Wed, 20 Feb 2013 00:22:19 +0800 Message-Id: <1361290948-16669-3-git-send-email-haojian.zhuang@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1361290948-16669-1-git-send-email-haojian.zhuang@linaro.org> References: <1361290948-16669-1-git-send-email-haojian.zhuang@linaro.org> X-Gm-Message-State: ALoCoQm8DIqT+CSjjb1tmeBnETvvh1lTD+xFCUHJI7QDHRMJAg/F1zOW70Cy3fzy2zlnhkf2S5DC Clean code to avoid similar variable. Now use gc for gpio_chip, and use c/chip for pxa_gpio_chip. It's used to avoid confusion. Signed-off-by: Haojian Zhuang Tested-by: Igor Grinberg --- drivers/gpio/gpio-pxa.c | 102 +++++++++++++++++++++++------------------------ 1 file changed, 50 insertions(+), 52 deletions(-) diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c index a4c6687..e611bed 100644 --- a/drivers/gpio/gpio-pxa.c +++ b/drivers/gpio/gpio-pxa.c @@ -69,20 +69,20 @@ static struct device_node *pxa_gpio_of_node; #endif struct pxa_gpio_chip { - struct gpio_chip chip; - void __iomem *regbase; - char label[10]; + struct gpio_chip gc; + void __iomem *regbase; + char label[10]; - unsigned long irq_mask; - unsigned long irq_edge_rise; - unsigned long irq_edge_fall; - int (*set_wake)(unsigned int gpio, unsigned int on); + unsigned long irq_mask; + unsigned long irq_edge_rise; + unsigned long irq_edge_fall; + int (*set_wake)(unsigned int gpio, unsigned int on); #ifdef CONFIG_PM - unsigned long saved_gplr; - unsigned long saved_gpdr; - unsigned long saved_grer; - unsigned long saved_gfer; + unsigned long saved_gplr; + unsigned long saved_gpdr; + unsigned long saved_grer; + unsigned long saved_gfer; #endif }; @@ -103,9 +103,9 @@ static void __iomem *gpio_reg_base; #define for_each_gpio_chip(i, c) \ for (i = 0, c = &pxa_gpio_chips[0]; i <= pxa_last_gpio; i += 32, c++) -static inline void __iomem *gpio_chip_base(struct gpio_chip *c) +static inline void __iomem *gpio_chip_base(struct gpio_chip *gc) { - return container_of(c, struct pxa_gpio_chip, chip)->regbase; + return container_of(gc, struct pxa_gpio_chip, gc)->regbase; } static inline struct pxa_gpio_chip *gpio_to_pxachip(unsigned gpio) @@ -147,7 +147,7 @@ static inline int __gpio_is_occupied(unsigned gpio) int ret, af = 0, dir = 0; pxachip = gpio_to_pxachip(gpio); - base = gpio_chip_base(&pxachip->chip); + base = gpio_chip_base(&pxachip->gc); gpdr = readl_relaxed(base + GPDR_OFFSET); switch (gpio_type) { @@ -170,9 +170,9 @@ static inline int __gpio_is_occupied(unsigned gpio) return ret; } -static int pxa_gpio_to_irq(struct gpio_chip *chip, unsigned offset) +static int pxa_gpio_to_irq(struct gpio_chip *gc, unsigned offset) { - return chip->base + offset + irq_base; + return gc->base + offset + irq_base; } int pxa_irq_to_gpio(int irq) @@ -180,16 +180,16 @@ int pxa_irq_to_gpio(int irq) return irq - irq_base; } -static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset) +static int pxa_gpio_direction_input(struct gpio_chip *gc, unsigned offset) { - void __iomem *base = gpio_chip_base(chip); + void __iomem *base = gpio_chip_base(gc); uint32_t value, mask = 1 << offset; unsigned long flags; spin_lock_irqsave(&gpio_lock, flags); value = readl_relaxed(base + GPDR_OFFSET); - if (__gpio_is_inverted(chip->base + offset)) + if (__gpio_is_inverted(gc->base + offset)) value |= mask; else value &= ~mask; @@ -199,10 +199,10 @@ static int pxa_gpio_direction_input(struct gpio_chip *chip, unsigned offset) return 0; } -static int pxa_gpio_direction_output(struct gpio_chip *chip, +static int pxa_gpio_direction_output(struct gpio_chip *gc, unsigned offset, int value) { - void __iomem *base = gpio_chip_base(chip); + void __iomem *base = gpio_chip_base(gc); uint32_t tmp, mask = 1 << offset; unsigned long flags; @@ -211,7 +211,7 @@ static int pxa_gpio_direction_output(struct gpio_chip *chip, spin_lock_irqsave(&gpio_lock, flags); tmp = readl_relaxed(base + GPDR_OFFSET); - if (__gpio_is_inverted(chip->base + offset)) + if (__gpio_is_inverted(gc->base + offset)) tmp &= ~mask; else tmp |= mask; @@ -221,15 +221,15 @@ static int pxa_gpio_direction_output(struct gpio_chip *chip, return 0; } -static int pxa_gpio_get(struct gpio_chip *chip, unsigned offset) +static int pxa_gpio_get(struct gpio_chip *gc, unsigned offset) { - return readl_relaxed(gpio_chip_base(chip) + GPLR_OFFSET) & (1 << offset); + return readl_relaxed(gpio_chip_base(gc) + GPLR_OFFSET) & (1 << offset); } -static void pxa_gpio_set(struct gpio_chip *chip, unsigned offset, int value) +static void pxa_gpio_set(struct gpio_chip *gc, unsigned offset, int value) { - writel_relaxed(1 << offset, gpio_chip_base(chip) + - (value ? GPSR_OFFSET : GPCR_OFFSET)); + writel_relaxed(1 << offset, gpio_chip_base(gc) + + (value ? GPSR_OFFSET : GPCR_OFFSET)); } #ifdef CONFIG_OF_GPIO @@ -240,7 +240,7 @@ static int pxa_gpio_of_xlate(struct gpio_chip *gc, if (gpiospec->args[0] > pxa_last_gpio) return -EINVAL; - if (gc != &pxa_gpio_chips[gpiospec->args[0] / 32].chip) + if (gc != &pxa_gpio_chips[gpiospec->args[0] / 32].gc) return -EINVAL; if (flags) @@ -250,42 +250,43 @@ static int pxa_gpio_of_xlate(struct gpio_chip *gc, } #endif -static int pxa_init_gpio_chip(int gpio_end, - int (*set_wake)(unsigned int, unsigned int)) +static int pxa_init_gpio_chip(struct platform_device *pdev, int gpio_end) { int i, gpio, nbanks = gpio_to_bank(gpio_end) + 1; struct pxa_gpio_chip *chips; + struct pxa_gpio_platform_data *pdata = dev_get_platdata(&pdev->dev); - chips = kzalloc(nbanks * sizeof(struct pxa_gpio_chip), GFP_KERNEL); - if (chips == NULL) { - pr_err("%s: failed to allocate GPIO chips\n", __func__); + chips = devm_kzalloc(&pdev->dev, nbanks * sizeof(*chips), GFP_KERNEL); + if (!chips) { + dev_err(&pdev->dev, "failed to allocate GPIO chips\n"); return -ENOMEM; } for (i = 0, gpio = 0; i < nbanks; i++, gpio += 32) { - struct gpio_chip *c = &chips[i].chip; + struct gpio_chip *gc = &chips[i].gc; sprintf(chips[i].label, "gpio-%d", i); chips[i].regbase = gpio_reg_base + BANK_OFF(i); - chips[i].set_wake = set_wake; + if (pdata->gpio_set_wake) + chips[i].set_wake = pdata->gpio_set_wake; - c->base = gpio; - c->label = chips[i].label; + gc->base = gpio; + gc->label = chips[i].label; - c->direction_input = pxa_gpio_direction_input; - c->direction_output = pxa_gpio_direction_output; - c->get = pxa_gpio_get; - c->set = pxa_gpio_set; - c->to_irq = pxa_gpio_to_irq; + gc->direction_input = pxa_gpio_direction_input; + gc->direction_output = pxa_gpio_direction_output; + gc->get = pxa_gpio_get; + gc->set = pxa_gpio_set; + gc->to_irq = pxa_gpio_to_irq; #ifdef CONFIG_OF_GPIO - c->of_node = pxa_gpio_of_node; - c->of_xlate = pxa_gpio_of_xlate; - c->of_gpio_n_cells = 2; + gc->of_node = pxa_gpio_of_node; + gc->of_xlate = pxa_gpio_of_xlate; + gc->of_gpio_n_cells = 2; #endif /* number of GPIOs on last bank may be less than 32 */ - c->ngpio = (gpio + 31 > gpio_end) ? (gpio_end - gpio + 1) : 32; - gpiochip_add(c); + gc->ngpio = (gpio + 31 > gpio_end) ? (gpio_end - gpio + 1) : 32; + gpiochip_add(gc); } pxa_gpio_chips = chips; return 0; @@ -364,7 +365,7 @@ static void pxa_gpio_demux_handler(unsigned int irq, struct irq_desc *desc) do { loop = 0; for_each_gpio_chip(gpio, c) { - gpio_base = c->chip.base; + gpio_base = c->gc.base; gedr = readl_relaxed(c->regbase + GEDR_OFFSET); gedr = gedr & c->irq_mask; @@ -537,9 +538,6 @@ static int pxa_gpio_probe_dt(struct platform_device *pdev) &pxa_irq_domain_ops, NULL); pxa_gpio_of_node = np; return 0; -err: - iounmap(gpio_reg_base); - return ret; } #else #define pxa_gpio_probe_dt(pdev) (-1) @@ -604,7 +602,7 @@ static int pxa_gpio_probe(struct platform_device *pdev) /* Initialize GPIO chips */ info = dev_get_platdata(&pdev->dev); - pxa_init_gpio_chip(pxa_last_gpio, info ? info->gpio_set_wake : NULL); + pxa_init_gpio_chip(pdev, pxa_last_gpio); /* clear all GPIO edge detects */ for_each_gpio_chip(gpio, c) {