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 | |
| 35 | #include <linux/mfd/arizona/registers.h> |
| 36 | |
Mark Brown | dc91428 | 2013-02-18 19:09:23 +0000 | [diff] [blame] | 37 | #include "arizona.h" |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 38 | #include "wm_adsp.h" |
| 39 | |
| 40 | #define adsp_crit(_dsp, fmt, ...) \ |
| 41 | dev_crit(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__) |
| 42 | #define adsp_err(_dsp, fmt, ...) \ |
| 43 | dev_err(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__) |
| 44 | #define adsp_warn(_dsp, fmt, ...) \ |
| 45 | dev_warn(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__) |
| 46 | #define adsp_info(_dsp, fmt, ...) \ |
| 47 | dev_info(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__) |
| 48 | #define adsp_dbg(_dsp, fmt, ...) \ |
| 49 | dev_dbg(_dsp->dev, "DSP%d: " fmt, _dsp->num, ##__VA_ARGS__) |
| 50 | |
| 51 | #define ADSP1_CONTROL_1 0x00 |
| 52 | #define ADSP1_CONTROL_2 0x02 |
| 53 | #define ADSP1_CONTROL_3 0x03 |
| 54 | #define ADSP1_CONTROL_4 0x04 |
| 55 | #define ADSP1_CONTROL_5 0x06 |
| 56 | #define ADSP1_CONTROL_6 0x07 |
| 57 | #define ADSP1_CONTROL_7 0x08 |
| 58 | #define ADSP1_CONTROL_8 0x09 |
| 59 | #define ADSP1_CONTROL_9 0x0A |
| 60 | #define ADSP1_CONTROL_10 0x0B |
| 61 | #define ADSP1_CONTROL_11 0x0C |
| 62 | #define ADSP1_CONTROL_12 0x0D |
| 63 | #define ADSP1_CONTROL_13 0x0F |
| 64 | #define ADSP1_CONTROL_14 0x10 |
| 65 | #define ADSP1_CONTROL_15 0x11 |
| 66 | #define ADSP1_CONTROL_16 0x12 |
| 67 | #define ADSP1_CONTROL_17 0x13 |
| 68 | #define ADSP1_CONTROL_18 0x14 |
| 69 | #define ADSP1_CONTROL_19 0x16 |
| 70 | #define ADSP1_CONTROL_20 0x17 |
| 71 | #define ADSP1_CONTROL_21 0x18 |
| 72 | #define ADSP1_CONTROL_22 0x1A |
| 73 | #define ADSP1_CONTROL_23 0x1B |
| 74 | #define ADSP1_CONTROL_24 0x1C |
| 75 | #define ADSP1_CONTROL_25 0x1E |
| 76 | #define ADSP1_CONTROL_26 0x20 |
| 77 | #define ADSP1_CONTROL_27 0x21 |
| 78 | #define ADSP1_CONTROL_28 0x22 |
| 79 | #define ADSP1_CONTROL_29 0x23 |
| 80 | #define ADSP1_CONTROL_30 0x24 |
| 81 | #define ADSP1_CONTROL_31 0x26 |
| 82 | |
| 83 | /* |
| 84 | * ADSP1 Control 19 |
| 85 | */ |
| 86 | #define ADSP1_WDMA_BUFFER_LENGTH_MASK 0x00FF /* DSP1_WDMA_BUFFER_LENGTH - [7:0] */ |
| 87 | #define ADSP1_WDMA_BUFFER_LENGTH_SHIFT 0 /* DSP1_WDMA_BUFFER_LENGTH - [7:0] */ |
| 88 | #define ADSP1_WDMA_BUFFER_LENGTH_WIDTH 8 /* DSP1_WDMA_BUFFER_LENGTH - [7:0] */ |
| 89 | |
| 90 | |
| 91 | /* |
| 92 | * ADSP1 Control 30 |
| 93 | */ |
| 94 | #define ADSP1_DBG_CLK_ENA 0x0008 /* DSP1_DBG_CLK_ENA */ |
| 95 | #define ADSP1_DBG_CLK_ENA_MASK 0x0008 /* DSP1_DBG_CLK_ENA */ |
| 96 | #define ADSP1_DBG_CLK_ENA_SHIFT 3 /* DSP1_DBG_CLK_ENA */ |
| 97 | #define ADSP1_DBG_CLK_ENA_WIDTH 1 /* DSP1_DBG_CLK_ENA */ |
| 98 | #define ADSP1_SYS_ENA 0x0004 /* DSP1_SYS_ENA */ |
| 99 | #define ADSP1_SYS_ENA_MASK 0x0004 /* DSP1_SYS_ENA */ |
| 100 | #define ADSP1_SYS_ENA_SHIFT 2 /* DSP1_SYS_ENA */ |
| 101 | #define ADSP1_SYS_ENA_WIDTH 1 /* DSP1_SYS_ENA */ |
| 102 | #define ADSP1_CORE_ENA 0x0002 /* DSP1_CORE_ENA */ |
| 103 | #define ADSP1_CORE_ENA_MASK 0x0002 /* DSP1_CORE_ENA */ |
| 104 | #define ADSP1_CORE_ENA_SHIFT 1 /* DSP1_CORE_ENA */ |
| 105 | #define ADSP1_CORE_ENA_WIDTH 1 /* DSP1_CORE_ENA */ |
| 106 | #define ADSP1_START 0x0001 /* DSP1_START */ |
| 107 | #define ADSP1_START_MASK 0x0001 /* DSP1_START */ |
| 108 | #define ADSP1_START_SHIFT 0 /* DSP1_START */ |
| 109 | #define ADSP1_START_WIDTH 1 /* DSP1_START */ |
| 110 | |
Chris Rattray | 94e205b | 2013-01-18 08:43:09 +0000 | [diff] [blame] | 111 | /* |
| 112 | * ADSP1 Control 31 |
| 113 | */ |
| 114 | #define ADSP1_CLK_SEL_MASK 0x0007 /* CLK_SEL_ENA */ |
| 115 | #define ADSP1_CLK_SEL_SHIFT 0 /* CLK_SEL_ENA */ |
| 116 | #define ADSP1_CLK_SEL_WIDTH 3 /* CLK_SEL_ENA */ |
| 117 | |
Mark Brown | 2d30b57 | 2013-01-28 20:18:17 +0800 | [diff] [blame] | 118 | #define ADSP2_CONTROL 0x0 |
| 119 | #define ADSP2_CLOCKING 0x1 |
| 120 | #define ADSP2_STATUS1 0x4 |
| 121 | #define ADSP2_WDMA_CONFIG_1 0x30 |
| 122 | #define ADSP2_WDMA_CONFIG_2 0x31 |
| 123 | #define ADSP2_RDMA_CONFIG_1 0x34 |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 124 | |
Richard Fitzgerald | 10337b0 | 2015-05-29 10:23:07 +0100 | [diff] [blame] | 125 | #define ADSP2_SCRATCH0 0x40 |
| 126 | #define ADSP2_SCRATCH1 0x41 |
| 127 | #define ADSP2_SCRATCH2 0x42 |
| 128 | #define ADSP2_SCRATCH3 0x43 |
| 129 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 130 | /* |
| 131 | * ADSP2 Control |
| 132 | */ |
| 133 | |
| 134 | #define ADSP2_MEM_ENA 0x0010 /* DSP1_MEM_ENA */ |
| 135 | #define ADSP2_MEM_ENA_MASK 0x0010 /* DSP1_MEM_ENA */ |
| 136 | #define ADSP2_MEM_ENA_SHIFT 4 /* DSP1_MEM_ENA */ |
| 137 | #define ADSP2_MEM_ENA_WIDTH 1 /* DSP1_MEM_ENA */ |
| 138 | #define ADSP2_SYS_ENA 0x0004 /* DSP1_SYS_ENA */ |
| 139 | #define ADSP2_SYS_ENA_MASK 0x0004 /* DSP1_SYS_ENA */ |
| 140 | #define ADSP2_SYS_ENA_SHIFT 2 /* DSP1_SYS_ENA */ |
| 141 | #define ADSP2_SYS_ENA_WIDTH 1 /* DSP1_SYS_ENA */ |
| 142 | #define ADSP2_CORE_ENA 0x0002 /* DSP1_CORE_ENA */ |
| 143 | #define ADSP2_CORE_ENA_MASK 0x0002 /* DSP1_CORE_ENA */ |
| 144 | #define ADSP2_CORE_ENA_SHIFT 1 /* DSP1_CORE_ENA */ |
| 145 | #define ADSP2_CORE_ENA_WIDTH 1 /* DSP1_CORE_ENA */ |
| 146 | #define ADSP2_START 0x0001 /* DSP1_START */ |
| 147 | #define ADSP2_START_MASK 0x0001 /* DSP1_START */ |
| 148 | #define ADSP2_START_SHIFT 0 /* DSP1_START */ |
| 149 | #define ADSP2_START_WIDTH 1 /* DSP1_START */ |
| 150 | |
| 151 | /* |
Mark Brown | 973838a | 2012-11-28 17:20:32 +0000 | [diff] [blame] | 152 | * ADSP2 clocking |
| 153 | */ |
| 154 | #define ADSP2_CLK_SEL_MASK 0x0007 /* CLK_SEL_ENA */ |
| 155 | #define ADSP2_CLK_SEL_SHIFT 0 /* CLK_SEL_ENA */ |
| 156 | #define ADSP2_CLK_SEL_WIDTH 3 /* CLK_SEL_ENA */ |
| 157 | |
| 158 | /* |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 159 | * ADSP2 Status 1 |
| 160 | */ |
| 161 | #define ADSP2_RAM_RDY 0x0001 |
| 162 | #define ADSP2_RAM_RDY_MASK 0x0001 |
| 163 | #define ADSP2_RAM_RDY_SHIFT 0 |
| 164 | #define ADSP2_RAM_RDY_WIDTH 1 |
| 165 | |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 166 | struct wm_adsp_buf { |
| 167 | struct list_head list; |
| 168 | void *buf; |
| 169 | }; |
| 170 | |
| 171 | static struct wm_adsp_buf *wm_adsp_buf_alloc(const void *src, size_t len, |
| 172 | struct list_head *list) |
| 173 | { |
| 174 | struct wm_adsp_buf *buf = kzalloc(sizeof(*buf), GFP_KERNEL); |
| 175 | |
| 176 | if (buf == NULL) |
| 177 | return NULL; |
| 178 | |
Charles Keepax | cdcd7f7 | 2014-11-14 15:40:45 +0000 | [diff] [blame] | 179 | buf->buf = vmalloc(len); |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 180 | if (!buf->buf) { |
Charles Keepax | cdcd7f7 | 2014-11-14 15:40:45 +0000 | [diff] [blame] | 181 | vfree(buf); |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 182 | return NULL; |
| 183 | } |
Charles Keepax | cdcd7f7 | 2014-11-14 15:40:45 +0000 | [diff] [blame] | 184 | memcpy(buf->buf, src, len); |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 185 | |
| 186 | if (list) |
| 187 | list_add_tail(&buf->list, list); |
| 188 | |
| 189 | return buf; |
| 190 | } |
| 191 | |
| 192 | static void wm_adsp_buf_free(struct list_head *list) |
| 193 | { |
| 194 | while (!list_empty(list)) { |
| 195 | struct wm_adsp_buf *buf = list_first_entry(list, |
| 196 | struct wm_adsp_buf, |
| 197 | list); |
| 198 | list_del(&buf->list); |
Charles Keepax | cdcd7f7 | 2014-11-14 15:40:45 +0000 | [diff] [blame] | 199 | vfree(buf->buf); |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 200 | kfree(buf); |
| 201 | } |
| 202 | } |
| 203 | |
Charles Keepax | 04d1300 | 2015-11-26 14:01:52 +0000 | [diff] [blame] | 204 | #define WM_ADSP_FW_MBC_VSS 0 |
| 205 | #define WM_ADSP_FW_HIFI 1 |
| 206 | #define WM_ADSP_FW_TX 2 |
| 207 | #define WM_ADSP_FW_TX_SPK 3 |
| 208 | #define WM_ADSP_FW_RX 4 |
| 209 | #define WM_ADSP_FW_RX_ANC 5 |
| 210 | #define WM_ADSP_FW_CTRL 6 |
| 211 | #define WM_ADSP_FW_ASR 7 |
| 212 | #define WM_ADSP_FW_TRACE 8 |
| 213 | #define WM_ADSP_FW_SPK_PROT 9 |
| 214 | #define WM_ADSP_FW_MISC 10 |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 215 | |
Charles Keepax | 04d1300 | 2015-11-26 14:01:52 +0000 | [diff] [blame] | 216 | #define WM_ADSP_NUM_FW 11 |
Mark Brown | dd84f92 | 2013-03-08 15:25:58 +0800 | [diff] [blame] | 217 | |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 218 | static const char *wm_adsp_fw_text[WM_ADSP_NUM_FW] = { |
Charles Keepax | 04d1300 | 2015-11-26 14:01:52 +0000 | [diff] [blame] | 219 | [WM_ADSP_FW_MBC_VSS] = "MBC/VSS", |
| 220 | [WM_ADSP_FW_HIFI] = "MasterHiFi", |
| 221 | [WM_ADSP_FW_TX] = "Tx", |
| 222 | [WM_ADSP_FW_TX_SPK] = "Tx Speaker", |
| 223 | [WM_ADSP_FW_RX] = "Rx", |
| 224 | [WM_ADSP_FW_RX_ANC] = "Rx ANC", |
| 225 | [WM_ADSP_FW_CTRL] = "Voice Ctrl", |
| 226 | [WM_ADSP_FW_ASR] = "ASR Assist", |
| 227 | [WM_ADSP_FW_TRACE] = "Dbg Trace", |
| 228 | [WM_ADSP_FW_SPK_PROT] = "Protection", |
| 229 | [WM_ADSP_FW_MISC] = "Misc", |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 230 | }; |
| 231 | |
| 232 | static struct { |
| 233 | const char *file; |
| 234 | } wm_adsp_fw[WM_ADSP_NUM_FW] = { |
Charles Keepax | 04d1300 | 2015-11-26 14:01:52 +0000 | [diff] [blame] | 235 | [WM_ADSP_FW_MBC_VSS] = { .file = "mbc-vss" }, |
| 236 | [WM_ADSP_FW_HIFI] = { .file = "hifi" }, |
| 237 | [WM_ADSP_FW_TX] = { .file = "tx" }, |
| 238 | [WM_ADSP_FW_TX_SPK] = { .file = "tx-spk" }, |
| 239 | [WM_ADSP_FW_RX] = { .file = "rx" }, |
| 240 | [WM_ADSP_FW_RX_ANC] = { .file = "rx-anc" }, |
| 241 | [WM_ADSP_FW_CTRL] = { .file = "ctrl" }, |
| 242 | [WM_ADSP_FW_ASR] = { .file = "asr" }, |
| 243 | [WM_ADSP_FW_TRACE] = { .file = "trace" }, |
| 244 | [WM_ADSP_FW_SPK_PROT] = { .file = "spk-prot" }, |
| 245 | [WM_ADSP_FW_MISC] = { .file = "misc" }, |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 246 | }; |
| 247 | |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 248 | struct wm_coeff_ctl_ops { |
| 249 | int (*xget)(struct snd_kcontrol *kcontrol, |
| 250 | struct snd_ctl_elem_value *ucontrol); |
| 251 | int (*xput)(struct snd_kcontrol *kcontrol, |
| 252 | struct snd_ctl_elem_value *ucontrol); |
| 253 | int (*xinfo)(struct snd_kcontrol *kcontrol, |
| 254 | struct snd_ctl_elem_info *uinfo); |
| 255 | }; |
| 256 | |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 257 | struct wm_coeff_ctl { |
| 258 | const char *name; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 259 | const char *fw_name; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 260 | struct wm_adsp_alg_region alg_region; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 261 | struct wm_coeff_ctl_ops ops; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 262 | struct wm_adsp *dsp; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 263 | unsigned int enabled:1; |
| 264 | struct list_head list; |
| 265 | void *cache; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 266 | unsigned int offset; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 267 | size_t len; |
Dimitris Papastamos | 0c2e3f3 | 2013-05-28 12:01:50 +0100 | [diff] [blame] | 268 | unsigned int set:1; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 269 | struct snd_kcontrol *kcontrol; |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 270 | unsigned int flags; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 271 | }; |
| 272 | |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 273 | #ifdef CONFIG_DEBUG_FS |
| 274 | static void wm_adsp_debugfs_save_wmfwname(struct wm_adsp *dsp, const char *s) |
| 275 | { |
| 276 | char *tmp = kasprintf(GFP_KERNEL, "%s\n", s); |
| 277 | |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 278 | kfree(dsp->wmfw_file_name); |
| 279 | dsp->wmfw_file_name = tmp; |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static void wm_adsp_debugfs_save_binname(struct wm_adsp *dsp, const char *s) |
| 283 | { |
| 284 | char *tmp = kasprintf(GFP_KERNEL, "%s\n", s); |
| 285 | |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 286 | kfree(dsp->bin_file_name); |
| 287 | dsp->bin_file_name = tmp; |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | static void wm_adsp_debugfs_clear(struct wm_adsp *dsp) |
| 291 | { |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 292 | kfree(dsp->wmfw_file_name); |
| 293 | kfree(dsp->bin_file_name); |
| 294 | dsp->wmfw_file_name = NULL; |
| 295 | dsp->bin_file_name = NULL; |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static ssize_t wm_adsp_debugfs_wmfw_read(struct file *file, |
| 299 | char __user *user_buf, |
| 300 | size_t count, loff_t *ppos) |
| 301 | { |
| 302 | struct wm_adsp *dsp = file->private_data; |
| 303 | ssize_t ret; |
| 304 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 305 | mutex_lock(&dsp->pwr_lock); |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 306 | |
| 307 | if (!dsp->wmfw_file_name || !dsp->running) |
| 308 | ret = 0; |
| 309 | else |
| 310 | ret = simple_read_from_buffer(user_buf, count, ppos, |
| 311 | dsp->wmfw_file_name, |
| 312 | strlen(dsp->wmfw_file_name)); |
| 313 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 314 | mutex_unlock(&dsp->pwr_lock); |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 315 | return ret; |
| 316 | } |
| 317 | |
| 318 | static ssize_t wm_adsp_debugfs_bin_read(struct file *file, |
| 319 | char __user *user_buf, |
| 320 | size_t count, loff_t *ppos) |
| 321 | { |
| 322 | struct wm_adsp *dsp = file->private_data; |
| 323 | ssize_t ret; |
| 324 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 325 | mutex_lock(&dsp->pwr_lock); |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 326 | |
| 327 | if (!dsp->bin_file_name || !dsp->running) |
| 328 | ret = 0; |
| 329 | else |
| 330 | ret = simple_read_from_buffer(user_buf, count, ppos, |
| 331 | dsp->bin_file_name, |
| 332 | strlen(dsp->bin_file_name)); |
| 333 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 334 | mutex_unlock(&dsp->pwr_lock); |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 335 | return ret; |
| 336 | } |
| 337 | |
| 338 | static const struct { |
| 339 | const char *name; |
| 340 | const struct file_operations fops; |
| 341 | } wm_adsp_debugfs_fops[] = { |
| 342 | { |
| 343 | .name = "wmfw_file_name", |
| 344 | .fops = { |
| 345 | .open = simple_open, |
| 346 | .read = wm_adsp_debugfs_wmfw_read, |
| 347 | }, |
| 348 | }, |
| 349 | { |
| 350 | .name = "bin_file_name", |
| 351 | .fops = { |
| 352 | .open = simple_open, |
| 353 | .read = wm_adsp_debugfs_bin_read, |
| 354 | }, |
| 355 | }, |
| 356 | }; |
| 357 | |
| 358 | static void wm_adsp2_init_debugfs(struct wm_adsp *dsp, |
| 359 | struct snd_soc_codec *codec) |
| 360 | { |
| 361 | struct dentry *root = NULL; |
| 362 | char *root_name; |
| 363 | int i; |
| 364 | |
| 365 | if (!codec->component.debugfs_root) { |
| 366 | adsp_err(dsp, "No codec debugfs root\n"); |
| 367 | goto err; |
| 368 | } |
| 369 | |
| 370 | root_name = kmalloc(PAGE_SIZE, GFP_KERNEL); |
| 371 | if (!root_name) |
| 372 | goto err; |
| 373 | |
| 374 | snprintf(root_name, PAGE_SIZE, "dsp%d", dsp->num); |
| 375 | root = debugfs_create_dir(root_name, codec->component.debugfs_root); |
| 376 | kfree(root_name); |
| 377 | |
| 378 | if (!root) |
| 379 | goto err; |
| 380 | |
| 381 | if (!debugfs_create_bool("running", S_IRUGO, root, &dsp->running)) |
| 382 | goto err; |
| 383 | |
| 384 | if (!debugfs_create_x32("fw_id", S_IRUGO, root, &dsp->fw_id)) |
| 385 | goto err; |
| 386 | |
| 387 | if (!debugfs_create_x32("fw_version", S_IRUGO, root, |
| 388 | &dsp->fw_id_version)) |
| 389 | goto err; |
| 390 | |
| 391 | for (i = 0; i < ARRAY_SIZE(wm_adsp_debugfs_fops); ++i) { |
| 392 | if (!debugfs_create_file(wm_adsp_debugfs_fops[i].name, |
| 393 | S_IRUGO, root, dsp, |
| 394 | &wm_adsp_debugfs_fops[i].fops)) |
| 395 | goto err; |
| 396 | } |
| 397 | |
| 398 | dsp->debugfs_root = root; |
| 399 | return; |
| 400 | |
| 401 | err: |
| 402 | debugfs_remove_recursive(root); |
| 403 | adsp_err(dsp, "Failed to create debugfs\n"); |
| 404 | } |
| 405 | |
| 406 | static void wm_adsp2_cleanup_debugfs(struct wm_adsp *dsp) |
| 407 | { |
| 408 | wm_adsp_debugfs_clear(dsp); |
| 409 | debugfs_remove_recursive(dsp->debugfs_root); |
| 410 | } |
| 411 | #else |
| 412 | static inline void wm_adsp2_init_debugfs(struct wm_adsp *dsp, |
| 413 | struct snd_soc_codec *codec) |
| 414 | { |
| 415 | } |
| 416 | |
| 417 | static inline void wm_adsp2_cleanup_debugfs(struct wm_adsp *dsp) |
| 418 | { |
| 419 | } |
| 420 | |
| 421 | static inline void wm_adsp_debugfs_save_wmfwname(struct wm_adsp *dsp, |
| 422 | const char *s) |
| 423 | { |
| 424 | } |
| 425 | |
| 426 | static inline void wm_adsp_debugfs_save_binname(struct wm_adsp *dsp, |
| 427 | const char *s) |
| 428 | { |
| 429 | } |
| 430 | |
| 431 | static inline void wm_adsp_debugfs_clear(struct wm_adsp *dsp) |
| 432 | { |
| 433 | } |
| 434 | #endif |
| 435 | |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 436 | static int wm_adsp_fw_get(struct snd_kcontrol *kcontrol, |
| 437 | struct snd_ctl_elem_value *ucontrol) |
| 438 | { |
Lars-Peter Clausen | ea53bf7 | 2014-03-18 09:02:04 +0100 | [diff] [blame] | 439 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 440 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 441 | struct wm_adsp *dsp = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 442 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 443 | ucontrol->value.integer.value[0] = dsp[e->shift_l].fw; |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 444 | |
| 445 | return 0; |
| 446 | } |
| 447 | |
| 448 | static int wm_adsp_fw_put(struct snd_kcontrol *kcontrol, |
| 449 | struct snd_ctl_elem_value *ucontrol) |
| 450 | { |
Lars-Peter Clausen | ea53bf7 | 2014-03-18 09:02:04 +0100 | [diff] [blame] | 451 | struct snd_soc_codec *codec = snd_soc_kcontrol_codec(kcontrol); |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 452 | struct soc_enum *e = (struct soc_enum *)kcontrol->private_value; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 453 | struct wm_adsp *dsp = snd_soc_codec_get_drvdata(codec); |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 454 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 455 | if (ucontrol->value.integer.value[0] == dsp[e->shift_l].fw) |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 456 | return 0; |
| 457 | |
| 458 | if (ucontrol->value.integer.value[0] >= WM_ADSP_NUM_FW) |
| 459 | return -EINVAL; |
| 460 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 461 | if (dsp[e->shift_l].running) |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 462 | return -EBUSY; |
| 463 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 464 | dsp[e->shift_l].fw = ucontrol->value.integer.value[0]; |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 465 | |
| 466 | return 0; |
| 467 | } |
| 468 | |
| 469 | static const struct soc_enum wm_adsp_fw_enum[] = { |
| 470 | SOC_ENUM_SINGLE(0, 0, ARRAY_SIZE(wm_adsp_fw_text), wm_adsp_fw_text), |
| 471 | SOC_ENUM_SINGLE(0, 1, ARRAY_SIZE(wm_adsp_fw_text), wm_adsp_fw_text), |
| 472 | SOC_ENUM_SINGLE(0, 2, ARRAY_SIZE(wm_adsp_fw_text), wm_adsp_fw_text), |
| 473 | SOC_ENUM_SINGLE(0, 3, ARRAY_SIZE(wm_adsp_fw_text), wm_adsp_fw_text), |
| 474 | }; |
| 475 | |
Richard Fitzgerald | 336d044 | 2015-06-18 13:43:19 +0100 | [diff] [blame] | 476 | const struct snd_kcontrol_new wm_adsp_fw_controls[] = { |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 477 | SOC_ENUM_EXT("DSP1 Firmware", wm_adsp_fw_enum[0], |
| 478 | wm_adsp_fw_get, wm_adsp_fw_put), |
| 479 | SOC_ENUM_EXT("DSP2 Firmware", wm_adsp_fw_enum[1], |
| 480 | wm_adsp_fw_get, wm_adsp_fw_put), |
| 481 | SOC_ENUM_EXT("DSP3 Firmware", wm_adsp_fw_enum[2], |
| 482 | wm_adsp_fw_get, wm_adsp_fw_put), |
Richard Fitzgerald | 336d044 | 2015-06-18 13:43:19 +0100 | [diff] [blame] | 483 | SOC_ENUM_EXT("DSP4 Firmware", wm_adsp_fw_enum[3], |
| 484 | wm_adsp_fw_get, wm_adsp_fw_put), |
Mark Brown | b6ed61cf | 2013-03-29 18:00:24 +0000 | [diff] [blame] | 485 | }; |
Richard Fitzgerald | 336d044 | 2015-06-18 13:43:19 +0100 | [diff] [blame] | 486 | EXPORT_SYMBOL_GPL(wm_adsp_fw_controls); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 487 | |
| 488 | static struct wm_adsp_region const *wm_adsp_find_region(struct wm_adsp *dsp, |
| 489 | int type) |
| 490 | { |
| 491 | int i; |
| 492 | |
| 493 | for (i = 0; i < dsp->num_mems; i++) |
| 494 | if (dsp->mem[i].type == type) |
| 495 | return &dsp->mem[i]; |
| 496 | |
| 497 | return NULL; |
| 498 | } |
| 499 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 500 | 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] | 501 | unsigned int offset) |
| 502 | { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 503 | if (WARN_ON(!mem)) |
Takashi Iwai | 6c452bd | 2013-11-05 18:40:00 +0100 | [diff] [blame] | 504 | return offset; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 505 | switch (mem->type) { |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 506 | case WMFW_ADSP1_PM: |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 507 | return mem->base + (offset * 3); |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 508 | case WMFW_ADSP1_DM: |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 509 | return mem->base + (offset * 2); |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 510 | case WMFW_ADSP2_XM: |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 511 | return mem->base + (offset * 2); |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 512 | case WMFW_ADSP2_YM: |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 513 | return mem->base + (offset * 2); |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 514 | case WMFW_ADSP1_ZM: |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 515 | return mem->base + (offset * 2); |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 516 | default: |
Takashi Iwai | 6c452bd | 2013-11-05 18:40:00 +0100 | [diff] [blame] | 517 | WARN(1, "Unknown memory region type"); |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 518 | return offset; |
| 519 | } |
| 520 | } |
| 521 | |
Richard Fitzgerald | 10337b0 | 2015-05-29 10:23:07 +0100 | [diff] [blame] | 522 | static void wm_adsp2_show_fw_status(struct wm_adsp *dsp) |
| 523 | { |
| 524 | u16 scratch[4]; |
| 525 | int ret; |
| 526 | |
| 527 | ret = regmap_raw_read(dsp->regmap, dsp->base + ADSP2_SCRATCH0, |
| 528 | scratch, sizeof(scratch)); |
| 529 | if (ret) { |
| 530 | adsp_err(dsp, "Failed to read SCRATCH regs: %d\n", ret); |
| 531 | return; |
| 532 | } |
| 533 | |
| 534 | adsp_dbg(dsp, "FW SCRATCH 0:0x%x 1:0x%x 2:0x%x 3:0x%x\n", |
| 535 | be16_to_cpu(scratch[0]), |
| 536 | be16_to_cpu(scratch[1]), |
| 537 | be16_to_cpu(scratch[2]), |
| 538 | be16_to_cpu(scratch[3])); |
| 539 | } |
| 540 | |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 541 | static int wm_coeff_info(struct snd_kcontrol *kcontrol, |
| 542 | struct snd_ctl_elem_info *uinfo) |
| 543 | { |
| 544 | struct wm_coeff_ctl *ctl = (struct wm_coeff_ctl *)kcontrol->private_value; |
| 545 | |
| 546 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; |
| 547 | uinfo->count = ctl->len; |
| 548 | return 0; |
| 549 | } |
| 550 | |
Charles Keepax | c9f8dd7 | 2015-04-13 13:27:58 +0100 | [diff] [blame] | 551 | static int wm_coeff_write_control(struct wm_coeff_ctl *ctl, |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 552 | const void *buf, size_t len) |
| 553 | { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 554 | struct wm_adsp_alg_region *alg_region = &ctl->alg_region; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 555 | const struct wm_adsp_region *mem; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 556 | struct wm_adsp *dsp = ctl->dsp; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 557 | void *scratch; |
| 558 | int ret; |
| 559 | unsigned int reg; |
| 560 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 561 | mem = wm_adsp_find_region(dsp, alg_region->type); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 562 | if (!mem) { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 563 | adsp_err(dsp, "No base for region %x\n", |
| 564 | alg_region->type); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 565 | return -EINVAL; |
| 566 | } |
| 567 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 568 | reg = ctl->alg_region.base + ctl->offset; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 569 | reg = wm_adsp_region_to_reg(mem, reg); |
| 570 | |
| 571 | scratch = kmemdup(buf, ctl->len, GFP_KERNEL | GFP_DMA); |
| 572 | if (!scratch) |
| 573 | return -ENOMEM; |
| 574 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 575 | ret = regmap_raw_write(dsp->regmap, reg, scratch, |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 576 | ctl->len); |
| 577 | if (ret) { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 578 | adsp_err(dsp, "Failed to write %zu bytes to %x: %d\n", |
Dimitris Papastamos | 43bc3bf | 2013-11-01 15:56:52 +0000 | [diff] [blame] | 579 | ctl->len, reg, ret); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 580 | kfree(scratch); |
| 581 | return ret; |
| 582 | } |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 583 | adsp_dbg(dsp, "Wrote %zu bytes to %x\n", ctl->len, reg); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 584 | |
| 585 | kfree(scratch); |
| 586 | |
| 587 | return 0; |
| 588 | } |
| 589 | |
| 590 | static int wm_coeff_put(struct snd_kcontrol *kcontrol, |
| 591 | struct snd_ctl_elem_value *ucontrol) |
| 592 | { |
| 593 | struct wm_coeff_ctl *ctl = (struct wm_coeff_ctl *)kcontrol->private_value; |
| 594 | char *p = ucontrol->value.bytes.data; |
| 595 | |
| 596 | memcpy(ctl->cache, p, ctl->len); |
| 597 | |
Nikesh Oswal | 65d17a9 | 2015-02-16 15:25:48 +0000 | [diff] [blame] | 598 | ctl->set = 1; |
| 599 | if (!ctl->enabled) |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 600 | return 0; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 601 | |
Charles Keepax | c9f8dd7 | 2015-04-13 13:27:58 +0100 | [diff] [blame] | 602 | return wm_coeff_write_control(ctl, p, ctl->len); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 603 | } |
| 604 | |
Charles Keepax | c9f8dd7 | 2015-04-13 13:27:58 +0100 | [diff] [blame] | 605 | static int wm_coeff_read_control(struct wm_coeff_ctl *ctl, |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 606 | void *buf, size_t len) |
| 607 | { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 608 | struct wm_adsp_alg_region *alg_region = &ctl->alg_region; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 609 | const struct wm_adsp_region *mem; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 610 | struct wm_adsp *dsp = ctl->dsp; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 611 | void *scratch; |
| 612 | int ret; |
| 613 | unsigned int reg; |
| 614 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 615 | mem = wm_adsp_find_region(dsp, alg_region->type); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 616 | if (!mem) { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 617 | adsp_err(dsp, "No base for region %x\n", |
| 618 | alg_region->type); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 619 | return -EINVAL; |
| 620 | } |
| 621 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 622 | reg = ctl->alg_region.base + ctl->offset; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 623 | reg = wm_adsp_region_to_reg(mem, reg); |
| 624 | |
| 625 | scratch = kmalloc(ctl->len, GFP_KERNEL | GFP_DMA); |
| 626 | if (!scratch) |
| 627 | return -ENOMEM; |
| 628 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 629 | ret = regmap_raw_read(dsp->regmap, reg, scratch, ctl->len); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 630 | if (ret) { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 631 | adsp_err(dsp, "Failed to read %zu bytes from %x: %d\n", |
Dimitris Papastamos | 43bc3bf | 2013-11-01 15:56:52 +0000 | [diff] [blame] | 632 | ctl->len, reg, ret); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 633 | kfree(scratch); |
| 634 | return ret; |
| 635 | } |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 636 | adsp_dbg(dsp, "Read %zu bytes from %x\n", ctl->len, reg); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 637 | |
| 638 | memcpy(buf, scratch, ctl->len); |
| 639 | kfree(scratch); |
| 640 | |
| 641 | return 0; |
| 642 | } |
| 643 | |
| 644 | static int wm_coeff_get(struct snd_kcontrol *kcontrol, |
| 645 | struct snd_ctl_elem_value *ucontrol) |
| 646 | { |
| 647 | struct wm_coeff_ctl *ctl = (struct wm_coeff_ctl *)kcontrol->private_value; |
| 648 | char *p = ucontrol->value.bytes.data; |
| 649 | |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 650 | if (ctl->flags & WMFW_CTL_FLAG_VOLATILE) { |
| 651 | if (ctl->enabled) |
| 652 | return wm_coeff_read_control(ctl, p, ctl->len); |
| 653 | else |
| 654 | return -EPERM; |
| 655 | } |
| 656 | |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 657 | memcpy(p, ctl->cache, ctl->len); |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 658 | |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 659 | return 0; |
| 660 | } |
| 661 | |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 662 | struct wmfw_ctl_work { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 663 | struct wm_adsp *dsp; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 664 | struct wm_coeff_ctl *ctl; |
| 665 | struct work_struct work; |
| 666 | }; |
| 667 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 668 | 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] | 669 | { |
| 670 | struct snd_kcontrol_new *kcontrol; |
| 671 | int ret; |
| 672 | |
Dimitris Papastamos | 92bb4c3 | 2013-08-01 11:11:28 +0100 | [diff] [blame] | 673 | if (!ctl || !ctl->name) |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 674 | return -EINVAL; |
| 675 | |
| 676 | kcontrol = kzalloc(sizeof(*kcontrol), GFP_KERNEL); |
| 677 | if (!kcontrol) |
| 678 | return -ENOMEM; |
| 679 | kcontrol->iface = SNDRV_CTL_ELEM_IFACE_MIXER; |
| 680 | |
| 681 | kcontrol->name = ctl->name; |
| 682 | kcontrol->info = wm_coeff_info; |
| 683 | kcontrol->get = wm_coeff_get; |
| 684 | kcontrol->put = wm_coeff_put; |
| 685 | kcontrol->private_value = (unsigned long)ctl; |
| 686 | |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 687 | if (ctl->flags) { |
| 688 | if (ctl->flags & WMFW_CTL_FLAG_WRITEABLE) |
| 689 | kcontrol->access |= SNDRV_CTL_ELEM_ACCESS_WRITE; |
| 690 | if (ctl->flags & WMFW_CTL_FLAG_READABLE) |
| 691 | kcontrol->access |= SNDRV_CTL_ELEM_ACCESS_READ; |
| 692 | if (ctl->flags & WMFW_CTL_FLAG_VOLATILE) |
| 693 | kcontrol->access |= SNDRV_CTL_ELEM_ACCESS_VOLATILE; |
| 694 | } |
| 695 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 696 | ret = snd_soc_add_card_controls(dsp->card, |
Dimitris Papastamos | 81ad93e | 2013-07-29 13:51:59 +0100 | [diff] [blame] | 697 | kcontrol, 1); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 698 | if (ret < 0) |
| 699 | goto err_kcontrol; |
| 700 | |
| 701 | kfree(kcontrol); |
| 702 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 703 | ctl->kcontrol = snd_soc_card_get_kcontrol(dsp->card, |
Dimitris Papastamos | 81ad93e | 2013-07-29 13:51:59 +0100 | [diff] [blame] | 704 | ctl->name); |
| 705 | |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 706 | return 0; |
| 707 | |
| 708 | err_kcontrol: |
| 709 | kfree(kcontrol); |
| 710 | return ret; |
| 711 | } |
| 712 | |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 713 | static int wm_coeff_init_control_caches(struct wm_adsp *dsp) |
| 714 | { |
| 715 | struct wm_coeff_ctl *ctl; |
| 716 | int ret; |
| 717 | |
| 718 | list_for_each_entry(ctl, &dsp->ctl_list, list) { |
| 719 | if (!ctl->enabled || ctl->set) |
| 720 | continue; |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 721 | if (ctl->flags & WMFW_CTL_FLAG_VOLATILE) |
| 722 | continue; |
| 723 | |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 724 | ret = wm_coeff_read_control(ctl, |
| 725 | ctl->cache, |
| 726 | ctl->len); |
| 727 | if (ret < 0) |
| 728 | return ret; |
| 729 | } |
| 730 | |
| 731 | return 0; |
| 732 | } |
| 733 | |
| 734 | static int wm_coeff_sync_controls(struct wm_adsp *dsp) |
| 735 | { |
| 736 | struct wm_coeff_ctl *ctl; |
| 737 | int ret; |
| 738 | |
| 739 | list_for_each_entry(ctl, &dsp->ctl_list, list) { |
| 740 | if (!ctl->enabled) |
| 741 | continue; |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 742 | if (ctl->set && !(ctl->flags & WMFW_CTL_FLAG_VOLATILE)) { |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 743 | ret = wm_coeff_write_control(ctl, |
| 744 | ctl->cache, |
| 745 | ctl->len); |
| 746 | if (ret < 0) |
| 747 | return ret; |
| 748 | } |
| 749 | } |
| 750 | |
| 751 | return 0; |
| 752 | } |
| 753 | |
| 754 | static void wm_adsp_ctl_work(struct work_struct *work) |
| 755 | { |
| 756 | struct wmfw_ctl_work *ctl_work = container_of(work, |
| 757 | struct wmfw_ctl_work, |
| 758 | work); |
| 759 | |
| 760 | wmfw_add_ctl(ctl_work->dsp, ctl_work->ctl); |
| 761 | kfree(ctl_work); |
| 762 | } |
| 763 | |
| 764 | static int wm_adsp_create_control(struct wm_adsp *dsp, |
| 765 | const struct wm_adsp_alg_region *alg_region, |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 766 | unsigned int offset, unsigned int len, |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 767 | const char *subname, unsigned int subname_len, |
| 768 | unsigned int flags) |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 769 | { |
| 770 | struct wm_coeff_ctl *ctl; |
| 771 | struct wmfw_ctl_work *ctl_work; |
| 772 | char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; |
| 773 | char *region_name; |
| 774 | int ret; |
| 775 | |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 776 | if (flags & WMFW_CTL_FLAG_SYS) |
| 777 | return 0; |
| 778 | |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 779 | switch (alg_region->type) { |
| 780 | case WMFW_ADSP1_PM: |
| 781 | region_name = "PM"; |
| 782 | break; |
| 783 | case WMFW_ADSP1_DM: |
| 784 | region_name = "DM"; |
| 785 | break; |
| 786 | case WMFW_ADSP2_XM: |
| 787 | region_name = "XM"; |
| 788 | break; |
| 789 | case WMFW_ADSP2_YM: |
| 790 | region_name = "YM"; |
| 791 | break; |
| 792 | case WMFW_ADSP1_ZM: |
| 793 | region_name = "ZM"; |
| 794 | break; |
| 795 | default: |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 796 | adsp_err(dsp, "Unknown region type: %d\n", alg_region->type); |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 797 | return -EINVAL; |
| 798 | } |
| 799 | |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 800 | switch (dsp->fw_ver) { |
| 801 | case 0: |
| 802 | case 1: |
| 803 | snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, "DSP%d %s %x", |
| 804 | dsp->num, region_name, alg_region->alg); |
| 805 | break; |
| 806 | default: |
| 807 | ret = snprintf(name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN, |
| 808 | "DSP%d%c %.12s %x", dsp->num, *region_name, |
| 809 | wm_adsp_fw_text[dsp->fw], alg_region->alg); |
| 810 | |
| 811 | /* Truncate the subname from the start if it is too long */ |
| 812 | if (subname) { |
| 813 | int avail = SNDRV_CTL_ELEM_ID_NAME_MAXLEN - ret - 2; |
| 814 | int skip = 0; |
| 815 | |
| 816 | if (subname_len > avail) |
| 817 | skip = subname_len - avail; |
| 818 | |
| 819 | snprintf(name + ret, |
| 820 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN - ret, " %.*s", |
| 821 | subname_len - skip, subname + skip); |
| 822 | } |
| 823 | break; |
| 824 | } |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 825 | |
| 826 | list_for_each_entry(ctl, &dsp->ctl_list, |
| 827 | list) { |
| 828 | if (!strcmp(ctl->name, name)) { |
| 829 | if (!ctl->enabled) |
| 830 | ctl->enabled = 1; |
| 831 | return 0; |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | ctl = kzalloc(sizeof(*ctl), GFP_KERNEL); |
| 836 | if (!ctl) |
| 837 | return -ENOMEM; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 838 | ctl->fw_name = wm_adsp_fw_text[dsp->fw]; |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 839 | ctl->alg_region = *alg_region; |
| 840 | ctl->name = kmemdup(name, strlen(name) + 1, GFP_KERNEL); |
| 841 | if (!ctl->name) { |
| 842 | ret = -ENOMEM; |
| 843 | goto err_ctl; |
| 844 | } |
| 845 | ctl->enabled = 1; |
| 846 | ctl->set = 0; |
| 847 | ctl->ops.xget = wm_coeff_get; |
| 848 | ctl->ops.xput = wm_coeff_put; |
| 849 | ctl->dsp = dsp; |
| 850 | |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 851 | ctl->flags = flags; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 852 | ctl->offset = offset; |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 853 | if (len > 512) { |
| 854 | adsp_warn(dsp, "Truncating control %s from %d\n", |
| 855 | ctl->name, len); |
| 856 | len = 512; |
| 857 | } |
| 858 | ctl->len = len; |
| 859 | ctl->cache = kzalloc(ctl->len, GFP_KERNEL); |
| 860 | if (!ctl->cache) { |
| 861 | ret = -ENOMEM; |
| 862 | goto err_ctl_name; |
| 863 | } |
| 864 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 865 | list_add(&ctl->list, &dsp->ctl_list); |
| 866 | |
Charles Keepax | b21acc1 | 2015-04-13 13:28:01 +0100 | [diff] [blame] | 867 | ctl_work = kzalloc(sizeof(*ctl_work), GFP_KERNEL); |
| 868 | if (!ctl_work) { |
| 869 | ret = -ENOMEM; |
| 870 | goto err_ctl_cache; |
| 871 | } |
| 872 | |
| 873 | ctl_work->dsp = dsp; |
| 874 | ctl_work->ctl = ctl; |
| 875 | INIT_WORK(&ctl_work->work, wm_adsp_ctl_work); |
| 876 | schedule_work(&ctl_work->work); |
| 877 | |
| 878 | return 0; |
| 879 | |
| 880 | err_ctl_cache: |
| 881 | kfree(ctl->cache); |
| 882 | err_ctl_name: |
| 883 | kfree(ctl->name); |
| 884 | err_ctl: |
| 885 | kfree(ctl); |
| 886 | |
| 887 | return ret; |
| 888 | } |
| 889 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 890 | struct wm_coeff_parsed_alg { |
| 891 | int id; |
| 892 | const u8 *name; |
| 893 | int name_len; |
| 894 | int ncoeff; |
| 895 | }; |
| 896 | |
| 897 | struct wm_coeff_parsed_coeff { |
| 898 | int offset; |
| 899 | int mem_type; |
| 900 | const u8 *name; |
| 901 | int name_len; |
| 902 | int ctl_type; |
| 903 | int flags; |
| 904 | int len; |
| 905 | }; |
| 906 | |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 907 | static int wm_coeff_parse_string(int bytes, const u8 **pos, const u8 **str) |
| 908 | { |
| 909 | int length; |
| 910 | |
| 911 | switch (bytes) { |
| 912 | case 1: |
| 913 | length = **pos; |
| 914 | break; |
| 915 | case 2: |
Charles Keepax | 8299ee8 | 2015-04-20 13:52:44 +0100 | [diff] [blame] | 916 | length = le16_to_cpu(*((__le16 *)*pos)); |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 917 | break; |
| 918 | default: |
| 919 | return 0; |
| 920 | } |
| 921 | |
| 922 | if (str) |
| 923 | *str = *pos + bytes; |
| 924 | |
| 925 | *pos += ((length + bytes) + 3) & ~0x03; |
| 926 | |
| 927 | return length; |
| 928 | } |
| 929 | |
| 930 | static int wm_coeff_parse_int(int bytes, const u8 **pos) |
| 931 | { |
| 932 | int val = 0; |
| 933 | |
| 934 | switch (bytes) { |
| 935 | case 2: |
Charles Keepax | 8299ee8 | 2015-04-20 13:52:44 +0100 | [diff] [blame] | 936 | val = le16_to_cpu(*((__le16 *)*pos)); |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 937 | break; |
| 938 | case 4: |
Charles Keepax | 8299ee8 | 2015-04-20 13:52:44 +0100 | [diff] [blame] | 939 | val = le32_to_cpu(*((__le32 *)*pos)); |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 940 | break; |
| 941 | default: |
| 942 | break; |
| 943 | } |
| 944 | |
| 945 | *pos += bytes; |
| 946 | |
| 947 | return val; |
| 948 | } |
| 949 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 950 | static inline void wm_coeff_parse_alg(struct wm_adsp *dsp, const u8 **data, |
| 951 | struct wm_coeff_parsed_alg *blk) |
| 952 | { |
| 953 | const struct wmfw_adsp_alg_data *raw; |
| 954 | |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 955 | switch (dsp->fw_ver) { |
| 956 | case 0: |
| 957 | case 1: |
| 958 | raw = (const struct wmfw_adsp_alg_data *)*data; |
| 959 | *data = raw->data; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 960 | |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 961 | blk->id = le32_to_cpu(raw->id); |
| 962 | blk->name = raw->name; |
| 963 | blk->name_len = strlen(raw->name); |
| 964 | blk->ncoeff = le32_to_cpu(raw->ncoeff); |
| 965 | break; |
| 966 | default: |
| 967 | blk->id = wm_coeff_parse_int(sizeof(raw->id), data); |
| 968 | blk->name_len = wm_coeff_parse_string(sizeof(u8), data, |
| 969 | &blk->name); |
| 970 | wm_coeff_parse_string(sizeof(u16), data, NULL); |
| 971 | blk->ncoeff = wm_coeff_parse_int(sizeof(raw->ncoeff), data); |
| 972 | break; |
| 973 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 974 | |
| 975 | adsp_dbg(dsp, "Algorithm ID: %#x\n", blk->id); |
| 976 | adsp_dbg(dsp, "Algorithm name: %.*s\n", blk->name_len, blk->name); |
| 977 | adsp_dbg(dsp, "# of coefficient descriptors: %#x\n", blk->ncoeff); |
| 978 | } |
| 979 | |
| 980 | static inline void wm_coeff_parse_coeff(struct wm_adsp *dsp, const u8 **data, |
| 981 | struct wm_coeff_parsed_coeff *blk) |
| 982 | { |
| 983 | const struct wmfw_adsp_coeff_data *raw; |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 984 | const u8 *tmp; |
| 985 | int length; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 986 | |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 987 | switch (dsp->fw_ver) { |
| 988 | case 0: |
| 989 | case 1: |
| 990 | raw = (const struct wmfw_adsp_coeff_data *)*data; |
| 991 | *data = *data + sizeof(raw->hdr) + le32_to_cpu(raw->hdr.size); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 992 | |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 993 | blk->offset = le16_to_cpu(raw->hdr.offset); |
| 994 | blk->mem_type = le16_to_cpu(raw->hdr.type); |
| 995 | blk->name = raw->name; |
| 996 | blk->name_len = strlen(raw->name); |
| 997 | blk->ctl_type = le16_to_cpu(raw->ctl_type); |
| 998 | blk->flags = le16_to_cpu(raw->flags); |
| 999 | blk->len = le32_to_cpu(raw->len); |
| 1000 | break; |
| 1001 | default: |
| 1002 | tmp = *data; |
| 1003 | blk->offset = wm_coeff_parse_int(sizeof(raw->hdr.offset), &tmp); |
| 1004 | blk->mem_type = wm_coeff_parse_int(sizeof(raw->hdr.type), &tmp); |
| 1005 | length = wm_coeff_parse_int(sizeof(raw->hdr.size), &tmp); |
| 1006 | blk->name_len = wm_coeff_parse_string(sizeof(u8), &tmp, |
| 1007 | &blk->name); |
| 1008 | wm_coeff_parse_string(sizeof(u8), &tmp, NULL); |
| 1009 | wm_coeff_parse_string(sizeof(u16), &tmp, NULL); |
| 1010 | blk->ctl_type = wm_coeff_parse_int(sizeof(raw->ctl_type), &tmp); |
| 1011 | blk->flags = wm_coeff_parse_int(sizeof(raw->flags), &tmp); |
| 1012 | blk->len = wm_coeff_parse_int(sizeof(raw->len), &tmp); |
| 1013 | |
| 1014 | *data = *data + sizeof(raw->hdr) + length; |
| 1015 | break; |
| 1016 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1017 | |
| 1018 | adsp_dbg(dsp, "\tCoefficient type: %#x\n", blk->mem_type); |
| 1019 | adsp_dbg(dsp, "\tCoefficient offset: %#x\n", blk->offset); |
| 1020 | adsp_dbg(dsp, "\tCoefficient name: %.*s\n", blk->name_len, blk->name); |
| 1021 | adsp_dbg(dsp, "\tCoefficient flags: %#x\n", blk->flags); |
| 1022 | adsp_dbg(dsp, "\tALSA control type: %#x\n", blk->ctl_type); |
| 1023 | adsp_dbg(dsp, "\tALSA control len: %#x\n", blk->len); |
| 1024 | } |
| 1025 | |
| 1026 | static int wm_adsp_parse_coeff(struct wm_adsp *dsp, |
| 1027 | const struct wmfw_region *region) |
| 1028 | { |
| 1029 | struct wm_adsp_alg_region alg_region = {}; |
| 1030 | struct wm_coeff_parsed_alg alg_blk; |
| 1031 | struct wm_coeff_parsed_coeff coeff_blk; |
| 1032 | const u8 *data = region->data; |
| 1033 | int i, ret; |
| 1034 | |
| 1035 | wm_coeff_parse_alg(dsp, &data, &alg_blk); |
| 1036 | for (i = 0; i < alg_blk.ncoeff; i++) { |
| 1037 | wm_coeff_parse_coeff(dsp, &data, &coeff_blk); |
| 1038 | |
| 1039 | switch (coeff_blk.ctl_type) { |
| 1040 | case SNDRV_CTL_ELEM_TYPE_BYTES: |
| 1041 | break; |
| 1042 | default: |
| 1043 | adsp_err(dsp, "Unknown control type: %d\n", |
| 1044 | coeff_blk.ctl_type); |
| 1045 | return -EINVAL; |
| 1046 | } |
| 1047 | |
| 1048 | alg_region.type = coeff_blk.mem_type; |
| 1049 | alg_region.alg = alg_blk.id; |
| 1050 | |
| 1051 | ret = wm_adsp_create_control(dsp, &alg_region, |
| 1052 | coeff_blk.offset, |
| 1053 | coeff_blk.len, |
| 1054 | coeff_blk.name, |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 1055 | coeff_blk.name_len, |
| 1056 | coeff_blk.flags); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1057 | if (ret < 0) |
| 1058 | adsp_err(dsp, "Failed to create control: %.*s, %d\n", |
| 1059 | coeff_blk.name_len, coeff_blk.name, ret); |
| 1060 | } |
| 1061 | |
| 1062 | return 0; |
| 1063 | } |
| 1064 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1065 | static int wm_adsp_load(struct wm_adsp *dsp) |
| 1066 | { |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1067 | LIST_HEAD(buf_list); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1068 | const struct firmware *firmware; |
| 1069 | struct regmap *regmap = dsp->regmap; |
| 1070 | unsigned int pos = 0; |
| 1071 | const struct wmfw_header *header; |
| 1072 | const struct wmfw_adsp1_sizes *adsp1_sizes; |
| 1073 | const struct wmfw_adsp2_sizes *adsp2_sizes; |
| 1074 | const struct wmfw_footer *footer; |
| 1075 | const struct wmfw_region *region; |
| 1076 | const struct wm_adsp_region *mem; |
| 1077 | const char *region_name; |
| 1078 | char *file, *text; |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1079 | struct wm_adsp_buf *buf; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1080 | unsigned int reg; |
| 1081 | int regions = 0; |
| 1082 | int ret, offset, type, sizes; |
| 1083 | |
| 1084 | file = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 1085 | if (file == NULL) |
| 1086 | return -ENOMEM; |
| 1087 | |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 1088 | snprintf(file, PAGE_SIZE, "%s-dsp%d-%s.wmfw", dsp->part, dsp->num, |
| 1089 | wm_adsp_fw[dsp->fw].file); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1090 | file[PAGE_SIZE - 1] = '\0'; |
| 1091 | |
| 1092 | ret = request_firmware(&firmware, file, dsp->dev); |
| 1093 | if (ret != 0) { |
| 1094 | adsp_err(dsp, "Failed to request '%s'\n", file); |
| 1095 | goto out; |
| 1096 | } |
| 1097 | ret = -EINVAL; |
| 1098 | |
| 1099 | pos = sizeof(*header) + sizeof(*adsp1_sizes) + sizeof(*footer); |
| 1100 | if (pos >= firmware->size) { |
| 1101 | adsp_err(dsp, "%s: file too short, %zu bytes\n", |
| 1102 | file, firmware->size); |
| 1103 | goto out_fw; |
| 1104 | } |
| 1105 | |
| 1106 | header = (void*)&firmware->data[0]; |
| 1107 | |
| 1108 | if (memcmp(&header->magic[0], "WMFW", 4) != 0) { |
| 1109 | adsp_err(dsp, "%s: invalid magic\n", file); |
| 1110 | goto out_fw; |
| 1111 | } |
| 1112 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1113 | switch (header->ver) { |
| 1114 | case 0: |
Charles Keepax | c61e59f | 2015-04-13 13:28:05 +0100 | [diff] [blame] | 1115 | adsp_warn(dsp, "%s: Depreciated file format %d\n", |
| 1116 | file, header->ver); |
| 1117 | break; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1118 | case 1: |
Charles Keepax | cb5b57a | 2015-04-13 13:28:04 +0100 | [diff] [blame] | 1119 | case 2: |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1120 | break; |
| 1121 | default: |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1122 | adsp_err(dsp, "%s: unknown file format %d\n", |
| 1123 | file, header->ver); |
| 1124 | goto out_fw; |
| 1125 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1126 | |
Dimitris Papastamos | 3626992 | 2013-11-01 15:56:57 +0000 | [diff] [blame] | 1127 | adsp_info(dsp, "Firmware version: %d\n", header->ver); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1128 | dsp->fw_ver = header->ver; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1129 | |
| 1130 | if (header->core != dsp->type) { |
| 1131 | adsp_err(dsp, "%s: invalid core %d != %d\n", |
| 1132 | file, header->core, dsp->type); |
| 1133 | goto out_fw; |
| 1134 | } |
| 1135 | |
| 1136 | switch (dsp->type) { |
| 1137 | case WMFW_ADSP1: |
| 1138 | pos = sizeof(*header) + sizeof(*adsp1_sizes) + sizeof(*footer); |
| 1139 | adsp1_sizes = (void *)&(header[1]); |
| 1140 | footer = (void *)&(adsp1_sizes[1]); |
| 1141 | sizes = sizeof(*adsp1_sizes); |
| 1142 | |
| 1143 | adsp_dbg(dsp, "%s: %d DM, %d PM, %d ZM\n", |
| 1144 | file, le32_to_cpu(adsp1_sizes->dm), |
| 1145 | le32_to_cpu(adsp1_sizes->pm), |
| 1146 | le32_to_cpu(adsp1_sizes->zm)); |
| 1147 | break; |
| 1148 | |
| 1149 | case WMFW_ADSP2: |
| 1150 | pos = sizeof(*header) + sizeof(*adsp2_sizes) + sizeof(*footer); |
| 1151 | adsp2_sizes = (void *)&(header[1]); |
| 1152 | footer = (void *)&(adsp2_sizes[1]); |
| 1153 | sizes = sizeof(*adsp2_sizes); |
| 1154 | |
| 1155 | adsp_dbg(dsp, "%s: %d XM, %d YM %d PM, %d ZM\n", |
| 1156 | file, le32_to_cpu(adsp2_sizes->xm), |
| 1157 | le32_to_cpu(adsp2_sizes->ym), |
| 1158 | le32_to_cpu(adsp2_sizes->pm), |
| 1159 | le32_to_cpu(adsp2_sizes->zm)); |
| 1160 | break; |
| 1161 | |
| 1162 | default: |
Takashi Iwai | 6c452bd | 2013-11-05 18:40:00 +0100 | [diff] [blame] | 1163 | WARN(1, "Unknown DSP type"); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1164 | goto out_fw; |
| 1165 | } |
| 1166 | |
| 1167 | if (le32_to_cpu(header->len) != sizeof(*header) + |
| 1168 | sizes + sizeof(*footer)) { |
| 1169 | adsp_err(dsp, "%s: unexpected header length %d\n", |
| 1170 | file, le32_to_cpu(header->len)); |
| 1171 | goto out_fw; |
| 1172 | } |
| 1173 | |
| 1174 | adsp_dbg(dsp, "%s: timestamp %llu\n", file, |
| 1175 | le64_to_cpu(footer->timestamp)); |
| 1176 | |
| 1177 | while (pos < firmware->size && |
| 1178 | pos - firmware->size > sizeof(*region)) { |
| 1179 | region = (void *)&(firmware->data[pos]); |
| 1180 | region_name = "Unknown"; |
| 1181 | reg = 0; |
| 1182 | text = NULL; |
| 1183 | offset = le32_to_cpu(region->offset) & 0xffffff; |
| 1184 | type = be32_to_cpu(region->type) & 0xff; |
| 1185 | mem = wm_adsp_find_region(dsp, type); |
| 1186 | |
| 1187 | switch (type) { |
| 1188 | case WMFW_NAME_TEXT: |
| 1189 | region_name = "Firmware name"; |
| 1190 | text = kzalloc(le32_to_cpu(region->len) + 1, |
| 1191 | GFP_KERNEL); |
| 1192 | break; |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1193 | case WMFW_ALGORITHM_DATA: |
| 1194 | region_name = "Algorithm"; |
| 1195 | ret = wm_adsp_parse_coeff(dsp, region); |
| 1196 | if (ret != 0) |
| 1197 | goto out_fw; |
| 1198 | break; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1199 | case WMFW_INFO_TEXT: |
| 1200 | region_name = "Information"; |
| 1201 | text = kzalloc(le32_to_cpu(region->len) + 1, |
| 1202 | GFP_KERNEL); |
| 1203 | break; |
| 1204 | case WMFW_ABSOLUTE: |
| 1205 | region_name = "Absolute"; |
| 1206 | reg = offset; |
| 1207 | break; |
| 1208 | case WMFW_ADSP1_PM: |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1209 | region_name = "PM"; |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 1210 | reg = wm_adsp_region_to_reg(mem, offset); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1211 | break; |
| 1212 | case WMFW_ADSP1_DM: |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1213 | region_name = "DM"; |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 1214 | reg = wm_adsp_region_to_reg(mem, offset); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1215 | break; |
| 1216 | case WMFW_ADSP2_XM: |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1217 | region_name = "XM"; |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 1218 | reg = wm_adsp_region_to_reg(mem, offset); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1219 | break; |
| 1220 | case WMFW_ADSP2_YM: |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1221 | region_name = "YM"; |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 1222 | reg = wm_adsp_region_to_reg(mem, offset); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1223 | break; |
| 1224 | case WMFW_ADSP1_ZM: |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1225 | region_name = "ZM"; |
Mark Brown | 45b9ee7 | 2013-01-08 16:02:06 +0000 | [diff] [blame] | 1226 | reg = wm_adsp_region_to_reg(mem, offset); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1227 | break; |
| 1228 | default: |
| 1229 | adsp_warn(dsp, |
| 1230 | "%s.%d: Unknown region type %x at %d(%x)\n", |
| 1231 | file, regions, type, pos, pos); |
| 1232 | break; |
| 1233 | } |
| 1234 | |
| 1235 | adsp_dbg(dsp, "%s.%d: %d bytes at %d in %s\n", file, |
| 1236 | regions, le32_to_cpu(region->len), offset, |
| 1237 | region_name); |
| 1238 | |
| 1239 | if (text) { |
| 1240 | memcpy(text, region->data, le32_to_cpu(region->len)); |
| 1241 | adsp_info(dsp, "%s: %s\n", file, text); |
| 1242 | kfree(text); |
| 1243 | } |
| 1244 | |
| 1245 | if (reg) { |
Charles Keepax | cdcd7f7 | 2014-11-14 15:40:45 +0000 | [diff] [blame] | 1246 | buf = wm_adsp_buf_alloc(region->data, |
| 1247 | le32_to_cpu(region->len), |
| 1248 | &buf_list); |
| 1249 | if (!buf) { |
| 1250 | adsp_err(dsp, "Out of memory\n"); |
| 1251 | ret = -ENOMEM; |
| 1252 | goto out_fw; |
| 1253 | } |
Mark Brown | a76fefa | 2013-01-07 19:03:17 +0000 | [diff] [blame] | 1254 | |
Charles Keepax | cdcd7f7 | 2014-11-14 15:40:45 +0000 | [diff] [blame] | 1255 | ret = regmap_raw_write_async(regmap, reg, buf->buf, |
| 1256 | le32_to_cpu(region->len)); |
| 1257 | if (ret != 0) { |
| 1258 | adsp_err(dsp, |
| 1259 | "%s.%d: Failed to write %d bytes at %d in %s: %d\n", |
| 1260 | file, regions, |
| 1261 | le32_to_cpu(region->len), offset, |
| 1262 | region_name, ret); |
| 1263 | goto out_fw; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | pos += le32_to_cpu(region->len) + sizeof(*region); |
| 1268 | regions++; |
| 1269 | } |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1270 | |
| 1271 | ret = regmap_async_complete(regmap); |
| 1272 | if (ret != 0) { |
| 1273 | adsp_err(dsp, "Failed to complete async write: %d\n", ret); |
| 1274 | goto out_fw; |
| 1275 | } |
| 1276 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1277 | if (pos > firmware->size) |
| 1278 | adsp_warn(dsp, "%s.%d: %zu bytes at end of file\n", |
| 1279 | file, regions, pos - firmware->size); |
| 1280 | |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 1281 | wm_adsp_debugfs_save_wmfwname(dsp, file); |
| 1282 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1283 | out_fw: |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1284 | regmap_async_complete(regmap); |
| 1285 | wm_adsp_buf_free(&buf_list); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1286 | release_firmware(firmware); |
| 1287 | out: |
| 1288 | kfree(file); |
| 1289 | |
| 1290 | return ret; |
| 1291 | } |
| 1292 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1293 | static void wm_adsp_ctl_fixup_base(struct wm_adsp *dsp, |
| 1294 | const struct wm_adsp_alg_region *alg_region) |
| 1295 | { |
| 1296 | struct wm_coeff_ctl *ctl; |
| 1297 | |
| 1298 | list_for_each_entry(ctl, &dsp->ctl_list, list) { |
| 1299 | if (ctl->fw_name == wm_adsp_fw_text[dsp->fw] && |
| 1300 | alg_region->alg == ctl->alg_region.alg && |
| 1301 | alg_region->type == ctl->alg_region.type) { |
| 1302 | ctl->alg_region.base = alg_region->base; |
| 1303 | } |
| 1304 | } |
| 1305 | } |
| 1306 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1307 | 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] | 1308 | unsigned int pos, unsigned int len) |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1309 | { |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1310 | void *alg; |
| 1311 | int ret; |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1312 | __be32 val; |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1313 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1314 | if (n_algs == 0) { |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1315 | adsp_err(dsp, "No algorithms\n"); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1316 | return ERR_PTR(-EINVAL); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1317 | } |
| 1318 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1319 | if (n_algs > 1024) { |
| 1320 | adsp_err(dsp, "Algorithm count %zx excessive\n", n_algs); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1321 | return ERR_PTR(-EINVAL); |
Mark Brown | d62f4bc | 2012-12-19 14:00:30 +0000 | [diff] [blame] | 1322 | } |
| 1323 | |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1324 | /* Read the terminator first to validate the length */ |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1325 | ret = regmap_raw_read(dsp->regmap, pos + len, &val, sizeof(val)); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1326 | if (ret != 0) { |
| 1327 | adsp_err(dsp, "Failed to read algorithm list end: %d\n", |
| 1328 | ret); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1329 | return ERR_PTR(ret); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | if (be32_to_cpu(val) != 0xbedead) |
| 1333 | adsp_warn(dsp, "Algorithm list end %x 0x%x != 0xbeadead\n", |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1334 | pos + len, be32_to_cpu(val)); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1335 | |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1336 | alg = kzalloc(len * 2, GFP_KERNEL | GFP_DMA); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1337 | if (!alg) |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1338 | return ERR_PTR(-ENOMEM); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1339 | |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1340 | ret = regmap_raw_read(dsp->regmap, pos, alg, len * 2); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1341 | if (ret != 0) { |
| 1342 | adsp_err(dsp, "Failed to read algorithm list: %d\n", |
| 1343 | ret); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1344 | kfree(alg); |
| 1345 | return ERR_PTR(ret); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1346 | } |
| 1347 | |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1348 | return alg; |
| 1349 | } |
| 1350 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1351 | static struct wm_adsp_alg_region *wm_adsp_create_region(struct wm_adsp *dsp, |
| 1352 | int type, __be32 id, |
| 1353 | __be32 base) |
| 1354 | { |
| 1355 | struct wm_adsp_alg_region *alg_region; |
| 1356 | |
| 1357 | alg_region = kzalloc(sizeof(*alg_region), GFP_KERNEL); |
| 1358 | if (!alg_region) |
| 1359 | return ERR_PTR(-ENOMEM); |
| 1360 | |
| 1361 | alg_region->type = type; |
| 1362 | alg_region->alg = be32_to_cpu(id); |
| 1363 | alg_region->base = be32_to_cpu(base); |
| 1364 | |
| 1365 | list_add_tail(&alg_region->list, &dsp->alg_regions); |
| 1366 | |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1367 | if (dsp->fw_ver > 0) |
| 1368 | wm_adsp_ctl_fixup_base(dsp, alg_region); |
| 1369 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1370 | return alg_region; |
| 1371 | } |
| 1372 | |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1373 | static int wm_adsp1_setup_algs(struct wm_adsp *dsp) |
| 1374 | { |
| 1375 | struct wmfw_adsp1_id_hdr adsp1_id; |
| 1376 | struct wmfw_adsp1_alg_hdr *adsp1_alg; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1377 | struct wm_adsp_alg_region *alg_region; |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1378 | const struct wm_adsp_region *mem; |
| 1379 | unsigned int pos, len; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1380 | size_t n_algs; |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1381 | int i, ret; |
| 1382 | |
| 1383 | mem = wm_adsp_find_region(dsp, WMFW_ADSP1_DM); |
| 1384 | if (WARN_ON(!mem)) |
| 1385 | return -EINVAL; |
| 1386 | |
| 1387 | ret = regmap_raw_read(dsp->regmap, mem->base, &adsp1_id, |
| 1388 | sizeof(adsp1_id)); |
| 1389 | if (ret != 0) { |
| 1390 | adsp_err(dsp, "Failed to read algorithm info: %d\n", |
| 1391 | ret); |
| 1392 | return ret; |
| 1393 | } |
| 1394 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1395 | n_algs = be32_to_cpu(adsp1_id.n_algs); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1396 | dsp->fw_id = be32_to_cpu(adsp1_id.fw.id); |
| 1397 | adsp_info(dsp, "Firmware: %x v%d.%d.%d, %zu algorithms\n", |
| 1398 | dsp->fw_id, |
| 1399 | (be32_to_cpu(adsp1_id.fw.ver) & 0xff0000) >> 16, |
| 1400 | (be32_to_cpu(adsp1_id.fw.ver) & 0xff00) >> 8, |
| 1401 | be32_to_cpu(adsp1_id.fw.ver) & 0xff, |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1402 | n_algs); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1403 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1404 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_ZM, |
| 1405 | adsp1_id.fw.id, adsp1_id.zm); |
| 1406 | if (IS_ERR(alg_region)) |
| 1407 | return PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1408 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1409 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_DM, |
| 1410 | adsp1_id.fw.id, adsp1_id.dm); |
| 1411 | if (IS_ERR(alg_region)) |
| 1412 | return PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1413 | |
| 1414 | pos = sizeof(adsp1_id) / 2; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1415 | len = (sizeof(*adsp1_alg) * n_algs) / 2; |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1416 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1417 | 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] | 1418 | if (IS_ERR(adsp1_alg)) |
| 1419 | return PTR_ERR(adsp1_alg); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1420 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1421 | for (i = 0; i < n_algs; i++) { |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1422 | adsp_info(dsp, "%d: ID %x v%d.%d.%d DM@%x ZM@%x\n", |
| 1423 | i, be32_to_cpu(adsp1_alg[i].alg.id), |
| 1424 | (be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff0000) >> 16, |
| 1425 | (be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff00) >> 8, |
| 1426 | be32_to_cpu(adsp1_alg[i].alg.ver) & 0xff, |
| 1427 | be32_to_cpu(adsp1_alg[i].dm), |
| 1428 | be32_to_cpu(adsp1_alg[i].zm)); |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 1429 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1430 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_DM, |
| 1431 | adsp1_alg[i].alg.id, |
| 1432 | adsp1_alg[i].dm); |
| 1433 | if (IS_ERR(alg_region)) { |
| 1434 | ret = PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1435 | goto out; |
| 1436 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1437 | if (dsp->fw_ver == 0) { |
| 1438 | if (i + 1 < n_algs) { |
| 1439 | len = be32_to_cpu(adsp1_alg[i + 1].dm); |
| 1440 | len -= be32_to_cpu(adsp1_alg[i].dm); |
| 1441 | len *= 4; |
| 1442 | wm_adsp_create_control(dsp, alg_region, 0, |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 1443 | len, NULL, 0, 0); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1444 | } else { |
| 1445 | adsp_warn(dsp, "Missing length info for region DM with ID %x\n", |
| 1446 | be32_to_cpu(adsp1_alg[i].alg.id)); |
| 1447 | } |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1448 | } |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 1449 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1450 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP1_ZM, |
| 1451 | adsp1_alg[i].alg.id, |
| 1452 | adsp1_alg[i].zm); |
| 1453 | if (IS_ERR(alg_region)) { |
| 1454 | ret = PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1455 | goto out; |
| 1456 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1457 | if (dsp->fw_ver == 0) { |
| 1458 | if (i + 1 < n_algs) { |
| 1459 | len = be32_to_cpu(adsp1_alg[i + 1].zm); |
| 1460 | len -= be32_to_cpu(adsp1_alg[i].zm); |
| 1461 | len *= 4; |
| 1462 | wm_adsp_create_control(dsp, alg_region, 0, |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 1463 | len, NULL, 0, 0); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1464 | } else { |
| 1465 | adsp_warn(dsp, "Missing length info for region ZM with ID %x\n", |
| 1466 | be32_to_cpu(adsp1_alg[i].alg.id)); |
| 1467 | } |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | out: |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1472 | kfree(adsp1_alg); |
| 1473 | return ret; |
| 1474 | } |
| 1475 | |
| 1476 | static int wm_adsp2_setup_algs(struct wm_adsp *dsp) |
| 1477 | { |
| 1478 | struct wmfw_adsp2_id_hdr adsp2_id; |
| 1479 | struct wmfw_adsp2_alg_hdr *adsp2_alg; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1480 | struct wm_adsp_alg_region *alg_region; |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1481 | const struct wm_adsp_region *mem; |
| 1482 | unsigned int pos, len; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1483 | size_t n_algs; |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1484 | int i, ret; |
| 1485 | |
| 1486 | mem = wm_adsp_find_region(dsp, WMFW_ADSP2_XM); |
| 1487 | if (WARN_ON(!mem)) |
| 1488 | return -EINVAL; |
| 1489 | |
| 1490 | ret = regmap_raw_read(dsp->regmap, mem->base, &adsp2_id, |
| 1491 | sizeof(adsp2_id)); |
| 1492 | if (ret != 0) { |
| 1493 | adsp_err(dsp, "Failed to read algorithm info: %d\n", |
| 1494 | ret); |
| 1495 | return ret; |
| 1496 | } |
| 1497 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1498 | n_algs = be32_to_cpu(adsp2_id.n_algs); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1499 | dsp->fw_id = be32_to_cpu(adsp2_id.fw.id); |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 1500 | dsp->fw_id_version = be32_to_cpu(adsp2_id.fw.ver); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1501 | adsp_info(dsp, "Firmware: %x v%d.%d.%d, %zu algorithms\n", |
| 1502 | dsp->fw_id, |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 1503 | (dsp->fw_id_version & 0xff0000) >> 16, |
| 1504 | (dsp->fw_id_version & 0xff00) >> 8, |
| 1505 | dsp->fw_id_version & 0xff, |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1506 | n_algs); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1507 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1508 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_XM, |
| 1509 | adsp2_id.fw.id, adsp2_id.xm); |
| 1510 | if (IS_ERR(alg_region)) |
| 1511 | return PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1512 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1513 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_YM, |
| 1514 | adsp2_id.fw.id, adsp2_id.ym); |
| 1515 | if (IS_ERR(alg_region)) |
| 1516 | return PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1517 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1518 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_ZM, |
| 1519 | adsp2_id.fw.id, adsp2_id.zm); |
| 1520 | if (IS_ERR(alg_region)) |
| 1521 | return PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1522 | |
| 1523 | pos = sizeof(adsp2_id) / 2; |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1524 | len = (sizeof(*adsp2_alg) * n_algs) / 2; |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1525 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1526 | 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] | 1527 | if (IS_ERR(adsp2_alg)) |
| 1528 | return PTR_ERR(adsp2_alg); |
| 1529 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1530 | for (i = 0; i < n_algs; i++) { |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1531 | adsp_info(dsp, |
| 1532 | "%d: ID %x v%d.%d.%d XM@%x YM@%x ZM@%x\n", |
| 1533 | i, be32_to_cpu(adsp2_alg[i].alg.id), |
| 1534 | (be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff0000) >> 16, |
| 1535 | (be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff00) >> 8, |
| 1536 | be32_to_cpu(adsp2_alg[i].alg.ver) & 0xff, |
| 1537 | be32_to_cpu(adsp2_alg[i].xm), |
| 1538 | be32_to_cpu(adsp2_alg[i].ym), |
| 1539 | be32_to_cpu(adsp2_alg[i].zm)); |
| 1540 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1541 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_XM, |
| 1542 | adsp2_alg[i].alg.id, |
| 1543 | adsp2_alg[i].xm); |
| 1544 | if (IS_ERR(alg_region)) { |
| 1545 | ret = PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1546 | goto out; |
| 1547 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1548 | if (dsp->fw_ver == 0) { |
| 1549 | if (i + 1 < n_algs) { |
| 1550 | len = be32_to_cpu(adsp2_alg[i + 1].xm); |
| 1551 | len -= be32_to_cpu(adsp2_alg[i].xm); |
| 1552 | len *= 4; |
| 1553 | wm_adsp_create_control(dsp, alg_region, 0, |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 1554 | len, NULL, 0, 0); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1555 | } else { |
| 1556 | adsp_warn(dsp, "Missing length info for region XM with ID %x\n", |
| 1557 | be32_to_cpu(adsp2_alg[i].alg.id)); |
| 1558 | } |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1559 | } |
| 1560 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1561 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_YM, |
| 1562 | adsp2_alg[i].alg.id, |
| 1563 | adsp2_alg[i].ym); |
| 1564 | if (IS_ERR(alg_region)) { |
| 1565 | ret = PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1566 | goto out; |
| 1567 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1568 | if (dsp->fw_ver == 0) { |
| 1569 | if (i + 1 < n_algs) { |
| 1570 | len = be32_to_cpu(adsp2_alg[i + 1].ym); |
| 1571 | len -= be32_to_cpu(adsp2_alg[i].ym); |
| 1572 | len *= 4; |
| 1573 | wm_adsp_create_control(dsp, alg_region, 0, |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 1574 | len, NULL, 0, 0); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1575 | } else { |
| 1576 | adsp_warn(dsp, "Missing length info for region YM with ID %x\n", |
| 1577 | be32_to_cpu(adsp2_alg[i].alg.id)); |
| 1578 | } |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1579 | } |
| 1580 | |
Charles Keepax | d9d20e1 | 2015-04-13 13:27:59 +0100 | [diff] [blame] | 1581 | alg_region = wm_adsp_create_region(dsp, WMFW_ADSP2_ZM, |
| 1582 | adsp2_alg[i].alg.id, |
| 1583 | adsp2_alg[i].zm); |
| 1584 | if (IS_ERR(alg_region)) { |
| 1585 | ret = PTR_ERR(alg_region); |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1586 | goto out; |
| 1587 | } |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1588 | if (dsp->fw_ver == 0) { |
| 1589 | if (i + 1 < n_algs) { |
| 1590 | len = be32_to_cpu(adsp2_alg[i + 1].zm); |
| 1591 | len -= be32_to_cpu(adsp2_alg[i].zm); |
| 1592 | len *= 4; |
| 1593 | wm_adsp_create_control(dsp, alg_region, 0, |
Charles Keepax | 26c22a1 | 2015-04-20 13:52:45 +0100 | [diff] [blame] | 1594 | len, NULL, 0, 0); |
Charles Keepax | 2323736 | 2015-04-13 13:28:02 +0100 | [diff] [blame] | 1595 | } else { |
| 1596 | adsp_warn(dsp, "Missing length info for region ZM with ID %x\n", |
| 1597 | be32_to_cpu(adsp2_alg[i].alg.id)); |
| 1598 | } |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1599 | } |
| 1600 | } |
| 1601 | |
| 1602 | out: |
| 1603 | kfree(adsp2_alg); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1604 | return ret; |
| 1605 | } |
| 1606 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1607 | static int wm_adsp_load_coeff(struct wm_adsp *dsp) |
| 1608 | { |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1609 | LIST_HEAD(buf_list); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1610 | struct regmap *regmap = dsp->regmap; |
| 1611 | struct wmfw_coeff_hdr *hdr; |
| 1612 | struct wmfw_coeff_item *blk; |
| 1613 | const struct firmware *firmware; |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 1614 | const struct wm_adsp_region *mem; |
| 1615 | struct wm_adsp_alg_region *alg_region; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1616 | const char *region_name; |
| 1617 | int ret, pos, blocks, type, offset, reg; |
| 1618 | char *file; |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1619 | struct wm_adsp_buf *buf; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1620 | |
| 1621 | file = kzalloc(PAGE_SIZE, GFP_KERNEL); |
| 1622 | if (file == NULL) |
| 1623 | return -ENOMEM; |
| 1624 | |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 1625 | snprintf(file, PAGE_SIZE, "%s-dsp%d-%s.bin", dsp->part, dsp->num, |
| 1626 | wm_adsp_fw[dsp->fw].file); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1627 | file[PAGE_SIZE - 1] = '\0'; |
| 1628 | |
| 1629 | ret = request_firmware(&firmware, file, dsp->dev); |
| 1630 | if (ret != 0) { |
| 1631 | adsp_warn(dsp, "Failed to request '%s'\n", file); |
| 1632 | ret = 0; |
| 1633 | goto out; |
| 1634 | } |
| 1635 | ret = -EINVAL; |
| 1636 | |
| 1637 | if (sizeof(*hdr) >= firmware->size) { |
| 1638 | adsp_err(dsp, "%s: file too short, %zu bytes\n", |
| 1639 | file, firmware->size); |
| 1640 | goto out_fw; |
| 1641 | } |
| 1642 | |
| 1643 | hdr = (void*)&firmware->data[0]; |
| 1644 | if (memcmp(hdr->magic, "WMDR", 4) != 0) { |
| 1645 | adsp_err(dsp, "%s: invalid magic\n", file); |
Charles Keepax | a4cdbec | 2013-01-21 09:02:31 +0000 | [diff] [blame] | 1646 | goto out_fw; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1647 | } |
| 1648 | |
Mark Brown | c712326 | 2013-01-16 16:59:04 +0900 | [diff] [blame] | 1649 | switch (be32_to_cpu(hdr->rev) & 0xff) { |
| 1650 | case 1: |
| 1651 | break; |
| 1652 | default: |
| 1653 | adsp_err(dsp, "%s: Unsupported coefficient file format %d\n", |
| 1654 | file, be32_to_cpu(hdr->rev) & 0xff); |
| 1655 | ret = -EINVAL; |
| 1656 | goto out_fw; |
| 1657 | } |
| 1658 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1659 | adsp_dbg(dsp, "%s: v%d.%d.%d\n", file, |
| 1660 | (le32_to_cpu(hdr->ver) >> 16) & 0xff, |
| 1661 | (le32_to_cpu(hdr->ver) >> 8) & 0xff, |
| 1662 | le32_to_cpu(hdr->ver) & 0xff); |
| 1663 | |
| 1664 | pos = le32_to_cpu(hdr->len); |
| 1665 | |
| 1666 | blocks = 0; |
| 1667 | while (pos < firmware->size && |
| 1668 | pos - firmware->size > sizeof(*blk)) { |
| 1669 | blk = (void*)(&firmware->data[pos]); |
| 1670 | |
Mark Brown | c712326 | 2013-01-16 16:59:04 +0900 | [diff] [blame] | 1671 | type = le16_to_cpu(blk->type); |
| 1672 | offset = le16_to_cpu(blk->offset); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1673 | |
| 1674 | adsp_dbg(dsp, "%s.%d: %x v%d.%d.%d\n", |
| 1675 | file, blocks, le32_to_cpu(blk->id), |
| 1676 | (le32_to_cpu(blk->ver) >> 16) & 0xff, |
| 1677 | (le32_to_cpu(blk->ver) >> 8) & 0xff, |
| 1678 | le32_to_cpu(blk->ver) & 0xff); |
| 1679 | adsp_dbg(dsp, "%s.%d: %d bytes at 0x%x in %x\n", |
| 1680 | file, blocks, le32_to_cpu(blk->len), offset, type); |
| 1681 | |
| 1682 | reg = 0; |
| 1683 | region_name = "Unknown"; |
| 1684 | switch (type) { |
Mark Brown | c712326 | 2013-01-16 16:59:04 +0900 | [diff] [blame] | 1685 | case (WMFW_NAME_TEXT << 8): |
| 1686 | case (WMFW_INFO_TEXT << 8): |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1687 | break; |
Mark Brown | c712326 | 2013-01-16 16:59:04 +0900 | [diff] [blame] | 1688 | case (WMFW_ABSOLUTE << 8): |
Mark Brown | f395a21 | 2013-03-05 22:39:54 +0800 | [diff] [blame] | 1689 | /* |
| 1690 | * Old files may use this for global |
| 1691 | * coefficients. |
| 1692 | */ |
| 1693 | if (le32_to_cpu(blk->id) == dsp->fw_id && |
| 1694 | offset == 0) { |
| 1695 | region_name = "global coefficients"; |
| 1696 | mem = wm_adsp_find_region(dsp, type); |
| 1697 | if (!mem) { |
| 1698 | adsp_err(dsp, "No ZM\n"); |
| 1699 | break; |
| 1700 | } |
| 1701 | reg = wm_adsp_region_to_reg(mem, 0); |
| 1702 | |
| 1703 | } else { |
| 1704 | region_name = "register"; |
| 1705 | reg = offset; |
| 1706 | } |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1707 | break; |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 1708 | |
| 1709 | case WMFW_ADSP1_DM: |
| 1710 | case WMFW_ADSP1_ZM: |
| 1711 | case WMFW_ADSP2_XM: |
| 1712 | case WMFW_ADSP2_YM: |
| 1713 | adsp_dbg(dsp, "%s.%d: %d bytes in %x for %x\n", |
| 1714 | file, blocks, le32_to_cpu(blk->len), |
| 1715 | type, le32_to_cpu(blk->id)); |
| 1716 | |
| 1717 | mem = wm_adsp_find_region(dsp, type); |
| 1718 | if (!mem) { |
| 1719 | adsp_err(dsp, "No base for region %x\n", type); |
| 1720 | break; |
| 1721 | } |
| 1722 | |
| 1723 | reg = 0; |
| 1724 | list_for_each_entry(alg_region, |
| 1725 | &dsp->alg_regions, list) { |
| 1726 | if (le32_to_cpu(blk->id) == alg_region->alg && |
| 1727 | type == alg_region->type) { |
Mark Brown | 338c518 | 2013-01-24 00:35:48 +0800 | [diff] [blame] | 1728 | reg = alg_region->base; |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 1729 | reg = wm_adsp_region_to_reg(mem, |
| 1730 | reg); |
Mark Brown | 338c518 | 2013-01-24 00:35:48 +0800 | [diff] [blame] | 1731 | reg += offset; |
Charles Keepax | d733dc0 | 2013-11-28 16:37:51 +0000 | [diff] [blame] | 1732 | break; |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | if (reg == 0) |
| 1737 | adsp_err(dsp, "No %x for algorithm %x\n", |
| 1738 | type, le32_to_cpu(blk->id)); |
| 1739 | break; |
| 1740 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1741 | default: |
Mark Brown | 25c62f7e | 2013-01-20 19:02:19 +0900 | [diff] [blame] | 1742 | adsp_err(dsp, "%s.%d: Unknown region type %x at %d\n", |
| 1743 | file, blocks, type, pos); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1744 | break; |
| 1745 | } |
| 1746 | |
| 1747 | if (reg) { |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1748 | buf = wm_adsp_buf_alloc(blk->data, |
| 1749 | le32_to_cpu(blk->len), |
| 1750 | &buf_list); |
Mark Brown | a76fefa | 2013-01-07 19:03:17 +0000 | [diff] [blame] | 1751 | if (!buf) { |
| 1752 | adsp_err(dsp, "Out of memory\n"); |
Wei Yongjun | f4b8281 | 2013-03-12 00:23:15 +0800 | [diff] [blame] | 1753 | ret = -ENOMEM; |
| 1754 | goto out_fw; |
Mark Brown | a76fefa | 2013-01-07 19:03:17 +0000 | [diff] [blame] | 1755 | } |
| 1756 | |
Mark Brown | 20da6d5 | 2013-01-12 19:58:17 +0000 | [diff] [blame] | 1757 | adsp_dbg(dsp, "%s.%d: Writing %d bytes at %x\n", |
| 1758 | file, blocks, le32_to_cpu(blk->len), |
| 1759 | reg); |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1760 | ret = regmap_raw_write_async(regmap, reg, buf->buf, |
| 1761 | le32_to_cpu(blk->len)); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1762 | if (ret != 0) { |
| 1763 | adsp_err(dsp, |
Dimitris Papastamos | 43bc3bf | 2013-11-01 15:56:52 +0000 | [diff] [blame] | 1764 | "%s.%d: Failed to write to %x in %s: %d\n", |
| 1765 | file, blocks, reg, region_name, ret); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1766 | } |
| 1767 | } |
| 1768 | |
Charles Keepax | be95101 | 2015-02-16 15:25:49 +0000 | [diff] [blame] | 1769 | pos += (le32_to_cpu(blk->len) + sizeof(*blk) + 3) & ~0x03; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1770 | blocks++; |
| 1771 | } |
| 1772 | |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1773 | ret = regmap_async_complete(regmap); |
| 1774 | if (ret != 0) |
| 1775 | adsp_err(dsp, "Failed to complete async write: %d\n", ret); |
| 1776 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1777 | if (pos > firmware->size) |
| 1778 | adsp_warn(dsp, "%s.%d: %zu bytes at end of file\n", |
| 1779 | file, blocks, pos - firmware->size); |
| 1780 | |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 1781 | wm_adsp_debugfs_save_binname(dsp, file); |
| 1782 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1783 | out_fw: |
Charles Keepax | 9da7a5a | 2014-11-17 10:48:21 +0000 | [diff] [blame] | 1784 | regmap_async_complete(regmap); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1785 | release_firmware(firmware); |
Mark Brown | cf17c83 | 2013-01-30 14:37:23 +0800 | [diff] [blame] | 1786 | wm_adsp_buf_free(&buf_list); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1787 | out: |
| 1788 | kfree(file); |
Wei Yongjun | f4b8281 | 2013-03-12 00:23:15 +0800 | [diff] [blame] | 1789 | return ret; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1790 | } |
| 1791 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1792 | int wm_adsp1_init(struct wm_adsp *dsp) |
Mark Brown | 5e7a7a2 | 2013-01-16 10:03:56 +0900 | [diff] [blame] | 1793 | { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 1794 | INIT_LIST_HEAD(&dsp->alg_regions); |
Mark Brown | 5e7a7a2 | 2013-01-16 10:03:56 +0900 | [diff] [blame] | 1795 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1796 | mutex_init(&dsp->pwr_lock); |
| 1797 | |
Mark Brown | 5e7a7a2 | 2013-01-16 10:03:56 +0900 | [diff] [blame] | 1798 | return 0; |
| 1799 | } |
| 1800 | EXPORT_SYMBOL_GPL(wm_adsp1_init); |
| 1801 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1802 | int wm_adsp1_event(struct snd_soc_dapm_widget *w, |
| 1803 | struct snd_kcontrol *kcontrol, |
| 1804 | int event) |
| 1805 | { |
Lars-Peter Clausen | 7271851 | 2015-01-13 10:27:34 +0100 | [diff] [blame] | 1806 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1807 | struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec); |
| 1808 | struct wm_adsp *dsp = &dsps[w->shift]; |
Dimitris Papastamos | b0101b4 | 2013-11-01 15:56:56 +0000 | [diff] [blame] | 1809 | struct wm_adsp_alg_region *alg_region; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 1810 | struct wm_coeff_ctl *ctl; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1811 | int ret; |
Chris Rattray | 94e205b | 2013-01-18 08:43:09 +0000 | [diff] [blame] | 1812 | int val; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1813 | |
Lars-Peter Clausen | 0020010 | 2014-07-17 22:01:07 +0200 | [diff] [blame] | 1814 | dsp->card = codec->component.card; |
Dimitris Papastamos | 92bb4c3 | 2013-08-01 11:11:28 +0100 | [diff] [blame] | 1815 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1816 | mutex_lock(&dsp->pwr_lock); |
| 1817 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1818 | switch (event) { |
| 1819 | case SND_SOC_DAPM_POST_PMU: |
| 1820 | regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30, |
| 1821 | ADSP1_SYS_ENA, ADSP1_SYS_ENA); |
| 1822 | |
Chris Rattray | 94e205b | 2013-01-18 08:43:09 +0000 | [diff] [blame] | 1823 | /* |
| 1824 | * For simplicity set the DSP clock rate to be the |
| 1825 | * SYSCLK rate rather than making it configurable. |
| 1826 | */ |
| 1827 | if(dsp->sysclk_reg) { |
| 1828 | ret = regmap_read(dsp->regmap, dsp->sysclk_reg, &val); |
| 1829 | if (ret != 0) { |
| 1830 | adsp_err(dsp, "Failed to read SYSCLK state: %d\n", |
| 1831 | ret); |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1832 | goto err_mutex; |
Chris Rattray | 94e205b | 2013-01-18 08:43:09 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | val = (val & dsp->sysclk_mask) |
| 1836 | >> dsp->sysclk_shift; |
| 1837 | |
| 1838 | ret = regmap_update_bits(dsp->regmap, |
| 1839 | dsp->base + ADSP1_CONTROL_31, |
| 1840 | ADSP1_CLK_SEL_MASK, val); |
| 1841 | if (ret != 0) { |
| 1842 | adsp_err(dsp, "Failed to set clock rate: %d\n", |
| 1843 | ret); |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1844 | goto err_mutex; |
Chris Rattray | 94e205b | 2013-01-18 08:43:09 +0000 | [diff] [blame] | 1845 | } |
| 1846 | } |
| 1847 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1848 | ret = wm_adsp_load(dsp); |
| 1849 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1850 | goto err_ena; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1851 | |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1852 | ret = wm_adsp1_setup_algs(dsp); |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1853 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1854 | goto err_ena; |
Mark Brown | db40517 | 2012-10-26 19:30:40 +0100 | [diff] [blame] | 1855 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1856 | ret = wm_adsp_load_coeff(dsp); |
| 1857 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1858 | goto err_ena; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1859 | |
Dimitris Papastamos | 0c2e3f3 | 2013-05-28 12:01:50 +0100 | [diff] [blame] | 1860 | /* Initialize caches for enabled and unset controls */ |
Dimitris Papastamos | 81ad93e | 2013-07-29 13:51:59 +0100 | [diff] [blame] | 1861 | ret = wm_coeff_init_control_caches(dsp); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 1862 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1863 | goto err_ena; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 1864 | |
Dimitris Papastamos | 0c2e3f3 | 2013-05-28 12:01:50 +0100 | [diff] [blame] | 1865 | /* Sync set controls */ |
Dimitris Papastamos | 81ad93e | 2013-07-29 13:51:59 +0100 | [diff] [blame] | 1866 | ret = wm_coeff_sync_controls(dsp); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 1867 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1868 | goto err_ena; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 1869 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1870 | /* Start the core running */ |
| 1871 | regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30, |
| 1872 | ADSP1_CORE_ENA | ADSP1_START, |
| 1873 | ADSP1_CORE_ENA | ADSP1_START); |
| 1874 | break; |
| 1875 | |
| 1876 | case SND_SOC_DAPM_PRE_PMD: |
| 1877 | /* Halt the core */ |
| 1878 | regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30, |
| 1879 | ADSP1_CORE_ENA | ADSP1_START, 0); |
| 1880 | |
| 1881 | regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_19, |
| 1882 | ADSP1_WDMA_BUFFER_LENGTH_MASK, 0); |
| 1883 | |
| 1884 | regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30, |
| 1885 | ADSP1_SYS_ENA, 0); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 1886 | |
Dimitris Papastamos | 81ad93e | 2013-07-29 13:51:59 +0100 | [diff] [blame] | 1887 | list_for_each_entry(ctl, &dsp->ctl_list, list) |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 1888 | ctl->enabled = 0; |
Dimitris Papastamos | b0101b4 | 2013-11-01 15:56:56 +0000 | [diff] [blame] | 1889 | |
| 1890 | while (!list_empty(&dsp->alg_regions)) { |
| 1891 | alg_region = list_first_entry(&dsp->alg_regions, |
| 1892 | struct wm_adsp_alg_region, |
| 1893 | list); |
| 1894 | list_del(&alg_region->list); |
| 1895 | kfree(alg_region); |
| 1896 | } |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1897 | break; |
| 1898 | |
| 1899 | default: |
| 1900 | break; |
| 1901 | } |
| 1902 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1903 | mutex_unlock(&dsp->pwr_lock); |
| 1904 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1905 | return 0; |
| 1906 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1907 | err_ena: |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1908 | regmap_update_bits(dsp->regmap, dsp->base + ADSP1_CONTROL_30, |
| 1909 | ADSP1_SYS_ENA, 0); |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1910 | err_mutex: |
| 1911 | mutex_unlock(&dsp->pwr_lock); |
| 1912 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1913 | return ret; |
| 1914 | } |
| 1915 | EXPORT_SYMBOL_GPL(wm_adsp1_event); |
| 1916 | |
| 1917 | static int wm_adsp2_ena(struct wm_adsp *dsp) |
| 1918 | { |
| 1919 | unsigned int val; |
| 1920 | int ret, count; |
| 1921 | |
Mark Brown | 1552c32 | 2013-11-28 18:11:38 +0000 | [diff] [blame] | 1922 | ret = regmap_update_bits_async(dsp->regmap, dsp->base + ADSP2_CONTROL, |
| 1923 | ADSP2_SYS_ENA, ADSP2_SYS_ENA); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1924 | if (ret != 0) |
| 1925 | return ret; |
| 1926 | |
| 1927 | /* Wait for the RAM to start, should be near instantaneous */ |
Charles Keepax | 939fd1e | 2013-12-18 09:25:49 +0000 | [diff] [blame] | 1928 | for (count = 0; count < 10; ++count) { |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1929 | ret = regmap_read(dsp->regmap, dsp->base + ADSP2_STATUS1, |
| 1930 | &val); |
| 1931 | if (ret != 0) |
| 1932 | return ret; |
Charles Keepax | 939fd1e | 2013-12-18 09:25:49 +0000 | [diff] [blame] | 1933 | |
| 1934 | if (val & ADSP2_RAM_RDY) |
| 1935 | break; |
| 1936 | |
| 1937 | msleep(1); |
| 1938 | } |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1939 | |
| 1940 | if (!(val & ADSP2_RAM_RDY)) { |
| 1941 | adsp_err(dsp, "Failed to start DSP RAM\n"); |
| 1942 | return -EBUSY; |
| 1943 | } |
| 1944 | |
| 1945 | adsp_dbg(dsp, "RAM ready after %d polls\n", count); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 1946 | |
| 1947 | return 0; |
| 1948 | } |
| 1949 | |
Charles Keepax | 18b1a90 | 2014-01-09 09:06:54 +0000 | [diff] [blame] | 1950 | static void wm_adsp2_boot_work(struct work_struct *work) |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 1951 | { |
| 1952 | struct wm_adsp *dsp = container_of(work, |
| 1953 | struct wm_adsp, |
| 1954 | boot_work); |
| 1955 | int ret; |
| 1956 | unsigned int val; |
| 1957 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1958 | mutex_lock(&dsp->pwr_lock); |
| 1959 | |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 1960 | /* |
| 1961 | * For simplicity set the DSP clock rate to be the |
| 1962 | * SYSCLK rate rather than making it configurable. |
| 1963 | */ |
| 1964 | ret = regmap_read(dsp->regmap, ARIZONA_SYSTEM_CLOCK_1, &val); |
| 1965 | if (ret != 0) { |
| 1966 | adsp_err(dsp, "Failed to read SYSCLK state: %d\n", ret); |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1967 | goto err_mutex; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 1968 | } |
| 1969 | val = (val & ARIZONA_SYSCLK_FREQ_MASK) |
| 1970 | >> ARIZONA_SYSCLK_FREQ_SHIFT; |
| 1971 | |
| 1972 | ret = regmap_update_bits_async(dsp->regmap, |
| 1973 | dsp->base + ADSP2_CLOCKING, |
| 1974 | ADSP2_CLK_SEL_MASK, val); |
| 1975 | if (ret != 0) { |
| 1976 | adsp_err(dsp, "Failed to set clock rate: %d\n", ret); |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1977 | goto err_mutex; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 1978 | } |
| 1979 | |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 1980 | ret = wm_adsp2_ena(dsp); |
| 1981 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1982 | goto err_mutex; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 1983 | |
| 1984 | ret = wm_adsp_load(dsp); |
| 1985 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1986 | goto err_ena; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 1987 | |
Charles Keepax | b618a185 | 2015-04-13 13:27:53 +0100 | [diff] [blame] | 1988 | ret = wm_adsp2_setup_algs(dsp); |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 1989 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1990 | goto err_ena; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 1991 | |
| 1992 | ret = wm_adsp_load_coeff(dsp); |
| 1993 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1994 | goto err_ena; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 1995 | |
| 1996 | /* Initialize caches for enabled and unset controls */ |
| 1997 | ret = wm_coeff_init_control_caches(dsp); |
| 1998 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 1999 | goto err_ena; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2000 | |
| 2001 | /* Sync set controls */ |
| 2002 | ret = wm_coeff_sync_controls(dsp); |
| 2003 | if (ret != 0) |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 2004 | goto err_ena; |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2005 | |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2006 | dsp->running = true; |
| 2007 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 2008 | mutex_unlock(&dsp->pwr_lock); |
| 2009 | |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2010 | return; |
| 2011 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 2012 | err_ena: |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2013 | regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL, |
| 2014 | ADSP2_SYS_ENA | ADSP2_CORE_ENA | ADSP2_START, 0); |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 2015 | err_mutex: |
| 2016 | mutex_unlock(&dsp->pwr_lock); |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2017 | } |
| 2018 | |
Charles Keepax | 12db5ed | 2014-01-08 17:42:19 +0000 | [diff] [blame] | 2019 | int wm_adsp2_early_event(struct snd_soc_dapm_widget *w, |
| 2020 | struct snd_kcontrol *kcontrol, int event) |
| 2021 | { |
Lars-Peter Clausen | 7271851 | 2015-01-13 10:27:34 +0100 | [diff] [blame] | 2022 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
Charles Keepax | 12db5ed | 2014-01-08 17:42:19 +0000 | [diff] [blame] | 2023 | struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec); |
| 2024 | struct wm_adsp *dsp = &dsps[w->shift]; |
| 2025 | |
Lars-Peter Clausen | 0020010 | 2014-07-17 22:01:07 +0200 | [diff] [blame] | 2026 | dsp->card = codec->component.card; |
Charles Keepax | 12db5ed | 2014-01-08 17:42:19 +0000 | [diff] [blame] | 2027 | |
| 2028 | switch (event) { |
| 2029 | case SND_SOC_DAPM_PRE_PMU: |
| 2030 | queue_work(system_unbound_wq, &dsp->boot_work); |
| 2031 | break; |
| 2032 | default: |
| 2033 | break; |
Charles Keepax | cab2725 | 2014-04-17 13:42:54 +0100 | [diff] [blame] | 2034 | } |
Charles Keepax | 12db5ed | 2014-01-08 17:42:19 +0000 | [diff] [blame] | 2035 | |
| 2036 | return 0; |
| 2037 | } |
| 2038 | EXPORT_SYMBOL_GPL(wm_adsp2_early_event); |
| 2039 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2040 | int wm_adsp2_event(struct snd_soc_dapm_widget *w, |
| 2041 | struct snd_kcontrol *kcontrol, int event) |
| 2042 | { |
Lars-Peter Clausen | 7271851 | 2015-01-13 10:27:34 +0100 | [diff] [blame] | 2043 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2044 | struct wm_adsp *dsps = snd_soc_codec_get_drvdata(codec); |
| 2045 | struct wm_adsp *dsp = &dsps[w->shift]; |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 2046 | struct wm_adsp_alg_region *alg_region; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 2047 | struct wm_coeff_ctl *ctl; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2048 | int ret; |
| 2049 | |
| 2050 | switch (event) { |
| 2051 | case SND_SOC_DAPM_POST_PMU: |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2052 | flush_work(&dsp->boot_work); |
Mark Brown | dd49e2c | 2012-12-02 21:50:46 +0900 | [diff] [blame] | 2053 | |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2054 | if (!dsp->running) |
| 2055 | return -EIO; |
Mark Brown | dd49e2c | 2012-12-02 21:50:46 +0900 | [diff] [blame] | 2056 | |
Charles Keepax | d8a64d6 | 2014-01-08 17:42:18 +0000 | [diff] [blame] | 2057 | ret = regmap_update_bits(dsp->regmap, |
| 2058 | dsp->base + ADSP2_CONTROL, |
Charles Keepax | 00e4c3b | 2014-11-18 16:25:27 +0000 | [diff] [blame] | 2059 | ADSP2_CORE_ENA | ADSP2_START, |
| 2060 | ADSP2_CORE_ENA | ADSP2_START); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2061 | if (ret != 0) |
| 2062 | goto err; |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2063 | break; |
| 2064 | |
| 2065 | case SND_SOC_DAPM_PRE_PMD: |
Richard Fitzgerald | 10337b0 | 2015-05-29 10:23:07 +0100 | [diff] [blame] | 2066 | /* Log firmware state, it can be useful for analysis */ |
| 2067 | wm_adsp2_show_fw_status(dsp); |
| 2068 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 2069 | mutex_lock(&dsp->pwr_lock); |
| 2070 | |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 2071 | wm_adsp_debugfs_clear(dsp); |
| 2072 | |
| 2073 | dsp->fw_id = 0; |
| 2074 | dsp->fw_id_version = 0; |
Mark Brown | 1023dbd | 2013-01-11 22:58:28 +0000 | [diff] [blame] | 2075 | dsp->running = false; |
| 2076 | |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2077 | regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL, |
Mark Brown | a7f9be7 | 2012-11-28 19:53:59 +0000 | [diff] [blame] | 2078 | ADSP2_SYS_ENA | ADSP2_CORE_ENA | |
| 2079 | ADSP2_START, 0); |
Mark Brown | 973838a | 2012-11-28 17:20:32 +0000 | [diff] [blame] | 2080 | |
Mark Brown | 2d30b57 | 2013-01-28 20:18:17 +0800 | [diff] [blame] | 2081 | /* Make sure DMAs are quiesced */ |
| 2082 | regmap_write(dsp->regmap, dsp->base + ADSP2_WDMA_CONFIG_1, 0); |
| 2083 | regmap_write(dsp->regmap, dsp->base + ADSP2_WDMA_CONFIG_2, 0); |
| 2084 | regmap_write(dsp->regmap, dsp->base + ADSP2_RDMA_CONFIG_1, 0); |
| 2085 | |
Dimitris Papastamos | 81ad93e | 2013-07-29 13:51:59 +0100 | [diff] [blame] | 2086 | list_for_each_entry(ctl, &dsp->ctl_list, list) |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 2087 | ctl->enabled = 0; |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 2088 | |
Mark Brown | 471f488 | 2013-01-08 16:09:31 +0000 | [diff] [blame] | 2089 | while (!list_empty(&dsp->alg_regions)) { |
| 2090 | alg_region = list_first_entry(&dsp->alg_regions, |
| 2091 | struct wm_adsp_alg_region, |
| 2092 | list); |
| 2093 | list_del(&alg_region->list); |
| 2094 | kfree(alg_region); |
| 2095 | } |
Charles Keepax | ddbc5ef | 2014-01-22 10:09:11 +0000 | [diff] [blame] | 2096 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 2097 | mutex_unlock(&dsp->pwr_lock); |
| 2098 | |
Charles Keepax | ddbc5ef | 2014-01-22 10:09:11 +0000 | [diff] [blame] | 2099 | adsp_dbg(dsp, "Shutdown complete\n"); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2100 | break; |
| 2101 | |
| 2102 | default: |
| 2103 | break; |
| 2104 | } |
| 2105 | |
| 2106 | return 0; |
| 2107 | err: |
| 2108 | regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL, |
Mark Brown | a7f9be7 | 2012-11-28 19:53:59 +0000 | [diff] [blame] | 2109 | ADSP2_SYS_ENA | ADSP2_CORE_ENA | ADSP2_START, 0); |
Mark Brown | 2159ad9 | 2012-10-11 11:54:02 +0900 | [diff] [blame] | 2110 | return ret; |
| 2111 | } |
| 2112 | EXPORT_SYMBOL_GPL(wm_adsp2_event); |
Mark Brown | 973838a | 2012-11-28 17:20:32 +0000 | [diff] [blame] | 2113 | |
Richard Fitzgerald | f5e2ce9 | 2015-06-11 11:32:30 +0100 | [diff] [blame] | 2114 | int wm_adsp2_codec_probe(struct wm_adsp *dsp, struct snd_soc_codec *codec) |
| 2115 | { |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 2116 | wm_adsp2_init_debugfs(dsp, codec); |
| 2117 | |
Richard Fitzgerald | 218e508 | 2015-06-11 11:32:31 +0100 | [diff] [blame] | 2118 | return snd_soc_add_codec_controls(codec, |
Richard Fitzgerald | 336d044 | 2015-06-18 13:43:19 +0100 | [diff] [blame] | 2119 | &wm_adsp_fw_controls[dsp->num - 1], |
| 2120 | 1); |
Richard Fitzgerald | f5e2ce9 | 2015-06-11 11:32:30 +0100 | [diff] [blame] | 2121 | } |
| 2122 | EXPORT_SYMBOL_GPL(wm_adsp2_codec_probe); |
| 2123 | |
| 2124 | int wm_adsp2_codec_remove(struct wm_adsp *dsp, struct snd_soc_codec *codec) |
| 2125 | { |
Richard Fitzgerald | f9f55e3 | 2015-06-11 11:32:32 +0100 | [diff] [blame] | 2126 | wm_adsp2_cleanup_debugfs(dsp); |
| 2127 | |
Richard Fitzgerald | f5e2ce9 | 2015-06-11 11:32:30 +0100 | [diff] [blame] | 2128 | return 0; |
| 2129 | } |
| 2130 | EXPORT_SYMBOL_GPL(wm_adsp2_codec_remove); |
| 2131 | |
Richard Fitzgerald | 81ac58b | 2015-06-02 11:53:34 +0100 | [diff] [blame] | 2132 | int wm_adsp2_init(struct wm_adsp *dsp) |
Mark Brown | 973838a | 2012-11-28 17:20:32 +0000 | [diff] [blame] | 2133 | { |
| 2134 | int ret; |
| 2135 | |
Mark Brown | 10a2b66 | 2012-12-02 21:37:00 +0900 | [diff] [blame] | 2136 | /* |
| 2137 | * Disable the DSP memory by default when in reset for a small |
| 2138 | * power saving. |
| 2139 | */ |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 2140 | ret = regmap_update_bits(dsp->regmap, dsp->base + ADSP2_CONTROL, |
Mark Brown | 10a2b66 | 2012-12-02 21:37:00 +0900 | [diff] [blame] | 2141 | ADSP2_MEM_ENA, 0); |
| 2142 | if (ret != 0) { |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 2143 | adsp_err(dsp, "Failed to clear memory retention: %d\n", ret); |
Mark Brown | 10a2b66 | 2012-12-02 21:37:00 +0900 | [diff] [blame] | 2144 | return ret; |
| 2145 | } |
| 2146 | |
Charles Keepax | 3809f00 | 2015-04-13 13:27:54 +0100 | [diff] [blame] | 2147 | INIT_LIST_HEAD(&dsp->alg_regions); |
| 2148 | INIT_LIST_HEAD(&dsp->ctl_list); |
| 2149 | INIT_WORK(&dsp->boot_work, wm_adsp2_boot_work); |
Dimitris Papastamos | 6ab2b7b | 2013-05-08 14:15:35 +0100 | [diff] [blame] | 2150 | |
Charles Keepax | 078e718 | 2015-12-08 16:08:26 +0000 | [diff] [blame^] | 2151 | mutex_init(&dsp->pwr_lock); |
| 2152 | |
Mark Brown | 973838a | 2012-11-28 17:20:32 +0000 | [diff] [blame] | 2153 | return 0; |
| 2154 | } |
| 2155 | EXPORT_SYMBOL_GPL(wm_adsp2_init); |
Praveen Diwakar | 0a37c6e | 2014-07-04 11:17:41 +0530 | [diff] [blame] | 2156 | |
| 2157 | MODULE_LICENSE("GPL v2"); |