xref: /freebsd/sys/arm/broadcom/bcm2835/bcm2835_firmware.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1201a1f34SAndrew Turner /*-
2201a1f34SAndrew Turner  * SPDX-License-Identifier: BSD-2-Clause
3201a1f34SAndrew Turner  *
4201a1f34SAndrew Turner  * Copyright (c) 2020 Andrew Turner
5201a1f34SAndrew Turner  *
6201a1f34SAndrew Turner  * This work was supported by Innovate UK project 105694, "Digital Security
7201a1f34SAndrew Turner  * by Design (DSbD) Technology Platform Prototype".
8201a1f34SAndrew Turner  *
9201a1f34SAndrew Turner  * Redistribution and use in source and binary forms, with or without
10201a1f34SAndrew Turner  * modification, are permitted provided that the following conditions
11201a1f34SAndrew Turner  * are met:
12201a1f34SAndrew Turner  * 1. Redistributions of source code must retain the above copyright
13201a1f34SAndrew Turner  *    notice, this list of conditions and the following disclaimer.
14201a1f34SAndrew Turner  * 2. Redistributions in binary form must reproduce the above copyright
15201a1f34SAndrew Turner  *    notice, this list of conditions and the following disclaimer in the
16201a1f34SAndrew Turner  *    documentation and/or other materials provided with the distribution.
17201a1f34SAndrew Turner  *
18201a1f34SAndrew Turner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19201a1f34SAndrew Turner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20201a1f34SAndrew Turner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21201a1f34SAndrew Turner  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22201a1f34SAndrew Turner  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23201a1f34SAndrew Turner  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24201a1f34SAndrew Turner  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25201a1f34SAndrew Turner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26201a1f34SAndrew Turner  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27201a1f34SAndrew Turner  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28201a1f34SAndrew Turner  * SUCH DAMAGE.
29201a1f34SAndrew Turner  */
30201a1f34SAndrew Turner 
31201a1f34SAndrew Turner #ifndef _BCM2835_FIRMWARE_H_
32201a1f34SAndrew Turner #define _BCM2835_FIRMWARE_H_
33201a1f34SAndrew Turner 
347413ae0eSAndrew Turner #define BCM2835_FIRMWARE_TAG_GET_CLOCK_RATE		0x00030002
357413ae0eSAndrew Turner #define BCM2835_FIRMWARE_TAG_SET_CLOCK_RATE		0x00038002
367413ae0eSAndrew Turner #define BCM2835_FIRMWARE_TAG_GET_MAX_CLOCK_RATE		0x00030004
377413ae0eSAndrew Turner #define BCM2835_FIRMWARE_TAG_GET_MIN_CLOCK_RATE		0x00030007
387413ae0eSAndrew Turner 
397413ae0eSAndrew Turner #define BCM2835_FIRMWARE_CLOCK_ID_EMMC			0x00000001
407413ae0eSAndrew Turner #define BCM2835_FIRMWARE_CLOCK_ID_UART			0x00000002
417413ae0eSAndrew Turner #define BCM2835_FIRMWARE_CLOCK_ID_ARM			0x00000003
427413ae0eSAndrew Turner #define BCM2835_FIRMWARE_CLOCK_ID_CORE			0x00000004
437413ae0eSAndrew Turner #define BCM2835_FIRMWARE_CLOCK_ID_V3D			0x00000005
447413ae0eSAndrew Turner #define BCM2835_FIRMWARE_CLOCK_ID_H264			0x00000006
457413ae0eSAndrew Turner #define BCM2835_FIRMWARE_CLOCK_ID_ISP			0x00000007
467413ae0eSAndrew Turner #define BCM2835_FIRMWARE_CLOCK_ID_SDRAM			0x00000008
477413ae0eSAndrew Turner #define BCM2835_FIRMWARE_CLOCK_ID_PIXEL			0x00000009
487413ae0eSAndrew Turner #define BCM2835_FIRMWARE_CLOCK_ID_PWM			0x0000000a
497413ae0eSAndrew Turner #define BCM2838_FIRMWARE_CLOCK_ID_EMMC2			0x0000000c
507413ae0eSAndrew Turner 
517413ae0eSAndrew Turner union msg_get_clock_rate_body {
527413ae0eSAndrew Turner 	struct {
537413ae0eSAndrew Turner 		uint32_t clock_id;
547413ae0eSAndrew Turner 	} req;
557413ae0eSAndrew Turner 	struct {
567413ae0eSAndrew Turner 		uint32_t clock_id;
577413ae0eSAndrew Turner 		uint32_t rate_hz;
587413ae0eSAndrew Turner 	} resp;
597413ae0eSAndrew Turner };
607413ae0eSAndrew Turner 
617413ae0eSAndrew Turner union msg_set_clock_rate_body {
627413ae0eSAndrew Turner 	struct {
637413ae0eSAndrew Turner 		uint32_t clock_id;
647413ae0eSAndrew Turner 		uint32_t rate_hz;
657413ae0eSAndrew Turner 	} req;
667413ae0eSAndrew Turner 	struct {
677413ae0eSAndrew Turner 		uint32_t clock_id;
687413ae0eSAndrew Turner 		uint32_t rate_hz;
697413ae0eSAndrew Turner 	} resp;
707413ae0eSAndrew Turner };
717413ae0eSAndrew Turner 
727413ae0eSAndrew Turner #define BCM2835_FIRMWARE_TAG_GET_VOLTAGE		0x00030003
737413ae0eSAndrew Turner #define BCM2835_FIRMWARE_TAG_SET_VOLTAGE		0x00038003
747413ae0eSAndrew Turner #define BCM2835_FIRMWARE_TAG_GET_MAX_VOLTAGE		0x00030005
757413ae0eSAndrew Turner #define BCM2835_FIRMWARE_TAG_GET_MIN_VOLTAGE		0x00030008
767413ae0eSAndrew Turner 
777413ae0eSAndrew Turner #define BCM2835_FIRMWARE_VOLTAGE_ID_CORE		0x00000001
787413ae0eSAndrew Turner #define BCM2835_FIRMWARE_VOLTAGE_ID_SDRAM_C		0x00000002
797413ae0eSAndrew Turner #define BCM2835_FIRMWARE_VOLTAGE_ID_SDRAM_P		0x00000003
807413ae0eSAndrew Turner #define BCM2835_FIRMWARE_VOLTAGE_ID_SDRAM_I		0x00000004
817413ae0eSAndrew Turner 
827413ae0eSAndrew Turner union msg_get_voltage_body {
837413ae0eSAndrew Turner 	struct {
847413ae0eSAndrew Turner 		uint32_t voltage_id;
857413ae0eSAndrew Turner 	} req;
867413ae0eSAndrew Turner 	struct {
877413ae0eSAndrew Turner 		uint32_t voltage_id;
887413ae0eSAndrew Turner 		uint32_t value;
897413ae0eSAndrew Turner 	} resp;
907413ae0eSAndrew Turner };
917413ae0eSAndrew Turner 
927413ae0eSAndrew Turner union msg_set_voltage_body {
937413ae0eSAndrew Turner 	struct {
947413ae0eSAndrew Turner 		uint32_t voltage_id;
957413ae0eSAndrew Turner 		uint32_t value;
967413ae0eSAndrew Turner 	} req;
977413ae0eSAndrew Turner 	struct {
987413ae0eSAndrew Turner 		uint32_t voltage_id;
997413ae0eSAndrew Turner 		uint32_t value;
1007413ae0eSAndrew Turner 	} resp;
1017413ae0eSAndrew Turner };
1027413ae0eSAndrew Turner 
1037413ae0eSAndrew Turner #define BCM2835_FIRMWARE_TAG_GET_TEMPERATURE		0x00030006
1047413ae0eSAndrew Turner #define BCM2835_FIRMWARE_TAG_GET_MAX_TEMPERATURE	0x0003000a
1057413ae0eSAndrew Turner 
1067413ae0eSAndrew Turner union msg_get_temperature_body {
1077413ae0eSAndrew Turner 	struct {
1087413ae0eSAndrew Turner 		uint32_t temperature_id;
1097413ae0eSAndrew Turner 	} req;
1107413ae0eSAndrew Turner 	struct {
1117413ae0eSAndrew Turner 		uint32_t temperature_id;
1127413ae0eSAndrew Turner 		uint32_t value;
1137413ae0eSAndrew Turner 	} resp;
1147413ae0eSAndrew Turner };
1157413ae0eSAndrew Turner 
1167413ae0eSAndrew Turner #define BCM2835_FIRMWARE_TAG_GET_TURBO			0x00030009
1177413ae0eSAndrew Turner #define BCM2835_FIRMWARE_TAG_SET_TURBO			0x00038009
1187413ae0eSAndrew Turner 
1197413ae0eSAndrew Turner #define BCM2835_FIRMWARE_TURBO_ON			1
1207413ae0eSAndrew Turner #define BCM2835_FIRMWARE_TURBO_OFF			0
1217413ae0eSAndrew Turner 
1227413ae0eSAndrew Turner union msg_get_turbo_body {
1237413ae0eSAndrew Turner 	struct {
1247413ae0eSAndrew Turner 		uint32_t id;
1257413ae0eSAndrew Turner 	} req;
1267413ae0eSAndrew Turner 	struct {
1277413ae0eSAndrew Turner 		uint32_t id;
1287413ae0eSAndrew Turner 		uint32_t level;
1297413ae0eSAndrew Turner 	} resp;
1307413ae0eSAndrew Turner };
1317413ae0eSAndrew Turner 
1327413ae0eSAndrew Turner union msg_set_turbo_body {
1337413ae0eSAndrew Turner 	struct {
1347413ae0eSAndrew Turner 		uint32_t id;
1357413ae0eSAndrew Turner 		uint32_t level;
1367413ae0eSAndrew Turner 	} req;
1377413ae0eSAndrew Turner 	struct {
1387413ae0eSAndrew Turner 		uint32_t id;
1397413ae0eSAndrew Turner 		uint32_t level;
1407413ae0eSAndrew Turner 	} resp;
1417413ae0eSAndrew Turner };
1427413ae0eSAndrew Turner 
143*d9501cbaSAndrew Turner #define	BCM2835_FIRMWARE_TAG_GET_GPIO_STATE		0x00030041
144*d9501cbaSAndrew Turner #define	BCM2835_FIRMWARE_TAG_SET_GPIO_STATE		0x00038041
145*d9501cbaSAndrew Turner #define	BCM2835_FIRMWARE_TAG_GET_GPIO_CONFIG		0x00030043
146*d9501cbaSAndrew Turner #define	BCM2835_FIRMWARE_TAG_SET_GPIO_CONFIG		0x00038043
147*d9501cbaSAndrew Turner 
148*d9501cbaSAndrew Turner #define	BCM2835_FIRMWARE_GPIO_IN			0
149*d9501cbaSAndrew Turner #define	BCM2835_FIRMWARE_GPIO_OUT			1
150*d9501cbaSAndrew Turner 
151*d9501cbaSAndrew Turner union msg_get_gpio_state {
152*d9501cbaSAndrew Turner 	struct {
153*d9501cbaSAndrew Turner 		uint32_t gpio;
154*d9501cbaSAndrew Turner 	} req;
155*d9501cbaSAndrew Turner 	struct {
156*d9501cbaSAndrew Turner 		uint32_t gpio;
157*d9501cbaSAndrew Turner 		uint32_t state;
158*d9501cbaSAndrew Turner 	} resp;
159*d9501cbaSAndrew Turner };
160*d9501cbaSAndrew Turner 
161*d9501cbaSAndrew Turner union msg_set_gpio_state {
162*d9501cbaSAndrew Turner 	struct {
163*d9501cbaSAndrew Turner 		uint32_t gpio;
164*d9501cbaSAndrew Turner 		uint32_t state;
165*d9501cbaSAndrew Turner 	} req;
166*d9501cbaSAndrew Turner 	struct {
167*d9501cbaSAndrew Turner 		uint32_t gpio;
168*d9501cbaSAndrew Turner 	} resp;
169*d9501cbaSAndrew Turner };
170*d9501cbaSAndrew Turner 
171*d9501cbaSAndrew Turner union msg_get_gpio_config {
172*d9501cbaSAndrew Turner 	struct {
173*d9501cbaSAndrew Turner 		uint32_t gpio;
174*d9501cbaSAndrew Turner 	} req;
175*d9501cbaSAndrew Turner 	struct {
176*d9501cbaSAndrew Turner 		uint32_t gpio;
177*d9501cbaSAndrew Turner 		uint32_t dir;
178*d9501cbaSAndrew Turner 		uint32_t pol;
179*d9501cbaSAndrew Turner 		uint32_t term_en;
180*d9501cbaSAndrew Turner 		uint32_t term_pull_up;
181*d9501cbaSAndrew Turner 	} resp;
182*d9501cbaSAndrew Turner };
183*d9501cbaSAndrew Turner 
184*d9501cbaSAndrew Turner union msg_set_gpio_config {
185*d9501cbaSAndrew Turner 	struct {
186*d9501cbaSAndrew Turner 		uint32_t gpio;
187*d9501cbaSAndrew Turner 		uint32_t dir;
188*d9501cbaSAndrew Turner 		uint32_t pol;
189*d9501cbaSAndrew Turner 		uint32_t term_en;
190*d9501cbaSAndrew Turner 		uint32_t term_pull_up;
191*d9501cbaSAndrew Turner 		uint32_t state;
192*d9501cbaSAndrew Turner 	} req;
193*d9501cbaSAndrew Turner 	struct {
194*d9501cbaSAndrew Turner 		uint32_t gpio;
195*d9501cbaSAndrew Turner 	} resp;
196*d9501cbaSAndrew Turner };
197*d9501cbaSAndrew Turner 
198201a1f34SAndrew Turner int bcm2835_firmware_property(device_t, uint32_t, void *, size_t);
199201a1f34SAndrew Turner 
200201a1f34SAndrew Turner #endif
201