1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/kernel.h>
3 #include <linux/init.h>
9 #include "prm-regbits-34xx.h"
10 #include "prm-regbits-44xx.h"
13 static u32
_vp_set_init_voltage(struct voltagedomain
*voltdm
, u32 volt
)
15 struct omap_vp_instance
*vp
= voltdm
->vp
;
19 vsel
= voltdm
->pmic
->uv_to_vsel(volt
);
21 vpconfig
= voltdm
->read(vp
->vpconfig
);
22 vpconfig
&= ~(vp
->common
->vpconfig_initvoltage_mask
|
23 vp
->common
->vpconfig_forceupdate
|
24 vp
->common
->vpconfig_initvdd
);
25 vpconfig
|= vsel
<< __ffs(vp
->common
->vpconfig_initvoltage_mask
);
26 voltdm
->write(vpconfig
, vp
->vpconfig
);
28 /* Trigger initVDD value copy to voltage processor */
29 voltdm
->write((vpconfig
| vp
->common
->vpconfig_initvdd
),
32 /* Clear initVDD copy trigger bit */
33 voltdm
->write(vpconfig
, vp
->vpconfig
);
38 /* Generic voltage init functions */
39 void __init
omap_vp_init(struct voltagedomain
*voltdm
)
41 struct omap_vp_instance
*vp
= voltdm
->vp
;
42 u32 val
, sys_clk_rate
, timeout
, waittime
;
43 u32 vddmin
, vddmax
, vstepmin
, vstepmax
;
45 if (!voltdm
->pmic
|| !voltdm
->pmic
->uv_to_vsel
) {
46 pr_err("%s: No PMIC info for vdd_%s\n", __func__
, voltdm
->name
);
50 if (!voltdm
->read
|| !voltdm
->write
) {
51 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
52 __func__
, voltdm
->name
);
58 /* Divide to avoid overflow */
59 sys_clk_rate
= voltdm
->sys_clk
.rate
/ 1000;
61 timeout
= (sys_clk_rate
* voltdm
->pmic
->vp_timeout_us
) / 1000;
62 vddmin
= max(voltdm
->vp_param
->vddmin
, voltdm
->pmic
->vddmin
);
63 vddmax
= min(voltdm
->vp_param
->vddmax
, voltdm
->pmic
->vddmax
);
64 vddmin
= voltdm
->pmic
->uv_to_vsel(vddmin
);
65 vddmax
= voltdm
->pmic
->uv_to_vsel(vddmax
);
67 waittime
= DIV_ROUND_UP(voltdm
->pmic
->step_size
* sys_clk_rate
,
68 1000 * voltdm
->pmic
->slew_rate
);
69 vstepmin
= voltdm
->pmic
->vp_vstepmin
;
70 vstepmax
= voltdm
->pmic
->vp_vstepmax
;
73 * VP_CONFIG: error gain is not set here, it will be updated
74 * on each scale, based on OPP.
76 val
= (voltdm
->pmic
->vp_erroroffset
<<
77 __ffs(voltdm
->vp
->common
->vpconfig_erroroffset_mask
)) |
78 vp
->common
->vpconfig_timeouten
;
79 voltdm
->write(val
, vp
->vpconfig
);
82 val
= (waittime
<< vp
->common
->vstepmin_smpswaittimemin_shift
) |
83 (vstepmin
<< vp
->common
->vstepmin_stepmin_shift
);
84 voltdm
->write(val
, vp
->vstepmin
);
87 val
= (vstepmax
<< vp
->common
->vstepmax_stepmax_shift
) |
88 (waittime
<< vp
->common
->vstepmax_smpswaittimemax_shift
);
89 voltdm
->write(val
, vp
->vstepmax
);
92 val
= (vddmax
<< vp
->common
->vlimitto_vddmax_shift
) |
93 (vddmin
<< vp
->common
->vlimitto_vddmin_shift
) |
94 (timeout
<< vp
->common
->vlimitto_timeout_shift
);
95 voltdm
->write(val
, vp
->vlimitto
);
98 int omap_vp_update_errorgain(struct voltagedomain
*voltdm
,
99 unsigned long target_volt
)
101 struct omap_volt_data
*volt_data
;
106 /* Get volt_data corresponding to target_volt */
107 volt_data
= omap_voltage_get_voltdata(voltdm
, target_volt
);
108 if (IS_ERR(volt_data
))
111 /* Setting vp errorgain based on the voltage */
112 voltdm
->rmw(voltdm
->vp
->common
->vpconfig_errorgain_mask
,
113 volt_data
->vp_errgain
<<
114 __ffs(voltdm
->vp
->common
->vpconfig_errorgain_mask
),
115 voltdm
->vp
->vpconfig
);
120 /* VP force update method of voltage scaling */
121 int omap_vp_forceupdate_scale(struct voltagedomain
*voltdm
,
122 unsigned long target_volt
)
124 struct omap_vp_instance
*vp
= voltdm
->vp
;
126 u8 target_vsel
, current_vsel
;
127 int ret
, timeout
= 0;
129 ret
= omap_vc_pre_scale(voltdm
, target_volt
, &target_vsel
, ¤t_vsel
);
134 * Clear all pending TransactionDone interrupt/status. Typical latency
137 while (timeout
++ < VP_TRANXDONE_TIMEOUT
) {
138 vp
->common
->ops
->clear_txdone(vp
->id
);
139 if (!vp
->common
->ops
->check_txdone(vp
->id
))
143 if (timeout
>= VP_TRANXDONE_TIMEOUT
) {
144 pr_warn("%s: vdd_%s TRANXDONE timeout exceeded. Voltage change aborted\n",
145 __func__
, voltdm
->name
);
149 vpconfig
= _vp_set_init_voltage(voltdm
, target_volt
);
151 /* Force update of voltage */
152 voltdm
->write(vpconfig
| vp
->common
->vpconfig_forceupdate
,
153 voltdm
->vp
->vpconfig
);
156 * Wait for TransactionDone. Typical latency is <200us.
157 * Depends on SMPSWAITTIMEMIN/MAX and voltage change
160 omap_test_timeout(vp
->common
->ops
->check_txdone(vp
->id
),
161 VP_TRANXDONE_TIMEOUT
, timeout
);
162 if (timeout
>= VP_TRANXDONE_TIMEOUT
)
163 pr_err("%s: vdd_%s TRANXDONE timeout exceeded. TRANXDONE never got set after the voltage update\n",
164 __func__
, voltdm
->name
);
166 omap_vc_post_scale(voltdm
, target_volt
, target_vsel
, current_vsel
);
169 * Disable TransactionDone interrupt , clear all status, clear
173 while (timeout
++ < VP_TRANXDONE_TIMEOUT
) {
174 vp
->common
->ops
->clear_txdone(vp
->id
);
175 if (!vp
->common
->ops
->check_txdone(vp
->id
))
180 if (timeout
>= VP_TRANXDONE_TIMEOUT
)
181 pr_warn("%s: vdd_%s TRANXDONE timeout exceeded while trying to clear the TRANXDONE status\n",
182 __func__
, voltdm
->name
);
184 /* Clear force bit */
185 voltdm
->write(vpconfig
, vp
->vpconfig
);
191 * omap_vp_enable() - API to enable a particular VP
192 * @voltdm: pointer to the VDD whose VP is to be enabled.
194 * This API enables a particular voltage processor. Needed by the smartreflex
197 void omap_vp_enable(struct voltagedomain
*voltdm
)
199 struct omap_vp_instance
*vp
;
202 if (!voltdm
|| IS_ERR(voltdm
)) {
203 pr_warn("%s: VDD specified does not exist!\n", __func__
);
208 if (!voltdm
->read
|| !voltdm
->write
) {
209 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
210 __func__
, voltdm
->name
);
214 /* If VP is already enabled, do nothing. Return */
218 volt
= voltdm_get_voltage(voltdm
);
220 pr_warn("%s: unable to find current voltage for %s\n",
221 __func__
, voltdm
->name
);
225 vpconfig
= _vp_set_init_voltage(voltdm
, volt
);
228 vpconfig
|= vp
->common
->vpconfig_vpenable
;
229 voltdm
->write(vpconfig
, vp
->vpconfig
);
235 * omap_vp_disable() - API to disable a particular VP
236 * @voltdm: pointer to the VDD whose VP is to be disabled.
238 * This API disables a particular voltage processor. Needed by the smartreflex
241 void omap_vp_disable(struct voltagedomain
*voltdm
)
243 struct omap_vp_instance
*vp
;
247 if (!voltdm
|| IS_ERR(voltdm
)) {
248 pr_warn("%s: VDD specified does not exist!\n", __func__
);
253 if (!voltdm
->read
|| !voltdm
->write
) {
254 pr_err("%s: No read/write API for accessing vdd_%s regs\n",
255 __func__
, voltdm
->name
);
259 /* If VP is already disabled, do nothing. Return */
261 pr_warn("%s: Trying to disable VP for vdd_%s when it is already disabled\n",
262 __func__
, voltdm
->name
);
267 vpconfig
= voltdm
->read(vp
->vpconfig
);
268 vpconfig
&= ~vp
->common
->vpconfig_vpenable
;
269 voltdm
->write(vpconfig
, vp
->vpconfig
);
272 * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us
274 omap_test_timeout((voltdm
->read(vp
->vstatus
)),
275 VP_IDLE_TIMEOUT
, timeout
);
277 if (timeout
>= VP_IDLE_TIMEOUT
)
278 pr_warn("%s: vdd_%s idle timedout\n", __func__
, voltdm
->name
);