From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: David Heidelberg <david@ixit.cz>
Cc: Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>, Lee Jones <lee@kernel.org>,
Stephen Boyd <sboyd@kernel.org>,
Bjorn Andersson <andersson@kernel.org>,
Konrad Dybcio <konradybcio@kernel.org>,
Abel Vesa <abelvesa@kernel.org>,
Subbaraman Narayanamurthy
<subbaraman.narayanamurthy@oss.qualcomm.com>,
Kamal Wadhwa <kamal.wadhwa@oss.qualcomm.com>,
Fenglin Wu <fenglin.wu@oss.qualcomm.com>,
Casey Connolly <casey@connolly.tech>,
linux-arm-msm@vger.kernel.org, linux-input@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
mfd@lists.linux.dev, phone-devel@vger.kernel.org
Subject: Re: [PATCH v8 3/9] Input: qcom-pmi8998-haptics - Add Qualcomm PMI8998 haptics driver
Date: Mon, 30 Nov 2026 20:48:44 -0800 [thread overview]
Message-ID: <e2198b0a278df12f939c0264cdf6be2b@gmail.com> (raw)
In-Reply-To: <20261130-qcom-pmi8998-haptics-v8-3-a64ecd72d3bb@ixit.cz>
Hi David,
On Mon, Nov 30, 2026 at 01:13:50AM +0100, David Heidelberg wrote:
> Add a driver for the haptics module in the Qualcomm PMI8998 PMIC, based
> on the downstream qpnp-haptics driver and using the input force-feedback
> framework.
>
> Both linear resonant actuators (LRA) and eccentric rotating mass (ERM)
> motors are supported in direct and 8-sample buffer play modes.
> FF_RUMBLE, FF_CONSTANT, FF_PERIODIC (FF_SINE and FF_CUSTOM) effects and
> FF_GAIN master gain are supported, with requested strength scaled
> linearly between 116 mV and the board's qcom,vmax-microvolt and timed
> effects stopped automatically after replay.length ms. For LRA actuators,
> the module's auto-resonance measurement is polled while driving to track
> resonance drift within the configured variation bounds; ERM actuators
> disable auto-resonance and use the configured sample play rate. Active
> braking and short-circuit fault handling (which shuts down the module if
> shorts persist) are supported. Audio and PWM waveform sources, overdrive
> and multi-set waveforms are not implemented.
>
> PMI8941, PMI8994 and PMI8996 carry a similar block; they can be added
> once tested.
>
> Based on work of Casey Connolly.
>
> Signed-off-by: David Heidelberg <david@ixit.cz>
Thank you for the driver. Please also mention PM660 in the commit
description since the driver adds support for qcom,pm660-haptics.
The biggest issue here is that the driver grew to over 2000 lines mostly
because it uses input_ff_create() and implements its own asynchronous FF
scheduler (effect array, request queue, spinlock, and multiple work
items). Since this hardware has no autonomous effect memory or replay
timer, please switch to input_ff_create_memless() like the other
vibrator drivers in drivers/input/misc/. That gives proper handling of
replay.delay, repeat counts, FF_GAIN, envelopes, and effect combining,
avoids hand-rolling partial FF_SINE and FF_CONSTANT support, and drops
the custom queue and work races (including the work()/erase() race
Sashiko pointed out).
As a heads up, I am looking into reworking the FF core and ff-memless to
better handle suspend, resume, and "slow" (sleepable) memoryless
devices. There is no need to wait on that work, though: a slim driver
built on the existing input_ff_create_memless() with a single
work_struct will be straightforward to adapt once those changes land.
Also, is there an actual userspace consumer for FF_CUSTOM? Right now it
exposes an undocumented driver-private binary format (1 to 8 s16 values
restricted to the signed 8-bit range, and -1/-2 end up encoded as
negative zero 0x80) that is also incompatible with the layout proposed
in qcom-spmi-haptics. Unless something depends on it today, I would drop
FF_CUSTOM from the initial submission and discuss adding it later with a
documented ABI.
Because switching to ff-memless removes roughly half the code, I skipped
most issues inside the custom scheduler. Besides Uwe's comments
(dropping linux/mod_devicetable.h, dropping "=" alignment) and Sashiko's
note on explicit error checks instead of tail returns in multi-failure
functions, a few comments on the parts that will remain are below.
...
> +static int pmi8998_haptics_write(struct pmi8998_haptics *haptics,
> + u16 offset, u8 *val, int len)
> +{
...
> + if (is_secure_addr(addr)) {
...
> + } else {
> + if (len > 1)
> + err = regmap_bulk_write(haptics->regmap, addr, val, len);
> + else
> + err = regmap_write(haptics->regmap, addr, *val);
Please drop pmi8998_haptics_read(), pmi8998_haptics_write(), and
pmi8998_haptics_write_masked() (as well as the trivial single-caller
register wrappers) and call the regmap helpers directly. Seven of the
nine write call sites are single-byte and only two are multi-byte, so
there is no reason for a generic wrapper with a "len > 1" split. The
is_secure_addr() loop here is also dead code since HAP_TEST2_REG is the
only secure register, and logging dev_err() inside the wrappers produces
duplicate (sometimes triple) error prints with the callers. Please also
drop __func__ from dev_err() and dev_dbg() messages.
...
> + if (is_secure_addr(addr)) {
> + err = regmap_write(haptics->regmap,
> + haptics->base + HAP_SEC_ACCESS_REG,
> + HAP_SEC_ACCESS_UNLOCK);
> + if (err < 0) {
> + dev_err(haptics->dev, "Error writing unlock code - err %d\n",
> + err);
> + return err;
> + }
> + }
> +
> + err = regmap_update_bits(haptics->regmap, addr, mask, val);
The parent SPMI regmap uses REGCACHE_NONE and has no native
reg_update_bits() handler, so regmap_update_bits() issues an SPMI read
between unlocking HAP_SEC_ACCESS_REG and writing HAP_TEST2_REG. If the
register already holds the target value, no write occurs and SEC_ACCESS
remains unlocked.
Please replace this with a small helper for HAP_TEST2_REG that reads the
register first, returns early if unchanged, and then writes
HAP_SEC_ACCESS_UNLOCK followed directly by regmap_write().
...
> + /* default from the upstream driver */
s/upstream/downstream/
...
> + /*
> + * The upper nibble of the high byte holds bits [11:8] of the
> + * measured drive period.
> + */
> + rate = ((u32)(buf[1] & 0xf0) << 4) | buf[0];
Use a named GENMASK() and FIELD_GET() here to match the rest of the
driver (and GENMASK(1, 0) for HAP_BRAKE_PAT_MASK).
...
> +static void pmi8998_haptics_auto_res_work(struct work_struct *work)
Sashiko's report about an already-dispatched worker blocked on play_lock
defeating cancel_delayed_work() (including the PM660 hw_auto_res polling
case) is valid and still needs to be addressed after switching to
ff-memless.
...
> + if (!(val & SC_FLAG_BIT)) {
> + haptics->sc_count = 0;
> + return IRQ_HANDLED;
> + }
> +
> + temp = ktime_get();
> + sc_delta_time_us = ktime_us_delta(temp, haptics->last_sc_time);
> + haptics->last_sc_time = temp;
> +
> + if (sc_delta_time_us > SC_COUNT_RST_DELAY_US)
> + haptics->sc_count = 0;
> + else
> + haptics->sc_count++;
> +
> + /* Clear the interrupt flag */
> + val = SC_CLR_BIT;
> + err = pmi8998_haptics_write(haptics, HAP_SC_CLR_REG, &val, 1);
> + if (err < 0)
> + return IRQ_HANDLED;
> +
> + if (haptics->sc_count > SC_MAX_COUNT) {
The binding and DTS specify IRQ_TYPE_EDGE_BOTH for the "short"
interrupt. Since handle_edge_irq() does not keep the line masked while
the threaded handler runs, does clearing SC_FLAG_BIT via HAP_SC_CLR_REG
trigger a falling edge where !(val & SC_FLAG_BIT) resets sc_count back
to 0? Also, why reset sc_count here (or use IRQ_TYPE_EDGE_BOTH instead
of IRQ_TYPE_EDGE_RISING) when the 1-second timeout already clears it?
Also:
- Returning early when the HAP_SC_CLR_REG write fails skips the
sc_count > SC_MAX_COUNT shutdown check.
- Starting at sc_count = 0 on the first fault and checking ">" against
SC_MAX_COUNT (5) means it takes 7 faults to shut down rather than 5.
- Once perm_disable is latched and logged with dev_crit(), please do not
emit an unratelimited dev_err() on every subsequent playback request
from userspace.
...
> + haptics = devm_kzalloc(dev, sizeof(*haptics), GFP_KERNEL);
Use devm_kzalloc_obj(dev, *haptics).
...
> + haptics->sc_irq = platform_get_irq_byname(pdev, "short");
> + if (haptics->sc_irq < 0)
> + return dev_err_probe(dev, haptics->sc_irq,
> + "Failed to get short-circuit IRQ\n");
platform_get_irq_byname() already logs via dev_err_probe(), so just
return the error directly. This can also be a local variable since
haptics->sc_irq is unused outside probe().
> +
> + haptics->vmax = haptics->vmax_limit;
> + for (int i = 0; i < HAP_WAVE_SAMP_LEN; i++)
> + haptics->wave_samp[i] = HAP_WF_SAMP_MAX;
haptics->wave_samp is overwritten in pmi8998_haptics_start_buffer()
anyway (and can use memset() where initialization is actually needed).
Also, probe() can be shortened quite a bit by factoring DT parsing out
and sharing helpers for the repeated power-of-2 repeat counts, variation
percentage properties, and play-rate bounds check.
...
> + err = devm_add_action_or_reset(dev, pmi8998_haptics_teardown, haptics);
This looks redundant with input_dev->close, which input core already
calls on input_unregister_device() if the device is open.
...
> +static int pmi8998_haptics_suspend(struct device *dev)
Suspend and resume should take input_dev->mutex to serialize with open
and close (and note that in the current code upload_effect() can still
restart hardware without going through the disabled works).
...
> +static void pmi8998_haptics_shutdown(struct platform_device *pdev)
> +{
> + struct pmi8998_haptics *haptics = platform_get_drvdata(pdev);
> +
> + pmi8998_haptics_stop_all(haptics);
> +}
Agree with Uwe on checking whether shutdown() is really needed. If a
reboot can leave the actuator running, please document why and use
disable_work_sync() / disable_delayed_work_sync() instead of
cancel_work_sync(), since the input device is still registered here.
A few general cleanups for the next version:
- Drop unused code and definitions: HAP_PAUSE / HAP_PAUSE_BIT,
HAP_ILIM_SEL_400_MA, HAP_ILIM_SEL_800_MA, HAP_SC_DEB_32_CYCLES, and
HAP_LRA_AUTO_RES_HI_REG.
- Use "if (err)" consistently instead of "if (err < 0)" for helpers that
only return 0 or a negative errno.
- Trim comments that merely restate the next line and boilerplate
kerneldoc on trivial static helpers.
Thanks.
--
Dmitry
next prev parent reply other threads:[~2026-12-01 4:48 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 0:13 [PATCH v8 0/9] input: Add support for the Qualcomm PMI8998 and PM660 haptics David Heidelberg via B4 Relay
2026-11-30 0:13 ` [PATCH v8 1/9] dt-bindings: input: Add Qualcomm PMI8998 / " David Heidelberg via B4 Relay
2026-11-30 0:22 ` sashiko-bot
2026-11-30 13:59 ` Rob Herring (Arm)
2026-11-30 0:13 ` [PATCH v8 2/9] dt-bindings: mfd: qcom,spmi-pmic: Allow the PMI8998 haptics child node David Heidelberg via B4 Relay
2026-11-30 13:59 ` Rob Herring (Arm)
2026-11-30 0:13 ` [PATCH v8 3/9] Input: qcom-pmi8998-haptics - Add Qualcomm PMI8998 haptics driver David Heidelberg via B4 Relay
2026-11-30 0:26 ` sashiko-bot
2026-11-30 9:33 ` Uwe Kleine-König
2026-11-30 10:36 ` Alexey Minnekhanov
2026-11-30 11:36 ` Uwe Kleine-König
2026-11-30 15:21 ` Andrey Derkach
2026-11-30 16:11 ` David Heidelberg
2026-11-30 16:16 ` Andrey Derkach
2026-11-30 16:26 ` Andrey Derkach
2026-11-30 23:56 ` David Heidelberg
2026-12-01 4:48 ` Dmitry Torokhov [this message]
2026-11-30 0:13 ` [PATCH v8 4/9] arm64: dts: qcom: pmi8998: Add haptics node David Heidelberg via B4 Relay
2026-11-30 0:13 ` [PATCH v8 5/9] arm64: dts: qcom: sdm845-oneplus: Enable haptics David Heidelberg via B4 Relay
2026-11-30 0:13 ` [PATCH v8 6/9] arm64: dts: qcom: sdm845-xiaomi-beryllium: " David Heidelberg via B4 Relay
2026-11-30 0:13 ` [PATCH v8 7/9] arm64: dts: qcom: sdm845-shift-axolotl: " David Heidelberg via B4 Relay
2026-11-30 0:13 ` [PATCH v8 8/9] arm64: dts: qcom: pm660: Add haptics node David Heidelberg via B4 Relay
2026-11-30 15:21 ` Andrey Derkach
2026-11-30 0:13 ` [PATCH v8 9/9] arm64: dts: qcom: sdm660-xiaomi-lavender: Enable haptics David Heidelberg via B4 Relay
2026-11-30 10:38 ` Alexey Minnekhanov
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=e2198b0a278df12f939c0264cdf6be2b@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=abelvesa@kernel.org \
--cc=andersson@kernel.org \
--cc=casey@connolly.tech \
--cc=conor+dt@kernel.org \
--cc=david@ixit.cz \
--cc=devicetree@vger.kernel.org \
--cc=fenglin.wu@oss.qualcomm.com \
--cc=kamal.wadhwa@oss.qualcomm.com \
--cc=konradybcio@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mfd@lists.linux.dev \
--cc=phone-devel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=subbaraman.narayanamurthy@oss.qualcomm.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