1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Rockchip RK805 PMIC Power Key driver 4 * 5 * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd 6 * 7 * Author: Joseph Chen <chenjh@rock-chips.com> 8 */ 9 10 #include <linux/errno.h> 11 #include <linux/init.h> 12 #include <linux/input.h> 13 #include <linux/interrupt.h> 14 #include <linux/kernel.h> 15 #include <linux/module.h> 16 #include <linux/platform_device.h> 17 18 static irqreturn_t pwrkey_fall_irq(int irq, void *_pwr) 19 { 20 struct input_dev *pwr = _pwr; 21 22 input_report_key(pwr, KEY_POWER, 1); 23 input_sync(pwr); 24 25 return IRQ_HANDLED; 26 } 27 28 static irqreturn_t pwrkey_rise_irq(int irq, void *_pwr) 29 { 30 struct input_dev *pwr = _pwr; 31 32 input_report_key(pwr, KEY_POWER, 0); 33 input_sync(pwr); 34 35 return IRQ_HANDLED; 36 } 37 38 static int rk805_pwrkey_probe(struct platform_device *pdev) 39 { 40 struct input_dev *pwr; 41 int fall_irq, rise_irq; 42 int err; 43 44 pwr = devm_input_allocate_device(&pdev->dev); 45 if (!pwr) { 46 dev_err(&pdev->dev, "Can't allocate power button\n"); 47 return -ENOMEM; 48 } 49 50 pwr->name = "rk805 pwrkey"; 51 pwr->phys = "rk805_pwrkey/input0"; 52 pwr->id.bustype = BUS_HOST; 53 input_set_capability(pwr, EV_KEY, KEY_POWER); 54 55 fall_irq = platform_get_irq(pdev, 0); 56 if (fall_irq < 0) 57 return fall_irq; 58 59 rise_irq = platform_get_irq(pdev, 1); 60 if (rise_irq < 0) 61 return rise_irq; 62 63 err = devm_request_any_context_irq(&pwr->dev, fall_irq, 64 pwrkey_fall_irq, 65 IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 66 "rk805_pwrkey_fall", pwr); 67 if (err < 0) { 68 dev_err(&pdev->dev, "Can't register fall irq: %d\n", err); 69 return err; 70 } 71 72 err = devm_request_any_context_irq(&pwr->dev, rise_irq, 73 pwrkey_rise_irq, 74 IRQF_TRIGGER_RISING | IRQF_ONESHOT, 75 "rk805_pwrkey_rise", pwr); 76 if (err < 0) { 77 dev_err(&pdev->dev, "Can't register rise irq: %d\n", err); 78 return err; 79 } 80 81 err = input_register_device(pwr); 82 if (err) { 83 dev_err(&pdev->dev, "Can't register power button: %d\n", err); 84 return err; 85 } 86 87 platform_set_drvdata(pdev, pwr); 88 device_init_wakeup(&pdev->dev, true); 89 90 return 0; 91 } 92 93 static struct platform_driver rk805_pwrkey_driver = { 94 .probe = rk805_pwrkey_probe, 95 .driver = { 96 .name = "rk805-pwrkey", 97 }, 98 }; 99 module_platform_driver(rk805_pwrkey_driver); 100 101 MODULE_ALIAS("platform:rk805-pwrkey"); 102 MODULE_AUTHOR("Joseph Chen <chenjh@rock-chips.com>"); 103 MODULE_DESCRIPTION("RK805 PMIC Power Key driver"); 104 MODULE_LICENSE("GPL"); 105