Loading...
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
9struct typec_mux;
10struct typec_switch;
11struct usb_device;
12
13struct typec_plug {
14 struct device dev;
15 enum typec_plug_index index;
16 struct ida mode_ids;
17 int num_altmodes;
18};
19
20struct typec_cable {
21 struct device dev;
22 enum typec_plug_type type;
23 struct usb_pd_identity *identity;
24 unsigned int active:1;
25 u16 pd_revision; /* 0300H = "3.0" */
26 enum usb_pd_svdm_ver svdm_version;
27};
28
29struct typec_partner {
30 struct device dev;
31 unsigned int usb_pd:1;
32 struct usb_pd_identity *identity;
33 enum typec_accessory accessory;
34 struct ida mode_ids;
35 int num_altmodes;
36 u16 pd_revision; /* 0300H = "3.0" */
37 enum usb_pd_svdm_ver svdm_version;
38
39 struct usb_power_delivery *pd;
40
41 void (*attach)(struct typec_partner *partner, struct device *dev);
42 void (*deattach)(struct typec_partner *partner, struct device *dev);
43};
44
45struct typec_port {
46 unsigned int id;
47 struct device dev;
48 struct ida mode_ids;
49
50 struct usb_power_delivery *pd;
51
52 int prefer_role;
53 enum typec_data_role data_role;
54 enum typec_role pwr_role;
55 enum typec_role vconn_role;
56 enum typec_pwr_opmode pwr_opmode;
57 enum typec_port_type port_type;
58 struct mutex port_type_lock;
59
60 enum typec_orientation orientation;
61 struct typec_switch *sw;
62 struct typec_mux *mux;
63 struct typec_retimer *retimer;
64
65 const struct typec_capability *cap;
66 const struct typec_operations *ops;
67
68 struct typec_connector con;
69
70 /*
71 * REVISIT: Only USB devices for now. If there are others, these need to
72 * be converted into a list.
73 *
74 * NOTE: These may be registered first before the typec_partner, so they
75 * will always have to be kept here instead of struct typec_partner.
76 */
77 struct device *usb2_dev;
78 struct device *usb3_dev;
79};
80
81#define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev)
82#define to_typec_plug(_dev_) container_of(_dev_, struct typec_plug, dev)
83#define to_typec_cable(_dev_) container_of(_dev_, struct typec_cable, dev)
84#define to_typec_partner(_dev_) container_of(_dev_, struct typec_partner, dev)
85
86extern const struct device_type typec_partner_dev_type;
87extern const struct device_type typec_cable_dev_type;
88extern const struct device_type typec_plug_dev_type;
89extern const struct device_type typec_port_dev_type;
90
91#define is_typec_partner(dev) ((dev)->type == &typec_partner_dev_type)
92#define is_typec_cable(dev) ((dev)->type == &typec_cable_dev_type)
93#define is_typec_plug(dev) ((dev)->type == &typec_plug_dev_type)
94#define is_typec_port(dev) ((dev)->type == &typec_port_dev_type)
95
96extern const struct class typec_mux_class;
97extern const struct class retimer_class;
98extern const struct class typec_class;
99
100#if defined(CONFIG_ACPI)
101int typec_link_ports(struct typec_port *connector);
102void typec_unlink_ports(struct typec_port *connector);
103#else
104static inline int typec_link_ports(struct typec_port *connector) { return 0; }
105static inline void typec_unlink_ports(struct typec_port *connector) { }
106#endif
107
108#endif /* __USB_TYPEC_CLASS__ */
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
9struct typec_mux;
10struct typec_switch;
11
12struct typec_plug {
13 struct device dev;
14 enum typec_plug_index index;
15 struct ida mode_ids;
16 int num_altmodes;
17};
18
19struct typec_cable {
20 struct device dev;
21 enum typec_plug_type type;
22 struct usb_pd_identity *identity;
23 unsigned int active:1;
24 u16 pd_revision; /* 0300H = "3.0" */
25};
26
27struct typec_partner {
28 struct device dev;
29 unsigned int usb_pd:1;
30 struct usb_pd_identity *identity;
31 enum typec_accessory accessory;
32 struct ida mode_ids;
33 int num_altmodes;
34 u16 pd_revision; /* 0300H = "3.0" */
35 enum usb_pd_svdm_ver svdm_version;
36
37 struct usb_power_delivery *pd;
38};
39
40struct typec_port {
41 unsigned int id;
42 struct device dev;
43 struct ida mode_ids;
44
45 struct usb_power_delivery *pd;
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 struct typec_retimer *retimer;
59
60 const struct typec_capability *cap;
61 const struct typec_operations *ops;
62};
63
64#define to_typec_port(_dev_) container_of(_dev_, struct typec_port, dev)
65#define to_typec_plug(_dev_) container_of(_dev_, struct typec_plug, dev)
66#define to_typec_cable(_dev_) container_of(_dev_, struct typec_cable, dev)
67#define to_typec_partner(_dev_) container_of(_dev_, struct typec_partner, dev)
68
69extern const struct device_type typec_partner_dev_type;
70extern const struct device_type typec_cable_dev_type;
71extern const struct device_type typec_plug_dev_type;
72extern const struct device_type typec_port_dev_type;
73
74#define is_typec_partner(dev) ((dev)->type == &typec_partner_dev_type)
75#define is_typec_cable(dev) ((dev)->type == &typec_cable_dev_type)
76#define is_typec_plug(dev) ((dev)->type == &typec_plug_dev_type)
77#define is_typec_port(dev) ((dev)->type == &typec_port_dev_type)
78
79extern struct class typec_mux_class;
80extern struct class retimer_class;
81extern struct class typec_class;
82
83#if defined(CONFIG_ACPI)
84int typec_link_ports(struct typec_port *connector);
85void typec_unlink_ports(struct typec_port *connector);
86#else
87static inline int typec_link_ports(struct typec_port *connector) { return 0; }
88static inline void typec_unlink_ports(struct typec_port *connector) { }
89#endif
90
91#endif /* __USB_TYPEC_CLASS__ */