intel_pmic_chtdc_ti.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Dollar Cove TI PMIC operation region driver
  3. * Copyright (C) 2014 Intel Corporation. All rights reserved.
  4. *
  5. * Rewritten and cleaned up
  6. * Copyright (C) 2017 Takashi Iwai <tiwai@suse.de>
  7. */
  8. #include <linux/acpi.h>
  9. #include <linux/init.h>
  10. #include <linux/mfd/intel_soc_pmic.h>
  11. #include <linux/platform_device.h>
  12. #include "intel_pmic.h"
  13. /* registers stored in 16bit BE (high:low, total 10bit) */
  14. #define CHTDC_TI_VBAT 0x54
  15. #define CHTDC_TI_DIETEMP 0x56
  16. #define CHTDC_TI_BPTHERM 0x58
  17. #define CHTDC_TI_GPADC 0x5a
  18. static struct pmic_table chtdc_ti_power_table[] = {
  19. { .address = 0x00, .reg = 0x41 },
  20. { .address = 0x04, .reg = 0x42 },
  21. { .address = 0x08, .reg = 0x43 },
  22. { .address = 0x0c, .reg = 0x45 },
  23. { .address = 0x10, .reg = 0x46 },
  24. { .address = 0x14, .reg = 0x47 },
  25. { .address = 0x18, .reg = 0x48 },
  26. { .address = 0x1c, .reg = 0x49 },
  27. { .address = 0x20, .reg = 0x4a },
  28. { .address = 0x24, .reg = 0x4b },
  29. { .address = 0x28, .reg = 0x4c },
  30. { .address = 0x2c, .reg = 0x4d },
  31. { .address = 0x30, .reg = 0x4e },
  32. };
  33. static struct pmic_table chtdc_ti_thermal_table[] = {
  34. {
  35. .address = 0x00,
  36. .reg = CHTDC_TI_GPADC
  37. },
  38. {
  39. .address = 0x0c,
  40. .reg = CHTDC_TI_GPADC
  41. },
  42. /* TMP2 -> SYSTEMP */
  43. {
  44. .address = 0x18,
  45. .reg = CHTDC_TI_GPADC
  46. },
  47. /* TMP3 -> BPTHERM */
  48. {
  49. .address = 0x24,
  50. .reg = CHTDC_TI_BPTHERM
  51. },
  52. {
  53. .address = 0x30,
  54. .reg = CHTDC_TI_GPADC
  55. },
  56. /* TMP5 -> DIETEMP */
  57. {
  58. .address = 0x3c,
  59. .reg = CHTDC_TI_DIETEMP
  60. },
  61. };
  62. static int chtdc_ti_pmic_get_power(struct regmap *regmap, int reg, int bit,
  63. u64 *value)
  64. {
  65. int data;
  66. if (regmap_read(regmap, reg, &data))
  67. return -EIO;
  68. *value = data & 1;
  69. return 0;
  70. }
  71. static int chtdc_ti_pmic_update_power(struct regmap *regmap, int reg, int bit,
  72. bool on)
  73. {
  74. return regmap_update_bits(regmap, reg, 1, on);
  75. }
  76. static int chtdc_ti_pmic_get_raw_temp(struct regmap *regmap, int reg)
  77. {
  78. u8 buf[2];
  79. if (regmap_bulk_read(regmap, reg, buf, 2))
  80. return -EIO;
  81. /* stored in big-endian */
  82. return ((buf[0] & 0x03) << 8) | buf[1];
  83. }
  84. static struct intel_pmic_opregion_data chtdc_ti_pmic_opregion_data = {
  85. .get_power = chtdc_ti_pmic_get_power,
  86. .update_power = chtdc_ti_pmic_update_power,
  87. .get_raw_temp = chtdc_ti_pmic_get_raw_temp,
  88. .power_table = chtdc_ti_power_table,
  89. .power_table_count = ARRAY_SIZE(chtdc_ti_power_table),
  90. .thermal_table = chtdc_ti_thermal_table,
  91. .thermal_table_count = ARRAY_SIZE(chtdc_ti_thermal_table),
  92. };
  93. static int chtdc_ti_pmic_opregion_probe(struct platform_device *pdev)
  94. {
  95. struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
  96. int err;
  97. err = intel_pmic_install_opregion_handler(&pdev->dev,
  98. ACPI_HANDLE(pdev->dev.parent), pmic->regmap,
  99. &chtdc_ti_pmic_opregion_data);
  100. if (err < 0)
  101. return err;
  102. /* Re-enumerate devices depending on PMIC */
  103. acpi_walk_dep_device_list(ACPI_HANDLE(pdev->dev.parent));
  104. return 0;
  105. }
  106. static const struct platform_device_id chtdc_ti_pmic_opregion_id_table[] = {
  107. { .name = "chtdc_ti_region" },
  108. {},
  109. };
  110. static struct platform_driver chtdc_ti_pmic_opregion_driver = {
  111. .probe = chtdc_ti_pmic_opregion_probe,
  112. .driver = {
  113. .name = "cht_dollar_cove_ti_pmic",
  114. },
  115. .id_table = chtdc_ti_pmic_opregion_id_table,
  116. };
  117. builtin_platform_driver(chtdc_ti_pmic_opregion_driver);