1 // SPDX-License-Identifier: (GPL-2.0-only 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-2022 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 <asm/unaligned.h>
14 #include <sound/soc.h>
15 #include <sound/sof.h>
22 * The sof_io_xyz() wrappers are typically referenced in snd_sof_dsp_ops
23 * structures and cannot be inlined.
26 void sof_io_write(struct snd_sof_dev *sdev, void __iomem *addr, u32 value)
30 EXPORT_SYMBOL(sof_io_write);
32 u32 sof_io_read(struct snd_sof_dev *sdev, void __iomem *addr)
36 EXPORT_SYMBOL(sof_io_read);
38 void sof_io_write64(struct snd_sof_dev *sdev, void __iomem *addr, u64 value)
42 EXPORT_SYMBOL(sof_io_write64);
44 u64 sof_io_read64(struct snd_sof_dev *sdev, void __iomem *addr)
48 EXPORT_SYMBOL(sof_io_read64);
54 void sof_mailbox_write(struct snd_sof_dev *sdev, u32 offset,
55 void *message, size_t bytes)
57 void __iomem *dest = sdev->bar[sdev->mailbox_bar] + offset;
59 memcpy_toio(dest, message, bytes);
61 EXPORT_SYMBOL(sof_mailbox_write);
63 void sof_mailbox_read(struct snd_sof_dev *sdev, u32 offset,
64 void *message, size_t bytes)
66 void __iomem *src = sdev->bar[sdev->mailbox_bar] + offset;
68 memcpy_fromio(message, src, bytes);
70 EXPORT_SYMBOL(sof_mailbox_read);
76 int sof_block_write(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
77 u32 offset, void *src, size_t size)
79 int bar = snd_sof_dsp_get_bar_index(sdev, blk_type);
80 const u8 *src_byte = src;
89 dest = sdev->bar[bar] + offset;
94 /* __iowrite32_copy use 32bit size values so divide by 4 */
95 __iowrite32_copy(dest, src, m);
98 affected_mask = (1 << (8 * n)) - 1;
100 /* first read the 32bit data of dest, then change affected
101 * bytes, and write back to dest. For unaffected bytes, it
102 * should not be changed
104 tmp = ioread32(dest + m * 4);
105 tmp &= ~affected_mask;
107 tmp |= *(u32 *)(src_byte + m * 4) & affected_mask;
108 iowrite32(tmp, dest + m * 4);
113 EXPORT_SYMBOL(sof_block_write);
115 int sof_block_read(struct snd_sof_dev *sdev, enum snd_sof_fw_blk_type blk_type,
116 u32 offset, void *dest, size_t size)
118 int bar = snd_sof_dsp_get_bar_index(sdev, blk_type);
123 memcpy_fromio(dest, sdev->bar[bar] + offset, size);
127 EXPORT_SYMBOL(sof_block_read);