drivers/leds/leds-an30259a.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-an30259a.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-an30259a.c- Extension
.c- Size
- 8431 bytes
- Lines
- 353
- 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/mutex.hlinux/of.hlinux/regmap.h
Detected Declarations
struct an30259astruct an30259a_ledstruct an30259afunction an30259a_brightness_setfunction an30259a_blink_setfunction an30259a_dt_initfunction for_each_available_child_of_nodefunction an30259a_init_default_statefunction an30259a_probe
Annotated Snippet
struct an30259a_led {
struct an30259a *chip;
struct fwnode_handle *fwnode;
struct led_classdev cdev;
u32 num;
enum led_default_state default_state;
bool sloping;
};
struct an30259a {
struct mutex mutex; /* held when writing to registers */
struct i2c_client *client;
struct an30259a_led leds[AN30259A_MAX_LEDS];
struct regmap *regmap;
int num_leds;
};
static int an30259a_brightness_set(struct led_classdev *cdev,
enum led_brightness brightness)
{
struct an30259a_led *led;
int ret;
unsigned int led_on;
led = container_of(cdev, struct an30259a_led, cdev);
mutex_lock(&led->chip->mutex);
ret = regmap_read(led->chip->regmap, AN30259A_REG_LED_ON, &led_on);
if (ret)
goto error;
switch (brightness) {
case LED_OFF:
led_on &= ~AN30259A_LED_EN(led->num);
led_on &= ~AN30259A_LED_SLOPE(led->num);
led->sloping = false;
break;
default:
led_on |= AN30259A_LED_EN(led->num);
if (led->sloping)
led_on |= AN30259A_LED_SLOPE(led->num);
ret = regmap_write(led->chip->regmap,
AN30259A_REG_LEDCNT1(led->num),
AN30259A_LED_DUTYMAX(0xf) |
AN30259A_LED_DUTYMID(0xf));
if (ret)
goto error;
break;
}
ret = regmap_write(led->chip->regmap, AN30259A_REG_LED_ON, led_on);
if (ret)
goto error;
ret = regmap_write(led->chip->regmap, AN30259A_REG_LEDCC(led->num),
brightness);
error:
mutex_unlock(&led->chip->mutex);
return ret;
}
static int an30259a_blink_set(struct led_classdev *cdev,
unsigned long *delay_off, unsigned long *delay_on)
{
struct an30259a_led *led;
int ret, num;
unsigned int led_on;
unsigned long off = *delay_off, on = *delay_on;
led = container_of(cdev, struct an30259a_led, cdev);
mutex_lock(&led->chip->mutex);
num = led->num;
/* slope time can only be a multiple of 500ms. */
if (off % AN30259A_SLOPE_RESOLUTION || on % AN30259A_SLOPE_RESOLUTION) {
ret = -EINVAL;
goto error;
}
/* up to a maximum of 7500ms. */
if (off > AN30259A_BLINK_MAX_TIME || on > AN30259A_BLINK_MAX_TIME) {
ret = -EINVAL;
goto error;
}
/* if no blink specified, default to 1 Hz. */
if (!off && !on) {
Annotation
- Immediate include surface: `linux/i2c.h`, `linux/leds.h`, `linux/module.h`, `linux/mutex.h`, `linux/of.h`, `linux/regmap.h`.
- Detected declarations: `struct an30259a`, `struct an30259a_led`, `struct an30259a`, `function an30259a_brightness_set`, `function an30259a_blink_set`, `function an30259a_dt_init`, `function for_each_available_child_of_node`, `function an30259a_init_default_state`, `function an30259a_probe`.
- 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.