Skip to contentSkip to conversation

Add support for MAX7360

PATCH Superseded Mathieu Dubois-Briand 5 participants 23 messages Dec 23, 2024 – Jan 27, 2025

Subsystems (7)

v2 of 14 Superseded Latest is v14 →

lore
Share & tools
lore

Mathieu Dubois-Briand

author maintainer
#0 lore raw

v2 cover Add support for MAX7360

This series implements a set of drivers allowing to support the Maxim Integrated MAX7360 device.

The MAX7360 is an I2C key-switch and led controller, with following functionalities:
- Keypad controller for a key matrix of up to 8 rows and 8 columns.
- Rotary encoder support, for a single rotary encoder.
- Up to 8 PWM outputs.
- Up to 8 GPIOs with support for interrupts and 6 GPOs.

Chipset pins are shared between all functionalities, so all cannot be used at the same time.

---
Changes in v2:
- Removing device tree subnodes for keypad, rotary encoder and pwm functionalities.
- Fixed dt-bindings syntax and naming.
- Fixed missing handling of requested period in PWM driver.
- Cleanup of the code
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Kamel Bouhara (2):
mfd: Add max7360 support
pwm: max7360: Add MAX7360 PWM support

Mathieu Dubois-Briand (5):
dt-bindings: mfd: gpio: Add MAX7360
gpio: max7360: Add MAX7360 gpio support
input: keyboard: Add support for MAX7360 keypad
input: misc: Add support for MAX7360 rotary
MAINTAINERS: Add entry on MAX7360 driver

 .../bindings/gpio/maxim,max7360-gpio.yaml          |  80 ++++
 .../devicetree/bindings/mfd/maxim,max7360.yaml     | 107 +++++
 MAINTAINERS                                        |  12 +
 drivers/gpio/Kconfig                               |  11 +
 drivers/gpio/Makefile                              |   1 +
 drivers/gpio/gpio-max7360.c                        | 455 +++++++++++++++++++++
 drivers/input/keyboard/Kconfig                     |  12 +
 drivers/input/keyboard/Makefile                    |   1 +
 drivers/input/keyboard/max7360-keypad.c            | 289 +++++++++++++
 drivers/input/misc/Kconfig                         |  11 +
 drivers/input/misc/Makefile                        |   1 +
 drivers/input/misc/max7360-rotary.c                | 185 +++++++++
 drivers/mfd/Kconfig                                |  12 +
 drivers/mfd/Makefile                               |   1 +
 drivers/mfd/max7360.c                              | 296 ++++++++++++++
 drivers/pwm/Kconfig                                |  11 +
 drivers/pwm/Makefile                               |   1 +
 drivers/pwm/pwm-max7360.c                          | 219 ++++++++++
 include/linux/mfd/max7360.h                        | 109 +++++
 19 files changed, 1814 insertions(+)

---
base-commit: 78d4f34e2115b517bcbfe7ec0d018bbbb6f9b0b8
change-id: 20241219-mdb-max7360-support-223a8ce45ba3

Best regards,

Signature · 1 line
Mathieu Dubois-Briand <[email protected]>
author maintainer
#1 lore raw

PATCH v2 1/7 dt-bindings: mfd: gpio: Add MAX7360

Add device tree bindings for Maxim Integrated MAX7360 device with support for keypad, rotary, gpios and pwm functionalities.

---
 .../bindings/gpio/maxim,max7360-gpio.yaml          |  80 +++++++++++++++
 .../devicetree/bindings/mfd/maxim,max7360.yaml     | 107 +++++++++++++++++++++
 2 files changed, 187 insertions(+)
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +80 -0
new file mode 100644
index 000000000000..6e6133ce6e68
@@ -0,0 +1,80 @@
+# 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 <[email protected]>
+  - Mathieu Dubois-Briand <[email protected]>
+
+description: |
+  Maxim MAX7360 GPIO controller, in MAX7360 chipset
+  https://www.analog.com/en/products/max7360.html
+
+properties:
+  compatible:
+    enum:
+      - maxim,max7360-gpio
+      - maxim,max7360-gpo
+
+  gpio-controller: true
+
+  "#gpio-cells":
+    const: 2
+
+  ngpios:
+    minimum: 0
+    maximum: 8
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 2
+
+  maxim,constant-current-disable:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Bit field, each bit disables constant-current output of the associated
+      GPIO, starting from the least significant bit for the first GPIO.
+
+
+required:
+  - compatible
+  - gpio-controller
+  - ngpios
+
+if:
+  properties:
+    compatible:
+      contains:
+        enum:
+          - maxim,max7360-gpio
+then:
+  required:
+    - interrupt-controller
+else:
+  properties:
+    interrupt-controller: false
+    maxim,constant-current-disable: false
+
+    ngpios:
+      maximum: 6
+
+additionalProperties: false
+
+examples:
+  - |
+    gpio {
+      compatible = "maxim,max7360-gpio";
+
+      gpio-controller;
+      #gpio-cells = <0x2>;
+      ngpios = <8>;
+      maxim,constant-current-disable = <0x06>;
+
+      interrupt-controller;
+      #interrupt-cells = <0x2>;
+      };
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +107 -0

107 lines not on this page · raw message

Signature · 1 line
2.39.5
#2 lore raw

Re: [PATCH v2 1/7] dt-bindings: mfd: gpio: Add MAX7360

Hello,

just a nitpick I noticed, not a full review:

Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml line 80

Quoted 13 lines · Mathieu Dubois-Briand
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +13 -0
+examples:
+  - |
+    gpio {
+      compatible = "maxim,max7360-gpio";
+
+      gpio-controller;
+      #gpio-cells = <0x2>;
+      ngpios = <8>;
+      maxim,constant-current-disable = <0x06>;
+
+      interrupt-controller;
+      #interrupt-cells = <0x2>;
+      };

I think s/ // in the line with the closing curly brace.

Best regards
Uwe

#3 lore raw

Re: [PATCH v2 1/7] dt-bindings: mfd: gpio: Add MAX7360

In reply to Mathieu Dubois-Briand
Quoted 20 lines · Mathieu Dubois-Briand

Add device tree bindings for Maxim Integrated MAX7360 device with support for keypad, rotary, gpios and pwm functionalities.

---
 .../bindings/gpio/maxim,max7360-gpio.yaml          |  80 +++++++++++++++
 .../devicetree/bindings/mfd/maxim,max7360.yaml     | 107 +++++++++++++++++++++
 2 files changed, 187 insertions(+)
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +5 -0
new file mode 100644
index 000000000000..6e6133ce6e68
@@ -0,0 +1,80 @@
+# 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#

Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml line 15

