drivers/video/backlight/lm3509_bl.c

Source file repositories/reference/linux-study-clean/drivers/video/backlight/lm3509_bl.c

File Facts

System
Linux kernel
Corpus path
drivers/video/backlight/lm3509_bl.c
Extension
.c
Size
8084 bytes
Lines
344
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 lm3509_bl {
	struct regmap *regmap;
	struct backlight_device *bl_main;
	struct backlight_device *bl_sub;
	struct gpio_desc *reset_gpio;
};

struct lm3509_bl_led_data {
	const char *label;
	int led_sources;
	u32 brightness;
	u32 max_brightness;
};

static void lm3509_reset(struct lm3509_bl *data)
{
	if (data->reset_gpio) {
		gpiod_set_value(data->reset_gpio, 1);
		udelay(1);
		gpiod_set_value(data->reset_gpio, 0);
		udelay(10);
	}
}

static int lm3509_update_status(struct backlight_device *bl,
				unsigned int en_mask, unsigned int br_reg)
{
	struct lm3509_bl *data = bl_get_data(bl);
	int ret;
	bool en;

	ret = regmap_write(data->regmap, br_reg, backlight_get_brightness(bl));
	if (ret < 0)
		return ret;

	en = !backlight_is_blank(bl);
	return regmap_update_bits(data->regmap, REG_GP, en_mask,
				  en ? en_mask : 0);
}

static int lm3509_main_update_status(struct backlight_device *bl)
{
	return lm3509_update_status(bl, BIT(REG_GP_ENM_BIT), REG_BMAIN);
}

static const struct backlight_ops lm3509_main_ops = {
	.options = BL_CORE_SUSPENDRESUME,
	.update_status = lm3509_main_update_status,
};

static int lm3509_sub_update_status(struct backlight_device *bl)
{
	return lm3509_update_status(bl, BIT(REG_GP_ENS_BIT), REG_BSUB);
}

static const struct backlight_ops lm3509_sub_ops = {
	.options = BL_CORE_SUSPENDRESUME,
	.update_status = lm3509_sub_update_status,
};

static struct backlight_device *
lm3509_backlight_register(struct device *dev, const char *name_suffix,
			  struct lm3509_bl *data,
			  const struct backlight_ops *ops,
			  const struct lm3509_bl_led_data *led_data)

{
	struct backlight_device *bd;
	struct backlight_properties props;
	const char *label = led_data->label;
	char name[64];

	memset(&props, 0, sizeof(props));
	props.type = BACKLIGHT_RAW;
	props.brightness = led_data->brightness;
	props.max_brightness = led_data->max_brightness;
	props.scale = BACKLIGHT_SCALE_NON_LINEAR;

	if (!label) {
		snprintf(name, sizeof(name), "lm3509-%s-%s", dev_name(dev),
			 name_suffix);
		label = name;
	}

	bd = devm_backlight_device_register(dev, label, dev, data, ops, &props);
	if (IS_ERR(bd))
		return bd;

	backlight_update_status(bd);
	return bd;

Annotation

Implementation Notes