RE: [PATCH v10 1/6] HID: intel-thc-hid: intel-thc: expose the operations an IPTS port needs
From: Xu, Even
Date: Wed Dec 02 2026 - 01:21:30 EST
> -----Original Message-----
> From: Emfox Zhou <emfox@xxxxxxxxxx>
> Sent: Friday, November 27, 2026 11:52 PM
> To: Xu, Even <even.xu@xxxxxxxxx>; Sun, Xinpeng <xinpeng.sun@xxxxxxxxx>; Jiri
> Kosina <jikos@xxxxxxxxxx>; Benjamin Tissoires <bentiss@xxxxxxxxxx>
> Cc: linux-input@xxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx
> Subject: [PATCH v10 1/6] HID: intel-thc-hid: intel-thc: expose the operations an
> IPTS port needs
>
> The IPTS backend sits on the same core but cannot reach everything it needs
> through it: it writes the reset and port-supported bits of THC_M_PRT_CONTROL
> itself, and keeps a copy of the SPI base clock to turn the divisor in the
> configuration block into a frequency it can ask for.
>
> Add the calls for those:
>
> - thc_port_supported() reads the capability bit. A port with nothing
> behind it answers nothing on the bus, so the question is worth asking
> before the port is brought up.
>
> - thc_port_reset_release() and thc_port_reset_hold() write the reset
> bit. It is the reset request, and reads as one while the port is out
> of reset, so it is written and never read-modify-written: the port
> has to be told either way, whatever the bit reads back.
>
> - thc_spi_hz_from_div() applies the base clock the gears are fractions
> of to a divisor a device reports. Keeping it next to the gear table
> is the point: a frequency computed from another base lands on the
> wrong gear, and the table compares rounded to 100 Hz, so this has to
> round the same way or divisor 3 falls just short of the 41 MHz gear.
>
> thc_interrupt_quiesce() also stops warning when the port is already in the state
> that was asked for. Every bring-up and teardown path calls it on both ends, so
> being idle at either end is the normal case, and the warning says nothing the caller
> can act on.
>
> No existing signature changes, and nothing else changes for the two modes
> already in tree; they can move over to the new calls later.
>
> Signed-off-by: Emfox Zhou <emfox@xxxxxxxxxx>
> ---
> .../intel-thc-hid/intel-thc/intel-thc-dev.c | 107 ++++++++++++++++--
> .../intel-thc-hid/intel-thc/intel-thc-dev.h | 4 +
> 2 files changed, 103 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c b/drivers/hid/intel-
> thc-hid/intel-thc/intel-thc-dev.c
> index 03d3b60b3..d98c450c2 100644
> --- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c
> +++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c
> @@ -642,16 +642,13 @@ int thc_interrupt_quiesce(const struct thc_device
> *dev, bool int_quiesce)
> u32 ctrl;
> int ret;
>
> + /* Every bring-up and teardown path calls this, and a port that is
> + * already in the state that was asked for is the normal case there:
> + * nothing to write, nothing to wait for, nothing to report.
> + */
> regmap_read(dev->thc_regmap, THC_M_PRT_CONTROL_OFFSET, &ctrl);
> - if (!(ctrl & THC_M_PRT_CONTROL_THC_DEVINT_QUIESCE_EN)
> && !int_quiesce) {
> - dev_warn(dev->dev, "THC interrupt already unquiesce\n");
> + if (!!(ctrl & THC_M_PRT_CONTROL_THC_DEVINT_QUIESCE_EN) ==
> int_quiesce)
> return 0;
> - }
It's better to leave a warning log here to notify no quiesce status change this time to avoid something wrong.
> -
> - if ((ctrl & THC_M_PRT_CONTROL_THC_DEVINT_QUIESCE_EN) &&
> int_quiesce) {
> - dev_warn(dev->dev, "THC interrupt already quiesce\n");
> - return 0;
> - }
>
> /* Quiesce device interrupt - Set quiesce bit and waiting for THC HW to
> ACK */
> if (int_quiesce)
> @@ -1117,6 +1114,66 @@ EXPORT_SYMBOL_NS_GPL(thc_port_select,
> "INTEL_THC");
> #define THC_SPI_FREQUENCY_3M1 3125000
> #define THC_SPI_FREQUENCY_3M9 3906250
> #define THC_SPI_FREQUENCY_5M2 5208333
> +/**
> + * thc_port_supported - Tell whether the port has a touch device
> +interface
> + *
> + * @dev: the pointer of THC private device context
> + * @supported: set to whether the port can drive a device at all
> + *
> + * Reads the capability bit of the port control register. A port that
> +is not
> + * supported answers nothing on the bus, so this is worth asking before
> +the
> + * port is brought up.
> + *
> + * Return: 0 on success, other error codes on failed */ int
> +thc_port_supported(struct thc_device *dev, bool *supported) {
> + u32 ctrl;
> + int ret;
> +
> + ret = regmap_read(dev->thc_regmap, THC_M_PRT_CONTROL_OFFSET,
> &ctrl);
> + if (ret)
> + return ret;
> +
> + *supported = ctrl & THC_M_PRT_CONTROL_PORT_SUPPORTED;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_NS_GPL(thc_port_supported, "INTEL_THC");
> +
> +/**
> + * thc_port_reset_release - Take the port out of reset
> + *
> + * @dev: the pointer of THC private device context
> + *
> + * The reset bit of the port control register is the reset request and
> +reads
> + * one when the port is out of reset, so the bit is written and never
> + * read-modify-written: the port has to be told either way.
> + *
> + * Return: 0 on success, other error codes on failed */ int
> +thc_port_reset_release(struct thc_device *dev) {
> + return regmap_write_bits(dev->thc_regmap,
> THC_M_PRT_CONTROL_OFFSET,
> + THC_M_PRT_CONTROL_DEVRST,
> + THC_M_PRT_CONTROL_DEVRST);
This register is used to trigger a reset pin signal which is used to reset touch IC.
In order to avoid confusion, you can chang the name to thc_tic_reset_release().
> +}
> +EXPORT_SYMBOL_NS_GPL(thc_port_reset_release, "INTEL_THC");
> +
> +/**
> + * thc_port_reset_hold - Put the port into reset
> + *
> + * @dev: the pointer of THC private device context
> + *
> + * Return: 0 on success, other error codes on failed */ int
> +thc_port_reset_hold(struct thc_device *dev) {
> + return regmap_write_bits(dev->thc_regmap,
> THC_M_PRT_CONTROL_OFFSET,
> + THC_M_PRT_CONTROL_DEVRST, 0);
> +}
> +EXPORT_SYMBOL_NS_GPL(thc_port_reset_hold, "INTEL_THC");
Also , it can be named to thc_tic_reset_hold().
> +
> #define THC_SPI_FREQUENCY_7M 7812500
> #define THC_SPI_FREQUENCY_10M 10416700
> #define THC_SPI_FREQUENCY_15M 15625000
> @@ -1130,6 +1187,9 @@ EXPORT_SYMBOL_NS_GPL(thc_port_select,
> "INTEL_THC");
>
> #define THC_SPI_LOW_FREQUENCY THC_SPI_FREQUENCY_17M
>
> +/* Every gear above is the base clock divided by an integer. */
> +#define THC_SPI_BASE_HZ 125000000
> +
> static u8 thc_get_spi_freq_div_val(struct thc_device *dev, u32 spi_freq_val) {
> static const int frequency[] = {
> @@ -1207,6 +1267,37 @@ static bool thc_spi_needs_half_div(u8 freq_div, u32
> spi_freq_val,
> spi_freq_val < THC_SPI_FREQUENCY_15M; }
>
> +/**
> + * thc_spi_hz_from_div - Turn a base clock divisor into a bus frequency
> + *
> + * @div: divisor, zero when the device did not provide one
> + * @div8: divide the result by eight as well
> + *
> + * A device that describes its bus timing as a divisor has to come back
> + * through here rather than through a copy of the base clock of its
> +own: the
> + * gears thc_spi_read_config() programs are fractions of that clock,
> +and a
> + * frequency computed from another base lands on the wrong one.
> + *
> + * Return: the frequency in Hz, or 0 for a divisor of zero */
> +u32 thc_spi_hz_from_div(u8 div, bool div8) {
> + u32 hz;
> +
> + if (!div)
> + return 0;
> +
> + hz = THC_SPI_BASE_HZ / div;
> + if (div8)
> + hz /= 8;
> +
> + /* Geared frequencies are compared rounded to 100 Hz: round the same
> + * way here, or divisor 3 lands just below the 41 MHz gear.
> + */
> + return DIV_ROUND_CLOSEST(hz, 100) * 100; }
> +EXPORT_SYMBOL_NS_GPL(thc_spi_hz_from_div, "INTEL_THC");
Is the function real needed?
THC already has frequency to div calculation function.
During initialization, TIC reports the max supported frequency, just calculate to div and configure to register is enough.
> +
> /**
> * thc_spi_read_config - Configure SPI bus read attributes
> *
> diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.h b/drivers/hid/intel-
> thc-hid/intel-thc/intel-thc-dev.h
> index be8a9605d..e766bcef3 100644
> --- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.h
> +++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.h
> @@ -134,7 +134,11 @@ void thc_change_ltr_mode(struct thc_device *dev, u32
> ltr_mode); void thc_ltr_unconfig(struct thc_device *dev);
> u32 thc_int_cause_read(struct thc_device *dev); int
> thc_interrupt_handler(struct thc_device *dev);
> +int thc_port_reset_hold(struct thc_device *dev); int
> +thc_port_reset_release(struct thc_device *dev);
> int thc_port_select(struct thc_device *dev, enum thc_port_type port_type);
> +int thc_port_supported(struct thc_device *dev, bool *supported);
> +u32 thc_spi_hz_from_div(u8 div, bool div8);
> int thc_spi_read_config(struct thc_device *dev, u32 spi_freq_val,
> u32 io_mode, u32 opcode, u32 spi_rd_mps); int
> thc_spi_write_config(struct thc_device *dev, u32 spi_freq_val,