Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: add support for OnKey module for DA9052/53 PMIC

On-key Driver for Dialog Semiconductor DA9052/53 PMICs.

Signed-off-by: David Dajun Chen <dchen@diasemi.com>
Signed-off-by: Ashish Jangam <ashish.jangam@kpitcummins.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>

authored by

Ashish Jangam and committed by
Dmitry Torokhov
f0c5f65b 1b8be32e

+180
+10
drivers/input/misc/Kconfig
··· 455 455 To compile this driver as a module, choose M here: the 456 456 module will be called rb532_button. 457 457 458 + config INPUT_DA9052_ONKEY 459 + tristate "Dialog DA9052/DA9053 Onkey" 460 + depends on PMIC_DA9052 461 + help 462 + Support the ONKEY of Dialog DA9052 PMICs as an input device 463 + reporting power button status. 464 + 465 + To compile this driver as a module, choose M here: the 466 + module will be called da9052_onkey. 467 + 458 468 config INPUT_DM355EVM 459 469 tristate "TI DaVinci DM355 EVM Keypad and IR Remote" 460 470 depends on MFD_DM355EVM_MSP
+1
drivers/input/misc/Makefile
··· 21 21 obj-$(CONFIG_INPUT_CMA3000) += cma3000_d0x.o 22 22 obj-$(CONFIG_INPUT_CMA3000_I2C) += cma3000_d0x_i2c.o 23 23 obj-$(CONFIG_INPUT_COBALT_BTNS) += cobalt_btns.o 24 + obj-$(CONFIG_INPUT_DA9052_ONKEY) += da9052_onkey.o 24 25 obj-$(CONFIG_INPUT_DM355EVM) += dm355evm_keys.o 25 26 obj-$(CONFIG_INPUT_GP2A) += gp2ap002a00f.o 26 27 obj-$(CONFIG_INPUT_GPIO_TILT_POLLED) += gpio_tilt_polled.o
+169
drivers/input/misc/da9052_onkey.c
··· 1 + /* 2 + * ON pin driver for Dialog DA9052 PMICs 3 + * 4 + * Copyright(c) 2012 Dialog Semiconductor Ltd. 5 + * 6 + * Author: David Dajun Chen <dchen@diasemi.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/init.h> 15 + #include <linux/input.h> 16 + #include <linux/module.h> 17 + #include <linux/platform_device.h> 18 + #include <linux/workqueue.h> 19 + 20 + #include <linux/mfd/da9052/da9052.h> 21 + #include <linux/mfd/da9052/reg.h> 22 + 23 + struct da9052_onkey { 24 + struct da9052 *da9052; 25 + struct input_dev *input; 26 + struct delayed_work work; 27 + unsigned int irq; 28 + }; 29 + 30 + static void da9052_onkey_query(struct da9052_onkey *onkey) 31 + { 32 + int key_stat; 33 + 34 + key_stat = da9052_reg_read(onkey->da9052, DA9052_EVENT_B_REG); 35 + if (key_stat < 0) { 36 + dev_err(onkey->da9052->dev, 37 + "Failed to read onkey event %d\n", key_stat); 38 + } else { 39 + /* 40 + * Since interrupt for deassertion of ONKEY pin is not 41 + * generated, onkey event state determines the onkey 42 + * button state. 43 + */ 44 + key_stat &= DA9052_EVENTB_ENONKEY; 45 + input_report_key(onkey->input, KEY_POWER, key_stat); 46 + input_sync(onkey->input); 47 + } 48 + 49 + /* 50 + * Interrupt is generated only when the ONKEY pin is asserted. 51 + * Hence the deassertion of the pin is simulated through work queue. 52 + */ 53 + if (key_stat) 54 + schedule_delayed_work(&onkey->work, msecs_to_jiffies(50)); 55 + } 56 + 57 + static void da9052_onkey_work(struct work_struct *work) 58 + { 59 + struct da9052_onkey *onkey = container_of(work, struct da9052_onkey, 60 + work.work); 61 + 62 + da9052_onkey_query(onkey); 63 + } 64 + 65 + static irqreturn_t da9052_onkey_irq(int irq, void *data) 66 + { 67 + struct da9052_onkey *onkey = data; 68 + 69 + da9052_onkey_query(onkey); 70 + 71 + return IRQ_HANDLED; 72 + } 73 + 74 + static int __devinit da9052_onkey_probe(struct platform_device *pdev) 75 + { 76 + struct da9052 *da9052 = dev_get_drvdata(pdev->dev.parent); 77 + struct da9052_onkey *onkey; 78 + struct input_dev *input_dev; 79 + int irq; 80 + int error; 81 + 82 + if (!da9052) { 83 + dev_err(&pdev->dev, "Failed to get the driver's data\n"); 84 + return -EINVAL; 85 + } 86 + 87 + irq = platform_get_irq_byname(pdev, "ONKEY"); 88 + if (irq < 0) { 89 + dev_err(&pdev->dev, 90 + "Failed to get an IRQ for input device, %d\n", irq); 91 + return -EINVAL; 92 + } 93 + 94 + onkey = kzalloc(sizeof(*onkey), GFP_KERNEL); 95 + input_dev = input_allocate_device(); 96 + if (!onkey || !input_dev) { 97 + dev_err(&pdev->dev, "Failed to allocate memory\n"); 98 + return -ENOMEM; 99 + } 100 + 101 + onkey->input = input_dev; 102 + onkey->da9052 = da9052; 103 + onkey->irq = irq; 104 + INIT_DELAYED_WORK(&onkey->work, da9052_onkey_work); 105 + 106 + input_dev->name = "da9052-onkey"; 107 + input_dev->phys = "da9052-onkey/input0"; 108 + input_dev->dev.parent = &pdev->dev; 109 + 110 + input_dev->evbit[0] = BIT_MASK(EV_KEY); 111 + __set_bit(KEY_POWER, input_dev->keybit); 112 + 113 + error = request_threaded_irq(onkey->irq, NULL, da9052_onkey_irq, 114 + IRQF_TRIGGER_LOW | IRQF_ONESHOT, 115 + "ONKEY", onkey); 116 + if (error < 0) { 117 + dev_err(onkey->da9052->dev, 118 + "Failed to register ONKEY IRQ %d, error = %d\n", 119 + onkey->irq, error); 120 + goto err_free_mem; 121 + } 122 + 123 + error = input_register_device(onkey->input); 124 + if (error) { 125 + dev_err(&pdev->dev, "Unable to register input device, %d\n", 126 + error); 127 + goto err_free_irq; 128 + } 129 + 130 + platform_set_drvdata(pdev, onkey); 131 + return 0; 132 + 133 + err_free_irq: 134 + free_irq(onkey->irq, onkey); 135 + cancel_delayed_work_sync(&onkey->work); 136 + err_free_mem: 137 + input_free_device(input_dev); 138 + kfree(onkey); 139 + 140 + return error; 141 + } 142 + 143 + static int __devexit da9052_onkey_remove(struct platform_device *pdev) 144 + { 145 + struct da9052_onkey *onkey = platform_get_drvdata(pdev); 146 + 147 + free_irq(onkey->irq, onkey); 148 + cancel_delayed_work_sync(&onkey->work); 149 + 150 + input_unregister_device(onkey->input); 151 + kfree(onkey); 152 + 153 + return 0; 154 + } 155 + 156 + static struct platform_driver da9052_onkey_driver = { 157 + .probe = da9052_onkey_probe, 158 + .remove = __devexit_p(da9052_onkey_remove), 159 + .driver = { 160 + .name = "da9052-onkey", 161 + .owner = THIS_MODULE, 162 + }, 163 + }; 164 + module_platform_driver(da9052_onkey_driver); 165 + 166 + MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); 167 + MODULE_DESCRIPTION("Onkey driver for DA9052"); 168 + MODULE_LICENSE("GPL"); 169 + MODULE_ALIAS("platform:da9052-onkey");