| 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 | |
| 10 | struct device; |
| 11 | struct typec_mux; |
| 12 | struct typec_mux_dev; |
| 13 | struct typec_switch; |
| 14 | struct typec_switch_dev; |
| 15 | struct typec_altmode; |
| 16 | struct fwnode_handle; |
| 17 | |
| 18 | typedef int (*typec_switch_set_fn_t)(struct typec_switch_dev *sw, |
| 19 | enum typec_orientation orientation); |
| 20 | |
| 21 | struct 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 | |
| 30 | struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode); |
| 31 | void typec_switch_put(struct typec_switch *sw); |
| 32 | int typec_switch_set(struct typec_switch *sw, |
| 33 | enum typec_orientation orientation); |
| 34 | |
| 35 | struct typec_switch_dev * |
| 36 | typec_switch_register(struct device *parent, |
| 37 | const struct typec_switch_desc *desc); |
| 38 | void typec_switch_unregister(struct typec_switch_dev *sw); |
| 39 | |
| 40 | void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data); |
| 41 | void *typec_switch_get_drvdata(struct typec_switch_dev *sw); |
| 42 | |
| 43 | #else |
| 44 | |
| 45 | static inline struct typec_switch * |
| 46 | fwnode_typec_switch_get(struct fwnode_handle *fwnode) |
| 47 | { |
| 48 | return NULL; |
| 49 | } |
| 50 | |
| 51 | static inline void typec_switch_put(struct typec_switch *sw) {} |
| 52 | |
| 53 | static inline int typec_switch_set(struct typec_switch *sw, |
| 54 | enum typec_orientation orientation) |
| 55 | { |
| 56 | return 0; |
| 57 | } |
| 58 | |
| 59 | static inline struct typec_switch_dev * |
| 60 | typec_switch_register(struct device *parent, |
| 61 | const struct typec_switch_desc *desc) |
| 62 | { |
| 63 | return ERR_PTR(-EOPNOTSUPP); |
| 64 | } |
| 65 | |
| 66 | static inline void typec_switch_unregister(struct typec_switch_dev *sw) {} |
| 67 | |
| 68 | static inline void typec_switch_set_drvdata(struct typec_switch_dev *sw, void *data) {} |
| 69 | static inline void *typec_switch_get_drvdata(struct typec_switch_dev *sw) |
| 70 | { |
| 71 | return ERR_PTR(-EOPNOTSUPP); |
| 72 | } |
| 73 | |
| 74 | #endif /* CONFIG_TYPEC */ |
| 75 | |
| 76 | static inline struct typec_switch *typec_switch_get(struct device *dev) |
| 77 | { |
| 78 | return fwnode_typec_switch_get(dev_fwnode(dev)); |
| 79 | } |
| 80 | |
| 81 | struct typec_mux_state { |
| 82 | struct typec_altmode *alt; |
| 83 | unsigned long mode; |
| 84 | void *data; |
| 85 | }; |
| 86 | |
| 87 | typedef int (*typec_mux_set_fn_t)(struct typec_mux_dev *mux, |
| 88 | struct typec_mux_state *state); |
| 89 | |
| 90 | struct 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 | |
| 99 | struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode); |
| 100 | void typec_mux_put(struct typec_mux *mux); |
| 101 | int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state); |
| 102 | |
| 103 | struct typec_mux_dev * |
| 104 | typec_mux_register(struct device *parent, const struct typec_mux_desc *desc); |
| 105 | void typec_mux_unregister(struct typec_mux_dev *mux); |
| 106 | |
| 107 | void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data); |
| 108 | void *typec_mux_get_drvdata(struct typec_mux_dev *mux); |
| 109 | |
| 110 | #else |
| 111 | |
| 112 | static inline struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode) |
| 113 | { |
| 114 | return NULL; |
| 115 | } |
| 116 | |
| 117 | static inline void typec_mux_put(struct typec_mux *mux) {} |
| 118 | |
| 119 | static inline int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state) |
| 120 | { |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | static inline struct typec_mux_dev * |
| 125 | typec_mux_register(struct device *parent, const struct typec_mux_desc *desc) |
| 126 | { |
| 127 | return ERR_PTR(-EOPNOTSUPP); |
| 128 | } |
| 129 | static inline void typec_mux_unregister(struct typec_mux_dev *mux) {} |
| 130 | |
| 131 | static inline void typec_mux_set_drvdata(struct typec_mux_dev *mux, void *data) {} |
| 132 | static inline void *typec_mux_get_drvdata(struct typec_mux_dev *mux) |
| 133 | { |
| 134 | return ERR_PTR(-EOPNOTSUPP); |
| 135 | } |
| 136 | |
| 137 | #endif /* CONFIG_TYPEC */ |
| 138 | |
| 139 | static 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 */ |
| 145 | |