mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Emfox Zhou <emfox@debian.org>
To: Even Xu <even.xu@intel.com>, Xinpeng Sun <xinpeng.sun@intel.com>,
	Jiri Kosina <jikos@kernel.org>,
	Benjamin Tissoires <bentiss@kernel.org>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v10 1/6] HID: intel-thc-hid: intel-thc: expose the operations an IPTS port needs
Date: Fri, 27 Nov 2026 23:51:35 +0800	[thread overview]
Message-ID: <306c05c7d1ddc7f96fd6d3aafb5d6645d04406ed.1795794049.git.emfox@debian.org> (raw)
In-Reply-To: <cover.1795794049.git.emfox@debian.org>

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@debian.org>
---
 .../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;
-	}
-
-	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);
+}
+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");
+
 #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");
+
 /**
  * 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,

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

Thread overview: 7+ 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 ` Emfox Zhou [this message]
2026-11-27 15:51 ` [PATCH v10 2/6] HID: intel-thc-hid: intel-ipts: bring up the port Emfox Zhou
2026-11-27 15:51 ` [PATCH v10 3/6] HID: intel-thc-hid: intel-ipts: receive reports Emfox Zhou
2026-11-27 15:51 ` [PATCH v10 4/6] HID: intel-thc-hid: intel-ipts: add the HID device Emfox Zhou
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=306c05c7d1ddc7f96fd6d3aafb5d6645d04406ed.1795794049.git.emfox@debian.org \
    --to=emfox@debian.org \
    --cc=bentiss@kernel.org \
    --cc=even.xu@intel.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=xinpeng.sun@intel.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®