1 From f05be589ff32e87821b86845625ed3d402d37dc7 Mon Sep 17 00:00:00 2001
2 From: Boris BREZILLON <boris.brezillon@free-electrons.com>
3 Date: Fri, 10 Apr 2015 12:09:01 +0800
4 Subject: [PATCH] mfd: axp20x: Add AXP22x PMIC support
6 Add support for the AXP22x PMIC devices to the existing AXP20x driver.
7 This includes the AXP221 and AXP223, which are identical except for
8 the external data bus. Only AXP221 is added for now. AXP223 will be
9 added after it's Reduced Serial Bus (RSB) interface is supported.
11 AXP22x defines a new set of registers, power supplies and regulators,
12 but most of the API is similar to the AXP20x ones.
14 A new irq chip definition is used, even though the available interrupts
15 on AXP22x is a subset of those on AXP20x. This is done so the interrupt
16 numbers match those on the datasheet.
18 This patch only enables the interrupts, system power-off function, and PEK
19 sub-device. The regulator driver must first support different variants
20 before we enable it from the mfd driver.
22 Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com>
23 [wens@csie.org: fix interrupts and move regulators to separate patch]
24 Signed-off-by: Chen-Yu Tsai <wens@csie.org>
25 Signed-off-by: Lee Jones <lee.jones@linaro.org>
27 drivers/mfd/axp20x.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++
28 include/linux/mfd/axp20x.h | 86 ++++++++++++++++++++++++++++++++++++++++
29 2 files changed, 184 insertions(+)
31 --- a/drivers/mfd/axp20x.c
32 +++ b/drivers/mfd/axp20x.c
34 static const char * const axp20x_model_names[] = {
41 @@ -54,6 +55,25 @@ static const struct regmap_access_table
42 .n_yes_ranges = ARRAY_SIZE(axp20x_volatile_ranges),
45 +static const struct regmap_range axp22x_writeable_ranges[] = {
46 + regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ5_STATE),
47 + regmap_reg_range(AXP20X_DCDC_MODE, AXP22X_BATLOW_THRES1),
50 +static const struct regmap_range axp22x_volatile_ranges[] = {
51 + regmap_reg_range(AXP20X_IRQ1_EN, AXP20X_IRQ5_STATE),
54 +static const struct regmap_access_table axp22x_writeable_table = {
55 + .yes_ranges = axp22x_writeable_ranges,
56 + .n_yes_ranges = ARRAY_SIZE(axp22x_writeable_ranges),
59 +static const struct regmap_access_table axp22x_volatile_table = {
60 + .yes_ranges = axp22x_volatile_ranges,
61 + .n_yes_ranges = ARRAY_SIZE(axp22x_volatile_ranges),
64 static const struct regmap_range axp288_writeable_ranges[] = {
65 regmap_reg_range(AXP20X_DATACACHE(0), AXP20X_IRQ6_STATE),
66 regmap_reg_range(AXP20X_DCDC_MODE, AXP288_FG_TUNE5),
67 @@ -87,6 +107,20 @@ static struct resource axp20x_pek_resour
71 +static struct resource axp22x_pek_resources[] = {
74 + .start = AXP22X_IRQ_PEK_RIS_EDGE,
75 + .end = AXP22X_IRQ_PEK_RIS_EDGE,
76 + .flags = IORESOURCE_IRQ,
79 + .start = AXP22X_IRQ_PEK_FAL_EDGE,
80 + .end = AXP22X_IRQ_PEK_FAL_EDGE,
81 + .flags = IORESOURCE_IRQ,
85 static struct resource axp288_fuel_gauge_resources[] = {
87 .start = AXP288_IRQ_QWBTU,
88 @@ -129,6 +163,15 @@ static const struct regmap_config axp20x
89 .cache_type = REGCACHE_RBTREE,
92 +static const struct regmap_config axp22x_regmap_config = {
95 + .wr_table = &axp22x_writeable_table,
96 + .volatile_table = &axp22x_volatile_table,
97 + .max_register = AXP22X_BATLOW_THRES1,
98 + .cache_type = REGCACHE_RBTREE,
101 static const struct regmap_config axp288_regmap_config = {
104 @@ -181,6 +224,34 @@ static const struct regmap_irq axp20x_re
105 INIT_REGMAP_IRQ(AXP20X, GPIO0_INPUT, 4, 0),
108 +static const struct regmap_irq axp22x_regmap_irqs[] = {
109 + INIT_REGMAP_IRQ(AXP22X, ACIN_OVER_V, 0, 7),
110 + INIT_REGMAP_IRQ(AXP22X, ACIN_PLUGIN, 0, 6),
111 + INIT_REGMAP_IRQ(AXP22X, ACIN_REMOVAL, 0, 5),
112 + INIT_REGMAP_IRQ(AXP22X, VBUS_OVER_V, 0, 4),
113 + INIT_REGMAP_IRQ(AXP22X, VBUS_PLUGIN, 0, 3),
114 + INIT_REGMAP_IRQ(AXP22X, VBUS_REMOVAL, 0, 2),
115 + INIT_REGMAP_IRQ(AXP22X, VBUS_V_LOW, 0, 1),
116 + INIT_REGMAP_IRQ(AXP22X, BATT_PLUGIN, 1, 7),
117 + INIT_REGMAP_IRQ(AXP22X, BATT_REMOVAL, 1, 6),
118 + INIT_REGMAP_IRQ(AXP22X, BATT_ENT_ACT_MODE, 1, 5),
119 + INIT_REGMAP_IRQ(AXP22X, BATT_EXIT_ACT_MODE, 1, 4),
120 + INIT_REGMAP_IRQ(AXP22X, CHARG, 1, 3),
121 + INIT_REGMAP_IRQ(AXP22X, CHARG_DONE, 1, 2),
122 + INIT_REGMAP_IRQ(AXP22X, BATT_TEMP_HIGH, 1, 1),
123 + INIT_REGMAP_IRQ(AXP22X, BATT_TEMP_LOW, 1, 0),
124 + INIT_REGMAP_IRQ(AXP22X, DIE_TEMP_HIGH, 2, 7),
125 + INIT_REGMAP_IRQ(AXP22X, PEK_SHORT, 2, 1),
126 + INIT_REGMAP_IRQ(AXP22X, PEK_LONG, 2, 0),
127 + INIT_REGMAP_IRQ(AXP22X, LOW_PWR_LVL1, 3, 1),
128 + INIT_REGMAP_IRQ(AXP22X, LOW_PWR_LVL2, 3, 0),
129 + INIT_REGMAP_IRQ(AXP22X, TIMER, 4, 7),
130 + INIT_REGMAP_IRQ(AXP22X, PEK_RIS_EDGE, 4, 6),
131 + INIT_REGMAP_IRQ(AXP22X, PEK_FAL_EDGE, 4, 5),
132 + INIT_REGMAP_IRQ(AXP22X, GPIO1_INPUT, 4, 1),
133 + INIT_REGMAP_IRQ(AXP22X, GPIO0_INPUT, 4, 0),
136 /* some IRQs are compatible with axp20x models */
137 static const struct regmap_irq axp288_regmap_irqs[] = {
138 INIT_REGMAP_IRQ(AXP288, VBUS_FALL, 0, 2),
139 @@ -224,6 +295,7 @@ static const struct regmap_irq axp288_re
140 static const struct of_device_id axp20x_of_match[] = {
141 { .compatible = "x-powers,axp202", .data = (void *) AXP202_ID },
142 { .compatible = "x-powers,axp209", .data = (void *) AXP209_ID },
143 + { .compatible = "x-powers,axp221", .data = (void *) AXP221_ID },
146 MODULE_DEVICE_TABLE(of, axp20x_of_match);
147 @@ -258,6 +330,18 @@ static const struct regmap_irq_chip axp2
151 +static const struct regmap_irq_chip axp22x_regmap_irq_chip = {
152 + .name = "axp22x_irq_chip",
153 + .status_base = AXP20X_IRQ1_STATE,
154 + .ack_base = AXP20X_IRQ1_STATE,
155 + .mask_base = AXP20X_IRQ1_EN,
156 + .mask_invert = true,
157 + .init_ack_masked = true,
158 + .irqs = axp22x_regmap_irqs,
159 + .num_irqs = ARRAY_SIZE(axp22x_regmap_irqs),
163 static const struct regmap_irq_chip axp288_regmap_irq_chip = {
164 .name = "axp288_irq_chip",
165 .status_base = AXP20X_IRQ1_STATE,
166 @@ -281,6 +365,14 @@ static struct mfd_cell axp20x_cells[] =
170 +static struct mfd_cell axp22x_cells[] = {
172 + .name = "axp20x-pek",
173 + .num_resources = ARRAY_SIZE(axp22x_pek_resources),
174 + .resources = axp22x_pek_resources,
178 static struct resource axp288_adc_resources[] = {
181 @@ -426,6 +518,12 @@ static int axp20x_match_device(struct ax
182 axp20x->regmap_cfg = &axp20x_regmap_config;
183 axp20x->regmap_irq_chip = &axp20x_regmap_irq_chip;
186 + axp20x->nr_cells = ARRAY_SIZE(axp22x_cells);
187 + axp20x->cells = axp22x_cells;
188 + axp20x->regmap_cfg = &axp22x_regmap_config;
189 + axp20x->regmap_irq_chip = &axp22x_regmap_irq_chip;
192 axp20x->cells = axp288_cells;
193 axp20x->nr_cells = ARRAY_SIZE(axp288_cells);
194 --- a/include/linux/mfd/axp20x.h
195 +++ b/include/linux/mfd/axp20x.h
204 @@ -45,6 +46,28 @@ enum {
205 #define AXP20X_V_LTF_DISCHRG 0x3c
206 #define AXP20X_V_HTF_DISCHRG 0x3d
208 +#define AXP22X_PWR_OUT_CTRL1 0x10
209 +#define AXP22X_PWR_OUT_CTRL2 0x12
210 +#define AXP22X_PWR_OUT_CTRL3 0x13
211 +#define AXP22X_DLDO1_V_OUT 0x15
212 +#define AXP22X_DLDO2_V_OUT 0x16
213 +#define AXP22X_DLDO3_V_OUT 0x17
214 +#define AXP22X_DLDO4_V_OUT 0x18
215 +#define AXP22X_ELDO1_V_OUT 0x19
216 +#define AXP22X_ELDO2_V_OUT 0x1a
217 +#define AXP22X_ELDO3_V_OUT 0x1b
218 +#define AXP22X_DC5LDO_V_OUT 0x1c
219 +#define AXP22X_DCDC1_V_OUT 0x21
220 +#define AXP22X_DCDC2_V_OUT 0x22
221 +#define AXP22X_DCDC3_V_OUT 0x23
222 +#define AXP22X_DCDC4_V_OUT 0x24
223 +#define AXP22X_DCDC5_V_OUT 0x25
224 +#define AXP22X_DCDC23_V_RAMP_CTRL 0x27
225 +#define AXP22X_ALDO1_V_OUT 0x28
226 +#define AXP22X_ALDO2_V_OUT 0x29
227 +#define AXP22X_ALDO3_V_OUT 0x2a
228 +#define AXP22X_CHRG_CTRL3 0x35
231 #define AXP20X_IRQ1_EN 0x40
232 #define AXP20X_IRQ2_EN 0x41
233 @@ -100,6 +123,9 @@ enum {
234 #define AXP20X_VBUS_MON 0x8b
235 #define AXP20X_OVER_TMP 0x8f
237 +#define AXP22X_PWREN_CTRL1 0x8c
238 +#define AXP22X_PWREN_CTRL2 0x8d
241 #define AXP20X_GPIO0_CTRL 0x90
242 #define AXP20X_LDO5_V_OUT 0x91
243 @@ -108,6 +134,11 @@ enum {
244 #define AXP20X_GPIO20_SS 0x94
245 #define AXP20X_GPIO3_CTRL 0x95
247 +#define AXP22X_LDO_IO0_V_OUT 0x91
248 +#define AXP22X_LDO_IO1_V_OUT 0x93
249 +#define AXP22X_GPIO_STATE 0x94
250 +#define AXP22X_GPIO_PULL_DOWN 0x95
253 #define AXP20X_CHRG_CC_31_24 0xb0
254 #define AXP20X_CHRG_CC_23_16 0xb1
255 @@ -120,6 +151,9 @@ enum {
256 #define AXP20X_CC_CTRL 0xb8
257 #define AXP20X_FG_RES 0xb9
259 +/* AXP22X specific registers */
260 +#define AXP22X_BATLOW_THRES1 0xe6
262 /* AXP288 specific registers */
263 #define AXP288_PMIC_ADC_H 0x56
264 #define AXP288_PMIC_ADC_L 0x57
265 @@ -158,6 +192,30 @@ enum {
295 AXP20X_IRQ_ACIN_OVER_V = 1,
296 @@ -199,6 +257,34 @@ enum {
297 AXP20X_IRQ_GPIO0_INPUT,
301 + AXP22X_IRQ_ACIN_OVER_V = 1,
302 + AXP22X_IRQ_ACIN_PLUGIN,
303 + AXP22X_IRQ_ACIN_REMOVAL,
304 + AXP22X_IRQ_VBUS_OVER_V,
305 + AXP22X_IRQ_VBUS_PLUGIN,
306 + AXP22X_IRQ_VBUS_REMOVAL,
307 + AXP22X_IRQ_VBUS_V_LOW,
308 + AXP22X_IRQ_BATT_PLUGIN,
309 + AXP22X_IRQ_BATT_REMOVAL,
310 + AXP22X_IRQ_BATT_ENT_ACT_MODE,
311 + AXP22X_IRQ_BATT_EXIT_ACT_MODE,
313 + AXP22X_IRQ_CHARG_DONE,
314 + AXP22X_IRQ_BATT_TEMP_HIGH,
315 + AXP22X_IRQ_BATT_TEMP_LOW,
316 + AXP22X_IRQ_DIE_TEMP_HIGH,
317 + AXP22X_IRQ_PEK_SHORT,
318 + AXP22X_IRQ_PEK_LONG,
319 + AXP22X_IRQ_LOW_PWR_LVL1,
320 + AXP22X_IRQ_LOW_PWR_LVL2,
322 + AXP22X_IRQ_PEK_RIS_EDGE,
323 + AXP22X_IRQ_PEK_FAL_EDGE,
324 + AXP22X_IRQ_GPIO1_INPUT,
325 + AXP22X_IRQ_GPIO0_INPUT,
329 AXP288_IRQ_VBUS_FALL = 2,
330 AXP288_IRQ_VBUS_RISE,