Skip to contentSkip to conversation

Add support for MAX7360

PATCH Superseded Mathieu Dubois-Briand 8 participants 69 messages Mar 18, 2025 – Mar 31, 2025

Subsystems (11)

v5 of 14 Superseded Latest is v14 →

lore
Share & tools
lore

Mathieu Dubois-Briand

author maintainer
#0 lore raw

v5 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 v5:
- Add pinctrl driver to replace the previous use of request()/free()
callbacks for PORT pins.
- Remove ngpios property from GPIO device tree bindings.
- Use GPIO valid_mask to mark unusable keypad columns GPOs, instead of
changing ngpios.
- Drop patches adding support for request()/free() callbacks in GPIO
regmap and gpio_regmap_get_ngpio().
- Allow gpio_regmap_register() to create the associated regmap IRQ.
- Various fixes in MFD, PWM, GPIO and KEYPAD drivers.
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Modified the GPIO driver to use gpio-regmap and regmap-irq.
- Add support for request()/free() callbacks in gpio-regmap.
- Add support for status_is_level in regmap-irq.
- Switched the PWM driver to waveform callbacks.
- Various small fixes in MFD, PWM, GPIO drivers and dt bindings.
- Rebased on v6.14-rc2.
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- Fix MFD device tree binding to add gpio child nodes.
- Fix various small issues in device tree bindings.
- Add missing line returns in error messages.
- Use dev_err_probe() when possible.
- Link to v2: https://lore.kernel.org/r/[email protected]

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 (9):
dt-bindings: mfd: gpio: Add MAX7360
pinctrl: Add MAX7360 pinctrl driver
regmap: irq: Add support for chips without separate IRQ status
gpio: regmap: Allow to allocate regmap-irq device
gpio: regmap: Allow to provide init_valid_mask callback
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          |  83 +++++++
 .../devicetree/bindings/mfd/maxim,max7360.yaml     | 170 +++++++++++++
 MAINTAINERS                                        |  13 +
 drivers/base/regmap/regmap-irq.c                   |  97 +++++---
 drivers/gpio/Kconfig                               |  12 +
 drivers/gpio/Makefile                              |   1 +
 drivers/gpio/gpio-max7360.c                        | 246 +++++++++++++++++++
 drivers/gpio/gpio-regmap.c                         |  26 +-
 drivers/input/keyboard/Kconfig                     |  12 +
 drivers/input/keyboard/Makefile                    |   1 +
 drivers/input/keyboard/max7360-keypad.c            | 264 +++++++++++++++++++++
 drivers/input/misc/Kconfig                         |  11 +
 drivers/input/misc/Makefile                        |   1 +
 drivers/input/misc/max7360-rotary.c                | 161 +++++++++++++
 drivers/mfd/Kconfig                                |  14 ++
 drivers/mfd/Makefile                               |   1 +
 drivers/mfd/max7360.c                              | 185 +++++++++++++++
 drivers/pinctrl/Kconfig                            |  11 +
 drivers/pinctrl/Makefile                           |   1 +
 drivers/pinctrl/pinctrl-max7360.c                  | 195 +++++++++++++++
 drivers/pwm/Kconfig                                |  11 +
 drivers/pwm/Makefile                               |   1 +
 drivers/pwm/pwm-max7360.c                          | 194 +++++++++++++++
 include/linux/gpio/regmap.h                        |  22 ++
 include/linux/mfd/max7360.h                        | 112 +++++++++
 include/linux/regmap.h                             |   3 +
 26 files changed, 1813 insertions(+), 35 deletions(-)

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

Best regards,

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

PATCH v5 1/11 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          |  83 ++++++++++
 .../devicetree/bindings/mfd/maxim,max7360.yaml     | 170 +++++++++++++++++++++
 2 files changed, 253 insertions(+)
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +83 -0
new file mode 100644
index 000000000000..21d603d9504c
@@ -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 <[email protected]>
+  - Mathieu Dubois-Briand <[email protected]>
+
+description: |
+  Maxim MAX7360 GPIO controller, in MAX7360 chipset
+  https://www.analog.com/en/products/max7360.html
+
+  The device provide two series of GPIOs, referred here as GPIOs and GPOs.
+
+  PORT0 to PORT7 pins can be used as GPIOs, with support for interrupts and
+  constant-current mode. These pins will also be used by the torary encoder and
+  PWM functionalities.
+
+  COL2 to COL7 pins can be used as GPOs, there is no input capability. COL pins
+  will be partitionned, with the first pins being affected to the keypad
+  functionality and the last ones as GPOs.
+
+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 associated
+      GPIO, starting from the least significant bit for the first GPIO.
+    maximum: 0xff
+
+required:
+  - compatible
+  - gpio-controller
+
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - maxim,max7360-gpio
+        ngpios: false
+    then:
+      required:
+        - interrupt-controller
+    else:
+      properties:
+        interrupt-controller: false
+        maxim,constant-current-disable: false
+
+additionalProperties: false
+
+examples:
+  - |
+    gpio {
+      compatible = "maxim,max7360-gpio";
+
+      gpio-controller;
+      #gpio-cells = <2>;
+      maxim,constant-current-disable = <0x06>;
+
+      interrupt-controller;
+      #interrupt-cells = <2>;
+    };
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +170 -0

170 lines not on this page · raw message

Signature · 1 line
2.39.5
maintainer
#2 lore raw

Re: [PATCH v5 01/11] dt-bindings: mfd: gpio: Add MAX7360

Quoted 136 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          |  83 ++++++++++
 .../devicetree/bindings/mfd/maxim,max7360.yaml     | 170 +++++++++++++++++++++
 2 files changed, 253 insertions(+)
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +83 -0
new file mode 100644
index 000000000000..21d603d9504c
@@ -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 <[email protected]>
+  - Mathieu Dubois-Briand <[email protected]>
+
+description: |
+  Maxim MAX7360 GPIO controller, in MAX7360 chipset
+  https://www.analog.com/en/products/max7360.html
+
+  The device provide two series of GPIOs, referred here as GPIOs and GPOs.
+
+  PORT0 to PORT7 pins can be used as GPIOs, with support for interrupts and
+  constant-current mode. These pins will also be used by the torary encoder and
+  PWM functionalities.
+
+  COL2 to COL7 pins can be used as GPOs, there is no input capability. COL pins
+  will be partitionned, with the first pins being affected to the keypad
+  functionality and the last ones as GPOs.
+
+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 associated
+      GPIO, starting from the least significant bit for the first GPIO.
+    maximum: 0xff
+
+required:
+  - compatible
+  - gpio-controller
+
+allOf:
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
+              - maxim,max7360-gpio
+        ngpios: false
+    then:
+      required:
+        - interrupt-controller
+    else:
+      properties:
+        interrupt-controller: false
+        maxim,constant-current-disable: false
+
+additionalProperties: false
+
+examples:
+  - |
+    gpio {
+      compatible = "maxim,max7360-gpio";
+
+      gpio-controller;
+      #gpio-cells = <2>;
+      maxim,constant-current-disable = <0x06>;
+
+      interrupt-controller;
+      #interrupt-cells = <2>;
+    };
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +32 -0
new file mode 100644
index 000000000000..d3c09531dc5c
@@ -0,0 +1,170 @@
+# 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
+
+  reg:
+    maxItems: 1

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

Quoted 10 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +10 -0
+
+  interrupts:
+    maxItems: 2
+
+  interrupt-names:
+    items:
+      - const: inti
+      - const: intk
+
+  keypad-debounce-delay-ms:

The existing debounce-delay-ms or poll-interval properties don't work for you?

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

Quoted 13 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +13 -0
+    description: Keypad debounce delay in ms
+    minimum: 9
+    maximum: 40
+    default: 9
+
+  rotary-debounce-delay-ms:
+    description: Rotary encoder debounce delay in ms
+    minimum: 0
+    maximum: 15
+    default: 0
+
+  linux,axis:
+    description: The input subsystem axis to map to this rotary encoder.

You should have a $ref to rotary-encoder.yaml too. None of the other properties in it are needed?

Quoted 4 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +4 -0
+
+  "#pwm-cells":
+    const: 3
+

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

Quoted 10 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +10 -0
+  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.

Are these paragraphs? If so, add a blank line between paragraphs. If not, re-wrap the lines.

Quoted 10 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +10 -0
+      The MAX7360 has 8 column lines and 6 of them can be used as GPOs. GPIOs
+      numbers used for this gpio-controller node do correspond to the column
+      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 configuration.

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

Quoted 10 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +10 -0
+      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$'

Don't you need ()?:

^(PORT[0-7]|ROTARY)$'

Quoted 85 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +81 -0
+        minItems: 1
+        maxItems: 8
+
+      function:
+        description:
+          Specify the alternative function to be configured for the specified
+          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 <dt-bindings/input/input.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      io-expander@38 {
+        compatible = "maxim,max7360";
+        reg = <0x38>;
+
+        interrupt-parent = <&gpio1>;
+        interrupts = <23 IRQ_TYPE_LEVEL_LOW>,
+                     <24 IRQ_TYPE_LEVEL_LOW>;
+        interrupt-names = "inti", "intk";
+
+        keypad,num-rows = <8>;
+        keypad,num-columns = <4>;
+        linux,keymap = <
+          MATRIX_KEY(0x00, 0x00, KEY_F5)
+          MATRIX_KEY(0x01, 0x00, KEY_F4)
+          MATRIX_KEY(0x02, 0x01, KEY_F6)
+          >;
+        keypad-debounce-delay-ms = <10>;
+        autorepeat;
+
+        rotary-debounce-delay-ms = <2>;
+        linux,axis = <0>; /* REL_X */
+
+        #pwm-cells = <3>;
+
+        max7360_gpio: gpio {
+          compatible = "maxim,max7360-gpio";
+
+          gpio-controller;
+          #gpio-cells = <2>;
+          maxim,constant-current-disable = <0x06>;
+
+          interrupt-controller;
+          #interrupt-cells = <0x2>;
+        };
+
+        max7360_gpo: gpo {
+          compatible = "maxim,max7360-gpo";
+
+          gpio-controller;
+          #gpio-cells = <2>;
+        };
+
+        backlight_pins: backlight-pins {
+          pins = "PORT2";
+          function = "pwm";
+        };
+      };
+    };
Signature · 2 lines
-- 
2.39.5
author maintainer
#3 lore raw

Re: [PATCH v5 01/11] dt-bindings: mfd: gpio: Add MAX7360

Quoted 17 lines · Rob Herring
Quoted 16 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          |  83 ++++++++++
 .../devicetree/bindings/mfd/maxim,max7360.yaml     | 170 +++++++++++++++++++++
 2 files changed, 253 insertions(+)
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +1 -0
new file mode 100644
index 000000000000..21d603d9504c
@@ -0,0 +1,83 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)

...

Quoted 6 lines

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

Quoted 2 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +2 -0
+
+  keypad-debounce-delay-ms:

The existing debounce-delay-ms or poll-interval properties don't work for you?

The issue is this node also describes the rotary encoder (just below), so I feel using only debounce-delay-ms is a bit misleading.

Quoted 8 lines
Quoted 8 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +8 -0
+    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
Quoted 8 lines

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

Quoted 5 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +5 -0
+    maximum: 15
+    default: 0
+
+  linux,axis:
+    description: The input subsystem axis to map to this rotary encoder.

You should have a $ref to rotary-encoder.yaml too. None of the other properties in it are needed?

Makes sense, thanks!

And no, I believe this is the only property we need.

Quoted 10 lines
Quoted 10 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +9 -0
+
+  "#pwm-cells":
+    const: 3
+
+  gpio:
+    $ref: /schemas/gpio/maxim,max7360-gpio.yaml#
+    description:
+      PORT0 to PORT7 general purpose input/output pins configuration.
+
Quoted 9 lines

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

Quoted 5 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +5 -0
+  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.

Are these paragraphs? If so, add a blank line between paragraphs. If not, re-wrap the lines.

OK

Quoted 23 lines
Quoted 10 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +10 -0
+      The MAX7360 has 8 column lines and 6 of them can be used as GPOs. GPIOs
+      numbers used for this gpio-controller node do correspond to the column
+      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 configuration.

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

Quoted 10 lines
Documentation/devicetree/bindings/gpio/maxim,max7360-gpio.yaml new file +10 -0
+      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$'

Don't you need ()?:

Quoted 2 lines

^(PORT[0-7]|ROTARY)$'

Yes!

Thanks for your review.
Mathieu

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

Re: [PATCH v5 01/11] dt-bindings: mfd: gpio: Add MAX7360

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

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

---

Hi,

Following discussion we had under the PWM patch of this series, we might need to refactor a bit the device tree binding architecture, adding two new subnodes, one for pinctrl and one for PWM.

This will need create two new compatible values with associated bindings and modify a bit the properties of the maxim,max7360.yaml binding.

Here is the example modified to reflect what I have in mind.

Quoted 32 lines

...

Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +21 -0
new file mode 100644
index 000000000000..d3c09531dc5c
@@ -0,0 +1,170 @@
 
...
 
+examples:
+  - |
+    #include <dt-bindings/input/input.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      io-expander@38 {
+        compatible = "maxim,max7360";
+        reg = <0x38>;
+
+        interrupt-parent = <&gpio1>;
+        interrupts = <23 IRQ_TYPE_LEVEL_LOW>,
+                     <24 IRQ_TYPE_LEVEL_LOW>;
+        interrupt-names = "inti", "intk";
+
+        keypad,num-rows = <8>;
+        keypad,num-columns = <4>;
+        linux,keymap = <

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

Quoted 10 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +10 -0
+          MATRIX_KEY(0x00, 0x00, KEY_F5)
+          MATRIX_KEY(0x01, 0x00, KEY_F4)
+          MATRIX_KEY(0x02, 0x01, KEY_F6)
+          >;
+        keypad-debounce-delay-ms = <10>;
+        autorepeat;
+
+        rotary-debounce-delay-ms = <2>;
+        linux,axis = <0>; /* REL_X */
+

+ max7360_pwm: pwm {
+ compatible = "maxim,max7360-pwm";

Quoted 1 line

+ #pwm-cells = <3>;

+ };

Quoted 8 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +8 -0
+
+        max7360_gpio: gpio {
+          compatible = "maxim,max7360-gpio";
+
+          gpio-controller;
+          #gpio-cells = <2>;
+          maxim,constant-current-disable = <0x06>;
+

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

Quoted 10 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +10 -0
+          interrupt-controller;
+          #interrupt-cells = <0x2>;
+        };
+
+        max7360_gpo: gpo {
+          compatible = "maxim,max7360-gpo";
+
+          gpio-controller;
+          #gpio-cells = <2>;
+        };

+ pinctrl {
+ compatible = "maxim,max7360-pinctrl";

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

Quoted 5 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +5 -0
+
+        backlight_pins: backlight-pins {
+          pins = "PORT2";
+          function = "pwm";
+        };

+ };

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

Quoted 2 lines
Documentation/devicetree/bindings/mfd/maxim,max7360.yaml new file +2 -0
+      };
+    };

This would allow to assign a device tree node to both the pinctrl and the PWM devices in the kernel?

Is there any comment regarding this proposal? Without any specific comment, I will send a new version with these changes in a few days.

Best regards,
Mathieu

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

PATCH v5 2/11 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         |  14 ++++
 drivers/mfd/Makefile        |   1 +
 drivers/mfd/max7360.c       | 185 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mfd/max7360.h | 112 +++++++++++++++++++++++++++
 4 files changed, 312 insertions(+)
drivers/mfd/Kconfig +14 -0
index 6b0682af6e32..ef02a1c4322c 100644
@@ -2439,5 +2439,19 @@ config MFD_UPBOARD_FPGA
 	  To compile this driver as a module, choose M here: the module will be
 	  called upboard-fpga.
 
+config MFD_MAX7360
+	tristate "Maxim MAX7360 I2C IO Expander"
+	depends on I2C
+	select MFD_CORE
+	select REGMAP_I2C
+	select REGMAP_IRQ
+	help
+	  Say yes here to add support for Maxim MAX7360 device, embedding
+	  keypad, rotary encoder, PWM and GPIO features.
+
+	  This driver provides common support for accessing the device;
+	  additional drivers must be enabled in order to use the functionality
+	  of the device.
+
 endmenu
 endif
drivers/mfd/Makefile +1 -0
index 9220eaf7cf12..db2bd232c150 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 +185 -0

185 lines not on this page · raw message

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

112 lines not on this page · raw message

Signature · 1 line
2.39.5
#6 lore raw

Re: [PATCH v5 02/11] mfd: Add max7360 support

Quoted 4 lines · On Tue, Mar 18, 2025 at 05:26:18PM +0100, [email protected]…

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.

...

+ array_size.h

drivers/mfd/max7360.c line 13

Quoted 4 lines
drivers/mfd/max7360.c new file +3 -0
+#include <linux/bits.h>
+#include <linux/delay.h>
 
+#include <linux/device.h>

Since it won;t make v6.15-rc1 anyway the above can be better specified as

device/devres.h
dev_printk.h

as device.h is monstrous.

+ err.h

drivers/mfd/max7360.c line 17

Quoted 4 lines
drivers/mfd/max7360.c new file +4 -0
+#include <linux/i2c.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/core.h>
+#include <linux/mfd/max7360.h>

+ mod_devicetable.h

Quoted 3 lines
drivers/mfd/max7360.c new file +3 -0
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/types.h>

...

drivers/mfd/max7360.c line 103

Quoted 2 lines
drivers/mfd/max7360.c new file +2 -0
+	ret = regmap_write(regmap, MAX7360_REG_GPIOCFG,
+			   MAX7360_GPIO_CFG_GPIO_RST);

I would suggest to leave it as a single line. In this and similar cases when it is ~83 characters, it's still fine (and even for strict 80 there is a documented exception)

...

drivers/mfd/max7360.c line 128

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

Just

	return ret;

?

drivers/mfd/max7360.c line 157

Quoted 3 lines
drivers/mfd/max7360.c new file +3 -0
+	ret = max7360_mask_irqs(regmap);
+	if (ret)
+		return dev_err_probe(dev, ret, "Could not mask interrupts\n");

Hmm... As far as I can read this masks GPIO interrups. Does it do anything else? If it's covered by the GPIO/pin control drivers, one want probably to see that to be done there in the respective callback (init_hw_irq or alike, I don't remember the name by heart).

...

include/linux/mfd/max7360.h line 7

Quoted 6 lines
include/linux/mfd/max7360.h new file +5 -0
+#ifndef __LINUX_MFD_MAX7360_H
+#define __LINUX_MFD_MAX7360_H
+
+#include <linux/bits.h>
 
+#include <linux/types.h>

Do you need types.h here? I don't see for what...

Quoted 1 line

+struct device;

Neither this. Perhaps it's for the following changes? Then add when required, not now.

Quoted 1 line

+#endif

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

Re: [PATCH v5 02/11] mfd: Add max7360 support

Quoted 11 lines · Andy Shevchenko

drivers/mfd/max7360.c line 157

Quoted 4 lines · On Tue, Mar 18, 2025 at 05:26:18PM +0100, [email protected]…

From: Kamel Bouhara <[email protected]>

drivers/mfd/max7360.c new file +3 -0
+	ret = max7360_mask_irqs(regmap);
+	if (ret)
+		return dev_err_probe(dev, ret, "Could not mask interrupts\n");

Hmm... As far as I can read this masks GPIO interrups. Does it do anything else? If it's covered by the GPIO/pin control drivers, one want probably to see that to be done there in the respective callback (init_hw_irq or alike, I don't remember the name by heart).

Hum, I'm not sure I can do that.

So the "inti" interrupt line is shared across the GPIO and the rotary encoder functionalities.

On reset, GPIO interrupts are not masked. This means, if we do the masking in the GPIO driver and the GPIO driver is not loaded but the rotary encoder driver is, the rotary encoder driver might get a lot of spurious interrupts.

