Skip to contentSkip to conversation

dt-bindings: input/touchscreen: add bindings for msg2638

PATCH Superseded Vincent Knecht 2 participants 4 messages Feb 16, 2021 – Mar 2, 2021

Subsystems (3)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/2 dt-bindings: input/touchscreen: add bindings for msg2638

This adds dts bindings for the mstar msg2638 touchscreen.

---
Changed in v5: nothing
Changed in v4:
- don't use wildcards in compatible strings (Rob H)
- rename from msg26xx to msg2638
- rename example pinctrl-0 to &ts_int_reset_default for consistency Changed in v3:
- added touchscreen-size-x: true and touchscreen-size-y: true properties Changed in v2:
- changed M-Star to MStar in title line
- changed reset gpio to active-low in example section

---
 .../input/touchscreen/mstar,msg2638.yaml      | 69 +++++++++++++++++++
 1 file changed, 69 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml
Documentation/devicetree/bindings/input/touchscreen/mstar,msg2638.yaml new file +69 -0
new file mode 100644
index 000000000000..12f44d9e4d41
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/input/touchscreen/mstar,msg2638.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: MStar msg2638 touchscreen controller Bindings
+
+maintainers:
+  - Vincent Knecht <[email protected]>
+
+allOf:
+  - $ref: touchscreen.yaml#
+
+properties:
+  compatible:
+    const: mstar,msg2638
+
+  reg:
+    const: 0x26
+
+  interrupts:
+    maxItems: 1
+
+  reset-gpios:
+    maxItems: 1
+
+  vdd-supply:
+    description: Power supply regulator for the chip
+
+  vddio-supply:
+    description: Power supply regulator for the I2C bus
+
+  touchscreen-size-x: true
+  touchscreen-size-y: true
+
+additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - reset-gpios
+  - touchscreen-size-x
+  - touchscreen-size-y
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      touchscreen@26 {
+        compatible = "mstar,msg2638";
+        reg = <0x26>;
+        interrupt-parent = <&msmgpio>;
+        interrupts = <13 IRQ_TYPE_EDGE_FALLING>;
+        reset-gpios = <&msmgpio 100 GPIO_ACTIVE_LOW>;
+        pinctrl-names = "default";
+        pinctrl-0 = <&ts_int_reset_default>;
+        vdd-supply = <&pm8916_l17>;
+        vddio-supply = <&pm8916_l5>;
+        touchscreen-size-x = <720>;
+        touchscreen-size-y = <1280>;
+      };
+    };
+
+...
Signature · 1 line
2.29.2
#1 lore raw

PATCH v5 2/2 Input: add MStar MSG2638 touchscreen driver

