From patchwork Thu May 12 19:28:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 9085721 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E58279F372 for ; Thu, 12 May 2016 19:30:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F1DB42022D for ; Thu, 12 May 2016 19:30:12 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0590520211 for ; Thu, 12 May 2016 19:30:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1b0wI2-0005Fp-UO; Thu, 12 May 2016 19:28:54 +0000 Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b0wI0-00054w-29 for linux-arm-kernel@lists.infradead.org; Thu, 12 May 2016 19:28:53 +0000 Received: by mail-wm0-x243.google.com with SMTP id n129so17706091wmn.1 for ; Thu, 12 May 2016 12:28:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/LQWUw18pkNqPz8lN0TR2vGOsik9DpUmLiefDHN4G6w=; b=I2mbcpxNYnoeyHU+Elb/27Xh/d9zySVdAUNbpiGDf/tsTsvJ0AdfmmjC7M66mtlNPF rNpFRSuAJTpQqXZ5iooTFbDXwPZEi4gt/t+OeLU6apeXFTcEcBlJ2cGTgEjJBhoYBiMD 3jtrhfkBAmm1m4GAYjivGzNRzqco1R1YtRpEwwupwOgP9o4YyD+Wb+ux/fz0KYQAlcFe W4otTuJmBF/V0ZRwM5AKkjJXgzvMFbxhXxU+OlhrzawkLMUin1lwfdp52ofgLhgLQvRZ 9/NFIYyCrlk0DDFaU4BL4Tk1cu8OK2vg85WIiuySBloizcIV+bP5Ho6bWiI0BAdDx14F 6AvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/LQWUw18pkNqPz8lN0TR2vGOsik9DpUmLiefDHN4G6w=; b=gSc3bsODnLaCH4IE1V3JyTq2OlM3Nv+AxY4NJg8QE/O39Fdr5GhIYzMtRC5HGmPEb0 kxVaB+ztpPxJUqY74IcL5qOikjHYDpfpLYf1YbcuuOaacY9zrWaB1+6pU0fh+FljogrQ L54sqZKZ75cQk1X3yEyTCxMgLg8ZHRntpFna95pNIrkSitES1vIoZWoFXPaq71NWSU6k 50PbCJsKNT7XTAzPR70MRKWjPdX4zDLg932m52C7Njo5n6i+wipK/bU1muBF7eoH0ZoD 9t3aaF9clOwXnxYx9WIEnmkNttLztjCWIfv544Ro/aKM7xNl9bRTz0+TUdhqrQ73yPdD v1Kw== X-Gm-Message-State: AOPr4FVqQyMJA3kHQOeTVrwu8EGVF8xQQf4AkVa/heHlD0DJYQiDzl1I3NG6kbI21p5GpA== X-Received: by 10.28.194.69 with SMTP id s66mr12935311wmf.88.1463081310746; Thu, 12 May 2016 12:28:30 -0700 (PDT) Received: from debian64.daheim (pD9F89BEC.dip0.t-ipconnect.de. [217.248.155.236]) by smtp.googlemail.com with ESMTPSA id r75sm42718514wme.18.2016.05.12.12.28.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 May 2016 12:28:29 -0700 (PDT) Received: from chuck by debian64.daheim with local (Exim 4.87) (envelope-from ) id 1b0wHb-0003oa-SD; Thu, 12 May 2016 21:28:27 +0200 From: Christian Lamparter To: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v9.1] gpio: mmio: add DT support for memory-mapped GPIOs Date: Thu, 12 May 2016 21:28:09 +0200 Message-Id: <3e75e8316ceac62f61f3ffc839faaac8789ca936.1463078228.git.chunkeey@googlemail.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <0a1ab2b6-b4c5-44d7-abb4-ce1e9da7e477@gmail.com> References: <0a1ab2b6-b4c5-44d7-abb4-ce1e9da7e477@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160512_122852_449382_CC24286A X-CRM114-Status: GOOD ( 20.78 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Courbot , =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= , Alexander Shiyan , Joachim Eastwood , Andy Shevchenko , Christian Lamparter , Linus Walleij Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Álvaro Fernández Rojas This patch adds support for defining memory-mapped GPIOs which are compatible with the existing gpio-mmio interface. The generic library provides support for many memory-mapped GPIO controllers that are found in various on-board FPGA and ASIC solutions that are used to control board's switches, LEDs, chip-selects, Ethernet/USB PHY power, etc. For setting GPIOs there are three configurations: 1. single input/output register resource (named "dat"), 2. set/clear pair (named "set" and "clr"), 3. single output register resource and single input resource ("set" and dat"). The configuration is detected by which resources are present. For the single output register, this drives a 1 by setting a bit and a zero by clearing a bit. For the set clr pair, this drives a 1 by setting a bit in the set register and clears it by setting a bit in the clear register. For setting the GPIO direction, there are three configurations: a. simple bidirectional GPIOs that requires no configuration. b. an output direction register (named "dirout") where a 1 bit indicates the GPIO is an output. c. an input direction register (named "dirin") where a 1 bit indicates the GPIO is an input. The first user for this binding is "wd,mbl-gpio". Reviewed-by: Andy Shevchenko Signed-off-by: Álvaro Fernández Rojas Signed-off-by: Christian Lamparter --- drivers/gpio/gpio-mmio.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c index 6c1cb3b..f72e40e 100644 --- a/drivers/gpio/gpio-mmio.c +++ b/drivers/gpio/gpio-mmio.c @@ -61,6 +61,8 @@ o ` ~~~~\___/~~~~ ` controller in FPGA is ,.` #include #include #include +#include +#include static void bgpio_write8(void __iomem *reg, unsigned long data) { @@ -569,6 +571,58 @@ static void __iomem *bgpio_map(struct platform_device *pdev, return devm_ioremap_resource(&pdev->dev, r); } +#ifdef CONFIG_OF +static int bgpio_basic_mmio_parse_dt(struct platform_device *pdev, + struct bgpio_pdata *pdata, + unsigned long *flags) +{ + struct device *dev = &pdev->dev; + + pdata->base = -1; + + if (of_property_read_bool(dev->of_node, "no-output")) + *flags |= BGPIOF_NO_OUTPUT; + + return 0; +} + +static const struct of_device_id bgpio_of_match[] = { + { .compatible = "wd,mbl-gpio", .data = bgpio_basic_mmio_parse_dt }, + { } +}; +MODULE_DEVICE_TABLE(of, bgpio_of_match); + +static struct bgpio_pdata *bgpio_parse_dt(struct platform_device *pdev, + unsigned long *flags) +{ + const int (*parse_dt)(struct platform_device *, + struct bgpio_pdata *, unsigned long *); + struct bgpio_pdata *pdata; + int err; + + parse_dt = of_device_get_match_data(&pdev->dev); + if (!parse_dt) + return NULL; + + pdata = devm_kzalloc(&pdev->dev, sizeof(struct bgpio_pdata), + GFP_KERNEL); + if (!pdata) + return ERR_PTR(-ENOMEM); + + err = parse_dt(pdev, pdata, flags); + if (err) + return ERR_PTR(err); + + return pdata; +} +#else +static struct bgpio_pdata *bgpio_parse_dt(struct platform_device *pdev, + unsigned long *flags) +{ + return NULL; +} +#endif /* CONFIG_OF */ + static int bgpio_pdev_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -579,10 +633,19 @@ static int bgpio_pdev_probe(struct platform_device *pdev) void __iomem *dirout; void __iomem *dirin; unsigned long sz; - unsigned long flags = pdev->id_entry->driver_data; + unsigned long flags = 0; int err; struct gpio_chip *gc; - struct bgpio_pdata *pdata = dev_get_platdata(dev); + struct bgpio_pdata *pdata; + + pdata = bgpio_parse_dt(pdev, &flags); + if (IS_ERR(pdata)) + return PTR_ERR(pdata); + + if (!pdata) { + pdata = dev_get_platdata(dev); + flags = pdev->id_entry->driver_data; + } r = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dat"); if (!r) @@ -646,6 +709,7 @@ MODULE_DEVICE_TABLE(platform, bgpio_id_table); static struct platform_driver bgpio_driver = { .driver = { .name = "basic-mmio-gpio", + .of_match_table = of_match_ptr(bgpio_of_match), }, .id_table = bgpio_id_table, .probe = bgpio_pdev_probe,