From patchwork Mon Dec 1 12:09:37 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: 41768 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 0D48324001 for ; Mon, 1 Dec 2014 12:09:12 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id r20sf6608310wiv.9 for ; Mon, 01 Dec 2014 04:09:10 -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=gfzDFHSIebjLvHMEd9jZlpMZZrYBh69NWhdAMI+F3Tg=; b=nOkxSjxkTP3yN8uOWp/k8wLgl0QlXHelOOLnUHpY2UDFTBJCQrWikAeoUX4SBG7C4f FacW3l5sb8ZRLg7UgJ+s/s+q2Dlf9xTCEupSFyfNLL9fGz8QxJvAiwQCCJrCJ+u57mFS WZz5rnhlsxWsEDFfHhHtNyIRqmvG6zt80xYB+I6uh+6l4HGzKONprzpfnpIsj5PUb9T3 /si5873+jRHT/BMM1HmyzdACOyd2RiRztRbUKiTRRm5gzU4AbWxkAztTHyNiZXtNyOS7 JRpYfGbvIf5eBFmHhd6LzBfhQBOcLDMf05PxduQ8qA8j5qcl486zBEjegP9zm5h8EjYv Ws3A== X-Gm-Message-State: ALoCoQkOcgGapKoTX59Hsj8CKroP6MQE6K/9zi3BMuxxiDW77TWFcXrI63VsYuC4ZNiCv9zUVjeM X-Received: by 10.194.134.193 with SMTP id pm1mr623125wjb.4.1417435750933; Mon, 01 Dec 2014 04:09:10 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.7.71 with SMTP id da7ls1188297lad.31.gmail; Mon, 01 Dec 2014 04:09:10 -0800 (PST) X-Received: by 10.152.205.11 with SMTP id lc11mr56634278lac.34.1417435750708; Mon, 01 Dec 2014 04:09:10 -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 kv10si17418606lac.131.2014.12.01.04.09.10 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Dec 2014 04:09:10 -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 10so8590636lbg.12 for ; Mon, 01 Dec 2014 04:09:10 -0800 (PST) X-Received: by 10.152.87.100 with SMTP id w4mr2149661laz.71.1417435750608; Mon, 01 Dec 2014 04:09:10 -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 ew9csp272737lbc; Mon, 1 Dec 2014 04:09:09 -0800 (PST) X-Received: by 10.66.251.167 with SMTP id zl7mr88813701pac.140.1417435748716; Mon, 01 Dec 2014 04:09:08 -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.08 for ; Mon, 01 Dec 2014 04:09:08 -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 S1753350AbaLAMJH (ORCPT ); Mon, 1 Dec 2014 07:09:07 -0500 Received: from mail-gw3-out.broadcom.com ([216.31.210.64]:14590 "EHLO mail-gw3-out.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753051AbaLAMJH (ORCPT ); Mon, 1 Dec 2014 07:09:07 -0500 X-IronPort-AV: E=Sophos;i="5.07,493,1413270000"; d="scan'208";a="51782619" Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw3-out.broadcom.com with ESMTP; 01 Dec 2014 04:18:05 -0800 Received: from IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) 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:07 -0800 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP3.corp.ad.broadcom.com (10.9.207.53) with Microsoft SMTP Server id 14.3.174.1; Mon, 1 Dec 2014 04:09:07 -0800 Received: from linaro.ban.broadcom.com (unknown [10.131.60.135]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id 0437341013; Mon, 1 Dec 2014 04:08:31 -0800 (PST) From: To: Linus Walleij , Alexandre Courbot CC: Kamlakant Patel , , Martyn Welch Subject: [PATCH v1 4/5] gpio: ge: convert to use basic mmio gpio library Date: Mon, 1 Dec 2014 17:39:37 +0530 Message-ID: <1417435778-21879-5-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 GE GPIO driver to use basic_mmio_gpio generic library. Signed-off-by: Kamlakant Patel --- drivers/gpio/Kconfig | 1 + drivers/gpio/gpio-ge.c | 96 ++++++++++++++++++++------------------------------ 2 files changed, 40 insertions(+), 57 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 8cbc3ab..35a315d 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -429,6 +429,7 @@ config GPIO_VX855 config GPIO_GE_FPGA bool "GE FPGA based GPIO" depends on GE_FPGA + select GPIO_GENERIC help Support for common GPIO functionality provided on some GE Single Board Computers. diff --git a/drivers/gpio/gpio-ge.c b/drivers/gpio/gpio-ge.c index 1237a73..7579d2e 100644 --- a/drivers/gpio/gpio-ge.c +++ b/drivers/gpio/gpio-ge.c @@ -21,7 +21,9 @@ #include #include #include +#include #include +#include #define GEF_GPIO_DIRECT 0x00 #define GEF_GPIO_IN 0x04 @@ -33,53 +35,6 @@ #define GEF_GPIO_OVERRUN 0x1C #define GEF_GPIO_MODE 0x20 -static void gef_gpio_set(struct gpio_chip *chip, unsigned offset, int value) -{ - struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); - unsigned int data; - - data = ioread32be(mmchip->regs + GEF_GPIO_OUT); - if (value) - data = data | BIT(offset); - else - data = data & ~BIT(offset); - iowrite32be(data, mmchip->regs + GEF_GPIO_OUT); -} - -static int gef_gpio_dir_in(struct gpio_chip *chip, unsigned offset) -{ - unsigned int data; - struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); - - data = ioread32be(mmchip->regs + GEF_GPIO_DIRECT); - data = data | BIT(offset); - iowrite32be(data, mmchip->regs + GEF_GPIO_DIRECT); - - return 0; -} - -static int gef_gpio_dir_out(struct gpio_chip *chip, unsigned offset, int value) -{ - unsigned int data; - struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); - - /* Set value before switching to output */ - gef_gpio_set(mmchip->regs + GEF_GPIO_OUT, offset, value); - - data = ioread32be(mmchip->regs + GEF_GPIO_DIRECT); - data = data & ~BIT(offset); - iowrite32be(data, mmchip->regs + GEF_GPIO_DIRECT); - - return 0; -} - -static int gef_gpio_get(struct gpio_chip *chip, unsigned offset) -{ - struct of_mm_gpio_chip *mmchip = to_of_mm_gpio_chip(chip); - - return !!(ioread32be(mmchip->regs + GEF_GPIO_IN) & BIT(offset)); -} - static const struct of_device_id gef_gpio_ids[] = { { .compatible = "gef,sbc610-gpio", @@ -99,22 +54,49 @@ static int __init gef_gpio_probe(struct platform_device *pdev) { const struct of_device_id *of_id = of_match_device(gef_gpio_ids, &pdev->dev); - struct of_mm_gpio_chip *mmchip; + struct bgpio_chip *bgc; + void __iomem *regs; + int ret; - mmchip = devm_kzalloc(&pdev->dev, sizeof(*mmchip), GFP_KERNEL); - if (!mmchip) + bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL); + if (!bgc) return -ENOMEM; + regs = of_iomap(pdev->dev.of_node, 0); + if (!regs) + return -ENOMEM; + + ret = bgpio_init(bgc, &pdev->dev, 4, regs + GEF_GPIO_IN, + regs + GEF_GPIO_OUT, NULL, NULL, + regs + GEF_GPIO_DIRECT, BGPIOF_BIG_ENDIAN_BYTE_ORDER); + if (ret) { + dev_err(&pdev->dev, "bgpio_init failed\n"); + goto err0; + } + /* Setup pointers to chip functions */ - mmchip->gc.ngpio = (u16)(uintptr_t)of_id->data; - mmchip->gc.of_gpio_n_cells = 2; - mmchip->gc.direction_input = gef_gpio_dir_in; - mmchip->gc.direction_output = gef_gpio_dir_out; - mmchip->gc.get = gef_gpio_get; - mmchip->gc.set = gef_gpio_set; + bgc->gc.label = kstrdup(pdev->dev.of_node->full_name, GFP_KERNEL); + if (!bgc->gc.label) + goto err0; + + bgc->gc.base = -1; + bgc->gc.ngpio = (u16)(uintptr_t)of_id->data; + bgc->gc.of_gpio_n_cells = 2; + bgc->gc.of_node = pdev->dev.of_node; /* This function adds a memory mapped GPIO chip */ - return of_mm_gpiochip_add(pdev->dev.of_node, mmchip); + ret = gpiochip_add(&bgc->gc); + if (ret) + goto err1; + + return 0; +err1: + kfree(bgc->gc.label); +err0: + iounmap(regs); + pr_err("%s: GPIO chip registration failed\n", + pdev->dev.of_node->full_name); + return ret; }; static struct platform_driver gef_gpio_driver = {