hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/arch/sh/drivers/dma/dma-sh.c
....@@ -19,6 +19,18 @@
1919 #include <cpu/dma.h>
2020
2121 /*
22
+ * Some of the SoCs feature two DMAC modules. In such a case, the channels are
23
+ * distributed equally among them.
24
+ */
25
+#ifdef SH_DMAC_BASE1
26
+#define SH_DMAC_NR_MD_CH (CONFIG_NR_ONCHIP_DMA_CHANNELS / 2)
27
+#else
28
+#define SH_DMAC_NR_MD_CH CONFIG_NR_ONCHIP_DMA_CHANNELS
29
+#endif
30
+
31
+#define SH_DMAC_CH_SZ 0x10
32
+
33
+/*
2234 * Define the default configuration for dual address memory-memory transfer.
2335 * The 0x400 value represents auto-request, external->external.
2436 */
....@@ -29,7 +41,7 @@
2941 unsigned long base = SH_DMAC_BASE0;
3042
3143 #ifdef SH_DMAC_BASE1
32
- if (chan >= 6)
44
+ if (chan >= SH_DMAC_NR_MD_CH)
3345 base = SH_DMAC_BASE1;
3446 #endif
3547
....@@ -40,13 +52,13 @@
4052 {
4153 unsigned long base = dma_find_base(chan);
4254
43
- /* Normalize offset calculation */
44
- if (chan >= 9)
45
- chan -= 6;
46
- if (chan >= 4)
47
- base += 0x10;
55
+ chan = (chan % SH_DMAC_NR_MD_CH) * SH_DMAC_CH_SZ;
4856
49
- return base + (chan * 0x10);
57
+ /* DMAOR is placed inside the channel register space. Step over it. */
58
+ if (chan >= DMAOR)
59
+ base += SH_DMAC_CH_SZ;
60
+
61
+ return base + chan;
5062 }
5163
5264 #ifdef CONFIG_SH_DMA_IRQ_MULTI
....@@ -250,12 +262,11 @@
250262 #define NR_DMAOR 1
251263 #endif
252264
253
-/*
254
- * DMAOR bases are broken out amongst channel groups. DMAOR0 manages
255
- * channels 0 - 5, DMAOR1 6 - 11 (optional).
256
- */
257
-#define dmaor_read_reg(n) __raw_readw(dma_find_base((n)*6))
258
-#define dmaor_write_reg(n, data) __raw_writew(data, dma_find_base(n)*6)
265
+#define dmaor_read_reg(n) __raw_readw(dma_find_base((n) * \
266
+ SH_DMAC_NR_MD_CH) + DMAOR)
267
+#define dmaor_write_reg(n, data) __raw_writew(data, \
268
+ dma_find_base((n) * \
269
+ SH_DMAC_NR_MD_CH) + DMAOR)
259270
260271 static inline int dmaor_reset(int no)
261272 {