Quoted 10 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +10 -0
+
+title: Maxim MAX7360 GPIO controller
+
+maintainers:
+  - Kamel Bouhara <[email protected]>
+  - Mathieu Dubois-Briand <[email protected]>
+
+description: |
+  Maxim MAX7360 GPIO controller, in MAX7360 chipset
+  https://www.analog.com/en/products/max7360.html

Don't send new versions so fast, especially for larger patchsets, so we can finish previous discussion.

You gave me yesterday around 1 hour to respond to your last email and then you sent v2.

Please implement my last comments on v1.

Quoted 6 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +6 -0
+
+properties:
+  compatible:
+    enum:
+      - maxim,max7360-gpio
+      - maxim,max7360-gpo

...

Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml line 74

Quoted 9 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +9 -0
+additionalProperties: false
+
+examples:
+  - |
+    gpio {
+      compatible = "maxim,max7360-gpio";
+
+      gpio-controller;
+      #gpio-cells = <0x2>;

Not a hex, <2>

Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml line 79

Quoted 5 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +5 -0
+      ngpios = <8>;
+      maxim,constant-current-disable = <0x06>;
+
+      interrupt-controller;
+      #interrupt-cells = <0x2>;

Not a hex, <2>

Quoted 32 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +1 -0
+      };
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +25 -0
new file mode 100644
index 000000000000..1f761707070a
@@ -0,0 +1,107 @@
+# 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 <[email protected]>
+  - Mathieu Dubois-Briand <[email protected]>
+
+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#
+

Documentation/devicetree/bindings/mfd/maxim,max7360.yaml line 35

Quoted 10 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +10 -0
+properties:
+  compatible:
+    enum:
+      - maxim,max7360
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    minItems: 2

You can drop minItems.

Quoted 27 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +27 -0
+    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
+
+  autorepeat: true
+
+  rotary-debounce-delay-ms:
+    description: Rotary encoder debounce delay in ms
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  linux,axis:
+    description: The input subsystem axis to map to this rotary encoder.
+
+  "#pwm-cells":
+    const: 3
+
+required:

Documentation/devicetree/bindings/mfd/maxim,max7360.yaml line 73

Quoted 10 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +10 -0
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+  - linux,keymap
+  - linux,axis
+  - "#pwm-cells"
+
+unevaluatedProperties: false
+

Well, I still see it incomplete... and to prove it, please post your DTS for entire max7360 and validate it against bindings.

There is no way this works, unless GPIO is not part of this device but then it is obviously incorrect design.

Best regards,
Krzysztof

author maintainer
#4 lore raw

Re: [PATCH v2 1/7] dt-bindings: mfd: gpio: Add MAX7360

Quoted 35 lines · Krzysztof Kozlowski
Quoted 20 lines · Mathieu Dubois-Briand

Add device tree bindings for Maxim Integrated MAX7360 device with support for keypad, rotary, gpios and pwm functionalities.

---
 .../bindings/gpio/maxim,max7360-gpio.yaml          |  80 +++++++++++++++
 .../devicetree/bindings/mfd/maxim,max7360.yaml     | 107 +++++++++++++++++++++
 2 files changed, 187 insertions(+)
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +5 -0
new file mode 100644
index 000000000000..6e6133ce6e68
@@ -0,0 +1,80 @@
+# 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#

Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml line 15

Quoted 10 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +10 -0
+
+title: Maxim MAX7360 GPIO controller
+
+maintainers:
+  - Kamel Bouhara <[email protected]>
+  - Mathieu Dubois-Briand <[email protected]>
+
+description: |
+  Maxim MAX7360 GPIO controller, in MAX7360 chipset
+  https://www.analog.com/en/products/max7360.html

Don't send new versions so fast, especially for larger patchsets, so we can finish previous discussion.

Quoted 3 lines

You gave me yesterday around 1 hour to respond to your last email and then you sent v2.

Soddy, I didn't mean to. I thought having a v2 would be easier to show how I addressed the previous comments, but I definitely was too fast. I will make sure to wait more next time.

Quoted 24 lines

Please implement my last comments on v1.

Quoted 6 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +6 -0
+
+properties:
+  compatible:
+    enum:
+      - maxim,max7360-gpio
+      - maxim,max7360-gpo

...

Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml line 74

Quoted 9 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +9 -0
+additionalProperties: false
+
+examples:
+  - |
+    gpio {
+      compatible = "maxim,max7360-gpio";
+
+      gpio-controller;
+      #gpio-cells = <0x2>;

Not a hex, <2>

Quoted 8 lines

Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml line 79

Quoted 5 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +5 -0
+      ngpios = <8>;
+      maxim,constant-current-disable = <0x06>;
+
+      interrupt-controller;
+      #interrupt-cells = <0x2>;

Not a hex, <2>

Ok, I will fix both values.

Quoted 36 lines
Quoted 36 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +1 -0
+      };
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +29 -0
new file mode 100644
index 000000000000..1f761707070a
@@ -0,0 +1,107 @@
+# 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 <[email protected]>
+  - Mathieu Dubois-Briand <[email protected]>
+
+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
Quoted 9 lines

Documentation/devicetree/bindings/mfd/maxim,max7360.yaml line 35

Quoted 6 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +6 -0
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    minItems: 2

You can drop minItems.

Ok, fixed.

Quoted 41 lines
Quoted 27 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +27 -0
+    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
+
+  autorepeat: true
+
+  rotary-debounce-delay-ms:
+    description: Rotary encoder debounce delay in ms
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  linux,axis:
+    description: The input subsystem axis to map to this rotary encoder.
+
+  "#pwm-cells":
+    const: 3
+
+required:

Documentation/devicetree/bindings/mfd/maxim,max7360.yaml line 73

Quoted 10 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +10 -0
+  - compatible
+  - reg
+  - interrupts
+  - interrupt-names
+  - linux,keymap
+  - linux,axis
+  - "#pwm-cells"
+
+unevaluatedProperties: false
+

Well, I still see it incomplete... and to prove it, please post your DTS for entire max7360 and validate it against bindings.

Quoted 3 lines

There is no way this works, unless GPIO is not part of this device but then it is obviously incorrect design.

Ok, it looks like I completely missed how it was supposed to be described. So, if I got it right, I need to:
- Add two properties, gpio and gpo, with $ref: /schemas/gpio/maxim,max7360-gpio.yaml#
- Add the two gpio and gpo child nodes in the example.

