9
0
Fork 0

ARM i.MX: move reset source detection code

- for i.MX1 the register is in the System Control unit, so move
  the code to arch/arm/mach-imx/imx1.c
- for the other i.MX the register is in the watchdog unit, so move
  the code to drivers/watchdog/imxwd.c

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2012-10-08 00:01:01 +02:00
parent 90e9f773c1
commit 2155bc5ba8
4 changed files with 61 additions and 73 deletions

View File

@ -1,5 +1,4 @@
obj-y += clocksource.o gpio.o
obj-$(CONFIG_RESET_SOURCE) += reset_source.o
obj-$(CONFIG_ARCH_IMX1) += imx1.o iomux-v1.o clk-imx1.o
obj-$(CONFIG_ARCH_IMX25) += imx25.o iomux-v3.o clk-imx25.o
obj-$(CONFIG_ARCH_IMX21) += imx21.o iomux-v1.o clk-imx21.o

View File

@ -16,6 +16,31 @@
#include <io.h>
#include <mach/imx-regs.h>
#include <mach/weim.h>
#include <reset_source.h>
#define MX1_RSR MX1_SCM_BASE_ADDR
#define RSR_EXR (1 << 0)
#define RSR_WDR (1 << 1)
static void imx1_detect_reset_source(void)
{
u32 val = readl((void *)MX1_RSR) & 0x3;
switch (val) {
case RSR_EXR:
set_reset_source(RESET_RST);
return;
case RSR_WDR:
set_reset_source(RESET_WDG);
return;
case 0:
set_reset_source(RESET_POR);
return;
default:
/* else keep the default 'unknown' state */
return;
}
}
void imx1_setup_eimcs(size_t cs, unsigned upper, unsigned lower)
{
@ -25,6 +50,8 @@ void imx1_setup_eimcs(size_t cs, unsigned upper, unsigned lower)
static int imx1_init(void)
{
imx1_detect_reset_source();
add_generic_device("imx1-ccm", 0, NULL, MX1_CCM_BASE_ADDR, 0x1000, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpt", 0, NULL, MX1_TIM1_BASE_ADDR, 0x100, IORESOURCE_MEM, NULL);
add_generic_device("imx1-gpio", 0, NULL, MX1_GPIO1_BASE_ADDR, 0x100, IORESOURCE_MEM, NULL);

View File

@ -1,72 +0,0 @@
/*
* (C) Copyright 2012 Juergen Beisert - <kernel@pengutronix.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <common.h>
#include <init.h>
#include <io.h>
#include <reset_source.h>
#include <mach/imx-regs.h>
#ifdef CONFIG_ARCH_IMX1
# define IMX_RESET_SRC_WDOG (1 << 1)
# define IMX_RESET_SRC_HRDRESET (1 << 0)
/* let the compiler sort out useless code on this arch */
# define IMX_RESET_SRC_WARMSTART 0
# define IMX_RESET_SRC_COLDSTART 0
#else
/* WRSR checked for i.MX25, i.MX27, i.MX31, i.MX35 and i.MX51 */
# define WDOG_WRSR 0x04
/* valid for i.MX25, i.MX27, i.MX31, i.MX35, i.MX51 */
# define IMX_RESET_SRC_WARMSTART (1 << 0)
/* valid for i.MX25, i.MX27, i.MX31, i.MX35, i.MX51 */
# define IMX_RESET_SRC_WDOG (1 << 1)
/* valid for i.MX27, i.MX31, always '0' on i.MX25, i.MX35, i.MX51 */
# define IMX_RESET_SRC_HRDRESET (1 << 3)
/* valid for i.MX27, i.MX31, always '0' on i.MX25, i.MX35, i.MX51 */
# define IMX_RESET_SRC_COLDSTART (1 << 4)
#endif
static unsigned read_detection_register(void)
{
#ifdef CONFIG_ARCH_IMX1
return readl(IMX_SYSCTRL_BASE);
#else
return readw(IMX_WDT_BASE + WDOG_WRSR);
#endif
}
static int imx_detect_reset_source(void)
{
unsigned reg = read_detection_register();
if (reg & IMX_RESET_SRC_COLDSTART) {
set_reset_source(RESET_POR);
return 0;
}
if (reg & (IMX_RESET_SRC_HRDRESET | IMX_RESET_SRC_WARMSTART)) {
set_reset_source(RESET_RST);
return 0;
}
if (reg & IMX_RESET_SRC_WDOG) {
set_reset_source(RESET_WDG);
return 0;
}
/* else keep the default 'unknown' state */
return 0;
}
device_initcall(imx_detect_reset_source);

View File

@ -42,6 +42,15 @@ struct imx_wd {
#define IMX21_WDOG_WCR_SRS (1 << 4)
#define IMX21_WDOG_WCR_WDA (1 << 5)
/* valid for i.MX25, i.MX27, i.MX31, i.MX35, i.MX51 */
#define WSTR_WARMSTART (1 << 0)
/* valid for i.MX25, i.MX27, i.MX31, i.MX35, i.MX51 */
#define WSTR_WDOG (1 << 1)
/* valid for i.MX27, i.MX31, always '0' on i.MX25, i.MX35, i.MX51 */
#define WSTR_HARDRESET (1 << 3)
/* valid for i.MX27, i.MX31, always '0' on i.MX25, i.MX35, i.MX51 */
#define WSTR_COLDSTART (1 << 4)
static int imx1_watchdog_set_timeout(struct imx_wd *priv, int timeout)
{
u16 val;
@ -115,6 +124,28 @@ void __noreturn reset_cpu(unsigned long addr)
hang();
}
static void imx_watchdog_detect_reset_source(struct imx_wd *priv)
{
u16 val = readw(priv->base + IMX21_WDOG_WSTR);
if (val & WSTR_COLDSTART) {
set_reset_source(RESET_POR);
return;
}
if (val & (WSTR_HARDRESET | WSTR_WARMSTART)) {
set_reset_source(RESET_RST);
return;
}
if (val & WSTR_WDOG) {
set_reset_source(RESET_WDG);
return;
}
/* else keep the default 'unknown' state */
}
static int imx_wd_probe(struct device_d *dev)
{
struct imx_wd *priv;
@ -140,6 +171,9 @@ static int imx_wd_probe(struct device_d *dev)
goto on_error;
}
if (fn != imx1_watchdog_set_timeout)
imx_watchdog_detect_reset_source(priv);
dev->priv = priv;
return 0;