aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2014-03-05 08:48:12 -0500
committerVinod Koul <vinod.koul@intel.com>2014-03-26 02:14:27 -0400
commit000871ce0336572f5b126a4d7f1ec13fc9adfda2 (patch)
tree6456ebc642e2f533b52da8be8061b4474cef90ad
parent2acec15034cc6a64b9fcac376e56b9071463812b (diff)
dma: dw: allocate memory in two stages in probe
This makes the probe() function a little bit clearer. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
-rw-r--r--drivers/dma/dw/core.c17
-rw-r--r--drivers/dma/dw/regs.h4
2 files changed, 12 insertions, 9 deletions
diff --git a/drivers/dma/dw/core.c b/drivers/dma/dw/core.c
index 1b4509712847..cfdbb92aae1d 100644
--- a/drivers/dma/dw/core.c
+++ b/drivers/dma/dw/core.c
@@ -1479,7 +1479,6 @@ static void dw_dma_off(struct dw_dma *dw)
1479int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata) 1479int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
1480{ 1480{
1481 struct dw_dma *dw; 1481 struct dw_dma *dw;
1482 size_t size;
1483 bool autocfg; 1482 bool autocfg;
1484 unsigned int dw_params; 1483 unsigned int dw_params;
1485 unsigned int nr_channels; 1484 unsigned int nr_channels;
@@ -1487,6 +1486,13 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
1487 int err; 1486 int err;
1488 int i; 1487 int i;
1489 1488
1489 dw = devm_kzalloc(chip->dev, sizeof(*dw), GFP_KERNEL);
1490 if (!dw)
1491 return -ENOMEM;
1492
1493 dw->regs = chip->regs;
1494 chip->dw = dw;
1495
1490 dw_params = dma_read_byaddr(chip->regs, DW_PARAMS); 1496 dw_params = dma_read_byaddr(chip->regs, DW_PARAMS);
1491 autocfg = dw_params >> DW_PARAMS_EN & 0x1; 1497 autocfg = dw_params >> DW_PARAMS_EN & 0x1;
1492 1498
@@ -1509,9 +1515,9 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
1509 else 1515 else
1510 nr_channels = pdata->nr_channels; 1516 nr_channels = pdata->nr_channels;
1511 1517
1512 size = sizeof(struct dw_dma) + nr_channels * sizeof(struct dw_dma_chan); 1518 dw->chan = devm_kcalloc(chip->dev, nr_channels, sizeof(*dw->chan),
1513 dw = devm_kzalloc(chip->dev, size, GFP_KERNEL); 1519 GFP_KERNEL);
1514 if (!dw) 1520 if (!dw->chan)
1515 return -ENOMEM; 1521 return -ENOMEM;
1516 1522
1517 dw->clk = devm_clk_get(chip->dev, "hclk"); 1523 dw->clk = devm_clk_get(chip->dev, "hclk");
@@ -1519,9 +1525,6 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
1519 return PTR_ERR(dw->clk); 1525 return PTR_ERR(dw->clk);
1520 clk_prepare_enable(dw->clk); 1526 clk_prepare_enable(dw->clk);
1521 1527
1522 dw->regs = chip->regs;
1523 chip->dw = dw;
1524
1525 /* Get hardware configuration parameters */ 1528 /* Get hardware configuration parameters */
1526 if (autocfg) { 1529 if (autocfg) {
1527 max_blk_size = dma_readl(dw, MAX_BLK_SIZE); 1530 max_blk_size = dma_readl(dw, MAX_BLK_SIZE);
diff --git a/drivers/dma/dw/regs.h b/drivers/dma/dw/regs.h
index deb4274f80f4..bb98d3e91e8b 100644
--- a/drivers/dma/dw/regs.h
+++ b/drivers/dma/dw/regs.h
@@ -252,13 +252,13 @@ struct dw_dma {
252 struct tasklet_struct tasklet; 252 struct tasklet_struct tasklet;
253 struct clk *clk; 253 struct clk *clk;
254 254
255 /* channels */
256 struct dw_dma_chan *chan;
255 u8 all_chan_mask; 257 u8 all_chan_mask;
256 258
257 /* hardware configuration */ 259 /* hardware configuration */
258 unsigned char nr_masters; 260 unsigned char nr_masters;
259 unsigned char data_width[4]; 261 unsigned char data_width[4];
260
261 struct dw_dma_chan chan[0];
262}; 262};
263 263
264static inline struct dw_dma_regs __iomem *__dw_regs(struct dw_dma *dw) 264static inline struct dw_dma_regs __iomem *__dw_regs(struct dw_dma *dw)