drivers/input/misc/tps65218-pwrbutton.c

Source file repositories/reference/linux-study-clean/drivers/input/misc/tps65218-pwrbutton.c

File Facts

System
Linux kernel
Corpus path
drivers/input/misc/tps65218-pwrbutton.c
Extension
.c
Size
3868 bytes
Lines
161
Domain
Driver Families
Bucket
drivers/input
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 tps6521x_data {
	unsigned int reg_status;
	unsigned int pb_mask;
	const char *name;
};

static const struct tps6521x_data tps65217_data = {
	.reg_status = TPS65217_REG_STATUS,
	.pb_mask = TPS65217_STATUS_PB,
	.name = "tps65217_pwrbutton",
};

static const struct tps6521x_data tps65218_data = {
	.reg_status = TPS65218_REG_STATUS,
	.pb_mask = TPS65218_STATUS_PB_STATE,
	.name = "tps65218_pwrbutton",
};

struct tps6521x_pwrbutton {
	struct device *dev;
	struct regmap *regmap;
	struct input_dev *idev;
	const struct tps6521x_data *data;
	char phys[32];
};

static const struct of_device_id of_tps6521x_pb_match[] = {
	{ .compatible = "ti,tps65217-pwrbutton", .data = &tps65217_data },
	{ .compatible = "ti,tps65218-pwrbutton", .data = &tps65218_data },
	{ },
};
MODULE_DEVICE_TABLE(of, of_tps6521x_pb_match);

static irqreturn_t tps6521x_pb_irq(int irq, void *_pwr)
{
	struct tps6521x_pwrbutton *pwr = _pwr;
	const struct tps6521x_data *tps_data = pwr->data;
	unsigned int reg;
	int error;

	error = regmap_read(pwr->regmap, tps_data->reg_status, &reg);
	if (error) {
		dev_err(pwr->dev, "can't read register: %d\n", error);
		goto out;
	}

	if (reg & tps_data->pb_mask) {
		input_report_key(pwr->idev, KEY_POWER, 1);
		pm_wakeup_event(pwr->dev, 0);
	} else {
		input_report_key(pwr->idev, KEY_POWER, 0);
	}

	input_sync(pwr->idev);

out:
	return IRQ_HANDLED;
}

static int tps6521x_pb_probe(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
	struct tps6521x_pwrbutton *pwr;
	struct input_dev *idev;
	const struct of_device_id *match;
	int error;
	int irq;

	match = of_match_node(of_tps6521x_pb_match, dev->of_node);
	if (!match)
		return -ENXIO;

	pwr = devm_kzalloc(dev, sizeof(*pwr), GFP_KERNEL);
	if (!pwr)
		return -ENOMEM;

	pwr->data = match->data;

	idev = devm_input_allocate_device(dev);
	if (!idev)
		return -ENOMEM;

	idev->name = pwr->data->name;
	snprintf(pwr->phys, sizeof(pwr->phys), "%s/input0",
		pwr->data->name);
	idev->phys = pwr->phys;
	idev->dev.parent = dev;
	idev->id.bustype = BUS_I2C;

	input_set_capability(idev, EV_KEY, KEY_POWER);

Annotation

Implementation Notes