drivers/leds/leds-pca963x.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-pca963x.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-pca963x.c- Extension
.c- Size
- 12123 bytes
- Lines
- 466
- 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/module.hlinux/delay.hlinux/string.hlinux/ctype.hlinux/leds.hlinux/err.hlinux/i2c.hlinux/property.hlinux/slab.hlinux/of.h
Detected Declarations
struct pca963x_chipdefstruct pca963xstruct pca963x_ledstruct pca963xenum pca963x_typefunction pca963x_brightnessfunction pca963x_blinkfunction pca963x_power_statefunction pca963x_led_setfunction pca963x_period_scalefunction pca963x_blink_setfunction pca963x_register_ledsfunction device_for_each_child_node_scopedfunction pca963x_suspendfunction pca963x_resumefunction pca963x_probe
Annotated Snippet
struct pca963x_chipdef {
u8 grppwm;
u8 grpfreq;
u8 ledout_base;
int n_leds;
unsigned int scaling;
};
static struct pca963x_chipdef pca963x_chipdefs[] = {
[pca9633] = {
.grppwm = 0x6,
.grpfreq = 0x7,
.ledout_base = 0x8,
.n_leds = 4,
},
[pca9634] = {
.grppwm = 0xa,
.grpfreq = 0xb,
.ledout_base = 0xc,
.n_leds = 8,
},
[pca9635] = {
.grppwm = 0x12,
.grpfreq = 0x13,
.ledout_base = 0x14,
.n_leds = 16,
},
};
/* Total blink period in milliseconds */
#define PCA963X_BLINK_PERIOD_MIN 42
#define PCA963X_BLINK_PERIOD_MAX 10667
static const struct i2c_device_id pca963x_id[] = {
{ .name = "pca9632", .driver_data = pca9633 },
{ .name = "pca9633", .driver_data = pca9633 },
{ .name = "pca9634", .driver_data = pca9634 },
{ .name = "pca9635", .driver_data = pca9635 },
{ }
};
MODULE_DEVICE_TABLE(i2c, pca963x_id);
struct pca963x;
struct pca963x_led {
struct pca963x *chip;
struct led_classdev led_cdev;
int led_num; /* 0 .. 15 potentially */
bool blinking;
u8 gdc;
u8 gfrq;
};
struct pca963x {
struct pca963x_chipdef *chipdef;
struct mutex mutex;
struct i2c_client *client;
unsigned long leds_on;
struct pca963x_led leds[];
};
static int pca963x_brightness(struct pca963x_led *led,
enum led_brightness brightness)
{
struct i2c_client *client = led->chip->client;
struct pca963x_chipdef *chipdef = led->chip->chipdef;
u8 ledout_addr, ledout, mask, val;
int shift;
int ret;
ledout_addr = chipdef->ledout_base + (led->led_num / 4);
shift = 2 * (led->led_num % 4);
mask = 0x3 << shift;
ledout = i2c_smbus_read_byte_data(client, ledout_addr);
switch (brightness) {
case LED_FULL:
if (led->blinking) {
val = (ledout & ~mask) | (PCA963X_LED_GRP_PWM << shift);
ret = i2c_smbus_write_byte_data(client,
PCA963X_PWM_BASE +
led->led_num,
LED_FULL);
} else {
val = (ledout & ~mask) | (PCA963X_LED_ON << shift);
}
ret = i2c_smbus_write_byte_data(client, ledout_addr, val);
break;
case LED_OFF:
val = ledout & ~mask;
Annotation
- Immediate include surface: `linux/module.h`, `linux/delay.h`, `linux/string.h`, `linux/ctype.h`, `linux/leds.h`, `linux/err.h`, `linux/i2c.h`, `linux/property.h`.
- Detected declarations: `struct pca963x_chipdef`, `struct pca963x`, `struct pca963x_led`, `struct pca963x`, `enum pca963x_type`, `function pca963x_brightness`, `function pca963x_blink`, `function pca963x_power_state`, `function pca963x_led_set`, `function pca963x_period_scale`.
- 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.