drivers/leds/rgb/leds-group-multicolor.c
Source file repositories/reference/linux-study-clean/drivers/leds/rgb/leds-group-multicolor.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/rgb/leds-group-multicolor.c- Extension
.c- Size
- 5208 bytes
- Lines
- 174
- 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.
- 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/err.hlinux/leds.hlinux/led-class-multicolor.hlinux/math.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/property.h
Detected Declarations
struct leds_multicolorfunction leds_gmc_setfunction restore_sysfs_write_accessfunction leds_gmc_probe
Annotated Snippet
struct leds_multicolor {
struct led_classdev_mc mc_cdev;
struct led_classdev **monochromatics;
};
static int leds_gmc_set(struct led_classdev *cdev, enum led_brightness brightness)
{
struct led_classdev_mc *mc_cdev = lcdev_to_mccdev(cdev);
struct leds_multicolor *priv = container_of(mc_cdev, struct leds_multicolor, mc_cdev);
const unsigned int group_max_brightness = mc_cdev->led_cdev.max_brightness;
int i;
for (i = 0; i < mc_cdev->num_colors; i++) {
struct led_classdev *mono = priv->monochromatics[i];
const unsigned int mono_max_brightness = mono->max_brightness;
unsigned int intensity = mc_cdev->subled_info[i].intensity;
int mono_brightness;
/*
* Scale the brightness according to relative intensity of the
* color AND the max brightness of the monochromatic LED.
*/
mono_brightness = DIV_ROUND_CLOSEST(brightness * intensity * mono_max_brightness,
group_max_brightness * group_max_brightness);
led_set_brightness(mono, mono_brightness);
}
return 0;
}
static void restore_sysfs_write_access(void *data)
{
struct led_classdev *led_cdev = data;
/* Restore the write access to the LED */
mutex_lock(&led_cdev->led_access);
led_sysfs_enable(led_cdev);
mutex_unlock(&led_cdev->led_access);
}
static int leds_gmc_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct led_init_data init_data = {};
struct led_classdev *cdev;
struct mc_subled *subled;
struct leds_multicolor *priv;
unsigned int max_brightness = 0;
int i, ret, count = 0, common_flags = 0;
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
for (;;) {
struct led_classdev *led_cdev;
led_cdev = devm_of_led_get_optional(dev, count);
if (IS_ERR(led_cdev))
return dev_err_probe(dev, PTR_ERR(led_cdev), "Unable to get LED #%d",
count);
if (!led_cdev)
break;
priv->monochromatics = devm_krealloc_array(dev, priv->monochromatics,
count + 1, sizeof(*priv->monochromatics),
GFP_KERNEL);
if (!priv->monochromatics)
return -ENOMEM;
common_flags |= led_cdev->flags;
priv->monochromatics[count] = led_cdev;
max_brightness = max(max_brightness, led_cdev->max_brightness);
count++;
}
subled = devm_kcalloc(dev, count, sizeof(*subled), GFP_KERNEL);
if (!subled)
return -ENOMEM;
priv->mc_cdev.subled_info = subled;
for (i = 0; i < count; i++) {
struct led_classdev *led_cdev = priv->monochromatics[i];
subled[i].color_index = led_cdev->color;
/* Configure the LED intensity to its maximum */
Annotation
- Immediate include surface: `linux/err.h`, `linux/leds.h`, `linux/led-class-multicolor.h`, `linux/math.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/property.h`.
- Detected declarations: `struct leds_multicolor`, `function leds_gmc_set`, `function restore_sysfs_write_access`, `function leds_gmc_probe`.
- Atlas domain: Driver Families / drivers/leds.
- 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.