1 /* SPDX-License-Identifier: GPL-2.0+ */ 2 /* 3 * Copyright 2022 Google, Inc 4 * 5 * MAXIM TCPC header file. 6 */ 7 #ifndef TCPCI_MAXIM_H_ 8 #define TCPCI_MAXIM_H_ 9 10 #define VENDOR_CC_STATUS2 0x85 11 #define CC1_VUFP_RD0P5 BIT(1) 12 #define CC2_VUFP_RD0P5 BIT(5) 13 #define TCPC_VENDOR_FLADC_STATUS 0x89 14 15 #define TCPC_VENDOR_CC_CTRL1 0x8c 16 #define CCCONNDRY BIT(7) 17 #define CCCOMPEN BIT(5) 18 19 #define TCPC_VENDOR_CC_CTRL2 0x8d 20 #define SBUOVPDIS BIT(7) 21 #define CCOVPDIS BIT(6) 22 #define SBURPCTRL BIT(5) 23 #define CCLPMODESEL GENMASK(4, 3) 24 #define LOW_POWER_MODE_DISABLE 0 25 #define ULTRA_LOW_POWER_MODE 1 26 #define CCRPCTRL GENMASK(2, 0) 27 #define UA_1_SRC 1 28 #define UA_80_SRC 3 29 30 #define TCPC_VENDOR_CC_CTRL3 0x8e 31 #define CCWTRDEB GENMASK(7, 6) 32 #define CCWTRDEB_1MS 1 33 #define CCWTRSEL GENMASK(5, 3) 34 #define CCWTRSEL_1V 0x4 35 #define CCLADDERDIS BIT(2) 36 #define WTRCYCLE GENMASK(0, 0) 37 #define WTRCYCLE_2_4_S 0 38 #define WTRCYCLE_4_8_S 1 39 40 #define TCPC_VENDOR_ADC_CTRL1 0x91 41 #define ADCINSEL GENMASK(7, 5) 42 #define ADCEN BIT(0) 43 44 enum contamiant_state { 45 NOT_DETECTED, 46 DETECTED, 47 SINK, 48 }; 49 50 /* 51 * @potential_contaminant: 52 * Last returned result to tcpm indicating whether the TCPM port 53 * has potential contaminant. 54 */ 55 struct max_tcpci_chip { 56 struct tcpci_data data; 57 struct tcpci *tcpci; 58 struct device *dev; 59 struct i2c_client *client; 60 struct tcpm_port *port; 61 enum contamiant_state contaminant_state; 62 bool veto_vconn_swap; 63 struct regulator *vbus_reg; 64 }; 65 66 static inline int max_tcpci_read16(struct max_tcpci_chip *chip, unsigned int reg, u16 *val) 67 { 68 return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u16)); 69 } 70 71 static inline int max_tcpci_write16(struct max_tcpci_chip *chip, unsigned int reg, u16 val) 72 { 73 return regmap_raw_write(chip->data.regmap, reg, &val, sizeof(u16)); 74 } 75 76 static inline int max_tcpci_read8(struct max_tcpci_chip *chip, unsigned int reg, u8 *val) 77 { 78 return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u8)); 79 } 80 81 static inline int max_tcpci_write8(struct max_tcpci_chip *chip, unsigned int reg, u8 val) 82 { 83 return regmap_raw_write(chip->data.regmap, reg, &val, sizeof(u8)); 84 } 85 86 /** 87 * max_contaminant_is_contaminant - Test if CC was toggled due to contaminant 88 * 89 * @chip: Handle to a struct max_tcpci_chip 90 * @disconnect_while_debounce: Whether the disconnect was detected when CC 91 * pins were debouncing 92 * @cc_handled: Returns whether or not update to CC status was handled here 93 * 94 * Determine if a contaminant was detected. 95 * 96 * Returns: true if a contaminant was detected, false otherwise. cc_handled 97 * is updated to reflect whether or not further CC handling is required. 98 */ 99 bool max_contaminant_is_contaminant(struct max_tcpci_chip *chip, bool disconnect_while_debounce, 100 bool *cc_handled); 101 102 #endif // TCPCI_MAXIM_H_ 103