blob: 6caea3aab3919b35c5d9be7c576c9a55ab725944 [file] [log] [blame]
Andreas Dannenberg694b0522018-08-27 15:57:46 +05301// 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>
Simon Glass61b29b82020-02-03 07:36:15 -070013#include <linux/err.h>
Andreas Dannenberg694b0522018-08-27 15:57:46 +053014#include <linux/soc/ti/ti_sci_protocol.h>
15
16/**
17 * struct ti_sci_sysreset_data - sysreset controller information structure
18 * @sci: TI SCI handle used for communication with system controller
19 */
20struct ti_sci_sysreset_data {
21 const struct ti_sci_handle *sci;
22};
23
24static int ti_sci_sysreset_probe(struct udevice *dev)
25{
26 struct ti_sci_sysreset_data *data = dev_get_priv(dev);
27
28 debug("%s(dev=%p)\n", __func__, dev);
29
30 if (!data)
31 return -ENOMEM;
32
33 /* Store handle for communication with the system controller */
34 data->sci = ti_sci_get_handle(dev);
35 if (IS_ERR(data->sci))
36 return PTR_ERR(data->sci);
37
38 return 0;
39}
40
41static int ti_sci_sysreset_request(struct udevice *dev, enum sysreset_t type)
42{
43 struct ti_sci_sysreset_data *data = dev_get_priv(dev);
44 const struct ti_sci_handle *sci = data->sci;
45 const struct ti_sci_core_ops *cops = &sci->ops.core_ops;
46 int ret;
47
48 debug("%s(dev=%p, type=%d)\n", __func__, dev, type);
49
50 ret = cops->reboot_device(sci);
51 if (ret)
52 dev_err(rst->dev, "%s: reboot_device failed (%d)\n",
53 __func__, ret);
54
55 return ret;
56}
57
58static struct sysreset_ops ti_sci_sysreset_ops = {
59 .request = ti_sci_sysreset_request,
60};
61
62static const struct udevice_id ti_sci_sysreset_of_match[] = {
63 { .compatible = "ti,sci-sysreset", },
64 { /* sentinel */ },
65};
66
67U_BOOT_DRIVER(ti_sci_sysreset) = {
68 .name = "ti-sci-sysreset",
69 .id = UCLASS_SYSRESET,
70 .of_match = ti_sci_sysreset_of_match,
71 .probe = ti_sci_sysreset_probe,
72 .priv_auto_alloc_size = sizeof(struct ti_sci_sysreset_data),
73 .ops = &ti_sci_sysreset_ops,
74};