blob: 3e35293514ed6ffa287dc601b962cbfce24da4d8 [file] [log] [blame]
Lokesh Vutlac365ed72018-08-27 15:57:52 +05301// SPDX-License-Identifier: GPL-2.0+
2/*
Lokesh Vutla54e43112019-06-07 19:25:59 +05303 * Texas Instruments' K3 ARM64 Remoteproc driver
Lokesh Vutlac365ed72018-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>
18#include <linux/soc/ti/ti_sci_protocol.h>
Lokesh Vutla44de37a2019-06-07 19:25:58 +053019#include "ti_sci_proc.h"
Lokesh Vutlac365ed72018-08-27 15:57:52 +053020
21#define INVALID_ID 0xffff
22
23#define GTC_CNTCR_REG 0x0
24#define GTC_CNTR_EN 0x3
25
26/**
Lokesh Vutla54e43112019-06-07 19:25:59 +053027 * struct k3_arm64_privdata - Structure representing Remote processor data.
Lokesh Vutlac365ed72018-08-27 15:57:52 +053028 * @rproc_pwrdmn: rproc power domain data
29 * @rproc_rst: rproc reset control data
30 * @sci: Pointer to TISCI handle
Lokesh Vutla44de37a2019-06-07 19:25:58 +053031 * @tsp: TISCI processor control helper structure
Lokesh Vutlac365ed72018-08-27 15:57:52 +053032 * @gtc_base: Timer base address.
Lokesh Vutlac365ed72018-08-27 15:57:52 +053033 */
Lokesh Vutla54e43112019-06-07 19:25:59 +053034struct k3_arm64_privdata {
Lokesh Vutlac365ed72018-08-27 15:57:52 +053035 struct power_domain rproc_pwrdmn;
36 struct power_domain gtc_pwrdmn;
37 struct reset_ctl rproc_rst;
Lokesh Vutla44de37a2019-06-07 19:25:58 +053038 struct ti_sci_proc tsp;
Lokesh Vutlac365ed72018-08-27 15:57:52 +053039 void *gtc_base;
Lokesh Vutlac365ed72018-08-27 15:57:52 +053040};
41
42/**
Lokesh Vutla54e43112019-06-07 19:25:59 +053043 * k3_arm64_load() - Load up the Remote processor image
Lokesh Vutlac365ed72018-08-27 15:57:52 +053044 * @dev: rproc device pointer
45 * @addr: Address at which image is available
46 * @size: size of the image
47 *
48 * Return: 0 if all goes good, else appropriate error message.
49 */
Lokesh Vutla54e43112019-06-07 19:25:59 +053050static int k3_arm64_load(struct udevice *dev, ulong addr, ulong size)
Lokesh Vutlac365ed72018-08-27 15:57:52 +053051{
Lokesh Vutla54e43112019-06-07 19:25:59 +053052 struct k3_arm64_privdata *rproc = dev_get_priv(dev);
Lokesh Vutlac365ed72018-08-27 15:57:52 +053053 int ret;
54
55 dev_dbg(dev, "%s addr = 0x%lx, size = 0x%lx\n", __func__, addr, size);
56
57 /* request for the processor */
Lokesh Vutla44de37a2019-06-07 19:25:58 +053058 ret = ti_sci_proc_request(&rproc->tsp);
59 if (ret)
Lokesh Vutlac365ed72018-08-27 15:57:52 +053060 return ret;
Lokesh Vutlac365ed72018-08-27 15:57:52 +053061
Lokesh Vutla44de37a2019-06-07 19:25:58 +053062 return ti_sci_proc_set_config(&rproc->tsp, addr, 0, 0);
Lokesh Vutlac365ed72018-08-27 15:57:52 +053063}
64
65/**
Lokesh Vutla54e43112019-06-07 19:25:59 +053066 * k3_arm64_start() - Start the remote processor
Lokesh Vutlac365ed72018-08-27 15:57:52 +053067 * @dev: rproc device pointer
68 *
69 * Return: 0 if all went ok, else return appropriate error
70 */
Lokesh Vutla54e43112019-06-07 19:25:59 +053071static int k3_arm64_start(struct udevice *dev)
Lokesh Vutlac365ed72018-08-27 15:57:52 +053072{
Lokesh Vutla54e43112019-06-07 19:25:59 +053073 struct k3_arm64_privdata *rproc = dev_get_priv(dev);
Lokesh Vutlac365ed72018-08-27 15:57:52 +053074 int ret;
75
76 dev_dbg(dev, "%s\n", __func__);
77
78 ret = power_domain_on(&rproc->gtc_pwrdmn);
79 if (ret) {
80 dev_err(dev, "power_domain_on() failed: %d\n", ret);
81 return ret;
82 }
83
84 /* Enable the timer before starting remote core */
85 writel(GTC_CNTR_EN, rproc->gtc_base + GTC_CNTCR_REG);
86
87 /*
88 * Setting the right clock frequency would have taken care by
89 * assigned-clock-rates during the device probe. So no need to
90 * set the frequency again here.
91 */
92 ret = power_domain_on(&rproc->rproc_pwrdmn);
93 if (ret) {
94 dev_err(dev, "power_domain_on() failed: %d\n", ret);
95 return ret;
96 }
97
Lokesh Vutla44de37a2019-06-07 19:25:58 +053098 return ti_sci_proc_release(&rproc->tsp);
Lokesh Vutlac365ed72018-08-27 15:57:52 +053099}
100
101/**
Lokesh Vutla54e43112019-06-07 19:25:59 +0530102 * k3_arm64_init() - Initialize the remote processor
Lokesh Vutlac365ed72018-08-27 15:57:52 +0530103 * @dev: rproc device pointer
104 *
105 * Return: 0 if all went ok, else return appropriate error
106 */
Lokesh Vutla54e43112019-06-07 19:25:59 +0530107static int k3_arm64_init(struct udevice *dev)
Lokesh Vutlac365ed72018-08-27 15:57:52 +0530108{
109 dev_dbg(dev, "%s\n", __func__);
110
111 /* Enable the module */
112 dev_dbg(dev, "%s: rproc successfully initialized\n", __func__);
113
114 return 0;
115}
116
Lokesh Vutla54e43112019-06-07 19:25:59 +0530117static const struct dm_rproc_ops k3_arm64_ops = {
118 .init = k3_arm64_init,
119 .load = k3_arm64_load,
120 .start = k3_arm64_start,
Lokesh Vutlac365ed72018-08-27 15:57:52 +0530121};
122
Lokesh Vutla44de37a2019-06-07 19:25:58 +0530123static int ti_sci_proc_of_to_priv(struct udevice *dev, struct ti_sci_proc *tsp)
124{
125 dev_dbg(dev, "%s\n", __func__);
126
127 tsp->sci = ti_sci_get_by_phandle(dev, "ti,sci");
128 if (IS_ERR(tsp->sci)) {
129 dev_err(dev, "ti_sci get failed: %ld\n", PTR_ERR(tsp->sci));
130 return PTR_ERR(tsp->sci);
131 }
132
133 tsp->proc_id = dev_read_u32_default(dev, "ti,sci-proc-id", INVALID_ID);
134 if (tsp->proc_id == INVALID_ID) {
135 dev_err(dev, "proc id not populated\n");
136 return -ENOENT;
137 }
138 tsp->host_id = dev_read_u32_default(dev, "ti,sci-host-id", INVALID_ID);
139 tsp->ops = &tsp->sci->ops.proc_ops;
140
141 return 0;
142}
143
Lokesh Vutlac365ed72018-08-27 15:57:52 +0530144/**
145 * k3_of_to_priv() - generate private data from device tree
146 * @dev: corresponding k3 remote processor device
147 * @priv: pointer to driver specific private data
148 *
149 * Return: 0 if all goes good, else appropriate error message.
150 */
Lokesh Vutla54e43112019-06-07 19:25:59 +0530151static int k3_arm64_of_to_priv(struct udevice *dev,
152 struct k3_arm64_privdata *rproc)
Lokesh Vutlac365ed72018-08-27 15:57:52 +0530153{
154 int ret;
155
156 dev_dbg(dev, "%s\n", __func__);
157
158 ret = power_domain_get_by_index(dev, &rproc->rproc_pwrdmn, 1);
159 if (ret) {
160 dev_err(dev, "power_domain_get() failed: %d\n", ret);
161 return ret;
162 }
163
164 ret = power_domain_get_by_index(dev, &rproc->gtc_pwrdmn, 0);
165 if (ret) {
166 dev_err(dev, "power_domain_get() failed: %d\n", ret);
167 return ret;
168 }
169
170 ret = reset_get_by_index(dev, 0, &rproc->rproc_rst);
171 if (ret) {
172 dev_err(dev, "reset_get() failed: %d\n", ret);
173 return ret;
174 }
175
Lokesh Vutla44de37a2019-06-07 19:25:58 +0530176 ret = ti_sci_proc_of_to_priv(dev, &rproc->tsp);
177 if (ret)
178 return ret;
Lokesh Vutlac365ed72018-08-27 15:57:52 +0530179
180 rproc->gtc_base = dev_read_addr_ptr(dev);
181 if (!rproc->gtc_base) {
182 dev_err(dev, "Get address failed\n");
183 return -ENODEV;
184 }
185
Lokesh Vutlac365ed72018-08-27 15:57:52 +0530186 return 0;
187}
188
189/**
Lokesh Vutla54e43112019-06-07 19:25:59 +0530190 * k3_arm64_probe() - Basic probe
Lokesh Vutlac365ed72018-08-27 15:57:52 +0530191 * @dev: corresponding k3 remote processor device
192 *
193 * Return: 0 if all goes good, else appropriate error message.
194 */
Lokesh Vutla54e43112019-06-07 19:25:59 +0530195static int k3_arm64_probe(struct udevice *dev)
Lokesh Vutlac365ed72018-08-27 15:57:52 +0530196{
Lokesh Vutla54e43112019-06-07 19:25:59 +0530197 struct k3_arm64_privdata *priv;
Lokesh Vutlac365ed72018-08-27 15:57:52 +0530198 int ret;
199
200 dev_dbg(dev, "%s\n", __func__);
201
202 priv = dev_get_priv(dev);
203
Lokesh Vutla54e43112019-06-07 19:25:59 +0530204 ret = k3_arm64_of_to_priv(dev, priv);
Lokesh Vutlac365ed72018-08-27 15:57:52 +0530205 if (ret) {
206 dev_dbg(dev, "%s: Probe failed with error %d\n", __func__, ret);
207 return ret;
208 }
209
210 dev_dbg(dev, "Remoteproc successfully probed\n");
211
212 return 0;
213}
214
Lokesh Vutla54e43112019-06-07 19:25:59 +0530215static const struct udevice_id k3_arm64_ids[] = {
216 { .compatible = "ti,am654-arm64"},
Lokesh Vutlac365ed72018-08-27 15:57:52 +0530217 { .compatible = "ti,am654-rproc"},
218 {}
219};
220
Lokesh Vutla54e43112019-06-07 19:25:59 +0530221U_BOOT_DRIVER(k3_arm64) = {
222 .name = "k3_arm64",
223 .of_match = k3_arm64_ids,
Lokesh Vutlac365ed72018-08-27 15:57:52 +0530224 .id = UCLASS_REMOTEPROC,
Lokesh Vutla54e43112019-06-07 19:25:59 +0530225 .ops = &k3_arm64_ops,
226 .probe = k3_arm64_probe,
227 .priv_auto_alloc_size = sizeof(struct k3_arm64_privdata),
Lokesh Vutlaaf17b0d2019-09-27 13:48:13 +0530228 .flags = DM_FLAG_DEFAULT_PD_CTRL_OFF,
Lokesh Vutlac365ed72018-08-27 15:57:52 +0530229};