All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Heiko Stuebner <heiko@sntech.de>,
	kernel@collabora.com, linux-input@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org
Subject: Re: [PATCH v2 2/4] Input: adc-keys - support EV_SW as well, not just EV_KEY.
Date: Tue, 16 Dec 2025 09:45:59 +0100	[thread overview]
Message-ID: <202512160845594c145070@mail.local> (raw)
In-Reply-To: <20251215-rock4d-audio-v2-2-82a61de39b4c@collabora.com>

On 15/12/2025 13:29:30+0100, Nicolas Frattaroli wrote:
> Instead of doing something like what gpio-keys is doing, adc-keys
> hardcodes that all keycodes must be of type EV_KEY.
> 
> This limits the usefulness of adc-keys, and overcomplicates the code
> with manual bit-setting logic.
> 
> Instead, refactor the code to read the linux,input-type fwnode property,
> and get rid of the custom bit setting logic, replacing it with
> input_set_capability instead. input_report_key is replaced with
> input_event, which allows us to explicitly pass the type.
> 
> Only EV_KEY and EV_SW is allowed at this stage.
> 
> Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>

Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

> ---
>  drivers/input/keyboard/adc-keys.c | 37 +++++++++++++++++++++++++------------
>  1 file changed, 25 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/input/keyboard/adc-keys.c b/drivers/input/keyboard/adc-keys.c
> index f1753207429d..62376f34f7d0 100644
> --- a/drivers/input/keyboard/adc-keys.c
> +++ b/drivers/input/keyboard/adc-keys.c
> @@ -18,13 +18,15 @@
>  
>  struct adc_keys_button {
>  	u32 voltage;
> -	u32 keycode;
> +	u32 code;
> +	u32 type;
>  };
>  
>  struct adc_keys_state {
>  	struct iio_channel *channel;
>  	u32 num_keys;
>  	u32 last_key;
> +	u32 last_type;
>  	u32 keyup_voltage;
>  	const struct adc_keys_button *map;
>  };
> @@ -34,7 +36,8 @@ static void adc_keys_poll(struct input_dev *input)
>  	struct adc_keys_state *st = input_get_drvdata(input);
>  	int i, value, ret;
>  	u32 diff, closest = 0xffffffff;
> -	int keycode = 0;
> +	u32 code = 0;
> +	u32 type = EV_KEY;
>  
>  	ret = iio_read_channel_processed(st->channel, &value);
>  	if (unlikely(ret < 0)) {
> @@ -45,22 +48,24 @@ static void adc_keys_poll(struct input_dev *input)
>  			diff = abs(st->map[i].voltage - value);
>  			if (diff < closest) {
>  				closest = diff;
> -				keycode = st->map[i].keycode;
> +				code = st->map[i].code;
> +				type = st->map[i].type;
>  			}
>  		}
>  	}
>  
>  	if (abs(st->keyup_voltage - value) < closest)
> -		keycode = 0;
> +		code = 0;
>  
> -	if (st->last_key && st->last_key != keycode)
> -		input_report_key(input, st->last_key, 0);
> +	if (st->last_key && st->last_key != code)
> +		input_event(input, st->last_type, st->last_key, 0);
>  
> -	if (keycode)
> -		input_report_key(input, keycode, 1);
> +	if (code)
> +		input_event(input, type, code, 1);
>  
>  	input_sync(input);
> -	st->last_key = keycode;
> +	st->last_key = code;
> +	st->last_type = type;
>  }
>  
>  static int adc_keys_load_keymap(struct device *dev, struct adc_keys_state *st)
> @@ -88,11 +93,20 @@ static int adc_keys_load_keymap(struct device *dev, struct adc_keys_state *st)
>  		map[i].voltage /= 1000;
>  
>  		if (fwnode_property_read_u32(child, "linux,code",
> -					     &map[i].keycode)) {
> +					     &map[i].code)) {
>  			dev_err(dev, "Key with invalid or missing linux,code\n");
>  			return -EINVAL;
>  		}
>  
> +		if (fwnode_property_read_u32(child, "linux,input-type",
> +					     &map[i].type))
> +			map[i].type = EV_KEY;
> +
> +		if (map[i].type != EV_KEY && map[i].type != EV_SW)
> +			return dev_err_probe(dev, -EINVAL,
> +					     "Invalid linux,input-type: 0x%x\n",
> +					     map[i].type);
> +
>  		i++;
>  	}
>  
> @@ -156,9 +170,8 @@ static int adc_keys_probe(struct platform_device *pdev)
>  	input->id.product = 0x0001;
>  	input->id.version = 0x0100;
>  
> -	__set_bit(EV_KEY, input->evbit);
>  	for (i = 0; i < st->num_keys; i++)
> -		__set_bit(st->map[i].keycode, input->keybit);
> +		input_set_capability(input, st->map[i].type, st->map[i].code);
>  
>  	if (device_property_read_bool(dev, "autorepeat"))
>  		__set_bit(EV_REP, input->evbit);
> 
> -- 
> 2.52.0
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


