Lines Matching full:abb
2 * Texas Instruments SoC Adaptive Body Bias(ABB) Regulator
33 * ABB LDO operating states:
34 * NOMINAL_OPP: bypasses the ABB LDO
35 * FAST_OPP: sets ABB LDO to Forward Body-Bias
36 * SLOW_OPP: sets ABB LDO to Reverse Body-Bias
43 * struct ti_abb_info - ABB information per voltage setting
56 * struct ti_abb_reg - Register description for ABB block
82 * struct ti_abb - ABB instance data
84 * @clk: clock(usually sysclk) supplying ABB block
85 * @base: base address of ABB block
86 * @setup_reg: setup register of ABB block
87 * @control_reg: control register of ABB block
89 * @efuse_base: (optional) efuse base address for ABB modes
91 * @regs: pointer to struct ti_abb_reg for ABB block
96 * @info: array to per voltage ABB configuration
142 * ti_abb_check_txdone() - handy wrapper to check ABB tranxdone status
143 * @abb: pointer to the abb instance
147 static inline bool ti_abb_check_txdone(const struct ti_abb *abb) in ti_abb_check_txdone() argument
149 return !!(readl(abb->int_base) & abb->txdone_mask); in ti_abb_check_txdone()
153 * ti_abb_clear_txdone() - handy wrapper to clear ABB tranxdone status
154 * @abb: pointer to the abb instance
156 static inline void ti_abb_clear_txdone(const struct ti_abb *abb) in ti_abb_clear_txdone() argument
158 writel(abb->txdone_mask, abb->int_base); in ti_abb_clear_txdone()
162 * ti_abb_wait_tranx() - waits for ABB tranxdone event
164 * @abb: pointer to the abb instance
168 static int ti_abb_wait_txdone(struct device *dev, struct ti_abb *abb) in ti_abb_wait_txdone() argument
173 while (timeout++ <= abb->settling_time) { in ti_abb_wait_txdone()
174 status = ti_abb_check_txdone(abb); in ti_abb_wait_txdone()
182 __func__, timeout, readl(abb->int_base)); in ti_abb_wait_txdone()
187 * ti_abb_clear_all_txdone() - clears ABB tranxdone event
189 * @abb: pointer to the abb instance
193 static int ti_abb_clear_all_txdone(struct device *dev, const struct ti_abb *abb) in ti_abb_clear_all_txdone() argument
198 while (timeout++ <= abb->settling_time) { in ti_abb_clear_all_txdone()
199 ti_abb_clear_txdone(abb); in ti_abb_clear_all_txdone()
201 status = ti_abb_check_txdone(abb); in ti_abb_clear_all_txdone()
209 __func__, timeout, readl(abb->int_base)); in ti_abb_clear_all_txdone()
216 * @abb: pointer to the abb instance
217 * @info: ABB info to program
219 static void ti_abb_program_ldovbb(struct device *dev, const struct ti_abb *abb, in ti_abb_program_ldovbb() argument
224 val = readl(abb->ldo_base); in ti_abb_program_ldovbb()
226 val &= ~(abb->ldovbb_override_mask | abb->ldovbb_vset_mask); in ti_abb_program_ldovbb()
231 val |= abb->ldovbb_override_mask; in ti_abb_program_ldovbb()
232 val |= info->vset << __ffs(abb->ldovbb_vset_mask); in ti_abb_program_ldovbb()
236 writel(val, abb->ldo_base); in ti_abb_program_ldovbb()
240 * ti_abb_set_opp() - Setup ABB and LDO VBB for required bias
242 * @abb: pointer to the abb instance
243 * @info: ABB info to program
247 static int ti_abb_set_opp(struct regulator_dev *rdev, struct ti_abb *abb, in ti_abb_set_opp() argument
250 const struct ti_abb_reg *regs = abb->regs; in ti_abb_set_opp()
254 ret = ti_abb_clear_all_txdone(dev, abb); in ti_abb_set_opp()
258 ti_abb_rmw(regs->fbb_sel_mask | regs->rbb_sel_mask, 0, abb->setup_reg); in ti_abb_set_opp()
262 ti_abb_rmw(regs->rbb_sel_mask, 1, abb->setup_reg); in ti_abb_set_opp()
265 ti_abb_rmw(regs->fbb_sel_mask, 1, abb->setup_reg); in ti_abb_set_opp()
269 /* program next state of ABB ldo */ in ti_abb_set_opp()
270 ti_abb_rmw(regs->opp_sel_mask, info->opp_sel, abb->control_reg); in ti_abb_set_opp()
277 if (abb->ldo_base && info->opp_sel != TI_ABB_NOMINAL_OPP) in ti_abb_set_opp()
278 ti_abb_program_ldovbb(dev, abb, info); in ti_abb_set_opp()
280 /* Initiate ABB ldo change */ in ti_abb_set_opp()
281 ti_abb_rmw(regs->opp_change_mask, 1, abb->control_reg); in ti_abb_set_opp()
283 /* Wait for ABB LDO to complete transition to new Bias setting */ in ti_abb_set_opp()
284 ret = ti_abb_wait_txdone(dev, abb); in ti_abb_set_opp()
288 ret = ti_abb_clear_all_txdone(dev, abb); in ti_abb_set_opp()
297 if (abb->ldo_base && info->opp_sel == TI_ABB_NOMINAL_OPP) in ti_abb_set_opp()
298 ti_abb_program_ldovbb(dev, abb, info); in ti_abb_set_opp()
305 * ti_abb_set_voltage_sel() - regulator accessor function to set ABB LDO
307 * @sel: selector to index into required ABB LDO settings (maps to
315 struct ti_abb *abb = rdev_get_drvdata(rdev); in ti_abb_set_voltage_sel() local
320 if (!abb) { in ti_abb_set_voltage_sel()
326 if (!desc->n_voltages || !abb->info) { in ti_abb_set_voltage_sel()
340 if (sel == abb->current_info_idx) { in ti_abb_set_voltage_sel()
345 info = &abb->info[sel]; in ti_abb_set_voltage_sel()
352 if (abb->current_info_idx == -EINVAL) in ti_abb_set_voltage_sel()
356 oinfo = &abb->info[abb->current_info_idx]; in ti_abb_set_voltage_sel()
359 sel, abb->current_info_idx); in ti_abb_set_voltage_sel()
364 ret = ti_abb_set_opp(rdev, abb, info); in ti_abb_set_voltage_sel()
368 abb->current_info_idx = sel; in ti_abb_set_voltage_sel()
378 * ti_abb_get_voltage_sel() - Regulator accessor to get current ABB LDO setting
386 struct ti_abb *abb = rdev_get_drvdata(rdev); in ti_abb_get_voltage_sel() local
389 if (!abb) { in ti_abb_get_voltage_sel()
395 if (!desc->n_voltages || !abb->info) { in ti_abb_get_voltage_sel()
402 if (abb->current_info_idx >= (int)desc->n_voltages) { in ti_abb_get_voltage_sel()
404 __func__, abb->current_info_idx, desc->n_voltages); in ti_abb_get_voltage_sel()
408 return abb->current_info_idx; in ti_abb_get_voltage_sel()
412 * ti_abb_init_timings() - setup ABB clock timing for the current platform
414 * @abb: pointer to the abb instance
418 static int ti_abb_init_timings(struct device *dev, struct ti_abb *abb) in ti_abb_init_timings() argument
422 const struct ti_abb_reg *regs = abb->regs; in ti_abb_init_timings()
427 ret = of_property_read_u32(dev->of_node, pname, &abb->settling_time); in ti_abb_init_timings()
433 /* ABB LDO cannot be settle in 0 time */ in ti_abb_init_timings()
434 if (!abb->settling_time) { in ti_abb_init_timings()
445 /* ABB LDO cannot be settle in 0 clock cycles */ in ti_abb_init_timings()
451 abb->clk = devm_clk_get(dev, NULL); in ti_abb_init_timings()
452 if (IS_ERR(abb->clk)) { in ti_abb_init_timings()
453 ret = PTR_ERR(abb->clk); in ti_abb_init_timings()
459 * SR2_WTCNT_VALUE is the settling time for the ABB ldo after a in ti_abb_init_timings()
482 clk_rate = DIV_ROUND_CLOSEST(clk_get_rate(abb->clk), 1000000); in ti_abb_init_timings()
488 sr2_wt_cnt_val = DIV_ROUND_CLOSEST(abb->settling_time * 10, cycle_rate); in ti_abb_init_timings()
491 clk_get_rate(abb->clk), sr2_wt_cnt_val); in ti_abb_init_timings()
493 ti_abb_rmw(regs->sr2_wtcnt_value_mask, sr2_wt_cnt_val, abb->setup_reg); in ti_abb_init_timings()
499 * ti_abb_init_table() - Initialize ABB table from device tree
501 * @abb: pointer to the abb instance
506 static int ti_abb_init_table(struct device *dev, struct ti_abb *abb, in ti_abb_init_table() argument
519 * of voltage and a set of detection logic for ABB information for that in ti_abb_init_table()
539 abb->info = info; in ti_abb_init_table()
546 abb->rdesc.n_voltages = num_entries; in ti_abb_init_table()
547 abb->rdesc.volt_table = volt_table; in ti_abb_init_table()
549 abb->current_info_idx = -EINVAL; in ti_abb_init_table()
570 "[%d]v=%d ABB=%d ef=0x%x rbb=0x%x fbb=0x%x vset=0x%x\n", in ti_abb_init_table()
580 if (!abb->efuse_base) { in ti_abb_init_table()
588 efuse_val = readl(abb->efuse_base + efuse_offset); in ti_abb_init_table()
590 /* Use ABB recommendation from Efuse */ in ti_abb_init_table()
599 "[%d]v=%d efusev=0x%x final ABB=%d\n", in ti_abb_init_table()
603 if (!abb->ldo_base) { in ti_abb_init_table()
619 dev_err(dev, "%s:[%d]v=%d, ABB=%d is invalid! Abort!\n", in ti_abb_init_table()
639 /* Default ABB block offsets, IF this changes in future, create new one */
678 {.compatible = "ti,abb-v1", .data = &abb_regs_v1},
679 {.compatible = "ti,abb-v2", .data = &abb_regs_v2},
680 {.compatible = "ti,abb-v3", .data = &abb_regs_generic},
687 * ti_abb_probe() - Initialize an ABB ldo instance
688 * @pdev: ABB platform device
690 * Initializes an individual ABB LDO for required Body-Bias. ABB is used to
701 struct ti_abb *abb; in ti_abb_probe() local
721 abb = devm_kzalloc(dev, sizeof(struct ti_abb), GFP_KERNEL); in ti_abb_probe()
722 if (!abb) in ti_abb_probe()
724 abb->regs = match->data; in ti_abb_probe()
726 /* Map ABB resources */ in ti_abb_probe()
727 if (abb->regs->setup_off || abb->regs->control_off) { in ti_abb_probe()
730 abb->base = devm_ioremap_resource(dev, res); in ti_abb_probe()
731 if (IS_ERR(abb->base)) in ti_abb_probe()
732 return PTR_ERR(abb->base); in ti_abb_probe()
734 abb->setup_reg = abb->base + abb->regs->setup_off; in ti_abb_probe()
735 abb->control_reg = abb->base + abb->regs->control_off; in ti_abb_probe()
740 abb->control_reg = devm_ioremap_resource(dev, res); in ti_abb_probe()
741 if (IS_ERR(abb->control_reg)) in ti_abb_probe()
742 return PTR_ERR(abb->control_reg); in ti_abb_probe()
746 abb->setup_reg = devm_ioremap_resource(dev, res); in ti_abb_probe()
747 if (IS_ERR(abb->setup_reg)) in ti_abb_probe()
748 return PTR_ERR(abb->setup_reg); in ti_abb_probe()
761 abb->int_base = devm_ioremap(dev, res->start, in ti_abb_probe()
763 if (!abb->int_base) { in ti_abb_probe()
781 abb->efuse_base = devm_ioremap(dev, res->start, in ti_abb_probe()
783 if (!abb->efuse_base) { in ti_abb_probe()
795 abb->ldo_base = devm_ioremap_resource(dev, res); in ti_abb_probe()
796 if (IS_ERR(abb->ldo_base)) in ti_abb_probe()
797 return PTR_ERR(abb->ldo_base); in ti_abb_probe()
803 &abb->ldovbb_override_mask); in ti_abb_probe()
808 if (!abb->ldovbb_override_mask) { in ti_abb_probe()
816 &abb->ldovbb_vset_mask); in ti_abb_probe()
821 if (!abb->ldovbb_vset_mask) { in ti_abb_probe()
830 &abb->txdone_mask); in ti_abb_probe()
835 if (!abb->txdone_mask) { in ti_abb_probe()
841 &abb->rdesc); in ti_abb_probe()
848 /* init ABB opp_sel table */ in ti_abb_probe()
849 ret = ti_abb_init_table(dev, abb, initdata); in ti_abb_probe()
853 /* init ABB timing */ in ti_abb_probe()
854 ret = ti_abb_init_timings(dev, abb); in ti_abb_probe()
858 desc = &abb->rdesc; in ti_abb_probe()
871 config.driver_data = abb; in ti_abb_probe()
884 ti_abb_rmw(abb->regs->sr2_en_mask, 1, abb->setup_reg); in ti_abb_probe()
900 MODULE_DESCRIPTION("Texas Instruments ABB LDO regulator driver");