File Index
Files and directories
Sign in
FILE

typec_mux.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/usb/typec_mux.h C
  1// SPDX-License-Identifier: GPL-2.0
  2
  3#ifndef __USB_TYPEC_MUX
  4#define __USB_TYPEC_MUX
  5
  6#include <linux/err.h>
  7#include <linux/property.h>
  8#include <linux/usb/typec.h>
  9
 10struct device;
 11struct typec_mux;
 12struct typec_mux_dev;
 13struct typec_switch;
 14struct typec_switch_dev;
 15struct typec_altmode;
 16struct fwnode_handle;
 17
 18typedef int (*typec_switch_set_fn_t)(struct typec_switch_dev *sw,
 19				     enum typec_orientation orientation);
 20
 21struct typec_switch_desc {
 22	struct fwnode_handle *fwnode;
 23	typec_switch_set_fn_t set;
 24	const char *name;
 25	void *drvdata;
 26};
 27
 28#if IS_ENABLED(CONFIG_TYPEC)
 29
 30struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode);
 31void typec_switch_put(struct typec_switch *sw);
 32int typec_switch_set(struct typec_switch *sw,
 33		     enum typec_orientation orientation);
 34
 35struct typec_switch_dev *
 36typec_switch_register(struct device *parent,
 37		      const struct typec_switch_desc *desc);
 38void typec_switch_unregister(struct typec_switch_dev *sw);
 39
 40void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data);
 41void *typec_switch_get_drvdata(struct typec_switch_dev *sw);
 42
 43#else
 44
 45static inline struct typec_switch *
 46fwnode_typec_switch_get(struct fwnode_handle *fwnode)
 47{
 48	return NULL;
 49}
 50
 51static inline void typec_switch_put(struct typec_switch *sw) {}
 52
 53static inline int typec_switch_set(struct typec_switch *sw,
 54				   enum typec_orientation orientation)
 55{
 56	return 0;
 57}
 58
 59static inline struct typec_switch_dev *
 60typec_switch_register(struct device *parent,
 61		      const struct typec_switch_desc *desc)
 62{
 63	return ERR_PTR(-EOPNOTSUPP);
 64}
 65
 66static inline void typec_switch_unregister(struct typec_switch_dev *sw) {}
 67
 68static inline void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data) {}
 69static inline void *typec_switch_get_drvdata(struct typec_switch_dev *sw)
 70{
 71	return ERR_PTR(-EOPNOTSUPP);
 72}
 73
 74#endif /* CONFIG_TYPEC */
 75
 76static inline struct typec_switch *typec_switch_get(struct device *dev)
 77{
 78	return fwnode_typec_switch_get(dev_fwnode(dev));
 79}
 80
 81struct typec_mux_state {
 82	struct typec_altmode *alt;
 83	unsigned long mode;
 84	void *data;
 85};
 86
 87typedef int (*typec_mux_set_fn_t)(struct typec_mux_dev *mux,
 88				  struct typec_mux_state *state);
 89
 90struct typec_mux_desc {
 91	struct fwnode_handle *fwnode;
 92	typec_mux_set_fn_t set;
 93	const char *name;
 94	void *drvdata;
 95};
 96
 97#if IS_ENABLED(CONFIG_TYPEC)
 98
 99struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode);
100void typec_mux_put(struct typec_mux *mux);
101int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state);
102
103struct typec_mux_dev *
104typec_mux_register(struct device *parent, const struct typec_mux_desc *desc);
105void typec_mux_unregister(struct typec_mux_dev *mux);
106
107void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data);
108void *typec_mux_get_drvdata(struct typec_mux_dev *mux);
109
110#else
111
112static inline struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode)
113{
114	return NULL;
115}
116
117static inline void typec_mux_put(struct typec_mux *mux) {}
118
119static inline int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state)
120{
121	return 0;
122}
123
124static inline struct typec_mux_dev *
125typec_mux_register(struct device *parent, const struct typec_mux_desc *desc)
126{
127	return ERR_PTR(-EOPNOTSUPP);
128}
129static inline void typec_mux_unregister(struct typec_mux_dev *mux) {}
130
131static inline void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data) {}
132static inline void *typec_mux_get_drvdata(struct typec_mux_dev *mux)
133{
134	return ERR_PTR(-EOPNOTSUPP);
135}
136
137#endif /* CONFIG_TYPEC */
138
139static inline struct typec_mux *typec_mux_get(struct device *dev)
140{
141	return fwnode_typec_mux_get(dev_fwnode(dev));
142}
143
144#endif /* __USB_TYPEC_MUX */
~/ Read-only file preview.