drivers/leds/leds-mc13783.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-mc13783.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-mc13783.c- Extension
.c- Size
- 7536 bytes
- Lines
- 312
- 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/cleanup.hlinux/module.hlinux/kernel.hlinux/platform_device.hlinux/leds.hlinux/of.hlinux/mfd/mc13xxx.h
Detected Declarations
struct mc13xxx_led_devtypestruct mc13xxx_ledstruct mc13xxx_ledsfunction mc13xxx_max_brightnessfunction mc13xxx_led_setfunction for_each_available_child_of_nodefunction mc13xxx_led_probefunction mc13xxx_led_remove
Annotated Snippet
struct mc13xxx_led_devtype {
int led_min;
int led_max;
int num_regs;
u32 ledctrl_base;
};
struct mc13xxx_led {
struct led_classdev cdev;
int id;
struct mc13xxx_leds *leds;
};
struct mc13xxx_leds {
struct mc13xxx *master;
struct mc13xxx_led_devtype *devtype;
int num_leds;
struct mc13xxx_led *led;
};
static unsigned int mc13xxx_max_brightness(int id)
{
if (id >= MC13783_LED_MD && id <= MC13783_LED_KP)
return 0x0f;
else if (id >= MC13783_LED_R1 && id <= MC13783_LED_B3)
return 0x1f;
return 0x3f;
}
static int mc13xxx_led_set(struct led_classdev *led_cdev,
enum led_brightness value)
{
struct mc13xxx_led *led =
container_of(led_cdev, struct mc13xxx_led, cdev);
struct mc13xxx_leds *leds = led->leds;
unsigned int reg, bank, off, shift;
switch (led->id) {
case MC13783_LED_MD:
case MC13783_LED_AD:
case MC13783_LED_KP:
reg = 2;
shift = 9 + (led->id - MC13783_LED_MD) * 4;
break;
case MC13783_LED_R1:
case MC13783_LED_G1:
case MC13783_LED_B1:
case MC13783_LED_R2:
case MC13783_LED_G2:
case MC13783_LED_B2:
case MC13783_LED_R3:
case MC13783_LED_G3:
case MC13783_LED_B3:
off = led->id - MC13783_LED_R1;
bank = off / 3;
reg = 3 + bank;
shift = (off - bank * 3) * 5 + 6;
break;
case MC13892_LED_MD:
case MC13892_LED_AD:
case MC13892_LED_KP:
off = led->id - MC13892_LED_MD;
reg = off / 2;
shift = 3 + (off - reg * 2) * 12;
break;
case MC13892_LED_R:
case MC13892_LED_G:
case MC13892_LED_B:
off = led->id - MC13892_LED_R;
bank = off / 2;
reg = 2 + bank;
shift = (off - bank * 2) * 12 + 3;
break;
case MC34708_LED_R:
case MC34708_LED_G:
reg = 0;
shift = 3 + (led->id - MC34708_LED_R) * 12;
break;
default:
BUG();
}
return mc13xxx_reg_rmw(leds->master, leds->devtype->ledctrl_base + reg,
mc13xxx_max_brightness(led->id) << shift,
value << shift);
}
#ifdef CONFIG_OF
static struct mc13xxx_leds_platform_data __init *mc13xxx_led_probe_dt(
Annotation
- Immediate include surface: `linux/cleanup.h`, `linux/module.h`, `linux/kernel.h`, `linux/platform_device.h`, `linux/leds.h`, `linux/of.h`, `linux/mfd/mc13xxx.h`.
- Detected declarations: `struct mc13xxx_led_devtype`, `struct mc13xxx_led`, `struct mc13xxx_leds`, `function mc13xxx_max_brightness`, `function mc13xxx_led_set`, `function for_each_available_child_of_node`, `function mc13xxx_led_probe`, `function mc13xxx_led_remove`.
- 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.