| @@ -43,6 +43,9 @@ · 42 unmodified lines |
| 43 | | 43 | |
| 44 | #define BXT_ADSP_FW_BIN_HDR_OFFSET 0x2000 | 44 | #define BXT_ADSP_FW_BIN_HDR_OFFSET 0x2000 |
| 45 | | 45 | |
| | 46 | /* Delay before scheduling D0i3 entry */ |
| | 47 | #define BXT_D0I3_DELAY 5000 |
| | 48 | |
| 46 | static unsigned int bxt_get_errorcode(struct sst_dsp *ctx) | 49 | static unsigned int bxt_get_errorcode(struct sst_dsp *ctx) |
| 47 | { | 50 | { |
| 48 | return sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE); | 51 | return sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE); |
| @@ -288,6 +291,141 @@ sst_load_base_firmware_failed: · 239 unmodified lines |
| 288 | return ret; | 291 | return ret; |
| 289 | } | 292 | } |
| 290 | | 293 | |
| | 294 | /* |
| | 295 | * Decide the D0i3 state that can be targeted based on the usecase |
| | 296 | * ref counts and DSP state |
| | 297 | * |
| | 298 | * Decision Matrix: (X= dont care; state = target state) |
| | 299 | * |
| | 300 | * DSP state != SKL_DSP_RUNNING ; state = no d0i3 |
| | 301 | * |
| | 302 | * DSP state == SKL_DSP_RUNNING , the following matrix applies |
| | 303 | * non_d0i3 >0; streaming =X; non_streaming =X; state = no d0i3 |
| | 304 | * non_d0i3 =X; streaming =0; non_streaming =0; state = no d0i3 |
| | 305 | * non_d0i3 =0; streaming >0; non_streaming =X; state = streaming d0i3 |
| | 306 | * non_d0i3 =0; streaming =0; non_streaming =X; state = non-streaming d0i3 |
| | 307 | */ |
| | 308 | static int bxt_d0i3_target_state(struct sst_dsp *ctx) |
| | 309 | { |
| | 310 | struct skl_sst *skl = ctx->thread_context; |
| | 311 | struct skl_d0i3_data *d0i3 = &skl->d0i3; |
| | 312 | |
| | 313 | if (skl->cores.state[SKL_DSP_CORE0_ID] != SKL_DSP_RUNNING) |
| | 314 | return SKL_DSP_D0I3_NONE; |
| | 315 | |
| | 316 | if (d0i3->non_d0i3) |
| | 317 | return SKL_DSP_D0I3_NONE; |
| | 318 | else if (d0i3->streaming) |
| | 319 | return SKL_DSP_D0I3_STREAMING; |
| | 320 | else if (d0i3->non_streaming) |
| | 321 | return SKL_DSP_D0I3_NON_STREAMING; |
| | 322 | else |
| | 323 | return SKL_DSP_D0I3_NONE; |
| | 324 | } |
| | 325 | |
| | 326 | static void bxt_set_dsp_D0i3(struct work_struct *work) |
| | 327 | { |
| | 328 | int ret; |
| | 329 | struct skl_ipc_d0ix_msg msg; |
| | 330 | struct skl_sst *skl = container_of(work, |
| | 331 | struct skl_sst, d0i3.work.work); |
| | 332 | struct sst_dsp *ctx = skl->dsp; |
| | 333 | struct skl_d0i3_data *d0i3 = &skl->d0i3; |
| | 334 | int target_state; |
| | 335 | |
| | 336 | dev_dbg(ctx->dev, "In %s:\n", __func__); |
| | 337 | |
| | 338 | /* D0i3 entry allowed only if core 0 alone is running */ |
| | 339 | if (skl_dsp_get_enabled_cores(ctx) != SKL_DSP_CORE0_MASK) { |
| | 340 | dev_warn(ctx->dev, |
| | 341 | "D0i3 allowed when only core0 running:Exit\n"); |
| | 342 | return; |
| | 343 | } |
| | 344 | |
| | 345 | target_state = bxt_d0i3_target_state(ctx); |
| | 346 | if (target_state == SKL_DSP_D0I3_NONE) |
| | 347 | return; |
| | 348 | |
| | 349 | msg.instance_id = 0; |
| | 350 | msg.module_id = 0; |
| | 351 | msg.wake = 1; |
| | 352 | msg.streaming = 0; |
| | 353 | if (target_state == SKL_DSP_D0I3_STREAMING) |
| | 354 | msg.streaming = 1; |
| | 355 | |
| | 356 | ret = skl_ipc_set_d0ix(&skl->ipc, &msg); |
| | 357 | |
| | 358 | if (ret < 0) { |
| | 359 | dev_err(ctx->dev, "Failed to set DSP to D0i3 state\n"); |
| | 360 | return; |
| | 361 | } |
| | 362 | |
| | 363 | /* Set Vendor specific register D0I3C.I3 to enable D0i3*/ |
| | 364 | if (skl->update_d0i3c) |
| | 365 | skl->update_d0i3c(skl->dev, true); |
| | 366 | |
| | 367 | d0i3->state = target_state; |
| | 368 | skl->cores.state[SKL_DSP_CORE0_ID] = SKL_DSP_RUNNING_D0I3; |
| | 369 | } |
| | 370 | |
| | 371 | static int bxt_schedule_dsp_D0i3(struct sst_dsp *ctx) |
| | 372 | { |
| | 373 | struct skl_sst *skl = ctx->thread_context; |
| | 374 | struct skl_d0i3_data *d0i3 = &skl->d0i3; |
| | 375 | |
| | 376 | /* Schedule D0i3 only if the usecase ref counts are appropriate */ |
| | 377 | if (bxt_d0i3_target_state(ctx) != SKL_DSP_D0I3_NONE) { |
| | 378 | |
| | 379 | dev_dbg(ctx->dev, "%s: Schedule D0i3\n", __func__); |
| | 380 | |
| | 381 | schedule_delayed_work(&d0i3->work, |
| | 382 | msecs_to_jiffies(BXT_D0I3_DELAY)); |
| | 383 | } |
| | 384 | |
| | 385 | return 0; |
| | 386 | } |
| | 387 | |
| | 388 | static int bxt_set_dsp_D0i0(struct sst_dsp *ctx) |
| | 389 | { |
| | 390 | int ret; |
| | 391 | struct skl_ipc_d0ix_msg msg; |
| | 392 | struct skl_sst *skl = ctx->thread_context; |
| | 393 | |
| | 394 | dev_dbg(ctx->dev, "In %s:\n", __func__); |
| | 395 | |
| | 396 | /* First Cancel any pending attempt to put DSP to D0i3 */ |
| | 397 | cancel_delayed_work_sync(&skl->d0i3.work); |
| | 398 | |
| | 399 | /* If DSP is currently in D0i3, bring it to D0i0 */ |
| | 400 | if (skl->cores.state[SKL_DSP_CORE0_ID] != SKL_DSP_RUNNING_D0I3) |
| | 401 | return 0; |
| | 402 | |
| | 403 | dev_dbg(ctx->dev, "Set DSP to D0i0\n"); |
| | 404 | |
| | 405 | msg.instance_id = 0; |
| | 406 | msg.module_id = 0; |
| | 407 | msg.streaming = 0; |
| | 408 | msg.wake = 0; |
| | 409 | |
| | 410 | if (skl->d0i3.state == SKL_DSP_D0I3_STREAMING) |
| | 411 | msg.streaming = 1; |
| | 412 | |
| | 413 | /* Clear Vendor specific register D0I3C.I3 to disable D0i3*/ |
| | 414 | if (skl->update_d0i3c) |
| | 415 | skl->update_d0i3c(skl->dev, false); |
| | 416 | |
| | 417 | ret = skl_ipc_set_d0ix(&skl->ipc, &msg); |
| | 418 | if (ret < 0) { |
| | 419 | dev_err(ctx->dev, "Failed to set DSP to D0i0\n"); |
| | 420 | return ret; |
| | 421 | } |
| | 422 | |
| | 423 | skl->cores.state[SKL_DSP_CORE0_ID] = SKL_DSP_RUNNING; |
| | 424 | skl->d0i3.state = SKL_DSP_D0I3_NONE; |
| | 425 | |
| | 426 | return 0; |
| | 427 | } |
| | 428 | |
| 291 | static int bxt_set_dsp_D0(struct sst_dsp *ctx, unsigned int core_id) | 429 | static int bxt_set_dsp_D0(struct sst_dsp *ctx, unsigned int core_id) |
| 292 | { | 430 | { |
| 293 | struct skl_sst *skl = ctx->thread_context; | 431 | struct skl_sst *skl = ctx->thread_context; |
| @@ -414,6 +552,8 @@ static int bxt_set_dsp_D3(struct sst_dsp *ctx, unsigned int core_id) · 120 unmodified lines |
| 414 | static struct skl_dsp_fw_ops bxt_fw_ops = { | 552 | static struct skl_dsp_fw_ops bxt_fw_ops = { |
| 415 | .set_state_D0 = bxt_set_dsp_D0, | 553 | .set_state_D0 = bxt_set_dsp_D0, |
| 416 | .set_state_D3 = bxt_set_dsp_D3, | 554 | .set_state_D3 = bxt_set_dsp_D3, |
| | 555 | .set_state_D0i3 = bxt_schedule_dsp_D0i3, |
| | 556 | .set_state_D0i0 = bxt_set_dsp_D0i0, |
| 417 | .load_fw = bxt_load_base_firmware, | 557 | .load_fw = bxt_load_base_firmware, |
| 418 | .get_fw_errcode = bxt_get_errorcode, | 558 | .get_fw_errcode = bxt_get_errorcode, |
| 419 | .load_library = bxt_load_library, | 559 | .load_library = bxt_load_library, |