drivers/leds/flash/leds-s2m-flash.c
Source file repositories/reference/linux-study-clean/drivers/leds/flash/leds-s2m-flash.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/flash/leds-s2m-flash.c- Extension
.c- Size
- 9473 bytes
- Lines
- 351
- 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/container_of.hlinux/led-class-flash.hlinux/mfd/samsung/core.hlinux/mfd/samsung/s2mu005.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/regmap.hmedia/v4l2-flash-led-class.h
Detected Declarations
struct s2m_ledfunction s2m_fled_flash_brightness_setfunction s2m_fled_flash_timeout_setfunction s2m_fled_flash_external_strobe_setfunction s2m_fled_v4l2_flash_releasefunction s2mu005_fled_torch_brightness_setfunction s2mu005_fled_flash_strobe_setfunction s2mu005_fled_flash_strobe_getfunction s2mu005_fled_initfunction s2mu005_fled_init_channelfunction s2m_fled_probefunction device_for_each_child_node_scoped
Annotated Snippet
struct s2m_led {
struct regmap *regmap;
struct led_classdev_flash fled;
struct v4l2_flash *v4l2_flash;
/*
* The mutex object prevents the concurrent access of flash control
* registers by the LED and V4L2 subsystems.
*/
struct mutex lock;
unsigned int reg_enable;
u8 channel;
u8 flash_brightness;
u8 flash_timeout;
};
static struct s2m_led *to_s2m_led(struct led_classdev_flash *fled)
{
return container_of(fled, struct s2m_led, fled);
}
static struct led_classdev_flash *to_s2m_fled(struct led_classdev *cdev)
{
return container_of(cdev, struct led_classdev_flash, led_cdev);
}
static int s2m_fled_flash_brightness_set(struct led_classdev_flash *fled, u32 brightness)
{
struct s2m_led *led = to_s2m_led(fled);
struct led_flash_setting *setting = &fled->brightness;
mutex_lock(&led->lock);
led->flash_brightness = (brightness - setting->min) / setting->step;
mutex_unlock(&led->lock);
return 0;
}
static int s2m_fled_flash_timeout_set(struct led_classdev_flash *fled, u32 timeout)
{
struct s2m_led *led = to_s2m_led(fled);
struct led_flash_setting *setting = &fled->timeout;
mutex_lock(&led->lock);
led->flash_timeout = (timeout - setting->min) / setting->step;
mutex_unlock(&led->lock);
return 0;
}
#if IS_ENABLED(CONFIG_V4L2_FLASH_LED_CLASS)
static int s2m_fled_flash_external_strobe_set(struct v4l2_flash *v4l2_flash, bool enable)
{
struct s2m_led *led = to_s2m_led(v4l2_flash->fled_cdev);
return led->fled.ops->strobe_set(&led->fled, enable);
}
static const struct v4l2_flash_ops s2m_fled_v4l2_flash_ops = {
.external_strobe_set = s2m_fled_flash_external_strobe_set,
};
#else
static const struct v4l2_flash_ops s2m_fled_v4l2_flash_ops;
#endif
static void s2m_fled_v4l2_flash_release(void *v4l2_flash)
{
v4l2_flash_release(v4l2_flash);
}
static int s2mu005_fled_torch_brightness_set(struct led_classdev *cdev, enum led_brightness value)
{
struct s2m_led *led = to_s2m_led(to_s2m_fled(cdev));
int ret;
mutex_lock(&led->lock);
if (!value) {
ret = regmap_clear_bits(led->regmap, led->reg_enable,
S2MU005_FLED_TORCH_EN(led->channel));
if (ret)
dev_err(cdev->dev, "failed to disable torch LED\n");
goto unlock;
}
ret = regmap_update_bits(led->regmap, S2MU005_REG_FLED_CH_CTRL1(led->channel),
S2MU005_FLED_TORCH_IOUT,
FIELD_PREP(S2MU005_FLED_TORCH_IOUT, value - 1));
if (ret) {
dev_err(cdev->dev, "failed to set torch current\n");
goto unlock;
Annotation
- Immediate include surface: `linux/container_of.h`, `linux/led-class-flash.h`, `linux/mfd/samsung/core.h`, `linux/mfd/samsung/s2mu005.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/regmap.h`.
- Detected declarations: `struct s2m_led`, `function s2m_fled_flash_brightness_set`, `function s2m_fled_flash_timeout_set`, `function s2m_fled_flash_external_strobe_set`, `function s2m_fled_v4l2_flash_release`, `function s2mu005_fled_torch_brightness_set`, `function s2mu005_fled_flash_strobe_set`, `function s2mu005_fled_flash_strobe_get`, `function s2mu005_fled_init`, `function s2mu005_fled_init_channel`.
- 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.