Skip to content

Commit beeaa10

Browse files
Nicolas FerreVinod Koul
authored andcommitted
dmaengine: at_hdmac: add slave config operation
This patch introduces DMA_SLAVE_CONFIG to at_hdmac Atmel DMA driver. It is needed to fix a regression in the use of atmel-mci.c driver on Atmel AT91 platforms brouth by e2b35f3: "dmaengine/dw_dmac: Fix dw_dmac user drivers to adapt to slave_config changes" We remove some parts of the private structure "at_dma_slave" and use the information provided by "struct dma_slave_config": source/destination peripheral registers and access width. AT_DMA_SLAVE_WIDTH_* values used previously are not needed anymore as we now use the standard ones. Although some conversion functions are needed to match register expected values. Some AT91 sub-architecture specific files are slightly touched by this patch but it cannot be split because it can break compilation. Signed-off-by: Nicolas Ferre <nicolas.ferre@atmel.com> Signed-off-by: Vinod Koul <vinod.koul@linux.intel.com>
1 parent 185ecb5 commit beeaa10

4 files changed

Lines changed: 75 additions & 29 deletions

File tree

‎arch/arm/mach-at91/at91sam9g45_devices.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,6 @@ void __init at91_add_device_mci(short mmc_id, struct mci_platform_data *data)
431431

432432
/* DMA slave channel configuration */
433433
atslave->dma_dev = &at_hdmac_device.dev;
434-
atslave->reg_width = AT_DMA_SLAVE_WIDTH_32BIT;
435434
atslave->cfg = ATC_FIFOCFG_HALFFIFO
436435
| ATC_SRC_H2SEL_HW | ATC_DST_H2SEL_HW;
437436
atslave->ctrla = ATC_SCSIZE_16 | ATC_DCSIZE_16;

‎arch/arm/mach-at91/include/mach/at_hdmac.h‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,6 @@ struct at_dma_platform_data {
2323
dma_cap_mask_t cap_mask;
2424
};
2525

26-
/**
27-
* enum at_dma_slave_width - DMA slave register access width.
28-
* @AT_DMA_SLAVE_WIDTH_8BIT: Do 8-bit slave register accesses
29-
* @AT_DMA_SLAVE_WIDTH_16BIT: Do 16-bit slave register accesses
30-
* @AT_DMA_SLAVE_WIDTH_32BIT: Do 32-bit slave register accesses
31-
*/
32-
enum at_dma_slave_width {
33-
AT_DMA_SLAVE_WIDTH_8BIT = 0,
34-
AT_DMA_SLAVE_WIDTH_16BIT,
35-
AT_DMA_SLAVE_WIDTH_32BIT,
36-
};
37-
3826
/**
3927
* struct at_dma_slave - Controller-specific information about a slave
4028
* @dma_dev: required DMA master device
@@ -48,9 +36,6 @@ enum at_dma_slave_width {
4836
*/
4937
struct at_dma_slave {
5038
struct device *dma_dev;
51-
dma_addr_t tx_reg;
52-
dma_addr_t rx_reg;
53-
enum at_dma_slave_width reg_width;
5439
u32 cfg;
5540
u32 ctrla;
5641
};

‎drivers/dma/at_hdmac.c‎

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
648648
{
649649
struct at_dma_chan *atchan = to_at_dma_chan(chan);
650650
struct at_dma_slave *atslave = chan->private;
651+
struct dma_slave_config *sconfig = &atchan->dma_sconfig;
651652
struct at_desc *first = NULL;
652653
struct at_desc *prev = NULL;
653654
u32 ctrla;
@@ -669,19 +670,18 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
669670
return NULL;
670671
}
671672

672-
reg_width = atslave->reg_width;
673-
674673
ctrla = ATC_DEFAULT_CTRLA | atslave->ctrla;
675674
ctrlb = ATC_IEN;
676675

