blob: ed00ba0d64d2e51e2049a408b43a2cbcf05363df [file] [log] [blame]
Carlo Caionecfb61a42014-05-01 14:29:27 +02001/*
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +08002 * MFD core driver for the X-Powers' Power Management ICs
Carlo Caionecfb61a42014-05-01 14:29:27 +02003 *
Jacob Panaf7e9062014-10-06 21:17:14 -07004 * AXP20x typically comprises an adaptive USB-Compatible PWM charger, BUCK DC-DC
5 * converters, LDOs, multiple 12-bit ADCs of voltage, current and temperature
6 * as well as configurable GPIOs.
Carlo Caionecfb61a42014-05-01 14:29:27 +02007 *
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +08008 * This file contains the interface independent core functions.
9 *
Chen-Yu Tsaie7402352016-02-12 10:02:41 +080010 * Copyright (C) 2014 Carlo Caione
11 *
Carlo Caionecfb61a42014-05-01 14:29:27 +020012 * Author: Carlo Caione <carlo@caione.org>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#include <linux/err.h>
Hans de Goede179dc632016-06-05 15:50:48 +020020#include <linux/delay.h>
Carlo Caionecfb61a42014-05-01 14:29:27 +020021#include <linux/interrupt.h>
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/pm_runtime.h>
25#include <linux/regmap.h>
Carlo Caionecfb61a42014-05-01 14:29:27 +020026#include <linux/regulator/consumer.h>
27#include <linux/mfd/axp20x.h>
28#include <linux/mfd/core.h>
29#include <linux/of_device.h>
Jacob Panaf7e9062014-10-06 21:17:14 -070030#include <linux/acpi.h>
Carlo Caionecfb61a42014-05-01 14:29:27 +020031
32#define AXP20X_OFF 0x80
33
Krzysztof Kozlowskic31e8582015-03-24 11:21:17 +010034static const char * const axp20x_model_names[] = {
Michal Suchanekd8d79f82015-07-11 14:59:56 +020035 "AXP152",
Jacob Panaf7e9062014-10-06 21:17:14 -070036 "AXP202",
37 "AXP209",
Boris BREZILLONf05be582015-04-10 12:09:01 +080038 "AXP221",
Chen-Yu Tsai02071f02016-02-12 10:02:44 +080039 "AXP223",
Jacob Panaf7e9062014-10-06 21:17:14 -070040 "AXP288",
Chen-Yu Tsai8824ee82016-08-27 15:55:38 +080041 "AXP806",
Chen-Yu Tsai20147f02016-03-29 17:22:26 +080042 "AXP809",
Jacob Panaf7e9062014-10-06 21:17:14 -070043};
44
Michal Suchanekd8d79f82015-07-11 14:59:56 +020045static const struct regmap_range axp152_writeable_ranges[] = {
46 regmap_reg_range(AXP152_LDO3456_DC1234_CTRL, AXP152_IRQ3_STATE),
47 regmap_reg_range(AXP152_DCDC_MODE, AXP152_PWM1_DUTY_CYCLE),
48};
49
50static const struct regmap_range axp152_volatile_ranges[] = {
51 regmap_reg_range(AXP152_PWR_OP_MODE, AXP152_PWR_OP_MODE),
52 regmap_reg_range(AXP152_IRQ1_EN, AXP152_IRQ3_STATE),
53 regmap_reg_range(AXP152_GPIO_INPUT, AXP152_GPIO_INPUT),
54};
55
56static const struct regmap_access_table axp152_writeable_table = {
57 .yes_ranges = axp152_writeable_ranges,
58 .n_yes_ranges = ARRAY_SIZE(axp152_writeable_ranges),
59};
60
61static const struct regmap_access_table axp152_volatile_table = {
62 .yes_ranges = axp152_volatile_ranges,
63 .n_yes_ranges = ARRAY_SIZE(axp152_volatile_ranges),
64};
65
Carlo Caionecfb61a42014-05-01 14:29:27 +020066static const struct regmap_range axp20x_writeable_ranges[] = {
67 regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ5_STATE),
68 regmap_reg_range(AXP20X_DCDC_MODE, AXP20X_FG_RES),
Bruno Prémont553ed4b2015-08-08 17:58:40 +020069 regmap_reg_range(AXP20X_RDC_H, AXP20X_OCV(AXP20X_OCV_MAX)),
Carlo Caionecfb61a42014-05-01 14:29:27 +020070};
71
72static const struct regmap_range axp20x_volatile_ranges[] = {
Bruno Prémont553ed4b2015-08-08 17:58:40 +020073 regmap_reg_range(AXP20X_PWR_INPUT_STATUS, AXP20X_USB_OTG_STATUS),
74 regmap_reg_range(AXP20X_CHRG_CTRL1, AXP20X_CHRG_CTRL2),
Carlo Caionecfb61a42014-05-01 14:29:27 +020075 regmap_reg_range(AXP20X_IRQ1_EN, AXP20X_IRQ5_STATE),
Bruno Prémont553ed4b2015-08-08 17:58:40 +020076 regmap_reg_range(AXP20X_ACIN_V_ADC_H, AXP20X_IPSOUT_V_HIGH_L),
77 regmap_reg_range(AXP20X_GPIO20_SS, AXP20X_GPIO3_CTRL),
78 regmap_reg_range(AXP20X_FG_RES, AXP20X_RDC_L),
Carlo Caionecfb61a42014-05-01 14:29:27 +020079};
80
81static const struct regmap_access_table axp20x_writeable_table = {
82 .yes_ranges = axp20x_writeable_ranges,
83 .n_yes_ranges = ARRAY_SIZE(axp20x_writeable_ranges),
84};
85
86static const struct regmap_access_table axp20x_volatile_table = {
87 .yes_ranges = axp20x_volatile_ranges,
88 .n_yes_ranges = ARRAY_SIZE(axp20x_volatile_ranges),
89};
90
Chen-Yu Tsai20147f02016-03-29 17:22:26 +080091/* AXP22x ranges are shared with the AXP809, as they cover the same range */
Boris BREZILLONf05be582015-04-10 12:09:01 +080092static const struct regmap_range axp22x_writeable_ranges[] = {
93 regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ5_STATE),
94 regmap_reg_range(AXP20X_DCDC_MODE, AXP22X_BATLOW_THRES1),
95};
96
97static const struct regmap_range axp22x_volatile_ranges[] = {
Hans de Goede15093252016-05-14 19:51:28 +020098 regmap_reg_range(AXP20X_PWR_INPUT_STATUS, AXP20X_PWR_OP_MODE),
Boris BREZILLONf05be582015-04-10 12:09:01 +080099 regmap_reg_range(AXP20X_IRQ1_EN, AXP20X_IRQ5_STATE),
Hans de Goede15093252016-05-14 19:51:28 +0200100 regmap_reg_range(AXP22X_GPIO_STATE, AXP22X_GPIO_STATE),
Icenowy Zheng3f895862016-07-01 17:29:23 +0800101 regmap_reg_range(AXP22X_PMIC_ADC_H, AXP20X_IPSOUT_V_HIGH_L),
Hans de Goede15093252016-05-14 19:51:28 +0200102 regmap_reg_range(AXP20X_FG_RES, AXP20X_FG_RES),
Boris BREZILLONf05be582015-04-10 12:09:01 +0800103};
104
105static const struct regmap_access_table axp22x_writeable_table = {
106 .yes_ranges = axp22x_writeable_ranges,
107 .n_yes_ranges = ARRAY_SIZE(axp22x_writeable_ranges),
108};
109
110static const struct regmap_access_table axp22x_volatile_table = {
111 .yes_ranges = axp22x_volatile_ranges,
112 .n_yes_ranges = ARRAY_SIZE(axp22x_volatile_ranges),
113};
114
Jacob Panaf7e9062014-10-06 21:17:14 -0700115static const struct regmap_range axp288_writeable_ranges[] = {
116 regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ6_STATE),
117 regmap_reg_range(AXP20X_DCDC_MODE, AXP288_FG_TUNE5),
118};
119
120static const struct regmap_range axp288_volatile_ranges[] = {
Hans de Goedecd532162016-12-16 21:09:06 +0100121 regmap_reg_range(AXP20X_PWR_INPUT_STATUS, AXP288_POWER_REASON),
122 regmap_reg_range(AXP288_BC_GLOBAL, AXP288_BC_GLOBAL),
123 regmap_reg_range(AXP288_BC_DET_STAT, AXP288_BC_DET_STAT),
Jacob Panaf7e9062014-10-06 21:17:14 -0700124 regmap_reg_range(AXP20X_IRQ1_EN, AXP20X_IPSOUT_V_HIGH_L),
Hans de Goedecd532162016-12-16 21:09:06 +0100125 regmap_reg_range(AXP20X_TIMER_CTRL, AXP20X_TIMER_CTRL),
126 regmap_reg_range(AXP22X_GPIO_STATE, AXP22X_GPIO_STATE),
127 regmap_reg_range(AXP288_RT_BATT_V_H, AXP288_RT_BATT_V_L),
128 regmap_reg_range(AXP20X_FG_RES, AXP288_FG_CC_CAP_REG),
Jacob Panaf7e9062014-10-06 21:17:14 -0700129};
130
131static const struct regmap_access_table axp288_writeable_table = {
132 .yes_ranges = axp288_writeable_ranges,
133 .n_yes_ranges = ARRAY_SIZE(axp288_writeable_ranges),
134};
135
136static const struct regmap_access_table axp288_volatile_table = {
137 .yes_ranges = axp288_volatile_ranges,
138 .n_yes_ranges = ARRAY_SIZE(axp288_volatile_ranges),
139};
140
Chen-Yu Tsai8824ee82016-08-27 15:55:38 +0800141static const struct regmap_range axp806_writeable_ranges[] = {
142 regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_DATACACHE(3)),
143 regmap_reg_range(AXP806_PWR_OUT_CTRL1, AXP806_CLDO3_V_CTRL),
144 regmap_reg_range(AXP20X_IRQ1_EN, AXP20X_IRQ2_EN),
145 regmap_reg_range(AXP20X_IRQ1_STATE, AXP20X_IRQ2_STATE),
Chen-Yu Tsai34d90302016-11-11 11:29:52 +0800146 regmap_reg_range(AXP806_REG_ADDR_EXT, AXP806_REG_ADDR_EXT),
Chen-Yu Tsai8824ee82016-08-27 15:55:38 +0800147};
148
149static const struct regmap_range axp806_volatile_ranges[] = {
150 regmap_reg_range(AXP20X_IRQ1_STATE, AXP20X_IRQ2_STATE),
151};
152
153static const struct regmap_access_table axp806_writeable_table = {
154 .yes_ranges = axp806_writeable_ranges,
155 .n_yes_ranges = ARRAY_SIZE(axp806_writeable_ranges),
156};
157
158static const struct regmap_access_table axp806_volatile_table = {
159 .yes_ranges = axp806_volatile_ranges,
160 .n_yes_ranges = ARRAY_SIZE(axp806_volatile_ranges),
161};
162
Michal Suchanekd8d79f82015-07-11 14:59:56 +0200163static struct resource axp152_pek_resources[] = {
164 DEFINE_RES_IRQ_NAMED(AXP152_IRQ_PEK_RIS_EDGE, "PEK_DBR"),
165 DEFINE_RES_IRQ_NAMED(AXP152_IRQ_PEK_FAL_EDGE, "PEK_DBF"),
166};
167
Michael Haascd7cf272016-05-06 07:19:49 +0200168static struct resource axp20x_ac_power_supply_resources[] = {
169 DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_ACIN_PLUGIN, "ACIN_PLUGIN"),
170 DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_ACIN_REMOVAL, "ACIN_REMOVAL"),
171 DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_ACIN_OVER_V, "ACIN_OVER_V"),
172};
173
Carlo Caionecfb61a42014-05-01 14:29:27 +0200174static struct resource axp20x_pek_resources[] = {
175 {
176 .name = "PEK_DBR",
177 .start = AXP20X_IRQ_PEK_RIS_EDGE,
178 .end = AXP20X_IRQ_PEK_RIS_EDGE,
179 .flags = IORESOURCE_IRQ,
180 }, {
181 .name = "PEK_DBF",
182 .start = AXP20X_IRQ_PEK_FAL_EDGE,
183 .end = AXP20X_IRQ_PEK_FAL_EDGE,
184 .flags = IORESOURCE_IRQ,
185 },
186};
187
Hans de Goede8de4efd2015-08-08 17:58:41 +0200188static struct resource axp20x_usb_power_supply_resources[] = {
189 DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_VBUS_PLUGIN, "VBUS_PLUGIN"),
190 DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_VBUS_REMOVAL, "VBUS_REMOVAL"),
191 DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_VBUS_VALID, "VBUS_VALID"),
192 DEFINE_RES_IRQ_NAMED(AXP20X_IRQ_VBUS_NOT_VALID, "VBUS_NOT_VALID"),
193};
194
Hans de Goedeecd98cc2016-06-02 19:18:55 +0200195static struct resource axp22x_usb_power_supply_resources[] = {
196 DEFINE_RES_IRQ_NAMED(AXP22X_IRQ_VBUS_PLUGIN, "VBUS_PLUGIN"),
197 DEFINE_RES_IRQ_NAMED(AXP22X_IRQ_VBUS_REMOVAL, "VBUS_REMOVAL"),
198};
199
Boris BREZILLONf05be582015-04-10 12:09:01 +0800200static struct resource axp22x_pek_resources[] = {
201 {
202 .name = "PEK_DBR",
203 .start = AXP22X_IRQ_PEK_RIS_EDGE,
204 .end = AXP22X_IRQ_PEK_RIS_EDGE,
205 .flags = IORESOURCE_IRQ,
206 }, {
207 .name = "PEK_DBF",
208 .start = AXP22X_IRQ_PEK_FAL_EDGE,
209 .end = AXP22X_IRQ_PEK_FAL_EDGE,
210 .flags = IORESOURCE_IRQ,
211 },
212};
213
Borun Fue56e5ad2015-10-14 16:16:26 +0800214static struct resource axp288_power_button_resources[] = {
215 {
216 .name = "PEK_DBR",
Hans de Goede1af468e2016-12-14 14:52:07 +0100217 .start = AXP288_IRQ_POKP,
218 .end = AXP288_IRQ_POKP,
Borun Fue56e5ad2015-10-14 16:16:26 +0800219 .flags = IORESOURCE_IRQ,
220 },
221 {
222 .name = "PEK_DBF",
Hans de Goede1af468e2016-12-14 14:52:07 +0100223 .start = AXP288_IRQ_POKN,
224 .end = AXP288_IRQ_POKN,
Borun Fue56e5ad2015-10-14 16:16:26 +0800225 .flags = IORESOURCE_IRQ,
226 },
227};
228
Todd Brandtd63878742015-02-02 15:41:41 -0800229static struct resource axp288_fuel_gauge_resources[] = {
Jacob Panaf7e9062014-10-06 21:17:14 -0700230 {
231 .start = AXP288_IRQ_QWBTU,
232 .end = AXP288_IRQ_QWBTU,
233 .flags = IORESOURCE_IRQ,
234 },
235 {
236 .start = AXP288_IRQ_WBTU,
237 .end = AXP288_IRQ_WBTU,
238 .flags = IORESOURCE_IRQ,
239 },
240 {
241 .start = AXP288_IRQ_QWBTO,
242 .end = AXP288_IRQ_QWBTO,
243 .flags = IORESOURCE_IRQ,
244 },
245 {
246 .start = AXP288_IRQ_WBTO,
247 .end = AXP288_IRQ_WBTO,
248 .flags = IORESOURCE_IRQ,
249 },
250 {
251 .start = AXP288_IRQ_WL2,
252 .end = AXP288_IRQ_WL2,
253 .flags = IORESOURCE_IRQ,
254 },
255 {
256 .start = AXP288_IRQ_WL1,
257 .end = AXP288_IRQ_WL1,
258 .flags = IORESOURCE_IRQ,
259 },
260};
261
Chen-Yu Tsai20147f02016-03-29 17:22:26 +0800262static struct resource axp809_pek_resources[] = {
263 {
264 .name = "PEK_DBR",
265 .start = AXP809_IRQ_PEK_RIS_EDGE,
266 .end = AXP809_IRQ_PEK_RIS_EDGE,
267 .flags = IORESOURCE_IRQ,
268 }, {
269 .name = "PEK_DBF",
270 .start = AXP809_IRQ_PEK_FAL_EDGE,
271 .end = AXP809_IRQ_PEK_FAL_EDGE,
272 .flags = IORESOURCE_IRQ,
273 },
274};
275
Michal Suchanekd8d79f82015-07-11 14:59:56 +0200276static const struct regmap_config axp152_regmap_config = {
277 .reg_bits = 8,
278 .val_bits = 8,
279 .wr_table = &axp152_writeable_table,
280 .volatile_table = &axp152_volatile_table,
281 .max_register = AXP152_PWM1_DUTY_CYCLE,
282 .cache_type = REGCACHE_RBTREE,
283};
284
Carlo Caionecfb61a42014-05-01 14:29:27 +0200285static const struct regmap_config axp20x_regmap_config = {
286 .reg_bits = 8,
287 .val_bits = 8,
288 .wr_table = &axp20x_writeable_table,
289 .volatile_table = &axp20x_volatile_table,
Bruno Prémont553ed4b2015-08-08 17:58:40 +0200290 .max_register = AXP20X_OCV(AXP20X_OCV_MAX),
Carlo Caionecfb61a42014-05-01 14:29:27 +0200291 .cache_type = REGCACHE_RBTREE,
292};
293
Boris BREZILLONf05be582015-04-10 12:09:01 +0800294static const struct regmap_config axp22x_regmap_config = {
295 .reg_bits = 8,
296 .val_bits = 8,
297 .wr_table = &axp22x_writeable_table,
298 .volatile_table = &axp22x_volatile_table,
299 .max_register = AXP22X_BATLOW_THRES1,
300 .cache_type = REGCACHE_RBTREE,
301};
302
Jacob Panaf7e9062014-10-06 21:17:14 -0700303static const struct regmap_config axp288_regmap_config = {
304 .reg_bits = 8,
305 .val_bits = 8,
306 .wr_table = &axp288_writeable_table,
307 .volatile_table = &axp288_volatile_table,
308 .max_register = AXP288_FG_TUNE5,
309 .cache_type = REGCACHE_RBTREE,
310};
311
Chen-Yu Tsai8824ee82016-08-27 15:55:38 +0800312static const struct regmap_config axp806_regmap_config = {
313 .reg_bits = 8,
314 .val_bits = 8,
315 .wr_table = &axp806_writeable_table,
316 .volatile_table = &axp806_volatile_table,
Chen-Yu Tsai34d90302016-11-11 11:29:52 +0800317 .max_register = AXP806_REG_ADDR_EXT,
Chen-Yu Tsai8824ee82016-08-27 15:55:38 +0800318 .cache_type = REGCACHE_RBTREE,
319};
320
Jacob Panaf7e9062014-10-06 21:17:14 -0700321#define INIT_REGMAP_IRQ(_variant, _irq, _off, _mask) \
322 [_variant##_IRQ_##_irq] = { .reg_offset = (_off), .mask = BIT(_mask) }
Carlo Caionecfb61a42014-05-01 14:29:27 +0200323
Michal Suchanekd8d79f82015-07-11 14:59:56 +0200324static const struct regmap_irq axp152_regmap_irqs[] = {
325 INIT_REGMAP_IRQ(AXP152, LDO0IN_CONNECT, 0, 6),
326 INIT_REGMAP_IRQ(AXP152, LDO0IN_REMOVAL, 0, 5),
327 INIT_REGMAP_IRQ(AXP152, ALDO0IN_CONNECT, 0, 3),
328 INIT_REGMAP_IRQ(AXP152, ALDO0IN_REMOVAL, 0, 2),
329 INIT_REGMAP_IRQ(AXP152, DCDC1_V_LOW, 1, 5),
330 INIT_REGMAP_IRQ(AXP152, DCDC2_V_LOW, 1, 4),
331 INIT_REGMAP_IRQ(AXP152, DCDC3_V_LOW, 1, 3),
332 INIT_REGMAP_IRQ(AXP152, DCDC4_V_LOW, 1, 2),
333 INIT_REGMAP_IRQ(AXP152, PEK_SHORT, 1, 1),
334 INIT_REGMAP_IRQ(AXP152, PEK_LONG, 1, 0),
335 INIT_REGMAP_IRQ(AXP152, TIMER, 2, 7),
336 INIT_REGMAP_IRQ(AXP152, PEK_RIS_EDGE, 2, 6),
337 INIT_REGMAP_IRQ(AXP152, PEK_FAL_EDGE, 2, 5),
338 INIT_REGMAP_IRQ(AXP152, GPIO3_INPUT, 2, 3),
339 INIT_REGMAP_IRQ(AXP152, GPIO2_INPUT, 2, 2),
340 INIT_REGMAP_IRQ(AXP152, GPIO1_INPUT, 2, 1),
341 INIT_REGMAP_IRQ(AXP152, GPIO0_INPUT, 2, 0),
342};
343
Carlo Caionecfb61a42014-05-01 14:29:27 +0200344static const struct regmap_irq axp20x_regmap_irqs[] = {
Jacob Panaf7e9062014-10-06 21:17:14 -0700345 INIT_REGMAP_IRQ(AXP20X, ACIN_OVER_V, 0, 7),
346 INIT_REGMAP_IRQ(AXP20X, ACIN_PLUGIN, 0, 6),
347 INIT_REGMAP_IRQ(AXP20X, ACIN_REMOVAL, 0, 5),
348 INIT_REGMAP_IRQ(AXP20X, VBUS_OVER_V, 0, 4),
349 INIT_REGMAP_IRQ(AXP20X, VBUS_PLUGIN, 0, 3),
350 INIT_REGMAP_IRQ(AXP20X, VBUS_REMOVAL, 0, 2),
351 INIT_REGMAP_IRQ(AXP20X, VBUS_V_LOW, 0, 1),
352 INIT_REGMAP_IRQ(AXP20X, BATT_PLUGIN, 1, 7),
353 INIT_REGMAP_IRQ(AXP20X, BATT_REMOVAL, 1, 6),
354 INIT_REGMAP_IRQ(AXP20X, BATT_ENT_ACT_MODE, 1, 5),
355 INIT_REGMAP_IRQ(AXP20X, BATT_EXIT_ACT_MODE, 1, 4),
356 INIT_REGMAP_IRQ(AXP20X, CHARG, 1, 3),
357 INIT_REGMAP_IRQ(AXP20X, CHARG_DONE, 1, 2),
358 INIT_REGMAP_IRQ(AXP20X, BATT_TEMP_HIGH, 1, 1),
359 INIT_REGMAP_IRQ(AXP20X, BATT_TEMP_LOW, 1, 0),
360 INIT_REGMAP_IRQ(AXP20X, DIE_TEMP_HIGH, 2, 7),
361 INIT_REGMAP_IRQ(AXP20X, CHARG_I_LOW, 2, 6),
362 INIT_REGMAP_IRQ(AXP20X, DCDC1_V_LONG, 2, 5),
363 INIT_REGMAP_IRQ(AXP20X, DCDC2_V_LONG, 2, 4),
364 INIT_REGMAP_IRQ(AXP20X, DCDC3_V_LONG, 2, 3),
365 INIT_REGMAP_IRQ(AXP20X, PEK_SHORT, 2, 1),
366 INIT_REGMAP_IRQ(AXP20X, PEK_LONG, 2, 0),
367 INIT_REGMAP_IRQ(AXP20X, N_OE_PWR_ON, 3, 7),
368 INIT_REGMAP_IRQ(AXP20X, N_OE_PWR_OFF, 3, 6),
369 INIT_REGMAP_IRQ(AXP20X, VBUS_VALID, 3, 5),
370 INIT_REGMAP_IRQ(AXP20X, VBUS_NOT_VALID, 3, 4),
371 INIT_REGMAP_IRQ(AXP20X, VBUS_SESS_VALID, 3, 3),
372 INIT_REGMAP_IRQ(AXP20X, VBUS_SESS_END, 3, 2),
373 INIT_REGMAP_IRQ(AXP20X, LOW_PWR_LVL1, 3, 1),
374 INIT_REGMAP_IRQ(AXP20X, LOW_PWR_LVL2, 3, 0),
375 INIT_REGMAP_IRQ(AXP20X, TIMER, 4, 7),
376 INIT_REGMAP_IRQ(AXP20X, PEK_RIS_EDGE, 4, 6),
377 INIT_REGMAP_IRQ(AXP20X, PEK_FAL_EDGE, 4, 5),
378 INIT_REGMAP_IRQ(AXP20X, GPIO3_INPUT, 4, 3),
379 INIT_REGMAP_IRQ(AXP20X, GPIO2_INPUT, 4, 2),
380 INIT_REGMAP_IRQ(AXP20X, GPIO1_INPUT, 4, 1),
381 INIT_REGMAP_IRQ(AXP20X, GPIO0_INPUT, 4, 0),
382};
383
Boris BREZILLONf05be582015-04-10 12:09:01 +0800384static const struct regmap_irq axp22x_regmap_irqs[] = {
385 INIT_REGMAP_IRQ(AXP22X, ACIN_OVER_V, 0, 7),
386 INIT_REGMAP_IRQ(AXP22X, ACIN_PLUGIN, 0, 6),
387 INIT_REGMAP_IRQ(AXP22X, ACIN_REMOVAL, 0, 5),
388 INIT_REGMAP_IRQ(AXP22X, VBUS_OVER_V, 0, 4),
389 INIT_REGMAP_IRQ(AXP22X, VBUS_PLUGIN, 0, 3),
390 INIT_REGMAP_IRQ(AXP22X, VBUS_REMOVAL, 0, 2),
391 INIT_REGMAP_IRQ(AXP22X, VBUS_V_LOW, 0, 1),
392 INIT_REGMAP_IRQ(AXP22X, BATT_PLUGIN, 1, 7),
393 INIT_REGMAP_IRQ(AXP22X, BATT_REMOVAL, 1, 6),
394 INIT_REGMAP_IRQ(AXP22X, BATT_ENT_ACT_MODE, 1, 5),
395 INIT_REGMAP_IRQ(AXP22X, BATT_EXIT_ACT_MODE, 1, 4),
396 INIT_REGMAP_IRQ(AXP22X, CHARG, 1, 3),
397 INIT_REGMAP_IRQ(AXP22X, CHARG_DONE, 1, 2),
398 INIT_REGMAP_IRQ(AXP22X, BATT_TEMP_HIGH, 1, 1),
399 INIT_REGMAP_IRQ(AXP22X, BATT_TEMP_LOW, 1, 0),
400 INIT_REGMAP_IRQ(AXP22X, DIE_TEMP_HIGH, 2, 7),
401 INIT_REGMAP_IRQ(AXP22X, PEK_SHORT, 2, 1),
402 INIT_REGMAP_IRQ(AXP22X, PEK_LONG, 2, 0),
403 INIT_REGMAP_IRQ(AXP22X, LOW_PWR_LVL1, 3, 1),
404 INIT_REGMAP_IRQ(AXP22X, LOW_PWR_LVL2, 3, 0),
405 INIT_REGMAP_IRQ(AXP22X, TIMER, 4, 7),
406 INIT_REGMAP_IRQ(AXP22X, PEK_RIS_EDGE, 4, 6),
407 INIT_REGMAP_IRQ(AXP22X, PEK_FAL_EDGE, 4, 5),
408 INIT_REGMAP_IRQ(AXP22X, GPIO1_INPUT, 4, 1),
409 INIT_REGMAP_IRQ(AXP22X, GPIO0_INPUT, 4, 0),
410};
411
Jacob Panaf7e9062014-10-06 21:17:14 -0700412/* some IRQs are compatible with axp20x models */
413static const struct regmap_irq axp288_regmap_irqs[] = {
Jacob Panff3bbc52014-11-11 11:30:09 -0800414 INIT_REGMAP_IRQ(AXP288, VBUS_FALL, 0, 2),
415 INIT_REGMAP_IRQ(AXP288, VBUS_RISE, 0, 3),
416 INIT_REGMAP_IRQ(AXP288, OV, 0, 4),
Hans de Goede8b44e672016-12-14 14:52:06 +0100417 INIT_REGMAP_IRQ(AXP288, FALLING_ALT, 0, 5),
418 INIT_REGMAP_IRQ(AXP288, RISING_ALT, 0, 6),
419 INIT_REGMAP_IRQ(AXP288, OV_ALT, 0, 7),
Jacob Panaf7e9062014-10-06 21:17:14 -0700420
Jacob Panff3bbc52014-11-11 11:30:09 -0800421 INIT_REGMAP_IRQ(AXP288, DONE, 1, 2),
422 INIT_REGMAP_IRQ(AXP288, CHARGING, 1, 3),
Jacob Panaf7e9062014-10-06 21:17:14 -0700423 INIT_REGMAP_IRQ(AXP288, SAFE_QUIT, 1, 4),
424 INIT_REGMAP_IRQ(AXP288, SAFE_ENTER, 1, 5),
Jacob Panff3bbc52014-11-11 11:30:09 -0800425 INIT_REGMAP_IRQ(AXP288, ABSENT, 1, 6),
426 INIT_REGMAP_IRQ(AXP288, APPEND, 1, 7),
Jacob Panaf7e9062014-10-06 21:17:14 -0700427
428 INIT_REGMAP_IRQ(AXP288, QWBTU, 2, 0),
429 INIT_REGMAP_IRQ(AXP288, WBTU, 2, 1),
430 INIT_REGMAP_IRQ(AXP288, QWBTO, 2, 2),
Jacob Panff3bbc52014-11-11 11:30:09 -0800431 INIT_REGMAP_IRQ(AXP288, WBTO, 2, 3),
Jacob Panaf7e9062014-10-06 21:17:14 -0700432 INIT_REGMAP_IRQ(AXP288, QCBTU, 2, 4),
433 INIT_REGMAP_IRQ(AXP288, CBTU, 2, 5),
434 INIT_REGMAP_IRQ(AXP288, QCBTO, 2, 6),
435 INIT_REGMAP_IRQ(AXP288, CBTO, 2, 7),
436
437 INIT_REGMAP_IRQ(AXP288, WL2, 3, 0),
438 INIT_REGMAP_IRQ(AXP288, WL1, 3, 1),
439 INIT_REGMAP_IRQ(AXP288, GPADC, 3, 2),
440 INIT_REGMAP_IRQ(AXP288, OT, 3, 7),
441
442 INIT_REGMAP_IRQ(AXP288, GPIO0, 4, 0),
443 INIT_REGMAP_IRQ(AXP288, GPIO1, 4, 1),
444 INIT_REGMAP_IRQ(AXP288, POKO, 4, 2),
445 INIT_REGMAP_IRQ(AXP288, POKL, 4, 3),
446 INIT_REGMAP_IRQ(AXP288, POKS, 4, 4),
447 INIT_REGMAP_IRQ(AXP288, POKN, 4, 5),
448 INIT_REGMAP_IRQ(AXP288, POKP, 4, 6),
Jacob Panff3bbc52014-11-11 11:30:09 -0800449 INIT_REGMAP_IRQ(AXP288, TIMER, 4, 7),
Jacob Panaf7e9062014-10-06 21:17:14 -0700450
451 INIT_REGMAP_IRQ(AXP288, MV_CHNG, 5, 0),
452 INIT_REGMAP_IRQ(AXP288, BC_USB_CHNG, 5, 1),
Carlo Caionecfb61a42014-05-01 14:29:27 +0200453};
454
Chen-Yu Tsai8824ee82016-08-27 15:55:38 +0800455static const struct regmap_irq axp806_regmap_irqs[] = {
456 INIT_REGMAP_IRQ(AXP806, DIE_TEMP_HIGH_LV1, 0, 0),
457 INIT_REGMAP_IRQ(AXP806, DIE_TEMP_HIGH_LV2, 0, 1),
458 INIT_REGMAP_IRQ(AXP806, DCDCA_V_LOW, 0, 3),
459 INIT_REGMAP_IRQ(AXP806, DCDCB_V_LOW, 0, 4),
460 INIT_REGMAP_IRQ(AXP806, DCDCC_V_LOW, 0, 5),
461 INIT_REGMAP_IRQ(AXP806, DCDCD_V_LOW, 0, 6),
462 INIT_REGMAP_IRQ(AXP806, DCDCE_V_LOW, 0, 7),
463 INIT_REGMAP_IRQ(AXP806, PWROK_LONG, 1, 0),
464 INIT_REGMAP_IRQ(AXP806, PWROK_SHORT, 1, 1),
465 INIT_REGMAP_IRQ(AXP806, WAKEUP, 1, 4),
466 INIT_REGMAP_IRQ(AXP806, PWROK_FALL, 1, 5),
467 INIT_REGMAP_IRQ(AXP806, PWROK_RISE, 1, 6),
468};
469
Chen-Yu Tsai20147f02016-03-29 17:22:26 +0800470static const struct regmap_irq axp809_regmap_irqs[] = {
471 INIT_REGMAP_IRQ(AXP809, ACIN_OVER_V, 0, 7),
472 INIT_REGMAP_IRQ(AXP809, ACIN_PLUGIN, 0, 6),
473 INIT_REGMAP_IRQ(AXP809, ACIN_REMOVAL, 0, 5),
474 INIT_REGMAP_IRQ(AXP809, VBUS_OVER_V, 0, 4),
475 INIT_REGMAP_IRQ(AXP809, VBUS_PLUGIN, 0, 3),
476 INIT_REGMAP_IRQ(AXP809, VBUS_REMOVAL, 0, 2),
477 INIT_REGMAP_IRQ(AXP809, VBUS_V_LOW, 0, 1),
478 INIT_REGMAP_IRQ(AXP809, BATT_PLUGIN, 1, 7),
479 INIT_REGMAP_IRQ(AXP809, BATT_REMOVAL, 1, 6),
480 INIT_REGMAP_IRQ(AXP809, BATT_ENT_ACT_MODE, 1, 5),
481 INIT_REGMAP_IRQ(AXP809, BATT_EXIT_ACT_MODE, 1, 4),
482 INIT_REGMAP_IRQ(AXP809, CHARG, 1, 3),
483 INIT_REGMAP_IRQ(AXP809, CHARG_DONE, 1, 2),
484 INIT_REGMAP_IRQ(AXP809, BATT_CHG_TEMP_HIGH, 2, 7),
485 INIT_REGMAP_IRQ(AXP809, BATT_CHG_TEMP_HIGH_END, 2, 6),
486 INIT_REGMAP_IRQ(AXP809, BATT_CHG_TEMP_LOW, 2, 5),
487 INIT_REGMAP_IRQ(AXP809, BATT_CHG_TEMP_LOW_END, 2, 4),
488 INIT_REGMAP_IRQ(AXP809, BATT_ACT_TEMP_HIGH, 2, 3),
489 INIT_REGMAP_IRQ(AXP809, BATT_ACT_TEMP_HIGH_END, 2, 2),
490 INIT_REGMAP_IRQ(AXP809, BATT_ACT_TEMP_LOW, 2, 1),
491 INIT_REGMAP_IRQ(AXP809, BATT_ACT_TEMP_LOW_END, 2, 0),
492 INIT_REGMAP_IRQ(AXP809, DIE_TEMP_HIGH, 3, 7),
493 INIT_REGMAP_IRQ(AXP809, LOW_PWR_LVL1, 3, 1),
494 INIT_REGMAP_IRQ(AXP809, LOW_PWR_LVL2, 3, 0),
495 INIT_REGMAP_IRQ(AXP809, TIMER, 4, 7),
496 INIT_REGMAP_IRQ(AXP809, PEK_RIS_EDGE, 4, 6),
497 INIT_REGMAP_IRQ(AXP809, PEK_FAL_EDGE, 4, 5),
498 INIT_REGMAP_IRQ(AXP809, PEK_SHORT, 4, 4),
499 INIT_REGMAP_IRQ(AXP809, PEK_LONG, 4, 3),
500 INIT_REGMAP_IRQ(AXP809, PEK_OVER_OFF, 4, 2),
501 INIT_REGMAP_IRQ(AXP809, GPIO1_INPUT, 4, 1),
502 INIT_REGMAP_IRQ(AXP809, GPIO0_INPUT, 4, 0),
503};
504
Michal Suchanekd8d79f82015-07-11 14:59:56 +0200505static const struct regmap_irq_chip axp152_regmap_irq_chip = {
506 .name = "axp152_irq_chip",
507 .status_base = AXP152_IRQ1_STATE,
508 .ack_base = AXP152_IRQ1_STATE,
509 .mask_base = AXP152_IRQ1_EN,
510 .mask_invert = true,
511 .init_ack_masked = true,
512 .irqs = axp152_regmap_irqs,
513 .num_irqs = ARRAY_SIZE(axp152_regmap_irqs),
514 .num_regs = 3,
515};
516
Carlo Caionecfb61a42014-05-01 14:29:27 +0200517static const struct regmap_irq_chip axp20x_regmap_irq_chip = {
518 .name = "axp20x_irq_chip",
519 .status_base = AXP20X_IRQ1_STATE,
520 .ack_base = AXP20X_IRQ1_STATE,
521 .mask_base = AXP20X_IRQ1_EN,
Carlo Caionecfb61a42014-05-01 14:29:27 +0200522 .mask_invert = true,
523 .init_ack_masked = true,
Jacob Panaf7e9062014-10-06 21:17:14 -0700524 .irqs = axp20x_regmap_irqs,
525 .num_irqs = ARRAY_SIZE(axp20x_regmap_irqs),
526 .num_regs = 5,
527
528};
529
Boris BREZILLONf05be582015-04-10 12:09:01 +0800530static const struct regmap_irq_chip axp22x_regmap_irq_chip = {
531 .name = "axp22x_irq_chip",
532 .status_base = AXP20X_IRQ1_STATE,
533 .ack_base = AXP20X_IRQ1_STATE,
534 .mask_base = AXP20X_IRQ1_EN,
535 .mask_invert = true,
536 .init_ack_masked = true,
537 .irqs = axp22x_regmap_irqs,
538 .num_irqs = ARRAY_SIZE(axp22x_regmap_irqs),
539 .num_regs = 5,
540};
541
Jacob Panaf7e9062014-10-06 21:17:14 -0700542static const struct regmap_irq_chip axp288_regmap_irq_chip = {
543 .name = "axp288_irq_chip",
544 .status_base = AXP20X_IRQ1_STATE,
545 .ack_base = AXP20X_IRQ1_STATE,
546 .mask_base = AXP20X_IRQ1_EN,
547 .mask_invert = true,
548 .init_ack_masked = true,
549 .irqs = axp288_regmap_irqs,
550 .num_irqs = ARRAY_SIZE(axp288_regmap_irqs),
551 .num_regs = 6,
552
Carlo Caionecfb61a42014-05-01 14:29:27 +0200553};
554
Chen-Yu Tsai8824ee82016-08-27 15:55:38 +0800555static const struct regmap_irq_chip axp806_regmap_irq_chip = {
556 .name = "axp806",
557 .status_base = AXP20X_IRQ1_STATE,
558 .ack_base = AXP20X_IRQ1_STATE,
559 .mask_base = AXP20X_IRQ1_EN,
560 .mask_invert = true,
561 .init_ack_masked = true,
562 .irqs = axp806_regmap_irqs,
563 .num_irqs = ARRAY_SIZE(axp806_regmap_irqs),
564 .num_regs = 2,
565};
566
Chen-Yu Tsai20147f02016-03-29 17:22:26 +0800567static const struct regmap_irq_chip axp809_regmap_irq_chip = {
568 .name = "axp809",
569 .status_base = AXP20X_IRQ1_STATE,
570 .ack_base = AXP20X_IRQ1_STATE,
571 .mask_base = AXP20X_IRQ1_EN,
572 .mask_invert = true,
573 .init_ack_masked = true,
574 .irqs = axp809_regmap_irqs,
575 .num_irqs = ARRAY_SIZE(axp809_regmap_irqs),
576 .num_regs = 5,
577};
578
Carlo Caionecfb61a42014-05-01 14:29:27 +0200579static struct mfd_cell axp20x_cells[] = {
580 {
Maxime Ripardb419c162016-07-20 16:11:37 +0200581 .name = "axp20x-gpio",
582 .of_compatible = "x-powers,axp209-gpio",
583 }, {
Hans de Goede8de4efd2015-08-08 17:58:41 +0200584 .name = "axp20x-pek",
585 .num_resources = ARRAY_SIZE(axp20x_pek_resources),
586 .resources = axp20x_pek_resources,
Carlo Caionecfb61a42014-05-01 14:29:27 +0200587 }, {
Hans de Goede8de4efd2015-08-08 17:58:41 +0200588 .name = "axp20x-regulator",
589 }, {
Michael Haascd7cf272016-05-06 07:19:49 +0200590 .name = "axp20x-ac-power-supply",
591 .of_compatible = "x-powers,axp202-ac-power-supply",
592 .num_resources = ARRAY_SIZE(axp20x_ac_power_supply_resources),
593 .resources = axp20x_ac_power_supply_resources,
594 }, {
Hans de Goede8de4efd2015-08-08 17:58:41 +0200595 .name = "axp20x-usb-power-supply",
596 .of_compatible = "x-powers,axp202-usb-power-supply",
597 .num_resources = ARRAY_SIZE(axp20x_usb_power_supply_resources),
598 .resources = axp20x_usb_power_supply_resources,
Carlo Caionecfb61a42014-05-01 14:29:27 +0200599 },
600};
601
Boris BREZILLONf05be582015-04-10 12:09:01 +0800602static struct mfd_cell axp22x_cells[] = {
603 {
604 .name = "axp20x-pek",
605 .num_resources = ARRAY_SIZE(axp22x_pek_resources),
606 .resources = axp22x_pek_resources,
Chen-Yu Tsai6d4fa892015-04-10 12:09:06 +0800607 }, {
608 .name = "axp20x-regulator",
Hans de Goedeecd98cc2016-06-02 19:18:55 +0200609 }, {
610 .name = "axp20x-usb-power-supply",
611 .of_compatible = "x-powers,axp221-usb-power-supply",
612 .num_resources = ARRAY_SIZE(axp22x_usb_power_supply_resources),
613 .resources = axp22x_usb_power_supply_resources,
Boris BREZILLONf05be582015-04-10 12:09:01 +0800614 },
615};
616
Michal Suchanekd8d79f82015-07-11 14:59:56 +0200617static struct mfd_cell axp152_cells[] = {
618 {
619 .name = "axp20x-pek",
620 .num_resources = ARRAY_SIZE(axp152_pek_resources),
621 .resources = axp152_pek_resources,
622 },
623};
624
Jacob Panaf7e9062014-10-06 21:17:14 -0700625static struct resource axp288_adc_resources[] = {
626 {
627 .name = "GPADC",
628 .start = AXP288_IRQ_GPADC,
629 .end = AXP288_IRQ_GPADC,
630 .flags = IORESOURCE_IRQ,
631 },
632};
633
Ramakrishna Pallalabdb01f72015-04-03 00:49:47 +0530634static struct resource axp288_extcon_resources[] = {
635 {
636 .start = AXP288_IRQ_VBUS_FALL,
637 .end = AXP288_IRQ_VBUS_FALL,
638 .flags = IORESOURCE_IRQ,
639 },
640 {
641 .start = AXP288_IRQ_VBUS_RISE,
642 .end = AXP288_IRQ_VBUS_RISE,
643 .flags = IORESOURCE_IRQ,
644 },
645 {
646 .start = AXP288_IRQ_MV_CHNG,
647 .end = AXP288_IRQ_MV_CHNG,
648 .flags = IORESOURCE_IRQ,
649 },
650 {
651 .start = AXP288_IRQ_BC_USB_CHNG,
652 .end = AXP288_IRQ_BC_USB_CHNG,
653 .flags = IORESOURCE_IRQ,
654 },
655};
656
Jacob Panaf7e9062014-10-06 21:17:14 -0700657static struct resource axp288_charger_resources[] = {
658 {
659 .start = AXP288_IRQ_OV,
660 .end = AXP288_IRQ_OV,
661 .flags = IORESOURCE_IRQ,
662 },
663 {
664 .start = AXP288_IRQ_DONE,
665 .end = AXP288_IRQ_DONE,
666 .flags = IORESOURCE_IRQ,
667 },
668 {
669 .start = AXP288_IRQ_CHARGING,
670 .end = AXP288_IRQ_CHARGING,
671 .flags = IORESOURCE_IRQ,
672 },
673 {
674 .start = AXP288_IRQ_SAFE_QUIT,
675 .end = AXP288_IRQ_SAFE_QUIT,
676 .flags = IORESOURCE_IRQ,
677 },
678 {
679 .start = AXP288_IRQ_SAFE_ENTER,
680 .end = AXP288_IRQ_SAFE_ENTER,
681 .flags = IORESOURCE_IRQ,
682 },
683 {
684 .start = AXP288_IRQ_QCBTU,
685 .end = AXP288_IRQ_QCBTU,
686 .flags = IORESOURCE_IRQ,
687 },
688 {
689 .start = AXP288_IRQ_CBTU,
690 .end = AXP288_IRQ_CBTU,
691 .flags = IORESOURCE_IRQ,
692 },
693 {
694 .start = AXP288_IRQ_QCBTO,
695 .end = AXP288_IRQ_QCBTO,
696 .flags = IORESOURCE_IRQ,
697 },
698 {
699 .start = AXP288_IRQ_CBTO,
700 .end = AXP288_IRQ_CBTO,
701 .flags = IORESOURCE_IRQ,
702 },
703};
704
705static struct mfd_cell axp288_cells[] = {
706 {
707 .name = "axp288_adc",
708 .num_resources = ARRAY_SIZE(axp288_adc_resources),
709 .resources = axp288_adc_resources,
710 },
711 {
Ramakrishna Pallalabdb01f72015-04-03 00:49:47 +0530712 .name = "axp288_extcon",
713 .num_resources = ARRAY_SIZE(axp288_extcon_resources),
714 .resources = axp288_extcon_resources,
715 },
716 {
Jacob Panaf7e9062014-10-06 21:17:14 -0700717 .name = "axp288_charger",
718 .num_resources = ARRAY_SIZE(axp288_charger_resources),
719 .resources = axp288_charger_resources,
720 },
721 {
Todd Brandtd63878742015-02-02 15:41:41 -0800722 .name = "axp288_fuel_gauge",
723 .num_resources = ARRAY_SIZE(axp288_fuel_gauge_resources),
724 .resources = axp288_fuel_gauge_resources,
Jacob Panaf7e9062014-10-06 21:17:14 -0700725 },
Aaron Lud8139f62014-11-24 17:24:47 +0800726 {
Borun Fue56e5ad2015-10-14 16:16:26 +0800727 .name = "axp20x-pek",
728 .num_resources = ARRAY_SIZE(axp288_power_button_resources),
729 .resources = axp288_power_button_resources,
730 },
731 {
Aaron Lud8139f62014-11-24 17:24:47 +0800732 .name = "axp288_pmic_acpi",
733 },
Jacob Panaf7e9062014-10-06 21:17:14 -0700734};
735
Chen-Yu Tsai8824ee82016-08-27 15:55:38 +0800736static struct mfd_cell axp806_cells[] = {
737 {
738 .id = 2,
739 .name = "axp20x-regulator",
740 },
741};
742
Chen-Yu Tsai20147f02016-03-29 17:22:26 +0800743static struct mfd_cell axp809_cells[] = {
744 {
745 .name = "axp20x-pek",
746 .num_resources = ARRAY_SIZE(axp809_pek_resources),
747 .resources = axp809_pek_resources,
748 }, {
Chen-Yu Tsai8824ee82016-08-27 15:55:38 +0800749 .id = 1,
Chen-Yu Tsai20147f02016-03-29 17:22:26 +0800750 .name = "axp20x-regulator",
751 },
752};
753
Carlo Caionecfb61a42014-05-01 14:29:27 +0200754static struct axp20x_dev *axp20x_pm_power_off;
755static void axp20x_power_off(void)
756{
Jacob Panaf7e9062014-10-06 21:17:14 -0700757 if (axp20x_pm_power_off->variant == AXP288_ID)
758 return;
759
Carlo Caionecfb61a42014-05-01 14:29:27 +0200760 regmap_write(axp20x_pm_power_off->regmap, AXP20X_OFF_CTRL,
761 AXP20X_OFF);
Hans de Goede179dc632016-06-05 15:50:48 +0200762
763 /* Give capacitors etc. time to drain to avoid kernel panic msg. */
764 msleep(500);
Carlo Caionecfb61a42014-05-01 14:29:27 +0200765}
766
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +0800767int axp20x_match_device(struct axp20x_dev *axp20x)
Jacob Panaf7e9062014-10-06 21:17:14 -0700768{
Chen-Yu Tsaie47a3cf2016-02-12 10:02:39 +0800769 struct device *dev = axp20x->dev;
Jacob Panaf7e9062014-10-06 21:17:14 -0700770 const struct acpi_device_id *acpi_id;
771 const struct of_device_id *of_id;
772
773 if (dev->of_node) {
Chen-Yu Tsaiaf7acc32016-02-12 10:02:40 +0800774 of_id = of_match_device(dev->driver->of_match_table, dev);
Jacob Panaf7e9062014-10-06 21:17:14 -0700775 if (!of_id) {
776 dev_err(dev, "Unable to match OF ID\n");
777 return -ENODEV;
778 }
Chen-Yu Tsai2260a452016-02-12 10:02:43 +0800779 axp20x->variant = (long)of_id->data;
Jacob Panaf7e9062014-10-06 21:17:14 -0700780 } else {
781 acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev);
782 if (!acpi_id || !acpi_id->driver_data) {
783 dev_err(dev, "Unable to match ACPI ID and data\n");
784 return -ENODEV;
785 }
Chen-Yu Tsai2260a452016-02-12 10:02:43 +0800786 axp20x->variant = (long)acpi_id->driver_data;
Jacob Panaf7e9062014-10-06 21:17:14 -0700787 }
788
789 switch (axp20x->variant) {
Michal Suchanekd8d79f82015-07-11 14:59:56 +0200790 case AXP152_ID:
791 axp20x->nr_cells = ARRAY_SIZE(axp152_cells);
792 axp20x->cells = axp152_cells;
793 axp20x->regmap_cfg = &axp152_regmap_config;
794 axp20x->regmap_irq_chip = &axp152_regmap_irq_chip;
795 break;
Jacob Panaf7e9062014-10-06 21:17:14 -0700796 case AXP202_ID:
797 case AXP209_ID:
798 axp20x->nr_cells = ARRAY_SIZE(axp20x_cells);
799 axp20x->cells = axp20x_cells;
800 axp20x->regmap_cfg = &axp20x_regmap_config;
801 axp20x->regmap_irq_chip = &axp20x_regmap_irq_chip;
802 break;
Boris BREZILLONf05be582015-04-10 12:09:01 +0800803 case AXP221_ID:
Chen-Yu Tsai02071f02016-02-12 10:02:44 +0800804 case AXP223_ID:
Boris BREZILLONf05be582015-04-10 12:09:01 +0800805 axp20x->nr_cells = ARRAY_SIZE(axp22x_cells);
806 axp20x->cells = axp22x_cells;
807 axp20x->regmap_cfg = &axp22x_regmap_config;
808 axp20x->regmap_irq_chip = &axp22x_regmap_irq_chip;
809 break;
Jacob Panaf7e9062014-10-06 21:17:14 -0700810 case AXP288_ID:
811 axp20x->cells = axp288_cells;
812 axp20x->nr_cells = ARRAY_SIZE(axp288_cells);
813 axp20x->regmap_cfg = &axp288_regmap_config;
814 axp20x->regmap_irq_chip = &axp288_regmap_irq_chip;
Hans de Goede0a5454c2016-12-14 14:52:05 +0100815 axp20x->irq_flags = IRQF_TRIGGER_LOW;
Jacob Panaf7e9062014-10-06 21:17:14 -0700816 break;
Chen-Yu Tsai8824ee82016-08-27 15:55:38 +0800817 case AXP806_ID:
818 axp20x->nr_cells = ARRAY_SIZE(axp806_cells);
819 axp20x->cells = axp806_cells;
820 axp20x->regmap_cfg = &axp806_regmap_config;
821 axp20x->regmap_irq_chip = &axp806_regmap_irq_chip;
822 break;
Chen-Yu Tsai20147f02016-03-29 17:22:26 +0800823 case AXP809_ID:
824 axp20x->nr_cells = ARRAY_SIZE(axp809_cells);
825 axp20x->cells = axp809_cells;
826 axp20x->regmap_cfg = &axp22x_regmap_config;
827 axp20x->regmap_irq_chip = &axp809_regmap_irq_chip;
828 break;
Jacob Panaf7e9062014-10-06 21:17:14 -0700829 default:
830 dev_err(dev, "unsupported AXP20X ID %lu\n", axp20x->variant);
831 return -EINVAL;
832 }
833 dev_info(dev, "AXP20x variant %s found\n",
Chen-Yu Tsai2260a452016-02-12 10:02:43 +0800834 axp20x_model_names[axp20x->variant]);
Jacob Panaf7e9062014-10-06 21:17:14 -0700835
836 return 0;
837}
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +0800838EXPORT_SYMBOL(axp20x_match_device);
Jacob Panaf7e9062014-10-06 21:17:14 -0700839
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +0800840int axp20x_device_probe(struct axp20x_dev *axp20x)
Carlo Caionecfb61a42014-05-01 14:29:27 +0200841{
Carlo Caionecfb61a42014-05-01 14:29:27 +0200842 int ret;
843
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +0800844 ret = regmap_add_irq_chip(axp20x->regmap, axp20x->irq,
Hans de Goede0a5454c2016-12-14 14:52:05 +0100845 IRQF_ONESHOT | IRQF_SHARED | axp20x->irq_flags,
846 -1, axp20x->regmap_irq_chip, &axp20x->regmap_irqc);
Carlo Caionecfb61a42014-05-01 14:29:27 +0200847 if (ret) {
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +0800848 dev_err(axp20x->dev, "failed to add irq chip: %d\n", ret);
Carlo Caionecfb61a42014-05-01 14:29:27 +0200849 return ret;
850 }
851
Jacob Panaf7e9062014-10-06 21:17:14 -0700852 ret = mfd_add_devices(axp20x->dev, -1, axp20x->cells,
Chen-Yu Tsai2260a452016-02-12 10:02:43 +0800853 axp20x->nr_cells, NULL, 0, NULL);
Carlo Caionecfb61a42014-05-01 14:29:27 +0200854
855 if (ret) {
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +0800856 dev_err(axp20x->dev, "failed to add MFD devices: %d\n", ret);
857 regmap_del_irq_chip(axp20x->irq, axp20x->regmap_irqc);
Carlo Caionecfb61a42014-05-01 14:29:27 +0200858 return ret;
859 }
860
861 if (!pm_power_off) {
862 axp20x_pm_power_off = axp20x;
863 pm_power_off = axp20x_power_off;
864 }
865
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +0800866 dev_info(axp20x->dev, "AXP20X driver loaded\n");
Carlo Caionecfb61a42014-05-01 14:29:27 +0200867
868 return 0;
869}
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +0800870EXPORT_SYMBOL(axp20x_device_probe);
Carlo Caionecfb61a42014-05-01 14:29:27 +0200871
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +0800872int axp20x_device_remove(struct axp20x_dev *axp20x)
Carlo Caionecfb61a42014-05-01 14:29:27 +0200873{
Carlo Caionecfb61a42014-05-01 14:29:27 +0200874 if (axp20x == axp20x_pm_power_off) {
875 axp20x_pm_power_off = NULL;
876 pm_power_off = NULL;
877 }
878
879 mfd_remove_devices(axp20x->dev);
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +0800880 regmap_del_irq_chip(axp20x->irq, axp20x->regmap_irqc);
Carlo Caionecfb61a42014-05-01 14:29:27 +0200881
882 return 0;
883}
Chen-Yu Tsai4fd41152016-02-12 10:02:42 +0800884EXPORT_SYMBOL(axp20x_device_remove);
Carlo Caionecfb61a42014-05-01 14:29:27 +0200885
886MODULE_DESCRIPTION("PMIC MFD core driver for AXP20X");
887MODULE_AUTHOR("Carlo Caione <carlo@caione.org>");
888MODULE_LICENSE("GPL");