palmas.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * (C) Copyright 2012-2013
  3. * Texas Instruments, <www.ti.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <config.h>
  8. #include <palmas.h>
  9. void palmas_init_settings(void)
  10. {
  11. #ifdef CONFIG_PALMAS_SMPS7_FPWM
  12. int err;
  13. /*
  14. * Set SMPS7 (1.8 V I/O supply on platforms with TWL6035/37) to
  15. * forced PWM mode. This reduces noise (but affects efficiency).
  16. */
  17. u8 val = SMPS_MODE_SLP_FPWM | SMPS_MODE_ACT_FPWM;
  18. err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS7_CTRL, val);
  19. if (err)
  20. printf("palmas: could not force PWM for SMPS7: err = %d\n",
  21. err);
  22. #endif
  23. }
  24. #if defined(CONFIG_OMAP54XX)
  25. int lp873x_mmc1_poweron_ldo(uint voltage)
  26. {
  27. if (palmas_i2c_write_u8(LP873X_LDO1_ADDR, LP873X_LDO1_VOLTAGE,
  28. voltage)) {
  29. printf("lp873x: could not set LDO1 voltage.\n");
  30. return 1;
  31. }
  32. /* TURN ON LDO1 */
  33. if (palmas_i2c_write_u8(LP873X_LDO1_ADDR, LP873X_LDO1_CTRL,
  34. LP873X_LDO_CTRL_EN | LP873X_LDO_CTRL_RDIS_EN)) {
  35. printf("lp873x: could not turn on LDO1.\n");
  36. return 1;
  37. }
  38. return 0;
  39. }
  40. #endif
  41. int palmas_mmc1_poweron_ldo(uint ldo_volt, uint ldo_ctrl, uint voltage)
  42. {
  43. u8 val = 0;
  44. #if defined(CONFIG_DRA7XX)
  45. int ret;
  46. ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, ldo_volt, voltage);
  47. if (ret) {
  48. printf("tps65903x: could not set LDO1 voltage.\n");
  49. return ret;
  50. }
  51. /* TURN ON LDO1 */
  52. val = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
  53. ret = palmas_i2c_write_u8(TPS65903X_CHIP_P1, ldo_ctrl, val);
  54. if (ret) {
  55. printf("tps65903x: could not turn on LDO1.\n");
  56. return ret;
  57. }
  58. return 0;
  59. #else
  60. /*
  61. * We assume that this is a OMAP543X + TWL603X board:
  62. * Set TWL6035/37 LDO9 to 3.0 V
  63. */
  64. val = LDO_VOLT_3V0;
  65. return twl603x_mmc1_set_ldo9(val);
  66. #endif
  67. }
  68. /*
  69. * On some OMAP5 + TWL603X hardware the SD card socket and LDO9_IN are
  70. * powered by an external 3.3 V regulator, while the output of LDO9
  71. * supplies VDDS_SDCARD for the OMAP5 interface only. This implies that
  72. * LDO9 could be set to 'bypass' mode when required (e.g. for 3.3 V cards).
  73. */
  74. int twl603x_mmc1_set_ldo9(u8 vsel)
  75. {
  76. u8 cval = 0, vval = 0; /* Off by default */
  77. int err;
  78. if (vsel) {
  79. /* Turn on */
  80. if (vsel > LDO_VOLT_3V3) {
  81. /* Put LDO9 in bypass */
  82. cval = LDO9_BYP_EN | RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
  83. vval = LDO_VOLT_3V3;
  84. } else {
  85. cval = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
  86. vval = vsel & 0x3f;
  87. }
  88. }
  89. err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_VOLTAGE, vval);
  90. if (err) {
  91. printf("twl603x: could not set LDO9 %s: err = %d\n",
  92. vsel > LDO_VOLT_3V3 ? "bypass" : "voltage", err);
  93. return err;
  94. }
  95. err = palmas_i2c_write_u8(TWL603X_CHIP_P1, LDO9_CTRL, cval);
  96. if (err)
  97. printf("twl603x: could not turn %s LDO9: err = %d\n",
  98. cval ? "on" : "off", err);
  99. return err;
  100. }
  101. #ifdef CONFIG_PALMAS_AUDPWR
  102. /*
  103. * Turn audio codec power and 32 kHz clock on/off. Use for
  104. * testing OMAP543X + TWL603X + TWL604X boards only.
  105. */
  106. int twl603x_audio_power(u8 on)
  107. {
  108. u8 cval = 0, vval = 0, c32k = 0;
  109. int err;
  110. if (on) {
  111. vval = SMPS_VOLT_2V1;
  112. cval = SMPS_MODE_SLP_AUTO | SMPS_MODE_ACT_AUTO;
  113. c32k = RSC_MODE_SLEEP | RSC_MODE_ACTIVE;
  114. }
  115. /* Set SMPS9 to 2.1 V (for TWL604x), or to 0 (off) */
  116. err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_VOLTAGE, vval);
  117. if (err) {
  118. printf("twl603x: could not set SMPS9 voltage: err = %d\n",
  119. err);
  120. return err;
  121. }
  122. /* Turn on or off SMPS9 */
  123. err = palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS9_CTRL, cval);
  124. if (err) {
  125. printf("twl603x: could not turn SMPS9 %s: err = %d\n",
  126. cval ? "on" : "off", err);
  127. return err;
  128. }
  129. /* Output 32 kHz clock on or off */
  130. err = palmas_i2c_write_u8(TWL603X_CHIP_P1, CLK32KGAUDIO_CTRL, c32k);
  131. if (err)
  132. printf("twl603x: could not turn CLK32KGAUDIO %s: err = %d\n",
  133. c32k ? "on" : "off", err);
  134. return err;
  135. }
  136. #endif
  137. #ifdef CONFIG_PALMAS_USB_SS_PWR
  138. /**
  139. * @brief palmas_enable_ss_ldo - Configure EVM board specific configurations
  140. * for the USB Super speed SMPS10 regulator.
  141. *
  142. * @return 0
  143. */
  144. int palmas_enable_ss_ldo(void)
  145. {
  146. /* Enable smps10 regulator */
  147. return palmas_i2c_write_u8(TWL603X_CHIP_P1, SMPS10_CTRL,
  148. SMPS10_MODE_ACTIVE_D);
  149. }
  150. #endif
  151. /*
  152. * Enable/disable back-up battery (or super cap) charging on TWL6035/37.
  153. * Please use defined BB_xxx values.
  154. */
  155. int twl603x_enable_bb_charge(u8 bb_fields)
  156. {
  157. u8 val = bb_fields & 0x0f;
  158. int err;
  159. val |= (VRTC_EN_SLP | VRTC_EN_OFF | VRTC_PWEN);
  160. err = palmas_i2c_write_u8(TWL603X_CHIP_P1, BB_VRTC_CTRL, val);
  161. if (err)
  162. printf("twl603x: could not set BB_VRTC_CTRL to 0x%02x: err = %d\n",
  163. val, err);
  164. return err;
  165. }