|
9 | 9 | #include <linux/firmware.h> |
10 | 10 | #include <linux/module.h> |
11 | 11 | #include <linux/slab.h> |
| 12 | +#include <sound/hdaudio.h> |
12 | 13 | #include <sound/hdaudio_ext.h> |
13 | 14 | #include "avs.h" |
14 | 15 | #include "cldma.h" |
|
18 | 19 | #define AVS_ROM_STS_MASK 0xFF |
19 | 20 | #define AVS_ROM_INIT_DONE 0x1 |
20 | 21 | #define SKL_ROM_BASEFW_ENTERED 0xF |
| 22 | +#define APL_ROM_FW_ENTERED 0x5 |
21 | 23 | #define AVS_ROM_INIT_POLLING_US 5 |
22 | 24 | #define SKL_ROM_INIT_TIMEOUT_US 1000000 |
| 25 | +#define APL_ROM_INIT_TIMEOUT_US 300000 |
| 26 | +#define APL_ROM_INIT_RETRIES 3 |
23 | 27 |
|
24 | 28 | #define AVS_FW_INIT_POLLING_US 500 |
25 | 29 | #define AVS_FW_INIT_TIMEOUT_US 3000000 |
@@ -261,6 +265,207 @@ int avs_cldma_transfer_modules(struct avs_dev *adev, bool load, |
261 | 265 | return 0; |
262 | 266 | } |
263 | 267 |
|
| 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 | + |
264 | 469 | static int avs_dsp_load_basefw(struct avs_dev *adev) |
265 | 470 | { |
266 | 471 | const struct avs_fw_version *min_req; |
@@ -316,6 +521,15 @@ int avs_dsp_boot_firmware(struct avs_dev *adev, bool purge) |
316 | 521 | { |
317 | 522 | int ret, i; |
318 | 523 |
|
| 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 | + |
319 | 533 | /* Full boot, clear cached data except for basefw (slot 0). */ |
320 | 534 | for (i = 1; i < adev->fw_cfg.max_libs_count; i++) |
321 | 535 | memset(adev->lib_names[i], 0, AVS_LIB_NAME_SIZE); |
|
0 commit comments