intel_pmic_crc.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /*
  2. * intel_pmic_crc.c - Intel CrystalCove PMIC operation region driver
  3. *
  4. * Copyright (C) 2014 Intel Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License version
  8. * 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <linux/init.h>
  16. #include <linux/acpi.h>
  17. #include <linux/mfd/intel_soc_pmic.h>
  18. #include <linux/regmap.h>
  19. #include <linux/platform_device.h>
  20. #include "intel_pmic.h"
  21. #define PWR_SOURCE_SELECT BIT(1)
  22. #define PMIC_A0LOCK_REG 0xc5
  23. static struct pmic_table power_table[] = {
  24. /* {
  25. .address = 0x00,
  26. .reg = ??,
  27. .bit = ??,
  28. }, ** VSYS */
  29. {
  30. .address = 0x04,
  31. .reg = 0x63,
  32. .bit = 0x00,
  33. }, /* SYSX -> VSYS_SX */
  34. {
  35. .address = 0x08,
  36. .reg = 0x62,
  37. .bit = 0x00,
  38. }, /* SYSU -> VSYS_U */
  39. {
  40. .address = 0x0c,
  41. .reg = 0x64,
  42. .bit = 0x00,
  43. }, /* SYSS -> VSYS_S */
  44. {
  45. .address = 0x10,
  46. .reg = 0x6a,
  47. .bit = 0x00,
  48. }, /* V50S -> V5P0S */
  49. {
  50. .address = 0x14,
  51. .reg = 0x6b,
  52. .bit = 0x00,
  53. }, /* HOST -> VHOST, USB2/3 host */
  54. {
  55. .address = 0x18,
  56. .reg = 0x6c,
  57. .bit = 0x00,
  58. }, /* VBUS -> VBUS, USB2/3 OTG */
  59. {
  60. .address = 0x1c,
  61. .reg = 0x6d,
  62. .bit = 0x00,
  63. }, /* HDMI -> VHDMI */
  64. /* {
  65. .address = 0x20,
  66. .reg = ??,
  67. .bit = ??,
  68. }, ** S285 */
  69. {
  70. .address = 0x24,
  71. .reg = 0x66,
  72. .bit = 0x00,
  73. }, /* X285 -> V2P85SX, camera */
  74. /* {
  75. .address = 0x28,
  76. .reg = ??,
  77. .bit = ??,
  78. }, ** V33A */
  79. {
  80. .address = 0x2c,
  81. .reg = 0x69,
  82. .bit = 0x00,
  83. }, /* V33S -> V3P3S, display/ssd/audio */
  84. {
  85. .address = 0x30,
  86. .reg = 0x68,
  87. .bit = 0x00,
  88. }, /* V33U -> V3P3U, SDIO wifi&bt */
  89. /* {
  90. .address = 0x34 .. 0x40,
  91. .reg = ??,
  92. .bit = ??,
  93. }, ** V33I, V18A, REFQ, V12A */
  94. {
  95. .address = 0x44,
  96. .reg = 0x5c,
  97. .bit = 0x00,
  98. }, /* V18S -> V1P8S, SOC/USB PHY/SIM */
  99. {
  100. .address = 0x48,
  101. .reg = 0x5d,
  102. .bit = 0x00,
  103. }, /* V18X -> V1P8SX, eMMC/camara/audio */
  104. {
  105. .address = 0x4c,
  106. .reg = 0x5b,
  107. .bit = 0x00,
  108. }, /* V18U -> V1P8U, LPDDR */
  109. {
  110. .address = 0x50,
  111. .reg = 0x61,
  112. .bit = 0x00,
  113. }, /* V12X -> V1P2SX, SOC SFR */
  114. {
  115. .address = 0x54,
  116. .reg = 0x60,
  117. .bit = 0x00,
  118. }, /* V12S -> V1P2S, MIPI */
  119. /* {
  120. .address = 0x58,
  121. .reg = ??,
  122. .bit = ??,
  123. }, ** V10A */
  124. {
  125. .address = 0x5c,
  126. .reg = 0x56,
  127. .bit = 0x00,
  128. }, /* V10S -> V1P0S, SOC GFX */
  129. {
  130. .address = 0x60,
  131. .reg = 0x57,
  132. .bit = 0x00,
  133. }, /* V10X -> V1P0SX, SOC display/DDR IO/PCIe */
  134. {
  135. .address = 0x64,
  136. .reg = 0x59,
  137. .bit = 0x00,
  138. }, /* V105 -> V1P05S, L2 SRAM */
  139. };
  140. static struct pmic_table thermal_table[] = {
  141. {
  142. .address = 0x00,
  143. .reg = 0x75
  144. },
  145. {
  146. .address = 0x04,
  147. .reg = 0x95
  148. },
  149. {
  150. .address = 0x08,
  151. .reg = 0x97
  152. },
  153. {
  154. .address = 0x0c,
  155. .reg = 0x77
  156. },
  157. {
  158. .address = 0x10,
  159. .reg = 0x9a
  160. },
  161. {
  162. .address = 0x14,
  163. .reg = 0x9c
  164. },
  165. {
  166. .address = 0x18,
  167. .reg = 0x79
  168. },
  169. {
  170. .address = 0x1c,
  171. .reg = 0x9f
  172. },
  173. {
  174. .address = 0x20,
  175. .reg = 0xa1
  176. },
  177. {
  178. .address = 0x48,
  179. .reg = 0x94
  180. },
  181. {
  182. .address = 0x4c,
  183. .reg = 0x99
  184. },
  185. {
  186. .address = 0x50,
  187. .reg = 0x9e
  188. },
  189. };
  190. static int intel_crc_pmic_get_power(struct regmap *regmap, int reg,
  191. int bit, u64 *value)
  192. {
  193. int data;
  194. if (regmap_read(regmap, reg, &data))
  195. return -EIO;
  196. *value = (data & PWR_SOURCE_SELECT) && (data & BIT(bit)) ? 1 : 0;
  197. return 0;
  198. }
  199. static int intel_crc_pmic_update_power(struct regmap *regmap, int reg,
  200. int bit, bool on)
  201. {
  202. int data;
  203. if (regmap_read(regmap, reg, &data))
  204. return -EIO;
  205. if (on) {
  206. data |= PWR_SOURCE_SELECT | BIT(bit);
  207. } else {
  208. data &= ~BIT(bit);
  209. data |= PWR_SOURCE_SELECT;
  210. }
  211. if (regmap_write(regmap, reg, data))
  212. return -EIO;
  213. return 0;
  214. }
  215. static int intel_crc_pmic_get_raw_temp(struct regmap *regmap, int reg)
  216. {
  217. int temp_l, temp_h;
  218. /*
  219. * Raw temperature value is 10bits: 8bits in reg
  220. * and 2bits in reg-1: bit0,1
  221. */
  222. if (regmap_read(regmap, reg, &temp_l) ||
  223. regmap_read(regmap, reg - 1, &temp_h))
  224. return -EIO;
  225. return temp_l | (temp_h & 0x3) << 8;
  226. }
  227. static int intel_crc_pmic_update_aux(struct regmap *regmap, int reg, int raw)
  228. {
  229. return regmap_write(regmap, reg, raw) ||
  230. regmap_update_bits(regmap, reg - 1, 0x3, raw >> 8) ? -EIO : 0;
  231. }
  232. static int intel_crc_pmic_get_policy(struct regmap *regmap,
  233. int reg, int bit, u64 *value)
  234. {
  235. int pen;
  236. if (regmap_read(regmap, reg, &pen))
  237. return -EIO;
  238. *value = pen >> 7;
  239. return 0;
  240. }
  241. static int intel_crc_pmic_update_policy(struct regmap *regmap,
  242. int reg, int bit, int enable)
  243. {
  244. int alert0;
  245. /* Update to policy enable bit requires unlocking a0lock */
  246. if (regmap_read(regmap, PMIC_A0LOCK_REG, &alert0))
  247. return -EIO;
  248. if (regmap_update_bits(regmap, PMIC_A0LOCK_REG, 0x01, 0))
  249. return -EIO;
  250. if (regmap_update_bits(regmap, reg, 0x80, enable << 7))
  251. return -EIO;
  252. /* restore alert0 */
  253. if (regmap_write(regmap, PMIC_A0LOCK_REG, alert0))
  254. return -EIO;
  255. return 0;
  256. }
  257. static struct intel_pmic_opregion_data intel_crc_pmic_opregion_data = {
  258. .get_power = intel_crc_pmic_get_power,
  259. .update_power = intel_crc_pmic_update_power,
  260. .get_raw_temp = intel_crc_pmic_get_raw_temp,
  261. .update_aux = intel_crc_pmic_update_aux,
  262. .get_policy = intel_crc_pmic_get_policy,
  263. .update_policy = intel_crc_pmic_update_policy,
  264. .power_table = power_table,
  265. .power_table_count= ARRAY_SIZE(power_table),
  266. .thermal_table = thermal_table,
  267. .thermal_table_count = ARRAY_SIZE(thermal_table),
  268. };
  269. static int intel_crc_pmic_opregion_probe(struct platform_device *pdev)
  270. {
  271. struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
  272. return intel_pmic_install_opregion_handler(&pdev->dev,
  273. ACPI_HANDLE(pdev->dev.parent), pmic->regmap,
  274. &intel_crc_pmic_opregion_data);
  275. }
  276. static struct platform_driver intel_crc_pmic_opregion_driver = {
  277. .probe = intel_crc_pmic_opregion_probe,
  278. .driver = {
  279. .name = "crystal_cove_pmic",
  280. },
  281. };
  282. builtin_platform_driver(intel_crc_pmic_opregion_driver);