Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  arch/arm/mach-vt8500/vt8500.c
0004  *
0005  *  Copyright (C) 2012 Tony Prisk <linux@prisktech.co.nz>
0006  */
0007 
0008 #include <linux/io.h>
0009 #include <linux/pm.h>
0010 #include <linux/reboot.h>
0011 
0012 #include <asm/mach-types.h>
0013 #include <asm/mach/arch.h>
0014 #include <asm/mach/time.h>
0015 #include <asm/mach/map.h>
0016 
0017 #include <linux/of.h>
0018 #include <linux/of_address.h>
0019 #include <linux/of_irq.h>
0020 
0021 #define LEGACY_GPIO_BASE    0xD8110000
0022 #define LEGACY_PMC_BASE     0xD8130000
0023 
0024 /* Registers in GPIO Controller */
0025 #define VT8500_GPIO_MUX_REG 0x200
0026 
0027 /* Registers in Power Management Controller */
0028 #define VT8500_HCR_REG      0x12
0029 #define VT8500_PMSR_REG     0x60
0030 
0031 static void __iomem *pmc_base;
0032 
0033 static void vt8500_restart(enum reboot_mode mode, const char *cmd)
0034 {
0035     if (pmc_base)
0036         writel(1, pmc_base + VT8500_PMSR_REG);
0037 }
0038 
0039 static struct map_desc vt8500_io_desc[] __initdata = {
0040     /* SoC MMIO registers */
0041     [0] = {
0042         .virtual    = 0xf8000000,
0043         .pfn        = __phys_to_pfn(0xd8000000),
0044         .length     = 0x00390000, /* max of all chip variants */
0045         .type       = MT_DEVICE
0046     },
0047 };
0048 
0049 static void __init vt8500_map_io(void)
0050 {
0051     iotable_init(vt8500_io_desc, ARRAY_SIZE(vt8500_io_desc));
0052 }
0053 
0054 static void vt8500_power_off(void)
0055 {
0056     local_irq_disable();
0057     writew(5, pmc_base + VT8500_HCR_REG);
0058     asm("mcr p15, 0, %0, c7, c0, 4" : : "r" (0));
0059 }
0060 
0061 static void __init vt8500_init(void)
0062 {
0063     struct device_node *np;
0064 #if defined(CONFIG_FB_VT8500) || defined(CONFIG_FB_WM8505)
0065     struct device_node *fb;
0066     void __iomem *gpio_base;
0067 #endif
0068 
0069 #ifdef CONFIG_FB_VT8500
0070     fb = of_find_compatible_node(NULL, NULL, "via,vt8500-fb");
0071     if (fb) {
0072         np = of_find_compatible_node(NULL, NULL, "via,vt8500-gpio");
0073         if (np) {
0074             gpio_base = of_iomap(np, 0);
0075 
0076             if (!gpio_base)
0077                 pr_err("%s: of_iomap(gpio_mux) failed\n",
0078                                 __func__);
0079 
0080             of_node_put(np);
0081         } else {
0082             gpio_base = ioremap(LEGACY_GPIO_BASE, 0x1000);
0083             if (!gpio_base)
0084                 pr_err("%s: ioremap(legacy_gpio_mux) failed\n",
0085                                 __func__);
0086         }
0087         if (gpio_base) {
0088             writel(readl(gpio_base + VT8500_GPIO_MUX_REG) | 1,
0089                 gpio_base + VT8500_GPIO_MUX_REG);
0090             iounmap(gpio_base);
0091         } else
0092             pr_err("%s: Could not remap GPIO mux\n", __func__);
0093 
0094         of_node_put(fb);
0095     }
0096 #endif
0097 
0098 #ifdef CONFIG_FB_WM8505
0099     fb = of_find_compatible_node(NULL, NULL, "wm,wm8505-fb");
0100     if (fb) {
0101         np = of_find_compatible_node(NULL, NULL, "wm,wm8505-gpio");
0102         if (!np)
0103             np = of_find_compatible_node(NULL, NULL,
0104                             "wm,wm8650-gpio");
0105         if (np) {
0106             gpio_base = of_iomap(np, 0);
0107 
0108             if (!gpio_base)
0109                 pr_err("%s: of_iomap(gpio_mux) failed\n",
0110                                 __func__);
0111 
0112             of_node_put(np);
0113         } else {
0114             gpio_base = ioremap(LEGACY_GPIO_BASE, 0x1000);
0115             if (!gpio_base)
0116                 pr_err("%s: ioremap(legacy_gpio_mux) failed\n",
0117                                 __func__);
0118         }
0119         if (gpio_base) {
0120             writel(readl(gpio_base + VT8500_GPIO_MUX_REG) |
0121                 0x80000000, gpio_base + VT8500_GPIO_MUX_REG);
0122             iounmap(gpio_base);
0123         } else
0124             pr_err("%s: Could not remap GPIO mux\n", __func__);
0125 
0126         of_node_put(fb);
0127     }
0128 #endif
0129 
0130     np = of_find_compatible_node(NULL, NULL, "via,vt8500-pmc");
0131     if (np) {
0132         pmc_base = of_iomap(np, 0);
0133 
0134         if (!pmc_base)
0135             pr_err("%s:of_iomap(pmc) failed\n", __func__);
0136 
0137         of_node_put(np);
0138     } else {
0139         pmc_base = ioremap(LEGACY_PMC_BASE, 0x1000);
0140         if (!pmc_base)
0141             pr_err("%s:ioremap(power_off) failed\n", __func__);
0142     }
0143     if (pmc_base)
0144         pm_power_off = &vt8500_power_off;
0145     else
0146         pr_err("%s: PMC Hibernation register could not be remapped, not enabling power off!\n", __func__);
0147 }
0148 
0149 static const char * const vt8500_dt_compat[] = {
0150     "via,vt8500",
0151     "wm,wm8650",
0152     "wm,wm8505",
0153     "wm,wm8750",
0154     "wm,wm8850",
0155     NULL
0156 };
0157 
0158 DT_MACHINE_START(WMT_DT, "VIA/Wondermedia SoC (Device Tree Support)")
0159     .dt_compat  = vt8500_dt_compat,
0160     .map_io     = vt8500_map_io,
0161     .init_machine   = vt8500_init,
0162     .restart    = vt8500_restart,
0163 MACHINE_END
0164