drivers/dma/loongson/loongson2-apb-cmc-dma.c

Source file repositories/reference/linux-study-clean/drivers/dma/loongson/loongson2-apb-cmc-dma.c

File Facts

System
Linux kernel
Corpus path
drivers/dma/loongson/loongson2-apb-cmc-dma.c
Extension
.c
Size
22046 bytes
Lines
731
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct loongson2_cmc_dma_chan_reg {
	u32 ccr;
	u32 cndtr;
	u32 cpar;
	u32 cmar;
};

struct loongson2_cmc_dma_sg_req {
	u32 len;
	struct loongson2_cmc_dma_chan_reg chan_reg;
};

struct loongson2_cmc_dma_desc {
	struct virt_dma_desc vdesc;
	bool cyclic;
	u32 num_sgs;
	struct loongson2_cmc_dma_sg_req sg_req[] __counted_by(num_sgs);
};

struct loongson2_cmc_dma_chan {
	struct virt_dma_chan vchan;
	struct dma_slave_config	dma_sconfig;
	struct loongson2_cmc_dma_desc *desc;
	u32 id;
	u32 irq;
	u32 next_sg;
	struct loongson2_cmc_dma_chan_reg chan_reg;
};

struct loongson2_cmc_dma_dev {
	struct dma_device ddev;
	struct clk *dma_clk;
	void __iomem *base;
	u32 nr_channels;
	u32 chan_reg_offset;
	struct loongson2_cmc_dma_chan chan[] __counted_by(nr_channels);
};

struct loongson2_cmc_dma_config {
	u32 max_channels;
	u32 chan_reg_offset;
};

static const struct loongson2_cmc_dma_config ls2k0300_cmc_dma_config = {
	.max_channels = 8,
	.chan_reg_offset = 0x14,
};

static const struct loongson2_cmc_dma_config ls2k3000_cmc_dma_config = {
	.max_channels = 4,
	.chan_reg_offset = 0x18,
};

static struct loongson2_cmc_dma_dev *lmdma_get_dev(struct loongson2_cmc_dma_chan *lchan)
{
	return container_of(lchan->vchan.chan.device, struct loongson2_cmc_dma_dev, ddev);
}

static struct loongson2_cmc_dma_chan *to_lmdma_chan(struct dma_chan *chan)
{
	return container_of(chan, struct loongson2_cmc_dma_chan, vchan.chan);
}

static struct loongson2_cmc_dma_desc *to_lmdma_desc(struct virt_dma_desc *vdesc)
{
	return container_of(vdesc, struct loongson2_cmc_dma_desc, vdesc);
}

static struct device *chan2dev(struct loongson2_cmc_dma_chan *lchan)
{
	return &lchan->vchan.chan.dev->device;
}

static u32 loongson2_cmc_dma_read(struct loongson2_cmc_dma_dev *lddev, u32 reg, u32 id)
{
	return readl(lddev->base + (reg + lddev->chan_reg_offset * id));
}

static void loongson2_cmc_dma_write(struct loongson2_cmc_dma_dev *lddev, u32 reg, u32 id, u32 val)
{
	writel(val, lddev->base + (reg + lddev->chan_reg_offset * id));
}

static int loongson2_cmc_dma_get_width(enum dma_slave_buswidth width)
{
	switch (width) {
	case DMA_SLAVE_BUSWIDTH_1_BYTE:
	case DMA_SLAVE_BUSWIDTH_2_BYTES:
	case DMA_SLAVE_BUSWIDTH_4_BYTES:
		return ffs(width) - 1;

Annotation

Implementation Notes