drivers/media/i2c/lm3560.c

Source file repositories/reference/linux-study-clean/drivers/media/i2c/lm3560.c

File Facts

System
Linux kernel
Corpus path
drivers/media/i2c/lm3560.c
Extension
.c
Size
18545 bytes
Lines
730
Domain
Driver Families
Bucket
drivers/media
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 lm3560_flash_config {
	u32 flash_brt_min_ua;
	u32 flash_brt_max_ua;
	u32 flash_brt_step_ua;

	u32 torch_brt_min_ua;
	u32 torch_brt_max_ua;
	u32 torch_brt_step_ua;
};

/**
 * struct lm3560_flash
 *
 * @dev: pointer to &struct device
 * @regmap: reg. map for i2c
 * @lock: muxtex for serial access.
 * @hwen_gpio: line connected to HWEN pin
 * @vin_supply: line connected to IN supply (2.5V - 5.5V)
 * @led_mode: V4L2 LED mode
 * @ctrls_led: V4L2 controls
 * @subdev_led: V4L2 subdev
 * @led_id: LED status holder
 * @peak: peak current
 * @max_flash_timeout: flash timeout
 * @max_flash_brt: flash mode led brightness
 * @max_torch_brt: torch mode led brightness
 * @config: device specific current configuration
 */
struct lm3560_flash {
	struct device *dev;
	struct regmap *regmap;
	struct mutex lock;

	struct gpio_desc *hwen_gpio;
	struct regulator *vin_supply;

	enum v4l2_flash_led_mode led_mode;
	struct v4l2_ctrl_handler ctrls_led[LM3560_LED_MAX];
	struct v4l2_subdev subdev_led[LM3560_LED_MAX];

	DECLARE_BITMAP(led_id, LM3560_LED_MAX);

	enum lm3560_peak_current peak;
	u32 max_flash_timeout;

	u32 max_flash_brt[LM3560_LED_MAX];
	u32 max_torch_brt[LM3560_LED_MAX];

	const struct lm3560_flash_config *config;
};

#define to_lm3560_flash(_ctrl, _no)	\
	container_of(_ctrl->handler, struct lm3560_flash, ctrls_led[_no])

/* enable mode control */
static int lm3560_mode_ctrl(struct lm3560_flash *flash)
{
	int rval = -EINVAL;

	switch (flash->led_mode) {
	case V4L2_FLASH_LED_MODE_NONE:
		rval = regmap_update_bits(flash->regmap,
					  REG_ENABLE, 0x03, MODE_SHDN);
		break;
	case V4L2_FLASH_LED_MODE_TORCH:
		rval = regmap_update_bits(flash->regmap,
					  REG_ENABLE, 0x03, MODE_TORCH);
		break;
	case V4L2_FLASH_LED_MODE_FLASH:
		rval = regmap_update_bits(flash->regmap,
					  REG_ENABLE, 0x03, MODE_FLASH);
		break;
	}
	return rval;
}

/* led1/2 enable/disable */
static int lm3560_enable_ctrl(struct lm3560_flash *flash,
			      enum lm3560_led_id led_no, bool on)
{
	int rval;

	if (led_no == LM3560_LED0) {
		if (on)
			rval = regmap_update_bits(flash->regmap,
						  REG_ENABLE, 0x08, 0x08);
		else
			rval = regmap_update_bits(flash->regmap,
						  REG_ENABLE, 0x08, 0x00);
	} else {

Annotation

Implementation Notes