From patchwork Tue Mar 18 16:26:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Dubois-Briand X-Patchwork-Id: 14021304 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A1B1211711; Tue, 18 Mar 2025 16:26:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742315218; cv=none; b=i5jPEMY5EB5Wbs3396pkt7AcqngGTownZX4lpYZS9d2zpkM8ShaugZ/f9vef7SIKhijJ5AP0Rql5eLXq5UumleR+aPf0kg0L1XguQ7IWvokAbEOKn/8EvTwJjXRCON+qc6W7vON8UD7kq3DeLXH/aLGzKrFmzDVrVqbKBd9PCfU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742315218; c=relaxed/simple; bh=xrlUTdykextPYsV/1jnz6LtQfDYDcF4SkXD991bKiC0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nWlG+qmFeDz5pMO5j+/35W/7b1Pu32Mfw+fXvSRncAkYyOu7jK5QA+lEU9wMbhlUz3nMy4bKwsBgsQ/dpGgAh0pw783BVnuUVVjY0BFBN3YZM6IIk2GwS2THoZmdJ9lCG9yV/TsePiZxaa6KTF2S28dTOHezEd3B/8+Zrhydqf0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Xl7tT+vb; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Xl7tT+vb" Received: by mail.gandi.net (Postfix) with ESMTPSA id 8C11C442BB; Tue, 18 Mar 2025 16:26:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1742315212; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yiXZW34TaZ0JT2DFtzh3yS72N2utR/4WtVCzvFltlBM=; b=Xl7tT+vbmmVnWfPzl+kGizXVRhPJZuFretXMrimG+wYn+QStLdyUqlWsSsk7fei3H2eu90 oufQm1/STY0EkLvOYRpikUdSjoE5PxBrapYkJWcg8gAEKhN06a1renkoaLv160SnOgCQtS PGiKCbjNeS2SlAQYmZfaq5dzWmNWfvsI8zI8WcURMO5OD3dI95RxEn1dn9H2bn5A6cDunH g7yIqrFAITCLREHYulVsgm5t0dplZu3RCqKFljtOH8JwKWWhrscNm+N/Gm9HMOyN21HW5V hSOGdYPAoiD/8comqJEPRMu/ireHgPl5VDYUjkuO6ZvjY00UZe3w2WirY3EzLA== From: Mathieu Dubois-Briand Date: Tue, 18 Mar 2025 17:26:22 +0100 Subject: [PATCH v5 06/11] gpio: regmap: Allow to allocate regmap-irq device Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250318-mdb-max7360-support-v5-6-fb20baf97da0@bootlin.com> References: <20250318-mdb-max7360-support-v5-0-fb20baf97da0@bootlin.com> In-Reply-To: <20250318-mdb-max7360-support-v5-0-fb20baf97da0@bootlin.com> To: Lee Jones , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Kamel Bouhara , Linus Walleij , Bartosz Golaszewski , Dmitry Torokhov , =?utf-8?q?Uwe_Kleine-K=C3=B6n?= =?utf-8?q?ig?= , Michael Walle , Mark Brown , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-input@vger.kernel.org, linux-pwm@vger.kernel.org, andriy.shevchenko@intel.com, =?utf-8?q?Gr=C3=A9?= =?utf-8?q?gory_Clement?= , Thomas Petazzoni , Mathieu Dubois-Briand X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1742315204; l=3331; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=xrlUTdykextPYsV/1jnz6LtQfDYDcF4SkXD991bKiC0=; b=S7NHTGbqDE8ZfQ+qLiKvHA3vE7GiQHlSsi8aYCuA6QjnTYBmkNV/K8YRbqQRf7e2fF4Byp/qc TOcRrZwzchYCL7VS/0hhgwWBC6wFRS/naAoe/VQj/Z6zXCTelTpybgE X-Developer-Key: i=mathieu.dubois-briand@bootlin.com; a=ed25519; pk=1PVTmzPXfKvDwcPUzG0aqdGoKZJA3b9s+3DqRlm0Lww= X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddugedvledvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhfffugggtgffkfhgjvfevofesthejredtredtjeenucfhrhhomhepofgrthhhihgvuhcuffhusghoihhsqdeurhhirghnugcuoehmrghthhhivghurdguuhgsohhishdqsghrihgrnhgusegsohhothhlihhnrdgtohhmqeenucggtffrrghtthgvrhhnpedthfegtedvvdehjeeiheehheeuteejleektdefheehgfefgeelhfetgedttdfhteenucfkphepvdgrtddumegtsgdugeemheehieemjegrtddtmeeffhgtfhemfhgstdgumeduvdeivdemvdgvjeeinecuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehinhgvthepvdgrtddumegtsgdugeemheehieemjegrtddtmeeffhgtfhemfhgstdgumeduvdeivdemvdgvjeeipdhhvghloheplgduvdejrddtrddurddungdpmhgrihhlfhhrohhmpehmrghthhhivghurdguuhgsohhishdqsghrihgrnhgusegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvfedprhgtphhtthhopehlihhnuhigqdhinhhpuhhtsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrkhhrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehrrghfrggvlhesk hgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdprhgtphhtthhopehukhhlvghinhgvkheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhgrmhgvlhdrsghouhhhrghrrgessghoohhtlhhinhdrtghomhdprhgtphhtthhopehgrhgvghhkhheslhhinhhugihfohhunhgurghtihhonhdrohhrghdprhgtphhtthhopehmfigrlhhlvgeskhgvrhhnvghlrdhorhhg X-GND-Sasl: mathieu.dubois-briand@bootlin.com GPIO controller often have support for IRQ: allow to easily allocate both gpio-regmap and regmap-irq in one operation. Signed-off-by: Mathieu Dubois-Briand --- drivers/gpio/gpio-regmap.c | 23 +++++++++++++++++++++-- include/linux/gpio/regmap.h | 15 +++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 05f8781b5204..61d5f48b445d 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -203,6 +203,7 @@ EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata); */ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config) { + struct irq_domain *irq_domain; struct gpio_regmap *gpio; struct gpio_chip *chip; int ret; @@ -280,8 +281,26 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config if (ret < 0) goto err_free_gpio; - if (config->irq_domain) { - ret = gpiochip_irqchip_add_domain(chip, config->irq_domain); + irq_domain = config->irq_domain; +#ifdef CONFIG_GPIOLIB_IRQCHIP + if (config->regmap_irq_chip) { + struct regmap_irq_chip_data *irq_chip_data; + + ret = devm_regmap_add_irq_chip_fwnode(config->parent, dev_fwnode(config->parent), + config->regmap, config->regmap_irq_irqno, + config->regmap_irq_flags, 0, + config->regmap_irq_chip, &irq_chip_data); + if (ret) + goto err_free_gpio; + + irq_domain = regmap_irq_get_domain(irq_chip_data); + if (config->regmap_irq_chip_data) + *config->regmap_irq_chip_data = irq_chip_data; + } +#endif + + if (irq_domain) { + ret = gpiochip_irqchip_add_domain(chip, irq_domain); if (ret) goto err_remove_gpiochip; } diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h index a9f7b7faf57b..55df2527b982 100644 --- a/include/linux/gpio/regmap.h +++ b/include/linux/gpio/regmap.h @@ -40,6 +40,14 @@ struct regmap; * @drvdata: (Optional) Pointer to driver specific data which is * not used by gpio-remap but is provided "as is" to the * driver callback(s). + * @regmap_irq_chip: (Optional) Pointer on an regmap_irq_chip structure. If + * set, a regmap-irq device will be created and the IRQ + * domain will be set accordingly. + * @regmap_irq_chip_data: (Optional) Pointer on an regmap_irq_chip_data + * structure pointer. If set, it will be populated with a + * pointer on allocated regmap_irq data. + * @regmap_irq_irqno (Optional) The IRQ the device uses to signal interrupts. + * @regmap_irq_flags (Optional) The IRQF_ flags to use for the interrupt. * * The ->reg_mask_xlate translates a given base address and GPIO offset to * register and mask pair. The base address is one of the given register @@ -78,6 +86,13 @@ struct gpio_regmap_config { int ngpio_per_reg; struct irq_domain *irq_domain; +#ifdef CONFIG_GPIOLIB_IRQCHIP + struct regmap_irq_chip *regmap_irq_chip; + struct regmap_irq_chip_data **regmap_irq_chip_data; + int regmap_irq_irqno; + unsigned long regmap_irq_flags; +#endif + int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base, unsigned int offset, unsigned int *reg, unsigned int *mask);