drivers/leds/leds-pm8058.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-pm8058.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-pm8058.c- Extension
.c- Size
- 4308 bytes
- Lines
- 183
- 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/leds.hlinux/module.hlinux/of.hlinux/platform_device.hlinux/pm.hlinux/regmap.h
Detected Declarations
struct pm8058_ledfunction pm8058_led_setfunction pm8058_led_getfunction pm8058_led_probe
Annotated Snippet
struct pm8058_led {
struct regmap *map;
u32 reg;
u32 ledtype;
struct led_classdev cdev;
};
static void pm8058_led_set(struct led_classdev *cled,
enum led_brightness value)
{
struct pm8058_led *led;
int ret = 0;
unsigned int mask = 0;
unsigned int val = 0;
led = container_of(cled, struct pm8058_led, cdev);
switch (led->ledtype) {
case PM8058_LED_TYPE_COMMON:
mask = PM8058_LED_TYPE_COMMON_MASK;
val = value << PM8058_LED_TYPE_COMMON_SHIFT;
break;
case PM8058_LED_TYPE_KEYPAD:
case PM8058_LED_TYPE_FLASH:
mask = PM8058_LED_TYPE_KEYPAD_MASK;
val = value << PM8058_LED_TYPE_KEYPAD_SHIFT;
break;
default:
break;
}
ret = regmap_update_bits(led->map, led->reg, mask, val);
if (ret)
pr_err("Failed to set LED brightness\n");
}
static enum led_brightness pm8058_led_get(struct led_classdev *cled)
{
struct pm8058_led *led;
int ret;
unsigned int val;
led = container_of(cled, struct pm8058_led, cdev);
ret = regmap_read(led->map, led->reg, &val);
if (ret) {
pr_err("Failed to get LED brightness\n");
return LED_OFF;
}
switch (led->ledtype) {
case PM8058_LED_TYPE_COMMON:
val &= PM8058_LED_TYPE_COMMON_MASK;
val >>= PM8058_LED_TYPE_COMMON_SHIFT;
break;
case PM8058_LED_TYPE_KEYPAD:
case PM8058_LED_TYPE_FLASH:
val &= PM8058_LED_TYPE_KEYPAD_MASK;
val >>= PM8058_LED_TYPE_KEYPAD_SHIFT;
break;
default:
val = LED_OFF;
break;
}
return val;
}
static int pm8058_led_probe(struct platform_device *pdev)
{
struct led_init_data init_data = {};
struct device *dev = &pdev->dev;
struct pm8058_led *led;
struct device_node *np;
int ret;
struct regmap *map;
enum led_brightness maxbright;
enum led_default_state state;
led = devm_kzalloc(dev, sizeof(*led), GFP_KERNEL);
if (!led)
return -ENOMEM;
led->ledtype = (u32)(unsigned long)of_device_get_match_data(dev);
map = dev_get_regmap(dev->parent, NULL);
if (!map) {
dev_err(dev, "Parent regmap unavailable.\n");
return -ENXIO;
}
led->map = map;
Annotation
- Immediate include surface: `linux/leds.h`, `linux/module.h`, `linux/of.h`, `linux/platform_device.h`, `linux/pm.h`, `linux/regmap.h`.
- Detected declarations: `struct pm8058_led`, `function pm8058_led_set`, `function pm8058_led_get`, `function pm8058_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.