int3402_thermal.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. break;
  34. default:
  35. break;
  36. }
  37. }
  38. static int int3402_thermal_probe(struct platform_device *pdev)
  39. {
  40. struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
  41. struct int3402_thermal_data *d;
  42. int ret;
  43. if (!acpi_has_method(adev->handle, "_TMP"))
  44. return -ENODEV;
  45. d = devm_kzalloc(&pdev->dev, sizeof(*d), GFP_KERNEL);
  46. if (!d)
  47. return -ENOMEM;
  48. d->int340x_zone = int340x_thermal_zone_add(adev, NULL);
  49. if (IS_ERR(d->int340x_zone))
  50. return PTR_ERR(d->int340x_zone);
  51. ret = acpi_install_notify_handler(adev->handle,
  52. ACPI_DEVICE_NOTIFY,
  53. int3402_notify,
  54. d);
  55. if (ret) {
  56. int340x_thermal_zone_remove(d->int340x_zone);
  57. return ret;
  58. }
  59. d->handle = adev->handle;
  60. platform_set_drvdata(pdev, d);
  61. return 0;
  62. }
  63. static int int3402_thermal_remove(struct platform_device *pdev)
  64. {
  65. struct int3402_thermal_data *d = platform_get_drvdata(pdev);
  66. acpi_remove_notify_handler(d->handle,
  67. ACPI_DEVICE_NOTIFY, int3402_notify);
  68. int340x_thermal_zone_remove(d->int340x_zone);
  69. return 0;
  70. }
  71. static const struct acpi_device_id int3402_thermal_match[] = {
  72. {"INT3402", 0},
  73. {}
  74. };
  75. MODULE_DEVICE_TABLE(acpi, int3402_thermal_match);
  76. static struct platform_driver int3402_thermal_driver = {
  77. .probe = int3402_thermal_probe,
  78. .remove = int3402_thermal_remove,
  79. .driver = {
  80. .name = "int3402 thermal",
  81. .acpi_match_table = int3402_thermal_match,
  82. },
  83. };
  84. module_platform_driver(int3402_thermal_driver);
  85. MODULE_DESCRIPTION("INT3402 Thermal driver");
  86. MODULE_LICENSE("GPL");