Lines Matching +full:uv +full:- +full:shutdown
1 /*-
95 * Regulator node - basic element for modelling SOC and bard power supply
156 #define REGNODE_SLOCK(_sc) sx_slock(&((_sc)->lock))
157 #define REGNODE_XLOCK(_sc) sx_xlock(&((_sc)->lock))
158 #define REGNODE_UNLOCK(_sc) sx_unlock(&((_sc)->lock))
176 entry->name, rv); in regulator_constraint()
203 if (!entry->std_param.always_on) { in regulator_shutdown()
208 entry->name); in regulator_shutdown()
214 * shutdown if the regulator is simply in regulator_shutdown()
215 * in-use. in regulator_shutdown()
239 if (regnode->std_param.min_uvolt == regnode->std_param.max_uvolt) { in regnode_uvolt_sysctl()
240 uvolt = regnode->std_param.min_uvolt; in regnode_uvolt_sysctl()
253 /* ----------------------------------------------------------------------------
288 if ((min_uvolt > regnode->std_param.max_uvolt) || in regnode_method_set_voltage()
289 (max_uvolt < regnode->std_param.min_uvolt)) in regnode_method_set_voltage()
299 *uvolt = regnode->std_param.min_uvolt + in regnode_method_get_voltage()
300 (regnode->std_param.max_uvolt - regnode->std_param.min_uvolt) / 2; in regnode_method_get_voltage()
308 if ((uvolt > regnode->std_param.max_uvolt) || in regnode_method_check_voltage()
309 (uvolt < regnode->std_param.min_uvolt)) in regnode_method_check_voltage()
314 /* ----------------------------------------------------------------------------
328 if (strcmp(entry->name, name) == 0) in regnode_find_by_name()
342 if ((entry->pdev == dev) && (entry->id == id)) in regnode_find_by_id()
359 KASSERT(def->name != NULL, ("regulator name is NULL")); in regnode_create()
360 KASSERT(def->name[0] != '\0', ("regulator name is empty")); in regnode_create()
363 if (regnode_find_by_name(def->name) != NULL) in regnode_create()
364 panic("Duplicated regulator registration: %s\n", def->name); in regnode_create()
371 sx_init(®node->lock, "Regulator node lock"); in regnode_create()
374 if (regnode_class->size > 0) { in regnode_create()
375 regnode->softc = malloc(regnode_class->size, M_REGULATOR, in regnode_create()
381 if (def->flags & REGULATOR_FLAGS_STATIC) { in regnode_create()
382 regnode->name = def->name; in regnode_create()
383 regnode->parent_name = def->parent_name; in regnode_create()
385 regnode->name = strdup(def->name, M_REGULATOR); in regnode_create()
386 if (def->parent_name != NULL) in regnode_create()
387 regnode->parent_name = strdup(def->parent_name, in regnode_create()
392 TAILQ_INIT(®node->consumers_list); in regnode_create()
393 regnode->id = def->id; in regnode_create()
394 regnode->pdev = pdev; in regnode_create()
395 regnode->flags = def->flags; in regnode_create()
396 regnode->parent = NULL; in regnode_create()
397 regnode->std_param = def->std_param; in regnode_create()
399 regnode->ofw_node = def->ofw_node; in regnode_create()
402 sysctl_ctx_init(®node->sysctl_ctx); in regnode_create()
403 regnode_oid = SYSCTL_ADD_NODE(®node->sysctl_ctx, in regnode_create()
405 OID_AUTO, regnode->name, in regnode_create()
408 SYSCTL_ADD_INT(®node->sysctl_ctx, in regnode_create()
411 CTLFLAG_RD, ®node->std_param.min_uvolt, 0, in regnode_create()
412 "Minimal voltage (in uV)"); in regnode_create()
413 SYSCTL_ADD_INT(®node->sysctl_ctx, in regnode_create()
416 CTLFLAG_RD, ®node->std_param.max_uvolt, 0, in regnode_create()
417 "Maximal voltage (in uV)"); in regnode_create()
418 SYSCTL_ADD_INT(®node->sysctl_ctx, in regnode_create()
421 CTLFLAG_RD, ®node->std_param.min_uamp, 0, in regnode_create()
423 SYSCTL_ADD_INT(®node->sysctl_ctx, in regnode_create()
426 CTLFLAG_RD, ®node->std_param.max_uamp, 0, in regnode_create()
428 SYSCTL_ADD_INT(®node->sysctl_ctx, in regnode_create()
431 CTLFLAG_RD, ®node->std_param.ramp_delay, 0, in regnode_create()
432 "Ramp delay (in uV/us)"); in regnode_create()
433 SYSCTL_ADD_INT(®node->sysctl_ctx, in regnode_create()
436 CTLFLAG_RD, ®node->std_param.enable_delay, 0, in regnode_create()
438 SYSCTL_ADD_INT(®node->sysctl_ctx, in regnode_create()
441 CTLFLAG_RD, ®node->enable_cnt, 0, in regnode_create()
443 SYSCTL_ADD_U8(®node->sysctl_ctx, in regnode_create()
446 CTLFLAG_RD, (uint8_t *) ®node->std_param.boot_on, 0, in regnode_create()
448 SYSCTL_ADD_U8(®node->sysctl_ctx, in regnode_create()
451 CTLFLAG_RD, (uint8_t *)®node->std_param.always_on, 0, in regnode_create()
454 SYSCTL_ADD_PROC(®node->sysctl_ctx, in regnode_create()
460 "Current voltage (in uV)"); in regnode_create()
472 if (regnode->ofw_node <= 0) in regnode_register()
473 regnode->ofw_node = ofw_bus_get_node(regnode->pdev); in regnode_register()
474 if (regnode->ofw_node <= 0) in regnode_register()
488 OF_device_register_xref(OF_xref_from_node(regnode->ofw_node), in regnode_register()
489 regnode->pdev); in regnode_register()
499 if ((regnode->parent != NULL) || in regnode_resolve_parent()
500 (regnode->parent_name == NULL)) in regnode_resolve_parent()
503 regnode->parent = regnode_find_by_name(regnode->parent_name); in regnode_resolve_parent()
504 if (regnode->parent == NULL) in regnode_resolve_parent()
524 /* --------------------------------------------------------------------------
534 return (regnode->name); in regnode_get_name()
541 return (regnode->parent_name); in regnode_get_parent_name()
548 return (regnode->flags); in regnode_get_flags()
555 return (regnode->softc); in regnode_get_softc()
562 return (regnode->pdev); in regnode_get_device()
568 return (®node->std_param); in regnode_get_stdparam()
590 /* --------------------------------------------------------------------------
606 return (regnode->parent); in regnode_get_parent()
624 if (regnode->parent != NULL) { in regnode_enable()
625 rv = regnode_enable(regnode->parent); in regnode_enable()
632 if (regnode->enable_cnt == 0) { in regnode_enable()
640 regnode->enable_cnt++; in regnode_enable()
659 if (regnode->enable_cnt == 1 && in regnode_disable()
660 (regnode->flags & REGULATOR_FLAGS_NOT_DISABLE) == 0 && in regnode_disable()
661 !regnode->std_param.always_on) { in regnode_disable()
669 regnode->enable_cnt--; in regnode_disable()
675 if (regnode->parent != NULL) in regnode_disable()
676 rv = regnode_disable(regnode->parent); in regnode_disable()
694 if ((regnode->enable_cnt != 0) && (depth == 0)) { in regnode_stop()
699 if ((regnode->enable_cnt == 0) && in regnode_stop()
700 ((regnode->flags & REGULATOR_FLAGS_NOT_DISABLE) == 0)) { in regnode_stop()
713 if (regnode->parent != NULL && regnode->parent->enable_cnt == 0) in regnode_stop()
714 rv = regnode_stop(regnode->parent, depth + 1); in regnode_stop()
753 if (regnode->parent != NULL) in regnode_get_voltage()
754 rv = regnode_get_voltage(regnode->parent, uvolt); in regnode_get_voltage()
797 if ((min_uvolt > regnode->std_param.max_uvolt) || in regnode_set_voltage_checked()
798 (max_uvolt < regnode->std_param.min_uvolt)) { in regnode_set_voltage_checked()
804 all_min_uvolt = regnode->std_param.min_uvolt; in regnode_set_voltage_checked()
805 all_max_uvolt = regnode->std_param.max_uvolt; in regnode_set_voltage_checked()
806 TAILQ_FOREACH(tmp, ®node->consumers_list, link) { in regnode_set_voltage_checked()
810 if (all_min_uvolt < tmp->min_uvolt) in regnode_set_voltage_checked()
811 all_min_uvolt = tmp->min_uvolt; in regnode_set_voltage_checked()
812 if (all_max_uvolt > tmp->max_uvolt) in regnode_set_voltage_checked()
813 all_max_uvolt = tmp->max_uvolt; in regnode_set_voltage_checked()
840 if (regnode->std_param.boot_on != true && in regnode_set_constraint()
841 regnode->std_param.always_on != true) in regnode_set_constraint()
863 if (uvolt < regnode->std_param.min_uvolt || in regnode_set_constraint()
864 uvolt > regnode->std_param.max_uvolt) { in regnode_set_constraint()
867 " acceptable range : %d<->%d\n", in regnode_set_constraint()
869 uvolt, regnode->std_param.min_uvolt, in regnode_set_constraint()
870 regnode->std_param.max_uvolt); in regnode_set_constraint()
890 return (regnode->ofw_node); in regnode_get_ofw_node()
894 /* --------------------------------------------------------------------------
909 reg->cdev = cdev; in regulator_create()
910 reg->regnode = regnode; in regulator_create()
911 reg->enable_cnt = 0; in regulator_create()
914 regnode->ref_cnt++; in regulator_create()
915 TAILQ_INSERT_TAIL(®node->consumers_list, reg, link); in regulator_create()
916 reg ->min_uvolt = regnode->std_param.min_uvolt; in regulator_create()
917 reg ->max_uvolt = regnode->std_param.max_uvolt; in regulator_create()
929 regnode = reg->regnode; in regulator_enable()
930 KASSERT(regnode->ref_cnt > 0, in regulator_enable()
931 ("Attempt to access unreferenced regulator: %s\n", regnode->name)); in regulator_enable()
935 reg->enable_cnt++; in regulator_enable()
946 regnode = reg->regnode; in regulator_disable()
947 KASSERT(regnode->ref_cnt > 0, in regulator_disable()
948 ("Attempt to access unreferenced regulator: %s\n", regnode->name)); in regulator_disable()
949 KASSERT(reg->enable_cnt > 0, in regulator_disable()
951 regnode->name)); in regulator_disable()
955 reg->enable_cnt--; in regulator_disable()
966 regnode = reg->regnode; in regulator_stop()
967 KASSERT(regnode->ref_cnt > 0, in regulator_stop()
968 ("Attempt to access unreferenced regulator: %s\n", regnode->name)); in regulator_stop()
969 KASSERT(reg->enable_cnt == 0, in regulator_stop()
970 ("Attempt to stop already enabled regulator: %s\n", regnode->name)); in regulator_stop()
984 regnode = reg->regnode; in regulator_status()
985 KASSERT(regnode->ref_cnt > 0, in regulator_status()
986 ("Attempt to access unreferenced regulator: %s\n", regnode->name)); in regulator_status()
988 if (reg->enable_cnt == 0) { in regulator_status()
1004 regnode = reg->regnode; in regulator_get_voltage()
1005 KASSERT(regnode->ref_cnt > 0, in regulator_get_voltage()
1006 ("Attempt to access unreferenced regulator: %s\n", regnode->name)); in regulator_get_voltage()
1020 regnode = reg->regnode; in regulator_set_voltage()
1021 KASSERT(regnode->ref_cnt > 0, in regulator_set_voltage()
1022 ("Attempt to access unreferenced regulator: %s\n", regnode->name)); in regulator_set_voltage()
1028 reg->min_uvolt = min_uvolt; in regulator_set_voltage()
1029 reg->max_uvolt = max_uvolt; in regulator_set_voltage()
1041 regnode = reg->regnode; in regulator_check_voltage()
1042 KASSERT(regnode->ref_cnt > 0, in regulator_check_voltage()
1043 ("Attempt to access unreferenced regulator: %s\n", regnode->name)); in regulator_check_voltage()
1056 regnode = reg->regnode; in regulator_get_name()
1057 KASSERT(regnode->ref_cnt > 0, in regulator_get_name()
1058 ("Attempt to access unreferenced regulator: %s\n", regnode->name)); in regulator_get_name()
1059 return (regnode->name); in regulator_get_name()
1101 regnode = reg->regnode; in regulator_release()
1102 KASSERT(regnode->ref_cnt > 0, in regulator_release()
1103 ("Attempt to access unreferenced regulator: %s\n", regnode->name)); in regulator_release()
1105 while (reg->enable_cnt > 0) { in regulator_release()
1107 reg->enable_cnt--; in regulator_release()
1110 TAILQ_REMOVE(®node->consumers_list, reg, link); in regulator_release()
1111 regnode->ref_cnt--; in regulator_release()
1143 par = &def->std_param; in regulator_parse_ofw_stdparam()
1144 rv = OF_getprop_alloc(node, "regulator-name", in regulator_parse_ofw_stdparam()
1145 (void **)&def->name); in regulator_parse_ofw_stdparam()
1152 rv = OF_getencprop(node, "regulator-min-microvolt", &par->min_uvolt, in regulator_parse_ofw_stdparam()
1153 sizeof(par->min_uvolt)); in regulator_parse_ofw_stdparam()
1155 par->min_uvolt = 0; in regulator_parse_ofw_stdparam()
1157 rv = OF_getencprop(node, "regulator-max-microvolt", &par->max_uvolt, in regulator_parse_ofw_stdparam()
1158 sizeof(par->max_uvolt)); in regulator_parse_ofw_stdparam()
1160 par->max_uvolt = 0; in regulator_parse_ofw_stdparam()
1162 rv = OF_getencprop(node, "regulator-min-microamp", &par->min_uamp, in regulator_parse_ofw_stdparam()
1163 sizeof(par->min_uamp)); in regulator_parse_ofw_stdparam()
1165 par->min_uamp = 0; in regulator_parse_ofw_stdparam()
1167 rv = OF_getencprop(node, "regulator-max-microamp", &par->max_uamp, in regulator_parse_ofw_stdparam()
1168 sizeof(par->max_uamp)); in regulator_parse_ofw_stdparam()
1170 par->max_uamp = 0; in regulator_parse_ofw_stdparam()
1172 rv = OF_getencprop(node, "regulator-ramp-delay", &par->ramp_delay, in regulator_parse_ofw_stdparam()
1173 sizeof(par->ramp_delay)); in regulator_parse_ofw_stdparam()
1175 par->ramp_delay = 0; in regulator_parse_ofw_stdparam()
1177 rv = OF_getencprop(node, "regulator-enable-ramp-delay", in regulator_parse_ofw_stdparam()
1178 &par->enable_delay, sizeof(par->enable_delay)); in regulator_parse_ofw_stdparam()
1180 par->enable_delay = 0; in regulator_parse_ofw_stdparam()
1182 if (OF_hasprop(node, "regulator-boot-on")) in regulator_parse_ofw_stdparam()
1183 par->boot_on = true; in regulator_parse_ofw_stdparam()
1185 if (OF_hasprop(node, "regulator-always-on")) in regulator_parse_ofw_stdparam()
1186 par->always_on = true; in regulator_parse_ofw_stdparam()
1188 if (OF_hasprop(node, "enable-active-high")) in regulator_parse_ofw_stdparam()
1189 par->enable_active_high = 1; in regulator_parse_ofw_stdparam()
1191 rv = OF_getencprop(node, "vin-supply", &supply_xref, in regulator_parse_ofw_stdparam()
1194 rv = OF_getprop_alloc(supply_xref, "regulator-name", in regulator_parse_ofw_stdparam()
1195 (void **)&def->parent_name); in regulator_parse_ofw_stdparam()
1197 def->parent_name = NULL; in regulator_parse_ofw_stdparam()
1235 rv = REGDEV_MAP(regdev, cells[0], ncells - 1, cells + 1, &id); in regulator_get_by_ofw_property()
1243 /* --------------------------------------------------------------------------
1263 if (!(sel >= range->min_sel && in regulator_range_sel8_to_volt()
1264 sel <= range->max_sel)) in regulator_range_sel8_to_volt()
1267 sel -= range->min_sel; in regulator_range_sel8_to_volt()
1269 *volt = range->min_uvolt + sel * range->step_uvolt; in regulator_range_sel8_to_volt()
1290 uvolt = range->min_uvolt + in regulator_range_volt_to_sel8()
1291 (range->max_sel - range->min_sel) * range->step_uvolt; in regulator_range_volt_to_sel8()
1294 (max_uvolt < range->min_uvolt)) in regulator_range_volt_to_sel8()
1297 if (min_uvolt <= range->min_uvolt) in regulator_range_volt_to_sel8()
1298 min_uvolt = range->min_uvolt; in regulator_range_volt_to_sel8()
1300 /* if step == 0 -> fixed voltage range. */ in regulator_range_volt_to_sel8()
1301 if (range->step_uvolt == 0) in regulator_range_volt_to_sel8()
1304 sel = DIV_ROUND_UP(min_uvolt - range->min_uvolt, in regulator_range_volt_to_sel8()
1305 range->step_uvolt); in regulator_range_volt_to_sel8()
1308 sel += range->min_sel; in regulator_range_volt_to_sel8()