drivers/leds/leds-lt3593.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-lt3593.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-lt3593.c- Extension
.c- Size
- 3245 bytes
- Lines
- 129
- 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/kernel.hlinux/platform_device.hlinux/leds.hlinux/delay.hlinux/gpio/consumer.hlinux/slab.hlinux/mod_devicetable.hlinux/module.hlinux/property.h
Detected Declarations
struct lt3593_led_datafunction lt3593_led_setfunction lt3593_led_probe
Annotated Snippet
struct lt3593_led_data {
struct led_classdev cdev;
struct gpio_desc *gpiod;
};
static int lt3593_led_set(struct led_classdev *led_cdev,
enum led_brightness value)
{
struct lt3593_led_data *led_dat =
container_of(led_cdev, struct lt3593_led_data, cdev);
int pulses;
/*
* The LT3593 resets its internal current level register to the maximum
* level on the first falling edge on the control pin. Each following
* falling edge decreases the current level by 625uA. Up to 32 pulses
* can be sent, so the maximum power reduction is 20mA.
* After a timeout of 128us, the value is taken from the register and
* applied is to the output driver.
*/
if (value == 0) {
gpiod_set_value_cansleep(led_dat->gpiod, 0);
return 0;
}
pulses = 32 - (value * 32) / 255;
if (pulses == 0) {
gpiod_set_value_cansleep(led_dat->gpiod, 0);
mdelay(1);
gpiod_set_value_cansleep(led_dat->gpiod, 1);
return 0;
}
gpiod_set_value_cansleep(led_dat->gpiod, 1);
while (pulses--) {
gpiod_set_value_cansleep(led_dat->gpiod, 0);
udelay(1);
gpiod_set_value_cansleep(led_dat->gpiod, 1);
udelay(1);
}
return 0;
}
static int lt3593_led_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct lt3593_led_data *led_data;
struct fwnode_handle *child;
int ret, state = LEDS_GPIO_DEFSTATE_OFF;
struct led_init_data init_data = {};
const char *tmp;
led_data = devm_kzalloc(dev, sizeof(*led_data), GFP_KERNEL);
if (!led_data)
return -ENOMEM;
if (device_get_child_node_count(dev) != 1) {
dev_err(dev, "Device must have exactly one LED sub-node.");
return -EINVAL;
}
led_data->gpiod = devm_gpiod_get(dev, "lltc,ctrl", 0);
if (IS_ERR(led_data->gpiod))
return PTR_ERR(led_data->gpiod);
child = device_get_next_child_node(dev, NULL);
if (!fwnode_property_read_string(child, "default-state", &tmp)) {
if (!strcmp(tmp, "on"))
state = LEDS_GPIO_DEFSTATE_ON;
}
led_data->cdev.brightness_set_blocking = lt3593_led_set;
led_data->cdev.brightness = state ? LED_FULL : LED_OFF;
init_data.fwnode = child;
init_data.devicename = LED_LT3593_NAME;
init_data.default_label = ":";
ret = devm_led_classdev_register_ext(dev, &led_data->cdev, &init_data);
fwnode_handle_put(child);
if (ret < 0)
return ret;
platform_set_drvdata(pdev, led_data);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/platform_device.h`, `linux/leds.h`, `linux/delay.h`, `linux/gpio/consumer.h`, `linux/slab.h`, `linux/mod_devicetable.h`, `linux/module.h`.
- Detected declarations: `struct lt3593_led_data`, `function lt3593_led_set`, `function lt3593_led_probe`.
- 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.