So I believe it makes sense to mask the interrupts here, setting the chip in a sane configuration, whatever child drivers are present.

Any thought about that?

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

Re: [PATCH v5 02/11] mfd: Add max7360 support

Quoted 22 lines · Mathieu Dubois-Briand
Quoted 10 lines · Andy Shevchenko

drivers/mfd/max7360.c line 157

Quoted 4 lines · On Tue, Mar 18, 2025 at 05:26:18PM +0100, [email protected]…

From: Kamel Bouhara <[email protected]>

drivers/mfd/max7360.c new file +3 -0
+	ret = max7360_mask_irqs(regmap);
+	if (ret)
+		return dev_err_probe(dev, ret, "Could not mask interrupts\n");

Hmm... As far as I can read this masks GPIO interrups. Does it do anything else? If it's covered by the GPIO/pin control drivers, one want probably to see that to be done there in the respective callback (init_hw_irq or alike, I don't remember the name by heart).

Hum, I'm not sure I can do that.

So the "inti" interrupt line is shared across the GPIO and the rotary encoder functionalities.

On reset, GPIO interrupts are not masked. This means, if we do the masking in the GPIO driver and the GPIO driver is not loaded but the rotary encoder driver is, the rotary encoder driver might get a lot of spurious interrupts.

Quoted 4 lines

So I believe it makes sense to mask the interrupts here, setting the chip in a sane configuration, whatever child drivers are present.

Any thought about that?

Okay, this makes sense. I forgot if you have any comment in the code (probably not if I asked the question), but in any case the above can be added on top of the function explaining this.

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

PATCH v5 3/11 pinctrl: Add MAX7360 pinctrl driver

In reply to Mathieu Dubois-Briand

Add driver for Maxim Integrated MAX7360 pinctrl on the PORT pins. Pins can be used either for GPIO, PWM or rotary encoder functionalities.

---
 drivers/pinctrl/Kconfig           |  11 +++
 drivers/pinctrl/Makefile          |   1 +
 drivers/pinctrl/pinctrl-max7360.c | 195 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 207 insertions(+)
drivers/pinctrl/Kconfig +11 -0
index 95a8e2b9a614..cf178ef44d5d 100644
@@ -334,6 +334,17 @@ config PINCTRL_LPC18XX
 	help
 	  Pinctrl driver for NXP LPC18xx/43xx System Control Unit (SCU).
 
+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 work as GPIO as well as
+	  PWM or rotary encoder alternate modes.
+
 config PINCTRL_MAX77620
 	tristate "MAX77620/MAX20024 Pincontrol support"
 	depends on MFD_MAX77620 && OF
drivers/pinctrl/Makefile +1 -0
index fba1c56624c0..f46209b7c930 100644
@@ -35,6 +35,7 @@ obj-$(CONFIG_PINCTRL_FALCON)	+= pinctrl-falcon.o
 obj-$(CONFIG_PINCTRL_LOONGSON2) += pinctrl-loongson2.o
 obj-$(CONFIG_PINCTRL_XWAY)	+= pinctrl-xway.o
 obj-$(CONFIG_PINCTRL_LPC18XX)	+= pinctrl-lpc18xx.o
+obj-$(CONFIG_PINCTRL_MAX7360)	+= pinctrl-max7360.o
 obj-$(CONFIG_PINCTRL_MAX77620)	+= pinctrl-max77620.o
 obj-$(CONFIG_PINCTRL_MCP23S08_I2C)	+= pinctrl-mcp23s08_i2c.o
 obj-$(CONFIG_PINCTRL_MCP23S08_SPI)	+= pinctrl-mcp23s08_spi.o
drivers/pinctrl/pinctrl-max7360.c new file +195 -0

195 lines not on this page · raw message

Signature · 1 line
2.39.5
Reviewed-by on v5 3/11
#10 lore raw

Re: [PATCH v5 03/11] pinctrl: Add MAX7360 pinctrl driver

Hi Mathieu,

thanks for your patch!

Quoted 4 lines · Mathieu Dubois-Briand

Add driver for Maxim Integrated MAX7360 pinctrl on the PORT pins. Pins can be used either for GPIO, PWM or rotary encoder functionalities.

Overall it's a clean and simple pin control driver, so:

Yours,
Linus Walleij

#11 lore raw

Re: [PATCH v5 03/11] pinctrl: Add MAX7360 pinctrl driver

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

Add driver for Maxim Integrated MAX7360 pinctrl on the PORT pins. Pins can be used either for GPIO, PWM or rotary encoder functionalities.

...

drivers/pinctrl/Kconfig config PINCTRL_LPC18XX · line 343

Quoted 2 lines
drivers/pinctrl/Kconfig +2 -0
+	help
+	  Say Y here to enable Pin control support for Maxim MAX7360 keypad

s/Pin/pin/

drivers/pinctrl/Kconfig config PINCTRL_LPC18XX · line 345

Quoted 2 lines
drivers/pinctrl/Kconfig +2 -0
+	  controller.
+	  This keypad controller has 8 GPIO pins that work as GPIO as well as

"...that may work as GPIO, or PWM, or..."

drivers/pinctrl/Kconfig config PINCTRL_LPC18XX · line 346

Quoted 1 line
drivers/pinctrl/Kconfig +1 -0
+	  PWM or rotary encoder alternate modes.

...

+ array_size.h
+ dev_printk.h
+ device/devres.h // currently only in Linux Next
+ err.h

drivers/pinctrl/pinctrl-max7360.c line 14

Quoted 8 lines
drivers/pinctrl/pinctrl-max7360.c new file +7 -0
+#include <linux/init.h>
+#include <linux/mfd/max7360.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
 
+#include <linux/pinctrl/pinctrl.h>
+#include <linux/pinctrl/pinconf-generic.h>
+#include <linux/pinctrl/pinmux.h>

We usually move this group of inclusions...

drivers/pinctrl/pinctrl-max7360.c line 16

Quoted 2 lines
drivers/pinctrl/pinctrl-max7360.c new file +2 -0
+#include <linux/regmap.h>
+#include <linux/slab.h>

...to somewhere here.

Quoted 2 lines
drivers/pinctrl/pinctrl-max7360.c new file +2 -0
+#include "core.h"
+#include "pinmux.h"

...

drivers/pinctrl/pinctrl-max7360.c line 56

Quoted 10 lines
drivers/pinctrl/pinctrl-max7360.c new file +10 -0
+static const struct pingroup max7360_groups[] = {
+	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))

Leave trailing comma. Helps in the future in case of expansion.

Quoted 1 line

+};

...

drivers/pinctrl/pinctrl-max7360.c line 91

Quoted 2 lines
drivers/pinctrl/pinctrl-max7360.c new file +2 -0
+static const char * const simple_groups[] = {"PORT0", "PORT1", "PORT2", "PORT3",
+					     "PORT4", "PORT5", "PORT6", "PORT7"};

It's better to read when split as

static const char * const simple_groups[] = {
	"PORT0", "PORT1", "PORT2", "PORT3",
	"PORT4", "PORT5", "PORT6", "PORT7",
};

(also note the trailing comma).

…

Quoted 1 line

+static const char * const rotary_groups[] = {"ROTARY"};

Add spaces inside {}.

...

drivers/pinctrl/pinctrl-max7360.c line 99

Quoted 6 lines
drivers/pinctrl/pinctrl-max7360.c new file +6 -0
+#define MAX7360_PINCTRL_FN_ROTARY	2
+static const struct pinfunction max7360_functions[] = {
+	PINCTRL_PINFUNCTION("gpio", simple_groups, ARRAY_SIZE(simple_groups)),
+	PINCTRL_PINFUNCTION("pwm", simple_groups, ARRAY_SIZE(simple_groups)),
+	[MAX7360_PINCTRL_FN_ROTARY] = PINCTRL_PINFUNCTION("rotary", rotary_groups,
+							  ARRAY_SIZE(rotary_groups)),

Please make them all look the same, if indexed, than add indices to all.

Quoted 1 line

+};

...

drivers/pinctrl/pinctrl-max7360.c line 126

Quoted 6 lines
drivers/pinctrl/pinctrl-max7360.c new file +5 -0
+static int max7360_set_mux(struct pinctrl_dev *pctldev, unsigned int selector,
+			   unsigned int group)
+{
+	struct regmap *regmap;
 
+	int ret = 0;

Variable is not needed, just return directly.

Quoted 18 lines
drivers/pinctrl/pinctrl-max7360.c new file +18 -0
+	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] >= 6) {
+		if (selector == MAX7360_PINCTRL_FN_ROTARY)
+			val = MAX7360_GPIO_CFG_RTR_EN;
+		else
+			val = 0;
+
+		regmap = dev_get_regmap(pctldev->dev, NULL);
+		ret = regmap_write_bits(regmap, MAX7360_REG_GPIOCFG, MAX7360_GPIO_CFG_RTR_EN, val);
+	}
+
+	return ret;
+}

...

drivers/pinctrl/pinctrl-max7360.c line 155

Quoted 2 lines
drivers/pinctrl/pinctrl-max7360.c new file +2 -0
+static int max7360_pinctrl_probe(struct platform_device *pdev)
+{

With

	struct device *dev = &pdev->dev;

the below will look better.

drivers/pinctrl/pinctrl-max7360.c line 166

Quoted 11 lines
drivers/pinctrl/pinctrl-max7360.c new file +11 -0
+	struct regmap *regmap;
+	struct pinctrl_desc *pd;
+	struct max7360_pinctrl *chip;
+
+	chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
+	if (!chip)
+		return -ENOMEM;
+
+	regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!regmap)
+		dev_err_probe(&pdev->dev, -ENODEV, "Could not get parent regmap\n");

Make it first check, in such a case you don't even need to allocate memory for peanuts.

Quoted 16 lines
drivers/pinctrl/pinctrl-max7360.c new file +16 -0
+	pd = &chip->pinctrl_desc;
+
+	pd->pctlops = &max7360_pinctrl_ops;
+	pd->pmxops = &max7360_pmxops;
+	pd->name = dev_name(&pdev->dev);
+	pd->pins = max7360_pins;
+	pd->npins = MAX7360_MAX_GPIO;
+	pd->owner = THIS_MODULE;
+
+	chip->pctldev = devm_pinctrl_register(pdev->dev.parent, pd, chip);
+	if (IS_ERR(chip->pctldev))
+		return dev_err_probe(&pdev->dev, PTR_ERR(chip->pctldev),
+			"can't register controller\n");
+
+	return 0;
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#12 lore raw

PATCH v5 4/11 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 | 194 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 206 insertions(+)
drivers/pwm/Kconfig +11 -0
index 0915c1e7df16..930cc7c61b82 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
+	select PINCTRL_MAX7360
+	help
+	  PWM driver for Maxim Integrated MAX7360 multifunction device, with
+	  support for up to 8 PWM outputs.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called pwm-max7360.
+
 endif
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 +194 -0

194 lines not on this page · raw message

Signature · 1 line
2.39.5
#13 lore raw

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

Quoted 4 lines · On Tue, Mar 18, 2025 at 05:26:20PM +0100, [email protected]…

From: Kamel Bouhara <[email protected]>

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

...

Quoted 13 lines
drivers/pwm/pwm-max7360.c new file +13 -0
+#include <linux/bits.h>
+#include <linux/dev_printk.h>
+#include <linux/err.h>
+#include <linux/math64.h>
+#include <linux/mfd/max7360.h>
+#include <linux/minmax.h>
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/pwm.h>
+#include <linux/regmap.h>
+#include <linux/time.h>
+#include <linux/types.h>

...

drivers/pwm/pwm-max7360.c line 61

Quoted 7 lines
drivers/pwm/pwm-max7360.c new file +7 -0
+static void max7360_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
+{
+	struct regmap *regmap;
+	struct device *dev;
+
+	regmap = pwmchip_get_drvdata(chip);
+	dev = regmap_get_device(regmap);

Huh?!

Quoted 1 line

+}

...

drivers/pwm/pwm-max7360.c line 67

Quoted 4 lines
drivers/pwm/pwm-max7360.c new file +4 -0
+static int max7360_pwm_round_waveform_tohw(struct pwm_chip *chip,
+					   struct pwm_device *pwm,
+					   const struct pwm_waveform *wf,
+					   void *_wfhw)

I would expect other way around, i.e. naming with leading underscore(s) to be private / local. Ditto for all similar cases.

...

drivers/pwm/pwm-max7360.c line 108

Quoted 11 lines
drivers/pwm/pwm-max7360.c new file +11 -0
+static int max7360_pwm_write_waveform(struct pwm_chip *chip,
+				      struct pwm_device *pwm,
+				      const void *_wfhw)
+{
+	const struct max7360_pwm_waveform *wfhw = _wfhw;
+	struct regmap *regmap;
+	unsigned int val;
+	int ret;
+
+	regmap = pwmchip_get_drvdata(chip);
+	val = (wfhw->enabled) ? BIT(pwm->hwpwm) : 0;

Redundant parentheses.

Quoted 9 lines
drivers/pwm/pwm-max7360.c new file +9 -0
+	ret = regmap_write_bits(regmap, MAX7360_REG_GPIOCTRL, BIT(pwm->hwpwm), val);
+	if (ret)
+		return ret;
+
+	if (wfhw->duty_steps)
+		return regmap_write(regmap, MAX7360_REG_PWM(pwm->hwpwm), wfhw->duty_steps);
+
+	return 0;
+}

...

