drivers/watchdog/pcwd_usb.c
Source file repositories/reference/linux-study-clean/drivers/watchdog/pcwd_usb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/watchdog/pcwd_usb.c- Extension
.c- Size
- 21384 bytes
- Lines
- 806
- Domain
- Driver Families
- Bucket
- drivers/watchdog
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern 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 an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/moduleparam.hlinux/types.hlinux/errno.hlinux/kernel.hlinux/delay.hlinux/miscdevice.hlinux/watchdog.hlinux/notifier.hlinux/reboot.hlinux/init.hlinux/fs.hlinux/usb.hlinux/slab.hlinux/mutex.hlinux/hid.hlinux/uaccess.h
Detected Declarations
struct usb_pcwd_privatefunction usb_pcwd_intr_donefunction usb_pcwd_send_commandfunction usb_pcwd_startfunction usb_pcwd_stopfunction usb_pcwd_keepalivefunction usb_pcwd_set_heartbeatfunction usb_pcwd_get_temperaturefunction usb_pcwd_get_timeleftfunction usb_pcwd_writefunction usb_pcwd_ioctlfunction usb_pcwd_openfunction usb_pcwd_releasefunction usb_pcwd_temperature_readfunction usb_pcwd_temperature_openfunction usb_pcwd_temperature_releasefunction usb_pcwd_notify_sysfunction usb_pcwd_deletefunction usb_pcwd_probefunction usb_pcwd_disconnect
Annotated Snippet
static const struct file_operations usb_pcwd_fops = {
.owner = THIS_MODULE,
.write = usb_pcwd_write,
.unlocked_ioctl = usb_pcwd_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.open = usb_pcwd_open,
.release = usb_pcwd_release,
};
static struct miscdevice usb_pcwd_miscdev = {
.minor = WATCHDOG_MINOR,
.name = "watchdog",
.fops = &usb_pcwd_fops,
};
static const struct file_operations usb_pcwd_temperature_fops = {
.owner = THIS_MODULE,
.read = usb_pcwd_temperature_read,
.open = usb_pcwd_temperature_open,
.release = usb_pcwd_temperature_release,
};
static struct miscdevice usb_pcwd_temperature_miscdev = {
.minor = TEMP_MINOR,
.name = "temperature",
.fops = &usb_pcwd_temperature_fops,
};
static struct notifier_block usb_pcwd_notifier = {
.notifier_call = usb_pcwd_notify_sys,
};
/*
* usb_pcwd_delete
*/
static inline void usb_pcwd_delete(struct usb_pcwd_private *usb_pcwd)
{
usb_free_urb(usb_pcwd->intr_urb);
usb_free_coherent(usb_pcwd->udev, usb_pcwd->intr_size,
usb_pcwd->intr_buffer, usb_pcwd->intr_dma);
kfree(usb_pcwd);
}
/*
* usb_pcwd_probe
*
* Called by the usb core when a new device is connected that it thinks
* this driver might be interested in.
*/
static int usb_pcwd_probe(struct usb_interface *interface,
const struct usb_device_id *id)
{
struct usb_device *udev = interface_to_usbdev(interface);
struct usb_host_interface *iface_desc;
struct usb_endpoint_descriptor *endpoint;
struct usb_pcwd_private *usb_pcwd = NULL;
int pipe;
int retval = -ENOMEM;
int got_fw_rev;
unsigned char fw_rev_major, fw_rev_minor;
char fw_ver_str[20];
unsigned char option_switches, dummy;
cards_found++;
if (cards_found > 1) {
pr_err("This driver only supports 1 device\n");
return -ENODEV;
}
/* get the active interface descriptor */
iface_desc = interface->cur_altsetting;
/* check out that we have a HID device */
if (!(iface_desc->desc.bInterfaceClass == USB_CLASS_HID)) {
pr_err("The device isn't a Human Interface Device\n");
return -ENODEV;
}
if (iface_desc->desc.bNumEndpoints < 1)
return -ENODEV;
/* check out the endpoint: it has to be Interrupt & IN */
endpoint = &iface_desc->endpoint[0].desc;
if (!usb_endpoint_is_int_in(endpoint)) {
/* we didn't find a Interrupt endpoint with direction IN */
pr_err("Couldn't find an INTR & IN endpoint\n");
return -ENODEV;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/moduleparam.h`, `linux/types.h`, `linux/errno.h`, `linux/kernel.h`, `linux/delay.h`, `linux/miscdevice.h`, `linux/watchdog.h`.
- Detected declarations: `struct usb_pcwd_private`, `function usb_pcwd_intr_done`, `function usb_pcwd_send_command`, `function usb_pcwd_start`, `function usb_pcwd_stop`, `function usb_pcwd_keepalive`, `function usb_pcwd_set_heartbeat`, `function usb_pcwd_get_temperature`, `function usb_pcwd_get_timeleft`, `function usb_pcwd_write`.
- Atlas domain: Driver Families / drivers/watchdog.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.