drivers/leds/leds-bd2802.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-bd2802.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-bd2802.c- Extension
.c- Size
- 20850 bytes
- Lines
- 799
- 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/module.hlinux/i2c.hlinux/gpio/consumer.hlinux/delay.hlinux/leds.hlinux/leds-bd2802.hlinux/slab.hlinux/pm.h
Detected Declarations
struct led_statestruct bd2802_ledenum led_idsenum led_colorsenum led_bitsfunction bd2802_is_rgb_offfunction bd2802_is_led_offfunction bd2802_is_all_offfunction bd2802_get_base_offsetfunction bd2802_get_reg_addrfunction bd2802_write_bytefunction bd2802_update_statefunction bd2802_configurefunction bd2802_reset_cancelfunction bd2802_enablefunction bd2802_set_onfunction bd2802_set_blinkfunction bd2802_turn_onfunction bd2802_turn_offfunction bd2802_enable_adv_conffunction bd2802_disable_adv_conffunction bd2802_show_adv_conffunction bd2802_store_adv_conffunction bd2802_register_led_classdevfunction bd2802_unregister_led_classdevfunction bd2802_probefunction bd2802_removefunction bd2802_restore_statefunction bd2802_suspendfunction bd2802_resume
Annotated Snippet
struct led_state {
unsigned r:2;
unsigned g:2;
unsigned b:2;
};
struct bd2802_led {
struct bd2802_led_platform_data *pdata;
struct i2c_client *client;
struct gpio_desc *reset;
struct rw_semaphore rwsem;
struct led_state led[2];
/*
* Making led_classdev as array is not recommended, because array
* members prevent using 'container_of' macro. So repetitive works
* are needed.
*/
struct led_classdev cdev_led1r;
struct led_classdev cdev_led1g;
struct led_classdev cdev_led1b;
struct led_classdev cdev_led2r;
struct led_classdev cdev_led2g;
struct led_classdev cdev_led2b;
/*
* Advanced Configuration Function(ADF) mode:
* In ADF mode, user can set registers of BD2802GU directly,
* therefore BD2802GU doesn't enter reset state.
*/
int adf_on;
enum led_ids led_id;
enum led_colors color;
enum led_bits state;
/* General attributes of RGB LEDs */
int wave_pattern;
int rgb_current;
};
/*--------------------------------------------------------------*/
/* BD2802GU helper functions */
/*--------------------------------------------------------------*/
static inline int bd2802_is_rgb_off(struct bd2802_led *led, enum led_ids id,
enum led_colors color)
{
switch (color) {
case RED:
return !led->led[id].r;
case GREEN:
return !led->led[id].g;
case BLUE:
return !led->led[id].b;
default:
dev_err(&led->client->dev, "%s: Invalid color\n", __func__);
return -EINVAL;
}
}
static inline int bd2802_is_led_off(struct bd2802_led *led, enum led_ids id)
{
if (led->led[id].r || led->led[id].g || led->led[id].b)
return 0;
return 1;
}
static inline int bd2802_is_all_off(struct bd2802_led *led)
{
int i;
for (i = 0; i < LED_NUM; i++)
if (!bd2802_is_led_off(led, i))
return 0;
return 1;
}
static inline u8 bd2802_get_base_offset(enum led_ids id, enum led_colors color)
{
return id * BD2802_LED_OFFSET + color * BD2802_COLOR_OFFSET;
}
static inline u8 bd2802_get_reg_addr(enum led_ids id, enum led_colors color,
u8 reg_offset)
{
Annotation
- Immediate include surface: `linux/module.h`, `linux/i2c.h`, `linux/gpio/consumer.h`, `linux/delay.h`, `linux/leds.h`, `linux/leds-bd2802.h`, `linux/slab.h`, `linux/pm.h`.
- Detected declarations: `struct led_state`, `struct bd2802_led`, `enum led_ids`, `enum led_colors`, `enum led_bits`, `function bd2802_is_rgb_off`, `function bd2802_is_led_off`, `function bd2802_is_all_off`, `function bd2802_get_base_offset`, `function bd2802_get_reg_addr`.
- 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.