Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Texas Instruments' K3 DSP Remoteproc driver |
| 4 | * |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame] | 5 | * Copyright (C) 2018-2020 Texas Instruments Incorporated - https://www.ti.com/ |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 6 | * Lokesh Vutla <lokeshvutla@ti.com> |
Suman Anna | be7fa2d | 2020-03-10 16:05:56 -0500 | [diff] [blame] | 7 | * Suman Anna <s-anna@ti.com> |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 8 | */ |
| 9 | |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 10 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 12 | #include <malloc.h> |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 13 | #include <remoteproc.h> |
| 14 | #include <errno.h> |
| 15 | #include <clk.h> |
| 16 | #include <reset.h> |
| 17 | #include <asm/io.h> |
| 18 | #include <power-domain.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 19 | #include <dm/device_compat.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 20 | #include <linux/err.h> |
Suman Anna | e45fa38 | 2020-03-10 16:05:54 -0500 | [diff] [blame] | 21 | #include <linux/sizes.h> |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 22 | #include <linux/soc/ti/ti_sci_protocol.h> |
| 23 | #include "ti_sci_proc.h" |
Manorit Chawdhry | 3b779d1 | 2024-05-21 16:26:46 +0530 | [diff] [blame] | 24 | #include <mach/security.h> |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 25 | |
| 26 | #define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1) |
| 27 | |
| 28 | /** |
| 29 | * struct k3_dsp_mem - internal memory structure |
| 30 | * @cpu_addr: MPU virtual address of the memory region |
| 31 | * @bus_addr: Bus address used to access the memory region |
| 32 | * @dev_addr: Device address from remoteproc view |
| 33 | * @size: Size of the memory region |
| 34 | */ |
| 35 | struct k3_dsp_mem { |
| 36 | void __iomem *cpu_addr; |
| 37 | phys_addr_t bus_addr; |
| 38 | phys_addr_t dev_addr; |
| 39 | size_t size; |
| 40 | }; |
| 41 | |
| 42 | /** |
Suman Anna | e45fa38 | 2020-03-10 16:05:54 -0500 | [diff] [blame] | 43 | * struct k3_dsp_boot_data - internal data structure used for boot |
| 44 | * @boot_align_addr: Boot vector address alignment granularity |
Suman Anna | be7fa2d | 2020-03-10 16:05:56 -0500 | [diff] [blame] | 45 | * @uses_lreset: Flag to denote the need for local reset management |
Suman Anna | e45fa38 | 2020-03-10 16:05:54 -0500 | [diff] [blame] | 46 | */ |
| 47 | struct k3_dsp_boot_data { |
| 48 | u32 boot_align_addr; |
Suman Anna | be7fa2d | 2020-03-10 16:05:56 -0500 | [diff] [blame] | 49 | bool uses_lreset; |
Suman Anna | e45fa38 | 2020-03-10 16:05:54 -0500 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | /** |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 53 | * struct k3_dsp_privdata - Structure representing Remote processor data. |
| 54 | * @rproc_rst: rproc reset control data |
| 55 | * @tsp: Pointer to TISCI proc contrl handle |
Suman Anna | e45fa38 | 2020-03-10 16:05:54 -0500 | [diff] [blame] | 56 | * @data: Pointer to DSP specific boot data structure |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 57 | * @mem: Array of available memories |
| 58 | * @num_mem: Number of available memories |
Udit Kumar | a962c2e | 2023-11-25 23:59:39 +0530 | [diff] [blame] | 59 | * @in_use: flag to tell if the core is already in use. |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 60 | */ |
| 61 | struct k3_dsp_privdata { |
| 62 | struct reset_ctl dsp_rst; |
| 63 | struct ti_sci_proc tsp; |
Suman Anna | e45fa38 | 2020-03-10 16:05:54 -0500 | [diff] [blame] | 64 | struct k3_dsp_boot_data *data; |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 65 | struct k3_dsp_mem *mem; |
| 66 | int num_mems; |
Udit Kumar | a962c2e | 2023-11-25 23:59:39 +0530 | [diff] [blame] | 67 | bool in_use; |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 68 | }; |
| 69 | |
Suman Anna | be7fa2d | 2020-03-10 16:05:56 -0500 | [diff] [blame] | 70 | /* |
| 71 | * The C66x DSP cores have a local reset that affects only the CPU, and a |
| 72 | * generic module reset that powers on the device and allows the DSP internal |
| 73 | * memories to be accessed while the local reset is asserted. This function is |
| 74 | * used to release the global reset on C66x DSPs to allow loading into the DSP |
| 75 | * internal RAMs. This helper function is invoked in k3_dsp_load() before any |
| 76 | * actual firmware loading and is undone only in k3_dsp_stop(). The local reset |
| 77 | * on C71x cores is a no-op and the global reset cannot be released on C71x |
| 78 | * cores until after the firmware images are loaded, so this function does |
| 79 | * nothing for C71x cores. |
| 80 | */ |
| 81 | static int k3_dsp_prepare(struct udevice *dev) |
| 82 | { |
| 83 | struct k3_dsp_privdata *dsp = dev_get_priv(dev); |
| 84 | struct k3_dsp_boot_data *data = dsp->data; |
| 85 | int ret; |
| 86 | |
| 87 | /* local reset is no-op on C71x processors */ |
| 88 | if (!data->uses_lreset) |
| 89 | return 0; |
| 90 | |
| 91 | ret = ti_sci_proc_power_domain_on(&dsp->tsp); |
| 92 | if (ret) |
| 93 | dev_err(dev, "cannot enable internal RAM loading, ret = %d\n", |
| 94 | ret); |
| 95 | |
| 96 | return ret; |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * This function is the counterpart to k3_dsp_prepare() and is used to assert |
| 101 | * the global reset on C66x DSP cores (no-op for C71x DSP cores). This completes |
| 102 | * the second step of powering down the C66x DSP cores. The cores themselves |
| 103 | * are halted through the local reset in first step. This function is invoked |
| 104 | * in k3_dsp_stop() after the local reset is asserted. |
| 105 | */ |
| 106 | static int k3_dsp_unprepare(struct udevice *dev) |
| 107 | { |
| 108 | struct k3_dsp_privdata *dsp = dev_get_priv(dev); |
| 109 | struct k3_dsp_boot_data *data = dsp->data; |
| 110 | |
| 111 | /* local reset is no-op on C71x processors */ |
| 112 | if (!data->uses_lreset) |
| 113 | return 0; |
| 114 | |
| 115 | return ti_sci_proc_power_domain_off(&dsp->tsp); |
| 116 | } |
| 117 | |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 118 | /** |
| 119 | * k3_dsp_load() - Load up the Remote processor image |
| 120 | * @dev: rproc device pointer |
| 121 | * @addr: Address at which image is available |
| 122 | * @size: size of the image |
| 123 | * |
| 124 | * Return: 0 if all goes good, else appropriate error message. |
| 125 | */ |
| 126 | static int k3_dsp_load(struct udevice *dev, ulong addr, ulong size) |
| 127 | { |
| 128 | struct k3_dsp_privdata *dsp = dev_get_priv(dev); |
Suman Anna | e45fa38 | 2020-03-10 16:05:54 -0500 | [diff] [blame] | 129 | struct k3_dsp_boot_data *data = dsp->data; |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 130 | u32 boot_vector; |
Manorit Chawdhry | 3b779d1 | 2024-05-21 16:26:46 +0530 | [diff] [blame] | 131 | void *image_addr = (void *)addr; |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 132 | int ret; |
| 133 | |
Udit Kumar | a962c2e | 2023-11-25 23:59:39 +0530 | [diff] [blame] | 134 | if (dsp->in_use) { |
| 135 | dev_err(dev, |
| 136 | "Invalid op: Trying to load/start on already running core %d\n", |
| 137 | dsp->tsp.proc_id); |
| 138 | return -EINVAL; |
| 139 | } |
| 140 | |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 141 | dev_dbg(dev, "%s addr = 0x%lx, size = 0x%lx\n", __func__, addr, size); |
| 142 | ret = ti_sci_proc_request(&dsp->tsp); |
| 143 | if (ret) |
| 144 | return ret; |
| 145 | |
Suman Anna | be7fa2d | 2020-03-10 16:05:56 -0500 | [diff] [blame] | 146 | ret = k3_dsp_prepare(dev); |
| 147 | if (ret) { |
| 148 | dev_err(dev, "DSP prepare failed for core %d\n", |
| 149 | dsp->tsp.proc_id); |
| 150 | goto proc_release; |
| 151 | } |
| 152 | |
Manorit Chawdhry | 3b779d1 | 2024-05-21 16:26:46 +0530 | [diff] [blame] | 153 | ti_secure_image_post_process(&image_addr, &size); |
| 154 | |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 155 | ret = rproc_elf_load_image(dev, addr, size); |
| 156 | if (ret < 0) { |
| 157 | dev_err(dev, "Loading elf failed %d\n", ret); |
Suman Anna | be7fa2d | 2020-03-10 16:05:56 -0500 | [diff] [blame] | 158 | goto unprepare; |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | boot_vector = rproc_elf_get_boot_addr(dev, addr); |
Suman Anna | e45fa38 | 2020-03-10 16:05:54 -0500 | [diff] [blame] | 162 | if (boot_vector & (data->boot_align_addr - 1)) { |
| 163 | ret = -EINVAL; |
| 164 | dev_err(dev, "Boot vector 0x%x not aligned on 0x%x boundary\n", |
| 165 | boot_vector, data->boot_align_addr); |
| 166 | goto proc_release; |
| 167 | } |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 168 | |
| 169 | dev_dbg(dev, "%s: Boot vector = 0x%x\n", __func__, boot_vector); |
| 170 | |
| 171 | ret = ti_sci_proc_set_config(&dsp->tsp, boot_vector, 0, 0); |
Suman Anna | be7fa2d | 2020-03-10 16:05:56 -0500 | [diff] [blame] | 172 | unprepare: |
| 173 | if (ret) |
| 174 | k3_dsp_unprepare(dev); |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 175 | proc_release: |
| 176 | ti_sci_proc_release(&dsp->tsp); |
| 177 | return ret; |
| 178 | } |
| 179 | |
| 180 | /** |
| 181 | * k3_dsp_start() - Start the remote processor |
| 182 | * @dev: rproc device pointer |
| 183 | * |
| 184 | * Return: 0 if all went ok, else return appropriate error |
| 185 | */ |
| 186 | static int k3_dsp_start(struct udevice *dev) |
| 187 | { |
| 188 | struct k3_dsp_privdata *dsp = dev_get_priv(dev); |
Suman Anna | be7fa2d | 2020-03-10 16:05:56 -0500 | [diff] [blame] | 189 | struct k3_dsp_boot_data *data = dsp->data; |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 190 | int ret; |
| 191 | |
| 192 | dev_dbg(dev, "%s\n", __func__); |
| 193 | |
| 194 | ret = ti_sci_proc_request(&dsp->tsp); |
| 195 | if (ret) |
| 196 | return ret; |
Suman Anna | 83d8fab | 2020-03-10 16:05:53 -0500 | [diff] [blame] | 197 | |
Suman Anna | be7fa2d | 2020-03-10 16:05:56 -0500 | [diff] [blame] | 198 | if (!data->uses_lreset) { |
| 199 | ret = ti_sci_proc_power_domain_on(&dsp->tsp); |
| 200 | if (ret) |
| 201 | goto proc_release; |
| 202 | } |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 203 | |
| 204 | ret = reset_deassert(&dsp->dsp_rst); |
Suman Anna | be7fa2d | 2020-03-10 16:05:56 -0500 | [diff] [blame] | 205 | if (ret) { |
| 206 | if (!data->uses_lreset) |
| 207 | ti_sci_proc_power_domain_off(&dsp->tsp); |
| 208 | } |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 209 | |
Udit Kumar | a962c2e | 2023-11-25 23:59:39 +0530 | [diff] [blame] | 210 | dsp->in_use = true; |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 211 | proc_release: |
| 212 | ti_sci_proc_release(&dsp->tsp); |
| 213 | |
| 214 | return ret; |
| 215 | } |
| 216 | |
| 217 | static int k3_dsp_stop(struct udevice *dev) |
| 218 | { |
| 219 | struct k3_dsp_privdata *dsp = dev_get_priv(dev); |
| 220 | |
| 221 | dev_dbg(dev, "%s\n", __func__); |
| 222 | |
Udit Kumar | a962c2e | 2023-11-25 23:59:39 +0530 | [diff] [blame] | 223 | dsp->in_use = false; |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 224 | ti_sci_proc_request(&dsp->tsp); |
| 225 | reset_assert(&dsp->dsp_rst); |
| 226 | ti_sci_proc_power_domain_off(&dsp->tsp); |
| 227 | ti_sci_proc_release(&dsp->tsp); |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * k3_dsp_init() - Initialize the remote processor |
| 234 | * @dev: rproc device pointer |
| 235 | * |
| 236 | * Return: 0 if all went ok, else return appropriate error |
| 237 | */ |
| 238 | static int k3_dsp_init(struct udevice *dev) |
| 239 | { |
| 240 | dev_dbg(dev, "%s\n", __func__); |
| 241 | |
| 242 | return 0; |
| 243 | } |
| 244 | |
| 245 | static int k3_dsp_reset(struct udevice *dev) |
| 246 | { |
| 247 | dev_dbg(dev, "%s\n", __func__); |
| 248 | |
| 249 | return 0; |
| 250 | } |
| 251 | |
| 252 | static void *k3_dsp_da_to_va(struct udevice *dev, ulong da, ulong len) |
| 253 | { |
| 254 | struct k3_dsp_privdata *dsp = dev_get_priv(dev); |
| 255 | phys_addr_t bus_addr, dev_addr; |
| 256 | void __iomem *va = NULL; |
| 257 | size_t size; |
| 258 | u32 offset; |
| 259 | int i; |
| 260 | |
| 261 | dev_dbg(dev, "%s\n", __func__); |
| 262 | |
| 263 | if (len <= 0) |
| 264 | return NULL; |
| 265 | |
| 266 | for (i = 0; i < dsp->num_mems; i++) { |
| 267 | bus_addr = dsp->mem[i].bus_addr; |
| 268 | dev_addr = dsp->mem[i].dev_addr; |
| 269 | size = dsp->mem[i].size; |
| 270 | |
| 271 | if (da >= dev_addr && ((da + len) <= (dev_addr + size))) { |
| 272 | offset = da - dev_addr; |
| 273 | va = dsp->mem[i].cpu_addr + offset; |
| 274 | return (__force void *)va; |
| 275 | } |
| 276 | |
| 277 | if (da >= bus_addr && (da + len) <= (bus_addr + size)) { |
| 278 | offset = da - bus_addr; |
| 279 | va = dsp->mem[i].cpu_addr + offset; |
| 280 | return (__force void *)va; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | /* Assume it is DDR region and return da */ |
| 285 | return map_physmem(da, len, MAP_NOCACHE); |
| 286 | } |
| 287 | |
| 288 | static const struct dm_rproc_ops k3_dsp_ops = { |
| 289 | .init = k3_dsp_init, |
| 290 | .load = k3_dsp_load, |
| 291 | .start = k3_dsp_start, |
| 292 | .stop = k3_dsp_stop, |
| 293 | .reset = k3_dsp_reset, |
| 294 | .device_to_virt = k3_dsp_da_to_va, |
| 295 | }; |
| 296 | |
| 297 | static int ti_sci_proc_of_to_priv(struct udevice *dev, struct ti_sci_proc *tsp) |
| 298 | { |
| 299 | u32 ids[2]; |
| 300 | int ret; |
| 301 | |
| 302 | dev_dbg(dev, "%s\n", __func__); |
| 303 | |
| 304 | tsp->sci = ti_sci_get_by_phandle(dev, "ti,sci"); |
| 305 | if (IS_ERR(tsp->sci)) { |
| 306 | dev_err(dev, "ti_sci get failed: %ld\n", PTR_ERR(tsp->sci)); |
| 307 | return PTR_ERR(tsp->sci); |
| 308 | } |
| 309 | |
| 310 | ret = dev_read_u32_array(dev, "ti,sci-proc-ids", ids, 2); |
| 311 | if (ret) { |
| 312 | dev_err(dev, "Proc IDs not populated %d\n", ret); |
| 313 | return ret; |
| 314 | } |
| 315 | |
| 316 | tsp->ops = &tsp->sci->ops.proc_ops; |
| 317 | tsp->proc_id = ids[0]; |
| 318 | tsp->host_id = ids[1]; |
| 319 | tsp->dev_id = dev_read_u32_default(dev, "ti,sci-dev-id", |
| 320 | TI_SCI_RESOURCE_NULL); |
| 321 | if (tsp->dev_id == TI_SCI_RESOURCE_NULL) { |
| 322 | dev_err(dev, "Device ID not populated %d\n", ret); |
| 323 | return -ENODEV; |
| 324 | } |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | static int k3_dsp_of_get_memories(struct udevice *dev) |
| 330 | { |
| 331 | static const char * const mem_names[] = {"l2sram", "l1pram", "l1dram"}; |
| 332 | struct k3_dsp_privdata *dsp = dev_get_priv(dev); |
| 333 | int i; |
| 334 | |
| 335 | dev_dbg(dev, "%s\n", __func__); |
| 336 | |
| 337 | dsp->num_mems = ARRAY_SIZE(mem_names); |
| 338 | dsp->mem = calloc(dsp->num_mems, sizeof(*dsp->mem)); |
| 339 | if (!dsp->mem) |
| 340 | return -ENOMEM; |
| 341 | |
| 342 | for (i = 0; i < dsp->num_mems; i++) { |
| 343 | /* C71 cores only have a L1P Cache, there are no L1P SRAMs */ |
Hari Nagalla | 1eb8681 | 2024-03-12 15:14:36 +0530 | [diff] [blame] | 344 | if (((device_is_compatible(dev, "ti,j721e-c71-dsp")) || |
Hari Nagalla | da85f78 | 2024-05-09 09:20:34 -0500 | [diff] [blame] | 345 | (device_is_compatible(dev, "ti,j721s2-c71-dsp")) || |
| 346 | (device_is_compatible(dev, "ti,am62a-c7xv-dsp"))) && |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 347 | !strcmp(mem_names[i], "l1pram")) { |
| 348 | dsp->mem[i].bus_addr = FDT_ADDR_T_NONE; |
| 349 | dsp->mem[i].dev_addr = FDT_ADDR_T_NONE; |
| 350 | dsp->mem[i].cpu_addr = NULL; |
| 351 | dsp->mem[i].size = 0; |
| 352 | continue; |
| 353 | } |
Hari Nagalla | da85f78 | 2024-05-09 09:20:34 -0500 | [diff] [blame] | 354 | if (device_is_compatible(dev, "ti,am62a-c7xv-dsp") && |
| 355 | !strcmp(mem_names[i], "l1dram")) { |
| 356 | dsp->mem[i].bus_addr = FDT_ADDR_T_NONE; |
| 357 | dsp->mem[i].dev_addr = FDT_ADDR_T_NONE; |
| 358 | dsp->mem[i].cpu_addr = NULL; |
| 359 | dsp->mem[i].size = 0; |
| 360 | continue; |
| 361 | } |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 362 | dsp->mem[i].bus_addr = dev_read_addr_size_name(dev, mem_names[i], |
| 363 | (fdt_addr_t *)&dsp->mem[i].size); |
| 364 | if (dsp->mem[i].bus_addr == FDT_ADDR_T_NONE) { |
| 365 | dev_err(dev, "%s bus address not found\n", mem_names[i]); |
| 366 | return -EINVAL; |
| 367 | } |
| 368 | dsp->mem[i].cpu_addr = map_physmem(dsp->mem[i].bus_addr, |
| 369 | dsp->mem[i].size, |
| 370 | MAP_NOCACHE); |
| 371 | dsp->mem[i].dev_addr = dsp->mem[i].bus_addr & |
| 372 | KEYSTONE_RPROC_LOCAL_ADDRESS_MASK; |
| 373 | |
| 374 | dev_dbg(dev, "memory %8s: bus addr %pa size 0x%zx va %p da %pa\n", |
| 375 | mem_names[i], &dsp->mem[i].bus_addr, |
| 376 | dsp->mem[i].size, dsp->mem[i].cpu_addr, |
| 377 | &dsp->mem[i].dev_addr); |
| 378 | } |
| 379 | |
| 380 | return 0; |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * k3_of_to_priv() - generate private data from device tree |
| 385 | * @dev: corresponding k3 dsp processor device |
| 386 | * @dsp: pointer to driver specific private data |
| 387 | * |
| 388 | * Return: 0 if all goes good, else appropriate error message. |
| 389 | */ |
| 390 | static int k3_dsp_of_to_priv(struct udevice *dev, struct k3_dsp_privdata *dsp) |
| 391 | { |
| 392 | int ret; |
| 393 | |
| 394 | dev_dbg(dev, "%s\n", __func__); |
| 395 | |
| 396 | ret = reset_get_by_index(dev, 0, &dsp->dsp_rst); |
| 397 | if (ret) { |
| 398 | dev_err(dev, "reset_get() failed: %d\n", ret); |
| 399 | return ret; |
| 400 | } |
| 401 | |
| 402 | ret = ti_sci_proc_of_to_priv(dev, &dsp->tsp); |
| 403 | if (ret) |
| 404 | return ret; |
| 405 | |
| 406 | ret = k3_dsp_of_get_memories(dev); |
| 407 | if (ret) |
| 408 | return ret; |
| 409 | |
Suman Anna | e45fa38 | 2020-03-10 16:05:54 -0500 | [diff] [blame] | 410 | dsp->data = (struct k3_dsp_boot_data *)dev_get_driver_data(dev); |
| 411 | |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 412 | return 0; |
| 413 | } |
| 414 | |
| 415 | /** |
| 416 | * k3_dsp_probe() - Basic probe |
| 417 | * @dev: corresponding k3 remote processor device |
| 418 | * |
| 419 | * Return: 0 if all goes good, else appropriate error message. |
| 420 | */ |
| 421 | static int k3_dsp_probe(struct udevice *dev) |
| 422 | { |
| 423 | struct k3_dsp_privdata *dsp; |
| 424 | int ret; |
| 425 | |
| 426 | dev_dbg(dev, "%s\n", __func__); |
| 427 | |
| 428 | dsp = dev_get_priv(dev); |
| 429 | |
| 430 | ret = k3_dsp_of_to_priv(dev, dsp); |
| 431 | if (ret) { |
| 432 | dev_dbg(dev, "%s: Probe failed with error %d\n", __func__, ret); |
| 433 | return ret; |
| 434 | } |
| 435 | |
Suman Anna | be7fa2d | 2020-03-10 16:05:56 -0500 | [diff] [blame] | 436 | /* |
| 437 | * The DSP local resets are deasserted by default on Power-On-Reset. |
| 438 | * Assert the local resets to ensure the DSPs don't execute bogus code |
| 439 | * in .load() callback when the module reset is released to support |
| 440 | * internal memory loading. This is needed for C66x DSPs, and is a |
| 441 | * no-op on C71x DSPs. |
| 442 | */ |
| 443 | reset_assert(&dsp->dsp_rst); |
| 444 | |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 445 | dev_dbg(dev, "Remoteproc successfully probed\n"); |
| 446 | |
| 447 | return 0; |
| 448 | } |
| 449 | |
| 450 | static int k3_dsp_remove(struct udevice *dev) |
| 451 | { |
| 452 | struct k3_dsp_privdata *dsp = dev_get_priv(dev); |
| 453 | |
| 454 | free(dsp->mem); |
| 455 | |
| 456 | return 0; |
| 457 | } |
| 458 | |
Suman Anna | e45fa38 | 2020-03-10 16:05:54 -0500 | [diff] [blame] | 459 | static const struct k3_dsp_boot_data c66_data = { |
| 460 | .boot_align_addr = SZ_1K, |
Suman Anna | be7fa2d | 2020-03-10 16:05:56 -0500 | [diff] [blame] | 461 | .uses_lreset = true, |
Suman Anna | e45fa38 | 2020-03-10 16:05:54 -0500 | [diff] [blame] | 462 | }; |
| 463 | |
| 464 | static const struct k3_dsp_boot_data c71_data = { |
| 465 | .boot_align_addr = SZ_2M, |
Suman Anna | be7fa2d | 2020-03-10 16:05:56 -0500 | [diff] [blame] | 466 | .uses_lreset = false, |
Suman Anna | e45fa38 | 2020-03-10 16:05:54 -0500 | [diff] [blame] | 467 | }; |
| 468 | |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 469 | static const struct udevice_id k3_dsp_ids[] = { |
Suman Anna | e45fa38 | 2020-03-10 16:05:54 -0500 | [diff] [blame] | 470 | { .compatible = "ti,j721e-c66-dsp", .data = (ulong)&c66_data, }, |
| 471 | { .compatible = "ti,j721e-c71-dsp", .data = (ulong)&c71_data, }, |
Hari Nagalla | 1eb8681 | 2024-03-12 15:14:36 +0530 | [diff] [blame] | 472 | { .compatible = "ti,j721s2-c71-dsp", .data = (ulong)&c71_data, }, |
Hari Nagalla | da85f78 | 2024-05-09 09:20:34 -0500 | [diff] [blame] | 473 | { .compatible = "ti,am62a-c7xv-dsp", .data = (ulong)&c71_data, }, |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 474 | {} |
| 475 | }; |
| 476 | |
| 477 | U_BOOT_DRIVER(k3_dsp) = { |
| 478 | .name = "k3_dsp", |
| 479 | .of_match = k3_dsp_ids, |
| 480 | .id = UCLASS_REMOTEPROC, |
| 481 | .ops = &k3_dsp_ops, |
| 482 | .probe = k3_dsp_probe, |
| 483 | .remove = k3_dsp_remove, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 484 | .priv_auto = sizeof(struct k3_dsp_privdata), |
Lokesh Vutla | 2c77185 | 2019-09-04 16:01:36 +0530 | [diff] [blame] | 485 | }; |