Skip to contentSkip to conversation

PCAP misc input driver (for 2.6.32)

PATCH In review Daniel Ribeiro 5 participants 8 messages Jun 27, 2009 – Jun 29, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCAP misc input driver (for 2.6.32)

This is a driver for misc input events for the PCAP2 PMIC, it handles the power button, headphone insertion/removal and the headphone button.

---
 drivers/input/keyboard/Kconfig     |    7 ++
 drivers/input/keyboard/Makefile    |    1 +
 drivers/input/keyboard/pcap_keys.c |  152 ++++++++++++++++++++++++++++++++++++
 3 files changed, 160 insertions(+), 0 deletions(-)
drivers/input/keyboard/Kconfig +7 -0
index 9d8f796..ea512b0 100644
@@ -353,4 +353,11 @@ config KEYBOARD_EP93XX
 	  To compile this driver as a module, choose M here: the
 	  module will be called ep93xx_keypad.
 
+config KEYBOARD_PCAP
+        tristate "Motorola EZX PCAP events"
+        depends on EZX_PCAP
+        help
+          Say Y here if you want to use power key and jack events
+          on Motorola EZX 2nd generation phones
+
 endif
drivers/input/keyboard/Makefile +1 -0
index 156b647..06b77dd 100644
@@ -30,3 +30,4 @@ obj-$(CONFIG_KEYBOARD_MAPLE)		+= maple_keyb.o
 obj-$(CONFIG_KEYBOARD_BFIN)		+= bf54x-keys.o
 obj-$(CONFIG_KEYBOARD_SH_KEYSC)		+= sh_keysc.o
 obj-$(CONFIG_KEYBOARD_EP93XX)		+= ep93xx_keypad.o
+obj-$(CONFIG_KEYBOARD_PCAP)		+= pcap_keys.o
drivers/input/keyboard/pcap_keys.c new file +152 -0

152 lines not on this page · raw message

Signature · 4 lines
tg: (22f99ae..) ezx/pcap_keys (depends on: ezx/local/pcap)

-- 
Daniel Ribeiro
#1 lore raw

Hi Daniel,

Quoted 15 lines
drivers/input/keyboard/pcap_keys.c new file +15 -0
+
+static int __init pcap_keys_probe(struct platform_device *pdev)
+{
+       int err = -ENOMEM;
+       struct pcap_keys *pcap_keys;
+
+       pcap_keys = kmalloc(sizeof(struct pcap_keys), GFP_KERNEL);
+       if (!pcap_keys)
+               return err;
+
+       pcap_keys->pcap = platform_get_drvdata(pdev);
+
+       pcap_keys->input = input_allocate_device();
+       if (!pcap_keys->input)
+               goto fail;

drivers/input/keyboard/pcap_keys.c line 78

Quoted 10 lines
drivers/input/keyboard/pcap_keys.c new file +10 -0
+
+       platform_set_drvdata(pdev, pcap_keys);
+       pcap_keys->input->name = pdev->name;
+       pcap_keys->input->phys = "pcap-keys/input0";
+       pcap_keys->input->dev.parent = &pdev->dev;
+
+       pcap_keys->input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_SW);
+       set_bit(KEY_POWER, pcap_keys->input->keybit);
+       set_bit(SW_HEADPHONE_INSERT, pcap_keys->input->swbit);
+       set_bit(KEY_HP, pcap_keys->input->keybit);

__set_bit please.

Quoted 9 lines
drivers/input/keyboard/pcap_keys.c new file +9 -0
+
+       err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_ONOFF),
+                       pcap_keys_handler, 0, "Power key", pcap_keys);
+       if (err)
+               goto fail_dev;
+
+       err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_HS),
+                       pcap_keys_handler, 0, "Headphone jack", pcap_keys);
+       if (err)

drivers/input/keyboard/pcap_keys.c line 97

Quoted 10 lines
drivers/input/keyboard/pcap_keys.c new file +10 -0
+               goto fail_pwrkey;
+
+       err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_MIC),
+                       pcap_keys_handler, 0, "MIC jack/button", pcap_keys);
+       if (err)
+               goto fail_jack;
+
+       err = input_register_device(pcap_keys->input);
+       if (err)
+               goto fail_mic;

