Linux 4.19.133
[linux/fpc-iii.git] / drivers / thermal / intel_soc_dts_thermal.c
blobd748527d7a38a98737a1f3e4d70e1cbda048a921
1 /*
2 * intel_soc_dts_thermal.c
3 * Copyright (c) 2014, Intel Corporation.
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.
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.
16 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
18 #include <linux/acpi.h>
19 #include <linux/module.h>
20 #include <linux/interrupt.h>
21 #include <asm/cpu_device_id.h>
22 #include <asm/intel-family.h>
23 #include "intel_soc_dts_iosf.h"
25 #define CRITICAL_OFFSET_FROM_TJ_MAX 5000
27 static int crit_offset = CRITICAL_OFFSET_FROM_TJ_MAX;
28 module_param(crit_offset, int, 0644);
29 MODULE_PARM_DESC(crit_offset,
30 "Critical Temperature offset from tj max in millidegree Celsius.");
32 /* IRQ 86 is a fixed APIC interrupt for BYT DTS Aux threshold notifications */
33 #define BYT_SOC_DTS_APIC_IRQ 86
35 static int soc_dts_thres_gsi;
36 static int soc_dts_thres_irq;
37 static struct intel_soc_dts_sensors *soc_dts;
39 static irqreturn_t soc_irq_thread_fn(int irq, void *dev_data)
41 pr_debug("proc_thermal_interrupt\n");
42 intel_soc_dts_iosf_interrupt_handler(soc_dts);
44 return IRQ_HANDLED;
47 static const struct x86_cpu_id soc_thermal_ids[] = {
48 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT, 0,
49 BYT_SOC_DTS_APIC_IRQ},
52 MODULE_DEVICE_TABLE(x86cpu, soc_thermal_ids);
54 static int __init intel_soc_thermal_init(void)
56 int err = 0;
57 const struct x86_cpu_id *match_cpu;
59 match_cpu = x86_match_cpu(soc_thermal_ids);
60 if (!match_cpu)
61 return -ENODEV;
63 /* Create a zone with 2 trips with marked as read only */
64 soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, 2, 1);
65 if (IS_ERR(soc_dts)) {
66 err = PTR_ERR(soc_dts);
67 return err;
70 soc_dts_thres_gsi = (int)match_cpu->driver_data;
71 if (soc_dts_thres_gsi) {
73 * Note the flags here MUST match the firmware defaults, rather
74 * then the request_irq flags, otherwise we get an EBUSY error.
76 soc_dts_thres_irq = acpi_register_gsi(NULL, soc_dts_thres_gsi,
77 ACPI_LEVEL_SENSITIVE,
78 ACPI_ACTIVE_LOW);
79 if (soc_dts_thres_irq < 0) {
80 pr_warn("intel_soc_dts: Could not get IRQ for GSI %d, err %d\n",
81 soc_dts_thres_gsi, soc_dts_thres_irq);
82 soc_dts_thres_irq = 0;
86 if (soc_dts_thres_irq) {
87 err = request_threaded_irq(soc_dts_thres_irq, NULL,
88 soc_irq_thread_fn,
89 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
90 "soc_dts", soc_dts);
91 if (err) {
93 * Do not just error out because the user space thermal
94 * daemon such as DPTF may use polling instead of being
95 * interrupt driven.
97 pr_warn("request_threaded_irq ret %d\n", err);
101 err = intel_soc_dts_iosf_add_read_only_critical_trip(soc_dts,
102 crit_offset);
103 if (err)
104 goto error_trips;
106 return 0;
108 error_trips:
109 if (soc_dts_thres_irq) {
110 free_irq(soc_dts_thres_irq, soc_dts);
111 acpi_unregister_gsi(soc_dts_thres_gsi);
113 intel_soc_dts_iosf_exit(soc_dts);
115 return err;
118 static void __exit intel_soc_thermal_exit(void)
120 if (soc_dts_thres_irq) {
121 free_irq(soc_dts_thres_irq, soc_dts);
122 acpi_unregister_gsi(soc_dts_thres_gsi);
124 intel_soc_dts_iosf_exit(soc_dts);
127 module_init(intel_soc_thermal_init)
128 module_exit(intel_soc_thermal_exit)
130 MODULE_DESCRIPTION("Intel SoC DTS Thermal Driver");
131 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
132 MODULE_LICENSE("GPL v2");