treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / acpi / dptf / dptf_power.c
blob387f27ef3368b1f9e591e0b143331428f36c1241
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * dptf_power: DPTF platform power driver
4 * Copyright (c) 2016, Intel Corporation.
5 */
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
17 * CTYP : Charger type
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,\
23 char *buf)\
25 struct acpi_device *acpi_dev = dev_get_drvdata(dev);\
26 unsigned long long val;\
27 acpi_status status;\
29 status = acpi_evaluate_integer(acpi_dev->handle, #object,\
30 NULL, &val);\
31 if (ACPI_SUCCESS(status))\
32 return sprintf(buf, "%d\n", (int)val);\
33 else \
34 return -EINVAL;\
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,
55 NULL
58 static const struct attribute_group dptf_power_attribute_group = {
59 .attrs = dptf_power_attrs,
60 .name = "dptf_power"
63 static int dptf_power_add(struct platform_device *pdev)
65 struct acpi_device *acpi_dev;
66 acpi_status status;
67 unsigned long long ptype;
68 int result;
70 acpi_dev = ACPI_COMPANION(&(pdev->dev));
71 if (!acpi_dev)
72 return -ENODEV;
74 status = acpi_evaluate_integer(acpi_dev->handle, "PTYP", NULL, &ptype);
75 if (ACPI_FAILURE(status))
76 return -ENODEV;
78 if (ptype != 0x11)
79 return -ENODEV;
81 result = sysfs_create_group(&pdev->dev.kobj,
82 &dptf_power_attribute_group);
83 if (result)
84 return result;
86 platform_set_drvdata(pdev, acpi_dev);
88 return 0;
91 static int dptf_power_remove(struct platform_device *pdev)
94 sysfs_remove_group(&pdev->dev.kobj, &dptf_power_attribute_group);
96 return 0;
99 static const struct acpi_device_id int3407_device_ids[] = {
100 {"INT1047", 0},
101 {"INT3407", 0},
102 {"", 0},
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,
109 .driver = {
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");