Lines Matching +full:dc +full:- +full:current +full:- +full:limit

1 // SPDX-License-Identifier: GPL-2.0+
27 REG_FIELD(_reg, __builtin_ffs((int)_mask) - 1, \
28 sizeof(unsigned int) * 8 - __builtin_clz((_mask)) - 1)
53 /* DA9063-only LDOs */
95 .desc.n_voltages = (((max_mV) - (min_mV))/(step_mV) + 1 \
107 /* Macros for voltage DC/DC converters (BUCKs) */
115 .desc.n_voltages = ((max_mV) - (min_mV))/(step_mV) + 1, \
171 * Current limits array (in uA) for BCORE1, BCORE2, BPRO.
180 * Current limits array (in uA) for BMEM, BIO, BPERI.
189 * Current limits array (in uA) for merged BCORE1 and BCORE2.
198 * Current limits array (in uA) for merged BMEM and BIO.
222 return -EINVAL; in da9063_buck_set_mode()
225 return regmap_field_write(regl->mode, val); in da9063_buck_set_mode()
240 ret = regmap_field_read(regl->mode, &val); in da9063_buck_get_mode()
257 ret = regmap_field_read(regl->sleep, &val); in da9063_buck_get_mode()
268 * LDOs use sleep flags - one for normal and one for suspend state.
285 return -EINVAL; in da9063_ldo_set_mode()
288 return regmap_field_write(regl->sleep, val); in da9063_ldo_set_mode()
296 ret = regmap_field_read(regl->sleep, &val); in da9063_ldo_get_mode()
317 ret = -EIO; in da9063_buck_get_status()
334 ret = -EIO; in da9063_ldo_get_status()
343 const struct da9063_regulator_info *rinfo = regl->info; in da9063_set_suspend_voltage()
350 sel <<= ffs(rdev->desc->vsel_mask) - 1; in da9063_set_suspend_voltage()
352 ret = regmap_update_bits(regl->hw->regmap, rinfo->suspend_vsel_reg, in da9063_set_suspend_voltage()
353 rdev->desc->vsel_mask, sel); in da9063_set_suspend_voltage()
362 return regmap_field_write(regl->suspend, 1); in da9063_suspend_enable()
369 return regmap_field_write(regl->suspend, 0); in da9063_suspend_disable()
389 return -EINVAL; in da9063_buck_set_suspend_mode()
392 return regmap_field_write(regl->mode, val); in da9063_buck_set_suspend_mode()
409 return -EINVAL; in da9063_ldo_set_suspend_mode()
412 return regmap_field_write(regl->suspend_sleep, val); in da9063_ldo_set_suspend_mode()
417 switch (desc->id) { in da9063_get_overdrive_mask()
435 * When enabling overdrive, do it before changing the current limit to in da9063_buck_set_limit_set_overdrive()
442 ret = regmap_read(regl->hw->regmap, DA9063_REG_CONFIG_H, in da9063_buck_set_limit_set_overdrive()
449 ret = regmap_set_bits(regl->hw->regmap, DA9063_REG_CONFIG_H, in da9063_buck_set_limit_set_overdrive()
460 * Attempt to restore original overdrive state, ignore failure- in da9063_buck_set_limit_set_overdrive()
461 * on-failure. in da9063_buck_set_limit_set_overdrive()
463 regmap_clear_bits(regl->hw->regmap, DA9063_REG_CONFIG_H, in da9063_buck_set_limit_set_overdrive()
474 * When disabling overdrive, do it after changing the current limit to in da9063_buck_set_limit_clear_overdrive()
480 ret = regmap_read(rdev->regmap, rdev->desc->csel_reg, &orig_limit); in da9063_buck_set_limit_clear_overdrive()
488 ret = regmap_clear_bits(regl->hw->regmap, DA9063_REG_CONFIG_H, in da9063_buck_set_limit_clear_overdrive()
492 * Attempt to restore original current limit, ignore failure- in da9063_buck_set_limit_clear_overdrive()
493 * on-failure. in da9063_buck_set_limit_clear_overdrive()
495 regmap_write(rdev->regmap, rdev->desc->csel_reg, orig_limit); in da9063_buck_set_limit_clear_overdrive()
505 overdrive_mask = da9063_get_overdrive_mask(rdev->desc); in da9063_buck_set_current_limit()
507 n_currents = rdev->desc->n_current_limits; in da9063_buck_set_current_limit()
509 return -EINVAL; in da9063_buck_set_current_limit()
511 if (max_uA > rdev->desc->curr_table[n_currents - 1]) in da9063_buck_set_current_limit()
526 int val, ret, limit; in da9063_buck_get_current_limit() local
529 limit = regulator_get_current_limit_regmap(rdev); in da9063_buck_get_current_limit()
530 if (limit < 0) in da9063_buck_get_current_limit()
531 return limit; in da9063_buck_get_current_limit()
532 mask = da9063_get_overdrive_mask(rdev->desc); in da9063_buck_get_current_limit()
534 ret = regmap_read(regl->hw->regmap, DA9063_REG_CONFIG_H, &val); in da9063_buck_get_current_limit()
538 limit *= 2; in da9063_buck_get_current_limit()
540 return limit; in da9063_buck_get_current_limit()
681 .n_regulators = ARRAY_SIZE(da9063_regulator_info) - 6,
691 struct da9063 *hw = regulators->regulator[0].hw; in da9063_ldo_lim_event()
695 ret = regmap_read(hw->regmap, DA9063_REG_STATUS_D, &bits); in da9063_ldo_lim_event()
699 for (i = regulators->n_regulators - 1; i >= 0; i--) { in da9063_ldo_lim_event()
700 regl = &regulators->regulator[i]; in da9063_ldo_lim_event()
701 if (regl->info->oc_event.reg != DA9063_REG_STATUS_D) in da9063_ldo_lim_event()
704 if (BIT(regl->info->oc_event.lsb) & bits) { in da9063_ldo_lim_event()
705 regulator_notifier_call_chain(regl->rdev, in da9063_ldo_lim_event()
721 for (i = 0; i < regl_pdata->n_regulators; i++) { in da9063_get_regulator_initdata()
722 if (id == regl_pdata->regulator_data[i].id) in da9063_get_regulator_initdata()
723 return regl_pdata->regulator_data[i].initdata; in da9063_get_regulator_initdata()
736 [DA9063_ID_BCORES_MERGED] = { .name = "bcores-merged" },
737 [DA9063_ID_BMEM_BIO_MERGED] = { .name = "bmem-bio-merged", },
756 struct da9063 *da9063 = dev_get_drvdata(pdev->dev.parent); in da9063_parse_regulators_dt()
763 if (da9063->type == PMIC_TYPE_DA9063L) in da9063_parse_regulators_dt()
764 da9063_matches_len -= 6; in da9063_parse_regulators_dt()
766 node = of_get_child_by_name(pdev->dev.parent->of_node, "regulators"); in da9063_parse_regulators_dt()
768 dev_err(&pdev->dev, "Regulators device node not found\n"); in da9063_parse_regulators_dt()
769 return ERR_PTR(-ENODEV); in da9063_parse_regulators_dt()
772 num = of_regulator_match(&pdev->dev, node, da9063_matches, in da9063_parse_regulators_dt()
776 dev_err(&pdev->dev, "Failed to match regulators\n"); in da9063_parse_regulators_dt()
777 return ERR_PTR(-EINVAL); in da9063_parse_regulators_dt()
780 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); in da9063_parse_regulators_dt()
782 return ERR_PTR(-ENOMEM); in da9063_parse_regulators_dt()
784 pdata->regulator_data = devm_kcalloc(&pdev->dev, in da9063_parse_regulators_dt()
785 num, sizeof(*pdata->regulator_data), in da9063_parse_regulators_dt()
787 if (!pdata->regulator_data) in da9063_parse_regulators_dt()
788 return ERR_PTR(-ENOMEM); in da9063_parse_regulators_dt()
789 pdata->n_regulators = num; in da9063_parse_regulators_dt()
796 rdata = &pdata->regulator_data[n]; in da9063_parse_regulators_dt()
797 rdata->id = i; in da9063_parse_regulators_dt()
798 rdata->initdata = da9063_matches[i].init_data; in da9063_parse_regulators_dt()
809 struct da9063 *da9063 = dev_get_drvdata(pdev->dev.parent); in da9063_regulator_probe()
821 if (IS_ERR(regl_pdata) || regl_pdata->n_regulators == 0) { in da9063_regulator_probe()
822 dev_err(&pdev->dev, in da9063_regulator_probe()
824 return -ENODEV; in da9063_regulator_probe()
828 for (model = regulators_models; model->regulator_info; model++) { in da9063_regulator_probe()
829 if (model->type == da9063->type) in da9063_regulator_probe()
832 if (!model->regulator_info) { in da9063_regulator_probe()
833 dev_err(&pdev->dev, "Chip model not recognised (%u)\n", in da9063_regulator_probe()
834 da9063->type); in da9063_regulator_probe()
835 return -ENODEV; in da9063_regulator_probe()
838 ret = regmap_read(da9063->regmap, DA9063_REG_CONFIG_H, &val); in da9063_regulator_probe()
840 dev_err(&pdev->dev, in da9063_regulator_probe()
847 n_regulators = model->n_regulators; in da9063_regulator_probe()
849 n_regulators -= 2; /* remove BCORE1, BCORE2 */ in da9063_regulator_probe()
851 n_regulators--; /* remove BCORES_MERGED */ in da9063_regulator_probe()
853 n_regulators -= 2; /* remove BMEM, BIO */ in da9063_regulator_probe()
855 n_regulators--; /* remove BMEM_BIO_MERGED */ in da9063_regulator_probe()
858 regulators = devm_kzalloc(&pdev->dev, struct_size(regulators, in da9063_regulator_probe()
861 return -ENOMEM; in da9063_regulator_probe()
863 regulators->n_regulators = n_regulators; in da9063_regulator_probe()
869 while (n < regulators->n_regulators) { in da9063_regulator_probe()
901 regl = &regulators->regulator[n]; in da9063_regulator_probe()
902 regl->hw = da9063; in da9063_regulator_probe()
903 regl->info = &model->regulator_info[id]; in da9063_regulator_probe()
904 regl->desc = regl->info->desc; in da9063_regulator_probe()
905 regl->desc.type = REGULATOR_VOLTAGE; in da9063_regulator_probe()
906 regl->desc.owner = THIS_MODULE; in da9063_regulator_probe()
908 if (regl->info->mode.reg) { in da9063_regulator_probe()
909 regl->mode = devm_regmap_field_alloc(&pdev->dev, in da9063_regulator_probe()
910 da9063->regmap, regl->info->mode); in da9063_regulator_probe()
911 if (IS_ERR(regl->mode)) in da9063_regulator_probe()
912 return PTR_ERR(regl->mode); in da9063_regulator_probe()
915 if (regl->info->suspend.reg) { in da9063_regulator_probe()
916 regl->suspend = devm_regmap_field_alloc(&pdev->dev, in da9063_regulator_probe()
917 da9063->regmap, regl->info->suspend); in da9063_regulator_probe()
918 if (IS_ERR(regl->suspend)) in da9063_regulator_probe()
919 return PTR_ERR(regl->suspend); in da9063_regulator_probe()
922 if (regl->info->sleep.reg) { in da9063_regulator_probe()
923 regl->sleep = devm_regmap_field_alloc(&pdev->dev, in da9063_regulator_probe()
924 da9063->regmap, regl->info->sleep); in da9063_regulator_probe()
925 if (IS_ERR(regl->sleep)) in da9063_regulator_probe()
926 return PTR_ERR(regl->sleep); in da9063_regulator_probe()
929 if (regl->info->suspend_sleep.reg) { in da9063_regulator_probe()
930 regl->suspend_sleep = devm_regmap_field_alloc(&pdev->dev, in da9063_regulator_probe()
931 da9063->regmap, regl->info->suspend_sleep); in da9063_regulator_probe()
932 if (IS_ERR(regl->suspend_sleep)) in da9063_regulator_probe()
933 return PTR_ERR(regl->suspend_sleep); in da9063_regulator_probe()
938 config.dev = &pdev->dev; in da9063_regulator_probe()
943 config.regmap = da9063->regmap; in da9063_regulator_probe()
944 regl->rdev = devm_regulator_register(&pdev->dev, &regl->desc, in da9063_regulator_probe()
946 if (IS_ERR(regl->rdev)) { in da9063_regulator_probe()
947 dev_err(&pdev->dev, in da9063_regulator_probe()
949 regl->desc.name); in da9063_regulator_probe()
950 return PTR_ERR(regl->rdev); in da9063_regulator_probe()
961 ret = devm_request_threaded_irq(&pdev->dev, irq, in da9063_regulator_probe()
966 dev_err(&pdev->dev, "Failed to request LDO_LIM IRQ.\n"); in da9063_regulator_probe()