Quoted 3 lines

Best regards,
Krzysztof

Thanks for your review,
Mathieu

Signature · 3 lines
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
author maintainer
#5 lore raw

PATCH v2 2/7 mfd: Add max7360 support

In reply to Mathieu Dubois-Briand

From: Kamel Bouhara <[email protected]>

Add core driver to support MAX7360 i2c chip, multi function device with keypad, gpio, pwm, gpo and rotary encoder submodules.

---
 drivers/mfd/Kconfig         |  12 ++
 drivers/mfd/Makefile        |   1 +
 drivers/mfd/max7360.c       | 296 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/max7360.h | 109 ++++++++++++++++
 4 files changed, 418 insertions(+)
drivers/mfd/Kconfig +12 -0
index ae23b317a64e..c1ddda480922 100644
@@ -2414,5 +2414,17 @@ config MFD_RSMU_SPI
 	  Additional drivers must be enabled in order to use the functionality
 	  of the device.
 
+config MFD_MAX7360
+	tristate "Maxim MAX7360 Support"
+	depends on I2C
+	select MFD_CORE
+	select REGMAP_I2C
+	select REGMAP_IRQ
+	help
+	  Say yes here to add support for Maxim MAX7360.
+	  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
drivers/mfd/Makefile +1 -0
index e057d6d6faef..6cd55504106d 100644
@@ -163,6 +163,7 @@ obj-$(CONFIG_MFD_DA9063)	+= da9063.o
 obj-$(CONFIG_MFD_DA9150)	+= da9150-core.o
 
 obj-$(CONFIG_MFD_MAX14577)	+= max14577.o
+obj-$(CONFIG_MFD_MAX7360)	+= max7360.o
 obj-$(CONFIG_MFD_MAX77541)	+= max77541.o
 obj-$(CONFIG_MFD_MAX77620)	+= max77620.o
 obj-$(CONFIG_MFD_MAX77650)	+= max77650.o
drivers/mfd/max7360.c new file +296 -0

296 lines not on this page · raw message

include/linux/mfd/max7360.h new file +109 -0

109 lines not on this page · raw message

Signature · 1 line
2.39.5
author maintainer
#6 lore raw

PATCH v2 3/7 pwm: max7360: Add MAX7360 PWM support

In reply to Mathieu Dubois-Briand

From: Kamel Bouhara <[email protected]>

Add driver for Maxim Integrated MAX7360 PWM controller, supporting up to 8 independent PWM outputs.

---
 drivers/pwm/Kconfig       |  11 +++
 drivers/pwm/Makefile      |   1 +
 drivers/pwm/pwm-max7360.c | 219 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 231 insertions(+)
drivers/pwm/Kconfig +11 -0
index 0915c1e7df16..399dc3f76e92 100644
@@ -745,4 +745,15 @@ config PWM_XILINX
 	  To compile this driver as a module, choose M here: the module
 	  will be called pwm-xilinx.
 
+config PWM_MAX7360
+	tristate "MAX7360 PWMs"
+	depends on MFD_MAX7360
+	depends on OF_GPIO
+	help
+	  PWM driver for Maxim Integrated MAX7360 multifunction device, with
+	  support for up to 8 PWM outputs.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called pwm-max7360.
+
 endif
drivers/pwm/Makefile +1 -0
index 9081e0c0e9e0..ae8908ffc892 100644
@@ -36,6 +36,7 @@ obj-$(CONFIG_PWM_LPC32XX)	+= pwm-lpc32xx.o
 obj-$(CONFIG_PWM_LPSS)		+= pwm-lpss.o
 obj-$(CONFIG_PWM_LPSS_PCI)	+= pwm-lpss-pci.o
 obj-$(CONFIG_PWM_LPSS_PLATFORM)	+= pwm-lpss-platform.o
+obj-$(CONFIG_PWM_MAX7360)	+= pwm-max7360.o
 obj-$(CONFIG_PWM_MESON)		+= pwm-meson.o
 obj-$(CONFIG_PWM_MEDIATEK)	+= pwm-mediatek.o
 obj-$(CONFIG_PWM_MICROCHIP_CORE)	+= pwm-microchip-core.o
drivers/pwm/pwm-max7360.c new file +219 -0

219 lines not on this page · raw message

Signature · 1 line
2.39.5
#7 lore raw

Re: [PATCH v2 3/7] pwm: max7360: Add MAX7360 PWM support

Le 23/12/2024 à 17:42, [email protected] a écrit :

Quoted 7 lines

From: Kamel Bouhara <[email protected]>

Add driver for Maxim Integrated MAX7360 PWM controller, supporting up to 8 independent PWM outputs.

...

Quoted 16 lines
drivers/pwm/pwm-max7360.c new file +16 -0
+static int max7360_pwm_probe(struct platform_device *pdev)
+{
+	struct max7360_pwm *max7360_pwm;
+	struct pwm_chip *chip;
+	int ret;
+
+	if (!pdev->dev.parent)
+		return dev_err_probe(&pdev->dev, -ENODEV, "no parent device\n");
+
+	chip = devm_pwmchip_alloc(pdev->dev.parent, MAX7360_NUM_PWMS,
+				  sizeof(*max7360_pwm));
+	if (IS_ERR(chip))
+		return PTR_ERR(chip);
+	chip->ops = &max7360_pwm_ops;
+
+	max7360_pwm = to_max7360_pwm(chip);

drivers/pwm/pwm-max7360.c line 203

Quoted 10 lines
drivers/pwm/pwm-max7360.c new file +10 -0
+	max7360_pwm->parent = pdev->dev.parent;
+
+	max7360_pwm->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!max7360_pwm->regmap)
+		return dev_err_probe(&pdev->dev, -ENODEV,
+				     "could not get parent regmap\n");
+
+	ret = devm_pwmchip_add(&pdev->dev, chip);
+	if (ret != 0)
+		dev_err_probe(&pdev->dev, ret, "failed to add PWM chip");

Missing return, or done on purpose?

Quoted 3 lines
drivers/pwm/pwm-max7360.c new file +3 -0
+
+	return 0;
+}
author maintainer
#8 lore raw

PATCH v2 4/7 gpio: max7360: Add MAX7360 gpio support

In reply to Mathieu Dubois-Briand

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.

---
 drivers/gpio/Kconfig        |  11 ++
 drivers/gpio/Makefile       |   1 +
 drivers/gpio/gpio-max7360.c | 455 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 467 insertions(+)
