drivers/leds/leds-menf21bmc.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-menf21bmc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-menf21bmc.c- Extension
.c- Size
- 2588 bytes
- Lines
- 111
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/kernel.hlinux/platform_device.hlinux/leds.hlinux/i2c.h
Detected Declarations
struct menf21bmc_ledfunction menf21bmc_led_setfunction menf21bmc_led_probe
Annotated Snippet
struct menf21bmc_led {
struct led_classdev cdev;
u8 led_bit;
const char *name;
struct i2c_client *i2c_client;
};
static struct menf21bmc_led leds[] = {
{
.name = "menf21bmc:led_status",
.led_bit = BMC_BIT_LED_STATUS,
},
{
.name = "menf21bmc:led_hotswap",
.led_bit = BMC_BIT_LED_HOTSWAP,
},
{
.name = "menf21bmc:led_user1",
.led_bit = BMC_BIT_LED_USER1,
},
{
.name = "menf21bmc:led_user2",
.led_bit = BMC_BIT_LED_USER2,
}
};
static DEFINE_MUTEX(led_lock);
static void
menf21bmc_led_set(struct led_classdev *led_cdev, enum led_brightness value)
{
int led_val;
struct menf21bmc_led *led = container_of(led_cdev,
struct menf21bmc_led, cdev);
mutex_lock(&led_lock);
led_val = i2c_smbus_read_byte_data(led->i2c_client,
BMC_CMD_LED_GET_SET);
if (led_val < 0)
goto err_out;
if (value == LED_OFF)
led_val &= ~led->led_bit;
else
led_val |= led->led_bit;
i2c_smbus_write_byte_data(led->i2c_client,
BMC_CMD_LED_GET_SET, led_val);
err_out:
mutex_unlock(&led_lock);
}
static int menf21bmc_led_probe(struct platform_device *pdev)
{
int i;
int ret;
struct i2c_client *i2c_client = to_i2c_client(pdev->dev.parent);
for (i = 0; i < ARRAY_SIZE(leds); i++) {
leds[i].cdev.name = leds[i].name;
leds[i].cdev.brightness_set = menf21bmc_led_set;
leds[i].i2c_client = i2c_client;
ret = devm_led_classdev_register(&pdev->dev, &leds[i].cdev);
if (ret < 0) {
dev_err(&pdev->dev, "failed to register LED device\n");
return ret;
}
}
dev_info(&pdev->dev, "MEN 140F21P00 BMC LED device enabled\n");
return 0;
}
static struct platform_driver menf21bmc_led = {
.probe = menf21bmc_led_probe,
.driver = {
.name = "menf21bmc_led",
},
};
module_platform_driver(menf21bmc_led);
MODULE_AUTHOR("Andreas Werner <andreas.werner@men.de>");
MODULE_DESCRIPTION("MEN 14F021P00 BMC led driver");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:menf21bmc_led");
Annotation
- Immediate include surface: `linux/module.h`, `linux/kernel.h`, `linux/platform_device.h`, `linux/leds.h`, `linux/i2c.h`.
- Detected declarations: `struct menf21bmc_led`, `function menf21bmc_led_set`, `function menf21bmc_led_probe`.
- Atlas domain: Driver Families / drivers/leds.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.