2 * Copyright 2015-2017 Google, Inc
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #ifndef __LINUX_USB_TCPM_H
16 #define __LINUX_USB_TCPM_H
18 #include <linux/bitops.h>
19 #include <linux/usb/typec.h>
22 enum typec_cc_status {
31 enum typec_cc_polarity {
36 /* Time to wait for TCPC to complete transmit */
37 #define PD_T_TCPC_TX_TIMEOUT 100 /* in ms */
38 #define PD_ROLE_SWAP_TIMEOUT (MSEC_PER_SEC * 10)
40 enum tcpm_transmit_status {
42 TCPC_TX_DISCARDED = 1,
46 enum tcpm_transmit_type {
48 TCPC_TX_SOP_PRIME = 1,
49 TCPC_TX_SOP_PRIME_PRIME = 2,
50 TCPC_TX_SOP_DEBUG_PRIME = 3,
51 TCPC_TX_SOP_DEBUG_PRIME_PRIME = 4,
52 TCPC_TX_HARD_RESET = 5,
53 TCPC_TX_CABLE_RESET = 6,
54 TCPC_TX_BIST_MODE_2 = 7
59 unsigned int nr_src_pdo;
62 unsigned int nr_snk_pdo;
65 unsigned int nr_snk_vdo;
67 unsigned int max_snk_mv;
68 unsigned int max_snk_ma;
69 unsigned int max_snk_mw;
70 unsigned int operating_snk_mw;
72 enum typec_port_type type;
73 enum typec_role default_role;
74 bool try_role_hw; /* try.{src,snk} implemented in hardware */
76 const struct typec_altmode_desc *alt_modes;
79 enum tcpc_usb_switch {
80 TCPC_USB_SWITCH_CONNECT,
81 TCPC_USB_SWITCH_DISCONNECT,
82 TCPC_USB_SWITCH_RESTORE, /* TODO FIXME */
85 /* Mux state attributes */
86 #define TCPC_MUX_USB_ENABLED BIT(0) /* USB enabled */
87 #define TCPC_MUX_DP_ENABLED BIT(1) /* DP enabled */
88 #define TCPC_MUX_POLARITY_INVERTED BIT(2) /* Polarity inverted */
90 /* Mux modes, decoded to attributes */
92 TYPEC_MUX_NONE = 0, /* Open switch */
93 TYPEC_MUX_USB = TCPC_MUX_USB_ENABLED, /* USB only */
94 TYPEC_MUX_DP = TCPC_MUX_DP_ENABLED, /* DP only */
95 TYPEC_MUX_DOCK = TCPC_MUX_USB_ENABLED | /* Both USB and DP */
100 int (*set)(struct tcpc_mux_dev *dev, enum tcpc_mux_mode mux_mode,
101 enum tcpc_usb_switch usb_config,
102 enum typec_cc_polarity polarity);
108 const struct tcpc_config *config;
110 int (*init)(struct tcpc_dev *dev);
111 int (*get_vbus)(struct tcpc_dev *dev);
113 * This optional callback gets called by the tcpm core when configured
114 * as a snk and cc=Rp-def. This allows the tcpm to provide a fallback
115 * current-limit detection method for the cc=Rp-def case. E.g. some
116 * tcpcs may include BC1.2 charger detection and use that in this case.
118 int (*get_current_limit)(struct tcpc_dev *dev);
119 int (*set_cc)(struct tcpc_dev *dev, enum typec_cc_status cc);
120 int (*get_cc)(struct tcpc_dev *dev, enum typec_cc_status *cc1,
121 enum typec_cc_status *cc2);
122 int (*set_polarity)(struct tcpc_dev *dev,
123 enum typec_cc_polarity polarity);
124 int (*set_vconn)(struct tcpc_dev *dev, bool on);
125 int (*set_vbus)(struct tcpc_dev *dev, bool on, bool charge);
126 int (*set_current_limit)(struct tcpc_dev *dev, u32 max_ma, u32 mv);
127 int (*set_pd_rx)(struct tcpc_dev *dev, bool on);
128 int (*set_roles)(struct tcpc_dev *dev, bool attached,
129 enum typec_role role, enum typec_data_role data);
130 int (*start_drp_toggling)(struct tcpc_dev *dev,
131 enum typec_cc_status cc);
132 int (*try_role)(struct tcpc_dev *dev, int role);
133 int (*pd_transmit)(struct tcpc_dev *dev, enum tcpm_transmit_type type,
134 const struct pd_message *msg);
135 struct tcpc_mux_dev *mux;
140 struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc);
141 void tcpm_unregister_port(struct tcpm_port *port);
143 void tcpm_update_source_capabilities(struct tcpm_port *port, const u32 *pdo,
144 unsigned int nr_pdo);
145 void tcpm_update_sink_capabilities(struct tcpm_port *port, const u32 *pdo,
147 unsigned int max_snk_mv,
148 unsigned int max_snk_ma,
149 unsigned int max_snk_mw,
150 unsigned int operating_snk_mw);
152 void tcpm_vbus_change(struct tcpm_port *port);
153 void tcpm_cc_change(struct tcpm_port *port);
154 void tcpm_pd_receive(struct tcpm_port *port,
155 const struct pd_message *msg);
156 void tcpm_pd_transmit_complete(struct tcpm_port *port,
157 enum tcpm_transmit_status status);
158 void tcpm_pd_hard_reset(struct tcpm_port *port);
159 void tcpm_tcpc_reset(struct tcpm_port *port);
161 #endif /* __LINUX_USB_TCPM_H */