summaryrefslogtreecommitdiff
path: root/sound/soc/codecs/wm_adsp.c
AgeCommit message (Collapse)Author
2018-03-28Merge remote-tracking branches 'asoc/topic/arizona', 'asoc/topic/atmel', ↵Mark Brown
'asoc/topic/bd28623', 'asoc/topic/blackfin' and 'asoc/topic/bt-sco' into asoc-next
2018-02-28ASoC: wm_adsp: For TLV controls only register TLV get/setRichard Fitzgerald
Normal 512-byte get/set of a TLV isn't supported but we were registering the normal get/set anyway and relying on omitting the SNDRV_CTL_ELEM_ACCESS_[READ|WRITE] flags to prevent them being called. Trouble is if this gets broken in the core ALSA code - as it has been since at least 4.14 - the standard get/set can be called unexpectedly and corrupt memory. There's no point providing functions that won't be called and it's a trivial change. The benefit is that if the ALSA core gets broken again we get a big fat immediate NULL dereference instead of a memory corruption timebomb. Signed-off-by: Richard Fitzgerald <rf@opensource.cirrus.com> Signed-off-by: Mark Brown <broonie@kernel.org> Cc: stable@vger.kernel.org
2018-02-14ASoC: arizona: replace codec to componentKuninori Morimoto
Now we can replace Codec to Component. Let's do it. Because there are many drivers which are using arizona, we need to update these all related drivers in same time. Otherwise compile error/warning happen Note: cs47l24 xxx_codec_xxx() -> xxx_component_xxx() .idle_bias_off = 1 -> .idle_bias_on = 0 .ignore_pmdown_time = 0 -> .use_pmdown_time = 1 - -> .endianness = 1 - -> .non_legacy_dai_naming = 1 wm5102 xxx_codec_xxx() -> xxx_component_xxx() .idle_bias_off = 1 -> .idle_bias_on = 0 .ignore_pmdown_time = 0 -> .use_pmdown_time = 1 - -> .endianness = 1 - -> .non_legacy_dai_naming = 1 wm5110 xxx_codec_xxx() -> xxx_component_xxx() .idle_bias_off = 1 -> .idle_bias_on = 0 .ignore_pmdown_time = 0 -> .use_pmdown_time = 1 - -> .endianness = 1 - -> .non_legacy_dai_naming = 1 wm8997 xxx_codec_xxx() -> xxx_component_xxx() .idle_bias_off = 1 -> .idle_bias_on = 0 .ignore_pmdown_time = 0 -> .use_pmdown_time = 1 - -> .endianness = 1 - -> .non_legacy_dai_naming = 1 wm8998 xxx_codec_xxx() -> xxx_component_xxx() .idle_bias_off = 1 -> .idle_bias_on = 0 .ignore_pmdown_time = 0 -> .use_pmdown_time = 1 - -> .endianness = 1 - -> .non_legacy_dai_naming = 1 Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Tested-by: Charles Keepax <ckeepax@opensource.cirrus.com> Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2017-12-08ASoC: wm_adsp: Fix validation of firmware and coeff lengthsBen Hutchings
The checks for whether another region/block header could be present are subtracting the size from the current offset. Obviously we should instead subtract the offset from the size. The checks for whether the region/block data fit in the file are adding the data size to the current offset and header size, without checking for integer overflow. Rearrange these so that overflow is impossible. Signed-off-by: Ben Hutchings <ben.hutchings@codethink.co.uk> Acked-by: Charles Keepax <ckeepax@opensource.cirrus.com> Tested-by: Charles Keepax <ckeepax@opensource.cirrus.com> Signed-off-by: Mark Brown <broonie@kernel.org> Cc: stable@vger.kernel.org
2017-05-26ASoC: wm_adsp: Fix typo in algorithm list warning messageRichard Fitzgerald
The list terminator is 0xbedead but the message warning if it wasn't found was showing that 0xbeadead was expected. Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2017-05-24ASoC: wm_adsp: Remove unused member of struct wm_coeff_ctl_opsRichard Fitzgerald
The xinfo member of struct wm_coeff_ctl_ops is never used. Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2017-05-24ASoC: wm_adsp: Fix type warning in sprintfRichard Fitzgerald
The shift member of struct soc_mixer_control is unsigned int. Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2017-04-05ASoC: wm_adsp: add support for DSP region lockMayuresh Kulkarni
Newer ADSP2V2 codecs include a memory protection unit that can be set to trap illegal accesses. When enabling an ADSPV2 core we must configure the memory region traps so that the firmware can access its own memory. Signed-off-by: Mayuresh Kulkarni <mkulkarni@opensource.wolfsonmicro.com> Signed-off-by: Nikesh Oswal <Nikesh.Oswal@wolfsonmicro.com> Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2017-04-05ASoC: wm_adsp: Add support for ADSP2V2Richard Fitzgerald
Adds support for ADSP2V2 cores. Primary differences are that they use a 32-bit register map compared to the 16-bit register map of ADSP2V1, and there are some changes to clocking control. Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2017-03-07ASoC: wm_adsp: Acknowledge controls should also check the DSP is runningCharles Keepax
We should not be writing acknowledge controls until the firmware is running, as in the case of preloaded firmwares the DSP memory may be unaccessible to whilst in the preloaded state. This means a write to the control during this time could be lost. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2017-03-07ASoC: wm_adsp: Return an error on write to a disabled volatile controlCharles Keepax
Volatile controls should only be accessed when the firmware is active, currently however writes to these controls will succeed, but the data will be lost, if the firmware is powered down. Update this behaviour such that an error is returned the same as it is for reads. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2017-02-19Merge remote-tracking branches 'asoc/topic/adau17x1', 'asoc/topic/adsp', ↵Mark Brown
'asoc/topic/ak4642', 'asoc/topic/amd' and 'asoc/topic/arizona' into asoc-next
2017-01-24ASoC: wm_adsp: Fixup wm_adsp2_boot_work error pathsCharles Keepax
Currently we are not disabling MEM_ENA on the error path, we should really do this to unwind the state back to how it was. This patch adds a clear of MEM_ENA on the error path, again there is no major issues caused by this minor fix. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2017-01-24ASoC: wm_adsp: Set booted/running flags at the end of bring upCharles Keepax
The booted and running flags should really only be set once all the steps at that power level have been complete. Currently operations can fail after the flags have been set, which would leave us in an inconsistent state where the flags are set but the things expected to reach that level have not happened. Whilst there isn't really any major impact from this it is best to clean it up. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2017-01-24ASoC: wm_adsp: Correct some missing lockingCharles Keepax
The recent refactoring overlooked some places which should be covered by the pwr_lock, all code that affects or depends on the power status of the DSP should be covered, this patch adds the missing coverage. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2017-01-06ASoC: wm_adsp: Add mechanism to preload firmware on a coreCharles Keepax
As requirements to bring up audio paths are continuous getting tighter and the DSP download to most ADSP devices happens over an external bus it can become an important factor in the path bring up time. As such sometimes it is a reasonable trade off to download the firmware ahead of when it will be required and take a small hit on power consumption for keeping the core powered up. This "preloading" adds an additional control for each DSP core "DSPx Preload Switch" that when set to true will power up the DSP core and download the firmware currently selected in the "DSPx Firmware" control. Whilst the core is preloaded the current firmware can not be changed and the CODEC will be kept powered up and SYSCLK held on. Although future improvements may allow the SYSCLK to be powered down as well because the hardware only requires SYSCLK whilst the download is actually taking place, but this is not covered in this series. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-12-20ASoC: wm_adsp: Don't overrun firmware file buffer when reading region dataRichard Fitzgerald
Protect against corrupt firmware files by ensuring that the length we get for the data in a region actually lies within the available firmware file data buffer. Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-12-12ASoC: wm_adsp: wm_adsp_buf_alloc should use kfree in error pathRichard Fitzgerald
buf was allocated by kzalloc() so it should be passed to kfree() Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-11-22ASoC: wm_adsp: Check return value from wm_adsp_buffer_initCharles Keepax
We are not checking the return value from a call to wm_adsp_buffer_init it looks like this used to be returned at the bottom of the function but probably got missed when more error paths were added. This patch adds the appropriate error check. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-11-22ASoC: wm_adsp: Remove unused wm_coeff_ctl.kcontrolRichard Fitzgerald
The kcontrol pointer in wm_coeff_ctl is not used now. Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-11-22ASoC: wm_adsp: Firmware controls should be added as codec controlsRichard Fitzgerald
We were adding firmware controls as card controls (using snd_soc_add_codec_controls). The DSP is part of a specific codec so we should be adding them as codec controls. Adding as codec controls also means that if the codec has a name_prefix it will be added to the control name, which won't happen when adding as a card control. As that was the only use of the card pointer in struct wm_adsp it can be removed. For ADSP2 codecs a wm_adsp2_codec_probe() was added since the original control handling was written, and that's the logical place to store a pointer to the codec rather than delaying it until the codec is powered-up. For ADSP1 we don't use a codec_probe() stage so the codec pointer initialization replaces the original card pointer initialization in wm_adsp1_event(). Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-11-21ASoC: wm_adsp: Only write shutdown controls for active firmwaresCharles Keepax
The control list may contain shutdown controls for firmwares that are not currently active, attempting to write this will at best fail. To avoid this issue we skip any control that is not active. Fixes: commit f4f0c4c60c39 ("ASoC: wm_adsp: Signal firmware shutdown through event control") Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-11-14ASoC: wm_adsp: factor out getting base register for a controlRichard Fitzgerald
The lookup of the base register corresponding to a control is duplicated in read and write so factor it out into a separate function. Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-11-11ASoC: wm_adsp: Support acknowledged controlsRichard Fitzgerald
This patch handles publishing acknowledged controls through ALSA. These controls allow user-side to send events to the firmware and wait for the firmware to acknowledge it. Note that although acked controls only operate in the direction host->firmware, and therefore they are write-only as seen from user- side code, we have to make them readable to account for all the code out there that assumes that ALSA controls are always readable (amixer for example.) Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-11-11ASoC: wm_adsp: Add support for SYSTEM firmware controlsStuart Henderson
Add support for firmware controls marked SYSTEM. These are internal to the driver-firmware interface and do not have a user-accessible ALSA control. Signed-off-by: Stuart Henderson <stuarth@opensource.wolfsonmicro.com> Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-11-11ASoC: wm_adsp: factor out getting region name from typeRichard Fitzgerald
This patch factors out converting a memory region type into a name string, mainly so that it can be used in log commands. Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-11-11ASoC: wm_adsp: Signal firmware shutdown through event controlRichard Fitzgerald
If the firmware has any system event signalling controls, signal them during DSP PRE_PMD to tell the firmware it is about to be stopped. Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-10-21ASoC: wm_adsp: Remove duplicate set of kcontrol->ifaceRichard Fitzgerald
Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-09-26ASoC: wm_adsp: Allow preloader to do the final shutdown of the DSPCharles Keepax
The booting process for the DSP is clearly separated into two parts, the preloader brings up the core and downloads code, then the main widget starts the code actually executing. However the shutdown sequence is all handled with the main widget. To allow the preloading to be run independently of the main audio bring up it makes sense, and is generally just cleaner, for the preloader widget to shutdown those things it initialised. This patch moves the appropriate parts of the shutdown process into the preloader widget. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-09-26ASoC: wm_adsp: Put DSP into low power state between loading and runningCharles Keepax
Between when we load the DSP and when it actually starts running put the core into a lower power state where the memory is retained but nothing is clocked. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-09-26ASoC: wm_adsp: Use usleep_range for short delayCharles Keepax
Replace the 1ms msleep in wm_adsp2_ena with a usleep_range, as per normal guidance on delay functions. Also tighten up the delay a little as 1ms was quite generous. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-09-24ASoC: wm_adsp: Move control cache sync out of preloaderCharles Keepax
As part of the work to download firmware before the audio path is brought up the DSP will be put into a low power state between downloading firmware to the core and starting it running. This will mean that the firmware ALSA controls are not accessible in the hardware during this period of time. To prepare for this change we gate access to the hardware in the ALSA control handlers on the DSP being running rather than simply booted and move the synchronisation of the control caches out of the preloader delayed work and into the main DAPM thread after the DSP will have been brought out of its low power state. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-09-24ASoC: wm_adsp: Separate concept of booted and runningCharles Keepax
Currently the wm_adsp driver has a flag that indicates the DSP is "running", this flag is used to gate access to the hardware. However this flag is actually set in the firmware download thread after the firmware has been downloaded, but this is before the core is actually started running, so really it currently indicates that the core has been booted and is perhaps running. This patch clearly separates out the concepts of booted (firmware is downloaded) and running (code is executing on the DSP) within the wm_adsp driver. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-07-24Merge remote-tracking branches 'asoc/topic/arizona', 'asoc/topic/atmel', ↵Mark Brown
'asoc/topic/bt-sco', 'asoc/topic/compress' and 'asoc/topic/cs35l33' into asoc-next
2016-06-22ASoC: wm_adsp: Disable DMAs before clearing the transfer lengthSimon Trimmer
This patch reorders the clearing of the DMA masks to avoid potential artefacts being introduced. Signed-off-by: Simon Trimmer <simont@opensource.wolfsonmicro.com> Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-06-13ASoC: wm_adsp: Treat missing compressed buffer as a fatal errorCharles Keepax
If the DSP is powered down whilst a compressed stream is being processed we should treat this as a fatal error, clearly the stream is no longer valid. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-06-13ASoC: wm_adsp: Use new snd_compr_stop_error to signal stream failureCharles Keepax
If we encounter a fatal error on the compressed stream call the new snd_compr_stop_error to shutdown the stream and allow the core to inform user-space that the stream is no longer valid. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Reviewed-by: Vinod Koul <vinod.koul@intel.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-05-30ASoC: wm_adsp: Specifically propagate voice trigger event to callerCharles Keepax
The DSP uses an IRQ to indicate data is available on the compressed stream. For voice trigger use-cases the first such IRQ can be considered an indication that the user has spoken the key phrase triggering the firmware. Provide a means for the ADSP code to communicate back to the calling driver whether an IRQ should be considered as trigger event or not. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-05-04ASoC: wm_adsp: Detach compressed stream on freeCharles Keepax
If someone powers down the DSP core (through routing changes say) whilst a compressed record is in progress we can end up using a freed pointer to the buffer object. When a compressed audio stream is triggered we attach it to a buffer on a physical DSP. This patch adds a detach of the buffer from the stream when the stream is freed or when the DSP is powered down which avoids the situation where we use a buffer when it is no longer valid. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-05-04ASoC: wm_adsp: Move compr_attach/attached functionsCharles Keepax
Move wm_adsp_compr_attach and wm_adsp_compr_attached functions so they will stay logically grouped with similar functions after some additional changes. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-05-04Merge branch 'topic/arizona' of ↵Mark Brown
git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound into asoc-adsp
2016-05-02ASoC: wm_adsp: Add support for TLV based binary controlsCharles Keepax
This patch adds support for the arbitrary length TLV based binary controls. This allows users to properly access controls that are more than 512 bytes in length. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-04-27ASoC: wm_adsp: factor out freeing of alg regionsRichard Fitzgerald
Add a function to delete and free the contents of the alg_regions list. Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-04-27ASoC: wm_adsp: free memory when unloaded or closedRichard Fitzgerald
The patch adds a wm_adsp2_remove() function to ensure that memory is freed when the driver is unloaded or shut down. Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-04-06ASoC: wm_adsp: Improve DSP error handlingCharles Keepax
If we encounter an error on the DSP side whilst user-space is waiting on the poll we should call snd_compr_fragment_elapsed, although data is not actually available we want to wake user-space such that the error can be propagated out quickly. Additionally some versions of the DSP firmware are not super consistent about actually generating an IRQ if they encounter an error, as such we will check the DSP error status every time we run out of available data as well, to ensure we catch it. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-04-06ASoC: wm_adsp: Factor out fetching of stream errors from the DSPCharles Keepax
Factor out the reading of the DSP error flag into its own function to support further improvements to the code. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-03-29ASoC: wm_adsp: Show avail in bytes to match other messagesCharles Keepax
All other debug messages talk about data on the compressed stream in bytes except avail which is shown in words. To avoid confusion show avail in bytes as well. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-03-29ASoC: wm_adsp: Fix some subtle races on compressed streamCharles Keepax
Firstly, we should be locking the pwr_lock when we initialise the compressed buffer. Secondly, fixup a couple of places when we should be pulling pointers only under the pwr_lock as they may be affected by operations that take that lock. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
2016-03-13Merge remote-tracking branches 'asoc/topic/ab8500', 'asoc/topic/adau17x1', ↵Mark Brown
'asoc/topic/ads117x', 'asoc/topic/adsp' and 'asoc/topic/arizona' into asoc-next
2016-03-11ASoC: wm_adsp: Use correct local length in error messageCharles Keepax
Fixes: 44029e9e1290 ("ASoC: wm_adsp: wm_coeff_{read|write}_control should use passed length") Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>