* [PATCH 0/5] msg2638: Add support for msg2138 and key events
@ 2021-11-23 7:25 Vincent Knecht
2021-11-23 7:25 ` [PATCH 1/5] Input: msg2638 - Set max finger number and irqhandler from driver data Vincent Knecht
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Vincent Knecht @ 2021-11-23 7:25 UTC (permalink / raw)
To: dmitry.torokhov, robh+dt, stephan, vincent.knecht
Cc: linux-input, devicetree, linux-kernel, phone-devel,
~postmarketos/upstreaming
This series:
- moves max fingers number and irqhandler settings in a struct
- adds support for msg2138 touchscreen
- adds support for buttons, which were only seen with msg2138 as of yet
Big thanks to Stephan Gerhold <stephan@gerhold.net> for the help with
deciphering the downstream driver [1] and writing clean and working code.
[1] https://github.com/LineageOS/android_kernel_huawei_msm8916/blob/2f24fa58086a969687434b40f237cb589a1f324f/drivers/input/touchscreen/mstar/msg2138_qc.c
Vincent Knecht (5):
Input: msg2638 - Set max finger number and irqhandler from driver data
dt-bindings: input: touchscreen: msg2638: Document msg2138 support
Input: msg2638 - Add support for msg2138
dt-bindings: input: touchscreen: msg2638: Document keys support
Input: msg2638 - Add support for msg2138 key events
.../input/touchscreen/mstar,msg2638.yaml | 8 +-
drivers/input/touchscreen/msg2638.c | 182 ++++++++++++++++--
2 files changed, 175 insertions(+), 15 deletions(-)
--
2.31.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/5] Input: msg2638 - Set max finger number and irqhandler from driver data
2021-11-23 7:25 [PATCH 0/5] msg2638: Add support for msg2138 and key events Vincent Knecht
@ 2021-11-23 7:25 ` Vincent Knecht
2021-11-23 7:25 ` [PATCH 2/5] dt-bindings: input: touchscreen: msg2638: Document msg2138 support Vincent Knecht
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Vincent Knecht @ 2021-11-23 7:25 UTC (permalink / raw)
To: dmitry.torokhov, robh+dt, stephan, vincent.knecht
Cc: linux-input, devicetree, linux-kernel, phone-devel,
~postmarketos/upstreaming
This will allow us to add other MStar touchscreen variants' support.
No functional change.
Signed-off-by: Vincent Knecht <vincent.knecht@mailoo.org>
---
drivers/input/touchscreen/msg2638.c | 40 +++++++++++++++++++++--------
1 file changed, 30 insertions(+), 10 deletions(-)
diff --git a/drivers/input/touchscreen/msg2638.c b/drivers/input/touchscreen/msg2638.c
index 75536bc88969..222adedf78bf 100644
--- a/drivers/input/touchscreen/msg2638.c
+++ b/drivers/input/touchscreen/msg2638.c
@@ -26,23 +26,28 @@
#define MODE_DATA_RAW 0x5A
-#define MAX_SUPPORTED_FINGER_NUM 5
+#define MSG2638_MAX_FINGERS 5
#define CHIP_ON_DELAY_MS 15
#define FIRMWARE_ON_DELAY_MS 50
#define RESET_DELAY_MIN_US 10000
#define RESET_DELAY_MAX_US 11000
-struct packet {
+struct msg_chip_data {
+ irq_handler_t irq_handler;
+ unsigned int max_fingers;
+};
+
+struct msg2638_packet {
u8 xy_hi; /* higher bits of x and y coordinates */
u8 x_low;
u8 y_low;
u8 pressure;
};
-struct touch_event {
+struct msg2638_touch_event {
u8 mode;
- struct packet pkt[MAX_SUPPORTED_FINGER_NUM];
+ struct msg2638_packet pkt[MSG2638_MAX_FINGERS];
u8 proximity;
u8 checksum;
};
@@ -53,6 +58,7 @@ struct msg2638_ts_data {
struct touchscreen_properties prop;
struct regulator_bulk_data supplies[2];
struct gpio_desc *reset_gpiod;
+ int max_fingers;
};
static u8 msg2638_checksum(u8 *data, u32 length)
@@ -71,7 +77,7 @@ static irqreturn_t msg2638_ts_irq_handler(int irq, void *msg2638_handler)
struct msg2638_ts_data *msg2638 = msg2638_handler;
struct i2c_client *client = msg2638->client;
struct input_dev *input = msg2638->input_dev;
- struct touch_event touch_event;
+ struct msg2638_touch_event touch_event;
u32 len = sizeof(touch_event);
struct i2c_msg msg[] = {
{
@@ -81,7 +87,7 @@ static irqreturn_t msg2638_ts_irq_handler(int irq, void *msg2638_handler)
.buf = (u8 *)&touch_event,
},
};
- struct packet *p;
+ struct msg2638_packet *p;
u16 x, y;
int ret;
int i;
@@ -103,7 +109,7 @@ static irqreturn_t msg2638_ts_irq_handler(int irq, void *msg2638_handler)
goto out;
}
- for (i = 0; i < MAX_SUPPORTED_FINGER_NUM; i++) {
+ for (i = 0; i < msg2638->max_fingers; i++) {
p = &touch_event.pkt[i];
/* Ignore non-pressed finger data */
@@ -215,7 +221,7 @@ static int msg2638_init_input_dev(struct msg2638_ts_data *msg2638)
return -EINVAL;
}
- error = input_mt_init_slots(input_dev, MAX_SUPPORTED_FINGER_NUM,
+ error = input_mt_init_slots(input_dev, msg2638->max_fingers,
INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
if (error) {
dev_err(dev, "Failed to initialize MT slots: %d\n", error);
@@ -233,6 +239,7 @@ static int msg2638_init_input_dev(struct msg2638_ts_data *msg2638)
static int msg2638_ts_probe(struct i2c_client *client)
{
+ const struct msg_chip_data *chip_data;
struct device *dev = &client->dev;
struct msg2638_ts_data *msg2638;
int error;
@@ -249,6 +256,14 @@ static int msg2638_ts_probe(struct i2c_client *client)
msg2638->client = client;
i2c_set_clientdata(client, msg2638);
+ chip_data = device_get_match_data(&client->dev);
+ if (!chip_data || !chip_data->max_fingers) {
+ dev_err(dev, "Invalid or missing chip data\n");
+ return -EINVAL;
+ }
+
+ msg2638->max_fingers = chip_data->max_fingers;
+
msg2638->supplies[0].supply = "vdd";
msg2638->supplies[1].supply = "vddio";
error = devm_regulator_bulk_get(dev, ARRAY_SIZE(msg2638->supplies),
@@ -272,7 +287,7 @@ static int msg2638_ts_probe(struct i2c_client *client)
}
error = devm_request_threaded_irq(dev, client->irq,
- NULL, msg2638_ts_irq_handler,
+ NULL, chip_data->irq_handler,
IRQF_ONESHOT | IRQF_NO_AUTOEN,
client->name, msg2638);
if (error) {
@@ -316,8 +331,13 @@ static int __maybe_unused msg2638_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(msg2638_pm_ops, msg2638_suspend, msg2638_resume);
+static const struct msg_chip_data msg2638_data = {
+ .irq_handler = msg2638_ts_irq_handler,
+ .max_fingers = MSG2638_MAX_FINGERS,
+};
+
static const struct of_device_id msg2638_of_match[] = {
- { .compatible = "mstar,msg2638" },
+ { .compatible = "mstar,msg2638", .data = &msg2638_data },
{ }
};
MODULE_DEVICE_TABLE(of, msg2638_of_match);
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/5] dt-bindings: input: touchscreen: msg2638: Document msg2138 support
2021-11-23 7:25 [PATCH 0/5] msg2638: Add support for msg2138 and key events Vincent Knecht
2021-11-23 7:25 ` [PATCH 1/5] Input: msg2638 - Set max finger number and irqhandler from driver data Vincent Knecht
@ 2021-11-23 7:25 ` Vincent Knecht
2021-11-23 7:25 ` [PATCH 3/5] Input: msg2638 - Add support for msg2138 Vincent Knecht
2021-11-23 7:25 ` [PATCH 4/5] dt-bindings: input: touchscreen: msg2638: Document keys support Vincent Knecht
3 siblings, 0 replies; 5+ messages in thread
From: Vincent Knecht @ 2021-11-23 7:25 UTC (permalink / raw)
To: dmitry.torokhov, robh+dt, stephan, vincent.knecht
Cc: linux-input, devicetree, linux-kernel, phone-devel,
~postmarketos/upstreaming
Document msg2138 support by adding mstar,msg2138 compatible.
Signed-off-by: Vincent Knecht <vincent.knecht@mailoo.org>
---
.../devicetree/bindings/input/touchscreen/mstar,msg2638.yaml | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml b/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml
index 3a42c23faf6f..2fb7e01bb65a 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml
@@ -14,7 +14,9 @@ allOf:
properties:
compatible:
- const: mstar,msg2638
+ enum:
+ - mstar,msg2138
+ - mstar,msg2638
reg:
const: 0x26
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 3/5] Input: msg2638 - Add support for msg2138
2021-11-23 7:25 [PATCH 0/5] msg2638: Add support for msg2138 and key events Vincent Knecht
2021-11-23 7:25 ` [PATCH 1/5] Input: msg2638 - Set max finger number and irqhandler from driver data Vincent Knecht
2021-11-23 7:25 ` [PATCH 2/5] dt-bindings: input: touchscreen: msg2638: Document msg2138 support Vincent Knecht
@ 2021-11-23 7:25 ` Vincent Knecht
2021-11-23 7:25 ` [PATCH 4/5] dt-bindings: input: touchscreen: msg2638: Document keys support Vincent Knecht
3 siblings, 0 replies; 5+ messages in thread
From: Vincent Knecht @ 2021-11-23 7:25 UTC (permalink / raw)
To: dmitry.torokhov, robh+dt, stephan, vincent.knecht
Cc: linux-input, devicetree, linux-kernel, phone-devel,
~postmarketos/upstreaming
msg2138 only supports 2 fingers presses, and needs different processing
since second finger press is encoded as a delta position wrt. first one
and the packet/touch_event structs are not the same as msg2638.
Add support for it by implementing distinct structs and irq handler.
Signed-off-by: Vincent Knecht <vincent.knecht@mailoo.org>
---
drivers/input/touchscreen/msg2638.c | 93 +++++++++++++++++++++++++++++
1 file changed, 93 insertions(+)
diff --git a/drivers/input/touchscreen/msg2638.c b/drivers/input/touchscreen/msg2638.c
index 222adedf78bf..73e1b4d550fb 100644
--- a/drivers/input/touchscreen/msg2638.c
+++ b/drivers/input/touchscreen/msg2638.c
@@ -26,6 +26,7 @@
#define MODE_DATA_RAW 0x5A
+#define MSG2138_MAX_FINGERS 2
#define MSG2638_MAX_FINGERS 5
#define CHIP_ON_DELAY_MS 15
@@ -38,6 +39,18 @@ struct msg_chip_data {
unsigned int max_fingers;
};
+struct msg2138_packet {
+ u8 xy_hi; /* higher bits of x and y coordinates */
+ u8 x_low;
+ u8 y_low;
+};
+
+struct msg2138_touch_event {
+ u8 magic;
+ struct msg2138_packet pkt[MSG2138_MAX_FINGERS];
+ u8 checksum;
+};
+
struct msg2638_packet {
u8 xy_hi; /* higher bits of x and y coordinates */
u8 x_low;
@@ -72,6 +85,80 @@ static u8 msg2638_checksum(u8 *data, u32 length)
return (u8)((-sum) & 0xFF);
}
+static irqreturn_t msg2138_ts_irq_handler(int irq, void *msg2638_handler)
+{
+ struct msg2638_ts_data *msg2638 = msg2638_handler;
+ struct i2c_client *client = msg2638->client;
+ struct input_dev *input = msg2638->input_dev;
+ struct msg2138_touch_event touch_event;
+ u32 len = sizeof(touch_event);
+ struct i2c_msg msg[] = {
+ {
+ .addr = client->addr,
+ .flags = I2C_M_RD,
+ .len = sizeof(touch_event),
+ .buf = (u8 *)&touch_event,
+ },
+ };
+ struct msg2138_packet *p0, *p1;
+ u16 x, y, delta_x, delta_y;
+ int ret;
+
+ ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
+ if (ret != ARRAY_SIZE(msg)) {
+ dev_err(&client->dev,
+ "Failed I2C transfer in irq handler: %d\n",
+ ret < 0 ? ret : -EIO);
+ goto out;
+ }
+
+ if (msg2638_checksum((u8 *)&touch_event, len - 1) !=
+ touch_event.checksum) {
+ dev_err(&client->dev, "Failed checksum!\n");
+ goto out;
+ }
+
+ 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)
+ goto report;
+
+ x = (((p0->xy_hi & 0xF0) << 4) | p0->x_low);
+ y = (((p0->xy_hi & 0x0F) << 8) | p0->y_low);
+
+ input_mt_slot(input, 0);
+ input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
+ touchscreen_report_pos(input, &msg2638->prop, x, y, true);
+
+ /* Ignore non-pressed finger data */
+ if (p1->xy_hi == 0xFF && p1->x_low == 0xFF && p1->y_low == 0xFF)
+ goto report;
+
+ /* Second finger is reported as a delta position */
+ delta_x = (((p1->xy_hi & 0xF0) << 4) | p1->x_low);
+ delta_y = (((p1->xy_hi & 0x0F) << 8) | p1->y_low);
+
+ /* Ignore second finger if both deltas equal 0 */
+ if (delta_x == 0 && delta_y == 0)
+ goto report;
+
+ x += delta_x;
+ y += delta_y;
+
+ input_mt_slot(input, 1);
+ input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
+ touchscreen_report_pos(input, &msg2638->prop, x, y, true);
+
+report:
+ input_mt_sync_frame(msg2638->input_dev);
+ input_sync(msg2638->input_dev);
+
+out:
+ return IRQ_HANDLED;
+}
+
static irqreturn_t msg2638_ts_irq_handler(int irq, void *msg2638_handler)
{
struct msg2638_ts_data *msg2638 = msg2638_handler;
@@ -331,12 +418,18 @@ static int __maybe_unused msg2638_resume(struct device *dev)
static SIMPLE_DEV_PM_OPS(msg2638_pm_ops, msg2638_suspend, msg2638_resume);
+static const struct msg_chip_data msg2138_data = {
+ .irq_handler = msg2138_ts_irq_handler,
+ .max_fingers = MSG2138_MAX_FINGERS,
+};
+
static const struct msg_chip_data msg2638_data = {
.irq_handler = msg2638_ts_irq_handler,
.max_fingers = MSG2638_MAX_FINGERS,
};
static const struct of_device_id msg2638_of_match[] = {
+ { .compatible = "mstar,msg2138", .data = &msg2138_data },
{ .compatible = "mstar,msg2638", .data = &msg2638_data },
{ }
};
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 4/5] dt-bindings: input: touchscreen: msg2638: Document keys support
2021-11-23 7:25 [PATCH 0/5] msg2638: Add support for msg2138 and key events Vincent Knecht
` (2 preceding siblings ...)
2021-11-23 7:25 ` [PATCH 3/5] Input: msg2638 - Add support for msg2138 Vincent Knecht
@ 2021-11-23 7:25 ` Vincent Knecht
3 siblings, 0 replies; 5+ messages in thread
From: Vincent Knecht @ 2021-11-23 7:25 UTC (permalink / raw)
To: dmitry.torokhov, robh+dt, stephan, vincent.knecht
Cc: linux-input, devicetree, linux-kernel, phone-devel,
~postmarketos/upstreaming
Document optional linux,keycodes support.
Signed-off-by: Vincent Knecht <vincent.knecht@mailoo.org>
---
.../devicetree/bindings/input/touchscreen/mstar,msg2638.yaml | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml b/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml
index 2fb7e01bb65a..af4f954de958 100644
--- a/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml
+++ b/Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml
@@ -36,6 +36,10 @@ properties:
touchscreen-size-x: true
touchscreen-size-y: true
+ linux,keycodes:
+ minItems: 1
+ maxItems: 4
+
additionalProperties: false
required:
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-11-23 7:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-23 7:25 [PATCH 0/5] msg2638: Add support for msg2138 and key events Vincent Knecht
2021-11-23 7:25 ` [PATCH 1/5] Input: msg2638 - Set max finger number and irqhandler from driver data Vincent Knecht
2021-11-23 7:25 ` [PATCH 2/5] dt-bindings: input: touchscreen: msg2638: Document msg2138 support Vincent Knecht
2021-11-23 7:25 ` [PATCH 3/5] Input: msg2638 - Add support for msg2138 Vincent Knecht
2021-11-23 7:25 ` [PATCH 4/5] dt-bindings: input: touchscreen: msg2638: Document keys support Vincent Knecht
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).