drivers/leds/leds-lp55xx-common.c

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

File Facts

System
Linux kernel
Corpus path
drivers/leds/leds-lp55xx-common.c
Extension
.c
Size
33899 bytes
Lines
1349
Domain
Driver Families
Bucket
drivers/leds
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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

scoped_guard(mutex, &chip->lock) {
			chip->engine_idx = val;
			ret = lp55xx_request_firmware(chip);
		}
		break;
	default:
		dev_err(dev, "%lu: invalid engine index. (1, 2, 3)\n", val);
		return -EINVAL;
	}

	if (ret) {
		dev_err(dev, "request firmware err: %d\n", ret);
		return ret;
	}

	return len;
}

static inline void lp55xx_run_engine(struct lp55xx_chip *chip, bool start)
{
	if (chip->cfg->run_engine)
		chip->cfg->run_engine(chip, start);
}

static ssize_t run_engine_store(struct device *dev,
				struct device_attribute *attr,
				const char *buf, size_t len)
{
	struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
	struct lp55xx_chip *chip = led->chip;
	unsigned long val;

	if (kstrtoul(buf, 0, &val))
		return -EINVAL;

	/* run or stop the selected engine */

	if (val <= 0) {
		lp55xx_run_engine(chip, false);
		return len;
	}

	guard(mutex)(&chip->lock);

	lp55xx_run_engine(chip, true);

	return len;
}

static DEVICE_ATTR_RW(select_engine);
static DEVICE_ATTR_WO(run_engine);

ssize_t lp55xx_show_engine_mode(struct device *dev,
				struct device_attribute *attr,
				char *buf, int nr)
{
	struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
	struct lp55xx_chip *chip = led->chip;
	enum lp55xx_engine_mode mode = chip->engines[nr - 1].mode;

	switch (mode) {
	case LP55XX_ENGINE_RUN:
		return sysfs_emit(buf, "run\n");
	case LP55XX_ENGINE_LOAD:
		return sysfs_emit(buf, "load\n");
	case LP55XX_ENGINE_DISABLED:
	default:
		return sysfs_emit(buf, "disabled\n");
	}
}
EXPORT_SYMBOL_GPL(lp55xx_show_engine_mode);

ssize_t lp55xx_store_engine_mode(struct device *dev,
				 struct device_attribute *attr,
				 const char *buf, size_t len, int nr)
{
	struct lp55xx_led *led = i2c_get_clientdata(to_i2c_client(dev));
	struct lp55xx_chip *chip = led->chip;
	const struct lp55xx_device_config *cfg = chip->cfg;
	struct lp55xx_engine *engine = &chip->engines[nr - 1];

	guard(mutex)(&chip->lock);

	chip->engine_idx = nr;

	if (!strncmp(buf, "run", 3)) {
		cfg->run_engine(chip, true);
		engine->mode = LP55XX_ENGINE_RUN;
	} else if (!strncmp(buf, "load", 4)) {
		lp55xx_stop_engine(chip);

Annotation

Implementation Notes