Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F177997618
D59124.1795727889.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
21 KB
Referenced Files
None
Subscribers
None
D59124.1795727889.diff
View Options
diff --git a/sys/arm/ti/am335x/files.am335x b/sys/arm/ti/am335x/files.am335x
--- a/sys/arm/ti/am335x/files.am335x
+++ b/sys/arm/ti/am335x/files.am335x
@@ -21,4 +21,5 @@
arm/ti/am335x/tda19988.c optional tda19988
arm/ti/ti_edma3.c standard
+arm/ti/ti_edma3_if.m standard
arm/ti/cpsw/if_cpsw.c optional cpsw
diff --git a/sys/arm/ti/ti_edma3.h b/sys/arm/ti/ti_edma3.h
--- a/sys/arm/ti/ti_edma3.h
+++ b/sys/arm/ti/ti_edma3.h
@@ -35,6 +35,10 @@
#define TI_EDMA3_EVENT_SDTXEVT0 24
#define TI_EDMA3_EVENT_SDRXEVT0 25
+/* ti_edma3_transfer_status() bits */
+#define TI_EDMA3_DONE 0x1
+#define TI_EDMA3_MISSED 0x2
+
struct ti_edma3cc_param_set {
struct {
uint32_t sam:1; /* Source address mode */
@@ -68,14 +72,4 @@
uint16_t reserved; /* Reserved */
};
-void ti_edma3_init(unsigned int eqn);
-int ti_edma3_request_dma_ch(unsigned int ch, unsigned int tccn, unsigned int eqn);
-int ti_edma3_request_qdma_ch(unsigned int ch, unsigned int tccn, unsigned int eqn);
-int ti_edma3_enable_transfer_manual(unsigned int ch);
-int ti_edma3_enable_transfer_qdma(unsigned int ch);
-int ti_edma3_enable_transfer_event(unsigned int ch);
-
-void ti_edma3_param_write(unsigned int ch, struct ti_edma3cc_param_set *prs);
-void ti_edma3_param_read(unsigned int ch, struct ti_edma3cc_param_set *prs);
-
#endif /* _TI_EDMA3_H_ */
diff --git a/sys/arm/ti/ti_edma3.c b/sys/arm/ti/ti_edma3.c
--- a/sys/arm/ti/ti_edma3.c
+++ b/sys/arm/ti/ti_edma3.c
@@ -47,6 +47,7 @@
#include <sys/rman.h>
#include <machine/resource.h>
+#include <dev/ofw/openfirm.h>
#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>
@@ -55,12 +56,15 @@
#include <arm/ti/ti_edma3.h>
+#include "ti_edma3_if.h"
+
#define TI_EDMA3_NUM_TCS 3
#define TI_EDMA3_NUM_IRQS 3
#define TI_EDMA3_NUM_DMA_CHS 64
#define TI_EDMA3_NUM_QDMA_CHS 8
#define TI_EDMA3CC_PID 0x000
+#define TI_EDMA3CC_CCCFG 0x004
#define TI_EDMA3CC_DCHMAP(p) (0x100 + ((p)*4))
#define TI_EDMA3CC_DMAQNUM(n) (0x240 + ((n)*4))
#define TI_EDMA3CC_QDMAQNUM 0x260
@@ -78,10 +82,16 @@
#define TI_EDMA3CC_S_SECRH(p) (0x2044 + ((p)*0x200))
#define TI_EDMA3CC_S_EESR(p) (0x2030 + ((p)*0x200))
#define TI_EDMA3CC_S_EESRH(p) (0x2034 + ((p)*0x200))
+#define TI_EDMA3CC_S_EECR(p) (0x2028 + ((p)*0x200))
+#define TI_EDMA3CC_S_EECRH(p) (0x202C + ((p)*0x200))
#define TI_EDMA3CC_S_IESR(p) (0x2060 + ((p)*0x200))
#define TI_EDMA3CC_S_IESRH(p) (0x2064 + ((p)*0x200))
#define TI_EDMA3CC_S_IPR(p) (0x2068 + ((p)*0x200))
#define TI_EDMA3CC_S_IPRH(p) (0x206C + ((p)*0x200))
+#define TI_EDMA3CC_EMR 0x300
+#define TI_EDMA3CC_EMRH 0x304
+#define TI_EDMA3CC_S_ICR(p) (0x2070 + ((p)*0x200))
+#define TI_EDMA3CC_S_ICRH(p) (0x2074 + ((p)*0x200))
#define TI_EDMA3CC_S_QEESR(p) (0x208C + ((p)*0x200))
#define TI_EDMA3CC_PARAM_OFFSET 0x4000
@@ -92,6 +102,8 @@
#define TI_EDMA3CC_QDMAQNUM_SET(c,q) ((0x7 & (q)) << ((c) * 4))
#define TI_EDMA3CC_QDMAQNUM_CLR(c) (~(0x7 << ((c) * 4)))
+#define TI_EDMA3CC_CCCFG_NUM_PAENTRY(r) (16 << (((r) >> 12) & 0x7))
+
#define TI_EDMA3CC_OPT_TCC_CLR (~(0x3F000))
#define TI_EDMA3CC_OPT_TCC_SET(p) (((0x3F000 >> 12) & (p)) << 12)
@@ -104,9 +116,23 @@
struct resource * mem_res[1];
struct resource * irq_res[TI_EDMA3_NUM_IRQS];
void *ih_cookie[TI_EDMA3_NUM_IRQS];
+ struct mtx mtx;
+ u_int num_param;
+ u_int next_param;
+ u_int link_base[TI_EDMA3_NUM_DMA_CHS];
+ u_int link_count[TI_EDMA3_NUM_DMA_CHS];
};
-static struct ti_edma3_softc *ti_edma3_sc = NULL;
+/*
+ * The device tree splits edma3 into a channel controller and separate
+ * transfer controllers. ti_edma3 attaches to the channel controller and
+ * ti_edma3tc to the transfer controllers.
+ */
+static struct ofw_compat_data compat_data[] = {
+ { "ti,edma3-tpcc", 1 },
+ { "ti,edma3", 1 },
+ { NULL, 0 }
+};
static struct resource_spec ti_edma3_mem_spec[] = {
{ SYS_RES_MEMORY, 0, RF_ACTIVE },
@@ -120,12 +146,19 @@
};
/* Read/Write macros */
-#define ti_edma3_cc_rd_4(reg) bus_read_4(ti_edma3_sc->mem_res[0], reg)
-#define ti_edma3_cc_wr_4(reg, val) bus_write_4(ti_edma3_sc->mem_res[0], reg, val)
+#define ti_edma3_cc_rd_4(sc, reg) bus_read_4((sc)->mem_res[0], reg)
+#define ti_edma3_cc_wr_4(sc, reg, val) bus_write_4((sc)->mem_res[0], reg, val)
static void ti_edma3_intr_comp(void *arg);
static void ti_edma3_intr_mperr(void *arg);
static void ti_edma3_intr_err(void *arg);
+static void ti_edma3_init(struct ti_edma3_softc *sc, unsigned int eqn);
+
+static ti_edma3_channel_alloc_t ti_edma3_channel_alloc;
+static ti_edma3_transfer_setup_t ti_edma3_transfer_setup;
+static ti_edma3_transfer_start_t ti_edma3_transfer_start;
+static ti_edma3_transfer_status_t ti_edma3_transfer_status;
+static ti_edma3_transfer_stop_t ti_edma3_transfer_stop;
static struct {
driver_intr_t *handler;
@@ -143,7 +176,7 @@
if (!ofw_bus_status_okay(dev))
return (ENXIO);
- if (!ofw_bus_is_compatible(dev, "ti,edma3"))
+ if (ofw_bus_search_compatible(dev, compat_data)->ocd_data == 0)
return (ENXIO);
device_set_desc(dev, "TI EDMA Controller");
@@ -158,11 +191,8 @@
int err;
int i;
- if (ti_edma3_sc)
- return (ENXIO);
-
- ti_edma3_sc = sc;
sc->sc_dev = dev;
+ mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF);
/* Request the memory resources */
err = bus_alloc_resources(dev, ti_edma3_mem_spec, sc->mem_res);
@@ -178,15 +208,18 @@
return (ENXIO);
}
- /* FIXME: Require DTS from Linux kernel 5.7 */
- /* FIXME: OK to enable clkctrl here? */
/* Enable Channel Controller */
ti_sysc_clock_enable(device_get_parent(dev));
- reg = ti_edma3_cc_rd_4(TI_EDMA3CC_PID);
+ reg = ti_edma3_cc_rd_4(sc, TI_EDMA3CC_PID);
device_printf(dev, "EDMA revision %08x\n", reg);
+ sc->num_param = TI_EDMA3CC_CCCFG_NUM_PAENTRY(
+ ti_edma3_cc_rd_4(sc, TI_EDMA3CC_CCCFG));
+ sc->next_param = TI_EDMA3_NUM_DMA_CHS;
+ ti_edma3_init(sc, 0);
+
/* Attach interrupt handlers */
for (i = 0; i < TI_EDMA3_NUM_IRQS; ++i) {
err = bus_setup_intr(dev, sc->irq_res[i], INTR_TYPE_MISC |
@@ -199,13 +232,23 @@
}
}
+ /* Register our xref so consumers can find us through "dmas". */
+ OF_device_register_xref(OF_xref_from_node(ofw_bus_get_node(dev)), dev);
+
return (0);
}
static device_method_t ti_edma3_methods[] = {
- DEVMETHOD(device_probe, ti_edma3_probe),
- DEVMETHOD(device_attach, ti_edma3_attach),
- {0, 0},
+ DEVMETHOD(device_probe, ti_edma3_probe),
+ DEVMETHOD(device_attach, ti_edma3_attach),
+
+ DEVMETHOD(ti_edma3_channel_alloc, ti_edma3_channel_alloc),
+ DEVMETHOD(ti_edma3_transfer_setup, ti_edma3_transfer_setup),
+ DEVMETHOD(ti_edma3_transfer_start, ti_edma3_transfer_start),
+ DEVMETHOD(ti_edma3_transfer_status, ti_edma3_transfer_status),
+ DEVMETHOD(ti_edma3_transfer_stop, ti_edma3_transfer_stop),
+
+ DEVMETHOD_END
};
static driver_t ti_edma3_driver = {
@@ -235,186 +278,384 @@
printf("%s: unimplemented\n", __func__);
}
-void
-ti_edma3_init(unsigned int eqn)
+static void
+ti_edma3_init(struct ti_edma3_softc *sc, unsigned int eqn)
{
uint32_t reg;
int i;
/* Clear Event Missed Regs */
- ti_edma3_cc_wr_4(TI_EDMA3CC_EMCR, 0xFFFFFFFF);
- ti_edma3_cc_wr_4(TI_EDMA3CC_EMCRH, 0xFFFFFFFF);
- ti_edma3_cc_wr_4(TI_EDMA3CC_QEMCR, 0xFFFFFFFF);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_EMCR, 0xFFFFFFFF);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_EMCRH, 0xFFFFFFFF);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_QEMCR, 0xFFFFFFFF);
/* Clear Error Reg */
- ti_edma3_cc_wr_4(TI_EDMA3CC_CCERRCLR, 0xFFFFFFFF);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_CCERRCLR, 0xFFFFFFFF);
/* Enable DMA channels 0-63 */
- ti_edma3_cc_wr_4(TI_EDMA3CC_DRAE(0), 0xFFFFFFFF);
- ti_edma3_cc_wr_4(TI_EDMA3CC_DRAEH(0), 0xFFFFFFFF);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_DRAE(0), 0xFFFFFFFF);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_DRAEH(0), 0xFFFFFFFF);
for (i = 0; i < 64; i++) {
- ti_edma3_cc_wr_4(TI_EDMA3CC_DCHMAP(i), i<<5);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_DCHMAP(i), i << 5);
}
/* Initialize the DMA Queue Number Registers */
for (i = 0; i < TI_EDMA3_NUM_DMA_CHS; i++) {
- reg = ti_edma3_cc_rd_4(TI_EDMA3CC_DMAQNUM(i>>3));
+ reg = ti_edma3_cc_rd_4(sc, TI_EDMA3CC_DMAQNUM(i >> 3));
reg &= TI_EDMA3CC_DMAQNUM_CLR(i);
reg |= TI_EDMA3CC_DMAQNUM_SET(i, eqn);
- ti_edma3_cc_wr_4(TI_EDMA3CC_DMAQNUM(i>>3), reg);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_DMAQNUM(i >> 3), reg);
}
/* Enable the QDMA Region access for all channels */
- ti_edma3_cc_wr_4(TI_EDMA3CC_QRAE(0), (1 << TI_EDMA3_NUM_QDMA_CHS) - 1);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_QRAE(0),
+ (1 << TI_EDMA3_NUM_QDMA_CHS) - 1);
/*Initialize QDMA Queue Number Registers */
for (i = 0; i < TI_EDMA3_NUM_QDMA_CHS; i++) {
- reg = ti_edma3_cc_rd_4(TI_EDMA3CC_QDMAQNUM);
+ reg = ti_edma3_cc_rd_4(sc, TI_EDMA3CC_QDMAQNUM);
reg &= TI_EDMA3CC_QDMAQNUM_CLR(i);
reg |= TI_EDMA3CC_QDMAQNUM_SET(i, eqn);
- ti_edma3_cc_wr_4(TI_EDMA3CC_QDMAQNUM, reg);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_QDMAQNUM, reg);
}
}
#ifdef notyet
-int
-ti_edma3_enable_event_intr(unsigned int ch)
+static int
+ti_edma3_enable_event_intr(device_t dev, unsigned int ch)
{
+ struct ti_edma3_softc *sc = device_get_softc(dev);
uint32_t reg;
if (ch >= TI_EDMA3_NUM_DMA_CHS)
return (EINVAL);
if (ch < 32) {
- ti_edma3_cc_wr_4(TI_EDMA3CC_S_IESR(0), 1 << ch);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_IESR(0), 1 << ch);
} else {
- ti_edma3_cc_wr_4(TI_EDMA3CC_S_IESRH(0), 1 << (ch - 32));
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_IESRH(0), 1 << (ch - 32));
}
return 0;
}
#endif
-int
-ti_edma3_request_dma_ch(unsigned int ch, unsigned int tccn, unsigned int eqn)
+static int
+ti_edma3_request_dma_ch(device_t dev, unsigned int ch, unsigned int tccn,
+ unsigned int eqn)
{
+ struct ti_edma3_softc *sc = device_get_softc(dev);
uint32_t reg;
if (ch >= TI_EDMA3_NUM_DMA_CHS)
return (EINVAL);
+ mtx_lock(&sc->mtx);
+
/* Enable the DMA channel in the DRAE/DRAEH registers */
if (ch < 32) {
- reg = ti_edma3_cc_rd_4(TI_EDMA3CC_DRAE(0));
+ reg = ti_edma3_cc_rd_4(sc, TI_EDMA3CC_DRAE(0));
reg |= (0x01 << ch);
- ti_edma3_cc_wr_4(TI_EDMA3CC_DRAE(0), reg);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_DRAE(0), reg);
} else {
- reg = ti_edma3_cc_rd_4(TI_EDMA3CC_DRAEH(0));
+ reg = ti_edma3_cc_rd_4(sc, TI_EDMA3CC_DRAEH(0));
reg |= (0x01 << (ch - 32));
- ti_edma3_cc_wr_4(TI_EDMA3CC_DRAEH(0), reg);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_DRAEH(0), reg);
}
/* Associate DMA Channel to Event Queue */
- reg = ti_edma3_cc_rd_4(TI_EDMA3CC_DMAQNUM(ch >> 3));
+ reg = ti_edma3_cc_rd_4(sc, TI_EDMA3CC_DMAQNUM(ch >> 3));
reg &= TI_EDMA3CC_DMAQNUM_CLR(ch);
reg |= TI_EDMA3CC_DMAQNUM_SET((ch), eqn);
- ti_edma3_cc_wr_4(TI_EDMA3CC_DMAQNUM(ch >> 3), reg);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_DMAQNUM(ch >> 3), reg);
/* Set TCC in corresponding PaRAM Entry */
- reg = ti_edma3_cc_rd_4(TI_EDMA3CC_OPT(ch));
+ reg = ti_edma3_cc_rd_4(sc, TI_EDMA3CC_OPT(ch));
reg &= TI_EDMA3CC_OPT_TCC_CLR;
reg |= TI_EDMA3CC_OPT_TCC_SET(ch);
- ti_edma3_cc_wr_4(TI_EDMA3CC_OPT(ch), reg);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_OPT(ch), reg);
+
+ mtx_unlock(&sc->mtx);
return 0;
}
-int
-ti_edma3_request_qdma_ch(unsigned int ch, unsigned int tccn, unsigned int eqn)
+#ifdef notyet
+static int
+ti_edma3_request_qdma_ch(device_t dev, unsigned int ch, unsigned int tccn,
+ unsigned int eqn)
{
+ struct ti_edma3_softc *sc = device_get_softc(dev);
uint32_t reg;
if (ch >= TI_EDMA3_NUM_DMA_CHS)
return (EINVAL);
+ mtx_lock(&sc->mtx);
+
/* Enable the QDMA channel in the QRAE registers */
- reg = ti_edma3_cc_rd_4(TI_EDMA3CC_QRAE(0));
+ reg = ti_edma3_cc_rd_4(sc, TI_EDMA3CC_QRAE(0));
reg |= (0x01 << ch);
- ti_edma3_cc_wr_4(TI_EDMA3CC_QRAE(0), reg);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_QRAE(0), reg);
/* Associate QDMA Channel to Event Queue */
- reg = ti_edma3_cc_rd_4(TI_EDMA3CC_QDMAQNUM);
+ reg = ti_edma3_cc_rd_4(sc, TI_EDMA3CC_QDMAQNUM);
reg |= TI_EDMA3CC_QDMAQNUM_SET(ch, eqn);
- ti_edma3_cc_wr_4(TI_EDMA3CC_QDMAQNUM, reg);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_QDMAQNUM, reg);
/* Set TCC in corresponding PaRAM Entry */
- reg = ti_edma3_cc_rd_4(TI_EDMA3CC_OPT(ch));
+ reg = ti_edma3_cc_rd_4(sc, TI_EDMA3CC_OPT(ch));
reg &= TI_EDMA3CC_OPT_TCC_CLR;
reg |= TI_EDMA3CC_OPT_TCC_SET(ch);
- ti_edma3_cc_wr_4(TI_EDMA3CC_OPT(ch), reg);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_OPT(ch), reg);
+
+ mtx_unlock(&sc->mtx);
return 0;
}
-int
-ti_edma3_enable_transfer_manual(unsigned int ch)
+static int
+ti_edma3_enable_transfer_manual(device_t dev, unsigned int ch)
{
+ struct ti_edma3_softc *sc = device_get_softc(dev);
+
if (ch >= TI_EDMA3_NUM_DMA_CHS)
return (EINVAL);
/* set corresponding bit in ESR/ESRH to set a event */
if (ch < 32) {
- ti_edma3_cc_wr_4(TI_EDMA3CC_S_ESR(0), 1 << ch);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_ESR(0), 1 << ch);
} else {
- ti_edma3_cc_wr_4(TI_EDMA3CC_S_ESRH(0), 1 << (ch - 32));
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_ESRH(0), 1 << (ch - 32));
}
return 0;
}
-int
-ti_edma3_enable_transfer_qdma(unsigned int ch)
+static int
+ti_edma3_enable_transfer_qdma(device_t dev, unsigned int ch)
{
+ struct ti_edma3_softc *sc = device_get_softc(dev);
+
if (ch >= TI_EDMA3_NUM_QDMA_CHS)
return (EINVAL);
/* set corresponding bit in QEESR to enable QDMA event */
- ti_edma3_cc_wr_4(TI_EDMA3CC_S_QEESR(0), (1 << ch));
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_QEESR(0), (1 << ch));
return 0;
}
+#endif
-int
-ti_edma3_enable_transfer_event(unsigned int ch)
+static int
+ti_edma3_enable_transfer_event(device_t dev, unsigned int ch)
{
+ struct ti_edma3_softc *sc = device_get_softc(dev);
+
if (ch >= TI_EDMA3_NUM_DMA_CHS)
return (EINVAL);
/* Clear SECR(H) & EMCR(H) to clean any previous NULL request
* and set corresponding bit in EESR to enable DMA event */
if(ch < 32) {
- ti_edma3_cc_wr_4(TI_EDMA3CC_S_SECR(0), (1 << ch));
- ti_edma3_cc_wr_4(TI_EDMA3CC_EMCR, (1 << ch));
- ti_edma3_cc_wr_4(TI_EDMA3CC_S_EESR(0), (1 << ch));
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_SECR(0), (1 << ch));
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_EMCR, (1 << ch));
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_EESR(0), (1 << ch));
} else {
- ti_edma3_cc_wr_4(TI_EDMA3CC_S_SECRH(0), 1 << (ch - 32));
- ti_edma3_cc_wr_4(TI_EDMA3CC_EMCRH, 1 << (ch - 32));
- ti_edma3_cc_wr_4(TI_EDMA3CC_S_EESRH(0), 1 << (ch - 32));
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_SECRH(0), 1 << (ch - 32));
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_EMCRH, 1 << (ch - 32));
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_EESRH(0), 1 << (ch - 32));
}
return 0;
}
-void
-ti_edma3_param_write(unsigned int ch, struct ti_edma3cc_param_set *prs)
+static void
+ti_edma3_param_write(device_t dev, unsigned int ch,
+ struct ti_edma3cc_param_set *prs)
{
- bus_write_region_4(ti_edma3_sc->mem_res[0], TI_EDMA3CC_OPT(ch),
+ struct ti_edma3_softc *sc = device_get_softc(dev);
+
+ bus_write_region_4(sc->mem_res[0], TI_EDMA3CC_OPT(ch),
(uint32_t *) prs, 8);
}
-void
-ti_edma3_param_read(unsigned int ch, struct ti_edma3cc_param_set *prs)
+#ifdef notyet
+static void
+ti_edma3_param_read(device_t dev, unsigned int ch,
+ struct ti_edma3cc_param_set *prs)
{
- bus_read_region_4(ti_edma3_sc->mem_res[0], TI_EDMA3CC_OPT(ch),
+ struct ti_edma3_softc *sc = device_get_softc(dev);
+
+ bus_read_region_4(sc->mem_res[0], TI_EDMA3CC_OPT(ch),
(uint32_t *) prs, 8);
}
+#endif
+
+static int
+ti_edma3_channel_alloc(device_t dev, unsigned int ch, unsigned int eqn,
+ unsigned int nsets)
+{
+ struct ti_edma3_softc *sc = device_get_softc(dev);
+ int err;
+
+ if (ch >= TI_EDMA3_NUM_DMA_CHS || nsets == 0)
+ return (EINVAL);
+
+ /* The channel's own PaRAM set is the first one in its chain. */
+ mtx_lock(&sc->mtx);
+ if (nsets - 1 <= sc->link_count[ch])
+ err = 0;
+ else if (nsets - 1 > sc->num_param - sc->next_param)
+ err = ENOSPC;
+ else {
+ sc->link_base[ch] = sc->next_param;
+ sc->link_count[ch] = nsets - 1;
+ sc->next_param += nsets - 1;
+ err = 0;
+ }
+ mtx_unlock(&sc->mtx);
+ if (err != 0)
+ return (err);
+
+ return (ti_edma3_request_dma_ch(dev, ch, ch, eqn));
+}
+
+/*
+ * Write a chain of nsets PaRAM sets for channel ch, linked in order. Every
+ * set uses the channel number as its completion code, and only the last one
+ * reports completion.
+ */
+static int
+ti_edma3_transfer_setup(device_t dev, unsigned int ch,
+ const struct ti_edma3cc_param_set *sets, unsigned int nsets)
+{
+ struct ti_edma3_softc *sc = device_get_softc(dev);
+ struct ti_edma3cc_param_set ps;
+ unsigned int i;
+
+ if (ch >= TI_EDMA3_NUM_DMA_CHS || nsets == 0 ||
+ nsets - 1 > sc->link_count[ch])
+ return (EINVAL);
+
+ for (i = 0; i < nsets; i++) {
+ ps = sets[i];
+ ps.opt.tcc = ch;
+ ps.opt.tcinten = (i + 1 == nsets) ? 1 : 0;
+ if (i + 1 < nsets)
+ ps.link = TI_EDMA3CC_OPT(sc->link_base[ch] + i);
+ else
+ ps.link = 0xffff;
+ ti_edma3_param_write(dev,
+ i == 0 ? ch : sc->link_base[ch] + i - 1, &ps);
+ }
+
+ return (0);
+}
+
+static int
+ti_edma3_transfer_start(device_t dev, unsigned int ch)
+{
+ struct ti_edma3_softc *sc = device_get_softc(dev);
+
+ if (ch >= TI_EDMA3_NUM_DMA_CHS)
+ return (EINVAL);
+
+ if (ch < 32)
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_ICR(0), 1 << ch);
+ else
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_ICRH(0), 1 << (ch - 32));
+
+ return (ti_edma3_enable_transfer_event(dev, ch));
+}
+
+static int
+ti_edma3_transfer_status(device_t dev, unsigned int ch)
+{
+ struct ti_edma3_softc *sc = device_get_softc(dev);
+ uint32_t ipr, emr;
+ int status;
+
+ if (ch >= TI_EDMA3_NUM_DMA_CHS)
+ return (0);
+
+ if (ch < 32) {
+ ipr = ti_edma3_cc_rd_4(sc, TI_EDMA3CC_S_IPR(0)) & (1 << ch);
+ emr = ti_edma3_cc_rd_4(sc, TI_EDMA3CC_EMR) & (1 << ch);
+ } else {
+ ipr = ti_edma3_cc_rd_4(sc, TI_EDMA3CC_S_IPRH(0)) &
+ (1 << (ch - 32));
+ emr = ti_edma3_cc_rd_4(sc, TI_EDMA3CC_EMRH) & (1 << (ch - 32));
+ }
+
+ status = 0;
+ if (ipr != 0)
+ status |= TI_EDMA3_DONE;
+ if (emr != 0)
+ status |= TI_EDMA3_MISSED;
+ return (status);
+}
+
+/* Disable the channel's event and clear its pending state. */
+static void
+ti_edma3_transfer_stop(device_t dev, unsigned int ch)
+{
+ struct ti_edma3_softc *sc = device_get_softc(dev);
+
+ if (ch >= TI_EDMA3_NUM_DMA_CHS)
+ return;
+
+ if (ch < 32) {
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_EECR(0), 1 << ch);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_SECR(0), 1 << ch);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_ICR(0), 1 << ch);
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_EMCR, 1 << ch);
+ } else {
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_EECRH(0), 1 << (ch - 32));
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_SECRH(0), 1 << (ch - 32));
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_S_ICRH(0), 1 << (ch - 32));
+ ti_edma3_cc_wr_4(sc, TI_EDMA3CC_EMCRH, 1 << (ch - 32));
+ }
+}
+
+/*
+ * The transfer controllers need no setup. Attach only to turn on their
+ * module clocks.
+ */
+static int
+ti_edma3tc_probe(device_t dev)
+{
+ if (!ofw_bus_status_okay(dev))
+ return (ENXIO);
+
+ if (!ofw_bus_is_compatible(dev, "ti,edma3-tptc"))
+ return (ENXIO);
+
+ device_set_desc(dev, "TI EDMA Transfer Controller");
+ return (BUS_PROBE_DEFAULT);
+}
+
+static int
+ti_edma3tc_attach(device_t dev)
+{
+ if (ti_sysc_clock_enable(device_get_parent(dev)) != 0) {
+ device_printf(dev, "cannot enable the module clock\n");
+ return (ENXIO);
+ }
+
+ return (0);
+}
+
+static device_method_t ti_edma3tc_methods[] = {
+ DEVMETHOD(device_probe, ti_edma3tc_probe),
+ DEVMETHOD(device_attach, ti_edma3tc_attach),
+ DEVMETHOD_END
+};
+
+static driver_t ti_edma3tc_driver = {
+ "ti_edma3tc",
+ ti_edma3tc_methods,
+ 0,
+};
+
+DRIVER_MODULE(ti_edma3tc, simplebus, ti_edma3tc_driver, 0, 0);
diff --git a/sys/arm/ti/ti_edma3_if.m b/sys/arm/ti/ti_edma3_if.m
new file mode 100644
--- /dev/null
+++ b/sys/arm/ti/ti_edma3_if.m
@@ -0,0 +1,82 @@
+#-
+# SPDX-License-Identifier: BSD-2-Clause
+#
+# Copyright (c) 2026 Rick Richard <rick@sloservers.com>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+
+#include <sys/bus.h>
+#include <arm/ti/ti_edma3.h>
+
+#
+# Methods of the EDMA3 channel controller. Consumers find it through their
+# "dmas" property, and channel numbers are the request lines given there.
+#
+INTERFACE ti_edma3;
+
+#
+# Set up DMA channel ch on event queue eqn, with room for chains of up to
+# nsets PaRAM sets.
+#
+METHOD int channel_alloc {
+ device_t dev;
+ unsigned int ch;
+ unsigned int eqn;
+ unsigned int nsets;
+};
+
+#
+# Load a transfer of nsets linked PaRAM sets on channel ch. The controller
+# fills in the completion code and the links.
+#
+METHOD int transfer_setup {
+ device_t dev;
+ unsigned int ch;
+ const struct ti_edma3cc_param_set *sets;
+ unsigned int nsets;
+};
+
+#
+# Enable the channel's hardware event, so its requests run the loaded transfer.
+#
+METHOD int transfer_start {
+ device_t dev;
+ unsigned int ch;
+};
+
+#
+# Return TI_EDMA3_DONE once the transfer has finished, and TI_EDMA3_MISSED if
+# the channel missed an event.
+#
+METHOD int transfer_status {
+ device_t dev;
+ unsigned int ch;
+};
+
+#
+# Stop the channel and clear its state.
+#
+METHOD void transfer_stop {
+ device_t dev;
+ unsigned int ch;
+};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Nov 26, 9:18 PM (21 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
42028270
Default Alt Text
D59124.1795727889.diff (21 KB)
Attached To
Mode
D59124: arm/ti: attach EDMA3 against the split device tree binding
Attached
Detach File
Event Timeline