/*
* Copyright (c) 2014 Michael Lorenz
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
int
rpi_fb_set_video(int b)
{
int error;
uint32_t res;
/*
* might as well put it here since we need to re-init it every time
* and it's not like this is going to be called very often anyway
*/
struct __aligned(16) {
struct vcprop_buffer_hdr vb_hdr;
struct vcprop_tag_blankscreen vbt_blank;
struct vcprop_tag end;
} vb_setblank =
{
.vb_hdr = {
.vpb_len = htole32(sizeof(vb_setblank)),
.vpb_rcode = htole32(VCPROP_PROCESS_REQUEST),
},
.vbt_blank = {
.tag = {
.vpt_tag = htole32(VCPROPTAG_BLANK_SCREEN),
.vpt_len = htole32(VCPROPTAG_LEN(
vb_setblank.vbt_blank)),
.vpt_rcode = htole32(VCPROPTAG_REQUEST),
},
.state = htole32((b != 0) ?
VCPROP_BLANK_OFF : VCPROP_BLANK_ON),
},
.end = {
.vpt_tag = htole32(VCPROPTAG_NULL),
},
};
if (!vcprop_buffer_success_p(&vb_pixelorder.vb_hdr) ||
!vcprop_tag_success_p(&vb_pixelorder.vbt_po.tag)) {
return EIO;
}
return 0;
}
int
rpi_set_domain(uint32_t domain, uint32_t state)
{
int error;
uint32_t tag, res;
tag = VCPROPTAG_SET_DOMAIN_STATE;
if (domain == VCPROP_DOMAIN_USB) {
/* use old interface */
tag = VCPROPTAG_SET_POWERSTATE;
domain = VCPROP_POWER_USB;
}
/*
* might as well put it here since we need to re-init it every time
* and it's not like this is going to be called very often anyway
*/
struct __aligned(16) {
struct vcprop_buffer_hdr vb_hdr;
struct vcprop_tag_powerstate vbt_power;
struct vcprop_tag end;
} vb_setpower =
{
.vb_hdr = {
.vpb_len = sizeof(vb_setpower),
.vpb_rcode = VCPROP_PROCESS_REQUEST,
},
.vbt_power = {
.tag = {
.vpt_tag = tag,
.vpt_len = VCPROPTAG_LEN(vb_setpower.vbt_power),
.vpt_rcode = VCPROPTAG_REQUEST,
},
.id = domain,
.state = state
},
.end = {
.vpt_tag = VCPROPTAG_NULL,
},
};
if (!vcprop_buffer_success_p(&vb_setpower.vb_hdr) ||
!vcprop_tag_success_p(&vb_setpower.vbt_power.tag)) {
return EIO;
}
return 0;
}
int
rpi_get_domain(uint32_t domain, uint32_t *statep)
{
int error;
uint32_t tag, res;
tag = VCPROPTAG_GET_DOMAIN_STATE;
if (domain == VCPROP_DOMAIN_USB) {
/* use old interface */
tag = VCPROPTAG_GET_POWERSTATE;
domain = VCPROP_POWER_USB;
}
/*
* might as well put it here since we need to re-init it every time
* and it's not like this is going to be called very often anyway
*/
struct __aligned(16) {
struct vcprop_buffer_hdr vb_hdr;
struct vcprop_tag_powerstate vbt_power;
struct vcprop_tag end;
} vb_setpower =
{
.vb_hdr = {
.vpb_len = sizeof(vb_setpower),
.vpb_rcode = VCPROP_PROCESS_REQUEST,
},
.vbt_power = {
.tag = {
.vpt_tag = tag,
.vpt_len = VCPROPTAG_LEN(vb_setpower.vbt_power),
.vpt_rcode = VCPROPTAG_REQUEST,
},
.id = domain,
.state = ~0
},
.end = {
.vpt_tag = VCPROPTAG_NULL,
},
};