drivers/leds/flash/leds-as3645a.c

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

File Facts

System
Linux kernel
Corpus path
drivers/leds/flash/leds-as3645a.c
Extension
.c
Size
19798 bytes
Lines
771
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 as3645a_config {
	u32 flash_timeout_us;
	u32 flash_max_ua;
	u32 assist_max_ua;
	u32 indicator_max_ua;
	u32 voltage_reference;
	u32 peak;
};

struct as3645a {
	struct i2c_client *client;

	struct mutex mutex;

	struct led_classdev_flash fled;
	struct led_classdev iled_cdev;

	struct v4l2_flash *vf;
	struct v4l2_flash *vfind;

	struct fwnode_handle *flash_node;
	struct fwnode_handle *indicator_node;

	struct as3645a_config cfg;

	enum as_mode mode;
	unsigned int timeout;
	unsigned int flash_current;
	unsigned int assist_current;
	unsigned int indicator_current;
	enum v4l2_flash_strobe_source strobe_source;
};

#define fled_to_as3645a(__fled) container_of(__fled, struct as3645a, fled)
#define iled_cdev_to_as3645a(__iled_cdev) \
	container_of(__iled_cdev, struct as3645a, iled_cdev)

/* Return negative errno else zero on success */
static int as3645a_write(struct as3645a *flash, u8 addr, u8 val)
{
	struct i2c_client *client = flash->client;
	int rval;

	rval = i2c_smbus_write_byte_data(client, addr, val);

	dev_dbg(&client->dev, "Write Addr:%02X Val:%02X %s\n", addr, val,
		rval < 0 ? "fail" : "ok");

	return rval;
}

/* Return negative errno else a data byte received from the device. */
static int as3645a_read(struct as3645a *flash, u8 addr)
{
	struct i2c_client *client = flash->client;
	int rval;

	rval = i2c_smbus_read_byte_data(client, addr);

	dev_dbg(&client->dev, "Read Addr:%02X Val:%02X %s\n", addr, rval,
		rval < 0 ? "fail" : "ok");

	return rval;
}

/* -----------------------------------------------------------------------------
 * Hardware configuration and trigger
 */

/**
 * as3645a_set_current - Set flash configuration registers
 * @flash: The flash
 *
 * Configure the hardware with flash, assist and indicator currents, as well as
 * flash timeout.
 *
 * Return 0 on success, or a negative error code if an I2C communication error
 * occurred.
 */
static int as3645a_set_current(struct as3645a *flash)
{
	u8 val;

	val = (flash->flash_current << AS_CURRENT_FLASH_CURRENT_SHIFT)
	    | (flash->assist_current << AS_CURRENT_ASSIST_LIGHT_SHIFT)
	    | AS_CURRENT_LED_DET_ON;

	return as3645a_write(flash, AS_CURRENT_SET_REG, val);
}

Annotation

Implementation Notes