aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/dma/ste_dma40.c
diff options
context:
space:
mode:
authorRabin Vincent <rabin.vincent@stericsson.com>2011-01-25 05:18:07 -0500
committerDan Williams <dan.j.williams@intel.com>2011-01-31 01:27:16 -0500
commit8ca84687b91322b9eafeaf4da43a21684cd0316e (patch)
treebae0ececa3a7975c4b2a0bd5a7611abdd86131ad /drivers/dma/ste_dma40.c
parent7d83a854a1a44a8f6a699503441403a36c42f66c (diff)
dma40: use helper for channel registers base
The register offset computation for accessing channel registers is copy/pasted in several places. Create a helper function to do it. Acked-by: Per Forlin <per.forlin@stericsson.com> Acked-by: Jonas Aaberg <jonas.aberg@stericsson.com> Signed-off-by: Rabin Vincent <rabin.vincent@stericsson.com> Signed-off-by: Linus Walleij <linus.walleij@stericsson.com> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Diffstat (limited to 'drivers/dma/ste_dma40.c')
-rw-r--r--drivers/dma/ste_dma40.c74
1 files changed, 30 insertions, 44 deletions
diff --git a/drivers/dma/ste_dma40.c b/drivers/dma/ste_dma40.c
index ed2a3ebcd86c..3d4cea3cff35 100644
--- a/drivers/dma/ste_dma40.c
+++ b/drivers/dma/ste_dma40.c
@@ -306,6 +306,12 @@ static struct device *chan2dev(struct d40_chan *d40c)
306 return &d40c->chan.dev->device; 306 return &d40c->chan.dev->device;
307} 307}
308 308
309static void __iomem *chan_base(struct d40_chan *chan)
310{
311 return chan->base->virtbase + D40_DREG_PCBASE +
312 chan->phy_chan->num * D40_DREG_PCDELTA;
313}
314
309static int d40_pool_lli_alloc(struct d40_desc *d40d, 315static int d40_pool_lli_alloc(struct d40_desc *d40d,
310 int lli_len, bool is_log) 316 int lli_len, bool is_log)
311{ 317{
@@ -695,8 +701,7 @@ static void d40_term_all(struct d40_chan *d40c)
695static void __d40_config_set_event(struct d40_chan *d40c, bool enable, 701static void __d40_config_set_event(struct d40_chan *d40c, bool enable,
696 u32 event, int reg) 702 u32 event, int reg)
697{ 703{
698 void __iomem *addr = d40c->base->virtbase + D40_DREG_PCBASE 704 void __iomem *addr = chan_base(d40c) + reg;
699 + d40c->phy_chan->num * D40_DREG_PCDELTA + reg;
700 int tries; 705 int tries;
701 706
702 if (!enable) { 707 if (!enable) {
@@ -755,15 +760,12 @@ static void d40_config_set_event(struct d40_chan *d40c, bool do_enable)
755 760
756static u32 d40_chan_has_events(struct d40_chan *d40c) 761static u32 d40_chan_has_events(struct d40_chan *d40c)
757{ 762{
763 void __iomem *chanbase = chan_base(d40c);
758 u32 val; 764 u32 val;
759 765
760 val = readl(d40c->base->virtbase + D40_DREG_PCBASE + 766 val = readl(chanbase + D40_CHAN_REG_SSLNK);
761 d40c->phy_chan->num * D40_DREG_PCDELTA + 767 val |= readl(chanbase + D40_CHAN_REG_SDLNK);
762 D40_CHAN_REG_SSLNK);
763 768
764 val |= readl(d40c->base->virtbase + D40_DREG_PCBASE +
765 d40c->phy_chan->num * D40_DREG_PCDELTA +
766 D40_CHAN_REG_SDLNK);
767 return val; 769 return val;
768} 770}
769 771
@@ -810,29 +812,17 @@ static void d40_config_write(struct d40_chan *d40c)
810 writel(var, d40c->base->virtbase + D40_DREG_PRMOE + addr_base); 812 writel(var, d40c->base->virtbase + D40_DREG_PRMOE + addr_base);
811 813
812 if (d40c->log_num != D40_PHY_CHAN) { 814 if (d40c->log_num != D40_PHY_CHAN) {
815 int lidx = (d40c->phy_chan->num << D40_SREG_ELEM_LOG_LIDX_POS)
816 & D40_SREG_ELEM_LOG_LIDX_MASK;
817 void __iomem *chanbase = chan_base(d40c);
818
813 /* Set default config for CFG reg */ 819 /* Set default config for CFG reg */
814 writel(d40c->src_def_cfg, 820 writel(d40c->src_def_cfg, chanbase + D40_CHAN_REG_SSCFG);
815 d40c->base->virtbase + D40_DREG_PCBASE + 821 writel(d40c->dst_def_cfg, chanbase + D40_CHAN_REG_SDCFG);
816 d40c->phy_chan->num * D40_DREG_PCDELTA +
817 D40_CHAN_REG_SSCFG);
818 writel(d40c->dst_def_cfg,
819 d40c->base->virtbase + D40_DREG_PCBASE +
820 d40c->phy_chan->num * D40_DREG_PCDELTA +
821 D40_CHAN_REG_SDCFG);
822 822
823 /* Set LIDX for lcla */ 823 /* Set LIDX for lcla */
824 writel((d40c->phy_chan->num << D40_SREG_ELEM_LOG_LIDX_POS) & 824 writel(lidx, chanbase + D40_CHAN_REG_SSELT);
825 D40_SREG_ELEM_LOG_LIDX_MASK, 825 writel(lidx, chanbase + D40_CHAN_REG_SDELT);
826 d40c->base->virtbase + D40_DREG_PCBASE +
827 d40c->phy_chan->num * D40_DREG_PCDELTA +
828 D40_CHAN_REG_SDELT);
829
830 writel((d40c->phy_chan->num << D40_SREG_ELEM_LOG_LIDX_POS) &
831 D40_SREG_ELEM_LOG_LIDX_MASK,
832 d40c->base->virtbase + D40_DREG_PCBASE +
833 d40c->phy_chan->num * D40_DREG_PCDELTA +
834 D40_CHAN_REG_SSELT);
835
836 } 826 }
837} 827}
838 828
@@ -843,12 +833,12 @@ static u32 d40_residue(struct d40_chan *d40c)
843 if (d40c->log_num != D40_PHY_CHAN) 833 if (d40c->log_num != D40_PHY_CHAN)
844 num_elt = (readl(&d40c->lcpa->lcsp2) & D40_MEM_LCSP2_ECNT_MASK) 834 num_elt = (readl(&d40c->lcpa->lcsp2) & D40_MEM_LCSP2_ECNT_MASK)
845 >> D40_MEM_LCSP2_ECNT_POS; 835 >> D40_MEM_LCSP2_ECNT_POS;
846 else 836 else {
847 num_elt = (readl(d40c->base->virtbase + D40_DREG_PCBASE + 837 u32 val = readl(chan_base(d40c) + D40_CHAN_REG_SDELT);
848 d40c->phy_chan->num * D40_DREG_PCDELTA + 838 num_elt = (val & D40_SREG_ELEM_PHY_ECNT_MASK)
849 D40_CHAN_REG_SDELT) & 839 >> D40_SREG_ELEM_PHY_ECNT_POS;
850 D40_SREG_ELEM_PHY_ECNT_MASK) >> 840 }
851 D40_SREG_ELEM_PHY_ECNT_POS; 841
852 return num_elt * (1 << d40c->dma_cfg.dst_info.data_width); 842 return num_elt * (1 << d40c->dma_cfg.dst_info.data_width);
853} 843}
854 844
@@ -859,10 +849,9 @@ static bool d40_tx_is_linked(struct d40_chan *d40c)
859 if (d40c->log_num != D40_PHY_CHAN) 849 if (d40c->log_num != D40_PHY_CHAN)
860 is_link = readl(&d40c->lcpa->lcsp3) & D40_MEM_LCSP3_DLOS_MASK; 850 is_link = readl(&d40c->lcpa->lcsp3) & D40_MEM_LCSP3_DLOS_MASK;
861 else 851 else
862 is_link = readl(d40c->base->virtbase + D40_DREG_PCBASE + 852 is_link = readl(chan_base(d40c) + D40_CHAN_REG_SDLNK)
863 d40c->phy_chan->num * D40_DREG_PCDELTA + 853 & D40_SREG_LNK_PHYS_LNK_MASK;
864 D40_CHAN_REG_SDLNK) & 854
865 D40_SREG_LNK_PHYS_LNK_MASK;
866 return is_link; 855 return is_link;
867} 856}
868 857
@@ -1550,6 +1539,7 @@ static int d40_free_dma(struct d40_chan *d40c)
1550 1539
1551static bool d40_is_paused(struct d40_chan *d40c) 1540static bool d40_is_paused(struct d40_chan *d40c)
1552{ 1541{
1542 void __iomem *chanbase = chan_base(d40c);
1553 bool is_paused = false; 1543 bool is_paused = false;
1554 unsigned long flags; 1544 unsigned long flags;
1555 void __iomem *active_reg; 1545 void __iomem *active_reg;
@@ -1576,14 +1566,10 @@ static bool d40_is_paused(struct d40_chan *d40c)
1576 if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_PERIPH || 1566 if (d40c->dma_cfg.dir == STEDMA40_MEM_TO_PERIPH ||
1577 d40c->dma_cfg.dir == STEDMA40_MEM_TO_MEM) { 1567 d40c->dma_cfg.dir == STEDMA40_MEM_TO_MEM) {
1578 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dst_dev_type); 1568 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.dst_dev_type);
1579 status = readl(d40c->base->virtbase + D40_DREG_PCBASE + 1569 status = readl(chanbase + D40_CHAN_REG_SDLNK);
1580 d40c->phy_chan->num * D40_DREG_PCDELTA +
1581 D40_CHAN_REG_SDLNK);
1582 } else if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) { 1570 } else if (d40c->dma_cfg.dir == STEDMA40_PERIPH_TO_MEM) {
1583 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.src_dev_type); 1571 event = D40_TYPE_TO_EVENT(d40c->dma_cfg.src_dev_type);
1584 status = readl(d40c->base->virtbase + D40_DREG_PCBASE + 1572 status = readl(chanbase + D40_CHAN_REG_SSLNK);
1585 d40c->phy_chan->num * D40_DREG_PCDELTA +
1586 D40_CHAN_REG_SSLNK);
1587 } else { 1573 } else {
1588 dev_err(&d40c->chan.dev->device, 1574 dev_err(&d40c->chan.dev->device,
1589 "[%s] Unknown direction\n", __func__); 1575 "[%s] Unknown direction\n", __func__);