blob: 99f11000dfbf5a2fa54687baa8068faf81279648 [file] [log] [blame]
Lokesh Vutlafdae32e2018-08-27 15:57:52 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
Lokesh Vutla247418b2019-06-07 19:25:59 +05303 * Texas Instruments' K3 ARM64 Remoteproc driver
Lokesh Vutlafdae32e2018-08-27 15:57:52 +05304 *
5 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
6 * Lokesh Vutla <lokeshvutla@ti.com>
7 *
8 */
9
10#include <common.h>
11#include <dm.h>
12#include <remoteproc.h>
13#include <errno.h>
14#include <clk.h>
15#include <reset.h>
16#include <asm/io.h>
17#include <power-domain.h>
Simon Glass9bc15642020-02-03 07:36:16 -070018#include <dm/device_compat.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070019#include <linux/err.h>
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053020#include <linux/soc/ti/ti_sci_protocol.h>
Lokesh Vutla142611f2019-06-07 19:25:58 +053021#include "ti_sci_proc.h"
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053022
23#define INVALID_ID 0xffff
24
25#define GTC_CNTCR_REG 0x0
Nishanth Menonf26b45c2021-01-06 13:20:32 -060026#define GTC_CNTFID0_REG 0x20
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053027#define GTC_CNTR_EN 0x3
28
29/**
Lokesh Vutla247418b2019-06-07 19:25:59 +053030 * struct k3_arm64_privdata - Structure representing Remote processor data.
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053031 * @rproc_pwrdmn: rproc power domain data
32 * @rproc_rst: rproc reset control data
33 * @sci: Pointer to TISCI handle
Lokesh Vutla142611f2019-06-07 19:25:58 +053034 * @tsp: TISCI processor control helper structure
Nishanth Menonf26b45c2021-01-06 13:20:32 -060035 * @gtc_clk: GTC clock description
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053036 * @gtc_base: Timer base address.
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053037 */
Lokesh Vutla247418b2019-06-07 19:25:59 +053038struct k3_arm64_privdata {
Manorit Chawdhrya62bd8c2023-04-14 09:48:00 +053039 bool has_cluster_node;
40 struct power_domain cluster_pwrdmn;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053041 struct power_domain rproc_pwrdmn;
42 struct power_domain gtc_pwrdmn;
43 struct reset_ctl rproc_rst;
Lokesh Vutla142611f2019-06-07 19:25:58 +053044 struct ti_sci_proc tsp;
Nishanth Menonf26b45c2021-01-06 13:20:32 -060045 struct clk gtc_clk;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053046 void *gtc_base;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053047};
48
49/**
Lokesh Vutla247418b2019-06-07 19:25:59 +053050 * k3_arm64_load() - Load up the Remote processor image
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053051 * @dev: rproc device pointer
52 * @addr: Address at which image is available
53 * @size: size of the image
54 *
55 * Return: 0 if all goes good, else appropriate error message.
56 */
Lokesh Vutla247418b2019-06-07 19:25:59 +053057static int k3_arm64_load(struct udevice *dev, ulong addr, ulong size)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053058{
Lokesh Vutla247418b2019-06-07 19:25:59 +053059 struct k3_arm64_privdata *rproc = dev_get_priv(dev);
Manorit Chawdhrya62bd8c2023-04-14 09:48:00 +053060 ulong gtc_rate;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053061 int ret;
62
63 dev_dbg(dev, "%s addr = 0x%lx, size = 0x%lx\n", __func__, addr, size);
64
65 /* request for the processor */
Lokesh Vutla142611f2019-06-07 19:25:58 +053066 ret = ti_sci_proc_request(&rproc->tsp);
67 if (ret)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053068 return ret;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053069
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053070 ret = power_domain_on(&rproc->gtc_pwrdmn);
71 if (ret) {
Manorit Chawdhrya62bd8c2023-04-14 09:48:00 +053072 dev_err(dev, "power_domain_on(&rproc->gtc_pwrdmn) failed: %d\n",
73 ret);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053074 return ret;
75 }
76
Nishanth Menonf26b45c2021-01-06 13:20:32 -060077 gtc_rate = clk_get_rate(&rproc->gtc_clk);
78 dev_dbg(dev, "GTC RATE= %d\n", (u32) gtc_rate);
79 /* Store the clock frequency down for GTC users to pick up */
80 writel((u32)gtc_rate, rproc->gtc_base + GTC_CNTFID0_REG);
81
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053082 /* Enable the timer before starting remote core */
83 writel(GTC_CNTR_EN, rproc->gtc_base + GTC_CNTCR_REG);
84
85 /*
86 * Setting the right clock frequency would have taken care by
87 * assigned-clock-rates during the device probe. So no need to
88 * set the frequency again here.
89 */
Manorit Chawdhrya62bd8c2023-04-14 09:48:00 +053090 if (rproc->has_cluster_node) {
91 ret = power_domain_on(&rproc->cluster_pwrdmn);
92 if (ret) {
93 dev_err(dev,
94 "power_domain_on(&rproc->cluster_pwrdmn) failed: %d\n",
95 ret);
96 return ret;
97 }
98 }
99
100 return ti_sci_proc_set_config(&rproc->tsp, addr, 0, 0);
101}
102
103/**
104 * k3_arm64_start() - Start the remote processor
105 * @dev: rproc device pointer
106 *
107 * Return: 0 if all went ok, else return appropriate error
108 */
109static int k3_arm64_start(struct udevice *dev)
110{
111 struct k3_arm64_privdata *rproc = dev_get_priv(dev);
112 int ret;
113
114 dev_dbg(dev, "%s\n", __func__);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530115 ret = power_domain_on(&rproc->rproc_pwrdmn);
116 if (ret) {
Manorit Chawdhrya62bd8c2023-04-14 09:48:00 +0530117 dev_err(dev,
118 "power_domain_on(&rproc->rproc_pwrdmn) failed: %d\n",
119 ret);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530120 return ret;
121 }
122
Lokesh Vutla142611f2019-06-07 19:25:58 +0530123 return ti_sci_proc_release(&rproc->tsp);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530124}
125
126/**
Lokesh Vutla247418b2019-06-07 19:25:59 +0530127 * k3_arm64_init() - Initialize the remote processor
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530128 * @dev: rproc device pointer
129 *
130 * Return: 0 if all went ok, else return appropriate error
131 */
Lokesh Vutla247418b2019-06-07 19:25:59 +0530132static int k3_arm64_init(struct udevice *dev)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530133{
134 dev_dbg(dev, "%s\n", __func__);
135
136 /* Enable the module */
137 dev_dbg(dev, "%s: rproc successfully initialized\n", __func__);
138
139 return 0;
140}
141
Lokesh Vutla247418b2019-06-07 19:25:59 +0530142static const struct dm_rproc_ops k3_arm64_ops = {
143 .init = k3_arm64_init,
144 .load = k3_arm64_load,
145 .start = k3_arm64_start,
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530146};
147
Lokesh Vutla142611f2019-06-07 19:25:58 +0530148static int ti_sci_proc_of_to_priv(struct udevice *dev, struct ti_sci_proc *tsp)
149{
150 dev_dbg(dev, "%s\n", __func__);
151
152 tsp->sci = ti_sci_get_by_phandle(dev, "ti,sci");
153 if (IS_ERR(tsp->sci)) {
154 dev_err(dev, "ti_sci get failed: %ld\n", PTR_ERR(tsp->sci));
155 return PTR_ERR(tsp->sci);
156 }
157
158 tsp->proc_id = dev_read_u32_default(dev, "ti,sci-proc-id", INVALID_ID);
159 if (tsp->proc_id == INVALID_ID) {
160 dev_err(dev, "proc id not populated\n");
161 return -ENOENT;
162 }
163 tsp->host_id = dev_read_u32_default(dev, "ti,sci-host-id", INVALID_ID);
164 tsp->ops = &tsp->sci->ops.proc_ops;
165
166 return 0;
167}
168
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530169/**
170 * k3_of_to_priv() - generate private data from device tree
171 * @dev: corresponding k3 remote processor device
172 * @priv: pointer to driver specific private data
173 *
174 * Return: 0 if all goes good, else appropriate error message.
175 */
Lokesh Vutla247418b2019-06-07 19:25:59 +0530176static int k3_arm64_of_to_priv(struct udevice *dev,
177 struct k3_arm64_privdata *rproc)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530178{
179 int ret;
180
181 dev_dbg(dev, "%s\n", __func__);
182
Manorit Chawdhrya62bd8c2023-04-14 09:48:00 +0530183 /* Cluster needs to be powered on if firewalls are being configured */
184 rproc->has_cluster_node = true;
185 ret = power_domain_get_by_index(dev, &rproc->cluster_pwrdmn, 2);
186 if (ret) {
187 dev_dbg(dev, "warning: power_domain_get_cluster() failed: %d\n", ret);
188 rproc->has_cluster_node = false;
189 }
190
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530191 ret = power_domain_get_by_index(dev, &rproc->rproc_pwrdmn, 1);
192 if (ret) {
Manorit Chawdhrya62bd8c2023-04-14 09:48:00 +0530193 dev_err(dev, "power_domain_get_rproc() failed: %d\n", ret);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530194 return ret;
195 }
196
197 ret = power_domain_get_by_index(dev, &rproc->gtc_pwrdmn, 0);
198 if (ret) {
199 dev_err(dev, "power_domain_get() failed: %d\n", ret);
200 return ret;
201 }
202
Nishanth Menonf26b45c2021-01-06 13:20:32 -0600203 ret = clk_get_by_index(dev, 0, &rproc->gtc_clk);
204 if (ret) {
205 dev_err(dev, "clk_get failed: %d\n", ret);
206 return ret;
207 }
208
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530209 ret = reset_get_by_index(dev, 0, &rproc->rproc_rst);
210 if (ret) {
211 dev_err(dev, "reset_get() failed: %d\n", ret);
212 return ret;
213 }
214
Lokesh Vutla142611f2019-06-07 19:25:58 +0530215 ret = ti_sci_proc_of_to_priv(dev, &rproc->tsp);
216 if (ret)
217 return ret;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530218
219 rproc->gtc_base = dev_read_addr_ptr(dev);
220 if (!rproc->gtc_base) {
221 dev_err(dev, "Get address failed\n");
222 return -ENODEV;
223 }
224
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530225 return 0;
226}
227
228/**
Lokesh Vutla247418b2019-06-07 19:25:59 +0530229 * k3_arm64_probe() - Basic probe
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530230 * @dev: corresponding k3 remote processor device
231 *
232 * Return: 0 if all goes good, else appropriate error message.
233 */
Lokesh Vutla247418b2019-06-07 19:25:59 +0530234static int k3_arm64_probe(struct udevice *dev)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530235{
Lokesh Vutla247418b2019-06-07 19:25:59 +0530236 struct k3_arm64_privdata *priv;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530237 int ret;
238
239 dev_dbg(dev, "%s\n", __func__);
240
241 priv = dev_get_priv(dev);
242
Lokesh Vutla247418b2019-06-07 19:25:59 +0530243 ret = k3_arm64_of_to_priv(dev, priv);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530244 if (ret) {
245 dev_dbg(dev, "%s: Probe failed with error %d\n", __func__, ret);
246 return ret;
247 }
248
249 dev_dbg(dev, "Remoteproc successfully probed\n");
250
251 return 0;
252}
253
Lokesh Vutla247418b2019-06-07 19:25:59 +0530254static const struct udevice_id k3_arm64_ids[] = {
255 { .compatible = "ti,am654-arm64"},
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530256 { .compatible = "ti,am654-rproc"},
257 {}
258};
259
Lokesh Vutla247418b2019-06-07 19:25:59 +0530260U_BOOT_DRIVER(k3_arm64) = {
261 .name = "k3_arm64",
262 .of_match = k3_arm64_ids,
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530263 .id = UCLASS_REMOTEPROC,
Lokesh Vutla247418b2019-06-07 19:25:59 +0530264 .ops = &k3_arm64_ops,
265 .probe = k3_arm64_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700266 .priv_auto = sizeof(struct k3_arm64_privdata),
Lokesh Vutla01cfdf72019-09-27 13:48:13 +0530267 .flags = DM_FLAG_DEFAULT_PD_CTRL_OFF,
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530268};