This is a driver for misc input events for the PCAP2 PMIC, it handles
the power button, headphone insertion/removal and the headphone button.
Signed-off-by: Ilya Petrov <ilya.muromec@gmail.com>
Signed-off-by: Daniel Ribeiro <drwyrm@gmail.com>
-diff module will be called ep93xx-keypad.
=20
+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
diff obj-$(CONFIG-KEYBOARD-SH-KEYSC) +=3D sh-keysc.o
obj-$(CONFIG-KEYBOARD-EP93XX) +=3D ep93xx-keypad.o
+obj-$(CONFIG-KEYBOARD-PCAP) +=3D pcap-keys.o
diff +/*
+ * Input driver for PCAP events:
+ * * Power key
+ * * Jack plug/unplug
+ * * Headphone button
+ *
+ * Copyright (c) 2008,2009 Ilya Petrov <ilya.muromec@gmail.com>
+ *
+ * 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 =3D -pcap-keys;
+ int pirq =3D irq-to-pcap(pcap-keys->pcap, irq);
+ u32 pstat;
+
+ ezx-pcap-read(pcap-keys->pcap, PCAP-REG-PSTAT, &pstat);
+ pstat &=3D 1 << pirq;
+
+ 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);
+ break;
+ }
+
+ input-sync(pcap-keys->input);
+
+ return IRQ-HANDLED;
+}
+
+static int + return err;
+
+ pcap-keys->pcap =3D platform-get-drvdata(pdev);
+
+ pcap-keys->input =3D input-allocate-device();
+ if (!pcap-keys->input)
+ goto fail;
+
+ platform-set-drvdata(pdev, pcap-keys);
+ pcap-keys->input->name =3D pdev->name;
+ pcap-keys->input->phys =3D "pcap-keys/input0";
+ pcap-keys->input->dev.parent =3D &pdev->dev;
+
+ pcap-keys->input->evbit[0] =3D 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);
+
+ err =3D 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 =3D 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 =3D 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 =3D 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);
+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)
+{
+ struct pcap-keys *pcap-keys =3D 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);
+
+ input-unregister-device(pcap-keys->input);
+ kfree(pcap-keys);
+
+ return 0;
+}
+
+static struct platform-driver pcap-keys-device-driver =3D {
+ .probe =3D pcap-keys-probe,
+ .remove =3D pcap-keys-remove,
+ .driver =3D {
+ .name =3D "pcap-keys",
+ .owner =3D THIS-MODULE,
+ }
+};
+
+static int + 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 <ilya.muromec@gmail.com>");
+MODULE-LICENSE("GPL");
Re: PATCH - PCAP misc input driver (for 2.6.32) by Trilok Soni on
2009-06-28T07:19:52+00:00
Hi Daniel,
> +
> +static int > + return err;
> +
> + 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;
> +
> + 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);
> +
> + 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;
Same comment as given in PCAP touchscreen driver.
> +
> +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);
> +
> + 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,
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: PATCH - PCAP misc input driver (for 2.6.32) by Daniel Ribeiro on
2009-06-28T17:53:30+00:00
Em Dom, 2009-06-28 =C3=A0s 12:49 +0530, Trilok Soni escreveu:
> > + pcap-keys->input->evbit[0] =3D BIT-MASK(EV-KEY) | BIT-MASK(EV-S=
W);
> > + 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);
>=20
> > > + pcap-keys-handler, 0, "Power key", pcap-keys);
> > + if (err)
> > + goto fail-dev;
> > +
> > + err =3D request-irq(pcap-to-irq(pcap-keys->pcap, PCAP-IRQ-HS),
> > + pcap-keys-handler, 0, "Headphone jack", pcap-ke=
ys);
> > + if (err)
> > + goto fail-pwrkey;
> > +
> > + err =3D request-irq(pcap-to-irq(pcap-keys->pcap, PCAP-IRQ-MIC),
> > + pcap-keys-handler, 0, "MIC jack/button", pcap-k=
eys);
> > + if (err)
> > + goto fail-jack;
> > +
> > + err =3D input-register-device(pcap-keys->input);
> > + if (err)
> > + goto fail-mic;
>=20
> Same comment as given in PCAP touchscreen driver.
Ok.
> > +static struct platform-driver pcap-keys-device-driver =3D {
> > + .probe =3D pcap-keys-probe,
> > + .remove =3D pcap-keys-remove,
>=20
>
Re: PATCH - PCAP misc input driver (for 2.6.32) by Dmitry Torokhov on
2009-06-29T06:22:21+00:00
Hi Daniel,
On Sat, Jun 27, 2009 at 02:09:52PM -0300, Daniel Ribeiro wrote:
> This is a driver for misc input events for the PCAP2 PMIC, it handles
> the power button, headphone insertion/removal and the headphone button.
>
> Signed-off-by: Ilya Petrov <ilya.muromec@gmail.com>
> Signed-off-by: Daniel Ribeiro <drwyrm@gmail.com>
>
> -First of all I think the driver should live in misc, not in keyboard,
since it is not a full-fledged keyboard.
> diff >
> +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...
> endif
> diff > obj-$(CONFIG-KEYBOARD-EP93XX) += ep93xx-keypad.o
> +obj-$(CONFIG-KEYBOARD-PCAP) += pcap-keys.o
> diff > + * Input driver for PCAP events:
> + * * Power key
> + * * Jack plug/unplug
> + * * Headphone button
> + *
> + * Copyright (c) 2008,2009 Ilya Petrov <ilya.muromec@gmail.com>
> + *
> + * 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;
> +
> + 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?
> + break;
> + }
> +
> + input-sync(pcap-keys->input);
> +
> + return IRQ-HANDLED;
> +}
> +
> +static int > +
> + 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;
> +
> + 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).
> +
> + 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);
> +
> + 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);
> +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)
> + free-irq(pcap-to-irq(pcap-keys->pcap, PCAP-IRQ-MIC), pcap-keys);
> +
> + 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,
> +
> +static int > + 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 <ilya.muromec@gmail.com>");
> +MODULE-LICENSE("GPL");
Do we need MODULE-ALIAS() here?
Thanks!
Re: PATCH - PCAP misc input driver (for 2.6.32) by Mark Brown on
2009-06-29T09:47:24+00:00
On Sat, Jun 27, 2009 at 02:09:52PM -0300, Daniel Ribeiro wrote:
> 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.
Re: PATCH - PCAP misc input driver (for 2.6.32) by Ilya Petrov on
2009-06-29T16:27:58+00:00
2009/6/29 Mark Brown <broonie@opensource.wolfsonmicro.com>:
> 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.
Please read the FAQ at http://www.tux.org/lkml/
Re: PATCH - PCAP misc input driver (for 2.6.32) by Mark Brown on
2009-06-29T16:33:44+00:00
On Mon, Jun 29, 2009 at 07:27:24PM +0300, Ilya Petrov wrote:
> 2009/6/29 Mark Brown <broonie@opensource.wolfsonmicro.com>:
> > 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.
Re: PATCH - PCAP misc input driver (for 2.6.32) by Daniel Ribeiro on
2009-06-29T20:47:41+00:00
Em Dom, 2009-06-28 =C3=A0s 23:14 -0700, Dmitry Torokhov escreveu:
> > drivers/input/keyboard/Kconfig | 7 ++
> > drivers/input/keyboard/Makefile | 1 +
> > drivers/input/keyboard/pcap-keys.c | 152 ++++++++++++++++++++++++++++=
++++++++
> > 3 files changed, 160 insertions(+), 0 deletions(-)
> >=20
>=20
> First of all I think the driver should live in misc, not in keyboard,
> since it is not a full-fledged keyboard.
Ok.
> > + Say Y here if you want to use power key and jack events
> > + on Motorola EZX 2nd generation phones
> > +
>=20
> To compile this driver as a module...
Ok.
> > + case PCAP-IRQ-MIC:
> > + input-report-key(pcap-keys->input, KEY-HP, !pstat);
>=20
> 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.
> > +static int > > + pcap-keys->input->phys =3D "pcap-keys/input0";
> > + pcap-keys->input->dev.parent =3D &pdev->dev;
>=20
> 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.
> > + set-bit(KEY-HP, pcap-keys->input->keybit);
>
Ok.
> > + .remove =3D pcap-keys-remove,
>=20
> >=20
> Do we need MODULE-ALIAS() here?
Do we? I think we don't, but well... It costs nothing. ;)