drivers/mfd/tps65219.c

Source file repositories/reference/linux-study-clean/drivers/mfd/tps65219.c

File Facts

System
Linux kernel
Corpus path
drivers/mfd/tps65219.c
Extension
.c
Size
27417 bytes
Lines
576
Domain
Driver Families
Bucket
drivers/mfd
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 tps65219_chip_data {
	const struct regmap_irq_chip *irq_chip;
	const struct mfd_cell *cells;
	int n_cells;
};

static const struct tps65219_chip_data chip_info_table[] = {
	[TPS65214] = {
		.irq_chip = &tps65214_irq_chip,
		.cells = tps65214_cells,
		.n_cells = ARRAY_SIZE(tps65214_cells),
	},
	[TPS65215] = {
		.irq_chip = &tps65215_irq_chip,
		.cells = tps65215_cells,
		.n_cells = ARRAY_SIZE(tps65215_cells),
	},
	[TPS65219] = {
		.irq_chip = &tps65219_irq_chip,
		.cells = tps65219_cells,
		.n_cells = ARRAY_SIZE(tps65219_cells),
	},
};

static int tps65219_probe(struct i2c_client *client)
{
	struct tps65219 *tps;
	const struct tps65219_chip_data *pmic;
	unsigned int chip_id;
	bool pwr_button;
	int ret;

	tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
	if (!tps)
		return -ENOMEM;

	i2c_set_clientdata(client, tps);

	tps->dev = &client->dev;
	chip_id = (uintptr_t)i2c_get_match_data(client);
	pmic = &chip_info_table[chip_id];

	tps->regmap = devm_regmap_init_i2c(client, &tps65219_regmap_config);
	if (IS_ERR(tps->regmap)) {
		ret = PTR_ERR(tps->regmap);
		dev_err(tps->dev, "Failed to allocate register map: %d\n", ret);
		return ret;
	}

	if (chip_id == TPS65214) {
		ret = i2c_smbus_write_byte_data(client, TPS65214_REG_LOCK,
						TPS65214_LOCK_ACCESS_CMD);
		if (ret) {
			dev_err(tps->dev, "Failed to unlock registers %d\n", ret);
			return ret;
		}
	}

	ret = devm_regmap_add_irq_chip(tps->dev, tps->regmap, client->irq,
				       IRQF_ONESHOT, 0, pmic->irq_chip,
				       &tps->irq_data);
	if (ret)
		return ret;

	ret = devm_mfd_add_devices(tps->dev, PLATFORM_DEVID_AUTO,
				   pmic->cells, pmic->n_cells,
				   NULL, 0, regmap_irq_get_domain(tps->irq_data));
	if (ret) {
		dev_err(tps->dev, "Failed to add child devices: %d\n", ret);
		return ret;
	}

	pwr_button = of_property_read_bool(tps->dev->of_node, "ti,power-button");
	if (pwr_button) {
		ret = devm_mfd_add_devices(tps->dev, PLATFORM_DEVID_AUTO,
					   &tps65219_pwrbutton_cell, 1, NULL, 0,
					   regmap_irq_get_domain(tps->irq_data));
		if (ret) {
			dev_err(tps->dev, "Failed to add power-button: %d\n", ret);
			return ret;
		}
	}

	ret = devm_register_restart_handler(tps->dev,
					    tps65219_restart_handler,
					    tps);

	if (ret) {
		dev_err(tps->dev, "cannot register restart handler, %d\n", ret);
		return ret;

Annotation

Implementation Notes