Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  Copyright (C) 2019 Texas Instruments Incorporated - http://www.ti.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *  Author: Peter Ujfalusi <peter.ujfalusi@ti.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/sys_soc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include "k3-psil-priv.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) static DEFINE_MUTEX(ep_map_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) static const struct psil_ep_map *soc_ep_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static const struct soc_device_attribute k3_soc_devices[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	{ .family = "AM65X", .data = &am654_ep_map },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	{ .family = "J721E", .data = &j721e_ep_map },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	{ .family = "J7200", .data = &j7200_ep_map },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	{ /* sentinel */ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) struct psil_endpoint_config *psil_get_ep_config(u32 thread_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	mutex_lock(&ep_map_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	if (!soc_ep_map) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		const struct soc_device_attribute *soc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		soc = soc_device_match(k3_soc_devices);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		if (soc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 			soc_ep_map = soc->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 			pr_err("PSIL: No compatible machine found for map\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 			mutex_unlock(&ep_map_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 			return ERR_PTR(-ENOTSUPP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		pr_debug("%s: Using map for %s\n", __func__, soc_ep_map->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	mutex_unlock(&ep_map_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (thread_id & K3_PSIL_DST_THREAD_ID_OFFSET && soc_ep_map->dst) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		/* check in destination thread map */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 		for (i = 0; i < soc_ep_map->dst_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			if (soc_ep_map->dst[i].thread_id == thread_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 				return &soc_ep_map->dst[i].ep_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	thread_id &= ~K3_PSIL_DST_THREAD_ID_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	if (soc_ep_map->src) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		for (i = 0; i < soc_ep_map->src_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 			if (soc_ep_map->src[i].thread_id == thread_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 				return &soc_ep_map->src[i].ep_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return ERR_PTR(-ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) EXPORT_SYMBOL_GPL(psil_get_ep_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) int psil_set_new_ep_config(struct device *dev, const char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			   struct psil_endpoint_config *ep_config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct psil_endpoint_config *dst_ep_config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct of_phandle_args dma_spec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	u32 thread_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (!dev || !dev->of_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	index = of_property_match_string(dev->of_node, "dma-names", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (index < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		return index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (of_parse_phandle_with_args(dev->of_node, "dmas", "#dma-cells",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 				       index, &dma_spec))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	thread_id = dma_spec.args[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	dst_ep_config = psil_get_ep_config(thread_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (IS_ERR(dst_ep_config)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		pr_err("PSIL: thread ID 0x%04x not defined in map\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		       thread_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		of_node_put(dma_spec.np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return PTR_ERR(dst_ep_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	memcpy(dst_ep_config, ep_config, sizeof(*dst_ep_config));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	of_node_put(dma_spec.np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) EXPORT_SYMBOL_GPL(psil_set_new_ep_config);