#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <sys/timetc.h>
#include <machine/bus.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcidevs.h>
#include <arch/i386/pci/geodescreg.h>
struct geodesc_softc {
struct device sc_dev;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
};
int geodesc_match(struct device *, void *, void *);
void geodesc_attach(struct device *, struct device *, void *);
int geodesc_activate(struct device *, int);
void sc1100_sysreset(void);
#ifndef SMALL_KERNEL
int geodesc_wdogctl_cb(void *, int);
#endif
const struct cfattach geodesc_ca = {
sizeof(struct geodesc_softc), geodesc_match, geodesc_attach,
NULL, geodesc_activate
};
struct cfdriver geodesc_cd = {
NULL, "geodesc", DV_DULL
};
u_int geodesc_get_timecount(struct timecounter *tc);
struct timecounter geodesc_timecounter = {
.tc_get_timecount = geodesc_get_timecount,
.tc_counter_mask = 0xffffffff,
.tc_frequency = 27000000,
.tc_name = "GEOTSC",
.tc_quality = 2000,
.tc_priv = NULL,
.tc_user = 0,
};
int
geodesc_match(struct device *parent, void *match, void *aux)
{
struct pci_attach_args *pa = aux;
if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_NS &&
(PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_NS_SC1100_XBUS ||
PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_NS_SCX200_XBUS))
return (1);
return (0);
}
#define WDSTSBITS "\20\x04WDRST\x03WDSMI\x02WDINT\x01WDOVF"
void
geodesc_attach(struct device *parent, struct device *self, void *aux)
{
struct geodesc_softc *sc = (void *) self;
struct pci_attach_args *pa = aux;
uint16_t cnfg, cba;
uint8_t sts, rev, iid;
pcireg_t reg;
extern void (*cpuresetfn)(void);
reg = pci_conf_read(pa->pa_pc, pa->pa_tag, SC1100_F5_SCRATCHPAD);
sc->sc_iot = pa->pa_iot;
if (reg == 0 ||
bus_space_map(sc->sc_iot, reg, 64, 0, &sc->sc_ioh)) {
printf(": unable to map registers at 0x%x\n", reg);
return;
}
cba = bus_space_read_2(sc->sc_iot, sc->sc_ioh, GCB_CBA);
if (cba != reg) {
printf(": cba mismatch: cba 0x%x != reg 0x%x\n", cba, reg);
bus_space_unmap(sc->sc_iot, sc->sc_ioh, 64);
return;
}
sts = bus_space_read_1(sc->sc_iot, sc->sc_ioh, GCB_WDSTS);
cnfg = bus_space_read_2(sc->sc_iot, sc->sc_ioh, GCB_WDCNFG);
iid = bus_space_read_1(sc->sc_iot, sc->sc_ioh, GCB_IID);
rev = bus_space_read_1(sc->sc_iot, sc->sc_ioh, GCB_REV);
printf(": iid %d revision %d wdstatus %b\n", iid, rev, sts, WDSTSBITS);
#ifndef SMALL_KERNEL
bus_space_write_2(sc->sc_iot, sc->sc_ioh, GCB_WDTO, 0);
sts |= WDOVF_CLEAR;
bus_space_write_1(sc->sc_iot, sc->sc_ioh, GCB_WDSTS, sts);
cnfg &= ~WDCNFG_MASK;
cnfg |= WDTYPE1_RESET|WDPRES_DIV_512;
bus_space_write_2(sc->sc_iot, sc->sc_ioh, GCB_WDCNFG, cnfg);
wdog_register(geodesc_wdogctl_cb, sc);
#endif
bus_space_write_4(sc->sc_iot, sc->sc_ioh, GCB_TSCNFG, TSC_ENABLE);
geodesc_timecounter.tc_priv = sc;
tc_init(&geodesc_timecounter);
cpuresetfn = sc1100_sysreset;
}
int
geodesc_activate(struct device *self, int act)
{
switch (act) {
case DVACT_POWERDOWN:
#ifndef SMALL_KERNEL
wdog_shutdown(self);
#endif
break;
}
return (0);
}
#ifndef SMALL_KERNEL
int
geodesc_wdogctl_cb(void *self, int period)
{
struct geodesc_softc *sc = self;
if (period > 0x03ff)
period = 0x03ff;
bus_space_write_2(sc->sc_iot, sc->sc_ioh, GCB_WDTO, period * 64);
return (period);
}
#endif
u_int
geodesc_get_timecount(struct timecounter *tc)
{
struct geodesc_softc *sc = tc->tc_priv;
return (bus_space_read_4(sc->sc_iot, sc->sc_ioh, GCB_TSC));
}
void
sc1100_sysreset(void)
{
outl(0xCF8, 0x80009044UL);
outb(0xCFC, 0x0F);
}