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