1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  Copyright © 2015 Broadcom
4  */
5 
6 #ifndef __SOC_RASPBERRY_FIRMWARE_H__
7 #define __SOC_RASPBERRY_FIRMWARE_H__
8 
9 #include <linux/types.h>
10 #include <linux/of_device.h>
11 
12 struct rpi_firmware;
13 
14 enum rpi_firmware_property_status {
15 	RPI_FIRMWARE_STATUS_REQUEST = 0,
16 	RPI_FIRMWARE_STATUS_SUCCESS = 0x80000000,
17 	RPI_FIRMWARE_STATUS_ERROR =   0x80000001,
18 };
19 
20 /**
21  * struct rpi_firmware_property_tag_header - Firmware property tag header
22  * @tag:		One of enum_mbox_property_tag.
23  * @buf_size:		The number of bytes in the value buffer following this
24  *			struct.
25  * @req_resp_size:	On submit, the length of the request (though it doesn't
26  *			appear to be currently used by the firmware).  On return,
27  *			the length of the response (always 4 byte aligned), with
28  *			the low bit set.
29  */
30 struct rpi_firmware_property_tag_header {
31 	u32 tag;
32 	u32 buf_size;
33 	u32 req_resp_size;
34 };
35 
36 enum rpi_firmware_property_tag {
37 	RPI_FIRMWARE_PROPERTY_END =                           0,
38 	RPI_FIRMWARE_GET_FIRMWARE_REVISION =                  0x00000001,
39 
40 	RPI_FIRMWARE_SET_CURSOR_INFO =                        0x00008010,
41 	RPI_FIRMWARE_SET_CURSOR_STATE =                       0x00008011,
42 
43 	RPI_FIRMWARE_GET_BOARD_MODEL =                        0x00010001,
44 	RPI_FIRMWARE_GET_BOARD_REVISION =                     0x00010002,
45 	RPI_FIRMWARE_GET_BOARD_MAC_ADDRESS =                  0x00010003,
46 	RPI_FIRMWARE_GET_BOARD_SERIAL =                       0x00010004,
47 	RPI_FIRMWARE_GET_ARM_MEMORY =                         0x00010005,
48 	RPI_FIRMWARE_GET_VC_MEMORY =                          0x00010006,
49 	RPI_FIRMWARE_GET_CLOCKS =                             0x00010007,
50 	RPI_FIRMWARE_GET_POWER_STATE =                        0x00020001,
51 	RPI_FIRMWARE_GET_TIMING =                             0x00020002,
52 	RPI_FIRMWARE_SET_POWER_STATE =                        0x00028001,
53 	RPI_FIRMWARE_GET_CLOCK_STATE =                        0x00030001,
54 	RPI_FIRMWARE_GET_CLOCK_RATE =                         0x00030002,
55 	RPI_FIRMWARE_GET_VOLTAGE =                            0x00030003,
56 	RPI_FIRMWARE_GET_MAX_CLOCK_RATE =                     0x00030004,
57 	RPI_FIRMWARE_GET_MAX_VOLTAGE =                        0x00030005,
58 	RPI_FIRMWARE_GET_TEMPERATURE =                        0x00030006,
59 	RPI_FIRMWARE_GET_MIN_CLOCK_RATE =                     0x00030007,
60 	RPI_FIRMWARE_GET_MIN_VOLTAGE =                        0x00030008,
61 	RPI_FIRMWARE_GET_TURBO =                              0x00030009,
62 	RPI_FIRMWARE_GET_MAX_TEMPERATURE =                    0x0003000a,
63 	RPI_FIRMWARE_GET_STC =                                0x0003000b,
64 	RPI_FIRMWARE_ALLOCATE_MEMORY =                        0x0003000c,
65 	RPI_FIRMWARE_LOCK_MEMORY =                            0x0003000d,
66 	RPI_FIRMWARE_UNLOCK_MEMORY =                          0x0003000e,
67 	RPI_FIRMWARE_RELEASE_MEMORY =                         0x0003000f,
68 	RPI_FIRMWARE_EXECUTE_CODE =                           0x00030010,
69 	RPI_FIRMWARE_EXECUTE_QPU =                            0x00030011,
70 	RPI_FIRMWARE_SET_ENABLE_QPU =                         0x00030012,
71 	RPI_FIRMWARE_GET_DISPMANX_RESOURCE_MEM_HANDLE =       0x00030014,
72 	RPI_FIRMWARE_GET_EDID_BLOCK =                         0x00030020,
73 	RPI_FIRMWARE_GET_CUSTOMER_OTP =                       0x00030021,
74 	RPI_FIRMWARE_GET_DOMAIN_STATE =                       0x00030030,
75 	RPI_FIRMWARE_GET_THROTTLED =                          0x00030046,
76 	RPI_FIRMWARE_GET_CLOCK_MEASURED =                     0x00030047,
77 	RPI_FIRMWARE_NOTIFY_REBOOT =                          0x00030048,
78 	RPI_FIRMWARE_SET_CLOCK_STATE =                        0x00038001,
79 	RPI_FIRMWARE_SET_CLOCK_RATE =                         0x00038002,
80 	RPI_FIRMWARE_SET_VOLTAGE =                            0x00038003,
81 	RPI_FIRMWARE_SET_TURBO =                              0x00038009,
82 	RPI_FIRMWARE_SET_CUSTOMER_OTP =                       0x00038021,
83 	RPI_FIRMWARE_SET_DOMAIN_STATE =                       0x00038030,
84 	RPI_FIRMWARE_GET_GPIO_STATE =                         0x00030041,
85 	RPI_FIRMWARE_SET_GPIO_STATE =                         0x00038041,
86 	RPI_FIRMWARE_SET_SDHOST_CLOCK =                       0x00038042,
87 	RPI_FIRMWARE_GET_GPIO_CONFIG =                        0x00030043,
88 	RPI_FIRMWARE_SET_GPIO_CONFIG =                        0x00038043,
89 	RPI_FIRMWARE_GET_PERIPH_REG =                         0x00030045,
90 	RPI_FIRMWARE_SET_PERIPH_REG =                         0x00038045,
91 	RPI_FIRMWARE_GET_POE_HAT_VAL =                        0x00030049,
92 	RPI_FIRMWARE_SET_POE_HAT_VAL =                        0x00030050,
93 	RPI_FIRMWARE_NOTIFY_XHCI_RESET =                      0x00030058,
94 	RPI_FIRMWARE_NOTIFY_DISPLAY_DONE =                    0x00030066,
95 
96 	/* Dispmanx TAGS */
97 	RPI_FIRMWARE_FRAMEBUFFER_ALLOCATE =                   0x00040001,
98 	RPI_FIRMWARE_FRAMEBUFFER_BLANK =                      0x00040002,
99 	RPI_FIRMWARE_FRAMEBUFFER_GET_PHYSICAL_WIDTH_HEIGHT =  0x00040003,
100 	RPI_FIRMWARE_FRAMEBUFFER_GET_VIRTUAL_WIDTH_HEIGHT =   0x00040004,
101 	RPI_FIRMWARE_FRAMEBUFFER_GET_DEPTH =                  0x00040005,
102 	RPI_FIRMWARE_FRAMEBUFFER_GET_PIXEL_ORDER =            0x00040006,
103 	RPI_FIRMWARE_FRAMEBUFFER_GET_ALPHA_MODE =             0x00040007,
104 	RPI_FIRMWARE_FRAMEBUFFER_GET_PITCH =                  0x00040008,
105 	RPI_FIRMWARE_FRAMEBUFFER_GET_VIRTUAL_OFFSET =         0x00040009,
106 	RPI_FIRMWARE_FRAMEBUFFER_GET_OVERSCAN =               0x0004000a,
107 	RPI_FIRMWARE_FRAMEBUFFER_GET_PALETTE =                0x0004000b,
108 	RPI_FIRMWARE_FRAMEBUFFER_GET_TOUCHBUF =               0x0004000f,
109 	RPI_FIRMWARE_FRAMEBUFFER_GET_GPIOVIRTBUF =            0x00040010,
110 	RPI_FIRMWARE_FRAMEBUFFER_RELEASE =                    0x00048001,
111 	RPI_FIRMWARE_FRAMEBUFFER_TEST_PHYSICAL_WIDTH_HEIGHT = 0x00044003,
112 	RPI_FIRMWARE_FRAMEBUFFER_TEST_VIRTUAL_WIDTH_HEIGHT =  0x00044004,
113 	RPI_FIRMWARE_FRAMEBUFFER_TEST_DEPTH =                 0x00044005,
114 	RPI_FIRMWARE_FRAMEBUFFER_TEST_PIXEL_ORDER =           0x00044006,
115 	RPI_FIRMWARE_FRAMEBUFFER_TEST_ALPHA_MODE =            0x00044007,
116 	RPI_FIRMWARE_FRAMEBUFFER_TEST_VIRTUAL_OFFSET =        0x00044009,
117 	RPI_FIRMWARE_FRAMEBUFFER_TEST_OVERSCAN =              0x0004400a,
118 	RPI_FIRMWARE_FRAMEBUFFER_TEST_PALETTE =               0x0004400b,
119 	RPI_FIRMWARE_FRAMEBUFFER_TEST_VSYNC =                 0x0004400e,
120 	RPI_FIRMWARE_FRAMEBUFFER_SET_PHYSICAL_WIDTH_HEIGHT =  0x00048003,
121 	RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_WIDTH_HEIGHT =   0x00048004,
122 	RPI_FIRMWARE_FRAMEBUFFER_SET_DEPTH =                  0x00048005,
123 	RPI_FIRMWARE_FRAMEBUFFER_SET_PIXEL_ORDER =            0x00048006,
124 	RPI_FIRMWARE_FRAMEBUFFER_SET_ALPHA_MODE =             0x00048007,
125 	RPI_FIRMWARE_FRAMEBUFFER_SET_VIRTUAL_OFFSET =         0x00048009,
126 	RPI_FIRMWARE_FRAMEBUFFER_SET_OVERSCAN =               0x0004800a,
127 	RPI_FIRMWARE_FRAMEBUFFER_SET_PALETTE =                0x0004800b,
128 	RPI_FIRMWARE_FRAMEBUFFER_SET_TOUCHBUF =               0x0004801f,
129 	RPI_FIRMWARE_FRAMEBUFFER_SET_GPIOVIRTBUF =            0x00048020,
130 	RPI_FIRMWARE_FRAMEBUFFER_SET_VSYNC =                  0x0004800e,
131 	RPI_FIRMWARE_FRAMEBUFFER_SET_BACKLIGHT =              0x0004800f,
132 
133 	RPI_FIRMWARE_VCHIQ_INIT =                             0x00048010,
134 
135 	RPI_FIRMWARE_GET_COMMAND_LINE =                       0x00050001,
136 	RPI_FIRMWARE_GET_DMA_CHANNELS =                       0x00060001,
137 };
138 
139 enum rpi_firmware_clk_id {
140 	RPI_FIRMWARE_EMMC_CLK_ID = 1,
141 	RPI_FIRMWARE_UART_CLK_ID,
142 	RPI_FIRMWARE_ARM_CLK_ID,
143 	RPI_FIRMWARE_CORE_CLK_ID,
144 	RPI_FIRMWARE_V3D_CLK_ID,
145 	RPI_FIRMWARE_H264_CLK_ID,
146 	RPI_FIRMWARE_ISP_CLK_ID,
147 	RPI_FIRMWARE_SDRAM_CLK_ID,
148 	RPI_FIRMWARE_PIXEL_CLK_ID,
149 	RPI_FIRMWARE_PWM_CLK_ID,
150 	RPI_FIRMWARE_HEVC_CLK_ID,
151 	RPI_FIRMWARE_EMMC2_CLK_ID,
152 	RPI_FIRMWARE_M2MC_CLK_ID,
153 	RPI_FIRMWARE_PIXEL_BVB_CLK_ID,
154 	RPI_FIRMWARE_VEC_CLK_ID,
155 	RPI_FIRMWARE_NUM_CLK_ID,
156 };
157 
158 /**
159  * struct rpi_firmware_clk_rate_request - Firmware Request for a rate
160  * @id:	ID of the clock being queried
161  * @rate: Rate in Hertz. Set by the firmware.
162  *
163  * Used by @RPI_FIRMWARE_GET_CLOCK_RATE, @RPI_FIRMWARE_GET_CLOCK_MEASURED,
164  * @RPI_FIRMWARE_GET_MAX_CLOCK_RATE and @RPI_FIRMWARE_GET_MIN_CLOCK_RATE.
165  */
166 struct rpi_firmware_clk_rate_request {
167 	__le32 id;
168 	__le32 rate;
169 } __packed;
170 
171 #define RPI_FIRMWARE_CLK_RATE_REQUEST(_id)	\
172 	{					\
173 		.id = cpu_to_le32(_id),		\
174 	}
175 
176 #if IS_ENABLED(CONFIG_RASPBERRYPI_FIRMWARE)
177 int rpi_firmware_property(struct rpi_firmware *fw,
178 			  u32 tag, void *data, size_t len);
179 int rpi_firmware_property_list(struct rpi_firmware *fw,
180 			       void *data, size_t tag_size);
181 void rpi_firmware_put(struct rpi_firmware *fw);
182 unsigned int rpi_firmware_clk_get_max_rate(struct rpi_firmware *fw,
183 					   unsigned int id);
184 struct device_node *rpi_firmware_find_node(void);
185 struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node);
186 struct rpi_firmware *devm_rpi_firmware_get(struct device *dev,
187 					   struct device_node *firmware_node);
188 #else
189 static inline int rpi_firmware_property(struct rpi_firmware *fw, u32 tag,
190 					void *data, size_t len)
191 {
192 	return -ENOSYS;
193 }
194 
195 static inline int rpi_firmware_property_list(struct rpi_firmware *fw,
196 					     void *data, size_t tag_size)
197 {
198 	return -ENOSYS;
199 }
200 
201 static inline void rpi_firmware_put(struct rpi_firmware *fw) { }
202 
203 static inline unsigned int rpi_firmware_clk_get_max_rate(struct rpi_firmware *fw,
204 							 unsigned int id)
205 {
206 	return UINT_MAX;
207 }
208 
209 static inline struct device_node *rpi_firmware_find_node(void)
210 {
211 	return NULL;
212 }
213 
214 static inline struct rpi_firmware *rpi_firmware_get(struct device_node *firmware_node)
215 {
216 	return NULL;
217 }
218 
219 static inline struct rpi_firmware *devm_rpi_firmware_get(struct device *dev,
220 					struct device_node *firmware_node)
221 {
222 	return NULL;
223 }
224 #endif
225 
226 #endif /* __SOC_RASPBERRY_FIRMWARE_H__ */
227