/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by NONAKA Kimihiro.
*
* 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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.
*/
/*
* Turn the LCD background light and contrast signal on or off.
*/
void
ioexp_set_backlight(int onoff, int cont)
{
struct ioexp_softc *sc = device_lookup_private(&ioexp_cd, 0);
if (sc == NULL || !sc->sc_inited) {
#ifdef DEBUG
aprint_error("ioexp: %s: not attached or not inited\n",
__func__);
#endif
if (onoff)
output_init_value |= IOEXP_BACKLIGHT_ON;
else
output_init_value &= ~IOEXP_BACKLIGHT_ON;
/* BACKLIGHT_CONT is inverted */
if (cont)
output_init_value &= ~IOEXP_BACKLIGHT_CONT;
else
output_init_value |= IOEXP_BACKLIGHT_CONT;
return;
}
/* BACKLIGHT_CONT is inverted */
if (cont && contreg) {
ioexp_gpio_pin_write(sc, IOEXP_BACKLIGHT_CONT,
GPIO_PIN_LOW, true);
} else if (!cont && !contreg) {
ioexp_gpio_pin_write(sc, IOEXP_BACKLIGHT_CONT,
GPIO_PIN_HIGH, true);
}
}
}
/*
* Turn the infrared LED on or off (must be on while transmitting).
*/
void
ioexp_set_irled(int onoff)
{
struct ioexp_softc *sc = device_lookup_private(&ioexp_cd, 0);
if (sc == NULL || !sc->sc_inited) {
#ifdef DEBUG
aprint_error("ioexp: %s: not attached or not inited\n",
__func__);
#endif
/* IR_ON is inverted */
if (onoff)
output_init_value &= ~IOEXP_IR_ON;
else
output_init_value |= IOEXP_IR_ON;
return;
}
if (sc != NULL) {
/* IR_ON is inverted */
uint8_t reg = ioexp_gpio_pin_get(sc, IOEXP_IR_ON);
if (onoff && reg) {
ioexp_gpio_pin_write(sc, IOEXP_IR_ON, GPIO_PIN_LOW,
true);
} else if (!onoff && !reg) {
ioexp_gpio_pin_write(sc, IOEXP_IR_ON, GPIO_PIN_HIGH,
true);
}
}
}
/*
* Enable or disable the mic bias
*/
void
ioexp_set_mic_bias(int onoff)
{
struct ioexp_softc *sc = device_lookup_private(&ioexp_cd, 0);
if (sc == NULL || !sc->sc_inited) {
#ifdef DEBUG
aprint_error("ioexp: %s: not attached or not inited\n",
__func__);
#endif
if (onoff)
output_init_value |= IOEXP_MIC_BIAS;
else
output_init_value &= ~IOEXP_MIC_BIAS;
return;
}