1*d7d8d7a2SKrzysztof Kozlowski /* SPDX-License-Identifier: GPL-2.0+ */ 23008ddbeSChanwoo Choi /* 3aee2a57cSKrzysztof Kozlowski * max14577-private.h - Common API for the Maxim 14577/77836 internal sub chip 43008ddbeSChanwoo Choi * 5aee2a57cSKrzysztof Kozlowski * Copyright (C) 2014 Samsung Electrnoics 63008ddbeSChanwoo Choi * Chanwoo Choi <cw00.choi@samsung.com> 78c5d0571SKrzysztof Kozlowski * Krzysztof Kozlowski <krzk@kernel.org> 83008ddbeSChanwoo Choi */ 93008ddbeSChanwoo Choi 103008ddbeSChanwoo Choi #ifndef __MAX14577_PRIVATE_H__ 113008ddbeSChanwoo Choi #define __MAX14577_PRIVATE_H__ 123008ddbeSChanwoo Choi 133008ddbeSChanwoo Choi #include <linux/i2c.h> 143008ddbeSChanwoo Choi #include <linux/regmap.h> 153008ddbeSChanwoo Choi 16aee2a57cSKrzysztof Kozlowski #define I2C_ADDR_PMIC (0x46 >> 1) 17aee2a57cSKrzysztof Kozlowski #define I2C_ADDR_MUIC (0x4A >> 1) 18aee2a57cSKrzysztof Kozlowski #define I2C_ADDR_FG (0x6C >> 1) 19aee2a57cSKrzysztof Kozlowski 20eccb80ccSKrzysztof Kozlowski enum maxim_device_type { 21eccb80ccSKrzysztof Kozlowski MAXIM_DEVICE_TYPE_UNKNOWN = 0, 22eccb80ccSKrzysztof Kozlowski MAXIM_DEVICE_TYPE_MAX14577, 23aee2a57cSKrzysztof Kozlowski MAXIM_DEVICE_TYPE_MAX77836, 24eccb80ccSKrzysztof Kozlowski 25eccb80ccSKrzysztof Kozlowski MAXIM_DEVICE_TYPE_NUM, 26eccb80ccSKrzysztof Kozlowski }; 27eccb80ccSKrzysztof Kozlowski 28575343d1SKrzysztof Kozlowski /* Slave addr = 0x4A: MUIC and Charger */ 293008ddbeSChanwoo Choi enum max14577_reg { 303008ddbeSChanwoo Choi MAX14577_REG_DEVICEID = 0x00, 313008ddbeSChanwoo Choi MAX14577_REG_INT1 = 0x01, 323008ddbeSChanwoo Choi MAX14577_REG_INT2 = 0x02, 333008ddbeSChanwoo Choi MAX14577_REG_INT3 = 0x03, 343008ddbeSChanwoo Choi MAX14577_REG_STATUS1 = 0x04, 353008ddbeSChanwoo Choi MAX14577_REG_STATUS2 = 0x05, 363008ddbeSChanwoo Choi MAX14577_REG_STATUS3 = 0x06, 373008ddbeSChanwoo Choi MAX14577_REG_INTMASK1 = 0x07, 383008ddbeSChanwoo Choi MAX14577_REG_INTMASK2 = 0x08, 393008ddbeSChanwoo Choi MAX14577_REG_INTMASK3 = 0x09, 403008ddbeSChanwoo Choi MAX14577_REG_CDETCTRL1 = 0x0A, 413008ddbeSChanwoo Choi MAX14577_REG_RFU = 0x0B, 423008ddbeSChanwoo Choi MAX14577_REG_CONTROL1 = 0x0C, 433008ddbeSChanwoo Choi MAX14577_REG_CONTROL2 = 0x0D, 443008ddbeSChanwoo Choi MAX14577_REG_CONTROL3 = 0x0E, 453008ddbeSChanwoo Choi MAX14577_REG_CHGCTRL1 = 0x0F, 463008ddbeSChanwoo Choi MAX14577_REG_CHGCTRL2 = 0x10, 473008ddbeSChanwoo Choi MAX14577_REG_CHGCTRL3 = 0x11, 483008ddbeSChanwoo Choi MAX14577_REG_CHGCTRL4 = 0x12, 493008ddbeSChanwoo Choi MAX14577_REG_CHGCTRL5 = 0x13, 503008ddbeSChanwoo Choi MAX14577_REG_CHGCTRL6 = 0x14, 513008ddbeSChanwoo Choi MAX14577_REG_CHGCTRL7 = 0x15, 523008ddbeSChanwoo Choi 533008ddbeSChanwoo Choi MAX14577_REG_END, 543008ddbeSChanwoo Choi }; 553008ddbeSChanwoo Choi 563008ddbeSChanwoo Choi /* Slave addr = 0x4A: MUIC */ 573008ddbeSChanwoo Choi enum max14577_muic_reg { 583008ddbeSChanwoo Choi MAX14577_MUIC_REG_STATUS1 = 0x04, 593008ddbeSChanwoo Choi MAX14577_MUIC_REG_STATUS2 = 0x05, 603008ddbeSChanwoo Choi MAX14577_MUIC_REG_CONTROL1 = 0x0C, 613008ddbeSChanwoo Choi MAX14577_MUIC_REG_CONTROL3 = 0x0E, 623008ddbeSChanwoo Choi 633008ddbeSChanwoo Choi MAX14577_MUIC_REG_END, 643008ddbeSChanwoo Choi }; 653008ddbeSChanwoo Choi 6625cc24c2SKrzysztof Kozlowski /* 6725cc24c2SKrzysztof Kozlowski * Combined charger types for max14577 and max77836. 6825cc24c2SKrzysztof Kozlowski * 6925cc24c2SKrzysztof Kozlowski * On max14577 three lower bits map to STATUS2/CHGTYP field. 7025cc24c2SKrzysztof Kozlowski * However the max77836 has different two last values of STATUS2/CHGTYP. 7125cc24c2SKrzysztof Kozlowski * To indicate the difference enum has two additional values for max77836. 7225cc24c2SKrzysztof Kozlowski * These values are just a register value bitwise OR with 0x8. 7325cc24c2SKrzysztof Kozlowski */ 743008ddbeSChanwoo Choi enum max14577_muic_charger_type { 7525cc24c2SKrzysztof Kozlowski MAX14577_CHARGER_TYPE_NONE = 0x0, 7625cc24c2SKrzysztof Kozlowski MAX14577_CHARGER_TYPE_USB = 0x1, 7725cc24c2SKrzysztof Kozlowski MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT = 0x2, 7825cc24c2SKrzysztof Kozlowski MAX14577_CHARGER_TYPE_DEDICATED_CHG = 0x3, 7925cc24c2SKrzysztof Kozlowski MAX14577_CHARGER_TYPE_SPECIAL_500MA = 0x4, 8025cc24c2SKrzysztof Kozlowski /* Special 1A or 2A charger */ 8125cc24c2SKrzysztof Kozlowski MAX14577_CHARGER_TYPE_SPECIAL_1A = 0x5, 8225cc24c2SKrzysztof Kozlowski /* max14577: reserved, used on max77836 */ 8325cc24c2SKrzysztof Kozlowski MAX14577_CHARGER_TYPE_RESERVED = 0x6, 8425cc24c2SKrzysztof Kozlowski /* max14577: dead-battery charing with maximum current 100mA */ 8525cc24c2SKrzysztof Kozlowski MAX14577_CHARGER_TYPE_DEAD_BATTERY = 0x7, 8625cc24c2SKrzysztof Kozlowski /* 8725cc24c2SKrzysztof Kozlowski * max77836: special charger (bias on D+/D-), 8825cc24c2SKrzysztof Kozlowski * matches register value of 0x6 8925cc24c2SKrzysztof Kozlowski */ 9025cc24c2SKrzysztof Kozlowski MAX77836_CHARGER_TYPE_SPECIAL_BIAS = 0xe, 9125cc24c2SKrzysztof Kozlowski /* max77836: reserved, register value 0x7 */ 9225cc24c2SKrzysztof Kozlowski MAX77836_CHARGER_TYPE_RESERVED = 0xf, 933008ddbeSChanwoo Choi }; 943008ddbeSChanwoo Choi 953008ddbeSChanwoo Choi /* MAX14577 interrupts */ 96c7846852SKrzysztof Kozlowski #define MAX14577_INT1_ADC_MASK BIT(0) 97c7846852SKrzysztof Kozlowski #define MAX14577_INT1_ADCLOW_MASK BIT(1) 98c7846852SKrzysztof Kozlowski #define MAX14577_INT1_ADCERR_MASK BIT(2) 994706a525SKrzysztof Kozlowski #define MAX77836_INT1_ADC1K_MASK BIT(3) 1003008ddbeSChanwoo Choi 101c7846852SKrzysztof Kozlowski #define MAX14577_INT2_CHGTYP_MASK BIT(0) 102c7846852SKrzysztof Kozlowski #define MAX14577_INT2_CHGDETRUN_MASK BIT(1) 103c7846852SKrzysztof Kozlowski #define MAX14577_INT2_DCDTMR_MASK BIT(2) 104c7846852SKrzysztof Kozlowski #define MAX14577_INT2_DBCHG_MASK BIT(3) 105c7846852SKrzysztof Kozlowski #define MAX14577_INT2_VBVOLT_MASK BIT(4) 106aee2a57cSKrzysztof Kozlowski #define MAX77836_INT2_VIDRM_MASK BIT(5) 1073008ddbeSChanwoo Choi 108c7846852SKrzysztof Kozlowski #define MAX14577_INT3_EOC_MASK BIT(0) 109c7846852SKrzysztof Kozlowski #define MAX14577_INT3_CGMBC_MASK BIT(1) 110c7846852SKrzysztof Kozlowski #define MAX14577_INT3_OVP_MASK BIT(2) 111c7846852SKrzysztof Kozlowski #define MAX14577_INT3_MBCCHGERR_MASK BIT(3) 1123008ddbeSChanwoo Choi 1133008ddbeSChanwoo Choi /* MAX14577 DEVICE ID register */ 1143008ddbeSChanwoo Choi #define DEVID_VENDORID_SHIFT 0 1153008ddbeSChanwoo Choi #define DEVID_DEVICEID_SHIFT 3 1163008ddbeSChanwoo Choi #define DEVID_VENDORID_MASK (0x07 << DEVID_VENDORID_SHIFT) 1173008ddbeSChanwoo Choi #define DEVID_DEVICEID_MASK (0x1f << DEVID_DEVICEID_SHIFT) 1183008ddbeSChanwoo Choi 1193008ddbeSChanwoo Choi /* MAX14577 STATUS1 register */ 1203008ddbeSChanwoo Choi #define STATUS1_ADC_SHIFT 0 1213008ddbeSChanwoo Choi #define STATUS1_ADCLOW_SHIFT 5 1223008ddbeSChanwoo Choi #define STATUS1_ADCERR_SHIFT 6 123aee2a57cSKrzysztof Kozlowski #define MAX77836_STATUS1_ADC1K_SHIFT 7 1243008ddbeSChanwoo Choi #define STATUS1_ADC_MASK (0x1f << STATUS1_ADC_SHIFT) 125aee2a57cSKrzysztof Kozlowski #define STATUS1_ADCLOW_MASK BIT(STATUS1_ADCLOW_SHIFT) 126aee2a57cSKrzysztof Kozlowski #define STATUS1_ADCERR_MASK BIT(STATUS1_ADCERR_SHIFT) 127aee2a57cSKrzysztof Kozlowski #define MAX77836_STATUS1_ADC1K_MASK BIT(MAX77836_STATUS1_ADC1K_SHIFT) 1283008ddbeSChanwoo Choi 1293008ddbeSChanwoo Choi /* MAX14577 STATUS2 register */ 1303008ddbeSChanwoo Choi #define STATUS2_CHGTYP_SHIFT 0 1313008ddbeSChanwoo Choi #define STATUS2_CHGDETRUN_SHIFT 3 1323008ddbeSChanwoo Choi #define STATUS2_DCDTMR_SHIFT 4 13325cc24c2SKrzysztof Kozlowski #define MAX14577_STATUS2_DBCHG_SHIFT 5 13425cc24c2SKrzysztof Kozlowski #define MAX77836_STATUS2_DXOVP_SHIFT 5 1353008ddbeSChanwoo Choi #define STATUS2_VBVOLT_SHIFT 6 136aee2a57cSKrzysztof Kozlowski #define MAX77836_STATUS2_VIDRM_SHIFT 7 1373008ddbeSChanwoo Choi #define STATUS2_CHGTYP_MASK (0x7 << STATUS2_CHGTYP_SHIFT) 138aee2a57cSKrzysztof Kozlowski #define STATUS2_CHGDETRUN_MASK BIT(STATUS2_CHGDETRUN_SHIFT) 139aee2a57cSKrzysztof Kozlowski #define STATUS2_DCDTMR_MASK BIT(STATUS2_DCDTMR_SHIFT) 14025cc24c2SKrzysztof Kozlowski #define MAX14577_STATUS2_DBCHG_MASK BIT(MAX14577_STATUS2_DBCHG_SHIFT) 14125cc24c2SKrzysztof Kozlowski #define MAX77836_STATUS2_DXOVP_MASK BIT(MAX77836_STATUS2_DXOVP_SHIFT) 142aee2a57cSKrzysztof Kozlowski #define STATUS2_VBVOLT_MASK BIT(STATUS2_VBVOLT_SHIFT) 143aee2a57cSKrzysztof Kozlowski #define MAX77836_STATUS2_VIDRM_MASK BIT(MAX77836_STATUS2_VIDRM_SHIFT) 1443008ddbeSChanwoo Choi 1453008ddbeSChanwoo Choi /* MAX14577 CONTROL1 register */ 1463008ddbeSChanwoo Choi #define COMN1SW_SHIFT 0 1473008ddbeSChanwoo Choi #define COMP2SW_SHIFT 3 1483008ddbeSChanwoo Choi #define MICEN_SHIFT 6 1493008ddbeSChanwoo Choi #define IDBEN_SHIFT 7 1503008ddbeSChanwoo Choi #define COMN1SW_MASK (0x7 << COMN1SW_SHIFT) 1513008ddbeSChanwoo Choi #define COMP2SW_MASK (0x7 << COMP2SW_SHIFT) 152aee2a57cSKrzysztof Kozlowski #define MICEN_MASK BIT(MICEN_SHIFT) 153aee2a57cSKrzysztof Kozlowski #define IDBEN_MASK BIT(IDBEN_SHIFT) 1543008ddbeSChanwoo Choi #define CLEAR_IDBEN_MICEN_MASK (COMN1SW_MASK | COMP2SW_MASK) 1553008ddbeSChanwoo Choi #define CTRL1_SW_USB ((1 << COMP2SW_SHIFT) \ 1563008ddbeSChanwoo Choi | (1 << COMN1SW_SHIFT)) 1573008ddbeSChanwoo Choi #define CTRL1_SW_AUDIO ((2 << COMP2SW_SHIFT) \ 1583008ddbeSChanwoo Choi | (2 << COMN1SW_SHIFT)) 1593008ddbeSChanwoo Choi #define CTRL1_SW_UART ((3 << COMP2SW_SHIFT) \ 1603008ddbeSChanwoo Choi | (3 << COMN1SW_SHIFT)) 1613008ddbeSChanwoo Choi #define CTRL1_SW_OPEN ((0 << COMP2SW_SHIFT) \ 1623008ddbeSChanwoo Choi | (0 << COMN1SW_SHIFT)) 1633008ddbeSChanwoo Choi 1643008ddbeSChanwoo Choi /* MAX14577 CONTROL2 register */ 1653008ddbeSChanwoo Choi #define CTRL2_LOWPWR_SHIFT (0) 1663008ddbeSChanwoo Choi #define CTRL2_ADCEN_SHIFT (1) 1673008ddbeSChanwoo Choi #define CTRL2_CPEN_SHIFT (2) 1683008ddbeSChanwoo Choi #define CTRL2_SFOUTASRT_SHIFT (3) 1693008ddbeSChanwoo Choi #define CTRL2_SFOUTORD_SHIFT (4) 1703008ddbeSChanwoo Choi #define CTRL2_ACCDET_SHIFT (5) 1713008ddbeSChanwoo Choi #define CTRL2_USBCPINT_SHIFT (6) 1723008ddbeSChanwoo Choi #define CTRL2_RCPS_SHIFT (7) 173aee2a57cSKrzysztof Kozlowski #define CTRL2_LOWPWR_MASK BIT(CTRL2_LOWPWR_SHIFT) 174aee2a57cSKrzysztof Kozlowski #define CTRL2_ADCEN_MASK BIT(CTRL2_ADCEN_SHIFT) 175aee2a57cSKrzysztof Kozlowski #define CTRL2_CPEN_MASK BIT(CTRL2_CPEN_SHIFT) 176aee2a57cSKrzysztof Kozlowski #define CTRL2_SFOUTASRT_MASK BIT(CTRL2_SFOUTASRT_SHIFT) 177aee2a57cSKrzysztof Kozlowski #define CTRL2_SFOUTORD_MASK BIT(CTRL2_SFOUTORD_SHIFT) 178aee2a57cSKrzysztof Kozlowski #define CTRL2_ACCDET_MASK BIT(CTRL2_ACCDET_SHIFT) 179aee2a57cSKrzysztof Kozlowski #define CTRL2_USBCPINT_MASK BIT(CTRL2_USBCPINT_SHIFT) 180aee2a57cSKrzysztof Kozlowski #define CTRL2_RCPS_MASK BIT(CTRL2_RCPS_SHIFT) 1813008ddbeSChanwoo Choi 1823008ddbeSChanwoo Choi #define CTRL2_CPEN1_LOWPWR0 ((1 << CTRL2_CPEN_SHIFT) | \ 1833008ddbeSChanwoo Choi (0 << CTRL2_LOWPWR_SHIFT)) 1843008ddbeSChanwoo Choi #define CTRL2_CPEN0_LOWPWR1 ((0 << CTRL2_CPEN_SHIFT) | \ 1853008ddbeSChanwoo Choi (1 << CTRL2_LOWPWR_SHIFT)) 1863008ddbeSChanwoo Choi 1873008ddbeSChanwoo Choi /* MAX14577 CONTROL3 register */ 1883008ddbeSChanwoo Choi #define CTRL3_JIGSET_SHIFT 0 1893008ddbeSChanwoo Choi #define CTRL3_BOOTSET_SHIFT 2 1903008ddbeSChanwoo Choi #define CTRL3_ADCDBSET_SHIFT 4 19125cc24c2SKrzysztof Kozlowski #define CTRL3_WBTH_SHIFT 6 1923008ddbeSChanwoo Choi #define CTRL3_JIGSET_MASK (0x3 << CTRL3_JIGSET_SHIFT) 1933008ddbeSChanwoo Choi #define CTRL3_BOOTSET_MASK (0x3 << CTRL3_BOOTSET_SHIFT) 1943008ddbeSChanwoo Choi #define CTRL3_ADCDBSET_MASK (0x3 << CTRL3_ADCDBSET_SHIFT) 19525cc24c2SKrzysztof Kozlowski #define CTRL3_WBTH_MASK (0x3 << CTRL3_WBTH_SHIFT) 1963008ddbeSChanwoo Choi 1973008ddbeSChanwoo Choi /* Slave addr = 0x4A: Charger */ 1983008ddbeSChanwoo Choi enum max14577_charger_reg { 1993008ddbeSChanwoo Choi MAX14577_CHG_REG_STATUS3 = 0x06, 2003008ddbeSChanwoo Choi MAX14577_CHG_REG_CHG_CTRL1 = 0x0F, 2013008ddbeSChanwoo Choi MAX14577_CHG_REG_CHG_CTRL2 = 0x10, 2023008ddbeSChanwoo Choi MAX14577_CHG_REG_CHG_CTRL3 = 0x11, 2033008ddbeSChanwoo Choi MAX14577_CHG_REG_CHG_CTRL4 = 0x12, 2043008ddbeSChanwoo Choi MAX14577_CHG_REG_CHG_CTRL5 = 0x13, 2053008ddbeSChanwoo Choi MAX14577_CHG_REG_CHG_CTRL6 = 0x14, 2063008ddbeSChanwoo Choi MAX14577_CHG_REG_CHG_CTRL7 = 0x15, 2073008ddbeSChanwoo Choi 2083008ddbeSChanwoo Choi MAX14577_CHG_REG_END, 2093008ddbeSChanwoo Choi }; 2103008ddbeSChanwoo Choi 2113008ddbeSChanwoo Choi /* MAX14577 STATUS3 register */ 2123008ddbeSChanwoo Choi #define STATUS3_EOC_SHIFT 0 2133008ddbeSChanwoo Choi #define STATUS3_CGMBC_SHIFT 1 2143008ddbeSChanwoo Choi #define STATUS3_OVP_SHIFT 2 2153008ddbeSChanwoo Choi #define STATUS3_MBCCHGERR_SHIFT 3 2163008ddbeSChanwoo Choi #define STATUS3_EOC_MASK (0x1 << STATUS3_EOC_SHIFT) 2173008ddbeSChanwoo Choi #define STATUS3_CGMBC_MASK (0x1 << STATUS3_CGMBC_SHIFT) 2183008ddbeSChanwoo Choi #define STATUS3_OVP_MASK (0x1 << STATUS3_OVP_SHIFT) 2193008ddbeSChanwoo Choi #define STATUS3_MBCCHGERR_MASK (0x1 << STATUS3_MBCCHGERR_SHIFT) 2203008ddbeSChanwoo Choi 2213008ddbeSChanwoo Choi /* MAX14577 CDETCTRL1 register */ 2223008ddbeSChanwoo Choi #define CDETCTRL1_CHGDETEN_SHIFT 0 2233008ddbeSChanwoo Choi #define CDETCTRL1_CHGTYPMAN_SHIFT 1 2243008ddbeSChanwoo Choi #define CDETCTRL1_DCDEN_SHIFT 2 2253008ddbeSChanwoo Choi #define CDETCTRL1_DCD2SCT_SHIFT 3 22625cc24c2SKrzysztof Kozlowski #define MAX14577_CDETCTRL1_DCHKTM_SHIFT 4 22725cc24c2SKrzysztof Kozlowski #define MAX77836_CDETCTRL1_CDLY_SHIFT 4 22825cc24c2SKrzysztof Kozlowski #define MAX14577_CDETCTRL1_DBEXIT_SHIFT 5 22925cc24c2SKrzysztof Kozlowski #define MAX77836_CDETCTRL1_DCDCPL_SHIFT 5 2303008ddbeSChanwoo Choi #define CDETCTRL1_DBIDLE_SHIFT 6 2313008ddbeSChanwoo Choi #define CDETCTRL1_CDPDET_SHIFT 7 232aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_CHGDETEN_MASK BIT(CDETCTRL1_CHGDETEN_SHIFT) 233aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_CHGTYPMAN_MASK BIT(CDETCTRL1_CHGTYPMAN_SHIFT) 234aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_DCDEN_MASK BIT(CDETCTRL1_DCDEN_SHIFT) 235aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_DCD2SCT_MASK BIT(CDETCTRL1_DCD2SCT_SHIFT) 23625cc24c2SKrzysztof Kozlowski #define MAX14577_CDETCTRL1_DCHKTM_MASK BIT(MAX14577_CDETCTRL1_DCHKTM_SHIFT) 23725cc24c2SKrzysztof Kozlowski #define MAX77836_CDETCTRL1_CDDLY_MASK BIT(MAX77836_CDETCTRL1_CDDLY_SHIFT) 23825cc24c2SKrzysztof Kozlowski #define MAX14577_CDETCTRL1_DBEXIT_MASK BIT(MAX14577_CDETCTRL1_DBEXIT_SHIFT) 23925cc24c2SKrzysztof Kozlowski #define MAX77836_CDETCTRL1_DCDCPL_MASK BIT(MAX77836_CDETCTRL1_DCDCPL_SHIFT) 240aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_DBIDLE_MASK BIT(CDETCTRL1_DBIDLE_SHIFT) 241aee2a57cSKrzysztof Kozlowski #define CDETCTRL1_CDPDET_MASK BIT(CDETCTRL1_CDPDET_SHIFT) 2423008ddbeSChanwoo Choi 2433008ddbeSChanwoo Choi /* MAX14577 CHGCTRL1 register */ 2443008ddbeSChanwoo Choi #define CHGCTRL1_TCHW_SHIFT 4 2453008ddbeSChanwoo Choi #define CHGCTRL1_TCHW_MASK (0x7 << CHGCTRL1_TCHW_SHIFT) 2463008ddbeSChanwoo Choi 2473008ddbeSChanwoo Choi /* MAX14577 CHGCTRL2 register */ 2483008ddbeSChanwoo Choi #define CHGCTRL2_MBCHOSTEN_SHIFT 6 249aee2a57cSKrzysztof Kozlowski #define CHGCTRL2_MBCHOSTEN_MASK BIT(CHGCTRL2_MBCHOSTEN_SHIFT) 2503008ddbeSChanwoo Choi #define CHGCTRL2_VCHGR_RC_SHIFT 7 251aee2a57cSKrzysztof Kozlowski #define CHGCTRL2_VCHGR_RC_MASK BIT(CHGCTRL2_VCHGR_RC_SHIFT) 2523008ddbeSChanwoo Choi 2533008ddbeSChanwoo Choi /* MAX14577 CHGCTRL3 register */ 2543008ddbeSChanwoo Choi #define CHGCTRL3_MBCCVWRC_SHIFT 0 2553008ddbeSChanwoo Choi #define CHGCTRL3_MBCCVWRC_MASK (0xf << CHGCTRL3_MBCCVWRC_SHIFT) 2563008ddbeSChanwoo Choi 2573008ddbeSChanwoo Choi /* MAX14577 CHGCTRL4 register */ 2583008ddbeSChanwoo Choi #define CHGCTRL4_MBCICHWRCH_SHIFT 0 2593008ddbeSChanwoo Choi #define CHGCTRL4_MBCICHWRCH_MASK (0xf << CHGCTRL4_MBCICHWRCH_SHIFT) 2603008ddbeSChanwoo Choi #define CHGCTRL4_MBCICHWRCL_SHIFT 4 261aee2a57cSKrzysztof Kozlowski #define CHGCTRL4_MBCICHWRCL_MASK BIT(CHGCTRL4_MBCICHWRCL_SHIFT) 2623008ddbeSChanwoo Choi 2633008ddbeSChanwoo Choi /* MAX14577 CHGCTRL5 register */ 2643008ddbeSChanwoo Choi #define CHGCTRL5_EOCS_SHIFT 0 2653008ddbeSChanwoo Choi #define CHGCTRL5_EOCS_MASK (0xf << CHGCTRL5_EOCS_SHIFT) 2663008ddbeSChanwoo Choi 2673008ddbeSChanwoo Choi /* MAX14577 CHGCTRL6 register */ 2683008ddbeSChanwoo Choi #define CHGCTRL6_AUTOSTOP_SHIFT 5 269aee2a57cSKrzysztof Kozlowski #define CHGCTRL6_AUTOSTOP_MASK BIT(CHGCTRL6_AUTOSTOP_SHIFT) 2703008ddbeSChanwoo Choi 2713008ddbeSChanwoo Choi /* MAX14577 CHGCTRL7 register */ 2723008ddbeSChanwoo Choi #define CHGCTRL7_OTPCGHCVS_SHIFT 0 2733008ddbeSChanwoo Choi #define CHGCTRL7_OTPCGHCVS_MASK (0x3 << CHGCTRL7_OTPCGHCVS_SHIFT) 2743008ddbeSChanwoo Choi 275b8f139f6SKrzysztof Kozlowski /* MAX14577 charger current limits (as in CHGCTRL4 register), uA */ 276b8f139f6SKrzysztof Kozlowski #define MAX14577_CHARGER_CURRENT_LIMIT_MIN 90000U 277b8f139f6SKrzysztof Kozlowski #define MAX14577_CHARGER_CURRENT_LIMIT_HIGH_START 200000U 278b8f139f6SKrzysztof Kozlowski #define MAX14577_CHARGER_CURRENT_LIMIT_HIGH_STEP 50000U 279b8f139f6SKrzysztof Kozlowski #define MAX14577_CHARGER_CURRENT_LIMIT_MAX 950000U 2803008ddbeSChanwoo Choi 281b8f139f6SKrzysztof Kozlowski /* MAX77836 charger current limits (as in CHGCTRL4 register), uA */ 282b8f139f6SKrzysztof Kozlowski #define MAX77836_CHARGER_CURRENT_LIMIT_MIN 45000U 283b8f139f6SKrzysztof Kozlowski #define MAX77836_CHARGER_CURRENT_LIMIT_HIGH_START 100000U 284b8f139f6SKrzysztof Kozlowski #define MAX77836_CHARGER_CURRENT_LIMIT_HIGH_STEP 25000U 285b8f139f6SKrzysztof Kozlowski #define MAX77836_CHARGER_CURRENT_LIMIT_MAX 475000U 2868a82b408SKrzysztof Kozlowski 287e30110e9SKrzysztof Kozlowski /* 288e30110e9SKrzysztof Kozlowski * MAX14577 charger End-Of-Charge current limits 289e30110e9SKrzysztof Kozlowski * (as in CHGCTRL5 register), uA 290e30110e9SKrzysztof Kozlowski */ 291e30110e9SKrzysztof Kozlowski #define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MIN 50000U 292e30110e9SKrzysztof Kozlowski #define MAX14577_CHARGER_EOC_CURRENT_LIMIT_STEP 10000U 293e30110e9SKrzysztof Kozlowski #define MAX14577_CHARGER_EOC_CURRENT_LIMIT_MAX 200000U 294e30110e9SKrzysztof Kozlowski 295e30110e9SKrzysztof Kozlowski /* 296e30110e9SKrzysztof Kozlowski * MAX14577/MAX77836 Battery Constant Voltage 297e30110e9SKrzysztof Kozlowski * (as in CHGCTRL3 register), uV 298e30110e9SKrzysztof Kozlowski */ 299e30110e9SKrzysztof Kozlowski #define MAXIM_CHARGER_CONSTANT_VOLTAGE_MIN 4000000U 300e30110e9SKrzysztof Kozlowski #define MAXIM_CHARGER_CONSTANT_VOLTAGE_STEP 20000U 301e30110e9SKrzysztof Kozlowski #define MAXIM_CHARGER_CONSTANT_VOLTAGE_MAX 4350000U 302e30110e9SKrzysztof Kozlowski 303e30110e9SKrzysztof Kozlowski /* Default value for fast charge timer, in hours */ 304e30110e9SKrzysztof Kozlowski #define MAXIM_CHARGER_FAST_CHARGE_TIMER_DEFAULT 5 305e30110e9SKrzysztof Kozlowski 3063008ddbeSChanwoo Choi /* MAX14577 regulator SFOUT LDO voltage, fixed, uV */ 3073008ddbeSChanwoo Choi #define MAX14577_REGULATOR_SAFEOUT_VOLTAGE 4900000 3083008ddbeSChanwoo Choi 3098a82b408SKrzysztof Kozlowski /* MAX77836 regulator LDOx voltage, uV */ 3108a82b408SKrzysztof Kozlowski #define MAX77836_REGULATOR_LDO_VOLTAGE_MIN 800000 3118a82b408SKrzysztof Kozlowski #define MAX77836_REGULATOR_LDO_VOLTAGE_MAX 3950000 3128a82b408SKrzysztof Kozlowski #define MAX77836_REGULATOR_LDO_VOLTAGE_STEP 50000 3138a82b408SKrzysztof Kozlowski #define MAX77836_REGULATOR_LDO_VOLTAGE_STEPS_NUM 64 3148a82b408SKrzysztof Kozlowski 315aee2a57cSKrzysztof Kozlowski /* Slave addr = 0x46: PMIC */ 316aee2a57cSKrzysztof Kozlowski enum max77836_pmic_reg { 317aee2a57cSKrzysztof Kozlowski MAX77836_PMIC_REG_PMIC_ID = 0x20, 318aee2a57cSKrzysztof Kozlowski MAX77836_PMIC_REG_PMIC_REV = 0x21, 319aee2a57cSKrzysztof Kozlowski MAX77836_PMIC_REG_INTSRC = 0x22, 320aee2a57cSKrzysztof Kozlowski MAX77836_PMIC_REG_INTSRC_MASK = 0x23, 321aee2a57cSKrzysztof Kozlowski MAX77836_PMIC_REG_TOPSYS_INT = 0x24, 322aee2a57cSKrzysztof Kozlowski MAX77836_PMIC_REG_TOPSYS_INT_MASK = 0x26, 323aee2a57cSKrzysztof Kozlowski MAX77836_PMIC_REG_TOPSYS_STAT = 0x28, 324aee2a57cSKrzysztof Kozlowski MAX77836_PMIC_REG_MRSTB_CNTL = 0x2A, 325aee2a57cSKrzysztof Kozlowski MAX77836_PMIC_REG_LSCNFG = 0x2B, 326aee2a57cSKrzysztof Kozlowski 327aee2a57cSKrzysztof Kozlowski MAX77836_LDO_REG_CNFG1_LDO1 = 0x51, 328aee2a57cSKrzysztof Kozlowski MAX77836_LDO_REG_CNFG2_LDO1 = 0x52, 329aee2a57cSKrzysztof Kozlowski MAX77836_LDO_REG_CNFG1_LDO2 = 0x53, 330aee2a57cSKrzysztof Kozlowski MAX77836_LDO_REG_CNFG2_LDO2 = 0x54, 331aee2a57cSKrzysztof Kozlowski MAX77836_LDO_REG_CNFG_LDO_BIAS = 0x55, 332aee2a57cSKrzysztof Kozlowski 333aee2a57cSKrzysztof Kozlowski MAX77836_COMP_REG_COMP1 = 0x60, 334aee2a57cSKrzysztof Kozlowski 335aee2a57cSKrzysztof Kozlowski MAX77836_PMIC_REG_END, 336aee2a57cSKrzysztof Kozlowski }; 337aee2a57cSKrzysztof Kozlowski 338aee2a57cSKrzysztof Kozlowski #define MAX77836_INTSRC_MASK_TOP_INT_SHIFT 1 339aee2a57cSKrzysztof Kozlowski #define MAX77836_INTSRC_MASK_MUIC_CHG_INT_SHIFT 3 340aee2a57cSKrzysztof Kozlowski #define MAX77836_INTSRC_MASK_TOP_INT_MASK BIT(MAX77836_INTSRC_MASK_TOP_INT_SHIFT) 341aee2a57cSKrzysztof Kozlowski #define MAX77836_INTSRC_MASK_MUIC_CHG_INT_MASK BIT(MAX77836_INTSRC_MASK_MUIC_CHG_INT_SHIFT) 342aee2a57cSKrzysztof Kozlowski 343aee2a57cSKrzysztof Kozlowski /* MAX77836 PMIC interrupts */ 344aee2a57cSKrzysztof Kozlowski #define MAX77836_TOPSYS_INT_T120C_SHIFT 0 345aee2a57cSKrzysztof Kozlowski #define MAX77836_TOPSYS_INT_T140C_SHIFT 1 346aee2a57cSKrzysztof Kozlowski #define MAX77836_TOPSYS_INT_T120C_MASK BIT(MAX77836_TOPSYS_INT_T120C_SHIFT) 347aee2a57cSKrzysztof Kozlowski #define MAX77836_TOPSYS_INT_T140C_MASK BIT(MAX77836_TOPSYS_INT_T140C_SHIFT) 348aee2a57cSKrzysztof Kozlowski 3498a82b408SKrzysztof Kozlowski /* LDO1/LDO2 CONFIG1 register */ 3508a82b408SKrzysztof Kozlowski #define MAX77836_CNFG1_LDO_PWRMD_SHIFT 6 3518a82b408SKrzysztof Kozlowski #define MAX77836_CNFG1_LDO_TV_SHIFT 0 3528a82b408SKrzysztof Kozlowski #define MAX77836_CNFG1_LDO_PWRMD_MASK (0x3 << MAX77836_CNFG1_LDO_PWRMD_SHIFT) 3538a82b408SKrzysztof Kozlowski #define MAX77836_CNFG1_LDO_TV_MASK (0x3f << MAX77836_CNFG1_LDO_TV_SHIFT) 3548a82b408SKrzysztof Kozlowski 3558a82b408SKrzysztof Kozlowski /* LDO1/LDO2 CONFIG2 register */ 3568a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_OVCLMPEN_SHIFT 7 3578a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_ALPMEN_SHIFT 6 3588a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_COMP_SHIFT 4 3598a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_POK_SHIFT 3 3608a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_ADE_SHIFT 1 3618a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_SS_SHIFT 0 3628a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_OVCLMPEN_MASK BIT(MAX77836_CNFG2_LDO_OVCLMPEN_SHIFT) 3638a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_ALPMEN_MASK BIT(MAX77836_CNFG2_LDO_ALPMEN_SHIFT) 3648a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_COMP_MASK (0x3 << MAX77836_CNFG2_LDO_COMP_SHIFT) 3658a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_POK_MASK BIT(MAX77836_CNFG2_LDO_POK_SHIFT) 3668a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_ADE_MASK BIT(MAX77836_CNFG2_LDO_ADE_SHIFT) 3678a82b408SKrzysztof Kozlowski #define MAX77836_CNFG2_LDO_SS_MASK BIT(MAX77836_CNFG2_LDO_SS_SHIFT) 3688a82b408SKrzysztof Kozlowski 369aee2a57cSKrzysztof Kozlowski /* Slave addr = 0x6C: Fuel-Gauge/Battery */ 370aee2a57cSKrzysztof Kozlowski enum max77836_fg_reg { 371aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_VCELL_MSB = 0x02, 372aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_VCELL_LSB = 0x03, 373aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_SOC_MSB = 0x04, 374aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_SOC_LSB = 0x05, 375aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_MODE_H = 0x06, 376aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_MODE_L = 0x07, 377aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_VERSION_MSB = 0x08, 378aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_VERSION_LSB = 0x09, 379aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_HIBRT_H = 0x0A, 380aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_HIBRT_L = 0x0B, 381aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_CONFIG_H = 0x0C, 382aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_CONFIG_L = 0x0D, 383aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_VALRT_MIN = 0x14, 384aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_VALRT_MAX = 0x15, 385aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_CRATE_MSB = 0x16, 386aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_CRATE_LSB = 0x17, 387aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_VRESET = 0x18, 388aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_FGID = 0x19, 389aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_STATUS_H = 0x1A, 390aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_STATUS_L = 0x1B, 391aee2a57cSKrzysztof Kozlowski /* 392aee2a57cSKrzysztof Kozlowski * TODO: TABLE registers 393aee2a57cSKrzysztof Kozlowski * TODO: CMD register 394aee2a57cSKrzysztof Kozlowski */ 395aee2a57cSKrzysztof Kozlowski 396aee2a57cSKrzysztof Kozlowski MAX77836_FG_REG_END, 397aee2a57cSKrzysztof Kozlowski }; 398aee2a57cSKrzysztof Kozlowski 3993008ddbeSChanwoo Choi enum max14577_irq { 4003008ddbeSChanwoo Choi /* INT1 */ 4013008ddbeSChanwoo Choi MAX14577_IRQ_INT1_ADC, 4023008ddbeSChanwoo Choi MAX14577_IRQ_INT1_ADCLOW, 4033008ddbeSChanwoo Choi MAX14577_IRQ_INT1_ADCERR, 4044706a525SKrzysztof Kozlowski MAX77836_IRQ_INT1_ADC1K, 4053008ddbeSChanwoo Choi 4063008ddbeSChanwoo Choi /* INT2 */ 4073008ddbeSChanwoo Choi MAX14577_IRQ_INT2_CHGTYP, 4083008ddbeSChanwoo Choi MAX14577_IRQ_INT2_CHGDETRUN, 4093008ddbeSChanwoo Choi MAX14577_IRQ_INT2_DCDTMR, 4103008ddbeSChanwoo Choi MAX14577_IRQ_INT2_DBCHG, 4113008ddbeSChanwoo Choi MAX14577_IRQ_INT2_VBVOLT, 4124706a525SKrzysztof Kozlowski MAX77836_IRQ_INT2_VIDRM, 4133008ddbeSChanwoo Choi 4143008ddbeSChanwoo Choi /* INT3 */ 4153008ddbeSChanwoo Choi MAX14577_IRQ_INT3_EOC, 4163008ddbeSChanwoo Choi MAX14577_IRQ_INT3_CGMBC, 4173008ddbeSChanwoo Choi MAX14577_IRQ_INT3_OVP, 4183008ddbeSChanwoo Choi MAX14577_IRQ_INT3_MBCCHGERR, 4193008ddbeSChanwoo Choi 420aee2a57cSKrzysztof Kozlowski /* TOPSYS_INT, only MAX77836 */ 421aee2a57cSKrzysztof Kozlowski MAX77836_IRQ_TOPSYS_T140C, 422aee2a57cSKrzysztof Kozlowski MAX77836_IRQ_TOPSYS_T120C, 423aee2a57cSKrzysztof Kozlowski 4243008ddbeSChanwoo Choi MAX14577_IRQ_NUM, 4253008ddbeSChanwoo Choi }; 4263008ddbeSChanwoo Choi 4273008ddbeSChanwoo Choi struct max14577 { 4283008ddbeSChanwoo Choi struct device *dev; 4293008ddbeSChanwoo Choi struct i2c_client *i2c; /* Slave addr = 0x4A */ 430aee2a57cSKrzysztof Kozlowski struct i2c_client *i2c_pmic; /* Slave addr = 0x46 */ 431eccb80ccSKrzysztof Kozlowski enum maxim_device_type dev_type; 4323008ddbeSChanwoo Choi 433aee2a57cSKrzysztof Kozlowski struct regmap *regmap; /* For MUIC and Charger */ 434aee2a57cSKrzysztof Kozlowski struct regmap *regmap_pmic; 4353008ddbeSChanwoo Choi 436aee2a57cSKrzysztof Kozlowski struct regmap_irq_chip_data *irq_data; /* For MUIC and Charger */ 437aee2a57cSKrzysztof Kozlowski struct regmap_irq_chip_data *irq_data_pmic; 4383008ddbeSChanwoo Choi int irq; 4393008ddbeSChanwoo Choi }; 4403008ddbeSChanwoo Choi 4413008ddbeSChanwoo Choi /* MAX14577 shared regmap API function */ 4423008ddbeSChanwoo Choi static inline int max14577_read_reg(struct regmap *map, u8 reg, u8 *dest) 4433008ddbeSChanwoo Choi { 4443008ddbeSChanwoo Choi unsigned int val; 4453008ddbeSChanwoo Choi int ret; 4463008ddbeSChanwoo Choi 4473008ddbeSChanwoo Choi ret = regmap_read(map, reg, &val); 4483008ddbeSChanwoo Choi *dest = val; 4493008ddbeSChanwoo Choi 4503008ddbeSChanwoo Choi return ret; 4513008ddbeSChanwoo Choi } 4523008ddbeSChanwoo Choi 4533008ddbeSChanwoo Choi static inline int max14577_bulk_read(struct regmap *map, u8 reg, u8 *buf, 4543008ddbeSChanwoo Choi int count) 4553008ddbeSChanwoo Choi { 4563008ddbeSChanwoo Choi return regmap_bulk_read(map, reg, buf, count); 4573008ddbeSChanwoo Choi } 4583008ddbeSChanwoo Choi 4593008ddbeSChanwoo Choi static inline int max14577_write_reg(struct regmap *map, u8 reg, u8 value) 4603008ddbeSChanwoo Choi { 4613008ddbeSChanwoo Choi return regmap_write(map, reg, value); 4623008ddbeSChanwoo Choi } 4633008ddbeSChanwoo Choi 4643008ddbeSChanwoo Choi static inline int max14577_bulk_write(struct regmap *map, u8 reg, u8 *buf, 4653008ddbeSChanwoo Choi int count) 4663008ddbeSChanwoo Choi { 4673008ddbeSChanwoo Choi return regmap_bulk_write(map, reg, buf, count); 4683008ddbeSChanwoo Choi } 4693008ddbeSChanwoo Choi 4703008ddbeSChanwoo Choi static inline int max14577_update_reg(struct regmap *map, u8 reg, u8 mask, 4713008ddbeSChanwoo Choi u8 val) 4723008ddbeSChanwoo Choi { 4733008ddbeSChanwoo Choi return regmap_update_bits(map, reg, mask, val); 4743008ddbeSChanwoo Choi } 4753008ddbeSChanwoo Choi 4763008ddbeSChanwoo Choi #endif /* __MAX14577_PRIVATE_H__ */ 477