0001
0002
0003
0004
0005
0006
0007 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
0008
0009 #include <linux/acpi.h>
0010 #include <linux/module.h>
0011 #include <linux/interrupt.h>
0012 #include <asm/cpu_device_id.h>
0013 #include <asm/intel-family.h>
0014 #include "intel_soc_dts_iosf.h"
0015
0016 #define CRITICAL_OFFSET_FROM_TJ_MAX 5000
0017
0018 static int crit_offset = CRITICAL_OFFSET_FROM_TJ_MAX;
0019 module_param(crit_offset, int, 0644);
0020 MODULE_PARM_DESC(crit_offset,
0021 "Critical Temperature offset from tj max in millidegree Celsius.");
0022
0023
0024 #define BYT_SOC_DTS_APIC_IRQ 86
0025
0026 static int soc_dts_thres_gsi;
0027 static int soc_dts_thres_irq;
0028 static struct intel_soc_dts_sensors *soc_dts;
0029
0030 static irqreturn_t soc_irq_thread_fn(int irq, void *dev_data)
0031 {
0032 pr_debug("proc_thermal_interrupt\n");
0033 intel_soc_dts_iosf_interrupt_handler(soc_dts);
0034
0035 return IRQ_HANDLED;
0036 }
0037
0038 static const struct x86_cpu_id soc_thermal_ids[] = {
0039 X86_MATCH_INTEL_FAM6_MODEL(ATOM_SILVERMONT, BYT_SOC_DTS_APIC_IRQ),
0040 {}
0041 };
0042 MODULE_DEVICE_TABLE(x86cpu, soc_thermal_ids);
0043
0044 static int __init intel_soc_thermal_init(void)
0045 {
0046 int err = 0;
0047 const struct x86_cpu_id *match_cpu;
0048
0049 match_cpu = x86_match_cpu(soc_thermal_ids);
0050 if (!match_cpu)
0051 return -ENODEV;
0052
0053
0054 soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, 2, 1);
0055 if (IS_ERR(soc_dts)) {
0056 err = PTR_ERR(soc_dts);
0057 return err;
0058 }
0059
0060 soc_dts_thres_gsi = (int)match_cpu->driver_data;
0061 if (soc_dts_thres_gsi) {
0062
0063
0064
0065
0066 soc_dts_thres_irq = acpi_register_gsi(NULL, soc_dts_thres_gsi,
0067 ACPI_LEVEL_SENSITIVE,
0068 ACPI_ACTIVE_LOW);
0069 if (soc_dts_thres_irq < 0) {
0070 pr_warn("intel_soc_dts: Could not get IRQ for GSI %d, err %d\n",
0071 soc_dts_thres_gsi, soc_dts_thres_irq);
0072 soc_dts_thres_irq = 0;
0073 }
0074 }
0075
0076 if (soc_dts_thres_irq) {
0077 err = request_threaded_irq(soc_dts_thres_irq, NULL,
0078 soc_irq_thread_fn,
0079 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
0080 "soc_dts", soc_dts);
0081 if (err) {
0082
0083
0084
0085
0086
0087 pr_warn("request_threaded_irq ret %d\n", err);
0088 }
0089 }
0090
0091 err = intel_soc_dts_iosf_add_read_only_critical_trip(soc_dts,
0092 crit_offset);
0093 if (err)
0094 goto error_trips;
0095
0096 return 0;
0097
0098 error_trips:
0099 if (soc_dts_thres_irq) {
0100 free_irq(soc_dts_thres_irq, soc_dts);
0101 acpi_unregister_gsi(soc_dts_thres_gsi);
0102 }
0103 intel_soc_dts_iosf_exit(soc_dts);
0104
0105 return err;
0106 }
0107
0108 static void __exit intel_soc_thermal_exit(void)
0109 {
0110 if (soc_dts_thres_irq) {
0111 free_irq(soc_dts_thres_irq, soc_dts);
0112 acpi_unregister_gsi(soc_dts_thres_gsi);
0113 }
0114 intel_soc_dts_iosf_exit(soc_dts);
0115 }
0116
0117 module_init(intel_soc_thermal_init)
0118 module_exit(intel_soc_thermal_exit)
0119
0120 MODULE_DESCRIPTION("Intel SoC DTS Thermal Driver");
0121 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
0122 MODULE_LICENSE("GPL v2");