From patchwork Wed Jan 25 15:34:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 92469 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp2238293obz; Wed, 25 Jan 2017 07:36:16 -0800 (PST) X-Received: by 10.99.52.11 with SMTP id b11mr47724697pga.131.1485358576152; Wed, 25 Jan 2017 07:36:16 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q26si23718440pgc.152.2017.01.25.07.36.15; Wed, 25 Jan 2017 07:36:16 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752018AbdAYPgN (ORCPT + 25 others); Wed, 25 Jan 2017 10:36:13 -0500 Received: from mail-wm0-f42.google.com ([74.125.82.42]:37015 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751731AbdAYPeg (ORCPT ); Wed, 25 Jan 2017 10:34:36 -0500 Received: by mail-wm0-f42.google.com with SMTP id c206so37094055wme.0 for ; Wed, 25 Jan 2017 07:34:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tuwHcfX2DJNHNlytZx2Grvu2SPsSBBtOMIF8kexKw1k=; b=vNb2r6TPWy419mcDt2Nv2x+Ki4c9SRkkk6S5vFg59CxpxkoXKjq72z68Hm4fKiaYqw HWD6phi74HN12yjUMNcWNI0zqfrdsEgPzntYYabCB/f704Toz3bOjEaQlTR3NjTlP6zj Ge/NOGSkPGVaMgC92U2YMh39mxonbuuYGK2F1tX29yM60DdvWjQhfNo5jYOQu5xPEiac wj6O75ZIgNDjUiqYEGUaZ2IWZ9PvYFSzRvOHu4qPyRHYeywyGsNrOryuZfiohfzD+Ffr p3VoLkbg1eBAdoacRKhMU/BA4SpBmKIR7L6vpZwGuebT2BUyY3zwGspDY/9ovVCEExyi 9Ldw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tuwHcfX2DJNHNlytZx2Grvu2SPsSBBtOMIF8kexKw1k=; b=nt6n/8ztO5dRjKQ23EePYbV17v/Dvb7j9jtL8MqwC/1TINzXMsK7GGCaZHVT4PP4T1 mn2lOa16JeVBhlh4TRwiXcLgV7XOimMJQDuSeoyv0zHTXhixl1L1YaYo2RR8sSIkHNVw EOlxCLuxy+nBPsK3C0yv5OYDlfohpq3djRz1BL3KDfFHQ8QLc6hqqjDWw6drIb32eeQ/ 6oLjDZPFqW/QEdjjYO2I+oIJsW2N2VrRWcFER/uEgcNNGty+kMhQTeM8GgwiOKUpYOFR AdTyZYdJeG7VeKBa/jdkr8cQA+H/ECsVYnb3kgslE6osr8gBYUW/gnC38Z3Ulgm4I8vE 28Rw== X-Gm-Message-State: AIkVDXLOdnTolKSfKqvo5Uhka0rLhGGlb6p79x1G05/Uc3jWwFsH3ujAjhSa/DY4UYYDcPgA X-Received: by 10.223.162.155 with SMTP id s27mr33206855wra.134.1485358469692; Wed, 25 Jan 2017 07:34:29 -0800 (PST) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id 33sm2462760wrd.34.2017.01.25.07.34.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Jan 2017 07:34:29 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Alexandre Courbot , Bamvor Jian Zhang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 1/7] gpiolib: clean up includes Date: Wed, 25 Jan 2017 16:34:15 +0100 Message-Id: <1485358461-24070-2-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com> References: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org gpiolib.h uses enum gpiod_flags, but doesn't pull in gpio/consumer.h. Include it in gpiolib.h and don't include neither consumer.h nor driver.h from modules that already include gpiolib.h. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-dwapb.c | 1 - drivers/gpio/gpio-xgene-sb.c | 1 - drivers/gpio/gpiolib-acpi.c | 2 -- drivers/gpio/gpiolib-devprop.c | 2 -- drivers/gpio/gpiolib-legacy.c | 3 --- drivers/gpio/gpiolib-of.c | 1 - drivers/gpio/gpiolib-sysfs.c | 2 -- drivers/gpio/gpiolib.c | 1 - drivers/gpio/gpiolib.h | 1 + 9 files changed, 1 insertion(+), 13 deletions(-) -- 2.9.3 diff --git a/drivers/gpio/gpio-dwapb.c b/drivers/gpio/gpio-dwapb.c index 6193f62..e486633 100644 --- a/drivers/gpio/gpio-dwapb.c +++ b/drivers/gpio/gpio-dwapb.c @@ -8,7 +8,6 @@ * All enquiries to support@picochip.com */ #include -#include /* FIXME: for gpio_get_value(), replace this with direct register read */ #include #include diff --git a/drivers/gpio/gpio-xgene-sb.c b/drivers/gpio/gpio-xgene-sb.c index 0332586..eb156c3 100644 --- a/drivers/gpio/gpio-xgene-sb.c +++ b/drivers/gpio/gpio-xgene-sb.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include "gpiolib.h" diff --git a/drivers/gpio/gpiolib-acpi.c b/drivers/gpio/gpiolib-acpi.c index 9b37a36..aebd072 100644 --- a/drivers/gpio/gpiolib-acpi.c +++ b/drivers/gpio/gpiolib-acpi.c @@ -12,8 +12,6 @@ #include #include -#include -#include #include #include #include diff --git a/drivers/gpio/gpiolib-devprop.c b/drivers/gpio/gpiolib-devprop.c index 27f383b..cf4c677 100644 --- a/drivers/gpio/gpiolib-devprop.c +++ b/drivers/gpio/gpiolib-devprop.c @@ -11,8 +11,6 @@ #include #include -#include -#include #include "gpiolib.h" diff --git a/drivers/gpio/gpiolib-legacy.c b/drivers/gpio/gpiolib-legacy.c index 8b83099..f5e7ce8 100644 --- a/drivers/gpio/gpiolib-legacy.c +++ b/drivers/gpio/gpiolib-legacy.c @@ -1,6 +1,3 @@ -#include -#include - #include #include "gpiolib.h" diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 975b9f6..064d51f 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 4b44dd9..844a7cd 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -2,8 +2,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 59d3d96..6722579 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 2495b7e..067e5e5 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -13,6 +13,7 @@ #define GPIOLIB_H #include +#include #include #include #include From patchwork Wed Jan 25 15:34:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 92468 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp2237728obz; Wed, 25 Jan 2017 07:34:59 -0800 (PST) X-Received: by 10.98.92.4 with SMTP id q4mr45309277pfb.151.1485358499327; Wed, 25 Jan 2017 07:34:59 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si1892835plk.180.2017.01.25.07.34.59; Wed, 25 Jan 2017 07:34:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751897AbdAYPe5 (ORCPT + 4 others); Wed, 25 Jan 2017 10:34:57 -0500 Received: from mail-wm0-f44.google.com ([74.125.82.44]:37897 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751878AbdAYPe4 (ORCPT ); Wed, 25 Jan 2017 10:34:56 -0500 Received: by mail-wm0-f44.google.com with SMTP id r144so37006351wme.1 for ; Wed, 25 Jan 2017 07:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QzJwGnQAxz2ChOsLgnntXlgQUvRFEZ9iiqm5k0dsk4A=; b=EhA1YNxLjPBIm6vsAaFjeb9kEX1ACJNN+gb85jYZY8PTRHpCH3+wbU9nrq1oWtuwb5 PHkUClaOVN3c9e+ZPGFgPzE+OLQzlkV+yzcoEeGy5ThIBKilkHwK20AD7p3nLIel7ytt rHmdW/zgvXxTtAY0Em6cIlDNIqms7AJen1A66kXfwt72bQLtdI/2hyQzk+zn5hvarEM2 8Azv2i/YVMy1X+hR3vrg6gBOir03nBtf1E4s4wQzXrAh+rUfDzJxbd4/LvhxL7nHl802 2q6Y28D1nRSaNMakE+ZembPHIUBHpgUmOetV8JecO5TkKKUpV1o0LAiOWlGHgtDO3Xk5 7mVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QzJwGnQAxz2ChOsLgnntXlgQUvRFEZ9iiqm5k0dsk4A=; b=tDyhf0QTkEbw/A1XPEGyauqjjFwU7a2OLJBd4jkU7c56vljnN430KEX6aSNJbG0Dfm aE5H4O7/rUzVuy99PEwOk9ksalD6f/ve/gz58t1gfkN727th/1TcmvyT8sHcsq60K2vN k4hssEwY58G8UWoQLV3dsUBzcHoSKkR4svzgP2aiKvOxnH3kB4+a3WD/iu17n2rIbsN4 IP9NIW/13MXAcj0gUOCQso2HIvp3Z+1gFXTJwqmADISf0cZort01N7OJ8fUu4F3V4Amj zyo+6GAY5H+Vtr98YqFDGSfBwVIhlyiD17qWtVK+Bgc6Wk2AbxRu/x8MmSO99X3HSQze WJpg== X-Gm-Message-State: AIkVDXJH1VXybI2yGSVsKMjdkuqBd6R6ZTsMFToGLjtDN4O0rp3RScidFmw+9y/REXh0ZlKm X-Received: by 10.223.164.85 with SMTP id e21mr26401257wra.111.1485358470711; Wed, 25 Jan 2017 07:34:30 -0800 (PST) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id 33sm2462760wrd.34.2017.01.25.07.34.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Jan 2017 07:34:30 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Alexandre Courbot , Bamvor Jian Zhang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 2/7] gpiolib: support monitoring mockup devices Date: Wed, 25 Jan 2017 16:34:16 +0100 Message-Id: <1485358461-24070-3-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com> References: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add a new flag to struct gpio_chip indicating that the chip doesn't model a real device. When setting up the line event queue, check if a device is a mockup chip and don't actually request the interrupt. This way we can monitor mockup GPIOs. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 27 +++++++++++++++++---------- include/linux/gpio/driver.h | 4 ++++ 2 files changed, 21 insertions(+), 10 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 6722579..19b4b8b 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -735,6 +735,7 @@ static irqreturn_t lineevent_irq_thread(int irq, void *p) static int lineevent_create(struct gpio_device *gdev, void __user *ip) { + struct gpio_chip *chip = gdev->chip; struct gpioevent_request eventreq; struct lineevent_state *le; struct gpio_desc *desc; @@ -807,7 +808,8 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) goto out_free_desc; le->irq = gpiod_to_irq(desc); - if (le->irq <= 0) { + /* Mockup gpiochips don't have to support this. */ + if (le->irq <= 0 && !chip->mockup) { ret = -ENODEV; goto out_free_desc; } @@ -823,15 +825,20 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) init_waitqueue_head(&le->wait); mutex_init(&le->read_lock); - /* Request a thread to read the events */ - ret = request_threaded_irq(le->irq, - NULL, - lineevent_irq_thread, - irqflags, - le->label, - le); - if (ret) - goto out_free_desc; + if (!chip->mockup) { + /* + * Request a thread to read the events unless we're dealing + * with a mockup gpiochip. + */ + ret = request_threaded_irq(le->irq, + NULL, + lineevent_irq_thread, + irqflags, + le->label, + le); + if (ret) + goto out_free_desc; + } fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC); if (fd < 0) { diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index e973fab..912eae1 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -82,6 +82,9 @@ enum single_ended_mode { * implies that if the chip supports IRQs, these IRQs need to be threaded * as the chip access may sleep when e.g. reading out the IRQ status * registers. + * @mockup: if set, the flag signifies that this gpiochip does not model a + * real device; this can affect the way the chip is handled internally + * by gpiolib. * @read_reg: reader function for generic GPIO * @write_reg: writer function for generic GPIO * @pin2mask: some generic GPIO controllers work with the big-endian bits @@ -166,6 +169,7 @@ struct gpio_chip { u16 ngpio; const char *const *names; bool can_sleep; + bool mockup; #if IS_ENABLED(CONFIG_GPIO_GENERIC) unsigned long (*read_reg)(void __iomem *reg); From patchwork Wed Jan 25 15:34:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 92464 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp2237608obz; Wed, 25 Jan 2017 07:34:46 -0800 (PST) X-Received: by 10.98.8.11 with SMTP id c11mr47361822pfd.135.1485358486393; Wed, 25 Jan 2017 07:34:46 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r17si20243879pgd.173.2017.01.25.07.34.46; Wed, 25 Jan 2017 07:34:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751803AbdAYPef (ORCPT + 25 others); Wed, 25 Jan 2017 10:34:35 -0500 Received: from mail-wm0-f49.google.com ([74.125.82.49]:36666 "EHLO mail-wm0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751731AbdAYPed (ORCPT ); Wed, 25 Jan 2017 10:34:33 -0500 Received: by mail-wm0-f49.google.com with SMTP id c85so31497741wmi.1 for ; Wed, 25 Jan 2017 07:34:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=B60h2x1N2gcRnEg0o3+3ymjTDz3+F+yMITVR6XGM5eM=; b=pTEhhjMjUUyMFQgip4DyZAmrpGPo2asSk1945+W0kyIQQAkKBrg1O3q8h1uW4dTu/+ gzm1wdaIa04zTO+QVYUtZJHIDQVuoF6w4CgcjqEVyarR5HlmOkjiy9ZLyPhAqhoI+k+B SppjaSyieXqAtFs58PT9BNMSmycPTKexS14LiTaNm3/S6WE8Uso2bmiYU76jyuvc19xk euRQNpJM7CxF7prUYqa55NuT4YbboiScBSE2VbemR+MocG0dfqmV85zKEQYwUslmJARn 4647W59KXoFCDr2HvjACKMlZ19lp3sTb9AmFDi22DZkpjOExLfMDXEED98fuCFfOp3CQ fOuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=B60h2x1N2gcRnEg0o3+3ymjTDz3+F+yMITVR6XGM5eM=; b=Or5siKvvsRsfynj5Rkt6bfYa3xX6J51lzdGpj71QwaOuay0lb5Y5zc9PoXUY4GkMrP QwejroOCtOp33NcikVQm/YXIG08VmDHEw4OQoovyYaWwOxOk6JUoA70s77Yb42oHzQuk NcRrWa2KQs9Htku+cJ5+aXYXB35UxRvtwOXJc12EfsHpQ6w0sva8WJgz84ThmZCuQwGY ywzakMd3AGz8Dqe1Bk1Qh9cWdJHD0x2rc3XgNswAVR4PJOMHo43vWZchPMktYIQ7uXBg DpboLaRJ2IYLmsdbueShoFOdeNDyHzgAI/AE2A4NE04m9rArckawaGfegrlAXEQ8vwQE gmXw== X-Gm-Message-State: AIkVDXIj84D/Q5NxTM33JTCsz5pP/vjYEitzTXuenghRk1OlsLRRv7rEsdhqLidWmSkbJJ5X X-Received: by 10.28.7.7 with SMTP id 7mr25439318wmh.55.1485358471734; Wed, 25 Jan 2017 07:34:31 -0800 (PST) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id 33sm2462760wrd.34.2017.01.25.07.34.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Jan 2017 07:34:31 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Alexandre Courbot , Bamvor Jian Zhang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 3/7] gpio: mockup: set the mockup flag in struct gpio_chip Date: Wed, 25 Jan 2017 16:34:17 +0100 Message-Id: <1485358461-24070-4-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com> References: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org gpio-mockup creates dummy devices, so indicate it. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 1 + 1 file changed, 1 insertion(+) -- 2.9.3 diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 82a9efd..cf8b1b2 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -101,6 +101,7 @@ static int mockup_gpio_add(struct device *dev, cntr->gc.direction_output = mockup_gpio_dirout; cntr->gc.direction_input = mockup_gpio_dirin; cntr->gc.get_direction = mockup_gpio_get_direction; + cntr->gc.mockup = true; cntr->stats = devm_kzalloc(dev, sizeof(*cntr->stats) * cntr->gc.ngpio, GFP_KERNEL); if (!cntr->stats) { From patchwork Wed Jan 25 15:34:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 92470 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp2238426obz; Wed, 25 Jan 2017 07:36:31 -0800 (PST) X-Received: by 10.99.234.83 with SMTP id l19mr44552851pgk.114.1485358591421; Wed, 25 Jan 2017 07:36:31 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h73si23758057pfj.165.2017.01.25.07.36.31; Wed, 25 Jan 2017 07:36:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752024AbdAYPg3 (ORCPT + 25 others); Wed, 25 Jan 2017 10:36:29 -0500 Received: from mail-wm0-f52.google.com ([74.125.82.52]:36689 "EHLO mail-wm0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751763AbdAYPee (ORCPT ); Wed, 25 Jan 2017 10:34:34 -0500 Received: by mail-wm0-f52.google.com with SMTP id c85so31498844wmi.1 for ; Wed, 25 Jan 2017 07:34:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=YVE8EvOYJwenlYlxuKofc920floT+VfLHZ1fDccm+Tc=; b=KsXVU8dzy3mQ4uqB65QZ2ULYyaMYa2p33eVpwhhEcSrZR5McuLGNG9Ev82mDBFhxfe CufeAqCEGim8qL5rbkqP8y7L/7RB6t/GxkFx5jP7a9kn0cPWsP429W9ErfpGZu+00coi 9L9x9oLqJgIxMQtGXiEGSudUYjjK2VByWEWvyD5IME2EcLDcnxjx57eYSu7NrTVmrnyf i76Eax96lWOSUJD2CaNcKNzkQ7N1TnWH5fY+i21g/c1y6PEXyp9rBE402LwTfdZTVSOr qM4Vg+2WGCzIYHo8vLIQCTY9QIvyLkqRg87I+T6Pk+tKY7SDuNz7mQjzB5WS2VDzfhVq zNhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YVE8EvOYJwenlYlxuKofc920floT+VfLHZ1fDccm+Tc=; b=nShyEZ8Nb0J93f59S+lgizCDi42GubQiRsZ+OQe1LtN2+3l9fWGoB80kVGCLkoGM0L hzJU4IToK+VyBIfQiGuiMt0d0znMpn2G0uD6kyvNyRFHHJfWoM/wDZ1PMsnva4tNOq99 /KnvYkeOH7go2P/yo5rgJ2l544vaGHKgznzA4MsmK99zGVINqLEd5evCJKqaIaQbjsxT 3rk2wuawTtLbBNdq8ulKmCaArTAwPtQdk41DwBhpcJcMbUWvEL4i5vNA479wbVHctdMU glZxgH1CemxTKAa3v6US/cPmETECnMCpMqV2A50In8XzvK8ZrSaKvMFmGnTCM36StWFF N94A== X-Gm-Message-State: AIkVDXJnjYO+C+A7n2AGdIdW3SVpjxDvnBcNHUg0ytLGVVIKdbSKvYn7ZAfoNrLejzvZ73wP X-Received: by 10.223.171.17 with SMTP id q17mr33717898wrc.61.1485358472851; Wed, 25 Jan 2017 07:34:32 -0800 (PST) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id 33sm2462760wrd.34.2017.01.25.07.34.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Jan 2017 07:34:32 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Alexandre Courbot , Bamvor Jian Zhang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 4/7] gpiolib: allow injecting line events Date: Wed, 25 Jan 2017 16:34:18 +0100 Message-Id: <1485358461-24070-5-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com> References: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Implement a routine visible inside the drivers/gpio directory, that allows to inject line events for testing/debugging purposes. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 16 ++++++++++++++++ drivers/gpio/gpiolib.h | 4 ++++ 2 files changed, 20 insertions(+) -- 2.9.3 diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 19b4b8b..8dde5f1 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -643,6 +643,7 @@ static int lineevent_release(struct inode *inode, struct file *filep) struct gpio_device *gdev = le->gdev; free_irq(le->irq, le); + le->desc->le = NULL; gpiod_free(le->desc); kfree(le->label); kfree(le); @@ -733,6 +734,20 @@ static irqreturn_t lineevent_irq_thread(int irq, void *p) return IRQ_HANDLED; } +void gpiod_inject_event(struct gpio_desc *desc) +{ + struct lineevent_state *le = desc->le; + unsigned long flags; + + if (le) { + /* Act as if we were in interrupt context. */ + local_irq_save(flags); + lineevent_irq_thread(-1 /* unused */, le); + local_irq_restore(flags); + } +} +EXPORT_SYMBOL(gpiod_inject_event); + static int lineevent_create(struct gpio_device *gdev, void __user *ip) { struct gpio_chip *chip = gdev->chip; @@ -794,6 +809,7 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) if (ret) goto out_free_desc; le->desc = desc; + desc->le = le; le->eflags = eflags; if (lflags & GPIOHANDLE_REQUEST_ACTIVE_LOW) diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 067e5e5..3c87222 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -23,6 +23,7 @@ enum of_gpio_flags; enum gpiod_flags; enum gpio_lookup_flags; struct acpi_device; +struct lineevent_state; /** * struct gpio_device - internal state container for GPIO devices @@ -196,12 +197,15 @@ struct gpio_desc { const char *label; /* Name of the GPIO */ const char *name; + /* Private: line event context for the GPIO */ + struct lineevent_state *le; }; int gpiod_request(struct gpio_desc *desc, const char *label); void gpiod_free(struct gpio_desc *desc); int gpiod_hog(struct gpio_desc *desc, const char *name, unsigned long lflags, enum gpiod_flags dflags); +void gpiod_inject_event(struct gpio_desc *desc); /* * Return the GPIO number of the passed descriptor relative to its chip From patchwork Wed Jan 25 15:34:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 92465 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp2237616obz; Wed, 25 Jan 2017 07:34:46 -0800 (PST) X-Received: by 10.98.133.11 with SMTP id u11mr47571424pfd.132.1485358486793; Wed, 25 Jan 2017 07:34:46 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r17si20243879pgd.173.2017.01.25.07.34.46; Wed, 25 Jan 2017 07:34:46 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751495AbdAYPem (ORCPT + 25 others); Wed, 25 Jan 2017 10:34:42 -0500 Received: from mail-wm0-f47.google.com ([74.125.82.47]:35238 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751784AbdAYPef (ORCPT ); Wed, 25 Jan 2017 10:34:35 -0500 Received: by mail-wm0-f47.google.com with SMTP id r126so31931233wmr.0 for ; Wed, 25 Jan 2017 07:34:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rIjwNTxW+s7KKYycVPktAAsYkQyntBU15JAHBLnK6VM=; b=efnz+1b/LhsP86Lr5VY73TcyaSjOhdbU/vKuqWIQjrAIVOQhzQ+6eQ6/SjObC2bGP+ Z01YMREjuOUE0ORL+icwEr9e89cU46Vu0FDhuve9Ss6aHGvIqV5MH/ZXELxcgv/E5/6F ffZPRLlhlav7sRaY3kwhFRRMZ+3GxH8H0b9T4nMwQXF96hNUWV2y/l/LsLeEdY5Z5hHl FyY82A9dpE0kS1ArZIAKBPrTvflgcQOhMOsB9azCVum32YF8YCSIogIqbTGE9ZbXubAd tq6BYCIJgGH2dskfopkeDUQLbLdukyNVJ5pZZeFz6TVeZjZvdXrOTZ2tEzv0CvsMA+nr ZyLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=rIjwNTxW+s7KKYycVPktAAsYkQyntBU15JAHBLnK6VM=; b=Il/4n2Jp5Ti07rEeyYvzQ9tmyewdOnWyAbA1wo7ibeQVGQEySpBjqwE8tEE53oWyBs QjC4s5OO5+Cy50GmQ6zrsPlPxDTpFKv6MiL7DCc0cw+yeOHs/WAKX4uiztHi4wkr+TJ/ vee5LO76KU/KuUvLL9rKScBGNzvndKs8rHRgQ2EoRM/VmgMYJb51Zr5d+KGgnF/Py1+2 GgBAIbB7f2n09ap9zePSSOdYkbAeWOzh6OFHaWh9VgSAvj8btea0jOxjLtfZySPXO8cj uqdjvSQijpT61bmbF24av8XKLJevmjVmcx3lYXm4Ep0vYeQU+K3W9XeJGN0y5AV9gr5W 8SxA== X-Gm-Message-State: AIkVDXJy7ZRpjoWsbMpqPa8ouu5rnlZ3DlwipTOBTrUrUV3tDPhXj6e0qopdkAg9PU9V8oCS X-Received: by 10.223.174.183 with SMTP id y52mr37617820wrc.112.1485358473854; Wed, 25 Jan 2017 07:34:33 -0800 (PST) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id 33sm2462760wrd.34.2017.01.25.07.34.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Jan 2017 07:34:33 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Alexandre Courbot , Bamvor Jian Zhang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 5/7] gpio: mockup: implement injecting events over debugfs Date: Wed, 25 Jan 2017 16:34:19 +0100 Message-Id: <1485358461-24070-6-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com> References: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When probing gpio-mockup, create a debugfs directory structure that allows the user to inject line events by writing either 0 (falling-edge) or 1 (rising-edge) to debugfs files. The gpio-mockup-event directory has one sub-directory per chip and a single event file per line. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) -- 2.9.3 diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index cf8b1b2..c5eb530 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -15,6 +15,10 @@ #include #include #include +#include +#include + +#include "gpiolib.h" #define GPIO_NAME "gpio-mockup" #define MAX_GC 10 @@ -37,6 +41,7 @@ struct gpio_pin_status { struct mockup_gpio_controller { struct gpio_chip gc; struct gpio_pin_status *stats; + struct dentry *dbg_dir; }; static int gpio_mockup_ranges[MAX_GC << 1]; @@ -44,6 +49,7 @@ static int gpio_mockup_params_nr; module_param_array(gpio_mockup_ranges, int, &gpio_mockup_params_nr, 0400); static const char pins_name_start = 'A'; +static struct dentry *dbg_dir; static int mockup_gpio_get(struct gpio_chip *gc, unsigned int offset) { @@ -85,6 +91,80 @@ static int mockup_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) return cntr->stats[offset].dir; } +static ssize_t mockup_gpio_event_write(struct file *file, + const char __user *usr_buf, + size_t size, loff_t *ppos) +{ + struct gpio_desc *desc; + struct seq_file *sfile; + int status, val; + char buf; + + sfile = file->private_data; + desc = sfile->private; + + status = copy_from_user(&buf, usr_buf, 1); + if (status) + return status; + + if (buf == '0') + val = 0; + else if (buf == '1') + val = 1; + else + return -EINVAL; + + gpiod_set_value_cansleep(desc, val); + gpiod_inject_event(desc); + + return size; +} + +static int mockup_gpio_event_open(struct inode *inode, struct file *file) +{ + return single_open(file, NULL, inode->i_private); +} + +static const struct file_operations mockup_gpio_event_ops = { + .owner = THIS_MODULE, + .open = mockup_gpio_event_open, + .write = mockup_gpio_event_write, + .llseek = no_llseek, +}; + +static void mockup_gpio_debugfs_setup(struct mockup_gpio_controller *cntr) +{ + struct dentry *evfile; + struct gpio_chip *gc; + struct device *dev; + char *name; + int i; + + gc = &cntr->gc; + dev = &gc->gpiodev->dev; + + cntr->dbg_dir = debugfs_create_dir(gc->label, dbg_dir); + if (!cntr->dbg_dir) + goto err; + + for (i = 0; i < gc->ngpio; i++) { + name = devm_kasprintf(dev, GFP_KERNEL, "%d", i); + if (!name) + goto err; + + evfile = debugfs_create_file(name, 0200, cntr->dbg_dir, + &gc->gpiodev->descs[i], + &mockup_gpio_event_ops); + if (!evfile) + goto err; + } + + return; + +err: + dev_err(dev, "error creating debugfs directory\n"); +} + static int mockup_gpio_add(struct device *dev, struct mockup_gpio_controller *cntr, const char *name, int base, int ngpio) @@ -112,6 +192,9 @@ static int mockup_gpio_add(struct device *dev, if (ret) goto err; + if (dbg_dir) + mockup_gpio_debugfs_setup(cntr); + dev_info(dev, "gpio<%d..%d> add successful!", base, base + ngpio); return 0; err: @@ -182,6 +265,10 @@ static int __init mock_device_init(void) { int err; + dbg_dir = debugfs_create_dir("gpio-mockup-event", NULL); + if (!dbg_dir) + pr_err("%s: error creating debugfs directory\n", GPIO_NAME); + pdev = platform_device_alloc(GPIO_NAME, -1); if (!pdev) return -ENOMEM; @@ -203,6 +290,7 @@ static int __init mock_device_init(void) static void __exit mock_device_exit(void) { + debugfs_remove_recursive(dbg_dir); platform_driver_unregister(&mockup_gpio_driver); platform_device_unregister(pdev); } From patchwork Wed Jan 25 15:34:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 92467 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp2237725obz; Wed, 25 Jan 2017 07:34:59 -0800 (PST) X-Received: by 10.84.210.8 with SMTP id z8mr4508357plh.94.1485358499131; Wed, 25 Jan 2017 07:34:59 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f9si1892835plk.180.2017.01.25.07.34.59; Wed, 25 Jan 2017 07:34:59 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751879AbdAYPey (ORCPT + 4 others); Wed, 25 Jan 2017 10:34:54 -0500 Received: from mail-wm0-f54.google.com ([74.125.82.54]:34192 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751878AbdAYPeq (ORCPT ); Wed, 25 Jan 2017 10:34:46 -0500 Received: by mail-wm0-f54.google.com with SMTP id f73so52862232wmf.1 for ; Wed, 25 Jan 2017 07:34:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=dgJhgHCm+EEUIQ1sce9EF83+QcIAtfgF4ykDEdD/BoE=; b=e/fkLc752ZRBiGkpvnw71D702PjyX356xsnEBS1+fSM3RNM2x37pyFGSBH4Rtpk6Li VXaymR+y1/tMcMcvOp7KP608lGm+j3RESVr1BlqIN6mye9CKQSKOz+UF8dwjQq4kp7IA wHoknNYVgWa1iNlpCdh1lGln5zecmcYaLm320/SxZkIsmM7JB9NoRafGqCUMX9F3o5mh BdzEmPZwSWlULPmHnlCO2GH5B9w3y2lq5HkTeQitGQdKj4uvV43SuxgE/p7BQp+NWWHu kY1lVjKClhrsxKo4a+NY7t+goYupLPXz7tWItxfClsmSIeozGN1AU2sWmawksceKpWXP bj+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=dgJhgHCm+EEUIQ1sce9EF83+QcIAtfgF4ykDEdD/BoE=; b=LK7to5Uy3/bvish+bO+tPiwB5DlWhGOse3/QgGMY2U+6DPjjef9LBgjlYny0IwsPDl 6rB3bwXp/6I0XK9V2MTLqq6WdaeV3iWBE5D1CQDdYvGIIl/Z/mVQs0gQhfdGstV7yEPt +lw1OJpGxN0AEZ9YJU+f/fj2l+MNHGhsv2wiyLBgSxHYicjxHNOX6cRm1h9RUiekdZh0 tpfcDUKK9YFa6TXj1+odtxEsckQkqx+4BW9/pIRCDV/wo5bYt8icBxRI5BthV+w+zchP UdvFuKFFJKh2gv8IcAQgc7yhQ1xpidbrxkV4brrftgJz8MdpXLz3VBrdxLqt9IrBGF6s JPHw== X-Gm-Message-State: AIkVDXIaGTJ1sTAQmfKN4QjZti8zydjjow0ej02NbkI2xADbbK+R+uFeDFwx25xv+zELumRB X-Received: by 10.28.215.200 with SMTP id o191mr22474608wmg.118.1485358474782; Wed, 25 Jan 2017 07:34:34 -0800 (PST) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id 33sm2462760wrd.34.2017.01.25.07.34.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Jan 2017 07:34:34 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Alexandre Courbot , Bamvor Jian Zhang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 6/7] gpio: mockup: implement naming the GPIO lines Date: Wed, 25 Jan 2017 16:34:20 +0100 Message-Id: <1485358461-24070-7-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com> References: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Implement a new boolean module argument that indicates that the mockup lines should be named. The names are created by appending the line offset to the chip label. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index c5eb530..dabf3ec 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "gpiolib.h" @@ -48,6 +49,10 @@ static int gpio_mockup_ranges[MAX_GC << 1]; static int gpio_mockup_params_nr; module_param_array(gpio_mockup_ranges, int, &gpio_mockup_params_nr, 0400); +static bool gpio_mockup_named_lines; +module_param_named(gpio_mockup_named_lines, + gpio_mockup_named_lines, bool, 0400); + static const char pins_name_start = 'A'; static struct dentry *dbg_dir; @@ -169,7 +174,8 @@ static int mockup_gpio_add(struct device *dev, struct mockup_gpio_controller *cntr, const char *name, int base, int ngpio) { - int ret; + char **names; + int ret, i; cntr->gc.base = base; cntr->gc.ngpio = ngpio; @@ -188,6 +194,28 @@ static int mockup_gpio_add(struct device *dev, ret = -ENOMEM; goto err; } + + if (gpio_mockup_named_lines) { + names = devm_kzalloc(dev, + sizeof(char *) * cntr->gc.ngpio, + GFP_KERNEL); + if (!names) { + ret = -ENOMEM; + goto err; + } + + for (i = 0; i < cntr->gc.ngpio; i++) { + names[i] = devm_kasprintf(dev, GFP_KERNEL, + "%s-%d", cntr->gc.label, i); + if (!names[i]) { + ret = -ENOMEM; + goto err; + } + } + + cntr->gc.names = (const char *const*)names; + } + ret = devm_gpiochip_add_data(dev, &cntr->gc, cntr); if (ret) goto err; From patchwork Wed Jan 25 15:34:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 92466 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp2237619obz; Wed, 25 Jan 2017 07:34:47 -0800 (PST) X-Received: by 10.84.176.1 with SMTP id u1mr4556509plb.71.1485358487153; Wed, 25 Jan 2017 07:34:47 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r17si20243879pgd.173.2017.01.25.07.34.46; Wed, 25 Jan 2017 07:34:47 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751874AbdAYPeo (ORCPT + 25 others); Wed, 25 Jan 2017 10:34:44 -0500 Received: from mail-wm0-f47.google.com ([74.125.82.47]:37123 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751838AbdAYPem (ORCPT ); Wed, 25 Jan 2017 10:34:42 -0500 Received: by mail-wm0-f47.google.com with SMTP id c206so37099098wme.0 for ; Wed, 25 Jan 2017 07:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=l9WMJNr8mTg7AQydVzKufltoOz3itPNMNa4zzMLHkN8=; b=gYvZosmtCsVU7lA/lajsSJs4ZEbAVdhm/j9B+XKOmcdFEraTbogSpDxniUWd2E8300 OlvJ09HOOO8gLOlC8hwksoh3x0pd88cdHwLd8+S/kEUZs2rYf444bVXo/WUAUMZPI9L7 4sOQkvZbRVIPabU0S4czFFsmlETlyn1cZ8Wh0iUFY1ivXXpXmImagRVIH8t7RwuJI7La 9dV50eS2s32+NgtEO1cTcHhE7orT/vgLiafP4glo/ECkvvkS9dJuaJI5NarcBg5vjZod 6QhS4Mvh3mjXSqmkEIcESGrIdWaCA0e5XtBbmNrbr8RUdyycO1DpjALGNlzhrIU4iGXS 58kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=l9WMJNr8mTg7AQydVzKufltoOz3itPNMNa4zzMLHkN8=; b=EUF+cINkFivxbwhA6TQwA9pkPDAQzRIIIizFFTn/QnKoBzjAp5DU1UVlp1nz77IWjh onZNiHpePy5RsNy1xE5x7rKGHtJ8Ss3MtALVeUKm4OP83FNE9pSA5kLOCIXtjpZTjeyT RIdq4DPpATRM7YlNswR4UFm68lL9xErnRy/D0xqstRJ44iujJBXQrnsgOPN4t/W2rgVo j2NhBSftWCXYPiX8y3Z2VCZjbFBl+AIBj5+KVUjwHpb+m/stuSLMqFTr845y2rElOJz7 qEJAeCRn73SKBldEFyZUgN0WGI3v7J2VYAyJtKoCe8by6APW/5+urCHDxr3ZSw8iZR3Q Xcxw== X-Gm-Message-State: AIkVDXKFgEfWc8D2DWiSOTHjHophW049nFCeDsbhBiGD1tWd2xmgFaCu1qJ+MyvkEO/9Q8DG X-Received: by 10.223.178.87 with SMTP id y23mr32446275wra.91.1485358475692; Wed, 25 Jan 2017 07:34:35 -0800 (PST) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id 33sm2462760wrd.34.2017.01.25.07.34.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Jan 2017 07:34:35 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Alexandre Courbot , Bamvor Jian Zhang Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 7/7] gpio: mockup: readability tweaks Date: Wed, 25 Jan 2017 16:34:21 +0100 Message-Id: <1485358461-24070-8-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com> References: <1485358461-24070-1-git-send-email-bgolaszewski@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add some newlines and use a temporary pointer in mockup_gpio_add(). Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) -- 2.9.3 diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index dabf3ec..4289bbd 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -78,6 +78,7 @@ static int mockup_gpio_dirout(struct gpio_chip *gc, unsigned int offset, mockup_gpio_set(gc, offset, value); cntr->stats[offset].dir = OUT; + return 0; } @@ -86,6 +87,7 @@ static int mockup_gpio_dirin(struct gpio_chip *gc, unsigned int offset) struct mockup_gpio_controller *cntr = gpiochip_get_data(gc); cntr->stats[offset].dir = IN; + return 0; } @@ -174,21 +176,22 @@ static int mockup_gpio_add(struct device *dev, struct mockup_gpio_controller *cntr, const char *name, int base, int ngpio) { + struct gpio_chip *gc = &cntr->gc; char **names; int ret, i; - cntr->gc.base = base; - cntr->gc.ngpio = ngpio; - cntr->gc.label = name; - cntr->gc.owner = THIS_MODULE; - cntr->gc.parent = dev; - cntr->gc.get = mockup_gpio_get; - cntr->gc.set = mockup_gpio_set; - cntr->gc.direction_output = mockup_gpio_dirout; - cntr->gc.direction_input = mockup_gpio_dirin; - cntr->gc.get_direction = mockup_gpio_get_direction; - cntr->gc.mockup = true; - cntr->stats = devm_kzalloc(dev, sizeof(*cntr->stats) * cntr->gc.ngpio, + gc->base = base; + gc->ngpio = ngpio; + gc->label = name; + gc->owner = THIS_MODULE; + gc->parent = dev; + gc->get = mockup_gpio_get; + gc->set = mockup_gpio_set; + gc->direction_output = mockup_gpio_dirout; + gc->direction_input = mockup_gpio_dirin; + gc->get_direction = mockup_gpio_get_direction; + gc->mockup = true; + cntr->stats = devm_kzalloc(dev, sizeof(*cntr->stats) * gc->ngpio, GFP_KERNEL); if (!cntr->stats) { ret = -ENOMEM; @@ -197,26 +200,25 @@ static int mockup_gpio_add(struct device *dev, if (gpio_mockup_named_lines) { names = devm_kzalloc(dev, - sizeof(char *) * cntr->gc.ngpio, - GFP_KERNEL); + sizeof(char *) * gc->ngpio, GFP_KERNEL); if (!names) { ret = -ENOMEM; goto err; } - for (i = 0; i < cntr->gc.ngpio; i++) { + for (i = 0; i < gc->ngpio; i++) { names[i] = devm_kasprintf(dev, GFP_KERNEL, - "%s-%d", cntr->gc.label, i); + "%s-%d", gc->label, i); if (!names[i]) { ret = -ENOMEM; goto err; } } - cntr->gc.names = (const char *const*)names; + gc->names = (const char *const*)names; } - ret = devm_gpiochip_add_data(dev, &cntr->gc, cntr); + ret = devm_gpiochip_add_data(dev, gc, cntr); if (ret) goto err;