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: lower 32 bits of destination address.
18 * @mask - For write command: register write mask.
19 * For read command on BAM v1.6.0+: upper 4 bits of destination address.
20 * For read command on BAM < v1.6.0: ignored by hardware.
21 * Setting to 0 ensures 32-bit addressing compatibility.
22 * @reserved - for future usage.
23 *
24 */
25 struct bam_cmd_element {
26 __le32 cmd_and_addr;
27 __le32 data;
28 __le32 mask;
29 __le32 reserved;
30 };
31
32 /*
33 * This enum indicates the command type in a command element
34 */
35 enum bam_command_type {
36 BAM_WRITE_COMMAND = 0,
37 BAM_READ_COMMAND,
38 };
39
40 /*
41 * prep_bam_ce_le32 - Wrapper function to prepare a single BAM command
42 * element with the data already in le32 format.
43 *
44 * @bam_ce: bam command element
45 * @addr: target address
46 * @cmd: BAM command
47 * @data: actual data for write and dest addr for read in le32
48 *
49 * For BAM v1.6.0+, the mask field behavior depends on command type:
50 * - Write commands: mask = write mask (typically 0xffffffff)
51 * - Read commands: mask = upper 4 bits of destination address (0 for 32-bit)
52 */
53 static inline void
bam_prep_ce_le32(struct bam_cmd_element * bam_ce,u32 addr,enum bam_command_type cmd,__le32 data)54 bam_prep_ce_le32(struct bam_cmd_element *bam_ce, u32 addr,
55 enum bam_command_type cmd, __le32 data)
56 {
57 bam_ce->cmd_and_addr =
58 cpu_to_le32((addr & 0xffffff) | ((cmd & 0xff) << 24));
59 bam_ce->data = data;
60 if (cmd == BAM_READ_COMMAND)
61 bam_ce->mask = cpu_to_le32(0x0); /* 32-bit addressing */
62 else
63 bam_ce->mask = cpu_to_le32(0xffffffff); /* Write mask */
64 bam_ce->reserved = 0;
65 }
66
67 /*
68 * bam_prep_ce - Wrapper function to prepare a single BAM command element
69 * with the data.
70 *
71 * @bam_ce: BAM command element
72 * @addr: target address
73 * @cmd: BAM command
74 * @data: actual data for write and destination address for read
75 */
76 static inline void
bam_prep_ce(struct bam_cmd_element * bam_ce,u32 addr,enum bam_command_type cmd,u32 data)77 bam_prep_ce(struct bam_cmd_element *bam_ce, u32 addr,
78 enum bam_command_type cmd, u32 data)
79 {
80 bam_prep_ce_le32(bam_ce, addr, cmd, cpu_to_le32(data));
81 }
82 #endif
83