2019-12-23 04:04:48 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
|
|
|
|
* Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2022-09-29 16:48:20 -07:00
|
|
|
#include <linux/module.h>
|
2019-12-23 04:04:48 -07:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/mutex.h>
|
|
|
|
#include <linux/of.h>
|
2020-08-03 05:57:12 -07:00
|
|
|
#include <linux/sys_soc.h>
|
2019-12-23 04:04:48 -07:00
|
|
|
|
|
|
|
#include "k3-psil-priv.h"
|
|
|
|
|
|
|
|
static DEFINE_MUTEX(ep_map_mutex);
|
2020-08-03 05:57:12 -07:00
|
|
|
static const struct psil_ep_map *soc_ep_map;
|
|
|
|
|
|
|
|
static const struct soc_device_attribute k3_soc_devices[] = {
|
|
|
|
{ .family = "AM65X", .data = &am654_ep_map },
|
|
|
|
{ .family = "J721E", .data = &j721e_ep_map },
|
2020-08-03 05:57:13 -07:00
|
|
|
{ .family = "J7200", .data = &j7200_ep_map },
|
2020-12-08 02:04:34 -07:00
|
|
|
{ .family = "AM64X", .data = &am64_ep_map },
|
2021-11-19 06:23:14 -07:00
|
|
|
{ .family = "J721S2", .data = &j721s2_ep_map },
|
2022-02-19 01:32:20 -07:00
|
|
|
{ .family = "AM62X", .data = &am62_ep_map },
|
2022-12-13 09:43:02 -07:00
|
|
|
{ .family = "AM62AX", .data = &am62a_ep_map },
|
2023-03-08 13:15:13 -07:00
|
|
|
{ .family = "J784S4", .data = &j784s4_ep_map },
|
2023-12-13 01:13:18 -07:00
|
|
|
{ .family = "AM62PX", .data = &am62p_ep_map },
|
|
|
|
{ .family = "J722S", .data = &am62p_ep_map },
|
2020-08-03 05:57:12 -07:00
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
2019-12-23 04:04:48 -07:00
|
|
|
|
|
|
|
struct psil_endpoint_config *psil_get_ep_config(u32 thread_id)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mutex_lock(&ep_map_mutex);
|
|
|
|
if (!soc_ep_map) {
|
2020-08-03 05:57:12 -07:00
|
|
|
const struct soc_device_attribute *soc;
|
|
|
|
|
|
|
|
soc = soc_device_match(k3_soc_devices);
|
|
|
|
if (soc) {
|
|
|
|
soc_ep_map = soc->data;
|
2019-12-23 04:04:48 -07:00
|
|
|
} else {
|
|
|
|
pr_err("PSIL: No compatible machine found for map\n");
|
2020-04-08 11:55:01 -07:00
|
|
|
mutex_unlock(&ep_map_mutex);
|
2019-12-23 04:04:48 -07:00
|
|
|
return ERR_PTR(-ENOTSUPP);
|
|
|
|
}
|
|
|
|
pr_debug("%s: Using map for %s\n", __func__, soc_ep_map->name);
|
|
|
|
}
|
|
|
|
mutex_unlock(&ep_map_mutex);
|
|
|
|
|
|
|
|
if (thread_id & K3_PSIL_DST_THREAD_ID_OFFSET && soc_ep_map->dst) {
|
|
|
|
/* check in destination thread map */
|
|
|
|
for (i = 0; i < soc_ep_map->dst_count; i++) {
|
|
|
|
if (soc_ep_map->dst[i].thread_id == thread_id)
|
|
|
|
return &soc_ep_map->dst[i].ep_config;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
thread_id &= ~K3_PSIL_DST_THREAD_ID_OFFSET;
|
|
|
|
if (soc_ep_map->src) {
|
|
|
|
for (i = 0; i < soc_ep_map->src_count; i++) {
|
|
|
|
if (soc_ep_map->src[i].thread_id == thread_id)
|
|
|
|
return &soc_ep_map->src[i].ep_config;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(psil_get_ep_config);
|
|
|
|
|
|
|
|
int psil_set_new_ep_config(struct device *dev, const char *name,
|
|
|
|
struct psil_endpoint_config *ep_config)
|
|
|
|
{
|
|
|
|
struct psil_endpoint_config *dst_ep_config;
|
|
|
|
struct of_phandle_args dma_spec;
|
|
|
|
u32 thread_id;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
if (!dev || !dev->of_node)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
index = of_property_match_string(dev->of_node, "dma-names", name);
|
|
|
|
if (index < 0)
|
|
|
|
return index;
|
|
|
|
|
|
|
|
if (of_parse_phandle_with_args(dev->of_node, "dmas", "#dma-cells",
|
|
|
|
index, &dma_spec))
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
thread_id = dma_spec.args[0];
|
|
|
|
|
|
|
|
dst_ep_config = psil_get_ep_config(thread_id);
|
|
|
|
if (IS_ERR(dst_ep_config)) {
|
|
|
|
pr_err("PSIL: thread ID 0x%04x not defined in map\n",
|
|
|
|
thread_id);
|
|
|
|
of_node_put(dma_spec.np);
|
|
|
|
return PTR_ERR(dst_ep_config);
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(dst_ep_config, ep_config, sizeof(*dst_ep_config));
|
|
|
|
|
|
|
|
of_node_put(dma_spec.np);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(psil_set_new_ep_config);
|
2024-06-13 12:27:22 -07:00
|
|
|
MODULE_DESCRIPTION("K3 PSI-L endpoint configuration");
|
2022-09-29 16:48:20 -07:00
|
|
|
MODULE_LICENSE("GPL v2");
|