xref: /freebsd/sys/arm/broadcom/bcm2835/bcm2835_firmware.h (revision 9f44a47fd07924afc035991af15d84e6585dea4f)
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  * $FreeBSD$
31  */
32 
33 #ifndef _BCM2835_FIRMWARE_H_
34 #define _BCM2835_FIRMWARE_H_
35 
36 #define BCM2835_FIRMWARE_TAG_GET_CLOCK_RATE		0x00030002
37 #define BCM2835_FIRMWARE_TAG_SET_CLOCK_RATE		0x00038002
38 #define BCM2835_FIRMWARE_TAG_GET_MAX_CLOCK_RATE		0x00030004
39 #define BCM2835_FIRMWARE_TAG_GET_MIN_CLOCK_RATE		0x00030007
40 
41 #define BCM2835_FIRMWARE_CLOCK_ID_EMMC			0x00000001
42 #define BCM2835_FIRMWARE_CLOCK_ID_UART			0x00000002
43 #define BCM2835_FIRMWARE_CLOCK_ID_ARM			0x00000003
44 #define BCM2835_FIRMWARE_CLOCK_ID_CORE			0x00000004
45 #define BCM2835_FIRMWARE_CLOCK_ID_V3D			0x00000005
46 #define BCM2835_FIRMWARE_CLOCK_ID_H264			0x00000006
47 #define BCM2835_FIRMWARE_CLOCK_ID_ISP			0x00000007
48 #define BCM2835_FIRMWARE_CLOCK_ID_SDRAM			0x00000008
49 #define BCM2835_FIRMWARE_CLOCK_ID_PIXEL			0x00000009
50 #define BCM2835_FIRMWARE_CLOCK_ID_PWM			0x0000000a
51 #define BCM2838_FIRMWARE_CLOCK_ID_EMMC2			0x0000000c
52 
53 union msg_get_clock_rate_body {
54 	struct {
55 		uint32_t clock_id;
56 	} req;
57 	struct {
58 		uint32_t clock_id;
59 		uint32_t rate_hz;
60 	} resp;
61 };
62 
63 union msg_set_clock_rate_body {
64 	struct {
65 		uint32_t clock_id;
66 		uint32_t rate_hz;
67 	} req;
68 	struct {
69 		uint32_t clock_id;
70 		uint32_t rate_hz;
71 	} resp;
72 };
73 
74 #define BCM2835_FIRMWARE_TAG_GET_VOLTAGE		0x00030003
75 #define BCM2835_FIRMWARE_TAG_SET_VOLTAGE		0x00038003
76 #define BCM2835_FIRMWARE_TAG_GET_MAX_VOLTAGE		0x00030005
77 #define BCM2835_FIRMWARE_TAG_GET_MIN_VOLTAGE		0x00030008
78 
79 #define BCM2835_FIRMWARE_VOLTAGE_ID_CORE		0x00000001
80 #define BCM2835_FIRMWARE_VOLTAGE_ID_SDRAM_C		0x00000002
81 #define BCM2835_FIRMWARE_VOLTAGE_ID_SDRAM_P		0x00000003
82 #define BCM2835_FIRMWARE_VOLTAGE_ID_SDRAM_I		0x00000004
83 
84 union msg_get_voltage_body {
85 	struct {
86 		uint32_t voltage_id;
87 	} req;
88 	struct {
89 		uint32_t voltage_id;
90 		uint32_t value;
91 	} resp;
92 };
93 
94 union msg_set_voltage_body {
95 	struct {
96 		uint32_t voltage_id;
97 		uint32_t value;
98 	} req;
99 	struct {
100 		uint32_t voltage_id;
101 		uint32_t value;
102 	} resp;
103 };
104 
105 #define BCM2835_FIRMWARE_TAG_GET_TEMPERATURE		0x00030006
106 #define BCM2835_FIRMWARE_TAG_GET_MAX_TEMPERATURE	0x0003000a
107 
108 union msg_get_temperature_body {
109 	struct {
110 		uint32_t temperature_id;
111 	} req;
112 	struct {
113 		uint32_t temperature_id;
114 		uint32_t value;
115 	} resp;
116 };
117 
118 #define BCM2835_FIRMWARE_TAG_GET_TURBO			0x00030009
119 #define BCM2835_FIRMWARE_TAG_SET_TURBO			0x00038009
120 
121 #define BCM2835_FIRMWARE_TURBO_ON			1
122 #define BCM2835_FIRMWARE_TURBO_OFF			0
123 
124 union msg_get_turbo_body {
125 	struct {
126 		uint32_t id;
127 	} req;
128 	struct {
129 		uint32_t id;
130 		uint32_t level;
131 	} resp;
132 };
133 
134 union msg_set_turbo_body {
135 	struct {
136 		uint32_t id;
137 		uint32_t level;
138 	} req;
139 	struct {
140 		uint32_t id;
141 		uint32_t level;
142 	} resp;
143 };
144 
145 #define	BCM2835_FIRMWARE_TAG_GET_GPIO_STATE		0x00030041
146 #define	BCM2835_FIRMWARE_TAG_SET_GPIO_STATE		0x00038041
147 #define	BCM2835_FIRMWARE_TAG_GET_GPIO_CONFIG		0x00030043
148 #define	BCM2835_FIRMWARE_TAG_SET_GPIO_CONFIG		0x00038043
149 
150 #define	BCM2835_FIRMWARE_GPIO_IN			0
151 #define	BCM2835_FIRMWARE_GPIO_OUT			1
152 
153 union msg_get_gpio_state {
154 	struct {
155 		uint32_t gpio;
156 	} req;
157 	struct {
158 		uint32_t gpio;
159 		uint32_t state;
160 	} resp;
161 };
162 
163 union msg_set_gpio_state {
164 	struct {
165 		uint32_t gpio;
166 		uint32_t state;
167 	} req;
168 	struct {
169 		uint32_t gpio;
170 	} resp;
171 };
172 
173 union msg_get_gpio_config {
174 	struct {
175 		uint32_t gpio;
176 	} req;
177 	struct {
178 		uint32_t gpio;
179 		uint32_t dir;
180 		uint32_t pol;
181 		uint32_t term_en;
182 		uint32_t term_pull_up;
183 	} resp;
184 };
185 
186 union msg_set_gpio_config {
187 	struct {
188 		uint32_t gpio;
189 		uint32_t dir;
190 		uint32_t pol;
191 		uint32_t term_en;
192 		uint32_t term_pull_up;
193 		uint32_t state;
194 	} req;
195 	struct {
196 		uint32_t gpio;
197 	} resp;
198 };
199 
200 int bcm2835_firmware_property(device_t, uint32_t, void *, size_t);
201 
202 #endif
203