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 4/5] HID: intel-thc-hid: intel-thc: add the slow SPI gears
Date: Mon, 16 Nov 2026 21:31:31 +0800 [thread overview]
Message-ID: <20261116133132.1282020-5-emfox@debian.org> (raw)
In-Reply-To: <20261116133132.1282020-1-emfox@debian.org>
The frequency table stops at 7.8125 MHz, so a device that asks for a
slower clock is rejected with -EINVAL. The divider enum already covers
that range: with the low frequency bit set the divider is multiplied by
eight (see intel-thc-hw.h), which brings DIV_7 down to 2.23 MHz.
Add the five missing gears. The half divider check exempts the new 5.2083
MHz gear, which is already DIV_3 with the eighth divider enabled, so the
extra half divider would land on top of it. The 10.4167 MHz gear is low
frequency as well but keeps the half divider; it is not part of this
change.
The read and write configuration carried identical copies of that check,
so move it to thc_spi_needs_half_div().
Signed-off-by: Emfox Zhou <emfox@debian.org>
---
.../intel-thc-hid/intel-thc/intel-thc-dev.c | 43 +++++++++++++++----
1 file changed, 35 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 7429f851c..e9c3462e6 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,12 @@ int thc_port_select(struct thc_device *dev, enum thc_port_type port_type)
}
EXPORT_SYMBOL_NS_GPL(thc_port_select, "INTEL_THC");
+/* 125 MHz / (8 * N), with the low frequency bit set. */
+#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
#define THC_SPI_FREQUENCY_7M 7812500
#define THC_SPI_FREQUENCY_10M 10416700
#define THC_SPI_FREQUENCY_15M 15625000
@@ -1127,6 +1133,11 @@ EXPORT_SYMBOL_NS_GPL(thc_port_select, "INTEL_THC");
static u8 thc_get_spi_freq_div_val(struct thc_device *dev, u32 spi_freq_val)
{
static const int frequency[] = {
+ THC_SPI_FREQUENCY_2M2,
+ THC_SPI_FREQUENCY_2M6,
+ THC_SPI_FREQUENCY_3M1,
+ THC_SPI_FREQUENCY_3M9,
+ THC_SPI_FREQUENCY_5M2,
THC_SPI_FREQUENCY_7M,
THC_SPI_FREQUENCY_10M,
THC_SPI_FREQUENCY_15M,
@@ -1139,6 +1150,11 @@ static u8 thc_get_spi_freq_div_val(struct thc_device *dev, u32 spi_freq_val)
THC_SPI_FREQUENCY_50M,
};
static const u8 frequency_div[] = {
+ THC_SPI_FRQ_DIV_7,
+ THC_SPI_FRQ_DIV_6,
+ THC_SPI_FRQ_DIV_5,
+ THC_SPI_FRQ_DIV_4,
+ THC_SPI_FRQ_DIV_3,
THC_SPI_FRQ_DIV_2,
THC_SPI_FRQ_DIV_1,
THC_SPI_FRQ_DIV_1,
@@ -1174,6 +1190,23 @@ static u8 thc_get_spi_freq_div_val(struct thc_device *dev, u32 spi_freq_val)
return freq_div;
}
+/*
+ * 10M, 35M and 50M take the half divider; 5.2083 MHz is already DIV_3, and
+ * 10.4167 MHz keeps it.
+ */
+static bool thc_spi_needs_half_div(u8 freq_div, u32 spi_freq_val,
+ bool is_low_freq)
+{
+ if (freq_div == THC_SPI_FRQ_DIV_2)
+ return spi_freq_val >= THC_SPI_FREQUENCY_50M;
+
+ if (freq_div == THC_SPI_FRQ_DIV_3)
+ return spi_freq_val < THC_SPI_FREQUENCY_41M && !is_low_freq;
+
+ return freq_div == THC_SPI_FRQ_DIV_1 &&
+ spi_freq_val < THC_SPI_FREQUENCY_15M;
+}
+
/**
* thc_spi_read_config - Configure SPI bus read attributes
*
@@ -1199,10 +1232,7 @@ int thc_spi_read_config(struct thc_device *dev, u32 spi_freq_val,
if (spi_freq_val < THC_SPI_LOW_FREQUENCY)
is_low_freq = true;
- /* 10M, 35M and 50M CLK need 1.5, 3.5 and 2.5 half divider */
- if ((freq_div == THC_SPI_FRQ_DIV_2 && spi_freq_val >= THC_SPI_FREQUENCY_50M) ||
- (freq_div == THC_SPI_FRQ_DIV_3 && spi_freq_val < THC_SPI_FREQUENCY_41M) ||
- (freq_div == THC_SPI_FRQ_DIV_1 && spi_freq_val < THC_SPI_FREQUENCY_15M)) {
+ if (thc_spi_needs_half_div(freq_div, spi_freq_val, is_low_freq)) {
regmap_write_bits(dev->thc_regmap, THC_M_PRT_SPI_DUTYC_CFG_OFFSET,
THC_M_PRT_SPI_DUTYC_CFG_SPI_TCRF_HALF_DIV_EN,
THC_M_PRT_SPI_DUTYC_CFG_SPI_TCRF_HALF_DIV_EN);
@@ -1271,10 +1301,7 @@ int thc_spi_write_config(struct thc_device *dev, u32 spi_freq_val,
if (spi_freq_val < THC_SPI_LOW_FREQUENCY)
is_low_freq = true;
- /* 10M, 35M and 50M CLK need 1.5, 3.5 and 2.5 half divider */
- if ((freq_div == THC_SPI_FRQ_DIV_2 && spi_freq_val >= THC_SPI_FREQUENCY_50M) ||
- (freq_div == THC_SPI_FRQ_DIV_3 && spi_freq_val < THC_SPI_FREQUENCY_41M) ||
- (freq_div == THC_SPI_FRQ_DIV_1 && spi_freq_val < THC_SPI_FREQUENCY_15M)) {
+ if (thc_spi_needs_half_div(freq_div, spi_freq_val, is_low_freq)) {
regmap_write_bits(dev->thc_regmap, THC_M_PRT_SPI_DUTYC_CFG_OFFSET,
THC_M_PRT_SPI_DUTYC_CFG_SPI_TCWF_HALF_DIV_EN,
THC_M_PRT_SPI_DUTYC_CFG_SPI_TCWF_HALF_DIV_EN);
next prev parent reply other threads:[~2026-11-16 13:32 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 13:31 [PATCH 0/5] HID: intel-thc-hid: intel-thc: DMA lifetime fixes Emfox Zhou
2026-11-16 13:31 ` [PATCH 1/5] HID: intel-thc-hid: intel-thc: keep TxDMA write errors Emfox Zhou
2026-11-16 13:31 ` [PATCH 2/5] HID: intel-thc-hid: intel-thc: free the failed channel Emfox Zhou
2026-11-16 13:31 ` [PATCH 3/5] HID: intel-thc-hid: intel-thc: stop all engines first Emfox Zhou
2026-11-16 13:31 ` Emfox Zhou [this message]
2026-11-16 13:31 ` [PATCH 5/5] HID: intel-thc-hid: intel-thc: budget the receive drain 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=20261116133132.1282020-5-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®