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