Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Uwe Kleine-König | 27ad4bf | 2011-03-17 09:40:29 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 1999,2000 Arm Limited |
| 4 | * Copyright (C) 2000 Deep Blue Solutions Ltd |
| 5 | * Copyright (C) 2002 Shane Nay (shane@minirl.com) |
| 6 | * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved. |
| 7 | * - add MX31 specific definitions |
Uwe Kleine-König | 27ad4bf | 2011-03-17 09:40:29 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/mm.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/err.h> |
Arnd Bergmann | c112d2a | 2016-06-24 12:49:58 +0200 | [diff] [blame] | 13 | #include <linux/io.h> |
Fabio Estevam | 2cf98d1 | 2020-09-16 21:41:18 -0300 | [diff] [blame] | 14 | #include <linux/of_address.h> |
Dong Aisheng | a2aa65a | 2012-05-02 19:31:20 +0800 | [diff] [blame] | 15 | #include <linux/pinctrl/machine.h> |
Uwe Kleine-König | 27ad4bf | 2011-03-17 09:40:29 +0100 | [diff] [blame] | 16 | |
Olof Johansson | 86dfe44 | 2012-03-29 23:22:44 -0700 | [diff] [blame] | 17 | #include <asm/system_misc.h> |
Shawn Guo | ddd5f51 | 2011-09-28 17:16:05 +0800 | [diff] [blame] | 18 | #include <asm/hardware/cache-l2x0.h> |
Uwe Kleine-König | 27ad4bf | 2011-03-17 09:40:29 +0100 | [diff] [blame] | 19 | #include <asm/mach/map.h> |
| 20 | |
Shawn Guo | e337247 | 2012-09-13 21:01:00 +0800 | [diff] [blame] | 21 | #include "common.h" |
Sascha Hauer | eb92044 | 2012-04-03 12:42:27 +0200 | [diff] [blame] | 22 | #include "crmregs-imx3.h" |
Shawn Guo | 50f2de6 | 2012-09-14 14:14:45 +0800 | [diff] [blame] | 23 | #include "hardware.h" |
Sascha Hauer | eb92044 | 2012-04-03 12:42:27 +0200 | [diff] [blame] | 24 | |
| 25 | void __iomem *mx3_ccm_base; |
| 26 | |
Shawn Guo | 41e7daf | 2011-09-28 17:16:06 +0800 | [diff] [blame] | 27 | static void imx3_idle(void) |
| 28 | { |
| 29 | unsigned long reg = 0; |
Shawn Guo | 8c6d831 | 2011-11-11 13:09:18 +0800 | [diff] [blame] | 30 | |
Nicolas Pitre | 4a3ea24 | 2011-08-03 11:34:59 -0400 | [diff] [blame] | 31 | __asm__ __volatile__( |
| 32 | /* disable I and D cache */ |
| 33 | "mrc p15, 0, %0, c1, c0, 0\n" |
| 34 | "bic %0, %0, #0x00001000\n" |
| 35 | "bic %0, %0, #0x00000004\n" |
| 36 | "mcr p15, 0, %0, c1, c0, 0\n" |
| 37 | /* invalidate I cache */ |
| 38 | "mov %0, #0\n" |
| 39 | "mcr p15, 0, %0, c7, c5, 0\n" |
| 40 | /* clear and invalidate D cache */ |
| 41 | "mov %0, #0\n" |
| 42 | "mcr p15, 0, %0, c7, c14, 0\n" |
| 43 | /* WFI */ |
| 44 | "mov %0, #0\n" |
| 45 | "mcr p15, 0, %0, c7, c0, 4\n" |
| 46 | "nop\n" "nop\n" "nop\n" "nop\n" |
| 47 | "nop\n" "nop\n" "nop\n" |
| 48 | /* enable I and D cache */ |
| 49 | "mrc p15, 0, %0, c1, c0, 0\n" |
| 50 | "orr %0, %0, #0x00001000\n" |
| 51 | "orr %0, %0, #0x00000004\n" |
| 52 | "mcr p15, 0, %0, c1, c0, 0\n" |
| 53 | : "=r" (reg)); |
Shawn Guo | 41e7daf | 2011-09-28 17:16:06 +0800 | [diff] [blame] | 54 | } |
| 55 | |
Laura Abbott | 9b97173 | 2013-05-16 19:40:22 +0100 | [diff] [blame] | 56 | static void __iomem *imx3_ioremap_caller(phys_addr_t phys_addr, size_t size, |
Rob Herring | c177aa9 | 2012-02-13 13:24:15 -0600 | [diff] [blame] | 57 | unsigned int mtype, void *caller) |
Shawn Guo | f548897 | 2011-09-28 17:16:07 +0800 | [diff] [blame] | 58 | { |
| 59 | if (mtype == MT_DEVICE) { |
| 60 | /* |
| 61 | * Access all peripherals below 0x80000000 as nonshared device |
| 62 | * on mx3, but leave l2cc alone. Otherwise cache corruptions |
| 63 | * can occur. |
| 64 | */ |
| 65 | if (phys_addr < 0x80000000 && |
| 66 | !addr_in_module(phys_addr, MX3x_L2CC)) |
| 67 | mtype = MT_DEVICE_NONSHARED; |
| 68 | } |
| 69 | |
Rob Herring | c177aa9 | 2012-02-13 13:24:15 -0600 | [diff] [blame] | 70 | return __arm_ioremap_caller(phys_addr, size, mtype, caller); |
Shawn Guo | f548897 | 2011-09-28 17:16:07 +0800 | [diff] [blame] | 71 | } |
| 72 | |
Uwe Kleine-König | 87514fc | 2011-11-22 10:07:26 +0100 | [diff] [blame] | 73 | #ifdef CONFIG_SOC_IMX31 |
Uwe Kleine-König | 27ad4bf | 2011-03-17 09:40:29 +0100 | [diff] [blame] | 74 | static struct map_desc mx31_io_desc[] __initdata = { |
| 75 | imx_map_entry(MX31, X_MEMC, MT_DEVICE), |
| 76 | imx_map_entry(MX31, AVIC, MT_DEVICE_NONSHARED), |
| 77 | imx_map_entry(MX31, AIPS1, MT_DEVICE_NONSHARED), |
| 78 | imx_map_entry(MX31, AIPS2, MT_DEVICE_NONSHARED), |
| 79 | imx_map_entry(MX31, SPBA0, MT_DEVICE_NONSHARED), |
| 80 | }; |
| 81 | |
| 82 | /* |
| 83 | * This function initializes the memory map. It is called during the |
| 84 | * system startup to create static physical to virtual memory mappings |
| 85 | * for the IO modules. |
| 86 | */ |
| 87 | void __init mx31_map_io(void) |
| 88 | { |
| 89 | iotable_init(mx31_io_desc, ARRAY_SIZE(mx31_io_desc)); |
| 90 | } |
| 91 | |
Arnd Bergmann | c112d2a | 2016-06-24 12:49:58 +0200 | [diff] [blame] | 92 | static void imx31_idle(void) |
| 93 | { |
| 94 | int reg = imx_readl(mx3_ccm_base + MXC_CCM_CCMR); |
| 95 | reg &= ~MXC_CCM_CCMR_LPM_MASK; |
| 96 | imx_writel(reg, mx3_ccm_base + MXC_CCM_CCMR); |
| 97 | |
| 98 | imx3_idle(); |
| 99 | } |
| 100 | |
Uwe Kleine-König | 27ad4bf | 2011-03-17 09:40:29 +0100 | [diff] [blame] | 101 | void __init imx31_init_early(void) |
| 102 | { |
Fabio Estevam | 2cf98d1 | 2020-09-16 21:41:18 -0300 | [diff] [blame] | 103 | struct device_node *np; |
| 104 | |
Uwe Kleine-König | 27ad4bf | 2011-03-17 09:40:29 +0100 | [diff] [blame] | 105 | mxc_set_cpu_type(MXC_CPU_MX31); |
Rob Herring | c177aa9 | 2012-02-13 13:24:15 -0600 | [diff] [blame] | 106 | arch_ioremap_caller = imx3_ioremap_caller; |
Arnd Bergmann | c112d2a | 2016-06-24 12:49:58 +0200 | [diff] [blame] | 107 | arm_pm_idle = imx31_idle; |
Fabio Estevam | 2cf98d1 | 2020-09-16 21:41:18 -0300 | [diff] [blame] | 108 | np = of_find_compatible_node(NULL, NULL, "fsl,imx31-ccm"); |
| 109 | mx3_ccm_base = of_iomap(np, 0); |
| 110 | BUG_ON(!mx3_ccm_base); |
Uwe Kleine-König | 27ad4bf | 2011-03-17 09:40:29 +0100 | [diff] [blame] | 111 | } |
Uwe Kleine-König | 87514fc | 2011-11-22 10:07:26 +0100 | [diff] [blame] | 112 | #endif /* ifdef CONFIG_SOC_IMX31 */ |
| 113 | |
| 114 | #ifdef CONFIG_SOC_IMX35 |
| 115 | static struct map_desc mx35_io_desc[] __initdata = { |
| 116 | imx_map_entry(MX35, X_MEMC, MT_DEVICE), |
| 117 | imx_map_entry(MX35, AVIC, MT_DEVICE_NONSHARED), |
| 118 | imx_map_entry(MX35, AIPS1, MT_DEVICE_NONSHARED), |
| 119 | imx_map_entry(MX35, AIPS2, MT_DEVICE_NONSHARED), |
| 120 | imx_map_entry(MX35, SPBA0, MT_DEVICE_NONSHARED), |
| 121 | }; |
| 122 | |
| 123 | void __init mx35_map_io(void) |
| 124 | { |
| 125 | iotable_init(mx35_io_desc, ARRAY_SIZE(mx35_io_desc)); |
| 126 | } |
| 127 | |
Arnd Bergmann | c112d2a | 2016-06-24 12:49:58 +0200 | [diff] [blame] | 128 | static void imx35_idle(void) |
| 129 | { |
| 130 | int reg = imx_readl(mx3_ccm_base + MXC_CCM_CCMR); |
| 131 | reg &= ~MXC_CCM_CCMR_LPM_MASK; |
| 132 | reg |= MXC_CCM_CCMR_LPM_WAIT_MX35; |
| 133 | imx_writel(reg, mx3_ccm_base + MXC_CCM_CCMR); |
| 134 | |
| 135 | imx3_idle(); |
| 136 | } |
| 137 | |
Uwe Kleine-König | 87514fc | 2011-11-22 10:07:26 +0100 | [diff] [blame] | 138 | void __init imx35_init_early(void) |
| 139 | { |
Fabio Estevam | 2cf98d1 | 2020-09-16 21:41:18 -0300 | [diff] [blame] | 140 | struct device_node *np; |
| 141 | |
Uwe Kleine-König | 87514fc | 2011-11-22 10:07:26 +0100 | [diff] [blame] | 142 | mxc_set_cpu_type(MXC_CPU_MX35); |
Arnd Bergmann | c112d2a | 2016-06-24 12:49:58 +0200 | [diff] [blame] | 143 | arm_pm_idle = imx35_idle; |
Rob Herring | c177aa9 | 2012-02-13 13:24:15 -0600 | [diff] [blame] | 144 | arch_ioremap_caller = imx3_ioremap_caller; |
Fabio Estevam | 2cf98d1 | 2020-09-16 21:41:18 -0300 | [diff] [blame] | 145 | np = of_find_compatible_node(NULL, NULL, "fsl,imx35-ccm"); |
| 146 | mx3_ccm_base = of_iomap(np, 0); |
| 147 | BUG_ON(!mx3_ccm_base); |
Uwe Kleine-König | 87514fc | 2011-11-22 10:07:26 +0100 | [diff] [blame] | 148 | } |
Uwe Kleine-König | 87514fc | 2011-11-22 10:07:26 +0100 | [diff] [blame] | 149 | #endif /* ifdef CONFIG_SOC_IMX35 */ |