Lines Matching +full:ldo +full:- +full:v
1 // SPDX-License-Identifier: GPL-2.0-only
8 * Copyright (C) 2012-2013 Texas Instruments, Inc.
24 * ABB LDO operating states:
25 * NOMINAL_OPP: bypasses the ABB LDO
26 * FAST_OPP: sets ABB LDO to Forward Body-Bias
27 * SLOW_OPP: sets ABB LDO to Reverse Body-Bias
34 * struct ti_abb_info - ABB information per voltage setting
47 * struct ti_abb_reg - Register description for ABB block
50 * @sr2_wtcnt_value_mask: setup register- sr2_wtcnt_value mask
51 * @fbb_sel_mask: setup register- FBB sel mask
52 * @rbb_sel_mask: setup register- RBB sel mask
53 * @sr2_en_mask: setup register- enable mask
54 * @opp_change_mask: control register - mask to trigger LDOVBB change
55 * @opp_sel_mask: control register - mask for mode to operate
73 * struct ti_abb - ABB instance data
84 * @ldovbb_override_mask: mask to ldo_base for overriding default LDO VBB
89 * @settling_time: SoC specific settling time for LDO VBB
113 * ti_abb_rmw() - handy wrapper to set specific register bits
133 * ti_abb_check_txdone() - handy wrapper to check ABB tranxdone status
140 return !!(readl(abb->int_base) & abb->txdone_mask); in ti_abb_check_txdone()
144 * ti_abb_clear_txdone() - handy wrapper to clear ABB tranxdone status
149 writel(abb->txdone_mask, abb->int_base); in ti_abb_clear_txdone()
153 * ti_abb_wait_txdone() - waits for ABB tranxdone event
157 * Return: 0 on success or -ETIMEDOUT if the event is not cleared on time.
164 while (timeout++ <= abb->settling_time) { in ti_abb_wait_txdone()
173 __func__, timeout, readl(abb->int_base)); in ti_abb_wait_txdone()
174 return -ETIMEDOUT; in ti_abb_wait_txdone()
178 * ti_abb_clear_all_txdone() - clears ABB tranxdone event
182 * Return: 0 on success or -ETIMEDOUT if the event is not cleared on time.
189 while (timeout++ <= abb->settling_time) { in ti_abb_clear_all_txdone()
200 __func__, timeout, readl(abb->int_base)); in ti_abb_clear_all_txdone()
201 return -ETIMEDOUT; in ti_abb_clear_all_txdone()
205 * ti_abb_program_ldovbb() - program LDOVBB register for override value
215 val = readl(abb->ldo_base); in ti_abb_program_ldovbb()
217 val &= ~(abb->ldovbb_override_mask | abb->ldovbb_vset_mask); in ti_abb_program_ldovbb()
219 switch (info->opp_sel) { in ti_abb_program_ldovbb()
222 val |= abb->ldovbb_override_mask; in ti_abb_program_ldovbb()
223 val |= info->vset << __ffs(abb->ldovbb_vset_mask); in ti_abb_program_ldovbb()
227 writel(val, abb->ldo_base); in ti_abb_program_ldovbb()
231 * ti_abb_set_opp() - Setup ABB and LDO VBB for required bias
241 const struct ti_abb_reg *regs = abb->regs; in ti_abb_set_opp()
242 struct device *dev = &rdev->dev; in ti_abb_set_opp()
249 ti_abb_rmw(regs->fbb_sel_mask | regs->rbb_sel_mask, 0, abb->setup_reg); in ti_abb_set_opp()
251 switch (info->opp_sel) { in ti_abb_set_opp()
253 ti_abb_rmw(regs->rbb_sel_mask, 1, abb->setup_reg); in ti_abb_set_opp()
256 ti_abb_rmw(regs->fbb_sel_mask, 1, abb->setup_reg); in ti_abb_set_opp()
260 /* program next state of ABB ldo */ in ti_abb_set_opp()
261 ti_abb_rmw(regs->opp_sel_mask, info->opp_sel, abb->control_reg); in ti_abb_set_opp()
264 * program LDO VBB vset override if needed for !bypass mode in ti_abb_set_opp()
265 * XXX: Do not switch sequence - for !bypass, LDO override reset *must* in ti_abb_set_opp()
268 if (abb->ldo_base && info->opp_sel != TI_ABB_NOMINAL_OPP) in ti_abb_set_opp()
271 /* Initiate ABB ldo change */ in ti_abb_set_opp()
272 ti_abb_rmw(regs->opp_change_mask, 1, abb->control_reg); in ti_abb_set_opp()
274 /* Wait for ABB LDO to complete transition to new Bias setting */ in ti_abb_set_opp()
284 * Reset LDO VBB vset override bypass mode in ti_abb_set_opp()
285 * XXX: Do not switch sequence - for bypass, LDO override reset *must* in ti_abb_set_opp()
288 if (abb->ldo_base && info->opp_sel == TI_ABB_NOMINAL_OPP) in ti_abb_set_opp()
296 * ti_abb_set_voltage_sel() - regulator accessor function to set ABB LDO
298 * @sel: selector to index into required ABB LDO settings (maps to
305 const struct regulator_desc *desc = rdev->desc; in ti_abb_set_voltage_sel()
307 struct device *dev = &rdev->dev; in ti_abb_set_voltage_sel()
314 return -ENODEV; in ti_abb_set_voltage_sel()
317 if (!desc->n_voltages || !abb->info) { in ti_abb_set_voltage_sel()
321 return -EINVAL; in ti_abb_set_voltage_sel()
324 if (sel >= desc->n_voltages) { in ti_abb_set_voltage_sel()
326 sel, desc->n_voltages); in ti_abb_set_voltage_sel()
327 return -EINVAL; in ti_abb_set_voltage_sel()
331 if (sel == abb->current_info_idx) { in ti_abb_set_voltage_sel()
336 info = &abb->info[sel]; in ti_abb_set_voltage_sel()
343 if (abb->current_info_idx == -EINVAL) in ti_abb_set_voltage_sel()
347 oinfo = &abb->info[abb->current_info_idx]; in ti_abb_set_voltage_sel()
350 sel, abb->current_info_idx); in ti_abb_set_voltage_sel()
359 abb->current_info_idx = sel; in ti_abb_set_voltage_sel()
363 __func__, desc->volt_table[sel], sel, in ti_abb_set_voltage_sel()
364 info->opp_sel, ret); in ti_abb_set_voltage_sel()
369 * ti_abb_get_voltage_sel() - Regulator accessor to get current ABB LDO setting
376 const struct regulator_desc *desc = rdev->desc; in ti_abb_get_voltage_sel()
378 struct device *dev = &rdev->dev; in ti_abb_get_voltage_sel()
383 return -ENODEV; in ti_abb_get_voltage_sel()
386 if (!desc->n_voltages || !abb->info) { in ti_abb_get_voltage_sel()
390 return -EINVAL; in ti_abb_get_voltage_sel()
393 if (abb->current_info_idx >= (int)desc->n_voltages) { in ti_abb_get_voltage_sel()
395 __func__, abb->current_info_idx, desc->n_voltages); in ti_abb_get_voltage_sel()
396 return -EINVAL; in ti_abb_get_voltage_sel()
399 return abb->current_info_idx; in ti_abb_get_voltage_sel()
403 * ti_abb_init_timings() - setup ABB clock timing for the current platform
413 const struct ti_abb_reg *regs = abb->regs; in ti_abb_init_timings()
415 char *pname = "ti,settling-time"; in ti_abb_init_timings()
418 ret = of_property_read_u32(dev->of_node, pname, &abb->settling_time); in ti_abb_init_timings()
424 /* ABB LDO cannot be settle in 0 time */ in ti_abb_init_timings()
425 if (!abb->settling_time) { in ti_abb_init_timings()
427 return -EINVAL; in ti_abb_init_timings()
430 pname = "ti,clock-cycles"; in ti_abb_init_timings()
431 ret = of_property_read_u32(dev->of_node, pname, &clock_cycles); in ti_abb_init_timings()
436 /* ABB LDO cannot be settle in 0 clock cycles */ in ti_abb_init_timings()
439 return -EINVAL; in ti_abb_init_timings()
442 abb->clk = devm_clk_get(dev, NULL); in ti_abb_init_timings()
443 if (IS_ERR(abb->clk)) { in ti_abb_init_timings()
444 ret = PTR_ERR(abb->clk); in ti_abb_init_timings()
450 * SR2_WTCNT_VALUE is the settling time for the ABB ldo after a in ti_abb_init_timings()
453 * clock cycles that match a given wall time profiled for the ldo. in ti_abb_init_timings()
455 * settling time of ldo in micro-seconds (varies per OMAP family) in ti_abb_init_timings()
460 * ldo settling time (in micro-seconds) in ti_abb_init_timings()
461 * SR2_WTCNT_VALUE = ------------------------------------------ in ti_abb_init_timings()
473 clk_rate = DIV_ROUND_CLOSEST(clk_get_rate(abb->clk), 1000000); in ti_abb_init_timings()
479 sr2_wt_cnt_val = DIV_ROUND_CLOSEST(abb->settling_time * 10, cycle_rate); in ti_abb_init_timings()
482 clk_get_rate(abb->clk), sr2_wt_cnt_val); in ti_abb_init_timings()
484 ti_abb_rmw(regs->sr2_wtcnt_value_mask, sr2_wt_cnt_val, abb->setup_reg); in ti_abb_init_timings()
490 * ti_abb_init_table() - Initialize ABB table from device tree
506 struct regulation_constraints *c = &rinit_data->constraints; in ti_abb_init_table()
509 * Each abb_info is a set of n-tuple, where n is num_values, consisting in ti_abb_init_table()
513 num_entries = of_property_count_u32_elems(dev->of_node, pname); in ti_abb_init_table()
522 return -EINVAL; in ti_abb_init_table()
528 return -ENOMEM; in ti_abb_init_table()
530 abb->info = info; in ti_abb_init_table()
535 return -ENOMEM; in ti_abb_init_table()
537 abb->rdesc.n_voltages = num_entries; in ti_abb_init_table()
538 abb->rdesc.volt_table = volt_table; in ti_abb_init_table()
540 abb->current_info_idx = -EINVAL; in ti_abb_init_table()
547 of_property_read_u32_index(dev->of_node, pname, i * num_values, in ti_abb_init_table()
549 of_property_read_u32_index(dev->of_node, pname, in ti_abb_init_table()
550 i * num_values + 1, &info->opp_sel); in ti_abb_init_table()
551 of_property_read_u32_index(dev->of_node, pname, in ti_abb_init_table()
553 of_property_read_u32_index(dev->of_node, pname, in ti_abb_init_table()
555 of_property_read_u32_index(dev->of_node, pname, in ti_abb_init_table()
557 of_property_read_u32_index(dev->of_node, pname, in ti_abb_init_table()
561 "[%d]v=%d ABB=%d ef=0x%x rbb=0x%x fbb=0x%x vset=0x%x\n", in ti_abb_init_table()
562 i, *volt_table, info->opp_sel, efuse_offset, rbb_mask, in ti_abb_init_table()
571 if (!abb->efuse_base) { in ti_abb_init_table()
574 dev_err(dev, "prop '%s': v=%d,bad efuse/mask\n", in ti_abb_init_table()
579 efuse_val = readl(abb->efuse_base + efuse_offset); in ti_abb_init_table()
583 info->opp_sel = TI_ABB_SLOW_OPP; in ti_abb_init_table()
585 info->opp_sel = TI_ABB_FAST_OPP; in ti_abb_init_table()
587 info->opp_sel = TI_ABB_NOMINAL_OPP; in ti_abb_init_table()
590 "[%d]v=%d efusev=0x%x final ABB=%d\n", in ti_abb_init_table()
591 i, *volt_table, efuse_val, info->opp_sel); in ti_abb_init_table()
594 if (!abb->ldo_base) { in ti_abb_init_table()
596 dev_err(dev, "prop'%s':v=%d vst=%x LDO base?\n", in ti_abb_init_table()
600 info->vset = (efuse_val & vset_mask) >> __ffs(vset_mask); in ti_abb_init_table()
601 dev_dbg(dev, "[%d]v=%d vset=%x\n", i, *volt_table, info->vset); in ti_abb_init_table()
603 switch (info->opp_sel) { in ti_abb_init_table()
610 dev_err(dev, "%s:[%d]v=%d, ABB=%d is invalid! Abort!\n", in ti_abb_init_table()
611 __func__, i, *volt_table, info->opp_sel); in ti_abb_init_table()
612 return -EINVAL; in ti_abb_init_table()
617 c->min_uV = min_uV; in ti_abb_init_table()
618 c->max_uV = max_uV; in ti_abb_init_table()
669 {.compatible = "ti,abb-v1", .data = &abb_regs_v1},
670 {.compatible = "ti,abb-v2", .data = &abb_regs_v2},
671 {.compatible = "ti,abb-v3", .data = &abb_regs_generic},
678 * ti_abb_probe() - Initialize an ABB ldo instance
681 * Initializes an individual ABB LDO for required Body-Bias. ABB is used to
689 struct device *dev = &pdev->dev; in ti_abb_probe()
702 return -ENOMEM; in ti_abb_probe()
704 abb->regs = device_get_match_data(dev); in ti_abb_probe()
705 if (!abb->regs) { in ti_abb_probe()
707 return -EINVAL; in ti_abb_probe()
711 if (abb->regs->setup_off || abb->regs->control_off) { in ti_abb_probe()
712 abb->base = devm_platform_ioremap_resource_byname(pdev, "base-address"); in ti_abb_probe()
713 if (IS_ERR(abb->base)) in ti_abb_probe()
714 return PTR_ERR(abb->base); in ti_abb_probe()
716 abb->setup_reg = abb->base + abb->regs->setup_off; in ti_abb_probe()
717 abb->control_reg = abb->base + abb->regs->control_off; in ti_abb_probe()
720 abb->control_reg = devm_platform_ioremap_resource_byname(pdev, "control-address"); in ti_abb_probe()
721 if (IS_ERR(abb->control_reg)) in ti_abb_probe()
722 return PTR_ERR(abb->control_reg); in ti_abb_probe()
724 abb->setup_reg = devm_platform_ioremap_resource_byname(pdev, "setup-address"); in ti_abb_probe()
725 if (IS_ERR(abb->setup_reg)) in ti_abb_probe()
726 return PTR_ERR(abb->setup_reg); in ti_abb_probe()
729 pname = "int-address"; in ti_abb_probe()
733 return -ENODEV; in ti_abb_probe()
737 * shared between regulator-abb-{ivahd,dspeve,gpu} driver in ti_abb_probe()
742 abb->int_base = devm_ioremap(dev, res->start, in ti_abb_probe()
744 if (!abb->int_base) { in ti_abb_probe()
746 return -ENOMEM; in ti_abb_probe()
750 pname = "efuse-address"; in ti_abb_probe()
754 ret = -ENODEV; in ti_abb_probe()
759 * We may have shared efuse register offsets which are read-only in ti_abb_probe()
762 abb->efuse_base = devm_ioremap(dev, res->start, in ti_abb_probe()
764 if (!abb->efuse_base) { in ti_abb_probe()
766 return -ENOMEM; in ti_abb_probe()
769 pname = "ldo-address"; in ti_abb_probe()
773 ret = -ENODEV; in ti_abb_probe()
776 abb->ldo_base = devm_ioremap_resource(dev, res); in ti_abb_probe()
777 if (IS_ERR(abb->ldo_base)) in ti_abb_probe()
778 return PTR_ERR(abb->ldo_base); in ti_abb_probe()
781 pname = "ti,ldovbb-override-mask"; in ti_abb_probe()
783 of_property_read_u32(pdev->dev.of_node, pname, in ti_abb_probe()
784 &abb->ldovbb_override_mask); in ti_abb_probe()
789 if (!abb->ldovbb_override_mask) { in ti_abb_probe()
791 return -EINVAL; in ti_abb_probe()
794 pname = "ti,ldovbb-vset-mask"; in ti_abb_probe()
796 of_property_read_u32(pdev->dev.of_node, pname, in ti_abb_probe()
797 &abb->ldovbb_vset_mask); in ti_abb_probe()
802 if (!abb->ldovbb_vset_mask) { in ti_abb_probe()
804 return -EINVAL; in ti_abb_probe()
808 pname = "ti,tranxdone-status-mask"; in ti_abb_probe()
810 of_property_read_u32(pdev->dev.of_node, pname, in ti_abb_probe()
811 &abb->txdone_mask); in ti_abb_probe()
816 if (!abb->txdone_mask) { in ti_abb_probe()
818 return -EINVAL; in ti_abb_probe()
821 initdata = of_get_regulator_init_data(dev, pdev->dev.of_node, in ti_abb_probe()
822 &abb->rdesc); in ti_abb_probe()
826 return -ENOMEM; in ti_abb_probe()
839 desc = &abb->rdesc; in ti_abb_probe()
840 desc->name = dev_name(dev); in ti_abb_probe()
841 desc->owner = THIS_MODULE; in ti_abb_probe()
842 desc->type = REGULATOR_VOLTAGE; in ti_abb_probe()
843 desc->ops = &ti_abb_reg_ops; in ti_abb_probe()
845 c = &initdata->constraints; in ti_abb_probe()
846 if (desc->n_voltages > 1) in ti_abb_probe()
847 c->valid_ops_mask |= REGULATOR_CHANGE_VOLTAGE; in ti_abb_probe()
848 c->always_on = true; in ti_abb_probe()
853 config.of_node = pdev->dev.of_node; in ti_abb_probe()
864 /* Enable the ldo if not already done by bootloader */ in ti_abb_probe()
865 ti_abb_rmw(abb->regs->sr2_en_mask, 1, abb->setup_reg); in ti_abb_probe()
882 MODULE_DESCRIPTION("Texas Instruments ABB LDO regulator driver");