aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/dma
diff options
context:
space:
mode:
authorArchit Taneja <architt@codeaurora.org>2014-09-29 00:33:07 -0400
committerVinod Koul <vinod.koul@intel.com>2014-11-17 03:20:39 -0500
commitfb93f520e0a5df581f5432bdb901539240391568 (patch)
treed99e067f184598518303b5bf9fec1b54754a5c1c /drivers/dma
parent0b04ddf8638ca5652b1f7ab7794beb363942407d (diff)
dmaengine: qcom_bam_dma: Generalize BAM register offset calculations
The BAM DMA IP comes in different versions. The register offset layout varies among these versions. The layouts depend on which generation/family of SoCs they belong to. The current SoCs(like 8084, 8074) have a layout where the Top level registers come in the beginning of the address range, followed by pipe and event registers. The BAM revision numbers fall above 1.4.0. The older SoCs (like 8064, 8960) have a layout where the pipe registers come first, and the top level come later. These have BAM revision numbers lesser than 1.4.0. It isn't suitable to have macros provide the register offsets with the layouts changed. Future BAM revisions may have different register layouts too. The register addresses are now calculated by referring a table which contains a base offset and multipliers for pipe/evnt/ee registers. We have a common function bam_addr() which computes addresses for all the registers. When computing address of top level/ee registers, we pass 0 to the pipe argument in addr() since they don't have any multiple instances. Some of the unused register definitions are removed. We can add new registers as we need them. Reviewed-by: Kumar Gala <galak@codeaurora.org> Reviewed-by: Andy Gross <agross@codeaurora.org> Signed-off-by: Archit Taneja <architt@codeaurora.org> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Diffstat (limited to 'drivers/dma')
-rw-r--r--drivers/dma/qcom_bam_dma.c176
1 files changed, 113 insertions, 63 deletions
diff --git a/drivers/dma/qcom_bam_dma.c b/drivers/dma/qcom_bam_dma.c
index 9d7b5542397c..d8fb4303bade 100644
--- a/drivers/dma/qcom_bam_dma.c
+++ b/drivers/dma/qcom_bam_dma.c
@@ -79,35 +79,68 @@ struct bam_async_desc {
79 struct bam_desc_hw desc[0]; 79 struct bam_desc_hw desc[0];
80}; 80};
81 81
82#define BAM_CTRL 0x0000 82enum bam_reg {
83#define BAM_REVISION 0x0004 83 BAM_CTRL,
84#define BAM_SW_REVISION 0x0080 84 BAM_REVISION,
85#define BAM_NUM_PIPES 0x003C 85 BAM_NUM_PIPES,
86#define BAM_TIMER 0x0040 86 BAM_DESC_CNT_TRSHLD,
87#define BAM_TIMER_CTRL 0x0044 87 BAM_IRQ_SRCS,
88#define BAM_DESC_CNT_TRSHLD 0x0008 88 BAM_IRQ_SRCS_MSK,
89#define BAM_IRQ_SRCS 0x000C 89 BAM_IRQ_SRCS_UNMASKED,
90#define BAM_IRQ_SRCS_MSK 0x0010 90 BAM_IRQ_STTS,
91#define BAM_IRQ_SRCS_UNMASKED 0x0030 91 BAM_IRQ_CLR,
92#define BAM_IRQ_STTS 0x0014 92 BAM_IRQ_EN,
93#define BAM_IRQ_CLR 0x0018 93 BAM_CNFG_BITS,
94#define BAM_IRQ_EN 0x001C 94 BAM_IRQ_SRCS_EE,
95#define BAM_CNFG_BITS 0x007C 95 BAM_IRQ_SRCS_MSK_EE,
96#define BAM_IRQ_SRCS_EE(ee) (0x0800 + ((ee) * 0x80)) 96 BAM_P_CTRL,
97#define BAM_IRQ_SRCS_MSK_EE(ee) (0x0804 + ((ee) * 0x80)) 97 BAM_P_RST,
98#define BAM_P_CTRL(pipe) (0x1000 + ((pipe) * 0x1000)) 98 BAM_P_HALT,
99#define BAM_P_RST(pipe) (0x1004 + ((pipe) * 0x1000)) 99 BAM_P_IRQ_STTS,
100#define BAM_P_HALT(pipe) (0x1008 + ((pipe) * 0x1000)) 100 BAM_P_IRQ_CLR,
101#define BAM_P_IRQ_STTS(pipe) (0x1010 + ((pipe) * 0x1000)) 101 BAM_P_IRQ_EN,
102#define BAM_P_IRQ_CLR(pipe) (0x1014 + ((pipe) * 0x1000)) 102 BAM_P_EVNT_DEST_ADDR,
103#define BAM_P_IRQ_EN(pipe) (0x1018 + ((pipe) * 0x1000)) 103 BAM_P_EVNT_REG,
104#define BAM_P_EVNT_DEST_ADDR(pipe) (0x182C + ((pipe) * 0x1000)) 104 BAM_P_SW_OFSTS,
105#define BAM_P_EVNT_REG(pipe) (0x1818 + ((pipe) * 0x1000)) 105 BAM_P_DATA_FIFO_ADDR,
106#define BAM_P_SW_OFSTS(pipe) (0x1800 + ((pipe) * 0x1000)) 106 BAM_P_DESC_FIFO_ADDR,
107#define BAM_P_DATA_FIFO_ADDR(pipe) (0x1824 + ((pipe) * 0x1000)) 107 BAM_P_EVNT_GEN_TRSHLD,
108#define BAM_P_DESC_FIFO_ADDR(pipe) (0x181C + ((pipe) * 0x1000)) 108 BAM_P_FIFO_SIZES,
109#define BAM_P_EVNT_TRSHLD(pipe) (0x1828 + ((pipe) * 0x1000)) 109};
110#define BAM_P_FIFO_SIZES(pipe) (0x1820 + ((pipe) * 0x1000)) 110
111struct reg_offset_data {
112 u32 base_offset;
113 unsigned int pipe_mult, evnt_mult, ee_mult;
114};
115
116static const struct reg_offset_data reg_info[] = {
117 [BAM_CTRL] = { 0x0000, 0x00, 0x00, 0x00 },
118 [BAM_REVISION] = { 0x0004, 0x00, 0x00, 0x00 },
119 [BAM_NUM_PIPES] = { 0x003C, 0x00, 0x00, 0x00 },
120 [BAM_DESC_CNT_TRSHLD] = { 0x0008, 0x00, 0x00, 0x00 },
121 [BAM_IRQ_SRCS] = { 0x000C, 0x00, 0x00, 0x00 },
122 [BAM_IRQ_SRCS_MSK] = { 0x0010, 0x00, 0x00, 0x00 },
123 [BAM_IRQ_SRCS_UNMASKED] = { 0x0030, 0x00, 0x00, 0x00 },
124 [BAM_IRQ_STTS] = { 0x0014, 0x00, 0x00, 0x00 },
125 [BAM_IRQ_CLR] = { 0x0018, 0x00, 0x00, 0x00 },
126 [BAM_IRQ_EN] = { 0x001C, 0x00, 0x00, 0x00 },
127 [BAM_CNFG_BITS] = { 0x007C, 0x00, 0x00, 0x00 },
128 [BAM_IRQ_SRCS_EE] = { 0x0800, 0x00, 0x00, 0x80 },
129 [BAM_IRQ_SRCS_MSK_EE] = { 0x0804, 0x00, 0x00, 0x80 },
130 [BAM_P_CTRL] = { 0x1000, 0x1000, 0x00, 0x00 },
131 [BAM_P_RST] = { 0x1004, 0x1000, 0x00, 0x00 },
132 [BAM_P_HALT] = { 0x1008, 0x1000, 0x00, 0x00 },
133 [BAM_P_IRQ_STTS] = { 0x1010, 0x1000, 0x00, 0x00 },
134 [BAM_P_IRQ_CLR] = { 0x1014, 0x1000, 0x00, 0x00 },
135 [BAM_P_IRQ_EN] = { 0x1018, 0x1000, 0x00, 0x00 },
136 [BAM_P_EVNT_DEST_ADDR] = { 0x102C, 0x00, 0x1000, 0x00 },
137 [BAM_P_EVNT_REG] = { 0x1018, 0x00, 0x1000, 0x00 },
138 [BAM_P_SW_OFSTS] = { 0x1000, 0x00, 0x1000, 0x00 },
139 [BAM_P_DATA_FIFO_ADDR] = { 0x1824, 0x00, 0x1000, 0x00 },
140 [BAM_P_DESC_FIFO_ADDR] = { 0x181C, 0x00, 0x1000, 0x00 },
141 [BAM_P_EVNT_GEN_TRSHLD] = { 0x1828, 0x00, 0x1000, 0x00 },
142 [BAM_P_FIFO_SIZES] = { 0x1820, 0x00, 0x1000, 0x00 },
143};
111 144
112/* BAM CTRL */ 145/* BAM CTRL */
113#define BAM_SW_RST BIT(0) 146#define BAM_SW_RST BIT(0)
@@ -305,6 +338,23 @@ struct bam_device {
305}; 338};
306 339
307/** 340/**
341 * bam_addr - returns BAM register address
342 * @bdev: bam device
343 * @pipe: pipe instance (ignored when register doesn't have multiple instances)
344 * @reg: register enum
345 */
346static inline void __iomem *bam_addr(struct bam_device *bdev, u32 pipe,
347 enum bam_reg reg)
348{
349 const struct reg_offset_data r = reg_info[reg];
350
351 return bdev->regs + r.base_offset +
352 r.pipe_mult * pipe +
353 r.evnt_mult * pipe +
354 r.ee_mult * bdev->ee;
355}
356
357/**
308 * bam_reset_channel - Reset individual BAM DMA channel 358 * bam_reset_channel - Reset individual BAM DMA channel
309 * @bchan: bam channel 359 * @bchan: bam channel
310 * 360 *
@@ -317,8 +367,8 @@ static void bam_reset_channel(struct bam_chan *bchan)
317 lockdep_assert_held(&bchan->vc.lock); 367 lockdep_assert_held(&bchan->vc.lock);
318 368
319 /* reset channel */ 369 /* reset channel */
320 writel_relaxed(1, bdev->regs + BAM_P_RST(bchan->id)); 370 writel_relaxed(1, bam_addr(bdev, bchan->id, BAM_P_RST));
321 writel_relaxed(0, bdev->regs + BAM_P_RST(bchan->id)); 371 writel_relaxed(0, bam_addr(bdev, bchan->id, BAM_P_RST));
322 372
323 /* don't allow cpu to reorder BAM register accesses done after this */ 373 /* don't allow cpu to reorder BAM register accesses done after this */
324 wmb(); 374 wmb();
@@ -347,17 +397,18 @@ static void bam_chan_init_hw(struct bam_chan *bchan,
347 * because we allocated 1 more descriptor (8 bytes) than we can use 397 * because we allocated 1 more descriptor (8 bytes) than we can use
348 */ 398 */
349 writel_relaxed(ALIGN(bchan->fifo_phys, sizeof(struct bam_desc_hw)), 399 writel_relaxed(ALIGN(bchan->fifo_phys, sizeof(struct bam_desc_hw)),
350 bdev->regs + BAM_P_DESC_FIFO_ADDR(bchan->id)); 400 bam_addr(bdev, bchan->id, BAM_P_DESC_FIFO_ADDR));
351 writel_relaxed(BAM_DESC_FIFO_SIZE, bdev->regs + 401 writel_relaxed(BAM_DESC_FIFO_SIZE,
352 BAM_P_FIFO_SIZES(bchan->id)); 402 bam_addr(bdev, bchan->id, BAM_P_FIFO_SIZES));
353 403
354 /* enable the per pipe interrupts, enable EOT, ERR, and INT irqs */ 404 /* enable the per pipe interrupts, enable EOT, ERR, and INT irqs */
355 writel_relaxed(P_DEFAULT_IRQS_EN, bdev->regs + BAM_P_IRQ_EN(bchan->id)); 405 writel_relaxed(P_DEFAULT_IRQS_EN,
406 bam_addr(bdev, bchan->id, BAM_P_IRQ_EN));
356 407
357 /* unmask the specific pipe and EE combo */ 408 /* unmask the specific pipe and EE combo */
358 val = readl_relaxed(bdev->regs + BAM_IRQ_SRCS_MSK_EE(bdev->ee)); 409 val = readl_relaxed(bam_addr(bdev, 0, BAM_IRQ_SRCS_MSK_EE));
359 val |= BIT(bchan->id); 410 val |= BIT(bchan->id);
360 writel_relaxed(val, bdev->regs + BAM_IRQ_SRCS_MSK_EE(bdev->ee)); 411 writel_relaxed(val, bam_addr(bdev, 0, BAM_IRQ_SRCS_MSK_EE));
361 412
362 /* don't allow cpu to reorder the channel enable done below */ 413 /* don't allow cpu to reorder the channel enable done below */
363 wmb(); 414 wmb();
@@ -367,7 +418,7 @@ static void bam_chan_init_hw(struct bam_chan *bchan,
367 if (dir == DMA_DEV_TO_MEM) 418 if (dir == DMA_DEV_TO_MEM)
368 val |= P_DIRECTION; 419 val |= P_DIRECTION;
369 420
370 writel_relaxed(val, bdev->regs + BAM_P_CTRL(bchan->id)); 421 writel_relaxed(val, bam_addr(bdev, bchan->id, BAM_P_CTRL));
371 422
372 bchan->initialized = 1; 423 bchan->initialized = 1;
373 424
@@ -432,12 +483,12 @@ static void bam_free_chan(struct dma_chan *chan)
432 bchan->fifo_virt = NULL; 483 bchan->fifo_virt = NULL;
433 484
434 /* mask irq for pipe/channel */ 485 /* mask irq for pipe/channel */
435 val = readl_relaxed(bdev->regs + BAM_IRQ_SRCS_MSK_EE(bdev->ee)); 486 val = readl_relaxed(bam_addr(bdev, 0, BAM_IRQ_SRCS_MSK_EE));
436 val &= ~BIT(bchan->id); 487 val &= ~BIT(bchan->id);
437 writel_relaxed(val, bdev->regs + BAM_IRQ_SRCS_MSK_EE(bdev->ee)); 488 writel_relaxed(val, bam_addr(bdev, 0, BAM_IRQ_SRCS_MSK_EE));
438 489
439 /* disable irq */ 490 /* disable irq */
440 writel_relaxed(0, bdev->regs + BAM_P_IRQ_EN(bchan->id)); 491 writel_relaxed(0, bam_addr(bdev, bchan->id, BAM_P_IRQ_EN));
441} 492}
442 493
443/** 494/**
@@ -583,14 +634,14 @@ static int bam_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
583 switch (cmd) { 634 switch (cmd) {
584 case DMA_PAUSE: 635 case DMA_PAUSE:
585 spin_lock_irqsave(&bchan->vc.lock, flag); 636 spin_lock_irqsave(&bchan->vc.lock, flag);
586 writel_relaxed(1, bdev->regs + BAM_P_HALT(bchan->id)); 637 writel_relaxed(1, bam_addr(bdev, bchan->id, BAM_P_HALT));
587 bchan->paused = 1; 638 bchan->paused = 1;
588 spin_unlock_irqrestore(&bchan->vc.lock, flag); 639 spin_unlock_irqrestore(&bchan->vc.lock, flag);
589 break; 640 break;
590 641
591 case DMA_RESUME: 642 case DMA_RESUME:
592 spin_lock_irqsave(&bchan->vc.lock, flag); 643 spin_lock_irqsave(&bchan->vc.lock, flag);
593 writel_relaxed(0, bdev->regs + BAM_P_HALT(bchan->id)); 644 writel_relaxed(0, bam_addr(bdev, bchan->id, BAM_P_HALT));
594 bchan->paused = 0; 645 bchan->paused = 0;
595 spin_unlock_irqrestore(&bchan->vc.lock, flag); 646 spin_unlock_irqrestore(&bchan->vc.lock, flag);
596 break; 647 break;
@@ -626,7 +677,7 @@ static u32 process_channel_irqs(struct bam_device *bdev)
626 unsigned long flags; 677 unsigned long flags;
627 struct bam_async_desc *async_desc; 678 struct bam_async_desc *async_desc;
628 679
629 srcs = readl_relaxed(bdev->regs + BAM_IRQ_SRCS_EE(bdev->ee)); 680 srcs = readl_relaxed(bam_addr(bdev, 0, BAM_IRQ_SRCS_EE));
630 681
631 /* return early if no pipe/channel interrupts are present */ 682 /* return early if no pipe/channel interrupts are present */
632 if (!(srcs & P_IRQ)) 683 if (!(srcs & P_IRQ))
@@ -639,11 +690,9 @@ static u32 process_channel_irqs(struct bam_device *bdev)
639 continue; 690 continue;
640 691
641 /* clear pipe irq */ 692 /* clear pipe irq */
642 pipe_stts = readl_relaxed(bdev->regs + 693 pipe_stts = readl_relaxed(bam_addr(bdev, i, BAM_P_IRQ_STTS));
643 BAM_P_IRQ_STTS(i));
644 694
645 writel_relaxed(pipe_stts, bdev->regs + 695 writel_relaxed(pipe_stts, bam_addr(bdev, i, BAM_P_IRQ_CLR));
646 BAM_P_IRQ_CLR(i));
647 696
648 spin_lock_irqsave(&bchan->vc.lock, flags); 697 spin_lock_irqsave(&bchan->vc.lock, flags);
649 async_desc = bchan->curr_txd; 698 async_desc = bchan->curr_txd;
@@ -694,12 +743,12 @@ static irqreturn_t bam_dma_irq(int irq, void *data)
694 tasklet_schedule(&bdev->task); 743 tasklet_schedule(&bdev->task);
695 744
696 if (srcs & BAM_IRQ) 745 if (srcs & BAM_IRQ)
697 clr_mask = readl_relaxed(bdev->regs + BAM_IRQ_STTS); 746 clr_mask = readl_relaxed(bam_addr(bdev, 0, BAM_IRQ_STTS));
698 747
699 /* don't allow reorder of the various accesses to the BAM registers */ 748 /* don't allow reorder of the various accesses to the BAM registers */
700 mb(); 749 mb();
701 750
702 writel_relaxed(clr_mask, bdev->regs + BAM_IRQ_CLR); 751 writel_relaxed(clr_mask, bam_addr(bdev, 0, BAM_IRQ_CLR));
703 752
704 return IRQ_HANDLED; 753 return IRQ_HANDLED;
705} 754}
@@ -763,7 +812,7 @@ static void bam_apply_new_config(struct bam_chan *bchan,
763 else 812 else
764 maxburst = bchan->slave.dst_maxburst; 813 maxburst = bchan->slave.dst_maxburst;
765 814
766 writel_relaxed(maxburst, bdev->regs + BAM_DESC_CNT_TRSHLD); 815 writel_relaxed(maxburst, bam_addr(bdev, 0, BAM_DESC_CNT_TRSHLD));
767 816
768 bchan->reconfigure = 0; 817 bchan->reconfigure = 0;
769} 818}
@@ -830,7 +879,7 @@ static void bam_start_dma(struct bam_chan *bchan)
830 /* ensure descriptor writes and dma start not reordered */ 879 /* ensure descriptor writes and dma start not reordered */
831 wmb(); 880 wmb();
832 writel_relaxed(bchan->tail * sizeof(struct bam_desc_hw), 881 writel_relaxed(bchan->tail * sizeof(struct bam_desc_hw),
833 bdev->regs + BAM_P_EVNT_REG(bchan->id)); 882 bam_addr(bdev, bchan->id, BAM_P_EVNT_REG));
834} 883}
835 884
836/** 885/**
@@ -918,43 +967,44 @@ static int bam_init(struct bam_device *bdev)
918 u32 val; 967 u32 val;
919 968
920 /* read revision and configuration information */ 969 /* read revision and configuration information */
921 val = readl_relaxed(bdev->regs + BAM_REVISION) >> NUM_EES_SHIFT; 970 val = readl_relaxed(bam_addr(bdev, 0, BAM_REVISION)) >> NUM_EES_SHIFT;
922 val &= NUM_EES_MASK; 971 val &= NUM_EES_MASK;
923 972
924 /* check that configured EE is within range */ 973 /* check that configured EE is within range */
925 if (bdev->ee >= val) 974 if (bdev->ee >= val)
926 return -EINVAL; 975 return -EINVAL;
927 976
928 val = readl_relaxed(bdev->regs + BAM_NUM_PIPES); 977 val = readl_relaxed(bam_addr(bdev, 0, BAM_NUM_PIPES));
929 bdev->num_channels = val & BAM_NUM_PIPES_MASK; 978 bdev->num_channels = val & BAM_NUM_PIPES_MASK;
930 979
931 /* s/w reset bam */ 980 /* s/w reset bam */
932 /* after reset all pipes are disabled and idle */ 981 /* after reset all pipes are disabled and idle */
933 val = readl_relaxed(bdev->regs + BAM_CTRL); 982 val = readl_relaxed(bam_addr(bdev, 0, BAM_CTRL));
934 val |= BAM_SW_RST; 983 val |= BAM_SW_RST;
935 writel_relaxed(val, bdev->regs + BAM_CTRL); 984 writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
936 val &= ~BAM_SW_RST; 985 val &= ~BAM_SW_RST;
937 writel_relaxed(val, bdev->regs + BAM_CTRL); 986 writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
938 987
939 /* make sure previous stores are visible before enabling BAM */ 988 /* make sure previous stores are visible before enabling BAM */
940 wmb(); 989 wmb();
941 990
942 /* enable bam */ 991 /* enable bam */
943 val |= BAM_EN; 992 val |= BAM_EN;
944 writel_relaxed(val, bdev->regs + BAM_CTRL); 993 writel_relaxed(val, bam_addr(bdev, 0, BAM_CTRL));
945 994
946 /* set descriptor threshhold, start with 4 bytes */ 995 /* set descriptor threshhold, start with 4 bytes */
947 writel_relaxed(DEFAULT_CNT_THRSHLD, bdev->regs + BAM_DESC_CNT_TRSHLD); 996 writel_relaxed(DEFAULT_CNT_THRSHLD,
997 bam_addr(bdev, 0, BAM_DESC_CNT_TRSHLD));
948 998
949 /* Enable default set of h/w workarounds, ie all except BAM_FULL_PIPE */ 999 /* Enable default set of h/w workarounds, ie all except BAM_FULL_PIPE */
950 writel_relaxed(BAM_CNFG_BITS_DEFAULT, bdev->regs + BAM_CNFG_BITS); 1000 writel_relaxed(BAM_CNFG_BITS_DEFAULT, bam_addr(bdev, 0, BAM_CNFG_BITS));
951 1001
952 /* enable irqs for errors */ 1002 /* enable irqs for errors */
953 writel_relaxed(BAM_ERROR_EN | BAM_HRESP_ERR_EN, 1003 writel_relaxed(BAM_ERROR_EN | BAM_HRESP_ERR_EN,
954 bdev->regs + BAM_IRQ_EN); 1004 bam_addr(bdev, 0, BAM_IRQ_EN));
955 1005
956 /* unmask global bam interrupt */ 1006 /* unmask global bam interrupt */
957 writel_relaxed(BAM_IRQ_MSK, bdev->regs + BAM_IRQ_SRCS_MSK_EE(bdev->ee)); 1007 writel_relaxed(BAM_IRQ_MSK, bam_addr(bdev, 0, BAM_IRQ_SRCS_MSK_EE));
958 1008
959 return 0; 1009 return 0;
960} 1010}
@@ -1084,7 +1134,7 @@ static int bam_dma_remove(struct platform_device *pdev)
1084 dma_async_device_unregister(&bdev->common); 1134 dma_async_device_unregister(&bdev->common);
1085 1135
1086 /* mask all interrupts for this execution environment */ 1136 /* mask all interrupts for this execution environment */
1087 writel_relaxed(0, bdev->regs + BAM_IRQ_SRCS_MSK_EE(bdev->ee)); 1137 writel_relaxed(0, bam_addr(bdev, 0, BAM_IRQ_SRCS_MSK_EE));
1088 1138
1089 devm_free_irq(bdev->dev, bdev->irq, bdev); 1139 devm_free_irq(bdev->dev, bdev->irq, bdev);
1090 1140