1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/init.h>
15#include <linux/module.h>
16#include <linux/kernel.h>
17#include <linux/compiler.h>
18#include <linux/spinlock.h>
19#include <linux/types.h>
20#include <linux/io.h>
21#include <linux/of.h>
22#include <asm/prom.h>
23#include <asm/fsl_lbc.h>
24
25static spinlock_t fsl_lbc_lock = __SPIN_LOCK_UNLOCKED(fsl_lbc_lock);
26static struct fsl_lbc_regs __iomem *fsl_lbc_regs;
27
28static char __initdata *compat_lbc[] = {
29 "fsl,pq2-localbus",
30 "fsl,pq2pro-localbus",
31 "fsl,pq3-localbus",
32 "fsl,elbc",
33};
34
35static int __init fsl_lbc_init(void)
36{
37 struct device_node *lbus;
38 int i;
39
40 for (i = 0; i < ARRAY_SIZE(compat_lbc); i++) {
41 lbus = of_find_compatible_node(NULL, NULL, compat_lbc[i]);
42 if (lbus)
43 goto found;
44 }
45 return -ENODEV;
46
47found:
48 fsl_lbc_regs = of_iomap(lbus, 0);
49 of_node_put(lbus);
50 if (!fsl_lbc_regs)
51 return -ENOMEM;
52 return 0;
53}
54arch_initcall(fsl_lbc_init);
55
56
57
58
59
60
61
62
63
64
65int fsl_lbc_find(phys_addr_t addr_base)
66{
67 int i;
68
69 if (!fsl_lbc_regs)
70 return -ENODEV;
71
72 for (i = 0; i < ARRAY_SIZE(fsl_lbc_regs->bank); i++) {
73 __be32 br = in_be32(&fsl_lbc_regs->bank[i].br);
74 __be32 or = in_be32(&fsl_lbc_regs->bank[i].or);
75
76 if (br & BR_V && (br & or & BR_BA) == addr_base)
77 return i;
78 }
79
80 return -ENOENT;
81}
82EXPORT_SYMBOL(fsl_lbc_find);
83
84
85
86
87
88
89
90
91
92
93int fsl_upm_find(phys_addr_t addr_base, struct fsl_upm *upm)
94{
95 int bank;
96 __be32 br;
97
98 bank = fsl_lbc_find(addr_base);
99 if (bank < 0)
100 return bank;
101
102 br = in_be32(&fsl_lbc_regs->bank[bank].br);
103
104 switch (br & BR_MSEL) {
105 case BR_MS_UPMA:
106 upm->mxmr = &fsl_lbc_regs->mamr;
107 break;
108 case BR_MS_UPMB:
109 upm->mxmr = &fsl_lbc_regs->mbmr;
110 break;
111 case BR_MS_UPMC:
112 upm->mxmr = &fsl_lbc_regs->mcmr;
113 break;
114 default:
115 return -EINVAL;
116 }
117
118 switch (br & BR_PS) {
119 case BR_PS_8:
120 upm->width = 8;
121 break;
122 case BR_PS_16:
123 upm->width = 16;
124 break;
125 case BR_PS_32:
126 upm->width = 32;
127 break;
128 default:
129 return -EINVAL;
130 }
131
132 return 0;
133}
134EXPORT_SYMBOL(fsl_upm_find);
135
136
137
138
139
140
141
142
143
144
145
146int fsl_upm_run_pattern(struct fsl_upm *upm, void __iomem *io_base, u32 mar)
147{
148 int ret = 0;
149 unsigned long flags;
150
151 spin_lock_irqsave(&fsl_lbc_lock, flags);
152
153 out_be32(&fsl_lbc_regs->mar, mar);
154
155 switch (upm->width) {
156 case 8:
157 out_8(io_base, 0x0);
158 break;
159 case 16:
160 out_be16(io_base, 0x0);
161 break;
162 case 32:
163 out_be32(io_base, 0x0);
164 break;
165 default:
166 ret = -EINVAL;
167 break;
168 }
169
170 spin_unlock_irqrestore(&fsl_lbc_lock, flags);
171
172 return ret;
173}
174EXPORT_SYMBOL(fsl_upm_run_pattern);
175