drivers/gpio/Kconfig +11 -0
index 93ee3aa092f8..efe07e21c442 100644
@@ -1444,6 +1444,17 @@ config GPIO_MADERA
 	help
 	  Support for GPIOs on Cirrus Logic Madera class codecs.
 
+config GPIO_MAX7360
+	tristate "MAX7360 GPIO support"
+	depends on MFD_MAX7360
+	depends on OF_GPIO
+	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
drivers/gpio/Makefile +1 -0
index af3ba4d81b58..581341b3e3e4 100644
@@ -100,6 +100,7 @@ obj-$(CONFIG_GPIO_MAX7300)		+= gpio-max7300.o
 obj-$(CONFIG_GPIO_MAX7301)		+= gpio-max7301.o
 obj-$(CONFIG_GPIO_MAX730X)		+= gpio-max730x.o
 obj-$(CONFIG_GPIO_MAX732X)		+= gpio-max732x.o
+obj-$(CONFIG_GPIO_MAX7360)		+= gpio-max7360.o
 obj-$(CONFIG_GPIO_MAX77620)		+= gpio-max77620.o
 obj-$(CONFIG_GPIO_MAX77650)		+= gpio-max77650.o
 obj-$(CONFIG_GPIO_MB86S7X)		+= gpio-mb86s7x.o
drivers/gpio/gpio-max7360.c new file +455 -0

455 lines not on this page · raw message

Signature · 1 line
2.39.5
#9 lore raw

Re: [PATCH v2 4/7] gpio: max7360: Add MAX7360 gpio support

Le 23/12/2024 à 17:42, Mathieu Dubois-Briand a écrit :

Quoted 10 lines

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.

...

Quoted 8 lines
drivers/gpio/gpio-max7360.c new file +8 -0
+static int max7360_gpio_probe(struct platform_device *pdev)
+{
+	struct max7360_gpio *max7360_gpio;
+	struct platform_device *parent;
+	unsigned int ngpios;
+	unsigned int outconf;
+	struct gpio_irq_chip *girq;
+	unsigned long flags;

drivers/gpio/gpio-max7360.c line 350

Quoted 10 lines
drivers/gpio/gpio-max7360.c new file +10 -0
+	int irq;
+	int ret;
+
+	if (!pdev->dev.parent) {
+		dev_err(&pdev->dev, "no parent device\n");
+		return -ENODEV;
+	}
+	parent = to_platform_device(pdev->dev.parent);
+
+	max7360_gpio = devm_kzalloc(&pdev->dev, sizeof(struct max7360_gpio),

sizeof(*max7360_gpio)?

Quoted 49 lines
drivers/gpio/gpio-max7360.c new file +49 -0
+				    GFP_KERNEL);
+	if (!max7360_gpio)
+		return -ENOMEM;
+
+	if (of_property_read_u32(pdev->dev.of_node, "ngpios", &ngpios)) {
+		dev_err(&pdev->dev, "Missing ngpios OF property\n");
+		return -ENODEV;
+	}
+
+	max7360_gpio->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!max7360_gpio->regmap) {
+		dev_err(&pdev->dev, "could not get parent regmap\n");
+		return -ENODEV;
+	}
+
+	max7360_gpio->dev = &pdev->dev;
+	max7360_gpio->chip = max7360_gpio_chip;
+	max7360_gpio->chip.ngpio = ngpios;
+	max7360_gpio->chip.parent = &pdev->dev;
+	max7360_gpio->chip.base = -1;
+	max7360_gpio->gpio_function = (uintptr_t)device_get_match_data(&pdev->dev);
+
+	dev_dbg(&pdev->dev, "gpio count: %d\n", max7360_gpio->chip.ngpio);
+
+	if (max7360_gpio->gpio_function == MAX7360_GPIO_PORT) {
+		/* Port GPIOs: set output mode configuration (constant-current
+		 * or not).
+		 * This property is optional.
+		 */
+		outconf = 0;
+		ret = of_property_read_u32(pdev->dev.of_node,
+					   "maxim,constant-current-disable",
+					   &outconf);
+		if (ret && (ret != -EINVAL)) {
+			dev_err(&pdev->dev,
+				"Failed to read maxim,constant-current-disable OF property\n");
+			return -ENODEV;
+		}
+
+	    regmap_write(max7360_gpio->regmap, MAX7360_REG_GPIOOUTM, outconf);
+	}
+
+	if (max7360_gpio->gpio_function == MAX7360_GPIO_PORT &&
+	    of_property_read_bool(pdev->dev.of_node, "interrupt-controller")) {
+		/* Port GPIOs: declare IRQ chip, if configuration was provided.
+		 */
+		irq = platform_get_irq_byname(parent, "inti");
+		if (irq < 0)
+			return dev_err_probe(&pdev->dev, irq,

drivers/gpio/gpio-max7360.c line 409

Quoted 10 lines
drivers/gpio/gpio-max7360.c new file +10 -0
+					     "Failed to get IRQ");
+
+		flags = IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED;
+		ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
+						max7360_gpio_irq, flags,
+						"max7360-gpio", max7360_gpio);
+		if (ret)
+			return dev_err_probe(&pdev->dev, ret,
+					     "Failed to register interrupt: %d\n",
+					     ret);

No need to duplicate ret in the message.

Quoted 4 lines
drivers/gpio/gpio-max7360.c new file +4 -0
+
+		girq = &max7360_gpio->chip.irq;
+		gpio_irq_chip_set_chip(girq, &max7360_gpio_irqchip);
+		girq->parent_handler = NULL;

drivers/gpio/gpio-max7360.c line 423

Quoted 10 lines
drivers/gpio/gpio-max7360.c new file +10 -0
+		girq->num_parents = 0;
+		girq->parents = NULL;
+		girq->threaded = true;
+		girq->default_type = IRQ_TYPE_NONE;
+		girq->handler = handle_simple_irq;
+	}
+
+	ret = devm_gpiochip_add_data(&pdev->dev, &max7360_gpio->chip, max7360_gpio);
+	if (ret) {
+		dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);

return dev_err_probe()?

drivers/gpio/gpio-max7360.c line 122

Quoted 5 lines
drivers/gpio/gpio-max7360.c new file +5 -0
+		return ret;
+	}
+
+	return 0;
+}

CJ

#10 lore raw

Re: [PATCH v2 4/7] gpio: max7360: Add MAX7360 gpio support

In reply to Mathieu Dubois-Briand
Quoted 6 lines · Mathieu Dubois-Briand

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.

