Commit Graph

138 Commits

Author SHA1 Message Date
Charles Keepax 721be3be2f ASoC: wm_adsp: Detach compressed stream on free
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-04 17:51:31 +01:00
Charles Keepax edd713509a ASoC: wm_adsp: Move compr_attach/attached functions
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-04 17:51:31 +01:00
Mark Brown 0023f8a6d5 Merge branch 'topic/arizona' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound into asoc-adsp 2016-05-04 17:51:26 +01:00
Charles Keepax 9ee78757d5 ASoC: wm_adsp: Add support for TLV based binary controls
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-05-02 15:25:52 +01:00
Richard Fitzgerald 56574d541f ASoC: wm_adsp: factor out freeing of alg regions
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-27 16:21:23 +01:00
Richard Fitzgerald 66225e98b9 ASoC: wm_adsp: free memory when unloaded or closed
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-27 16:21:23 +01:00
Charles Keepax 5847609edb ASoC: wm_adsp: Improve DSP error handling
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-06 10:15:21 -07:00
Charles Keepax 9771b18a0b ASoC: wm_adsp: Factor out fetching of stream errors from the DSP
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-04-06 10:15:21 -07:00
Charles Keepax 33d740e07d ASoC: wm_adsp: Show avail in bytes to match other messages
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-29 10:11:10 -07:00
Charles Keepax 612047f0ba ASoC: wm_adsp: Fix some subtle races on compressed stream
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-29 10:10:36 -07:00
Mark Brown 343b890871 Merge remote-tracking branches 'asoc/topic/ab8500', 'asoc/topic/adau17x1', 'asoc/topic/ads117x', 'asoc/topic/adsp' and 'asoc/topic/arizona' into asoc-next 2016-03-13 15:16:41 +07:00
Charles Keepax 5602a64318 ASoC: wm_adsp: Use correct local length in error message
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>
2016-03-11 14:21:13 +07:00
Takashi Iwai 15c665700b ASoC: wm_adsp: Fix enum ctl accesses in a wrong type
The firmware ctls like "DSP1 Firmware" in wm_adsp codec driver are
enum, while the current driver accesses wrongly via
value.integer.value[].  They have to be via value.enumerated.item[]
instead.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org
2016-03-01 12:13:12 +09:00
Charles Keepax 4f8ea6d759 ASoC: wm_adsp: wm_coeff_{read|write}_control should use passed length
wm_coeff_{read|write}_control were using the control length rather than
the length parameter passed to them. This is not causing any issues as
the two values are currently always the same, but this needs fixed to
allow future improvements.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-02-21 03:08:19 +09:00
Charles Keepax 7d00cd975a ASoC: wm_adsp: Fixup some odd line wrapping
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-02-21 03:08:19 +09:00
Charles Keepax cc815c4b86 ASoC: wm_adsp: Explicitly set the control access flags in all cases
In the case where the firmware does not tell us the access flags for the
control, we let ALSA select a default (READWRITE). But really we should
be applying the volatile flag in this case, as we will read the control
from the DSP if it is on in this case. This patch explicitly sets the
access flags in all cases.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-02-21 03:08:19 +09:00
Charles Keepax c7dae7c4c6 ASoC: wm_adsp: Avoid narrow race condition on compr pointer
There is a very small window between then wm_adsp_compr_free gets call
and when the DSP is actually powered down. If we get an IRQ from the DSP
in this window then the wm_adsp_compr pointer will be NULL. This patch
adds a check for this into the IRQ handler to avoid any issues when this
happens.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-02-21 03:08:19 +09:00
Charles Keepax da2b335890 ASoC: wm_adsp: Return sample rate in wm_adsp_compr_pointer
We should return a valid sample rate from the pointer callback, this
patch adds this into the driver.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-02-02 19:27:11 +00:00
Charles Keepax 3a9686c4ba ASoC: wm_adsp: Add missing const from region definitions
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-02-02 19:19:44 +00:00
Charles Keepax 31889507fd ASoC: wm5110: Add support for audio trace firmware
Mainly this adds DAI links for the audio trace, however, it is also
necessary to update the data IRQ handler to check more cores. We have
the handler check every core so it should not be necessary to update
this function if more compressed firmwares are added in the future.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-01-29 12:38:01 +01:00
Charles Keepax d82d767f0e ASoC: wm_adsp: Move setting of DSP speed into CODEC specific code
The ADSP code should be agnostic of which CODEC it runs upon, currently
there is only one remaining part of the implementation that doesn't
follow this. When the DSP is booted on ADSP2 we read
ARIZONA_SYSTEM_CLOCK_1 and use that to set the initial speed for the DSP
clock. This patch factors that out into CODEC specific code, leaving the
ADSP code entirely CODEC agnostic.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-01-29 00:31:46 +01:00
Charles Keepax 7ce4283ca4 ASoC: wm_adsp: Add debug audio trace firmware
The audio trace firmware allows the capture of arbitrary streams of
audio from the DSP and commonly used for debugging other firmwares. This
patch adds support for this firwmare into the ADSP driver.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-01-29 00:31:46 +01:00
Charles Keepax e6d00f3403 ASoC: wm_adsp: Use more generic naming for regions and caps definitions
The region definition will be shared by most firmwares so give this a
more generic name and whilst we are there improve the naming of the
voice control capabilities array as well.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-01-29 00:31:46 +01:00
Charles Keepax 83a40ce993 ASoC: wm_adsp: Pull data through compressed read
Data is read in blocks of up to one fragment is size from the circular
buffer on the DSP and is re-packed to remove the padding byte that
exists in the DSP memory map.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-01-06 17:44:17 +00:00
Charles Keepax 565ace4641 ASoC: wm_adsp: Add a handler for the compressed IRQ
Here support is added for responding to DSP IRQs that are used to
indicate data being available on the DSP. The idea is that we check the
amount of data available upon receipt of an IRQ and on subsequent calls
to the pointer callback we recheck once less than one fragment is
available (to avoid excessive SPI traffic), if there is truely less than
one fragment available we ack the last IRQ and wait for a new one.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2016-01-06 17:44:17 +00:00
Charles Keepax 95fe9597d2 ASoC: wm_adsp: Attach buffers and streams together
The stream is created whilst the compressed stream is opened and a
buffer is created when the DSP powers up. It is necessary at a point
once both the DSP has powered up and the the stream has been opened to
connect a stream to a buffer on the DSP. This is done in the trigger
callback as this is after the DSP has been powered and obviously the
stream must be open. Note that whilst the connect is currently trivial
it is expected that this will get more complex when support for multiple
buffers/streams per DSP is added.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-12-23 00:20:50 +00:00
Charles Keepax 2cd19bdbf8 ASoC: wm_adsp: Add code to locate and initialise compressed buffer
Add code that locates and initialises the buffer of compressed data on
the DSP if the firmware supported compressed data capture. The buffer
struct (wm_adsp_compr_buf) is kept separate from the stream struct
(wm_adsp_compr) this will allow much easier support of multiple
streams of data from the one DSP in the future, although support for
this will not be added in this patch chain.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-12-23 00:20:50 +00:00
Charles Keepax 406abc95a0 ASoC: wm_adsp: Add support for opening a compressed stream
Allow user-space to open a compressed stream, although no data will be
passed yet, as part of this adding the ability to define supported
capabilities per firmware and check these match the stream being opened.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-12-23 00:20:50 +00:00
Charles Keepax 14197095e1 ASoC: wm_adsp: Factor out finding the location of an algorithm region
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-12-23 00:20:50 +00:00
Charles Keepax bc1765d6e8 ASoC: wm_adsp: Mimic legacy behaviour of reading controls when DSP is on
Older firmwares don't specify access flags for the controls,
unfortunately the usage of some of these firmware relies on being able
to read back values from the DSP. The current control code will only do
this for volatile controls. This patch will read the control from the
hardware if no flags are specified and the control is currently
enabled, which should cover these legacy use-cases.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-12-17 12:13:08 +00:00
Charles Keepax 168d10e74c ASoC: wm_adsp: Add locking to DSP firmware controls
Locking is currently missing from the DSP firmware controls, which can
lead to some race conditions if the controls are accessed as the DSP
powers up or down. This patch adds them to the new power lock.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-12-12 22:43:21 +00:00
Charles Keepax 7585a5b0ab ASoC: wm_adsp: Fixup some minor formatting and checkpatch errors
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-12-12 22:43:15 +00:00
Charles Keepax d27c5e155c ASoC: wm_adsp: Add power lock for firmware change control
We should hold the DSP power lock whilst changing the firmware since we
need to check if it is running first.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-12-12 22:43:15 +00:00
Charles Keepax 078e71838c ASoC: wm_adsp: Replace debugfs lock with more general DSP power lock
Most events around the DSP just need to be locked to ensure that the DSP
can't change power state whilst they are happening. This includes the
debugfs entries and this will make sorting the rest of the locking
simpler.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-12-12 22:43:13 +00:00
Charles Keepax 04d1300fd3 ASoC: wm_adsp: Expand the list of available firmwares
Expand the list of available firmware names to include a good selection
of generic uses for the DSP cores.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-11-27 12:23:40 +00:00
Richard Fitzgerald 336d0442b9 ASoC: wm_adsp: Move DSP Rate controls into the codec
The rate controls are codec-specific, it's not possible to
generically say what the range or the meaning of each control
is (or even if they exist at all) - that depends on the
particular codec.

