xref: /openbmc/linux/drivers/thermal/intel/int340x_thermal/int3401_thermal.c (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
18fe145f7SSrinivas Pandruvada // SPDX-License-Identifier: GPL-2.0-only
28fe145f7SSrinivas Pandruvada /*
38fe145f7SSrinivas Pandruvada  * INT3401 processor thermal device
48fe145f7SSrinivas Pandruvada  * Copyright (c) 2020, Intel Corporation.
58fe145f7SSrinivas Pandruvada  */
68fe145f7SSrinivas Pandruvada #include <linux/acpi.h>
78fe145f7SSrinivas Pandruvada #include <linux/kernel.h>
88fe145f7SSrinivas Pandruvada #include <linux/module.h>
98fe145f7SSrinivas Pandruvada #include <linux/platform_device.h>
108fe145f7SSrinivas Pandruvada #include <linux/thermal.h>
118fe145f7SSrinivas Pandruvada 
128fe145f7SSrinivas Pandruvada #include "int340x_thermal_zone.h"
138fe145f7SSrinivas Pandruvada #include "processor_thermal_device.h"
148fe145f7SSrinivas Pandruvada 
158fe145f7SSrinivas Pandruvada static const struct acpi_device_id int3401_device_ids[] = {
168fe145f7SSrinivas Pandruvada 	{"INT3401", 0},
178fe145f7SSrinivas Pandruvada 	{"", 0},
188fe145f7SSrinivas Pandruvada };
198fe145f7SSrinivas Pandruvada MODULE_DEVICE_TABLE(acpi, int3401_device_ids);
208fe145f7SSrinivas Pandruvada 
int3401_add(struct platform_device * pdev)218fe145f7SSrinivas Pandruvada static int int3401_add(struct platform_device *pdev)
228fe145f7SSrinivas Pandruvada {
238fe145f7SSrinivas Pandruvada 	struct proc_thermal_device *proc_priv;
248fe145f7SSrinivas Pandruvada 	int ret;
258fe145f7SSrinivas Pandruvada 
268fe145f7SSrinivas Pandruvada 	proc_priv = devm_kzalloc(&pdev->dev, sizeof(*proc_priv), GFP_KERNEL);
278fe145f7SSrinivas Pandruvada 	if (!proc_priv)
288fe145f7SSrinivas Pandruvada 		return -ENOMEM;
298fe145f7SSrinivas Pandruvada 
308fe145f7SSrinivas Pandruvada 	ret = proc_thermal_add(&pdev->dev, proc_priv);
318fe145f7SSrinivas Pandruvada 	if (ret)
328fe145f7SSrinivas Pandruvada 		return ret;
338fe145f7SSrinivas Pandruvada 
348fe145f7SSrinivas Pandruvada 	platform_set_drvdata(pdev, proc_priv);
358fe145f7SSrinivas Pandruvada 
368fe145f7SSrinivas Pandruvada 	return ret;
378fe145f7SSrinivas Pandruvada }
388fe145f7SSrinivas Pandruvada 
int3401_remove(struct platform_device * pdev)398fe145f7SSrinivas Pandruvada static int int3401_remove(struct platform_device *pdev)
408fe145f7SSrinivas Pandruvada {
418fe145f7SSrinivas Pandruvada 	proc_thermal_remove(platform_get_drvdata(pdev));
428fe145f7SSrinivas Pandruvada 
438fe145f7SSrinivas Pandruvada 	return 0;
448fe145f7SSrinivas Pandruvada }
458fe145f7SSrinivas Pandruvada 
468fe145f7SSrinivas Pandruvada #ifdef CONFIG_PM_SLEEP
int3401_thermal_suspend(struct device * dev)47c4fcf1adSAntoine Tenart static int int3401_thermal_suspend(struct device *dev)
48c4fcf1adSAntoine Tenart {
49c4fcf1adSAntoine Tenart 	return proc_thermal_suspend(dev);
50c4fcf1adSAntoine Tenart }
int3401_thermal_resume(struct device * dev)518fe145f7SSrinivas Pandruvada static int int3401_thermal_resume(struct device *dev)
528fe145f7SSrinivas Pandruvada {
538fe145f7SSrinivas Pandruvada 	return proc_thermal_resume(dev);
548fe145f7SSrinivas Pandruvada }
558fe145f7SSrinivas Pandruvada #else
56c4fcf1adSAntoine Tenart #define int3401_thermal_suspend NULL
578fe145f7SSrinivas Pandruvada #define int3401_thermal_resume NULL
588fe145f7SSrinivas Pandruvada #endif
598fe145f7SSrinivas Pandruvada 
60c4fcf1adSAntoine Tenart static SIMPLE_DEV_PM_OPS(int3401_proc_thermal_pm, int3401_thermal_suspend,
61c4fcf1adSAntoine Tenart 			 int3401_thermal_resume);
628fe145f7SSrinivas Pandruvada 
638fe145f7SSrinivas Pandruvada static struct platform_driver int3401_driver = {
648fe145f7SSrinivas Pandruvada 	.probe = int3401_add,
658fe145f7SSrinivas Pandruvada 	.remove = int3401_remove,
668fe145f7SSrinivas Pandruvada 	.driver = {
678fe145f7SSrinivas Pandruvada 		.name = "int3401 thermal",
688fe145f7SSrinivas Pandruvada 		.acpi_match_table = int3401_device_ids,
698fe145f7SSrinivas Pandruvada 		.pm = &int3401_proc_thermal_pm,
708fe145f7SSrinivas Pandruvada 	},
718fe145f7SSrinivas Pandruvada };
728fe145f7SSrinivas Pandruvada 
73*1a6e1004SYang Yingliang module_platform_driver(int3401_driver);
748fe145f7SSrinivas Pandruvada 
758fe145f7SSrinivas Pandruvada MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
768fe145f7SSrinivas Pandruvada MODULE_DESCRIPTION("Processor Thermal Reporting Device Driver");
778fe145f7SSrinivas Pandruvada MODULE_LICENSE("GPL v2");
78