Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Nishanth Menon | 129a114 | 2016-02-25 12:53:45 -0600 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2015-2016 |
Nishanth Menon | eaa39c6 | 2023-11-01 15:56:03 -0500 | [diff] [blame^] | 4 | * Texas Instruments Incorporated - https://www.ti.com/ |
Nishanth Menon | 129a114 | 2016-02-25 12:53:45 -0600 | [diff] [blame] | 5 | */ |
| 6 | #define pr_fmt(fmt) "%s: " fmt, __func__ |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <errno.h> |
| 10 | #include <fdtdec.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Nishanth Menon | 129a114 | 2016-02-25 12:53:45 -0600 | [diff] [blame] | 12 | #include <remoteproc.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 14 | #include <linux/printk.h> |
Nishanth Menon | 129a114 | 2016-02-25 12:53:45 -0600 | [diff] [blame] | 15 | #include <mach/psc_defs.h> |
| 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
| 19 | /** |
| 20 | * struct ti_powerproc_privdata - power processor private data |
| 21 | * @loadaddr: base address for loading the power processor |
| 22 | * @psc_module: psc module address. |
| 23 | */ |
| 24 | struct ti_powerproc_privdata { |
| 25 | phys_addr_t loadaddr; |
| 26 | u32 psc_module; |
| 27 | }; |
| 28 | |
| 29 | /** |
| 30 | * ti_of_to_priv() - generate private data from device tree |
| 31 | * @dev: corresponding ti remote processor device |
| 32 | * @priv: pointer to driver specific private data |
| 33 | * |
| 34 | * Return: 0 if all went ok, else corresponding -ve error |
| 35 | */ |
| 36 | static int ti_of_to_priv(struct udevice *dev, |
| 37 | struct ti_powerproc_privdata *priv) |
| 38 | { |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 39 | int node = dev_of_offset(dev); |
Nishanth Menon | 129a114 | 2016-02-25 12:53:45 -0600 | [diff] [blame] | 40 | const void *blob = gd->fdt_blob; |
| 41 | int tmp; |
| 42 | |
| 43 | if (!blob) { |
| 44 | debug("'%s' no dt?\n", dev->name); |
| 45 | return -EINVAL; |
| 46 | } |
| 47 | |
| 48 | priv->loadaddr = fdtdec_get_addr(blob, node, "reg"); |
| 49 | if (priv->loadaddr == FDT_ADDR_T_NONE) { |
| 50 | debug("'%s': no 'reg' property\n", dev->name); |
| 51 | return -EINVAL; |
| 52 | } |
| 53 | |
| 54 | tmp = fdtdec_get_int(blob, node, "ti,lpsc_module", -EINVAL); |
| 55 | if (tmp < 0) { |
| 56 | debug("'%s': no 'ti,lpsc_module' property\n", dev->name); |
| 57 | return tmp; |
| 58 | } |
| 59 | priv->psc_module = tmp; |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * ti_powerproc_probe() - Basic probe |
| 66 | * @dev: corresponding ti remote processor device |
| 67 | * |
| 68 | * Return: 0 if all went ok, else corresponding -ve error |
| 69 | */ |
| 70 | static int ti_powerproc_probe(struct udevice *dev) |
| 71 | { |
| 72 | struct dm_rproc_uclass_pdata *uc_pdata; |
| 73 | struct ti_powerproc_privdata *priv; |
| 74 | int ret; |
| 75 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 76 | uc_pdata = dev_get_uclass_plat(dev); |
Nishanth Menon | 129a114 | 2016-02-25 12:53:45 -0600 | [diff] [blame] | 77 | priv = dev_get_priv(dev); |
| 78 | |
| 79 | ret = ti_of_to_priv(dev, priv); |
| 80 | |
| 81 | debug("%s probed with slave_addr=0x%08lX module=%d(%d)\n", |
| 82 | uc_pdata->name, priv->loadaddr, priv->psc_module, ret); |
| 83 | |
| 84 | return ret; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * ti_powerproc_load() - Loadup the TI remote processor |
| 89 | * @dev: corresponding ti remote processor device |
| 90 | * @addr: Address in memory where image binary is stored |
| 91 | * @size: Size in bytes of the image binary |
| 92 | * |
| 93 | * Return: 0 if all went ok, else corresponding -ve error |
| 94 | */ |
| 95 | static int ti_powerproc_load(struct udevice *dev, ulong addr, ulong size) |
| 96 | { |
| 97 | struct dm_rproc_uclass_pdata *uc_pdata; |
| 98 | struct ti_powerproc_privdata *priv; |
| 99 | int ret; |
| 100 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 101 | uc_pdata = dev_get_uclass_plat(dev); |
Nishanth Menon | 129a114 | 2016-02-25 12:53:45 -0600 | [diff] [blame] | 102 | if (!uc_pdata) { |
| 103 | debug("%s: no uc pdata!\n", dev->name); |
| 104 | return -EINVAL; |
| 105 | } |
| 106 | |
| 107 | priv = dev_get_priv(dev); |
| 108 | ret = psc_module_keep_in_reset_enabled(priv->psc_module, false); |
| 109 | if (ret) { |
| 110 | debug("%s Unable to disable module '%d'(ret=%d)\n", |
| 111 | uc_pdata->name, priv->psc_module, ret); |
| 112 | return ret; |
| 113 | } |
| 114 | |
| 115 | debug("%s: Loading binary from 0x%08lX, size 0x%08lX to 0x%08lX\n", |
| 116 | uc_pdata->name, addr, size, priv->loadaddr); |
| 117 | |
| 118 | memcpy((void *)priv->loadaddr, (void *)addr, size); |
| 119 | |
| 120 | debug("%s: Complete!\n", uc_pdata->name); |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * ti_powerproc_start() - (replace: short desc) |
| 126 | * @dev: corresponding ti remote processor device |
| 127 | * |
| 128 | * Return: 0 if all went ok, else corresponding -ve error |
| 129 | */ |
| 130 | static int ti_powerproc_start(struct udevice *dev) |
| 131 | { |
| 132 | struct dm_rproc_uclass_pdata *uc_pdata; |
| 133 | struct ti_powerproc_privdata *priv; |
| 134 | int ret; |
| 135 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 136 | uc_pdata = dev_get_uclass_plat(dev); |
Nishanth Menon | 129a114 | 2016-02-25 12:53:45 -0600 | [diff] [blame] | 137 | if (!uc_pdata) { |
| 138 | debug("%s: no uc pdata!\n", dev->name); |
| 139 | return -EINVAL; |
| 140 | } |
| 141 | |
| 142 | priv = dev_get_priv(dev); |
| 143 | ret = psc_disable_module(priv->psc_module); |
| 144 | if (ret) { |
| 145 | debug("%s Unable to disable module '%d'(ret=%d)\n", |
| 146 | uc_pdata->name, priv->psc_module, ret); |
| 147 | return ret; |
| 148 | } |
| 149 | |
| 150 | ret = psc_module_release_from_reset(priv->psc_module); |
| 151 | if (ret) { |
| 152 | debug("%s Failed to wait for module '%d'(ret=%d)\n", |
| 153 | uc_pdata->name, priv->psc_module, ret); |
| 154 | return ret; |
| 155 | } |
| 156 | ret = psc_enable_module(priv->psc_module); |
| 157 | if (ret) { |
| 158 | debug("%s Unable to disable module '%d'(ret=%d)\n", |
| 159 | uc_pdata->name, priv->psc_module, ret); |
| 160 | return ret; |
| 161 | } |
| 162 | |
| 163 | return 0; |
| 164 | } |
| 165 | |
| 166 | static const struct dm_rproc_ops ti_powerproc_ops = { |
| 167 | .load = ti_powerproc_load, |
| 168 | .start = ti_powerproc_start, |
| 169 | }; |
| 170 | |
| 171 | static const struct udevice_id ti_powerproc_ids[] = { |
| 172 | {.compatible = "ti,power-processor"}, |
| 173 | {} |
| 174 | }; |
| 175 | |
| 176 | U_BOOT_DRIVER(ti_powerproc) = { |
| 177 | .name = "ti_power_proc", |
| 178 | .of_match = ti_powerproc_ids, |
| 179 | .id = UCLASS_REMOTEPROC, |
| 180 | .ops = &ti_powerproc_ops, |
| 181 | .probe = ti_powerproc_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 182 | .priv_auto = sizeof(struct ti_powerproc_privdata), |
Nishanth Menon | 129a114 | 2016-02-25 12:53:45 -0600 | [diff] [blame] | 183 | }; |