omap_twl.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /**
  2. * OMAP and TWL PMIC specific intializations.
  3. *
  4. * Copyright (C) 2010 Texas Instruments Incorporated.
  5. * Thara Gopinath
  6. * Copyright (C) 2009 Texas Instruments Incorporated.
  7. * Nishanth Menon
  8. * Copyright (C) 2009 Nokia Corporation
  9. * Paul Walmsley
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License version 2 as
  13. * published by the Free Software Foundation.
  14. */
  15. #include <linux/err.h>
  16. #include <linux/io.h>
  17. #include <linux/kernel.h>
  18. #include <linux/i2c/twl.h>
  19. #include "voltage.h"
  20. #include "pm.h"
  21. #define OMAP3_SRI2C_SLAVE_ADDR 0x12
  22. #define OMAP3_VDD_MPU_SR_CONTROL_REG 0x00
  23. #define OMAP3_VDD_CORE_SR_CONTROL_REG 0x01
  24. #define OMAP3_VP_CONFIG_ERROROFFSET 0x00
  25. #define OMAP3_VP_VSTEPMIN_VSTEPMIN 0x1
  26. #define OMAP3_VP_VSTEPMAX_VSTEPMAX 0x04
  27. #define OMAP3_VP_VLIMITTO_TIMEOUT_US 200
  28. #define OMAP4_SRI2C_SLAVE_ADDR 0x12
  29. #define OMAP4_VDD_MPU_SR_VOLT_REG 0x55
  30. #define OMAP4_VDD_MPU_SR_CMD_REG 0x56
  31. #define OMAP4_VDD_IVA_SR_VOLT_REG 0x5B
  32. #define OMAP4_VDD_IVA_SR_CMD_REG 0x5C
  33. #define OMAP4_VDD_CORE_SR_VOLT_REG 0x61
  34. #define OMAP4_VDD_CORE_SR_CMD_REG 0x62
  35. #define OMAP4_VP_CONFIG_ERROROFFSET 0x00
  36. #define OMAP4_VP_VSTEPMIN_VSTEPMIN 0x01
  37. #define OMAP4_VP_VSTEPMAX_VSTEPMAX 0x04
  38. #define OMAP4_VP_VLIMITTO_TIMEOUT_US 200
  39. static bool is_offset_valid;
  40. static u8 smps_offset;
  41. /*
  42. * Flag to ensure Smartreflex bit in TWL
  43. * being cleared in board file is not overwritten.
  44. */
  45. static bool __initdata twl_sr_enable_autoinit;
  46. #define TWL4030_DCDC_GLOBAL_CFG 0x06
  47. #define REG_SMPS_OFFSET 0xE0
  48. #define SMARTREFLEX_ENABLE BIT(3)
  49. static unsigned long twl4030_vsel_to_uv(const u8 vsel)
  50. {
  51. return (((vsel * 125) + 6000)) * 100;
  52. }
  53. static u8 twl4030_uv_to_vsel(unsigned long uv)
  54. {
  55. return DIV_ROUND_UP(uv - 600000, 12500);
  56. }
  57. static unsigned long twl6030_vsel_to_uv(const u8 vsel)
  58. {
  59. /*
  60. * In TWL6030 depending on the value of SMPS_OFFSET
  61. * efuse register the voltage range supported in
  62. * standard mode can be either between 0.6V - 1.3V or
  63. * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
  64. * is programmed to all 0's where as starting from
  65. * TWL6030 ES1.1 the efuse is programmed to 1
  66. */
  67. if (!is_offset_valid) {
  68. twl_i2c_read_u8(TWL6030_MODULE_ID0, &smps_offset,
  69. REG_SMPS_OFFSET);
  70. is_offset_valid = true;
  71. }
  72. if (!vsel)
  73. return 0;
  74. /*
  75. * There is no specific formula for voltage to vsel
  76. * conversion above 1.3V. There are special hardcoded
  77. * values for voltages above 1.3V. Currently we are
  78. * hardcoding only for 1.35 V which is used for 1GH OPP for
  79. * OMAP4430.
  80. */
  81. if (vsel == 0x3A)
  82. return 1350000;
  83. if (smps_offset & 0x8)
  84. return ((((vsel - 1) * 1266) + 70900)) * 10;
  85. else
  86. return ((((vsel - 1) * 1266) + 60770)) * 10;
  87. }
  88. static u8 twl6030_uv_to_vsel(unsigned long uv)
  89. {
  90. /*
  91. * In TWL6030 depending on the value of SMPS_OFFSET
  92. * efuse register the voltage range supported in
  93. * standard mode can be either between 0.6V - 1.3V or
  94. * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
  95. * is programmed to all 0's where as starting from
  96. * TWL6030 ES1.1 the efuse is programmed to 1
  97. */
  98. if (!is_offset_valid) {
  99. twl_i2c_read_u8(TWL6030_MODULE_ID0, &smps_offset,
  100. REG_SMPS_OFFSET);
  101. is_offset_valid = true;
  102. }
  103. if (!uv)
  104. return 0x00;
  105. /*
  106. * There is no specific formula for voltage to vsel
  107. * conversion above 1.3V. There are special hardcoded
  108. * values for voltages above 1.3V. Currently we are
  109. * hardcoding only for 1.35 V which is used for 1GH OPP for
  110. * OMAP4430.
  111. */
  112. if (uv > twl6030_vsel_to_uv(0x39)) {
  113. if (uv == 1350000)
  114. return 0x3A;
  115. pr_err("%s:OUT OF RANGE! non mapped vsel for %ld Vs max %ld\n",
  116. __func__, uv, twl6030_vsel_to_uv(0x39));
  117. return 0x3A;
  118. }
  119. if (smps_offset & 0x8)
  120. return DIV_ROUND_UP(uv - 709000, 12660) + 1;
  121. else
  122. return DIV_ROUND_UP(uv - 607700, 12660) + 1;
  123. }
  124. static struct omap_voltdm_pmic omap3_mpu_pmic = {
  125. .slew_rate = 4000,
  126. .step_size = 12500,
  127. .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
  128. .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
  129. .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
  130. .vddmin = 600000,
  131. .vddmax = 1450000,
  132. .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
  133. .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
  134. .volt_reg_addr = OMAP3_VDD_MPU_SR_CONTROL_REG,
  135. .i2c_high_speed = true,
  136. .vsel_to_uv = twl4030_vsel_to_uv,
  137. .uv_to_vsel = twl4030_uv_to_vsel,
  138. };
  139. static struct omap_voltdm_pmic omap3_core_pmic = {
  140. .slew_rate = 4000,
  141. .step_size = 12500,
  142. .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
  143. .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
  144. .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
  145. .vddmin = 600000,
  146. .vddmax = 1450000,
  147. .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
  148. .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
  149. .volt_reg_addr = OMAP3_VDD_CORE_SR_CONTROL_REG,
  150. .i2c_high_speed = true,
  151. .vsel_to_uv = twl4030_vsel_to_uv,
  152. .uv_to_vsel = twl4030_uv_to_vsel,
  153. };
  154. static struct omap_voltdm_pmic omap4_mpu_pmic = {
  155. .slew_rate = 4000,
  156. .step_size = 12660,
  157. .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
  158. .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
  159. .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
  160. .vddmin = 0,
  161. .vddmax = 2100000,
  162. .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
  163. .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
  164. .volt_reg_addr = OMAP4_VDD_MPU_SR_VOLT_REG,
  165. .cmd_reg_addr = OMAP4_VDD_MPU_SR_CMD_REG,
  166. .i2c_high_speed = true,
  167. .i2c_pad_load = 3,
  168. .vsel_to_uv = twl6030_vsel_to_uv,
  169. .uv_to_vsel = twl6030_uv_to_vsel,
  170. };
  171. static struct omap_voltdm_pmic omap4_iva_pmic = {
  172. .slew_rate = 4000,
  173. .step_size = 12660,
  174. .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
  175. .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
  176. .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
  177. .vddmin = 0,
  178. .vddmax = 2100000,
  179. .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
  180. .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
  181. .volt_reg_addr = OMAP4_VDD_IVA_SR_VOLT_REG,
  182. .cmd_reg_addr = OMAP4_VDD_IVA_SR_CMD_REG,
  183. .i2c_high_speed = true,
  184. .i2c_pad_load = 3,
  185. .vsel_to_uv = twl6030_vsel_to_uv,
  186. .uv_to_vsel = twl6030_uv_to_vsel,
  187. };
  188. static struct omap_voltdm_pmic omap4_core_pmic = {
  189. .slew_rate = 4000,
  190. .step_size = 12660,
  191. .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
  192. .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
  193. .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
  194. .vddmin = 0,
  195. .vddmax = 2100000,
  196. .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
  197. .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
  198. .volt_reg_addr = OMAP4_VDD_CORE_SR_VOLT_REG,
  199. .cmd_reg_addr = OMAP4_VDD_CORE_SR_CMD_REG,
  200. .i2c_high_speed = true,
  201. .i2c_pad_load = 3,
  202. .vsel_to_uv = twl6030_vsel_to_uv,
  203. .uv_to_vsel = twl6030_uv_to_vsel,
  204. };
  205. int __init omap4_twl_init(void)
  206. {
  207. struct voltagedomain *voltdm;
  208. if (!cpu_is_omap44xx())
  209. return -ENODEV;
  210. voltdm = voltdm_lookup("mpu");
  211. omap_voltage_register_pmic(voltdm, &omap4_mpu_pmic);
  212. voltdm = voltdm_lookup("iva");
  213. omap_voltage_register_pmic(voltdm, &omap4_iva_pmic);
  214. voltdm = voltdm_lookup("core");
  215. omap_voltage_register_pmic(voltdm, &omap4_core_pmic);
  216. return 0;
  217. }
  218. int __init omap3_twl_init(void)
  219. {
  220. struct voltagedomain *voltdm;
  221. if (!cpu_is_omap34xx())
  222. return -ENODEV;
  223. /*
  224. * The smartreflex bit on twl4030 specifies if the setting of voltage
  225. * is done over the I2C_SR path. Since this setting is independent of
  226. * the actual usage of smartreflex AVS module, we enable TWL SR bit
  227. * by default irrespective of whether smartreflex AVS module is enabled
  228. * on the OMAP side or not. This is because without this bit enabled,
  229. * the voltage scaling through vp forceupdate/bypass mechanism of
  230. * voltage scaling will not function on TWL over I2C_SR.
  231. */
  232. if (!twl_sr_enable_autoinit)
  233. omap3_twl_set_sr_bit(true);
  234. voltdm = voltdm_lookup("mpu_iva");
  235. omap_voltage_register_pmic(voltdm, &omap3_mpu_pmic);
  236. voltdm = voltdm_lookup("core");
  237. omap_voltage_register_pmic(voltdm, &omap3_core_pmic);
  238. return 0;
  239. }
  240. /**
  241. * omap3_twl_set_sr_bit() - Set/Clear SR bit on TWL
  242. * @enable: enable SR mode in twl or not
  243. *
  244. * If 'enable' is true, enables Smartreflex bit on TWL 4030 to make sure
  245. * voltage scaling through OMAP SR works. Else, the smartreflex bit
  246. * on twl4030 is cleared as there are platforms which use OMAP3 and T2 but
  247. * use Synchronized Scaling Hardware Strategy (ENABLE_VMODE=1) and Direct
  248. * Strategy Software Scaling Mode (ENABLE_VMODE=0), for setting the voltages,
  249. * in those scenarios this bit is to be cleared (enable = false).
  250. *
  251. * Returns 0 on success, error is returned if I2C read/write fails.
  252. */
  253. int __init omap3_twl_set_sr_bit(bool enable)
  254. {
  255. u8 temp;
  256. int ret;
  257. if (twl_sr_enable_autoinit)
  258. pr_warning("%s: unexpected multiple calls\n", __func__);
  259. ret = twl_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &temp,
  260. TWL4030_DCDC_GLOBAL_CFG);
  261. if (ret)
  262. goto err;
  263. if (enable)
  264. temp |= SMARTREFLEX_ENABLE;
  265. else
  266. temp &= ~SMARTREFLEX_ENABLE;
  267. ret = twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, temp,
  268. TWL4030_DCDC_GLOBAL_CFG);
  269. if (!ret) {
  270. twl_sr_enable_autoinit = true;
  271. return 0;
  272. }
  273. err:
  274. pr_err("%s: Error access to TWL4030 (%d)\n", __func__, ret);
  275. return ret;
  276. }