[PATCH v11 1/6] HID: intel-thc-hid: intel-thc: expose the port operations IPTS needs

From: Emfox Zhou

Date: Wed Dec 02 2026 - 21:04:52 EST


Add thc_port_supported() and thc_port_reset(), so a backend can read the
port capability bit and drive the touch controller reset pin without
writing THC_M_PRT_CONTROL itself.

Signed-off-by: Emfox Zhou <emfox@xxxxxxxxxx>
---
.../intel-thc-hid/intel-thc/intel-thc-dev.c | 58 +++++++++++++++++++
.../intel-thc-hid/intel-thc/intel-thc-dev.h | 2 +
2 files changed, 60 insertions(+)

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..c7d495915 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
@@ -1111,6 +1111,64 @@ int thc_port_select(struct thc_device *dev, enum thc_port_type port_type)
}
EXPORT_SYMBOL_NS_GPL(thc_port_select, "INTEL_THC");

+/**
+ * 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 - Drive the reset line of the touch IC
+ *
+ * @dev: the pointer of THC private device context
+ * @hold: keep the touch IC in reset instead of releasing it
+ *
+ * The reset bit of the port control register drives the reset pin of the
+ * touch IC: zero asserts the reset, one releases it. Firmware may leave
+ * the pin released, so a start asserts it and then lets it go rather than
+ * assume it was held.
+ *
+ * Return: 0 on success, other error codes on failed
+ */
+int thc_port_reset(struct thc_device *dev, bool hold)
+{
+ int ret;
+
+ /* DEVRST: 0 asserts the reset, 1 releases it. */
+ ret = regmap_write_bits(dev->thc_regmap, THC_M_PRT_CONTROL_OFFSET,
+ THC_M_PRT_CONTROL_DEVRST, 0);
+ if (ret || hold)
+ return ret;
+
+ usleep_range(1000, 2000);
+
+ return regmap_write_bits(dev->thc_regmap, THC_M_PRT_CONTROL_OFFSET,
+ THC_M_PRT_CONTROL_DEVRST,
+ THC_M_PRT_CONTROL_DEVRST);
+}
+EXPORT_SYMBOL_NS_GPL(thc_port_reset, "INTEL_THC");
+
/* 125 MHz / (8 * N), with the low frequency bit set. */
#define THC_SPI_FREQUENCY_2M2 2232143
#define THC_SPI_FREQUENCY_2M6 2604167
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..c34611e78 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
@@ -135,6 +135,8 @@ 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_select(struct thc_device *dev, enum thc_port_type port_type);
+int thc_port_reset(struct thc_device *dev, bool hold);
+int thc_port_supported(struct thc_device *dev, bool *supported);
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,