drivers/video/backlight/adp8860_bl.c

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

File Facts

System
Linux kernel
Corpus path
drivers/video/backlight/adp8860_bl.c
Extension
.c
Size
22239 bytes
Lines
815
Domain
Driver Families
Bucket
drivers/video
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 adp8860_led {
	struct led_classdev	cdev;
	struct work_struct	work;
	struct i2c_client	*client;
	enum led_brightness	new_brightness;
	int			id;
	int			flags;
};

struct adp8860_bl {
	struct i2c_client *client;
	struct backlight_device *bl;
	struct adp8860_led *led;
	struct adp8860_backlight_platform_data *pdata;
	struct mutex lock;
	unsigned long cached_daylight_max;
	int id;
	int revid;
	int current_brightness;
	unsigned en_ambl_sens:1;
	unsigned gdwn_dis:1;
};

static int adp8860_read(struct i2c_client *client, int reg, uint8_t *val)
{
	int ret;

	ret = i2c_smbus_read_byte_data(client, reg);
	if (ret < 0) {
		dev_err(&client->dev, "failed reading at 0x%02x\n", reg);
		return ret;
	}

	*val = (uint8_t)ret;
	return 0;
}

static int adp8860_write(struct i2c_client *client, u8 reg, u8 val)
{
	return i2c_smbus_write_byte_data(client, reg, val);
}

static int adp8860_set_bits(struct i2c_client *client, int reg, uint8_t bit_mask)
{
	struct adp8860_bl *data = i2c_get_clientdata(client);
	uint8_t reg_val;
	int ret;

	mutex_lock(&data->lock);

	ret = adp8860_read(client, reg, &reg_val);

	if (!ret && ((reg_val & bit_mask) != bit_mask)) {
		reg_val |= bit_mask;
		ret = adp8860_write(client, reg, reg_val);
	}

	mutex_unlock(&data->lock);
	return ret;
}

static int adp8860_clr_bits(struct i2c_client *client, int reg, uint8_t bit_mask)
{
	struct adp8860_bl *data = i2c_get_clientdata(client);
	uint8_t reg_val;
	int ret;

	mutex_lock(&data->lock);

	ret = adp8860_read(client, reg, &reg_val);

	if (!ret && (reg_val & bit_mask)) {
		reg_val &= ~bit_mask;
		ret = adp8860_write(client, reg, reg_val);
	}

	mutex_unlock(&data->lock);
	return ret;
}

/*
 * Independent sink / LED
 */
#if defined(ADP8860_USE_LEDS)
static void adp8860_led_work(struct work_struct *work)
{
	struct adp8860_led *led = container_of(work, struct adp8860_led, work);

	adp8860_write(led->client, ADP8860_ISC1 - led->id + 1,
			 led->new_brightness >> 1);

Annotation

Implementation Notes