Lines Matching +full:uv +full:- +full:shutdown
1 /*-
28 * X-Powers AXP803/813/818 PMU for Allwinner SoCs
193 #define AXP_BAP_CAP_WARN_LV1BASE 5 /* 5-20%, 1% per step */
215 { "x-powers,axp803", AXP803 },
216 { "x-powers,axp813", AXP813 },
217 { "x-powers,axp818", AXP813 },
223 { -1, 0 }
527 .name = "ldo-io0",
540 .name = "ldo-io1",
654 int batsense_step; /* uV */
701 /* Warning, shutdown thresholds */
706 #define AXP_LOCK(sc) mtx_lock(&(sc)->mtx)
707 #define AXP_UNLOCK(sc) mtx_unlock(&(sc)->mtx)
719 msg[0].slave = sc->addr; in axp8xx_read()
724 msg[1].slave = sc->addr; in axp8xx_read()
740 msg[0].slave = sc->addr; in axp8xx_write()
745 msg[1].slave = sc->addr; in axp8xx_write()
760 if (param->min_uvolt == 0) in axp8xx_regnode_init()
768 rv = axp8xx_regnode_set_voltage(regnode, param->min_uvolt, in axp8xx_regnode_init()
769 param->max_uvolt, &udelay); in axp8xx_regnode_init()
785 device_printf(sc->base_dev, "%sable %s (%s)\n", in axp8xx_regnode_enable()
788 sc->def->name); in axp8xx_regnode_enable()
790 axp8xx_read(sc->base_dev, sc->def->enable_reg, &val, 1); in axp8xx_regnode_enable()
791 val &= ~sc->def->enable_mask; in axp8xx_regnode_enable()
793 val |= sc->def->enable_value; in axp8xx_regnode_enable()
795 if (sc->def->disable_value) in axp8xx_regnode_enable()
796 val |= sc->def->disable_value; in axp8xx_regnode_enable()
798 val &= ~sc->def->enable_value; in axp8xx_regnode_enable()
800 axp8xx_write(sc->base_dev, sc->def->enable_reg, val); in axp8xx_regnode_enable()
808 axp8xx_regnode_reg_to_voltage(struct axp8xx_reg_sc *sc, uint8_t val, int *uv) in axp8xx_regnode_reg_to_voltage() argument
810 if (val < sc->def->voltage_nstep1) in axp8xx_regnode_reg_to_voltage()
811 *uv = sc->def->voltage_min + val * sc->def->voltage_step1; in axp8xx_regnode_reg_to_voltage()
813 *uv = sc->def->voltage_min + in axp8xx_regnode_reg_to_voltage()
814 (sc->def->voltage_nstep1 * sc->def->voltage_step1) + in axp8xx_regnode_reg_to_voltage()
815 ((val - sc->def->voltage_nstep1) * sc->def->voltage_step2); in axp8xx_regnode_reg_to_voltage()
816 *uv *= 1000; in axp8xx_regnode_reg_to_voltage()
827 uvolt = sc->def->voltage_min * 1000; in axp8xx_regnode_voltage_to_reg()
829 for (nstep = 0; nstep < sc->def->voltage_nstep1 && uvolt < min_uvolt; in axp8xx_regnode_voltage_to_reg()
832 uvolt += (sc->def->voltage_step1 * 1000); in axp8xx_regnode_voltage_to_reg()
834 for (nstep = 0; nstep < sc->def->voltage_nstep2 && uvolt < min_uvolt; in axp8xx_regnode_voltage_to_reg()
837 uvolt += (sc->def->voltage_step2 * 1000); in axp8xx_regnode_voltage_to_reg()
855 axp8xx_read(sc->base_dev, sc->def->enable_reg, &val, 1); in axp8xx_regnode_status()
856 if (val & sc->def->enable_mask) in axp8xx_regnode_status()
872 device_printf(sc->base_dev, "Setting %s (%s) to %d<->%d\n", in axp8xx_regnode_set_voltage()
874 sc->def->name, in axp8xx_regnode_set_voltage()
877 if (sc->def->voltage_step1 == 0) in axp8xx_regnode_set_voltage()
883 axp8xx_write(sc->base_dev, sc->def->voltage_reg, val); in axp8xx_regnode_set_voltage()
898 if (!sc->def->voltage_step1 || !sc->def->voltage_step2) in axp8xx_regnode_get_voltage()
901 axp8xx_read(sc->base_dev, sc->def->voltage_reg, &val, 1); in axp8xx_regnode_get_voltage()
931 device_printf(dev, "Shutdown Axp8xx\n"); in axp8xx_shutdown()
951 if (error || !req->newptr) /* error || read request */ in axp8xx_sysctl_chargecurrent()
975 c = sc->config; in axp8xx_sysctl()
977 for (found = 0, i = 0; i < sc->nsensors; i++) { in axp8xx_sysctl()
978 if (sc->sensors[i].id == sensor) { in axp8xx_sysctl()
1010 if (batt_val <= sc->shut_thres) in axp8xx_sysctl()
1012 else if (batt_val <= sc->warn_thres) in axp8xx_sysctl()
1027 val *= c->batsense_step; in axp8xx_sysctl()
1036 val *= c->charge_step; in axp8xx_sysctl()
1045 val *= c->discharge_step; in axp8xx_sysctl()
1052 val *= c->maxcap_step; in axp8xx_sysctl()
1059 val *= c->coulomb_step; in axp8xx_sysctl()
1131 devctl_notify("PMU", "Battery", "shutdown-threshold", NULL); in axp8xx_intr()
1133 devctl_notify("PMU", "Battery", "warning-threshold", NULL); in axp8xx_intr()
1169 return (sc->gpiodev); in axp8xx_gpio_get_bus()
1175 *maxpin = nitems(axp8xx_pins) - 1; in axp8xx_gpio_pin_max()
1398 initdef.std_param.min_uvolt = def->voltage_min * 1000; in axp8xx_reg_attach()
1400 initdef.std_param.max_uvolt = def->voltage_max * 1000; in axp8xx_reg_attach()
1401 initdef.id = def->id; in axp8xx_reg_attach()
1410 reg_sc->regnode = regnode; in axp8xx_reg_attach()
1411 reg_sc->base_dev = dev; in axp8xx_reg_attach()
1412 reg_sc->def = def; in axp8xx_reg_attach()
1413 reg_sc->xref = OF_xref_from_node(node); in axp8xx_reg_attach()
1414 reg_sc->param = regnode_get_stdparam(regnode); in axp8xx_reg_attach()
1429 for (i = 0; i < sc->nregs; i++) { in axp8xx_regdev_map()
1430 if (sc->regs[i] == NULL) in axp8xx_regdev_map()
1432 if (sc->regs[i]->xref == xref) { in axp8xx_regdev_map()
1433 *num = sc->regs[i]->def->id; in axp8xx_regdev_map()
1447 switch (ofw_bus_search_compatible(dev, compat_data)->ocd_data) in axp8xx_probe()
1450 device_set_desc(dev, "X-Powers AXP803 Power Management Unit"); in axp8xx_probe()
1453 device_set_desc(dev, "X-Powers AXP813 Power Management Unit"); in axp8xx_probe()
1473 sc->addr = iicbus_get_addr(dev); in axp8xx_attach()
1474 mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF); in axp8xx_attach()
1476 error = bus_alloc_resources(dev, axp8xx_spec, &sc->res); in axp8xx_attach()
1487 sc->nregs = nitems(axp8xx_common_regdefs); in axp8xx_attach()
1488 sc->type = ofw_bus_search_compatible(dev, compat_data)->ocd_data; in axp8xx_attach()
1489 switch (sc->type) { in axp8xx_attach()
1491 sc->nregs += nitems(axp803_regdefs); in axp8xx_attach()
1494 sc->nregs += nitems(axp813_regdefs); in axp8xx_attach()
1497 sc->config = &axp803_config; in axp8xx_attach()
1498 sc->sensors = axp8xx_common_sensors; in axp8xx_attach()
1499 sc->nsensors = nitems(axp8xx_common_sensors); in axp8xx_attach()
1501 sc->regs = malloc(sizeof(struct axp8xx_reg_sc *) * sc->nregs, in axp8xx_attach()
1507 for (i = 0; i < sc->nregs; i++) { in axp8xx_attach()
1517 off = i - nitems(axp8xx_common_regdefs); in axp8xx_attach()
1518 switch (sc->type) { in axp8xx_attach()
1541 sc->regs[i] = reg; in axp8xx_attach()
1546 for (i = 0; i < sc->nsensors; i++) { in axp8xx_attach()
1549 OID_AUTO, sc->sensors[i].name, in axp8xx_attach()
1551 dev, sc->sensors[i].id, axp8xx_sysctl, in axp8xx_attach()
1552 sc->sensors[i].format, in axp8xx_attach()
1553 sc->sensors[i].desc); in axp8xx_attach()
1568 sc->warn_thres = (val & AXP_BAT_CAP_WARN_LV1) >> 4; in axp8xx_attach()
1569 sc->warn_thres += AXP_BAP_CAP_WARN_LV1BASE; in axp8xx_attach()
1570 sc->shut_thres = (val & AXP_BAT_CAP_WARN_LV2); in axp8xx_attach()
1575 "Warning threshold: 0x%02x\n", sc->warn_thres); in axp8xx_attach()
1577 "Shutdown threshold: 0x%02x\n", sc->shut_thres); in axp8xx_attach()
1602 error = bus_setup_intr(dev, sc->res, INTR_TYPE_MISC | INTR_MPSAFE, in axp8xx_attach()
1603 NULL, axp8xx_intr, dev, &sc->ih); in axp8xx_attach()
1612 sc->gpiodev = gpiobus_attach_bus(dev); in axp8xx_attach()