linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Support CrystalCove PMIC ACPI operation region
@ 2014-09-09  2:32 Aaron Lu
  2014-09-09  2:32 ` [PATCH 1/2] gpio / CrystalCove: support virtual GPIO Aaron Lu
                   ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: Aaron Lu @ 2014-09-09  2:32 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, Samuel Ortiz, Lee Jones, Arnd Bergmann
  Cc: linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, linux-acpi,
	Rafael J. Wysocki

The two patches add support for CrystalCove PMIC ACPI operation region.
The PMIC chip has two customized operation regions: one for power rail
manipulation and one for thermal purpose: sensor temperature reading
and trip point value reading/setting.

For an example ASL code on ASUS T100 with CrystalCove PMIC, see here:
https://gist.github.com/aaronlu/f5f65771a6c3251fae5d

Aaron Lu (2):
  gpio / CrystalCove: support virtual GPIO
  PMIC / opregion: support PMIC customized operation region for
    CrystalCove

 drivers/gpio/gpio-crystalcove.c           |  19 +-
 drivers/mfd/Kconfig                       |  11 +
 drivers/mfd/Makefile                      |   1 +
 drivers/mfd/intel_soc_pmic_crc.c          |   3 +
 drivers/mfd/intel_soc_pmic_crc_opregion.c | 229 +++++++++++++++++++
 drivers/mfd/intel_soc_pmic_opregion.c     | 350 ++++++++++++++++++++++++++++++
 drivers/mfd/intel_soc_pmic_opregion.h     |  35 +++
 include/asm-generic/gpio.h                |   2 +-
 8 files changed, 646 insertions(+), 4 deletions(-)
 create mode 100644 drivers/mfd/intel_soc_pmic_crc_opregion.c
 create mode 100644 drivers/mfd/intel_soc_pmic_opregion.c
 create mode 100644 drivers/mfd/intel_soc_pmic_opregion.h

-- 
1.9.3


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

* [PATCH 1/2] gpio / CrystalCove: support virtual GPIO
  2014-09-09  2:32 [PATCH 0/2] Support CrystalCove PMIC ACPI operation region Aaron Lu
@ 2014-09-09  2:32 ` Aaron Lu
  2014-09-23 10:13   ` Linus Walleij
  2014-09-24 11:18   ` Linus Walleij
  2014-09-09  2:32 ` [PATCH 2/2] PMIC / opregion: support PMIC customized operation region for CrystalCove Aaron Lu
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 21+ messages in thread
From: Aaron Lu @ 2014-09-09  2:32 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, Samuel Ortiz, Lee Jones, Arnd Bergmann
  Cc: linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, linux-acpi,
	Rafael J. Wysocki

The virtual GPIO introduced in ACPI table of Baytrail-T based system is
used to solve a problem under Windows. We do not have such problems
under Linux so we do not actually need them. But we have to tell GPIO
library that the Crystal Cove GPIO chip has this many GPIO pins or the
common GPIO handler will refuse any access to those high number GPIO
pins, which will resulted in a failure evaluation of every ACPI control
method that is used to turn on/off power resource and/or report sensor
temperatures.

Due to the high number of virtual GPIOs, the value of ARCH_NR_GPIOS is
bumped from 256 to 512 to avoid failures on platforms that have various
GPIO controllers.

Signed-off-by: Aaron Lu <aaron.lu@intel.com>
---
 drivers/gpio/gpio-crystalcove.c | 19 ++++++++++++++++---
 include/asm-generic/gpio.h      |  2 +-
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-crystalcove.c b/drivers/gpio/gpio-crystalcove.c
index 934462f5bd22..a8daada67aa4 100644
--- a/drivers/gpio/gpio-crystalcove.c
+++ b/drivers/gpio/gpio-crystalcove.c
@@ -24,6 +24,7 @@
 #include <linux/mfd/intel_soc_pmic.h>
 
 #define CRYSTALCOVE_GPIO_NUM	16
+#define CRYSTALCOVE_VGPIO_NUM	0x5e
 
 #define UPDATE_IRQ_TYPE		BIT(0)
 #define UPDATE_IRQ_MASK		BIT(1)
@@ -130,6 +131,9 @@ static int crystalcove_gpio_dir_in(struct gpio_chip *chip, unsigned gpio)
 {
 	struct crystalcove_gpio *cg = to_cg(chip);
 
+	if (gpio > CRYSTALCOVE_VGPIO_NUM)
+		return 0;
+
 	return regmap_write(cg->regmap, to_reg(gpio, CTRL_OUT),
 			    CTLO_INPUT_SET);
 }
@@ -139,6 +143,9 @@ static int crystalcove_gpio_dir_out(struct gpio_chip *chip, unsigned gpio,
 {
 	struct crystalcove_gpio *cg = to_cg(chip);
 
+	if (gpio > CRYSTALCOVE_VGPIO_NUM)
+		return 0;
+
 	return regmap_write(cg->regmap, to_reg(gpio, CTRL_OUT),
 			    CTLO_OUTPUT_SET | value);
 }
@@ -149,6 +156,9 @@ static int crystalcove_gpio_get(struct gpio_chip *chip, unsigned gpio)
 	int ret;
 	unsigned int val;
 
+	if (gpio > CRYSTALCOVE_VGPIO_NUM)
+		return 0;
+
 	ret = regmap_read(cg->regmap, to_reg(gpio, CTRL_IN), &val);
 	if (ret)
 		return ret;
@@ -161,6 +171,9 @@ static void crystalcove_gpio_set(struct gpio_chip *chip,
 {
 	struct crystalcove_gpio *cg = to_cg(chip);
 
+	if (gpio > CRYSTALCOVE_VGPIO_NUM)
+		return;
+
 	if (value)
 		regmap_update_bits(cg->regmap, to_reg(gpio, CTRL_OUT), 1, 1);
 	else
@@ -256,7 +269,7 @@ static irqreturn_t crystalcove_gpio_irq_handler(int irq, void *data)
 
 	pending = p0 | p1 << 8;
 
-	for (gpio = 0; gpio < cg->chip.ngpio; gpio++) {
+	for (gpio = 0; gpio < CRYSTALCOVE_GPIO_NUM; gpio++) {
 		if (pending & BIT(gpio)) {
 			virq = irq_find_mapping(cg->chip.irqdomain, gpio);
 			generic_handle_irq(virq);
@@ -273,7 +286,7 @@ static void crystalcove_gpio_dbg_show(struct seq_file *s,
 	int gpio, offset;
 	unsigned int ctlo, ctli, mirqs0, mirqsx, irq;
 
-	for (gpio = 0; gpio < cg->chip.ngpio; gpio++) {
+	for (gpio = 0; gpio < CRYSTALCOVE_GPIO_NUM; gpio++) {
 		regmap_read(cg->regmap, to_reg(gpio, CTRL_OUT), &ctlo);
 		regmap_read(cg->regmap, to_reg(gpio, CTRL_IN), &ctli);
 		regmap_read(cg->regmap, gpio < 8 ? MGPIO0IRQS0 : MGPIO1IRQS0,
@@ -320,7 +333,7 @@ static int crystalcove_gpio_probe(struct platform_device *pdev)
 	cg->chip.get = crystalcove_gpio_get;
 	cg->chip.set = crystalcove_gpio_set;
 	cg->chip.base = -1;
-	cg->chip.ngpio = CRYSTALCOVE_GPIO_NUM;
+	cg->chip.ngpio = CRYSTALCOVE_VGPIO_NUM;
 	cg->chip.can_sleep = true;
 	cg->chip.dev = dev;
 	cg->chip.dbg_show = crystalcove_gpio_dbg_show;
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index c1d4105e1c1d..383ade1a211b 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -27,7 +27,7 @@
  */
 
 #ifndef ARCH_NR_GPIOS
-#define ARCH_NR_GPIOS		256
+#define ARCH_NR_GPIOS		512
 #endif
 
 /*
-- 
1.9.3


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

* [PATCH 2/2] PMIC / opregion: support PMIC customized operation region for CrystalCove
  2014-09-09  2:32 [PATCH 0/2] Support CrystalCove PMIC ACPI operation region Aaron Lu
  2014-09-09  2:32 ` [PATCH 1/2] gpio / CrystalCove: support virtual GPIO Aaron Lu
@ 2014-09-09  2:32 ` Aaron Lu
  2014-10-08  8:05   ` Lee Jones
  2014-09-09  2:37 ` [PATCH 0/2] Support CrystalCove PMIC ACPI operation region Aaron Lu
  2014-09-15  2:57 ` Aaron Lu
  3 siblings, 1 reply; 21+ messages in thread
From: Aaron Lu @ 2014-09-09  2:32 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, Samuel Ortiz, Lee Jones, Arnd Bergmann
  Cc: linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, linux-acpi,
	Rafael J. Wysocki

The Baytrail-T platform firmware has defined two customized operation
regions for PMIC chip Crystal Cove - one is for power resource handling
and one is for thermal: sensor temperature reporting, trip point setting,
etc. This patch adds support for them on top of the existing Crystal Cove
PMIC driver.

The reason to split code into a separate file intel_soc_pmic_opregion.c
is that there are more PMIC driver with ACPI operation region support
coming and we can re-use those code. The intel_soc_pmic_opregion_data
structure is created also for this purpose: when we need to support a
new PMIC's operation region, we just need to fill those callbacks and
the two register mapping tables.

Signed-off-by: Aaron Lu <aaron.lu@intel.com>
---
 drivers/mfd/Kconfig                       |  11 +
 drivers/mfd/Makefile                      |   1 +
 drivers/mfd/intel_soc_pmic_crc.c          |   3 +
 drivers/mfd/intel_soc_pmic_crc_opregion.c | 229 +++++++++++++++++++
 drivers/mfd/intel_soc_pmic_opregion.c     | 350 ++++++++++++++++++++++++++++++
 drivers/mfd/intel_soc_pmic_opregion.h     |  35 +++
 6 files changed, 629 insertions(+)
 create mode 100644 drivers/mfd/intel_soc_pmic_crc_opregion.c
 create mode 100644 drivers/mfd/intel_soc_pmic_opregion.c
 create mode 100644 drivers/mfd/intel_soc_pmic_opregion.h

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index de5abf244746..77a7229058a6 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -266,6 +266,17 @@ config INTEL_SOC_PMIC
 	  thermal, charger and related power management functions
 	  on these systems.
 
+config CRC_PMIC_OPREGION
+	tristate "ACPI operation region support for CrystalCove PMIC"
+	depends on ACPI
+	depends on INTEL_SOC_PMIC
+	help
+	  Select this option to enable support for ACPI operation
+	  region of the PMIC chip. The operation region can be used
+	  to control power rails and sensor reading/writing on the
+	  PMIC chip. This config addes ACPI operation region support
+	  for CrystalCove PMIC.
+
 config MFD_INTEL_MSIC
 	bool "Intel MSIC"
 	depends on INTEL_SCU_IPC
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index f00148782d9b..e02f0573e293 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -172,3 +172,4 @@ obj-$(CONFIG_MFD_IPAQ_MICRO)	+= ipaq-micro.o
 
 intel-soc-pmic-objs		:= intel_soc_pmic_core.o intel_soc_pmic_crc.o
 obj-$(CONFIG_INTEL_SOC_PMIC)	+= intel-soc-pmic.o
+obj-$(CONFIG_CRC_PMIC_OPREGION) += intel_soc_pmic_crc_opregion.o intel_soc_pmic_opregion.o
diff --git a/drivers/mfd/intel_soc_pmic_crc.c b/drivers/mfd/intel_soc_pmic_crc.c
index 7107cab832e6..48845d636bba 100644
--- a/drivers/mfd/intel_soc_pmic_crc.c
+++ b/drivers/mfd/intel_soc_pmic_crc.c
@@ -106,6 +106,9 @@ static struct mfd_cell crystal_cove_dev[] = {
 		.num_resources = ARRAY_SIZE(gpio_resources),
 		.resources = gpio_resources,
 	},
