drivers/leds/leds-pca9532.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-pca9532.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-pca9532.c- Extension
.c- Size
- 15780 bytes
- Lines
- 603
- 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/i2c.hlinux/slab.hlinux/leds.hlinux/input.hlinux/mutex.hlinux/workqueue.hlinux/leds-pca9532.hlinux/gpio/driver.hlinux/of.h
Detected Declarations
struct pca9532_chip_infostruct pca9532_datafunction pca9532_calcpwmfunction pca9532_setpwmfunction pca9532_setledfunction pca9532_set_brightnessfunction pca9532_update_hw_blinkfunction pca9532_set_blinkfunction pca9532_eventfunction pca9532_input_workfunction pca9532_getledfunction pca9532_gpio_request_pinfunction pca9532_gpio_set_valuefunction pca9532_gpio_get_valuefunction pca9532_gpio_direction_inputfunction pca9532_gpio_direction_outputfunction pca9532_destroy_devicesfunction pca9532_configurefunction pca9532_of_populate_pdatafunction for_each_available_child_of_node_scopedfunction pca9532_probefunction pca9532_remove
Annotated Snippet
struct pca9532_chip_info {
u8 num_leds;
};
struct pca9532_data {
struct i2c_client *client;
struct pca9532_led leds[16];
struct mutex update_lock;
struct input_dev *idev;
struct work_struct work;
#ifdef CONFIG_LEDS_PCA9532_GPIO
struct gpio_chip gpio;
#endif
const struct pca9532_chip_info *chip_info;
#define PCA9532_PWM_ID_0 0
#define PCA9532_PWM_ID_1 1
u8 pwm[2];
u8 psc[2];
bool hw_blink;
};
static int pca9532_probe(struct i2c_client *client);
static void pca9532_remove(struct i2c_client *client);
enum {
pca9530,
pca9531,
pca9532,
pca9533,
};
static const struct i2c_device_id pca9532_id[] = {
{ .name = "pca9530", .driver_data = pca9530 },
{ .name = "pca9531", .driver_data = pca9531 },
{ .name = "pca9532", .driver_data = pca9532 },
{ .name = "pca9533", .driver_data = pca9533 },
{ }
};
MODULE_DEVICE_TABLE(i2c, pca9532_id);
static const struct pca9532_chip_info pca9532_chip_info_tbl[] = {
[pca9530] = {
.num_leds = 2,
},
[pca9531] = {
.num_leds = 8,
},
[pca9532] = {
.num_leds = 16,
},
[pca9533] = {
.num_leds = 4,
},
};
#ifdef CONFIG_OF
static const struct of_device_id of_pca9532_leds_match[] = {
{ .compatible = "nxp,pca9530", .data = (void *)pca9530 },
{ .compatible = "nxp,pca9531", .data = (void *)pca9531 },
{ .compatible = "nxp,pca9532", .data = (void *)pca9532 },
{ .compatible = "nxp,pca9533", .data = (void *)pca9533 },
{},
};
MODULE_DEVICE_TABLE(of, of_pca9532_leds_match);
#endif
static struct i2c_driver pca9532_driver = {
.driver = {
.name = "leds-pca953x",
.of_match_table = of_match_ptr(of_pca9532_leds_match),
},
.probe = pca9532_probe,
.remove = pca9532_remove,
.id_table = pca9532_id,
};
/* We have two pwm/blinkers, but 16 possible leds to drive. Additionally,
* the clever Thecus people are using one pwm to drive the beeper. So,
* as a compromise we average one pwm to the values requested by all
* leds that are not ON/OFF.
* */
static int pca9532_calcpwm(struct i2c_client *client, int pwm, int blink,
enum led_brightness value)
{
int a = 0, b = 0, i = 0;
struct pca9532_data *data = i2c_get_clientdata(client);
for (i = 0; i < data->chip_info->num_leds; i++) {
Annotation
- Immediate include surface: `linux/module.h`, `linux/i2c.h`, `linux/slab.h`, `linux/leds.h`, `linux/input.h`, `linux/mutex.h`, `linux/workqueue.h`, `linux/leds-pca9532.h`.
- Detected declarations: `struct pca9532_chip_info`, `struct pca9532_data`, `function pca9532_calcpwm`, `function pca9532_setpwm`, `function pca9532_setled`, `function pca9532_set_brightness`, `function pca9532_update_hw_blink`, `function pca9532_set_blink`, `function pca9532_event`, `function pca9532_input_work`.
- 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.