Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 3 | * Texas Instruments' K3 ARM64 Remoteproc driver |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 4 | * |
| 5 | * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/ |
| 6 | * Lokesh Vutla <lokeshvutla@ti.com> |
| 7 | * |
| 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <dm.h> |
| 12 | #include <remoteproc.h> |
| 13 | #include <errno.h> |
| 14 | #include <clk.h> |
| 15 | #include <reset.h> |
| 16 | #include <asm/io.h> |
| 17 | #include <power-domain.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 18 | #include <dm/device_compat.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 19 | #include <linux/err.h> |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 20 | #include <linux/soc/ti/ti_sci_protocol.h> |
Lokesh Vutla | 142611f | 2019-06-07 19:25:58 +0530 | [diff] [blame] | 21 | #include "ti_sci_proc.h" |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 22 | |
| 23 | #define INVALID_ID 0xffff |
| 24 | |
| 25 | #define GTC_CNTCR_REG 0x0 |
| 26 | #define GTC_CNTR_EN 0x3 |
| 27 | |
| 28 | /** |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 29 | * struct k3_arm64_privdata - Structure representing Remote processor data. |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 30 | * @rproc_pwrdmn: rproc power domain data |
| 31 | * @rproc_rst: rproc reset control data |
| 32 | * @sci: Pointer to TISCI handle |
Lokesh Vutla | 142611f | 2019-06-07 19:25:58 +0530 | [diff] [blame] | 33 | * @tsp: TISCI processor control helper structure |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 34 | * @gtc_base: Timer base address. |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 35 | */ |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 36 | struct k3_arm64_privdata { |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 37 | struct power_domain rproc_pwrdmn; |
| 38 | struct power_domain gtc_pwrdmn; |
| 39 | struct reset_ctl rproc_rst; |
Lokesh Vutla | 142611f | 2019-06-07 19:25:58 +0530 | [diff] [blame] | 40 | struct ti_sci_proc tsp; |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 41 | void *gtc_base; |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | /** |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 45 | * k3_arm64_load() - Load up the Remote processor image |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 46 | * @dev: rproc device pointer |
| 47 | * @addr: Address at which image is available |
| 48 | * @size: size of the image |
| 49 | * |
| 50 | * Return: 0 if all goes good, else appropriate error message. |
| 51 | */ |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 52 | static int k3_arm64_load(struct udevice *dev, ulong addr, ulong size) |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 53 | { |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 54 | struct k3_arm64_privdata *rproc = dev_get_priv(dev); |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 55 | int ret; |
| 56 | |
| 57 | dev_dbg(dev, "%s addr = 0x%lx, size = 0x%lx\n", __func__, addr, size); |
| 58 | |
| 59 | /* request for the processor */ |
Lokesh Vutla | 142611f | 2019-06-07 19:25:58 +0530 | [diff] [blame] | 60 | ret = ti_sci_proc_request(&rproc->tsp); |
| 61 | if (ret) |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 62 | return ret; |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 63 | |
Lokesh Vutla | 142611f | 2019-06-07 19:25:58 +0530 | [diff] [blame] | 64 | return ti_sci_proc_set_config(&rproc->tsp, addr, 0, 0); |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | /** |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 68 | * k3_arm64_start() - Start the remote processor |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 69 | * @dev: rproc device pointer |
| 70 | * |
| 71 | * Return: 0 if all went ok, else return appropriate error |
| 72 | */ |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 73 | static int k3_arm64_start(struct udevice *dev) |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 74 | { |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 75 | struct k3_arm64_privdata *rproc = dev_get_priv(dev); |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 76 | int ret; |
| 77 | |
| 78 | dev_dbg(dev, "%s\n", __func__); |
| 79 | |
| 80 | ret = power_domain_on(&rproc->gtc_pwrdmn); |
| 81 | if (ret) { |
| 82 | dev_err(dev, "power_domain_on() failed: %d\n", ret); |
| 83 | return ret; |
| 84 | } |
| 85 | |
| 86 | /* Enable the timer before starting remote core */ |
| 87 | writel(GTC_CNTR_EN, rproc->gtc_base + GTC_CNTCR_REG); |
| 88 | |
| 89 | /* |
| 90 | * Setting the right clock frequency would have taken care by |
| 91 | * assigned-clock-rates during the device probe. So no need to |
| 92 | * set the frequency again here. |
| 93 | */ |
| 94 | ret = power_domain_on(&rproc->rproc_pwrdmn); |
| 95 | if (ret) { |
| 96 | dev_err(dev, "power_domain_on() failed: %d\n", ret); |
| 97 | return ret; |
| 98 | } |
| 99 | |
Lokesh Vutla | 142611f | 2019-06-07 19:25:58 +0530 | [diff] [blame] | 100 | return ti_sci_proc_release(&rproc->tsp); |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /** |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 104 | * k3_arm64_init() - Initialize the remote processor |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 105 | * @dev: rproc device pointer |
| 106 | * |
| 107 | * Return: 0 if all went ok, else return appropriate error |
| 108 | */ |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 109 | static int k3_arm64_init(struct udevice *dev) |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 110 | { |
| 111 | dev_dbg(dev, "%s\n", __func__); |
| 112 | |
| 113 | /* Enable the module */ |
| 114 | dev_dbg(dev, "%s: rproc successfully initialized\n", __func__); |
| 115 | |
| 116 | return 0; |
| 117 | } |
| 118 | |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 119 | static const struct dm_rproc_ops k3_arm64_ops = { |
| 120 | .init = k3_arm64_init, |
| 121 | .load = k3_arm64_load, |
| 122 | .start = k3_arm64_start, |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 123 | }; |
| 124 | |
Lokesh Vutla | 142611f | 2019-06-07 19:25:58 +0530 | [diff] [blame] | 125 | static int ti_sci_proc_of_to_priv(struct udevice *dev, struct ti_sci_proc *tsp) |
| 126 | { |
| 127 | dev_dbg(dev, "%s\n", __func__); |
| 128 | |
| 129 | tsp->sci = ti_sci_get_by_phandle(dev, "ti,sci"); |
| 130 | if (IS_ERR(tsp->sci)) { |
| 131 | dev_err(dev, "ti_sci get failed: %ld\n", PTR_ERR(tsp->sci)); |
| 132 | return PTR_ERR(tsp->sci); |
| 133 | } |
| 134 | |
| 135 | tsp->proc_id = dev_read_u32_default(dev, "ti,sci-proc-id", INVALID_ID); |
| 136 | if (tsp->proc_id == INVALID_ID) { |
| 137 | dev_err(dev, "proc id not populated\n"); |
| 138 | return -ENOENT; |
| 139 | } |
| 140 | tsp->host_id = dev_read_u32_default(dev, "ti,sci-host-id", INVALID_ID); |
| 141 | tsp->ops = &tsp->sci->ops.proc_ops; |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 146 | /** |
| 147 | * k3_of_to_priv() - generate private data from device tree |
| 148 | * @dev: corresponding k3 remote processor device |
| 149 | * @priv: pointer to driver specific private data |
| 150 | * |
| 151 | * Return: 0 if all goes good, else appropriate error message. |
| 152 | */ |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 153 | static int k3_arm64_of_to_priv(struct udevice *dev, |
| 154 | struct k3_arm64_privdata *rproc) |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 155 | { |
| 156 | int ret; |
| 157 | |
| 158 | dev_dbg(dev, "%s\n", __func__); |
| 159 | |
| 160 | ret = power_domain_get_by_index(dev, &rproc->rproc_pwrdmn, 1); |
| 161 | if (ret) { |
| 162 | dev_err(dev, "power_domain_get() failed: %d\n", ret); |
| 163 | return ret; |
| 164 | } |
| 165 | |
| 166 | ret = power_domain_get_by_index(dev, &rproc->gtc_pwrdmn, 0); |
| 167 | if (ret) { |
| 168 | dev_err(dev, "power_domain_get() failed: %d\n", ret); |
| 169 | return ret; |
| 170 | } |
| 171 | |
| 172 | ret = reset_get_by_index(dev, 0, &rproc->rproc_rst); |
| 173 | if (ret) { |
| 174 | dev_err(dev, "reset_get() failed: %d\n", ret); |
| 175 | return ret; |
| 176 | } |
| 177 | |
Lokesh Vutla | 142611f | 2019-06-07 19:25:58 +0530 | [diff] [blame] | 178 | ret = ti_sci_proc_of_to_priv(dev, &rproc->tsp); |
| 179 | if (ret) |
| 180 | return ret; |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 181 | |
| 182 | rproc->gtc_base = dev_read_addr_ptr(dev); |
| 183 | if (!rproc->gtc_base) { |
| 184 | dev_err(dev, "Get address failed\n"); |
| 185 | return -ENODEV; |
| 186 | } |
| 187 | |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | /** |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 192 | * k3_arm64_probe() - Basic probe |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 193 | * @dev: corresponding k3 remote processor device |
| 194 | * |
| 195 | * Return: 0 if all goes good, else appropriate error message. |
| 196 | */ |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 197 | static int k3_arm64_probe(struct udevice *dev) |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 198 | { |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 199 | struct k3_arm64_privdata *priv; |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 200 | int ret; |
| 201 | |
| 202 | dev_dbg(dev, "%s\n", __func__); |
| 203 | |
| 204 | priv = dev_get_priv(dev); |
| 205 | |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 206 | ret = k3_arm64_of_to_priv(dev, priv); |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 207 | if (ret) { |
| 208 | dev_dbg(dev, "%s: Probe failed with error %d\n", __func__, ret); |
| 209 | return ret; |
| 210 | } |
| 211 | |
| 212 | dev_dbg(dev, "Remoteproc successfully probed\n"); |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 217 | static const struct udevice_id k3_arm64_ids[] = { |
| 218 | { .compatible = "ti,am654-arm64"}, |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 219 | { .compatible = "ti,am654-rproc"}, |
| 220 | {} |
| 221 | }; |
| 222 | |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 223 | U_BOOT_DRIVER(k3_arm64) = { |
| 224 | .name = "k3_arm64", |
| 225 | .of_match = k3_arm64_ids, |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 226 | .id = UCLASS_REMOTEPROC, |
Lokesh Vutla | 247418b | 2019-06-07 19:25:59 +0530 | [diff] [blame] | 227 | .ops = &k3_arm64_ops, |
| 228 | .probe = k3_arm64_probe, |
| 229 | .priv_auto_alloc_size = sizeof(struct k3_arm64_privdata), |
Lokesh Vutla | 01cfdf7 | 2019-09-27 13:48:13 +0530 | [diff] [blame] | 230 | .flags = DM_FLAG_DEFAULT_PD_CTRL_OFF, |
Lokesh Vutla | fdae32e | 2018-08-27 15:57:52 +0530 | [diff] [blame] | 231 | }; |