drivers/dma/mediatek/mtk-uart-apdma.c
Source file repositories/reference/linux-study-clean/drivers/dma/mediatek/mtk-uart-apdma.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/dma/mediatek/mtk-uart-apdma.c- Extension
.c- Size
- 17142 bytes
- Lines
- 654
- Domain
- Driver Families
- Bucket
- drivers/dma
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/dmaengine.hlinux/dma-mapping.hlinux/err.hlinux/init.hlinux/interrupt.hlinux/iopoll.hlinux/kernel.hlinux/list.hlinux/module.hlinux/of_dma.hlinux/platform_device.hlinux/pm_runtime.hlinux/slab.hlinux/spinlock.h../virt-dma.h
Detected Declarations
struct mtk_uart_apdmadevstruct mtk_uart_apdma_descstruct mtk_chanfunction to_mtk_uart_apdma_devfunction mtk_uart_apdma_writefunction mtk_uart_apdma_readfunction mtk_uart_apdma_desc_freefunction mtk_uart_apdma_start_txfunction mtk_uart_apdma_start_rxfunction mtk_uart_apdma_tx_handlerfunction mtk_uart_apdma_rx_handlerfunction mtk_uart_apdma_chan_complete_handlerfunction mtk_uart_apdma_irq_handlerfunction mtk_uart_apdma_alloc_chan_resourcesfunction mtk_uart_apdma_free_chan_resourcesfunction mtk_uart_apdma_tx_statusfunction mtk_uart_apdma_issue_pendingfunction mtk_uart_apdma_slave_configfunction mtk_uart_apdma_terminate_allfunction mtk_uart_apdma_device_pausefunction mtk_uart_apdma_freefunction mtk_uart_apdma_probefunction mtk_uart_apdma_removefunction mtk_uart_apdma_suspendfunction mtk_uart_apdma_resumefunction mtk_uart_apdma_runtime_suspendfunction mtk_uart_apdma_runtime_resume
Annotated Snippet
struct mtk_uart_apdmadev {
struct dma_device ddev;
struct clk *clk;
bool support_ext_addr;
unsigned int dma_requests;
};
struct mtk_uart_apdma_desc {
struct virt_dma_desc vd;
dma_addr_t addr;
unsigned int avail_len;
};
struct mtk_chan {
struct virt_dma_chan vc;
struct dma_slave_config cfg;
struct mtk_uart_apdma_desc *desc;
enum dma_transfer_direction dir;
void __iomem *base;
unsigned int irq;
unsigned int rx_status;
};
static inline struct mtk_uart_apdmadev *
to_mtk_uart_apdma_dev(struct dma_device *d)
{
return container_of(d, struct mtk_uart_apdmadev, ddev);
}
static inline struct mtk_chan *to_mtk_uart_apdma_chan(struct dma_chan *c)
{
return container_of(c, struct mtk_chan, vc.chan);
}
static inline struct mtk_uart_apdma_desc *to_mtk_uart_apdma_desc
(struct dma_async_tx_descriptor *t)
{
return container_of(t, struct mtk_uart_apdma_desc, vd.tx);
}
static void mtk_uart_apdma_write(struct mtk_chan *c,
unsigned int reg, unsigned int val)
{
writel(val, c->base + reg);
}
static unsigned int mtk_uart_apdma_read(struct mtk_chan *c, unsigned int reg)
{
return readl(c->base + reg);
}
static void mtk_uart_apdma_desc_free(struct virt_dma_desc *vd)
{
kfree(container_of(vd, struct mtk_uart_apdma_desc, vd));
}
static void mtk_uart_apdma_start_tx(struct mtk_chan *c)
{
struct mtk_uart_apdmadev *mtkd =
to_mtk_uart_apdma_dev(c->vc.chan.device);
struct mtk_uart_apdma_desc *d = c->desc;
unsigned int wpt, vff_sz;
vff_sz = c->cfg.dst_port_window_size;
if (!mtk_uart_apdma_read(c, VFF_LEN)) {
mtk_uart_apdma_write(c, VFF_ADDR, d->addr);
mtk_uart_apdma_write(c, VFF_LEN, vff_sz);
mtk_uart_apdma_write(c, VFF_THRE, VFF_TX_THRE(vff_sz));
mtk_uart_apdma_write(c, VFF_WPT, 0);
mtk_uart_apdma_write(c, VFF_INT_FLAG, VFF_TX_INT_CLR_B);
if (mtkd->support_ext_addr)
mtk_uart_apdma_write(c, VFF_ADDR2, upper_32_bits(d->addr));
}
mtk_uart_apdma_write(c, VFF_EN, VFF_EN_B);
if (mtk_uart_apdma_read(c, VFF_EN) != VFF_EN_B)
dev_err(c->vc.chan.device->dev, "Enable TX fail\n");
if (!mtk_uart_apdma_read(c, VFF_LEFT_SIZE)) {
mtk_uart_apdma_write(c, VFF_INT_EN, VFF_TX_INT_EN_B);
return;
}
wpt = mtk_uart_apdma_read(c, VFF_WPT);
wpt += c->desc->avail_len;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/dmaengine.h`, `linux/dma-mapping.h`, `linux/err.h`, `linux/init.h`, `linux/interrupt.h`, `linux/iopoll.h`, `linux/kernel.h`.
- Detected declarations: `struct mtk_uart_apdmadev`, `struct mtk_uart_apdma_desc`, `struct mtk_chan`, `function to_mtk_uart_apdma_dev`, `function mtk_uart_apdma_write`, `function mtk_uart_apdma_read`, `function mtk_uart_apdma_desc_free`, `function mtk_uart_apdma_start_tx`, `function mtk_uart_apdma_start_rx`, `function mtk_uart_apdma_tx_handler`.
- Atlas domain: Driver Families / drivers/dma.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.