Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1 | /* |
| 2 | * wm_adsp.c -- Wolfson ADSP support |
| 3 | * |
| 4 | * Copyright 2012 Wolfson Microelectronics plc |
| 5 | * |
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.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 version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/moduleparam.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/firmware.h> |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 18 | #include <linux/list.h> |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 19 | #include <linux/pm.h> |
| 20 | #include <linux/pm_runtime.h> |
| 21 | #include <linux/regmap.h> |
Mark Brown | 973838a | 2012-11-28 17:20:32 +0000 | [diff] [blame] | 22 | #include <linux/regulator/consumer.h> |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Charles Keepax | cdcd7f7 | 2014-11-14 15:40:45 +0000 | [diff] [blame] | 24 | #include <linux/vmalloc.h> |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 25 | #include <linux/workqueue.h> |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 26 | #include <linux/debugfs.h> |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 27 | #include <sound/core.h> |
| 28 | #include <sound/pcm.h> |
| 29 | #include <sound/pcm_params.h> |
| 30 | #include <sound/soc.h> |
| 31 | #include <sound/jack.h> |
| 32 | #include <sound/initval.h> |
| 33 | #include <sound/tlv.h> |
| 34 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 35 | #include "wm_adsp.h" |
| 36 | |
| 37 | #define adsp_crit(_dsp, fmt, ...) \ |
| 38 | dev_crit(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__) |
| 39 | #define adsp_err(_dsp, fmt, ...) \ |
| 40 | dev_err(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__) |
| 41 | #define adsp_warn(_dsp, fmt, ...) \ |
| 42 | dev_warn(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__) |
| 43 | #define adsp_info(_dsp, fmt, ...) \ |
| 44 | dev_info(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__) |
| 45 | #define adsp_dbg(_dsp, fmt, ...) \ |
| 46 | dev_dbg(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__) |
| 47 | |
| 48 | #define ADSP1_CONTROL_1 0x00 |
| 49 | #define ADSP1_CONTROL_2 0x02 |
| 50 | #define ADSP1_CONTROL_3 0x03 |
| 51 | #define ADSP1_CONTROL_4 0x04 |
| 52 | #define ADSP1_CONTROL_5 0x06 |
| 53 | #define ADSP1_CONTROL_6 0x07 |
| 54 | #define ADSP1_CONTROL_7 0x08 |
| 55 | #define ADSP1_CONTROL_8 0x09 |
| 56 | #define ADSP1_CONTROL_9 0x0A |
| 57 | #define ADSP1_CONTROL_10 0x0B |
| 58 | #define ADSP1_CONTROL_11 0x0C |
| 59 | #define ADSP1_CONTROL_12 0x0D |
| 60 | #define ADSP1_CONTROL_13 0x0F |
| 61 | #define ADSP1_CONTROL_14 0x10 |
| 62 | #define ADSP1_CONTROL_15 0x11 |
| 63 | #define ADSP1_CONTROL_16 0x12 |
| 64 | #define ADSP1_CONTROL_17 0x13 |
| 65 | #define ADSP1_CONTROL_18 0x14 |
| 66 | #define ADSP1_CONTROL_19 0x16 |
| 67 | #define ADSP1_CONTROL_20 0x17 |
| 68 | #define ADSP1_CONTROL_21 0x18 |
| 69 | #define ADSP1_CONTROL_22 0x1A |
| 70 | #define ADSP1_CONTROL_23 0x1B |
| 71 | #define ADSP1_CONTROL_24 0x1C |
| 72 | #define ADSP1_CONTROL_25 0x1E |
| 73 | #define ADSP1_CONTROL_26 0x20 |
| 74 | #define ADSP1_CONTROL_27 0x21 |
| 75 | #define ADSP1_CONTROL_28 0x22 |
| 76 | #define ADSP1_CONTROL_29 0x23 |
| 77 | #define ADSP1_CONTROL_30 0x24 |
| 78 | #define ADSP1_CONTROL_31 0x26 |
| 79 | |
| 80 | /* |
| 81 | * ADSP1 Control 19 |
| 82 | */ |
| 83 | #define ADSP1_WDMA_BUFFER_LENGTH_MASK 0x00FF /* DSP1_WDMA_BUFFER_LENGTH - [7:0] */ |
| 84 | #define ADSP1_WDMA_BUFFER_LENGTH_SHIFT 0 /* DSP1_WDMA_BUFFER_LENGTH - [7:0] */ |
| 85 | #define ADSP1_WDMA_BUFFER_LENGTH_WIDTH 8 /* DSP1_WDMA_BUFFER_LENGTH - [7:0] */ |
| 86 | |
| 87 | |
| 88 | /* |
| 89 | * ADSP1 Control 30 |
| 90 | */ |
| 91 | #define ADSP1_DBG_CLK_ENA 0x0008 /* DSP1_DBG_CLK_ENA */ |
| 92 | #define ADSP1_DBG_CLK_ENA_MASK 0x0008 /* DSP1_DBG_CLK_ENA */ |
| 93 | #define ADSP1_DBG_CLK_ENA_SHIFT 3 /* DSP1_DBG_CLK_ENA */ |
| 94 | #define ADSP1_DBG_CLK_ENA_WIDTH 1 /* DSP1_DBG_CLK_ENA */ |
| 95 | #define ADSP1_SYS_ENA 0x0004 /* DSP1_SYS_ENA */ |
| 96 | #define ADSP1_SYS_ENA_MASK 0x0004 /* DSP1_SYS_ENA */ |
| 97 | #define ADSP1_SYS_ENA_SHIFT 2 /* DSP1_SYS_ENA */ |
| 98 | #define ADSP1_SYS_ENA_WIDTH 1 /* DSP1_SYS_ENA */ |
| 99 | #define ADSP1_CORE_ENA 0x0002 /* DSP1_CORE_ENA */ |
| 100 | #define ADSP1_CORE_ENA_MASK 0x0002 /* DSP1_CORE_ENA */ |
| 101 | #define ADSP1_CORE_ENA_SHIFT 1 /* DSP1_CORE_ENA */ |
| 102 | #define ADSP1_CORE_ENA_WIDTH 1 /* DSP1_CORE_ENA */ |
| 103 | #define ADSP1_START 0x0001 /* DSP1_START */ |
| 104 | #define ADSP1_START_MASK 0x0001 /* DSP1_START */ |
| 105 | #define ADSP1_START_SHIFT 0 /* DSP1_START */ |
| 106 | #define ADSP1_START_WIDTH 1 /* DSP1_START */ |
| 107 | |
Chris Rattray | 94e205b | 2013-01-18 08:43:09 +0000 | [diff] [blame] | 108 | /* |
| 109 | * ADSP1 Control 31 |
| 110 | */ |
| 111 | #define ADSP1_CLK_SEL_MASK 0x0007 /* CLK_SEL_ENA */ |
| 112 | #define ADSP1_CLK_SEL_SHIFT 0 /* CLK_SEL_ENA */ |
| 113 | #define ADSP1_CLK_SEL_WIDTH 3 /* CLK_SEL_ENA */ |
| 114 | |
Mark Brown | 2d30b57 | 2013-01-28 20:18:17 +0800 | [diff] [blame] | 115 | #define ADSP2_CONTROL 0x0 |
| 116 | #define ADSP2_CLOCKING 0x1 |
| 117 | #define ADSP2_STATUS1 0x4 |
| 118 | #define ADSP2_WDMA_CONFIG_1 0x30 |
| 119 | #define ADSP2_WDMA_CONFIG_2 0x31 |
| 120 | #define ADSP2_RDMA_CONFIG_1 0x34 |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 121 | |
Richard Fitzgerald | 10337b0 | 2015-05-29 10:23:07 +0100 | [diff] [blame] | 122 | #define ADSP2_SCRATCH0 0x40 |
| 123 | #define ADSP2_SCRATCH1 0x41 |
| 124 | #define ADSP2_SCRATCH2 0x42 |
| 125 | #define ADSP2_SCRATCH3 0x43 |
| 126 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 127 | /* |
| 128 | * ADSP2 Control |
| 129 | */ |
| 130 | |
| 131 | #define ADSP2_MEM_ENA 0x0010 /* DSP1_MEM_ENA */ |
| 132 | #define ADSP2_MEM_ENA_MASK 0x0010 /* DSP1_MEM_ENA */ |
| 133 | #define ADSP2_MEM_ENA_SHIFT 4 /* DSP1_MEM_ENA */ |
| 134 | #define ADSP2_MEM_ENA_WIDTH 1 /* DSP1_MEM_ENA */ |
| 135 | #define ADSP2_SYS_ENA 0x0004 /* DSP1_SYS_ENA */ |
| 136 | #define ADSP2_SYS_ENA_MASK 0x0004 /* DSP1_SYS_ENA */ |
| 137 | #define ADSP2_SYS_ENA_SHIFT 2 /* DSP1_SYS_ENA */ |
| 138 | #define ADSP2_SYS_ENA_WIDTH 1 /* DSP1_SYS_ENA */ |
| 139 | #define ADSP2_CORE_ENA 0x0002 /* DSP1_CORE_ENA */ |
| 140 | #define ADSP2_CORE_ENA_MASK 0x0002 /* DSP1_CORE_ENA */ |
| 141 | #define ADSP2_CORE_ENA_SHIFT 1 /* DSP1_CORE_ENA */ |
| 142 | #define ADSP2_CORE_ENA_WIDTH 1 /* DSP1_CORE_ENA */ |
| 143 | #define ADSP2_START 0x0001 /* DSP1_START */ |
| 144 | #define ADSP2_START_MASK 0x0001 /* DSP1_START */ |
| 145 | #define ADSP2_START_SHIFT 0 /* DSP1_START */ |
| 146 | #define ADSP2_START_WIDTH 1 /* DSP1_START */ |
| 147 | |
| 148 | /* |
Mark Brown | 973838a | 2012-11-28 17:20:32 +0000 | [diff] [blame] | 149 | * ADSP2 clocking |
| 150 | */ |
| 151 | #define ADSP2_CLK_SEL_MASK 0x0007 /* CLK_SEL_ENA */ |
| 152 | #define ADSP2_CLK_SEL_SHIFT 0 /* CLK_SEL_ENA */ |
| 153 | #define ADSP2_CLK_SEL_WIDTH 3 /* CLK_SEL_ENA */ |
| 154 | |
| 155 | /* |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 156 | * ADSP2 Status 1 |
| 157 | */ |
| 158 | #define ADSP2_RAM_RDY 0x0001 |
| 159 | #define ADSP2_RAM_RDY_MASK 0x0001 |
| 160 | #define ADSP2_RAM_RDY_SHIFT 0 |
| 161 | #define ADSP2_RAM_RDY_WIDTH 1 |
| 162 | |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 163 | struct wm_adsp_buf { |
| 164 | struct list_head list; |
| 165 | void *buf; |
| 166 | }; |
| 167 | |
| 168 | static struct wm_adsp_buf *wm_adsp_buf_alloc(const void *src, size_t len, |
| 169 | struct list_head *list) |
| 170 | { |
| 171 | struct wm_adsp_buf *buf = kzalloc(sizeof(*buf), GFP_KERNEL); |
| 172 | |
| 173 | if (buf == NULL) |
| 174 | return NULL; |
| 175 | |
Charles Keepax | cdcd7f7 | 2014-11-14 15:40:45 +0000 | [diff] [blame] | 176 | buf->buf = vmalloc(len); |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 177 | if (!buf->buf) { |
Charles Keepax | cdcd7f7 | 2014-11-14 15:40:45 +0000 | [diff] [blame] | 178 | vfree(buf); |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 179 | return NULL; |
| 180 | } |
Charles Keepax | cdcd7f7 | 2014-11-14 15:40:45 +0000 | [diff] [blame] | 181 | memcpy(buf->buf, src, len); |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 182 | |
| 183 | if (list) |
| 184 | list_add_tail(&buf->list, list); |
| 185 | |
| 186 | return buf; |
| 187 | } |
| 188 | |
| 189 | static void wm_adsp_buf_free(struct list_head *list) |
| 190 | { |
| 191 | while (!list_empty(list)) { |
| 192 | struct wm_adsp_buf *buf = list_first_entry(list, |
| 193 | struct wm_adsp_buf, |
| 194 | list); |
| 195 | list_del(&buf->list); |
Charles Keepax | cdcd7f7 | 2014-11-14 15:40:45 +0000 | [diff] [blame] | 196 | vfree(buf->buf); |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 197 | kfree(buf); |
| 198 | } |
| 199 | } |
| 200 | |
Charles Keepax | 04d1300 | 2015-11-26 14:01:52 +0000 | [diff] [blame] | 201 | #define WM_ADSP_FW_MBC_VSS 0 |
| 202 | #define WM_ADSP_FW_HIFI 1 |
| 203 | #define WM_ADSP_FW_TX 2 |
| 204 | #define WM_ADSP_FW_TX_SPK 3 |
| 205 | #define WM_ADSP_FW_RX 4 |
| 206 | #define WM_ADSP_FW_RX_ANC 5 |
| 207 | #define WM_ADSP_FW_CTRL 6 |
| 208 | #define WM_ADSP_FW_ASR 7 |
| 209 | #define WM_ADSP_FW_TRACE 8 |
| 210 | #define WM_ADSP_FW_SPK_PROT 9 |
| 211 | #define WM_ADSP_FW_MISC 10 |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 212 | |
Charles Keepax | 04d1300 | 2015-11-26 14:01:52 +0000 | [diff] [blame] | 213 | #define WM_ADSP_NUM_FW 11 |
Mark Brown | dd84f92 | 2013-03-08 15:25:58 +0800 | [diff] [blame] | 214 | |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 215 | static const char *wm_adsp_fw_text[WM_ADSP_NUM_FW] = { |
Charles Keepax | 04d1300 | 2015-11-26 14:01:52 +0000 | [diff] [blame] | 216 | [WM_ADSP_FW_MBC_VSS] = "MBC/VSS", |
| 217 | [WM_ADSP_FW_HIFI] = "MasterHiFi", |
| 218 | [WM_ADSP_FW_TX] = "Tx", |
| 219 | [WM_ADSP_FW_TX_SPK] = "Tx Speaker", |
| 220 | [WM_ADSP_FW_RX] = "Rx", |
| 221 | [WM_ADSP_FW_RX_ANC] = "Rx ANC", |
| 222 | [WM_ADSP_FW_CTRL] = "Voice Ctrl", |
| 223 | [WM_ADSP_FW_ASR] = "ASR Assist", |
| 224 | [WM_ADSP_FW_TRACE] = "Dbg Trace", |
| 225 | [WM_ADSP_FW_SPK_PROT] = "Protection", |
| 226 | [WM_ADSP_FW_MISC] = "Misc", |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 227 | }; |
| 228 | |
Charles Keepax | 2cd19bd | 2015-12-15 11:29:46 +0000 | [diff] [blame] | 229 | struct wm_adsp_system_config_xm_hdr { |
| 230 | __be32 sys_enable; |
| 231 | __be32 fw_id; |
| 232 | __be32 fw_rev; |
| 233 | __be32 boot_status; |
| 234 | __be32 watchdog; |
| 235 | __be32 dma_buffer_size; |
| 236 | __be32 rdma[6]; |
| 237 | __be32 wdma[8]; |
| 238 | __be32 build_job_name[3]; |
| 239 | __be32 build_job_number; |
| 240 | }; |
| 241 | |
| 242 | struct wm_adsp_alg_xm_struct { |
| 243 | __be32 magic; |
| 244 | __be32 smoothing; |
| 245 | __be32 threshold; |
| 246 | __be32 host_buf_ptr; |
| 247 | __be32 start_seq; |
| 248 | __be32 high_water_mark; |
| 249 | __be32 low_water_mark; |
| 250 | __be64 smoothed_power; |
| 251 | }; |
| 252 | |
| 253 | struct wm_adsp_buffer { |
| 254 | __be32 X_buf_base; /* XM base addr of first X area */ |
| 255 | __be32 X_buf_size; /* Size of 1st X area in words */ |
| 256 | __be32 X_buf_base2; /* XM base addr of 2nd X area */ |
| 257 | __be32 X_buf_brk; /* Total X size in words */ |
| 258 | __be32 Y_buf_base; /* YM base addr of Y area */ |
| 259 | __be32 wrap; /* Total size X and Y in words */ |
| 260 | __be32 high_water_mark; /* Point at which IRQ is asserted */ |
| 261 | __be32 irq_count; /* bits 1-31 count IRQ assertions */ |
| 262 | __be32 irq_ack; /* acked IRQ count, bit 0 enables IRQ */ |
| 263 | __be32 next_write_index; /* word index of next write */ |
| 264 | __be32 next_read_index; /* word index of next read */ |
| 265 | __be32 error; /* error if any */ |
| 266 | __be32 oldest_block_index; /* word index of oldest surviving */ |
| 267 | __be32 requested_rewind; /* how many blocks rewind was done */ |
| 268 | __be32 reserved_space; /* internal */ |
| 269 | __be32 min_free; /* min free space since stream start */ |
| 270 | __be32 blocks_written[2]; /* total blocks written (64 bit) */ |
| 271 | __be32 words_written[2]; /* total words written (64 bit) */ |
| 272 | }; |
| 273 | |
| 274 | struct wm_adsp_compr_buf { |
| 275 | struct wm_adsp *dsp; |
| 276 | |
| 277 | struct wm_adsp_buffer_region *regions; |
| 278 | u32 host_buf_ptr; |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 279 | |
| 280 | u32 error; |
| 281 | u32 irq_count; |
| 282 | int read_index; |
| 283 | int avail; |
Charles Keepax | 2cd19bd | 2015-12-15 11:29:46 +0000 | [diff] [blame] | 284 | }; |
| 285 | |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 286 | struct wm_adsp_compr { |
| 287 | struct wm_adsp *dsp; |
Charles Keepax | 95fe959 | 2015-12-15 11:29:47 +0000 | [diff] [blame] | 288 | struct wm_adsp_compr_buf *buf; |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 289 | |
| 290 | struct snd_compr_stream *stream; |
| 291 | struct snd_compressed_buffer size; |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 292 | |
Charles Keepax | 83a40ce | 2016-01-06 12:33:19 +0000 | [diff] [blame] | 293 | u32 *raw_buf; |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 294 | unsigned int copied_total; |
Charles Keepax | da2b335 | 2016-02-02 16:41:36 +0000 | [diff] [blame] | 295 | |
| 296 | unsigned int sample_rate; |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 297 | }; |
| 298 | |
| 299 | #define WM_ADSP_DATA_WORD_SIZE 3 |
| 300 | |
| 301 | #define WM_ADSP_MIN_FRAGMENTS 1 |
| 302 | #define WM_ADSP_MAX_FRAGMENTS 256 |
| 303 | #define WM_ADSP_MIN_FRAGMENT_SIZE (64 * WM_ADSP_DATA_WORD_SIZE) |
| 304 | #define WM_ADSP_MAX_FRAGMENT_SIZE (4096 * WM_ADSP_DATA_WORD_SIZE) |
| 305 | |
Charles Keepax | 2cd19bd | 2015-12-15 11:29:46 +0000 | [diff] [blame] | 306 | #define WM_ADSP_ALG_XM_STRUCT_MAGIC 0x49aec7 |
| 307 | |
| 308 | #define HOST_BUFFER_FIELD(field) \ |
| 309 | (offsetof(struct wm_adsp_buffer, field) / sizeof(__be32)) |
| 310 | |
| 311 | #define ALG_XM_FIELD(field) \ |
| 312 | (offsetof(struct wm_adsp_alg_xm_struct, field) / sizeof(__be32)) |
| 313 | |
| 314 | static int wm_adsp_buffer_init(struct wm_adsp *dsp); |
| 315 | static int wm_adsp_buffer_free(struct wm_adsp *dsp); |
| 316 | |
| 317 | struct wm_adsp_buffer_region { |
| 318 | unsigned int offset; |
| 319 | unsigned int cumulative_size; |
| 320 | unsigned int mem_type; |
| 321 | unsigned int base_addr; |
| 322 | }; |
| 323 | |
| 324 | struct wm_adsp_buffer_region_def { |
| 325 | unsigned int mem_type; |
| 326 | unsigned int base_offset; |
| 327 | unsigned int size_offset; |
| 328 | }; |
| 329 | |
Charles Keepax | 3a9686c | 2016-02-01 15:22:34 +0000 | [diff] [blame] | 330 | static const struct wm_adsp_buffer_region_def default_regions[] = { |
Charles Keepax | 2cd19bd | 2015-12-15 11:29:46 +0000 | [diff] [blame] | 331 | { |
| 332 | .mem_type = WMFW_ADSP2_XM, |
| 333 | .base_offset = HOST_BUFFER_FIELD(X_buf_base), |
| 334 | .size_offset = HOST_BUFFER_FIELD(X_buf_size), |
| 335 | }, |
| 336 | { |
| 337 | .mem_type = WMFW_ADSP2_XM, |
| 338 | .base_offset = HOST_BUFFER_FIELD(X_buf_base2), |
| 339 | .size_offset = HOST_BUFFER_FIELD(X_buf_brk), |
| 340 | }, |
| 341 | { |
| 342 | .mem_type = WMFW_ADSP2_YM, |
| 343 | .base_offset = HOST_BUFFER_FIELD(Y_buf_base), |
| 344 | .size_offset = HOST_BUFFER_FIELD(wrap), |
| 345 | }, |
| 346 | }; |
| 347 | |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 348 | struct wm_adsp_fw_caps { |
| 349 | u32 id; |
| 350 | struct snd_codec_desc desc; |
Charles Keepax | 2cd19bd | 2015-12-15 11:29:46 +0000 | [diff] [blame] | 351 | int num_regions; |
Charles Keepax | 3a9686c | 2016-02-01 15:22:34 +0000 | [diff] [blame] | 352 | const struct wm_adsp_buffer_region_def *region_defs; |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 353 | }; |
| 354 | |
Charles Keepax | e6d00f3 | 2016-01-21 17:52:58 +0000 | [diff] [blame] | 355 | static const struct wm_adsp_fw_caps ctrl_caps[] = { |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 356 | { |
| 357 | .id = SND_AUDIOCODEC_BESPOKE, |
| 358 | .desc = { |
| 359 | .max_ch = 1, |
| 360 | .sample_rates = { 16000 }, |
| 361 | .num_sample_rates = 1, |
| 362 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 363 | }, |
Charles Keepax | e6d00f3 | 2016-01-21 17:52:58 +0000 | [diff] [blame] | 364 | .num_regions = ARRAY_SIZE(default_regions), |
| 365 | .region_defs = default_regions, |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 366 | }, |
| 367 | }; |
| 368 | |
Charles Keepax | 7ce4283 | 2016-01-21 17:52:59 +0000 | [diff] [blame] | 369 | static const struct wm_adsp_fw_caps trace_caps[] = { |
| 370 | { |
| 371 | .id = SND_AUDIOCODEC_BESPOKE, |
| 372 | .desc = { |
| 373 | .max_ch = 8, |
| 374 | .sample_rates = { |
| 375 | 4000, 8000, 11025, 12000, 16000, 22050, |
| 376 | 24000, 32000, 44100, 48000, 64000, 88200, |
| 377 | 96000, 176400, 192000 |
| 378 | }, |
| 379 | .num_sample_rates = 15, |
| 380 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 381 | }, |
| 382 | .num_regions = ARRAY_SIZE(default_regions), |
| 383 | .region_defs = default_regions, |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 384 | }, |
| 385 | }; |
| 386 | |
| 387 | static const struct { |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 388 | const char *file; |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 389 | int compr_direction; |
| 390 | int num_caps; |
| 391 | const struct wm_adsp_fw_caps *caps; |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 392 | } wm_adsp_fw[WM_ADSP_NUM_FW] = { |
Charles Keepax | 04d1300 | 2015-11-26 14:01:52 +0000 | [diff] [blame] | 393 | [WM_ADSP_FW_MBC_VSS] = { .file = "mbc-vss" }, |
| 394 | [WM_ADSP_FW_HIFI] = { .file = "hifi" }, |
| 395 | [WM_ADSP_FW_TX] = { .file = "tx" }, |
| 396 | [WM_ADSP_FW_TX_SPK] = { .file = "tx-spk" }, |
| 397 | [WM_ADSP_FW_RX] = { .file = "rx" }, |
| 398 | [WM_ADSP_FW_RX_ANC] = { .file = "rx-anc" }, |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 399 | [WM_ADSP_FW_CTRL] = { |
| 400 | .file = "ctrl", |
| 401 | .compr_direction = SND_COMPRESS_CAPTURE, |
Charles Keepax | e6d00f3 | 2016-01-21 17:52:58 +0000 | [diff] [blame] | 402 | .num_caps = ARRAY_SIZE(ctrl_caps), |
| 403 | .caps = ctrl_caps, |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 404 | }, |
Charles Keepax | 04d1300 | 2015-11-26 14:01:52 +0000 | [diff] [blame] | 405 | [WM_ADSP_FW_ASR] = { .file = "asr" }, |
Charles Keepax | 7ce4283 | 2016-01-21 17:52:59 +0000 | [diff] [blame] | 406 | [WM_ADSP_FW_TRACE] = { |
| 407 | .file = "trace", |
| 408 | .compr_direction = SND_COMPRESS_CAPTURE, |
| 409 | .num_caps = ARRAY_SIZE(trace_caps), |
| 410 | .caps = trace_caps, |
| 411 | }, |
Charles Keepax | 04d1300 | 2015-11-26 14:01:52 +0000 | [diff] [blame] | 412 | [WM_ADSP_FW_SPK_PROT] = { .file = "spk-prot" }, |
| 413 | [WM_ADSP_FW_MISC] = { .file = "misc" }, |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 414 | }; |
| 415 | |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 416 | struct wm_coeff_ctl_ops { |
| 417 | int (*xget)(struct snd_kcontrol *kcontrol, |
| 418 | struct snd_ctl_elem_value *ucontrol); |
| 419 | int (*xput)(struct snd_kcontrol *kcontrol, |
| 420 | struct snd_ctl_elem_value *ucontrol); |
| 421 | int (*xinfo)(struct snd_kcontrol *kcontrol, |
| 422 | struct snd_ctl_elem_info *uinfo); |
| 423 | }; |
| 424 | |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 425 | struct wm_coeff_ctl { |
| 426 | const char *name; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 427 | const char *fw_name; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 428 | struct wm_adsp_alg_region alg_region; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 429 | struct wm_coeff_ctl_ops ops; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 430 | struct wm_adsp *dsp; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 431 | unsigned int enabled:1; |
| 432 | struct list_head list; |
| 433 | void *cache; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 434 | unsigned int offset; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 435 | size_t len; |
Dimitris Papastamos | 0c2e3f3 | 2013-05-28 12:01:50 +0100 | [diff] [blame] | 436 | unsigned int set:1; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 437 | struct snd_kcontrol *kcontrol; |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 438 | unsigned int flags; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 439 | }; |
| 440 | |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 441 | #ifdef CONFIG_DEBUG_FS |
| 442 | static void wm_adsp_debugfs_save_wmfwname(struct wm_adsp *dsp, const char *s) |
| 443 | { |
| 444 | char *tmp = kasprintf(GFP_KERNEL, "%s\n", s); |
| 445 | |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 446 | kfree(dsp->wmfw_file_name); |
| 447 | dsp->wmfw_file_name = tmp; |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | static void wm_adsp_debugfs_save_binname(struct wm_adsp *dsp, const char *s) |
| 451 | { |
| 452 | char *tmp = kasprintf(GFP_KERNEL, "%s\n", s); |
| 453 | |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 454 | kfree(dsp->bin_file_name); |
| 455 | dsp->bin_file_name = tmp; |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | static void wm_adsp_debugfs_clear(struct wm_adsp *dsp) |
| 459 | { |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 460 | kfree(dsp->wmfw_file_name); |
| 461 | kfree(dsp->bin_file_name); |
| 462 | dsp->wmfw_file_name = NULL; |
| 463 | dsp->bin_file_name = NULL; |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static ssize_t wm_adsp_debugfs_wmfw_read(struct file *file, |
| 467 | char __user *user_buf, |
| 468 | size_t count, loff_t *ppos) |
| 469 | { |
| 470 | struct wm_adsp *dsp = file->private_data; |
| 471 | ssize_t ret; |
| 472 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 473 | mutex_lock(&dsp->pwr_lock); |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 474 | |
| 475 | if (!dsp->wmfw_file_name || !dsp->running) |
| 476 | ret = 0; |
| 477 | else |
| 478 | ret = simple_read_from_buffer(user_buf, count, ppos, |
| 479 | dsp->wmfw_file_name, |
| 480 | strlen(dsp->wmfw_file_name)); |
| 481 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 482 | mutex_unlock(&dsp->pwr_lock); |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 483 | return ret; |
| 484 | } |
| 485 | |
| 486 | static ssize_t wm_adsp_debugfs_bin_read(struct file *file, |
| 487 | char __user *user_buf, |
| 488 | size_t count, loff_t *ppos) |
| 489 | { |
| 490 | struct wm_adsp *dsp = file->private_data; |
| 491 | ssize_t ret; |
| 492 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 493 | mutex_lock(&dsp->pwr_lock); |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 494 | |
| 495 | if (!dsp->bin_file_name || !dsp->running) |
| 496 | ret = 0; |
| 497 | else |
| 498 | ret = simple_read_from_buffer(user_buf, count, ppos, |
| 499 | dsp->bin_file_name, |
| 500 | strlen(dsp->bin_file_name)); |
| 501 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 502 | mutex_unlock(&dsp->pwr_lock); |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 503 | return ret; |
| 504 | } |
| 505 | |
| 506 | static const struct { |
| 507 | const char *name; |
| 508 | const struct file_operations fops; |
| 509 | } wm_adsp_debugfs_fops[] = { |
| 510 | { |
| 511 | .name = "wmfw_file_name", |
| 512 | .fops = { |
| 513 | .open = simple_open, |
| 514 | .read = wm_adsp_debugfs_wmfw_read, |
| 515 | }, |
| 516 | }, |
| 517 | { |
| 518 | .name = "bin_file_name", |
| 519 | .fops = { |
| 520 | .open = simple_open, |
| 521 | .read = wm_adsp_debugfs_bin_read, |
| 522 | }, |
| 523 | }, |
| 524 | }; |
| 525 | |
| 526 | static void wm_adsp2_init_debugfs(struct wm_adsp *dsp, |
| 527 | struct snd_soc_codec *codec) |
| 528 | { |
| 529 | struct dentry *root = NULL; |
| 530 | char *root_name; |
| 531 | int i; |
| 532 | |
| 533 | if (!codec->component.debugfs_root) { |
| 534 | adsp_err(dsp, "No codec debugfs root\n"); |
| 535 | goto err; |
| 536 | } |
| 537 | |
| 538 | root_name = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 539 | if (!root_name) |
| 540 | goto err; |
| 541 | |
| 542 | snprintf(root_name, PAGE_SIZE, "dsp%d", dsp->num); |
| 543 | root = debugfs_create_dir(root_name, codec->component.debugfs_root); |
| 544 | kfree(root_name); |
| 545 | |
| 546 | if (!root) |
| 547 | goto err; |
| 548 | |
| 549 | if (!debugfs_create_bool("running", S_IRUGO, root, &dsp->running)) |
| 550 | goto err; |
| 551 | |
| 552 | if (!debugfs_create_x32("fw_id", S_IRUGO, root, &dsp->fw_id)) |
| 553 | goto err; |
| 554 | |
| 555 | if (!debugfs_create_x32("fw_version", S_IRUGO, root, |
| 556 | &dsp->fw_id_version)) |
| 557 | goto err; |
| 558 | |
| 559 | for (i = 0; i < ARRAY_SIZE(wm_adsp_debugfs_fops); ++i) { |
| 560 | if (!debugfs_create_file(wm_adsp_debugfs_fops[i].name, |
| 561 | S_IRUGO, root, dsp, |
| 562 | &wm_adsp_debugfs_fops[i].fops)) |
| 563 | goto err; |
| 564 | } |
| 565 | |
| 566 | dsp->debugfs_root = root; |
| 567 | return; |
| 568 | |
| 569 | err: |
| 570 | debugfs_remove_recursive(root); |
| 571 | adsp_err(dsp, "Failed to create debugfs\n"); |
| 572 | } |
| 573 | |
| 574 | static void wm_adsp2_cleanup_debugfs(struct wm_adsp *dsp) |
| 575 | { |
| 576 | wm_adsp_debugfs_clear(dsp); |
| 577 | debugfs_remove_recursive(dsp->debugfs_root); |
| 578 | } |
| 579 | #else |
| 580 | static inline void wm_adsp2_init_debugfs(struct wm_adsp *dsp, |
| 581 | struct snd_soc_codec *codec) |
| 582 | { |
| 583 | } |
| 584 | |
| 585 | static inline void wm_adsp2_cleanup_debugfs(struct wm_adsp *dsp) |
| 586 | { |
| 587 | } |
| 588 | |
| 589 | static inline void wm_adsp_debugfs_save_wmfwname(struct wm_adsp *dsp, |
| 590 | const char *s) |
| 591 | { |
| 592 | } |
| 593 | |
| 594 | static inline void wm_adsp_debugfs_save_binname(struct wm_adsp *dsp, |
| 595 | const char *s) |
| 596 | { |
| 597 | } |
| 598 | |
| 599 | static inline void wm_adsp_debugfs_clear(struct wm_adsp *dsp) |
| 600 | { |
| 601 | } |
| 602 | #endif |
| 603 | |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 604 | static int wm_adsp_fw_get(struct snd_kcontrol *kcontrol, |
| 605 | struct snd_ctl_elem_value *ucontrol) |
| 606 | { |
Lars-Peter Clausen | ea53bf7 | 2014-03-18 09:02:04 +0100 | [diff] [blame] | 607 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 608 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 609 | struct wm_adsp *dsp = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 610 | |
Takashi Iwai | 15c6657 | 2016-02-29 18:01:18 +0100 | [diff] [blame] | 611 | ucontrol->value.enumerated.item[0] = dsp[e->shift_l].fw; |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 612 | |
| 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | static int wm_adsp_fw_put(struct snd_kcontrol *kcontrol, |
| 617 | struct snd_ctl_elem_value *ucontrol) |
| 618 | { |
Lars-Peter Clausen | ea53bf7 | 2014-03-18 09:02:04 +0100 | [diff] [blame] | 619 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 620 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 621 | struct wm_adsp *dsp = snd_soc_codec_get_drvdata(codec); |
Charles Keepax | d27c5e1 | 2015-12-08 16:08:28 +0000 | [diff] [blame] | 622 | int ret = 0; |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 623 | |
Takashi Iwai | 15c6657 | 2016-02-29 18:01:18 +0100 | [diff] [blame] | 624 | if (ucontrol->value.enumerated.item[0] == dsp[e->shift_l].fw) |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 625 | return 0; |
| 626 | |
Takashi Iwai | 15c6657 | 2016-02-29 18:01:18 +0100 | [diff] [blame] | 627 | if (ucontrol->value.enumerated.item[0] >= WM_ADSP_NUM_FW) |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 628 | return -EINVAL; |
| 629 | |
Charles Keepax | d27c5e1 | 2015-12-08 16:08:28 +0000 | [diff] [blame] | 630 | mutex_lock(&dsp[e->shift_l].pwr_lock); |
| 631 | |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 632 | if (dsp[e->shift_l].running || dsp[e->shift_l].compr) |
Charles Keepax | d27c5e1 | 2015-12-08 16:08:28 +0000 | [diff] [blame] | 633 | ret = -EBUSY; |
| 634 | else |
Takashi Iwai | 15c6657 | 2016-02-29 18:01:18 +0100 | [diff] [blame] | 635 | dsp[e->shift_l].fw = ucontrol->value.enumerated.item[0]; |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 636 | |
Charles Keepax | d27c5e1 | 2015-12-08 16:08:28 +0000 | [diff] [blame] | 637 | mutex_unlock(&dsp[e->shift_l].pwr_lock); |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 638 | |
Charles Keepax | d27c5e1 | 2015-12-08 16:08:28 +0000 | [diff] [blame] | 639 | return ret; |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | static const struct soc_enum wm_adsp_fw_enum[] = { |
| 643 | SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(wm_adsp_fw_text), wm_adsp_fw_text), |
| 644 | SOC_ENUM_SINGLE(0, 1, ARRAY_SIZE(wm_adsp_fw_text), wm_adsp_fw_text), |
| 645 | SOC_ENUM_SINGLE(0, 2, ARRAY_SIZE(wm_adsp_fw_text), wm_adsp_fw_text), |
| 646 | SOC_ENUM_SINGLE(0, 3, ARRAY_SIZE(wm_adsp_fw_text), wm_adsp_fw_text), |
| 647 | }; |
| 648 | |
Richard Fitzgerald | 336d044 | 2015-06-18 13:43:19 +0100 | [diff] [blame] | 649 | const struct snd_kcontrol_new wm_adsp_fw_controls[] = { |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 650 | SOC_ENUM_EXT("DSP1 Firmware", wm_adsp_fw_enum[0], |
| 651 | wm_adsp_fw_get, wm_adsp_fw_put), |
| 652 | SOC_ENUM_EXT("DSP2 Firmware", wm_adsp_fw_enum[1], |
| 653 | wm_adsp_fw_get, wm_adsp_fw_put), |
| 654 | SOC_ENUM_EXT("DSP3 Firmware", wm_adsp_fw_enum[2], |
| 655 | wm_adsp_fw_get, wm_adsp_fw_put), |
Richard Fitzgerald | 336d044 | 2015-06-18 13:43:19 +0100 | [diff] [blame] | 656 | SOC_ENUM_EXT("DSP4 Firmware", wm_adsp_fw_enum[3], |
| 657 | wm_adsp_fw_get, wm_adsp_fw_put), |
Mark Brown | b6ed61cf | 2013-03-29 18:00:24 +0000 | [diff] [blame] | 658 | }; |
Richard Fitzgerald | 336d044 | 2015-06-18 13:43:19 +0100 | [diff] [blame] | 659 | EXPORT_SYMBOL_GPL(wm_adsp_fw_controls); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 660 | |
| 661 | static struct wm_adsp_region const *wm_adsp_find_region(struct wm_adsp *dsp, |
| 662 | int type) |
| 663 | { |
| 664 | int i; |
| 665 | |
| 666 | for (i = 0; i < dsp->num_mems; i++) |
| 667 | if (dsp->mem[i].type == type) |
| 668 | return &dsp->mem[i]; |
| 669 | |
| 670 | return NULL; |
| 671 | } |
| 672 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 673 | static unsigned int wm_adsp_region_to_reg(struct wm_adsp_region const *mem, |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 674 | unsigned int offset) |
| 675 | { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 676 | if (WARN_ON(!mem)) |
Takashi Iwai | 6c452bd | 2013-11-05 18:40:00 +0100 | [diff] [blame] | 677 | return offset; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 678 | switch (mem->type) { |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 679 | case WMFW_ADSP1_PM: |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 680 | return mem->base + (offset * 3); |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 681 | case WMFW_ADSP1_DM: |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 682 | return mem->base + (offset * 2); |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 683 | case WMFW_ADSP2_XM: |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 684 | return mem->base + (offset * 2); |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 685 | case WMFW_ADSP2_YM: |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 686 | return mem->base + (offset * 2); |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 687 | case WMFW_ADSP1_ZM: |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 688 | return mem->base + (offset * 2); |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 689 | default: |
Takashi Iwai | 6c452bd | 2013-11-05 18:40:00 +0100 | [diff] [blame] | 690 | WARN(1, "Unknown memory region type"); |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 691 | return offset; |
| 692 | } |
| 693 | } |
| 694 | |
Richard Fitzgerald | 10337b0 | 2015-05-29 10:23:07 +0100 | [diff] [blame] | 695 | static void wm_adsp2_show_fw_status(struct wm_adsp *dsp) |
| 696 | { |
| 697 | u16 scratch[4]; |
| 698 | int ret; |
| 699 | |
| 700 | ret = regmap_raw_read(dsp->regmap, dsp->base + ADSP2_SCRATCH0, |
| 701 | scratch, sizeof(scratch)); |
| 702 | if (ret) { |
| 703 | adsp_err(dsp, "Failed to read SCRATCH regs: %d\n", ret); |
| 704 | return; |
| 705 | } |
| 706 | |
| 707 | adsp_dbg(dsp, "FW SCRATCH 0:0x%x 1:0x%x 2:0x%x 3:0x%x\n", |
| 708 | be16_to_cpu(scratch[0]), |
| 709 | be16_to_cpu(scratch[1]), |
| 710 | be16_to_cpu(scratch[2]), |
| 711 | be16_to_cpu(scratch[3])); |
| 712 | } |
| 713 | |
Charles Keepax | 7585a5b | 2015-12-08 16:08:25 +0000 | [diff] [blame] | 714 | static int wm_coeff_info(struct snd_kcontrol *kctl, |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 715 | struct snd_ctl_elem_info *uinfo) |
| 716 | { |
Charles Keepax | 7585a5b | 2015-12-08 16:08:25 +0000 | [diff] [blame] | 717 | struct wm_coeff_ctl *ctl = (struct wm_coeff_ctl *)kctl->private_value; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 718 | |
| 719 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; |
| 720 | uinfo->count = ctl->len; |
| 721 | return 0; |
| 722 | } |
| 723 | |
Charles Keepax | c9f8dd7 | 2015-04-13 13:27:58 +0100 | [diff] [blame] | 724 | static int wm_coeff_write_control(struct wm_coeff_ctl *ctl, |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 725 | const void *buf, size_t len) |
| 726 | { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 727 | struct wm_adsp_alg_region *alg_region = &ctl->alg_region; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 728 | const struct wm_adsp_region *mem; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 729 | struct wm_adsp *dsp = ctl->dsp; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 730 | void *scratch; |
| 731 | int ret; |
| 732 | unsigned int reg; |
| 733 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 734 | mem = wm_adsp_find_region(dsp, alg_region->type); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 735 | if (!mem) { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 736 | adsp_err(dsp, "No base for region %x\n", |
| 737 | alg_region->type); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 738 | return -EINVAL; |
| 739 | } |
| 740 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 741 | reg = ctl->alg_region.base + ctl->offset; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 742 | reg = wm_adsp_region_to_reg(mem, reg); |
| 743 | |
Charles Keepax | 4f8ea6d | 2016-02-19 14:44:44 +0000 | [diff] [blame] | 744 | scratch = kmemdup(buf, len, GFP_KERNEL | GFP_DMA); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 745 | if (!scratch) |
| 746 | return -ENOMEM; |
| 747 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 748 | ret = regmap_raw_write(dsp->regmap, reg, scratch, |
Charles Keepax | 4f8ea6d | 2016-02-19 14:44:44 +0000 | [diff] [blame] | 749 | len); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 750 | if (ret) { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 751 | adsp_err(dsp, "Failed to write %zu bytes to %x: %d\n", |
Charles Keepax | 4f8ea6d | 2016-02-19 14:44:44 +0000 | [diff] [blame] | 752 | len, reg, ret); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 753 | kfree(scratch); |
| 754 | return ret; |
| 755 | } |
Charles Keepax | 4f8ea6d | 2016-02-19 14:44:44 +0000 | [diff] [blame] | 756 | adsp_dbg(dsp, "Wrote %zu bytes to %x\n", len, reg); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 757 | |
| 758 | kfree(scratch); |
| 759 | |
| 760 | return 0; |
| 761 | } |
| 762 | |
Charles Keepax | 7585a5b | 2015-12-08 16:08:25 +0000 | [diff] [blame] | 763 | static int wm_coeff_put(struct snd_kcontrol *kctl, |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 764 | struct snd_ctl_elem_value *ucontrol) |
| 765 | { |
Charles Keepax | 7585a5b | 2015-12-08 16:08:25 +0000 | [diff] [blame] | 766 | struct wm_coeff_ctl *ctl = (struct wm_coeff_ctl *)kctl->private_value; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 767 | char *p = ucontrol->value.bytes.data; |
Charles Keepax | 168d10e | 2015-12-08 16:08:27 +0000 | [diff] [blame] | 768 | int ret = 0; |
| 769 | |
| 770 | mutex_lock(&ctl->dsp->pwr_lock); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 771 | |
| 772 | memcpy(ctl->cache, p, ctl->len); |
| 773 | |
Nikesh Oswal | 65d17a9 | 2015-02-16 15:25:48 +0000 | [diff] [blame] | 774 | ctl->set = 1; |
Charles Keepax | 168d10e | 2015-12-08 16:08:27 +0000 | [diff] [blame] | 775 | if (ctl->enabled) |
| 776 | ret = wm_coeff_write_control(ctl, p, ctl->len); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 777 | |
Charles Keepax | 168d10e | 2015-12-08 16:08:27 +0000 | [diff] [blame] | 778 | mutex_unlock(&ctl->dsp->pwr_lock); |
| 779 | |
| 780 | return ret; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 781 | } |
| 782 | |
Charles Keepax | c9f8dd7 | 2015-04-13 13:27:58 +0100 | [diff] [blame] | 783 | static int wm_coeff_read_control(struct wm_coeff_ctl *ctl, |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 784 | void *buf, size_t len) |
| 785 | { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 786 | struct wm_adsp_alg_region *alg_region = &ctl->alg_region; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 787 | const struct wm_adsp_region *mem; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 788 | struct wm_adsp *dsp = ctl->dsp; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 789 | void *scratch; |
| 790 | int ret; |
| 791 | unsigned int reg; |
| 792 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 793 | mem = wm_adsp_find_region(dsp, alg_region->type); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 794 | if (!mem) { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 795 | adsp_err(dsp, "No base for region %x\n", |
| 796 | alg_region->type); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 797 | return -EINVAL; |
| 798 | } |
| 799 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 800 | reg = ctl->alg_region.base + ctl->offset; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 801 | reg = wm_adsp_region_to_reg(mem, reg); |
| 802 | |
Charles Keepax | 4f8ea6d | 2016-02-19 14:44:44 +0000 | [diff] [blame] | 803 | scratch = kmalloc(len, GFP_KERNEL | GFP_DMA); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 804 | if (!scratch) |
| 805 | return -ENOMEM; |
| 806 | |
Charles Keepax | 4f8ea6d | 2016-02-19 14:44:44 +0000 | [diff] [blame] | 807 | ret = regmap_raw_read(dsp->regmap, reg, scratch, len); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 808 | if (ret) { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 809 | adsp_err(dsp, "Failed to read %zu bytes from %x: %d\n", |
Charles Keepax | 5602a64 | 2016-03-10 10:46:07 +0000 | [diff] [blame] | 810 | len, reg, ret); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 811 | kfree(scratch); |
| 812 | return ret; |
| 813 | } |
Charles Keepax | 4f8ea6d | 2016-02-19 14:44:44 +0000 | [diff] [blame] | 814 | adsp_dbg(dsp, "Read %zu bytes from %x\n", len, reg); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 815 | |
Charles Keepax | 4f8ea6d | 2016-02-19 14:44:44 +0000 | [diff] [blame] | 816 | memcpy(buf, scratch, len); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 817 | kfree(scratch); |
| 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
Charles Keepax | 7585a5b | 2015-12-08 16:08:25 +0000 | [diff] [blame] | 822 | static int wm_coeff_get(struct snd_kcontrol *kctl, |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 823 | struct snd_ctl_elem_value *ucontrol) |
| 824 | { |
Charles Keepax | 7585a5b | 2015-12-08 16:08:25 +0000 | [diff] [blame] | 825 | struct wm_coeff_ctl *ctl = (struct wm_coeff_ctl *)kctl->private_value; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 826 | char *p = ucontrol->value.bytes.data; |
Charles Keepax | 168d10e | 2015-12-08 16:08:27 +0000 | [diff] [blame] | 827 | int ret = 0; |
| 828 | |
| 829 | mutex_lock(&ctl->dsp->pwr_lock); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 830 | |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 831 | if (ctl->flags & WMFW_CTL_FLAG_VOLATILE) { |
| 832 | if (ctl->enabled) |
Charles Keepax | 168d10e | 2015-12-08 16:08:27 +0000 | [diff] [blame] | 833 | ret = wm_coeff_read_control(ctl, p, ctl->len); |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 834 | else |
Charles Keepax | 168d10e | 2015-12-08 16:08:27 +0000 | [diff] [blame] | 835 | ret = -EPERM; |
| 836 | } else { |
Charles Keepax | bc1765d | 2015-12-17 10:05:59 +0000 | [diff] [blame] | 837 | if (!ctl->flags && ctl->enabled) |
| 838 | ret = wm_coeff_read_control(ctl, ctl->cache, ctl->len); |
| 839 | |
Charles Keepax | 168d10e | 2015-12-08 16:08:27 +0000 | [diff] [blame] | 840 | memcpy(p, ctl->cache, ctl->len); |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 841 | } |
| 842 | |
Charles Keepax | 168d10e | 2015-12-08 16:08:27 +0000 | [diff] [blame] | 843 | mutex_unlock(&ctl->dsp->pwr_lock); |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 844 | |
Charles Keepax | 168d10e | 2015-12-08 16:08:27 +0000 | [diff] [blame] | 845 | return ret; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 846 | } |
| 847 | |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 848 | struct wmfw_ctl_work { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 849 | struct wm_adsp *dsp; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 850 | struct wm_coeff_ctl *ctl; |
| 851 | struct work_struct work; |
| 852 | }; |
| 853 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 854 | static int wmfw_add_ctl(struct wm_adsp *dsp, struct wm_coeff_ctl *ctl) |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 855 | { |
| 856 | struct snd_kcontrol_new *kcontrol; |
| 857 | int ret; |
| 858 | |
Dimitris Papastamos | 92bb4c3 | 2013-08-01 11:11:28 +0100 | [diff] [blame] | 859 | if (!ctl || !ctl->name) |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 860 | return -EINVAL; |
| 861 | |
| 862 | kcontrol = kzalloc(sizeof(*kcontrol), GFP_KERNEL); |
| 863 | if (!kcontrol) |
| 864 | return -ENOMEM; |
| 865 | kcontrol->iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 866 | |
| 867 | kcontrol->name = ctl->name; |
| 868 | kcontrol->info = wm_coeff_info; |
| 869 | kcontrol->get = wm_coeff_get; |
| 870 | kcontrol->put = wm_coeff_put; |
| 871 | kcontrol->private_value = (unsigned long)ctl; |
| 872 | |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 873 | if (ctl->flags) { |
| 874 | if (ctl->flags & WMFW_CTL_FLAG_WRITEABLE) |
| 875 | kcontrol->access |= SNDRV_CTL_ELEM_ACCESS_WRITE; |
| 876 | if (ctl->flags & WMFW_CTL_FLAG_READABLE) |
| 877 | kcontrol->access |= SNDRV_CTL_ELEM_ACCESS_READ; |
| 878 | if (ctl->flags & WMFW_CTL_FLAG_VOLATILE) |
| 879 | kcontrol->access |= SNDRV_CTL_ELEM_ACCESS_VOLATILE; |
Charles Keepax | cc815c4 | 2016-02-19 14:44:42 +0000 | [diff] [blame] | 880 | } else { |
| 881 | kcontrol->access = SNDRV_CTL_ELEM_ACCESS_READWRITE; |
| 882 | kcontrol->access |= SNDRV_CTL_ELEM_ACCESS_VOLATILE; |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 883 | } |
| 884 | |
Charles Keepax | 7d00cd9 | 2016-02-19 14:44:43 +0000 | [diff] [blame] | 885 | ret = snd_soc_add_card_controls(dsp->card, kcontrol, 1); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 886 | if (ret < 0) |
| 887 | goto err_kcontrol; |
| 888 | |
| 889 | kfree(kcontrol); |
| 890 | |
Charles Keepax | 7d00cd9 | 2016-02-19 14:44:43 +0000 | [diff] [blame] | 891 | ctl->kcontrol = snd_soc_card_get_kcontrol(dsp->card, ctl->name); |
Dimitris Papastamos | 81ad93e | 2013-07-29 13:51:59 +0100 | [diff] [blame] | 892 | |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 893 | return 0; |
| 894 | |
| 895 | err_kcontrol: |
| 896 | kfree(kcontrol); |
| 897 | return ret; |
| 898 | } |
| 899 | |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 900 | static int wm_coeff_init_control_caches(struct wm_adsp *dsp) |
| 901 | { |
| 902 | struct wm_coeff_ctl *ctl; |
| 903 | int ret; |
| 904 | |
| 905 | list_for_each_entry(ctl, &dsp->ctl_list, list) { |
| 906 | if (!ctl->enabled || ctl->set) |
| 907 | continue; |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 908 | if (ctl->flags & WMFW_CTL_FLAG_VOLATILE) |
| 909 | continue; |
| 910 | |
Charles Keepax | 7d00cd9 | 2016-02-19 14:44:43 +0000 | [diff] [blame] | 911 | ret = wm_coeff_read_control(ctl, ctl->cache, ctl->len); |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 912 | if (ret < 0) |
| 913 | return ret; |
| 914 | } |
| 915 | |
| 916 | return 0; |
| 917 | } |
| 918 | |
| 919 | static int wm_coeff_sync_controls(struct wm_adsp *dsp) |
| 920 | { |
| 921 | struct wm_coeff_ctl *ctl; |
| 922 | int ret; |
| 923 | |
| 924 | list_for_each_entry(ctl, &dsp->ctl_list, list) { |
| 925 | if (!ctl->enabled) |
| 926 | continue; |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 927 | if (ctl->set && !(ctl->flags & WMFW_CTL_FLAG_VOLATILE)) { |
Charles Keepax | 7d00cd9 | 2016-02-19 14:44:43 +0000 | [diff] [blame] | 928 | ret = wm_coeff_write_control(ctl, ctl->cache, ctl->len); |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 929 | if (ret < 0) |
| 930 | return ret; |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | return 0; |
| 935 | } |
| 936 | |
| 937 | static void wm_adsp_ctl_work(struct work_struct *work) |
| 938 | { |
| 939 | struct wmfw_ctl_work *ctl_work = container_of(work, |
| 940 | struct wmfw_ctl_work, |
| 941 | work); |
| 942 | |
| 943 | wmfw_add_ctl(ctl_work->dsp, ctl_work->ctl); |
| 944 | kfree(ctl_work); |
| 945 | } |
| 946 | |
| 947 | static int wm_adsp_create_control(struct wm_adsp *dsp, |
| 948 | const struct wm_adsp_alg_region *alg_region, |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 949 | unsigned int offset, unsigned int len, |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 950 | const char *subname, unsigned int subname_len, |
| 951 | unsigned int flags) |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 952 | { |
| 953 | struct wm_coeff_ctl *ctl; |
| 954 | struct wmfw_ctl_work *ctl_work; |
| 955 | char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; |
| 956 | char *region_name; |
| 957 | int ret; |
| 958 | |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 959 | if (flags & WMFW_CTL_FLAG_SYS) |
| 960 | return 0; |
| 961 | |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 962 | switch (alg_region->type) { |
| 963 | case WMFW_ADSP1_PM: |
| 964 | region_name = "PM"; |
| 965 | break; |
| 966 | case WMFW_ADSP1_DM: |
| 967 | region_name = "DM"; |
| 968 | break; |
| 969 | case WMFW_ADSP2_XM: |
| 970 | region_name = "XM"; |
| 971 | break; |
| 972 | case WMFW_ADSP2_YM: |
| 973 | region_name = "YM"; |
| 974 | break; |
| 975 | case WMFW_ADSP1_ZM: |
| 976 | region_name = "ZM"; |
| 977 | break; |
| 978 | default: |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 979 | adsp_err(dsp, "Unknown region type: %d\n", alg_region->type); |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 980 | return -EINVAL; |
| 981 | } |
| 982 | |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 983 | switch (dsp->fw_ver) { |
| 984 | case 0: |
| 985 | case 1: |
| 986 | snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "DSP%d %s %x", |
| 987 | dsp->num, region_name, alg_region->alg); |
| 988 | break; |
| 989 | default: |
| 990 | ret = snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, |
| 991 | "DSP%d%c %.12s %x", dsp->num, *region_name, |
| 992 | wm_adsp_fw_text[dsp->fw], alg_region->alg); |
| 993 | |
| 994 | /* Truncate the subname from the start if it is too long */ |
| 995 | if (subname) { |
| 996 | int avail = SNDRV_CTL_ELEM_ID_NAME_MAXLEN - ret - 2; |
| 997 | int skip = 0; |
| 998 | |
| 999 | if (subname_len > avail) |
| 1000 | skip = subname_len - avail; |
| 1001 | |
| 1002 | snprintf(name + ret, |
| 1003 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN - ret, " %.*s", |
| 1004 | subname_len - skip, subname + skip); |
| 1005 | } |
| 1006 | break; |
| 1007 | } |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 1008 | |
Charles Keepax | 7585a5b | 2015-12-08 16:08:25 +0000 | [diff] [blame] | 1009 | list_for_each_entry(ctl, &dsp->ctl_list, list) { |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 1010 | if (!strcmp(ctl->name, name)) { |
| 1011 | if (!ctl->enabled) |
| 1012 | ctl->enabled = 1; |
| 1013 | return 0; |
| 1014 | } |
| 1015 | } |
| 1016 | |
| 1017 | ctl = kzalloc(sizeof(*ctl), GFP_KERNEL); |
| 1018 | if (!ctl) |
| 1019 | return -ENOMEM; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1020 | ctl->fw_name = wm_adsp_fw_text[dsp->fw]; |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 1021 | ctl->alg_region = *alg_region; |
| 1022 | ctl->name = kmemdup(name, strlen(name) + 1, GFP_KERNEL); |
| 1023 | if (!ctl->name) { |
| 1024 | ret = -ENOMEM; |
| 1025 | goto err_ctl; |
| 1026 | } |
| 1027 | ctl->enabled = 1; |
| 1028 | ctl->set = 0; |
| 1029 | ctl->ops.xget = wm_coeff_get; |
| 1030 | ctl->ops.xput = wm_coeff_put; |
| 1031 | ctl->dsp = dsp; |
| 1032 | |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 1033 | ctl->flags = flags; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1034 | ctl->offset = offset; |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 1035 | if (len > 512) { |
| 1036 | adsp_warn(dsp, "Truncating control %s from %d\n", |
| 1037 | ctl->name, len); |
| 1038 | len = 512; |
| 1039 | } |
| 1040 | ctl->len = len; |
| 1041 | ctl->cache = kzalloc(ctl->len, GFP_KERNEL); |
| 1042 | if (!ctl->cache) { |
| 1043 | ret = -ENOMEM; |
| 1044 | goto err_ctl_name; |
| 1045 | } |
| 1046 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1047 | list_add(&ctl->list, &dsp->ctl_list); |
| 1048 | |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 1049 | ctl_work = kzalloc(sizeof(*ctl_work), GFP_KERNEL); |
| 1050 | if (!ctl_work) { |
| 1051 | ret = -ENOMEM; |
| 1052 | goto err_ctl_cache; |
| 1053 | } |
| 1054 | |
| 1055 | ctl_work->dsp = dsp; |
| 1056 | ctl_work->ctl = ctl; |
| 1057 | INIT_WORK(&ctl_work->work, wm_adsp_ctl_work); |
| 1058 | schedule_work(&ctl_work->work); |
| 1059 | |
| 1060 | return 0; |
| 1061 | |
| 1062 | err_ctl_cache: |
| 1063 | kfree(ctl->cache); |
| 1064 | err_ctl_name: |
| 1065 | kfree(ctl->name); |
| 1066 | err_ctl: |
| 1067 | kfree(ctl); |
| 1068 | |
| 1069 | return ret; |
| 1070 | } |
| 1071 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1072 | struct wm_coeff_parsed_alg { |
| 1073 | int id; |
| 1074 | const u8 *name; |
| 1075 | int name_len; |
| 1076 | int ncoeff; |
| 1077 | }; |
| 1078 | |
| 1079 | struct wm_coeff_parsed_coeff { |
| 1080 | int offset; |
| 1081 | int mem_type; |
| 1082 | const u8 *name; |
| 1083 | int name_len; |
| 1084 | int ctl_type; |
| 1085 | int flags; |
| 1086 | int len; |
| 1087 | }; |
| 1088 | |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 1089 | static int wm_coeff_parse_string(int bytes, const u8 **pos, const u8 **str) |
| 1090 | { |
| 1091 | int length; |
| 1092 | |
| 1093 | switch (bytes) { |
| 1094 | case 1: |
| 1095 | length = **pos; |
| 1096 | break; |
| 1097 | case 2: |
Charles Keepax | 8299ee8 | 2015-04-20 13:52:44 +0100 | [diff] [blame] | 1098 | length = le16_to_cpu(*((__le16 *)*pos)); |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 1099 | break; |
| 1100 | default: |
| 1101 | return 0; |
| 1102 | } |
| 1103 | |
| 1104 | if (str) |
| 1105 | *str = *pos + bytes; |
| 1106 | |
| 1107 | *pos += ((length + bytes) + 3) & ~0x03; |
| 1108 | |
| 1109 | return length; |
| 1110 | } |
| 1111 | |
| 1112 | static int wm_coeff_parse_int(int bytes, const u8 **pos) |
| 1113 | { |
| 1114 | int val = 0; |
| 1115 | |
| 1116 | switch (bytes) { |
| 1117 | case 2: |
Charles Keepax | 8299ee8 | 2015-04-20 13:52:44 +0100 | [diff] [blame] | 1118 | val = le16_to_cpu(*((__le16 *)*pos)); |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 1119 | break; |
| 1120 | case 4: |
Charles Keepax | 8299ee8 | 2015-04-20 13:52:44 +0100 | [diff] [blame] | 1121 | val = le32_to_cpu(*((__le32 *)*pos)); |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 1122 | break; |
| 1123 | default: |
| 1124 | break; |
| 1125 | } |
| 1126 | |
| 1127 | *pos += bytes; |
| 1128 | |
| 1129 | return val; |
| 1130 | } |
| 1131 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1132 | static inline void wm_coeff_parse_alg(struct wm_adsp *dsp, const u8 **data, |
| 1133 | struct wm_coeff_parsed_alg *blk) |
| 1134 | { |
| 1135 | const struct wmfw_adsp_alg_data *raw; |
| 1136 | |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 1137 | switch (dsp->fw_ver) { |
| 1138 | case 0: |
| 1139 | case 1: |
| 1140 | raw = (const struct wmfw_adsp_alg_data *)*data; |
| 1141 | *data = raw->data; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1142 | |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 1143 | blk->id = le32_to_cpu(raw->id); |
| 1144 | blk->name = raw->name; |
| 1145 | blk->name_len = strlen(raw->name); |
| 1146 | blk->ncoeff = le32_to_cpu(raw->ncoeff); |
| 1147 | break; |
| 1148 | default: |
| 1149 | blk->id = wm_coeff_parse_int(sizeof(raw->id), data); |
| 1150 | blk->name_len = wm_coeff_parse_string(sizeof(u8), data, |
| 1151 | &blk->name); |
| 1152 | wm_coeff_parse_string(sizeof(u16), data, NULL); |
| 1153 | blk->ncoeff = wm_coeff_parse_int(sizeof(raw->ncoeff), data); |
| 1154 | break; |
| 1155 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1156 | |
| 1157 | adsp_dbg(dsp, "Algorithm ID: %#x\n", blk->id); |
| 1158 | adsp_dbg(dsp, "Algorithm name: %.*s\n", blk->name_len, blk->name); |
| 1159 | adsp_dbg(dsp, "# of coefficient descriptors: %#x\n", blk->ncoeff); |
| 1160 | } |
| 1161 | |
| 1162 | static inline void wm_coeff_parse_coeff(struct wm_adsp *dsp, const u8 **data, |
| 1163 | struct wm_coeff_parsed_coeff *blk) |
| 1164 | { |
| 1165 | const struct wmfw_adsp_coeff_data *raw; |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 1166 | const u8 *tmp; |
| 1167 | int length; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1168 | |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 1169 | switch (dsp->fw_ver) { |
| 1170 | case 0: |
| 1171 | case 1: |
| 1172 | raw = (const struct wmfw_adsp_coeff_data *)*data; |
| 1173 | *data = *data + sizeof(raw->hdr) + le32_to_cpu(raw->hdr.size); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1174 | |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 1175 | blk->offset = le16_to_cpu(raw->hdr.offset); |
| 1176 | blk->mem_type = le16_to_cpu(raw->hdr.type); |
| 1177 | blk->name = raw->name; |
| 1178 | blk->name_len = strlen(raw->name); |
| 1179 | blk->ctl_type = le16_to_cpu(raw->ctl_type); |
| 1180 | blk->flags = le16_to_cpu(raw->flags); |
| 1181 | blk->len = le32_to_cpu(raw->len); |
| 1182 | break; |
| 1183 | default: |
| 1184 | tmp = *data; |
| 1185 | blk->offset = wm_coeff_parse_int(sizeof(raw->hdr.offset), &tmp); |
| 1186 | blk->mem_type = wm_coeff_parse_int(sizeof(raw->hdr.type), &tmp); |
| 1187 | length = wm_coeff_parse_int(sizeof(raw->hdr.size), &tmp); |
| 1188 | blk->name_len = wm_coeff_parse_string(sizeof(u8), &tmp, |
| 1189 | &blk->name); |
| 1190 | wm_coeff_parse_string(sizeof(u8), &tmp, NULL); |
| 1191 | wm_coeff_parse_string(sizeof(u16), &tmp, NULL); |
| 1192 | blk->ctl_type = wm_coeff_parse_int(sizeof(raw->ctl_type), &tmp); |
| 1193 | blk->flags = wm_coeff_parse_int(sizeof(raw->flags), &tmp); |
| 1194 | blk->len = wm_coeff_parse_int(sizeof(raw->len), &tmp); |
| 1195 | |
| 1196 | *data = *data + sizeof(raw->hdr) + length; |
| 1197 | break; |
| 1198 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1199 | |
| 1200 | adsp_dbg(dsp, "\tCoefficient type: %#x\n", blk->mem_type); |
| 1201 | adsp_dbg(dsp, "\tCoefficient offset: %#x\n", blk->offset); |
| 1202 | adsp_dbg(dsp, "\tCoefficient name: %.*s\n", blk->name_len, blk->name); |
| 1203 | adsp_dbg(dsp, "\tCoefficient flags: %#x\n", blk->flags); |
| 1204 | adsp_dbg(dsp, "\tALSA control type: %#x\n", blk->ctl_type); |
| 1205 | adsp_dbg(dsp, "\tALSA control len: %#x\n", blk->len); |
| 1206 | } |
| 1207 | |
| 1208 | static int wm_adsp_parse_coeff(struct wm_adsp *dsp, |
| 1209 | const struct wmfw_region *region) |
| 1210 | { |
| 1211 | struct wm_adsp_alg_region alg_region = {}; |
| 1212 | struct wm_coeff_parsed_alg alg_blk; |
| 1213 | struct wm_coeff_parsed_coeff coeff_blk; |
| 1214 | const u8 *data = region->data; |
| 1215 | int i, ret; |
| 1216 | |
| 1217 | wm_coeff_parse_alg(dsp, &data, &alg_blk); |
| 1218 | for (i = 0; i < alg_blk.ncoeff; i++) { |
| 1219 | wm_coeff_parse_coeff(dsp, &data, &coeff_blk); |
| 1220 | |
| 1221 | switch (coeff_blk.ctl_type) { |
| 1222 | case SNDRV_CTL_ELEM_TYPE_BYTES: |
| 1223 | break; |
| 1224 | default: |
| 1225 | adsp_err(dsp, "Unknown control type: %d\n", |
| 1226 | coeff_blk.ctl_type); |
| 1227 | return -EINVAL; |
| 1228 | } |
| 1229 | |
| 1230 | alg_region.type = coeff_blk.mem_type; |
| 1231 | alg_region.alg = alg_blk.id; |
| 1232 | |
| 1233 | ret = wm_adsp_create_control(dsp, &alg_region, |
| 1234 | coeff_blk.offset, |
| 1235 | coeff_blk.len, |
| 1236 | coeff_blk.name, |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 1237 | coeff_blk.name_len, |
| 1238 | coeff_blk.flags); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1239 | if (ret < 0) |
| 1240 | adsp_err(dsp, "Failed to create control: %.*s, %d\n", |
| 1241 | coeff_blk.name_len, coeff_blk.name, ret); |
| 1242 | } |
| 1243 | |
| 1244 | return 0; |
| 1245 | } |
| 1246 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1247 | static int wm_adsp_load(struct wm_adsp *dsp) |
| 1248 | { |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1249 | LIST_HEAD(buf_list); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1250 | const struct firmware *firmware; |
| 1251 | struct regmap *regmap = dsp->regmap; |
| 1252 | unsigned int pos = 0; |
| 1253 | const struct wmfw_header *header; |
| 1254 | const struct wmfw_adsp1_sizes *adsp1_sizes; |
| 1255 | const struct wmfw_adsp2_sizes *adsp2_sizes; |
| 1256 | const struct wmfw_footer *footer; |
| 1257 | const struct wmfw_region *region; |
| 1258 | const struct wm_adsp_region *mem; |
| 1259 | const char *region_name; |
| 1260 | char *file, *text; |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1261 | struct wm_adsp_buf *buf; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1262 | unsigned int reg; |
| 1263 | int regions = 0; |
| 1264 | int ret, offset, type, sizes; |
| 1265 | |
| 1266 | file = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 1267 | if (file == NULL) |
| 1268 | return -ENOMEM; |
| 1269 | |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 1270 | snprintf(file, PAGE_SIZE, "%s-dsp%d-%s.wmfw", dsp->part, dsp->num, |
| 1271 | wm_adsp_fw[dsp->fw].file); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1272 | file[PAGE_SIZE - 1] = '\0'; |
| 1273 | |
| 1274 | ret = request_firmware(&firmware, file, dsp->dev); |
| 1275 | if (ret != 0) { |
| 1276 | adsp_err(dsp, "Failed to request '%s'\n", file); |
| 1277 | goto out; |
| 1278 | } |
| 1279 | ret = -EINVAL; |
| 1280 | |
| 1281 | pos = sizeof(*header) + sizeof(*adsp1_sizes) + sizeof(*footer); |
| 1282 | if (pos >= firmware->size) { |
| 1283 | adsp_err(dsp, "%s: file too short, %zu bytes\n", |
| 1284 | file, firmware->size); |
| 1285 | goto out_fw; |
| 1286 | } |
| 1287 | |
Charles Keepax | 7585a5b | 2015-12-08 16:08:25 +0000 | [diff] [blame] | 1288 | header = (void *)&firmware->data[0]; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1289 | |
| 1290 | if (memcmp(&header->magic[0], "WMFW", 4) != 0) { |
| 1291 | adsp_err(dsp, "%s: invalid magic\n", file); |
| 1292 | goto out_fw; |
| 1293 | } |
| 1294 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1295 | switch (header->ver) { |
| 1296 | case 0: |
Charles Keepax | c61e59f | 2015-04-13 13:28:05 +0100 | [diff] [blame] | 1297 | adsp_warn(dsp, "%s: Depreciated file format %d\n", |
| 1298 | file, header->ver); |
| 1299 | break; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1300 | case 1: |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 1301 | case 2: |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1302 | break; |
| 1303 | default: |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1304 | adsp_err(dsp, "%s: unknown file format %d\n", |
| 1305 | file, header->ver); |
| 1306 | goto out_fw; |
| 1307 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1308 | |
Dimitris Papastamos | 3626992 | 2013-11-01 15:56:57 +0000 | [diff] [blame] | 1309 | adsp_info(dsp, "Firmware version: %d\n", header->ver); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1310 | dsp->fw_ver = header->ver; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1311 | |
| 1312 | if (header->core != dsp->type) { |
| 1313 | adsp_err(dsp, "%s: invalid core %d != %d\n", |
| 1314 | file, header->core, dsp->type); |
| 1315 | goto out_fw; |
| 1316 | } |
| 1317 | |
| 1318 | switch (dsp->type) { |
| 1319 | case WMFW_ADSP1: |
| 1320 | pos = sizeof(*header) + sizeof(*adsp1_sizes) + sizeof(*footer); |
| 1321 | adsp1_sizes = (void *)&(header[1]); |
| 1322 | footer = (void *)&(adsp1_sizes[1]); |
| 1323 | sizes = sizeof(*adsp1_sizes); |
| 1324 | |
| 1325 | adsp_dbg(dsp, "%s: %d DM, %d PM, %d ZM\n", |
| 1326 | file, le32_to_cpu(adsp1_sizes->dm), |
| 1327 | le32_to_cpu(adsp1_sizes->pm), |
| 1328 | le32_to_cpu(adsp1_sizes->zm)); |
| 1329 | break; |
| 1330 | |
| 1331 | case WMFW_ADSP2: |
| 1332 | pos = sizeof(*header) + sizeof(*adsp2_sizes) + sizeof(*footer); |
| 1333 | adsp2_sizes = (void *)&(header[1]); |
| 1334 | footer = (void *)&(adsp2_sizes[1]); |
| 1335 | sizes = sizeof(*adsp2_sizes); |
| 1336 | |
| 1337 | adsp_dbg(dsp, "%s: %d XM, %d YM %d PM, %d ZM\n", |
| 1338 | file, le32_to_cpu(adsp2_sizes->xm), |
| 1339 | le32_to_cpu(adsp2_sizes->ym), |
| 1340 | le32_to_cpu(adsp2_sizes->pm), |
| 1341 | le32_to_cpu(adsp2_sizes->zm)); |
| 1342 | break; |
| 1343 | |
| 1344 | default: |
Takashi Iwai | 6c452bd | 2013-11-05 18:40:00 +0100 | [diff] [blame] | 1345 | WARN(1, "Unknown DSP type"); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1346 | goto out_fw; |
| 1347 | } |
| 1348 | |
| 1349 | if (le32_to_cpu(header->len) != sizeof(*header) + |
| 1350 | sizes + sizeof(*footer)) { |
| 1351 | adsp_err(dsp, "%s: unexpected header length %d\n", |
| 1352 | file, le32_to_cpu(header->len)); |
| 1353 | goto out_fw; |
| 1354 | } |
| 1355 | |
| 1356 | adsp_dbg(dsp, "%s: timestamp %llu\n", file, |
| 1357 | le64_to_cpu(footer->timestamp)); |
| 1358 | |
| 1359 | while (pos < firmware->size && |
| 1360 | pos - firmware->size > sizeof(*region)) { |
| 1361 | region = (void *)&(firmware->data[pos]); |
| 1362 | region_name = "Unknown"; |
| 1363 | reg = 0; |
| 1364 | text = NULL; |
| 1365 | offset = le32_to_cpu(region->offset) & 0xffffff; |
| 1366 | type = be32_to_cpu(region->type) & 0xff; |
| 1367 | mem = wm_adsp_find_region(dsp, type); |
Charles Keepax | 7585a5b | 2015-12-08 16:08:25 +0000 | [diff] [blame] | 1368 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1369 | switch (type) { |
| 1370 | case WMFW_NAME_TEXT: |
| 1371 | region_name = "Firmware name"; |
| 1372 | text = kzalloc(le32_to_cpu(region->len) + 1, |
| 1373 | GFP_KERNEL); |
| 1374 | break; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1375 | case WMFW_ALGORITHM_DATA: |
| 1376 | region_name = "Algorithm"; |
| 1377 | ret = wm_adsp_parse_coeff(dsp, region); |
| 1378 | if (ret != 0) |
| 1379 | goto out_fw; |
| 1380 | break; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1381 | case WMFW_INFO_TEXT: |
| 1382 | region_name = "Information"; |
| 1383 | text = kzalloc(le32_to_cpu(region->len) + 1, |
| 1384 | GFP_KERNEL); |
| 1385 | break; |
| 1386 | case WMFW_ABSOLUTE: |
| 1387 | region_name = "Absolute"; |
| 1388 | reg = offset; |
| 1389 | break; |
| 1390 | case WMFW_ADSP1_PM: |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1391 | region_name = "PM"; |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 1392 | reg = wm_adsp_region_to_reg(mem, offset); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1393 | break; |
| 1394 | case WMFW_ADSP1_DM: |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1395 | region_name = "DM"; |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 1396 | reg = wm_adsp_region_to_reg(mem, offset); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1397 | break; |
| 1398 | case WMFW_ADSP2_XM: |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1399 | region_name = "XM"; |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 1400 | reg = wm_adsp_region_to_reg(mem, offset); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1401 | break; |
| 1402 | case WMFW_ADSP2_YM: |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1403 | region_name = "YM"; |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 1404 | reg = wm_adsp_region_to_reg(mem, offset); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1405 | break; |
| 1406 | case WMFW_ADSP1_ZM: |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1407 | region_name = "ZM"; |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 1408 | reg = wm_adsp_region_to_reg(mem, offset); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1409 | break; |
| 1410 | default: |
| 1411 | adsp_warn(dsp, |
| 1412 | "%s.%d: Unknown region type %x at %d(%x)\n", |
| 1413 | file, regions, type, pos, pos); |
| 1414 | break; |
| 1415 | } |
| 1416 | |
| 1417 | adsp_dbg(dsp, "%s.%d: %d bytes at %d in %s\n", file, |
| 1418 | regions, le32_to_cpu(region->len), offset, |
| 1419 | region_name); |
| 1420 | |
| 1421 | if (text) { |
| 1422 | memcpy(text, region->data, le32_to_cpu(region->len)); |
| 1423 | adsp_info(dsp, "%s: %s\n", file, text); |
| 1424 | kfree(text); |
| 1425 | } |
| 1426 | |
| 1427 | if (reg) { |
Charles Keepax | cdcd7f7 | 2014-11-14 15:40:45 +0000 | [diff] [blame] | 1428 | buf = wm_adsp_buf_alloc(region->data, |
| 1429 | le32_to_cpu(region->len), |
| 1430 | &buf_list); |
| 1431 | if (!buf) { |
| 1432 | adsp_err(dsp, "Out of memory\n"); |
| 1433 | ret = -ENOMEM; |
| 1434 | goto out_fw; |
| 1435 | } |
Mark Brown | a76fefa | 2013-01-07 19:03:17 +0000 | [diff] [blame] | 1436 | |
Charles Keepax | cdcd7f7 | 2014-11-14 15:40:45 +0000 | [diff] [blame] | 1437 | ret = regmap_raw_write_async(regmap, reg, buf->buf, |
| 1438 | le32_to_cpu(region->len)); |
| 1439 | if (ret != 0) { |
| 1440 | adsp_err(dsp, |
| 1441 | "%s.%d: Failed to write %d bytes at %d in %s: %d\n", |
| 1442 | file, regions, |
| 1443 | le32_to_cpu(region->len), offset, |
| 1444 | region_name, ret); |
| 1445 | goto out_fw; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | pos += le32_to_cpu(region->len) + sizeof(*region); |
| 1450 | regions++; |
| 1451 | } |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1452 | |
| 1453 | ret = regmap_async_complete(regmap); |
| 1454 | if (ret != 0) { |
| 1455 | adsp_err(dsp, "Failed to complete async write: %d\n", ret); |
| 1456 | goto out_fw; |
| 1457 | } |
| 1458 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1459 | if (pos > firmware->size) |
| 1460 | adsp_warn(dsp, "%s.%d: %zu bytes at end of file\n", |
| 1461 | file, regions, pos - firmware->size); |
| 1462 | |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 1463 | wm_adsp_debugfs_save_wmfwname(dsp, file); |
| 1464 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1465 | out_fw: |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1466 | regmap_async_complete(regmap); |
| 1467 | wm_adsp_buf_free(&buf_list); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1468 | release_firmware(firmware); |
| 1469 | out: |
| 1470 | kfree(file); |
| 1471 | |
| 1472 | return ret; |
| 1473 | } |
| 1474 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1475 | static void wm_adsp_ctl_fixup_base(struct wm_adsp *dsp, |
| 1476 | const struct wm_adsp_alg_region *alg_region) |
| 1477 | { |
| 1478 | struct wm_coeff_ctl *ctl; |
| 1479 | |
| 1480 | list_for_each_entry(ctl, &dsp->ctl_list, list) { |
| 1481 | if (ctl->fw_name == wm_adsp_fw_text[dsp->fw] && |
| 1482 | alg_region->alg == ctl->alg_region.alg && |
| 1483 | alg_region->type == ctl->alg_region.type) { |
| 1484 | ctl->alg_region.base = alg_region->base; |
| 1485 | } |
| 1486 | } |
| 1487 | } |
| 1488 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1489 | static void *wm_adsp_read_algs(struct wm_adsp *dsp, size_t n_algs, |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1490 | unsigned int pos, unsigned int len) |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1491 | { |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1492 | void *alg; |
| 1493 | int ret; |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1494 | __be32 val; |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1495 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1496 | if (n_algs == 0) { |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1497 | adsp_err(dsp, "No algorithms\n"); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1498 | return ERR_PTR(-EINVAL); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1499 | } |
| 1500 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1501 | if (n_algs > 1024) { |
| 1502 | adsp_err(dsp, "Algorithm count %zx excessive\n", n_algs); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1503 | return ERR_PTR(-EINVAL); |
Mark Brown | d62f4bc | 2012-12-19 14:00:30 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1506 | /* Read the terminator first to validate the length */ |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1507 | ret = regmap_raw_read(dsp->regmap, pos + len, &val, sizeof(val)); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1508 | if (ret != 0) { |
| 1509 | adsp_err(dsp, "Failed to read algorithm list end: %d\n", |
| 1510 | ret); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1511 | return ERR_PTR(ret); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | if (be32_to_cpu(val) != 0xbedead) |
| 1515 | adsp_warn(dsp, "Algorithm list end %x 0x%x != 0xbeadead\n", |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1516 | pos + len, be32_to_cpu(val)); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1517 | |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1518 | alg = kzalloc(len * 2, GFP_KERNEL | GFP_DMA); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1519 | if (!alg) |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1520 | return ERR_PTR(-ENOMEM); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1521 | |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1522 | ret = regmap_raw_read(dsp->regmap, pos, alg, len * 2); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1523 | if (ret != 0) { |
Charles Keepax | 7d00cd9 | 2016-02-19 14:44:43 +0000 | [diff] [blame] | 1524 | adsp_err(dsp, "Failed to read algorithm list: %d\n", ret); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1525 | kfree(alg); |
| 1526 | return ERR_PTR(ret); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1527 | } |
| 1528 | |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1529 | return alg; |
| 1530 | } |
| 1531 | |
Charles Keepax | 1419709 | 2015-12-15 11:29:43 +0000 | [diff] [blame] | 1532 | static struct wm_adsp_alg_region * |
| 1533 | wm_adsp_find_alg_region(struct wm_adsp *dsp, int type, unsigned int id) |
| 1534 | { |
| 1535 | struct wm_adsp_alg_region *alg_region; |
| 1536 | |
| 1537 | list_for_each_entry(alg_region, &dsp->alg_regions, list) { |
| 1538 | if (id == alg_region->alg && type == alg_region->type) |
| 1539 | return alg_region; |
| 1540 | } |
| 1541 | |
| 1542 | return NULL; |
| 1543 | } |
| 1544 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1545 | static struct wm_adsp_alg_region *wm_adsp_create_region(struct wm_adsp *dsp, |
| 1546 | int type, __be32 id, |
| 1547 | __be32 base) |
| 1548 | { |
| 1549 | struct wm_adsp_alg_region *alg_region; |
| 1550 | |
| 1551 | alg_region = kzalloc(sizeof(*alg_region), GFP_KERNEL); |
| 1552 | if (!alg_region) |
| 1553 | return ERR_PTR(-ENOMEM); |
| 1554 | |
| 1555 | alg_region->type = type; |
| 1556 | alg_region->alg = be32_to_cpu(id); |
| 1557 | alg_region->base = be32_to_cpu(base); |
| 1558 | |
| 1559 | list_add_tail(&alg_region->list, &dsp->alg_regions); |
| 1560 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1561 | if (dsp->fw_ver > 0) |
| 1562 | wm_adsp_ctl_fixup_base(dsp, alg_region); |
| 1563 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1564 | return alg_region; |
| 1565 | } |
| 1566 | |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1567 | static int wm_adsp1_setup_algs(struct wm_adsp *dsp) |
| 1568 | { |
| 1569 | struct wmfw_adsp1_id_hdr adsp1_id; |
| 1570 | struct wmfw_adsp1_alg_hdr *adsp1_alg; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1571 | struct wm_adsp_alg_region *alg_region; |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1572 | const struct wm_adsp_region *mem; |
| 1573 | unsigned int pos, len; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1574 | size_t n_algs; |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1575 | int i, ret; |
| 1576 | |
| 1577 | mem = wm_adsp_find_region(dsp, WMFW_ADSP1_DM); |
| 1578 | if (WARN_ON(!mem)) |
| 1579 | return -EINVAL; |
| 1580 | |
| 1581 | ret = regmap_raw_read(dsp->regmap, mem->base, &adsp1_id, |
| 1582 | sizeof(adsp1_id)); |
| 1583 | if (ret != 0) { |
| 1584 | adsp_err(dsp, "Failed to read algorithm info: %d\n", |
| 1585 | ret); |
| 1586 | return ret; |
| 1587 | } |
| 1588 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1589 | n_algs = be32_to_cpu(adsp1_id.n_algs); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1590 | dsp->fw_id = be32_to_cpu(adsp1_id.fw.id); |
| 1591 | adsp_info(dsp, "Firmware: %x v%d.%d.%d, %zu algorithms\n", |
| 1592 | dsp->fw_id, |
| 1593 | (be32_to_cpu(adsp1_id.fw.ver) & 0xff0000) >> 16, |
| 1594 | (be32_to_cpu(adsp1_id.fw.ver) & 0xff00) >> 8, |
| 1595 | be32_to_cpu(adsp1_id.fw.ver) & 0xff, |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1596 | n_algs); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1597 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1598 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_ZM, |
| 1599 | adsp1_id.fw.id, adsp1_id.zm); |
| 1600 | if (IS_ERR(alg_region)) |
| 1601 | return PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1602 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1603 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_DM, |
| 1604 | adsp1_id.fw.id, adsp1_id.dm); |
| 1605 | if (IS_ERR(alg_region)) |
| 1606 | return PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1607 | |
| 1608 | pos = sizeof(adsp1_id) / 2; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1609 | len = (sizeof(*adsp1_alg) * n_algs) / 2; |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1610 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1611 | adsp1_alg = wm_adsp_read_algs(dsp, n_algs, mem->base + pos, len); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1612 | if (IS_ERR(adsp1_alg)) |
| 1613 | return PTR_ERR(adsp1_alg); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1614 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1615 | for (i = 0; i < n_algs; i++) { |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1616 | adsp_info(dsp, "%d: ID %x v%d.%d.%d DM@%x ZM@%x\n", |
| 1617 | i, be32_to_cpu(adsp1_alg[i].alg.id), |
| 1618 | (be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff0000) >> 16, |
| 1619 | (be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff00) >> 8, |
| 1620 | be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff, |
| 1621 | be32_to_cpu(adsp1_alg[i].dm), |
| 1622 | be32_to_cpu(adsp1_alg[i].zm)); |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 1623 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1624 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_DM, |
| 1625 | adsp1_alg[i].alg.id, |
| 1626 | adsp1_alg[i].dm); |
| 1627 | if (IS_ERR(alg_region)) { |
| 1628 | ret = PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1629 | goto out; |
| 1630 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1631 | if (dsp->fw_ver == 0) { |
| 1632 | if (i + 1 < n_algs) { |
| 1633 | len = be32_to_cpu(adsp1_alg[i + 1].dm); |
| 1634 | len -= be32_to_cpu(adsp1_alg[i].dm); |
| 1635 | len *= 4; |
| 1636 | wm_adsp_create_control(dsp, alg_region, 0, |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 1637 | len, NULL, 0, 0); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1638 | } else { |
| 1639 | adsp_warn(dsp, "Missing length info for region DM with ID %x\n", |
| 1640 | be32_to_cpu(adsp1_alg[i].alg.id)); |
| 1641 | } |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1642 | } |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 1643 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1644 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_ZM, |
| 1645 | adsp1_alg[i].alg.id, |
| 1646 | adsp1_alg[i].zm); |
| 1647 | if (IS_ERR(alg_region)) { |
| 1648 | ret = PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1649 | goto out; |
| 1650 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1651 | if (dsp->fw_ver == 0) { |
| 1652 | if (i + 1 < n_algs) { |
| 1653 | len = be32_to_cpu(adsp1_alg[i + 1].zm); |
| 1654 | len -= be32_to_cpu(adsp1_alg[i].zm); |
| 1655 | len *= 4; |
| 1656 | wm_adsp_create_control(dsp, alg_region, 0, |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 1657 | len, NULL, 0, 0); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1658 | } else { |
| 1659 | adsp_warn(dsp, "Missing length info for region ZM with ID %x\n", |
| 1660 | be32_to_cpu(adsp1_alg[i].alg.id)); |
| 1661 | } |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1662 | } |
| 1663 | } |
| 1664 | |
| 1665 | out: |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1666 | kfree(adsp1_alg); |
| 1667 | return ret; |
| 1668 | } |
| 1669 | |
| 1670 | static int wm_adsp2_setup_algs(struct wm_adsp *dsp) |
| 1671 | { |
| 1672 | struct wmfw_adsp2_id_hdr adsp2_id; |
| 1673 | struct wmfw_adsp2_alg_hdr *adsp2_alg; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1674 | struct wm_adsp_alg_region *alg_region; |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1675 | const struct wm_adsp_region *mem; |
| 1676 | unsigned int pos, len; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1677 | size_t n_algs; |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1678 | int i, ret; |
| 1679 | |
| 1680 | mem = wm_adsp_find_region(dsp, WMFW_ADSP2_XM); |
| 1681 | if (WARN_ON(!mem)) |
| 1682 | return -EINVAL; |
| 1683 | |
| 1684 | ret = regmap_raw_read(dsp->regmap, mem->base, &adsp2_id, |
| 1685 | sizeof(adsp2_id)); |
| 1686 | if (ret != 0) { |
| 1687 | adsp_err(dsp, "Failed to read algorithm info: %d\n", |
| 1688 | ret); |
| 1689 | return ret; |
| 1690 | } |
| 1691 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1692 | n_algs = be32_to_cpu(adsp2_id.n_algs); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1693 | dsp->fw_id = be32_to_cpu(adsp2_id.fw.id); |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 1694 | dsp->fw_id_version = be32_to_cpu(adsp2_id.fw.ver); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1695 | adsp_info(dsp, "Firmware: %x v%d.%d.%d, %zu algorithms\n", |
| 1696 | dsp->fw_id, |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 1697 | (dsp->fw_id_version & 0xff0000) >> 16, |
| 1698 | (dsp->fw_id_version & 0xff00) >> 8, |
| 1699 | dsp->fw_id_version & 0xff, |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1700 | n_algs); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1701 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1702 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_XM, |
| 1703 | adsp2_id.fw.id, adsp2_id.xm); |
| 1704 | if (IS_ERR(alg_region)) |
| 1705 | return PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1706 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1707 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_YM, |
| 1708 | adsp2_id.fw.id, adsp2_id.ym); |
| 1709 | if (IS_ERR(alg_region)) |
| 1710 | return PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1711 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1712 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_ZM, |
| 1713 | adsp2_id.fw.id, adsp2_id.zm); |
| 1714 | if (IS_ERR(alg_region)) |
| 1715 | return PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1716 | |
| 1717 | pos = sizeof(adsp2_id) / 2; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1718 | len = (sizeof(*adsp2_alg) * n_algs) / 2; |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1719 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1720 | adsp2_alg = wm_adsp_read_algs(dsp, n_algs, mem->base + pos, len); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1721 | if (IS_ERR(adsp2_alg)) |
| 1722 | return PTR_ERR(adsp2_alg); |
| 1723 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1724 | for (i = 0; i < n_algs; i++) { |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1725 | adsp_info(dsp, |
| 1726 | "%d: ID %x v%d.%d.%d XM@%x YM@%x ZM@%x\n", |
| 1727 | i, be32_to_cpu(adsp2_alg[i].alg.id), |
| 1728 | (be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff0000) >> 16, |
| 1729 | (be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff00) >> 8, |
| 1730 | be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff, |
| 1731 | be32_to_cpu(adsp2_alg[i].xm), |
| 1732 | be32_to_cpu(adsp2_alg[i].ym), |
| 1733 | be32_to_cpu(adsp2_alg[i].zm)); |
| 1734 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1735 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_XM, |
| 1736 | adsp2_alg[i].alg.id, |
| 1737 | adsp2_alg[i].xm); |
| 1738 | if (IS_ERR(alg_region)) { |
| 1739 | ret = PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1740 | goto out; |
| 1741 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1742 | if (dsp->fw_ver == 0) { |
| 1743 | if (i + 1 < n_algs) { |
| 1744 | len = be32_to_cpu(adsp2_alg[i + 1].xm); |
| 1745 | len -= be32_to_cpu(adsp2_alg[i].xm); |
| 1746 | len *= 4; |
| 1747 | wm_adsp_create_control(dsp, alg_region, 0, |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 1748 | len, NULL, 0, 0); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1749 | } else { |
| 1750 | adsp_warn(dsp, "Missing length info for region XM with ID %x\n", |
| 1751 | be32_to_cpu(adsp2_alg[i].alg.id)); |
| 1752 | } |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1753 | } |
| 1754 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1755 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_YM, |
| 1756 | adsp2_alg[i].alg.id, |
| 1757 | adsp2_alg[i].ym); |
| 1758 | if (IS_ERR(alg_region)) { |
| 1759 | ret = PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1760 | goto out; |
| 1761 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1762 | if (dsp->fw_ver == 0) { |
| 1763 | if (i + 1 < n_algs) { |
| 1764 | len = be32_to_cpu(adsp2_alg[i + 1].ym); |
| 1765 | len -= be32_to_cpu(adsp2_alg[i].ym); |
| 1766 | len *= 4; |
| 1767 | wm_adsp_create_control(dsp, alg_region, 0, |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 1768 | len, NULL, 0, 0); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1769 | } else { |
| 1770 | adsp_warn(dsp, "Missing length info for region YM with ID %x\n", |
| 1771 | be32_to_cpu(adsp2_alg[i].alg.id)); |
| 1772 | } |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1773 | } |
| 1774 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1775 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_ZM, |
| 1776 | adsp2_alg[i].alg.id, |
| 1777 | adsp2_alg[i].zm); |
| 1778 | if (IS_ERR(alg_region)) { |
| 1779 | ret = PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1780 | goto out; |
| 1781 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1782 | if (dsp->fw_ver == 0) { |
| 1783 | if (i + 1 < n_algs) { |
| 1784 | len = be32_to_cpu(adsp2_alg[i + 1].zm); |
| 1785 | len -= be32_to_cpu(adsp2_alg[i].zm); |
| 1786 | len *= 4; |
| 1787 | wm_adsp_create_control(dsp, alg_region, 0, |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 1788 | len, NULL, 0, 0); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1789 | } else { |
| 1790 | adsp_warn(dsp, "Missing length info for region ZM with ID %x\n", |
| 1791 | be32_to_cpu(adsp2_alg[i].alg.id)); |
| 1792 | } |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1793 | } |
| 1794 | } |
| 1795 | |
| 1796 | out: |
| 1797 | kfree(adsp2_alg); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1798 | return ret; |
| 1799 | } |
| 1800 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1801 | static int wm_adsp_load_coeff(struct wm_adsp *dsp) |
| 1802 | { |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1803 | LIST_HEAD(buf_list); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1804 | struct regmap *regmap = dsp->regmap; |
| 1805 | struct wmfw_coeff_hdr *hdr; |
| 1806 | struct wmfw_coeff_item *blk; |
| 1807 | const struct firmware *firmware; |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 1808 | const struct wm_adsp_region *mem; |
| 1809 | struct wm_adsp_alg_region *alg_region; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1810 | const char *region_name; |
| 1811 | int ret, pos, blocks, type, offset, reg; |
| 1812 | char *file; |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1813 | struct wm_adsp_buf *buf; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1814 | |
| 1815 | file = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 1816 | if (file == NULL) |
| 1817 | return -ENOMEM; |
| 1818 | |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 1819 | snprintf(file, PAGE_SIZE, "%s-dsp%d-%s.bin", dsp->part, dsp->num, |
| 1820 | wm_adsp_fw[dsp->fw].file); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1821 | file[PAGE_SIZE - 1] = '\0'; |
| 1822 | |
| 1823 | ret = request_firmware(&firmware, file, dsp->dev); |
| 1824 | if (ret != 0) { |
| 1825 | adsp_warn(dsp, "Failed to request '%s'\n", file); |
| 1826 | ret = 0; |
| 1827 | goto out; |
| 1828 | } |
| 1829 | ret = -EINVAL; |
| 1830 | |
| 1831 | if (sizeof(*hdr) >= firmware->size) { |
| 1832 | adsp_err(dsp, "%s: file too short, %zu bytes\n", |
| 1833 | file, firmware->size); |
| 1834 | goto out_fw; |
| 1835 | } |
| 1836 | |
Charles Keepax | 7585a5b | 2015-12-08 16:08:25 +0000 | [diff] [blame] | 1837 | hdr = (void *)&firmware->data[0]; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1838 | if (memcmp(hdr->magic, "WMDR", 4) != 0) { |
| 1839 | adsp_err(dsp, "%s: invalid magic\n", file); |
Charles Keepax | a4cdbec | 2013-01-21 09:02:31 +0000 | [diff] [blame] | 1840 | goto out_fw; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1841 | } |
| 1842 | |
Mark Brown | c712326 | 2013-01-16 16:59:04 +0900 | [diff] [blame] | 1843 | switch (be32_to_cpu(hdr->rev) & 0xff) { |
| 1844 | case 1: |
| 1845 | break; |
| 1846 | default: |
| 1847 | adsp_err(dsp, "%s: Unsupported coefficient file format %d\n", |
| 1848 | file, be32_to_cpu(hdr->rev) & 0xff); |
| 1849 | ret = -EINVAL; |
| 1850 | goto out_fw; |
| 1851 | } |
| 1852 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1853 | adsp_dbg(dsp, "%s: v%d.%d.%d\n", file, |
| 1854 | (le32_to_cpu(hdr->ver) >> 16) & 0xff, |
| 1855 | (le32_to_cpu(hdr->ver) >> 8) & 0xff, |
| 1856 | le32_to_cpu(hdr->ver) & 0xff); |
| 1857 | |
| 1858 | pos = le32_to_cpu(hdr->len); |
| 1859 | |
| 1860 | blocks = 0; |
| 1861 | while (pos < firmware->size && |
| 1862 | pos - firmware->size > sizeof(*blk)) { |
Charles Keepax | 7585a5b | 2015-12-08 16:08:25 +0000 | [diff] [blame] | 1863 | blk = (void *)(&firmware->data[pos]); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1864 | |
Mark Brown | c712326 | 2013-01-16 16:59:04 +0900 | [diff] [blame] | 1865 | type = le16_to_cpu(blk->type); |
| 1866 | offset = le16_to_cpu(blk->offset); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1867 | |
| 1868 | adsp_dbg(dsp, "%s.%d: %x v%d.%d.%d\n", |
| 1869 | file, blocks, le32_to_cpu(blk->id), |
| 1870 | (le32_to_cpu(blk->ver) >> 16) & 0xff, |
| 1871 | (le32_to_cpu(blk->ver) >> 8) & 0xff, |
| 1872 | le32_to_cpu(blk->ver) & 0xff); |
| 1873 | adsp_dbg(dsp, "%s.%d: %d bytes at 0x%x in %x\n", |
| 1874 | file, blocks, le32_to_cpu(blk->len), offset, type); |
| 1875 | |
| 1876 | reg = 0; |
| 1877 | region_name = "Unknown"; |
| 1878 | switch (type) { |
Mark Brown | c712326 | 2013-01-16 16:59:04 +0900 | [diff] [blame] | 1879 | case (WMFW_NAME_TEXT << 8): |
| 1880 | case (WMFW_INFO_TEXT << 8): |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1881 | break; |
Mark Brown | c712326 | 2013-01-16 16:59:04 +0900 | [diff] [blame] | 1882 | case (WMFW_ABSOLUTE << 8): |
Mark Brown | f395a21 | 2013-03-05 22:39:54 +0800 | [diff] [blame] | 1883 | /* |
| 1884 | * Old files may use this for global |
| 1885 | * coefficients. |
| 1886 | */ |
| 1887 | if (le32_to_cpu(blk->id) == dsp->fw_id && |
| 1888 | offset == 0) { |
| 1889 | region_name = "global coefficients"; |
| 1890 | mem = wm_adsp_find_region(dsp, type); |
| 1891 | if (!mem) { |
| 1892 | adsp_err(dsp, "No ZM\n"); |
| 1893 | break; |
| 1894 | } |
| 1895 | reg = wm_adsp_region_to_reg(mem, 0); |
| 1896 | |
| 1897 | } else { |
| 1898 | region_name = "register"; |
| 1899 | reg = offset; |
| 1900 | } |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1901 | break; |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 1902 | |
| 1903 | case WMFW_ADSP1_DM: |
| 1904 | case WMFW_ADSP1_ZM: |
| 1905 | case WMFW_ADSP2_XM: |
| 1906 | case WMFW_ADSP2_YM: |
| 1907 | adsp_dbg(dsp, "%s.%d: %d bytes in %x for %x\n", |
| 1908 | file, blocks, le32_to_cpu(blk->len), |
| 1909 | type, le32_to_cpu(blk->id)); |
| 1910 | |
| 1911 | mem = wm_adsp_find_region(dsp, type); |
| 1912 | if (!mem) { |
| 1913 | adsp_err(dsp, "No base for region %x\n", type); |
| 1914 | break; |
| 1915 | } |
| 1916 | |
Charles Keepax | 1419709 | 2015-12-15 11:29:43 +0000 | [diff] [blame] | 1917 | alg_region = wm_adsp_find_alg_region(dsp, type, |
| 1918 | le32_to_cpu(blk->id)); |
| 1919 | if (alg_region) { |
| 1920 | reg = alg_region->base; |
| 1921 | reg = wm_adsp_region_to_reg(mem, reg); |
| 1922 | reg += offset; |
| 1923 | } else { |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 1924 | adsp_err(dsp, "No %x for algorithm %x\n", |
| 1925 | type, le32_to_cpu(blk->id)); |
Charles Keepax | 1419709 | 2015-12-15 11:29:43 +0000 | [diff] [blame] | 1926 | } |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 1927 | break; |
| 1928 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1929 | default: |
Mark Brown | 25c62f7e | 2013-01-20 19:02:19 +0900 | [diff] [blame] | 1930 | adsp_err(dsp, "%s.%d: Unknown region type %x at %d\n", |
| 1931 | file, blocks, type, pos); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1932 | break; |
| 1933 | } |
| 1934 | |
| 1935 | if (reg) { |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1936 | buf = wm_adsp_buf_alloc(blk->data, |
| 1937 | le32_to_cpu(blk->len), |
| 1938 | &buf_list); |
Mark Brown | a76fefa | 2013-01-07 19:03:17 +0000 | [diff] [blame] | 1939 | if (!buf) { |
| 1940 | adsp_err(dsp, "Out of memory\n"); |
Wei Yongjun | f4b8281 | 2013-03-12 00:23:15 +0800 | [diff] [blame] | 1941 | ret = -ENOMEM; |
| 1942 | goto out_fw; |
Mark Brown | a76fefa | 2013-01-07 19:03:17 +0000 | [diff] [blame] | 1943 | } |
| 1944 | |
Mark Brown | 20da6d5 | 2013-01-12 19:58:17 +0000 | [diff] [blame] | 1945 | adsp_dbg(dsp, "%s.%d: Writing %d bytes at %x\n", |
| 1946 | file, blocks, le32_to_cpu(blk->len), |
| 1947 | reg); |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1948 | ret = regmap_raw_write_async(regmap, reg, buf->buf, |
| 1949 | le32_to_cpu(blk->len)); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1950 | if (ret != 0) { |
| 1951 | adsp_err(dsp, |
Dimitris Papastamos | 43bc3bf | 2013-11-01 15:56:52 +0000 | [diff] [blame] | 1952 | "%s.%d: Failed to write to %x in %s: %d\n", |
| 1953 | file, blocks, reg, region_name, ret); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1954 | } |
| 1955 | } |
| 1956 | |
Charles Keepax | be95101 | 2015-02-16 15:25:49 +0000 | [diff] [blame] | 1957 | pos += (le32_to_cpu(blk->len) + sizeof(*blk) + 3) & ~0x03; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1958 | blocks++; |
| 1959 | } |
| 1960 | |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1961 | ret = regmap_async_complete(regmap); |
| 1962 | if (ret != 0) |
| 1963 | adsp_err(dsp, "Failed to complete async write: %d\n", ret); |
| 1964 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1965 | if (pos > firmware->size) |
| 1966 | adsp_warn(dsp, "%s.%d: %zu bytes at end of file\n", |
| 1967 | file, blocks, pos - firmware->size); |
| 1968 | |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 1969 | wm_adsp_debugfs_save_binname(dsp, file); |
| 1970 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1971 | out_fw: |
Charles Keepax | 9da7a5a | 2014-11-17 10:48:21 +0000 | [diff] [blame] | 1972 | regmap_async_complete(regmap); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1973 | release_firmware(firmware); |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1974 | wm_adsp_buf_free(&buf_list); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1975 | out: |
| 1976 | kfree(file); |
Wei Yongjun | f4b8281 | 2013-03-12 00:23:15 +0800 | [diff] [blame] | 1977 | return ret; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1978 | } |
| 1979 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1980 | int wm_adsp1_init(struct wm_adsp *dsp) |
Mark Brown | 5e7a7a2 | 2013-01-16 10:03:56 +0900 | [diff] [blame] | 1981 | { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1982 | INIT_LIST_HEAD(&dsp->alg_regions); |
Mark Brown | 5e7a7a2 | 2013-01-16 10:03:56 +0900 | [diff] [blame] | 1983 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 1984 | mutex_init(&dsp->pwr_lock); |
| 1985 | |
Mark Brown | 5e7a7a2 | 2013-01-16 10:03:56 +0900 | [diff] [blame] | 1986 | return 0; |
| 1987 | } |
| 1988 | EXPORT_SYMBOL_GPL(wm_adsp1_init); |
| 1989 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1990 | int wm_adsp1_event(struct snd_soc_dapm_widget *w, |
| 1991 | struct snd_kcontrol *kcontrol, |
| 1992 | int event) |
| 1993 | { |
Lars-Peter Clausen | 7271851 | 2015-01-13 10:27:34 +0100 | [diff] [blame] | 1994 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1995 | struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec); |
| 1996 | struct wm_adsp *dsp = &dsps[w->shift]; |
Dimitris Papastamos | b0101b4 | 2013-11-01 15:56:56 +0000 | [diff] [blame] | 1997 | struct wm_adsp_alg_region *alg_region; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 1998 | struct wm_coeff_ctl *ctl; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1999 | int ret; |
Charles Keepax | 7585a5b | 2015-12-08 16:08:25 +0000 | [diff] [blame] | 2000 | unsigned int val; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2001 | |
Lars-Peter Clausen | 0020010 | 2014-07-17 22:01:07 +0200 | [diff] [blame] | 2002 | dsp->card = codec->component.card; |
Dimitris Papastamos | 92bb4c3 | 2013-08-01 11:11:28 +0100 | [diff] [blame] | 2003 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2004 | mutex_lock(&dsp->pwr_lock); |
| 2005 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2006 | switch (event) { |
| 2007 | case SND_SOC_DAPM_POST_PMU: |
| 2008 | regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30, |
| 2009 | ADSP1_SYS_ENA, ADSP1_SYS_ENA); |
| 2010 | |
Chris Rattray | 94e205b | 2013-01-18 08:43:09 +0000 | [diff] [blame] | 2011 | /* |
| 2012 | * For simplicity set the DSP clock rate to be the |
| 2013 | * SYSCLK rate rather than making it configurable. |
| 2014 | */ |
Charles Keepax | 7585a5b | 2015-12-08 16:08:25 +0000 | [diff] [blame] | 2015 | if (dsp->sysclk_reg) { |
Chris Rattray | 94e205b | 2013-01-18 08:43:09 +0000 | [diff] [blame] | 2016 | ret = regmap_read(dsp->regmap, dsp->sysclk_reg, &val); |
| 2017 | if (ret != 0) { |
| 2018 | adsp_err(dsp, "Failed to read SYSCLK state: %d\n", |
| 2019 | ret); |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2020 | goto err_mutex; |
Chris Rattray | 94e205b | 2013-01-18 08:43:09 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
Charles Keepax | 7d00cd9 | 2016-02-19 14:44:43 +0000 | [diff] [blame] | 2023 | val = (val & dsp->sysclk_mask) >> dsp->sysclk_shift; |
Chris Rattray | 94e205b | 2013-01-18 08:43:09 +0000 | [diff] [blame] | 2024 | |
| 2025 | ret = regmap_update_bits(dsp->regmap, |
| 2026 | dsp->base + ADSP1_CONTROL_31, |
| 2027 | ADSP1_CLK_SEL_MASK, val); |
| 2028 | if (ret != 0) { |
| 2029 | adsp_err(dsp, "Failed to set clock rate: %d\n", |
| 2030 | ret); |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2031 | goto err_mutex; |
Chris Rattray | 94e205b | 2013-01-18 08:43:09 +0000 | [diff] [blame] | 2032 | } |
| 2033 | } |
| 2034 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2035 | ret = wm_adsp_load(dsp); |
| 2036 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2037 | goto err_ena; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2038 | |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 2039 | ret = wm_adsp1_setup_algs(dsp); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 2040 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2041 | goto err_ena; |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 2042 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2043 | ret = wm_adsp_load_coeff(dsp); |
| 2044 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2045 | goto err_ena; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2046 | |
Dimitris Papastamos | 0c2e3f3 | 2013-05-28 12:01:50 +0100 | [diff] [blame] | 2047 | /* Initialize caches for enabled and unset controls */ |
Dimitris Papastamos | 81ad93e | 2013-07-29 13:51:59 +0100 | [diff] [blame] | 2048 | ret = wm_coeff_init_control_caches(dsp); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 2049 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2050 | goto err_ena; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 2051 | |
Dimitris Papastamos | 0c2e3f3 | 2013-05-28 12:01:50 +0100 | [diff] [blame] | 2052 | /* Sync set controls */ |
Dimitris Papastamos | 81ad93e | 2013-07-29 13:51:59 +0100 | [diff] [blame] | 2053 | ret = wm_coeff_sync_controls(dsp); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 2054 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2055 | goto err_ena; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 2056 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2057 | /* Start the core running */ |
| 2058 | regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30, |
| 2059 | ADSP1_CORE_ENA | ADSP1_START, |
| 2060 | ADSP1_CORE_ENA | ADSP1_START); |
| 2061 | break; |
| 2062 | |
| 2063 | case SND_SOC_DAPM_PRE_PMD: |
| 2064 | /* Halt the core */ |
| 2065 | regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30, |
| 2066 | ADSP1_CORE_ENA | ADSP1_START, 0); |
| 2067 | |
| 2068 | regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_19, |
| 2069 | ADSP1_WDMA_BUFFER_LENGTH_MASK, 0); |
| 2070 | |
| 2071 | regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30, |
| 2072 | ADSP1_SYS_ENA, 0); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 2073 | |
Dimitris Papastamos | 81ad93e | 2013-07-29 13:51:59 +0100 | [diff] [blame] | 2074 | list_for_each_entry(ctl, &dsp->ctl_list, list) |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 2075 | ctl->enabled = 0; |
Dimitris Papastamos | b0101b4 | 2013-11-01 15:56:56 +0000 | [diff] [blame] | 2076 | |
| 2077 | while (!list_empty(&dsp->alg_regions)) { |
| 2078 | alg_region = list_first_entry(&dsp->alg_regions, |
| 2079 | struct wm_adsp_alg_region, |
| 2080 | list); |
| 2081 | list_del(&alg_region->list); |
| 2082 | kfree(alg_region); |
| 2083 | } |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2084 | break; |
| 2085 | |
| 2086 | default: |
| 2087 | break; |
| 2088 | } |
| 2089 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2090 | mutex_unlock(&dsp->pwr_lock); |
| 2091 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2092 | return 0; |
| 2093 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2094 | err_ena: |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2095 | regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30, |
| 2096 | ADSP1_SYS_ENA, 0); |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2097 | err_mutex: |
| 2098 | mutex_unlock(&dsp->pwr_lock); |
| 2099 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2100 | return ret; |
| 2101 | } |
| 2102 | EXPORT_SYMBOL_GPL(wm_adsp1_event); |
| 2103 | |
| 2104 | static int wm_adsp2_ena(struct wm_adsp *dsp) |
| 2105 | { |
| 2106 | unsigned int val; |
| 2107 | int ret, count; |
| 2108 | |
Mark Brown | 1552c32 | 2013-11-28 18:11:38 +0000 | [diff] [blame] | 2109 | ret = regmap_update_bits_async(dsp->regmap, dsp->base + ADSP2_CONTROL, |
| 2110 | ADSP2_SYS_ENA, ADSP2_SYS_ENA); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2111 | if (ret != 0) |
| 2112 | return ret; |
| 2113 | |
| 2114 | /* Wait for the RAM to start, should be near instantaneous */ |
Charles Keepax | 939fd1e | 2013-12-18 09:25:49 +0000 | [diff] [blame] | 2115 | for (count = 0; count < 10; ++count) { |
Charles Keepax | 7d00cd9 | 2016-02-19 14:44:43 +0000 | [diff] [blame] | 2116 | ret = regmap_read(dsp->regmap, dsp->base + ADSP2_STATUS1, &val); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2117 | if (ret != 0) |
| 2118 | return ret; |
Charles Keepax | 939fd1e | 2013-12-18 09:25:49 +0000 | [diff] [blame] | 2119 | |
| 2120 | if (val & ADSP2_RAM_RDY) |
| 2121 | break; |
| 2122 | |
| 2123 | msleep(1); |
| 2124 | } |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2125 | |
| 2126 | if (!(val & ADSP2_RAM_RDY)) { |
| 2127 | adsp_err(dsp, "Failed to start DSP RAM\n"); |
| 2128 | return -EBUSY; |
| 2129 | } |
| 2130 | |
| 2131 | adsp_dbg(dsp, "RAM ready after %d polls\n", count); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2132 | |
| 2133 | return 0; |
| 2134 | } |
| 2135 | |
Charles Keepax | 18b1a90 | 2014-01-09 09:06:54 +0000 | [diff] [blame] | 2136 | static void wm_adsp2_boot_work(struct work_struct *work) |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2137 | { |
| 2138 | struct wm_adsp *dsp = container_of(work, |
| 2139 | struct wm_adsp, |
| 2140 | boot_work); |
| 2141 | int ret; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2142 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2143 | mutex_lock(&dsp->pwr_lock); |
| 2144 | |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2145 | ret = wm_adsp2_ena(dsp); |
| 2146 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2147 | goto err_mutex; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2148 | |
| 2149 | ret = wm_adsp_load(dsp); |
| 2150 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2151 | goto err_ena; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2152 | |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 2153 | ret = wm_adsp2_setup_algs(dsp); |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2154 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2155 | goto err_ena; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2156 | |
| 2157 | ret = wm_adsp_load_coeff(dsp); |
| 2158 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2159 | goto err_ena; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2160 | |
| 2161 | /* Initialize caches for enabled and unset controls */ |
| 2162 | ret = wm_coeff_init_control_caches(dsp); |
| 2163 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2164 | goto err_ena; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2165 | |
| 2166 | /* Sync set controls */ |
| 2167 | ret = wm_coeff_sync_controls(dsp); |
| 2168 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2169 | goto err_ena; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2170 | |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2171 | dsp->running = true; |
| 2172 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2173 | mutex_unlock(&dsp->pwr_lock); |
| 2174 | |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2175 | return; |
| 2176 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2177 | err_ena: |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2178 | regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL, |
| 2179 | ADSP2_SYS_ENA | ADSP2_CORE_ENA | ADSP2_START, 0); |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2180 | err_mutex: |
| 2181 | mutex_unlock(&dsp->pwr_lock); |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
Charles Keepax | d82d767 | 2016-01-21 17:53:02 +0000 | [diff] [blame] | 2184 | static void wm_adsp2_set_dspclk(struct wm_adsp *dsp, unsigned int freq) |
| 2185 | { |
| 2186 | int ret; |
| 2187 | |
| 2188 | ret = regmap_update_bits_async(dsp->regmap, |
| 2189 | dsp->base + ADSP2_CLOCKING, |
| 2190 | ADSP2_CLK_SEL_MASK, |
| 2191 | freq << ADSP2_CLK_SEL_SHIFT); |
| 2192 | if (ret != 0) |
| 2193 | adsp_err(dsp, "Failed to set clock rate: %d\n", ret); |
| 2194 | } |
| 2195 | |
Charles Keepax | 12db5ed | 2014-01-08 17:42:19 +0000 | [diff] [blame] | 2196 | int wm_adsp2_early_event(struct snd_soc_dapm_widget *w, |
Charles Keepax | d82d767 | 2016-01-21 17:53:02 +0000 | [diff] [blame] | 2197 | struct snd_kcontrol *kcontrol, int event, |
| 2198 | unsigned int freq) |
Charles Keepax | 12db5ed | 2014-01-08 17:42:19 +0000 | [diff] [blame] | 2199 | { |
Lars-Peter Clausen | 7271851 | 2015-01-13 10:27:34 +0100 | [diff] [blame] | 2200 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
Charles Keepax | 12db5ed | 2014-01-08 17:42:19 +0000 | [diff] [blame] | 2201 | struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec); |
| 2202 | struct wm_adsp *dsp = &dsps[w->shift]; |
| 2203 | |
Lars-Peter Clausen | 0020010 | 2014-07-17 22:01:07 +0200 | [diff] [blame] | 2204 | dsp->card = codec->component.card; |
Charles Keepax | 12db5ed | 2014-01-08 17:42:19 +0000 | [diff] [blame] | 2205 | |
| 2206 | switch (event) { |
| 2207 | case SND_SOC_DAPM_PRE_PMU: |
Charles Keepax | d82d767 | 2016-01-21 17:53:02 +0000 | [diff] [blame] | 2208 | wm_adsp2_set_dspclk(dsp, freq); |
Charles Keepax | 12db5ed | 2014-01-08 17:42:19 +0000 | [diff] [blame] | 2209 | queue_work(system_unbound_wq, &dsp->boot_work); |
| 2210 | break; |
| 2211 | default: |
| 2212 | break; |
Charles Keepax | cab2725 | 2014-04-17 13:42:54 +0100 | [diff] [blame] | 2213 | } |
Charles Keepax | 12db5ed | 2014-01-08 17:42:19 +0000 | [diff] [blame] | 2214 | |
| 2215 | return 0; |
| 2216 | } |
| 2217 | EXPORT_SYMBOL_GPL(wm_adsp2_early_event); |
| 2218 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2219 | int wm_adsp2_event(struct snd_soc_dapm_widget *w, |
| 2220 | struct snd_kcontrol *kcontrol, int event) |
| 2221 | { |
Lars-Peter Clausen | 7271851 | 2015-01-13 10:27:34 +0100 | [diff] [blame] | 2222 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2223 | struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec); |
| 2224 | struct wm_adsp *dsp = &dsps[w->shift]; |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 2225 | struct wm_adsp_alg_region *alg_region; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 2226 | struct wm_coeff_ctl *ctl; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2227 | int ret; |
| 2228 | |
| 2229 | switch (event) { |
| 2230 | case SND_SOC_DAPM_POST_PMU: |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2231 | flush_work(&dsp->boot_work); |
Mark Brown | dd49e2c | 2012-12-02 21:50:46 +0900 | [diff] [blame] | 2232 | |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2233 | if (!dsp->running) |
| 2234 | return -EIO; |
Mark Brown | dd49e2c | 2012-12-02 21:50:46 +0900 | [diff] [blame] | 2235 | |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2236 | ret = regmap_update_bits(dsp->regmap, |
| 2237 | dsp->base + ADSP2_CONTROL, |
Charles Keepax | 00e4c3b | 2014-11-18 16:25:27 +0000 | [diff] [blame] | 2238 | ADSP2_CORE_ENA | ADSP2_START, |
| 2239 | ADSP2_CORE_ENA | ADSP2_START); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2240 | if (ret != 0) |
| 2241 | goto err; |
Charles Keepax | 2cd19bd | 2015-12-15 11:29:46 +0000 | [diff] [blame] | 2242 | |
Charles Keepax | 612047f | 2016-03-28 14:29:22 +0100 | [diff] [blame] | 2243 | mutex_lock(&dsp->pwr_lock); |
| 2244 | |
Charles Keepax | 2cd19bd | 2015-12-15 11:29:46 +0000 | [diff] [blame] | 2245 | if (wm_adsp_fw[dsp->fw].num_caps != 0) |
| 2246 | ret = wm_adsp_buffer_init(dsp); |
| 2247 | |
Charles Keepax | 612047f | 2016-03-28 14:29:22 +0100 | [diff] [blame] | 2248 | mutex_unlock(&dsp->pwr_lock); |
| 2249 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2250 | break; |
| 2251 | |
| 2252 | case SND_SOC_DAPM_PRE_PMD: |
Richard Fitzgerald | 10337b0 | 2015-05-29 10:23:07 +0100 | [diff] [blame] | 2253 | /* Log firmware state, it can be useful for analysis */ |
| 2254 | wm_adsp2_show_fw_status(dsp); |
| 2255 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2256 | mutex_lock(&dsp->pwr_lock); |
| 2257 | |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 2258 | wm_adsp_debugfs_clear(dsp); |
| 2259 | |
| 2260 | dsp->fw_id = 0; |
| 2261 | dsp->fw_id_version = 0; |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 2262 | dsp->running = false; |
| 2263 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2264 | regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL, |
Mark Brown | a7f9be7 | 2012-11-28 19:53:59 +0000 | [diff] [blame] | 2265 | ADSP2_SYS_ENA | ADSP2_CORE_ENA | |
| 2266 | ADSP2_START, 0); |
Mark Brown | 973838a | 2012-11-28 17:20:32 +0000 | [diff] [blame] | 2267 | |
Mark Brown | 2d30b57 | 2013-01-28 20:18:17 +0800 | [diff] [blame] | 2268 | /* Make sure DMAs are quiesced */ |
| 2269 | regmap_write(dsp->regmap, dsp->base + ADSP2_WDMA_CONFIG_1, 0); |
| 2270 | regmap_write(dsp->regmap, dsp->base + ADSP2_WDMA_CONFIG_2, 0); |
| 2271 | regmap_write(dsp->regmap, dsp->base + ADSP2_RDMA_CONFIG_1, 0); |
| 2272 | |
Dimitris Papastamos | 81ad93e | 2013-07-29 13:51:59 +0100 | [diff] [blame] | 2273 | list_for_each_entry(ctl, &dsp->ctl_list, list) |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 2274 | ctl->enabled = 0; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 2275 | |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 2276 | while (!list_empty(&dsp->alg_regions)) { |
| 2277 | alg_region = list_first_entry(&dsp->alg_regions, |
| 2278 | struct wm_adsp_alg_region, |
| 2279 | list); |
| 2280 | list_del(&alg_region->list); |
| 2281 | kfree(alg_region); |
| 2282 | } |
Charles Keepax | ddbc5ef | 2014-01-22 10:09:11 +0000 | [diff] [blame] | 2283 | |
Charles Keepax | 2cd19bd | 2015-12-15 11:29:46 +0000 | [diff] [blame] | 2284 | if (wm_adsp_fw[dsp->fw].num_caps != 0) |
| 2285 | wm_adsp_buffer_free(dsp); |
| 2286 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2287 | mutex_unlock(&dsp->pwr_lock); |
| 2288 | |
Charles Keepax | ddbc5ef | 2014-01-22 10:09:11 +0000 | [diff] [blame] | 2289 | adsp_dbg(dsp, "Shutdown complete\n"); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2290 | break; |
| 2291 | |
| 2292 | default: |
| 2293 | break; |
| 2294 | } |
| 2295 | |
| 2296 | return 0; |
| 2297 | err: |
| 2298 | regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL, |
Mark Brown | a7f9be7 | 2012-11-28 19:53:59 +0000 | [diff] [blame] | 2299 | ADSP2_SYS_ENA | ADSP2_CORE_ENA | ADSP2_START, 0); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2300 | return ret; |
| 2301 | } |
| 2302 | EXPORT_SYMBOL_GPL(wm_adsp2_event); |
Mark Brown | 973838a | 2012-11-28 17:20:32 +0000 | [diff] [blame] | 2303 | |
Richard Fitzgerald | f5e2ce9 | 2015-06-11 11:32:30 +0100 | [diff] [blame] | 2304 | int wm_adsp2_codec_probe(struct wm_adsp *dsp, struct snd_soc_codec *codec) |
| 2305 | { |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 2306 | wm_adsp2_init_debugfs(dsp, codec); |
| 2307 | |
Richard Fitzgerald | 218e508 | 2015-06-11 11:32:31 +0100 | [diff] [blame] | 2308 | return snd_soc_add_codec_controls(codec, |
Richard Fitzgerald | 336d044 | 2015-06-18 13:43:19 +0100 | [diff] [blame] | 2309 | &wm_adsp_fw_controls[dsp->num - 1], |
| 2310 | 1); |
Richard Fitzgerald | f5e2ce9 | 2015-06-11 11:32:30 +0100 | [diff] [blame] | 2311 | } |
| 2312 | EXPORT_SYMBOL_GPL(wm_adsp2_codec_probe); |
| 2313 | |
| 2314 | int wm_adsp2_codec_remove(struct wm_adsp *dsp, struct snd_soc_codec *codec) |
| 2315 | { |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 2316 | wm_adsp2_cleanup_debugfs(dsp); |
| 2317 | |
Richard Fitzgerald | f5e2ce9 | 2015-06-11 11:32:30 +0100 | [diff] [blame] | 2318 | return 0; |
| 2319 | } |
| 2320 | EXPORT_SYMBOL_GPL(wm_adsp2_codec_remove); |
| 2321 | |
Richard Fitzgerald | 81ac58b | 2015-06-02 11:53:34 +0100 | [diff] [blame] | 2322 | int wm_adsp2_init(struct wm_adsp *dsp) |
Mark Brown | 973838a | 2012-11-28 17:20:32 +0000 | [diff] [blame] | 2323 | { |
| 2324 | int ret; |
| 2325 | |
Mark Brown | 10a2b66 | 2012-12-02 21:37:00 +0900 | [diff] [blame] | 2326 | /* |
| 2327 | * Disable the DSP memory by default when in reset for a small |
| 2328 | * power saving. |
| 2329 | */ |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 2330 | ret = regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL, |
Mark Brown | 10a2b66 | 2012-12-02 21:37:00 +0900 | [diff] [blame] | 2331 | ADSP2_MEM_ENA, 0); |
| 2332 | if (ret != 0) { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 2333 | adsp_err(dsp, "Failed to clear memory retention: %d\n", ret); |
Mark Brown | 10a2b66 | 2012-12-02 21:37:00 +0900 | [diff] [blame] | 2334 | return ret; |
| 2335 | } |
| 2336 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 2337 | INIT_LIST_HEAD(&dsp->alg_regions); |
| 2338 | INIT_LIST_HEAD(&dsp->ctl_list); |
| 2339 | INIT_WORK(&dsp->boot_work, wm_adsp2_boot_work); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 2340 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame] | 2341 | mutex_init(&dsp->pwr_lock); |
| 2342 | |
Mark Brown | 973838a | 2012-11-28 17:20:32 +0000 | [diff] [blame] | 2343 | return 0; |
| 2344 | } |
| 2345 | EXPORT_SYMBOL_GPL(wm_adsp2_init); |
Praveen Diwakar | 0a37c6e | 2014-07-04 11:17:41 +0530 | [diff] [blame] | 2346 | |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 2347 | int wm_adsp_compr_open(struct wm_adsp *dsp, struct snd_compr_stream *stream) |
| 2348 | { |
| 2349 | struct wm_adsp_compr *compr; |
| 2350 | int ret = 0; |
| 2351 | |
| 2352 | mutex_lock(&dsp->pwr_lock); |
| 2353 | |
| 2354 | if (wm_adsp_fw[dsp->fw].num_caps == 0) { |
| 2355 | adsp_err(dsp, "Firmware does not support compressed API\n"); |
| 2356 | ret = -ENXIO; |
| 2357 | goto out; |
| 2358 | } |
| 2359 | |
| 2360 | if (wm_adsp_fw[dsp->fw].compr_direction != stream->direction) { |
| 2361 | adsp_err(dsp, "Firmware does not support stream direction\n"); |
| 2362 | ret = -EINVAL; |
| 2363 | goto out; |
| 2364 | } |
| 2365 | |
Charles Keepax | 95fe959 | 2015-12-15 11:29:47 +0000 | [diff] [blame] | 2366 | if (dsp->compr) { |
| 2367 | /* It is expect this limitation will be removed in future */ |
| 2368 | adsp_err(dsp, "Only a single stream supported per DSP\n"); |
| 2369 | ret = -EBUSY; |
| 2370 | goto out; |
| 2371 | } |
| 2372 | |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 2373 | compr = kzalloc(sizeof(*compr), GFP_KERNEL); |
| 2374 | if (!compr) { |
| 2375 | ret = -ENOMEM; |
| 2376 | goto out; |
| 2377 | } |
| 2378 | |
| 2379 | compr->dsp = dsp; |
| 2380 | compr->stream = stream; |
| 2381 | |
| 2382 | dsp->compr = compr; |
| 2383 | |
| 2384 | stream->runtime->private_data = compr; |
| 2385 | |
| 2386 | out: |
| 2387 | mutex_unlock(&dsp->pwr_lock); |
| 2388 | |
| 2389 | return ret; |
| 2390 | } |
| 2391 | EXPORT_SYMBOL_GPL(wm_adsp_compr_open); |
| 2392 | |
| 2393 | int wm_adsp_compr_free(struct snd_compr_stream *stream) |
| 2394 | { |
| 2395 | struct wm_adsp_compr *compr = stream->runtime->private_data; |
| 2396 | struct wm_adsp *dsp = compr->dsp; |
| 2397 | |
| 2398 | mutex_lock(&dsp->pwr_lock); |
| 2399 | |
| 2400 | dsp->compr = NULL; |
| 2401 | |
Charles Keepax | 83a40ce | 2016-01-06 12:33:19 +0000 | [diff] [blame] | 2402 | kfree(compr->raw_buf); |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 2403 | kfree(compr); |
| 2404 | |
| 2405 | mutex_unlock(&dsp->pwr_lock); |
| 2406 | |
| 2407 | return 0; |
| 2408 | } |
| 2409 | EXPORT_SYMBOL_GPL(wm_adsp_compr_free); |
| 2410 | |
| 2411 | static int wm_adsp_compr_check_params(struct snd_compr_stream *stream, |
| 2412 | struct snd_compr_params *params) |
| 2413 | { |
| 2414 | struct wm_adsp_compr *compr = stream->runtime->private_data; |
| 2415 | struct wm_adsp *dsp = compr->dsp; |
| 2416 | const struct wm_adsp_fw_caps *caps; |
| 2417 | const struct snd_codec_desc *desc; |
| 2418 | int i, j; |
| 2419 | |
| 2420 | if (params->buffer.fragment_size < WM_ADSP_MIN_FRAGMENT_SIZE || |
| 2421 | params->buffer.fragment_size > WM_ADSP_MAX_FRAGMENT_SIZE || |
| 2422 | params->buffer.fragments < WM_ADSP_MIN_FRAGMENTS || |
| 2423 | params->buffer.fragments > WM_ADSP_MAX_FRAGMENTS || |
| 2424 | params->buffer.fragment_size % WM_ADSP_DATA_WORD_SIZE) { |
| 2425 | adsp_err(dsp, "Invalid buffer fragsize=%d fragments=%d\n", |
| 2426 | params->buffer.fragment_size, |
| 2427 | params->buffer.fragments); |
| 2428 | |
| 2429 | return -EINVAL; |
| 2430 | } |
| 2431 | |
| 2432 | for (i = 0; i < wm_adsp_fw[dsp->fw].num_caps; i++) { |
| 2433 | caps = &wm_adsp_fw[dsp->fw].caps[i]; |
| 2434 | desc = &caps->desc; |
| 2435 | |
| 2436 | if (caps->id != params->codec.id) |
| 2437 | continue; |
| 2438 | |
| 2439 | if (stream->direction == SND_COMPRESS_PLAYBACK) { |
| 2440 | if (desc->max_ch < params->codec.ch_out) |
| 2441 | continue; |
| 2442 | } else { |
| 2443 | if (desc->max_ch < params->codec.ch_in) |
| 2444 | continue; |
| 2445 | } |
| 2446 | |
| 2447 | if (!(desc->formats & (1 << params->codec.format))) |
| 2448 | continue; |
| 2449 | |
| 2450 | for (j = 0; j < desc->num_sample_rates; ++j) |
| 2451 | if (desc->sample_rates[j] == params->codec.sample_rate) |
| 2452 | return 0; |
| 2453 | } |
| 2454 | |
| 2455 | adsp_err(dsp, "Invalid params id=%u ch=%u,%u rate=%u fmt=%u\n", |
| 2456 | params->codec.id, params->codec.ch_in, params->codec.ch_out, |
| 2457 | params->codec.sample_rate, params->codec.format); |
| 2458 | return -EINVAL; |
| 2459 | } |
| 2460 | |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2461 | static inline unsigned int wm_adsp_compr_frag_words(struct wm_adsp_compr *compr) |
| 2462 | { |
| 2463 | return compr->size.fragment_size / WM_ADSP_DATA_WORD_SIZE; |
| 2464 | } |
| 2465 | |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 2466 | int wm_adsp_compr_set_params(struct snd_compr_stream *stream, |
| 2467 | struct snd_compr_params *params) |
| 2468 | { |
| 2469 | struct wm_adsp_compr *compr = stream->runtime->private_data; |
Charles Keepax | 83a40ce | 2016-01-06 12:33:19 +0000 | [diff] [blame] | 2470 | unsigned int size; |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 2471 | int ret; |
| 2472 | |
| 2473 | ret = wm_adsp_compr_check_params(stream, params); |
| 2474 | if (ret) |
| 2475 | return ret; |
| 2476 | |
| 2477 | compr->size = params->buffer; |
| 2478 | |
| 2479 | adsp_dbg(compr->dsp, "fragment_size=%d fragments=%d\n", |
| 2480 | compr->size.fragment_size, compr->size.fragments); |
| 2481 | |
Charles Keepax | 83a40ce | 2016-01-06 12:33:19 +0000 | [diff] [blame] | 2482 | size = wm_adsp_compr_frag_words(compr) * sizeof(*compr->raw_buf); |
| 2483 | compr->raw_buf = kmalloc(size, GFP_DMA | GFP_KERNEL); |
| 2484 | if (!compr->raw_buf) |
| 2485 | return -ENOMEM; |
| 2486 | |
Charles Keepax | da2b335 | 2016-02-02 16:41:36 +0000 | [diff] [blame] | 2487 | compr->sample_rate = params->codec.sample_rate; |
| 2488 | |
Charles Keepax | 406abc9 | 2015-12-15 11:29:45 +0000 | [diff] [blame] | 2489 | return 0; |
| 2490 | } |
| 2491 | EXPORT_SYMBOL_GPL(wm_adsp_compr_set_params); |
| 2492 | |
| 2493 | int wm_adsp_compr_get_caps(struct snd_compr_stream *stream, |
| 2494 | struct snd_compr_caps *caps) |
| 2495 | { |
| 2496 | struct wm_adsp_compr *compr = stream->runtime->private_data; |
| 2497 | int fw = compr->dsp->fw; |
| 2498 | int i; |
| 2499 | |
| 2500 | if (wm_adsp_fw[fw].caps) { |
| 2501 | for (i = 0; i < wm_adsp_fw[fw].num_caps; i++) |
| 2502 | caps->codecs[i] = wm_adsp_fw[fw].caps[i].id; |
| 2503 | |
| 2504 | caps->num_codecs = i; |
| 2505 | caps->direction = wm_adsp_fw[fw].compr_direction; |
| 2506 | |
| 2507 | caps->min_fragment_size = WM_ADSP_MIN_FRAGMENT_SIZE; |
| 2508 | caps->max_fragment_size = WM_ADSP_MAX_FRAGMENT_SIZE; |
| 2509 | caps->min_fragments = WM_ADSP_MIN_FRAGMENTS; |
| 2510 | caps->max_fragments = WM_ADSP_MAX_FRAGMENTS; |
| 2511 | } |
| 2512 | |
| 2513 | return 0; |
| 2514 | } |
| 2515 | EXPORT_SYMBOL_GPL(wm_adsp_compr_get_caps); |
| 2516 | |
Charles Keepax | 2cd19bd | 2015-12-15 11:29:46 +0000 | [diff] [blame] | 2517 | static int wm_adsp_read_data_block(struct wm_adsp *dsp, int mem_type, |
| 2518 | unsigned int mem_addr, |
| 2519 | unsigned int num_words, u32 *data) |
| 2520 | { |
| 2521 | struct wm_adsp_region const *mem = wm_adsp_find_region(dsp, mem_type); |
| 2522 | unsigned int i, reg; |
| 2523 | int ret; |
| 2524 | |
| 2525 | if (!mem) |
| 2526 | return -EINVAL; |
| 2527 | |
| 2528 | reg = wm_adsp_region_to_reg(mem, mem_addr); |
| 2529 | |
| 2530 | ret = regmap_raw_read(dsp->regmap, reg, data, |
| 2531 | sizeof(*data) * num_words); |
| 2532 | if (ret < 0) |
| 2533 | return ret; |
| 2534 | |
| 2535 | for (i = 0; i < num_words; ++i) |
| 2536 | data[i] = be32_to_cpu(data[i]) & 0x00ffffffu; |
| 2537 | |
| 2538 | return 0; |
| 2539 | } |
| 2540 | |
| 2541 | static inline int wm_adsp_read_data_word(struct wm_adsp *dsp, int mem_type, |
| 2542 | unsigned int mem_addr, u32 *data) |
| 2543 | { |
| 2544 | return wm_adsp_read_data_block(dsp, mem_type, mem_addr, 1, data); |
| 2545 | } |
| 2546 | |
| 2547 | static int wm_adsp_write_data_word(struct wm_adsp *dsp, int mem_type, |
| 2548 | unsigned int mem_addr, u32 data) |
| 2549 | { |
| 2550 | struct wm_adsp_region const *mem = wm_adsp_find_region(dsp, mem_type); |
| 2551 | unsigned int reg; |
| 2552 | |
| 2553 | if (!mem) |
| 2554 | return -EINVAL; |
| 2555 | |
| 2556 | reg = wm_adsp_region_to_reg(mem, mem_addr); |
| 2557 | |
| 2558 | data = cpu_to_be32(data & 0x00ffffffu); |
| 2559 | |
| 2560 | return regmap_raw_write(dsp->regmap, reg, &data, sizeof(data)); |
| 2561 | } |
| 2562 | |
| 2563 | static inline int wm_adsp_buffer_read(struct wm_adsp_compr_buf *buf, |
| 2564 | unsigned int field_offset, u32 *data) |
| 2565 | { |
| 2566 | return wm_adsp_read_data_word(buf->dsp, WMFW_ADSP2_XM, |
| 2567 | buf->host_buf_ptr + field_offset, data); |
| 2568 | } |
| 2569 | |
| 2570 | static inline int wm_adsp_buffer_write(struct wm_adsp_compr_buf *buf, |
| 2571 | unsigned int field_offset, u32 data) |
| 2572 | { |
| 2573 | return wm_adsp_write_data_word(buf->dsp, WMFW_ADSP2_XM, |
| 2574 | buf->host_buf_ptr + field_offset, data); |
| 2575 | } |
| 2576 | |
| 2577 | static int wm_adsp_buffer_locate(struct wm_adsp_compr_buf *buf) |
| 2578 | { |
| 2579 | struct wm_adsp_alg_region *alg_region; |
| 2580 | struct wm_adsp *dsp = buf->dsp; |
| 2581 | u32 xmalg, addr, magic; |
| 2582 | int i, ret; |
| 2583 | |
| 2584 | alg_region = wm_adsp_find_alg_region(dsp, WMFW_ADSP2_XM, dsp->fw_id); |
| 2585 | xmalg = sizeof(struct wm_adsp_system_config_xm_hdr) / sizeof(__be32); |
| 2586 | |
| 2587 | addr = alg_region->base + xmalg + ALG_XM_FIELD(magic); |
| 2588 | ret = wm_adsp_read_data_word(dsp, WMFW_ADSP2_XM, addr, &magic); |
| 2589 | if (ret < 0) |
| 2590 | return ret; |
| 2591 | |
| 2592 | if (magic != WM_ADSP_ALG_XM_STRUCT_MAGIC) |
| 2593 | return -EINVAL; |
| 2594 | |
| 2595 | addr = alg_region->base + xmalg + ALG_XM_FIELD(host_buf_ptr); |
| 2596 | for (i = 0; i < 5; ++i) { |
| 2597 | ret = wm_adsp_read_data_word(dsp, WMFW_ADSP2_XM, addr, |
| 2598 | &buf->host_buf_ptr); |
| 2599 | if (ret < 0) |
| 2600 | return ret; |
| 2601 | |
| 2602 | if (buf->host_buf_ptr) |
| 2603 | break; |
| 2604 | |
| 2605 | usleep_range(1000, 2000); |
| 2606 | } |
| 2607 | |
| 2608 | if (!buf->host_buf_ptr) |
| 2609 | return -EIO; |
| 2610 | |
| 2611 | adsp_dbg(dsp, "host_buf_ptr=%x\n", buf->host_buf_ptr); |
| 2612 | |
| 2613 | return 0; |
| 2614 | } |
| 2615 | |
| 2616 | static int wm_adsp_buffer_populate(struct wm_adsp_compr_buf *buf) |
| 2617 | { |
| 2618 | const struct wm_adsp_fw_caps *caps = wm_adsp_fw[buf->dsp->fw].caps; |
| 2619 | struct wm_adsp_buffer_region *region; |
| 2620 | u32 offset = 0; |
| 2621 | int i, ret; |
| 2622 | |
| 2623 | for (i = 0; i < caps->num_regions; ++i) { |
| 2624 | region = &buf->regions[i]; |
| 2625 | |
| 2626 | region->offset = offset; |
| 2627 | region->mem_type = caps->region_defs[i].mem_type; |
| 2628 | |
| 2629 | ret = wm_adsp_buffer_read(buf, caps->region_defs[i].base_offset, |
| 2630 | ®ion->base_addr); |
| 2631 | if (ret < 0) |
| 2632 | return ret; |
| 2633 | |
| 2634 | ret = wm_adsp_buffer_read(buf, caps->region_defs[i].size_offset, |
| 2635 | &offset); |
| 2636 | if (ret < 0) |
| 2637 | return ret; |
| 2638 | |
| 2639 | region->cumulative_size = offset; |
| 2640 | |
| 2641 | adsp_dbg(buf->dsp, |
| 2642 | "region=%d type=%d base=%04x off=%04x size=%04x\n", |
| 2643 | i, region->mem_type, region->base_addr, |
| 2644 | region->offset, region->cumulative_size); |
| 2645 | } |
| 2646 | |
| 2647 | return 0; |
| 2648 | } |
| 2649 | |
| 2650 | static int wm_adsp_buffer_init(struct wm_adsp *dsp) |
| 2651 | { |
| 2652 | struct wm_adsp_compr_buf *buf; |
| 2653 | int ret; |
| 2654 | |
| 2655 | buf = kzalloc(sizeof(*buf), GFP_KERNEL); |
| 2656 | if (!buf) |
| 2657 | return -ENOMEM; |
| 2658 | |
| 2659 | buf->dsp = dsp; |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2660 | buf->read_index = -1; |
| 2661 | buf->irq_count = 0xFFFFFFFF; |
Charles Keepax | 2cd19bd | 2015-12-15 11:29:46 +0000 | [diff] [blame] | 2662 | |
| 2663 | ret = wm_adsp_buffer_locate(buf); |
| 2664 | if (ret < 0) { |
| 2665 | adsp_err(dsp, "Failed to acquire host buffer: %d\n", ret); |
| 2666 | goto err_buffer; |
| 2667 | } |
| 2668 | |
| 2669 | buf->regions = kcalloc(wm_adsp_fw[dsp->fw].caps->num_regions, |
| 2670 | sizeof(*buf->regions), GFP_KERNEL); |
| 2671 | if (!buf->regions) { |
| 2672 | ret = -ENOMEM; |
| 2673 | goto err_buffer; |
| 2674 | } |
| 2675 | |
| 2676 | ret = wm_adsp_buffer_populate(buf); |
| 2677 | if (ret < 0) { |
| 2678 | adsp_err(dsp, "Failed to populate host buffer: %d\n", ret); |
| 2679 | goto err_regions; |
| 2680 | } |
| 2681 | |
| 2682 | dsp->buffer = buf; |
| 2683 | |
| 2684 | return 0; |
| 2685 | |
| 2686 | err_regions: |
| 2687 | kfree(buf->regions); |
| 2688 | err_buffer: |
| 2689 | kfree(buf); |
| 2690 | return ret; |
| 2691 | } |
| 2692 | |
| 2693 | static int wm_adsp_buffer_free(struct wm_adsp *dsp) |
| 2694 | { |
| 2695 | if (dsp->buffer) { |
| 2696 | kfree(dsp->buffer->regions); |
| 2697 | kfree(dsp->buffer); |
| 2698 | |
| 2699 | dsp->buffer = NULL; |
| 2700 | } |
| 2701 | |
| 2702 | return 0; |
| 2703 | } |
| 2704 | |
Charles Keepax | 95fe959 | 2015-12-15 11:29:47 +0000 | [diff] [blame] | 2705 | static inline int wm_adsp_compr_attached(struct wm_adsp_compr *compr) |
| 2706 | { |
| 2707 | return compr->buf != NULL; |
| 2708 | } |
| 2709 | |
| 2710 | static int wm_adsp_compr_attach(struct wm_adsp_compr *compr) |
| 2711 | { |
| 2712 | /* |
| 2713 | * Note this will be more complex once each DSP can support multiple |
| 2714 | * streams |
| 2715 | */ |
| 2716 | if (!compr->dsp->buffer) |
| 2717 | return -EINVAL; |
| 2718 | |
| 2719 | compr->buf = compr->dsp->buffer; |
| 2720 | |
| 2721 | return 0; |
| 2722 | } |
| 2723 | |
| 2724 | int wm_adsp_compr_trigger(struct snd_compr_stream *stream, int cmd) |
| 2725 | { |
| 2726 | struct wm_adsp_compr *compr = stream->runtime->private_data; |
| 2727 | struct wm_adsp *dsp = compr->dsp; |
| 2728 | int ret = 0; |
| 2729 | |
| 2730 | adsp_dbg(dsp, "Trigger: %d\n", cmd); |
| 2731 | |
| 2732 | mutex_lock(&dsp->pwr_lock); |
| 2733 | |
| 2734 | switch (cmd) { |
| 2735 | case SNDRV_PCM_TRIGGER_START: |
| 2736 | if (wm_adsp_compr_attached(compr)) |
| 2737 | break; |
| 2738 | |
| 2739 | ret = wm_adsp_compr_attach(compr); |
| 2740 | if (ret < 0) { |
| 2741 | adsp_err(dsp, "Failed to link buffer and stream: %d\n", |
| 2742 | ret); |
| 2743 | break; |
| 2744 | } |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2745 | |
| 2746 | /* Trigger the IRQ at one fragment of data */ |
| 2747 | ret = wm_adsp_buffer_write(compr->buf, |
| 2748 | HOST_BUFFER_FIELD(high_water_mark), |
| 2749 | wm_adsp_compr_frag_words(compr)); |
| 2750 | if (ret < 0) { |
| 2751 | adsp_err(dsp, "Failed to set high water mark: %d\n", |
| 2752 | ret); |
| 2753 | break; |
| 2754 | } |
Charles Keepax | 95fe959 | 2015-12-15 11:29:47 +0000 | [diff] [blame] | 2755 | break; |
| 2756 | case SNDRV_PCM_TRIGGER_STOP: |
| 2757 | break; |
| 2758 | default: |
| 2759 | ret = -EINVAL; |
| 2760 | break; |
| 2761 | } |
| 2762 | |
| 2763 | mutex_unlock(&dsp->pwr_lock); |
| 2764 | |
| 2765 | return ret; |
| 2766 | } |
| 2767 | EXPORT_SYMBOL_GPL(wm_adsp_compr_trigger); |
| 2768 | |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2769 | static inline int wm_adsp_buffer_size(struct wm_adsp_compr_buf *buf) |
| 2770 | { |
| 2771 | int last_region = wm_adsp_fw[buf->dsp->fw].caps->num_regions - 1; |
| 2772 | |
| 2773 | return buf->regions[last_region].cumulative_size; |
| 2774 | } |
| 2775 | |
| 2776 | static int wm_adsp_buffer_update_avail(struct wm_adsp_compr_buf *buf) |
| 2777 | { |
| 2778 | u32 next_read_index, next_write_index; |
| 2779 | int write_index, read_index, avail; |
| 2780 | int ret; |
| 2781 | |
| 2782 | /* Only sync read index if we haven't already read a valid index */ |
| 2783 | if (buf->read_index < 0) { |
| 2784 | ret = wm_adsp_buffer_read(buf, |
| 2785 | HOST_BUFFER_FIELD(next_read_index), |
| 2786 | &next_read_index); |
| 2787 | if (ret < 0) |
| 2788 | return ret; |
| 2789 | |
| 2790 | read_index = sign_extend32(next_read_index, 23); |
| 2791 | |
| 2792 | if (read_index < 0) { |
| 2793 | adsp_dbg(buf->dsp, "Avail check on unstarted stream\n"); |
| 2794 | return 0; |
| 2795 | } |
| 2796 | |
| 2797 | buf->read_index = read_index; |
| 2798 | } |
| 2799 | |
| 2800 | ret = wm_adsp_buffer_read(buf, HOST_BUFFER_FIELD(next_write_index), |
| 2801 | &next_write_index); |
| 2802 | if (ret < 0) |
| 2803 | return ret; |
| 2804 | |
| 2805 | write_index = sign_extend32(next_write_index, 23); |
| 2806 | |
| 2807 | avail = write_index - buf->read_index; |
| 2808 | if (avail < 0) |
| 2809 | avail += wm_adsp_buffer_size(buf); |
| 2810 | |
| 2811 | adsp_dbg(buf->dsp, "readindex=0x%x, writeindex=0x%x, avail=%d\n", |
Charles Keepax | 33d740e | 2016-03-28 14:29:21 +0100 | [diff] [blame] | 2812 | buf->read_index, write_index, avail * WM_ADSP_DATA_WORD_SIZE); |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2813 | |
| 2814 | buf->avail = avail; |
| 2815 | |
| 2816 | return 0; |
| 2817 | } |
| 2818 | |
Charles Keepax | 9771b18 | 2016-04-06 11:21:53 +0100 | [diff] [blame] | 2819 | static int wm_adsp_buffer_get_error(struct wm_adsp_compr_buf *buf) |
| 2820 | { |
| 2821 | int ret; |
| 2822 | |
| 2823 | ret = wm_adsp_buffer_read(buf, HOST_BUFFER_FIELD(error), &buf->error); |
| 2824 | if (ret < 0) { |
| 2825 | adsp_err(buf->dsp, "Failed to check buffer error: %d\n", ret); |
| 2826 | return ret; |
| 2827 | } |
| 2828 | if (buf->error != 0) { |
| 2829 | adsp_err(buf->dsp, "Buffer error occurred: %d\n", buf->error); |
| 2830 | return -EIO; |
| 2831 | } |
| 2832 | |
| 2833 | return 0; |
| 2834 | } |
| 2835 | |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2836 | int wm_adsp_compr_handle_irq(struct wm_adsp *dsp) |
| 2837 | { |
Charles Keepax | 612047f | 2016-03-28 14:29:22 +0100 | [diff] [blame] | 2838 | struct wm_adsp_compr_buf *buf; |
| 2839 | struct wm_adsp_compr *compr; |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2840 | int ret = 0; |
| 2841 | |
| 2842 | mutex_lock(&dsp->pwr_lock); |
| 2843 | |
Charles Keepax | 612047f | 2016-03-28 14:29:22 +0100 | [diff] [blame] | 2844 | buf = dsp->buffer; |
| 2845 | compr = dsp->compr; |
| 2846 | |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2847 | if (!buf) { |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2848 | ret = -ENODEV; |
| 2849 | goto out; |
| 2850 | } |
| 2851 | |
| 2852 | adsp_dbg(dsp, "Handling buffer IRQ\n"); |
| 2853 | |
Charles Keepax | 9771b18 | 2016-04-06 11:21:53 +0100 | [diff] [blame] | 2854 | ret = wm_adsp_buffer_get_error(buf); |
| 2855 | if (ret < 0) |
Charles Keepax | 5847609 | 2016-04-06 11:21:54 +0100 | [diff] [blame^] | 2856 | goto out_notify; /* Wake poll to report error */ |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2857 | |
| 2858 | ret = wm_adsp_buffer_read(buf, HOST_BUFFER_FIELD(irq_count), |
| 2859 | &buf->irq_count); |
| 2860 | if (ret < 0) { |
| 2861 | adsp_err(dsp, "Failed to get irq_count: %d\n", ret); |
| 2862 | goto out; |
| 2863 | } |
| 2864 | |
| 2865 | ret = wm_adsp_buffer_update_avail(buf); |
| 2866 | if (ret < 0) { |
| 2867 | adsp_err(dsp, "Error reading avail: %d\n", ret); |
| 2868 | goto out; |
| 2869 | } |
| 2870 | |
Charles Keepax | 5847609 | 2016-04-06 11:21:54 +0100 | [diff] [blame^] | 2871 | out_notify: |
Charles Keepax | c7dae7c | 2016-02-19 14:44:41 +0000 | [diff] [blame] | 2872 | if (compr && compr->stream) |
Charles Keepax | 83a40ce | 2016-01-06 12:33:19 +0000 | [diff] [blame] | 2873 | snd_compr_fragment_elapsed(compr->stream); |
| 2874 | |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2875 | out: |
| 2876 | mutex_unlock(&dsp->pwr_lock); |
| 2877 | |
| 2878 | return ret; |
| 2879 | } |
| 2880 | EXPORT_SYMBOL_GPL(wm_adsp_compr_handle_irq); |
| 2881 | |
| 2882 | static int wm_adsp_buffer_reenable_irq(struct wm_adsp_compr_buf *buf) |
| 2883 | { |
| 2884 | if (buf->irq_count & 0x01) |
| 2885 | return 0; |
| 2886 | |
| 2887 | adsp_dbg(buf->dsp, "Enable IRQ(0x%x) for next fragment\n", |
| 2888 | buf->irq_count); |
| 2889 | |
| 2890 | buf->irq_count |= 0x01; |
| 2891 | |
| 2892 | return wm_adsp_buffer_write(buf, HOST_BUFFER_FIELD(irq_ack), |
| 2893 | buf->irq_count); |
| 2894 | } |
| 2895 | |
| 2896 | int wm_adsp_compr_pointer(struct snd_compr_stream *stream, |
| 2897 | struct snd_compr_tstamp *tstamp) |
| 2898 | { |
| 2899 | struct wm_adsp_compr *compr = stream->runtime->private_data; |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2900 | struct wm_adsp *dsp = compr->dsp; |
Charles Keepax | 612047f | 2016-03-28 14:29:22 +0100 | [diff] [blame] | 2901 | struct wm_adsp_compr_buf *buf; |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2902 | int ret = 0; |
| 2903 | |
| 2904 | adsp_dbg(dsp, "Pointer request\n"); |
| 2905 | |
| 2906 | mutex_lock(&dsp->pwr_lock); |
| 2907 | |
Charles Keepax | 612047f | 2016-03-28 14:29:22 +0100 | [diff] [blame] | 2908 | buf = compr->buf; |
| 2909 | |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2910 | if (!compr->buf) { |
| 2911 | ret = -ENXIO; |
| 2912 | goto out; |
| 2913 | } |
| 2914 | |
| 2915 | if (compr->buf->error) { |
| 2916 | ret = -EIO; |
| 2917 | goto out; |
| 2918 | } |
| 2919 | |
| 2920 | if (buf->avail < wm_adsp_compr_frag_words(compr)) { |
| 2921 | ret = wm_adsp_buffer_update_avail(buf); |
| 2922 | if (ret < 0) { |
| 2923 | adsp_err(dsp, "Error reading avail: %d\n", ret); |
| 2924 | goto out; |
| 2925 | } |
| 2926 | |
| 2927 | /* |
| 2928 | * If we really have less than 1 fragment available tell the |
| 2929 | * DSP to inform us once a whole fragment is available. |
| 2930 | */ |
| 2931 | if (buf->avail < wm_adsp_compr_frag_words(compr)) { |
Charles Keepax | 5847609 | 2016-04-06 11:21:54 +0100 | [diff] [blame^] | 2932 | ret = wm_adsp_buffer_get_error(buf); |
| 2933 | if (ret < 0) |
| 2934 | goto out; |
| 2935 | |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2936 | ret = wm_adsp_buffer_reenable_irq(buf); |
| 2937 | if (ret < 0) { |
| 2938 | adsp_err(dsp, |
| 2939 | "Failed to re-enable buffer IRQ: %d\n", |
| 2940 | ret); |
| 2941 | goto out; |
| 2942 | } |
| 2943 | } |
| 2944 | } |
| 2945 | |
| 2946 | tstamp->copied_total = compr->copied_total; |
| 2947 | tstamp->copied_total += buf->avail * WM_ADSP_DATA_WORD_SIZE; |
Charles Keepax | da2b335 | 2016-02-02 16:41:36 +0000 | [diff] [blame] | 2948 | tstamp->sampling_rate = compr->sample_rate; |
Charles Keepax | 565ace4 | 2016-01-06 12:33:18 +0000 | [diff] [blame] | 2949 | |
| 2950 | out: |
| 2951 | mutex_unlock(&dsp->pwr_lock); |
| 2952 | |
| 2953 | return ret; |
| 2954 | } |
| 2955 | EXPORT_SYMBOL_GPL(wm_adsp_compr_pointer); |
| 2956 | |
Charles Keepax | 83a40ce | 2016-01-06 12:33:19 +0000 | [diff] [blame] | 2957 | static int wm_adsp_buffer_capture_block(struct wm_adsp_compr *compr, int target) |
| 2958 | { |
| 2959 | struct wm_adsp_compr_buf *buf = compr->buf; |
| 2960 | u8 *pack_in = (u8 *)compr->raw_buf; |
| 2961 | u8 *pack_out = (u8 *)compr->raw_buf; |
| 2962 | unsigned int adsp_addr; |
| 2963 | int mem_type, nwords, max_read; |
| 2964 | int i, j, ret; |
| 2965 | |
| 2966 | /* Calculate read parameters */ |
| 2967 | for (i = 0; i < wm_adsp_fw[buf->dsp->fw].caps->num_regions; ++i) |
| 2968 | if (buf->read_index < buf->regions[i].cumulative_size) |
| 2969 | break; |
| 2970 | |
| 2971 | if (i == wm_adsp_fw[buf->dsp->fw].caps->num_regions) |
| 2972 | return -EINVAL; |
| 2973 | |
| 2974 | mem_type = buf->regions[i].mem_type; |
| 2975 | adsp_addr = buf->regions[i].base_addr + |
| 2976 | (buf->read_index - buf->regions[i].offset); |
| 2977 | |
| 2978 | max_read = wm_adsp_compr_frag_words(compr); |
| 2979 | nwords = buf->regions[i].cumulative_size - buf->read_index; |
| 2980 | |
| 2981 | if (nwords > target) |
| 2982 | nwords = target; |
| 2983 | if (nwords > buf->avail) |
| 2984 | nwords = buf->avail; |
| 2985 | if (nwords > max_read) |
| 2986 | nwords = max_read; |
| 2987 | if (!nwords) |
| 2988 | return 0; |
| 2989 | |
| 2990 | /* Read data from DSP */ |
| 2991 | ret = wm_adsp_read_data_block(buf->dsp, mem_type, adsp_addr, |
| 2992 | nwords, compr->raw_buf); |
| 2993 | if (ret < 0) |
| 2994 | return ret; |
| 2995 | |
| 2996 | /* Remove the padding bytes from the data read from the DSP */ |
| 2997 | for (i = 0; i < nwords; i++) { |
| 2998 | for (j = 0; j < WM_ADSP_DATA_WORD_SIZE; j++) |
| 2999 | *pack_out++ = *pack_in++; |
| 3000 | |
| 3001 | pack_in += sizeof(*(compr->raw_buf)) - WM_ADSP_DATA_WORD_SIZE; |
| 3002 | } |
| 3003 | |
| 3004 | /* update read index to account for words read */ |
| 3005 | buf->read_index += nwords; |
| 3006 | if (buf->read_index == wm_adsp_buffer_size(buf)) |
| 3007 | buf->read_index = 0; |
| 3008 | |
| 3009 | ret = wm_adsp_buffer_write(buf, HOST_BUFFER_FIELD(next_read_index), |
| 3010 | buf->read_index); |
| 3011 | if (ret < 0) |
| 3012 | return ret; |
| 3013 | |
| 3014 | /* update avail to account for words read */ |
| 3015 | buf->avail -= nwords; |
| 3016 | |
| 3017 | return nwords; |
| 3018 | } |
| 3019 | |
| 3020 | static int wm_adsp_compr_read(struct wm_adsp_compr *compr, |
| 3021 | char __user *buf, size_t count) |
| 3022 | { |
| 3023 | struct wm_adsp *dsp = compr->dsp; |
| 3024 | int ntotal = 0; |
| 3025 | int nwords, nbytes; |
| 3026 | |
| 3027 | adsp_dbg(dsp, "Requested read of %zu bytes\n", count); |
| 3028 | |
| 3029 | if (!compr->buf) |
| 3030 | return -ENXIO; |
| 3031 | |
| 3032 | if (compr->buf->error) |
| 3033 | return -EIO; |
| 3034 | |
| 3035 | count /= WM_ADSP_DATA_WORD_SIZE; |
| 3036 | |
| 3037 | do { |
| 3038 | nwords = wm_adsp_buffer_capture_block(compr, count); |
| 3039 | if (nwords < 0) { |
| 3040 | adsp_err(dsp, "Failed to capture block: %d\n", nwords); |
| 3041 | return nwords; |
| 3042 | } |
| 3043 | |
| 3044 | nbytes = nwords * WM_ADSP_DATA_WORD_SIZE; |
| 3045 | |
| 3046 | adsp_dbg(dsp, "Read %d bytes\n", nbytes); |
| 3047 | |
| 3048 | if (copy_to_user(buf + ntotal, compr->raw_buf, nbytes)) { |
| 3049 | adsp_err(dsp, "Failed to copy data to user: %d, %d\n", |
| 3050 | ntotal, nbytes); |
| 3051 | return -EFAULT; |
| 3052 | } |
| 3053 | |
| 3054 | count -= nwords; |
| 3055 | ntotal += nbytes; |
| 3056 | } while (nwords > 0 && count > 0); |
| 3057 | |
| 3058 | compr->copied_total += ntotal; |
| 3059 | |
| 3060 | return ntotal; |
| 3061 | } |
| 3062 | |
| 3063 | int wm_adsp_compr_copy(struct snd_compr_stream *stream, char __user *buf, |
| 3064 | size_t count) |
| 3065 | { |
| 3066 | struct wm_adsp_compr *compr = stream->runtime->private_data; |
| 3067 | struct wm_adsp *dsp = compr->dsp; |
| 3068 | int ret; |
| 3069 | |
| 3070 | mutex_lock(&dsp->pwr_lock); |
| 3071 | |
| 3072 | if (stream->direction == SND_COMPRESS_CAPTURE) |
| 3073 | ret = wm_adsp_compr_read(compr, buf, count); |
| 3074 | else |
| 3075 | ret = -ENOTSUPP; |
| 3076 | |
| 3077 | mutex_unlock(&dsp->pwr_lock); |
| 3078 | |
| 3079 | return ret; |
| 3080 | } |
| 3081 | EXPORT_SYMBOL_GPL(wm_adsp_compr_copy); |
| 3082 | |
Praveen Diwakar | 0a37c6e | 2014-07-04 11:17:41 +0530 | [diff] [blame] | 3083 | MODULE_LICENSE("GPL v2"); |