blob: e88ca027129db832f34a7d85dc7e29646e07c4fe [file] [log] [blame]
Thomas Gleixnerc942fdd2019-05-27 08:55:06 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Juergen Beiserteea643f2008-07-05 10:02:56 +02002/*
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 Yanok74bef9a2009-03-03 02:49:23 +03007 * Copyright 2009 Ilya Yanok, Emcraft Systems Ltd, yanok@emcraft.com
Juergen Beiserteea643f2008-07-05 10:02:56 +02008 */
9
10#include <linux/kernel.h>
11#include <linux/clk.h>
12#include <linux/io.h>
Ilya Yanok74bef9a2009-03-03 02:49:23 +030013#include <linux/err.h>
14#include <linux/delay.h>
Shawn Guoc1e31d12013-05-10 10:19:01 +080015#include <linux/of.h>
16#include <linux/of_address.h>
Juergen Beiserteea643f2008-07-05 10:02:56 +020017
David Howells9f97da72012-03-28 18:30:01 +010018#include <asm/system_misc.h>
Juergen Beiserteea643f2008-07-05 10:02:56 +020019#include <asm/proc-fns.h>
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +020020#include <asm/mach-types.h>
Shawn Guoe6a07562013-07-08 21:45:20 +080021#include <asm/hardware/cache-l2x0.h>
Juergen Beiserteea643f2008-07-05 10:02:56 +020022
Shawn Guoe3372472012-09-13 21:01:00 +080023#include "common.h"
Shawn Guo50f2de62012-09-14 14:14:45 +080024#include "hardware.h"
Shawn Guoe3372472012-09-13 21:01:00 +080025
Sascha Hauerbe124c92009-06-04 12:19:02 +020026static void __iomem *wdog_base;
Shawn Guo18cb6802013-05-10 09:13:44 +080027static struct clk *wdog_clk;
Arnd Bergmann6f98cb22016-06-24 12:49:56 +020028static int wcr_enable = (1 << 2);
Juergen Beiserteea643f2008-07-05 10:02:56 +020029
30/*
31 * Reset the system. It is called by machine_restart().
32 */
Robin Holt7b6d8642013-07-08 16:01:40 -070033void mxc_restart(enum reboot_mode mode, const char *cmd)
Juergen Beiserteea643f2008-07-05 10:02:56 +020034{
Alexander Shiyan5a6e1502014-06-13 11:26:13 +040035 if (!wdog_base)
36 goto reset_fallback;
37
Alexander Shiyance8ad882014-06-13 11:26:12 +040038 if (!IS_ERR(wdog_clk))
Shawn Guo18cb6802013-05-10 09:13:44 +080039 clk_enable(wdog_clk);
Juergen Beiserteea643f2008-07-05 10:02:56 +020040
Juergen Beiserteea643f2008-07-05 10:02:56 +020041 /* Assert SRS signal */
Johannes Bergc5531382016-01-27 17:59:35 +010042 imx_writew(wcr_enable, wdog_base);
Shawn Guo2c11b572013-10-31 10:35:40 +080043 /*
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 Bergc5531382016-01-27 17:59:35 +010050 imx_writew(wcr_enable, wdog_base);
51 imx_writew(wcr_enable, wdog_base);
Ilya Yanok74bef9a2009-03-03 02:49:23 +030052
53 /* wait for reset to assert... */
54 mdelay(500);
55
Shawn Guo18cb6802013-05-10 09:13:44 +080056 pr_err("%s: Watchdog reset failed to assert reset\n", __func__);
Ilya Yanok74bef9a2009-03-03 02:49:23 +030057
58 /* delay to allow the serial port to show the message */
59 mdelay(50);
60
Alexander Shiyan5a6e1502014-06-13 11:26:13 +040061reset_fallback:
Ilya Yanok74bef9a2009-03-03 02:49:23 +030062 /* we'll take a jump through zero as a poor second */
Russell Kinge879c862011-11-01 13:16:26 +000063 soft_restart(0);
Juergen Beiserteea643f2008-07-05 10:02:56 +020064}
Sascha Hauerbe124c92009-06-04 12:19:02 +020065
Shawn Guo18cb6802013-05-10 09:13:44 +080066void __init mxc_arch_reset_init(void __iomem *base)
Sascha Hauerbe124c92009-06-04 12:19:02 +020067{
68 wdog_base = base;
Shawn Guo18cb6802013-05-10 09:13:44 +080069
70 wdog_clk = clk_get_sys("imx2-wdt.0", NULL);
Alexander Shiyance8ad882014-06-13 11:26:12 +040071 if (IS_ERR(wdog_clk))
Shawn Guo18cb6802013-05-10 09:13:44 +080072 pr_warn("%s: failed to get wdog clock\n", __func__);
Alexander Shiyance8ad882014-06-13 11:26:12 +040073 else
74 clk_prepare(wdog_clk);
Sascha Hauerbe124c92009-06-04 12:19:02 +020075}
Shawn Guoc1e31d12013-05-10 10:19:01 +080076
Arnd Bergmann6f98cb22016-06-24 12:49:56 +020077#ifdef CONFIG_SOC_IMX1
78void __init imx1_reset_init(void __iomem *base)
79{
80 wcr_enable = (1 << 0);
81 mxc_arch_reset_init(base);
82}
83#endif
84
Shawn Guoe6a07562013-07-08 21:45:20 +080085#ifdef CONFIG_CACHE_L2X0
Vincent Stehlé10eff772013-07-10 11:45:46 +020086void __init imx_init_l2cache(void)
Shawn Guoe6a07562013-07-08 21:45:20 +080087{
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 Smirnov510aca62016-06-18 18:09:31 -070094 return;
Shawn Guoe6a07562013-07-08 21:45:20 +080095
96 l2x0_base = of_iomap(np, 0);
Andrey Smirnov510aca62016-06-18 18:09:31 -070097 if (!l2x0_base)
98 goto put_node;
Shawn Guoe6a07562013-07-08 21:45:20 +080099
Andrey Smirnovc00e4c52016-06-18 18:09:27 -0700100 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 Smirnovb8290372016-06-18 18:09:29 -0700103 val |= L310_PREFETCH_CTRL_DBL_LINEFILL |
104 L310_PREFETCH_CTRL_INSTR_PREFETCH |
Andrey Smirnov1d9e94772016-06-18 18:09:30 -0700105 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 Smirnovc00e4c52016-06-18 18:09:27 -0700111 writel_relaxed(val, l2x0_base + L310_PREFETCH_CTRL);
112 }
Dirk Behmebc3d8ed2016-02-19 07:50:12 +0100113
Shawn Guoe6a07562013-07-08 21:45:20 +0800114 iounmap(l2x0_base);
Andrey Smirnov510aca62016-06-18 18:09:31 -0700115put_node:
Shawn Guoe6a07562013-07-08 21:45:20 +0800116 of_node_put(np);
Shawn Guoe6a07562013-07-08 21:45:20 +0800117}
118#endif