drivers/leds/leds-bcm6328.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-bcm6328.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-bcm6328.c- Extension
.c- Size
- 12938 bytes
- Lines
- 484
- 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/io.hlinux/leds.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/spinlock.h
Detected Declarations
struct bcm6328_ledfunction bcm6328_led_writefunction bcm6328_led_readfunction bcm6328_pin2shiftfunction bcm6328_led_modefunction bcm6328_led_setfunction bcm6328_blink_delayfunction bcm6328_blink_setfunction bcm6328_hwledfunction bcm6328_ledfunction bcm6328_leds_probefunction for_each_available_child_of_node_scoped
Annotated Snippet
struct bcm6328_led {
struct led_classdev cdev;
void __iomem *mem;
spinlock_t *lock;
unsigned long pin;
unsigned long *blink_leds;
unsigned long *blink_delay;
bool active_low;
};
static void bcm6328_led_write(void __iomem *reg, unsigned long data)
{
#ifdef CONFIG_CPU_BIG_ENDIAN
iowrite32be(data, reg);
#else
writel(data, reg);
#endif
}
static unsigned long bcm6328_led_read(void __iomem *reg)
{
#ifdef CONFIG_CPU_BIG_ENDIAN
return ioread32be(reg);
#else
return readl(reg);
#endif
}
/*
* LEDMode 64 bits / 24 LEDs
* bits [31:0] -> LEDs 8-23
* bits [47:32] -> LEDs 0-7
* bits [63:48] -> unused
*/
static unsigned long bcm6328_pin2shift(unsigned long pin)
{
if (pin < 8)
return pin + 16; /* LEDs 0-7 (bits 47:32) */
else
return pin - 8; /* LEDs 8-23 (bits 31:0) */
}
static void bcm6328_led_mode(struct bcm6328_led *led, unsigned long value)
{
void __iomem *mode;
unsigned long val, shift;
shift = bcm6328_pin2shift(led->pin);
if (shift >= 16)
mode = led->mem + BCM6328_REG_MODE_HI;
else
mode = led->mem + BCM6328_REG_MODE_LO;
val = bcm6328_led_read(mode);
val &= ~(BCM6328_LED_MODE_MASK << BCM6328_LED_SHIFT(shift % 16));
val |= (value << BCM6328_LED_SHIFT(shift % 16));
bcm6328_led_write(mode, val);
}
static void bcm6328_led_set(struct led_classdev *led_cdev,
enum led_brightness value)
{
struct bcm6328_led *led =
container_of(led_cdev, struct bcm6328_led, cdev);
unsigned long flags;
spin_lock_irqsave(led->lock, flags);
/* Remove LED from cached HW blinking intervals */
led->blink_leds[0] &= ~BIT(led->pin);
led->blink_leds[1] &= ~BIT(led->pin);
/* Set LED on/off */
if ((led->active_low && value == LED_OFF) ||
(!led->active_low && value != LED_OFF))
bcm6328_led_mode(led, BCM6328_LED_MODE_ON);
else
bcm6328_led_mode(led, BCM6328_LED_MODE_OFF);
spin_unlock_irqrestore(led->lock, flags);
}
static unsigned long bcm6328_blink_delay(unsigned long delay)
{
unsigned long bcm6328_delay;
bcm6328_delay = delay + BCM6328_LED_BLINK_MS / 2;
bcm6328_delay = bcm6328_delay / BCM6328_LED_BLINK_MS;
if (bcm6328_delay == 0)
bcm6328_delay = 1;
Annotation
- Immediate include surface: `linux/io.h`, `linux/leds.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/spinlock.h`.
- Detected declarations: `struct bcm6328_led`, `function bcm6328_led_write`, `function bcm6328_led_read`, `function bcm6328_pin2shift`, `function bcm6328_led_mode`, `function bcm6328_led_set`, `function bcm6328_blink_delay`, `function bcm6328_blink_set`, `function bcm6328_hwled`, `function bcm6328_led`.
- 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.