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