1 /* Wrapper for DMA channel allocator that starts clocks etc */
3 #include <linux/kernel.h>
4 #include <linux/spinlock.h>
6 #include <hwregs/reg_map.h>
7 #include <hwregs/reg_rdwr.h>
8 #include <hwregs/marb_defs.h>
9 #include <hwregs/clkgen_defs.h>
10 #include <hwregs/strmux_defs.h>
11 #include <linux/errno.h>
12 #include <asm/system.h>
15 static char used_dma_channels
[MAX_DMA_CHANNELS
];
16 static const char *used_dma_channels_users
[MAX_DMA_CHANNELS
];
18 static DEFINE_SPINLOCK(dma_lock
);
20 int crisv32_request_dma(unsigned int dmanr
, const char *device_id
,
21 unsigned options
, unsigned int bandwidth
, enum dma_owner owner
)
24 reg_clkgen_rw_clk_ctrl clk_ctrl
;
25 reg_strmux_rw_cfg strmux_cfg
;
27 if (crisv32_arbiter_allocate_bandwidth(dmanr
,
28 options
& DMA_INT_MEM
? INT_REGION
: EXT_REGION
,
32 spin_lock_irqsave(&dma_lock
, flags
);
34 if (used_dma_channels
[dmanr
]) {
35 spin_unlock_irqrestore(&dma_lock
, flags
);
36 if (options
& DMA_VERBOSE_ON_ERROR
)
37 printk(KERN_ERR
"Failed to request DMA %i for %s, "
38 "already allocated by %s\n",
41 used_dma_channels_users
[dmanr
]);
43 if (options
& DMA_PANIC_ON_ERROR
)
44 panic("request_dma error!");
45 spin_unlock_irqrestore(&dma_lock
, flags
);
48 clk_ctrl
= REG_RD(clkgen
, regi_clkgen
, rw_clk_ctrl
);
49 strmux_cfg
= REG_RD(strmux
, regi_strmux
, rw_cfg
);
54 clk_ctrl
.dma0_1_eth
= 1;
58 clk_ctrl
.dma2_3_strcop
= 1;
62 clk_ctrl
.dma4_5_iop
= 1;
66 clk_ctrl
.sser_ser_dma6_7
= 1;
72 #if MAX_DMA_CHANNELS-1 != 11
76 spin_unlock_irqrestore(&dma_lock
, flags
);
77 if (options
& DMA_VERBOSE_ON_ERROR
)
78 printk(KERN_ERR
"Failed to request DMA %i for %s, "
80 dmanr
, device_id
, MAX_DMA_CHANNELS
-1);
82 if (options
& DMA_PANIC_ON_ERROR
)
83 panic("request_dma error!");
90 strmux_cfg
.dma0
= regk_strmux_eth
;
92 strmux_cfg
.dma1
= regk_strmux_eth
;
94 panic("Invalid DMA channel for eth\n");
98 strmux_cfg
.dma0
= regk_strmux_ser0
;
100 strmux_cfg
.dma1
= regk_strmux_ser0
;
102 panic("Invalid DMA channel for ser0\n");
106 strmux_cfg
.dma2
= regk_strmux_ser3
;
108 strmux_cfg
.dma3
= regk_strmux_ser3
;
110 panic("Invalid DMA channel for ser3\n");
114 strmux_cfg
.dma2
= regk_strmux_strcop
;
116 strmux_cfg
.dma3
= regk_strmux_strcop
;
118 panic("Invalid DMA channel for strp\n");
122 strmux_cfg
.dma4
= regk_strmux_ser1
;
124 strmux_cfg
.dma5
= regk_strmux_ser1
;
126 panic("Invalid DMA channel for ser1\n");
130 strmux_cfg
.dma4
= regk_strmux_iop
;
132 strmux_cfg
.dma5
= regk_strmux_iop
;
134 panic("Invalid DMA channel for iop\n");
138 strmux_cfg
.dma6
= regk_strmux_ser2
;
140 strmux_cfg
.dma7
= regk_strmux_ser2
;
142 panic("Invalid DMA channel for ser2\n");
146 strmux_cfg
.dma6
= regk_strmux_sser
;
148 strmux_cfg
.dma7
= regk_strmux_sser
;
150 panic("Invalid DMA channel for sser\n");
154 strmux_cfg
.dma9
= regk_strmux_ser4
;
156 panic("Invalid DMA channel for ser4\n");
160 strmux_cfg
.dma9
= regk_strmux_jpeg
;
162 panic("Invalid DMA channel for JPEG\n");
166 strmux_cfg
.dma11
= regk_strmux_h264
;
168 panic("Invalid DMA channel for H264\n");
172 used_dma_channels
[dmanr
] = 1;
173 used_dma_channels_users
[dmanr
] = device_id
;
174 REG_WR(clkgen
, regi_clkgen
, rw_clk_ctrl
, clk_ctrl
);
175 REG_WR(strmux
, regi_strmux
, rw_cfg
, strmux_cfg
);
176 spin_unlock_irqrestore(&dma_lock
, flags
);
180 void crisv32_free_dma(unsigned int dmanr
)
182 spin_lock(&dma_lock
);
183 used_dma_channels
[dmanr
] = 0;
184 spin_unlock(&dma_lock
);