Skip to content

Commit 092cf7b

Browse files
crojewsk-intelbroonie
authored andcommitted
ASoC: Intel: avs: Code loading over HDA
Compared to SKL and KBL, more recent cAVS platforms are meant to re-use one of HDAudio streams during boot procedure causing CLDMA to become obsolete. Once transferred, given stream is returned to pool available for audio streaming. Module loading handler is stub as library and module code became inseparable in later firmware generations. Signed-off-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com> Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com> Link: https://lore.kernel.org/r/20220311153544.136854-18-cezary.rojewski@intel.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 65794fe commit 092cf7b

File tree

3 files changed

+220
-0
lines changed

3 files changed

+220
-0
lines changed

sound/soc/intel/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ config SND_SOC_INTEL_AVS
215215
depends on COMMON_CLK
216216
select SND_SOC_ACPI
217217
select SND_HDA_EXT_CORE
218+
select SND_HDA_DSP_LOADER
218219
help
219220
Enable support for Intel(R) cAVS 1.5 platforms with DSP
220221
capabilities. This includes Skylake, Kabylake, Amberlake and

sound/soc/intel/avs/avs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ struct avs_dsp_ops {
4444
((adev)->spec->dsp_ops->op(adev, ## __VA_ARGS__))
4545

4646
#define AVS_PLATATTR_CLDMA BIT_ULL(0)
47+
#define AVS_PLATATTR_IMR BIT_ULL(1)
4748

4849
#define avs_platattr_test(adev, attr) \
4950
((adev)->spec->attributes & AVS_PLATATTR_##attr)
@@ -238,5 +239,9 @@ int avs_cldma_load_basefw(struct avs_dev *adev, struct firmware *fw);
238239
int avs_cldma_load_library(struct avs_dev *adev, struct firmware *lib, u32 id);
239240
int avs_cldma_transfer_modules(struct avs_dev *adev, bool load,
240241
struct avs_module_entry *mods, u32 num_mods);
242+
int avs_hda_load_basefw(struct avs_dev *adev, struct firmware *fw);
243+
int avs_hda_load_library(struct avs_dev *adev, struct firmware *lib, u32 id);
244+
int avs_hda_transfer_modules(struct avs_dev *adev, bool load,
245+
struct avs_module_entry *mods, u32 num_mods);
241246

242247
#endif /* __SOUND_SOC_INTEL_AVS_H */

sound/soc/intel/avs/loader.c

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/firmware.h>
1010
#include <linux/module.h>
1111
#include <linux/slab.h>
12+
#include <sound/hdaudio.h>
1213
#include <sound/hdaudio_ext.h>
1314
#include "avs.h"
1415
#include "cldma.h"
@@ -18,8 +19,11 @@
1819
#define AVS_ROM_STS_MASK 0xFF
1920
#define AVS_ROM_INIT_DONE 0x1
2021
#define SKL_ROM_BASEFW_ENTERED 0xF
22+
#define APL_ROM_FW_ENTERED 0x5
2123
#define AVS_ROM_INIT_POLLING_US 5
2224
#define SKL_ROM_INIT_TIMEOUT_US 1000000
25+
#define APL_ROM_INIT_TIMEOUT_US 300000
26+
#define APL_ROM_INIT_RETRIES 3
2327

2428
#define AVS_FW_INIT_POLLING_US 500
2529
#define AVS_FW_INIT_TIMEOUT_US 3000000
@@ -261,6 +265,207 @@ int avs_cldma_transfer_modules(struct avs_dev *adev, bool load,
261265
return 0;
262266
}
263267

268+
static int
269+
avs_hda_init_rom(struct avs_dev *adev, unsigned int dma_id, bool purge)
270+
{
271+
const struct avs_spec *const spec = adev->spec;
272+
unsigned int corex_mask, reg;
273+
int ret;
274+
275+
corex_mask = spec->core_init_mask & ~AVS_MAIN_CORE_MASK;
276+
277+
ret = avs_dsp_op(adev, power, spec->core_init_mask, true);
278+
if (ret < 0)
279+
goto err;
280+
281+
ret = avs_dsp_op(adev, reset, AVS_MAIN_CORE_MASK, false);
282+
if (ret < 0)
283+
goto err;
284+
285+
reinit_completion(&adev->fw_ready);
286+
avs_dsp_op(adev, int_control, true);
287+
288+
/* set boot config */
289+
ret = avs_ipc_set_boot_config(adev, dma_id, purge);
290+
if (ret) {
291+
ret = AVS_IPC_RET(ret);
292+
goto err;
293+
}
294+
295+
/* await ROM init */
296+
ret = snd_hdac_adsp_readq_poll(adev, spec->rom_status, reg,
297+
(reg & 0xF) == AVS_ROM_INIT_DONE ||
298+
(reg & 0xF) == APL_ROM_FW_ENTERED,
299+
AVS_ROM_INIT_POLLING_US, APL_ROM_INIT_TIMEOUT_US);
300+
if (ret < 0) {
301+
dev_err(adev->dev, "rom init timeout: %d\n", ret);
302+
goto err;
303+
}
304+
305+
/* power down non-main cores */
306+
if (corex_mask) {
307+
ret = avs_dsp_op(adev, power, corex_mask, false);
308+
if (ret < 0)
309+
goto err;
310+
}
311+
312+
return 0;
313+
314+
err:
315+
avs_dsp_core_disable(adev, spec->core_init_mask);
316+
return ret;
317+
}
318+
319+
static int avs_imr_load_basefw(struct avs_dev *adev)
320+
{
321+
int ret;
322+
323+
/* DMA id ignored when flashing from IMR as no transfer occurs. */
324+
ret = avs_hda_init_rom(adev, 0, false);
325+
if (ret < 0) {
326+
dev_err(adev->dev, "rom init failed: %d\n", ret);
327+
return ret;
328+
}
329+
330+
ret = wait_for_completion_timeout(&adev->fw_ready,
331+
msecs_to_jiffies(AVS_FW_INIT_TIMEOUT_MS));
332+
if (!ret) {
333+
dev_err(adev->dev, "firmware ready timeout\n");
334+
avs_dsp_core_disable(adev, AVS_MAIN_CORE_MASK);
335+
return -ETIMEDOUT;
336+
}
337+
338+
return 0;
339+
}
340+
341+
int avs_hda_load_basefw(struct avs_dev *adev, struct firmware *fw)
342+
{
343+
struct snd_pcm_substream substream;
344+
struct snd_dma_buffer dmab;
345+
struct hdac_ext_stream *estream;
346+
struct hdac_stream *hstream;
347+
struct hdac_bus *bus = &adev->base.core;
348+
unsigned int sdfmt, reg;
349+
int ret, i;
350+
351+
/* configure hda dma */
352+
memset(&substream, 0, sizeof(substream));
353+
substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
354+
estream = snd_hdac_ext_stream_assign(bus, &substream,
355+
HDAC_EXT_STREAM_TYPE_HOST);
356+
if (!estream)
357+
return -ENODEV;
358+
hstream = hdac_stream(estream);
359+
360+
/* code loading performed with default format */
361+
sdfmt = snd_hdac_calc_stream_format(48000, 1, SNDRV_PCM_FORMAT_S32_LE, 32, 0);
362+
ret = snd_hdac_dsp_prepare(hstream, sdfmt, fw->size, &dmab);
363+
if (ret < 0)
364+
goto release_stream;
365+
366+
/* enable SPIB for hda stream */
367+
snd_hdac_ext_stream_spbcap_enable(bus, true, hstream->index);
368+
ret = snd_hdac_ext_stream_set_spib(bus, estream, fw->size);
369+
if (ret)
370+
goto cleanup_resources;
371+
372+
memcpy(dmab.area, fw->data, fw->size);
373+
374+
for (i = 0; i < APL_ROM_INIT_RETRIES; i++) {
375+
unsigned int dma_id = hstream->stream_tag - 1;
376+
377+
ret = avs_hda_init_rom(adev, dma_id, true);
378+
if (!ret)
379+
break;
380+
dev_info(adev->dev, "#%d rom init fail: %d\n", i + 1, ret);
381+
}
382+
if (ret < 0)
383+
goto cleanup_resources;
384+
385+
/* transfer firmware */
386+
snd_hdac_dsp_trigger(hstream, true);
387+
ret = snd_hdac_adsp_readl_poll(adev, AVS_FW_REG_STATUS(adev), reg,
388+
(reg & AVS_ROM_STS_MASK) == APL_ROM_FW_ENTERED,
389+
AVS_FW_INIT_POLLING_US, AVS_FW_INIT_TIMEOUT_US);
390+
snd_hdac_dsp_trigger(hstream, false);
391+
if (ret < 0) {
392+
dev_err(adev->dev, "transfer fw failed: %d\n", ret);
393+
avs_dsp_core_disable(adev, AVS_MAIN_CORE_MASK);
394+
}
395+
396+
cleanup_resources:
397+
/* disable SPIB for hda stream */
398+
snd_hdac_ext_stream_spbcap_enable(bus, false, hstream->index);
399+
snd_hdac_ext_stream_set_spib(bus, estream, 0);
400+
401+
snd_hdac_dsp_cleanup(hstream, &dmab);
402+
release_stream:
403+
snd_hdac_ext_stream_release(estream, HDAC_EXT_STREAM_TYPE_HOST);
404+
405+
return ret;
406+
}
407+
408+
int avs_hda_load_library(struct avs_dev *adev, struct firmware *lib, u32 id)
409+
{
410+
struct snd_pcm_substream substream;
411+
struct snd_dma_buffer dmab;
412+
struct hdac_ext_stream *estream;
413+
struct hdac_stream *stream;
414+
struct hdac_bus *bus = &adev->base.core;
415+
unsigned int sdfmt;
416+
int ret;
417+
418+
/* configure hda dma */
419+
memset(&substream, 0, sizeof(substream));
420+
substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
421+
estream = snd_hdac_ext_stream_assign(bus, &substream,
422+
HDAC_EXT_STREAM_TYPE_HOST);
423+
if (!estream)
424+
return -ENODEV;
425+
stream = hdac_stream(estream);
426+
427+
/* code loading performed with default format */
428+
sdfmt = snd_hdac_calc_stream_format(48000, 1, SNDRV_PCM_FORMAT_S32_LE, 32, 0);
429+
ret = snd_hdac_dsp_prepare(stream, sdfmt, lib->size, &dmab);
430+
if (ret < 0)
431+
goto release_stream;
432+
433+
/* enable SPIB for hda stream */
434+
snd_hdac_ext_stream_spbcap_enable(bus, true, stream->index);
435+
snd_hdac_ext_stream_set_spib(bus, estream, lib->size);
436+
437+
memcpy(dmab.area, lib->data, lib->size);
438+
439+
/* transfer firmware */
440+
snd_hdac_dsp_trigger(stream, true);
441+
ret = avs_ipc_load_library(adev, stream->stream_tag - 1, id);
442+
snd_hdac_dsp_trigger(stream, false);
443+
if (ret) {
444+
dev_err(adev->dev, "transfer lib %d failed: %d\n", id, ret);
445+
ret = AVS_IPC_RET(ret);
446+
}
447+
448+
/* disable SPIB for hda stream */
449+
snd_hdac_ext_stream_spbcap_enable(bus, false, stream->index);
450+
snd_hdac_ext_stream_set_spib(bus, estream, 0);
451+
452+
snd_hdac_dsp_cleanup(stream, &dmab);
453+
release_stream:
454+
snd_hdac_ext_stream_release(estream, HDAC_EXT_STREAM_TYPE_HOST);
455+
456+
return ret;
457+
}
458+
459+
int avs_hda_transfer_modules(struct avs_dev *adev, bool load,
460+
struct avs_module_entry *mods, u32 num_mods)
461+
{
462+
/*
463+
* All platforms without CLDMA are equipped with IMR,
464+
* and thus the module transferring is offloaded to DSP.
465+
*/
466+
return 0;
467+
}
468+
264469
static int avs_dsp_load_basefw(struct avs_dev *adev)
265470
{
266471
const struct avs_fw_version *min_req;
@@ -316,6 +521,15 @@ int avs_dsp_boot_firmware(struct avs_dev *adev, bool purge)
316521
{
317522
int ret, i;
318523

524+
/* Forgo full boot if flash from IMR succeeds. */
525+
if (!purge && avs_platattr_test(adev, IMR)) {
526+
ret = avs_imr_load_basefw(adev);
527+
if (!ret)
528+
return 0;
529+
530+
dev_dbg(adev->dev, "firmware flash from imr failed: %d\n", ret);
531+
}
532+
319533
/* Full boot, clear cached data except for basefw (slot 0). */
320534
for (i = 1; i < adev->fw_cfg.max_libs_count; i++)
321535
memset(adev->lib_names[i], 0, AVS_LIB_NAME_SIZE);

0 commit comments

Comments
 (0)