aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/dma/imx-sdma.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-08-20 04:04:31 -0400
committerVinod Koul <vinod.koul@intel.com>2013-08-26 11:17:16 -0400
commit17bba72f8f89a1a164faa0d0b3f1d850eba399ce (patch)
tree482ea74df9cf34b1e9987829a5f497198cfbb844 /drivers/dma/imx-sdma.c
parent023bf55f1c21214cab411cf767d53c8717de6d21 (diff)
dma: imx-sdma: Use struct for driver data
Use a struct type instead of an enum type for distinguishing between different versions. This makes it simpler to handle multiple differences without cluttering the code with comparisons for certain devtypes. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Acked-by: Shawn Guo <shawn.guo@linaro.org> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Diffstat (limited to 'drivers/dma/imx-sdma.c')
-rw-r--r--drivers/dma/imx-sdma.c63
1 files changed, 33 insertions, 30 deletions
diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index 960367d95895..e62be230d2fc 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -305,9 +305,9 @@ struct sdma_firmware_header {
305 u32 ram_code_size; 305 u32 ram_code_size;
306}; 306};
307 307
308enum sdma_devtype { 308struct sdma_driver_data {
309 IMX31_SDMA, /* runs on i.mx31 */ 309 int chnenbl0;
310 IMX35_SDMA, /* runs on i.mx35 and later */ 310 int num_events;
311}; 311};
312 312
313struct sdma_engine { 313struct sdma_engine {
@@ -316,8 +316,6 @@ struct sdma_engine {
316 struct sdma_channel channel[MAX_DMA_CHANNELS]; 316 struct sdma_channel channel[MAX_DMA_CHANNELS];
317 struct sdma_channel_control *channel_control; 317 struct sdma_channel_control *channel_control;
318 void __iomem *regs; 318 void __iomem *regs;
319 enum sdma_devtype devtype;
320 unsigned int num_events;
321 struct sdma_context_data *context; 319 struct sdma_context_data *context;
322 dma_addr_t context_phys; 320 dma_addr_t context_phys;
323 struct dma_device dma_device; 321 struct dma_device dma_device;
@@ -325,15 +323,26 @@ struct sdma_engine {
325 struct clk *clk_ahb; 323 struct clk *clk_ahb;
326 spinlock_t channel_0_lock; 324 spinlock_t channel_0_lock;
327 struct sdma_script_start_addrs *script_addrs; 325 struct sdma_script_start_addrs *script_addrs;
326 const struct sdma_driver_data *drvdata;
327};
328
329struct sdma_driver_data sdma_imx31 = {
330 .chnenbl0 = SDMA_CHNENBL0_IMX31,
331 .num_events = 32,
332};
333
334struct sdma_driver_data sdma_imx35 = {
335 .chnenbl0 = SDMA_CHNENBL0_IMX35,
336 .num_events = 48,
328}; 337};
329 338
330static struct platform_device_id sdma_devtypes[] = { 339static struct platform_device_id sdma_devtypes[] = {
331 { 340 {
332 .name = "imx31-sdma", 341 .name = "imx31-sdma",
333 .driver_data = IMX31_SDMA, 342 .driver_data = (unsigned long)&sdma_imx31,
334 }, { 343 }, {
335 .name = "imx35-sdma", 344 .name = "imx35-sdma",
336 .driver_data = IMX35_SDMA, 345 .driver_data = (unsigned long)&sdma_imx35,
337 }, { 346 }, {
338 /* sentinel */ 347 /* sentinel */
339 } 348 }
@@ -341,8 +350,8 @@ static struct platform_device_id sdma_devtypes[] = {
341MODULE_DEVICE_TABLE(platform, sdma_devtypes); 350MODULE_DEVICE_TABLE(platform, sdma_devtypes);
342 351
343static const struct of_device_id sdma_dt_ids[] = { 352static const struct of_device_id sdma_dt_ids[] = {
344 { .compatible = "fsl,imx31-sdma", .data = &sdma_devtypes[IMX31_SDMA], }, 353 { .compatible = "fsl,imx31-sdma", .data = &sdma_imx31, },
345 { .compatible = "fsl,imx35-sdma", .data = &sdma_devtypes[IMX35_SDMA], }, 354 { .compatible = "fsl,imx35-sdma", .data = &sdma_imx35, },
346 { /* sentinel */ } 355 { /* sentinel */ }
347}; 356};
348MODULE_DEVICE_TABLE(of, sdma_dt_ids); 357MODULE_DEVICE_TABLE(of, sdma_dt_ids);
@@ -354,8 +363,7 @@ MODULE_DEVICE_TABLE(of, sdma_dt_ids);
354 363
355static inline u32 chnenbl_ofs(struct sdma_engine *sdma, unsigned int event) 364static inline u32 chnenbl_ofs(struct sdma_engine *sdma, unsigned int event)
356{ 365{
357 u32 chnenbl0 = (sdma->devtype == IMX31_SDMA ? SDMA_CHNENBL0_IMX31 : 366 u32 chnenbl0 = sdma->drvdata->chnenbl0;
358 SDMA_CHNENBL0_IMX35);
359 return chnenbl0 + event * 4; 367 return chnenbl0 + event * 4;
360} 368}
361 369
@@ -729,7 +737,7 @@ static int sdma_config_channel(struct sdma_channel *sdmac)
729 sdmac->per_addr = 0; 737 sdmac->per_addr = 0;
730 738
731 if (sdmac->event_id0) { 739 if (sdmac->event_id0) {
732 if (sdmac->event_id0 >= sdmac->sdma->num_events) 740 if (sdmac->event_id0 >= sdmac->sdma->drvdata->num_events)
733 return -EINVAL; 741 return -EINVAL;
734 sdma_event_enable(sdmac, sdmac->event_id0); 742 sdma_event_enable(sdmac, sdmac->event_id0);
735 } 743 }
@@ -1208,19 +1216,6 @@ static int __init sdma_init(struct sdma_engine *sdma)
1208 int i, ret; 1216 int i, ret;
1209 dma_addr_t ccb_phys; 1217 dma_addr_t ccb_phys;
1210 1218
1211 switch (sdma->devtype) {
1212 case IMX31_SDMA:
1213 sdma->num_events = 32;
1214 break;
1215 case IMX35_SDMA:
1216 sdma->num_events = 48;
1217 break;
1218 default:
1219 dev_err(sdma->dev, "Unknown sdma type %d. aborting\n",
1220 sdma->devtype);
1221 return -ENODEV;
1222 }
1223
1224 clk_enable(sdma->clk_ipg); 1219 clk_enable(sdma->clk_ipg);
1225 clk_enable(sdma->clk_ahb); 1220 clk_enable(sdma->clk_ahb);
1226 1221
@@ -1247,7 +1242,7 @@ static int __init sdma_init(struct sdma_engine *sdma)
1247 MAX_DMA_CHANNELS * sizeof (struct sdma_channel_control)); 1242 MAX_DMA_CHANNELS * sizeof (struct sdma_channel_control));
1248 1243
1249 /* disable all channels */ 1244 /* disable all channels */
1250 for (i = 0; i < sdma->num_events; i++) 1245 for (i = 0; i < sdma->drvdata->num_events; i++)
1251 writel_relaxed(0, sdma->regs + chnenbl_ofs(sdma, i)); 1246 writel_relaxed(0, sdma->regs + chnenbl_ofs(sdma, i));
1252 1247
1253 /* All channels have priority 0 */ 1248 /* All channels have priority 0 */
@@ -1329,6 +1324,17 @@ static int __init sdma_probe(struct platform_device *pdev)
1329 int i; 1324 int i;
1330 struct sdma_engine *sdma; 1325 struct sdma_engine *sdma;
1331 s32 *saddr_arr; 1326 s32 *saddr_arr;
1327 const struct sdma_driver_data *drvdata = NULL;
1328
1329 if (of_id)
1330 drvdata = of_id->data;
1331 else if (pdev->id_entry)
1332 drvdata = (void *)pdev->id_entry->driver_data;
1333
1334 if (!drvdata) {
1335 dev_err(&pdev->dev, "unable to find driver data\n");
1336 return -EINVAL;
1337 }
1332 1338
1333 sdma = kzalloc(sizeof(*sdma), GFP_KERNEL); 1339 sdma = kzalloc(sizeof(*sdma), GFP_KERNEL);
1334 if (!sdma) 1340 if (!sdma)
@@ -1337,6 +1343,7 @@ static int __init sdma_probe(struct platform_device *pdev)
1337 spin_lock_init(&sdma->channel_0_lock); 1343 spin_lock_init(&sdma->channel_0_lock);
1338 1344
1339 sdma->dev = &pdev->dev; 1345 sdma->dev = &pdev->dev;
1346 sdma->drvdata = drvdata;
1340 1347
1341 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1348 iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1342 irq = platform_get_irq(pdev, 0); 1349 irq = platform_get_irq(pdev, 0);
@@ -1386,10 +1393,6 @@ static int __init sdma_probe(struct platform_device *pdev)
1386 for (i = 0; i < SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1; i++) 1393 for (i = 0; i < SDMA_SCRIPT_ADDRS_ARRAY_SIZE_V1; i++)
1387 saddr_arr[i] = -EINVAL; 1394 saddr_arr[i] = -EINVAL;
1388 1395
1389 if (of_id)
1390 pdev->id_entry = of_id->data;
1391 sdma->devtype = pdev->id_entry->driver_data;
1392
1393 dma_cap_set(DMA_SLAVE, sdma->dma_device.cap_mask); 1396 dma_cap_set(DMA_SLAVE, sdma->dma_device.cap_mask);
1394 dma_cap_set(DMA_CYCLIC, sdma->dma_device.cap_mask); 1397 dma_cap_set(DMA_CYCLIC, sdma->dma_device.cap_mask);
1395 1398