All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Emfox Zhou" <emfox@debian.org>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v10 2/6] HID: intel-thc-hid: intel-ipts: bring up the port
Date: Fri, 27 Nov 2026 16:11:03 +0000	[thread overview]
Message-ID: <sashiko-outbox-237844@kernel.org> (raw)
In-Reply-To: <011c212a1187be630f0106a059adc16ba7540fec.1795794049.git.emfox@debian.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] HID: intel-thc-hid: 100 Hz rounding in thc_spi_hz_from_div()
  misses slow gears
--

commit 9057f6d4695018de027656c79eb1b4c3207e3b0b
Author: Emfox Zhou <emfox@debian.org>

HID: intel-thc-hid: intel-ipts: bring up the port

This commit adds the intel-ipts PCI port driver to initialize Intel Touch
Host Controller ports in IPTS mode, read the controller's configuration
block over PIO, configure SPI timing, and enable the touch engine.

> diff --git a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> new file mode 100644
> index 0000000000000..c680b09265667
> --- /dev/null
> +++ b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
[ ... ]
> +/* The core takes the fastest gear that is not above the request. */
> +static void thc_ipts_spi_from_cfg(struct thc_ipts *idev, u32 *hz, u32 *mode)
> +{
> +	u32 cfg = le32_to_cpu(idev->cfg.spi_cfg);
> +
> +	*hz = thc_spi_hz_from_div(THC_IPTS_SPI_CLKDIV(cfg),
> +				  cfg & THC_IPTS_SPI_CLKDIV8);
> +	if (!*hz) {
> +		dev_warn_once(idev->dev, "controller asks for divisor 0\n");
> +		*hz = THC_IPTS_SPI_MIN_HZ;
> +	}
> +
> +	/*
> +	 * THC_IPTS_SPI_MIN_HZ is the slowest gear the core has, so a lower
> +	 * request would be refused: run at the floor and keep the port.
> +	 */
> +	if (*hz < THC_IPTS_SPI_MIN_HZ) {
> +		dev_warn_once(idev->dev,
> +			      "controller asks for %u Hz, running at %u Hz\n",
> +			      *hz, THC_IPTS_SPI_MIN_HZ);
> +		*hz = THC_IPTS_SPI_MIN_HZ;
> +	}

[Severity: Medium]
Does the 100 Hz rounding in thc_spi_hz_from_div() cause slow SPI gears
with THC_IPTS_SPI_CLKDIV8 set to miss their target frequencies?

thc_spi_hz_from_div() rounds the computed frequency to the nearest 100 Hz,
whereas the low-frequency gear constants in intel-thc-dev.c and
THC_IPTS_SPI_MIN_HZ in ipts.h are specified to 1 Hz precision:

drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c:
    #define THC_SPI_FREQUENCY_2M2	2232143
    #define THC_SPI_FREQUENCY_2M6	2604167
    #define THC_SPI_FREQUENCY_3M1	3125000
    #define THC_SPI_FREQUENCY_3M9	3906250
    #define THC_SPI_FREQUENCY_5M2	5208333

drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c:thc_spi_hz_from_div() {
    ...
	hz = THC_SPI_BASE_HZ / div;
	if (div8)
		hz /= 8;
    ...
	return DIV_ROUND_CLOSEST(hz, 100) * 100;
}

When a controller requests divisor 3 with divide-by-8 enabled,
thc_spi_hz_from_div(3, true) rounds 5208333 down to 5208300.  Because
5208300 is below THC_SPI_FREQUENCY_5M2 (5208333),
thc_get_spi_freq_div_val() falls back to THC_SPI_FREQUENCY_3M9 (3906250
Hz, THC_SPI_FRQ_DIV_4), running the SPI bus 25% slower than requested.

Similarly, when a controller requests the valid slowest hardware gear
(divisor 7 with divide-by-8 enabled), thc_spi_hz_from_div(7, true)
returns 2232100, which is below THC_IPTS_SPI_MIN_HZ (2232143) and
triggers a spurious warning in thc_ipts_spi_from_cfg().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795794049.git.emfox@debian.org?part=2

  reply	other threads:[~2026-11-27 16:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-27 15:51 [PATCH v10 0/6] HID: intel-thc-hid: intel-ipts: support THC IPTS ports Emfox Zhou
2026-11-27 15:51 ` [PATCH v10 1/6] HID: intel-thc-hid: intel-thc: expose the operations an IPTS port needs Emfox Zhou
2026-11-27 16:01   ` sashiko-bot
2026-11-27 15:51 ` [PATCH v10 2/6] HID: intel-thc-hid: intel-ipts: bring up the port Emfox Zhou
2026-11-27 16:11   ` sashiko-bot [this message]
2026-11-27 15:51 ` [PATCH v10 3/6] HID: intel-thc-hid: intel-ipts: receive reports Emfox Zhou
2026-11-27 16:18   ` sashiko-bot
2026-11-27 15:51 ` [PATCH v10 4/6] HID: intel-thc-hid: intel-ipts: add the HID device Emfox Zhou
2026-11-27 16:06   ` sashiko-bot
2026-11-27 15:51 ` [PATCH v10 5/6] HID: intel-thc-hid: intel-ipts: handle system sleep Emfox Zhou
2026-11-27 15:51 ` [PATCH v10 6/6] HID: intel-thc-hid: intel-ipts: document the IPTS mode Emfox Zhou

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=sashiko-outbox-237844@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=emfox@debian.org \
    --cc=linux-input@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.