drivers/leds/flash/leds-rt4505.c
Source file repositories/reference/linux-study-clean/drivers/leds/flash/leds-rt4505.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/flash/leds-rt4505.c- Extension
.c- Size
- 11196 bytes
- Lines
- 431
- 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/bitops.hlinux/i2c.hlinux/kernel.hlinux/led-class-flash.hlinux/module.hlinux/mutex.hlinux/property.hlinux/regmap.hmedia/v4l2-flash-led-class.h
Detected Declarations
struct rt4505_privfunction rt4505_torch_brightness_setfunction rt4505_torch_brightness_getfunction rt4505_flash_brightness_setfunction rt4505_flash_strobe_setfunction rt4505_flash_strobe_getfunction rt4505_flash_timeout_setfunction rt4505_fault_getfunction rt4505_is_accessible_regfunction rt4505_flash_external_strobe_setfunction rt4505_init_v4l2_configfunction rt4505_init_v4l2_configfunction rt4505_probefunction rt4505_removefunction rt4505_shutdown
Annotated Snippet
struct rt4505_priv {
struct device *dev;
struct regmap *regmap;
struct mutex lock;
struct led_classdev_flash flash;
struct v4l2_flash *v4l2_flash;
};
static int rt4505_torch_brightness_set(struct led_classdev *lcdev,
enum led_brightness level)
{
struct rt4505_priv *priv =
container_of(lcdev, struct rt4505_priv, flash.led_cdev);
u32 val = 0;
int ret;
mutex_lock(&priv->lock);
if (level != LED_OFF) {
ret = regmap_update_bits(priv->regmap,
RT4505_REG_ILED, RT4505_ITORCH_MASK,
(level - 1) << RT4505_ITORCH_SHIFT);
if (ret)
goto unlock;
val = RT4505_TORCH_SET;
}
ret = regmap_update_bits(priv->regmap, RT4505_REG_ENABLE,
RT4505_ENABLE_MASK, val);
unlock:
mutex_unlock(&priv->lock);
return ret;
}
static enum led_brightness rt4505_torch_brightness_get(
struct led_classdev *lcdev)
{
struct rt4505_priv *priv =
container_of(lcdev, struct rt4505_priv, flash.led_cdev);
u32 val;
int ret;
mutex_lock(&priv->lock);
ret = regmap_read(priv->regmap, RT4505_REG_ENABLE, &val);
if (ret) {
dev_err(lcdev->dev, "Failed to get LED enable\n");
ret = LED_OFF;
goto unlock;
}
if ((val & RT4505_ENABLE_MASK) != RT4505_TORCH_SET) {
ret = LED_OFF;
goto unlock;
}
ret = regmap_read(priv->regmap, RT4505_REG_ILED, &val);
if (ret) {
dev_err(lcdev->dev, "Failed to get LED brightness\n");
ret = LED_OFF;
goto unlock;
}
ret = ((val & RT4505_ITORCH_MASK) >> RT4505_ITORCH_SHIFT) + 1;
unlock:
mutex_unlock(&priv->lock);
return ret;
}
static int rt4505_flash_brightness_set(struct led_classdev_flash *fled_cdev,
u32 brightness)
{
struct rt4505_priv *priv =
container_of(fled_cdev, struct rt4505_priv, flash);
struct led_flash_setting *s = &fled_cdev->brightness;
u32 val = (brightness - s->min) / s->step;
int ret;
mutex_lock(&priv->lock);
ret = regmap_update_bits(priv->regmap, RT4505_REG_ILED,
RT4505_IFLASH_MASK, val);
mutex_unlock(&priv->lock);
return ret;
}
static int rt4505_flash_strobe_set(struct led_classdev_flash *fled_cdev,
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/i2c.h`, `linux/kernel.h`, `linux/led-class-flash.h`, `linux/module.h`, `linux/mutex.h`, `linux/property.h`, `linux/regmap.h`.
- Detected declarations: `struct rt4505_priv`, `function rt4505_torch_brightness_set`, `function rt4505_torch_brightness_get`, `function rt4505_flash_brightness_set`, `function rt4505_flash_strobe_set`, `function rt4505_flash_strobe_get`, `function rt4505_flash_timeout_set`, `function rt4505_fault_get`, `function rt4505_is_accessible_reg`, `function rt4505_flash_external_strobe_set`.
- 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.