Same comment as given in PCAP touchscreen driver.

Quoted 8 lines
drivers/input/keyboard/pcap_keys.c new file +8 -0
+
+static int pcap_keys_remove(struct platform_device *pdev)
+{
+       struct pcap_keys *pcap_keys = platform_get_drvdata(pdev);
+
+       free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_ONOFF), pcap_keys);
+       free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_HS), pcap_keys);
+       free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_MIC), pcap_keys);

drivers/input/keyboard/pcap_keys.c line 130

Quoted 10 lines
drivers/input/keyboard/pcap_keys.c new file +10 -0
+
+       input_unregister_device(pcap_keys->input);
+       kfree(pcap_keys);
+
+       return 0;
+}
+
+static struct platform_driver pcap_keys_device_driver = {
+       .probe          = pcap_keys_probe,
+       .remove         = pcap_keys_remove,

__devexit_p ?

Signature · 7 lines
---Trilok Soni
http://triloksoni.wordpress.com
http://www.linkedin.com/in/triloksoni
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

Em Dom, 2009-06-28 às 12:49 +0530, Trilok Soni escreveu:

Quoted 6 lines

drivers/input/keyboard/pcap_keys.c line 78

Quoted 4 lines
drivers/input/keyboard/pcap_keys.c new file +4 -0
+       pcap_keys->input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_SW);
+       set_bit(KEY_POWER, pcap_keys->input->keybit);
+       set_bit(SW_HEADPHONE_INSERT, pcap_keys->input->swbit);
+       set_bit(KEY_HP, pcap_keys->input->keybit);

__set_bit please.

Ok.

Quoted 13 lines
Quoted 13 lines
drivers/input/keyboard/pcap_keys.c new file +13 -0
+
+       err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_ONOFF),
+                       pcap_keys_handler, 0, "Power key", pcap_keys);
+       if (err)
+               goto fail_dev;
+
+       err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_HS),
+                       pcap_keys_handler, 0, "Headphone jack", pcap_keys);
+       if (err)
+               goto fail_pwrkey;
+
+       err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_MIC),
+                       pcap_keys_handler, 0, "MIC jack/button", pcap_keys);
Quoted 8 lines

drivers/input/keyboard/pcap_keys.c line 97

Quoted 6 lines
drivers/input/keyboard/pcap_keys.c new file +6 -0
+       if (err)
+               goto fail_jack;
+
+       err = input_register_device(pcap_keys->input);
+       if (err)
+               goto fail_mic;

Same comment as given in PCAP touchscreen driver.

Ok.

Quoted 5 lines

drivers/input/keyboard/pcap_keys.c line 130

