Path: blob/master/arch/arm/mach-orion5x/addr-map.c
10819 views
/*1* arch/arm/mach-orion5x/addr-map.c2*3* Address map functions for Marvell Orion 5x SoCs4*5* Maintainer: Tzachi Perelstein <[email protected]>6*7* This file is licensed under the terms of the GNU General Public8* License version 2. This program is licensed "as is" without any9* warranty of any kind, whether express or implied.10*/1112#include <linux/kernel.h>13#include <linux/init.h>14#include <linux/mbus.h>15#include <linux/io.h>16#include <linux/errno.h>17#include <mach/hardware.h>18#include "common.h"1920/*21* The Orion has fully programmable address map. There's a separate address22* map for each of the device _master_ interfaces, e.g. CPU, PCI, PCIe, USB,23* Gigabit Ethernet, DMA/XOR engines, etc. Each interface has its own24* address decode windows that allow it to access any of the Orion resources.25*26* CPU address decoding --27* Linux assumes that it is the boot loader that already setup the access to28* DDR and internal registers.29* Setup access to PCI and PCIe IO/MEM space is issued by this file.30* Setup access to various devices located on the device bus interface (e.g.31* flashes, RTC, etc) should be issued by machine-setup.c according to32* specific board population (by using orion5x_setup_*_win()).33*34* Non-CPU Masters address decoding --35* Unlike the CPU, we setup the access from Orion's master interfaces to DDR36* banks only (the typical use case).37* Setup access for each master to DDR is issued by platform device setup.38*/3940/*41* Generic Address Decode Windows bit settings42*/43#define TARGET_DDR 044#define TARGET_DEV_BUS 145#define TARGET_PCI 346#define TARGET_PCIE 447#define TARGET_SRAM 948#define ATTR_PCIE_MEM 0x5949#define ATTR_PCIE_IO 0x5150#define ATTR_PCIE_WA 0x7951#define ATTR_PCI_MEM 0x5952#define ATTR_PCI_IO 0x5153#define ATTR_DEV_CS0 0x1e54#define ATTR_DEV_CS1 0x1d55#define ATTR_DEV_CS2 0x1b56#define ATTR_DEV_BOOT 0xf57#define ATTR_SRAM 0x05859/*60* Helpers to get DDR bank info61*/62#define ORION5X_DDR_REG(x) (ORION5X_DDR_VIRT_BASE | (x))63#define DDR_BASE_CS(n) ORION5X_DDR_REG(0x1500 + ((n) << 3))64#define DDR_SIZE_CS(n) ORION5X_DDR_REG(0x1504 + ((n) << 3))6566/*67* CPU Address Decode Windows registers68*/69#define ORION5X_BRIDGE_REG(x) (ORION5X_BRIDGE_VIRT_BASE | (x))70#define CPU_WIN_CTRL(n) ORION5X_BRIDGE_REG(0x000 | ((n) << 4))71#define CPU_WIN_BASE(n) ORION5X_BRIDGE_REG(0x004 | ((n) << 4))72#define CPU_WIN_REMAP_LO(n) ORION5X_BRIDGE_REG(0x008 | ((n) << 4))73#define CPU_WIN_REMAP_HI(n) ORION5X_BRIDGE_REG(0x00c | ((n) << 4))747576struct mbus_dram_target_info orion5x_mbus_dram_info;77static int __initdata win_alloc_count;7879static int __init orion5x_cpu_win_can_remap(int win)80{81u32 dev, rev;8283orion5x_pcie_id(&dev, &rev);84if ((dev == MV88F5281_DEV_ID && win < 4)85|| (dev == MV88F5182_DEV_ID && win < 2)86|| (dev == MV88F5181_DEV_ID && win < 2)87|| (dev == MV88F6183_DEV_ID && win < 4))88return 1;8990return 0;91}9293static int __init setup_cpu_win(int win, u32 base, u32 size,94u8 target, u8 attr, int remap)95{96if (win >= 8) {97printk(KERN_ERR "setup_cpu_win: trying to allocate "98"window %d\n", win);99return -ENOSPC;100}101102writel(base & 0xffff0000, CPU_WIN_BASE(win));103writel(((size - 1) & 0xffff0000) | (attr << 8) | (target << 4) | 1,104CPU_WIN_CTRL(win));105106if (orion5x_cpu_win_can_remap(win)) {107if (remap < 0)108remap = base;109110writel(remap & 0xffff0000, CPU_WIN_REMAP_LO(win));111writel(0, CPU_WIN_REMAP_HI(win));112}113return 0;114}115116void __init orion5x_setup_cpu_mbus_bridge(void)117{118int i;119int cs;120121/*122* First, disable and clear windows.123*/124for (i = 0; i < 8; i++) {125writel(0, CPU_WIN_BASE(i));126writel(0, CPU_WIN_CTRL(i));127if (orion5x_cpu_win_can_remap(i)) {128writel(0, CPU_WIN_REMAP_LO(i));129writel(0, CPU_WIN_REMAP_HI(i));130}131}132133/*134* Setup windows for PCI+PCIe IO+MEM space.135*/136setup_cpu_win(0, ORION5X_PCIE_IO_PHYS_BASE, ORION5X_PCIE_IO_SIZE,137TARGET_PCIE, ATTR_PCIE_IO, ORION5X_PCIE_IO_BUS_BASE);138setup_cpu_win(1, ORION5X_PCI_IO_PHYS_BASE, ORION5X_PCI_IO_SIZE,139TARGET_PCI, ATTR_PCI_IO, ORION5X_PCI_IO_BUS_BASE);140setup_cpu_win(2, ORION5X_PCIE_MEM_PHYS_BASE, ORION5X_PCIE_MEM_SIZE,141TARGET_PCIE, ATTR_PCIE_MEM, -1);142setup_cpu_win(3, ORION5X_PCI_MEM_PHYS_BASE, ORION5X_PCI_MEM_SIZE,143TARGET_PCI, ATTR_PCI_MEM, -1);144win_alloc_count = 4;145146/*147* Setup MBUS dram target info.148*/149orion5x_mbus_dram_info.mbus_dram_target_id = TARGET_DDR;150151for (i = 0, cs = 0; i < 4; i++) {152u32 base = readl(DDR_BASE_CS(i));153u32 size = readl(DDR_SIZE_CS(i));154155/*156* Chip select enabled?157*/158if (size & 1) {159struct mbus_dram_window *w;160161w = &orion5x_mbus_dram_info.cs[cs++];162w->cs_index = i;163w->mbus_attr = 0xf & ~(1 << i);164w->base = base & 0xffff0000;165w->size = (size | 0x0000ffff) + 1;166}167}168orion5x_mbus_dram_info.num_cs = cs;169}170171void __init orion5x_setup_dev_boot_win(u32 base, u32 size)172{173setup_cpu_win(win_alloc_count++, base, size,174TARGET_DEV_BUS, ATTR_DEV_BOOT, -1);175}176177void __init orion5x_setup_dev0_win(u32 base, u32 size)178{179setup_cpu_win(win_alloc_count++, base, size,180TARGET_DEV_BUS, ATTR_DEV_CS0, -1);181}182183void __init orion5x_setup_dev1_win(u32 base, u32 size)184{185setup_cpu_win(win_alloc_count++, base, size,186TARGET_DEV_BUS, ATTR_DEV_CS1, -1);187}188189void __init orion5x_setup_dev2_win(u32 base, u32 size)190{191setup_cpu_win(win_alloc_count++, base, size,192TARGET_DEV_BUS, ATTR_DEV_CS2, -1);193}194195void __init orion5x_setup_pcie_wa_win(u32 base, u32 size)196{197setup_cpu_win(win_alloc_count++, base, size,198TARGET_PCIE, ATTR_PCIE_WA, -1);199}200201int __init orion5x_setup_sram_win(void)202{203return setup_cpu_win(win_alloc_count++, ORION5X_SRAM_PHYS_BASE,204ORION5X_SRAM_SIZE, TARGET_SRAM, ATTR_SRAM, -1);205}206207208