• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Texas Instruments System Control Interface (TI SCI) system reset driver
4  *
5  * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
6  *	Andreas Dannenberg <dannenberg@ti.com>
7  */
8 
9 #include <common.h>
10 #include <dm.h>
11 #include <errno.h>
12 #include <sysreset.h>
13 #include <linux/soc/ti/ti_sci_protocol.h>
14 
15 /**
16  * struct ti_sci_sysreset_data - sysreset controller information structure
17  * @sci: TI SCI handle used for communication with system controller
18  */
19 struct ti_sci_sysreset_data {
20 	const struct ti_sci_handle *sci;
21 };
22 
ti_sci_sysreset_probe(struct udevice * dev)23 static int ti_sci_sysreset_probe(struct udevice *dev)
24 {
25 	struct ti_sci_sysreset_data *data = dev_get_priv(dev);
26 
27 	debug("%s(dev=%p)\n", __func__, dev);
28 
29 	if (!data)
30 		return -ENOMEM;
31 
32 	/* Store handle for communication with the system controller */
33 	data->sci = ti_sci_get_handle(dev);
34 	if (IS_ERR(data->sci))
35 		return PTR_ERR(data->sci);
36 
37 	return 0;
38 }
39 
ti_sci_sysreset_request(struct udevice * dev,enum sysreset_t type)40 static int ti_sci_sysreset_request(struct udevice *dev, enum sysreset_t type)
41 {
42 	struct ti_sci_sysreset_data *data = dev_get_priv(dev);
43 	const struct ti_sci_handle *sci = data->sci;
44 	const struct ti_sci_core_ops *cops = &sci->ops.core_ops;
45 	int ret;
46 
47 	debug("%s(dev=%p, type=%d)\n", __func__, dev, type);
48 
49 	ret = cops->reboot_device(sci);
50 	if (ret)
51 		dev_err(rst->dev, "%s: reboot_device failed (%d)\n",
52 			__func__, ret);
53 
54 	return ret;
55 }
56 
57 static struct sysreset_ops ti_sci_sysreset_ops = {
58 	.request = ti_sci_sysreset_request,
59 };
60 
61 static const struct udevice_id ti_sci_sysreset_of_match[] = {
62 	{ .compatible = "ti,sci-sysreset", },
63 	{ /* sentinel */ },
64 };
65 
66 U_BOOT_DRIVER(ti_sci_sysreset) = {
67 	.name = "ti-sci-sysreset",
68 	.id = UCLASS_SYSRESET,
69 	.of_match = ti_sci_sysreset_of_match,
70 	.probe = ti_sci_sysreset_probe,
71 	.priv_auto_alloc_size = sizeof(struct ti_sci_sysreset_data),
72 	.ops = &ti_sci_sysreset_ops,
73 };
74