2015-06-23 21:39:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Google, Inc
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2016-05-12 18:03:35 +00:00
|
|
|
#include <sysreset.h>
|
2015-06-23 21:39:13 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <regmap.h>
|
|
|
|
#include <dm/device-internal.h>
|
|
|
|
#include <dm/lists.h>
|
|
|
|
#include <dm/root.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
|
2016-05-12 18:03:35 +00:00
|
|
|
int sysreset_request(struct udevice *dev, enum sysreset_t type)
|
2015-06-23 21:39:13 +00:00
|
|
|
{
|
2016-05-12 18:03:35 +00:00
|
|
|
struct sysreset_ops *ops = sysreset_get_ops(dev);
|
2015-06-23 21:39:13 +00:00
|
|
|
|
|
|
|
if (!ops->request)
|
|
|
|
return -ENOSYS;
|
|
|
|
|
|
|
|
return ops->request(dev, type);
|
|
|
|
}
|
|
|
|
|
2016-05-12 18:03:35 +00:00
|
|
|
int sysreset_walk(enum sysreset_t type)
|
2015-06-23 21:39:13 +00:00
|
|
|
{
|
|
|
|
struct udevice *dev;
|
2015-07-06 18:54:27 +00:00
|
|
|
int ret = -ENOSYS;
|
2015-06-23 21:39:13 +00:00
|
|
|
|
2016-05-12 18:03:35 +00:00
|
|
|
while (ret != -EINPROGRESS && type < SYSRESET_COUNT) {
|
|
|
|
for (uclass_first_device(UCLASS_SYSRESET, &dev);
|
2015-07-06 18:54:27 +00:00
|
|
|
dev;
|
|
|
|
uclass_next_device(&dev)) {
|
2016-05-12 18:03:35 +00:00
|
|
|
ret = sysreset_request(dev, type);
|
2015-06-23 21:39:13 +00:00
|
|
|
if (ret == -EINPROGRESS)
|
|
|
|
break;
|
|
|
|
}
|
2015-07-06 18:54:27 +00:00
|
|
|
type++;
|
2015-06-23 21:39:13 +00:00
|
|
|
}
|
|
|
|
|
2015-07-06 18:54:27 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-05-12 18:03:35 +00:00
|
|
|
void sysreset_walk_halt(enum sysreset_t type)
|
2015-07-06 18:54:27 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2016-05-12 18:03:35 +00:00
|
|
|
ret = sysreset_walk(type);
|
2015-07-06 18:54:27 +00:00
|
|
|
|
2015-06-23 21:39:13 +00:00
|
|
|
/* Wait for the reset to take effect */
|
2015-07-06 18:54:27 +00:00
|
|
|
if (ret == -EINPROGRESS)
|
|
|
|
mdelay(100);
|
2015-06-23 21:39:13 +00:00
|
|
|
|
|
|
|
/* Still no reset? Give up */
|
2016-05-14 20:02:54 +00:00
|
|
|
debug("System reset not supported on this platform\n");
|
2015-06-23 21:39:13 +00:00
|
|
|
hang();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-05-12 18:03:35 +00:00
|
|
|
* reset_cpu() - calls sysreset_walk(SYSRESET_WARM)
|
2015-06-23 21:39:13 +00:00
|
|
|
*/
|
|
|
|
void reset_cpu(ulong addr)
|
|
|
|
{
|
2016-05-12 18:03:35 +00:00
|
|
|
sysreset_walk_halt(SYSRESET_WARM);
|
2015-07-06 18:54:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|
|
|
{
|
2017-11-24 17:37:58 +00:00
|
|
|
sysreset_walk_halt(SYSRESET_COLD);
|
2015-07-06 18:54:27 +00:00
|
|
|
|
|
|
|
return 0;
|
2015-06-23 21:39:13 +00:00
|
|
|
}
|
|
|
|
|
2016-05-12 18:03:35 +00:00
|
|
|
UCLASS_DRIVER(sysreset) = {
|
|
|
|
.id = UCLASS_SYSRESET,
|
|
|
|
.name = "sysreset",
|
2015-06-23 21:39:13 +00:00
|
|
|
};
|