add driver for max16150
Subsystems (3)
cover add driver for max16150
Introduce pushbutton control and debouncing support for the MAX16150/MAX16169. The component is a low‑power on/off controller featuring an integrated switch debouncer and internal latch, designed to accept a noisy mechanical pushbutton input while providing a clean, stable latched output. It also includes a one‑shot interrupt output for event signaling, enabling reliable switch interfacing in low‑power embedded systems.
---
Marc Paolo Sosa (2):
dt-bindings: input: add adi,max16150.yaml
input: misc: add driver for max16150
.../devicetree/bindings/input/adi,max16150.yaml | 57 ++++++++ drivers/input/misc/Kconfig | 9 ++ drivers/input/misc/Makefile | 1 + drivers/input/misc/max16150.c | 161 +++++++++++++++++++++ 4 files changed, 228 insertions(+)
---
base-commit: e7b53288d9ea899abc6d47a7f20065ab511a810c
change-id: 20260223-max16150-8ef94e643cd0
Best regards,
Signature · 1 line
Marc Paolo Sosa <[email protected]>
PATCH 1/2 dt-bindings: input: add adi,max16150.yaml
Add documentation for device tree bindings for MAX16150/MAX16169
--- .../devicetree/bindings/input/adi,max16150.yaml | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+)
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +57 -0
@@ -0,0 +1,57 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/adi,max16150.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices MAX16150/MAX16169 nanoPower Pushbutton On/Off Controller + +maintainers: + - Marc Paolo Sosa <[email protected]> + +description: + The MAX16150/MAX16169 is a low-power pushbutton on/off controller with a + switch debouncer and built-in latch. It accepts a noisy input from a + mechanical switch and produces a clean latched output, as well as a one-shot + interrupt output. + +properties: + compatible: + description: + Specifies the supported device variants. The MAX16150 and MAX16169 are supported. + enum: + - adi,max16150a + - adi,max16150b + - adi,max16169a + - adi,max16169b + + interrupt-gpio: + maxItems: 1 + + clr-gpios: + description: + Clear Input. Pulling CLR low deasserts the latched OUT signal. If OUT is + already deasserted when CLR is pulled low, the state of OUT is unchanged. + maxItems: 1 + + linux,code: + default: KEY_POWER + +required: + - compatible + - interrupt-gpios + - clr-gpios + +additionalProperties: false + +examples: + - | + #include <dt-bindings/input/linux-event-codes.h> + #include <dt-bindings/gpio/gpio.h> + + power-button { + compatible = "adi,max16150a"; + interrupt-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>; + clr-gpios = <&gpio 4 GPIO_ACTIVE_LOW>; + linux,code = <KEY_POWER>; + };
Signature · 1 line
2.34.1
Rob Herring (Arm)
maintainerRe: [PATCH 1/2] dt-bindings: input: add adi,max16150.yaml
Quoted 7 lines · Marc Paolo Sosa
Add documentation for device tree bindings for MAX16150/MAX16169
Signed-off-by Marc Paolo Sosa <[email protected]>--- .../devicetree/bindings/input/adi,max16150.yaml | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+)
My bot found errors running 'make dt_binding_check' on your patch:
yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/input/adi,max16150.example.dtb: power-button (adi,max16150a): 'interrupt-gpios' does not match any of the regexes: '^pinctrl-[0-9]+$'
from schema $id: http://devicetree.org/schemas/input/adi,max16150.yaml
doc reference errors (make refcheckdocs):
See https://patchwork.kernel.org/project/devicetree/patch/[email protected]
The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that DT_SCHEMA_FILES can be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
RE: [PATCH 1/2] dt-bindings: input: add adi,max16150.yaml
Quoted 55 lines
-----Original Message-----
From: Rob Herring (Arm) <[email protected]>
Sent: Monday, February 23, 2026 8:25 PM
To: Sosa, Marc Paolo <[email protected]>
Cc: Dmitry Torokhov <[email protected]>; linux- [email protected]; Conor Dooley <[email protected]>; [email protected]; [email protected]; Krzysztof Kozlowski <[email protected]>
Subject: Re: [PATCH 1/2] dt-bindings: input: add adi,max16150.yaml[External]
Quoted 5 lines · Marc Paolo Sosa
Add documentation for device tree bindings for MAX16150/MAX16169
Signed-off-by Marc Paolo Sosa <[email protected]>--- .../devicetree/bindings/input/adi,max16150.yaml | 57++++++++++++++++++++++
Quoted 2 lines
1 file changed, 57 insertions(+)My bot found errors running 'make
dt_binding_check' on your patch:yamllint warnings/errors:
dtschema/dtc warnings/errors:
/builds/robherring/dt-review- ci/linux/Documentation/devicetree/bindings/input/adi,max16150.example.dtb : power-button (adi,max16150a): 'interrupt-gpios' does not match any of the
regexes: '^pinctrl-[0-9]+$'
from schema $id:
https://urldefense.com/v3/__http://devicetree.org/schemas/input/adi,max16
150.yaml__;!!A3Ni8CS0y2Y!-TPsir0eSI17GHXi7gGeaK1XizFHf0bf6SbAJdX07Ztz- nAbFzqUqkvcxua95NPqfd9F9hYLmClYnD4Q$doc reference errors (make refcheckdocs):
See
https://urldefense.com/v3/__https://patchwork.kernel.org/project/devicetree
/patch/20260223-max16150-v1-1-
[email protected]__;!!A3Ni8CS0y2Y!-
TPsir0eSI17GHXi7gGeaK1XizFHf0bf6SbAJdX07Ztz-
nAbFzqUqkvcxua95NPqfd9F9hYLmMWFLC-A$The base for the series is generally the latest rc1. A different dependency should be noted in *this* patch.
If you already ran 'make
dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:
Quoted 5 lines
pip3 install dtschema --upgrade
Please check and re-submit after running the above command yourself. Note that
DT_SCHEMA_FILEScan be set to your schema file to speed up checking your schema. However, it must be unset to test all examples with your schema.
Alright, will check this out before sending another patch.
Thanks,
Pao
Rob Herring
maintainerRe: [PATCH 1/2] dt-bindings: input: add adi,max16150.yaml
In reply to Marc Paolo SosaQuoted 24 lines · Marc Paolo Sosa
Add documentation for device tree bindings for MAX16150/MAX16169
Signed-off-by Marc Paolo Sosa <[email protected]>--- .../devicetree/bindings/input/adi,max16150.yaml | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+)Documentation/devicetree/bindings/input/adi,max16150.yaml new file +11
-0@@ -0,0 +1,57 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/adi,max16150.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Analog Devices MAX16150/MAX16169 nanoPower Pushbutton On/Off Controller + +maintainers: + - Marc Paolo Sosa <[email protected]> +
Documentation/devicetree/bindings/input/adi,max16150.yaml line 21
Quoted 10 lines
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +10
-0+description: + The MAX16150/MAX16169 is a low-power pushbutton on/off controller with a + switch debouncer and built-in latch. It accepts a noisy input from a + mechanical switch and produces a clean latched output, as well as a one-shot + interrupt output. + +properties: + compatible: + description: + Specifies the supported device variants. The MAX16150 and MAX16169 are supported.
Drop description.
Documentation/devicetree/bindings/input/adi,max16150.yaml line 26
Quoted 5 lines
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +5
-0+ enum: + - adi,max16150a + - adi,max16150b + - adi,max16169a + - adi,max16169b
What's the diff between a and b? If nothing s/w needs to know about, then maybe you don't need to distinguish.
Documentation/devicetree/bindings/input/adi,max16150.yaml line 29
Quoted 3 lines
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +3
-0+ + interrupt-gpio: + maxItems: 1
Use 'interrupts' property.
Quoted 32 lines
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +28
-0+ + clr-gpios: + description: + Clear Input. Pulling CLR low deasserts the latched OUT signal. If OUT is + already deasserted when CLR is pulled low, the state of OUT is unchanged. + maxItems: 1 + + linux,code: + default: KEY_POWER + +required: + - compatible + - interrupt-gpios + - clr-gpios + +additionalProperties: false + +examples: + - | + #include <dt-bindings/input/linux-event-codes.h> + #include <dt-bindings/gpio/gpio.h> + + power-button { + compatible = "adi,max16150a"; + interrupt-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>; + clr-gpios = <&gpio 4 GPIO_ACTIVE_LOW>; + linux,code = <KEY_POWER>; + };Signature · 2 lines
-- 2.34.1
RE: [PATCH 1/2] dt-bindings: input: add adi,max16150.yaml
Quoted 113 lines
-----Original Message-----
From: Rob Herring <[email protected]>
Sent: Tuesday, February 24, 2026 12:51 AM
To: Sosa, Marc Paolo <[email protected]>
Cc: Dmitry Torokhov <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]
Subject: Re: [PATCH 1/2] dt-bindings: input: add adi,max16150.yaml[External]
Quoted 5 lines · Marc Paolo Sosa
Add documentation for device tree bindings for MAX16150/MAX16169
Signed-off-by Marc Paolo Sosa <[email protected]>--- .../devicetree/bindings/input/adi,max16150.yaml | 57++++++++++++++++++++++
Quoted 10 lines
1 file changed, 57 insertions(+)Documentation/devicetree/bindings/input/adi,max16150.yaml new file +0
-0Documentation/devicetree/bindings/input/adi,max16150.yaml line 4
Quoted 4 lines
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +4
-0@@ -0,0 +1,57 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) %YAML 1.2 +--- +$id: +https://urldefense.com/v3/__http://devicetree.org/schemas/input/adi,m+ax16150.yaml*__;Iw!!A3Ni8CS0y2Y!7MP9aN8nPEM3L2rIf_pWYnGRpvrMnRa dsVK3J
Documentation/devicetree/bindings/input/adi,max16150.yaml line 7
Quoted 4 lines
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +3
-0+dATD43g-6ZDMtcTwePpZWP1Ji7DaZoV6c0Iy5nMrfJM$ +$schema: +https://urldefense.com/v3/__http://devicetree.org/meta-schemas/core.y+aml*__;Iw!!A3Ni8CS0y2Y!7MP9aN8nPEM3L2rIf_pWYnGRpvrMnRadsVK3JdA TD43g-6
Quoted 11 lines
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +11
-0+ZDMtcTwePpZWP1Ji7DaZoV6c0IywbOF-bm$ + +title: Analog Devices MAX16150/MAX16169 nanoPower Pushbutton On/Off +Controller + +maintainers: + - Marc Paolo Sosa <[email protected]> + +description: + The MAX16150/MAX16169 is a low-power pushbutton on/off controller +with aDocumentation/devicetree/bindings/input/adi,max16150.yaml
Quoted 10 lines
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +10
-0+ switch debouncer and built-in latch. It accepts a noisy input from +a + mechanical switch and produces a clean latched output, as well as a +one-shot + interrupt output. + +properties: + compatible: + description: + Specifies the supported device variants. The MAX16150 and MAX16169are supported.
Drop description.
Documentation/devicetree/bindings/input/adi,max16150.yaml line 26
Quoted 5 lines
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +5
-0+ enum: + - adi,max16150a + - adi,max16150b + - adi,max16169a + - adi,max16169bWhat's the diff between a and b? If nothing s/w needs to know about, then maybe you don't need to distinguish.
Documentation/devicetree/bindings/input/adi,max16150.yaml line 29
Quoted 3 lines
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +3
-0+ + interrupt-gpio: + maxItems: 1Use 'interrupts' property.
Documentation/devicetree/bindings/input/adi,max16150.yaml
Quoted 5 lines
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +5
-0+ + clr-gpios: + description: + Clear Input. Pulling CLR low deasserts the latched OUT signal. If OUT is + already deasserted when CLR is pulled low, the state of OUT isunchanged.
Quoted 24 lines
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +23
-0+ maxItems: 1 + + linux,code: + default: KEY_POWER + +required: + - compatible + - interrupt-gpios + - clr-gpios + +additionalProperties: false + +examples: + - | + #include <dt-bindings/input/linux-event-codes.h> + #include <dt-bindings/gpio/gpio.h> + + power-button { + compatible = "adi,max16150a"; + interrupt-gpios = <&gpio 17 GPIO_ACTIVE_HIGH>; + clr-gpios = <&gpio 4 GPIO_ACTIVE_LOW>; + linux,code = <KEY_POWER>; + };
Quoted 3 lines
Quoted 3 lines
--
2.34.1
This is noted, I'll test this out and will apply it on my next patch.
Regards,
Pao
Re: [PATCH 1/2] dt-bindings: input: add adi,max16150.yaml
In reply to Marc Paolo SosaDocumentation/devicetree/bindings/input/adi,max16150.yaml line 26
Quoted 10 lines · On 23/02/2026 12:03, Marc Paolo Sosa via B4 Relay wrote:
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +10
-0+ +properties: + compatible: + description: + Specifies the supported device variants. The MAX16150 and MAX16169 are supported. + enum: + - adi,max16150a + - adi,max16150b + - adi,max16169a + - adi,max16169b
Your driver code says 16150 and 16169 are compatible, to express it with fallback (oneOf). See example-schema.
Best regards,
Krzysztof
RE: [PATCH 1/2] dt-bindings: input: add adi,max16150.yaml
Quoted 21 lines
-----Original Message-----
From: Krzysztof Kozlowski <[email protected]>
Sent: Tuesday, February 24, 2026 1:02 AM
To: Sosa, Marc Paolo <[email protected]>; Dmitry Torokhov <[email protected]>; Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]
Subject: Re: [PATCH 1/2] dt-bindings: input: add adi,max16150.yaml[External]
Documentation/devicetree/bindings/input/adi,max16150.yaml
Quoted 5 lines · On 23/02/2026 12:03, Marc Paolo Sosa via B4 Relay wrote:
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +5
-0+ +properties: + compatible: + description: + Specifies the supported device variants. The MAX16150 and MAX16169are supported.
Quoted 9 lines
Documentation/devicetree/bindings/input/adi,max16150.yaml line 26
Quoted 5 lines
Documentation/devicetree/bindings/input/adi,max16150.yaml new file +5
-0+ enum: + - adi,max16150a + - adi,max16150b + - adi,max16169a + - adi,max16169bYour driver code says 16150 and 16169 are compatible, to express it with fallback (oneOf). See example-schema.
This is noted; I will apply this on my next patch.
Thanks,
Pao
PATCH 2/2 input: misc: add driver for max16150
In reply to Marc Paolo SosaMAX16150/MAX16169 nanoPower Pushbutton On/Off Controller
--- drivers/input/misc/Kconfig | 9 +++ drivers/input/misc/Makefile | 1 + drivers/input/misc/max16150.c | 161 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+)
drivers/input/misc/Kconfig +9 -0
@@ -178,6 +178,15 @@ config INPUT_E3X0_BUTTON To compile this driver as a module, choose M here: the module will be called e3x0_button. +config INPUT_MAX16150_PWRBUTTON + tristate "MAX16150/MAX16169 Pushbutton driver" + help + Say Y here if you want to enable power key reporting via + MAX16150/MAX16169 nanoPower Pushbutton On/Off Controller. + + To compile this driver as a module, choose M here. The module will + be called max16150. + config INPUT_PCSPKR tristate "PC Speaker support" depends on PCSPKR_PLATFORM
drivers/input/misc/Makefile +1 -0
@@ -52,6 +52,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_MAX16150_PWRBUTTON) += max16150.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
drivers/input/misc/max16150.c new file +161 -0
161 lines not on this page · raw message
Signature · 1 line
2.34.1
Dmitry Torokhov
maintainerRe: [PATCH 2/2] input: misc: add driver for max16150
Hi Marc,
Quoted 68 lines · On Mon, Feb 23, 2026 at 07:03:40PM +0800, Marc Paolo Sosa via B4 Relay wrote:
From: Marc Paolo Sosa <[email protected]>
MAX16150/MAX16169 nanoPower Pushbutton On/Off Controller
Signed-off-by Marc Paolo Sosa <[email protected]>--- drivers/input/misc/Kconfig | 9 +++ drivers/input/misc/Makefile | 1 + drivers/input/misc/max16150.c | 161 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+)drivers/input/misc/Kconfig +9
-0@@ -178,6 +178,15 @@ config INPUT_E3X0_BUTTON To compile this driver as a module, choose M here: the module will be called e3x0_button. +config INPUT_MAX16150_PWRBUTTON + tristate "MAX16150/MAX16169 Pushbutton driver" + help + Say Y here if you want to enable power key reporting via + MAX16150/MAX16169 nanoPower Pushbutton On/Off Controller. + + To compile this driver as a module, choose M here. The module will + be called max16150. + config INPUT_PCSPKR tristate "PC Speaker support" depends on PCSPKR_PLATFORMdrivers/input/misc/Makefile +1
-0@@ -52,6 +52,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_MAX16150_PWRBUTTON) += max16150.o obj-$(CONFIG_INPUT_MAX7360_ROTARY) += max7360-rotary.o obj-$(CONFIG_INPUT_MAX77650_ONKEY) += max77650-onkey.o obj-$(CONFIG_INPUT_MAX77693_HAPTIC) += max77693-haptic.odrivers/input/misc/max16150.c new file +19
-0@@ -0,0 +1,161 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Analog Devices MAX16150/MAX16169 Pushbutton Driver +* +* Copyright 2025 Analog Devices Inc. +*/ + +#include <linux/delay.h> +#include <linux/init.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/gpio/consumer.h> +#include <linux/kernel.h> +#include <linux/mod_devicetable.h> +#include <linux/platform_device.h> +#include <linux/property.h> + +#define MAX16150_LONG_INTERRUPT 120000000 +
drivers/input/misc/max16150.c line 29
Quoted 10 lines
drivers/input/misc/max16150.c new file +10
-0+struct max16150_chip_info { +bool has_clr_gpio; +}; + +struct max16150_device { +struct input_dev *input; +struct gpio_desc *gpiod; +struct gpio_desc *clr_gpiod; +const struct max16150_chip_info *chip_info; +u64 low, high, duration;
I do not think you need to store "high" and "duration", just "press" time. I also do not think you need nanosecond resilution, jiffies will do.
Quoted 10 lines
drivers/input/misc/max16150.c new file +10
-0+unsigned int keycode; +}; + +static irqreturn_t max16150_irq_handler (int irq,void *_max16150) +{ +struct max16150_device *max16150 = _max16150; +int value; + + value =gpiod_get_value (max16150->gpiod); +
drivers/input/misc/max16150.c line 49
Quoted 10 lines
drivers/input/misc/max16150.c new file +10
-0+if (!value) { + max16150->low =ktime_get_ns (); +return IRQ_HANDLED ; + } + + max16150->high =ktime_get_ns (); +if (max16150->low) { + max16150->duration = max16150->high - max16150->low; + +if (max16150->duration >MAX16150_LONG_INTERRUPT ) {
time_after() is probably what you need here.
drivers/input/misc/max16150.c line 52
Quoted 3 lines
drivers/input/misc/max16150.c new file +3
-0+gpiod_set_value (max16150->clr_gpiod,1 ); +input_report_key (max16150->input, max16150->keycode,1 ); +input_sync (max16150->input);
Why is press not reported right away?
Quoted 14 lines
drivers/input/misc/max16150.c new file +14
-0+input_report_key (max16150->input, max16150->keycode,0 ); +input_sync (max16150->input); + } + + max16150->low =0 ; + } + +return IRQ_HANDLED ; +} + +static const struct max16150_chip_info max16150_variant_a = { + .has_clr_gpio = true, +}; +
drivers/input/misc/max16150.c line 76
Quoted 10 lines
drivers/input/misc/max16150.c new file +10
-0+static const struct max16150_chip_info max16150_variant_b = { + .has_clr_gpio = false, +}; + +static int max16150_probe (struct platform_device *pdev) +{ +const struct max16150_chip_info *chip_info; +struct max16150_device *max16150; +struct device *dev = &pdev->dev; +int err, irq, ret;
Why do you need both err and ret?
Quoted 12 lines
drivers/input/misc/max16150.c new file +12
-0+u32 keycode; + + chip_info =device_get_match_data (dev); +if (!chip_info) +return -EINVAL ; + + max16150 =devm_kzalloc (dev,sizeof (*max16150),GFP_KERNEL ); +if (!max16150) +return -ENOMEM ; + + max16150->chip_info = chip_info; +
drivers/input/misc/max16150.c line 98
Quoted 10 lines
drivers/input/misc/max16150.c new file +10
-0+ max16150->input =devm_input_allocate_device (dev); +if (!max16150->input) +return -ENOMEM ; + + max16150->input->name ="MAX16150 Pushbutton" ; + max16150->input->phys ="max16150/input0" ; + max16150->input->id.bustype =BUS_HOST ; + + keycode =KEY_POWER ; + ret =device_property_read_u32 (dev,"linux,code" , &keycode);
err = ...
Quoted 9 lines
drivers/input/misc/max16150.c new file +9
-0+if (ret) +return dev_err_probe (dev, ret,"Failed to get keycode\n" ); + + max16150->keycode = keycode; + +input_set_capability (max16150->input,EV_KEY , max16150->keycode); + + max16150->gpiod =devm_gpiod_get (dev,"interrupt" ,GPIOD_IN ); +if (IS_ERR (max16150->gpiod))
drivers/input/misc/max16150.c line 117
Quoted 10 lines
drivers/input/misc/max16150.c new file +10
-0+return dev_err_probe (dev,PTR_ERR (max16150->gpiod), +"Failed to get interrupt GPIO\n" ); + +if (chip_info->has_clr_gpio) { + max16150->clr_gpiod =devm_gpiod_get (dev,"clr" ,GPIOD_OUT_HIGH ); +if (IS_ERR (max16150->clr_gpiod)) +return dev_err_probe (dev,PTR_ERR (max16150->clr_gpiod), +"Failed to get clr GPIO\n" ); + +if (!max16150->clr_gpiod)
How would we end up here? You are using devm_gpiod_get() which will never return NULL GPIO descriptor.
drivers/input/misc/max16150.c line 130
Quoted 13 lines
drivers/input/misc/max16150.c new file +13
-0+return dev_err_probe (dev, -ENODEV , +"clr GPIO is mandatory\n" ); + +if (max16150->clr_gpiod) { +fsleep (1000 ); +gpiod_set_value (max16150->clr_gpiod,0 ); + } + } + + irq =gpiod_to_irq (max16150->gpiod); +if (irq <0 ) +return dev_err_probe (dev, irq, +"MAX16150: Failed to map GPIO to IRQ" );
As Rob said in DT binding review use interrupts property and separate IRQ and GPIO handling.
drivers/input/misc/max16150.c line 138
Quoted 8 lines
drivers/input/misc/max16150.c new file +8
-0+ + err =devm_request_irq (dev, irq, max16150_irq_handler, +IRQF_TRIGGER_RISING |IRQF_TRIGGER_FALLING , +"max16150_irq" , max16150); +if (err) +return err; + +return input_register_device (max16150->input);
err = input_register_device(...); if (err) return err; return 0;
Quoted 13 lines
drivers/input/misc/max16150.c new file +13
-0+} + +static const struct of_device_id max16150_of_match[] = { + { .compatible ="adi,max16150a" , .data = &max16150_variant_a }, + { .compatible ="adi,max16150b" , .data = &max16150_variant_b }, + { .compatible ="adi,max16169a" , .data = &max16150_variant_a }, + { .compatible ="adi,max16169b" , .data = &max16150_variant_b }, + { } +}; +MODULE_DEVICE_TABLE (of, max16150_of_match); + +static struct platform_driver max16150_driver = { + .probe = max16150_probe,
drivers/input/misc/max16150.c line 161
Quoted 10 lines
drivers/input/misc/max16150.c new file +10
-0+ .driver = { + .name = "max16150", + .of_match_table = max16150_of_match, + }, +}; +module_platform_driver (max16150_driver); + +MODULE_AUTHOR ("Marc Paolo Sosa <[email protected]>" ); +MODULE_DESCRIPTION ("MAX16150/MAX16169 Pushbutton Driver" ); +MODULE_LICENSE ("GPL" );
Thanks.
Signature · 1 line
Dmitry
RE: [PATCH 2/2] input: misc: add driver for max16150
Quoted 255 lines
-----Original Message-----
From: Dmitry Torokhov <[email protected]>
Sent: Wednesday, February 25, 2026 6:42 AM
To: Sosa, Marc Paolo <[email protected]>
Cc: Rob Herring <[email protected]>; Krzysztof Kozlowski <[email protected]>; Conor Dooley <[email protected]>; linux- [email protected]; [email protected]; linux- [email protected]
Subject: Re: [PATCH 2/2] input: misc: add driver for max16150[External]
Hi Marc,
Quoted 69 lines · On Mon, Feb 23, 2026 at 07:03:40PM +0800, Marc Paolo Sosa via B4 Relay wrote:
From: Marc Paolo Sosa <[email protected]>
MAX16150/MAX16169 nanoPower Pushbutton On/Off Controller
Signed-off-by Marc Paolo Sosa <[email protected]>--- drivers/input/misc/Kconfig | 9 +++ drivers/input/misc/Makefile | 1 + drivers/input/misc/max16150.c | 161 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 171 insertions(+)drivers/input/misc/Kconfig +9
-0@@ -178,6 +178,15 @@ config INPUT_E3X0_BUTTON To compile this driver as a module, choose M here: the module will be called e3x0_button. +config INPUT_MAX16150_PWRBUTTON + tristate "MAX16150/MAX16169 Pushbutton driver" + help + Say Y here if you want to enable power key reporting via + MAX16150/MAX16169 nanoPower Pushbutton On/Off Controller. + + To compile this driver as a module, choose M here. The module will + be called max16150. + config INPUT_PCSPKR tristate "PC Speaker support" depends on PCSPKR_PLATFORMdrivers/input/misc/Makefile +1
-0@@ -52,6 +52,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_MAX16150_PWRBUTTON) += max16150.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(quoted diff) +0
-0
b/drivers/input/misc/max16150.cnew file mode 100644 index 000000000000..ae353b926afcdrivers/input/misc/max16150.c new file +19
-0@@ -0,0 +1,161 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Analog Devices MAX16150/MAX16169 Pushbutton Driver +* +* Copyright 2025 Analog Devices Inc. +*/ + +#include <linux/delay.h> +#include <linux/init.h> +#include <linux/input.h> +#include <linux/interrupt.h> +#include <linux/gpio/consumer.h> +#include <linux/kernel.h> +#include <linux/mod_devicetable.h> +#include <linux/platform_device.h> +#include <linux/property.h> + +#define MAX16150_LONG_INTERRUPT 120000000 +drivers/input/misc/max16150.c line 29
Quoted 10 lines
drivers/input/misc/max16150.c new file +10
-0+struct max16150_chip_info { +bool has_clr_gpio; +}; + +struct max16150_device { +struct input_dev *input; +struct gpio_desc *gpiod; +struct gpio_desc *clr_gpiod; +const struct max16150_chip_info *chip_info; +u64 low, high, duration;I do not think you need to store "high" and "duration", just "press" time. I also do not think you need nanosecond resilution, jiffies will do.
Quoted 9 lines
drivers/input/misc/max16150.c new file +9
-0+unsigned int keycode; +}; + +static irqreturn_t max16150_irq_handler (int irq,void *_max16150) { +struct max16150_device *max16150 = _max16150; +int value; + + value =gpiod_get_value (max16150->gpiod); +drivers/input/misc/max16150.c line 49
Quoted 10 lines
drivers/input/misc/max16150.c new file +10
-0+if (!value) { + max16150->low =ktime_get_ns (); +return IRQ_HANDLED ; + } + + max16150->high =ktime_get_ns (); +if (max16150->low) { + max16150->duration = max16150->high - max16150->low; + +if (max16150->duration >MAX16150_LONG_INTERRUPT ) {
time_after()is probably what you need here.drivers/input/misc/max16150.c
Quoted 4 lines
drivers/input/misc/max16150.c new file +2
-0+gpiod_set_value (max16150->clr_gpiod,1 ); + input_report_key(max16150->input, max16150-keycode, 1);
drivers/input/misc/max16150.c new file +1
-0+input_sync (max16150->input);Why is press not reported right away?
Quoted 14 lines
drivers/input/misc/max16150.c new file +1
-0+ input_report_key(max16150->input, max16150-keycode, 0);
drivers/input/misc/max16150.c new file +12
-0+input_sync (max16150->input); + } + + max16150->low =0 ; + } + +return IRQ_HANDLED ; +} + +static const struct max16150_chip_info max16150_variant_a = { + .has_clr_gpio = true, +};drivers/input/misc/max16150.c line 76
Quoted 10 lines
drivers/input/misc/max16150.c new file +10
-0+ +static const struct max16150_chip_info max16150_variant_b = { + .has_clr_gpio = false, +}; + +static int max16150_probe (struct platform_device *pdev) { +const struct max16150_chip_info *chip_info; +struct max16150_device *max16150; +struct device *dev = &pdev->dev; +int err, irq, ret;Why do you need both err and ret?
Quoted 12 lines
drivers/input/misc/max16150.c new file +12
-0+u32 keycode; + + chip_info =device_get_match_data (dev); +if (!chip_info) +return -EINVAL ; + + max16150 =devm_kzalloc (dev,sizeof (*max16150),GFP_KERNEL ); +if (!max16150) +return -ENOMEM ; + + max16150->chip_info = chip_info; +drivers/input/misc/max16150.c line 98
Quoted 10 lines
drivers/input/misc/max16150.c new file +10
-0+ max16150->input =devm_input_allocate_device (dev); +if (!max16150->input) +return -ENOMEM ; + + max16150->input->name ="MAX16150 Pushbutton" ; + max16150->input->phys ="max16150/input0" ; + max16150->input->id.bustype =BUS_HOST ; + + keycode =KEY_POWER ; + ret =device_property_read_u32 (dev,"linux,code" , &keycode);err = ...Quoted 4 lines
drivers/input/misc/max16150.c new file +4
-0+if (ret) +return dev_err_probe (dev, ret,"Failed to get keycode\n" ); + + max16150->keycode = keycode;drivers/input/misc/max16150.c
Quoted 10 lines
drivers/input/misc/max16150.c new file +10
-0+ +input_set_capability (max16150->input,EV_KEY , max16150->keycode); + + max16150->gpiod =devm_gpiod_get (dev,"interrupt" ,GPIOD_IN ); +if (IS_ERR (max16150->gpiod)) +return dev_err_probe (dev,PTR_ERR (max16150->gpiod), +"Failed to get interrupt GPIO\n" ); + +if (chip_info->has_clr_gpio) { + max16150->clr_gpiod = devm_gpiod_get(dev, "clr",
GPIOD_OUT_HIGH);drivers/input/misc/max16150.c line 117
Quoted 6 lines
drivers/input/misc/max16150.c new file +2
-0+if (IS_ERR (max16150->clr_gpiod)) + return dev_err_probe(dev, PTR_ERR(max16150-
clr_gpiod),drivers/input/misc/max16150.c new file +3
-0+ "Failed to get clr GPIO\n"); + +if (!max16150->clr_gpiod)How would we end up here? You are using
devm_gpiod_get()which will never return NULL GPIO descriptor.drivers/input/misc/max16150.c line 130
Quoted 13 lines
drivers/input/misc/max16150.c new file +13
-0+return dev_err_probe (dev, -ENODEV , +"clr GPIO is mandatory\n" ); + +if (max16150->clr_gpiod) { +fsleep (1000 ); +gpiod_set_value (max16150->clr_gpiod,0 ); + } + } + + irq =gpiod_to_irq (max16150->gpiod); +if (irq <0 ) +return dev_err_probe (dev, irq, +"MAX16150: Failed to map GPIO to IRQ" );As Rob said in DT binding review use interrupts property and separate IRQ and GPIO handling.
drivers/input/misc/max16150.c line 138
Quoted 8 lines
drivers/input/misc/max16150.c new file +8
-0+ + err =devm_request_irq (dev, irq, max16150_irq_handler, +IRQF_TRIGGER_RISING |IRQF_TRIGGER_FALLING , +"max16150_irq" , max16150); +if (err) +return err; + +return input_register_device (max16150->input);err = input_register_device(...); if (err) return err; return 0;Quoted 15 lines
drivers/input/misc/max16150.c new file +15
-0+} + +static const struct of_device_id max16150_of_match[] = { + { .compatible ="adi,max16150a" , .data = &max16150_variant_a }, + { .compatible ="adi,max16150b" , .data = &max16150_variant_b }, + { .compatible ="adi,max16169a" , .data = &max16150_variant_a }, + { .compatible ="adi,max16169b" , .data = &max16150_variant_b }, + { } +}; +MODULE_DEVICE_TABLE (of, max16150_of_match); + +static struct platform_driver max16150_driver = { + .probe = max16150_probe, + .driver = { + .name ="max16150" ,
Quoted 9 lines
drivers/input/misc/max16150.c line 161
Quoted 8 lines
drivers/input/misc/max16150.c new file +8
-0+ .of_match_table = max16150_of_match, + }, +}; +module_platform_driver (max16150_driver); + +MODULE_AUTHOR ("Marc Paolo Sosa <[email protected]>" ); +MODULE_DESCRIPTION ("MAX16150/MAX16169 Pushbutton Driver" ); +MODULE_LICENSE ("GPL" );
Thank you for the initial review, I'll test the ff suggestions above and apply it to V2, for summary,
1. Switch from nanoseconds to jiffies with single press_time variable and time_after() for comparison
2. Remove redundant err/ret variables and use consistent naming
3. Remove impossible NULL checks after devm_gpiod_get() since it never returns NULL
4. Fix device_property_read_u32() error handling since linux,code is optional with default
5. Use explicit error checking pattern instead of implicit return
6. The MAX16150's OUT pin serves dual purposes (interrupt + GPIO state reading) - should I use separate 'interrupts' and 'out-gpios' properties for the same physical pin, or is there a preferred approach for this hardware design?
7. The duration measurement is needed since the device ignores short presses, but I could report press immediately and validate on release instead
I'll send v2 with these improvements once I clarify the preferred IRQ/GPIO handling approach.
Best regards,
Pao