Lines Matching +full:pin +full:- +full:val
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",
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()
733 axp8xx_write(device_t dev, uint8_t reg, uint8_t val) in axp8xx_write() argument
740 msg[0].slave = sc->addr; in axp8xx_write()
745 msg[1].slave = sc->addr; in axp8xx_write()
748 msg[1].buf = &val; 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()
780 uint8_t val; in axp8xx_regnode_enable() local
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()
821 int max_uvolt, uint8_t *val) in axp8xx_regnode_voltage_to_reg() argument
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()
842 *val = nval; in axp8xx_regnode_voltage_to_reg()
850 uint8_t val; in axp8xx_regnode_status() local
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()
867 uint8_t val; in axp8xx_regnode_set_voltage() local
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()
880 if (axp8xx_regnode_voltage_to_reg(sc, min_uvolt, max_uvolt, &val) != 0) in axp8xx_regnode_set_voltage()
883 axp8xx_write(sc->base_dev, sc->def->voltage_reg, val); in axp8xx_regnode_set_voltage()
894 uint8_t val; in axp8xx_regnode_get_voltage() local
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()
902 axp8xx_regnode_reg_to_voltage(sc, val & AXP_VOLTCTL_MASK, uvolt); in axp8xx_regnode_get_voltage()
941 int val, error; in axp8xx_sysctl_chargecurrent() local
948 device_printf(dev, "Raw CHARGECTL1 val: 0x%0x\n", data); in axp8xx_sysctl_chargecurrent()
949 val = (data & AXP_CHARGERCTL1_CMASK); in axp8xx_sysctl_chargecurrent()
950 error = sysctl_handle_int(oidp, &val, 0, req); in axp8xx_sysctl_chargecurrent()
951 if (error || !req->newptr) /* error || read request */ in axp8xx_sysctl_chargecurrent()
954 if ((val < AXP_CHARGERCTL1_MIN) || (val > AXP_CHARGERCTL1_MAX)) in axp8xx_sysctl_chargecurrent()
957 val |= (data & (AXP_CHARGERCTL1_CMASK << 4)); in axp8xx_sysctl_chargecurrent()
958 axp8xx_write(dev, AXP_CHARGERCTL1, val); in axp8xx_sysctl_chargecurrent()
971 int val, i, found, batt_val; in axp8xx_sysctl() local
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()
990 val = !!(data & AXP_POWERSRC_ACIN); in axp8xx_sysctl()
994 val = !!(data & AXP_POWERSRC_VBUS); in axp8xx_sysctl()
999 val = !!(data & AXP_POWERMODE_BAT_PRESENT); in axp8xx_sysctl()
1004 val = !!(data & AXP_POWERMODE_BAT_CHARGING); in axp8xx_sysctl()
1010 if (batt_val <= sc->shut_thres) in axp8xx_sysctl()
1011 val = BATT_CAPACITY_CRITICAL; in axp8xx_sysctl()
1012 else if (batt_val <= sc->warn_thres) in axp8xx_sysctl()
1013 val = BATT_CAPACITY_WARNING; in axp8xx_sysctl()
1015 val = BATT_CAPACITY_NORMAL; in axp8xx_sysctl()
1021 val = (data & AXP_BAT_CAP_PERCENT); in axp8xx_sysctl()
1026 val = (AXP_SENSOR_BAT_H(hi) | AXP_SENSOR_BAT_L(lo)); in axp8xx_sysctl()
1027 val *= c->batsense_step; in axp8xx_sysctl()
1035 val = (AXP_SENSOR_BAT_H(hi) | AXP_SENSOR_BAT_L(lo)); in axp8xx_sysctl()
1036 val *= c->charge_step; in axp8xx_sysctl()
1044 val = (AXP_SENSOR_BAT_H(hi) | AXP_SENSOR_BAT_L(lo)); in axp8xx_sysctl()
1045 val *= c->discharge_step; in axp8xx_sysctl()
1051 val = AXP_SENSOR_COULOMB(hi, lo); in axp8xx_sysctl()
1052 val *= c->maxcap_step; in axp8xx_sysctl()
1058 val = AXP_SENSOR_COULOMB(hi, lo); in axp8xx_sysctl()
1059 val *= c->coulomb_step; in axp8xx_sysctl()
1064 return sysctl_handle_opaque(oidp, &val, sizeof(val), req); in axp8xx_sysctl()
1071 uint8_t val; in axp8xx_intr() local
1076 error = axp8xx_read(dev, AXP_IRQSTAT1, &val, 1); in axp8xx_intr()
1080 if (val) { in axp8xx_intr()
1082 device_printf(dev, "AXP_IRQSTAT1 val: %x\n", val); in axp8xx_intr()
1083 if (val & AXP_IRQSTAT1_ACIN_HI) in axp8xx_intr()
1085 if (val & AXP_IRQSTAT1_ACIN_LO) in axp8xx_intr()
1087 if (val & AXP_IRQSTAT1_VBUS_HI) in axp8xx_intr()
1089 if (val & AXP_IRQSTAT1_VBUS_LO) in axp8xx_intr()
1092 axp8xx_write(dev, AXP_IRQSTAT1, val); in axp8xx_intr()
1095 error = axp8xx_read(dev, AXP_IRQSTAT2, &val, 1); in axp8xx_intr()
1099 if (val) { in axp8xx_intr()
1101 device_printf(dev, "AXP_IRQSTAT2 val: %x\n", val); in axp8xx_intr()
1102 if (val & AXP_IRQSTAT2_BATCHGD) in axp8xx_intr()
1104 if (val & AXP_IRQSTAT2_BATCHGC) in axp8xx_intr()
1106 if (val & AXP_IRQSTAT2_BAT_NO) in axp8xx_intr()
1108 if (val & AXP_IRQSTAT2_BAT_IN) in axp8xx_intr()
1111 axp8xx_write(dev, AXP_IRQSTAT2, val); in axp8xx_intr()
1114 error = axp8xx_read(dev, AXP_IRQSTAT3, &val, 1); in axp8xx_intr()
1118 if (val) { in axp8xx_intr()
1120 axp8xx_write(dev, AXP_IRQSTAT3, val); in axp8xx_intr()
1123 error = axp8xx_read(dev, AXP_IRQSTAT4, &val, 1); in axp8xx_intr()
1127 if (val) { in axp8xx_intr()
1129 device_printf(dev, "AXP_IRQSTAT4 val: %x\n", val); in axp8xx_intr()
1130 if (val & AXP_IRQSTAT4_BATLVL_LO0) in axp8xx_intr()
1131 devctl_notify("PMU", "Battery", "shutdown-threshold", NULL); in axp8xx_intr()
1132 if (val & AXP_IRQSTAT4_BATLVL_LO1) in axp8xx_intr()
1133 devctl_notify("PMU", "Battery", "warning-threshold", NULL); in axp8xx_intr()
1135 axp8xx_write(dev, AXP_IRQSTAT4, val); in axp8xx_intr()
1138 error = axp8xx_read(dev, AXP_IRQSTAT5, &val, 1); in axp8xx_intr()
1142 if (val != 0) { in axp8xx_intr()
1143 if ((val & AXP_IRQSTAT5_POKSIRQ) != 0) { in axp8xx_intr()
1149 axp8xx_write(dev, AXP_IRQSTAT5, val); in axp8xx_intr()
1152 error = axp8xx_read(dev, AXP_IRQSTAT6, &val, 1); in axp8xx_intr()
1156 if (val) { in axp8xx_intr()
1158 axp8xx_write(dev, AXP_IRQSTAT6, val); in axp8xx_intr()
1169 return (sc->gpiodev); in axp8xx_gpio_get_bus()
1175 *maxpin = nitems(axp8xx_pins) - 1; in axp8xx_gpio_pin_max()
1181 axp8xx_gpio_pin_getname(device_t dev, uint32_t pin, char *name) in axp8xx_gpio_pin_getname() argument
1183 if (pin >= nitems(axp8xx_pins)) in axp8xx_gpio_pin_getname()
1186 snprintf(name, GPIOMAXNAME, "%s", axp8xx_pins[pin].name); in axp8xx_gpio_pin_getname()
1192 axp8xx_gpio_pin_getcaps(device_t dev, uint32_t pin, uint32_t *caps) in axp8xx_gpio_pin_getcaps() argument
1194 if (pin >= nitems(axp8xx_pins)) in axp8xx_gpio_pin_getcaps()
1203 axp8xx_gpio_pin_getflags(device_t dev, uint32_t pin, uint32_t *flags) in axp8xx_gpio_pin_getflags() argument
1209 if (pin >= nitems(axp8xx_pins)) in axp8xx_gpio_pin_getflags()
1215 error = axp8xx_read(dev, axp8xx_pins[pin].ctrl_reg, &data, 1); in axp8xx_gpio_pin_getflags()
1232 axp8xx_gpio_pin_setflags(device_t dev, uint32_t pin, uint32_t flags) in axp8xx_gpio_pin_setflags() argument
1238 if (pin >= nitems(axp8xx_pins)) in axp8xx_gpio_pin_setflags()
1244 error = axp8xx_read(dev, axp8xx_pins[pin].ctrl_reg, &data, 1); in axp8xx_gpio_pin_setflags()
1251 error = axp8xx_write(dev, axp8xx_pins[pin].ctrl_reg, data); in axp8xx_gpio_pin_setflags()
1259 axp8xx_gpio_pin_get(device_t dev, uint32_t pin, unsigned int *val) in axp8xx_gpio_pin_get() argument
1265 if (pin >= nitems(axp8xx_pins)) in axp8xx_gpio_pin_get()
1271 error = axp8xx_read(dev, axp8xx_pins[pin].ctrl_reg, &data, 1); in axp8xx_gpio_pin_get()
1276 *val = 0; in axp8xx_gpio_pin_get()
1279 *val = 1; in axp8xx_gpio_pin_get()
1284 *val = (data & (1 << pin)) ? 1 : 0; in axp8xx_gpio_pin_get()
1297 axp8xx_gpio_pin_set(device_t dev, uint32_t pin, unsigned int val) in axp8xx_gpio_pin_set() argument
1303 if (pin >= nitems(axp8xx_pins)) in axp8xx_gpio_pin_set()
1309 error = axp8xx_read(dev, axp8xx_pins[pin].ctrl_reg, &data, 1); in axp8xx_gpio_pin_set()
1316 data |= (val << AXP_GPIO_FUNC_SHIFT); in axp8xx_gpio_pin_set()
1324 error = axp8xx_write(dev, axp8xx_pins[pin].ctrl_reg, data); in axp8xx_gpio_pin_set()
1331 axp8xx_gpio_pin_toggle(device_t dev, uint32_t pin) in axp8xx_gpio_pin_toggle() argument
1337 if (pin >= nitems(axp8xx_pins)) in axp8xx_gpio_pin_toggle()
1343 error = axp8xx_read(dev, axp8xx_pins[pin].ctrl_reg, &data, 1); in axp8xx_gpio_pin_toggle()
1361 error = axp8xx_write(dev, axp8xx_pins[pin].ctrl_reg, data); in axp8xx_gpio_pin_toggle()
1369 int gcells, pcell_t *gpios, uint32_t *pin, uint32_t *flags) in axp8xx_gpio_map_gpios() argument
1374 *pin = gpios[0]; in axp8xx_gpio_map_gpios()
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()
1467 uint8_t chip_id, val; in axp8xx_attach() local
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()
1567 if (axp8xx_read(dev, AXP_BAT_CAP_WARN, &val, 1) == 0) { 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()
1573 "Raw reg val: 0x%02x\n", val); 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()