blob: 1f2415dc1a68d4619ba17374f7782c9f57de25d9 [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 {
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053039 struct power_domain rproc_pwrdmn;
40 struct power_domain gtc_pwrdmn;
41 struct reset_ctl rproc_rst;
Lokesh Vutla142611f2019-06-07 19:25:58 +053042 struct ti_sci_proc tsp;
Nishanth Menonf26b45c2021-01-06 13:20:32 -060043 struct clk gtc_clk;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053044 void *gtc_base;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053045};
46
47/**
Lokesh Vutla247418b2019-06-07 19:25:59 +053048 * k3_arm64_load() - Load up the Remote processor image
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053049 * @dev: rproc device pointer
50 * @addr: Address at which image is available
51 * @size: size of the image
52 *
53 * Return: 0 if all goes good, else appropriate error message.
54 */
Lokesh Vutla247418b2019-06-07 19:25:59 +053055static int k3_arm64_load(struct udevice *dev, ulong addr, ulong size)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053056{
Lokesh Vutla247418b2019-06-07 19:25:59 +053057 struct k3_arm64_privdata *rproc = dev_get_priv(dev);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053058 int ret;
59
60 dev_dbg(dev, "%s addr = 0x%lx, size = 0x%lx\n", __func__, addr, size);
61
62 /* request for the processor */
Lokesh Vutla142611f2019-06-07 19:25:58 +053063 ret = ti_sci_proc_request(&rproc->tsp);
64 if (ret)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053065 return ret;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053066
Lokesh Vutla142611f2019-06-07 19:25:58 +053067 return ti_sci_proc_set_config(&rproc->tsp, addr, 0, 0);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053068}
69
70/**
Lokesh Vutla247418b2019-06-07 19:25:59 +053071 * k3_arm64_start() - Start the remote processor
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053072 * @dev: rproc device pointer
73 *
74 * Return: 0 if all went ok, else return appropriate error
75 */
Lokesh Vutla247418b2019-06-07 19:25:59 +053076static int k3_arm64_start(struct udevice *dev)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053077{
Lokesh Vutla247418b2019-06-07 19:25:59 +053078 struct k3_arm64_privdata *rproc = dev_get_priv(dev);
Nishanth Menonf26b45c2021-01-06 13:20:32 -060079 ulong gtc_rate;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053080 int ret;
81
82 dev_dbg(dev, "%s\n", __func__);
83
84 ret = power_domain_on(&rproc->gtc_pwrdmn);
85 if (ret) {
86 dev_err(dev, "power_domain_on() failed: %d\n", ret);
87 return ret;
88 }
89
Nishanth Menonf26b45c2021-01-06 13:20:32 -060090 gtc_rate = clk_get_rate(&rproc->gtc_clk);
91 dev_dbg(dev, "GTC RATE= %d\n", (u32) gtc_rate);
92 /* Store the clock frequency down for GTC users to pick up */
93 writel((u32)gtc_rate, rproc->gtc_base + GTC_CNTFID0_REG);
94
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053095 /* Enable the timer before starting remote core */
96 writel(GTC_CNTR_EN, rproc->gtc_base + GTC_CNTCR_REG);
97
98 /*
99 * Setting the right clock frequency would have taken care by
100 * assigned-clock-rates during the device probe. So no need to
101 * set the frequency again here.
102 */
103 ret = power_domain_on(&rproc->rproc_pwrdmn);
104 if (ret) {
105 dev_err(dev, "power_domain_on() failed: %d\n", ret);
106 return ret;
107 }
108
Lokesh Vutla142611f2019-06-07 19:25:58 +0530109 return ti_sci_proc_release(&rproc->tsp);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530110}
111
112/**
Lokesh Vutla247418b2019-06-07 19:25:59 +0530113 * k3_arm64_init() - Initialize the remote processor
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530114 * @dev: rproc device pointer
115 *
116 * Return: 0 if all went ok, else return appropriate error
117 */
Lokesh Vutla247418b2019-06-07 19:25:59 +0530118static int k3_arm64_init(struct udevice *dev)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530119{
120 dev_dbg(dev, "%s\n", __func__);
121
122 /* Enable the module */
123 dev_dbg(dev, "%s: rproc successfully initialized\n", __func__);
124
125 return 0;
126}
127
Lokesh Vutla247418b2019-06-07 19:25:59 +0530128static const struct dm_rproc_ops k3_arm64_ops = {
129 .init = k3_arm64_init,
130 .load = k3_arm64_load,
131 .start = k3_arm64_start,
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530132};
133
Lokesh Vutla142611f2019-06-07 19:25:58 +0530134static int ti_sci_proc_of_to_priv(struct udevice *dev, struct ti_sci_proc *tsp)
135{
136 dev_dbg(dev, "%s\n", __func__);
137
138 tsp->sci = ti_sci_get_by_phandle(dev, "ti,sci");
139 if (IS_ERR(tsp->sci)) {
140 dev_err(dev, "ti_sci get failed: %ld\n", PTR_ERR(tsp->sci));
141 return PTR_ERR(tsp->sci);
142 }
143
144 tsp->proc_id = dev_read_u32_default(dev, "ti,sci-proc-id", INVALID_ID);
145 if (tsp->proc_id == INVALID_ID) {
146 dev_err(dev, "proc id not populated\n");
147 return -ENOENT;
148 }
149 tsp->host_id = dev_read_u32_default(dev, "ti,sci-host-id", INVALID_ID);
150 tsp->ops = &tsp->sci->ops.proc_ops;
151
152 return 0;
153}
154
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530155/**
156 * k3_of_to_priv() - generate private data from device tree
157 * @dev: corresponding k3 remote processor device
158 * @priv: pointer to driver specific private data
159 *
160 * Return: 0 if all goes good, else appropriate error message.
161 */
Lokesh Vutla247418b2019-06-07 19:25:59 +0530162static int k3_arm64_of_to_priv(struct udevice *dev,
163 struct k3_arm64_privdata *rproc)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530164{
165 int ret;
166
167 dev_dbg(dev, "%s\n", __func__);
168
169 ret = power_domain_get_by_index(dev, &rproc->rproc_pwrdmn, 1);
170 if (ret) {
171 dev_err(dev, "power_domain_get() failed: %d\n", ret);
172 return ret;
173 }
174
175 ret = power_domain_get_by_index(dev, &rproc->gtc_pwrdmn, 0);
176 if (ret) {
177 dev_err(dev, "power_domain_get() failed: %d\n", ret);
178 return ret;
179 }
180
Nishanth Menonf26b45c2021-01-06 13:20:32 -0600181 ret = clk_get_by_index(dev, 0, &rproc->gtc_clk);
182 if (ret) {
183 dev_err(dev, "clk_get failed: %d\n", ret);
184 return ret;
185 }
186
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530187 ret = reset_get_by_index(dev, 0, &rproc->rproc_rst);
188 if (ret) {
189 dev_err(dev, "reset_get() failed: %d\n", ret);
190 return ret;
191 }
192
Lokesh Vutla142611f2019-06-07 19:25:58 +0530193 ret = ti_sci_proc_of_to_priv(dev, &rproc->tsp);
194 if (ret)
195 return ret;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530196
197 rproc->gtc_base = dev_read_addr_ptr(dev);
198 if (!rproc->gtc_base) {
199 dev_err(dev, "Get address failed\n");
200 return -ENODEV;
201 }
202
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530203 return 0;
204}
205
206/**
Lokesh Vutla247418b2019-06-07 19:25:59 +0530207 * k3_arm64_probe() - Basic probe
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530208 * @dev: corresponding k3 remote processor device
209 *
210 * Return: 0 if all goes good, else appropriate error message.
211 */
Lokesh Vutla247418b2019-06-07 19:25:59 +0530212static int k3_arm64_probe(struct udevice *dev)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530213{
Lokesh Vutla247418b2019-06-07 19:25:59 +0530214 struct k3_arm64_privdata *priv;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530215 int ret;
216
217 dev_dbg(dev, "%s\n", __func__);
218
219 priv = dev_get_priv(dev);
220
Lokesh Vutla247418b2019-06-07 19:25:59 +0530221 ret = k3_arm64_of_to_priv(dev, priv);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530222 if (ret) {
223 dev_dbg(dev, "%s: Probe failed with error %d\n", __func__, ret);
224 return ret;
225 }
226
227 dev_dbg(dev, "Remoteproc successfully probed\n");
228
229 return 0;
230}
231
Lokesh Vutla247418b2019-06-07 19:25:59 +0530232static const struct udevice_id k3_arm64_ids[] = {
233 { .compatible = "ti,am654-arm64"},
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530234 { .compatible = "ti,am654-rproc"},
235 {}
236};
237
Lokesh Vutla247418b2019-06-07 19:25:59 +0530238U_BOOT_DRIVER(k3_arm64) = {
239 .name = "k3_arm64",
240 .of_match = k3_arm64_ids,
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530241 .id = UCLASS_REMOTEPROC,
Lokesh Vutla247418b2019-06-07 19:25:59 +0530242 .ops = &k3_arm64_ops,
243 .probe = k3_arm64_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700244 .priv_auto = sizeof(struct k3_arm64_privdata),
Lokesh Vutla01cfdf72019-09-27 13:48:13 +0530245 .flags = DM_FLAG_DEFAULT_PD_CTRL_OFF,
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530246};