2 * Copyright (c) 2016, NVIDIA CORPORATION.
4 * SPDX-License-Identifier: GPL-2.0
11 #include <reset-uclass.h>
13 DECLARE_GLOBAL_DATA_PTR;
15 static inline struct reset_ops *reset_dev_ops(struct udevice *dev)
17 return (struct reset_ops *)dev->driver->ops;
20 static int reset_of_xlate_default(struct reset_ctl *reset_ctl,
21 struct ofnode_phandle_args *args)
23 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
25 if (args->args_count != 1) {
26 debug("Invaild args_count: %d\n", args->args_count);
30 reset_ctl->id = args->args[0];
35 int reset_get_by_index(struct udevice *dev, int index,
36 struct reset_ctl *reset_ctl)
38 struct ofnode_phandle_args args;
40 struct udevice *dev_reset;
41 struct reset_ops *ops;
43 debug("%s(dev=%p, index=%d, reset_ctl=%p)\n", __func__, dev, index,
46 ret = dev_read_phandle_with_args(dev, "resets", "#reset-cells", 0,
49 debug("%s: fdtdec_parse_phandle_with_args() failed: %d\n",
54 ret = uclass_get_device_by_ofnode(UCLASS_RESET, args.node,
57 debug("%s: uclass_get_device_by_ofnode() failed: %d\n",
59 debug("%s %d\n", ofnode_get_name(args.node), args.args[0]);
62 ops = reset_dev_ops(dev_reset);
64 reset_ctl->dev = dev_reset;
66 ret = ops->of_xlate(reset_ctl, &args);
68 ret = reset_of_xlate_default(reset_ctl, &args);
70 debug("of_xlate() failed: %d\n", ret);
74 ret = ops->request(reset_ctl);
76 debug("ops->request() failed: %d\n", ret);
83 int reset_get_by_name(struct udevice *dev, const char *name,
84 struct reset_ctl *reset_ctl)
88 debug("%s(dev=%p, name=%s, reset_ctl=%p)\n", __func__, dev, name,
91 index = dev_read_stringlist_search(dev, "reset-names", name);
93 debug("fdt_stringlist_search() failed: %d\n", index);
97 return reset_get_by_index(dev, index, reset_ctl);
100 int reset_free(struct reset_ctl *reset_ctl)
102 struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
104 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
106 return ops->free(reset_ctl);
109 int reset_assert(struct reset_ctl *reset_ctl)
111 struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
113 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
115 return ops->rst_assert(reset_ctl);
118 int reset_deassert(struct reset_ctl *reset_ctl)
120 struct reset_ops *ops = reset_dev_ops(reset_ctl->dev);
122 debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
124 return ops->rst_deassert(reset_ctl);
127 UCLASS_DRIVER(reset) = {