May I ask if you researched for the existing drivers that may host this without much to modify?

Second, please, avoid OF-centric APIs in a new code. Use fwnode and/or device property APIs. (This stands for the whole series and any new contributions)

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#11 lore raw

Re: [PATCH v2 4/7] gpio: max7360: Add MAX7360 gpio support

Quoted 1 line · Andy Shevchenko

On Mon, Dec 23, 2024 at 05:42:36PM +0100, Mathieu Dubois-Briand wrote:

Hi Andy,

Thanks for your review. I'm not sure you have seen it, but there is a v3 of this series. V3 of this patch can be seen here:
https://lore.kernel.org/all/[email protected]/

Yet, your comments are still valid for the v3.

Quoted 10 lines
Quoted 6 lines

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.

May I ask if you researched for the existing drivers that may host this without much to modify?

I did had a look at the existing drivers and in particular at all gpio-max* drivers. Unfortunately, I believe none of them target chipsets similar to the MAX7360.

The only similarity I noted, is with the MAX732x chipsets, on the IRQ
side: both lack of dedicated bits for each line, leading to some logic to try to recover the corresponding lines on interrupt. My code is partly based on the MAX732x code on this specific point.

Quoted 2 lines

Second, please, avoid OF-centric APIs in a new code. Use fwnode and/or device property APIs. (This stands for the whole series and any new contributions)

Yes, I definitely need to remove these of_property_read_*() calls. I'm going to replace them with device_property_read_*() calls.

Best regards,
Mathieu

Signature · 3 lines
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#12 lore raw

Re: [PATCH v2 4/7] gpio: max7360: Add MAX7360 gpio support

Quoted 1 line · Mathieu Dubois-Briand

On Tue Jan 21, 2025 at 4:20 PM CET, Andy Shevchenko wrote:

...

Quoted 3 lines

Thanks for your review. I'm not sure you have seen it, but there is a v3 of this series. V3 of this patch can be seen here:
https://lore.kernel.org/all/[email protected]/

Thanks for sharing, I will look at it later this on next week.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#13 lore raw

Re: [PATCH v2 4/7] gpio: max7360: Add MAX7360 gpio support

Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Mathieu Dubois-Briand

On Tue Jan 21, 2025 at 4:20 PM CET, Andy Shevchenko wrote:

...

Quoted 5 lines
Quoted 3 lines

Thanks for your review. I'm not sure you have seen it, but there is a v3 of this series. V3 of this patch can be seen here:
https://lore.kernel.org/all/[email protected]/

Thanks for sharing, I will look at it later this on next week.

Just answered to the GPIO patch in it. Waiting for v4...

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#14 lore raw

PATCH v2 5/7 input: keyboard: Add support for MAX7360 keypad

In reply to Mathieu Dubois-Briand

Add driver for Maxim Integrated MAX7360 keypad controller, providing support for up to 64 keys, with a matrix of 8 columns and 8 rows.

---
 drivers/input/keyboard/Kconfig          |  12 ++
 drivers/input/keyboard/Makefile         |   1 +
 drivers/input/keyboard/max7360-keypad.c | 289 ++++++++++++++++++++++++++++++++
 3 files changed, 302 insertions(+)
drivers/input/keyboard/Kconfig +12 -0
index 721ab69e84ac..bba029f65cfa 100644
@@ -421,6 +421,18 @@ config KEYBOARD_MAX7359
 	  To compile this driver as a module, choose M here: the
 	  module will be called max7359_keypad.
 
+config KEYBOARD_MAX7360
+	tristate "Maxim MAX7360 Key Switch Controller"
+	select INPUT_MATRIXKMAP
+	depends on I2C
+	depends on MFD_MAX7360
+	help
+	  If you say yes here you get support for the keypad controller on the
+	  Maxim MAX7360 I/O Expander.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called max7360_keypad.
+
 config KEYBOARD_MPR121
 	tristate "Freescale MPR121 Touchkey"
 	depends on I2C
drivers/input/keyboard/Makefile +1 -0
index 1e0721c30709..b49d32d4003d 100644
@@ -42,6 +42,7 @@ obj-$(CONFIG_KEYBOARD_LPC32XX)		+= lpc32xx-keys.o
 obj-$(CONFIG_KEYBOARD_MAPLE)		+= maple_keyb.o
 obj-$(CONFIG_KEYBOARD_MATRIX)		+= matrix_keypad.o
 obj-$(CONFIG_KEYBOARD_MAX7359)		+= max7359_keypad.o
+obj-$(CONFIG_KEYBOARD_MAX7360)		+= max7360-keypad.o
 obj-$(CONFIG_KEYBOARD_MPR121)		+= mpr121_touchkey.o
 obj-$(CONFIG_KEYBOARD_MT6779)		+= mt6779-keypad.o
 obj-$(CONFIG_KEYBOARD_MTK_PMIC) 	+= mtk-pmic-keys.o
drivers/input/keyboard/max7360-keypad.c new file +289 -0

289 lines not on this page · raw message

Signature · 1 line
2.39.5
#15 lore raw

Re: [PATCH v2 5/7] input: keyboard: Add support for MAX7360 keypad

Le 23/12/2024 à 17:42, Mathieu Dubois-Briand a écrit :

Quoted 4 lines

Add driver for Maxim Integrated MAX7360 keypad controller, providing support for up to 64 keys, with a matrix of 8 columns and 8 rows.

...

drivers/input/keyboard/max7360-keypad.c line 90

Quoted 13 lines
drivers/input/keyboard/max7360-keypad.c new file +13 -0
+static int max7360_keypad_open(struct input_dev *pdev)
+{
+	struct max7360_keypad *max7360_keypad = input_get_drvdata(pdev);
+	int error;
+
+	/*
+	 * Somebody is using the device: get out of sleep.
+	 */
+	error = regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_CONFIG,
+				  MAX7360_CFG_SLEEP, MAX7360_CFG_SLEEP);
+	if (error) {
+		dev_err(&max7360_keypad->input->dev,
+			"Failed to write max7360 configuration");

Missing \n.

Quoted 9 lines
drivers/input/keyboard/max7360-keypad.c new file +9 -0
+		return error;
+	}
+
+	return 0;
+}
+
+static void max7360_keypad_close(struct input_dev *pdev)
+{
+	struct max7360_keypad *max7360_keypad = input_get_drvdata(pdev);

drivers/input/keyboard/max7360-keypad.c line 109

Quoted 10 lines
drivers/input/keyboard/max7360-keypad.c new file +10 -0
+	int error;
+
+	/*
+	 * Nobody is using the device anymore: go to sleep.
+	 */
+	error = regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_CONFIG,
+				  MAX7360_CFG_SLEEP, ~MAX7360_CFG_SLEEP);
+	if (error)
+		dev_err(&max7360_keypad->input->dev,
+			"Failed to write max7360 configuration");

