drivers/video/backlight/backlight.c

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

File Facts

System
Linux kernel
Corpus path
drivers/video/backlight/backlight.c
Extension
.c
Size
18471 bytes
Lines
691
Domain
Driver Families
Bucket
drivers/video
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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

if (!bd->use_count++) {
			bd->props.state &= ~BL_CORE_FBBLANK;
			backlight_update_status(bd);
		}
	} else if (!fb_on && prev_fb_on && bd->use_count) {
		if (!(--bd->use_count)) {
			bd->props.state |= BL_CORE_FBBLANK;
			backlight_update_status(bd);
		}
	}
}
EXPORT_SYMBOL(backlight_notify_blank);

void backlight_notify_blank_all(struct device *display_dev, bool fb_on, bool prev_fb_on)
{
	struct backlight_device *bd;

	guard(mutex)(&backlight_dev_list_mutex);

	list_for_each_entry(bd, &backlight_dev_list, entry)
		backlight_notify_blank(bd, display_dev, fb_on, prev_fb_on);
}
EXPORT_SYMBOL(backlight_notify_blank_all);

static void backlight_generate_event(struct backlight_device *bd,
				     enum backlight_update_reason reason)
{
	char *envp[2];

	switch (reason) {
	case BACKLIGHT_UPDATE_SYSFS:
		envp[0] = "SOURCE=sysfs";
		break;
	case BACKLIGHT_UPDATE_HOTKEY:
		envp[0] = "SOURCE=hotkey";
		break;
	default:
		envp[0] = "SOURCE=unknown";
		break;
	}
	envp[1] = NULL;
	kobject_uevent_env(&bd->dev.kobj, KOBJ_CHANGE, envp);
	sysfs_notify(&bd->dev.kobj, NULL, "actual_brightness");
}

static ssize_t bl_power_show(struct device *dev, struct device_attribute *attr,
		char *buf)
{
	struct backlight_device *bd = to_backlight_device(dev);

	return sprintf(buf, "%d\n", bd->props.power);
}

static ssize_t bl_power_store(struct device *dev, struct device_attribute *attr,
		const char *buf, size_t count)
{
	int rc;
	struct backlight_device *bd = to_backlight_device(dev);
	unsigned long power, old_power;

	rc = kstrtoul(buf, 0, &power);
	if (rc)
		return rc;

	rc = -ENXIO;
	mutex_lock(&bd->ops_lock);
	if (bd->ops) {
		pr_debug("set power to %lu\n", power);
		if (bd->props.power != power) {
			old_power = bd->props.power;
			bd->props.power = power;
			rc = backlight_update_status(bd);
			if (rc)
				bd->props.power = old_power;
			else
				rc = count;
		} else {
			rc = count;
		}
	}
	mutex_unlock(&bd->ops_lock);

	return rc;
}
static DEVICE_ATTR_RW(bl_power);

static ssize_t brightness_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{
	struct backlight_device *bd = to_backlight_device(dev);

Annotation

Implementation Notes