WARNING: multiple messages have this Message-ID (diff)
From: Alexandre Belloni <alexandre.belloni@bootlin.com>
To: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Heiko Stuebner <heiko@sntech.de>,
	kernel@collabora.com, linux-input@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org
Subject: Re: [PATCH v2 2/4] Input: adc-keys - support EV_SW as well, not just EV_KEY.
Date: Tue, 16 Dec 2025 09:45:59 +0100	[thread overview]
Message-ID: <202512160845594c145070@mail.local> (raw)
In-Reply-To: <20251215-rock4d-audio-v2-2-82a61de39b4c@collabora.com>

On 15/12/2025 13:29:30+0100, Nicolas Frattaroli wrote:
> Instead of doing something like what gpio-keys is doing, adc-keys
> hardcodes that all keycodes must be of type EV_KEY.
> 
> This limits the usefulness of adc-keys, and overcomplicates the code
> with manual bit-setting logic.
> 
> Instead, refactor the code to read the linux,input-type fwnode property,
> and get rid of the custom bit setting logic, replacing it with
> input_set_capability instead. input_report_key is replaced with
> input_event, which allows us to explicitly pass the type.
> 
> Only EV_KEY and EV_SW is allowed at this stage.
> 
> Signed-off-by: Nicolas Frattaroli <nicolas.frattaroli@collabora.com>

Reviewed-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

> ---
>  drivers/input/keyboard/adc-keys.c | 37 +++++++++++++++++++++++++------------
>  1 file changed, 25 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/input/keyboard/adc-keys.c b/drivers/input/keyboard/adc-keys.c
> index f1753207429d..62376f34f7d0 100644
> --- a/drivers/input/keyboard/adc-keys.c
> +++ b/drivers/input/keyboard/adc-keys.c
> @@ -18,13 +18,15 @@
>  
>  struct adc_keys_button {
>  	u32 voltage;
> -	u32 keycode;
> +	u32 code;
> +	u32 type;
>  };
>  
>  struct adc_keys_state {
>  	struct iio_channel *channel;
>  	u32 num_keys;
>  	u32 last_key;
> +	u32 last_type;
>  	u32 keyup_voltage;
>  	const struct adc_keys_button *map;
>  };
> @@ -34,7 +36,8 @@ static void adc_keys_poll(struct input_dev *input)
>  	struct adc_keys_state *st = input_get_drvdata(input);
>  	int i, value, ret;
>  	u32 diff, closest = 0xffffffff;
> -	int keycode = 0;
> +	u32 code = 0;
> +	u32 type = EV_KEY;
>  
>  	ret = iio_read_channel_processed(st->channel, &value);
>  	if (unlikely(ret < 0)) {
> @@ -45,22 +48,24 @@ static void adc_keys_poll(struct input_dev *input)
>  			diff = abs(st->map[i].voltage - value);
>  			if (diff < closest) {
>  				closest = diff;
> -				keycode = st->map[i].keycode;
> +				code = st->map[i].code;
> +				type = st->map[i].type;
>  			}
>  		}
>  	}
>  
>  	if (abs(st->keyup_voltage - value) < closest)
> -		keycode = 0;
> +		code = 0;
>  
> -	if (st->last_key && st->last_key != keycode)
> -		input_report_key(input, st->last_key, 0);
> +	if (st->last_key && st->last_key != code)
> +		input_event(input, st->last_type, st->last_key, 0);
>  
> -	if (keycode)
> -		input_report_key(input, keycode, 1);
> +	if (code)
> +		input_event(input, type, code, 1);
>  
>  	input_sync(input);
> -	st->last_key = keycode;
> +	st->last_key = code;
> +	st->last_type = type;
>  }
>  
>  static int adc_keys_load_keymap(struct device *dev, struct adc_keys_state *st)
> @@ -88,11 +93,20 @@ static int adc_keys_load_keymap(struct device *dev, struct adc_keys_state *st)
>  		map[i].voltage /= 1000;
>  
>  		if (fwnode_property_read_u32(child, "linux,code",
> -					     &map[i].keycode)) {
> +					     &map[i].code)) {
>  			dev_err(dev, "Key with invalid or missing linux,code\n");
>  			return -EINVAL;
>  		}
>  
> +		if (fwnode_property_read_u32(child, "linux,input-type",
> +					     &map[i].type))
> +			map[i].type = EV_KEY;
> +
> +		if (map[i].type != EV_KEY && map[i].type != EV_SW)
> +			return dev_err_probe(dev, -EINVAL,
> +					     "Invalid linux,input-type: 0x%x\n",
> +					     map[i].type);
> +
>  		i++;
>  	}
>  
> @@ -156,9 +170,8 @@ static int adc_keys_probe(struct platform_device *pdev)
>  	input->id.product = 0x0001;
>  	input->id.version = 0x0100;
>  
> -	__set_bit(EV_KEY, input->evbit);
>  	for (i = 0; i < st->num_keys; i++)
> -		__set_bit(st->map[i].keycode, input->keybit);
> +		input_set_capability(input, st->map[i].type, st->map[i].code);
>  
>  	if (device_property_read_bool(dev, "autorepeat"))
>  		__set_bit(EV_REP, input->evbit);
> 
> -- 
> 2.52.0
> 

