devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC 0/4] Support for MELFAS MIP4 touchkey devices
@ 2025-05-03  9:08 Kaustabh Chakraborty
  2025-05-03  9:08 ` [PATCH RFC 1/4] dt-bindings: input: melfas-mip4: document linux,keycodes property Kaustabh Chakraborty
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Kaustabh Chakraborty @ 2025-05-03  9:08 UTC (permalink / raw)
  To: Sangwon Jee, Dmitry Torokhov, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Henrik Rydberg
  Cc: linux-input, devicetree, linux-kernel, Kaustabh Chakraborty

MIP4 is a protocol developed and used by MELFAS in its touchscreen and
touchkey devices. The MIP4 touchscreen driver acknowledges the
touchscreen capabilities, but touchkeys are left unimplemented.

Apart from touchscreen + touchkey devices, the protocol is also used by
devices which are, functionally, touchkey devices. Thus, the driver
should also be compatible with those devices. This series aims to
introduce such required changes.

RFC: How should the compatible string be handled? The string defined in
dtschema is 'melfas,mip4_ts', which implies that it's a MIP4 touchscreen
by MELFAS.

Signed-off-by: Kaustabh Chakraborty <kauschluss@disroot.org>
---
Kaustabh Chakraborty (4):
      dt-bindings: input: melfas-mip4: document linux,keycodes property
      Input: melfas-mip4 - add support for touchkey input events
      Input: melfas-mip4 - initialize touch events only if the device is a touchscreen
      Input: melfas-mip4 - add support for event formats 4 and 9

 .../bindings/input/touchscreen/melfas_mip4.txt     |  2 +
 drivers/input/touchscreen/melfas_mip4.c            | 98 ++++++++++++++++------
 2 files changed, 74 insertions(+), 26 deletions(-)
---
base-commit: 3e039dcc9c1320c0d33ddd51c372dcc91d3ea3c7
change-id: 20250501-mip4-touchkey-66a113226bce

Best regards,
-- 
Kaustabh Chakraborty <kauschluss@disroot.org>


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

* [PATCH RFC 1/4] dt-bindings: input: melfas-mip4: document linux,keycodes property
  2025-05-03  9:08 [PATCH RFC 0/4] Support for MELFAS MIP4 touchkey devices Kaustabh Chakraborty
@ 2025-05-03  9:08 ` Kaustabh Chakraborty
  2025-05-09 22:06   ` Rob Herring
  2025-05-03  9:08 ` [PATCH RFC 2/4] Input: melfas-mip4 - add support for touchkey input events Kaustabh Chakraborty
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Kaustabh Chakraborty @ 2025-05-03  9:08 UTC (permalink / raw)
  To: Sangwon Jee, Dmitry Torokhov, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Henrik Rydberg
  Cc: linux-input, devicetree, linux-kernel, Kaustabh Chakraborty

Document the linux,keycodes property. The property values are key codes
which are used in input key events generated by the touchkey device.

Signed-off-by: Kaustabh Chakraborty <kauschluss@disroot.org>
---
 Documentation/devicetree/bindings/input/touchscreen/melfas_mip4.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/input/touchscreen/melfas_mip4.txt b/Documentation/devicetree/bindings/input/touchscreen/melfas_mip4.txt
index b2ab5498e51900e887fab4d9b5239cccccec2ea9..16d1031ee017604ac56109dfbebfce6a05491c60 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/melfas_mip4.txt
+++ b/Documentation/devicetree/bindings/input/touchscreen/melfas_mip4.txt
@@ -7,6 +7,7 @@ Required properties:
 
 Optional properties:
 - ce-gpios: GPIO connected to the CE (chip enable) pin of the chip
+- linux,keycodes: array of keycodes to be reported by touchkeys
 
 Example:
 	i2c@00000000 {
@@ -16,5 +17,6 @@ Example:
 			interrupt-parent = <&gpio>;
 			interrupts = <0 IRQ_TYPE_EDGE_FALLING>;
 			ce-gpios = <&gpio 0 GPIO_ACTIVE_HIGH>;
+			linux,keycodes = <KEY_MENU>, <KEY_BACK>;
 		};
 	};

-- 
2.49.0


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

