Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 1 | /* |
| 2 | * bxt-sst.c - DSP library functions for BXT platform |
| 3 | * |
| 4 | * Copyright (C) 2015-16 Intel Corp |
| 5 | * Author:Rafal Redzimski <rafal.f.redzimski@intel.com> |
| 6 | * 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 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/firmware.h> |
| 21 | #include <linux/device.h> |
| 22 | |
| 23 | #include "../common/sst-dsp.h" |
| 24 | #include "../common/sst-dsp-priv.h" |
| 25 | #include "skl-sst-ipc.h" |
| 26 | |
| 27 | #define BXT_BASEFW_TIMEOUT 3000 |
Jeeja KP | 7d3f91d | 2017-02-17 22:48:57 +0530 | [diff] [blame] | 28 | #define BXT_INIT_TIMEOUT 300 |
| 29 | #define BXT_ROM_INIT_TIMEOUT 70 |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 30 | #define BXT_IPC_PURGE_FW 0x01004000 |
| 31 | |
| 32 | #define BXT_ROM_INIT 0x5 |
| 33 | #define BXT_ADSP_SRAM0_BASE 0x80000 |
| 34 | |
| 35 | /* Firmware status window */ |
| 36 | #define BXT_ADSP_FW_STATUS BXT_ADSP_SRAM0_BASE |
| 37 | #define BXT_ADSP_ERROR_CODE (BXT_ADSP_FW_STATUS + 0x4) |
| 38 | |
| 39 | #define BXT_ADSP_SRAM1_BASE 0xA0000 |
| 40 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 41 | #define BXT_INSTANCE_ID 0 |
| 42 | #define BXT_BASE_FW_MODULE_ID 0 |
| 43 | |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 44 | #define BXT_ADSP_FW_BIN_HDR_OFFSET 0x2000 |
| 45 | |
Jayachandran B | 5bb4cd4 | 2016-11-03 17:07:17 +0530 | [diff] [blame] | 46 | /* Delay before scheduling D0i3 entry */ |
| 47 | #define BXT_D0I3_DELAY 5000 |
| 48 | |
Jeeja KP | 7d3f91d | 2017-02-17 22:48:57 +0530 | [diff] [blame] | 49 | #define BXT_FW_ROM_INIT_RETRY 3 |
| 50 | |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 51 | static unsigned int bxt_get_errorcode(struct sst_dsp *ctx) |
| 52 | { |
| 53 | return sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE); |
| 54 | } |
| 55 | |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 56 | static int |
Jeeja KP | eee0e16 | 2017-01-02 09:50:04 +0530 | [diff] [blame] | 57 | bxt_load_library(struct sst_dsp *ctx, struct skl_lib_info *linfo, int lib_count) |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 58 | { |
| 59 | struct snd_dma_buffer dmab; |
| 60 | struct skl_sst *skl = ctx->thread_context; |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 61 | struct firmware stripped_fw; |
| 62 | int ret = 0, i, dma_id, stream_tag; |
| 63 | |
| 64 | /* library indices start from 1 to N. 0 represents base FW */ |
Jeeja KP | eee0e16 | 2017-01-02 09:50:04 +0530 | [diff] [blame] | 65 | for (i = 1; i < lib_count; i++) { |
Subhransu S. Prusty | ebe8907 | 2017-04-25 12:18:20 +0530 | [diff] [blame^] | 66 | ret = skl_prepare_lib_load(skl, &skl->lib_info[i], &stripped_fw, |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 67 | BXT_ADSP_FW_BIN_HDR_OFFSET, i); |
Subhransu S. Prusty | ebe8907 | 2017-04-25 12:18:20 +0530 | [diff] [blame^] | 68 | if (ret < 0) |
| 69 | goto load_library_failed; |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 70 | |
| 71 | stream_tag = ctx->dsp_ops.prepare(ctx->dev, 0x40, |
| 72 | stripped_fw.size, &dmab); |
| 73 | if (stream_tag <= 0) { |
| 74 | dev_err(ctx->dev, "Lib prepare DMA err: %x\n", |
| 75 | stream_tag); |
| 76 | ret = stream_tag; |
| 77 | goto load_library_failed; |
| 78 | } |
| 79 | |
| 80 | dma_id = stream_tag - 1; |
| 81 | memcpy(dmab.area, stripped_fw.data, stripped_fw.size); |
| 82 | |
| 83 | ctx->dsp_ops.trigger(ctx->dev, true, stream_tag); |
| 84 | ret = skl_sst_ipc_load_library(&skl->ipc, dma_id, i); |
| 85 | if (ret < 0) |
| 86 | dev_err(ctx->dev, "IPC Load Lib for %s fail: %d\n", |
Jeeja KP | eee0e16 | 2017-01-02 09:50:04 +0530 | [diff] [blame] | 87 | linfo[i].name, ret); |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 88 | |
| 89 | ctx->dsp_ops.trigger(ctx->dev, false, stream_tag); |
| 90 | ctx->dsp_ops.cleanup(ctx->dev, &dmab, stream_tag); |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | return ret; |
| 94 | |
| 95 | load_library_failed: |
Subhransu S. Prusty | ebe8907 | 2017-04-25 12:18:20 +0530 | [diff] [blame^] | 96 | skl_release_library(linfo, lib_count); |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 97 | return ret; |
| 98 | } |
| 99 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 100 | /* |
| 101 | * First boot sequence has some extra steps. Core 0 waits for power |
| 102 | * status on core 1, so power up core 1 also momentarily, keep it in |
| 103 | * reset/stall and then turn it off |
| 104 | */ |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 105 | static int sst_bxt_prepare_fw(struct sst_dsp *ctx, |
| 106 | const void *fwdata, u32 fwsize) |
| 107 | { |
Jeeja KP | eee0e16 | 2017-01-02 09:50:04 +0530 | [diff] [blame] | 108 | int stream_tag, ret; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 109 | |
| 110 | stream_tag = ctx->dsp_ops.prepare(ctx->dev, 0x40, fwsize, &ctx->dmab); |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 111 | if (stream_tag <= 0) { |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 112 | dev_err(ctx->dev, "Failed to prepare DMA FW loading err: %x\n", |
| 113 | stream_tag); |
| 114 | return stream_tag; |
| 115 | } |
| 116 | |
| 117 | ctx->dsp_ops.stream_tag = stream_tag; |
| 118 | memcpy(ctx->dmab.area, fwdata, fwsize); |
| 119 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 120 | /* Step 1: Power up core 0 and core1 */ |
| 121 | ret = skl_dsp_core_power_up(ctx, SKL_DSP_CORE0_MASK | |
| 122 | SKL_DSP_CORE_MASK(1)); |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 123 | if (ret < 0) { |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 124 | dev_err(ctx->dev, "dsp core0/1 power up failed\n"); |
Senthilnathan Veppur | 2023576 | 2016-06-13 17:59:02 +0530 | [diff] [blame] | 125 | goto base_fw_load_failed; |
| 126 | } |
| 127 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 128 | /* Step 2: Purge FW request */ |
Senthilnathan Veppur | 2023576 | 2016-06-13 17:59:02 +0530 | [diff] [blame] | 129 | sst_dsp_shim_write(ctx, SKL_ADSP_REG_HIPCI, SKL_ADSP_REG_HIPCI_BUSY | |
| 130 | (BXT_IPC_PURGE_FW | ((stream_tag - 1) << 9))); |
| 131 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 132 | /* Step 3: Unset core0 reset state & unstall/run core0 */ |
Jayachandran B | 052f103 | 2016-06-21 10:17:41 +0530 | [diff] [blame] | 133 | ret = skl_dsp_start_core(ctx, SKL_DSP_CORE0_MASK); |
Senthilnathan Veppur | 2023576 | 2016-06-13 17:59:02 +0530 | [diff] [blame] | 134 | if (ret < 0) { |
| 135 | dev_err(ctx->dev, "Start dsp core failed ret: %d\n", ret); |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 136 | ret = -EIO; |
| 137 | goto base_fw_load_failed; |
| 138 | } |
| 139 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 140 | /* Step 4: Wait for DONE Bit */ |
Jeeja KP | 1448099 | 2017-01-02 09:50:03 +0530 | [diff] [blame] | 141 | ret = sst_dsp_register_poll(ctx, SKL_ADSP_REG_HIPCIE, |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 142 | SKL_ADSP_REG_HIPCIE_DONE, |
Jeeja KP | 1448099 | 2017-01-02 09:50:03 +0530 | [diff] [blame] | 143 | SKL_ADSP_REG_HIPCIE_DONE, |
| 144 | BXT_INIT_TIMEOUT, "HIPCIE Done"); |
| 145 | if (ret < 0) { |
Colin Ian King | 5f75b19 | 2017-03-30 11:09:34 +0100 | [diff] [blame] | 146 | dev_err(ctx->dev, "Timeout for Purge Request%d\n", ret); |
Jeeja KP | 1448099 | 2017-01-02 09:50:03 +0530 | [diff] [blame] | 147 | goto base_fw_load_failed; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 148 | } |
| 149 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 150 | /* Step 5: power down core1 */ |
| 151 | ret = skl_dsp_core_power_down(ctx, SKL_DSP_CORE_MASK(1)); |
| 152 | if (ret < 0) { |
| 153 | dev_err(ctx->dev, "dsp core1 power down failed\n"); |
| 154 | goto base_fw_load_failed; |
| 155 | } |
| 156 | |
| 157 | /* Step 6: Enable Interrupt */ |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 158 | skl_ipc_int_enable(ctx); |
| 159 | skl_ipc_op_int_enable(ctx); |
| 160 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 161 | /* Step 7: Wait for ROM init */ |
Jeeja KP | 1448099 | 2017-01-02 09:50:03 +0530 | [diff] [blame] | 162 | ret = sst_dsp_register_poll(ctx, BXT_ADSP_FW_STATUS, SKL_FW_STS_MASK, |
Jeeja KP | 7d3f91d | 2017-02-17 22:48:57 +0530 | [diff] [blame] | 163 | SKL_FW_INIT, BXT_ROM_INIT_TIMEOUT, "ROM Load"); |
Jeeja KP | 1448099 | 2017-01-02 09:50:03 +0530 | [diff] [blame] | 164 | if (ret < 0) { |
| 165 | dev_err(ctx->dev, "Timeout for ROM init, ret:%d\n", ret); |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 166 | goto base_fw_load_failed; |
| 167 | } |
| 168 | |
| 169 | return ret; |
| 170 | |
| 171 | base_fw_load_failed: |
| 172 | ctx->dsp_ops.cleanup(ctx->dev, &ctx->dmab, stream_tag); |
Jayachandran B | 052f103 | 2016-06-21 10:17:41 +0530 | [diff] [blame] | 173 | skl_dsp_core_power_down(ctx, SKL_DSP_CORE_MASK(1)); |
Senthilnathan Veppur | c787226 | 2016-07-14 09:05:25 +0530 | [diff] [blame] | 174 | skl_dsp_disable_core(ctx, SKL_DSP_CORE0_MASK); |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 175 | return ret; |
| 176 | } |
| 177 | |
| 178 | static int sst_transfer_fw_host_dma(struct sst_dsp *ctx) |
| 179 | { |
| 180 | int ret; |
| 181 | |
| 182 | ctx->dsp_ops.trigger(ctx->dev, true, ctx->dsp_ops.stream_tag); |
| 183 | ret = sst_dsp_register_poll(ctx, BXT_ADSP_FW_STATUS, SKL_FW_STS_MASK, |
| 184 | BXT_ROM_INIT, BXT_BASEFW_TIMEOUT, "Firmware boot"); |
| 185 | |
| 186 | ctx->dsp_ops.trigger(ctx->dev, false, ctx->dsp_ops.stream_tag); |
| 187 | ctx->dsp_ops.cleanup(ctx->dev, &ctx->dmab, ctx->dsp_ops.stream_tag); |
| 188 | |
| 189 | return ret; |
| 190 | } |
| 191 | |
| 192 | static int bxt_load_base_firmware(struct sst_dsp *ctx) |
| 193 | { |
Vinod Koul | bf242d1 | 2016-05-30 17:42:58 +0530 | [diff] [blame] | 194 | struct firmware stripped_fw; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 195 | struct skl_sst *skl = ctx->thread_context; |
Jeeja KP | 7d3f91d | 2017-02-17 22:48:57 +0530 | [diff] [blame] | 196 | int ret, i; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 197 | |
Jeeja KP | 31d648f | 2017-02-17 22:48:56 +0530 | [diff] [blame] | 198 | if (ctx->fw == NULL) { |
| 199 | ret = request_firmware(&ctx->fw, ctx->fw_name, ctx->dev); |
| 200 | if (ret < 0) { |
| 201 | dev_err(ctx->dev, "Request firmware failed %d\n", ret); |
| 202 | return ret; |
| 203 | } |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 204 | } |
| 205 | |
Vinod Koul | 0bdd6d8 | 2016-07-26 18:06:46 +0530 | [diff] [blame] | 206 | /* prase uuids on first boot */ |
| 207 | if (skl->is_first_boot) { |
| 208 | ret = snd_skl_parse_uuids(ctx, ctx->fw, BXT_ADSP_FW_BIN_HDR_OFFSET, 0); |
| 209 | if (ret < 0) |
| 210 | goto sst_load_base_firmware_failed; |
| 211 | } |
Vinod Koul | bf242d1 | 2016-05-30 17:42:58 +0530 | [diff] [blame] | 212 | |
| 213 | stripped_fw.data = ctx->fw->data; |
| 214 | stripped_fw.size = ctx->fw->size; |
| 215 | skl_dsp_strip_extended_manifest(&stripped_fw); |
| 216 | |
Jeeja KP | 7d3f91d | 2017-02-17 22:48:57 +0530 | [diff] [blame] | 217 | |
| 218 | for (i = 0; i < BXT_FW_ROM_INIT_RETRY; i++) { |
Vinod Koul | bf242d1 | 2016-05-30 17:42:58 +0530 | [diff] [blame] | 219 | ret = sst_bxt_prepare_fw(ctx, stripped_fw.data, stripped_fw.size); |
Jeeja KP | 7d3f91d | 2017-02-17 22:48:57 +0530 | [diff] [blame] | 220 | if (ret == 0) |
| 221 | break; |
| 222 | } |
| 223 | |
| 224 | if (ret < 0) { |
| 225 | dev_err(ctx->dev, "Error code=0x%x: FW status=0x%x\n", |
Senthilnathan Veppur | 2023576 | 2016-06-13 17:59:02 +0530 | [diff] [blame] | 226 | sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE), |
| 227 | sst_dsp_shim_read(ctx, BXT_ADSP_FW_STATUS)); |
| 228 | |
Jeeja KP | 7d3f91d | 2017-02-17 22:48:57 +0530 | [diff] [blame] | 229 | dev_err(ctx->dev, "Core En/ROM load fail:%d\n", ret); |
| 230 | goto sst_load_base_firmware_failed; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | ret = sst_transfer_fw_host_dma(ctx); |
| 234 | if (ret < 0) { |
| 235 | dev_err(ctx->dev, "Transfer firmware failed %d\n", ret); |
| 236 | dev_info(ctx->dev, "Error code=0x%x: FW status=0x%x\n", |
| 237 | sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE), |
| 238 | sst_dsp_shim_read(ctx, BXT_ADSP_FW_STATUS)); |
| 239 | |
Jayachandran B | 052f103 | 2016-06-21 10:17:41 +0530 | [diff] [blame] | 240 | skl_dsp_disable_core(ctx, SKL_DSP_CORE0_MASK); |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 241 | } else { |
| 242 | dev_dbg(ctx->dev, "Firmware download successful\n"); |
| 243 | ret = wait_event_timeout(skl->boot_wait, skl->boot_complete, |
| 244 | msecs_to_jiffies(SKL_IPC_BOOT_MSECS)); |
| 245 | if (ret == 0) { |
| 246 | dev_err(ctx->dev, "DSP boot fail, FW Ready timeout\n"); |
Jayachandran B | 052f103 | 2016-06-21 10:17:41 +0530 | [diff] [blame] | 247 | skl_dsp_disable_core(ctx, SKL_DSP_CORE0_MASK); |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 248 | ret = -EIO; |
| 249 | } else { |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 250 | ret = 0; |
Jayachandran B | 1665c17 | 2016-06-13 17:59:01 +0530 | [diff] [blame] | 251 | skl->fw_loaded = true; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
Jeeja KP | 31d648f | 2017-02-17 22:48:56 +0530 | [diff] [blame] | 255 | return ret; |
| 256 | |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 257 | sst_load_base_firmware_failed: |
Vinod Koul | fdfa82e | 2016-05-30 17:42:56 +0530 | [diff] [blame] | 258 | release_firmware(ctx->fw); |
Jeeja KP | 31d648f | 2017-02-17 22:48:56 +0530 | [diff] [blame] | 259 | ctx->fw = NULL; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 260 | return ret; |
| 261 | } |
| 262 | |
Jayachandran B | 5bb4cd4 | 2016-11-03 17:07:17 +0530 | [diff] [blame] | 263 | /* |
| 264 | * Decide the D0i3 state that can be targeted based on the usecase |
| 265 | * ref counts and DSP state |
| 266 | * |
| 267 | * Decision Matrix: (X= dont care; state = target state) |
| 268 | * |
| 269 | * DSP state != SKL_DSP_RUNNING ; state = no d0i3 |
| 270 | * |
| 271 | * DSP state == SKL_DSP_RUNNING , the following matrix applies |
| 272 | * non_d0i3 >0; streaming =X; non_streaming =X; state = no d0i3 |
| 273 | * non_d0i3 =X; streaming =0; non_streaming =0; state = no d0i3 |
| 274 | * non_d0i3 =0; streaming >0; non_streaming =X; state = streaming d0i3 |
| 275 | * non_d0i3 =0; streaming =0; non_streaming =X; state = non-streaming d0i3 |
| 276 | */ |
| 277 | static int bxt_d0i3_target_state(struct sst_dsp *ctx) |
| 278 | { |
| 279 | struct skl_sst *skl = ctx->thread_context; |
| 280 | struct skl_d0i3_data *d0i3 = &skl->d0i3; |
| 281 | |
| 282 | if (skl->cores.state[SKL_DSP_CORE0_ID] != SKL_DSP_RUNNING) |
| 283 | return SKL_DSP_D0I3_NONE; |
| 284 | |
| 285 | if (d0i3->non_d0i3) |
| 286 | return SKL_DSP_D0I3_NONE; |
| 287 | else if (d0i3->streaming) |
| 288 | return SKL_DSP_D0I3_STREAMING; |
| 289 | else if (d0i3->non_streaming) |
| 290 | return SKL_DSP_D0I3_NON_STREAMING; |
| 291 | else |
| 292 | return SKL_DSP_D0I3_NONE; |
| 293 | } |
| 294 | |
| 295 | static void bxt_set_dsp_D0i3(struct work_struct *work) |
| 296 | { |
| 297 | int ret; |
| 298 | struct skl_ipc_d0ix_msg msg; |
| 299 | struct skl_sst *skl = container_of(work, |
| 300 | struct skl_sst, d0i3.work.work); |
| 301 | struct sst_dsp *ctx = skl->dsp; |
| 302 | struct skl_d0i3_data *d0i3 = &skl->d0i3; |
| 303 | int target_state; |
| 304 | |
| 305 | dev_dbg(ctx->dev, "In %s:\n", __func__); |
| 306 | |
| 307 | /* D0i3 entry allowed only if core 0 alone is running */ |
| 308 | if (skl_dsp_get_enabled_cores(ctx) != SKL_DSP_CORE0_MASK) { |
| 309 | dev_warn(ctx->dev, |
| 310 | "D0i3 allowed when only core0 running:Exit\n"); |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | target_state = bxt_d0i3_target_state(ctx); |
| 315 | if (target_state == SKL_DSP_D0I3_NONE) |
| 316 | return; |
| 317 | |
| 318 | msg.instance_id = 0; |
| 319 | msg.module_id = 0; |
| 320 | msg.wake = 1; |
| 321 | msg.streaming = 0; |
| 322 | if (target_state == SKL_DSP_D0I3_STREAMING) |
| 323 | msg.streaming = 1; |
| 324 | |
| 325 | ret = skl_ipc_set_d0ix(&skl->ipc, &msg); |
| 326 | |
| 327 | if (ret < 0) { |
| 328 | dev_err(ctx->dev, "Failed to set DSP to D0i3 state\n"); |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | /* Set Vendor specific register D0I3C.I3 to enable D0i3*/ |
| 333 | if (skl->update_d0i3c) |
| 334 | skl->update_d0i3c(skl->dev, true); |
| 335 | |
| 336 | d0i3->state = target_state; |
| 337 | skl->cores.state[SKL_DSP_CORE0_ID] = SKL_DSP_RUNNING_D0I3; |
| 338 | } |
| 339 | |
| 340 | static int bxt_schedule_dsp_D0i3(struct sst_dsp *ctx) |
| 341 | { |
| 342 | struct skl_sst *skl = ctx->thread_context; |
| 343 | struct skl_d0i3_data *d0i3 = &skl->d0i3; |
| 344 | |
| 345 | /* Schedule D0i3 only if the usecase ref counts are appropriate */ |
| 346 | if (bxt_d0i3_target_state(ctx) != SKL_DSP_D0I3_NONE) { |
| 347 | |
| 348 | dev_dbg(ctx->dev, "%s: Schedule D0i3\n", __func__); |
| 349 | |
| 350 | schedule_delayed_work(&d0i3->work, |
| 351 | msecs_to_jiffies(BXT_D0I3_DELAY)); |
| 352 | } |
| 353 | |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | static int bxt_set_dsp_D0i0(struct sst_dsp *ctx) |
| 358 | { |
| 359 | int ret; |
| 360 | struct skl_ipc_d0ix_msg msg; |
| 361 | struct skl_sst *skl = ctx->thread_context; |
| 362 | |
| 363 | dev_dbg(ctx->dev, "In %s:\n", __func__); |
| 364 | |
| 365 | /* First Cancel any pending attempt to put DSP to D0i3 */ |
| 366 | cancel_delayed_work_sync(&skl->d0i3.work); |
| 367 | |
| 368 | /* If DSP is currently in D0i3, bring it to D0i0 */ |
| 369 | if (skl->cores.state[SKL_DSP_CORE0_ID] != SKL_DSP_RUNNING_D0I3) |
| 370 | return 0; |
| 371 | |
| 372 | dev_dbg(ctx->dev, "Set DSP to D0i0\n"); |
| 373 | |
| 374 | msg.instance_id = 0; |
| 375 | msg.module_id = 0; |
| 376 | msg.streaming = 0; |
| 377 | msg.wake = 0; |
| 378 | |
| 379 | if (skl->d0i3.state == SKL_DSP_D0I3_STREAMING) |
| 380 | msg.streaming = 1; |
| 381 | |
| 382 | /* Clear Vendor specific register D0I3C.I3 to disable D0i3*/ |
| 383 | if (skl->update_d0i3c) |
| 384 | skl->update_d0i3c(skl->dev, false); |
| 385 | |
| 386 | ret = skl_ipc_set_d0ix(&skl->ipc, &msg); |
| 387 | if (ret < 0) { |
| 388 | dev_err(ctx->dev, "Failed to set DSP to D0i0\n"); |
| 389 | return ret; |
| 390 | } |
| 391 | |
| 392 | skl->cores.state[SKL_DSP_CORE0_ID] = SKL_DSP_RUNNING; |
| 393 | skl->d0i3.state = SKL_DSP_D0I3_NONE; |
| 394 | |
| 395 | return 0; |
| 396 | } |
| 397 | |
Jayachandran B | 052f103 | 2016-06-21 10:17:41 +0530 | [diff] [blame] | 398 | static int bxt_set_dsp_D0(struct sst_dsp *ctx, unsigned int core_id) |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 399 | { |
| 400 | struct skl_sst *skl = ctx->thread_context; |
| 401 | int ret; |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 402 | struct skl_ipc_dxstate_info dx; |
| 403 | unsigned int core_mask = SKL_DSP_CORE_MASK(core_id); |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 404 | |
Jayachandran B | 1665c17 | 2016-06-13 17:59:01 +0530 | [diff] [blame] | 405 | if (skl->fw_loaded == false) { |
Senthilnathan Veppur | c787226 | 2016-07-14 09:05:25 +0530 | [diff] [blame] | 406 | skl->boot_complete = false; |
Jayachandran B | 1665c17 | 2016-06-13 17:59:01 +0530 | [diff] [blame] | 407 | ret = bxt_load_base_firmware(ctx); |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 408 | if (ret < 0) { |
Jayachandran B | 1665c17 | 2016-06-13 17:59:01 +0530 | [diff] [blame] | 409 | dev_err(ctx->dev, "reload fw failed: %d\n", ret); |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 410 | return ret; |
| 411 | } |
| 412 | |
Jeeja KP | eee0e16 | 2017-01-02 09:50:04 +0530 | [diff] [blame] | 413 | if (skl->lib_count > 1) { |
| 414 | ret = bxt_load_library(ctx, skl->lib_info, |
| 415 | skl->lib_count); |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 416 | if (ret < 0) { |
| 417 | dev_err(ctx->dev, "reload libs failed: %d\n", ret); |
| 418 | return ret; |
| 419 | } |
| 420 | } |
Jeeja KP | 1fb344a | 2017-03-13 22:11:26 +0530 | [diff] [blame] | 421 | skl->cores.state[core_id] = SKL_DSP_RUNNING; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 422 | return ret; |
| 423 | } |
| 424 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 425 | /* If core 0 is being turned on, turn on core 1 as well */ |
| 426 | if (core_id == SKL_DSP_CORE0_ID) |
| 427 | ret = skl_dsp_core_power_up(ctx, core_mask | |
| 428 | SKL_DSP_CORE_MASK(1)); |
| 429 | else |
| 430 | ret = skl_dsp_core_power_up(ctx, core_mask); |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 431 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 432 | if (ret < 0) |
| 433 | goto err; |
| 434 | |
| 435 | if (core_id == SKL_DSP_CORE0_ID) { |
| 436 | |
| 437 | /* |
| 438 | * Enable interrupt after SPA is set and before |
| 439 | * DSP is unstalled |
| 440 | */ |
| 441 | skl_ipc_int_enable(ctx); |
| 442 | skl_ipc_op_int_enable(ctx); |
| 443 | skl->boot_complete = false; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 444 | } |
| 445 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 446 | ret = skl_dsp_start_core(ctx, core_mask); |
| 447 | if (ret < 0) |
| 448 | goto err; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 449 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 450 | if (core_id == SKL_DSP_CORE0_ID) { |
| 451 | ret = wait_event_timeout(skl->boot_wait, |
| 452 | skl->boot_complete, |
| 453 | msecs_to_jiffies(SKL_IPC_BOOT_MSECS)); |
| 454 | |
| 455 | /* If core 1 was turned on for booting core 0, turn it off */ |
| 456 | skl_dsp_core_power_down(ctx, SKL_DSP_CORE_MASK(1)); |
| 457 | if (ret == 0) { |
| 458 | dev_err(ctx->dev, "%s: DSP boot timeout\n", __func__); |
| 459 | dev_err(ctx->dev, "Error code=0x%x: FW status=0x%x\n", |
| 460 | sst_dsp_shim_read(ctx, BXT_ADSP_ERROR_CODE), |
| 461 | sst_dsp_shim_read(ctx, BXT_ADSP_FW_STATUS)); |
| 462 | dev_err(ctx->dev, "Failed to set core0 to D0 state\n"); |
| 463 | ret = -EIO; |
| 464 | goto err; |
| 465 | } |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 466 | } |
| 467 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 468 | /* Tell FW if additional core in now On */ |
| 469 | |
| 470 | if (core_id != SKL_DSP_CORE0_ID) { |
| 471 | dx.core_mask = core_mask; |
| 472 | dx.dx_mask = core_mask; |
| 473 | |
| 474 | ret = skl_ipc_set_dx(&skl->ipc, BXT_INSTANCE_ID, |
| 475 | BXT_BASE_FW_MODULE_ID, &dx); |
| 476 | if (ret < 0) { |
| 477 | dev_err(ctx->dev, "IPC set_dx for core %d fail: %d\n", |
| 478 | core_id, ret); |
| 479 | goto err; |
| 480 | } |
| 481 | } |
| 482 | |
| 483 | skl->cores.state[core_id] = SKL_DSP_RUNNING; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 484 | return 0; |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 485 | err: |
| 486 | if (core_id == SKL_DSP_CORE0_ID) |
| 487 | core_mask |= SKL_DSP_CORE_MASK(1); |
| 488 | skl_dsp_disable_core(ctx, core_mask); |
| 489 | |
| 490 | return ret; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 491 | } |
| 492 | |
Jayachandran B | 052f103 | 2016-06-21 10:17:41 +0530 | [diff] [blame] | 493 | static int bxt_set_dsp_D3(struct sst_dsp *ctx, unsigned int core_id) |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 494 | { |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 495 | int ret; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 496 | struct skl_ipc_dxstate_info dx; |
| 497 | struct skl_sst *skl = ctx->thread_context; |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 498 | unsigned int core_mask = SKL_DSP_CORE_MASK(core_id); |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 499 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 500 | dx.core_mask = core_mask; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 501 | dx.dx_mask = SKL_IPC_D3_MASK; |
| 502 | |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 503 | dev_dbg(ctx->dev, "core mask=%x dx_mask=%x\n", |
| 504 | dx.core_mask, dx.dx_mask); |
| 505 | |
| 506 | ret = skl_ipc_set_dx(&skl->ipc, BXT_INSTANCE_ID, |
| 507 | BXT_BASE_FW_MODULE_ID, &dx); |
Jeeja KP | 03de8c2 | 2017-03-13 22:11:27 +0530 | [diff] [blame] | 508 | if (ret < 0) { |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 509 | dev_err(ctx->dev, |
| 510 | "Failed to set DSP to D3:core id = %d;Continue reset\n", |
| 511 | core_id); |
Jeeja KP | 03de8c2 | 2017-03-13 22:11:27 +0530 | [diff] [blame] | 512 | /* |
| 513 | * In case of D3 failure, re-download the firmware, so set |
| 514 | * fw_loaded to false. |
| 515 | */ |
| 516 | skl->fw_loaded = false; |
| 517 | } |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 518 | |
Jeeja KP | 5518af9 | 2017-03-13 22:11:25 +0530 | [diff] [blame] | 519 | if (core_id == SKL_DSP_CORE0_ID) { |
| 520 | /* disable Interrupt */ |
| 521 | skl_ipc_op_int_disable(ctx); |
| 522 | skl_ipc_int_disable(ctx); |
| 523 | } |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 524 | ret = skl_dsp_disable_core(ctx, core_mask); |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 525 | if (ret < 0) { |
Colin Ian King | ecd286a | 2016-09-16 18:51:21 +0100 | [diff] [blame] | 526 | dev_err(ctx->dev, "Failed to disable core %d\n", ret); |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 527 | return ret; |
| 528 | } |
Jayachandran B | e68aca0 | 2016-06-21 10:17:43 +0530 | [diff] [blame] | 529 | skl->cores.state[core_id] = SKL_DSP_RESET; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | static struct skl_dsp_fw_ops bxt_fw_ops = { |
| 534 | .set_state_D0 = bxt_set_dsp_D0, |
| 535 | .set_state_D3 = bxt_set_dsp_D3, |
Jayachandran B | 5bb4cd4 | 2016-11-03 17:07:17 +0530 | [diff] [blame] | 536 | .set_state_D0i3 = bxt_schedule_dsp_D0i3, |
| 537 | .set_state_D0i0 = bxt_set_dsp_D0i0, |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 538 | .load_fw = bxt_load_base_firmware, |
| 539 | .get_fw_errcode = bxt_get_errorcode, |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 540 | .load_library = bxt_load_library, |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 541 | }; |
| 542 | |
| 543 | static struct sst_ops skl_ops = { |
| 544 | .irq_handler = skl_dsp_sst_interrupt, |
| 545 | .write = sst_shim32_write, |
| 546 | .read = sst_shim32_read, |
| 547 | .ram_read = sst_memcpy_fromio_32, |
| 548 | .ram_write = sst_memcpy_toio_32, |
| 549 | .free = skl_dsp_free, |
| 550 | }; |
| 551 | |
| 552 | static struct sst_dsp_device skl_dev = { |
| 553 | .thread = skl_dsp_irq_thread_handler, |
| 554 | .ops = &skl_ops, |
| 555 | }; |
| 556 | |
| 557 | int bxt_sst_dsp_init(struct device *dev, void __iomem *mmio_base, int irq, |
| 558 | const char *fw_name, struct skl_dsp_loader_ops dsp_ops, |
| 559 | struct skl_sst **dsp) |
| 560 | { |
| 561 | struct skl_sst *skl; |
| 562 | struct sst_dsp *sst; |
| 563 | int ret; |
| 564 | |
G Kranthi | 9fe9c71 | 2017-04-25 12:18:19 +0530 | [diff] [blame] | 565 | ret = skl_sst_ctx_init(dev, irq, fw_name, dsp_ops, dsp, &skl_dev); |
| 566 | if (ret < 0) { |
| 567 | dev_err(skl->dev, "%s: no device\n", __func__); |
| 568 | return ret; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 569 | } |
| 570 | |
G Kranthi | 9fe9c71 | 2017-04-25 12:18:19 +0530 | [diff] [blame] | 571 | skl = *dsp; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 572 | sst = skl->dsp; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 573 | sst->fw_ops = bxt_fw_ops; |
| 574 | sst->addr.lpe = mmio_base; |
| 575 | sst->addr.shim = mmio_base; |
| 576 | |
| 577 | sst_dsp_mailbox_init(sst, (BXT_ADSP_SRAM0_BASE + SKL_ADSP_W0_STAT_SZ), |
| 578 | SKL_ADSP_W0_UP_SZ, BXT_ADSP_SRAM1_BASE, SKL_ADSP_W1_SZ); |
| 579 | |
Vinod Koul | a83e3b4 | 2016-11-03 17:07:20 +0530 | [diff] [blame] | 580 | /* set the D0i3 check */ |
| 581 | skl->ipc.ops.check_dsp_lp_on = skl_ipc_check_D0i0; |
| 582 | |
Jayachandran B | 052f103 | 2016-06-21 10:17:41 +0530 | [diff] [blame] | 583 | skl->cores.count = 2; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 584 | skl->boot_complete = false; |
| 585 | init_waitqueue_head(&skl->boot_wait); |
Vinod Koul | a83e3b4 | 2016-11-03 17:07:20 +0530 | [diff] [blame] | 586 | INIT_DELAYED_WORK(&skl->d0i3.work, bxt_set_dsp_D0i3); |
| 587 | skl->d0i3.state = SKL_DSP_D0I3_NONE; |
Vinod Koul | 78cdbbd | 2016-07-26 18:06:42 +0530 | [diff] [blame] | 588 | |
Vinod Koul | 78cdbbd | 2016-07-26 18:06:42 +0530 | [diff] [blame] | 589 | return 0; |
| 590 | } |
| 591 | EXPORT_SYMBOL_GPL(bxt_sst_dsp_init); |
| 592 | |
| 593 | int bxt_sst_init_fw(struct device *dev, struct skl_sst *ctx) |
| 594 | { |
| 595 | int ret; |
| 596 | struct sst_dsp *sst = ctx->dsp; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 597 | |
| 598 | ret = sst->fw_ops.load_fw(sst); |
| 599 | if (ret < 0) { |
Colin Ian King | ecd286a | 2016-09-16 18:51:21 +0100 | [diff] [blame] | 600 | dev_err(dev, "Load base fw failed: %x\n", ret); |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 601 | return ret; |
| 602 | } |
| 603 | |
Jayachandran B | 052f103 | 2016-06-21 10:17:41 +0530 | [diff] [blame] | 604 | skl_dsp_init_core_state(sst); |
| 605 | |
Jeeja KP | eee0e16 | 2017-01-02 09:50:04 +0530 | [diff] [blame] | 606 | if (ctx->lib_count > 1) { |
| 607 | ret = sst->fw_ops.load_library(sst, ctx->lib_info, |
| 608 | ctx->lib_count); |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 609 | if (ret < 0) { |
Colin Ian King | ecd286a | 2016-09-16 18:51:21 +0100 | [diff] [blame] | 610 | dev_err(dev, "Load Library failed : %x\n", ret); |
Ramesh Babu | 1ef015e | 2016-07-26 18:06:48 +0530 | [diff] [blame] | 611 | return ret; |
| 612 | } |
| 613 | } |
Vinod Koul | 78cdbbd | 2016-07-26 18:06:42 +0530 | [diff] [blame] | 614 | ctx->is_first_boot = false; |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 615 | |
| 616 | return 0; |
| 617 | } |
Vinod Koul | 78cdbbd | 2016-07-26 18:06:42 +0530 | [diff] [blame] | 618 | EXPORT_SYMBOL_GPL(bxt_sst_init_fw); |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 619 | |
| 620 | void bxt_sst_dsp_cleanup(struct device *dev, struct skl_sst *ctx) |
| 621 | { |
Jeeja KP | 31d648f | 2017-02-17 22:48:56 +0530 | [diff] [blame] | 622 | |
Subhransu S. Prusty | ebe8907 | 2017-04-25 12:18:20 +0530 | [diff] [blame^] | 623 | skl_release_library(ctx->lib_info, ctx->lib_count); |
Jeeja KP | 31d648f | 2017-02-17 22:48:56 +0530 | [diff] [blame] | 624 | if (ctx->dsp->fw) |
| 625 | release_firmware(ctx->dsp->fw); |
Vinod Koul | 3467a64 | 2016-05-30 17:43:01 +0530 | [diff] [blame] | 626 | skl_freeup_uuid_list(ctx); |
Jeeja KP | 92eb4f6 | 2016-03-11 10:12:56 +0530 | [diff] [blame] | 627 | skl_ipc_free(&ctx->ipc); |
| 628 | ctx->dsp->cl_dev.ops.cl_cleanup_controller(ctx->dsp); |
| 629 | |
| 630 | if (ctx->dsp->addr.lpe) |
| 631 | iounmap(ctx->dsp->addr.lpe); |
| 632 | |
| 633 | ctx->dsp->ops->free(ctx->dsp); |
| 634 | } |
| 635 | EXPORT_SYMBOL_GPL(bxt_sst_dsp_cleanup); |
| 636 | |
| 637 | MODULE_LICENSE("GPL v2"); |
| 638 | MODULE_DESCRIPTION("Intel Broxton IPC driver"); |