/* * wait for built-in display hsync. * should be called before writing to frame buffer. * might be called before realconfig. */ void mfp_wait_for_hsync(void) { /* wait for CRT HSYNC */ while (mfp_get_gpip() & MFP_GPIP_HSYNC) __asm("nop"); while (!(mfp_get_gpip() & MFP_GPIP_HSYNC)) __asm("nop"); }
void powsw_softintr(void *arg) { struct powsw_softc *sc = arg; int sw; int s; s = spl6(); if (sc->sc_tick++ >= POWSW_MAX_TICK) { /* tick is over, broken switch? */ printf("%s: unstable power switch?, ignored\n", device_xname(sc->sc_dev)); powsw_reset_counter(sc); mfp_bit_set_ierb(sc->sc_mask); splx(s); return; } sw = (mfp_get_gpip() & sc->sc_mask) ? 1 : 0; DEBUG_LOG_ADD('0' + sw); if (sw == sc->sc_last_sw) { sc->sc_count++; } else { sc->sc_last_sw = sw; sc->sc_count = 1; } if (sc->sc_count < POWSW_THRESHOLD) { callout_schedule(&sc->sc_callout, 1); } else { /* switch seems stable */ DEBUG_LOG_PRINT(); if (sc->sc_last_sw == sc->sc_prev) { /* switch state is not changed, it was a noise */ DPRINTF(" ignore(sw=%d,prev=%d)\n", sc->sc_last_sw, sc->sc_prev); } else { /* switch state has been changed */ sc->sc_prev = sc->sc_last_sw; powsw_set_aer(sc, 1 - sc->sc_prev); sysmon_task_queue_sched(0, powsw_pswitch_event, sc); } powsw_reset_counter(sc); mfp_bit_set_ierb(sc->sc_mask); // enable interrupt } splx(s); }
static void powsw_attach(device_t parent, device_t self, void *aux) { struct powsw_softc *sc = device_private(self); powsw_desc_t *desc; const char *xname; int unit; int sw; unit = device_unit(self); xname = device_xname(self); desc = &powsw_desc[unit]; memset(sc, 0, sizeof(*sc)); sc->sc_dev = self; sc->sc_mask = desc->mask; sc->sc_prev = -1; powsw_reset_counter(sc); sysmon_task_queue_init(); sc->sc_smpsw.smpsw_name = xname; sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_POWER; if (sysmon_pswitch_register(&sc->sc_smpsw) != 0) panic("can't register with sysmon"); callout_init(&sc->sc_callout, 0); callout_setfunc(&sc->sc_callout, powsw_softintr, sc); if (shutdownhook_establish(powsw_shutdown_check, sc) == NULL) panic("%s: can't establish shutdown hook", xname); if (intio_intr_establish(desc->vector, xname, powsw_intr, sc) < 0) panic("%s: can't establish interrupt", xname); /* Set AER and enable interrupt */ sw = (mfp_get_gpip() & sc->sc_mask); powsw_set_aer(sc, sw ? 0 : 1); mfp_bit_set_ierb(sc->sc_mask); aprint_normal(": %s\n", desc->name); }