From nobody Mon Oct 6 10:17:35 2025 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 46D92185E4A; Tue, 22 Jul 2025 16:24:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201448; cv=none; b=ltOZCHmyfjBAs+W9i8X0FQF8kO2zorirDZdaZrx9a0Qem/R/p9zK4sHMw/GFI9Mzvix51+z4FmzEIKXHMF+Im0qqOwRC+V0dZdaOXFGWlj9ZABSzWNJRgUmcA+2NC13Lgn27cURKPzulsljhoL0AwyFTDmY9CDKgqo2IF/XqrGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201448; c=relaxed/simple; bh=wprZAh4BLREySU3+zEXoQ34/ISWzpqaxjbFXM1cNUzI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DmvYNLtB+yQYy98/dZT4mIM8EbwwfpGcurN8OlQJpBz3I13flsE/D49f7nNGScNbKwx2zCftHqGSSJgZOwtT16EG1Ac3DB2RsDdcwfrBAKZ2UXRCtqnKt3j0zUwcG9ZFRDZZnCDTekuCI+uh616r0wILA5om0CxdtAxt+M2lRSQ= 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=EiWdBSat; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="EiWdBSat" Received: by mail.gandi.net (Postfix) with ESMTPSA id 79427442BC; Tue, 22 Jul 2025 16:24:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1753201443; 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=VBVnORInjejJx4XhdEI/Ybeem6+PgF2XxE1ECVXz2Tw=; b=EiWdBSattn1gU+vvA8S1ASAbOxRPVXN/aTPzNuwQRVWcS75cU/Ymr//UYqhGEDdugKN+IG Ffc9pmQnsOi/aKoGekRmfU/eKk8cvlGap08Y2xcRXGMKgejHYCcI3e7SA20k+/iu4CkRX8 k2t6p7YF9DrGlDs4LTSj7Km1PDCPYRcCzacVGRW2ULC3F4YlZXFKJBAr/zY4qWA80ZCaJv irYa38I0zGdBtKHF9FhAPFpqq80ZbfgYTEWYvx3qfSw/NWnHOKd8w1tqxawnNwmJDp2ky3 bekR0J8yOiX8Ehm5DFcoHu/oLV9gycuVM/fgL/zXsjBYye1u6DgxnFf2/TJDxA== From: Mathieu Dubois-Briand Date: Tue, 22 Jul 2025 18:23:45 +0200 Subject: [PATCH v12 01/10] dt-bindings: mfd: gpio: Add MAX7360 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250722-mdb-max7360-support-v12-1-3747721a8d02@bootlin.com> References: <20250722-mdb-max7360-support-v12-0-3747721a8d02@bootlin.com> In-Reply-To: <20250722-mdb-max7360-support-v12-0-3747721a8d02@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=B6nig?= , 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=A9gory_Clement?= , Thomas Petazzoni , Mathieu Dubois-Briand , Krzysztof Kozlowski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1753201440; l=8461; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=wprZAh4BLREySU3+zEXoQ34/ISWzpqaxjbFXM1cNUzI=; b=0dZV2GKG77C/hqni/fB6rSz2JapPWkl4mhCZtXwBLfECg1qXY8H68vgKenjjH9nUPg8K9xo2i 40FYPyfeV+XBCC8uNxRGDeG0fcd8LzluWuBpLj+dFEvcy+760V7IjsK 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: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejheefiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepheejtdfffeegfeelleektedvgefgteegtdejtedutdevteegtdeileefgfdviefhnecuffhomhgrihhnpeguvghvihgtvghtrhgvvgdrohhrghdprghnrghlohhgrdgtohhmnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdegpdhrtghpthhtoheplhhinhhushdrfigrlhhlvghijheslhhinhgrrhhordhorhhgpdhrtghpthhtohepm hifrghllhgvsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhihidrshhhvghvtghhvghnkhhosehinhhtvghlrdgtohhmpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpfihmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptghonhhorhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlvggvsehkvghrnhgvlhdrohhrgh 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. Reviewed-by: Rob Herring (Arm) Reviewed-by: Krzysztof Kozlowski Signed-off-by: Mathieu Dubois-Briand --- .../bindings/gpio/maxim,max7360-gpio.yaml | 83 +++++++++ .../devicetree/bindings/mfd/maxim,max7360.yaml | 191 +++++++++++++++++= ++++ 2 files changed, 274 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..c5c3fc4c816f --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml @@ -0,0 +1,83 @@ +# 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 provides 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 rotary encode= r and + PWM functionalities. + + COL2 to COL7 pins can be used as GPOs, there is no input capability. COL= pins + will be partitioned, with the first pins being affected to the keypad + functionality and the last ones as GPOs. + +properties: + compatible: + enum: + - maxim,max7360-gpio + - maxim,max7360-gpo + + gpio-controller: true + + "#gpio-cells": + const: 2 + + 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 associat= ed + 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 + +additionalProperties: false + +examples: + - | + gpio { + compatible =3D "maxim,max7360-gpio"; + + gpio-controller; + #gpio-cells =3D <2>; + maxim,constant-current-disable =3D <0x06>; + + interrupt-controller; + #interrupt-cells =3D <2>; + }; diff --git a/Documentation/devicetree/bindings/mfd/maxim,max7360.yaml b/Doc= umentation/devicetree/bindings/mfd/maxim,max7360.yaml new file mode 100644 index 000000000000..3fc920c8639d --- /dev/null +++ b/Documentation/devicetree/bindings/mfd/maxim,max7360.yaml @@ -0,0 +1,191 @@ +# 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: + $ref: /schemas/input/rotary-encoder.yaml#/properties/linux,axis + + rotary-encoder,relative-axis: + $ref: /schemas/types.yaml#/definitions/flag + description: + Register a relative axis rather than an absolute one. + + rotary-encoder,steps: + $ref: /schemas/types.yaml#/definitions/uint32 + default: 24 + description: + Number of steps in a full turnaround of the + encoder. Only relevant for absolute axis. Defaults to 24 which is a + typical value for such devices. + + rotary-encoder,rollover: + $ref: /schemas/types.yaml#/definitions/flag + description: + Automatic rollover when the rotary value becomes + greater than the specified steps or smaller than 0. For absolute axi= s only. + + "#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. GP= IOs + numbers used for this gpio-controller node do correspond to the colu= mn + numbers: values 0 and 1 are never valid, values from 2 to 7 might be= valid + depending on the value of the keypad,num-column property. + +patternProperties: + '-pins$': + type: object + description: + Pinctrl node's client devices use subnodes for desired pin configura= tion. + Client device subnodes use below standard properties. + $ref: /schemas/pinctrl/pincfg-node.yaml + + properties: + pins: + description: + List of gpio pins affected by the properties specified in this + subnode. + items: + pattern: '^(PORT[0-7]|ROTARY)$' + minItems: 1 + maxItems: 8 + + function: + description: + Specify the alternative function to be configured for the specif= ied + pins. + enum: [gpio, pwm, rotary] + + additionalProperties: false + +required: + - compatible + - reg + - interrupts + - interrupt-names + - linux,keymap + - linux,axis + - "#pwm-cells" + - gpio + - gpo + +unevaluatedProperties: false + +examples: + - | + #include + #include + + i2c { + #address-cells =3D <1>; + #size-cells =3D <0>; + + io-expander@38 { + compatible =3D "maxim,max7360"; + reg =3D <0x38>; + + interrupt-parent =3D <&gpio1>; + interrupts =3D <23 IRQ_TYPE_LEVEL_LOW>, + <24 IRQ_TYPE_LEVEL_LOW>; + interrupt-names =3D "inti", "intk"; + + keypad,num-rows =3D <8>; + keypad,num-columns =3D <4>; + linux,keymap =3D < + MATRIX_KEY(0x00, 0x00, KEY_F5) + MATRIX_KEY(0x01, 0x00, KEY_F4) + MATRIX_KEY(0x02, 0x01, KEY_F6) + >; + keypad-debounce-delay-ms =3D <10>; + autorepeat; + + rotary-debounce-delay-ms =3D <2>; + linux,axis =3D <0>; /* REL_X */ + rotary-encoder,relative-axis; + + #pwm-cells =3D <3>; + + max7360_gpio: gpio { + compatible =3D "maxim,max7360-gpio"; + + gpio-controller; + #gpio-cells =3D <2>; + maxim,constant-current-disable =3D <0x06>; + + interrupt-controller; + #interrupt-cells =3D <0x2>; + }; + + max7360_gpo: gpo { + compatible =3D "maxim,max7360-gpo"; + + gpio-controller; + #gpio-cells =3D <2>; + }; + + backlight_pins: backlight-pins { + pins =3D "PORT2"; + function =3D "pwm"; + }; + }; + }; --=20 2.39.5 From nobody Mon Oct 6 10:17:35 2025 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 721F51DDA32; Tue, 22 Jul 2025 16:24:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201449; cv=none; b=FYK5xVMA98eDpZtyN8coFNtIbfNte1PETSMHTmKAXU0InooN2t2a+tbR5DXPbWeNdCgXJMPcdnaizQxMjwyA/Royldyxq81r2OVsJPTo369PWAz6X7mKPzax+1fO8iYFAJ2/yRYRHk35xtgVHsO+vNw5R3oe+5EeswG0FGp/lnk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201449; c=relaxed/simple; bh=g/VkPL/gZxdlMrHnk7IDQwUv8dRf6yFbgswsZFCufbo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=HlvXdL0I/CX1+iEcsKCyEMSbcvE0n/QfbxxQzCIsM9GIkYDfCyV6Zj3fTUxcIl/0cSc+PKRnjo2pb8qfmN1sWTpjaBOi89zTDg787E3iuV6R6bG1Uarop/DR9VQN70XRaW1YtNFu1Wu15u+9ydkOhqvkdvjjswUO4FrDUBXTIew= 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=RTCP1EEO; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="RTCP1EEO" Received: by mail.gandi.net (Postfix) with ESMTPSA id 9139B442BB; Tue, 22 Jul 2025 16:24:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1753201444; 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=pjEKAjsncR4/L4GtOYqGr+uDeSgXQ1x/SJMQAuOaQ64=; b=RTCP1EEOnxP4cO7Gk3PdfGExkevZlookRDMNraSRTWYjRgDd0cxtOWDnqhNBOwC57aTwS6 Jg5g+1Pu9miGyWxj6n51AO0naycFV6AeoyACF3w+9WFZVqArhKKeGe+W0hMwGhSaEEfPCT mR68SMSmM1CsYlJBtbhHabZSPuwj4SoB8lI/o7/9DVuSDVQbJvHcvpLUDI5euTTtLZ+DHe 1I/ZwdfI+lZN7Tg1c3dD18dpaMz+B8TaJ0op8/Wd+btTZoT+/tWIAeLujUal9ABq/YunMZ QTTa6ZJeCFTAJNJ5NP0HqkUkaacHeZRL7Vvykr3IzA5KElxbtpEtTAJeEy3ERg== From: Mathieu Dubois-Briand Date: Tue, 22 Jul 2025 18:23:46 +0200 Subject: [PATCH v12 02/10] mfd: Add max7360 support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250722-mdb-max7360-support-v12-2-3747721a8d02@bootlin.com> References: <20250722-mdb-max7360-support-v12-0-3747721a8d02@bootlin.com> In-Reply-To: <20250722-mdb-max7360-support-v12-0-3747721a8d02@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=B6nig?= , 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=A9gory_Clement?= , Thomas Petazzoni , Mathieu Dubois-Briand , Andy Shevchenko X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1753201440; l=10567; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=LhRu+I96dRoD3M/3pvdt12mTdtT8JVFtpePMi3DJGLM=; b=iQXfR8gGENOpyRJbEmVrGdIiqyGngRWQB3oODOUdW5W3p/J66osJHaskifuyEXWBRCeVftPE0 3xQ2G0YWSJYAQc8lwdwPHZBKvg30FA4hpDL5EhHEFrISiYubmWzr3ie 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: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejheefiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnheptdfhgeetvddvheejieehheehueetjeelkedtfeehhefgfeeglefhteegtddthfetnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdegpdhrtghpthhtoheplhhinhhushdrfigrlhhlvghijheslhhinhgrrhhordhorhhgpdhrtghpthhtohepmhifrghllhgvsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhihidrshhhv ghvtghhvghnkhhosehinhhtvghlrdgtohhmpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpfihmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptghonhhorhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlvggvsehkvghrnhgvlhdrohhrgh 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 Reviewed-by: Andy Shevchenko --- drivers/mfd/Kconfig | 14 ++++ drivers/mfd/Makefile | 1 + drivers/mfd/max7360.c | 171 ++++++++++++++++++++++++++++++++++++++++= ++++ include/linux/mfd/max7360.h | 109 ++++++++++++++++++++++++++++ 4 files changed, 295 insertions(+) diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig index 6fb3768e3d71..b9092ba6c7c5 100644 --- a/drivers/mfd/Kconfig +++ b/drivers/mfd/Kconfig @@ -2463,5 +2463,19 @@ config MFD_UPBOARD_FPGA To compile this driver as a module, choose M here: the module will be called upboard-fpga. =20 +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 79495f9f3457..ed5a7ea0b1dd 100644 --- a/drivers/mfd/Makefile +++ b/drivers/mfd/Makefile @@ -162,6 +162,7 @@ obj-$(CONFIG_MFD_DA9063) +=3D da9063.o obj-$(CONFIG_MFD_DA9150) +=3D da9150-core.o =20 obj-$(CONFIG_MFD_MAX14577) +=3D max14577.o +obj-$(CONFIG_MFD_MAX7360) +=3D max7360.o obj-$(CONFIG_MFD_MAX77541) +=3D max77541.o obj-$(CONFIG_MFD_MAX77620) +=3D max77620.o obj-$(CONFIG_MFD_MAX77650) +=3D max77650.o diff --git a/drivers/mfd/max7360.c b/drivers/mfd/max7360.c new file mode 100644 index 000000000000..5ee459c490ec --- /dev/null +++ b/drivers/mfd/max7360.c @@ -0,0 +1,171 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Maxim MAX7360 Core Driver + * + * Copyright 2025 Bootlin + * + * Authors: + * Kamel Bouhara + * Mathieu Dubois-Briand + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static const struct mfd_cell max7360_cells[] =3D { + { .name =3D "max7360-pinctrl" }, + { .name =3D "max7360-pwm" }, + { .name =3D "max7360-keypad" }, + { .name =3D "max7360-rotary" }, + { + .name =3D "max7360-gpo", + .of_compatible =3D "maxim,max7360-gpo", + }, + { + .name =3D "max7360-gpio", + .of_compatible =3D "maxim,max7360-gpio", + }, +}; + +static const struct regmap_range max7360_volatile_ranges[] =3D { + regmap_reg_range(MAX7360_REG_KEYFIFO, MAX7360_REG_KEYFIFO), + regmap_reg_range(MAX7360_REG_I2C_TIMEOUT, MAX7360_REG_RTR_CNT), +}; + +static const struct regmap_access_table max7360_volatile_table =3D { + .yes_ranges =3D max7360_volatile_ranges, + .n_yes_ranges =3D ARRAY_SIZE(max7360_volatile_ranges), +}; + +static const struct regmap_config max7360_regmap_config =3D { + .reg_bits =3D 8, + .val_bits =3D 8, + .max_register =3D MAX7360_REG_PWMCFG(MAX7360_PORT_PWM_COUNT - 1), + .volatile_table =3D &max7360_volatile_table, + .cache_type =3D REGCACHE_MAPLE, +}; + +static int max7360_mask_irqs(struct regmap *regmap) +{ + struct device *dev =3D regmap_get_device(regmap); + unsigned int val; + int ret; + + /* + * GPIO/PWM interrupts are not masked on reset: as the MAX7360 "INTI" + * interrupt line is shared between GPIOs and rotary encoder, this could + * result in repeated spurious interrupts on the rotary encoder driver + * if the GPIO driver is not loaded. Mask them now to avoid this + * situation. + */ + for (unsigned int i =3D 0; i < MAX7360_PORT_PWM_COUNT; i++) { + ret =3D regmap_write_bits(regmap, MAX7360_REG_PWMCFG(i), + MAX7360_PORT_CFG_INTERRUPT_MASK, + MAX7360_PORT_CFG_INTERRUPT_MASK); + if (ret) + return dev_err_probe(dev, ret, + "Failed to write MAX7360 port configuration\n"); + } + + /* Read GPIO in register, to ACK any pending IRQ. */ + ret =3D regmap_read(regmap, MAX7360_REG_GPIOIN, &val); + if (ret) + return dev_err_probe(dev, ret, "Failed to read GPIO values\n"); + + return 0; +} + +static int max7360_reset(struct regmap *regmap) +{ + struct device *dev =3D regmap_get_device(regmap); + int ret; + + ret =3D regmap_write(regmap, MAX7360_REG_GPIOCFG, MAX7360_GPIO_CFG_GPIO_R= ST); + if (ret) { + dev_err(dev, "Failed to reset GPIO configuration: %x\n", ret); + return ret; + } + + ret =3D regcache_drop_region(regmap, MAX7360_REG_GPIOCFG, MAX7360_REG_GPI= O_LAST); + if (ret) { + dev_err(dev, "Failed to drop regmap cache: %x\n", ret); + return ret; + } + + ret =3D regmap_write(regmap, MAX7360_REG_SLEEP, 0); + if (ret) { + dev_err(dev, "Failed to reset autosleep configuration: %x\n", ret); + return ret; + } + + ret =3D regmap_write(regmap, MAX7360_REG_DEBOUNCE, 0); + if (ret) + dev_err(dev, "Failed to reset GPO port count: %x\n", ret); + + return ret; +} + +static int max7360_probe(struct i2c_client *client) +{ + struct device *dev =3D &client->dev; + struct regmap *regmap; + int ret; + + regmap =3D 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"); + + ret =3D max7360_reset(regmap); + if (ret) + return dev_err_probe(dev, ret, "Failed to reset device\n"); + + /* Get the device out of shutdown mode. */ + ret =3D regmap_write_bits(regmap, MAX7360_REG_GPIOCFG, + MAX7360_GPIO_CFG_GPIO_EN, + MAX7360_GPIO_CFG_GPIO_EN); + if (ret) + return dev_err_probe(dev, ret, "Failed to enable GPIO and PWM module\n"); + + ret =3D max7360_mask_irqs(regmap); + if (ret) + return dev_err_probe(dev, ret, "Could not mask interrupts\n"); + + ret =3D devm_mfd_add_devices(dev, PLATFORM_DEVID_NONE, + max7360_cells, ARRAY_SIZE(max7360_cells), + NULL, 0, NULL); + if (ret) + return dev_err_probe(dev, ret, "Failed to register child devices\n"); + + return 0; +} + +static const struct of_device_id max7360_dt_match[] =3D { + { .compatible =3D "maxim,max7360" }, + {} +}; +MODULE_DEVICE_TABLE(of, max7360_dt_match); + +static struct i2c_driver max7360_driver =3D { + .driver =3D { + .name =3D "max7360", + .of_match_table =3D max7360_dt_match, + }, + .probe =3D 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..44cf2bf651a2 --- /dev/null +++ b/include/linux/mfd/max7360.h @@ -0,0 +1,109 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __LINUX_MFD_MAX7360_H +#define __LINUX_MFD_MAX7360_H + +#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_I2C_TIMEOUT 0x48 +#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_PORT_CFG_COMMON_PWM BIT(5) + +/* + * Autosleep register values + */ +#define MAX7360_AUTOSLEEP_8192MS 0x01 +#define MAX7360_AUTOSLEEP_4096MS 0x02 +#define MAX7360_AUTOSLEEP_2048MS 0x03 +#define MAX7360_AUTOSLEEP_1024MS 0x04 +#define MAX7360_AUTOSLEEP_512MS 0x05 +#define MAX7360_AUTOSLEEP_256MS 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 + +#endif --=20 2.39.5 From nobody Mon Oct 6 10:17:35 2025 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6CCFC27A127; Tue, 22 Jul 2025 16:24:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201450; cv=none; b=qZJ5IQcAt2HS/9zVlgF6rxM3qiay6z3Zb01h6XVk3HtNLWtOZYBmhayUXnPEZ8ViC8SA0oiN0COeCHT9sc5CqlBriICy21bqn1dUcNSlsKTlJrlWuav+bILqRGtHx9xDRqv9j8BSvU42sGn+PEhYjo+6iQ5c9SOZlAspZjCGK08= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201450; c=relaxed/simple; bh=Vfwr3T6oFIr11ChPVQ4cLfkvMx4CouG1IEddNOdLMdg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XymFn56id0iKoDbXQGH6fr4iWPKa1llzBxp0KtA7Fbj2F8NoWydvbqDO9uSHfvR8uBXclCbAZFxmjt8I1xIPOpAjcdCNwTZrX3bqP0lPrifP6HAvbJaDDxuXaO6uZvHECz1OIQfNOc5VbrnTsoIXzqE7+d8zDscGeVbxsQYzPuk= 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=ZNI6dIFV; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="ZNI6dIFV" Received: by mail.gandi.net (Postfix) with ESMTPSA id B1D17442BE; Tue, 22 Jul 2025 16:24:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1753201445; 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=t/2/VGmKfyMKjx1nQXnOEIb84oP44Mh6hiFeixIS2G0=; b=ZNI6dIFVWNPd5PGwKDJuA3Z6cLziCUwjxFECMFI1DM8LVbOsqVBY5jpqbAIkHVzpgm84/R 6xvvwXu4TzB2ZWbcHcDxSe/PFrpPeJ71aptGEAg/PsE+sjLR2e11qHPOtLDyJeRersIS/T c7PavbBsPcItUmrfol4Q6skgd2KuzbBkjrjNXwy9ikVk4bmnv56R2DT2BDg/AfZMG6cVBb /kb2vhaVamlvUbV9ebnB93FeqEGTjQh/RdQl8KAwKwklz5IM534G8nQnJlrPdk00CApnQb RmdyGPepS8WTMLoJpKtVUJck0GATqP3Q1z0KWwNdld9gP/I6bF2mLH+0KrmREg== From: Mathieu Dubois-Briand Date: Tue, 22 Jul 2025 18:23:47 +0200 Subject: [PATCH v12 03/10] pinctrl: Add MAX7360 pinctrl driver Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250722-mdb-max7360-support-v12-3-3747721a8d02@bootlin.com> References: <20250722-mdb-max7360-support-v12-0-3747721a8d02@bootlin.com> In-Reply-To: <20250722-mdb-max7360-support-v12-0-3747721a8d02@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=B6nig?= , 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=A9gory_Clement?= , Thomas Petazzoni , Mathieu Dubois-Briand , Andy Shevchenko X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1753201440; l=9011; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=Vfwr3T6oFIr11ChPVQ4cLfkvMx4CouG1IEddNOdLMdg=; b=4yOWmJFbVHMGrApee5Eo2KOfmkOj7K0Fg9jF8JjZ2cksLuZgruJguQ6HFADtlwYHBFByVi0rC bQHNaQWXMseBZvOpvExbcAow0w+V1sj8XMoNazbuZejLtKBlNyQrFP6 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: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejheefiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnheptdfhgeetvddvheejieehheehueetjeelkedtfeehhefgfeeglefhteegtddthfetnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdegpdhrtghpthhtoheplhhinhhushdrfigrlhhlvghijheslhhinhgrrhhordhorhhgpdhrtghpthhtohepmhifrghllhgvsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhihidrshhhv ghvtghhvghnkhhosehinhhtvghlrdgtohhmpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpfihmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptghonhhorhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlvggvsehkvghrnhgvlhdrohhrgh X-GND-Sasl: mathieu.dubois-briand@bootlin.com Add driver for Maxim Integrated MAX7360 pinctrl on the PORT pins. Pins can be used either for GPIO, PWM or rotary encoder functionalities. Signed-off-by: Mathieu Dubois-Briand Reviewed-by: Linus Walleij Reviewed-by: Andy Shevchenko --- drivers/pinctrl/Kconfig | 11 ++ drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-max7360.c | 215 ++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 227 insertions(+) diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig index 33db9104df17..98448db31456 100644 --- a/drivers/pinctrl/Kconfig +++ b/drivers/pinctrl/Kconfig @@ -346,6 +346,17 @@ config PINCTRL_LPC18XX help Pinctrl driver for NXP LPC18xx/43xx System Control Unit (SCU). =20 +config PINCTRL_MAX7360 + tristate "MAX7360 Pincontrol support" + depends on MFD_MAX7360 + select PINMUX + select GENERIC_PINCONF + help + Say Y here to enable pin control support for Maxim MAX7360 keypad + controller. + This keypad controller has 8 GPIO pins that may work as GPIO, or PWM, + or rotary encoder alternate modes. + config PINCTRL_MAX77620 tristate "MAX77620/MAX20024 Pincontrol support" depends on MFD_MAX77620 && OF diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile index ac27e88677d1..974a179b5593 100644 --- a/drivers/pinctrl/Makefile +++ b/drivers/pinctrl/Makefile @@ -36,6 +36,7 @@ obj-$(CONFIG_PINCTRL_FALCON) +=3D pinctrl-falcon.o obj-$(CONFIG_PINCTRL_LOONGSON2) +=3D pinctrl-loongson2.o obj-$(CONFIG_PINCTRL_XWAY) +=3D pinctrl-xway.o obj-$(CONFIG_PINCTRL_LPC18XX) +=3D pinctrl-lpc18xx.o +obj-$(CONFIG_PINCTRL_MAX7360) +=3D pinctrl-max7360.o obj-$(CONFIG_PINCTRL_MAX77620) +=3D pinctrl-max77620.o obj-$(CONFIG_PINCTRL_MCP23S08_I2C) +=3D pinctrl-mcp23s08_i2c.o obj-$(CONFIG_PINCTRL_MCP23S08_SPI) +=3D pinctrl-mcp23s08_spi.o diff --git a/drivers/pinctrl/pinctrl-max7360.c b/drivers/pinctrl/pinctrl-ma= x7360.c new file mode 100644 index 000000000000..abfaff468bad --- /dev/null +++ b/drivers/pinctrl/pinctrl-max7360.c @@ -0,0 +1,215 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2025 Bootlin + * + * Author: Mathieu Dubois-Briand + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "core.h" +#include "pinmux.h" + +struct max7360_pinctrl { + struct pinctrl_dev *pctldev; + struct pinctrl_desc pinctrl_desc; +}; + +static const struct pinctrl_pin_desc max7360_pins[] =3D { + PINCTRL_PIN(0, "PORT0"), + PINCTRL_PIN(1, "PORT1"), + PINCTRL_PIN(2, "PORT2"), + PINCTRL_PIN(3, "PORT3"), + PINCTRL_PIN(4, "PORT4"), + PINCTRL_PIN(5, "PORT5"), + PINCTRL_PIN(6, "PORT6"), + PINCTRL_PIN(7, "PORT7"), +}; + +static const unsigned int port0_pins[] =3D {0}; +static const unsigned int port1_pins[] =3D {1}; +static const unsigned int port2_pins[] =3D {2}; +static const unsigned int port3_pins[] =3D {3}; +static const unsigned int port4_pins[] =3D {4}; +static const unsigned int port5_pins[] =3D {5}; +static const unsigned int port6_pins[] =3D {6}; +static const unsigned int port7_pins[] =3D {7}; +static const unsigned int rotary_pins[] =3D {6, 7}; + +static const struct pingroup max7360_groups[] =3D { + PINCTRL_PINGROUP("PORT0", port0_pins, ARRAY_SIZE(port0_pins)), + PINCTRL_PINGROUP("PORT1", port1_pins, ARRAY_SIZE(port1_pins)), + PINCTRL_PINGROUP("PORT2", port2_pins, ARRAY_SIZE(port2_pins)), + PINCTRL_PINGROUP("PORT3", port3_pins, ARRAY_SIZE(port3_pins)), + PINCTRL_PINGROUP("PORT4", port4_pins, ARRAY_SIZE(port4_pins)), + PINCTRL_PINGROUP("PORT5", port5_pins, ARRAY_SIZE(port5_pins)), + PINCTRL_PINGROUP("PORT6", port6_pins, ARRAY_SIZE(port6_pins)), + PINCTRL_PINGROUP("PORT7", port7_pins, ARRAY_SIZE(port7_pins)), + PINCTRL_PINGROUP("ROTARY", rotary_pins, ARRAY_SIZE(rotary_pins)), +}; + +static int max7360_pinctrl_get_groups_count(struct pinctrl_dev *pctldev) +{ + return ARRAY_SIZE(max7360_groups); +} + +static const char *max7360_pinctrl_get_group_name(struct pinctrl_dev *pctl= dev, + unsigned int group) +{ + return max7360_groups[group].name; +} + +static int max7360_pinctrl_get_group_pins(struct pinctrl_dev *pctldev, + unsigned int group, + const unsigned int **pins, + unsigned int *num_pins) +{ + *pins =3D max7360_groups[group].pins; + *num_pins =3D max7360_groups[group].npins; + return 0; +} + +static const struct pinctrl_ops max7360_pinctrl_ops =3D { + .get_groups_count =3D max7360_pinctrl_get_groups_count, + .get_group_name =3D max7360_pinctrl_get_group_name, + .get_group_pins =3D max7360_pinctrl_get_group_pins, +#ifdef CONFIG_OF + .dt_node_to_map =3D pinconf_generic_dt_node_to_map_pin, + .dt_free_map =3D pinconf_generic_dt_free_map, +#endif +}; + +static const char * const simple_groups[] =3D { + "PORT0", "PORT1", "PORT2", "PORT3", + "PORT4", "PORT5", "PORT6", "PORT7", +}; + +static const char * const rotary_groups[] =3D { "ROTARY" }; + +#define MAX7360_PINCTRL_FN_GPIO 0 +#define MAX7360_PINCTRL_FN_PWM 1 +#define MAX7360_PINCTRL_FN_ROTARY 2 +static const struct pinfunction max7360_functions[] =3D { + [MAX7360_PINCTRL_FN_GPIO] =3D PINCTRL_PINFUNCTION("gpio", simple_groups, + ARRAY_SIZE(simple_groups)), + [MAX7360_PINCTRL_FN_PWM] =3D PINCTRL_PINFUNCTION("pwm", simple_groups, + ARRAY_SIZE(simple_groups)), + [MAX7360_PINCTRL_FN_ROTARY] =3D PINCTRL_PINFUNCTION("rotary", rotary_grou= ps, + ARRAY_SIZE(rotary_groups)), +}; + +static int max7360_get_functions_count(struct pinctrl_dev *pctldev) +{ + return ARRAY_SIZE(max7360_functions); +} + +static const char *max7360_get_function_name(struct pinctrl_dev *pctldev, = unsigned int selector) +{ + return max7360_functions[selector].name; +} + +static int max7360_get_function_groups(struct pinctrl_dev *pctldev, unsign= ed int selector, + const char * const **groups, + unsigned int * const num_groups) +{ + *groups =3D max7360_functions[selector].groups; + *num_groups =3D max7360_functions[selector].ngroups; + + return 0; +} + +static int max7360_set_mux(struct pinctrl_dev *pctldev, unsigned int selec= tor, + unsigned int group) +{ + struct regmap *regmap =3D dev_get_regmap(pctldev->dev->parent, NULL); + int val; + + /* + * GPIO and PWM functions are the same: we only need to handle the + * rotary encoder function, on pins 6 and 7. + */ + if (max7360_groups[group].pins[0] >=3D 6) { + if (selector =3D=3D MAX7360_PINCTRL_FN_ROTARY) + val =3D MAX7360_GPIO_CFG_RTR_EN; + else + val =3D 0; + + return regmap_write_bits(regmap, MAX7360_REG_GPIOCFG, MAX7360_GPIO_CFG_R= TR_EN, val); + } + + return 0; +} + +static const struct pinmux_ops max7360_pmxops =3D { + .get_functions_count =3D max7360_get_functions_count, + .get_function_name =3D max7360_get_function_name, + .get_function_groups =3D max7360_get_function_groups, + .set_mux =3D max7360_set_mux, + .strict =3D true, +}; + +static int max7360_pinctrl_probe(struct platform_device *pdev) +{ + struct regmap *regmap; + struct pinctrl_desc *pd; + struct max7360_pinctrl *chip; + struct device *dev =3D &pdev->dev; + + regmap =3D dev_get_regmap(dev->parent, NULL); + if (!regmap) + return dev_err_probe(dev, -ENODEV, "Could not get parent regmap\n"); + + chip =3D devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL); + if (!chip) + return -ENOMEM; + + pd =3D &chip->pinctrl_desc; + + pd->pctlops =3D &max7360_pinctrl_ops; + pd->pmxops =3D &max7360_pmxops; + pd->name =3D dev_name(dev); + pd->pins =3D max7360_pins; + pd->npins =3D MAX7360_MAX_GPIO; + pd->owner =3D THIS_MODULE; + + /* + * This MFD sub-device does not have any associated device tree node: + * properties are stored in the device node of the parent (MFD) device + * and this same node is used in phandles of client devices. + * Reuse this device tree node here, as otherwise the pinctrl subsystem + * would be confused by this topology. + */ + device_set_of_node_from_dev(dev, dev->parent); + + chip->pctldev =3D devm_pinctrl_register(dev, pd, chip); + if (IS_ERR(chip->pctldev)) + return dev_err_probe(dev, PTR_ERR(chip->pctldev), "can't register contro= ller\n"); + + return 0; +} + +static struct platform_driver max7360_pinctrl_driver =3D { + .driver =3D { + .name =3D "max7360-pinctrl", + }, + .probe =3D max7360_pinctrl_probe, +}; +module_platform_driver(max7360_pinctrl_driver); + +MODULE_DESCRIPTION("MAX7360 pinctrl driver"); +MODULE_AUTHOR("Mathieu Dubois-Briand "); +MODULE_LICENSE("GPL"); --=20 2.39.5 From nobody Mon Oct 6 10:17:35 2025 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7901627AC5C; Tue, 22 Jul 2025 16:24:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201451; cv=none; b=L7UzXp/zuwNszLgePaSJiaZDgTZYsO2VkZLHB2cB+VT0Wq3n8Rz+QiXkd5+PeLHZYf/95svmy3E9h2vxk6u0P6yaUPH3jHLivYMBWzsg4CODkBiYHmQCgDulchyOrhzhbE9u3zUfy1K2DRq0Bqv1qkkH0LnA7OtCOeReWTucK6c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201451; c=relaxed/simple; bh=B59nQRM4OCJKfHLvX2oaTSXwxhw78E4Kff9lIuci+5w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XFmSPy/rl47mIC/qxVR5MEAfkFL74twpQhOU/D3yD7TXZY9o7Tulf5jBnKYiCSx/4Vwj7W4GJ0d7jloaTS2xjKb8Z1rJNbz81+KXLI1oeqSZR8UL4qOkorq1vlOKLpTr4WjTKj1gMLAXpOqWtLEXoBvWpu5oL/dEVg3PLp8wG7c= 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=EhmMYKje; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="EhmMYKje" Received: by mail.gandi.net (Postfix) with ESMTPSA id C671143292; Tue, 22 Jul 2025 16:24:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1753201446; 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=jBMjx8v8dFWA7l8aFxli1l7Noq+zfsEDhaB6354aIiA=; b=EhmMYKjewtnzADA/n669HNXzXjchAWoMbQ3fmwjxZh/Qb5eAn9gb9ZfR4ENWrTzRYnga9g 8ER+PC1LognSafR8gnseRt19YTmuT0etUdOiM29SDiB+wRFpp7qxQw5+xUjFgNQ21X9LYQ 9h1ZqrAAQpBPmYIBtE11Jc/TJkXgzunMQpYzWauvPQaF0eBL05RBqHaMKEZikweq2a2D5U r9AiMueNnndFfmc5/XXakg1bEblhdLyNRNFXI+pGlbP2tO7I3zgoG496khL9I9E8al00Zx hPB/BkBCHFhLRKDId5ZH4gwaDujuDP2PjpfK1K1e+bNIU9dRYQkMwy+gUaNJjw== From: Mathieu Dubois-Briand Date: Tue, 22 Jul 2025 18:23:48 +0200 Subject: [PATCH v12 04/10] pwm: max7360: Add MAX7360 PWM support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250722-mdb-max7360-support-v12-4-3747721a8d02@bootlin.com> References: <20250722-mdb-max7360-support-v12-0-3747721a8d02@bootlin.com> In-Reply-To: <20250722-mdb-max7360-support-v12-0-3747721a8d02@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=B6nig?= , 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=A9gory_Clement?= , Thomas Petazzoni , Mathieu Dubois-Briand , Andy Shevchenko X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1753201440; l=8231; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=y0xadsyuEhq8dPG/0EBjvPHdE0OxVl29OXK2WOiCV8k=; b=JQwQEEBbQHmCgl9N0lSZ0OQR0pjRiV2PH2Z37gZBLyVCekKRj0RG3mgUxyRD09eaI+kofUZgQ FVEqJBx/j2TB/V3nGupML4Vc4rVAr/kxU4QopBjIQRWsWoqjFP751Ds 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: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejheefiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnhepjeeliefghefhvdekgeeuveehieejteetudejieethefhvdeghffgtefhkeeukeetnecuffhomhgrihhnpegrnhgrlhhoghdrtghomhenucfkphepvdgrtddumegtsgdugeemheehieemjegrtddtmeeffhgtfhemfhgstdgumeduvdeivdemvdgvjeeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdgrtddumegtsgdugeemheehieemjegrtddtmeeffhgtfhemfhgstdgumeduvdeivdemvdgvjeeipdhhvghloheplgduvdejrddtrddurddungdpmhgrihhlfhhrohhmpehmrghthhhivghurdguuhgsohhishdqsghrihgrnhgusegsohhothhlihhnrdgtohhmpdhnsggprhgtphhtthhopedvgedprhgtphhtthhopehlihhnuhhsrdifrghllhgvihhjsehlihhnrghrohdrohhrghdprhgtphhtthhopehmfigrlhhlvgeskhgvrhhnvghlrdhor hhgpdhrtghpthhtoheprghnughrihihrdhshhgvvhgthhgvnhhkohesihhnthgvlhdrtghomhdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepkhhriihkodgutheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphifmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegtohhnohhrodgutheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhgvvgeskhgvrhhnvghlrdhorhhg 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 Reviewed-by: Andy Shevchenko --- drivers/pwm/Kconfig | 10 +++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-max7360.c | 206 ++++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 217 insertions(+) diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index d9bcd1e8413e..c8352e503e3b 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -423,6 +423,16 @@ config PWM_LPSS_PLATFORM To compile this driver as a module, choose M here: the module will be called pwm-lpss-platform. =20 +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. + config PWM_MC33XS2410 tristate "MC33XS2410 PWM support" depends on OF diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile index 96160f4257fc..7e30f30bec50 100644 --- a/drivers/pwm/Makefile +++ b/drivers/pwm/Makefile @@ -37,6 +37,7 @@ obj-$(CONFIG_PWM_LPC32XX) +=3D pwm-lpc32xx.o obj-$(CONFIG_PWM_LPSS) +=3D pwm-lpss.o obj-$(CONFIG_PWM_LPSS_PCI) +=3D pwm-lpss-pci.o obj-$(CONFIG_PWM_LPSS_PLATFORM) +=3D pwm-lpss-platform.o +obj-$(CONFIG_PWM_MAX7360) +=3D pwm-max7360.o obj-$(CONFIG_PWM_MC33XS2410) +=3D pwm-mc33xs2410.o obj-$(CONFIG_PWM_MEDIATEK) +=3D pwm-mediatek.o obj-$(CONFIG_PWM_MESON) +=3D pwm-meson.o diff --git a/drivers/pwm/pwm-max7360.c b/drivers/pwm/pwm-max7360.c new file mode 100644 index 000000000000..e3743c8dd20f --- /dev/null +++ b/drivers/pwm/pwm-max7360.c @@ -0,0 +1,206 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2025 Bootlin + * + * Author: Kamel BOUHARA + * Author: Mathieu Dubois-Briand + * + * PWM functionality of the MAX7360 multi-function device. + * https://www.analog.com/media/en/technical-documentation/data-sheets/MAX= 7360.pdf + * + * 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 beg= inning + * of the next cycle. + * - When disabled, the output is put in Hi-Z immediately. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX7360_NUM_PWMS 8 +#define MAX7360_PWM_MAX 255 +#define MAX7360_PWM_STEPS 256 +#define MAX7360_PWM_PERIOD_NS (2 * NSEC_PER_MSEC) + +struct max7360_pwm_waveform { + u8 duty_steps; + bool enabled; +}; + +static int max7360_pwm_request(struct pwm_chip *chip, struct pwm_device *p= wm) +{ + struct regmap *regmap =3D pwmchip_get_drvdata(chip); + + /* + * Make sure we use the individual PWM configuration register and not + * the global one. + * We never need to use the global one, so there is no need to revert + * that in the .free() callback. + */ + return regmap_write_bits(regmap, MAX7360_REG_PWMCFG(pwm->hwpwm), + MAX7360_PORT_CFG_COMMON_PWM, 0); +} + +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 =3D _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. + * Values from 0 to 254 as duty_steps will provide duty cycles of 0/256 + * to 254/256, while value 255 will provide a duty cycle of 100%. + */ + if (wf->duty_length_ns >=3D MAX7360_PWM_PERIOD_NS) { + duty_steps =3D MAX7360_PWM_MAX; + } else { + duty_steps =3D (u32)wf->duty_length_ns * MAX7360_PWM_STEPS / MAX7360_PWM= _PERIOD_NS; + if (duty_steps =3D=3D MAX7360_PWM_MAX) + duty_steps =3D MAX7360_PWM_MAX - 1; + } + + wfhw->duty_steps =3D min(MAX7360_PWM_MAX, duty_steps); + wfhw->enabled =3D !!wf->period_length_ns; + + 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 =3D _wfhw; + + wf->period_length_ns =3D wfhw->enabled ? MAX7360_PWM_PERIOD_NS : 0; + wf->duty_offset_ns =3D 0; + + if (wfhw->enabled) { + if (wfhw->duty_steps =3D=3D MAX7360_PWM_MAX) + wf->duty_length_ns =3D MAX7360_PWM_PERIOD_NS; + else + wf->duty_length_ns =3D DIV_ROUND_UP(wfhw->duty_steps * MAX7360_PWM_PERI= OD_NS, + MAX7360_PWM_STEPS); + } else { + wf->duty_length_ns =3D 0; + } + + return 0; +} + +static int max7360_pwm_write_waveform(struct pwm_chip *chip, + struct pwm_device *pwm, + const void *_wfhw) +{ + struct regmap *regmap =3D pwmchip_get_drvdata(chip); + const struct max7360_pwm_waveform *wfhw =3D _wfhw; + unsigned int val; + int ret; + + if (wfhw->enabled) { + ret =3D regmap_write(regmap, MAX7360_REG_PWM(pwm->hwpwm), wfhw->duty_ste= ps); + if (ret) + return ret; + } + + val =3D wfhw->enabled ? BIT(pwm->hwpwm) : 0; + return regmap_write_bits(regmap, MAX7360_REG_GPIOCTRL, BIT(pwm->hwpwm), v= al); +} + +static int max7360_pwm_read_waveform(struct pwm_chip *chip, + struct pwm_device *pwm, + void *_wfhw) +{ + struct regmap *regmap =3D pwmchip_get_drvdata(chip); + struct max7360_pwm_waveform *wfhw =3D _wfhw; + unsigned int val; + int ret; + + ret =3D regmap_read(regmap, MAX7360_REG_GPIOCTRL, &val); + if (ret) + return ret; + + if (val & BIT(pwm->hwpwm)) { + wfhw->enabled =3D true; + ret =3D regmap_read(regmap, MAX7360_REG_PWM(pwm->hwpwm), &val); + if (ret) + return ret; + + wfhw->duty_steps =3D val; + } else { + wfhw->enabled =3D false; + wfhw->duty_steps =3D 0; + } + + return 0; +} + +static const struct pwm_ops max7360_pwm_ops =3D { + .request =3D max7360_pwm_request, + .round_waveform_tohw =3D max7360_pwm_round_waveform_tohw, + .round_waveform_fromhw =3D max7360_pwm_round_waveform_fromhw, + .read_waveform =3D max7360_pwm_read_waveform, + .write_waveform =3D max7360_pwm_write_waveform, +}; + +static int max7360_pwm_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct pwm_chip *chip; + struct regmap *regmap; + int ret; + + regmap =3D dev_get_regmap(dev->parent, NULL); + if (!regmap) + return dev_err_probe(dev, -ENODEV, "Could not get parent regmap\n"); + + /* + * This MFD sub-device does not have any associated device tree node: + * properties are stored in the device node of the parent (MFD) device + * and this same node is used in phandles of client devices. + * Reuse this device tree node here, as otherwise the PWM subsystem + * would be confused by this topology. + */ + device_set_of_node_from_dev(dev, dev->parent); + + chip =3D devm_pwmchip_alloc(dev, MAX7360_NUM_PWMS, 0); + if (IS_ERR(chip)) + return PTR_ERR(chip); + chip->ops =3D &max7360_pwm_ops; + + pwmchip_set_drvdata(chip, regmap); + + ret =3D devm_pwmchip_add(dev, chip); + if (ret) + return dev_err_probe(dev, ret, "Failed to add PWM chip\n"); + + return 0; +} + +static struct platform_driver max7360_pwm_driver =3D { + .driver =3D { + .name =3D "max7360-pwm", + .probe_type =3D PROBE_PREFER_ASYNCHRONOUS, + }, + .probe =3D 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"); --=20 2.39.5 From nobody Mon Oct 6 10:17:35 2025 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A9D9927CCE2; Tue, 22 Jul 2025 16:24:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201452; cv=none; b=La8ZI2+uB8zl6nSxsj0rb8vaqKpx6xWabD1HxoLmn3N7p2Ms745Sw+fAMgQOeimOsv8ObFCgplwF6YOR/OAAa6P9CXk1R+rO3DUYdy5NDQ6RmOkblMfGavGsdWMIuhwh8jAHl3o4l8Pnl7bEUHjfyTKau1ztpHCptbNRUDDPl+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201452; c=relaxed/simple; bh=IUYTqjI5pTHjU9ANib2167NJnXt6BqBtzsrS6ngudfE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iwXrpYSdiDRm68fV73g+tcjcOr9hjrrUjNk4nRLwRGP/ceK5q23Ls4uudPYjlofLQmB0KBDPgMA9deTc0vcGOgj4hJxFiGp+BA3XVwsE5572XQsm8FquDG0Z3Fi3A8UhhvHvc23g+KJ+3XP73eNIa6OoTUfX2GqI0Rtw2eY4AMY= 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=nosZA0Rl; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="nosZA0Rl" Received: by mail.gandi.net (Postfix) with ESMTPSA id E1664442C1; Tue, 22 Jul 2025 16:24:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1753201447; 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=RO95m2cyHs6sn8Uc+QCWljQAZhTJcGxJ9NM13w191Vg=; b=nosZA0Rl9sqnlQWnG3PTXU1gk2GXqtktw/7ISgxKXvxtlntCKXuwAwku8L7vcxt734/5a1 a28UEDQso9/WTs5LGh8mBPhtRiGvBEAJCLJT6PPCVOUl5rwSwkJUq0decwqIXnZNYKVwW8 /hv6tv5qYkbDvB2ckY+vdAqqmmey7KYJijT0mLMHLWoTFJpR5pTSd9t/iGiC5eCG8nMEa9 FMvBBj2EV6i3uieiqSM0e7rrJON2ySKxQEoLffEm6eE1Iw5Gxog9KdtoSd0OlezfkBq65l SxjEk2WfSFUyE9yltRrD/gZKzxWmKIaWVR8Mb/wxQSrFf4zyJwtqLWZluzLbFg== From: Mathieu Dubois-Briand Date: Tue, 22 Jul 2025 18:23:49 +0200 Subject: [PATCH v12 05/10] gpio: regmap: Allow to allocate regmap-irq device Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250722-mdb-max7360-support-v12-5-3747721a8d02@bootlin.com> References: <20250722-mdb-max7360-support-v12-0-3747721a8d02@bootlin.com> In-Reply-To: <20250722-mdb-max7360-support-v12-0-3747721a8d02@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=B6nig?= , 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=A9gory_Clement?= , Thomas Petazzoni , Mathieu Dubois-Briand , Andy Shevchenko , Bartosz Golaszewski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1753201440; l=3757; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=IUYTqjI5pTHjU9ANib2167NJnXt6BqBtzsrS6ngudfE=; b=eAJfqdGNDnPxmUktleckMRG4IeZIp3A0W+n30VQTsOPsW3cToWj2CEOYVSA8YlyAjlcSrfG7h HUgp8q2Y9hoD1F7eim6FxhjxTGdTG27koWdPYry0ZXqqWtaptQjafOA 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: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejheefiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnheptdfhgeetvddvheejieehheehueetjeelkedtfeehhefgfeeglefhteegtddthfetnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdehpdhrtghpthhtoheplhhinhhushdrfigrlhhlvghijheslhhinhgrrhhordhorhhgpdhrtghpthhtohepmhifrghllhgvsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhihidrshhhv ghvtghhvghnkhhosehinhhtvghlrdgtohhmpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegsrghrthhoshiirdhgohhlrghsiigvfihskhhisehlihhnrghrohdrohhrghdprhgtphhtthhopehlihhnuhigqdhpfihmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptghonhhorhdoughtsehkvghrnhgvlhdrohhrgh X-GND-Sasl: mathieu.dubois-briand@bootlin.com GPIO controller often have support for IRQ: allow to easily allocate both gpio-regmap and regmap-irq in one operation. Reviewed-by: Andy Shevchenko Acked-by: Bartosz Golaszewski Signed-off-by: Mathieu Dubois-Briand --- drivers/gpio/gpio-regmap.c | 29 +++++++++++++++++++++++++++-- include/linux/gpio/regmap.h | 11 +++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 87c4225784cf..039dbe70d009 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -32,6 +32,11 @@ struct gpio_regmap { unsigned int reg_dir_in_base; unsigned int reg_dir_out_base; =20 +#ifdef CONFIG_REGMAP_IRQ + int regmap_irq_line; + struct regmap_irq_chip_data *irq_chip_data; +#endif + int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base, unsigned int offset, unsigned int *reg, unsigned int *mask); @@ -215,6 +220,7 @@ EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata); */ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *= config) { + struct irq_domain *irq_domain; struct gpio_regmap *gpio; struct gpio_chip *chip; int ret; @@ -295,8 +301,22 @@ struct gpio_regmap *gpio_regmap_register(const struct = gpio_regmap_config *config if (ret < 0) goto err_free_gpio; =20 - if (config->irq_domain) { - ret =3D gpiochip_irqchip_add_domain(chip, config->irq_domain); +#ifdef CONFIG_REGMAP_IRQ + if (config->regmap_irq_chip) { + gpio->regmap_irq_line =3D config->regmap_irq_line; + ret =3D regmap_add_irq_chip_fwnode(dev_fwnode(config->parent), config->r= egmap, + config->regmap_irq_line, config->regmap_irq_flags, + 0, config->regmap_irq_chip, &gpio->irq_chip_data); + if (ret) + goto err_free_gpio; + + irq_domain =3D regmap_irq_get_domain(gpio->irq_chip_data); + } else +#endif + irq_domain =3D config->irq_domain; + + if (irq_domain) { + ret =3D gpiochip_irqchip_add_domain(chip, irq_domain); if (ret) goto err_remove_gpiochip; } @@ -317,6 +337,11 @@ EXPORT_SYMBOL_GPL(gpio_regmap_register); */ void gpio_regmap_unregister(struct gpio_regmap *gpio) { +#ifdef CONFIG_REGMAP_IRQ + if (gpio->irq_chip_data) + regmap_del_irq_chip(gpio->regmap_irq_line, gpio->irq_chip_data); +#endif + gpiochip_remove(&gpio->gpio_chip); kfree(gpio); } diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h index c722c67668c6..19b52ac03a5d 100644 --- a/include/linux/gpio/regmap.h +++ b/include/linux/gpio/regmap.h @@ -40,6 +40,11 @@ struct regmap; * @drvdata: (Optional) Pointer to driver specific data which is * not used by gpio-remap but is provided "as is" to the * driver callback(s). + * @regmap_irq_chip: (Optional) Pointer on an regmap_irq_chip structure. If + * set, a regmap-irq device will be created and the IRQ + * domain will be set accordingly. + * @regmap_irq_line (Optional) The IRQ the device uses to signal interrupt= s. + * @regmap_irq_flags (Optional) The IRQF_ flags to use for the interrupt. * * The ->reg_mask_xlate translates a given base address and GPIO offset to * register and mask pair. The base address is one of the given register @@ -78,6 +83,12 @@ struct gpio_regmap_config { int ngpio_per_reg; struct irq_domain *irq_domain; =20 +#ifdef CONFIG_REGMAP_IRQ + struct regmap_irq_chip *regmap_irq_chip; + int regmap_irq_line; + unsigned long regmap_irq_flags; +#endif + int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base, unsigned int offset, unsigned int *reg, unsigned int *mask); --=20 2.39.5 From nobody Mon Oct 6 10:17:35 2025 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6DEDF27E05F; Tue, 22 Jul 2025 16:24:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201452; cv=none; b=s4QkL6d476/s3IrwFzaDVtExlhYJJPfjiBptzohiiiNtaZ32rn1XioqwZWx4Tlez6tkrfkRkXvSb3u62gQxYQUr4FYxGFS26Lh2IeXHFY1zfvWvvpzUacxZUpEOLmm1Eq12S6H37Kpvk4ulMLeVAB3OcyWgkjbqdcL5lmkU5otM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201452; c=relaxed/simple; bh=zir2OPwyW4bBN24qymo8eRzifRgx80iFtJEIr1HVw9E=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qlnUgo+N1Cm/qTZam/zv+lyFZ5dEr4NNG9/ggJPrrt4zqmWD6bmURxzpl84UZALA2MUAQQ6n5uk/s71c2yWm82ylXrzOksREJkJ3x5jgZR9GY7DGrqZ0CCFlisVb+9BWog/dqBXQZJCKbTIP2qS7VB015ZzhDln/V1wAmUeFzfA= 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=B9P0vvh1; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="B9P0vvh1" Received: by mail.gandi.net (Postfix) with ESMTPSA id 0F44D431FC; Tue, 22 Jul 2025 16:24:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1753201449; 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=IrI+eqYF1HchsNKCg9CghNontX5ta0tdSFqHpYdIKuY=; b=B9P0vvh1JN0tREMQdIDgnHWDgZ5o5WPa5Dk/v+62O98NwNOMC59QYJHLNBTAQCXyZYg8wn sE0YZUySuj9ybiBJ5OqRliK6DBQmWS5KSmwAYxRE4eB8WskiBrha4knHkQjsoAauE59M4A zfpzmtJhp67/pZwchy44VaLeb0GsVrHDmt+BgHy71vbtLYnmq/eznkj9+V5hCvQtvZluOy gXwmPPdzOkEsAlyKx6Fw1lOVV2BRAb11CFy1nK/Pez6U/VWzlS34YWNpAukZ+bi8qfmujU 8sXN5W18yxEWrl6UkY9lNgMoczizV+ArMJJCEi1R1Adf2tFlj4qtqVvI1f6BGw== From: Mathieu Dubois-Briand Date: Tue, 22 Jul 2025 18:23:50 +0200 Subject: [PATCH v12 06/10] gpio: regmap: Allow to provide init_valid_mask callback Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250722-mdb-max7360-support-v12-6-3747721a8d02@bootlin.com> References: <20250722-mdb-max7360-support-v12-0-3747721a8d02@bootlin.com> In-Reply-To: <20250722-mdb-max7360-support-v12-0-3747721a8d02@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=B6nig?= , 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=A9gory_Clement?= , Thomas Petazzoni , Mathieu Dubois-Briand , Andy Shevchenko , Bartosz Golaszewski X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1753201440; l=2233; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=zir2OPwyW4bBN24qymo8eRzifRgx80iFtJEIr1HVw9E=; b=fYk/ei09FBSrDnaUL/v/JkTZNZlp0TH+KmYaV9Yg5Mzvjlg/uf1rTs8clo/IeoYLbivOVsVHB kpPZ2YES64eBZ/iusMuWpoZcMiAxXWw0D7HfXczF6vB9eQdN6aU56nL 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: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejheefiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnheptdfhgeetvddvheejieehheehueetjeelkedtfeehhefgfeeglefhteegtddthfetnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdehpdhrtghpthhtoheplhhinhhushdrfigrlhhlvghijheslhhinhgrrhhordhorhhgpdhrtghpthhtohepmhifrghllhgvsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhihidrshhhv ghvtghhvghnkhhosehinhhtvghlrdgtohhmpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegsrghrthhoshiirdhgohhlrghsiigvfihskhhisehlihhnrghrohdrohhrghdprhgtphhtthhopehlihhnuhigqdhpfihmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptghonhhorhdoughtsehkvghrnhgvlhdrohhrgh X-GND-Sasl: mathieu.dubois-briand@bootlin.com Allows to populate the gpio_regmap_config structure with init_valid_mask() callback to set on the final gpio_chip structure. Reviewed-by: Michael Walle Reviewed-by: Andy Shevchenko Reviewed-by: Linus Walleij Reviewed-by: Bartosz Golaszewski Signed-off-by: Mathieu Dubois-Briand --- drivers/gpio/gpio-regmap.c | 1 + include/linux/gpio/regmap.h | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 039dbe70d009..cf1413fa950d 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -261,6 +261,7 @@ struct gpio_regmap *gpio_regmap_register(const struct g= pio_regmap_config *config chip->names =3D config->names; chip->label =3D config->label ?: dev_name(config->parent); chip->can_sleep =3D regmap_might_sleep(config->regmap); + chip->init_valid_mask =3D config->init_valid_mask; =20 chip->request =3D gpiochip_generic_request; chip->free =3D gpiochip_generic_free; diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h index 19b52ac03a5d..622a2939ebe0 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; =20 @@ -40,6 +41,8 @@ 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). + * @init_valid_mask: (Optional) Routine to initialize @valid_mask, to be u= sed + * if not all GPIOs are valid. * @regmap_irq_chip: (Optional) Pointer on an regmap_irq_chip structure. If * set, a regmap-irq device will be created and the IRQ * domain will be set accordingly. @@ -93,6 +96,10 @@ struct gpio_regmap_config { unsigned int offset, unsigned int *reg, unsigned int *mask); =20 + int (*init_valid_mask)(struct gpio_chip *gc, + unsigned long *valid_mask, + unsigned int ngpios); + void *drvdata; }; =20 --=20 2.39.5 From nobody Mon Oct 6 10:17:35 2025 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5ABD27EC7C; Tue, 22 Jul 2025 16:24:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201454; cv=none; b=X288n0/92yDghgc4oROhhTdVSf+SODZ8jNcHPXmDXL3LRutS6QdH3NNPuwkKWjrVp6xKwcvDaW4Uvd4q8dV5XZkWNuxzSP+cyPOLSK9aV6jgDlY1n4kZxALe/YKT6dwbfwszUXiUwSTcj4UW6m/cV2R8HNs4jEYHCvAN045bKds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201454; c=relaxed/simple; bh=3iwJbYUR/LAxOGUhS1zGPT1t58CykfoVPrO/zbv3qts=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B5ooTNeBeu7jaYGqHSHKA6nzUchGiAkuUFxEQ32DFG69F/89gHz/1hpIImhLTQ86UNknuzmqQZqee5xBo64bb91EKLciwOyNh+37jyulnsAWI6BIR7rzM/0GqnjGMM5BjNFSBroah3EoiK8g88Zz6rn+DwUHm3TsNc9EnH8a4YA= 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=H1mWjNso; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="H1mWjNso" Received: by mail.gandi.net (Postfix) with ESMTPSA id 307B944202; Tue, 22 Jul 2025 16:24:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1753201450; 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=2aXGr3pUpsPcWEtHenI7ncwYTSbvgnEKOTBu0I55o8U=; b=H1mWjNsoSF3r6UHwjohZLb5yVwrl1A+Glw7lwqGT3X+zoDtHrb8Dj+BSQkqNkNcTK3LAHw FjIhWh+pV/Vcbzr9gfRb/wJhTTyeVtzAIoj2XUFnIlOx88Cu5AWskiERdWkLNIIA/TcQYt IzjcgWR7aNy6T3KgXnaWSExzLhol/dd+kvno7wH5sg3/KvXxDMGYevXifs+7rsA4CFsCpr Dvvr/KQZ58T9pGHorZH/M8DVv8mk7VPhwA5H3zkPbhO8qgyFQb4SgsOkTO2VyWtWdulDWn bc8z1F2b48w5a6K3fUAwNCg2L3NpNtrdSFMBJ5RkFuMmqFfQNtuKtZyeGxTQiA== From: Mathieu Dubois-Briand Date: Tue, 22 Jul 2025 18:23:51 +0200 Subject: [PATCH v12 07/10] gpio: max7360: Add MAX7360 gpio support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250722-mdb-max7360-support-v12-7-3747721a8d02@bootlin.com> References: <20250722-mdb-max7360-support-v12-0-3747721a8d02@bootlin.com> In-Reply-To: <20250722-mdb-max7360-support-v12-0-3747721a8d02@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=B6nig?= , 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=A9gory_Clement?= , Thomas Petazzoni , Mathieu Dubois-Briand , Bartosz Golaszewski , Andy Shevchenko X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1753201440; l=10280; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=3iwJbYUR/LAxOGUhS1zGPT1t58CykfoVPrO/zbv3qts=; b=9lh0eLRAGwtqXphtBNBV8j4BxJjEDZziqUpGTFGyesG1dLDl5OMxY6TZX/bORZAYal/f04Jre 8rhApO2eA/YAuG7nu8j7Bx6vowXJhd7M4n1BwJ2X920iy6rNDX9XgLZ 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: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejheefiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnheptdfhgeetvddvheejieehheehueetjeelkedtfeehhefgfeeglefhteegtddthfetnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpedunecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdehpdhrtghpthhtoheplhhinhhushdrfigrlhhlvghijheslhhinhgrrhhordhorhhgpdhrtghpthhtohepmhifrghllhgvsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhihidrshhhv ghvtghhvghnkhhosehinhhtvghlrdgtohhmpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegsrghrthhoshiirdhgohhlrghsiigvfihskhhisehlihhnrghrohdrohhrghdprhgtphhtthhopehlihhnuhigqdhpfihmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptghonhhorhdoughtsehkvghrnhgvlhdrohhrgh 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 Acked-by: Bartosz Golaszewski Reviewed-by: Andy Shevchenko Signed-off-by: Mathieu Dubois-Briand --- drivers/gpio/Kconfig | 12 +++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-max7360.c | 257 ++++++++++++++++++++++++++++++++++++++++= ++++ 3 files changed, 270 insertions(+) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 44f922e10db2..39c3ce6145f3 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1470,6 +1470,18 @@ config GPIO_MADERA help Support for GPIOs on Cirrus Logic Madera class codecs. =20 +config GPIO_MAX7360 + tristate "MAX7360 GPIO support" + depends on MFD_MAX7360 + select GPIO_REGMAP + select REGMAP_IRQ + 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 88dedd298256..360a47b2793d 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -105,6 +105,7 @@ obj-$(CONFIG_GPIO_MAX7300) +=3D gpio-max7300.o obj-$(CONFIG_GPIO_MAX7301) +=3D gpio-max7301.o obj-$(CONFIG_GPIO_MAX730X) +=3D gpio-max730x.o obj-$(CONFIG_GPIO_MAX732X) +=3D gpio-max732x.o +obj-$(CONFIG_GPIO_MAX7360) +=3D gpio-max7360.o obj-$(CONFIG_GPIO_MAX77620) +=3D gpio-max77620.o obj-$(CONFIG_GPIO_MAX77650) +=3D gpio-max77650.o obj-$(CONFIG_GPIO_MAX77759) +=3D gpio-max77759.o diff --git a/drivers/gpio/gpio-max7360.c b/drivers/gpio/gpio-max7360.c new file mode 100644 index 000000000000..db92a43776a9 --- /dev/null +++ b/drivers/gpio/gpio-max7360.c @@ -0,0 +1,257 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2025 Bootlin + * + * Author: Kamel BOUHARA + * Author: Mathieu Dubois-Briand + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX7360_GPIO_PORT 1 +#define MAX7360_GPIO_COL 2 + +struct max7360_gpio_plat_data { + unsigned int function; +}; + +static struct max7360_gpio_plat_data max7360_gpio_port_plat =3D { .functio= n =3D MAX7360_GPIO_PORT }; +static struct max7360_gpio_plat_data max7360_gpio_col_plat =3D { .function= =3D MAX7360_GPIO_COL }; + +static int max7360_get_available_gpos(struct device *dev, unsigned int *av= ailable_gpios) +{ + u32 columns; + int ret; + + ret =3D device_property_read_u32(dev->parent, "keypad,num-columns", &colu= mns); + if (ret) { + dev_err(dev, "Failed to read columns count\n"); + return ret; + } + + *available_gpios =3D min(MAX7360_MAX_GPO, MAX7360_MAX_KEY_COLS - columns); + + return 0; +} + +static int max7360_gpo_init_valid_mask(struct gpio_chip *gc, + unsigned long *valid_mask, + unsigned int ngpios) +{ + unsigned int available_gpios; + int ret; + + ret =3D max7360_get_available_gpos(gc->parent, &available_gpios); + if (ret) + return ret; + + bitmap_clear(valid_mask, 0, MAX7360_MAX_KEY_COLS - available_gpios); + + return 0; +} + +static int max7360_set_gpos_count(struct device *dev, struct regmap *regma= p) +{ + /* + * MAX7360 COL0 to COL7 pins can be used either as keypad columns, + * general purpose output or a mix of both. + * By default, all pins are used as keypad, here we update this + * configuration to allow to use some of them as GPIOs. + */ + unsigned int available_gpios; + unsigned int val; + int ret; + + ret =3D max7360_get_available_gpos(dev, &available_gpios); + if (ret) + return ret; + + /* + * Configure which GPIOs will be used for keypad. + * MAX7360_REG_DEBOUNCE contains configuration both for keypad debounce + * timings and gpos/keypad columns repartition. Only the later is + * modified here. + */ + val =3D FIELD_PREP(MAX7360_PORTS, available_gpios); + ret =3D regmap_write_bits(regmap, MAX7360_REG_DEBOUNCE, MAX7360_PORTS, va= l); + if (ret) + dev_err(dev, "Failed to write max7360 columns/gpos configuration"); + + return ret; +} + +static int max7360_gpio_reg_mask_xlate(struct gpio_regmap *gpio, + unsigned int base, unsigned int offset, + unsigned int *reg, unsigned int *mask) +{ + if (base =3D=3D MAX7360_REG_PWMBASE) { + /* + * GPIO output is using PWM duty cycle registers: one register + * per line, with value being either 0 or 255. + */ + *reg =3D base + offset; + *mask =3D GENMASK(7, 0); + } else { + *reg =3D base; + *mask =3D BIT(offset); + } + + return 0; +} + +static const struct regmap_irq max7360_regmap_irqs[MAX7360_MAX_GPIO] =3D { + 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 =3D irq_drv_data; + int ret; + + for (unsigned int i =3D 0; i < MAX7360_MAX_GPIO; i++) { + ret =3D regmap_assign_bits(regmap, MAX7360_REG_PWMCFG(i), + MAX7360_PORT_CFG_INTERRUPT_MASK, mask_buf & BIT(i)); + if (ret) + return ret; + } + + return 0; +} + +static int max7360_gpio_probe(struct platform_device *pdev) +{ + const struct max7360_gpio_plat_data *plat_data; + struct gpio_regmap_config gpio_config =3D { }; + struct regmap_irq_chip *irq_chip; + struct device *dev =3D &pdev->dev; + struct regmap *regmap; + unsigned int outconf; + int ret; + + regmap =3D dev_get_regmap(dev->parent, NULL); + if (!regmap) + return dev_err_probe(dev, -ENODEV, "could not get parent regmap\n"); + + plat_data =3D device_get_match_data(dev); + if (plat_data->function =3D=3D MAX7360_GPIO_PORT) { + if (device_property_read_bool(dev, "interrupt-controller")) { + /* + * Port GPIOs with interrupt-controller property: add IRQ + * controller. + */ + gpio_config.regmap_irq_flags =3D IRQF_ONESHOT | IRQF_SHARED; + gpio_config.regmap_irq_line =3D + fwnode_irq_get_byname(dev_fwnode(dev->parent), "inti"); + if (gpio_config.regmap_irq_line < 0) + return dev_err_probe(dev, gpio_config.regmap_irq_line, + "Failed to get IRQ\n"); + + /* Create custom IRQ configuration. */ + irq_chip =3D devm_kzalloc(dev, sizeof(*irq_chip), GFP_KERNEL); + gpio_config.regmap_irq_chip =3D irq_chip; + if (!irq_chip) + return -ENOMEM; + + irq_chip->name =3D dev_name(dev); + irq_chip->status_base =3D MAX7360_REG_GPIOIN; + irq_chip->status_is_level =3D true; + irq_chip->num_regs =3D 1; + irq_chip->num_irqs =3D MAX7360_MAX_GPIO; + irq_chip->irqs =3D max7360_regmap_irqs; + irq_chip->handle_mask_sync =3D max7360_handle_mask_sync; + irq_chip->irq_drv_data =3D regmap; + + for (unsigned int i =3D 0; i < MAX7360_MAX_GPIO; i++) { + ret =3D regmap_write_bits(regmap, MAX7360_REG_PWMCFG(i), + MAX7360_PORT_CFG_INTERRUPT_EDGES, + MAX7360_PORT_CFG_INTERRUPT_EDGES); + if (ret) + return dev_err_probe(dev, ret, + "Failed to enable interrupts\n"); + } + } + + /* + * Port GPIOs: set output mode configuration (constant-current or not). + * This property is optional. + */ + ret =3D device_property_read_u32(dev, "maxim,constant-current-disable", = &outconf); + if (!ret) { + ret =3D regmap_write(regmap, MAX7360_REG_GPIOOUTM, outconf); + if (ret) + return dev_err_probe(dev, ret, + "Failed to set constant-current configuration\n"); + } + } + + /* Add gpio device. */ + gpio_config.parent =3D dev; + gpio_config.regmap =3D regmap; + if (plat_data->function =3D=3D MAX7360_GPIO_PORT) { + gpio_config.ngpio =3D MAX7360_MAX_GPIO; + gpio_config.reg_dat_base =3D GPIO_REGMAP_ADDR(MAX7360_REG_GPIOIN); + gpio_config.reg_set_base =3D GPIO_REGMAP_ADDR(MAX7360_REG_PWMBASE); + gpio_config.reg_dir_out_base =3D GPIO_REGMAP_ADDR(MAX7360_REG_GPIOCTRL); + gpio_config.ngpio_per_reg =3D MAX7360_MAX_GPIO; + gpio_config.reg_mask_xlate =3D max7360_gpio_reg_mask_xlate; + } else { + ret =3D max7360_set_gpos_count(dev, regmap); + if (ret) + return dev_err_probe(dev, ret, "Failed to set GPOS pin count\n"); + + gpio_config.reg_set_base =3D GPIO_REGMAP_ADDR(MAX7360_REG_PORTS); + gpio_config.ngpio =3D MAX7360_MAX_KEY_COLS; + gpio_config.init_valid_mask =3D max7360_gpo_init_valid_mask; + } + + return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(dev, &gpio_config)); +} + +static const struct of_device_id max7360_gpio_of_match[] =3D { + { + .compatible =3D "maxim,max7360-gpo", + .data =3D &max7360_gpio_col_plat + }, { + .compatible =3D "maxim,max7360-gpio", + .data =3D &max7360_gpio_port_plat + }, { + } +}; +MODULE_DEVICE_TABLE(of, max7360_gpio_of_match); + +static struct platform_driver max7360_gpio_driver =3D { + .driver =3D { + .name =3D "max7360-gpio", + .of_match_table =3D max7360_gpio_of_match, + }, + .probe =3D 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"); --=20 2.39.5 From nobody Mon Oct 6 10:17:35 2025 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE5F427F18B; Tue, 22 Jul 2025 16:24:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201455; cv=none; b=B3+JWhvKks/gYyjJsDiYbOHb/eApddt9SlWn2rafzqTkV+nim7XLGRTjv0fajXUx2trGHExaLMpYoZTh9miz6ndU0f3fHLGxF5cEwaf+SKeeg0Feaikn5eVINFJrTCq1LUlPJONYvywFlBU9rPPcWMkWWwr+WbUj0wh1oX5O6kw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201455; c=relaxed/simple; bh=jGd22I0zQbaHVM0YJnF+U5fXMlDRM/CPnCHXIHVXDQs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=W3WtBhxi8qV7hg3JPW4Sgcx9dRvGGY/WrYrxa1cNXWvZeTHLNaEFGPso2sVgAnxr4ehHsoFunE90/114o/eovG1yaUMyaKlQWQZLWVNYE0DqKWmYx41FZYeIKgZWpvcnsxOXTr7VUimjzUsOdpBJMq1u+lO6MkkpOw2v+2fWiIk= 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=GjBLkLRE; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="GjBLkLRE" Received: by mail.gandi.net (Postfix) with ESMTPSA id 4CF4F442BB; Tue, 22 Jul 2025 16:24:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1753201451; 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=2b/5U8/b0csXR4OquzQrnhV9r9vuO/TcUum6zPaVKOA=; b=GjBLkLRENHlNK0PM8caZW9xy01pSxgBVoDrr2jOQmQk5I8QT4XuV82kE0HFTlCjbxlYOSC f3pQdMrtAlSmpn4+izsNX4FB+SzAvaKFUVqPH2CSsmGCoF76dLLgOKi13I2QlqrtXK8MMF 9SzLdgQnk75EvP1w/viRoD3wf7Tw4L0t0vCPz7pH3C2DZebb5puYZWlzNpS2GIE8JX1vv3 XIzGuO2lxUHY4Nv2RLgRbuf9cFLchjvj77uOjFhbiIbRI2ZrHtOGr23LSJM3jawsfovJyS CPAH34H2X6VxiusN4JJwk6vX9G2Oo8TGlX8+UN1yxgbM7bz22WAeo59KQyuArA== From: Mathieu Dubois-Briand Date: Tue, 22 Jul 2025 18:23:52 +0200 Subject: [PATCH v12 08/10] input: keyboard: Add support for MAX7360 keypad Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250722-mdb-max7360-support-v12-8-3747721a8d02@bootlin.com> References: <20250722-mdb-max7360-support-v12-0-3747721a8d02@bootlin.com> In-Reply-To: <20250722-mdb-max7360-support-v12-0-3747721a8d02@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=B6nig?= , 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=A9gory_Clement?= , Thomas Petazzoni , Mathieu Dubois-Briand X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1753201440; l=11685; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=jGd22I0zQbaHVM0YJnF+U5fXMlDRM/CPnCHXIHVXDQs=; b=gNiWNjRb11kiUf6e8EIaEy68zUPW2lp5qos+9MzANPOlDPFNbYv2aB9/uPFDKQdqUtaSjK4Bt pnwxoW667OMB/YBOUMouEWJVQy3m/V/RgGYAOisVizqgLete5W9WUy7 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: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejheefiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnheptdfhgeetvddvheejieehheehueetjeelkedtfeehhefgfeeglefhteegtddthfetnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpeehnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdefpdhrtghpthhtoheplhhinhhushdrfigrlhhlvghijheslhhinhgrrhhordhorhhgpdhrtghpthhtohepmhifrghllhgvsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhihidrshhhv ghvtghhvghnkhhosehinhhtvghlrdgtohhmpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpfihmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptghonhhorhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlvggvsehkvghrnhgvlhdrohhrgh 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. Acked-by: Dmitry Torokhov Signed-off-by: Mathieu Dubois-Briand --- drivers/input/keyboard/Kconfig | 12 ++ drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/max7360-keypad.c | 308 ++++++++++++++++++++++++++++= ++++ 3 files changed, 321 insertions(+) diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig index 721ab69e84ac..93b5cccf6892 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. =20 +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/Makef= ile index 1e0721c30709..b49d32d4003d 100644 --- a/drivers/input/keyboard/Makefile +++ b/drivers/input/keyboard/Makefile @@ -42,6 +42,7 @@ obj-$(CONFIG_KEYBOARD_LPC32XX) +=3D lpc32xx-keys.o obj-$(CONFIG_KEYBOARD_MAPLE) +=3D maple_keyb.o obj-$(CONFIG_KEYBOARD_MATRIX) +=3D matrix_keypad.o obj-$(CONFIG_KEYBOARD_MAX7359) +=3D max7359_keypad.o +obj-$(CONFIG_KEYBOARD_MAX7360) +=3D max7360-keypad.o obj-$(CONFIG_KEYBOARD_MPR121) +=3D mpr121_touchkey.o obj-$(CONFIG_KEYBOARD_MT6779) +=3D mt6779-keypad.o obj-$(CONFIG_KEYBOARD_MTK_PMIC) +=3D mtk-pmic-keys.o diff --git a/drivers/input/keyboard/max7360-keypad.c b/drivers/input/keyboa= rd/max7360-keypad.c new file mode 100644 index 000000000000..503be952b0a6 --- /dev/null +++ b/drivers/input/keyboard/max7360-keypad.c @@ -0,0 +1,308 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2025 Bootlin + * + * Author: Mathieu Dubois-Briand + */ + +#include +#include +#include +#include +#include +#include +#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 =3D data; + struct device *dev =3D max7360_keypad->input->dev.parent; + unsigned int val; + unsigned int row, col; + unsigned int release; + unsigned int code; + int error; + + error =3D regmap_read(max7360_keypad->regmap, MAX7360_REG_KEYFIFO, &val); + if (error) { + dev_err(dev, "Failed to read MAX7360 FIFO"); + return IRQ_NONE; + } + + /* FIFO overflow: ignore it and get next event. */ + if (val =3D=3D MAX7360_FIFO_OVERFLOW) { + dev_warn(dev, "max7360 FIFO overflow"); + error =3D regmap_read_poll_timeout(max7360_keypad->regmap, MAX7360_REG_K= EYFIFO, + val, val !=3D MAX7360_FIFO_OVERFLOW, 0, 1000); + if (error) { + dev_err(dev, "Failed to empty MAX7360 FIFO"); + return IRQ_NONE; + } + } + + if (val =3D=3D MAX7360_FIFO_EMPTY) { + dev_dbg(dev, "Got a spurious interrupt"); + + return IRQ_NONE; + } + + row =3D FIELD_GET(MAX7360_FIFO_ROW, val); + col =3D FIELD_GET(MAX7360_FIFO_COL, val); + release =3D val & MAX7360_FIFO_RELEASE; + + code =3D MATRIX_SCAN_CODE(row, col, get_count_order(max7360_keypad->cols)= ); + + dev_dbg(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 =3D input_get_drvdata(pdev); + struct device *dev =3D max7360_keypad->input->dev.parent; + int error; + + /* Somebody is using the device: get out of sleep. */ + error =3D regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_CONFIG, + MAX7360_CFG_SLEEP, MAX7360_CFG_SLEEP); + if (error) + dev_err(dev, "Failed to write max7360 configuration: %d\n", error); + + return error; +} + +static void max7360_keypad_close(struct input_dev *pdev) +{ + struct max7360_keypad *max7360_keypad =3D input_get_drvdata(pdev); + struct device *dev =3D max7360_keypad->input->dev.parent; + int error; + + /* Nobody is using the device anymore: go to sleep. */ + error =3D regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_CONFIG, M= AX7360_CFG_SLEEP, 0); + if (error) + dev_err(dev, "Failed to write max7360 configuration: %d\n", error); +} + +static int max7360_keypad_hw_init(struct max7360_keypad *max7360_keypad) +{ + struct device *dev =3D max7360_keypad->input->dev.parent; + unsigned int val; + int error; + + val =3D max7360_keypad->debounce_ms - MAX7360_DEBOUNCE_MIN; + error =3D regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_DEBOUNCE, + MAX7360_DEBOUNCE, + FIELD_PREP(MAX7360_DEBOUNCE, val)); + if (error) + return dev_err_probe(dev, error, + "Failed to write max7360 debounce configuration\n"); + + error =3D 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(dev, error, + "Failed to write max7360 keypad interrupt configuration\n"); + + return 0; +} + +static int max7360_keypad_build_keymap(struct max7360_keypad *max7360_keyp= ad) +{ + struct input_dev *input_dev =3D max7360_keypad->input; + struct device *dev =3D input_dev->dev.parent->parent; + struct matrix_keymap_data keymap_data; + const char *propname =3D "linux,keymap"; + unsigned int max_keys; + int error; + int size; + + size =3D device_property_count_u32(dev, propname); + if (size <=3D 0) { + dev_err(dev, "missing or malformed property %s: %d\n", propname, size); + return size < 0 ? size : -EINVAL; + } + + max_keys =3D max7360_keypad->cols * max7360_keypad->rows; + if (size > max_keys) { + dev_err(dev, "%s size overflow (%d vs max %u)\n", propname, size, max_ke= ys); + return -EINVAL; + } + + u32 *keys __free(kfree) =3D kmalloc_array(size, sizeof(*keys), GFP_KERNEL= ); + if (!keys) + return -ENOMEM; + + error =3D device_property_read_u32_array(dev, propname, keys, size); + if (error) { + dev_err(dev, "failed to read %s property: %d\n", propname, error); + return error; + } + + keymap_data.keymap =3D keys; + keymap_data.keymap_size =3D size; + error =3D matrix_keypad_build_keymap(&keymap_data, NULL, + max7360_keypad->rows, max7360_keypad->cols, + max7360_keypad->keycodes, max7360_keypad->input); + if (error) + return error; + + return 0; +} + +static int max7360_keypad_parse_fw(struct device *dev, + struct max7360_keypad *max7360_keypad, + bool *autorepeat) +{ + int error; + + error =3D matrix_keypad_parse_properties(dev->parent, &max7360_keypad->ro= ws, + &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(dev, "Invalid number of columns or rows (%ux%u)\n", + max7360_keypad->cols, max7360_keypad->rows); + return -EINVAL; + } + + *autorepeat =3D device_property_read_bool(dev->parent, "autorepeat"); + + max7360_keypad->debounce_ms =3D MAX7360_DEBOUNCE_MIN; + error =3D device_property_read_u32(dev->parent, "keypad-debounce-delay-ms= ", + &max7360_keypad->debounce_ms); + if (error =3D=3D -EINVAL) { + dev_info(dev, "Using default keypad-debounce-delay-ms: %u\n", + max7360_keypad->debounce_ms); + } else if (error < 0) { + dev_err(dev, "Failed to read keypad-debounce-delay-ms property\n"); + return error; + } + + if (!in_range(max7360_keypad->debounce_ms, MAX7360_DEBOUNCE_MIN, + MAX7360_DEBOUNCE_MAX - MAX7360_DEBOUNCE_MIN + 1)) { + dev_err(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 device *dev =3D &pdev->dev; + struct input_dev *input; + struct regmap *regmap; + bool autorepeat; + int error; + int irq; + + regmap =3D dev_get_regmap(dev->parent, NULL); + if (!regmap) + return dev_err_probe(dev, -ENODEV, "Could not get parent regmap\n"); + + irq =3D fwnode_irq_get_byname(dev_fwnode(dev->parent), "intk"); + if (irq < 0) + return dev_err_probe(dev, irq, "Failed to get IRQ\n"); + + max7360_keypad =3D devm_kzalloc(dev, sizeof(*max7360_keypad), GFP_KERNEL); + if (!max7360_keypad) + return -ENOMEM; + + max7360_keypad->regmap =3D regmap; + + error =3D max7360_keypad_parse_fw(dev, max7360_keypad, &autorepeat); + if (error) + return error; + + input =3D devm_input_allocate_device(dev); + if (!input) + return -ENOMEM; + + max7360_keypad->input =3D input; + + input->id.bustype =3D BUS_I2C; + input->name =3D pdev->name; + input->open =3D max7360_keypad_open; + input->close =3D max7360_keypad_close; + + error =3D max7360_keypad_build_keymap(max7360_keypad); + if (error) + return dev_err_probe(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 =3D devm_request_threaded_irq(dev, irq, NULL, max7360_keypad_irq, + IRQF_ONESHOT, + "max7360-keypad", max7360_keypad); + if (error) + return dev_err_probe(dev, error, "Failed to register interrupt\n"); + + error =3D input_register_device(input); + if (error) + return dev_err_probe(dev, error, "Could not register input device\n"); + + error =3D max7360_keypad_hw_init(max7360_keypad); + if (error) + return dev_err_probe(dev, error, "Failed to initialize max7360 keypad\n"= ); + + device_init_wakeup(dev, true); + error =3D dev_pm_set_wake_irq(dev, irq); + if (error) + dev_warn(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); + device_init_wakeup(&pdev->dev, false); +} + +static struct platform_driver max7360_keypad_driver =3D { + .driver =3D { + .name =3D "max7360-keypad", + }, + .probe =3D max7360_keypad_probe, + .remove =3D max7360_keypad_remove, +}; +module_platform_driver(max7360_keypad_driver); + +MODULE_DESCRIPTION("MAX7360 Keypad driver"); +MODULE_AUTHOR("Mathieu Dubois-Briand "); +MODULE_LICENSE("GPL"); --=20 2.39.5 From nobody Mon Oct 6 10:17:35 2025 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7898B27FD4A; Tue, 22 Jul 2025 16:24:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201457; cv=none; b=i79eXW3A3yi9bvOC6GQEK1lJu0Hd84LqEsdVl6S7erXCrvAucWGfd2XJub+rweHRSoPA6Id7QPKvq/vP3984P58MsIMe2a9wECIUzTTDjbQzSNnA2wfulS+myO2pNlh12MDWP8T8h8nkBCaGQdvSjVEUnGGNDHcri4FTKaYDcyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201457; c=relaxed/simple; bh=ivCv2diegFAI10yvN/kIznk53Nc/V6s4C22VehNSBd4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Bckvnx0FJ5BI1/Tumyw5rj22q+eyr6aqszFhW9MPE+S7Vd2St/VVB4xwllbacO5uVk5qPga5NGqfHRLXDJPjRyh/IH1DNLP9SgOVa5t7wdVTmTTGcvo+DSkmGXiC3J52buCTTvDEOKOE2Bnt81bFLQ3WDTXouq0QQmh1ci7Y21k= 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=il8mbBqw; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="il8mbBqw" Received: by mail.gandi.net (Postfix) with ESMTPSA id 632DB442B9; Tue, 22 Jul 2025 16:24:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1753201453; 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=l3qubtbFuYPrSo/BjVwcQQS6M3xWsCf4JaEdFKScetg=; b=il8mbBqwMRoKA30LS169957IoeC/qdLg3Oq7AX3RD4zXhzXiMSIAcPyVJf4XXyEFW074mg mnOdu9tx8x1VV+eaoMpJeIpEXwFzc1XJEBXo4CIMCuQcKcFSKpPGv4AiEjK6bi5qRD8ZCT xM7bChHzCNDnyi2vXUPjgKOXPkzGcAGQy3NmUtbvN7X3Zc9UvNllj30H1kngSgCa1p+vbS AIP2lzL+4Hi0rYKvEPTvPqWtGnk6kxhlYGf+oep5c23TelzFHw5lyXMqRp20mUxJRWG6Pi vtdGPr59ODGha9ZQkcVbt82fz3KUsvohSSDlU45qX78IgrqrE/rHiRL3LK1WdA== From: Mathieu Dubois-Briand Date: Tue, 22 Jul 2025 18:23:53 +0200 Subject: [PATCH v12 09/10] input: misc: Add support for MAX7360 rotary Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250722-mdb-max7360-support-v12-9-3747721a8d02@bootlin.com> References: <20250722-mdb-max7360-support-v12-0-3747721a8d02@bootlin.com> In-Reply-To: <20250722-mdb-max7360-support-v12-0-3747721a8d02@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=B6nig?= , 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=A9gory_Clement?= , Thomas Petazzoni , Mathieu Dubois-Briand X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1753201440; l=7729; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=ivCv2diegFAI10yvN/kIznk53Nc/V6s4C22VehNSBd4=; b=O0CnSm2QFJp+hkCEqXqYv4Fcc4hrmKeeZWQp1pQfIPp/EFS5BD8LWJdviQuHtUiDRYXIzvgA1 47p6LRbqrBVDVOsHSxtnDcIiCSBc6MqIicUZt+PFzAM1TQSi1d2QhmP 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: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejheefiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnheptdfhgeetvddvheejieehheehueetjeelkedtfeehhefgfeeglefhteegtddthfetnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpeehnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdefpdhrtghpthhtoheplhhinhhushdrfigrlhhlvghijheslhhinhgrrhhordhorhhgpdhrtghpthhtohepmhifrghllhgvsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhihidrshhhv ghvtghhvghnkhhosehinhhtvghlrdgtohhmpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpfihmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptghonhhorhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlvggvsehkvghrnhgvlhdrohhrgh X-GND-Sasl: mathieu.dubois-briand@bootlin.com Add driver for Maxim Integrated MAX7360 rotary encoder controller, supporting a single rotary switch. Acked-by: Dmitry Torokhov Signed-off-by: Mathieu Dubois-Briand --- drivers/input/misc/Kconfig | 10 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/max7360-rotary.c | 192 ++++++++++++++++++++++++++++++++= ++++ 3 files changed, 203 insertions(+) diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig index f5496ca0c0d2..0bc9d121c984 100644 --- a/drivers/input/misc/Kconfig +++ b/drivers/input/misc/Kconfig @@ -230,6 +230,16 @@ config INPUT_M68K_BEEP tristate "M68k Beeper support" depends on M68K =20 +config INPUT_MAX7360_ROTARY + tristate "Maxim MAX7360 Rotary Encoder" + 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) +=3D iqs7222.o obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) +=3D keyspan_remote.o obj-$(CONFIG_INPUT_KXTJ9) +=3D kxtj9.o obj-$(CONFIG_INPUT_M68K_BEEP) +=3D m68kspkr.o +obj-$(CONFIG_INPUT_MAX7360_ROTARY) +=3D max7360-rotary.o obj-$(CONFIG_INPUT_MAX77650_ONKEY) +=3D max77650-onkey.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC) +=3D max77693-haptic.o obj-$(CONFIG_INPUT_MAX8925_ONKEY) +=3D max8925_onkey.o diff --git a/drivers/input/misc/max7360-rotary.c b/drivers/input/misc/max73= 60-rotary.c new file mode 100644 index 000000000000..385831ef34b6 --- /dev/null +++ b/drivers/input/misc/max7360-rotary.c @@ -0,0 +1,192 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright 2025 Bootlin + * + * Author: Mathieu Dubois-Briand + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MAX7360_ROTARY_DEFAULT_STEPS 24 + +struct max7360_rotary { + struct input_dev *input; + struct regmap *regmap; + unsigned int debounce_ms; + + unsigned int pos; + + u32 steps; + u32 axis; + bool relative_axis; + bool rollover; +}; + +static void max7360_rotary_report_event(struct max7360_rotary *max7360_rot= ary, int steps) +{ + if (max7360_rotary->relative_axis) { + input_report_rel(max7360_rotary->input, max7360_rotary->axis, steps); + } else { + int pos =3D max7360_rotary->pos; + int maxval =3D max7360_rotary->steps; + + /* + * Add steps to the position. + * Make sure added steps are always in ]-maxval; maxval[ + * interval, so (pos + maxval) is always >=3D 0. + * Then set back pos to the [0; maxval[ interval. + */ + pos +=3D steps % maxval; + if (max7360_rotary->rollover) + pos =3D (pos + maxval) % maxval; + else + pos =3D clamp(pos, 0, maxval - 1); + + max7360_rotary->pos =3D pos; + input_report_abs(max7360_rotary->input, max7360_rotary->axis, max7360_ro= tary->pos); + } + + input_sync(max7360_rotary->input); +} + +static irqreturn_t max7360_rotary_irq(int irq, void *data) +{ + struct max7360_rotary *max7360_rotary =3D data; + struct device *dev =3D max7360_rotary->input->dev.parent; + unsigned int val; + int error; + + error =3D regmap_read(max7360_rotary->regmap, MAX7360_REG_RTR_CNT, &val); + if (error < 0) { + dev_err(dev, "Failed to read rotary counter\n"); + return IRQ_NONE; + } + + if (val =3D=3D 0) + return IRQ_NONE; + + max7360_rotary_report_event(max7360_rotary, sign_extend32(val, 7)); + + return IRQ_HANDLED; +} + +static int max7360_rotary_hw_init(struct max7360_rotary *max7360_rotary) +{ + struct device *dev =3D max7360_rotary->input->dev.parent; + int val; + int error; + + val =3D FIELD_PREP(MAX7360_ROT_DEBOUNCE, max7360_rotary->debounce_ms) | + FIELD_PREP(MAX7360_ROT_INTCNT, 1) | MAX7360_ROT_INTCNT_DLY; + error =3D regmap_write(max7360_rotary->regmap, MAX7360_REG_RTRCFG, val); + if (error) + dev_err(dev, "Failed to set max7360 rotary encoder configuration\n"); + + return error; +} + +static int max7360_rotary_probe(struct platform_device *pdev) +{ + struct max7360_rotary *max7360_rotary; + struct device *dev =3D &pdev->dev; + struct input_dev *input; + struct regmap *regmap; + int irq; + int error; + + regmap =3D dev_get_regmap(dev->parent, NULL); + if (!regmap) + return dev_err_probe(dev, -ENODEV, "Could not get parent regmap\n"); + + irq =3D fwnode_irq_get_byname(dev_fwnode(dev->parent), "inti"); + if (irq < 0) + return dev_err_probe(dev, irq, "Failed to get IRQ\n"); + + max7360_rotary =3D devm_kzalloc(dev, sizeof(*max7360_rotary), GFP_KERNEL); + if (!max7360_rotary) + return -ENOMEM; + + max7360_rotary->regmap =3D regmap; + + device_property_read_u32(dev->parent, "linux,axis", &max7360_rotary->axis= ); + max7360_rotary->rollover =3D device_property_read_bool(dev->parent, + "rotary-encoder,rollover"); + max7360_rotary->relative_axis =3D + device_property_read_bool(dev->parent, "rotary-encoder,relative-axis"); + + error =3D device_property_read_u32(dev->parent, "rotary-encoder,steps", + &max7360_rotary->steps); + if (error) + max7360_rotary->steps =3D MAX7360_ROTARY_DEFAULT_STEPS; + + device_property_read_u32(dev->parent, "rotary-debounce-delay-ms", + &max7360_rotary->debounce_ms); + if (max7360_rotary->debounce_ms > MAX7360_ROT_DEBOUNCE_MAX) + return dev_err_probe(dev, -EINVAL, "Invalid debounce timing: %u\n", + max7360_rotary->debounce_ms); + + input =3D devm_input_allocate_device(dev); + if (!input) + return -ENOMEM; + + max7360_rotary->input =3D input; + + input->id.bustype =3D BUS_I2C; + input->name =3D pdev->name; + + if (max7360_rotary->relative_axis) + input_set_capability(input, EV_REL, max7360_rotary->axis); + else + input_set_abs_params(input, max7360_rotary->axis, 0, max7360_rotary->ste= ps, 0, 1); + + error =3D devm_request_threaded_irq(dev, irq, NULL, max7360_rotary_irq, + IRQF_ONESHOT | IRQF_SHARED, + "max7360-rotary", max7360_rotary); + if (error) + return dev_err_probe(dev, error, "Failed to register interrupt\n"); + + error =3D input_register_device(input); + if (error) + return dev_err_probe(dev, error, "Could not register input device\n"); + + error =3D max7360_rotary_hw_init(max7360_rotary); + if (error) + return dev_err_probe(dev, error, "Failed to initialize max7360 rotary\n"= ); + + device_init_wakeup(dev, true); + error =3D dev_pm_set_wake_irq(dev, irq); + if (error) + dev_warn(dev, "Failed to set up wakeup irq: %d\n", error); + + return 0; +} + +static void max7360_rotary_remove(struct platform_device *pdev) +{ + dev_pm_clear_wake_irq(&pdev->dev); + device_init_wakeup(&pdev->dev, false); +} + +static struct platform_driver max7360_rotary_driver =3D { + .driver =3D { + .name =3D "max7360-rotary", + }, + .probe =3D max7360_rotary_probe, + .remove =3D max7360_rotary_remove, +}; +module_platform_driver(max7360_rotary_driver); + +MODULE_DESCRIPTION("MAX7360 Rotary driver"); +MODULE_AUTHOR("Mathieu Dubois-Briand "); +MODULE_LICENSE("GPL"); --=20 2.39.5 From nobody Mon Oct 6 10:17:35 2025 Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8118281525; Tue, 22 Jul 2025 16:24:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201461; cv=none; b=JUKA6Kg0ov9St2oB+6HpX66trQFzYrf/IOytRIKfuemzOZa7fWV5O9YRUZYWlpav0jvdNLvcU7E2isikPxky97Xw4eMBorY4s/2GvpJ3euSDHMreQbBvN+RweYu6D5HSyXVmlM8k3Zp9koQh3LutRfWOo2Ft2yhOridErrOKqm8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753201461; c=relaxed/simple; bh=xJ6iY8o+ZOpmD8Y1clJfWaa8E3xKOaOVi2G4V5Rnvlk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=EU1A85DcwiLw3A0px/fFHuLT7KlLjlxPbbuHGm915d8EsjB1qsiWrUfFQn4OIFH7y4mZosw4ePh6TH2nFkPlYNwoNqrDAuIbfGO4gXn+3OublTeTjdiDPdEN7vNQ7PyQdjB9z9JRw7yHLo4xyFaWd0nG+GBwl8M11VXovFZXAHU= 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=bLGzyCoq; arc=none smtp.client-ip=217.70.183.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="bLGzyCoq" Received: by mail.gandi.net (Postfix) with ESMTPSA id 3903E442BA; Tue, 22 Jul 2025 16:24:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1753201454; 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=Sx6wkia9Ry4UV/E6LGN80qIoVg+MTk5IsREllQ76Ch0=; b=bLGzyCoqzxIMa79ZmkUahyDwsQ+XS6zaMNd5Pf5V2rhY8d7vNUINERAx5x5Mt8gYhp4F0B Jg5Px/QOUd+A9V9dY7VAXZZwItq1PeQiMZqb13VBwgjme0i2RnRSM4QO1wjvQuyMdGM0JG rlb47DSgd3f5XyvNx5daQyMTmsFUOzvmxUYnk9BrYUu+AtKZdF2ZCP9LBrNV4fvg3vEODl +P9d0cWXD8buV5w5P0QGnFt2drcApwLWG56ynsnZULkyRTgcPfCo5fpGB6/4lEMEtCKZGt B0OopUC/tfJ1PTjplNLMJk6iVQZhWlbtsaY8jnimobHo0Nqmq/i1iXtCh4/NRg== From: Mathieu Dubois-Briand Date: Tue, 22 Jul 2025 18:23:54 +0200 Subject: [PATCH v12 10/10] MAINTAINERS: Add entry on MAX7360 driver Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20250722-mdb-max7360-support-v12-10-3747721a8d02@bootlin.com> References: <20250722-mdb-max7360-support-v12-0-3747721a8d02@bootlin.com> In-Reply-To: <20250722-mdb-max7360-support-v12-0-3747721a8d02@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=B6nig?= , 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=A9gory_Clement?= , Thomas Petazzoni , Mathieu Dubois-Briand X-Mailer: b4 0.14.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1753201440; l=1082; i=mathieu.dubois-briand@bootlin.com; s=20241219; h=from:subject:message-id; bh=xJ6iY8o+ZOpmD8Y1clJfWaa8E3xKOaOVi2G4V5Rnvlk=; b=RCtvc6Srpi81Hw3SAZmo9YPbfFfM9Vq/dZhYOLivl7rVBPorISC3LthYFL0evjIQ9O0I0LgBM smlCMBzi1IPCGB54JVnNsV915RaNmFWhlivYJPIbbp5VuJ2sDKhD6vw 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: gggruggvucftvghtrhhoucdtuddrgeeffedrtdefgdejheefiecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfitefpfffkpdcuggftfghnshhusghstghrihgsvgenuceurghilhhouhhtmecufedtudenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeforghthhhivghuucffuhgsohhishdquehrihgrnhguuceomhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomheqnecuggftrfgrthhtvghrnheptdfhgeetvddvheejieehheehueetjeelkedtfeehhefgfeeglefhteegtddthfetnecukfhppedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejieenucevlhhushhtvghrufhiiigvpeehnecurfgrrhgrmhepihhnvghtpedvrgdtudemtggsudegmeehheeimeejrgdttdemfehftghfmehfsgdtugemuddviedvmedvvgejiedphhgvlhhopegluddvjedrtddruddrudgnpdhmrghilhhfrhhomhepmhgrthhhihgvuhdrughusghoihhsqdgsrhhirghnugessghoohhtlhhinhdrtghomhdpnhgspghrtghpthhtohepvdefpdhrtghpthhtoheplhhinhhushdrfigrlhhlvghijheslhhinhgrrhhordhorhhgpdhrtghpthhtohepmhifrghllhgvsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnhgurhhihidrshhhv ghvtghhvghnkhhosehinhhtvghlrdgtohhmpdhrtghpthhtoheprhgrfhgrvghlsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrhiikhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpfihmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheptghonhhorhdoughtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehlvggvsehkvghrnhgvlhdrohhrgh 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 | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 60bba48f5479..469317272dab 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -14808,6 +14808,19 @@ L: linux-iio@vger.kernel.org S: Maintained F: drivers/iio/temperature/max30208.c =20 +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/pinctrl/pinctrl-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 --=20 2.39.5