1
2
3#ifndef __USB_TYPEC_ALTMODE_H
4#define __USB_TYPEC_ALTMODE_H
5
6#include <linux/mod_devicetable.h>
7#include <linux/usb/typec.h>
8#include <linux/device.h>
9
10#define MODE_DISCOVERY_MAX 6
11
12struct typec_altmode_ops;
13
14
15
16
17
18
19
20
21
22
23
24struct typec_altmode {
25 struct device dev;
26 u16 svid;
27 int mode;
28 u32 vdo;
29 unsigned int active:1;
30
31 char *desc;
32 const struct typec_altmode_ops *ops;
33};
34
35#define to_typec_altmode(d) container_of(d, struct typec_altmode, dev)
36
37static inline void typec_altmode_set_drvdata(struct typec_altmode *altmode,
38 void *data)
39{
40 dev_set_drvdata(&altmode->dev, data);
41}
42
43static inline void *typec_altmode_get_drvdata(struct typec_altmode *altmode)
44{
45 return dev_get_drvdata(&altmode->dev);
46}
47
48
49
50
51
52
53
54
55
56
57struct typec_altmode_ops {
58 int (*enter)(struct typec_altmode *altmode);
59 int (*exit)(struct typec_altmode *altmode);
60 void (*attention)(struct typec_altmode *altmode, u32 vdo);
61 int (*vdm)(struct typec_altmode *altmode, const u32 hdr,
62 const u32 *vdo, int cnt);
63 int (*notify)(struct typec_altmode *altmode, unsigned long conf,
64 void *data);
65 int (*activate)(struct typec_altmode *altmode, int activate);
66};
67
68int typec_altmode_enter(struct typec_altmode *altmode);
69int typec_altmode_exit(struct typec_altmode *altmode);
70void typec_altmode_attention(struct typec_altmode *altmode, u32 vdo);
71int typec_altmode_vdm(struct typec_altmode *altmode,
72 const u32 header, const u32 *vdo, int count);
73int typec_altmode_notify(struct typec_altmode *altmode, unsigned long conf,
74 void *data);
75const struct typec_altmode *
76typec_altmode_get_partner(struct typec_altmode *altmode);
77
78
79
80
81
82
83enum {
84 TYPEC_STATE_SAFE,
85 TYPEC_STATE_USB,
86 TYPEC_STATE_MODAL,
87};
88
89
90
91
92
93
94
95
96
97
98
99enum {
100 TYPEC_MODE_AUDIO = TYPEC_STATE_MODAL,
101 TYPEC_MODE_DEBUG,
102};
103
104#define TYPEC_MODAL_STATE(_state_) ((_state_) + TYPEC_STATE_MODAL)
105
106struct typec_altmode *typec_altmode_get_plug(struct typec_altmode *altmode,
107 enum typec_plug_index index);
108void typec_altmode_put_plug(struct typec_altmode *plug);
109
110struct typec_altmode *typec_match_altmode(struct typec_altmode **altmodes,
111 size_t n, u16 svid, u8 mode);
112
113struct typec_altmode *
114typec_altmode_register_notifier(struct device *dev, u16 svid, u8 mode,
115 struct notifier_block *nb);
116
117void typec_altmode_unregister_notifier(struct typec_altmode *adev,
118 struct notifier_block *nb);
119
120
121
122
123
124static inline enum typec_orientation
125typec_altmode_get_orientation(struct typec_altmode *altmode)
126{
127 return typec_get_orientation(typec_altmode2port(altmode));
128}
129
130
131
132
133
134
135
136
137
138
139
140struct typec_altmode_driver {
141 const struct typec_device_id *id_table;
142 int (*probe)(struct typec_altmode *altmode);
143 void (*remove)(struct typec_altmode *altmode);
144 struct device_driver driver;
145};
146
147#define to_altmode_driver(d) container_of(d, struct typec_altmode_driver, \
148 driver)
149
150#define typec_altmode_register_driver(drv) \
151 __typec_altmode_register_driver(drv, THIS_MODULE)
152int __typec_altmode_register_driver(struct typec_altmode_driver *drv,
153 struct module *module);
154void typec_altmode_unregister_driver(struct typec_altmode_driver *drv);
155
156#define module_typec_altmode_driver(__typec_altmode_driver) \
157 module_driver(__typec_altmode_driver, typec_altmode_register_driver, \
158 typec_altmode_unregister_driver)
159
160#endif
161