blob: 18788109cae63973e88a5ed11aa583097da7776b [file] [log] [blame]
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -07001/*
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
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17
18#include <linux/module.h>
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070019#include <linux/interrupt.h>
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070020#include <asm/cpu_device_id.h>
Dave Hansence53da02016-06-02 17:19:52 -070021#include <asm/intel-family.h>
Srinivas Pandruvada3a2419f2015-03-02 13:12:59 -080022#include "intel_soc_dts_iosf.h"
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070023
24#define CRITICAL_OFFSET_FROM_TJ_MAX 5000
25
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070026static int crit_offset = CRITICAL_OFFSET_FROM_TJ_MAX;
27module_param(crit_offset, int, 0644);
28MODULE_PARM_DESC(crit_offset,
29 "Critical Temperature offset from tj max in millidegree Celsius.");
30
Srinivas Pandruvada3a2419f2015-03-02 13:12:59 -080031/* IRQ 86 is a fixed APIC interrupt for BYT DTS Aux threshold notifications */
32#define BYT_SOC_DTS_APIC_IRQ 86
33
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070034static int soc_dts_thres_irq;
Srinivas Pandruvada3a2419f2015-03-02 13:12:59 -080035static struct intel_soc_dts_sensors *soc_dts;
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070036
37static irqreturn_t soc_irq_thread_fn(int irq, void *dev_data)
38{
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070039 pr_debug("proc_thermal_interrupt\n");
Srinivas Pandruvada3a2419f2015-03-02 13:12:59 -080040 intel_soc_dts_iosf_interrupt_handler(soc_dts);
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070041
42 return IRQ_HANDLED;
43}
44
45static const struct x86_cpu_id soc_thermal_ids[] = {
Peter Zijlstra1739ba82018-08-07 10:17:27 -070046 { X86_VENDOR_INTEL, 6, INTEL_FAM6_ATOM_SILVERMONT, 0,
Dave Hansence53da02016-06-02 17:19:52 -070047 BYT_SOC_DTS_APIC_IRQ},
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070048 {}
49};
50MODULE_DEVICE_TABLE(x86cpu, soc_thermal_ids);
51
52static int __init intel_soc_thermal_init(void)
53{
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070054 int err = 0;
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070055 const struct x86_cpu_id *match_cpu;
56
57 match_cpu = x86_match_cpu(soc_thermal_ids);
58 if (!match_cpu)
59 return -ENODEV;
60
Srinivas Pandruvada3a2419f2015-03-02 13:12:59 -080061 /* Create a zone with 2 trips with marked as read only */
62 soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, 2, 1);
63 if (IS_ERR(soc_dts)) {
64 err = PTR_ERR(soc_dts);
65 return err;
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070066 }
67
Srinivas Pandruvada3a2419f2015-03-02 13:12:59 -080068 soc_dts_thres_irq = (int)match_cpu->driver_data;
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070069
Srinivas Pandruvada6c355fa2015-01-28 11:48:02 -080070 if (soc_dts_thres_irq) {
71 err = request_threaded_irq(soc_dts_thres_irq, NULL,
72 soc_irq_thread_fn,
73 IRQF_TRIGGER_RISING | IRQF_ONESHOT,
74 "soc_dts", soc_dts);
75 if (err) {
76 pr_err("request_threaded_irq ret %d\n", err);
Srinivas Pandruvada3a2419f2015-03-02 13:12:59 -080077 goto error_irq;
Srinivas Pandruvada6c355fa2015-01-28 11:48:02 -080078 }
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070079 }
80
Srinivas Pandruvada3a2419f2015-03-02 13:12:59 -080081 err = intel_soc_dts_iosf_add_read_only_critical_trip(soc_dts,
82 crit_offset);
83 if (err)
84 goto error_trips;
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070085
86 return 0;
87
Srinivas Pandruvada3a2419f2015-03-02 13:12:59 -080088error_trips:
Srinivas Pandruvada6c355fa2015-01-28 11:48:02 -080089 if (soc_dts_thres_irq)
90 free_irq(soc_dts_thres_irq, soc_dts);
Srinivas Pandruvada3a2419f2015-03-02 13:12:59 -080091error_irq:
92 intel_soc_dts_iosf_exit(soc_dts);
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -070093
94 return err;
95}
96
97static void __exit intel_soc_thermal_exit(void)
98{
Srinivas Pandruvada6c355fa2015-01-28 11:48:02 -080099 if (soc_dts_thres_irq)
100 free_irq(soc_dts_thres_irq, soc_dts);
Srinivas Pandruvada3a2419f2015-03-02 13:12:59 -0800101 intel_soc_dts_iosf_exit(soc_dts);
Srinivas Pandruvadabc40b5e2014-04-07 13:57:15 -0700102}
103
104module_init(intel_soc_thermal_init)
105module_exit(intel_soc_thermal_exit)
106
107MODULE_DESCRIPTION("Intel SoC DTS Thermal Driver");
108MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
109MODULE_LICENSE("GPL v2");