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