xref: /linux/include/linux/mfd/max14577-private.h (revision 4706a5253bcc502a5889feb98392ea7b15dd936e)
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 
753008ddbeSChanwoo Choi enum max14577_muic_charger_type {
763008ddbeSChanwoo Choi 	MAX14577_CHARGER_TYPE_NONE = 0,
773008ddbeSChanwoo Choi 	MAX14577_CHARGER_TYPE_USB,
783008ddbeSChanwoo Choi 	MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT,
793008ddbeSChanwoo Choi 	MAX14577_CHARGER_TYPE_DEDICATED_CHG,
803008ddbeSChanwoo Choi 	MAX14577_CHARGER_TYPE_SPECIAL_500MA,
813008ddbeSChanwoo Choi 	MAX14577_CHARGER_TYPE_SPECIAL_1A,
823008ddbeSChanwoo Choi 	MAX14577_CHARGER_TYPE_RESERVED,
833008ddbeSChanwoo Choi 	MAX14577_CHARGER_TYPE_DEAD_BATTERY = 7,
843008ddbeSChanwoo Choi };
853008ddbeSChanwoo Choi 
863008ddbeSChanwoo Choi /* MAX14577 interrupts */
87c7846852SKrzysztof Kozlowski #define MAX14577_INT1_ADC_MASK		BIT(0)
88c7846852SKrzysztof Kozlowski #define MAX14577_INT1_ADCLOW_MASK	BIT(1)
89c7846852SKrzysztof Kozlowski #define MAX14577_INT1_ADCERR_MASK	BIT(2)
90*4706a525SKrzysztof Kozlowski #define MAX77836_INT1_ADC1K_MASK	BIT(3)
913008ddbeSChanwoo Choi 
92c7846852SKrzysztof Kozlowski #define MAX14577_INT2_CHGTYP_MASK	BIT(0)
93c7846852SKrzysztof Kozlowski #define MAX14577_INT2_CHGDETRUN_MASK	BIT(1)
94c7846852SKrzysztof Kozlowski #define MAX14577_INT2_DCDTMR_MASK	BIT(2)
95c7846852SKrzysztof Kozlowski #define MAX14577_INT2_DBCHG_MASK	BIT(3)
96c7846852SKrzysztof Kozlowski #define MAX14577_INT2_VBVOLT_MASK	BIT(4)
97aee2a57cSKrzysztof Kozlowski #define MAX77836_INT2_VIDRM_MASK	BIT(5)
983008ddbeSChanwoo Choi 
99c7846852SKrzysztof Kozlowski #define MAX14577_INT3_EOC_MASK		BIT(0)
100c7846852SKrzysztof Kozlowski #define MAX14577_INT3_CGMBC_MASK	BIT(1)
101c7846852SKrzysztof Kozlowski #define MAX14577_INT3_OVP_MASK		BIT(2)
102c7846852SKrzysztof Kozlowski #define MAX14577_INT3_MBCCHGERR_MASK	BIT(3)
1033008ddbeSChanwoo Choi 
1043008ddbeSChanwoo Choi /* MAX14577 DEVICE ID register */
1053008ddbeSChanwoo Choi #define DEVID_VENDORID_SHIFT		0
1063008ddbeSChanwoo Choi #define DEVID_DEVICEID_SHIFT		3
1073008ddbeSChanwoo Choi #define DEVID_VENDORID_MASK		(0x07 << DEVID_VENDORID_SHIFT)
1083008ddbeSChanwoo Choi #define DEVID_DEVICEID_MASK		(0x1f << DEVID_DEVICEID_SHIFT)
1093008ddbeSChanwoo Choi 
1103008ddbeSChanwoo Choi /* MAX14577 STATUS1 register */
1113008ddbeSChanwoo Choi #define STATUS1_ADC_SHIFT		0
1123008ddbeSChanwoo Choi #define STATUS1_ADCLOW_SHIFT		5
1133008ddbeSChanwoo Choi #define STATUS1_ADCERR_SHIFT		6
114aee2a57cSKrzysztof Kozlowski #define MAX77836_STATUS1_ADC1K_SHIFT	7
1153008ddbeSChanwoo Choi #define STATUS1_ADC_MASK		(0x1f << STATUS1_ADC_SHIFT)
116aee2a57cSKrzysztof Kozlowski #define STATUS1_ADCLOW_MASK		BIT(STATUS1_ADCLOW_SHIFT)
117aee2a57cSKrzysztof Kozlowski #define STATUS1_ADCERR_MASK		BIT(STATUS1_ADCERR_SHIFT)
118aee2a57cSKrzysztof Kozlowski #define MAX77836_STATUS1_ADC1K_MASK	BIT(MAX77836_STATUS1_ADC1K_SHIFT)
1193008ddbeSChanwoo Choi 
1203008ddbeSChanwoo Choi /* MAX14577 STATUS2 register */
1213008ddbeSChanwoo Choi #define STATUS2_CHGTYP_SHIFT		0
1223008ddbeSChanwoo Choi #define STATUS2_CHGDETRUN_SHIFT		3
1233008ddbeSChanwoo Choi #define STATUS2_DCDTMR_SHIFT		4
1243008ddbeSChanwoo Choi #define STATUS2_DBCHG_SHIFT		5
1253008ddbeSChanwoo Choi #define STATUS2_VBVOLT_SHIFT		6
126aee2a57cSKrzysztof Kozlowski #define MAX77836_STATUS2_VIDRM_SHIFT	7
1273008ddbeSChanwoo Choi #define STATUS2_CHGTYP_MASK		(0x7 << STATUS2_CHGTYP_SHIFT)
128aee2a57cSKrzysztof Kozlowski #define STATUS2_CHGDETRUN_MASK		BIT(STATUS2_CHGDETRUN_SHIFT)
129aee2a57cSKrzysztof Kozlowski #define STATUS2_DCDTMR_MASK		BIT(STATUS2_DCDTMR_SHIFT)
130aee2a57cSKrzysztof Kozlowski #define STATUS2_DBCHG_MASK		BIT(STATUS2_DBCHG_SHIFT)
131aee2a57cSKrzysztof Kozlowski #define STATUS2_VBVOLT_MASK		BIT(STATUS2_VBVOLT_SHIFT)
132aee2a57cSKrzysztof Kozlowski #define MAX77836_STATUS2_VIDRM_MASK	BIT(MAX77836_STATUS2_VIDRM_SHIFT)
1333008ddbeSChanwoo Choi 
1343008ddbeSChanwoo Choi /* MAX14577 CONTROL1 register */
1353008ddbeSChanwoo Choi #define COMN1SW_SHIFT			0
1363008ddbeSChanwoo Choi #define COMP2SW_SHIFT			3
1373008ddbeSChanwoo Choi #define MICEN_SHIFT			6
1383008ddbeSChanwoo Choi #define IDBEN_SHIFT			7
1393008ddbeSChanwoo Choi #define COMN1SW_MASK			(0x7 << COMN1SW_SHIFT)
1403008ddbeSChanwoo Choi #define COMP2SW_MASK			(0x7 << COMP2SW_SHIFT)
141aee2a57cSKrzysztof Kozlowski #define MICEN_MASK			BIT(MICEN_SHIFT)
142aee2a57cSKrzysztof Kozlowski #define IDBEN_MASK			BIT(IDBEN_SHIFT)
1433008ddbeSChanwoo Choi #define CLEAR_IDBEN_MICEN_MASK		(COMN1SW_MASK | COMP2SW_MASK)
1443008ddbeSChanwoo Choi #define CTRL1_SW_USB			((1 << COMP2SW_SHIFT) \
1453008ddbeSChanwoo Choi 						| (1 << COMN1SW_SHIFT))
1463008ddbeSChanwoo Choi #define CTRL1_SW_AUDIO			((2 << COMP2SW_SHIFT) \
1473008ddbeSChanwoo Choi 						| (2 << COMN1SW_SHIFT))
1483008ddbeSChanwoo Choi #define CTRL1_SW_UART			((3 << COMP2SW_SHIFT) \
1493008ddbeSChanwoo Choi 						| (3 << COMN1SW_SHIFT))
1503008ddbeSChanwoo Choi #define CTRL1_SW_OPEN			((0 << COMP2SW_SHIFT) \
1513008ddbeSChanwoo Choi 						| (0 << COMN1SW_SHIFT))
1523008ddbeSChanwoo Choi 
1533008ddbeSChanwoo Choi /* MAX14577 CONTROL2 register */
1543008ddbeSChanwoo Choi #define CTRL2_LOWPWR_SHIFT		(0)
1553008ddbeSChanwoo Choi #define CTRL2_ADCEN_SHIFT		(1)
1563008ddbeSChanwoo Choi #define CTRL2_CPEN_SHIFT		(2)
1573008ddbeSChanwoo Choi #define CTRL2_SFOUTASRT_SHIFT		(3)
1583008ddbeSChanwoo Choi #define CTRL2_SFOUTORD_SHIFT		(4)
1593008ddbeSChanwoo Choi #define CTRL2_ACCDET_SHIFT		(5)
1603008ddbeSChanwoo Choi #define CTRL2_USBCPINT_SHIFT		(6)
1613008ddbeSChanwoo Choi #define CTRL2_RCPS_SHIFT		(7)
162aee2a57cSKrzysztof Kozlowski #define CTRL2_LOWPWR_MASK		BIT(CTRL2_LOWPWR_SHIFT)
163aee2a57cSKrzysztof Kozlowski #define CTRL2_ADCEN_MASK		BIT(CTRL2_ADCEN_SHIFT)
164aee2a57cSKrzysztof Kozlowski #define CTRL2_CPEN_MASK			BIT(CTRL2_CPEN_SHIFT)
165aee2a57cSKrzysztof Kozlowski #define CTRL2_SFOUTASRT_MASK		BIT(CTRL2_SFOUTASRT_SHIFT)
166aee2a57cSKrzysztof Kozlowski #define CTRL2_SFOUTORD_MASK		BIT(CTRL2_SFOUTORD_SHIFT)
167aee2a57cSKrzysztof Kozlowski #define CTRL2_ACCDET_MASK		BIT(CTRL2_ACCDET_SHIFT)
168aee2a57cSKrzysztof Kozlowski #define CTRL2_USBCPINT_MASK		BIT(CTRL2_USBCPINT_SHIFT)
169aee2a57cSKrzysztof Kozlowski #define CTRL2_RCPS_MASK			BIT(CTRL2_RCPS_SHIFT)
1703008ddbeSChanwoo Choi 
1713008ddbeSChanwoo Choi #define CTRL2_CPEN1_LOWPWR0 ((1 << CTRL2_CPEN_SHIFT) | \
1723008ddbeSChanwoo Choi 				(0 << CTRL2_LOWPWR_SHIFT))
1733008ddbeSChanwoo Choi #define CTRL2_CPEN0_LOWPWR1 ((0 << CTRL2_CPEN_SHIFT) | \
1743008ddbeSChanwoo Choi 				(1 << CTRL2_LOWPWR_SHIFT))
1753008ddbeSChanwoo Choi 
1763008ddbeSChanwoo Choi /* MAX14577 CONTROL3 register */
1773008ddbeSChanwoo Choi #define CTRL3_JIGSET_SHIFT		0
1783008ddbeSChanwoo Choi #define CTRL3_BOOTSET_SHIFT		2
1793008ddbeSChanwoo Choi #define CTRL3_ADCDBSET_SHIFT		4
1803008ddbeSChanwoo Choi #define CTRL3_JIGSET_MASK		(0x3 << CTRL3_JIGSET_SHIFT)
1813008ddbeSChanwoo Choi #define CTRL3_BOOTSET_MASK		(0x3 << CTRL3_BOOTSET_SHIFT)
1823008ddbeSChanwoo Choi #define CTRL3_ADCDBSET_MASK		(0x3 << CTRL3_ADCDBSET_SHIFT)
1833008ddbeSChanwoo Choi 
1843008ddbeSChanwoo Choi /* Slave addr = 0x4A: Charger */
1853008ddbeSChanwoo Choi enum max14577_charger_reg {
1863008ddbeSChanwoo Choi 	MAX14577_CHG_REG_STATUS3	= 0x06,
1873008ddbeSChanwoo Choi 	MAX14577_CHG_REG_CHG_CTRL1	= 0x0F,
1883008ddbeSChanwoo Choi 	MAX14577_CHG_REG_CHG_CTRL2	= 0x10,
1893008ddbeSChanwoo Choi 	MAX14577_CHG_REG_CHG_CTRL3	= 0x11,
1903008ddbeSChanwoo Choi 	MAX14577_CHG_REG_CHG_CTRL4	= 0x12,
1913008ddbeSChanwoo Choi 	MAX14577_CHG_REG_CHG_CTRL5	= 0x13,
1923008ddbeSChanwoo Choi 	MAX14577_CHG_REG_CHG_CTRL6	= 0x14,
1933008ddbeSChanwoo Choi 	MAX14577_CHG_REG_CHG_CTRL7	= 0x15,
1943008ddbeSChanwoo Choi 
1953008ddbeSChanwoo Choi 	MAX14577_CHG_REG_END,
1963008ddbeSChanwoo Choi };
1973008ddbeSChanwoo Choi 
1983008ddbeSChanwoo Choi /* MAX14577 STATUS3 register */
1993008ddbeSChanwoo Choi #define STATUS3_EOC_SHIFT		0
2003008ddbeSChanwoo Choi #define STATUS3_CGMBC_SHIFT		1
2013008ddbeSChanwoo Choi #define STATUS3_OVP_SHIFT		2
2023008ddbeSChanwoo Choi #define STATUS3_MBCCHGERR_SHIFT		3
2033008ddbeSChanwoo Choi #define STATUS3_EOC_MASK		(0x1 << STATUS3_EOC_SHIFT)
2043008ddbeSChanwoo Choi #define STATUS3_CGMBC_MASK		(0x1 << STATUS3_CGMBC_SHIFT)
2053008ddbeSChanwoo Choi #define STATUS3_OVP_MASK		(0x1 << STATUS3_OVP_SHIFT)
2063008ddbeSChanwoo Choi #define STATUS3_MBCCHGERR_MASK		(0x1 << STATUS3_MBCCHGERR_SHIFT)
2073008ddbeSChanwoo Choi 
2083008ddbeSChanwoo Choi /* MAX14577 CDETCTRL1 register */
2093008ddbeSChanwoo Choi #define CDETCTRL1_CHGDETEN_SHIFT	0
2103008ddbeSChanwoo Choi #define CDETCTRL1_CHGTYPMAN_SHIFT	1
2113008ddbeSChanwoo Choi #define CDETCTRL1_DCDEN_SHIFT		2
2123008ddbeSChanwoo Choi #define CDETCTRL1_DCD2SCT_SHIFT		3
2133008ddbeSChanwoo Choi #define CDETCTRL1_DCHKTM_SHIFT		4
2143008ddbeSChanwoo Choi #define CDETCTRL1_DBEXIT_SHIFT		5
2153008ddbeSChanwoo Choi #define CDETCTRL1_DBIDLE_SHIFT		6
2163008ddbeSChanwoo Choi #define CDETCTRL1_CDPDET_SHIFT		7
217aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_CHGDETEN_MASK		BIT(CDETCTRL1_CHGDETEN_SHIFT)
218aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_CHGTYPMAN_MASK	BIT(CDETCTRL1_CHGTYPMAN_SHIFT)
219aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_DCDEN_MASK		BIT(CDETCTRL1_DCDEN_SHIFT)
220aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_DCD2SCT_MASK		BIT(CDETCTRL1_DCD2SCT_SHIFT)
221aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_DCHKTM_MASK		BIT(CDETCTRL1_DCHKTM_SHIFT)
222aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_DBEXIT_MASK		BIT(CDETCTRL1_DBEXIT_SHIFT)
223aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_DBIDLE_MASK		BIT(CDETCTRL1_DBIDLE_SHIFT)
224aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_CDPDET_MASK		BIT(CDETCTRL1_CDPDET_SHIFT)
2253008ddbeSChanwoo Choi 
2263008ddbeSChanwoo Choi /* MAX14577 CHGCTRL1 register */
2273008ddbeSChanwoo Choi #define CHGCTRL1_TCHW_SHIFT		4
2283008ddbeSChanwoo Choi #define CHGCTRL1_TCHW_MASK		(0x7 << CHGCTRL1_TCHW_SHIFT)
2293008ddbeSChanwoo Choi 
2303008ddbeSChanwoo Choi /* MAX14577 CHGCTRL2 register */
2313008ddbeSChanwoo Choi #define CHGCTRL2_MBCHOSTEN_SHIFT	6
232aee2a57cSKrzysztof Kozlowski #define CHGCTRL2_MBCHOSTEN_MASK		BIT(CHGCTRL2_MBCHOSTEN_SHIFT)
2333008ddbeSChanwoo Choi #define CHGCTRL2_VCHGR_RC_SHIFT		7
234aee2a57cSKrzysztof Kozlowski #define CHGCTRL2_VCHGR_RC_MASK		BIT(CHGCTRL2_VCHGR_RC_SHIFT)
2353008ddbeSChanwoo Choi 
2363008ddbeSChanwoo Choi /* MAX14577 CHGCTRL3 register */
2373008ddbeSChanwoo Choi #define CHGCTRL3_MBCCVWRC_SHIFT		0
2383008ddbeSChanwoo Choi #define CHGCTRL3_MBCCVWRC_MASK		(0xf << CHGCTRL3_MBCCVWRC_SHIFT)
2393008ddbeSChanwoo Choi 
2403008ddbeSChanwoo Choi /* MAX14577 CHGCTRL4 register */
2413008ddbeSChanwoo Choi #define CHGCTRL4_MBCICHWRCH_SHIFT	0
2423008ddbeSChanwoo Choi #define CHGCTRL4_MBCICHWRCH_MASK	(0xf << CHGCTRL4_MBCICHWRCH_SHIFT)
2433008ddbeSChanwoo Choi #define CHGCTRL4_MBCICHWRCL_SHIFT	4
244aee2a57cSKrzysztof Kozlowski #define CHGCTRL4_MBCICHWRCL_MASK	BIT(CHGCTRL4_MBCICHWRCL_SHIFT)
2453008ddbeSChanwoo Choi 
2463008ddbeSChanwoo Choi /* MAX14577 CHGCTRL5 register */
2473008ddbeSChanwoo Choi #define CHGCTRL5_EOCS_SHIFT		0
2483008ddbeSChanwoo Choi #define CHGCTRL5_EOCS_MASK		(0xf << CHGCTRL5_EOCS_SHIFT)
2493008ddbeSChanwoo Choi 
2503008ddbeSChanwoo Choi /* MAX14577 CHGCTRL6 register */
2513008ddbeSChanwoo Choi #define CHGCTRL6_AUTOSTOP_SHIFT		5
252aee2a57cSKrzysztof Kozlowski #define CHGCTRL6_AUTOSTOP_MASK		BIT(CHGCTRL6_AUTOSTOP_SHIFT)
2533008ddbeSChanwoo Choi 
2543008ddbeSChanwoo Choi /* MAX14577 CHGCTRL7 register */
2553008ddbeSChanwoo Choi #define CHGCTRL7_OTPCGHCVS_SHIFT	0
2563008ddbeSChanwoo Choi #define CHGCTRL7_OTPCGHCVS_MASK		(0x3 << CHGCTRL7_OTPCGHCVS_SHIFT)
2573008ddbeSChanwoo Choi 
2583008ddbeSChanwoo Choi /* MAX14577 regulator current limits (as in CHGCTRL4 register), uA */
2593008ddbeSChanwoo Choi #define MAX14577_REGULATOR_CURRENT_LIMIT_MIN		 90000
2603008ddbeSChanwoo Choi #define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_START	200000
2613008ddbeSChanwoo Choi #define MAX14577_REGULATOR_CURRENT_LIMIT_HIGH_STEP	 50000
2623008ddbeSChanwoo Choi #define MAX14577_REGULATOR_CURRENT_LIMIT_MAX		950000
2633008ddbeSChanwoo Choi 
2643008ddbeSChanwoo Choi /* MAX14577 regulator SFOUT LDO voltage, fixed, uV */
2653008ddbeSChanwoo Choi #define MAX14577_REGULATOR_SAFEOUT_VOLTAGE		4900000
2663008ddbeSChanwoo Choi 
267aee2a57cSKrzysztof Kozlowski /* Slave addr = 0x46: PMIC */
268aee2a57cSKrzysztof Kozlowski enum max77836_pmic_reg {
269aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_PMIC_ID		= 0x20,
270aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_PMIC_REV		= 0x21,
271aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_INTSRC		= 0x22,
272aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_INTSRC_MASK		= 0x23,
273aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_TOPSYS_INT		= 0x24,
274aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_TOPSYS_INT_MASK	= 0x26,
275aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_TOPSYS_STAT		= 0x28,
276aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_MRSTB_CNTL		= 0x2A,
277aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_LSCNFG		= 0x2B,
278aee2a57cSKrzysztof Kozlowski 
279aee2a57cSKrzysztof Kozlowski 	MAX77836_LDO_REG_CNFG1_LDO1		= 0x51,
280aee2a57cSKrzysztof Kozlowski 	MAX77836_LDO_REG_CNFG2_LDO1		= 0x52,
281aee2a57cSKrzysztof Kozlowski 	MAX77836_LDO_REG_CNFG1_LDO2		= 0x53,
282aee2a57cSKrzysztof Kozlowski 	MAX77836_LDO_REG_CNFG2_LDO2		= 0x54,
283aee2a57cSKrzysztof Kozlowski 	MAX77836_LDO_REG_CNFG_LDO_BIAS		= 0x55,
284aee2a57cSKrzysztof Kozlowski 
285aee2a57cSKrzysztof Kozlowski 	MAX77836_COMP_REG_COMP1			= 0x60,
286aee2a57cSKrzysztof Kozlowski 
287aee2a57cSKrzysztof Kozlowski 	MAX77836_PMIC_REG_END,
288aee2a57cSKrzysztof Kozlowski };
289aee2a57cSKrzysztof Kozlowski 
290aee2a57cSKrzysztof Kozlowski #define MAX77836_INTSRC_MASK_TOP_INT_SHIFT	1
291aee2a57cSKrzysztof Kozlowski #define MAX77836_INTSRC_MASK_MUIC_CHG_INT_SHIFT	3
292aee2a57cSKrzysztof Kozlowski #define MAX77836_INTSRC_MASK_TOP_INT_MASK	BIT(MAX77836_INTSRC_MASK_TOP_INT_SHIFT)
293aee2a57cSKrzysztof Kozlowski #define MAX77836_INTSRC_MASK_MUIC_CHG_INT_MASK	BIT(MAX77836_INTSRC_MASK_MUIC_CHG_INT_SHIFT)
294aee2a57cSKrzysztof Kozlowski 
295aee2a57cSKrzysztof Kozlowski /* MAX77836 PMIC interrupts */
296aee2a57cSKrzysztof Kozlowski #define MAX77836_TOPSYS_INT_T120C_SHIFT		0
297aee2a57cSKrzysztof Kozlowski #define MAX77836_TOPSYS_INT_T140C_SHIFT		1
298aee2a57cSKrzysztof Kozlowski #define MAX77836_TOPSYS_INT_T120C_MASK		BIT(MAX77836_TOPSYS_INT_T120C_SHIFT)
299aee2a57cSKrzysztof Kozlowski #define MAX77836_TOPSYS_INT_T140C_MASK		BIT(MAX77836_TOPSYS_INT_T140C_SHIFT)
300aee2a57cSKrzysztof Kozlowski 
301aee2a57cSKrzysztof Kozlowski /* Slave addr = 0x6C: Fuel-Gauge/Battery */
302aee2a57cSKrzysztof Kozlowski enum max77836_fg_reg {
303aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_VCELL_MSB	= 0x02,
304aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_VCELL_LSB	= 0x03,
305aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_SOC_MSB		= 0x04,
306aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_SOC_LSB		= 0x05,
307aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_MODE_H		= 0x06,
308aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_MODE_L		= 0x07,
309aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_VERSION_MSB	= 0x08,
310aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_VERSION_LSB	= 0x09,
311aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_HIBRT_H		= 0x0A,
312aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_HIBRT_L		= 0x0B,
313aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_CONFIG_H	= 0x0C,
314aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_CONFIG_L	= 0x0D,
315aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_VALRT_MIN	= 0x14,
316aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_VALRT_MAX	= 0x15,
317aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_CRATE_MSB	= 0x16,
318aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_CRATE_LSB	= 0x17,
319aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_VRESET		= 0x18,
320aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_FGID		= 0x19,
321aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_STATUS_H	= 0x1A,
322aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_STATUS_L	= 0x1B,
323aee2a57cSKrzysztof Kozlowski 	/*
324aee2a57cSKrzysztof Kozlowski 	 * TODO: TABLE registers
325aee2a57cSKrzysztof Kozlowski 	 * TODO: CMD register
326aee2a57cSKrzysztof Kozlowski 	 */
327aee2a57cSKrzysztof Kozlowski 
328aee2a57cSKrzysztof Kozlowski 	MAX77836_FG_REG_END,
329aee2a57cSKrzysztof Kozlowski };
330aee2a57cSKrzysztof Kozlowski 
3313008ddbeSChanwoo Choi enum max14577_irq {
3323008ddbeSChanwoo Choi 	/* INT1 */
3333008ddbeSChanwoo Choi 	MAX14577_IRQ_INT1_ADC,
3343008ddbeSChanwoo Choi 	MAX14577_IRQ_INT1_ADCLOW,
3353008ddbeSChanwoo Choi 	MAX14577_IRQ_INT1_ADCERR,
336*4706a525SKrzysztof Kozlowski 	MAX77836_IRQ_INT1_ADC1K,
3373008ddbeSChanwoo Choi 
3383008ddbeSChanwoo Choi 	/* INT2 */
3393008ddbeSChanwoo Choi 	MAX14577_IRQ_INT2_CHGTYP,
3403008ddbeSChanwoo Choi 	MAX14577_IRQ_INT2_CHGDETRUN,
3413008ddbeSChanwoo Choi 	MAX14577_IRQ_INT2_DCDTMR,
3423008ddbeSChanwoo Choi 	MAX14577_IRQ_INT2_DBCHG,
3433008ddbeSChanwoo Choi 	MAX14577_IRQ_INT2_VBVOLT,
344*4706a525SKrzysztof Kozlowski 	MAX77836_IRQ_INT2_VIDRM,
3453008ddbeSChanwoo Choi 
3463008ddbeSChanwoo Choi 	/* INT3 */
3473008ddbeSChanwoo Choi 	MAX14577_IRQ_INT3_EOC,
3483008ddbeSChanwoo Choi 	MAX14577_IRQ_INT3_CGMBC,
3493008ddbeSChanwoo Choi 	MAX14577_IRQ_INT3_OVP,
3503008ddbeSChanwoo Choi 	MAX14577_IRQ_INT3_MBCCHGERR,
3513008ddbeSChanwoo Choi 
352aee2a57cSKrzysztof Kozlowski 	/* TOPSYS_INT, only MAX77836 */
353aee2a57cSKrzysztof Kozlowski 	MAX77836_IRQ_TOPSYS_T140C,
354aee2a57cSKrzysztof Kozlowski 	MAX77836_IRQ_TOPSYS_T120C,
355aee2a57cSKrzysztof Kozlowski 
3563008ddbeSChanwoo Choi 	MAX14577_IRQ_NUM,
3573008ddbeSChanwoo Choi };
3583008ddbeSChanwoo Choi 
3593008ddbeSChanwoo Choi struct max14577 {
3603008ddbeSChanwoo Choi 	struct device *dev;
3613008ddbeSChanwoo Choi 	struct i2c_client *i2c; /* Slave addr = 0x4A */
362aee2a57cSKrzysztof Kozlowski 	struct i2c_client *i2c_pmic; /* Slave addr = 0x46 */
363eccb80ccSKrzysztof Kozlowski 	enum maxim_device_type dev_type;
3643008ddbeSChanwoo Choi 
365aee2a57cSKrzysztof Kozlowski 	struct regmap *regmap; /* For MUIC and Charger */
366aee2a57cSKrzysztof Kozlowski 	struct regmap *regmap_pmic;
3673008ddbeSChanwoo Choi 
368aee2a57cSKrzysztof Kozlowski 	struct regmap_irq_chip_data *irq_data; /* For MUIC and Charger */
369aee2a57cSKrzysztof Kozlowski 	struct regmap_irq_chip_data *irq_data_pmic;
3703008ddbeSChanwoo Choi 	int irq;
3713008ddbeSChanwoo Choi };
3723008ddbeSChanwoo Choi 
3733008ddbeSChanwoo Choi /* MAX14577 shared regmap API function */
3743008ddbeSChanwoo Choi static inline int max14577_read_reg(struct regmap *map, u8 reg, u8 *dest)
3753008ddbeSChanwoo Choi {
3763008ddbeSChanwoo Choi 	unsigned int val;
3773008ddbeSChanwoo Choi 	int ret;
3783008ddbeSChanwoo Choi 
3793008ddbeSChanwoo Choi 	ret = regmap_read(map, reg, &val);
3803008ddbeSChanwoo Choi 	*dest = val;
3813008ddbeSChanwoo Choi 
3823008ddbeSChanwoo Choi 	return ret;
3833008ddbeSChanwoo Choi }
3843008ddbeSChanwoo Choi 
3853008ddbeSChanwoo Choi static inline int max14577_bulk_read(struct regmap *map, u8 reg, u8 *buf,
3863008ddbeSChanwoo Choi 		int count)
3873008ddbeSChanwoo Choi {
3883008ddbeSChanwoo Choi 	return regmap_bulk_read(map, reg, buf, count);
3893008ddbeSChanwoo Choi }
3903008ddbeSChanwoo Choi 
3913008ddbeSChanwoo Choi static inline int max14577_write_reg(struct regmap *map, u8 reg, u8 value)
3923008ddbeSChanwoo Choi {
3933008ddbeSChanwoo Choi 	return regmap_write(map, reg, value);
3943008ddbeSChanwoo Choi }
3953008ddbeSChanwoo Choi 
3963008ddbeSChanwoo Choi static inline int max14577_bulk_write(struct regmap *map, u8 reg, u8 *buf,
3973008ddbeSChanwoo Choi 		int count)
3983008ddbeSChanwoo Choi {
3993008ddbeSChanwoo Choi 	return regmap_bulk_write(map, reg, buf, count);
4003008ddbeSChanwoo Choi }
4013008ddbeSChanwoo Choi 
4023008ddbeSChanwoo Choi static inline int max14577_update_reg(struct regmap *map, u8 reg, u8 mask,
4033008ddbeSChanwoo Choi 		u8 val)
4043008ddbeSChanwoo Choi {
4053008ddbeSChanwoo Choi 	return regmap_update_bits(map, reg, mask, val);
4063008ddbeSChanwoo Choi }
4073008ddbeSChanwoo Choi 
4083008ddbeSChanwoo Choi #endif /* __MAX14577_PRIVATE_H__ */
409