void mcclock_mace_attach(struct device *parent, struct device *self, void *aux) { struct mcclock_mace_softc *sc = (void *)self; struct mace_attach_args *maa = aux; sc->sc_st = maa->maa_st; /* XXX should be bus_space_map() */ if (bus_space_subregion(maa->maa_st, maa->maa_sh, maa->maa_offset, 0, &sc->sc_sh)) panic("mcclock_mace_attach: couldn't map"); /* * We want a fixed format: 24-hour, BCD data, so just force the * RTC to this mode; if there was junk there we'll be able to * fix things up later when we discover the time read back is * no good. */ ds1687_write(sc, DS1687_CONTROLA, DS1687_DV1 | DS1687_BANK1); ds1687_write(sc, DS1687_CONTROLB, DS1687_24HRS); /* XXXrkb: init kickstart/wakeup stuff */ if (!(ds1687_read(sc, DS1687_CONTROLD) & DS1687_VRT)) printf(": lithium cell is dead, RTC unreliable"); printf("\n"); clockattach(&sc->sc_dev, &mcclock_mace_clockfns); }
void mcclock_poweroff(void) { uint8_t a, xctl_a, xctl_b; if (mace0 == NULL) return; (void)splhigh(); a = ds1687_read(mace0, DS1687_CONTROLA); a &= ~DS1687_DV2; a |= DS1687_DV1; ds1687_write(mace0, DS1687_CONTROLA, a | DS1687_BANK1); wbflush(); xctl_b = ds1687_read(mace0, DS1687_BANK1_XCTRL4B); xctl_b |= DS1687_X4B_ABE | DS1687_X4B_KIE; ds1687_write(mace0, DS1687_BANK1_XCTRL4B, xctl_b); xctl_a = ds1687_read(mace0, DS1687_BANK1_XCTRL4A); xctl_a &= ~(DS1687_X4A_RCF | DS1687_X4A_WAF | DS1687_X4A_KF); ds1687_write(mace0, DS1687_BANK1_XCTRL4A, xctl_a); wbflush(); /* and down we go */ ds1687_write(mace0, DS1687_BANK1_XCTRL4A, xctl_a | DS1687_X4A_PAB); ds1687_write(mace0, DS1687_CONTROLA, a); wbflush(); for (;;) ; }