// SPDX-License-Identifier: GPL-2.0 /* * USB Type-C Multiplexer/DeMultiplexer Switch support * * Copyright (C) 2018 Intel Corporation * Author: Heikki Krogerus <[email protected]> * Hans de Goede <[email protected]> */ #include <linux/device.h> #include <linux/list.h> #include <linux/module.h> #include <linux/mutex.h> #include <linux/property.h> #include <linux/slab.h> #include "class.h" #include "mux.h" #define TYPEC_MUX_MAX_DEVS … struct typec_switch { … }; static int switch_fwnode_match(struct device *dev, const void *fwnode) { … } static void *typec_switch_match(const struct fwnode_handle *fwnode, const char *id, void *data) { … } /** * fwnode_typec_switch_get - Find USB Type-C orientation switch * @fwnode: The caller device node * * Finds a switch linked with @dev. Returns a reference to the switch on * success, NULL if no matching connection was found, or * ERR_PTR(-EPROBE_DEFER) when a connection was found but the switch * has not been enumerated yet. */ struct typec_switch *fwnode_typec_switch_get(struct fwnode_handle *fwnode) { … } EXPORT_SYMBOL_GPL(…); /** * typec_switch_put - Release USB Type-C orientation switch * @sw: USB Type-C orientation switch * * Decrement reference count for @sw. */ void typec_switch_put(struct typec_switch *sw) { … } EXPORT_SYMBOL_GPL(…); static void typec_switch_release(struct device *dev) { … } const struct device_type typec_switch_dev_type = …; /** * typec_switch_register - Register USB Type-C orientation switch * @parent: Parent device * @desc: Orientation switch description * * This function registers a switch that can be used for routing the correct * data pairs depending on the cable plug orientation from the USB Type-C * connector to the USB controllers. USB Type-C plugs can be inserted * right-side-up or upside-down. */ struct typec_switch_dev * typec_switch_register(struct device *parent, const struct typec_switch_desc *desc) { … } EXPORT_SYMBOL_GPL(…); int typec_switch_set(struct typec_switch *sw, enum typec_orientation orientation) { … } EXPORT_SYMBOL_GPL(…); /** * typec_switch_unregister - Unregister USB Type-C orientation switch * @sw_dev: USB Type-C orientation switch * * Unregister switch that was registered with typec_switch_register(). */ void typec_switch_unregister(struct typec_switch_dev *sw_dev) { … } EXPORT_SYMBOL_GPL(…); void typec_switch_set_drvdata(struct typec_switch_dev *sw_dev, void *data) { … } EXPORT_SYMBOL_GPL(…); void *typec_switch_get_drvdata(struct typec_switch_dev *sw_dev) { … } EXPORT_SYMBOL_GPL(…); /* ------------------------------------------------------------------------- */ struct typec_mux { … }; static int mux_fwnode_match(struct device *dev, const void *fwnode) { … } static void *typec_mux_match(const struct fwnode_handle *fwnode, const char *id, void *data) { … } /** * fwnode_typec_mux_get - Find USB Type-C Multiplexer * @fwnode: The caller device node * * Finds a mux linked to the caller. This function is primarily meant for the * Type-C drivers. Returns a reference to the mux on success, NULL if no * matching connection was found, or ERR_PTR(-EPROBE_DEFER) when a connection * was found but the mux has not been enumerated yet. */ struct typec_mux *fwnode_typec_mux_get(struct fwnode_handle *fwnode) { … } EXPORT_SYMBOL_GPL(…); /** * typec_mux_put - Release handle to a Multiplexer * @mux: USB Type-C Connector Multiplexer/DeMultiplexer * * Decrements reference count for @mux. */ void typec_mux_put(struct typec_mux *mux) { … } EXPORT_SYMBOL_GPL(…); int typec_mux_set(struct typec_mux *mux, struct typec_mux_state *state) { … } EXPORT_SYMBOL_GPL(…); static void typec_mux_release(struct device *dev) { … } const struct device_type typec_mux_dev_type = …; /** * typec_mux_register - Register Multiplexer routing USB Type-C pins * @parent: Parent device * @desc: Multiplexer description * * USB Type-C connectors can be used for alternate modes of operation besides * USB when Accessory/Alternate Modes are supported. With some of those modes, * the pins on the connector need to be reconfigured. This function registers * multiplexer switches routing the pins on the connector. */ struct typec_mux_dev * typec_mux_register(struct device *parent, const struct typec_mux_desc *desc) { … } EXPORT_SYMBOL_GPL(…); /** * typec_mux_unregister - Unregister Multiplexer Switch * @mux_dev: USB Type-C Connector Multiplexer/DeMultiplexer * * Unregister mux that was registered with typec_mux_register(). */ void typec_mux_unregister(struct typec_mux_dev *mux_dev) { … } EXPORT_SYMBOL_GPL(…); void typec_mux_set_drvdata(struct typec_mux_dev *mux_dev, void *data) { … } EXPORT_SYMBOL_GPL(…); void *typec_mux_get_drvdata(struct typec_mux_dev *mux_dev) { … } EXPORT_SYMBOL_GPL(…); const struct class typec_mux_class = …;