Quoted 3 lines
drivers/input/keyboard/pcap_keys.c new file +3 -0
+static struct platform_driver pcap_keys_device_driver = {
+       .probe          = pcap_keys_probe,
+       .remove         = pcap_keys_remove,

__devexit_p ?

Ok.

Thanks for the review, I will send new versions addressing your comments as soon as possible.

Signature · 1 line
Daniel Ribeiro
maintainer
#3 lore raw
In reply to Daniel Ribeiro

Hi Daniel,

Quoted 12 lines · Daniel Ribeiro

This is a driver for misc input events for the PCAP2 PMIC, it handles the power button, headphone insertion/removal and the headphone button.

---
 drivers/input/keyboard/Kconfig     |    7 ++
 drivers/input/keyboard/Makefile    |    1 +
 drivers/input/keyboard/pcap_keys.c |  152 ++++++++++++++++++++++++++++++++++++
 3 files changed, 160 insertions(+), 0 deletions(-)

First of all I think the driver should live in misc, not in keyboard, since it is not a full-fledged keyboard.

Quoted 5 lines
drivers/input/keyboard/Kconfig +0 -0
index 9d8f796..ea512b0 100644

drivers/input/keyboard/Kconfig config KEYBOARD_EP93XX · line 362

Quoted 10 lines
drivers/input/keyboard/Kconfig +7 -0
@@ -353,4 +353,11 @@ config KEYBOARD_EP93XX
 	  To compile this driver as a module, choose M here: the
 	  module will be called ep93xx_keypad.
 
+config KEYBOARD_PCAP
+        tristate "Motorola EZX PCAP events"
+        depends on EZX_PCAP
+        help
+          Say Y here if you want to use power key and jack events
+          on Motorola EZX 2nd generation phones
+

To compile this driver as a module...

Quoted 52 lines
drivers/input/keyboard/Kconfig +0 -0
 endif
drivers/input/keyboard/Makefile +1 -0
index 156b647..06b77dd 100644
@@ -30,3 +30,4 @@ obj-$(CONFIG_KEYBOARD_MAPLE)		+= maple_keyb.o
 obj-$(CONFIG_KEYBOARD_BFIN)		+= bf54x-keys.o
 obj-$(CONFIG_KEYBOARD_SH_KEYSC)		+= sh_keysc.o
 obj-$(CONFIG_KEYBOARD_EP93XX)		+= ep93xx_keypad.o
+obj-$(CONFIG_KEYBOARD_PCAP)		+= pcap_keys.o
drivers/input/keyboard/pcap_keys.c new file +36 -0
new file mode 100644
index 0000000..8a9b533
@@ -0,0 +1,152 @@
+/*
+ *  Input driver for PCAP events:
+ *   * Power key
+ *   * Jack plug/unplug
+ *   * Headphone button
+ *
+ *  Copyright (c) 2008,2009 Ilya Petrov <[email protected]>
+ *
+ *  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/module.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/input.h>
+#include <linux/mfd/ezx-pcap.h>
+
+struct pcap_keys {
+	struct pcap_chip *pcap;
+	struct input_dev *input;
+};
+
+/* PCAP2 interrupts us on keypress */
+static irqreturn_t pcap_keys_handler(int irq, void *_pcap_keys)
+{
+	struct pcap_keys *pcap_keys = _pcap_keys;
+	int pirq = irq_to_pcap(pcap_keys->pcap, irq);
+	u32 pstat;
+
+	ezx_pcap_read(pcap_keys->pcap, PCAP_REG_PSTAT, &pstat);
+	pstat &= 1 << pirq;
+

drivers/input/keyboard/pcap_keys.c line 46

Quoted 10 lines
drivers/input/keyboard/pcap_keys.c new file +10 -0
+	switch (pirq) {
+	case PCAP_IRQ_ONOFF:
+		input_report_key(pcap_keys->input, KEY_POWER, !pstat);
+		break;
+	case PCAP_IRQ_HS:
+		input_report_switch(pcap_keys->input,
+				SW_HEADPHONE_INSERT, !pstat);
+		break;
+	case PCAP_IRQ_MIC:
+		input_report_key(pcap_keys->input, KEY_HP, !pstat);

Why not SW_MICROPHONE_INSERT?

drivers/input/keyboard/pcap_keys.c line 55

Quoted 9 lines
drivers/input/keyboard/pcap_keys.c new file +9 -0
+		break;
+	}
+
+	input_sync(pcap_keys->input);
+
+	return IRQ_HANDLED;
+}
+
+static int __init pcap_keys_probe(struct platform_device *pdev)

__devinit, not __init should be used on driver's probe() methods.

Quoted 8 lines
drivers/input/keyboard/pcap_keys.c new file +8 -0
+{
+	int err = -ENOMEM;
+	struct pcap_keys *pcap_keys;
+
+	pcap_keys = kmalloc(sizeof(struct pcap_keys), GFP_KERNEL);
+	if (!pcap_keys)
+		return err;
+

drivers/input/keyboard/pcap_keys.c line 73

Quoted 10 lines
drivers/input/keyboard/pcap_keys.c new file +10 -0
+	pcap_keys->pcap = platform_get_drvdata(pdev);
+
+	pcap_keys->input = input_allocate_device();
+	if (!pcap_keys->input)
+		goto fail;
+
+	platform_set_drvdata(pdev, pcap_keys);
+	pcap_keys->input->name = pdev->name;
+	pcap_keys->input->phys = "pcap-keys/input0";
+	pcap_keys->input->dev.parent = &pdev->dev;

I do like a temp for input_dev, it usually makes code a bit smaller. Also it would be nice to have but type set (BUS_HOST I think).

drivers/input/keyboard/pcap_keys.c line 79

Quoted 6 lines
drivers/input/keyboard/pcap_keys.c new file +6 -0
+
+	pcap_keys->input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_SW);
+	set_bit(KEY_POWER, pcap_keys->input->keybit);
+	set_bit(SW_HEADPHONE_INSERT, pcap_keys->input->swbit);
+	set_bit(KEY_HP, pcap_keys->input->keybit);
+

__set_bit() please, like Trolok said.

Quoted 25 lines
drivers/input/keyboard/pcap_keys.c new file +25 -0
+	err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_ONOFF),
+			pcap_keys_handler, 0, "Power key", pcap_keys);
+	if (err)
+		goto fail_dev;
+
+	err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_HS),
+			pcap_keys_handler, 0, "Headphone jack", pcap_keys);
+	if (err)
+		goto fail_pwrkey;
+
+	err = request_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_MIC),
+			pcap_keys_handler, 0, "MIC jack/button", pcap_keys);
+	if (err)
+		goto fail_jack;
+
+	err = input_register_device(pcap_keys->input);
+	if (err)
+		goto fail_mic;
+
+	return 0;
+
+fail_mic:
+	free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_MIC), pcap_keys);
+fail_jack:
+	free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_HS), pcap_keys);

