From patchwork Fri May 13 21:07:11 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christian Lamparter X-Patchwork-Id: 622136 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3r62WV2G6fz9t5Y for ; Sat, 14 May 2016 07:08:06 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=googlemail.com header.i=@googlemail.com header.b=CGHCqPoO; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753646AbcEMVHt (ORCPT ); Fri, 13 May 2016 17:07:49 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36440 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753515AbcEMVH3 (ORCPT ); Fri, 13 May 2016 17:07:29 -0400 Received: by mail-wm0-f67.google.com with SMTP id w143so5923552wmw.3; Fri, 13 May 2016 14:07:28 -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=wZCWDD1TPlATRcPHa8ddC1vkQKF+TRZnlyCJCnM8I2g=; b=CGHCqPoOL5eXfAIBG8poXOPjFWy2IAQopRQrSkiQVIsZ6QOXwhvP0034su1i6V8439 DNxfzVlkkKNtSobobuxUCMkQtFTevJ8FMmvc1lEzC+cECyVdeaeru62NUkNLc+g/+P9k Wa214/Luw7q4rdIuyuTbQSJnje4dqMc/YnB0MU8SOtIrZt59mx5+j0ZuaHmqF/1lak76 pZ2fPItRZfaOwfh+RFPgUB23BSnT8tAsC5fVK241oP13hvzAKWB6YAjD+gh28+9Rj7/e S/Q35raPSCu8vl3sAGq6B3DU8PL3sP1ds7GmuQAbURKdjeKruoJU/SqFfe+rcaC8TiZS /S5Q== 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=wZCWDD1TPlATRcPHa8ddC1vkQKF+TRZnlyCJCnM8I2g=; b=ebCwFI1WM8aPvl0yhUhYpjgTSWhqzhYNVVSmV8MPb5Q862tR1p6sfdHEnrOo5U20in ZxtNEk/v4CznSdWNl9pCfljkw83TGqky0/Y/ndHxvN3sVo6nIBO1LXm/I7Hvd2g9FMEe HKRav6TkPqwnHvRAuEhrwrY/tEzxUTcNdalfrrnRKOawFkreNlV4bTDWlT71KkUb7l5g oGiOjMXoz/iMLGxWSZfzE+EldGwrLXU+EvAL19FYaAf3l/rArZjwRk7d4SMySC+h5va4 k8QHk3yLpFLejFV0AaUr0Auqu2fzzFiZGlU8H5ni/+mMpPxpqaDk46Lm0KQR0LOgwLdO 9UdA== X-Gm-Message-State: AOPr4FWZ5iDHQBPOihBn6ux5my3Hqab1Pstx03pApSQc5dFbvEBMk9xCBuVb4xX1f4Wf2A== X-Received: by 10.194.22.167 with SMTP id e7mr17617557wjf.9.1463173647387; Fri, 13 May 2016 14:07:27 -0700 (PDT) Received: from debian64.daheim (pD9F8B164.dip0.t-ipconnect.de. [217.248.177.100]) by smtp.googlemail.com with ESMTPSA id gk6sm20371657wjc.31.2016.05.13.14.07.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 13 May 2016 14:07:26 -0700 (PDT) Received: from chuck by debian64.daheim with local (Exim 4.87) (envelope-from ) id 1b1KIu-0001TP-3h; Fri, 13 May 2016 23:07:24 +0200 From: Christian Lamparter To: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= , Alexandre Courbot , Linus Walleij , Andy Shevchenko , Joachim Eastwood , Christian Lamparter Subject: [PATCH v10 1/2] gpio: mmio: add DT support for memory-mapped GPIOs Date: Fri, 13 May 2016 23:07:11 +0200 Message-Id: <4af460fea30b60fbb1d621fcb568c5f3b04e1eee.1463172434.git.chunkeey@googlemail.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org 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. Reviewed-by: Andy Shevchenko Signed-off-by: Álvaro Fernández Rojas Signed-off-by: Christian Lamparter --- drivers/gpio/gpio-mmio.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-mmio.c b/drivers/gpio/gpio-mmio.c index 6c1cb3b..af583be 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,37 @@ static void __iomem *bgpio_map(struct platform_device *pdev, return devm_ioremap_resource(&pdev->dev, r); } +#ifdef CONFIG_OF +static const struct of_device_id bgpio_of_match[] = { + { } +}; +MODULE_DEVICE_TABLE(of, bgpio_of_match); + +static struct bgpio_pdata *bgpio_parse_dt(struct platform_device *pdev, + unsigned long *flags) +{ + struct bgpio_pdata *pdata; + + if (!of_match_device(bgpio_of_match, &pdev->dev)) + return NULL; + + pdata = devm_kzalloc(&pdev->dev, sizeof(struct bgpio_pdata), + GFP_KERNEL); + if (!pdata) + return ERR_PTR(-ENOMEM); + + pdata->base = -1; + + 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 +612,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 +688,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,