void ykbec_attach(device_t parent, device_t self, void *aux) { struct isa_attach_args *ia = aux; struct ykbec_softc *sc = device_private(self); int i; sc->sc_iot = ia->ia_iot; if (bus_space_map(sc->sc_iot, ia->ia_iobase, ia->ia_iosize, 0, &sc->sc_ioh)) { aprint_error(": couldn't map I/O space"); return; } /* Initialize sensor data. */ strlcpy(sc->sc_sensordev.xname, device_xname(self), sizeof(sc->sc_sensordev.xname)); if (sensor_task_register(sc, ykbec_refresh, 5) == NULL) { aprint_error(", unable to register update task\n"); return; } #ifdef DEBUG ykbec_print_bat_info(sc); #endif aprint_normal("\n"); for (i = 0; i < YKBEC_NSENSORS; i++) { sc->sc_sensor[i].type = ykbec_table[i].type; if (ykbec_table[i].desc) strlcpy(sc->sc_sensor[i].desc, ykbec_table[i].desc, sizeof(sc->sc_sensor[i].desc)); sensor_attach(&sc->sc_sensordev, &sc->sc_sensor[i]); } sensordev_install(&sc->sc_sensordev); #if NAPM > 0 /* make sure we have the apm state initialized before apm attaches */ ykbec_refresh(sc); apm_setinfohook(ykbec_apminfo); #endif #if NPCKBD > 0 || NHIDKBD > 0 timeout_set(&sc->sc_bell_tmo, ykbec_bell_stop, sc); #if NPCKBD > 0 pckbd_hookup_bell(ykbec_bell, sc); #endif #if NHIDKBD > 0 hidkbd_hookup_bell(ykbec_bell, sc); #endif #endif ykbec_sc = sc; }
void stsec_attach(struct device *parent, struct device *self, void *aux) { struct stsec_softc *sc = (struct stsec_softc *)self; struct i2c_attach_args *ia = (struct i2c_attach_args *)aux; int rev, sig; int rc; uint i; sc->sc_tag = ia->ia_tag; sc->sc_addr = ia->ia_addr; /* * Figure out where to get our information, and display microcode * version for geek value if available. */ sc->sc_base = 0; switch (gdium_revision) { case 0: break; default: /* read version before sc_base is set */ rc = stsec_read(sc, ST7_VERSION, &rev); if (rc != 0) { printf(": can't read microcode revision\n"); return; } printf(": revision %d.%d", (rev >> 4) & 0x0f, rev & 0x0f); sc->sc_base = ST7_VERSION + 1; break; } printf("\n"); /* * Better trust the ST7 firmware to control charge operation. */ rc = stsec_read(sc, ST7_SIGNATURE, &sig); if (rc != 0) { printf("%s: can't verify charge policy\n", self->dv_xname); /* not fatal */ } else { if (sig != STSIG_EC_CONTROL) stsec_write(sc, ST7_SIGNATURE, STSIG_EC_CONTROL); } /* * Setup sensors. We use a quite short refresh interval to react * quickly enough to button presses. * XXX but we don't do anything on lid or button presses... yet */ strlcpy(sc->sc_sensordev.xname, self->dv_xname, sizeof(sc->sc_sensordev.xname)); sc->sc_sensors_update_task = sensor_task_register(sc, stsec_sensors_update, 2); if (sc->sc_sensors_update_task == NULL) { printf("%s: can't initialize refresh task\n", self->dv_xname); return; } for (i = 0; i < nitems(sc->sc_sensors); i++) { sc->sc_sensors[i].type = stsec_sensors_template[i].type; strlcpy(sc->sc_sensors[i].desc, stsec_sensors_template[i].desc, sizeof(sc->sc_sensors[i].desc)); sensor_attach(&sc->sc_sensordev, &sc->sc_sensors[i]); } sensordev_install(&sc->sc_sensordev); #if NAPM > 0 /* make sure we have the apm state initialized before apm attaches */ stsec_sensors_update(sc); apm_setinfohook(stsec_apminfo); #endif }