2 * Functions and registers to access AXP20X power management chip.
4 * Copyright (C) 2013, Carlo Caione <carlo@caione.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 #ifndef __LINUX_MFD_AXP20X_H
12 #define __LINUX_MFD_AXP20X_H
14 #include <linux/regmap.h>
28 #define AXP20X_DATACACHE(m) (0x04 + (m))
31 #define AXP152_PWR_OP_MODE 0x01
32 #define AXP152_LDO3456_DC1234_CTRL 0x12
33 #define AXP152_ALDO_OP_MODE 0x13
34 #define AXP152_LDO0_CTRL 0x15
35 #define AXP152_DCDC2_V_OUT 0x23
36 #define AXP152_DCDC2_V_SCAL 0x25
37 #define AXP152_DCDC1_V_OUT 0x26
38 #define AXP152_DCDC3_V_OUT 0x27
39 #define AXP152_ALDO12_V_OUT 0x28
40 #define AXP152_DLDO1_V_OUT 0x29
41 #define AXP152_DLDO2_V_OUT 0x2a
42 #define AXP152_DCDC4_V_OUT 0x2b
43 #define AXP152_V_OFF 0x31
44 #define AXP152_OFF_CTRL 0x32
45 #define AXP152_PEK_KEY 0x36
46 #define AXP152_DCDC_FREQ 0x37
47 #define AXP152_DCDC_MODE 0x80
49 #define AXP20X_PWR_INPUT_STATUS 0x00
50 #define AXP20X_PWR_OP_MODE 0x01
51 #define AXP20X_USB_OTG_STATUS 0x02
52 #define AXP20X_PWR_OUT_CTRL 0x12
53 #define AXP20X_DCDC2_V_OUT 0x23
54 #define AXP20X_DCDC2_LDO3_V_SCAL 0x25
55 #define AXP20X_DCDC3_V_OUT 0x27
56 #define AXP20X_LDO24_V_OUT 0x28
57 #define AXP20X_LDO3_V_OUT 0x29
58 #define AXP20X_VBUS_IPSOUT_MGMT 0x30
59 #define AXP20X_V_OFF 0x31
60 #define AXP20X_OFF_CTRL 0x32
61 #define AXP20X_CHRG_CTRL1 0x33
62 #define AXP20X_CHRG_CTRL2 0x34
63 #define AXP20X_CHRG_BAK_CTRL 0x35
64 #define AXP20X_PEK_KEY 0x36
65 #define AXP20X_DCDC_FREQ 0x37
66 #define AXP20X_V_LTF_CHRG 0x38
67 #define AXP20X_V_HTF_CHRG 0x39
68 #define AXP20X_APS_WARN_L1 0x3a
69 #define AXP20X_APS_WARN_L2 0x3b
70 #define AXP20X_V_LTF_DISCHRG 0x3c
71 #define AXP20X_V_HTF_DISCHRG 0x3d
73 #define AXP22X_PWR_OUT_CTRL1 0x10
74 #define AXP22X_PWR_OUT_CTRL2 0x12
75 #define AXP22X_PWR_OUT_CTRL3 0x13
76 #define AXP22X_DLDO1_V_OUT 0x15
77 #define AXP22X_DLDO2_V_OUT 0x16
78 #define AXP22X_DLDO3_V_OUT 0x17
79 #define AXP22X_DLDO4_V_OUT 0x18
80 #define AXP22X_ELDO1_V_OUT 0x19
81 #define AXP22X_ELDO2_V_OUT 0x1a
82 #define AXP22X_ELDO3_V_OUT 0x1b
83 #define AXP22X_DC5LDO_V_OUT 0x1c
84 #define AXP22X_DCDC1_V_OUT 0x21
85 #define AXP22X_DCDC2_V_OUT 0x22
86 #define AXP22X_DCDC3_V_OUT 0x23
87 #define AXP22X_DCDC4_V_OUT 0x24
88 #define AXP22X_DCDC5_V_OUT 0x25
89 #define AXP22X_DCDC23_V_RAMP_CTRL 0x27
90 #define AXP22X_ALDO1_V_OUT 0x28
91 #define AXP22X_ALDO2_V_OUT 0x29
92 #define AXP22X_ALDO3_V_OUT 0x2a
93 #define AXP22X_CHRG_CTRL3 0x35
95 #define AXP806_STARTUP_SRC 0x00
96 #define AXP806_CHIP_ID 0x03
97 #define AXP806_PWR_OUT_CTRL1 0x10
98 #define AXP806_PWR_OUT_CTRL2 0x11
99 #define AXP806_DCDCA_V_CTRL 0x12
100 #define AXP806_DCDCB_V_CTRL 0x13
101 #define AXP806_DCDCC_V_CTRL 0x14
102 #define AXP806_DCDCD_V_CTRL 0x15
103 #define AXP806_DCDCE_V_CTRL 0x16
104 #define AXP806_ALDO1_V_CTRL 0x17
105 #define AXP806_ALDO2_V_CTRL 0x18
106 #define AXP806_ALDO3_V_CTRL 0x19
107 #define AXP806_DCDC_MODE_CTRL1 0x1a
108 #define AXP806_DCDC_MODE_CTRL2 0x1b
109 #define AXP806_DCDC_FREQ_CTRL 0x1c
110 #define AXP806_BLDO1_V_CTRL 0x20
111 #define AXP806_BLDO2_V_CTRL 0x21
112 #define AXP806_BLDO3_V_CTRL 0x22
113 #define AXP806_BLDO4_V_CTRL 0x23
114 #define AXP806_CLDO1_V_CTRL 0x24
115 #define AXP806_CLDO2_V_CTRL 0x25
116 #define AXP806_CLDO3_V_CTRL 0x26
117 #define AXP806_VREF_TEMP_WARN_L 0xf3
118 #define AXP806_BUS_ADDR_EXT 0xfe
119 #define AXP806_REG_ADDR_EXT 0xff
122 #define AXP152_IRQ1_EN 0x40
123 #define AXP152_IRQ2_EN 0x41
124 #define AXP152_IRQ3_EN 0x42
125 #define AXP152_IRQ1_STATE 0x48
126 #define AXP152_IRQ2_STATE 0x49
127 #define AXP152_IRQ3_STATE 0x4a
129 #define AXP20X_IRQ1_EN 0x40
130 #define AXP20X_IRQ2_EN 0x41
131 #define AXP20X_IRQ3_EN 0x42
132 #define AXP20X_IRQ4_EN 0x43
133 #define AXP20X_IRQ5_EN 0x44
134 #define AXP20X_IRQ6_EN 0x45
135 #define AXP20X_IRQ1_STATE 0x48
136 #define AXP20X_IRQ2_STATE 0x49
137 #define AXP20X_IRQ3_STATE 0x4a
138 #define AXP20X_IRQ4_STATE 0x4b
139 #define AXP20X_IRQ5_STATE 0x4c
140 #define AXP20X_IRQ6_STATE 0x4d
143 #define AXP20X_ACIN_V_ADC_H 0x56
144 #define AXP20X_ACIN_V_ADC_L 0x57
145 #define AXP20X_ACIN_I_ADC_H 0x58
146 #define AXP20X_ACIN_I_ADC_L 0x59
147 #define AXP20X_VBUS_V_ADC_H 0x5a
148 #define AXP20X_VBUS_V_ADC_L 0x5b
149 #define AXP20X_VBUS_I_ADC_H 0x5c
150 #define AXP20X_VBUS_I_ADC_L 0x5d
151 #define AXP20X_TEMP_ADC_H 0x5e
152 #define AXP20X_TEMP_ADC_L 0x5f
153 #define AXP20X_TS_IN_H 0x62
154 #define AXP20X_TS_IN_L 0x63
155 #define AXP20X_GPIO0_V_ADC_H 0x64
156 #define AXP20X_GPIO0_V_ADC_L 0x65
157 #define AXP20X_GPIO1_V_ADC_H 0x66
158 #define AXP20X_GPIO1_V_ADC_L 0x67
159 #define AXP20X_PWR_BATT_H 0x70
160 #define AXP20X_PWR_BATT_M 0x71
161 #define AXP20X_PWR_BATT_L 0x72
162 #define AXP20X_BATT_V_H 0x78
163 #define AXP20X_BATT_V_L 0x79
164 #define AXP20X_BATT_CHRG_I_H 0x7a
165 #define AXP20X_BATT_CHRG_I_L 0x7b
166 #define AXP20X_BATT_DISCHRG_I_H 0x7c
167 #define AXP20X_BATT_DISCHRG_I_L 0x7d
168 #define AXP20X_IPSOUT_V_HIGH_H 0x7e
169 #define AXP20X_IPSOUT_V_HIGH_L 0x7f
172 #define AXP20X_DCDC_MODE 0x80
173 #define AXP20X_ADC_EN1 0x82
174 #define AXP20X_ADC_EN2 0x83
175 #define AXP20X_ADC_RATE 0x84
176 #define AXP20X_GPIO10_IN_RANGE 0x85
177 #define AXP20X_GPIO1_ADC_IRQ_RIS 0x86
178 #define AXP20X_GPIO1_ADC_IRQ_FAL 0x87
179 #define AXP20X_TIMER_CTRL 0x8a
180 #define AXP20X_VBUS_MON 0x8b
181 #define AXP20X_OVER_TMP 0x8f
183 #define AXP22X_PWREN_CTRL1 0x8c
184 #define AXP22X_PWREN_CTRL2 0x8d
187 #define AXP152_GPIO0_CTRL 0x90
188 #define AXP152_GPIO1_CTRL 0x91
189 #define AXP152_GPIO2_CTRL 0x92
190 #define AXP152_GPIO3_CTRL 0x93
191 #define AXP152_LDOGPIO2_V_OUT 0x96
192 #define AXP152_GPIO_INPUT 0x97
193 #define AXP152_PWM0_FREQ_X 0x98
194 #define AXP152_PWM0_FREQ_Y 0x99
195 #define AXP152_PWM0_DUTY_CYCLE 0x9a
196 #define AXP152_PWM1_FREQ_X 0x9b
197 #define AXP152_PWM1_FREQ_Y 0x9c
198 #define AXP152_PWM1_DUTY_CYCLE 0x9d
200 #define AXP20X_GPIO0_CTRL 0x90
201 #define AXP20X_LDO5_V_OUT 0x91
202 #define AXP20X_GPIO1_CTRL 0x92
203 #define AXP20X_GPIO2_CTRL 0x93
204 #define AXP20X_GPIO20_SS 0x94
205 #define AXP20X_GPIO3_CTRL 0x95
207 #define AXP22X_LDO_IO0_V_OUT 0x91
208 #define AXP22X_LDO_IO1_V_OUT 0x93
209 #define AXP22X_GPIO_STATE 0x94
210 #define AXP22X_GPIO_PULL_DOWN 0x95
213 #define AXP20X_CHRG_CC_31_24 0xb0
214 #define AXP20X_CHRG_CC_23_16 0xb1
215 #define AXP20X_CHRG_CC_15_8 0xb2
216 #define AXP20X_CHRG_CC_7_0 0xb3
217 #define AXP20X_DISCHRG_CC_31_24 0xb4
218 #define AXP20X_DISCHRG_CC_23_16 0xb5
219 #define AXP20X_DISCHRG_CC_15_8 0xb6
220 #define AXP20X_DISCHRG_CC_7_0 0xb7
221 #define AXP20X_CC_CTRL 0xb8
222 #define AXP20X_FG_RES 0xb9
225 #define AXP20X_RDC_H 0xba
226 #define AXP20X_RDC_L 0xbb
227 #define AXP20X_OCV(m) (0xc0 + (m))
228 #define AXP20X_OCV_MAX 0xf
230 /* AXP22X specific registers */
231 #define AXP22X_PMIC_ADC_H 0x56
232 #define AXP22X_PMIC_ADC_L 0x57
233 #define AXP22X_TS_ADC_H 0x58
234 #define AXP22X_TS_ADC_L 0x59
235 #define AXP22X_BATLOW_THRES1 0xe6
237 /* AXP288 specific registers */
238 #define AXP288_PMIC_ADC_H 0x56
239 #define AXP288_PMIC_ADC_L 0x57
240 #define AXP288_ADC_TS_PIN_CTRL 0x84
241 #define AXP288_PMIC_ADC_EN 0x84
244 #define AXP288_FG_RDC1_REG 0xba
245 #define AXP288_FG_RDC0_REG 0xbb
246 #define AXP288_FG_OCVH_REG 0xbc
247 #define AXP288_FG_OCVL_REG 0xbd
248 #define AXP288_FG_OCV_CURVE_REG 0xc0
249 #define AXP288_FG_DES_CAP1_REG 0xe0
250 #define AXP288_FG_DES_CAP0_REG 0xe1
251 #define AXP288_FG_CC_MTR1_REG 0xe2
252 #define AXP288_FG_CC_MTR0_REG 0xe3
253 #define AXP288_FG_OCV_CAP_REG 0xe4
254 #define AXP288_FG_CC_CAP_REG 0xe5
255 #define AXP288_FG_LOW_CAP_REG 0xe6
256 #define AXP288_FG_TUNE0 0xe8
257 #define AXP288_FG_TUNE1 0xe9
258 #define AXP288_FG_TUNE2 0xea
259 #define AXP288_FG_TUNE3 0xeb
260 #define AXP288_FG_TUNE4 0xec
261 #define AXP288_FG_TUNE5 0xed
344 AXP152_IRQ_LDO0IN_CONNECT = 1,
345 AXP152_IRQ_LDO0IN_REMOVAL,
346 AXP152_IRQ_ALDO0IN_CONNECT,
347 AXP152_IRQ_ALDO0IN_REMOVAL,
348 AXP152_IRQ_DCDC1_V_LOW,
349 AXP152_IRQ_DCDC2_V_LOW,
350 AXP152_IRQ_DCDC3_V_LOW,
351 AXP152_IRQ_DCDC4_V_LOW,
352 AXP152_IRQ_PEK_SHORT,
355 AXP152_IRQ_PEK_RIS_EDGE,
356 AXP152_IRQ_PEK_FAL_EDGE,
357 AXP152_IRQ_GPIO3_INPUT,
358 AXP152_IRQ_GPIO2_INPUT,
359 AXP152_IRQ_GPIO1_INPUT,
360 AXP152_IRQ_GPIO0_INPUT,
364 AXP20X_IRQ_ACIN_OVER_V = 1,
365 AXP20X_IRQ_ACIN_PLUGIN,
366 AXP20X_IRQ_ACIN_REMOVAL,
367 AXP20X_IRQ_VBUS_OVER_V,
368 AXP20X_IRQ_VBUS_PLUGIN,
369 AXP20X_IRQ_VBUS_REMOVAL,
370 AXP20X_IRQ_VBUS_V_LOW,
371 AXP20X_IRQ_BATT_PLUGIN,
372 AXP20X_IRQ_BATT_REMOVAL,
373 AXP20X_IRQ_BATT_ENT_ACT_MODE,
374 AXP20X_IRQ_BATT_EXIT_ACT_MODE,
376 AXP20X_IRQ_CHARG_DONE,
377 AXP20X_IRQ_BATT_TEMP_HIGH,
378 AXP20X_IRQ_BATT_TEMP_LOW,
379 AXP20X_IRQ_DIE_TEMP_HIGH,
380 AXP20X_IRQ_CHARG_I_LOW,
381 AXP20X_IRQ_DCDC1_V_LONG,
382 AXP20X_IRQ_DCDC2_V_LONG,
383 AXP20X_IRQ_DCDC3_V_LONG,
384 AXP20X_IRQ_PEK_SHORT = 22,
386 AXP20X_IRQ_N_OE_PWR_ON,
387 AXP20X_IRQ_N_OE_PWR_OFF,
388 AXP20X_IRQ_VBUS_VALID,
389 AXP20X_IRQ_VBUS_NOT_VALID,
390 AXP20X_IRQ_VBUS_SESS_VALID,
391 AXP20X_IRQ_VBUS_SESS_END,
392 AXP20X_IRQ_LOW_PWR_LVL1,
393 AXP20X_IRQ_LOW_PWR_LVL2,
395 AXP20X_IRQ_PEK_RIS_EDGE,
396 AXP20X_IRQ_PEK_FAL_EDGE,
397 AXP20X_IRQ_GPIO3_INPUT,
398 AXP20X_IRQ_GPIO2_INPUT,
399 AXP20X_IRQ_GPIO1_INPUT,
400 AXP20X_IRQ_GPIO0_INPUT,
404 AXP22X_IRQ_ACIN_OVER_V = 1,
405 AXP22X_IRQ_ACIN_PLUGIN,
406 AXP22X_IRQ_ACIN_REMOVAL,
407 AXP22X_IRQ_VBUS_OVER_V,
408 AXP22X_IRQ_VBUS_PLUGIN,
409 AXP22X_IRQ_VBUS_REMOVAL,
410 AXP22X_IRQ_VBUS_V_LOW,
411 AXP22X_IRQ_BATT_PLUGIN,
412 AXP22X_IRQ_BATT_REMOVAL,
413 AXP22X_IRQ_BATT_ENT_ACT_MODE,
414 AXP22X_IRQ_BATT_EXIT_ACT_MODE,
416 AXP22X_IRQ_CHARG_DONE,
417 AXP22X_IRQ_BATT_TEMP_HIGH,
418 AXP22X_IRQ_BATT_TEMP_LOW,
419 AXP22X_IRQ_DIE_TEMP_HIGH,
420 AXP22X_IRQ_PEK_SHORT,
422 AXP22X_IRQ_LOW_PWR_LVL1,
423 AXP22X_IRQ_LOW_PWR_LVL2,
425 AXP22X_IRQ_PEK_RIS_EDGE,
426 AXP22X_IRQ_PEK_FAL_EDGE,
427 AXP22X_IRQ_GPIO1_INPUT,
428 AXP22X_IRQ_GPIO0_INPUT,
432 AXP288_IRQ_VBUS_FALL = 2,
433 AXP288_IRQ_VBUS_RISE,
435 AXP288_IRQ_FALLING_ALT,
436 AXP288_IRQ_RISING_ALT,
438 AXP288_IRQ_DONE = 10,
440 AXP288_IRQ_SAFE_QUIT,
441 AXP288_IRQ_SAFE_ENTER,
465 AXP288_IRQ_BC_USB_CHNG,
469 AXP806_IRQ_DIE_TEMP_HIGH_LV1,
470 AXP806_IRQ_DIE_TEMP_HIGH_LV2,
471 AXP806_IRQ_DCDCA_V_LOW,
472 AXP806_IRQ_DCDCB_V_LOW,
473 AXP806_IRQ_DCDCC_V_LOW,
474 AXP806_IRQ_DCDCD_V_LOW,
475 AXP806_IRQ_DCDCE_V_LOW,
476 AXP806_IRQ_PWROK_LONG,
477 AXP806_IRQ_PWROK_SHORT,
479 AXP806_IRQ_PWROK_FALL,
480 AXP806_IRQ_PWROK_RISE,
484 AXP809_IRQ_ACIN_OVER_V = 1,
485 AXP809_IRQ_ACIN_PLUGIN,
486 AXP809_IRQ_ACIN_REMOVAL,
487 AXP809_IRQ_VBUS_OVER_V,
488 AXP809_IRQ_VBUS_PLUGIN,
489 AXP809_IRQ_VBUS_REMOVAL,
490 AXP809_IRQ_VBUS_V_LOW,
491 AXP809_IRQ_BATT_PLUGIN,
492 AXP809_IRQ_BATT_REMOVAL,
493 AXP809_IRQ_BATT_ENT_ACT_MODE,
494 AXP809_IRQ_BATT_EXIT_ACT_MODE,
496 AXP809_IRQ_CHARG_DONE,
497 AXP809_IRQ_BATT_CHG_TEMP_HIGH,
498 AXP809_IRQ_BATT_CHG_TEMP_HIGH_END,
499 AXP809_IRQ_BATT_CHG_TEMP_LOW,
500 AXP809_IRQ_BATT_CHG_TEMP_LOW_END,
501 AXP809_IRQ_BATT_ACT_TEMP_HIGH,
502 AXP809_IRQ_BATT_ACT_TEMP_HIGH_END,
503 AXP809_IRQ_BATT_ACT_TEMP_LOW,
504 AXP809_IRQ_BATT_ACT_TEMP_LOW_END,
505 AXP809_IRQ_DIE_TEMP_HIGH,
506 AXP809_IRQ_LOW_PWR_LVL1,
507 AXP809_IRQ_LOW_PWR_LVL2,
509 AXP809_IRQ_PEK_RIS_EDGE,
510 AXP809_IRQ_PEK_FAL_EDGE,
511 AXP809_IRQ_PEK_SHORT,
513 AXP809_IRQ_PEK_OVER_OFF,
514 AXP809_IRQ_GPIO1_INPUT,
515 AXP809_IRQ_GPIO0_INPUT,
518 #define AXP288_TS_ADC_H 0x58
519 #define AXP288_TS_ADC_L 0x59
520 #define AXP288_GP_ADC_H 0x5a
521 #define AXP288_GP_ADC_L 0x5b
526 struct regmap *regmap;
527 struct regmap_irq_chip_data *regmap_irqc;
530 struct mfd_cell *cells;
531 const struct regmap_config *regmap_cfg;
532 const struct regmap_irq_chip *regmap_irq_chip;
535 #define BATTID_LEN 64
536 #define OCV_CURVE_SIZE 32
537 #define MAX_THERM_CURVE_SIZE 25
538 #define PD_DEF_MIN_TEMP 0
539 #define PD_DEF_MAX_TEMP 55
541 struct axp20x_fg_pdata {
542 char battid[BATTID_LEN + 1];
552 int ocv_curve[OCV_CURVE_SIZE];
554 int thermistor_curve[MAX_THERM_CURVE_SIZE][2];
557 struct axp288_extcon_pdata {
558 /* GPIO pin control to switch D+/D- lines b/w PMIC and SOC */
559 struct gpio_desc *gpio_mux_cntl;
562 /* generic helper function for reading 9-16 bit wide regs */
563 static inline int axp20x_read_variable_width(struct regmap *regmap,
564 unsigned int reg, unsigned int width)
566 unsigned int reg_val, result;
569 err = regmap_read(regmap, reg, ®_val);
573 result = reg_val << (width - 8);
575 err = regmap_read(regmap, reg + 1, ®_val);
585 * axp20x_match_device(): Setup axp20x variant related fields
587 * @axp20x: axp20x device to setup (.dev field must be set)
588 * @dev: device associated with this axp20x device
590 * This lets the axp20x core configure the mfd cells and register maps
593 int axp20x_match_device(struct axp20x_dev *axp20x);
596 * axp20x_device_probe(): Probe a configured axp20x device
598 * @axp20x: axp20x device to probe (must be configured)
600 * This function lets the axp20x core register the axp20x mfd devices
601 * and irqchip. The axp20x device passed in must be fully configured
602 * with axp20x_match_device, its irq set, and regmap created.
604 int axp20x_device_probe(struct axp20x_dev *axp20x);
607 * axp20x_device_probe(): Remove a axp20x device
609 * @axp20x: axp20x device to remove
611 * This tells the axp20x core to remove the associated mfd devices
613 int axp20x_device_remove(struct axp20x_dev *axp20x);
615 #endif /* __LINUX_MFD_AXP20X_H */