From patchwork Mon Jun 6 14:31:29 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 852232 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter2.kernel.org (8.14.4/8.14.3) with ESMTP id p56ENDfX002384 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 6 Jun 2011 14:23:34 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QTahe-000257-Qs; Mon, 06 Jun 2011 14:22:50 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QTahe-0006bK-Dm; Mon, 06 Jun 2011 14:22:50 +0000 Received: from mail-pw0-f49.google.com ([209.85.160.49]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QTahb-0006b1-7y for linux-arm-kernel@lists.infradead.org; Mon, 06 Jun 2011 14:22:48 +0000 Received: by pwi8 with SMTP id 8so3023842pwi.36 for ; Mon, 06 Jun 2011 07:22:42 -0700 (PDT) Received: by 10.142.226.3 with SMTP id y3mr344780wfg.132.1307370161074; Mon, 06 Jun 2011 07:22:41 -0700 (PDT) Received: from localhost.localdomain ([114.216.154.155]) by mx.google.com with ESMTPS id n1sm3715268pbi.79.2011.06.06.07.22.32 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 06 Jun 2011 07:22:39 -0700 (PDT) From: Shawn Guo To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2] gpio/mxs: convert gpio-mxs to use basic_mmio_gpio library Date: Mon, 6 Jun 2011 22:31:29 +0800 Message-Id: <1307370689-1941-1-git-send-email-shawn.guo@linaro.org> X-Mailer: git-send-email 1.7.4.1 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110606_102247_705176_6117E886 X-CRM114-Status: GOOD ( 17.39 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.49 listed in list.dnswl.org] Cc: grant.likely@secretlab.ca, jamie@jamieiles.com, Shawn Guo , patches@linaro.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Mon, 06 Jun 2011 14:23:34 +0000 (UTC) The gpio-mxs controller complies with basic_mmio_gpio library. This patch converts the driver to use the library. Signed-off-by: Shawn Guo --- Changes since v1: * Drop '[PATCH 1/2] gpio/mxs: save the unnecessary function mxs_gpio_to_irq' drivers/gpio/Kconfig | 1 + drivers/gpio/gpio-mxs.c | 80 ++++++++++------------------------------------ 2 files changed, 19 insertions(+), 62 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index daaef0f..0b858e5 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -96,6 +96,7 @@ config GPIO_EXYNOS4 config GPIO_MXS def_bool y depends on ARCH_MXS + select GPIO_BASIC_MMIO_CORE config GPIO_PLAT_SAMSUNG bool "Samsung SoCs GPIO library support" diff --git a/drivers/gpio/gpio-mxs.c b/drivers/gpio/gpio-mxs.c index a287614..9d2dba7 100644 --- a/drivers/gpio/gpio-mxs.c +++ b/drivers/gpio/gpio-mxs.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #define MXS_SET 0x4 @@ -54,7 +55,7 @@ struct mxs_gpio_port { int irq; int irq_high; int virtual_irq_start; - struct gpio_chip chip; + struct bgpio_chip bgc; }; /* Note: This driver assumes 32 GPIOs are handled in one register */ @@ -99,8 +100,6 @@ static void mxs_gpio_unmask_irq(struct irq_data *d) set_gpio_irqenable(port, gpio & 0x1f, 1); } -static int mxs_gpio_get(struct gpio_chip *chip, unsigned offset); - static int mxs_gpio_set_irq_type(struct irq_data *d, unsigned int type) { u32 gpio = irq_to_gpio(d->irq); @@ -203,61 +202,15 @@ static struct irq_chip gpio_irq_chip = { .irq_set_wake = mxs_gpio_set_wake_irq, }; -static void mxs_set_gpio_direction(struct gpio_chip *chip, unsigned offset, - int dir) -{ - struct mxs_gpio_port *port = - container_of(chip, struct mxs_gpio_port, chip); - void __iomem *pin_addr = port->base + PINCTRL_DOE(port->id); - - if (dir) - writel(1 << offset, pin_addr + MXS_SET); - else - writel(1 << offset, pin_addr + MXS_CLR); -} - -static int mxs_gpio_get(struct gpio_chip *chip, unsigned offset) -{ - struct mxs_gpio_port *port = - container_of(chip, struct mxs_gpio_port, chip); - - return (readl(port->base + PINCTRL_DIN(port->id)) >> offset) & 1; -} - -static void mxs_gpio_set(struct gpio_chip *chip, unsigned offset, int value) -{ - struct mxs_gpio_port *port = - container_of(chip, struct mxs_gpio_port, chip); - void __iomem *pin_addr = port->base + PINCTRL_DOUT(port->id); - - if (value) - writel(1 << offset, pin_addr + MXS_SET); - else - writel(1 << offset, pin_addr + MXS_CLR); -} - -static int mxs_gpio_to_irq(struct gpio_chip *chip, unsigned offset) +static int mxs_gpio_to_irq(struct gpio_chip *gc, unsigned offset) { + struct bgpio_chip *bgc = to_bgpio_chip(gc); struct mxs_gpio_port *port = - container_of(chip, struct mxs_gpio_port, chip); + container_of(bgc, struct mxs_gpio_port, bgc); return port->virtual_irq_start + offset; } -static int mxs_gpio_direction_input(struct gpio_chip *chip, unsigned offset) -{ - mxs_set_gpio_direction(chip, offset, 0); - return 0; -} - -static int mxs_gpio_direction_output(struct gpio_chip *chip, - unsigned offset, int value) -{ - mxs_gpio_set(chip, offset, value); - mxs_set_gpio_direction(chip, offset, 1); - return 0; -} - static int __devinit mxs_gpio_probe(struct platform_device *pdev) { static void __iomem *base; @@ -322,21 +275,24 @@ static int __devinit mxs_gpio_probe(struct platform_device *pdev) irq_set_chained_handler(port->irq, mxs_gpio_irq_handler); irq_set_handler_data(port->irq, port); - /* register gpio chip */ - port->chip.direction_input = mxs_gpio_direction_input; - port->chip.direction_output = mxs_gpio_direction_output; - port->chip.get = mxs_gpio_get; - port->chip.set = mxs_gpio_set; - port->chip.to_irq = mxs_gpio_to_irq; - port->chip.base = port->id * 32; - port->chip.ngpio = 32; - - err = gpiochip_add(&port->chip); + err = bgpio_init(&port->bgc, &pdev->dev, 4, + port->base + PINCTRL_DIN(port->id), + port->base + PINCTRL_DOUT(port->id), NULL, + port->base + PINCTRL_DOE(port->id), NULL, false); if (err) goto out_iounmap; + port->bgc.gc.to_irq = mxs_gpio_to_irq; + port->bgc.gc.base = port->id * 32; + + err = gpiochip_add(&port->bgc.gc); + if (err) + goto out_bgpio_remove; + return 0; +out_bgpio_remove: + bgpio_remove(&port->bgc); out_iounmap: if (iores) iounmap(port->base);