3ff7c26
From cc2b0e2c164d02ab42efa736f91f53baf8d8bc36 Mon Sep 17 00:00:00 2001
3ff7c26
From: Hans de Goede <hdegoede@redhat.com>
3ff7c26
Date: Thu, 20 Apr 2017 22:41:20 +0200
3ff7c26
Subject: [PATCH 05/16] ACPI / PMIC: xpower: Add support for the GPI1 regulator
3ff7c26
 to the OpRegion handler
3ff7c26
3ff7c26
Some Bay Trail devices use a GPI1 regulator field (address 0x4c) in
3ff7c26
their 0x8d power OpRegion, add support for this.
3ff7c26
3ff7c26
This fixes AE_BAD_PARAMETER errors getting thrown on these devices and
3ff7c26
fixes these errors causing these devices to not suspend.
3ff7c26
3ff7c26
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
3ff7c26
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
3ff7c26
---
3ff7c26
Changes in v2:
3ff7c26
-Simplify reg == 0x92 handling (suggested by Andy Shevchenko)
3ff7c26
-Add special handling for reg == 0x92 to intel_xpower_pmic_get_power() too
3ff7c26
Changes in v3:
3ff7c26
-Use defines for GPI1 reg and bits, rather then hardcoded hex values
3ff7c26
---
3ff7c26
 drivers/acpi/pmic/intel_pmic_xpower.c | 21 ++++++++++++++++++++-
3ff7c26
 1 file changed, 20 insertions(+), 1 deletion(-)
3ff7c26
3ff7c26
diff --git a/drivers/acpi/pmic/intel_pmic_xpower.c b/drivers/acpi/pmic/intel_pmic_xpower.c
3ff7c26
index 1a76c784cd4c..3b7d5be5b7ed 100644
3ff7c26
--- a/drivers/acpi/pmic/intel_pmic_xpower.c
3ff7c26
+++ b/drivers/acpi/pmic/intel_pmic_xpower.c
3ff7c26
@@ -21,6 +21,11 @@
3ff7c26
 #include "intel_pmic.h"
3ff7c26
 
3ff7c26
 #define XPOWER_GPADC_LOW	0x5b
3ff7c26
+#define XPOWER_GPI1_CTRL	0x92
3ff7c26
+
3ff7c26
+#define GPI1_LDO_MASK		GENMASK(2, 0)
3ff7c26
+#define GPI1_LDO_ON		(3 << 0)
3ff7c26
+#define GPI1_LDO_OFF		(4 << 0)
3ff7c26
 
3ff7c26
 static struct pmic_table power_table[] = {
3ff7c26
 	{
3ff7c26
@@ -118,6 +123,10 @@ static struct pmic_table power_table[] = {
3ff7c26
 		.reg = 0x10,
3ff7c26
 		.bit = 0x00
3ff7c26
 	}, /* BUC6 */
3ff7c26
+	{
3ff7c26
+		.address = 0x4c,
3ff7c26
+		.reg = 0x92,
3ff7c26
+	}, /* GPI1 */
3ff7c26
 };
3ff7c26
 
3ff7c26
 /* TMP0 - TMP5 are the same, all from GPADC */
3ff7c26
@@ -156,7 +165,12 @@ static int intel_xpower_pmic_get_power(struct regmap *regmap, int reg,
3ff7c26
 	if (regmap_read(regmap, reg, &data))
3ff7c26
 		return -EIO;
3ff7c26
 
3ff7c26
-	*value = (data & BIT(bit)) ? 1 : 0;
3ff7c26
+	/* GPIO1 LDO regulator needs special handling */
3ff7c26
+	if (reg == XPOWER_GPI1_CTRL)
3ff7c26
+		*value = ((data & GPI1_LDO_MASK) == GPI1_LDO_ON);
3ff7c26
+	else
3ff7c26
+		*value = (data & BIT(bit)) ? 1 : 0;
3ff7c26
+
3ff7c26
 	return 0;
3ff7c26
 }
3ff7c26
 
3ff7c26
@@ -165,6 +179,11 @@ static int intel_xpower_pmic_update_power(struct regmap *regmap, int reg,
3ff7c26
 {
3ff7c26
 	int data;
3ff7c26
 
3ff7c26
+	/* GPIO1 LDO regulator needs special handling */
3ff7c26
+	if (reg == XPOWER_GPI1_CTRL)
3ff7c26
+		return regmap_update_bits(regmap, reg, GPI1_LDO_MASK,
3ff7c26
+					  on ? GPI1_LDO_ON : GPI1_LDO_OFF);
3ff7c26
+
3ff7c26
 	if (regmap_read(regmap, reg, &data))
3ff7c26
 		return -EIO;
3ff7c26
 
3ff7c26
-- 
3ff7c26
2.13.0
3ff7c26