omap_twl.c 8.9 KB

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