drivers/leds/leds-nic78bx.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-nic78bx.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-nic78bx.c- Extension
.c- Size
- 4817 bytes
- Lines
- 210
- 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/array_size.hlinux/bits.hlinux/container_of.hlinux/device.hlinux/errno.hlinux/io.hlinux/ioport.hlinux/leds.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/spinlock.hlinux/types.h
Detected Declarations
struct nic78bx_led_datastruct nic78bx_ledfunction nic78bx_brightness_setfunction nic78bx_brightness_getfunction lock_led_reg_actionfunction nic78bx_probe
Annotated Snippet
struct nic78bx_led_data {
u16 io_base;
spinlock_t lock;
struct platform_device *pdev;
};
struct nic78bx_led {
u8 bit;
u8 mask;
struct nic78bx_led_data *data;
struct led_classdev cdev;
};
static inline struct nic78bx_led *to_nic78bx_led(struct led_classdev *cdev)
{
return container_of(cdev, struct nic78bx_led, cdev);
}
static void nic78bx_brightness_set(struct led_classdev *cdev,
enum led_brightness brightness)
{
struct nic78bx_led *nled = to_nic78bx_led(cdev);
unsigned long flags;
u8 value;
spin_lock_irqsave(&nled->data->lock, flags);
value = inb(nled->data->io_base);
if (brightness) {
value &= ~nled->mask;
value |= nled->bit;
} else {
value &= ~nled->bit;
}
outb(value, nled->data->io_base);
spin_unlock_irqrestore(&nled->data->lock, flags);
}
static enum led_brightness nic78bx_brightness_get(struct led_classdev *cdev)
{
struct nic78bx_led *nled = to_nic78bx_led(cdev);
unsigned long flags;
u8 value;
spin_lock_irqsave(&nled->data->lock, flags);
value = inb(nled->data->io_base);
spin_unlock_irqrestore(&nled->data->lock, flags);
return (value & nled->bit) ? 1 : LED_OFF;
}
static struct nic78bx_led nic78bx_leds[] = {
{
.bit = NIC78BX_USER1_GREEN_LED,
.mask = NIC78BX_USER1_LED_MASK,
.cdev = {
.name = "nilrt:green:user1",
.max_brightness = 1,
.brightness_set = nic78bx_brightness_set,
.brightness_get = nic78bx_brightness_get,
}
},
{
.bit = NIC78BX_USER1_YELLOW_LED,
.mask = NIC78BX_USER1_LED_MASK,
.cdev = {
.name = "nilrt:yellow:user1",
.max_brightness = 1,
.brightness_set = nic78bx_brightness_set,
.brightness_get = nic78bx_brightness_get,
}
},
{
.bit = NIC78BX_USER2_GREEN_LED,
.mask = NIC78BX_USER2_LED_MASK,
.cdev = {
.name = "nilrt:green:user2",
.max_brightness = 1,
.brightness_set = nic78bx_brightness_set,
.brightness_get = nic78bx_brightness_get,
}
},
{
.bit = NIC78BX_USER2_YELLOW_LED,
.mask = NIC78BX_USER2_LED_MASK,
.cdev = {
.name = "nilrt:yellow:user2",
.max_brightness = 1,
.brightness_set = nic78bx_brightness_set,
Annotation
- Immediate include surface: `linux/array_size.h`, `linux/bits.h`, `linux/container_of.h`, `linux/device.h`, `linux/errno.h`, `linux/io.h`, `linux/ioport.h`, `linux/leds.h`.
- Detected declarations: `struct nic78bx_led_data`, `struct nic78bx_led`, `function nic78bx_brightness_set`, `function nic78bx_brightness_get`, `function lock_led_reg_action`, `function nic78bx_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.