Quoted 7 lines
drivers/pwm/pwm-max7360.c new file +7 -0
+static int max7360_pwm_read_waveform(struct pwm_chip *chip,
+				     struct pwm_device *pwm,
+				     void *_wfhw)
+{
+	struct max7360_pwm_waveform *wfhw = _wfhw;
+	struct regmap *regmap;
+	unsigned int val;

drivers/pwm/pwm-max7360.c line 135

Quoted 10 lines
drivers/pwm/pwm-max7360.c new file +10 -0
+	int ret;
+
+	regmap = pwmchip_get_drvdata(chip);
+
+	ret = regmap_read(regmap, MAX7360_REG_GPIOCTRL, &val);
+	if (ret)
+		return ret;
+
+	if (val & BIT(pwm->hwpwm)) {
+		wfhw->enabled = true;

Also can be (but up to you)

	wfhw->enabled = val & BIT(pwm->hwpwm);
	if (wfhw->enabled) {

And also see below. Perhaps it is not a good suggestion after all.

drivers/pwm/pwm-max7360.c line 137

Quoted 2 lines
drivers/pwm/pwm-max7360.c new file +2 -0
+		ret = regmap_read(regmap, MAX7360_REG_PWM(pwm->hwpwm), &val);
+		wfhw->duty_steps = val;

Set to a garbage in case of error, why?

Quoted 7 lines
drivers/pwm/pwm-max7360.c new file +7 -0
+	} else {
+		wfhw->enabled = false;
+		wfhw->duty_steps = 0;
+	}
+
+	return ret;
+}

...

drivers/pwm/pwm-max7360.c line 163

Quoted 9 lines
drivers/pwm/pwm-max7360.c new file +9 -0
+static int max7360_pwm_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct pwm_chip *chip;
+	struct regmap *regmap;
+	int ret;
+
+	if (!dev->parent)
+		return dev_err_probe(dev, -ENODEV, "no parent device\n");

Why? Code most likely will fail on the regmap retrieval. Just do that first.

drivers/pwm/pwm-max7360.c line 165

Quoted 1 line
drivers/pwm/pwm-max7360.c new file +1 -0
+	chip = devm_pwmchip_alloc(dev->parent, MAX7360_NUM_PWMS, 0);

This is quite worrying. The devm_ to parent makes a lot of assumptions that may not be realised. If you really need this, it has to have a very good comment explaining why and object lifetimes.

Quoted 16 lines
drivers/pwm/pwm-max7360.c new file +16 -0
+	if (IS_ERR(chip))
+		return PTR_ERR(chip);
+	chip->ops = &max7360_pwm_ops;
+
+	regmap = dev_get_regmap(dev->parent, NULL);
+	if (!regmap)
+		return dev_err_probe(dev, -ENODEV, "could not get parent regmap\n");
+
+	pwmchip_set_drvdata(chip, regmap);
+
+	ret = devm_pwmchip_add(dev, chip);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to add PWM chip\n");
+
+	return 0;
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#14 lore raw

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

Quoted 8 lines · Andy Shevchenko

drivers/pwm/pwm-max7360.c line 67

Quoted 4 lines · On Tue, Mar 18, 2025 at 05:26:20PM +0100, [email protected]…
drivers/pwm/pwm-max7360.c new file +4 -0
+static int max7360_pwm_round_waveform_tohw(struct pwm_chip *chip,
+					   struct pwm_device *pwm,
+					   const struct pwm_waveform *wf,
+					   void *_wfhw)

I would expect other way around, i.e. naming with leading underscore(s) to be private / local. Ditto for all similar cases.

I guess that one of the other waveform drivers is the source of that. I chose to name the void pointer with the underscore because I consider that the strange one that has the void* type for technical reasons. That's obviously subjective, but I'm happy with that choice.

Quoted 12 lines

drivers/pwm/pwm-max7360.c line 163

Quoted 9 lines
drivers/pwm/pwm-max7360.c new file +9 -0
+static int max7360_pwm_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct pwm_chip *chip;
+	struct regmap *regmap;
+	int ret;
+
+	if (!dev->parent)
+		return dev_err_probe(dev, -ENODEV, "no parent device\n");

Why? Code most likely will fail on the regmap retrieval. Just do that first.

Quoted 5 lines

drivers/pwm/pwm-max7360.c line 165

Quoted 1 line
drivers/pwm/pwm-max7360.c new file +1 -0
+	chip = devm_pwmchip_alloc(dev->parent, MAX7360_NUM_PWMS, 0);

This is quite worrying. The devm_ to parent makes a lot of assumptions that may not be realised. If you really need this, it has to have a very good comment explaining why and object lifetimes.

Pretty sure this is broken. This results for example in the device link being created on the parent. So if the pwm devices goes away a consumer might not notice (at least in the usual way). I guess this was done to ensure that #pwm-cells is parsed from the right dt node? If so, that needs a different adaption. That will probably involve calling device_set_of_node_from_dev().

Best regards
Uwe

#15 lore raw

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

Quoted 2 lines · Uwe Kleine-König
Quoted 1 line · Andy Shevchenko

On Tue, Mar 18, 2025 at 05:26:20PM +0100, [email protected] wrote:

...

Quoted 6 lines
Quoted 5 lines

drivers/pwm/pwm-max7360.c line 165

Quoted 1 line
drivers/pwm/pwm-max7360.c new file +1 -0
+	chip = devm_pwmchip_alloc(dev->parent, MAX7360_NUM_PWMS, 0);

This is quite worrying. The devm_ to parent makes a lot of assumptions that may not be realised. If you really need this, it has to have a very good comment explaining why and object lifetimes.

Quoted 6 lines

Pretty sure this is broken. This results for example in the device link being created on the parent. So if the pwm devices goes away a consumer might not notice (at least in the usual way). I guess this was done to ensure that #pwm-cells is parsed from the right dt node? If so, that needs a different adaption. That will probably involve calling device_set_of_node_from_dev().

It's an MFD based driver, and MFD core cares about propagating fwnode by default. I believe it should just work if we drop that '->parent' part.

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

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

Quoted 19 lines · Andy Shevchenko
Quoted 2 lines · Uwe Kleine-König
Quoted 1 line · Andy Shevchenko

On Tue, Mar 18, 2025 at 05:26:20PM +0100, [email protected] wrote:

...

Quoted 6 lines
Quoted 5 lines

drivers/pwm/pwm-max7360.c line 165

Quoted 1 line
drivers/pwm/pwm-max7360.c new file +1 -0
+	chip = devm_pwmchip_alloc(dev->parent, MAX7360_NUM_PWMS, 0);

This is quite worrying. The devm_ to parent makes a lot of assumptions that may not be realised. If you really need this, it has to have a very good comment explaining why and object lifetimes.

Quoted 6 lines

Pretty sure this is broken. This results for example in the device link being created on the parent. So if the pwm devices goes away a consumer might not notice (at least in the usual way). I guess this was done to ensure that #pwm-cells is parsed from the right dt node? If so, that needs a different adaption. That will probably involve calling device_set_of_node_from_dev().

Quoted 2 lines

It's an MFD based driver, and MFD core cares about propagating fwnode by default. I believe it should just work if we drop that '->parent' part.

Are you sure about that?

On my side it does not work if I just drop the '->parent', this is why I ended whit this (bad) pattern.

Now it does work if I do call device_set_of_node_from_dev() manually, so it's definitely better. But I believe the MFD core is not propagating OF data, and I did not find where it would do that in the code. Yet it does something like this for ACPI in mfd_acpi_add_device(). Or maybe we do something bad in our MFD driver?

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

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

Quoted 4 lines · Mathieu Dubois-Briand
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Uwe Kleine-König
Quoted 1 line · Andy Shevchenko

On Tue, Mar 18, 2025 at 05:26:20PM +0100, [email protected] wrote:

...

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 5 lines

drivers/pwm/pwm-max7360.c line 165

Quoted 1 line
drivers/pwm/pwm-max7360.c new file +1 -0
+	chip = devm_pwmchip_alloc(dev->parent, MAX7360_NUM_PWMS, 0);

This is quite worrying. The devm_ to parent makes a lot of assumptions that may not be realised. If you really need this, it has to have a very good comment explaining why and object lifetimes.

Pretty sure this is broken. This results for example in the device link being created on the parent. So if the pwm devices goes away a consumer might not notice (at least in the usual way). I guess this was done to ensure that #pwm-cells is parsed from the right dt node? If so, that needs a different adaption. That will probably involve calling device_set_of_node_from_dev().

Quoted 4 lines
Quoted 2 lines

It's an MFD based driver, and MFD core cares about propagating fwnode by default. I believe it should just work if we drop that '->parent' part.

Are you sure about that?

Yes and no. If your DT looks like (pseudo code as I don't know DTS syntax by heart):

	device: {
		parent-property = value;
		child0:
			...
		child1:
			...
	}

the parent-property value is automatically accessible via fwnode API, but I don't know what will happen to the cases when each of the children has its own compatible string. This might be your case, but again, I'm not an expert in DT.

Quoted 4 lines

On my side it does not work if I just drop the '->parent', this is why I ended whit this (bad) pattern.

Now it does work if I do call device_set_of_node_from_dev() manually,

AFAICT, this is wrong API to be called in the children. Are you talking about parent code?

Quoted 4 lines

so it's definitely better. But I believe the MFD core is not propagating OF data, and I did not find where it would do that in the code. Yet it does something like this for ACPI in mfd_acpi_add_device(). Or maybe we do something bad in our MFD driver?

...or MFD needs something to have... Dunno.

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

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

Quoted 37 lines · Andy Shevchenko
Quoted 4 lines · Mathieu Dubois-Briand
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Uwe Kleine-König
Quoted 1 line · Andy Shevchenko

On Tue, Mar 18, 2025 at 05:26:20PM +0100, [email protected] wrote:

...

Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 5 lines

drivers/pwm/pwm-max7360.c line 165

Quoted 1 line
drivers/pwm/pwm-max7360.c new file +1 -0
+	chip = devm_pwmchip_alloc(dev->parent, MAX7360_NUM_PWMS, 0);

This is quite worrying. The devm_ to parent makes a lot of assumptions that may not be realised. If you really need this, it has to have a very good comment explaining why and object lifetimes.

Pretty sure this is broken. This results for example in the device link being created on the parent. So if the pwm devices goes away a consumer might not notice (at least in the usual way). I guess this was done to ensure that #pwm-cells is parsed from the right dt node? If so, that needs a different adaption. That will probably involve calling device_set_of_node_from_dev().

Quoted 4 lines
Quoted 2 lines

It's an MFD based driver, and MFD core cares about propagating fwnode by default. I believe it should just work if we drop that '->parent' part.

Are you sure about that?

Yes and no. If your DT looks like (pseudo code as I don't know DTS syntax by heart):

	device: {
		parent-property = value;
		child0:
			...
		child1:
			...
	}
Quoted 5 lines

the parent-property value is automatically accessible via fwnode API, but I don't know what will happen to the cases when each of the children has its own compatible string. This might be your case, but again, I'm not an expert in DT.

On my side:
- Some MFD child do have a child node in the device tree, with an associated compatible value. No problem for these, they do get correct of_node/fwnode values pointing on the child device tree node.
- Some MFD child do not have any node in the device tree, and for these, they have to use properties from the parent (MFD) device tree node. And here we do have some problems.

Quoted 8 lines
Quoted 4 lines

On my side it does not work if I just drop the '->parent', this is why I ended whit this (bad) pattern.

Now it does work if I do call device_set_of_node_from_dev() manually,

AFAICT, this is wrong API to be called in the children. Are you talking about parent code?

I believe I cannot do it in the parent code, as I would need to do it after the call to devm_mfd_add_devices(), and so it might happen after the probe. I still tried to see how it behaved, and it looks like PWM core really did not expect to get an of_node assigned to the device after adding the PWM device.

So either I can do something in MFD core or in sub devices probe(), or I need to come with a different way to do things.

Quoted 6 lines
Quoted 4 lines

so it's definitely better. But I believe the MFD core is not propagating OF data, and I did not find where it would do that in the code. Yet it does something like this for ACPI in mfd_acpi_add_device(). Or maybe we do something bad in our MFD driver?

...or MFD needs something to have... Dunno.

I have something working with a very simple change in mfd-core.c, but I'm really not confident it won't break anything else. I wish I could get some insights from an MFD expert.

@@ -210,6 +210,8 @@ static int mfd_add_device(struct device *parent, int id,

                if (!pdev->dev.of_node)
                        pr_warn("%s: Failed to locate of_node [id: %d]\n",
                                cell->name, platform_id);
+       } else if (IS_ENABLED(CONFIG_OF) && parent->of_node) {
+               device_set_of_node_from_dev(&pdev->dev, parent);
        }
Signature · 3 lines
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#19 lore raw

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

Quoted 6 lines · Mathieu Dubois-Briand
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Mathieu Dubois-Briand
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Uwe Kleine-König
Quoted 1 line · Andy Shevchenko

On Tue, Mar 18, 2025 at 05:26:20PM +0100, [email protected] wrote:

...

Quoted 73 lines
Quoted 29 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 5 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	chip = devm_pwmchip_alloc(dev->parent, MAX7360_NUM_PWMS, 0);

This is quite worrying. The devm_ to parent makes a lot of assumptions that may not be realised. If you really need this, it has to have a very good comment explaining why and object lifetimes.

Pretty sure this is broken. This results for example in the device link being created on the parent. So if the pwm devices goes away a consumer might not notice (at least in the usual way). I guess this was done to ensure that #pwm-cells is parsed from the right dt node? If so, that needs a different adaption. That will probably involve calling device_set_of_node_from_dev().

Quoted 4 lines
Quoted 2 lines

It's an MFD based driver, and MFD core cares about propagating fwnode by default. I believe it should just work if we drop that '->parent' part.

Are you sure about that?

Yes and no. If your DT looks like (pseudo code as I don't know DTS syntax by heart):

	device: {
		parent-property = value;
		child0:
			...
		child1:
			...
	}
Quoted 5 lines

the parent-property value is automatically accessible via fwnode API, but I don't know what will happen to the cases when each of the children has its own compatible string. This might be your case, but again, I'm not an expert in DT.

On my side:
- Some MFD child do have a child node in the device tree, with an associated compatible value. No problem for these, they do get correct of_node/fwnode values pointing on the child device tree node.
- Some MFD child do not have any node in the device tree, and for these, they have to use properties from the parent (MFD) device tree node. And here we do have some problems.

Quoted 8 lines
Quoted 4 lines

On my side it does not work if I just drop the '->parent', this is why I ended whit this (bad) pattern.

Now it does work if I do call device_set_of_node_from_dev() manually,

AFAICT, this is wrong API to be called in the children. Are you talking about parent code?

I believe I cannot do it in the parent code, as I would need to do it after the call to devm_mfd_add_devices(), and so it might happen after the probe. I still tried to see how it behaved, and it looks like PWM core really did not expect to get an of_node assigned to the device after adding the PWM device.

So either I can do something in MFD core or in sub devices probe(), or I need to come with a different way to do things.

Quoted 6 lines
Quoted 4 lines

so it's definitely better. But I believe the MFD core is not propagating OF data, and I did not find where it would do that in the code. Yet it does something like this for ACPI in mfd_acpi_add_device(). Or maybe we do something bad in our MFD driver?

...or MFD needs something to have... Dunno.

I have something working with a very simple change in mfd-core.c, but I'm really not confident it won't break anything else. I wish I could get some insights from an MFD expert.

Review static int mfd_add_device(struct device *parent, int id, · line 214

Quoted 5 lines
(quoted diff) +2 -0
@@ -210,6 +210,8 @@ static int mfd_add_device(struct device *parent, int id,
                if (!pdev->dev.of_node)
                        pr_warn("%s: Failed to locate of_node [id: %d]\n",
                                cell->name, platform_id);
+       } else if (IS_ENABLED(CONFIG_OF) && parent->of_node) {
+               device_set_of_node_from_dev(&pdev->dev, parent);

The use of this API is inappropriate here AFAICT. It drops the parent refcount and on the second call to it you will have a warning from refcount library.

It should be as simple as device_set_node().

Review static int mfd_add_device(struct device *parent, int id, · line 215

Quoted 1 line
(quoted diff) +0 -0
        }

With that, the conditional becomes

	} else if (is_of_node(fwnode)) {
		device_set_node(&pdev->dev, fwnode);
	}

where fwnode is something like

	struct fwnode_handle *fwnode = dev_fwnode(parent);
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#20 lore raw

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

Quoted 82 lines · Andy Shevchenko
Quoted 6 lines · Mathieu Dubois-Briand
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Mathieu Dubois-Briand
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Uwe Kleine-König
Quoted 1 line · Andy Shevchenko

On Tue, Mar 18, 2025 at 05:26:20PM +0100, [email protected] wrote:

...

Quoted 72 lines
Quoted 29 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 5 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	chip = devm_pwmchip_alloc(dev->parent, MAX7360_NUM_PWMS, 0);

This is quite worrying. The devm_ to parent makes a lot of assumptions that may not be realised. If you really need this, it has to have a very good comment explaining why and object lifetimes.

Pretty sure this is broken. This results for example in the device link being created on the parent. So if the pwm devices goes away a consumer might not notice (at least in the usual way). I guess this was done to ensure that #pwm-cells is parsed from the right dt node? If so, that needs a different adaption. That will probably involve calling device_set_of_node_from_dev().

Quoted 4 lines
Quoted 2 lines

It's an MFD based driver, and MFD core cares about propagating fwnode by default. I believe it should just work if we drop that '->parent' part.

Are you sure about that?

Yes and no. If your DT looks like (pseudo code as I don't know DTS syntax by heart):

	device: {
		parent-property = value;
		child0:
			...
		child1:
			...
	}
Quoted 5 lines

the parent-property value is automatically accessible via fwnode API, but I don't know what will happen to the cases when each of the children has its own compatible string. This might be your case, but again, I'm not an expert in DT.

On my side:
- Some MFD child do have a child node in the device tree, with an associated compatible value. No problem for these, they do get correct of_node/fwnode values pointing on the child device tree node.
- Some MFD child do not have any node in the device tree, and for these, they have to use properties from the parent (MFD) device tree node. And here we do have some problems.

Quoted 8 lines
Quoted 4 lines

On my side it does not work if I just drop the '->parent', this is why I ended whit this (bad) pattern.

Now it does work if I do call device_set_of_node_from_dev() manually,

AFAICT, this is wrong API to be called in the children. Are you talking about parent code?

I believe I cannot do it in the parent code, as I would need to do it after the call to devm_mfd_add_devices(), and so it might happen after the probe. I still tried to see how it behaved, and it looks like PWM core really did not expect to get an of_node assigned to the device after adding the PWM device.

So either I can do something in MFD core or in sub devices probe(), or I need to come with a different way to do things.

Quoted 6 lines
Quoted 4 lines

so it's definitely better. But I believe the MFD core is not propagating OF data, and I did not find where it would do that in the code. Yet it does something like this for ACPI in mfd_acpi_add_device(). Or maybe we do something bad in our MFD driver?

...or MFD needs something to have... Dunno.

I have something working with a very simple change in mfd-core.c, but I'm really not confident it won't break anything else. I wish I could get some insights from an MFD expert.

Quoted 9 lines

Review static int mfd_add_device(struct device *parent, int id, · line 214

Quoted 6 lines
(quoted diff) +2 -0
@@ -210,6 +210,8 @@ static int mfd_add_device(struct device *parent, int id,
                if (!pdev->dev.of_node)
                        pr_warn("%s: Failed to locate of_node [id: %d]\n",
                                cell->name, platform_id);
+       } else if (IS_ENABLED(CONFIG_OF) && parent->of_node) {
+               device_set_of_node_from_dev(&pdev->dev, parent);

The use of this API is inappropriate here AFAICT. It drops the parent refcount and on the second call to it you will have a warning from refcount library.

device_set_of_node_from_dev() does:

	of_node_put(pdev->dev->of_node);
	pdev->dev->of_node = of_node_get(parent->of_node);
	pdev->dev->of_node_reused = true;

Note that pdev isn't the platform device associated with the parent device but the just allocated one representing the subdevice so pdev->dev->of_node is NULL and the parent refcount isn't dropped.

But I'm unsure if this is the right place to call it or if device_set_node() is indeed enough (also I wonder if device_set_of_node_from_dev() should care for fwnode). I'll keep that question for someone else.

Best regards
Uwe

#21 lore raw

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

Quoted 8 lines · Uwe Kleine-König
Quoted 7 lines · Andy Shevchenko
Quoted 6 lines · Mathieu Dubois-Briand
Quoted 5 lines · Andy Shevchenko
Quoted 4 lines · Mathieu Dubois-Briand
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Uwe Kleine-König
Quoted 1 line · Andy Shevchenko

On Tue, Mar 18, 2025 at 05:26:20PM +0100, [email protected] wrote:

...

Quoted 84 lines
Quoted 72 lines
Quoted 72 lines
Quoted 29 lines
Quoted 13 lines
Quoted 13 lines
Quoted 12 lines
Quoted 5 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	chip = devm_pwmchip_alloc(dev->parent, MAX7360_NUM_PWMS, 0);

This is quite worrying. The devm_ to parent makes a lot of assumptions that may not be realised. If you really need this, it has to have a very good comment explaining why and object lifetimes.

Pretty sure this is broken. This results for example in the device link being created on the parent. So if the pwm devices goes away a consumer might not notice (at least in the usual way). I guess this was done to ensure that #pwm-cells is parsed from the right dt node? If so, that needs a different adaption. That will probably involve calling device_set_of_node_from_dev().

Quoted 4 lines
Quoted 2 lines

It's an MFD based driver, and MFD core cares about propagating fwnode by default. I believe it should just work if we drop that '->parent' part.

Are you sure about that?

Yes and no. If your DT looks like (pseudo code as I don't know DTS syntax by heart):

	device: {
		parent-property = value;
		child0:
			...
		child1:
			...
	}
Quoted 5 lines

the parent-property value is automatically accessible via fwnode API, but I don't know what will happen to the cases when each of the children has its own compatible string. This might be your case, but again, I'm not an expert in DT.

On my side:
- Some MFD child do have a child node in the device tree, with an associated compatible value. No problem for these, they do get correct of_node/fwnode values pointing on the child device tree node.
- Some MFD child do not have any node in the device tree, and for these, they have to use properties from the parent (MFD) device tree node. And here we do have some problems.

Quoted 8 lines
Quoted 4 lines

On my side it does not work if I just drop the '->parent', this is why I ended whit this (bad) pattern.

Now it does work if I do call device_set_of_node_from_dev() manually,

AFAICT, this is wrong API to be called in the children. Are you talking about parent code?

I believe I cannot do it in the parent code, as I would need to do it after the call to devm_mfd_add_devices(), and so it might happen after the probe. I still tried to see how it behaved, and it looks like PWM core really did not expect to get an of_node assigned to the device after adding the PWM device.

So either I can do something in MFD core or in sub devices probe(), or I need to come with a different way to do things.

Quoted 6 lines
Quoted 4 lines

so it's definitely better. But I believe the MFD core is not propagating OF data, and I did not find where it would do that in the code. Yet it does something like this for ACPI in mfd_acpi_add_device(). Or maybe we do something bad in our MFD driver?

...or MFD needs something to have... Dunno.

I have something working with a very simple change in mfd-core.c, but I'm really not confident it won't break anything else. I wish I could get some insights from an MFD expert.

Quoted 9 lines

Review static int mfd_add_device(struct device *parent, int id, · line 214

Quoted 6 lines
(quoted diff) +2 -0
@@ -210,6 +210,8 @@ static int mfd_add_device(struct device *parent, int id,
                if (!pdev->dev.of_node)
                        pr_warn("%s: Failed to locate of_node [id: %d]\n",
                                cell->name, platform_id);
+       } else if (IS_ENABLED(CONFIG_OF) && parent->of_node) {
+               device_set_of_node_from_dev(&pdev->dev, parent);

The use of this API is inappropriate here AFAICT. It drops the parent refcount and on the second call to it you will have a warning from refcount library.

device_set_of_node_from_dev() does:

Quoted 7 lines
	of_node_put(pdev->dev->of_node);
	pdev->dev->of_node = of_node_get(parent->of_node);
	pdev->dev->of_node_reused = true;

Note that pdev isn't the platform device associated with the parent device but the just allocated one representing the subdevice so pdev->dev->of_node is NULL and the parent refcount isn't dropped.

Ah, I stand corrected, thanks! Okay, so what it does basically, it drops a reference for the child, and propagates the parent's node at the same time bumping its reference count. Sounds legit, but this should be done equally for DT, ACPI and software node cases.

Quoted 2 lines

But I'm unsure if this is the right place to call it or if device_set_node() is indeed enough

This all about node reference counting. Whatever the correct choice for DT. Anyway this sounds right to do for any of the system, but also note, that this API is good when device node is not backed by the struct device, otherwise, the struct device reference count covers the device node AFAIU.

TL;DR: What are the object lifetimes for struct device and struct device_node (struct fwnode_handle)?

Quoted 3 lines

(also I wonder if device_set_of_node_from_dev() should care for fwnode). I'll keep that question for someone else.

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

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

In reply to Andy Shevchenko
Quoted 9 lines · Andy Shevchenko

The use of this API is inappropriate here AFAICT. It drops the parent refcount and on the second call to it you will have a warning from refcount library.

It should be as simple as device_set_node().

Quoted 1 line
        }

With that, the conditional becomes

Quoted 7 lines
	} else if (is_of_node(fwnode)) {
		device_set_node(&pdev->dev, fwnode);
	}

where fwnode is something like

	struct fwnode_handle *fwnode = dev_fwnode(parent);

Hi,

I tried to use device_set_node(), but then I got some other issue: as we now have several devices with the same firmware node, they all share the same properties. In particular, if we do use pinctrl- properties to apply some pinmmuxing, all devices will try to apply this pinmuxing and of course all but one will fail.

And this makes me think again about the whole thing, maybe copying the fwnode or of_node from the parent is not the way to go.

So today we rely on the parent node for four drivers:
- keypad and rotary, just to ease a bit the parsing of some properties, such as the keymap with matrix_keypad_build_keymap(). I can easily do it another way.
- PWM and pinctrl drivers, are a bit more complicated, as in both case the device tree node associated with the device is used internally. In one case to find the correct PWM device for PWM clients listed in the device tree, in the other case to find the pinctrl device when applying pinctrl described in the device tree.

So maybe I have to find a better way for have this association. One way would be to modify the device tree bindings to add a PWM and a pinctrl node, with their own compatible, so they are associated to the corresponding device. But maybe there is a better way to do it.

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

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

Quoted 38 lines · Mathieu Dubois-Briand
Quoted 9 lines · Andy Shevchenko

The use of this API is inappropriate here AFAICT. It drops the parent refcount and on the second call to it you will have a warning from refcount library.

It should be as simple as device_set_node().

Quoted 1 line
        }

With that, the conditional becomes

Quoted 7 lines
	} else if (is_of_node(fwnode)) {
		device_set_node(&pdev->dev, fwnode);
	}

where fwnode is something like

	struct fwnode_handle *fwnode = dev_fwnode(parent);

I tried to use device_set_node(), but then I got some other issue: as we now have several devices with the same firmware node, they all share the same properties. In particular, if we do use pinctrl- properties to apply some pinmmuxing, all devices will try to apply this pinmuxing and of course all but one will fail.

And this makes me think again about the whole thing, maybe copying the fwnode or of_node from the parent is not the way to go.

So today we rely on the parent node for four drivers:
- keypad and rotary, just to ease a bit the parsing of some properties, such as the keymap with matrix_keypad_build_keymap(). I can easily do it another way.
- PWM and pinctrl drivers, are a bit more complicated, as in both case the device tree node associated with the device is used internally. In one case to find the correct PWM device for PWM clients listed in the device tree, in the other case to find the pinctrl device when applying pinctrl described in the device tree.

Quoted 4 lines

So maybe I have to find a better way for have this association. One way would be to modify the device tree bindings to add a PWM and a pinctrl node, with their own compatible, so they are associated to the corresponding device. But maybe there is a better way to do it.

Okay, so the main question now, why do the device share their properties to begin with? It can be done via fwnode graph or similar APIs (in case it is _really_ needed).

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

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

Quoted 39 lines · Andy Shevchenko
Quoted 38 lines · Mathieu Dubois-Briand
Quoted 9 lines · Andy Shevchenko

The use of this API is inappropriate here AFAICT. It drops the parent refcount and on the second call to it you will have a warning from refcount library.

It should be as simple as device_set_node().

Quoted 1 line
        }

With that, the conditional becomes

Quoted 7 lines
	} else if (is_of_node(fwnode)) {
		device_set_node(&pdev->dev, fwnode);
	}

where fwnode is something like

	struct fwnode_handle *fwnode = dev_fwnode(parent);

I tried to use device_set_node(), but then I got some other issue: as we now have several devices with the same firmware node, they all share the same properties. In particular, if we do use pinctrl- properties to apply some pinmmuxing, all devices will try to apply this pinmuxing and of course all but one will fail.

And this makes me think again about the whole thing, maybe copying the fwnode or of_node from the parent is not the way to go.

So today we rely on the parent node for four drivers:
- keypad and rotary, just to ease a bit the parsing of some properties, such as the keymap with matrix_keypad_build_keymap(). I can easily do it another way.
- PWM and pinctrl drivers, are a bit more complicated, as in both case the device tree node associated with the device is used internally. In one case to find the correct PWM device for PWM clients listed in the device tree, in the other case to find the pinctrl device when applying pinctrl described in the device tree.

Quoted 8 lines
Quoted 4 lines

So maybe I have to find a better way for have this association. One way would be to modify the device tree bindings to add a PWM and a pinctrl node, with their own compatible, so they are associated to the corresponding device. But maybe there is a better way to do it.

Okay, so the main question now, why do the device share their properties to begin with? It can be done via fwnode graph or similar APIs (in case it is _really_ needed).

I wouldn't say the properties are shared: we have a single node in the device tree as this is just one device. But as we create several (software) devices in the MFD driver, we now have several devices linked with a single device tree node.

One solution would be to create more subnodes in the device tree, one for pinctrl and one for PWM, but this feels a bit like describing our software implementation in the device tree instead of describing the hardware.

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

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

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

On Wed Mar 26, 2025 at 4:49 PM CET, Andy Shevchenko wrote:

...

Quoted 50 lines
Quoted 36 lines
Quoted 36 lines
Quoted 9 lines

The use of this API is inappropriate here AFAICT. It drops the parent refcount and on the second call to it you will have a warning from refcount library.

It should be as simple as device_set_node().

Quoted 1 line
        }

With that, the conditional becomes

Quoted 7 lines
	} else if (is_of_node(fwnode)) {
		device_set_node(&pdev->dev, fwnode);
	}

where fwnode is something like

	struct fwnode_handle *fwnode = dev_fwnode(parent);

I tried to use device_set_node(), but then I got some other issue: as we now have several devices with the same firmware node, they all share the same properties. In particular, if we do use pinctrl- properties to apply some pinmmuxing, all devices will try to apply this pinmuxing and of course all but one will fail.

And this makes me think again about the whole thing, maybe copying the fwnode or of_node from the parent is not the way to go.

So today we rely on the parent node for four drivers:
- keypad and rotary, just to ease a bit the parsing of some properties, such as the keymap with matrix_keypad_build_keymap(). I can easily do it another way.
- PWM and pinctrl drivers, are a bit more complicated, as in both case the device tree node associated with the device is used internally. In one case to find the correct PWM device for PWM clients listed in the device tree, in the other case to find the pinctrl device when applying pinctrl described in the device tree.

Quoted 8 lines
Quoted 4 lines

So maybe I have to find a better way for have this association. One way would be to modify the device tree bindings to add a PWM and a pinctrl node, with their own compatible, so they are associated to the corresponding device. But maybe there is a better way to do it.

Okay, so the main question now, why do the device share their properties to begin with? It can be done via fwnode graph or similar APIs (in case it is _really_ needed).

I wouldn't say the properties are shared: we have a single node in the device tree as this is just one device. But as we create several (software) devices in the MFD driver, we now have several devices linked with a single device tree node.

Quoted 4 lines

One solution would be to create more subnodes in the device tree, one for pinctrl and one for PWM, but this feels a bit like describing our software implementation in the device tree instead of describing the hardware.

I see. From my point of view the above is the correct approach, but you need to ask DT experts, I'm not one of them.

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

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

In reply to Andy Shevchenko
Quoted 9 lines · Andy Shevchenko
Quoted 4 lines · On Tue, Mar 18, 2025 at 05:26:20PM +0100, [email protected]…

From: Kamel Bouhara <[email protected]>

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

...

Quoted 7 lines

drivers/pwm/pwm-max7360.c line 67

Quoted 4 lines
drivers/pwm/pwm-max7360.c new file +4 -0
+static int max7360_pwm_round_waveform_tohw(struct pwm_chip *chip,
+					   struct pwm_device *pwm,
+					   const struct pwm_waveform *wf,
+					   void *_wfhw)

I would expect other way around, i.e. naming with leading underscore(s) to be private / local. Ditto for all similar cases.

I get the point, but the 2 existing drivers based on pwm_ops structure name it that way: drivers/pwm/pwm-axi-pwmgen.c and drivers/pwm/pwm-stm32.c.

Also, the parameter is mostly unusable as-is, as it is a void*, so I believe it also makes sense to have no underscore for the correctly casted one, that we will be using in the function body (wfhw).

Quoted 26 lines

...

Quoted 7 lines
drivers/pwm/pwm-max7360.c new file +7 -0
+static int max7360_pwm_read_waveform(struct pwm_chip *chip,
+				     struct pwm_device *pwm,
+				     void *_wfhw)
+{
+	struct max7360_pwm_waveform *wfhw = _wfhw;
+	struct regmap *regmap;
+	unsigned int val;

drivers/pwm/pwm-max7360.c line 135

Quoted 10 lines
drivers/pwm/pwm-max7360.c new file +10 -0
+	int ret;
+
+	regmap = pwmchip_get_drvdata(chip);
+
+	ret = regmap_read(regmap, MAX7360_REG_GPIOCTRL, &val);
+	if (ret)
+		return ret;
+
+	if (val & BIT(pwm->hwpwm)) {
+		wfhw->enabled = true;

Also can be (but up to you)

	wfhw->enabled = val & BIT(pwm->hwpwm);
	if (wfhw->enabled) {
Quoted 7 lines

And also see below. Perhaps it is not a good suggestion after all.

drivers/pwm/pwm-max7360.c line 137

Quoted 2 lines
drivers/pwm/pwm-max7360.c new file +2 -0
+		ret = regmap_read(regmap, MAX7360_REG_PWM(pwm->hwpwm), &val);
+		wfhw->duty_steps = val;

Set to a garbage in case of error, why?

Ok, I'm fixing the whole block of code.

Quoted 22 lines
Quoted 7 lines
drivers/pwm/pwm-max7360.c new file +7 -0
+	} else {
+		wfhw->enabled = false;
+		wfhw->duty_steps = 0;
+	}
+
+	return ret;
+}

...

drivers/pwm/pwm-max7360.c line 163

Quoted 9 lines
drivers/pwm/pwm-max7360.c new file +9 -0
+static int max7360_pwm_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct pwm_chip *chip;
+	struct regmap *regmap;
+	int ret;
+
+	if (!dev->parent)
+		return dev_err_probe(dev, -ENODEV, "no parent device\n");

Why? Code most likely will fail on the regmap retrieval. Just do that first.

Quoted 6 lines

drivers/pwm/pwm-max7360.c line 165

Quoted 1 line
drivers/pwm/pwm-max7360.c new file +1 -0
+	chip = devm_pwmchip_alloc(dev->parent, MAX7360_NUM_PWMS, 0);

This is quite worrying. The devm_ to parent makes a lot of assumptions that may not be realised. If you really need this, it has to have a very good comment explaining why and object lifetimes.

Thanks, I'm fixing this in this driver and similar code in keypad, rotary and pinctrl. More details in the child mail.

Thanks for your review!
Mathieu

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

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

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

On Tue, Mar 18, 2025 at 05:26:20PM +0100, [email protected] wrote:

...

Quoted 8 lines
Quoted 7 lines

drivers/pwm/pwm-max7360.c line 67

Quoted 4 lines
drivers/pwm/pwm-max7360.c new file +4 -0
+static int max7360_pwm_round_waveform_tohw(struct pwm_chip *chip,
+					   struct pwm_device *pwm,
+					   const struct pwm_waveform *wf,
+					   void *_wfhw)

I would expect other way around, i.e. naming with leading underscore(s) to be private / local. Ditto for all similar cases.

Quoted 7 lines

I get the point, but the 2 existing drivers based on pwm_ops structure name it that way: drivers/pwm/pwm-axi-pwmgen.c and drivers/pwm/pwm-stm32.c.

Also, the parameter is mostly unusable as-is, as it is a void*, so I believe it also makes sense to have no underscore for the correctly casted one, that we will be using in the function body (wfhw).

It's all up to PWM maintainers, but I find this style a bit weird, sorry. I only saw this in the macros, where it's kinda okay. In functions it's something that needs an additional thinking and understanding the semantics of the underscore.

...

Quoted 12 lines
Quoted 12 lines

drivers/pwm/pwm-max7360.c line 163

Quoted 9 lines
drivers/pwm/pwm-max7360.c new file +9 -0
+static int max7360_pwm_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct pwm_chip *chip;
+	struct regmap *regmap;
+	int ret;
+
+	if (!dev->parent)
+		return dev_err_probe(dev, -ENODEV, "no parent device\n");

Why? Code most likely will fail on the regmap retrieval. Just do that first.

Quoted 8 lines
Quoted 5 lines

drivers/pwm/pwm-max7360.c line 165

Quoted 1 line
drivers/pwm/pwm-max7360.c new file +1 -0
+	chip = devm_pwmchip_alloc(dev->parent, MAX7360_NUM_PWMS, 0);

This is quite worrying. The devm_ to parent makes a lot of assumptions that may not be realised. If you really need this, it has to have a very good comment explaining why and object lifetimes.

Thanks, I'm fixing this in this driver and similar code in keypad, rotary and pinctrl. More details in the child mail.

Sure, thanks!

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

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

In reply to [email protected]
kernel test robot noticed the following build warnings:

Hi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on a64dcfb451e254085a7daee5fe51bf22959d52d3]

url:    https://github.com/intel-lab-lkp/linux/commits/Mathieu-Dubois-Briand/dt-bindings-mfd-gpio-Add-MAX7360/20250319-003750
base:   a64dcfb451e254085a7daee5fe51bf22959d52d3
patch link:    https://lore.kernel.org/r/20250318-mdb-max7360-support-v5-4-fb20baf97da0%40bootlin.com
patch subject: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20250319/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250319/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/pwm/pwm-max7360.c: In function 'max7360_pwm_request':

>> drivers/pwm/pwm-max7360.c:41:17: warning: variable 'dev' set but not used [-Wunused-but-set-variable]
     struct device *dev;
                    ^~~
   drivers/pwm/pwm-max7360.c: In function 'max7360_pwm_free':
   drivers/pwm/pwm-max7360.c:58:17: warning: variable 'dev' set but not used [-Wunused-but-set-variable]
     struct device *dev;
                    ^~~

vim +/dev +41 drivers/pwm/pwm-max7360.c

    37	
    38	static int max7360_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
    39	{
    40		struct regmap *regmap;
  > 41		struct device *dev;
    42		int ret;
    43	
    44		regmap = pwmchip_get_drvdata(chip);
    45		dev = regmap_get_device(regmap);
    46	
    47		ret = regmap_write_bits(regmap, MAX7360_REG_PWMCFG(pwm->hwpwm),
    48					MAX7360_PORT_CFG_COMMON_PWM, 0);
    49		if (ret)
    50			return ret;
    51	
    52		return regmap_write_bits(regmap, MAX7360_REG_PORTS, BIT(pwm->hwpwm), BIT(pwm->hwpwm));
    53	}
    54	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#29 lore raw

Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

In reply to [email protected]
kernel test robot noticed the following build warnings:

Hi,

kernel test robot noticed the following build warnings:

[auto build test WARNING on a64dcfb451e254085a7daee5fe51bf22959d52d3]

url:    https://github.com/intel-lab-lkp/linux/commits/Mathieu-Dubois-Briand/dt-bindings-mfd-gpio-Add-MAX7360/20250319-003750
base:   a64dcfb451e254085a7daee5fe51bf22959d52d3
patch link:    https://lore.kernel.org/r/20250318-mdb-max7360-support-v5-4-fb20baf97da0%40bootlin.com
patch subject: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support
config: nios2-kismet-CONFIG_PINCTRL_MAX7360-CONFIG_PWM_MAX7360-0-0 (https://download.01.org/0day-ci/archive/20250320/[email protected]/config)
reproduce: (https://download.01.org/0day-ci/archive/20250320/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

kismet warnings: (new ones prefixed by >>)

>> kismet: WARNING: unmet direct dependencies detected for PINCTRL_MAX7360 when selected by PWM_MAX7360

WARNING: unmet direct dependencies detected for PINCTRL_MAX7360
Depends on [n]: PINCTRL [=n] && MFD_MAX7360 [=y] Selected by [y]:
- PWM_MAX7360 [=y] && PWM [=y] && MFD_MAX7360 [=y]

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#30 lore raw

PATCH v5 5/11 regmap: irq: Add support for chips without separate IRQ status

In reply to Mathieu Dubois-Briand

Some GPIO chips allow to rise an IRQ on GPIO level changes but do not provide an IRQ status for each separate line: only the current gpio level can be retrieved.

Add support for these chips, emulating IRQ status by comparing GPIO levels with the levels during the previous interrupt.

---
 drivers/base/regmap/regmap-irq.c | 97 +++++++++++++++++++++++++++-------------
 include/linux/regmap.h           |  3 ++
 2 files changed, 69 insertions(+), 31 deletions(-)
drivers/base/regmap/regmap-irq.c +66 -31
index 0bcd81389a29..0e53b64d028d 100644
@@ -33,6 +33,7 @@ struct regmap_irq_chip_data {
 	void *status_reg_buf;
 	unsigned int *main_status_buf;
 	unsigned int *status_buf;
+	unsigned int *prev_status_buf;
 	unsigned int *mask_buf;
 	unsigned int *mask_buf_def;
 	unsigned int *wake_buf;
@@ -332,27 +333,13 @@ static inline int read_sub_irq_data(struct regmap_irq_chip_data *data,
 	return ret;
 }
 
-static irqreturn_t regmap_irq_thread(int irq, void *d)
+static int read_irq_data(struct regmap_irq_chip_data *data)
 {
-	struct regmap_irq_chip_data *data = d;
 	const struct regmap_irq_chip *chip = data->chip;
 	struct regmap *map = data->map;
 	int ret, i;
-	bool handled = false;
 	u32 reg;
 
-	if (chip->handle_pre_irq)
-		chip->handle_pre_irq(chip->irq_drv_data);
-
-	if (chip->runtime_pm) {
-		ret = pm_runtime_get_sync(map->dev);
-		if (ret < 0) {
-			dev_err(map->dev, "IRQ thread failed to resume: %d\n",
-				ret);
-			goto exit;
-		}
-	}
-
 	/*
 	 * Read only registers with active IRQs if the chip has 'main status
 	 * register'. Else read in the statuses, using a single bulk read if
@@ -379,10 +366,8 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
 			reg = data->get_irq_reg(data, chip->main_status, i);
 			ret = regmap_read(map, reg, &data->main_status_buf[i]);
 			if (ret) {
-				dev_err(map->dev,
-					"Failed to read IRQ status %d\n",
-					ret);
-				goto exit;
+				dev_err(map->dev, "Failed to read IRQ status %d\n", ret);
+				return ret;
 			}
 		}
 
@@ -398,10 +383,8 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
 				ret = read_sub_irq_data(data, b);
 
 				if (ret != 0) {
-					dev_err(map->dev,
-						"Failed to read IRQ status %d\n",
-						ret);
-					goto exit;
+					dev_err(map->dev, "Failed to read IRQ status %d\n", ret);
+					return ret;
 				}
 			}
 
@@ -418,9 +401,8 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
 				       data->status_reg_buf,
 				       chip->num_regs);
 		if (ret != 0) {
-			dev_err(map->dev, "Failed to read IRQ status: %d\n",
-				ret);
-			goto exit;
+			dev_err(map->dev, "Failed to read IRQ status: %d\n", ret);
+			return ret;
 		}
 
 		for (i = 0; i < data->chip->num_regs; i++) {
@@ -436,7 +418,7 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
 				break;
 			default:
 				BUG();
-				goto exit;
+				return ret;
 			}
 		}
 
@@ -447,10 +429,8 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
 			ret = regmap_read(map, reg, &data->status_buf[i]);
 
 			if (ret != 0) {
-				dev_err(map->dev,
-					"Failed to read IRQ status: %d\n",
-					ret);
-				goto exit;
+				dev_err(map->dev, "Failed to read IRQ status: %d\n", ret);
+				return ret;
 			}
 		}
 	}
@@ -459,6 +439,42 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
 		for (i = 0; i < data->chip->num_regs; i++)
 			data->status_buf[i] = ~data->status_buf[i];
 
+	return 0;
+}
+
+static irqreturn_t regmap_irq_thread(int irq, void *d)
+{
+	struct regmap_irq_chip_data *data = d;
+	const struct regmap_irq_chip *chip = data->chip;
+	struct regmap *map = data->map;
+	int ret, i;
+	bool handled = false;
+	u32 reg;
+
+	if (chip->handle_pre_irq)
+		chip->handle_pre_irq(chip->irq_drv_data);
+
+	if (chip->runtime_pm) {
+		ret = pm_runtime_get_sync(map->dev);
+		if (ret < 0) {
+			dev_err(map->dev, "IRQ thread failed to resume: %d\n", ret);
+			goto exit;
+		}
+	}
+
+	ret = read_irq_data(data);
+	if (ret < 0)
+		goto exit;
+
+	if (chip->status_is_level) {
+		for (i = 0; i < data->chip->num_regs; i++) {
+			unsigned int val = data->status_buf[i];
+
+			data->status_buf[i] ^= data->prev_status_buf[i];
+			data->prev_status_buf[i] = val;
+		}
+	}
+
 	/*
 	 * Ignore masked IRQs and ack if we need to; we ack early so
 	 * there is no race between handling and acknowledging the
@@ -705,6 +721,13 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
 	if (!d->status_buf)
 		goto err_alloc;
 
+	if (chip->status_is_level) {
+		d->prev_status_buf = kcalloc(chip->num_regs, sizeof(*d->prev_status_buf),
+					     GFP_KERNEL);
+		if (!d->prev_status_buf)
+			goto err_alloc;
+	}
+
 	d->mask_buf = kcalloc(chip->num_regs, sizeof(*d->mask_buf),
 			      GFP_KERNEL);
 	if (!d->mask_buf)
@@ -881,6 +904,16 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
 		}
 	}
 
+	/* Store current levels */
+	if (chip->status_is_level) {
+		ret = read_irq_data(d);
+		if (ret < 0)
+			goto err_alloc;
+
+		memcpy(d->prev_status_buf, d->status_buf,
+		       d->chip->num_regs * sizeof(d->prev_status_buf[0]));
+	}
+
 	ret = regmap_irq_create_domain(fwnode, irq_base, chip, d);
 	if (ret)
 		goto err_alloc;
@@ -907,6 +940,7 @@ int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode,
 	kfree(d->mask_buf_def);
 	kfree(d->mask_buf);
 	kfree(d->status_buf);
+	kfree(d->prev_status_buf);
 	kfree(d->status_reg_buf);
 	if (d->config_buf) {
 		for (i = 0; i < chip->num_config_bases; i++)
@@ -983,6 +1017,7 @@ void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *d)
 	kfree(d->mask_buf);
 	kfree(d->status_reg_buf);
 	kfree(d->status_buf);
+	kfree(d->prev_status_buf);
 	if (d->config_buf) {
 		for (i = 0; i < d->chip->num_config_bases; i++)
 			kfree(d->config_buf[i]);
include/linux/regmap.h +3 -0
index 3a96d068915f..159527e97f00 100644
@@ -1640,6 +1640,8 @@ struct regmap_irq_chip_data;
  * @ack_invert:  Inverted ack register: cleared bits for ack.
  * @clear_ack:  Use this to set 1 and 0 or vice-versa to clear interrupts.
  * @status_invert: Inverted status register: cleared bits are active interrupts.
+ * @status_is_level: Status register is actuall signal level: Xor status
+ *		     register with previous value to get active interrupts.
  * @wake_invert: Inverted wake register: cleared bits are wake enabled.
  * @type_in_mask: Use the mask registers for controlling irq type. Use this if
  *		  the hardware provides separate bits for rising/falling edge
@@ -1703,6 +1705,7 @@ struct regmap_irq_chip {
 	unsigned int ack_invert:1;
 	unsigned int clear_ack:1;
 	unsigned int status_invert:1;
+	unsigned int status_is_level:1;
 	unsigned int wake_invert:1;
 	unsigned int type_in_mask:1;
 	unsigned int clear_on_unmask:1;
Signature · 1 line
2.39.5
Reviewed-by on v5 5/11
#31 lore raw

Re: [PATCH v5 05/11] regmap: irq: Add support for chips without separate IRQ status

Quoted 6 lines · Mathieu Dubois-Briand

Some GPIO chips allow to rise an IRQ on GPIO level changes but do not provide an IRQ status for each separate line: only the current gpio level can be retrieved.

Add support for these chips, emulating IRQ status by comparing GPIO levels with the levels during the previous interrupt.

Some nit-picks below, but either way

...

drivers/base/regmap/regmap-irq.c static irqreturn_t regmap_irq_thread(int irq, void *d) · line 421

Quoted 4 lines
drivers/base/regmap/regmap-irq.c +1 -1
 			default:
 				BUG();
-				goto exit;
+				return ret;

Hmm... BUG() implies unreachable, perhaps just a precursor patch to drop this goto completely?

...

drivers/base/regmap/regmap-irq.c int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode, · line 914

Quoted 8 lines
drivers/base/regmap/regmap-irq.c +8 -0
+	/* Store current levels */
+	if (chip->status_is_level) {
+		ret = read_irq_data(d);
+		if (ret < 0)
+			goto err_alloc;
+
+		memcpy(d->prev_status_buf, d->status_buf,
+		       d->chip->num_regs * sizeof(d->prev_status_buf[0]));

Perhaps array_size()?

Quoted 1 line
(quoted diff) +1 -0
+	}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#32 lore raw

Re: [PATCH v5 05/11] regmap: irq: Add support for chips without separate IRQ status

Quoted 14 lines · Andy Shevchenko
Quoted 6 lines · Mathieu Dubois-Briand

Some GPIO chips allow to rise an IRQ on GPIO level changes but do not provide an IRQ status for each separate line: only the current gpio level can be retrieved.

Add support for these chips, emulating IRQ status by comparing GPIO levels with the levels during the previous interrupt.

Some nit-picks below, but either way

...

Quoted 8 lines

drivers/base/regmap/regmap-irq.c static irqreturn_t regmap_irq_thread(int irq, void *d) · line 421

Quoted 4 lines
drivers/base/regmap/regmap-irq.c +1 -1
 			default:
 				BUG();
-				goto exit;
+				return ret;

Hmm... BUG() implies unreachable, perhaps just a precursor patch to drop this goto completely?

Ok, I will add a separate patch to remove the goto.

Quoted 13 lines

...

drivers/base/regmap/regmap-irq.c int regmap_add_irq_chip_fwnode(struct fwnode_handle *fwnode, · line 914

Quoted 8 lines
drivers/base/regmap/regmap-irq.c +8 -0
+	/* Store current levels */
+	if (chip->status_is_level) {
+		ret = read_irq_data(d);
+		if (ret < 0)
+			goto err_alloc;
+
+		memcpy(d->prev_status_buf, d->status_buf,
+		       d->chip->num_regs * sizeof(d->prev_status_buf[0]));

Perhaps array_size()?

OK

Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+	}

Thanks for your review, and thanks for the tag.
Mathieu

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

Re: [PATCH v5 05/11] regmap: irq: Add support for chips without separate IRQ status

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

On Tue, Mar 18, 2025 at 05:26:21PM +0100, Mathieu Dubois-Briand wrote:

...

Quoted 9 lines
Quoted 7 lines

drivers/base/regmap/regmap-irq.c static irqreturn_t regmap_irq_thread(int irq, void *d) · line 421

Quoted 4 lines
drivers/base/regmap/regmap-irq.c +1 -1
 			default:
 				BUG();
-				goto exit;
+				return ret;

Hmm... BUG() implies unreachable, perhaps just a precursor patch to drop this goto completely?

Ok, I will add a separate patch to remove the goto.

I just browsed the code for the similar and there are handful that do this. At least one commit (from 2011) refers to GCC 4.3.3 that complains, but our minimum requirement AFAIR is 5.1 nowadays. In any case it's up to you. I am totally fine if you leave this as is.

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

PATCH v5 6/11 gpio: regmap: Allow to allocate regmap-irq device

In reply to Mathieu Dubois-Briand

GPIO controller often have support for IRQ: allow to easily allocate both gpio-regmap and regmap-irq in one operation.

---
 drivers/gpio/gpio-regmap.c  | 23 +++++++++++++++++++++--
 include/linux/gpio/regmap.h | 15 +++++++++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)
drivers/gpio/gpio-regmap.c +21 -2
index 05f8781b5204..61d5f48b445d 100644
@@ -203,6 +203,7 @@ EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata);
  */
 struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config)
 {
+	struct irq_domain *irq_domain;
 	struct gpio_regmap *gpio;
 	struct gpio_chip *chip;
 	int ret;
@@ -280,8 +281,26 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
 	if (ret < 0)
 		goto err_free_gpio;
 
-	if (config->irq_domain) {
-		ret = gpiochip_irqchip_add_domain(chip, config->irq_domain);
+	irq_domain = config->irq_domain;
+#ifdef CONFIG_GPIOLIB_IRQCHIP
+	if (config->regmap_irq_chip) {
+		struct regmap_irq_chip_data *irq_chip_data;
+
+		ret = devm_regmap_add_irq_chip_fwnode(config->parent, dev_fwnode(config->parent),
+						      config->regmap, config->regmap_irq_irqno,
+						      config->regmap_irq_flags, 0,
+						      config->regmap_irq_chip, &irq_chip_data);
+		if (ret)
+			goto err_free_gpio;
+
+		irq_domain = regmap_irq_get_domain(irq_chip_data);
+		if (config->regmap_irq_chip_data)
+			*config->regmap_irq_chip_data = irq_chip_data;
+	}
+#endif
+
+	if (irq_domain) {
+		ret = gpiochip_irqchip_add_domain(chip, irq_domain);
 		if (ret)
 			goto err_remove_gpiochip;
 	}
include/linux/gpio/regmap.h +15 -0
index a9f7b7faf57b..55df2527b982 100644
@@ -40,6 +40,14 @@ struct regmap;
  * @drvdata:		(Optional) Pointer to driver specific data which is
  *			not used by gpio-remap but is provided "as is" to the
  *			driver callback(s).
+ * @regmap_irq_chip:	(Optional) Pointer on an regmap_irq_chip structure. If
+ *			set, a regmap-irq device will be created and the IRQ
+ *			domain will be set accordingly.
+ * @regmap_irq_chip_data: (Optional) Pointer on an regmap_irq_chip_data
+ *                      structure pointer. If set, it will be populated with a
+ *                      pointer on allocated regmap_irq data.
+ * @regmap_irq_irqno	(Optional) The IRQ the device uses to signal interrupts.
+ * @regmap_irq_flags	(Optional) The IRQF_ flags to use for the interrupt.
  *
  * The ->reg_mask_xlate translates a given base address and GPIO offset to
  * register and mask pair. The base address is one of the given register
@@ -78,6 +86,13 @@ struct gpio_regmap_config {
 	int ngpio_per_reg;
 	struct irq_domain *irq_domain;
 
+#ifdef CONFIG_GPIOLIB_IRQCHIP
+	struct regmap_irq_chip *regmap_irq_chip;
+	struct regmap_irq_chip_data **regmap_irq_chip_data;
+	int regmap_irq_irqno;
+	unsigned long regmap_irq_flags;
+#endif
+
 	int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
 			      unsigned int offset, unsigned int *reg,
 			      unsigned int *mask);
Signature · 1 line
2.39.5
#35 lore raw

Re: [PATCH v5 06/11] gpio: regmap: Allow to allocate regmap-irq device

Quoted 2 lines · Mathieu Dubois-Briand

GPIO controller often have support for IRQ: allow to easily allocate both gpio-regmap and regmap-irq in one operation.

...

drivers/gpio/gpio-regmap.c struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config · line 284

Quoted 4 lines
drivers/gpio/gpio-regmap.c +1 -2
-	if (config->irq_domain) {
-		ret = gpiochip_irqchip_add_domain(chip, config->irq_domain);
 
+	irq_domain = config->irq_domain;

Better to move it into #else, so we avoid double assignment (see below).

Quoted 4 lines
drivers/gpio/gpio-regmap.c +4 -0
+#ifdef CONFIG_GPIOLIB_IRQCHIP
+	if (config->regmap_irq_chip) {
+		struct regmap_irq_chip_data *irq_chip_data;
+

drivers/gpio/gpio-regmap.c struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config · line 298

Quoted 10 lines
drivers/gpio/gpio-regmap.c +10 -0
+		ret = devm_regmap_add_irq_chip_fwnode(config->parent, dev_fwnode(config->parent),
+						      config->regmap, config->regmap_irq_irqno,
+						      config->regmap_irq_flags, 0,
+						      config->regmap_irq_chip, &irq_chip_data);
+		if (ret)
+			goto err_free_gpio;
+
+		irq_domain = regmap_irq_get_domain(irq_chip_data);
+		if (config->regmap_irq_chip_data)
+			*config->regmap_irq_chip_data = irq_chip_data;

Hmm... I was under impression that we don't need this to be returned. Do we have any user of it right now? If not, no need to export until it is needed.

drivers/gpio/gpio-regmap.c struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config · line 299

Quoted 1 line
drivers/gpio/gpio-regmap.c +1 -0
+	}
	} else
Quoted 1 line

+#endif

	irq_domain = config->irq_domain;
Quoted 6 lines
drivers/gpio/gpio-regmap.c +3 -0
+
+	if (irq_domain) {
+		ret = gpiochip_irqchip_add_domain(chip, irq_domain);
 		if (ret)
 			goto err_remove_gpiochip;
 	}

...

include/linux/gpio/regmap.h struct gpio_regmap_config { · line 91

Quoted 3 lines
include/linux/gpio/regmap.h +3 -0
+#ifdef CONFIG_GPIOLIB_IRQCHIP
+	struct regmap_irq_chip *regmap_irq_chip;
+	struct regmap_irq_chip_data **regmap_irq_chip_data;

But why double pointer?

Quoted 3 lines
include/linux/gpio/regmap.h +3 -0
+	int regmap_irq_irqno;
+	unsigned long regmap_irq_flags;
+#endif
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#36 lore raw

Re: [PATCH v5 06/11] gpio: regmap: Allow to allocate regmap-irq device

Quoted 4 lines · Andy Shevchenko
Quoted 2 lines · Mathieu Dubois-Briand

GPIO controller often have support for IRQ: allow to easily allocate both gpio-regmap and regmap-irq in one operation.

Quoted 9 lines

...

drivers/gpio/gpio-regmap.c struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config · line 284

Quoted 4 lines
drivers/gpio/gpio-regmap.c +1 -2
-	if (config->irq_domain) {
-		ret = gpiochip_irqchip_add_domain(chip, config->irq_domain);
 
+	irq_domain = config->irq_domain;

Better to move it into #else, so we avoid double assignment (see below).

OK

Quoted 10 lines
Quoted 10 lines
drivers/gpio/gpio-regmap.c +10 -0
+#ifdef CONFIG_GPIOLIB_IRQCHIP
+	if (config->regmap_irq_chip) {
+		struct regmap_irq_chip_data *irq_chip_data;
+
+		ret = devm_regmap_add_irq_chip_fwnode(config->parent, dev_fwnode(config->parent),
+						      config->regmap, config->regmap_irq_irqno,
+						      config->regmap_irq_flags, 0,
+						      config->regmap_irq_chip, &irq_chip_data);
+		if (ret)
+			goto err_free_gpio;
Quoted 9 lines

drivers/gpio/gpio-regmap.c struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config · line 298

Quoted 4 lines
drivers/gpio/gpio-regmap.c +4 -0
+
+		irq_domain = regmap_irq_get_domain(irq_chip_data);
+		if (config->regmap_irq_chip_data)
+			*config->regmap_irq_chip_data = irq_chip_data;

Hmm... I was under impression that we don't need this to be returned. Do we have any user of it right now? If not, no need to export until it is needed.

Right, I will remove it.

Quoted 17 lines

drivers/gpio/gpio-regmap.c struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config · line 299

Quoted 1 line
drivers/gpio/gpio-regmap.c +1 -0
+	}
	} else
Quoted 1 line

+#endif

	irq_domain = config->irq_domain;
Quoted 6 lines
drivers/gpio/gpio-regmap.c +3 -0
+
+	if (irq_domain) {
+		ret = gpiochip_irqchip_add_domain(chip, irq_domain);
 		if (ret)
 			goto err_remove_gpiochip;
 	}

...

Quoted 6 lines

include/linux/gpio/regmap.h struct gpio_regmap_config { · line 91

Quoted 3 lines
include/linux/gpio/regmap.h +3 -0
+#ifdef CONFIG_GPIOLIB_IRQCHIP
+	struct regmap_irq_chip *regmap_irq_chip;
+	struct regmap_irq_chip_data **regmap_irq_chip_data;

But why double pointer?

I believe this has to be a double pointer, as it is going to be assigned a pointer value: data buffer is allocated inside of devm_regmap_add_irq_chip_fwnode().

But as you said, it's better to remove it and add it later if there is an use case.

Quoted 3 lines

include/linux/gpio/regmap.h struct gpio_regmap_config { · line 94

Quoted 3 lines
include/linux/gpio/regmap.h +3 -0
+	int regmap_irq_irqno;
+	unsigned long regmap_irq_flags;
+#endif

Thanks for your review.

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

Re: [PATCH v5 06/11] gpio: regmap: Allow to allocate regmap-irq device

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

On Tue, Mar 18, 2025 at 05:26:22PM +0100, Mathieu Dubois-Briand wrote:

...

Quoted 9 lines
Quoted 5 lines

include/linux/gpio/regmap.h struct gpio_regmap_config { · line 91

Quoted 3 lines
include/linux/gpio/regmap.h +3 -0
+#ifdef CONFIG_GPIOLIB_IRQCHIP
+	struct regmap_irq_chip *regmap_irq_chip;
+	struct regmap_irq_chip_data **regmap_irq_chip_data;

But why double pointer?

I believe this has to be a double pointer, as it is going to be assigned a pointer value: data buffer is allocated inside of devm_regmap_add_irq_chip_fwnode().

Yes, but it doesn't need to be a double one in the data structrure, right?

Quoted 2 lines

But as you said, it's better to remove it and add it later if there is an use case.

This would be even better for now, thanks!

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

Re: [PATCH v5 06/11] gpio: regmap: Allow to allocate regmap-irq device

In reply to Mathieu Dubois-Briand

Hi,

Quoted 22 lines

GPIO controller often have support for IRQ: allow to easily allocate both gpio-regmap and regmap-irq in one operation.

---
 drivers/gpio/gpio-regmap.c  | 23 +++++++++++++++++++++--
 include/linux/gpio/regmap.h | 15 +++++++++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)
drivers/gpio/gpio-regmap.c +1 -0
index 05f8781b5204..61d5f48b445d 100644
@@ -203,6 +203,7 @@ EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata);
  */
 struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config)
 {
+	struct irq_domain *irq_domain;
 	struct gpio_regmap *gpio;
 	struct gpio_chip *chip;
 	int ret;

drivers/gpio/gpio-regmap.c struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config · line 285

Quoted 7 lines
drivers/gpio/gpio-regmap.c +2 -2
@@ -280,8 +281,26 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
 	if (ret < 0)
 		goto err_free_gpio;
 
-	if (config->irq_domain) {
-		ret = gpiochip_irqchip_add_domain(chip, config->irq_domain);
+	irq_domain = config->irq_domain;
+#ifdef CONFIG_GPIOLIB_IRQCHIP

Why do we need this ifdef?

drivers/gpio/gpio-regmap.c struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config · line 298

Quoted 13 lines
drivers/gpio/gpio-regmap.c +13 -0
+	if (config->regmap_irq_chip) {
+		struct regmap_irq_chip_data *irq_chip_data;
+
+		ret = devm_regmap_add_irq_chip_fwnode(config->parent, dev_fwnode(config->parent),
+						      config->regmap, config->regmap_irq_irqno,
+						      config->regmap_irq_flags, 0,
+						      config->regmap_irq_chip, &irq_chip_data);
+		if (ret)
+			goto err_free_gpio;
+
+		irq_domain = regmap_irq_get_domain(irq_chip_data);
+		if (config->regmap_irq_chip_data)
+			*config->regmap_irq_chip_data = irq_chip_data;

I'm not a fan of misusing the config to return any data. Can we have a normal gpio_regmap_get_...()? Usually, the config is on the stack of the caller, what if you need to get irq_chip_data afterwards? Then your caller has to save it somewhere.

Also, what is the advantage of this? Your caller doesn't have to call devm_regmap_add_irq_chip_fwnode(), but on the flip side you have to cram all its parameters in the gpio_regmap config. I'd like to keep that small and simple (but still extensible!). IMHO just setting the irq_domain is enough to achieve that.

-michael

Quoted 41 lines
drivers/gpio/gpio-regmap.c +5 -0
+	}
+#endif
+
+	if (irq_domain) {
+		ret = gpiochip_irqchip_add_domain(chip, irq_domain);
 		if (ret)
 			goto err_remove_gpiochip;
 	}
include/linux/gpio/regmap.h +15 -0
index a9f7b7faf57b..55df2527b982 100644
@@ -40,6 +40,14 @@ struct regmap;
  * @drvdata:		(Optional) Pointer to driver specific data which is
  *			not used by gpio-remap but is provided "as is" to the
  *			driver callback(s).
+ * @regmap_irq_chip:	(Optional) Pointer on an regmap_irq_chip structure. If
+ *			set, a regmap-irq device will be created and the IRQ
+ *			domain will be set accordingly.
+ * @regmap_irq_chip_data: (Optional) Pointer on an regmap_irq_chip_data
+ *                      structure pointer. If set, it will be populated with a
+ *                      pointer on allocated regmap_irq data.
+ * @regmap_irq_irqno	(Optional) The IRQ the device uses to signal interrupts.
+ * @regmap_irq_flags	(Optional) The IRQF_ flags to use for the interrupt.
  *
  * The ->reg_mask_xlate translates a given base address and GPIO offset to
  * register and mask pair. The base address is one of the given register
@@ -78,6 +86,13 @@ struct gpio_regmap_config {
 	int ngpio_per_reg;
 	struct irq_domain *irq_domain;
 
+#ifdef CONFIG_GPIOLIB_IRQCHIP
+	struct regmap_irq_chip *regmap_irq_chip;
+	struct regmap_irq_chip_data **regmap_irq_chip_data;
+	int regmap_irq_irqno;
+	unsigned long regmap_irq_flags;
+#endif
+
 	int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
 			      unsigned int offset, unsigned int *reg,
 			      unsigned int *mask);
author maintainer
#39 lore raw

Re: [PATCH v5 06/11] gpio: regmap: Allow to allocate regmap-irq device

Quoted 27 lines · Michael Walle

Hi,

Quoted 25 lines

GPIO controller often have support for IRQ: allow to easily allocate both gpio-regmap and regmap-irq in one operation.

---
 drivers/gpio/gpio-regmap.c  | 23 +++++++++++++++++++++--
 include/linux/gpio/regmap.h | 15 +++++++++++++++
 2 files changed, 36 insertions(+), 2 deletions(-)
drivers/gpio/gpio-regmap.c +1 -0
index 05f8781b5204..61d5f48b445d 100644
@@ -203,6 +203,7 @@ EXPORT_SYMBOL_GPL(gpio_regmap_get_drvdata);
  */
 struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config)
 {
+	struct irq_domain *irq_domain;
 	struct gpio_regmap *gpio;
 	struct gpio_chip *chip;
 	int ret;
@@ -280,8 +281,26 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
 	if (ret < 0)
 		goto err_free_gpio;
 
Quoted 7 lines

drivers/gpio/gpio-regmap.c struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config · line 285

Quoted 4 lines
drivers/gpio/gpio-regmap.c +2 -2
-	if (config->irq_domain) {
-		ret = gpiochip_irqchip_add_domain(chip, config->irq_domain);
+	irq_domain = config->irq_domain;
+#ifdef CONFIG_GPIOLIB_IRQCHIP

Why do we need this ifdef?

Hum yes, on second thought we probably need to depend on CONFIG_REGMAP_IRQ here.

Quoted 10 lines
Quoted 10 lines
drivers/gpio/gpio-regmap.c +10 -0
+	if (config->regmap_irq_chip) {
+		struct regmap_irq_chip_data *irq_chip_data;
+
+		ret = devm_regmap_add_irq_chip_fwnode(config->parent, dev_fwnode(config->parent),
+						      config->regmap, config->regmap_irq_irqno,
+						      config->regmap_irq_flags, 0,
+						      config->regmap_irq_chip, &irq_chip_data);
+		if (ret)
+			goto err_free_gpio;
+
Quoted 9 lines

drivers/gpio/gpio-regmap.c struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config · line 298

Quoted 3 lines
drivers/gpio/gpio-regmap.c +3 -0
+		irq_domain = regmap_irq_get_domain(irq_chip_data);
+		if (config->regmap_irq_chip_data)
+			*config->regmap_irq_chip_data = irq_chip_data;

I'm not a fan of misusing the config to return any data. Can we have a normal gpio_regmap_get_...()? Usually, the config is on the stack of the caller, what if you need to get irq_chip_data afterwards? Then your caller has to save it somewhere.

Yes, makes sense. As suggested by Andy Shevchenko, I will remove this parameter as there is no user today: a way to retrieve it can be added later if needed.

Quoted 5 lines

Also, what is the advantage of this? Your caller doesn't have to call devm_regmap_add_irq_chip_fwnode(), but on the flip side you have to cram all its parameters in the gpio_regmap config. I'd like to keep that small and simple (but still extensible!). IMHO just setting the irq_domain is enough to achieve that.

This was a request from Andy on my previous series.

Quoted 3 lines

-michael

Thanks for your review.
Mathieu

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

Re: [PATCH v5 06/11] gpio: regmap: Allow to allocate regmap-irq device

Quoted 1 line · Mathieu Dubois-Briand

On Wed Mar 19, 2025 at 8:15 AM CET, Michael Walle wrote:

...

Quoted 7 lines
Quoted 5 lines

Also, what is the advantage of this? Your caller doesn't have to call devm_regmap_add_irq_chip_fwnode(), but on the flip side you have to cram all its parameters in the gpio_regmap config. I'd like to keep that small and simple (but still extensible!). IMHO just setting the irq_domain is enough to achieve that.

This was a request from Andy on my previous series.

The benefit is deduplication of a lot of code. You may consider it the same as GPIO library does with IRQ chip. This is just the same on a different level.

Besides the driver in this series, I would think of other GPIO drivers that are not (yet) converted to regmap (partially because of this is being absent) or existing drivers, if any, that may utilise it.

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

Re: [PATCH v5 06/11] gpio: regmap: Allow to allocate regmap-irq device

Hi,

Quoted 10 lines
Quoted 7 lines
Quoted 5 lines

Also, what is the advantage of this? Your caller doesn't have to call devm_regmap_add_irq_chip_fwnode(), but on the flip side you have to cram all its parameters in the gpio_regmap config. I'd like to keep that small and simple (but still extensible!). IMHO just setting the irq_domain is enough to achieve that.

This was a request from Andy on my previous series.

The benefit is deduplication of a lot of code. You may consider it the same as GPIO library does with IRQ chip. This is just the same on a different level.

I'd say "a lot of code" is slightly exaggerated :-) I was hesitant because it sounded like a one-off for the regmap_irq support. There could theoretically be other irq_domain providers (I think).

I just had a quick look at all the gpio_regmap drivers and they all use regmap_irq. So maybe it's fair to say that one could be directly supported within gpio_regmap.

Quoted 3 lines

Besides the driver in this series, I would think of other GPIO drivers that are not (yet) converted to regmap (partially because of this is being absent) or existing drivers, if any, that may utilise it.

Yes probably all of the existing ones :)

-michael

maintainer
#42 lore raw

Re: [PATCH v5 06/11] gpio: regmap: Allow to allocate regmap-irq device

In reply to Mathieu Dubois-Briand

Hi,

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

+#ifdef CONFIG_GPIOLIB_IRQCHIP

Why do we need this ifdef?

Hum yes, on second thought we probably need to depend on CONFIG_REGMAP_IRQ here.

But then, you'd also require the regmap_irq support for chips that don't support IRQs at all. devm_regmap_add_irq_fwnode() seems to be missing a stub version.

-michael

author maintainer
#43 lore raw

Re: [PATCH v5 06/11] gpio: regmap: Allow to allocate regmap-irq device

Quoted 5 lines · Michael Walle
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

+#ifdef CONFIG_GPIOLIB_IRQCHIP

Why do we need this ifdef?

Quoted 7 lines
Quoted 2 lines

Hum yes, on second thought we probably need to depend on CONFIG_REGMAP_IRQ here.

But then, you'd also require the regmap_irq support for chips that don't support IRQs at all. devm_regmap_add_irq_fwnode() seems to be missing a stub version.

Sorry, maybe my previous message was not clear, when I said "depend", what I meant is having an "#ifdef CONFIG_REGMAP_IRQ" here in place of "#ifdef CONFIG_GPIOLIB_IRQCHIP"

If CONFIG_REGMAP_IRQ is enabled, drivers/base/regmap/regmap-irq.c is built, so we do have both devm_regmap_add_irq_chip_fwnode() and regmap_irq_get_domain(). So this code block should compile and link correctly.

I did some build tests with and without CONFIG_GPIOLIB_IRQCHIP and I believe this is fine.

Or am I missing something?

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

Re: [PATCH v5 06/11] gpio: regmap: Allow to allocate regmap-irq device

Quoted 14 lines · Mathieu Dubois-Briand
Quoted 5 lines · Michael Walle
Quoted 5 lines
Quoted 4 lines
Quoted 1 line

+#ifdef CONFIG_GPIOLIB_IRQCHIP

Why do we need this ifdef?

Quoted 7 lines
Quoted 2 lines

Hum yes, on second thought we probably need to depend on CONFIG_REGMAP_IRQ here.

But then, you'd also require the regmap_irq support for chips that don't support IRQs at all. devm_regmap_add_irq_fwnode() seems to be missing a stub version.

Quoted 8 lines

Sorry, maybe my previous message was not clear, when I said "depend", what I meant is having an "#ifdef CONFIG_REGMAP_IRQ" here in place of "#ifdef CONFIG_GPIOLIB_IRQCHIP"

If CONFIG_REGMAP_IRQ is enabled, drivers/base/regmap/regmap-irq.c is built, so we do have both devm_regmap_add_irq_chip_fwnode() and regmap_irq_get_domain(). So this code block should compile and link correctly.

Yes.

Quoted 4 lines

I did some build tests with and without CONFIG_GPIOLIB_IRQCHIP and I believe this is fine.

Or am I missing something?

I'd like to avoid the ifdef macros if possible. Thus you'd need stubs for devm_regmap_add_irq_chip_fwnode() and regmap_irq_get_domain() if CONFIG_REGMAP_IRQ is not defined.

Not sure if broonie agrees though (?).

-michael

author maintainer
#45 lore raw

PATCH v5 7/11 gpio: regmap: Allow to provide init_valid_mask callback

In reply to Mathieu Dubois-Briand

Allows to populate the gpio_regmap_config structure with init_valid_mask() callback to set on the final gpio_chip structure.

---
 drivers/gpio/gpio-regmap.c  | 3 +--
 include/linux/gpio/regmap.h | 7 +++++++
 2 files changed, 8 insertions(+), 2 deletions(-)
drivers/gpio/gpio-regmap.c +1 -2
index 61d5f48b445d..4c66a90bbbf1 100644
@@ -262,9 +262,8 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
 	chip->names = config->names;
 	chip->label = config->label ?: dev_name(config->parent);
 	chip->can_sleep = regmap_might_sleep(config->regmap);
+	chip->init_valid_mask = config->init_valid_mask;
 
-	chip->request = gpiochip_generic_request;
-	chip->free = gpiochip_generic_free;
 	chip->get = gpio_regmap_get;
 	if (gpio->reg_set_base && gpio->reg_clr_base)
 		chip->set = gpio_regmap_set_with_clear;
include/linux/gpio/regmap.h +7 -0
index 55df2527b982..c14bf65d22e9 100644
@@ -6,6 +6,7 @@
 struct device;
 struct fwnode_handle;
 struct gpio_regmap;
+struct gpio_chip;
 struct irq_domain;
 struct regmap;
 
@@ -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 used
+ *			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.
@@ -97,6 +100,10 @@ struct gpio_regmap_config {
 			      unsigned int offset, unsigned int *reg,
 			      unsigned int *mask);
 
+	int (*init_valid_mask)(struct gpio_chip *gc,
+			       unsigned long *valid_mask,
+			       unsigned int ngpios);
+
 	void *drvdata;
 };
 
Signature · 1 line
2.39.5
#46 lore raw

Re: [PATCH v5 07/11] gpio: regmap: Allow to provide init_valid_mask callback

Quoted 2 lines · Mathieu Dubois-Briand

Allows to populate the gpio_regmap_config structure with init_valid_mask() callback to set on the final gpio_chip structure.

...

drivers/gpio/gpio-regmap.c struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config · line 267

Quoted 2 lines
drivers/gpio/gpio-regmap.c +0 -2
-	chip->request = gpiochip_generic_request;
-	chip->free = gpiochip_generic_free;

Stray change.

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

Re: [PATCH v5 07/11] gpio: regmap: Allow to provide init_valid_mask callback

Quoted 10 lines · Andy Shevchenko
Quoted 2 lines · Mathieu Dubois-Briand

Allows to populate the gpio_regmap_config structure with init_valid_mask() callback to set on the final gpio_chip structure.

...

drivers/gpio/gpio-regmap.c struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config · line 267

Quoted 2 lines
drivers/gpio/gpio-regmap.c +0 -2
-	chip->request = gpiochip_generic_request;
-	chip->free = gpiochip_generic_free;

Stray change.

Oops, reminder of a dropped patch, thanks for noticing this.

Best regards,
Mathieu

Signature · 3 lines
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
maintainer Reviewed-by on v5 7/11
#48 lore raw

Re: [PATCH v5 07/11] gpio: regmap: Allow to provide init_valid_mask callback

In reply to Mathieu Dubois-Briand

Hi,

drivers/gpio/gpio-regmap.c struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config · line 267

Quoted 8 lines

Allows to populate the gpio_regmap_config structure with init_valid_mask() callback to set on the final gpio_chip structure.

---

drivers/gpio/gpio-regmap.c +0 -2
-	chip->request = gpiochip_generic_request;
-	chip->free = gpiochip_generic_free;

With this removed:

author maintainer
#49 lore raw

Re: [PATCH v5 07/11] gpio: regmap: Allow to provide init_valid_mask callback

Quoted 8 lines · Michael Walle

Hi,

Quoted 5 lines

Allows to populate the gpio_regmap_config structure with init_valid_mask() callback to set on the final gpio_chip structure.

---

Quoted 6 lines

drivers/gpio/gpio-regmap.c struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config · line 267

Quoted 2 lines
drivers/gpio/gpio-regmap.c +0 -2
-	chip->request = gpiochip_generic_request;
-	chip->free = gpiochip_generic_free;

With this removed:

Yes, reminder of a dropped patch.

Thanks for your review and the tag.
Mathieu

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

PATCH v5 8/11 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        |  12 +++
 drivers/gpio/Makefile       |   1 +
 drivers/gpio/gpio-max7360.c | 246 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 259 insertions(+)
drivers/gpio/Kconfig +12 -0
index 98b4d1633b25..4ff68ec6a990 100644
@@ -1445,6 +1445,18 @@ config GPIO_MADERA
 	help
 	  Support for GPIOs on Cirrus Logic Madera class codecs.
 
+config GPIO_MAX7360
+	tristate "MAX7360 GPIO support"
+	depends on MFD_MAX7360
+	select GPIO_REGMAP
+	select PINCTRL_MAX7360
+	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 +246 -0

246 lines not on this page · raw message

Signature · 1 line
2.39.5
#51 lore raw

Re: [PATCH v5 08/11] gpio: max7360: Add MAX7360 gpio support

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.

...

+ bitfield.h

Quoted 1 line

+#include <linux/bitmap.h>

+ err.h

drivers/gpio/gpio-max7360.c line 14

Quoted 5 lines
drivers/gpio/gpio-max7360.c new file +5 -0
+#include <linux/gpio/driver.h>
+#include <linux/gpio/regmap.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/max7360.h>

+ mod_devicetable.h

drivers/gpio/gpio-max7360.c line 30

Quoted 13 lines
drivers/gpio/gpio-max7360.c new file +12 -0
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/slab.h>
 
+static int max7360_get_available_gpos(struct device *dev, unsigned int *available_gpios)
+{
+	u32 columns;
+	int ret;
+
+	ret = device_property_read_u32(dev->parent, "keypad,num-columns", &columns);
+	if (ret < 0) {

' < 0' is redundant,

Quoted 8 lines
drivers/gpio/gpio-max7360.c new file +8 -0
+		dev_err(dev, "Failed to read columns count\n");
+		return ret;
+	}
+
+	*available_gpios = min(MAX7360_MAX_GPO, MAX7360_MAX_KEY_COLS - columns);
+
+	return 0;
+}

...

Quoted 21 lines
drivers/gpio/gpio-max7360.c new file +21 -0
+static int max7360_set_gpos_count(struct device *dev, struct regmap *regmap)
+{
+	/*
+	 * MAX7360 COL0 to COL7 pins can be used either as keypad columns,
+	 * general purpose output or a mix of both.
+	 * 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 = 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.

drivers/gpio/gpio-max7360.c line 85

Quoted 10 lines
drivers/gpio/gpio-max7360.c new file +9 -0
+	 */
+	val = FIELD_PREP(MAX7360_PORTS, available_gpios);
+	ret = regmap_write_bits(regmap, MAX7360_REG_DEBOUNCE, MAX7360_PORTS, val);
+	if (ret) {
+		dev_err(dev, "Failed to write max7360 columns/gpos configuration");
 
+		return ret;
+	}
+
+	return 0;

Just

	return ret;

?

Quoted 1 line

+}

...

drivers/gpio/gpio-max7360.c line 98

Quoted 11 lines
drivers/gpio/gpio-max7360.c new file +11 -0
+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 == MAX7360_REG_PWMBASE) {
+		/*
+		 * GPIO output is using PWM duty cycle registers: one register
+		 * per line, with value being either 0 or 255.
+		 */
+		*reg = base + offset;
+		*mask = 0xFF;

GENMASK() ?

Quoted 7 lines
drivers/gpio/gpio-max7360.c new file +7 -0
+	} else {
+		*reg = base;
+		*mask = BIT(offset);
+	}
+
+	return 0;
+}

...

drivers/gpio/gpio-max7360.c line 129

Quoted 12 lines
drivers/gpio/gpio-max7360.c new file +12 -0
+static int max7360_handle_mask_sync(const int index,
+				    const unsigned int mask_buf_def,
+				    const unsigned int mask_buf,
+				    void *const irq_drv_data)
+{
+	struct regmap *regmap = irq_drv_data;
+	unsigned int val;
+
+	for (unsigned int i = 0; i < MAX7360_MAX_GPIO; ++i) {
+		val = (mask_buf & BIT(i)) ? MAX7360_PORT_CFG_INTERRUPT_MASK : 0;
+		regmap_write_bits(regmap, MAX7360_REG_PWMCFG(i),
+				  MAX7360_PORT_CFG_INTERRUPT_MASK, val);

Wondering if regmap_assign_bits() can be used here.

But in any case, no error checks? It seems you do elsewhere, but this driver...

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

...

Quoted 7 lines
drivers/gpio/gpio-max7360.c new file +7 -0
+static int max7360_gpio_probe(struct platform_device *pdev)
+{
+	struct regmap_irq_chip *irq_chip;
+	struct gpio_regmap_config gpio_config = { };
+	struct device *dev = &pdev->dev;
+	unsigned long gpio_function;
+	struct regmap *regmap;

drivers/gpio/gpio-max7360.c line 150

Quoted 10 lines
drivers/gpio/gpio-max7360.c new file +9 -0
+	unsigned int outconf;
+	int ret;
+
+	regmap = dev_get_regmap(dev->parent, NULL);
+	if (!regmap)
+		return dev_err_probe(dev, -ENODEV, "could not get parent regmap\n");
+
+	gpio_function = (uintptr_t)device_get_match_data(dev);
 
+

Redundant blank line.

drivers/gpio/gpio-max7360.c line 152

Quoted 2 lines
drivers/gpio/gpio-max7360.c new file +2 -0
+	if (gpio_function == MAX7360_GPIO_PORT &&
+	    (device_property_read_bool(dev, "interrupt-controller"))) {

Unneeded parentheses.

drivers/gpio/gpio-max7360.c line 157

Quoted 5 lines
drivers/gpio/gpio-max7360.c new file +5 -0
+		/*
+		 * Port GPIOs with interrupt-controller property: add IRQ
+		 * controller.
+		 */
+		gpio_config.regmap_irq_flags = IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED;

But why is this being overridden? The DT or another firmware description has to provide the correct settings, no?

drivers/gpio/gpio-max7360.c line 159

Quoted 2 lines
drivers/gpio/gpio-max7360.c new file +2 -0
+		gpio_config.regmap_irq_irqno = fwnode_irq_get_byname(dev_fwnode(dev->parent),
+								     "inti");

Better split is

		gpio_config.regmap_irq_irqno =
			fwnode_irq_get_byname(dev_fwnode(dev->parent), "inti");

You also can use the same trick elsewhere in the similar cases.

Quoted 6 lines
drivers/gpio/gpio-max7360.c new file +6 -0
+		if (gpio_config.regmap_irq_irqno < 0)
+			return dev_err_probe(dev, gpio_config.regmap_irq_irqno,
+					     "Failed to get IRQ\n");
+
+		irq_chip = devm_kzalloc(dev, sizeof(*irq_chip), GFP_KERNEL);
+		gpio_config.regmap_irq_chip = irq_chip;

drivers/gpio/gpio-max7360.c line 175

Quoted 10 lines
drivers/gpio/gpio-max7360.c new file +10 -0
+		if (!irq_chip)
+			return -ENOMEM;
+
+		irq_chip->name = dev_name(dev);
+		irq_chip->status_base = MAX7360_REG_GPIOIN;
+		irq_chip->num_regs = 1;
+		irq_chip->num_irqs = MAX7360_MAX_GPIO;
+		irq_chip->irqs = max7360_regmap_irqs;
+		irq_chip->handle_mask_sync = max7360_handle_mask_sync;
+		irq_chip->status_is_level = true;

I would group this with status_base above. Easier to read and I think they are kinda related.

drivers/gpio/gpio-max7360.c line 181

Quoted 6 lines
drivers/gpio/gpio-max7360.c new file +6 -0
+		irq_chip->irq_drv_data = regmap;
+
+		for (unsigned int i = 0; i < MAX7360_MAX_GPIO; i++) {
+			regmap_write_bits(regmap, MAX7360_REG_PWMCFG(i),
+					  MAX7360_PORT_CFG_INTERRUPT_EDGES,
+					  MAX7360_PORT_CFG_INTERRUPT_EDGES);

No error checks?

drivers/gpio/gpio-max7360.c line 39

Quoted 4 lines
drivers/gpio/gpio-max7360.c new file +3 -0
+		}
 
+	}
+

Probably a comment why it's not 'else if' here?

drivers/gpio/gpio-max7360.c line 194

Quoted 11 lines
drivers/gpio/gpio-max7360.c new file +10 -0
+	if (gpio_function == MAX7360_GPIO_PORT) {
+		/*
+		 * Port GPIOs: set output mode configuration (constant-current or not).
+		 * This property is optional.
+		 */
+		outconf = 0;
+		ret = device_property_read_u32(dev, "maxim,constant-current-disable", &outconf);
 
+		if (ret && (ret != -EINVAL))
+			return dev_err_probe(dev, ret, "Failed to read %s device property\n",
+					     "maxim,constant-current-disable");

This part is fragile, error codes are not _so_ stable inside the kernel, and this may add an unneeded churn in case of pedantic cleanup.

Personally I would drop any messages and avoid failing the probe as to me it does not sound like a critical issue.

Quoted 25 lines
drivers/gpio/gpio-max7360.c new file +25 -0
+		regmap_write(regmap, MAX7360_REG_GPIOOUTM, outconf);
+	}
+
+	/* Add gpio device. */
+	gpio_config.parent = dev;
+	gpio_config.regmap = regmap;
+	if (gpio_function == MAX7360_GPIO_PORT) {
+		gpio_config.ngpio = MAX7360_MAX_GPIO;
+		gpio_config.reg_dat_base = GPIO_REGMAP_ADDR(MAX7360_REG_GPIOIN);
+		gpio_config.reg_set_base = GPIO_REGMAP_ADDR(MAX7360_REG_PWMBASE);
+		gpio_config.reg_dir_out_base = GPIO_REGMAP_ADDR(MAX7360_REG_GPIOCTRL);
+		gpio_config.ngpio_per_reg = MAX7360_MAX_GPIO;
+		gpio_config.reg_mask_xlate = max7360_gpio_reg_mask_xlate;
+	} else {
+		ret = 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 = GPIO_REGMAP_ADDR(MAX7360_REG_PORTS);
+		gpio_config.ngpio = MAX7360_MAX_KEY_COLS;
+		gpio_config.init_valid_mask = max7360_gpo_init_valid_mask;
+	}
+
+	return PTR_ERR_OR_ZERO(devm_gpio_regmap_register(dev, &gpio_config));
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#52 lore raw

Re: [PATCH v5 08/11] gpio: max7360: Add MAX7360 gpio support

Quoted 10 lines · Andy Shevchenko
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.

...

Quoted 9 lines

drivers/gpio/gpio-max7360.c line 157

Quoted 5 lines
drivers/gpio/gpio-max7360.c new file +5 -0
+		/*
+		 * Port GPIOs with interrupt-controller property: add IRQ
+		 * controller.
+		 */
+		gpio_config.regmap_irq_flags = IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED;

But why is this being overridden? The DT or another firmware description has to provide the correct settings, no?

Ok, thinking about it, yes, IRQF_TRIGGER_LOW shoud come from firmware description. But IRQF_ONESHOT and IRQF_SHARED should still come from here, no?

I'm OK with all other points.

Thanks for your review!
Mathieu

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

Re: [PATCH v5 08/11] gpio: max7360: Add MAX7360 gpio support

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

On Tue, Mar 18, 2025 at 05:26:24PM +0100, Mathieu Dubois-Briand wrote:

...

Quoted 9 lines
Quoted 8 lines

drivers/gpio/gpio-max7360.c line 157

Quoted 5 lines
drivers/gpio/gpio-max7360.c new file +5 -0
+		/*
+		 * Port GPIOs with interrupt-controller property: add IRQ
+		 * controller.
+		 */
+		gpio_config.regmap_irq_flags = IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED;

But why is this being overridden? The DT or another firmware description has to provide the correct settings, no?

Quoted 3 lines

Ok, thinking about it, yes, IRQF_TRIGGER_LOW shoud come from firmware description. But IRQF_ONESHOT and IRQF_SHARED should still come from here, no?

This is my view as well.

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

Re: [PATCH v5 08/11] gpio: max7360: Add MAX7360 gpio support

In reply to Mathieu Dubois-Briand
kernel test robot noticed the following build errors:

Hi Mathieu,

kernel test robot noticed the following build errors:

[auto build test ERROR on a64dcfb451e254085a7daee5fe51bf22959d52d3]

url:    https://github.com/intel-lab-lkp/linux/commits/Mathieu-Dubois-Briand/dt-bindings-mfd-gpio-Add-MAX7360/20250319-003750
base:   a64dcfb451e254085a7daee5fe51bf22959d52d3
patch link:    https://lore.kernel.org/r/20250318-mdb-max7360-support-v5-8-fb20baf97da0%40bootlin.com
patch subject: [PATCH v5 08/11] gpio: max7360: Add MAX7360 gpio support
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20250319/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250319/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/gpio/gpio-max7360.c: In function 'max7360_set_gpos_count':

>> drivers/gpio/gpio-max7360.c:78:8: error: implicit declaration of function 'FIELD_PREP' [-Werror=implicit-function-declaration]
     val = FIELD_PREP(MAX7360_PORTS, available_gpios);
           ^~~~~~~~~~

cc1: some warnings being treated as errors

vim +/FIELD_PREP +78 drivers/gpio/gpio-max7360.c

    55	
    56	static int max7360_set_gpos_count(struct device *dev, struct regmap *regmap)
    57	{
    58		/*
    59		 * MAX7360 COL0 to COL7 pins can be used either as keypad columns,
    60		 * general purpose output or a mix of both.
    61		 * By default, all pins are used as keypad, here we update this
    62		 * configuration to allow to use some of them as GPIOs.
    63		 */
    64		unsigned int available_gpios;
    65		unsigned int val;
    66		int ret;
    67	
    68		ret = max7360_get_available_gpos(dev, &available_gpios);
    69		if (ret)
    70			return ret;
    71	
    72		/*
    73		 * Configure which GPIOs will be used for keypad.
    74		 * MAX7360_REG_DEBOUNCE contains configuration both for keypad debounce
    75		 * timings and gpos/keypad columns repartition. Only the later is
    76		 * modified here.
    77		 */
  > 78		val = FIELD_PREP(MAX7360_PORTS, available_gpios);
    79		ret = regmap_write_bits(regmap, MAX7360_REG_DEBOUNCE, MAX7360_PORTS, val);
    80		if (ret) {
    81			dev_err(dev, "Failed to write max7360 columns/gpos configuration");
    82			return ret;
    83		}
    84	
    85		return 0;
    86	}
    87	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#55 lore raw

Re: [PATCH v5 08/11] gpio: max7360: Add MAX7360 gpio support

In reply to Mathieu Dubois-Briand
kernel test robot noticed the following build warnings:

Hi Mathieu,

kernel test robot noticed the following build warnings:

[auto build test WARNING on a64dcfb451e254085a7daee5fe51bf22959d52d3]

url:    https://github.com/intel-lab-lkp/linux/commits/Mathieu-Dubois-Briand/dt-bindings-mfd-gpio-Add-MAX7360/20250319-003750
base:   a64dcfb451e254085a7daee5fe51bf22959d52d3
patch link:    https://lore.kernel.org/r/20250318-mdb-max7360-support-v5-8-fb20baf97da0%40bootlin.com
patch subject: [PATCH v5 08/11] gpio: max7360: Add MAX7360 gpio support
config: nios2-kismet-CONFIG_PINCTRL_MAX7360-CONFIG_GPIO_MAX7360-0-0 (https://download.01.org/0day-ci/archive/20250320/[email protected]/config)
reproduce: (https://download.01.org/0day-ci/archive/20250320/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

kismet warnings: (new ones prefixed by >>)

>> kismet: WARNING: unmet direct dependencies detected for PINCTRL_MAX7360 when selected by GPIO_MAX7360

WARNING: unmet direct dependencies detected for PINCTRL_MAX7360
Depends on [n]: PINCTRL [=n] && MFD_MAX7360 [=y] Selected by [y]:
- GPIO_MAX7360 [=y] && GPIOLIB [=y] && MFD_MAX7360 [=y]

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#56 lore raw

PATCH v5 9/11 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 | 264 ++++++++++++++++++++++++++++++++
 3 files changed, 277 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 +264 -0

264 lines not on this page · raw message

Signature · 1 line
2.39.5
#57 lore raw

Re: [PATCH v5 09/11] input: keyboard: Add support for MAX7360 keypad

Quoted 2 lines · 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 config KEYBOARD_MAX7359 · line 434

Quoted 6 lines
drivers/input/keyboard/Kconfig +6 -0
+	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.

One paragraph is wrapped way too late or too early, can you make them approx. the same in terms of a line width?

...

+ bitfield.h
+ bitops.h
+ dev_printk.h
+ device/devres.h
+ err.h

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

Quoted 5 lines
drivers/input/keyboard/max7360-keypad.c new file +5 -0
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/input/matrix_keypad.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/max7360.h>

+ mod_devicetable.h

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

Quoted 7 lines
drivers/input/keyboard/max7360-keypad.c new file +6 -0
+#include <linux/module.h>
+#include <linux/property.h>
+#include <linux/platform_device.h>
+#include <linux/pm_wakeirq.h>
+#include <linux/regmap.h>
 
+#include <linux/slab.h>

IS it used? I think it's device/devres.h that covers it.

...

Quoted 8 lines
drivers/input/keyboard/max7360-keypad.c new file +8 -0
+static int max7360_keypad_open(struct input_dev *pdev)
+{
+	struct max7360_keypad *max7360_keypad = input_get_drvdata(pdev);
+	int ret;
+
+	/*
+	 * Somebody is using the device: get out of sleep.
+	 */

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

Quoted 10 lines
drivers/input/keyboard/max7360-keypad.c new file +9 -0
+	ret = regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_CONFIG,
+				MAX7360_CFG_SLEEP, MAX7360_CFG_SLEEP);
+	if (ret) {
+		dev_err(&max7360_keypad->input->dev,
+			"Failed to write max7360 configuration\n");
 
+		return ret;
+	}
+
+	return 0;

Just

	return ret;

?

Quoted 1 line

+}

...

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

Quoted 3 lines
drivers/input/keyboard/max7360-keypad.c new file +3 -0
+	/*
+	 * Nobody is using the device anymore: go to sleep.
+	 */

The comment message can take only a line.

Quoted 5 lines
drivers/input/keyboard/max7360-keypad.c new file +5 -0
+	ret = regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_CONFIG, MAX7360_CFG_SLEEP, 0);
+	if (ret)
+		dev_err(&max7360_keypad->input->dev,
+			"Failed to write max7360 configuration\n");
+}

...

Quoted 1 line

+static int max7360_keypad_parse_dt(struct platform_device *pdev,

s/dt/fw

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

Quoted 3 lines
drivers/input/keyboard/max7360-keypad.c new file +3 -0
+				   struct max7360_keypad *max7360_keypad,
+				   bool *autorepeat)
+{
	struct device *dev = &pdev>dev;

but why not supply struct device to begin with? How is the platform part used here?

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

Quoted 10 lines
drivers/input/keyboard/max7360-keypad.c new file +10 -0
+	int ret;
+
+	ret = matrix_keypad_parse_properties(pdev->dev.parent, &max7360_keypad->rows,
+					     &max7360_keypad->cols);
+	if (ret)
+		return ret;
+
+	if (!max7360_keypad->rows || !max7360_keypad->cols ||
+	    max7360_keypad->rows > MAX7360_MAX_KEY_ROWS ||
+	    max7360_keypad->cols > MAX7360_MAX_KEY_COLS) {

See also below comment.

Quoted 10 lines
drivers/input/keyboard/max7360-keypad.c new file +10 -0
+		dev_err(&pdev->dev,
+			"Invalid number of columns or rows (%ux%u)\n",
+			max7360_keypad->cols, max7360_keypad->rows);
+		return -EINVAL;
+	}
+
+	*autorepeat = device_property_read_bool(pdev->dev.parent, "autorepeat");
+
+	max7360_keypad->debounce_ms = MAX7360_DEBOUNCE_MIN;
+	ret = device_property_read_u32(pdev->dev.parent, "keypad-debounce-delay-ms",

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

Quoted 10 lines
drivers/input/keyboard/max7360-keypad.c new file +9 -0
+				       &max7360_keypad->debounce_ms);
+	if (ret == -EINVAL) {
+		dev_info(&pdev->dev, "Using default keypad-debounce-delay-ms: %u\n",
+			 max7360_keypad->debounce_ms);
+	} else if (ret < 0) {
+		dev_err(&pdev->dev,
+			"Failed to read keypad-debounce-delay-ms property\n");
+		return ret;
 
+	} else if (max7360_keypad->debounce_ms < MAX7360_DEBOUNCE_MIN ||

Redundant 'else'.

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

Quoted 1 line
drivers/input/keyboard/max7360-keypad.c new file +1 -0
+		   max7360_keypad->debounce_ms > MAX7360_DEBOUNCE_MAX) {

Maybe in_range()? But up to you, it takes start:len and not start:end.

Quoted 8 lines
drivers/input/keyboard/max7360-keypad.c new file +8 -0
+		dev_err(&pdev->dev,
+			"Invalid keypad-debounce-delay-ms: %u, should be between %u and %u.\n",
+			max7360_keypad->debounce_ms, MAX7360_DEBOUNCE_MIN, MAX7360_DEBOUNCE_MAX);
+		return -EINVAL;
+	}
+
+	return 0;
+}

...

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

Quoted 3 lines
drivers/input/keyboard/max7360-keypad.c new file +3 -0
+static int max7360_keypad_probe(struct platform_device *pdev)
+{
+	struct max7360_keypad *max7360_keypad;
	struct device *dev = &pdev>dev;

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

Quoted 7 lines
drivers/input/keyboard/max7360-keypad.c new file +6 -0
+	struct input_dev *input;
+	bool autorepeat;
+	int ret;
+	int irq;
 
+	if (!pdev->dev.parent)
+		return dev_err_probe(&pdev->dev, -ENODEV, "No parent device\n");

Just do like in the rest, i.e. local variable for regmap and its validness will be the one that indicates the wrong enumeration path.

Quoted 23 lines
drivers/input/keyboard/max7360-keypad.c new file +23 -0
+	irq = platform_get_irq_byname(to_platform_device(pdev->dev.parent), "intk");
+	if (irq < 0)
+		return irq;
+
+	max7360_keypad = devm_kzalloc(&pdev->dev, sizeof(*max7360_keypad), GFP_KERNEL);
+	if (!max7360_keypad)
+		return -ENOMEM;
+
+	max7360_keypad->regmap = dev_get_regmap(pdev->dev.parent, NULL);
+	if (!max7360_keypad->regmap)
+		return dev_err_probe(&pdev->dev, -ENODEV, "Could not get parent regmap\n");
+
+	ret = max7360_keypad_parse_dt(pdev, max7360_keypad, &autorepeat);
+	if (ret)
+		return ret;
+
+	input = devm_input_allocate_device(pdev->dev.parent);
+	if (!input)
+		return -ENOMEM;
+
+	max7360_keypad->input = input;
+
+	input->id.bustype = BUS_I2C;

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

Quoted 10 lines
drivers/input/keyboard/max7360-keypad.c new file +9 -0
+	input->name = pdev->name;
+	input->open = max7360_keypad_open;
+	input->close = max7360_keypad_close;
+
+	ret = matrix_keypad_build_keymap(NULL, NULL, MAX7360_MAX_KEY_ROWS, MAX7360_MAX_KEY_COLS,
+					 max7360_keypad->keycodes, input);
+	if (ret)
 
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to build keymap\n");

One line.

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

Quoted 9 lines
drivers/input/keyboard/max7360-keypad.c new file +9 -0
+
+	input_set_capability(input, EV_MSC, MSC_SCAN);
+	if (autorepeat)
+		__set_bit(EV_REP, input->evbit);
+
+	input_set_drvdata(input, max7360_keypad);
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, max7360_keypad_irq,
+					IRQF_TRIGGER_LOW | IRQF_ONESHOT,

What's wrong with the interrupt flags provided by firmware description?

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

Quoted 9 lines
drivers/input/keyboard/max7360-keypad.c new file +8 -0
+					"max7360-keypad", max7360_keypad);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "Failed to register interrupt\n");
+
+	ret = input_register_device(input);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "Could not register input device\n");
 
+	platform_set_drvdata(pdev, max7360_keypad);

Is it used?

Quoted 11 lines
drivers/input/keyboard/max7360-keypad.c new file +11 -0
+	ret = max7360_keypad_hw_init(max7360_keypad);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret, "Failed to initialize max7360 keypad\n");
+
+	device_init_wakeup(&pdev->dev, true);
+	ret = dev_pm_set_wake_irq(&pdev->dev, irq);
+	if (ret)
+		dev_warn(&pdev->dev, "Failed to set up wakeup irq: %d\n", ret);
+
+	return 0;
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#58 lore raw

Re: [PATCH v5 09/11] input: keyboard: Add support for MAX7360 keypad

Quoted 6 lines · Andy Shevchenko
Quoted 2 lines · 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.

...

Quoted 10 lines

drivers/input/keyboard/Kconfig config KEYBOARD_MAX7359 · line 434

Quoted 6 lines
drivers/input/keyboard/Kconfig +6 -0
+	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.

One paragraph is wrapped way too late or too early, can you make them approx. the same in terms of a line width?

Thanks. I had a look at all other Kconfigs, I believe they are all fixed now.

Quoted 12 lines

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

Quoted 9 lines
drivers/input/keyboard/max7360-keypad.c new file +9 -0
+
+	input_set_capability(input, EV_MSC, MSC_SCAN);
+	if (autorepeat)
+		__set_bit(EV_REP, input->evbit);
+
+	input_set_drvdata(input, max7360_keypad);
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, max7360_keypad_irq,
+					IRQF_TRIGGER_LOW | IRQF_ONESHOT,

What's wrong with the interrupt flags provided by firmware description?

So same question as for the GPIO driver: IRQF_TRIGGER_LOW from the firmware, but IRQF_ONESHOT from the driver? Or should everything come from the firmware?

Thanks again for your review.
Mathieu

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

Re: [PATCH v5 09/11] input: keyboard: Add support for MAX7360 keypad

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

On Tue, Mar 18, 2025 at 05:26:25PM +0100, Mathieu Dubois-Briand wrote:

...

Quoted 8 lines
Quoted 4 lines

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

Quoted 2 lines
drivers/input/keyboard/max7360-keypad.c new file +2 -0
+	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, max7360_keypad_irq,
+					IRQF_TRIGGER_LOW | IRQF_ONESHOT,

What's wrong with the interrupt flags provided by firmware description?

So same question as for the GPIO driver: IRQF_TRIGGER_LOW from the firmware, but IRQF_ONESHOT from the driver? Or should everything come from the firmware?

The same answer, yes, the Linux stuff (e.g., ONESHOT) should be given explicitly here.

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

Re: [PATCH v5 09/11] input: keyboard: Add support for MAX7360 keypad

In reply to Mathieu Dubois-Briand
kernel test robot noticed the following build errors:

Hi Mathieu,

kernel test robot noticed the following build errors:

[auto build test ERROR on a64dcfb451e254085a7daee5fe51bf22959d52d3]

url:    https://github.com/intel-lab-lkp/linux/commits/Mathieu-Dubois-Briand/dt-bindings-mfd-gpio-Add-MAX7360/20250319-003750
base:   a64dcfb451e254085a7daee5fe51bf22959d52d3
patch link:    https://lore.kernel.org/r/20250318-mdb-max7360-support-v5-9-fb20baf97da0%40bootlin.com
patch subject: [PATCH v5 09/11] input: keyboard: Add support for MAX7360 keypad
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20250319/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250319/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/input/keyboard/max7360-keypad.c: In function 'max7360_keypad_irq':

>> drivers/input/keyboard/max7360-keypad.c:57:8: error: implicit declaration of function 'FIELD_GET' [-Werror=implicit-function-declaration]
     row = FIELD_GET(MAX7360_FIFO_ROW, val);
           ^~~~~~~~~
   drivers/input/keyboard/max7360-keypad.c: In function 'max7360_keypad_hw_init':
>> drivers/input/keyboard/max7360-keypad.c:114:5: error: implicit declaration of function 'FIELD_PREP'; did you mean 'EV_REP'? [-Werror=implicit-function-declaration]
        FIELD_PREP(MAX7360_DEBOUNCE, val));
        ^~~~~~~~~~
        EV_REP

cc1: some warnings being treated as errors

vim +/FIELD_GET +57 drivers/input/keyboard/max7360-keypad.c

    29	
    30	static irqreturn_t max7360_keypad_irq(int irq, void *data)
    31	{
    32		struct max7360_keypad *max7360_keypad = data;
    33		unsigned int val;
    34		unsigned int row, col;
    35		unsigned int release;
    36		unsigned int code;
    37		int ret;
    38	
    39		do {
    40			ret = regmap_read(max7360_keypad->regmap, MAX7360_REG_KEYFIFO, &val);
    41			if (ret) {
    42				dev_err(&max7360_keypad->input->dev, "Failed to read max7360 FIFO");
    43				return IRQ_NONE;
    44			}
    45	
    46			/* FIFO overflow: ignore it and get next event. */
    47			if (val == MAX7360_FIFO_OVERFLOW)
    48				dev_warn(&max7360_keypad->input->dev, "max7360 FIFO overflow");
    49		} while (val == MAX7360_FIFO_OVERFLOW);
    50	
    51		if (val == MAX7360_FIFO_EMPTY) {
    52			dev_dbg(&max7360_keypad->input->dev, "Got a spurious interrupt");
    53	
    54			return IRQ_NONE;
    55		}
    56	
  > 57		row = FIELD_GET(MAX7360_FIFO_ROW, val);
    58		col = FIELD_GET(MAX7360_FIFO_COL, val);
    59		release = val & MAX7360_FIFO_RELEASE;
    60	
    61		code = MATRIX_SCAN_CODE(row, col, MAX7360_ROW_SHIFT);
    62	
    63		dev_dbg(&max7360_keypad->input->dev, "key[%d:%d] %s\n", row, col,
    64			release ? "release" : "press");
    65	
    66		input_event(max7360_keypad->input, EV_MSC, MSC_SCAN, code);
    67		input_report_key(max7360_keypad->input, max7360_keypad->keycodes[code], !release);
    68		input_sync(max7360_keypad->input);
    69	
    70		return IRQ_HANDLED;
    71	}
    72	
    73	static int max7360_keypad_open(struct input_dev *pdev)
    74	{
    75		struct max7360_keypad *max7360_keypad = input_get_drvdata(pdev);
    76		int ret;
    77	
    78		/*
    79		 * Somebody is using the device: get out of sleep.
    80		 */
    81		ret = regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_CONFIG,
    82					MAX7360_CFG_SLEEP, MAX7360_CFG_SLEEP);
    83		if (ret) {
    84			dev_err(&max7360_keypad->input->dev,
    85				"Failed to write max7360 configuration\n");
    86			return ret;
    87		}
    88	
    89		return 0;
    90	}
    91	
    92	static void max7360_keypad_close(struct input_dev *pdev)
    93	{
    94		struct max7360_keypad *max7360_keypad = input_get_drvdata(pdev);
    95		int ret;
    96	
    97		/*
    98		 * Nobody is using the device anymore: go to sleep.
    99		 */
   100		ret = regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_CONFIG, MAX7360_CFG_SLEEP, 0);
   101		if (ret)
   102			dev_err(&max7360_keypad->input->dev,
   103				"Failed to write max7360 configuration\n");
   104	}
   105	
   106	static int max7360_keypad_hw_init(struct max7360_keypad *max7360_keypad)
   107	{
   108		unsigned int val;
   109		int ret;
   110	
   111		val = max7360_keypad->debounce_ms - MAX7360_DEBOUNCE_MIN;
   112		ret = regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_DEBOUNCE,
   113					MAX7360_DEBOUNCE,
 > 114					FIELD_PREP(MAX7360_DEBOUNCE, val));

115 if (ret) {
116 return dev_err_probe(&max7360_keypad->input->dev, ret,
117 "Failed to write max7360 debounce configuration\n");
118 }
119
120 ret = regmap_write_bits(max7360_keypad->regmap, MAX7360_REG_INTERRUPT,
121 MAX7360_INTERRUPT_TIME_MASK,
122 FIELD_PREP(MAX7360_INTERRUPT_TIME_MASK, 1));
123 if (ret) {
124 return dev_err_probe(&max7360_keypad->input->dev, ret,
125 "Failed to write max7360 keypad interrupt configuration\n");
126 }
127
128 return 0;
129 }
130

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#61 lore raw

PATCH v5 10/11 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 | 161 ++++++++++++++++++++++++++++++++++++
 3 files changed, 173 insertions(+)
drivers/input/misc/Kconfig +11 -0
index 13d135257e06..77b07e053265 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 MFD_MAX7360
+	select PINCTRL_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 6d91804d0a6f..c454fba3a3ae 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 +161 -0

161 lines not on this page · raw message

Signature · 1 line
2.39.5
#62 lore raw

Re: [PATCH v5 10/11] input: misc: Add support for MAX7360 rotary

Quoted 2 lines · Mathieu Dubois-Briand

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

...

drivers/input/misc/Kconfig config INPUT_M68K_BEEP · line 242

Quoted 6 lines
drivers/input/misc/Kconfig +6 -0
+	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.

Seems all your patches have unaligned line widths in the help texts.

...

+ bitfield.h
+ device/devres.h
+ dev_printk.h

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

Quoted 7 lines
drivers/input/misc/max7360-rotary.c new file +6 -0
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/mfd/max7360.h>
+#include <linux/property.h>
 
+#include <linux/of.h>

Why?

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

Quoted 5 lines
drivers/input/misc/max7360-rotary.c new file +4 -0
+#include <linux/platform_device.h>
+#include <linux/pm_wakeirq.h>
+#include <linux/regmap.h>
 
+#include <linux/slab.h>

Not needed.

+ types.h

...

Quoted 12 lines
drivers/input/misc/max7360-rotary.c new file +12 -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\n");
+		return IRQ_NONE;
+	}

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

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

This is strange:
1) why casting to begin with?
2) why to C type and not kernel (s8) type?

Quoted 4 lines
drivers/input/misc/max7360-rotary.c new file +4 -0
+	input_sync(max7360_rotary->input);
+
+	return IRQ_HANDLED;
+}

...

Quoted 6 lines
drivers/input/misc/max7360-rotary.c new file +6 -0
+static int max7360_rotary_hw_init(struct max7360_rotary *max7360_rotary)
+{
+	int val;
+	int ret;
+
+	val = FIELD_PREP(MAX7360_ROT_DEBOUNCE, max7360_rotary->debounce_ms) |

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

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

Just

	return ret;

?

Quoted 1 line

+}

...

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

Quoted 3 lines
drivers/input/misc/max7360-rotary.c new file +3 -0
+static int max7360_rotary_probe(struct platform_device *pdev)
+{
+	struct max7360_rotary *max7360_rotary;
	struct device *dev = &pdev->dev;

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

Quoted 6 lines
drivers/input/misc/max7360-rotary.c new file +5 -0
+	struct input_dev *input;
+	int irq;
+	int ret;
 
+	if (!pdev->dev.parent)
+		return dev_err_probe(&pdev->dev, -ENODEV, "No parent device\n");

Just check for regmap.

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

Quoted 2 lines
drivers/input/misc/max7360-rotary.c new file +2 -0
+	irq = platform_get_irq_byname(to_platform_device(pdev->dev.parent),
+				      "inti");

One line (and instead of that dance with container_of(), just use fwnode_irq_get_byname().

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

Quoted 5 lines
drivers/input/misc/max7360-rotary.c new file +5 -0
+	if (irq < 0)
+		return irq;
+
+	max7360_rotary = devm_kzalloc(&pdev->dev, sizeof(*max7360_rotary),
+				      GFP_KERNEL);

One line.

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

Quoted 8 lines
drivers/input/misc/max7360-rotary.c new file +7 -0
+	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");

One line.

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

Quoted 4 lines
drivers/input/misc/max7360-rotary.c new file +4 -0
+	device_property_read_u32(pdev->dev.parent, "linux,axis",
+				 &max7360_rotary->axis);
+	device_property_read_u32(pdev->dev.parent, "rotary-debounce-delay-ms",
+				 &max7360_rotary->debounce_ms);

No, instead of parent, make sure that fwnode is propagated to the children (and tadaam, it's done in MFD already).

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

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

Quoted 10 lines
drivers/input/misc/max7360-rotary.c new file +9 -0
+	input->name = pdev->name;
+	input->dev.parent = &pdev->dev;
+
+	input_set_capability(input, EV_REL, max7360_rotary->axis);
+	input_set_drvdata(input, max7360_rotary);
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
+					max7360_rotary_irq,
 
+					IRQF_TRIGGER_LOW | IRQF_ONESHOT | IRQF_SHARED,

What's wrong with the firmware description of the interrupt?

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

Quoted 10 lines
drivers/input/misc/max7360-rotary.c new file +9 -0
+					"max7360-rotary", max7360_rotary);
+	if (ret)
+		return dev_err_probe(&pdev->dev, ret,
+				     "Failed to register interrupt\n");
+
+	ret = input_register_device(input);
+	if (ret)
 
+		return dev_err_probe(&pdev->dev, ret,
+				     "Could not register input device\n");

One line.

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

Quoted 1 line
drivers/input/misc/max7360-rotary.c new file +1 -0
+	platform_set_drvdata(pdev, max7360_rotary);

Is it used?

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

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

In the other driver the HW initialisation and wake setup were swapped, can you choose one way? Otherwise both cases need a comment to explain the order of calls.

Quoted 2 lines
(quoted diff) +2 -0
+	return 0;
+}
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#63 lore raw

Re: [PATCH v5 10/11] input: misc: Add support for MAX7360 rotary

Quoted 24 lines · Andy Shevchenko
Quoted 2 lines · Mathieu Dubois-Briand

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

...

Quoted 18 lines
drivers/input/misc/max7360-rotary.c new file +18 -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\n");
+		return IRQ_NONE;
+	}
+
+	if (val == 0) {
+		dev_dbg(&max7360_rotary->input->dev,
+			"Got a spurious interrupt\n");
+
+		return IRQ_NONE;
Quoted 9 lines

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

Quoted 4 lines
drivers/input/misc/max7360-rotary.c new file +4 -0
+	}
+
+	input_report_rel(max7360_rotary->input, max7360_rotary->axis,
+			 (int8_t)val);

This is strange:
1) why casting to begin with?
2) why to C type and not kernel (s8) type?

