drivers/leds/leds-cht-wcove.c
Source file repositories/reference/linux-study-clean/drivers/leds/leds-cht-wcove.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/leds-cht-wcove.c- Extension
.c- Size
- 12974 bytes
- Lines
- 473
- 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.
- 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/kernel.hlinux/leds.hlinux/mfd/intel_soc_pmic.hlinux/module.hlinux/mod_devicetable.hlinux/platform_device.hlinux/regmap.hlinux/suspend.h
Detected Declarations
struct cht_wc_led_regsstruct cht_wc_led_saved_regsstruct cht_wc_ledstruct cht_wc_ledsfunction cht_wc_leds_brightness_setfunction cht_wc_leds_brightness_getfunction cht_wc_leds_get_periodfunction cht_wc_leds_find_freqfunction cht_wc_leds_set_effectfunction cht_wc_leds_blink_setfunction cht_wc_leds_pattern_setfunction cht_wc_leds_pattern_clearfunction cht_wc_led_save_regsfunction cht_wc_led_restore_regsfunction cht_wc_leds_probefunction cht_wc_leds_removefunction cht_wc_leds_disablefunction cht_wc_leds_suspendfunction cht_wc_leds_resume
Annotated Snippet
struct cht_wc_led_regs {
/* Register addresses */
u16 ctrl;
u16 fsm;
u16 pwm;
/* Mask + values for turning the LED on/off */
u8 on_off_mask;
u8 on_val;
u8 off_val;
};
struct cht_wc_led_saved_regs {
unsigned int ctrl;
unsigned int fsm;
unsigned int pwm;
};
struct cht_wc_led {
struct led_classdev cdev;
const struct cht_wc_led_regs *regs;
struct regmap *regmap;
struct mutex mutex;
struct cht_wc_led_saved_regs saved_regs;
};
struct cht_wc_leds {
struct cht_wc_led leds[CHT_WC_LED_COUNT];
/* Saved LED1 initial register values */
struct cht_wc_led_saved_regs led1_initial_regs;
};
static const struct cht_wc_led_regs cht_wc_led_regs[CHT_WC_LED_COUNT] = {
{
.ctrl = CHT_WC_LED1_CTRL,
.fsm = CHT_WC_LED1_FSM,
.pwm = CHT_WC_LED1_PWM,
.on_off_mask = CHT_WC_LED1_SWCTL | CHT_WC_LED1_ON,
.on_val = CHT_WC_LED1_SWCTL | CHT_WC_LED1_ON,
.off_val = CHT_WC_LED1_SWCTL,
},
{
.ctrl = CHT_WC_LED2_CTRL,
.fsm = CHT_WC_LED2_FSM,
.pwm = CHT_WC_LED2_PWM,
.on_off_mask = CHT_WC_LED2_ON,
.on_val = CHT_WC_LED2_ON,
.off_val = 0,
},
};
static const char * const cht_wc_leds_names[CHT_WC_LED_COUNT] = {
"platform::" LED_FUNCTION_CHARGING,
"platform::" LED_FUNCTION_INDICATOR,
};
static int cht_wc_leds_brightness_set(struct led_classdev *cdev,
enum led_brightness value)
{
struct cht_wc_led *led = container_of(cdev, struct cht_wc_led, cdev);
int ret;
mutex_lock(&led->mutex);
if (!value) {
ret = regmap_update_bits(led->regmap, led->regs->ctrl,
led->regs->on_off_mask, led->regs->off_val);
if (ret < 0) {
dev_err(cdev->dev, "Failed to turn off: %d\n", ret);
goto out;
}
/* Disable HW blinking */
ret = regmap_update_bits(led->regmap, led->regs->fsm,
CHT_WC_LED_EFF_MASK, CHT_WC_LED_EFF_ON);
if (ret < 0)
dev_err(cdev->dev, "Failed to update LED FSM reg: %d\n", ret);
} else {
ret = regmap_write(led->regmap, led->regs->pwm, value);
if (ret < 0) {
dev_err(cdev->dev, "Failed to set brightness: %d\n", ret);
goto out;
}
ret = regmap_update_bits(led->regmap, led->regs->ctrl,
led->regs->on_off_mask, led->regs->on_val);
if (ret < 0)
dev_err(cdev->dev, "Failed to turn on: %d\n", ret);
}
out:
mutex_unlock(&led->mutex);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/leds.h`, `linux/mfd/intel_soc_pmic.h`, `linux/module.h`, `linux/mod_devicetable.h`, `linux/platform_device.h`, `linux/regmap.h`, `linux/suspend.h`.
- Detected declarations: `struct cht_wc_led_regs`, `struct cht_wc_led_saved_regs`, `struct cht_wc_led`, `struct cht_wc_leds`, `function cht_wc_leds_brightness_set`, `function cht_wc_leds_brightness_get`, `function cht_wc_leds_get_period`, `function cht_wc_leds_find_freq`, `function cht_wc_leds_set_effect`, `function cht_wc_leds_blink_set`.
- 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.