int3402_thermal.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/acpi.h>
  15. #include <linux/thermal.h>
  16. #include "int340x_thermal_zone.h"
  17. #define INT3402_PERF_CHANGED_EVENT 0x80
  18. #define INT3402_THERMAL_EVENT 0x90
  19. struct int3402_thermal_data {
  20. acpi_handle *handle;
  21. struct int34x_thermal_zone *int340x_zone;
  22. };
  23. static void int3402_notify(acpi_handle handle, u32 event, void *data)
  24. {
  25. struct int3402_thermal_data *priv = data;
  26. if (!priv)
  27. return;
  28. switch (event) {
  29. case INT3402_PERF_CHANGED_EVENT:
  30. break;
  31. case INT3402_THERMAL_EVENT:
  32. int340x_thermal_zone_device_update(priv->int340x_zone,
  33. THERMAL_TRIP_VIOLATED);
  34. break;
  35. default:
  36. break;
  37. }
  38. }
  39. static int int3402_thermal_probe(struct platform_device *pdev)
  40. {
  41. struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
  42. struct int3402_thermal_data *d;
  43. int ret;
  44. if (!acpi_has_method(adev->handle, "_TMP"))
  45. return -ENODEV;
  46. d = devm_kzalloc(&pdev->dev, sizeof(*d), GFP_KERNEL);
  47. if (!d)
  48. return -ENOMEM;
  49. d->int340x_zone = int340x_thermal_zone_add(adev, NULL);
  50. if (IS_ERR(d->int340x_zone))
  51. return PTR_ERR(d->int340x_zone);
  52. ret = acpi_install_notify_handler(adev->handle,
  53. ACPI_DEVICE_NOTIFY,
  54. int3402_notify,
  55. d);
  56. if (ret) {
  57. int340x_thermal_zone_remove(d->int340x_zone);
  58. return ret;
  59. }
  60. d->handle = adev->handle;
  61. platform_set_drvdata(pdev, d);
  62. return 0;
  63. }
  64. static int int3402_thermal_remove(struct platform_device *pdev)
  65. {
  66. struct int3402_thermal_data *d = platform_get_drvdata(pdev);
  67. acpi_remove_notify_handler(d->handle,
  68. ACPI_DEVICE_NOTIFY, int3402_notify);
  69. int340x_thermal_zone_remove(d->int340x_zone);
  70. return 0;
  71. }
  72. static const struct acpi_device_id int3402_thermal_match[] = {
  73. {"INT3402", 0},
  74. {}
  75. };
  76. MODULE_DEVICE_TABLE(acpi, int3402_thermal_match);
  77. static struct platform_driver int3402_thermal_driver = {
  78. .probe = int3402_thermal_probe,
  79. .remove = int3402_thermal_remove,
  80. .driver = {
  81. .name = "int3402 thermal",
  82. .acpi_match_table = int3402_thermal_match,
  83. },
  84. };
  85. module_platform_driver(int3402_thermal_driver);
  86. MODULE_DESCRIPTION("INT3402 Thermal driver");
  87. MODULE_LICENSE("GPL");