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