1 // SPDX-License-Identifier: GPL-2.0+
3 * Adaptive Body Bias programming sequence for OMAP family
6 * Texas Instruments, <www.ti.com>
11 #include <asm/omap_common.h>
12 #include <asm/arch/clock.h>
14 #include <asm/arch/sys_proto.h>
15 #include <linux/bitops.h>
17 __weak s8 abb_setup_ldovbb(u32 fuse, u32 ldovbb)
22 static void abb_setup_timings(u32 setup)
24 u32 sys_rate, sr2_cnt, clk_cycles;
27 * SR2_WTCNT_VALUE is the settling time for the ABB ldo after a
28 * transition and must be programmed with the correct time at boot.
29 * The value programmed into the register is the number of SYS_CLK
30 * clock cycles that match a given wall time profiled for the ldo.
31 * This value depends on:
32 * settling time of ldo in micro-seconds (varies per OMAP family),
33 * of clock cycles per SYS_CLK period (varies per OMAP family),
34 * the SYS_CLK frequency in MHz (varies per board)
37 * ldo settling time (in micro-seconds)
38 * SR2_WTCNT_VALUE = ------------------------------------------
39 * (# system clock cycles) * (sys_clk period)
43 * SR2_WTCNT_VALUE = settling time / (# SYS_CLK cycles / SYS_CLK rate))
45 * To avoid dividing by zero multiply both "# clock cycles" and
46 * "settling time" by 10 such that the final result is the one we want.
49 /* calculate SR2_WTCNT_VALUE */
50 sys_rate = DIV_ROUND_CLOSEST(V_OSCK, 1000000);
51 clk_cycles = DIV_ROUND_CLOSEST(OMAP_ABB_CLOCK_CYCLES * 10, sys_rate);
52 sr2_cnt = DIV_ROUND_CLOSEST(OMAP_ABB_SETTLING_TIME * 10, clk_cycles);
55 sr2_cnt << (ffs(OMAP_ABB_SETUP_SR2_WTCNT_VALUE_MASK) - 1));
58 void abb_setup(u32 fuse, u32 ldovbb, u32 setup, u32 control,
59 u32 txdone, u32 txdone_mask, u32 opp)
61 u32 abb_type_mask, opp_sel_mask;
64 if (!setup || !control || !txdone)
67 /* setup ABB only in case of Fast or Slow OPP */
69 case OMAP_ABB_FAST_OPP:
70 abb_type_mask = OMAP_ABB_SETUP_ACTIVE_FBB_SEL_MASK;
71 opp_sel_mask = OMAP_ABB_CONTROL_FAST_OPP_SEL_MASK;
73 case OMAP_ABB_SLOW_OPP:
74 abb_type_mask = OMAP_ABB_SETUP_ACTIVE_RBB_SEL_MASK;
75 opp_sel_mask = OMAP_ABB_CONTROL_SLOW_OPP_SEL_MASK;
82 * For some OMAP silicons additional setup for LDOVBB register is
83 * required. This is determined by data retrieved from corresponding
84 * OPP EFUSE register. Data, which is retrieved from EFUSE - is
85 * ABB enable/disable flag and VSET value, which must be copied
86 * to LDOVBB register. If function call fails - return quietly,
87 * it means no ABB is required for such silicon.
89 * For silicons, which don't require LDOVBB setup "fuse" and
90 * "ldovbb" offsets are not defined. ABB will be initialized in
91 * the common way for them.
94 if (abb_setup_ldovbb(fuse, ldovbb))
98 /* clear ABB registers */
102 /* configure timings, based on oscillator value */
103 abb_setup_timings(setup);
105 /* clear pending interrupts before setup */
106 setbits_le32(txdone, txdone_mask);
108 /* select ABB type */
109 setbits_le32(setup, abb_type_mask | OMAP_ABB_SETUP_SR2EN_MASK);
111 /* initiate ABB ldo change */
112 setbits_le32(control, opp_sel_mask | OMAP_ABB_CONTROL_OPP_CHANGE_MASK);
114 /* wait until transition complete */
115 if (!wait_on_value(txdone_mask, txdone_mask, (void *)txdone, LDELAY))
116 puts("Error: ABB txdone is not set\n");
118 /* clear ABB tranxdone */
119 setbits_le32(txdone, txdone_mask);