Skip to content

Commit 8c92013

Browse files
author
Shawn Guo
committed
dma: mxs-dma: make platform_device_id more generic
Rewrite mxs_dma_is_apbh and mxs_dma_is_apbx in order to support other SoCs like imx6q and reform the platform_device_id for the better further dt support. Cc: Dan Williams <dan.j.williams@intel.com> Cc: Sascha Hauer <s.hauer@pengutronix.de> Cc: Huang Shijie <b32955@freescale.com> Signed-off-by: Dong Aisheng <dong.aisheng@linaro.org> Signed-off-by: Shawn Guo <shawn.guo@linaro.org> Acked-by: Marek Vasut <marex@denx.de> Acked-by: Vinod Koul <vinod.koul@intel.com>
1 parent bb11fb6 commit 8c92013

5 files changed

Lines changed: 93 additions & 56 deletions

File tree

‎arch/arm/mach-mxs/devices/platform-dma.c‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@ static struct platform_device *__init mxs_add_dma(const char *devid,
3232

3333
static int __init mxs_add_mxs_dma(void)
3434
{
35-
char *apbh = "mxs-dma-apbh";
36-
char *apbx = "mxs-dma-apbx";
35+
char *mx23_apbh = "imx23-dma-apbh";
36+
char *mx23_apbx = "imx23-dma-apbx";
37+
char *mx28_apbh = "imx28-dma-apbh";
38+
char *mx28_apbx = "imx28-dma-apbx";
3739

3840
if (cpu_is_mx23()) {
39-
mxs_add_dma(apbh, MX23_APBH_DMA_BASE_ADDR);
40-
mxs_add_dma(apbx, MX23_APBX_DMA_BASE_ADDR);
41+
mxs_add_dma(mx23_apbh, MX23_APBH_DMA_BASE_ADDR);
42+
mxs_add_dma(mx23_apbx, MX23_APBX_DMA_BASE_ADDR);
4143
}
4244

4345
if (cpu_is_mx28()) {
44-
mxs_add_dma(apbh, MX28_APBH_DMA_BASE_ADDR);
45-
mxs_add_dma(apbx, MX28_APBX_DMA_BASE_ADDR);
46+
mxs_add_dma(mx28_apbh, MX28_APBH_DMA_BASE_ADDR);
47+
mxs_add_dma(mx28_apbx, MX28_APBX_DMA_BASE_ADDR);
4648
}
4749

4850
return 0;

‎drivers/clk/mxs/clk-imx23.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,14 @@ static struct clk_lookup uart_lookups[] __initdata = {
8181
};
8282

8383
static struct clk_lookup hbus_lookups[] __initdata = {
84-
{ .dev_id = "mxs-dma-apbh", },
84+
{ .dev_id = "imx23-dma-apbh", },
8585
{ .dev_id = "80004000.dma-apbh", },
8686
};
8787

8888
static struct clk_lookup xbus_lookups[] __initdata = {
8989
{ .dev_id = "duart", .con_id = "apb_pclk"},
9090
{ .dev_id = "80070000.serial", .con_id = "apb_pclk"},
91-
{ .dev_id = "mxs-dma-apbx", },
91+
{ .dev_id = "imx23-dma-apbx", },
9292
{ .dev_id = "80024000.dma-apbx", },
9393
};
9494

‎drivers/clk/mxs/clk-imx28.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ static struct clk_lookup uart_lookups[] __initdata = {
136136
};
137137

138138
static struct clk_lookup hbus_lookups[] __initdata = {
139-
{ .dev_id = "mxs-dma-apbh", },
139+
{ .dev_id = "imx28-dma-apbh", },
140140
{ .dev_id = "80004000.dma-apbh", },
141141
};
142142

143143
static struct clk_lookup xbus_lookups[] __initdata = {
144144
{ .dev_id = "duart", .con_id = "apb_pclk"},
145145
{ .dev_id = "80074000.serial", .con_id = "apb_pclk"},
146-
{ .dev_id = "mxs-dma-apbx", },
146+
{ .dev_id = "imx28-dma-apbx", },
147147
{ .dev_id = "80024000.dma-apbx", },
148148
};
149149

‎drivers/dma/mxs-dma.c‎

Lines changed: 79 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,8 @@
3636
* dma can program the controller registers of peripheral devices.
3737
*/
3838

39-
#define MXS_DMA_APBH 0
40-
#define MXS_DMA_APBX 1
41-
#define dma_is_apbh(mxs_dma) ((mxs_dma)->dev_id == MXS_DMA_APBH)
42-
43-
#define APBH_VERSION_LATEST 3
44-
#define apbh_is_old(mxs_dma) ((mxs_dma)->version < APBH_VERSION_LATEST)
39+
#define dma_is_apbh(mxs_dma) ((mxs_dma)->type == MXS_DMA_APBH)
40+
#define apbh_is_old(mxs_dma) ((mxs_dma)->dev_id == IMX23_DMA)
4541

4642
#define HW_APBHX_CTRL0 0x000
4743
#define BM_APBH_CTRL0_APB_BURST8_EN (1 << 29)
@@ -51,9 +47,6 @@
5147
#define HW_APBHX_CTRL2 0x020
5248
#define HW_APBHX_CHANNEL_CTRL 0x030
5349
#define BP_APBHX_CHANNEL_CTRL_RESET_CHANNEL 16
54-
#define HW_APBH_VERSION (cpu_is_mx23() ? 0x3f0 : 0x800)
55-
#define HW_APBX_VERSION 0x800
56-
#define BP_APBHX_VERSION_MAJOR 24
5750
/*
5851
* The offset of NXTCMDAR register is different per both dma type and version,
5952
* while stride for each channel is all the same 0x70.
@@ -125,16 +118,86 @@ struct mxs_dma_chan {
125118
#define MXS_DMA_CHANNELS 16
126119
#define MXS_DMA_CHANNELS_MASK 0xffff
127120

121+
enum mxs_dma_devtype {
122+
MXS_DMA_APBH,
123+
MXS_DMA_APBX,
124+
};
125+
126+
enum mxs_dma_id {
127+
IMX23_DMA,
128+
IMX28_DMA,
129+
};
130+
128131
struct mxs_dma_engine {
129-
int dev_id;
130-
unsigned int version;
132+
enum mxs_dma_id dev_id;
133+
enum mxs_dma_devtype type;
131134
void __iomem *base;
132135
struct clk *clk;
133136
struct dma_device dma_device;
134137
struct device_dma_parameters dma_parms;
135138
struct mxs_dma_chan mxs_chans[MXS_DMA_CHANNELS];
136139
};
137140

141+
struct mxs_dma_type {
142+
enum mxs_dma_id id;
143+
enum mxs_dma_devtype type;
144+
};
145+
146+
static struct mxs_dma_type mxs_dma_types[] = {
147+
{
148+
.id = IMX23_DMA,
149+
.type = MXS_DMA_APBH,
150+
}, {
151+
.id = IMX23_DMA,
152+
.type = MXS_DMA_APBX,
153+
}, {
154+
.id = IMX28_DMA,
155+
.type = MXS_DMA_APBH,
156+
}, {
157+
.id = IMX28_DMA,
158+
.type = MXS_DMA_APBX,
159+
}
160+
};
161+
162+
static struct platform_device_id mxs_dma_ids[] = {
163+
{
164+
.name = "imx23-dma-apbh",
165+
.driver_data = (kernel_ulong_t) &mxs_dma_types[0],
166+
}, {
167+
.name = "imx23-dma-apbx",
168+
.driver_data = (kernel_ulong_t) &mxs_dma_types[1],
169+
}, {
170+
.name = "imx28-dma-apbh",
171+
.driver_data = (kernel_ulong_t) &mxs_dma_types[2],
172+
}, {
173+
.name = "imx28-dma-apbx",
174+
.driver_data = (kernel_ulong_t) &mxs_dma_types[3],
175+
}, {
176+
/* end of list */
177+
}
178+
};
179+
180+
static struct mxs_dma_chan *to_mxs_dma_chan(struct dma_chan *chan)
181+
{
182+
return container_of(chan, struct mxs_dma_chan, chan);
183+
}
184+
185+
int mxs_dma_is_apbh(struct dma_chan *chan)
186+
{
187+
struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
188+
struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
189+
190+
return dma_is_apbh(mxs_dma);
191+
}
192+
193+
int mxs_dma_is_apbx(struct dma_chan *chan)
194+
{
195+
struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan);
196+
struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
197+
198+
return !dma_is_apbh(mxs_dma);
199+
}
200+
138201
static void mxs_dma_reset_chan(struct mxs_dma_chan *mxs_chan)
139202
{
140203
struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma;
@@ -198,11 +261,6 @@ static void mxs_dma_resume_chan(struct mxs_dma_chan *mxs_chan)
198261
mxs_chan->status = DMA_IN_PROGRESS;
199262
}
200263

