xref: /freebsd/sys/arm/freescale/imx/imx6_sdma.h (revision 1719886f6d08408b834d270c59ffcfd821c8f63a)
1 /*-
2  * Copyright (c) 2015 Ruslan Bukin <br@bsdpad.com>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #define	SDMAARM_MC0PTR		0x00	/* ARM platform Channel 0 Pointer */
28 #define	SDMAARM_INTR		0x04	/* Channel Interrupts */
29 #define	SDMAARM_STOP_STAT	0x08	/* Channel Stop/Channel Status */
30 #define	SDMAARM_HSTART		0x0C	/* Channel Start */
31 #define	SDMAARM_EVTOVR		0x10	/* Channel Event Override */
32 #define	SDMAARM_DSPOVR		0x14	/* Channel BP Override */
33 #define	SDMAARM_HOSTOVR		0x18	/* Channel ARM platform Override */
34 #define	SDMAARM_EVTPEND		0x1C	/* Channel Event Pending */
35 #define	SDMAARM_RESET		0x24	/* Reset Register */
36 #define	SDMAARM_EVTERR		0x28	/* DMA Request Error Register */
37 #define	SDMAARM_INTRMASK	0x2C	/* Channel ARM platform Interrupt Mask */
38 #define	SDMAARM_PSW		0x30	/* Schedule Status */
39 #define	SDMAARM_EVTERRDBG	0x34	/* DMA Request Error Register */
40 #define	SDMAARM_CONFIG		0x38	/* Configuration Register */
41 #define	 CONFIG_CSM		0x3
42 #define	SDMAARM_SDMA_LOCK	0x3C	/* SDMA LOCK */
43 #define	SDMAARM_ONCE_ENB	0x40	/* OnCE Enable */
44 #define	SDMAARM_ONCE_DATA	0x44	/* OnCE Data Register */
45 #define	SDMAARM_ONCE_INSTR	0x48	/* OnCE Instruction Register */
46 #define	SDMAARM_ONCE_STAT	0x4C	/* OnCE Status Register */
47 #define	SDMAARM_ONCE_CMD	0x50	/* OnCE Command Register */
48 #define	SDMAARM_ILLINSTADDR	0x58	/* Illegal Instruction Trap Address */
49 #define	SDMAARM_CHN0ADDR	0x5C	/* Channel 0 Boot Address */
50 #define	SDMAARM_EVT_MIRROR	0x60	/* DMA Requests */
51 #define	SDMAARM_EVT_MIRROR2	0x64	/* DMA Requests 2 */
52 #define	SDMAARM_XTRIG_CONF1	0x70	/* Cross-Trigger Events Configuration Register 1 */
53 #define	SDMAARM_XTRIG_CONF2	0x74	/* Cross-Trigger Events Configuration Register 2 */
54 #define	SDMAARM_SDMA_CHNPRI(n)	(0x100 + 0x4 * n)	/* Channel Priority Registers */
55 #define	SDMAARM_CHNENBL(n)	(0x200 + 0x4 * n)	/* Channel Enable RAM */
56 
57 /* SDMA Event Mappings */
58 #define	SSI1_RX_1	35
59 #define	SSI1_TX_1	36
60 #define	SSI1_RX_0	37
61 #define	SSI1_TX_0	38
62 #define	SSI2_RX_1	39
63 #define	SSI2_TX_1	40
64 #define	SSI2_RX_0	41
65 #define	SSI2_TX_0	42
66 #define	SSI3_RX_1	43
67 #define	SSI3_TX_1	44
68 #define	SSI3_RX_0	45
69 #define	SSI3_TX_0	46
70 
71 #define	C0_ADDR		0x01
72 #define	C0_LOAD		0x02
73 #define	C0_DUMP		0x03
74 #define	C0_SETCTX	0x07
75 #define	C0_GETCTX	0x03
76 #define	C0_SETDM	0x01
77 #define	C0_SETPM	0x04
78 #define	C0_GETDM	0x02
79 #define	C0_GETPM	0x08
80 
81 #define	BD_DONE		0x01
82 #define	BD_WRAP		0x02
83 #define	BD_CONT		0x04
84 #define	BD_INTR		0x08
85 #define	BD_RROR		0x10
86 #define	BD_LAST		0x20
87 #define	BD_EXTD		0x80
88 
89 /* sDMA data transfer length */
90 #define	CMD_4BYTES	0
91 #define	CMD_3BYTES	3
92 #define	CMD_2BYTES	2
93 #define	CMD_1BYTES	1
94 
95 struct sdma_firmware_header {
96 	uint32_t	magic;
97 	uint32_t	version_major;
98 	uint32_t	version_minor;
99 	uint32_t	script_addrs_start;
100 	uint32_t	num_script_addrs;
101 	uint32_t	ram_code_start;
102 	uint32_t	ram_code_size;
103 };
104 
105 struct sdma_mode_count {
106 	uint16_t count;
107 	uint8_t status;
108 	uint8_t command;
109 };
110 
111 struct sdma_buffer_descriptor {
112 	struct sdma_mode_count	mode;
113 	uint32_t		buffer_addr;
114 	uint32_t		ext_buffer_addr;
115 } __packed;
116 
117 struct sdma_channel_control {
118 	uint32_t	current_bd_ptr;
119 	uint32_t	base_bd_ptr;
120 	uint32_t	unused[2];
121 } __packed;
122 
123 struct sdma_state_registers {
124 	uint32_t	pc     :14;
125 	uint32_t	unused1: 1;
126 	uint32_t	t      : 1;
127 	uint32_t	rpc    :14;
128 	uint32_t	unused0: 1;
129 	uint32_t	sf     : 1;
130 	uint32_t	spc    :14;
131 	uint32_t	unused2: 1;
132 	uint32_t	df     : 1;
133 	uint32_t	epc    :14;
134 	uint32_t	lm     : 2;
135 } __packed;
136 
137 struct sdma_context_data {
138 	struct sdma_state_registers	channel_state;
139 	uint32_t	gReg[8];
140 	uint32_t	mda;
141 	uint32_t	msa;
142 	uint32_t	ms;
143 	uint32_t	md;
144 	uint32_t	pda;
145 	uint32_t	psa;
146 	uint32_t	ps;
147 	uint32_t	pd;
148 	uint32_t	ca;
149 	uint32_t	cs;
150 	uint32_t	dda;
151 	uint32_t	dsa;
152 	uint32_t	ds;
153 	uint32_t	dd;
154 	uint32_t	unused[8];
155 } __packed;
156 
157 /* SDMA firmware script pointers */
158 struct sdma_script_start_addrs {
159 	int32_t	ap_2_ap_addr;
160 	int32_t	ap_2_bp_addr;
161 	int32_t	ap_2_ap_fixed_addr;
162 	int32_t	bp_2_ap_addr;
163 	int32_t	loopback_on_dsp_side_addr;
164 	int32_t	mcu_interrupt_only_addr;
165 	int32_t	firi_2_per_addr;
166 	int32_t	firi_2_mcu_addr;
167 	int32_t	per_2_firi_addr;
168 	int32_t	mcu_2_firi_addr;
169 	int32_t	uart_2_per_addr;
170 	int32_t	uart_2_mcu_addr;
171 	int32_t	per_2_app_addr;
172 	int32_t	mcu_2_app_addr;
173 	int32_t	per_2_per_addr;
174 	int32_t	uartsh_2_per_addr;
175 	int32_t	uartsh_2_mcu_addr;
176 	int32_t	per_2_shp_addr;
177 	int32_t	mcu_2_shp_addr;
178 	int32_t	ata_2_mcu_addr;
179 	int32_t	mcu_2_ata_addr;
180 	int32_t	app_2_per_addr;
181 	int32_t	app_2_mcu_addr;
182 	int32_t	shp_2_per_addr;
183 	int32_t	shp_2_mcu_addr;
184 	int32_t	mshc_2_mcu_addr;
185 	int32_t	mcu_2_mshc_addr;
186 	int32_t	spdif_2_mcu_addr;
187 	int32_t	mcu_2_spdif_addr;
188 	int32_t	asrc_2_mcu_addr;
189 	int32_t	ext_mem_2_ipu_addr;
190 	int32_t	descrambler_addr;
191 	int32_t	dptc_dvfs_addr;
192 	int32_t	utra_addr;
193 	int32_t	ram_code_start_addr;
194 	int32_t	mcu_2_ssish_addr;
195 	int32_t	ssish_2_mcu_addr;
196 	int32_t	hdmi_dma_addr;
197 };
198 
199 #define	SDMA_N_CHANNELS 32
200 #define	SDMA_N_EVENTS	48
201 #define	FW_HEADER_MAGIC	0x414d4453
202 
203 struct sdma_channel {
204 	struct sdma_conf		*conf;
205 	struct sdma_buffer_descriptor	*bd;
206 	uint8_t 			in_use;
207 };
208 
209 struct sdma_softc {
210 	struct resource			*res[2];
211 	bus_space_tag_t			bst;
212 	bus_space_handle_t		bsh;
213 	device_t			dev;
214 	void				*ih;
215 	struct sdma_channel_control	*ccb;
216 	struct sdma_buffer_descriptor	*bd0;
217 	struct sdma_context_data	*context;
218 	struct sdma_channel		channel[SDMA_N_CHANNELS];
219 	uint32_t			num_bd;
220 	uint32_t			ccb_phys;
221 	uint32_t			context_phys;
222 	const struct sdma_firmware_header	*fw_header;
223 	const struct sdma_script_start_addrs	*fw_scripts;
224 };
225 
226 struct sdma_conf {
227 	bus_addr_t	saddr;
228 	bus_addr_t	daddr;
229 	uint32_t	word_length;
230 	uint32_t	nbits;
231 	uint32_t	command;
232 	uint32_t	num_bd;
233 	uint32_t	event;
234 	uint32_t	period;
235 	uint32_t	(*ih)(void *, int);
236 	void		*ih_user;
237 };
238 
239 int sdma_configure(int, struct sdma_conf *);
240 int sdma_start(int);
241 int sdma_stop(int);
242 int sdma_alloc(void);
243 int sdma_free(int);
244