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.

Dependency Surface

Detected Declarations

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

Implementation Notes