Lines Matching refs:sc
76 struct acpibat_softc *sc = (struct acpibat_softc *)self; in acpibat_attach() local
80 sc->sc_acpi = (struct acpi_softc *)parent; in acpibat_attach()
81 sc->sc_devnode = aa->aaa_node; in acpibat_attach()
83 if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode, "_STA", 0, NULL, &sta)) { in acpibat_attach()
84 dnprintf(10, "%s: no _STA\n", DEVNAME(sc)); in acpibat_attach()
89 sc->sc_bat_present = 1; in acpibat_attach()
90 acpibat_getbix(sc); in acpibat_attach()
91 acpibat_getbst(sc); in acpibat_attach()
93 printf(": %s", sc->sc_devnode->name); in acpibat_attach()
94 if (sc->sc_bix.bix_model[0]) in acpibat_attach()
95 printf(" model \"%s\"", sc->sc_bix.bix_model); in acpibat_attach()
96 if (sc->sc_bix.bix_serial[0]) in acpibat_attach()
97 printf(" serial %s", sc->sc_bix.bix_serial); in acpibat_attach()
98 if (sc->sc_bix.bix_type[0]) in acpibat_attach()
99 printf(" type %s", sc->sc_bix.bix_type); in acpibat_attach()
100 if (sc->sc_bix.bix_oem[0]) in acpibat_attach()
101 printf(" oem \"%s\"", sc->sc_bix.bix_oem); in acpibat_attach()
105 sc->sc_bat_present = 0; in acpibat_attach()
106 printf(": %s not present\n", sc->sc_devnode->name); in acpibat_attach()
110 acpibat_monitor(sc); in acpibat_attach()
113 acpibat_refresh(sc); in acpibat_attach()
115 aml_register_notify(sc->sc_devnode, aa->aaa_dev, in acpibat_attach()
116 acpibat_notify, sc, ACPIDEV_POLL); in acpibat_attach()
122 struct acpibat_softc *sc = (struct acpibat_softc *)self; in acpibat_activate() local
128 if (aml_evalinteger(sc->sc_acpi, sc->sc_devnode, "_STA", 0, in acpibat_activate()
131 sc->sc_bat_present = 1; in acpibat_activate()
133 sc->sc_bat_present = 0; in acpibat_activate()
135 acpibat_getbix(sc); in acpibat_activate()
136 acpibat_getbst(sc); in acpibat_activate()
137 acpibat_refresh(sc); in acpibat_activate()
145 acpibat_monitor(struct acpibat_softc *sc) in acpibat_monitor() argument
150 strlcpy(sc->sc_sensdev.xname, DEVNAME(sc), in acpibat_monitor()
151 sizeof(sc->sc_sensdev.xname)); in acpibat_monitor()
153 type = sc->sc_bix.bix_power_unit ? SENSOR_AMPHOUR : SENSOR_WATTHOUR; in acpibat_monitor()
155 strlcpy(sc->sc_sens[0].desc, "last full capacity", in acpibat_monitor()
156 sizeof(sc->sc_sens[0].desc)); in acpibat_monitor()
157 sc->sc_sens[0].type = type; in acpibat_monitor()
158 sensor_attach(&sc->sc_sensdev, &sc->sc_sens[0]); in acpibat_monitor()
159 sc->sc_sens[0].value = sc->sc_bix.bix_last_capacity * 1000; in acpibat_monitor()
161 strlcpy(sc->sc_sens[1].desc, "warning capacity", in acpibat_monitor()
162 sizeof(sc->sc_sens[1].desc)); in acpibat_monitor()
163 sc->sc_sens[1].type = type; in acpibat_monitor()
164 sensor_attach(&sc->sc_sensdev, &sc->sc_sens[1]); in acpibat_monitor()
165 sc->sc_sens[1].value = sc->sc_bix.bix_warning * 1000; in acpibat_monitor()
167 strlcpy(sc->sc_sens[2].desc, "low capacity", in acpibat_monitor()
168 sizeof(sc->sc_sens[2].desc)); in acpibat_monitor()
169 sc->sc_sens[2].type = type; in acpibat_monitor()
170 sensor_attach(&sc->sc_sensdev, &sc->sc_sens[2]); in acpibat_monitor()
171 sc->sc_sens[2].value = sc->sc_bix.bix_low * 1000; in acpibat_monitor()
173 strlcpy(sc->sc_sens[3].desc, "voltage", sizeof(sc->sc_sens[3].desc)); in acpibat_monitor()
174 sc->sc_sens[3].type = SENSOR_VOLTS_DC; in acpibat_monitor()
175 sensor_attach(&sc->sc_sensdev, &sc->sc_sens[3]); in acpibat_monitor()
176 sc->sc_sens[3].value = sc->sc_bix.bix_voltage * 1000; in acpibat_monitor()
178 strlcpy(sc->sc_sens[4].desc, "battery unknown", in acpibat_monitor()
179 sizeof(sc->sc_sens[4].desc)); in acpibat_monitor()
180 sc->sc_sens[4].type = SENSOR_INTEGER; in acpibat_monitor()
181 sensor_attach(&sc->sc_sensdev, &sc->sc_sens[4]); in acpibat_monitor()
182 sc->sc_sens[4].value = sc->sc_bst.bst_state; in acpibat_monitor()
184 strlcpy(sc->sc_sens[5].desc, "rate", sizeof(sc->sc_sens[5].desc)); in acpibat_monitor()
185 sc->sc_sens[5].type = in acpibat_monitor()
186 sc->sc_bix.bix_power_unit ? SENSOR_AMPS : SENSOR_WATTS; in acpibat_monitor()
187 sensor_attach(&sc->sc_sensdev, &sc->sc_sens[5]); in acpibat_monitor()
188 sc->sc_sens[5].value = sc->sc_bst.bst_rate * 1000; in acpibat_monitor()
190 strlcpy(sc->sc_sens[6].desc, "remaining capacity", in acpibat_monitor()
191 sizeof(sc->sc_sens[6].desc)); in acpibat_monitor()
192 sc->sc_sens[6].type = type; in acpibat_monitor()
193 sensor_attach(&sc->sc_sensdev, &sc->sc_sens[6]); in acpibat_monitor()
194 sc->sc_sens[6].value = sc->sc_bix.bix_capacity * 1000; in acpibat_monitor()
196 strlcpy(sc->sc_sens[7].desc, "current voltage", in acpibat_monitor()
197 sizeof(sc->sc_sens[7].desc)); in acpibat_monitor()
198 sc->sc_sens[7].type = SENSOR_VOLTS_DC; in acpibat_monitor()
199 sensor_attach(&sc->sc_sensdev, &sc->sc_sens[7]); in acpibat_monitor()
200 sc->sc_sens[7].value = sc->sc_bix.bix_voltage * 1000; in acpibat_monitor()
202 strlcpy(sc->sc_sens[8].desc, "design capacity", in acpibat_monitor()
203 sizeof(sc->sc_sens[8].desc)); in acpibat_monitor()
204 sc->sc_sens[8].type = type; in acpibat_monitor()
205 sensor_attach(&sc->sc_sensdev, &sc->sc_sens[8]); in acpibat_monitor()
206 sc->sc_sens[8].value = sc->sc_bix.bix_capacity * 1000; in acpibat_monitor()
208 if (!sc->sc_use_bif) { in acpibat_monitor()
209 strlcpy(sc->sc_sens[9].desc, "discharge cycles", in acpibat_monitor()
210 sizeof(sc->sc_sens[9].desc)); in acpibat_monitor()
211 sc->sc_sens[9].type = SENSOR_INTEGER; in acpibat_monitor()
212 sensor_attach(&sc->sc_sensdev, &sc->sc_sens[9]); in acpibat_monitor()
213 sc->sc_sens[9].value = sc->sc_bix.bix_cycle_count; in acpibat_monitor()
216 sensordev_install(&sc->sc_sensdev); in acpibat_monitor()
222 struct acpibat_softc *sc = arg; in acpibat_refresh() local
225 dnprintf(30, "%s: %s: refresh\n", DEVNAME(sc), in acpibat_refresh()
226 sc->sc_devnode->name); in acpibat_refresh()
228 if (!sc->sc_bat_present) { in acpibat_refresh()
229 for (i = 0; i < nitems(sc->sc_sens); i++) { in acpibat_refresh()
230 sc->sc_sens[i].value = 0; in acpibat_refresh()
231 sc->sc_sens[i].status = SENSOR_S_UNSPEC; in acpibat_refresh()
232 sc->sc_sens[i].flags = SENSOR_FINVALID; in acpibat_refresh()
235 strlcpy(sc->sc_sens[4].desc, "battery removed", in acpibat_refresh()
236 sizeof(sc->sc_sens[4].desc)); in acpibat_refresh()
241 if (sc->sc_bix.bix_last_capacity == BIX_UNKNOWN) { in acpibat_refresh()
242 sc->sc_sens[0].value = 0; in acpibat_refresh()
243 sc->sc_sens[0].status = SENSOR_S_UNKNOWN; in acpibat_refresh()
244 sc->sc_sens[0].flags = SENSOR_FUNKNOWN; in acpibat_refresh()
246 sc->sc_sens[0].value = sc->sc_bix.bix_last_capacity * 1000; in acpibat_refresh()
247 sc->sc_sens[0].status = SENSOR_S_UNSPEC; in acpibat_refresh()
248 sc->sc_sens[0].flags = 0; in acpibat_refresh()
250 sc->sc_sens[1].value = sc->sc_bix.bix_warning * 1000; in acpibat_refresh()
251 sc->sc_sens[1].flags = 0; in acpibat_refresh()
252 sc->sc_sens[2].value = sc->sc_bix.bix_low * 1000; in acpibat_refresh()
253 sc->sc_sens[2].flags = 0; in acpibat_refresh()
254 if (sc->sc_bix.bix_voltage == BIX_UNKNOWN) { in acpibat_refresh()
255 sc->sc_sens[3].value = 0; in acpibat_refresh()
256 sc->sc_sens[3].status = SENSOR_S_UNKNOWN; in acpibat_refresh()
257 sc->sc_sens[3].flags = SENSOR_FUNKNOWN; in acpibat_refresh()
259 sc->sc_sens[3].value = sc->sc_bix.bix_voltage * 1000; in acpibat_refresh()
260 sc->sc_sens[3].status = SENSOR_S_UNSPEC; in acpibat_refresh()
261 sc->sc_sens[3].flags = 0; in acpibat_refresh()
265 sc->sc_sens[4].status = SENSOR_S_OK; in acpibat_refresh()
266 sc->sc_sens[4].flags = 0; in acpibat_refresh()
267 if (sc->sc_bix.bix_last_capacity == BIX_UNKNOWN || in acpibat_refresh()
268 sc->sc_bst.bst_capacity == BST_UNKNOWN) { in acpibat_refresh()
269 sc->sc_sens[4].status = SENSOR_S_UNKNOWN; in acpibat_refresh()
270 sc->sc_sens[4].flags = SENSOR_FUNKNOWN; in acpibat_refresh()
271 strlcpy(sc->sc_sens[4].desc, "battery unknown", in acpibat_refresh()
272 sizeof(sc->sc_sens[4].desc)); in acpibat_refresh()
273 } else if (sc->sc_bst.bst_capacity >= sc->sc_bix.bix_last_capacity) in acpibat_refresh()
274 strlcpy(sc->sc_sens[4].desc, "battery full", in acpibat_refresh()
275 sizeof(sc->sc_sens[4].desc)); in acpibat_refresh()
276 else if (sc->sc_bst.bst_state & BST_DISCHARGE) in acpibat_refresh()
277 strlcpy(sc->sc_sens[4].desc, "battery discharging", in acpibat_refresh()
278 sizeof(sc->sc_sens[4].desc)); in acpibat_refresh()
279 else if (sc->sc_bst.bst_state & BST_CHARGE) in acpibat_refresh()
280 strlcpy(sc->sc_sens[4].desc, "battery charging", in acpibat_refresh()
281 sizeof(sc->sc_sens[4].desc)); in acpibat_refresh()
283 strlcpy(sc->sc_sens[4].desc, "battery idle", in acpibat_refresh()
284 sizeof(sc->sc_sens[4].desc)); in acpibat_refresh()
285 if (sc->sc_bst.bst_state & BST_CRITICAL) in acpibat_refresh()
286 sc->sc_sens[4].status = SENSOR_S_CRIT; in acpibat_refresh()
287 sc->sc_sens[4].value = sc->sc_bst.bst_state; in acpibat_refresh()
289 if (sc->sc_bst.bst_rate == BST_UNKNOWN) { in acpibat_refresh()
290 sc->sc_sens[5].value = 0; in acpibat_refresh()
291 sc->sc_sens[5].status = SENSOR_S_UNKNOWN; in acpibat_refresh()
292 sc->sc_sens[5].flags = SENSOR_FUNKNOWN; in acpibat_refresh()
294 sc->sc_sens[5].value = sc->sc_bst.bst_rate * 1000; in acpibat_refresh()
295 sc->sc_sens[5].status = SENSOR_S_UNSPEC; in acpibat_refresh()
296 sc->sc_sens[5].flags = 0; in acpibat_refresh()
299 if (sc->sc_bst.bst_capacity == BST_UNKNOWN) { in acpibat_refresh()
300 sc->sc_sens[6].value = 0; in acpibat_refresh()
301 sc->sc_sens[6].status = SENSOR_S_UNKNOWN; in acpibat_refresh()
302 sc->sc_sens[6].flags = SENSOR_FUNKNOWN; in acpibat_refresh()
304 sc->sc_sens[6].value = sc->sc_bst.bst_capacity * 1000; in acpibat_refresh()
305 sc->sc_sens[6].flags = 0; in acpibat_refresh()
307 if (sc->sc_bst.bst_capacity < sc->sc_bix.bix_low) in acpibat_refresh()
309 sc->sc_sens[6].status = SENSOR_S_CRIT; in acpibat_refresh()
310 else if (sc->sc_bst.bst_capacity < sc->sc_bix.bix_warning) in acpibat_refresh()
311 sc->sc_sens[6].status = SENSOR_S_WARN; in acpibat_refresh()
313 sc->sc_sens[6].status = SENSOR_S_OK; in acpibat_refresh()
316 if (sc->sc_bst.bst_voltage == BST_UNKNOWN) { in acpibat_refresh()
317 sc->sc_sens[7].value = 0; in acpibat_refresh()
318 sc->sc_sens[7].status = SENSOR_S_UNKNOWN; in acpibat_refresh()
319 sc->sc_sens[7].flags = SENSOR_FUNKNOWN; in acpibat_refresh()
321 sc->sc_sens[7].value = sc->sc_bst.bst_voltage * 1000; in acpibat_refresh()
322 sc->sc_sens[7].status = SENSOR_S_UNSPEC; in acpibat_refresh()
323 sc->sc_sens[7].flags = 0; in acpibat_refresh()
326 if (sc->sc_bix.bix_capacity == BIX_UNKNOWN) { in acpibat_refresh()
327 sc->sc_sens[8].value = 0; in acpibat_refresh()
328 sc->sc_sens[8].status = SENSOR_S_UNKNOWN; in acpibat_refresh()
329 sc->sc_sens[8].flags = SENSOR_FUNKNOWN; in acpibat_refresh()
331 sc->sc_sens[8].value = sc->sc_bix.bix_capacity * 1000; in acpibat_refresh()
332 sc->sc_sens[8].status = SENSOR_S_UNSPEC; in acpibat_refresh()
333 sc->sc_sens[8].flags = 0; in acpibat_refresh()
336 if (!sc->sc_use_bif) { in acpibat_refresh()
337 if (sc->sc_bix.bix_capacity == BIX_UNKNOWN) { in acpibat_refresh()
338 sc->sc_sens[9].value = 0; in acpibat_refresh()
339 sc->sc_sens[9].status = SENSOR_S_UNKNOWN; in acpibat_refresh()
340 sc->sc_sens[9].flags = SENSOR_FUNKNOWN; in acpibat_refresh()
342 sc->sc_sens[9].value = sc->sc_bix.bix_cycle_count; in acpibat_refresh()
343 sc->sc_sens[9].status = SENSOR_S_UNSPEC; in acpibat_refresh()
344 sc->sc_sens[9].flags = 0; in acpibat_refresh()
350 acpibat_getbix(struct acpibat_softc *sc) in acpibat_getbix() argument
356 if (!sc->sc_bat_present) { in acpibat_getbix()
357 memset(&sc->sc_bix, 0, sizeof(sc->sc_bix)); in acpibat_getbix()
361 sc->sc_use_bif = 1; in acpibat_getbix()
363 if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_BIX", 0, NULL, in acpibat_getbix()
366 sc->sc_use_bif = 0; in acpibat_getbix()
369 DEVNAME(sc), res.length); in acpibat_getbix()
372 if (sc->sc_use_bif) { in acpibat_getbix()
373 if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_BIF", 0, NULL, in acpibat_getbix()
375 dnprintf(10, "%s: no _BIX or _BIF\n", DEVNAME(sc)); in acpibat_getbix()
381 DEVNAME(sc), res.length); in acpibat_getbix()
386 if (!sc->sc_use_bif) in acpibat_getbix()
387 sc->sc_bix.bix_revision = aml_val2int(res.v_package[n++]); in acpibat_getbix()
389 sc->sc_bix.bix_power_unit = aml_val2int(res.v_package[n++]); in acpibat_getbix()
390 sc->sc_bix.bix_capacity = aml_val2int(res.v_package[n++]); in acpibat_getbix()
391 sc->sc_bix.bix_last_capacity = aml_val2int(res.v_package[n++]); in acpibat_getbix()
392 sc->sc_bix.bix_technology = aml_val2int(res.v_package[n++]); in acpibat_getbix()
393 sc->sc_bix.bix_voltage = aml_val2int(res.v_package[n++]); in acpibat_getbix()
394 sc->sc_bix.bix_warning = aml_val2int(res.v_package[n++]); in acpibat_getbix()
395 sc->sc_bix.bix_low = aml_val2int(res.v_package[n++]); in acpibat_getbix()
397 if (!sc->sc_use_bif) { in acpibat_getbix()
398 sc->sc_bix.bix_cycle_count = aml_val2int(res.v_package[n++]); in acpibat_getbix()
399 sc->sc_bix.bix_accuracy = aml_val2int(res.v_package[n++]); in acpibat_getbix()
400 sc->sc_bix.bix_max_sample = aml_val2int(res.v_package[n++]); in acpibat_getbix()
401 sc->sc_bix.bix_min_sample = aml_val2int(res.v_package[n++]); in acpibat_getbix()
402 sc->sc_bix.bix_max_avg = aml_val2int(res.v_package[n++]); in acpibat_getbix()
403 sc->sc_bix.bix_min_avg = aml_val2int(res.v_package[n++]); in acpibat_getbix()
406 sc->sc_bix.bix_cap_granu1 = aml_val2int(res.v_package[n++]); in acpibat_getbix()
407 sc->sc_bix.bix_cap_granu2 = aml_val2int(res.v_package[n++]); in acpibat_getbix()
409 strlcpy(sc->sc_bix.bix_model, aml_val_to_string(res.v_package[n++]), in acpibat_getbix()
410 sizeof(sc->sc_bix.bix_model)); in acpibat_getbix()
411 strlcpy(sc->sc_bix.bix_serial, aml_val_to_string(res.v_package[n++]), in acpibat_getbix()
412 sizeof(sc->sc_bix.bix_serial)); in acpibat_getbix()
413 strlcpy(sc->sc_bix.bix_type, aml_val_to_string(res.v_package[n++]), in acpibat_getbix()
414 sizeof(sc->sc_bix.bix_type)); in acpibat_getbix()
415 strlcpy(sc->sc_bix.bix_oem, aml_val_to_string(res.v_package[n++]), in acpibat_getbix()
416 sizeof(sc->sc_bix.bix_oem)); in acpibat_getbix()
418 if (!sc->sc_use_bif) in acpibat_getbix()
419 dnprintf(60, "revision: %u ", sc->sc_bix.bix_revision); in acpibat_getbix()
423 sc->sc_bix.bix_power_unit, in acpibat_getbix()
424 sc->sc_bix.bix_capacity, in acpibat_getbix()
425 sc->sc_bix.bix_last_capacity, in acpibat_getbix()
426 sc->sc_bix.bix_technology, in acpibat_getbix()
427 sc->sc_bix.bix_voltage, in acpibat_getbix()
428 sc->sc_bix.bix_warning, in acpibat_getbix()
429 sc->sc_bix.bix_low); in acpibat_getbix()
431 if (!sc->sc_use_bif) in acpibat_getbix()
434 sc->sc_bix.bix_cycle_count, in acpibat_getbix()
435 sc->sc_bix.bix_accuracy, in acpibat_getbix()
436 sc->sc_bix.bix_max_sample, in acpibat_getbix()
437 sc->sc_bix.bix_min_sample, in acpibat_getbix()
438 sc->sc_bix.bix_max_avg, in acpibat_getbix()
439 sc->sc_bix.bix_min_avg); in acpibat_getbix()
443 sc->sc_bix.bix_cap_granu1, in acpibat_getbix()
444 sc->sc_bix.bix_cap_granu2, in acpibat_getbix()
445 sc->sc_bix.bix_model, in acpibat_getbix()
446 sc->sc_bix.bix_serial, in acpibat_getbix()
447 sc->sc_bix.bix_type, in acpibat_getbix()
448 sc->sc_bix.bix_oem); in acpibat_getbix()
457 acpibat_getbst(struct acpibat_softc *sc) in acpibat_getbst() argument
462 if (!sc->sc_bat_present) { in acpibat_getbst()
463 memset(&sc->sc_bst, 0, sizeof(sc->sc_bst)); in acpibat_getbst()
467 if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_BST", 0, NULL, &res)) { in acpibat_getbst()
468 dnprintf(10, "%s: no _BST\n", DEVNAME(sc)); in acpibat_getbst()
474 DEVNAME(sc)); in acpibat_getbst()
478 sc->sc_bst.bst_state = aml_val2int(res.v_package[0]); in acpibat_getbst()
479 sc->sc_bst.bst_rate = aml_val2int(res.v_package[1]); in acpibat_getbst()
480 sc->sc_bst.bst_capacity = aml_val2int(res.v_package[2]); in acpibat_getbst()
481 sc->sc_bst.bst_voltage = aml_val2int(res.v_package[3]); in acpibat_getbst()
484 sc->sc_bst.bst_state, in acpibat_getbst()
485 sc->sc_bst.bst_rate, in acpibat_getbst()
486 sc->sc_bst.bst_capacity, in acpibat_getbst()
487 sc->sc_bst.bst_voltage); in acpibat_getbst()
508 struct acpibat_softc *sc = arg; in acpibat_notify() local
512 sc->sc_devnode->name); in acpibat_notify()
515 if (aml_evalinteger(sc->sc_acpi, node, "_STA", 0, NULL, &sta) == 0) { in acpibat_notify()
517 sc->sc_bat_present = 1; in acpibat_notify()
519 sc->sc_bat_present = 0; in acpibat_notify()
525 acpibat_getbst(sc); in acpibat_notify()
534 acpibat_getbix(sc); in acpibat_notify()
540 acpibat_refresh(sc); in acpibat_notify()
541 acpi_record_event(sc->sc_acpi, APM_POWER_CHANGE); in acpibat_notify()