+	{
+		.name = "crystal_cove_region",
+	},
 };
 
 static struct regmap_config crystal_cove_regmap_config = {
diff --git a/drivers/mfd/intel_soc_pmic_crc_opregion.c b/drivers/mfd/intel_soc_pmic_crc_opregion.c
new file mode 100644
index 000000000000..27b67dc3fa8d
--- /dev/null
+++ b/drivers/mfd/intel_soc_pmic_crc_opregion.c
@@ -0,0 +1,229 @@
+/*
+ * intel_soc_pmic_crc_opregion.c - Intel SoC PMIC operation region Driver
+ *
+ * Copyright (C) 2014 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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/module.h>
+#include <linux/acpi.h>
+#include <linux/mfd/intel_soc_pmic.h>
+#include <linux/regmap.h>
+#include <linux/platform_device.h>
+#include "intel_soc_pmic_opregion.h"
+
+#define PWR_SOURCE_SELECT	BIT(1)
+
+#define PMIC_A0LOCK_REG		0xc5
+
+static struct pmic_pwr_table pwr_table[] = {
+	{
+		.address = 0x24,
+		.pwr_reg = {
+			.reg = 0x66,
+			.bit = 0x00,
+		},
+	},	/* X285 -> V2P85SX, camara */
+	{
+		.address = 0x48,
+		.pwr_reg = {
+			.reg = 0x5d,
+			.bit = 0x00,
+		},
+	},	/* V18X -> V1P8SX, eMMC/camara/audio */
+};
+
+static struct pmic_dptf_table dptf_table[] = {
+	{
+		.address = 0x00,
+		.reg = 0x75
+	},	/* TMP0 -> SYS0_THRM_RSLT_L */
+	{
+		.address = 0x04,
+		.reg = 0x95
+	},	/* AX00 -> SYS0_THRMALRT0_L */
+	{
+		.address = 0x08,
+		.reg = 0x97
+	},	/* AX01 -> SYS0_THRMALRT1_L */
+	{
+		.address = 0x0c,
+		.reg = 0x77
+	},	/* TMP1 -> SYS1_THRM_RSLT_L */
+	{
+		.address = 0x10,
+		.reg = 0x9a
+	},	/* AX10 -> SYS1_THRMALRT0_L */
+	{
+		.address = 0x14,
+		.reg = 0x9c
+	},	/* AX11 -> SYS1_THRMALRT1_L */
+	{
+		.address = 0x18,
+		.reg = 0x79
+	},	/* TMP2 -> SYS2_THRM_RSLT_L */
+	{
+		.address = 0x1c,
+		.reg = 0x9f
+	},	/* AX20 -> SYS2_THRMALRT0_L */
+	{
+		.address = 0x20,
+		.reg = 0xa1
+	},	/* AX21 -> SYS2_THRMALRT1_L */
+	{
+		.address = 0x48,
+		.reg = 0x94
+	},	/* PEN0 -> SYS0_THRMALRT0_H */
+	{
+		.address = 0x4c,
+		.reg = 0x99
+	},	/* PEN1 -> SYS1_THRMALRT1_H */
+	{
+		.address = 0x50,
+		.reg = 0x9e
+	},	/* PEN2 -> SYS2_THRMALRT2_H */
+};
+
+static int intel_crc_pmic_get_power(struct regmap *regmap,
+				    struct pmic_pwr_reg *preg, u64 *value)
+{
+	int data;
+
+	if (regmap_read(regmap, preg->reg, &data))
+		return -EIO;
+
+	*value = (data & PWR_SOURCE_SELECT) && (data & BIT(preg->bit)) ? 1 : 0;
+	return 0;
+}
+
+static int intel_crc_pmic_update_power(struct regmap *regmap,
+				       struct pmic_pwr_reg *preg, bool on)
+{
+	int data;
+
+	if (regmap_read(regmap, preg->reg, &data))
+		return -EIO;
+
+	if (on) {
+		data |= PWR_SOURCE_SELECT | BIT(preg->bit);
+	} else {
+		data &= ~BIT(preg->bit);
+		data |= PWR_SOURCE_SELECT;
+	}
+
+	if (regmap_write(regmap, preg->reg, data))
+		return -EIO;
+	return 0;
+}
+
+/* Raw temperature value is 10bits: 8bits in reg and 2bits in reg-1 bit0,1 */
+static int intel_crc_pmic_get_raw_temp(struct regmap *regmap, int reg)
+{
+	int temp_l, temp_h;
+
+	if (regmap_read(regmap, reg, &temp_l) ||
+	    regmap_read(regmap, reg - 1, &temp_h))
+		return -EIO;
+
+	return (temp_l | ((temp_h & 0x3) << 8));
+}
+
+static int
+intel_crc_pmic_update_aux(struct regmap *regmap, int reg, int raw)
+{
+	if (regmap_write(regmap, reg, raw) ||
+	    regmap_update_bits(regmap, reg - 1, 0x3, raw >> 8))
+		return -EIO;
+
+	return 0;
+}
+
+static int
+intel_crc_pmic_get_policy(struct regmap *regmap, int reg, u64 *value)
+{
+	int pen;
+
+	if (regmap_read(regmap, reg, &pen))
+		return -EIO;
+	*value = pen >> 7;
+	return 0;
+}
+
+static int intel_crc_pmic_update_policy(struct regmap *regmap,
+					int reg, int enable)
+{
+	int alert0;
+
+	/* Update to policy enable bit requires unlocking a0lock */
+	if (regmap_read(regmap, PMIC_A0LOCK_REG, &alert0))
+		return -EIO;
+	if (regmap_update_bits(regmap, PMIC_A0LOCK_REG, 0x01, 0))
+		return -EIO;
+
+	if (regmap_update_bits(regmap, reg, 0x80, enable << 7))
+		return -EIO;
+
+	/* restore alert0 */
+	if (regmap_write(regmap, PMIC_A0LOCK_REG, alert0))
+		return -EIO;
+
+	return 0;
+}
+
+static struct intel_soc_pmic_opregion_data intel_crc_pmic_opregion_data = {
+	.get_power	= intel_crc_pmic_get_power,
+	.update_power	= intel_crc_pmic_update_power,
+	.get_raw_temp	= intel_crc_pmic_get_raw_temp,
+	.update_aux	= intel_crc_pmic_update_aux,
+	.get_policy	= intel_crc_pmic_get_policy,
+	.update_policy	= intel_crc_pmic_update_policy,
+	.pwr_table	= pwr_table,
+	.pwr_table_count= ARRAY_SIZE(pwr_table),
+	.dptf_table	= dptf_table,
+	.dptf_table_count = ARRAY_SIZE(dptf_table),
+};
+
+static int intel_crc_pmic_opregion_probe(struct platform_device *pdev)
+{
+	struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
+	return intel_soc_pmic_install_opregion_handler(&pdev->dev,
+			ACPI_HANDLE(pdev->dev.parent), pmic->regmap,
+			&intel_crc_pmic_opregion_data);
+}
+
+static int intel_crc_pmic_opregion_remove(struct platform_device *pdev)
+{
+	intel_soc_pmic_remove_opregion_handler(ACPI_HANDLE(pdev->dev.parent));
+	return 0;
+}
+
+#define DRV_NAME "crystal_cove_region"
+
+static struct platform_device_id crystal_cove_opregion_id_table[] = {
+	{ .name = DRV_NAME },
+	{},
+};
+
+static struct platform_driver intel_crc_pmic_opregion_driver = {
+	.probe = intel_crc_pmic_opregion_probe,
+	.remove = intel_crc_pmic_opregion_remove,
+	.id_table = crystal_cove_opregion_id_table,
+	.driver = {
+		.name = DRV_NAME,
+	},
+};
+
+MODULE_DEVICE_TABLE(platform, crystal_cove_opregion_id_table);
+
+module_platform_driver(intel_crc_pmic_opregion_driver);
+
+MODULE_DESCRIPTION("CrystalCove ACPI opregion driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/intel_soc_pmic_opregion.c b/drivers/mfd/intel_soc_pmic_opregion.c
new file mode 100644
index 000000000000..62824a35ce97
--- /dev/null
+++ b/drivers/mfd/intel_soc_pmic_opregion.c
@@ -0,0 +1,350 @@
+/*
+ * intel_soc_pmic_opregion.c - Intel SoC PMIC operation region Driver
+ *
+ * Copyright (C) 2014 Intel Corporation. All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License version
+ * 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that 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/module.h>
+#include <linux/acpi.h>
+#include <linux/regmap.h>
+#include "intel_soc_pmic_opregion.h"
+
+#define PMIC_PMOP_OPREGION_ID	0x8d
+#define PMIC_DPTF_OPREGION_ID	0x8c
+
+struct acpi_lpat {
+	int temp;
+	int raw;
+};
+
+struct intel_soc_pmic_opregion {
+	struct mutex lock;
+	struct acpi_lpat *lpat;
+	int lpat_count;
+	struct regmap *regmap;
+	struct intel_soc_pmic_opregion_data *data;
+};
+
+static struct pmic_pwr_reg *
+pmic_get_pwr_reg(int address, struct pmic_pwr_table *table, int count)
+{
+	int i;
+
+	for (i = 0; i < count; i++) {
+		if (table[i].address == address)
+			return &table[i].pwr_reg;
+	}
+	return NULL;
+}
+
+static int
+pmic_get_dptf_reg(int address, struct pmic_dptf_table *table, int count)
+{
+	int i;
+
+	for (i = 0; i < count; i++) {
+		if (table[i].address == address)
+			return table[i].reg;
+	}
+	return -ENOENT;
+}
+
+/* Return temperature from raw value through LPAT table */
+static int raw_to_temp(struct acpi_lpat *lpat, int count, int raw)
+{
+	int i, delta_temp, delta_raw, temp;
+
+	for (i = 0; i < count - 1; i++) {
+		if ((raw >= lpat[i].raw && raw <= lpat[i+1].raw) ||
+		    (raw <= lpat[i].raw && raw >= lpat[i+1].raw))
+			break;
+	}
+
+	if (i == count - 1)
+		return -ENOENT;
+
+	delta_temp = lpat[i+1].temp - lpat[i].temp;
+	delta_raw = lpat[i+1].raw - lpat[i].raw;
+	temp = lpat[i].temp + (raw - lpat[i].raw) * delta_temp / delta_raw;
+
+	return temp;
+}
+
+/* Return raw value from temperature through LPAT table */
+static int temp_to_raw(struct acpi_lpat *lpat, int count, int temp)
+{
+	int i, delta_temp, delta_raw, raw;
+
+	for (i = 0; i < count - 1; i++) {
+		if (temp >= lpat[i].temp && temp <= lpat[i+1].temp)
+			break;
+	}
+
+	if (i == count - 1)
+		return -ENOENT;
+
+	delta_temp = lpat[i+1].temp - lpat[i].temp;
+	delta_raw = lpat[i+1].raw - lpat[i].raw;
+	raw = lpat[i].raw + (temp - lpat[i].temp) * delta_raw / delta_temp;
+
+	return raw;
+}
+
+static void
+pmic_dptf_lpat(struct intel_soc_pmic_opregion *opregion, acpi_handle handle,
+	       struct device *dev)
+{
+	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+	union acpi_object *obj_p, *obj_e;
+	int *lpat, i;
+	acpi_status status;
+
+	status = acpi_evaluate_object(handle, "LPAT", NULL, &buffer);
+	if (ACPI_FAILURE(status))
+		return;
+
+	obj_p = (union acpi_object *)buffer.pointer;
+	if (!obj_p || (obj_p->type != ACPI_TYPE_PACKAGE) ||
+	    (obj_p->package.count % 2) || (obj_p->package.count < 4))
+		goto out;
+
+	lpat = devm_kmalloc(dev, sizeof(*lpat) * obj_p->package.count,
+			    GFP_KERNEL);
+	if (!lpat)
+		goto out;
+
+	for (i = 0; i < obj_p->package.count; i++) {
+		obj_e = &obj_p->package.elements[i];
+		if (obj_e->type != ACPI_TYPE_INTEGER)
+			goto out;
+		lpat[i] = obj_e->integer.value;
+	}
+
+	opregion->lpat = (struct acpi_lpat *)lpat;
+	opregion->lpat_count = obj_p->package.count / 2;
+
+out:
+	kfree(buffer.pointer);
+}
+
+static acpi_status
+intel_soc_pmic_pmop_handler(u32 function, acpi_physical_address address,
+			    u32 bits, u64 *value64,
+			    void *handler_context, void *region_context)
+{
+	struct intel_soc_pmic_opregion *opregion = region_context;
+	struct regmap *regmap = opregion->regmap;
+	struct intel_soc_pmic_opregion_data *d = opregion->data;
+	struct pmic_pwr_reg *preg;
+	int result;
+
+	if (bits != 32 || !value64)
+		return AE_BAD_PARAMETER;
+
+	if (function == ACPI_WRITE && !(*value64 == 0 || *value64 == 1))
+		return AE_BAD_PARAMETER;
+
+	preg = pmic_get_pwr_reg(address, d->pwr_table, d->pwr_table_count);
+	if (!preg)
+		return AE_BAD_PARAMETER;
+
+	mutex_lock(&opregion->lock);
+
+	if (function == ACPI_READ)
+		result = d->get_power(regmap, preg, value64);
+	else
+		result = d->update_power(regmap, preg, *value64 == 1);
+
+	mutex_unlock(&opregion->lock);
+
+	return result ? AE_ERROR : AE_OK;
+}
+
+static acpi_status pmic_read_temp(struct intel_soc_pmic_opregion *opregion,
+				  int reg, u64 *value)
+{
+	int raw_temp, temp;
+
+	if (!opregion->data->get_raw_temp)
+		return AE_BAD_PARAMETER;
+
+	raw_temp = opregion->data->get_raw_temp(opregion->regmap, reg);
+	if (raw_temp < 0)
+		return AE_ERROR;
+
+	if (!opregion->lpat) {
+		*value = raw_temp;
+		return AE_OK;
+	}
+
+	temp = raw_to_temp(opregion->lpat, opregion->lpat_count, raw_temp);
+	if (temp < 0)
+		return AE_ERROR;
+
+	*value = temp;
+	return AE_OK;
+}
+
+static acpi_status pmic_dptf_temp(struct intel_soc_pmic_opregion *opregion,
+				  int reg, u32 function, u64 *value)
+{
+	if (function != ACPI_READ)
+		return AE_BAD_PARAMETER;
+
+	return pmic_read_temp(opregion, reg, value);
+}
+
+static acpi_status pmic_dptf_aux(struct intel_soc_pmic_opregion *opregion,
+				 int reg, u32 function, u64 *value)
+{
+	int raw_temp;
+
+	if (function == ACPI_READ)
+		return pmic_read_temp(opregion, reg, value);
+
+	if (!opregion->data->update_aux)
+		return AE_BAD_PARAMETER;
+
+	if (opregion->lpat) {
+		raw_temp = temp_to_raw(opregion->lpat, opregion->lpat_count,
+					 *value);
+		if (raw_temp < 0)
+			return AE_ERROR;
+	} else {
+		raw_temp = *value;
+	}
+
+	return opregion->data->update_aux(opregion->regmap, reg, raw_temp) ?
+		AE_ERROR : AE_OK;
+}
+
+static acpi_status pmic_dptf_pen(struct intel_soc_pmic_opregion *opregion,
+				 int reg, u32 function, u64 *value)
+{
+	struct intel_soc_pmic_opregion_data *d = opregion->data;
+	struct regmap *regmap = opregion->regmap;
+
+	if (!d->get_policy || !d->update_policy)
+		return AE_BAD_PARAMETER;
+
+	if (function == ACPI_READ)
+		return d->get_policy(regmap, reg, value) ? AE_ERROR : AE_OK;
+
+	if (*value != 0 || *value != 1)
+		return AE_BAD_PARAMETER;
+
+	return d->update_policy(regmap, reg, *value) ? AE_ERROR : AE_OK;
+}
+
+static bool pmic_dptf_is_temp(int address)
+{
+	return (address <= 0x3c) && !(address % 12);
+}
+
+static bool pmic_dptf_is_aux(int address)
+{
+	return (address >= 4 && address <= 0x40 && !((address - 4) % 12)) ||
+	       (address >= 8 && address <= 0x44 && !((address - 8) % 12));
+}
+
+static bool pmic_dptf_is_pen(int address)
+{
+	return address >= 0x48 && address <= 0x5c;
+}
+
+static acpi_status
+intel_soc_pmic_dptf_handler(u32 function, acpi_physical_address address,
+			    u32 bits, u64 *value64,
+			    void *handler_context, void *region_context)
+{
+	struct intel_soc_pmic_opregion *opregion = region_context;
+	int reg;
+	int result;
+
+	if (bits != 32 || !value64)
+		return AE_BAD_PARAMETER;
+
+	reg = pmic_get_dptf_reg(address, opregion->data->dptf_table,
+				opregion->data->dptf_table_count);
+	if (!reg)
+		return AE_BAD_PARAMETER;
+
+	mutex_lock(&opregion->lock);
+
+	result = AE_BAD_PARAMETER;
+	if (pmic_dptf_is_temp(address))
+		result = pmic_dptf_temp(opregion, reg, function, value64);
+	else if (pmic_dptf_is_aux(address))
+		result = pmic_dptf_aux(opregion, reg, function, value64);
+	else if (pmic_dptf_is_pen(address))
+		result = pmic_dptf_pen(opregion, reg, function, value64);
+
+	mutex_unlock(&opregion->lock);
+
+	return result;
+}
+
+int
+intel_soc_pmic_install_opregion_handler(struct device *dev,
+					acpi_handle handle,
+					struct regmap *regmap,
+					struct intel_soc_pmic_opregion_data *d)
+{
+	acpi_status status;
+	struct intel_soc_pmic_opregion *opregion;
+
+	if (!dev || !regmap || !d)
+		return -EINVAL;
+
+	if (!handle)
+		return -ENODEV;
+
+	opregion = devm_kzalloc(dev, sizeof(*opregion), GFP_KERNEL);
+	if (!opregion)
+		return -ENOMEM;
+
+	mutex_init(&opregion->lock);
+	opregion->regmap = regmap;
+	pmic_dptf_lpat(opregion, handle, dev);
+
+	status = acpi_install_address_space_handler(handle,
+						    PMIC_PMOP_OPREGION_ID,
+						    intel_soc_pmic_pmop_handler,
+						    NULL, opregion);
+	if (ACPI_FAILURE(status))
+		return -ENODEV;
+
+	status = acpi_install_address_space_handler(handle,
+						    PMIC_DPTF_OPREGION_ID,
+						    intel_soc_pmic_dptf_handler,
+						    NULL, opregion);
+	if (ACPI_FAILURE(status)) {
+		acpi_remove_address_space_handler(handle, PMIC_PMOP_OPREGION_ID,
+						  intel_soc_pmic_pmop_handler);
+		return -ENODEV;
+	}
+
+	opregion->data = d;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(intel_soc_pmic_install_opregion_handler);
+
+void intel_soc_pmic_remove_opregion_handler(acpi_handle handle)
+{
+	acpi_remove_address_space_handler(handle, PMIC_PMOP_OPREGION_ID,
+					  intel_soc_pmic_pmop_handler);
+	acpi_remove_address_space_handler(handle, PMIC_DPTF_OPREGION_ID,
+					  intel_soc_pmic_dptf_handler);
+}
+EXPORT_SYMBOL_GPL(intel_soc_pmic_remove_opregion_handler);
+
+MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/intel_soc_pmic_opregion.h b/drivers/mfd/intel_soc_pmic_opregion.h
new file mode 100644
index 000000000000..752ec3d2bcbb
--- /dev/null
+++ b/drivers/mfd/intel_soc_pmic_opregion.h
@@ -0,0 +1,35 @@
+#ifndef __INTEL_SOC_PMIC_OPREGION_H
+#define __INTEL_SOC_PMIC_OPREGION_H
+
+struct pmic_pwr_reg {
+	int reg;	/* corresponding PMIC register */
+	int bit;	/* control bit for power */
+};
+
+struct pmic_pwr_table {
+	int address;	/* operation region address */
+	struct pmic_pwr_reg pwr_reg;
+};
+
+struct pmic_dptf_table {
+	int address;	/* operation region address */
+	int reg;	/* corresponding thermal register */
+};
+
+struct intel_soc_pmic_opregion_data {
+	int (*get_power)(struct regmap *r, struct pmic_pwr_reg *preg, u64 *value);
+	int (*update_power)(struct regmap *r, struct pmic_pwr_reg *preg, bool on);
+	int (*get_raw_temp)(struct regmap *r, int reg);
+	int (*update_aux)(struct regmap *r, int reg, int raw_temp);
+	int (*get_policy)(struct regmap *r, int reg, u64 *value);
+	int (*update_policy)(struct regmap *r, int reg, int enable);
+	struct pmic_pwr_table *pwr_table;
+	int pwr_table_count;
+	struct pmic_dptf_table *dptf_table;
+	int dptf_table_count;
+};
+
+int intel_soc_pmic_install_opregion_handler(struct device *dev, acpi_handle handle, struct regmap *regmap, struct intel_soc_pmic_opregion_data *d);
+void intel_soc_pmic_remove_opregion_handler(acpi_handle handle);
+
+#endif
-- 
1.9.3


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

* Re: [PATCH 0/2] Support CrystalCove PMIC ACPI operation region
  2014-09-09  2:32 [PATCH 0/2] Support CrystalCove PMIC ACPI operation region Aaron Lu
  2014-09-09  2:32 ` [PATCH 1/2] gpio / CrystalCove: support virtual GPIO Aaron Lu
  2014-09-09  2:32 ` [PATCH 2/2] PMIC / opregion: support PMIC customized operation region for CrystalCove Aaron Lu
@ 2014-09-09  2:37 ` Aaron Lu
  2014-09-15  2:57 ` Aaron Lu
  3 siblings, 0 replies; 21+ messages in thread
From: Aaron Lu @ 2014-09-09  2:37 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, Samuel Ortiz, Lee Jones, Arnd Bergmann
  Cc: linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, linux-acpi,
	Rafael J. Wysocki

I forgot to cc linux-acpi in the last series so please reply to this
thread, sorry for the inconvenience.

Regards,
Aaron

On Tue, Sep 09, 2014 at 10:32:46AM +0800, Aaron Lu wrote:
> The two patches add support for CrystalCove PMIC ACPI operation region.
> The PMIC chip has two customized operation regions: one for power rail
> manipulation and one for thermal purpose: sensor temperature reading
> and trip point value reading/setting.
> 
> For an example ASL code on ASUS T100 with CrystalCove PMIC, see here:
> https://gist.github.com/aaronlu/f5f65771a6c3251fae5d
> 
> Aaron Lu (2):
>   gpio / CrystalCove: support virtual GPIO
>   PMIC / opregion: support PMIC customized operation region for
>     CrystalCove
> 
>  drivers/gpio/gpio-crystalcove.c           |  19 +-
>  drivers/mfd/Kconfig                       |  11 +
>  drivers/mfd/Makefile                      |   1 +
>  drivers/mfd/intel_soc_pmic_crc.c          |   3 +
>  drivers/mfd/intel_soc_pmic_crc_opregion.c | 229 +++++++++++++++++++
>  drivers/mfd/intel_soc_pmic_opregion.c     | 350 ++++++++++++++++++++++++++++++
>  drivers/mfd/intel_soc_pmic_opregion.h     |  35 +++
>  include/asm-generic/gpio.h                |   2 +-
>  8 files changed, 646 insertions(+), 4 deletions(-)
>  create mode 100644 drivers/mfd/intel_soc_pmic_crc_opregion.c
>  create mode 100644 drivers/mfd/intel_soc_pmic_opregion.c
>  create mode 100644 drivers/mfd/intel_soc_pmic_opregion.h
> 
> -- 
> 1.9.3
> 
> --
> 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] 21+ messages in thread

* Re: [PATCH 0/2] Support CrystalCove PMIC ACPI operation region
  2014-09-09  2:32 [PATCH 0/2] Support CrystalCove PMIC ACPI operation region Aaron Lu
                   ` (2 preceding siblings ...)
  2014-09-09  2:37 ` [PATCH 0/2] Support CrystalCove PMIC ACPI operation region Aaron Lu
@ 2014-09-15  2:57 ` Aaron Lu
  2014-09-15 22:43   ` Lee Jones
  3 siblings, 1 reply; 21+ messages in thread
From: Aaron Lu @ 2014-09-15  2:57 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, Samuel Ortiz, Lee Jones, Arnd Bergmann
  Cc: linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, linux-acpi,
	Rafael J. Wysocki

I wonder if anyone has looked at this?

Note that this is for CrystalCove PMIC operation region support and the
CrystalCove driver is already in mainline, not for the DollarCove PMIC
driver that Jacob is currently upstreaming, so the patch doesn't have
any dependency.

Regards,
Aaron

On Tue, Sep 09, 2014 at 10:32:46AM +0800, Aaron Lu wrote:
> The two patches add support for CrystalCove PMIC ACPI operation region.
> The PMIC chip has two customized operation regions: one for power rail
> manipulation and one for thermal purpose: sensor temperature reading
> and trip point value reading/setting.
> 
> For an example ASL code on ASUS T100 with CrystalCove PMIC, see here:
> https://gist.github.com/aaronlu/f5f65771a6c3251fae5d
> 
> Aaron Lu (2):
>   gpio / CrystalCove: support virtual GPIO
>   PMIC / opregion: support PMIC customized operation region for
>     CrystalCove
> 
>  drivers/gpio/gpio-crystalcove.c           |  19 +-
>  drivers/mfd/Kconfig                       |  11 +
>  drivers/mfd/Makefile                      |   1 +
>  drivers/mfd/intel_soc_pmic_crc.c          |   3 +
>  drivers/mfd/intel_soc_pmic_crc_opregion.c | 229 +++++++++++++++++++
>  drivers/mfd/intel_soc_pmic_opregion.c     | 350 ++++++++++++++++++++++++++++++
>  drivers/mfd/intel_soc_pmic_opregion.h     |  35 +++
>  include/asm-generic/gpio.h                |   2 +-
>  8 files changed, 646 insertions(+), 4 deletions(-)
>  create mode 100644 drivers/mfd/intel_soc_pmic_crc_opregion.c
>  create mode 100644 drivers/mfd/intel_soc_pmic_opregion.c
>  create mode 100644 drivers/mfd/intel_soc_pmic_opregion.h
> 
> -- 
> 1.9.3
> 
> --
> 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] 21+ messages in thread

* Re: [PATCH 0/2] Support CrystalCove PMIC ACPI operation region
  2014-09-15  2:57 ` Aaron Lu
@ 2014-09-15 22:43   ` Lee Jones
  0 siblings, 0 replies; 21+ messages in thread
From: Lee Jones @ 2014-09-15 22:43 UTC (permalink / raw)
  To: Aaron Lu
  Cc: Linus Walleij, Alexandre Courbot, Samuel Ortiz, Arnd Bergmann,
	linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, linux-acpi,
	Rafael J. Wysocki

On Mon, 15 Sep 2014, Aaron Lu wrote:

> I wonder if anyone has looked at this?
> 
> Note that this is for CrystalCove PMIC operation region support and the
> CrystalCove driver is already in mainline, not for the DollarCove PMIC
> driver that Jacob is currently upstreaming, so the patch doesn't have
> any dependency.

Not yet.  It is on my list of TODOs though.

