dm thin metadata: fix __udivdi3 undefined on 32-bit
[linux/fpc-iii.git] / drivers / acpi / pmic / intel_pmic_xpower.c
blob24a793957bc0e7d7a93a87aeb9d5962b9c29b566
1 /*
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/module.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 <linux/iio/consumer.h>
22 #include "intel_pmic.h"
24 #define XPOWER_GPADC_LOW 0x5b
26 static struct pmic_table power_table[] = {
28 .address = 0x00,
29 .reg = 0x13,
30 .bit = 0x05,
31 }, /* ALD1 */
33 .address = 0x04,
34 .reg = 0x13,
35 .bit = 0x06,
36 }, /* ALD2 */
38 .address = 0x08,
39 .reg = 0x13,
40 .bit = 0x07,
41 }, /* ALD3 */
43 .address = 0x0c,
44 .reg = 0x12,
45 .bit = 0x03,
46 }, /* DLD1 */
48 .address = 0x10,
49 .reg = 0x12,
50 .bit = 0x04,
51 }, /* DLD2 */
53 .address = 0x14,
54 .reg = 0x12,
55 .bit = 0x05,
56 }, /* DLD3 */
58 .address = 0x18,
59 .reg = 0x12,
60 .bit = 0x06,
61 }, /* DLD4 */
63 .address = 0x1c,
64 .reg = 0x12,
65 .bit = 0x00,
66 }, /* ELD1 */
68 .address = 0x20,
69 .reg = 0x12,
70 .bit = 0x01,
71 }, /* ELD2 */
73 .address = 0x24,
74 .reg = 0x12,
75 .bit = 0x02,
76 }, /* ELD3 */
78 .address = 0x28,
79 .reg = 0x13,
80 .bit = 0x02,
81 }, /* FLD1 */
83 .address = 0x2c,
84 .reg = 0x13,
85 .bit = 0x03,
86 }, /* FLD2 */
88 .address = 0x30,
89 .reg = 0x13,
90 .bit = 0x04,
91 }, /* FLD3 */
93 .address = 0x34,
94 .reg = 0x10,
95 .bit = 0x03,
96 }, /* BUC1 */
98 .address = 0x38,
99 .reg = 0x10,
100 .bit = 0x06,
101 }, /* BUC2 */
103 .address = 0x3c,
104 .reg = 0x10,
105 .bit = 0x05,
106 }, /* BUC3 */
108 .address = 0x40,
109 .reg = 0x10,
110 .bit = 0x04,
111 }, /* BUC4 */
113 .address = 0x44,
114 .reg = 0x10,
115 .bit = 0x01,
116 }, /* BUC5 */
118 .address = 0x48,
119 .reg = 0x10,
120 .bit = 0x00
121 }, /* BUC6 */
124 /* TMP0 - TMP5 are the same, all from GPADC */
125 static struct pmic_table thermal_table[] = {
127 .address = 0x00,
128 .reg = XPOWER_GPADC_LOW
131 .address = 0x0c,
132 .reg = XPOWER_GPADC_LOW
135 .address = 0x18,
136 .reg = XPOWER_GPADC_LOW
139 .address = 0x24,
140 .reg = XPOWER_GPADC_LOW
143 .address = 0x30,
144 .reg = XPOWER_GPADC_LOW
147 .address = 0x3c,
148 .reg = XPOWER_GPADC_LOW
152 static int intel_xpower_pmic_get_power(struct regmap *regmap, int reg,
153 int bit, u64 *value)
155 int data;
157 if (regmap_read(regmap, reg, &data))
158 return -EIO;
160 *value = (data & BIT(bit)) ? 1 : 0;
161 return 0;
164 static int intel_xpower_pmic_update_power(struct regmap *regmap, int reg,
165 int bit, bool on)
167 int data;
169 if (regmap_read(regmap, reg, &data))
170 return -EIO;
172 if (on)
173 data |= BIT(bit);
174 else
175 data &= ~BIT(bit);
177 if (regmap_write(regmap, reg, data))
178 return -EIO;
180 return 0;
184 * intel_xpower_pmic_get_raw_temp(): Get raw temperature reading from the PMIC
186 * @regmap: regmap of the PMIC device
187 * @reg: register to get the reading
189 * We could get the sensor value by manipulating the HW regs here, but since
190 * the axp288 IIO driver may also access the same regs at the same time, the
191 * APIs provided by IIO subsystem are used here instead to avoid problems. As
192 * a result, the two passed in params are of no actual use.
194 * Return a positive value on success, errno on failure.
196 static int intel_xpower_pmic_get_raw_temp(struct regmap *regmap, int reg)
198 struct iio_channel *gpadc_chan;
199 int ret, val;
201 gpadc_chan = iio_channel_get(NULL, "axp288-system-temp");
202 if (IS_ERR_OR_NULL(gpadc_chan))
203 return -EACCES;
205 ret = iio_read_channel_raw(gpadc_chan, &val);
206 if (ret < 0)
207 val = ret;
209 iio_channel_release(gpadc_chan);
210 return val;
213 static struct intel_pmic_opregion_data intel_xpower_pmic_opregion_data = {
214 .get_power = intel_xpower_pmic_get_power,
215 .update_power = intel_xpower_pmic_update_power,
216 .get_raw_temp = intel_xpower_pmic_get_raw_temp,
217 .power_table = power_table,
218 .power_table_count = ARRAY_SIZE(power_table),
219 .thermal_table = thermal_table,
220 .thermal_table_count = ARRAY_SIZE(thermal_table),
223 static acpi_status intel_xpower_pmic_gpio_handler(u32 function,
224 acpi_physical_address address, u32 bit_width, u64 *value,
225 void *handler_context, void *region_context)
227 return AE_OK;
230 static int intel_xpower_pmic_opregion_probe(struct platform_device *pdev)
232 struct device *parent = pdev->dev.parent;
233 struct axp20x_dev *axp20x = dev_get_drvdata(parent);
234 acpi_status status;
235 int result;
237 status = acpi_install_address_space_handler(ACPI_HANDLE(parent),
238 ACPI_ADR_SPACE_GPIO, intel_xpower_pmic_gpio_handler,
239 NULL, NULL);
240 if (ACPI_FAILURE(status))
241 return -ENODEV;
243 result = intel_pmic_install_opregion_handler(&pdev->dev,
244 ACPI_HANDLE(parent), axp20x->regmap,
245 &intel_xpower_pmic_opregion_data);
246 if (result)
247 acpi_remove_address_space_handler(ACPI_HANDLE(parent),
248 ACPI_ADR_SPACE_GPIO,
249 intel_xpower_pmic_gpio_handler);
251 return result;
254 static struct platform_driver intel_xpower_pmic_opregion_driver = {
255 .probe = intel_xpower_pmic_opregion_probe,
256 .driver = {
257 .name = "axp288_pmic_acpi",
261 static int __init intel_xpower_pmic_opregion_driver_init(void)
263 return platform_driver_register(&intel_xpower_pmic_opregion_driver);
265 module_init(intel_xpower_pmic_opregion_driver_init);
267 MODULE_DESCRIPTION("XPower AXP288 ACPI operation region driver");
268 MODULE_LICENSE("GPL");