xref: /linux/drivers/usb/typec/tcpm/tcpci_maxim.h (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
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 ULTRA_LOW_POWER_MODE                    1
25 #define CCRPCTRL                                GENMASK(2, 0)
26 #define UA_1_SRC                                1
27 #define UA_80_SRC                               3
28 
29 #define TCPC_VENDOR_CC_CTRL3                    0x8e
30 #define CCWTRDEB                                GENMASK(7, 6)
31 #define CCWTRDEB_1MS                            1
32 #define CCWTRSEL                                GENMASK(5, 3)
33 #define CCWTRSEL_1V                             0x4
34 #define CCLADDERDIS                             BIT(2)
35 #define WTRCYCLE                                GENMASK(0, 0)
36 #define WTRCYCLE_2_4_S                          0
37 #define WTRCYCLE_4_8_S                          1
38 
39 #define TCPC_VENDOR_ADC_CTRL1                   0x91
40 #define ADCINSEL                                GENMASK(7, 5)
41 #define ADCEN                                   BIT(0)
42 
43 enum contamiant_state {
44 	NOT_DETECTED,
45 	DETECTED,
46 	SINK,
47 };
48 
49 /*
50  * @potential_contaminant:
51  *		Last returned result to tcpm indicating whether the TCPM port
52  *		has potential contaminant.
53  */
54 struct max_tcpci_chip {
55 	struct tcpci_data data;
56 	struct tcpci *tcpci;
57 	struct device *dev;
58 	struct i2c_client *client;
59 	struct tcpm_port *port;
60 	enum contamiant_state contaminant_state;
61 	bool veto_vconn_swap;
62 };
63 
max_tcpci_read16(struct max_tcpci_chip * chip,unsigned int reg,u16 * val)64 static inline int max_tcpci_read16(struct max_tcpci_chip *chip, unsigned int reg, u16 *val)
65 {
66 	return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u16));
67 }
68 
max_tcpci_write16(struct max_tcpci_chip * chip,unsigned int reg,u16 val)69 static inline int max_tcpci_write16(struct max_tcpci_chip *chip, unsigned int reg, u16 val)
70 {
71 	return regmap_raw_write(chip->data.regmap, reg, &val, sizeof(u16));
72 }
73 
max_tcpci_read8(struct max_tcpci_chip * chip,unsigned int reg,u8 * val)74 static inline int max_tcpci_read8(struct max_tcpci_chip *chip, unsigned int reg, u8 *val)
75 {
76 	return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u8));
77 }
78 
max_tcpci_write8(struct max_tcpci_chip * chip,unsigned int reg,u8 val)79 static inline int max_tcpci_write8(struct max_tcpci_chip *chip, unsigned int reg, u8 val)
80 {
81 	return regmap_raw_write(chip->data.regmap, reg, &val, sizeof(u8));
82 }
83 
84 /**
85  * max_contaminant_is_contaminant - Test if CC was toggled due to contaminant
86  *
87  * @chip: Handle to a struct max_tcpci_chip
88  * @disconnect_while_debounce: Whether the disconnect was detected when CC
89  *      		       pins were debouncing
90  * @cc_handled: Returns whether or not update to CC status was handled here
91  *
92  * Determine if a contaminant was detected.
93  *
94  * Returns: true if a contaminant was detected, false otherwise. cc_handled
95  * is updated to reflect whether or not further CC handling is required.
96  */
97 bool max_contaminant_is_contaminant(struct max_tcpci_chip *chip, bool disconnect_while_debounce,
98 				    bool *cc_handled);
99 
100 #endif  // TCPCI_MAXIM_H_
101