dptf_power.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * dptf_power: DPTF platform power driver
  3. * Copyright (c) 2016, Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/acpi.h>
  18. #include <linux/platform_device.h>
  19. /*
  20. * Presentation of attributes which are defined for INT3407. They are:
  21. * PMAX : Maximum platform powe
  22. * PSRC : Platform power source
  23. * ARTG : Adapter rating
  24. * CTYP : Charger type
  25. * PBSS : Battery steady power
  26. */
  27. #define DPTF_POWER_SHOW(name, object) \
  28. static ssize_t name##_show(struct device *dev,\
  29. struct device_attribute *attr,\
  30. char *buf)\
  31. {\
  32. struct platform_device *pdev = to_platform_device(dev);\
  33. struct acpi_device *acpi_dev = platform_get_drvdata(pdev);\
  34. unsigned long long val;\
  35. acpi_status status;\
  36. \
  37. status = acpi_evaluate_integer(acpi_dev->handle, #object,\
  38. NULL, &val);\
  39. if (ACPI_SUCCESS(status))\
  40. return sprintf(buf, "%d\n", (int)val);\
  41. else \
  42. return -EINVAL;\
  43. }
  44. DPTF_POWER_SHOW(max_platform_power_mw, PMAX)
  45. DPTF_POWER_SHOW(platform_power_source, PSRC)
  46. DPTF_POWER_SHOW(adapter_rating_mw, ARTG)
  47. DPTF_POWER_SHOW(battery_steady_power_mw, PBSS)
  48. DPTF_POWER_SHOW(charger_type, CTYP)
  49. static DEVICE_ATTR_RO(max_platform_power_mw);
  50. static DEVICE_ATTR_RO(platform_power_source);
  51. static DEVICE_ATTR_RO(adapter_rating_mw);
  52. static DEVICE_ATTR_RO(battery_steady_power_mw);
  53. static DEVICE_ATTR_RO(charger_type);
  54. static struct attribute *dptf_power_attrs[] = {
  55. &dev_attr_max_platform_power_mw.attr,
  56. &dev_attr_platform_power_source.attr,
  57. &dev_attr_adapter_rating_mw.attr,
  58. &dev_attr_battery_steady_power_mw.attr,
  59. &dev_attr_charger_type.attr,
  60. NULL
  61. };
  62. static struct attribute_group dptf_power_attribute_group = {
  63. .attrs = dptf_power_attrs,
  64. .name = "dptf_power"
  65. };
  66. static int dptf_power_add(struct platform_device *pdev)
  67. {
  68. struct acpi_device *acpi_dev;
  69. acpi_status status;
  70. unsigned long long ptype;
  71. int result;
  72. acpi_dev = ACPI_COMPANION(&(pdev->dev));
  73. if (!acpi_dev)
  74. return -ENODEV;
  75. status = acpi_evaluate_integer(acpi_dev->handle, "PTYP", NULL, &ptype);
  76. if (ACPI_FAILURE(status))
  77. return -ENODEV;
  78. if (ptype != 0x11)
  79. return -ENODEV;
  80. result = sysfs_create_group(&pdev->dev.kobj,
  81. &dptf_power_attribute_group);
  82. if (result)
  83. return result;
  84. platform_set_drvdata(pdev, acpi_dev);
  85. return 0;
  86. }
  87. static int dptf_power_remove(struct platform_device *pdev)
  88. {
  89. sysfs_remove_group(&pdev->dev.kobj, &dptf_power_attribute_group);
  90. return 0;
  91. }
  92. static const struct acpi_device_id int3407_device_ids[] = {
  93. {"INT3407", 0},
  94. {"", 0},
  95. };
  96. MODULE_DEVICE_TABLE(acpi, int3407_device_ids);
  97. static struct platform_driver dptf_power_driver = {
  98. .probe = dptf_power_add,
  99. .remove = dptf_power_remove,
  100. .driver = {
  101. .name = "DPTF Platform Power",
  102. .acpi_match_table = int3407_device_ids,
  103. },
  104. };
  105. module_platform_driver(dptf_power_driver);
  106. MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
  107. MODULE_LICENSE("GPL v2");
  108. MODULE_DESCRIPTION("ACPI DPTF platform power driver");