0001
0002
0003
0004
0005
0006
0007 #include <linux/kernel.h>
0008 #include <linux/device.h>
0009 #include <linux/init.h>
0010 #include <linux/mutex.h>
0011 #include <linux/of.h>
0012 #include <linux/sys_soc.h>
0013
0014 #include "k3-psil-priv.h"
0015
0016 static DEFINE_MUTEX(ep_map_mutex);
0017 static const struct psil_ep_map *soc_ep_map;
0018
0019 static const struct soc_device_attribute k3_soc_devices[] = {
0020 { .family = "AM65X", .data = &am654_ep_map },
0021 { .family = "J721E", .data = &j721e_ep_map },
0022 { .family = "J7200", .data = &j7200_ep_map },
0023 { .family = "AM64X", .data = &am64_ep_map },
0024 { .family = "J721S2", .data = &j721s2_ep_map },
0025 { .family = "AM62X", .data = &am62_ep_map },
0026 { }
0027 };
0028
0029 struct psil_endpoint_config *psil_get_ep_config(u32 thread_id)
0030 {
0031 int i;
0032
0033 mutex_lock(&ep_map_mutex);
0034 if (!soc_ep_map) {
0035 const struct soc_device_attribute *soc;
0036
0037 soc = soc_device_match(k3_soc_devices);
0038 if (soc) {
0039 soc_ep_map = soc->data;
0040 } else {
0041 pr_err("PSIL: No compatible machine found for map\n");
0042 mutex_unlock(&ep_map_mutex);
0043 return ERR_PTR(-ENOTSUPP);
0044 }
0045 pr_debug("%s: Using map for %s\n", __func__, soc_ep_map->name);
0046 }
0047 mutex_unlock(&ep_map_mutex);
0048
0049 if (thread_id & K3_PSIL_DST_THREAD_ID_OFFSET && soc_ep_map->dst) {
0050
0051 for (i = 0; i < soc_ep_map->dst_count; i++) {
0052 if (soc_ep_map->dst[i].thread_id == thread_id)
0053 return &soc_ep_map->dst[i].ep_config;
0054 }
0055 }
0056
0057 thread_id &= ~K3_PSIL_DST_THREAD_ID_OFFSET;
0058 if (soc_ep_map->src) {
0059 for (i = 0; i < soc_ep_map->src_count; i++) {
0060 if (soc_ep_map->src[i].thread_id == thread_id)
0061 return &soc_ep_map->src[i].ep_config;
0062 }
0063 }
0064
0065 return ERR_PTR(-ENOENT);
0066 }
0067 EXPORT_SYMBOL_GPL(psil_get_ep_config);
0068
0069 int psil_set_new_ep_config(struct device *dev, const char *name,
0070 struct psil_endpoint_config *ep_config)
0071 {
0072 struct psil_endpoint_config *dst_ep_config;
0073 struct of_phandle_args dma_spec;
0074 u32 thread_id;
0075 int index;
0076
0077 if (!dev || !dev->of_node)
0078 return -EINVAL;
0079
0080 index = of_property_match_string(dev->of_node, "dma-names", name);
0081 if (index < 0)
0082 return index;
0083
0084 if (of_parse_phandle_with_args(dev->of_node, "dmas", "#dma-cells",
0085 index, &dma_spec))
0086 return -ENOENT;
0087
0088 thread_id = dma_spec.args[0];
0089
0090 dst_ep_config = psil_get_ep_config(thread_id);
0091 if (IS_ERR(dst_ep_config)) {
0092 pr_err("PSIL: thread ID 0x%04x not defined in map\n",
0093 thread_id);
0094 of_node_put(dma_spec.np);
0095 return PTR_ERR(dst_ep_config);
0096 }
0097
0098 memcpy(dst_ep_config, ep_config, sizeof(*dst_ep_config));
0099
0100 of_node_put(dma_spec.np);
0101 return 0;
0102 }
0103 EXPORT_SYMBOL_GPL(psil_set_new_ep_config);