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
25 static struct pmic_table power_table[] = {
123 /* TMP0 - TMP5 are the same, all from GPADC */
124 static struct pmic_table thermal_table[] = {
127 .reg = XPOWER_GPADC_LOW
131 .reg = XPOWER_GPADC_LOW
135 .reg = XPOWER_GPADC_LOW
139 .reg = XPOWER_GPADC_LOW
143 .reg = XPOWER_GPADC_LOW
147 .reg = XPOWER_GPADC_LOW
151 static int intel_xpower_pmic_get_power(struct regmap *regmap, int reg,
156 if (regmap_read(regmap, reg, &data))
159 *value = (data & BIT(bit)) ? 1 : 0;
163 static int intel_xpower_pmic_update_power(struct regmap *regmap, int reg,
168 if (regmap_read(regmap, reg, &data))
176 if (regmap_write(regmap, reg, data))
183 * intel_xpower_pmic_get_raw_temp(): Get raw temperature reading from the PMIC
185 * @regmap: regmap of the PMIC device
186 * @reg: register to get the reading
188 * Return a positive value on success, errno on failure.
190 static int intel_xpower_pmic_get_raw_temp(struct regmap *regmap, int reg)
194 if (regmap_bulk_read(regmap, AXP288_GP_ADC_H, buf, 2))
197 return (buf[0] << 4) + ((buf[1] >> 4) & 0x0F);
200 static struct intel_pmic_opregion_data intel_xpower_pmic_opregion_data = {
201 .get_power = intel_xpower_pmic_get_power,
202 .update_power = intel_xpower_pmic_update_power,
203 .get_raw_temp = intel_xpower_pmic_get_raw_temp,
204 .power_table = power_table,
205 .power_table_count = ARRAY_SIZE(power_table),
206 .thermal_table = thermal_table,
207 .thermal_table_count = ARRAY_SIZE(thermal_table),
210 static acpi_status intel_xpower_pmic_gpio_handler(u32 function,
211 acpi_physical_address address, u32 bit_width, u64 *value,
212 void *handler_context, void *region_context)
217 static int intel_xpower_pmic_opregion_probe(struct platform_device *pdev)
219 struct device *parent = pdev->dev.parent;
220 struct axp20x_dev *axp20x = dev_get_drvdata(parent);
224 status = acpi_install_address_space_handler(ACPI_HANDLE(parent),
225 ACPI_ADR_SPACE_GPIO, intel_xpower_pmic_gpio_handler,
227 if (ACPI_FAILURE(status))
230 result = intel_pmic_install_opregion_handler(&pdev->dev,
231 ACPI_HANDLE(parent), axp20x->regmap,
232 &intel_xpower_pmic_opregion_data);
234 acpi_remove_address_space_handler(ACPI_HANDLE(parent),
236 intel_xpower_pmic_gpio_handler);
241 static struct platform_driver intel_xpower_pmic_opregion_driver = {
242 .probe = intel_xpower_pmic_opregion_probe,
244 .name = "axp288_pmic_acpi",
248 static int __init intel_xpower_pmic_opregion_driver_init(void)
250 return platform_driver_register(&intel_xpower_pmic_opregion_driver);
252 device_initcall(intel_xpower_pmic_opregion_driver_init);