This is currently being handled for Arizona codecs by putting
an Arizona-specific table of controls inside the wm_adsp driver.
This creates a dependency between wm_adsp and arizona.c, and is an
awkward solution if the ADSP is used in another family of codecs

Fix this by moving the Arizona-specific rate controls into the
Arizona codec drivers.

Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-06-19 11:17:23 +01:00
Richard Fitzgerald f9f55e31f8 ASoC: wm_adsp: Add basic debugfs entries
This patch adds some debugfs nodes to get information
about the currently running firmware.

Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-06-11 11:39:39 +01:00
Richard Fitzgerald 218e508784 ASoC: wm_adsp: create ALSA controls from wm_adsp driver
Now that we have a codec_probe stage initialization in the wm_adsp
driver, we can make the wm_adsp driver create its own ALSA controls
instead of having that responsibility pushed to every codec driver.

Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-06-11 11:39:39 +01:00
Richard Fitzgerald f5e2ce92bd ASoC: wm_adsp: Add codec_probe and codec_remove stubs
Currently the only init function in wm_adsp is called by the
codec driver early in its probe before the codec has been
registered with SOC.

This patch adds stubs for the codec_probe and codec_remove stages
and calls them from WM5102 and WM5110 codec drivers. This allows us
to hang anything that needs setup during the codec probe stage off
these functions without further modification of the codec drivers.

Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-06-11 11:39:39 +01:00
Richard Fitzgerald 81ac58b13f ASoC: wm_adsp: Move DVFS control into codec driver
In theory the ADSP driver should not need to know anything
about the codec it is part of. But the WM5102 needs DVFS
control based on ADSP clocking speed. This was being handled
by bundling part of the knowledge of this into the ADSP driver.

