drivers/leds/leds-as3668.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-as3668.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-as3668.c- Extension
.c- Size
- 5465 bytes
- Lines
- 203
- 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.
- 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/bitfield.hlinux/i2c.hlinux/leds.hlinux/module.hlinux/uleds.h
Detected Declarations
struct as3668_ledstruct as3668function as3668_channel_mode_setfunction as3668_brightness_getfunction as3668_brightness_setfunction as3668_dt_initfunction for_each_available_child_of_node_scopedfunction as3668_probefunction as3668_remove
Annotated Snippet
struct as3668_led {
struct led_classdev cdev;
struct as3668 *chip;
struct fwnode_handle *fwnode;
u8 mode_mask;
u8 current_reg;
};
struct as3668 {
struct i2c_client *client;
struct as3668_led leds[AS3668_MAX_LEDS];
};
static int as3668_channel_mode_set(struct as3668_led *led, u8 mode)
{
int ret;
u8 channel_modes;
ret = i2c_smbus_read_byte_data(led->chip->client, AS3668_CURR_MODE_REG);
if (ret < 0) {
dev_err(led->cdev.dev, "failed to read channel modes\n");
return ret;
}
channel_modes = (u8)ret;
channel_modes &= ~led->mode_mask;
channel_modes |= led->mode_mask & (AS3668_CURR_MODE_PACK(mode));
return i2c_smbus_write_byte_data(led->chip->client, AS3668_CURR_MODE_REG, channel_modes);
}
static enum led_brightness as3668_brightness_get(struct led_classdev *cdev)
{
struct as3668_led *led = container_of(cdev, struct as3668_led, cdev);
return i2c_smbus_read_byte_data(led->chip->client, led->current_reg);
}
static void as3668_brightness_set(struct led_classdev *cdev, enum led_brightness brightness)
{
struct as3668_led *led = container_of(cdev, struct as3668_led, cdev);
int err;
err = as3668_channel_mode_set(led, !!brightness);
if (err)
dev_err(cdev->dev, "failed to set channel mode: %d\n", err);
err = i2c_smbus_write_byte_data(led->chip->client, led->current_reg, brightness);
if (err)
dev_err(cdev->dev, "failed to set brightness: %d\n", err);
}
static int as3668_dt_init(struct as3668 *as3668)
{
struct device *dev = &as3668->client->dev;
struct as3668_led *led;
struct led_init_data init_data = {};
int err;
u32 reg;
for_each_available_child_of_node_scoped(dev_of_node(dev), child) {
err = of_property_read_u32(child, "reg", ®);
if (err)
return dev_err_probe(dev, err, "failed to read 'reg' property");
if (reg < 0 || reg >= AS3668_MAX_LEDS)
return dev_err_probe(dev, -EINVAL,
"unsupported LED: %d\n", reg);
led = &as3668->leds[reg];
led->fwnode = of_fwnode_handle(child);
led->current_reg = reg + AS3668_CURR1_REG;
led->mode_mask = AS3668_CURR1_MODE_MASK << (reg * 2);
led->chip = as3668;
led->cdev.max_brightness = U8_MAX;
led->cdev.brightness_get = as3668_brightness_get;
led->cdev.brightness_set = as3668_brightness_set;
init_data.fwnode = led->fwnode;
init_data.default_label = ":";
err = devm_led_classdev_register_ext(dev, &led->cdev, &init_data);
if (err)
return dev_err_probe(dev, err, "failed to register LED %d\n", reg);
}
return 0;
}
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/i2c.h`, `linux/leds.h`, `linux/module.h`, `linux/uleds.h`.
- Detected declarations: `struct as3668_led`, `struct as3668`, `function as3668_channel_mode_set`, `function as3668_brightness_get`, `function as3668_brightness_set`, `function as3668_dt_init`, `function for_each_available_child_of_node_scoped`, `function as3668_probe`, `function as3668_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.