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