xref: /openbmc/linux/include/linux/pruss_driver.h (revision d2a3b501)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * PRU-ICSS sub-system specific definitions
4  *
5  * Copyright (C) 2014-2020 Texas Instruments Incorporated - http://www.ti.com/
6  *	Suman Anna <s-anna@ti.com>
7  */
8 
9 #ifndef _PRUSS_DRIVER_H_
10 #define _PRUSS_DRIVER_H_
11 
12 #include <linux/mutex.h>
13 #include <linux/remoteproc/pruss.h>
14 #include <linux/types.h>
15 #include <linux/err.h>
16 
17 /*
18  * enum pruss_gp_mux_sel - PRUSS GPI/O Mux modes for the
19  * PRUSS_GPCFG0/1 registers
20  *
21  * NOTE: The below defines are the most common values, but there
22  * are some exceptions like on 66AK2G, where the RESERVED and MII2
23  * values are interchanged. Also, this bit-field does not exist on
24  * AM335x SoCs
25  */
26 enum pruss_gp_mux_sel {
27 	PRUSS_GP_MUX_SEL_GP,
28 	PRUSS_GP_MUX_SEL_ENDAT,
29 	PRUSS_GP_MUX_SEL_RESERVED,
30 	PRUSS_GP_MUX_SEL_SD,
31 	PRUSS_GP_MUX_SEL_MII2,
32 	PRUSS_GP_MUX_SEL_MAX,
33 };
34 
35 /*
36  * enum pruss_gpi_mode - PRUSS GPI configuration modes, used
37  *			 to program the PRUSS_GPCFG0/1 registers
38  */
39 enum pruss_gpi_mode {
40 	PRUSS_GPI_MODE_DIRECT,
41 	PRUSS_GPI_MODE_PARALLEL,
42 	PRUSS_GPI_MODE_28BIT_SHIFT,
43 	PRUSS_GPI_MODE_MII,
44 	PRUSS_GPI_MODE_MAX,
45 };
46 
47 /**
48  * enum pru_type - PRU core type identifier
49  *
50  * @PRU_TYPE_PRU: Programmable Real-time Unit
51  * @PRU_TYPE_RTU: Auxiliary Programmable Real-Time Unit
52  * @PRU_TYPE_TX_PRU: Transmit Programmable Real-Time Unit
53  * @PRU_TYPE_MAX: just keep this one at the end
54  */
55 enum pru_type {
56 	PRU_TYPE_PRU,
57 	PRU_TYPE_RTU,
58 	PRU_TYPE_TX_PRU,
59 	PRU_TYPE_MAX,
60 };
61 
62 /*
63  * enum pruss_mem - PRUSS memory range identifiers
64  */
65 enum pruss_mem {
66 	PRUSS_MEM_DRAM0 = 0,
67 	PRUSS_MEM_DRAM1,
68 	PRUSS_MEM_SHRD_RAM2,
69 	PRUSS_MEM_MAX,
70 };
71 
72 /**
73  * struct pruss_mem_region - PRUSS memory region structure
74  * @va: kernel virtual address of the PRUSS memory region
75  * @pa: physical (bus) address of the PRUSS memory region
76  * @size: size of the PRUSS memory region
77  */
78 struct pruss_mem_region {
79 	void __iomem *va;
80 	phys_addr_t pa;
81 	size_t size;
82 };
83 
84 /**
85  * struct pruss - PRUSS parent structure
86  * @dev: pruss device pointer
87  * @cfg_base: base iomap for CFG region
88  * @cfg_regmap: regmap for config region
89  * @mem_regions: data for each of the PRUSS memory regions
90  * @mem_in_use: to indicate if memory resource is in use
91  * @lock: mutex to serialize access to resources
92  * @core_clk_mux: clk handle for PRUSS CORE_CLK_MUX
93  * @iep_clk_mux: clk handle for PRUSS IEP_CLK_MUX
94  */
95 struct pruss {
96 	struct device *dev;
97 	void __iomem *cfg_base;
98 	struct regmap *cfg_regmap;
99 	struct pruss_mem_region mem_regions[PRUSS_MEM_MAX];
100 	struct pruss_mem_region *mem_in_use[PRUSS_MEM_MAX];
101 	struct mutex lock; /* PRU resource lock */
102 	struct clk *core_clk_mux;
103 	struct clk *iep_clk_mux;
104 };
105 
106 #if IS_ENABLED(CONFIG_TI_PRUSS)
107 
108 struct pruss *pruss_get(struct rproc *rproc);
109 void pruss_put(struct pruss *pruss);
110 int pruss_request_mem_region(struct pruss *pruss, enum pruss_mem mem_id,
111 			     struct pruss_mem_region *region);
112 int pruss_release_mem_region(struct pruss *pruss,
113 			     struct pruss_mem_region *region);
114 int pruss_cfg_get_gpmux(struct pruss *pruss, enum pruss_pru_id pru_id, u8 *mux);
115 int pruss_cfg_set_gpmux(struct pruss *pruss, enum pruss_pru_id pru_id, u8 mux);
116 int pruss_cfg_gpimode(struct pruss *pruss, enum pruss_pru_id pru_id,
117 		      enum pruss_gpi_mode mode);
118 int pruss_cfg_miirt_enable(struct pruss *pruss, bool enable);
119 int pruss_cfg_xfr_enable(struct pruss *pruss, enum pru_type pru_type,
120 			 bool enable);
121 
122 #else
123 
124 static inline struct pruss *pruss_get(struct rproc *rproc)
125 {
126 	return ERR_PTR(-EOPNOTSUPP);
127 }
128 
129 static inline void pruss_put(struct pruss *pruss) { }
130 
131 static inline int pruss_request_mem_region(struct pruss *pruss,
132 					   enum pruss_mem mem_id,
133 					   struct pruss_mem_region *region)
134 {
135 	return -EOPNOTSUPP;
136 }
137 
138 static inline int pruss_release_mem_region(struct pruss *pruss,
139 					   struct pruss_mem_region *region)
140 {
141 	return -EOPNOTSUPP;
142 }
143 
144 static inline int pruss_cfg_get_gpmux(struct pruss *pruss,
145 				      enum pruss_pru_id pru_id, u8 *mux)
146 {
147 	return ERR_PTR(-EOPNOTSUPP);
148 }
149 
150 static inline int pruss_cfg_set_gpmux(struct pruss *pruss,
151 				      enum pruss_pru_id pru_id, u8 mux)
152 {
153 	return ERR_PTR(-EOPNOTSUPP);
154 }
155 
156 static inline int pruss_cfg_gpimode(struct pruss *pruss,
157 				    enum pruss_pru_id pru_id,
158 				    enum pruss_gpi_mode mode)
159 {
160 	return ERR_PTR(-EOPNOTSUPP);
161 }
162 
163 static inline int pruss_cfg_miirt_enable(struct pruss *pruss, bool enable)
164 {
165 	return ERR_PTR(-EOPNOTSUPP);
166 }
167 
168 static inline int pruss_cfg_xfr_enable(struct pruss *pruss,
169 				       enum pru_type pru_type,
170 				       bool enable);
171 {
172 	return ERR_PTR(-EOPNOTSUPP);
173 }
174 
175 #endif /* CONFIG_TI_PRUSS */
176 
177 #endif	/* _PRUSS_DRIVER_H_ */
178