drivers/leds/rgb/leds-mt6370-rgb.c
Source file repositories/reference/linux-study-clean/drivers/leds/rgb/leds-mt6370-rgb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/leds/rgb/leds-mt6370-rgb.c- Extension
.c- Size
- 25698 bytes
- Lines
- 996
- 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/bitfield.hlinux/bitops.hlinux/kernel.hlinux/leds.hlinux/led-class-multicolor.hlinux/linear_range.hlinux/mod_devicetable.hlinux/module.hlinux/mutex.hlinux/platform_device.hlinux/property.hlinux/regmap.hlinux/util_macros.hlinux/unaligned.h
Detected Declarations
struct mt6370_ledstruct mt6370_pdatastruct mt6370_privenum mt6370_led_modeenum mt6370_led_fieldenum mt6370_led_rangesenum mt6370_patternfunction mt6370_get_led_current_fieldfunction mt6370_set_led_brightnessfunction mt6370_get_led_brightnessfunction mt6370_set_led_dutyfunction mt6370_set_led_freqfunction mt6370_get_breath_reg_basefunction mt6370_gen_breath_patternfunction mt6370_set_led_modefunction mt6370_mc_brightness_setfunction mt6370_mc_blink_setfunction mt6370_mc_pattern_setfunction mt6370_mc_pattern_clearfunction mt6370_isnk_brightness_setfunction mt6370_isnk_blink_setfunction mt6370_isnk_pattern_setfunction mt6370_isnk_pattern_clearfunction mt6370_assign_multicolor_infofunction fwnode_for_each_child_nodefunction mt6370_init_led_propertiesfunction mt6370_isnk_init_default_statefunction mt6370_multicolor_led_registerfunction mt6370_led_registerfunction mt6370_check_vendor_infofunction mt6370_leds_probefunction device_for_each_child_node_scoped
Annotated Snippet
struct mt6370_led {
/*
* If the color of the LED in DT is set to
* - 'LED_COLOR_ID_RGB'
* - 'LED_COLOR_ID_MULTI'
* The member 'index' of this struct will be set to
* 'MT6370_VIRTUAL_MULTICOLOR'.
* If so, this LED will choose 'struct led_classdev_mc mc' to use.
* Instead, if the member 'index' of this struct is set to
* 'MT6370_LED_ISNK1' ~ 'MT6370_LED_ISNK4', then this LED will choose
* 'struct led_classdev isink' to use.
*/
union {
struct led_classdev isink;
struct led_classdev_mc mc;
};
struct mt6370_priv *priv;
enum led_default_state default_state;
u32 index;
};
struct mt6370_pdata {
const unsigned int *tfreq;
unsigned int tfreq_len;
u16 reg_rgb1_tr;
s16 reg_rgb_chrind_tr;
u8 pwm_duty;
};
struct mt6370_priv {
/* Per LED access lock */
struct mutex lock;
struct regmap *regmap;
struct regmap_field *fields[F_MAX_FIELDS];
const struct reg_field *reg_fields;
const struct linear_range *ranges;
const struct mt6370_pdata *pdata;
unsigned int leds_count;
unsigned int leds_active;
struct mt6370_led leds[] __counted_by(leds_count);
};
static const struct reg_field common_reg_fields[F_MAX_FIELDS] = {
[F_RGB_EN] = REG_FIELD(MT6370_REG_RGB_EN, 4, 7),
[F_CHGIND_EN] = REG_FIELD(MT6370_REG_RGB_CHRIND_DIM, 7, 7),
[F_LED1_CURR] = REG_FIELD(MT6370_REG_RGB1_ISNK, 0, 2),
[F_LED2_CURR] = REG_FIELD(MT6370_REG_RGB2_ISNK, 0, 2),
[F_LED3_CURR] = REG_FIELD(MT6370_REG_RGB3_ISNK, 0, 2),
[F_LED4_CURR] = REG_FIELD(MT6370_REG_RGB_CHRIND_CTRL, 0, 1),
[F_LED1_MODE] = REG_FIELD(MT6370_REG_RGB1_DIM, 5, 6),
[F_LED2_MODE] = REG_FIELD(MT6370_REG_RGB2_DIM, 5, 6),
[F_LED3_MODE] = REG_FIELD(MT6370_REG_RGB3_DIM, 5, 6),
[F_LED4_MODE] = REG_FIELD(MT6370_REG_RGB_CHRIND_DIM, 5, 6),
[F_LED1_DUTY] = REG_FIELD(MT6370_REG_RGB1_DIM, 0, 4),
[F_LED2_DUTY] = REG_FIELD(MT6370_REG_RGB2_DIM, 0, 4),
[F_LED3_DUTY] = REG_FIELD(MT6370_REG_RGB3_DIM, 0, 4),
[F_LED4_DUTY] = REG_FIELD(MT6370_REG_RGB_CHRIND_DIM, 0, 4),
[F_LED1_FREQ] = REG_FIELD(MT6370_REG_RGB1_ISNK, 3, 5),
[F_LED2_FREQ] = REG_FIELD(MT6370_REG_RGB2_ISNK, 3, 5),
[F_LED3_FREQ] = REG_FIELD(MT6370_REG_RGB3_ISNK, 3, 5),
[F_LED4_FREQ] = REG_FIELD(MT6370_REG_RGB_CHRIND_CTRL, 2, 4),
};
static const struct reg_field mt6372_reg_fields[F_MAX_FIELDS] = {
[F_RGB_EN] = REG_FIELD(MT6372_REG_RGB_EN, 4, 7),
[F_CHGIND_EN] = REG_FIELD(MT6372_REG_RGB_EN, 3, 3),
[F_LED1_CURR] = REG_FIELD(MT6372_REG_RGB1_ISNK, 0, 3),
[F_LED2_CURR] = REG_FIELD(MT6372_REG_RGB2_ISNK, 0, 3),
[F_LED3_CURR] = REG_FIELD(MT6372_REG_RGB3_ISNK, 0, 3),
[F_LED4_CURR] = REG_FIELD(MT6372_REG_RGB4_ISNK, 0, 3),
[F_LED1_MODE] = REG_FIELD(MT6372_REG_RGB1_ISNK, 6, 7),
[F_LED2_MODE] = REG_FIELD(MT6372_REG_RGB2_ISNK, 6, 7),
[F_LED3_MODE] = REG_FIELD(MT6372_REG_RGB3_ISNK, 6, 7),
[F_LED4_MODE] = REG_FIELD(MT6372_REG_RGB4_ISNK, 6, 7),
[F_LED1_DUTY] = REG_FIELD(MT6372_REG_RGB1_DIM, 0, 7),
[F_LED2_DUTY] = REG_FIELD(MT6372_REG_RGB2_DIM, 0, 7),
[F_LED3_DUTY] = REG_FIELD(MT6372_REG_RGB3_DIM, 0, 7),
[F_LED4_DUTY] = REG_FIELD(MT6372_REG_RGB4_DIM, 0, 7),
[F_LED1_FREQ] = REG_FIELD(MT6372_REG_RGB12_FREQ, 5, 7),
[F_LED2_FREQ] = REG_FIELD(MT6372_REG_RGB12_FREQ, 2, 4),
[F_LED3_FREQ] = REG_FIELD(MT6372_REG_RGB34_FREQ, 5, 7),
[F_LED4_FREQ] = REG_FIELD(MT6372_REG_RGB34_FREQ, 2, 4),
};
/* Current unit: microamp, time unit: millisecond */
static const struct linear_range common_led_ranges[R_MAX_RANGES] = {
[R_LED123_CURR] = LINEAR_RANGE(4000, 1, 6, 4000),
[R_LED4_CURR] = LINEAR_RANGE(2000, 1, 3, 2000),
[R_LED_TRFON] = LINEAR_RANGE(125, 0, 15, 200),
[R_LED_TOFF] = LINEAR_RANGE(250, 0, 15, 400),
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/bitops.h`, `linux/kernel.h`, `linux/leds.h`, `linux/led-class-multicolor.h`, `linux/linear_range.h`, `linux/mod_devicetable.h`, `linux/module.h`.
- Detected declarations: `struct mt6370_led`, `struct mt6370_pdata`, `struct mt6370_priv`, `enum mt6370_led_mode`, `enum mt6370_led_field`, `enum mt6370_led_ranges`, `enum mt6370_pattern`, `function mt6370_get_led_current_field`, `function mt6370_set_led_brightness`, `function mt6370_get_led_brightness`.
- 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.