drivers/input/misc/pf1550-onkey.c

Source file repositories/reference/linux-study-clean/drivers/input/misc/pf1550-onkey.c

File Facts

System
Linux kernel
Corpus path
drivers/input/misc/pf1550-onkey.c
Extension
.c
Size
4964 bytes
Lines
198
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 onkey_drv_data {
	struct device *dev;
	const struct pf1550_ddata *pf1550;
	bool wakeup;
	struct input_dev *input;
};

static irqreturn_t pf1550_onkey_irq_handler(int irq, void *data)
{
	struct onkey_drv_data *onkey = data;
	struct platform_device *pdev = to_platform_device(onkey->dev);
	int i, state, irq_type = -1;

	for (i = 0; i < PF1550_ONKEY_IRQ_NR; i++)
		if (irq == platform_get_irq(pdev, i))
			irq_type = i;

	switch (irq_type) {
	case PF1550_ONKEY_IRQ_PUSHI:
		state = 0;
		break;
	case PF1550_ONKEY_IRQ_1SI:
	case PF1550_ONKEY_IRQ_2SI:
	case PF1550_ONKEY_IRQ_3SI:
	case PF1550_ONKEY_IRQ_4SI:
	case PF1550_ONKEY_IRQ_8SI:
		state = 1;
		break;
	default:
		dev_err(onkey->dev, "onkey interrupt: irq %d occurred\n",
			irq_type);
		return IRQ_HANDLED;
	}

	input_event(onkey->input, EV_KEY, KEY_POWER, state);
	input_sync(onkey->input);

	return IRQ_HANDLED;
}

static int pf1550_onkey_probe(struct platform_device *pdev)
{
	struct onkey_drv_data *onkey;
	struct input_dev *input;
	bool key_power = false;
	int i, irq, error;

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

	onkey->dev = &pdev->dev;

	onkey->pf1550 = dev_get_drvdata(pdev->dev.parent);
	if (!onkey->pf1550->regmap)
		return dev_err_probe(&pdev->dev, -ENODEV,
				     "failed to get regmap\n");

	onkey->wakeup = device_property_read_bool(pdev->dev.parent,
						  "wakeup-source");

	if (device_property_read_bool(pdev->dev.parent,
				      "nxp,disable-key-power")) {
		error = regmap_clear_bits(onkey->pf1550->regmap,
					  PF1550_PMIC_REG_PWRCTRL1,
					  PF1550_ONKEY_RST_EN);
		if (error)
			return dev_err_probe(&pdev->dev, error,
					     "failed: disable turn system off");
	} else {
		key_power = true;
	}

	input = devm_input_allocate_device(&pdev->dev);
	if (!input)
		return dev_err_probe(&pdev->dev, -ENOMEM,
				     "failed to allocate the input device\n");

	input->name = pdev->name;
	input->phys = "pf1550-onkey/input0";
	input->id.bustype = BUS_HOST;

	if (key_power)
		input_set_capability(input, EV_KEY, KEY_POWER);

	onkey->input = input;
	platform_set_drvdata(pdev, onkey);

	for (i = 0; i < PF1550_ONKEY_IRQ_NR; i++) {
		irq = platform_get_irq(pdev, i);

Annotation

Implementation Notes