1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2015-2016
4 * Texas Instruments Incorporated - https://www.ti.com/
6 #define pr_fmt(fmt) "%s: " fmt, __func__
11 #include <remoteproc.h>
12 #include <asm/global_data.h>
13 #include <linux/printk.h>
14 #include <mach/psc_defs.h>
16 DECLARE_GLOBAL_DATA_PTR;
19 * struct ti_powerproc_privdata - power processor private data
20 * @loadaddr: base address for loading the power processor
21 * @psc_module: psc module address.
23 struct ti_powerproc_privdata {
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
33 * Return: 0 if all went ok, else corresponding -ve error
35 static int ti_of_to_priv(struct udevice *dev,
36 struct ti_powerproc_privdata *priv)
38 int node = dev_of_offset(dev);
39 const void *blob = gd->fdt_blob;
43 debug("'%s' no dt?\n", dev->name);
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);
53 tmp = fdtdec_get_int(blob, node, "ti,lpsc_module", -EINVAL);
55 debug("'%s': no 'ti,lpsc_module' property\n", dev->name);
58 priv->psc_module = tmp;
64 * ti_powerproc_probe() - Basic probe
65 * @dev: corresponding ti remote processor device
67 * Return: 0 if all went ok, else corresponding -ve error
69 static int ti_powerproc_probe(struct udevice *dev)
71 struct dm_rproc_uclass_pdata *uc_pdata;
72 struct ti_powerproc_privdata *priv;
75 uc_pdata = dev_get_uclass_plat(dev);
76 priv = dev_get_priv(dev);
78 ret = ti_of_to_priv(dev, priv);
80 debug("%s probed with slave_addr=0x%08lX module=%d(%d)\n",
81 uc_pdata->name, priv->loadaddr, priv->psc_module, ret);
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
92 * Return: 0 if all went ok, else corresponding -ve error
94 static int ti_powerproc_load(struct udevice *dev, ulong addr, ulong size)
96 struct dm_rproc_uclass_pdata *uc_pdata;
97 struct ti_powerproc_privdata *priv;
100 uc_pdata = dev_get_uclass_plat(dev);
102 debug("%s: no uc pdata!\n", dev->name);
106 priv = dev_get_priv(dev);
107 ret = psc_module_keep_in_reset_enabled(priv->psc_module, false);
109 debug("%s Unable to disable module '%d'(ret=%d)\n",
110 uc_pdata->name, priv->psc_module, ret);
114 debug("%s: Loading binary from 0x%08lX, size 0x%08lX to 0x%08lX\n",
115 uc_pdata->name, addr, size, priv->loadaddr);
117 memcpy((void *)priv->loadaddr, (void *)addr, size);
119 debug("%s: Complete!\n", uc_pdata->name);
124 * ti_powerproc_start() - (replace: short desc)
125 * @dev: corresponding ti remote processor device
127 * Return: 0 if all went ok, else corresponding -ve error
129 static int ti_powerproc_start(struct udevice *dev)
131 struct dm_rproc_uclass_pdata *uc_pdata;
132 struct ti_powerproc_privdata *priv;
135 uc_pdata = dev_get_uclass_plat(dev);
137 debug("%s: no uc pdata!\n", dev->name);
141 priv = dev_get_priv(dev);
142 ret = psc_disable_module(priv->psc_module);
144 debug("%s Unable to disable module '%d'(ret=%d)\n",
145 uc_pdata->name, priv->psc_module, ret);
149 ret = psc_module_release_from_reset(priv->psc_module);
151 debug("%s Failed to wait for module '%d'(ret=%d)\n",
152 uc_pdata->name, priv->psc_module, ret);
155 ret = psc_enable_module(priv->psc_module);
157 debug("%s Unable to disable module '%d'(ret=%d)\n",
158 uc_pdata->name, priv->psc_module, ret);
165 static const struct dm_rproc_ops ti_powerproc_ops = {
166 .load = ti_powerproc_load,
167 .start = ti_powerproc_start,
170 static const struct udevice_id ti_powerproc_ids[] = {
171 {.compatible = "ti,power-processor"},
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,
181 .priv_auto = sizeof(struct ti_powerproc_privdata),