drivers/video/backlight/rt4831-backlight.c
Source file repositories/reference/linux-study-clean/drivers/video/backlight/rt4831-backlight.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/video/backlight/rt4831-backlight.c- Extension
.c- Size
- 6466 bytes
- Lines
- 235
- Domain
- Driver Families
- Bucket
- drivers/video
- 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
dt-bindings/leds/rt4831-backlight.hlinux/backlight.hlinux/bitops.hlinux/kernel.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/property.hlinux/regmap.h
Detected Declarations
struct rt4831_privfunction rt4831_bl_update_statusfunction rt4831_bl_get_brightnessfunction rt4831_parse_backlight_propertiesfunction rt4831_bl_probefunction rt4831_bl_remove
Annotated Snippet
struct rt4831_priv {
struct device *dev;
struct regmap *regmap;
struct backlight_device *bl;
};
static int rt4831_bl_update_status(struct backlight_device *bl_dev)
{
struct rt4831_priv *priv = bl_get_data(bl_dev);
int brightness = backlight_get_brightness(bl_dev);
unsigned int enable = brightness ? RT4831_BLEN_MASK : 0;
u8 v[2];
int ret;
if (brightness) {
v[0] = (brightness - 1) & RT4831_BLDIML_MASK;
v[1] = ((brightness - 1) & RT4831_BLDIMH_MASK) >> RT4831_BLDIMH_SHIFT;
ret = regmap_raw_write(priv->regmap, RT4831_REG_BLDIML, v, sizeof(v));
if (ret)
return ret;
}
return regmap_update_bits(priv->regmap, RT4831_REG_ENABLE, RT4831_BLEN_MASK, enable);
}
static int rt4831_bl_get_brightness(struct backlight_device *bl_dev)
{
struct rt4831_priv *priv = bl_get_data(bl_dev);
unsigned int val;
u8 v[2];
int ret;
ret = regmap_read(priv->regmap, RT4831_REG_ENABLE, &val);
if (ret)
return ret;
if (!(val & RT4831_BLEN_MASK))
return 0;
ret = regmap_raw_read(priv->regmap, RT4831_REG_BLDIML, v, sizeof(v));
if (ret)
return ret;
ret = (v[1] << RT4831_BLDIMH_SHIFT) + (v[0] & RT4831_BLDIML_MASK) + 1;
return ret;
}
static const struct backlight_ops rt4831_bl_ops = {
.options = BL_CORE_SUSPENDRESUME,
.update_status = rt4831_bl_update_status,
.get_brightness = rt4831_bl_get_brightness,
};
static int rt4831_parse_backlight_properties(struct rt4831_priv *priv,
struct backlight_properties *bl_props)
{
struct device *dev = priv->dev;
u8 propval;
u32 brightness, ocp_uA;
unsigned int val = 0;
int ret;
/* common properties */
ret = device_property_read_u32(dev, "max-brightness", &brightness);
if (ret)
brightness = RT4831_BLMAX_BRIGHTNESS;
bl_props->max_brightness = min_t(u32, brightness, RT4831_BLMAX_BRIGHTNESS);
ret = device_property_read_u32(dev, "default-brightness", &brightness);
if (ret)
brightness = bl_props->max_brightness;
bl_props->brightness = min_t(u32, brightness, bl_props->max_brightness);
/* vendor properties */
if (device_property_read_bool(dev, "richtek,pwm-enable"))
val = RT4831_BLPWMEN_MASK;
ret = regmap_update_bits(priv->regmap, RT4831_REG_BLCFG, RT4831_BLPWMEN_MASK, val);
if (ret)
return ret;
ret = device_property_read_u8(dev, "richtek,bled-ovp-sel", &propval);
if (ret)
propval = RT4831_BLOVPLVL_21V;
Annotation
- Immediate include surface: `dt-bindings/leds/rt4831-backlight.h`, `linux/backlight.h`, `linux/bitops.h`, `linux/kernel.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_device.h`, `linux/property.h`.
- Detected declarations: `struct rt4831_priv`, `function rt4831_bl_update_status`, `function rt4831_bl_get_brightness`, `function rt4831_parse_backlight_properties`, `function rt4831_bl_probe`, `function rt4831_bl_remove`.
- Atlas domain: Driver Families / drivers/video.
- 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.