Missing \n.

Quoted 4 lines
drivers/input/keyboard/max7360-keypad.c new file +4 -0
+}
+
+static int max7360_keypad_hw_init(struct max7360_keypad *max7360_keypad)
+{

drivers/input/keyboard/max7360-keypad.c line 123

Quoted 10 lines
drivers/input/keyboard/max7360-keypad.c new file +10 -0
+	unsigned int val;
+	int error;
+
+	val = max7360_keypad->debounce_ms - MAX7360_DEBOUNCE_MIN;
+	error = regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_DEBOUNCE,
+				  MAX7360_DEBOUNCE,
+				  FIELD_PREP(MAX7360_DEBOUNCE, val));
+	if (error) {
+		dev_err(&max7360_keypad->input->dev,
+			"Failed to write max7360 debounce configuration");

Missing \n.
This is called from probe. Use dev_err_rpobe()?

drivers/input/keyboard/max7360-keypad.c line 132

Quoted 9 lines
drivers/input/keyboard/max7360-keypad.c new file +9 -0
+		return error;
+	}
+
+	error = regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_INTERRUPT,
+				  MAX7360_INTERRUPT_TIME_MASK,
+				  FIELD_PREP(MAX7360_INTERRUPT_TIME_MASK, 1));
+	if (error) {
+		dev_err(&max7360_keypad->input->dev,
+			"Failed to write max7360 keypad interrupt configuration");

Missing \n.
This is called from probe. Use dev_err_rpobe()?

Quoted 5 lines
drivers/input/keyboard/max7360-keypad.c new file +5 -0
+		return error;
+	}
+
+	return 0;
+}

...

Quoted 24 lines
drivers/input/keyboard/max7360-keypad.c new file +24 -0
+static int max7360_keypad_probe(struct platform_device *pdev)
+{
+	struct max7360_keypad *max7360_keypad;
+	struct input_dev *input;
+	bool autorepeat;
+	int error;
+	int irq;
+
+	if (!pdev->dev.parent)
+		return dev_err_probe(&pdev->dev, -ENODEV, "No parent device\n");
+
+	irq = platform_get_irq_byname(to_platform_device(pdev->dev.parent),
+				      "intk");
+	if (irq < 0)
+		return irq;
+
+	max7360_keypad = devm_kzalloc(&pdev->dev, sizeof(*max7360_keypad),
+				      GFP_KERNEL);
+	if (!max7360_keypad)
+		return -ENOMEM;
+
+	max7360_keypad->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!max7360_keypad->regmap)
+		return dev_err_probe(&pdev->dev, -ENODEV,

drivers/input/keyboard/max7360-keypad.c line 218

Quoted 10 lines
drivers/input/keyboard/max7360-keypad.c new file +10 -0
+				     "Could not get parent regmap\n");
+
+	error = max7360_keypad_parse_dt(pdev, max7360_keypad, &autorepeat);
+	if (error)
+		return error;
+
+	input = devm_input_allocate_device(pdev->dev.parent);
+	if (!input)
+		return dev_err_probe(&pdev->dev, -ENOMEM,
+				     "Failed to allocate input device\n");

Not sure an error message is needed.

Quoted 20 lines
drivers/input/keyboard/max7360-keypad.c new file +20 -0
+
+	max7360_keypad->input = input;
+
+	input->id.bustype = BUS_I2C;
+	input->name = pdev->name;
+	input->open = max7360_keypad_open;
+	input->close = max7360_keypad_close;
+
+	error = matrix_keypad_build_keymap(NULL, NULL,
+					   MAX7360_MAX_KEY_ROWS,
+					   MAX7360_MAX_KEY_COLS,
+					   max7360_keypad->keycodes, input);
+	if (error)
+		return dev_err_probe(&pdev->dev, error,
+				     "Failed to build keymap\n");
+
+	input_set_capability(input, EV_MSC, MSC_SCAN);
+	if (autorepeat)
+		__set_bit(EV_REP, input->evbit);
+

drivers/input/keyboard/max7360-keypad.c line 248

Quoted 10 lines
drivers/input/keyboard/max7360-keypad.c new file +10 -0
+	input_set_drvdata(input, max7360_keypad);
+
+	error = devm_request_threaded_irq(&pdev->dev, irq, NULL,
+					  max7360_keypad_irq,
+					  IRQF_TRIGGER_LOW | IRQF_ONESHOT,
+					  "max7360-keypad", max7360_keypad);
+	if (error)
+		return dev_err_probe(&pdev->dev, error,
+				     "Failed to register interrupt: %d\n",
+				     error);

No need to duplicate error.

drivers/input/keyboard/max7360-keypad.c line 254

Quoted 6 lines
drivers/input/keyboard/max7360-keypad.c new file +6 -0
+
+	error = input_register_device(input);
+	if (error)
+		return dev_err_probe(&pdev->dev, error,
+				     "Could not register input device: %d\n",
+				     error);

No need to duplicate error.

Quoted 6 lines
drivers/input/keyboard/max7360-keypad.c new file +6 -0
+
+	platform_set_drvdata(pdev, max7360_keypad);
+
+	error = max7360_keypad_hw_init(max7360_keypad);
+	if (error)
+		return dev_err_probe(&pdev->dev, error,

drivers/input/keyboard/max7360-keypad.c line 270

Quoted 10 lines
drivers/input/keyboard/max7360-keypad.c new file +10 -0
+				     "Failed to initialize max7360 keypad\n");
+
+	device_init_wakeup(&pdev->dev, true);
+	error = dev_pm_set_wake_irq(&pdev->dev, irq);
+	if (error)
+		dev_warn(&pdev->dev, "Failed to set up wakeup irq: %d\n",
+			 error);
+
+	return 0;
+}

CJ

author maintainer
#16 lore raw

PATCH v2 6/7 input: misc: Add support for MAX7360 rotary

In reply to Mathieu Dubois-Briand

Add driver for Maxim Integrated MAX7360 rotary encoder controller, supporting a single rotary switch.

---
 drivers/input/misc/Kconfig          |  11 +++
 drivers/input/misc/Makefile         |   1 +
 drivers/input/misc/max7360-rotary.c | 185 ++++++++++++++++++++++++++++++++++++
 3 files changed, 197 insertions(+)
