bcm2835_mbox_prop.h revision 280294
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 280294 2015-03-20 16:54:21Z andrew $
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_POWER_ID_EMMC		0x00000000
56#define BCM2835_MBOX_POWER_ID_UART0		0x00000001
57#define BCM2835_MBOX_POWER_ID_UART1		0x00000002
58#define BCM2835_MBOX_POWER_ID_USB_HCD		0x00000003
59#define BCM2835_MBOX_POWER_ID_I2C0		0x00000004
60#define BCM2835_MBOX_POWER_ID_I2C1		0x00000005
61#define BCM2835_MBOX_POWER_ID_I2C2		0x00000006
62#define BCM2835_MBOX_POWER_ID_SPI		0x00000007
63#define BCM2835_MBOX_POWER_ID_CCP2TX		0x00000008
64
65#define BCM2835_MBOX_POWER_ON			(1 << 0)
66#define BCM2835_MBOX_POWER_WAIT			(1 << 1)
67
68#define BCM2835_MBOX_TAG_GET_POWER_STATE	0x00020001
69#define BCM2835_MBOX_TAG_SET_POWER_STATE	0x00028001
70
71struct msg_get_power_state {
72	struct bcm2835_mbox_hdr hdr;
73	struct bcm2835_mbox_tag_hdr tag_hdr;
74	union {
75		struct {
76			uint32_t device_id;
77		} req;
78		struct {
79			uint32_t device_id;
80			uint32_t state;
81		} resp;
82	} body;
83	uint32_t end_tag;
84};
85
86struct msg_set_power_state {
87	struct bcm2835_mbox_hdr hdr;
88	struct bcm2835_mbox_tag_hdr tag_hdr;
89	union {
90		struct {
91			uint32_t device_id;
92			uint32_t state;
93		} req;
94		struct {
95			uint32_t device_id;
96			uint32_t state;
97		} resp;
98	} body;
99	uint32_t end_tag;
100};
101
102/* Sets the power state for a given device */
103int bcm2835_mbox_set_power_state(device_t, uint32_t, boolean_t);
104
105#define BCM2835_MBOX_CLOCK_ID_EMMC		0x00000001
106#define BCM2835_MBOX_CLOCK_ID_UART		0x00000002
107#define BCM2835_MBOX_CLOCK_ID_ARM		0x00000003
108#define BCM2835_MBOX_CLOCK_ID_CORE		0x00000004
109#define BCM2835_MBOX_CLOCK_ID_V3D		0x00000005
110#define BCM2835_MBOX_CLOCK_ID_H264		0x00000006
111#define BCM2835_MBOX_CLOCK_ID_ISP		0x00000007
112#define BCM2835_MBOX_CLOCK_ID_SDRAM		0x00000008
113#define BCM2835_MBOX_CLOCK_ID_PIXEL		0x00000009
114#define BCM2835_MBOX_CLOCK_ID_PWM		0x0000000a
115
116#define BCM2835_MBOX_TAG_GET_CLOCK_RATE		0x00030002
117#define BCM2835_MBOX_TAG_SET_CLOCK_RATE		0x00038002
118#define BCM2835_MBOX_TAG_GET_MAX_CLOCK_RATE	0x00030004
119#define BCM2835_MBOX_TAG_GET_MIN_CLOCK_RATE	0x00030007
120
121struct msg_get_clock_rate {
122	struct bcm2835_mbox_hdr hdr;
123	struct bcm2835_mbox_tag_hdr tag_hdr;
124	union {
125		struct {
126			uint32_t clock_id;
127		} req;
128		struct {
129			uint32_t clock_id;
130			uint32_t rate_hz;
131		} resp;
132	} body;
133	uint32_t end_tag;
134};
135
136struct msg_set_clock_rate {
137	struct bcm2835_mbox_hdr hdr;
138	struct bcm2835_mbox_tag_hdr tag_hdr;
139	union {
140		struct {
141			uint32_t clock_id;
142			uint32_t rate_hz;
143		} req;
144		struct {
145			uint32_t clock_id;
146			uint32_t rate_hz;
147		} resp;
148	} body;
149	uint32_t end_tag;
150};
151
152struct msg_get_max_clock_rate {
153	struct bcm2835_mbox_hdr hdr;
154	struct bcm2835_mbox_tag_hdr tag_hdr;
155	union {
156		struct {
157			uint32_t clock_id;
158		} req;
159		struct {
160			uint32_t clock_id;
161			uint32_t rate_hz;
162		} resp;
163	} body;
164	uint32_t end_tag;
165};
166
167struct msg_get_min_clock_rate {
168	struct bcm2835_mbox_hdr hdr;
169	struct bcm2835_mbox_tag_hdr tag_hdr;
170	union {
171		struct {
172			uint32_t clock_id;
173		} req;
174		struct {
175			uint32_t clock_id;
176			uint32_t rate_hz;
177		} resp;
178	} body;
179	uint32_t end_tag;
180};
181
182int bcm2835_mbox_get_clock_rate(device_t, uint32_t, uint32_t *);
183
184#define BCM2835_MBOX_TURBO_ON			1
185#define BCM2835_MBOX_TURBO_OFF			0
186
187#define BCM2835_MBOX_TAG_GET_TURBO		0x00030009
188#define BCM2835_MBOX_TAG_SET_TURBO		0x00038009
189
190struct msg_get_turbo {
191	struct bcm2835_mbox_hdr hdr;
192	struct bcm2835_mbox_tag_hdr tag_hdr;
193	union {
194		struct {
195			uint32_t id;
196		} req;
197		struct {
198			uint32_t id;
199			uint32_t level;
200		} resp;
201	} body;
202	uint32_t end_tag;
203};
204
205struct msg_set_turbo {
206	struct bcm2835_mbox_hdr hdr;
207	struct bcm2835_mbox_tag_hdr tag_hdr;
208	union {
209		struct {
210			uint32_t id;
211			uint32_t level;
212		} req;
213		struct {
214			uint32_t id;
215			uint32_t level;
216		} resp;
217	} body;
218	uint32_t end_tag;
219};
220
221#define BCM2835_MBOX_VOLTAGE_ID_CORE		0x00000001
222#define BCM2835_MBOX_VOLTAGE_ID_SDRAM_C		0x00000002
223#define BCM2835_MBOX_VOLTAGE_ID_SDRAM_P		0x00000003
224#define BCM2835_MBOX_VOLTAGE_ID_SDRAM_I		0x00000004
225
226#define BCM2835_MBOX_TAG_GET_VOLTAGE		0x00030003
227#define BCM2835_MBOX_TAG_SET_VOLTAGE		0x00038003
228#define BCM2835_MBOX_TAG_GET_MAX_VOLTAGE	0x00030005
229#define BCM2835_MBOX_TAG_GET_MIN_VOLTAGE	0x00030008
230
231struct msg_get_voltage {
232	struct bcm2835_mbox_hdr hdr;
233	struct bcm2835_mbox_tag_hdr tag_hdr;
234	union {
235		struct {
236			uint32_t voltage_id;
237		} req;
238		struct {
239			uint32_t voltage_id;
240			uint32_t value;
241		} resp;
242	} body;
243	uint32_t end_tag;
244};
245
246struct msg_set_voltage {
247	struct bcm2835_mbox_hdr hdr;
248	struct bcm2835_mbox_tag_hdr tag_hdr;
249	union {
250		struct {
251			uint32_t voltage_id;
252			uint32_t value;
253		} req;
254		struct {
255			uint32_t voltage_id;
256			uint32_t value;
257		} resp;
258	} body;
259	uint32_t end_tag;
260};
261
262struct msg_get_max_voltage {
263	struct bcm2835_mbox_hdr hdr;
264	struct bcm2835_mbox_tag_hdr tag_hdr;
265	union {
266		struct {
267			uint32_t voltage_id;
268		} req;
269		struct {
270			uint32_t voltage_id;
271			uint32_t value;
272		} resp;
273	} body;
274	uint32_t end_tag;
275};
276
277struct msg_get_min_voltage {
278	struct bcm2835_mbox_hdr hdr;
279	struct bcm2835_mbox_tag_hdr tag_hdr;
280	union {
281		struct {
282			uint32_t voltage_id;
283		} req;
284		struct {
285			uint32_t voltage_id;
286			uint32_t value;
287		} resp;
288	} body;
289	uint32_t end_tag;
290};
291
292#define BCM2835_MBOX_TAG_GET_TEMPERATURE	0x00030006
293#define BCM2835_MBOX_TAG_GET_MAX_TEMPERATURE	0x0003000a
294
295struct msg_get_temperature {
296	struct bcm2835_mbox_hdr hdr;
297	struct bcm2835_mbox_tag_hdr tag_hdr;
298	union {
299		struct {
300			uint32_t temperature_id;
301		} req;
302		struct {
303			uint32_t temperature_id;
304			uint32_t value;
305		} resp;
306	} body;
307	uint32_t end_tag;
308};
309
310struct msg_get_max_temperature {
311	struct bcm2835_mbox_hdr hdr;
312	struct bcm2835_mbox_tag_hdr tag_hdr;
313	union {
314		struct {
315			uint32_t temperature_id;
316		} req;
317		struct {
318			uint32_t temperature_id;
319			uint32_t value;
320		} resp;
321	} body;
322	uint32_t end_tag;
323};
324
325#endif /* _BCM2835_MBOX_PROP_H_ */
326