677676
switch (direction) {
678677
case DMA_MEM_TO_DEV:
678+
reg_width = convert_buswidth(sconfig->dst_addr_width);
679679
ctrla |= ATC_DST_WIDTH(reg_width);
680680
ctrlb |= ATC_DST_ADDR_MODE_FIXED
681681
| ATC_SRC_ADDR_MODE_INCR
682682
| ATC_FC_MEM2PER
683683
| ATC_SIF(AT_DMA_MEM_IF) | ATC_DIF(AT_DMA_PER_IF);
684-
reg = atslave->tx_reg;
684+
reg = sconfig->dst_addr;
685685
for_each_sg(sgl, sg, sg_len, i) {
686686
struct at_desc *desc;
687687
u32 len;
@@ -709,13 +709,14 @@ atc_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl,
709709
}
710710
break;
711711
case DMA_DEV_TO_MEM:
712+
reg_width = convert_buswidth(sconfig->src_addr_width);
712713
ctrla |= ATC_SRC_WIDTH(reg_width);
713714
ctrlb |= ATC_DST_ADDR_MODE_INCR
714715
| ATC_SRC_ADDR_MODE_FIXED
715716
| ATC_FC_PER2MEM
716717
| ATC_SIF(AT_DMA_PER_IF) | ATC_DIF(AT_DMA_MEM_IF);
717718

718-
reg = atslave->rx_reg;
719+
reg = sconfig->src_addr;
719720
for_each_sg(sgl, sg, sg_len, i) {
720721
struct at_desc *desc;
721722
u32 len;
@@ -791,12 +792,15 @@ atc_dma_cyclic_check_values(unsigned int reg_width, dma_addr_t buf_addr,
791792
* atc_dma_cyclic_fill_desc - Fill one period decriptor
792793
*/
793794
static int
794-
atc_dma_cyclic_fill_desc(struct at_dma_slave *atslave, struct at_desc *desc,
795+
atc_dma_cyclic_fill_desc(struct dma_chan *chan, struct at_desc *desc,
795796
unsigned int period_index, dma_addr_t buf_addr,
796-
size_t period_len, enum dma_transfer_direction direction)
797+
unsigned int reg_width, size_t period_len,
798+
enum dma_transfer_direction direction)
797799
{
798-
u32 ctrla;
799-
unsigned int reg_width = atslave->reg_width;
800+
struct at_dma_chan *atchan = to_at_dma_chan(chan);
801+
struct at_dma_slave *atslave = chan->private;
802+
struct dma_slave_config *sconfig = &atchan->dma_sconfig;
803+
u32 ctrla;
800804

801805
/* prepare common CRTLA value */
802806
ctrla = ATC_DEFAULT_CTRLA | atslave->ctrla
@@ -807,7 +811,7 @@ atc_dma_cyclic_fill_desc(struct at_dma_slave *atslave, struct at_desc *desc,
807811
switch (direction) {
808812
case DMA_MEM_TO_DEV:
809813
desc->lli.saddr = buf_addr + (period_len * period_index);
810-
desc->lli.daddr = atslave->tx_reg;
814+
desc->lli.daddr = sconfig->dst_addr;
811815
desc->lli.ctrla = ctrla;
812816
desc->lli.ctrlb = ATC_DST_ADDR_MODE_FIXED
813817
| ATC_SRC_ADDR_MODE_INCR
@@ -817,7 +821,7 @@ atc_dma_cyclic_fill_desc(struct at_dma_slave *atslave, struct at_desc *desc,
817821
break;
818822

819823
case DMA_DEV_TO_MEM:
820-
desc->lli.saddr = atslave->rx_reg;
824+
desc->lli.saddr = sconfig->src_addr;
821825
desc->lli.daddr = buf_addr + (period_len * period_index);
822826
desc->lli.ctrla = ctrla;
823827
desc->lli.ctrlb = ATC_DST_ADDR_MODE_INCR
@@ -850,9 +854,11 @@ atc_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
850854
{
851855
struct at_dma_chan *atchan = to_at_dma_chan(chan);
852856
struct at_dma_slave *atslave = chan->private;
857+
struct dma_slave_config *sconfig = &atchan->dma_sconfig;
853858
struct at_desc *first = NULL;
854859
struct at_desc *prev = NULL;
855860
unsigned long was_cyclic;
861+
unsigned int reg_width;
856862
unsigned int periods = buf_len / period_len;
857863
unsigned int i;
858864

@@ -872,8 +878,13 @@ atc_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
872878
return NULL;
873879
}
874880

881+
if (sconfig->direction == DMA_MEM_TO_DEV)
882+
reg_width = convert_buswidth(sconfig->dst_addr_width);
883+
else
884+
reg_width = convert_buswidth(sconfig->src_addr_width);
885+
875886
/* Check for too big/unaligned periods and unaligned DMA buffer */
876-
if (atc_dma_cyclic_check_values(atslave->reg_width, buf_addr,
887+
if (atc_dma_cyclic_check_values(reg_width, buf_addr,
877888
period_len, direction))
878889
goto err_out;
879890

@@ -885,8 +896,8 @@ atc_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
885896
if (!desc)
886897
goto err_desc_get;
887898

888-
if (atc_dma_cyclic_fill_desc(atslave, desc, i, buf_addr,
889-
period_len, direction))
899+
if (atc_dma_cyclic_fill_desc(chan, desc, i, buf_addr,
900+
reg_width, period_len, direction))
890901
goto err_desc_get;
891902

892903
atc_desc_chain(&first, &prev, desc);
@@ -909,6 +920,23 @@ atc_prep_dma_cyclic(struct dma_chan *chan, dma_addr_t buf_addr, size_t buf_len,
909920
return NULL;
910921
}
911922

923+
static int set_runtime_config(struct dma_chan *chan,
924+
struct dma_slave_config *sconfig)
925+
{
926+
struct at_dma_chan *atchan = to_at_dma_chan(chan);
927+
928+
/* Check if it is chan is configured for slave transfers */
929+
if (!chan->private)
930+
return -EINVAL;
931+
932+
memcpy(&atchan->dma_sconfig, sconfig, sizeof(*sconfig));
933+
934+
convert_burst(&atchan->dma_sconfig.src_maxburst);
935+
convert_burst(&atchan->dma_sconfig.dst_maxburst);
936+
937+
return 0;
938+
}
939+
912940

913941
static int atc_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
914942
unsigned long arg)
@@ -969,6 +997,8 @@ static int atc_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
969997
clear_bit(ATC_IS_CYCLIC, &atchan->status);
970998

971999
spin_unlock_irqrestore(&atchan->lock, flags);
1000+
} else if (cmd == DMA_SLAVE_CONFIG) {
1001+
return set_runtime_config(chan, (struct dma_slave_config *)arg);
9721002
} else {
9731003
return -ENXIO;
9741004
}

‎drivers/dma/at_hdmac_regs.h‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ enum atc_status {
207207
* @save_cfg: configuration register that is saved on suspend/resume cycle
208208
* @save_dscr: for cyclic operations, preserve next descriptor address in
209209
* the cyclic list on suspend/resume cycle
210+
* @dma_sconfig: configuration for slave transfers, passed via DMA_SLAVE_CONFIG
210211
* @lock: serializes enqueue/dequeue operations to descriptors lists
211212
* @active_list: list of descriptors dmaengine is being running on
212213
* @queue: list of descriptors ready to be submitted to engine
@@ -222,6 +223,7 @@ struct at_dma_chan {
222223
struct tasklet_struct tasklet;
223224
u32 save_cfg;
224225
u32 save_dscr;
226+
struct dma_slave_config dma_sconfig;
225227

226228
spinlock_t lock;
227229

@@ -243,6 +245,36 @@ static inline struct at_dma_chan *to_at_dma_chan(struct dma_chan *dchan)
243245
return container_of(dchan, struct at_dma_chan, chan_common);
244246
}
245247

248+
/*
249+
* Fix sconfig's burst size according to at_hdmac. We need to convert them as:
250+
* 1 -> 0, 4 -> 1, 8 -> 2, 16 -> 3, 32 -> 4, 64 -> 5, 128 -> 6, 256 -> 7.
251+
*
252+
* This can be done by finding most significant bit set.
253+
*/
254+
static inline void convert_burst(u32 *maxburst)
255+
{
256+
if (*maxburst > 1)
257+
*maxburst = fls(*maxburst) - 2;
258+
else
259+
*maxburst = 0;
260+
}
261+
262+
/*
263+
* Fix sconfig's bus width according to at_hdmac.
264+
* 1 byte -> 0, 2 bytes -> 1, 4 bytes -> 2.
265+
*/
266+
static inline u8 convert_buswidth(enum dma_slave_buswidth addr_width)
267+
{
268+
switch (addr_width) {
269+
case DMA_SLAVE_BUSWIDTH_2_BYTES:
270+
return 1;
271+
case DMA_SLAVE_BUSWIDTH_4_BYTES:
272+
return 2;
273+
default:
274+
/* For 1 byte width or fallback */
275+
return 0;
276+
}
277+
}
246278

247279
/*-- Controller ------------------------------------------------------*/
248280

0 commit comments

Comments
 (0)