0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/module.h>
0010 #include <linux/platform_device.h>
0011 #include <linux/acpi.h>
0012 #include <linux/thermal.h>
0013 #include "int340x_thermal_zone.h"
0014
0015 #define INT3402_PERF_CHANGED_EVENT 0x80
0016 #define INT3402_THERMAL_EVENT 0x90
0017
0018 struct int3402_thermal_data {
0019 acpi_handle *handle;
0020 struct int34x_thermal_zone *int340x_zone;
0021 };
0022
0023 static void int3402_notify(acpi_handle handle, u32 event, void *data)
0024 {
0025 struct int3402_thermal_data *priv = data;
0026
0027 if (!priv)
0028 return;
0029
0030 switch (event) {
0031 case INT3402_PERF_CHANGED_EVENT:
0032 break;
0033 case INT3402_THERMAL_EVENT:
0034 int340x_thermal_zone_device_update(priv->int340x_zone,
0035 THERMAL_TRIP_VIOLATED);
0036 break;
0037 default:
0038 break;
0039 }
0040 }
0041
0042 static int int3402_thermal_probe(struct platform_device *pdev)
0043 {
0044 struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
0045 struct int3402_thermal_data *d;
0046 int ret;
0047
0048 if (!acpi_has_method(adev->handle, "_TMP"))
0049 return -ENODEV;
0050
0051 d = devm_kzalloc(&pdev->dev, sizeof(*d), GFP_KERNEL);
0052 if (!d)
0053 return -ENOMEM;
0054
0055 d->int340x_zone = int340x_thermal_zone_add(adev, NULL);
0056 if (IS_ERR(d->int340x_zone))
0057 return PTR_ERR(d->int340x_zone);
0058
0059 ret = acpi_install_notify_handler(adev->handle,
0060 ACPI_DEVICE_NOTIFY,
0061 int3402_notify,
0062 d);
0063 if (ret) {
0064 int340x_thermal_zone_remove(d->int340x_zone);
0065 return ret;
0066 }
0067
0068 d->handle = adev->handle;
0069 platform_set_drvdata(pdev, d);
0070
0071 return 0;
0072 }
0073
0074 static int int3402_thermal_remove(struct platform_device *pdev)
0075 {
0076 struct int3402_thermal_data *d = platform_get_drvdata(pdev);
0077
0078 acpi_remove_notify_handler(d->handle,
0079 ACPI_DEVICE_NOTIFY, int3402_notify);
0080 int340x_thermal_zone_remove(d->int340x_zone);
0081
0082 return 0;
0083 }
0084
0085 static const struct acpi_device_id int3402_thermal_match[] = {
0086 {"INT3402", 0},
0087 {}
0088 };
0089
0090 MODULE_DEVICE_TABLE(acpi, int3402_thermal_match);
0091
0092 static struct platform_driver int3402_thermal_driver = {
0093 .probe = int3402_thermal_probe,
0094 .remove = int3402_thermal_remove,
0095 .driver = {
0096 .name = "int3402 thermal",
0097 .acpi_match_table = int3402_thermal_match,
0098 },
0099 };
0100
0101 module_platform_driver(int3402_thermal_driver);
0102
0103 MODULE_DESCRIPTION("INT3402 Thermal driver");
0104 MODULE_LICENSE("GPL");