3 * Texas Instruments Incorporated - http://www.ti.com/
4 * SPDX-License-Identifier: GPL-2.0+
6 #define pr_fmt(fmt) "%s: " fmt, __func__
10 #include <remoteproc.h>
13 * enum sandbox_state - different device states
14 * @sb_booted: Entry condition, just booted
15 * @sb_init: Initialized (basic environment is ready)
16 * @sb_reset: Held in reset (accessible, but not running)
17 * @sb_loaded: Loaded with image (but not running)
18 * @sb_running: Processor is running
29 * struct sandbox_test_devdata - private data per device
30 * @current_state: device current state
32 struct sandbox_test_devdata
{
33 enum sandbox_state current_state
;
37 * sandbox_dev_move_to_state() - statemachine for our dummy device
38 * @dev: device to switch state
39 * @next_state: next proposed state
41 * This tries to follow the following statemachine:
47 * | | | <---------------------+
53 * | | | <----------+ |
57 * | +----v----+ reset | |
59 * | Loaded +-----------+ |
64 * +->| Running | Stop |
65 * Ping +- | +--------------------+
68 * (is_running does not change state)
70 * Return: 0 when valid state transition is seen, else returns -EINVAL
72 static int sandbox_dev_move_to_state(struct udevice
*dev
,
73 enum sandbox_state next_state
)
75 struct sandbox_test_devdata
*ddata
= dev_get_priv(dev
);
77 /* No state transition is OK */
78 if (ddata
->current_state
== next_state
)
81 debug("current_state=%d, next_state=%d\n", ddata
->current_state
,
83 switch (ddata
->current_state
) {
85 if (next_state
== sb_init
)
90 if (next_state
== sb_reset
|| next_state
== sb_loaded
)
95 if (next_state
== sb_loaded
|| next_state
== sb_init
)
100 if (next_state
== sb_reset
|| next_state
== sb_init
||
101 next_state
== sb_running
)
106 if (next_state
== sb_reset
|| next_state
== sb_init
)
113 ddata
->current_state
= next_state
;
118 * sandbox_testproc_probe() - basic probe function
119 * @dev: test proc device that is being probed.
121 * Return: 0 if all went ok, else return appropriate error
123 static int sandbox_testproc_probe(struct udevice
*dev
)
125 struct dm_rproc_uclass_pdata
*uc_pdata
;
126 struct sandbox_test_devdata
*ddata
;
129 uc_pdata
= dev_get_uclass_platdata(dev
);
130 ddata
= dev_get_priv(dev
);
132 debug("%s: platform private data missing\n", uc_pdata
->name
);
135 ret
= sandbox_dev_move_to_state(dev
, sb_booted
);
136 debug("%s: called(%d)\n", uc_pdata
->name
, ret
);
142 * sandbox_testproc_init() - Simple initialization function
143 * @dev: device to operate upon
145 * Return: 0 if all went ok, else return appropriate error
147 static int sandbox_testproc_init(struct udevice
*dev
)
149 struct dm_rproc_uclass_pdata
*uc_pdata
;
152 uc_pdata
= dev_get_uclass_platdata(dev
);
154 ret
= sandbox_dev_move_to_state(dev
, sb_init
);
156 debug("%s: called(%d)\n", uc_pdata
->name
, ret
);
158 debug("%s init failed\n", uc_pdata
->name
);
164 * sandbox_testproc_reset() - Reset the remote processor
165 * @dev: device to operate upon
167 * Return: 0 if all went ok, else return appropriate error
169 static int sandbox_testproc_reset(struct udevice
*dev
)
171 struct dm_rproc_uclass_pdata
*uc_pdata
;
174 uc_pdata
= dev_get_uclass_platdata(dev
);
176 ret
= sandbox_dev_move_to_state(dev
, sb_reset
);
178 debug("%s: called(%d)\n", uc_pdata
->name
, ret
);
181 debug("%s reset failed\n", uc_pdata
->name
);
186 * sandbox_testproc_load() - (replace: short desc)
187 * @dev: device to operate upon
188 * @addr: Address of the binary image to load
189 * @size: Size (in bytes) of the binary image to load
191 * Return: 0 if all went ok, else return appropriate error
193 static int sandbox_testproc_load(struct udevice
*dev
, ulong addr
, ulong size
)
195 struct dm_rproc_uclass_pdata
*uc_pdata
;
198 uc_pdata
= dev_get_uclass_platdata(dev
);
200 ret
= sandbox_dev_move_to_state(dev
, sb_loaded
);
202 debug("%s: called(%d) Loading to %08lX %lu size\n",
203 uc_pdata
->name
, ret
, addr
, size
);
206 debug("%s load failed\n", uc_pdata
->name
);
211 * sandbox_testproc_start() - Start the remote processor
212 * @dev: device to operate upon
214 * Return: 0 if all went ok, else return appropriate error
216 static int sandbox_testproc_start(struct udevice
*dev
)
218 struct dm_rproc_uclass_pdata
*uc_pdata
;
221 uc_pdata
= dev_get_uclass_platdata(dev
);
223 ret
= sandbox_dev_move_to_state(dev
, sb_running
);
225 debug("%s: called(%d)\n", uc_pdata
->name
, ret
);
228 debug("%s start failed\n", uc_pdata
->name
);
233 * sandbox_testproc_stop() - Stop the remote processor
234 * @dev: device to operate upon
236 * Return: 0 if all went ok, else return appropriate error
238 static int sandbox_testproc_stop(struct udevice
*dev
)
240 struct dm_rproc_uclass_pdata
*uc_pdata
;
243 uc_pdata
= dev_get_uclass_platdata(dev
);
245 ret
= sandbox_dev_move_to_state(dev
, sb_init
);
247 debug("%s: called(%d)\n", uc_pdata
->name
, ret
);
250 debug("%s stop failed\n", uc_pdata
->name
);
255 * sandbox_testproc_is_running() - Check if remote processor is running
256 * @dev: device to operate upon
258 * Return: 0 if running, 1 if not running
260 static int sandbox_testproc_is_running(struct udevice
*dev
)
262 struct dm_rproc_uclass_pdata
*uc_pdata
;
263 struct sandbox_test_devdata
*ddata
;
266 uc_pdata
= dev_get_uclass_platdata(dev
);
267 ddata
= dev_get_priv(dev
);
269 if (ddata
->current_state
== sb_running
)
271 debug("%s: called(%d)\n", uc_pdata
->name
, ret
);
277 * sandbox_testproc_ping() - Try pinging remote processor
278 * @dev: device to operate upon
280 * Return: 0 if running, -EINVAL if not running
282 static int sandbox_testproc_ping(struct udevice
*dev
)
284 struct dm_rproc_uclass_pdata
*uc_pdata
;
285 struct sandbox_test_devdata
*ddata
;
288 uc_pdata
= dev_get_uclass_platdata(dev
);
289 ddata
= dev_get_priv(dev
);
291 if (ddata
->current_state
== sb_running
)
296 debug("%s: called(%d)\n", uc_pdata
->name
, ret
);
298 debug("%s: No response.(Not started?)\n", uc_pdata
->name
);
303 static const struct dm_rproc_ops sandbox_testproc_ops
= {
304 .init
= sandbox_testproc_init
,
305 .reset
= sandbox_testproc_reset
,
306 .load
= sandbox_testproc_load
,
307 .start
= sandbox_testproc_start
,
308 .stop
= sandbox_testproc_stop
,
309 .is_running
= sandbox_testproc_is_running
,
310 .ping
= sandbox_testproc_ping
,
313 static const struct udevice_id sandbox_ids
[] = {
314 {.compatible
= "sandbox,test-processor"},
318 U_BOOT_DRIVER(sandbox_testproc
) = {
319 .name
= "sandbox_test_proc",
320 .of_match
= sandbox_ids
,
321 .id
= UCLASS_REMOTEPROC
,
322 .ops
= &sandbox_testproc_ops
,
323 .probe
= sandbox_testproc_probe
,
324 .priv_auto_alloc_size
= sizeof(struct sandbox_test_devdata
),
327 /* TODO(nm@ti.com): Remove this along with non-DT support */
328 static struct dm_rproc_uclass_pdata proc_3_test
= {
329 .name
= "proc_3_legacy",
330 .mem_type
= RPROC_INTERNAL_MEMORY_MAPPED
,
333 U_BOOT_DEVICE(proc_3_demo
) = {
334 .name
= "sandbox_test_proc",
335 .platdata
= &proc_3_test
,