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