Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Juergen Beisert | eea643f | 2008-07-05 10:02:56 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 1999 ARM Limited |
| 4 | * Copyright (C) 2000 Deep Blue Solutions Ltd |
| 5 | * Copyright 2006-2007 Freescale Semiconductor, Inc. All Rights Reserved. |
| 6 | * Copyright 2008 Juergen Beisert, kernel@pengutronix.de |
Ilya Yanok | 74bef9a | 2009-03-03 02:49:23 +0300 | [diff] [blame] | 7 | * Copyright 2009 Ilya Yanok, Emcraft Systems Ltd, yanok@emcraft.com |
Juergen Beisert | eea643f | 2008-07-05 10:02:56 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/clk.h> |
| 12 | #include <linux/io.h> |
Ilya Yanok | 74bef9a | 2009-03-03 02:49:23 +0300 | [diff] [blame] | 13 | #include <linux/err.h> |
| 14 | #include <linux/delay.h> |
Shawn Guo | c1e31d1 | 2013-05-10 10:19:01 +0800 | [diff] [blame] | 15 | #include <linux/of.h> |
| 16 | #include <linux/of_address.h> |
Juergen Beisert | eea643f | 2008-07-05 10:02:56 +0200 | [diff] [blame] | 17 | |
David Howells | 9f97da7 | 2012-03-28 18:30:01 +0100 | [diff] [blame] | 18 | #include <asm/system_misc.h> |
Juergen Beisert | eea643f | 2008-07-05 10:02:56 +0200 | [diff] [blame] | 19 | #include <asm/proc-fns.h> |
Arnaud Patard (Rtp) | c2932bf | 2010-10-27 14:40:55 +0200 | [diff] [blame] | 20 | #include <asm/mach-types.h> |
Shawn Guo | e6a0756 | 2013-07-08 21:45:20 +0800 | [diff] [blame] | 21 | #include <asm/hardware/cache-l2x0.h> |
Juergen Beisert | eea643f | 2008-07-05 10:02:56 +0200 | [diff] [blame] | 22 | |
Shawn Guo | e337247 | 2012-09-13 21:01:00 +0800 | [diff] [blame] | 23 | #include "common.h" |
Shawn Guo | 50f2de6 | 2012-09-14 14:14:45 +0800 | [diff] [blame] | 24 | #include "hardware.h" |
Shawn Guo | e337247 | 2012-09-13 21:01:00 +0800 | [diff] [blame] | 25 | |
Sascha Hauer | be124c9 | 2009-06-04 12:19:02 +0200 | [diff] [blame] | 26 | static void __iomem *wdog_base; |
Shawn Guo | 18cb680 | 2013-05-10 09:13:44 +0800 | [diff] [blame] | 27 | static struct clk *wdog_clk; |
Arnd Bergmann | 6f98cb2 | 2016-06-24 12:49:56 +0200 | [diff] [blame] | 28 | static int wcr_enable = (1 << 2); |
Juergen Beisert | eea643f | 2008-07-05 10:02:56 +0200 | [diff] [blame] | 29 | |
| 30 | /* |
| 31 | * Reset the system. It is called by machine_restart(). |
| 32 | */ |
Robin Holt | 7b6d864 | 2013-07-08 16:01:40 -0700 | [diff] [blame] | 33 | void mxc_restart(enum reboot_mode mode, const char *cmd) |
Juergen Beisert | eea643f | 2008-07-05 10:02:56 +0200 | [diff] [blame] | 34 | { |
Alexander Shiyan | 5a6e150 | 2014-06-13 11:26:13 +0400 | [diff] [blame] | 35 | if (!wdog_base) |
| 36 | goto reset_fallback; |
| 37 | |
Alexander Shiyan | ce8ad88 | 2014-06-13 11:26:12 +0400 | [diff] [blame] | 38 | if (!IS_ERR(wdog_clk)) |
Shawn Guo | 18cb680 | 2013-05-10 09:13:44 +0800 | [diff] [blame] | 39 | clk_enable(wdog_clk); |
Juergen Beisert | eea643f | 2008-07-05 10:02:56 +0200 | [diff] [blame] | 40 | |
Juergen Beisert | eea643f | 2008-07-05 10:02:56 +0200 | [diff] [blame] | 41 | /* Assert SRS signal */ |
Johannes Berg | c553138 | 2016-01-27 17:59:35 +0100 | [diff] [blame] | 42 | imx_writew(wcr_enable, wdog_base); |
Shawn Guo | 2c11b57 | 2013-10-31 10:35:40 +0800 | [diff] [blame] | 43 | /* |
| 44 | * Due to imx6q errata ERR004346 (WDOG: WDOG SRS bit requires to be |
| 45 | * written twice), we add another two writes to ensure there must be at |
| 46 | * least two writes happen in the same one 32kHz clock period. We save |
| 47 | * the target check here, since the writes shouldn't be a huge burden |
| 48 | * for other platforms. |
| 49 | */ |
Johannes Berg | c553138 | 2016-01-27 17:59:35 +0100 | [diff] [blame] | 50 | imx_writew(wcr_enable, wdog_base); |
| 51 | imx_writew(wcr_enable, wdog_base); |
Ilya Yanok | 74bef9a | 2009-03-03 02:49:23 +0300 | [diff] [blame] | 52 | |
| 53 | /* wait for reset to assert... */ |
| 54 | mdelay(500); |
| 55 | |
Shawn Guo | 18cb680 | 2013-05-10 09:13:44 +0800 | [diff] [blame] | 56 | pr_err("%s: Watchdog reset failed to assert reset\n", __func__); |
Ilya Yanok | 74bef9a | 2009-03-03 02:49:23 +0300 | [diff] [blame] | 57 | |
| 58 | /* delay to allow the serial port to show the message */ |
| 59 | mdelay(50); |
| 60 | |
Alexander Shiyan | 5a6e150 | 2014-06-13 11:26:13 +0400 | [diff] [blame] | 61 | reset_fallback: |
Ilya Yanok | 74bef9a | 2009-03-03 02:49:23 +0300 | [diff] [blame] | 62 | /* we'll take a jump through zero as a poor second */ |
Russell King | e879c86 | 2011-11-01 13:16:26 +0000 | [diff] [blame] | 63 | soft_restart(0); |
Juergen Beisert | eea643f | 2008-07-05 10:02:56 +0200 | [diff] [blame] | 64 | } |
Sascha Hauer | be124c9 | 2009-06-04 12:19:02 +0200 | [diff] [blame] | 65 | |
Shawn Guo | 18cb680 | 2013-05-10 09:13:44 +0800 | [diff] [blame] | 66 | void __init mxc_arch_reset_init(void __iomem *base) |
Sascha Hauer | be124c9 | 2009-06-04 12:19:02 +0200 | [diff] [blame] | 67 | { |
| 68 | wdog_base = base; |
Shawn Guo | 18cb680 | 2013-05-10 09:13:44 +0800 | [diff] [blame] | 69 | |
| 70 | wdog_clk = clk_get_sys("imx2-wdt.0", NULL); |
Alexander Shiyan | ce8ad88 | 2014-06-13 11:26:12 +0400 | [diff] [blame] | 71 | if (IS_ERR(wdog_clk)) |
Shawn Guo | 18cb680 | 2013-05-10 09:13:44 +0800 | [diff] [blame] | 72 | pr_warn("%s: failed to get wdog clock\n", __func__); |
Alexander Shiyan | ce8ad88 | 2014-06-13 11:26:12 +0400 | [diff] [blame] | 73 | else |
| 74 | clk_prepare(wdog_clk); |
Sascha Hauer | be124c9 | 2009-06-04 12:19:02 +0200 | [diff] [blame] | 75 | } |
Shawn Guo | c1e31d1 | 2013-05-10 10:19:01 +0800 | [diff] [blame] | 76 | |
Arnd Bergmann | 6f98cb2 | 2016-06-24 12:49:56 +0200 | [diff] [blame] | 77 | #ifdef CONFIG_SOC_IMX1 |
| 78 | void __init imx1_reset_init(void __iomem *base) |
| 79 | { |
| 80 | wcr_enable = (1 << 0); |
| 81 | mxc_arch_reset_init(base); |
| 82 | } |
| 83 | #endif |
| 84 | |
Shawn Guo | e6a0756 | 2013-07-08 21:45:20 +0800 | [diff] [blame] | 85 | #ifdef CONFIG_CACHE_L2X0 |
Vincent Stehlé | 10eff77 | 2013-07-10 11:45:46 +0200 | [diff] [blame] | 86 | void __init imx_init_l2cache(void) |
Shawn Guo | e6a0756 | 2013-07-08 21:45:20 +0800 | [diff] [blame] | 87 | { |
| 88 | void __iomem *l2x0_base; |
| 89 | struct device_node *np; |
| 90 | unsigned int val; |
| 91 | |
| 92 | np = of_find_compatible_node(NULL, NULL, "arm,pl310-cache"); |
| 93 | if (!np) |
Andrey Smirnov | 510aca6 | 2016-06-18 18:09:31 -0700 | [diff] [blame] | 94 | return; |
Shawn Guo | e6a0756 | 2013-07-08 21:45:20 +0800 | [diff] [blame] | 95 | |
| 96 | l2x0_base = of_iomap(np, 0); |
Andrey Smirnov | 510aca6 | 2016-06-18 18:09:31 -0700 | [diff] [blame] | 97 | if (!l2x0_base) |
| 98 | goto put_node; |
Shawn Guo | e6a0756 | 2013-07-08 21:45:20 +0800 | [diff] [blame] | 99 | |
Andrey Smirnov | c00e4c5 | 2016-06-18 18:09:27 -0700 | [diff] [blame] | 100 | if (!(readl_relaxed(l2x0_base + L2X0_CTRL) & L2X0_CTRL_EN)) { |
| 101 | /* Configure the L2 PREFETCH and POWER registers */ |
| 102 | val = readl_relaxed(l2x0_base + L310_PREFETCH_CTRL); |
Andrey Smirnov | b829037 | 2016-06-18 18:09:29 -0700 | [diff] [blame] | 103 | val |= L310_PREFETCH_CTRL_DBL_LINEFILL | |
| 104 | L310_PREFETCH_CTRL_INSTR_PREFETCH | |
Andrey Smirnov | 1d9e9477 | 2016-06-18 18:09:30 -0700 | [diff] [blame] | 105 | L310_PREFETCH_CTRL_DATA_PREFETCH; |
| 106 | |
| 107 | /* Set perfetch offset to improve performance */ |
| 108 | val &= ~L310_PREFETCH_CTRL_OFFSET_MASK; |
| 109 | val |= 15; |
| 110 | |
Andrey Smirnov | c00e4c5 | 2016-06-18 18:09:27 -0700 | [diff] [blame] | 111 | writel_relaxed(val, l2x0_base + L310_PREFETCH_CTRL); |
| 112 | } |
Dirk Behme | bc3d8ed | 2016-02-19 07:50:12 +0100 | [diff] [blame] | 113 | |
Shawn Guo | e6a0756 | 2013-07-08 21:45:20 +0800 | [diff] [blame] | 114 | iounmap(l2x0_base); |
Andrey Smirnov | 510aca6 | 2016-06-18 18:09:31 -0700 | [diff] [blame] | 115 | put_node: |
Shawn Guo | e6a0756 | 2013-07-08 21:45:20 +0800 | [diff] [blame] | 116 | of_node_put(np); |
Shawn Guo | e6a0756 | 2013-07-08 21:45:20 +0800 | [diff] [blame] | 117 | } |
| 118 | #endif |