drivers/leds/flash/leds-sgm3140.c
Source file repositories/reference/linux-study-clean/drivers/leds/flash/leds-sgm3140.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/flash/leds-sgm3140.c- Extension
.c- Size
- 7805 bytes
- Lines
- 314
- 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/gpio/consumer.hlinux/led-class-flash.hlinux/module.hlinux/regulator/consumer.hlinux/platform_device.hmedia/v4l2-flash-led-class.h
Detected Declarations
struct sgm3140function sgm3140_strobe_setfunction sgm3140_strobe_getfunction sgm3140_timeout_setfunction sgm3140_brightness_setfunction sgm3140_powerdown_timerfunction sgm3140_init_flash_timeoutfunction sgm3140_init_v4l2_flash_configfunction sgm3140_init_v4l2_flash_configfunction sgm3140_remove
Annotated Snippet
struct sgm3140 {
struct led_classdev_flash fled_cdev;
struct v4l2_flash *v4l2_flash;
struct timer_list powerdown_timer;
struct gpio_desc *flash_gpio;
struct gpio_desc *enable_gpio;
struct regulator *vin_regulator;
bool enabled;
/* current timeout in us */
u32 timeout;
/* maximum timeout in us */
u32 max_timeout;
};
static struct sgm3140 *flcdev_to_sgm3140(struct led_classdev_flash *flcdev)
{
return container_of(flcdev, struct sgm3140, fled_cdev);
}
static int sgm3140_strobe_set(struct led_classdev_flash *fled_cdev, bool state)
{
struct sgm3140 *priv = flcdev_to_sgm3140(fled_cdev);
int ret;
if (priv->enabled == state)
return 0;
if (state) {
ret = regulator_enable(priv->vin_regulator);
if (ret) {
dev_err(fled_cdev->led_cdev.dev,
"failed to enable regulator: %d\n", ret);
return ret;
}
gpiod_set_value_cansleep(priv->flash_gpio, 1);
gpiod_set_value_cansleep(priv->enable_gpio, 1);
mod_timer(&priv->powerdown_timer,
jiffies + usecs_to_jiffies(priv->timeout));
} else {
timer_delete_sync(&priv->powerdown_timer);
gpiod_set_value_cansleep(priv->enable_gpio, 0);
gpiod_set_value_cansleep(priv->flash_gpio, 0);
ret = regulator_disable(priv->vin_regulator);
if (ret) {
dev_err(fled_cdev->led_cdev.dev,
"failed to disable regulator: %d\n", ret);
return ret;
}
}
priv->enabled = state;
return 0;
}
static int sgm3140_strobe_get(struct led_classdev_flash *fled_cdev, bool *state)
{
struct sgm3140 *priv = flcdev_to_sgm3140(fled_cdev);
*state = timer_pending(&priv->powerdown_timer);
return 0;
}
static int sgm3140_timeout_set(struct led_classdev_flash *fled_cdev,
u32 timeout)
{
struct sgm3140 *priv = flcdev_to_sgm3140(fled_cdev);
priv->timeout = timeout;
return 0;
}
static const struct led_flash_ops sgm3140_flash_ops = {
.strobe_set = sgm3140_strobe_set,
.strobe_get = sgm3140_strobe_get,
.timeout_set = sgm3140_timeout_set,
};
static int sgm3140_brightness_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
struct led_classdev_flash *fled_cdev = lcdev_to_flcdev(led_cdev);
struct sgm3140 *priv = flcdev_to_sgm3140(fled_cdev);
bool enable = brightness == LED_ON;
Annotation
- Immediate include surface: `linux/gpio/consumer.h`, `linux/led-class-flash.h`, `linux/module.h`, `linux/regulator/consumer.h`, `linux/platform_device.h`, `media/v4l2-flash-led-class.h`.
- Detected declarations: `struct sgm3140`, `function sgm3140_strobe_set`, `function sgm3140_strobe_get`, `function sgm3140_timeout_set`, `function sgm3140_brightness_set`, `function sgm3140_powerdown_timer`, `function sgm3140_init_flash_timeout`, `function sgm3140_init_v4l2_flash_config`, `function sgm3140_init_v4l2_flash_config`, `function sgm3140_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.