From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796100528; b=gagujr0MvGGuzYHCCRrK+5r9McKLbjvSRxsEx+JDG5xZsp1Tx5nEBvl/nG3S9uqp8FtC 7WlF6HLm0s1Yk8TwPFa0+aCE0sTj0BSunQfJVfeDaAizHk5pETD/MjxWGnB3JGsKvI6G2 ZPg0YqN1gugGB1lq7HBkigQzbBLzeUuPVv3PcllYbVeC4MJKPczFlO4irq4hoLQqSx97D yX6yXzlow2t3Okz422eBfvRLZ0r55RIDLDlfMvF8sEizPUfAXeYzX17AZFy5IdrtF7MFR zg69YDlRd+WobX9e6z8so9h8LT4NxCRAoukLWLym2SjSU/RbTQBggGOqhLCDtqs7hkg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796100528; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding: Content-Disposition; bh=zsscbweRSf4gHTtwrxkj9sSo1qHJd9FMOCvai14bitY=; b=2paN2fJRVLC1SDuII/Rny1PZQUjj7y8ZrygZvE65oxckaQNOWjLJgJCFvEiKz6RzFRaA +Rz+0PxwXTCVw83yjKCLpYe1yk1zPQBvOjdpDPlBGSJNlJ4FGGPF7AYMZQ86P5qOnVh0C e2Ypu9Tw0sPFD225Rgn0O5R+t61HgTYV54ZvbgkgwnA213bgT75LgN2sGTrsLBMfmG19R OEH7vM0x6SSdm3dPZj6E8T+K8l5B9fFB0qJC7ZqSfnq6S0O3qQTA8s9EeLrUCz8ArOtXt bRUYNUqxlswy2TXUnY/F6K+JG6dUedMTukP8yahWAkYwdFbUjF6HWHDfgjcOEW9n9ew== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=XYTo6fH6; arc=none smtp.remote-ip=74.125.82.52 Received: from mail-dl1-f52.google.com (mail-dl1-f52.google.com [74.125.82.52]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62925606A31A for ; Tue, 1 Dec 2026 04:48:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 62925606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=XYTo6fH6 Received: by mail-dl1-f52.google.com with SMTP id a92af1059eb24-170135e43c7so4021917c88.0 for ; Mon, 30 Nov 2026 20:48:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796100526; x=1796705326; darn=vger.kernel.org; h=content-disposition:content-transfer-encoding:content-type :mime-version:references:in-reply-to:subject:cc:to:from:message-id :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=zsscbweRSf4gHTtwrxkj9sSo1qHJd9FMOCvai14bitY=; b=XYTo6fH6SmOCYoDn4q5Hz9abjHktb/ikhwVqJnnJOSUTLDbjrJg9XM7P6E0M/hnnSM 79yVlBCQZRbCNebJk2ZOshF1YgaiTuKBFWqZ9OA4MI+Yk8duZKFU6xRJe+NJdOfWhfB+ w9XwbciKGc90K1skM/vptMvSiTU7P0KzNyPEfWX/FG6aP1gorNbOv/4PDCLq+evoE3n8 e2Kg9xrKsC+Tn3tm7Yep16y9WSSauNk8pbZhZAniSesX7Lja9Ws4AmHCyml1ied6EurI x9wcPpwtrWWKmBflnVXV7I+0Q5O1minoYnz9VoLzlWgKcaDgHUmuZQkcGnUdBVa1FKoi cb0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796100526; x=1796705326; h=content-disposition:content-transfer-encoding:content-type :mime-version:references:in-reply-to:subject:cc:to:from:message-id :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=zsscbweRSf4gHTtwrxkj9sSo1qHJd9FMOCvai14bitY=; b=W/1lFoE0v2Y3PxpyQxK+4Z4kPpUCF8fktKL2F+yXZ4gL8uJ8zRu4sZaO/RY9svF7Za M/aBhBQqflM2ity/Zi6Jj3NooPRltlo4HTE3HwsG6aNZ2QZ//oY0+FnuFhUvQtokLDED 7x8XgfrcKZpAnROu6GuDtBva//mMz5vznRRAL1SXnrin79P+fmwXmPrnxwWoimc+4Ifw tXVt+xCGubTYGpyjR7IykMSozkITG3gw+xHVc2AXcdNIV5CNmdfyA1ER7cKT1BVLGfMO InL8sHxF9pphFjbyVajaWN9OaLGY7VCTh6msEpZqJh5JSpLvjjW8FdXM0yYh8QtPX2db l2ew== X-Forwarded-Encrypted: i=1; AL+hErEj0znY1THczs0/pMhdRSKpLFaFOMqcToANSWCxDHmTz12zB+DiIqBSKzhEzwBMqwSdeiJFfuEnkiOhpsQ=@vger.kernel.org X-Gm-Message-State: APuU4Z+zposaeS/sGWwsoyXu2bcxMXeeVJta2KTiE6nddDuYIxXHEZGK 4dXf89kPoAaMsSZ+OYrHO3+Str44UxJWa4J4GJ85wdAX1/w1GO6TioME X-Gm-Gg: AZFdTZepNJjxZhE0dinenYW0QegeJKFC++uwAnyM6MriIVuhpHhpGk0zwjIXb1SpLm5 hIIiS4N6RkGa3iVQS3pgcrg+3xLWmNT1WOglxwoKe7CmqXuA8EzAy2o4uO1aHNHeUG9LMTt3XL3 4xb1yuy98KPFkeHX2fvSbLDsiMCViyDjiSdnBLVI5mvmg4jT/ATcOI5t0VO+B7RJNFsYLHyGbXO viSGvtykVoYWd7kkB2HlhAOMHqh5p4YbsepKj7zntQttLG51ZA72Ldufrimp4LC+Fxmly7swa7I Vvby+QKQaLxzR6DGu/oPpp1gPrQtU1fuYnrx2ry6T+w7upf3C7wnvwom/VyYF/j5/RQmzb+i/qc 0/+vwk0zZsAu6GA7txfAVOwS85km/KAGTb2zCJb68ely/ISQFGF4jPu21X+cN1xLz1ctvsnAkn7 9jJEpuUNGchdNDXTQacjzJWMxNBIWbFoPIEAOh6wtiAPjM7SAIMzZxSDsc1k2ct76n0hUoWJ8lE TlQDSNiQSg+swzunlPhvWvQom0FPJu17PohM+aVhwNEbV1D1uWYI9OQPZeH+rZYZnEFCzEb/pHc 1SuM14yeaRXscuCsBjfLmgvHdhvGQZXM8EJFn9iRNjO8/7pcM3cCcrGYi4x8YmT1gs4yaw== X-Received: by 2002:a05:701a:844a:20b0:1b5:ade5:da90 with SMTP id a92af1059eb24-1b5ade5db51mr6280507c88.1.1796100526406; Mon, 30 Nov 2026 20:48:46 -0800 (PST) Received: from localhost ([2a00:79e0:2ebe:8:9f42:1ffe:38c8:d6a]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5566c3052sm80866761c88.1.2026.11.30.20.48.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 20:48:45 -0800 (PST) Date: Mon, 30 Nov 2026 20:48:44 -0800 Message-ID: From: Dmitry Torokhov To: David Heidelberg Cc: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Lee Jones , Stephen Boyd , Bjorn Andersson , Konrad Dybcio , Abel Vesa , Subbaraman Narayanamurthy , Kamal Wadhwa , Fenglin Wu , Casey Connolly , 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 In-Reply-To: <20261130-qcom-pmi8998-haptics-v8-3-a64ecd72d3bb@ixit.cz> References: <20261130-qcom-pmi8998-haptics-v8-0-a64ecd72d3bb@ixit.cz> <20261130-qcom-pmi8998-haptics-v8-3-a64ecd72d3bb@ixit.cz> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 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