bcm2835_mbox_prop.h revision 290381
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: head/sys/arm/broadcom/bcm2835/bcm2835_mbox_prop.h 290381 2015-11-05 03:46:54Z gonzo $
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
44struct bcm2835_mbox_hdr {
45	uint32_t	buf_size;
46	uint32_t	code;
47};
48
49struct 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
77struct 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
92struct 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 */
109int 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
122#define BCM2835_MBOX_TAG_GET_CLOCK_RATE		0x00030002
123#define BCM2835_MBOX_TAG_SET_CLOCK_RATE		0x00038002
124#define BCM2835_MBOX_TAG_GET_MAX_CLOCK_RATE	0x00030004
125#define BCM2835_MBOX_TAG_GET_MIN_CLOCK_RATE	0x00030007
126
127struct msg_get_clock_rate {
128	struct bcm2835_mbox_hdr hdr;
129	struct bcm2835_mbox_tag_hdr tag_hdr;
130	union {
131		struct {
132			uint32_t clock_id;
133		} req;
134		struct {
135			uint32_t clock_id;
136			uint32_t rate_hz;
137		} resp;
138	} body;
139	uint32_t end_tag;
140};
141
142struct msg_set_clock_rate {
143	struct bcm2835_mbox_hdr hdr;
144	struct bcm2835_mbox_tag_hdr tag_hdr;
145	union {
146		struct {
147			uint32_t clock_id;
148			uint32_t rate_hz;
149		} req;
150		struct {
151			uint32_t clock_id;
152			uint32_t rate_hz;
153		} resp;
154	} body;
155	uint32_t end_tag;
156};
157
158struct msg_get_max_clock_rate {
159	struct bcm2835_mbox_hdr hdr;
160	struct bcm2835_mbox_tag_hdr tag_hdr;
161	union {
162		struct {
163			uint32_t clock_id;
164		} req;
165		struct {
166			uint32_t clock_id;
167			uint32_t rate_hz;
168		} resp;
169	} body;
170	uint32_t end_tag;
171};
172
173struct msg_get_min_clock_rate {
174	struct bcm2835_mbox_hdr hdr;
175	struct bcm2835_mbox_tag_hdr tag_hdr;
176	union {
177		struct {
178			uint32_t clock_id;
179		} req;
180		struct {
181			uint32_t clock_id;
182			uint32_t rate_hz;
183		} resp;
184	} body;
185	uint32_t end_tag;
186};
187
188int bcm2835_mbox_get_clock_rate(uint32_t, uint32_t *);
189
190#define BCM2835_MBOX_TURBO_ON			1
191#define BCM2835_MBOX_TURBO_OFF			0
192
193#define BCM2835_MBOX_TAG_GET_TURBO		0x00030009
194#define BCM2835_MBOX_TAG_SET_TURBO		0x00038009
195
196struct msg_get_turbo {
197	struct bcm2835_mbox_hdr hdr;
198	struct bcm2835_mbox_tag_hdr tag_hdr;
199	union {
200		struct {
201			uint32_t id;
202		} req;
203		struct {
204			uint32_t id;
205			uint32_t level;
206		} resp;
207	} body;
208	uint32_t end_tag;
209};
210
211struct msg_set_turbo {
212	struct bcm2835_mbox_hdr hdr;
213	struct bcm2835_mbox_tag_hdr tag_hdr;
214	union {
215		struct {
216			uint32_t id;
217			uint32_t level;
218		} req;
219		struct {
220			uint32_t id;
221			uint32_t level;
222		} resp;
223	} body;
224	uint32_t end_tag;
225};
226
227#define BCM2835_MBOX_VOLTAGE_ID_CORE		0x00000001
228#define BCM2835_MBOX_VOLTAGE_ID_SDRAM_C		0x00000002
229#define BCM2835_MBOX_VOLTAGE_ID_SDRAM_P		0x00000003
230#define BCM2835_MBOX_VOLTAGE_ID_SDRAM_I		0x00000004
231
232#define BCM2835_MBOX_TAG_GET_VOLTAGE		0x00030003
233#define BCM2835_MBOX_TAG_SET_VOLTAGE		0x00038003
234#define BCM2835_MBOX_TAG_GET_MAX_VOLTAGE	0x00030005
235#define BCM2835_MBOX_TAG_GET_MIN_VOLTAGE	0x00030008
236
237struct msg_get_voltage {
238	struct bcm2835_mbox_hdr hdr;
239	struct bcm2835_mbox_tag_hdr tag_hdr;
240	union {
241		struct {
242			uint32_t voltage_id;
243		} req;
244		struct {
245			uint32_t voltage_id;
246			uint32_t value;
247		} resp;
248	} body;
249	uint32_t end_tag;
250};
251
252struct msg_set_voltage {
253	struct bcm2835_mbox_hdr hdr;
254	struct bcm2835_mbox_tag_hdr tag_hdr;
255	union {
256		struct {
257			uint32_t voltage_id;
258			uint32_t value;
259		} req;
260		struct {
261			uint32_t voltage_id;
262			uint32_t value;
263		} resp;
264	} body;
265	uint32_t end_tag;
266};
267
268struct msg_get_max_voltage {
269	struct bcm2835_mbox_hdr hdr;
270	struct bcm2835_mbox_tag_hdr tag_hdr;
271	union {
272		struct {
273			uint32_t voltage_id;
274		} req;
275		struct {
276			uint32_t voltage_id;
277			uint32_t value;
278		} resp;
279	} body;
280	uint32_t end_tag;
281};
282
283struct msg_get_min_voltage {
284	struct bcm2835_mbox_hdr hdr;
285	struct bcm2835_mbox_tag_hdr tag_hdr;
286	union {
287		struct {
288			uint32_t voltage_id;
289		} req;
290		struct {
291			uint32_t voltage_id;
292			uint32_t value;
293		} resp;
294	} body;
295	uint32_t end_tag;
296};
297
298#define BCM2835_MBOX_TAG_GET_TEMPERATURE	0x00030006
299#define BCM2835_MBOX_TAG_GET_MAX_TEMPERATURE	0x0003000a
300
301struct msg_get_temperature {
302	struct bcm2835_mbox_hdr hdr;
303	struct bcm2835_mbox_tag_hdr tag_hdr;
304	union {
305		struct {
306			uint32_t temperature_id;
307		} req;
308		struct {
309			uint32_t temperature_id;
310			uint32_t value;
311		} resp;
312	} body;
313	uint32_t end_tag;
314};
315
316struct msg_get_max_temperature {
317	struct bcm2835_mbox_hdr hdr;
318	struct bcm2835_mbox_tag_hdr tag_hdr;
319	union {
320		struct {
321			uint32_t temperature_id;
322		} req;
323		struct {
324			uint32_t temperature_id;
325			uint32_t value;
326		} resp;
327	} body;
328	uint32_t end_tag;
329};
330
331#define	BCM2835_MBOX_TAG_GET_PHYSICAL_W_H	0x00040003
332#define	BCM2835_MBOX_TAG_SET_PHYSICAL_W_H	0x00048003
333#define	BCM2835_MBOX_TAG_GET_VIRTUAL_W_H	0x00040004
334#define	BCM2835_MBOX_TAG_SET_VIRTUAL_W_H	0x00048004
335
336struct bcm2835_mbox_tag_fb_w_h {
337	struct bcm2835_mbox_tag_hdr tag_hdr;
338	union {
339		struct {
340			uint32_t width;
341			uint32_t height;
342		} req;
343		struct {
344			uint32_t width;
345			uint32_t height;
346		} resp;
347	} body;
348};
349
350#define	BCM2835_MBOX_TAG_GET_DEPTH		0x00040005
351#define	BCM2835_MBOX_TAG_SET_DEPTH		0x00048005
352
353struct bcm2835_mbox_tag_depth {
354	struct bcm2835_mbox_tag_hdr tag_hdr;
355	union {
356		struct {
357			uint32_t bpp;
358		} req;
359		struct {
360			uint32_t bpp;
361		} resp;
362	} body;
363};
364
365#define	BCM2835_MBOX_TAG_GET_ALPHA_MODE		0x00040007
366#define	BCM2835_MBOX_TAG_SET_ALPHA_MODE		0x00048007
367
368#define	BCM2835_MBOX_ALPHA_MODE_0_OPAQUE	0
369#define	BCM2835_MBOX_ALPHA_MODE_0_TRANSPARENT	1
370#define	BCM2835_MBOX_ALPHA_MODE_IGNORED		2
371
372struct bcm2835_mbox_tag_alpha_mode {
373	struct bcm2835_mbox_tag_hdr tag_hdr;
374	union {
375		struct {
376			uint32_t alpha;
377		} req;
378		struct {
379			uint32_t alpha;
380		} resp;
381	} body;
382};
383
384#define	BCM2835_MBOX_TAG_GET_VIRTUAL_OFFSET	0x00040009
385#define	BCM2835_MBOX_TAG_SET_VIRTUAL_OFFSET	0x00048009
386
387struct bcm2835_mbox_tag_virtual_offset {
388	struct bcm2835_mbox_tag_hdr tag_hdr;
389	union {
390		struct {
391			uint32_t x;
392			uint32_t y;
393		} req;
394		struct {
395			uint32_t x;
396			uint32_t y;
397		} resp;
398	} body;
399};
400
401#define	BCM2835_MBOX_TAG_GET_PITCH		0x00040008
402
403struct bcm2835_mbox_tag_pitch {
404	struct bcm2835_mbox_tag_hdr tag_hdr;
405	union {
406		struct {
407		} req;
408		struct {
409			uint32_t pitch;
410		} resp;
411	} body;
412};
413
414#define	BCM2835_MBOX_TAG_ALLOCATE_BUFFER	0x00040001
415
416struct bcm2835_mbox_tag_allocate_buffer {
417	struct bcm2835_mbox_tag_hdr tag_hdr;
418	union {
419		struct {
420			uint32_t alignment;
421		} req;
422		struct {
423			uint32_t fb_address;
424			uint32_t fb_size;
425		} resp;
426	} body;
427};
428
429#define	BCM2835_MBOX_TAG_RELEASE_BUFFER		0x00048001
430
431struct bcm2835_mbox_tag_release_buffer {
432	struct bcm2835_mbox_tag_hdr tag_hdr;
433	union {
434		struct {
435		} req;
436		struct {
437		} resp;
438	} body;
439};
440
441#define	BCM2835_MBOX_TAG_GET_TOUCHBUF		0x0004000f
442
443struct bcm2835_mbox_tag_touchbuf {
444	struct bcm2835_mbox_hdr hdr;
445	struct bcm2835_mbox_tag_hdr tag_hdr;
446	union {
447		struct {
448		} req;
449		struct {
450			uint32_t address;
451		} resp;
452	} body;
453	uint32_t end_tag;
454};
455
456struct bcm2835_fb_config {
457	uint32_t xres;
458	uint32_t yres;
459	uint32_t vxres;
460	uint32_t vyres;
461	uint32_t xoffset;
462	uint32_t yoffset;
463	uint32_t bpp;
464	uint32_t pitch;
465	uint32_t base;
466	uint32_t size;
467};
468
469struct msg_fb_get_w_h {
470	struct bcm2835_mbox_hdr hdr;
471	struct bcm2835_mbox_tag_fb_w_h physical_w_h;
472	struct bcm2835_mbox_tag_fb_w_h virtual_w_h;
473	struct bcm2835_mbox_tag_virtual_offset offset;
474	uint32_t end_tag;
475};
476
477int bcm2835_mbox_fb_get_w_h(struct bcm2835_fb_config *);
478
479struct msg_fb_setup {
480	struct bcm2835_mbox_hdr hdr;
481	struct bcm2835_mbox_tag_fb_w_h physical_w_h;
482	struct bcm2835_mbox_tag_fb_w_h virtual_w_h;
483	struct bcm2835_mbox_tag_virtual_offset offset;
484	struct bcm2835_mbox_tag_depth depth;
485	struct bcm2835_mbox_tag_alpha_mode alpha;
486	struct bcm2835_mbox_tag_allocate_buffer buffer;
487	struct bcm2835_mbox_tag_pitch pitch;
488	uint32_t end_tag;
489};
490
491int bcm2835_mbox_fb_init(struct bcm2835_fb_config *);
492
493int bcm2835_mbox_property(void *, size_t);
494
495#endif /* _BCM2835_MBOX_PROP_H_ */
496