drivers/misc/cardreader/rtsx_usb.c
Source file repositories/reference/linux-study-clean/drivers/misc/cardreader/rtsx_usb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/misc/cardreader/rtsx_usb.c- Extension
.c- Size
- 19442 bytes
- Lines
- 810
- Domain
- Driver Families
- Bucket
- drivers/misc
- 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/slab.hlinux/mutex.hlinux/usb.hlinux/platform_device.hlinux/mfd/core.hlinux/rtsx_usb.h
Detected Declarations
function rtsx_usb_sg_timed_outfunction rtsx_usb_bulk_transfer_sglistfunction rtsx_usb_transfer_datafunction rtsx_usb_seq_cmd_hdrfunction rtsx_usb_seq_write_registerfunction rtsx_usb_seq_read_registerfunction rtsx_usb_read_ppbuffunction rtsx_usb_write_ppbuffunction rtsx_usb_ep0_write_registerfunction rtsx_usb_ep0_read_registerfunction rtsx_usb_add_cmdfunction rtsx_usb_send_cmdfunction rtsx_usb_get_rspfunction rtsx_usb_get_status_with_bulkfunction rtsx_usb_get_card_statusfunction rtsx_usb_write_phy_registerfunction rtsx_usb_write_registerfunction rtsx_usb_read_registerfunction double_ssc_depthfunction revise_ssc_depthfunction rtsx_usb_switch_clockfunction rtsx_usb_card_exclusive_checkfunction rtsx_usb_reset_chipfunction rtsx_usb_init_chipfunction rtsx_usb_probefunction rtsx_usb_disconnectfunction rtsx_usb_resume_childfunction rtsx_usb_suspendfunction rtsx_usb_resumefunction rtsx_usb_reset_resumefunction rtsx_usb_pre_resetfunction rtsx_usb_post_resetexport rtsx_usb_transfer_dataexport rtsx_usb_read_ppbufexport rtsx_usb_write_ppbufexport rtsx_usb_ep0_write_registerexport rtsx_usb_ep0_read_registerexport rtsx_usb_add_cmdexport rtsx_usb_send_cmdexport rtsx_usb_get_rspexport rtsx_usb_get_card_statusexport rtsx_usb_write_registerexport rtsx_usb_read_registerexport rtsx_usb_switch_clockexport rtsx_usb_card_exclusive_check
Annotated Snippet
if (mutex_trylock(&ucr->dev_mutex)) {
rtsx_usb_get_card_status(ucr, &val);
mutex_unlock(&ucr->dev_mutex);
/* Defer the autosuspend if card exists */
if (val & (SD_CD | MS_CD)) {
device_for_each_child(&intf->dev, NULL, rtsx_usb_resume_child);
return -EAGAIN;
} else {
/* if the card does not exists, clear OCP status */
rtsx_usb_write_register(ucr, OCPCTL, MS_OCP_CLEAR, MS_OCP_CLEAR);
}
} else {
/* There is an ongoing operation*/
return -EAGAIN;
}
}
return 0;
}
static int rtsx_usb_resume(struct usb_interface *intf)
{
device_for_each_child(&intf->dev, NULL, rtsx_usb_resume_child);
return 0;
}
static int rtsx_usb_reset_resume(struct usb_interface *intf)
{
struct rtsx_ucr *ucr =
(struct rtsx_ucr *)usb_get_intfdata(intf);
rtsx_usb_reset_chip(ucr);
device_for_each_child(&intf->dev, NULL, rtsx_usb_resume_child);
return 0;
}
#else /* CONFIG_PM */
#define rtsx_usb_suspend NULL
#define rtsx_usb_resume NULL
#define rtsx_usb_reset_resume NULL
#endif /* CONFIG_PM */
static int rtsx_usb_pre_reset(struct usb_interface *intf)
{
struct rtsx_ucr *ucr = (struct rtsx_ucr *)usb_get_intfdata(intf);
mutex_lock(&ucr->dev_mutex);
return 0;
}
static int rtsx_usb_post_reset(struct usb_interface *intf)
{
struct rtsx_ucr *ucr = (struct rtsx_ucr *)usb_get_intfdata(intf);
mutex_unlock(&ucr->dev_mutex);
return 0;
}
static const struct usb_device_id rtsx_usb_usb_ids[] = {
{ USB_DEVICE(0x0BDA, 0x0129) },
{ USB_DEVICE(0x0BDA, 0x0139) },
{ USB_DEVICE(0x0BDA, 0x0140) },
{ }
};
MODULE_DEVICE_TABLE(usb, rtsx_usb_usb_ids);
static struct usb_driver rtsx_usb_driver = {
.name = DRV_NAME_RTSX_USB,
.probe = rtsx_usb_probe,
.disconnect = rtsx_usb_disconnect,
.suspend = rtsx_usb_suspend,
.resume = rtsx_usb_resume,
.reset_resume = rtsx_usb_reset_resume,
.pre_reset = rtsx_usb_pre_reset,
.post_reset = rtsx_usb_post_reset,
.id_table = rtsx_usb_usb_ids,
.supports_autosuspend = 1,
.soft_unbind = 1,
};
module_usb_driver(rtsx_usb_driver);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("Roger Tseng <rogerable@realtek.com>");
MODULE_DESCRIPTION("Realtek USB Card Reader Driver");
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/mutex.h`, `linux/usb.h`, `linux/platform_device.h`, `linux/mfd/core.h`, `linux/rtsx_usb.h`.
- Detected declarations: `function rtsx_usb_sg_timed_out`, `function rtsx_usb_bulk_transfer_sglist`, `function rtsx_usb_transfer_data`, `function rtsx_usb_seq_cmd_hdr`, `function rtsx_usb_seq_write_register`, `function rtsx_usb_seq_read_register`, `function rtsx_usb_read_ppbuf`, `function rtsx_usb_write_ppbuf`, `function rtsx_usb_ep0_write_register`, `function rtsx_usb_ep0_read_register`.
- Atlas domain: Driver Families / drivers/misc.
- 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.