Merge tag 'for-5.13-rc6-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave...
[linux-2.6-microblaze.git] / drivers / usb / typec / class.h
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
9 struct typec_mux;
10 struct typec_switch;
11
12 struct typec_plug {
13         struct device                   dev;
14         enum typec_plug_index           index;
15         struct ida                      mode_ids;
16         int                             num_altmodes;
17 };
18
19 struct 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
27 struct 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
38 struct typec_port {
39         unsigned int                    id;
40         struct device                   dev;
41         struct ida                      mode_ids;
42
43         int                             prefer_role;
44         enum typec_data_role            data_role;
45         enum typec_role                 pwr_role;
46         enum typec_role                 vconn_role;
47         enum typec_pwr_opmode           pwr_opmode;
48         enum typec_port_type            port_type;
49         struct mutex                    port_type_lock;
50
51         enum typec_orientation          orientation;
52         struct typec_switch             *sw;
53         struct typec_mux                *mux;
54
55         const struct typec_capability   *cap;
56         const struct typec_operations   *ops;
57
58         struct list_head                port_list;
59         struct mutex                    port_list_lock; /* Port list lock */
60
61         void                            *pld;
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
69 extern const struct device_type typec_partner_dev_type;
70 extern const struct device_type typec_cable_dev_type;
71 extern const struct device_type typec_plug_dev_type;
72 extern 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
79 extern struct class typec_mux_class;
80 extern struct class typec_class;
81
82 int typec_link_ports(struct typec_port *connector);
83 void typec_unlink_ports(struct typec_port *connector);
84
85 #endif /* __USB_TYPEC_CLASS__ */