vp.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. #include <linux/kernel.h>
  2. #include <linux/init.h>
  3. #include "common.h"
  4. #include "voltage.h"
  5. #include "vp.h"
  6. #include "prm-regbits-34xx.h"
  7. #include "prm-regbits-44xx.h"
  8. #include "prm44xx.h"
  9. static u32 _vp_set_init_voltage(struct voltagedomain *voltdm, u32 volt)
  10. {
  11. struct omap_vp_instance *vp = voltdm->vp;
  12. u32 vpconfig;
  13. char vsel;
  14. vsel = voltdm->pmic->uv_to_vsel(volt);
  15. vpconfig = voltdm->read(vp->vpconfig);
  16. vpconfig &= ~(vp->common->vpconfig_initvoltage_mask |
  17. vp->common->vpconfig_forceupdate |
  18. vp->common->vpconfig_initvdd);
  19. vpconfig |= vsel << __ffs(vp->common->vpconfig_initvoltage_mask);
  20. voltdm->write(vpconfig, vp->vpconfig);
  21. /* Trigger initVDD value copy to voltage processor */
  22. voltdm->write((vpconfig | vp->common->vpconfig_initvdd),
  23. vp->vpconfig);
  24. /* Clear initVDD copy trigger bit */
  25. voltdm->write(vpconfig, vp->vpconfig);
  26. return vpconfig;
  27. }
  28. /* Generic voltage init functions */
  29. void __init omap_vp_init(struct voltagedomain *voltdm)
  30. {
  31. struct omap_vp_instance *vp = voltdm->vp;
  32. u32 val, sys_clk_rate, timeout, waittime;
  33. u32 vddmin, vddmax, vstepmin, vstepmax;
  34. if (!voltdm->pmic || !voltdm->pmic->uv_to_vsel) {
  35. pr_err("%s: No PMIC info for vdd_%s\n", __func__, voltdm->name);
  36. return;
  37. }
  38. if (!voltdm->read || !voltdm->write) {
  39. pr_err("%s: No read/write API for accessing vdd_%s regs\n",
  40. __func__, voltdm->name);
  41. return;
  42. }
  43. vp->enabled = false;
  44. /* Divide to avoid overflow */
  45. sys_clk_rate = voltdm->sys_clk.rate / 1000;
  46. timeout = (sys_clk_rate * voltdm->pmic->vp_timeout_us) / 1000;
  47. vddmin = max(voltdm->vp_param->vddmin, voltdm->pmic->vddmin);
  48. vddmax = min(voltdm->vp_param->vddmax, voltdm->pmic->vddmax);
  49. vddmin = voltdm->pmic->uv_to_vsel(vddmin);
  50. vddmax = voltdm->pmic->uv_to_vsel(vddmax);
  51. waittime = DIV_ROUND_UP(voltdm->pmic->step_size * sys_clk_rate,
  52. 1000 * voltdm->pmic->slew_rate);
  53. vstepmin = voltdm->pmic->vp_vstepmin;
  54. vstepmax = voltdm->pmic->vp_vstepmax;
  55. /*
  56. * VP_CONFIG: error gain is not set here, it will be updated
  57. * on each scale, based on OPP.
  58. */
  59. val = (voltdm->pmic->vp_erroroffset <<
  60. __ffs(voltdm->vp->common->vpconfig_erroroffset_mask)) |
  61. vp->common->vpconfig_timeouten;
  62. voltdm->write(val, vp->vpconfig);
  63. /* VSTEPMIN */
  64. val = (waittime << vp->common->vstepmin_smpswaittimemin_shift) |
  65. (vstepmin << vp->common->vstepmin_stepmin_shift);
  66. voltdm->write(val, vp->vstepmin);
  67. /* VSTEPMAX */
  68. val = (vstepmax << vp->common->vstepmax_stepmax_shift) |
  69. (waittime << vp->common->vstepmax_smpswaittimemax_shift);
  70. voltdm->write(val, vp->vstepmax);
  71. /* VLIMITTO */
  72. val = (vddmax << vp->common->vlimitto_vddmax_shift) |
  73. (vddmin << vp->common->vlimitto_vddmin_shift) |
  74. (timeout << vp->common->vlimitto_timeout_shift);
  75. voltdm->write(val, vp->vlimitto);
  76. }
  77. int omap_vp_update_errorgain(struct voltagedomain *voltdm,
  78. unsigned long target_volt)
  79. {
  80. struct omap_volt_data *volt_data;
  81. if (!voltdm->vp)
  82. return -EINVAL;
  83. /* Get volt_data corresponding to target_volt */
  84. volt_data = omap_voltage_get_voltdata(voltdm, target_volt);
  85. if (IS_ERR(volt_data))
  86. return -EINVAL;
  87. /* Setting vp errorgain based on the voltage */
  88. voltdm->rmw(voltdm->vp->common->vpconfig_errorgain_mask,
  89. volt_data->vp_errgain <<
  90. __ffs(voltdm->vp->common->vpconfig_errorgain_mask),
  91. voltdm->vp->vpconfig);
  92. return 0;
  93. }
  94. /* VP force update method of voltage scaling */
  95. int omap_vp_forceupdate_scale(struct voltagedomain *voltdm,
  96. unsigned long target_volt)
  97. {
  98. struct omap_vp_instance *vp = voltdm->vp;
  99. u32 vpconfig;
  100. u8 target_vsel, current_vsel;
  101. int ret, timeout = 0;
  102. ret = omap_vc_pre_scale(voltdm, target_volt, &target_vsel, &current_vsel);
  103. if (ret)
  104. return ret;
  105. /*
  106. * Clear all pending TransactionDone interrupt/status. Typical latency
  107. * is <3us
  108. */
  109. while (timeout++ < VP_TRANXDONE_TIMEOUT) {
  110. vp->common->ops->clear_txdone(vp->id);
  111. if (!vp->common->ops->check_txdone(vp->id))
  112. break;
  113. udelay(1);
  114. }
  115. if (timeout >= VP_TRANXDONE_TIMEOUT) {
  116. pr_warn("%s: vdd_%s TRANXDONE timeout exceeded. Voltage change aborted\n",
  117. __func__, voltdm->name);
  118. return -ETIMEDOUT;
  119. }
  120. vpconfig = _vp_set_init_voltage(voltdm, target_volt);
  121. /* Force update of voltage */
  122. voltdm->write(vpconfig | vp->common->vpconfig_forceupdate,
  123. voltdm->vp->vpconfig);
  124. /*
  125. * Wait for TransactionDone. Typical latency is <200us.
  126. * Depends on SMPSWAITTIMEMIN/MAX and voltage change
  127. */
  128. timeout = 0;
  129. omap_test_timeout(vp->common->ops->check_txdone(vp->id),
  130. VP_TRANXDONE_TIMEOUT, timeout);
  131. if (timeout >= VP_TRANXDONE_TIMEOUT)
  132. pr_err("%s: vdd_%s TRANXDONE timeout exceeded. TRANXDONE never got set after the voltage update\n",
  133. __func__, voltdm->name);
  134. omap_vc_post_scale(voltdm, target_volt, target_vsel, current_vsel);
  135. /*
  136. * Disable TransactionDone interrupt , clear all status, clear
  137. * control registers
  138. */
  139. timeout = 0;
  140. while (timeout++ < VP_TRANXDONE_TIMEOUT) {
  141. vp->common->ops->clear_txdone(vp->id);
  142. if (!vp->common->ops->check_txdone(vp->id))
  143. break;
  144. udelay(1);
  145. }
  146. if (timeout >= VP_TRANXDONE_TIMEOUT)
  147. pr_warn("%s: vdd_%s TRANXDONE timeout exceeded while trying to clear the TRANXDONE status\n",
  148. __func__, voltdm->name);
  149. /* Clear force bit */
  150. voltdm->write(vpconfig, vp->vpconfig);
  151. return 0;
  152. }
  153. /**
  154. * omap_vp_enable() - API to enable a particular VP
  155. * @voltdm: pointer to the VDD whose VP is to be enabled.
  156. *
  157. * This API enables a particular voltage processor. Needed by the smartreflex
  158. * class drivers.
  159. */
  160. void omap_vp_enable(struct voltagedomain *voltdm)
  161. {
  162. struct omap_vp_instance *vp;
  163. u32 vpconfig, volt;
  164. if (!voltdm || IS_ERR(voltdm)) {
  165. pr_warn("%s: VDD specified does not exist!\n", __func__);
  166. return;
  167. }
  168. vp = voltdm->vp;
  169. if (!voltdm->read || !voltdm->write) {
  170. pr_err("%s: No read/write API for accessing vdd_%s regs\n",
  171. __func__, voltdm->name);
  172. return;
  173. }
  174. /* If VP is already enabled, do nothing. Return */
  175. if (vp->enabled)
  176. return;
  177. volt = voltdm_get_voltage(voltdm);
  178. if (!volt) {
  179. pr_warn("%s: unable to find current voltage for %s\n",
  180. __func__, voltdm->name);
  181. return;
  182. }
  183. vpconfig = _vp_set_init_voltage(voltdm, volt);
  184. /* Enable VP */
  185. vpconfig |= vp->common->vpconfig_vpenable;
  186. voltdm->write(vpconfig, vp->vpconfig);
  187. vp->enabled = true;
  188. }
  189. /**
  190. * omap_vp_disable() - API to disable a particular VP
  191. * @voltdm: pointer to the VDD whose VP is to be disabled.
  192. *
  193. * This API disables a particular voltage processor. Needed by the smartreflex
  194. * class drivers.
  195. */
  196. void omap_vp_disable(struct voltagedomain *voltdm)
  197. {
  198. struct omap_vp_instance *vp;
  199. u32 vpconfig;
  200. int timeout;
  201. if (!voltdm || IS_ERR(voltdm)) {
  202. pr_warn("%s: VDD specified does not exist!\n", __func__);
  203. return;
  204. }
  205. vp = voltdm->vp;
  206. if (!voltdm->read || !voltdm->write) {
  207. pr_err("%s: No read/write API for accessing vdd_%s regs\n",
  208. __func__, voltdm->name);
  209. return;
  210. }
  211. /* If VP is already disabled, do nothing. Return */
  212. if (!vp->enabled) {
  213. pr_warn("%s: Trying to disable VP for vdd_%s when it is already disabled\n",
  214. __func__, voltdm->name);
  215. return;
  216. }
  217. /* Disable VP */
  218. vpconfig = voltdm->read(vp->vpconfig);
  219. vpconfig &= ~vp->common->vpconfig_vpenable;
  220. voltdm->write(vpconfig, vp->vpconfig);
  221. /*
  222. * Wait for VP idle Typical latency is <2us. Maximum latency is ~100us
  223. */
  224. omap_test_timeout((voltdm->read(vp->vstatus)),
  225. VP_IDLE_TIMEOUT, timeout);
  226. if (timeout >= VP_IDLE_TIMEOUT)
  227. pr_warn("%s: vdd_%s idle timedout\n", __func__, voltdm->name);
  228. vp->enabled = false;
  229. return;
  230. }