From patchwork Wed May 11 09:34:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 9066731 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 5C7FE9F1C1 for ; Wed, 11 May 2016 09:37:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D046A20172 for ; Wed, 11 May 2016 09:37:02 +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 5F1B82015A for ; Wed, 11 May 2016 09:36:57 +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 1b0QYL-0003Mk-1k; Wed, 11 May 2016 09:35:37 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1b0QXq-0001gM-HI for linux-arm-kernel@lists.infradead.org; Wed, 11 May 2016 09:35:08 +0000 Received: by mail-wm0-x241.google.com with SMTP id e201so8250639wme.2 for ; Wed, 11 May 2016 02:34:46 -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 :in-reply-to:references:mime-version:content-transfer-encoding; bh=IyRdacmE+h4ckZaMEq9ekatGYdFtFIuc2R5RQNEVegM=; b=Wsn2BU/18qnoPMMDZpGMq/bGFLoll0Pzfx8t3ZxB9Ys6vEz4Sera93CPwAPijyYXza lj8dGar6zG3bsCNc4S4AmO6rNljOIDuhVwnKJiX2aMBa4jHTrEbFAFEF5rio7DMRzv8a wY9TLdbvrEJUFFBCT6MXXBBynWhIdR3PGHZHjDuwQcOb6slBqmu1AeDDNvsiUmSYbVFb rVthoMmjfl8PqDZoR7YQAuzOr5BUQPBTyvkMnCjLOc6RIS1FnAnO9Ay7vPZ0dZR99CHx 0iXKDLjHJu1tCXSFAF6nXH6bL8uTtuDs3J0PBC53rymUL/k0nCCmlBzoGdgdD52ZH2ur bObw== 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:in-reply-to:references:mime-version :content-transfer-encoding; bh=IyRdacmE+h4ckZaMEq9ekatGYdFtFIuc2R5RQNEVegM=; b=PDloQPdBLgOYGGH3vg5Vz61Mn6kjC62tS1NR2ViGvXBM9qj/VeseWYNLVC/s7WTzCt GbRPV1apvwi6znivFrwzvxFOtw4bUKCRY5WyRNNHSUKnwkvg74up5dAnukK+11PGg8by f/j6eXvMYth3eSMgfaoW5CUxCUDTFdXEu1jLQG4lIQkIgGBfkl0QlJCEHLBoHBuTcat0 dzxD+SncpQz/iPAbM6UynD9jr83h+Vyd6Oxk6NkGSVrA4F0xqjsMY3/zKU5GS07BuUv/ VsA/V9kskUeTHKtlKJFhEAuQzoDBSDbAws9YtRCDMZquxGdZD7v5AhvOzkBRdI3loQVI yp+w== X-Gm-Message-State: AOPr4FWh2w9RbmEbE7QBW1ZMCaknY+ZkoC5UbeS99QgY3xz7Y51jEAbIK3KbeK+51WCY3Q== X-Received: by 10.28.105.200 with SMTP id z69mr3147901wmh.78.1462959285095; Wed, 11 May 2016 02:34:45 -0700 (PDT) Received: from debian64.daheim (pD9F899E0.dip0.t-ipconnect.de. [217.248.153.224]) by smtp.googlemail.com with ESMTPSA id f135sm7484415wmf.22.2016.05.11.02.34.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 May 2016 02:34:43 -0700 (PDT) Received: from chuck by debian64.daheim with local (Exim 4.87) (envelope-from ) id 1b0QXS-00022V-MR; Wed, 11 May 2016 11:34:42 +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/2] gpio: mmio: add DT support for memory-mapped GPIOs Date: Wed, 11 May 2016 11:34:34 +0200 Message-Id: <2c0675cd6f67bd487105c46c38c72d49d84d4df8.1462911225.git.chunkeey@googlemail.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160511_023506_886377_D111402E X-CRM114-Status: GOOD ( 20.49 ) 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 GPIO's 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. The configuration is detected by which resources are present. 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,