From patchwork Fri Feb 14 11:49:55 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: 865179 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 8BEC52641F7; Fri, 14 Feb 2025 11:50:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533825; cv=none; b=V0RJAo3h4O/wPHJ/ZnVtpKAUdc8FzSMPrKINJayHSyzXNTYq83LHeu3xvIRYk5CP3H2eXPXjpH5txIn7gb+kmZ6SXnHvpyyIROB+lQbM0Ulns2dBsbC/YwFJ40ml2A6fTBR1/osqeYM8/gIm4Rn7oXDOrb69VTGxZASGkVopaZI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533825; c=relaxed/simple; bh=HXxkaspPnOSHffFaaCFOnNwmjHEf0gB01arX3laHS+M=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mzIlZvWMyaL4LIapc736vcBJRCcCIhqfPbzVOz70gTZwa1DEElzOdFhIsNxuwf3m4qvdYm1bKgcA9Xq1wzQTcWEFzqlyTMd9qIm4Wi1CL+Pg9YAGyrUz1DPwLuwUvNT8XaOqGPyQB5EIZmbZa3ywACvE4/zwOVFDoDMtJsPAzXs= 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=hccMvHQC; arc=none smtp.client-ip=217.70.183.197 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="hccMvHQC" Received: by mail.gandi.net (Postfix) with ESMTPSA id 9A141442E2; Fri, 14 Feb 2025 11:50:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1739533815; 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=Lil4E8fY9Or1EESTp42XtfVLm65FbceH7FB2DR+3Qv0=; b=hccMvHQCYFO9XbOMNsSHLowwuqFjrRiSryNPN8T47AOIhbzN5o48SDZkGjXgcKQIhnwItX TAl7Lok3/MXd/zgyw0UetFo2mvufquj5lwb2u3t1yBmKym6Xghur0Kcpgqgl4PrszwgNmS ZU5pUj2J4QeZsyAA80bhyOAZD3FT1Ea4PEsL3ZbU8L+OV1Nz69NzGHFq6CFc1KC6lf5MzM oAT15JSz4BI+BYQdeJtjfkDslB6FwbYGc2bbRGhkRyotuX4V3qYkAtbaENlN4K/m7tDKta SVqdXPIVAErfegXZt1LI4Vdigh3QABOHO/PM2oHVSj+tWWbu863nnN+xsaiaaQ== From: Mathieu Dubois-Briand Date: Fri, 14 Feb 2025 12:49:55 +0100 Subject: [PATCH v4 05/10] gpio: regmap: Allow to retrieve ngpio Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250214-mdb-max7360-support-v4-5-8a35c6dbb966@bootlin.com> References: <20250214-mdb-max7360-support-v4-0-8a35c6dbb966@bootlin.com> In-Reply-To: <20250214-mdb-max7360-support-v4-0-8a35c6dbb966@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=1739533806; l=1793; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=HXxkaspPnOSHffFaaCFOnNwmjHEf0gB01arX3laHS+M=; b=482K44vzklse1KrUmJSFdjVsm8fhdYP1BMAYtekeCyMy4gdE8T6Hs6tMfARXLDuZI4DL2txEy igFIWVGviG8DEdA7DGngRWcEGynGOU4US/mwUsNUyWic7pjYChO3PwG 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: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegleehjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnheptdfhgeetvddvheejieehheehueetjeelkedtfeehhefgfeeglefhteegtddthfetnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdefpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrt ghomhdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhrvghgohhrhidrtghlvghmvghnthessghoohhtlhhinhdrtghomhdprhgtphhtthhopegurghkrheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepthhhohhmrghsrdhpvghtrgiiiihonhhisegsohhothhlihhnrdgtohhmpdhrtghpthhtohepsghrghhlsegsghguvghvrdhplhdprhgtphhtthhopehlihhnuhigqdhgphhiohesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-GND-Sasl: mathieu.dubois-briand@bootlin.com Drivers can leave the ngpio field of the gpio_regmap_config structure uninitialized, letting gpio_regmap_register() retrieve its value from the "ngpios" device property. Yet, the driver might still need to know the ngpio value later: allow to extract this value from the gpio_regmap structure. Signed-off-by: Mathieu Dubois-Briand --- drivers/gpio/gpio-regmap.c | 6 ++++++ include/linux/gpio/regmap.h | 3 +++ 2 files changed, 9 insertions(+) diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index ba72c23bcf97..7d8bfde386a4 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -195,6 +195,12 @@ void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio) } EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata); +u16 gpio_regmap_get_ngpio(struct gpio_regmap *gpio) +{ + return gpio->gpio_chip.ngpio; +} +EXPORT_SYMBOL_GPL(gpio_regmap_get_ngpio); + /** * gpio_regmap_register() - Register a generic regmap GPIO controller * @config: configuration for gpio_regmap diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h index 16f0c33df75d..0fdc213178d1 100644 --- a/include/linux/gpio/regmap.h +++ b/include/linux/gpio/regmap.h @@ -3,6 +3,8 @@ #ifndef _LINUX_GPIO_REGMAP_H #define _LINUX_GPIO_REGMAP_H +#include + struct device; struct fwnode_handle; struct gpio_regmap; @@ -97,5 +99,6 @@ void gpio_regmap_unregister(struct gpio_regmap *gpio); struct gpio_regmap *devm_gpio_regmap_register(struct device *dev, const struct gpio_regmap_config *config); void *gpio_regmap_get_drvdata(struct gpio_regmap *gpio); +u16 gpio_regmap_get_ngpio(struct gpio_regmap *gpio); #endif /* _LINUX_GPIO_REGMAP_H */ From patchwork Fri Feb 14 11:49:56 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: 865183 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 37C13275412; Fri, 14 Feb 2025 11:50:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533821; cv=none; b=Yo4UKaCtGilsa/UWgwYOCkGL6eOyBIem6SJDILH8RUxd7Ir1/7xOGbVFCRbAB5D8GpZphpeP6wMto6ky6px4K1+jgr8rNEuY0VYZOcIryjtuMoZaZk04bt0mgCdog/w5lQVq2sprzzKHnd/VcC7nzYOispYAmYM/Bnjch0OTXgs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533821; c=relaxed/simple; bh=ZnQLFD2EL5I4hMAOBZqIup0nFRbw4KAr5qzEHr5tnmI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ke2HYsRb/ZKmQKGTwioOa0Z37pX66I7lS10jzju7t4uNChj9PBNGybLJJC9u3GRG0f5XqvNb238cRrv63K45BokGFzi18ItnOHIOl2Su6ICbP3+IQn558+kq7xhDgAQDbAClmb/L9dTOCmeiYW64QhtUxkxK3PwsUGzkpD77CdY= 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=kGlgWfl5; arc=none smtp.client-ip=217.70.183.197 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="kGlgWfl5" Received: by mail.gandi.net (Postfix) with ESMTPSA id 9F908442E3; Fri, 14 Feb 2025 11:50:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1739533816; 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=eP+uWWSmBatI5PtAbRnJ86dfP7uUp+WPw6KeqKtV4Kk=; b=kGlgWfl5bbImlCXMAzxyJkAx1Hs4ZhS6sb335Ra4I/LSc2G420rT6DpXhvakCFoPl29Ifm q6l2a+I7M3klvq3tKdwq+/4wIIs/wXfvkiWWSqvWr7j/57knM3f/zYXIPoZVfmxeP9pqlZ e0d54pXaMPwThs8fRrsa8n1J8LeI/sczJPh0TlBEi0ZvY74S40FFf9ycWIH47bmkCqOERn D9a10cNSZXesV4HrtZd5St23FvDBQBTQpLUABBANijcTVVdMZPUuUc2Ga61My/GVwTNqs+ ZEbzvw2QE/Ch/fkCUd6h2RoMTMsKuUI9erWNeO5AoayOFBmOfOqNytiRU5rEoA== From: Mathieu Dubois-Briand Date: Fri, 14 Feb 2025 12:49:56 +0100 Subject: [PATCH v4 06/10] regmap: irq: Add support for chips without separate IRQ status Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250214-mdb-max7360-support-v4-6-8a35c6dbb966@bootlin.com> References: <20250214-mdb-max7360-support-v4-0-8a35c6dbb966@bootlin.com> In-Reply-To: <20250214-mdb-max7360-support-v4-0-8a35c6dbb966@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=1739533806; l=6569; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=ZnQLFD2EL5I4hMAOBZqIup0nFRbw4KAr5qzEHr5tnmI=; b=mTCtWXr3vYzOays92P3osmlH3QHOJUR0DDL/RRCNh7PM0ULiKn2ji11HWG/PcXhqVW1VneR3Q wm4JOSejM3ZBJMui4Ds5Q4diQezfhU/eVP9VX9vT086WamAEUV8PcxB 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: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegleehjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnheptdfhgeetvddvheejieehheehueetjeelkedtfeehhefgfeeglefhteegtddthfetnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdefpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrt ghomhdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhrvghgohhrhidrtghlvghmvghnthessghoohhtlhhinhdrtghomhdprhgtphhtthhopegurghkrheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepthhhohhmrghsrdhpvghtrgiiiihonhhisegsohhothhlihhnrdgtohhmpdhrtghpthhtohepsghrghhlsegsghguvghvrdhplhdprhgtphhtthhopehlihhnuhigqdhgphhiohesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-GND-Sasl: mathieu.dubois-briand@bootlin.com Some GPIO chips allow to rise an IRQ on GPIO level changes but do not provide an IRQ status for each separate line: only the current gpio level can be retrieved. Add support for these chips, emulating IRQ status by comparing GPIO levels with the levels during the previous interrupt. Signed-off-by: Mathieu Dubois-Briand --- drivers/base/regmap/regmap-irq.c | 83 ++++++++++++++++++++++++++++++---------- include/linux/regmap.h | 3 ++ 2 files changed, 66 insertions(+), 20 deletions(-) diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c index 0bcd81389a29..531ea799383b 100644 --- a/drivers/base/regmap/regmap-irq.c +++ b/drivers/base/regmap/regmap-irq.c @@ -33,6 +33,7 @@ struct regmap_irq_chip_data { void *status_reg_buf; unsigned int *main_status_buf; unsigned int *status_buf; + unsigned int *prev_status_buf; unsigned int *mask_buf; unsigned int *mask_buf_def; unsigned int *wake_buf; @@ -332,27 +333,13 @@ static inline int read_sub_irq_data(struct regmap_irq_chip_data *data, return ret; } -static irqreturn_t regmap_irq_thread(int irq, void *d) +static int read_irq_data(struct regmap_irq_chip_data *data) { - struct regmap_irq_chip_data *data = d; const struct regmap_irq_chip *chip = data->chip; struct regmap *map = data->map; int ret, i; - bool handled = false; u32 reg; - if (chip->handle_pre_irq) - chip->handle_pre_irq(chip->irq_drv_data); - - if (chip->runtime_pm) { - ret = pm_runtime_get_sync(map->dev); - if (ret < 0) { - dev_err(map->dev, "IRQ thread failed to resume: %d\n", - ret); - goto exit; - } - } - /* * Read only registers with active IRQs if the chip has 'main status * register'. Else read in the statuses, using a single bulk read if @@ -382,7 +369,7 @@ static irqreturn_t regmap_irq_thread(int irq, void *d) dev_err(map->dev, "Failed to read IRQ status %d\n", ret); - goto exit; + return ret; } } @@ -401,7 +388,7 @@ static irqreturn_t regmap_irq_thread(int irq, void *d) dev_err(map->dev, "Failed to read IRQ status %d\n", ret); - goto exit; + return ret; } } @@ -420,7 +407,7 @@ static irqreturn_t regmap_irq_thread(int irq, void *d) if (ret != 0) { dev_err(map->dev, "Failed to read IRQ status: %d\n", ret); - goto exit; + return ret; } for (i = 0; i < data->chip->num_regs; i++) { @@ -436,7 +423,7 @@ static irqreturn_t regmap_irq_thread(int irq, void *d) break; default: BUG(); - goto exit; + return ret; } } @@ -450,7 +437,7 @@ static irqreturn_t regmap_irq_thread(int irq, void *d) dev_err(map->dev, "Failed to read IRQ status: %d\n", ret); - goto exit; + return ret; } } } @@ -459,6 +446,43 @@ static irqreturn_t regmap_irq_thread(int irq, void *d) for (i = 0; i < data->chip->num_regs; i++) data->status_buf[i] = ~data->status_buf[i]; + return 0; +} + +static irqreturn_t regmap_irq_thread(int irq, void *d) +{ + struct regmap_irq_chip_data *data = d; + const struct regmap_irq_chip *chip = data->chip; + struct regmap *map = data->map; + int ret, i; + bool handled = false; + u32 reg; + + if (chip->handle_pre_irq) + chip->handle_pre_irq(chip->irq_drv_data); + + if (chip->runtime_pm) { + ret = pm_runtime_get_sync(map->dev); + if (ret < 0) { + dev_err(map->dev, "IRQ thread failed to resume: %d\n", + ret); + goto exit; + } + } + + ret = read_irq_data(data); + if (ret < 0) + goto exit; + + if (chip->status_is_level) { + for (i = 0; i < data->chip->num_regs; i++) { + unsigned int val = data->status_buf[i]; + + data->status_buf[i] ^= data->prev_status_buf[i]; + data->prev_status_buf[i] = val; + } + } + /* * Ignore masked IRQs and ack if we need to; we ack early so * there is no race between handling and acknowledging the @@ -705,6 +729,13 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode, if (!d->status_buf) goto err_alloc; + if (chip->status_is_level) { + d->prev_status_buf = kcalloc(chip->num_regs, sizeof(*d->prev_status_buf), + GFP_KERNEL); + if (!d->prev_status_buf) + goto err_alloc; + } + d->mask_buf = kcalloc(chip->num_regs, sizeof(*d->mask_buf), GFP_KERNEL); if (!d->mask_buf) @@ -881,6 +912,16 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode, } } + /* Store current levels */ + if (chip->status_is_level) { + ret = read_irq_data(d); + if (ret < 0) + goto err_alloc; + + for (i = 0; i < d->chip->num_regs; i++) + d->prev_status_buf[i] = d->status_buf[i]; + } + ret = regmap_irq_create_domain(fwnode, irq_base, chip, d); if (ret) goto err_alloc; @@ -907,6 +948,7 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode, kfree(d->mask_buf_def); kfree(d->mask_buf); kfree(d->status_buf); + kfree(d->prev_status_buf); kfree(d->status_reg_buf); if (d->config_buf) { for (i = 0; i < chip->num_config_bases; i++) @@ -983,6 +1025,7 @@ void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *d) kfree(d->mask_buf); kfree(d->status_reg_buf); kfree(d->status_buf); + kfree(d->prev_status_buf); if (d->config_buf) { for (i = 0; i < d->chip->num_config_bases; i++) kfree(d->config_buf[i]); diff --git a/include/linux/regmap.h b/include/linux/regmap.h index 3a96d068915f..159527e97f00 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -1640,6 +1640,8 @@ struct regmap_irq_chip_data; * @ack_invert: Inverted ack register: cleared bits for ack. * @clear_ack: Use this to set 1 and 0 or vice-versa to clear interrupts. * @status_invert: Inverted status register: cleared bits are active interrupts. + * @status_is_level: Status register is actuall signal level: Xor status + * register with previous value to get active interrupts. * @wake_invert: Inverted wake register: cleared bits are wake enabled. * @type_in_mask: Use the mask registers for controlling irq type. Use this if * the hardware provides separate bits for rising/falling edge @@ -1703,6 +1705,7 @@ struct regmap_irq_chip { unsigned int ack_invert:1; unsigned int clear_ack:1; unsigned int status_invert:1; + unsigned int status_is_level:1; unsigned int wake_invert:1; unsigned int type_in_mask:1; unsigned int clear_on_unmask:1; From patchwork Fri Feb 14 11:49:57 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: 865182 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 4A497263C70; Fri, 14 Feb 2025 11:50:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533822; cv=none; b=iDPeYD90f4UbVYAHFXka4UbJQY6agvs9pCDkiohZ4pMsmixVLDakuotrJUJY+FZn3ynQ0jaAR9K2Lk1n+ZAU2V1Qag+m/fZSSUAUoVj0rJWTv2/hlFUEvLIUtimUTv2IeTGwmyXFlUU5ez77bkcn8/VTa/PLVhGDAqmz3f9a0MA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533822; c=relaxed/simple; bh=+/brog6yOneIHTXSivDBSeKcb0NPvBa2cb8E0wfddBA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=a0G99XFV9CATV8tM6VdCjuVCKs+pL9bQGR7hu45U0pnfEXIldQg1CjADhyDhGHYy+azmGdjJC6VQ2ea6RyE2El7aXv5hsnFMe7LiFBWS08GMd5tRUd076GriCCybYQMtXmV2iam2pipzJwYB4CTcOKJ5uFNz7a2wYRjsOMDi5YE= 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=XDSMCzMp; arc=none smtp.client-ip=217.70.183.197 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="XDSMCzMp" Received: by mail.gandi.net (Postfix) with ESMTPSA id A81B5442A5; Fri, 14 Feb 2025 11:50:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1739533817; 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=dLXKpMthXdWQSi9HXQKyQXRueDKRFXkR7s6n7DDIuo0=; b=XDSMCzMpBSGxa1eV6C71D/C+ObxWT/wy32StPjqjvXn6bj/rYU2pC65rIS+nCQmwVFIlx/ hvvF7tFiFGXDvQ3ZdlM/L5cm/2KHICwNTSIqr+R6LoT0jTDYDjLMXDMtOSHWs2lLnYcvII J2n6XWiQYZ6qPXDIZztLsjdb87nT15qLzbPiWY+ZtJIWlS5bYq4Q8izLOuC3/s0yyA2raG 7DmxyuukNzJ7saHXmZIoX/9C81CPDtoJfoj1aT+mLbRAU4ehbpxSiSABqjg9dzovfQYHTi EbjyrNen7hLhSBmTr6qUjMouU3phRtkrSYpGaBeav+kuV1rg/CROoGUPP3wMNQ== From: Mathieu Dubois-Briand Date: Fri, 14 Feb 2025 12:49:57 +0100 Subject: [PATCH v4 07/10] gpio: max7360: Add MAX7360 gpio support Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250214-mdb-max7360-support-v4-7-8a35c6dbb966@bootlin.com> References: <20250214-mdb-max7360-support-v4-0-8a35c6dbb966@bootlin.com> In-Reply-To: <20250214-mdb-max7360-support-v4-0-8a35c6dbb966@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=1739533806; l=9950; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=+/brog6yOneIHTXSivDBSeKcb0NPvBa2cb8E0wfddBA=; b=zKH/h447CwCnmBp79KfhXvgX1gsrWsIlf7wB18ZbgkqHm0gkGcJ43G7j3Vaho3UpfCHvUPcc5 AxPrMqyrYA1D4bICFIy/2UUZwCsKYKmnJZkhzOdyNal0o8P7r569/Mg 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: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegleehjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnheptdfhgeetvddvheejieehheehueetjeelkedtfeehhefgfeeglefhteegtddthfetnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdefpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrt ghomhdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhrvghgohhrhidrtghlvghmvghnthessghoohhtlhhinhdrtghomhdprhgtphhtthhopegurghkrheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepthhhohhmrghsrdhpvghtrgiiiihonhhisegsohhothhlihhnrdgtohhmpdhrtghpthhtohepsghrghhlsegsghguvghvrdhplhdprhgtphhtthhopehlihhnuhigqdhgphhiohesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-GND-Sasl: mathieu.dubois-briand@bootlin.com Add driver for Maxim Integrated MAX7360 GPIO/GPO controller. Two sets of GPIOs are provided by the device: - Up to 8 GPIOs, shared with the PWM and rotary encoder functionalities. These GPIOs also provide interrupts on input changes. - Up to 6 GPOs, on unused keypad columns pins. Co-developed-by: Kamel Bouhara Signed-off-by: Kamel Bouhara Signed-off-by: Mathieu Dubois-Briand --- drivers/gpio/Kconfig | 11 ++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-max7360.c | 253 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 265 insertions(+) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 98b4d1633b25..3b3babc1c029 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1445,6 +1445,17 @@ config GPIO_MADERA help Support for GPIOs on Cirrus Logic Madera class codecs. +config GPIO_MAX7360 + tristate "MAX7360 GPIO support" + depends on MFD_MAX7360 + select GPIO_REGMAP + help + Allows to use MAX7360 I/O Expander PWM lines as GPIO and keypad COL + lines as GPO. + + This driver can also be built as a module. If so, the module will be + called gpio-max7360. + config GPIO_MAX77620 tristate "GPIO support for PMIC MAX77620 and MAX20024" depends on MFD_MAX77620 diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index af3ba4d81b58..581341b3e3e4 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -100,6 +100,7 @@ obj-$(CONFIG_GPIO_MAX7300) += gpio-max7300.o obj-$(CONFIG_GPIO_MAX7301) += gpio-max7301.o obj-$(CONFIG_GPIO_MAX730X) += gpio-max730x.o obj-$(CONFIG_GPIO_MAX732X) += gpio-max732x.o +obj-$(CONFIG_GPIO_MAX7360) += gpio-max7360.o obj-$(CONFIG_GPIO_MAX77620) += gpio-max77620.o obj-$(CONFIG_GPIO_MAX77650) += gpio-max77650.o obj-$(CONFIG_GPIO_MB86S7X) += gpio-mb86s7x.o diff --git a/drivers/gpio/gpio-max7360.c b/drivers/gpio/gpio-max7360.c new file mode 100644 index 000000000000..99ccda687b88 --- /dev/null +++ b/drivers/gpio/gpio-max7360.c @@ -0,0 +1,253 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2024 Bootlin + * + * Author: Kamel BOUHARA + * Author: Mathieu Dubois-Briand + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX7360_GPIO_PORT 1 +#define MAX7360_GPIO_COL 2 + +static int max7360_gpo_reg_mask_xlate(struct gpio_regmap *gpio, + unsigned int base, unsigned int offset, + unsigned int *reg, unsigned int *mask) +{ + u16 ngpios = gpio_regmap_get_ngpio(gpio); + + *reg = base; + *mask = BIT(MAX7360_MAX_KEY_COLS - (ngpios - offset)); + + return 0; +} + +static int max7360_gpio_request(struct gpio_chip *gc, unsigned int pin) +{ + /* + * GPIOs on PORT pins are shared with the PWM and rotary encoder + * drivers: they have to be requested from the MFD driver. + */ + return max7360_port_pin_request(gc->parent->parent, pin, true); +} + +static void max7360_gpio_free(struct gpio_chip *gc, unsigned int pin) +{ + max7360_port_pin_request(gc->parent->parent, pin, false); +} + +static int max7360_set_gpos_count(struct device *dev, struct regmap *regmap) +{ + /* + * MAX7360 COL0 to COL7 pins can be used either as keypad columns, + * general purpose output or a mix of both. + */ + unsigned int val; + u32 columns; + u32 ngpios; + int ret; + + ret = device_property_read_u32(dev, "ngpios", &ngpios); + if (ret < 0) { + dev_err(dev, "Missing ngpios OF property\n"); + return ret; + } + + /* + * Get the number of pins requested by the keypad and ensure our own pin + * count is compatible with it. + */ + ret = device_property_read_u32(dev->parent, "keypad,num-columns", &columns); + if (ret < 0) { + dev_err(dev, "Failed to read columns count\n"); + return ret; + } + + if (ngpios > MAX7360_MAX_GPO || + (ngpios + columns > MAX7360_MAX_KEY_COLS)) { + dev_err(dev, "Incompatible gpos and columns count (%u, %u)\n", + ngpios, columns); + return -EINVAL; + } + + /* + * MAX7360_REG_DEBOUNCE contains configuration both for keypad debounce + * timings and gpos/keypad columns repartition. Only the later is + * modified here. + */ + val = FIELD_PREP(MAX7360_PORTS, ngpios); + ret = regmap_write_bits(regmap, MAX7360_REG_DEBOUNCE, MAX7360_PORTS, val); + if (ret) { + dev_err(dev, "Failed to write max7360 columns/gpos configuration"); + return ret; + } + + return 0; +} + +static const struct regmap_irq max7360_regmap_irqs[MAX7360_MAX_GPIO] = { + REGMAP_IRQ_REG(0, 0, BIT(0)), + REGMAP_IRQ_REG(1, 0, BIT(1)), + REGMAP_IRQ_REG(2, 0, BIT(2)), + REGMAP_IRQ_REG(3, 0, BIT(3)), + REGMAP_IRQ_REG(4, 0, BIT(4)), + REGMAP_IRQ_REG(5, 0, BIT(5)), + REGMAP_IRQ_REG(6, 0, BIT(6)), + REGMAP_IRQ_REG(7, 0, BIT(7)), +}; + +static int max7360_handle_mask_sync(const int index, + const unsigned int mask_buf_def, + const unsigned int mask_buf, + void *const irq_drv_data) +{ + struct regmap *regmap = irq_drv_data; + unsigned int val; + + for (unsigned int i = 0; i < MAX7360_MAX_GPIO; ++i) { + val = (mask_buf & 1 << i) ? MAX7360_PORT_CFG_INTERRUPT_MASK : 0; + regmap_write_bits(regmap, MAX7360_REG_PWMCFG(i), + MAX7360_PORT_CFG_INTERRUPT_MASK, val); + } + + return 0; +} + +static int max7360_gpio_probe(struct platform_device *pdev) +{ + struct regmap_irq_chip *irq_chip; + struct regmap_irq_chip_data *irq_chip_data; + struct gpio_regmap_config gpio_config = { }; + struct device *dev = &pdev->dev; + unsigned long gpio_function; + struct regmap *regmap; + unsigned int outconf; + unsigned long flags; + int irq; + int ret; + + regmap = dev_get_regmap(dev->parent, NULL); + if (!regmap) + return dev_err_probe(dev, -ENODEV, "could not get parent regmap\n"); + + gpio_function = (uintptr_t)device_get_match_data(dev); + + if (gpio_function == MAX7360_GPIO_PORT && + (device_property_read_bool(dev, "interrupt-controller"))) { + /* + * Port GPIOs with interrupt-controller property: add IRQ + * controller. + */ + irq = fwnode_irq_get_byname(dev->parent->fwnode, "inti"); + if (irq < 0) + return dev_err_probe(dev, irq, "Failed to get IRQ\n"); + + irq_chip = devm_kzalloc(dev, sizeof(*irq_chip), GFP_KERNEL); + if (!irq_chip) + return -ENOMEM; + + irq_chip->name = dev_name(dev); + irq_chip->status_base = MAX7360_REG_GPIOIN; + irq_chip->num_regs = 1; + irq_chip->num_irqs = MAX7360_MAX_GPIO; + irq_chip->irqs = max7360_regmap_irqs; + irq_chip->handle_mask_sync = max7360_handle_mask_sync; + irq_chip->status_is_level = true; + irq_chip->irq_drv_data = regmap; + + for (unsigned int i = 0; i < MAX7360_MAX_GPIO; i++) { + regmap_write_bits(regmap, MAX7360_REG_PWMCFG(i), + MAX7360_PORT_CFG_INTERRUPT_EDGES, + MAX7360_PORT_CFG_INTERRUPT_EDGES); + } + + flags = IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED; + ret = devm_regmap_add_irq_chip_fwnode(dev, dev_fwnode(dev), regmap, irq, flags, 0, + irq_chip, &irq_chip_data); + if (ret) + return dev_err_probe(dev, ret, "IRQ registration failed\n"); + + gpio_config.irq_domain = regmap_irq_get_domain(irq_chip_data); + } + + if (gpio_function == MAX7360_GPIO_PORT) { + /* + * Port GPIOs: set output mode configuration (constant-current or not). + * This property is optional. + */ + outconf = 0; + ret = device_property_read_u32(dev, "maxim,constant-current-disable", &outconf); + if (ret && (ret != -EINVAL)) + return dev_err_probe(dev, -ENODEV, + "Failed to read maxim,constant-current-disable OF property\n"); + + regmap_write(regmap, MAX7360_REG_GPIOOUTM, outconf); + } + + /* Add gpio device. */ + gpio_config.parent = dev; + gpio_config.regmap = regmap; + if (gpio_function == MAX7360_GPIO_PORT) { + gpio_config.ngpio = MAX7360_MAX_GPIO; + gpio_config.reg_dat_base = GPIO_REGMAP_ADDR(MAX7360_REG_GPIOIN); + gpio_config.reg_set_base = GPIO_REGMAP_ADDR(MAX7360_REG_PWMBASE); + gpio_config.reg_dir_out_base = GPIO_REGMAP_ADDR(MAX7360_REG_GPIOCTRL); + gpio_config.ngpio_per_reg = MAX7360_MAX_GPIO; + gpio_config.request = max7360_gpio_request; + gpio_config.free = max7360_gpio_free; + } else { + u32 ngpios; + + ret = device_property_read_u32(dev, "ngpios", &ngpios); + if (ret < 0) { + dev_err(dev, "Missing ngpios OF property\n"); + return ret; + } + + gpio_config.reg_set_base = GPIO_REGMAP_ADDR(MAX7360_REG_PORTS); + gpio_config.reg_mask_xlate = max7360_gpo_reg_mask_xlate; + gpio_config.ngpio = ngpios; + + ret = max7360_set_gpos_count(dev, regmap); + if (ret) + return dev_err_probe(dev, ret, "Failed to set GPOS pin count\n"); + } + + return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(dev, &gpio_config)); +} + +static const struct of_device_id max7360_gpio_of_match[] = { + { + .compatible = "maxim,max7360-gpo", + .data = (void *)MAX7360_GPIO_COL + }, { + .compatible = "maxim,max7360-gpio", + .data = (void *)MAX7360_GPIO_PORT + }, { + } +}; +MODULE_DEVICE_TABLE(of, max7360_gpio_of_match); + +static struct platform_driver max7360_gpio_driver = { + .driver = { + .name = "max7360-gpio", + .of_match_table = max7360_gpio_of_match, + }, + .probe = max7360_gpio_probe, +}; +module_platform_driver(max7360_gpio_driver); + +MODULE_DESCRIPTION("MAX7360 GPIO driver"); +MODULE_AUTHOR("Kamel BOUHARA "); +MODULE_AUTHOR("Mathieu Dubois-Briand "); +MODULE_LICENSE("GPL"); From patchwork Fri Feb 14 11:49:58 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: 865181 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 68E77275408; Fri, 14 Feb 2025 11:50:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533823; cv=none; b=seTJFDa+Pk68Ib+HiO+x8tdmnFLDaBgSJnj9hwr/kXE0oiJyeamxNsf/zfTKywE5NA7xIbKeVbHR9UMlqQU3d5heEHhseZb76BBsud12EG1KiDQtLlNbcQBLxwsBWX8UVxjLMvNUey+1iwg7kaVjWsheRhLzW1Msv7HClBeBB24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533823; c=relaxed/simple; bh=nZQEprp8+oiNn9RsvNWJu1IbaydTP5rxdB/SFV8Wajg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=R18Kgib1fPqBPbCrFi857Rd15A052YXknyUM65cLS3YimMw12yXrVDRRLqtd6vM8g8gmFygOU4XINUnJvWouO0Mf4vKlcaApu7DBmw0iiOe1Qx7XNl+vrrgEHHBpJ4HwOHBj8RGWIBXOk+REl5QRKJ5qmLuRTKcYnuR4VD/cj8w= 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=cG5ExuKq; arc=none smtp.client-ip=217.70.183.197 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="cG5ExuKq" Received: by mail.gandi.net (Postfix) with ESMTPSA id C3DDD442E5; Fri, 14 Feb 2025 11:50:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1739533818; 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=BTvbQ2Bfe6aSvsw8ko87YVo83vtCIokrGKqSKaxryrc=; b=cG5ExuKq2t7ATlzPlSgFUhpmY+irep+91gm98poqO5KqGU9+NiAIbvSgsROCRDV3L66kN3 fbSbWWW47Y3I+wRen6COSU1Os95zT8dLuSQCQrpvffUe9NDLeqDelIucO09EkP83uoGk5x xhbFmwMfQW5gKucnnZydsxEaFdNe2s955zDBkYygcfYyUd/TAq3Ho3gV3aGPEU2Va7gTh9 MITw8K01u6R5sy+pW/OMXHxJq3e47pV2yjgUzQbcYeBFwryjC9GClM53fmoxwVsc4gK+cB a5q3KfGMXXHiM3wnTRxnFhMejPCNs+H53HBCLSIbrqhwQzaVUiQuRw6X35EYxw== From: Mathieu Dubois-Briand Date: Fri, 14 Feb 2025 12:49:58 +0100 Subject: [PATCH v4 08/10] input: keyboard: Add support for MAX7360 keypad Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250214-mdb-max7360-support-v4-8-8a35c6dbb966@bootlin.com> References: <20250214-mdb-max7360-support-v4-0-8a35c6dbb966@bootlin.com> In-Reply-To: <20250214-mdb-max7360-support-v4-0-8a35c6dbb966@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=1739533806; l=10353; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=nZQEprp8+oiNn9RsvNWJu1IbaydTP5rxdB/SFV8Wajg=; b=L9aDrAQqRtdKyWr0uX8McBVa2CZAP7cosiwIQTSVIF6JkAq5iOWYszZjdIV8bV5MWMi16X3dS BzNNsBzPuT/C1JBWUSbUabmQqHdlkBFNxcRvhH6pUTQFXvP7oV6SvbA 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: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegleehjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnheptdfhgeetvddvheejieehheehueetjeelkedtfeehhefgfeeglefhteegtddthfetnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpeegnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdefpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrt ghomhdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhrvghgohhrhidrtghlvghmvghnthessghoohhtlhhinhdrtghomhdprhgtphhtthhopegurghkrheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepthhhohhmrghsrdhpvghtrgiiiihonhhisegsohhothhlihhnrdgtohhmpdhrtghpthhtohepsghrghhlsegsghguvghvrdhplhdprhgtphhtthhopehlihhnuhigqdhgphhiohesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-GND-Sasl: mathieu.dubois-briand@bootlin.com Add driver for Maxim Integrated MAX7360 keypad controller, providing support for up to 64 keys, with a matrix of 8 columns and 8 rows. Signed-off-by: Mathieu Dubois-Briand --- drivers/input/keyboard/Kconfig | 12 ++ drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/max7360-keypad.c | 282 ++++++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+) diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 721ab69e84ac..bba029f65cfa 100644 --- a/drivers/input/keyboard/Kconfig +++ b/drivers/input/keyboard/Kconfig @@ -421,6 +421,18 @@ config KEYBOARD_MAX7359 To compile this driver as a module, choose M here: the module will be called max7359_keypad. +config KEYBOARD_MAX7360 + tristate "Maxim MAX7360 Key Switch Controller" + select INPUT_MATRIXKMAP + depends on I2C + depends on MFD_MAX7360 + help + If you say yes here you get support for the keypad controller on the + Maxim MAX7360 I/O Expander. + + To compile this driver as a module, choose M here: the + module will be called max7360_keypad. + config KEYBOARD_MPR121 tristate "Freescale MPR121 Touchkey" depends on I2C diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile index 1e0721c30709..b49d32d4003d 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile @@ -42,6 +42,7 @@ obj-$(CONFIG_KEYBOARD_LPC32XX) += lpc32xx-keys.o obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o +obj-$(CONFIG_KEYBOARD_MAX7360) += max7360-keypad.o obj-$(CONFIG_KEYBOARD_MPR121) += mpr121_touchkey.o obj-$(CONFIG_KEYBOARD_MT6779) += mt6779-keypad.o obj-$(CONFIG_KEYBOARD_MTK_PMIC) += mtk-pmic-keys.o diff --git a/drivers/input/keyboard/max7360-keypad.c b/drivers/input/keyboard/max7360-keypad.c new file mode 100644 index 000000000000..da7a0faea873 --- /dev/null +++ b/drivers/input/keyboard/max7360-keypad.c @@ -0,0 +1,282 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2024 Bootlin + * + * Author: Mathieu Dubois-Briand + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct max7360_keypad { + struct input_dev *input; + unsigned int rows; + unsigned int cols; + unsigned int debounce_ms; + int irq; + struct regmap *regmap; + unsigned short keycodes[MAX7360_MAX_KEY_ROWS * MAX7360_MAX_KEY_COLS]; +}; + +static irqreturn_t max7360_keypad_irq(int irq, void *data) +{ + struct max7360_keypad *max7360_keypad = data; + unsigned int val; + unsigned int row, col; + unsigned int release; + unsigned int code; + int error; + + do { + error = regmap_read(max7360_keypad->regmap, MAX7360_REG_KEYFIFO, + &val); + if (error) { + dev_err(&max7360_keypad->input->dev, + "Failed to read max7360 FIFO"); + return IRQ_NONE; + } + + /* FIFO overflow: ignore it and get next event. */ + if (val == MAX7360_FIFO_OVERFLOW) + dev_warn(&max7360_keypad->input->dev, + "max7360 FIFO overflow"); + } while (val == MAX7360_FIFO_OVERFLOW); + + if (val == MAX7360_FIFO_EMPTY) { + dev_dbg(&max7360_keypad->input->dev, + "Got a spurious interrupt"); + + return IRQ_NONE; + } + + row = FIELD_GET(MAX7360_FIFO_ROW, val); + col = FIELD_GET(MAX7360_FIFO_COL, val); + release = val & MAX7360_FIFO_RELEASE; + + code = MATRIX_SCAN_CODE(row, col, MAX7360_ROW_SHIFT); + + dev_dbg(&max7360_keypad->input->dev, + "key[%d:%d] %s\n", row, col, release ? "release" : "press"); + + input_event(max7360_keypad->input, EV_MSC, MSC_SCAN, code); + input_report_key(max7360_keypad->input, max7360_keypad->keycodes[code], + !release); + input_sync(max7360_keypad->input); + + return IRQ_HANDLED; +} + +static int max7360_keypad_open(struct input_dev *pdev) +{ + struct max7360_keypad *max7360_keypad = input_get_drvdata(pdev); + int error; + + /* + * Somebody is using the device: get out of sleep. + */ + error = regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_CONFIG, + MAX7360_CFG_SLEEP, MAX7360_CFG_SLEEP); + if (error) { + dev_err(&max7360_keypad->input->dev, + "Failed to write max7360 configuration\n"); + return error; + } + + return 0; +} + +static void max7360_keypad_close(struct input_dev *pdev) +{ + struct max7360_keypad *max7360_keypad = input_get_drvdata(pdev); + int error; + + /* + * Nobody is using the device anymore: go to sleep. + */ + error = regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_CONFIG, MAX7360_CFG_SLEEP, 0); + if (error) + dev_err(&max7360_keypad->input->dev, + "Failed to write max7360 configuration\n"); +} + +static int max7360_keypad_hw_init(struct max7360_keypad *max7360_keypad) +{ + unsigned int val; + int error; + + val = max7360_keypad->debounce_ms - MAX7360_DEBOUNCE_MIN; + error = regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_DEBOUNCE, + MAX7360_DEBOUNCE, + FIELD_PREP(MAX7360_DEBOUNCE, val)); + if (error) { + return dev_err_probe(&max7360_keypad->input->dev, error, + "Failed to write max7360 debounce configuration\n"); + } + + error = regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_INTERRUPT, + MAX7360_INTERRUPT_TIME_MASK, + FIELD_PREP(MAX7360_INTERRUPT_TIME_MASK, 1)); + if (error) { + return dev_err_probe(&max7360_keypad->input->dev, error, + "Failed to write max7360 keypad interrupt configuration\n"); + } + + return 0; +} + +static int max7360_keypad_parse_dt(struct platform_device *pdev, + struct max7360_keypad *max7360_keypad, + bool *autorepeat) +{ + int error; + + error = matrix_keypad_parse_properties(pdev->dev.parent, + &max7360_keypad->rows, + &max7360_keypad->cols); + if (error) + return error; + + if (!max7360_keypad->rows || !max7360_keypad->cols || + max7360_keypad->rows > MAX7360_MAX_KEY_ROWS || + max7360_keypad->cols > MAX7360_MAX_KEY_COLS) { + dev_err(&pdev->dev, + "Invalid number of columns or rows (%ux%u)\n", + max7360_keypad->cols, max7360_keypad->rows); + return -EINVAL; + } + + *autorepeat = device_property_read_bool(pdev->dev.parent, "autorepeat"); + + max7360_keypad->debounce_ms = MAX7360_DEBOUNCE_MIN; + error = device_property_read_u32(pdev->dev.parent, + "keypad-debounce-delay-ms", + &max7360_keypad->debounce_ms); + if (error == -EINVAL) { + dev_info(&pdev->dev, "Using default keypad-debounce-delay-ms: %u\n", + max7360_keypad->debounce_ms); + } else if (error < 0) { + dev_err(&pdev->dev, + "Failed to read keypad-debounce-delay-ms property\n"); + return error; + } else if (max7360_keypad->debounce_ms < MAX7360_DEBOUNCE_MIN || + max7360_keypad->debounce_ms > MAX7360_DEBOUNCE_MAX) { + dev_err(&pdev->dev, + "Invalid keypad-debounce-delay-ms: %u, should be between %u and %u.\n", + max7360_keypad->debounce_ms, MAX7360_DEBOUNCE_MIN, + MAX7360_DEBOUNCE_MAX); + return -EINVAL; + } + + return 0; +} + +static int max7360_keypad_probe(struct platform_device *pdev) +{ + struct max7360_keypad *max7360_keypad; + struct input_dev *input; + bool autorepeat; + int error; + int irq; + + if (!pdev->dev.parent) + return dev_err_probe(&pdev->dev, -ENODEV, "No parent device\n"); + + irq = platform_get_irq_byname(to_platform_device(pdev->dev.parent), + "intk"); + if (irq < 0) + return irq; + + max7360_keypad = devm_kzalloc(&pdev->dev, sizeof(*max7360_keypad), + GFP_KERNEL); + if (!max7360_keypad) + return -ENOMEM; + + max7360_keypad->regmap = dev_get_regmap(pdev->dev.parent, NULL); + if (!max7360_keypad->regmap) + return dev_err_probe(&pdev->dev, -ENODEV, + "Could not get parent regmap\n"); + + error = max7360_keypad_parse_dt(pdev, max7360_keypad, &autorepeat); + if (error) + return error; + + input = devm_input_allocate_device(pdev->dev.parent); + if (!input) + return -ENOMEM; + + max7360_keypad->input = input; + + input->id.bustype = BUS_I2C; + input->name = pdev->name; + input->open = max7360_keypad_open; + input->close = max7360_keypad_close; + + error = matrix_keypad_build_keymap(NULL, NULL, + MAX7360_MAX_KEY_ROWS, + MAX7360_MAX_KEY_COLS, + max7360_keypad->keycodes, input); + if (error) + return dev_err_probe(&pdev->dev, error, + "Failed to build keymap\n"); + + input_set_capability(input, EV_MSC, MSC_SCAN); + if (autorepeat) + __set_bit(EV_REP, input->evbit); + + input_set_drvdata(input, max7360_keypad); + + error = devm_request_threaded_irq(&pdev->dev, irq, NULL, + max7360_keypad_irq, + IRQF_TRIGGER_LOW | IRQF_ONESHOT, + "max7360-keypad", max7360_keypad); + if (error) + return dev_err_probe(&pdev->dev, error, + "Failed to register interrupt\n"); + + error = input_register_device(input); + if (error) + return dev_err_probe(&pdev->dev, error, + "Could not register input device\n"); + + platform_set_drvdata(pdev, max7360_keypad); + + error = max7360_keypad_hw_init(max7360_keypad); + if (error) + return dev_err_probe(&pdev->dev, error, + "Failed to initialize max7360 keypad\n"); + + device_init_wakeup(&pdev->dev, true); + error = dev_pm_set_wake_irq(&pdev->dev, irq); + if (error) + dev_warn(&pdev->dev, "Failed to set up wakeup irq: %d\n", + error); + + return 0; +} + +static void max7360_keypad_remove(struct platform_device *pdev) +{ + dev_pm_clear_wake_irq(&pdev->dev); +} + +static struct platform_driver max7360_keypad_driver = { + .driver = { + .name = "max7360-keypad", + }, + .probe = max7360_keypad_probe, + .remove = max7360_keypad_remove, +}; +module_platform_driver(max7360_keypad_driver); + +MODULE_DESCRIPTION("MAX7360 Keypad driver"); +MODULE_AUTHOR("Mathieu Dubois-Briand "); +MODULE_LICENSE("GPL"); From patchwork Fri Feb 14 11:49:59 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: 865180 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) (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 6ADA3263F2D; Fri, 14 Feb 2025 11:50:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533824; cv=none; b=Nb5JSY7+GuyCzebxKpQXpkeKwYWBtP3QL0OROruoWBzwSTXInQonNtvMeC0GwvLJ3MVMH+qcj7ur6W1caQr4Q3gg6nmYUkqq3fp1p6e2SkCEOtcxHqeqDV6jWUGKxMThnzlbxBMrBGzalAwlDbjzH2m3HnKQXvAJ728QvfldqQc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533824; c=relaxed/simple; bh=2YQix1en3Vx/atfszEacllAnN0Jh/8t0ppRktHo2Hz4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PQtMfFcpciP2q935j2E6iIcfEEbLlB6bxryLxS+ZcCCjqivk8JF0JNynHL0kRFWy9kjedYtj3bSAYQBsLz9xP388NycWozq1h8rXHhsWO6b3FKriYRBbasJEvvV4G9pBZX9ZOS5x5lsON9rgkQTzt3ZMexmvl2J3pkcjlxwqP4k= 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=kQCT0dDq; arc=none smtp.client-ip=217.70.183.197 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="kQCT0dDq" Received: by mail.gandi.net (Postfix) with ESMTPSA id DAE6C442E4; Fri, 14 Feb 2025 11:50:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1739533819; 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=5RjYNaOLtqlk640MTT3kapCE7TApzxrTf3pYinTkrbk=; b=kQCT0dDqyAW87DJ0p5LUC8QK3GCMi3V3b29K2JdINE4WDl5Ie6feHlsY9RUZctTovYnWvi Q0WAcAof2agxXsr9x7OFMc26r8yJsxY2On9Xd/1JbJDvEC0RJ3h6hx1iXZvfLXrkJgmCaL 1WdZFzyYSU5eFQM01Pvqh/rc3L7vK37NgtCefvbeg7vHQTxnD3R8X0RgfojBZMiHaEvm/Y tRjeFtDj0Ax1fuma8q3phzsrOL1pkiTSdslYMv2LKTvAuD6yf3jmuiMcqLjjXNErD4d62P q8Ra62TvSIYcbL9/gRi5Z66k7DBKKL7LGZ+xhfUuR/ey1c/g0wr2hfuvreSIzQ== From: Mathieu Dubois-Briand Date: Fri, 14 Feb 2025 12:49:59 +0100 Subject: [PATCH v4 09/10] input: misc: Add support for MAX7360 rotary Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250214-mdb-max7360-support-v4-9-8a35c6dbb966@bootlin.com> References: <20250214-mdb-max7360-support-v4-0-8a35c6dbb966@bootlin.com> In-Reply-To: <20250214-mdb-max7360-support-v4-0-8a35c6dbb966@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=1739533806; l=7143; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=2YQix1en3Vx/atfszEacllAnN0Jh/8t0ppRktHo2Hz4=; b=dQU9wHAKLuEv+C0CVk1g6smFcRccf5AY/VjOnb6Kha4QAeG07laRGyutJtRXUnQPeAZvsX5Wm khMSvGdmYUtBzKn25zjpjqzTehdYhzVapXYTt+0PWC+AYIARbD25o+r 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: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegleehjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnheptdfhgeetvddvheejieehheehueetjeelkedtfeehhefgfeeglefhteegtddthfetnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpeegnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdefpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrt ghomhdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhrvghgohhrhidrtghlvghmvghnthessghoohhtlhhinhdrtghomhdprhgtphhtthhopegurghkrheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepthhhohhmrghsrdhpvghtrgiiiihonhhisegsohhothhlihhnrdgtohhmpdhrtghpthhtohepsghrghhlsegsghguvghvrdhplhdprhgtphhtthhopehlihhnuhigqdhgphhiohesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-GND-Sasl: mathieu.dubois-briand@bootlin.com Add driver for Maxim Integrated MAX7360 rotary encoder controller, supporting a single rotary switch. Signed-off-by: Mathieu Dubois-Briand --- drivers/input/misc/Kconfig | 11 +++ drivers/input/misc/Makefile | 1 + drivers/input/misc/max7360-rotary.c | 182 ++++++++++++++++++++++++++++++++++++ 3 files changed, 194 insertions(+) diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index 13d135257e06..96b183b4d3a5 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -230,6 +230,17 @@ config INPUT_M68K_BEEP tristate "M68k Beeper support" depends on M68K +config INPUT_MAX7360_ROTARY + tristate "Maxim MAX7360 Rotary Encoder" + depends on I2C + depends on MFD_MAX7360 + help + If you say yes here you get support for the rotary encoder on the + Maxim MAX7360 I/O Expander. + + To compile this driver as a module, choose M here: the + module will be called max7360_rotary. + config INPUT_MAX77650_ONKEY tristate "Maxim MAX77650 ONKEY support" depends on MFD_MAX77650 diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile index 6d91804d0a6f..c454fba3a3ae 100644 --- a/drivers/input/misc/Makefile +++ b/drivers/input/misc/Makefile @@ -51,6 +51,7 @@ obj-$(CONFIG_INPUT_IQS7222) += iqs7222.o obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o obj-$(CONFIG_INPUT_KXTJ9) += kxtj9.o obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o +obj-$(CONFIG_INPUT_MAX7360_ROTARY) += max7360-rotary.o obj-$(CONFIG_INPUT_MAX77650_ONKEY) += max77650-onkey.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC) += max77693-haptic.o obj-$(CONFIG_INPUT_MAX8925_ONKEY) += max8925_onkey.o diff --git a/drivers/input/misc/max7360-rotary.c b/drivers/input/misc/max7360-rotary.c new file mode 100644 index 000000000000..bea25203a5c1 --- /dev/null +++ b/drivers/input/misc/max7360-rotary.c @@ -0,0 +1,182 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2024 Bootlin + * + * Author: Mathieu Dubois-Briand + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct max7360_rotary { + u32 axis; + struct input_dev *input; + unsigned int debounce_ms; + struct regmap *regmap; +}; + +static irqreturn_t max7360_rotary_irq(int irq, void *data) +{ + struct max7360_rotary *max7360_rotary = data; + int val; + int ret; + + ret = regmap_read(max7360_rotary->regmap, MAX7360_REG_RTR_CNT, &val); + if (ret < 0) { + dev_err(&max7360_rotary->input->dev, + "Failed to read rotary counter\n"); + return IRQ_NONE; + } + + if (val == 0) { + dev_dbg(&max7360_rotary->input->dev, + "Got a spurious interrupt\n"); + + return IRQ_NONE; + } + + input_report_rel(max7360_rotary->input, max7360_rotary->axis, + (int8_t)val); + input_sync(max7360_rotary->input); + + return IRQ_HANDLED; +} + +static int max7360_rotary_hw_init(struct max7360_rotary *max7360_rotary) +{ + int val; + int ret; + + ret = regmap_write_bits(max7360_rotary->regmap, MAX7360_REG_GPIOCFG, + MAX7360_GPIO_CFG_RTR_EN, + MAX7360_GPIO_CFG_RTR_EN); + if (ret) { + dev_err(&max7360_rotary->input->dev, + "Failed to enable max7360 rotary encoder\n"); + return ret; + } + + val = FIELD_PREP(MAX7360_ROT_DEBOUNCE, max7360_rotary->debounce_ms) | + FIELD_PREP(MAX7360_ROT_INTCNT, 1) | MAX7360_ROT_INTCNT_DLY; + ret = regmap_write(max7360_rotary->regmap, MAX7360_REG_RTRCFG, val); + if (ret) { + dev_err(&max7360_rotary->input->dev, + "Failed to set max7360 rotary encoder configuration\n"); + return ret; + } + + return 0; +} + +static int max7360_rotary_probe(struct platform_device *pdev) +{ + struct max7360_rotary *max7360_rotary; + struct input_dev *input; + int irq; + int ret; + + if (!pdev->dev.parent) + return dev_err_probe(&pdev->dev, -ENODEV, "No parent device\n"); + + ret = max7360_port_pin_request(pdev->dev.parent, MAX7360_PORT_RTR_PIN, + true); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "Could not request rotary pin\n"); + + irq = platform_get_irq_byname(to_platform_device(pdev->dev.parent), + "inti"); + if (irq < 0) + return irq; + + max7360_rotary = devm_kzalloc(&pdev->dev, sizeof(*max7360_rotary), + GFP_KERNEL); + if (!max7360_rotary) + return -ENOMEM; + + max7360_rotary->regmap = dev_get_regmap(pdev->dev.parent, NULL); + if (!max7360_rotary->regmap) + dev_err_probe(&pdev->dev, -ENODEV, + "Could not get parent regmap\n"); + + device_property_read_u32(pdev->dev.parent, "linux,axis", + &max7360_rotary->axis); + device_property_read_u32(pdev->dev.parent, "rotary-debounce-delay-ms", + &max7360_rotary->debounce_ms); + if (max7360_rotary->debounce_ms > MAX7360_ROT_DEBOUNCE_MAX) + return dev_err_probe(&pdev->dev, -EINVAL, + "Invalid debounce timing: %u\n", + max7360_rotary->debounce_ms); + + input = devm_input_allocate_device(&pdev->dev); + if (!input) + return -ENOMEM; + + max7360_rotary->input = input; + + input->id.bustype = BUS_I2C; + input->name = pdev->name; + input->dev.parent = &pdev->dev; + + input_set_capability(input, EV_REL, max7360_rotary->axis); + input_set_drvdata(input, max7360_rotary); + + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, + max7360_rotary_irq, + IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED, + "max7360-rotary", max7360_rotary); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "Failed to register interrupt\n"); + + ret = input_register_device(input); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "Could not register input device\n"); + + platform_set_drvdata(pdev, max7360_rotary); + + device_init_wakeup(&pdev->dev, true); + ret = dev_pm_set_wake_irq(&pdev->dev, irq); + if (ret) + dev_warn(&pdev->dev, "Failed to set up wakeup irq: %d\n", ret); + + ret = max7360_rotary_hw_init(max7360_rotary); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "Failed to initialize max7360 rotary\n"); + + return 0; +} + +static void max7360_rotary_remove(struct platform_device *pdev) +{ + dev_pm_clear_wake_irq(&pdev->dev); + + /* + * Free the MAX7360_PORT_RTR_PIN pin, so it can be requested later by + * this driver, the MAX7360 GPIO driver or the MAX7360 PWM driver. + */ + max7360_port_pin_request(pdev->dev.parent, MAX7360_PORT_RTR_PIN, false); +} + +static struct platform_driver max7360_rotary_driver = { + .driver = { + .name = "max7360-rotary", + }, + .probe = max7360_rotary_probe, + .remove = max7360_rotary_remove, +}; +module_platform_driver(max7360_rotary_driver); + +MODULE_DESCRIPTION("MAX7360 Rotary driver"); +MODULE_AUTHOR("Mathieu Dubois-Briand "); +MODULE_LICENSE("GPL");