/*
* Copyright (c) 2000 SATO Kazumi. 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 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 AUTHOR 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.
*/
/*
* Change LED state
*
*/
void
vrled_change_state(struct vrled_softc *sc)
{
switch (sc->sc_next) {
case LEDOFF:
vrled_stop(sc);
break;
case LEDON:
vrled_on(sc);
break;
case LED1SB:
case LED2SB:
vrled_blink(sc);
break;
case LED8DIVF:
case LED4DIVF:
case LED2DIVF:
case LED1SF:
vrled_flash(sc);
break;
default:
vrled_stop(sc);
break;
}
}
/*
* Set LED state
*
*/
void
vrled_set_state(struct vrled_softc *sc, vrled_status state)
{
int ledstate;
ledstate = vrled_read(sc, LEDCNT_REG_W);
if (ledstate&LEDCNT_BLINK) { /* currently processing */
if (sc->sc_next == state)
sc->sc_state_cnt++;
switch (sc->sc_next) {
case LEDOFF:
case LEDON:
sc->sc_next = state;
break;
case LED8DIVF:
case LED4DIVF:
case LED2DIVF:
case LED1SF:
switch (state) {
case LEDOFF:
case LED8DIVF:
case LED4DIVF:
case LED2DIVF:
case LED1SF:
sc->sc_next = state;
break;
default:
break;
}
break;
case LED1SB:
case LED2SB:
switch (state) {
case LEDOFF:
case LEDON:
case LED1SB:
case LED2SB:
sc->sc_next = state;
break;
default:
break;
}
break;
default:
sc->sc_next = LEDOFF;
break;
}
return;
}
sc->sc_next = state;
vrled_change_state(sc);
}
/*
* LED config hook events
*
*/
int
vrled_event(void *ctx, int type, long id, void *msg)
{
struct vrled_softc *sc = (struct vrled_softc *)ctx;
int why =*(int *)msg;
if (type != CONFIG_HOOK_SET
|| id != CONFIG_HOOK_LED)
return (1);
if (msg == NULL)
return (1);
switch (why) {
case CONFIG_HOOK_LED_OFF:
vrled_set_state(sc, LEDOFF);
break;
case CONFIG_HOOK_LED_ON:
vrled_set_state(sc, LEDON);
break;
case CONFIG_HOOK_LED_FLASH:
vrled_set_state(sc, LED8DIVF);
break;
case CONFIG_HOOK_LED_FLASH2:
vrled_set_state(sc, LED4DIVF);
break;
case CONFIG_HOOK_LED_FLASH5:
vrled_set_state(sc, LED2DIVF);
break;
case CONFIG_HOOK_LED_BLINK:
vrled_set_state(sc, LED1SB);
break;
case CONFIG_HOOK_LED_BLINK2:
vrled_set_state(sc, LED2SB);
break;
default:
vrled_set_state(sc, LEDOFF);
}
return (0);
}