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.
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/i2c.hlinux/leds.hlinux/mfd/max77650.hlinux/module.hlinux/platform_device.hlinux/regmap.h
Detected Declarations
struct max77650_ledfunction max77650_led_brightness_setfunction max77650_led_probefunction device_for_each_child_node_scoped
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", ®);
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
- Immediate include surface: `linux/i2c.h`, `linux/leds.h`, `linux/mfd/max77650.h`, `linux/module.h`, `linux/platform_device.h`, `linux/regmap.h`.
- Detected declarations: `struct max77650_led`, `function max77650_led_brightness_set`, `function max77650_led_probe`, `function device_for_each_child_node_scoped`.
- Atlas domain: Driver Families / drivers/leds.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.