intel_soc_dts_thermal.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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/module.h>
  17. #include <linux/interrupt.h>
  18. #include <asm/cpu_device_id.h>
  19. #include "intel_soc_dts_iosf.h"
  20. #define CRITICAL_OFFSET_FROM_TJ_MAX 5000
  21. static int crit_offset = CRITICAL_OFFSET_FROM_TJ_MAX;
  22. module_param(crit_offset, int, 0644);
  23. MODULE_PARM_DESC(crit_offset,
  24. "Critical Temperature offset from tj max in millidegree Celsius.");
  25. /* IRQ 86 is a fixed APIC interrupt for BYT DTS Aux threshold notifications */
  26. #define BYT_SOC_DTS_APIC_IRQ 86
  27. static int soc_dts_thres_irq;
  28. static struct intel_soc_dts_sensors *soc_dts;
  29. static irqreturn_t soc_irq_thread_fn(int irq, void *dev_data)
  30. {
  31. pr_debug("proc_thermal_interrupt\n");
  32. intel_soc_dts_iosf_interrupt_handler(soc_dts);
  33. return IRQ_HANDLED;
  34. }
  35. static const struct x86_cpu_id soc_thermal_ids[] = {
  36. { X86_VENDOR_INTEL, X86_FAMILY_ANY, 0x37, 0, BYT_SOC_DTS_APIC_IRQ},
  37. {}
  38. };
  39. MODULE_DEVICE_TABLE(x86cpu, soc_thermal_ids);
  40. static int __init intel_soc_thermal_init(void)
  41. {
  42. int err = 0;
  43. const struct x86_cpu_id *match_cpu;
  44. match_cpu = x86_match_cpu(soc_thermal_ids);
  45. if (!match_cpu)
  46. return -ENODEV;
  47. /* Create a zone with 2 trips with marked as read only */
  48. soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, 2, 1);
  49. if (IS_ERR(soc_dts)) {
  50. err = PTR_ERR(soc_dts);
  51. return err;
  52. }
  53. soc_dts_thres_irq = (int)match_cpu->driver_data;
  54. if (soc_dts_thres_irq) {
  55. err = request_threaded_irq(soc_dts_thres_irq, NULL,
  56. soc_irq_thread_fn,
  57. IRQF_TRIGGER_RISING | IRQF_ONESHOT,
  58. "soc_dts", soc_dts);
  59. if (err) {
  60. pr_err("request_threaded_irq ret %d\n", err);
  61. goto error_irq;
  62. }
  63. }
  64. err = intel_soc_dts_iosf_add_read_only_critical_trip(soc_dts,
  65. crit_offset);
  66. if (err)
  67. goto error_trips;
  68. return 0;
  69. error_trips:
  70. if (soc_dts_thres_irq)
  71. free_irq(soc_dts_thres_irq, soc_dts);
  72. error_irq:
  73. intel_soc_dts_iosf_exit(soc_dts);
  74. return err;
  75. }
  76. static void __exit intel_soc_thermal_exit(void)
  77. {
  78. if (soc_dts_thres_irq)
  79. free_irq(soc_dts_thres_irq, soc_dts);
  80. intel_soc_dts_iosf_exit(soc_dts);
  81. }
  82. module_init(intel_soc_thermal_init)
  83. module_exit(intel_soc_thermal_exit)
  84. MODULE_DESCRIPTION("Intel SoC DTS Thermal Driver");
  85. MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
  86. MODULE_LICENSE("GPL v2");