drivers/platform/x86/lenovo/wmi-camera.c
Source file repositories/reference/linux-study-clean/drivers/platform/x86/lenovo/wmi-camera.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/x86/lenovo/wmi-camera.c- Extension
.c- Size
- 3498 bytes
- Lines
- 148
- Domain
- Driver Families
- Bucket
- drivers/platform
- 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/acpi.hlinux/device.hlinux/input.hlinux/types.hlinux/module.hlinux/mutex.hlinux/wmi.hlinux/cleanup.h
Detected Declarations
struct lenovo_wmi_privfunction camera_shutter_input_setupfunction lenovo_wmi_notifyfunction lenovo_wmi_probefunction lenovo_wmi_remove
Annotated Snippet
struct lenovo_wmi_priv {
struct input_dev *idev;
struct mutex notify_lock; /* lenovo WMI camera button notify lock */
};
enum {
SW_CAMERA_OFF = 0,
SW_CAMERA_ON = 1,
};
static int camera_shutter_input_setup(struct wmi_device *wdev, u8 camera_mode)
{
struct lenovo_wmi_priv *priv = dev_get_drvdata(&wdev->dev);
int err;
priv->idev = input_allocate_device();
if (!priv->idev)
return -ENOMEM;
priv->idev->name = "Lenovo WMI Camera Button";
priv->idev->phys = "wmi/input0";
priv->idev->id.bustype = BUS_HOST;
priv->idev->dev.parent = &wdev->dev;
input_set_capability(priv->idev, EV_SW, SW_CAMERA_LENS_COVER);
input_report_switch(priv->idev, SW_CAMERA_LENS_COVER,
camera_mode == SW_CAMERA_ON ? 0 : 1);
input_sync(priv->idev);
err = input_register_device(priv->idev);
if (err) {
input_free_device(priv->idev);
priv->idev = NULL;
}
return err;
}
static void lenovo_wmi_notify(struct wmi_device *wdev, union acpi_object *obj)
{
struct lenovo_wmi_priv *priv = dev_get_drvdata(&wdev->dev);
u8 camera_mode;
if (obj->type != ACPI_TYPE_BUFFER) {
dev_err(&wdev->dev, "Bad response type %u\n", obj->type);
return;
}
if (obj->buffer.length != 1) {
dev_err(&wdev->dev, "Invalid buffer length %u\n", obj->buffer.length);
return;
}
/*
* obj->buffer.pointer[0] is camera mode:
* 0 camera close
* 1 camera open
*/
camera_mode = obj->buffer.pointer[0];
if (camera_mode > SW_CAMERA_ON) {
dev_err(&wdev->dev, "Unknown camera mode %u\n", camera_mode);
return;
}
guard(mutex)(&priv->notify_lock);
if (!priv->idev) {
if (camera_shutter_input_setup(wdev, camera_mode))
dev_warn(&wdev->dev, "Failed to register input device\n");
return;
}
if (camera_mode == SW_CAMERA_ON)
input_report_switch(priv->idev, SW_CAMERA_LENS_COVER, 0);
else
input_report_switch(priv->idev, SW_CAMERA_LENS_COVER, 1);
input_sync(priv->idev);
}
static int lenovo_wmi_probe(struct wmi_device *wdev, const void *context)
{
struct lenovo_wmi_priv *priv;
priv = devm_kzalloc(&wdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
dev_set_drvdata(&wdev->dev, priv);
Annotation
- Immediate include surface: `linux/acpi.h`, `linux/device.h`, `linux/input.h`, `linux/types.h`, `linux/module.h`, `linux/mutex.h`, `linux/wmi.h`, `linux/cleanup.h`.
- Detected declarations: `struct lenovo_wmi_priv`, `function camera_shutter_input_setup`, `function lenovo_wmi_notify`, `function lenovo_wmi_probe`, `function lenovo_wmi_remove`.
- Atlas domain: Driver Families / drivers/platform.
- 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.