blob: ba277570c56731f001e2576a314e725e1c0e636c [file] [log] [blame]
Simon Glassf9917452015-06-23 15:39:13 -06001/*
2 * Copyright (C) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <reset.h>
10#include <dm.h>
11#include <errno.h>
12#include <regmap.h>
13#include <dm/device-internal.h>
14#include <dm/lists.h>
15#include <dm/root.h>
16#include <linux/err.h>
17
18int reset_request(struct udevice *dev, enum reset_t type)
19{
20 struct reset_ops *ops = reset_get_ops(dev);
21
22 if (!ops->request)
23 return -ENOSYS;
24
25 return ops->request(dev, type);
26}
27
28void reset_walk(enum reset_t type)
29{
30 struct udevice *dev;
31 int ret = 0;
32
33 while (ret != -EINPROGRESS && type < RESET_COUNT) {
34 for (uclass_first_device(UCLASS_RESET, &dev);
35 dev;
36 uclass_next_device(&dev)) {
37 ret = reset_request(dev, type);
38 if (ret == -EINPROGRESS)
39 break;
40 }
41 }
42
43 /* Wait for the reset to take effect */
44 mdelay(100);
45
46 /* Still no reset? Give up */
47 printf("Reset not supported on this platform\n");
48 hang();
49}
50
51/**
52 * reset_cpu() - calls reset_walk(RESET_WARM)
53 */
54void reset_cpu(ulong addr)
55{
56 reset_walk(RESET_WARM);
57}
58
59UCLASS_DRIVER(reset) = {
60 .id = UCLASS_RESET,
61 .name = "reset",
62};