1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/kernel.h>
17#include <linux/module.h>
18#include <linux/acpi.h>
19#include <linux/platform_device.h>
20
21
22
23
24
25
26
27
28
29#define DPTF_POWER_SHOW(name, object) \
30static ssize_t name##_show(struct device *dev,\
31 struct device_attribute *attr,\
32 char *buf)\
33{\
34 struct platform_device *pdev = to_platform_device(dev);\
35 struct acpi_device *acpi_dev = platform_get_drvdata(pdev);\
36 unsigned long long val;\
37 acpi_status status;\
38\
39 status = acpi_evaluate_integer(acpi_dev->handle, #object,\
40 NULL, &val);\
41 if (ACPI_SUCCESS(status))\
42 return sprintf(buf, "%d\n", (int)val);\
43 else \
44 return -EINVAL;\
45}
46
47DPTF_POWER_SHOW(max_platform_power_mw, PMAX)
48DPTF_POWER_SHOW(platform_power_source, PSRC)
49DPTF_POWER_SHOW(adapter_rating_mw, ARTG)
50DPTF_POWER_SHOW(battery_steady_power_mw, PBSS)
51DPTF_POWER_SHOW(charger_type, CTYP)
52
53static DEVICE_ATTR_RO(max_platform_power_mw);
54static DEVICE_ATTR_RO(platform_power_source);
55static DEVICE_ATTR_RO(adapter_rating_mw);
56static DEVICE_ATTR_RO(battery_steady_power_mw);
57static DEVICE_ATTR_RO(charger_type);
58
59static struct attribute *dptf_power_attrs[] = {
60 &dev_attr_max_platform_power_mw.attr,
61 &dev_attr_platform_power_source.attr,
62 &dev_attr_adapter_rating_mw.attr,
63 &dev_attr_battery_steady_power_mw.attr,
64 &dev_attr_charger_type.attr,
65 NULL
66};
67
68static const struct attribute_group dptf_power_attribute_group = {
69 .attrs = dptf_power_attrs,
70 .name = "dptf_power"
71};
72
73static int dptf_power_add(struct platform_device *pdev)
74{
75 struct acpi_device *acpi_dev;
76 acpi_status status;
77 unsigned long long ptype;
78 int result;
79
80 acpi_dev = ACPI_COMPANION(&(pdev->dev));
81 if (!acpi_dev)
82 return -ENODEV;
83
84 status = acpi_evaluate_integer(acpi_dev->handle, "PTYP", NULL, &ptype);
85 if (ACPI_FAILURE(status))
86 return -ENODEV;
87
88 if (ptype != 0x11)
89 return -ENODEV;
90
91 result = sysfs_create_group(&pdev->dev.kobj,
92 &dptf_power_attribute_group);
93 if (result)
94 return result;
95
96 platform_set_drvdata(pdev, acpi_dev);
97
98 return 0;
99}
100
101static int dptf_power_remove(struct platform_device *pdev)
102{
103
104 sysfs_remove_group(&pdev->dev.kobj, &dptf_power_attribute_group);
105
106 return 0;
107}
108
109static const struct acpi_device_id int3407_device_ids[] = {
110 {"INT3407", 0},
111 {"", 0},
112};
113MODULE_DEVICE_TABLE(acpi, int3407_device_ids);
114
115static struct platform_driver dptf_power_driver = {
116 .probe = dptf_power_add,
117 .remove = dptf_power_remove,
118 .driver = {
119 .name = "DPTF Platform Power",
120 .acpi_match_table = int3407_device_ids,
121 },
122};
123
124module_platform_driver(dptf_power_driver);
125
126MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
127MODULE_LICENSE("GPL v2");
128MODULE_DESCRIPTION("ACPI DPTF platform power driver");
129