drivers/leds/leds-upboard.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-upboard.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-upboard.c- Extension
.c- Size
- 3361 bytes
- Lines
- 127
- 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/device.hlinux/container_of.hlinux/leds.hlinux/mfd/upboard-fpga.hlinux/module.hlinux/platform_device.hlinux/regmap.h
Detected Declarations
struct upboard_ledstruct upboard_led_profilefunction upboard_led_brightness_getfunction upboard_led_brightness_setfunction upboard_led_probe
Annotated Snippet
struct upboard_led {
struct regmap_field *field;
struct led_classdev cdev;
};
struct upboard_led_profile {
const char *name;
unsigned int bit;
};
static struct upboard_led_profile upboard_up_led_profile[] = {
{ "upboard:yellow:" LED_FUNCTION_STATUS, 0 },
{ "upboard:green:" LED_FUNCTION_STATUS, 1 },
{ "upboard:red:" LED_FUNCTION_STATUS, 2 },
};
static struct upboard_led_profile upboard_up2_led_profile[] = {
{ "upboard:blue:" LED_FUNCTION_STATUS, 0 },
{ "upboard:yellow:" LED_FUNCTION_STATUS, 1 },
{ "upboard:green:" LED_FUNCTION_STATUS, 2 },
{ "upboard:red:" LED_FUNCTION_STATUS, 3 },
};
static enum led_brightness upboard_led_brightness_get(struct led_classdev *cdev)
{
struct upboard_led *led = led_cdev_to_led_upboard(cdev);
int brightness, ret;
ret = regmap_field_read(led->field, &brightness);
return ret ? LED_OFF : brightness;
};
static int upboard_led_brightness_set(struct led_classdev *cdev, enum led_brightness brightness)
{
struct upboard_led *led = led_cdev_to_led_upboard(cdev);
return regmap_field_write(led->field, brightness != LED_OFF);
};
static int upboard_led_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct upboard_fpga *fpga = dev_get_drvdata(dev->parent);
struct upboard_led_profile *led_profile;
struct upboard_led *led;
int led_instances, ret, i;
switch (fpga->fpga_data->type) {
case UPBOARD_UP_FPGA:
led_profile = upboard_up_led_profile;
led_instances = ARRAY_SIZE(upboard_up_led_profile);
break;
case UPBOARD_UP2_FPGA:
led_profile = upboard_up2_led_profile;
led_instances = ARRAY_SIZE(upboard_up2_led_profile);
break;
default:
return dev_err_probe(dev, -EINVAL, "Unknown device type %d\n",
fpga->fpga_data->type);
}
for (i = 0; i < led_instances; i++) {
const struct reg_field fldconf = {
.reg = UPBOARD_REG_FUNC_EN0,
.lsb = led_profile[i].bit,
.msb = led_profile[i].bit,
};
led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
if (!led)
return -ENOMEM;
led->field = devm_regmap_field_alloc(&pdev->dev, fpga->regmap, fldconf);
if (IS_ERR(led->field))
return PTR_ERR(led->field);
led->cdev.brightness_get = upboard_led_brightness_get;
led->cdev.brightness_set_blocking = upboard_led_brightness_set;
led->cdev.max_brightness = LED_ON;
led->cdev.name = led_profile[i].name;
ret = devm_led_classdev_register(dev, &led->cdev);
if (ret)
return ret;
}
return 0;
}
Annotation
- Immediate include surface: `linux/device.h`, `linux/container_of.h`, `linux/leds.h`, `linux/mfd/upboard-fpga.h`, `linux/module.h`, `linux/platform_device.h`, `linux/regmap.h`.
- Detected declarations: `struct upboard_led`, `struct upboard_led_profile`, `function upboard_led_brightness_get`, `function upboard_led_brightness_set`, `function upboard_led_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.