From nobody Fri Jul 24 05:21:38 2026 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 81FBE45D180 for ; Thu, 23 Jul 2026 15:23:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784820212; cv=none; b=CUq+qAhYYaGYad3DydxvcuY80mtIhNteDMjgJC9fGB9+UXGBTCVlqqCS/z/AVhlAOTMFiCA81klOCVfzc5WCfTS9c7zJn+IqrfEIcU3JZS2Seleljs9kQ4ui/NW9Ek8zb1POFJtQAd8odwLTNotsML06bo5c9RS/wVqSpIRbN+o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784820212; c=relaxed/simple; bh=IxfGdOD8c+bs/ofS0nPioWhzBnW302ku2so1VQ4QdXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DW4UmJuWq8mJzeOrqDUsGNqBqKcyQN21qD/yQXa7im0/nd+UT++H8mKuf/VGa1l5rZq9sfjb0hZ2YdJj5iZ9usjP7klQGE+CNWCUid7kTEC4hMbqoUck/dhoSA7iHo2Rpz54Mv4uCVGllenqxnOebrGiZelNPOdbhJRkAygJatU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mide.dk; spf=none smtp.mailfrom=mide.dk; dkim=pass (2048-bit key) header.d=mide-dk.20251104.gappssmtp.com header.i=@mide-dk.20251104.gappssmtp.com header.b=EIov3dK6; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mide.dk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=mide.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mide-dk.20251104.gappssmtp.com header.i=@mide-dk.20251104.gappssmtp.com header.b="EIov3dK6" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-c15e2dab83eso134102366b.1 for ; Thu, 23 Jul 2026 08:23:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mide-dk.20251104.gappssmtp.com; s=20251104; t=1784820206; x=1785425006; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Imh04o9mc49Waklr40dCWoXoSYRmEDG+6s9mmv06zbw=; b=EIov3dK6bac9lVV8Md9LULCBrJcH/c3MqTIfTVYGxkhVauxDZFcF799H3mAR+dweOF oQH7d6o+yd0qZYIbxMwRUNhvVLENOnznVNJzPaXcMWp+8JyO1wZMH1nKE5FQ4faMrl4d gYtnD84ogt+KbXJge2sODgzGlBkGU8T2pVPiUup4PEksX2F5dn3T80f06aqgtnhXf6zJ f7SJ4MePAQkAM3vuPeUQhPEHkz73NtOgS1f16eyJC7CmkV8HVgNvnQOwtjnP4gDD/Fse IIGTWbJaVEFLcfiw2jd5OQRy/UY8pApkoETMtCADx3PVvMVaYwzTX41H5eMWZ5ghZbSm hJrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784820206; x=1785425006; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Imh04o9mc49Waklr40dCWoXoSYRmEDG+6s9mmv06zbw=; b=J5FYO0bmXYHcM4JIYXCatpN1uWgGED/rn9Js3fhgoxSzqncAiO/jnP5MUfbpzrH0XK +mc5JtI/zR9cLK0ZtjfdnOaM5pTGo1nAngqlVC3AuynUVilXqjWNz71UP4I0HtcX5dtv IOkJaoR/hE38DOr3Ky40oM34D+e07Sf+vMDoNeZ/80cPkZrJSDZeGdDQzrMIhgw0mrts UDUHWTW8QMwYbaFyqMOx7S4l1eWgJmKbqRDDMsK4f45nN5HtgyyjgqCmVIIIiE/VRrZ9 K80o+xMhQpclHIviQWqrH3Iy+4y6ORkmFPb6qJVjF9fruoMBtOkA2V6igkYVCyrjZUKz br0w== X-Forwarded-Encrypted: i=1; AHgh+RoiZ7+m79yYEUHHSwWfOzKMAJY8+SJAnbu3/+enVtqpRx34OW+WMnFwWciWkhefXyD6x5u3L/FxvH33jJo=@vger.kernel.org X-Gm-Message-State: AOJu0YyYN+rKbZUMnxh0SbjbCwWgSbICYESnxfuKFsOHtJqQM+STpHef c7kwEbDlIR2ZlzTb+Xg9Q4WFc++HES+z0TXdzPb0QuO6NHDqx8zjRm5U0lLz3LcmFw== X-Gm-Gg: AR+sD132G6OMNBRyllYSX/RtfllCOQGYR5DhWqri/MGZib7CRYN/ieYbAy3tio52jly RYxGK091TnIKdoysqEphbOGIhlkXBMqqoVdzba4gU3BFLJta1ErZdQa4hUfer0A7HHQqgnQPOED PF5hZ7+1x0HX6RlC3cXJ3h6vCzv9GHwW6sCA9sjffrjTvD0dhpUuBSfX7wpuAJsnzTMRG9/jkDK DpoDq518vPW0fvV9243O+2wgiYmSWyOtEPj7nOdDebmPRecgfjxbKYRhxPcugIqJyIV4hF+b3a+ u6HFjsBJNbT+2TXrXOnyyupibE4hf5f1tfc23kBplDctccBgheCFMEGbr2GCJTOyScQIU+2vd14 qslO3rnoOrFk55aOguSmwTqQWjui30eV0298vR/UOFEqtXQnGb7K4NVdGfzXaq+Ik4DLJb0yOaU HIOoAkyCpj0uinJRRNRq2JVMhslqB5GxYySFiH5e/rwLQz9dkNp7efUFt/5vtNCeRj1C8/SfVfW eNcEo2zl5ULZCXrZrHFGxOrh8h2qh7zh8jT6j4XKw== X-Received: by 2002:a17:906:9fce:b0:c12:83da:7eeb with SMTP id a640c23a62f3a-c1c50993672mr182744766b.19.1784820205559; Thu, 23 Jul 2026 08:23:25 -0700 (PDT) Received: from localhost.localdomain (2a06.4004.215b.0000.2aa0.6bff.feb3.5b8c.static6.kviknet.net. [2a06:4004:215b:0:2aa0:6bff:feb3:5b8c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1c32ebb385sm250749666b.52.2026.07.23.08.23.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 08:23:25 -0700 (PDT) From: Kristian Mide To: dmitry.torokhov@gmail.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Kristian Mide Subject: [PATCH v3 1/3] Input: ilitek_ts: add stylus input support Date: Thu, 23 Jul 2026 17:22:42 +0200 Message-ID: <20260723152244.11252-2-kristian@mide.dk> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260723152244.11252-1-kristian@mide.dk> References: <20260709182602.7308-1-kristian@mide.dk> <20260723152244.11252-1-kristian@mide.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a separate stylus input device for report ID 0x0c packets, with pressure, hover, and side-button support. The pen device is created lazily on first pen report so touchscreen-only hardware does not expose stylus capabilities up front. The packet format is reverse engineered from a tested CHUWI Hi10 Max. Pressure is reported from buf[6..7] shifted right by one, matching the observed 1024 pressure levels on the tested device. Pen coordinates are reported through touchscreen_report_pos() so the same axis inversion and swapping properties used by the touch path apply to the stylus as well. The pen device lifetime is managed explicitly so the IRQ is removed before the lazy pen input device is unregistered during driver teardown. Use input_set_capability() for the pen key capabilities. Signed-off-by: Kristian Mide --- drivers/input/touchscreen/ilitek_ts_i2c.c | 137 +++++++++++++++++++++- 1 file changed, 134 insertions(+), 3 deletions(-) diff --git a/drivers/input/touchscreen/ilitek_ts_i2c.c b/drivers/input/touc= hscreen/ilitek_ts_i2c.c index 3de0fbf8d..86975fa9a 100644 --- a/drivers/input/touchscreen/ilitek_ts_i2c.c +++ b/drivers/input/touchscreen/ilitek_ts_i2c.c @@ -37,6 +37,18 @@ #define ILITEK_TP_CMD_GET_IC_MODE 0xC0 =20 #define ILITEK_TP_I2C_REPORT_ID 0x48 +/* Reverse engineered stylus report on a tested CHUWI Hi10 Max device. */ +#define ILITEK_PEN_I2C_REPORT_ID 0x0C +#define ILITEK_PEN_PRESSURE_MAX 1023 +#define ILITEK_PEN_DISTANCE_MAX 2 +/* Userspace expects tablet axis resolution; with INPUT_PROP_DIRECT this i= s */ +/* mostly descriptive and does not materially affect event coordinates. */ +#define ILITEK_PEN_RESOLUTION 68 + +#define ILITEK_PEN_FLAG_TOUCH 0x01 +#define ILITEK_PEN_FLAG_STYLUS2 0x02 +#define ILITEK_PEN_FLAG_STYLUS 0x08 +#define ILITEK_PEN_FLAG_PROX 0x10 =20 #define REPORT_COUNT_ADDRESS 61 #define ILITEK_SUPPORT_MAX_POINT 40 @@ -50,6 +62,7 @@ struct ilitek_ts_data { struct i2c_client *client; struct gpio_desc *reset_gpio; struct input_dev *input_dev; + struct input_dev *pen_input_dev; struct touchscreen_properties prop; =20 const struct ilitek_protocol_map *ptl_cb_func; @@ -89,6 +102,9 @@ enum ilitek_cmds { MAX_CMD_CNT }; =20 +static int ilitek_pen_input_dev_init(struct device *dev, + struct ilitek_ts_data *ts); + /* ILITEK I2C R/W APIs */ static int ilitek_i2c_write_and_read(struct ilitek_ts_data *ts, u8 *cmd, int write_len, int delay, @@ -146,6 +162,54 @@ static void ilitek_touch_down(struct ilitek_ts_data *t= s, unsigned int id, touchscreen_report_pos(input, &ts->prop, x, y, true); } =20 +/* + * buf[1] carries prox/touch/side-button state and buf[6..7] carries + * pressure. A right shift by one matches the observed 1024 pressure level= s. + */ +static int ilitek_process_pen_report(struct ilitek_ts_data *ts, u8 *buf) +{ + struct device *dev =3D &ts->client->dev; + struct input_dev *input =3D ts->pen_input_dev; + unsigned int x, y, z, distance; + bool prox, touch, stylus, stylus2; + int error; + + if (!input) { + error =3D ilitek_pen_input_dev_init(dev, ts); + if (error) { + dev_err_ratelimited(dev, + "failed to register pen input device: %d\n", + error); + return 0; + } + input =3D ts->pen_input_dev; + } + + x =3D get_unaligned_le16(buf + 2); + y =3D get_unaligned_le16(buf + 4); + z =3D get_unaligned_le16(buf + 6) >> 1; + prox =3D !!(buf[1] & ILITEK_PEN_FLAG_PROX); + touch =3D !!(buf[1] & ILITEK_PEN_FLAG_TOUCH); + stylus =3D !!(buf[1] & ILITEK_PEN_FLAG_STYLUS); + stylus2 =3D !!(buf[1] & ILITEK_PEN_FLAG_STYLUS2); + distance =3D prox ? (touch ? 0 : 1) : ILITEK_PEN_DISTANCE_MAX; + if (!touch) + z =3D 0; + else if (z > ILITEK_PEN_PRESSURE_MAX) + z =3D ILITEK_PEN_PRESSURE_MAX; + + input_report_key(input, BTN_TOOL_PEN, prox || touch); + input_report_key(input, BTN_TOUCH, touch); + input_report_key(input, BTN_STYLUS, stylus); + input_report_key(input, BTN_STYLUS2, stylus2); + touchscreen_report_pos(input, &ts->prop, x, y, false); + input_report_abs(input, ABS_PRESSURE, z); + input_report_abs(input, ABS_DISTANCE, distance); + input_sync(input); + + return 0; +} + static int ilitek_process_and_report_v6(struct ilitek_ts_data *ts) { int error =3D 0; @@ -164,6 +228,9 @@ static int ilitek_process_and_report_v6(struct ilitek_t= s_data *ts) return error; } =20 + if (buf[0] =3D=3D ILITEK_PEN_I2C_REPORT_ID) + return ilitek_process_pen_report(ts, buf); + if (buf[0] !=3D ILITEK_TP_I2C_REPORT_ID) { dev_err(dev, "get touch info failed. Wrong id: 0x%02X\n", buf[0]); return -EINVAL; @@ -459,6 +526,58 @@ static int ilitek_read_tp_info(struct ilitek_ts_data *= ts, bool boot) return 0; } =20 +static int ilitek_pen_input_dev_init(struct device *dev, struct ilitek_ts_= data *ts) +{ + struct input_dev *pen_input; + int error; + + if (ts->pen_input_dev) + return 0; + + /* No explicit pen capability probe is known; create on first pen report.= */ + + pen_input =3D input_allocate_device(); + if (!pen_input) + return -ENOMEM; + + ts->pen_input_dev =3D pen_input; + pen_input->dev.parent =3D dev; + pen_input->name =3D "ilitek_ts_pen"; + pen_input->id.bustype =3D BUS_I2C; + + __set_bit(INPUT_PROP_DIRECT, pen_input->propbit); + input_set_capability(pen_input, EV_KEY, BTN_TOUCH); + input_set_capability(pen_input, EV_KEY, BTN_TOOL_PEN); + input_set_capability(pen_input, EV_KEY, BTN_STYLUS); + input_set_capability(pen_input, EV_KEY, BTN_STYLUS2); + + input_set_abs_params(pen_input, ABS_X, + input_abs_get_min(ts->input_dev, ABS_MT_POSITION_X), + input_abs_get_max(ts->input_dev, ABS_MT_POSITION_X), + 0, 0); + input_set_abs_params(pen_input, ABS_Y, + input_abs_get_min(ts->input_dev, ABS_MT_POSITION_Y), + input_abs_get_max(ts->input_dev, ABS_MT_POSITION_Y), + 0, 0); + input_set_abs_params(pen_input, ABS_PRESSURE, 0, + ILITEK_PEN_PRESSURE_MAX, 0, 0); + input_set_abs_params(pen_input, ABS_DISTANCE, 0, + ILITEK_PEN_DISTANCE_MAX, 0, 0); + input_abs_set_res(pen_input, ABS_X, ILITEK_PEN_RESOLUTION); + input_abs_set_res(pen_input, ABS_Y, ILITEK_PEN_RESOLUTION); + + error =3D input_register_device(pen_input); + if (error) + goto err_free_pen_input; + + return 0; + +err_free_pen_input: + ts->pen_input_dev =3D NULL; + input_free_device(pen_input); + return error; +} + static int ilitek_input_dev_init(struct device *dev, struct ilitek_ts_data= *ts) { int error; @@ -589,9 +708,8 @@ static int ilitek_ts_i2c_probe(struct i2c_client *clien= t) return error; } =20 - error =3D devm_request_threaded_irq(dev, ts->client->irq, - NULL, ilitek_i2c_isr, IRQF_ONESHOT, - "ilitek_touch_irq", ts); + error =3D request_threaded_irq(ts->client->irq, NULL, ilitek_i2c_isr, + IRQF_ONESHOT, "ilitek_touch_irq", ts); if (error) { dev_err(dev, "request threaded irq failed: %d\n", error); return error; @@ -600,6 +718,18 @@ static int ilitek_ts_i2c_probe(struct i2c_client *clie= nt) return 0; } =20 +static void ilitek_ts_i2c_remove(struct i2c_client *client) +{ + struct ilitek_ts_data *ts =3D i2c_get_clientdata(client); + + free_irq(client->irq, ts); + + if (ts->pen_input_dev) { + input_unregister_device(ts->pen_input_dev); + ts->pen_input_dev =3D NULL; + } +} + static int ilitek_suspend(struct device *dev) { struct i2c_client *client =3D to_i2c_client(dev); @@ -677,6 +807,7 @@ static struct i2c_driver ilitek_ts_i2c_driver =3D { .acpi_match_table =3D ACPI_PTR(ilitekts_acpi_id), }, .probe =3D ilitek_ts_i2c_probe, + .remove =3D ilitek_ts_i2c_remove, .id_table =3D ilitek_ts_i2c_id, }; module_i2c_driver(ilitek_ts_i2c_driver); --=20 2.54.0 From nobody Fri Jul 24 05:21:38 2026 Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3BB9F45D197 for ; Thu, 23 Jul 2026 15:23:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784820213; cv=none; b=Kz5NdMqHN8jZFXggMcvzr1PpZcFo/tOPT8OSKOZ7jQ9arluwL4zi+6m1ZWj/jtXWrc46iWuE6qEY49pfhxhNl06toLEA2coc94FrLo7unoqfOr87ys6Lu21Q8Wcvwdv41bfbvgsa/eWieVxDy/mXG2QXVoDrZoOCrNOrMklXt1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784820213; c=relaxed/simple; bh=EHwnDfpKTHBKLjDbOg7K1zPk+bXLu9KD+RIz9v6ndpU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LRMldcI45ppaySYIjFhDzhH0x2DxFHQElSeTriva9Icoav1A1N+hgtyC/wXX4qzsYuKQtx30atBrY8EA2NP0+2x7BP7Mw33QLMmgMghvAtnLlisQI1okBv8z51T90b++P8aNfVBSXAgjjyHreL1dr2Wnpmg+slpcVi1BgbGt8aU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mide.dk; spf=none smtp.mailfrom=mide.dk; dkim=pass (2048-bit key) header.d=mide-dk.20251104.gappssmtp.com header.i=@mide-dk.20251104.gappssmtp.com header.b=mVp2XUGF; arc=none smtp.client-ip=209.85.218.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mide.dk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=mide.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mide-dk.20251104.gappssmtp.com header.i=@mide-dk.20251104.gappssmtp.com header.b="mVp2XUGF" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-c1691e4ec40so106699566b.3 for ; Thu, 23 Jul 2026 08:23:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mide-dk.20251104.gappssmtp.com; s=20251104; t=1784820208; x=1785425008; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xCeah5PtaC40w3m+OfjkHtjZGFO19xRp2kS9i0vWTUw=; b=mVp2XUGFv1NFknNCn4OSAbQnAR5Pk8yMSabtXk0GJ+8C56m3pa2hc/vHl8kVVF18bt OPQDybw8s9nDm7apHdvbhjEYq+EIHEY7KUpFzoMGXmxtOCZRiOn5iMAocbEZkOGvNVVB o8T0BJ/kfIlhbdNYWp9hhJfHh9Z12IAcvx+53QAKH40lQo+9Y+KGAbDjnZldBObUJK6w JLwZ8sSyMOyTelca7rdOfQefyB0nHSb95oDQVNpTvLOdfShPjaLWLh0IhmdQStwuBVu0 ArKK8tcGedvBUIftDLXlqZ8vLpKqu7V+rmadcvxYLFNbxilVxGR9p5EAsAtyg9fbZM6G TiUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784820208; x=1785425008; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=xCeah5PtaC40w3m+OfjkHtjZGFO19xRp2kS9i0vWTUw=; b=s36FiwtM0FvpBejHYeAUq5ijKW5v1Pio7FwAM9K1xgIIKvTRCGT17s1QgdJFffEOM4 CtOGUwg7D2uVROHm21QWzLc7Wo9wY0T0qgyHrayLTMuGC4HBQCqtViiwVgHxz/xLv42Z S7neaz5gKFqoMMlv9ANoGhRBtPTI/vuWsw9S/8cHLgGyd6jAFZ6Z/uWF1PsWyKniGV8+ 563hCEnRGvnwzWMyI27dNSkQzcgm9KJiDVwsWa/4D9opDlyuxFWWvEBOFZvxVcFDFtpy ohLfvAvDOsEBqysvwvTysrwhCPdTa5+8NtB0H2CnRDQslNc1oSyP3XjT8wSIQcEP7BGO 1FHA== X-Forwarded-Encrypted: i=1; AHgh+RoB8VyJKvCZHxNVGi05AiwuOwKvQPqhLE1T71kek6T4WmBcxIjY+nMYFdLO8iRbTNa/d8J25R8WNwyr65Q=@vger.kernel.org X-Gm-Message-State: AOJu0YyfpXTtSJesjwxavwPavRbaBNT506uaTS0lzLS1ubAMf1EdF2Kg TfAwnPHfqvc8UY//6Hsm0lql0LBXzfG3dLQZlMztDCr+IC4KCG8HVn24q+Qk7WqsTA== X-Gm-Gg: AR+sD10MFfQeIkAd+skhaWUsUieSGgTMtxAFwlqLl/vWfAKjCtq1xOOB8b8fddrm/jb vl9fd0MxMRVjCGB1108I9wblpk3rf4xnuLmVv/EItp+xc4mOyno145738hd9tLzqqhwxrWQGHW/ tT/5TuoURQfzgwo2onEey9DNVsJg6MFOk7SEA/zmalzSLb361Ep/W7PE6smgKS/V51645wmoUlO dFNxIMzwNSv56P80Qgfvv0IAkn/hjIGcBDZhQFNZCMxrHUsWJFX4hTmiM11oHn0Syk117XogbLh xhqAyu8ZsODuUODIz5lYXdavxW6AfVRncMoQZaMfONfQ8Cv/04kwSkA3+xi1XnuZr4siqBB2AUa XYf7YDzDHYEU/5BvZRFpb+e1ietYtR6mlrMpU32o0pJVYPyfEprRGZRGqjOGqh+z4+TyQ2v+EIu 8S2/XMROGTEz7X9Q6Ycu8wJ8wCzT/ZQbdqsKHqGSCWVZcuZryCkKScqN74E3Wvx/u+S+niMOhvp GPH/2VNlFAuVULF+nS5sea0m0A+hEIozLoASEIF23tMSjkAuNA5 X-Received: by 2002:a17:907:741:b0:c12:4c93:852b with SMTP id a640c23a62f3a-c1c50b42321mr166886666b.13.1784820207907; Thu, 23 Jul 2026 08:23:27 -0700 (PDT) Received: from localhost.localdomain (2a06.4004.215b.0000.2aa0.6bff.feb3.5b8c.static6.kviknet.net. [2a06:4004:215b:0:2aa0:6bff:feb3:5b8c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1c32ebb385sm250749666b.52.2026.07.23.08.23.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 08:23:27 -0700 (PDT) From: Kristian Mide To: dmitry.torokhov@gmail.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Kristian Mide Subject: [PATCH v3 2/3] Input: ilitek_ts: handle short I2C transfers Date: Thu, 23 Jul 2026 17:22:43 +0200 Message-ID: <20260723152244.11252-3-kristian@mide.dk> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260723152244.11252-1-kristian@mide.dk> References: <20260709182602.7308-1-kristian@mide.dk> <20260723152244.11252-1-kristian@mide.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Check that i2c_transfer() returns the expected number of messages in ilitek_i2c_write_and_read(). Short transfers were previously treated as success, allowing callers to continue with partially filled buffers. In the report path that can expose uninitialized stack data through debugging output and can also confuse packet parsing. Signed-off-by: Kristian Mide --- drivers/input/touchscreen/ilitek_ts_i2c.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/input/touchscreen/ilitek_ts_i2c.c b/drivers/input/touc= hscreen/ilitek_ts_i2c.c index 86975fa9a..a184d024d 100644 --- a/drivers/input/touchscreen/ilitek_ts_i2c.c +++ b/drivers/input/touchscreen/ilitek_ts_i2c.c @@ -131,11 +131,15 @@ static int ilitek_i2c_write_and_read(struct ilitek_ts= _data *ts, error =3D i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); if (error < 0) return error; + if (error !=3D ARRAY_SIZE(msgs)) + return -EIO; } else { if (write_len > 0) { error =3D i2c_transfer(client->adapter, msgs, 1); if (error < 0) return error; + if (error !=3D 1) + return -EIO; } if (delay > 0) fsleep(delay * 1000); @@ -144,6 +148,8 @@ static int ilitek_i2c_write_and_read(struct ilitek_ts_d= ata *ts, error =3D i2c_transfer(client->adapter, msgs + 1, 1); if (error < 0) return error; + if (error !=3D 1) + return -EIO; } } =20 --=20 2.54.0 From nobody Fri Jul 24 05:21:38 2026 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2A2F45D185 for ; Thu, 23 Jul 2026 15:23:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784820217; cv=none; b=RaCfgP9t9/kNyt2h15BfuK+TrGxO2fBvv/W42U/wjPc3LN2Ybr0mDs4a7lEtNtr8E+w2u6lUod+4MRiDLNStEpeBTkFol+l546GqTlISCo4WGUCNR19Z8M8CaDmayVuN4hBZVuqGWYgr3Va9rm0fgME44pA7weQhJg8+EmufaxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784820217; c=relaxed/simple; bh=3+mLGmb+xo+Y7FWnjPd6Bk5tOhqzEHPjo9ocA5cAeR8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kj55acrADzpy+CFAl+bhCO9MZFAObHYxFDUyKbxElQI3WJiSolIiPfX6j16Yz5wV3fnwQHuOKfNLuHYWIFxYihZkAK2E7zjRw/m5RKn8gMe/dUR4L6C6D/QrRfcIeiI1IR+Ed/0atasQGWK8IhnJ79UNJFL5vHZt5SRomkJDK9I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mide.dk; spf=none smtp.mailfrom=mide.dk; dkim=pass (2048-bit key) header.d=mide-dk.20251104.gappssmtp.com header.i=@mide-dk.20251104.gappssmtp.com header.b=nWxR9koJ; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=mide.dk Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=mide.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mide-dk.20251104.gappssmtp.com header.i=@mide-dk.20251104.gappssmtp.com header.b="nWxR9koJ" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-c15e592da74so96180266b.1 for ; Thu, 23 Jul 2026 08:23:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mide-dk.20251104.gappssmtp.com; s=20251104; t=1784820210; x=1785425010; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=OYlmrDRiIg93kPdC5KGJzikRrWWC1NJtz0hg41SezaM=; b=nWxR9koJQabmO9NIM5I45hzDIzoPU6L962Wo6OO7UVVqTNIesvjlJAwiGIyMTvhNr9 lBUjDyrVZRerecOjeTDt413DTqsja3wjVHqHj1ngkR2rbmQXdAW6eyYB2EP9Gq/33g76 C71o0gAw0soY6ssTOHMRHp6OlzmCSsCnRJsV6IJE7KF0s5zA0v9R9xURMNm7QNgaVDpC p32e6L11LLh6hKCHAxIaaNJ1h15STO69SgNI7J01R+RDRe4oDsSw6dZsRaA46cbXkMla x7YQMVH7VQ+AoziEDLQNYXNhpiI3KYVKzTIOJ5rZWS3+RGEUpHfjgq4ay2vCmWhEC574 9HFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784820210; x=1785425010; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=OYlmrDRiIg93kPdC5KGJzikRrWWC1NJtz0hg41SezaM=; b=YYkn7laRsLGG7XY5dx4zf/jQjL6FtsNYRcIqLukMhdaeQRJ2eDuXQltaWrd6QMYk8B iMxKhWY9dgWuQpl+9Dh9nFsC2UkkbOezMBf40XpJ9tuM2klogT3TuW+NMvZgFdpD5kQf nOHnY8D2TMr7NjbuXywauztx26nSPIcFKwv1G31MtTVec0vXNpSM1kjPNkbMItiO0kNO zyGRl6+vwKBuKQUK3Gu9vkCM+RAxg71GlIwTCOns4wOHKTuJMlVhccGXMsyzR8NPdE6z FoaiPFyWzPkFrN2crFUmybZkTumouqQF9QWPQfpwZaN2F54Qga9DReRrq78x6ng8OCdG C/DQ== X-Forwarded-Encrypted: i=1; AHgh+Ro1YgXhtJq2WZwEJ1CRakmYUXkCFUl+MdNejSiwegGqjPRXsjLKnx3aXMEV+m74czv0zwSNWhjhI74gXWE=@vger.kernel.org X-Gm-Message-State: AOJu0YyKr14+uYS8Q4LmZDuzB52fFhW4+DMwVgnH0Zk2p06RHP20/gQx /nonqhETrY+21w9rsNNJvBTyC6b3o7PxhGgDuKjKSP0nIpP5V9dlIHul7EfQXGuoKQ== X-Gm-Gg: AR+sD12QOQjn3MpfGCHUjAPsrlMw95wuwUKH92rK/Kg0Xz35Jl5wDUX4GKVnXcb5kCY pgfh7+V7Xp6CHsxhCNmNwSCi0icwsYo+r3PRYv3dk23fOH5idS+gZDZHGSaC4ciK89arNkrJUJO 6KDc2BGJMV1IIU2lKleUdCWx0Puxui4bfVqKpHC1QimJ1VOoU8crVlarBOHnCltudVRjqUrmRNk qYHVjHwO9yrR14L61bQDQ2nc6bcs1aGEn7kTWwoRpH9E9Vy2/laY15UMsnQ84BgsChsMp3JBC73 KB1FCyuFMpJoVqnftL0HptgxtLNU+II0yLHc8CclvABfnBlHJAwpIhNzyn0xn0dC7cT5vVkihza oTC78YuEVk8N/sUbTtxlWUrrI7ZDTGwcbsn2/e22RoFBXQ7kYPGGnl68qv0TW3o5i7I3A/jwWGd MvvC5LmFgnkCOWzk3LcDpKeS8QKdYihuJv/FbtKssP8OD445TL+gebsgpMOd1pka3t/UpLqLMDj WUmsL9tZ1EKc7sm0J2+6dVBM0/BsXcmWpCQSSq2sQ== X-Received: by 2002:a17:907:3d46:b0:c15:b67b:523e with SMTP id a640c23a62f3a-c1c5092ecdfmr168445266b.19.1784820209846; Thu, 23 Jul 2026 08:23:29 -0700 (PDT) Received: from localhost.localdomain (2a06.4004.215b.0000.2aa0.6bff.feb3.5b8c.static6.kviknet.net. [2a06:4004:215b:0:2aa0:6bff:feb3:5b8c]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1c32ebb385sm250749666b.52.2026.07.23.08.23.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 08:23:29 -0700 (PDT) From: Kristian Mide To: dmitry.torokhov@gmail.com Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Kristian Mide Subject: [PATCH v3 3/3] Input: ilitek_ts: ratelimit unexpected report logging Date: Thu, 23 Jul 2026 17:22:44 +0200 Message-ID: <20260723152244.11252-4-kristian@mide.dk> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260723152244.11252-1-kristian@mide.dk> References: <20260709182602.7308-1-kristian@mide.dk> <20260723152244.11252-1-kristian@mide.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Unexpected report IDs can repeat quickly when the controller emits unknown packets. Use dev_err_ratelimited() and include the first 16 bytes of the raw packet to keep dmesg usable while preserving enough context for debugging. Return success after logging the unexpected report ID so the IRQ handler does not emit a second unratelimited error for the same condition. Signed-off-by: Kristian Mide --- drivers/input/touchscreen/ilitek_ts_i2c.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/input/touchscreen/ilitek_ts_i2c.c b/drivers/input/touc= hscreen/ilitek_ts_i2c.c index a184d024d..2f1741d77 100644 --- a/drivers/input/touchscreen/ilitek_ts_i2c.c +++ b/drivers/input/touchscreen/ilitek_ts_i2c.c @@ -238,8 +238,10 @@ static int ilitek_process_and_report_v6(struct ilitek_= ts_data *ts) return ilitek_process_pen_report(ts, buf); =20 if (buf[0] !=3D ILITEK_TP_I2C_REPORT_ID) { - dev_err(dev, "get touch info failed. Wrong id: 0x%02X\n", buf[0]); - return -EINVAL; + dev_err_ratelimited(dev, + "get touch info failed. Wrong id: 0x%02X raw[0:16]=3D%*ph\n", + buf[0], 16, buf); + return 0; } =20 report_max_point =3D buf[REPORT_COUNT_ADDRESS]; --=20 2.54.0