xref: /linux/drivers/remoteproc/ti_sci_proc.h (revision c7546e2c3cb739a3c1a2f5acaf9bb629d401afe5)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Texas Instruments TI-SCI Processor Controller Helper Functions
4  *
5  * Copyright (C) 2018-2020 Texas Instruments Incorporated - https://www.ti.com/
6  *	Suman Anna <s-anna@ti.com>
7  */
8 
9 #ifndef REMOTEPROC_TI_SCI_PROC_H
10 #define REMOTEPROC_TI_SCI_PROC_H
11 
12 #include <linux/soc/ti/ti_sci_protocol.h>
13 
14 /**
15  * struct ti_sci_proc - structure representing a processor control client
16  * @sci: cached TI-SCI protocol handle
17  * @ops: cached TI-SCI proc ops
18  * @dev: cached client device pointer
19  * @proc_id: processor id for the consumer remoteproc device
20  * @host_id: host id to pass the control over for this consumer remoteproc
21  *	     device
22  */
23 struct ti_sci_proc {
24 	const struct ti_sci_handle *sci;
25 	const struct ti_sci_proc_ops *ops;
26 	struct device *dev;
27 	u8 proc_id;
28 	u8 host_id;
29 };
30 
31 static inline
32 struct ti_sci_proc *ti_sci_proc_of_get_tsp(struct device *dev,
33 					   const struct ti_sci_handle *sci)
34 {
35 	struct ti_sci_proc *tsp;
36 	u32 temp[2];
37 	int ret;
38 
39 	ret = of_property_read_u32_array(dev_of_node(dev), "ti,sci-proc-ids",
40 					 temp, 2);
41 	if (ret < 0)
42 		return ERR_PTR(ret);
43 
44 	tsp = devm_kzalloc(dev, sizeof(*tsp), GFP_KERNEL);
45 	if (!tsp)
46 		return ERR_PTR(-ENOMEM);
47 
48 	tsp->dev = dev;
49 	tsp->sci = sci;
50 	tsp->ops = &sci->ops.proc_ops;
51 	tsp->proc_id = temp[0];
52 	tsp->host_id = temp[1];
53 
54 	return tsp;
55 }
56 
57 static inline int ti_sci_proc_request(struct ti_sci_proc *tsp)
58 {
59 	int ret;
60 
61 	ret = tsp->ops->request(tsp->sci, tsp->proc_id);
62 	if (ret)
63 		dev_err(tsp->dev, "ti-sci processor request failed: %d\n",
64 			ret);
65 	return ret;
66 }
67 
68 static inline int ti_sci_proc_release(struct ti_sci_proc *tsp)
69 {
70 	int ret;
71 
72 	ret = tsp->ops->release(tsp->sci, tsp->proc_id);
73 	if (ret)
74 		dev_err(tsp->dev, "ti-sci processor release failed: %d\n",
75 			ret);
76 	return ret;
77 }
78 
79 static inline int ti_sci_proc_handover(struct ti_sci_proc *tsp)
80 {
81 	int ret;
82 
83 	ret = tsp->ops->handover(tsp->sci, tsp->proc_id, tsp->host_id);
84 	if (ret)
85 		dev_err(tsp->dev, "ti-sci processor handover of %d to %d failed: %d\n",
86 			tsp->proc_id, tsp->host_id, ret);
87 	return ret;
88 }
89 
90 static inline int ti_sci_proc_set_config(struct ti_sci_proc *tsp,
91 					 u64 boot_vector,
92 					 u32 cfg_set, u32 cfg_clr)
93 {
94 	int ret;
95 
96 	ret = tsp->ops->set_config(tsp->sci, tsp->proc_id, boot_vector,
97 				   cfg_set, cfg_clr);
98 	if (ret)
99 		dev_err(tsp->dev, "ti-sci processor set_config failed: %d\n",
100 			ret);
101 	return ret;
102 }
103 
104 static inline int ti_sci_proc_set_control(struct ti_sci_proc *tsp,
105 					  u32 ctrl_set, u32 ctrl_clr)
106 {
107 	int ret;
108 
109 	ret = tsp->ops->set_control(tsp->sci, tsp->proc_id, ctrl_set, ctrl_clr);
110 	if (ret)
111 		dev_err(tsp->dev, "ti-sci processor set_control failed: %d\n",
112 			ret);
113 	return ret;
114 }
115 
116 static inline int ti_sci_proc_get_status(struct ti_sci_proc *tsp,
117 					 u64 *boot_vector, u32 *cfg_flags,
118 					 u32 *ctrl_flags, u32 *status_flags)
119 {
120 	int ret;
121 
122 	ret = tsp->ops->get_status(tsp->sci, tsp->proc_id, boot_vector,
123 				   cfg_flags, ctrl_flags, status_flags);
124 	if (ret)
125 		dev_err(tsp->dev, "ti-sci processor get_status failed: %d\n",
126 			ret);
127 	return ret;
128 }
129 
130 #endif /* REMOTEPROC_TI_SCI_PROC_H */
131