drivers/hid/hid-appletb-bl.c
Source file repositories/reference/linux-study-clean/drivers/hid/hid-appletb-bl.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hid/hid-appletb-bl.c- Extension
.c- Size
- 5182 bytes
- Lines
- 205
- Domain
- Driver Families
- Bucket
- drivers/hid
- 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.
- 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/hid.hlinux/backlight.hlinux/device.hhid-ids.h
Detected Declarations
struct appletb_blfunction appletb_bl_set_brightnessfunction appletb_bl_update_statusfunction appletb_bl_probefunction appletb_bl_remove
Annotated Snippet
struct appletb_bl {
struct hid_field *aux1_field, *brightness_field;
struct backlight_device *bdev;
bool full_on;
};
static const u8 appletb_bl_brightness_map[] = {
APPLETB_BL_OFF,
APPLETB_BL_DIM,
APPLETB_BL_ON,
};
static int appletb_bl_set_brightness(struct appletb_bl *bl, u8 brightness)
{
struct hid_report *report = bl->brightness_field->report;
struct hid_device *hdev = report->device;
int ret;
ret = hid_set_field(bl->aux1_field, 0, 1);
if (ret) {
hid_err(hdev, "Failed to set auxiliary field (%pe)\n", ERR_PTR(ret));
return ret;
}
ret = hid_set_field(bl->brightness_field, 0, brightness);
if (ret) {
hid_err(hdev, "Failed to set brightness field (%pe)\n", ERR_PTR(ret));
return ret;
}
if (!bl->full_on) {
ret = hid_hw_power(hdev, PM_HINT_FULLON);
if (ret < 0) {
hid_err(hdev, "Device didn't power on (%pe)\n", ERR_PTR(ret));
return ret;
}
bl->full_on = true;
}
hid_hw_request(hdev, report, HID_REQ_SET_REPORT);
if (brightness == APPLETB_BL_OFF) {
hid_hw_power(hdev, PM_HINT_NORMAL);
bl->full_on = false;
}
return 0;
}
static int appletb_bl_update_status(struct backlight_device *bdev)
{
struct appletb_bl *bl = bl_get_data(bdev);
u8 brightness;
if (backlight_is_blank(bdev))
brightness = APPLETB_BL_OFF;
else
brightness = appletb_bl_brightness_map[backlight_get_brightness(bdev)];
return appletb_bl_set_brightness(bl, brightness);
}
static const struct backlight_ops appletb_bl_backlight_ops = {
.options = BL_CORE_SUSPENDRESUME,
.update_status = appletb_bl_update_status,
};
static int appletb_bl_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
struct hid_field *aux1_field, *brightness_field;
struct backlight_properties bl_props = { 0 };
struct device *dev = &hdev->dev;
struct appletb_bl *bl;
int ret;
ret = hid_parse(hdev);
if (ret)
return dev_err_probe(dev, ret, "HID parse failed\n");
aux1_field = hid_find_field(hdev, HID_FEATURE_REPORT,
HID_VD_APPLE_TB_BRIGHTNESS, HID_USAGE_AUX1);
brightness_field = hid_find_field(hdev, HID_FEATURE_REPORT,
HID_VD_APPLE_TB_BRIGHTNESS, HID_USAGE_BRIGHTNESS);
if (!aux1_field || !brightness_field)
return -ENODEV;
Annotation
- Immediate include surface: `linux/hid.h`, `linux/backlight.h`, `linux/device.h`, `hid-ids.h`.
- Detected declarations: `struct appletb_bl`, `function appletb_bl_set_brightness`, `function appletb_bl_update_status`, `function appletb_bl_probe`, `function appletb_bl_remove`.
- Atlas domain: Driver Families / drivers/hid.
- 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.