Andreas Dannenberg | 694b052 | 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 | * |
| 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> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Andreas Dannenberg | 694b052 | 2018-08-27 15:57:46 +0530 | [diff] [blame] | 13 | #include <sysreset.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 14 | #include <dm/device_compat.h> |
Simon Glass | 61b29b8 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 15 | #include <linux/err.h> |
Andreas Dannenberg | 694b052 | 2018-08-27 15:57:46 +0530 | [diff] [blame] | 16 | #include <linux/soc/ti/ti_sci_protocol.h> |
| 17 | |
| 18 | /** |
| 19 | * struct ti_sci_sysreset_data - sysreset controller information structure |
| 20 | * @sci: TI SCI handle used for communication with system controller |
| 21 | */ |
| 22 | struct ti_sci_sysreset_data { |
| 23 | const struct ti_sci_handle *sci; |
| 24 | }; |
| 25 | |
| 26 | static int ti_sci_sysreset_probe(struct udevice *dev) |
| 27 | { |
| 28 | struct ti_sci_sysreset_data *data = dev_get_priv(dev); |
| 29 | |
| 30 | debug("%s(dev=%p)\n", __func__, dev); |
| 31 | |
| 32 | if (!data) |
| 33 | return -ENOMEM; |
| 34 | |
| 35 | /* Store handle for communication with the system controller */ |
| 36 | data->sci = ti_sci_get_handle(dev); |
| 37 | if (IS_ERR(data->sci)) |
| 38 | return PTR_ERR(data->sci); |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static int ti_sci_sysreset_request(struct udevice *dev, enum sysreset_t type) |
| 44 | { |
| 45 | struct ti_sci_sysreset_data *data = dev_get_priv(dev); |
| 46 | const struct ti_sci_handle *sci = data->sci; |
| 47 | const struct ti_sci_core_ops *cops = &sci->ops.core_ops; |
| 48 | int ret; |
| 49 | |
| 50 | debug("%s(dev=%p, type=%d)\n", __func__, dev, type); |
| 51 | |
| 52 | ret = cops->reboot_device(sci); |
| 53 | if (ret) |
Sean Anderson | 9c61028 | 2020-09-15 10:45:13 -0400 | [diff] [blame] | 54 | dev_err(dev, "%s: reboot_device failed (%d)\n", __func__, ret); |
Andreas Dannenberg | 694b052 | 2018-08-27 15:57:46 +0530 | [diff] [blame] | 55 | |
| 56 | return ret; |
| 57 | } |
| 58 | |
| 59 | static struct sysreset_ops ti_sci_sysreset_ops = { |
| 60 | .request = ti_sci_sysreset_request, |
| 61 | }; |
| 62 | |
| 63 | static const struct udevice_id ti_sci_sysreset_of_match[] = { |
| 64 | { .compatible = "ti,sci-sysreset", }, |
| 65 | { /* sentinel */ }, |
| 66 | }; |
| 67 | |
| 68 | U_BOOT_DRIVER(ti_sci_sysreset) = { |
| 69 | .name = "ti-sci-sysreset", |
| 70 | .id = UCLASS_SYSRESET, |
| 71 | .of_match = ti_sci_sysreset_of_match, |
| 72 | .probe = ti_sci_sysreset_probe, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 73 | .priv_auto = sizeof(struct ti_sci_sysreset_data), |
Andreas Dannenberg | 694b052 | 2018-08-27 15:57:46 +0530 | [diff] [blame] | 74 | .ops = &ti_sci_sysreset_ops, |
| 75 | }; |