From patchwork Mon Aug 14 11:20:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 801156 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="G4AVZKTf"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xWCq74gzlz9sPr for ; Mon, 14 Aug 2017 21:21:23 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753079AbdHNLVV (ORCPT ); Mon, 14 Aug 2017 07:21:21 -0400 Received: from mail-wr0-f177.google.com ([209.85.128.177]:35391 "EHLO mail-wr0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752975AbdHNLVF (ORCPT ); Mon, 14 Aug 2017 07:21:05 -0400 Received: by mail-wr0-f177.google.com with SMTP id k71so33428257wrc.2 for ; Mon, 14 Aug 2017 04:21:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=2LsqyJacn+9zpzPJlwTqLCrX0csdpkalEC5uAQeNDiQ=; b=G4AVZKTf5VvWgQv68wo2DuuVpAgFUy7xOHEcSHXh5Bt5I7fiw2on3sds348/vh29Sx NC+aEUG6JUnNJ+YCxP7y1X2MWzqvfhyFPmVvoi5oe0kGEbwFhznoAzLJjAJOAqDjYvRR qE7xumcNyPNKKufaAc/6qpKHb+dVkIYi4n4insPp9Xx0T038yGStHOxjWmpybtiraayO DxK4pnycz7IbroQVNgw9a/k50i2Bev8ZHXe1WkPOvnn3/R000u2evuU1s3vtjK+YLcQw vRbQsqaIYV9bgZ84y13ccbDp0JoybPlVUyP6Y/Om1h5JD94n9up9KST88qb4UCMzsbJN z0Mg== 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=2LsqyJacn+9zpzPJlwTqLCrX0csdpkalEC5uAQeNDiQ=; b=hWREl+OWD1U0jM99rLXNHAMOaWVA7NstbmpsBahk61KrcjCeXVBdd4t1lfjoCLQWTJ y/E1Cz2+ol0nHcESmcKqwWwJdU6HgrL0VtkbKzEaLXI+/BlZxSwGVmwBbvKxk7H5JYgA PRrxcb3OZg5U8hhKQyWR7ubxgoADlY+zvKdVny2nuK5YhF02FzY7BS3aHydyU7w22+Li kkFlT5pe91fjnLE22vRAoCas+in5DPLIFkEBZyrD1TqAV/jeXajiD4pIYbIEnJRIXiIi p0WeJdtAUZFCtq5Ln4NcVpQsyqDaQKzzYLCHScZ03HyVf0WXgtSC/ufD7iYpq2IUdbn2 vpNg== X-Gm-Message-State: AHYfb5gyHSYwzILj2uZlC+KxF/DMNph3QRKXoHTBOZHHDS1BfOGXaU0G FSVr4w0dz7+P+lI3 X-Received: by 10.223.139.21 with SMTP id n21mr18522462wra.116.1502709664238; Mon, 14 Aug 2017 04:21:04 -0700 (PDT) Received: from bgdev-debian.lan (LFbn-1-7079-41.w90-116.abo.wanadoo.fr. [90.116.248.41]) by smtp.gmail.com with ESMTPSA id d20sm5488593wrc.96.2017.08.14.04.21.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Aug 2017 04:21:03 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , Jonathan Corbet , Bamvor Jian Zhang , Jonathan Cameron , Lars-Peter Clausen Cc: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-doc@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v3 3/3] gpio: mockup: use irq_sim Date: Mon, 14 Aug 2017 13:20:56 +0200 Message-Id: <20170814112056.3751-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170814112056.3751-1-brgl@bgdev.pl> References: <20170814112056.3751-1-brgl@bgdev.pl> Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Shrink the driver by removing the code dealing with dummy interrupts and replacing it with calls to the irq_sim API. Signed-off-by: Bartosz Golaszewski Acked-by: Jonathan Cameron Reviewed-by: Linus Walleij --- drivers/gpio/Kconfig | 2 +- drivers/gpio/gpio-mockup.c | 77 +++++----------------------------------------- 2 files changed, 8 insertions(+), 71 deletions(-) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 461d6fc3688b..f858faa5731a 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -311,7 +311,7 @@ config GPIO_MOCKUP depends on GPIOLIB && SYSFS select GPIO_SYSFS select GPIOLIB_IRQCHIP - select IRQ_WORK + select IRQ_SIM help This enables GPIO Testing driver, which provides a way to test GPIO subsystem through sysfs(or char device) and debugfs. GPIO_SYSFS diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index a6565e128f9e..6db7163e6d98 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include @@ -47,18 +47,12 @@ enum { struct gpio_mockup_line_status { int dir; bool value; - bool irq_enabled; -}; - -struct gpio_mockup_irq_context { - struct irq_work work; - int irq; }; struct gpio_mockup_chip { struct gpio_chip gc; struct gpio_mockup_line_status *lines; - struct gpio_mockup_irq_context irq_ctx; + struct irq_sim irqsim; struct dentry *dbg_dir; }; @@ -144,65 +138,11 @@ static int gpio_mockup_name_lines(struct device *dev, return 0; } -static int gpio_mockup_to_irq(struct gpio_chip *chip, unsigned int offset) -{ - return chip->irq_base + offset; -} - -static void gpio_mockup_irqmask(struct irq_data *data) +static int gpio_mockup_to_irq(struct gpio_chip *gc, unsigned int offset) { - struct gpio_chip *gc = irq_data_get_irq_chip_data(data); struct gpio_mockup_chip *chip = gpiochip_get_data(gc); - chip->lines[data->irq - gc->irq_base].irq_enabled = false; -} - -static void gpio_mockup_irqunmask(struct irq_data *data) -{ - struct gpio_chip *gc = irq_data_get_irq_chip_data(data); - struct gpio_mockup_chip *chip = gpiochip_get_data(gc); - - chip->lines[data->irq - gc->irq_base].irq_enabled = true; -} - -static struct irq_chip gpio_mockup_irqchip = { - .name = GPIO_MOCKUP_NAME, - .irq_mask = gpio_mockup_irqmask, - .irq_unmask = gpio_mockup_irqunmask, -}; - -static void gpio_mockup_handle_irq(struct irq_work *work) -{ - struct gpio_mockup_irq_context *irq_ctx; - - irq_ctx = container_of(work, struct gpio_mockup_irq_context, work); - handle_simple_irq(irq_to_desc(irq_ctx->irq)); -} - -static int gpio_mockup_irqchip_setup(struct device *dev, - struct gpio_mockup_chip *chip) -{ - struct gpio_chip *gc = &chip->gc; - int irq_base, i; - - irq_base = devm_irq_alloc_descs(dev, -1, 0, gc->ngpio, 0); - if (irq_base < 0) - return irq_base; - - gc->irq_base = irq_base; - gc->irqchip = &gpio_mockup_irqchip; - - for (i = 0; i < gc->ngpio; i++) { - irq_set_chip(irq_base + i, gc->irqchip); - irq_set_chip_data(irq_base + i, gc); - irq_set_handler(irq_base + i, &handle_simple_irq); - irq_modify_status(irq_base + i, - IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE); - } - - init_irq_work(&chip->irq_ctx.work, gpio_mockup_handle_irq); - - return 0; + return irq_sim_irqnum(&chip->irqsim, offset); } static ssize_t gpio_mockup_event_write(struct file *file, @@ -228,11 +168,8 @@ static ssize_t gpio_mockup_event_write(struct file *file, chip = priv->chip; gc = &chip->gc; - if (chip->lines[priv->offset].irq_enabled) { - gpiod_set_value_cansleep(desc, val); - priv->chip->irq_ctx.irq = gc->irq_base + priv->offset; - irq_work_queue(&priv->chip->irq_ctx.work); - } + gpiod_set_value_cansleep(desc, val); + irq_sim_fire(&chip->irqsim, priv->offset); return size; } @@ -319,7 +256,7 @@ static int gpio_mockup_add(struct device *dev, return ret; } - ret = gpio_mockup_irqchip_setup(dev, chip); + ret = devm_irq_sim_init(dev, &chip->irqsim, gc->ngpio); if (ret) return ret;