drivers/leds/leds-aw2013.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-aw2013.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-aw2013.c- Extension
.c- Size
- 9864 bytes
- Lines
- 442
- 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/i2c.hlinux/leds.hlinux/module.hlinux/regulator/consumer.hlinux/mutex.hlinux/of.hlinux/regmap.h
Detected Declarations
struct aw2013struct aw2013_ledstruct aw2013function aw2013_chip_initfunction aw2013_chip_disablefunction aw2013_chip_enablefunction aw2013_chip_in_usefunction aw2013_brightness_setfunction aw2013_blink_setfunction aw2013_probe_dtfunction for_each_available_child_of_node_scopedfunction aw2013_chip_disable_actionfunction aw2013_probe
Annotated Snippet
struct aw2013_led {
struct aw2013 *chip;
struct led_classdev cdev;
u32 num;
unsigned int imax;
};
struct aw2013 {
struct mutex mutex; /* held when writing to registers */
struct regulator_bulk_data regulators[2];
struct i2c_client *client;
struct aw2013_led leds[AW2013_MAX_LEDS];
struct regmap *regmap;
int num_leds;
bool enabled;
};
static int aw2013_chip_init(struct aw2013 *chip)
{
int i, ret;
ret = regmap_write(chip->regmap, AW2013_GCR, AW2013_GCR_ENABLE);
if (ret) {
dev_err(&chip->client->dev, "Failed to enable the chip: %d\n",
ret);
return ret;
}
for (i = 0; i < chip->num_leds; i++) {
ret = regmap_update_bits(chip->regmap,
AW2013_LCFG(chip->leds[i].num),
AW2013_LCFG_IMAX_MASK,
chip->leds[i].imax);
if (ret) {
dev_err(&chip->client->dev,
"Failed to set maximum current for led %d: %d\n",
chip->leds[i].num, ret);
return ret;
}
}
return ret;
}
static void aw2013_chip_disable(struct aw2013 *chip)
{
int ret;
if (!chip->enabled)
return;
regmap_write(chip->regmap, AW2013_GCR, 0);
ret = regulator_bulk_disable(ARRAY_SIZE(chip->regulators),
chip->regulators);
if (ret) {
dev_err(&chip->client->dev,
"Failed to disable regulators: %d\n", ret);
return;
}
chip->enabled = false;
}
static int aw2013_chip_enable(struct aw2013 *chip)
{
int ret;
if (chip->enabled)
return 0;
ret = regulator_bulk_enable(ARRAY_SIZE(chip->regulators),
chip->regulators);
if (ret) {
dev_err(&chip->client->dev,
"Failed to enable regulators: %d\n", ret);
return ret;
}
chip->enabled = true;
ret = aw2013_chip_init(chip);
if (ret)
aw2013_chip_disable(chip);
return ret;
}
static bool aw2013_chip_in_use(struct aw2013 *chip)
{
int i;
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/leds.h`, `linux/module.h`, `linux/regulator/consumer.h`, `linux/mutex.h`, `linux/of.h`, `linux/regmap.h`.
- Detected declarations: `struct aw2013`, `struct aw2013_led`, `struct aw2013`, `function aw2013_chip_init`, `function aw2013_chip_disable`, `function aw2013_chip_enable`, `function aw2013_chip_in_use`, `function aw2013_brightness_set`, `function aw2013_blink_set`, `function aw2013_probe_dt`.
- 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.