Merge tag 'for-linus-20190706' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / sound / soc / sof / utils.c
blob2ac4c3da03206d4ed614630d19bebfb72e18714d
1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
2 //
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
5 //
6 // Copyright(c) 2018 Intel Corporation. All rights reserved.
7 //
8 // Author: Keyon Jie <yang.jie@linux.intel.com>
9 //
11 #include <linux/io-64-nonatomic-lo-hi.h>
12 #include <linux/platform_device.h>
13 #include <sound/soc.h>
14 #include <sound/sof.h>
15 #include "sof-priv.h"
18 * Register IO
20 * The sof_io_xyz() wrappers are typically referenced in snd_sof_dsp_ops
21 * structures and cannot be inlined.
24 void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value)
26 writel(value, addr);
28 EXPORT_SYMBOL(sof_io_write);
30 u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr)
32 return readl(addr);
34 EXPORT_SYMBOL(sof_io_read);
36 void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value)
38 writeq(value, addr);
40 EXPORT_SYMBOL(sof_io_write64);
42 u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr)
44 return readq(addr);
46 EXPORT_SYMBOL(sof_io_read64);
49 * IPC Mailbox IO
52 void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
53 void *message, size_t bytes)
55 void __iomem *dest = sdev->bar[sdev->mailbox_bar] + offset;
57 memcpy_toio(dest, message, bytes);
59 EXPORT_SYMBOL(sof_mailbox_write);
61 void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
62 void *message, size_t bytes)
64 void __iomem *src = sdev->bar[sdev->mailbox_bar] + offset;
66 memcpy_fromio(message, src, bytes);
68 EXPORT_SYMBOL(sof_mailbox_read);
71 * Memory copy.
74 void sof_block_write(struct snd_sof_dev *sdev, u32 bar, u32 offset, void *src,
75 size_t size)
77 void __iomem *dest = sdev->bar[bar] + offset;
78 const u8 *src_byte = src;
79 u32 affected_mask;
80 u32 tmp;
81 int m, n;
83 m = size / 4;
84 n = size % 4;
86 /* __iowrite32_copy use 32bit size values so divide by 4 */
87 __iowrite32_copy(dest, src, m);
89 if (n) {
90 affected_mask = (1 << (8 * n)) - 1;
92 /* first read the 32bit data of dest, then change affected
93 * bytes, and write back to dest. For unaffected bytes, it
94 * should not be changed
96 tmp = ioread32(dest + m * 4);
97 tmp &= ~affected_mask;
99 tmp |= *(u32 *)(src_byte + m * 4) & affected_mask;
100 iowrite32(tmp, dest + m * 4);
103 EXPORT_SYMBOL(sof_block_write);
105 void sof_block_read(struct snd_sof_dev *sdev, u32 bar, u32 offset, void *dest,
106 size_t size)
108 void __iomem *src = sdev->bar[bar] + offset;
110 memcpy_fromio(dest, src, size);
112 EXPORT_SYMBOL(sof_block_read);