From: rofikkerneldev <rofikcoga@gmail.com>
To: linux-arm-msm@vger.kernel.org
Cc: devicetree@vger.kernel.org, dri-devel@lists.freedesktop.org,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Neil Armstrong <neil.armstrong@linaro.org>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
rofikkerneldev <rofikcoga@gmail.com>
Subject: [PATCH v1 07/11] Input: touchscreen: add Silicon Works SW42902 support
Date: Tue, 17 Nov 2026 13:39:42 +0100 [thread overview]
Message-ID: <20261117123946.668557-8-rofikcoga@gmail.com> (raw)
In-Reply-To: <20261117123946.668557-1-rofikcoga@gmail.com>
Add basic multitouch support for the SW42902 controller. Implement the
GPIO power and reset sequence and use the firmware already present in
controller flash; no firmware update is performed.
Signed-off-by: rofikkerneldev <rofikcoga@gmail.com>
---
MAINTAINERS | 1 +
drivers/input/touchscreen/Kconfig | 11 +
drivers/input/touchscreen/Makefile | 1 +
drivers/input/touchscreen/sw42902.c | 315 ++++++++++++++++++++++++++++
4 files changed, 328 insertions(+)
create mode 100644 drivers/input/touchscreen/sw42902.c
diff --git a/MAINTAINERS b/MAINTAINERS
index f4c54d7d86bd8..83bbedde94533 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -25840,6 +25840,7 @@ M: rofikkerneldev <rofikcoga@gmail.com>
L: linux-input@vger.kernel.org
S: Maintained
F: Documentation/devicetree/bindings/input/touchscreen/lg,sw42902.yaml
+F: drivers/input/touchscreen/sw42902.c
SILVACO I3C DUAL-ROLE MASTER
M: Miquel Raynal <miquel.raynal@bootlin.com>
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 9b9ae8ac3f7fd..eadba5125a225 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -1402,6 +1402,17 @@ config TOUCHSCREEN_ZINITIX
To compile this driver as a module, choose M here: the
module will be called zinitix.
+config TOUCHSCREEN_SW42902
+ tristate "Silicon Works SW42902 touchscreen"
+ depends on I2C
+ depends on GPIOLIB
+ help
+ Say Y here for the SW42902 I2C touchscreen used in the LG V60.
+ Basic multitouch uses the controller's existing flash firmware.
+
+ To compile this driver as a module, choose M here: the module
+ will be called sw42902.
+
config TOUCHSCREEN_HIMAX_HX83112B
tristate "Himax hx83112b touchscreen driver"
depends on I2C
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index bfd9de83389d8..ee312c2d1529c 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -119,3 +119,4 @@ obj-$(CONFIG_TOUCHSCREEN_IQS5XX) += iqs5xx.o
obj-$(CONFIG_TOUCHSCREEN_IQS7211) += iqs7211.o
obj-$(CONFIG_TOUCHSCREEN_ZINITIX) += zinitix.o
obj-$(CONFIG_TOUCHSCREEN_HIMAX_HX83112B) += himax_hx83112b.o
+obj-$(CONFIG_TOUCHSCREEN_SW42902) += sw42902.o
diff --git a/drivers/input/touchscreen/sw42902.c b/drivers/input/touchscreen/sw42902.c
new file mode 100644
index 0000000000000..7b39a97053c63
--- /dev/null
+++ b/drivers/input/touchscreen/sw42902.c
@@ -0,0 +1,315 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Silicon Works SW42902 touchscreen, as used by LG V60 (timelm).
+ * Register protocol and report layout derived from the LGE vendor driver
+ * (Copyright (C) 2015 LGE, author hoyeon.jang@lge.com).
+ * This driver uses the controller's existing flash firmware.
+ */
+
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/input/mt.h>
+#include <linux/input/touchscreen.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/pm.h>
+#include <linux/slab.h>
+#include <linux/unaligned.h>
+
+#define SW42902_MAX_CONTACTS 10
+#define SW42902_REPORT_SIZE (12 + 24 + 12 * SW42902_MAX_CONTACTS)
+#define SW42902_IC_STATUS 0x600
+#define SW42902_VERSION 0x642
+#define SW42902_DEVICE_CTL 0xc00
+#define SW42902_INTERRUPT_CTL 0xc01
+#define SW42902_DRIVING_CTL 0xc03
+#define SW42902_SERIAL_SPI_EN 0xfe4
+#define SW42902_DRIVING_STOP 0x04
+#define SW42902_DRIVING_U3 0x8303
+
+struct sw42902 {
+ struct i2c_client *client;
+ struct input_dev *input;
+ struct touchscreen_properties prop;
+ struct gpio_desc *reset;
+ struct gpio_desc *vcl;
+ struct gpio_desc *vdd;
+ u8 report[SW42902_REPORT_SIZE];
+};
+
+static int sw42902_read(struct sw42902 *ts, u16 reg, void *data, u16 len)
+{
+ u8 command[] = { (reg >> 8) | (len > 4 ? 0x20 : 0), reg & 0xff };
+ struct i2c_msg msgs[] = {
+ { .addr = ts->client->addr, .len = sizeof(command),
+ .buf = command },
+ { .addr = ts->client->addr, .flags = I2C_M_RD,
+ .len = len, .buf = data },
+ };
+ int ret;
+
+ ret = i2c_transfer(ts->client->adapter, msgs, ARRAY_SIZE(msgs));
+ if (ret < 0)
+ return ret;
+ return ret == ARRAY_SIZE(msgs) ? 0 : -EIO;
+}
+
+static int sw42902_write(struct sw42902 *ts, u16 reg, u32 value)
+{
+ u8 command[6] = { 0x40 | (reg >> 8), reg & 0xff };
+ int ret;
+
+ put_unaligned_le32(value, command + 2);
+ ret = i2c_master_send(ts->client, command, sizeof(command));
+ if (ret < 0)
+ return ret;
+ return ret == sizeof(command) ? 0 : -EIO;
+}
+
+static void sw42902_release_contacts(struct sw42902 *ts)
+{
+ int i;
+
+ for (i = 0; i < SW42902_MAX_CONTACTS; i++) {
+ input_mt_slot(ts->input, i);
+ input_mt_report_slot_state(ts->input, MT_TOOL_FINGER, false);
+ }
+ input_mt_sync_frame(ts->input);
+ input_sync(ts->input);
+}
+
+static irqreturn_t sw42902_irq(int irq, void *data)
+{
+ struct sw42902 *ts = data;
+ struct input_dev *input = ts->input;
+ u32 status, header;
+ unsigned int count, i;
+ int ret;
+
+ ret = sw42902_read(ts, SW42902_IC_STATUS, ts->report,
+ sizeof(ts->report));
+ if (ret) {
+ dev_err_ratelimited(&ts->client->dev, "report read failed: %d\n", ret);
+ sw42902_release_contacts(ts);
+ return IRQ_HANDLED;
+ }
+
+ status = get_unaligned_le32(ts->report + 4);
+ header = get_unaligned_le32(ts->report + 8);
+ /* Only normal absolute-touch reports; ignore pen/gesture/debug IRQs. */
+ if (((status >> 16) & 0xf) != 5 || (header & 0xff))
+ return IRQ_HANDLED;
+
+ count = (header >> 8) & 0x1f;
+ if (count > SW42902_MAX_CONTACTS) {
+ dev_warn_ratelimited(&ts->client->dev, "invalid contact count: %u\n", count);
+ sw42902_release_contacts(ts);
+ return IRQ_HANDLED;
+ }
+
+ /* A palm report cancels all active fingers. */
+ if (header & BIT(31)) {
+ sw42902_release_contacts(ts);
+ return IRQ_HANDLED;
+ }
+
+ for (i = 0; i < count; i++) {
+ const u8 *contact = ts->report + 36 + 12 * i;
+ u32 a = get_unaligned_le32(contact);
+ u32 b = get_unaligned_le32(contact + 4);
+ u32 c = get_unaligned_le32(contact + 8);
+ unsigned int id = a & 0x1f;
+ unsigned int event = (a >> 16) & 3;
+
+ if (id == 15) {
+ sw42902_release_contacts(ts);
+ return IRQ_HANDLED;
+ }
+ if (id >= SW42902_MAX_CONTACTS || (event != 1 && event != 2))
+ continue;
+
+ input_mt_slot(input, id);
+ input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
+ touchscreen_report_pos(input, &ts->prop, a >> 18, b & 0x3fff, true);
+ input_report_abs(input, ABS_MT_PRESSURE, (b >> 14) & 0xff);
+ input_report_abs(input, ABS_MT_TOUCH_MAJOR, (c >> 4) & 0x3fff);
+ input_report_abs(input, ABS_MT_TOUCH_MINOR, c >> 18);
+ }
+
+ input_mt_sync_frame(input);
+ input_sync(input);
+ return IRQ_HANDLED;
+}
+
+static void sw42902_power_off(void *data)
+{
+ struct sw42902 *ts = data;
+
+ gpiod_set_value_cansleep(ts->reset, 1);
+ usleep_range(1000, 2000);
+ gpiod_set_value_cansleep(ts->vdd, 0);
+ usleep_range(1000, 2000);
+ gpiod_set_value_cansleep(ts->vcl, 0);
+}
+
+static void sw42902_power_on(struct sw42902 *ts)
+{
+ gpiod_set_value_cansleep(ts->vcl, 1);
+ usleep_range(1000, 2000);
+ gpiod_set_value_cansleep(ts->vdd, 1);
+ usleep_range(10000, 11000);
+ gpiod_set_value_cansleep(ts->reset, 0);
+ /* Docomo downstream DT specifies a 90 ms hardware reset delay. */
+ msleep(90);
+}
+
+static int sw42902_start(struct sw42902 *ts)
+{
+ u8 version[4];
+ int ret;
+
+ ret = sw42902_read(ts, SW42902_VERSION, version, sizeof(version));
+ if (ret)
+ return ret;
+ if (version[2] != 10 || (version[3] & 0xf) != 4) {
+ dev_err(&ts->client->dev, "unexpected chip/protocol: %u/%u\n",
+ version[2], version[3] & 0xf);
+ return -ENODEV;
+ }
+
+ ret = sw42902_write(ts, SW42902_SERIAL_SPI_EN, 0);
+ if (ret)
+ return ret;
+ ret = sw42902_write(ts, SW42902_DEVICE_CTL, 1);
+ if (ret)
+ return ret;
+ ret = sw42902_write(ts, SW42902_INTERRUPT_CTL, 1);
+ if (ret)
+ return ret;
+ ret = sw42902_write(ts, SW42902_DRIVING_CTL, SW42902_DRIVING_STOP);
+ if (ret)
+ return ret;
+ msleep(30);
+ return sw42902_write(ts, SW42902_DRIVING_CTL, SW42902_DRIVING_U3);
+}
+
+static int sw42902_probe(struct i2c_client *client)
+{
+ struct device *dev = &client->dev;
+ struct sw42902 *ts;
+ struct input_dev *input;
+ int ret;
+
+ if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
+ return -EOPNOTSUPP;
+ if (client->irq <= 0)
+ return dev_err_probe(dev, -EINVAL, "missing interrupt\n");
+
+ ts = devm_kzalloc(dev, sizeof(*ts), GFP_KERNEL);
+ if (!ts)
+ return -ENOMEM;
+ ts->client = client;
+ i2c_set_clientdata(client, ts);
+
+ ts->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
+ if (IS_ERR(ts->reset))
+ return dev_err_probe(dev, PTR_ERR(ts->reset), "reset GPIO\n");
+ ts->vcl = devm_gpiod_get(dev, "vcl", GPIOD_OUT_LOW);
+ if (IS_ERR(ts->vcl))
+ return dev_err_probe(dev, PTR_ERR(ts->vcl), "3.3 V enable GPIO\n");
+ ts->vdd = devm_gpiod_get(dev, "vdd", GPIOD_OUT_LOW);
+ if (IS_ERR(ts->vdd))
+ return dev_err_probe(dev, PTR_ERR(ts->vdd), "1.8 V enable GPIO\n");
+ ret = devm_add_action_or_reset(dev, sw42902_power_off, ts);
+ if (ret)
+ return ret;
+
+ input = devm_input_allocate_device(dev);
+ if (!input)
+ return -ENOMEM;
+ ts->input = input;
+ input->name = "Silicon Works SW42902";
+ input->id.bustype = BUS_I2C;
+ input_set_abs_params(input, ABS_MT_POSITION_X, 0, 1079, 0, 0);
+ input_set_abs_params(input, ABS_MT_POSITION_Y, 0, 2459, 0, 0);
+ input_set_abs_params(input, ABS_MT_PRESSURE, 0, 255, 0, 0);
+ input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, 16383, 0, 0);
+ input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, 16383, 0, 0);
+ touchscreen_parse_properties(input, true, &ts->prop);
+ ret = input_mt_init_slots(input, SW42902_MAX_CONTACTS,
+ INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED);
+ if (ret)
+ return ret;
+ ret = devm_request_threaded_irq(dev, client->irq, NULL, sw42902_irq,
+ IRQF_ONESHOT | IRQF_NO_AUTOEN,
+ dev_name(dev), ts);
+ if (ret)
+ return dev_err_probe(dev, ret, "interrupt request failed\n");
+
+ sw42902_power_on(ts);
+ ret = sw42902_start(ts);
+ if (ret)
+ return dev_err_probe(dev, ret, "controller initialization failed\n");
+ ret = input_register_device(input);
+ if (ret)
+ return ret;
+ enable_irq(client->irq);
+ dev_info(dev, "SW42902 initialized using existing flash firmware\n");
+ return 0;
+}
+
+static int sw42902_suspend(struct device *dev)
+{
+ struct sw42902 *ts = i2c_get_clientdata(to_i2c_client(dev));
+
+ disable_irq(ts->client->irq);
+ sw42902_release_contacts(ts);
+ sw42902_write(ts, SW42902_DRIVING_CTL, SW42902_DRIVING_STOP);
+ sw42902_power_off(ts);
+ return 0;
+}
+
+static int sw42902_resume(struct device *dev)
+{
+ struct sw42902 *ts = i2c_get_clientdata(to_i2c_client(dev));
+ int ret;
+
+ sw42902_power_on(ts);
+ ret = sw42902_start(ts);
+ if (ret) {
+ sw42902_power_off(ts);
+ return ret;
+ }
+ enable_irq(ts->client->irq);
+ return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(sw42902_pm_ops, sw42902_suspend, sw42902_resume);
+
+static const struct of_device_id sw42902_of_match[] = {
+ { .compatible = "lg,sw42902" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, sw42902_of_match);
+
+static const struct i2c_device_id sw42902_ids[] = {
+ { "sw42902" },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, sw42902_ids);
+
+static struct i2c_driver sw42902_driver = {
+ .driver = {
+ .name = "sw42902",
+ .of_match_table = sw42902_of_match,
+ .pm = pm_sleep_ptr(&sw42902_pm_ops),
+ },
+ .probe = sw42902_probe,
+ .id_table = sw42902_ids,
+};
+module_i2c_driver(sw42902_driver);
+
+MODULE_DESCRIPTION("Silicon Works SW42902 touchscreen driver");
+MODULE_LICENSE("GPL");
--
2.39.5
next prev parent reply other threads:[~2026-11-17 12:39 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 12:39 [PATCH v1 00/11] arm64: qcom: Add initial support for LG V60 ThinQ 5G (timelm) rofikkerneldev
2026-11-17 12:39 ` [PATCH v1 01/11] dt-bindings: arm: qcom: add " rofikkerneldev
2026-11-17 12:47 ` sashiko-bot
2026-11-17 12:39 ` [PATCH v1 02/11] arm64: dts: qcom: add LG V60 ThinQ 5G (timelm) support rofikkerneldev
2026-11-17 13:06 ` sashiko-bot
2026-11-17 12:39 ` [PATCH v1 03/11] arm64: dts: qcom: sm8250-lge-timelm: add reserved memory regions rofikkerneldev
2026-11-17 12:57 ` sashiko-bot
2026-11-17 12:39 ` [PATCH v1 04/11] dt-bindings: display: panel: add LG SW43103 rofikkerneldev
2026-11-17 12:51 ` sashiko-bot
2026-11-17 12:39 ` [PATCH v1 05/11] drm/panel: add LG SW43103 panel driver rofikkerneldev
2026-11-17 13:04 ` sashiko-bot
2026-11-17 12:39 ` [PATCH v1 06/11] dt-bindings: input: touchscreen: add Silicon Works SW42902 rofikkerneldev
2026-11-17 12:51 ` sashiko-bot
2026-11-17 12:39 ` rofikkerneldev [this message]
2026-11-17 13:01 ` [PATCH v1 07/11] Input: touchscreen: add Silicon Works SW42902 support sashiko-bot
2026-11-17 12:39 ` [PATCH v1 08/11] arm64: dts: qcom: sm8250-lge-timelm: enable SW43103 panel rofikkerneldev
2026-11-17 13:12 ` sashiko-bot
2026-11-17 12:39 ` [PATCH v1 09/11] arm64: dts: qcom: sm8250-lge-timelm: add SW42902 touchscreen rofikkerneldev
2026-11-17 12:56 ` sashiko-bot
2026-11-17 12:39 ` [PATCH v1 10/11] arm64: dts: qcom: sm8250-lge-timelm: enable USB Type-C rofikkerneldev
2026-11-17 13:12 ` sashiko-bot
2026-11-17 12:39 ` [PATCH v1 11/11] arm64: dts: qcom: sm8250-lge-timelm: add QCA6390 Bluetooth rofikkerneldev
2026-11-17 13:09 ` sashiko-bot
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=20261117123946.668557-8-rofikcoga@gmail.com \
--to=rofikcoga@gmail.com \
--cc=andersson@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=robh@kernel.org \
/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.