drivers/leds/leds-da9052.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-da9052.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-da9052.c- Extension
.c- Size
- 4516 bytes
- Lines
- 190
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/kernel.hlinux/platform_device.hlinux/leds.hlinux/slab.hlinux/mfd/da9052/reg.hlinux/mfd/da9052/da9052.hlinux/mfd/da9052/pdata.h
Detected Declarations
struct da9052_ledfunction da9052_set_led_brightnessfunction da9052_led_setfunction da9052_configure_ledsfunction da9052_led_probefunction da9052_led_remove
Annotated Snippet
struct da9052_led {
struct led_classdev cdev;
struct da9052 *da9052;
unsigned char led_index;
unsigned char id;
};
static unsigned char led_reg[] = {
DA9052_LED_CONT_4_REG,
DA9052_LED_CONT_5_REG,
};
static int da9052_set_led_brightness(struct da9052_led *led,
enum led_brightness brightness)
{
u8 val;
int error;
val = (brightness & 0x7f) | DA9052_LED_CONT_DIM;
error = da9052_reg_write(led->da9052, led_reg[led->led_index], val);
if (error < 0)
dev_err(led->da9052->dev, "Failed to set led brightness, %d\n",
error);
return error;
}
static int da9052_led_set(struct led_classdev *led_cdev,
enum led_brightness value)
{
struct da9052_led *led =
container_of(led_cdev, struct da9052_led, cdev);
return da9052_set_led_brightness(led, value);
}
static int da9052_configure_leds(struct da9052 *da9052)
{
int error;
unsigned char register_value = DA9052_OPENDRAIN_OUTPUT
| DA9052_SET_HIGH_LVL_OUTPUT;
error = da9052_reg_update(da9052, DA9052_GPIO_14_15_REG,
DA9052_MASK_LOWER_NIBBLE,
register_value);
if (error < 0) {
dev_err(da9052->dev, "Failed to write GPIO 14-15 reg, %d\n",
error);
return error;
}
error = da9052_reg_update(da9052, DA9052_GPIO_14_15_REG,
DA9052_MASK_UPPER_NIBBLE,
register_value << DA9052_NIBBLE_SHIFT);
if (error < 0)
dev_err(da9052->dev, "Failed to write GPIO 14-15 reg, %d\n",
error);
return error;
}
static int da9052_led_probe(struct platform_device *pdev)
{
struct da9052_pdata *pdata;
struct da9052 *da9052;
struct led_platform_data *pled;
struct da9052_led *led = NULL;
int error = -ENODEV;
int i;
da9052 = dev_get_drvdata(pdev->dev.parent);
pdata = dev_get_platdata(da9052->dev);
if (pdata == NULL) {
dev_err(&pdev->dev, "No platform data\n");
goto err;
}
pled = pdata->pled;
if (pled == NULL) {
dev_err(&pdev->dev, "No platform data for LED\n");
goto err;
}
led = devm_kcalloc(&pdev->dev,
pled->num_leds, sizeof(struct da9052_led),
GFP_KERNEL);
if (!led) {
error = -ENOMEM;
goto err;
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/platform_device.h`, `linux/leds.h`, `linux/slab.h`, `linux/mfd/da9052/reg.h`, `linux/mfd/da9052/da9052.h`, `linux/mfd/da9052/pdata.h`.
- Detected declarations: `struct da9052_led`, `function da9052_set_led_brightness`, `function da9052_led_set`, `function da9052_configure_leds`, `function da9052_led_probe`, `function da9052_led_remove`.
- 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.