linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] mms114: add support for touch keys
@ 2023-05-21 14:58 Artur Weber
  2023-05-21 14:58 ` [PATCH 1/2] dt-bindings: mms114: Add linux,keycodes property " Artur Weber
  2023-05-21 14:58 ` [PATCH 2/2] Input: mms114 - add support " Artur Weber
  0 siblings, 2 replies; 4+ messages in thread
From: Artur Weber @ 2023-05-21 14:58 UTC (permalink / raw)
  To: Dmitry Torokhov, Rob Herring
  Cc: Krzysztof Kozlowski, Linus Walleij, linux-input, devicetree,
	linux-kernel, ~postmarketos/upstreaming, Artur Weber

MELFAS MMS114 and similar touchscreens have support for touch keys.
Enable support of them in the driver. The keycodes to emit can be
controlled by the linux,keycodes DT property.

Signed-off-by: Artur Weber <aweber.kernel@gmail.com>

Artur Weber (2):
  dt-bindings: mms114: Add linux,keycodes property for touch keys
  Input: mms114 - add support for touch keys

 .../input/touchscreen/melfas,mms114.yaml      |  5 ++
 drivers/input/touchscreen/mms114.c            | 88 +++++++++++++++++--
 2 files changed, 86 insertions(+), 7 deletions(-)


base-commit: f219050af06d83f436945880fc9c04db3bb2860f
-- 
2.40.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] dt-bindings: mms114: Add linux,keycodes property for touch keys
  2023-05-21 14:58 [PATCH 0/2] mms114: add support for touch keys Artur Weber
@ 2023-05-21 14:58 ` Artur Weber
  2023-05-22 12:14   ` Conor Dooley
  2023-05-21 14:58 ` [PATCH 2/2] Input: mms114 - add support " Artur Weber
  1 sibling, 1 reply; 4+ messages in thread
From: Artur Weber @ 2023-05-21 14:58 UTC (permalink / raw)
  To: Dmitry Torokhov, Rob Herring
  Cc: Krzysztof Kozlowski, Linus Walleij, linux-input, devicetree,
	linux-kernel, ~postmarketos/upstreaming, Artur Weber

MELFAS MMS114 and similar touchscreens have support for touch keys.
Add the linux,keycodes property which can be used to set up the
keycodes for the touch keys.

Signed-off-by: Artur Weber <aweber.kernel@gmail.com>
---
 .../devicetree/bindings/input/touchscreen/melfas,mms114.yaml | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/melfas,mms114.yaml b/Documentation/devicetree/bindings/input/touchscreen/melfas,mms114.yaml
index fdd02898e249..07f9dd6b1c9c 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/melfas,mms114.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/melfas,mms114.yaml
@@ -52,6 +52,11 @@ properties:
   touchscreen-swapped-x-y: true
   touchscreen-max-pressure: true
 
+  linux,keycodes:
+    description: Keycodes for the touch keys
+    minItems: 1
+    maxItems: 15
+
 additionalProperties: false
 
 required:
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] Input: mms114 - add support for touch keys
  2023-05-21 14:58 [PATCH 0/2] mms114: add support for touch keys Artur Weber
  2023-05-21 14:58 ` [PATCH 1/2] dt-bindings: mms114: Add linux,keycodes property " Artur Weber
