Aaron Lu | 77e337c | 2014-09-03 15:13:02 +0800 | [diff] [blame] | 1 | /* |
| 2 | * INT3402 thermal driver for memory temperature reporting |
| 3 | * |
| 4 | * Copyright (C) 2014, Intel Corporation |
| 5 | * Authors: Aaron Lu <aaron.lu@intel.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License version 2 as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/acpi.h> |
| 16 | #include <linux/thermal.h> |
Srinivas Pandruvada | 820cdeb | 2015-01-16 15:59:04 -0800 | [diff] [blame] | 17 | #include "int340x_thermal_zone.h" |
Aaron Lu | 77e337c | 2014-09-03 15:13:02 +0800 | [diff] [blame] | 18 | |
Srinivas Pandruvada | acebf7e | 2014-12-23 15:29:57 -0800 | [diff] [blame] | 19 | #define INT3402_PERF_CHANGED_EVENT 0x80 |
| 20 | #define INT3402_THERMAL_EVENT 0x90 |
| 21 | |
Aaron Lu | 77e337c | 2014-09-03 15:13:02 +0800 | [diff] [blame] | 22 | struct int3402_thermal_data { |
Aaron Lu | 77e337c | 2014-09-03 15:13:02 +0800 | [diff] [blame] | 23 | acpi_handle *handle; |
Srinivas Pandruvada | 820cdeb | 2015-01-16 15:59:04 -0800 | [diff] [blame] | 24 | struct int34x_thermal_zone *int340x_zone; |
Aaron Lu | 77e337c | 2014-09-03 15:13:02 +0800 | [diff] [blame] | 25 | }; |
| 26 | |
Srinivas Pandruvada | acebf7e | 2014-12-23 15:29:57 -0800 | [diff] [blame] | 27 | static void int3402_notify(acpi_handle handle, u32 event, void *data) |
| 28 | { |
| 29 | struct int3402_thermal_data *priv = data; |
| 30 | |
| 31 | if (!priv) |
| 32 | return; |
| 33 | |
| 34 | switch (event) { |
| 35 | case INT3402_PERF_CHANGED_EVENT: |
| 36 | break; |
| 37 | case INT3402_THERMAL_EVENT: |
| 38 | int340x_thermal_zone_device_update(priv->int340x_zone); |
| 39 | break; |
| 40 | default: |
| 41 | break; |
| 42 | } |
| 43 | } |
| 44 | |
Aaron Lu | 77e337c | 2014-09-03 15:13:02 +0800 | [diff] [blame] | 45 | static int int3402_thermal_probe(struct platform_device *pdev) |
| 46 | { |
| 47 | struct acpi_device *adev = ACPI_COMPANION(&pdev->dev); |
| 48 | struct int3402_thermal_data *d; |
Srinivas Pandruvada | acebf7e | 2014-12-23 15:29:57 -0800 | [diff] [blame] | 49 | int ret; |
Aaron Lu | 77e337c | 2014-09-03 15:13:02 +0800 | [diff] [blame] | 50 | |
| 51 | if (!acpi_has_method(adev->handle, "_TMP")) |
| 52 | return -ENODEV; |
| 53 | |
| 54 | d = devm_kzalloc(&pdev->dev, sizeof(*d), GFP_KERNEL); |
| 55 | if (!d) |
| 56 | return -ENOMEM; |
| 57 | |
Srinivas Pandruvada | 820cdeb | 2015-01-16 15:59:04 -0800 | [diff] [blame] | 58 | d->int340x_zone = int340x_thermal_zone_add(adev, NULL); |
| 59 | if (IS_ERR(d->int340x_zone)) |
| 60 | return PTR_ERR(d->int340x_zone); |
Aaron Lu | 77e337c | 2014-09-03 15:13:02 +0800 | [diff] [blame] | 61 | |
Srinivas Pandruvada | acebf7e | 2014-12-23 15:29:57 -0800 | [diff] [blame] | 62 | ret = acpi_install_notify_handler(adev->handle, |
| 63 | ACPI_DEVICE_NOTIFY, |
| 64 | int3402_notify, |
| 65 | d); |
| 66 | if (ret) { |
| 67 | int340x_thermal_zone_remove(d->int340x_zone); |
| 68 | return ret; |
| 69 | } |
| 70 | |
Srinivas Pandruvada | 820cdeb | 2015-01-16 15:59:04 -0800 | [diff] [blame] | 71 | d->handle = adev->handle; |
| 72 | platform_set_drvdata(pdev, d); |
Aaron Lu | 77e337c | 2014-09-03 15:13:02 +0800 | [diff] [blame] | 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | static int int3402_thermal_remove(struct platform_device *pdev) |
| 78 | { |
Srinivas Pandruvada | 820cdeb | 2015-01-16 15:59:04 -0800 | [diff] [blame] | 79 | struct int3402_thermal_data *d = platform_get_drvdata(pdev); |
Aaron Lu | 77e337c | 2014-09-03 15:13:02 +0800 | [diff] [blame] | 80 | |
Srinivas Pandruvada | acebf7e | 2014-12-23 15:29:57 -0800 | [diff] [blame] | 81 | acpi_remove_notify_handler(d->handle, |
| 82 | ACPI_DEVICE_NOTIFY, int3402_notify); |
Srinivas Pandruvada | 820cdeb | 2015-01-16 15:59:04 -0800 | [diff] [blame] | 83 | int340x_thermal_zone_remove(d->int340x_zone); |
| 84 | |
Aaron Lu | 77e337c | 2014-09-03 15:13:02 +0800 | [diff] [blame] | 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static const struct acpi_device_id int3402_thermal_match[] = { |
| 89 | {"INT3402", 0}, |
| 90 | {} |
| 91 | }; |
| 92 | |
| 93 | MODULE_DEVICE_TABLE(acpi, int3402_thermal_match); |
| 94 | |
| 95 | static struct platform_driver int3402_thermal_driver = { |
| 96 | .probe = int3402_thermal_probe, |
| 97 | .remove = int3402_thermal_remove, |
| 98 | .driver = { |
| 99 | .name = "int3402 thermal", |
Aaron Lu | 77e337c | 2014-09-03 15:13:02 +0800 | [diff] [blame] | 100 | .acpi_match_table = int3402_thermal_match, |
| 101 | }, |
| 102 | }; |
| 103 | |
| 104 | module_platform_driver(int3402_thermal_driver); |
| 105 | |
| 106 | MODULE_DESCRIPTION("INT3402 Thermal driver"); |
| 107 | MODULE_LICENSE("GPL"); |