Lines Matching +full:uv +full:- +full:shutdown
1 /*-
2 * Copyright (c) 2015-2016 Emmanuel Vadot <manu@freebsd.org>
29 * X-Power AXP209/AXP211 PMU for Allwinner SoCs
525 .value_convert = -(AXP209_TEMPMON_MIN - AXP209_0C_TO_K),
589 .value_convert = -(AXP221_TEMPMON_MIN - AXP209_0C_TO_K),
622 { "x-powers,axp209", AXP209 },
623 { "x-powers,axp221", AXP221 },
629 { -1, 0, 0 }
632 #define AXP_LOCK(sc) mtx_lock(&(sc)->mtx)
633 #define AXP_UNLOCK(sc) mtx_unlock(&(sc)->mtx)
663 axp2xx_read(sc->base_dev, sc->def->enable_reg, &val, 1); in axp2xx_regnode_enable()
665 val |= sc->def->enable_mask; in axp2xx_regnode_enable()
667 val &= ~sc->def->enable_mask; in axp2xx_regnode_enable()
668 axp2xx_write(sc->base_dev, sc->def->enable_reg, val); in axp2xx_regnode_enable()
676 axp2xx_regnode_reg_to_voltage(struct axp2xx_reg_sc *sc, uint8_t val, int *uv) in axp2xx_regnode_reg_to_voltage() argument
678 if (val < sc->def->voltage_nstep) in axp2xx_regnode_reg_to_voltage()
679 *uv = sc->def->voltage_min + val * sc->def->voltage_step; in axp2xx_regnode_reg_to_voltage()
681 *uv = sc->def->voltage_min + in axp2xx_regnode_reg_to_voltage()
682 (sc->def->voltage_nstep * sc->def->voltage_step); in axp2xx_regnode_reg_to_voltage()
683 *uv *= 1000; in axp2xx_regnode_reg_to_voltage()
694 uvolt = sc->def->voltage_min * 1000; in axp2xx_regnode_voltage_to_reg()
696 for (nstep = 0; nstep < sc->def->voltage_nstep && uvolt < min_uvolt; in axp2xx_regnode_voltage_to_reg()
699 uvolt += (sc->def->voltage_step * 1000); in axp2xx_regnode_voltage_to_reg()
717 axp2xx_read(sc->base_dev, sc->def->enable_reg, &val, 1); in axp2xx_regnode_status()
718 if (val & sc->def->enable_mask) in axp2xx_regnode_status()
733 if (!sc->def->voltage_step) in axp2xx_regnode_set_voltage()
739 axp2xx_write(sc->base_dev, sc->def->voltage_reg, val); in axp2xx_regnode_set_voltage()
754 if (!sc->def->voltage_step) in axp2xx_regnode_get_voltage()
757 axp2xx_read(sc->base_dev, sc->def->voltage_reg, &val, 1); in axp2xx_regnode_get_voltage()
758 axp2xx_regnode_reg_to_voltage(sc, val & sc->def->voltage_mask, uvolt); in axp2xx_regnode_get_voltage()
787 for (found = 0, i = 0; i < sc->nsensors; i++) { in axp2xx_sysctl()
788 if (sc->sensors[i].id == sensor) { in axp2xx_sysctl()
797 error = axp2xx_read(dev, sc->sensors[i].value_reg, data, 2); in axp2xx_sysctl()
801 val = ((data[0] & sc->sensors[i].h_value_mask) << in axp2xx_sysctl()
802 sc->sensors[i].h_value_shift); in axp2xx_sysctl()
803 val |= ((data[1] & sc->sensors[i].l_value_mask) << in axp2xx_sysctl()
804 sc->sensors[i].l_value_shift); in axp2xx_sysctl()
805 val *= sc->sensors[i].value_step; in axp2xx_sysctl()
806 val += sc->sensors[i].value_convert; in axp2xx_sysctl()
821 device_printf(dev, "Shutdown AXP2xx\n"); in axp2xx_shutdown()
834 axp2xx_read(sc->dev, AXP2XX_IRQ1_STATUS, ®, 1); in axp2xx_intr()
850 axp2xx_write(sc->dev, AXP2XX_IRQ1_STATUS, AXP2XX_IRQ_ACK); in axp2xx_intr()
853 axp2xx_read(sc->dev, AXP2XX_IRQ2_STATUS, ®, 1); in axp2xx_intr()
864 devctl_notify("PMU", "Battery", "low-temp", NULL); in axp2xx_intr()
866 devctl_notify("PMU", "Battery", "high-temp", NULL); in axp2xx_intr()
867 axp2xx_write(sc->dev, AXP2XX_IRQ2_STATUS, AXP2XX_IRQ_ACK); in axp2xx_intr()
870 axp2xx_read(sc->dev, AXP2XX_IRQ3_STATUS, ®, 1); in axp2xx_intr()
874 axp2xx_write(sc->dev, AXP2XX_IRQ3_STATUS, AXP2XX_IRQ_ACK); in axp2xx_intr()
877 axp2xx_read(sc->dev, AXP2XX_IRQ4_STATUS, ®, 1); in axp2xx_intr()
879 axp2xx_write(sc->dev, AXP2XX_IRQ4_STATUS, AXP2XX_IRQ_ACK); in axp2xx_intr()
882 axp2xx_read(sc->dev, AXP2XX_IRQ5_STATUS, ®, 1); in axp2xx_intr()
884 axp2xx_write(sc->dev, AXP2XX_IRQ5_STATUS, AXP2XX_IRQ_ACK); in axp2xx_intr()
895 return (sc->gpiodev); in axp2xx_gpio_get_bus()
905 *maxpin = sc->npins - 1; in axp2xx_gpio_pin_max()
917 if (pin >= sc->npins) in axp2xx_gpio_pin_getname()
932 if (pin >= sc->npins) in axp2xx_gpio_pin_getcaps()
949 if (pin >= sc->npins) in axp2xx_gpio_pin_getflags()
953 error = axp2xx_read(dev, sc->pins[pin].ctrl_reg, &data, 1); in axp2xx_gpio_pin_getflags()
978 if (pin >= sc->npins) in axp2xx_gpio_pin_setflags()
982 error = axp2xx_read(dev, sc->pins[pin].ctrl_reg, &data, 1); in axp2xx_gpio_pin_setflags()
989 error = axp2xx_write(dev, sc->pins[pin].ctrl_reg, data); in axp2xx_gpio_pin_setflags()
1005 if (pin >= sc->npins) in axp2xx_gpio_pin_get()
1009 error = axp2xx_read(dev, sc->pins[pin].ctrl_reg, &data, 1); in axp2xx_gpio_pin_get()
1020 error = axp2xx_read(dev, sc->pins[pin].status_reg, in axp2xx_gpio_pin_get()
1023 *val = (data & sc->pins[pin].status_mask); in axp2xx_gpio_pin_get()
1024 *val >>= sc->pins[pin].status_shift; in axp2xx_gpio_pin_get()
1046 if (pin >= sc->npins) in axp2xx_gpio_pin_set()
1050 error = axp2xx_read(dev, sc->pins[pin].ctrl_reg, &data, 1); in axp2xx_gpio_pin_set()
1070 error = axp2xx_write(dev, sc->pins[pin].ctrl_reg, data); in axp2xx_gpio_pin_set()
1085 if (pin >= sc->npins) in axp2xx_gpio_pin_toggle()
1089 error = axp2xx_read(dev, sc->pins[pin].ctrl_reg, &data, 1); in axp2xx_gpio_pin_toggle()
1112 error = axp2xx_write(dev, sc->pins[pin].ctrl_reg, data); in axp2xx_gpio_pin_toggle()
1126 if (gpios[0] >= sc->npins) in axp2xx_gpio_map_gpios()
1155 initdef.std_param.min_uvolt = def->voltage_min * 1000; in axp2xx_reg_attach()
1157 initdef.std_param.max_uvolt = def->voltage_max * 1000; in axp2xx_reg_attach()
1158 initdef.id = def->id; in axp2xx_reg_attach()
1167 reg_sc->regnode = regnode; in axp2xx_reg_attach()
1168 reg_sc->base_dev = dev; in axp2xx_reg_attach()
1169 reg_sc->def = def; in axp2xx_reg_attach()
1170 reg_sc->xref = OF_xref_from_node(node); in axp2xx_reg_attach()
1171 reg_sc->param = regnode_get_stdparam(regnode); in axp2xx_reg_attach()
1186 for (i = 0; i < sc->nregs; i++) { in axp2xx_regdev_map()
1187 if (sc->regs[i] == NULL) in axp2xx_regdev_map()
1189 if (sc->regs[i]->xref == xref) { in axp2xx_regdev_map()
1190 *num = sc->regs[i]->def->id; in axp2xx_regdev_map()
1211 sc->dev = dev; in axp2xx_start()
1221 ((data & AXP2XX_PSR_VBUS) >> (AXP2XX_PSR_VBUS_SHIFT - 1)); in axp2xx_start()
1253 for (i = 0; i < sc->nsensors; i++) { in axp2xx_start()
1254 if (axp2xx_read(dev, sc->sensors[i].enable_reg, ®, 1) == -1) { in axp2xx_start()
1256 sc->sensors[i].name); in axp2xx_start()
1259 reg |= sc->sensors[i].enable_mask; in axp2xx_start()
1260 if (axp2xx_write(dev, sc->sensors[i].enable_reg, reg) == -1) { in axp2xx_start()
1262 sc->sensors[i].name); in axp2xx_start()
1267 OID_AUTO, sc->sensors[i].name, in axp2xx_start()
1269 dev, sc->sensors[i].id, axp2xx_sysctl, in axp2xx_start()
1270 sc->sensors[i].format, in axp2xx_start()
1271 sc->sensors[i].desc); in axp2xx_start()
1274 if ((bus_setup_intr(dev, sc->res[0], INTR_TYPE_MISC | INTR_MPSAFE, in axp2xx_start()
1275 NULL, axp2xx_intr, sc, &sc->intrcookie))) in axp2xx_start()
1278 config_intrhook_disestablish(&sc->intr_hook); in axp2xx_start()
1288 switch (ofw_bus_search_compatible(dev, compat_data)->ocd_data) in axp2xx_probe()
1291 device_set_desc(dev, "X-Powers AXP209 Power Management Unit"); in axp2xx_probe()
1294 device_set_desc(dev, "X-Powers AXP221 Power Management Unit"); in axp2xx_probe()
1313 mtx_init(&sc->mtx, device_get_nameunit(dev), NULL, MTX_DEF); in axp2xx_attach()
1315 if (bus_alloc_resources(dev, axp_res_spec, sc->res) != 0) { in axp2xx_attach()
1320 sc->type = ofw_bus_search_compatible(dev, compat_data)->ocd_data; in axp2xx_attach()
1321 switch (sc->type) { in axp2xx_attach()
1323 sc->pins = axp209_pins; in axp2xx_attach()
1324 sc->npins = nitems(axp209_pins); in axp2xx_attach()
1325 sc->gpiodev = gpiobus_attach_bus(dev); in axp2xx_attach()
1327 sc->sensors = axp209_sensors; in axp2xx_attach()
1328 sc->nsensors = nitems(axp209_sensors); in axp2xx_attach()
1331 sc->nregs = nitems(axp209_regdefs); in axp2xx_attach()
1334 sc->pins = axp221_pins; in axp2xx_attach()
1335 sc->npins = nitems(axp221_pins); in axp2xx_attach()
1336 sc->gpiodev = gpiobus_attach_bus(dev); in axp2xx_attach()
1338 sc->sensors = axp221_sensors; in axp2xx_attach()
1339 sc->nsensors = nitems(axp221_sensors); in axp2xx_attach()
1342 sc->nregs = nitems(axp221_regdefs); in axp2xx_attach()
1346 sc->regs = malloc(sizeof(struct axp2xx_reg_sc *) * sc->nregs, in axp2xx_attach()
1349 sc->intr_hook.ich_func = axp2xx_start; in axp2xx_attach()
1350 sc->intr_hook.ich_arg = dev; in axp2xx_attach()
1352 if (config_intrhook_establish(&sc->intr_hook) != 0) in axp2xx_attach()
1358 for (i = 0; i < sc->nregs; i++) { in axp2xx_attach()
1370 sc->regs[i] = reg; in axp2xx_attach()