@ 2023-05-21 14:58 ` Artur Weber
  1 sibling, 0 replies; 4+ messages in thread
From: Artur Weber @ 2023-05-21 14:58 UTC (permalink / raw)
  To: Dmitry Torokhov, Rob Herring
  Cc: Krzysztof Kozlowski, Linus Walleij, linux-input, devicetree,
	linux-kernel, ~postmarketos/upstreaming, Artur Weber

MELFAS MMS114 and similar touchscreens have support for touch keys.
Enable support of them in the driver. The keycodes to emit can be
controlled by the linux,keycodes DT property.

Sidenote - the MAX_TOUCHKEYS value is set to 15, as that's the
maximum value that the ID field can contain. I don't have access
to any datasheets that could confirm or deny whether this is accurate.

Most downstream drivers I've been able to find only use up to 2 keys
(though I did find a driver that mentioned up to 4, but only 2 were
used). They don't have any checks for a maximum keycode value, it is
just extracted from the ID bits (0xf mask).

The drivers I've been able to find also don't use touch ID 0; I assume
that it is never used, so the keycodes provided in the DT start from
touch ID 1. I suppose this is in-line with the regular behavior
for touch IDs in touchscreen events, as there the provided touch ID
is always lowered by 1, which would cause an overflow if it was 0...
Just in case, we quietly return if the touch ID is set to 0 here.

The implementation of the linux,keycodes property handling code was
adapted from the msg2638 driver.

Signed-off-by: Artur Weber <aweber.kernel@gmail.com>
---
 drivers/input/touchscreen/mms114.c | 88 +++++++++++++++++++++++++++---
 1 file changed, 81 insertions(+), 7 deletions(-)

diff --git a/drivers/input/touchscreen/mms114.c b/drivers/input/touchscreen/mms114.c
index ac12494c7930..14c0514a21ff 100644
--- a/drivers/input/touchscreen/mms114.c
+++ b/drivers/input/touchscreen/mms114.c
@@ -43,6 +43,7 @@
 /* Touchscreen absolute values */
 #define MMS114_MAX_AREA			0xff
 
+#define MMS114_MAX_TOUCHKEYS		15
 #define MMS114_MAX_TOUCH		10
 #define MMS114_EVENT_SIZE		8
 #define MMS136_EVENT_SIZE		6
@@ -70,6 +71,9 @@ struct mms114_data {
 	unsigned int		contact_threshold;
 	unsigned int		moving_threshold;
 
+	u32 keycodes[MMS114_MAX_TOUCHKEYS];
+	int num_keycodes;
+
 	/* Use cache data for mode control register(write only) */
 	u8			cache_mode_control;
 };
@@ -167,11 +171,6 @@ static void mms114_process_mt(struct mms114_data *data, struct mms114_touch *tou
 		return;
 	}
 
-	if (touch->type != MMS114_TYPE_TOUCHSCREEN) {
-		dev_err(&client->dev, "Wrong touch type (%d)\n", touch->type);
-		return;
-	}
-
 	id = touch->id - 1;
 	x = touch->x_lo | touch->x_hi << 8;
 	y = touch->y_lo | touch->y_hi << 8;
@@ -191,9 +190,33 @@ static void mms114_process_mt(struct mms114_data *data, struct mms114_touch *tou
 	}
 }
 
+static void mms114_process_touchkey(struct mms114_data *data,
+				    struct mms114_touch *touch)
+{
+	struct i2c_client *client = data->client;
+	struct input_dev *input_dev = data->input_dev;
+	unsigned int keycode_id;
+
+	if (touch->id == 0)
+		return;
+
+	if (touch->id > data->num_keycodes) {
+		dev_err(&client->dev, "Wrong touch id for touchkey (%d)\n",
+			touch->id);
+		return;
+	}
+
+	keycode_id = touch->id - 1;
+	dev_dbg(&client->dev, "keycode id: %d, pressed: %d\n", keycode_id,
+		touch->pressed);
+
+	input_report_key(input_dev, data->keycodes[keycode_id], touch->pressed);
+}
+
 static irqreturn_t mms114_interrupt(int irq, void *dev_id)
 {
 	struct mms114_data *data = dev_id;
+	struct i2c_client *client = data->client;
 	struct input_dev *input_dev = data->input_dev;
 	struct mms114_touch touch[MMS114_MAX_TOUCH];
 	int packet_size;
@@ -223,8 +246,22 @@ static irqreturn_t mms114_interrupt(int irq, void *dev_id)
 	if (error < 0)
 		goto out;
 
-	for (index = 0; index < touch_size; index++)
-		mms114_process_mt(data, touch + index);
+	for (index = 0; index < touch_size; index++) {
+		switch (touch[index].type) {
+		case MMS114_TYPE_TOUCHSCREEN:
+			mms114_process_mt(data, touch + index);
+			break;
+
+		case MMS114_TYPE_TOUCHKEY:
+			mms114_process_touchkey(data, touch + index);
+			break;
+
+		default:
+			dev_err(&client->dev, "Wrong touch type (%d)\n",
+				touch[index].type);
+			break;
+		}
+	}
 
 	input_mt_report_pointer_emulation(data->input_dev, true);
 	input_sync(data->input_dev);
@@ -446,6 +483,7 @@ static int mms114_probe(struct i2c_client *client)
 	struct input_dev *input_dev;
 	const void *match_data;
 	int error;
+	int i;
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
 		dev_err(&client->dev, "Not supported I2C adapter\n");
@@ -469,6 +507,42 @@ static int mms114_probe(struct i2c_client *client)
 
 	data->type = (enum mms_type)match_data;
 
+	data->num_keycodes = device_property_count_u32(&client->dev,
+						       "linux,keycodes");
+	if (data->num_keycodes == -EINVAL) {
+		data->num_keycodes = 0;
+	} else if (data->num_keycodes < 0) {
+		dev_err(&client->dev,
+			"Unable to parse linux,keycodes property: %d\n",
+			data->num_keycodes);
+		return data->num_keycodes;
+	} else if (data->num_keycodes > MMS114_MAX_TOUCHKEYS) {
+		dev_warn(&client->dev,
+			"Found %d linux,keycodes but max is %zd, ignoring the rest\n",
+			 data->num_keycodes, MMS114_MAX_TOUCHKEYS);
+		data->num_keycodes = MMS114_MAX_TOUCHKEYS;
+	}
+
+	if (data->num_keycodes > 0) {
+		error = device_property_read_u32_array(&client->dev,
+						       "linux,keycodes",
+						       data->keycodes,
+						       data->num_keycodes);
+		if (error) {
+			dev_err(&client->dev,
+				"Unable to read linux,keycodes values: %d\n",
+				error);
+			return error;
+		}
+
+		input_dev->keycode = data->keycodes;
+		input_dev->keycodemax = data->num_keycodes;
+		input_dev->keycodesize = sizeof(data->keycodes[0]);
+		for (i = 0; i < data->num_keycodes; i++)
+			input_set_capability(input_dev,
+					     EV_KEY, data->keycodes[i]);
+	}
+
 	input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_X);
 	input_set_capability(input_dev, EV_ABS, ABS_MT_POSITION_Y);
 	input_set_abs_params(input_dev, ABS_MT_PRESSURE, 0, 255, 0, 0);
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] dt-bindings: mms114: Add linux,keycodes property for touch keys
  2023-05-21 14:58 ` [PATCH 1/2] dt-bindings: mms114: Add linux,keycodes property " Artur Weber
