drivers/usb/typec/class.c
Source file repositories/reference/linux-study-clean/drivers/usb/typec/class.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/typec/class.c- Extension
.c- Size
- 74589 bytes
- Lines
- 2894
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/module.hlinux/mutex.hlinux/property.hlinux/slab.hlinux/string_choices.hlinux/usb/pd_vdo.hlinux/usb/typec_mux.hlinux/usb/typec_retimer.hlinux/usb.hbus.hclass.hpd.h
Detected Declarations
function id_header_showfunction cert_stat_showfunction product_showfunction product_type_vdo1_showfunction product_type_vdo2_showfunction product_type_vdo3_showfunction typec_product_type_notifyfunction typec_report_identityfunction type_showfunction altmode_matchfunction typec_altmode_set_partnerfunction typec_altmode_put_partnerfunction typec_altmode_update_activefunction vdo_showfunction description_showfunction active_showfunction active_storefunction supported_roles_showfunction mode_showfunction svid_showfunction increment_duplicated_priorityfunction find_duplicated_priorityfunction typec_mode_set_priorityfunction priority_storefunction priority_showfunction typec_altmode_attr_is_visiblefunction typec_altmode_set_opsfunction altmode_id_getfunction altmode_id_removefunction typec_altmode_releasefunction typec_register_altmodefunction typec_partner_register_altmodefunction typec_partner_set_usb_modefunction usb_mode_showfunction usb_mode_storefunction accessory_mode_showfunction supports_usb_power_delivery_showfunction number_of_alternate_modes_showfunction typec_partner_attr_is_visiblefunction typec_partner_releasefunction typec_partner_link_devicefunction typec_partner_unlink_devicefunction typec_partner_set_identityfunction typec_partner_set_pd_revisionfunction typec_partner_set_usb_power_deliveryfunction typec_partner_set_num_altmodesfunction typec_partner_register_altmodefunction typec_partner_set_svdm_version
Annotated Snippet
ret = device_add(&port->dev);
if (ret) {
dev_err(parent, "failed to register port (%d)\n", ret);
put_device(&port->dev);
return ERR_PTR(ret);
}
ret = usb_power_delivery_link_device(port->pd, &port->dev);
if (ret) {
dev_err(&port->dev, "failed to link pd\n");
device_unregister(&port->dev);
return ERR_PTR(ret);
}
ret = typec_link_ports(port);
if (ret)
dev_warn(&port->dev, "failed to create symlinks (%d)\n", ret);
return port;
}
EXPORT_SYMBOL_GPL(typec_register_port);
/**
* typec_unregister_port - Unregister a USB Type-C Port
* @port: The port to be unregistered
*
* Unregister device created with typec_register_port().
*/
void typec_unregister_port(struct typec_port *port)
{
if (!IS_ERR_OR_NULL(port)) {
typec_unlink_ports(port);
typec_port_set_usb_power_delivery(port, NULL);
device_unregister(&port->dev);
}
}
EXPORT_SYMBOL_GPL(typec_unregister_port);
static int __init typec_init(void)
{
int ret;
ret = bus_register(&typec_bus);
if (ret)
return ret;
ret = class_register(&typec_mux_class);
if (ret)
goto err_unregister_bus;
ret = class_register(&retimer_class);
if (ret)
goto err_unregister_mux_class;
ret = class_register(&typec_class);
if (ret)
goto err_unregister_retimer_class;
ret = usb_power_delivery_init();
if (ret)
goto err_unregister_class;
return 0;
err_unregister_class:
class_unregister(&typec_class);
err_unregister_retimer_class:
class_unregister(&retimer_class);
err_unregister_mux_class:
class_unregister(&typec_mux_class);
err_unregister_bus:
bus_unregister(&typec_bus);
return ret;
}
subsys_initcall(typec_init);
static void __exit typec_exit(void)
{
usb_power_delivery_exit();
class_unregister(&typec_class);
ida_destroy(&typec_index_ida);
bus_unregister(&typec_bus);
class_unregister(&typec_mux_class);
class_unregister(&retimer_class);
}
module_exit(typec_exit);
Annotation
- Immediate include surface: `linux/module.h`, `linux/mutex.h`, `linux/property.h`, `linux/slab.h`, `linux/string_choices.h`, `linux/usb/pd_vdo.h`, `linux/usb/typec_mux.h`, `linux/usb/typec_retimer.h`.
- Detected declarations: `function id_header_show`, `function cert_stat_show`, `function product_show`, `function product_type_vdo1_show`, `function product_type_vdo2_show`, `function product_type_vdo3_show`, `function typec_product_type_notify`, `function typec_report_identity`, `function type_show`, `function altmode_match`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.