All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5] DPTF Platform power participant driver
@ 2016-07-17 20:45 Srinivas Pandruvada
  2016-07-17 20:45 ` [PATCH v5] acpi: dptf_power: Add DPTF power participant Srinivas Pandruvada
  0 siblings, 1 reply; 4+ messages in thread
From: Srinivas Pandruvada @ 2016-07-17 20:45 UTC (permalink / raw)
  To: rjw; +Cc: linux-acpi, Srinivas Pandruvada

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=a, Size: 2351 bytes --]

The Intel ® Dynamic Platform and Thermal Framework (Intel ® DPTF) platform
Power Participant is responsible for exposing platform telemetry such as
-Platform Power
-Battery Information such as State of Charge, estimated maximum
sustainable power (PMax), SMART battery spec information

The Platform Power related objects are exported via sysfs, but the battery
information objects are not exposed as they are already exposed by the
current ACPI battery driver.

v5:
Removed battery common part. No more changes to acpi battery driver.
The only platform power related attributes are presented via sysfs. For
battery status releated information, the user space need to look at the
acpi battery power supply information.

v4:
When both INT3407 and ACPI battery objects are present, then it will
cause two batteries to appear in Linux desktop. There is no way to
avoid this as long as we register with power_supply class. In this
version all battery information and state is presented in sysfs
instead using power_supply class for the DPTF power driver. DPTF
power driver will not register to the power supply class if ACPI_BATTERY
config is defined. 

v3:
Moved dptf_power to drivers/acpi/dptf folder.

v2:
When both CONFIG_ACPI_BATTERY and CONFIG_DPTF_POWER are defined and
platform has support for INT3407, then dptf power registration is
delayed for 100ms. In 100 ms, if there is no ACPI battery is registered
then dptf power will be registered. Since both can be modules and
battery driver loads in async thread, there can be race even if we
specify loading order for initialization. 


Srinivas Pandruvada (1):
  acpi: dptf_power: Add DPTF power participant

 drivers/acpi/Kconfig           |   1 +
 drivers/acpi/Makefile          |   1 +
 drivers/acpi/dptf/Kconfig      |  16 ++++++
 drivers/acpi/dptf/Makefile     |   3 +
 drivers/acpi/dptf/dptf_power.c | 128 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 149 insertions(+)
 create mode 100644 drivers/acpi/dptf/Kconfig
 create mode 100644 drivers/acpi/dptf/Makefile
 create mode 100644 drivers/acpi/dptf/dptf_power.c

-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v5] acpi: dptf_power: Add DPTF power participant
  2016-07-17 20:45 [PATCH v5] DPTF Platform power participant driver Srinivas Pandruvada
@ 2016-07-17 20:45 ` Srinivas Pandruvada
  2016-07-18 23:00   ` Rafael J. Wysocki
  0 siblings, 1 reply; 4+ messages in thread
From: Srinivas Pandruvada @ 2016-07-17 20:45 UTC (permalink / raw)
  To: rjw; +Cc: linux-acpi, Srinivas Pandruvada

This driver adds support for Dynamic Platform and Thermal Framework
(DPTF) Platform Power Participant device (INT3407) support.

This participant is responsible for exposing platform telemetry such as:
    max_platform_power
    platform_power_source
    adapter_rating
    battery_steady_power
    charger_type

These attributes are presented via sysfs interface under the INT3407
platform device:
$ls /sys/bus/platform/devices/INT3407\:00/dptf_power/
    adapter_rating_mw
    battery_steady_power_mw
    charger_type
    max_platform_power_mw
    platform_power_source
    `
ACPI methods description used in this driver:
    PMAX: Maximum platform power that can be supported by the battery in
          mW.
    PSRC: System charge source,
            0x00 = DC
            0x01 = AC
            0x02 = USB
            0x03 = Wireless Charger
    ARTG: Adapter rating in mW (Maximum Adapter power) Must be 0 if no
          AC adapter is plugged in.
    CTYP: Charger Type,
            Traditional : 0x01
            Hybrid: 0x02
            NVDC: 0x03
    PBSS: Returns max sustained power for battery in milliWatts.

The INT3407 also contains _BTS and _BIX objects, which are compliant to
ACPI 5.0, specification. Those objects are already used by ACPI battery
(PNP0C0A) driver and information about them is exported via Linux power
supply class registration.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/acpi/Kconfig           |   1 +
 drivers/acpi/Makefile          |   1 +
 drivers/acpi/dptf/Kconfig      |  16 ++++++
 drivers/acpi/dptf/Makefile     |   1 +
 drivers/acpi/dptf/dptf_power.c | 128 +++++++++++++++++++++++++++++++++++++++++
 5 files changed, 147 insertions(+)
 create mode 100644 drivers/acpi/dptf/Kconfig
 create mode 100644 drivers/acpi/dptf/Makefile
 create mode 100644 drivers/acpi/dptf/dptf_power.c

diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index b7e2e77..b91a35b 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -475,6 +475,7 @@ config ACPI_NFIT_DEBUG
 	  issue.
 
 source "drivers/acpi/apei/Kconfig"
+source "drivers/acpi/dptf/Kconfig"
 
 config ACPI_EXTLOG
 	tristate "Extended Error Log support"
diff --git a/drivers/acpi/Makefile b/drivers/acpi/Makefile
index 251ce85..f6d0cc0 100644
--- a/drivers/acpi/Makefile
+++ b/drivers/acpi/Makefile
@@ -101,3 +101,4 @@ obj-$(CONFIG_CRC_PMIC_OPREGION) += pmic/intel_pmic_crc.o
 obj-$(CONFIG_XPOWER_PMIC_OPREGION) += pmic/intel_pmic_xpower.o
 
 video-objs			+= acpi_video.o video_detect.o
+obj-y				+= dptf/
diff --git a/drivers/acpi/dptf/Kconfig b/drivers/acpi/dptf/Kconfig
new file mode 100644
index 0000000..684543a
--- /dev/null
+++ b/drivers/acpi/dptf/Kconfig
@@ -0,0 +1,16 @@
+config DPTF_POWER
+	tristate "DPTF Platform Power Participant"
+	depends on X86
+	help
+	  This driver adds support for Dynamic Platform and Thermal Framework
+	  (DPTF) Platform Power Participant device (INT3407) support.
+	  This participant is responsible for exposing platform telemetry:
+		max_platform_power
+		platform_power_source
+		adapter_rating
+		battery_steady_power
+		charger_type
+
+	  To compile this driver as a module, choose M here:
+	  the module will be called dptf_power.
+
diff --git a/drivers/acpi/dptf/Makefile b/drivers/acpi/dptf/Makefile
new file mode 100644
index 0000000..62cbe87
--- /dev/null
+++ b/drivers/acpi/dptf/Makefile
@@ -0,0 +1 @@
+obj-$(CONFIG_DPTF_POWER)	+= dptf_power.o
diff --git a/drivers/acpi/dptf/dptf_power.c b/drivers/acpi/dptf/dptf_power.c
new file mode 100644
index 0000000..734642d
--- /dev/null
+++ b/drivers/acpi/dptf/dptf_power.c
@@ -0,0 +1,128 @@
+/*
+ * dptf_power:  DPTF platform power driver
+ * Copyright (c) 2016, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/acpi.h>
+#include <linux/platform_device.h>
+
+/*
+ * Presentation of attributes which are defined for INT3407. They are:
+ * PMAX : Maximum platform powe
+ * PSRC : Platform power source
+ * ARTG : Adapter rating
+ * CTYP : Charger type
+ * PBSS : Battery steady power
+ */
+#define DPTF_POWER_SHOW(name, object) \
+static ssize_t name##_show(struct device *dev,\
+			   struct device_attribute *attr,\
+			   char *buf)\
+{\
+	struct platform_device *pdev = to_platform_device(dev);\
+	struct acpi_device *acpi_dev = platform_get_drvdata(pdev);\
+	unsigned long long val;\
+	acpi_status status;\
+\
+	status = acpi_evaluate_integer(acpi_dev->handle, #object,\
+				       NULL, &val);\
+	if (ACPI_SUCCESS(status))\
+		return sprintf(buf, "%d\n", (int)val);\
+	else \
+		return -EINVAL;\
+}
+
+DPTF_POWER_SHOW(max_platform_power_mw, PMAX)
+DPTF_POWER_SHOW(platform_power_source, PSRC)
+DPTF_POWER_SHOW(adapter_rating_mw, ARTG)
+DPTF_POWER_SHOW(battery_steady_power_mw, PBSS)
+DPTF_POWER_SHOW(charger_type, CTYP)
+
+static DEVICE_ATTR_RO(max_platform_power_mw);
+static DEVICE_ATTR_RO(platform_power_source);
+static DEVICE_ATTR_RO(adapter_rating_mw);
+static DEVICE_ATTR_RO(battery_steady_power_mw);
+static DEVICE_ATTR_RO(charger_type);
+
+static struct attribute *dptf_power_attrs[] = {
+	&dev_attr_max_platform_power_mw.attr,
+	&dev_attr_platform_power_source.attr,
+	&dev_attr_adapter_rating_mw.attr,
+	&dev_attr_battery_steady_power_mw.attr,
+	&dev_attr_charger_type.attr,
+	NULL
+};
+
+static struct attribute_group dptf_power_attribute_group = {
+	.attrs = dptf_power_attrs,
+	.name = "dptf_power"
+};
+
+static int dptf_power_add(struct platform_device *pdev)
+{
+	struct acpi_device *acpi_dev;
+	acpi_status status;
+	unsigned long long ptype;
+	int result;
+
+	acpi_dev = ACPI_COMPANION(&(pdev->dev));
+	if (!acpi_dev)
+		return -ENODEV;
+
+	status = acpi_evaluate_integer(acpi_dev->handle, "PTYP", NULL, &ptype);
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
+
+	if (ptype != 0x11)
+		return -ENODEV;
+
+	result = sysfs_create_group(&pdev->dev.kobj,
+				    &dptf_power_attribute_group);
+	if (result)
+		return result;
+
+	platform_set_drvdata(pdev, acpi_dev);
+
+	return 0;
+}
+
+static int dptf_power_remove(struct platform_device *pdev)
+{
+
+	sysfs_remove_group(&pdev->dev.kobj, &dptf_power_attribute_group);
+
+	return 0;
+}
+
+static const struct acpi_device_id int3407_device_ids[] = {
+	{"INT3407", 0},
+	{"", 0},
+};
+MODULE_DEVICE_TABLE(acpi, int3407_device_ids);
+
+static struct platform_driver dptf_power_driver = {
+	.probe = dptf_power_add,
+	.remove = dptf_power_remove,
+	.driver = {
+		.name = "DPTF Platform Power",
+		.acpi_match_table = int3407_device_ids,
+	},
+};
+
+module_platform_driver(dptf_power_driver);
+
+MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("ACPI DPTF platform power driver");
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v5] acpi: dptf_power: Add DPTF power participant
  2016-07-17 20:45 ` [PATCH v5] acpi: dptf_power: Add DPTF power participant Srinivas Pandruvada
@ 2016-07-18 23:00   ` Rafael J. Wysocki
  2016-07-19 22:01     ` Srinivas Pandruvada
  0 siblings, 1 reply; 4+ messages in thread
From: Rafael J. Wysocki @ 2016-07-18 23:00 UTC (permalink / raw)
  To: Srinivas Pandruvada; +Cc: Rafael J. Wysocki, ACPI Devel Maling List

On Sun, Jul 17, 2016 at 10:45 PM, Srinivas Pandruvada
<srinivas.pandruvada@linux.intel.com> wrote:
> This driver adds support for Dynamic Platform and Thermal Framework
> (DPTF) Platform Power Participant device (INT3407) support.
>
> This participant is responsible for exposing platform telemetry such as:
>     max_platform_power
>     platform_power_source
>     adapter_rating
>     battery_steady_power
>     charger_type
>
> These attributes are presented via sysfs interface under the INT3407
> platform device:
> $ls /sys/bus/platform/devices/INT3407\:00/dptf_power/
>     adapter_rating_mw
>     battery_steady_power_mw
>     charger_type
>     max_platform_power_mw
>     platform_power_source
>     `
> ACPI methods description used in this driver:
>     PMAX: Maximum platform power that can be supported by the battery in
>           mW.
>     PSRC: System charge source,
>             0x00 = DC
>             0x01 = AC
>             0x02 = USB
>             0x03 = Wireless Charger
>     ARTG: Adapter rating in mW (Maximum Adapter power) Must be 0 if no
>           AC adapter is plugged in.
>     CTYP: Charger Type,
>             Traditional : 0x01
>             Hybrid: 0x02
>             NVDC: 0x03
>     PBSS: Returns max sustained power for battery in milliWatts.
>
> The INT3407 also contains _BTS and _BIX objects, which are compliant to
> ACPI 5.0, specification. Those objects are already used by ACPI battery
> (PNP0C0A) driver and information about them is exported via Linux power
> supply class registration.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>

