drivers/leds/leds-max77650.c

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

File Facts

System
Linux kernel
Corpus path
drivers/leds/leds-max77650.c
Extension
.c
Size
3564 bytes
Lines
143
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 max77650_led {
	struct led_classdev cdev;
	struct regmap *map;
	unsigned int regA;
	unsigned int regB;
};

static struct max77650_led *max77650_to_led(struct led_classdev *cdev)
{
	return container_of(cdev, struct max77650_led, cdev);
}

static int max77650_led_brightness_set(struct led_classdev *cdev,
				       enum led_brightness brightness)
{
	struct max77650_led *led = max77650_to_led(cdev);
	int val, mask;

	mask = MAX77650_LED_BR_MASK | MAX77650_LED_EN_MASK;

	if (brightness == LED_OFF)
		val = MAX77650_LED_DISABLE;
	else
		val = MAX77650_LED_ENABLE | brightness;

	return regmap_update_bits(led->map, led->regA, mask, val);
}

static int max77650_led_probe(struct platform_device *pdev)
{
	struct max77650_led *leds, *led;
	struct device *dev;
	struct regmap *map;
	int rv, num_leds;
	u32 reg;

	dev = &pdev->dev;

	leds = devm_kcalloc(dev, sizeof(*leds),
			    MAX77650_LED_NUM_LEDS, GFP_KERNEL);
	if (!leds)
		return -ENOMEM;

	map = dev_get_regmap(dev->parent, NULL);
	if (!map)
		return -ENODEV;

	num_leds = device_get_child_node_count(dev);
	if (!num_leds || num_leds > MAX77650_LED_NUM_LEDS)
		return -ENODEV;

	device_for_each_child_node_scoped(dev, child) {
		struct led_init_data init_data = {};

		rv = fwnode_property_read_u32(child, "reg", &reg);
		if (rv || reg >= MAX77650_LED_NUM_LEDS)
			return -EINVAL;

		led = &leds[reg];
		led->map = map;
		led->regA = MAX77650_LED_A_BASE + reg;
		led->regB = MAX77650_LED_B_BASE + reg;
		led->cdev.brightness_set_blocking = max77650_led_brightness_set;
		led->cdev.max_brightness = MAX77650_LED_MAX_BRIGHTNESS;

		init_data.fwnode = child;
		init_data.devicename = "max77650";
		/* for backwards compatibility if `label` is not present */
		init_data.default_label = ":";

		rv = devm_led_classdev_register_ext(dev, &led->cdev,
						    &init_data);
		if (rv)
			return rv;

		rv = regmap_write(map, led->regA, MAX77650_LED_A_DEFAULT);
		if (rv)
			return rv;

		rv = regmap_write(map, led->regB, MAX77650_LED_B_DEFAULT);
		if (rv)
			return rv;
	}

	return regmap_write(map,
			    MAX77650_REG_CNFG_LED_TOP,
			    MAX77650_LED_TOP_DEFAULT);
}

static const struct of_device_id max77650_led_of_match[] = {

Annotation

Implementation Notes