1 // SPDX-License-Identifier: GPL-2.0-only
3 * Texas Instruments SoC Adaptive Body Bias(ABB) Regulator
5 * Copyright (C) 2011 Texas Instruments, Inc.
6 * Mike Turquette <mturquette@ti.com>
8 * Copyright (C) 2012-2013 Texas Instruments, Inc.
9 * Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
10 * Nishanth Menon <nm@ti.com>
12 #include <linux/clk.h>
13 #include <linux/delay.h>
14 #include <linux/err.h>
16 #include <linux/module.h>
18 #include <linux/platform_device.h>
19 #include <linux/regulator/driver.h>
20 #include <linux/regulator/machine.h>
21 #include <linux/regulator/of_regulator.h>
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
29 #define TI_ABB_NOMINAL_OPP 0
30 #define TI_ABB_FAST_OPP 1
31 #define TI_ABB_SLOW_OPP 3
34 * struct ti_abb_info - ABB information per voltage setting
35 * @opp_sel: one of TI_ABB macro
36 * @vset: (optional) vset value that LDOVBB needs to be overridden with.
38 * Array of per voltage entries organized in the same order as regulator_desc's
39 * volt_table list. (selector is used to index from this array)
47 * struct ti_abb_reg - Register description for ABB block
48 * @setup_off: setup register offset from base
49 * @control_off: control register offset from base
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
61 /* Setup register fields */
62 u32 sr2_wtcnt_value_mask
;
67 /* Control register fields */
73 * struct ti_abb - ABB instance data
74 * @rdesc: regulator descriptor
75 * @clk: clock(usually sysclk) supplying ABB block
76 * @base: base address of ABB block
77 * @setup_reg: setup register of ABB block
78 * @control_reg: control register of ABB block
79 * @int_base: interrupt register base address
80 * @efuse_base: (optional) efuse base address for ABB modes
81 * @ldo_base: (optional) LDOVBB vset override base address
82 * @regs: pointer to struct ti_abb_reg for ABB block
83 * @txdone_mask: mask on int_base for tranxdone interrupt
84 * @ldovbb_override_mask: mask to ldo_base for overriding default LDO VBB
85 * vset with value from efuse
86 * @ldovbb_vset_mask: mask to ldo_base for providing the VSET override
87 * @info: array to per voltage ABB configuration
88 * @current_info_idx: current index to info
89 * @settling_time: SoC specific settling time for LDO VBB
92 struct regulator_desc rdesc
;
95 void __iomem
*setup_reg
;
96 void __iomem
*control_reg
;
97 void __iomem
*int_base
;
98 void __iomem
*efuse_base
;
99 void __iomem
*ldo_base
;
101 const struct ti_abb_reg
*regs
;
103 u32 ldovbb_override_mask
;
104 u32 ldovbb_vset_mask
;
106 struct ti_abb_info
*info
;
107 int current_info_idx
;
113 * ti_abb_rmw() - handy wrapper to set specific register bits
114 * @mask: mask for register field
115 * @value: value shifted to mask location and written
116 * @reg: register address
118 * Return: final register value (may be unused)
120 static inline u32
ti_abb_rmw(u32 mask
, u32 value
, void __iomem
*reg
)
126 val
|= (value
<< __ffs(mask
)) & mask
;
133 * ti_abb_check_txdone() - handy wrapper to check ABB tranxdone status
134 * @abb: pointer to the abb instance
136 * Return: true or false
138 static inline bool ti_abb_check_txdone(const struct ti_abb
*abb
)
140 return !!(readl(abb
->int_base
) & abb
->txdone_mask
);
144 * ti_abb_clear_txdone() - handy wrapper to clear ABB tranxdone status
145 * @abb: pointer to the abb instance
147 static inline void ti_abb_clear_txdone(const struct ti_abb
*abb
)
149 writel(abb
->txdone_mask
, abb
->int_base
);
153 * ti_abb_wait_txdone() - waits for ABB tranxdone event
155 * @abb: pointer to the abb instance
157 * Return: 0 on success or -ETIMEDOUT if the event is not cleared on time.
159 static int ti_abb_wait_txdone(struct device
*dev
, struct ti_abb
*abb
)
164 while (timeout
++ <= abb
->settling_time
) {
165 status
= ti_abb_check_txdone(abb
);
172 dev_warn_ratelimited(dev
, "%s:TRANXDONE timeout(%duS) int=0x%08x\n",
173 __func__
, timeout
, readl(abb
->int_base
));
178 * ti_abb_clear_all_txdone() - clears ABB tranxdone event
180 * @abb: pointer to the abb instance
182 * Return: 0 on success or -ETIMEDOUT if the event is not cleared on time.
184 static int ti_abb_clear_all_txdone(struct device
*dev
, const struct ti_abb
*abb
)
189 while (timeout
++ <= abb
->settling_time
) {
190 ti_abb_clear_txdone(abb
);
192 status
= ti_abb_check_txdone(abb
);
199 dev_warn_ratelimited(dev
, "%s:TRANXDONE timeout(%duS) int=0x%08x\n",
200 __func__
, timeout
, readl(abb
->int_base
));
205 * ti_abb_program_ldovbb() - program LDOVBB register for override value
207 * @abb: pointer to the abb instance
208 * @info: ABB info to program
210 static void ti_abb_program_ldovbb(struct device
*dev
, const struct ti_abb
*abb
,
211 struct ti_abb_info
*info
)
215 val
= readl(abb
->ldo_base
);
216 /* clear up previous values */
217 val
&= ~(abb
->ldovbb_override_mask
| abb
->ldovbb_vset_mask
);
219 switch (info
->opp_sel
) {
220 case TI_ABB_SLOW_OPP
:
221 case TI_ABB_FAST_OPP
:
222 val
|= abb
->ldovbb_override_mask
;
223 val
|= info
->vset
<< __ffs(abb
->ldovbb_vset_mask
);
227 writel(val
, abb
->ldo_base
);
231 * ti_abb_set_opp() - Setup ABB and LDO VBB for required bias
232 * @rdev: regulator device
233 * @abb: pointer to the abb instance
234 * @info: ABB info to program
236 * Return: 0 on success or appropriate error value when fails
238 static int ti_abb_set_opp(struct regulator_dev
*rdev
, struct ti_abb
*abb
,
239 struct ti_abb_info
*info
)
241 const struct ti_abb_reg
*regs
= abb
->regs
;
242 struct device
*dev
= &rdev
->dev
;
245 ret
= ti_abb_clear_all_txdone(dev
, abb
);
249 ti_abb_rmw(regs
->fbb_sel_mask
| regs
->rbb_sel_mask
, 0, abb
->setup_reg
);
251 switch (info
->opp_sel
) {
252 case TI_ABB_SLOW_OPP
:
253 ti_abb_rmw(regs
->rbb_sel_mask
, 1, abb
->setup_reg
);
255 case TI_ABB_FAST_OPP
:
256 ti_abb_rmw(regs
->fbb_sel_mask
, 1, abb
->setup_reg
);
260 /* program next state of ABB ldo */
261 ti_abb_rmw(regs
->opp_sel_mask
, info
->opp_sel
, abb
->control_reg
);
264 * program LDO VBB vset override if needed for !bypass mode
265 * XXX: Do not switch sequence - for !bypass, LDO override reset *must*
266 * be performed *before* switch to bias mode else VBB glitches.
268 if (abb
->ldo_base
&& info
->opp_sel
!= TI_ABB_NOMINAL_OPP
)
269 ti_abb_program_ldovbb(dev
, abb
, info
);
271 /* Initiate ABB ldo change */
272 ti_abb_rmw(regs
->opp_change_mask
, 1, abb
->control_reg
);
274 /* Wait for ABB LDO to complete transition to new Bias setting */
275 ret
= ti_abb_wait_txdone(dev
, abb
);
279 ret
= ti_abb_clear_all_txdone(dev
, abb
);
284 * Reset LDO VBB vset override bypass mode
285 * XXX: Do not switch sequence - for bypass, LDO override reset *must*
286 * be performed *after* switch to bypass else VBB glitches.
288 if (abb
->ldo_base
&& info
->opp_sel
== TI_ABB_NOMINAL_OPP
)
289 ti_abb_program_ldovbb(dev
, abb
, info
);
296 * ti_abb_set_voltage_sel() - regulator accessor function to set ABB LDO
297 * @rdev: regulator device
298 * @sel: selector to index into required ABB LDO settings (maps to
299 * regulator descriptor's volt_table)
301 * Return: 0 on success or appropriate error value when fails
303 static int ti_abb_set_voltage_sel(struct regulator_dev
*rdev
, unsigned int sel
)
305 const struct regulator_desc
*desc
= rdev
->desc
;
306 struct ti_abb
*abb
= rdev_get_drvdata(rdev
);
307 struct device
*dev
= &rdev
->dev
;
308 struct ti_abb_info
*info
, *oinfo
;
312 dev_err_ratelimited(dev
, "%s: No regulator drvdata\n",
317 if (!desc
->n_voltages
|| !abb
->info
) {
318 dev_err_ratelimited(dev
,
319 "%s: No valid voltage table entries?\n",
324 if (sel
>= desc
->n_voltages
) {
325 dev_err(dev
, "%s: sel idx(%d) >= n_voltages(%d)\n", __func__
,
326 sel
, desc
->n_voltages
);
330 /* If we are in the same index as we were, nothing to do here! */
331 if (sel
== abb
->current_info_idx
) {
332 dev_dbg(dev
, "%s: Already at sel=%d\n", __func__
, sel
);
336 info
= &abb
->info
[sel
];
338 * When Linux kernel is starting up, we aren't sure of the
339 * Bias configuration that bootloader has configured.
340 * So, we get to know the actual setting the first time
341 * we are asked to transition.
343 if (abb
->current_info_idx
== -EINVAL
)
346 /* If data is exactly the same, then just update index, no change */
347 oinfo
= &abb
->info
[abb
->current_info_idx
];
348 if (!memcmp(info
, oinfo
, sizeof(*info
))) {
349 dev_dbg(dev
, "%s: Same data new idx=%d, old idx=%d\n", __func__
,
350 sel
, abb
->current_info_idx
);
355 ret
= ti_abb_set_opp(rdev
, abb
, info
);
359 abb
->current_info_idx
= sel
;
361 dev_err_ratelimited(dev
,
362 "%s: Volt[%d] idx[%d] mode[%d] Fail(%d)\n",
363 __func__
, desc
->volt_table
[sel
], sel
,
369 * ti_abb_get_voltage_sel() - Regulator accessor to get current ABB LDO setting
370 * @rdev: regulator device
372 * Return: 0 on success or appropriate error value when fails
374 static int ti_abb_get_voltage_sel(struct regulator_dev
*rdev
)
376 const struct regulator_desc
*desc
= rdev
->desc
;
377 struct ti_abb
*abb
= rdev_get_drvdata(rdev
);
378 struct device
*dev
= &rdev
->dev
;
381 dev_err_ratelimited(dev
, "%s: No regulator drvdata\n",
386 if (!desc
->n_voltages
|| !abb
->info
) {
387 dev_err_ratelimited(dev
,
388 "%s: No valid voltage table entries?\n",
393 if (abb
->current_info_idx
>= (int)desc
->n_voltages
) {
394 dev_err(dev
, "%s: Corrupted data? idx(%d) >= n_voltages(%d)\n",
395 __func__
, abb
->current_info_idx
, desc
->n_voltages
);
399 return abb
->current_info_idx
;
403 * ti_abb_init_timings() - setup ABB clock timing for the current platform
405 * @abb: pointer to the abb instance
407 * Return: 0 if timing is updated, else returns error result.
409 static int ti_abb_init_timings(struct device
*dev
, struct ti_abb
*abb
)
412 u32 clk_rate
, sr2_wt_cnt_val
, cycle_rate
;
413 const struct ti_abb_reg
*regs
= abb
->regs
;
415 char *pname
= "ti,settling-time";
417 /* read device tree properties */
418 ret
= of_property_read_u32(dev
->of_node
, pname
, &abb
->settling_time
);
420 dev_err(dev
, "Unable to get property '%s'(%d)\n", pname
, ret
);
424 /* ABB LDO cannot be settle in 0 time */
425 if (!abb
->settling_time
) {
426 dev_err(dev
, "Invalid property:'%s' set as 0!\n", pname
);
430 pname
= "ti,clock-cycles";
431 ret
= of_property_read_u32(dev
->of_node
, pname
, &clock_cycles
);
433 dev_err(dev
, "Unable to get property '%s'(%d)\n", pname
, ret
);
436 /* ABB LDO cannot be settle in 0 clock cycles */
438 dev_err(dev
, "Invalid property:'%s' set as 0!\n", pname
);
442 abb
->clk
= devm_clk_get(dev
, NULL
);
443 if (IS_ERR(abb
->clk
)) {
444 ret
= PTR_ERR(abb
->clk
);
445 dev_err(dev
, "%s: Unable to get clk(%d)\n", __func__
, ret
);
450 * SR2_WTCNT_VALUE is the settling time for the ABB ldo after a
451 * transition and must be programmed with the correct time at boot.
452 * The value programmed into the register is the number of SYS_CLK
453 * clock cycles that match a given wall time profiled for the ldo.
454 * This value depends on:
455 * settling time of ldo in micro-seconds (varies per OMAP family)
456 * # of clock cycles per SYS_CLK period (varies per OMAP family)
457 * the SYS_CLK frequency in MHz (varies per board)
460 * ldo settling time (in micro-seconds)
461 * SR2_WTCNT_VALUE = ------------------------------------------
462 * (# system clock cycles) * (sys_clk period)
466 * SR2_WTCNT_VALUE = settling time / (# SYS_CLK cycles / SYS_CLK rate))
468 * To avoid dividing by zero multiply both "# clock cycles" and
469 * "settling time" by 10 such that the final result is the one we want.
472 /* Convert SYS_CLK rate to MHz & prevent divide by zero */
473 clk_rate
= DIV_ROUND_CLOSEST(clk_get_rate(abb
->clk
), 1000000);
475 /* Calculate cycle rate */
476 cycle_rate
= DIV_ROUND_CLOSEST(clock_cycles
* 10, clk_rate
);
478 /* Calculate SR2_WTCNT_VALUE */
479 sr2_wt_cnt_val
= DIV_ROUND_CLOSEST(abb
->settling_time
* 10, cycle_rate
);
481 dev_dbg(dev
, "%s: Clk_rate=%ld, sr2_cnt=0x%08x\n", __func__
,
482 clk_get_rate(abb
->clk
), sr2_wt_cnt_val
);
484 ti_abb_rmw(regs
->sr2_wtcnt_value_mask
, sr2_wt_cnt_val
, abb
->setup_reg
);
490 * ti_abb_init_table() - Initialize ABB table from device tree
492 * @abb: pointer to the abb instance
493 * @rinit_data: regulator initdata
495 * Return: 0 on success or appropriate error value when fails
497 static int ti_abb_init_table(struct device
*dev
, struct ti_abb
*abb
,
498 struct regulator_init_data
*rinit_data
)
500 struct ti_abb_info
*info
;
501 const u32 num_values
= 6;
502 char *pname
= "ti,abb_info";
504 unsigned int *volt_table
;
505 int num_entries
, min_uV
= INT_MAX
, max_uV
= 0;
506 struct regulation_constraints
*c
= &rinit_data
->constraints
;
509 * Each abb_info is a set of n-tuple, where n is num_values, consisting
510 * of voltage and a set of detection logic for ABB information for that
513 num_entries
= of_property_count_u32_elems(dev
->of_node
, pname
);
514 if (num_entries
< 0) {
515 dev_err(dev
, "No '%s' property?\n", pname
);
519 if (!num_entries
|| (num_entries
% num_values
)) {
520 dev_err(dev
, "All '%s' list entries need %d vals\n", pname
,
524 num_entries
/= num_values
;
526 info
= devm_kcalloc(dev
, num_entries
, sizeof(*info
), GFP_KERNEL
);
532 volt_table
= devm_kcalloc(dev
, num_entries
, sizeof(unsigned int),
537 abb
->rdesc
.n_voltages
= num_entries
;
538 abb
->rdesc
.volt_table
= volt_table
;
539 /* We do not know where the OPP voltage is at the moment */
540 abb
->current_info_idx
= -EINVAL
;
542 for (i
= 0; i
< num_entries
; i
++, info
++, volt_table
++) {
543 u32 efuse_offset
, rbb_mask
, fbb_mask
, vset_mask
;
546 /* NOTE: num_values should equal to entries picked up here */
547 of_property_read_u32_index(dev
->of_node
, pname
, i
* num_values
,
549 of_property_read_u32_index(dev
->of_node
, pname
,
550 i
* num_values
+ 1, &info
->opp_sel
);
551 of_property_read_u32_index(dev
->of_node
, pname
,
552 i
* num_values
+ 2, &efuse_offset
);
553 of_property_read_u32_index(dev
->of_node
, pname
,
554 i
* num_values
+ 3, &rbb_mask
);
555 of_property_read_u32_index(dev
->of_node
, pname
,
556 i
* num_values
+ 4, &fbb_mask
);
557 of_property_read_u32_index(dev
->of_node
, pname
,
558 i
* num_values
+ 5, &vset_mask
);
561 "[%d]v=%d ABB=%d ef=0x%x rbb=0x%x fbb=0x%x vset=0x%x\n",
562 i
, *volt_table
, info
->opp_sel
, efuse_offset
, rbb_mask
,
563 fbb_mask
, vset_mask
);
565 /* Find min/max for voltage set */
566 if (min_uV
> *volt_table
)
567 min_uV
= *volt_table
;
568 if (max_uV
< *volt_table
)
569 max_uV
= *volt_table
;
571 if (!abb
->efuse_base
) {
572 /* Ignore invalid data, but warn to help cleanup */
573 if (efuse_offset
|| rbb_mask
|| fbb_mask
|| vset_mask
)
574 dev_err(dev
, "prop '%s': v=%d,bad efuse/mask\n",
579 efuse_val
= readl(abb
->efuse_base
+ efuse_offset
);
581 /* Use ABB recommendation from Efuse */
582 if (efuse_val
& rbb_mask
)
583 info
->opp_sel
= TI_ABB_SLOW_OPP
;
584 else if (efuse_val
& fbb_mask
)
585 info
->opp_sel
= TI_ABB_FAST_OPP
;
586 else if (rbb_mask
|| fbb_mask
)
587 info
->opp_sel
= TI_ABB_NOMINAL_OPP
;
590 "[%d]v=%d efusev=0x%x final ABB=%d\n",
591 i
, *volt_table
, efuse_val
, info
->opp_sel
);
593 /* Use recommended Vset bits from Efuse */
594 if (!abb
->ldo_base
) {
596 dev_err(dev
, "prop'%s':v=%d vst=%x LDO base?\n",
597 pname
, *volt_table
, vset_mask
);
600 info
->vset
= (efuse_val
& vset_mask
) >> __ffs(vset_mask
);
601 dev_dbg(dev
, "[%d]v=%d vset=%x\n", i
, *volt_table
, info
->vset
);
603 switch (info
->opp_sel
) {
604 case TI_ABB_NOMINAL_OPP
:
605 case TI_ABB_FAST_OPP
:
606 case TI_ABB_SLOW_OPP
:
610 dev_err(dev
, "%s:[%d]v=%d, ABB=%d is invalid! Abort!\n",
611 __func__
, i
, *volt_table
, info
->opp_sel
);
616 /* Setup the min/max voltage constraints from the supported list */
623 static const struct regulator_ops ti_abb_reg_ops
= {
624 .list_voltage
= regulator_list_voltage_table
,
626 .set_voltage_sel
= ti_abb_set_voltage_sel
,
627 .get_voltage_sel
= ti_abb_get_voltage_sel
,
630 /* Default ABB block offsets, IF this changes in future, create new one */
631 static const struct ti_abb_reg abb_regs_v1
= {
632 /* WARNING: registers are wrongly documented in TRM */
636 .sr2_wtcnt_value_mask
= (0xff << 8),
637 .fbb_sel_mask
= (0x01 << 2),
638 .rbb_sel_mask
= (0x01 << 1),
639 .sr2_en_mask
= (0x01 << 0),
641 .opp_change_mask
= (0x01 << 2),
642 .opp_sel_mask
= (0x03 << 0),
645 static const struct ti_abb_reg abb_regs_v2
= {
649 .sr2_wtcnt_value_mask
= (0xff << 8),
650 .fbb_sel_mask
= (0x01 << 2),
651 .rbb_sel_mask
= (0x01 << 1),
652 .sr2_en_mask
= (0x01 << 0),
654 .opp_change_mask
= (0x01 << 2),
655 .opp_sel_mask
= (0x03 << 0),
658 static const struct ti_abb_reg abb_regs_generic
= {
659 .sr2_wtcnt_value_mask
= (0xff << 8),
660 .fbb_sel_mask
= (0x01 << 2),
661 .rbb_sel_mask
= (0x01 << 1),
662 .sr2_en_mask
= (0x01 << 0),
664 .opp_change_mask
= (0x01 << 2),
665 .opp_sel_mask
= (0x03 << 0),
668 static const struct of_device_id ti_abb_of_match
[] = {
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
},
675 MODULE_DEVICE_TABLE(of
, ti_abb_of_match
);
678 * ti_abb_probe() - Initialize an ABB ldo instance
679 * @pdev: ABB platform device
681 * Initializes an individual ABB LDO for required Body-Bias. ABB is used to
682 * additional bias supply to SoC modules for power savings or mandatory stability
683 * configuration at certain Operating Performance Points(OPPs).
685 * Return: 0 on success or appropriate error value when fails
687 static int ti_abb_probe(struct platform_device
*pdev
)
689 struct device
*dev
= &pdev
->dev
;
690 struct resource
*res
;
692 struct regulator_init_data
*initdata
= NULL
;
693 struct regulator_dev
*rdev
= NULL
;
694 struct regulator_desc
*desc
;
695 struct regulation_constraints
*c
;
696 struct regulator_config config
= { };
700 abb
= devm_kzalloc(dev
, sizeof(struct ti_abb
), GFP_KERNEL
);
704 abb
->regs
= device_get_match_data(dev
);
706 dev_err(dev
, "%s: Bad data in match\n", __func__
);
710 /* Map ABB resources */
711 if (abb
->regs
->setup_off
|| abb
->regs
->control_off
) {
712 abb
->base
= devm_platform_ioremap_resource_byname(pdev
, "base-address");
713 if (IS_ERR(abb
->base
))
714 return PTR_ERR(abb
->base
);
716 abb
->setup_reg
= abb
->base
+ abb
->regs
->setup_off
;
717 abb
->control_reg
= abb
->base
+ abb
->regs
->control_off
;
720 abb
->control_reg
= devm_platform_ioremap_resource_byname(pdev
, "control-address");
721 if (IS_ERR(abb
->control_reg
))
722 return PTR_ERR(abb
->control_reg
);
724 abb
->setup_reg
= devm_platform_ioremap_resource_byname(pdev
, "setup-address");
725 if (IS_ERR(abb
->setup_reg
))
726 return PTR_ERR(abb
->setup_reg
);
729 pname
= "int-address";
730 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, pname
);
732 dev_err(dev
, "Missing '%s' IO resource\n", pname
);
736 * The MPU interrupt status register (PRM_IRQSTATUS_MPU) is
737 * shared between regulator-abb-{ivahd,dspeve,gpu} driver
738 * instances. Therefore use devm_ioremap() rather than
739 * devm_platform_ioremap_resource_byname() to avoid busy
740 * resource region conflicts.
742 abb
->int_base
= devm_ioremap(dev
, res
->start
,
744 if (!abb
->int_base
) {
745 dev_err(dev
, "Unable to map '%s'\n", pname
);
749 /* Map Optional resources */
750 pname
= "efuse-address";
751 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, pname
);
753 dev_dbg(dev
, "Missing '%s' IO resource\n", pname
);
759 * We may have shared efuse register offsets which are read-only
762 abb
->efuse_base
= devm_ioremap(dev
, res
->start
,
764 if (!abb
->efuse_base
) {
765 dev_err(dev
, "Unable to map '%s'\n", pname
);
769 pname
= "ldo-address";
770 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, pname
);
772 dev_dbg(dev
, "Missing '%s' IO resource\n", pname
);
776 abb
->ldo_base
= devm_ioremap_resource(dev
, res
);
777 if (IS_ERR(abb
->ldo_base
))
778 return PTR_ERR(abb
->ldo_base
);
780 /* IF ldo_base is set, the following are mandatory */
781 pname
= "ti,ldovbb-override-mask";
783 of_property_read_u32(pdev
->dev
.of_node
, pname
,
784 &abb
->ldovbb_override_mask
);
786 dev_err(dev
, "Missing '%s' (%d)\n", pname
, ret
);
789 if (!abb
->ldovbb_override_mask
) {
790 dev_err(dev
, "Invalid property:'%s' set as 0!\n", pname
);
794 pname
= "ti,ldovbb-vset-mask";
796 of_property_read_u32(pdev
->dev
.of_node
, pname
,
797 &abb
->ldovbb_vset_mask
);
799 dev_err(dev
, "Missing '%s' (%d)\n", pname
, ret
);
802 if (!abb
->ldovbb_vset_mask
) {
803 dev_err(dev
, "Invalid property:'%s' set as 0!\n", pname
);
808 pname
= "ti,tranxdone-status-mask";
810 of_property_read_u32(pdev
->dev
.of_node
, pname
,
813 dev_err(dev
, "Missing '%s' (%d)\n", pname
, ret
);
816 if (!abb
->txdone_mask
) {
817 dev_err(dev
, "Invalid property:'%s' set as 0!\n", pname
);
821 initdata
= of_get_regulator_init_data(dev
, pdev
->dev
.of_node
,
824 dev_err(dev
, "%s: Unable to alloc regulator init data\n",
829 /* init ABB opp_sel table */
830 ret
= ti_abb_init_table(dev
, abb
, initdata
);
834 /* init ABB timing */
835 ret
= ti_abb_init_timings(dev
, abb
);
840 desc
->name
= dev_name(dev
);
841 desc
->owner
= THIS_MODULE
;
842 desc
->type
= REGULATOR_VOLTAGE
;
843 desc
->ops
= &ti_abb_reg_ops
;
845 c
= &initdata
->constraints
;
846 if (desc
->n_voltages
> 1)
847 c
->valid_ops_mask
|= REGULATOR_CHANGE_VOLTAGE
;
851 config
.init_data
= initdata
;
852 config
.driver_data
= abb
;
853 config
.of_node
= pdev
->dev
.of_node
;
855 rdev
= devm_regulator_register(dev
, desc
, &config
);
858 dev_err(dev
, "%s: failed to register regulator(%d)\n",
862 platform_set_drvdata(pdev
, rdev
);
864 /* Enable the ldo if not already done by bootloader */
865 ti_abb_rmw(abb
->regs
->sr2_en_mask
, 1, abb
->setup_reg
);
870 MODULE_ALIAS("platform:ti_abb");
872 static struct platform_driver ti_abb_driver
= {
873 .probe
= ti_abb_probe
,
876 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
877 .of_match_table
= ti_abb_of_match
,
880 module_platform_driver(ti_abb_driver
);
882 MODULE_DESCRIPTION("Texas Instruments ABB LDO regulator driver");
883 MODULE_AUTHOR("Texas Instruments Inc.");
884 MODULE_LICENSE("GPL v2");