This looks good to me.

You had a patch moving some other DPTF stuff to the dptf subdirectory,
can you please resend it?

Thanks,
Rafael

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v5] acpi: dptf_power: Add DPTF power participant
  2016-07-18 23:00   ` Rafael J. Wysocki
@ 2016-07-19 22:01     ` Srinivas Pandruvada
  0 siblings, 0 replies; 4+ messages in thread
From: Srinivas Pandruvada @ 2016-07-19 22:01 UTC (permalink / raw)
  To: Rafael J. Wysocki, Zhang Rui; +Cc: Rafael J. Wysocki, ACPI Devel Maling List

On Tue, 2016-07-19 at 01:00 +0200, Rafael J. Wysocki wrote:
> > 
> On Sun, Jul 17, 2016 at 10:45 PM, Srinivas Pandruvada
> <srinivas.pandruvada@linux.intel.com> wrote:
> > This driver adds support for Dynamic Platform and Thermal Framework
> > (DPTF) Platform Power Participant device (INT3407) support.
> > 
[...]
> > 
> You had a patch moving some other DPTF stuff to the dptf
> subdirectory,
> can you please resend it?
> 
Sent again. But want to get Rui's opinion on the patch.

Thanks,
Srinivas

> Thanks,
> Rafael
--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-07-19 22:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-17 20:45 [PATCH v5] DPTF Platform power participant driver Srinivas Pandruvada
2016-07-17 20:45 ` [PATCH v5] acpi: dptf_power: Add DPTF power participant Srinivas Pandruvada
2016-07-18 23:00   ` Rafael J. Wysocki
2016-07-19 22:01     ` Srinivas Pandruvada

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.