2018-08-27 10:27:52 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
2019-06-07 13:55:59 +00:00
|
|
|
* Texas Instruments' K3 ARM64 Remoteproc driver
|
2018-08-27 10:27:52 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
|
|
|
|
* Lokesh Vutla <lokeshvutla@ti.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <remoteproc.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <clk.h>
|
|
|
|
#include <reset.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <power-domain.h>
|
|
|
|
#include <linux/soc/ti/ti_sci_protocol.h>
|
2019-06-07 13:55:58 +00:00
|
|
|
#include "ti_sci_proc.h"
|
2018-08-27 10:27:52 +00:00
|
|
|
|
|
|
|
#define INVALID_ID 0xffff
|
|
|
|
|
|
|
|
#define GTC_CNTCR_REG 0x0
|
|
|
|
#define GTC_CNTR_EN 0x3
|
|
|
|
|
|
|
|
/**
|
2019-06-07 13:55:59 +00:00
|
|
|
* struct k3_arm64_privdata - Structure representing Remote processor data.
|
2018-08-27 10:27:52 +00:00
|
|
|
* @rproc_pwrdmn: rproc power domain data
|
|
|
|
* @rproc_rst: rproc reset control data
|
|
|
|
* @sci: Pointer to TISCI handle
|
2019-06-07 13:55:58 +00:00
|
|
|
* @tsp: TISCI processor control helper structure
|
2018-08-27 10:27:52 +00:00
|
|
|
* @gtc_base: Timer base address.
|
|
|
|
*/
|
2019-06-07 13:55:59 +00:00
|
|
|
struct k3_arm64_privdata {
|
2018-08-27 10:27:52 +00:00
|
|
|
struct power_domain rproc_pwrdmn;
|
|
|
|
struct power_domain gtc_pwrdmn;
|
|
|
|
struct reset_ctl rproc_rst;
|
2019-06-07 13:55:58 +00:00
|
|
|
struct ti_sci_proc tsp;
|
2018-08-27 10:27:52 +00:00
|
|
|
void *gtc_base;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2019-06-07 13:55:59 +00:00
|
|
|
* k3_arm64_load() - Load up the Remote processor image
|
2018-08-27 10:27:52 +00:00
|
|
|
* @dev: rproc device pointer
|
|
|
|
* @addr: Address at which image is available
|
|
|
|
* @size: size of the image
|
|
|
|
*
|
|
|
|
* Return: 0 if all goes good, else appropriate error message.
|
|
|
|
*/
|
2019-06-07 13:55:59 +00:00
|
|
|
static int k3_arm64_load(struct udevice *dev, ulong addr, ulong size)
|
2018-08-27 10:27:52 +00:00
|
|
|
{
|
2019-06-07 13:55:59 +00:00
|
|
|
struct k3_arm64_privdata *rproc = dev_get_priv(dev);
|
2018-08-27 10:27:52 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_dbg(dev, "%s addr = 0x%lx, size = 0x%lx\n", __func__, addr, size);
|
|
|
|
|
|
|
|
/* request for the processor */
|
2019-06-07 13:55:58 +00:00
|
|
|
ret = ti_sci_proc_request(&rproc->tsp);
|
|
|
|
if (ret)
|
2018-08-27 10:27:52 +00:00
|
|
|
return ret;
|
|
|
|
|
2019-06-07 13:55:58 +00:00
|
|
|
return ti_sci_proc_set_config(&rproc->tsp, addr, 0, 0);
|
2018-08-27 10:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-06-07 13:55:59 +00:00
|
|
|
* k3_arm64_start() - Start the remote processor
|
2018-08-27 10:27:52 +00:00
|
|
|
* @dev: rproc device pointer
|
|
|
|
*
|
|
|
|
* Return: 0 if all went ok, else return appropriate error
|
|
|
|
*/
|
2019-06-07 13:55:59 +00:00
|
|
|
static int k3_arm64_start(struct udevice *dev)
|
2018-08-27 10:27:52 +00:00
|
|
|
{
|
2019-06-07 13:55:59 +00:00
|
|
|
struct k3_arm64_privdata *rproc = dev_get_priv(dev);
|
2018-08-27 10:27:52 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_dbg(dev, "%s\n", __func__);
|
|
|
|
|
|
|
|
ret = power_domain_on(&rproc->gtc_pwrdmn);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "power_domain_on() failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable the timer before starting remote core */
|
|
|
|
writel(GTC_CNTR_EN, rproc->gtc_base + GTC_CNTCR_REG);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setting the right clock frequency would have taken care by
|
|
|
|
* assigned-clock-rates during the device probe. So no need to
|
|
|
|
* set the frequency again here.
|
|
|
|
*/
|
|
|
|
ret = power_domain_on(&rproc->rproc_pwrdmn);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "power_domain_on() failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-07 13:55:58 +00:00
|
|
|
return ti_sci_proc_release(&rproc->tsp);
|
2018-08-27 10:27:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-06-07 13:55:59 +00:00
|
|
|
* k3_arm64_init() - Initialize the remote processor
|
2018-08-27 10:27:52 +00:00
|
|
|
* @dev: rproc device pointer
|
|
|
|
*
|
|
|
|
* Return: 0 if all went ok, else return appropriate error
|
|
|
|
*/
|
2019-06-07 13:55:59 +00:00
|
|
|
static int k3_arm64_init(struct udevice *dev)
|
2018-08-27 10:27:52 +00:00
|
|
|
{
|
|
|
|
dev_dbg(dev, "%s\n", __func__);
|
|
|
|
|
|
|
|
/* Enable the module */
|
|
|
|
dev_dbg(dev, "%s: rproc successfully initialized\n", __func__);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-07 13:55:59 +00:00
|
|
|
static const struct dm_rproc_ops k3_arm64_ops = {
|
|
|
|
.init = k3_arm64_init,
|
|
|
|
.load = k3_arm64_load,
|
|
|
|
.start = k3_arm64_start,
|
2018-08-27 10:27:52 +00:00
|
|
|
};
|
|
|
|
|
2019-06-07 13:55:58 +00:00
|
|
|
static int ti_sci_proc_of_to_priv(struct udevice *dev, struct ti_sci_proc *tsp)
|
|
|
|
{
|
|
|
|
dev_dbg(dev, "%s\n", __func__);
|
|
|
|
|
|
|
|
tsp->sci = ti_sci_get_by_phandle(dev, "ti,sci");
|
|
|
|
if (IS_ERR(tsp->sci)) {
|
|
|
|
dev_err(dev, "ti_sci get failed: %ld\n", PTR_ERR(tsp->sci));
|
|
|
|
return PTR_ERR(tsp->sci);
|
|
|
|
}
|
|
|
|
|
|
|
|
tsp->proc_id = dev_read_u32_default(dev, "ti,sci-proc-id", INVALID_ID);
|
|
|
|
if (tsp->proc_id == INVALID_ID) {
|
|
|
|
dev_err(dev, "proc id not populated\n");
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
tsp->host_id = dev_read_u32_default(dev, "ti,sci-host-id", INVALID_ID);
|
|
|
|
tsp->ops = &tsp->sci->ops.proc_ops;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-27 10:27:52 +00:00
|
|
|
/**
|
|
|
|
* k3_of_to_priv() - generate private data from device tree
|
|
|
|
* @dev: corresponding k3 remote processor device
|
|
|
|
* @priv: pointer to driver specific private data
|
|
|
|
*
|
|
|
|
* Return: 0 if all goes good, else appropriate error message.
|
|
|
|
*/
|
2019-06-07 13:55:59 +00:00
|
|
|
static int k3_arm64_of_to_priv(struct udevice *dev,
|
|
|
|
struct k3_arm64_privdata *rproc)
|
2018-08-27 10:27:52 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_dbg(dev, "%s\n", __func__);
|
|
|
|
|
|
|
|
ret = power_domain_get_by_index(dev, &rproc->rproc_pwrdmn, 1);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "power_domain_get() failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = power_domain_get_by_index(dev, &rproc->gtc_pwrdmn, 0);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "power_domain_get() failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = reset_get_by_index(dev, 0, &rproc->rproc_rst);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "reset_get() failed: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-07 13:55:58 +00:00
|
|
|
ret = ti_sci_proc_of_to_priv(dev, &rproc->tsp);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2018-08-27 10:27:52 +00:00
|
|
|
|
|
|
|
rproc->gtc_base = dev_read_addr_ptr(dev);
|
|
|
|
if (!rproc->gtc_base) {
|
|
|
|
dev_err(dev, "Get address failed\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-06-07 13:55:59 +00:00
|
|
|
* k3_arm64_probe() - Basic probe
|
2018-08-27 10:27:52 +00:00
|
|
|
* @dev: corresponding k3 remote processor device
|
|
|
|
*
|
|
|
|
* Return: 0 if all goes good, else appropriate error message.
|
|
|
|
*/
|
2019-06-07 13:55:59 +00:00
|
|
|
static int k3_arm64_probe(struct udevice *dev)
|
2018-08-27 10:27:52 +00:00
|
|
|
{
|
2019-06-07 13:55:59 +00:00
|
|
|
struct k3_arm64_privdata *priv;
|
2018-08-27 10:27:52 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
dev_dbg(dev, "%s\n", __func__);
|
|
|
|
|
|
|
|
priv = dev_get_priv(dev);
|
|
|
|
|
2019-06-07 13:55:59 +00:00
|
|
|
ret = k3_arm64_of_to_priv(dev, priv);
|
2018-08-27 10:27:52 +00:00
|
|
|
if (ret) {
|
|
|
|
dev_dbg(dev, "%s: Probe failed with error %d\n", __func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_dbg(dev, "Remoteproc successfully probed\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-06-07 13:55:59 +00:00
|
|
|
static const struct udevice_id k3_arm64_ids[] = {
|
|
|
|
{ .compatible = "ti,am654-arm64"},
|
2018-08-27 10:27:52 +00:00
|
|
|
{ .compatible = "ti,am654-rproc"},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2019-06-07 13:55:59 +00:00
|
|
|
U_BOOT_DRIVER(k3_arm64) = {
|
|
|
|
.name = "k3_arm64",
|
|
|
|
.of_match = k3_arm64_ids,
|
2018-08-27 10:27:52 +00:00
|
|
|
.id = UCLASS_REMOTEPROC,
|
2019-06-07 13:55:59 +00:00
|
|
|
.ops = &k3_arm64_ops,
|
|
|
|
.probe = k3_arm64_probe,
|
|
|
|
.priv_auto_alloc_size = sizeof(struct k3_arm64_privdata),
|
2019-09-27 08:18:13 +00:00
|
|
|
.flags = DM_FLAG_DEFAULT_PD_CTRL_OFF,
|
2018-08-27 10:27:52 +00:00
|
|
|
};
|