drivers/usb/typec/mux.c
Source file repositories/reference/linux-study-clean/drivers/usb/typec/mux.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/typec/mux.c- Extension
.c- Size
- 12063 bytes
- Lines
- 496
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/list.hlinux/module.hlinux/mutex.hlinux/property.hlinux/slab.hclass.hmux.h
Detected Declarations
struct typec_switchstruct typec_muxfunction switch_fwnode_matchfunction ERR_PTRfunction typec_switch_putfunction typec_switch_releasefunction typec_switch_registerfunction typec_switch_setfunction typec_switch_registerfunction typec_switch_set_drvdatafunction mux_fwnode_matchfunction typec_mux_putfunction typec_mux_setfunction typec_mux_releasefunction typec_mux_registerfunction typec_mux_registerfunction typec_mux_set_drvdataexport fwnode_typec_switch_getexport typec_switch_putexport typec_switch_registerexport typec_switch_setexport typec_switch_unregisterexport typec_switch_set_drvdataexport typec_switch_get_drvdataexport fwnode_typec_mux_getexport typec_mux_putexport typec_mux_setexport typec_mux_registerexport typec_mux_unregisterexport typec_mux_set_drvdataexport typec_mux_get_drvdata
Annotated Snippet
ret = device_add(&sw_dev->dev);
if (ret) {
dev_err(parent, "failed to register switch (%d)\n", ret);
put_device(&sw_dev->dev);
return ERR_PTR(ret);
}
return sw_dev;
}
EXPORT_SYMBOL_GPL(typec_switch_register);
int typec_switch_set(struct typec_switch *sw,
enum typec_orientation orientation)
{
struct typec_switch_dev *sw_dev;
unsigned int i;
int ret;
if (IS_ERR_OR_NULL(sw))
return 0;
for (i = 0; i < sw->num_sw_devs; i++) {
sw_dev = sw->sw_devs[i];
ret = sw_dev->set(sw_dev, orientation);
if (ret && ret != -EOPNOTSUPP)
return ret;
}
return 0;
}
EXPORT_SYMBOL_GPL(typec_switch_set);
/**
* 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)
{
if (!IS_ERR_OR_NULL(sw_dev))
device_unregister(&sw_dev->dev);
}
EXPORT_SYMBOL_GPL(typec_switch_unregister);
void typec_switch_set_drvdata(struct typec_switch_dev *sw_dev, void *data)
{
dev_set_drvdata(&sw_dev->dev, data);
}
EXPORT_SYMBOL_GPL(typec_switch_set_drvdata);
void *typec_switch_get_drvdata(struct typec_switch_dev *sw_dev)
{
return dev_get_drvdata(&sw_dev->dev);
}
EXPORT_SYMBOL_GPL(typec_switch_get_drvdata);
/* ------------------------------------------------------------------------- */
struct typec_mux {
struct typec_mux_dev *mux_devs[TYPEC_MUX_MAX_DEVS];
unsigned int num_mux_devs;
};
static int mux_fwnode_match(struct device *dev, const void *fwnode)
{
if (!is_typec_mux_dev(dev))
return 0;
return device_match_fwnode(dev, fwnode);
}
static void *typec_mux_match(const struct fwnode_handle *fwnode,
const char *id, void *data)
{
struct typec_mux_dev **mux_devs = data;
struct device *dev;
int i;
/*
* Device graph (OF graph) does not give any means to identify the
* device type or the device class of the remote port parent that @fwnode
* represents, so in order to identify the type or the class of @fwnode
* an additional device property is needed. With typec muxes the
* property is named "mode-switch" (@id). The value of the device
* property is ignored.
*/
if (id && !fwnode_property_present(fwnode, id))
return NULL;
Annotation
- Immediate include surface: `linux/device.h`, `linux/list.h`, `linux/module.h`, `linux/mutex.h`, `linux/property.h`, `linux/slab.h`, `class.h`, `mux.h`.
- Detected declarations: `struct typec_switch`, `struct typec_mux`, `function switch_fwnode_match`, `function ERR_PTR`, `function typec_switch_put`, `function typec_switch_release`, `function typec_switch_register`, `function typec_switch_set`, `function typec_switch_register`, `function typec_switch_set_drvdata`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.