1e53470feSOleksandr Tymoshenko /*-
251369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause
351369649SPedro F. Giffuni *
4e53470feSOleksandr Tymoshenko * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
5e53470feSOleksandr Tymoshenko * Copyright (c) 2012 Damjan Marion <dmarion@Freebsd.org>
6e53470feSOleksandr Tymoshenko * All rights reserved.
7e53470feSOleksandr Tymoshenko *
8e53470feSOleksandr Tymoshenko * Redistribution and use in source and binary forms, with or without
9e53470feSOleksandr Tymoshenko * modification, are permitted provided that the following conditions
10e53470feSOleksandr Tymoshenko * are met:
11e53470feSOleksandr Tymoshenko * 1. Redistributions of source code must retain the above copyright
12e53470feSOleksandr Tymoshenko * notice, this list of conditions and the following disclaimer.
13e53470feSOleksandr Tymoshenko * 2. Redistributions in binary form must reproduce the above copyright
14e53470feSOleksandr Tymoshenko * notice, this list of conditions and the following disclaimer in the
15e53470feSOleksandr Tymoshenko * documentation and/or other materials provided with the distribution.
16e53470feSOleksandr Tymoshenko * 3. Neither the name of authors nor the names of its contributors may be
17e53470feSOleksandr Tymoshenko * used to endorse or promote products derived from this software without
18e53470feSOleksandr Tymoshenko * specific prior written permission.
19e53470feSOleksandr Tymoshenko *
20e53470feSOleksandr Tymoshenko * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21e53470feSOleksandr Tymoshenko * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22e53470feSOleksandr Tymoshenko * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23e53470feSOleksandr Tymoshenko * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24e53470feSOleksandr Tymoshenko * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25e53470feSOleksandr Tymoshenko * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26e53470feSOleksandr Tymoshenko * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27e53470feSOleksandr Tymoshenko * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28e53470feSOleksandr Tymoshenko * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29e53470feSOleksandr Tymoshenko * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30e53470feSOleksandr Tymoshenko * SUCH DAMAGE.
31e53470feSOleksandr Tymoshenko */
32e53470feSOleksandr Tymoshenko
33e53470feSOleksandr Tymoshenko #include <sys/param.h>
34e53470feSOleksandr Tymoshenko #include <sys/systm.h>
35e53470feSOleksandr Tymoshenko #include <sys/endian.h>
36e53470feSOleksandr Tymoshenko #include <sys/mbuf.h>
37e53470feSOleksandr Tymoshenko #include <sys/lock.h>
38e53470feSOleksandr Tymoshenko #include <sys/mutex.h>
39e53470feSOleksandr Tymoshenko #include <sys/kernel.h>
40e53470feSOleksandr Tymoshenko #include <sys/module.h>
41e53470feSOleksandr Tymoshenko #include <sys/socket.h>
42e53470feSOleksandr Tymoshenko #include <sys/sysctl.h>
43e53470feSOleksandr Tymoshenko
44e53470feSOleksandr Tymoshenko #include <sys/sockio.h>
45e53470feSOleksandr Tymoshenko #include <sys/bus.h>
46e53470feSOleksandr Tymoshenko #include <machine/bus.h>
47e53470feSOleksandr Tymoshenko #include <sys/rman.h>
48e53470feSOleksandr Tymoshenko #include <machine/resource.h>
49e53470feSOleksandr Tymoshenko
50e53470feSOleksandr Tymoshenko #include <dev/ofw/ofw_bus.h>
51e53470feSOleksandr Tymoshenko #include <dev/ofw/ofw_bus_subr.h>
52e53470feSOleksandr Tymoshenko
53e53470feSOleksandr Tymoshenko #include <arm/ti/ti_scm.h>
540050ea24SMichal Meloun #include <arm/ti/ti_sysc.h>
55e53470feSOleksandr Tymoshenko
56e53470feSOleksandr Tymoshenko #include <arm/ti/ti_edma3.h>
57e53470feSOleksandr Tymoshenko
58e53470feSOleksandr Tymoshenko #define TI_EDMA3_NUM_TCS 3
59e53470feSOleksandr Tymoshenko #define TI_EDMA3_NUM_IRQS 3
60e53470feSOleksandr Tymoshenko #define TI_EDMA3_NUM_DMA_CHS 64
61e53470feSOleksandr Tymoshenko #define TI_EDMA3_NUM_QDMA_CHS 8
62e53470feSOleksandr Tymoshenko
63e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_PID 0x000
64e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_DCHMAP(p) (0x100 + ((p)*4))
65e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_DMAQNUM(n) (0x240 + ((n)*4))
66e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_QDMAQNUM 0x260
67e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_EMCR 0x308
68e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_EMCRH 0x30C
69e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_QEMCR 0x314
70e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_CCERR 0x318
71e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_CCERRCLR 0x31C
72e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_DRAE(p) (0x340 + ((p)*8))
73e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_DRAEH(p) (0x344 + ((p)*8))
74e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_QRAE(p) (0x380 + ((p)*4))
75e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_S_ESR(p) (0x2010 + ((p)*0x200))
76e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_S_ESRH(p) (0x2014 + ((p)*0x200))
77e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_S_SECR(p) (0x2040 + ((p)*0x200))
78e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_S_SECRH(p) (0x2044 + ((p)*0x200))
79e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_S_EESR(p) (0x2030 + ((p)*0x200))
80e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_S_EESRH(p) (0x2034 + ((p)*0x200))
81e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_S_IESR(p) (0x2060 + ((p)*0x200))
82e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_S_IESRH(p) (0x2064 + ((p)*0x200))
83e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_S_IPR(p) (0x2068 + ((p)*0x200))
84e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_S_IPRH(p) (0x206C + ((p)*0x200))
85e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_S_QEESR(p) (0x208C + ((p)*0x200))
86e53470feSOleksandr Tymoshenko
87e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_PARAM_OFFSET 0x4000
88e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_OPT(p) (TI_EDMA3CC_PARAM_OFFSET + 0x0 + ((p)*0x20))
89e53470feSOleksandr Tymoshenko
90e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_DMAQNUM_SET(c,q) ((0x7 & (q)) << (((c) % 8) * 4))
91e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_DMAQNUM_CLR(c) (~(0x7 << (((c) % 8) * 4)))
92e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_QDMAQNUM_SET(c,q) ((0x7 & (q)) << ((c) * 4))
93e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_QDMAQNUM_CLR(c) (~(0x7 << ((c) * 4)))
94e53470feSOleksandr Tymoshenko
95e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_OPT_TCC_CLR (~(0x3F000))
96e53470feSOleksandr Tymoshenko #define TI_EDMA3CC_OPT_TCC_SET(p) (((0x3F000 >> 12) & (p)) << 12)
97e53470feSOleksandr Tymoshenko
98e53470feSOleksandr Tymoshenko struct ti_edma3_softc {
99e53470feSOleksandr Tymoshenko device_t sc_dev;
1005b03aba6SOleksandr Tymoshenko /*
1015b03aba6SOleksandr Tymoshenko * We use one-element array in case if we need to add
1025b03aba6SOleksandr Tymoshenko * mem resources for transfer control windows
1035b03aba6SOleksandr Tymoshenko */
1045b03aba6SOleksandr Tymoshenko struct resource * mem_res[1];
105e53470feSOleksandr Tymoshenko struct resource * irq_res[TI_EDMA3_NUM_IRQS];
106e53470feSOleksandr Tymoshenko void *ih_cookie[TI_EDMA3_NUM_IRQS];
107e53470feSOleksandr Tymoshenko };
108e53470feSOleksandr Tymoshenko
109e53470feSOleksandr Tymoshenko static struct ti_edma3_softc *ti_edma3_sc = NULL;
110e53470feSOleksandr Tymoshenko
111e53470feSOleksandr Tymoshenko static struct resource_spec ti_edma3_mem_spec[] = {
112e53470feSOleksandr Tymoshenko { SYS_RES_MEMORY, 0, RF_ACTIVE },
113e53470feSOleksandr Tymoshenko { -1, 0, 0 }
114e53470feSOleksandr Tymoshenko };
115e53470feSOleksandr Tymoshenko static struct resource_spec ti_edma3_irq_spec[] = {
116e53470feSOleksandr Tymoshenko { SYS_RES_IRQ, 0, RF_ACTIVE },
117e53470feSOleksandr Tymoshenko { SYS_RES_IRQ, 1, RF_ACTIVE },
118e53470feSOleksandr Tymoshenko { SYS_RES_IRQ, 2, RF_ACTIVE },
119e53470feSOleksandr Tymoshenko { -1, 0, 0 }
120e53470feSOleksandr Tymoshenko };
121e53470feSOleksandr Tymoshenko
122e53470feSOleksandr Tymoshenko /* Read/Write macros */
123e53470feSOleksandr Tymoshenko #define ti_edma3_cc_rd_4(reg) bus_read_4(ti_edma3_sc->mem_res[0], reg)
124e53470feSOleksandr Tymoshenko #define ti_edma3_cc_wr_4(reg, val) bus_write_4(ti_edma3_sc->mem_res[0], reg, val)
125e53470feSOleksandr Tymoshenko
126e53470feSOleksandr Tymoshenko static void ti_edma3_intr_comp(void *arg);
127e53470feSOleksandr Tymoshenko static void ti_edma3_intr_mperr(void *arg);
128e53470feSOleksandr Tymoshenko static void ti_edma3_intr_err(void *arg);
129e53470feSOleksandr Tymoshenko
130e53470feSOleksandr Tymoshenko static struct {
131e53470feSOleksandr Tymoshenko driver_intr_t *handler;
132e53470feSOleksandr Tymoshenko char * description;
133e53470feSOleksandr Tymoshenko } ti_edma3_intrs[TI_EDMA3_NUM_IRQS] = {
134e53470feSOleksandr Tymoshenko { ti_edma3_intr_comp, "EDMA Completion Interrupt" },
135e53470feSOleksandr Tymoshenko { ti_edma3_intr_mperr, "EDMA Memory Protection Error Interrupt" },
136e53470feSOleksandr Tymoshenko { ti_edma3_intr_err, "EDMA Error Interrupt" },
137e53470feSOleksandr Tymoshenko };
138e53470feSOleksandr Tymoshenko
139e53470feSOleksandr Tymoshenko static int
ti_edma3_probe(device_t dev)140e53470feSOleksandr Tymoshenko ti_edma3_probe(device_t dev)
141e53470feSOleksandr Tymoshenko {
142add35ed5SIan Lepore
143add35ed5SIan Lepore if (!ofw_bus_status_okay(dev))
144add35ed5SIan Lepore return (ENXIO);
145add35ed5SIan Lepore
146cddf6d2aSTim Kientzle if (!ofw_bus_is_compatible(dev, "ti,edma3"))
147e53470feSOleksandr Tymoshenko return (ENXIO);
148e53470feSOleksandr Tymoshenko
149e53470feSOleksandr Tymoshenko device_set_desc(dev, "TI EDMA Controller");
150e53470feSOleksandr Tymoshenko return (0);
151e53470feSOleksandr Tymoshenko }
152e53470feSOleksandr Tymoshenko
153e53470feSOleksandr Tymoshenko static int
ti_edma3_attach(device_t dev)154e53470feSOleksandr Tymoshenko ti_edma3_attach(device_t dev)
155e53470feSOleksandr Tymoshenko {
156e53470feSOleksandr Tymoshenko struct ti_edma3_softc *sc = device_get_softc(dev);
157e53470feSOleksandr Tymoshenko uint32_t reg;
158e53470feSOleksandr Tymoshenko int err;
159e53470feSOleksandr Tymoshenko int i;
160e53470feSOleksandr Tymoshenko
161e53470feSOleksandr Tymoshenko if (ti_edma3_sc)
162e53470feSOleksandr Tymoshenko return (ENXIO);
163e53470feSOleksandr Tymoshenko
164e53470feSOleksandr Tymoshenko ti_edma3_sc = sc;
165e53470feSOleksandr Tymoshenko sc->sc_dev = dev;
166e53470feSOleksandr Tymoshenko
167e53470feSOleksandr Tymoshenko /* Request the memory resources */
168e53470feSOleksandr Tymoshenko err = bus_alloc_resources(dev, ti_edma3_mem_spec, sc->mem_res);
169e53470feSOleksandr Tymoshenko if (err) {
170e53470feSOleksandr Tymoshenko device_printf(dev, "Error: could not allocate mem resources\n");
171e53470feSOleksandr Tymoshenko return (ENXIO);
172e53470feSOleksandr Tymoshenko }
173e53470feSOleksandr Tymoshenko
174e53470feSOleksandr Tymoshenko /* Request the IRQ resources */
175e53470feSOleksandr Tymoshenko err = bus_alloc_resources(dev, ti_edma3_irq_spec, sc->irq_res);
176e53470feSOleksandr Tymoshenko if (err) {
177e53470feSOleksandr Tymoshenko device_printf(dev, "Error: could not allocate irq resources\n");
178e53470feSOleksandr Tymoshenko return (ENXIO);
179e53470feSOleksandr Tymoshenko }
180e53470feSOleksandr Tymoshenko
1810050ea24SMichal Meloun /* FIXME: Require DTS from Linux kernel 5.7 */
1820050ea24SMichal Meloun /* FIXME: OK to enable clkctrl here? */
183e53470feSOleksandr Tymoshenko /* Enable Channel Controller */
1840050ea24SMichal Meloun ti_sysc_clock_enable(device_get_parent(dev));
185e53470feSOleksandr Tymoshenko
186e53470feSOleksandr Tymoshenko reg = ti_edma3_cc_rd_4(TI_EDMA3CC_PID);
187e53470feSOleksandr Tymoshenko
188e53470feSOleksandr Tymoshenko device_printf(dev, "EDMA revision %08x\n", reg);
189e53470feSOleksandr Tymoshenko
190e53470feSOleksandr Tymoshenko /* Attach interrupt handlers */
191e53470feSOleksandr Tymoshenko for (i = 0; i < TI_EDMA3_NUM_IRQS; ++i) {
192e53470feSOleksandr Tymoshenko err = bus_setup_intr(dev, sc->irq_res[i], INTR_TYPE_MISC |
193e53470feSOleksandr Tymoshenko INTR_MPSAFE, NULL, *ti_edma3_intrs[i].handler,
194e53470feSOleksandr Tymoshenko sc, &sc->ih_cookie[i]);
195e53470feSOleksandr Tymoshenko if (err) {
196e53470feSOleksandr Tymoshenko device_printf(dev, "could not setup %s\n",
197e53470feSOleksandr Tymoshenko ti_edma3_intrs[i].description);
198e53470feSOleksandr Tymoshenko return (err);
199e53470feSOleksandr Tymoshenko }
200e53470feSOleksandr Tymoshenko }
201e53470feSOleksandr Tymoshenko
202e53470feSOleksandr Tymoshenko return (0);
203e53470feSOleksandr Tymoshenko }
204e53470feSOleksandr Tymoshenko
205e53470feSOleksandr Tymoshenko static device_method_t ti_edma3_methods[] = {
206e53470feSOleksandr Tymoshenko DEVMETHOD(device_probe, ti_edma3_probe),
207e53470feSOleksandr Tymoshenko DEVMETHOD(device_attach, ti_edma3_attach),
208e53470feSOleksandr Tymoshenko {0, 0},
209e53470feSOleksandr Tymoshenko };
210e53470feSOleksandr Tymoshenko
211e53470feSOleksandr Tymoshenko static driver_t ti_edma3_driver = {
212e53470feSOleksandr Tymoshenko "ti_edma3",
213e53470feSOleksandr Tymoshenko ti_edma3_methods,
214e53470feSOleksandr Tymoshenko sizeof(struct ti_edma3_softc),
215e53470feSOleksandr Tymoshenko };
216e53470feSOleksandr Tymoshenko
217*8537e671SJohn Baldwin DRIVER_MODULE(ti_edma3, simplebus, ti_edma3_driver, 0, 0);
2180050ea24SMichal Meloun MODULE_DEPEND(ti_edma3, ti_sysc, 1, 1, 1);
219e53470feSOleksandr Tymoshenko
220e53470feSOleksandr Tymoshenko static void
ti_edma3_intr_comp(void * arg)221e53470feSOleksandr Tymoshenko ti_edma3_intr_comp(void *arg)
222e53470feSOleksandr Tymoshenko {
223e53470feSOleksandr Tymoshenko printf("%s: unimplemented\n", __func__);
224e53470feSOleksandr Tymoshenko }
225e53470feSOleksandr Tymoshenko
226e53470feSOleksandr Tymoshenko static void
ti_edma3_intr_mperr(void * arg)227e53470feSOleksandr Tymoshenko ti_edma3_intr_mperr(void *arg)
228e53470feSOleksandr Tymoshenko {
229e53470feSOleksandr Tymoshenko printf("%s: unimplemented\n", __func__);
230e53470feSOleksandr Tymoshenko }
231e53470feSOleksandr Tymoshenko
232e53470feSOleksandr Tymoshenko static void
ti_edma3_intr_err(void * arg)233e53470feSOleksandr Tymoshenko ti_edma3_intr_err(void *arg)
234e53470feSOleksandr Tymoshenko {
235e53470feSOleksandr Tymoshenko printf("%s: unimplemented\n", __func__);
236e53470feSOleksandr Tymoshenko }
237e53470feSOleksandr Tymoshenko
238e53470feSOleksandr Tymoshenko void
ti_edma3_init(unsigned int eqn)239e53470feSOleksandr Tymoshenko ti_edma3_init(unsigned int eqn)
240e53470feSOleksandr Tymoshenko {
241e53470feSOleksandr Tymoshenko uint32_t reg;
242e53470feSOleksandr Tymoshenko int i;
243e53470feSOleksandr Tymoshenko
244e53470feSOleksandr Tymoshenko /* Clear Event Missed Regs */
245e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_EMCR, 0xFFFFFFFF);
246e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_EMCRH, 0xFFFFFFFF);
247e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_QEMCR, 0xFFFFFFFF);
248e53470feSOleksandr Tymoshenko
249e53470feSOleksandr Tymoshenko /* Clear Error Reg */
250e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_CCERRCLR, 0xFFFFFFFF);
251e53470feSOleksandr Tymoshenko
252e53470feSOleksandr Tymoshenko /* Enable DMA channels 0-63 */
253e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_DRAE(0), 0xFFFFFFFF);
254e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_DRAEH(0), 0xFFFFFFFF);
255e53470feSOleksandr Tymoshenko
256e53470feSOleksandr Tymoshenko for (i = 0; i < 64; i++) {
257e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_DCHMAP(i), i<<5);
258e53470feSOleksandr Tymoshenko }
259e53470feSOleksandr Tymoshenko
260e53470feSOleksandr Tymoshenko /* Initialize the DMA Queue Number Registers */
261e53470feSOleksandr Tymoshenko for (i = 0; i < TI_EDMA3_NUM_DMA_CHS; i++) {
262e53470feSOleksandr Tymoshenko reg = ti_edma3_cc_rd_4(TI_EDMA3CC_DMAQNUM(i>>3));
263e53470feSOleksandr Tymoshenko reg &= TI_EDMA3CC_DMAQNUM_CLR(i);
264e53470feSOleksandr Tymoshenko reg |= TI_EDMA3CC_DMAQNUM_SET(i, eqn);
265e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_DMAQNUM(i>>3), reg);
266e53470feSOleksandr Tymoshenko }
267e53470feSOleksandr Tymoshenko
268e53470feSOleksandr Tymoshenko /* Enable the QDMA Region access for all channels */
269e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_QRAE(0), (1 << TI_EDMA3_NUM_QDMA_CHS) - 1);
270e53470feSOleksandr Tymoshenko
271e53470feSOleksandr Tymoshenko /*Initialize QDMA Queue Number Registers */
272e53470feSOleksandr Tymoshenko for (i = 0; i < TI_EDMA3_NUM_QDMA_CHS; i++) {
273e53470feSOleksandr Tymoshenko reg = ti_edma3_cc_rd_4(TI_EDMA3CC_QDMAQNUM);
274e53470feSOleksandr Tymoshenko reg &= TI_EDMA3CC_QDMAQNUM_CLR(i);
275e53470feSOleksandr Tymoshenko reg |= TI_EDMA3CC_QDMAQNUM_SET(i, eqn);
276e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_QDMAQNUM, reg);
277e53470feSOleksandr Tymoshenko }
278e53470feSOleksandr Tymoshenko }
279e53470feSOleksandr Tymoshenko
280e53470feSOleksandr Tymoshenko #ifdef notyet
281e53470feSOleksandr Tymoshenko int
ti_edma3_enable_event_intr(unsigned int ch)282e53470feSOleksandr Tymoshenko ti_edma3_enable_event_intr(unsigned int ch)
283e53470feSOleksandr Tymoshenko {
284e53470feSOleksandr Tymoshenko uint32_t reg;
285e53470feSOleksandr Tymoshenko
286e53470feSOleksandr Tymoshenko if (ch >= TI_EDMA3_NUM_DMA_CHS)
287e53470feSOleksandr Tymoshenko return (EINVAL);
288e53470feSOleksandr Tymoshenko
289e53470feSOleksandr Tymoshenko if (ch < 32) {
290e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_S_IESR(0), 1 << ch);
291e53470feSOleksandr Tymoshenko } else {
292e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_S_IESRH(0), 1 << (ch - 32));
293e53470feSOleksandr Tymoshenko }
294e53470feSOleksandr Tymoshenko return 0;
295e53470feSOleksandr Tymoshenko }
296e53470feSOleksandr Tymoshenko #endif
297e53470feSOleksandr Tymoshenko
298e53470feSOleksandr Tymoshenko int
ti_edma3_request_dma_ch(unsigned int ch,unsigned int tccn,unsigned int eqn)299e53470feSOleksandr Tymoshenko ti_edma3_request_dma_ch(unsigned int ch, unsigned int tccn, unsigned int eqn)
300e53470feSOleksandr Tymoshenko {
301e53470feSOleksandr Tymoshenko uint32_t reg;
302e53470feSOleksandr Tymoshenko
303e53470feSOleksandr Tymoshenko if (ch >= TI_EDMA3_NUM_DMA_CHS)
304e53470feSOleksandr Tymoshenko return (EINVAL);
305e53470feSOleksandr Tymoshenko
306e53470feSOleksandr Tymoshenko /* Enable the DMA channel in the DRAE/DRAEH registers */
307e53470feSOleksandr Tymoshenko if (ch < 32) {
308e53470feSOleksandr Tymoshenko reg = ti_edma3_cc_rd_4(TI_EDMA3CC_DRAE(0));
309e53470feSOleksandr Tymoshenko reg |= (0x01 << ch);
310e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_DRAE(0), reg);
311e53470feSOleksandr Tymoshenko } else {
312e53470feSOleksandr Tymoshenko reg = ti_edma3_cc_rd_4(TI_EDMA3CC_DRAEH(0));
313e53470feSOleksandr Tymoshenko reg |= (0x01 << (ch - 32));
314e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_DRAEH(0), reg);
315e53470feSOleksandr Tymoshenko }
316e53470feSOleksandr Tymoshenko
317e53470feSOleksandr Tymoshenko /* Associate DMA Channel to Event Queue */
318e53470feSOleksandr Tymoshenko reg = ti_edma3_cc_rd_4(TI_EDMA3CC_DMAQNUM(ch >> 3));
319e53470feSOleksandr Tymoshenko reg &= TI_EDMA3CC_DMAQNUM_CLR(ch);
320e53470feSOleksandr Tymoshenko reg |= TI_EDMA3CC_DMAQNUM_SET((ch), eqn);
321e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_DMAQNUM(ch >> 3), reg);
322e53470feSOleksandr Tymoshenko
323e53470feSOleksandr Tymoshenko /* Set TCC in corresponding PaRAM Entry */
324e53470feSOleksandr Tymoshenko reg = ti_edma3_cc_rd_4(TI_EDMA3CC_OPT(ch));
325e53470feSOleksandr Tymoshenko reg &= TI_EDMA3CC_OPT_TCC_CLR;
326e53470feSOleksandr Tymoshenko reg |= TI_EDMA3CC_OPT_TCC_SET(ch);
327e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_OPT(ch), reg);
328e53470feSOleksandr Tymoshenko
329e53470feSOleksandr Tymoshenko return 0;
330e53470feSOleksandr Tymoshenko }
331e53470feSOleksandr Tymoshenko
332e53470feSOleksandr Tymoshenko int
ti_edma3_request_qdma_ch(unsigned int ch,unsigned int tccn,unsigned int eqn)333e53470feSOleksandr Tymoshenko ti_edma3_request_qdma_ch(unsigned int ch, unsigned int tccn, unsigned int eqn)
334e53470feSOleksandr Tymoshenko {
335e53470feSOleksandr Tymoshenko uint32_t reg;
336e53470feSOleksandr Tymoshenko
337e53470feSOleksandr Tymoshenko if (ch >= TI_EDMA3_NUM_DMA_CHS)
338e53470feSOleksandr Tymoshenko return (EINVAL);
339e53470feSOleksandr Tymoshenko
340e53470feSOleksandr Tymoshenko /* Enable the QDMA channel in the QRAE registers */
341e53470feSOleksandr Tymoshenko reg = ti_edma3_cc_rd_4(TI_EDMA3CC_QRAE(0));
342e53470feSOleksandr Tymoshenko reg |= (0x01 << ch);
343e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_QRAE(0), reg);
344e53470feSOleksandr Tymoshenko
345e53470feSOleksandr Tymoshenko /* Associate QDMA Channel to Event Queue */
346e53470feSOleksandr Tymoshenko reg = ti_edma3_cc_rd_4(TI_EDMA3CC_QDMAQNUM);
347e53470feSOleksandr Tymoshenko reg |= TI_EDMA3CC_QDMAQNUM_SET(ch, eqn);
348e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_QDMAQNUM, reg);
349e53470feSOleksandr Tymoshenko
350e53470feSOleksandr Tymoshenko /* Set TCC in corresponding PaRAM Entry */
351e53470feSOleksandr Tymoshenko reg = ti_edma3_cc_rd_4(TI_EDMA3CC_OPT(ch));
352e53470feSOleksandr Tymoshenko reg &= TI_EDMA3CC_OPT_TCC_CLR;
353e53470feSOleksandr Tymoshenko reg |= TI_EDMA3CC_OPT_TCC_SET(ch);
354e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_OPT(ch), reg);
355e53470feSOleksandr Tymoshenko
356e53470feSOleksandr Tymoshenko return 0;
357e53470feSOleksandr Tymoshenko }
358e53470feSOleksandr Tymoshenko
359e53470feSOleksandr Tymoshenko int
ti_edma3_enable_transfer_manual(unsigned int ch)360e53470feSOleksandr Tymoshenko ti_edma3_enable_transfer_manual(unsigned int ch)
361e53470feSOleksandr Tymoshenko {
362e53470feSOleksandr Tymoshenko if (ch >= TI_EDMA3_NUM_DMA_CHS)
363e53470feSOleksandr Tymoshenko return (EINVAL);
364e53470feSOleksandr Tymoshenko
365e53470feSOleksandr Tymoshenko /* set corresponding bit in ESR/ESRH to set a event */
366e53470feSOleksandr Tymoshenko if (ch < 32) {
367e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_S_ESR(0), 1 << ch);
368e53470feSOleksandr Tymoshenko } else {
369e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_S_ESRH(0), 1 << (ch - 32));
370e53470feSOleksandr Tymoshenko }
371e53470feSOleksandr Tymoshenko
372e53470feSOleksandr Tymoshenko return 0;
373e53470feSOleksandr Tymoshenko }
374e53470feSOleksandr Tymoshenko
375e53470feSOleksandr Tymoshenko int
ti_edma3_enable_transfer_qdma(unsigned int ch)376e53470feSOleksandr Tymoshenko ti_edma3_enable_transfer_qdma(unsigned int ch)
377e53470feSOleksandr Tymoshenko {
378e53470feSOleksandr Tymoshenko if (ch >= TI_EDMA3_NUM_QDMA_CHS)
379e53470feSOleksandr Tymoshenko return (EINVAL);
380e53470feSOleksandr Tymoshenko
381e53470feSOleksandr Tymoshenko /* set corresponding bit in QEESR to enable QDMA event */
382e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_S_QEESR(0), (1 << ch));
383e53470feSOleksandr Tymoshenko
384e53470feSOleksandr Tymoshenko return 0;
385e53470feSOleksandr Tymoshenko }
386e53470feSOleksandr Tymoshenko
387e53470feSOleksandr Tymoshenko int
ti_edma3_enable_transfer_event(unsigned int ch)388e53470feSOleksandr Tymoshenko ti_edma3_enable_transfer_event(unsigned int ch)
389e53470feSOleksandr Tymoshenko {
390e53470feSOleksandr Tymoshenko if (ch >= TI_EDMA3_NUM_DMA_CHS)
391e53470feSOleksandr Tymoshenko return (EINVAL);
392e53470feSOleksandr Tymoshenko
393e53470feSOleksandr Tymoshenko /* Clear SECR(H) & EMCR(H) to clean any previous NULL request
394e53470feSOleksandr Tymoshenko * and set corresponding bit in EESR to enable DMA event */
395e53470feSOleksandr Tymoshenko if(ch < 32) {
396e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_S_SECR(0), (1 << ch));
397e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_EMCR, (1 << ch));
398e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_S_EESR(0), (1 << ch));
399e53470feSOleksandr Tymoshenko } else {
400e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_S_SECRH(0), 1 << (ch - 32));
401e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_EMCRH, 1 << (ch - 32));
402e53470feSOleksandr Tymoshenko ti_edma3_cc_wr_4(TI_EDMA3CC_S_EESRH(0), 1 << (ch - 32));
403e53470feSOleksandr Tymoshenko }
404e53470feSOleksandr Tymoshenko
405e53470feSOleksandr Tymoshenko return 0;
406e53470feSOleksandr Tymoshenko }
407e53470feSOleksandr Tymoshenko
408e53470feSOleksandr Tymoshenko void
ti_edma3_param_write(unsigned int ch,struct ti_edma3cc_param_set * prs)409e53470feSOleksandr Tymoshenko ti_edma3_param_write(unsigned int ch, struct ti_edma3cc_param_set *prs)
410e53470feSOleksandr Tymoshenko {
411e53470feSOleksandr Tymoshenko bus_write_region_4(ti_edma3_sc->mem_res[0], TI_EDMA3CC_OPT(ch),
412e53470feSOleksandr Tymoshenko (uint32_t *) prs, 8);
413e53470feSOleksandr Tymoshenko }
414e53470feSOleksandr Tymoshenko
415e53470feSOleksandr Tymoshenko void
ti_edma3_param_read(unsigned int ch,struct ti_edma3cc_param_set * prs)416e53470feSOleksandr Tymoshenko ti_edma3_param_read(unsigned int ch, struct ti_edma3cc_param_set *prs)
417e53470feSOleksandr Tymoshenko {
418e53470feSOleksandr Tymoshenko bus_read_region_4(ti_edma3_sc->mem_res[0], TI_EDMA3CC_OPT(ch),
419e53470feSOleksandr Tymoshenko (uint32_t *) prs, 8);
420e53470feSOleksandr Tymoshenko }
421