drivers/leds/leds-qnap-mcu.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-qnap-mcu.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-qnap-mcu.c- Extension
.c- Size
- 10666 bytes
- Lines
- 393
- Domain
- Driver Families
- Bucket
- drivers/leds
- 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/leds.hlinux/mfd/qnap-mcu.hlinux/module.hlinux/platform_device.hlinux/slab.huapi/linux/uleds.h
Detected Declarations
struct qnap_mcu_err_ledstruct qnap_mcu_usb_ledstruct qnap_mcu_status_ledstruct qnap_mcu_statusenum qnap_mcu_err_led_modeenum qnap_mcu_usb_led_modeenum qnap_mcu_status_led_modefunction cdev_to_qnap_mcu_err_ledfunction qnap_mcu_err_led_setfunction qnap_mcu_err_led_blink_setfunction qnap_mcu_register_err_ledfunction cdev_to_qnap_mcu_usb_ledfunction qnap_mcu_usb_led_setfunction qnap_mcu_usb_led_blink_setfunction qnap_mcu_register_usb_ledfunction qnap_mcu_status_led_encodefunction qnap_mcu_status_led_updatefunction qnap_mcu_status_led_setfunction qnap_mcu_status_led_blink_setfunction qnap_mcu_register_status_ledsfunction qnap_mcu_leds_probe
Annotated Snippet
struct qnap_mcu_err_led {
struct qnap_mcu *mcu;
struct led_classdev cdev;
char name[LED_MAX_NAME_SIZE];
u8 num;
u8 mode;
};
static inline struct qnap_mcu_err_led *
cdev_to_qnap_mcu_err_led(struct led_classdev *led_cdev)
{
return container_of(led_cdev, struct qnap_mcu_err_led, cdev);
}
static int qnap_mcu_err_led_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
struct qnap_mcu_err_led *err_led = cdev_to_qnap_mcu_err_led(led_cdev);
u8 cmd[] = { '@', 'R', '0' + err_led->num, '0' };
/* Don't disturb a possible set blink-mode if LED stays on */
if (brightness != 0 && err_led->mode >= QNAP_MCU_ERR_LED_BLINK_FAST)
return 0;
err_led->mode = brightness ? QNAP_MCU_ERR_LED_ON : QNAP_MCU_ERR_LED_OFF;
cmd[3] = '0' + err_led->mode;
return qnap_mcu_exec_with_ack(err_led->mcu, cmd, sizeof(cmd));
}
static int qnap_mcu_err_led_blink_set(struct led_classdev *led_cdev,
unsigned long *delay_on,
unsigned long *delay_off)
{
struct qnap_mcu_err_led *err_led = cdev_to_qnap_mcu_err_led(led_cdev);
u8 cmd[] = { '@', 'R', '0' + err_led->num, '0' };
/* LED is off, nothing to do */
if (err_led->mode == QNAP_MCU_ERR_LED_OFF)
return 0;
if (*delay_on < 500) {
*delay_on = 100;
*delay_off = 100;
err_led->mode = QNAP_MCU_ERR_LED_BLINK_FAST;
} else {
*delay_on = 500;
*delay_off = 500;
err_led->mode = QNAP_MCU_ERR_LED_BLINK_SLOW;
}
cmd[3] = '0' + err_led->mode;
return qnap_mcu_exec_with_ack(err_led->mcu, cmd, sizeof(cmd));
}
static int qnap_mcu_register_err_led(struct device *dev, struct qnap_mcu *mcu, int num_err_led)
{
struct qnap_mcu_err_led *err_led;
int ret;
err_led = devm_kzalloc(dev, sizeof(*err_led), GFP_KERNEL);
if (!err_led)
return -ENOMEM;
err_led->mcu = mcu;
err_led->num = num_err_led;
err_led->mode = QNAP_MCU_ERR_LED_OFF;
scnprintf(err_led->name, LED_MAX_NAME_SIZE, "hdd%d:red:status", num_err_led + 1);
err_led->cdev.name = err_led->name;
err_led->cdev.brightness_set_blocking = qnap_mcu_err_led_set;
err_led->cdev.blink_set = qnap_mcu_err_led_blink_set;
err_led->cdev.brightness = 0;
err_led->cdev.max_brightness = 1;
ret = devm_led_classdev_register(dev, &err_led->cdev);
if (ret)
return ret;
return qnap_mcu_err_led_set(&err_led->cdev, 0);
}
enum qnap_mcu_usb_led_mode {
QNAP_MCU_USB_LED_ON = 0,
QNAP_MCU_USB_LED_OFF = 2,
QNAP_MCU_USB_LED_BLINK = 1,
};
Annotation
- Immediate include surface: `linux/leds.h`, `linux/mfd/qnap-mcu.h`, `linux/module.h`, `linux/platform_device.h`, `linux/slab.h`, `uapi/linux/uleds.h`.
- Detected declarations: `struct qnap_mcu_err_led`, `struct qnap_mcu_usb_led`, `struct qnap_mcu_status_led`, `struct qnap_mcu_status`, `enum qnap_mcu_err_led_mode`, `enum qnap_mcu_usb_led_mode`, `enum qnap_mcu_status_led_mode`, `function cdev_to_qnap_mcu_err_led`, `function qnap_mcu_err_led_set`, `function qnap_mcu_err_led_blink_set`.
- Atlas domain: Driver Families / drivers/leds.
- 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.