Andreas Dannenberg | ebc6879 | 2018-08-27 15:57:46 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Texas Instruments System Control Interface (TI SCI) system reset driver |
| 4 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 5 | * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/ |
Andreas Dannenberg | ebc6879 | 2018-08-27 15:57:46 +0530 | [diff] [blame] | 6 | * Andreas Dannenberg <dannenberg@ti.com> |
| 7 | */ |
| 8 | |
Andreas Dannenberg | ebc6879 | 2018-08-27 15:57:46 +0530 | [diff] [blame] | 9 | #include <dm.h> |
| 10 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Andreas Dannenberg | ebc6879 | 2018-08-27 15:57:46 +0530 | [diff] [blame] | 12 | #include <sysreset.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 13 | #include <dm/device_compat.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 14 | #include <linux/err.h> |
Andreas Dannenberg | ebc6879 | 2018-08-27 15:57:46 +0530 | [diff] [blame] | 15 | #include <linux/soc/ti/ti_sci_protocol.h> |
| 16 | |
| 17 | /** |
| 18 | * struct ti_sci_sysreset_data - sysreset controller information structure |
| 19 | * @sci: TI SCI handle used for communication with system controller |
| 20 | */ |
| 21 | struct ti_sci_sysreset_data { |
| 22 | const struct ti_sci_handle *sci; |
| 23 | }; |
| 24 | |
| 25 | static int ti_sci_sysreset_probe(struct udevice *dev) |
| 26 | { |
| 27 | struct ti_sci_sysreset_data *data = dev_get_priv(dev); |
| 28 | |
| 29 | debug("%s(dev=%p)\n", __func__, dev); |
| 30 | |
| 31 | if (!data) |
| 32 | return -ENOMEM; |
| 33 | |
| 34 | /* Store handle for communication with the system controller */ |
| 35 | data->sci = ti_sci_get_handle(dev); |
| 36 | if (IS_ERR(data->sci)) |
| 37 | return PTR_ERR(data->sci); |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | static int ti_sci_sysreset_request(struct udevice *dev, enum sysreset_t type) |
| 43 | { |
| 44 | struct ti_sci_sysreset_data *data = dev_get_priv(dev); |
| 45 | const struct ti_sci_handle *sci = data->sci; |
| 46 | const struct ti_sci_core_ops *cops = &sci->ops.core_ops; |
| 47 | int ret; |
| 48 | |
| 49 | debug("%s(dev=%p, type=%d)\n", __func__, dev, type); |
| 50 | |
| 51 | ret = cops->reboot_device(sci); |
| 52 | if (ret) |
Sean Anderson | ada921f | 2020-09-15 10:45:13 -0400 | [diff] [blame] | 53 | dev_err(dev, "%s: reboot_device failed (%d)\n", __func__, ret); |
Andreas Dannenberg | ebc6879 | 2018-08-27 15:57:46 +0530 | [diff] [blame] | 54 | |
| 55 | return ret; |
| 56 | } |
| 57 | |
| 58 | static struct sysreset_ops ti_sci_sysreset_ops = { |
| 59 | .request = ti_sci_sysreset_request, |
| 60 | }; |
| 61 | |
Andreas Dannenberg | ebc6879 | 2018-08-27 15:57:46 +0530 | [diff] [blame] | 62 | U_BOOT_DRIVER(ti_sci_sysreset) = { |
| 63 | .name = "ti-sci-sysreset", |
| 64 | .id = UCLASS_SYSRESET, |
Andreas Dannenberg | ebc6879 | 2018-08-27 15:57:46 +0530 | [diff] [blame] | 65 | .probe = ti_sci_sysreset_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 66 | .priv_auto = sizeof(struct ti_sci_sysreset_data), |
Andreas Dannenberg | ebc6879 | 2018-08-27 15:57:46 +0530 | [diff] [blame] | 67 | .ops = &ti_sci_sysreset_ops, |
| 68 | }; |