2 * dptf_power: DPTF platform power driver
3 * Copyright (c) 2016, Intel Corporation.
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.
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
16 #include <linux/kernel.h>
17 #include <linux/module.h>
18 #include <linux/acpi.h>
19 #include <linux/platform_device.h>
22 * Presentation of attributes which are defined for INT3407. They are:
23 * PMAX : Maximum platform powe
24 * PSRC : Platform power source
25 * ARTG : Adapter rating
27 * PBSS : Battery steady power
29 #define DPTF_POWER_SHOW(name, object) \
30 static ssize_t name##_show(struct device *dev,\
31 struct device_attribute *attr,\
34 struct platform_device *pdev = to_platform_device(dev);\
35 struct acpi_device *acpi_dev = platform_get_drvdata(pdev);\
36 unsigned long long val;\
39 status = acpi_evaluate_integer(acpi_dev->handle, #object,\
41 if (ACPI_SUCCESS(status))\
42 return sprintf(buf, "%d\n", (int)val);\
47 DPTF_POWER_SHOW(max_platform_power_mw
, PMAX
)
48 DPTF_POWER_SHOW(platform_power_source
, PSRC
)
49 DPTF_POWER_SHOW(adapter_rating_mw
, ARTG
)
50 DPTF_POWER_SHOW(battery_steady_power_mw
, PBSS
)
51 DPTF_POWER_SHOW(charger_type
, CTYP
)
53 static DEVICE_ATTR_RO(max_platform_power_mw
);
54 static DEVICE_ATTR_RO(platform_power_source
);
55 static DEVICE_ATTR_RO(adapter_rating_mw
);
56 static DEVICE_ATTR_RO(battery_steady_power_mw
);
57 static DEVICE_ATTR_RO(charger_type
);
59 static 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
,
68 static const struct attribute_group dptf_power_attribute_group
= {
69 .attrs
= dptf_power_attrs
,
73 static int dptf_power_add(struct platform_device
*pdev
)
75 struct acpi_device
*acpi_dev
;
77 unsigned long long ptype
;
80 acpi_dev
= ACPI_COMPANION(&(pdev
->dev
));
84 status
= acpi_evaluate_integer(acpi_dev
->handle
, "PTYP", NULL
, &ptype
);
85 if (ACPI_FAILURE(status
))
91 result
= sysfs_create_group(&pdev
->dev
.kobj
,
92 &dptf_power_attribute_group
);
96 platform_set_drvdata(pdev
, acpi_dev
);
101 static int dptf_power_remove(struct platform_device
*pdev
)
104 sysfs_remove_group(&pdev
->dev
.kobj
, &dptf_power_attribute_group
);
109 static const struct acpi_device_id int3407_device_ids
[] = {
113 MODULE_DEVICE_TABLE(acpi
, int3407_device_ids
);
115 static struct platform_driver dptf_power_driver
= {
116 .probe
= dptf_power_add
,
117 .remove
= dptf_power_remove
,
119 .name
= "DPTF Platform Power",
120 .acpi_match_table
= int3407_device_ids
,
124 module_platform_driver(dptf_power_driver
);
126 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
127 MODULE_LICENSE("GPL v2");
128 MODULE_DESCRIPTION("ACPI DPTF platform power driver");