blob: d0336a1ce559291b0baffb00c7fd501e0483a6c8 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
maxims@google.com4697abe2017-01-18 13:44:55 -08002/*
3 * (C) Copyright 2016 Google, Inc
maxims@google.com4697abe2017-01-18 13:44:55 -08004 */
5
6#include <common.h>
7#include <dm.h>
8#include <errno.h>
9#include <sysreset.h>
maxims@google.com99f8ad72017-04-17 12:00:26 -070010#include <wdt.h>
maxims@google.com4697abe2017-01-18 13:44:55 -080011#include <asm/io.h>
12#include <asm/arch/wdt.h>
13#include <linux/err.h>
14
maxims@google.com4697abe2017-01-18 13:44:55 -080015static int ast_sysreset_request(struct udevice *dev, enum sysreset_t type)
16{
maxims@google.com99f8ad72017-04-17 12:00:26 -070017 struct udevice *wdt;
18 u32 reset_mode;
19 int ret = uclass_first_device(UCLASS_WDT, &wdt);
maxims@google.com4697abe2017-01-18 13:44:55 -080020
maxims@google.com99f8ad72017-04-17 12:00:26 -070021 if (ret)
22 return ret;
maxims@google.com4697abe2017-01-18 13:44:55 -080023
24 switch (type) {
25 case SYSRESET_WARM:
26 reset_mode = WDT_CTRL_RESET_CPU;
27 break;
28 case SYSRESET_COLD:
29 reset_mode = WDT_CTRL_RESET_CHIP;
30 break;
31 default:
32 return -EPROTONOSUPPORT;
33 }
34
maxims@google.com99f8ad72017-04-17 12:00:26 -070035 ret = wdt_expire_now(wdt, reset_mode);
36 if (ret) {
37 debug("Sysreset failed: %d", ret);
38 return ret;
39 }
maxims@google.com4697abe2017-01-18 13:44:55 -080040
41 return -EINPROGRESS;
42}
43
44static struct sysreset_ops ast_sysreset = {
45 .request = ast_sysreset_request,
46};
47
48U_BOOT_DRIVER(sysreset_ast) = {
49 .name = "ast_sysreset",
50 .id = UCLASS_SYSRESET,
51 .ops = &ast_sysreset,
52};