xref: /freebsd/sys/arm/broadcom/bcm2835/bcm2835_firmware.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2020 Andrew Turner
5  *
6  * This work was supported by Innovate UK project 105694, "Digital Security
7  * by Design (DSbD) Technology Platform Prototype".
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 #ifndef _BCM2835_FIRMWARE_H_
32 #define _BCM2835_FIRMWARE_H_
33 
34 #define BCM2835_FIRMWARE_TAG_GET_CLOCK_RATE		0x00030002
35 #define BCM2835_FIRMWARE_TAG_SET_CLOCK_RATE		0x00038002
36 #define BCM2835_FIRMWARE_TAG_GET_MAX_CLOCK_RATE		0x00030004
37 #define BCM2835_FIRMWARE_TAG_GET_MIN_CLOCK_RATE		0x00030007
38 
39 #define BCM2835_FIRMWARE_CLOCK_ID_EMMC			0x00000001
40 #define BCM2835_FIRMWARE_CLOCK_ID_UART			0x00000002
41 #define BCM2835_FIRMWARE_CLOCK_ID_ARM			0x00000003
42 #define BCM2835_FIRMWARE_CLOCK_ID_CORE			0x00000004
43 #define BCM2835_FIRMWARE_CLOCK_ID_V3D			0x00000005
44 #define BCM2835_FIRMWARE_CLOCK_ID_H264			0x00000006
45 #define BCM2835_FIRMWARE_CLOCK_ID_ISP			0x00000007
46 #define BCM2835_FIRMWARE_CLOCK_ID_SDRAM			0x00000008
47 #define BCM2835_FIRMWARE_CLOCK_ID_PIXEL			0x00000009
48 #define BCM2835_FIRMWARE_CLOCK_ID_PWM			0x0000000a
49 #define BCM2838_FIRMWARE_CLOCK_ID_EMMC2			0x0000000c
50 
51 union msg_get_clock_rate_body {
52 	struct {
53 		uint32_t clock_id;
54 	} req;
55 	struct {
56 		uint32_t clock_id;
57 		uint32_t rate_hz;
58 	} resp;
59 };
60 
61 union msg_set_clock_rate_body {
62 	struct {
63 		uint32_t clock_id;
64 		uint32_t rate_hz;
65 	} req;
66 	struct {
67 		uint32_t clock_id;
68 		uint32_t rate_hz;
69 	} resp;
70 };
71 
72 #define BCM2835_FIRMWARE_TAG_GET_VOLTAGE		0x00030003
73 #define BCM2835_FIRMWARE_TAG_SET_VOLTAGE		0x00038003
74 #define BCM2835_FIRMWARE_TAG_GET_MAX_VOLTAGE		0x00030005
75 #define BCM2835_FIRMWARE_TAG_GET_MIN_VOLTAGE		0x00030008
76 
77 #define BCM2835_FIRMWARE_VOLTAGE_ID_CORE		0x00000001
78 #define BCM2835_FIRMWARE_VOLTAGE_ID_SDRAM_C		0x00000002
79 #define BCM2835_FIRMWARE_VOLTAGE_ID_SDRAM_P		0x00000003
80 #define BCM2835_FIRMWARE_VOLTAGE_ID_SDRAM_I		0x00000004
81 
82 union msg_get_voltage_body {
83 	struct {
84 		uint32_t voltage_id;
85 	} req;
86 	struct {
87 		uint32_t voltage_id;
88 		uint32_t value;
89 	} resp;
90 };
91 
92 union msg_set_voltage_body {
93 	struct {
94 		uint32_t voltage_id;
95 		uint32_t value;
96 	} req;
97 	struct {
98 		uint32_t voltage_id;
99 		uint32_t value;
100 	} resp;
101 };
102 
103 #define BCM2835_FIRMWARE_TAG_GET_TEMPERATURE		0x00030006
104 #define BCM2835_FIRMWARE_TAG_GET_MAX_TEMPERATURE	0x0003000a
105 
106 union msg_get_temperature_body {
107 	struct {
108 		uint32_t temperature_id;
109 	} req;
110 	struct {
111 		uint32_t temperature_id;
112 		uint32_t value;
113 	} resp;
114 };
115 
116 #define BCM2835_FIRMWARE_TAG_GET_TURBO			0x00030009
117 #define BCM2835_FIRMWARE_TAG_SET_TURBO			0x00038009
118 
119 #define BCM2835_FIRMWARE_TURBO_ON			1
120 #define BCM2835_FIRMWARE_TURBO_OFF			0
121 
122 union msg_get_turbo_body {
123 	struct {
124 		uint32_t id;
125 	} req;
126 	struct {
127 		uint32_t id;
128 		uint32_t level;
129 	} resp;
130 };
131 
132 union msg_set_turbo_body {
133 	struct {
134 		uint32_t id;
135 		uint32_t level;
136 	} req;
137 	struct {
138 		uint32_t id;
139 		uint32_t level;
140 	} resp;
141 };
142 
143 #define	BCM2835_FIRMWARE_TAG_GET_GPIO_STATE		0x00030041
144 #define	BCM2835_FIRMWARE_TAG_SET_GPIO_STATE		0x00038041
145 #define	BCM2835_FIRMWARE_TAG_GET_GPIO_CONFIG		0x00030043
146 #define	BCM2835_FIRMWARE_TAG_SET_GPIO_CONFIG		0x00038043
147 
148 #define	BCM2835_FIRMWARE_GPIO_IN			0
149 #define	BCM2835_FIRMWARE_GPIO_OUT			1
150 
151 union msg_get_gpio_state {
152 	struct {
153 		uint32_t gpio;
154 	} req;
155 	struct {
156 		uint32_t gpio;
157 		uint32_t state;
158 	} resp;
159 };
160 
161 union msg_set_gpio_state {
162 	struct {
163 		uint32_t gpio;
164 		uint32_t state;
165 	} req;
166 	struct {
167 		uint32_t gpio;
168 	} resp;
169 };
170 
171 union msg_get_gpio_config {
172 	struct {
173 		uint32_t gpio;
174 	} req;
175 	struct {
176 		uint32_t gpio;
177 		uint32_t dir;
178 		uint32_t pol;
179 		uint32_t term_en;
180 		uint32_t term_pull_up;
181 	} resp;
182 };
183 
184 union msg_set_gpio_config {
185 	struct {
186 		uint32_t gpio;
187 		uint32_t dir;
188 		uint32_t pol;
189 		uint32_t term_en;
190 		uint32_t term_pull_up;
191 		uint32_t state;
192 	} req;
193 	struct {
194 		uint32_t gpio;
195 	} resp;
196 };
197 
198 int bcm2835_firmware_property(device_t, uint32_t, void *, size_t);
199 
200 #endif
201