Skip to content

Commit e0ddaab

Browse files
saschahauermiquelraynal
authored andcommitted
dmaengine: mxs: Add header file to be shared with gpmi nand driver
The mxs dma driver can do PIO transfers. A pointer to the PIO words to transfer is passed in the struct scatterlist * argument of dmaengine_prep_slave_sg(). It's quite ugly and non obvious to cast u32 * to struct scatterlist * each time when calling dmaengine_prep_slave_sg(), so add a static inline wrapper function to be called by the user along with a description what is going on. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Acked-by: Vinod Koul <vkoul@kernel.org> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 475345e commit e0ddaab

3 files changed

Lines changed: 36 additions & 22 deletions

File tree

‎drivers/dma/mxs-dma.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/of_device.h>
2525
#include <linux/of_dma.h>
2626
#include <linux/list.h>
27+
#include <linux/dma/mxs-dma.h>
2728

2829
#include <asm/irq.h>
2930

‎drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c‎

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/of.h>
1616
#include <linux/of_device.h>
1717
#include <linux/pm_runtime.h>
18+
#include <linux/dma/mxs-dma.h>
1819
#include "gpmi-nand.h"
1920
#include "gpmi-regs.h"
2021
#include "bch-regs.h"
@@ -914,9 +915,8 @@ static int gpmi_send_command(struct gpmi_nand_data *this)
914915
| BM_GPMI_CTRL0_ADDRESS_INCREMENT
915916
| BF_GPMI_CTRL0_XFER_COUNT(this->command_length);
916917
pio[1] = pio[2] = 0;
917-
desc = dmaengine_prep_slave_sg(channel,
918-
(struct scatterlist *)pio,
919-
ARRAY_SIZE(pio), DMA_TRANS_NONE, 0);
918+
desc = mxs_dmaengine_prep_pio(channel, pio, ARRAY_SIZE(pio),
919+
DMA_TRANS_NONE, 0);
920920
if (!desc)
921921
return -EINVAL;
922922

@@ -988,8 +988,8 @@ static int gpmi_send_data(struct gpmi_nand_data *this, const void *buf, int len)
988988
| BF_GPMI_CTRL0_ADDRESS(address)
989989
| BF_GPMI_CTRL0_XFER_COUNT(len);
990990
pio[1] = 0;
991-
desc = dmaengine_prep_slave_sg(channel, (struct scatterlist *)pio,
992-
ARRAY_SIZE(pio), DMA_TRANS_NONE, 0);
991+
desc = mxs_dmaengine_prep_pio(channel, pio, ARRAY_SIZE(pio),
992+
DMA_TRANS_NONE, 0);
993993
if (!desc)
994994
return -EINVAL;
995995

@@ -1025,9 +1025,8 @@ static int gpmi_read_data(struct gpmi_nand_data *this, void *buf, int len)
10251025
| BF_GPMI_CTRL0_ADDRESS(BV_GPMI_CTRL0_ADDRESS__NAND_DATA)
10261026
| BF_GPMI_CTRL0_XFER_COUNT(len);
10271027
pio[1] = 0;
1028-
desc = dmaengine_prep_slave_sg(channel,
1029-
(struct scatterlist *)pio,
1030-
ARRAY_SIZE(pio), DMA_TRANS_NONE, 0);
1028+
desc = mxs_dmaengine_prep_pio(channel, pio, ARRAY_SIZE(pio),
1029+
DMA_TRANS_NONE, 0);
10311030
if (!desc)
10321031
return -EINVAL;
10331032

@@ -1083,10 +1082,8 @@ static int gpmi_send_page(struct gpmi_nand_data *this, dma_addr_t payload,
10831082
pio[4] = payload;
10841083
pio[5] = auxiliary;
10851084

1086-
desc = dmaengine_prep_slave_sg(channel,
1087-
(struct scatterlist *)pio,
1088-
ARRAY_SIZE(pio), DMA_TRANS_NONE,
1089-
DMA_CTRL_ACK);
1085+
desc = mxs_dmaengine_prep_pio(channel, pio, ARRAY_SIZE(pio),
1086+
DMA_TRANS_NONE, DMA_CTRL_ACK);
10901087
if (!desc)
10911088
return -EINVAL;
10921089

@@ -1117,9 +1114,7 @@ static int gpmi_read_page(struct gpmi_nand_data *this, dma_addr_t payload,
11171114
| BF_GPMI_CTRL0_ADDRESS(address)
11181115
| BF_GPMI_CTRL0_XFER_COUNT(0);
11191116
pio[1] = 0;
1120-
desc = dmaengine_prep_slave_sg(channel,
1121-
(struct scatterlist *)pio, 2,
1122-
DMA_TRANS_NONE, 0);
1117+
desc = mxs_dmaengine_prep_pio(channel, pio, 2, DMA_TRANS_NONE, 0);
11231118
if (!desc)
11241119
return -EINVAL;
11251120

@@ -1144,10 +1139,8 @@ static int gpmi_read_page(struct gpmi_nand_data *this, dma_addr_t payload,
11441139
pio[3] = geo->page_size;
11451140
pio[4] = payload;
11461141
pio[5] = auxiliary;
1147-
desc = dmaengine_prep_slave_sg(channel,
1148-
(struct scatterlist *)pio,
1149-
ARRAY_SIZE(pio), DMA_TRANS_NONE,
1150-
DMA_CTRL_ACK);
1142+
desc = mxs_dmaengine_prep_pio(channel, pio, ARRAY_SIZE(pio),
1143+
DMA_TRANS_NONE, DMA_CTRL_ACK);
11511144
if (!desc)
11521145
return -EINVAL;
11531146

@@ -1163,9 +1156,8 @@ static int gpmi_read_page(struct gpmi_nand_data *this, dma_addr_t payload,
11631156
| BF_GPMI_CTRL0_XFER_COUNT(geo->page_size);
11641157
pio[1] = 0;
11651158
pio[2] = 0; /* clear GPMI_HW_GPMI_ECCCTRL, disable the BCH. */
1166-
desc = dmaengine_prep_slave_sg(channel,
1167-
(struct scatterlist *)pio, 3,
1168-
DMA_TRANS_NONE, DMA_CTRL_ACK);
1159+
desc = mxs_dmaengine_prep_pio(channel, pio, 3, DMA_TRANS_NONE,
1160+
DMA_CTRL_ACK);
11691161
if (!desc)
11701162
return -EINVAL;
11711163

‎include/linux/dma/mxs-dma.h‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _MXS_DMA_H_
3+
#define _MXS_DMA_H_
4+
5+
#include <linux/dmaengine.h>
6+
7+
/*
8+
* The mxs dmaengine can do PIO transfers. We pass a pointer to the PIO words
9+
* in the second argument to dmaengine_prep_slave_sg when the direction is
10+
* set to DMA_TRANS_NONE. To make this clear and to prevent users from doing
11+
* the error prone casting we have this wrapper function
12+
*/
13+
static inline struct dma_async_tx_descriptor *mxs_dmaengine_prep_pio(
14+
struct dma_chan *chan, u32 *pio, unsigned int npio,
15+
enum dma_transfer_direction dir, unsigned long flags)
16+
{
17+
return dmaengine_prep_slave_sg(chan, (struct scatterlist *)pio, npio,
18+
dir, flags);
19+
}
20+
21+
#endif /* _MXS_DMA_H_ */

0 commit comments

Comments
 (0)