1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2013,2018 Intel Corporation
4 #include <linux/bitops.h>
5 #include <linux/errno.h>
6 #include <linux/slab.h>
7 #include <linux/types.h>
11 static void idma32_initialize_chan(struct dw_dma_chan *dwc)
16 /* Set default burst alignment */
17 cfglo |= IDMA32C_CFGL_DST_BURST_ALIGN | IDMA32C_CFGL_SRC_BURST_ALIGN;
19 /* Low 4 bits of the request lines */
20 cfghi |= IDMA32C_CFGH_DST_PER(dwc->dws.dst_id & 0xf);
21 cfghi |= IDMA32C_CFGH_SRC_PER(dwc->dws.src_id & 0xf);
23 /* Request line extension (2 bits) */
24 cfghi |= IDMA32C_CFGH_DST_PER_EXT(dwc->dws.dst_id >> 4 & 0x3);
25 cfghi |= IDMA32C_CFGH_SRC_PER_EXT(dwc->dws.src_id >> 4 & 0x3);
27 channel_writel(dwc, CFG_LO, cfglo);
28 channel_writel(dwc, CFG_HI, cfghi);
31 static void idma32_suspend_chan(struct dw_dma_chan *dwc, bool drain)
33 u32 cfglo = channel_readl(dwc, CFG_LO);
36 cfglo |= IDMA32C_CFGL_CH_DRAIN;
38 channel_writel(dwc, CFG_LO, cfglo | DWC_CFGL_CH_SUSP);
41 static void idma32_resume_chan(struct dw_dma_chan *dwc, bool drain)
43 u32 cfglo = channel_readl(dwc, CFG_LO);
46 cfglo &= ~IDMA32C_CFGL_CH_DRAIN;
48 channel_writel(dwc, CFG_LO, cfglo & ~DWC_CFGL_CH_SUSP);
51 static u32 idma32_bytes2block(struct dw_dma_chan *dwc,
52 size_t bytes, unsigned int width, size_t *len)
56 if (bytes > dwc->block_size) {
57 block = dwc->block_size;
58 *len = dwc->block_size;
67 static size_t idma32_block2bytes(struct dw_dma_chan *dwc, u32 block, u32 width)
69 return IDMA32C_CTLH_BLOCK_TS(block);
72 static void idma32_encode_maxburst(struct dw_dma_chan *dwc, u32 *maxburst)
74 *maxburst = *maxburst > 1 ? fls(*maxburst) - 1 : 0;
77 static void idma32_set_device_name(struct dw_dma *dw, int id)
79 snprintf(dw->name, sizeof(dw->name), "idma32:dmac%d", id);
83 * Program FIFO size of channels.
85 * By default full FIFO (512 bytes) is assigned to channel 0. Here we
86 * slice FIFO on equal parts between channels.
88 static void idma32_fifo_partition(struct dw_dma *dw)
90 u64 value = IDMA32C_FP_PSIZE_CH0(64) | IDMA32C_FP_PSIZE_CH1(64) |
92 u64 fifo_partition = 0;
94 /* Fill FIFO_PARTITION low bits (Channels 0..1, 4..5) */
95 fifo_partition |= value << 0;
97 /* Fill FIFO_PARTITION high bits (Channels 2..3, 6..7) */
98 fifo_partition |= value << 32;
100 /* Program FIFO Partition registers - 64 bytes per channel */
101 idma32_writeq(dw, FIFO_PARTITION1, fifo_partition);
102 idma32_writeq(dw, FIFO_PARTITION0, fifo_partition);
105 static void idma32_disable(struct dw_dma *dw)
108 idma32_fifo_partition(dw);
111 static void idma32_enable(struct dw_dma *dw)
113 idma32_fifo_partition(dw);
117 int idma32_dma_probe(struct dw_dma_chip *chip)
121 dw = devm_kzalloc(chip->dev, sizeof(*dw), GFP_KERNEL);
125 /* Channel operations */
126 dw->initialize_chan = idma32_initialize_chan;
127 dw->suspend_chan = idma32_suspend_chan;
128 dw->resume_chan = idma32_resume_chan;
129 dw->encode_maxburst = idma32_encode_maxburst;
130 dw->bytes2block = idma32_bytes2block;
131 dw->block2bytes = idma32_block2bytes;
133 /* Device operations */
134 dw->set_device_name = idma32_set_device_name;
135 dw->disable = idma32_disable;
136 dw->enable = idma32_enable;
139 return do_dma_probe(chip);
141 EXPORT_SYMBOL_GPL(idma32_dma_probe);
143 int idma32_dma_remove(struct dw_dma_chip *chip)
145 return do_dma_remove(chip);
147 EXPORT_SYMBOL_GPL(idma32_dma_remove);