@ 2023-05-22 12:14   ` Conor Dooley
  0 siblings, 0 replies; 4+ messages in thread
From: Conor Dooley @ 2023-05-22 12:14 UTC (permalink / raw)
  To: Artur Weber
  Cc: Dmitry Torokhov, Rob Herring, Krzysztof Kozlowski, Linus Walleij,
	linux-input, devicetree, linux-kernel, ~postmarketos/upstreaming

[-- Attachment #1: Type: text/plain, Size: 1154 bytes --]

On Sun, May 21, 2023 at 04:58:42PM +0200, Artur Weber wrote:
> MELFAS MMS114 and similar touchscreens have support for touch keys.
> Add the linux,keycodes property which can be used to set up the
> keycodes for the touch keys.
> 
> Signed-off-by: Artur Weber <aweber.kernel@gmail.com>

Acked-by: Conor Dooley <conor.dooley@microchip.com>

Thanks,
Conor.

> ---
>  .../devicetree/bindings/input/touchscreen/melfas,mms114.yaml | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/input/touchscreen/melfas,mms114.yaml b/Documentation/devicetree/bindings/input/touchscreen/melfas,mms114.yaml
> index fdd02898e249..07f9dd6b1c9c 100644
> --- a/Documentation/devicetree/bindings/input/touchscreen/melfas,mms114.yaml
> +++ b/Documentation/devicetree/bindings/input/touchscreen/melfas,mms114.yaml
> @@ -52,6 +52,11 @@ properties:
>    touchscreen-swapped-x-y: true
>    touchscreen-max-pressure: true
>  
> +  linux,keycodes:
> +    description: Keycodes for the touch keys
> +    minItems: 1
> +    maxItems: 15
> +
>  additionalProperties: false
>  
>  required:
> -- 
> 2.40.1
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-22 12:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-21 14:58 [PATCH 0/2] mms114: add support for touch keys Artur Weber
2023-05-21 14:58 ` [PATCH 1/2] dt-bindings: mms114: Add linux,keycodes property " Artur Weber
2023-05-22 12:14   ` Conor Dooley
2023-05-21 14:58 ` [PATCH 2/2] Input: mms114 - add support " Artur Weber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).