Lines Matching +full:overcurrent +full:- +full:retry

1 // SPDX-License-Identifier: GPL-2.0-only
30 #define MAX_OVERCURRENT_WAIT 3 /* Overcurrent wait must be <= this */
33 * struct tps65090_regulator - Per-regulator data for a tps65090 regulator
54 * tps65090_reg_set_overcurrent_wait - Setup overcurrent wait
56 * This will set the overcurrent wait time based on what's in the regulator
62 * Return: 0 if no error, non-zero if there was an error writing the register.
69 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, in tps65090_reg_set_overcurrent_wait()
71 ri->overcurrent_wait << CTRL_WT_BIT); in tps65090_reg_set_overcurrent_wait()
73 dev_err(&rdev->dev, "Error updating overcurrent wait %#x\n", in tps65090_reg_set_overcurrent_wait()
74 rdev->desc->enable_reg); in tps65090_reg_set_overcurrent_wait()
81 * tps65090_try_enable_fet - Try to enable a FET
85 * Return: 0 if ok, -ENOTRECOVERABLE if the FET power good bit did not get
86 * set, or some other -ve value if another error occurred (e.g. i2c error)
93 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, in tps65090_try_enable_fet()
94 rdev->desc->enable_mask, in tps65090_try_enable_fet()
95 rdev->desc->enable_mask); in tps65090_try_enable_fet()
97 dev_err(&rdev->dev, "Error in updating reg %#x\n", in tps65090_try_enable_fet()
98 rdev->desc->enable_reg); in tps65090_try_enable_fet()
103 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, in tps65090_try_enable_fet()
114 return -ENOTRECOVERABLE; in tps65090_try_enable_fet()
120 * tps65090_fet_enable - Enable a FET, trying a few times if it fails
125 * - We'll make sure that we bump the "overcurrent wait" to the maximum, which
127 * - We'll retry turning the FET on multiple times (turning off in between).
131 * Return: 0 if ok, non-zero if it fails.
146 if (ret != -ENOTRECOVERABLE || tries == MAX_FET_ENABLE_TRIES) in tps65090_fet_enable()
150 ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, in tps65090_fet_enable()
151 rdev->desc->enable_mask, 0); in tps65090_fet_enable()
159 dev_warn(&rdev->dev, "reg %#x enable ok after %d tries\n", in tps65090_fet_enable()
160 rdev->desc->enable_reg, tries); in tps65090_fet_enable()
164 dev_warn(&rdev->dev, "reg %#x enable failed\n", rdev->desc->enable_reg); in tps65090_fet_enable()
236 tps65090_REG_FIXEDV(LDO1, "vsys-l1", 0, 0, 5000000,
238 tps65090_REG_FIXEDV(LDO2, "vsys-l2", 0, 0, 3300000,
258 struct device *parent = ri->dev->parent; in tps65090_config_ext_control()
259 unsigned int reg_en_reg = ri->desc->enable_reg; in tps65090_config_ext_control()
266 dev_err(ri->dev, "Error in updating reg 0x%x\n", reg_en_reg); in tps65090_config_ext_control()
275 struct device *parent = ri->dev->parent; in tps65090_regulator_disable_ext_control()
276 unsigned int reg_en_reg = ri->desc->enable_reg; in tps65090_regulator_disable_ext_control()
282 if (tps_pdata->reg_init_data->constraints.always_on || in tps65090_regulator_disable_ext_control()
283 tps_pdata->reg_init_data->constraints.boot_on) { in tps65090_regulator_disable_ext_control()
286 dev_err(ri->dev, "Error in set reg 0x%x\n", reg_en_reg); in tps65090_regulator_disable_ext_control()
314 struct device_node *np = pdev->dev.parent->of_node; in tps65090_parse_dt_reg_data()
319 tps65090_pdata = devm_kzalloc(&pdev->dev, sizeof(*tps65090_pdata), in tps65090_parse_dt_reg_data()
322 return ERR_PTR(-ENOMEM); in tps65090_parse_dt_reg_data()
324 reg_pdata = devm_kcalloc(&pdev->dev, in tps65090_parse_dt_reg_data()
328 return ERR_PTR(-ENOMEM); in tps65090_parse_dt_reg_data()
332 dev_err(&pdev->dev, "regulator node not found\n"); in tps65090_parse_dt_reg_data()
333 return ERR_PTR(-ENODEV); in tps65090_parse_dt_reg_data()
336 ret = of_regulator_match(&pdev->dev, regulators, tps65090_matches, in tps65090_parse_dt_reg_data()
340 dev_err(&pdev->dev, in tps65090_parse_dt_reg_data()
360 rpdata->reg_init_data = ri_data; in tps65090_parse_dt_reg_data()
361 rpdata->enable_ext_control = of_property_read_bool(np, in tps65090_parse_dt_reg_data()
362 "ti,enable-ext-control"); in tps65090_parse_dt_reg_data()
363 if (rpdata->enable_ext_control) { in tps65090_parse_dt_reg_data()
366 if (ri_data->constraints.always_on || in tps65090_parse_dt_reg_data()
367 ri_data->constraints.boot_on) in tps65090_parse_dt_reg_data()
373 rpdata->gpiod = devm_fwnode_gpiod_get( in tps65090_parse_dt_reg_data()
374 &pdev->dev, in tps65090_parse_dt_reg_data()
376 "dcdc-ext-control", in tps65090_parse_dt_reg_data()
379 if (PTR_ERR(rpdata->gpiod) == -ENOENT) { in tps65090_parse_dt_reg_data()
380 dev_err(&pdev->dev, in tps65090_parse_dt_reg_data()
382 rpdata->gpiod = NULL; in tps65090_parse_dt_reg_data()
383 } else if (IS_ERR(rpdata->gpiod)) in tps65090_parse_dt_reg_data()
384 return ERR_CAST(rpdata->gpiod); in tps65090_parse_dt_reg_data()
387 if (of_property_read_u32(np, "ti,overcurrent-wait", in tps65090_parse_dt_reg_data()
388 &rpdata->overcurrent_wait) == 0) in tps65090_parse_dt_reg_data()
389 rpdata->overcurrent_wait_valid = true; in tps65090_parse_dt_reg_data()
391 tps65090_pdata->reg_pdata[idx] = rpdata; in tps65090_parse_dt_reg_data()
407 struct tps65090 *tps65090_mfd = dev_get_drvdata(pdev->dev.parent); in tps65090_regulator_probe()
418 dev_dbg(&pdev->dev, "Probing regulator\n"); in tps65090_regulator_probe()
420 tps65090_pdata = dev_get_platdata(pdev->dev.parent); in tps65090_regulator_probe()
421 if (!tps65090_pdata && tps65090_mfd->dev->of_node) in tps65090_regulator_probe()
425 dev_err(&pdev->dev, "Platform data missing\n"); in tps65090_regulator_probe()
426 return tps65090_pdata ? PTR_ERR(tps65090_pdata) : -EINVAL; in tps65090_regulator_probe()
429 pmic = devm_kcalloc(&pdev->dev, in tps65090_regulator_probe()
433 return -ENOMEM; in tps65090_regulator_probe()
436 tps_pdata = tps65090_pdata->reg_pdata[num]; in tps65090_regulator_probe()
439 ri->dev = &pdev->dev; in tps65090_regulator_probe()
440 ri->desc = &tps65090_regulator_desc[num]; in tps65090_regulator_probe()
442 ri->overcurrent_wait_valid = in tps65090_regulator_probe()
443 tps_pdata->overcurrent_wait_valid; in tps65090_regulator_probe()
444 ri->overcurrent_wait = tps_pdata->overcurrent_wait; in tps65090_regulator_probe()
451 if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data) { in tps65090_regulator_probe()
452 if (tps_pdata->enable_ext_control) { in tps65090_regulator_probe()
453 config.ena_gpiod = tps_pdata->gpiod; in tps65090_regulator_probe()
454 ri->desc->ops = &tps65090_ext_control_ops; in tps65090_regulator_probe()
459 dev_err(&pdev->dev, in tps65090_regulator_probe()
466 config.dev = pdev->dev.parent; in tps65090_regulator_probe()
468 config.regmap = tps65090_mfd->rmap; in tps65090_regulator_probe()
470 config.init_data = tps_pdata->reg_init_data; in tps65090_regulator_probe()
483 devm_gpiod_unhinge(&pdev->dev, config.ena_gpiod); in tps65090_regulator_probe()
484 rdev = devm_regulator_register(&pdev->dev, ri->desc, &config); in tps65090_regulator_probe()
486 dev_err(&pdev->dev, "failed to register regulator %s\n", in tps65090_regulator_probe()
487 ri->desc->name); in tps65090_regulator_probe()
490 ri->rdev = rdev; in tps65090_regulator_probe()
492 if (ri->overcurrent_wait_valid) { in tps65090_regulator_probe()
499 if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data && in tps65090_regulator_probe()
500 tps_pdata->enable_ext_control) { in tps65090_regulator_probe()
513 .name = "tps65090-pmic",
534 MODULE_ALIAS("platform:tps65090-pmic");