| .. | .. | 
|---|
|  | 1 | +// SPDX-License-Identifier: GPL-2.0-only | 
|---|
| 1 | 2 | /* | 
|---|
| 2 | 3 | *  bxt-sst.c - DSP library functions for BXT platform | 
|---|
| 3 | 4 | * | 
|---|
| 4 | 5 | *  Copyright (C) 2015-16 Intel Corp | 
|---|
| 5 | 6 | *  Author:Rafal Redzimski <rafal.f.redzimski@intel.com> | 
|---|
| 6 | 7 | *	   Jeeja KP <jeeja.kp@intel.com> | 
|---|
| 7 |  | - * | 
|---|
| 8 |  | - *  This program is free software; you can redistribute it and/or modify | 
|---|
| 9 |  | - *  it under the terms of the GNU General Public License as published by | 
|---|
| 10 |  | - *  the Free Software Foundation; version 2 of the License. | 
|---|
| 11 |  | - * | 
|---|
| 12 |  | - *  This program is distributed in the hope that it will be useful, but | 
|---|
| 13 |  | - *  WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 14 |  | - *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
|---|
| 15 |  | - *  General Public License for more details. | 
|---|
| 16 | 8 | */ | 
|---|
| 17 | 9 |  | 
|---|
| 18 | 10 | #include <linux/module.h> | 
|---|
| .. | .. | 
|---|
| 22 | 14 |  | 
|---|
| 23 | 15 | #include "../common/sst-dsp.h" | 
|---|
| 24 | 16 | #include "../common/sst-dsp-priv.h" | 
|---|
| 25 |  | -#include "skl-sst-ipc.h" | 
|---|
|  | 17 | +#include "skl.h" | 
|---|
| 26 | 18 |  | 
|---|
| 27 | 19 | #define BXT_BASEFW_TIMEOUT	3000 | 
|---|
| 28 |  | -#define BXT_INIT_TIMEOUT	300 | 
|---|
| 29 | 20 | #define BXT_ROM_INIT_TIMEOUT	70 | 
|---|
| 30 | 21 | #define BXT_IPC_PURGE_FW	0x01004000 | 
|---|
| 31 | 22 |  | 
|---|
| .. | .. | 
|---|
| 46 | 37 | /* Delay before scheduling D0i3 entry */ | 
|---|
| 47 | 38 | #define BXT_D0I3_DELAY 5000 | 
|---|
| 48 | 39 |  | 
|---|
| 49 |  | -#define BXT_FW_ROM_INIT_RETRY 3 | 
|---|
| 50 |  | - | 
|---|
| 51 | 40 | static unsigned int bxt_get_errorcode(struct sst_dsp *ctx) | 
|---|
| 52 | 41 | { | 
|---|
| 53 | 42 | return sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE); | 
|---|
| .. | .. | 
|---|
| 57 | 46 | bxt_load_library(struct sst_dsp *ctx, struct skl_lib_info *linfo, int lib_count) | 
|---|
| 58 | 47 | { | 
|---|
| 59 | 48 | struct snd_dma_buffer dmab; | 
|---|
| 60 |  | -	struct skl_sst *skl = ctx->thread_context; | 
|---|
|  | 49 | +	struct skl_dev *skl = ctx->thread_context; | 
|---|
| 61 | 50 | struct firmware stripped_fw; | 
|---|
| 62 | 51 | int ret = 0, i, dma_id, stream_tag; | 
|---|
| 63 | 52 |  | 
|---|
| .. | .. | 
|---|
| 192 | 181 | static int bxt_load_base_firmware(struct sst_dsp *ctx) | 
|---|
| 193 | 182 | { | 
|---|
| 194 | 183 | struct firmware stripped_fw; | 
|---|
| 195 |  | -	struct skl_sst *skl = ctx->thread_context; | 
|---|
|  | 184 | +	struct skl_dev *skl = ctx->thread_context; | 
|---|
| 196 | 185 | int ret, i; | 
|---|
| 197 | 186 |  | 
|---|
| 198 | 187 | if (ctx->fw == NULL) { | 
|---|
| .. | .. | 
|---|
| 276 | 265 | */ | 
|---|
| 277 | 266 | static int bxt_d0i3_target_state(struct sst_dsp *ctx) | 
|---|
| 278 | 267 | { | 
|---|
| 279 |  | -	struct skl_sst *skl = ctx->thread_context; | 
|---|
|  | 268 | +	struct skl_dev *skl = ctx->thread_context; | 
|---|
| 280 | 269 | struct skl_d0i3_data *d0i3 = &skl->d0i3; | 
|---|
| 281 | 270 |  | 
|---|
| 282 | 271 | if (skl->cores.state[SKL_DSP_CORE0_ID] != SKL_DSP_RUNNING) | 
|---|
| .. | .. | 
|---|
| 296 | 285 | { | 
|---|
| 297 | 286 | int ret; | 
|---|
| 298 | 287 | struct skl_ipc_d0ix_msg msg; | 
|---|
| 299 |  | -	struct skl_sst *skl = container_of(work, | 
|---|
| 300 |  | -			struct skl_sst, d0i3.work.work); | 
|---|
|  | 288 | +	struct skl_dev *skl = container_of(work, | 
|---|
|  | 289 | +			struct skl_dev, d0i3.work.work); | 
|---|
| 301 | 290 | struct sst_dsp *ctx = skl->dsp; | 
|---|
| 302 | 291 | struct skl_d0i3_data *d0i3 = &skl->d0i3; | 
|---|
| 303 | 292 | int target_state; | 
|---|
| .. | .. | 
|---|
| 339 | 328 |  | 
|---|
| 340 | 329 | static int bxt_schedule_dsp_D0i3(struct sst_dsp *ctx) | 
|---|
| 341 | 330 | { | 
|---|
| 342 |  | -	struct skl_sst *skl = ctx->thread_context; | 
|---|
|  | 331 | +	struct skl_dev *skl = ctx->thread_context; | 
|---|
| 343 | 332 | struct skl_d0i3_data *d0i3 = &skl->d0i3; | 
|---|
| 344 | 333 |  | 
|---|
| 345 | 334 | /* Schedule D0i3 only if the usecase ref counts are appropriate */ | 
|---|
| .. | .. | 
|---|
| 358 | 347 | { | 
|---|
| 359 | 348 | int ret; | 
|---|
| 360 | 349 | struct skl_ipc_d0ix_msg msg; | 
|---|
| 361 |  | -	struct skl_sst *skl = ctx->thread_context; | 
|---|
|  | 350 | +	struct skl_dev *skl = ctx->thread_context; | 
|---|
| 362 | 351 |  | 
|---|
| 363 | 352 | dev_dbg(ctx->dev, "In %s:\n", __func__); | 
|---|
| 364 | 353 |  | 
|---|
| .. | .. | 
|---|
| 397 | 386 |  | 
|---|
| 398 | 387 | static int bxt_set_dsp_D0(struct sst_dsp *ctx, unsigned int core_id) | 
|---|
| 399 | 388 | { | 
|---|
| 400 |  | -	struct skl_sst *skl = ctx->thread_context; | 
|---|
|  | 389 | +	struct skl_dev *skl = ctx->thread_context; | 
|---|
| 401 | 390 | int ret; | 
|---|
| 402 | 391 | struct skl_ipc_dxstate_info dx; | 
|---|
| 403 | 392 | unsigned int core_mask = SKL_DSP_CORE_MASK(core_id); | 
|---|
| .. | .. | 
|---|
| 494 | 483 | { | 
|---|
| 495 | 484 | int ret; | 
|---|
| 496 | 485 | struct skl_ipc_dxstate_info dx; | 
|---|
| 497 |  | -	struct skl_sst *skl = ctx->thread_context; | 
|---|
|  | 486 | +	struct skl_dev *skl = ctx->thread_context; | 
|---|
| 498 | 487 | unsigned int core_mask = SKL_DSP_CORE_MASK(core_id); | 
|---|
| 499 | 488 |  | 
|---|
| 500 | 489 | dx.core_mask = core_mask; | 
|---|
| .. | .. | 
|---|
| 544 | 533 | .irq_handler = skl_dsp_sst_interrupt, | 
|---|
| 545 | 534 | .write = sst_shim32_write, | 
|---|
| 546 | 535 | .read = sst_shim32_read, | 
|---|
| 547 |  | -	.ram_read = sst_memcpy_fromio_32, | 
|---|
| 548 |  | -	.ram_write = sst_memcpy_toio_32, | 
|---|
| 549 | 536 | .free = skl_dsp_free, | 
|---|
| 550 | 537 | }; | 
|---|
| 551 | 538 |  | 
|---|
| .. | .. | 
|---|
| 556 | 543 |  | 
|---|
| 557 | 544 | int bxt_sst_dsp_init(struct device *dev, void __iomem *mmio_base, int irq, | 
|---|
| 558 | 545 | const char *fw_name, struct skl_dsp_loader_ops dsp_ops, | 
|---|
| 559 |  | -			struct skl_sst **dsp) | 
|---|
|  | 546 | +			struct skl_dev **dsp) | 
|---|
| 560 | 547 | { | 
|---|
| 561 |  | -	struct skl_sst *skl; | 
|---|
|  | 548 | +	struct skl_dev *skl; | 
|---|
| 562 | 549 | struct sst_dsp *sst; | 
|---|
| 563 | 550 | int ret; | 
|---|
| 564 | 551 |  | 
|---|
| .. | .. | 
|---|
| 599 | 586 | } | 
|---|
| 600 | 587 | EXPORT_SYMBOL_GPL(bxt_sst_dsp_init); | 
|---|
| 601 | 588 |  | 
|---|
| 602 |  | -int bxt_sst_init_fw(struct device *dev, struct skl_sst *ctx) | 
|---|
|  | 589 | +int bxt_sst_init_fw(struct device *dev, struct skl_dev *skl) | 
|---|
| 603 | 590 | { | 
|---|
| 604 | 591 | int ret; | 
|---|
| 605 |  | -	struct sst_dsp *sst = ctx->dsp; | 
|---|
|  | 592 | +	struct sst_dsp *sst = skl->dsp; | 
|---|
| 606 | 593 |  | 
|---|
| 607 | 594 | ret = sst->fw_ops.load_fw(sst); | 
|---|
| 608 | 595 | if (ret < 0) { | 
|---|
| .. | .. | 
|---|
| 612 | 599 |  | 
|---|
| 613 | 600 | skl_dsp_init_core_state(sst); | 
|---|
| 614 | 601 |  | 
|---|
| 615 |  | -	if (ctx->lib_count > 1) { | 
|---|
| 616 |  | -		ret = sst->fw_ops.load_library(sst, ctx->lib_info, | 
|---|
| 617 |  | -						ctx->lib_count); | 
|---|
|  | 602 | +	if (skl->lib_count > 1) { | 
|---|
|  | 603 | +		ret = sst->fw_ops.load_library(sst, skl->lib_info, | 
|---|
|  | 604 | +						skl->lib_count); | 
|---|
| 618 | 605 | if (ret < 0) { | 
|---|
| 619 | 606 | dev_err(dev, "Load Library failed : %x\n", ret); | 
|---|
| 620 | 607 | return ret; | 
|---|
| 621 | 608 | } | 
|---|
| 622 | 609 | } | 
|---|
| 623 |  | -	ctx->is_first_boot = false; | 
|---|
|  | 610 | +	skl->is_first_boot = false; | 
|---|
| 624 | 611 |  | 
|---|
| 625 | 612 | return 0; | 
|---|
| 626 | 613 | } | 
|---|
| 627 | 614 | EXPORT_SYMBOL_GPL(bxt_sst_init_fw); | 
|---|
| 628 | 615 |  | 
|---|
| 629 |  | -void bxt_sst_dsp_cleanup(struct device *dev, struct skl_sst *ctx) | 
|---|
|  | 616 | +void bxt_sst_dsp_cleanup(struct device *dev, struct skl_dev *skl) | 
|---|
| 630 | 617 | { | 
|---|
| 631 | 618 |  | 
|---|
| 632 |  | -	skl_release_library(ctx->lib_info, ctx->lib_count); | 
|---|
| 633 |  | -	if (ctx->dsp->fw) | 
|---|
| 634 |  | -		release_firmware(ctx->dsp->fw); | 
|---|
| 635 |  | -	skl_freeup_uuid_list(ctx); | 
|---|
| 636 |  | -	skl_ipc_free(&ctx->ipc); | 
|---|
| 637 |  | -	ctx->dsp->ops->free(ctx->dsp); | 
|---|
|  | 619 | +	skl_release_library(skl->lib_info, skl->lib_count); | 
|---|
|  | 620 | +	if (skl->dsp->fw) | 
|---|
|  | 621 | +		release_firmware(skl->dsp->fw); | 
|---|
|  | 622 | +	skl_freeup_uuid_list(skl); | 
|---|
|  | 623 | +	skl_ipc_free(&skl->ipc); | 
|---|
|  | 624 | +	skl->dsp->ops->free(skl->dsp); | 
|---|
| 638 | 625 | } | 
|---|
| 639 | 626 | EXPORT_SYMBOL_GPL(bxt_sst_dsp_cleanup); | 
|---|
| 640 | 627 |  | 
|---|