intel_pmic_chtdc_ti.c 3.2 KB

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