From patchwork Mon Dec 1 12:09:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: kamlakant.patel@linaro.org X-Patchwork-Id: 41766 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0FC0B24001 for ; Mon, 1 Dec 2014 12:09:07 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id k14sf6417322wgh.0 for ; Mon, 01 Dec 2014 04:09:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-type:sender:precedence :list-id:x-original-sender:x-original-authentication-results :mailing-list:list-post:list-help:list-archive:list-unsubscribe; bh=ZFyIr183xpqYoRZSYIB4dnxs/GztnmkoEuWWOPDMXTQ=; b=QpaFInuBBvCBjUawXlO1MbzNhgp3Xmncinv4ewP86KRnAkNVT56DMCvkvSURIj9giD rPjFy43u+aLCOtEhXnuaM8RNAbwDC9iA6yRy2vRUsIX22i56hq5dJJSKWToP087z/JAE srQpp9SPdqus2ZVhUlCfS0KwrJjWBFEpRVz/GNpxPwBfN191KlZaIqrQgq1AfxZTL2Is I1kh7piO/gxOeTlrRvt4uSZWmLfn9DDhSdpdnawmiUDAYPNfY7jYdIdErSstTEuOfj/E gwJ7k/euQ96gIB6QWYVoeyn759lm3zHEjfdwq4wWkEtvWhnDtDzs4Uwr7Pg2w1VgNJap 2ShA== X-Gm-Message-State: ALoCoQlUV/yH33xkoaiwVkozYRFi5WS7m38o2zKSPte2Oc4atBHd89j+V9hO486XzdaPHVUOnnlR X-Received: by 10.180.82.34 with SMTP id f2mr13635260wiy.1.1417435746253; Mon, 01 Dec 2014 04:09:06 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.9 with SMTP id w9ls1170220law.1.gmail; Mon, 01 Dec 2014 04:09:06 -0800 (PST) X-Received: by 10.112.150.71 with SMTP id ug7mr56568555lbb.73.1417435746094; Mon, 01 Dec 2014 04:09:06 -0800 (PST) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id is2si5524099lac.12.2014.12.01.04.09.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Dec 2014 04:09:06 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id 10so8246111lbg.40 for ; Mon, 01 Dec 2014 04:09:06 -0800 (PST) X-Received: by 10.112.14.69 with SMTP id n5mr56449242lbc.34.1417435744904; Mon, 01 Dec 2014 04:09:04 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp272718lbc; Mon, 1 Dec 2014 04:09:03 -0800 (PST) X-Received: by 10.66.66.102 with SMTP id e6mr101672880pat.6.1417435742926; Mon, 01 Dec 2014 04:09:02 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si630660pds.219.2014.12.01.04.09.02 for ; Mon, 01 Dec 2014 04:09:02 -0800 (PST) Received-SPF: none (google.com: linux-gpio-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753298AbaLAMJB (ORCPT ); Mon, 1 Dec 2014 07:09:01 -0500 Received: from mail-gw2-out.broadcom.com ([216.31.210.63]:29411 "EHLO mail-gw2-out.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753051AbaLAMJA (ORCPT ); Mon, 1 Dec 2014 07:09:00 -0500 X-IronPort-AV: E=Sophos;i="5.07,493,1413270000"; d="scan'208";a="51943682" Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw2-out.broadcom.com with ESMTP; 01 Dec 2014 04:37:54 -0800 Received: from IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.3.174.1; Mon, 1 Dec 2014 04:09:01 -0800 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) with Microsoft SMTP Server id 14.3.174.1; Mon, 1 Dec 2014 04:08:58 -0800 Received: from linaro.ban.broadcom.com (unknown [10.131.60.135]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id F17C440FE5; Mon, 1 Dec 2014 04:08:27 -0800 (PST) From: To: Linus Walleij , Alexandre Courbot CC: Kamlakant Patel , , Grant Likely Subject: [PATCH v1 2/5] gpio: timberdale: convert to use basic mmio gpio library Date: Mon, 1 Dec 2014 17:39:35 +0530 Message-ID: <1417435778-21879-3-git-send-email-kamlakant.patel@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1417435778-21879-1-git-send-email-kamlakant.patel@linaro.org> References: <1417435778-21879-1-git-send-email-kamlakant.patel@linaro.org> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-gpio@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: kamlakant.patel@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Kamlakant Patel This patch converts TIMBERDALE GPIO driver to use basic_mmio_gpio generic library. Signed-off-by: Kamlakant Patel --- drivers/gpio/Kconfig | 1 + drivers/gpio/gpio-timberdale.c | 96 ++++++++++++------------------------------ 2 files changed, 28 insertions(+), 69 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 3bd4d63..875d312 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -783,6 +783,7 @@ config GPIO_SODAVILLE config GPIO_TIMBERDALE bool "Support for timberdale GPIO IP" depends on MFD_TIMBERDALE + select GPIO_GENERIC ---help--- Add support for the GPIO IP in the timberdale FPGA. diff --git a/drivers/gpio/gpio-timberdale.c b/drivers/gpio/gpio-timberdale.c index a685a3c..8849851 100644 --- a/drivers/gpio/gpio-timberdale.c +++ b/drivers/gpio/gpio-timberdale.c @@ -28,6 +28,7 @@ #include #include #include +#include #define DRIVER_NAME "timb-gpio" @@ -45,60 +46,15 @@ struct timbgpio { void __iomem *membase; spinlock_t lock; /* mutual exclusion */ - struct gpio_chip gpio; + struct bgpio_chip bgc; int irq_base; unsigned long last_ier; }; -static int timbgpio_update_bit(struct gpio_chip *gpio, unsigned index, - unsigned offset, bool enabled) -{ - struct timbgpio *tgpio = container_of(gpio, struct timbgpio, gpio); - u32 reg; - - spin_lock(&tgpio->lock); - reg = ioread32(tgpio->membase + offset); - - if (enabled) - reg |= (1 << index); - else - reg &= ~(1 << index); - - iowrite32(reg, tgpio->membase + offset); - spin_unlock(&tgpio->lock); - - return 0; -} - -static int timbgpio_gpio_direction_input(struct gpio_chip *gpio, unsigned nr) -{ - return timbgpio_update_bit(gpio, nr, TGPIODIR, true); -} - -static int timbgpio_gpio_get(struct gpio_chip *gpio, unsigned nr) -{ - struct timbgpio *tgpio = container_of(gpio, struct timbgpio, gpio); - u32 value; - - value = ioread32(tgpio->membase + TGPIOVAL); - return (value & (1 << nr)) ? 1 : 0; -} - -static int timbgpio_gpio_direction_output(struct gpio_chip *gpio, - unsigned nr, int val) -{ - return timbgpio_update_bit(gpio, nr, TGPIODIR, false); -} - -static void timbgpio_gpio_set(struct gpio_chip *gpio, - unsigned nr, int val) -{ - timbgpio_update_bit(gpio, nr, TGPIOVAL, val != 0); -} - static int timbgpio_to_irq(struct gpio_chip *gpio, unsigned offset) { - struct timbgpio *tgpio = container_of(gpio, struct timbgpio, gpio); + struct bgpio_chip *bgc = container_of(gpio, struct bgpio_chip, gc); + struct timbgpio *tgpio = container_of(bgc, struct timbgpio, bgc); if (tgpio->irq_base <= 0) return -EINVAL; @@ -142,7 +98,7 @@ static int timbgpio_irq_type(struct irq_data *d, unsigned trigger) u32 ver; int ret = 0; - if (offset < 0 || offset > tgpio->gpio.ngpio) + if (offset < 0 || offset > tgpio->bgc.gc.ngpio) return -EINVAL; ver = ioread32(tgpio->membase + TGPIO_VER); @@ -208,8 +164,8 @@ static void timbgpio_irq(unsigned int irq, struct irq_desc *desc) */ iowrite32(0, tgpio->membase + TGPIO_IER); - for_each_set_bit(offset, &ipr, tgpio->gpio.ngpio) - generic_handle_irq(timbgpio_to_irq(&tgpio->gpio, offset)); + for_each_set_bit(offset, &ipr, tgpio->bgc.gc.ngpio) + generic_handle_irq(timbgpio_to_irq(&tgpio->bgc.gc, offset)); iowrite32(tgpio->last_ier, tgpio->membase + TGPIO_IER); } @@ -225,7 +181,6 @@ static int timbgpio_probe(struct platform_device *pdev) { int err, i; struct device *dev = &pdev->dev; - struct gpio_chip *gc; struct timbgpio *tgpio; struct resource *iomem; struct timbgpio_platform_data *pdata = dev_get_platdata(&pdev->dev); @@ -247,6 +202,7 @@ static int timbgpio_probe(struct platform_device *pdev) dev_err(dev, "Memory alloc failed\n"); return -EINVAL; } + tgpio->irq_base = pdata->irq_base; spin_lock_init(&tgpio->lock); @@ -263,22 +219,24 @@ static int timbgpio_probe(struct platform_device *pdev) return -ENOMEM; } - gc = &tgpio->gpio; - - gc->label = dev_name(&pdev->dev); - gc->owner = THIS_MODULE; - gc->dev = &pdev->dev; - gc->direction_input = timbgpio_gpio_direction_input; - gc->get = timbgpio_gpio_get; - gc->direction_output = timbgpio_gpio_direction_output; - gc->set = timbgpio_gpio_set; - gc->to_irq = (irq >= 0 && tgpio->irq_base > 0) ? timbgpio_to_irq : NULL; - gc->dbg_show = NULL; - gc->base = pdata->gpio_base; - gc->ngpio = pdata->nr_pins; - gc->can_sleep = false; - - err = gpiochip_add(gc); + err = bgpio_init(&tgpio->bgc, dev, 4, tgpio->membase + TGPIOVAL, + NULL, NULL, NULL, tgpio->membase + TGPIODIR, 0); + + if (err) { + dev_err(&pdev->dev, "bgpio_init failed\n"); + return err; + } + tgpio->bgc.gc.label = dev_name(&pdev->dev); + tgpio->bgc.gc.owner = THIS_MODULE; + tgpio->bgc.gc.dev = &pdev->dev; + tgpio->bgc.gc.to_irq = (irq >= 0 && tgpio->irq_base > 0) ? + timbgpio_to_irq : NULL; + tgpio->bgc.gc.dbg_show = NULL; + tgpio->bgc.gc.base = pdata->gpio_base; + tgpio->bgc.gc.ngpio = pdata->nr_pins; + tgpio->bgc.gc.can_sleep = false; + + err = gpiochip_add(&tgpio->bgc.gc); if (err) return err; @@ -322,7 +280,7 @@ static int timbgpio_remove(struct platform_device *pdev) irq_set_handler_data(irq, NULL); } - gpiochip_remove(&tgpio->gpio); + gpiochip_remove(&tgpio->bgc.gc); return 0; }