1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
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.
6 // Copyright(c) 2018 Intel Corporation. All rights reserved.
8 // Author: Keyon Jie <yang.jie@linux.intel.com>
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>
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)
28 EXPORT_SYMBOL(sof_io_write);
30 u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr)
34 EXPORT_SYMBOL(sof_io_read);
36 void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value)
40 EXPORT_SYMBOL(sof_io_write64);
42 u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr)
46 EXPORT_SYMBOL(sof_io_read64);
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);
74 void sof_block_write(struct snd_sof_dev *sdev, u32 bar, u32 offset, void *src,
77 void __iomem *dest = sdev->bar[bar] + offset;
78 const u8 *src_byte = src;
86 /* __iowrite32_copy use 32bit size values so divide by 4 */
87 __iowrite32_copy(dest, src, m);
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,
108 void __iomem *src = sdev->bar[bar] + offset;
110 memcpy_fromio(dest, src, size);
112 EXPORT_SYMBOL(sof_block_read);