xref: /openbsd/sys/dev/ic/bcm2835_dmac.h (revision fdec9127)
1 /*     $OpenBSD: bcm2835_dmac.h,v 1.1 2020/04/21 18:56:54 tobhe Exp $ */
2 
3 /*
4  * Copyright (c) 2020 Tobias Heider <tobhe@openbsd.org>
5  * Copyright (c) 2019 Neil Ashford <ashfordneil0@gmail.com>
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /*-
21  * Copyright (c) 2014 Jared D. McNeill <jmcneill@invisible.ca>
22  * All rights reserved.
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  * 1. Redistributions of source code must retain the above copyright
28  *    notice, this list of conditions and the following disclaimer.
29  * 2. Redistributions in binary form must reproduce the above copyright
30  *    notice, this list of conditions and the following disclaimer in the
31  *    documentation and/or other materials provided with the distribution.
32  *
33  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
34  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
36  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
37  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
38  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
39  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
40  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
41  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43  * SUCH DAMAGE.
44  */
45 
46 #ifndef BCM2835_DMAC_H
47 #define BCM2835_DMAC_H
48 
49 #define DMAC_CS(n)		(0x00 + (0x100 * (n)))
50 #define  DMAC_CS_RESET		(1<<31)
51 #define  DMAC_CS_ABORT		(1<<30)
52 #define  DMAC_CS_DISDEBUG	(1<<29)
53 #define  DMAC_CS_WAIT_FOR_OUTSTANDING_WRITES (1<<28)
54 #define  DMAC_CS_PANIC_PRIORITY	(((1<<24) - 1) ^ (1<<20))
55 #define  DMAC_CS_PRIORITY	(((1<<20) - 1) ^ (1<<16))
56 #define  DMAC_CS_ERROR		(1<<8)
57 #define  DMAC_CS_WAITING_FOR_OUTSTANDING_WRITES (1<<6)
58 #define  DMAC_CS_DREQ_STOPS_DMA	(1<<5)
59 #define  DMAC_CS_PAUSED		(1<<4)
60 #define  DMAC_CS_DREQ		(1<<3)
61 #define  DMAC_CS_INT		(1<<2)
62 #define  DMAC_CS_END		(1<<1)
63 #define  DMAC_CS_ACTIVE		(1<<0)
64 #define  DMAC_CS_INTMASK	(DMAC_CS_INT|DMAC_CS_END)
65 #define DMAC_CONBLK_AD(n)	(0x04 + (0x100 * (n)))
66 #define DMAC_TI(n)		(0x08 + (0x100 * (n)))
67 #define DMAC_SOURCE_AD(n)	(0x0c + (0x100 * (n)))
68 #define DMAC_DEST_AD(n)		(0x10 + (0x100 * (n)))
69 #define DMAC_TXFR_LEN(n)	(0x14 + (0x100 * (n)))
70 #define DMAC_STRIDE(n)		(0x18 + (0x100 * (n)))
71 #define DMAC_NEXTCONBK(n)	(0x1c + (0x100 * (n)))
72 #define DMAC_DEBUG(n)		(0x20 + (0x100 * (n)))
73 #define  DMAC_DEBUG_LITE	(1<<28)
74 #define  DMAC_DEBUG_VERSION	(((1<<28) - 1) ^ (1<<25))
75 #define  DMAC_DEBUG_DMA_STATE	(((1<<25) - 1) ^ (1<<16))
76 #define  DMAC_DEBUG_DMA_ID	(((1<<16) - 1) ^ (1<<8))
77 #define  DMAC_DEBUG_OUTSTANDING_WRITES (((1<<8) - 1) ^ (1<<4))
78 #define  DMAC_DEBUG_READ_ERROR	(1<<2)
79 #define  DMAC_DEBUG_FIFO_ERROR	(1<<1)
80 #define  DMAC_DEBUG_READ_LAST_NOT_SET_ERROR (1<<0)
81 
82 struct bcmdmac_conblk {
83 	uint32_t cb_ti;
84 #define DMAC_TI_NO_WIDE_BURSTS (1 << 26)
85 #define DMAC_TI_WAITS (((1 << 26) - 1) ^ (1 << 21))
86 #define DMAC_TI_PERMAP (((1 << 21) - 1) ^ (1 << 16))
87 #define  DMAC_TI_PERMAP_BASE (1 << 16)
88 #define DMAC_TI_BURST_LENGTH (((1 << 16) - 1) ^ (1 << 12))
89 #define DMAC_TI_SRC_IGNORE (1 << 11)
90 #define DMAC_TI_SRC_DREQ (1 << 10)
91 #define DMAC_TI_SRC_WIDTH (1 << 9)
92 #define DMAC_TI_SRC_INC (1 << 8)
93 #define DMAC_TI_DEST_IGNORE (1 << 7)
94 #define DMAC_TI_DEST_DREQ (1 << 6)
95 #define DMAC_TI_DEST_WIDTH (1 << 5)
96 #define DMAC_TI_DEST_INC (1 << 4)
97 #define DMAC_TI_WAIT_RESP (1 << 3)
98 #define DMAC_TI_TDMODE (1 << 1)
99 #define DMAC_TI_INTEN (1 << 0)
100 	uint32_t cb_source_ad;
101 	uint32_t cb_dest_ad;
102 	uint32_t cb_txfr_len;
103 #define DMAC_TXFR_LEN_YLENGTH (((1 << 30) - 1) ^ (1 << 16))
104 #define DMAC_TXFR_LEN_XLENGTH (((1 << 16) - 1) ^ (1 << 0))
105 	uint32_t cb_stride;
106 #define DMAC_STRIDE_D_STRIDE (((1 << 32) - 1) ^ (1 << 16))
107 #define DMAC_STRIDE_S_STRIDE (((1 << 16) - 1) ^ (1 << 0))
108 	uint32_t cb_nextconbk;
109 	uint32_t cb_padding[2];
110 } __packed;
111 
112 #define DMAC_INT_STATUS 0xfe0
113 #define DMAC_ENABLE 0xff0
114 
115 enum bcmdmac_type { BCMDMAC_TYPE_NORMAL, BCMDMAC_TYPE_LITE };
116 
117 struct bcmdmac_channel;
118 
119 struct bcmdmac_channel *bcmdmac_alloc(enum bcmdmac_type, int,
120 				  void (*)(uint32_t, uint32_t, void *), void *);
121 void bcmdmac_free(struct bcmdmac_channel *);
122 void bcmdmac_set_conblk_addr(struct bcmdmac_channel *, bus_addr_t);
123 int bcmdmac_transfer(struct bcmdmac_channel *);
124 void bcmdmac_halt(struct bcmdmac_channel *);
125 
126 #endif /* BCM2835_DMAC_H */
127