Merge tag 'arm64-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux
[linux-2.6-block.git] / include / linux / usb / typec_mux.h
CommitLineData
bdecb33a
HK
1// SPDX-License-Identifier: GPL-2.0
2
3#ifndef __USB_TYPEC_MUX
4#define __USB_TYPEC_MUX
5
d1c6a769 6#include <linux/property.h>
bdecb33a
HK
7#include <linux/usb/typec.h>
8
9struct device;
3370db35 10struct typec_mux;
713fd49b 11struct typec_mux_dev;
3370db35 12struct typec_switch;
713fd49b 13struct typec_switch_dev;
87e3daa0 14struct typec_altmode;
3370db35 15struct fwnode_handle;
bdecb33a 16
713fd49b 17typedef int (*typec_switch_set_fn_t)(struct typec_switch_dev *sw,
3370db35 18 enum typec_orientation orientation);
bdecb33a 19
3370db35
HK
20struct typec_switch_desc {
21 struct fwnode_handle *fwnode;
22 typec_switch_set_fn_t set;
ef441dd6 23 const char *name;
3370db35 24 void *drvdata;
bdecb33a
HK
25};
26
d1c6a769 27struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode);
bdecb33a 28void typec_switch_put(struct typec_switch *sw);
774a9df6
HK
29int typec_switch_set(struct typec_switch *sw,
30 enum typec_orientation orientation);
31
d1c6a769
HK
32static inline struct typec_switch *typec_switch_get(struct device *dev)
33{
34 return fwnode_typec_switch_get(dev_fwnode(dev));
35}
36
713fd49b 37struct typec_switch_dev *
3370db35
HK
38typec_switch_register(struct device *parent,
39 const struct typec_switch_desc *desc);
713fd49b 40void typec_switch_unregister(struct typec_switch_dev *sw);
bdecb33a 41
713fd49b
BA
42void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data);
43void *typec_switch_get_drvdata(struct typec_switch_dev *sw);
3370db35 44
87e3daa0
HK
45struct typec_mux_state {
46 struct typec_altmode *alt;
47 unsigned long mode;
48 void *data;
49};
50
713fd49b 51typedef int (*typec_mux_set_fn_t)(struct typec_mux_dev *mux,
87e3daa0 52 struct typec_mux_state *state);
3370db35
HK
53
54struct typec_mux_desc {
55 struct fwnode_handle *fwnode;
56 typec_mux_set_fn_t set;
ef441dd6 57 const char *name;
3370db35
HK
58 void *drvdata;
59};
60
a37599eb
PM
61#if IS_ENABLED(CONFIG_TYPEC)
62
3524fe31 63struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode);
bdecb33a 64void typec_mux_put(struct typec_mux *mux);
774a9df6
HK
65int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state);
66
713fd49b 67struct typec_mux_dev *
3370db35 68typec_mux_register(struct device *parent, const struct typec_mux_desc *desc);
713fd49b 69void typec_mux_unregister(struct typec_mux_dev *mux);
bdecb33a 70
713fd49b
BA
71void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data);
72void *typec_mux_get_drvdata(struct typec_mux_dev *mux);
3370db35 73
a37599eb
PM
74#else
75
243ff7e6 76static inline struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode)
a37599eb
PM
77{
78 return NULL;
79}
80
81static inline void typec_mux_put(struct typec_mux *mux) {}
82
83static inline int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state)
84{
85 return 0;
86}
87
88static inline struct typec_mux_dev *
89typec_mux_register(struct device *parent, const struct typec_mux_desc *desc)
90{
91 return ERR_PTR(-EOPNOTSUPP);
92}
93static inline void typec_mux_unregister(struct typec_mux_dev *mux) {}
94
95static inline void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data) {}
96static inline void *typec_mux_get_drvdata(struct typec_mux_dev *mux)
97{
98 return ERR_PTR(-EOPNOTSUPP);
99}
100
101#endif /* CONFIG_TYPEC */
102
3524fe31 103static inline struct typec_mux *typec_mux_get(struct device *dev)
a37599eb 104{
3524fe31 105 return fwnode_typec_mux_get(dev_fwnode(dev));
a37599eb
PM
106}
107
bdecb33a 108#endif /* __USB_TYPEC_MUX */