drivers/leds/leds-pca955x.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-pca955x.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-pca955x.c- Extension
.c- Size
- 20490 bytes
- Lines
- 800
- 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/bitops.hlinux/ctype.hlinux/delay.hlinux/err.hlinux/gpio/driver.hlinux/i2c.hlinux/leds.hlinux/module.hlinux/of.hlinux/property.hlinux/slab.hlinux/string.hdt-bindings/leds/leds-pca955x.h
Detected Declarations
struct pca955x_chipdefstruct pca955xstruct pca955x_ledstruct pca955x_platform_dataenum pca955x_typefunction pca955x_num_input_regsfunction pca955x_num_led_regsfunction pca955x_ledselfunction pca955x_ledstatefunction pca955x_write_pscfunction isfunction pca955x_write_lsfunction pca955x_read_lsfunction pca955x_read_pwmfunction pca955x_read_pscfunction pca955x_led_getfunction pca955x_led_setfunction pca955x_period_to_pscfunction pca955x_psc_to_periodfunction pca955x_led_blinkfunction pca955x_read_inputfunction pca955x_gpio_request_pinfunction pca955x_gpio_free_pinfunction pca955x_set_valuefunction pca955x_gpio_set_valuefunction pca955x_gpio_get_valuefunction pca955x_gpio_direction_inputfunction pca955x_gpio_direction_outputfunction pca955x_get_pdatafunction device_for_each_child_nodefunction pca955x_probe
Annotated Snippet
struct pca955x_chipdef {
u8 bits;
u8 slv_addr; /* 7-bit slave address mask */
int slv_addr_shift; /* Number of bits to ignore */
int blink_div; /* PSC divider */
};
static const struct pca955x_chipdef pca955x_chipdefs[] = {
[pca9550] = {
.bits = 2,
.slv_addr = /* 110000x */ 0x60,
.slv_addr_shift = 1,
.blink_div = 44,
},
[pca9551] = {
.bits = 8,
.slv_addr = /* 1100xxx */ 0x60,
.slv_addr_shift = 3,
.blink_div = 38,
},
[pca9552] = {
.bits = 16,
.slv_addr = /* 1100xxx */ 0x60,
.slv_addr_shift = 3,
.blink_div = 44,
},
[ibm_pca9552] = {
.bits = 16,
.slv_addr = /* 0110xxx */ 0x30,
.slv_addr_shift = 3,
.blink_div = 44,
},
[pca9553] = {
.bits = 4,
.slv_addr = /* 110001x */ 0x62,
.slv_addr_shift = 1,
.blink_div = 44,
},
};
struct pca955x {
struct mutex lock;
struct pca955x_led *leds;
const struct pca955x_chipdef *chipdef;
struct i2c_client *client;
unsigned long active_blink;
unsigned long active_pins;
unsigned long blink_period;
#ifdef CONFIG_LEDS_PCA955X_GPIO
struct gpio_chip gpio;
#endif
};
struct pca955x_led {
struct pca955x *pca955x;
struct led_classdev led_cdev;
int led_num; /* 0 .. 15 potentially */
u32 type;
enum led_default_state default_state;
struct fwnode_handle *fwnode;
};
#define led_to_pca955x(l) container_of(l, struct pca955x_led, led_cdev)
struct pca955x_platform_data {
struct pca955x_led *leds;
int num_leds;
};
/* 8 bits per input register */
static inline u8 pca955x_num_input_regs(u8 bits)
{
return (bits + 7) / 8;
}
/* 4 bits per LED selector register */
static inline u8 pca955x_num_led_regs(u8 bits)
{
return (bits + 3) / 4;
}
/*
* Return an LED selector register value based on an existing one, with
* the appropriate 2-bit state value set for the given LED number (0-3).
*/
static inline u8 pca955x_ledsel(u8 oldval, int led_num, int state)
{
return (oldval & (~(0x3 << (led_num << 1)))) |
((state & 0x3) << (led_num << 1));
}
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/ctype.h`, `linux/delay.h`, `linux/err.h`, `linux/gpio/driver.h`, `linux/i2c.h`, `linux/leds.h`, `linux/module.h`.
- Detected declarations: `struct pca955x_chipdef`, `struct pca955x`, `struct pca955x_led`, `struct pca955x_platform_data`, `enum pca955x_type`, `function pca955x_num_input_regs`, `function pca955x_num_led_regs`, `function pca955x_ledsel`, `function pca955x_ledstate`, `function pca955x_write_psc`.
- 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.