Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Versatile board support using the device tree
0004  *
0005  *  Copyright (C) 2010 Secret Lab Technologies Ltd.
0006  *  Copyright (C) 2009 Jeremy Kerr <jeremy.kerr@canonical.com>
0007  *  Copyright (C) 2004 ARM Limited
0008  *  Copyright (C) 2000 Deep Blue Solutions Ltd
0009  */
0010 
0011 #include <linux/init.h>
0012 #include <linux/io.h>
0013 #include <linux/of.h>
0014 #include <linux/of_address.h>
0015 #include <linux/of_irq.h>
0016 #include <linux/of_platform.h>
0017 #include <linux/slab.h>
0018 #include <linux/amba/bus.h>
0019 #include <linux/amba/mmci.h>
0020 #include <asm/mach-types.h>
0021 #include <asm/mach/arch.h>
0022 #include <asm/mach/map.h>
0023 
0024 /* macro to get at MMIO space when running virtually */
0025 #define IO_ADDRESS(x)       (((x) & 0x0fffffff) + (((x) >> 4) & 0x0f000000) + 0xf0000000)
0026 #define __io_address(n)     ((void __iomem __force *)IO_ADDRESS(n))
0027 
0028 /*
0029  * ------------------------------------------------------------------------
0030  *  Versatile Registers
0031  * ------------------------------------------------------------------------
0032  */
0033 #define VERSATILE_SYS_PCICTL_OFFSET           0x44
0034 #define VERSATILE_SYS_MCI_OFFSET              0x48
0035 
0036 /*
0037  * VERSATILE peripheral addresses
0038  */
0039 #define VERSATILE_MMCI0_BASE           0x10005000   /* MMC interface */
0040 #define VERSATILE_MMCI1_BASE           0x1000B000   /* MMC Interface */
0041 #define VERSATILE_SCTL_BASE            0x101E0000   /* System controller */
0042 
0043 /*
0044  * System controller bit assignment
0045  */
0046 #define VERSATILE_REFCLK    0
0047 #define VERSATILE_TIMCLK    1
0048 
0049 #define VERSATILE_TIMER1_EnSel  15
0050 #define VERSATILE_TIMER2_EnSel  17
0051 #define VERSATILE_TIMER3_EnSel  19
0052 #define VERSATILE_TIMER4_EnSel  21
0053 
0054 static void __iomem *versatile_sys_base;
0055 
0056 unsigned int mmc_status(struct device *dev)
0057 {
0058     struct amba_device *adev = container_of(dev, struct amba_device, dev);
0059     u32 mask;
0060 
0061     if (adev->res.start == VERSATILE_MMCI0_BASE)
0062         mask = 1;
0063     else
0064         mask = 2;
0065 
0066     return readl(versatile_sys_base + VERSATILE_SYS_MCI_OFFSET) & mask;
0067 }
0068 
0069 static struct mmci_platform_data mmc0_plat_data = {
0070     .ocr_mask   = MMC_VDD_32_33|MMC_VDD_33_34,
0071     .status     = mmc_status,
0072 };
0073 
0074 static struct mmci_platform_data mmc1_plat_data = {
0075     .ocr_mask   = MMC_VDD_32_33|MMC_VDD_33_34,
0076     .status     = mmc_status,
0077 };
0078 
0079 /*
0080  * Lookup table for attaching a specific name and platform_data pointer to
0081  * devices as they get created by of_platform_populate().  Ideally this table
0082  * would not exist, but the current clock implementation depends on some devices
0083  * having a specific name.
0084  */
0085 struct of_dev_auxdata versatile_auxdata_lookup[] __initdata = {
0086     OF_DEV_AUXDATA("arm,primecell", VERSATILE_MMCI0_BASE, "fpga:05", &mmc0_plat_data),
0087     OF_DEV_AUXDATA("arm,primecell", VERSATILE_MMCI1_BASE, "fpga:0b", &mmc1_plat_data),
0088     {}
0089 };
0090 
0091 static struct map_desc versatile_io_desc[] __initdata __maybe_unused = {
0092     {
0093         .virtual    =  IO_ADDRESS(VERSATILE_SCTL_BASE),
0094         .pfn        = __phys_to_pfn(VERSATILE_SCTL_BASE),
0095         .length     = SZ_4K * 9,
0096         .type       = MT_DEVICE
0097     }
0098 };
0099 
0100 static void __init versatile_map_io(void)
0101 {
0102     debug_ll_io_init();
0103     iotable_init(versatile_io_desc, ARRAY_SIZE(versatile_io_desc));
0104 }
0105 
0106 static void __init versatile_init_early(void)
0107 {
0108     u32 val;
0109 
0110     /*
0111      * set clock frequency:
0112      *  VERSATILE_REFCLK is 32KHz
0113      *  VERSATILE_TIMCLK is 1MHz
0114      */
0115     val = readl(__io_address(VERSATILE_SCTL_BASE));
0116     writel((VERSATILE_TIMCLK << VERSATILE_TIMER1_EnSel) |
0117            (VERSATILE_TIMCLK << VERSATILE_TIMER2_EnSel) |
0118            (VERSATILE_TIMCLK << VERSATILE_TIMER3_EnSel) |
0119            (VERSATILE_TIMCLK << VERSATILE_TIMER4_EnSel) | val,
0120            __io_address(VERSATILE_SCTL_BASE));
0121 }
0122 
0123 static void __init versatile_dt_pci_init(void)
0124 {
0125     u32 val;
0126     struct device_node *np;
0127     struct property *newprop;
0128 
0129     np = of_find_compatible_node(NULL, NULL, "arm,versatile-pci");
0130     if (!np)
0131         return;
0132 
0133     /* Check if PCI backplane is detected */
0134     val = readl(versatile_sys_base + VERSATILE_SYS_PCICTL_OFFSET);
0135     if (val & 1) {
0136         /*
0137          * Enable PCI accesses. Note that the documentaton is
0138          * inconsistent whether or not this is needed, but the old
0139          * driver had it so we will keep it.
0140          */
0141         writel(1, versatile_sys_base + VERSATILE_SYS_PCICTL_OFFSET);
0142         goto out_put_node;
0143     }
0144 
0145     newprop = kzalloc(sizeof(*newprop), GFP_KERNEL);
0146     if (!newprop)
0147         goto out_put_node;
0148 
0149     newprop->name = kstrdup("status", GFP_KERNEL);
0150     newprop->value = kstrdup("disabled", GFP_KERNEL);
0151     newprop->length = sizeof("disabled");
0152     of_update_property(np, newprop);
0153 
0154     pr_info("Not plugged into PCI backplane!\n");
0155 
0156 out_put_node:
0157     of_node_put(np);
0158 }
0159 
0160 static void __init versatile_dt_init(void)
0161 {
0162     struct device_node *np;
0163 
0164     np = of_find_compatible_node(NULL, NULL, "arm,core-module-versatile");
0165     if (np)
0166         versatile_sys_base = of_iomap(np, 0);
0167     WARN_ON(!versatile_sys_base);
0168 
0169     versatile_dt_pci_init();
0170 
0171     of_platform_default_populate(NULL, versatile_auxdata_lookup, NULL);
0172 }
0173 
0174 static const char *const versatile_dt_match[] __initconst = {
0175     "arm,versatile-ab",
0176     "arm,versatile-pb",
0177     NULL,
0178 };
0179 
0180 DT_MACHINE_START(VERSATILE_PB, "ARM-Versatile (Device Tree Support)")
0181     .map_io     = versatile_map_io,
0182     .init_early = versatile_init_early,
0183     .init_machine   = versatile_dt_init,
0184     .dt_compat  = versatile_dt_match,
0185 MACHINE_END