1 // SPDX-License-Identifier: GPL-2.0-only
3 * dptf_power: DPTF platform power driver
4 * Copyright (c) 2016, Intel Corporation.
7 #include <linux/kernel.h>
8 #include <linux/module.h>
9 #include <linux/acpi.h>
10 #include <linux/platform_device.h>
13 * Presentation of attributes which are defined for INT3407. They are:
14 * PMAX : Maximum platform powe
15 * PSRC : Platform power source
16 * ARTG : Adapter rating
18 * PBSS : Battery steady power
20 #define DPTF_POWER_SHOW(name, object) \
21 static ssize_t name##_show(struct device *dev,\
22 struct device_attribute *attr,\
25 struct acpi_device *acpi_dev = dev_get_drvdata(dev);\
26 unsigned long long val;\
29 status = acpi_evaluate_integer(acpi_dev->handle, #object,\
31 if (ACPI_SUCCESS(status))\
32 return sprintf(buf, "%d\n", (int)val);\
37 DPTF_POWER_SHOW(max_platform_power_mw
, PMAX
)
38 DPTF_POWER_SHOW(platform_power_source
, PSRC
)
39 DPTF_POWER_SHOW(adapter_rating_mw
, ARTG
)
40 DPTF_POWER_SHOW(battery_steady_power_mw
, PBSS
)
41 DPTF_POWER_SHOW(charger_type
, CTYP
)
43 static DEVICE_ATTR_RO(max_platform_power_mw
);
44 static DEVICE_ATTR_RO(platform_power_source
);
45 static DEVICE_ATTR_RO(adapter_rating_mw
);
46 static DEVICE_ATTR_RO(battery_steady_power_mw
);
47 static DEVICE_ATTR_RO(charger_type
);
49 static struct attribute
*dptf_power_attrs
[] = {
50 &dev_attr_max_platform_power_mw
.attr
,
51 &dev_attr_platform_power_source
.attr
,
52 &dev_attr_adapter_rating_mw
.attr
,
53 &dev_attr_battery_steady_power_mw
.attr
,
54 &dev_attr_charger_type
.attr
,
58 static const struct attribute_group dptf_power_attribute_group
= {
59 .attrs
= dptf_power_attrs
,
63 static int dptf_power_add(struct platform_device
*pdev
)
65 struct acpi_device
*acpi_dev
;
67 unsigned long long ptype
;
70 acpi_dev
= ACPI_COMPANION(&(pdev
->dev
));
74 status
= acpi_evaluate_integer(acpi_dev
->handle
, "PTYP", NULL
, &ptype
);
75 if (ACPI_FAILURE(status
))
81 result
= sysfs_create_group(&pdev
->dev
.kobj
,
82 &dptf_power_attribute_group
);
86 platform_set_drvdata(pdev
, acpi_dev
);
91 static int dptf_power_remove(struct platform_device
*pdev
)
94 sysfs_remove_group(&pdev
->dev
.kobj
, &dptf_power_attribute_group
);
99 static const struct acpi_device_id int3407_device_ids
[] = {
104 MODULE_DEVICE_TABLE(acpi
, int3407_device_ids
);
106 static struct platform_driver dptf_power_driver
= {
107 .probe
= dptf_power_add
,
108 .remove
= dptf_power_remove
,
110 .name
= "DPTF Platform Power",
111 .acpi_match_table
= int3407_device_ids
,
115 module_platform_driver(dptf_power_driver
);
117 MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
118 MODULE_LICENSE("GPL v2");
119 MODULE_DESCRIPTION("ACPI DPTF platform power driver");