* [PATCH RFC 2/4] Input: melfas-mip4 - add support for touchkey input events
  2025-05-03  9:08 [PATCH RFC 0/4] Support for MELFAS MIP4 touchkey devices Kaustabh Chakraborty
  2025-05-03  9:08 ` [PATCH RFC 1/4] dt-bindings: input: melfas-mip4: document linux,keycodes property Kaustabh Chakraborty
@ 2025-05-03  9:08 ` Kaustabh Chakraborty
  2025-05-03  9:08 ` [PATCH RFC 3/4] Input: melfas-mip4 - initialize touch events only if the device is a touchscreen Kaustabh Chakraborty
  2025-05-03  9:08 ` [PATCH RFC 4/4] Input: melfas-mip4 - add support for event formats 4 and 9 Kaustabh Chakraborty
  3 siblings, 0 replies; 7+ messages in thread
From: Kaustabh Chakraborty @ 2025-05-03  9:08 UTC (permalink / raw)
  To: Sangwon Jee, Dmitry Torokhov, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Henrik Rydberg
  Cc: linux-input, devicetree, linux-kernel, Kaustabh Chakraborty

The MIP4 protocol are supposed to support touchscreens, touchkeys, and
combo-devices. The driver handles touchscreen events, but touchkey
events are unimplemented.

Implement them. If compiled with devicetree support, the driver attempts
to retrieve keycodes from a property named "linux,keycodes".

Signed-off-by: Kaustabh Chakraborty <kauschluss@disroot.org>
---
 drivers/input/touchscreen/melfas_mip4.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)

diff --git a/drivers/input/touchscreen/melfas_mip4.c b/drivers/input/touchscreen/melfas_mip4.c
index a6946e3d8376d7e9b4c26f4194409e0ba78bb075..061ac353bc7a2e28f17581411af81f35c89733a1 100644
--- a/drivers/input/touchscreen/melfas_mip4.c
+++ b/drivers/input/touchscreen/melfas_mip4.c
@@ -169,7 +169,7 @@ struct mip4_ts {
 	unsigned int event_format;
 
 	unsigned int key_num;
-	unsigned short key_code[MIP4_MAX_KEYS];
+	unsigned int key_code[MIP4_MAX_KEYS];
 
 	bool wake_irq_enabled;
 
@@ -337,8 +337,13 @@ static int mip4_query_device(struct mip4_ts *ts)
 			ts->ppm_x, ts->ppm_y);
 
 		/* Key ts */
-		if (ts->node_key > 0)
+		if (ts->node_key > MIP4_MAX_KEYS) {
+			dev_warn(&ts->client->dev,
+				"Too many keys (%u) found\n", ts->node_key);
+			ts->key_num = MIP4_MAX_KEYS;
+		} else {
 			ts->key_num = ts->node_key;
+		}
 	}
 
 	/* Protocol */
