2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-06-23 21:39:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Google, Inc
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*/
|
|
|
|
|
2018-10-01 18:22:45 +00:00
|
|
|
#define LOG_CATEGORY UCLASS_SYSRESET
|
|
|
|
|
2015-06-23 21:39:13 +00:00
|
|
|
#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);
|
|
|
|
}
|
|
|
|
|
2018-08-06 08:23:32 +00:00
|
|
|
int sysreset_get_status(struct udevice *dev, char *buf, int size)
|
|
|
|
{
|
|
|
|
struct sysreset_ops *ops = sysreset_get_ops(dev);
|
|
|
|
|
|
|
|
if (!ops->get_status)
|
|
|
|
return -ENOSYS;
|
|
|
|
|
|
|
|
return ops->get_status(dev, buf, size);
|
|
|
|
}
|
|
|
|
|
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 */
|
2018-10-01 18:22:45 +00:00
|
|
|
log_err("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[])
|
|
|
|
{
|
2018-07-19 10:07:31 +00:00
|
|
|
printf("resetting ...\n");
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-07-12 08:36:07 +00: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-12 18:03:35 +00:00
|
|
|
UCLASS_DRIVER(sysreset) = {
|
|
|
|
.id = UCLASS_SYSRESET,
|
|
|
|
.name = "sysreset",
|
2018-07-12 08:36:07 +00:00
|
|
|
.post_bind = sysreset_post_bind,
|
2015-06-23 21:39:13 +00:00
|
|
|
};
|