> On Tue, Sep 09, 2014 at 10:32:46AM +0800, Aaron Lu wrote:
> > The two patches add support for CrystalCove PMIC ACPI operation region.
> > The PMIC chip has two customized operation regions: one for power rail
> > manipulation and one for thermal purpose: sensor temperature reading
> > and trip point value reading/setting.
> > 
> > For an example ASL code on ASUS T100 with CrystalCove PMIC, see here:
> > https://gist.github.com/aaronlu/f5f65771a6c3251fae5d
> > 
> > Aaron Lu (2):
> >   gpio / CrystalCove: support virtual GPIO
> >   PMIC / opregion: support PMIC customized operation region for
> >     CrystalCove
> > 
> >  drivers/gpio/gpio-crystalcove.c           |  19 +-
> >  drivers/mfd/Kconfig                       |  11 +
> >  drivers/mfd/Makefile                      |   1 +
> >  drivers/mfd/intel_soc_pmic_crc.c          |   3 +
> >  drivers/mfd/intel_soc_pmic_crc_opregion.c | 229 +++++++++++++++++++
> >  drivers/mfd/intel_soc_pmic_opregion.c     | 350 ++++++++++++++++++++++++++++++
> >  drivers/mfd/intel_soc_pmic_opregion.h     |  35 +++
> >  include/asm-generic/gpio.h                |   2 +-
> >  8 files changed, 646 insertions(+), 4 deletions(-)
> >  create mode 100644 drivers/mfd/intel_soc_pmic_crc_opregion.c
> >  create mode 100644 drivers/mfd/intel_soc_pmic_opregion.c
> >  create mode 100644 drivers/mfd/intel_soc_pmic_opregion.h
> > 

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH 1/2] gpio / CrystalCove: support virtual GPIO
  2014-09-09  2:32 ` [PATCH 1/2] gpio / CrystalCove: support virtual GPIO Aaron Lu
@ 2014-09-23 10:13   ` Linus Walleij
  2014-09-24 11:18   ` Linus Walleij
  1 sibling, 0 replies; 21+ messages in thread
From: Linus Walleij @ 2014-09-23 10:13 UTC (permalink / raw)
  To: Aaron Lu, Mika Westerberg, Darren Hart
  Cc: Alexandre Courbot, Samuel Ortiz, Lee Jones, Arnd Bergmann,
	linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, ACPI Devel Maling List,
	Rafael J. Wysocki

On Tue, Sep 9, 2014 at 4:32 AM, Aaron Lu <aaron.lu@intel.com> wrote:

> The virtual GPIO introduced in ACPI table of Baytrail-T based system is
> used to solve a problem under Windows. We do not have such problems
> under Linux so we do not actually need them. But we have to tell GPIO
> library that the Crystal Cove GPIO chip has this many GPIO pins or the
> common GPIO handler will refuse any access to those high number GPIO
> pins, which will resulted in a failure evaluation of every ACPI control
> method that is used to turn on/off power resource and/or report sensor
> temperatures.
>
> Due to the high number of virtual GPIOs, the value of ARCH_NR_GPIOS is
> bumped from 256 to 512 to avoid failures on platforms that have various
> GPIO controllers.
>
> Signed-off-by: Aaron Lu <aaron.lu@intel.com>

I have some other patch pending increasing the default GPIO# to
512, but anyhow: this needs review from someone. Where is
Lejun? Mika also reviewed last time. Someone I trust to understand
ACPI need to be involved, Rafael, Darren....

Yours,
Linus Walleij

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

* Re: [PATCH 1/2] gpio / CrystalCove: support virtual GPIO
  2014-09-09  2:32 ` [PATCH 1/2] gpio / CrystalCove: support virtual GPIO Aaron Lu
  2014-09-23 10:13   ` Linus Walleij
@ 2014-09-24 11:18   ` Linus Walleij
  2014-09-25  2:57     ` [PATCH v2 " Aaron Lu
  1 sibling, 1 reply; 21+ messages in thread
From: Linus Walleij @ 2014-09-24 11:18 UTC (permalink / raw)
  To: Aaron Lu
  Cc: Alexandre Courbot, Samuel Ortiz, Lee Jones, Arnd Bergmann,
	linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, ACPI Devel Maling List,
	Rafael J. Wysocki

On Tue, Sep 9, 2014 at 4:32 AM, Aaron Lu <aaron.lu@intel.com> wrote:

> diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
> index c1d4105e1c1d..383ade1a211b 100644
> --- a/include/asm-generic/gpio.h
> +++ b/include/asm-generic/gpio.h
> @@ -27,7 +27,7 @@
>   */
>
>  #ifndef ARCH_NR_GPIOS
> -#define ARCH_NR_GPIOS          256
> +#define ARCH_NR_GPIOS          512
>  #endif

I have applied another patch from Mika for this, so remove this
hunk of the patch.

Yours,
Linus Walleij

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

* [PATCH v2 1/2] gpio / CrystalCove: support virtual GPIO
  2014-09-24 11:18   ` Linus Walleij
