>From bfa80124f849a8fa35a9ef7bd5db50f10e852a34 Mon Sep 17 00:00:00 2001 From: Vinod Koul <[email protected]> Date: Wed, 17 Nov 2010 21:59:42 +0530 Subject: [PATCH 2/4] sst: add firmware context restore
During suspend and runtime_suspend audio dsp is power gated This causes it to loose the current context This patch adds support in driver to save the dsp context and restore this context during resume Signed-off-by: Vinod Koul <[email protected]> --- sound/pci/sst/intel_sst.c | 67 ++++++++++++++++++++++++++++- sound/pci/sst/intel_sst_common.h | 9 +++- sound/pci/sst/intel_sst_dsp.c | 14 ++++-- sound/pci/sst/intel_sst_fw_ipc.h | 6 +++ sound/pci/sst/intel_sst_ipc.c | 56 +++++++++++++++++++++++-- sound/pci/sst/intel_sst_stream.c | 10 +++-- sound/pci/sst/intel_sst_stream_encoded.c | 4 +- 7 files changed, 145 insertions(+), 21 deletions(-) diff --git a/sound/pci/sst/intel_sst.c b/sound/pci/sst/intel_sst.c index ae2ea75..2fc11aa 100644 --- a/sound/pci/sst/intel_sst.c +++ b/sound/pci/sst/intel_sst.c @@ -317,6 +317,22 @@ static int __devinit intel_sst_probe(struct pci_dev *pci, pr_err("sst: couldn't register LPE device\n"); goto do_free_misc; } + } else if (sst_drv_ctx->pci_id == SST_MFLD_PCI_ID) { + u32 csr; + + /*allocate mem for fw context save during suspend*/ + sst_drv_ctx->fw_cntx = kzalloc(FW_CONTEXT_MEM, GFP_KERNEL); + if (!sst_drv_ctx->fw_cntx) { + ret = -ENOMEM; + goto do_free_misc; + } + /*setting zero as that is valid mem to restore*/ + sst_drv_ctx->fw_cntx_size = 0; + + /*set lpe start clock and ram size*/ + csr = sst_shim_read(sst_drv_ctx->shim, SST_CSR); + csr |= 0x30060; /*remove the clock ratio after fw fix*/ + sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr); } sst_drv_ctx->lpe_stalled = 0; pm_runtime_set_active(&pci->dev); @@ -353,6 +369,7 @@ free_mad_wq: destroy_workqueue(sst_drv_ctx->mad_wq); do_free_drv_ctx: kfree(sst_drv_ctx); + sst_drv_ctx = NULL; pr_err("sst: Probe failed with 0x%x\n", ret); return ret; } @@ -372,16 +389,17 @@ static void __devexit intel_sst_remove(struct pci_dev *pci) sst_drv_ctx->sst_state = SST_UN_INIT; mutex_unlock(&sst_drv_ctx->sst_lock); misc_deregister(&lpe_ctrl); - if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID) + if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID) { misc_deregister(&lpe_dev); + kfree(sst_drv_ctx->mmap_mem); + } else + kfree(sst_drv_ctx->fw_cntx); free_irq(pci->irq, sst_drv_ctx); iounmap(sst_drv_ctx->dram); iounmap(sst_drv_ctx->iram); iounmap(sst_drv_ctx->mailbox); iounmap(sst_drv_ctx->shim); sst_drv_ctx->pmic_state = SND_MAD_UN_INIT; - if (sst_drv_ctx->pci_id == SST_MRST_PCI_ID) - kfree(sst_drv_ctx->mmap_mem); flush_scheduled_work(); destroy_workqueue(sst_drv_ctx->process_reply_wq); destroy_workqueue(sst_drv_ctx->process_msg_wq); @@ -396,6 +414,46 @@ static void __devexit intel_sst_remove(struct pci_dev *pci) pci_set_drvdata(pci, NULL); } +void sst_save_dsp_context(void) +{ + struct snd_sst_ctxt_params fw_context; + unsigned int pvt_id, i; + struct ipc_post *msg = NULL; + + /*check cpu type*/ + if (sst_drv_ctx->pci_id != SST_MFLD_PCI_ID) + return; + /*not supported for rest*/ + if (sst_drv_ctx->sst_state != SST_FW_RUNNING) { + pr_debug("sst: fw not running no context save ...\n"); + return; + } + + /*send msg to fw*/ + if (sst_create_large_msg(&msg)) + return; + pvt_id = sst_assign_pvt_id(sst_drv_ctx); + i = sst_get_block_stream(sst_drv_ctx); + sst_drv_ctx->alloc_block[i].sst_id = pvt_id; + sst_fill_header(&msg->header, IPC_IA_GET_FW_CTXT, 1, pvt_id); + msg->header.part.data = sizeof(fw_context) + sizeof(u32); + fw_context.address = virt_to_phys((void *)sst_drv_ctx->fw_cntx); + fw_context.size = FW_CONTEXT_MEM; + memcpy(msg->mailbox_data, &msg->header, sizeof(u32)); + memcpy(msg->mailbox_data + sizeof(u32), + &fw_context, sizeof(fw_context)); + spin_lock(&sst_drv_ctx->list_spin_lock); + list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list); + spin_unlock(&sst_drv_ctx->list_spin_lock); + sst_post_message(&sst_drv_ctx->ipc_post_msg_wq); + /*wait for reply*/ + if (sst_wait_timeout(sst_drv_ctx, &sst_drv_ctx->alloc_block[i])) + pr_debug("sst: err fw context save timeout ...\n"); + sst_drv_ctx->alloc_block[i].sst_id = BLOCK_UNINIT; + pr_debug("sst: fw context saved ...\n"); + return; +} + /* Power Management */ /* * intel_sst_suspend - PCI suspend function @@ -414,6 +472,8 @@ int intel_sst_suspend(struct pci_dev *pci, pm_message_t state) pr_err("sst: active streams,not able to suspend\n"); return -EBUSY; } + /*save fw context*/ + sst_save_dsp_context(); /*Assert RESET on LPE Processor*/ csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR); csr.full = csr.full | 0x2; @@ -542,6 +602,7 @@ static void __exit intel_sst_exit(void) pci_unregister_driver(&driver); pr_debug("sst: driver unloaded\n"); + sst_drv_ctx = NULL; return; } diff --git a/sound/pci/sst/intel_sst_common.h b/sound/pci/sst/intel_sst_common.h index e9eb510..39837b3 100644 --- a/sound/pci/sst/intel_sst_common.h +++ b/sound/pci/sst/intel_sst_common.h @@ -28,8 +28,8 @@ * Common private declarations for SST */ -#define SST_DRIVER_VERSION "1.2.09" -#define SST_VERSION_NUM 0x1209 +#define SST_DRIVER_VERSION "1.2.11" +#define SST_VERSION_NUM 0x1211 /* driver names */ #define SST_DRV_NAME "intel_sst_driver" @@ -37,6 +37,7 @@ #define SST_MFLD_PCI_ID 0x082F #define PCI_ID_LENGTH 4 #define SST_SUSPEND_DELAY 2000 +#define FW_CONTEXT_MEM (64*1024) enum sst_states { SST_FW_LOADED = 1, @@ -94,7 +95,7 @@ enum sst_ram_type { /* SST shim registers to structure mapping */ union config_status_reg { struct { - u32 rsvd0:1; + u32 mfld_strb:1; u32 sst_reset:1; u32 hw_rsvd:3; u32 sst_clk:2; @@ -417,6 +418,8 @@ struct intel_sst_drv { unsigned int audio_start; dev_t devt_d, devt_c; unsigned int max_streams; + unsigned int *fw_cntx; + unsigned int fw_cntx_size; }; extern struct intel_sst_drv *sst_drv_ctx; diff --git a/sound/pci/sst/intel_sst_dsp.c b/sound/pci/sst/intel_sst_dsp.c index 585e2c1..3eb5594 100644 --- a/sound/pci/sst/intel_sst_dsp.c +++ b/sound/pci/sst/intel_sst_dsp.c @@ -70,7 +70,8 @@ static int intel_sst_reset_dsp_medfield(void) union config_status_reg csr; pr_debug("sst: Resetting the DSP in medfield\n"); - csr.full = 0x048303E2; + csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR); + csr.full |= 0x382; sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full); return 0; @@ -106,11 +107,16 @@ static int sst_start_medfield(void) { union config_status_reg csr; - csr.full = 0x04830062; + csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR); + csr.part.bypass = 0; sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full); - csr.full = 0x04830063; + csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR); + csr.part.mfld_strb = 1; sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full); - csr.full = 0x04830061; + csr.full = sst_shim_read(sst_drv_ctx->shim, SST_CSR); + csr.part.run_stall = 0; + csr.part.sst_reset = 0; + pr_debug("sst: Starting the DSP_medfld %x\n", csr.full); sst_shim_write(sst_drv_ctx->shim, SST_CSR, csr.full); pr_debug("sst: Starting the DSP_medfld\n"); diff --git a/sound/pci/sst/intel_sst_fw_ipc.h b/sound/pci/sst/intel_sst_fw_ipc.h index 8df313d..ed237c3 100644 --- a/sound/pci/sst/intel_sst_fw_ipc.h +++ b/sound/pci/sst/intel_sst_fw_ipc.h @@ -56,6 +56,8 @@ #define IPC_IA_GET_FW_VERSION 0x04 #define IPC_IA_GET_FW_BUILD_INF 0x05 #define IPC_IA_GET_FW_INFO 0x06 +#define IPC_IA_GET_FW_CTXT 0x07 +#define IPC_IA_SET_FW_CTXT 0x08 /* I2L Codec Config/control msgs */ #define IPC_IA_SET_CODEC_PARAMS 0x10 @@ -406,4 +408,8 @@ struct ipc_post { char *mailbox_data; }; +struct snd_sst_ctxt_params { + u32 address; /* Physical Address in DDR where the context is stored */ + u32 size; /* size of the context */ +}; #endif /* __INTEL_SST_FW_IPC_H__ */ diff --git a/sound/pci/sst/intel_sst_ipc.c b/sound/pci/sst/intel_sst_ipc.c index 603a96e..4ff6470 100644 --- a/sound/pci/sst/intel_sst_ipc.c +++ b/sound/pci/sst/intel_sst_ipc.c @@ -151,6 +151,37 @@ void sst_clear_interrupt(void) sst_shim_write(sst_drv_ctx->shim, SST_IMRX, imr.full); } +void sst_restore_fw_context(void) +{ + struct snd_sst_ctxt_params fw_context; + struct ipc_post *msg = NULL; + + pr_debug("sst: restore_fw_context\n"); + /*check cpu type*/ + if (sst_drv_ctx->pci_id != SST_MFLD_PCI_ID) + return; + /*not supported for rest*/ + if (!sst_drv_ctx->fw_cntx_size) + return; + /*nothing to restore*/ + pr_debug("sst: restoring context......\n"); + /*send msg to fw*/ + if (sst_create_large_msg(&msg)) + return; + + sst_fill_header(&msg->header, IPC_IA_SET_FW_CTXT, 1, 0); + msg->header.part.data = sizeof(fw_context) + sizeof(u32); + fw_context.address = virt_to_phys((void *)sst_drv_ctx->fw_cntx); + fw_context.size = sst_drv_ctx->fw_cntx_size; + memcpy(msg->mailbox_data, &msg->header, sizeof(u32)); + memcpy(msg->mailbox_data + sizeof(u32), + &fw_context, sizeof(fw_context)); + spin_lock(&sst_drv_ctx->list_spin_lock); + list_add_tail(&msg->node, &sst_drv_ctx->ipc_dispatch_list); + spin_unlock(&sst_drv_ctx->list_spin_lock); + sst_post_message(&sst_drv_ctx->ipc_post_msg_wq); + return; +} /* * process_fw_init - process the FW init msg * @@ -181,13 +212,13 @@ int process_fw_init(struct sst_ipc_msg_wq *msg) sst_drv_ctx->sst_state = SST_FW_RUNNING; sst_drv_ctx->lpe_stalled = 0; mutex_unlock(&sst_drv_ctx->sst_lock); - pr_debug("sst: FW Version %x.%x\n", - init->fw_version.major, init->fw_version.minor); - pr_debug("sst: Build No %x Type %x\n", - init->fw_version.build, init->fw_version.type); + pr_debug("sst: FW Version %02x.%02x.%02x\n", init->fw_version.major, + init->fw_version.minor, init->fw_version.build); + pr_debug("sst: Build Type %x\n", init->fw_version.type); pr_debug("sst: Build date %s Time %s\n", init->build_info.date, init->build_info.time); sst_wake_up_alloc_block(sst_drv_ctx, FW_DWNL_ID, retval, NULL); + sst_restore_fw_context(); return retval; } /** @@ -603,12 +634,18 @@ void sst_process_reply(struct work_struct *work) break; case IPC_IA_FREE_STREAM: + str_info = &sst_drv_ctx->streams[str_id]; if (!msg->header.part.data) { pr_debug("sst: Stream %d freed\n", str_id); } else { pr_err("sst: Free for %d ret error %x\n", str_id, msg->header.part.data); } + if (str_info->ctrl_blk.on == true) { + str_info->ctrl_blk.on = false; + str_info->ctrl_blk.condition = true; + wake_up(&sst_drv_ctx->wait_queue); + } break; case IPC_IA_ALLOC_STREAM: { /* map to stream, call play */ @@ -687,6 +724,17 @@ void sst_process_reply(struct work_struct *work) case IPC_IA_START_STREAM: pr_debug("sst: reply for START STREAM %x\n", msg->header.full); break; + + case IPC_IA_GET_FW_CTXT: + pr_debug("sst: reply for get fw ctxt %x\n", msg->header.full); + if (msg->header.part.data) + sst_drv_ctx->fw_cntx_size = 0; + else + sst_drv_ctx->fw_cntx_size = *sst_drv_ctx->fw_cntx; + pr_debug("sst: fw copied data %x\n", sst_drv_ctx->fw_cntx_size); + sst_wake_up_alloc_block( + sst_drv_ctx, str_id, msg->header.part.data, NULL); + break; default: /* Illegal case */ pr_err("sst: process reply:default = %x\n", msg->header.full); diff --git a/sound/pci/sst/intel_sst_stream.c b/sound/pci/sst/intel_sst_stream.c index 6c7300f..ee5bd5d 100644 --- a/sound/pci/sst/intel_sst_stream.c +++ b/sound/pci/sst/intel_sst_stream.c @@ -516,10 +516,6 @@ int sst_drain_stream(int str_id) str_info->data_blk.on = true; retval = sst_wait_interruptible(sst_drv_ctx, &str_info->data_blk); str_info->need_draining = false; - if (retval == -SST_ERR_INVALID_STREAM_ID) { - retval = -EINVAL; - sst_clean_stream(str_info); - } return retval; } @@ -560,6 +556,12 @@ int sst_free_stream(int str_id) str_info->data_blk.ret_code = 0; wake_up(&sst_drv_ctx->wait_queue); } + str_info->data_blk.on = true; + str_info->data_blk.condition = false; + retval = sst_wait_interruptible_timeout(sst_drv_ctx, + &str_info->ctrl_blk, SST_BLOCK_TIMEOUT); + pr_debug("sst: wait for free returned %d\n", retval); + msleep(100); mutex_lock(&sst_drv_ctx->stream_lock); sst_clean_stream(str_info); mutex_unlock(&sst_drv_ctx->stream_lock); diff --git a/sound/pci/sst/intel_sst_stream_encoded.c b/sound/pci/sst/intel_sst_stream_encoded.c index de577c9..738de71 100644 --- a/sound/pci/sst/intel_sst_stream_encoded.c +++ b/sound/pci/sst/intel_sst_stream_encoded.c @@ -360,7 +360,6 @@ int sst_parse_target(struct snd_sst_slot_info *slot) pr_err("sst: SST_Activate_target_fail\n"); else pr_err("sst: SST_Activate_target_pass\n"); - return retval; } else if (slot->action == SND_SST_PORT_PREPARE && slot->device_type == SND_SST_DEVICE_PCM) { retval = sst_prepare_target(slot); @@ -368,12 +367,11 @@ int sst_parse_target(struct snd_sst_slot_info *slot) pr_err("sst: SST_prepare_target_fail\n"); else pr_err("sst: SST_prepare_target_pass\n"); - return retval; } else { pr_err("sst: slot_action : %d, device_type: %d\n", slot->action, slot->device_type); - return retval; } + return retval; } int sst_send_target(struct snd_sst_target_device *target) -- 1.7.2.3
0002-sst-add-firmware-context-restore.patch
Description: 0002-sst-add-firmware-context-restore.patch
_______________________________________________ MeeGo-kernel mailing list [email protected] http://lists.meego.com/listinfo/meego-kernel
