drivers/leds/flash/leds-max77693.c

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

File Facts

System
Linux kernel
Corpus path
drivers/leds/flash/leds-max77693.c
Extension
.c
Size
27597 bytes
Lines
1058
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 max77693_led_config_data {
	const char *label[2];
	u32 iout_torch_max[2];
	u32 iout_flash_max[2];
	u32 flash_timeout_max[2];
	u32 num_leds;
	u32 boost_mode;
	u32 boost_vout;
	u32 low_vsys;
};

struct max77693_sub_led {
	/* corresponding FLED output identifier */
	int fled_id;
	/* corresponding LED Flash class device */
	struct led_classdev_flash fled_cdev;
	/* V4L2 Flash device */
	struct v4l2_flash *v4l2_flash;

	/* brightness cache */
	unsigned int torch_brightness;
	/* flash timeout cache */
	unsigned int flash_timeout;
	/* flash faults that may have occurred */
	u32 flash_faults;
};

struct max77693_led_device {
	/* parent mfd regmap */
	struct regmap *regmap;
	/* platform device data */
	struct platform_device *pdev;
	/* secures access to the device */
	struct mutex lock;

	/* sub led data */
	struct max77693_sub_led sub_leds[2];

	/* maximum torch current values for FLED outputs */
	u32 iout_torch_max[2];
	/* maximum flash current values for FLED outputs */
	u32 iout_flash_max[2];

	/* current flash timeout cache */
	unsigned int current_flash_timeout;
	/* ITORCH register cache */
	u8 torch_iout_reg;
	/* mode of fled outputs */
	unsigned int mode_flags;
	/* recently strobed fled */
	int strobing_sub_led_id;
	/* bitmask of FLED outputs use state (bit 0. - FLED1, bit 1. - FLED2) */
	u8 fled_mask;
	/* FLED modes that can be set */
	u8 allowed_modes;

	/* arrangement of current outputs */
	bool iout_joint;
};

static u8 max77693_led_iout_to_reg(u32 ua)
{
	if (ua < FLASH_IOUT_MIN)
		ua = FLASH_IOUT_MIN;
	return (ua - FLASH_IOUT_MIN) / FLASH_IOUT_STEP;
}

static u8 max77693_flash_timeout_to_reg(u32 us)
{
	return (us - FLASH_TIMEOUT_MIN) / FLASH_TIMEOUT_STEP;
}

static inline struct max77693_sub_led *flcdev_to_sub_led(
					struct led_classdev_flash *fled_cdev)
{
	return container_of(fled_cdev, struct max77693_sub_led, fled_cdev);
}

static inline struct max77693_led_device *sub_led_to_led(
					struct max77693_sub_led *sub_led)
{
	return container_of(sub_led, struct max77693_led_device,
				sub_leds[sub_led->fled_id]);
}

static inline u8 max77693_led_vsys_to_reg(u32 mv)
{
	return ((mv - MAX_FLASH1_VSYS_MIN) / MAX_FLASH1_VSYS_STEP) << 2;
}

Annotation

Implementation Notes