Add support for the msg2638 touchscreen IC from MStar.
This driver reuses zinitix.c structure, while the checksum and irq handler functions are based on out-of-tree driver for Alcatel Idol 3 (4.7").

---
Changed in v5:
- use gpiod_set_value_cansleep() (Stephan G)
- use msleep/usleep_range() rathen than mdelay() (Stephan G)
Changed in v4:
- rename from msg26xx to msg2638, following compatible string change
- rename mstar_* functions to msg2638_* for consistency
- add RESET_DELAY define and use it in msg2638_power_on()
- change a few dev_err() calls to be on one line only
- add missing \n in a few dev_err() strings
Changed in v3:
- no change
Changed in v2:
- don't use bitfields in packet struct, to prevent endian-ness related problems (Dmitry)
- fix reset gpiod calls order in mstar_power_on() (Dmitry)

---
 drivers/input/touchscreen/Kconfig   |  12 +
 drivers/input/touchscreen/Makefile  |   1 +
 drivers/input/touchscreen/msg2638.c | 363 ++++++++++++++++++++++++++++
 3 files changed, 376 insertions(+)
 create mode 100644 drivers/input/touchscreen/msg2638.c
drivers/input/touchscreen/Kconfig +12 -0
index f012fe746df0..fefbe1c1bb10 100644
@@ -1334,4 +1334,16 @@ config TOUCHSCREEN_ZINITIX
 	  To compile this driver as a module, choose M here: the
 	  module will be called zinitix.
 
+config TOUCHSCREEN_MSG2638
+	tristate "MStar msg2638 touchscreen support"
+	depends on I2C
+	depends on GPIOLIB || COMPILE_TEST
+	help
+	  Say Y here if you have an I2C touchscreen using MStar msg2638.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called msg2638.
+
 endif
drivers/input/touchscreen/Makefile +1 -0
index 6233541e9173..83e516cb3d33 100644
@@ -112,3 +112,4 @@ obj-$(CONFIG_TOUCHSCREEN_ROHM_BU21023)	+= rohm_bu21023.o
 obj-$(CONFIG_TOUCHSCREEN_RASPBERRYPI_FW)	+= raspberrypi-ts.o
 obj-$(CONFIG_TOUCHSCREEN_IQS5XX)	+= iqs5xx.o
 obj-$(CONFIG_TOUCHSCREEN_ZINITIX)	+= zinitix.o
+obj-$(CONFIG_TOUCHSCREEN_MSG2638)	+= msg2638.o
drivers/input/touchscreen/msg2638.c new file +363 -0

363 lines not on this page · raw message

Signature · 1 line
2.29.2
#2 lore raw

Re: [PATCH v5 2/2] Input: add MStar MSG2638 touchscreen driver

Hi Vincent,

thanks for your patch!

Quoted 9 lines · Vincent Knecht

Add support for the msg2638 touchscreen IC from MStar.
This driver reuses zinitix.c structure, while the checksum and irq handler functions are based on out-of-tree driver for Alcatel Idol 3 (4.7").

---
Changed in v5:
- use gpiod_set_value_cansleep() (Stephan G)
- use msleep/usleep_range() rathen than mdelay() (Stephan G)

(...)

drivers/input/touchscreen/msg2638.c line 14

Quoted 2 lines
drivers/input/touchscreen/msg2638.c new file +2 -0
+#include <linux/delay.h>
+#include <linux/gpio.h>

Please only include
#include <linux/gpio/consumer.h>

drivers/input/touchscreen/msg2638.c line 37

Quoted 4 lines
drivers/input/touchscreen/msg2638.c new file +4 -0
+#define CHIP_ON_DELAY                  15 // ms
+#define FIRMWARE_ON_DELAY              50 // ms
+#define RESET_DELAY_MIN                        10000 // µs
+#define RESET_DELAY_MAX                        11000 // µs

Rename the defines with _MS and _US suffixes so you don't need the comments, CHIP_ON_DELAY_MS etc.

drivers/input/touchscreen/msg2638.c line 69

Quoted 4 lines
drivers/input/touchscreen/msg2638.c new file +4 -0
+static int msg2638_init_regulators(struct msg2638_ts_data *msg2638)
+{
+       struct i2c_client *client = msg2638->client;
+       int error;

I usually prefer a short name like "err" (cognitive load) but your choice.

drivers/input/touchscreen/msg2638.c line 112

Quoted 10 lines
drivers/input/touchscreen/msg2638.c new file +10 -0
+static u8 msg2638_checksum(u8 *data, u32 length)
+{
+       s32 sum = 0;
+       u32 i;
+
+       for (i = 0; i < length; i++)
+               sum += data[i];
+
+       return (u8)((-sum) & 0xFF);
+}

Interesting checksum algoritm.

Quoted 4 lines
drivers/input/touchscreen/msg2638.c new file +4 -0
+static int msg2638_start(struct msg2638_ts_data *msg2638)
+{
+       int error;
+

drivers/input/touchscreen/msg2638.c line 179

Quoted 10 lines
drivers/input/touchscreen/msg2638.c new file +10 -0
+       error = regulator_bulk_enable(ARRAY_SIZE(msg2638->supplies),
+                                     msg2638->supplies);
+       if (error) {
+               dev_err(&msg2638->client->dev, "Failed to enable regulators: %d\n", error);
+               return error;
+       }
+
+       msleep(CHIP_ON_DELAY);
+
+       msg2638_power_on(msg2638);

Maybe move enable_irq() here from power on to mirror the stop() function below?

drivers/input/touchscreen/msg2638.c line 349

Quoted 7 lines
drivers/input/touchscreen/msg2638.c new file +7 -0
+#ifdef CONFIG_OF
+static const struct of_device_id msg2638_of_match[] = {
+       { .compatible = "mstar,msg2638" },
+       { }
+};
+MODULE_DEVICE_TABLE(of, msg2638_of_match);
+#endif

I think these #ifdefs are not needed anymore. We just have struct of_device_id available at all times.

Yours,
Linus Walleij