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);