drivers/usb/misc/appledisplay.c
Source file repositories/reference/linux-study-clean/drivers/usb/misc/appledisplay.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/misc/appledisplay.c- Extension
.c- Size
- 8986 bytes
- Lines
- 355
- 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.
- 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/kernel.hlinux/errno.hlinux/init.hlinux/module.hlinux/slab.hlinux/hid.hlinux/usb.hlinux/backlight.hlinux/timer.hlinux/workqueue.hlinux/atomic.h
Detected Declarations
struct appledisplayfunction appledisplay_completefunction appledisplay_bl_update_statusfunction appledisplay_bl_get_brightnessfunction appledisplay_workfunction appledisplay_probefunction appledisplay_disconnect
Annotated Snippet
struct appledisplay {
struct usb_device *udev; /* usb device */
struct urb *urb; /* usb request block */
struct backlight_device *bd; /* backlight device */
u8 *urbdata; /* interrupt URB data buffer */
u8 *msgdata; /* control message data buffer */
struct delayed_work work;
int button_pressed;
struct mutex sysfslock; /* concurrent read and write */
};
static atomic_t count_displays = ATOMIC_INIT(0);
static void appledisplay_complete(struct urb *urb)
{
struct appledisplay *pdata = urb->context;
struct device *dev = &pdata->udev->dev;
int status = urb->status;
int retval;
switch (status) {
case 0:
/* success */
break;
case -EOVERFLOW:
dev_err(dev,
"OVERFLOW with data length %d, actual length is %d\n",
ACD_URB_BUFFER_LEN, pdata->urb->actual_length);
fallthrough;
case -ECONNRESET:
case -ENOENT:
case -ESHUTDOWN:
/* This urb is terminated, clean up */
dev_dbg(dev, "%s - urb shuttingdown with status: %d\n",
__func__, status);
return;
default:
dev_dbg(dev, "%s - nonzero urb status received: %d\n",
__func__, status);
goto exit;
}
switch(pdata->urbdata[1]) {
case ACD_BTN_BRIGHT_UP:
case ACD_BTN_BRIGHT_DOWN:
pdata->button_pressed = 1;
/*
* there is a window during which no device
* is registered
*/
if (pdata->bd )
schedule_delayed_work(&pdata->work, 0);
break;
case ACD_BTN_NONE:
default:
pdata->button_pressed = 0;
break;
}
exit:
retval = usb_submit_urb(pdata->urb, GFP_ATOMIC);
if (retval) {
dev_err(dev, "%s - usb_submit_urb failed with result %d\n",
__func__, retval);
}
}
static int appledisplay_bl_update_status(struct backlight_device *bd)
{
struct appledisplay *pdata = bl_get_data(bd);
int retval;
mutex_lock(&pdata->sysfslock);
pdata->msgdata[0] = 0x10;
pdata->msgdata[1] = bd->props.brightness;
retval = usb_control_msg(
pdata->udev,
usb_sndctrlpipe(pdata->udev, 0),
HID_REQ_SET_REPORT,
USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
ACD_USB_BRIGHTNESS,
0,
pdata->msgdata, 2,
ACD_USB_TIMEOUT);
mutex_unlock(&pdata->sysfslock);
if (retval < 0)
return retval;
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/errno.h`, `linux/init.h`, `linux/module.h`, `linux/slab.h`, `linux/hid.h`, `linux/usb.h`, `linux/backlight.h`.
- Detected declarations: `struct appledisplay`, `function appledisplay_complete`, `function appledisplay_bl_update_status`, `function appledisplay_bl_get_brightness`, `function appledisplay_work`, `function appledisplay_probe`, `function appledisplay_disconnect`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source 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.