1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2013,2018 Intel Corporation
4 #include <linux/bitops.h>
5 #include <linux/dmaengine.h>
6 #include <linux/errno.h>
7 #include <linux/slab.h>
8 #include <linux/types.h>
12 static void idma32_initialize_chan(struct dw_dma_chan
*dwc
)
17 /* Set default burst alignment */
18 cfglo
|= IDMA32C_CFGL_DST_BURST_ALIGN
| IDMA32C_CFGL_SRC_BURST_ALIGN
;
20 /* Low 4 bits of the request lines */
21 cfghi
|= IDMA32C_CFGH_DST_PER(dwc
->dws
.dst_id
& 0xf);
22 cfghi
|= IDMA32C_CFGH_SRC_PER(dwc
->dws
.src_id
& 0xf);
24 /* Request line extension (2 bits) */
25 cfghi
|= IDMA32C_CFGH_DST_PER_EXT(dwc
->dws
.dst_id
>> 4 & 0x3);
26 cfghi
|= IDMA32C_CFGH_SRC_PER_EXT(dwc
->dws
.src_id
>> 4 & 0x3);
28 channel_writel(dwc
, CFG_LO
, cfglo
);
29 channel_writel(dwc
, CFG_HI
, cfghi
);
32 static void idma32_suspend_chan(struct dw_dma_chan
*dwc
, bool drain
)
34 u32 cfglo
= channel_readl(dwc
, CFG_LO
);
37 cfglo
|= IDMA32C_CFGL_CH_DRAIN
;
39 channel_writel(dwc
, CFG_LO
, cfglo
| DWC_CFGL_CH_SUSP
);
42 static void idma32_resume_chan(struct dw_dma_chan
*dwc
, bool drain
)
44 u32 cfglo
= channel_readl(dwc
, CFG_LO
);
47 cfglo
&= ~IDMA32C_CFGL_CH_DRAIN
;
49 channel_writel(dwc
, CFG_LO
, cfglo
& ~DWC_CFGL_CH_SUSP
);
52 static u32
idma32_bytes2block(struct dw_dma_chan
*dwc
,
53 size_t bytes
, unsigned int width
, size_t *len
)
57 if (bytes
> dwc
->block_size
) {
58 block
= dwc
->block_size
;
59 *len
= dwc
->block_size
;
68 static size_t idma32_block2bytes(struct dw_dma_chan
*dwc
, u32 block
, u32 width
)
70 return IDMA32C_CTLH_BLOCK_TS(block
);
73 static u32
idma32_prepare_ctllo(struct dw_dma_chan
*dwc
)
75 struct dma_slave_config
*sconfig
= &dwc
->dma_sconfig
;
76 u8 smsize
= (dwc
->direction
== DMA_DEV_TO_MEM
) ? sconfig
->src_maxburst
: 0;
77 u8 dmsize
= (dwc
->direction
== DMA_MEM_TO_DEV
) ? sconfig
->dst_maxburst
: 0;
79 return DWC_CTLL_LLP_D_EN
| DWC_CTLL_LLP_S_EN
|
80 DWC_CTLL_DST_MSIZE(dmsize
) | DWC_CTLL_SRC_MSIZE(smsize
);
83 static void idma32_encode_maxburst(struct dw_dma_chan
*dwc
, u32
*maxburst
)
85 *maxburst
= *maxburst
> 1 ? fls(*maxburst
) - 1 : 0;
88 static void idma32_set_device_name(struct dw_dma
*dw
, int id
)
90 snprintf(dw
->name
, sizeof(dw
->name
), "idma32:dmac%d", id
);
94 * Program FIFO size of channels.
96 * By default full FIFO (512 bytes) is assigned to channel 0. Here we
97 * slice FIFO on equal parts between channels.
99 static void idma32_fifo_partition(struct dw_dma
*dw
)
101 u64 value
= IDMA32C_FP_PSIZE_CH0(64) | IDMA32C_FP_PSIZE_CH1(64) |
103 u64 fifo_partition
= 0;
105 /* Fill FIFO_PARTITION low bits (Channels 0..1, 4..5) */
106 fifo_partition
|= value
<< 0;
108 /* Fill FIFO_PARTITION high bits (Channels 2..3, 6..7) */
109 fifo_partition
|= value
<< 32;
111 /* Program FIFO Partition registers - 64 bytes per channel */
112 idma32_writeq(dw
, FIFO_PARTITION1
, fifo_partition
);
113 idma32_writeq(dw
, FIFO_PARTITION0
, fifo_partition
);
116 static void idma32_disable(struct dw_dma
*dw
)
119 idma32_fifo_partition(dw
);
122 static void idma32_enable(struct dw_dma
*dw
)
124 idma32_fifo_partition(dw
);
128 int idma32_dma_probe(struct dw_dma_chip
*chip
)
132 dw
= devm_kzalloc(chip
->dev
, sizeof(*dw
), GFP_KERNEL
);
136 /* Channel operations */
137 dw
->initialize_chan
= idma32_initialize_chan
;
138 dw
->suspend_chan
= idma32_suspend_chan
;
139 dw
->resume_chan
= idma32_resume_chan
;
140 dw
->prepare_ctllo
= idma32_prepare_ctllo
;
141 dw
->encode_maxburst
= idma32_encode_maxburst
;
142 dw
->bytes2block
= idma32_bytes2block
;
143 dw
->block2bytes
= idma32_block2bytes
;
145 /* Device operations */
146 dw
->set_device_name
= idma32_set_device_name
;
147 dw
->disable
= idma32_disable
;
148 dw
->enable
= idma32_enable
;
151 return do_dma_probe(chip
);
153 EXPORT_SYMBOL_GPL(idma32_dma_probe
);
155 int idma32_dma_remove(struct dw_dma_chip
*chip
)
157 return do_dma_remove(chip
);
159 EXPORT_SYMBOL_GPL(idma32_dma_remove
);