1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/amba/pl08x.h>
15#include <linux/amba/bus.h>
16#include <linux/bug.h>
17#include <linux/err.h>
18#include <linux/io.h>
19#include <linux/spinlock_types.h>
20#include <mach/spear.h>
21#include <mach/misc_regs.h>
22
23static spinlock_t lock = __SPIN_LOCK_UNLOCKED(x);
24
25struct {
26 unsigned char busy;
27 unsigned char val;
28} signals[16] = {{0, 0}, };
29
30int pl080_get_signal(const struct pl08x_channel_data *cd)
31{
32 unsigned int signal = cd->min_signal, val;
33 unsigned long flags;
34
35 spin_lock_irqsave(&lock, flags);
36
37
38 if (signals[signal].busy &&
39 (signals[signal].val != cd->muxval)) {
40 spin_unlock_irqrestore(&lock, flags);
41 return -EBUSY;
42 }
43
44
45 if (!signals[signal].busy) {
46 val = readl(DMA_CHN_CFG);
47
48
49
50
51
52
53 val &= ~(0x3 << (signal * 2));
54 val |= cd->muxval << (signal * 2);
55 writel(val, DMA_CHN_CFG);
56 }
57
58 signals[signal].busy++;
59 signals[signal].val = cd->muxval;
60 spin_unlock_irqrestore(&lock, flags);
61
62 return signal;
63}
64
65void pl080_put_signal(const struct pl08x_channel_data *cd, int signal)
66{
67 unsigned long flags;
68
69 spin_lock_irqsave(&lock, flags);
70
71
72 if (!signals[signal].busy)
73 BUG();
74
75 signals[signal].busy--;
76
77 spin_unlock_irqrestore(&lock, flags);
78}
79