Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp385476lqp; Wed, 12 Jun 2024 04:53:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWtPjMh9MH1g5lFC5kluAApgu3Y4KP44RaK8YKoSyvZXrkBG0djfR3vPDJ732boe1zmrqP6+6oeWpbz2xdv3myd7rIIk+cAz5oL3GS7cw== X-Google-Smtp-Source: AGHT+IEiyNdfJ/oczpVDcIwzjFidFpvLucYNRPZNIYWTPGTuTnaSaOfFmaIEmFCN6+j9j8xGmJsl X-Received: by 2002:a17:907:868d:b0:a58:e8c7:c0b8 with SMTP id a640c23a62f3a-a6f47d35904mr124581766b.7.1718193207352; Wed, 12 Jun 2024 04:53:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718193207; cv=pass; d=google.com; s=arc-20160816; b=i3D9UksZYbc74k3YSotF8hgIB9CKplY7cg00zf6imXA9X2th0FwXzwPJdFBr/o7jdY RWLmtjceiS35J9HJvnqfwZkQQwbdljFRA7OL7CTGCTaZFG7EnTYVPAaE/PMOoVjpQWV3 gKLPLRQLgO+3jT94NyEB3Q5Vek0AvmNknD3SOyYIjIDJtEQZfhIOUgve6BDioLDG0YM8 OfJOI2ES9TEryRS7DUwsR1Q0lKqI80h6bfYB4BzbeMq/n3iiU9IP9Ww4gLO06yANtrVz VWFeFO9Y3xH9l40phwmLZ7pJoAsC4LumbFsDZIx+eFUbm1lqC1E/h1Wyjq5m8PEwqsCx G8pg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ufjGpymO2l4pPxuTK47gK3FSS4v9zOl7SdWpW7/pLTw=; fh=pTxJBvEf1yBgejfuxDhEhymzx7UaQOo3fWfTle+A3q4=; b=mJAijK/ARMY9tvIt7nAQhl8xXg8egNTBW7/6a5B2ycb8Imv8V4o+vb8JTggU+R2ZbB RYQCenQSdigqZXYpkXuf0BXbsVve72UDP1EnxMc9Vrs1s2SOeNrX7KKVqFozyavgTZgo j9cB+E+aBU00FR5o4vgfTOHOnnYhp8EKgTNC2PhW+Wf86CzsZ0+HdqKMKSpTjQx+zij7 gY+05mc283FfungmnpLxpJkkgL8nXp+Yf/HdRICVQEWPOeg/BVw8Zljzv0NScazdMuww v3SoDXrFW8ClJ5UXFZqbVscNbp3hMiXIG2TfQ1L/AF1vym39YVUINcNKGms3ZkDGS1qy 0mrg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=o5ZwoQR0; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-211442-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211442-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57c962fc44asi1639430a12.107.2024.06.12.04.53.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 04:53:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-211442-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=o5ZwoQR0; arc=pass (i=1 dkim=pass dkdomain=bgdev-pl.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-211442-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-211442-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CB75B1F230E9 for ; Wed, 12 Jun 2024 11:53:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 15E5F16F821; Wed, 12 Jun 2024 11:53:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b="o5ZwoQR0" Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A874D16F0E9 for ; Wed, 12 Jun 2024 11:53:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718193186; cv=none; b=IDxRM6T48oPGw4wxntI+JuuL9BDNS/yPjNowyY5RPnhkqsNVhu3w52NmLRq1rTfmxzvq2uyT9AAb+yRPAKeLX1esV7KxxbBkQ1hbLdb8mO8mcsLKKJhs0cJPieKqXOL/kc34lr0MaTic7GCakcKBHtvQ79fJpGmkSq3/MAABUTY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718193186; c=relaxed/simple; bh=JDQkMWjIUvqE84ikntSBnxeL6cRw7OvNB40R51BdsFM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=irr3pNbdt9A5AfAfGZbv4pWy2R7QGFUbQ3w+JA3fowXIXcq06UZdVsShcBaP9lokIxD4EQ5CWii/v0FKnQBEjyNHRQFQsCqM1g0X6dJic9L9GoQSSTvJtscfp8byu7eeyOJsU1v/poTyjfGqil2vfWgg1PveCpvcjDLXWOx/BVs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl; spf=none smtp.mailfrom=bgdev.pl; dkim=pass (2048-bit key) header.d=bgdev-pl.20230601.gappssmtp.com header.i=@bgdev-pl.20230601.gappssmtp.com header.b=o5ZwoQR0; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bgdev.pl Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-35f1c567ae4so18890f8f.1 for ; Wed, 12 Jun 2024 04:53:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1718193183; x=1718797983; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ufjGpymO2l4pPxuTK47gK3FSS4v9zOl7SdWpW7/pLTw=; b=o5ZwoQR0rAO4TGVJnnplKBsHMPK351oUwBYkRYyvRftaiqSh3r6JtdKgZsjQf8/OZa aB/yAtFAM5KdBd6XONd605p7gUOTnLtXYtDNc/jYjJzOktoF3d5UWolndePo4Yckl/Xr pKsj3+8x7ZMhnkvBeMmAHS0uAfFZHVPoqTpIWj3+p/pIbU73PlJ3ezMRGeXPLfAxHX/H QLuAnggjYIzAPaEIgbxUwoQlMSB1g0ZhR3fyKuncsXSv565QSirkBKPvLndWJyBAo8b+ WeJIGMAk8Ys8JTDaaPeayEaOOitrkXaH017iKkWqT20kTBn1ZB2JDNT+CF7QrUFQFwfX skUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718193183; x=1718797983; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ufjGpymO2l4pPxuTK47gK3FSS4v9zOl7SdWpW7/pLTw=; b=XLAmJAok/ajuGBfafmuNbh4WQsM2LM32ycgK2FVlZncfB2j8YdDCakVOy6y9rrwZzQ IRaIddsY8InrgV5PzZHz6F8c1VlnoZ9L1M0hPYTd2xbEaoNDpjKKkF+rAMMCvIbwuSGL zuA99DapHwBy7V4dF6ihFiYP7PsSAPhOvzcrIbKL13eYsJMnzeCvi8oEPRmp8g/EH/0v LGt9PFTavUvEnHioI7jKDy4jSboACesSDfinZ8ic9v/ktkQTyhtfVdb1SLgdfTb2xOE8 GP61qJy/n80D1DsCg4Zy9QSciHOw7+EEP652FLC7BTvSN36Gdlqr5O3tCy0Egn6mXS7y RIjQ== X-Forwarded-Encrypted: i=1; AJvYcCUtSGn0u0v6RsdJ3FeWw/X9UBtgyUuRTkEtaWBGvZV3H09yyM/kcBWdfSs9Jbm5CY5S/FFzRqhySvmjNq13RzlSi8un5L5dfggomqCx X-Gm-Message-State: AOJu0YyGoki5n3fZrVdKUELvpcNG+sMhAlikXQcJQ5FN2G6GhQFaapsj XiuL3UVZizgPDNgGfbqYVXEEfZ/VDKUNFtHpibCF28JifED1UsqHuBRS360YFFk= X-Received: by 2002:a05:6000:bd0:b0:35f:1522:10b1 with SMTP id ffacd0b85a97d-35fe8910281mr1125602f8f.52.1718193183229; Wed, 12 Jun 2024 04:53:03 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:8d3:3800:a172:4e8b:453e:2f03]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35f1c958f9fsm10457352f8f.38.2024.06.12.04.53.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 04:53:02 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 2/2] gpio: sim: lock GPIOs as interrupts when they are requested Date: Wed, 12 Jun 2024 13:52:26 +0200 Message-ID: <20240612115231.26703-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240612115231.26703-1-brgl@bgdev.pl> References: <20240612115231.26703-1-brgl@bgdev.pl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Bartosz Golaszewski Use the notifier exposed by the interrupt simulator to be notified about interrupts associated with simulated GPIO pins being requested or released and lock/unlock them as interrupts accordingly. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-sim.c | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c index 2ed5cbe7c8a8..b5526f09b22b 100644 --- a/drivers/gpio/gpio-sim.c +++ b/drivers/gpio/gpio-sim.c @@ -53,6 +53,7 @@ struct gpio_sim_chip { struct irq_domain *irq_sim; struct mutex lock; const struct attribute_group **attr_groups; + struct notifier_block nb; }; struct gpio_sim_attribute { @@ -227,6 +228,24 @@ static void gpio_sim_free(struct gpio_chip *gc, unsigned int offset) } } +static int gpio_sim_irq_domain_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct gpio_sim_chip *chip = container_of(nb, struct gpio_sim_chip, nb); + irq_hw_number_t *offset = data; + + switch (action) { + case IRQ_SIM_DOMAIN_IRQ_REQUESTED: + gpiochip_lock_as_irq(&chip->gc, *offset); + return NOTIFY_OK; + case IRQ_SIM_DOMAIN_IRQ_RELEASED: + gpiochip_unlock_as_irq(&chip->gc, *offset); + return NOTIFY_OK; + } + + return NOTIFY_DONE; +} + static void gpio_sim_dbg_show(struct seq_file *seq, struct gpio_chip *gc) { struct gpio_sim_chip *chip = gpiochip_get_data(gc); @@ -322,13 +341,15 @@ static void gpio_sim_put_device(void *data) put_device(dev); } -static void gpio_sim_dispose_mappings(void *data) +static void gpio_sim_teardown_irq_sim(void *data) { struct gpio_sim_chip *chip = data; unsigned int i; for (i = 0; i < chip->gc.ngpio; i++) irq_dispose_mapping(irq_find_mapping(chip->irq_sim, i)); + + irq_sim_domain_unregister_notifier(chip->irq_sim, &chip->nb); } static void gpio_sim_sysfs_remove(void *data) @@ -454,7 +475,12 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev) if (IS_ERR(chip->irq_sim)) return PTR_ERR(chip->irq_sim); - ret = devm_add_action_or_reset(dev, gpio_sim_dispose_mappings, chip); + chip->nb.notifier_call = gpio_sim_irq_domain_notify; + ret = irq_sim_domain_register_notifier(chip->irq_sim, &chip->nb); + if (ret) + return ret; + + ret = devm_add_action_or_reset(dev, gpio_sim_teardown_irq_sim, chip); if (ret) return ret; -- 2.40.1