Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[POWERPC] fsl_lbc: implement few UPM routines

Freescale UPM can be used to adjust localbus timings or to generate
orbitrary, pre-programmed "patterns" on the external Localbus signals.
This patch implements few routines so drivers could work with UPMs in
safe and generic manner.

So far there is just one user of these routines: Freescale UPM NAND
driver.

Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>

authored by

Anton Vorontsov and committed by
Kumar Gala
acaa7aa3 d4a32fe4

+223
+5
arch/powerpc/Kconfig
··· 520 520 config 4xx_SOC 521 521 bool 522 522 523 + config FSL_LBC 524 + bool 525 + help 526 + Freescale Localbus support 527 + 523 528 # Yes MCA RS/6000s exist but Linux-PPC does not currently support any 524 529 config MCA 525 530 bool
+1
arch/powerpc/sysdev/Makefile
··· 12 12 obj-$(CONFIG_MMIO_NVRAM) += mmio_nvram.o 13 13 obj-$(CONFIG_FSL_SOC) += fsl_soc.o 14 14 obj-$(CONFIG_FSL_PCI) += fsl_pci.o 15 + obj-$(CONFIG_FSL_LBC) += fsl_lbc.o 15 16 obj-$(CONFIG_RAPIDIO) += fsl_rio.o 16 17 obj-$(CONFIG_TSI108_BRIDGE) += tsi108_pci.o tsi108_dev.o 17 18 obj-$(CONFIG_QUICC_ENGINE) += qe_lib/
+129
arch/powerpc/sysdev/fsl_lbc.c
··· 1 + /* 2 + * Freescale LBC and UPM routines. 3 + * 4 + * Copyright (c) 2007-2008 MontaVista Software, Inc. 5 + * 6 + * Author: Anton Vorontsov <avorontsov@ru.mvista.com> 7 + * 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. 12 + */ 13 + 14 + #include <linux/kernel.h> 15 + #include <linux/of.h> 16 + #include <asm/fsl_lbc.h> 17 + 18 + spinlock_t fsl_lbc_lock = __SPIN_LOCK_UNLOCKED(fsl_lbc_lock); 19 + 20 + struct fsl_lbc_regs __iomem *fsl_lbc_regs; 21 + EXPORT_SYMBOL(fsl_lbc_regs); 22 + 23 + static char __initdata *compat_lbc[] = { 24 + "fsl,pq2-localbus", 25 + "fsl,pq2pro-localbus", 26 + "fsl,pq3-localbus", 27 + "fsl,elbc", 28 + }; 29 + 30 + static int __init fsl_lbc_init(void) 31 + { 32 + struct device_node *lbus; 33 + int i; 34 + 35 + for (i = 0; i < ARRAY_SIZE(compat_lbc); i++) { 36 + lbus = of_find_compatible_node(NULL, NULL, compat_lbc[i]); 37 + if (lbus) 38 + goto found; 39 + } 40 + return -ENODEV; 41 + 42 + found: 43 + fsl_lbc_regs = of_iomap(lbus, 0); 44 + of_node_put(lbus); 45 + if (!fsl_lbc_regs) 46 + return -ENOMEM; 47 + return 0; 48 + } 49 + arch_initcall(fsl_lbc_init); 50 + 51 + /** 52 + * fsl_lbc_find - find Localbus bank 53 + * @addr_base: base address of the memory bank 54 + * 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. 59 + */ 60 + int fsl_lbc_find(phys_addr_t addr_base) 61 + { 62 + int i; 63 + 64 + if (!fsl_lbc_regs) 65 + return -ENODEV; 66 + 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); 70 + 71 + if (br & BR_V && (br & or & BR_BA) == addr_base) 72 + return i; 73 + } 74 + 75 + return -ENOENT; 76 + } 77 + EXPORT_SYMBOL(fsl_lbc_find); 78 + 79 + /** 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 83 + * 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. 87 + */ 88 + int fsl_upm_find(phys_addr_t addr_base, struct fsl_upm *upm) 89 + { 90 + int bank; 91 + __be32 br; 92 + 93 + bank = fsl_lbc_find(addr_base); 94 + if (bank < 0) 95 + return bank; 96 + 97 + br = in_be32(&fsl_lbc_regs->bank[bank].br); 98 + 99 + switch (br & BR_MSEL) { 100 + case BR_MS_UPMA: 101 + upm->mxmr = &fsl_lbc_regs->mamr; 102 + break; 103 + case BR_MS_UPMB: 104 + upm->mxmr = &fsl_lbc_regs->mbmr; 105 + break; 106 + case BR_MS_UPMC: 107 + upm->mxmr = &fsl_lbc_regs->mcmr; 108 + break; 109 + default: 110 + return -EINVAL; 111 + } 112 + 113 + switch (br & BR_PS) { 114 + case BR_PS_8: 115 + upm->width = 8; 116 + break; 117 + case BR_PS_16: 118 + upm->width = 16; 119 + break; 120 + case BR_PS_32: 121 + upm->width = 32; 122 + break; 123 + default: 124 + return -EINVAL; 125 + } 126 + 127 + return 0; 128 + } 129 + EXPORT_SYMBOL(fsl_upm_find);
+88
include/asm-powerpc/fsl_lbc.h
··· 24 24 #define __ASM_FSL_LBC_H 25 25 26 26 #include <linux/types.h> 27 + #include <linux/spinlock.h> 28 + #include <asm/io.h> 27 29 28 30 struct fsl_lbc_bank { 29 31 __be32 br; /**< Base Register */ ··· 100 98 __be32 mar; /**< UPM Address Register */ 101 99 u8 res1[0x4]; 102 100 __be32 mamr; /**< UPMA Mode Register */ 101 + #define MxMR_OP_NO (0 << 28) /**< normal operation */ 102 + #define MxMR_OP_WA (1 << 28) /**< write array */ 103 + #define MxMR_OP_RA (2 << 28) /**< read array */ 104 + #define MxMR_OP_RP (3 << 28) /**< run pattern */ 105 + #define MxMR_MAD 0x3f /**< machine address */ 103 106 __be32 mbmr; /**< UPMB Mode Register */ 104 107 __be32 mcmr; /**< UPMC Mode Register */ 105 108 u8 res2[0x8]; ··· 226 219 u8 res11[0x8]; 227 220 u8 res8[0xF00]; 228 221 }; 222 + 223 + extern struct fsl_lbc_regs __iomem *fsl_lbc_regs; 224 + extern spinlock_t fsl_lbc_lock; 225 + 226 + /* 227 + * FSL UPM routines 228 + */ 229 + struct fsl_upm { 230 + __be32 __iomem *mxmr; 231 + int width; 232 + }; 233 + 234 + extern int fsl_lbc_find(phys_addr_t addr_base); 235 + extern int fsl_upm_find(phys_addr_t addr_base, struct fsl_upm *upm); 236 + 237 + /** 238 + * fsl_upm_start_pattern - start UPM patterns execution 239 + * @upm: pointer to the fsl_upm structure obtained via fsl_upm_find 240 + * @pat_offset: UPM pattern offset for the command to be executed 241 + * 242 + * This routine programmes UPM so the next memory access that hits an UPM 243 + * will trigger pattern execution, starting at pat_offset. 244 + */ 245 + static inline void fsl_upm_start_pattern(struct fsl_upm *upm, u8 pat_offset) 246 + { 247 + clrsetbits_be32(upm->mxmr, MxMR_MAD, MxMR_OP_RP | pat_offset); 248 + } 249 + 250 + /** 251 + * fsl_upm_end_pattern - end UPM patterns execution 252 + * @upm: pointer to the fsl_upm structure obtained via fsl_upm_find 253 + * 254 + * This routine reverts UPM to normal operation mode. 255 + */ 256 + static inline void fsl_upm_end_pattern(struct fsl_upm *upm) 257 + { 258 + clrbits32(upm->mxmr, MxMR_OP_RP); 259 + 260 + while (in_be32(upm->mxmr) & MxMR_OP_RP) 261 + cpu_relax(); 262 + } 263 + 264 + /** 265 + * fsl_upm_run_pattern - actually run an UPM pattern 266 + * @upm: pointer to the fsl_upm structure obtained via fsl_upm_find 267 + * @io_base: remapped pointer to where memory access should happen 268 + * @mar: MAR register content during pattern execution 269 + * 270 + * This function triggers dummy write to the memory specified by the io_base, 271 + * thus UPM pattern actually executed. Note that mar usage depends on the 272 + * pre-programmed AMX bits in the UPM RAM. 273 + */ 274 + static inline int fsl_upm_run_pattern(struct fsl_upm *upm, 275 + void __iomem *io_base, u32 mar) 276 + { 277 + int ret = 0; 278 + unsigned long flags; 279 + 280 + spin_lock_irqsave(&fsl_lbc_lock, flags); 281 + 282 + out_be32(&fsl_lbc_regs->mar, mar << (32 - upm->width)); 283 + 284 + switch (upm->width) { 285 + case 8: 286 + out_8(io_base, 0x0); 287 + break; 288 + case 16: 289 + out_be16(io_base, 0x0); 290 + break; 291 + case 32: 292 + out_be32(io_base, 0x0); 293 + break; 294 + default: 295 + ret = -EINVAL; 296 + break; 297 + } 298 + 299 + spin_unlock_irqrestore(&fsl_lbc_lock, flags); 300 + 301 + return ret; 302 + } 229 303 230 304 #endif /* __ASM_FSL_LBC_H */