This change moves this handling out of the ADSP driver and
into the WM5102 driver.

Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-06-02 21:07:20 +01:00
Richard Fitzgerald 10337b070d ASoC: wm_adsp: Dump scratch registers on DSP shutdown
The SCRATCH registers are used by firmwares to hold diagnostic
information. Log this during shutdown to assist analysis and debug
of firmwares.

Signed-off-by: Richard Fitzgerald <rf@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-05-29 10:37:34 +01:00
Charles Keepax 26c22a1922 ASoC: wm_adsp: Add support for DSP control flags
The DSP control information contains various hints about the usage of
the control use these when handling the control.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-04-27 15:38:26 +01:00
Charles Keepax 8299ee8123 ASoC: wm_adsp: Use __leXX for little endian data
Using uXX for little endian data, was triggering some warnings through
sparse:

sound/soc/codecs/wm_adsp.c:716:26: sparse: cast to restricted __le16
sound/soc/codecs/wm_adsp.c:736:23: sparse: cast to restricted __le16
sound/soc/codecs/wm_adsp.c:739:23: sparse: cast to restricted __le32

Correct this by changing the casts to use __leXX instead of uXX.

Reported-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-04-27 15:38:26 +01:00
Charles Keepax c61e59fe4d ASoC: wm_adsp: Warn that firmware file format 0 is depreciated
There are very few version 0 firmwares in the wild and at some point in
the future it would be nice to remove support for them from the driver,
as they require several work arounds to be present to create controls
properly.

This patch adds a depreciated warning if someone is using this file
format.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-04-27 15:38:25 +01:00
Charles Keepax cb5b57a9a4 ASoC: wm_adsp: Add support for rev 2 firmware file format
Version 2 of the firmware file format includes length fields for the
various strings associated with control creation, to reduce file size.
However this does increase the parsing complexity slightly. This patch
adds support for the revision of the file format.

This patch also adds a new naming scheme for controls created from rev 2
firmware files. This version of the file format is commonly used to
add multiple controls per algorithm per memory region and the old
control naming scheme would cause multiple controls to have the same
name in this case.. Note that the naming scheme for older firmware
versions is left intact to ensure backwards compatibility.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-04-27 15:38:25 +01:00
Charles Keepax 2323736dca ASoC: wm_adsp: Add basic support for rev 1 firmware file format
Revision one of the file format includes new algorithm and coefficient
blocks which provide additional information about the controls exported
by the firmware. This patch updates the processing to handle this
version of the file format. Note that whilst this version of the format
adds support for specifying a name for the control through the firmware
file this has not been used and to keep compatibility with existing
deployments no changes to the firmware control naming are made by this
patch.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-04-27 15:38:25 +01:00
Charles Keepax b21acc1c37 ASoC: wm_adsp: Group all the ALSA control functions together
This is slightly logically better and avoids some unnecessary forward
declarations in the following refactoring.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-04-27 15:38:25 +01:00
Charles Keepax ec184cfcb9 ASoC: wm_adsp: Remove private field from wm_coeff_ctl
The private field in wm_coeff_ctl is currently unused and given the
controls are entirely handled within the ADSP code it is not clear what
it would be used for in the future. Remove the field for now it can be
readded if it is ever required.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-04-27 15:38:25 +01:00
Charles Keepax d9d20e17ea ASoC: wm_adsp: Factor out creation of alg_regions
Tidy up the code a little by factoring out the creation of the algorithm
regions.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-04-27 15:38:24 +01:00
Charles Keepax c9f8dd712e ASoC: wm_adsp: Clean up low level control read/write functions
Physically reading and writing controls to/from the DSP are handled by
two low level functions (wm_coeff_{write|read}_control, these currently
take in a snd_kcontrol pointer but immediately pull out a wm_coeff_ctl
pointer from the private data. These functions don't handle the kcontrols
at all they just shuttle data to and from the chip and all the call
sites have a wm_coeff_ctl pointer available. This patch just passes the
wm_coeff_ctl pointer straight into these functions.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
2015-04-27 15:38:24 +01:00