Lines Matching +full:enable +full:- +full:charge +full:- +full:control
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
115 * List of battery-related sysctls we might ask for
192 -1, -1, -1, -1, -1, -1, -1, -1,
193 -1, -1, -1, -1, -1, -1, -1, -1,
194 0x01, 0x01, -1, -1, -1, -1, -1, -1,
195 0x00, 0x00, -1, -1, -1, -1, -1, 0x00,
196 -1, 0x00, 0x02, 0x01, 0x01, -1, -1, -1,
197 0x00, -1, -1, -1, -1, -1, -1, -1,
198 0x04, 0x14, -1, 0x03, -1, -1, -1, -1,
199 0x00, 0x00, 0x02, 0x02, -1, -1, -1, -1,
200 0x01, 0x01, -1, -1, -1, -1, -1, -1,
201 0x00, 0x00, -1, -1, 0x01, -1, -1, -1,
202 0x01, 0x00, 0x02, 0x02, -1, 0x01, 0x03, 0x01,
203 0x00, 0x01, 0x00, 0x00, 0x00, -1, -1, -1,
204 0x02, -1, -1, -1, -1, -1, -1, -1,
205 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, -1, -1,
206 0x01, 0x01, 0x01, -1, -1, -1, -1, -1,
207 0x00, 0x00, -1, -1, -1, 0x05, 0x04, 0x04,
208 0x04, -1, 0x00, -1, -1, -1, -1, -1,
209 0x00, -1, -1, -1, -1, -1, -1, -1,
210 0x01, 0x02, -1, -1, -1, -1, -1, -1,
211 0x00, 0x00, -1, -1, -1, -1, -1, -1,
212 0x02, 0x02, 0x02, 0x04, -1, 0x00, -1, -1,
213 0x01, 0x01, 0x03, 0x02, -1, -1, -1, -1,
214 -1, -1, -1, -1, -1, -1, -1, -1,
215 -1, -1, -1, -1, -1, -1, -1, -1,
216 -1, -1, -1, -1, -1, -1, -1, -1,
217 -1, -1, -1, -1, -1, -1, -1, -1,
218 0x00, -1, -1, -1, -1, -1, -1, -1,
219 0x01, 0x01, -1, -1, 0x00, 0x00, -1, -1,
220 -1, 0x04, 0x00, -1, -1, -1, -1, -1,
221 0x03, -1, 0x00, -1, 0x00, -1, -1, 0x00,
222 -1, -1, -1, -1, -1, -1, -1, -1,
223 -1, -1, -1, -1, -1, -1, -1, -1
229 -1, -1, -1, -1, -1, -1, -1, -1,
231 0x02, 0x02, -1, -1, -1, -1, -1, 0x00,
233 -1, -1, -1, -1, -1, -1, -1, -1,
235 0x05, 0x15, -1, 0x02, -1, -1, -1, -1,
237 0x02, 0x02, -1, -1, -1, -1, -1, -1,
239 0x02, 0x00, 0x03, 0x03, -1, -1, -1, -1,
241 0x04, 0x04, 0x03, 0x09, -1, -1, -1, -1,
243 -1, -1, -1, -1, -1, 0x01, 0x01, 0x01,
245 0x06, -1, -1, -1, -1, -1, -1, -1,
247 0x02, 0x02, -1, -1, -1, -1, -1, -1,
249 0x02, 0x00, 0x00, 0x00, -1, -1, -1, -1,
251 -1, -1, -1, -1, -1, -1, -1, -1,
253 -1, -1, -1, -1, -1, -1, -1, -1,
255 0x02, 0x02, -1, -1, 0x02, -1, -1, -1,
257 -1, -1, 0x02, -1, -1, -1, -1, 0x00,
259 -1, -1, -1, -1, -1, -1, -1, -1,
279 if (strcmp(type, "extint-gpio1") != 0)
291 if (strcmp(type, "via-pmu") != 0)
304 sc->sc_irqrid = 0;
305 sc->sc_irq = bus_alloc_resource_any(extint, SYS_RES_IRQ, &sc->sc_irqrid,
307 if (sc->sc_irq == NULL) {
312 if (bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_MISC | INTR_MPSAFE
313 | INTR_ENTROPY, NULL, pmu_intr, dev, &sc->sc_ih) != 0) {
315 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irqrid,
316 sc->sc_irq);
347 sc->sc_dev = dev;
349 sc->sc_memrid = 0;
350 sc->sc_memr = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
351 &sc->sc_memrid, RF_ACTIVE);
353 mtx_init(&sc->sc_mutex,"pmu",NULL,MTX_DEF | MTX_RECURSE);
355 if (sc->sc_memr == NULL) {
371 sc->sc_autopoll = 0;
372 sc->sc_batteries = 0;
373 sc->adb_bus = NULL;
374 sc->sc_leddev = NULL;
402 sc->adb_bus = device_add_child(dev,"adb",DEVICE_UNIT_ANY);
405 if (strncmp(name, "power-mgt", 9) == 0) {
408 if (OF_getprop(child, "prim-info", prim_info,
410 sc->sc_batteries = (prim_info[6] >> 16) & 0xff;
412 if (bootverbose && sc->sc_batteries > 0)
414 sc->sc_batteries);
427 pmu_server_mode, "I", "Enable reboot after power failure");
429 if (sc->sc_batteries > 0) {
448 for (i = 0; i < sc->sc_batteries; i++) {
467 "charge",
470 "I", "Battery charge (mAh)");
506 sc->sc_leddev = led_create(pmu_set_sleepled, sc, "sleepled");
515 * Register power control handler
536 if (sc->sc_leddev != NULL)
537 led_destroy(sc->sc_leddev);
539 bus_teardown_intr(dev, sc->sc_irq, sc->sc_ih);
540 bus_release_resource(dev, SYS_RES_IRQ, sc->sc_irqrid, sc->sc_irq);
541 bus_release_resource(dev, SYS_RES_MEMORY, sc->sc_memrid, sc->sc_memr);
542 mtx_destroy(&sc->sc_mutex);
550 return (bus_read_1(sc->sc_memr, offset));
556 bus_write_1(sc->sc_memr, offset, value);
600 int i, rcv_len = -1;
708 mtx_lock(&sc->sc_mutex);
713 mtx_unlock(&sc->sc_mutex);
723 * re-enable autopoll here whenever we receive an ACK for a
726 mtx_lock(&sc->sc_mutex);
729 if (sc->sc_autopoll) {
731 (sc->sc_autopoll >> 8) & 0xff,
732 sc->sc_autopoll & 0xff};
738 mtx_unlock(&sc->sc_mutex);
740 adb_receive_raw_packet(sc->adb_bus,resp[1],resp[2],
741 len - 3,&resp[3]);
745 if ((resp[2] & PMU_ENV_LID_CLOSED) && (!sc->lid_closed)) {
746 sc->lid_closed = 1;
749 else if (!(resp[2] & PMU_ENV_LID_CLOSED) && (sc->lid_closed)) {
751 sc->lid_closed = 0;
776 mtx_lock(&sc->sc_mutex);
778 mtx_unlock(&sc->sc_mutex);
791 /* magical incantation to re-enable autopolling */
795 mtx_lock(&sc->sc_mutex);
797 if (sc->sc_autopoll == mask) {
798 mtx_unlock(&sc->sc_mutex);
802 sc->sc_autopoll = mask & 0xffff;
809 mtx_unlock(&sc->sc_mutex);
838 mtx_lock(&sc->sc_mutex);
840 mtx_unlock(&sc->sc_mutex);
854 mtx_lock(&sc->sc_mutex);
856 mtx_unlock(&sc->sc_mutex);
866 if (error || !req->newptr)
878 mtx_lock(&sc->sc_mutex);
880 mtx_unlock(&sc->sc_mutex);
894 mtx_lock(&sc->sc_mutex);
896 mtx_unlock(&sc->sc_mutex);
899 return (-1);
906 info->state = resp[2];
913 * Byte 3 Charge
914 * Byte 4 Max Charge
919 info->charge = resp[3];
920 info->maxcharge = resp[4];
922 info->current = (int8_t)resp[5];
923 info->voltage = resp[6];
928 * Byte 3-4 Charge
929 * Byte 5-6 Max Charge
930 * Byte 7-8 Current
931 * Byte 9-10 Voltage
934 info->charge = (resp[3] << 8) | resp[4];
935 info->maxcharge = (resp[5] << 8) | resp[6];
937 info->current = (int16_t)((resp[7] << 8) | resp[8]);
938 info->voltage = (resp[9] << 8) | resp[10];
941 device_printf(sc->sc_dev, "Unknown battery info format (%d)!\n",
943 return (-1);
955 new_acline = (batt->state & PMU_PWR_AC_PRESENT) ? 1 : 0;
956 old_acline = (old->state & PMU_PWR_AC_PRESENT) ? 1 : 0;
996 if (error || !req->newptr)
1051 result = batt.charge;
1063 /* Time remaining until full charge/discharge, in minutes */
1066 result = (batt.maxcharge - batt.charge) /* mAh */ * 60
1069 result = (batt.charge /* mAh */ * 60)
1070 / (-batt.current /* mA */);
1073 /* Battery charge fraction, in percent */
1074 result = (batt.charge * 100) / batt.maxcharge;
1078 result = -1;
1095 mtx_lock(&sc->sc_mutex);
1097 mtx_unlock(&sc->sc_mutex);
1100 ts->tv_sec = sec - DIFF19041970;
1101 ts->tv_nsec = 0;
1112 sec = ts->tv_sec + DIFF19041970;
1114 mtx_lock(&sc->sc_mutex);
1116 mtx_unlock(&sc->sc_mutex);