drivers/leds/flash/leds-rt8515.c

Source file repositories/reference/linux-study-clean/drivers/leds/flash/leds-rt8515.c

File Facts

System
Linux kernel
Corpus path
drivers/leds/flash/leds-rt8515.c
Extension
.c
Size
10525 bytes
Lines
398
Domain
Driver Families
Bucket
drivers/leds
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 rt8515 {
	struct led_classdev_flash fled;
	struct device *dev;
	struct v4l2_flash *v4l2_flash;
	struct mutex lock;
	struct regulator *reg;
	struct gpio_desc *enable_torch;
	struct gpio_desc *enable_flash;
	struct timer_list powerdown_timer;
	u32 max_timeout; /* Flash max timeout */
	int flash_max_intensity;
	int torch_max_intensity;
};

static struct rt8515 *to_rt8515(struct led_classdev_flash *fled)
{
	return container_of(fled, struct rt8515, fled);
}

static void rt8515_gpio_led_off(struct rt8515 *rt)
{
	gpiod_set_value(rt->enable_flash, 0);
	gpiod_set_value(rt->enable_torch, 0);
}

static void rt8515_gpio_brightness_commit(struct gpio_desc *gpiod,
					  int brightness)
{
	int i;

	/*
	 * Toggling a GPIO line with a small delay increases the
	 * brightness one step at a time.
	 */
	for (i = 0; i < brightness; i++) {
		gpiod_set_value(gpiod, 0);
		udelay(1);
		gpiod_set_value(gpiod, 1);
		udelay(1);
	}
}

/* This is setting the torch light level */
static int rt8515_led_brightness_set(struct led_classdev *led,
				     enum led_brightness brightness)
{
	struct led_classdev_flash *fled = lcdev_to_flcdev(led);
	struct rt8515 *rt = to_rt8515(fled);

	mutex_lock(&rt->lock);

	if (brightness == LED_OFF) {
		/* Off */
		rt8515_gpio_led_off(rt);
	} else if (brightness < RT8515_TORCH_MAX) {
		/* Step it up to movie mode brightness using the flash pin */
		rt8515_gpio_brightness_commit(rt->enable_torch, brightness);
	} else {
		/* Max torch brightness requested */
		gpiod_set_value(rt->enable_torch, 1);
	}

	mutex_unlock(&rt->lock);

	return 0;
}

static int rt8515_led_flash_strobe_set(struct led_classdev_flash *fled,
				       bool state)
{
	struct rt8515 *rt = to_rt8515(fled);
	struct led_flash_setting *timeout = &fled->timeout;
	int brightness = rt->flash_max_intensity;

	mutex_lock(&rt->lock);

	if (state) {
		/* Enable LED flash mode and set brightness */
		rt8515_gpio_brightness_commit(rt->enable_flash, brightness);
		/* Set timeout */
		mod_timer(&rt->powerdown_timer,
			  jiffies + usecs_to_jiffies(timeout->val));
	} else {
		timer_delete_sync(&rt->powerdown_timer);
		/* Turn the LED off */
		rt8515_gpio_led_off(rt);
	}

	fled->led_cdev.brightness = LED_OFF;
	/* After this the torch LED will be disabled */

Annotation

Implementation Notes