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