HAP525_HV module Vmax setting follows the HV_HAP_DRIVER defined
in HW_CONFIG, so add the check to make sure the Vmax can be set
correctly.
Change-Id: I116e068c774dea47648f345cc3cf89a98f2eee52
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Based on hardware recommendation, set FORCE_VSET_ACK when HAP525_HV
module is working in open-loop mode.
Change-Id: I7f9bb45bc25b0923743fad0c58410523e278d1e7
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
PATx_MEM mode has a different play rate setting with FIFO mode and
all PATx_MEM sources share the same play rate. Set the play rate
when configuring the mmap configuration for preload FIFO effect.
Change-Id: I1c0dbf80977b864264e4580d476cf25b4202f757
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Correct the logic of finding an available PAT_MEMx source to store
preload FIFO effect. Also add a debug print for preload property when
dumping FIFO effect settings.
Change-Id: If328e8bdb32f28495ac893a5a31f2be48fedd2b9
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Add TOGGLE_EN_TO_FLUSH_FIFO and RECOVER_SWR_SLAVE flags for the SW fixes
only applicable for HAP520 haptics module.
Change-Id: I8b5e1ca8e4d734dd4ed8c05edb88fa6642460e83
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Currently, HAPTICS_EN bit is toggled whenever a FIFO pattern is played
followed by setting Vmax. However, this would issue a SWR_VMAX handshake
and then follow a SPMI_VMAX handshake in HW if haptics effect is played
over SWR bus in the background. This back to back Vmax handshake would
potentially cause the HW not responding and no vibration being played.
To address this, set the Vmax before toggling HAPTICS_EN bit to avoid
back to back Vmax handshakes when SWR and FIFO are played concurrently.
Change-Id: I0b8924ab7f369db446458fe2510a0da01519a978
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
As per the hardware recommendation, MOD_STATUS_XT need to be programmed
before programming MOD_STATUS_SEL to get the correct status data in all
cases. Update it.
Change-Id: Ie66b12cdc702f32ebfad78a72396ad3ac4d14adf
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
"fifo" is allocated per effect only when "qcom,wf-fifo-data" DT
property is specified. Fix haptics_init_fifo_memory() so that it
doesn't access that when parsing per effect data structure for
configuration.
Change-Id: I4f48e5c43c3b289e47d9a9a0934a642172e65555
Signed-off-by: Subbaraman Narayanamurthy <quic_subbaram@quicinc.com>
Currently, when waiting for hBoost ready times out, error code -EBUSY is
returned. In addition to that, reset the FIFO play logic so that the
following FIFO requests can still be served.
Meanwhile, add 100us before updating HAPTICS_EN for hBoost to have
enough time to handle its power transition as per the hardware
recommendation.
Change-Id: Iebfc98b589bda747e4c2b6fdf6ff78d2f46ece5d
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Reallocate memory using vmalloc() for custom FIFO data if the memory
allocation using kcalloc() is failed. This may happen if the vibrator
HAL is passing down a vibration effect with a very big chunk of FIFO
data and system is running out of memory.
Change-Id: I3612208df42e46a44ca0fd43ec9b4c6ca862620e
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
If getting close-loop TLRA failed in driver probe, such as if there
is no valid value in SDAM register for CAL_TLRA_CL_STS because of the
bootloader had not run the frequency calibration successfully. Use
open-loop TLRA to program the hardware so the vibrator can still be
functional but just lose some efficiency because of unadjusted
frequency.
Change-Id: I8b8dd0906aa6b3fa882e2044cdbe579c746714a3
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
HAP525_HV haptics module has 2048 bytes of SRAM which can be allocated
for 1 FIFO partition and 4 PATx_MEM partitions. The PATx_MEM memory
space is allocated following the FIFO memory and the size for either
FIFO or PATx_MEM can be configured differently. Normally, memory
allocation can be started at the end and the space is sequentially
allocated to PAT4_MEM through PAT1_MEM, and the leftover space is for
FIFO. Any PATx_MEM with memory size 0 will not be used/enabled. Also,
it's suggested to cofigure FIFO memory size not less than 640 bytes
to ensure the normal function of FIFO streaming mode. For each PATx_MEM
memory partition, it has a corresponding PATx_MEM mode which can read
data from its space as the pattern source for a vibration effect. This
is very similar to FIFO mode but just PATx_MEM mode can't be played in
a loop with data refilling.
Add "qcom,wf-fifo-preload" property to allow use PATx_MEM mode to
implement preload FIFO effect. If this property is specified, during
driver probe, PATx_MEM partition with enough memory will be allocated
to store the preload effect data, and the data will be remain unchanged
until a device reboot. Later, whenever a play request with such effect
is issued, it will be simply triggered by writing to the play register.
If there is not free PATx_MEM partition or no big enough memory for
storing the preload effect data during driver probe, the preload
effect will be treated as normal FIFO streaming effect and it will
be loaded and played at runtime.
Change-Id: Ic165e396f22f56e61b68bbc5cfc05c461f0f77d6
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Split haptics_hw_init() into small functions for better readability.
Change-Id: I34a6d48d0760d3dc834f6e8d2763ff8735f13f83
Signed-off-by: Fenglin Wu <quic_fenglinw@quicinc.com>
Haptics clock calibration is based on SLEEP_CLK which is a 32.768 KHz
clock however HAP520 module in PM8350B assumes SLEEP_CLK is 32 KHz
exactly. Adjust LRA period and coefficients for calculations only when
PM8350B haptics is present.
Change-Id: If217937405aed2c2d93883f3645fe1bd5e7f6d8c
Signed-off-by: Anjelique Melendez <quic_amelende@quicinc.com>
Haptics with HW type HAP525_HV is having revision value 4 in both
HAPTICS_CFG and HAPTICS_PATTERN modules. Add this HW type support.
Change-Id: Icb1f2291aaaffd0790f133146ea9601b0182989b
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
SW_CTRL_HBST flag is added to include the hBoost control logic which
is required for HAP520 haptics module.
Change-Id: I6615e6cff90f4cfb8d266752c61b3daf06dfe571
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
Currently, the name of the PMIC along with haptics module is used to
differentiate the HW. Modify it to use only HW type of the haptics
module. The HW type can be detected by reading HAPTICS_CFG and
HAPTICS_PATTERN module revision register. Add the logic for HW type
detection. Also, unify the code places that use module revisions,
instead, use HW type for differentiation.
Change-Id: I8428cc74988e88c1057af8b41ed46979aa6009cb
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
PM8350B V1 chip is no longer used for new targets so clean up the
driver to remove the support for haptics module inside PM8350B V1 chip.
Change-Id: If8a6dfd025753a768aa067958f10d613b574ee3f
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
Remove the return value when creating "fifo_empty_thresh" debugfs node
because debugfs_create_u32() API no longer supports return value.
Change-Id: I7b39ed79a9148c2815b8656222dc6f61540b2129
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
FIFO_REAL_TIME_FILL_STATUS_MASK is different for haptics HW
version V3. Update it.
Change-Id: Ida8326d89678af34ae2c3a35164ae1a7ad5f6b7b
Signed-off-by: Kiran Gunda <kgunda@codeaurora.org>
The incorrect first cycle vibration issue is applicable only
for PM8350B PMIC. Hence, make the SW W/A to toggle the CAL_EN mode
from disabled to auto mode specific for PM8350B PMIC. Introduce
a "wa_flags" variable to handle the SW W/A in a cleaner way.
Change-Id: I8f0c31fd21681274081a4d58d589b4ed9a188f34
Signed-off-by: Kiran Gunda <kgunda@codeaurora.org>
The VMAX_STEP value is different for HV and MV haptics.
Update the VMAX configuration accordingly.
Change-Id: I5d0f00e9a07e76b01b16539d79897675ddd63117
Signed-off-by: Kiran Gunda <kgunda@codeaurora.org>
Some PMICs such as PM5100 does not have the HBOOST peripheral
for haptics input supply. Add a new compatible string to avoid
accessing the non-existent HBOOST peripheral and also make the
necessary configurations required for hpwr supply.
Change-Id: I84301115706ee59984f7b051bc467d1537bbad29
Signed-off-by: Kiran Gunda <kgunda@codeaurora.org>
Since HAP_CFG V3 doesn't support soundwire haptics, skip initializing
swr regulator so that swr_haptics cannot use it.
Change-Id: I64d783aabcf699233c68a96af5ffd922d361fb24
Signed-off-by: Shyam Kumar Thella <sthella@codeaurora.org>
Commit b610aa2d70a3 ("input: qcom-hv-haptics: Ignore checking HBoost status
when SWR is playing") is added to ignore checking hBoost ready status when
triggering a non-FIFO play with SWR playing in the background. This should
be also applicable when triggering a FIFO play, so remove the pattern_src
check as the HBoost should be always ready when triggering the play with
SWR playing in the background.
Change-Id: If3d5ff7138e189c81991775d7814229c4d0e8c0a
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
In haptics pattern/fifo/brake debugfs file write operation functions,
strsep() is used iteratively to split the user-passed string into tokens
for setting parameters. However, strsep() modifies the pointer passed
and hence the same pointer cannot be used in kfree(). Fix this by
copying the pointer originally allocated by kzalloc() and use it in
kfree() as well.
Change-Id: I2baf8db4f7c39e7ab0a83411717e46a29a2e849b
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
The haptics module would get stuck in SWR mode if SWR port is
disconnected during SWR play, and this can happen if ADSP SSR
(subsystem reset) is triggered when playing in SWR mode. This
stuck condition can be detected by checking if haptics module
has already been in SWR mode when swr-haptics driver requests
to enable SWR haptics. When it's detected, ignore SWR mode
temporarily and toggle HAPTICS_EN for a HW reset. When SWR play
is attempted again i.e. when swr_haptics driver request to turn
on SWR slave device, SWR mode would get re-enabled.
Change-Id: Ie55d331e3c689972b42dd9688f0d2b182b3fd282
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
HBoost would be kept on when triggering a non-FIFO play with SWR playing
in the background, there is no need to wait HBoost to be ready hence bypass
the HBoost ready check in this case.
Change-Id: I68c4a97d1c5953fb5dc0dd53fa8792a02df4b3de
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
Update following settings in LRA frequency detection sequence according
to HW recommendation:
1) Increase to 6 drive cycles before enabling High-Z period for auto
resonance config.
2) Disable adaptive drive duty function.
Change-Id: I551974603c99fcdad5d38fdef6edf15746c0033e
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
When uploading a constant effect after stopping FIFO play, the effect
pointer in haptics_play_info structure will be set to NULL. If there
is any pending fifo-empty IRQ gets served after that, it will trigger
a NULL pointer dereference issue. To avoid this, check the playing
effect pointer before use it in the IRQ handler.
Change-Id: Iacfea5e48d0a9519fa2c930ec821e395c43b6281
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
HBoost is required to be in disabled state before triggering the play.
Check this through DTEST1 signal and ensure the HBoost is ready before
serving a new vibration request.
Change-Id: I0d4b73fef39aa6da15abbb832369579221665d07
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
Currently, haptics_fifo_empty_irq_config() uses a mutex lock and it's
called from playback() of input framework which is from an atomic
context. Fix this by moving it out of haptics_playback() and call it
from haptics_set_fifo() which gets eventually called in upload().
With this change, the irq_lock mutex is no longer needed because all
the calling paths of haptics_fifo_empty_irq_config() have been protected
by the mutex lock defined in haptics_play_info structure, hence remove
it.
Change-Id: I4e4d353f8427fb279fd3f4d6a28737acbdb22a0a
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
When FIFO samples are played back to back along with SWR mode, there is
a chance that FIFO samples won't get flushed out if they're not fully
played before FIFO mode is stopped. When this happens, FIFO samples gets
accumulated leading to overflow after which FIFO mode stops working.
Only way to recover from this is to toggle HAPTICS_EN_BIT before
starting FIFO mode playing again. While at it, add logs to print out
FIFO real time fill status which is helpful for debugging.
Change-Id: I07cd9ac34ad5ccfe7011850db554ba727f568482
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
FORCE_VREG_RDY bit can be always set when non-HBoost regulator is used
and don't clear it when stopping play in non-HBoost case. Also set this
bit in driver initialization in non-HBoost case so that swr-haptics
driver can take the advantage of triggering SWR play without setting
this bit.
Change-Id: I6283396d9d5a4f0b87d87932d6db2d8e7bb7a623
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
When calculating play length for FIFO play, it is out of bound
of the FIFO samples array. Fix it.
Change-Id: I8ad458802a0070f493ac53160ab90a6cf648d9e7
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
When stop command comes during FIFO refill, it would free custom_effect
FIFO sample memory and set the pointer to NULL, and this would cause
the NULL pointer dereference during FIFO refill. To fix this, add a
mutex lock between FIFO stop and FIFO refill sequence to avoid a race.
Change-Id: I8792c2183f06e84fca3a7c4dddfed667b25f2528
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
By default, haptics module is supplied from HBoost module and it
talks to HBoost module in hardware to get an appropriate operating
voltage. Haptics module can also be supplied from non-HBoost regulator
and it requires software to request the voltage.
Add support to operate haptics under a fixed voltage from a non-HBoost
regulator. Make the following modifications:
1) Set voltage and enable the regulator before enabling the play.
2) Force VREG_RDY signal in haptics module before enabling the play.
3) Scale the DIRECT_PLAY amplitude to achieve appropriate output
voltage in constant playing.
4) Scale the DIRECT_PLAY amplitude instead of Vmax setting for
gain setting in constant playing.
5) Adjust the LRA impedance detectability according to the regulator
output voltage.
Change-Id: If832b6512d7641ad3d271bb68f4bdb7dbb90a5c5
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
SW trigger for PBS to configure ISC in LRA detection doesn't need to
pass any parameter or wait on any condition including checking status.
Hence switch using qpnp_pbs_trigger_single_event() instead of
qpnp_pbs_trigger_event() to trigger PBS.
Change-Id: I8b252e293265994976924435f8a6a11d9b463119
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
Correct register values when toggling RC_CLK_CAL for playing haptics in
HBoost open loop case.
Change-Id: Ia48ab3af93181c61ec719716634e94a819353c8b
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
The haptics module supports writing FIFO samples using 4-byte burst
mode as well as 1-byte mode. During FIFO refilling, if a 1-byte write
was used, then the hardware would fill zeros automatically after that
to keep the FIFO data 4-byte aligned. When this happened in the middle
of playing, the hardware inserted 0 values would cause spurs on the
haptics output. To fix this, only use 4-byte burst writes during FIFO
refilling until the end of the play.
Change-Id: I0441942585e0e0d5da62ec4a7123b2763b292739
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
To help with power savings, disable haptics module when the device
enters suspend and enable it when it exits suspend.
Change-Id: I8956be849b876a2b514c1de49f8ff447267d28a1
Signed-off-by: Subbaraman Narayanamurthy <subbaram@codeaurora.org>
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
Auto resonance needs to be disabled for FIFO streaming mode. Hence
disable it when playing custom FIFO data.
Change-Id: I11bb2e944bebf642b780b964bdea7907cae3c843
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
Add support for detecting LRA impedance. The detection is done using
following procedure: set ISC to 250 mA and Vmax to 10 V, then sweep
the duty cycle using binary approach based on the SC_FAULT status until
reaching to the last step. The impedance can be only detected between
a range and the resolution depends on the sweeping steps. Currently,
total number of steps used for calculating LRA impedance using
approximation is 5 which can achieve an accuracy of 1.25 Ohms.
This detection is only available for PM8350B 2.0 chip and it can be
triggered using command:
echo 1 > /sys/class/qcom-haptics/lra_calibration
After that, the result can be read out using command:
cat /sys/class/qcom-haptics/lra_impedance
Change-Id: I7edc00ecdb019ccf7ca5af459dec8105834706f5
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
When RC_CLK_CAL_EN is set in auto mode while haptics boost is working
in open loop, the first cycle of the vibration would be played
incorrectly because the haptics module couldn't get enough clock count
before the play gets triggered. Fix this by toggling the RC clock
calibration mode from disabled to auto mode.
Change-Id: I80b3c48b9bb508b12841a679eafa2c618771edf2
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
During LRA frequency calibration, reading CAL_TLRA_CL_STS has to be
done before de-asserting play. In the boot up LRA frequency calibration
sequence, CAL_TLRA_CL_STS was read out and stored in SDAM module
registers by the bootloader. Later, HLOS haptics driver can read it from
there and use it for calculating LRA frequency. This boot up LRA
frequency calibration sequence is only available for PM8350B 2.0 chip.
Update the driver to support this.
Change-Id: I0b81e79bad57160f9c79e01151e2d4060b4bbd41
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
RC_CLK_CAL_COUNT is the calibration count used in manual RC_CLK_CAL
mode when playing FIFO patterns. For haptics module in PM8350B 2.0,
there are new equations recommended to calculate RC_CLK_CAL_COUNT
based on CAL_TLRA_CL_STS and LAST_GOOD_TLRA_CL_STS status to achieve
better accuracy. Update the driver to support this.
Change-Id: I983c1b1f284006847549d2b3d23a0c1039f8b4c1
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
There is a new scheme recommended in PM8350B 2.0 haptics module for
getting close-loop LRA period. There are 4 situations need to be
considered depending on if auto mode RC CLK calibration is used
and if auto resonance calibration is done during the playing. In
each situation, different status values and equations are used for
calculating close-loop LRA period. Update the driver to support this.
Change-Id: I8f5fdcdd3ebae71af333a0b05fb4860e1c43ce10
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
HAPTICS module controls the output voltage of HAPTICS_BOOST module
through hardware signals when playing a vibration. During FIFO mode
playing, HAPTICS module would request HAPTICS_BOOST module to turn
on/off the output based on FIFO empty status. HAPTICS_BOOST is turned
off when FIFO is empty and it's turned on again when more FIFO samples
are filled.
During this voltage transition request (off->on), HAPTICS_BOOST module
may have a race condition if this requests comes in rapid succession.
This can lead to its FSM getting stuck. To avoid this race condition,
notify HAPTICS_BOOST module to keep the output enabled until the
playing is stopped. This is done by triggering a PBS sequence through
a SDAM module.
Change-Id: I5cef13df7a1fa4608dd64d509c802e0bcfde6b92
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
In constant waveform playing, there is no need to use an effect data
structure to capture the current playing effect, hence set it to NULL.
This also helps the set_gain() callback to use the correct Vmax when
it's called in constant playing case. Also add a debug message to show
the Vmax setting.
Change-Id: I763ec7407b8696300dbe93f5e6935900544e75a8
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>
Per HW recommendation, when reading HAP_CFG_STATUS_DATA registers,
MOD_STATUS_XT.SEL need to be written first to select the right mux,
then update MOD_STATUS_SEL register so haptics module can present the
desired status values into STATUS_DATA registers.
Change-Id: I24205072074ff75b25b42c752333b5f99d83d067
Signed-off-by: Fenglin Wu <fenglinw@codeaurora.org>