Add a check for number of input patterns detected in string read from
userspace in pattern_s_dbgfs_write() API, to avoid out-of-bounds write
in a local array.
Change-Id: Ic35561ae34f95c67fbd54ae4db4a7174342f45f4
Signed-off-by: Jishnu Prakash <quic_jprakash@quicinc.com>
Remove the call to input_ff_destroy from remove callback as
it is needed only in error path. This fixes an issue
where there is a crash from input_ff_flush() due to NULL
pointer dereference if haptics module is removed with
rmmod. In addition, add input_unregister_device() call
in remove callback to ensure proper cleanup.
This is the call stack for the crash:
__mutex_lock+0x60/0x89c
mutex_lock_nested+0x4c/0x5c
input_ff_flush+0x3c/0xb4
input_flush_device+0x64/0xb8
evdev_cleanup+0xa4/0xc4
evdev_disconnect+0x38/0x74
__input_unregister_device+0x164/0x24c
devm_input_device_unregister+0x24/0x78
release_nodes+0x244/0x2cc
devres_release_all+0x40/0x60
device_release_driver_internal+0x288/0x3bc
device_release_driver+0x1c/0x2c
bus_remove_device+0x110/0x170
device_del+0x324/0x500
platform_device_unregister+0x34/0xb4
Change-Id: Ieae1ec1630c018b91dd8290143b9b3859be2b0c5
Signed-off-by: Jishnu Prakash <quic_jprakash@quicinc.com>
There is an issue introduced in commit b40e334321
("input: qcom-hv-haptics: update HW type detection logic") that
the hBoost module register address base is used before parsed
from device-tree. Fix it.
Fixes: b40e334321 ("input: qcom-hv-haptics: update HW type detection logic")
Change-Id: I801d09228b2483e45adb7e96eb883cbb40334dca
Signed-off-by: Hui Liu <quic_huliu@quicinc.com>
Remove cancel_work_sync() as it would sleep on waiting work execution
but this is not permitted in haptics_set_gain(). Also it's fine to keep
any pending work because the work function has appropriate protection
for reentrance.
Fixes: 279ed1a5b9 ("input: qcom-hv-haptics: move set_gain() operation into a work")
Change-Id: Idf1f7eabd7ae391353de691cc8bc3707e09f4194
Signed-off-by: xuanpeng <quic_xuanpeng@quicinc.com>
In commit ba1e02b8f5b0("input: qcom-hv-haptics: poll HPWR_INTF status
after setting Vmax"), the mutex lock in haptics_play_info is used to
protect the data structure in haptics_set_gain(), and set_vmax() also
introduced a mutex lock and it's also called in haptics_set_gain().
However, haptics_set_gain() is running in an atomic context with
spinlock held and it shouldn't call any sleep function, hence, move the
set_gain() operation into to a work.
Fixes: ba1e02b8f5b0("input: qcom-hv-haptics: poll HPWR_INTF status after setting Vmax")
Change-Id: Ic2c95cb6dd6fc4646ac9038cdda0e311a3b71e62
Signed-off-by: xuanpeng <quic_xuanpeng@quicinc.com>
Some of the application might not send stop command after triggered
constant effect play, stop the play when its play length is reached.
Change-Id: I87f8260af8b395c6f7616ec9f26a87e08129e0c0
Signed-off-by: xuanpeng <quic_xuanpeng@quicinc.com>
Update the LRA impedance resolution in SDAM register which has been
updated to 250 mohm per LSB.
CRs-Fixed: 3351475
Change-Id: I2e7cea15594adb2e07899c32cc4bffdd3e73e187
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
The haptics HW may be still driving after PLAY bit is deasserted,
especially when brake is enabled. Haptics HW would be still driving
output for brake sychronization and playing the brake patterns. If
haptics is configured to trigger another play at the same time, it
would cause HW problem, such as: If a FIFO effect with a high Vmax
setting is triggered while haptics is driving brake pattern right after
the DIRECT play is stopped, the high Vmax will be applied to the brake
pattern and it would cause the LRA overdriving.
To avoid this, poll HPWR_DISABLED status after the play is stopped to
guarantee that HW has fully stopped before trigger a new play.
Meanwhile, move the play disabling function to erase() hook because the
playback(0) is running in an atomic context and it couldn't call sleep
functions.
Change-Id: Ief7fe88b5b3ab3bbfe2eb69542e778062c544af8
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Currently, hw_type is used before it's been set when reading
revision registers, correct it.
Change-Id: Ic543d8d059492c6a6f656194319e49d2b1eba90e
Signed-off-by: Hui Liu <quic_huliu@quicinc.com>
Disable ILIM(cycle by cycle current limiting) before LRA impedance
detection for monaco.
Change-Id: I1eb019eae1aa46250cb6aa99db46013ae009179f
Signed-off-by: Hui Liu <quic_huliu@quicinc.com>
When Vmax setting is updated, haptics module would request corresponding
voltage from hBoost when the driving waveform is zero crossing. This
would take some time for the Vmax setting to complete. The voltage
requesting status is shown in HPWR_INTF register and it is expected to
be either HPWR_DISABLED or HPWR_READY. Haptics module can only switch
play mode or request another voltage change after that, otherwise the
haptics module may get stuck.
To address this, poll HPWR_INTF register for a period of 10 ms after
updating Vmax. If Vmax setting is not complete in that period, toggle
HAPTICS_EN to reset haptics HW from that stuck state. Also, add a mutex
lock for updating Vmax settings to avoid multiple requests interfere
with each other.
Change-Id: Ibcb37adad43d9814baaa5a97fc8799b8fd69aee9
Signed-off-by: xuanpeng <quic_xuanpeng@quicinc.com>
This part of logic was missed when propagating the change 'commit
<3377e29a1222> ("<input: qcom-hv-haptics: Toggle EN_CTL for PM5100 v1.0>")'
so add it back as a separate change.
Change-Id: I06eb093fe012ddcabf6ec8657254d9c79eb95ada
Signed-off-by: Hui Liu <quic_huliu@quicinc.com>
Replace using mem_sleep_current node to check for Deep Sleep(DS)
with pm_suspend_via_firmware() API for GKI compliance.
Change-Id: I628416aaf3a3a72cf3d029c154a64dff9d5f602c
Signed-off-by: Umang Chheda <quic_uchheda@quicinc.com>
HW faults may be happened after LRA calibration sequence, clear the
faults after the sequence to prevent any faults blocking next vibration
request.
Change-Id: I03004c83268b1d772c110c868ab9f93446f881f1
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Disable auto resonance explicitly for PATx_MEM mode play according to HW
recommendation. Also, clear MEM_PAT_ACCESS_BIT after written PATx_MEM
samples and it reduces device quiescent current in power off state.
Change-Id: Iafaca15482bf1a03a19a49ee4d5e30faeb2fdeeb
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Update the register configuration for F0 detection/calibration
based on hardware recommendation.
Change-Id: I423ed84bf10508dc6ded2bc4248ac9ce396ce8cb
Signed-off-by: Anjelique Melendez <quic_amelende@quicinc.com>
Move the logging after calculating Vmax so that the right Vmax value
can be printed out.
Change-Id: I8d916a13685c8d85f1363e7a8bc766aeb4d5e2ba
Signed-off-by: Hui Liu <quic_huliu@quicinc.com>
On SKUs with MSM + Co-proc there can be possiblity that
because of Interrupts enabled from MSM side (SPMI) the exit
of LPM might not work because PBS gets locked because of
which the sequence to exit LPM might not get triggered.
Add support for shutdown callback and disable INT in shutdown
cb to ensure that INT are disabled before entering LPM.
Change-Id: I29bafb72bef3a5591839015f2a598fa4ad85072a
Signed-off-by: Umang Chheda <quic_uchheda@quicinc.com>
Primitive effect is very similar to predefined effect
which has been supported and each primitive effect has
an unique id defined in "qcom,primitive-id" devicetree
property. Add support for it.
Change-Id: I4a03dd09e97f1b7988d4ab87e1cf78f075b05101
Signed-off-by: Hui Liu <quic_huliu@quicinc.com>
Free/request the fifo empty interrupt during the DeepSleep and
hibernate entry or exit respectively. Also restore the hardware
initial configuration done during the boot.
Change-Id: I6b0d4838a6d1c48869ca760d4e93788440983b3c
Signed-off-by: Kiran Gunda <kgunda@codeaurora.org>
In the boot up LRA frequency calibration sequence, CAL_TLRA_CL_STS
is read out and stored in SDAM module registers by the bootloader.
Later, the HLOS haptics driver can read it from there and use it
for calculating LRA frequency. Enable the same for PM5100 PMIC.
Change-Id: Ia5e307e5d536a42b29ab05e9888640121188312c
Signed-off-by: Kiran Gunda <kgunda@codeaurora.org>
Move the logging after calculating Vmax so that the right Vmax value
can be printed out.
CRs-Fixed: 3227145
Change-Id: I17b64f9e3a230058b7e30ca4c30de4d3000d1f87
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
When hBoost is working in open-loop mode, it's supposed to be used by
other modules like the charger firmware and it shouldn't be turned off
by haptics driver. Ignore turning on and off hBoost in such case.
Change-Id: Id3eb2c37cf7316b4617872614cc2a7adc50d12d8
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Print in hex when a read/write to an address fails.
Change-Id: I35dddaa33d18f72079ec3d814a36fd304cd0f331
Signed-off-by: Subbaraman Narayanamurthy <quic_subbaram@quicinc.com>
Update initial FIFO programming count to 320 which can help to reduce
vibration request latency.
Change-Id: If0e12dd626dda66a0b296b9832562bbeaee57fd9
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
When hBoost is enabled by the charger firmware, force-vreg-ready need
to be set before triggering haptics play. This applies to all play modes
including SWR play mode. Set it base on VMAX_CLAMP notification and
keep it until the charger firmware unvote VMAX_CLAMP which indicates
it's no longer using hBoost. This helps to trigger SWR mode play
correctly in such case from swr-haptics driver which has no SPMI
regiser access in there.
Change-Id: I0a318dd7c5e9d856e200264b11eaea184be15e50
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Add trace events to log down the FIFO play process for debug purpose.
Change-Id: I54671a0b6a1228351067db8b6a7a052d11d8d080
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Add LRA impedance detection for HAP520_MV and HAP525_HV haptics
modules. Both modules can support binary search based impedance
detection as before which relies on the short circuit comparators.
HAP525_HV module has added a new impedance detection comparator
which can be used to support realtime impedance measurement. Add
binary search based impedance detection for both haptics modules,
and also add realtime impedance measurement for HAP525_HV module
but use a devicetree bool property to keep it as optional.
Change-Id: I4cb3f5360084c2d3d36778bed4c8d878f3b465ad
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
For haptics module with HAP520 HW revision, the HW would only read 1
valid byte in every 4 bytes if the 1-byte FIFO write clashes with the
FIFO read operation. To avoid this, don't use 1-byte write but just
pad zeros at end of the pattern to keep the samples 4-byte aligned
and always use 4-byte write for FIFO programming.
Change-Id: I3ebde0fe7378c0dcffb5c51e15e6ffaae5af3e29
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
The equations for calculating RC_CLK_CAL_COUNT need to be updated
when flag SLEEP_CLK_32K_SCALE is not set. Update it by introducing
a coefficient named as SLEEP_CLK_CAL_DIVIDER which is the divider
of the 19.2 MHz system clock to generate the sleep clock.
Change-Id: I75d16eca3fe160c425af5cf3545272e0d1999a8a
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Handle VMAX_CLAMP notification which contains a desired Vmax value when
hBoost is enabled by the charger firmware. Any vibration after this
notification should be set to a Vmax not higher than that to avoid
hBoost overloading.
Change-Id: I6fb1b66663df60041967e2cad0a914f57c310158
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>