From patchwork Tue Jan 29 08:44:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1032601 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; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="19J9WBAu"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43pg6v5y2xz9sDL for ; Tue, 29 Jan 2019 19:45:11 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727198AbfA2IpL (ORCPT ); Tue, 29 Jan 2019 03:45:11 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36689 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727892AbfA2IoV (ORCPT ); Tue, 29 Jan 2019 03:44:21 -0500 Received: by mail-wr1-f67.google.com with SMTP id u4so21034034wrp.3 for ; Tue, 29 Jan 2019 00:44:20 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=WQ66DLEKc/MG0DXybe6MWB+l9aGMWDp/DgE2ls7LES8=; b=19J9WBAujCPa7W+q9JrzLjm9Yhpyp2rgsVO/LGDMaJWej8bxfAE4VsiDijFnRGmJp/ L5ZSePWmnW3NdTZzFURQcmu14xnZGv1D5z0J2/Cwj9TKIZliemYMhTGnnPykpRsI7Lyy BsoyZeWP9ZT9XMIPg6HKmKjbxuE5xDo613/Gy1zRQHiusUcoXQKLP0eZjd4Up3iQ8AiM 7CMa9r/cKarVpsIlKWF8gSGTVJNVwMbFxJ44DHdsucwxvrsr276GqQElzzcQyQl+eSLA 3tM8+YgsH2gqKvwfUdFwy1oib1nfKHjPbT8isuRUyBTwpuyzE/CPxlfwK7WDkZpjDFrj nppg== 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:mime-version:content-transfer-encoding; bh=WQ66DLEKc/MG0DXybe6MWB+l9aGMWDp/DgE2ls7LES8=; b=dzep38q3rkPFl2BhpgaXFkgCERSm+tCG8guDkPTzmVAqqUe6ZJ1xDmfvCbucYaUUwO N5uExP+7ReCTaBKyOM8XjFLriVooQHrx+ICWZecwcMYa/ZF48lys7Ry4fN05JE+vgdFO ADihPvphNDthA3WzvhCCv/6Wf3EVHtUre8fH1nHXp8AevyCzpr3Be9kzB9UZIRkWe9pz 8M03dzhpu495xhBya/3mf8f5AFnkwcUc28fy7uVeM1S9EUr5P728y4sNeGPIQfr9eGDp Qamvn7CJEzzFhN6FoG+VriszLySXKqnjjC8zMhAZt/n+OQiZ8aa7WzwNaTf1QmGVuvXN ffnA== X-Gm-Message-State: AJcUukef5+ud4lHRxRrKwQ1StMrJUkEQrW3f+6YK8sjjCTJAduG3iMhb 5bAM+Mc7Xlc+fOCynwhTpIbWVw== X-Google-Smtp-Source: ALg8bN6LQVZ+Z6VoPZb55wXgNP87fbo7rwsmnQOKWUGWkpn/s7LqbHpDae77iy7BgvLKwqvz3t3o8A== X-Received: by 2002:adf:a1d2:: with SMTP id v18mr23835506wrv.87.1548751459446; Tue, 29 Jan 2019 00:44:19 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id c1sm3979319wmb.14.2019.01.29.00.44.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 00:44:18 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 1/9] irq/irq_sim: don't share the irq_chip structure between simulators Date: Tue, 29 Jan 2019 09:44:03 +0100 Message-Id: <20190129084411.30495-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190129084411.30495-1-brgl@bgdev.pl> References: <20190129084411.30495-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We want to support multiple instances of irq_sim. Make struct irq_chip part of the irq_sim structure. Signed-off-by: Bartosz Golaszewski --- include/linux/irq_sim.h | 2 ++ kernel/irq/irq_sim.c | 12 +++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/linux/irq_sim.h b/include/linux/irq_sim.h index 4500d453a63e..eda132c22b57 100644 --- a/include/linux/irq_sim.h +++ b/include/linux/irq_sim.h @@ -6,6 +6,7 @@ #ifndef _LINUX_IRQ_SIM_H #define _LINUX_IRQ_SIM_H +#include #include #include @@ -25,6 +26,7 @@ struct irq_sim_irq_ctx { }; struct irq_sim { + struct irq_chip chip; struct irq_sim_work_ctx work_ctx; int irq_base; unsigned int irq_count; diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c index 98a20e1594ce..b732e4e2e45b 100644 --- a/kernel/irq/irq_sim.c +++ b/kernel/irq/irq_sim.c @@ -25,12 +25,6 @@ static void irq_sim_irqunmask(struct irq_data *data) irq_ctx->enabled = true; } -static struct irq_chip irq_sim_irqchip = { - .name = "irq_sim", - .irq_mask = irq_sim_irqmask, - .irq_unmask = irq_sim_irqunmask, -}; - static void irq_sim_handle_irq(struct irq_work *work) { struct irq_sim_work_ctx *work_ctx; @@ -74,6 +68,10 @@ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs) return sim->irq_base; } + sim->chip.name = "irq_sim"; + sim->chip.irq_mask = irq_sim_irqmask; + sim->chip.irq_unmask = irq_sim_irqunmask; + sim->work_ctx.pending = bitmap_zalloc(num_irqs, GFP_KERNEL); if (!sim->work_ctx.pending) { kfree(sim->irqs); @@ -84,7 +82,7 @@ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs) for (i = 0; i < num_irqs; i++) { sim->irqs[i].irqnum = sim->irq_base + i; sim->irqs[i].enabled = false; - irq_set_chip(sim->irq_base + i, &irq_sim_irqchip); + irq_set_chip(sim->irq_base + i, &sim->chip); irq_set_chip_data(sim->irq_base + i, &sim->irqs[i]); irq_set_handler(sim->irq_base + i, &handle_simple_irq); irq_modify_status(sim->irq_base + i, From patchwork Tue Jan 29 08:44:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1032600 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; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="owXvs/3K"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43pg6t1DPWz9sDr for ; Tue, 29 Jan 2019 19:45:10 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727930AbfA2IoX (ORCPT ); Tue, 29 Jan 2019 03:44:23 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43785 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727904AbfA2IoX (ORCPT ); Tue, 29 Jan 2019 03:44:23 -0500 Received: by mail-wr1-f68.google.com with SMTP id r10so20995863wrs.10 for ; Tue, 29 Jan 2019 00:44:21 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=8M8SkLlBUO6aIkmvQdt73jSIyNWAPLQHicQuYx4M/z8=; b=owXvs/3KpQ85MmIixWzVI0ge13IlH4i71lzEJUZsZ0nglkRxj4rU1LQSV5uXXGP8Fj XGu/X4WUlJHUBxrOcsHpc4Q7aZlXJQtvqTOh+/ioLWHkRrpsNPGAhejvxu2m2LQKg7e4 Sprc5xDWgGX/DYuP4ZC7LEpCqxD8C4Z69SjsmpjxJUsttMUSa4Fb3N1uvzagv0N/3L7G I+c/apqs6DIE9a5exEZRwoxb1ClYc16NI8V51OQLKG4XhXtC/MQ3mx/v3b6XchYVTFi1 zt7gxpeXydjehOgLT7LK/VrapPYdVK6F585wqylS3CYhdI6I3s4U1zuyOmaBxUw2JW7l j2IA== 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:mime-version:content-transfer-encoding; bh=8M8SkLlBUO6aIkmvQdt73jSIyNWAPLQHicQuYx4M/z8=; b=enkPdz2GrimMSKq+1TwTcFw8yROZa+sMyAWwBZZjNiF2CpcI5Ns/xlsQRbj5QWgkBI +72rOCmRDF2sSUfdjgYTpAKwwRf8OXkYjmDygYk0PZ0Ks830utPUIRiPmcO+8AbluXR0 +GoRfREpo1n/ubqR/bIZPataU5C8yk5HVlH/9HRmDC1K4KKr3pKvzSFRg9mhvcGLnydb CbDl/marvMhjunL/uvohP+ZuG62c9KKid/3DbtSdd4UxM+L623wFlJo5LD/gXzE6dAna DGIdVvb9bfs8dWqshEfj1sWBk7Jof3YRuKJbNs+7VzG4JQR9X7Cqc8bIiHjU/ojSlI/+ Gbmw== X-Gm-Message-State: AJcUukfGbbeXgaAuiOdnOUlCamBxgls0Da6q7LfBqCtg9Z3VWb8wmnbJ X9KnaBDn00ahaoNUa2LSGxyRaA== X-Google-Smtp-Source: ALg8bN4+NvpMzrhdEqitwilEY5AqTwtc15FHuRDWKiQKJ8UCYsp1gyI6SCHZNWs/UMBXVjxRztriaQ== X-Received: by 2002:adf:891a:: with SMTP id s26mr24772955wrs.44.1548751460628; Tue, 29 Jan 2019 00:44:20 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id c1sm3979319wmb.14.2019.01.29.00.44.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 00:44:20 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 2/9] irq/irq_sim: use irq domain Date: Tue, 29 Jan 2019 09:44:04 +0100 Message-Id: <20190129084411.30495-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190129084411.30495-1-brgl@bgdev.pl> References: <20190129084411.30495-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Delegate the offset to virq number mapping to the provided framework instead of handling it locally. Use the legacy domain as we want to preallocate the irq descriptors. Signed-off-by: Bartosz Golaszewski --- include/linux/irq_sim.h | 6 +-- kernel/irq/irq_sim.c | 94 +++++++++++++++++++++++++++++------------ 2 files changed, 71 insertions(+), 29 deletions(-) diff --git a/include/linux/irq_sim.h b/include/linux/irq_sim.h index eda132c22b57..b96c2f752320 100644 --- a/include/linux/irq_sim.h +++ b/include/linux/irq_sim.h @@ -8,6 +8,7 @@ #include #include +#include #include /* @@ -21,16 +22,15 @@ struct irq_sim_work_ctx { }; struct irq_sim_irq_ctx { - int irqnum; bool enabled; }; struct irq_sim { struct irq_chip chip; + struct irq_domain *domain; struct irq_sim_work_ctx work_ctx; - int irq_base; + int virq_base; unsigned int irq_count; - struct irq_sim_irq_ctx *irqs; }; int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs); diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c index b732e4e2e45b..2bcdbab1bc5a 100644 --- a/kernel/irq/irq_sim.c +++ b/kernel/irq/irq_sim.c @@ -44,6 +44,43 @@ static void irq_sim_handle_irq(struct irq_work *work) } } +static int irq_sim_domain_map(struct irq_domain *domain, + unsigned int virq, irq_hw_number_t hw) +{ + struct irq_sim *sim = domain->host_data; + struct irq_sim_irq_ctx *ctx; + + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + irq_set_chip(virq, &sim->chip); + irq_set_chip_data(virq, ctx); + irq_set_handler(virq, handle_simple_irq); + irq_modify_status(virq, IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE); + + return 0; +} + +static void irq_sim_domain_free(struct irq_domain *domain, + unsigned int virq, unsigned int num_irqs) +{ + struct irq_sim_irq_ctx *ctx; + struct irq_data *irq; + int i; + + for (i = 0; i < num_irqs; i++) { + irq = irq_domain_get_irq_data(domain, virq + i); + ctx = irq_data_get_irq_chip_data(irq); + kfree(ctx); + } +} + +static const struct irq_domain_ops irq_sim_domain_ops = { + .map = irq_sim_domain_map, + .free = irq_sim_domain_free, +}; + /** * irq_sim_init - Initialize the interrupt simulator: allocate a range of * dummy interrupts. @@ -56,16 +93,15 @@ static void irq_sim_handle_irq(struct irq_work *work) */ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs) { - int i; - - sim->irqs = kmalloc_array(num_irqs, sizeof(*sim->irqs), GFP_KERNEL); - if (!sim->irqs) + sim->virq_base = irq_alloc_descs(-1, 0, num_irqs, 0); + if (sim->virq_base < 0) + return sim->virq_base; + + sim->domain = irq_domain_add_legacy(NULL, num_irqs, sim->virq_base, + 0, &irq_sim_domain_ops, sim); + if (!sim->domain) { + irq_free_descs(sim->virq_base, num_irqs); return -ENOMEM; - - sim->irq_base = irq_alloc_descs(-1, 0, num_irqs, 0); - if (sim->irq_base < 0) { - kfree(sim->irqs); - return sim->irq_base; } sim->chip.name = "irq_sim"; @@ -74,25 +110,15 @@ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs) sim->work_ctx.pending = bitmap_zalloc(num_irqs, GFP_KERNEL); if (!sim->work_ctx.pending) { - kfree(sim->irqs); - irq_free_descs(sim->irq_base, num_irqs); + irq_domain_remove(sim->domain); + irq_free_descs(sim->virq_base, num_irqs); return -ENOMEM; } - for (i = 0; i < num_irqs; i++) { - sim->irqs[i].irqnum = sim->irq_base + i; - sim->irqs[i].enabled = false; - irq_set_chip(sim->irq_base + i, &sim->chip); - irq_set_chip_data(sim->irq_base + i, &sim->irqs[i]); - irq_set_handler(sim->irq_base + i, &handle_simple_irq); - irq_modify_status(sim->irq_base + i, - IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE); - } - init_irq_work(&sim->work_ctx.work, irq_sim_handle_irq); sim->irq_count = num_irqs; - return sim->irq_base; + return sim->virq_base; } EXPORT_SYMBOL_GPL(irq_sim_init); @@ -106,8 +132,8 @@ void irq_sim_fini(struct irq_sim *sim) { irq_work_sync(&sim->work_ctx.work); bitmap_free(sim->work_ctx.pending); - irq_free_descs(sim->irq_base, sim->irq_count); - kfree(sim->irqs); + irq_domain_free_irqs(sim->virq_base, sim->irq_count); + irq_domain_remove(sim->domain); } EXPORT_SYMBOL_GPL(irq_sim_fini); @@ -151,6 +177,20 @@ int devm_irq_sim_init(struct device *dev, struct irq_sim *sim, } EXPORT_SYMBOL_GPL(devm_irq_sim_init); +static struct irq_sim_irq_ctx * +irq_sim_get_ctx(struct irq_sim *sim, unsigned int offset) +{ + struct irq_sim_irq_ctx *ctx; + struct irq_data *irq; + int virq; + + virq = irq_find_mapping(sim->domain, offset); + irq = irq_domain_get_irq_data(sim->domain, virq); + ctx = irq_data_get_irq_chip_data(irq); + + return ctx; +} + /** * irq_sim_fire - Enqueue an interrupt. * @@ -159,7 +199,9 @@ EXPORT_SYMBOL_GPL(devm_irq_sim_init); */ void irq_sim_fire(struct irq_sim *sim, unsigned int offset) { - if (sim->irqs[offset].enabled) { + struct irq_sim_irq_ctx *ctx = irq_sim_get_ctx(sim, offset); + + if (ctx->enabled) { set_bit(offset, sim->work_ctx.pending); irq_work_queue(&sim->work_ctx.work); } @@ -175,6 +217,6 @@ EXPORT_SYMBOL_GPL(irq_sim_fire); */ int irq_sim_irqnum(struct irq_sim *sim, unsigned int offset) { - return sim->irqs[offset].irqnum; + return irq_find_mapping(sim->domain, offset); } EXPORT_SYMBOL_GPL(irq_sim_irqnum); From patchwork Tue Jan 29 08:44:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1032588 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; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="Bey5pOIp"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43pg625lrnz9sDL for ; Tue, 29 Jan 2019 19:44:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727903AbfA2IoZ (ORCPT ); Tue, 29 Jan 2019 03:44:25 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:36204 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727923AbfA2IoY (ORCPT ); Tue, 29 Jan 2019 03:44:24 -0500 Received: by mail-wm1-f65.google.com with SMTP id p6so16715069wmc.1 for ; Tue, 29 Jan 2019 00:44:22 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=LyKOxtNvIzNO612oh1cgft6iGoalHffCBs8NIdrqxbg=; b=Bey5pOIpEYce6rE72UEsnLBBCz3oPP86VduaN172XUV0ZfD19faJAkikztUOzHSvie k8jDpfXqDlFc/jeGmog+0/xhdugXk/es3OFhQVlWC5DRxONpEzmHfnATudv9QvYWWGS9 8TUP1HQyopP39ObgpNBL5+OUedzPArQTClGc0GYhxoCy4Wudlft5aywTPxr/+/EQtKKR Odxch5ZRdR3ajitQ8kPMyH5eJPxW972joNT4xyCvFxRO8UU4EL1tVd29j73a2AA3FsTi beIPoq7odo+ZMdszbKGQoYgYe5w+K1hFA7aJz3H+5JyTpgGQ3IsY2ZSNox5O6QJd/g6Q sfZQ== 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:mime-version:content-transfer-encoding; bh=LyKOxtNvIzNO612oh1cgft6iGoalHffCBs8NIdrqxbg=; b=YyEMuGQWks0EdW/ZmJjSNvykrUbpqOKEaA0YhBDUbjwz1FQ1JXL1m5Cz2mIIbSErqr Pn+QA59tGIhwOztDDOoODPJ1+b0Wx4sJPvAjzrJZIQ/E4BryBZFED8/9GTNIsUwBgwl5 8chy3SQx3deSMwcxJ1ZW05KvWe0gs2ubWylm5SLyP+jIOU12MIqnvojwXYctRkZb369m YLYi7jJ0gwCYsj5ub0d59WdyH2hwgWFBIzX+xWU7wZN9D3Bfn44jkAOBdu6hdFhkje/1 WgTCCeqW6BOcv3NgenxfYeGdEdIqtwKPkdsAo8WMVZQOdU0KnIDj53Y9oiHB8EZQ9kdQ Ce9A== X-Gm-Message-State: AJcUuke89/hTDLN/Xunt36oBGobI+IOA3fuGNUw/5XssYJHC7qVjOcTM dD2aDbjFXxBRrhwmqBg7QszixQ== X-Google-Smtp-Source: ALg8bN4TCg2CGHRaz+V3V2hIkJog0VDogHDLlA+h0Y8lfAQa/XOdHdPx8tvCFvoPGeBSGgUF2AY2Ww== X-Received: by 2002:a1c:f112:: with SMTP id p18mr19060358wmh.83.1548751462018; Tue, 29 Jan 2019 00:44:22 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id c1sm3979319wmb.14.2019.01.29.00.44.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 00:44:21 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 3/9] irq/irq_sim: provide irq_sim_fire_type() Date: Tue, 29 Jan 2019 09:44:05 +0100 Message-Id: <20190129084411.30495-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190129084411.30495-1-brgl@bgdev.pl> References: <20190129084411.30495-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Provide a more specialized variant of irq_sim_fire() that allows to specify the type of the fired interrupt. The type is stored in the dummy irq context struct via the set_type callback. Signed-off-by: Bartosz Golaszewski --- include/linux/irq_sim.h | 9 ++++++++- kernel/irq/irq_sim.c | 26 ++++++++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/include/linux/irq_sim.h b/include/linux/irq_sim.h index b96c2f752320..647a6c8ffb31 100644 --- a/include/linux/irq_sim.h +++ b/include/linux/irq_sim.h @@ -23,6 +23,7 @@ struct irq_sim_work_ctx { struct irq_sim_irq_ctx { bool enabled; + unsigned int type; }; struct irq_sim { @@ -37,7 +38,13 @@ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs); int devm_irq_sim_init(struct device *dev, struct irq_sim *sim, unsigned int num_irqs); void irq_sim_fini(struct irq_sim *sim); -void irq_sim_fire(struct irq_sim *sim, unsigned int offset); +void irq_sim_fire_type(struct irq_sim *sim, + unsigned int offset, unsigned int type); int irq_sim_irqnum(struct irq_sim *sim, unsigned int offset); +static inline void irq_sim_fire(struct irq_sim *sim, unsigned int offset) +{ + irq_sim_fire_type(sim, offset, IRQ_TYPE_DEFAULT); +} + #endif /* _LINUX_IRQ_SIM_H */ diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c index 2bcdbab1bc5a..e3160b5e59b8 100644 --- a/kernel/irq/irq_sim.c +++ b/kernel/irq/irq_sim.c @@ -25,6 +25,15 @@ static void irq_sim_irqunmask(struct irq_data *data) irq_ctx->enabled = true; } +static int irq_sim_set_type(struct irq_data *data, unsigned int type) +{ + struct irq_sim_irq_ctx *irq_ctx = irq_data_get_irq_chip_data(data); + + irq_ctx->type = type; + + return 0; +} + static void irq_sim_handle_irq(struct irq_work *work) { struct irq_sim_work_ctx *work_ctx; @@ -107,6 +116,7 @@ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs) sim->chip.name = "irq_sim"; sim->chip.irq_mask = irq_sim_irqmask; sim->chip.irq_unmask = irq_sim_irqunmask; + sim->chip.irq_set_type = irq_sim_set_type; sim->work_ctx.pending = bitmap_zalloc(num_irqs, GFP_KERNEL); if (!sim->work_ctx.pending) { @@ -192,21 +202,29 @@ irq_sim_get_ctx(struct irq_sim *sim, unsigned int offset) } /** - * irq_sim_fire - Enqueue an interrupt. + * irq_sim_fire_type - Enqueue an interrupt. * * @sim: The interrupt simulator object. * @offset: Offset of the simulated interrupt which should be fired. + * @type: Type of the fired interrupt. Must be one of the following: + * IRQ_TYPE_EDGE_RISING, IRQ_TYPE_EDGE_FALLING, + * IRQ_TYPE_EDGE_BOTH, IRQ_TYPE_LEVEL_HIGH, + * IRQ_TYPE_LEVEL_LOW, IRQ_TYPE_DEFAULT */ -void irq_sim_fire(struct irq_sim *sim, unsigned int offset) +void irq_sim_fire_type(struct irq_sim *sim, + unsigned int offset, unsigned int type) { struct irq_sim_irq_ctx *ctx = irq_sim_get_ctx(sim, offset); - if (ctx->enabled) { + /* Only care about relevant flags. */ + type &= IRQ_TYPE_SENSE_MASK; + + if (ctx->enabled && (ctx->type & type)) { set_bit(offset, sim->work_ctx.pending); irq_work_queue(&sim->work_ctx.work); } } -EXPORT_SYMBOL_GPL(irq_sim_fire); +EXPORT_SYMBOL_GPL(irq_sim_fire_type); /** * irq_sim_irqnum - Get the allocated number of a dummy interrupt. From patchwork Tue Jan 29 08:44:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1032599 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; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="ltJWi/rZ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43pg6k6twlz9sDr for ; Tue, 29 Jan 2019 19:45:02 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728173AbfA2Io4 (ORCPT ); Tue, 29 Jan 2019 03:44:56 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:55704 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727940AbfA2IoZ (ORCPT ); Tue, 29 Jan 2019 03:44:25 -0500 Received: by mail-wm1-f66.google.com with SMTP id y139so16681148wmc.5 for ; Tue, 29 Jan 2019 00:44:23 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=xh6JAmkBnBKkEOMZQs9o929ceuBTII37rCxqn/4TinI=; b=ltJWi/rZsnURDFa+IEr8utG5+hqmxoQ5Dfe6jZ8tlr8Yj/JCkzIsaV9okuhDKjEcBz clcdm3VwumIICl5P7Nz0BAGnEihG7kf+j/7wYX43+9ZMorSAoz0sL11JBMnqkFiPnPXD hjMj/niUOLDhRhFhTrGv8Mr34rKY3BQNnSh+5pULYUYuUReZ2Qv2fw7N/UecYrtx8TU2 2AviEK0qQNhqb+tJhjfP9GBLLqt0ax7/0+IO5ND6lg5kaRXPKpyU3D+goL+gjfnHIeNl yOH6VoDAWWaHnP3g29IkfLATNU+w8N5/DcbmojdtvtM2bA906nnWNbq7yOLQcbbsBHcj PEbg== 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:mime-version:content-transfer-encoding; bh=xh6JAmkBnBKkEOMZQs9o929ceuBTII37rCxqn/4TinI=; b=Zq3hwKyR4CqAVQ3EhmcpUFUbETx4VHnW+31ULYfCDqAEL5hg1hbfnoniwbLAIDTO0D sREH+s2VappvU5I3UTNFb1CzuLkMfRzZANSLIaAcWtJSK037c6uTqS6UF8UoZeSMJQhu hJHmp/7JZOCvQttbmQ3IKmJBBWUzDxLgOUc78BNp44t0hpDePeG/XGSgYseo2lV5/4Hp qhDETY24RohIpFkDG+4WPR7WXbtQ9nrtwzz5SQwrt6zrqc6EdwCOVvg9H8mVsJPu2koG 4q56EhR3FEl7CPY8khFqmk03+ftpxkL9kOwtWX3loaLELNu+QKY6Wz/Fkg5cEiK7Cuws NREw== X-Gm-Message-State: AJcUukdFOXWJZITE4FdHQS2DrIg9AoGN0g+WmefKydg6zBphHl3cAXtV R6F4is94j7YPfs35tTKDxS/VUw== X-Google-Smtp-Source: ALg8bN6eqKUxs1UYmYtabYgWnQX+3uVAffAfuckU/4UwLxqWIJeuVNl0L4lK8zyBNxr03mX2dsvn9A== X-Received: by 2002:a1c:544f:: with SMTP id p15mr20303242wmi.37.1548751463054; Tue, 29 Jan 2019 00:44:23 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id c1sm3979319wmb.14.2019.01.29.00.44.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 00:44:22 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 4/9] gpio: mockup: add locking Date: Tue, 29 Jan 2019 09:44:06 +0100 Message-Id: <20190129084411.30495-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190129084411.30495-1-brgl@bgdev.pl> References: <20190129084411.30495-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski While no user reported any race condition problems with gpio-mockup, let's be on the safe side and use a mutex when performing any changes on the dummy chip structures. Suggested-by: Uwe Kleine-König Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 50 ++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 6a50f9f59c90..b4c1de6acf74 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -54,6 +54,7 @@ struct gpio_mockup_chip { struct gpio_mockup_line_status *lines; struct irq_sim irqsim; struct dentry *dbg_dir; + struct mutex lock; }; struct gpio_mockup_dbgfs_private { @@ -82,29 +83,53 @@ static int gpio_mockup_range_ngpio(unsigned int index) return gpio_mockup_ranges[index * 2 + 1]; } -static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) +static int __gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); return chip->lines[offset].value; } -static void gpio_mockup_set(struct gpio_chip *gc, - unsigned int offset, int value) +static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) +{ + struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + int val; + + mutex_lock(&chip->lock); + val = __gpio_mockup_get(gc, offset); + mutex_unlock(&chip->lock); + + return val; +} + +static void __gpio_mockup_set(struct gpio_chip *gc, + unsigned int offset, int value) { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); chip->lines[offset].value = !!value; } +static void gpio_mockup_set(struct gpio_chip *gc, + unsigned int offset, int value) +{ + struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + + mutex_lock(&chip->lock); + __gpio_mockup_set(gc, offset, value); + mutex_unlock(&chip->lock); +} + static void gpio_mockup_set_multiple(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits) { + struct gpio_mockup_chip *chip = gpiochip_get_data(gc); unsigned int bit; + mutex_lock(&chip->lock); for_each_set_bit(bit, mask, gc->ngpio) - gpio_mockup_set(gc, bit, test_bit(bit, bits)); - + __gpio_mockup_set(gc, bit, test_bit(bit, bits)); + mutex_unlock(&chip->lock); } static int gpio_mockup_dirout(struct gpio_chip *gc, @@ -112,8 +137,10 @@ static int gpio_mockup_dirout(struct gpio_chip *gc, { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); - gpio_mockup_set(gc, offset, value); + mutex_lock(&chip->lock); chip->lines[offset].dir = GPIO_MOCKUP_DIR_OUT; + __gpio_mockup_set(gc, offset, value); + mutex_unlock(&chip->lock); return 0; } @@ -122,7 +149,9 @@ static int gpio_mockup_dirin(struct gpio_chip *gc, unsigned int offset) { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + mutex_lock(&chip->lock); chip->lines[offset].dir = GPIO_MOCKUP_DIR_IN; + mutex_unlock(&chip->lock); return 0; } @@ -130,8 +159,13 @@ static int gpio_mockup_dirin(struct gpio_chip *gc, unsigned int offset) static int gpio_mockup_get_direction(struct gpio_chip *gc, unsigned int offset) { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + int direction; - return !chip->lines[offset].dir; + mutex_lock(&chip->lock); + direction = !chip->lines[offset].dir; + mutex_unlock(&chip->lock); + + return direction; } static int gpio_mockup_to_irq(struct gpio_chip *gc, unsigned int offset) @@ -283,6 +317,8 @@ static int gpio_mockup_probe(struct platform_device *pdev) return -ENOMEM; } + mutex_init(&chip->lock); + gc = &chip->gc; gc->base = base; gc->ngpio = ngpio; From patchwork Tue Jan 29 08:44:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1032596 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; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="Pp5HBo+z"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43pg6d14MRz9sN6 for ; Tue, 29 Jan 2019 19:44:57 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727973AbfA2Io0 (ORCPT ); Tue, 29 Jan 2019 03:44:26 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:36206 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727958AbfA2Io0 (ORCPT ); Tue, 29 Jan 2019 03:44:26 -0500 Received: by mail-wm1-f65.google.com with SMTP id p6so16715165wmc.1 for ; Tue, 29 Jan 2019 00:44:24 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=PpLsHCDGluO1vsNVw+7Cy8rzFc8ImPXS2+/9yCySWm4=; b=Pp5HBo+zRn/FU3isdmHpTUH2RZxF4VrG1kIQFAFHV7e3eCTHrhIqw0HV5j+fgORdEb AyeOXMEEhhUV5WAOteb6y+p8Db3NR4cwuI2d6nk2DTcBeM9wrJxY3L1DumfbihVPbUir K8UYsOdcbW+BFEr5+nBg+p1ebfAsf/tWzkDgOWZb4fMe8AID9Lg85VvOcBf0oSHF9RVK LbnHmFnKYOqMG4nC//v3wcvYBkVjCvO+o/RmKxa1kKQ8YyxdXS7mSBdEQuGh1OWgHyOp PPsuU/Kw5vf9vNkQQCH7htsqKQsaKSZcVtgKjugMEeXPH6Zw08HIj5uxvMZ67m1SW4JV AOiw== 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:mime-version:content-transfer-encoding; bh=PpLsHCDGluO1vsNVw+7Cy8rzFc8ImPXS2+/9yCySWm4=; b=oKXhUsbhgCXJcVRDrQAUw6oMybl/BzdO00oZTJa8utkU+W9sHzYzAwu0bHGkR/k7Lw PAJkDzRRbgOo9ZFpXNNWXSI/xiXDYD9K4z7hvrbOr/99SnbMDB5+/lK6PjqqrqyliUZg zG4VI5yWtN+kyeUZJXmQG6SgT2JhBA5tiIrExA1w40EYtfjOWzE4xhuCYIv3XRD7g3Ia V5EOQz06OtUFOMCaaullcbGAIMvVU+ns3p6balAuf1yBBWuQcRWO+mtMCjJq779oPZQp 3e1YLnHluj96q6c+mRMsM7dZwi3/Uuyuw7ABFRyq2L1Lvm9SIQ03voKckSHrx+My9lRH ycAw== X-Gm-Message-State: AJcUukf5mYAqxLIfmLuhuxAvqDkIUBD0U3XlQ4qrL6pNxpEiVOwgREMx 2eN7VnaBz5q0qGDJxU/4H9hxTg== X-Google-Smtp-Source: ALg8bN6YcqkYwHzvCHmHeMYrBuWpIGlT1j625Q0slRB9xXDK9KqBHcVex1iZ8MJnK+qisOvn0hTZ0A== X-Received: by 2002:a1c:b189:: with SMTP id a131mr21019132wmf.38.1548751464206; Tue, 29 Jan 2019 00:44:24 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id c1sm3979319wmb.14.2019.01.29.00.44.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 00:44:23 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 5/9] gpio: mockup: implement get_multiple() Date: Tue, 29 Jan 2019 09:44:07 +0100 Message-Id: <20190129084411.30495-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190129084411.30495-1-brgl@bgdev.pl> References: <20190129084411.30495-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We already support set_multiple(). Implement get_multiple() as well. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index b4c1de6acf74..1c945c967f60 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -102,6 +102,22 @@ static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) return val; } +static int gpio_mockup_get_multiple(struct gpio_chip *gc, + unsigned long *mask, unsigned long *bits) +{ + struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + unsigned int bit, val; + + mutex_lock(&chip->lock); + for_each_set_bit(bit, mask, gc->ngpio) { + val = __gpio_mockup_get(gc, bit); + __assign_bit(bit, bits, val); + } + mutex_unlock(&chip->lock); + + return 0; +} + static void __gpio_mockup_set(struct gpio_chip *gc, unsigned int offset, int value) { @@ -327,6 +343,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) gc->parent = dev; gc->get = gpio_mockup_get; gc->set = gpio_mockup_set; + gc->get_multiple = gpio_mockup_get_multiple; gc->set_multiple = gpio_mockup_set_multiple; gc->direction_output = gpio_mockup_dirout; gc->direction_input = gpio_mockup_dirin; From patchwork Tue Jan 29 08:44:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1032597 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; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="luLynmjS"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43pg6d6bbYz9sDr for ; Tue, 29 Jan 2019 19:44:57 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727981AbfA2Ioz (ORCPT ); Tue, 29 Jan 2019 03:44:55 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54674 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727968AbfA2Io1 (ORCPT ); Tue, 29 Jan 2019 03:44:27 -0500 Received: by mail-wm1-f67.google.com with SMTP id a62so16828801wmh.4 for ; Tue, 29 Jan 2019 00:44:26 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=oFYrT2wnMCaEZTFTRohnQPMYE3Q3Qh5QyDn+YPY7eC4=; b=luLynmjSgmxhjno+ghspWTDkEw4fn3ucg4QWzyQSRZgMJUXCVFXp/jx+TPHborJqUW YoUZlaJtpHdZnVh2f5oagC06B5RsojUpskYnsjBJE55/z4V1V3tZL1VkA0QN0gccjc2e q/vbGtK4H+RMs9y/n9adtV5RFBMGqCE4ynsjUFZHBtucDKCWb9toqXGJuzug0LM5H4gW lPRDwiDhQgX2a2OxEKUmdtdp4GL4dTR6GVXTmOvJOib+PY6M3mQdCCIDhz7Jr7icS+Dh mo/Ckt7K0Kw2NGV624Dk3z1zTXiI8+tjcV1JklNaJieuy5+ywzeCTWtUr0i0f7+cYSDg Ttrg== 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:mime-version:content-transfer-encoding; bh=oFYrT2wnMCaEZTFTRohnQPMYE3Q3Qh5QyDn+YPY7eC4=; b=d5T6M9vgjgqNZeahAFfzyUB3bwTtzgfuwKtlAeF50QQ9lXfY6FYdiwdjwAaNkFWHei UmQDJca7NKwdqlQOKIX8idR0igpz7WCf5dFaDX7c12cVVzfOf3pVQNnKwyT2FAohnfH3 Fe5MrwtcaheXvzNdI4gf9N/5x2tDnS3C/WQ1Aul77yQyFYSmUuxEBsZ9T7dw8r7mYv+S 9YPUKUYsI0LTgn+nx1oOwyAZRGEnmS0jz7wkRQUok1Gp1bsg6dOnCIpI4gqnXFowsV/e GQ2ka7Mlw1CUeIlP57T3ibvAQBvn5VMhubFFyh9Q/19zzq4k7j1AzerQi0bHkY4SKNDh fZDw== X-Gm-Message-State: AJcUukdf6Lb1SToTxMsdusPebdaTeZm0W0WiQB2eGrn3Pb2rVIMWj8Cg VSNReJfpR0QQ+jYBrcbsb0/3dA== X-Google-Smtp-Source: ALg8bN7A1Sc1cfxBCtiCvPa6pMMq1FAWwAEjKba+JVQvJtpGDEZsLLL1h7wiIbO1I0xjJ35JVp2tCw== X-Received: by 2002:a1c:b1d5:: with SMTP id a204mr21301315wmf.32.1548751465616; Tue, 29 Jan 2019 00:44:25 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id c1sm3979319wmb.14.2019.01.29.00.44.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 00:44:24 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 6/9] gpio: mockup: don't create the debugfs link named after the label Date: Tue, 29 Jan 2019 09:44:08 +0100 Message-Id: <20190129084411.30495-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190129084411.30495-1-brgl@bgdev.pl> References: <20190129084411.30495-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski User-space tests no longer use it and we're breaking the interface anyway. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 1c945c967f60..0317917a3678 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -234,7 +234,7 @@ static void gpio_mockup_debugfs_setup(struct device *dev, struct gpio_mockup_chip *chip) { struct gpio_mockup_dbgfs_private *priv; - struct dentry *evfile, *link; + struct dentry *evfile; struct gpio_chip *gc; const char *devname; char *name; @@ -247,10 +247,6 @@ static void gpio_mockup_debugfs_setup(struct device *dev, if (IS_ERR_OR_NULL(chip->dbg_dir)) goto err; - link = debugfs_create_symlink(gc->label, gpio_mockup_dbg_dir, devname); - if (IS_ERR_OR_NULL(link)) - goto err; - for (i = 0; i < gc->ngpio; i++) { name = devm_kasprintf(dev, GFP_KERNEL, "%d", i); if (!name) From patchwork Tue Jan 29 08:44:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1032593 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; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="bzvT4yHr"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43pg6b2x0Jz9sNG for ; Tue, 29 Jan 2019 19:44:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727997AbfA2Iot (ORCPT ); Tue, 29 Jan 2019 03:44:49 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38387 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727985AbfA2Io2 (ORCPT ); Tue, 29 Jan 2019 03:44:28 -0500 Received: by mail-wm1-f67.google.com with SMTP id m22so16833289wml.3 for ; Tue, 29 Jan 2019 00:44:27 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=Z770VfwimnPEUjTF5L5saIw2a2GAQPLZtqYgE1wTw+k=; b=bzvT4yHrth8hQqClKtQsifaxCoVXHOrRa/tm/EttPukcflaK6v6VJbAsiSewuJZRnE OjO4nJoSvgq8ARcsL6jICcHK2HOulaVYYHi4dasWveANeahgb5v/pw2+xKXUCDsjt2yc ZSQlgE72CSf0HvbtglIrNM+DsthNsg2hDFUFRf0wprj780mpvHeEdtJZNmQq0y9rI/uC EfAJfcXiFRzTh+LNEDxewsAi3CenCQgAigzGHcDdhLGqQo8vROCmmRj1V+hGXrUhGwwt 1zPC88HLpmBxVEOQmElvSf5psKrQz0y6iElTJdofVgXvbC5FIlx/oFTB3cYo1iBbc2w1 GIbw== 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:mime-version:content-transfer-encoding; bh=Z770VfwimnPEUjTF5L5saIw2a2GAQPLZtqYgE1wTw+k=; b=lYgpgdkLa6iKkRco6XsmpG7srUl2kaZym0Oor/8Kx6RziLJ5+muY2DNfJK0xAjGjcW IffBAuNXsxpvfs4bLiKfaWjGMlr1wQwI1xG64gg9/30dKAPVtSXDVCkwCpyK89E3DIpG BzFnyMhqtwZ/HTNh8HUN8HUT6r9Q93FcjjKEs3PWBO1fviL1hdPLCMRYBowm/Y5TjFy3 Rmf3aHqX0K2DCrYAOwhIrWUDLJnLiO8Jn198CSnlEdvAKsk3G2UGonJLvQuMcZF1oq29 Q1tKqtGz4yj8ID+jwYpC5WJ+GFdF8ppCYkVpb0+F5FkYmbB5cLGEsikBNOr1C91IkpoJ vb5Q== X-Gm-Message-State: AJcUukfLAHueNJn0L/GeAjCzKGCyN/n4giKJJnT7sKrQGzNZvaGTpMtc bB2Dd2HT+NXHn++s2lMMpi7qTm4LhgQ= X-Google-Smtp-Source: ALg8bN4mruzQd6zEc+el217ASavkSee1JAuNMSFZXAhxyd0xXW1X9glanCV3pnhFKMjG26Pg4U/edQ== X-Received: by 2002:a1c:dd04:: with SMTP id u4mr20207089wmg.84.1548751466628; Tue, 29 Jan 2019 00:44:26 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id c1sm3979319wmb.14.2019.01.29.00.44.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 00:44:26 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 7/9] gpio: mockup: change the type of 'offset' to unsigned int Date: Tue, 29 Jan 2019 09:44:09 +0100 Message-Id: <20190129084411.30495-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190129084411.30495-1-brgl@bgdev.pl> References: <20190129084411.30495-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski This field can never be negative. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 0317917a3678..433adb3b4617 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -60,7 +60,7 @@ struct gpio_mockup_chip { struct gpio_mockup_dbgfs_private { struct gpio_mockup_chip *chip; struct gpio_desc *desc; - int offset; + unsigned int offset; }; static int gpio_mockup_ranges[GPIO_MOCKUP_MAX_RANGES]; From patchwork Tue Jan 29 08:44:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1032594 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; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="lyKX9xki"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43pg6c21Cwz9sDr for ; Tue, 29 Jan 2019 19:44:56 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727588AbfA2Iot (ORCPT ); Tue, 29 Jan 2019 03:44:49 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:55710 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727997AbfA2Io3 (ORCPT ); Tue, 29 Jan 2019 03:44:29 -0500 Received: by mail-wm1-f66.google.com with SMTP id y139so16681418wmc.5 for ; Tue, 29 Jan 2019 00:44:28 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=758F2G6mHwZtHqDlM/wuN9QC0Q3bwGTIieLyA4J0jgo=; b=lyKX9xkiI/Bovn76zRMXJO30jERWYnJHRj1nbY9VwTRItB8f+F68u07LdTNwMtLeX2 X3ooOKBVT/qgY1uoEyFq9QuzXUbdTLSmGzTq9iuIAPpDm1gbtyeqEPmSPHXmsFnpIp1N xGNEM/DsWCvDe/IgcfNV1uMUFj3I4Hp1MGhuKpX3HXfDTAkNfTcdQqP9ncoy7lAJMIp9 2ceyhF7D40/4fyZ8dEB9cEVM1LLmLovFxhQdfOSUIZ1KRzsGxlfB8tWZpIQY9N/LgHY3 tXK23cl3PGGz2+nCGSxpPKr0TMmMj9+F972KnYQBivI4BTUeVVUSFuLkpTQcSwOgKIe4 PSUA== 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:mime-version:content-transfer-encoding; bh=758F2G6mHwZtHqDlM/wuN9QC0Q3bwGTIieLyA4J0jgo=; b=uBUVr782t6fgsZHG06i1YV1zEOIogdx4EbCzkzKNisDgL8lLOSFP4SpHy5d2joZHKm 2Q84afo+0XmI1cw6hAS2OIbq28s986d01REFqRoW4ljDoYRUZtxNWil5QDcp9dH59fzH QN3x0eqBfQilcRlmBTsXf/d2ZuEc8GcAZ6jYU1IW9gRGSYtOZdL3U2RKFSZOuN9VmBqi dm6UgbJgYeJWly+55lHb6wjSQ0MpJwVC5oR/zjpM/WBXZQhFUVdAFsjR1AT0hPk674/y u1SXr0hHdgVuQZxHXBKd9zJ46VQJkdeSb6VKKGMBhQjlsF+gZIX5OWcn/IE1GmG+Xg5F ikxw== X-Gm-Message-State: AJcUukcE1mJzLOIO1ZNRa7ERYVMfr3qcUWimvAnmiMLi2VMcO5cIHrgv GL66dXQEmHlouLlO0qpJvE8Dow== X-Google-Smtp-Source: ALg8bN4m1L7bgNHf5/WqP1XjiyFIzvV2wKp1npYAIqMfzD5zkyUybevb9PiM7ahJVcTc0l2Rt+6KsA== X-Received: by 2002:a1c:b70b:: with SMTP id h11mr21132414wmf.72.1548751467733; Tue, 29 Jan 2019 00:44:27 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id c1sm3979319wmb.14.2019.01.29.00.44.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 00:44:27 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 8/9] gpio: mockup: change the signature of unlocked get/set helpers Date: Tue, 29 Jan 2019 09:44:10 +0100 Message-Id: <20190129084411.30495-9-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190129084411.30495-1-brgl@bgdev.pl> References: <20190129084411.30495-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski The unlocked variants only get called from places where we already have the pointer to the underlying gpio_mockup_chip structure, so take it as parameter instead of struct gpio_chip. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 433adb3b4617..c498b0fbbec8 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -83,10 +83,9 @@ static int gpio_mockup_range_ngpio(unsigned int index) return gpio_mockup_ranges[index * 2 + 1]; } -static int __gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) +static int __gpio_mockup_get(struct gpio_mockup_chip *chip, + unsigned int offset) { - struct gpio_mockup_chip *chip = gpiochip_get_data(gc); - return chip->lines[offset].value; } @@ -96,7 +95,7 @@ static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) int val; mutex_lock(&chip->lock); - val = __gpio_mockup_get(gc, offset); + val = __gpio_mockup_get(chip, offset); mutex_unlock(&chip->lock); return val; @@ -110,7 +109,7 @@ static int gpio_mockup_get_multiple(struct gpio_chip *gc, mutex_lock(&chip->lock); for_each_set_bit(bit, mask, gc->ngpio) { - val = __gpio_mockup_get(gc, bit); + val = __gpio_mockup_get(chip, bit); __assign_bit(bit, bits, val); } mutex_unlock(&chip->lock); @@ -118,11 +117,9 @@ static int gpio_mockup_get_multiple(struct gpio_chip *gc, return 0; } -static void __gpio_mockup_set(struct gpio_chip *gc, +static void __gpio_mockup_set(struct gpio_mockup_chip *chip, unsigned int offset, int value) { - struct gpio_mockup_chip *chip = gpiochip_get_data(gc); - chip->lines[offset].value = !!value; } @@ -132,7 +129,7 @@ static void gpio_mockup_set(struct gpio_chip *gc, struct gpio_mockup_chip *chip = gpiochip_get_data(gc); mutex_lock(&chip->lock); - __gpio_mockup_set(gc, offset, value); + __gpio_mockup_set(chip, offset, value); mutex_unlock(&chip->lock); } @@ -144,7 +141,7 @@ static void gpio_mockup_set_multiple(struct gpio_chip *gc, mutex_lock(&chip->lock); for_each_set_bit(bit, mask, gc->ngpio) - __gpio_mockup_set(gc, bit, test_bit(bit, bits)); + __gpio_mockup_set(chip, bit, test_bit(bit, bits)); mutex_unlock(&chip->lock); } @@ -155,7 +152,7 @@ static int gpio_mockup_dirout(struct gpio_chip *gc, mutex_lock(&chip->lock); chip->lines[offset].dir = GPIO_MOCKUP_DIR_OUT; - __gpio_mockup_set(gc, offset, value); + __gpio_mockup_set(chip, offset, value); mutex_unlock(&chip->lock); return 0; From patchwork Tue Jan 29 08:44:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1032589 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; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="gUlsvIER"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43pg6S44rXz9sMM for ; Tue, 29 Jan 2019 19:44:48 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727941AbfA2Ioq (ORCPT ); Tue, 29 Jan 2019 03:44:46 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:53277 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728007AbfA2Ioa (ORCPT ); Tue, 29 Jan 2019 03:44:30 -0500 Received: by mail-wm1-f68.google.com with SMTP id d15so16829007wmb.3 for ; Tue, 29 Jan 2019 00:44:29 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=vHL+0UNr5kGvk4GaQolbiJExCUhkATZNz3ED6gc++tc=; b=gUlsvIERtEqpZBuGE4P4LLxHAjBiyPnHXdPNkJPj1AWHGntJldc5s4zryCYbVpGE5J +ZRykGd0M1asMw0Aq5Bzg+2IC4dUjoXJENa8GQGwdSoZSO/spj0RZsGr+ivEk6vdwWg/ aT3wMc3F0/Q7nLlQqfLejiNdk4L3zFtU53aZHQD+j2LJxywJO9Zu2ZO3oVquHTz4/FmY rTs6uo+RiNk+JfWi6J8OZRmVDFU8Bxo0AMsSJPlKdMevfN75VZvO1s3PGsYmON2sGBsV RC8/NGQJw05k7xpPFC9PHkZhMsrz3v9Fb+4Fmypb8fxz05mwH5H4yHvH2ONQb1ghxyTD msvw== 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:mime-version:content-transfer-encoding; bh=vHL+0UNr5kGvk4GaQolbiJExCUhkATZNz3ED6gc++tc=; b=odfgAx5LPfR7+65N5cWNZbEPGMraLYar7DFCo8/mEpnBO/MdZKjhAocqvw4kXSluOJ t0lw4/4I5GWO2grJsjcL20DUUmwfqDJUJPVF30z8/gZUgIpbeOh7OF8gfur4wgE0VUXC iJWtldY+et2i8vBYB8PgnNVkR19zLkfK41YFfR2cmxDtco0BcgmYRFvcTMtJKhTmU74Z N1v/y8HVW4EvhI6wy2TqsMJ2NzH3rlhBAkvVkvgZNgyoTX833kO1/YKeTDAccZX8naOD LhWMMcndzhn6t5tyWUoo0JaANDFJSpdgAlNSJ07yNUObbM2h73jT7U5CNNRzYPvxUBC5 kt4w== X-Gm-Message-State: AJcUukejJWnjz8ST9omX2tYEQTuum1o20yfVRLl9NpI0mpke55atgay4 sKNqTsmtqb9qwq4JIaowIieUF0UCX/Q= X-Google-Smtp-Source: ALg8bN6zHnlcq0NFmoWfWe5C5gjoqr2/cjzh0TDAJ5PDbL1dXKWPdynk26TIDP+a7aRNrZm2TB9S3Q== X-Received: by 2002:a1c:bbd6:: with SMTP id l205mr19060518wmf.97.1548751468765; Tue, 29 Jan 2019 00:44:28 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id c1sm3979319wmb.14.2019.01.29.00.44.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Jan 2019 00:44:28 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v2 9/9] gpio: mockup: rework debugfs interface Date: Tue, 29 Jan 2019 09:44:11 +0100 Message-Id: <20190129084411.30495-10-brgl@bgdev.pl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190129084411.30495-1-brgl@bgdev.pl> References: <20190129084411.30495-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Modify the way the debugfs interface works in gpio-mockup. Introduce the concept of dummy pull config which will keep the mockup lines in known state. The pull values can be modified by writing to the debugfs files corresponding to lines. Lines in input mode always report the current pull value, lines in output mode change the line value but it will revert back to the one specified by current pull when released. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 113 ++++++++++++++++++++++++++++++++----- 1 file changed, 99 insertions(+), 14 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index c498b0fbbec8..0b8de6e127eb 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -47,6 +47,7 @@ enum { struct gpio_mockup_line_status { int dir; int value; + int pull; }; struct gpio_mockup_chip { @@ -188,15 +189,56 @@ static int gpio_mockup_to_irq(struct gpio_chip *gc, unsigned int offset) return irq_sim_irqnum(&chip->irqsim, offset); } -static ssize_t gpio_mockup_event_write(struct file *file, - const char __user *usr_buf, - size_t size, loff_t *ppos) +static void gpio_mockup_free(struct gpio_chip *gc, unsigned int offset) +{ + struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + + __gpio_mockup_set(chip, offset, chip->lines[offset].pull); +} + +static ssize_t gpio_mockup_debugfs_read(struct file *file, + char __user *usr_buf, + size_t size, loff_t *ppos) +{ + struct gpio_mockup_dbgfs_private *priv; + struct gpio_mockup_chip *chip; + struct seq_file *sfile; + struct gpio_chip *gc; + char buf[3]; + int val, rv; + + if (*ppos != 0) + return 0; + + sfile = file->private_data; + priv = sfile->private; + chip = priv->chip; + gc = &chip->gc; + + val = gpio_mockup_get(gc, priv->offset); + snprintf(buf, sizeof(buf), "%d\n", val); + + rv = copy_to_user(usr_buf, buf, sizeof(buf)); + if (rv) + return rv; + + return sizeof(buf) - 1; +} + +static ssize_t gpio_mockup_debugfs_write(struct file *file, + const char __user *usr_buf, + size_t size, loff_t *ppos) { struct gpio_mockup_dbgfs_private *priv; struct gpio_mockup_chip *chip; struct seq_file *sfile; struct gpio_desc *desc; - int rv, val; + unsigned int irq_type; + struct gpio_chip *gc; + int rv, val, curr; + + if (*ppos != 0) + return -EINVAL; rv = kstrtoint_from_user(usr_buf, size, 0, &val); if (rv) @@ -206,24 +248,66 @@ static ssize_t gpio_mockup_event_write(struct file *file, sfile = file->private_data; priv = sfile->private; - desc = priv->desc; chip = priv->chip; + gc = &chip->gc; + desc = &gc->gpiodev->descs[priv->offset]; + + mutex_lock(&chip->lock); - gpiod_set_value_cansleep(desc, val); - irq_sim_fire(&chip->irqsim, priv->offset); + if (test_bit(FLAG_REQUESTED, &desc->flags) && + !test_bit(FLAG_IS_OUT, &desc->flags)) { + curr = __gpio_mockup_get(chip, priv->offset); + if (curr == val) + goto out; + + irq_type = val == 0 ? IRQ_TYPE_EDGE_FALLING + : IRQ_TYPE_EDGE_RISING; + irq_sim_fire_type(&chip->irqsim, priv->offset, irq_type); + } + + /* Change the value unless we're actively driving the line. */ + if (!test_bit(FLAG_REQUESTED, &desc->flags) || + !test_bit(FLAG_IS_OUT, &desc->flags)) + __gpio_mockup_set(chip, priv->offset, val); + +out: + chip->lines[priv->offset].pull = val; + mutex_unlock(&chip->lock); return size; } -static int gpio_mockup_event_open(struct inode *inode, struct file *file) +static int gpio_mockup_debugfs_open(struct inode *inode, struct file *file) { return single_open(file, NULL, inode->i_private); } -static const struct file_operations gpio_mockup_event_ops = { +/* + * Each mockup chip is represented by a directory named after the chip's device + * name under /sys/kernel/debug/gpio-mockup/. Each line is represented by + * a file using the line's offset as the name under the chip's directory. + * + * Reading from the line's file yields the current *value*, writing to the + * line's file changes the current *pull*. Default pull for mockup lines is + * down. + * + * Examples: + * - when a line pulled down is requested in output mode and driven high, its + * value will return to 0 once it's released + * - when the line is requested in output mode and driven high, writing 0 to + * the corresponding debugfs file will change the pull to down but the + * reported value will still be 1 until the line is released + * - line requested in input mode always reports the same value as its pull + * configuration + * - when the line is requested in input mode and monitored for events, writing + * the same value to the debugfs file will be a noop, while writing the + * opposite value will generate a dummy interrupt with an appropriate edge + */ +static const struct file_operations gpio_mockup_debugfs_ops = { .owner = THIS_MODULE, - .open = gpio_mockup_event_open, - .write = gpio_mockup_event_write, + .open = gpio_mockup_debugfs_open, + .read = gpio_mockup_debugfs_read, + .write = gpio_mockup_debugfs_write, .llseek = no_llseek, }; @@ -258,7 +342,7 @@ static void gpio_mockup_debugfs_setup(struct device *dev, priv->desc = &gc->gpiodev->descs[i]; evfile = debugfs_create_file(name, 0200, chip->dbg_dir, priv, - &gpio_mockup_event_ops); + &gpio_mockup_debugfs_ops); if (IS_ERR_OR_NULL(evfile)) goto err; } @@ -266,7 +350,7 @@ static void gpio_mockup_debugfs_setup(struct device *dev, return; err: - dev_err(dev, "error creating debugfs event files\n"); + dev_err(dev, "error creating debugfs files\n"); } static int gpio_mockup_name_lines(struct device *dev, @@ -342,6 +426,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) gc->direction_input = gpio_mockup_dirin; gc->get_direction = gpio_mockup_get_direction; gc->to_irq = gpio_mockup_to_irq; + gc->free = gpio_mockup_free; chip->lines = devm_kcalloc(dev, gc->ngpio, sizeof(*chip->lines), GFP_KERNEL); @@ -415,7 +500,7 @@ static int __init gpio_mockup_init(void) return -EINVAL; } - gpio_mockup_dbg_dir = debugfs_create_dir("gpio-mockup-event", NULL); + gpio_mockup_dbg_dir = debugfs_create_dir("gpio-mockup", NULL); if (IS_ERR_OR_NULL(gpio_mockup_dbg_dir)) gpio_mockup_err("error creating debugfs directory\n");