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/kernel.h>
16 #include <asm/fsl_lbc.h>
18 spinlock_t fsl_lbc_lock = __SPIN_LOCK_UNLOCKED(fsl_lbc_lock);
20 struct fsl_lbc_regs __iomem *fsl_lbc_regs;
21 EXPORT_SYMBOL(fsl_lbc_regs);
23 static char __initdata *compat_lbc[] = {
25 "fsl,pq2pro-localbus",
30 static int __init fsl_lbc_init(void)
32 struct device_node *lbus;
35 for (i = 0; i < ARRAY_SIZE(compat_lbc); i++) {
36 lbus = of_find_compatible_node(NULL, NULL, compat_lbc[i]);
43 fsl_lbc_regs = of_iomap(lbus, 0);
49 arch_initcall(fsl_lbc_init);
52 * fsl_lbc_find - find Localbus bank
53 * @addr_base: base address of the memory bank
55 * This function walks LBC banks comparing "Base address" field of the BR
56 * registers with the supplied addr_base argument. When bases match this
57 * function returns bank number (starting with 0), otherwise it returns
58 * appropriate errno value.
60 int fsl_lbc_find(phys_addr_t addr_base)
67 for (i = 0; i < ARRAY_SIZE(fsl_lbc_regs->bank); i++) {
68 __be32 br = in_be32(&fsl_lbc_regs->bank[i].br);
69 __be32 or = in_be32(&fsl_lbc_regs->bank[i].or);
71 if (br & BR_V && (br & or & BR_BA) == addr_base)
77 EXPORT_SYMBOL(fsl_lbc_find);
80 * fsl_upm_find - find pre-programmed UPM via base address
81 * @addr_base: base address of the memory bank controlled by the UPM
82 * @upm: pointer to the allocated fsl_upm structure
84 * This function fills fsl_upm structure so you can use it with the rest of
85 * UPM API. On success this function returns 0, otherwise it returns
86 * appropriate errno value.
88 int fsl_upm_find(phys_addr_t addr_base, struct fsl_upm *upm)
93 bank = fsl_lbc_find(addr_base);
97 br = in_be32(&fsl_lbc_regs->bank[bank].br);
99 switch (br & BR_MSEL) {
101 upm->mxmr = &fsl_lbc_regs->mamr;
104 upm->mxmr = &fsl_lbc_regs->mbmr;
107 upm->mxmr = &fsl_lbc_regs->mcmr;
113 switch (br & BR_PS) {
129 EXPORT_SYMBOL(fsl_upm_find);