drivers/usb/mtu3/mtu3_dr.c
Source file repositories/reference/linux-study-clean/drivers/usb/mtu3/mtu3_dr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/mtu3/mtu3_dr.c- Extension
.c- Size
- 8533 bytes
- Lines
- 332
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/string_choices.hmtu3.hmtu3_dr.hmtu3_debug.h
Detected Declarations
function Copyrightfunction toggle_opstatefunction ssusb_port0_switchfunction switch_port_to_hostfunction switch_port_to_devicefunction ssusb_set_vbusfunction ssusb_mode_sw_workfunction ssusb_set_modefunction ssusb_id_notifierfunction ssusb_extcon_registerfunction ssusb_mode_switchfunction ssusb_set_force_modefunction ssusb_role_sw_setfunction ssusb_role_sw_getfunction ssusb_role_sw_registerfunction ssusb_otg_switch_initfunction ssusb_otg_switch_exit
Annotated Snippet
if (ret) {
dev_err(ssusb->dev, "vbus regulator enable failed\n");
return ret;
}
} else {
regulator_disable(vbus);
}
return 0;
}
static void ssusb_mode_sw_work(struct work_struct *work)
{
struct otg_switch_mtk *otg_sx =
container_of(work, struct otg_switch_mtk, dr_work);
struct ssusb_mtk *ssusb = otg_sx_to_ssusb(otg_sx);
struct mtu3 *mtu = ssusb->u3d;
enum usb_role desired_role = otg_sx->desired_role;
enum usb_role current_role;
current_role = ssusb->is_host ? USB_ROLE_HOST : USB_ROLE_DEVICE;
if (desired_role == USB_ROLE_NONE) {
/* the default mode is host as probe does */
desired_role = USB_ROLE_HOST;
if (otg_sx->default_role == USB_ROLE_DEVICE)
desired_role = USB_ROLE_DEVICE;
}
if (current_role == desired_role)
return;
dev_dbg(ssusb->dev, "set role : %s\n", usb_role_string(desired_role));
mtu3_dbg_trace(ssusb->dev, "set role : %s", usb_role_string(desired_role));
pm_runtime_get_sync(ssusb->dev);
switch (desired_role) {
case USB_ROLE_HOST:
ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_HOST);
mtu3_stop(mtu);
switch_port_to_host(ssusb);
ssusb_set_vbus(otg_sx, 1);
ssusb->is_host = true;
break;
case USB_ROLE_DEVICE:
ssusb_set_force_mode(ssusb, MTU3_DR_FORCE_DEVICE);
ssusb->is_host = false;
ssusb_set_vbus(otg_sx, 0);
switch_port_to_device(ssusb);
mtu3_start(mtu);
break;
case USB_ROLE_NONE:
default:
dev_err(ssusb->dev, "invalid role\n");
}
pm_runtime_put(ssusb->dev);
}
static void ssusb_set_mode(struct otg_switch_mtk *otg_sx, enum usb_role role)
{
struct ssusb_mtk *ssusb = otg_sx_to_ssusb(otg_sx);
if (ssusb->dr_mode != USB_DR_MODE_OTG)
return;
otg_sx->desired_role = role;
queue_work(system_freezable_wq, &otg_sx->dr_work);
}
static int ssusb_id_notifier(struct notifier_block *nb,
unsigned long event, void *ptr)
{
struct otg_switch_mtk *otg_sx =
container_of(nb, struct otg_switch_mtk, id_nb);
ssusb_set_mode(otg_sx, event ? USB_ROLE_HOST : USB_ROLE_DEVICE);
return NOTIFY_DONE;
}
static int ssusb_extcon_register(struct otg_switch_mtk *otg_sx)
{
struct ssusb_mtk *ssusb = otg_sx_to_ssusb(otg_sx);
struct extcon_dev *edev = otg_sx->edev;
int ret;
/* extcon is optional */
if (!edev)
return 0;
Annotation
- Immediate include surface: `linux/string_choices.h`, `mtu3.h`, `mtu3_dr.h`, `mtu3_debug.h`.
- Detected declarations: `function Copyright`, `function toggle_opstate`, `function ssusb_port0_switch`, `function switch_port_to_host`, `function switch_port_to_device`, `function ssusb_set_vbus`, `function ssusb_mode_sw_work`, `function ssusb_set_mode`, `function ssusb_id_notifier`, `function ssusb_extcon_register`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source 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.