blob: 105d1ce4ed9d1400da09d476c03761e2de5c982e [file] [log] [blame]
Juergen Beiserteea643f2008-07-05 10:02:56 +02001/*
2 * Copyright (C) 1999 ARM Limited
3 * Copyright (C) 2000 Deep Blue Solutions Ltd
4 * Copyright 2006-2007 Freescale Semiconductor, Inc. All Rights Reserved.
5 * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
Ilya Yanok74bef9a2009-03-03 02:49:23 +03006 * Copyright 2009 Ilya Yanok, Emcraft Systems Ltd, yanok@emcraft.com
Juergen Beiserteea643f2008-07-05 10:02:56 +02007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Juergen Beiserteea643f2008-07-05 10:02:56 +020017 */
18
19#include <linux/kernel.h>
20#include <linux/clk.h>
21#include <linux/io.h>
Ilya Yanok74bef9a2009-03-03 02:49:23 +030022#include <linux/err.h>
23#include <linux/delay.h>
Shawn Guoc1e31d12013-05-10 10:19:01 +080024#include <linux/of.h>
25#include <linux/of_address.h>
Juergen Beiserteea643f2008-07-05 10:02:56 +020026
David Howells9f97da72012-03-28 18:30:01 +010027#include <asm/system_misc.h>
Juergen Beiserteea643f2008-07-05 10:02:56 +020028#include <asm/proc-fns.h>
Arnaud Patard (Rtp)c2932bf2010-10-27 14:40:55 +020029#include <asm/mach-types.h>
Shawn Guoe6a07562013-07-08 21:45:20 +080030#include <asm/hardware/cache-l2x0.h>
Juergen Beiserteea643f2008-07-05 10:02:56 +020031
Shawn Guoe3372472012-09-13 21:01:00 +080032#include "common.h"
Shawn Guo50f2de62012-09-14 14:14:45 +080033#include "hardware.h"
Shawn Guoe3372472012-09-13 21:01:00 +080034
Sascha Hauerbe124c92009-06-04 12:19:02 +020035static void __iomem *wdog_base;
Shawn Guo18cb6802013-05-10 09:13:44 +080036static struct clk *wdog_clk;
Juergen Beiserteea643f2008-07-05 10:02:56 +020037
38/*
39 * Reset the system. It is called by machine_restart().
40 */
Robin Holt7b6d8642013-07-08 16:01:40 -070041void mxc_restart(enum reboot_mode mode, const char *cmd)
Juergen Beiserteea643f2008-07-05 10:02:56 +020042{
Sascha Hauerbe124c92009-06-04 12:19:02 +020043 unsigned int wcr_enable;
44
Alexander Shiyan5a6e1502014-06-13 11:26:13 +040045 if (!wdog_base)
46 goto reset_fallback;
47
Alexander Shiyance8ad882014-06-13 11:26:12 +040048 if (!IS_ERR(wdog_clk))
Shawn Guo18cb6802013-05-10 09:13:44 +080049 clk_enable(wdog_clk);
Juergen Beiserteea643f2008-07-05 10:02:56 +020050
Shawn Guo18cb6802013-05-10 09:13:44 +080051 if (cpu_is_mx1())
52 wcr_enable = (1 << 0);
53 else
Sascha Hauerbe124c92009-06-04 12:19:02 +020054 wcr_enable = (1 << 2);
Juergen Beiserteea643f2008-07-05 10:02:56 +020055
Juergen Beiserteea643f2008-07-05 10:02:56 +020056 /* Assert SRS signal */
Johannes Bergc5531382016-01-27 17:59:35 +010057 imx_writew(wcr_enable, wdog_base);
Shawn Guo2c11b572013-10-31 10:35:40 +080058 /*
59 * Due to imx6q errata ERR004346 (WDOG: WDOG SRS bit requires to be
60 * written twice), we add another two writes to ensure there must be at
61 * least two writes happen in the same one 32kHz clock period. We save
62 * the target check here, since the writes shouldn't be a huge burden
63 * for other platforms.
64 */
Johannes Bergc5531382016-01-27 17:59:35 +010065 imx_writew(wcr_enable, wdog_base);
66 imx_writew(wcr_enable, wdog_base);
Ilya Yanok74bef9a2009-03-03 02:49:23 +030067
68 /* wait for reset to assert... */
69 mdelay(500);
70
Shawn Guo18cb6802013-05-10 09:13:44 +080071 pr_err("%s: Watchdog reset failed to assert reset\n", __func__);
Ilya Yanok74bef9a2009-03-03 02:49:23 +030072
73 /* delay to allow the serial port to show the message */
74 mdelay(50);
75
Alexander Shiyan5a6e1502014-06-13 11:26:13 +040076reset_fallback:
Ilya Yanok74bef9a2009-03-03 02:49:23 +030077 /* we'll take a jump through zero as a poor second */
Russell Kinge879c862011-11-01 13:16:26 +000078 soft_restart(0);
Juergen Beiserteea643f2008-07-05 10:02:56 +020079}
Sascha Hauerbe124c92009-06-04 12:19:02 +020080
Shawn Guo18cb6802013-05-10 09:13:44 +080081void __init mxc_arch_reset_init(void __iomem *base)
Sascha Hauerbe124c92009-06-04 12:19:02 +020082{
83 wdog_base = base;
Shawn Guo18cb6802013-05-10 09:13:44 +080084
85 wdog_clk = clk_get_sys("imx2-wdt.0", NULL);
Alexander Shiyance8ad882014-06-13 11:26:12 +040086 if (IS_ERR(wdog_clk))
Shawn Guo18cb6802013-05-10 09:13:44 +080087 pr_warn("%s: failed to get wdog clock\n", __func__);
Alexander Shiyance8ad882014-06-13 11:26:12 +040088 else
89 clk_prepare(wdog_clk);
Sascha Hauerbe124c92009-06-04 12:19:02 +020090}
Shawn Guoc1e31d12013-05-10 10:19:01 +080091
Shawn Guoe6a07562013-07-08 21:45:20 +080092#ifdef CONFIG_CACHE_L2X0
Vincent Stehlé10eff772013-07-10 11:45:46 +020093void __init imx_init_l2cache(void)
Shawn Guoe6a07562013-07-08 21:45:20 +080094{
95 void __iomem *l2x0_base;
96 struct device_node *np;
97 unsigned int val;
98
99 np = of_find_compatible_node(NULL, NULL, "arm,pl310-cache");
100 if (!np)
101 goto out;
102
103 l2x0_base = of_iomap(np, 0);
104 if (!l2x0_base) {
105 of_node_put(np);
106 goto out;
107 }
108
Dirk Behmebc3d8ed2016-02-19 07:50:12 +0100109 if (readl_relaxed(l2x0_base + L2X0_CTRL) & L2X0_CTRL_EN)
110 goto skip_if_enabled;
111
Shawn Guoe6a07562013-07-08 21:45:20 +0800112 /* Configure the L2 PREFETCH and POWER registers */
Russell King1a5a9542014-03-16 20:52:25 +0000113 val = readl_relaxed(l2x0_base + L310_PREFETCH_CTRL);
Shawn Guoe6a07562013-07-08 21:45:20 +0800114 val |= 0x70800000;
Jason Liu9779f0e2013-09-16 09:29:03 +0800115 /*
116 * The L2 cache controller(PL310) version on the i.MX6D/Q is r3p1-50rel0
117 * The L2 cache controller(PL310) version on the i.MX6DL/SOLO/SL is r3p2
118 * But according to ARM PL310 errata: 752271
119 * ID: 752271: Double linefill feature can cause data corruption
120 * Fault Status: Present in: r3p0, r3p1, r3p1-50rel0. Fixed in r3p2
121 * Workaround: The only workaround to this erratum is to disable the
122 * double linefill feature. This is the default behavior.
123 */
124 if (cpu_is_imx6q())
125 val &= ~(1 << 30 | 1 << 23);
Russell King1a5a9542014-03-16 20:52:25 +0000126 writel_relaxed(val, l2x0_base + L310_PREFETCH_CTRL);
Shawn Guoe6a07562013-07-08 21:45:20 +0800127
Dirk Behmebc3d8ed2016-02-19 07:50:12 +0100128skip_if_enabled:
Shawn Guoe6a07562013-07-08 21:45:20 +0800129 iounmap(l2x0_base);
130 of_node_put(np);
131
132out:
Russell Kingd453ef72014-03-19 12:50:53 +0000133 l2x0_of_init(0, ~0);
Shawn Guoe6a07562013-07-08 21:45:20 +0800134}
135#endif