strtab is always non-null so remove unnecessary check.
This is a follow up of patch
167a6d79f ("ASoC: fsl: Skip checking for string section type")
and finally fixes CID3901026
Reviewed-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
In the case where lo_vag <= SGTL5000_LINE_OUT_GND_BASE, lo_vag
is set to zero and later vol_quot is computed by dividing by
lo_vag causing a division by zero error. Fix this by avoiding
a zero division and set vol_quot to zero in this specific case
so that the lowest setting for i is correctly set.
Signed-off-by: Colin Ian King <colin.king@canonical.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Both dataline_off and dataline_off_dsd fields are unsigned,
thus checking negative values make no sense. Use a signed
variable to calculate offset instead.
This fixes Coverity issue: CID1899299
Signed-off-by: Viorel Suman <viorel.suman@nxp.com>
Save error so that the following error checking now make sense.
This fixes Coverity issue: CID2828734
Signed-off-by: Viorel Suman <viorel.suman@nxp.com>
When hwvad is enabled, if you try to re-enable it again, it should fail.
However, we were also double setting state to OFF on fail, which is
wrong because it resets the state and allows the second retry to enable
even if it wasn't disabled before.
Now we only return EBUSY.
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Signed-off-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
An unsigned value can never be negative, so this test will always
evaluate the same way.
Fixes Coverity issue CID3618200
Reviewed-by: Viorel Suman <viorel.suman@nxp.com>
Signed-off-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
There may be a null pointer dereference, or else the comparison against
null is unnecessary.
Fixes Coverity issue CID5327850
Reviewed-by: Viorel Suman <viorel.suman@nxp.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Signed-off-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
e_shstrndx already contains the section header index, so
shdr->sh_type will always be SHT_STRTAB.
Remove this redundant check and make Coverity happy.
Fixes: CID3901026
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
xf_cmd_send_recv returns with lock taken if waiting was
interrupted by a signal.
This fixes Coverity issues: CID5233120 / CID5233060
Reviewed-by: S.j. Wang <shengjiu.wang@nxp.com>
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Bail out if kernel_read returns an error.
Fixes: CID1477415
Reviewed-by: S.j. Wang <shengjiu.wang@nxp.com>
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
At this point err is always 0. So, just remove the check.
Fixes: CID1477380
Reviewed-by: S.j. Wang <shengjiu.wang@nxp.com>
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Return value is not used so better use atomic_dec.
This also silences coverity warning CID3344689.
Reviewed-by: S.j. Wang <shengjiu.wang@nxp.com>
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
xf_cmd_recv will return with lock taken in two cases:
* msg was received
* waiting for msg was interrupted by a signal
Make sure we unlock proxy->lock in both cases.
This fixes Coverity issue: CID3335482.
Reviewed-by: S.j. Wang <shengjiu.wang@nxp.com>
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
The reason is same as commit d4eb8ab263 ("MLK-19854-1: ASoC:
imx-cs42888: fix error when m4 image is not loaded")
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
In LPA mode, the system will be resumed by audio notification, when the
period size is small, there will be occasion that when notification
the underrun is happen, but the substream runtime state is not running
so the aplay won't trigger stop first, then start. just only trigger
the start, which don't comply with the convention.
So in this patch, we change the substream runtime state to running, when
the notification happened at resume.
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
For the LPA mode, when the system enter suspend, the M4 will
continue to play the data, but for normal ALSA case, the digital
mute should be called at suspend, so the codec will be mute,
which conflict with the requirement of LPA.
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
With the case that underrun happened, the aplay will trigger
stop and start, if the period index is not reset at stop, the
counter of period will be wrong
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Enable and disable procedures contain info and warn prints. This
introduces delay in initialization / disablement procedures and we have
kept only the necessary prints in case of error.
Signed-off-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Reviewed-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Implemented system suspend resume functions to call hwvad enable/disable
then do runtime_force_suspend/resume.
Since hwvad can run independently, when user calls enable/disable, we
will have to increment/decrement usage counter by calling
runtime_*_sync but to avoid doing this when disable/enable is called
from system_suspend/resume since we called pm_runtime functions - this
is why we have added the sync parameter in enable/disable_hwvad.
However, we ignore the busy flag because the module wasn't designed to
work with arecord and hwvad in parralel and we only print a warning.
Since hwvad and recording share the same clock and initialization
procedures require module to be disabled, the busy flag will be set
when having both features enabled.
Signed-off-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
We must find a way to no longer touch resources after they are
cleand up.
Now, after a stress test we get the following crash:
[ 2156.863772] fsl-dsp 596e8000.dsp: xf_pool_alloc failed
[ 2156.869337] Unable to handle kernel NULL pointer dereference at
virtual address 00000060
[ 2157.148594] [<ffff000008d8839c>] _raw_spin_lock+0x14/0x48
[ 2157.153995] [<ffff000008b3e0b8>] xf_cmd_send_recv_complete+0x40/0xf0
[ 2157.160354] [<ffff000008b3e470>] xf_close+0x40/0x88
[ 2157.165239] [<ffff000008b3f7a4>] xaf_comp_delete+0x5c/0x70
[ 2157.170730] [<ffff000008b40530>] dsp_platform_compr_free+0xa0/0xe8
[ 2157.176917] [<ffff000008b287fc>] soc_compr_free_fe+0x144/0x1a0
[ 2157.182754] [<ffff000008b11b24>] snd_compr_free+0x64/0x98
This happens because:
1) dsp_platform_process work handler waits in a loop for
messages to arrive.
2) when cplay process finishes it cleans up most of the
resources.
3) when another cplay process starts it reinitializes the
resources including queues for example.
4) a message will be generated and kernel will crash because
dsp_platform_process uses the older queues.
A solution for this is to make sure dsp_platform_process work loop
is stopped at cleanup time.
We use is_active state and signal dsp_platform_process handler to
finish because we are on the cleanup path.
While at it replace cancel_work with cancel_work sync to be sure
that work handler ends before going on with the rest of the cleanup.
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
In order to support 44kHz and 48kHz sample rate together, we need to
reconfigure the parent clock of mclk.
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
with this patch,codec driver can support tx and rx in
different master/slave mode, for example, tx in master mode,
rx in slave mode
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
with this patch, codec driver can support tx and rx in
different master/slave mode, for example, tx in master mode,
rx in slave mode
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
The documentation specifies that VADCHSEL is used to select
the channel number on which hwvad detector will work. However,
we have used this field wrong (similar to the recording where
you can enable, disable multiple channels at the time).
This patch fixes hwvad and you can enable it by writing 0 to 7
in /sys/devices/platform/30080000.micfil/hwvad/enable or any
other number to disable it.
Signed-off-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Remove all clock disable from driver suspend/hwvad_disable
to avoid crashing one or another when recording stops or
voice is detected and hwvad is disabled.
Another change done to make this work is to remove atomic
variables that guard mutual exclusion between recording and
VAD.
We have also added a restriction such that recording rate
should be the same as hwvad rate when hwvad is enabled to
avoid changing the mclk rate.
However, the hwvad can be enabled before or after recording
but not when recording is done. On the other hand, recording
can be triggered at any time.
I am not sure we are supposed to support recording and hwvad
in parallel since micfil documentation requires PDM to be
disabled when any initialization or reconfiguration of hwvad
is done. An workaround to make this working is never disabling
the pdm module from hwvad functions and this seems to work,
even we are not following the whole reconfiguration procedure.
Signed-off-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Reviewed-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Because we don't correctly free resources when an error occurs
on component creation path we can end up with partially initialized
components.
Freeing such partially initialized components most of the time leads
to kernel crashing in pain.
Avoid this by making sure we either:
* return a fully initialized component, comp->active = true
* don't "create" the component at all, comp->active = false
Reviewed-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
In case of error no cleanup was done leaving thus reasources
in an undefined state.
This can cause crashes like this:
[ 34.259281] fsl-dsp 596e8000.dsp: load codec wrap lib error
[ 34.266333] fsl-dsp 596e8000.dsp: create component failed, type = 1,
err = -2
[ 34.273493] err pool alloc ret = -2
[ 34.298363] Unable to handle kernel NULL pointer dereference at
virtual address 00000000
... which happens when lib_dsp_codec_wrap.so is not present.
While at it, we also realign some lines of code in order to avoid
going over the 80 characters limit that Linux kernel coding style
preaches on.
Reviewed-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
When enable DSD for ak4458 with imx8mm platform, in DSD256 mode
the mclk calculated from ak4458_get_mclk_rate is 256fs, but
the codec require the mclk should be 512fs. so just hard code
the clock to be 512fs in DSD mode.
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Add control to select clock source from alasamixer or select
auto mode where clock source is automatically selected.
Signed-off-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Add rate when calling dai sysclk so we can set rate after
we change the pdm_src parrent.
Signed-off-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
At this moment, using audio_pll1 offers accurate clock for 48KHz only
and audio_pll2 offers accurate clock for 44.1KHz only.
With this patch, we dynamically switch between audio PLL1 and audio
PLL2 to support both 48KHz and 44.1KHZ rates.
Signed-off-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Old implementation uses /usr/lib/imx-mm/audio-codec
to look for codec libraries.
Also this is the patch where Yocto rootfs stores the codec
libraries. So until we align Yocto with the kernel lets
change the driver to use the old path.
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
With rpmsg sound, when the m4 image is not loaded. There is error log
[ 46.275223] imx-wm8960 sound-rpmsg-wm8960: ASoC: CODEC DAI rpmsg-wm8960-hifi not registered
[ 46.284543] imx-wm8960 sound-rpmsg-wm8960: snd_soc_register_card failed (-517)
The issue is caused by that codec is not registered, the sound
card registration will fail
So add check in probe function for codec dai is ready or not.
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
With rpmsg sound, when the m4 image is not loaded. There is error log
[ 46.257647] imx-cs42888 sound-rpmsg-cs42888: ASoC: CODEC DAI cs42888 not registered
[ 46.265413] imx-cs42888 sound-rpmsg-cs42888: snd_soc_register_card failed (-517)
The issue is that codec is not register, the sound registeration will fail
So add check in probe function for codec dai ready or not.
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
If the DSP firmware binary is already loaded it is wrong to update
SDRAM located sections because we will overwrite and data stored there.
This makes suspend/resume work.
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Finally! We register DSP as a sound card.
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
DSP driver now supports two interfaces. Old ioctl chardev based
interface and ALSA compress inteface.
Because some part of the open/close code is common introduce
two new functions which encapsulate the common functionality.
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
While at it add include guard to dsp.h
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
This is based on Xtensa Audio framework
userspace implemention API.
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
This is based on RF-2016.4-linux package received from Cadence
and introduce the API for loading shared libraries into memory.
Based on this we create xf_load_lib/xf_load_unlib functions
which are used to tell DSP framework that codec libraries
are mapped in memory and it can start using them.
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
This will allow DSP driver to create/destroy a client on
DSP audio-framework proxy.
Registering a client on remote DSP proxy means creating
a component.
The implementation is similar with userspace application
proxy implementation.
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
Memory is allocated to clients from memory pools. A memory pool
allocation is requested to DSP framework via XF_ALLOC command and
freed via XF_FREE.
Memory pool allocation API offers two functions:
* xf_pool_alloc, allocate a number of buffers of given length
* xf_pool_free, free memory area allocated for a pool.
Once a buffer pool is allocated users can handle buffers using the
following API:
* xf_buffer_get(pool), gets a buffer from a pool
* xf_buffer_put(buf), puts back a buffer into its pool
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
This commit adds 3 new function helpers for sending
messages to DSP framework and waiting for response.
While at it cleanup spaces around struct client fields.
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
xf_cmd_send_recv function returns with a lock taken
in case of success. Fix this, now!
This bug is present since the beginning of time and it didn't
show up because no one used xd_cmd_alloc/xf_cmd_free.
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>
This is a cleanup patch to have all the headers style
consistent across DSP driver.
Reviewed-by: Cosmin-Gabriel Samoila <cosmin.samoila@nxp.com>
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com
Signed-off-by: Daniel Baluta <daniel.baluta@nxp.com>