diff options
Diffstat (limited to 'sound/soc/intel/sst-dsp.c')
| -rw-r--r-- | sound/soc/intel/sst-dsp.c | 385 |
1 files changed, 385 insertions, 0 deletions
diff --git a/sound/soc/intel/sst-dsp.c b/sound/soc/intel/sst-dsp.c new file mode 100644 index 000000000000..0c129fd85ecf --- /dev/null +++ b/sound/soc/intel/sst-dsp.c | |||
| @@ -0,0 +1,385 @@ | |||
| 1 | /* | ||
| 2 | * Intel Smart Sound Technology (SST) DSP Core Driver | ||
| 3 | * | ||
| 4 | * Copyright (C) 2013, Intel Corporation. All rights reserved. | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or | ||
| 7 | * modify it under the terms of the GNU General Public License version | ||
| 8 | * 2 as published by the Free Software Foundation. | ||
| 9 | * | ||
| 10 | * This program is distributed in the hope that it will be useful, | ||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 13 | * GNU General Public License for more details. | ||
| 14 | * | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include <linux/slab.h> | ||
| 18 | #include <linux/export.h> | ||
| 19 | #include <linux/interrupt.h> | ||
| 20 | #include <linux/module.h> | ||
| 21 | #include <linux/platform_device.h> | ||
| 22 | #include <linux/io.h> | ||
| 23 | |||
| 24 | #include "sst-dsp.h" | ||
| 25 | #include "sst-dsp-priv.h" | ||
| 26 | |||
| 27 | #define CREATE_TRACE_POINTS | ||
| 28 | #include <trace/events/intel-sst.h> | ||
| 29 | |||
| 30 | /* Internal generic low-level SST IO functions - can be overidden */ | ||
| 31 | void sst_shim32_write(void __iomem *addr, u32 offset, u32 value) | ||
| 32 | { | ||
| 33 | writel(value, addr + offset); | ||
| 34 | } | ||
| 35 | EXPORT_SYMBOL_GPL(sst_shim32_write); | ||
| 36 | |||
| 37 | u32 sst_shim32_read(void __iomem *addr, u32 offset) | ||
| 38 | { | ||
| 39 | return readl(addr + offset); | ||
| 40 | } | ||
| 41 | EXPORT_SYMBOL_GPL(sst_shim32_read); | ||
| 42 | |||
| 43 | void sst_shim32_write64(void __iomem *addr, u32 offset, u64 value) | ||
| 44 | { | ||
| 45 | memcpy_toio(addr + offset, &value, sizeof(value)); | ||
| 46 | } | ||
| 47 | EXPORT_SYMBOL_GPL(sst_shim32_write64); | ||
| 48 | |||
| 49 | u64 sst_shim32_read64(void __iomem *addr, u32 offset) | ||
| 50 | { | ||
| 51 | u64 val; | ||
| 52 | |||
| 53 | memcpy_fromio(&val, addr + offset, sizeof(val)); | ||
| 54 | return val; | ||
| 55 | } | ||
| 56 | EXPORT_SYMBOL_GPL(sst_shim32_read64); | ||
| 57 | |||
| 58 | static inline void _sst_memcpy_toio_32(volatile u32 __iomem *dest, | ||
| 59 | u32 *src, size_t bytes) | ||
| 60 | { | ||
| 61 | int i, words = bytes >> 2; | ||
| 62 | |||
| 63 | for (i = 0; i < words; i++) | ||
| 64 | writel(src[i], dest + i); | ||
| 65 | } | ||
| 66 | |||
| 67 | static inline void _sst_memcpy_fromio_32(u32 *dest, | ||
| 68 | const volatile __iomem u32 *src, size_t bytes) | ||
| 69 | { | ||
| 70 | int i, words = bytes >> 2; | ||
| 71 | |||
| 72 | for (i = 0; i < words; i++) | ||
| 73 | dest[i] = readl(src + i); | ||
| 74 | } | ||
| 75 | |||
| 76 | void sst_memcpy_toio_32(struct sst_dsp *sst, | ||
| 77 | void __iomem *dest, void *src, size_t bytes) | ||
| 78 | { | ||
| 79 | _sst_memcpy_toio_32(dest, src, bytes); | ||
| 80 | } | ||
| 81 | EXPORT_SYMBOL_GPL(sst_memcpy_toio_32); | ||
| 82 | |||
| 83 | void sst_memcpy_fromio_32(struct sst_dsp *sst, void *dest, | ||
| 84 | void __iomem *src, size_t bytes) | ||
| 85 | { | ||
| 86 | _sst_memcpy_fromio_32(dest, src, bytes); | ||
| 87 | } | ||
| 88 | EXPORT_SYMBOL_GPL(sst_memcpy_fromio_32); | ||
| 89 | |||
| 90 | /* Public API */ | ||
| 91 | void sst_dsp_shim_write(struct sst_dsp *sst, u32 offset, u32 value) | ||
| 92 | { | ||
| 93 | unsigned long flags; | ||
| 94 | |||
| 95 | spin_lock_irqsave(&sst->spinlock, flags); | ||
| 96 | sst->ops->write(sst->addr.shim, offset, value); | ||
| 97 | spin_unlock_irqrestore(&sst->spinlock, flags); | ||
| 98 | } | ||
| 99 | EXPORT_SYMBOL_GPL(sst_dsp_shim_write); | ||
| 100 | |||
| 101 | u32 sst_dsp_shim_read(struct sst_dsp *sst, u32 offset) | ||
| 102 | { | ||
| 103 | unsigned long flags; | ||
| 104 | u32 val; | ||
| 105 | |||
| 106 | spin_lock_irqsave(&sst->spinlock, flags); | ||
| 107 | val = sst->ops->read(sst->addr.shim, offset); | ||
| 108 | spin_unlock_irqrestore(&sst->spinlock, flags); | ||
| 109 | |||
| 110 | return val; | ||
| 111 | } | ||
| 112 | EXPORT_SYMBOL_GPL(sst_dsp_shim_read); | ||
| 113 | |||
| 114 | void sst_dsp_shim_write64(struct sst_dsp *sst, u32 offset, u64 value) | ||
| 115 | { | ||
| 116 | unsigned long flags; | ||
| 117 | |||
| 118 | spin_lock_irqsave(&sst->spinlock, flags); | ||
| 119 | sst->ops->write64(sst->addr.shim, offset, value); | ||
| 120 | spin_unlock_irqrestore(&sst->spinlock, flags); | ||
| 121 | } | ||
| 122 | EXPORT_SYMBOL_GPL(sst_dsp_shim_write64); | ||
| 123 | |||
| 124 | u64 sst_dsp_shim_read64(struct sst_dsp *sst, u32 offset) | ||
| 125 | { | ||
| 126 | unsigned long flags; | ||
| 127 | u64 val; | ||
| 128 | |||
| 129 | spin_lock_irqsave(&sst->spinlock, flags); | ||
| 130 | val = sst->ops->read64(sst->addr.shim, offset); | ||
| 131 | spin_unlock_irqrestore(&sst->spinlock, flags); | ||
| 132 | |||
| 133 | return val; | ||
| 134 | } | ||
| 135 | EXPORT_SYMBOL_GPL(sst_dsp_shim_read64); | ||
| 136 | |||
| 137 | void sst_dsp_shim_write_unlocked(struct sst_dsp *sst, u32 offset, u32 value) | ||
| 138 | { | ||
| 139 | sst->ops->write(sst->addr.shim, offset, value); | ||
| 140 | } | ||
| 141 | EXPORT_SYMBOL_GPL(sst_dsp_shim_write_unlocked); | ||
| 142 | |||
| 143 | u32 sst_dsp_shim_read_unlocked(struct sst_dsp *sst, u32 offset) | ||
| 144 | { | ||
| 145 | return sst->ops->read(sst->addr.shim, offset); | ||
| 146 | } | ||
| 147 | EXPORT_SYMBOL_GPL(sst_dsp_shim_read_unlocked); | ||
| 148 | |||
| 149 | void sst_dsp_shim_write64_unlocked(struct sst_dsp *sst, u32 offset, u64 value) | ||
| 150 | { | ||
| 151 | sst->ops->write64(sst->addr.shim, offset, value); | ||
| 152 | } | ||
| 153 | EXPORT_SYMBOL_GPL(sst_dsp_shim_write64_unlocked); | ||
| 154 | |||
| 155 | u64 sst_dsp_shim_read64_unlocked(struct sst_dsp *sst, u32 offset) | ||
| 156 | { | ||
| 157 | return sst->ops->read64(sst->addr.shim, offset); | ||
| 158 | } | ||
| 159 | EXPORT_SYMBOL_GPL(sst_dsp_shim_read64_unlocked); | ||
| 160 | |||
| 161 | int sst_dsp_shim_update_bits_unlocked(struct sst_dsp *sst, u32 offset, | ||
| 162 | u32 mask, u32 value) | ||
| 163 | { | ||
| 164 | bool change; | ||
| 165 | unsigned int old, new; | ||
| 166 | u32 ret; | ||
| 167 | |||
| 168 | ret = sst_dsp_shim_read_unlocked(sst, offset); | ||
| 169 | |||
| 170 | old = ret; | ||
| 171 | new = (old & (~mask)) | (value & mask); | ||
| 172 | |||
| 173 | change = (old != new); | ||
| 174 | if (change) | ||
| 175 | sst_dsp_shim_write_unlocked(sst, offset, new); | ||
| 176 | |||
| 177 | return change; | ||
| 178 | } | ||
| 179 | EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits_unlocked); | ||
| 180 | |||
| 181 | int sst_dsp_shim_update_bits64_unlocked(struct sst_dsp *sst, u32 offset, | ||
| 182 | u64 mask, u64 value) | ||
| 183 | { | ||
| 184 | bool change; | ||
| 185 | u64 old, new; | ||
| 186 | |||
| 187 | old = sst_dsp_shim_read64_unlocked(sst, offset); | ||
| 188 | |||
| 189 | new = (old & (~mask)) | (value & mask); | ||
| 190 | |||
| 191 | change = (old != new); | ||
| 192 | if (change) | ||
| 193 | sst_dsp_shim_write64_unlocked(sst, offset, new); | ||
| 194 | |||
| 195 | return change; | ||
| 196 | } | ||
| 197 | EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits64_unlocked); | ||
| 198 | |||
| 199 | int sst_dsp_shim_update_bits(struct sst_dsp *sst, u32 offset, | ||
| 200 | u32 mask, u32 value) | ||
| 201 | { | ||
| 202 | unsigned long flags; | ||
| 203 | bool change; | ||
| 204 | |||
| 205 | spin_lock_irqsave(&sst->spinlock, flags); | ||
| 206 | change = sst_dsp_shim_update_bits_unlocked(sst, offset, mask, value); | ||
| 207 | spin_unlock_irqrestore(&sst->spinlock, flags); | ||
| 208 | return change; | ||
| 209 | } | ||
| 210 | EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits); | ||
| 211 | |||
| 212 | int sst_dsp_shim_update_bits64(struct sst_dsp *sst, u32 offset, | ||
| 213 | u64 mask, u64 value) | ||
| 214 | { | ||
| 215 | unsigned long flags; | ||
| 216 | bool change; | ||
| 217 | |||
| 218 | spin_lock_irqsave(&sst->spinlock, flags); | ||
| 219 | change = sst_dsp_shim_update_bits64_unlocked(sst, offset, mask, value); | ||
| 220 | spin_unlock_irqrestore(&sst->spinlock, flags); | ||
| 221 | return change; | ||
| 222 | } | ||
| 223 | EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits64); | ||
| 224 | |||
| 225 | void sst_dsp_dump(struct sst_dsp *sst) | ||
| 226 | { | ||
| 227 | sst->ops->dump(sst); | ||
| 228 | } | ||
| 229 | EXPORT_SYMBOL_GPL(sst_dsp_dump); | ||
| 230 | |||
| 231 | void sst_dsp_reset(struct sst_dsp *sst) | ||
| 232 | { | ||
| 233 | sst->ops->reset(sst); | ||
| 234 | } | ||
| 235 | EXPORT_SYMBOL_GPL(sst_dsp_reset); | ||
| 236 | |||
| 237 | int sst_dsp_boot(struct sst_dsp *sst) | ||
| 238 | { | ||
| 239 | sst->ops->boot(sst); | ||
| 240 | return 0; | ||
| 241 | } | ||
| 242 | EXPORT_SYMBOL_GPL(sst_dsp_boot); | ||
| 243 | |||
| 244 | void sst_dsp_ipc_msg_tx(struct sst_dsp *dsp, u32 msg) | ||
| 245 | { | ||
| 246 | sst_dsp_shim_write_unlocked(dsp, SST_IPCX, msg | SST_IPCX_BUSY); | ||
| 247 | trace_sst_ipc_msg_tx(msg); | ||
| 248 | } | ||
| 249 | EXPORT_SYMBOL_GPL(sst_dsp_ipc_msg_tx); | ||
| 250 | |||
| 251 | u32 sst_dsp_ipc_msg_rx(struct sst_dsp *dsp) | ||
| 252 | { | ||
| 253 | u32 msg; | ||
| 254 | |||
| 255 | msg = sst_dsp_shim_read_unlocked(dsp, SST_IPCX); | ||
| 256 | trace_sst_ipc_msg_rx(msg); | ||
| 257 | |||
| 258 | return msg; | ||
| 259 | } | ||
| 260 | EXPORT_SYMBOL_GPL(sst_dsp_ipc_msg_rx); | ||
| 261 | |||
| 262 | int sst_dsp_mailbox_init(struct sst_dsp *sst, u32 inbox_offset, size_t inbox_size, | ||
| 263 | u32 outbox_offset, size_t outbox_size) | ||
| 264 | { | ||
| 265 | sst->mailbox.in_base = sst->addr.lpe + inbox_offset; | ||
| 266 | sst->mailbox.out_base = sst->addr.lpe + outbox_offset; | ||
| 267 | sst->mailbox.in_size = inbox_size; | ||
| 268 | sst->mailbox.out_size = outbox_size; | ||
| 269 | return 0; | ||
| 270 | } | ||
| 271 | EXPORT_SYMBOL_GPL(sst_dsp_mailbox_init); | ||
| 272 | |||
| 273 | void sst_dsp_outbox_write(struct sst_dsp *sst, void *message, size_t bytes) | ||
| 274 | { | ||
| 275 | u32 i; | ||
| 276 | |||
| 277 | trace_sst_ipc_outbox_write(bytes); | ||
| 278 | |||
| 279 | memcpy_toio(sst->mailbox.out_base, message, bytes); | ||
| 280 | |||
| 281 | for (i = 0; i < bytes; i += 4) | ||
| 282 | trace_sst_ipc_outbox_wdata(i, *(u32 *)(message + i)); | ||
| 283 | } | ||
| 284 | EXPORT_SYMBOL_GPL(sst_dsp_outbox_write); | ||
| 285 | |||
| 286 | void sst_dsp_outbox_read(struct sst_dsp *sst, void *message, size_t bytes) | ||
| 287 | { | ||
| 288 | u32 i; | ||
| 289 | |||
| 290 | trace_sst_ipc_outbox_read(bytes); | ||
| 291 | |||
| 292 | memcpy_fromio(message, sst->mailbox.out_base, bytes); | ||
| 293 | |||
| 294 | for (i = 0; i < bytes; i += 4) | ||
| 295 | trace_sst_ipc_outbox_rdata(i, *(u32 *)(message + i)); | ||
| 296 | } | ||
| 297 | EXPORT_SYMBOL_GPL(sst_dsp_outbox_read); | ||
| 298 | |||
| 299 | void sst_dsp_inbox_write(struct sst_dsp *sst, void *message, size_t bytes) | ||
| 300 | { | ||
| 301 | u32 i; | ||
| 302 | |||
| 303 | trace_sst_ipc_inbox_write(bytes); | ||
| 304 | |||
| 305 | memcpy_toio(sst->mailbox.in_base, message, bytes); | ||
| 306 | |||
| 307 | for (i = 0; i < bytes; i += 4) | ||
| 308 | trace_sst_ipc_inbox_wdata(i, *(u32 *)(message + i)); | ||
| 309 | } | ||
| 310 | EXPORT_SYMBOL_GPL(sst_dsp_inbox_write); | ||
| 311 | |||
| 312 | void sst_dsp_inbox_read(struct sst_dsp *sst, void *message, size_t bytes) | ||
| 313 | { | ||
| 314 | u32 i; | ||
| 315 | |||
| 316 | trace_sst_ipc_inbox_read(bytes); | ||
| 317 | |||
| 318 | memcpy_fromio(message, sst->mailbox.in_base, bytes); | ||
| 319 | |||
| 320 | for (i = 0; i < bytes; i += 4) | ||
| 321 | trace_sst_ipc_inbox_rdata(i, *(u32 *)(message + i)); | ||
| 322 | } | ||
| 323 | EXPORT_SYMBOL_GPL(sst_dsp_inbox_read); | ||
| 324 | |||
| 325 | struct sst_dsp *sst_dsp_new(struct device *dev, | ||
| 326 | struct sst_dsp_device *sst_dev, struct sst_pdata *pdata) | ||
| 327 | { | ||
| 328 | struct sst_dsp *sst; | ||
| 329 | int err; | ||
| 330 | |||
| 331 | dev_dbg(dev, "initialising audio DSP id 0x%x\n", pdata->id); | ||
| 332 | |||
| 333 | sst = devm_kzalloc(dev, sizeof(*sst), GFP_KERNEL); | ||
| 334 | if (sst == NULL) | ||
| 335 | return NULL; | ||
| 336 | |||
| 337 | spin_lock_init(&sst->spinlock); | ||
| 338 | mutex_init(&sst->mutex); | ||
| 339 | sst->dev = dev; | ||
| 340 | sst->thread_context = sst_dev->thread_context; | ||
| 341 | sst->sst_dev = sst_dev; | ||
| 342 | sst->id = pdata->id; | ||
| 343 | sst->irq = pdata->irq; | ||
| 344 | sst->ops = sst_dev->ops; | ||
| 345 | sst->pdata = pdata; | ||
| 346 | INIT_LIST_HEAD(&sst->used_block_list); | ||
| 347 | INIT_LIST_HEAD(&sst->free_block_list); | ||
| 348 | INIT_LIST_HEAD(&sst->module_list); | ||
| 349 | INIT_LIST_HEAD(&sst->fw_list); | ||
| 350 | |||
| 351 | /* Initialise SST Audio DSP */ | ||
| 352 | if (sst->ops->init) { | ||
| 353 | err = sst->ops->init(sst, pdata); | ||
| 354 | if (err < 0) | ||
| 355 | return NULL; | ||
| 356 | } | ||
| 357 | |||
| 358 | /* Register the ISR */ | ||
| 359 | err = request_threaded_irq(sst->irq, sst->ops->irq_handler, | ||
| 360 | sst_dev->thread, IRQF_SHARED, "AudioDSP", sst); | ||
| 361 | if (err) | ||
| 362 | goto irq_err; | ||
| 363 | |||
| 364 | return sst; | ||
| 365 | |||
| 366 | irq_err: | ||
| 367 | if (sst->ops->free) | ||
| 368 | sst->ops->free(sst); | ||
| 369 | |||
| 370 | return NULL; | ||
| 371 | } | ||
| 372 | EXPORT_SYMBOL_GPL(sst_dsp_new); | ||
| 373 | |||
| 374 | void sst_dsp_free(struct sst_dsp *sst) | ||
| 375 | { | ||
| 376 | free_irq(sst->irq, sst); | ||
| 377 | if (sst->ops->free) | ||
| 378 | sst->ops->free(sst); | ||
| 379 | } | ||
| 380 | EXPORT_SYMBOL_GPL(sst_dsp_free); | ||
| 381 | |||
| 382 | /* Module information */ | ||
| 383 | MODULE_AUTHOR("Liam Girdwood"); | ||
| 384 | MODULE_DESCRIPTION("Intel SST Core"); | ||
| 385 | MODULE_LICENSE("GPL v2"); | ||
