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.
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitops.hlinux/device.hlinux/err.hlinux/leds.hlinux/leds-ti-lmu-common.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/property.hlinux/mfd/ti-lmu.hlinux/mfd/ti-lmu-register.huapi/linux/uleds.h
Detected Declarations
struct lm36274function lm36274_brightness_setfunction lm36274_initfunction lm36274_parse_dtfunction lm36274_probe
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
- Immediate include surface: `linux/bitops.h`, `linux/device.h`, `linux/err.h`, `linux/leds.h`, `linux/leds-ti-lmu-common.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_device.h`.
- Detected declarations: `struct lm36274`, `function lm36274_brightness_set`, `function lm36274_init`, `function lm36274_parse_dt`, `function lm36274_probe`.
- 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.