drivers/leds/leds-lm36274.c

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

File Facts

System
Linux kernel
Corpus path
drivers/leds/leds-lm36274.c
Extension
.c
Size
4311 bytes
Lines
173
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 lm36274 {
	struct platform_device *pdev;
	struct led_classdev led_dev;
	struct ti_lmu_bank lmu_data;
	struct regmap *regmap;
	struct device *dev;

	u32 led_sources[LM36274_MAX_STRINGS];
	int num_leds;
};

static int lm36274_brightness_set(struct led_classdev *led_cdev,
				  enum led_brightness brt_val)
{
	struct lm36274 *chip = container_of(led_cdev, struct lm36274, led_dev);

	return ti_lmu_common_set_brightness(&chip->lmu_data, brt_val);
}

static int lm36274_init(struct lm36274 *chip)
{
	int enable_val = 0;
	int i;

	for (i = 0; i < chip->num_leds; i++)
		enable_val |= (1 << chip->led_sources[i]);

	if (!enable_val) {
		dev_err(chip->dev, "No LEDs were enabled\n");
		return -EINVAL;
	}

	enable_val |= LM36274_BL_EN;

	return regmap_write(chip->regmap, LM36274_REG_BL_EN, enable_val);
}

static int lm36274_parse_dt(struct lm36274 *chip,
			    struct led_init_data *init_data)
{
	struct device *dev = chip->dev;
	struct fwnode_handle *child;
	int ret;

	/* There should only be 1 node */
	if (device_get_child_node_count(dev) != 1)
		return -EINVAL;

	child = device_get_next_child_node(dev, NULL);

	init_data->fwnode = child;
	init_data->devicename = chip->pdev->name;
	/* for backwards compatibility when `label` property is not present */
	init_data->default_label = ":";

	chip->num_leds = fwnode_property_count_u32(child, "led-sources");
	if (chip->num_leds <= 0) {
		ret = -ENODEV;
		goto err;
	}

	ret = fwnode_property_read_u32_array(child, "led-sources",
					     chip->led_sources, chip->num_leds);
	if (ret) {
		dev_err(dev, "led-sources property missing\n");
		goto err;
	}

	return 0;
err:
	fwnode_handle_put(child);
	return ret;
}

static int lm36274_probe(struct platform_device *pdev)
{
	struct ti_lmu *lmu = dev_get_drvdata(pdev->dev.parent);
	struct led_init_data init_data = {};
	struct lm36274 *chip;
	int ret;

	chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
	if (!chip)
		return -ENOMEM;

	chip->pdev = pdev;
	chip->dev = &pdev->dev;
	chip->regmap = lmu->regmap;
	platform_set_drvdata(pdev, chip);

Annotation

Implementation Notes