Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 
0003 #ifndef __USB_TYPEC_MUX
0004 #define __USB_TYPEC_MUX
0005 
0006 #include <linux/property.h>
0007 #include <linux/usb/typec.h>
0008 
0009 struct device;
0010 struct typec_mux;
0011 struct typec_mux_dev;
0012 struct typec_switch;
0013 struct typec_switch_dev;
0014 struct typec_altmode;
0015 struct fwnode_handle;
0016 
0017 typedef int (*typec_switch_set_fn_t)(struct typec_switch_dev *sw,
0018                      enum typec_orientation orientation);
0019 
0020 struct typec_switch_desc {
0021     struct fwnode_handle *fwnode;
0022     typec_switch_set_fn_t set;
0023     const char *name;
0024     void *drvdata;
0025 };
0026 
0027 struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode);
0028 void typec_switch_put(struct typec_switch *sw);
0029 int typec_switch_set(struct typec_switch *sw,
0030              enum typec_orientation orientation);
0031 
0032 static inline struct typec_switch *typec_switch_get(struct device *dev)
0033 {
0034     return fwnode_typec_switch_get(dev_fwnode(dev));
0035 }
0036 
0037 struct typec_switch_dev *
0038 typec_switch_register(struct device *parent,
0039               const struct typec_switch_desc *desc);
0040 void typec_switch_unregister(struct typec_switch_dev *sw);
0041 
0042 void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data);
0043 void *typec_switch_get_drvdata(struct typec_switch_dev *sw);
0044 
0045 struct typec_mux_state {
0046     struct typec_altmode *alt;
0047     unsigned long mode;
0048     void *data;
0049 };
0050 
0051 typedef int (*typec_mux_set_fn_t)(struct typec_mux_dev *mux,
0052                   struct typec_mux_state *state);
0053 
0054 struct typec_mux_desc {
0055     struct fwnode_handle *fwnode;
0056     typec_mux_set_fn_t set;
0057     const char *name;
0058     void *drvdata;
0059 };
0060 
0061 #if IS_ENABLED(CONFIG_TYPEC)
0062 
0063 struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode,
0064                        const struct typec_altmode_desc *desc);
0065 void typec_mux_put(struct typec_mux *mux);
0066 int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state);
0067 
0068 struct typec_mux_dev *
0069 typec_mux_register(struct device *parent, const struct typec_mux_desc *desc);
0070 void typec_mux_unregister(struct typec_mux_dev *mux);
0071 
0072 void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data);
0073 void *typec_mux_get_drvdata(struct typec_mux_dev *mux);
0074 
0075 #else
0076 
0077 static inline struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode,
0078                        const struct typec_altmode_desc *desc)
0079 {
0080     return NULL;
0081 }
0082 
0083 static inline void typec_mux_put(struct typec_mux *mux) {}
0084 
0085 static inline int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state)
0086 {
0087     return 0;
0088 }
0089 
0090 static inline struct typec_mux_dev *
0091 typec_mux_register(struct device *parent, const struct typec_mux_desc *desc)
0092 {
0093     return ERR_PTR(-EOPNOTSUPP);
0094 }
0095 static inline void typec_mux_unregister(struct typec_mux_dev *mux) {}
0096 
0097 static inline void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data) {}
0098 static inline void *typec_mux_get_drvdata(struct typec_mux_dev *mux)
0099 {
0100     return ERR_PTR(-EOPNOTSUPP);
0101 }
0102 
0103 #endif /* CONFIG_TYPEC */
0104 
0105 static inline struct typec_mux *
0106 typec_mux_get(struct device *dev, const struct typec_altmode_desc *desc)
0107 {
0108     return fwnode_typec_mux_get(dev_fwnode(dev), desc);
0109 }
0110 
0111 #endif /* __USB_TYPEC_MUX */