intel_pmic_xpower.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * intel_pmic_xpower.c - XPower AXP288 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/axp20x.h>
  18. #include <linux/regmap.h>
  19. #include <linux/platform_device.h>
  20. #include "intel_pmic.h"
  21. #define XPOWER_GPADC_LOW 0x5b
  22. static struct pmic_table power_table[] = {
  23. {
  24. .address = 0x00,
  25. .reg = 0x13,
  26. .bit = 0x05,
  27. }, /* ALD1 */
  28. {
  29. .address = 0x04,
  30. .reg = 0x13,
  31. .bit = 0x06,
  32. }, /* ALD2 */
  33. {
  34. .address = 0x08,
  35. .reg = 0x13,
  36. .bit = 0x07,
  37. }, /* ALD3 */
  38. {
  39. .address = 0x0c,
  40. .reg = 0x12,
  41. .bit = 0x03,
  42. }, /* DLD1 */
  43. {
  44. .address = 0x10,
  45. .reg = 0x12,
  46. .bit = 0x04,
  47. }, /* DLD2 */
  48. {
  49. .address = 0x14,
  50. .reg = 0x12,
  51. .bit = 0x05,
  52. }, /* DLD3 */
  53. {
  54. .address = 0x18,
  55. .reg = 0x12,
  56. .bit = 0x06,
  57. }, /* DLD4 */
  58. {
  59. .address = 0x1c,
  60. .reg = 0x12,
  61. .bit = 0x00,
  62. }, /* ELD1 */
  63. {
  64. .address = 0x20,
  65. .reg = 0x12,
  66. .bit = 0x01,
  67. }, /* ELD2 */
  68. {
  69. .address = 0x24,
  70. .reg = 0x12,
  71. .bit = 0x02,
  72. }, /* ELD3 */
  73. {
  74. .address = 0x28,
  75. .reg = 0x13,
  76. .bit = 0x02,
  77. }, /* FLD1 */
  78. {
  79. .address = 0x2c,
  80. .reg = 0x13,
  81. .bit = 0x03,
  82. }, /* FLD2 */
  83. {
  84. .address = 0x30,
  85. .reg = 0x13,
  86. .bit = 0x04,
  87. }, /* FLD3 */
  88. {
  89. .address = 0x34,
  90. .reg = 0x10,
  91. .bit = 0x03,
  92. }, /* BUC1 */
  93. {
  94. .address = 0x38,
  95. .reg = 0x10,
  96. .bit = 0x06,
  97. }, /* BUC2 */
  98. {
  99. .address = 0x3c,
  100. .reg = 0x10,
  101. .bit = 0x05,
  102. }, /* BUC3 */
  103. {
  104. .address = 0x40,
  105. .reg = 0x10,
  106. .bit = 0x04,
  107. }, /* BUC4 */
  108. {
  109. .address = 0x44,
  110. .reg = 0x10,
  111. .bit = 0x01,
  112. }, /* BUC5 */
  113. {
  114. .address = 0x48,
  115. .reg = 0x10,
  116. .bit = 0x00
  117. }, /* BUC6 */
  118. };
  119. /* TMP0 - TMP5 are the same, all from GPADC */
  120. static struct pmic_table thermal_table[] = {
  121. {
  122. .address = 0x00,
  123. .reg = XPOWER_GPADC_LOW
  124. },
  125. {
  126. .address = 0x0c,
  127. .reg = XPOWER_GPADC_LOW
  128. },
  129. {
  130. .address = 0x18,
  131. .reg = XPOWER_GPADC_LOW
  132. },
  133. {
  134. .address = 0x24,
  135. .reg = XPOWER_GPADC_LOW
  136. },
  137. {
  138. .address = 0x30,
  139. .reg = XPOWER_GPADC_LOW
  140. },
  141. {
  142. .address = 0x3c,
  143. .reg = XPOWER_GPADC_LOW
  144. },
  145. };
  146. static int intel_xpower_pmic_get_power(struct regmap *regmap, int reg,
  147. int bit, u64 *value)
  148. {
  149. int data;
  150. if (regmap_read(regmap, reg, &data))
  151. return -EIO;
  152. *value = (data & BIT(bit)) ? 1 : 0;
  153. return 0;
  154. }
  155. static int intel_xpower_pmic_update_power(struct regmap *regmap, int reg,
  156. int bit, bool on)
  157. {
  158. int data;
  159. if (regmap_read(regmap, reg, &data))
  160. return -EIO;
  161. if (on)
  162. data |= BIT(bit);
  163. else
  164. data &= ~BIT(bit);
  165. if (regmap_write(regmap, reg, data))
  166. return -EIO;
  167. return 0;
  168. }
  169. /**
  170. * intel_xpower_pmic_get_raw_temp(): Get raw temperature reading from the PMIC
  171. *
  172. * @regmap: regmap of the PMIC device
  173. * @reg: register to get the reading
  174. *
  175. * Return a positive value on success, errno on failure.
  176. */
  177. static int intel_xpower_pmic_get_raw_temp(struct regmap *regmap, int reg)
  178. {
  179. u8 buf[2];
  180. if (regmap_bulk_read(regmap, AXP288_GP_ADC_H, buf, 2))
  181. return -EIO;
  182. return (buf[0] << 4) + ((buf[1] >> 4) & 0x0F);
  183. }
  184. static struct intel_pmic_opregion_data intel_xpower_pmic_opregion_data = {
  185. .get_power = intel_xpower_pmic_get_power,
  186. .update_power = intel_xpower_pmic_update_power,
  187. .get_raw_temp = intel_xpower_pmic_get_raw_temp,
  188. .power_table = power_table,
  189. .power_table_count = ARRAY_SIZE(power_table),
  190. .thermal_table = thermal_table,
  191. .thermal_table_count = ARRAY_SIZE(thermal_table),
  192. };
  193. static acpi_status intel_xpower_pmic_gpio_handler(u32 function,
  194. acpi_physical_address address, u32 bit_width, u64 *value,
  195. void *handler_context, void *region_context)
  196. {
  197. return AE_OK;
  198. }
  199. static int intel_xpower_pmic_opregion_probe(struct platform_device *pdev)
  200. {
  201. struct device *parent = pdev->dev.parent;
  202. struct axp20x_dev *axp20x = dev_get_drvdata(parent);
  203. acpi_status status;
  204. int result;
  205. status = acpi_install_address_space_handler(ACPI_HANDLE(parent),
  206. ACPI_ADR_SPACE_GPIO, intel_xpower_pmic_gpio_handler,
  207. NULL, NULL);
  208. if (ACPI_FAILURE(status))
  209. return -ENODEV;
  210. result = intel_pmic_install_opregion_handler(&pdev->dev,
  211. ACPI_HANDLE(parent), axp20x->regmap,
  212. &intel_xpower_pmic_opregion_data);
  213. if (result)
  214. acpi_remove_address_space_handler(ACPI_HANDLE(parent),
  215. ACPI_ADR_SPACE_GPIO,
  216. intel_xpower_pmic_gpio_handler);
  217. return result;
  218. }
  219. static struct platform_driver intel_xpower_pmic_opregion_driver = {
  220. .probe = intel_xpower_pmic_opregion_probe,
  221. .driver = {
  222. .name = "axp288_pmic_acpi",
  223. },
  224. };
  225. static int __init intel_xpower_pmic_opregion_driver_init(void)
  226. {
  227. return platform_driver_register(&intel_xpower_pmic_opregion_driver);
  228. }
  229. device_initcall(intel_xpower_pmic_opregion_driver_init);