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_CURRENT_ON_OFF_MASK GENMASK(1, 0)
31 #define AXP288_ADC_TS_CURRENT_OFF (0 << 0)
32 #define AXP288_ADC_TS_CURRENT_ON_WHEN_CHARGING (1 << 0)
33 #define AXP288_ADC_TS_CURRENT_ON_ONDEMAND (2 << 0)
34 #define AXP288_ADC_TS_CURRENT_ON (3 << 0)
36 static struct pmic_table power_table[] = {
138 /* TMP0 - TMP5 are the same, all from GPADC */
139 static struct pmic_table thermal_table[] = {
142 .reg = XPOWER_GPADC_LOW
146 .reg = XPOWER_GPADC_LOW
150 .reg = XPOWER_GPADC_LOW
154 .reg = XPOWER_GPADC_LOW
158 .reg = XPOWER_GPADC_LOW
162 .reg = XPOWER_GPADC_LOW
166 static int intel_xpower_pmic_get_power(struct regmap *regmap, int reg,
171 if (regmap_read(regmap, reg, &data))
174 /* GPIO1 LDO regulator needs special handling */
175 if (reg == XPOWER_GPI1_CTRL)
176 *value = ((data & GPI1_LDO_MASK) == GPI1_LDO_ON);
178 *value = (data & BIT(bit)) ? 1 : 0;
183 static int intel_xpower_pmic_update_power(struct regmap *regmap, int reg,
188 /* GPIO1 LDO regulator needs special handling */
189 if (reg == XPOWER_GPI1_CTRL)
190 return regmap_update_bits(regmap, reg, GPI1_LDO_MASK,
191 on ? GPI1_LDO_ON : GPI1_LDO_OFF);
193 if (regmap_read(regmap, reg, &data))
201 if (regmap_write(regmap, reg, data))
208 * intel_xpower_pmic_get_raw_temp(): Get raw temperature reading from the PMIC
210 * @regmap: regmap of the PMIC device
211 * @reg: register to get the reading
213 * Return a positive value on success, errno on failure.
215 static int intel_xpower_pmic_get_raw_temp(struct regmap *regmap, int reg)
217 int ret, adc_ts_pin_ctrl;
221 * The current-source used for the battery temp-sensor (TS) is shared
222 * with the GPADC. For proper fuel-gauge and charger operation the TS
223 * current-source needs to be permanently on. But to read the GPADC we
224 * need to temporary switch the TS current-source to ondemand, so that
225 * the GPADC can use it, otherwise we will always read an all 0 value.
227 * Note that the switching from on to on-ondemand is not necessary
228 * when the TS current-source is off (this happens on devices which
229 * do not use the TS-pin).
231 ret = regmap_read(regmap, AXP288_ADC_TS_PIN_CTRL, &adc_ts_pin_ctrl);
235 if (adc_ts_pin_ctrl & AXP288_ADC_TS_CURRENT_ON_OFF_MASK) {
236 ret = regmap_update_bits(regmap, AXP288_ADC_TS_PIN_CTRL,
237 AXP288_ADC_TS_CURRENT_ON_OFF_MASK,
238 AXP288_ADC_TS_CURRENT_ON_ONDEMAND);
242 /* Wait a bit after switching the current-source */
243 usleep_range(6000, 10000);
246 ret = regmap_bulk_read(regmap, AXP288_GP_ADC_H, buf, 2);
248 ret = (buf[0] << 4) + ((buf[1] >> 4) & 0x0f);
250 if (adc_ts_pin_ctrl & AXP288_ADC_TS_CURRENT_ON_OFF_MASK) {
251 regmap_update_bits(regmap, AXP288_ADC_TS_PIN_CTRL,
252 AXP288_ADC_TS_CURRENT_ON_OFF_MASK,
253 AXP288_ADC_TS_CURRENT_ON);
259 static struct intel_pmic_opregion_data intel_xpower_pmic_opregion_data = {
260 .get_power = intel_xpower_pmic_get_power,
261 .update_power = intel_xpower_pmic_update_power,
262 .get_raw_temp = intel_xpower_pmic_get_raw_temp,
263 .power_table = power_table,
264 .power_table_count = ARRAY_SIZE(power_table),
265 .thermal_table = thermal_table,
266 .thermal_table_count = ARRAY_SIZE(thermal_table),
269 static acpi_status intel_xpower_pmic_gpio_handler(u32 function,
270 acpi_physical_address address, u32 bit_width, u64 *value,
271 void *handler_context, void *region_context)
276 static int intel_xpower_pmic_opregion_probe(struct platform_device *pdev)
278 struct device *parent = pdev->dev.parent;
279 struct axp20x_dev *axp20x = dev_get_drvdata(parent);
283 status = acpi_install_address_space_handler(ACPI_HANDLE(parent),
284 ACPI_ADR_SPACE_GPIO, intel_xpower_pmic_gpio_handler,
286 if (ACPI_FAILURE(status))
289 result = intel_pmic_install_opregion_handler(&pdev->dev,
290 ACPI_HANDLE(parent), axp20x->regmap,
291 &intel_xpower_pmic_opregion_data);
293 acpi_remove_address_space_handler(ACPI_HANDLE(parent),
295 intel_xpower_pmic_gpio_handler);
300 static struct platform_driver intel_xpower_pmic_opregion_driver = {
301 .probe = intel_xpower_pmic_opregion_probe,
303 .name = "axp288_pmic_acpi",
307 static int __init intel_xpower_pmic_opregion_driver_init(void)
309 return platform_driver_register(&intel_xpower_pmic_opregion_driver);
311 device_initcall(intel_xpower_pmic_opregion_driver_init);