Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openbmc/wdt #5

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 24 additions & 20 deletions drivers/watchdog/aspeed_wdt.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,33 @@ static const struct of_device_id aspeed_wdt_of_table[] = {
};
MODULE_DEVICE_TABLE(of, aspeed_wdt_of_table);

#define WDT_STATUS 0x00
#define WDT_BITE_COUNT 0x04
#define WDT_RELOAD 0x08
#define WDT_CTRL 0x0C
#define WDT_STATUS 0x00
#define WDT_RELOAD_VALUE 0x04
#define WDT_RESTART 0x08
#define WDT_CTRL 0x0C
#define WDT_CTRL_RESET_MODE_FULL_CHIP (0x01 << 5)
#define WDT_CTRL_RESET_SYSTEM (0x1 << 1)
#define WDT_CTRL_ENABLE (0x1 << 0)

#define WDT_RELOAD_MAGIC 0x4755
#define WDT_RESTART_MAGIC 0x4755

static int aspeed_wdt_start(struct watchdog_device *wdd)
static void aspeed_wdt_enable(struct aspeed_wdt *wdt, int count)
{
struct aspeed_wdt *wdt = container_of(wdd, struct aspeed_wdt, wdd);
u32 ctrl = WDT_CTRL_RESET_MODE_FULL_CHIP | WDT_CTRL_RESET_SYSTEM |
WDT_CTRL_ENABLE;

writel(0, wdt->base + WDT_CTRL);
writel(wdd->timeout * wdt->rate, wdt->base + WDT_BITE_COUNT);
writel(WDT_RELOAD_MAGIC, wdt->base + WDT_RELOAD);
writel(3, wdt->base + WDT_CTRL);
writel(count, wdt->base + WDT_RELOAD_VALUE);
writel(WDT_RESTART_MAGIC, wdt->base + WDT_RESTART);
writel(ctrl, wdt->base + WDT_CTRL);
}

static int aspeed_wdt_start(struct watchdog_device *wdd)
{
struct aspeed_wdt *wdt = container_of(wdd, struct aspeed_wdt, wdd);
dev_dbg(wdd->dev, "starting with timeout of %d (rate %lu)\n",
wdd->timeout, wdt->rate);

aspeed_wdt_enable(wdt, wdd->timeout * wdt->rate);
return 0;
}

Expand All @@ -68,7 +76,7 @@ static int aspeed_wdt_ping(struct watchdog_device *wdd)
struct aspeed_wdt *wdt = container_of(wdd, struct aspeed_wdt, wdd);

dev_dbg(wdd->dev, "ping\n");
writel(WDT_RELOAD_MAGIC, wdt->base + WDT_RELOAD);
writel(WDT_RESTART_MAGIC, wdt->base + WDT_RESTART);
return 0;
}

Expand All @@ -83,19 +91,15 @@ static int aspeed_wdt_set_timeout(struct watchdog_device *wdd,
static int aspeed_wdt_restart(struct notifier_block *nb, unsigned long action,
void *data)
{
struct aspeed_wdt *wdt = container_of(nb, struct aspeed_wdt, restart_nb);
u32 timeout;
struct aspeed_wdt *wdt = container_of(nb,
struct aspeed_wdt, restart_nb);

/*
* Trigger watchdog bite:
* Setup BITE_TIME to be 128ms, and enable WDT.
* Setup reload count to be 128ms, and enable WDT.
*/
timeout = 128 * wdt->rate / 1000;
aspeed_wdt_enable(wdt, 128 * wdt->rate / 1000);

writel(0, wdt->base + WDT_CTRL);
writel(timeout, wdt->base + WDT_BITE_COUNT);
writel(WDT_RELOAD_MAGIC, wdt->base + WDT_RELOAD);
writel(3, wdt->base + WDT_CTRL);
return NOTIFY_DONE;
}

Expand Down