drivers/leds/blink/leds-bcm63138.c
Source file repositories/reference/linux-study-clean/drivers/leds/blink/leds-bcm63138.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/blink/leds-bcm63138.c- Extension
.c- Size
- 8382 bytes
- Lines
- 314
- 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/bits.hlinux/cleanup.hlinux/delay.hlinux/io.hlinux/leds.hlinux/module.hlinux/of.hlinux/pinctrl/consumer.hlinux/platform_device.hlinux/spinlock.h
Detected Declarations
struct bcm63138_ledsstruct bcm63138_ledfunction bcm63138_leds_writefunction bcm63138_leds_readfunction bcm63138_leds_update_bitsfunction bcm63138_leds_set_flash_ratefunction bcm63138_leds_set_brightfunction bcm63138_leds_enable_ledfunction bcm63138_leds_brightness_setfunction bcm63138_leds_blink_setfunction bcm63138_leds_create_ledfunction bcm63138_leds_probefunction for_each_available_child_of_node_scoped
Annotated Snippet
struct bcm63138_leds {
struct device *dev;
void __iomem *base;
spinlock_t lock;
};
struct bcm63138_led {
struct bcm63138_leds *leds;
struct led_classdev cdev;
u32 pin;
bool active_low;
};
/*
* I/O access
*/
static void bcm63138_leds_write(struct bcm63138_leds *leds, unsigned int reg,
u32 data)
{
writel(data, leds->base + reg);
}
static unsigned long bcm63138_leds_read(struct bcm63138_leds *leds,
unsigned int reg)
{
return readl(leds->base + reg);
}
static void bcm63138_leds_update_bits(struct bcm63138_leds *leds,
unsigned int reg, u32 mask, u32 val)
{
WARN_ON(val & ~mask);
bcm63138_leds_write(leds, reg, (bcm63138_leds_read(leds, reg) & ~mask) | (val & mask));
}
/*
* Helpers
*/
static void bcm63138_leds_set_flash_rate(struct bcm63138_leds *leds,
struct bcm63138_led *led,
u8 value)
{
int reg_offset = (led->pin >> fls((BCM63138_LEDS_PER_REG - 1))) * 4;
int shift = (led->pin & (BCM63138_LEDS_PER_REG - 1)) * BCM63138_LED_BITS;
bcm63138_leds_update_bits(leds, BCM63138_FLASH_RATE_CTRL1 + reg_offset,
BCM63138_LED_MASK << shift, value << shift);
}
static void bcm63138_leds_set_bright(struct bcm63138_leds *leds,
struct bcm63138_led *led,
u8 value)
{
int reg_offset = (led->pin >> fls((BCM63138_LEDS_PER_REG - 1))) * 4;
int shift = (led->pin & (BCM63138_LEDS_PER_REG - 1)) * BCM63138_LED_BITS;
bcm63138_leds_update_bits(leds, BCM63138_BRIGHT_CTRL1 + reg_offset,
BCM63138_LED_MASK << shift, value << shift);
}
static void bcm63138_leds_enable_led(struct bcm63138_leds *leds,
struct bcm63138_led *led,
enum led_brightness value)
{
u32 bit = BIT(led->pin);
bcm63138_leds_update_bits(leds, BCM63138_SW_DATA, bit, value ? bit : 0);
}
/*
* API callbacks
*/
static void bcm63138_leds_brightness_set(struct led_classdev *led_cdev,
enum led_brightness value)
{
struct bcm63138_led *led = container_of(led_cdev, struct bcm63138_led, cdev);
struct bcm63138_leds *leds = led->leds;
guard(spinlock_irqsave)(&leds->lock);
bcm63138_leds_enable_led(leds, led, value);
if (!value)
bcm63138_leds_set_flash_rate(leds, led, 0);
else
bcm63138_leds_set_bright(leds, led, value);
}
Annotation
- Immediate include surface: `linux/bits.h`, `linux/cleanup.h`, `linux/delay.h`, `linux/io.h`, `linux/leds.h`, `linux/module.h`, `linux/of.h`, `linux/pinctrl/consumer.h`.
- Detected declarations: `struct bcm63138_leds`, `struct bcm63138_led`, `function bcm63138_leds_write`, `function bcm63138_leds_read`, `function bcm63138_leds_update_bits`, `function bcm63138_leds_set_flash_rate`, `function bcm63138_leds_set_bright`, `function bcm63138_leds_enable_led`, `function bcm63138_leds_brightness_set`, `function bcm63138_leds_blink_set`.
- 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.