xref: /linux/drivers/usb/typec/tcpm/tcpci_maxim.h (revision 8004d08330e1aa7ae797778509e864f7ac3da687)
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 };
64 
max_tcpci_read16(struct max_tcpci_chip * chip,unsigned int reg,u16 * val)65 static inline int max_tcpci_read16(struct max_tcpci_chip *chip, unsigned int reg, u16 *val)
66 {
67 	return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u16));
68 }
69 
max_tcpci_write16(struct max_tcpci_chip * chip,unsigned int reg,u16 val)70 static inline int max_tcpci_write16(struct max_tcpci_chip *chip, unsigned int reg, u16 val)
71 {
72 	return regmap_raw_write(chip->data.regmap, reg, &val, sizeof(u16));
73 }
74 
max_tcpci_read8(struct max_tcpci_chip * chip,unsigned int reg,u8 * val)75 static inline int max_tcpci_read8(struct max_tcpci_chip *chip, unsigned int reg, u8 *val)
76 {
77 	return regmap_raw_read(chip->data.regmap, reg, val, sizeof(u8));
78 }
79 
max_tcpci_write8(struct max_tcpci_chip * chip,unsigned int reg,u8 val)80 static inline int max_tcpci_write8(struct max_tcpci_chip *chip, unsigned int reg, u8 val)
81 {
82 	return regmap_raw_write(chip->data.regmap, reg, &val, sizeof(u8));
83 }
84 
85 /**
86  * max_contaminant_is_contaminant - Test if CC was toggled due to contaminant
87  *
88  * @chip: Handle to a struct max_tcpci_chip
89  * @disconnect_while_debounce: Whether the disconnect was detected when CC
90  *      		       pins were debouncing
91  * @cc_handled: Returns whether or not update to CC status was handled here
92  *
93  * Determine if a contaminant was detected.
94  *
95  * Returns: true if a contaminant was detected, false otherwise. cc_handled
96  * is updated to reflect whether or not further CC handling is required.
97  */
98 bool max_contaminant_is_contaminant(struct max_tcpci_chip *chip, bool disconnect_while_debounce,
99 				    bool *cc_handled);
100 
101 #endif  // TCPCI_MAXIM_H_
102