omap_twl.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. #define REG_SMPS_OFFSET 0xE0
  43. static unsigned long twl4030_vsel_to_uv(const u8 vsel)
  44. {
  45. return (((vsel * 125) + 6000)) * 100;
  46. }
  47. static u8 twl4030_uv_to_vsel(unsigned long uv)
  48. {
  49. return DIV_ROUND_UP(uv - 600000, 12500);
  50. }
  51. static unsigned long twl6030_vsel_to_uv(const u8 vsel)
  52. {
  53. /*
  54. * In TWL6030 depending on the value of SMPS_OFFSET
  55. * efuse register the voltage range supported in
  56. * standard mode can be either between 0.6V - 1.3V or
  57. * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
  58. * is programmed to all 0's where as starting from
  59. * TWL6030 ES1.1 the efuse is programmed to 1
  60. */
  61. if (!is_offset_valid) {
  62. twl_i2c_read_u8(TWL6030_MODULE_ID0, &smps_offset,
  63. REG_SMPS_OFFSET);
  64. is_offset_valid = true;
  65. }
  66. if (!vsel)
  67. return 0;
  68. /*
  69. * There is no specific formula for voltage to vsel
  70. * conversion above 1.3V. There are special hardcoded
  71. * values for voltages above 1.3V. Currently we are
  72. * hardcoding only for 1.35 V which is used for 1GH OPP for
  73. * OMAP4430.
  74. */
  75. if (vsel == 0x3A)
  76. return 1350000;
  77. if (smps_offset & 0x8)
  78. return ((((vsel - 1) * 1266) + 70900)) * 10;
  79. else
  80. return ((((vsel - 1) * 1266) + 60770)) * 10;
  81. }
  82. static u8 twl6030_uv_to_vsel(unsigned long uv)
  83. {
  84. /*
  85. * In TWL6030 depending on the value of SMPS_OFFSET
  86. * efuse register the voltage range supported in
  87. * standard mode can be either between 0.6V - 1.3V or
  88. * 0.7V - 1.4V. In TWL6030 ES1.0 SMPS_OFFSET efuse
  89. * is programmed to all 0's where as starting from
  90. * TWL6030 ES1.1 the efuse is programmed to 1
  91. */
  92. if (!is_offset_valid) {
  93. twl_i2c_read_u8(TWL6030_MODULE_ID0, &smps_offset,
  94. REG_SMPS_OFFSET);
  95. is_offset_valid = true;
  96. }
  97. if (!uv)
  98. return 0x00;
  99. /*
  100. * There is no specific formula for voltage to vsel
  101. * conversion above 1.3V. There are special hardcoded
  102. * values for voltages above 1.3V. Currently we are
  103. * hardcoding only for 1.35 V which is used for 1GH OPP for
  104. * OMAP4430.
  105. */
  106. if (uv > twl6030_vsel_to_uv(0x39)) {
  107. if (uv == 1350000)
  108. return 0x3A;
  109. pr_err("%s:OUT OF RANGE! non mapped vsel for %ld Vs max %ld\n",
  110. __func__, uv, twl6030_vsel_to_uv(0x39));
  111. return 0x3A;
  112. }
  113. if (smps_offset & 0x8)
  114. return DIV_ROUND_UP(uv - 709000, 12660) + 1;
  115. else
  116. return DIV_ROUND_UP(uv - 607700, 12660) + 1;
  117. }
  118. static struct omap_voltdm_pmic omap3_mpu_pmic = {
  119. .slew_rate = 4000,
  120. .step_size = 12500,
  121. .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
  122. .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
  123. .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
  124. .vddmin = 600000,
  125. .vddmax = 1450000,
  126. .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
  127. .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
  128. .volt_reg_addr = OMAP3_VDD_MPU_SR_CONTROL_REG,
  129. .i2c_high_speed = true,
  130. .vsel_to_uv = twl4030_vsel_to_uv,
  131. .uv_to_vsel = twl4030_uv_to_vsel,
  132. };
  133. static struct omap_voltdm_pmic omap3_core_pmic = {
  134. .slew_rate = 4000,
  135. .step_size = 12500,
  136. .vp_erroroffset = OMAP3_VP_CONFIG_ERROROFFSET,
  137. .vp_vstepmin = OMAP3_VP_VSTEPMIN_VSTEPMIN,
  138. .vp_vstepmax = OMAP3_VP_VSTEPMAX_VSTEPMAX,
  139. .vddmin = 600000,
  140. .vddmax = 1450000,
  141. .vp_timeout_us = OMAP3_VP_VLIMITTO_TIMEOUT_US,
  142. .i2c_slave_addr = OMAP3_SRI2C_SLAVE_ADDR,
  143. .volt_reg_addr = OMAP3_VDD_CORE_SR_CONTROL_REG,
  144. .i2c_high_speed = true,
  145. .vsel_to_uv = twl4030_vsel_to_uv,
  146. .uv_to_vsel = twl4030_uv_to_vsel,
  147. };
  148. static struct omap_voltdm_pmic omap4_mpu_pmic = {
  149. .slew_rate = 4000,
  150. .step_size = 12660,
  151. .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
  152. .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
  153. .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
  154. .vddmin = 0,
  155. .vddmax = 2100000,
  156. .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
  157. .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
  158. .volt_reg_addr = OMAP4_VDD_MPU_SR_VOLT_REG,
  159. .cmd_reg_addr = OMAP4_VDD_MPU_SR_CMD_REG,
  160. .i2c_high_speed = true,
  161. .i2c_pad_load = 3,
  162. .vsel_to_uv = twl6030_vsel_to_uv,
  163. .uv_to_vsel = twl6030_uv_to_vsel,
  164. };
  165. static struct omap_voltdm_pmic omap4_iva_pmic = {
  166. .slew_rate = 4000,
  167. .step_size = 12660,
  168. .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
  169. .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
  170. .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
  171. .vddmin = 0,
  172. .vddmax = 2100000,
  173. .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
  174. .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
  175. .volt_reg_addr = OMAP4_VDD_IVA_SR_VOLT_REG,
  176. .cmd_reg_addr = OMAP4_VDD_IVA_SR_CMD_REG,
  177. .i2c_high_speed = true,
  178. .i2c_pad_load = 3,
  179. .vsel_to_uv = twl6030_vsel_to_uv,
  180. .uv_to_vsel = twl6030_uv_to_vsel,
  181. };
  182. static struct omap_voltdm_pmic omap4_core_pmic = {
  183. .slew_rate = 4000,
  184. .step_size = 12660,
  185. .vp_erroroffset = OMAP4_VP_CONFIG_ERROROFFSET,
  186. .vp_vstepmin = OMAP4_VP_VSTEPMIN_VSTEPMIN,
  187. .vp_vstepmax = OMAP4_VP_VSTEPMAX_VSTEPMAX,
  188. .vddmin = 0,
  189. .vddmax = 2100000,
  190. .vp_timeout_us = OMAP4_VP_VLIMITTO_TIMEOUT_US,
  191. .i2c_slave_addr = OMAP4_SRI2C_SLAVE_ADDR,
  192. .volt_reg_addr = OMAP4_VDD_CORE_SR_VOLT_REG,
  193. .cmd_reg_addr = OMAP4_VDD_CORE_SR_CMD_REG,
  194. .i2c_high_speed = true,
  195. .i2c_pad_load = 3,
  196. .vsel_to_uv = twl6030_vsel_to_uv,
  197. .uv_to_vsel = twl6030_uv_to_vsel,
  198. };
  199. int __init omap4_twl_init(void)
  200. {
  201. struct voltagedomain *voltdm;
  202. if (!cpu_is_omap44xx())
  203. return -ENODEV;
  204. voltdm = voltdm_lookup("mpu");
  205. omap_voltage_register_pmic(voltdm, &omap4_mpu_pmic);
  206. voltdm = voltdm_lookup("iva");
  207. omap_voltage_register_pmic(voltdm, &omap4_iva_pmic);
  208. voltdm = voltdm_lookup("core");
  209. omap_voltage_register_pmic(voltdm, &omap4_core_pmic);
  210. return 0;
  211. }
  212. int __init omap3_twl_init(void)
  213. {
  214. struct voltagedomain *voltdm;
  215. if (!cpu_is_omap34xx())
  216. return -ENODEV;
  217. voltdm = voltdm_lookup("mpu_iva");
  218. omap_voltage_register_pmic(voltdm, &omap3_mpu_pmic);
  219. voltdm = voltdm_lookup("core");
  220. omap_voltage_register_pmic(voltdm, &omap3_core_pmic);
  221. return 0;
  222. }