xref: /linux/include/linux/mfd/max14577-private.h (revision e30110e9c96f48aea01abc3e6dfadb369cbafec3)
13008ddbeSChanwoo Choi /*
2aee2a57cSKrzysztof Kozlowski  * max14577-private.h - Common API for the Maxim 14577/77836 internal sub chip
33008ddbeSChanwoo Choi  *
4aee2a57cSKrzysztof Kozlowski  * Copyright (C) 2014 Samsung Electrnoics
53008ddbeSChanwoo Choi  * Chanwoo Choi <cw00.choi@samsung.com>
63008ddbeSChanwoo Choi  * Krzysztof Kozlowski <k.kozlowski@samsung.com>
73008ddbeSChanwoo Choi  *
83008ddbeSChanwoo Choi  * This program is free software; you can redistribute it and/or modify
93008ddbeSChanwoo Choi  * it under the terms of the GNU General Public License as published by
103008ddbeSChanwoo Choi  * the Free Software Foundation; either version 2 of the License, or
113008ddbeSChanwoo Choi  * (at your option) any later version.
123008ddbeSChanwoo Choi  *
133008ddbeSChanwoo Choi  * This program is distributed in the hope that it will be useful,
143008ddbeSChanwoo Choi  * but WITHOUT ANY WARRANTY; without even the implied warranty of
153008ddbeSChanwoo Choi  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
163008ddbeSChanwoo Choi  * GNU General Public License for more details.
173008ddbeSChanwoo Choi  */
183008ddbeSChanwoo Choi 
193008ddbeSChanwoo Choi #ifndef __MAX14577_PRIVATE_H__
203008ddbeSChanwoo Choi #define __MAX14577_PRIVATE_H__
213008ddbeSChanwoo Choi 
223008ddbeSChanwoo Choi #include <linux/i2c.h>
233008ddbeSChanwoo Choi #include <linux/regmap.h>
243008ddbeSChanwoo Choi 
25aee2a57cSKrzysztof Kozlowski #define I2C_ADDR_PMIC	(0x46 >> 1)
26aee2a57cSKrzysztof Kozlowski #define I2C_ADDR_MUIC	(0x4A >> 1)
27aee2a57cSKrzysztof Kozlowski #define I2C_ADDR_FG	(0x6C >> 1)
28aee2a57cSKrzysztof Kozlowski 
29eccb80ccSKrzysztof Kozlowski enum maxim_device_type {
30eccb80ccSKrzysztof Kozlowski 	MAXIM_DEVICE_TYPE_UNKNOWN	= 0,
31eccb80ccSKrzysztof Kozlowski 	MAXIM_DEVICE_TYPE_MAX14577,
32aee2a57cSKrzysztof Kozlowski 	MAXIM_DEVICE_TYPE_MAX77836,
33eccb80ccSKrzysztof Kozlowski 
34eccb80ccSKrzysztof Kozlowski 	MAXIM_DEVICE_TYPE_NUM,
35eccb80ccSKrzysztof Kozlowski };
36eccb80ccSKrzysztof Kozlowski 
37575343d1SKrzysztof Kozlowski /* Slave addr = 0x4A: MUIC and Charger */
383008ddbeSChanwoo Choi enum max14577_reg {
393008ddbeSChanwoo Choi 	MAX14577_REG_DEVICEID		= 0x00,
403008ddbeSChanwoo Choi 	MAX14577_REG_INT1		= 0x01,
413008ddbeSChanwoo Choi 	MAX14577_REG_INT2		= 0x02,
423008ddbeSChanwoo Choi 	MAX14577_REG_INT3		= 0x03,
433008ddbeSChanwoo Choi 	MAX14577_REG_STATUS1		= 0x04,
443008ddbeSChanwoo Choi 	MAX14577_REG_STATUS2		= 0x05,
453008ddbeSChanwoo Choi 	MAX14577_REG_STATUS3		= 0x06,
463008ddbeSChanwoo Choi 	MAX14577_REG_INTMASK1		= 0x07,
473008ddbeSChanwoo Choi 	MAX14577_REG_INTMASK2		= 0x08,
483008ddbeSChanwoo Choi 	MAX14577_REG_INTMASK3		= 0x09,
493008ddbeSChanwoo Choi 	MAX14577_REG_CDETCTRL1		= 0x0A,
503008ddbeSChanwoo Choi 	MAX14577_REG_RFU		= 0x0B,
513008ddbeSChanwoo Choi 	MAX14577_REG_CONTROL1		= 0x0C,
523008ddbeSChanwoo Choi 	MAX14577_REG_CONTROL2		= 0x0D,
533008ddbeSChanwoo Choi 	MAX14577_REG_CONTROL3		= 0x0E,
543008ddbeSChanwoo Choi 	MAX14577_REG_CHGCTRL1		= 0x0F,
553008ddbeSChanwoo Choi 	MAX14577_REG_CHGCTRL2		= 0x10,
563008ddbeSChanwoo Choi 	MAX14577_REG_CHGCTRL3		= 0x11,
573008ddbeSChanwoo Choi 	MAX14577_REG_CHGCTRL4		= 0x12,
583008ddbeSChanwoo Choi 	MAX14577_REG_CHGCTRL5		= 0x13,
593008ddbeSChanwoo Choi 	MAX14577_REG_CHGCTRL6		= 0x14,
603008ddbeSChanwoo Choi 	MAX14577_REG_CHGCTRL7		= 0x15,
613008ddbeSChanwoo Choi 
623008ddbeSChanwoo Choi 	MAX14577_REG_END,
633008ddbeSChanwoo Choi };
643008ddbeSChanwoo Choi 
653008ddbeSChanwoo Choi /* Slave addr = 0x4A: MUIC */
663008ddbeSChanwoo Choi enum max14577_muic_reg {
673008ddbeSChanwoo Choi 	MAX14577_MUIC_REG_STATUS1	= 0x04,
683008ddbeSChanwoo Choi 	MAX14577_MUIC_REG_STATUS2	= 0x05,
693008ddbeSChanwoo Choi 	MAX14577_MUIC_REG_CONTROL1	= 0x0C,
703008ddbeSChanwoo Choi 	MAX14577_MUIC_REG_CONTROL3	= 0x0E,
713008ddbeSChanwoo Choi 
723008ddbeSChanwoo Choi 	MAX14577_MUIC_REG_END,
733008ddbeSChanwoo Choi };
743008ddbeSChanwoo Choi 
7525cc24c2SKrzysztof Kozlowski /*
7625cc24c2SKrzysztof Kozlowski  * Combined charger types for max14577 and max77836.
7725cc24c2SKrzysztof Kozlowski  *
7825cc24c2SKrzysztof Kozlowski  * On max14577 three lower bits map to STATUS2/CHGTYP field.
7925cc24c2SKrzysztof Kozlowski  * However the max77836 has different two last values of STATUS2/CHGTYP.
8025cc24c2SKrzysztof Kozlowski  * To indicate the difference enum has two additional values for max77836.
8125cc24c2SKrzysztof Kozlowski  * These values are just a register value bitwise OR with 0x8.
8225cc24c2SKrzysztof Kozlowski  */
833008ddbeSChanwoo Choi enum max14577_muic_charger_type {
8425cc24c2SKrzysztof Kozlowski 	MAX14577_CHARGER_TYPE_NONE		= 0x0,
8525cc24c2SKrzysztof Kozlowski 	MAX14577_CHARGER_TYPE_USB		= 0x1,
8625cc24c2SKrzysztof Kozlowski 	MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT	= 0x2,
8725cc24c2SKrzysztof Kozlowski 	MAX14577_CHARGER_TYPE_DEDICATED_CHG	= 0x3,
8825cc24c2SKrzysztof Kozlowski 	MAX14577_CHARGER_TYPE_SPECIAL_500MA	= 0x4,
8925cc24c2SKrzysztof Kozlowski 	/* Special 1A or 2A charger */
9025cc24c2SKrzysztof Kozlowski 	MAX14577_CHARGER_TYPE_SPECIAL_1A	= 0x5,
9125cc24c2SKrzysztof Kozlowski 	/* max14577: reserved, used on max77836 */
9225cc24c2SKrzysztof Kozlowski 	MAX14577_CHARGER_TYPE_RESERVED		= 0x6,
9325cc24c2SKrzysztof Kozlowski 	/* max14577: dead-battery charing with maximum current 100mA */
9425cc24c2SKrzysztof Kozlowski 	MAX14577_CHARGER_TYPE_DEAD_BATTERY	= 0x7,
9525cc24c2SKrzysztof Kozlowski 	/*
9625cc24c2SKrzysztof Kozlowski 	 * max77836: special charger (bias on D+/D-),
9725cc24c2SKrzysztof Kozlowski 	 * matches register value of 0x6
9825cc24c2SKrzysztof Kozlowski 	 */
9925cc24c2SKrzysztof Kozlowski 	MAX77836_CHARGER_TYPE_SPECIAL_BIAS	= 0xe,
10025cc24c2SKrzysztof Kozlowski 	/* max77836: reserved, register value 0x7 */
10125cc24c2SKrzysztof Kozlowski 	MAX77836_CHARGER_TYPE_RESERVED		= 0xf,
1023008ddbeSChanwoo Choi };
1033008ddbeSChanwoo Choi 
1043008ddbeSChanwoo Choi /* MAX14577 interrupts */
105c7846852SKrzysztof Kozlowski #define MAX14577_INT1_ADC_MASK		BIT(0)
106c7846852SKrzysztof Kozlowski #define MAX14577_INT1_ADCLOW_MASK	BIT(1)
107c7846852SKrzysztof Kozlowski #define MAX14577_INT1_ADCERR_MASK	BIT(2)
1084706a525SKrzysztof Kozlowski #define MAX77836_INT1_ADC1K_MASK	BIT(3)
1093008ddbeSChanwoo Choi 
110c7846852SKrzysztof Kozlowski #define MAX14577_INT2_CHGTYP_MASK	BIT(0)
111c7846852SKrzysztof Kozlowski #define MAX14577_INT2_CHGDETRUN_MASK	BIT(1)
112c7846852SKrzysztof Kozlowski #define MAX14577_INT2_DCDTMR_MASK	BIT(2)
113c7846852SKrzysztof Kozlowski #define MAX14577_INT2_DBCHG_MASK	BIT(3)
114c7846852SKrzysztof Kozlowski #define MAX14577_INT2_VBVOLT_MASK	BIT(4)
115aee2a57cSKrzysztof Kozlowski #define MAX77836_INT2_VIDRM_MASK	BIT(5)
1163008ddbeSChanwoo Choi 
117c7846852SKrzysztof Kozlowski #define MAX14577_INT3_EOC_MASK		BIT(0)
118c7846852SKrzysztof Kozlowski #define MAX14577_INT3_CGMBC_MASK	BIT(1)
119c7846852SKrzysztof Kozlowski #define MAX14577_INT3_OVP_MASK		BIT(2)
120c7846852SKrzysztof Kozlowski #define MAX14577_INT3_MBCCHGERR_MASK	BIT(3)
1213008ddbeSChanwoo Choi 
1223008ddbeSChanwoo Choi /* MAX14577 DEVICE ID register */
1233008ddbeSChanwoo Choi #define DEVID_VENDORID_SHIFT		0
1243008ddbeSChanwoo Choi #define DEVID_DEVICEID_SHIFT		3
1253008ddbeSChanwoo Choi #define DEVID_VENDORID_MASK		(0x07 << DEVID_VENDORID_SHIFT)
1263008ddbeSChanwoo Choi #define DEVID_DEVICEID_MASK		(0x1f << DEVID_DEVICEID_SHIFT)
1273008ddbeSChanwoo Choi 
1283008ddbeSChanwoo Choi /* MAX14577 STATUS1 register */
1293008ddbeSChanwoo Choi #define STATUS1_ADC_SHIFT		0
1303008ddbeSChanwoo Choi #define STATUS1_ADCLOW_SHIFT		5
1313008ddbeSChanwoo Choi #define STATUS1_ADCERR_SHIFT		6
132aee2a57cSKrzysztof Kozlowski #define MAX77836_STATUS1_ADC1K_SHIFT	7
1333008ddbeSChanwoo Choi #define STATUS1_ADC_MASK		(0x1f << STATUS1_ADC_SHIFT)
134aee2a57cSKrzysztof Kozlowski #define STATUS1_ADCLOW_MASK		BIT(STATUS1_ADCLOW_SHIFT)
135aee2a57cSKrzysztof Kozlowski #define STATUS1_ADCERR_MASK		BIT(STATUS1_ADCERR_SHIFT)
136aee2a57cSKrzysztof Kozlowski #define MAX77836_STATUS1_ADC1K_MASK	BIT(MAX77836_STATUS1_ADC1K_SHIFT)
1373008ddbeSChanwoo Choi 
1383008ddbeSChanwoo Choi /* MAX14577 STATUS2 register */
1393008ddbeSChanwoo Choi #define STATUS2_CHGTYP_SHIFT		0
1403008ddbeSChanwoo Choi #define STATUS2_CHGDETRUN_SHIFT		3
1413008ddbeSChanwoo Choi #define STATUS2_DCDTMR_SHIFT		4
14225cc24c2SKrzysztof Kozlowski #define MAX14577_STATUS2_DBCHG_SHIFT	5
14325cc24c2SKrzysztof Kozlowski #define MAX77836_STATUS2_DXOVP_SHIFT	5
1443008ddbeSChanwoo Choi #define STATUS2_VBVOLT_SHIFT		6
145aee2a57cSKrzysztof Kozlowski #define MAX77836_STATUS2_VIDRM_SHIFT	7
1463008ddbeSChanwoo Choi #define STATUS2_CHGTYP_MASK		(0x7 << STATUS2_CHGTYP_SHIFT)
147aee2a57cSKrzysztof Kozlowski #define STATUS2_CHGDETRUN_MASK		BIT(STATUS2_CHGDETRUN_SHIFT)
148aee2a57cSKrzysztof Kozlowski #define STATUS2_DCDTMR_MASK		BIT(STATUS2_DCDTMR_SHIFT)
14925cc24c2SKrzysztof Kozlowski #define MAX14577_STATUS2_DBCHG_MASK	BIT(MAX14577_STATUS2_DBCHG_SHIFT)
15025cc24c2SKrzysztof Kozlowski #define MAX77836_STATUS2_DXOVP_MASK	BIT(MAX77836_STATUS2_DXOVP_SHIFT)
151aee2a57cSKrzysztof Kozlowski #define STATUS2_VBVOLT_MASK		BIT(STATUS2_VBVOLT_SHIFT)
152aee2a57cSKrzysztof Kozlowski #define MAX77836_STATUS2_VIDRM_MASK	BIT(MAX77836_STATUS2_VIDRM_SHIFT)
1533008ddbeSChanwoo Choi 
1543008ddbeSChanwoo Choi /* MAX14577 CONTROL1 register */
1553008ddbeSChanwoo Choi #define COMN1SW_SHIFT			0
1563008ddbeSChanwoo Choi #define COMP2SW_SHIFT			3
1573008ddbeSChanwoo Choi #define MICEN_SHIFT			6
1583008ddbeSChanwoo Choi #define IDBEN_SHIFT			7
1593008ddbeSChanwoo Choi #define COMN1SW_MASK			(0x7 << COMN1SW_SHIFT)
1603008ddbeSChanwoo Choi #define COMP2SW_MASK			(0x7 << COMP2SW_SHIFT)
161aee2a57cSKrzysztof Kozlowski #define MICEN_MASK			BIT(MICEN_SHIFT)
162aee2a57cSKrzysztof Kozlowski #define IDBEN_MASK			BIT(IDBEN_SHIFT)
1633008ddbeSChanwoo Choi #define CLEAR_IDBEN_MICEN_MASK		(COMN1SW_MASK | COMP2SW_MASK)
1643008ddbeSChanwoo Choi #define CTRL1_SW_USB			((1 << COMP2SW_SHIFT) \
1653008ddbeSChanwoo Choi 						| (1 << COMN1SW_SHIFT))
1663008ddbeSChanwoo Choi #define CTRL1_SW_AUDIO			((2 << COMP2SW_SHIFT) \
1673008ddbeSChanwoo Choi 						| (2 << COMN1SW_SHIFT))
1683008ddbeSChanwoo Choi #define CTRL1_SW_UART			((3 << COMP2SW_SHIFT) \
1693008ddbeSChanwoo Choi 						| (3 << COMN1SW_SHIFT))
1703008ddbeSChanwoo Choi #define CTRL1_SW_OPEN			((0 << COMP2SW_SHIFT) \
1713008ddbeSChanwoo Choi 						| (0 << COMN1SW_SHIFT))
1723008ddbeSChanwoo Choi 
1733008ddbeSChanwoo Choi /* MAX14577 CONTROL2 register */
1743008ddbeSChanwoo Choi #define CTRL2_LOWPWR_SHIFT		(0)
1753008ddbeSChanwoo Choi #define CTRL2_ADCEN_SHIFT		(1)
1763008ddbeSChanwoo Choi #define CTRL2_CPEN_SHIFT		(2)
1773008ddbeSChanwoo Choi #define CTRL2_SFOUTASRT_SHIFT		(3)
1783008ddbeSChanwoo Choi #define CTRL2_SFOUTORD_SHIFT		(4)
1793008ddbeSChanwoo Choi #define CTRL2_ACCDET_SHIFT		(5)
1803008ddbeSChanwoo Choi #define CTRL2_USBCPINT_SHIFT		(6)
1813008ddbeSChanwoo Choi #define CTRL2_RCPS_SHIFT		(7)
182aee2a57cSKrzysztof Kozlowski #define CTRL2_LOWPWR_MASK		BIT(CTRL2_LOWPWR_SHIFT)
183aee2a57cSKrzysztof Kozlowski #define CTRL2_ADCEN_MASK		BIT(CTRL2_ADCEN_SHIFT)
184aee2a57cSKrzysztof Kozlowski #define CTRL2_CPEN_MASK			BIT(CTRL2_CPEN_SHIFT)
185aee2a57cSKrzysztof Kozlowski #define CTRL2_SFOUTASRT_MASK		BIT(CTRL2_SFOUTASRT_SHIFT)
186aee2a57cSKrzysztof Kozlowski #define CTRL2_SFOUTORD_MASK		BIT(CTRL2_SFOUTORD_SHIFT)
187aee2a57cSKrzysztof Kozlowski #define CTRL2_ACCDET_MASK		BIT(CTRL2_ACCDET_SHIFT)
188aee2a57cSKrzysztof Kozlowski #define CTRL2_USBCPINT_MASK		BIT(CTRL2_USBCPINT_SHIFT)
189aee2a57cSKrzysztof Kozlowski #define CTRL2_RCPS_MASK			BIT(CTRL2_RCPS_SHIFT)
1903008ddbeSChanwoo Choi 
1913008ddbeSChanwoo Choi #define CTRL2_CPEN1_LOWPWR0 ((1 << CTRL2_CPEN_SHIFT) | \
1923008ddbeSChanwoo Choi 				(0 << CTRL2_LOWPWR_SHIFT))
1933008ddbeSChanwoo Choi #define CTRL2_CPEN0_LOWPWR1 ((0 << CTRL2_CPEN_SHIFT) | \
1943008ddbeSChanwoo Choi 				(1 << CTRL2_LOWPWR_SHIFT))
1953008ddbeSChanwoo Choi 
1963008ddbeSChanwoo Choi /* MAX14577 CONTROL3 register */
1973008ddbeSChanwoo Choi #define CTRL3_JIGSET_SHIFT		0
1983008ddbeSChanwoo Choi #define CTRL3_BOOTSET_SHIFT		2
1993008ddbeSChanwoo Choi #define CTRL3_ADCDBSET_SHIFT		4
20025cc24c2SKrzysztof Kozlowski #define CTRL3_WBTH_SHIFT		6
2013008ddbeSChanwoo Choi #define CTRL3_JIGSET_MASK		(0x3 << CTRL3_JIGSET_SHIFT)
2023008ddbeSChanwoo Choi #define CTRL3_BOOTSET_MASK		(0x3 << CTRL3_BOOTSET_SHIFT)
2033008ddbeSChanwoo Choi #define CTRL3_ADCDBSET_MASK		(0x3 << CTRL3_ADCDBSET_SHIFT)
20425cc24c2SKrzysztof Kozlowski #define CTRL3_WBTH_MASK			(0x3 << CTRL3_WBTH_SHIFT)
2053008ddbeSChanwoo Choi 
2063008ddbeSChanwoo Choi /* Slave addr = 0x4A: Charger */
2073008ddbeSChanwoo Choi enum max14577_charger_reg {
2083008ddbeSChanwoo Choi 	MAX14577_CHG_REG_STATUS3	= 0x06,
2093008ddbeSChanwoo Choi 	MAX14577_CHG_REG_CHG_CTRL1	= 0x0F,
2103008ddbeSChanwoo Choi 	MAX14577_CHG_REG_CHG_CTRL2	= 0x10,
2113008ddbeSChanwoo Choi 	MAX14577_CHG_REG_CHG_CTRL3	= 0x11,
2123008ddbeSChanwoo Choi 	MAX14577_CHG_REG_CHG_CTRL4	= 0x12,
2133008ddbeSChanwoo Choi 	MAX14577_CHG_REG_CHG_CTRL5	= 0x13,
2143008ddbeSChanwoo Choi 	MAX14577_CHG_REG_CHG_CTRL6	= 0x14,
2153008ddbeSChanwoo Choi 	MAX14577_CHG_REG_CHG_CTRL7	= 0x15,
2163008ddbeSChanwoo Choi 
2173008ddbeSChanwoo Choi 	MAX14577_CHG_REG_END,
2183008ddbeSChanwoo Choi };
2193008ddbeSChanwoo Choi 
2203008ddbeSChanwoo Choi /* MAX14577 STATUS3 register */
2213008ddbeSChanwoo Choi #define STATUS3_EOC_SHIFT		0
2223008ddbeSChanwoo Choi #define STATUS3_CGMBC_SHIFT		1
2233008ddbeSChanwoo Choi #define STATUS3_OVP_SHIFT		2
2243008ddbeSChanwoo Choi #define STATUS3_MBCCHGERR_SHIFT		3
2253008ddbeSChanwoo Choi #define STATUS3_EOC_MASK		(0x1 << STATUS3_EOC_SHIFT)
2263008ddbeSChanwoo Choi #define STATUS3_CGMBC_MASK		(0x1 << STATUS3_CGMBC_SHIFT)
2273008ddbeSChanwoo Choi #define STATUS3_OVP_MASK		(0x1 << STATUS3_OVP_SHIFT)
2283008ddbeSChanwoo Choi #define STATUS3_MBCCHGERR_MASK		(0x1 << STATUS3_MBCCHGERR_SHIFT)
2293008ddbeSChanwoo Choi 
2303008ddbeSChanwoo Choi /* MAX14577 CDETCTRL1 register */
2313008ddbeSChanwoo Choi #define CDETCTRL1_CHGDETEN_SHIFT	0
2323008ddbeSChanwoo Choi #define CDETCTRL1_CHGTYPMAN_SHIFT	1
2333008ddbeSChanwoo Choi #define CDETCTRL1_DCDEN_SHIFT		2
2343008ddbeSChanwoo Choi #define CDETCTRL1_DCD2SCT_SHIFT		3
23525cc24c2SKrzysztof Kozlowski #define MAX14577_CDETCTRL1_DCHKTM_SHIFT	4
23625cc24c2SKrzysztof Kozlowski #define MAX77836_CDETCTRL1_CDLY_SHIFT	4
23725cc24c2SKrzysztof Kozlowski #define MAX14577_CDETCTRL1_DBEXIT_SHIFT	5
23825cc24c2SKrzysztof Kozlowski #define MAX77836_CDETCTRL1_DCDCPL_SHIFT	5
2393008ddbeSChanwoo Choi #define CDETCTRL1_DBIDLE_SHIFT		6
2403008ddbeSChanwoo Choi #define CDETCTRL1_CDPDET_SHIFT		7
241aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_CHGDETEN_MASK		BIT(CDETCTRL1_CHGDETEN_SHIFT)
242aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_CHGTYPMAN_MASK	BIT(CDETCTRL1_CHGTYPMAN_SHIFT)
243aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_DCDEN_MASK		BIT(CDETCTRL1_DCDEN_SHIFT)
244aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_DCD2SCT_MASK		BIT(CDETCTRL1_DCD2SCT_SHIFT)
24525cc24c2SKrzysztof Kozlowski #define MAX14577_CDETCTRL1_DCHKTM_MASK	BIT(MAX14577_CDETCTRL1_DCHKTM_SHIFT)
24625cc24c2SKrzysztof Kozlowski #define MAX77836_CDETCTRL1_CDDLY_MASK	BIT(MAX77836_CDETCTRL1_CDDLY_SHIFT)
24725cc24c2SKrzysztof Kozlowski #define MAX14577_CDETCTRL1_DBEXIT_MASK	BIT(MAX14577_CDETCTRL1_DBEXIT_SHIFT)
24825cc24c2SKrzysztof Kozlowski #define MAX77836_CDETCTRL1_DCDCPL_MASK	BIT(MAX77836_CDETCTRL1_DCDCPL_SHIFT)
249aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_DBIDLE_MASK		BIT(CDETCTRL1_DBIDLE_SHIFT)
250aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_CDPDET_MASK		BIT(CDETCTRL1_CDPDET_SHIFT)
2513008ddbeSChanwoo Choi 
2523008ddbeSChanwoo Choi /* MAX14577 CHGCTRL1 register */
2533008ddbeSChanwoo Choi #define CHGCTRL1_TCHW_SHIFT		4
2543008ddbeSChanwoo Choi #define CHGCTRL1_TCHW_MASK		(0x7 << CHGCTRL1_TCHW_SHIFT)
2553008ddbeSChanwoo Choi 
2563008ddbeSChanwoo Choi /* MAX14577 CHGCTRL2 register */
2573008ddbeSChanwoo Choi #define CHGCTRL2_MBCHOSTEN_SHIFT	6
258aee2a57cSKrzysztof Kozlowski #define CHGCTRL2_MBCHOSTEN_MASK		BIT(CHGCTRL2_MBCHOSTEN_SHIFT)
2593008ddbeSChanwoo Choi #define CHGCTRL2_VCHGR_RC_SHIFT		7
260aee2a57cSKrzysztof Kozlowski #define CHGCTRL2_VCHGR_RC_MASK		BIT(CHGCTRL2_VCHGR_RC_SHIFT)
2613008ddbeSChanwoo Choi 
2623008ddbeSChanwoo Choi /* MAX14577 CHGCTRL3 register */
2633008ddbeSChanwoo Choi #define CHGCTRL3_MBCCVWRC_SHIFT		0
2643008ddbeSChanwoo Choi #define CHGCTRL3_MBCCVWRC_MASK		(0xf << CHGCTRL3_MBCCVWRC_SHIFT)
2653008ddbeSChanwoo Choi 
2663008ddbeSChanwoo Choi /* MAX14577 CHGCTRL4 register */
2673008ddbeSChanwoo Choi #define CHGCTRL4_MBCICHWRCH_SHIFT	0
2683008ddbeSChanwoo Choi #define CHGCTRL4_MBCICHWRCH_MASK	(0xf << CHGCTRL4_MBCICHWRCH_SHIFT)
2693008ddbeSChanwoo Choi #define CHGCTRL4_MBCICHWRCL_SHIFT	4
270aee2a57cSKrzysztof Kozlowski #define CHGCTRL4_MBCICHWRCL_MASK	BIT(CHGCTRL4_MBCICHWRCL_SHIFT)
2713008ddbeSChanwoo Choi 
2723008ddbeSChanwoo Choi /* MAX14577 CHGCTRL5 register */
2733008ddbeSChanwoo Choi #define CHGCTRL5_EOCS_SHIFT		0
2743008ddbeSChanwoo Choi #define CHGCTRL5_EOCS_MASK		(0xf << CHGCTRL5_EOCS_SHIFT)
2753008ddbeSChanwoo Choi 
2763008ddbeSChanwoo Choi /* MAX14577 CHGCTRL6 register */
2773008ddbeSChanwoo Choi #define CHGCTRL6_AUTOSTOP_SHIFT		5
278aee2a57cSKrzysztof Kozlowski #define CHGCTRL6_AUTOSTOP_MASK		BIT(CHGCTRL6_AUTOSTOP_SHIFT)
2793008ddbeSChanwoo Choi 
2803008ddbeSChanwoo Choi /* MAX14577 CHGCTRL7 register */
2813008ddbeSChanwoo Choi #define CHGCTRL7_OTPCGHCVS_SHIFT	0
2823008ddbeSChanwoo Choi #define CHGCTRL7_OTPCGHCVS_MASK		(0x3 << CHGCTRL7_OTPCGHCVS_SHIFT)
2833008ddbeSChanwoo Choi 
284b8f139f6SKrzysztof Kozlowski /* MAX14577 charger current limits (as in CHGCTRL4 register), uA */
285b8f139f6SKrzysztof Kozlowski #define MAX14577_CHARGER_CURRENT_LIMIT_MIN		 90000U
286b8f139f6SKrzysztof Kozlowski #define MAX14577_CHARGER_CURRENT_LIMIT_HIGH_START	200000U
287b8f139f6SKrzysztof Kozlowski #define MAX14577_CHARGER_CURRENT_LIMIT_HIGH_STEP	 50000U
288b8f139f6SKrzysztof Kozlowski #define MAX14577_CHARGER_CURRENT_LIMIT_MAX		950000U
2893008ddbeSChanwoo Choi 
290b8f139f6SKrzysztof Kozlowski /* MAX77836 charger current limits (as in CHGCTRL4 register), uA */
291b8f139f6SKrzysztof Kozlowski #define MAX77836_CHARGER_CURRENT_LIMIT_MIN		 45000U
292b8f139f6SKrzysztof Kozlowski #define MAX77836_CHARGER_CURRENT_LIMIT_HIGH_START	100000U
293b8f139f6SKrzysztof Kozlowski #define MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP	 25000U
294b8f139f6SKrzysztof Kozlowski #define MAX77836_CHARGER_CURRENT_LIMIT_MAX		475000U
2958a82b408SKrzysztof Kozlowski 
296*e30110e9SKrzysztof Kozlowski /*
297*e30110e9SKrzysztof Kozlowski  * MAX14577 charger End-Of-Charge current limits
298*e30110e9SKrzysztof Kozlowski  * (as in CHGCTRL5 register), uA
299*e30110e9SKrzysztof Kozlowski  */
300*e30110e9SKrzysztof Kozlowski #define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN		50000U
301*e30110e9SKrzysztof Kozlowski #define MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP		10000U
302*e30110e9SKrzysztof Kozlowski #define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX		200000U
303*e30110e9SKrzysztof Kozlowski 
304*e30110e9SKrzysztof Kozlowski /*
305*e30110e9SKrzysztof Kozlowski  * MAX14577/MAX77836 Battery Constant Voltage
306*e30110e9SKrzysztof Kozlowski  * (as in CHGCTRL3 register), uV
307*e30110e9SKrzysztof Kozlowski  */
308*e30110e9SKrzysztof Kozlowski #define MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN		4000000U
309*e30110e9SKrzysztof Kozlowski #define MAXIM_CHARGER_CONSTANT_VOLTAGE_STEP		20000U
310*e30110e9SKrzysztof Kozlowski #define MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX		4350000U
311*e30110e9SKrzysztof Kozlowski 
312*e30110e9SKrzysztof Kozlowski /* Default value for fast charge timer, in hours */
313*e30110e9SKrzysztof Kozlowski #define MAXIM_CHARGER_FAST_CHARGE_TIMER_DEFAULT		5
314*e30110e9SKrzysztof Kozlowski 
3153008ddbeSChanwoo Choi /* MAX14577 regulator SFOUT LDO voltage, fixed, uV */
3163008ddbeSChanwoo Choi #define MAX14577_REGULATOR_SAFEOUT_VOLTAGE		4900000
3173008ddbeSChanwoo Choi 
3188a82b408SKrzysztof Kozlowski /* MAX77836 regulator LDOx voltage, uV */
3198a82b408SKrzysztof Kozlowski #define MAX77836_REGULATOR_LDO_VOLTAGE_MIN		800000
3208a82b408SKrzysztof Kozlowski #define MAX77836_REGULATOR_LDO_VOLTAGE_MAX		3950000
3218a82b408SKrzysztof Kozlowski #define MAX77836_REGULATOR_LDO_VOLTAGE_STEP		50000
3228a82b408SKrzysztof Kozlowski #define MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM	64
3238a82b408SKrzysztof Kozlowski 
324aee2a57cSKrzysztof Kozlowski /* Slave addr = 0x46: PMIC */
325aee2a57cSKrzysztof Kozlowski enum max77836_pmic_reg {
326aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_PMIC_ID		= 0x20,
327aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_PMIC_REV		= 0x21,
328aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_INTSRC		= 0x22,
329aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_INTSRC_MASK		= 0x23,
330aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_TOPSYS_INT		= 0x24,
331aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_TOPSYS_INT_MASK	= 0x26,
332aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_TOPSYS_STAT		= 0x28,
333aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_MRSTB_CNTL		= 0x2A,
334aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_LSCNFG		= 0x2B,
335aee2a57cSKrzysztof Kozlowski 
336aee2a57cSKrzysztof Kozlowski 	MAX77836_LDO_REG_CNFG1_LDO1		= 0x51,
337aee2a57cSKrzysztof Kozlowski 	MAX77836_LDO_REG_CNFG2_LDO1		= 0x52,
338aee2a57cSKrzysztof Kozlowski 	MAX77836_LDO_REG_CNFG1_LDO2		= 0x53,
339aee2a57cSKrzysztof Kozlowski 	MAX77836_LDO_REG_CNFG2_LDO2		= 0x54,
340aee2a57cSKrzysztof Kozlowski 	MAX77836_LDO_REG_CNFG_LDO_BIAS		= 0x55,
341aee2a57cSKrzysztof Kozlowski 
342aee2a57cSKrzysztof Kozlowski 	MAX77836_COMP_REG_COMP1			= 0x60,
343aee2a57cSKrzysztof Kozlowski 
344aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_END,
345aee2a57cSKrzysztof Kozlowski };
346aee2a57cSKrzysztof Kozlowski 
347aee2a57cSKrzysztof Kozlowski #define MAX77836_INTSRC_MASK_TOP_INT_SHIFT	1
348aee2a57cSKrzysztof Kozlowski #define MAX77836_INTSRC_MASK_MUIC_CHG_INT_SHIFT	3
349aee2a57cSKrzysztof Kozlowski #define MAX77836_INTSRC_MASK_TOP_INT_MASK	BIT(MAX77836_INTSRC_MASK_TOP_INT_SHIFT)
350aee2a57cSKrzysztof Kozlowski #define MAX77836_INTSRC_MASK_MUIC_CHG_INT_MASK	BIT(MAX77836_INTSRC_MASK_MUIC_CHG_INT_SHIFT)
351aee2a57cSKrzysztof Kozlowski 
352aee2a57cSKrzysztof Kozlowski /* MAX77836 PMIC interrupts */
353aee2a57cSKrzysztof Kozlowski #define MAX77836_TOPSYS_INT_T120C_SHIFT		0
354aee2a57cSKrzysztof Kozlowski #define MAX77836_TOPSYS_INT_T140C_SHIFT		1
355aee2a57cSKrzysztof Kozlowski #define MAX77836_TOPSYS_INT_T120C_MASK		BIT(MAX77836_TOPSYS_INT_T120C_SHIFT)
356aee2a57cSKrzysztof Kozlowski #define MAX77836_TOPSYS_INT_T140C_MASK		BIT(MAX77836_TOPSYS_INT_T140C_SHIFT)
357aee2a57cSKrzysztof Kozlowski 
3588a82b408SKrzysztof Kozlowski /* LDO1/LDO2 CONFIG1 register */
3598a82b408SKrzysztof Kozlowski #define MAX77836_CNFG1_LDO_PWRMD_SHIFT		6
3608a82b408SKrzysztof Kozlowski #define MAX77836_CNFG1_LDO_TV_SHIFT		0
3618a82b408SKrzysztof Kozlowski #define MAX77836_CNFG1_LDO_PWRMD_MASK		(0x3 << MAX77836_CNFG1_LDO_PWRMD_SHIFT)
3628a82b408SKrzysztof Kozlowski #define MAX77836_CNFG1_LDO_TV_MASK		(0x3f << MAX77836_CNFG1_LDO_TV_SHIFT)
3638a82b408SKrzysztof Kozlowski 
3648a82b408SKrzysztof Kozlowski /* LDO1/LDO2 CONFIG2 register */
3658a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_OVCLMPEN_SHIFT	7
3668a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_ALPMEN_SHIFT		6
3678a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_COMP_SHIFT		4
3688a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_POK_SHIFT		3
3698a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_ADE_SHIFT		1
3708a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_SS_SHIFT		0
3718a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_OVCLMPEN_MASK	BIT(MAX77836_CNFG2_LDO_OVCLMPEN_SHIFT)
3728a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_ALPMEN_MASK		BIT(MAX77836_CNFG2_LDO_ALPMEN_SHIFT)
3738a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_COMP_MASK		(0x3 << MAX77836_CNFG2_LDO_COMP_SHIFT)
3748a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_POK_MASK		BIT(MAX77836_CNFG2_LDO_POK_SHIFT)
3758a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_ADE_MASK		BIT(MAX77836_CNFG2_LDO_ADE_SHIFT)
3768a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_SS_MASK		BIT(MAX77836_CNFG2_LDO_SS_SHIFT)
3778a82b408SKrzysztof Kozlowski 
378aee2a57cSKrzysztof Kozlowski /* Slave addr = 0x6C: Fuel-Gauge/Battery */
379aee2a57cSKrzysztof Kozlowski enum max77836_fg_reg {
380aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_VCELL_MSB	= 0x02,
381aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_VCELL_LSB	= 0x03,
382aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_SOC_MSB		= 0x04,
383aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_SOC_LSB		= 0x05,
384aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_MODE_H		= 0x06,
385aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_MODE_L		= 0x07,
386aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_VERSION_MSB	= 0x08,
387aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_VERSION_LSB	= 0x09,
388aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_HIBRT_H		= 0x0A,
389aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_HIBRT_L		= 0x0B,
390aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_CONFIG_H	= 0x0C,
391aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_CONFIG_L	= 0x0D,
392aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_VALRT_MIN	= 0x14,
393aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_VALRT_MAX	= 0x15,
394aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_CRATE_MSB	= 0x16,
395aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_CRATE_LSB	= 0x17,
396aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_VRESET		= 0x18,
397aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_FGID		= 0x19,
398aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_STATUS_H	= 0x1A,
399aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_STATUS_L	= 0x1B,
400aee2a57cSKrzysztof Kozlowski 	/*
401aee2a57cSKrzysztof Kozlowski 	 * TODO: TABLE registers
402aee2a57cSKrzysztof Kozlowski 	 * TODO: CMD register
403aee2a57cSKrzysztof Kozlowski 	 */
404aee2a57cSKrzysztof Kozlowski 
405aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_END,
406aee2a57cSKrzysztof Kozlowski };
407aee2a57cSKrzysztof Kozlowski 
4083008ddbeSChanwoo Choi enum max14577_irq {
4093008ddbeSChanwoo Choi 	/* INT1 */
4103008ddbeSChanwoo Choi 	MAX14577_IRQ_INT1_ADC,
4113008ddbeSChanwoo Choi 	MAX14577_IRQ_INT1_ADCLOW,
4123008ddbeSChanwoo Choi 	MAX14577_IRQ_INT1_ADCERR,
4134706a525SKrzysztof Kozlowski 	MAX77836_IRQ_INT1_ADC1K,
4143008ddbeSChanwoo Choi 
4153008ddbeSChanwoo Choi 	/* INT2 */
4163008ddbeSChanwoo Choi 	MAX14577_IRQ_INT2_CHGTYP,
4173008ddbeSChanwoo Choi 	MAX14577_IRQ_INT2_CHGDETRUN,
4183008ddbeSChanwoo Choi 	MAX14577_IRQ_INT2_DCDTMR,
4193008ddbeSChanwoo Choi 	MAX14577_IRQ_INT2_DBCHG,
4203008ddbeSChanwoo Choi 	MAX14577_IRQ_INT2_VBVOLT,
4214706a525SKrzysztof Kozlowski 	MAX77836_IRQ_INT2_VIDRM,
4223008ddbeSChanwoo Choi 
4233008ddbeSChanwoo Choi 	/* INT3 */
4243008ddbeSChanwoo Choi 	MAX14577_IRQ_INT3_EOC,
4253008ddbeSChanwoo Choi 	MAX14577_IRQ_INT3_CGMBC,
4263008ddbeSChanwoo Choi 	MAX14577_IRQ_INT3_OVP,
4273008ddbeSChanwoo Choi 	MAX14577_IRQ_INT3_MBCCHGERR,
4283008ddbeSChanwoo Choi 
429aee2a57cSKrzysztof Kozlowski 	/* TOPSYS_INT, only MAX77836 */
430aee2a57cSKrzysztof Kozlowski 	MAX77836_IRQ_TOPSYS_T140C,
431aee2a57cSKrzysztof Kozlowski 	MAX77836_IRQ_TOPSYS_T120C,
432aee2a57cSKrzysztof Kozlowski 
4333008ddbeSChanwoo Choi 	MAX14577_IRQ_NUM,
4343008ddbeSChanwoo Choi };
4353008ddbeSChanwoo Choi 
4363008ddbeSChanwoo Choi struct max14577 {
4373008ddbeSChanwoo Choi 	struct device *dev;
4383008ddbeSChanwoo Choi 	struct i2c_client *i2c; /* Slave addr = 0x4A */
439aee2a57cSKrzysztof Kozlowski 	struct i2c_client *i2c_pmic; /* Slave addr = 0x46 */
440eccb80ccSKrzysztof Kozlowski 	enum maxim_device_type dev_type;
4413008ddbeSChanwoo Choi 
442aee2a57cSKrzysztof Kozlowski 	struct regmap *regmap; /* For MUIC and Charger */
443aee2a57cSKrzysztof Kozlowski 	struct regmap *regmap_pmic;
4443008ddbeSChanwoo Choi 
445aee2a57cSKrzysztof Kozlowski 	struct regmap_irq_chip_data *irq_data; /* For MUIC and Charger */
446aee2a57cSKrzysztof Kozlowski 	struct regmap_irq_chip_data *irq_data_pmic;
4473008ddbeSChanwoo Choi 	int irq;
4483008ddbeSChanwoo Choi };
4493008ddbeSChanwoo Choi 
4503008ddbeSChanwoo Choi /* MAX14577 shared regmap API function */
4513008ddbeSChanwoo Choi static inline int max14577_read_reg(struct regmap *map, u8 reg, u8 *dest)
4523008ddbeSChanwoo Choi {
4533008ddbeSChanwoo Choi 	unsigned int val;
4543008ddbeSChanwoo Choi 	int ret;
4553008ddbeSChanwoo Choi 
4563008ddbeSChanwoo Choi 	ret = regmap_read(map, reg, &val);
4573008ddbeSChanwoo Choi 	*dest = val;
4583008ddbeSChanwoo Choi 
4593008ddbeSChanwoo Choi 	return ret;
4603008ddbeSChanwoo Choi }
4613008ddbeSChanwoo Choi 
4623008ddbeSChanwoo Choi static inline int max14577_bulk_read(struct regmap *map, u8 reg, u8 *buf,
4633008ddbeSChanwoo Choi 		int count)
4643008ddbeSChanwoo Choi {
4653008ddbeSChanwoo Choi 	return regmap_bulk_read(map, reg, buf, count);
4663008ddbeSChanwoo Choi }
4673008ddbeSChanwoo Choi 
4683008ddbeSChanwoo Choi static inline int max14577_write_reg(struct regmap *map, u8 reg, u8 value)
4693008ddbeSChanwoo Choi {
4703008ddbeSChanwoo Choi 	return regmap_write(map, reg, value);
4713008ddbeSChanwoo Choi }
4723008ddbeSChanwoo Choi 
4733008ddbeSChanwoo Choi static inline int max14577_bulk_write(struct regmap *map, u8 reg, u8 *buf,
4743008ddbeSChanwoo Choi 		int count)
4753008ddbeSChanwoo Choi {
4763008ddbeSChanwoo Choi 	return regmap_bulk_write(map, reg, buf, count);
4773008ddbeSChanwoo Choi }
4783008ddbeSChanwoo Choi 
4793008ddbeSChanwoo Choi static inline int max14577_update_reg(struct regmap *map, u8 reg, u8 mask,
4803008ddbeSChanwoo Choi 		u8 val)
4813008ddbeSChanwoo Choi {
4823008ddbeSChanwoo Choi 	return regmap_update_bits(map, reg, mask, val);
4833008ddbeSChanwoo Choi }
4843008ddbeSChanwoo Choi 
4853008ddbeSChanwoo Choi #endif /* __MAX14577_PRIVATE_H__ */
486