omap_twl.c 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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. .on_volt = 1200000,
  128. .onlp_volt = 1000000,
  129. .ret_volt = 975000,
  130. .off_volt = 600000,
  131. .volt_setup_time = 0xfff,
  132. .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
  133. .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
  134. .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
  135. .vp_vddmin = OMAP3430_VP1_VLIMITTO_VDDMIN,
  136. .vp_vddmax = OMAP3430_VP1_VLIMITTO_VDDMAX,
  137. .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
  138. .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
  139. .volt_reg_addr = OMAP3_VDD_MPU_SR_CONTROL_REG,
  140. .i2c_high_speed = true,
  141. .vsel_to_uv = twl4030_vsel_to_uv,
  142. .uv_to_vsel = twl4030_uv_to_vsel,
  143. };
  144. static struct omap_voltdm_pmic omap3_core_pmic = {
  145. .slew_rate = 4000,
  146. .step_size = 12500,
  147. .on_volt = 1200000,
  148. .onlp_volt = 1000000,
  149. .ret_volt = 975000,
  150. .off_volt = 600000,
  151. .volt_setup_time = 0xfff,
  152. .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
  153. .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
  154. .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
  155. .vp_vddmin = OMAP3430_VP2_VLIMITTO_VDDMIN,
  156. .vp_vddmax = OMAP3430_VP2_VLIMITTO_VDDMAX,
  157. .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
  158. .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
  159. .volt_reg_addr = OMAP3_VDD_CORE_SR_CONTROL_REG,
  160. .i2c_high_speed = true,
  161. .vsel_to_uv = twl4030_vsel_to_uv,
  162. .uv_to_vsel = twl4030_uv_to_vsel,
  163. };
  164. static struct omap_voltdm_pmic omap4_mpu_pmic = {
  165. .slew_rate = 4000,
  166. .step_size = 12660,
  167. .on_volt = 1375000,
  168. .onlp_volt = 1375000,
  169. .ret_volt = 830000,
  170. .off_volt = 0,
  171. .volt_setup_time = 0,
  172. .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
  173. .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
  174. .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
  175. .vp_vddmin = OMAP4_VP_MPU_VLIMITTO_VDDMIN,
  176. .vp_vddmax = OMAP4_VP_MPU_VLIMITTO_VDDMAX,
  177. .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
  178. .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
  179. .volt_reg_addr = OMAP4_VDD_MPU_SR_VOLT_REG,
  180. .cmd_reg_addr = OMAP4_VDD_MPU_SR_CMD_REG,
  181. .i2c_high_speed = true,
  182. .vsel_to_uv = twl6030_vsel_to_uv,
  183. .uv_to_vsel = twl6030_uv_to_vsel,
  184. };
  185. static struct omap_voltdm_pmic omap4_iva_pmic = {
  186. .slew_rate = 4000,
  187. .step_size = 12660,
  188. .on_volt = 1188000,
  189. .onlp_volt = 1188000,
  190. .ret_volt = 830000,
  191. .off_volt = 0,
  192. .volt_setup_time = 0,
  193. .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
  194. .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
  195. .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
  196. .vp_vddmin = OMAP4_VP_IVA_VLIMITTO_VDDMIN,
  197. .vp_vddmax = OMAP4_VP_IVA_VLIMITTO_VDDMAX,
  198. .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
  199. .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
  200. .volt_reg_addr = OMAP4_VDD_IVA_SR_VOLT_REG,
  201. .cmd_reg_addr = OMAP4_VDD_IVA_SR_CMD_REG,
  202. .i2c_high_speed = true,
  203. .vsel_to_uv = twl6030_vsel_to_uv,
  204. .uv_to_vsel = twl6030_uv_to_vsel,
  205. };
  206. static struct omap_voltdm_pmic omap4_core_pmic = {
  207. .slew_rate = 4000,
  208. .step_size = 12660,
  209. .on_volt = 1200000,
  210. .onlp_volt = 1200000,
  211. .ret_volt = 830000,
  212. .off_volt = 0,
  213. .volt_setup_time = 0,
  214. .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
  215. .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
  216. .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
  217. .vp_vddmin = OMAP4_VP_CORE_VLIMITTO_VDDMIN,
  218. .vp_vddmax = OMAP4_VP_CORE_VLIMITTO_VDDMAX,
  219. .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
  220. .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
  221. .volt_reg_addr = OMAP4_VDD_CORE_SR_VOLT_REG,
  222. .cmd_reg_addr = OMAP4_VDD_CORE_SR_CMD_REG,
  223. .vsel_to_uv = twl6030_vsel_to_uv,
  224. .uv_to_vsel = twl6030_uv_to_vsel,
  225. };
  226. int __init omap4_twl_init(void)
  227. {
  228. struct voltagedomain *voltdm;
  229. if (!cpu_is_omap44xx())
  230. return -ENODEV;
  231. voltdm = voltdm_lookup("mpu");
  232. omap_voltage_register_pmic(voltdm, &omap4_mpu_pmic);
  233. voltdm = voltdm_lookup("iva");
  234. omap_voltage_register_pmic(voltdm, &omap4_iva_pmic);
  235. voltdm = voltdm_lookup("core");
  236. omap_voltage_register_pmic(voltdm, &omap4_core_pmic);
  237. return 0;
  238. }
  239. int __init omap3_twl_init(void)
  240. {
  241. struct voltagedomain *voltdm;
  242. if (!cpu_is_omap34xx())
  243. return -ENODEV;
  244. if (cpu_is_omap3630()) {
  245. omap3_mpu_pmic.vp_vddmin = OMAP3630_VP1_VLIMITTO_VDDMIN;
  246. omap3_mpu_pmic.vp_vddmax = OMAP3630_VP1_VLIMITTO_VDDMAX;
  247. omap3_core_pmic.vp_vddmin = OMAP3630_VP2_VLIMITTO_VDDMIN;
  248. omap3_core_pmic.vp_vddmax = OMAP3630_VP2_VLIMITTO_VDDMAX;
  249. }
  250. /*
  251. * The smartreflex bit on twl4030 specifies if the setting of voltage
  252. * is done over the I2C_SR path. Since this setting is independent of
  253. * the actual usage of smartreflex AVS module, we enable TWL SR bit
  254. * by default irrespective of whether smartreflex AVS module is enabled
  255. * on the OMAP side or not. This is because without this bit enabled,
  256. * the voltage scaling through vp forceupdate/bypass mechanism of
  257. * voltage scaling will not function on TWL over I2C_SR.
  258. */
  259. if (!twl_sr_enable_autoinit)
  260. omap3_twl_set_sr_bit(true);
  261. voltdm = voltdm_lookup("mpu_iva");
  262. omap_voltage_register_pmic(voltdm, &omap3_mpu_pmic);
  263. voltdm = voltdm_lookup("core");
  264. omap_voltage_register_pmic(voltdm, &omap3_core_pmic);
  265. return 0;
  266. }
  267. /**
  268. * omap3_twl_set_sr_bit() - Set/Clear SR bit on TWL
  269. * @enable: enable SR mode in twl or not
  270. *
  271. * If 'enable' is true, enables Smartreflex bit on TWL 4030 to make sure
  272. * voltage scaling through OMAP SR works. Else, the smartreflex bit
  273. * on twl4030 is cleared as there are platforms which use OMAP3 and T2 but
  274. * use Synchronized Scaling Hardware Strategy (ENABLE_VMODE=1) and Direct
  275. * Strategy Software Scaling Mode (ENABLE_VMODE=0), for setting the voltages,
  276. * in those scenarios this bit is to be cleared (enable = false).
  277. *
  278. * Returns 0 on success, error is returned if I2C read/write fails.
  279. */
  280. int __init omap3_twl_set_sr_bit(bool enable)
  281. {
  282. u8 temp;
  283. int ret;
  284. if (twl_sr_enable_autoinit)
  285. pr_warning("%s: unexpected multiple calls\n", __func__);
  286. ret = twl_i2c_read_u8(TWL4030_MODULE_PM_RECEIVER, &temp,
  287. TWL4030_DCDC_GLOBAL_CFG);
  288. if (ret)
  289. goto err;
  290. if (enable)
  291. temp |= SMARTREFLEX_ENABLE;
  292. else
  293. temp &= ~SMARTREFLEX_ENABLE;
  294. ret = twl_i2c_write_u8(TWL4030_MODULE_PM_RECEIVER, temp,
  295. TWL4030_DCDC_GLOBAL_CFG);
  296. if (!ret) {
  297. twl_sr_enable_autoinit = true;
  298. return 0;
  299. }
  300. err:
  301. pr_err("%s: Error access to TWL4030 (%d)\n", __func__, ret);
  302. return ret;
  303. }