* [PATCH 8/12] neo1973: button input device driver
@ 2007-12-18 11:08 Harald Welte
[not found] ` <4767AE27.1050201@dominion.kabel.utwente.nl>
2008-01-03 17:05 ` Dmitry Torokhov
0 siblings, 2 replies; 3+ messages in thread
From: Harald Welte @ 2007-12-18 11:08 UTC (permalink / raw)
To: linux-arm-kernel; +Cc: linux-input
This driver provides support for the Neo1973 button/switch
Signed-off-by: Harald Welte <laforge@openmoko.org>
---
Index: linux-2.6/drivers/input/keyboard/Kconfig
===================================================================
--- linux-2.6.orig/drivers/input/keyboard/Kconfig
+++ linux-2.6/drivers/input/keyboard/Kconfig
@@ -293,4 +293,16 @@
To compile this driver as a module, choose M here: the
module will be called bf54x-keys.
+config KEYBOARD_NEO1973
+ tristate "FIC Neo1973 buttons"
+ depends on MACH_NEO1973
+ default y
+ help
+ Say Y here to enable the buttons on the FIC Neo1973
+ GSM phone.
+
+ To compile this driver as a module, choose M here: the
+ module will be called gta01kbd.
+
+
endif
Index: linux-2.6/drivers/input/keyboard/Makefile
===================================================================
--- linux-2.6.orig/drivers/input/keyboard/Makefile
+++ linux-2.6/drivers/input/keyboard/Makefile
@@ -14,6 +14,7 @@
obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o
obj-$(CONFIG_KEYBOARD_STOWAWAY) += stowaway.o
obj-$(CONFIG_KEYBOARD_CORGI) += corgikbd.o
+obj-$(CONFIG_KEYBOARD_NEO1973) += neo1973kbd.o
obj-$(CONFIG_KEYBOARD_SPITZ) += spitzkbd.o
obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o
obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o
Index: linux-2.6/drivers/input/keyboard/neo1973kbd.c
===================================================================
--- /dev/null
+++ linux-2.6/drivers/input/keyboard/neo1973kbd.c
@@ -0,0 +1,236 @@
+/*
+ * Keyboard driver for FIC Neo1973 GSM phone
+ *
+ * (C) 2006-2007 by OpenMoko, Inc.
+ * Author: Harald Welte <laforge@openmoko.org>
+ * All rights reserved.
+ *
+ * inspired by corkgbd.c by Richard Purdie
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/delay.h>
+#include <linux/platform_device.h>
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/jiffies.h>
+#include <linux/module.h>
+#include <linux/slab.h>
+
+#include <asm/hardware.h>
+#include <asm/arch/gta01.h>
+
+struct neo1973kbd {
+ struct input_dev *input;
+ unsigned int suspended;
+ unsigned long suspend_jiffies;
+};
+
+static irqreturn_t neo1973kbd_aux_irq(int irq, void *dev_id)
+{
+ struct neo1973kbd *neo1973kbd_data = dev_id;
+
+ /* FIXME: use GPIO from platform_dev resources */
+ if (s3c2410_gpio_getpin(GTA01_GPIO_AUX_KEY))
+ input_report_key(neo1973kbd_data->input, KEY_PHONE, 0);
+ else
+ input_report_key(neo1973kbd_data->input, KEY_PHONE, 1);
+
+ input_sync(neo1973kbd_data->input);
+
+ return IRQ_HANDLED;
+}
+
+static irqreturn_t neo1973kbd_hold_irq(int irq, void *dev_id)
+{
+ struct neo1973kbd *neo1973kbd_data = dev_id;
+
+ /* FIXME: use GPIO from platform_dev resources */
+ if (s3c2410_gpio_getpin(GTA01_GPIO_HOLD_KEY))
+ input_report_key(neo1973kbd_data->input, KEY_PAUSE, 1);
+ else
+ input_report_key(neo1973kbd_data->input, KEY_PAUSE, 0);
+
+ input_sync(neo1973kbd_data->input);
+
+ return IRQ_HANDLED;
+}
+
+static irqreturn_t neo1973kbd_headphone_irq(int irq, void *dev_id)
+{
+ struct neo1973kbd *neo1973kbd_data = dev_id;
+
+ /* FIXME: use GPIO from platform_dev resources */
+ if (s3c2410_gpio_getpin(GTA01_GPIO_JACK_INSERT))
+ input_report_switch(neo1973kbd_data->input,
+ SW_HEADPHONE_INSERT, 1);
+ else
+ input_report_switch(neo1973kbd_data->input,
+ SW_HEADPHONE_INSERT, 0);
+
+ input_sync(neo1973kbd_data->input);
+
+ return IRQ_HANDLED;
+}
+
+#ifdef CONFIG_PM
+static int neo1973kbd_suspend(struct platform_device *dev, pm_message_t state)
+{
+ struct neo1973kbd *neo1973kbd = platform_get_drvdata(dev);
+
+ neo1973kbd->suspended = 1;
+
+ return 0;
+}
+
+static int neo1973kbd_resume(struct platform_device *dev)
+{
+ struct neo1973kbd *neo1973kbd = platform_get_drvdata(dev);
+
+ neo1973kbd->suspended = 0;
+
+ return 0;
+}
+#else
+#define neo1973kbd_suspend NULL
+#define neo1973kbd_resume NULL
+#endif
+
+static int neo1973kbd_probe(struct platform_device *pdev)
+{
+ struct neo1973kbd *neo1973kbd;
+ struct input_dev *input_dev;
+ int rc, irq_aux, irq_hold, irq_jack;
+
+ neo1973kbd = kzalloc(sizeof(struct neo1973kbd), GFP_KERNEL);
+ input_dev = input_allocate_device();
+ if (!neo1973kbd || !input_dev) {
+ kfree(neo1973kbd);
+ input_free_device(input_dev);
+ return -ENOMEM;
+ }
+
+ if (pdev->resource[0].flags != 0)
+ return -EINVAL;
+
+ irq_aux = s3c2410_gpio_getirq(pdev->resource[0].start);
+ if (irq_aux < 0)
+ return -EINVAL;
+
+ irq_hold = s3c2410_gpio_getirq(pdev->resource[1].start);
+ if (irq_hold < 0)
+ return -EINVAL;
+
+ irq_jack = s3c2410_gpio_getirq(pdev->resource[2].start);
+ if (irq_jack < 0)
+ return -EINVAL;
+
+ platform_set_drvdata(pdev, neo1973kbd);
+
+ neo1973kbd->input = input_dev;
+
+ input_dev->name = "Neo1973 Buttons";
+ input_dev->phys = "neo1973kbd/input0";
+ input_dev->id.bustype = BUS_HOST;
+ input_dev->id.vendor = 0x0001;
+ input_dev->id.product = 0x0001;
+ input_dev->id.version = 0x0100;
+ input_dev->cdev.dev = &pdev->dev;
+ input_dev->private = neo1973kbd;
+
+ input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_SW);
+ set_bit(SW_HEADPHONE_INSERT, input_dev->swbit);
+ set_bit(KEY_PHONE, input_dev->keybit);
+ set_bit(KEY_PAUSE, input_dev->keybit);
+
+ rc = input_register_device(neo1973kbd->input);
+ if (rc)
+ goto out_register;
+
+ if (request_irq(irq_aux, neo1973kbd_aux_irq, IRQF_DISABLED |
+ IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+ "Neo1973 AUX button", neo1973kbd)) {
+ dev_err(&pdev->dev, "Can't get IRQ %u\n", irq_aux);
+ goto out_aux;
+ }
+ enable_irq_wake(irq_aux);
+
+ if (request_irq(irq_hold, neo1973kbd_hold_irq, IRQF_DISABLED |
+ IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+ "Neo1973 HOLD button", neo1973kbd)) {
+ dev_err(&pdev->dev, "Can't get IRQ %u\n", irq_hold);
+ goto out_hold;
+ }
+ enable_irq_wake(irq_hold);
+
+ if (request_irq(irq_jack, neo1973kbd_headphone_irq, IRQF_DISABLED |
+ IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
+ "Neo1973 Headphone Jack", neo1973kbd)) {
+ dev_err(&pdev->dev, "Can't get IRQ %u\n", irq_jack);
+ goto out_jack;
+ }
+ enable_irq_wake(irq_jack);
+
+ return 0;
+
+out_jack:
+ free_irq(irq_hold, neo1973kbd);
+out_hold:
+ free_irq(irq_aux, neo1973kbd);
+out_aux:
+ input_unregister_device(neo1973kbd->input);
+out_register:
+ input_free_device(neo1973kbd->input);
+ platform_set_drvdata(pdev, NULL);
+ kfree(neo1973kbd);
+
+ return -ENODEV;
+}
+
+static int neo1973kbd_remove(struct platform_device *pdev)
+{
+ struct neo1973kbd *neo1973kbd = platform_get_drvdata(pdev);
+
+ free_irq(s3c2410_gpio_getirq(pdev->resource[2].start), neo1973kbd);
+ free_irq(s3c2410_gpio_getirq(pdev->resource[1].start), neo1973kbd);
+ free_irq(s3c2410_gpio_getirq(pdev->resource[0].start), neo1973kbd);
+
+ input_unregister_device(neo1973kbd->input);
+ input_free_device(neo1973kbd->input);
+ platform_set_drvdata(pdev, NULL);
+ kfree(neo1973kbd);
+
+ return 0;
+}
+
+static struct platform_driver neo1973kbd_driver = {
+ .probe = neo1973kbd_probe,
+ .remove = neo1973kbd_remove,
+ .suspend = neo1973kbd_suspend,
+ .resume = neo1973kbd_resume,
+ .driver = {
+ .name = "neo1973-button",
+ },
+};
+
+static int __devinit neo1973kbd_init(void)
+{
+ return platform_driver_register(&neo1973kbd_driver);
+}
+
+static void __exit neo1973kbd_exit(void)
+{
+ platform_driver_unregister(&neo1973kbd_driver);
+}
+
+module_init(neo1973kbd_init);
+module_exit(neo1973kbd_exit);
+
+MODULE_AUTHOR("Harald Welte <laforge@openmoko.org>");
+MODULE_DESCRIPTION("FIC Neo1973 buttons input driver");
+MODULE_LICENSE("GPL");
--
- Harald Welte <laforge@openmoko.org> http://openmoko.org/
============================================================================
Software for the world's first truly open Free Software mobile phone
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 8/12] neo1973: button input device driver
[not found] ` <4767AE27.1050201@dominion.kabel.utwente.nl>
@ 2007-12-21 8:33 ` Harald Welte
0 siblings, 0 replies; 3+ messages in thread
From: Harald Welte @ 2007-12-21 8:33 UTC (permalink / raw)
To: Koen Kooi; +Cc: linux-arm-kernel, linux-input
On Tue, Dec 18, 2007 at 12:25:27PM +0100, Koen Kooi wrote:
> > This driver provides support for the Neo1973 button/switch
> >
> > Signed-off-by: Harald Welte <laforge@openmoko.org>
> >
> > + To compile this driver as a module, choose M here: the
> > + module will be called gta01kbd.
>
> I think that needs a s/gta01kbd/neo1973kbd/ because:
Thanks a lot, I've fixed this in my patchset. Will await further
comments before re-posting that patch.
--
- Harald Welte <laforge@openmoko.org> http://openmoko.org/
============================================================================
Software for the world's first truly open Free Software mobile phone
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 8/12] neo1973: button input device driver
2007-12-18 11:08 [PATCH 8/12] neo1973: button input device driver Harald Welte
[not found] ` <4767AE27.1050201@dominion.kabel.utwente.nl>
@ 2008-01-03 17:05 ` Dmitry Torokhov
1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Torokhov @ 2008-01-03 17:05 UTC (permalink / raw)
To: Harald Welte; +Cc: linux-arm-kernel, linux-input
Hi Harald,
Sorry for the slow response.
On Dec 18, 2007 6:08 AM, Harald Welte <laforge@openmoko.org> wrote:
> +
> + input_dev->name = "Neo1973 Buttons";
> + input_dev->phys = "neo1973kbd/input0";
> + input_dev->id.bustype = BUS_HOST;
> + input_dev->id.vendor = 0x0001;
> + input_dev->id.product = 0x0001;
> + input_dev->id.version = 0x0100;
> + input_dev->cdev.dev = &pdev->dev;
Please use input_dev->dev.parent instead of cdev as it is going away.
> + input_dev->private = neo1973kbd;
Please use input_set_drvdata() instead of accessing private directly.
> +out_aux:
> + input_unregister_device(neo1973kbd->input);
Add neo1973kbd->input = NULL here, otherwise we'll end up doing
input_free_device after input_unregister_device which is no good
(unregister will free the device if it is the last reference).
> +out_register:
> + input_free_device(neo1973kbd->input);
> + platform_set_drvdata(pdev, NULL);
> + kfree(neo1973kbd);
> +
> + return -ENODEV;
> +}
> +
> +static int neo1973kbd_remove(struct platform_device *pdev)
> +{
> + struct neo1973kbd *neo1973kbd = platform_get_drvdata(pdev);
> +
> + free_irq(s3c2410_gpio_getirq(pdev->resource[2].start), neo1973kbd);
> + free_irq(s3c2410_gpio_getirq(pdev->resource[1].start), neo1973kbd);
> + free_irq(s3c2410_gpio_getirq(pdev->resource[0].start), neo1973kbd);
> +
> + input_unregister_device(neo1973kbd->input);
> + input_free_device(neo1973kbd->input);
Same here, input_free_device() is harmful here.
--
Dmitry
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-01-03 17:05 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-18 11:08 [PATCH 8/12] neo1973: button input device driver Harald Welte
[not found] ` <4767AE27.1050201@dominion.kabel.utwente.nl>
2007-12-21 8:33 ` Harald Welte
2008-01-03 17:05 ` Dmitry Torokhov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).