@@ -1080,6 +1085,7 @@ static int mip4_flash_fw(struct mip4_ts *ts,
 			 const u8 *fw_data, u32 fw_size, u32 fw_offset)
 {
 	struct i2c_client *client = ts->client;
+	unsigned int i;
 	int offset;
 	u16 buf_addr;
 	int error, error2;
@@ -1149,6 +1155,11 @@ static int mip4_flash_fw(struct mip4_ts *ts,
 	input_abs_set_res(ts->input, ABS_X, ts->ppm_x);
 	input_abs_set_res(ts->input, ABS_Y, ts->ppm_y);
 
+	for (i = 0; i < ts->key_num; i++) {
+		if (ts->key_code[i])
+			input_set_capability(ts->input, EV_KEY, ts->key_code[i]);
+	}
+
 	return error ? error : 0;
 }
 
@@ -1425,6 +1436,7 @@ static int mip4_probe(struct i2c_client *client)
 {
 	struct mip4_ts *ts;
 	struct input_dev *input;
+	unsigned int i;
 	int error;
 
 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
@@ -1471,6 +1483,17 @@ static int mip4_probe(struct i2c_client *client)
 
 	input_set_drvdata(input, ts);
 
+#ifdef CONFIG_OF
+	error = of_property_read_u32_array(client->dev.of_node, "linux,keycodes",
+					   ts->key_code, ts->key_num);
+	if (error && ts->key_num) {
+		dev_warn(&client->dev,
+			 "Failed to get codes for %u supported keys", ts->key_num);
+		/* Disable touchkey support */
+		ts->key_num = 0;
+	}
+#endif
+
 	input->keycode = ts->key_code;
 	input->keycodesize = sizeof(*ts->key_code);
 	input->keycodemax = ts->key_num;
@@ -1491,6 +1514,11 @@ static int mip4_probe(struct i2c_client *client)
 	if (error)
 		return error;
 
+	for (i = 0; i < ts->key_num; i++) {
+		if (ts->key_code[i])
+			input_set_capability(input, EV_KEY, ts->key_code[i]);
+	}
+
 	i2c_set_clientdata(client, ts);
 
 	error = devm_request_threaded_irq(&client->dev, client->irq,

-- 
2.49.0


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

* [PATCH RFC 3/4] Input: melfas-mip4 - initialize touch events only if the device is a touchscreen
  2025-05-03  9:08 [PATCH RFC 0/4] Support for MELFAS MIP4 touchkey devices Kaustabh Chakraborty
  2025-05-03  9:08 ` [PATCH RFC 1/4] dt-bindings: input: melfas-mip4: document linux,keycodes property Kaustabh Chakraborty
  2025-05-03  9:08 ` [PATCH RFC 2/4] Input: melfas-mip4 - add support for touchkey input events Kaustabh Chakraborty
@ 2025-05-03  9:08 ` Kaustabh Chakraborty
  2025-05-03  9:08 ` [PATCH RFC 4/4] Input: melfas-mip4 - add support for event formats 4 and 9 Kaustabh Chakraborty
  3 siblings, 0 replies; 7+ messages in thread
From: Kaustabh Chakraborty @ 2025-05-03  9:08 UTC (permalink / raw)
  To: Sangwon Jee, Dmitry Torokhov, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Henrik Rydberg
  Cc: linux-input, devicetree, linux-kernel, Kaustabh Chakraborty

Certain MIP4 devices report zero values when enquired for its touchscreen
dimensions (MIP4_R1_INFO_RESOLUTION_X and MIP4_R1_INFO_RESOLUTION_Y),
which is indicative of the fact that those devices are not touchscreens.

While registering for touch events for the device, always check - and
proceed - only if the device reports a non-zero resolution.

Signed-off-by: Kaustabh Chakraborty <kauschluss@disroot.org>
---
 drivers/input/touchscreen/melfas_mip4.c | 50 ++++++++++++++++++---------------
 1 file changed, 27 insertions(+), 23 deletions(-)

diff --git a/drivers/input/touchscreen/melfas_mip4.c b/drivers/input/touchscreen/melfas_mip4.c
index 061ac353bc7a2e28f17581411af81f35c89733a1..57b657694a420220be135c2f78d3ddad3ef6f520 100644
--- a/drivers/input/touchscreen/melfas_mip4.c
+++ b/drivers/input/touchscreen/melfas_mip4.c
@@ -1146,14 +1146,16 @@ static int mip4_flash_fw(struct mip4_ts *ts,
 	mip4_query_device(ts);
 
 	/* Refresh device parameters */
-	input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, ts->max_x, 0, 0);
-	input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, ts->max_y, 0, 0);
-	input_set_abs_params(ts->input, ABS_X, 0, ts->max_x, 0, 0);
-	input_set_abs_params(ts->input, ABS_Y, 0, ts->max_y, 0, 0);
-	input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->ppm_x);
-	input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->ppm_y);
-	input_abs_set_res(ts->input, ABS_X, ts->ppm_x);
-	input_abs_set_res(ts->input, ABS_Y, ts->ppm_y);
+	if (ts->max_x && ts->max_y) {
+		input_set_abs_params(ts->input, ABS_MT_POSITION_X, 0, ts->max_x, 0, 0);
+		input_set_abs_params(ts->input, ABS_MT_POSITION_Y, 0, ts->max_y, 0, 0);
+		input_set_abs_params(ts->input, ABS_X, 0, ts->max_x, 0, 0);
+		input_set_abs_params(ts->input, ABS_Y, 0, ts->max_y, 0, 0);
+		input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->ppm_x);
+		input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->ppm_y);
+		input_abs_set_res(ts->input, ABS_X, ts->ppm_x);
+		input_abs_set_res(ts->input, ABS_Y, ts->ppm_y);
+	}
 
 	for (i = 0; i < ts->key_num; i++) {
 		if (ts->key_code[i])
@@ -1498,21 +1500,23 @@ static int mip4_probe(struct i2c_client *client)
 	input->keycodesize = sizeof(*ts->key_code);
 	input->keycodemax = ts->key_num;
 
-	input_set_abs_params(input, ABS_MT_TOOL_TYPE, 0, MT_TOOL_PALM, 0, 0);
-	input_set_abs_params(input, ABS_MT_POSITION_X, 0, ts->max_x, 0, 0);
-	input_set_abs_params(input, ABS_MT_POSITION_Y, 0, ts->max_y, 0, 0);
-	input_set_abs_params(input, ABS_MT_PRESSURE,
-			     MIP4_PRESSURE_MIN, MIP4_PRESSURE_MAX, 0, 0);
-	input_set_abs_params(input, ABS_MT_TOUCH_MAJOR,
-			     MIP4_TOUCH_MAJOR_MIN, MIP4_TOUCH_MAJOR_MAX, 0, 0);
-	input_set_abs_params(input, ABS_MT_TOUCH_MINOR,
-			     MIP4_TOUCH_MINOR_MIN, MIP4_TOUCH_MINOR_MAX, 0, 0);
-	input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->ppm_x);
-	input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->ppm_y);
-
-	error = input_mt_init_slots(input, MIP4_MAX_FINGERS, INPUT_MT_DIRECT);
-	if (error)
-		return error;
+	if (ts->max_x && ts->max_y) {
+		input_set_abs_params(input, ABS_MT_TOOL_TYPE, 0, MT_TOOL_PALM, 0, 0);
+		input_set_abs_params(input, ABS_MT_POSITION_X, 0, ts->max_x, 0, 0);
+		input_set_abs_params(input, ABS_MT_POSITION_Y, 0, ts->max_y, 0, 0);
+		input_set_abs_params(input, ABS_MT_PRESSURE,
+				     MIP4_PRESSURE_MIN, MIP4_PRESSURE_MAX, 0, 0);
+		input_set_abs_params(input, ABS_MT_TOUCH_MAJOR,
+				     MIP4_TOUCH_MAJOR_MIN, MIP4_TOUCH_MAJOR_MAX, 0, 0);
+		input_set_abs_params(input, ABS_MT_TOUCH_MINOR,
+				     MIP4_TOUCH_MINOR_MIN, MIP4_TOUCH_MINOR_MAX, 0, 0);
+		input_abs_set_res(ts->input, ABS_MT_POSITION_X, ts->ppm_x);
+		input_abs_set_res(ts->input, ABS_MT_POSITION_Y, ts->ppm_y);
+
+		error = input_mt_init_slots(input, MIP4_MAX_FINGERS, INPUT_MT_DIRECT);
+		if (error)
+			return error;
+	}
 
 	for (i = 0; i < ts->key_num; i++) {
 		if (ts->key_code[i])

-- 
2.49.0


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

* [PATCH RFC 4/4] Input: melfas-mip4 - add support for event formats 4 and 9
  2025-05-03  9:08 [PATCH RFC 0/4] Support for MELFAS MIP4 touchkey devices Kaustabh Chakraborty
                   ` (2 preceding siblings ...)
  2025-05-03  9:08 ` [PATCH RFC 3/4] Input: melfas-mip4 - initialize touch events only if the device is a touchscreen Kaustabh Chakraborty
@ 2025-05-03  9:08 ` Kaustabh Chakraborty
  3 siblings, 0 replies; 7+ messages in thread
From: Kaustabh Chakraborty @ 2025-05-03  9:08 UTC (permalink / raw)
  To: Sangwon Jee, Dmitry Torokhov, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Henrik Rydberg
  Cc: linux-input, devicetree, linux-kernel, Kaustabh Chakraborty

Valid event formats in this driver is limited to 0, 1, and 3. These are
event formats for MIP4 touchscreen devices. Add support for event
formats 4 and 9, which belong to touchkey devices.

While at it, simplify the logic in function mip4_query_device where
valid event formats are checked. Use a human-readable switch-case block
instead of an if statement with obscure conditions.

Signed-off-by: Kaustabh Chakraborty <kauschluss@disroot.org>
---
 drivers/input/touchscreen/melfas_mip4.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/drivers/input/touchscreen/melfas_mip4.c b/drivers/input/touchscreen/melfas_mip4.c
index 57b657694a420220be135c2f78d3ddad3ef6f520..95a78c86873355d0a8e0207b1eb4a8408f55cee4 100644
--- a/drivers/input/touchscreen/melfas_mip4.c
+++ b/drivers/input/touchscreen/melfas_mip4.c
@@ -360,9 +360,19 @@ static int mip4_query_device(struct mip4_ts *ts)
 		dev_dbg(&ts->client->dev, "event_format: %d, event_size: %d\n",
 			ts->event_format, ts->event_size);
 
-		if (ts->event_format == 2 || ts->event_format > 3)
+		switch (ts->event_format) {
+		/* Touchscreens */
+		case 0:
+		case 1:
+		case 3:
+		/* Touchkeys */
+		case 4:
+		case 9:
+			break;
+		default:
 			dev_warn(&ts->client->dev,
 				 "Unknown event format %d\n", ts->event_format);
+		}
 	}
 
 	return 0;
@@ -440,6 +450,8 @@ static void mip4_report_keys(struct mip4_ts *ts, u8 *packet)
 	switch (ts->event_format) {
 	case 0:
 	case 1:
+	case 4:
+	case 9:
 		key = packet[0] & 0x0F;
 		down = packet[0] & 0x80;
 		break;
@@ -552,6 +564,8 @@ static int mip4_handle_packet(struct mip4_ts *ts, u8 *packet)
 	switch (ts->event_format) {
 	case 0:
 	case 1:
+	case 4:
+	case 9:
 		type = (packet[0] & 0x40) >> 6;
 		break;
 

-- 
2.49.0


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

* Re: [PATCH RFC 1/4] dt-bindings: input: melfas-mip4: document linux,keycodes property
  2025-05-03  9:08 ` [PATCH RFC 1/4] dt-bindings: input: melfas-mip4: document linux,keycodes property Kaustabh Chakraborty
@ 2025-05-09 22:06   ` Rob Herring
  2025-05-14 18:13     ` Kaustabh Chakraborty
  0 siblings, 1 reply; 7+ messages in thread
From: Rob Herring @ 2025-05-09 22:06 UTC (permalink / raw)
  To: Kaustabh Chakraborty
  Cc: Sangwon Jee, Dmitry Torokhov, Krzysztof Kozlowski, Conor Dooley,
	Henrik Rydberg, linux-input, devicetree, linux-kernel

On Sat, May 03, 2025 at 02:38:27PM +0530, Kaustabh Chakraborty wrote:
> Document the linux,keycodes property. The property values are key codes
> which are used in input key events generated by the touchkey device.
> 
> Signed-off-by: Kaustabh Chakraborty <kauschluss@disroot.org>
> ---
>  Documentation/devicetree/bindings/input/touchscreen/melfas_mip4.txt | 2 ++
>  1 file changed, 2 insertions(+)

Convert to DT schema if you want to add to this.

Rob

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

* Re: [PATCH RFC 1/4] dt-bindings: input: melfas-mip4: document linux,keycodes property
  2025-05-09 22:06   ` Rob Herring
@ 2025-05-14 18:13     ` Kaustabh Chakraborty
  0 siblings, 0 replies; 7+ messages in thread
From: Kaustabh Chakraborty @ 2025-05-14 18:13 UTC (permalink / raw)
  To: Rob Herring
  Cc: Sangwon Jee, Dmitry Torokhov, Krzysztof Kozlowski, Conor Dooley,
	Henrik Rydberg, linux-input, devicetree, linux-kernel

On 2025-05-09 22:06, Rob Herring wrote:
> On Sat, May 03, 2025 at 02:38:27PM +0530, Kaustabh Chakraborty wrote:
>> Document the linux,keycodes property. The property values are key codes
>> which are used in input key events generated by the touchkey device.
>> 
>> Signed-off-by: Kaustabh Chakraborty <kauschluss@disroot.org>
>> ---
>>  Documentation/devicetree/bindings/input/touchscreen/melfas_mip4.txt | 2 ++
>>  1 file changed, 2 insertions(+)
> 
> Convert to DT schema if you want to add to this.

Sure will. Who would be the maintainer of this driver though?
MAINTAINERS says that the driver is 'Supported' but Sangwon's
e-mail is bouncing.

> 
> Rob

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

end of thread, other threads:[~2025-05-14 18:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-03  9:08 [PATCH RFC 0/4] Support for MELFAS MIP4 touchkey devices Kaustabh Chakraborty
2025-05-03  9:08 ` [PATCH RFC 1/4] dt-bindings: input: melfas-mip4: document linux,keycodes property Kaustabh Chakraborty
2025-05-09 22:06   ` Rob Herring
2025-05-14 18:13     ` Kaustabh Chakraborty
2025-05-03  9:08 ` [PATCH RFC 2/4] Input: melfas-mip4 - add support for touchkey input events Kaustabh Chakraborty
2025-05-03  9:08 ` [PATCH RFC 3/4] Input: melfas-mip4 - initialize touch events only if the device is a touchscreen Kaustabh Chakraborty
2025-05-03  9:08 ` [PATCH RFC 4/4] Input: melfas-mip4 - add support for event formats 4 and 9 Kaustabh Chakraborty

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).