intel_soc_dts_thermal.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * intel_soc_dts_thermal.c
  3. * Copyright (c) 2014, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. */
  15. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  16. #include <linux/acpi.h>
  17. #include <linux/module.h>
  18. #include <linux/interrupt.h>
  19. #include <asm/cpu_device_id.h>
  20. #include <asm/intel-family.h>
  21. #include "intel_soc_dts_iosf.h"
  22. #define CRITICAL_OFFSET_FROM_TJ_MAX 5000
  23. static int crit_offset = CRITICAL_OFFSET_FROM_TJ_MAX;
  24. module_param(crit_offset, int, 0644);
  25. MODULE_PARM_DESC(crit_offset,
  26. "Critical Temperature offset from tj max in millidegree Celsius.");
  27. /* IRQ 86 is a fixed APIC interrupt for BYT DTS Aux threshold notifications */
  28. #define BYT_SOC_DTS_APIC_IRQ 86
  29. static int soc_dts_thres_gsi;
  30. static int soc_dts_thres_irq;
  31. static struct intel_soc_dts_sensors *soc_dts;
  32. static irqreturn_t soc_irq_thread_fn(int irq, void *dev_data)
  33. {
  34. pr_debug("proc_thermal_interrupt\n");
  35. intel_soc_dts_iosf_interrupt_handler(soc_dts);
  36. return IRQ_HANDLED;
  37. }
  38. static const struct x86_cpu_id soc_thermal_ids[] = {
  39. { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT, 0,
  40. BYT_SOC_DTS_APIC_IRQ},
  41. {}
  42. };
  43. MODULE_DEVICE_TABLE(x86cpu, soc_thermal_ids);
  44. static int __init intel_soc_thermal_init(void)
  45. {
  46. int err = 0;
  47. const struct x86_cpu_id *match_cpu;
  48. match_cpu = x86_match_cpu(soc_thermal_ids);
  49. if (!match_cpu)
  50. return -ENODEV;
  51. /* Create a zone with 2 trips with marked as read only */
  52. soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, 2, 1);
  53. if (IS_ERR(soc_dts)) {
  54. err = PTR_ERR(soc_dts);
  55. return err;
  56. }
  57. soc_dts_thres_gsi = (int)match_cpu->driver_data;
  58. if (soc_dts_thres_gsi) {
  59. /*
  60. * Note the flags here MUST match the firmware defaults, rather
  61. * then the request_irq flags, otherwise we get an EBUSY error.
  62. */
  63. soc_dts_thres_irq = acpi_register_gsi(NULL, soc_dts_thres_gsi,
  64. ACPI_LEVEL_SENSITIVE,
  65. ACPI_ACTIVE_LOW);
  66. if (soc_dts_thres_irq < 0) {
  67. pr_warn("intel_soc_dts: Could not get IRQ for GSI %d, err %d\n",
  68. soc_dts_thres_gsi, soc_dts_thres_irq);
  69. soc_dts_thres_irq = 0;
  70. }
  71. }
  72. if (soc_dts_thres_irq) {
  73. err = request_threaded_irq(soc_dts_thres_irq, NULL,
  74. soc_irq_thread_fn,
  75. IRQF_TRIGGER_RISING | IRQF_ONESHOT,
  76. "soc_dts", soc_dts);
  77. if (err) {
  78. /*
  79. * Do not just error out because the user space thermal
  80. * daemon such as DPTF may use polling instead of being
  81. * interrupt driven.
  82. */
  83. pr_warn("request_threaded_irq ret %d\n", err);
  84. }
  85. }
  86. err = intel_soc_dts_iosf_add_read_only_critical_trip(soc_dts,
  87. crit_offset);
  88. if (err)
  89. goto error_trips;
  90. return 0;
  91. error_trips:
  92. if (soc_dts_thres_irq) {
  93. free_irq(soc_dts_thres_irq, soc_dts);
  94. acpi_unregister_gsi(soc_dts_thres_gsi);
  95. }
  96. intel_soc_dts_iosf_exit(soc_dts);
  97. return err;
  98. }
  99. static void __exit intel_soc_thermal_exit(void)
  100. {
  101. if (soc_dts_thres_irq) {
  102. free_irq(soc_dts_thres_irq, soc_dts);
  103. acpi_unregister_gsi(soc_dts_thres_gsi);
  104. }
  105. intel_soc_dts_iosf_exit(soc_dts);
  106. }
  107. module_init(intel_soc_thermal_init)
  108. module_exit(intel_soc_thermal_exit)
  109. MODULE_DESCRIPTION("Intel SoC DTS Thermal Driver");
  110. MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
  111. MODULE_LICENSE("GPL v2");