I believe the cast is needed, as, while the value read with regmap_read() is stored in an int, the underlying value is indeed a signed 8 bits integer.

Without cast negative values will not be correct: -1 (0xFF) -> will be interpreted as 255 (0x000000FF).

Ok for s8.

Thanks for your review
Mathieu

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

Re: [PATCH v5 10/11] input: misc: Add support for MAX7360 rotary

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

On Tue, Mar 18, 2025 at 05:26:26PM +0100, Mathieu Dubois-Briand wrote:

...

Quoted 1 line
Quoted 1 line

Review

Quoted 1 line
(quoted diff) +1 -0
+	int val;

Btw, this has to be unsigned to match the API.

Quoted 16 lines
Quoted 9 lines
Quoted 8 lines
drivers/input/misc/max7360-rotary.c new file +8 -0
+	int ret;
+
+	ret = regmap_read(max7360_rotary->regmap, MAX7360_REG_RTR_CNT, &val);
+	if (ret < 0) {
+		dev_err(&max7360_rotary->input->dev,
+			"Failed to read rotary counter\n");
+		return IRQ_NONE;
+	}
Quoted 6 lines

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

Quoted 2 lines
drivers/input/misc/max7360-rotary.c new file +2 -0
+	input_report_rel(max7360_rotary->input, max7360_rotary->axis,
+			 (int8_t)val);

