.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Intel Smart Sound Technology (SST) DSP Core Driver |
---|
3 | 4 | * |
---|
4 | 5 | * 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 | 6 | */ |
---|
16 | 7 | |
---|
17 | 8 | #include <linux/slab.h> |
---|
.. | .. |
---|
19 | 10 | #include <linux/interrupt.h> |
---|
20 | 11 | #include <linux/module.h> |
---|
21 | 12 | #include <linux/platform_device.h> |
---|
22 | | -#include <linux/io.h> |
---|
| 13 | +#include <linux/io-64-nonatomic-lo-hi.h> |
---|
23 | 14 | #include <linux/delay.h> |
---|
24 | 15 | |
---|
25 | 16 | #include "sst-dsp.h" |
---|
.. | .. |
---|
43 | 34 | |
---|
44 | 35 | void sst_shim32_write64(void __iomem *addr, u32 offset, u64 value) |
---|
45 | 36 | { |
---|
46 | | - memcpy_toio(addr + offset, &value, sizeof(value)); |
---|
| 37 | + writeq(value, addr + offset); |
---|
47 | 38 | } |
---|
48 | 39 | EXPORT_SYMBOL_GPL(sst_shim32_write64); |
---|
49 | 40 | |
---|
50 | 41 | u64 sst_shim32_read64(void __iomem *addr, u32 offset) |
---|
51 | 42 | { |
---|
52 | | - u64 val; |
---|
53 | | - |
---|
54 | | - memcpy_fromio(&val, addr + offset, sizeof(val)); |
---|
55 | | - return val; |
---|
| 43 | + return readq(addr + offset); |
---|
56 | 44 | } |
---|
57 | 45 | EXPORT_SYMBOL_GPL(sst_shim32_read64); |
---|
58 | | - |
---|
59 | | -static inline void _sst_memcpy_toio_32(volatile u32 __iomem *dest, |
---|
60 | | - u32 *src, size_t bytes) |
---|
61 | | -{ |
---|
62 | | - int i, words = bytes >> 2; |
---|
63 | | - |
---|
64 | | - for (i = 0; i < words; i++) |
---|
65 | | - writel(src[i], dest + i); |
---|
66 | | -} |
---|
67 | | - |
---|
68 | | -static inline void _sst_memcpy_fromio_32(u32 *dest, |
---|
69 | | - const volatile __iomem u32 *src, size_t bytes) |
---|
70 | | -{ |
---|
71 | | - int i, words = bytes >> 2; |
---|
72 | | - |
---|
73 | | - for (i = 0; i < words; i++) |
---|
74 | | - dest[i] = readl(src + i); |
---|
75 | | -} |
---|
76 | | - |
---|
77 | | -void sst_memcpy_toio_32(struct sst_dsp *sst, |
---|
78 | | - void __iomem *dest, void *src, size_t bytes) |
---|
79 | | -{ |
---|
80 | | - _sst_memcpy_toio_32(dest, src, bytes); |
---|
81 | | -} |
---|
82 | | -EXPORT_SYMBOL_GPL(sst_memcpy_toio_32); |
---|
83 | | - |
---|
84 | | -void sst_memcpy_fromio_32(struct sst_dsp *sst, void *dest, |
---|
85 | | - void __iomem *src, size_t bytes) |
---|
86 | | -{ |
---|
87 | | - _sst_memcpy_fromio_32(dest, src, bytes); |
---|
88 | | -} |
---|
89 | | -EXPORT_SYMBOL_GPL(sst_memcpy_fromio_32); |
---|
90 | 46 | |
---|
91 | 47 | /* Public API */ |
---|
92 | 48 | void sst_dsp_shim_write(struct sst_dsp *sst, u32 offset, u32 value) |
---|
.. | .. |
---|
112 | 68 | } |
---|
113 | 69 | EXPORT_SYMBOL_GPL(sst_dsp_shim_read); |
---|
114 | 70 | |
---|
115 | | -void sst_dsp_shim_write64(struct sst_dsp *sst, u32 offset, u64 value) |
---|
116 | | -{ |
---|
117 | | - unsigned long flags; |
---|
118 | | - |
---|
119 | | - spin_lock_irqsave(&sst->spinlock, flags); |
---|
120 | | - sst->ops->write64(sst->addr.shim, offset, value); |
---|
121 | | - spin_unlock_irqrestore(&sst->spinlock, flags); |
---|
122 | | -} |
---|
123 | | -EXPORT_SYMBOL_GPL(sst_dsp_shim_write64); |
---|
124 | | - |
---|
125 | | -u64 sst_dsp_shim_read64(struct sst_dsp *sst, u32 offset) |
---|
126 | | -{ |
---|
127 | | - unsigned long flags; |
---|
128 | | - u64 val; |
---|
129 | | - |
---|
130 | | - spin_lock_irqsave(&sst->spinlock, flags); |
---|
131 | | - val = sst->ops->read64(sst->addr.shim, offset); |
---|
132 | | - spin_unlock_irqrestore(&sst->spinlock, flags); |
---|
133 | | - |
---|
134 | | - return val; |
---|
135 | | -} |
---|
136 | | -EXPORT_SYMBOL_GPL(sst_dsp_shim_read64); |
---|
137 | | - |
---|
138 | 71 | void sst_dsp_shim_write_unlocked(struct sst_dsp *sst, u32 offset, u32 value) |
---|
139 | 72 | { |
---|
140 | 73 | sst->ops->write(sst->addr.shim, offset, value); |
---|
.. | .. |
---|
146 | 79 | return sst->ops->read(sst->addr.shim, offset); |
---|
147 | 80 | } |
---|
148 | 81 | EXPORT_SYMBOL_GPL(sst_dsp_shim_read_unlocked); |
---|
149 | | - |
---|
150 | | -void sst_dsp_shim_write64_unlocked(struct sst_dsp *sst, u32 offset, u64 value) |
---|
151 | | -{ |
---|
152 | | - sst->ops->write64(sst->addr.shim, offset, value); |
---|
153 | | -} |
---|
154 | | -EXPORT_SYMBOL_GPL(sst_dsp_shim_write64_unlocked); |
---|
155 | | - |
---|
156 | | -u64 sst_dsp_shim_read64_unlocked(struct sst_dsp *sst, u32 offset) |
---|
157 | | -{ |
---|
158 | | - return sst->ops->read64(sst->addr.shim, offset); |
---|
159 | | -} |
---|
160 | | -EXPORT_SYMBOL_GPL(sst_dsp_shim_read64_unlocked); |
---|
161 | 82 | |
---|
162 | 83 | int sst_dsp_shim_update_bits_unlocked(struct sst_dsp *sst, u32 offset, |
---|
163 | 84 | u32 mask, u32 value) |
---|
.. | .. |
---|
178 | 99 | return change; |
---|
179 | 100 | } |
---|
180 | 101 | EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits_unlocked); |
---|
181 | | - |
---|
182 | | -int sst_dsp_shim_update_bits64_unlocked(struct sst_dsp *sst, u32 offset, |
---|
183 | | - u64 mask, u64 value) |
---|
184 | | -{ |
---|
185 | | - bool change; |
---|
186 | | - u64 old, new; |
---|
187 | | - |
---|
188 | | - old = sst_dsp_shim_read64_unlocked(sst, offset); |
---|
189 | | - |
---|
190 | | - new = (old & (~mask)) | (value & mask); |
---|
191 | | - |
---|
192 | | - change = (old != new); |
---|
193 | | - if (change) |
---|
194 | | - sst_dsp_shim_write64_unlocked(sst, offset, new); |
---|
195 | | - |
---|
196 | | - return change; |
---|
197 | | -} |
---|
198 | | -EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits64_unlocked); |
---|
199 | 102 | |
---|
200 | 103 | /* This is for registers bits with attribute RWC */ |
---|
201 | 104 | void sst_dsp_shim_update_bits_forced_unlocked(struct sst_dsp *sst, u32 offset, |
---|
.. | .. |
---|
225 | 128 | return change; |
---|
226 | 129 | } |
---|
227 | 130 | EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits); |
---|
228 | | - |
---|
229 | | -int sst_dsp_shim_update_bits64(struct sst_dsp *sst, u32 offset, |
---|
230 | | - u64 mask, u64 value) |
---|
231 | | -{ |
---|
232 | | - unsigned long flags; |
---|
233 | | - bool change; |
---|
234 | | - |
---|
235 | | - spin_lock_irqsave(&sst->spinlock, flags); |
---|
236 | | - change = sst_dsp_shim_update_bits64_unlocked(sst, offset, mask, value); |
---|
237 | | - spin_unlock_irqrestore(&sst->spinlock, flags); |
---|
238 | | - return change; |
---|
239 | | -} |
---|
240 | | -EXPORT_SYMBOL_GPL(sst_dsp_shim_update_bits64); |
---|
241 | 131 | |
---|
242 | 132 | /* This is for registers bits with attribute RWC */ |
---|
243 | 133 | void sst_dsp_shim_update_bits_forced(struct sst_dsp *sst, u32 offset, |
---|
.. | .. |
---|
290 | 180 | return -ETIME; |
---|
291 | 181 | } |
---|
292 | 182 | EXPORT_SYMBOL_GPL(sst_dsp_register_poll); |
---|
293 | | - |
---|
294 | | -void sst_dsp_dump(struct sst_dsp *sst) |
---|
295 | | -{ |
---|
296 | | - if (sst->ops->dump) |
---|
297 | | - sst->ops->dump(sst); |
---|
298 | | -} |
---|
299 | | -EXPORT_SYMBOL_GPL(sst_dsp_dump); |
---|
300 | | - |
---|
301 | | -void sst_dsp_reset(struct sst_dsp *sst) |
---|
302 | | -{ |
---|
303 | | - if (sst->ops->reset) |
---|
304 | | - sst->ops->reset(sst); |
---|
305 | | -} |
---|
306 | | -EXPORT_SYMBOL_GPL(sst_dsp_reset); |
---|
307 | | - |
---|
308 | | -int sst_dsp_boot(struct sst_dsp *sst) |
---|
309 | | -{ |
---|
310 | | - if (sst->ops->boot) |
---|
311 | | - sst->ops->boot(sst); |
---|
312 | | - |
---|
313 | | - return 0; |
---|
314 | | -} |
---|
315 | | -EXPORT_SYMBOL_GPL(sst_dsp_boot); |
---|
316 | | - |
---|
317 | | -int sst_dsp_wake(struct sst_dsp *sst) |
---|
318 | | -{ |
---|
319 | | - if (sst->ops->wake) |
---|
320 | | - return sst->ops->wake(sst); |
---|
321 | | - |
---|
322 | | - return 0; |
---|
323 | | -} |
---|
324 | | -EXPORT_SYMBOL_GPL(sst_dsp_wake); |
---|
325 | | - |
---|
326 | | -void sst_dsp_sleep(struct sst_dsp *sst) |
---|
327 | | -{ |
---|
328 | | - if (sst->ops->sleep) |
---|
329 | | - sst->ops->sleep(sst); |
---|
330 | | -} |
---|
331 | | -EXPORT_SYMBOL_GPL(sst_dsp_sleep); |
---|
332 | | - |
---|
333 | | -void sst_dsp_stall(struct sst_dsp *sst) |
---|
334 | | -{ |
---|
335 | | - if (sst->ops->stall) |
---|
336 | | - sst->ops->stall(sst); |
---|
337 | | -} |
---|
338 | | -EXPORT_SYMBOL_GPL(sst_dsp_stall); |
---|
339 | | - |
---|
340 | | -void sst_dsp_ipc_msg_tx(struct sst_dsp *dsp, u32 msg) |
---|
341 | | -{ |
---|
342 | | - sst_dsp_shim_write_unlocked(dsp, SST_IPCX, msg | SST_IPCX_BUSY); |
---|
343 | | - trace_sst_ipc_msg_tx(msg); |
---|
344 | | -} |
---|
345 | | -EXPORT_SYMBOL_GPL(sst_dsp_ipc_msg_tx); |
---|
346 | | - |
---|
347 | | -u32 sst_dsp_ipc_msg_rx(struct sst_dsp *dsp) |
---|
348 | | -{ |
---|
349 | | - u32 msg; |
---|
350 | | - |
---|
351 | | - msg = sst_dsp_shim_read_unlocked(dsp, SST_IPCX); |
---|
352 | | - trace_sst_ipc_msg_rx(msg); |
---|
353 | | - |
---|
354 | | - return msg; |
---|
355 | | -} |
---|
356 | | -EXPORT_SYMBOL_GPL(sst_dsp_ipc_msg_rx); |
---|
357 | 183 | |
---|
358 | 184 | int sst_dsp_mailbox_init(struct sst_dsp *sst, u32 inbox_offset, size_t inbox_size, |
---|
359 | 185 | u32 outbox_offset, size_t outbox_size) |
---|