201-
static struct mxs_dma_chan *to_mxs_dma_chan(struct dma_chan *chan)
202-
{
203-
return container_of(chan, struct mxs_dma_chan, chan);
204-
}
205-
206264
static dma_cookie_t mxs_dma_tx_submit(struct dma_async_tx_descriptor *tx)
207265
{
208266
return dma_cookie_assign(tx);
@@ -575,12 +633,6 @@ static int __init mxs_dma_init(struct mxs_dma_engine *mxs_dma)
575633
if (ret)
576634
goto err_out;
577635

578-
/* only major version matters */
579-
mxs_dma->version = readl(mxs_dma->base +
580-
((mxs_dma->dev_id == MXS_DMA_APBX) ?
581-
HW_APBX_VERSION : HW_APBH_VERSION)) >>
582-
BP_APBHX_VERSION_MAJOR;
583-
584636
/* enable apbh burst */
585637
if (dma_is_apbh(mxs_dma)) {
586638
writel(BM_APBH_CTRL0_APB_BURST_EN,
@@ -602,6 +654,8 @@ static int __init mxs_dma_probe(struct platform_device *pdev)
602654
{
603655
const struct platform_device_id *id_entry =
604656
platform_get_device_id(pdev);
657+
const struct mxs_dma_type *dma_type =
658+
(struct mxs_dma_type *)id_entry->driver_data;
605659
struct mxs_dma_engine *mxs_dma;
606660
struct resource *iores;
607661
int ret, i;
@@ -610,7 +664,8 @@ static int __init mxs_dma_probe(struct platform_device *pdev)
610664
if (!mxs_dma)
611665
return -ENOMEM;
612666

613-
mxs_dma->dev_id = id_entry->driver_data;
667+
mxs_dma->dev_id = dma_type->id;
668+
mxs_dma->type = dma_type->type;
614669

615670
iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
616671

@@ -693,23 +748,11 @@ static int __init mxs_dma_probe(struct platform_device *pdev)
693748
return ret;
694749
}
695750

696-
static struct platform_device_id mxs_dma_type[] = {
697-
{
698-
.name = "mxs-dma-apbh",
699-
.driver_data = MXS_DMA_APBH,
700-
}, {
701-
.name = "mxs-dma-apbx",
702-
.driver_data = MXS_DMA_APBX,
703-
}, {
704-
/* end of list */
705-
}
706-
};
707-
708751
static struct platform_driver mxs_dma_driver = {
709752
.driver = {
710753
.name = "mxs-dma",
711754
},
712-
.id_table = mxs_dma_type,
755+
.id_table = mxs_dma_ids,
713756
};
714757

715758
static int __init mxs_dma_module_init(void)

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,6 @@ struct mxs_dma_data {
1515
int chan_irq;
1616
};
1717

18-
static inline int mxs_dma_is_apbh(struct dma_chan *chan)
19-
{
20-
return !strcmp(dev_name(chan->device->dev), "mxs-dma-apbh");
21-
}
22-
23-
static inline int mxs_dma_is_apbx(struct dma_chan *chan)
24-
{
25-
return !strcmp(dev_name(chan->device->dev), "mxs-dma-apbx");
26-
}
27-
18+
extern int mxs_dma_is_apbh(struct dma_chan *chan);
19+
extern int mxs_dma_is_apbx(struct dma_chan *chan);
2820
#endif /* __MACH_MXS_DMA_H__ */

0 commit comments

Comments
 (0)