Balaji Rao | 1851b06 | 2009-01-09 01:50:58 +0100 | [diff] [blame] | 1 | /* NXP PCF50633 Input Driver |
| 2 | * |
| 3 | * (C) 2006-2008 by Openmoko, Inc. |
| 4 | * Author: Balaji Rao <balajirrao@openmoko.org> |
| 5 | * All rights reserved. |
| 6 | * |
| 7 | * Broken down from monstrous PCF50633 driver mainly by |
| 8 | * Harald Welte, Andy Green and Werner Almesberger |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify it |
| 11 | * under the terms of the GNU General Public License as published by the |
| 12 | * Free Software Foundation; either version 2 of the License, or (at your |
| 13 | * option) any later version. |
| 14 | * |
| 15 | */ |
| 16 | |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/module.h> |
Balaji Rao | 1851b06 | 2009-01-09 01:50:58 +0100 | [diff] [blame] | 19 | #include <linux/device.h> |
| 20 | #include <linux/platform_device.h> |
| 21 | #include <linux/input.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Balaji Rao | 1851b06 | 2009-01-09 01:50:58 +0100 | [diff] [blame] | 23 | |
| 24 | #include <linux/mfd/pcf50633/core.h> |
| 25 | |
| 26 | #define PCF50633_OOCSTAT_ONKEY 0x01 |
| 27 | #define PCF50633_REG_OOCSTAT 0x12 |
| 28 | #define PCF50633_REG_OOCMODE 0x10 |
| 29 | |
| 30 | struct pcf50633_input { |
| 31 | struct pcf50633 *pcf; |
| 32 | struct input_dev *input_dev; |
| 33 | }; |
| 34 | |
| 35 | static void |
| 36 | pcf50633_input_irq(int irq, void *data) |
| 37 | { |
| 38 | struct pcf50633_input *input; |
| 39 | int onkey_released; |
| 40 | |
| 41 | input = data; |
| 42 | |
| 43 | /* We report only one event depending on the key press status */ |
| 44 | onkey_released = pcf50633_reg_read(input->pcf, PCF50633_REG_OOCSTAT) |
| 45 | & PCF50633_OOCSTAT_ONKEY; |
| 46 | |
| 47 | if (irq == PCF50633_IRQ_ONKEYF && !onkey_released) |
| 48 | input_report_key(input->input_dev, KEY_POWER, 1); |
| 49 | else if (irq == PCF50633_IRQ_ONKEYR && onkey_released) |
| 50 | input_report_key(input->input_dev, KEY_POWER, 0); |
| 51 | |
| 52 | input_sync(input->input_dev); |
| 53 | } |
| 54 | |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 55 | static int pcf50633_input_probe(struct platform_device *pdev) |
Balaji Rao | 1851b06 | 2009-01-09 01:50:58 +0100 | [diff] [blame] | 56 | { |
| 57 | struct pcf50633_input *input; |
Balaji Rao | 1851b06 | 2009-01-09 01:50:58 +0100 | [diff] [blame] | 58 | struct input_dev *input_dev; |
| 59 | int ret; |
| 60 | |
| 61 | |
| 62 | input = kzalloc(sizeof(*input), GFP_KERNEL); |
| 63 | if (!input) |
| 64 | return -ENOMEM; |
| 65 | |
| 66 | input_dev = input_allocate_device(); |
| 67 | if (!input_dev) { |
| 68 | kfree(input); |
| 69 | return -ENOMEM; |
| 70 | } |
| 71 | |
| 72 | platform_set_drvdata(pdev, input); |
Lars-Peter Clausen | 68d641e | 2009-10-14 02:12:33 +0400 | [diff] [blame] | 73 | input->pcf = dev_to_pcf50633(pdev->dev.parent); |
Balaji Rao | 1851b06 | 2009-01-09 01:50:58 +0100 | [diff] [blame] | 74 | input->input_dev = input_dev; |
| 75 | |
| 76 | input_dev->name = "PCF50633 PMU events"; |
| 77 | input_dev->id.bustype = BUS_I2C; |
| 78 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_PWR); |
| 79 | set_bit(KEY_POWER, input_dev->keybit); |
| 80 | |
| 81 | ret = input_register_device(input_dev); |
| 82 | if (ret) { |
| 83 | input_free_device(input_dev); |
| 84 | kfree(input); |
| 85 | return ret; |
| 86 | } |
Lars-Peter Clausen | 68d641e | 2009-10-14 02:12:33 +0400 | [diff] [blame] | 87 | pcf50633_register_irq(input->pcf, PCF50633_IRQ_ONKEYR, |
Balaji Rao | 1851b06 | 2009-01-09 01:50:58 +0100 | [diff] [blame] | 88 | pcf50633_input_irq, input); |
Lars-Peter Clausen | 68d641e | 2009-10-14 02:12:33 +0400 | [diff] [blame] | 89 | pcf50633_register_irq(input->pcf, PCF50633_IRQ_ONKEYF, |
Balaji Rao | 1851b06 | 2009-01-09 01:50:58 +0100 | [diff] [blame] | 90 | pcf50633_input_irq, input); |
| 91 | |
| 92 | return 0; |
| 93 | } |
| 94 | |
Bill Pemberton | e2619cf | 2012-11-23 21:50:47 -0800 | [diff] [blame] | 95 | static int pcf50633_input_remove(struct platform_device *pdev) |
Balaji Rao | 1851b06 | 2009-01-09 01:50:58 +0100 | [diff] [blame] | 96 | { |
| 97 | struct pcf50633_input *input = platform_get_drvdata(pdev); |
| 98 | |
| 99 | pcf50633_free_irq(input->pcf, PCF50633_IRQ_ONKEYR); |
| 100 | pcf50633_free_irq(input->pcf, PCF50633_IRQ_ONKEYF); |
| 101 | |
| 102 | input_unregister_device(input->input_dev); |
| 103 | kfree(input); |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static struct platform_driver pcf50633_input_driver = { |
| 109 | .driver = { |
| 110 | .name = "pcf50633-input", |
| 111 | }, |
| 112 | .probe = pcf50633_input_probe, |
Bill Pemberton | 1cb0aa8 | 2012-11-23 21:27:39 -0800 | [diff] [blame] | 113 | .remove = pcf50633_input_remove, |
Balaji Rao | 1851b06 | 2009-01-09 01:50:58 +0100 | [diff] [blame] | 114 | }; |
JJ Ding | 840a746 | 2011-11-29 11:08:40 -0800 | [diff] [blame] | 115 | module_platform_driver(pcf50633_input_driver); |
Balaji Rao | 1851b06 | 2009-01-09 01:50:58 +0100 | [diff] [blame] | 116 | |
| 117 | MODULE_AUTHOR("Balaji Rao <balajirrao@openmoko.org>"); |
| 118 | MODULE_DESCRIPTION("PCF50633 input driver"); |
| 119 | MODULE_LICENSE("GPL"); |
| 120 | MODULE_ALIAS("platform:pcf50633-input"); |