intel_pmic_chtdc_ti.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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/bits.h>
  11. #include <linux/init.h>
  12. #include <linux/mfd/intel_soc_pmic.h>
  13. #include <linux/platform_device.h>
  14. #include <asm/byteorder.h>
  15. #include "intel_pmic.h"
  16. /* registers stored in 16bit BE (high:low, total 10bit) */
  17. #define PMIC_REG_MASK GENMASK(9, 0)
  18. #define CHTDC_TI_VBAT 0x54
  19. #define CHTDC_TI_DIETEMP 0x56
  20. #define CHTDC_TI_BPTHERM 0x58
  21. #define CHTDC_TI_GPADC 0x5a
  22. static const struct pmic_table chtdc_ti_power_table[] = {
  23. { .address = 0x00, .reg = 0x41 }, /* LDO1 */
  24. { .address = 0x04, .reg = 0x42 }, /* LDO2 */
  25. { .address = 0x08, .reg = 0x43 }, /* LDO3 */
  26. { .address = 0x0c, .reg = 0x45 }, /* LDO5 */
  27. { .address = 0x10, .reg = 0x46 }, /* LDO6 */
  28. { .address = 0x14, .reg = 0x47 }, /* LDO7 */
  29. { .address = 0x18, .reg = 0x48 }, /* LDO8 */
  30. { .address = 0x1c, .reg = 0x49 }, /* LDO9 */
  31. { .address = 0x20, .reg = 0x4a }, /* LD10 */
  32. { .address = 0x24, .reg = 0x4b }, /* LD11 */
  33. { .address = 0x28, .reg = 0x4c }, /* LD12 */
  34. { .address = 0x2c, .reg = 0x4d }, /* LD13 */
  35. { .address = 0x30, .reg = 0x4e }, /* LD14 */
  36. };
  37. static const struct pmic_table chtdc_ti_thermal_table[] = {
  38. {
  39. .address = 0x00,
  40. .reg = CHTDC_TI_GPADC
  41. },
  42. {
  43. .address = 0x0c,
  44. .reg = CHTDC_TI_GPADC
  45. },
  46. /* TMP2 -> SYSTEMP */
  47. {
  48. .address = 0x18,
  49. .reg = CHTDC_TI_GPADC
  50. },
  51. /* TMP3 -> BPTHERM */
  52. {
  53. .address = 0x24,
  54. .reg = CHTDC_TI_BPTHERM
  55. },
  56. {
  57. .address = 0x30,
  58. .reg = CHTDC_TI_GPADC
  59. },
  60. /* TMP5 -> DIETEMP */
  61. {
  62. .address = 0x3c,
  63. .reg = CHTDC_TI_DIETEMP
  64. },
  65. };
  66. static int chtdc_ti_pmic_get_power(struct regmap *regmap, int reg, int bit,
  67. u64 *value)
  68. {
  69. int data;
  70. if (regmap_read(regmap, reg, &data))
  71. return -EIO;
  72. *value = data & BIT(0);
  73. return 0;
  74. }
  75. static int chtdc_ti_pmic_update_power(struct regmap *regmap, int reg, int bit,
  76. bool on)
  77. {
  78. return regmap_update_bits(regmap, reg, 1, on);
  79. }
  80. static int chtdc_ti_pmic_get_raw_temp(struct regmap *regmap, int reg)
  81. {
  82. __be16 buf;
  83. if (regmap_bulk_read(regmap, reg, &buf, sizeof(buf)))
  84. return -EIO;
  85. return be16_to_cpu(buf) & PMIC_REG_MASK;
  86. }
  87. static const struct intel_pmic_opregion_data chtdc_ti_pmic_opregion_data = {
  88. .get_power = chtdc_ti_pmic_get_power,
  89. .update_power = chtdc_ti_pmic_update_power,
  90. .get_raw_temp = chtdc_ti_pmic_get_raw_temp,
  91. .lpat_raw_to_temp = acpi_lpat_raw_to_temp,
  92. .power_table = chtdc_ti_power_table,
  93. .power_table_count = ARRAY_SIZE(chtdc_ti_power_table),
  94. .thermal_table = chtdc_ti_thermal_table,
  95. .thermal_table_count = ARRAY_SIZE(chtdc_ti_thermal_table),
  96. .pmic_i2c_address = 0x5e,
  97. };
  98. static int chtdc_ti_pmic_opregion_probe(struct platform_device *pdev)
  99. {
  100. struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
  101. int err;
  102. err = intel_pmic_install_opregion_handler(&pdev->dev,
  103. ACPI_HANDLE(pdev->dev.parent), pmic->regmap,
  104. &chtdc_ti_pmic_opregion_data);
  105. if (err < 0)
  106. return err;
  107. /* Re-enumerate devices depending on PMIC */
  108. acpi_dev_clear_dependencies(ACPI_COMPANION(pdev->dev.parent));
  109. return 0;
  110. }
  111. static const struct platform_device_id chtdc_ti_pmic_opregion_id_table[] = {
  112. { .name = "chtdc_ti_region" },
  113. {},
  114. };
  115. static struct platform_driver chtdc_ti_pmic_opregion_driver = {
  116. .probe = chtdc_ti_pmic_opregion_probe,
  117. .driver = {
  118. .name = "cht_dollar_cove_ti_pmic",
  119. },
  120. .id_table = chtdc_ti_pmic_opregion_id_table,
  121. };
  122. builtin_platform_driver(chtdc_ti_pmic_opregion_driver);