This is strange:
1) why casting to begin with?
2) why to C type and not kernel (s8) type?

Quoted 6 lines

I believe the cast is needed, as, while the value read with regmap_read() is stored in an int, the underlying value is indeed a signed 8 bits integer.

Without cast negative values will not be correct: -1 (0xFF) -> will be interpreted as 255 (0x000000FF).

With the above fix it makes sense, but it's not clear for the reader still. What you want is most likely to call sign_extend32().

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

Re: [PATCH v5 10/11] input: misc: Add support for MAX7360 rotary

In reply to Mathieu Dubois-Briand
kernel test robot noticed the following build errors:

Hi Mathieu,

kernel test robot noticed the following build errors:

[auto build test ERROR on a64dcfb451e254085a7daee5fe51bf22959d52d3]

url:    https://github.com/intel-lab-lkp/linux/commits/Mathieu-Dubois-Briand/dt-bindings-mfd-gpio-Add-MAX7360/20250319-003750
base:   a64dcfb451e254085a7daee5fe51bf22959d52d3
patch link:    https://lore.kernel.org/r/20250318-mdb-max7360-support-v5-10-fb20baf97da0%40bootlin.com
patch subject: [PATCH v5 10/11] input: misc: Add support for MAX7360 rotary
config: m68k-allmodconfig (https://download.01.org/0day-ci/archive/20250319/[email protected]/config)
compiler: m68k-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250319/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/input/misc/max7360-rotary.c: In function 'max7360_rotary_hw_init':

>> drivers/input/misc/max7360-rotary.c:58:8: error: implicit declaration of function 'FIELD_PREP'; did you mean 'EV_REP'? [-Werror=implicit-function-declaration]
     val = FIELD_PREP(MAX7360_ROT_DEBOUNCE, max7360_rotary->debounce_ms) |
           ^~~~~~~~~~
           EV_REP

cc1: some warnings being treated as errors

vim +58 drivers/input/misc/max7360-rotary.c

    52	
    53	static int max7360_rotary_hw_init(struct max7360_rotary *max7360_rotary)
    54	{
    55		int val;
    56		int ret;
    57	
  > 58		val = FIELD_PREP(MAX7360_ROT_DEBOUNCE, max7360_rotary->debounce_ms) |
    59			FIELD_PREP(MAX7360_ROT_INTCNT, 1) | MAX7360_ROT_INTCNT_DLY;
    60		ret = regmap_write(max7360_rotary->regmap, MAX7360_REG_RTRCFG, val);
    61		if (ret) {
    62			dev_err(&max7360_rotary->input->dev,
    63				"Failed to set max7360 rotary encoder configuration\n");
    64			return ret;
    65		}
    66	
    67		return 0;
    68	}
    69	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#66 lore raw

Re: [PATCH v5 10/11] input: misc: Add support for MAX7360 rotary

In reply to Mathieu Dubois-Briand
kernel test robot noticed the following build warnings:

Hi Mathieu,

kernel test robot noticed the following build warnings:

[auto build test WARNING on a64dcfb451e254085a7daee5fe51bf22959d52d3]

url:    https://github.com/intel-lab-lkp/linux/commits/Mathieu-Dubois-Briand/dt-bindings-mfd-gpio-Add-MAX7360/20250319-003750
base:   a64dcfb451e254085a7daee5fe51bf22959d52d3
patch link:    https://lore.kernel.org/r/20250318-mdb-max7360-support-v5-10-fb20baf97da0%40bootlin.com
patch subject: [PATCH v5 10/11] input: misc: Add support for MAX7360 rotary
config: nios2-kismet-CONFIG_PINCTRL_MAX7360-CONFIG_INPUT_MAX7360_ROTARY-0-0 (https://download.01.org/0day-ci/archive/20250320/[email protected]/config)
reproduce: (https://download.01.org/0day-ci/archive/20250320/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

kismet warnings: (new ones prefixed by >>)

>> kismet: WARNING: unmet direct dependencies detected for PINCTRL_MAX7360 when selected by INPUT_MAX7360_ROTARY

WARNING: unmet direct dependencies detected for PINCTRL_MAX7360
Depends on [n]: PINCTRL [=n] && MFD_MAX7360 [=y]
Selected by [y]:
- INPUT_MAX7360_ROTARY [=y] && INPUT [=y] && INPUT_MISC [=y] && MFD_MAX7360 [=y]

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author maintainer
#67 lore raw

PATCH v5 11/11 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 | 13 +++++++++++++
 1 file changed, 13 insertions(+)
MAINTAINERS +13 -0
index 25c86f47353d..2b67d356a4a7 100644
@@ -14259,6 +14259,19 @@ 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/pinctrl/pinctrl-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
#68 lore raw
In reply to Mathieu Dubois-Briand
Quoted 10 lines · Mathieu Dubois-Briand

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.

Quoted 2 lines

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

Thanks!

Skeleton more or less looks at it's stable phase, there are tons of the style and small amendments that may be made. I would expect one or two at most new versions of this series.

Signature · 2 lines
With Best Regards,
Andy Shevchenko