All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Vincent Knecht <vincent.knecht@mailoo.org>
Cc: Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	linux-input@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, w.david0@protonmail.com,
	stephan@gerhold.net, phone-devel@vger.kernel.org,
	~postmarketos/upstreaming@lists.sr.ht
Subject: Re: [PATCH v4 5/5] Input: msg2638 - Add support for msg2138 key events
Date: Mon, 14 Nov 2022 17:17:16 -0800	[thread overview]
Message-ID: <Y3LonDibllKkTmPs@google.com> (raw)
In-Reply-To: <20221110171952.34207-6-vincent.knecht@mailoo.org>

On Thu, Nov 10, 2022 at 06:19:48PM +0100, Vincent Knecht wrote:
> Some devices with msg2138 have back/menu/home keys.
> Add support for them.
> 
> Signed-off-by: Vincent Knecht <vincent.knecht@mailoo.org>
> ---
>  drivers/input/touchscreen/msg2638.c | 53 +++++++++++++++++++++++++----
>  1 file changed, 47 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/msg2638.c b/drivers/input/touchscreen/msg2638.c
> index 73e1b4d550fb..36069b30ab9b 100644
> --- a/drivers/input/touchscreen/msg2638.c
> +++ b/drivers/input/touchscreen/msg2638.c
> @@ -29,6 +29,8 @@
>  #define MSG2138_MAX_FINGERS		2
>  #define MSG2638_MAX_FINGERS		5
>  
> +#define MAX_BUTTONS			4
> +
>  #define CHIP_ON_DELAY_MS		15
>  #define FIRMWARE_ON_DELAY_MS		50
>  #define RESET_DELAY_MIN_US		10000
> @@ -72,6 +74,8 @@ struct msg2638_ts_data {
>  	struct regulator_bulk_data supplies[2];
>  	struct gpio_desc *reset_gpiod;
>  	int max_fingers;
> +	u32 keycodes[MAX_BUTTONS];
> +	int num_keycodes;
>  };
>  
>  static u8 msg2638_checksum(u8 *data, u32 length)
> @@ -85,6 +89,19 @@ static u8 msg2638_checksum(u8 *data, u32 length)
>  	return (u8)((-sum) & 0xFF);
>  }
>  
> +static void msg2138_report_keys(struct msg2638_ts_data *msg2638, u8 keys)
> +{
> +	int i;
> +
> +	/* keys can be 0x00 or 0xff when all keys have been released */
> +	if (keys == 0xff)
> +		keys = 0;
> +
> +	for (i = 0; i < msg2638->num_keycodes; ++i)
> +		input_report_key(msg2638->input_dev, msg2638->keycodes[i],
> +				 !!(keys & BIT(i)));

No need to do double-negation here, input_report_key() does it already.

> +}
> +
>  static irqreturn_t msg2138_ts_irq_handler(int irq, void *msg2638_handler)
>  {
>  	struct msg2638_ts_data *msg2638 = msg2638_handler;
> @@ -121,9 +138,12 @@ static irqreturn_t msg2138_ts_irq_handler(int irq, void *msg2638_handler)
>  	p0 = &touch_event.pkt[0];
>  	p1 = &touch_event.pkt[1];
>  
> -	/* Ignore non-pressed finger data */
> -	if (p0->xy_hi == 0xFF && p0->x_low == 0xFF && p0->y_low == 0xFF)
> +	/* Ignore non-pressed finger data, but check for key code */
> +	if (p0->xy_hi == 0xFF && p0->x_low == 0xFF && p0->y_low == 0xFF) {
> +		if (p1->xy_hi == 0xFF && p1->y_low == 0xFF)
> +			msg2138_report_keys(msg2638, p1->x_low);
>  		goto report;
> +	}
>  
>  	x = (((p0->xy_hi & 0xF0) << 4) | p0->x_low);
>  	y = (((p0->xy_hi & 0x0F) << 8) | p0->y_low);
> @@ -283,6 +303,7 @@ static int msg2638_init_input_dev(struct msg2638_ts_data *msg2638)
>  	struct device *dev = &msg2638->client->dev;
>  	struct input_dev *input_dev;
>  	int error;
> +	int i;
>  
>  	input_dev = devm_input_allocate_device(dev);
>  	if (!input_dev) {
> @@ -299,6 +320,14 @@ static int msg2638_init_input_dev(struct msg2638_ts_data *msg2638)
>  	input_dev->open = msg2638_input_open;
>  	input_dev->close = msg2638_input_close;
>  
> +	if (msg2638->num_keycodes) {
> +		input_dev->keycode = msg2638->keycodes;
> +		input_dev->keycodemax = msg2638->num_keycodes;
> +		input_dev->keycodesize = sizeof(msg2638->keycodes[0]);
> +		for (i = 0; i < msg2638->num_keycodes; i++)
> +			input_set_capability(input_dev, EV_KEY, msg2638->keycodes[i]);
> +	}
> +
>  	input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X);
>  	input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y);
>  
> @@ -367,10 +396,16 @@ static int msg2638_ts_probe(struct i2c_client *client)
>  		return error;
>  	}
>  
> -	error = msg2638_init_input_dev(msg2638);
> -	if (error) {
> -		dev_err(dev, "Failed to initialize input device: %d\n", error);
> -		return error;
> +	msg2638->num_keycodes =
> +		of_property_read_variable_u32_array(dev->of_node, "linux,keycodes",
> +						    msg2638->keycodes, 0,
> +						    ARRAY_SIZE(msg2638->keycodes));

Please do not use OF-specific API, use generic device property API (yes,
you will need 2 calls, one to get the count, and another to actually
fill the array).

Thanks.

-- 
Dmitry

      reply	other threads:[~2022-11-15  1:17 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10 17:19 [PATCH v4 0/5] Input: msg2638: Add support for msg2138 and key Vincent Knecht
2022-11-10 17:19 ` [PATCH v4 1/5] Input: msg2638 - Set max finger number and irqhandler from driver data Vincent Knecht
2022-11-15  1:14   ` Dmitry Torokhov
2022-11-10 17:19 ` [PATCH v4 2/5] dt-bindings: input: touchscreen: msg2638: Document msg2138 support Vincent Knecht
2022-11-15  1:15   ` Dmitry Torokhov
2022-11-10 17:19 ` [PATCH v4 3/5] Input: msg2638 - Add support for msg2138 Vincent Knecht
2022-11-15  1:15   ` Dmitry Torokhov
2022-11-10 17:19 ` [PATCH v4 4/5] dt-bindings: input: touchscreen: msg2638: Document keys support Vincent Knecht
2022-11-10 17:19 ` [PATCH v4 5/5] Input: msg2638 - Add support for msg2138 key events Vincent Knecht
2022-11-15  1:17   ` Dmitry Torokhov [this message]

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=Y3LonDibllKkTmPs@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=phone-devel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=stephan@gerhold.net \
    --cc=vincent.knecht@mailoo.org \
    --cc=w.david0@protonmail.com \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /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.