drivers/video/backlight/mt6370-backlight.c
Source file repositories/reference/linux-study-clean/drivers/video/backlight/mt6370-backlight.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/video/backlight/mt6370-backlight.c- Extension
.c- Size
- 9876 bytes
- Lines
- 350
- 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
linux/backlight.hlinux/bitfield.hlinux/bits.hlinux/gpio/consumer.hlinux/kernel.hlinux/minmax.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/property.hlinux/regmap.h
Detected Declarations
struct mt6370_privfunction mt6370_bl_update_statusfunction mt6370_bl_get_brightnessfunction mt6370_init_backlight_propertiesfunction mt6370_check_vendor_infofunction mt6370_bl_probefunction mt6370_bl_remove
Annotated Snippet
struct mt6370_priv {
u8 dim2_mask;
u8 dim2_shift;
int def_max_brightness;
struct backlight_device *bl;
struct device *dev;
struct gpio_desc *enable_gpio;
struct regmap *regmap;
};
static int mt6370_bl_update_status(struct backlight_device *bl_dev)
{
struct mt6370_priv *priv = bl_get_data(bl_dev);
int brightness = backlight_get_brightness(bl_dev);
unsigned int enable_val;
u8 brightness_val[2];
int ret;
if (brightness) {
brightness_val[0] = (brightness - 1) & priv->dim2_mask;
brightness_val[1] = (brightness - 1) >> priv->dim2_shift;
ret = regmap_raw_write(priv->regmap, MT6370_REG_BL_DIM2,
brightness_val, sizeof(brightness_val));
if (ret)
return ret;
}
gpiod_set_value(priv->enable_gpio, !!brightness);
enable_val = brightness ? MT6370_BL_EN_MASK : 0;
return regmap_update_bits(priv->regmap, MT6370_REG_BL_EN,
MT6370_BL_EN_MASK, enable_val);
}
static int mt6370_bl_get_brightness(struct backlight_device *bl_dev)
{
struct mt6370_priv *priv = bl_get_data(bl_dev);
unsigned int enable;
u8 brightness_val[2];
int brightness, ret;
ret = regmap_read(priv->regmap, MT6370_REG_BL_EN, &enable);
if (ret)
return ret;
if (!(enable & MT6370_BL_EN_MASK))
return 0;
ret = regmap_raw_read(priv->regmap, MT6370_REG_BL_DIM2,
brightness_val, sizeof(brightness_val));
if (ret)
return ret;
brightness = brightness_val[1] << priv->dim2_shift;
brightness += brightness_val[0] & priv->dim2_mask;
return brightness + 1;
}
static const struct backlight_ops mt6370_bl_ops = {
.options = BL_CORE_SUSPENDRESUME,
.update_status = mt6370_bl_update_status,
.get_brightness = mt6370_bl_get_brightness,
};
static int mt6370_init_backlight_properties(struct mt6370_priv *priv,
struct backlight_properties *props)
{
struct device *dev = priv->dev;
u8 prop_val;
u32 brightness, ovp_uV, ocp_uA;
unsigned int mask, val;
int ret;
/* Vendor optional properties */
val = 0;
if (device_property_read_bool(dev, "mediatek,bled-pwm-enable"))
val |= MT6370_BL_PWM_EN_MASK;
if (device_property_read_bool(dev, "mediatek,bled-pwm-hys-enable"))
val |= MT6370_BL_PWM_HYS_EN_MASK;
ret = device_property_read_u8(dev,
"mediatek,bled-pwm-hys-input-th-steps",
&prop_val);
if (!ret) {
prop_val = clamp_val(prop_val,
MT6370_BL_PWM_HYS_TH_MIN_STEP,
MT6370_BL_PWM_HYS_TH_MAX_STEP);
Annotation
- Immediate include surface: `linux/backlight.h`, `linux/bitfield.h`, `linux/bits.h`, `linux/gpio/consumer.h`, `linux/kernel.h`, `linux/minmax.h`, `linux/mod_devicetable.h`, `linux/module.h`.
- Detected declarations: `struct mt6370_priv`, `function mt6370_bl_update_status`, `function mt6370_bl_get_brightness`, `function mt6370_init_backlight_properties`, `function mt6370_check_vendor_info`, `function mt6370_bl_probe`, `function mt6370_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.