From patchwork Wed Oct 29 13:56:44 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: 39781 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 1617424046 for ; Wed, 29 Oct 2014 13:57:40 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id b13sf749423wgh.2 for ; Wed, 29 Oct 2014 06:57:40 -0700 (PDT) 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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=gfzDFHSIebjLvHMEd9jZlpMZZrYBh69NWhdAMI+F3Tg=; b=YJYVYvGRVtAdmtRoi49B6qBpHTXVXt0q9GwProhjowzWYIbee6c3OgFqGw30rTGn0I s4N4xzrvbESeCOv+FDAWzffFyQQSs3pHinCN7Q8+gIR1YNvedxrZUK4yPKJKTtEFgoz5 Oo1/RMURbAbza/QXtZ94bYzGwu0BYSPT2AN+DgnghkDn01W8lvi1C4w/7FAXLiZjmY3m pGrhLeXWiH4pnezp3GbfU++laYkv6S5TTmLZW4KtvOAI9bmerEszwHEyLwLyHOB2YyP+ 39+rkaYKWywjwOiKs5lHO7TVD0cqLvJn0dZRWECOeA9VTlSLmzKvZBa6wYxWIrQbQhFw NJIw== X-Gm-Message-State: ALoCoQkLE5Icu3q8gjbkNQP5AoxbCMMlCT+4f+4n8Ii8NsGySjqQlvBrbuD+Tjpj9rbaxWJuUFOI X-Received: by 10.112.38.101 with SMTP id f5mr1823702lbk.7.1414591060180; Wed, 29 Oct 2014 06:57:40 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.6 with SMTP id r6ls47162lae.5.gmail; Wed, 29 Oct 2014 06:57:40 -0700 (PDT) X-Received: by 10.112.54.229 with SMTP id m5mr11580183lbp.11.1414591060039; Wed, 29 Oct 2014 06:57:40 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id u16si2240308laz.45.2014.10.29.06.57.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 29 Oct 2014 06:57:39 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by mail-la0-f43.google.com with SMTP id ge10so2566396lab.2 for ; Wed, 29 Oct 2014 06:57:39 -0700 (PDT) X-Received: by 10.112.77.74 with SMTP id q10mr11490822lbw.66.1414591059890; Wed, 29 Oct 2014 06:57:39 -0700 (PDT) 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.84.229 with SMTP id c5csp661674lbz; Wed, 29 Oct 2014 06:57:38 -0700 (PDT) X-Received: by 10.70.123.138 with SMTP id ma10mr6502845pdb.64.1414591058099; Wed, 29 Oct 2014 06:57:38 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id fl11si4063918pdb.144.2014.10.29.06.57.37 for ; Wed, 29 Oct 2014 06:57:38 -0700 (PDT) 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 S932906AbaJ2N5c (ORCPT ); Wed, 29 Oct 2014 09:57:32 -0400 Received: from mail-gw3-out.broadcom.com ([216.31.210.64]:36456 "EHLO mail-gw3-out.broadcom.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932964AbaJ2N5a (ORCPT ); Wed, 29 Oct 2014 09:57:30 -0400 X-IronPort-AV: E=Sophos;i="5.04,810,1406617200"; d="scan'208";a="49245036" Received: from irvexchcas07.broadcom.com (HELO IRVEXCHCAS07.corp.ad.broadcom.com) ([10.9.208.55]) by mail-gw3-out.broadcom.com with ESMTP; 29 Oct 2014 07:01:57 -0700 Received: from IRVEXCHSMTP2.corp.ad.broadcom.com (10.9.207.52) by IRVEXCHCAS07.corp.ad.broadcom.com (10.9.208.55) with Microsoft SMTP Server (TLS) id 14.3.174.1; Wed, 29 Oct 2014 06:57:29 -0700 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP2.corp.ad.broadcom.com (10.9.207.52) with Microsoft SMTP Server id 14.3.174.1; Wed, 29 Oct 2014 06:57:34 -0700 Received: from linaro.ban.broadcom.com (unknown [10.131.60.135]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id D7D9E40FE6; Wed, 29 Oct 2014 06:57:10 -0700 (PDT) From: To: Linus Walleij , Alexandre Courbot CC: Kamlakant Patel , , Martyn Welch Subject: [PATCH 4/5] gpio: ge: convert to use basic mmio gpio library Date: Wed, 29 Oct 2014 19:26:44 +0530 Message-ID: <1414591005-30961-5-git-send-email-kamlakant.patel@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1414591005-30961-1-git-send-email-kamlakant.patel@linaro.org> References: <1414591005-30961-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.215.43 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 = {