@ 2014-09-25  2:57     ` Aaron Lu
  2014-09-25 11:15       ` Mika Westerberg
  2014-09-25 13:16       ` Linus Walleij
  0 siblings, 2 replies; 21+ messages in thread
From: Aaron Lu @ 2014-09-25  2:57 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Samuel Ortiz, Lee Jones, Arnd Bergmann,
	linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, ACPI Devel Maling List,
	Rafael J. Wysocki

The virtual GPIO introduced in ACPI table of Baytrail-T based system is
used to solve a problem under Windows. We do not have such problems
under Linux so we do not actually need them. But we have to tell GPIO
library that the Crystal Cove GPIO chip has this many GPIO pins or the
common GPIO handler will refuse any access to those high number GPIO
pins, which will resulted in a failure evaluation of every ACPI control
method that is used to turn on/off power resource and/or report sensor
temperatures.

Signed-off-by: Aaron Lu <aaron.lu@intel.com>
---
v2: remove the hunk to increase NR_GPIO to 512.

 drivers/gpio/gpio-crystalcove.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpio-crystalcove.c b/drivers/gpio/gpio-crystalcove.c
index e3712f0e51ab..186b76ef71a1 100644
--- a/drivers/gpio/gpio-crystalcove.c
+++ b/drivers/gpio/gpio-crystalcove.c
@@ -24,6 +24,7 @@
 #include <linux/mfd/intel_soc_pmic.h>
 
 #define CRYSTALCOVE_GPIO_NUM	16
+#define CRYSTALCOVE_VGPIO_NUM	0x5e
 
 #define UPDATE_IRQ_TYPE		BIT(0)
 #define UPDATE_IRQ_MASK		BIT(1)
@@ -130,6 +131,9 @@ static int crystalcove_gpio_dir_in(struct gpio_chip *chip, unsigned gpio)
 {
 	struct crystalcove_gpio *cg = to_cg(chip);
 
+	if (gpio > CRYSTALCOVE_VGPIO_NUM)
+		return 0;
+
 	return regmap_write(cg->regmap, to_reg(gpio, CTRL_OUT),
 			    CTLO_INPUT_SET);
 }
@@ -139,6 +143,9 @@ static int crystalcove_gpio_dir_out(struct gpio_chip *chip, unsigned gpio,
 {
 	struct crystalcove_gpio *cg = to_cg(chip);
 
+	if (gpio > CRYSTALCOVE_VGPIO_NUM)
+		return 0;
+
 	return regmap_write(cg->regmap, to_reg(gpio, CTRL_OUT),
 			    CTLO_OUTPUT_SET | value);
 }
@@ -149,6 +156,9 @@ static int crystalcove_gpio_get(struct gpio_chip *chip, unsigned gpio)
 	int ret;
 	unsigned int val;
 
+	if (gpio > CRYSTALCOVE_VGPIO_NUM)
+		return 0;
+
 	ret = regmap_read(cg->regmap, to_reg(gpio, CTRL_IN), &val);
 	if (ret)
 		return ret;
@@ -161,6 +171,9 @@ static void crystalcove_gpio_set(struct gpio_chip *chip,
 {
 	struct crystalcove_gpio *cg = to_cg(chip);
 
+	if (gpio > CRYSTALCOVE_VGPIO_NUM)
+		return;
+
 	if (value)
 		regmap_update_bits(cg->regmap, to_reg(gpio, CTRL_OUT), 1, 1);
 	else
@@ -256,7 +269,7 @@ static irqreturn_t crystalcove_gpio_irq_handler(int irq, void *data)
 
 	pending = p0 | p1 << 8;
 
-	for (gpio = 0; gpio < cg->chip.ngpio; gpio++) {
+	for (gpio = 0; gpio < CRYSTALCOVE_GPIO_NUM; gpio++) {
 		if (pending & BIT(gpio)) {
 			virq = irq_find_mapping(cg->chip.irqdomain, gpio);
 			generic_handle_irq(virq);
@@ -273,7 +286,7 @@ static void crystalcove_gpio_dbg_show(struct seq_file *s,
 	int gpio, offset;
 	unsigned int ctlo, ctli, mirqs0, mirqsx, irq;
 
-	for (gpio = 0; gpio < cg->chip.ngpio; gpio++) {
+	for (gpio = 0; gpio < CRYSTALCOVE_GPIO_NUM; gpio++) {
 		regmap_read(cg->regmap, to_reg(gpio, CTRL_OUT), &ctlo);
 		regmap_read(cg->regmap, to_reg(gpio, CTRL_IN), &ctli);
 		regmap_read(cg->regmap, gpio < 8 ? MGPIO0IRQS0 : MGPIO1IRQS0,
@@ -320,7 +333,7 @@ static int crystalcove_gpio_probe(struct platform_device *pdev)
 	cg->chip.get = crystalcove_gpio_get;
 	cg->chip.set = crystalcove_gpio_set;
 	cg->chip.base = -1;
-	cg->chip.ngpio = CRYSTALCOVE_GPIO_NUM;
+	cg->chip.ngpio = CRYSTALCOVE_VGPIO_NUM;
 	cg->chip.can_sleep = true;
 	cg->chip.dev = dev;
 	cg->chip.dbg_show = crystalcove_gpio_dbg_show;
-- 
1.9.3


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

* Re: [PATCH v2 1/2] gpio / CrystalCove: support virtual GPIO
  2014-09-25  2:57     ` [PATCH v2 " Aaron Lu
@ 2014-09-25 11:15       ` Mika Westerberg
  2014-09-26  5:21         ` Aaron Lu
  2014-09-25 13:16       ` Linus Walleij
  1 sibling, 1 reply; 21+ messages in thread
From: Mika Westerberg @ 2014-09-25 11:15 UTC (permalink / raw)
  To: Aaron Lu
  Cc: Linus Walleij, Alexandre Courbot, Samuel Ortiz, Lee Jones,
	Arnd Bergmann, linux-gpio, linux-arch, linux-kernel, Jacob Pan,
	Lejun Zhu, Radivoje Jovanovic, Daniel Glöckner,
	ACPI Devel Maling List, Rafael J. Wysocki

On Thu, Sep 25, 2014 at 10:57:26AM +0800, Aaron Lu wrote:
> The virtual GPIO introduced in ACPI table of Baytrail-T based system is
> used to solve a problem under Windows. We do not have such problems
> under Linux so we do not actually need them. But we have to tell GPIO
> library that the Crystal Cove GPIO chip has this many GPIO pins or the
> common GPIO handler will refuse any access to those high number GPIO
> pins, which will resulted in a failure evaluation of every ACPI control
> method that is used to turn on/off power resource and/or report sensor
> temperatures.
> 
> Signed-off-by: Aaron Lu <aaron.lu@intel.com>

Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>

A minor nit, see below:

> ---
> v2: remove the hunk to increase NR_GPIO to 512.
> 
>  drivers/gpio/gpio-crystalcove.c | 19 ++++++++++++++++---
>  1 file changed, 16 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpio/gpio-crystalcove.c b/drivers/gpio/gpio-crystalcove.c
> index e3712f0e51ab..186b76ef71a1 100644
> --- a/drivers/gpio/gpio-crystalcove.c
> +++ b/drivers/gpio/gpio-crystalcove.c
> @@ -24,6 +24,7 @@
>  #include <linux/mfd/intel_soc_pmic.h>
>  
>  #define CRYSTALCOVE_GPIO_NUM	16
> +#define CRYSTALCOVE_VGPIO_NUM	0x5e

I would rather see this spelled in decimal base.

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

* Re: [PATCH v2 1/2] gpio / CrystalCove: support virtual GPIO
  2014-09-25  2:57     ` [PATCH v2 " Aaron Lu
  2014-09-25 11:15       ` Mika Westerberg
@ 2014-09-25 13:16       ` Linus Walleij
  2014-09-26  5:22         ` Aaron Lu
  1 sibling, 1 reply; 21+ messages in thread
From: Linus Walleij @ 2014-09-25 13:16 UTC (permalink / raw)
  To: Aaron Lu
  Cc: Alexandre Courbot, Samuel Ortiz, Lee Jones, Arnd Bergmann,
	linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, ACPI Devel Maling List,
	Rafael J. Wysocki

On Thu, Sep 25, 2014 at 4:57 AM, Aaron Lu <aaron.lu@intel.com> wrote:

> The virtual GPIO introduced in ACPI table of Baytrail-T based system is
> used to solve a problem under Windows. We do not have such problems
> under Linux so we do not actually need them. But we have to tell GPIO
> library that the Crystal Cove GPIO chip has this many GPIO pins or the
> common GPIO handler will refuse any access to those high number GPIO
> pins, which will resulted in a failure evaluation of every ACPI control
> method that is used to turn on/off power resource and/or report sensor
> temperatures.
>
> Signed-off-by: Aaron Lu <aaron.lu@intel.com>
> ---
> v2: remove the hunk to increase NR_GPIO to 512.

Patch applied with Mika's ACK, also renumbered 0x5e to 94.

Yours,
Linus Walleij

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

* Re: [PATCH v2 1/2] gpio / CrystalCove: support virtual GPIO
  2014-09-25 11:15       ` Mika Westerberg
@ 2014-09-26  5:21         ` Aaron Lu
  0 siblings, 0 replies; 21+ messages in thread
From: Aaron Lu @ 2014-09-26  5:21 UTC (permalink / raw)
  To: Mika Westerberg
  Cc: Linus Walleij, Alexandre Courbot, Samuel Ortiz, Lee Jones,
	Arnd Bergmann, linux-gpio, linux-arch, linux-kernel, Jacob Pan,
	Lejun Zhu, Radivoje Jovanovic, Daniel Glöckner,
	ACPI Devel Maling List, Rafael J. Wysocki

On 09/25/2014 07:15 PM, Mika Westerberg wrote:
> On Thu, Sep 25, 2014 at 10:57:26AM +0800, Aaron Lu wrote:
>> The virtual GPIO introduced in ACPI table of Baytrail-T based system is
>> used to solve a problem under Windows. We do not have such problems
>> under Linux so we do not actually need them. But we have to tell GPIO
>> library that the Crystal Cove GPIO chip has this many GPIO pins or the
>> common GPIO handler will refuse any access to those high number GPIO
>> pins, which will resulted in a failure evaluation of every ACPI control
>> method that is used to turn on/off power resource and/or report sensor
>> temperatures.
>>
>> Signed-off-by: Aaron Lu <aaron.lu@intel.com>
> 
> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>

Thanks for the review!

Regards,
Aaron

> 
> A minor nit, see below:
> 
>> ---
>> v2: remove the hunk to increase NR_GPIO to 512.
>>
>>  drivers/gpio/gpio-crystalcove.c | 19 ++++++++++++++++---
>>  1 file changed, 16 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpio/gpio-crystalcove.c b/drivers/gpio/gpio-crystalcove.c
>> index e3712f0e51ab..186b76ef71a1 100644
>> --- a/drivers/gpio/gpio-crystalcove.c
>> +++ b/drivers/gpio/gpio-crystalcove.c
>> @@ -24,6 +24,7 @@
>>  #include <linux/mfd/intel_soc_pmic.h>
>>  
>>  #define CRYSTALCOVE_GPIO_NUM	16
>> +#define CRYSTALCOVE_VGPIO_NUM	0x5e
> 
> I would rather see this spelled in decimal base.
> 


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

* Re: [PATCH v2 1/2] gpio / CrystalCove: support virtual GPIO
  2014-09-25 13:16       ` Linus Walleij
@ 2014-09-26  5:22         ` Aaron Lu
  0 siblings, 0 replies; 21+ messages in thread
From: Aaron Lu @ 2014-09-26  5:22 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Alexandre Courbot, Samuel Ortiz, Lee Jones, Arnd Bergmann,
	linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, ACPI Devel Maling List,
	Rafael J. Wysocki

On 09/25/2014 09:16 PM, Linus Walleij wrote:
> On Thu, Sep 25, 2014 at 4:57 AM, Aaron Lu <aaron.lu@intel.com> wrote:
> 
>> The virtual GPIO introduced in ACPI table of Baytrail-T based system is
>> used to solve a problem under Windows. We do not have such problems
>> under Linux so we do not actually need them. But we have to tell GPIO
>> library that the Crystal Cove GPIO chip has this many GPIO pins or the
>> common GPIO handler will refuse any access to those high number GPIO
>> pins, which will resulted in a failure evaluation of every ACPI control
>> method that is used to turn on/off power resource and/or report sensor
>> temperatures.
>>
>> Signed-off-by: Aaron Lu <aaron.lu@intel.com>
>> ---
>> v2: remove the hunk to increase NR_GPIO to 512.
> 
> Patch applied with Mika's ACK, also renumbered 0x5e to 94.

Thanks for taking care of this.

Regards,
Aaron

> 
> Yours,
> Linus Walleij
> 


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

* Re: [PATCH 2/2] PMIC / opregion: support PMIC customized operation region for CrystalCove
  2014-09-09  2:32 ` [PATCH 2/2] PMIC / opregion: support PMIC customized operation region for CrystalCove Aaron Lu
@ 2014-10-08  8:05   ` Lee Jones
  2014-10-08  9:16     ` Linus Walleij
  2014-10-09  9:21     ` Aaron Lu
  0 siblings, 2 replies; 21+ messages in thread
From: Lee Jones @ 2014-10-08  8:05 UTC (permalink / raw)
  To: Aaron Lu
  Cc: Linus Walleij, Alexandre Courbot, Samuel Ortiz, Arnd Bergmann,
	linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, linux-acpi,
	Rafael J. Wysocki, Mark Brown

To all those CC'ed,

> The Baytrail-T platform firmware has defined two customized operation
> regions for PMIC chip Crystal Cove - one is for power resource handling
> and one is for thermal: sensor temperature reporting, trip point setting,
> etc. This patch adds support for them on top of the existing Crystal Cove
> PMIC driver.
> 
> The reason to split code into a separate file intel_soc_pmic_opregion.c
> is that there are more PMIC driver with ACPI operation region support
> coming and we can re-use those code. The intel_soc_pmic_opregion_data
> structure is created also for this purpose: when we need to support a
> new PMIC's operation region, we just need to fill those callbacks and
> the two register mapping tables.
> 
> Signed-off-by: Aaron Lu <aaron.lu@intel.com>
> ---
>  drivers/mfd/Kconfig                       |  11 +
>  drivers/mfd/Makefile                      |   1 +
>  drivers/mfd/intel_soc_pmic_crc.c          |   3 +
>  drivers/mfd/intel_soc_pmic_crc_opregion.c | 229 +++++++++++++++++++
>  drivers/mfd/intel_soc_pmic_opregion.c     | 350 ++++++++++++++++++++++++++++++
>  drivers/mfd/intel_soc_pmic_opregion.h     |  35 +++

With the influx of new same-chip devices, I think the MFD subsystem is
fast becoming overloaded.  I think all of the PMIC handling should in
fact either live in Regulators or have its own subsystem.

Let's open this up to the floor by Cc'ing some probable interested
parties.

[Leaving the driver code in, but my comments stop here]

>  6 files changed, 629 insertions(+)
>  create mode 100644 drivers/mfd/intel_soc_pmic_crc_opregion.c
>  create mode 100644 drivers/mfd/intel_soc_pmic_opregion.c
>  create mode 100644 drivers/mfd/intel_soc_pmic_opregion.h
> 
> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> index de5abf244746..77a7229058a6 100644
> --- a/drivers/mfd/Kconfig
> +++ b/drivers/mfd/Kconfig
> @@ -266,6 +266,17 @@ config INTEL_SOC_PMIC
>  	  thermal, charger and related power management functions
>  	  on these systems.
>  
> +config CRC_PMIC_OPREGION
> +	tristate "ACPI operation region support for CrystalCove PMIC"
> +	depends on ACPI
> +	depends on INTEL_SOC_PMIC
> +	help
> +	  Select this option to enable support for ACPI operation
> +	  region of the PMIC chip. The operation region can be used
> +	  to control power rails and sensor reading/writing on the
> +	  PMIC chip. This config addes ACPI operation region support
> +	  for CrystalCove PMIC.
> +
>  config MFD_INTEL_MSIC
>  	bool "Intel MSIC"
>  	depends on INTEL_SCU_IPC
> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> index f00148782d9b..e02f0573e293 100644
> --- a/drivers/mfd/Makefile
> +++ b/drivers/mfd/Makefile
> @@ -172,3 +172,4 @@ obj-$(CONFIG_MFD_IPAQ_MICRO)	+= ipaq-micro.o
>  
>  intel-soc-pmic-objs		:= intel_soc_pmic_core.o intel_soc_pmic_crc.o
>  obj-$(CONFIG_INTEL_SOC_PMIC)	+= intel-soc-pmic.o
> +obj-$(CONFIG_CRC_PMIC_OPREGION) += intel_soc_pmic_crc_opregion.o intel_soc_pmic_opregion.o
> diff --git a/drivers/mfd/intel_soc_pmic_crc.c b/drivers/mfd/intel_soc_pmic_crc.c
> index 7107cab832e6..48845d636bba 100644
> --- a/drivers/mfd/intel_soc_pmic_crc.c
> +++ b/drivers/mfd/intel_soc_pmic_crc.c
> @@ -106,6 +106,9 @@ static struct mfd_cell crystal_cove_dev[] = {
>  		.num_resources = ARRAY_SIZE(gpio_resources),
>  		.resources = gpio_resources,
>  	},
> +	{
> +		.name = "crystal_cove_region",
> +	},
>  };
>  
>  static struct regmap_config crystal_cove_regmap_config = {
> diff --git a/drivers/mfd/intel_soc_pmic_crc_opregion.c b/drivers/mfd/intel_soc_pmic_crc_opregion.c
> new file mode 100644
> index 000000000000..27b67dc3fa8d
> --- /dev/null
> +++ b/drivers/mfd/intel_soc_pmic_crc_opregion.c
> @@ -0,0 +1,229 @@
> +/*
> + * intel_soc_pmic_crc_opregion.c - Intel SoC PMIC operation region Driver
> + *
> + * Copyright (C) 2014 Intel Corporation. All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License version
> + * 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that 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/module.h>
> +#include <linux/acpi.h>
> +#include <linux/mfd/intel_soc_pmic.h>
> +#include <linux/regmap.h>
> +#include <linux/platform_device.h>
> +#include "intel_soc_pmic_opregion.h"
> +
> +#define PWR_SOURCE_SELECT	BIT(1)
> +
> +#define PMIC_A0LOCK_REG		0xc5
> +
> +static struct pmic_pwr_table pwr_table[] = {
> +	{
> +		.address = 0x24,
> +		.pwr_reg = {
> +			.reg = 0x66,
> +			.bit = 0x00,
> +		},
> +	},	/* X285 -> V2P85SX, camara */
> +	{
> +		.address = 0x48,
> +		.pwr_reg = {
> +			.reg = 0x5d,
> +			.bit = 0x00,
> +		},
> +	},	/* V18X -> V1P8SX, eMMC/camara/audio */
> +};
> +
> +static struct pmic_dptf_table dptf_table[] = {
> +	{
> +		.address = 0x00,
> +		.reg = 0x75
> +	},	/* TMP0 -> SYS0_THRM_RSLT_L */
> +	{
> +		.address = 0x04,
> +		.reg = 0x95
> +	},	/* AX00 -> SYS0_THRMALRT0_L */
> +	{
> +		.address = 0x08,
> +		.reg = 0x97
> +	},	/* AX01 -> SYS0_THRMALRT1_L */
> +	{
> +		.address = 0x0c,
> +		.reg = 0x77
> +	},	/* TMP1 -> SYS1_THRM_RSLT_L */
> +	{
> +		.address = 0x10,
> +		.reg = 0x9a
> +	},	/* AX10 -> SYS1_THRMALRT0_L */
> +	{
> +		.address = 0x14,
> +		.reg = 0x9c
> +	},	/* AX11 -> SYS1_THRMALRT1_L */
> +	{
> +		.address = 0x18,
> +		.reg = 0x79
> +	},	/* TMP2 -> SYS2_THRM_RSLT_L */
> +	{
> +		.address = 0x1c,
> +		.reg = 0x9f
> +	},	/* AX20 -> SYS2_THRMALRT0_L */
> +	{
> +		.address = 0x20,
> +		.reg = 0xa1
> +	},	/* AX21 -> SYS2_THRMALRT1_L */
> +	{
> +		.address = 0x48,
> +		.reg = 0x94
> +	},	/* PEN0 -> SYS0_THRMALRT0_H */
> +	{
> +		.address = 0x4c,
> +		.reg = 0x99
> +	},	/* PEN1 -> SYS1_THRMALRT1_H */
> +	{
> +		.address = 0x50,
> +		.reg = 0x9e
> +	},	/* PEN2 -> SYS2_THRMALRT2_H */
> +};
> +
> +static int intel_crc_pmic_get_power(struct regmap *regmap,
> +				    struct pmic_pwr_reg *preg, u64 *value)
> +{
> +	int data;
> +
> +	if (regmap_read(regmap, preg->reg, &data))
> +		return -EIO;
> +
> +	*value = (data & PWR_SOURCE_SELECT) && (data & BIT(preg->bit)) ? 1 : 0;
> +	return 0;
> +}
> +
> +static int intel_crc_pmic_update_power(struct regmap *regmap,
> +				       struct pmic_pwr_reg *preg, bool on)
> +{
> +	int data;
> +
> +	if (regmap_read(regmap, preg->reg, &data))
> +		return -EIO;
> +
> +	if (on) {
> +		data |= PWR_SOURCE_SELECT | BIT(preg->bit);
> +	} else {
> +		data &= ~BIT(preg->bit);
> +		data |= PWR_SOURCE_SELECT;
> +	}
> +
> +	if (regmap_write(regmap, preg->reg, data))
> +		return -EIO;
> +	return 0;
> +}
> +
> +/* Raw temperature value is 10bits: 8bits in reg and 2bits in reg-1 bit0,1 */
> +static int intel_crc_pmic_get_raw_temp(struct regmap *regmap, int reg)
> +{
> +	int temp_l, temp_h;
> +
> +	if (regmap_read(regmap, reg, &temp_l) ||
> +	    regmap_read(regmap, reg - 1, &temp_h))
> +		return -EIO;
> +
> +	return (temp_l | ((temp_h & 0x3) << 8));
> +}
> +
> +static int
> +intel_crc_pmic_update_aux(struct regmap *regmap, int reg, int raw)
> +{
> +	if (regmap_write(regmap, reg, raw) ||
> +	    regmap_update_bits(regmap, reg - 1, 0x3, raw >> 8))
> +		return -EIO;
> +
> +	return 0;
> +}
> +
> +static int
> +intel_crc_pmic_get_policy(struct regmap *regmap, int reg, u64 *value)
> +{
> +	int pen;
> +
> +	if (regmap_read(regmap, reg, &pen))
> +		return -EIO;
> +	*value = pen >> 7;
> +	return 0;
> +}
> +
> +static int intel_crc_pmic_update_policy(struct regmap *regmap,
> +					int reg, int enable)
> +{
> +	int alert0;
> +
> +	/* Update to policy enable bit requires unlocking a0lock */
> +	if (regmap_read(regmap, PMIC_A0LOCK_REG, &alert0))
> +		return -EIO;
> +	if (regmap_update_bits(regmap, PMIC_A0LOCK_REG, 0x01, 0))
> +		return -EIO;
> +
> +	if (regmap_update_bits(regmap, reg, 0x80, enable << 7))
> +		return -EIO;
> +
> +	/* restore alert0 */
> +	if (regmap_write(regmap, PMIC_A0LOCK_REG, alert0))
> +		return -EIO;
> +
> +	return 0;
> +}
> +
> +static struct intel_soc_pmic_opregion_data intel_crc_pmic_opregion_data = {
> +	.get_power	= intel_crc_pmic_get_power,
> +	.update_power	= intel_crc_pmic_update_power,
> +	.get_raw_temp	= intel_crc_pmic_get_raw_temp,
> +	.update_aux	= intel_crc_pmic_update_aux,
> +	.get_policy	= intel_crc_pmic_get_policy,
> +	.update_policy	= intel_crc_pmic_update_policy,
> +	.pwr_table	= pwr_table,
> +	.pwr_table_count= ARRAY_SIZE(pwr_table),
> +	.dptf_table	= dptf_table,
> +	.dptf_table_count = ARRAY_SIZE(dptf_table),
> +};
> +
> +static int intel_crc_pmic_opregion_probe(struct platform_device *pdev)
> +{
> +	struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
> +	return intel_soc_pmic_install_opregion_handler(&pdev->dev,
> +			ACPI_HANDLE(pdev->dev.parent), pmic->regmap,
> +			&intel_crc_pmic_opregion_data);
> +}
> +
> +static int intel_crc_pmic_opregion_remove(struct platform_device *pdev)
> +{
> +	intel_soc_pmic_remove_opregion_handler(ACPI_HANDLE(pdev->dev.parent));
> +	return 0;
> +}
> +
> +#define DRV_NAME "crystal_cove_region"
> +
> +static struct platform_device_id crystal_cove_opregion_id_table[] = {
> +	{ .name = DRV_NAME },
> +	{},
> +};
> +
> +static struct platform_driver intel_crc_pmic_opregion_driver = {
> +	.probe = intel_crc_pmic_opregion_probe,
> +	.remove = intel_crc_pmic_opregion_remove,
> +	.id_table = crystal_cove_opregion_id_table,
> +	.driver = {
> +		.name = DRV_NAME,
> +	},
> +};
> +
> +MODULE_DEVICE_TABLE(platform, crystal_cove_opregion_id_table);
> +
> +module_platform_driver(intel_crc_pmic_opregion_driver);
> +
> +MODULE_DESCRIPTION("CrystalCove ACPI opregion driver");
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/mfd/intel_soc_pmic_opregion.c b/drivers/mfd/intel_soc_pmic_opregion.c
> new file mode 100644
> index 000000000000..62824a35ce97
> --- /dev/null
> +++ b/drivers/mfd/intel_soc_pmic_opregion.c
> @@ -0,0 +1,350 @@
> +/*
> + * intel_soc_pmic_opregion.c - Intel SoC PMIC operation region Driver
> + *
> + * Copyright (C) 2014 Intel Corporation. All rights reserved.
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License version
> + * 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that 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/module.h>
> +#include <linux/acpi.h>
> +#include <linux/regmap.h>
> +#include "intel_soc_pmic_opregion.h"
> +
> +#define PMIC_PMOP_OPREGION_ID	0x8d
> +#define PMIC_DPTF_OPREGION_ID	0x8c
> +
> +struct acpi_lpat {
> +	int temp;
> +	int raw;
> +};
> +
> +struct intel_soc_pmic_opregion {
> +	struct mutex lock;
> +	struct acpi_lpat *lpat;
> +	int lpat_count;
> +	struct regmap *regmap;
> +	struct intel_soc_pmic_opregion_data *data;
> +};
> +
> +static struct pmic_pwr_reg *
> +pmic_get_pwr_reg(int address, struct pmic_pwr_table *table, int count)
> +{
> +	int i;
> +
> +	for (i = 0; i < count; i++) {
> +		if (table[i].address == address)
> +			return &table[i].pwr_reg;
> +	}
> +	return NULL;
> +}
> +
> +static int
> +pmic_get_dptf_reg(int address, struct pmic_dptf_table *table, int count)
> +{
> +	int i;
> +
> +	for (i = 0; i < count; i++) {
> +		if (table[i].address == address)
> +			return table[i].reg;
> +	}
> +	return -ENOENT;
> +}
> +
> +/* Return temperature from raw value through LPAT table */
> +static int raw_to_temp(struct acpi_lpat *lpat, int count, int raw)
> +{
> +	int i, delta_temp, delta_raw, temp;
> +
> +	for (i = 0; i < count - 1; i++) {
> +		if ((raw >= lpat[i].raw && raw <= lpat[i+1].raw) ||
> +		    (raw <= lpat[i].raw && raw >= lpat[i+1].raw))
> +			break;
> +	}
> +
> +	if (i == count - 1)
> +		return -ENOENT;
> +
> +	delta_temp = lpat[i+1].temp - lpat[i].temp;
> +	delta_raw = lpat[i+1].raw - lpat[i].raw;
> +	temp = lpat[i].temp + (raw - lpat[i].raw) * delta_temp / delta_raw;
> +
> +	return temp;
> +}
> +
> +/* Return raw value from temperature through LPAT table */
> +static int temp_to_raw(struct acpi_lpat *lpat, int count, int temp)
> +{
> +	int i, delta_temp, delta_raw, raw;
> +
> +	for (i = 0; i < count - 1; i++) {
> +		if (temp >= lpat[i].temp && temp <= lpat[i+1].temp)
> +			break;
> +	}
> +
> +	if (i == count - 1)
> +		return -ENOENT;
> +
> +	delta_temp = lpat[i+1].temp - lpat[i].temp;
> +	delta_raw = lpat[i+1].raw - lpat[i].raw;
> +	raw = lpat[i].raw + (temp - lpat[i].temp) * delta_raw / delta_temp;
> +
> +	return raw;
> +}
> +
> +static void
> +pmic_dptf_lpat(struct intel_soc_pmic_opregion *opregion, acpi_handle handle,
> +	       struct device *dev)
> +{
> +	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
> +	union acpi_object *obj_p, *obj_e;
> +	int *lpat, i;
> +	acpi_status status;
> +
> +	status = acpi_evaluate_object(handle, "LPAT", NULL, &buffer);
> +	if (ACPI_FAILURE(status))
> +		return;
> +
> +	obj_p = (union acpi_object *)buffer.pointer;
> +	if (!obj_p || (obj_p->type != ACPI_TYPE_PACKAGE) ||
> +	    (obj_p->package.count % 2) || (obj_p->package.count < 4))
> +		goto out;
> +
> +	lpat = devm_kmalloc(dev, sizeof(*lpat) * obj_p->package.count,
> +			    GFP_KERNEL);
> +	if (!lpat)
> +		goto out;
> +
> +	for (i = 0; i < obj_p->package.count; i++) {
> +		obj_e = &obj_p->package.elements[i];
> +		if (obj_e->type != ACPI_TYPE_INTEGER)
> +			goto out;
> +		lpat[i] = obj_e->integer.value;
> +	}
> +
> +	opregion->lpat = (struct acpi_lpat *)lpat;
> +	opregion->lpat_count = obj_p->package.count / 2;
> +
> +out:
> +	kfree(buffer.pointer);
> +}
> +
> +static acpi_status
> +intel_soc_pmic_pmop_handler(u32 function, acpi_physical_address address,
> +			    u32 bits, u64 *value64,
> +			    void *handler_context, void *region_context)
> +{
> +	struct intel_soc_pmic_opregion *opregion = region_context;
> +	struct regmap *regmap = opregion->regmap;
> +	struct intel_soc_pmic_opregion_data *d = opregion->data;
> +	struct pmic_pwr_reg *preg;
> +	int result;
> +
> +	if (bits != 32 || !value64)
> +		return AE_BAD_PARAMETER;
> +
> +	if (function == ACPI_WRITE && !(*value64 == 0 || *value64 == 1))
> +		return AE_BAD_PARAMETER;
> +
> +	preg = pmic_get_pwr_reg(address, d->pwr_table, d->pwr_table_count);
> +	if (!preg)
> +		return AE_BAD_PARAMETER;
> +
> +	mutex_lock(&opregion->lock);
> +
> +	if (function == ACPI_READ)
> +		result = d->get_power(regmap, preg, value64);
> +	else
> +		result = d->update_power(regmap, preg, *value64 == 1);
> +
> +	mutex_unlock(&opregion->lock);
> +
> +	return result ? AE_ERROR : AE_OK;
> +}
> +
> +static acpi_status pmic_read_temp(struct intel_soc_pmic_opregion *opregion,
> +				  int reg, u64 *value)
> +{
> +	int raw_temp, temp;
> +
> +	if (!opregion->data->get_raw_temp)
> +		return AE_BAD_PARAMETER;
> +
> +	raw_temp = opregion->data->get_raw_temp(opregion->regmap, reg);
> +	if (raw_temp < 0)
> +		return AE_ERROR;
> +
> +	if (!opregion->lpat) {
> +		*value = raw_temp;
> +		return AE_OK;
> +	}
> +
> +	temp = raw_to_temp(opregion->lpat, opregion->lpat_count, raw_temp);
> +	if (temp < 0)
> +		return AE_ERROR;
> +
> +	*value = temp;
> +	return AE_OK;
> +}
> +
> +static acpi_status pmic_dptf_temp(struct intel_soc_pmic_opregion *opregion,
> +				  int reg, u32 function, u64 *value)
> +{
> +	if (function != ACPI_READ)
> +		return AE_BAD_PARAMETER;
> +
> +	return pmic_read_temp(opregion, reg, value);
> +}
> +
> +static acpi_status pmic_dptf_aux(struct intel_soc_pmic_opregion *opregion,
> +				 int reg, u32 function, u64 *value)
> +{
> +	int raw_temp;
> +
> +	if (function == ACPI_READ)
> +		return pmic_read_temp(opregion, reg, value);
> +
> +	if (!opregion->data->update_aux)
> +		return AE_BAD_PARAMETER;
> +
> +	if (opregion->lpat) {
> +		raw_temp = temp_to_raw(opregion->lpat, opregion->lpat_count,
> +					 *value);
> +		if (raw_temp < 0)
> +			return AE_ERROR;
> +	} else {
> +		raw_temp = *value;
> +	}
> +
> +	return opregion->data->update_aux(opregion->regmap, reg, raw_temp) ?
> +		AE_ERROR : AE_OK;
> +}
> +
> +static acpi_status pmic_dptf_pen(struct intel_soc_pmic_opregion *opregion,
> +				 int reg, u32 function, u64 *value)
> +{
> +	struct intel_soc_pmic_opregion_data *d = opregion->data;
> +	struct regmap *regmap = opregion->regmap;
> +
> +	if (!d->get_policy || !d->update_policy)
> +		return AE_BAD_PARAMETER;
> +
> +	if (function == ACPI_READ)
> +		return d->get_policy(regmap, reg, value) ? AE_ERROR : AE_OK;
> +
> +	if (*value != 0 || *value != 1)
> +		return AE_BAD_PARAMETER;
> +
> +	return d->update_policy(regmap, reg, *value) ? AE_ERROR : AE_OK;
> +}
> +
> +static bool pmic_dptf_is_temp(int address)
> +{
> +	return (address <= 0x3c) && !(address % 12);
> +}
> +
> +static bool pmic_dptf_is_aux(int address)
> +{
> +	return (address >= 4 && address <= 0x40 && !((address - 4) % 12)) ||
> +	       (address >= 8 && address <= 0x44 && !((address - 8) % 12));
> +}
> +
> +static bool pmic_dptf_is_pen(int address)
> +{
> +	return address >= 0x48 && address <= 0x5c;
> +}
> +
> +static acpi_status
> +intel_soc_pmic_dptf_handler(u32 function, acpi_physical_address address,
> +			    u32 bits, u64 *value64,
> +			    void *handler_context, void *region_context)
> +{
> +	struct intel_soc_pmic_opregion *opregion = region_context;
> +	int reg;
> +	int result;
> +
> +	if (bits != 32 || !value64)
> +		return AE_BAD_PARAMETER;
> +
> +	reg = pmic_get_dptf_reg(address, opregion->data->dptf_table,
> +				opregion->data->dptf_table_count);
> +	if (!reg)
> +		return AE_BAD_PARAMETER;
> +
> +	mutex_lock(&opregion->lock);
> +
> +	result = AE_BAD_PARAMETER;
> +	if (pmic_dptf_is_temp(address))
> +		result = pmic_dptf_temp(opregion, reg, function, value64);
> +	else if (pmic_dptf_is_aux(address))
> +		result = pmic_dptf_aux(opregion, reg, function, value64);
> +	else if (pmic_dptf_is_pen(address))
> +		result = pmic_dptf_pen(opregion, reg, function, value64);
> +
> +	mutex_unlock(&opregion->lock);
> +
> +	return result;
> +}
> +
> +int
> +intel_soc_pmic_install_opregion_handler(struct device *dev,
> +					acpi_handle handle,
> +					struct regmap *regmap,
> +					struct intel_soc_pmic_opregion_data *d)
> +{
> +	acpi_status status;
> +	struct intel_soc_pmic_opregion *opregion;
> +
> +	if (!dev || !regmap || !d)
> +		return -EINVAL;
> +
> +	if (!handle)
> +		return -ENODEV;
> +
> +	opregion = devm_kzalloc(dev, sizeof(*opregion), GFP_KERNEL);
> +	if (!opregion)
> +		return -ENOMEM;
> +
> +	mutex_init(&opregion->lock);
> +	opregion->regmap = regmap;
> +	pmic_dptf_lpat(opregion, handle, dev);
> +
> +	status = acpi_install_address_space_handler(handle,
> +						    PMIC_PMOP_OPREGION_ID,
> +						    intel_soc_pmic_pmop_handler,
> +						    NULL, opregion);
> +	if (ACPI_FAILURE(status))
> +		return -ENODEV;
> +
> +	status = acpi_install_address_space_handler(handle,
> +						    PMIC_DPTF_OPREGION_ID,
> +						    intel_soc_pmic_dptf_handler,
> +						    NULL, opregion);
> +	if (ACPI_FAILURE(status)) {
> +		acpi_remove_address_space_handler(handle, PMIC_PMOP_OPREGION_ID,
> +						  intel_soc_pmic_pmop_handler);
> +		return -ENODEV;
> +	}
> +
> +	opregion->data = d;
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(intel_soc_pmic_install_opregion_handler);
> +
> +void intel_soc_pmic_remove_opregion_handler(acpi_handle handle)
> +{
> +	acpi_remove_address_space_handler(handle, PMIC_PMOP_OPREGION_ID,
> +					  intel_soc_pmic_pmop_handler);
> +	acpi_remove_address_space_handler(handle, PMIC_DPTF_OPREGION_ID,
> +					  intel_soc_pmic_dptf_handler);
> +}
> +EXPORT_SYMBOL_GPL(intel_soc_pmic_remove_opregion_handler);
> +
> +MODULE_LICENSE("GPL");
> diff --git a/drivers/mfd/intel_soc_pmic_opregion.h b/drivers/mfd/intel_soc_pmic_opregion.h
> new file mode 100644
> index 000000000000..752ec3d2bcbb
> --- /dev/null
> +++ b/drivers/mfd/intel_soc_pmic_opregion.h
> @@ -0,0 +1,35 @@
> +#ifndef __INTEL_SOC_PMIC_OPREGION_H
> +#define __INTEL_SOC_PMIC_OPREGION_H
> +
> +struct pmic_pwr_reg {
> +	int reg;	/* corresponding PMIC register */
> +	int bit;	/* control bit for power */
> +};
> +
> +struct pmic_pwr_table {
> +	int address;	/* operation region address */
> +	struct pmic_pwr_reg pwr_reg;
> +};
> +
> +struct pmic_dptf_table {
> +	int address;	/* operation region address */
> +	int reg;	/* corresponding thermal register */
> +};
> +
> +struct intel_soc_pmic_opregion_data {
> +	int (*get_power)(struct regmap *r, struct pmic_pwr_reg *preg, u64 *value);
> +	int (*update_power)(struct regmap *r, struct pmic_pwr_reg *preg, bool on);
> +	int (*get_raw_temp)(struct regmap *r, int reg);
> +	int (*update_aux)(struct regmap *r, int reg, int raw_temp);
> +	int (*get_policy)(struct regmap *r, int reg, u64 *value);
> +	int (*update_policy)(struct regmap *r, int reg, int enable);
> +	struct pmic_pwr_table *pwr_table;
> +	int pwr_table_count;
> +	struct pmic_dptf_table *dptf_table;
> +	int dptf_table_count;
> +};
> +
> +int intel_soc_pmic_install_opregion_handler(struct device *dev, acpi_handle handle, struct regmap *regmap, struct intel_soc_pmic_opregion_data *d);
> +void intel_soc_pmic_remove_opregion_handler(acpi_handle handle);
> +
> +#endif

-- 
Lee Jones
Linaro STMicroelectronics Landing Team Lead
Linaro.org │ Open source software for ARM SoCs
Follow Linaro: Facebook | Twitter | Blog

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

* Re: [PATCH 2/2] PMIC / opregion: support PMIC customized operation region for CrystalCove
  2014-10-08  8:05   ` Lee Jones
@ 2014-10-08  9:16     ` Linus Walleij
  2014-10-08 11:58       ` Jacob Pan
  2014-10-08 12:54       ` Mark Brown
  2014-10-09  9:21     ` Aaron Lu
  1 sibling, 2 replies; 21+ messages in thread
From: Linus Walleij @ 2014-10-08  9:16 UTC (permalink / raw)
  To: Lee Jones
  Cc: Aaron Lu, Alexandre Courbot, Samuel Ortiz, Arnd Bergmann,
	linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, ACPI Devel Maling List,
	Rafael J. Wysocki, Mark Brown

On Wed, Oct 8, 2014 at 10:05 AM, Lee Jones <lee.jones@linaro.org> wrote:

> With the influx of new same-chip devices, I think the MFD subsystem is
> fast becoming overloaded.  I think all of the PMIC handling should in
> fact either live in Regulators or have its own subsystem.

You have a valid point, and it's been raised before that MFD risk being
a dumping ground of the same kind that drivers/misc used to be (is?).

PMIC (Power Management Integrated Circuit) is often not even a
correct name for the thing if it contains things like audio amplifiers
USB PHY intrerfaces or LED boosters as some do.

MSIC (Mixed-Signal Integrated Circuit) is the correct name for
silicon that is created as a one-stop shop for anything combining
digital and analog constructions, often in a higher micron node
(not as densely integrated) as a digital IC (the latter referred to
as SoCs, "baseband", "CPU" and whatnot).

If they shall live in MFD the driver there should (IMHO) just be
an exchange station, multiplexing messages and spawning
MFD cells into platform devices for respective *real* subsystem,
various misc stuff should not be allowed to be shoehorned
into MFD just because there is no other place to put it.

This driver clearly does not qualify, look:

> +static int intel_crc_pmic_update_power(struct regmap *regmap,
> +                                    struct pmic_pwr_reg *preg, bool on)
> +{
> +     int data;
> +
> +     if (regmap_read(regmap, preg->reg, &data))
> +             return -EIO;
> +
> +     if (on) {
> +             data |= PWR_SOURCE_SELECT | BIT(preg->bit);
> +     } else {
> +             data &= ~BIT(preg->bit);
> +             data |= PWR_SOURCE_SELECT;
> +     }
> +
> +     if (regmap_write(regmap, preg->reg, data))
> +             return -EIO;
> +     return 0;
> +}

Selecting power source? Isn't that something and MFD cell
spawned driver in either drivers/regulator or drivers/power should
be doing?

I know I have sinned in this regard in the past. But let's move
forward with defining what this subsystem should *REALLY*
be.

Yours,
Linus Walleij

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

* Re: [PATCH 2/2] PMIC / opregion: support PMIC customized operation region for CrystalCove
  2014-10-08  9:16     ` Linus Walleij
@ 2014-10-08 11:58       ` Jacob Pan
  2014-10-08 12:54       ` Mark Brown
  1 sibling, 0 replies; 21+ messages in thread
From: Jacob Pan @ 2014-10-08 11:58 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Lee Jones, Aaron Lu, Alexandre Courbot, Samuel Ortiz,
	Arnd Bergmann, linux-gpio, linux-arch, linux-kernel, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, ACPI Devel Maling List,
	Rafael J. Wysocki, Mark Brown

On Wed, 8 Oct 2014 11:16:11 +0200
Linus Walleij <linus.walleij@linaro.org> wrote:

> On Wed, Oct 8, 2014 at 10:05 AM, Lee Jones <lee.jones@linaro.org>
> wrote:
> 
> > With the influx of new same-chip devices, I think the MFD subsystem
> > is fast becoming overloaded.  I think all of the PMIC handling
> > should in fact either live in Regulators or have its own subsystem.
> 
> You have a valid point, and it's been raised before that MFD risk
> being a dumping ground of the same kind that drivers/misc used to be
> (is?).
> 
> PMIC (Power Management Integrated Circuit) is often not even a
> correct name for the thing if it contains things like audio amplifiers
> USB PHY intrerfaces or LED boosters as some do.
> 
> MSIC (Mixed-Signal Integrated Circuit) is the correct name for
> silicon that is created as a one-stop shop for anything combining
> digital and analog constructions, often in a higher micron node
> (not as densely integrated) as a digital IC (the latter referred to
> as SoCs, "baseband", "CPU" and whatnot).
> 
> If they shall live in MFD the driver there should (IMHO) just be
> an exchange station, multiplexing messages and spawning
> MFD cells into platform devices for respective *real* subsystem,
> various misc stuff should not be allowed to be shoehorned
> into MFD just because there is no other place to put it.
> 
I agree since in most cases there are not much common code to
consolidate among cell drivers. MFD is convenient as an exchange
station as you pointed out but the same time, drivers can create their
own platform devices without MFD. Perhaps we can add a set of MFD
internal APIs for PMIC for the things are common, e.g.
- regmap
- irq chip

> This driver clearly does not qualify, look:
> 
ACPI is kind of special since it is already an abstraction of the HW
making it easy to consolidate code. Perhaps that is why Aaron provides
the kind of callbacks for each PMIC.
> > +static int intel_crc_pmic_update_power(struct regmap *regmap,
> > +                                    struct pmic_pwr_reg *preg,
> > bool on) +{
> > +     int data;
> > +
> > +     if (regmap_read(regmap, preg->reg, &data))
> > +             return -EIO;
> > +
> > +     if (on) {
> > +             data |= PWR_SOURCE_SELECT | BIT(preg->bit);
> > +     } else {
> > +             data &= ~BIT(preg->bit);
> > +             data |= PWR_SOURCE_SELECT;
> > +     }
> > +
> > +     if (regmap_write(regmap, preg->reg, data))
> > +             return -EIO;
> > +     return 0;
> > +}
> 
> Selecting power source? Isn't that something and MFD cell
> spawned driver in either drivers/regulator or drivers/power should
> be doing?
> 
The difference in this case is that opregion handler driver does not
need the interfaces provided by sys/class/power_supply, or regulator
etc. By moving them away from the opregion common code, you would need
to export the APIs. I think we can have opregion code under
drivers/acpi?
> I know I have sinned in this regard in the past. But let's move
> forward with defining what this subsystem should *REALLY*
> be.
> 

> Yours,
> Linus Walleij

[Jacob Pan]

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

* Re: [PATCH 2/2] PMIC / opregion: support PMIC customized operation region for CrystalCove
  2014-10-08  9:16     ` Linus Walleij
  2014-10-08 11:58       ` Jacob Pan
@ 2014-10-08 12:54       ` Mark Brown
  1 sibling, 0 replies; 21+ messages in thread
From: Mark Brown @ 2014-10-08 12:54 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Lee Jones, Aaron Lu, Alexandre Courbot, Samuel Ortiz,
	Arnd Bergmann, linux-gpio, linux-arch, linux-kernel, Jacob Pan,
	Lejun Zhu, Radivoje Jovanovic, Daniel Glöckner,
	ACPI Devel Maling List, Rafael J. Wysocki

[-- Attachment #1: Type: text/plain, Size: 1317 bytes --]

On Wed, Oct 08, 2014 at 11:16:11AM +0200, Linus Walleij wrote:
> On Wed, Oct 8, 2014 at 10:05 AM, Lee Jones <lee.jones@linaro.org> wrote:

Please don't send upstream mail to my work account (which I've never
used for upstream mail and isn't advertised in MAINTAINERS), it mostly
gets deleted unread.

> > With the influx of new same-chip devices, I think the MFD subsystem is
> > fast becoming overloaded.  I think all of the PMIC handling should in
> > fact either live in Regulators or have its own subsystem.

> You have a valid point, and it's been raised before that MFD risk being
> a dumping ground of the same kind that drivers/misc used to be (is?).

> If they shall live in MFD the driver there should (IMHO) just be
> an exchange station, multiplexing messages and spawning
> MFD cells into platform devices for respective *real* subsystem,
> various misc stuff should not be allowed to be shoehorned
> into MFD just because there is no other place to put it.

Right, there's a very clear role for MFD in multiplexing the various
functions of the device and dealing with any core behaviour it needs for
bootstrapping or things like chip level suspend and resume.  Dumping
that into some random subsystem doesn't seem to make any sense, but
doing things that fall outside that remit also don't seem clever.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

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

* Re: [PATCH 2/2] PMIC / opregion: support PMIC customized operation region for CrystalCove
  2014-10-08  8:05   ` Lee Jones
  2014-10-08  9:16     ` Linus Walleij
@ 2014-10-09  9:21     ` Aaron Lu
  2014-10-13  9:02       ` Aaron Lu
  1 sibling, 1 reply; 21+ messages in thread
From: Aaron Lu @ 2014-10-09  9:21 UTC (permalink / raw)
  To: Lee Jones
  Cc: Linus Walleij, Alexandre Courbot, Samuel Ortiz, Arnd Bergmann,
	linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner, linux-acpi,
	Rafael J. Wysocki, Mark Brown

On 10/08/2014 04:05 PM, Lee Jones wrote:
> To all those CC'ed,
> 
>> The Baytrail-T platform firmware has defined two customized operation
>> regions for PMIC chip Crystal Cove - one is for power resource handling
>> and one is for thermal: sensor temperature reporting, trip point setting,
>> etc. This patch adds support for them on top of the existing Crystal Cove
>> PMIC driver.
>>
>> The reason to split code into a separate file intel_soc_pmic_opregion.c
>> is that there are more PMIC driver with ACPI operation region support
>> coming and we can re-use those code. The intel_soc_pmic_opregion_data
>> structure is created also for this purpose: when we need to support a
>> new PMIC's operation region, we just need to fill those callbacks and
>> the two register mapping tables.
>>
>> Signed-off-by: Aaron Lu <aaron.lu@intel.com>
>> ---
>>  drivers/mfd/Kconfig                       |  11 +
>>  drivers/mfd/Makefile                      |   1 +
>>  drivers/mfd/intel_soc_pmic_crc.c          |   3 +
>>  drivers/mfd/intel_soc_pmic_crc_opregion.c | 229 +++++++++++++++++++
>>  drivers/mfd/intel_soc_pmic_opregion.c     | 350 ++++++++++++++++++++++++++++++
>>  drivers/mfd/intel_soc_pmic_opregion.h     |  35 +++
> 
> With the influx of new same-chip devices, I think the MFD subsystem is
> fast becoming overloaded.  I think all of the PMIC handling should in
> fact either live in Regulators or have its own subsystem.
> 
> Let's open this up to the floor by Cc'ing some probable interested
> parties.

The ACPI operation region handler provides implementation for the ASL
code written by firmware developer, and since the ACPI PMIC device node
has two customized operation regions: power rail handling and thermal
sensor manipulating, implementing the handler will inevitably touch
power rail registers and thermal registers of the PMIC chip. In this
regard, it doesn't fit what the MFD subsystem is meant to contain(
according to your comments, I didn't know this before, sorry about that).

It seems that we have two options:
1 Create two cell devices from the PMIC I2C driver, one for power and
  one for thermal; the driver for the power part goes to drivers/power
  or drivers/regulator and the driver for thermal one goes to
  drivers/thermal;
  The problem of this approach is that, the operation region handler
  driver doesn't really need to expose those power or thermal sysfs
  interfaces for user space to consume, perhaps it shouldn't, as its
  sole purpose is to satisfy the ASL code access, not more.
2 Move these operation region handler drivers to drivers/acpi
  We now have EC operation region handler driver there, but we also have
  I2C, GPIO, i915 operation region handlers in their own subsystems. Not
  sure if PMIC operation region handler qualifies there.

Suggestions are welcome.

Thanks,
Aaron

> 
> [Leaving the driver code in, but my comments stop here]
> 
>>  6 files changed, 629 insertions(+)
>>  create mode 100644 drivers/mfd/intel_soc_pmic_crc_opregion.c
>>  create mode 100644 drivers/mfd/intel_soc_pmic_opregion.c
>>  create mode 100644 drivers/mfd/intel_soc_pmic_opregion.h
>>
>> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
>> index de5abf244746..77a7229058a6 100644
>> --- a/drivers/mfd/Kconfig
>> +++ b/drivers/mfd/Kconfig
>> @@ -266,6 +266,17 @@ config INTEL_SOC_PMIC
>>  	  thermal, charger and related power management functions
>>  	  on these systems.
>>  
>> +config CRC_PMIC_OPREGION
>> +	tristate "ACPI operation region support for CrystalCove PMIC"
>> +	depends on ACPI
>> +	depends on INTEL_SOC_PMIC
>> +	help
>> +	  Select this option to enable support for ACPI operation
>> +	  region of the PMIC chip. The operation region can be used
>> +	  to control power rails and sensor reading/writing on the
>> +	  PMIC chip. This config addes ACPI operation region support
>> +	  for CrystalCove PMIC.
>> +
>>  config MFD_INTEL_MSIC
>>  	bool "Intel MSIC"
>>  	depends on INTEL_SCU_IPC
>> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
>> index f00148782d9b..e02f0573e293 100644
>> --- a/drivers/mfd/Makefile
>> +++ b/drivers/mfd/Makefile
>> @@ -172,3 +172,4 @@ obj-$(CONFIG_MFD_IPAQ_MICRO)	+= ipaq-micro.o
>>  
>>  intel-soc-pmic-objs		:= intel_soc_pmic_core.o intel_soc_pmic_crc.o
>>  obj-$(CONFIG_INTEL_SOC_PMIC)	+= intel-soc-pmic.o
>> +obj-$(CONFIG_CRC_PMIC_OPREGION) += intel_soc_pmic_crc_opregion.o intel_soc_pmic_opregion.o
>> diff --git a/drivers/mfd/intel_soc_pmic_crc.c b/drivers/mfd/intel_soc_pmic_crc.c
>> index 7107cab832e6..48845d636bba 100644
>> --- a/drivers/mfd/intel_soc_pmic_crc.c
>> +++ b/drivers/mfd/intel_soc_pmic_crc.c
>> @@ -106,6 +106,9 @@ static struct mfd_cell crystal_cove_dev[] = {
>>  		.num_resources = ARRAY_SIZE(gpio_resources),
>>  		.resources = gpio_resources,
>>  	},
>> +	{
>> +		.name = "crystal_cove_region",
>> +	},
>>  };
>>  
>>  static struct regmap_config crystal_cove_regmap_config = {
>> diff --git a/drivers/mfd/intel_soc_pmic_crc_opregion.c b/drivers/mfd/intel_soc_pmic_crc_opregion.c
>> new file mode 100644
>> index 000000000000..27b67dc3fa8d
>> --- /dev/null
>> +++ b/drivers/mfd/intel_soc_pmic_crc_opregion.c
>> @@ -0,0 +1,229 @@
>> +/*
>> + * intel_soc_pmic_crc_opregion.c - Intel SoC PMIC operation region Driver
>> + *
>> + * Copyright (C) 2014 Intel Corporation. All rights reserved.
>> + *
>> + * This program is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU General Public License version
>> + * 2 as published by the Free Software Foundation.
>> + *
>> + * This program is distributed in the hope that 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/module.h>
>> +#include <linux/acpi.h>
>> +#include <linux/mfd/intel_soc_pmic.h>
>> +#include <linux/regmap.h>
>> +#include <linux/platform_device.h>
>> +#include "intel_soc_pmic_opregion.h"
>> +
>> +#define PWR_SOURCE_SELECT	BIT(1)
>> +
>> +#define PMIC_A0LOCK_REG		0xc5
>> +
>> +static struct pmic_pwr_table pwr_table[] = {
>> +	{
>> +		.address = 0x24,
>> +		.pwr_reg = {
>> +			.reg = 0x66,
>> +			.bit = 0x00,
>> +		},
>> +	},	/* X285 -> V2P85SX, camara */
>> +	{
>> +		.address = 0x48,
>> +		.pwr_reg = {
>> +			.reg = 0x5d,
>> +			.bit = 0x00,
>> +		},
>> +	},	/* V18X -> V1P8SX, eMMC/camara/audio */
>> +};
>> +
>> +static struct pmic_dptf_table dptf_table[] = {
>> +	{
>> +		.address = 0x00,
>> +		.reg = 0x75
>> +	},	/* TMP0 -> SYS0_THRM_RSLT_L */
>> +	{
>> +		.address = 0x04,
>> +		.reg = 0x95
>> +	},	/* AX00 -> SYS0_THRMALRT0_L */
>> +	{
>> +		.address = 0x08,
>> +		.reg = 0x97
>> +	},	/* AX01 -> SYS0_THRMALRT1_L */
>> +	{
>> +		.address = 0x0c,
>> +		.reg = 0x77
>> +	},	/* TMP1 -> SYS1_THRM_RSLT_L */
>> +	{
>> +		.address = 0x10,
>> +		.reg = 0x9a
>> +	},	/* AX10 -> SYS1_THRMALRT0_L */
>> +	{
>> +		.address = 0x14,
>> +		.reg = 0x9c
>> +	},	/* AX11 -> SYS1_THRMALRT1_L */
>> +	{
>> +		.address = 0x18,
>> +		.reg = 0x79
>> +	},	/* TMP2 -> SYS2_THRM_RSLT_L */
>> +	{
>> +		.address = 0x1c,
>> +		.reg = 0x9f
>> +	},	/* AX20 -> SYS2_THRMALRT0_L */
>> +	{
>> +		.address = 0x20,
>> +		.reg = 0xa1
>> +	},	/* AX21 -> SYS2_THRMALRT1_L */
>> +	{
>> +		.address = 0x48,
>> +		.reg = 0x94
>> +	},	/* PEN0 -> SYS0_THRMALRT0_H */
>> +	{
>> +		.address = 0x4c,
>> +		.reg = 0x99
>> +	},	/* PEN1 -> SYS1_THRMALRT1_H */
>> +	{
>> +		.address = 0x50,
>> +		.reg = 0x9e
>> +	},	/* PEN2 -> SYS2_THRMALRT2_H */
>> +};
>> +
>> +static int intel_crc_pmic_get_power(struct regmap *regmap,
>> +				    struct pmic_pwr_reg *preg, u64 *value)
>> +{
>> +	int data;
>> +
>> +	if (regmap_read(regmap, preg->reg, &data))
>> +		return -EIO;
>> +
>> +	*value = (data & PWR_SOURCE_SELECT) && (data & BIT(preg->bit)) ? 1 : 0;
>> +	return 0;
>> +}
>> +
>> +static int intel_crc_pmic_update_power(struct regmap *regmap,
>> +				       struct pmic_pwr_reg *preg, bool on)
>> +{
>> +	int data;
>> +
>> +	if (regmap_read(regmap, preg->reg, &data))
>> +		return -EIO;
>> +
>> +	if (on) {
>> +		data |= PWR_SOURCE_SELECT | BIT(preg->bit);
>> +	} else {
>> +		data &= ~BIT(preg->bit);
>> +		data |= PWR_SOURCE_SELECT;
>> +	}
>> +
>> +	if (regmap_write(regmap, preg->reg, data))
>> +		return -EIO;
>> +	return 0;
>> +}
>> +
>> +/* Raw temperature value is 10bits: 8bits in reg and 2bits in reg-1 bit0,1 */
>> +static int intel_crc_pmic_get_raw_temp(struct regmap *regmap, int reg)
>> +{
>> +	int temp_l, temp_h;
>> +
>> +	if (regmap_read(regmap, reg, &temp_l) ||
>> +	    regmap_read(regmap, reg - 1, &temp_h))
>> +		return -EIO;
>> +
>> +	return (temp_l | ((temp_h & 0x3) << 8));
>> +}
>> +
>> +static int
>> +intel_crc_pmic_update_aux(struct regmap *regmap, int reg, int raw)
>> +{
>> +	if (regmap_write(regmap, reg, raw) ||
>> +	    regmap_update_bits(regmap, reg - 1, 0x3, raw >> 8))
>> +		return -EIO;
>> +
>> +	return 0;
>> +}
>> +
>> +static int
>> +intel_crc_pmic_get_policy(struct regmap *regmap, int reg, u64 *value)
>> +{
>> +	int pen;
>> +
>> +	if (regmap_read(regmap, reg, &pen))
>> +		return -EIO;
>> +	*value = pen >> 7;
>> +	return 0;
>> +}
>> +
>> +static int intel_crc_pmic_update_policy(struct regmap *regmap,
>> +					int reg, int enable)
>> +{
>> +	int alert0;
>> +
>> +	/* Update to policy enable bit requires unlocking a0lock */
>> +	if (regmap_read(regmap, PMIC_A0LOCK_REG, &alert0))
>> +		return -EIO;
>> +	if (regmap_update_bits(regmap, PMIC_A0LOCK_REG, 0x01, 0))
>> +		return -EIO;
>> +
>> +	if (regmap_update_bits(regmap, reg, 0x80, enable << 7))
>> +		return -EIO;
>> +
>> +	/* restore alert0 */
>> +	if (regmap_write(regmap, PMIC_A0LOCK_REG, alert0))
>> +		return -EIO;
>> +
>> +	return 0;
>> +}
>> +
>> +static struct intel_soc_pmic_opregion_data intel_crc_pmic_opregion_data = {
>> +	.get_power	= intel_crc_pmic_get_power,
>> +	.update_power	= intel_crc_pmic_update_power,
>> +	.get_raw_temp	= intel_crc_pmic_get_raw_temp,
>> +	.update_aux	= intel_crc_pmic_update_aux,
>> +	.get_policy	= intel_crc_pmic_get_policy,
>> +	.update_policy	= intel_crc_pmic_update_policy,
>> +	.pwr_table	= pwr_table,
>> +	.pwr_table_count= ARRAY_SIZE(pwr_table),
>> +	.dptf_table	= dptf_table,
>> +	.dptf_table_count = ARRAY_SIZE(dptf_table),
>> +};
>> +
>> +static int intel_crc_pmic_opregion_probe(struct platform_device *pdev)
>> +{
>> +	struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
>> +	return intel_soc_pmic_install_opregion_handler(&pdev->dev,
>> +			ACPI_HANDLE(pdev->dev.parent), pmic->regmap,
>> +			&intel_crc_pmic_opregion_data);
>> +}
>> +
>> +static int intel_crc_pmic_opregion_remove(struct platform_device *pdev)
>> +{
>> +	intel_soc_pmic_remove_opregion_handler(ACPI_HANDLE(pdev->dev.parent));
>> +	return 0;
>> +}
>> +
>> +#define DRV_NAME "crystal_cove_region"
>> +
>> +static struct platform_device_id crystal_cove_opregion_id_table[] = {
>> +	{ .name = DRV_NAME },
>> +	{},
>> +};
>> +
>> +static struct platform_driver intel_crc_pmic_opregion_driver = {
>> +	.probe = intel_crc_pmic_opregion_probe,
>> +	.remove = intel_crc_pmic_opregion_remove,
>> +	.id_table = crystal_cove_opregion_id_table,
>> +	.driver = {
>> +		.name = DRV_NAME,
>> +	},
>> +};
>> +
>> +MODULE_DEVICE_TABLE(platform, crystal_cove_opregion_id_table);
>> +
>> +module_platform_driver(intel_crc_pmic_opregion_driver);
>> +
>> +MODULE_DESCRIPTION("CrystalCove ACPI opregion driver");
>> +MODULE_LICENSE("GPL");
>> diff --git a/drivers/mfd/intel_soc_pmic_opregion.c b/drivers/mfd/intel_soc_pmic_opregion.c
>> new file mode 100644
>> index 000000000000..62824a35ce97
>> --- /dev/null
>> +++ b/drivers/mfd/intel_soc_pmic_opregion.c
>> @@ -0,0 +1,350 @@
>> +/*
>> + * intel_soc_pmic_opregion.c - Intel SoC PMIC operation region Driver
>> + *
>> + * Copyright (C) 2014 Intel Corporation. All rights reserved.
>> + *
>> + * This program is free software; you can redistribute it and/or
>> + * modify it under the terms of the GNU General Public License version
>> + * 2 as published by the Free Software Foundation.
>> + *
>> + * This program is distributed in the hope that 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/module.h>
>> +#include <linux/acpi.h>
>> +#include <linux/regmap.h>
>> +#include "intel_soc_pmic_opregion.h"
>> +
>> +#define PMIC_PMOP_OPREGION_ID	0x8d
>> +#define PMIC_DPTF_OPREGION_ID	0x8c
>> +
>> +struct acpi_lpat {
>> +	int temp;
>> +	int raw;
>> +};
>> +
>> +struct intel_soc_pmic_opregion {
>> +	struct mutex lock;
>> +	struct acpi_lpat *lpat;
>> +	int lpat_count;
>> +	struct regmap *regmap;
>> +	struct intel_soc_pmic_opregion_data *data;
>> +};
>> +
>> +static struct pmic_pwr_reg *
>> +pmic_get_pwr_reg(int address, struct pmic_pwr_table *table, int count)
>> +{
>> +	int i;
>> +
>> +	for (i = 0; i < count; i++) {
>> +		if (table[i].address == address)
>> +			return &table[i].pwr_reg;
>> +	}
>> +	return NULL;
>> +}
>> +
>> +static int
>> +pmic_get_dptf_reg(int address, struct pmic_dptf_table *table, int count)
>> +{
>> +	int i;
>> +
>> +	for (i = 0; i < count; i++) {
>> +		if (table[i].address == address)
>> +			return table[i].reg;
>> +	}
>> +	return -ENOENT;
>> +}
>> +
>> +/* Return temperature from raw value through LPAT table */
>> +static int raw_to_temp(struct acpi_lpat *lpat, int count, int raw)
>> +{
>> +	int i, delta_temp, delta_raw, temp;
>> +
>> +	for (i = 0; i < count - 1; i++) {
>> +		if ((raw >= lpat[i].raw && raw <= lpat[i+1].raw) ||
>> +		    (raw <= lpat[i].raw && raw >= lpat[i+1].raw))
>> +			break;
>> +	}
>> +
>> +	if (i == count - 1)
>> +		return -ENOENT;
>> +
>> +	delta_temp = lpat[i+1].temp - lpat[i].temp;
>> +	delta_raw = lpat[i+1].raw - lpat[i].raw;
>> +	temp = lpat[i].temp + (raw - lpat[i].raw) * delta_temp / delta_raw;
>> +
>> +	return temp;
>> +}
>> +
>> +/* Return raw value from temperature through LPAT table */
>> +static int temp_to_raw(struct acpi_lpat *lpat, int count, int temp)
>> +{
>> +	int i, delta_temp, delta_raw, raw;
>> +
>> +	for (i = 0; i < count - 1; i++) {
>> +		if (temp >= lpat[i].temp && temp <= lpat[i+1].temp)
>> +			break;
>> +	}
>> +
>> +	if (i == count - 1)
>> +		return -ENOENT;
>> +
>> +	delta_temp = lpat[i+1].temp - lpat[i].temp;
>> +	delta_raw = lpat[i+1].raw - lpat[i].raw;
>> +	raw = lpat[i].raw + (temp - lpat[i].temp) * delta_raw / delta_temp;
>> +
>> +	return raw;
>> +}
>> +
>> +static void
>> +pmic_dptf_lpat(struct intel_soc_pmic_opregion *opregion, acpi_handle handle,
>> +	       struct device *dev)
>> +{
>> +	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
>> +	union acpi_object *obj_p, *obj_e;
>> +	int *lpat, i;
>> +	acpi_status status;
>> +
>> +	status = acpi_evaluate_object(handle, "LPAT", NULL, &buffer);
>> +	if (ACPI_FAILURE(status))
>> +		return;
>> +
>> +	obj_p = (union acpi_object *)buffer.pointer;
>> +	if (!obj_p || (obj_p->type != ACPI_TYPE_PACKAGE) ||
>> +	    (obj_p->package.count % 2) || (obj_p->package.count < 4))
>> +		goto out;
>> +
>> +	lpat = devm_kmalloc(dev, sizeof(*lpat) * obj_p->package.count,
>> +			    GFP_KERNEL);
>> +	if (!lpat)
>> +		goto out;
>> +
>> +	for (i = 0; i < obj_p->package.count; i++) {
>> +		obj_e = &obj_p->package.elements[i];
>> +		if (obj_e->type != ACPI_TYPE_INTEGER)
>> +			goto out;
>> +		lpat[i] = obj_e->integer.value;
>> +	}
>> +
>> +	opregion->lpat = (struct acpi_lpat *)lpat;
>> +	opregion->lpat_count = obj_p->package.count / 2;
>> +
>> +out:
>> +	kfree(buffer.pointer);
>> +}
>> +
>> +static acpi_status
>> +intel_soc_pmic_pmop_handler(u32 function, acpi_physical_address address,
>> +			    u32 bits, u64 *value64,
>> +			    void *handler_context, void *region_context)
>> +{
>> +	struct intel_soc_pmic_opregion *opregion = region_context;
>> +	struct regmap *regmap = opregion->regmap;
>> +	struct intel_soc_pmic_opregion_data *d = opregion->data;
>> +	struct pmic_pwr_reg *preg;
>> +	int result;
>> +
>> +	if (bits != 32 || !value64)
>> +		return AE_BAD_PARAMETER;
>> +
>> +	if (function == ACPI_WRITE && !(*value64 == 0 || *value64 == 1))
>> +		return AE_BAD_PARAMETER;
>> +
>> +	preg = pmic_get_pwr_reg(address, d->pwr_table, d->pwr_table_count);
>> +	if (!preg)
>> +		return AE_BAD_PARAMETER;
>> +
>> +	mutex_lock(&opregion->lock);
>> +
>> +	if (function == ACPI_READ)
>> +		result = d->get_power(regmap, preg, value64);
>> +	else
>> +		result = d->update_power(regmap, preg, *value64 == 1);
>> +
>> +	mutex_unlock(&opregion->lock);
>> +
>> +	return result ? AE_ERROR : AE_OK;
>> +}
>> +
>> +static acpi_status pmic_read_temp(struct intel_soc_pmic_opregion *opregion,
>> +				  int reg, u64 *value)
>> +{
>> +	int raw_temp, temp;
>> +
>> +	if (!opregion->data->get_raw_temp)
>> +		return AE_BAD_PARAMETER;
>> +
>> +	raw_temp = opregion->data->get_raw_temp(opregion->regmap, reg);
>> +	if (raw_temp < 0)
>> +		return AE_ERROR;
>> +
>> +	if (!opregion->lpat) {
>> +		*value = raw_temp;
>> +		return AE_OK;
>> +	}
>> +
>> +	temp = raw_to_temp(opregion->lpat, opregion->lpat_count, raw_temp);
>> +	if (temp < 0)
>> +		return AE_ERROR;
>> +
>> +	*value = temp;
>> +	return AE_OK;
>> +}
>> +
>> +static acpi_status pmic_dptf_temp(struct intel_soc_pmic_opregion *opregion,
>> +				  int reg, u32 function, u64 *value)
>> +{
>> +	if (function != ACPI_READ)
>> +		return AE_BAD_PARAMETER;
>> +
>> +	return pmic_read_temp(opregion, reg, value);
>> +}
>> +
>> +static acpi_status pmic_dptf_aux(struct intel_soc_pmic_opregion *opregion,
>> +				 int reg, u32 function, u64 *value)
>> +{
>> +	int raw_temp;
>> +
>> +	if (function == ACPI_READ)
>> +		return pmic_read_temp(opregion, reg, value);
>> +
>> +	if (!opregion->data->update_aux)
>> +		return AE_BAD_PARAMETER;
>> +
>> +	if (opregion->lpat) {
>> +		raw_temp = temp_to_raw(opregion->lpat, opregion->lpat_count,
>> +					 *value);
>> +		if (raw_temp < 0)
>> +			return AE_ERROR;
>> +	} else {
>> +		raw_temp = *value;
>> +	}
>> +
>> +	return opregion->data->update_aux(opregion->regmap, reg, raw_temp) ?
>> +		AE_ERROR : AE_OK;
>> +}
>> +
>> +static acpi_status pmic_dptf_pen(struct intel_soc_pmic_opregion *opregion,
>> +				 int reg, u32 function, u64 *value)
>> +{
>> +	struct intel_soc_pmic_opregion_data *d = opregion->data;
>> +	struct regmap *regmap = opregion->regmap;
>> +
>> +	if (!d->get_policy || !d->update_policy)
>> +		return AE_BAD_PARAMETER;
>> +
>> +	if (function == ACPI_READ)
>> +		return d->get_policy(regmap, reg, value) ? AE_ERROR : AE_OK;
>> +
>> +	if (*value != 0 || *value != 1)
>> +		return AE_BAD_PARAMETER;
>> +
>> +	return d->update_policy(regmap, reg, *value) ? AE_ERROR : AE_OK;
>> +}
>> +
>> +static bool pmic_dptf_is_temp(int address)
>> +{
>> +	return (address <= 0x3c) && !(address % 12);
>> +}
>> +
>> +static bool pmic_dptf_is_aux(int address)
>> +{
>> +	return (address >= 4 && address <= 0x40 && !((address - 4) % 12)) ||
>> +	       (address >= 8 && address <= 0x44 && !((address - 8) % 12));
>> +}
>> +
>> +static bool pmic_dptf_is_pen(int address)
>> +{
>> +	return address >= 0x48 && address <= 0x5c;
>> +}
>> +
>> +static acpi_status
>> +intel_soc_pmic_dptf_handler(u32 function, acpi_physical_address address,
>> +			    u32 bits, u64 *value64,
>> +			    void *handler_context, void *region_context)
>> +{
>> +	struct intel_soc_pmic_opregion *opregion = region_context;
>> +	int reg;
>> +	int result;
>> +
>> +	if (bits != 32 || !value64)
>> +		return AE_BAD_PARAMETER;
>> +
>> +	reg = pmic_get_dptf_reg(address, opregion->data->dptf_table,
>> +				opregion->data->dptf_table_count);
>> +	if (!reg)
>> +		return AE_BAD_PARAMETER;
>> +
>> +	mutex_lock(&opregion->lock);
>> +
>> +	result = AE_BAD_PARAMETER;
>> +	if (pmic_dptf_is_temp(address))
>> +		result = pmic_dptf_temp(opregion, reg, function, value64);
>> +	else if (pmic_dptf_is_aux(address))
>> +		result = pmic_dptf_aux(opregion, reg, function, value64);
>> +	else if (pmic_dptf_is_pen(address))
>> +		result = pmic_dptf_pen(opregion, reg, function, value64);
>> +
>> +	mutex_unlock(&opregion->lock);
>> +
>> +	return result;
>> +}
>> +
>> +int
>> +intel_soc_pmic_install_opregion_handler(struct device *dev,
>> +					acpi_handle handle,
>> +					struct regmap *regmap,
>> +					struct intel_soc_pmic_opregion_data *d)
>> +{
>> +	acpi_status status;
>> +	struct intel_soc_pmic_opregion *opregion;
>> +
>> +	if (!dev || !regmap || !d)
>> +		return -EINVAL;
>> +
>> +	if (!handle)
>> +		return -ENODEV;
>> +
>> +	opregion = devm_kzalloc(dev, sizeof(*opregion), GFP_KERNEL);
>> +	if (!opregion)
>> +		return -ENOMEM;
>> +
>> +	mutex_init(&opregion->lock);
>> +	opregion->regmap = regmap;
>> +	pmic_dptf_lpat(opregion, handle, dev);
>> +
>> +	status = acpi_install_address_space_handler(handle,
>> +						    PMIC_PMOP_OPREGION_ID,
>> +						    intel_soc_pmic_pmop_handler,
>> +						    NULL, opregion);
>> +	if (ACPI_FAILURE(status))
>> +		return -ENODEV;
>> +
>> +	status = acpi_install_address_space_handler(handle,
>> +						    PMIC_DPTF_OPREGION_ID,
>> +						    intel_soc_pmic_dptf_handler,
>> +						    NULL, opregion);
>> +	if (ACPI_FAILURE(status)) {
>> +		acpi_remove_address_space_handler(handle, PMIC_PMOP_OPREGION_ID,
>> +						  intel_soc_pmic_pmop_handler);
>> +		return -ENODEV;
>> +	}
>> +
>> +	opregion->data = d;
>> +	return 0;
>> +}
>> +EXPORT_SYMBOL_GPL(intel_soc_pmic_install_opregion_handler);
>> +
>> +void intel_soc_pmic_remove_opregion_handler(acpi_handle handle)
>> +{
>> +	acpi_remove_address_space_handler(handle, PMIC_PMOP_OPREGION_ID,
>> +					  intel_soc_pmic_pmop_handler);
>> +	acpi_remove_address_space_handler(handle, PMIC_DPTF_OPREGION_ID,
>> +					  intel_soc_pmic_dptf_handler);
>> +}
>> +EXPORT_SYMBOL_GPL(intel_soc_pmic_remove_opregion_handler);
>> +
>> +MODULE_LICENSE("GPL");
>> diff --git a/drivers/mfd/intel_soc_pmic_opregion.h b/drivers/mfd/intel_soc_pmic_opregion.h
>> new file mode 100644
>> index 000000000000..752ec3d2bcbb
>> --- /dev/null
>> +++ b/drivers/mfd/intel_soc_pmic_opregion.h
>> @@ -0,0 +1,35 @@
>> +#ifndef __INTEL_SOC_PMIC_OPREGION_H
>> +#define __INTEL_SOC_PMIC_OPREGION_H
>> +
>> +struct pmic_pwr_reg {
>> +	int reg;	/* corresponding PMIC register */
>> +	int bit;	/* control bit for power */
>> +};
>> +
>> +struct pmic_pwr_table {
>> +	int address;	/* operation region address */
>> +	struct pmic_pwr_reg pwr_reg;
>> +};
>> +
>> +struct pmic_dptf_table {
>> +	int address;	/* operation region address */
>> +	int reg;	/* corresponding thermal register */
>> +};
>> +
>> +struct intel_soc_pmic_opregion_data {
>> +	int (*get_power)(struct regmap *r, struct pmic_pwr_reg *preg, u64 *value);
>> +	int (*update_power)(struct regmap *r, struct pmic_pwr_reg *preg, bool on);
>> +	int (*get_raw_temp)(struct regmap *r, int reg);
>> +	int (*update_aux)(struct regmap *r, int reg, int raw_temp);
>> +	int (*get_policy)(struct regmap *r, int reg, u64 *value);
>> +	int (*update_policy)(struct regmap *r, int reg, int enable);
>> +	struct pmic_pwr_table *pwr_table;
>> +	int pwr_table_count;
>> +	struct pmic_dptf_table *dptf_table;
>> +	int dptf_table_count;
>> +};
>> +
>> +int intel_soc_pmic_install_opregion_handler(struct device *dev, acpi_handle handle, struct regmap *regmap, struct intel_soc_pmic_opregion_data *d);
>> +void intel_soc_pmic_remove_opregion_handler(acpi_handle handle);
>> +
>> +#endif
> 


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

* Re: [PATCH 2/2] PMIC / opregion: support PMIC customized operation region for CrystalCove
  2014-10-09  9:21     ` Aaron Lu
@ 2014-10-13  9:02       ` Aaron Lu
  2014-10-13 14:51         ` Rafael J. Wysocki
  0 siblings, 1 reply; 21+ messages in thread
From: Aaron Lu @ 2014-10-13  9:02 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Linus Walleij, Lee Jones, Alexandre Courbot, Samuel Ortiz,
	Arnd Bergmann, linux-gpio, linux-arch, linux-kernel, Jacob Pan,
	Lejun Zhu, Radivoje Jovanovic, Daniel Glöckner, linux-acpi,
	Mark Brown

On Thu, Oct 09, 2014 at 05:21:28PM +0800, Aaron Lu wrote:
> On 10/08/2014 04:05 PM, Lee Jones wrote:
> > To all those CC'ed,
> > 
> >> The Baytrail-T platform firmware has defined two customized operation
> >> regions for PMIC chip Crystal Cove - one is for power resource handling
> >> and one is for thermal: sensor temperature reporting, trip point setting,
> >> etc. This patch adds support for them on top of the existing Crystal Cove
> >> PMIC driver.
> >>
> >> The reason to split code into a separate file intel_soc_pmic_opregion.c
> >> is that there are more PMIC driver with ACPI operation region support
> >> coming and we can re-use those code. The intel_soc_pmic_opregion_data
> >> structure is created also for this purpose: when we need to support a
> >> new PMIC's operation region, we just need to fill those callbacks and
> >> the two register mapping tables.
> >>
> >> Signed-off-by: Aaron Lu <aaron.lu@intel.com>
> >> ---
> >>  drivers/mfd/Kconfig                       |  11 +
> >>  drivers/mfd/Makefile                      |   1 +
> >>  drivers/mfd/intel_soc_pmic_crc.c          |   3 +
> >>  drivers/mfd/intel_soc_pmic_crc_opregion.c | 229 +++++++++++++++++++
> >>  drivers/mfd/intel_soc_pmic_opregion.c     | 350 ++++++++++++++++++++++++++++++
> >>  drivers/mfd/intel_soc_pmic_opregion.h     |  35 +++
> > 
> > With the influx of new same-chip devices, I think the MFD subsystem is
> > fast becoming overloaded.  I think all of the PMIC handling should in
> > fact either live in Regulators or have its own subsystem.
> > 
> > Let's open this up to the floor by Cc'ing some probable interested
> > parties.
> 
> The ACPI operation region handler provides implementation for the ASL
> code written by firmware developer, and since the ACPI PMIC device node
> has two customized operation regions: power rail handling and thermal
> sensor manipulating, implementing the handler will inevitably touch
> power rail registers and thermal registers of the PMIC chip. In this
> regard, it doesn't fit what the MFD subsystem is meant to contain(
> according to your comments, I didn't know this before, sorry about that).
> 
> It seems that we have two options:
> 1 Create two cell devices from the PMIC I2C driver, one for power and
>   one for thermal; the driver for the power part goes to drivers/power
>   or drivers/regulator and the driver for thermal one goes to
>   drivers/thermal;
>   The problem of this approach is that, the operation region handler
>   driver doesn't really need to expose those power or thermal sysfs
>   interfaces for user space to consume, perhaps it shouldn't, as its
>   sole purpose is to satisfy the ASL code access, not more.
> 2 Move these operation region handler drivers to drivers/acpi
>   We now have EC operation region handler driver there, but we also have
>   I2C, GPIO, i915 operation region handlers in their own subsystems. Not
>   sure if PMIC operation region handler qualifies there.

Rafael,

May I have your opinion on option 2? Do you think it is OK to place the
operation region code under drivers/acpi? Thanks.

Regards,
Aaron

> 
> Suggestions are welcome.
> 
> Thanks,
> Aaron
> 
> > 
> > [Leaving the driver code in, but my comments stop here]
> > 
> >>  6 files changed, 629 insertions(+)
> >>  create mode 100644 drivers/mfd/intel_soc_pmic_crc_opregion.c
> >>  create mode 100644 drivers/mfd/intel_soc_pmic_opregion.c
> >>  create mode 100644 drivers/mfd/intel_soc_pmic_opregion.h
> >>
> >> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
> >> index de5abf244746..77a7229058a6 100644
> >> --- a/drivers/mfd/Kconfig
> >> +++ b/drivers/mfd/Kconfig
> >> @@ -266,6 +266,17 @@ config INTEL_SOC_PMIC
> >>  	  thermal, charger and related power management functions
> >>  	  on these systems.
> >>  
> >> +config CRC_PMIC_OPREGION
> >> +	tristate "ACPI operation region support for CrystalCove PMIC"
> >> +	depends on ACPI
> >> +	depends on INTEL_SOC_PMIC
> >> +	help
> >> +	  Select this option to enable support for ACPI operation
> >> +	  region of the PMIC chip. The operation region can be used
> >> +	  to control power rails and sensor reading/writing on the
> >> +	  PMIC chip. This config addes ACPI operation region support
> >> +	  for CrystalCove PMIC.
> >> +
> >>  config MFD_INTEL_MSIC
> >>  	bool "Intel MSIC"
> >>  	depends on INTEL_SCU_IPC
> >> diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
> >> index f00148782d9b..e02f0573e293 100644
> >> --- a/drivers/mfd/Makefile
> >> +++ b/drivers/mfd/Makefile
> >> @@ -172,3 +172,4 @@ obj-$(CONFIG_MFD_IPAQ_MICRO)	+= ipaq-micro.o
> >>  
> >>  intel-soc-pmic-objs		:= intel_soc_pmic_core.o intel_soc_pmic_crc.o
> >>  obj-$(CONFIG_INTEL_SOC_PMIC)	+= intel-soc-pmic.o
> >> +obj-$(CONFIG_CRC_PMIC_OPREGION) += intel_soc_pmic_crc_opregion.o intel_soc_pmic_opregion.o
> >> diff --git a/drivers/mfd/intel_soc_pmic_crc.c b/drivers/mfd/intel_soc_pmic_crc.c
> >> index 7107cab832e6..48845d636bba 100644
> >> --- a/drivers/mfd/intel_soc_pmic_crc.c
> >> +++ b/drivers/mfd/intel_soc_pmic_crc.c
> >> @@ -106,6 +106,9 @@ static struct mfd_cell crystal_cove_dev[] = {
> >>  		.num_resources = ARRAY_SIZE(gpio_resources),
> >>  		.resources = gpio_resources,
> >>  	},
> >> +	{
> >> +		.name = "crystal_cove_region",
> >> +	},
> >>  };
> >>  
> >>  static struct regmap_config crystal_cove_regmap_config = {
> >> diff --git a/drivers/mfd/intel_soc_pmic_crc_opregion.c b/drivers/mfd/intel_soc_pmic_crc_opregion.c
> >> new file mode 100644
> >> index 000000000000..27b67dc3fa8d
> >> --- /dev/null
> >> +++ b/drivers/mfd/intel_soc_pmic_crc_opregion.c
> >> @@ -0,0 +1,229 @@
> >> +/*
> >> + * intel_soc_pmic_crc_opregion.c - Intel SoC PMIC operation region Driver
> >> + *
> >> + * Copyright (C) 2014 Intel Corporation. All rights reserved.
> >> + *
> >> + * This program is free software; you can redistribute it and/or
> >> + * modify it under the terms of the GNU General Public License version
> >> + * 2 as published by the Free Software Foundation.
> >> + *
> >> + * This program is distributed in the hope that 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/module.h>
> >> +#include <linux/acpi.h>
> >> +#include <linux/mfd/intel_soc_pmic.h>
> >> +#include <linux/regmap.h>
> >> +#include <linux/platform_device.h>
> >> +#include "intel_soc_pmic_opregion.h"
> >> +
> >> +#define PWR_SOURCE_SELECT	BIT(1)
> >> +
> >> +#define PMIC_A0LOCK_REG		0xc5
> >> +
> >> +static struct pmic_pwr_table pwr_table[] = {
> >> +	{
> >> +		.address = 0x24,
> >> +		.pwr_reg = {
> >> +			.reg = 0x66,
> >> +			.bit = 0x00,
> >> +		},
> >> +	},	/* X285 -> V2P85SX, camara */
> >> +	{
> >> +		.address = 0x48,
> >> +		.pwr_reg = {
> >> +			.reg = 0x5d,
> >> +			.bit = 0x00,
> >> +		},
> >> +	},	/* V18X -> V1P8SX, eMMC/camara/audio */
> >> +};
> >> +
> >> +static struct pmic_dptf_table dptf_table[] = {
> >> +	{
> >> +		.address = 0x00,
> >> +		.reg = 0x75
> >> +	},	/* TMP0 -> SYS0_THRM_RSLT_L */
> >> +	{
> >> +		.address = 0x04,
> >> +		.reg = 0x95
> >> +	},	/* AX00 -> SYS0_THRMALRT0_L */
> >> +	{
> >> +		.address = 0x08,
> >> +		.reg = 0x97
> >> +	},	/* AX01 -> SYS0_THRMALRT1_L */
> >> +	{
> >> +		.address = 0x0c,
> >> +		.reg = 0x77
> >> +	},	/* TMP1 -> SYS1_THRM_RSLT_L */
> >> +	{
> >> +		.address = 0x10,
> >> +		.reg = 0x9a
> >> +	},	/* AX10 -> SYS1_THRMALRT0_L */
> >> +	{
> >> +		.address = 0x14,
> >> +		.reg = 0x9c
> >> +	},	/* AX11 -> SYS1_THRMALRT1_L */
> >> +	{
> >> +		.address = 0x18,
> >> +		.reg = 0x79
> >> +	},	/* TMP2 -> SYS2_THRM_RSLT_L */
> >> +	{
> >> +		.address = 0x1c,
> >> +		.reg = 0x9f
> >> +	},	/* AX20 -> SYS2_THRMALRT0_L */
> >> +	{
> >> +		.address = 0x20,
> >> +		.reg = 0xa1
> >> +	},	/* AX21 -> SYS2_THRMALRT1_L */
> >> +	{
> >> +		.address = 0x48,
> >> +		.reg = 0x94
> >> +	},	/* PEN0 -> SYS0_THRMALRT0_H */
> >> +	{
> >> +		.address = 0x4c,
> >> +		.reg = 0x99
> >> +	},	/* PEN1 -> SYS1_THRMALRT1_H */
> >> +	{
> >> +		.address = 0x50,
> >> +		.reg = 0x9e
> >> +	},	/* PEN2 -> SYS2_THRMALRT2_H */
> >> +};
> >> +
> >> +static int intel_crc_pmic_get_power(struct regmap *regmap,
> >> +				    struct pmic_pwr_reg *preg, u64 *value)
> >> +{
> >> +	int data;
> >> +
> >> +	if (regmap_read(regmap, preg->reg, &data))
> >> +		return -EIO;
> >> +
> >> +	*value = (data & PWR_SOURCE_SELECT) && (data & BIT(preg->bit)) ? 1 : 0;
> >> +	return 0;
> >> +}
> >> +
> >> +static int intel_crc_pmic_update_power(struct regmap *regmap,
> >> +				       struct pmic_pwr_reg *preg, bool on)
> >> +{
> >> +	int data;
> >> +
> >> +	if (regmap_read(regmap, preg->reg, &data))
> >> +		return -EIO;
> >> +
> >> +	if (on) {
> >> +		data |= PWR_SOURCE_SELECT | BIT(preg->bit);
> >> +	} else {
> >> +		data &= ~BIT(preg->bit);
> >> +		data |= PWR_SOURCE_SELECT;
> >> +	}
> >> +
> >> +	if (regmap_write(regmap, preg->reg, data))
> >> +		return -EIO;
> >> +	return 0;
> >> +}
> >> +
> >> +/* Raw temperature value is 10bits: 8bits in reg and 2bits in reg-1 bit0,1 */
> >> +static int intel_crc_pmic_get_raw_temp(struct regmap *regmap, int reg)
> >> +{
> >> +	int temp_l, temp_h;
> >> +
> >> +	if (regmap_read(regmap, reg, &temp_l) ||
> >> +	    regmap_read(regmap, reg - 1, &temp_h))
> >> +		return -EIO;
> >> +
> >> +	return (temp_l | ((temp_h & 0x3) << 8));
> >> +}
> >> +
> >> +static int
> >> +intel_crc_pmic_update_aux(struct regmap *regmap, int reg, int raw)
> >> +{
> >> +	if (regmap_write(regmap, reg, raw) ||
> >> +	    regmap_update_bits(regmap, reg - 1, 0x3, raw >> 8))
> >> +		return -EIO;
> >> +
> >> +	return 0;
> >> +}
> >> +
> >> +static int
> >> +intel_crc_pmic_get_policy(struct regmap *regmap, int reg, u64 *value)
> >> +{
> >> +	int pen;
> >> +
> >> +	if (regmap_read(regmap, reg, &pen))
> >> +		return -EIO;
> >> +	*value = pen >> 7;
> >> +	return 0;
> >> +}
> >> +
> >> +static int intel_crc_pmic_update_policy(struct regmap *regmap,
> >> +					int reg, int enable)
> >> +{
> >> +	int alert0;
> >> +
> >> +	/* Update to policy enable bit requires unlocking a0lock */
> >> +	if (regmap_read(regmap, PMIC_A0LOCK_REG, &alert0))
> >> +		return -EIO;
> >> +	if (regmap_update_bits(regmap, PMIC_A0LOCK_REG, 0x01, 0))
> >> +		return -EIO;
> >> +
> >> +	if (regmap_update_bits(regmap, reg, 0x80, enable << 7))
> >> +		return -EIO;
> >> +
> >> +	/* restore alert0 */
> >> +	if (regmap_write(regmap, PMIC_A0LOCK_REG, alert0))
> >> +		return -EIO;
> >> +
> >> +	return 0;
> >> +}
> >> +
> >> +static struct intel_soc_pmic_opregion_data intel_crc_pmic_opregion_data = {
> >> +	.get_power	= intel_crc_pmic_get_power,
> >> +	.update_power	= intel_crc_pmic_update_power,
> >> +	.get_raw_temp	= intel_crc_pmic_get_raw_temp,
> >> +	.update_aux	= intel_crc_pmic_update_aux,
> >> +	.get_policy	= intel_crc_pmic_get_policy,
> >> +	.update_policy	= intel_crc_pmic_update_policy,
> >> +	.pwr_table	= pwr_table,
> >> +	.pwr_table_count= ARRAY_SIZE(pwr_table),
> >> +	.dptf_table	= dptf_table,
> >> +	.dptf_table_count = ARRAY_SIZE(dptf_table),
> >> +};
> >> +
> >> +static int intel_crc_pmic_opregion_probe(struct platform_device *pdev)
> >> +{
> >> +	struct intel_soc_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
> >> +	return intel_soc_pmic_install_opregion_handler(&pdev->dev,
> >> +			ACPI_HANDLE(pdev->dev.parent), pmic->regmap,
> >> +			&intel_crc_pmic_opregion_data);
> >> +}
> >> +
> >> +static int intel_crc_pmic_opregion_remove(struct platform_device *pdev)
> >> +{
> >> +	intel_soc_pmic_remove_opregion_handler(ACPI_HANDLE(pdev->dev.parent));
> >> +	return 0;
> >> +}
> >> +
> >> +#define DRV_NAME "crystal_cove_region"
> >> +
> >> +static struct platform_device_id crystal_cove_opregion_id_table[] = {
> >> +	{ .name = DRV_NAME },
> >> +	{},
> >> +};
> >> +
> >> +static struct platform_driver intel_crc_pmic_opregion_driver = {
> >> +	.probe = intel_crc_pmic_opregion_probe,
> >> +	.remove = intel_crc_pmic_opregion_remove,
> >> +	.id_table = crystal_cove_opregion_id_table,
> >> +	.driver = {
> >> +		.name = DRV_NAME,
> >> +	},
> >> +};
> >> +
> >> +MODULE_DEVICE_TABLE(platform, crystal_cove_opregion_id_table);
> >> +
> >> +module_platform_driver(intel_crc_pmic_opregion_driver);
> >> +
> >> +MODULE_DESCRIPTION("CrystalCove ACPI opregion driver");
> >> +MODULE_LICENSE("GPL");
> >> diff --git a/drivers/mfd/intel_soc_pmic_opregion.c b/drivers/mfd/intel_soc_pmic_opregion.c
> >> new file mode 100644
> >> index 000000000000..62824a35ce97
> >> --- /dev/null
> >> +++ b/drivers/mfd/intel_soc_pmic_opregion.c
> >> @@ -0,0 +1,350 @@
> >> +/*
> >> + * intel_soc_pmic_opregion.c - Intel SoC PMIC operation region Driver
> >> + *
> >> + * Copyright (C) 2014 Intel Corporation. All rights reserved.
> >> + *
> >> + * This program is free software; you can redistribute it and/or
> >> + * modify it under the terms of the GNU General Public License version
> >> + * 2 as published by the Free Software Foundation.
> >> + *
> >> + * This program is distributed in the hope that 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/module.h>
> >> +#include <linux/acpi.h>
> >> +#include <linux/regmap.h>
> >> +#include "intel_soc_pmic_opregion.h"
> >> +
> >> +#define PMIC_PMOP_OPREGION_ID	0x8d
> >> +#define PMIC_DPTF_OPREGION_ID	0x8c
> >> +
> >> +struct acpi_lpat {
> >> +	int temp;
> >> +	int raw;
> >> +};
> >> +
> >> +struct intel_soc_pmic_opregion {
> >> +	struct mutex lock;
> >> +	struct acpi_lpat *lpat;
> >> +	int lpat_count;
> >> +	struct regmap *regmap;
> >> +	struct intel_soc_pmic_opregion_data *data;
> >> +};
> >> +
> >> +static struct pmic_pwr_reg *
> >> +pmic_get_pwr_reg(int address, struct pmic_pwr_table *table, int count)
> >> +{
> >> +	int i;
> >> +
> >> +	for (i = 0; i < count; i++) {
> >> +		if (table[i].address == address)
> >> +			return &table[i].pwr_reg;
> >> +	}
> >> +	return NULL;
> >> +}
> >> +
> >> +static int
> >> +pmic_get_dptf_reg(int address, struct pmic_dptf_table *table, int count)
> >> +{
> >> +	int i;
> >> +
> >> +	for (i = 0; i < count; i++) {
> >> +		if (table[i].address == address)
> >> +			return table[i].reg;
> >> +	}
> >> +	return -ENOENT;
> >> +}
> >> +
> >> +/* Return temperature from raw value through LPAT table */
> >> +static int raw_to_temp(struct acpi_lpat *lpat, int count, int raw)
> >> +{
> >> +	int i, delta_temp, delta_raw, temp;
> >> +
> >> +	for (i = 0; i < count - 1; i++) {
> >> +		if ((raw >= lpat[i].raw && raw <= lpat[i+1].raw) ||
> >> +		    (raw <= lpat[i].raw && raw >= lpat[i+1].raw))
> >> +			break;
> >> +	}
> >> +
> >> +	if (i == count - 1)
> >> +		return -ENOENT;
> >> +
> >> +	delta_temp = lpat[i+1].temp - lpat[i].temp;
> >> +	delta_raw = lpat[i+1].raw - lpat[i].raw;
> >> +	temp = lpat[i].temp + (raw - lpat[i].raw) * delta_temp / delta_raw;
> >> +
> >> +	return temp;
> >> +}
> >> +
> >> +/* Return raw value from temperature through LPAT table */
> >> +static int temp_to_raw(struct acpi_lpat *lpat, int count, int temp)
> >> +{
> >> +	int i, delta_temp, delta_raw, raw;
> >> +
> >> +	for (i = 0; i < count - 1; i++) {
> >> +		if (temp >= lpat[i].temp && temp <= lpat[i+1].temp)
> >> +			break;
> >> +	}
> >> +
> >> +	if (i == count - 1)
> >> +		return -ENOENT;
> >> +
> >> +	delta_temp = lpat[i+1].temp - lpat[i].temp;
> >> +	delta_raw = lpat[i+1].raw - lpat[i].raw;
> >> +	raw = lpat[i].raw + (temp - lpat[i].temp) * delta_raw / delta_temp;
> >> +
> >> +	return raw;
> >> +}
> >> +
> >> +static void
> >> +pmic_dptf_lpat(struct intel_soc_pmic_opregion *opregion, acpi_handle handle,
> >> +	       struct device *dev)
> >> +{
> >> +	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
> >> +	union acpi_object *obj_p, *obj_e;
> >> +	int *lpat, i;
> >> +	acpi_status status;
> >> +
> >> +	status = acpi_evaluate_object(handle, "LPAT", NULL, &buffer);
> >> +	if (ACPI_FAILURE(status))
> >> +		return;
> >> +
> >> +	obj_p = (union acpi_object *)buffer.pointer;
> >> +	if (!obj_p || (obj_p->type != ACPI_TYPE_PACKAGE) ||
> >> +	    (obj_p->package.count % 2) || (obj_p->package.count < 4))
> >> +		goto out;
> >> +
> >> +	lpat = devm_kmalloc(dev, sizeof(*lpat) * obj_p->package.count,
> >> +			    GFP_KERNEL);
> >> +	if (!lpat)
> >> +		goto out;
> >> +
> >> +	for (i = 0; i < obj_p->package.count; i++) {
> >> +		obj_e = &obj_p->package.elements[i];
> >> +		if (obj_e->type != ACPI_TYPE_INTEGER)
> >> +			goto out;
> >> +		lpat[i] = obj_e->integer.value;
> >> +	}
> >> +
> >> +	opregion->lpat = (struct acpi_lpat *)lpat;
> >> +	opregion->lpat_count = obj_p->package.count / 2;
> >> +
> >> +out:
> >> +	kfree(buffer.pointer);
> >> +}
> >> +
> >> +static acpi_status
> >> +intel_soc_pmic_pmop_handler(u32 function, acpi_physical_address address,
> >> +			    u32 bits, u64 *value64,
> >> +			    void *handler_context, void *region_context)
> >> +{
> >> +	struct intel_soc_pmic_opregion *opregion = region_context;
> >> +	struct regmap *regmap = opregion->regmap;
> >> +	struct intel_soc_pmic_opregion_data *d = opregion->data;
> >> +	struct pmic_pwr_reg *preg;
> >> +	int result;
> >> +
> >> +	if (bits != 32 || !value64)
> >> +		return AE_BAD_PARAMETER;
> >> +
> >> +	if (function == ACPI_WRITE && !(*value64 == 0 || *value64 == 1))
> >> +		return AE_BAD_PARAMETER;
> >> +
> >> +	preg = pmic_get_pwr_reg(address, d->pwr_table, d->pwr_table_count);
> >> +	if (!preg)
> >> +		return AE_BAD_PARAMETER;
> >> +
> >> +	mutex_lock(&opregion->lock);
> >> +
> >> +	if (function == ACPI_READ)
> >> +		result = d->get_power(regmap, preg, value64);
> >> +	else
> >> +		result = d->update_power(regmap, preg, *value64 == 1);
> >> +
> >> +	mutex_unlock(&opregion->lock);
> >> +
> >> +	return result ? AE_ERROR : AE_OK;
> >> +}
> >> +
> >> +static acpi_status pmic_read_temp(struct intel_soc_pmic_opregion *opregion,
> >> +				  int reg, u64 *value)
> >> +{
> >> +	int raw_temp, temp;
> >> +
> >> +	if (!opregion->data->get_raw_temp)
> >> +		return AE_BAD_PARAMETER;
> >> +
> >> +	raw_temp = opregion->data->get_raw_temp(opregion->regmap, reg);
> >> +	if (raw_temp < 0)
> >> +		return AE_ERROR;
> >> +
> >> +	if (!opregion->lpat) {
> >> +		*value = raw_temp;
> >> +		return AE_OK;
> >> +	}
> >> +
> >> +	temp = raw_to_temp(opregion->lpat, opregion->lpat_count, raw_temp);
> >> +	if (temp < 0)
> >> +		return AE_ERROR;
> >> +
> >> +	*value = temp;
> >> +	return AE_OK;
> >> +}
> >> +
> >> +static acpi_status pmic_dptf_temp(struct intel_soc_pmic_opregion *opregion,
> >> +				  int reg, u32 function, u64 *value)
> >> +{
> >> +	if (function != ACPI_READ)
> >> +		return AE_BAD_PARAMETER;
> >> +
> >> +	return pmic_read_temp(opregion, reg, value);
> >> +}
> >> +
> >> +static acpi_status pmic_dptf_aux(struct intel_soc_pmic_opregion *opregion,
> >> +				 int reg, u32 function, u64 *value)
> >> +{
> >> +	int raw_temp;
> >> +
> >> +	if (function == ACPI_READ)
> >> +		return pmic_read_temp(opregion, reg, value);
> >> +
> >> +	if (!opregion->data->update_aux)
> >> +		return AE_BAD_PARAMETER;
> >> +
> >> +	if (opregion->lpat) {
> >> +		raw_temp = temp_to_raw(opregion->lpat, opregion->lpat_count,
> >> +					 *value);
> >> +		if (raw_temp < 0)
> >> +			return AE_ERROR;
> >> +	} else {
> >> +		raw_temp = *value;
> >> +	}
> >> +
> >> +	return opregion->data->update_aux(opregion->regmap, reg, raw_temp) ?
> >> +		AE_ERROR : AE_OK;
> >> +}
> >> +
> >> +static acpi_status pmic_dptf_pen(struct intel_soc_pmic_opregion *opregion,
> >> +				 int reg, u32 function, u64 *value)
> >> +{
> >> +	struct intel_soc_pmic_opregion_data *d = opregion->data;
> >> +	struct regmap *regmap = opregion->regmap;
> >> +
> >> +	if (!d->get_policy || !d->update_policy)
> >> +		return AE_BAD_PARAMETER;
> >> +
> >> +	if (function == ACPI_READ)
> >> +		return d->get_policy(regmap, reg, value) ? AE_ERROR : AE_OK;
> >> +
> >> +	if (*value != 0 || *value != 1)
> >> +		return AE_BAD_PARAMETER;
> >> +
> >> +	return d->update_policy(regmap, reg, *value) ? AE_ERROR : AE_OK;
> >> +}
> >> +
> >> +static bool pmic_dptf_is_temp(int address)
> >> +{
> >> +	return (address <= 0x3c) && !(address % 12);
> >> +}
> >> +
> >> +static bool pmic_dptf_is_aux(int address)
> >> +{
> >> +	return (address >= 4 && address <= 0x40 && !((address - 4) % 12)) ||
> >> +	       (address >= 8 && address <= 0x44 && !((address - 8) % 12));
> >> +}
> >> +
> >> +static bool pmic_dptf_is_pen(int address)
> >> +{
> >> +	return address >= 0x48 && address <= 0x5c;
> >> +}
> >> +
> >> +static acpi_status
> >> +intel_soc_pmic_dptf_handler(u32 function, acpi_physical_address address,
> >> +			    u32 bits, u64 *value64,
> >> +			    void *handler_context, void *region_context)
> >> +{
> >> +	struct intel_soc_pmic_opregion *opregion = region_context;
> >> +	int reg;
> >> +	int result;
> >> +
> >> +	if (bits != 32 || !value64)
> >> +		return AE_BAD_PARAMETER;
> >> +
> >> +	reg = pmic_get_dptf_reg(address, opregion->data->dptf_table,
> >> +				opregion->data->dptf_table_count);
> >> +	if (!reg)
> >> +		return AE_BAD_PARAMETER;
> >> +
> >> +	mutex_lock(&opregion->lock);
> >> +
> >> +	result = AE_BAD_PARAMETER;
> >> +	if (pmic_dptf_is_temp(address))
> >> +		result = pmic_dptf_temp(opregion, reg, function, value64);
> >> +	else if (pmic_dptf_is_aux(address))
> >> +		result = pmic_dptf_aux(opregion, reg, function, value64);
> >> +	else if (pmic_dptf_is_pen(address))
> >> +		result = pmic_dptf_pen(opregion, reg, function, value64);
> >> +
> >> +	mutex_unlock(&opregion->lock);
> >> +
> >> +	return result;
> >> +}
> >> +
> >> +int
> >> +intel_soc_pmic_install_opregion_handler(struct device *dev,
> >> +					acpi_handle handle,
> >> +					struct regmap *regmap,
> >> +					struct intel_soc_pmic_opregion_data *d)
> >> +{
> >> +	acpi_status status;
> >> +	struct intel_soc_pmic_opregion *opregion;
> >> +
> >> +	if (!dev || !regmap || !d)
> >> +		return -EINVAL;
> >> +
> >> +	if (!handle)
> >> +		return -ENODEV;
> >> +
> >> +	opregion = devm_kzalloc(dev, sizeof(*opregion), GFP_KERNEL);
> >> +	if (!opregion)
> >> +		return -ENOMEM;
> >> +
> >> +	mutex_init(&opregion->lock);
> >> +	opregion->regmap = regmap;
> >> +	pmic_dptf_lpat(opregion, handle, dev);
> >> +
> >> +	status = acpi_install_address_space_handler(handle,
> >> +						    PMIC_PMOP_OPREGION_ID,
> >> +						    intel_soc_pmic_pmop_handler,
> >> +						    NULL, opregion);
> >> +	if (ACPI_FAILURE(status))
> >> +		return -ENODEV;
> >> +
> >> +	status = acpi_install_address_space_handler(handle,
> >> +						    PMIC_DPTF_OPREGION_ID,
> >> +						    intel_soc_pmic_dptf_handler,
> >> +						    NULL, opregion);
> >> +	if (ACPI_FAILURE(status)) {
> >> +		acpi_remove_address_space_handler(handle, PMIC_PMOP_OPREGION_ID,
> >> +						  intel_soc_pmic_pmop_handler);
> >> +		return -ENODEV;
> >> +	}
> >> +
> >> +	opregion->data = d;
> >> +	return 0;
> >> +}
> >> +EXPORT_SYMBOL_GPL(intel_soc_pmic_install_opregion_handler);
> >> +
> >> +void intel_soc_pmic_remove_opregion_handler(acpi_handle handle)
> >> +{
> >> +	acpi_remove_address_space_handler(handle, PMIC_PMOP_OPREGION_ID,
> >> +					  intel_soc_pmic_pmop_handler);
> >> +	acpi_remove_address_space_handler(handle, PMIC_DPTF_OPREGION_ID,
> >> +					  intel_soc_pmic_dptf_handler);
> >> +}
> >> +EXPORT_SYMBOL_GPL(intel_soc_pmic_remove_opregion_handler);
> >> +
> >> +MODULE_LICENSE("GPL");
> >> diff --git a/drivers/mfd/intel_soc_pmic_opregion.h b/drivers/mfd/intel_soc_pmic_opregion.h
> >> new file mode 100644
> >> index 000000000000..752ec3d2bcbb
> >> --- /dev/null
> >> +++ b/drivers/mfd/intel_soc_pmic_opregion.h
> >> @@ -0,0 +1,35 @@
> >> +#ifndef __INTEL_SOC_PMIC_OPREGION_H
> >> +#define __INTEL_SOC_PMIC_OPREGION_H
> >> +
> >> +struct pmic_pwr_reg {
> >> +	int reg;	/* corresponding PMIC register */
> >> +	int bit;	/* control bit for power */
> >> +};
> >> +
> >> +struct pmic_pwr_table {
> >> +	int address;	/* operation region address */
> >> +	struct pmic_pwr_reg pwr_reg;
> >> +};
> >> +
> >> +struct pmic_dptf_table {
> >> +	int address;	/* operation region address */
> >> +	int reg;	/* corresponding thermal register */
> >> +};
> >> +
> >> +struct intel_soc_pmic_opregion_data {
> >> +	int (*get_power)(struct regmap *r, struct pmic_pwr_reg *preg, u64 *value);
> >> +	int (*update_power)(struct regmap *r, struct pmic_pwr_reg *preg, bool on);
> >> +	int (*get_raw_temp)(struct regmap *r, int reg);
> >> +	int (*update_aux)(struct regmap *r, int reg, int raw_temp);
> >> +	int (*get_policy)(struct regmap *r, int reg, u64 *value);
> >> +	int (*update_policy)(struct regmap *r, int reg, int enable);
> >> +	struct pmic_pwr_table *pwr_table;
> >> +	int pwr_table_count;
> >> +	struct pmic_dptf_table *dptf_table;
> >> +	int dptf_table_count;
> >> +};
> >> +
> >> +int intel_soc_pmic_install_opregion_handler(struct device *dev, acpi_handle handle, struct regmap *regmap, struct intel_soc_pmic_opregion_data *d);
> >> +void intel_soc_pmic_remove_opregion_handler(acpi_handle handle);
> >> +
> >> +#endif
> > 
> 

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

* Re: [PATCH 2/2] PMIC / opregion: support PMIC customized operation region for CrystalCove
  2014-10-13  9:02       ` Aaron Lu
@ 2014-10-13 14:51         ` Rafael J. Wysocki
  0 siblings, 0 replies; 21+ messages in thread
From: Rafael J. Wysocki @ 2014-10-13 14:51 UTC (permalink / raw)
  To: Aaron Lu
  Cc: Linus Walleij, Lee Jones, Alexandre Courbot, Samuel Ortiz,
	Arnd Bergmann, linux-gpio, linux-arch, linux-kernel, Jacob Pan,
	Lejun Zhu, Radivoje Jovanovic, Daniel Glöckner, linux-acpi,
	Mark Brown

On Monday, October 13, 2014 05:02:13 PM Aaron Lu wrote:
> On Thu, Oct 09, 2014 at 05:21:28PM +0800, Aaron Lu wrote:
> > On 10/08/2014 04:05 PM, Lee Jones wrote:
> > > To all those CC'ed,
> > > 
> > >> The Baytrail-T platform firmware has defined two customized operation
> > >> regions for PMIC chip Crystal Cove - one is for power resource handling
> > >> and one is for thermal: sensor temperature reporting, trip point setting,
> > >> etc. This patch adds support for them on top of the existing Crystal Cove
> > >> PMIC driver.
> > >>
> > >> The reason to split code into a separate file intel_soc_pmic_opregion.c
> > >> is that there are more PMIC driver with ACPI operation region support
> > >> coming and we can re-use those code. The intel_soc_pmic_opregion_data
> > >> structure is created also for this purpose: when we need to support a
> > >> new PMIC's operation region, we just need to fill those callbacks and
> > >> the two register mapping tables.
> > >>
> > >> Signed-off-by: Aaron Lu <aaron.lu@intel.com>
> > >> ---
> > >>  drivers/mfd/Kconfig                       |  11 +
> > >>  drivers/mfd/Makefile                      |   1 +
> > >>  drivers/mfd/intel_soc_pmic_crc.c          |   3 +
> > >>  drivers/mfd/intel_soc_pmic_crc_opregion.c | 229 +++++++++++++++++++
> > >>  drivers/mfd/intel_soc_pmic_opregion.c     | 350 ++++++++++++++++++++++++++++++
> > >>  drivers/mfd/intel_soc_pmic_opregion.h     |  35 +++
> > > 
> > > With the influx of new same-chip devices, I think the MFD subsystem is
> > > fast becoming overloaded.  I think all of the PMIC handling should in
> > > fact either live in Regulators or have its own subsystem.
> > > 
> > > Let's open this up to the floor by Cc'ing some probable interested
> > > parties.
> > 
> > The ACPI operation region handler provides implementation for the ASL
> > code written by firmware developer, and since the ACPI PMIC device node
> > has two customized operation regions: power rail handling and thermal
> > sensor manipulating, implementing the handler will inevitably touch
> > power rail registers and thermal registers of the PMIC chip. In this
> > regard, it doesn't fit what the MFD subsystem is meant to contain(
> > according to your comments, I didn't know this before, sorry about that).
> > 
> > It seems that we have two options:
> > 1 Create two cell devices from the PMIC I2C driver, one for power and
> >   one for thermal; the driver for the power part goes to drivers/power
> >   or drivers/regulator and the driver for thermal one goes to
> >   drivers/thermal;
> >   The problem of this approach is that, the operation region handler
> >   driver doesn't really need to expose those power or thermal sysfs
> >   interfaces for user space to consume, perhaps it shouldn't, as its
> >   sole purpose is to satisfy the ASL code access, not more.
> > 2 Move these operation region handler drivers to drivers/acpi
> >   We now have EC operation region handler driver there, but we also have
> >   I2C, GPIO, i915 operation region handlers in their own subsystems. Not
> >   sure if PMIC operation region handler qualifies there.
> 
> Rafael,
> 
> May I have your opinion on option 2? Do you think it is OK to place the
> operation region code under drivers/acpi? Thanks.

In my opinion, yes it is.  After all, operation regions are a mechanism by
which the AML interpreter can access hardware.

-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.

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

* [PATCH 0/2] Support CrystalCove PMIC ACPI operation region
@ 2014-09-09  2:26 Aaron Lu
  0 siblings, 0 replies; 21+ messages in thread
From: Aaron Lu @ 2014-09-09  2:26 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot, Samuel Ortiz, Lee Jones, Arnd Bergmann
  Cc: linux-gpio, linux-arch, linux-kernel, Jacob Pan, Lejun Zhu,
	Radivoje Jovanovic, Daniel Glöckner

The two patches add support for CrystalCove PMIC ACPI operation region.
The PMIC chip has two customized operation regions: one for power rail
manipulation and one for thermal purpose: sensor temperature reading
and trip point value reading/setting.

For an example ASL code on ASUS T100 with CrystalCove PMIC, see here:
https://gist.github.com/aaronlu/f5f65771a6c3251fae5d

Aaron Lu (2):
  gpio / CrystalCove: support virtual GPIO
  PMIC / opregion: support PMIC customized operation region for
    CrystalCove

 drivers/gpio/gpio-crystalcove.c           |  19 +-
 drivers/mfd/Kconfig                       |  11 +
 drivers/mfd/Makefile                      |   1 +
 drivers/mfd/intel_soc_pmic_crc.c          |   3 +
 drivers/mfd/intel_soc_pmic_crc_opregion.c | 229 +++++++++++++++++++
 drivers/mfd/intel_soc_pmic_opregion.c     | 350 ++++++++++++++++++++++++++++++
 drivers/mfd/intel_soc_pmic_opregion.h     |  35 +++
 include/asm-generic/gpio.h                |   2 +-
 8 files changed, 646 insertions(+), 4 deletions(-)
 create mode 100644 drivers/mfd/intel_soc_pmic_crc_opregion.c
 create mode 100644 drivers/mfd/intel_soc_pmic_opregion.c
 create mode 100644 drivers/mfd/intel_soc_pmic_opregion.h

-- 
1.9.3


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

end of thread, other threads:[~2014-10-13 14:31 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-09  2:32 [PATCH 0/2] Support CrystalCove PMIC ACPI operation region Aaron Lu
2014-09-09  2:32 ` [PATCH 1/2] gpio / CrystalCove: support virtual GPIO Aaron Lu
2014-09-23 10:13   ` Linus Walleij
2014-09-24 11:18   ` Linus Walleij
2014-09-25  2:57     ` [PATCH v2 " Aaron Lu
2014-09-25 11:15       ` Mika Westerberg
2014-09-26  5:21         ` Aaron Lu
2014-09-25 13:16       ` Linus Walleij
2014-09-26  5:22         ` Aaron Lu
2014-09-09  2:32 ` [PATCH 2/2] PMIC / opregion: support PMIC customized operation region for CrystalCove Aaron Lu
2014-10-08  8:05   ` Lee Jones
2014-10-08  9:16     ` Linus Walleij
2014-10-08 11:58       ` Jacob Pan
2014-10-08 12:54       ` Mark Brown
2014-10-09  9:21     ` Aaron Lu
2014-10-13  9:02       ` Aaron Lu
2014-10-13 14:51         ` Rafael J. Wysocki
2014-09-09  2:37 ` [PATCH 0/2] Support CrystalCove PMIC ACPI operation region Aaron Lu
2014-09-15  2:57 ` Aaron Lu
2014-09-15 22:43   ` Lee Jones
  -- strict thread matches above, loose matches on Subject: below --
2014-09-09  2:26 Aaron Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).