drivers/input/keyboard/pcap_keys.c line 114

Quoted 10 lines
drivers/input/keyboard/pcap_keys.c new file +10 -0
+fail_pwrkey:
+	free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_ONOFF), pcap_keys);
+fail_dev:
+	input_free_device(pcap_keys->input);
+fail:
+	kfree(pcap_keys);
+	return err;
+}
+
+static int pcap_keys_remove(struct platform_device *pdev)

__devexit here.

Quoted 6 lines
drivers/input/keyboard/pcap_keys.c new file +6 -0
+{
+	struct pcap_keys *pcap_keys = platform_get_drvdata(pdev);
+
+	free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_ONOFF), pcap_keys);
+	free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_HS), pcap_keys);
+	free_irq(pcap_to_irq(pcap_keys->pcap, PCAP_IRQ_MIC), pcap_keys);

drivers/input/keyboard/pcap_keys.c line 130

Quoted 10 lines
drivers/input/keyboard/pcap_keys.c new file +10 -0
+
+	input_unregister_device(pcap_keys->input);
+	kfree(pcap_keys);
+
+	return 0;
+}
+
+static struct platform_driver pcap_keys_device_driver = {
+	.probe		= pcap_keys_probe,
+	.remove		= pcap_keys_remove,

__devexit_p()

Quoted 12 lines
drivers/input/keyboard/pcap_keys.c new file +12 -0
+	.driver		= {
+		.name	= "pcap-keys",
+		.owner	= THIS_MODULE,
+	}
+};
+
+static int __init pcap_keys_init(void)
+{
+	return platform_driver_register(&pcap_keys_device_driver);
+};
+
+static void __exit pcap_keys_exit(void)

drivers/input/keyboard/pcap_keys.c line 152

Quoted 10 lines
drivers/input/keyboard/pcap_keys.c new file +10 -0
+{
+	platform_driver_unregister(&pcap_keys_device_driver);
+};
+
+module_init(pcap_keys_init);
+module_exit(pcap_keys_exit);
+
+MODULE_DESCRIPTION("Motorola PCAP2 input events driver");
+MODULE_AUTHOR("Ilya Petrov <[email protected]>");
+MODULE_LICENSE("GPL");

Do we need MODULE_ALIAS() here?

Thanks!

Signature · 1 line
Dmitry
#4 lore raw

Em Dom, 2009-06-28 às 23:14 -0700, Dmitry Torokhov escreveu:

Quoted 8 lines
Quoted 5 lines
 drivers/input/keyboard/Kconfig     |    7 ++
 drivers/input/keyboard/Makefile    |    1 +
 drivers/input/keyboard/pcap_keys.c |  152 ++++++++++++++++++++++++++++++++++++
 3 files changed, 160 insertions(+), 0 deletions(-)

First of all I think the driver should live in misc, not in keyboard, since it is not a full-fledged keyboard.

