xref: /freebsd/sys/arm/broadcom/bcm2835/bcm2835_mbox_prop.h (revision 2f513db72b034fd5ef7f080b11be5c711c15186a)
1 /*-
2  * Copyright (C) 2013-2014 Daisuke Aoyama <aoyama@peach.ne.jp>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  * $FreeBSD$
27  */
28 
29 #ifndef _BCM2835_MBOX_PROP_H_
30 #define _BCM2835_MBOX_PROP_H_
31 
32 #include <sys/cdefs.h>
33 #include <sys/types.h>
34 
35 /*
36  * Mailbox property interface:
37  * https://github.com/raspberrypi/firmware/wiki/Mailbox-property-interface
38  */
39 #define BCM2835_MBOX_CODE_REQ			0
40 #define BCM2835_MBOX_CODE_RESP_SUCCESS		0x80000000
41 #define BCM2835_MBOX_CODE_RESP_ERROR		0x80000001
42 #define BCM2835_MBOX_TAG_VAL_LEN_RESPONSE	0x80000000
43 
44 struct bcm2835_mbox_hdr {
45 	uint32_t	buf_size;
46 	uint32_t	code;
47 };
48 
49 struct bcm2835_mbox_tag_hdr {
50 	uint32_t	tag;
51 	uint32_t	val_buf_size;
52 	uint32_t	val_len;
53 };
54 
55 #define	BCM2835_MBOX_INIT_TAG(tag_, tagid_) do {		\
56 	(tag_)->tag_hdr.tag = BCM2835_MBOX_TAG_##tagid_;	\
57 	(tag_)->tag_hdr.val_buf_size = sizeof((tag_)->body);	\
58 	(tag_)->tag_hdr.val_len = sizeof((tag_)->body.req);	\
59 } while (0)
60 
61 #define BCM2835_MBOX_POWER_ID_EMMC		0x00000000
62 #define BCM2835_MBOX_POWER_ID_UART0		0x00000001
63 #define BCM2835_MBOX_POWER_ID_UART1		0x00000002
64 #define BCM2835_MBOX_POWER_ID_USB_HCD		0x00000003
65 #define BCM2835_MBOX_POWER_ID_I2C0		0x00000004
66 #define BCM2835_MBOX_POWER_ID_I2C1		0x00000005
67 #define BCM2835_MBOX_POWER_ID_I2C2		0x00000006
68 #define BCM2835_MBOX_POWER_ID_SPI		0x00000007
69 #define BCM2835_MBOX_POWER_ID_CCP2TX		0x00000008
70 
71 #define BCM2835_MBOX_POWER_ON			(1 << 0)
72 #define BCM2835_MBOX_POWER_WAIT			(1 << 1)
73 
74 #define BCM2835_MBOX_TAG_GET_POWER_STATE	0x00020001
75 #define BCM2835_MBOX_TAG_SET_POWER_STATE	0x00028001
76 
77 struct msg_get_power_state {
78 	struct bcm2835_mbox_hdr hdr;
79 	struct bcm2835_mbox_tag_hdr tag_hdr;
80 	union {
81 		struct {
82 			uint32_t device_id;
83 		} req;
84 		struct {
85 			uint32_t device_id;
86 			uint32_t state;
87 		} resp;
88 	} body;
89 	uint32_t end_tag;
90 };
91 
92 struct msg_set_power_state {
93 	struct bcm2835_mbox_hdr hdr;
94 	struct bcm2835_mbox_tag_hdr tag_hdr;
95 	union {
96 		struct {
97 			uint32_t device_id;
98 			uint32_t state;
99 		} req;
100 		struct {
101 			uint32_t device_id;
102 			uint32_t state;
103 		} resp;
104 	} body;
105 	uint32_t end_tag;
106 };
107 
108 /* Sets the power state for a given device */
109 int bcm2835_mbox_set_power_state(uint32_t, boolean_t);
110 
111 #define BCM2835_MBOX_CLOCK_ID_EMMC		0x00000001
112 #define BCM2835_MBOX_CLOCK_ID_UART		0x00000002
113 #define BCM2835_MBOX_CLOCK_ID_ARM		0x00000003
114 #define BCM2835_MBOX_CLOCK_ID_CORE		0x00000004
115 #define BCM2835_MBOX_CLOCK_ID_V3D		0x00000005
116 #define BCM2835_MBOX_CLOCK_ID_H264		0x00000006
117 #define BCM2835_MBOX_CLOCK_ID_ISP		0x00000007
118 #define BCM2835_MBOX_CLOCK_ID_SDRAM		0x00000008
119 #define BCM2835_MBOX_CLOCK_ID_PIXEL		0x00000009
120 #define BCM2835_MBOX_CLOCK_ID_PWM		0x0000000a
121 #define BCM2838_MBOX_CLOCK_ID_EMMC2		0x0000000c
122 
123 #define BCM2835_MBOX_TAG_GET_CLOCK_RATE		0x00030002
124 #define BCM2835_MBOX_TAG_SET_CLOCK_RATE		0x00038002
125 #define BCM2835_MBOX_TAG_GET_MAX_CLOCK_RATE	0x00030004
126 #define BCM2835_MBOX_TAG_GET_MIN_CLOCK_RATE	0x00030007
127 
128 struct msg_get_clock_rate {
129 	struct bcm2835_mbox_hdr hdr;
130 	struct bcm2835_mbox_tag_hdr tag_hdr;
131 	union {
132 		struct {
133 			uint32_t clock_id;
134 		} req;
135 		struct {
136 			uint32_t clock_id;
137 			uint32_t rate_hz;
138 		} resp;
139 	} body;
140 	uint32_t end_tag;
141 };
142 
143 struct msg_set_clock_rate {
144 	struct bcm2835_mbox_hdr hdr;
145 	struct bcm2835_mbox_tag_hdr tag_hdr;
146 	union {
147 		struct {
148 			uint32_t clock_id;
149 			uint32_t rate_hz;
150 		} req;
151 		struct {
152 			uint32_t clock_id;
153 			uint32_t rate_hz;
154 		} resp;
155 	} body;
156 	uint32_t end_tag;
157 };
158 
159 struct msg_get_max_clock_rate {
160 	struct bcm2835_mbox_hdr hdr;
161 	struct bcm2835_mbox_tag_hdr tag_hdr;
162 	union {
163 		struct {
164 			uint32_t clock_id;
165 		} req;
166 		struct {
167 			uint32_t clock_id;
168 			uint32_t rate_hz;
169 		} resp;
170 	} body;
171 	uint32_t end_tag;
172 };
173 
174 struct msg_get_min_clock_rate {
175 	struct bcm2835_mbox_hdr hdr;
176 	struct bcm2835_mbox_tag_hdr tag_hdr;
177 	union {
178 		struct {
179 			uint32_t clock_id;
180 		} req;
181 		struct {
182 			uint32_t clock_id;
183 			uint32_t rate_hz;
184 		} resp;
185 	} body;
186 	uint32_t end_tag;
187 };
188 
189 int bcm2835_mbox_get_clock_rate(uint32_t, uint32_t *);
190 
191 #define BCM2835_MBOX_TURBO_ON			1
192 #define BCM2835_MBOX_TURBO_OFF			0
193 
194 #define BCM2835_MBOX_TAG_GET_TURBO		0x00030009
195 #define BCM2835_MBOX_TAG_SET_TURBO		0x00038009
196 
197 struct msg_get_turbo {
198 	struct bcm2835_mbox_hdr hdr;
199 	struct bcm2835_mbox_tag_hdr tag_hdr;
200 	union {
201 		struct {
202 			uint32_t id;
203 		} req;
204 		struct {
205 			uint32_t id;
206 			uint32_t level;
207 		} resp;
208 	} body;
209 	uint32_t end_tag;
210 };
211 
212 struct msg_set_turbo {
213 	struct bcm2835_mbox_hdr hdr;
214 	struct bcm2835_mbox_tag_hdr tag_hdr;
215 	union {
216 		struct {
217 			uint32_t id;
218 			uint32_t level;
219 		} req;
220 		struct {
221 			uint32_t id;
222 			uint32_t level;
223 		} resp;
224 	} body;
225 	uint32_t end_tag;
226 };
227 
228 #define BCM2835_MBOX_VOLTAGE_ID_CORE		0x00000001
229 #define BCM2835_MBOX_VOLTAGE_ID_SDRAM_C		0x00000002
230 #define BCM2835_MBOX_VOLTAGE_ID_SDRAM_P		0x00000003
231 #define BCM2835_MBOX_VOLTAGE_ID_SDRAM_I		0x00000004
232 
233 #define BCM2835_MBOX_TAG_GET_VOLTAGE		0x00030003
234 #define BCM2835_MBOX_TAG_SET_VOLTAGE		0x00038003
235 #define BCM2835_MBOX_TAG_GET_MAX_VOLTAGE	0x00030005
236 #define BCM2835_MBOX_TAG_GET_MIN_VOLTAGE	0x00030008
237 
238 struct msg_get_voltage {
239 	struct bcm2835_mbox_hdr hdr;
240 	struct bcm2835_mbox_tag_hdr tag_hdr;
241 	union {
242 		struct {
243 			uint32_t voltage_id;
244 		} req;
245 		struct {
246 			uint32_t voltage_id;
247 			uint32_t value;
248 		} resp;
249 	} body;
250 	uint32_t end_tag;
251 };
252 
253 struct msg_set_voltage {
254 	struct bcm2835_mbox_hdr hdr;
255 	struct bcm2835_mbox_tag_hdr tag_hdr;
256 	union {
257 		struct {
258 			uint32_t voltage_id;
259 			uint32_t value;
260 		} req;
261 		struct {
262 			uint32_t voltage_id;
263 			uint32_t value;
264 		} resp;
265 	} body;
266 	uint32_t end_tag;
267 };
268 
269 struct msg_get_max_voltage {
270 	struct bcm2835_mbox_hdr hdr;
271 	struct bcm2835_mbox_tag_hdr tag_hdr;
272 	union {
273 		struct {
274 			uint32_t voltage_id;
275 		} req;
276 		struct {
277 			uint32_t voltage_id;
278 			uint32_t value;
279 		} resp;
280 	} body;
281 	uint32_t end_tag;
282 };
283 
284 struct msg_get_min_voltage {
285 	struct bcm2835_mbox_hdr hdr;
286 	struct bcm2835_mbox_tag_hdr tag_hdr;
287 	union {
288 		struct {
289 			uint32_t voltage_id;
290 		} req;
291 		struct {
292 			uint32_t voltage_id;
293 			uint32_t value;
294 		} resp;
295 	} body;
296 	uint32_t end_tag;
297 };
298 
299 #define BCM2835_MBOX_TAG_GET_TEMPERATURE	0x00030006
300 #define BCM2835_MBOX_TAG_GET_MAX_TEMPERATURE	0x0003000a
301 
302 struct msg_get_temperature {
303 	struct bcm2835_mbox_hdr hdr;
304 	struct bcm2835_mbox_tag_hdr tag_hdr;
305 	union {
306 		struct {
307 			uint32_t temperature_id;
308 		} req;
309 		struct {
310 			uint32_t temperature_id;
311 			uint32_t value;
312 		} resp;
313 	} body;
314 	uint32_t end_tag;
315 };
316 
317 struct msg_get_max_temperature {
318 	struct bcm2835_mbox_hdr hdr;
319 	struct bcm2835_mbox_tag_hdr tag_hdr;
320 	union {
321 		struct {
322 			uint32_t temperature_id;
323 		} req;
324 		struct {
325 			uint32_t temperature_id;
326 			uint32_t value;
327 		} resp;
328 	} body;
329 	uint32_t end_tag;
330 };
331 
332 #define	BCM2835_MBOX_TAG_GET_PHYSICAL_W_H	0x00040003
333 #define	BCM2835_MBOX_TAG_SET_PHYSICAL_W_H	0x00048003
334 #define	BCM2835_MBOX_TAG_GET_VIRTUAL_W_H	0x00040004
335 #define	BCM2835_MBOX_TAG_SET_VIRTUAL_W_H	0x00048004
336 
337 struct bcm2835_mbox_tag_fb_w_h {
338 	struct bcm2835_mbox_tag_hdr tag_hdr;
339 	union {
340 		struct {
341 			uint32_t width;
342 			uint32_t height;
343 		} req;
344 		struct {
345 			uint32_t width;
346 			uint32_t height;
347 		} resp;
348 	} body;
349 };
350 
351 #define	BCM2835_MBOX_TAG_GET_DEPTH		0x00040005
352 #define	BCM2835_MBOX_TAG_SET_DEPTH		0x00048005
353 
354 struct bcm2835_mbox_tag_depth {
355 	struct bcm2835_mbox_tag_hdr tag_hdr;
356 	union {
357 		struct {
358 			uint32_t bpp;
359 		} req;
360 		struct {
361 			uint32_t bpp;
362 		} resp;
363 	} body;
364 };
365 
366 #define	BCM2835_MBOX_TAG_GET_ALPHA_MODE		0x00040007
367 #define	BCM2835_MBOX_TAG_SET_ALPHA_MODE		0x00048007
368 
369 #define	BCM2835_MBOX_ALPHA_MODE_0_OPAQUE	0
370 #define	BCM2835_MBOX_ALPHA_MODE_0_TRANSPARENT	1
371 #define	BCM2835_MBOX_ALPHA_MODE_IGNORED		2
372 
373 struct bcm2835_mbox_tag_alpha_mode {
374 	struct bcm2835_mbox_tag_hdr tag_hdr;
375 	union {
376 		struct {
377 			uint32_t alpha;
378 		} req;
379 		struct {
380 			uint32_t alpha;
381 		} resp;
382 	} body;
383 };
384 
385 #define	BCM2835_MBOX_TAG_GET_VIRTUAL_OFFSET	0x00040009
386 #define	BCM2835_MBOX_TAG_SET_VIRTUAL_OFFSET	0x00048009
387 
388 struct bcm2835_mbox_tag_virtual_offset {
389 	struct bcm2835_mbox_tag_hdr tag_hdr;
390 	union {
391 		struct {
392 			uint32_t x;
393 			uint32_t y;
394 		} req;
395 		struct {
396 			uint32_t x;
397 			uint32_t y;
398 		} resp;
399 	} body;
400 };
401 
402 #define	BCM2835_MBOX_TAG_GET_PITCH		0x00040008
403 
404 struct bcm2835_mbox_tag_pitch {
405 	struct bcm2835_mbox_tag_hdr tag_hdr;
406 	union {
407 		struct {
408 		} req;
409 		struct {
410 			uint32_t pitch;
411 		} resp;
412 	} body;
413 };
414 
415 #define	BCM2835_MBOX_TAG_ALLOCATE_BUFFER	0x00040001
416 
417 struct bcm2835_mbox_tag_allocate_buffer {
418 	struct bcm2835_mbox_tag_hdr tag_hdr;
419 	union {
420 		struct {
421 			uint32_t alignment;
422 		} req;
423 		struct {
424 			uint32_t fb_address;
425 			uint32_t fb_size;
426 		} resp;
427 	} body;
428 };
429 
430 #define	BCM2835_MBOX_TAG_RELEASE_BUFFER		0x00048001
431 
432 struct bcm2835_mbox_tag_release_buffer {
433 	struct bcm2835_mbox_tag_hdr tag_hdr;
434 	union {
435 		struct {
436 		} req;
437 		struct {
438 		} resp;
439 	} body;
440 };
441 
442 #define	BCM2835_MBOX_TAG_GET_TOUCHBUF		0x0004000f
443 
444 struct bcm2835_mbox_tag_touchbuf {
445 	struct bcm2835_mbox_hdr hdr;
446 	struct bcm2835_mbox_tag_hdr tag_hdr;
447 	union {
448 		struct {
449 		} req;
450 		struct {
451 			uint32_t address;
452 		} resp;
453 	} body;
454 	uint32_t end_tag;
455 };
456 
457 struct bcm2835_fb_config {
458 	uint32_t xres;
459 	uint32_t yres;
460 	uint32_t vxres;
461 	uint32_t vyres;
462 	uint32_t xoffset;
463 	uint32_t yoffset;
464 	uint32_t bpp;
465 	uint32_t pitch;
466 	uint32_t base;
467 	uint32_t size;
468 };
469 
470 struct msg_fb_get_w_h {
471 	struct bcm2835_mbox_hdr hdr;
472 	struct bcm2835_mbox_tag_fb_w_h physical_w_h;
473 	uint32_t end_tag;
474 };
475 
476 int bcm2835_mbox_fb_get_w_h(struct bcm2835_fb_config *);
477 
478 struct msg_fb_get_bpp {
479 	struct bcm2835_mbox_hdr hdr;
480 	struct bcm2835_mbox_tag_depth bpp;
481 	uint32_t end_tag;
482 };
483 
484 int bcm2835_mbox_fb_get_bpp(struct bcm2835_fb_config *);
485 
486 struct msg_fb_setup {
487 	struct bcm2835_mbox_hdr hdr;
488 	struct bcm2835_mbox_tag_fb_w_h physical_w_h;
489 	struct bcm2835_mbox_tag_fb_w_h virtual_w_h;
490 	struct bcm2835_mbox_tag_virtual_offset offset;
491 	struct bcm2835_mbox_tag_depth depth;
492 	struct bcm2835_mbox_tag_alpha_mode alpha;
493 	struct bcm2835_mbox_tag_allocate_buffer buffer;
494 	struct bcm2835_mbox_tag_pitch pitch;
495 	uint32_t end_tag;
496 };
497 
498 int bcm2835_mbox_fb_init(struct bcm2835_fb_config *);
499 
500 int bcm2835_mbox_property(void *, size_t);
501 
502 #endif /* _BCM2835_MBOX_PROP_H_ */
503