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 dev_err(&pdev->dev, "Can't get fall irq: %d\n", fall_irq); 58 return fall_irq; 59 } 60 61 rise_irq = platform_get_irq(pdev, 1); 62 if (rise_irq < 0) { 63 dev_err(&pdev->dev, "Can't get rise irq: %d\n", rise_irq); 64 return rise_irq; 65 } 66 67 err = devm_request_any_context_irq(&pwr->dev, fall_irq, 68 pwrkey_fall_irq, 69 IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 70 "rk805_pwrkey_fall", pwr); 71 if (err < 0) { 72 dev_err(&pdev->dev, "Can't register fall irq: %d\n", err); 73 return err; 74 } 75 76 err = devm_request_any_context_irq(&pwr->dev, rise_irq, 77 pwrkey_rise_irq, 78 IRQF_TRIGGER_RISING | IRQF_ONESHOT, 79 "rk805_pwrkey_rise", pwr); 80 if (err < 0) { 81 dev_err(&pdev->dev, "Can't register rise irq: %d\n", err); 82 return err; 83 } 84 85 err = input_register_device(pwr); 86 if (err) { 87 dev_err(&pdev->dev, "Can't register power button: %d\n", err); 88 return err; 89 } 90 91 platform_set_drvdata(pdev, pwr); 92 device_init_wakeup(&pdev->dev, true); 93 94 return 0; 95 } 96 97 static struct platform_driver rk805_pwrkey_driver = { 98 .probe = rk805_pwrkey_probe, 99 .driver = { 100 .name = "rk805-pwrkey", 101 }, 102 }; 103 module_platform_driver(rk805_pwrkey_driver); 104 105 MODULE_AUTHOR("Joseph Chen <chenjh@rock-chips.com>"); 106 MODULE_DESCRIPTION("RK805 PMIC Power Key driver"); 107 MODULE_LICENSE("GPL"); 108