#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: auxreg.c,v 1.40 2012/07/29 00:04:05 matt Exp $");
#include "opt_blink.h"
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/callout.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <machine/autoconf.h>
#include <sparc/sparc/vaddrs.h>
#include <sparc/sparc/auxreg.h>
volatile u_char *auxio_reg;
u_char auxio_regval;
static int auxregmatch_mainbus(device_t, cfdata_t, void *);
static int auxregmatch_obio(device_t, cfdata_t, void *);
static void auxregattach_mainbus(device_t, device_t, void *);
static void auxregattach_obio(device_t, device_t, void *);
static void auxregattach(void);
CFATTACH_DECL_NEW(auxreg_mainbus, 0,
auxregmatch_mainbus, auxregattach_mainbus, NULL, NULL);
CFATTACH_DECL_NEW(auxreg_obio, 0,
auxregmatch_obio, auxregattach_obio, NULL, NULL);
#ifdef BLINK
static callout_t blink_ch;
static void blink(void *);
static void
blink(void *zero)
{
register int s;
s = splhigh();
LED_FLIP;
splx(s);
s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
callout_reset(&blink_ch, s, blink, NULL);
}
#endif
static int
auxregmatch_mainbus(device_t parent, cfdata_t cf, void *aux)
{
struct mainbus_attach_args *ma = aux;
return (strcmp("auxiliary-io", ma->ma_name) == 0);
}
static int
auxregmatch_obio(device_t parent, cfdata_t cf, void *aux)
{
union obio_attach_args *uoba = aux;
if (uoba->uoba_isobio4 != 0)
return (0);
return (strcmp("auxio", uoba->uoba_sbus.sa_name) == 0);
}
static void
auxregattach_mainbus(device_t parent, device_t self, void *aux)
{
struct mainbus_attach_args *ma = aux;
bus_space_handle_t bh;
if (bus_space_map2(ma->ma_bustag,
(bus_addr_t)ma->ma_paddr,
sizeof(long),
BUS_SPACE_MAP_LINEAR,
AUXREG_VA,
&bh) != 0) {
printf("auxregattach_mainbus: can't map register\n");
return;
}
auxio_reg = AUXIO4C_REG;
auxio_regval = *AUXIO4C_REG | AUXIO4C_FEJ | AUXIO4C_MB1;
auxregattach();
}
static void
auxregattach_obio(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 (bus_space_map2(sa->sa_bustag,
BUS_ADDR(sa->sa_slot, sa->sa_offset),
sizeof(long),
BUS_SPACE_MAP_LINEAR,
AUXREG_VA, &bh) != 0) {
printf("auxregattach_obio: can't map register\n");
return;
}
auxio_reg = AUXIO4M_REG;
auxio_regval = *AUXIO4M_REG | AUXIO4M_MB1;
auxregattach();
}
static void
auxregattach(void)
{
printf("\n");
#ifdef BLINK
callout_init(&blink_ch, 0);
blink((void *)0);
#else
LED_ON;
#endif
}
unsigned int
auxregbisc(int bis, int bic)
{
register int s;
if (auxio_reg == 0)
panic("no aux register");
s = splhigh();
auxio_regval = (auxio_regval | bis) & ~bic;
*auxio_reg = auxio_regval;
splx(s);
return (auxio_regval);
}