2 * intel_pmic_xpower.c - XPower AXP288 PMIC operation region driver
4 * Copyright (C) 2014 Intel Corporation. All rights reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #include <linux/init.h>
17 #include <linux/acpi.h>
18 #include <linux/mfd/axp20x.h>
19 #include <linux/regmap.h>
20 #include <linux/platform_device.h>
21 #include "intel_pmic.h"
23 #define XPOWER_GPADC_LOW 0x5b
24 #define XPOWER_GPI1_CTRL 0x92
26 #define GPI1_LDO_MASK GENMASK(2, 0)
27 #define GPI1_LDO_ON (3 << 0)
28 #define GPI1_LDO_OFF (4 << 0)
30 #define AXP288_ADC_TS_PIN_GPADC 0xf2
31 #define AXP288_ADC_TS_PIN_ON 0xf3
33 static struct pmic_table power_table[] = {
135 /* TMP0 - TMP5 are the same, all from GPADC */
136 static struct pmic_table thermal_table[] = {
139 .reg = XPOWER_GPADC_LOW
143 .reg = XPOWER_GPADC_LOW
147 .reg = XPOWER_GPADC_LOW
151 .reg = XPOWER_GPADC_LOW
155 .reg = XPOWER_GPADC_LOW
159 .reg = XPOWER_GPADC_LOW
163 static int intel_xpower_pmic_get_power(struct regmap *regmap, int reg,
168 if (regmap_read(regmap, reg, &data))
171 /* GPIO1 LDO regulator needs special handling */
172 if (reg == XPOWER_GPI1_CTRL)
173 *value = ((data & GPI1_LDO_MASK) == GPI1_LDO_ON);
175 *value = (data & BIT(bit)) ? 1 : 0;
180 static int intel_xpower_pmic_update_power(struct regmap *regmap, int reg,
185 /* GPIO1 LDO regulator needs special handling */
186 if (reg == XPOWER_GPI1_CTRL)
187 return regmap_update_bits(regmap, reg, GPI1_LDO_MASK,
188 on ? GPI1_LDO_ON : GPI1_LDO_OFF);
190 if (regmap_read(regmap, reg, &data))
198 if (regmap_write(regmap, reg, data))
205 * intel_xpower_pmic_get_raw_temp(): Get raw temperature reading from the PMIC
207 * @regmap: regmap of the PMIC device
208 * @reg: register to get the reading
210 * Return a positive value on success, errno on failure.
212 static int intel_xpower_pmic_get_raw_temp(struct regmap *regmap, int reg)
217 ret = regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL,
218 AXP288_ADC_TS_PIN_GPADC);
222 /* After switching to the GPADC pin give things some time to settle */
223 usleep_range(6000, 10000);
225 ret = regmap_bulk_read(regmap, AXP288_GP_ADC_H, buf, 2);
227 ret = (buf[0] << 4) + ((buf[1] >> 4) & 0x0f);
229 regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, AXP288_ADC_TS_PIN_ON);
234 static struct intel_pmic_opregion_data intel_xpower_pmic_opregion_data = {
235 .get_power = intel_xpower_pmic_get_power,
236 .update_power = intel_xpower_pmic_update_power,
237 .get_raw_temp = intel_xpower_pmic_get_raw_temp,
238 .power_table = power_table,
239 .power_table_count = ARRAY_SIZE(power_table),
240 .thermal_table = thermal_table,
241 .thermal_table_count = ARRAY_SIZE(thermal_table),
244 static acpi_status intel_xpower_pmic_gpio_handler(u32 function,
245 acpi_physical_address address, u32 bit_width, u64 *value,
246 void *handler_context, void *region_context)
251 static int intel_xpower_pmic_opregion_probe(struct platform_device *pdev)
253 struct device *parent = pdev->dev.parent;
254 struct axp20x_dev *axp20x = dev_get_drvdata(parent);
258 status = acpi_install_address_space_handler(ACPI_HANDLE(parent),
259 ACPI_ADR_SPACE_GPIO, intel_xpower_pmic_gpio_handler,
261 if (ACPI_FAILURE(status))
264 result = intel_pmic_install_opregion_handler(&pdev->dev,
265 ACPI_HANDLE(parent), axp20x->regmap,
266 &intel_xpower_pmic_opregion_data);
268 acpi_remove_address_space_handler(ACPI_HANDLE(parent),
270 intel_xpower_pmic_gpio_handler);
275 static struct platform_driver intel_xpower_pmic_opregion_driver = {
276 .probe = intel_xpower_pmic_opregion_probe,
278 .name = "axp288_pmic_acpi",
281 builtin_platform_driver(intel_xpower_pmic_opregion_driver);