-- 
Alexandre Belloni, co-owner and COO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

  reply	other threads:[~2025-12-16  8:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-15 12:29 [PATCH v2 0/4] ROCK 4D audio enablement Nicolas Frattaroli
2025-12-15 12:29 ` Nicolas Frattaroli
2025-12-15 12:29 ` [PATCH v2 1/4] dt-bindings: input: adc-keys: allow linux,input-type property Nicolas Frattaroli
2025-12-15 12:29   ` Nicolas Frattaroli
2025-12-16  8:47   ` Alexandre Belloni
2025-12-16  8:47     ` Alexandre Belloni
2025-12-17  8:31   ` Krzysztof Kozlowski
2025-12-17  8:31     ` Krzysztof Kozlowski
2025-12-17 12:57     ` Nicolas Frattaroli
2025-12-17 12:57       ` Nicolas Frattaroli
2025-12-17 13:34       ` Rob Herring
2025-12-17 13:34         ` Rob Herring
2026-04-08 16:59         ` Dmitry Torokhov
2026-04-08 16:59           ` Dmitry Torokhov
2026-04-08 17:11           ` Nicolas Frattaroli
2026-04-08 17:11             ` Nicolas Frattaroli
2025-12-15 12:29 ` [PATCH v2 2/4] Input: adc-keys - support EV_SW as well, not just EV_KEY Nicolas Frattaroli
2025-12-15 12:29   ` Nicolas Frattaroli
2025-12-16  8:45   ` Alexandre Belloni [this message]
2025-12-16  8:45     ` Alexandre Belloni
2025-12-15 12:29 ` [PATCH v2 3/4] Input: adc-keys - Use dev_err_probe in probe function Nicolas Frattaroli
2025-12-15 12:29   ` Nicolas Frattaroli
2025-12-16  8:45   ` Alexandre Belloni
2025-12-16  8:45     ` Alexandre Belloni
2025-12-15 12:29 ` [PATCH v2 4/4] arm64: dts: rockchip: add analog audio to ROCK 4D Nicolas Frattaroli
2025-12-15 12:29   ` Nicolas Frattaroli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=202512160845594c145070@mail.local \
    --to=alexandre.belloni@bootlin.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=heiko@sntech.de \
    --cc=kernel@collabora.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=nicolas.frattaroli@collabora.com \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.