#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: auxiotwo.c,v 1.11 2012/07/29 00:04:05 matt Exp $");
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <machine/autoconf.h>
#include <sparc/include/tctrl.h>
#include <sparc/sparc/auxiotwo.h>
#include <sparc/sparc/vaddrs.h>
volatile u_char *auxiotwo_reg;
u_char auxiotwo_regval;
static int serial_refcount;
static int serial_power;
static int auxiotwomatch(device_t, cfdata_t, void *);
static void auxiotwoattach(device_t, device_t, void *);
CFATTACH_DECL_NEW(auxiotwo_obio, 0,
auxiotwomatch, auxiotwoattach, NULL, NULL);
static int
auxiotwomatch(device_t parent, cfdata_t cf, void *aux)
{
union obio_attach_args *uoba = aux;
if (uoba->uoba_isobio4 != 0)
return (0);
return (strcmp("auxio2", uoba->uoba_sbus.sa_name) == 0);
}
static void
auxiotwoattach(device_t parent, device_t self, void *aux)
{
union obio_attach_args *uoba = aux;
struct sbus_attach_args *sa = &uoba->uoba_sbus;
bus_space_handle_t bh;
if (sbus_bus_map(sa->sa_bustag,
sa->sa_slot, sa->sa_offset,
sizeof(long),
BUS_SPACE_MAP_LINEAR, &bh) != 0) {
printf("auxiotwoattach: can't map register\n");
return;
}
auxiotwo_reg = (volatile u_char *)bh;
auxiotwo_regval = *auxiotwo_reg;
serial_refcount = 0;
serial_power = PORT_PWR_STANDBY;
printf("\n");
}
unsigned int
auxiotwobisc(int bis, int bic)
{
register int s;
if (auxiotwo_reg == 0)
panic("no aux2 register");
s = splhigh();
auxiotwo_regval = (auxiotwo_regval | bis) & ~bic;
*auxiotwo_reg = auxiotwo_regval;
splx(s);
return (auxiotwo_regval);
}
void
auxiotwoserialendis(int state)
{
switch (state) {
case ZS_ENABLE:
serial_refcount++;
if (serial_refcount == 1 && serial_power == PORT_PWR_STANDBY)
auxiotwobisc(AUXIOTWO_SON, 0);
break;
case ZS_DISABLE:
serial_refcount--;
if (!serial_refcount && serial_power == PORT_PWR_STANDBY)
auxiotwobisc(AUXIOTWO_SOF, 1);
break;
}
}
void
auxiotwoserialsetapm(int state)
{
switch (state) {
case PORT_PWR_ON:
if (serial_power == PORT_PWR_OFF ||
(serial_power == PORT_PWR_STANDBY && !serial_refcount))
auxiotwobisc(AUXIOTWO_SON, 0);
serial_power = PORT_PWR_ON;
break;
case PORT_PWR_STANDBY:
if (serial_power == PORT_PWR_ON && !serial_refcount)
auxiotwobisc(AUXIOTWO_SOF, 1);
if (serial_power == PORT_PWR_OFF && serial_refcount)
auxiotwobisc(AUXIOTWO_SON, 0);
serial_power = PORT_PWR_STANDBY;
break;
case PORT_PWR_OFF:
if (serial_power == PORT_PWR_ON ||
(serial_power == PORT_PWR_STANDBY && serial_refcount))
auxiotwobisc(AUXIOTWO_SOF, 1);
serial_power = PORT_PWR_OFF;
break;
}
}
int
auxiotwoserialgetapm (void)
{
return (serial_power);
}