drivers/input/misc/Kconfig +11 -0
index 6a852c76331b..8430aaf08c04 100644
@@ -230,6 +230,17 @@ config INPUT_M68K_BEEP
 	tristate "M68k Beeper support"
 	depends on M68K
 
+config INPUT_MAX7360_ROTARY
+	tristate "Maxim MAX7360 Rotary Encoder"
+	depends on I2C
+	depends on MFD_MAX7360
+	help
+	  If you say yes here you get support for the rotary encoder on the
+	  Maxim MAX7360 I/O Expander.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called max7360_rotary.
+
 config INPUT_MAX77650_ONKEY
 	tristate "Maxim MAX77650 ONKEY support"
 	depends on MFD_MAX77650
drivers/input/misc/Makefile +1 -0
index 4f7f736831ba..0ed447543e43 100644
@@ -51,6 +51,7 @@ obj-$(CONFIG_INPUT_IQS7222)		+= iqs7222.o
 obj-$(CONFIG_INPUT_KEYSPAN_REMOTE)	+= keyspan_remote.o
 obj-$(CONFIG_INPUT_KXTJ9)		+= kxtj9.o
 obj-$(CONFIG_INPUT_M68K_BEEP)		+= m68kspkr.o
+obj-$(CONFIG_INPUT_MAX7360_ROTARY)	+= max7360-rotary.o
 obj-$(CONFIG_INPUT_MAX77650_ONKEY)	+= max77650-onkey.o
 obj-$(CONFIG_INPUT_MAX77693_HAPTIC)	+= max77693-haptic.o
 obj-$(CONFIG_INPUT_MAX8925_ONKEY)	+= max8925_onkey.o
drivers/input/misc/max7360-rotary.c new file +185 -0

185 lines not on this page · raw message

Signature · 1 line
2.39.5
#17 lore raw

Re: [PATCH v2 6/7] input: misc: Add support for MAX7360 rotary

Le 23/12/2024 à 17:42, Mathieu Dubois-Briand a écrit :

Quoted 4 lines

Add driver for Maxim Integrated MAX7360 rotary encoder controller, supporting a single rotary switch.

...

drivers/input/misc/max7360-rotary.c line 35

Quoted 10 lines
drivers/input/misc/max7360-rotary.c new file +10 -0
+static irqreturn_t max7360_rotary_irq(int irq, void *data)
+{
+	struct max7360_rotary *max7360_rotary = data;
+	int val;
+	int ret;
+
+	ret = regmap_read(max7360_rotary->regmap, MAX7360_REG_RTR_CNT, &val);
+	if (ret < 0) {
+		dev_err(&max7360_rotary->input->dev,
+			"Failed to read rotary counter");

Missing \n.

drivers/input/misc/max7360-rotary.c line 41

Quoted 6 lines
drivers/input/misc/max7360-rotary.c new file +6 -0
+		return IRQ_NONE;
+	}
+
+	if (val == 0) {
+		dev_dbg(&max7360_rotary->input->dev,
+			"Got a spurious interrupt");

Missing \n.

Quoted 12 lines
drivers/input/misc/max7360-rotary.c new file +12 -0
+
+		return IRQ_NONE;
+	}
+
+	input_report_rel(max7360_rotary->input, max7360_rotary->axis,
+			 (int8_t)val);
+	input_sync(max7360_rotary->input);
+
+	return IRQ_HANDLED;
+}
+
+static int max7360_rotary_hw_init(struct max7360_rotary *max7360_rotary)

drivers/input/misc/max7360-rotary.c line 63

Quoted 10 lines
drivers/input/misc/max7360-rotary.c new file +10 -0
+{
+	int val;
+	int ret;
+
+	ret = regmap_write_bits(max7360_rotary->regmap, MAX7360_REG_GPIOCFG,
+				MAX7360_GPIO_CFG_RTR_EN,
+				MAX7360_GPIO_CFG_RTR_EN);
+	if (ret) {
+		dev_err(&max7360_rotary->input->dev,
+			"Failed to enable max7360 rotary encoder");

Missing \n.

drivers/input/misc/max7360-rotary.c line 72

Quoted 9 lines
drivers/input/misc/max7360-rotary.c new file +9 -0
+		return ret;
+	}
+
+	val = FIELD_PREP(MAX7360_ROT_DEBOUNCE, max7360_rotary->debounce_ms) |
+		FIELD_PREP(MAX7360_ROT_INTCNT, 1) | MAX7360_ROT_INTCNT_DLY;
+	ret = regmap_write(max7360_rotary->regmap, MAX7360_REG_RTRCFG, val);
+	if (ret) {
+		dev_err(&max7360_rotary->input->dev,
+			"Failed to set max7360 rotary encoder configuration");

Missing \n.

Quoted 11 lines
drivers/input/misc/max7360-rotary.c new file +11 -0
+		return ret;
+	}
+
+	return 0;
+}
+
+static int max7360_rotary_probe(struct platform_device *pdev)
+{
+	struct max7360_rotary *max7360_rotary;
+	struct input_dev *input;
+	int irq;

drivers/input/misc/max7360-rotary.c line 93

Quoted 10 lines
drivers/input/misc/max7360-rotary.c new file +10 -0
+	int ret;
+
+	if (!pdev->dev.parent)
+		return dev_err_probe(&pdev->dev, -ENODEV, "No parent device\n");
+
+	ret = max7360_port_pin_request(pdev->dev.parent, MAX7360_PORT_RTR_PIN,
+				       true);
+	if (ret)
+		dev_err_probe(&pdev->dev, ret,
+			      "Could not request rotary pin\n");

Missing return or done on purpose?

Quoted 19 lines
drivers/input/misc/max7360-rotary.c new file +19 -0
+
+	irq = platform_get_irq_byname(to_platform_device(pdev->dev.parent),
+				      "inti");
+	if (irq < 0)
+		return irq;
+
+	max7360_rotary = devm_kzalloc(&pdev->dev, sizeof(*max7360_rotary),
+				      GFP_KERNEL);
+	if (!max7360_rotary)
+		return -ENOMEM;
+
+	max7360_rotary->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!max7360_rotary->regmap)
+		dev_err_probe(&pdev->dev, -ENODEV,
+			      "Could not get parent regmap\n");
+
+	device_property_read_u32(pdev->dev.parent, "linux,axis",
+				 &max7360_rotary->axis);
+	device_property_read_u32(pdev->dev.parent, "rotary-debounce-delay-ms",

drivers/input/misc/max7360-rotary.c line 122

Quoted 10 lines
drivers/input/misc/max7360-rotary.c new file +10 -0
+				 &max7360_rotary->debounce_ms);
+	if (max7360_rotary->debounce_ms > MAX7360_ROT_DEBOUNCE_MAX)
+		return dev_err_probe(&pdev->dev, -EINVAL,
+				     "Invalid debounce timing: %u\n",
+				     max7360_rotary->debounce_ms);
+
+	input = devm_input_allocate_device(&pdev->dev);
+	if (!input)
+		return dev_err_probe(&pdev->dev, -ENOMEM,
+				     "Failed to allocate input device\n");

