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.

Dependency Surface

Detected Declarations

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

Implementation Notes