• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef __USB_TYPEC_CLASS__
4 #define __USB_TYPEC_CLASS__
5 
6 #include <linux/device.h>
7 #include <linux/usb/typec.h>
8 #include <linux/android_kabi.h>
9 
10 struct typec_mux;
11 struct typec_switch;
12 
13 struct typec_plug {
14 	struct device			dev;
15 	enum typec_plug_index		index;
16 	struct ida			mode_ids;
17 	int				num_altmodes;
18 	ANDROID_KABI_RESERVE(1);
19 };
20 
21 struct typec_cable {
22 	struct device			dev;
23 	enum typec_plug_type		type;
24 	struct usb_pd_identity		*identity;
25 	unsigned int			active:1;
26 	u16				pd_revision; /* 0300H = "3.0" */
27 	ANDROID_KABI_RESERVE(1);
28 };
29 
30 struct typec_partner {
31 	struct device			dev;
32 	unsigned int			usb_pd:1;
33 	struct usb_pd_identity		*identity;
34 	enum typec_accessory		accessory;
35 	struct ida			mode_ids;
36 	int				num_altmodes;
37 	u16				pd_revision; /* 0300H = "3.0" */
38 	enum usb_pd_svdm_ver		svdm_version;
39 	ANDROID_KABI_RESERVE(1);
40 };
41 
42 struct typec_port {
43 	unsigned int			id;
44 	struct device			dev;
45 	struct ida			mode_ids;
46 
47 	int				prefer_role;
48 	enum typec_data_role		data_role;
49 	enum typec_role			pwr_role;
50 	enum typec_role			vconn_role;
51 	enum typec_pwr_opmode		pwr_opmode;
52 	enum typec_port_type		port_type;
53 	struct mutex			port_type_lock;
54 
55 	enum typec_orientation		orientation;
56 	struct typec_switch		*sw;
57 	struct typec_mux		*mux;
58 
59 	const struct typec_capability	*cap;
60 	const struct typec_operations   *ops;
61 
62 	struct list_head		port_list;
63 	struct mutex			port_list_lock; /* Port list lock */
64 
65 	void				*pld;
66 	ANDROID_KABI_RESERVE(1);
67 };
68 
69 #define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev)
70 #define to_typec_plug(_dev_) container_of(_dev_, struct typec_plug, dev)
71 #define to_typec_cable(_dev_) container_of(_dev_, struct typec_cable, dev)
72 #define to_typec_partner(_dev_) container_of(_dev_, struct typec_partner, dev)
73 
74 extern const struct device_type typec_partner_dev_type;
75 extern const struct device_type typec_cable_dev_type;
76 extern const struct device_type typec_plug_dev_type;
77 extern const struct device_type typec_port_dev_type;
78 
79 #define is_typec_partner(dev) ((dev)->type == &typec_partner_dev_type)
80 #define is_typec_cable(dev) ((dev)->type == &typec_cable_dev_type)
81 #define is_typec_plug(dev) ((dev)->type == &typec_plug_dev_type)
82 #define is_typec_port(dev) ((dev)->type == &typec_port_dev_type)
83 
84 extern struct class typec_mux_class;
85 extern struct class typec_class;
86 
87 int typec_link_ports(struct typec_port *connector);
88 void typec_unlink_ports(struct typec_port *connector);
89 
90 #endif /* __USB_TYPEC_CLASS__ */
91