Not sure an error message is needed.

Quoted 7 lines
drivers/input/misc/max7360-rotary.c new file +7 -0
+
+	max7360_rotary->input = input;
+
+	input->id.bustype = BUS_I2C;
+	input->name = pdev->name;
+	input->dev.parent = &pdev->dev;
+

drivers/input/misc/max7360-rotary.c line 139

Quoted 10 lines
drivers/input/misc/max7360-rotary.c new file +10 -0
+	input_set_capability(input, EV_REL, max7360_rotary->axis);
+	input_set_drvdata(input, max7360_rotary);
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
+					max7360_rotary_irq,
+					IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED,
+					"max7360-rotary", max7360_rotary);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to register interrupt: %d\n", ret);

No need to duplicate ret.

drivers/input/misc/max7360-rotary.c line 145

Quoted 6 lines
drivers/input/misc/max7360-rotary.c new file +6 -0
+
+	ret = input_register_device(input);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Could not register input device: %d\n",
+			ret);

No need to duplicate ret.

Quoted 5 lines
drivers/input/misc/max7360-rotary.c new file +5 -0
+
+	platform_set_drvdata(pdev, max7360_rotary);
+
+	device_init_wakeup(&pdev->dev, true);
+	ret = dev_pm_set_wake_irq(&pdev->dev, irq);

drivers/input/misc/max7360-rotary.c line 160

Quoted 10 lines
drivers/input/misc/max7360-rotary.c new file +10 -0
+	if (ret)
+		dev_warn(&pdev->dev, "Failed to set up wakeup irq: %d\n", ret);
+
+	ret = max7360_rotary_hw_init(max7360_rotary);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to initialize max7360 rotary\n");
+
+	return 0;
+}

CJ

author maintainer
#18 lore raw

Re: [PATCH v2 6/7] input: misc: Add support for MAX7360 rotary

Quoted 10 lines · Christophe JAILLET

Le 23/12/2024 à 17:42, Mathieu Dubois-Briand a écrit :

Quoted 4 lines

Add driver for Maxim Integrated MAX7360 rotary encoder controller, supporting a single rotary switch.

...

CJ

Hi Christophe,

Thanks a lot for all your comments. I've integrated fixes for all of them, to be shipped with the next version.

Signature · 3 lines
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
author maintainer
#19 lore raw

PATCH v2 7/7 MAINTAINERS: Add entry on MAX7360 driver

In reply to Mathieu Dubois-Briand

Add myself as maintainer of Maxim MAX7360 driver and device-tree bindings.

---
 MAINTAINERS | 12 ++++++++++++
 1 file changed, 12 insertions(+)
MAINTAINERS +12 -0
index baf0eeb9a355..18a7b7cf0b60 100644
@@ -14132,6 +14132,18 @@ L:	[email protected]
 S:	Maintained
 F:	drivers/iio/temperature/max30208.c
 
+MAXIM MAX7360 KEYPAD LED MFD DRIVER
+M:	Mathieu Dubois-Briand <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml
+F:	Documentation/devicetree/bindings/mfd/maxim,max7360.yaml
+F:	drivers/gpio/gpio-max7360.c
+F:	drivers/input/keyboard/max7360-keypad.c
+F:	drivers/input/misc/max7360-rotary.c
+F:	drivers/mfd/max7360.c
+F:	drivers/pwm/pwm-max7360.c
+F:	include/linux/mfd/max7360.h
+
 MAXIM MAX77650 PMIC MFD DRIVER
 M:	Bartosz Golaszewski <[email protected]>
 L:	[email protected]
Signature · 1 line
2.39.5
#20 lore raw
In reply to Mathieu Dubois-Briand

Hello Mathieu,

Quoted 2 lines · Mathieu Dubois-Briand

- Removing device tree subnodes for keypad, rotary encoder and pwm functionalities.

How did you test the pwm? Just using sysfs? Without a node there is hardly any other usage left, because you cannot pass the pwm to e.g. a pwm-fan node. So it might be sensible to drop the nodes for keypad and rotary encoder, but I think you better keep the pwm one.

Best regards
Uwe

#21 lore raw

Hello Mathieu,

Quoted 8 lines · Uwe Kleine-König
Quoted 2 lines · Mathieu Dubois-Briand

- Removing device tree subnodes for keypad, rotary encoder and pwm functionalities.

How did you test the pwm? Just using sysfs? Without a node there is hardly any other usage left, because you cannot pass the pwm to e.g. a pwm-fan node. So it might be sensible to drop the nodes for keypad and rotary encoder, but I think you better keep the pwm one.

I think I was to quick here. It might just work ...

Best regards
Uwe

author maintainer
#22 lore raw
Quoted 12 lines · Uwe Kleine-König

Hello Mathieu,

Quoted 8 lines · Uwe Kleine-König
Quoted 2 lines · Mathieu Dubois-Briand

- Removing device tree subnodes for keypad, rotary encoder and pwm functionalities.

How did you test the pwm? Just using sysfs? Without a node there is hardly any other usage left, because you cannot pass the pwm to e.g. a pwm-fan node. So it might be sensible to drop the nodes for keypad and rotary encoder, but I think you better keep the pwm one.

Quoted 4 lines

I think I was to quick here. It might just work ...

Best regards
Uwe

Hi Uwe,

I also had some doubt here, keeping the node might be bit more clear but I thought you wanted me to drop it.

And yes, as you said, it does work. For reference, I test it using some pwm-led:

pwm-leds {
	compatible = "pwm-leds";

	battery {
		label = "battery";
		pwms = <&max7360 0 2000000 0>;
		max-brightness = <128>;
		linux,default-trigger = "heartbeat";
	};
};

Where &max7360 is a reference to the root node (io-expander@38 in the binding example).

Best regards,
Mathieu

Signature · 3 lines
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com