drivers/leds/leds-aw200xx.c

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

File Facts

System
Linux kernel
Corpus path
drivers/leds/leds-aw200xx.c
Extension
.c
Size
17496 bytes
Lines
670
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 aw200xx_chipdef {
	u32 channels;
	u32 display_size_rows_max;
	u32 display_size_columns;
};

struct aw200xx_led {
	struct led_classdev cdev;
	struct aw200xx *chip;
	int dim;
	u32 num;
};

struct aw200xx {
	const struct aw200xx_chipdef *cdef;
	struct i2c_client *client;
	struct regmap *regmap;
	struct mutex mutex;
	u32 num_leds;
	u32 display_rows;
	struct gpio_desc *hwen;
	struct aw200xx_led leds[] __counted_by(num_leds);
};

static ssize_t dim_show(struct device *dev, struct device_attribute *devattr,
			char *buf)
{
	struct led_classdev *cdev = dev_get_drvdata(dev);
	struct aw200xx_led *led = container_of(cdev, struct aw200xx_led, cdev);
	int dim = led->dim;

	if (dim < 0)
		return sysfs_emit(buf, "auto\n");

	return sysfs_emit(buf, "%d\n", dim);
}

static ssize_t dim_store(struct device *dev, struct device_attribute *devattr,
			 const char *buf, size_t count)
{
	struct led_classdev *cdev = dev_get_drvdata(dev);
	struct aw200xx_led *led = container_of(cdev, struct aw200xx_led, cdev);
	struct aw200xx *chip = led->chip;
	u32 columns = chip->cdef->display_size_columns;
	int dim;
	ssize_t ret;

	if (sysfs_streq(buf, "auto")) {
		dim = -1;
	} else {
		ret = kstrtoint(buf, 0, &dim);
		if (ret)
			return ret;

		if (dim > AW200XX_DIM_MAX)
			return -EINVAL;
	}

	mutex_lock(&chip->mutex);

	if (dim >= 0) {
		ret = regmap_write(chip->regmap,
				   AW200XX_REG_DIM_PAGE1(led->num, columns),
				   dim);
		if (ret)
			goto out_unlock;
	}

	led->dim = dim;
	ret = count;

out_unlock:
	mutex_unlock(&chip->mutex);
	return ret;
}
static DEVICE_ATTR_RW(dim);

static struct attribute *dim_attrs[] = {
	&dev_attr_dim.attr,
	NULL
};
ATTRIBUTE_GROUPS(dim);

static int aw200xx_brightness_set(struct led_classdev *cdev,
				  enum led_brightness brightness)
{
	struct aw200xx_led *led = container_of(cdev, struct aw200xx_led, cdev);
	struct aw200xx *chip = led->chip;
	int dim;
	u32 reg;

Annotation

Implementation Notes