blob: 9dbbb44e955d6dd18615cd986c22ce3e7d18875b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nishanth Menon129a1142016-02-25 12:53:45 -06002/*
3 * (C) Copyright 2015-2016
4 * Texas Instruments Incorporated - http://www.ti.com/
Nishanth Menon129a1142016-02-25 12:53:45 -06005 */
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 Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Nishanth Menon129a1142016-02-25 12:53:45 -060012#include <remoteproc.h>
13#include <mach/psc_defs.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17/**
18 * struct ti_powerproc_privdata - power processor private data
19 * @loadaddr: base address for loading the power processor
20 * @psc_module: psc module address.
21 */
22struct ti_powerproc_privdata {
23 phys_addr_t loadaddr;
24 u32 psc_module;
25};
26
27/**
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
31 *
32 * Return: 0 if all went ok, else corresponding -ve error
33 */
34static int ti_of_to_priv(struct udevice *dev,
35 struct ti_powerproc_privdata *priv)
36{
Simon Glassdd79d6e2017-01-17 16:52:55 -070037 int node = dev_of_offset(dev);
Nishanth Menon129a1142016-02-25 12:53:45 -060038 const void *blob = gd->fdt_blob;
39 int tmp;
40
41 if (!blob) {
42 debug("'%s' no dt?\n", dev->name);
43 return -EINVAL;
44 }
45
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);
49 return -EINVAL;
50 }
51
52 tmp = fdtdec_get_int(blob, node, "ti,lpsc_module", -EINVAL);
53 if (tmp < 0) {
54 debug("'%s': no 'ti,lpsc_module' property\n", dev->name);
55 return tmp;
56 }
57 priv->psc_module = tmp;
58
59 return 0;
60}
61
62/**
63 * ti_powerproc_probe() - Basic probe
64 * @dev: corresponding ti remote processor device
65 *
66 * Return: 0 if all went ok, else corresponding -ve error
67 */
68static int ti_powerproc_probe(struct udevice *dev)
69{
70 struct dm_rproc_uclass_pdata *uc_pdata;
71 struct ti_powerproc_privdata *priv;
72 int ret;
73
Simon Glass71fa5b42020-12-03 16:55:18 -070074 uc_pdata = dev_get_uclass_plat(dev);
Nishanth Menon129a1142016-02-25 12:53:45 -060075 priv = dev_get_priv(dev);
76
77 ret = ti_of_to_priv(dev, priv);
78
79 debug("%s probed with slave_addr=0x%08lX module=%d(%d)\n",
80 uc_pdata->name, priv->loadaddr, priv->psc_module, ret);
81
82 return ret;
83}
84
85/**
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
90 *
91 * Return: 0 if all went ok, else corresponding -ve error
92 */
93static int ti_powerproc_load(struct udevice *dev, ulong addr, ulong size)
94{
95 struct dm_rproc_uclass_pdata *uc_pdata;
96 struct ti_powerproc_privdata *priv;
97 int ret;
98
Simon Glass71fa5b42020-12-03 16:55:18 -070099 uc_pdata = dev_get_uclass_plat(dev);
Nishanth Menon129a1142016-02-25 12:53:45 -0600100 if (!uc_pdata) {
101 debug("%s: no uc pdata!\n", dev->name);
102 return -EINVAL;
103 }
104
105 priv = dev_get_priv(dev);
106 ret = psc_module_keep_in_reset_enabled(priv->psc_module, false);
107 if (ret) {
108 debug("%s Unable to disable module '%d'(ret=%d)\n",
109 uc_pdata->name, priv->psc_module, ret);
110 return ret;
111 }
112
113 debug("%s: Loading binary from 0x%08lX, size 0x%08lX to 0x%08lX\n",
114 uc_pdata->name, addr, size, priv->loadaddr);
115
116 memcpy((void *)priv->loadaddr, (void *)addr, size);
117
118 debug("%s: Complete!\n", uc_pdata->name);
119 return 0;
120}
121
122/**
123 * ti_powerproc_start() - (replace: short desc)
124 * @dev: corresponding ti remote processor device
125 *
126 * Return: 0 if all went ok, else corresponding -ve error
127 */
128static int ti_powerproc_start(struct udevice *dev)
129{
130 struct dm_rproc_uclass_pdata *uc_pdata;
131 struct ti_powerproc_privdata *priv;
132 int ret;
133
Simon Glass71fa5b42020-12-03 16:55:18 -0700134 uc_pdata = dev_get_uclass_plat(dev);
Nishanth Menon129a1142016-02-25 12:53:45 -0600135 if (!uc_pdata) {
136 debug("%s: no uc pdata!\n", dev->name);
137 return -EINVAL;
138 }
139
140 priv = dev_get_priv(dev);
141 ret = psc_disable_module(priv->psc_module);
142 if (ret) {
143 debug("%s Unable to disable module '%d'(ret=%d)\n",
144 uc_pdata->name, priv->psc_module, ret);
145 return ret;
146 }
147
148 ret = psc_module_release_from_reset(priv->psc_module);
149 if (ret) {
150 debug("%s Failed to wait for module '%d'(ret=%d)\n",
151 uc_pdata->name, priv->psc_module, ret);
152 return ret;
153 }
154 ret = psc_enable_module(priv->psc_module);
155 if (ret) {
156 debug("%s Unable to disable module '%d'(ret=%d)\n",
157 uc_pdata->name, priv->psc_module, ret);
158 return ret;
159 }
160
161 return 0;
162}
163
164static const struct dm_rproc_ops ti_powerproc_ops = {
165 .load = ti_powerproc_load,
166 .start = ti_powerproc_start,
167};
168
169static const struct udevice_id ti_powerproc_ids[] = {
170 {.compatible = "ti,power-processor"},
171 {}
172};
173
174U_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,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700180 .priv_auto = sizeof(struct ti_powerproc_privdata),
Nishanth Menon129a1142016-02-25 12:53:45 -0600181};