1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * processor_thermal_device.c
4  * Copyright (c) 2014, Intel Corporation.
5  */
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/init.h>
9 #include <linux/pci.h>
10 #include <linux/interrupt.h>
11 #include <linux/platform_device.h>
12 #include <linux/acpi.h>
13 #include <linux/thermal.h>
14 #include <linux/cpuhotplug.h>
15 #include <linux/intel_rapl.h>
16 #include "int340x_thermal_zone.h"
17 #include "../intel_soc_dts_iosf.h"
18 
19 /* Broadwell-U/HSB thermal reporting device */
20 #define PCI_DEVICE_ID_PROC_BDW_THERMAL	0x1603
21 #define PCI_DEVICE_ID_PROC_HSB_THERMAL	0x0A03
22 
23 /* Skylake thermal reporting device */
24 #define PCI_DEVICE_ID_PROC_SKL_THERMAL	0x1903
25 
26 /* CannonLake thermal reporting device */
27 #define PCI_DEVICE_ID_PROC_CNL_THERMAL	0x5a03
28 #define PCI_DEVICE_ID_PROC_CFL_THERMAL	0x3E83
29 
30 /* Braswell thermal reporting device */
31 #define PCI_DEVICE_ID_PROC_BSW_THERMAL	0x22DC
32 
33 /* Broxton thermal reporting device */
34 #define PCI_DEVICE_ID_PROC_BXT0_THERMAL  0x0A8C
35 #define PCI_DEVICE_ID_PROC_BXT1_THERMAL  0x1A8C
36 #define PCI_DEVICE_ID_PROC_BXTX_THERMAL  0x4A8C
37 #define PCI_DEVICE_ID_PROC_BXTP_THERMAL  0x5A8C
38 
39 /* GeminiLake thermal reporting device */
40 #define PCI_DEVICE_ID_PROC_GLK_THERMAL	0x318C
41 
42 #define DRV_NAME "proc_thermal"
43 
44 struct power_config {
45 	u32	index;
46 	u32	min_uw;
47 	u32	max_uw;
48 	u32	tmin_us;
49 	u32	tmax_us;
50 	u32	step_uw;
51 };
52 
53 struct proc_thermal_device {
54 	struct device *dev;
55 	struct acpi_device *adev;
56 	struct power_config power_limits[2];
57 	struct int34x_thermal_zone *int340x_zone;
58 	struct intel_soc_dts_sensors *soc_dts;
59 	void __iomem *mmio_base;
60 };
61 
62 enum proc_thermal_emum_mode_type {
63 	PROC_THERMAL_NONE,
64 	PROC_THERMAL_PCI,
65 	PROC_THERMAL_PLATFORM_DEV
66 };
67 
68 struct rapl_mmio_regs {
69 	u64 reg_unit;
70 	u64 regs[RAPL_DOMAIN_MAX][RAPL_DOMAIN_REG_MAX];
71 	int limits[RAPL_DOMAIN_MAX];
72 };
73 
74 /*
75  * We can have only one type of enumeration, PCI or Platform,
76  * not both. So we don't need instance specific data.
77  */
78 static enum proc_thermal_emum_mode_type proc_thermal_emum_mode =
79 							PROC_THERMAL_NONE;
80 
81 #define POWER_LIMIT_SHOW(index, suffix) \
82 static ssize_t power_limit_##index##_##suffix##_show(struct device *dev, \
83 					struct device_attribute *attr, \
84 					char *buf) \
85 { \
86 	struct proc_thermal_device *proc_dev = dev_get_drvdata(dev); \
87 	\
88 	if (proc_thermal_emum_mode == PROC_THERMAL_NONE) { \
89 		dev_warn(dev, "Attempted to get power limit before device was initialized!\n"); \
90 		return 0; \
91 	} \
92 	\
93 	return sprintf(buf, "%lu\n",\
94 	(unsigned long)proc_dev->power_limits[index].suffix * 1000); \
95 }
96 
97 POWER_LIMIT_SHOW(0, min_uw)
98 POWER_LIMIT_SHOW(0, max_uw)
99 POWER_LIMIT_SHOW(0, step_uw)
100 POWER_LIMIT_SHOW(0, tmin_us)
101 POWER_LIMIT_SHOW(0, tmax_us)
102 
103 POWER_LIMIT_SHOW(1, min_uw)
104 POWER_LIMIT_SHOW(1, max_uw)
105 POWER_LIMIT_SHOW(1, step_uw)
106 POWER_LIMIT_SHOW(1, tmin_us)
107 POWER_LIMIT_SHOW(1, tmax_us)
108 
109 static DEVICE_ATTR_RO(power_limit_0_min_uw);
110 static DEVICE_ATTR_RO(power_limit_0_max_uw);
111 static DEVICE_ATTR_RO(power_limit_0_step_uw);
112 static DEVICE_ATTR_RO(power_limit_0_tmin_us);
113 static DEVICE_ATTR_RO(power_limit_0_tmax_us);
114 
115 static DEVICE_ATTR_RO(power_limit_1_min_uw);
116 static DEVICE_ATTR_RO(power_limit_1_max_uw);
117 static DEVICE_ATTR_RO(power_limit_1_step_uw);
118 static DEVICE_ATTR_RO(power_limit_1_tmin_us);
119 static DEVICE_ATTR_RO(power_limit_1_tmax_us);
120 
121 static struct attribute *power_limit_attrs[] = {
122 	&dev_attr_power_limit_0_min_uw.attr,
123 	&dev_attr_power_limit_1_min_uw.attr,
124 	&dev_attr_power_limit_0_max_uw.attr,
125 	&dev_attr_power_limit_1_max_uw.attr,
126 	&dev_attr_power_limit_0_step_uw.attr,
127 	&dev_attr_power_limit_1_step_uw.attr,
128 	&dev_attr_power_limit_0_tmin_us.attr,
129 	&dev_attr_power_limit_1_tmin_us.attr,
130 	&dev_attr_power_limit_0_tmax_us.attr,
131 	&dev_attr_power_limit_1_tmax_us.attr,
132 	NULL
133 };
134 
135 static const struct attribute_group power_limit_attribute_group = {
136 	.attrs = power_limit_attrs,
137 	.name = "power_limits"
138 };
139 
140 static int stored_tjmax; /* since it is fixed, we can have local storage */
141 
142 static int get_tjmax(void)
143 {
144 	u32 eax, edx;
145 	u32 val;
146 	int err;
147 
148 	err = rdmsr_safe(MSR_IA32_TEMPERATURE_TARGET, &eax, &edx);
149 	if (err)
150 		return err;
151 
152 	val = (eax >> 16) & 0xff;
153 	if (val)
154 		return val;
155 
156 	return -EINVAL;
157 }
158 
159 static int read_temp_msr(int *temp)
160 {
161 	int cpu;
162 	u32 eax, edx;
163 	int err;
164 	unsigned long curr_temp_off = 0;
165 
166 	*temp = 0;
167 
168 	for_each_online_cpu(cpu) {
169 		err = rdmsr_safe_on_cpu(cpu, MSR_IA32_THERM_STATUS, &eax,
170 					&edx);
171 		if (err)
172 			goto err_ret;
173 		else {
174 			if (eax & 0x80000000) {
175 				curr_temp_off = (eax >> 16) & 0x7f;
176 				if (!*temp || curr_temp_off < *temp)
177 					*temp = curr_temp_off;
178 			} else {
179 				err = -EINVAL;
180 				goto err_ret;
181 			}
182 		}
183 	}
184 
185 	return 0;
186 err_ret:
187 	return err;
188 }
189 
190 static int proc_thermal_get_zone_temp(struct thermal_zone_device *zone,
191 					 int *temp)
192 {
193 	int ret;
194 
195 	ret = read_temp_msr(temp);
196 	if (!ret)
197 		*temp = (stored_tjmax - *temp) * 1000;
198 
199 	return ret;
200 }
201 
202 static struct thermal_zone_device_ops proc_thermal_local_ops = {
203 	.get_temp       = proc_thermal_get_zone_temp,
204 };
205 
206 static int proc_thermal_read_ppcc(struct proc_thermal_device *proc_priv)
207 {
208 	int i;
209 	acpi_status status;
210 	struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER, NULL };
211 	union acpi_object *elements, *ppcc;
212 	union acpi_object *p;
213 	int ret = 0;
214 
215 	status = acpi_evaluate_object(proc_priv->adev->handle, "PPCC",
216 				      NULL, &buf);
217 	if (ACPI_FAILURE(status))
218 		return -ENODEV;
219 
220 	p = buf.pointer;
221 	if (!p || (p->type != ACPI_TYPE_PACKAGE)) {
222 		dev_err(proc_priv->dev, "Invalid PPCC data\n");
223 		ret = -EFAULT;
224 		goto free_buffer;
225 	}
226 
227 	if (!p->package.count) {
228 		dev_err(proc_priv->dev, "Invalid PPCC package size\n");
229 		ret = -EFAULT;
230 		goto free_buffer;
231 	}
232 
233 	for (i = 0; i < min((int)p->package.count - 1, 2); ++i) {
234 		elements = &(p->package.elements[i+1]);
235 		if (elements->type != ACPI_TYPE_PACKAGE ||
236 		    elements->package.count != 6) {
237 			ret = -EFAULT;
238 			goto free_buffer;
239 		}
240 		ppcc = elements->package.elements;
241 		proc_priv->power_limits[i].index = ppcc[0].integer.value;
242 		proc_priv->power_limits[i].min_uw = ppcc[1].integer.value;
243 		proc_priv->power_limits[i].max_uw = ppcc[2].integer.value;
244 		proc_priv->power_limits[i].tmin_us = ppcc[3].integer.value;
245 		proc_priv->power_limits[i].tmax_us = ppcc[4].integer.value;
246 		proc_priv->power_limits[i].step_uw = ppcc[5].integer.value;
247 	}
248 
249 free_buffer:
250 	kfree(buf.pointer);
251 
252 	return ret;
253 }
254 
255 #define PROC_POWER_CAPABILITY_CHANGED	0x83
256 static void proc_thermal_notify(acpi_handle handle, u32 event, void *data)
257 {
258 	struct proc_thermal_device *proc_priv = data;
259 
260 	if (!proc_priv)
261 		return;
262 
263 	switch (event) {
264 	case PROC_POWER_CAPABILITY_CHANGED:
265 		proc_thermal_read_ppcc(proc_priv);
266 		int340x_thermal_zone_device_update(proc_priv->int340x_zone,
267 				THERMAL_DEVICE_POWER_CAPABILITY_CHANGED);
268 		break;
269 	default:
270 		dev_dbg(proc_priv->dev, "Unsupported event [0x%x]\n", event);
271 		break;
272 	}
273 }
274 
275 
276 static int proc_thermal_add(struct device *dev,
277 			    struct proc_thermal_device **priv)
278 {
279 	struct proc_thermal_device *proc_priv;
280 	struct acpi_device *adev;
281 	acpi_status status;
282 	unsigned long long tmp;
283 	struct thermal_zone_device_ops *ops = NULL;
284 	int ret;
285 
286 	adev = ACPI_COMPANION(dev);
287 	if (!adev)
288 		return -ENODEV;
289 
290 	proc_priv = devm_kzalloc(dev, sizeof(*proc_priv), GFP_KERNEL);
291 	if (!proc_priv)
292 		return -ENOMEM;
293 
294 	proc_priv->dev = dev;
295 	proc_priv->adev = adev;
296 	*priv = proc_priv;
297 
298 	ret = proc_thermal_read_ppcc(proc_priv);
299 	if (ret)
300 		return ret;
301 
302 	status = acpi_evaluate_integer(adev->handle, "_TMP", NULL, &tmp);
303 	if (ACPI_FAILURE(status)) {
304 		/* there is no _TMP method, add local method */
305 		stored_tjmax = get_tjmax();
306 		if (stored_tjmax > 0)
307 			ops = &proc_thermal_local_ops;
308 	}
309 
310 	proc_priv->int340x_zone = int340x_thermal_zone_add(adev, ops);
311 	if (IS_ERR(proc_priv->int340x_zone)) {
312 		return PTR_ERR(proc_priv->int340x_zone);
313 	} else
314 		ret = 0;
315 
316 	ret = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY,
317 					  proc_thermal_notify,
318 					  (void *)proc_priv);
319 	if (ret)
320 		goto remove_zone;
321 
322 	return 0;
323 
324 remove_zone:
325 	int340x_thermal_zone_remove(proc_priv->int340x_zone);
326 
327 	return ret;
328 }
329 
330 static void proc_thermal_remove(struct proc_thermal_device *proc_priv)
331 {
332 	acpi_remove_notify_handler(proc_priv->adev->handle,
333 				   ACPI_DEVICE_NOTIFY, proc_thermal_notify);
334 	int340x_thermal_zone_remove(proc_priv->int340x_zone);
335 	sysfs_remove_group(&proc_priv->dev->kobj,
336 			   &power_limit_attribute_group);
337 }
338 
339 static int int3401_add(struct platform_device *pdev)
340 {
341 	struct proc_thermal_device *proc_priv;
342 	int ret;
343 
344 	if (proc_thermal_emum_mode == PROC_THERMAL_PCI) {
345 		dev_err(&pdev->dev, "error: enumerated as PCI dev\n");
346 		return -ENODEV;
347 	}
348 
349 	ret = proc_thermal_add(&pdev->dev, &proc_priv);
350 	if (ret)
351 		return ret;
352 
353 	platform_set_drvdata(pdev, proc_priv);
354 	proc_thermal_emum_mode = PROC_THERMAL_PLATFORM_DEV;
355 
356 	dev_info(&pdev->dev, "Creating sysfs group for PROC_THERMAL_PLATFORM_DEV\n");
357 
358 	return sysfs_create_group(&pdev->dev.kobj,
359 					 &power_limit_attribute_group);
360 }
361 
362 static int int3401_remove(struct platform_device *pdev)
363 {
364 	proc_thermal_remove(platform_get_drvdata(pdev));
365 
366 	return 0;
367 }
368 
369 static irqreturn_t proc_thermal_pci_msi_irq(int irq, void *devid)
370 {
371 	struct proc_thermal_device *proc_priv;
372 	struct pci_dev *pdev = devid;
373 
374 	proc_priv = pci_get_drvdata(pdev);
375 
376 	intel_soc_dts_iosf_interrupt_handler(proc_priv->soc_dts);
377 
378 	return IRQ_HANDLED;
379 }
380 
381 #ifdef CONFIG_PROC_THERMAL_MMIO_RAPL
382 
383 #define MCHBAR 0
384 
385 /* RAPL Support via MMIO interface */
386 static struct rapl_if_priv rapl_mmio_priv;
387 
388 static int rapl_mmio_cpu_online(unsigned int cpu)
389 {
390 	struct rapl_package *rp;
391 
392 	/* mmio rapl supports package 0 only for now */
393 	if (topology_physical_package_id(cpu))
394 		return 0;
395 
396 	rp = rapl_find_package_domain(cpu, &rapl_mmio_priv);
397 	if (!rp) {
398 		rp = rapl_add_package(cpu, &rapl_mmio_priv);
399 		if (IS_ERR(rp))
400 			return PTR_ERR(rp);
401 	}
402 	cpumask_set_cpu(cpu, &rp->cpumask);
403 	return 0;
404 }
405 
406 static int rapl_mmio_cpu_down_prep(unsigned int cpu)
407 {
408 	struct rapl_package *rp;
409 	int lead_cpu;
410 
411 	rp = rapl_find_package_domain(cpu, &rapl_mmio_priv);
412 	if (!rp)
413 		return 0;
414 
415 	cpumask_clear_cpu(cpu, &rp->cpumask);
416 	lead_cpu = cpumask_first(&rp->cpumask);
417 	if (lead_cpu >= nr_cpu_ids)
418 		rapl_remove_package(rp);
419 	else if (rp->lead_cpu == cpu)
420 		rp->lead_cpu = lead_cpu;
421 	return 0;
422 }
423 
424 static int rapl_mmio_read_raw(int cpu, struct reg_action *ra)
425 {
426 	if (!ra->reg)
427 		return -EINVAL;
428 
429 	ra->value = readq((void __iomem *)ra->reg);
430 	ra->value &= ra->mask;
431 	return 0;
432 }
433 
434 static int rapl_mmio_write_raw(int cpu, struct reg_action *ra)
435 {
436 	u64 val;
437 
438 	if (!ra->reg)
439 		return -EINVAL;
440 
441 	val = readq((void __iomem *)ra->reg);
442 	val &= ~ra->mask;
443 	val |= ra->value;
444 	writeq(val, (void __iomem *)ra->reg);
445 	return 0;
446 }
447 
448 static int proc_thermal_rapl_add(struct pci_dev *pdev,
449 				 struct proc_thermal_device *proc_priv,
450 				 struct rapl_mmio_regs *rapl_regs)
451 {
452 	enum rapl_domain_reg_id reg;
453 	enum rapl_domain_type domain;
454 	int ret;
455 
456 	if (!rapl_regs)
457 		return 0;
458 
459 	ret = pcim_iomap_regions(pdev, 1 << MCHBAR, DRV_NAME);
460 	if (ret) {
461 		dev_err(&pdev->dev, "cannot reserve PCI memory region\n");
462 		return -ENOMEM;
463 	}
464 
465 	proc_priv->mmio_base = pcim_iomap_table(pdev)[MCHBAR];
466 
467 	for (domain = RAPL_DOMAIN_PACKAGE; domain < RAPL_DOMAIN_MAX; domain++) {
468 		for (reg = RAPL_DOMAIN_REG_LIMIT; reg < RAPL_DOMAIN_REG_MAX; reg++)
469 			if (rapl_regs->regs[domain][reg])
470 				rapl_mmio_priv.regs[domain][reg] =
471 						(u64)proc_priv->mmio_base +
472 						rapl_regs->regs[domain][reg];
473 		rapl_mmio_priv.limits[domain] = rapl_regs->limits[domain];
474 	}
475 	rapl_mmio_priv.reg_unit = (u64)proc_priv->mmio_base + rapl_regs->reg_unit;
476 
477 	rapl_mmio_priv.read_raw = rapl_mmio_read_raw;
478 	rapl_mmio_priv.write_raw = rapl_mmio_write_raw;
479 
480 	rapl_mmio_priv.control_type = powercap_register_control_type(NULL, "intel-rapl-mmio", NULL);
481 	if (IS_ERR(rapl_mmio_priv.control_type)) {
482 		pr_debug("failed to register powercap control_type.\n");
483 		return PTR_ERR(rapl_mmio_priv.control_type);
484 	}
485 
486 	ret = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "powercap/rapl:online",
487 				rapl_mmio_cpu_online, rapl_mmio_cpu_down_prep);
488 	if (ret < 0) {
489 		powercap_unregister_control_type(rapl_mmio_priv.control_type);
490 		rapl_mmio_priv.control_type = NULL;
491 		return ret;
492 	}
493 	rapl_mmio_priv.pcap_rapl_online = ret;
494 
495 	return 0;
496 }
497 
498 static void proc_thermal_rapl_remove(void)
499 {
500 	if (IS_ERR_OR_NULL(rapl_mmio_priv.control_type))
501 		return;
502 
503 	cpuhp_remove_state(rapl_mmio_priv.pcap_rapl_online);
504 	powercap_unregister_control_type(rapl_mmio_priv.control_type);
505 }
506 
507 static const struct rapl_mmio_regs rapl_mmio_hsw = {
508 	.reg_unit = 0x5938,
509 	.regs[RAPL_DOMAIN_PACKAGE] = { 0x59a0, 0x593c, 0x58f0, 0, 0x5930},
510 	.regs[RAPL_DOMAIN_DRAM] = { 0x58e0, 0x58e8, 0x58ec, 0, 0},
511 	.limits[RAPL_DOMAIN_PACKAGE] = 2,
512 	.limits[RAPL_DOMAIN_DRAM] = 2,
513 };
514 
515 #else
516 
517 static int proc_thermal_rapl_add(struct pci_dev *pdev,
518 				 struct proc_thermal_device *proc_priv,
519 				 struct rapl_mmio_regs *rapl_regs)
520 {
521 	return 0;
522 }
523 static void proc_thermal_rapl_remove(void) {}
524 static const struct rapl_mmio_regs rapl_mmio_hsw;
525 
526 #endif /* CONFIG_MMIO_RAPL */
527 
528 static int  proc_thermal_pci_probe(struct pci_dev *pdev,
529 				   const struct pci_device_id *id)
530 {
531 	struct proc_thermal_device *proc_priv;
532 	int ret;
533 
534 	if (proc_thermal_emum_mode == PROC_THERMAL_PLATFORM_DEV) {
535 		dev_err(&pdev->dev, "error: enumerated as platform dev\n");
536 		return -ENODEV;
537 	}
538 
539 	ret = pcim_enable_device(pdev);
540 	if (ret < 0) {
541 		dev_err(&pdev->dev, "error: could not enable device\n");
542 		return ret;
543 	}
544 
545 	ret = proc_thermal_add(&pdev->dev, &proc_priv);
546 	if (ret)
547 		return ret;
548 
549 	ret = proc_thermal_rapl_add(pdev, proc_priv,
550 				(struct rapl_mmio_regs *)id->driver_data);
551 	if (ret) {
552 		dev_err(&pdev->dev, "failed to add RAPL MMIO interface\n");
553 		proc_thermal_remove(proc_priv);
554 		return ret;
555 	}
556 
557 	pci_set_drvdata(pdev, proc_priv);
558 	proc_thermal_emum_mode = PROC_THERMAL_PCI;
559 
560 	if (pdev->device == PCI_DEVICE_ID_PROC_BSW_THERMAL) {
561 		/*
562 		 * Enumerate additional DTS sensors available via IOSF.
563 		 * But we are not treating as a failure condition, if
564 		 * there are no aux DTSs enabled or fails. This driver
565 		 * already exposes sensors, which can be accessed via
566 		 * ACPI/MSR. So we don't want to fail for auxiliary DTSs.
567 		 */
568 		proc_priv->soc_dts = intel_soc_dts_iosf_init(
569 					INTEL_SOC_DTS_INTERRUPT_MSI, 2, 0);
570 
571 		if (!IS_ERR(proc_priv->soc_dts) && pdev->irq) {
572 			ret = pci_enable_msi(pdev);
573 			if (!ret) {
574 				ret = request_threaded_irq(pdev->irq, NULL,
575 						proc_thermal_pci_msi_irq,
576 						IRQF_ONESHOT, "proc_thermal",
577 						pdev);
578 				if (ret) {
579 					intel_soc_dts_iosf_exit(
580 							proc_priv->soc_dts);
581 					pci_disable_msi(pdev);
582 					proc_priv->soc_dts = NULL;
583 				}
584 			}
585 		} else
586 			dev_err(&pdev->dev, "No auxiliary DTSs enabled\n");
587 	}
588 
589 	dev_info(&pdev->dev, "Creating sysfs group for PROC_THERMAL_PCI\n");
590 
591 	return sysfs_create_group(&pdev->dev.kobj,
592 					 &power_limit_attribute_group);
593 }
594 
595 static void  proc_thermal_pci_remove(struct pci_dev *pdev)
596 {
597 	struct proc_thermal_device *proc_priv = pci_get_drvdata(pdev);
598 
599 	if (proc_priv->soc_dts) {
600 		intel_soc_dts_iosf_exit(proc_priv->soc_dts);
601 		if (pdev->irq) {
602 			free_irq(pdev->irq, pdev);
603 			pci_disable_msi(pdev);
604 		}
605 	}
606 	proc_thermal_rapl_remove();
607 	proc_thermal_remove(proc_priv);
608 }
609 
610 #ifdef CONFIG_PM_SLEEP
611 static int proc_thermal_resume(struct device *dev)
612 {
613 	struct proc_thermal_device *proc_dev;
614 
615 	proc_dev = dev_get_drvdata(dev);
616 	proc_thermal_read_ppcc(proc_dev);
617 
618 	return 0;
619 }
620 #else
621 #define proc_thermal_resume NULL
622 #endif
623 
624 static SIMPLE_DEV_PM_OPS(proc_thermal_pm, NULL, proc_thermal_resume);
625 
626 static const struct pci_device_id proc_thermal_pci_ids[] = {
627 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_BDW_THERMAL)},
628 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_HSB_THERMAL)},
629 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_SKL_THERMAL),
630 		.driver_data = (kernel_ulong_t)&rapl_mmio_hsw, },
631 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_BSW_THERMAL)},
632 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_BXT0_THERMAL)},
633 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_BXT1_THERMAL)},
634 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_BXTX_THERMAL)},
635 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_BXTP_THERMAL)},
636 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_CNL_THERMAL)},
637 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_CFL_THERMAL)},
638 	{ PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_PROC_GLK_THERMAL)},
639 	{ 0, },
640 };
641 
642 MODULE_DEVICE_TABLE(pci, proc_thermal_pci_ids);
643 
644 static struct pci_driver proc_thermal_pci_driver = {
645 	.name		= DRV_NAME,
646 	.probe		= proc_thermal_pci_probe,
647 	.remove		= proc_thermal_pci_remove,
648 	.id_table	= proc_thermal_pci_ids,
649 	.driver.pm	= &proc_thermal_pm,
650 };
651 
652 static const struct acpi_device_id int3401_device_ids[] = {
653 	{"INT3401", 0},
654 	{"", 0},
655 };
656 MODULE_DEVICE_TABLE(acpi, int3401_device_ids);
657 
658 static struct platform_driver int3401_driver = {
659 	.probe = int3401_add,
660 	.remove = int3401_remove,
661 	.driver = {
662 		.name = "int3401 thermal",
663 		.acpi_match_table = int3401_device_ids,
664 		.pm = &proc_thermal_pm,
665 	},
666 };
667 
668 static int __init proc_thermal_init(void)
669 {
670 	int ret;
671 
672 	ret = platform_driver_register(&int3401_driver);
673 	if (ret)
674 		return ret;
675 
676 	ret = pci_register_driver(&proc_thermal_pci_driver);
677 
678 	return ret;
679 }
680 
681 static void __exit proc_thermal_exit(void)
682 {
683 	platform_driver_unregister(&int3401_driver);
684 	pci_unregister_driver(&proc_thermal_pci_driver);
685 }
686 
687 module_init(proc_thermal_init);
688 module_exit(proc_thermal_exit);
689 
690 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
691 MODULE_DESCRIPTION("Processor Thermal Reporting Device Driver");
692 MODULE_LICENSE("GPL v2");
693