From patchwork Fri Feb 14 11:49:51 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: 13974786 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 6925525A623; 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=1739533821; cv=none; b=r+yq3XLskUQL0JQHF/65BlX1YUVuOCcmFDo44rz2XrUO3DHZypXTHBh+jlq8C1s+hKnCcAeqm9kNbZ4XdQV0aUP5PWIcec4cAUZLLhN0csqHQnrBh47G7q/UZo2zZdzgnyKmh9/8RJShdLJqPFHQS9eoABsqi9QzDML3wkfq/6Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533821; c=relaxed/simple; bh=4iN68doD3fuxmdxwZZOCLGLep9xA7tPWi7Ap13zkwBA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EVOZyJktrZ4Xu+JFzVQkLTPrU1HJM1BAKQLF2bsPEzqy/7B4q6wuDjGBZzKSnNKcjvsS4jHbx3/2gxAzU4+RQZdBaDiUL1uvxVi+SDKCdcovVfTbPaB5V/3PywpGmX77jO7cr7EJW272Q6cXV/vT+yYn6YMvFbHkgrnW8Ev3GfY= 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=YA0s2APU; 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="YA0s2APU" Received: by mail.gandi.net (Postfix) with ESMTPSA id 603D543315; Fri, 14 Feb 2025 11:50:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1739533811; 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=OdVQYpsk+S3y1cmSBqy5oKwPS+bnRUAOfytj1CpgdKA=; b=YA0s2APUsrSChhVJ0dtfkDKxt8MsP+Ta4WYrKiChOeV90qon9vr2bCP9jZbqvkE5XkMmFJ eItEBvqc3Q91dVnxvmeGAF6YmMtnHMUDuTsxTDLia7PjgoPTrRjow16xKvR0FLgOh/xjwl ynO2Yg5Gr65JuLOvTzpqNW+HuUUHuHqH6Tyv9xLWKAsqctGvPNWWwqgUVtBOlYXzIVowxc c+5RFW4SuKlYTIuDYkM2IKR78VnXPUTxsQIBw2vH0P63z0czna/L3dmhMyjX8yP3q+kXol AWzM14wqVncUzZWnCF4H9XbuoSTrOcLazBcbfmig2dt69CR3vPwfvvLhZ+UWpg== From: Mathieu Dubois-Briand Date: Fri, 14 Feb 2025 12:49:51 +0100 Subject: [PATCH v4 01/10] dt-bindings: mfd: gpio: Add MAX7360 Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250214-mdb-max7360-support-v4-1-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=6853; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=4iN68doD3fuxmdxwZZOCLGLep9xA7tPWi7Ap13zkwBA=; b=MiqBcqTYxprBR3aTieH/Hn5c56g2HISIhRM1q8vJjhnXpakA/pVZxNgycSTwv00Z5Wf51QOg4 Vn4Kn1rZmj6AqS0OwsAs152iOEIjrcJ3xqe0/UY3GWeWNYzxF7f/ypo 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: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegleehjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepheejtdfffeegfeelleektedvgefgteegtdejtedutdevteegtdeileefgfdviefhnecuffhomhgrihhnpeguvghvihgtvghtrhgvvgdrohhrghdprghnrghlohhgrdgtohhmnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdefpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpt hhtohepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepghhrvghgohhrhidrtghlvghmvghnthessghoohhtlhhinhdrtghomhdprhgtphhtthhopegurghkrheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepthhhohhmrghsrdhpvghtrgiiiihonhhisegsohhothhlihhnrdgtohhmpdhrtghpthhtohepsghrghhlsegsghguvghvrdhplhdprhgtphhtthhopehlihhnuhigqdhgphhiohesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-GND-Sasl: mathieu.dubois-briand@bootlin.com Add device tree bindings for Maxim Integrated MAX7360 device with support for keypad, rotary, gpios and pwm functionalities. Signed-off-by: Mathieu Dubois-Briand Reviewed-by: Krzysztof Kozlowski --- .../bindings/gpio/maxim,max7360-gpio.yaml | 91 ++++++++++++++ .../devicetree/bindings/mfd/maxim,max7360.yaml | 139 +++++++++++++++++++++ 2 files changed, 230 insertions(+) diff --git a/Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml b/Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file mode 100644 index 000000000000..bdaed7917051 --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml @@ -0,0 +1,91 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/gpio/maxim,max7360-gpio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Maxim MAX7360 GPIO controller + +maintainers: + - Kamel Bouhara + - Mathieu Dubois-Briand + +description: | + Maxim MAX7360 GPIO controller, in MAX7360 chipset + https://www.analog.com/en/products/max7360.html + + The device provide two series of GPIOs, referred here as GPIOs and GPOs. + + PORT0 to PORT7 pins can be used as GPIOs, with support for interrupts and + constant-current mode. These pins will also be used by the torary encoder and + PWM functionalities. + + COL2 to COL7 pins can be used as GPOs, there is no input capability. COL pins + will be partitionned, with the first pins being affected to the keypad + functionality and the last ones as GPOs. This partioning must be described + here using the ngpios property. + +properties: + compatible: + enum: + - maxim,max7360-gpio + - maxim,max7360-gpo + + gpio-controller: true + + "#gpio-cells": + const: 2 + + ngpios: + minimum: 0 + maximum: 6 + + interrupt-controller: true + + "#interrupt-cells": + const: 2 + + maxim,constant-current-disable: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Bit field, each bit disables constant-current output of the associated + GPIO, starting from the least significant bit for the first GPIO. + maximum: 0xff + +required: + - compatible + - gpio-controller + +allOf: + - if: + properties: + compatible: + contains: + enum: + - maxim,max7360-gpio + ngpios: false + then: + required: + - interrupt-controller + else: + properties: + interrupt-controller: false + maxim,constant-current-disable: false + + required: + - ngpios + +additionalProperties: false + +examples: + - | + gpio { + compatible = "maxim,max7360-gpio"; + + gpio-controller; + #gpio-cells = <2>; + maxim,constant-current-disable = <0x06>; + + interrupt-controller; + #interrupt-cells = <2>; + }; diff --git a/Documentation/devicetree/bindings/mfd/maxim,max7360.yaml b/Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file mode 100644 index 000000000000..4b93a3dd8ae4 --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/maxim,max7360.yaml @@ -0,0 +1,139 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/mfd/maxim,max7360.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Maxim MAX7360 Keypad, Rotary encoder, PWM and GPIO controller + +maintainers: + - Kamel Bouhara + - Mathieu Dubois-Briand + +description: | + Maxim MAX7360 device, with following functions: + - keypad controller + - rotary controller + - GPIO and GPO controller + - PWM controller + + https://www.analog.com/en/products/max7360.html + +allOf: + - $ref: /schemas/input/matrix-keymap.yaml# + - $ref: /schemas/input/input.yaml# + +properties: + compatible: + enum: + - maxim,max7360 + + reg: + maxItems: 1 + + interrupts: + maxItems: 2 + + interrupt-names: + items: + - const: inti + - const: intk + + keypad-debounce-delay-ms: + description: Keypad debounce delay in ms + minimum: 9 + maximum: 40 + default: 9 + + rotary-debounce-delay-ms: + description: Rotary encoder debounce delay in ms + minimum: 0 + maximum: 15 + default: 0 + + linux,axis: + description: The input subsystem axis to map to this rotary encoder. + + "#pwm-cells": + const: 3 + + gpio: + $ref: /schemas/gpio/maxim,max7360-gpio.yaml# + description: + PORT0 to PORT7 general purpose input/output pins configuration. + + gpo: + $ref: /schemas/gpio/maxim,max7360-gpio.yaml# + description: + COL2 to COL7 general purpose output pins configuration. + Allows to use unused keypad columns as outputs. + The MAX7360 has 8 column lines and 6 of them can be used as GPOs. Value + of ngpios must be coherent with the value of keypad,num-columns, as their + sum must not exceed the number of physical lines. + +required: + - compatible + - reg + - interrupts + - interrupt-names + - linux,keymap + - linux,axis + - "#pwm-cells" + - gpio + - gpo + +unevaluatedProperties: false + +examples: + - | + #include + #include + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + io-expander@38 { + compatible = "maxim,max7360"; + reg = <0x38>; + + interrupt-parent = <&gpio1>; + interrupts = <23 IRQ_TYPE_LEVEL_LOW>, + <24 IRQ_TYPE_LEVEL_LOW>; + interrupt-names = "inti", "intk"; + + keypad,num-rows = <8>; + keypad,num-columns = <4>; + linux,keymap = < + MATRIX_KEY(0x00, 0x00, KEY_F5) + MATRIX_KEY(0x01, 0x00, KEY_F4) + MATRIX_KEY(0x02, 0x01, KEY_F6) + >; + keypad-debounce-delay-ms = <10>; + autorepeat; + + rotary-debounce-delay-ms = <2>; + linux,axis = <0>; /* REL_X */ + + #pwm-cells = <3>; + + max7360_gpio: gpio { + compatible = "maxim,max7360-gpio"; + + gpio-controller; + #gpio-cells = <2>; + maxim,constant-current-disable = <0x06>; + + interrupt-controller; + #interrupt-cells = <0x2>; + }; + + max7360_gpo: gpo { + compatible = "maxim,max7360-gpo"; + + gpio-controller; + #gpio-cells = <2>; + ngpios = <4>; + }; + }; + }; From patchwork Fri Feb 14 11:49:52 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: 13974788 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 4A3B3263C64; 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=A1paWREWbC5uLRyMtEIdKHBE0ew1Gx3C44j5Cwxom6x6J+HtIeln1ziNg+MMSua+FsWkbrVrvOBImwEM4bsT+9mIdGVytqU+OxpH4EcSEQcj4zVObjaJRbR+1GoEoRoCUoUFlW4k/uDFWDUsvFTvKG0AGZ71cj2YsCzAj+z7ghY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533822; c=relaxed/simple; bh=cM8GtLZ+bLNxWZhWtRWMTgHK+nu3k2+SE/685tamwdA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=PMUD3+wkyFW02tEv+y4iXGEHGMR3eKYikGJ5rfZDQUl2zyUB73s3UQb3GCM9WcbT7vLFoROLykrPNZ7W8PoTQO1Hc04jgl6KEqdKNMtAvnhhcUgTUJa7AIO/5mvJcPBlFg8pmrV3HtQPMM+K0YC3NP+WN2/C7L966gcKYTfpWvo= 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=LqYFCJGj; 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="LqYFCJGj" Received: by mail.gandi.net (Postfix) with ESMTPSA id 629AD4429B; Fri, 14 Feb 2025 11:50:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1739533812; 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=q6dN52st5BOuW/1TAQeF1FVppaZge03iCWeKGuavnsY=; b=LqYFCJGjWSUikCbXdJIMbogCscRV3XKsQq0VH8eFqTgyPpiQajFFe/cT5ZLQ5Bwd0aRIgv kfq0adqMcRuHAZ1erhu5HD9OWaR3QUCreJ78eXBbOffOKEJ9uV2uCgVb2zeaN/8JvlnmAG af73+tZskRpJCC30VKkLBtOZUMSu2IY2vAJAXEy6OJL4owaiG5Ym359NCm2YhNCFenU2aW dQvGBFe2S0TC44ZUlzGXjbIIRJa7Yt2WWoR8aGLdwwEZIqKQGWqoCx+LzdmnTtfaHH0bd/ 2Il5lzQtMMQRMA3jd3eqdf61UQ7vB+Nz1tzlW2L069NKISZfGhO3jYWqOLZofQ== From: mathieu.dubois-briand@bootlin.com Date: Fri, 14 Feb 2025 12:49:52 +0100 Subject: [PATCH v4 02/10] mfd: Add max7360 support Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250214-mdb-max7360-support-v4-2-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=11127; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=eGMCWid0yMZTgPOBVWirLnrWY5N03FatifPs65pXIts=; b=qSSZJbN+EQIdnJ/qbC+KKVS/y+y1rmDCBNL7drRv2hQRVX87/KrqfCly+kfn6Qrywpw47GIj9 LOb7A0Gl0YWBaKUTy5LvfPepQMkLIUyBx9r3aLTcl8EUIdakP+OWyAQ 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: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegleehjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpehmrghthhhivghurdguuhgsohhishdqsghrihgrnhgusegsohhothhlihhnrdgtohhmnecuggftrfgrthhtvghrnhepveehffetteetffeftedvleeltddttdfhvefhgfelheefvdevudduhfehudfgleegnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdefpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlr dhorhhgpdhrtghpthhtohepghhrvghgohhrhidrtghlvghmvghnthessghoohhtlhhinhdrtghomhdprhgtphhtthhopegurghkrheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepthhhohhmrghsrdhpvghtrgiiiihonhhisegsohhothhlihhnrdgtohhmpdhrtghpthhtohepsghrghhlsegsghguvghvrdhplhdprhgtphhtthhopehlihhnuhigqdhgphhiohesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-GND-Sasl: mathieu.dubois-briand@bootlin.com From: Kamel Bouhara Add core driver to support MAX7360 i2c chip, multi function device with keypad, gpio, pwm, gpo and rotary encoder submodules. Signed-off-by: Kamel Bouhara Co-developed-by: Mathieu Dubois-Briand Signed-off-by: Mathieu Dubois-Briand --- drivers/mfd/Kconfig | 14 +++ drivers/mfd/Makefile | 1 + drivers/mfd/max7360.c | 218 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/mfd/max7360.h | 112 +++++++++++++++++++++++ 4 files changed, 345 insertions(+) diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 6b0682af6e32..ef02a1c4322c 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -2439,5 +2439,19 @@ config MFD_UPBOARD_FPGA To compile this driver as a module, choose M here: the module will be called upboard-fpga. +config MFD_MAX7360 + tristate "Maxim MAX7360 I2C IO Expander" + depends on I2C + select MFD_CORE + select REGMAP_I2C + select REGMAP_IRQ + help + Say yes here to add support for Maxim MAX7360 device, embedding + keypad, rotary encoder, PWM and GPIO features. + + This driver provides common support for accessing the device; + additional drivers must be enabled in order to use the functionality + of the device. + endmenu endif diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile index 9220eaf7cf12..db2bd232c150 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -163,6 +163,7 @@ obj-$(CONFIG_MFD_DA9063) += da9063.o obj-$(CONFIG_MFD_DA9150) += da9150-core.o obj-$(CONFIG_MFD_MAX14577) += max14577.o +obj-$(CONFIG_MFD_MAX7360) += max7360.o obj-$(CONFIG_MFD_MAX77541) += max77541.o obj-$(CONFIG_MFD_MAX77620) += max77620.o obj-$(CONFIG_MFD_MAX77650) += max77650.o diff --git a/drivers/mfd/max7360.c b/drivers/mfd/max7360.c new file mode 100644 index 000000000000..04ff8f5c811b --- /dev/null +++ b/drivers/mfd/max7360.c @@ -0,0 +1,218 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Maxim MAX7360 Core Driver + * + * Copyright (C) 2024 Kamel Bouhara + * Author: Kamel Bouhara + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static DEFINE_SPINLOCK(request_lock); + +struct max7360 { + struct device *dev; + struct regmap *regmap; + unsigned int requested_ports; +}; + +static const struct mfd_cell max7360_cells[] = { + { + .name = "max7360-pwm", + }, + { + .name = "max7360-gpo", + .of_compatible = "maxim,max7360-gpo", + }, + { + .name = "max7360-gpio", + .of_compatible = "maxim,max7360-gpio", + }, + { + .name = "max7360-keypad", + }, + { + .name = "max7360-rotary", + }, +}; + +static const struct regmap_range max7360_volatile_ranges[] = { + { + .range_min = MAX7360_REG_KEYFIFO, + .range_max = MAX7360_REG_KEYFIFO, + }, { + .range_min = 0x48, + .range_max = 0x4a, + }, +}; + +static const struct regmap_access_table max7360_volatile_table = { + .yes_ranges = max7360_volatile_ranges, + .n_yes_ranges = ARRAY_SIZE(max7360_volatile_ranges), +}; + +static const struct regmap_config max7360_regmap_config = { + .reg_bits = 8, + .val_bits = 8, + .max_register = 0xff, + .volatile_table = &max7360_volatile_table, + .cache_type = REGCACHE_MAPLE, +}; + +int max7360_port_pin_request(struct device *dev, unsigned int pin, bool request) +{ + struct i2c_client *client; + struct max7360 *max7360; + unsigned long flags; + int ret = 0; + + client = to_i2c_client(dev); + max7360 = i2c_get_clientdata(client); + + spin_lock_irqsave(&request_lock, flags); + if (request) { + if (max7360->requested_ports & BIT(pin)) + ret = -EBUSY; + else + max7360->requested_ports |= BIT(pin); + } else { + max7360->requested_ports &= ~BIT(pin); + } + spin_unlock_irqrestore(&request_lock, flags); + + return ret; +} +EXPORT_SYMBOL_GPL(max7360_port_pin_request); + +static int max7360_mask_irqs(struct max7360 *max7360) +{ + unsigned int val; + int ret; + + /* + * GPIO/PWM interrupts are not masked on reset: mask the during probe, + * avoiding repeated spurious interrupts if the corresponding drivers + * are not present. + */ + for (int i = 0; i < MAX7360_PORT_PWM_COUNT; i++) { + ret = regmap_write_bits(max7360->regmap, MAX7360_REG_PWMCFG(i), + MAX7360_PORT_CFG_INTERRUPT_MASK, + MAX7360_PORT_CFG_INTERRUPT_MASK); + if (ret) { + dev_err(max7360->dev, "Failed to write max7360 port configuration"); + return ret; + } + } + + /* Read GPIO in register, to ACK any pending IRQ. */ + ret = regmap_read(max7360->regmap, MAX7360_REG_GPIOIN, &val); + if (ret) { + dev_err(max7360->dev, "Failed to read gpio values: %d\n", ret); + return ret; + } + + return 0; +} + +static int max7360_reset(struct max7360 *max7360) +{ + int err; + + err = regmap_write(max7360->regmap, MAX7360_REG_GPIOCFG, + MAX7360_GPIO_CFG_GPIO_RST); + if (err) { + dev_err(max7360->dev, "Failed to reset GPIO configuration: %x\n", err); + return err; + } + + err = regcache_drop_region(max7360->regmap, MAX7360_REG_GPIOCFG, + MAX7360_REG_GPIO_LAST); + if (err) { + dev_err(max7360->dev, "Failed to drop regmap cache: %x\n", err); + return err; + } + + err = regmap_write(max7360->regmap, MAX7360_REG_SLEEP, 0); + if (err) { + dev_err(max7360->dev, "Failed to reset autosleep configuration: %x\n", err); + return err; + } + + err = regmap_write(max7360->regmap, MAX7360_REG_DEBOUNCE, 0); + if (err) { + dev_err(max7360->dev, "Failed to reset GPO port count: %x\n", err); + return err; + } + + return 0; +} + +static int max7360_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct regmap *regmap; + struct max7360 *max7360; + int err; + + regmap = devm_regmap_init_i2c(client, &max7360_regmap_config); + if (IS_ERR(regmap)) + return dev_err_probe(dev, PTR_ERR(regmap), + "Failed to initialise regmap\n"); + + max7360 = devm_kzalloc(dev, sizeof(*max7360), GFP_KERNEL); + if (!max7360) + return -ENOMEM; + + max7360->regmap = regmap; + max7360->dev = dev; + i2c_set_clientdata(client, max7360); + + err = max7360_reset(max7360); + if (err) + return dev_err_probe(dev, err, "Failed to reset device\n"); + + /* Get the device out of shutdown mode. */ + err = regmap_write_bits(regmap, MAX7360_REG_GPIOCFG, + MAX7360_GPIO_CFG_GPIO_EN, + MAX7360_GPIO_CFG_GPIO_EN); + if (err) + return dev_err_probe(dev, err, "Failed to enable GPIO and PWM module\n"); + + err = max7360_mask_irqs(max7360); + if (err) + return dev_err_probe(dev, err, "Could not mask interrupts\n"); + + err = devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, + max7360_cells, ARRAY_SIZE(max7360_cells), + NULL, 0, NULL); + if (err) + return dev_err_probe(dev, err, "Failed to register child devices\n"); + + return 0; +} + +static const struct of_device_id max7360_dt_match[] = { + { .compatible = "maxim,max7360" }, + {}, +}; +MODULE_DEVICE_TABLE(of, max7360_dt_match); + +static struct i2c_driver max7360_driver = { + .driver = { + .name = "max7360", + .of_match_table = max7360_dt_match, + }, + .probe = max7360_probe, +}; +module_i2c_driver(max7360_driver); + +MODULE_DESCRIPTION("Maxim MAX7360 I2C IO Expander core driver"); +MODULE_AUTHOR("Kamel Bouhara "); +MODULE_LICENSE("GPL"); diff --git a/include/linux/mfd/max7360.h b/include/linux/mfd/max7360.h new file mode 100644 index 000000000000..6beff7405d10 --- /dev/null +++ b/include/linux/mfd/max7360.h @@ -0,0 +1,112 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __LINUX_MFD_MAX7360_H +#define __LINUX_MFD_MAX7360_H + +#include +#include + +#define MAX7360_MAX_KEY_ROWS 8 +#define MAX7360_MAX_KEY_COLS 8 +#define MAX7360_MAX_KEY_NUM (MAX7360_MAX_KEY_ROWS * MAX7360_MAX_KEY_COLS) +#define MAX7360_ROW_SHIFT 3 + +#define MAX7360_MAX_GPIO 8 +#define MAX7360_MAX_GPO 6 +#define MAX7360_PORT_PWM_COUNT 8 +#define MAX7360_PORT_RTR_PIN (MAX7360_PORT_PWM_COUNT - 1) + +/* + * MAX7360 registers + */ +#define MAX7360_REG_KEYFIFO 0x00 +#define MAX7360_REG_CONFIG 0x01 +#define MAX7360_REG_DEBOUNCE 0x02 +#define MAX7360_REG_INTERRUPT 0x03 +#define MAX7360_REG_PORTS 0x04 +#define MAX7360_REG_KEYREP 0x05 +#define MAX7360_REG_SLEEP 0x06 + +/* + * MAX7360 GPIO registers + * + * All these registers are reset together when writing bit 3 of + * MAX7360_REG_GPIOCFG. + */ +#define MAX7360_REG_GPIOCFG 0x40 +#define MAX7360_REG_GPIOCTRL 0x41 +#define MAX7360_REG_GPIODEB 0x42 +#define MAX7360_REG_GPIOCURR 0x43 +#define MAX7360_REG_GPIOOUTM 0x44 +#define MAX7360_REG_PWMCOM 0x45 +#define MAX7360_REG_RTRCFG 0x46 +#define MAX7360_REG_GPIOIN 0x49 +#define MAX7360_REG_RTR_CNT 0x4A +#define MAX7360_REG_PWMBASE 0x50 +#define MAX7360_REG_PWMCFGBASE 0x58 + +#define MAX7360_REG_GPIO_LAST 0x5F + +#define MAX7360_REG_PWM(x) (MAX7360_REG_PWMBASE + (x)) +#define MAX7360_REG_PWMCFG(x) (MAX7360_REG_PWMCFGBASE + (x)) + +/* + * Configuration register bits + */ +#define MAX7360_FIFO_EMPTY 0x3f +#define MAX7360_FIFO_OVERFLOW 0x7f +#define MAX7360_FIFO_RELEASE BIT(6) +#define MAX7360_FIFO_COL GENMASK(5, 3) +#define MAX7360_FIFO_ROW GENMASK(2, 0) + +#define MAX7360_CFG_SLEEP BIT(7) +#define MAX7360_CFG_INTERRUPT BIT(5) +#define MAX7360_CFG_KEY_RELEASE BIT(3) +#define MAX7360_CFG_WAKEUP BIT(1) +#define MAX7360_CFG_TIMEOUT BIT(0) + +#define MAX7360_DEBOUNCE GENMASK(4, 0) +#define MAX7360_DEBOUNCE_MIN 9 +#define MAX7360_DEBOUNCE_MAX 40 +#define MAX7360_PORTS GENMASK(8, 5) + +#define MAX7360_INTERRUPT_TIME_MASK GENMASK(4, 0) +#define MAX7360_INTERRUPT_FIFO_MASK GENMASK(7, 5) + +#define MAX7360_PORT_CFG_INTERRUPT_MASK BIT(7) +#define MAX7360_PORT_CFG_INTERRUPT_EDGES BIT(6) + +#define MAX7360_REG_GPIOCURR_FIXED 0xC0 + +/* + * Autosleep register values (ms) + */ +#define MAX7360_AUTOSLEEP_8192 0x01 +#define MAX7360_AUTOSLEEP_4096 0x02 +#define MAX7360_AUTOSLEEP_2048 0x03 +#define MAX7360_AUTOSLEEP_1024 0x04 +#define MAX7360_AUTOSLEEP_512 0x05 +#define MAX7360_AUTOSLEEP_256 0x06 + +#define MAX7360_GPIO_CFG_RTR_EN BIT(7) +#define MAX7360_GPIO_CFG_GPIO_EN BIT(4) +#define MAX7360_GPIO_CFG_GPIO_RST BIT(3) + +#define MAX7360_ROT_DEBOUNCE GENMASK(3, 0) +#define MAX7360_ROT_DEBOUNCE_MIN 0 +#define MAX7360_ROT_DEBOUNCE_MAX 15 +#define MAX7360_ROT_INTCNT GENMASK(6, 4) +#define MAX7360_ROT_INTCNT_DLY BIT(7) + +#define MAX7360_INT_INTI 0 +#define MAX7360_INT_INTK 1 + +#define MAX7360_INT_GPIO 0 +#define MAX7360_INT_KEYPAD 1 +#define MAX7360_INT_ROTARY 2 + +#define MAX7360_NR_INTERNAL_IRQS 3 + +int max7360_port_pin_request(struct device *dev, unsigned int pin, bool request); + +#endif From patchwork Fri Feb 14 11:49:53 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: 13974793 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 6A99B263F2C; 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=1739533825; cv=none; b=rEORddKVbdTDx93FcCQd1qca88Fvga+KMTcgvtZLk1QfTfkWlSZC+1ICS+lOGr9zuPK70RORmjmZ91ctTZP6HpKUNZab2bCDssZTpvWnxTEpQxA2A1VfGPtanb8WIkoPu5RsjJfjfm6+hZTzMmNCb7zmLNAnkdNIM2wzfc9D6qo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533825; c=relaxed/simple; bh=t/EuLZQlpOe/LmOn/GZ77df/7tGyTGkWiw9+9XzVGCU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qGek3ueVCCqStY1ij5txNQBOcXrkCtLALIkx7hkV89n+JPJPXMuCOksQ+ULcqEIBD7qmjSLahOsihYu+Jwk8Zh2brHdgxUMSC6APxqZHN81pkwL7iT+gJMDmKEfDuPEDCBFf+Ub3UL9iQjxW17T4C1Et1GJk6Vhe8uaClDk2D0U= 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=kWwxQrjT; 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="kWwxQrjT" Received: by mail.gandi.net (Postfix) with ESMTPSA id 7E95D44299; Fri, 14 Feb 2025 11:50:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1739533813; 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=zhAfL6p2Tu5CbkRFq/4tIEg0OmDK9rfhbiyVWYECfuM=; b=kWwxQrjTkeU8P8uyg2zVtlWcs1TVhdU1FzA5WaIufSWq1oVFDjdYAsE0apwQvraHqz5wts wbTxCfLkpH/oCKPmLftQH4yRpSQS7lWcF9SOxf8PhYLJMsqHtZQhpcyG41/PP8Cq0cu/V3 d1vWzWu4oYDMv05AC4CMXb74VLUT6nSU99I66PIVD3vn9519T8HEUAw6M3gv1OCKIhZRQH 4lD68av5+UOfMfQsqNYtcfS9pddcdIbgtjuj12sz7NHgkZH/00Z4CnpTatx6JCp9MMJd2W LKiOiRem58N2ks/fYQtNxgJ5XJnZwMWH5gLSfpKMQQthjVhPtcgXDz/WmMS+6Q== From: mathieu.dubois-briand@bootlin.com Date: Fri, 14 Feb 2025 12:49:53 +0100 Subject: [PATCH v4 03/10] pwm: max7360: Add MAX7360 PWM support Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250214-mdb-max7360-support-v4-3-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=7974; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=CxMsleng0cZ3BeZymcuuErbxiPnn4kKb8ceRlh9SgXg=; b=Xf0beUWgYo9vw+zVjpW9nw5AzwSlbfq7WymEaxfdXlfS9/YO42oRReLTA62OxjSOzw36JU7W/ 4p9p03wKfBWAx2klJz8/khdfvwl4odUMreQ8DuokEv6yWBLflI5htJv 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: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgdegleehjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpehmrghthhhivghurdguuhgsohhishdqsghrihgrnhgusegsohhothhlihhnrdgtohhmnecuggftrfgrthhtvghrnhepveehffetteetffeftedvleeltddttdfhvefhgfelheefvdevudduhfehudfgleegnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdefpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlr dhorhhgpdhrtghpthhtohepghhrvghgohhrhidrtghlvghmvghnthessghoohhtlhhinhdrtghomhdprhgtphhtthhopegurghkrheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepthhhohhmrghsrdhpvghtrgiiiihonhhisegsohhothhlihhnrdgtohhmpdhrtghpthhtohepsghrghhlsegsghguvghvrdhplhdprhgtphhtthhopehlihhnuhigqdhgphhiohesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-GND-Sasl: mathieu.dubois-briand@bootlin.com From: Kamel Bouhara Add driver for Maxim Integrated MAX7360 PWM controller, supporting up to 8 independent PWM outputs. Signed-off-by: Kamel Bouhara Co-developed-by: Mathieu Dubois-Briand Signed-off-by: Mathieu Dubois-Briand --- drivers/pwm/Kconfig | 10 +++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-max7360.c | 213 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 224 insertions(+) diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index 0915c1e7df16..fac811ee46b5 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -745,4 +745,14 @@ config PWM_XILINX To compile this driver as a module, choose M here: the module will be called pwm-xilinx. +config PWM_MAX7360 + tristate "MAX7360 PWMs" + depends on MFD_MAX7360 + help + PWM driver for Maxim Integrated MAX7360 multifunction device, with + support for up to 8 PWM outputs. + + To compile this driver as a module, choose M here: the module + will be called pwm-max7360. + endif diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile index 9081e0c0e9e0..ae8908ffc892 100644 --- a/drivers/pwm/Makefile +++ b/drivers/pwm/Makefile @@ -36,6 +36,7 @@ obj-$(CONFIG_PWM_LPC32XX) += pwm-lpc32xx.o obj-$(CONFIG_PWM_LPSS) += pwm-lpss.o obj-$(CONFIG_PWM_LPSS_PCI) += pwm-lpss-pci.o obj-$(CONFIG_PWM_LPSS_PLATFORM) += pwm-lpss-platform.o +obj-$(CONFIG_PWM_MAX7360) += pwm-max7360.o obj-$(CONFIG_PWM_MESON) += pwm-meson.o obj-$(CONFIG_PWM_MEDIATEK) += pwm-mediatek.o obj-$(CONFIG_PWM_MICROCHIP_CORE) += pwm-microchip-core.o diff --git a/drivers/pwm/pwm-max7360.c b/drivers/pwm/pwm-max7360.c new file mode 100644 index 000000000000..f1257c20add2 --- /dev/null +++ b/drivers/pwm/pwm-max7360.c @@ -0,0 +1,213 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2024 Bootlin + * + * Author: Kamel BOUHARA + * Author: Mathieu Dubois-Briand + * + * Limitations: + * - Only supports normal polarity. + * - The period is fixed to 2 ms. + * - Only the duty cycle can be changed, new values are applied at the beginning + * of the next cycle. + * - When disabled, the output is put in Hi-Z. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX7360_NUM_PWMS 8 +#define MAX7360_PWM_MAX_RES 255 +#define MAX7360_PWM_PERIOD_NS 2000000 /* 500 Hz */ +#define MAX7360_PWM_COMMON_PWN BIT(5) +#define MAX7360_PWM_CTRL_ENABLE(n) BIT(n) +#define MAX7360_PWM_PORT(n) BIT(n) + +struct max7360_pwm { + struct device *parent; + struct regmap *regmap; +}; + +struct max7360_pwm_waveform { + u8 duty_steps; +}; + +static inline struct max7360_pwm *max7360_pwm_from_chip(struct pwm_chip *chip) +{ + return pwmchip_get_drvdata(chip); +} + +static int max7360_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) +{ + struct max7360_pwm *max7360_pwm; + int ret; + + max7360_pwm = max7360_pwm_from_chip(chip); + ret = max7360_port_pin_request(max7360_pwm->parent, pwm->hwpwm, true); + if (ret) { + dev_warn(&chip->dev, "failed to request pwm-%d\n", pwm->hwpwm); + return ret; + } + + ret = regmap_write_bits(max7360_pwm->regmap, + MAX7360_REG_PWMCFG(pwm->hwpwm), + MAX7360_PWM_COMMON_PWN, + 0); + if (ret) + return ret; + + return regmap_write_bits(max7360_pwm->regmap, MAX7360_REG_PORTS, + MAX7360_PWM_PORT(pwm->hwpwm), + MAX7360_PWM_PORT(pwm->hwpwm)); +} + +static void max7360_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) +{ + struct max7360_pwm *max7360_pwm; + + max7360_pwm = max7360_pwm_from_chip(chip); + max7360_port_pin_request(max7360_pwm->parent, pwm->hwpwm, false); +} + +static int max7360_pwm_round_waveform_tohw(struct pwm_chip *chip, + struct pwm_device *pwm, + const struct pwm_waveform *wf, + void *_wfhw) +{ + struct max7360_pwm_waveform *wfhw = _wfhw; + u64 duty_steps; + + /* + * Ignore user provided values for period_length_ns and duty_offset_ns: + * we only support fixed period of MAX7360_PWM_PERIOD_NS and offset of + * 0. + */ + + duty_steps = mul_u64_u64_div_u64(wf->duty_length_ns, MAX7360_PWM_MAX_RES, + MAX7360_PWM_PERIOD_NS); + + wfhw->duty_steps = min(MAX7360_PWM_MAX_RES, duty_steps); + + return 0; +} + +static int max7360_pwm_round_waveform_fromhw(struct pwm_chip *chip, struct pwm_device *pwm, + const void *_wfhw, struct pwm_waveform *wf) +{ + const struct max7360_pwm_waveform *wfhw = _wfhw; + + wf->period_length_ns = MAX7360_PWM_PERIOD_NS; + wf->duty_offset_ns = 0; + wf->duty_length_ns = DIV64_U64_ROUND_UP(wfhw->duty_steps * MAX7360_PWM_PERIOD_NS, + MAX7360_PWM_MAX_RES); + + return 0; +} + +static int max7360_pwm_write_waveform(struct pwm_chip *chip, + struct pwm_device *pwm, + const void *_wfhw) +{ + const struct max7360_pwm_waveform *wfhw = _wfhw; + struct max7360_pwm *max7360_pwm; + unsigned int val; + int ret; + + max7360_pwm = max7360_pwm_from_chip(chip); + + val = (wfhw->duty_steps == 0) ? 0 : MAX7360_PWM_CTRL_ENABLE(pwm->hwpwm); + ret = regmap_write_bits(max7360_pwm->regmap, MAX7360_REG_GPIOCTRL, + MAX7360_PWM_CTRL_ENABLE(pwm->hwpwm), val); + + if (!ret && wfhw->duty_steps != 0) { + ret = regmap_write(max7360_pwm->regmap, MAX7360_REG_PWM(pwm->hwpwm), + wfhw->duty_steps); + } + + return ret; +} + +static int max7360_pwm_read_waveform(struct pwm_chip *chip, + struct pwm_device *pwm, + void *_wfhw) +{ + struct max7360_pwm_waveform *wfhw = _wfhw; + struct max7360_pwm *max7360_pwm; + unsigned int val; + int ret; + + max7360_pwm = max7360_pwm_from_chip(chip); + + ret = regmap_read(max7360_pwm->regmap, MAX7360_REG_GPIOCTRL, &val); + if (ret) + return ret; + + if (val & MAX7360_PWM_CTRL_ENABLE(pwm->hwpwm)) { + ret = regmap_read(max7360_pwm->regmap, MAX7360_REG_PWM(pwm->hwpwm), + &val); + val = wfhw->duty_steps; + } else { + wfhw->duty_steps = 0; + } + + return ret; +} + +static const struct pwm_ops max7360_pwm_ops = { + .request = max7360_pwm_request, + .free = max7360_pwm_free, + .round_waveform_tohw = max7360_pwm_round_waveform_tohw, + .round_waveform_fromhw = max7360_pwm_round_waveform_fromhw, + .read_waveform = max7360_pwm_read_waveform, + .write_waveform = max7360_pwm_write_waveform, +}; + +static int max7360_pwm_probe(struct platform_device *pdev) +{ + struct max7360_pwm *max7360_pwm; + struct pwm_chip *chip; + int ret; + + if (!pdev->dev.parent) + return dev_err_probe(&pdev->dev, -ENODEV, "no parent device\n"); + + chip = devm_pwmchip_alloc(pdev->dev.parent, MAX7360_NUM_PWMS, + sizeof(*max7360_pwm)); + if (IS_ERR(chip)) + return PTR_ERR(chip); + chip->ops = &max7360_pwm_ops; + + max7360_pwm = max7360_pwm_from_chip(chip); + max7360_pwm->parent = pdev->dev.parent; + + max7360_pwm->regmap = dev_get_regmap(pdev->dev.parent, NULL); + if (!max7360_pwm->regmap) + return dev_err_probe(&pdev->dev, -ENODEV, + "could not get parent regmap\n"); + + ret = devm_pwmchip_add(&pdev->dev, chip); + if (ret != 0) + return dev_err_probe(&pdev->dev, ret, + "failed to add PWM chip\n"); + + return 0; +} + +static struct platform_driver max7360_pwm_driver = { + .driver = { + .name = "max7360-pwm", + }, + .probe = max7360_pwm_probe, +}; +module_platform_driver(max7360_pwm_driver); + +MODULE_DESCRIPTION("MAX7360 PWM driver"); +MODULE_AUTHOR("Kamel BOUHARA "); +MODULE_AUTHOR("Mathieu Dubois-Briand "); +MODULE_LICENSE("GPL"); From patchwork Fri Feb 14 11:49:54 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: 13974790 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 6AE26263F2E; 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=DJaAl0vqHO+A/RB7gVlz2qUtKOCVk8WksqHpIAa4WpBgji5Uyv/+oABB4PUlL54hwr9GWBiKk/FcK3YFNjzj3Rt1jjTqVPHdrB/VuBXRFPEsSt8TIQWnhMu1ouR51ZSU4KjFFmxP4sOZ3JjWoypa/eaI1r8RXx5HADbhDmyRINg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533824; c=relaxed/simple; bh=RACglYSaKk38UOV2H+jm6GJa3jpL0WJBtuPusm0yxSg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nlG8MNRJ7SvI9HrUB1lWK2axlLmLIN3XmXRozfuGOls+YVFOcAKbWWjZhKxpnilzzfO5f84Y58/fLzVRP8/f2xswuEoe5vps4/5YxmMdTcRMQOdBfeKcKGP/Ze4MJfrJAxVlJfz26enXVpQj7TJ2IO3gWa39Iy3fjfztsK4l8fA= 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=QPP1kn/O; 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="QPP1kn/O" Received: by mail.gandi.net (Postfix) with ESMTPSA id 97427442E0; Fri, 14 Feb 2025 11:50:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1739533814; 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=mOp6v2Ru6Y06CuRpAEPXOFL6ll0w0HhqmA5LgQKfTVU=; b=QPP1kn/OkSeUFxayYEB6SsGSDpzdTyUG3yO3yFj7BnNuUSqgiWF9Phl8qZD0IV6cmF6sGn fHSIhtIJkyRmOha1MQtLO8zEGAUBee9Kcc6yk5ye814Zza5dRKARr3seA+e/ypS4PkMiTZ EptJFEcBiSb8uHXq1GNtD2xSNzjEjTjWx99e40lNVnXEOoerlTLV1cPGlKxsqC2cBxA0Jv JsXmdNwg7FveYOei3rLwog0Cl1Elhzl2H4UsO+tV+U2CmeF8oSIouSWb/6jPbyqojP7+qw PKQF1gBnH4fdd8/OEEGv9ULKDohLLr6bnQc77hqXTbS6zlCPxUXFOpdj99lDJA== From: Mathieu Dubois-Briand Date: Fri, 14 Feb 2025 12:49:54 +0100 Subject: [PATCH v4 04/10] gpio: regmap: Allow to provide request and free callbacks Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250214-mdb-max7360-support-v4-4-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=2131; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=RACglYSaKk38UOV2H+jm6GJa3jpL0WJBtuPusm0yxSg=; b=oje7y82KnEsmMhMkE2XtUgZhcjWPi5QYw/4g0u1gfSdllShmhkXWjcw+5uJrxvsV/6ax3sixB GjL7vy3dz3uCD5aLzXB6V+kKBEc/GnP+AuMt+dJyxXzIIL3mLrC9GHG 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 Allows to populate the gpio_regmap_config structure with request() and free() callbacks to set on the final gpio_chip structure. Signed-off-by: Mathieu Dubois-Briand --- drivers/gpio/gpio-regmap.c | 2 ++ include/linux/gpio/regmap.h | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 05f8781b5204..ba72c23bcf97 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -261,6 +261,8 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config chip->names = config->names; chip->label = config->label ?: dev_name(config->parent); chip->can_sleep = regmap_might_sleep(config->regmap); + chip->request = config->request; + chip->free = config->free; chip->request = gpiochip_generic_request; chip->free = gpiochip_generic_free; diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h index a9f7b7faf57b..16f0c33df75d 100644 --- a/include/linux/gpio/regmap.h +++ b/include/linux/gpio/regmap.h @@ -6,6 +6,7 @@ struct device; struct fwnode_handle; struct gpio_regmap; +struct gpio_chip; struct irq_domain; struct regmap; @@ -40,6 +41,10 @@ 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). + * @request: (Optional) Hook for chip-specific activation, such as + * enabling module power and clock + * @free: (Optional) Hook for chip-specific deactivation, such as + * disabling module power and clock * * 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 @@ -83,6 +88,8 @@ struct gpio_regmap_config { unsigned int *mask); void *drvdata; + int (*request)(struct gpio_chip *gc, unsigned int offset); + void (*free)(struct gpio_chip *gc, unsigned int offset); }; struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config); 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: 13974794 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-input@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: 13974785 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-input@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: 13974787 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-input@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: 13974789 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-input@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: 13974792 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-input@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"); From patchwork Fri Feb 14 11:50:00 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: 13974795 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 BF56E26462F; 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=L61Ai2nmqUQIVw3eQYjRprpzEHUsgtDskJnMOedwEdQFkWHlwQE/rKYWXf6BMJZaNfrThT+iUmUMHe0iS+tb1NKKgV9lbjkXA9IZSovt8bm2irg8JkAJvGk2RUwsqPS6ZtqX0N3/8OYagyBuaiQ6KgU0cHfZF2FGC5z7MxXPQro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739533825; c=relaxed/simple; bh=D/eIms9kiC35KWhyUeLOEVFRQllk3whI5W6tAPS54ps=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ufs5NuxNRH4qS2ib2LVTjiusHBKOqhByRowAnufCmRyIcA13iqAbwckzGxQSYJK9boZ3MqxHcK8xT5inJXA+k7dUPtUPNtniILDVqfLt7tTP51nI3mjWZLDNrq61BZGfYgxZl78yeQRfOD1vrNOfetYK+ak5SUsUdvSIwR0MM+E= 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=iQQumOHM; 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="iQQumOHM" Received: by mail.gandi.net (Postfix) with ESMTPSA id EC35B442C0; Fri, 14 Feb 2025 11:50:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1739533820; 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=KmhFstE9r58cW4sRIbJleq7fBxZv+mHOP5YHY97/3Lg=; b=iQQumOHM8h8wylM5W0LrNpmPlfFLza5iiw1Jof2W8UYFDCddBWEP1NriQQd6ZLoL+oRJ1Z xrozJooF0Ma8aNgEnoqp/bNjgK0QOB7Q3AqjpGYJYVHzjcx+E/sy/ggei7lgdmAunx53ph pIsiwdiFhjI61NBcGGyTOTpr3k/lZ+xZeOALY88LhTJKD9aCl04h9hpMAdeotuWoSdIS6B Ux0By4r/PF5uQv3p/9IGQnjISG67FkJxNJ2AebFcC6kQAZlSeuxf3iQZ5vr1f6VYgjwlSl pH6r9gDqzpDJ6XomyXN8XNxRr1I2w0YpvsKLTPUb6mktzInGk7HWSJNt9FjSZA== From: Mathieu Dubois-Briand Date: Fri, 14 Feb 2025 12:50:00 +0100 Subject: [PATCH v4 10/10] MAINTAINERS: Add entry on MAX7360 driver Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250214-mdb-max7360-support-v4-10-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=1042; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=D/eIms9kiC35KWhyUeLOEVFRQllk3whI5W6tAPS54ps=; b=BjvuPwcQmsL5Sf8B6SZYaiHb2mS3Iic12ZFWmdR/RTDKCB2JGwSjcdWTcmfYcV6l1FqewUbOq lUMYXFjsYL0AwLvSWdOys6h4oJLrm2I9P25YLvVIBLgfNu4BOzcXpn0 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 myself as maintainer of Maxim MAX7360 driver and device-tree bindings. Signed-off-by: Mathieu Dubois-Briand --- MAINTAINERS | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 25c86f47353d..1916b41309f0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14259,6 +14259,18 @@ L: linux-iio@vger.kernel.org S: Maintained F: drivers/iio/temperature/max30208.c +MAXIM MAX7360 KEYPAD LED MFD DRIVER +M: Mathieu Dubois-Briand +S: Maintained +F: Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml +F: Documentation/devicetree/bindings/mfd/maxim,max7360.yaml +F: drivers/gpio/gpio-max7360.c +F: drivers/input/keyboard/max7360-keypad.c +F: drivers/input/misc/max7360-rotary.c +F: drivers/mfd/max7360.c +F: drivers/pwm/pwm-max7360.c +F: include/linux/mfd/max7360.h + MAXIM MAX77650 PMIC MFD DRIVER M: Bartosz Golaszewski L: linux-kernel@vger.kernel.org