1 // SPDX-License-Identifier: GPL-2.0+
3 * Texas Instruments System Control Interface (TI SCI) reset driver
5 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
6 * Andreas Dannenberg <dannenberg@ti.com>
8 * Loosely based on Linux kernel reset-ti-sci.c...
16 #include <reset-uclass.h>
17 #include <dm/device_compat.h>
18 #include <linux/err.h>
19 #include <linux/soc/ti/ti_sci_protocol.h>
22 * struct ti_sci_reset_data - reset controller information structure
23 * @sci: TI SCI handle used for communication with system controller
25 struct ti_sci_reset_data {
26 const struct ti_sci_handle *sci;
29 static int ti_sci_reset_probe(struct udevice *dev)
31 struct ti_sci_reset_data *data = dev_get_priv(dev);
33 debug("%s(dev=%p)\n", __func__, dev);
38 /* Store handle for communication with the system controller */
39 data->sci = ti_sci_get_handle(dev);
40 if (IS_ERR(data->sci))
41 return PTR_ERR(data->sci);
46 static int ti_sci_reset_of_xlate(struct reset_ctl *rst,
47 struct ofnode_phandle_args *args)
49 debug("%s(rst=%p, args_count=%d)\n", __func__, rst, args->args_count);
51 if (args->args_count != 2) {
52 debug("Invalid args_count: %d\n", args->args_count);
57 * On TI SCI-based devices, the reset provider id field is used as a
58 * device ID, and the data field is used as the associated reset mask.
60 rst->id = args->args[0];
61 rst->data = args->args[1];
67 * ti_sci_reset_set() - program a device's reset
68 * @rst: Handle to a single reset signal
69 * @assert: boolean flag to indicate assert or deassert
71 * This is a common internal function used to assert or deassert a device's
72 * reset using the TI SCI protocol. The device's reset is asserted if the
73 * @assert argument is true, or deasserted if @assert argument is false.
74 * The mechanism itself is a read-modify-write procedure, the current device
75 * reset register is read using a TI SCI device operation, the new value is
76 * set or un-set using the reset's mask, and the new reset value written by
77 * using another TI SCI device operation.
79 * Return: 0 for successful request, else a corresponding error value
81 static int ti_sci_reset_set(struct reset_ctl *rst, bool assert)
83 struct ti_sci_reset_data *data = dev_get_priv(rst->dev);
84 const struct ti_sci_handle *sci = data->sci;
85 const struct ti_sci_dev_ops *dops = &sci->ops.dev_ops;
89 ret = dops->get_device_resets(sci, rst->id, &reset_state);
91 dev_err(rst->dev, "%s: get_device_resets failed (%d)\n",
97 reset_state |= rst->data;
99 reset_state &= ~rst->data;
101 ret = dops->set_device_resets(sci, rst->id, reset_state);
103 dev_err(rst->dev, "%s: set_device_resets failed (%d)\n",
112 * ti_sci_reset_assert() - assert device reset
113 * @rst: Handle to a single reset signal
115 * This function implements the reset driver op to assert a device's reset
116 * using the TI SCI protocol. This invokes the function ti_sci_reset_set()
117 * with the corresponding parameters as passed in, but with the @assert
118 * argument set to true for asserting the reset.
120 * Return: 0 for successful request, else a corresponding error value
122 static int ti_sci_reset_assert(struct reset_ctl *rst)
124 debug("%s(rst=%p)\n", __func__, rst);
125 return ti_sci_reset_set(rst, true);
129 * ti_sci_reset_deassert() - deassert device reset
130 * @rst: Handle to a single reset signal
132 * This function implements the reset driver op to deassert a device's reset
133 * using the TI SCI protocol. This invokes the function ti_sci_reset_set()
134 * with the corresponding parameters as passed in, but with the @assert
135 * argument set to false for deasserting the reset.
137 * Return: 0 for successful request, else a corresponding error value
139 static int ti_sci_reset_deassert(struct reset_ctl *rst)
141 debug("%s(rst=%p)\n", __func__, rst);
142 return ti_sci_reset_set(rst, false);
146 * ti_sci_reset_status() - check device reset status
147 * @rst: Handle to a single reset signal
149 * This function implements the reset driver op to return the status of a
150 * device's reset using the TI SCI protocol. The reset register value is read
151 * by invoking the TI SCI device operation .get_device_resets(), and the
152 * status of the specific reset is extracted and returned using this reset's
155 * Return: 0 if reset is deasserted, or a non-zero value if reset is asserted
157 static int ti_sci_reset_status(struct reset_ctl *rst)
159 struct ti_sci_reset_data *data = dev_get_priv(rst->dev);
160 const struct ti_sci_handle *sci = data->sci;
161 const struct ti_sci_dev_ops *dops = &sci->ops.dev_ops;
165 debug("%s(rst=%p)\n", __func__, rst);
167 ret = dops->get_device_resets(sci, rst->id, &reset_state);
169 dev_err(rst->dev, "%s: get_device_resets failed (%d)\n",
174 return reset_state & rst->data;
177 static const struct udevice_id ti_sci_reset_of_match[] = {
178 { .compatible = "ti,sci-reset", },
182 static struct reset_ops ti_sci_reset_ops = {
183 .of_xlate = ti_sci_reset_of_xlate,
184 .rst_assert = ti_sci_reset_assert,
185 .rst_deassert = ti_sci_reset_deassert,
186 .rst_status = ti_sci_reset_status,
189 U_BOOT_DRIVER(ti_sci_reset) = {
190 .name = "ti-sci-reset",
192 .of_match = ti_sci_reset_of_match,
193 .probe = ti_sci_reset_probe,
194 .priv_auto = sizeof(struct ti_sci_reset_data),
195 .ops = &ti_sci_reset_ops,