2 * Freescale LBC and UPM routines.
4 * Copyright (c) 2007-2008 MontaVista Software, Inc.
6 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
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>
23 #include <asm/fsl_lbc.h>
25 static spinlock_t fsl_lbc_lock
= __SPIN_LOCK_UNLOCKED(fsl_lbc_lock
);
26 static struct fsl_lbc_regs __iomem
*fsl_lbc_regs
;
28 static char __initdata
*compat_lbc
[] = {
30 "fsl,pq2pro-localbus",
35 static int __init
fsl_lbc_init(void)
37 struct device_node
*lbus
;
40 for (i
= 0; i
< ARRAY_SIZE(compat_lbc
); i
++) {
41 lbus
= of_find_compatible_node(NULL
, NULL
, compat_lbc
[i
]);
48 fsl_lbc_regs
= of_iomap(lbus
, 0);
54 arch_initcall(fsl_lbc_init
);
57 * fsl_lbc_find - find Localbus bank
58 * @addr_base: base address of the memory bank
60 * This function walks LBC banks comparing "Base address" field of the BR
61 * registers with the supplied addr_base argument. When bases match this
62 * function returns bank number (starting with 0), otherwise it returns
63 * appropriate errno value.
65 int fsl_lbc_find(phys_addr_t addr_base
)
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);
76 if (br
& BR_V
&& (br
& or & BR_BA
) == addr_base
)
82 EXPORT_SYMBOL(fsl_lbc_find
);
85 * fsl_upm_find - find pre-programmed UPM via base address
86 * @addr_base: base address of the memory bank controlled by the UPM
87 * @upm: pointer to the allocated fsl_upm structure
89 * This function fills fsl_upm structure so you can use it with the rest of
90 * UPM API. On success this function returns 0, otherwise it returns
91 * appropriate errno value.
93 int fsl_upm_find(phys_addr_t addr_base
, struct fsl_upm
*upm
)
98 bank
= fsl_lbc_find(addr_base
);
102 br
= in_be32(&fsl_lbc_regs
->bank
[bank
].br
);
104 switch (br
& BR_MSEL
) {
106 upm
->mxmr
= &fsl_lbc_regs
->mamr
;
109 upm
->mxmr
= &fsl_lbc_regs
->mbmr
;
112 upm
->mxmr
= &fsl_lbc_regs
->mcmr
;
118 switch (br
& BR_PS
) {
134 EXPORT_SYMBOL(fsl_upm_find
);
137 * fsl_upm_run_pattern - actually run an UPM pattern
138 * @upm: pointer to the fsl_upm structure obtained via fsl_upm_find
139 * @io_base: remapped pointer to where memory access should happen
140 * @mar: MAR register content during pattern execution
142 * This function triggers dummy write to the memory specified by the io_base,
143 * thus UPM pattern actually executed. Note that mar usage depends on the
144 * pre-programmed AMX bits in the UPM RAM.
146 int fsl_upm_run_pattern(struct fsl_upm
*upm
, void __iomem
*io_base
, u32 mar
)
151 spin_lock_irqsave(&fsl_lbc_lock
, flags
);
153 out_be32(&fsl_lbc_regs
->mar
, mar
<< (32 - upm
->width
));
155 switch (upm
->width
) {
160 out_be16(io_base
, 0x0);
163 out_be32(io_base
, 0x0);
170 spin_unlock_irqrestore(&fsl_lbc_lock
, flags
);
174 EXPORT_SYMBOL(fsl_upm_run_pattern
);