drivers/leds/leds-pca9532.c

Source file repositories/reference/linux-study-clean/drivers/leds/leds-pca9532.c

File Facts

System
Linux kernel
Corpus path
drivers/leds/leds-pca9532.c
Extension
.c
Size
15780 bytes
Lines
603
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 pca9532_chip_info {
	u8	num_leds;
};

struct pca9532_data {
	struct i2c_client *client;
	struct pca9532_led leds[16];
	struct mutex update_lock;
	struct input_dev *idev;
	struct work_struct work;
#ifdef CONFIG_LEDS_PCA9532_GPIO
	struct gpio_chip gpio;
#endif
	const struct pca9532_chip_info *chip_info;

#define PCA9532_PWM_ID_0	0
#define PCA9532_PWM_ID_1	1
	u8 pwm[2];
	u8 psc[2];
	bool hw_blink;
};

static int pca9532_probe(struct i2c_client *client);
static void pca9532_remove(struct i2c_client *client);

enum {
	pca9530,
	pca9531,
	pca9532,
	pca9533,
};

static const struct i2c_device_id pca9532_id[] = {
	{ .name = "pca9530", .driver_data = pca9530 },
	{ .name = "pca9531", .driver_data = pca9531 },
	{ .name = "pca9532", .driver_data = pca9532 },
	{ .name = "pca9533", .driver_data = pca9533 },
	{ }
};

MODULE_DEVICE_TABLE(i2c, pca9532_id);

static const struct pca9532_chip_info pca9532_chip_info_tbl[] = {
	[pca9530] = {
		.num_leds = 2,
	},
	[pca9531] = {
		.num_leds = 8,
	},
	[pca9532] = {
		.num_leds = 16,
	},
	[pca9533] = {
		.num_leds = 4,
	},
};

#ifdef CONFIG_OF
static const struct of_device_id of_pca9532_leds_match[] = {
	{ .compatible = "nxp,pca9530", .data = (void *)pca9530 },
	{ .compatible = "nxp,pca9531", .data = (void *)pca9531 },
	{ .compatible = "nxp,pca9532", .data = (void *)pca9532 },
	{ .compatible = "nxp,pca9533", .data = (void *)pca9533 },
	{},
};

MODULE_DEVICE_TABLE(of, of_pca9532_leds_match);
#endif

static struct i2c_driver pca9532_driver = {
	.driver = {
		.name = "leds-pca953x",
		.of_match_table = of_match_ptr(of_pca9532_leds_match),
	},
	.probe = pca9532_probe,
	.remove = pca9532_remove,
	.id_table = pca9532_id,
};

/* We have two pwm/blinkers, but 16 possible leds to drive. Additionally,
 * the clever Thecus people are using one pwm to drive the beeper. So,
 * as a compromise we average one pwm to the values requested by all
 * leds that are not ON/OFF.
 * */
static int pca9532_calcpwm(struct i2c_client *client, int pwm, int blink,
	enum led_brightness value)
{
	int a = 0, b = 0, i = 0;
	struct pca9532_data *data = i2c_get_clientdata(client);
	for (i = 0; i < data->chip_info->num_leds; i++) {

Annotation

Implementation Notes