blob: 28c6ddb691913d98a3a18802a88a213e7777d888 [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
26#define GTC_CNTR_EN 0x3
27
28/**
Lokesh Vutla247418b2019-06-07 19:25:59 +053029 * struct k3_arm64_privdata - Structure representing Remote processor data.
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053030 * @rproc_pwrdmn: rproc power domain data
31 * @rproc_rst: rproc reset control data
32 * @sci: Pointer to TISCI handle
Lokesh Vutla142611f2019-06-07 19:25:58 +053033 * @tsp: TISCI processor control helper structure
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053034 * @gtc_base: Timer base address.
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053035 */
Lokesh Vutla247418b2019-06-07 19:25:59 +053036struct k3_arm64_privdata {
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053037 struct power_domain rproc_pwrdmn;
38 struct power_domain gtc_pwrdmn;
39 struct reset_ctl rproc_rst;
Lokesh Vutla142611f2019-06-07 19:25:58 +053040 struct ti_sci_proc tsp;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053041 void *gtc_base;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053042};
43
44/**
Lokesh Vutla247418b2019-06-07 19:25:59 +053045 * k3_arm64_load() - Load up the Remote processor image
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053046 * @dev: rproc device pointer
47 * @addr: Address at which image is available
48 * @size: size of the image
49 *
50 * Return: 0 if all goes good, else appropriate error message.
51 */
Lokesh Vutla247418b2019-06-07 19:25:59 +053052static int k3_arm64_load(struct udevice *dev, ulong addr, ulong size)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053053{
Lokesh Vutla247418b2019-06-07 19:25:59 +053054 struct k3_arm64_privdata *rproc = dev_get_priv(dev);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053055 int ret;
56
57 dev_dbg(dev, "%s addr = 0x%lx, size = 0x%lx\n", __func__, addr, size);
58
59 /* request for the processor */
Lokesh Vutla142611f2019-06-07 19:25:58 +053060 ret = ti_sci_proc_request(&rproc->tsp);
61 if (ret)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053062 return ret;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053063
Lokesh Vutla142611f2019-06-07 19:25:58 +053064 return ti_sci_proc_set_config(&rproc->tsp, addr, 0, 0);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053065}
66
67/**
Lokesh Vutla247418b2019-06-07 19:25:59 +053068 * k3_arm64_start() - Start the remote processor
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053069 * @dev: rproc device pointer
70 *
71 * Return: 0 if all went ok, else return appropriate error
72 */
Lokesh Vutla247418b2019-06-07 19:25:59 +053073static int k3_arm64_start(struct udevice *dev)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053074{
Lokesh Vutla247418b2019-06-07 19:25:59 +053075 struct k3_arm64_privdata *rproc = dev_get_priv(dev);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +053076 int ret;
77
78 dev_dbg(dev, "%s\n", __func__);
79
80 ret = power_domain_on(&rproc->gtc_pwrdmn);
81 if (ret) {
82 dev_err(dev, "power_domain_on() failed: %d\n", ret);
83 return ret;
84 }
85
86 /* Enable the timer before starting remote core */
87 writel(GTC_CNTR_EN, rproc->gtc_base + GTC_CNTCR_REG);
88
89 /*
90 * Setting the right clock frequency would have taken care by
91 * assigned-clock-rates during the device probe. So no need to
92 * set the frequency again here.
93 */
94 ret = power_domain_on(&rproc->rproc_pwrdmn);
95 if (ret) {
96 dev_err(dev, "power_domain_on() failed: %d\n", ret);
97 return ret;
98 }
99
Lokesh Vutla142611f2019-06-07 19:25:58 +0530100 return ti_sci_proc_release(&rproc->tsp);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530101}
102
103/**
Lokesh Vutla247418b2019-06-07 19:25:59 +0530104 * k3_arm64_init() - Initialize the remote processor
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530105 * @dev: rproc device pointer
106 *
107 * Return: 0 if all went ok, else return appropriate error
108 */
Lokesh Vutla247418b2019-06-07 19:25:59 +0530109static int k3_arm64_init(struct udevice *dev)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530110{
111 dev_dbg(dev, "%s\n", __func__);
112
113 /* Enable the module */
114 dev_dbg(dev, "%s: rproc successfully initialized\n", __func__);
115
116 return 0;
117}
118
Lokesh Vutla247418b2019-06-07 19:25:59 +0530119static const struct dm_rproc_ops k3_arm64_ops = {
120 .init = k3_arm64_init,
121 .load = k3_arm64_load,
122 .start = k3_arm64_start,
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530123};
124
Lokesh Vutla142611f2019-06-07 19:25:58 +0530125static int ti_sci_proc_of_to_priv(struct udevice *dev, struct ti_sci_proc *tsp)
126{
127 dev_dbg(dev, "%s\n", __func__);
128
129 tsp->sci = ti_sci_get_by_phandle(dev, "ti,sci");
130 if (IS_ERR(tsp->sci)) {
131 dev_err(dev, "ti_sci get failed: %ld\n", PTR_ERR(tsp->sci));
132 return PTR_ERR(tsp->sci);
133 }
134
135 tsp->proc_id = dev_read_u32_default(dev, "ti,sci-proc-id", INVALID_ID);
136 if (tsp->proc_id == INVALID_ID) {
137 dev_err(dev, "proc id not populated\n");
138 return -ENOENT;
139 }
140 tsp->host_id = dev_read_u32_default(dev, "ti,sci-host-id", INVALID_ID);
141 tsp->ops = &tsp->sci->ops.proc_ops;
142
143 return 0;
144}
145
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530146/**
147 * k3_of_to_priv() - generate private data from device tree
148 * @dev: corresponding k3 remote processor device
149 * @priv: pointer to driver specific private data
150 *
151 * Return: 0 if all goes good, else appropriate error message.
152 */
Lokesh Vutla247418b2019-06-07 19:25:59 +0530153static int k3_arm64_of_to_priv(struct udevice *dev,
154 struct k3_arm64_privdata *rproc)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530155{
156 int ret;
157
158 dev_dbg(dev, "%s\n", __func__);
159
160 ret = power_domain_get_by_index(dev, &rproc->rproc_pwrdmn, 1);
161 if (ret) {
162 dev_err(dev, "power_domain_get() failed: %d\n", ret);
163 return ret;
164 }
165
166 ret = power_domain_get_by_index(dev, &rproc->gtc_pwrdmn, 0);
167 if (ret) {
168 dev_err(dev, "power_domain_get() failed: %d\n", ret);
169 return ret;
170 }
171
172 ret = reset_get_by_index(dev, 0, &rproc->rproc_rst);
173 if (ret) {
174 dev_err(dev, "reset_get() failed: %d\n", ret);
175 return ret;
176 }
177
Lokesh Vutla142611f2019-06-07 19:25:58 +0530178 ret = ti_sci_proc_of_to_priv(dev, &rproc->tsp);
179 if (ret)
180 return ret;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530181
182 rproc->gtc_base = dev_read_addr_ptr(dev);
183 if (!rproc->gtc_base) {
184 dev_err(dev, "Get address failed\n");
185 return -ENODEV;
186 }
187
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530188 return 0;
189}
190
191/**
Lokesh Vutla247418b2019-06-07 19:25:59 +0530192 * k3_arm64_probe() - Basic probe
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530193 * @dev: corresponding k3 remote processor device
194 *
195 * Return: 0 if all goes good, else appropriate error message.
196 */
Lokesh Vutla247418b2019-06-07 19:25:59 +0530197static int k3_arm64_probe(struct udevice *dev)
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530198{
Lokesh Vutla247418b2019-06-07 19:25:59 +0530199 struct k3_arm64_privdata *priv;
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530200 int ret;
201
202 dev_dbg(dev, "%s\n", __func__);
203
204 priv = dev_get_priv(dev);
205
Lokesh Vutla247418b2019-06-07 19:25:59 +0530206 ret = k3_arm64_of_to_priv(dev, priv);
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530207 if (ret) {
208 dev_dbg(dev, "%s: Probe failed with error %d\n", __func__, ret);
209 return ret;
210 }
211
212 dev_dbg(dev, "Remoteproc successfully probed\n");
213
214 return 0;
215}
216
Lokesh Vutla247418b2019-06-07 19:25:59 +0530217static const struct udevice_id k3_arm64_ids[] = {
218 { .compatible = "ti,am654-arm64"},
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530219 { .compatible = "ti,am654-rproc"},
220 {}
221};
222
Lokesh Vutla247418b2019-06-07 19:25:59 +0530223U_BOOT_DRIVER(k3_arm64) = {
224 .name = "k3_arm64",
225 .of_match = k3_arm64_ids,
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530226 .id = UCLASS_REMOTEPROC,
Lokesh Vutla247418b2019-06-07 19:25:59 +0530227 .ops = &k3_arm64_ops,
228 .probe = k3_arm64_probe,
229 .priv_auto_alloc_size = sizeof(struct k3_arm64_privdata),
Lokesh Vutla01cfdf72019-09-27 13:48:13 +0530230 .flags = DM_FLAG_DEFAULT_PD_CTRL_OFF,
Lokesh Vutlafdae32e2018-08-27 15:57:52 +0530231};