1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2015-2016
4 * Texas Instruments Incorporated - http://www.ti.com/
6 #define pr_fmt(fmt) "%s: " fmt, __func__
12 #include <remoteproc.h>
13 #include <mach/psc_defs.h>
15 DECLARE_GLOBAL_DATA_PTR;
18 * struct ti_powerproc_privdata - power processor private data
19 * @loadaddr: base address for loading the power processor
20 * @psc_module: psc module address.
22 struct ti_powerproc_privdata {
28 * ti_of_to_priv() - generate private data from device tree
29 * @dev: corresponding ti remote processor device
30 * @priv: pointer to driver specific private data
32 * Return: 0 if all went ok, else corresponding -ve error
34 static int ti_of_to_priv(struct udevice *dev,
35 struct ti_powerproc_privdata *priv)
37 int node = dev_of_offset(dev);
38 const void *blob = gd->fdt_blob;
42 debug("'%s' no dt?\n", dev->name);
46 priv->loadaddr = fdtdec_get_addr(blob, node, "reg");
47 if (priv->loadaddr == FDT_ADDR_T_NONE) {
48 debug("'%s': no 'reg' property\n", dev->name);
52 tmp = fdtdec_get_int(blob, node, "ti,lpsc_module", -EINVAL);
54 debug("'%s': no 'ti,lpsc_module' property\n", dev->name);
57 priv->psc_module = tmp;
63 * ti_powerproc_probe() - Basic probe
64 * @dev: corresponding ti remote processor device
66 * Return: 0 if all went ok, else corresponding -ve error
68 static int ti_powerproc_probe(struct udevice *dev)
70 struct dm_rproc_uclass_pdata *uc_pdata;
71 struct ti_powerproc_privdata *priv;
74 uc_pdata = dev_get_uclass_platdata(dev);
75 priv = dev_get_priv(dev);
77 ret = ti_of_to_priv(dev, priv);
79 debug("%s probed with slave_addr=0x%08lX module=%d(%d)\n",
80 uc_pdata->name, priv->loadaddr, priv->psc_module, ret);
86 * ti_powerproc_load() - Loadup the TI remote processor
87 * @dev: corresponding ti remote processor device
88 * @addr: Address in memory where image binary is stored
89 * @size: Size in bytes of the image binary
91 * Return: 0 if all went ok, else corresponding -ve error
93 static int ti_powerproc_load(struct udevice *dev, ulong addr, ulong size)
95 struct dm_rproc_uclass_pdata *uc_pdata;
96 struct ti_powerproc_privdata *priv;
99 uc_pdata = dev_get_uclass_platdata(dev);
101 debug("%s: no uc pdata!\n", dev->name);
105 priv = dev_get_priv(dev);
106 ret = psc_module_keep_in_reset_enabled(priv->psc_module, false);
108 debug("%s Unable to disable module '%d'(ret=%d)\n",
109 uc_pdata->name, priv->psc_module, ret);
113 debug("%s: Loading binary from 0x%08lX, size 0x%08lX to 0x%08lX\n",
114 uc_pdata->name, addr, size, priv->loadaddr);
116 memcpy((void *)priv->loadaddr, (void *)addr, size);
118 debug("%s: Complete!\n", uc_pdata->name);
123 * ti_powerproc_start() - (replace: short desc)
124 * @dev: corresponding ti remote processor device
126 * Return: 0 if all went ok, else corresponding -ve error
128 static int ti_powerproc_start(struct udevice *dev)
130 struct dm_rproc_uclass_pdata *uc_pdata;
131 struct ti_powerproc_privdata *priv;
134 uc_pdata = dev_get_uclass_platdata(dev);
136 debug("%s: no uc pdata!\n", dev->name);
140 priv = dev_get_priv(dev);
141 ret = psc_disable_module(priv->psc_module);
143 debug("%s Unable to disable module '%d'(ret=%d)\n",
144 uc_pdata->name, priv->psc_module, ret);
148 ret = psc_module_release_from_reset(priv->psc_module);
150 debug("%s Failed to wait for module '%d'(ret=%d)\n",
151 uc_pdata->name, priv->psc_module, ret);
154 ret = psc_enable_module(priv->psc_module);
156 debug("%s Unable to disable module '%d'(ret=%d)\n",
157 uc_pdata->name, priv->psc_module, ret);
164 static const struct dm_rproc_ops ti_powerproc_ops = {
165 .load = ti_powerproc_load,
166 .start = ti_powerproc_start,
169 static const struct udevice_id ti_powerproc_ids[] = {
170 {.compatible = "ti,power-processor"},
174 U_BOOT_DRIVER(ti_powerproc) = {
175 .name = "ti_power_proc",
176 .of_match = ti_powerproc_ids,
177 .id = UCLASS_REMOTEPROC,
178 .ops = &ti_powerproc_ops,
179 .probe = ti_powerproc_probe,
180 .priv_auto = sizeof(struct ti_powerproc_privdata),