^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) ST-Ericsson SA 2010
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Author: Sundar Iyer <sundar.iyer@stericsson.com> for ST-Ericsson
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * AB8500 Power-On Key handler
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/mfd/abx500/ab8500.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * struct ab8500_ponkey - ab8500 ponkey information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * @input_dev: pointer to input device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * @ab8500: ab8500 parent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * @irq_dbf: irq number for falling transition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * @irq_dbr: irq number for rising transition
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct ab8500_ponkey {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) struct input_dev *idev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) struct ab8500 *ab8500;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) int irq_dbf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int irq_dbr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* AB8500 gives us an interrupt when ONKEY is held */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static irqreturn_t ab8500_ponkey_handler(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct ab8500_ponkey *ponkey = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) if (irq == ponkey->irq_dbf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) input_report_key(ponkey->idev, KEY_POWER, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) else if (irq == ponkey->irq_dbr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) input_report_key(ponkey->idev, KEY_POWER, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) input_sync(ponkey->idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) static int ab8500_ponkey_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct ab8500 *ab8500 = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct ab8500_ponkey *ponkey;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct input_dev *input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int irq_dbf, irq_dbr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) irq_dbf = platform_get_irq_byname(pdev, "ONKEY_DBF");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (irq_dbf < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return irq_dbf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) irq_dbr = platform_get_irq_byname(pdev, "ONKEY_DBR");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) if (irq_dbr < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) return irq_dbr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) ponkey = devm_kzalloc(&pdev->dev, sizeof(struct ab8500_ponkey),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) if (!ponkey)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) input = devm_input_allocate_device(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (!input)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ponkey->idev = input;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ponkey->ab8500 = ab8500;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ponkey->irq_dbf = irq_dbf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) ponkey->irq_dbr = irq_dbr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) input->name = "AB8500 POn(PowerOn) Key";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) input->dev.parent = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) input_set_capability(input, EV_KEY, KEY_POWER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) ab8500_ponkey_handler, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) "ab8500-ponkey-dbf", ponkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) dev_err(ab8500->dev, "Failed to request dbf IRQ#%d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) ponkey->irq_dbf, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) error = devm_request_any_context_irq(&pdev->dev, ponkey->irq_dbr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) ab8500_ponkey_handler, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) "ab8500-ponkey-dbr", ponkey);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (error < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) dev_err(ab8500->dev, "Failed to request dbr IRQ#%d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) ponkey->irq_dbr, error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) error = input_register_device(ponkey->idev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) dev_err(ab8500->dev, "Can't register input device: %d\n", error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) #ifdef CONFIG_OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static const struct of_device_id ab8500_ponkey_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) { .compatible = "stericsson,ab8500-ponkey", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) MODULE_DEVICE_TABLE(of, ab8500_ponkey_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static struct platform_driver ab8500_ponkey_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .name = "ab8500-poweron-key",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .of_match_table = of_match_ptr(ab8500_ponkey_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .probe = ab8500_ponkey_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) module_platform_driver(ab8500_ponkey_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) MODULE_LICENSE("GPL v2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) MODULE_AUTHOR("Sundar Iyer <sundar.iyer@stericsson.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) MODULE_DESCRIPTION("ST-Ericsson AB8500 Power-ON(Pon) Key driver");