blob: 6887a3c8541fccfba08b0bfe5f35c005f9e0c0c4 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Nishanth Menon42392842016-02-25 12:53:45 -06002/*
3 * (C) Copyright 2015-2016
4 * Texas Instruments Incorporated - http://www.ti.com/
Nishanth Menon42392842016-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 Glassf7ae49f2020-05-10 11:40:05 -060011#include <log.h>
Nishanth Menon42392842016-02-25 12:53:45 -060012#include <remoteproc.h>
Simon Glass401d1c42020-10-30 21:38:53 -060013#include <asm/global_data.h>
Simon Glass1e94b462023-09-14 18:21:46 -060014#include <linux/printk.h>
Nishanth Menon42392842016-02-25 12:53:45 -060015#include <mach/psc_defs.h>
16
17DECLARE_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 */
24struct 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 */
36static int ti_of_to_priv(struct udevice *dev,
37 struct ti_powerproc_privdata *priv)
38{
Simon Glasse160f7d2017-01-17 16:52:55 -070039 int node = dev_of_offset(dev);
Nishanth Menon42392842016-02-25 12:53:45 -060040 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 */
70static 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 Glasscaa4daa2020-12-03 16:55:18 -070076 uc_pdata = dev_get_uclass_plat(dev);
Nishanth Menon42392842016-02-25 12:53:45 -060077 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 */
95static 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 Glasscaa4daa2020-12-03 16:55:18 -0700101 uc_pdata = dev_get_uclass_plat(dev);
Nishanth Menon42392842016-02-25 12:53:45 -0600102 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 */
130static 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 Glasscaa4daa2020-12-03 16:55:18 -0700136 uc_pdata = dev_get_uclass_plat(dev);
Nishanth Menon42392842016-02-25 12:53:45 -0600137 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
166static const struct dm_rproc_ops ti_powerproc_ops = {
167 .load = ti_powerproc_load,
168 .start = ti_powerproc_start,
169};
170
171static const struct udevice_id ti_powerproc_ids[] = {
172 {.compatible = "ti,power-processor"},
173 {}
174};
175
176U_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 Glass41575d82020-12-03 16:55:17 -0700182 .priv_auto = sizeof(struct ti_powerproc_privdata),
Nishanth Menon42392842016-02-25 12:53:45 -0600183};