drivers/leds/led-class-multicolor.c
Source file repositories/reference/linux-study-clean/drivers/leds/led-class-multicolor.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/led-class-multicolor.c- Extension
.c- Size
- 6619 bytes
- Lines
- 249
- Domain
- Driver Families
- Bucket
- drivers/leds
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/init.hlinux/led-class-multicolor.hlinux/math.hlinux/minmax.hlinux/module.hlinux/slab.hlinux/uaccess.h
Detected Declarations
function led_mc_get_max_intensityfunction led_mc_calc_color_componentsfunction multi_max_intensity_showfunction multi_intensity_storefunction multi_intensity_showfunction multi_index_showfunction led_classdev_multicolor_register_extfunction led_classdev_multicolor_unregisterfunction devm_led_classdev_multicolor_releasefunction devm_led_classdev_multicolor_register_extfunction devm_led_classdev_multicolor_matchfunction devm_led_classdev_multicolor_unregisterexport led_mc_calc_color_componentsexport led_classdev_multicolor_register_extexport led_classdev_multicolor_unregisterexport devm_led_classdev_multicolor_register_extexport devm_led_classdev_multicolor_unregister
Annotated Snippet
if (ret != 1) {
ret = -EINVAL;
goto err_out;
}
offset += nrchars;
}
offset++;
if (offset < size) {
ret = -EINVAL;
goto err_out;
}
for (int i = 0; i < mcled_cdev->num_colors; i++) {
max_intensity = led_mc_get_max_intensity(mcled_cdev, i);
mcled_cdev->subled_info[i].intensity = min(intensity_value[i], max_intensity);
}
if (!test_bit(LED_BLINK_SW, &led_cdev->work_flags))
led_set_brightness(led_cdev, led_cdev->brightness);
ret = size;
err_out:
mutex_unlock(&led_cdev->led_access);
return ret;
}
static ssize_t multi_intensity_show(struct device *dev,
struct device_attribute *intensity_attr,
char *buf)
{
struct led_classdev *led_cdev = dev_get_drvdata(dev);
struct led_classdev_mc *mcled_cdev = lcdev_to_mccdev(led_cdev);
int len = 0;
int i;
for (i = 0; i < mcled_cdev->num_colors; i++) {
len += sprintf(buf + len, "%d",
mcled_cdev->subled_info[i].intensity);
if (i < mcled_cdev->num_colors - 1)
len += sprintf(buf + len, " ");
}
buf[len++] = '\n';
return len;
}
static DEVICE_ATTR_RW(multi_intensity);
static ssize_t multi_index_show(struct device *dev,
struct device_attribute *multi_index_attr,
char *buf)
{
struct led_classdev *led_cdev = dev_get_drvdata(dev);
struct led_classdev_mc *mcled_cdev = lcdev_to_mccdev(led_cdev);
int len = 0;
int index;
int i;
for (i = 0; i < mcled_cdev->num_colors; i++) {
index = mcled_cdev->subled_info[i].color_index;
len += sprintf(buf + len, "%s", led_get_color_name(index));
if (i < mcled_cdev->num_colors - 1)
len += sprintf(buf + len, " ");
}
buf[len++] = '\n';
return len;
}
static DEVICE_ATTR_RO(multi_index);
static struct attribute *led_multicolor_attrs[] = {
&dev_attr_multi_max_intensity.attr,
&dev_attr_multi_intensity.attr,
&dev_attr_multi_index.attr,
NULL,
};
ATTRIBUTE_GROUPS(led_multicolor);
int led_classdev_multicolor_register_ext(struct device *parent,
struct led_classdev_mc *mcled_cdev,
struct led_init_data *init_data)
{
struct led_classdev *led_cdev;
if (!mcled_cdev)
return -EINVAL;
if (mcled_cdev->num_colors <= 0)
return -EINVAL;
if (mcled_cdev->num_colors > LED_COLOR_ID_MAX)
Annotation
- Immediate include surface: `linux/device.h`, `linux/init.h`, `linux/led-class-multicolor.h`, `linux/math.h`, `linux/minmax.h`, `linux/module.h`, `linux/slab.h`, `linux/uaccess.h`.
- Detected declarations: `function led_mc_get_max_intensity`, `function led_mc_calc_color_components`, `function multi_max_intensity_show`, `function multi_intensity_store`, `function multi_intensity_show`, `function multi_index_show`, `function led_classdev_multicolor_register_ext`, `function led_classdev_multicolor_unregister`, `function devm_led_classdev_multicolor_release`, `function devm_led_classdev_multicolor_register_ext`.
- Atlas domain: Driver Families / drivers/leds.
- Implementation status: integration 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.