intel_soc_dts_thermal.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * intel_soc_dts_thermal.c
  4. * Copyright (c) 2014, Intel Corporation.
  5. */
  6. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  7. #include <linux/acpi.h>
  8. #include <linux/module.h>
  9. #include <linux/interrupt.h>
  10. #include <asm/cpu_device_id.h>
  11. #include <asm/intel-family.h>
  12. #include "intel_soc_dts_iosf.h"
  13. #define CRITICAL_OFFSET_FROM_TJ_MAX 5000
  14. static int crit_offset = CRITICAL_OFFSET_FROM_TJ_MAX;
  15. module_param(crit_offset, int, 0644);
  16. MODULE_PARM_DESC(crit_offset,
  17. "Critical Temperature offset from tj max in millidegree Celsius.");
  18. /* IRQ 86 is a fixed APIC interrupt for BYT DTS Aux threshold notifications */
  19. #define BYT_SOC_DTS_APIC_IRQ 86
  20. static int soc_dts_thres_gsi;
  21. static int soc_dts_thres_irq;
  22. static struct intel_soc_dts_sensors *soc_dts;
  23. static irqreturn_t soc_irq_thread_fn(int irq, void *dev_data)
  24. {
  25. pr_debug("proc_thermal_interrupt\n");
  26. intel_soc_dts_iosf_interrupt_handler(soc_dts);
  27. return IRQ_HANDLED;
  28. }
  29. static const struct x86_cpu_id soc_thermal_ids[] = {
  30. X86_MATCH_VFM(INTEL_ATOM_SILVERMONT, BYT_SOC_DTS_APIC_IRQ),
  31. {}
  32. };
  33. MODULE_DEVICE_TABLE(x86cpu, soc_thermal_ids);
  34. static int __init intel_soc_thermal_init(void)
  35. {
  36. int err = 0;
  37. const struct x86_cpu_id *match_cpu;
  38. match_cpu = x86_match_cpu(soc_thermal_ids);
  39. if (!match_cpu)
  40. return -ENODEV;
  41. /* Create a zone with 2 trips with marked as read only */
  42. soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, true,
  43. crit_offset);
  44. if (IS_ERR(soc_dts)) {
  45. err = PTR_ERR(soc_dts);
  46. return err;
  47. }
  48. soc_dts_thres_gsi = (int)match_cpu->driver_data;
  49. if (soc_dts_thres_gsi) {
  50. /*
  51. * Note the flags here MUST match the firmware defaults, rather
  52. * then the request_irq flags, otherwise we get an EBUSY error.
  53. */
  54. soc_dts_thres_irq = acpi_register_gsi(NULL, soc_dts_thres_gsi,
  55. ACPI_LEVEL_SENSITIVE,
  56. ACPI_ACTIVE_LOW);
  57. if (soc_dts_thres_irq < 0) {
  58. pr_warn("intel_soc_dts: Could not get IRQ for GSI %d, err %d\n",
  59. soc_dts_thres_gsi, soc_dts_thres_irq);
  60. soc_dts_thres_irq = 0;
  61. }
  62. }
  63. if (soc_dts_thres_irq) {
  64. err = request_threaded_irq(soc_dts_thres_irq, NULL,
  65. soc_irq_thread_fn,
  66. IRQF_TRIGGER_RISING | IRQF_ONESHOT,
  67. "soc_dts", soc_dts);
  68. if (err) {
  69. /*
  70. * Do not just error out because the user space thermal
  71. * daemon such as DPTF may use polling instead of being
  72. * interrupt driven.
  73. */
  74. pr_warn("request_threaded_irq ret %d\n", err);
  75. }
  76. }
  77. return 0;
  78. }
  79. static void __exit intel_soc_thermal_exit(void)
  80. {
  81. if (soc_dts_thres_irq) {
  82. free_irq(soc_dts_thres_irq, soc_dts);
  83. acpi_unregister_gsi(soc_dts_thres_gsi);
  84. }
  85. intel_soc_dts_iosf_exit(soc_dts);
  86. }
  87. module_init(intel_soc_thermal_init)
  88. module_exit(intel_soc_thermal_exit)
  89. MODULE_DESCRIPTION("Intel SoC DTS Thermal Driver");
  90. MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
  91. MODULE_LICENSE("GPL v2");