Ok.

Quoted 5 lines

drivers/input/keyboard/Kconfig config KEYBOARD_EP93XX · line 362

Quoted 3 lines
drivers/input/keyboard/Kconfig +3 -0
+          Say Y here if you want to use power key and jack events
+          on Motorola EZX 2nd generation phones
+

To compile this driver as a module...

Ok.

Quoted 4 lines

drivers/input/keyboard/pcap_keys.c line 46

Quoted 2 lines
drivers/input/keyboard/pcap_keys.c new file +2 -0
+	case PCAP_IRQ_MIC:
+		input_report_key(pcap_keys->input, KEY_HP, !pstat);

Why not SW_MICROPHONE_INSERT?

Its actually a button.

The device has a single jack for headphone and microphone. And the headset that we connect to it has a button that you use to answer calls, or dial.

Quoted 3 lines
Quoted 1 line

+static int __init pcap_keys_probe(struct platform_device *pdev)

__devinit, not __init should be used on driver's probe() methods.

Ok.

Quoted 6 lines

drivers/input/keyboard/pcap_keys.c line 73

Quoted 3 lines
drivers/input/keyboard/pcap_keys.c new file +3 -0
+	pcap_keys->input->name = pdev->name;
+	pcap_keys->input->phys = "pcap-keys/input0";
+	pcap_keys->input->dev.parent = &pdev->dev;

I do like a temp for input_dev, it usually makes code a bit smaller. Also it would be nice to have but type set (BUS_HOST I think).

Ok.

Quoted 3 lines

drivers/input/keyboard/pcap_keys.c line 78

Quoted 1 line
drivers/input/keyboard/pcap_keys.c new file +1 -0
+	set_bit(KEY_HP, pcap_keys->input->keybit);

__set_bit() please, like Trolok said.

Ok.

Quoted 3 lines
Quoted 1 line

+static int pcap_keys_remove(struct platform_device *pdev)

__devexit here.

Ok.

Quoted 3 lines

drivers/input/keyboard/pcap_keys.c line 130

Quoted 1 line
drivers/input/keyboard/pcap_keys.c new file +1 -0
+	.remove		= pcap_keys_remove,

__devexit_p()

Ok.

Quoted 5 lines

drivers/input/keyboard/pcap_keys.c line 152

Quoted 3 lines
drivers/input/keyboard/pcap_keys.c new file +3 -0
+MODULE_DESCRIPTION("Motorola PCAP2 input events driver");
+MODULE_AUTHOR("Ilya Petrov <[email protected]>");
+MODULE_LICENSE("GPL");

Do we need MODULE_ALIAS() here?

Do we? I think we don't, but well... It costs nothing. ;)

Signature · 1 line
Daniel Ribeiro
#5 lore raw
In reply to Daniel Ribeiro
Quoted 2 lines · Daniel Ribeiro

This is a driver for misc input events for the PCAP2 PMIC, it handles the power button, headphone insertion/removal and the headphone button.

Depending on the power management capabilities of the CODEC it may be better to support at laest the headphone insert/removal via the audio driver as a jack to allow automatic management of the power for the relevant paths within the CODEC.

#6 lore raw

2009/6/29 Mark Brown <[email protected]>:

Quoted 4 lines

Depending on the power management capabilities of the CODEC it may be better to support at laest the headphone insert/removal via the audio driver as a jack to allow automatic management of the power for the relevant paths within the CODEC.

we need to control this manually from userspace - for example, even with headphone plugged in ringtone should be played via speaker.

Signature · 2 lines
 wbr, Ilya
 ICQ: none, Jabber: [email protected]
#7 lore raw
Quoted 9 lines · Ilya Petrov

2009/6/29 Mark Brown <[email protected]>:

Quoted 4 lines

Depending on the power management capabilities of the CODEC it may be better to support at laest the headphone insert/removal via the audio driver as a jack to allow automatic management of the power for the relevant paths within the CODEC.

we need to control this manually from userspace - for example, even with headphone plugged in ringtone should be played via speaker.

ALSA jacks are still visible to user space as input devices. The difference it will make here is that the kernel can autonomously control power for paths where that makes sense.