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 static struct pmic_table power_table
[] = {
132 /* TMP0 - TMP5 are the same, all from GPADC */
133 static struct pmic_table thermal_table
[] = {
136 .reg
= XPOWER_GPADC_LOW
140 .reg
= XPOWER_GPADC_LOW
144 .reg
= XPOWER_GPADC_LOW
148 .reg
= XPOWER_GPADC_LOW
152 .reg
= XPOWER_GPADC_LOW
156 .reg
= XPOWER_GPADC_LOW
160 static int intel_xpower_pmic_get_power(struct regmap
*regmap
, int reg
,
165 if (regmap_read(regmap
, reg
, &data
))
168 /* GPIO1 LDO regulator needs special handling */
169 if (reg
== XPOWER_GPI1_CTRL
)
170 *value
= ((data
& GPI1_LDO_MASK
) == GPI1_LDO_ON
);
172 *value
= (data
& BIT(bit
)) ? 1 : 0;
177 static int intel_xpower_pmic_update_power(struct regmap
*regmap
, int reg
,
182 /* GPIO1 LDO regulator needs special handling */
183 if (reg
== XPOWER_GPI1_CTRL
)
184 return regmap_update_bits(regmap
, reg
, GPI1_LDO_MASK
,
185 on
? GPI1_LDO_ON
: GPI1_LDO_OFF
);
187 if (regmap_read(regmap
, reg
, &data
))
195 if (regmap_write(regmap
, reg
, data
))
202 * intel_xpower_pmic_get_raw_temp(): Get raw temperature reading from the PMIC
204 * @regmap: regmap of the PMIC device
205 * @reg: register to get the reading
207 * Return a positive value on success, errno on failure.
209 static int intel_xpower_pmic_get_raw_temp(struct regmap
*regmap
, int reg
)
213 if (regmap_bulk_read(regmap
, AXP288_GP_ADC_H
, buf
, 2))
216 return (buf
[0] << 4) + ((buf
[1] >> 4) & 0x0F);
219 static struct intel_pmic_opregion_data intel_xpower_pmic_opregion_data
= {
220 .get_power
= intel_xpower_pmic_get_power
,
221 .update_power
= intel_xpower_pmic_update_power
,
222 .get_raw_temp
= intel_xpower_pmic_get_raw_temp
,
223 .power_table
= power_table
,
224 .power_table_count
= ARRAY_SIZE(power_table
),
225 .thermal_table
= thermal_table
,
226 .thermal_table_count
= ARRAY_SIZE(thermal_table
),
229 static acpi_status
intel_xpower_pmic_gpio_handler(u32 function
,
230 acpi_physical_address address
, u32 bit_width
, u64
*value
,
231 void *handler_context
, void *region_context
)
236 static int intel_xpower_pmic_opregion_probe(struct platform_device
*pdev
)
238 struct device
*parent
= pdev
->dev
.parent
;
239 struct axp20x_dev
*axp20x
= dev_get_drvdata(parent
);
243 status
= acpi_install_address_space_handler(ACPI_HANDLE(parent
),
244 ACPI_ADR_SPACE_GPIO
, intel_xpower_pmic_gpio_handler
,
246 if (ACPI_FAILURE(status
))
249 result
= intel_pmic_install_opregion_handler(&pdev
->dev
,
250 ACPI_HANDLE(parent
), axp20x
->regmap
,
251 &intel_xpower_pmic_opregion_data
);
253 acpi_remove_address_space_handler(ACPI_HANDLE(parent
),
255 intel_xpower_pmic_gpio_handler
);
260 static struct platform_driver intel_xpower_pmic_opregion_driver
= {
261 .probe
= intel_xpower_pmic_opregion_probe
,
263 .name
= "axp288_pmic_acpi",
267 static int __init
intel_xpower_pmic_opregion_driver_init(void)
269 return platform_driver_register(&intel_xpower_pmic_opregion_driver
);
271 device_initcall(intel_xpower_pmic_opregion_driver_init
);