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