abb.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Adaptive Body Bias programming sequence for OMAP family
  4. *
  5. * (C) Copyright 2013
  6. * Texas Instruments, <www.ti.com>
  7. *
  8. * Andrii Tseglytskyi <andrii.tseglytskyi@ti.com>
  9. */
  10. #include <common.h>
  11. #include <asm/omap_common.h>
  12. #include <asm/arch/clock.h>
  13. #include <asm/io.h>
  14. #include <asm/arch/sys_proto.h>
  15. __weak s8 abb_setup_ldovbb(u32 fuse, u32 ldovbb)
  16. {
  17. return -1;
  18. }
  19. static void abb_setup_timings(u32 setup)
  20. {
  21. u32 sys_rate, sr2_cnt, clk_cycles;
  22. /*
  23. * SR2_WTCNT_VALUE is the settling time for the ABB ldo after a
  24. * transition and must be programmed with the correct time at boot.
  25. * The value programmed into the register is the number of SYS_CLK
  26. * clock cycles that match a given wall time profiled for the ldo.
  27. * This value depends on:
  28. * settling time of ldo in micro-seconds (varies per OMAP family),
  29. * of clock cycles per SYS_CLK period (varies per OMAP family),
  30. * the SYS_CLK frequency in MHz (varies per board)
  31. * The formula is:
  32. *
  33. * ldo settling time (in micro-seconds)
  34. * SR2_WTCNT_VALUE = ------------------------------------------
  35. * (# system clock cycles) * (sys_clk period)
  36. *
  37. * Put another way:
  38. *
  39. * SR2_WTCNT_VALUE = settling time / (# SYS_CLK cycles / SYS_CLK rate))
  40. *
  41. * To avoid dividing by zero multiply both "# clock cycles" and
  42. * "settling time" by 10 such that the final result is the one we want.
  43. */
  44. /* calculate SR2_WTCNT_VALUE */
  45. sys_rate = DIV_ROUND_CLOSEST(V_OSCK, 1000000);
  46. clk_cycles = DIV_ROUND_CLOSEST(OMAP_ABB_CLOCK_CYCLES * 10, sys_rate);
  47. sr2_cnt = DIV_ROUND_CLOSEST(OMAP_ABB_SETTLING_TIME * 10, clk_cycles);
  48. setbits_le32(setup,
  49. sr2_cnt << (ffs(OMAP_ABB_SETUP_SR2_WTCNT_VALUE_MASK) - 1));
  50. }
  51. void abb_setup(u32 fuse, u32 ldovbb, u32 setup, u32 control,
  52. u32 txdone, u32 txdone_mask, u32 opp)
  53. {
  54. u32 abb_type_mask, opp_sel_mask;
  55. /* sanity check */
  56. if (!setup || !control || !txdone)
  57. return;
  58. /* setup ABB only in case of Fast or Slow OPP */
  59. switch (opp) {
  60. case OMAP_ABB_FAST_OPP:
  61. abb_type_mask = OMAP_ABB_SETUP_ACTIVE_FBB_SEL_MASK;
  62. opp_sel_mask = OMAP_ABB_CONTROL_FAST_OPP_SEL_MASK;
  63. break;
  64. case OMAP_ABB_SLOW_OPP:
  65. abb_type_mask = OMAP_ABB_SETUP_ACTIVE_RBB_SEL_MASK;
  66. opp_sel_mask = OMAP_ABB_CONTROL_SLOW_OPP_SEL_MASK;
  67. break;
  68. default:
  69. return;
  70. }
  71. /*
  72. * For some OMAP silicons additional setup for LDOVBB register is
  73. * required. This is determined by data retrieved from corresponding
  74. * OPP EFUSE register. Data, which is retrieved from EFUSE - is
  75. * ABB enable/disable flag and VSET value, which must be copied
  76. * to LDOVBB register. If function call fails - return quietly,
  77. * it means no ABB is required for such silicon.
  78. *
  79. * For silicons, which don't require LDOVBB setup "fuse" and
  80. * "ldovbb" offsets are not defined. ABB will be initialized in
  81. * the common way for them.
  82. */
  83. if (fuse && ldovbb) {
  84. if (abb_setup_ldovbb(fuse, ldovbb))
  85. return;
  86. }
  87. /* clear ABB registers */
  88. writel(0, setup);
  89. writel(0, control);
  90. /* configure timings, based on oscillator value */
  91. abb_setup_timings(setup);
  92. /* clear pending interrupts before setup */
  93. setbits_le32(txdone, txdone_mask);
  94. /* select ABB type */
  95. setbits_le32(setup, abb_type_mask | OMAP_ABB_SETUP_SR2EN_MASK);
  96. /* initiate ABB ldo change */
  97. setbits_le32(control, opp_sel_mask | OMAP_ABB_CONTROL_OPP_CHANGE_MASK);
  98. /* wait until transition complete */
  99. if (!wait_on_value(txdone_mask, txdone_mask, (void *)txdone, LDELAY))
  100. puts("Error: ABB txdone is not set\n");
  101. /* clear ABB tranxdone */
  102. setbits_le32(txdone, txdone_mask);
  103. }