1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
4 */
5
6 #ifndef _QCOM_BAM_DMA_H
7 #define _QCOM_BAM_DMA_H
8
9 #include <asm/byteorder.h>
10
11 /*
12 * This data type corresponds to the native Command Element
13 * supported by BAM DMA Engine.
14 *
15 * @cmd_and_addr - upper 8 bits command and lower 24 bits register address.
16 * @data - for write command: content to be written into peripheral register.
17 * for read command: dest addr to write peripheral register value.
18 * @mask - register mask.
19 * @reserved - for future usage.
20 *
21 */
22 struct bam_cmd_element {
23 __le32 cmd_and_addr;
24 __le32 data;
25 __le32 mask;
26 __le32 reserved;
27 };
28
29 /*
30 * This enum indicates the command type in a command element
31 */
32 enum bam_command_type {
33 BAM_WRITE_COMMAND = 0,
34 BAM_READ_COMMAND,
35 };
36
37 /*
38 * prep_bam_ce_le32 - Wrapper function to prepare a single BAM command
39 * element with the data already in le32 format.
40 *
41 * @bam_ce: bam command element
42 * @addr: target address
43 * @cmd: BAM command
44 * @data: actual data for write and dest addr for read in le32
45 */
46 static inline void
bam_prep_ce_le32(struct bam_cmd_element * bam_ce,u32 addr,enum bam_command_type cmd,__le32 data)47 bam_prep_ce_le32(struct bam_cmd_element *bam_ce, u32 addr,
48 enum bam_command_type cmd, __le32 data)
49 {
50 bam_ce->cmd_and_addr =
51 cpu_to_le32((addr & 0xffffff) | ((cmd & 0xff) << 24));
52 bam_ce->data = data;
53 bam_ce->mask = cpu_to_le32(0xffffffff);
54 }
55
56 /*
57 * bam_prep_ce - Wrapper function to prepare a single BAM command element
58 * with the data.
59 *
60 * @bam_ce: BAM command element
61 * @addr: target address
62 * @cmd: BAM command
63 * @data: actual data for write and dest addr for read
64 */
65 static inline void
bam_prep_ce(struct bam_cmd_element * bam_ce,u32 addr,enum bam_command_type cmd,u32 data)66 bam_prep_ce(struct bam_cmd_element *bam_ce, u32 addr,
67 enum bam_command_type cmd, u32 data)
68 {
69 bam_prep_ce_le32(bam_ce, addr, cmd, cpu_to_le32(data));
70 }
71 #endif
72