All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] mc13783: add pwr button support
@ 2010-05-31 19:28 ` Philippe Rétornaz
  0 siblings, 0 replies; 20+ messages in thread
From: Philippe Rétornaz @ 2010-05-31 19:28 UTC (permalink / raw)
  To: s.hauer
  Cc: linux-input, broonie, sameo, dmitry.torokhov, valentin.longchamp,
	ext-jari.vanhala, u.kleine-koenig, Philippe Rétornaz,
	linux-arm-kernel

Hello

This add button handling for the MC13783 PMIC.
The first patch modify the mc13783 MFD driver to add a button 
subdevice and also adds the mc13783-pwrbutton driver using a misc
input device.

The second patch adds the power on button support to the mx31moboard
boards.

Regards,
Philippe


Philippe Rétornaz (2):
  mc13783: add power button support
  mx31moboard: Add MC13783 power button support

 arch/arm/mach-mx3/mach-mx31moboard.c   |   10 +-
 drivers/input/misc/Kconfig             |    7 +
 drivers/input/misc/Makefile            |    1 +
 drivers/input/misc/mc13783-pwrbutton.c |  301 ++++++++++++++++++++++++++++++++
 drivers/mfd/mc13783-core.c             |    4 +
 include/linux/mfd/mc13783.h            |   19 ++
 6 files changed, 341 insertions(+), 1 deletions(-)
 create mode 100644 drivers/input/misc/mc13783-pwrbutton.c


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 0/2] mc13783: add pwr button support
@ 2010-05-31 19:28 ` Philippe Rétornaz
  0 siblings, 0 replies; 20+ messages in thread
From: Philippe Rétornaz @ 2010-05-31 19:28 UTC (permalink / raw)
  To: linux-arm-kernel

Hello

This add button handling for the MC13783 PMIC.
The first patch modify the mc13783 MFD driver to add a button 
subdevice and also adds the mc13783-pwrbutton driver using a misc
input device.

The second patch adds the power on button support to the mx31moboard
boards.

Regards,
Philippe


Philippe R?tornaz (2):
  mc13783: add power button support
  mx31moboard: Add MC13783 power button support

 arch/arm/mach-mx3/mach-mx31moboard.c   |   10 +-
 drivers/input/misc/Kconfig             |    7 +
 drivers/input/misc/Makefile            |    1 +
 drivers/input/misc/mc13783-pwrbutton.c |  301 ++++++++++++++++++++++++++++++++
 drivers/mfd/mc13783-core.c             |    4 +
 include/linux/mfd/mc13783.h            |   19 ++
 6 files changed, 341 insertions(+), 1 deletions(-)
 create mode 100644 drivers/input/misc/mc13783-pwrbutton.c

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 1/2] mc13783: add power button support
  2010-05-31 19:28 ` Philippe Rétornaz
@ 2010-05-31 19:28   ` Philippe Rétornaz
  -1 siblings, 0 replies; 20+ messages in thread
From: Philippe Rétornaz @ 2010-05-31 19:28 UTC (permalink / raw)
  To: s.hauer
  Cc: linux-input, broonie, sameo, dmitry.torokhov, valentin.longchamp,
	ext-jari.vanhala, u.kleine-koenig, Philippe Rétornaz,
	linux-arm-kernel

This adds support for the power-on buttons of MC13783 PMIC.
This is done using a misc input device.

Signed-off-by: Philippe Rétornaz <philippe.retornaz@epfl.ch>
---
 drivers/input/misc/Kconfig             |    7 +
 drivers/input/misc/Makefile            |    1 +
 drivers/input/misc/mc13783-pwrbutton.c |  301 ++++++++++++++++++++++++++++++++
 drivers/mfd/mc13783-core.c             |    4 +
 include/linux/mfd/mc13783.h            |   19 ++
 5 files changed, 332 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/misc/mc13783-pwrbutton.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 23140a3..2d25b16 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -340,4 +340,11 @@ config INPUT_PCAP
 	  To compile this driver as a module, choose M here: the
 	  module will be called pcap_keys.
 
+config INPUT_MC13783_ON
+	tristate "MC13783 ON buttons"
+	depends on MFD_MC13783
+	help
+	  Support the ON buttons of MC13783 PMIC as an input device
+	  reporting power button status.
+
 endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 7e95a5d..c96311d 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -32,4 +32,5 @@ obj-$(CONFIG_INPUT_WINBOND_CIR)		+= winbond-cir.o
 obj-$(CONFIG_INPUT_WISTRON_BTNS)	+= wistron_btns.o
 obj-$(CONFIG_INPUT_WM831X_ON)		+= wm831x-on.o
 obj-$(CONFIG_INPUT_YEALINK)		+= yealink.o
+obj-$(CONFIG_INPUT_MC13783_ON)		+= mc13783-pwrbutton.o
 
diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
new file mode 100644
index 0000000..61cfcce
--- /dev/null
+++ b/drivers/input/misc/mc13783-pwrbutton.c
@@ -0,0 +1,301 @@
+/**
+ * mc13783-pwrbutton.c - MC13783 Power Button Input Driver
+ *
+ * Copyright (C) 2010 Philippe Rétornaz
+ *
+ * Based on twl4030-pwrbutton driver by:
+ *	Peter De Schrijver <peter.de-schrijver@nokia.com>
+ *	Felipe Balbi <felipe.balbi@nokia.com>
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file "COPYING" in the main directory of this
+ * archive for more details.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/mfd/mc13783.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+
+struct mc13783_pwrb {
+	struct input_dev *pwr;
+	struct mc13783 *mc13783;
+#define MC13783_PWRB_B1_EMULATE_CAD	(1 << 0)
+#define MC13783_PWRB_B2_EMULATE_CAD	(1 << 1)
+#define MC13783_PWRB_B3_EMULATE_CAD	(1 << 2)
+#define MC13783_PWRB_B1_POL_INVERT	(1 << 3)
+#define MC13783_PWRB_B2_POL_INVERT	(1 << 4)
+#define MC13783_PWRB_B3_POL_INVERT	(1 << 5)
+	int flags;
+	unsigned int b1on_key;
+	unsigned int b2on_key;
+	unsigned int b3on_key;
+};
+
+#define MC13783_REG_INTERRUPT_SENSE_1		5
+#define MC13783_IRQSENSE1_ONOFD1S		(1 << 3)
+#define MC13783_IRQSENSE1_ONOFD2S		(1 << 4)
+#define MC13783_IRQSENSE1_ONOFD3S		(1 << 5)
+
+#define MC13783_REG_POWER_CONTROL_2		15
+#define MC13783_POWER_CONTROL_2_ON1BDBNC	4
+#define MC13783_POWER_CONTROL_2_ON2BDBNC	6
+#define MC13783_POWER_CONTROL_2_ON3BDBNC	8
+#define MC13783_POWER_CONTROL_2_ON1BRSTEN	(1 << 1)
+#define MC13783_POWER_CONTROL_2_ON2BRSTEN	(1 << 2)
+#define MC13783_POWER_CONTROL_2_ON3BRSTEN	(1 << 3)
+
+static irqreturn_t b1on_irq(int irq, void *_priv)
+{
+	struct mc13783_pwrb *priv = _priv;
+	int val;
+
+	mc13783_irq_ack(priv->mc13783, irq);
+	mc13783_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
+
+	val = val & MC13783_IRQSENSE1_ONOFD1S ? 1 : 0;
+
+	if (priv->flags & MC13783_PWRB_B1_POL_INVERT)
+		val ^= 1;
+
+	if (val && priv->flags & MC13783_PWRB_B1_EMULATE_CAD)
+		kill_cad_pid(SIGINT, 1);
+
+	input_report_key(priv->pwr, priv->b1on_key, val);
+	input_sync(priv->pwr);
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t b2on_irq(int irq, void *_priv)
+{
+	struct mc13783_pwrb *priv = _priv;
+	int val;
+
+	mc13783_irq_ack(priv->mc13783, irq);
+	mc13783_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
+
+	val = val & MC13783_IRQSENSE1_ONOFD2S ? 1 : 0;
+
+	if (priv->flags & MC13783_PWRB_B2_POL_INVERT)
+		val ^= 1;
+
+	if (val && priv->flags & MC13783_PWRB_B2_EMULATE_CAD)
+		kill_cad_pid(SIGINT, 1);
+
+	input_report_key(priv->pwr, priv->b2on_key, val);
+	input_sync(priv->pwr);
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t b3on_irq(int irq, void *_priv)
+{
+	struct mc13783_pwrb *priv = _priv;
+	int val;
+
+	mc13783_irq_ack(priv->mc13783, irq);
+	mc13783_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
+
+	val = val & MC13783_IRQSENSE1_ONOFD3S ? 1 : 0;
+
+	if (priv->flags & MC13783_PWRB_B3_POL_INVERT)
+		val ^= 1;
+
+	if (val && priv->flags & MC13783_PWRB_B3_EMULATE_CAD)
+		kill_cad_pid(SIGINT, 1);
+
+	input_report_key(priv->pwr, priv->b3on_key, val);
+	input_sync(priv->pwr);
+	return IRQ_HANDLED;
+}
+
+static int __devinit mc13783_pwrbutton_probe(struct platform_device *pdev)
+{
+	struct mc13783_buttons_platform_data *pdata;
+	struct mc13783 *mc13783 = dev_get_drvdata(pdev->dev.parent);
+	struct input_dev *pwr;
+	struct mc13783_pwrb *priv;
+	int err = 0;
+	int reg = 0;
+
+	pdata = dev_get_platdata(&pdev->dev);
+	if (pdata == NULL) {
+		dev_err(&pdev->dev, "missing platform data\n");
+		return -ENODEV;
+	}
+
+	pwr = input_allocate_device();
+	if (!pwr) {
+		dev_dbg(&pdev->dev, "Can't allocate power button\n");
+		return -ENOMEM;
+	}
+
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+
+	if (!priv) {
+		dev_dbg(&pdev->dev, "Can't allocate power button\n");
+		goto free_input_dev;
+	}
+
+	pwr->evbit[0] = BIT_MASK(EV_KEY);
+
+	reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
+	reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
+	reg |= (pdata->b3on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC;
+
+	priv->pwr = pwr;
+	priv->mc13783 = mc13783;
+
+	mc13783_lock(mc13783);
+
+	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) {
+		priv->b1on_key = pdata->b1on_key;
+		if (pdata->b1on_key != KEY_RESERVED)
+			pwr->keybit[BIT_WORD(pdata->b1on_key)] |=
+						BIT_MASK(pdata->b1on_key);
+
+		if (pdata->b1on_flags & MC13783_BUTTON_POL_INVERT)
+			priv->flags |= MC13783_PWRB_B1_POL_INVERT;
+		if (pdata->b1on_flags & MC13783_BUTTON_EMUL_CAD)
+			priv->flags |= MC13783_PWRB_B1_EMULATE_CAD;
+
+		if (pdata->b1on_flags & MC13783_BUTTON_RESET_EN)
+			reg |= MC13783_POWER_CONTROL_2_ON1BRSTEN;
+
+		mc13783_irq_request(mc13783, MC13783_IRQ_ONOFD1, b1on_irq,
+							"b1on", priv);
+	}
+
+	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) {
+		priv->b2on_key = pdata->b2on_key;
+		if (pdata->b2on_key != KEY_RESERVED)
+			pwr->keybit[BIT_WORD(pdata->b2on_key)] |=
+						BIT_MASK(pdata->b2on_key);
+
+		if (pdata->b2on_flags & MC13783_BUTTON_POL_INVERT)
+			priv->flags |= MC13783_PWRB_B2_POL_INVERT;
+		if (pdata->b2on_flags & MC13783_BUTTON_EMUL_CAD)
+			priv->flags |= MC13783_PWRB_B2_EMULATE_CAD;
+
+		if (pdata->b2on_flags & MC13783_BUTTON_RESET_EN)
+			reg |= MC13783_POWER_CONTROL_2_ON2BRSTEN;
+
+		mc13783_irq_request(mc13783, MC13783_IRQ_ONOFD2, b2on_irq,
+							"b2on", priv);
+	}
+
+	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) {
+		priv->b3on_key = pdata->b3on_key;
+		if (pdata->b3on_key != KEY_RESERVED)
+			pwr->keybit[BIT_WORD(pdata->b3on_key)] |=
+						BIT_MASK(pdata->b3on_key);
+
+		if (pdata->b3on_flags & MC13783_BUTTON_POL_INVERT)
+			priv->flags |= MC13783_PWRB_B3_POL_INVERT;
+		if (pdata->b3on_flags & MC13783_BUTTON_EMUL_CAD)
+			priv->flags |= MC13783_PWRB_B3_EMULATE_CAD;
+
+		if (pdata->b3on_flags & MC13783_BUTTON_RESET_EN)
+			reg |= MC13783_POWER_CONTROL_2_ON3BRSTEN;
+
+		mc13783_irq_request(mc13783, MC13783_IRQ_ONOFD3, b3on_irq,
+							"b3on", priv);
+	}
+
+	mc13783_reg_rmw(mc13783, MC13783_REG_POWER_CONTROL_2, 0x3FE, reg);
+
+	mc13783_unlock(mc13783);
+
+	pwr->name = "mc13783_pwrbutton";
+	pwr->phys = "mc13783_pwrbutton/input0";
+	pwr->dev.parent = &pdev->dev;
+
+	err = input_register_device(pwr);
+	if (err) {
+		dev_dbg(&pdev->dev, "Can't register power button: %d\n", err);
+		goto free_irq;
+	}
+
+	platform_set_drvdata(pdev, priv);
+
+	return 0;
+
+free_irq:
+	mc13783_lock(mc13783);
+	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
+		mc13783_irq_free(mc13783, MC13783_IRQ_ONOFD3, priv);
+	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
+		mc13783_irq_free(mc13783, MC13783_IRQ_ONOFD2, priv);
+	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
+		mc13783_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);
+	mc13783_unlock(mc13783);
+
+	kfree(priv);
+
+free_input_dev:
+	input_free_device(pwr);
+	return err;
+}
+
+static int __devexit mc13783_pwrbutton_remove(struct platform_device *pdev)
+{
+	struct mc13783_pwrb *priv = platform_get_drvdata(pdev);
+	struct mc13783_buttons_platform_data *pdata;
+	pdata = dev_get_platdata(&pdev->dev);
+
+	mc13783_lock(priv->mc13783);
+	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
+		mc13783_irq_free(priv->mc13783, MC13783_IRQ_ONOFD3, priv);
+	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
+		mc13783_irq_free(priv->mc13783, MC13783_IRQ_ONOFD2, priv);
+	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
+		mc13783_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv);
+	mc13783_unlock(priv->mc13783);
+
+	input_unregister_device(priv->pwr);
+
+	kfree(priv);
+
+	return 0;
+}
+
+struct platform_driver mc13783_pwrbutton_driver = {
+	.probe		= mc13783_pwrbutton_probe,
+	.remove		= __devexit_p(mc13783_pwrbutton_remove),
+	.driver		= {
+		.name	= "mc13783-pwrbutton",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init mc13783_pwrbutton_init(void)
+{
+	return platform_driver_register(&mc13783_pwrbutton_driver);
+}
+module_init(mc13783_pwrbutton_init);
+
+static void __exit mc13783_pwrbutton_exit(void)
+{
+	platform_driver_unregister(&mc13783_pwrbutton_driver);
+}
+module_exit(mc13783_pwrbutton_exit);
+
+MODULE_ALIAS("platform:mc13783-pwrbutton");
+MODULE_DESCRIPTION("MC13783 Power Button");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Philippe Retornaz");
+
diff --git a/drivers/mfd/mc13783-core.c b/drivers/mfd/mc13783-core.c
index fecf38a..fb3e98b 100644
--- a/drivers/mfd/mc13783-core.c
+++ b/drivers/mfd/mc13783-core.c
@@ -683,6 +683,10 @@ err_revision:
 		mc13783_add_subdevice_pdata(mc13783, "mc13783-led",
 					pdata->leds, sizeof(*pdata->leds));
 
+	if (pdata->flags & MC13783_USE_BUTTON)
+		mc13783_add_subdevice_pdata(mc13783, "mc13783-pwrbutton",
+				pdata->buttons, sizeof(*pdata->buttons));
+
 	return 0;
 }
 
diff --git a/include/linux/mfd/mc13783.h b/include/linux/mfd/mc13783.h
index 4a894f6..66981a5 100644
--- a/include/linux/mfd/mc13783.h
+++ b/include/linux/mfd/mc13783.h
@@ -128,6 +128,23 @@ struct mc13783_leds_platform_data {
 	char tc3_period;
 };
 
+struct mc13783_buttons_platform_data {
+#define MC13783_BUTTON_DBNC_0MS		0
+#define MC13783_BUTTON_DBNC_30MS	1
+#define MC13783_BUTTON_DBNC_150MS	2
+#define MC13783_BUTTON_DBNC_750MS	3
+#define MC13783_BUTTON_ENABLE		(1 << 2)
+#define MC13783_BUTTON_POL_INVERT	(1 << 3)
+#define MC13783_BUTTON_RESET_EN		(1 << 4)
+#define MC13783_BUTTON_EMUL_CAD		(1 << 5)
+	int b1on_flags;
+	unsigned int b1on_key;
+	int b2on_flags;
+	unsigned int b2on_key;
+	int b3on_flags;
+	unsigned int b3on_key;
+};
+
 /* to be cleaned up */
 struct regulator_init_data;
 
@@ -145,6 +162,7 @@ struct mc13783_platform_data {
 	int num_regulators;
 	struct mc13783_regulator_init_data *regulators;
 	struct mc13783_leds_platform_data *leds;
+	struct mc13783_buttons_platform_data *buttons;
 
 #define MC13783_USE_TOUCHSCREEN (1 << 0)
 #define MC13783_USE_CODEC	(1 << 1)
@@ -152,6 +170,7 @@ struct mc13783_platform_data {
 #define MC13783_USE_RTC		(1 << 3)
 #define MC13783_USE_REGULATOR	(1 << 4)
 #define MC13783_USE_LED		(1 << 5)
+#define MC13783_USE_BUTTON	(1 << 6)
 	unsigned int flags;
 };
 
-- 
1.6.3.3


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 1/2] mc13783: add power button support
@ 2010-05-31 19:28   ` Philippe Rétornaz
  0 siblings, 0 replies; 20+ messages in thread
From: Philippe Rétornaz @ 2010-05-31 19:28 UTC (permalink / raw)
  To: linux-arm-kernel

This adds support for the power-on buttons of MC13783 PMIC.
This is done using a misc input device.

Signed-off-by: Philippe R?tornaz <philippe.retornaz@epfl.ch>
---
 drivers/input/misc/Kconfig             |    7 +
 drivers/input/misc/Makefile            |    1 +
 drivers/input/misc/mc13783-pwrbutton.c |  301 ++++++++++++++++++++++++++++++++
 drivers/mfd/mc13783-core.c             |    4 +
 include/linux/mfd/mc13783.h            |   19 ++
 5 files changed, 332 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/misc/mc13783-pwrbutton.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 23140a3..2d25b16 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -340,4 +340,11 @@ config INPUT_PCAP
 	  To compile this driver as a module, choose M here: the
 	  module will be called pcap_keys.
 
+config INPUT_MC13783_ON
+	tristate "MC13783 ON buttons"
+	depends on MFD_MC13783
+	help
+	  Support the ON buttons of MC13783 PMIC as an input device
+	  reporting power button status.
+
 endif
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 7e95a5d..c96311d 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -32,4 +32,5 @@ obj-$(CONFIG_INPUT_WINBOND_CIR)		+= winbond-cir.o
 obj-$(CONFIG_INPUT_WISTRON_BTNS)	+= wistron_btns.o
 obj-$(CONFIG_INPUT_WM831X_ON)		+= wm831x-on.o
 obj-$(CONFIG_INPUT_YEALINK)		+= yealink.o
+obj-$(CONFIG_INPUT_MC13783_ON)		+= mc13783-pwrbutton.o
 
diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
new file mode 100644
index 0000000..61cfcce
--- /dev/null
+++ b/drivers/input/misc/mc13783-pwrbutton.c
@@ -0,0 +1,301 @@
+/**
+ * mc13783-pwrbutton.c - MC13783 Power Button Input Driver
+ *
+ * Copyright (C) 2010 Philippe R?tornaz
+ *
+ * Based on twl4030-pwrbutton driver by:
+ *	Peter De Schrijver <peter.de-schrijver@nokia.com>
+ *	Felipe Balbi <felipe.balbi@nokia.com>
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file "COPYING" in the main directory of this
+ * archive for more details.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/mfd/mc13783.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+
+struct mc13783_pwrb {
+	struct input_dev *pwr;
+	struct mc13783 *mc13783;
+#define MC13783_PWRB_B1_EMULATE_CAD	(1 << 0)
+#define MC13783_PWRB_B2_EMULATE_CAD	(1 << 1)
+#define MC13783_PWRB_B3_EMULATE_CAD	(1 << 2)
+#define MC13783_PWRB_B1_POL_INVERT	(1 << 3)
+#define MC13783_PWRB_B2_POL_INVERT	(1 << 4)
+#define MC13783_PWRB_B3_POL_INVERT	(1 << 5)
+	int flags;
+	unsigned int b1on_key;
+	unsigned int b2on_key;
+	unsigned int b3on_key;
+};
+
+#define MC13783_REG_INTERRUPT_SENSE_1		5
+#define MC13783_IRQSENSE1_ONOFD1S		(1 << 3)
+#define MC13783_IRQSENSE1_ONOFD2S		(1 << 4)
+#define MC13783_IRQSENSE1_ONOFD3S		(1 << 5)
+
+#define MC13783_REG_POWER_CONTROL_2		15
+#define MC13783_POWER_CONTROL_2_ON1BDBNC	4
+#define MC13783_POWER_CONTROL_2_ON2BDBNC	6
+#define MC13783_POWER_CONTROL_2_ON3BDBNC	8
+#define MC13783_POWER_CONTROL_2_ON1BRSTEN	(1 << 1)
+#define MC13783_POWER_CONTROL_2_ON2BRSTEN	(1 << 2)
+#define MC13783_POWER_CONTROL_2_ON3BRSTEN	(1 << 3)
+
+static irqreturn_t b1on_irq(int irq, void *_priv)
+{
+	struct mc13783_pwrb *priv = _priv;
+	int val;
+
+	mc13783_irq_ack(priv->mc13783, irq);
+	mc13783_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
+
+	val = val & MC13783_IRQSENSE1_ONOFD1S ? 1 : 0;
+
+	if (priv->flags & MC13783_PWRB_B1_POL_INVERT)
+		val ^= 1;
+
+	if (val && priv->flags & MC13783_PWRB_B1_EMULATE_CAD)
+		kill_cad_pid(SIGINT, 1);
+
+	input_report_key(priv->pwr, priv->b1on_key, val);
+	input_sync(priv->pwr);
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t b2on_irq(int irq, void *_priv)
+{
+	struct mc13783_pwrb *priv = _priv;
+	int val;
+
+	mc13783_irq_ack(priv->mc13783, irq);
+	mc13783_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
+
+	val = val & MC13783_IRQSENSE1_ONOFD2S ? 1 : 0;
+
+	if (priv->flags & MC13783_PWRB_B2_POL_INVERT)
+		val ^= 1;
+
+	if (val && priv->flags & MC13783_PWRB_B2_EMULATE_CAD)
+		kill_cad_pid(SIGINT, 1);
+
+	input_report_key(priv->pwr, priv->b2on_key, val);
+	input_sync(priv->pwr);
+	return IRQ_HANDLED;
+}
+
+static irqreturn_t b3on_irq(int irq, void *_priv)
+{
+	struct mc13783_pwrb *priv = _priv;
+	int val;
+
+	mc13783_irq_ack(priv->mc13783, irq);
+	mc13783_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
+
+	val = val & MC13783_IRQSENSE1_ONOFD3S ? 1 : 0;
+
+	if (priv->flags & MC13783_PWRB_B3_POL_INVERT)
+		val ^= 1;
+
+	if (val && priv->flags & MC13783_PWRB_B3_EMULATE_CAD)
+		kill_cad_pid(SIGINT, 1);
+
+	input_report_key(priv->pwr, priv->b3on_key, val);
+	input_sync(priv->pwr);
+	return IRQ_HANDLED;
+}
+
+static int __devinit mc13783_pwrbutton_probe(struct platform_device *pdev)
+{
+	struct mc13783_buttons_platform_data *pdata;
+	struct mc13783 *mc13783 = dev_get_drvdata(pdev->dev.parent);
+	struct input_dev *pwr;
+	struct mc13783_pwrb *priv;
+	int err = 0;
+	int reg = 0;
+
+	pdata = dev_get_platdata(&pdev->dev);
+	if (pdata == NULL) {
+		dev_err(&pdev->dev, "missing platform data\n");
+		return -ENODEV;
+	}
+
+	pwr = input_allocate_device();
+	if (!pwr) {
+		dev_dbg(&pdev->dev, "Can't allocate power button\n");
+		return -ENOMEM;
+	}
+
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+
+	if (!priv) {
+		dev_dbg(&pdev->dev, "Can't allocate power button\n");
+		goto free_input_dev;
+	}
+
+	pwr->evbit[0] = BIT_MASK(EV_KEY);
+
+	reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
+	reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
+	reg |= (pdata->b3on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC;
+
+	priv->pwr = pwr;
+	priv->mc13783 = mc13783;
+
+	mc13783_lock(mc13783);
+
+	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) {
+		priv->b1on_key = pdata->b1on_key;
+		if (pdata->b1on_key != KEY_RESERVED)
+			pwr->keybit[BIT_WORD(pdata->b1on_key)] |=
+						BIT_MASK(pdata->b1on_key);
+
+		if (pdata->b1on_flags & MC13783_BUTTON_POL_INVERT)
+			priv->flags |= MC13783_PWRB_B1_POL_INVERT;
+		if (pdata->b1on_flags & MC13783_BUTTON_EMUL_CAD)
+			priv->flags |= MC13783_PWRB_B1_EMULATE_CAD;
+
+		if (pdata->b1on_flags & MC13783_BUTTON_RESET_EN)
+			reg |= MC13783_POWER_CONTROL_2_ON1BRSTEN;
+
+		mc13783_irq_request(mc13783, MC13783_IRQ_ONOFD1, b1on_irq,
+							"b1on", priv);
+	}
+
+	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) {
+		priv->b2on_key = pdata->b2on_key;
+		if (pdata->b2on_key != KEY_RESERVED)
+			pwr->keybit[BIT_WORD(pdata->b2on_key)] |=
+						BIT_MASK(pdata->b2on_key);
+
+		if (pdata->b2on_flags & MC13783_BUTTON_POL_INVERT)
+			priv->flags |= MC13783_PWRB_B2_POL_INVERT;
+		if (pdata->b2on_flags & MC13783_BUTTON_EMUL_CAD)
+			priv->flags |= MC13783_PWRB_B2_EMULATE_CAD;
+
+		if (pdata->b2on_flags & MC13783_BUTTON_RESET_EN)
+			reg |= MC13783_POWER_CONTROL_2_ON2BRSTEN;
+
+		mc13783_irq_request(mc13783, MC13783_IRQ_ONOFD2, b2on_irq,
+							"b2on", priv);
+	}
+
+	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) {
+		priv->b3on_key = pdata->b3on_key;
+		if (pdata->b3on_key != KEY_RESERVED)
+			pwr->keybit[BIT_WORD(pdata->b3on_key)] |=
+						BIT_MASK(pdata->b3on_key);
+
+		if (pdata->b3on_flags & MC13783_BUTTON_POL_INVERT)
+			priv->flags |= MC13783_PWRB_B3_POL_INVERT;
+		if (pdata->b3on_flags & MC13783_BUTTON_EMUL_CAD)
+			priv->flags |= MC13783_PWRB_B3_EMULATE_CAD;
+
+		if (pdata->b3on_flags & MC13783_BUTTON_RESET_EN)
+			reg |= MC13783_POWER_CONTROL_2_ON3BRSTEN;
+
+		mc13783_irq_request(mc13783, MC13783_IRQ_ONOFD3, b3on_irq,
+							"b3on", priv);
+	}
+
+	mc13783_reg_rmw(mc13783, MC13783_REG_POWER_CONTROL_2, 0x3FE, reg);
+
+	mc13783_unlock(mc13783);
+
+	pwr->name = "mc13783_pwrbutton";
+	pwr->phys = "mc13783_pwrbutton/input0";
+	pwr->dev.parent = &pdev->dev;
+
+	err = input_register_device(pwr);
+	if (err) {
+		dev_dbg(&pdev->dev, "Can't register power button: %d\n", err);
+		goto free_irq;
+	}
+
+	platform_set_drvdata(pdev, priv);
+
+	return 0;
+
+free_irq:
+	mc13783_lock(mc13783);
+	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
+		mc13783_irq_free(mc13783, MC13783_IRQ_ONOFD3, priv);
+	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
+		mc13783_irq_free(mc13783, MC13783_IRQ_ONOFD2, priv);
+	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
+		mc13783_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);
+	mc13783_unlock(mc13783);
+
+	kfree(priv);
+
+free_input_dev:
+	input_free_device(pwr);
+	return err;
+}
+
+static int __devexit mc13783_pwrbutton_remove(struct platform_device *pdev)
+{
+	struct mc13783_pwrb *priv = platform_get_drvdata(pdev);
+	struct mc13783_buttons_platform_data *pdata;
+	pdata = dev_get_platdata(&pdev->dev);
+
+	mc13783_lock(priv->mc13783);
+	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
+		mc13783_irq_free(priv->mc13783, MC13783_IRQ_ONOFD3, priv);
+	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
+		mc13783_irq_free(priv->mc13783, MC13783_IRQ_ONOFD2, priv);
+	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
+		mc13783_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv);
+	mc13783_unlock(priv->mc13783);
+
+	input_unregister_device(priv->pwr);
+
+	kfree(priv);
+
+	return 0;
+}
+
+struct platform_driver mc13783_pwrbutton_driver = {
+	.probe		= mc13783_pwrbutton_probe,
+	.remove		= __devexit_p(mc13783_pwrbutton_remove),
+	.driver		= {
+		.name	= "mc13783-pwrbutton",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init mc13783_pwrbutton_init(void)
+{
+	return platform_driver_register(&mc13783_pwrbutton_driver);
+}
+module_init(mc13783_pwrbutton_init);
+
+static void __exit mc13783_pwrbutton_exit(void)
+{
+	platform_driver_unregister(&mc13783_pwrbutton_driver);
+}
+module_exit(mc13783_pwrbutton_exit);
+
+MODULE_ALIAS("platform:mc13783-pwrbutton");
+MODULE_DESCRIPTION("MC13783 Power Button");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Philippe Retornaz");
+
diff --git a/drivers/mfd/mc13783-core.c b/drivers/mfd/mc13783-core.c
index fecf38a..fb3e98b 100644
--- a/drivers/mfd/mc13783-core.c
+++ b/drivers/mfd/mc13783-core.c
@@ -683,6 +683,10 @@ err_revision:
 		mc13783_add_subdevice_pdata(mc13783, "mc13783-led",
 					pdata->leds, sizeof(*pdata->leds));
 
+	if (pdata->flags & MC13783_USE_BUTTON)
+		mc13783_add_subdevice_pdata(mc13783, "mc13783-pwrbutton",
+				pdata->buttons, sizeof(*pdata->buttons));
+
 	return 0;
 }
 
diff --git a/include/linux/mfd/mc13783.h b/include/linux/mfd/mc13783.h
index 4a894f6..66981a5 100644
--- a/include/linux/mfd/mc13783.h
+++ b/include/linux/mfd/mc13783.h
@@ -128,6 +128,23 @@ struct mc13783_leds_platform_data {
 	char tc3_period;
 };
 
+struct mc13783_buttons_platform_data {
+#define MC13783_BUTTON_DBNC_0MS		0
+#define MC13783_BUTTON_DBNC_30MS	1
+#define MC13783_BUTTON_DBNC_150MS	2
+#define MC13783_BUTTON_DBNC_750MS	3
+#define MC13783_BUTTON_ENABLE		(1 << 2)
+#define MC13783_BUTTON_POL_INVERT	(1 << 3)
+#define MC13783_BUTTON_RESET_EN		(1 << 4)
+#define MC13783_BUTTON_EMUL_CAD		(1 << 5)
+	int b1on_flags;
+	unsigned int b1on_key;
+	int b2on_flags;
+	unsigned int b2on_key;
+	int b3on_flags;
+	unsigned int b3on_key;
+};
+
 /* to be cleaned up */
 struct regulator_init_data;
 
@@ -145,6 +162,7 @@ struct mc13783_platform_data {
 	int num_regulators;
 	struct mc13783_regulator_init_data *regulators;
 	struct mc13783_leds_platform_data *leds;
+	struct mc13783_buttons_platform_data *buttons;
 
 #define MC13783_USE_TOUCHSCREEN (1 << 0)
 #define MC13783_USE_CODEC	(1 << 1)
@@ -152,6 +170,7 @@ struct mc13783_platform_data {
 #define MC13783_USE_RTC		(1 << 3)
 #define MC13783_USE_REGULATOR	(1 << 4)
 #define MC13783_USE_LED		(1 << 5)
+#define MC13783_USE_BUTTON	(1 << 6)
 	unsigned int flags;
 };
 
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 2/2] mx31moboard: Add MC13783 power button support
  2010-05-31 19:28   ` Philippe Rétornaz
@ 2010-05-31 19:29     ` Philippe Rétornaz
  -1 siblings, 0 replies; 20+ messages in thread
From: Philippe Rétornaz @ 2010-05-31 19:29 UTC (permalink / raw)
  To: s.hauer
  Cc: linux-input, broonie, sameo, dmitry.torokhov, valentin.longchamp,
	ext-jari.vanhala, u.kleine-koenig, Philippe Rétornaz,
	linux-arm-kernel

Add the power-on button on mx31moboard using MC13783 PMIC.

Signed-off-by: Philippe Rétornaz <philippe.retornaz@epfl.ch>
---
 arch/arm/mach-mx3/mach-mx31moboard.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/arch/arm/mach-mx3/mach-mx31moboard.c b/arch/arm/mach-mx3/mach-mx31moboard.c
index 62b5e40..7a8f078 100644
--- a/arch/arm/mach-mx3/mach-mx31moboard.c
+++ b/arch/arm/mach-mx3/mach-mx31moboard.c
@@ -31,6 +31,7 @@
 #include <linux/mfd/mc13783.h>
 #include <linux/spi/spi.h>
 #include <linux/types.h>
+#include <linux/input.h>
 
 #include <linux/usb/otg.h>
 #include <linux/usb/ulpi.h>
@@ -262,12 +263,19 @@ static struct mc13783_leds_platform_data moboard_leds = {
 	.tc2_period = MC13783_LED_PERIOD_10MS,
 };
 
+static struct mc13783_buttons_platform_data moboard_buttons = {
+	.b1on_flags = MC13783_BUTTON_DBNC_750MS | MC13783_BUTTON_ENABLE |
+			MC13783_BUTTON_POL_INVERT | MC13783_BUTTON_EMUL_CAD,
+	.b1on_key = KEY_POWER,
+};
+
 static struct mc13783_platform_data moboard_pmic = {
 	.regulators = moboard_regulators,
 	.num_regulators = ARRAY_SIZE(moboard_regulators),
 	.leds = &moboard_leds,
+	.buttons = &moboard_buttons,
 	.flags = MC13783_USE_REGULATOR | MC13783_USE_RTC |
-		MC13783_USE_ADC | MC13783_USE_LED,
+		MC13783_USE_ADC | MC13783_USE_LED | MC13783_USE_BUTTON,
 };
 
 static struct spi_board_info moboard_spi_board_info[] __initdata = {
-- 
1.6.3.3


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 2/2] mx31moboard: Add MC13783 power button support
@ 2010-05-31 19:29     ` Philippe Rétornaz
  0 siblings, 0 replies; 20+ messages in thread
From: Philippe Rétornaz @ 2010-05-31 19:29 UTC (permalink / raw)
  To: linux-arm-kernel

Add the power-on button on mx31moboard using MC13783 PMIC.

Signed-off-by: Philippe R?tornaz <philippe.retornaz@epfl.ch>
---
 arch/arm/mach-mx3/mach-mx31moboard.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/arch/arm/mach-mx3/mach-mx31moboard.c b/arch/arm/mach-mx3/mach-mx31moboard.c
index 62b5e40..7a8f078 100644
--- a/arch/arm/mach-mx3/mach-mx31moboard.c
+++ b/arch/arm/mach-mx3/mach-mx31moboard.c
@@ -31,6 +31,7 @@
 #include <linux/mfd/mc13783.h>
 #include <linux/spi/spi.h>
 #include <linux/types.h>
+#include <linux/input.h>
 
 #include <linux/usb/otg.h>
 #include <linux/usb/ulpi.h>
@@ -262,12 +263,19 @@ static struct mc13783_leds_platform_data moboard_leds = {
 	.tc2_period = MC13783_LED_PERIOD_10MS,
 };
 
+static struct mc13783_buttons_platform_data moboard_buttons = {
+	.b1on_flags = MC13783_BUTTON_DBNC_750MS | MC13783_BUTTON_ENABLE |
+			MC13783_BUTTON_POL_INVERT | MC13783_BUTTON_EMUL_CAD,
+	.b1on_key = KEY_POWER,
+};
+
 static struct mc13783_platform_data moboard_pmic = {
 	.regulators = moboard_regulators,
 	.num_regulators = ARRAY_SIZE(moboard_regulators),
 	.leds = &moboard_leds,
+	.buttons = &moboard_buttons,
 	.flags = MC13783_USE_REGULATOR | MC13783_USE_RTC |
-		MC13783_USE_ADC | MC13783_USE_LED,
+		MC13783_USE_ADC | MC13783_USE_LED | MC13783_USE_BUTTON,
 };
 
 static struct spi_board_info moboard_spi_board_info[] __initdata = {
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/2] mc13783: add power button support
  2010-05-31 19:28   ` Philippe Rétornaz
@ 2010-06-02  7:52     ` Dmitry Torokhov
  -1 siblings, 0 replies; 20+ messages in thread
From: Dmitry Torokhov @ 2010-06-02  7:52 UTC (permalink / raw)
  To: Philippe Rétornaz
  Cc: s.hauer, linux-arm-kernel, sameo, linux-input, broonie,
	u.kleine-koenig, ext-jari.vanhala, valentin.longchamp

Hi Philippe,

On Mon, May 31, 2010 at 09:28:59PM +0200, Philippe Rétornaz wrote:
> This adds support for the power-on buttons of MC13783 PMIC.
> This is done using a misc input device.
> 
> Signed-off-by: Philippe Rétornaz <philippe.retornaz@epfl.ch>
> ---
>  drivers/input/misc/Kconfig             |    7 +
>  drivers/input/misc/Makefile            |    1 +
>  drivers/input/misc/mc13783-pwrbutton.c |  301 ++++++++++++++++++++++++++++++++
>  drivers/mfd/mc13783-core.c             |    4 +
>  include/linux/mfd/mc13783.h            |   19 ++
>  5 files changed, 332 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/input/misc/mc13783-pwrbutton.c
> 
> diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
> index 23140a3..2d25b16 100644
> --- a/drivers/input/misc/Kconfig
> +++ b/drivers/input/misc/Kconfig
> @@ -340,4 +340,11 @@ config INPUT_PCAP
>  	  To compile this driver as a module, choose M here: the
>  	  module will be called pcap_keys.
>  
> +config INPUT_MC13783_ON
> +	tristate "MC13783 ON buttons"
> +	depends on MFD_MC13783
> +	help
> +	  Support the ON buttons of MC13783 PMIC as an input device
> +	  reporting power button status.
> +

To compile this driver as a module...

>  endif
> diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
> index 7e95a5d..c96311d 100644
> --- a/drivers/input/misc/Makefile
> +++ b/drivers/input/misc/Makefile
> @@ -32,4 +32,5 @@ obj-$(CONFIG_INPUT_WINBOND_CIR)		+= winbond-cir.o
>  obj-$(CONFIG_INPUT_WISTRON_BTNS)	+= wistron_btns.o
>  obj-$(CONFIG_INPUT_WM831X_ON)		+= wm831x-on.o
>  obj-$(CONFIG_INPUT_YEALINK)		+= yealink.o
> +obj-$(CONFIG_INPUT_MC13783_ON)		+= mc13783-pwrbutton.o

Keep makefile sorted please.

>  
> diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
> new file mode 100644
> index 0000000..61cfcce
> --- /dev/null
> +++ b/drivers/input/misc/mc13783-pwrbutton.c
> @@ -0,0 +1,301 @@
> +/**
> + * mc13783-pwrbutton.c - MC13783 Power Button Input Driver
> + *
> + * Copyright (C) 2010 Philippe Rétornaz
> + *
> + * Based on twl4030-pwrbutton driver by:
> + *	Peter De Schrijver <peter.de-schrijver@nokia.com>
> + *	Felipe Balbi <felipe.balbi@nokia.com>
> + *
> + * This file is subject to the terms and conditions of the GNU General
> + * Public License. See the file "COPYING" in the main directory of this
> + * archive for more details.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
> + */
> +
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/errno.h>
> +#include <linux/input.h>
> +#include <linux/interrupt.h>
> +#include <linux/platform_device.h>
> +#include <linux/mfd/mc13783.h>
> +#include <linux/sched.h>
> +#include <linux/slab.h>
> +
> +struct mc13783_pwrb {
> +	struct input_dev *pwr;
> +	struct mc13783 *mc13783;
> +#define MC13783_PWRB_B1_EMULATE_CAD	(1 << 0)
> +#define MC13783_PWRB_B2_EMULATE_CAD	(1 << 1)
> +#define MC13783_PWRB_B3_EMULATE_CAD	(1 << 2)
> +#define MC13783_PWRB_B1_POL_INVERT	(1 << 3)
> +#define MC13783_PWRB_B2_POL_INVERT	(1 << 4)
> +#define MC13783_PWRB_B3_POL_INVERT	(1 << 5)
> +	int flags;
> +	unsigned int b1on_key;
> +	unsigned int b2on_key;
> +	unsigned int b3on_key;

Make it:

	unsigned short keymap[3];

and then do

	input->keycode = pwrb->keymap;
	input->keycodemax = ARRAY_SIZE(pwrb->keymap);
	input->keycodesize = sizeof(pwrb->keymap[0]);

so that keys can be remapped from userspace.

> +};
> +
> +#define MC13783_REG_INTERRUPT_SENSE_1		5
> +#define MC13783_IRQSENSE1_ONOFD1S		(1 << 3)
> +#define MC13783_IRQSENSE1_ONOFD2S		(1 << 4)
> +#define MC13783_IRQSENSE1_ONOFD3S		(1 << 5)
> +
> +#define MC13783_REG_POWER_CONTROL_2		15
> +#define MC13783_POWER_CONTROL_2_ON1BDBNC	4
> +#define MC13783_POWER_CONTROL_2_ON2BDBNC	6
> +#define MC13783_POWER_CONTROL_2_ON3BDBNC	8
> +#define MC13783_POWER_CONTROL_2_ON1BRSTEN	(1 << 1)
> +#define MC13783_POWER_CONTROL_2_ON2BRSTEN	(1 << 2)
> +#define MC13783_POWER_CONTROL_2_ON3BRSTEN	(1 << 3)
> +
> +static irqreturn_t b1on_irq(int irq, void *_priv)
> +{
> +	struct mc13783_pwrb *priv = _priv;
> +	int val;
> +
> +	mc13783_irq_ack(priv->mc13783, irq);
> +	mc13783_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
> +
> +	val = val & MC13783_IRQSENSE1_ONOFD1S ? 1 : 0;
> +
> +	if (priv->flags & MC13783_PWRB_B1_POL_INVERT)
> +		val ^= 1;
> +
> +	if (val && priv->flags & MC13783_PWRB_B1_EMULATE_CAD)
> +		kill_cad_pid(SIGINT, 1);

I do not think that individual input drivers should do this - CAD is
handled by the keyboard driver (drivers/char/keyboard) so it is just a
matter of loading proper keymap for your device.

> +
> +	input_report_key(priv->pwr, priv->b1on_key, val);
> +	input_sync(priv->pwr);
> +	return IRQ_HANDLED;
> +}
> +
> +static irqreturn_t b2on_irq(int irq, void *_priv)
> +{
> +	struct mc13783_pwrb *priv = _priv;
> +	int val;
> +
> +	mc13783_irq_ack(priv->mc13783, irq);
> +	mc13783_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
> +
> +	val = val & MC13783_IRQSENSE1_ONOFD2S ? 1 : 0;
> +
> +	if (priv->flags & MC13783_PWRB_B2_POL_INVERT)
> +		val ^= 1;
> +
> +	if (val && priv->flags & MC13783_PWRB_B2_EMULATE_CAD)
> +		kill_cad_pid(SIGINT, 1);
> +
> +	input_report_key(priv->pwr, priv->b2on_key, val);
> +	input_sync(priv->pwr);
> +	return IRQ_HANDLED;
> +}
> +
> +static irqreturn_t b3on_irq(int irq, void *_priv)
> +{
> +	struct mc13783_pwrb *priv = _priv;
> +	int val;
> +
> +	mc13783_irq_ack(priv->mc13783, irq);
> +	mc13783_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
> +
> +	val = val & MC13783_IRQSENSE1_ONOFD3S ? 1 : 0;
> +
> +	if (priv->flags & MC13783_PWRB_B3_POL_INVERT)
> +		val ^= 1;
> +
> +	if (val && priv->flags & MC13783_PWRB_B3_EMULATE_CAD)
> +		kill_cad_pid(SIGINT, 1);
> +
> +	input_report_key(priv->pwr, priv->b3on_key, val);
> +	input_sync(priv->pwr);
> +	return IRQ_HANDLED;

I am pretty sure these 3 functions can be combined.

> +}
> +
> +static int __devinit mc13783_pwrbutton_probe(struct platform_device *pdev)
> +{
> +	struct mc13783_buttons_platform_data *pdata;
> +	struct mc13783 *mc13783 = dev_get_drvdata(pdev->dev.parent);
> +	struct input_dev *pwr;
> +	struct mc13783_pwrb *priv;
> +	int err = 0;
> +	int reg = 0;
> +
> +	pdata = dev_get_platdata(&pdev->dev);
> +	if (pdata == NULL) {
> +		dev_err(&pdev->dev, "missing platform data\n");
> +		return -ENODEV;
> +	}
> +
> +	pwr = input_allocate_device();
> +	if (!pwr) {
> +		dev_dbg(&pdev->dev, "Can't allocate power button\n");
> +		return -ENOMEM;
> +	}
> +
> +	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> +
> +	if (!priv) {
> +		dev_dbg(&pdev->dev, "Can't allocate power button\n");
> +		goto free_input_dev;
> +	}
> +
> +	pwr->evbit[0] = BIT_MASK(EV_KEY);
> +
> +	reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
> +	reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
> +	reg |= (pdata->b3on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC;
> +
> +	priv->pwr = pwr;
> +	priv->mc13783 = mc13783;
> +
> +	mc13783_lock(mc13783);
> +
> +	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) {
> +		priv->b1on_key = pdata->b1on_key;
> +		if (pdata->b1on_key != KEY_RESERVED)
> +			pwr->keybit[BIT_WORD(pdata->b1on_key)] |=
> +						BIT_MASK(pdata->b1on_key);

Just use __set_bit().

> +
> +		if (pdata->b1on_flags & MC13783_BUTTON_POL_INVERT)
> +			priv->flags |= MC13783_PWRB_B1_POL_INVERT;
> +		if (pdata->b1on_flags & MC13783_BUTTON_EMUL_CAD)
> +			priv->flags |= MC13783_PWRB_B1_EMULATE_CAD;
> +
> +		if (pdata->b1on_flags & MC13783_BUTTON_RESET_EN)
> +			reg |= MC13783_POWER_CONTROL_2_ON1BRSTEN;
> +
> +		mc13783_irq_request(mc13783, MC13783_IRQ_ONOFD1, b1on_irq,
> +							"b1on", priv);

No error handling here?

> +	}
> +
> +	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) {
> +		priv->b2on_key = pdata->b2on_key;
> +		if (pdata->b2on_key != KEY_RESERVED)
> +			pwr->keybit[BIT_WORD(pdata->b2on_key)] |=
> +						BIT_MASK(pdata->b2on_key);
> +
> +		if (pdata->b2on_flags & MC13783_BUTTON_POL_INVERT)
> +			priv->flags |= MC13783_PWRB_B2_POL_INVERT;
> +		if (pdata->b2on_flags & MC13783_BUTTON_EMUL_CAD)
> +			priv->flags |= MC13783_PWRB_B2_EMULATE_CAD;
> +
> +		if (pdata->b2on_flags & MC13783_BUTTON_RESET_EN)
> +			reg |= MC13783_POWER_CONTROL_2_ON2BRSTEN;
> +
> +		mc13783_irq_request(mc13783, MC13783_IRQ_ONOFD2, b2on_irq,
> +							"b2on", priv);
> +	}
> +
> +	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) {
> +		priv->b3on_key = pdata->b3on_key;
> +		if (pdata->b3on_key != KEY_RESERVED)
> +			pwr->keybit[BIT_WORD(pdata->b3on_key)] |=
> +						BIT_MASK(pdata->b3on_key);
> +
> +		if (pdata->b3on_flags & MC13783_BUTTON_POL_INVERT)
> +			priv->flags |= MC13783_PWRB_B3_POL_INVERT;
> +		if (pdata->b3on_flags & MC13783_BUTTON_EMUL_CAD)
> +			priv->flags |= MC13783_PWRB_B3_EMULATE_CAD;
> +
> +		if (pdata->b3on_flags & MC13783_BUTTON_RESET_EN)
> +			reg |= MC13783_POWER_CONTROL_2_ON3BRSTEN;
> +
> +		mc13783_irq_request(mc13783, MC13783_IRQ_ONOFD3, b3on_irq,
> +							"b3on", priv);
> +	}
> +
> +	mc13783_reg_rmw(mc13783, MC13783_REG_POWER_CONTROL_2, 0x3FE, reg);
> +
> +	mc13783_unlock(mc13783);
> +
> +	pwr->name = "mc13783_pwrbutton";
> +	pwr->phys = "mc13783_pwrbutton/input0";
> +	pwr->dev.parent = &pdev->dev;
> +
> +	err = input_register_device(pwr);
> +	if (err) {
> +		dev_dbg(&pdev->dev, "Can't register power button: %d\n", err);
> +		goto free_irq;
> +	}
> +
> +	platform_set_drvdata(pdev, priv);
> +
> +	return 0;
> +
> +free_irq:
> +	mc13783_lock(mc13783);
> +	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
> +		mc13783_irq_free(mc13783, MC13783_IRQ_ONOFD3, priv);
> +	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
> +		mc13783_irq_free(mc13783, MC13783_IRQ_ONOFD2, priv);
> +	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
> +		mc13783_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);
> +	mc13783_unlock(mc13783);
> +
> +	kfree(priv);
> +
> +free_input_dev:
> +	input_free_device(pwr);
> +	return err;
> +}
> +
> +static int __devexit mc13783_pwrbutton_remove(struct platform_device *pdev)
> +{
> +	struct mc13783_pwrb *priv = platform_get_drvdata(pdev);
> +	struct mc13783_buttons_platform_data *pdata;
> +	pdata = dev_get_platdata(&pdev->dev);
> +
> +	mc13783_lock(priv->mc13783);
> +	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
> +		mc13783_irq_free(priv->mc13783, MC13783_IRQ_ONOFD3, priv);
> +	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
> +		mc13783_irq_free(priv->mc13783, MC13783_IRQ_ONOFD2, priv);
> +	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
> +		mc13783_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv);
> +	mc13783_unlock(priv->mc13783);

Looks like this can be factored into a separate function.

> +
> +	input_unregister_device(priv->pwr);
> +
> +	kfree(priv);
> +
> +	return 0;
> +}
> +
> +struct platform_driver mc13783_pwrbutton_driver = {
> +	.probe		= mc13783_pwrbutton_probe,
> +	.remove		= __devexit_p(mc13783_pwrbutton_remove),
> +	.driver		= {
> +		.name	= "mc13783-pwrbutton",
> +		.owner	= THIS_MODULE,
> +	},
> +};
> +
> +static int __init mc13783_pwrbutton_init(void)
> +{
> +	return platform_driver_register(&mc13783_pwrbutton_driver);
> +}
> +module_init(mc13783_pwrbutton_init);
> +
> +static void __exit mc13783_pwrbutton_exit(void)
> +{
> +	platform_driver_unregister(&mc13783_pwrbutton_driver);
> +}
> +module_exit(mc13783_pwrbutton_exit);
> +
> +MODULE_ALIAS("platform:mc13783-pwrbutton");
> +MODULE_DESCRIPTION("MC13783 Power Button");
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Philippe Retornaz");
> +
> diff --git a/drivers/mfd/mc13783-core.c b/drivers/mfd/mc13783-core.c
> index fecf38a..fb3e98b 100644
> --- a/drivers/mfd/mc13783-core.c
> +++ b/drivers/mfd/mc13783-core.c
> @@ -683,6 +683,10 @@ err_revision:
>  		mc13783_add_subdevice_pdata(mc13783, "mc13783-led",
>  					pdata->leds, sizeof(*pdata->leds));
>  
> +	if (pdata->flags & MC13783_USE_BUTTON)
> +		mc13783_add_subdevice_pdata(mc13783, "mc13783-pwrbutton",
> +				pdata->buttons, sizeof(*pdata->buttons));
> +
>  	return 0;
>  }
>  
> diff --git a/include/linux/mfd/mc13783.h b/include/linux/mfd/mc13783.h
> index 4a894f6..66981a5 100644
> --- a/include/linux/mfd/mc13783.h
> +++ b/include/linux/mfd/mc13783.h
> @@ -128,6 +128,23 @@ struct mc13783_leds_platform_data {
>  	char tc3_period;
>  };
>  
> +struct mc13783_buttons_platform_data {
> +#define MC13783_BUTTON_DBNC_0MS		0
> +#define MC13783_BUTTON_DBNC_30MS	1
> +#define MC13783_BUTTON_DBNC_150MS	2
> +#define MC13783_BUTTON_DBNC_750MS	3
> +#define MC13783_BUTTON_ENABLE		(1 << 2)
> +#define MC13783_BUTTON_POL_INVERT	(1 << 3)
> +#define MC13783_BUTTON_RESET_EN		(1 << 4)
> +#define MC13783_BUTTON_EMUL_CAD		(1 << 5)
> +	int b1on_flags;
> +	unsigned int b1on_key;
> +	int b2on_flags;
> +	unsigned int b2on_key;
> +	int b3on_flags;
> +	unsigned int b3on_key;
> +};
> +
>  /* to be cleaned up */
>  struct regulator_init_data;
>  
> @@ -145,6 +162,7 @@ struct mc13783_platform_data {
>  	int num_regulators;
>  	struct mc13783_regulator_init_data *regulators;
>  	struct mc13783_leds_platform_data *leds;
> +	struct mc13783_buttons_platform_data *buttons;
>  
>  #define MC13783_USE_TOUCHSCREEN (1 << 0)
>  #define MC13783_USE_CODEC	(1 << 1)
> @@ -152,6 +170,7 @@ struct mc13783_platform_data {
>  #define MC13783_USE_RTC		(1 << 3)
>  #define MC13783_USE_REGULATOR	(1 << 4)
>  #define MC13783_USE_LED		(1 << 5)
> +#define MC13783_USE_BUTTON	(1 << 6)
>  	unsigned int flags;
>  };
>  
> -- 
> 1.6.3.3
> 

-- 
Dmitry
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 1/2] mc13783: add power button support
@ 2010-06-02  7:52     ` Dmitry Torokhov
  0 siblings, 0 replies; 20+ messages in thread
From: Dmitry Torokhov @ 2010-06-02  7:52 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Philippe,

On Mon, May 31, 2010 at 09:28:59PM +0200, Philippe R?tornaz wrote:
> This adds support for the power-on buttons of MC13783 PMIC.
> This is done using a misc input device.
> 
> Signed-off-by: Philippe R?tornaz <philippe.retornaz@epfl.ch>
> ---
>  drivers/input/misc/Kconfig             |    7 +
>  drivers/input/misc/Makefile            |    1 +
>  drivers/input/misc/mc13783-pwrbutton.c |  301 ++++++++++++++++++++++++++++++++
>  drivers/mfd/mc13783-core.c             |    4 +
>  include/linux/mfd/mc13783.h            |   19 ++
>  5 files changed, 332 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/input/misc/mc13783-pwrbutton.c
> 
> diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
> index 23140a3..2d25b16 100644
> --- a/drivers/input/misc/Kconfig
> +++ b/drivers/input/misc/Kconfig
> @@ -340,4 +340,11 @@ config INPUT_PCAP
>  	  To compile this driver as a module, choose M here: the
>  	  module will be called pcap_keys.
>  
> +config INPUT_MC13783_ON
> +	tristate "MC13783 ON buttons"
> +	depends on MFD_MC13783
> +	help
> +	  Support the ON buttons of MC13783 PMIC as an input device
> +	  reporting power button status.
> +

To compile this driver as a module...

>  endif
> diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
> index 7e95a5d..c96311d 100644
> --- a/drivers/input/misc/Makefile
> +++ b/drivers/input/misc/Makefile
> @@ -32,4 +32,5 @@ obj-$(CONFIG_INPUT_WINBOND_CIR)		+= winbond-cir.o
>  obj-$(CONFIG_INPUT_WISTRON_BTNS)	+= wistron_btns.o
>  obj-$(CONFIG_INPUT_WM831X_ON)		+= wm831x-on.o
>  obj-$(CONFIG_INPUT_YEALINK)		+= yealink.o
> +obj-$(CONFIG_INPUT_MC13783_ON)		+= mc13783-pwrbutton.o

Keep makefile sorted please.

>  
> diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
> new file mode 100644
> index 0000000..61cfcce
> --- /dev/null
> +++ b/drivers/input/misc/mc13783-pwrbutton.c
> @@ -0,0 +1,301 @@
> +/**
> + * mc13783-pwrbutton.c - MC13783 Power Button Input Driver
> + *
> + * Copyright (C) 2010 Philippe R?tornaz
> + *
> + * Based on twl4030-pwrbutton driver by:
> + *	Peter De Schrijver <peter.de-schrijver@nokia.com>
> + *	Felipe Balbi <felipe.balbi@nokia.com>
> + *
> + * This file is subject to the terms and conditions of the GNU General
> + * Public License. See the file "COPYING" in the main directory of this
> + * archive for more details.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
> + */
> +
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/errno.h>
> +#include <linux/input.h>
> +#include <linux/interrupt.h>
> +#include <linux/platform_device.h>
> +#include <linux/mfd/mc13783.h>
> +#include <linux/sched.h>
> +#include <linux/slab.h>
> +
> +struct mc13783_pwrb {
> +	struct input_dev *pwr;
> +	struct mc13783 *mc13783;
> +#define MC13783_PWRB_B1_EMULATE_CAD	(1 << 0)
> +#define MC13783_PWRB_B2_EMULATE_CAD	(1 << 1)
> +#define MC13783_PWRB_B3_EMULATE_CAD	(1 << 2)
> +#define MC13783_PWRB_B1_POL_INVERT	(1 << 3)
> +#define MC13783_PWRB_B2_POL_INVERT	(1 << 4)
> +#define MC13783_PWRB_B3_POL_INVERT	(1 << 5)
> +	int flags;
> +	unsigned int b1on_key;
> +	unsigned int b2on_key;
> +	unsigned int b3on_key;

Make it:

	unsigned short keymap[3];

and then do

	input->keycode = pwrb->keymap;
	input->keycodemax = ARRAY_SIZE(pwrb->keymap);
	input->keycodesize = sizeof(pwrb->keymap[0]);

so that keys can be remapped from userspace.

> +};
> +
> +#define MC13783_REG_INTERRUPT_SENSE_1		5
> +#define MC13783_IRQSENSE1_ONOFD1S		(1 << 3)
> +#define MC13783_IRQSENSE1_ONOFD2S		(1 << 4)
> +#define MC13783_IRQSENSE1_ONOFD3S		(1 << 5)
> +
> +#define MC13783_REG_POWER_CONTROL_2		15
> +#define MC13783_POWER_CONTROL_2_ON1BDBNC	4
> +#define MC13783_POWER_CONTROL_2_ON2BDBNC	6
> +#define MC13783_POWER_CONTROL_2_ON3BDBNC	8
> +#define MC13783_POWER_CONTROL_2_ON1BRSTEN	(1 << 1)
> +#define MC13783_POWER_CONTROL_2_ON2BRSTEN	(1 << 2)
> +#define MC13783_POWER_CONTROL_2_ON3BRSTEN	(1 << 3)
> +
> +static irqreturn_t b1on_irq(int irq, void *_priv)
> +{
> +	struct mc13783_pwrb *priv = _priv;
> +	int val;
> +
> +	mc13783_irq_ack(priv->mc13783, irq);
> +	mc13783_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
> +
> +	val = val & MC13783_IRQSENSE1_ONOFD1S ? 1 : 0;
> +
> +	if (priv->flags & MC13783_PWRB_B1_POL_INVERT)
> +		val ^= 1;
> +
> +	if (val && priv->flags & MC13783_PWRB_B1_EMULATE_CAD)
> +		kill_cad_pid(SIGINT, 1);

I do not think that individual input drivers should do this - CAD is
handled by the keyboard driver (drivers/char/keyboard) so it is just a
matter of loading proper keymap for your device.

> +
> +	input_report_key(priv->pwr, priv->b1on_key, val);
> +	input_sync(priv->pwr);
> +	return IRQ_HANDLED;
> +}
> +
> +static irqreturn_t b2on_irq(int irq, void *_priv)
> +{
> +	struct mc13783_pwrb *priv = _priv;
> +	int val;
> +
> +	mc13783_irq_ack(priv->mc13783, irq);
> +	mc13783_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
> +
> +	val = val & MC13783_IRQSENSE1_ONOFD2S ? 1 : 0;
> +
> +	if (priv->flags & MC13783_PWRB_B2_POL_INVERT)
> +		val ^= 1;
> +
> +	if (val && priv->flags & MC13783_PWRB_B2_EMULATE_CAD)
> +		kill_cad_pid(SIGINT, 1);
> +
> +	input_report_key(priv->pwr, priv->b2on_key, val);
> +	input_sync(priv->pwr);
> +	return IRQ_HANDLED;
> +}
> +
> +static irqreturn_t b3on_irq(int irq, void *_priv)
> +{
> +	struct mc13783_pwrb *priv = _priv;
> +	int val;
> +
> +	mc13783_irq_ack(priv->mc13783, irq);
> +	mc13783_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
> +
> +	val = val & MC13783_IRQSENSE1_ONOFD3S ? 1 : 0;
> +
> +	if (priv->flags & MC13783_PWRB_B3_POL_INVERT)
> +		val ^= 1;
> +
> +	if (val && priv->flags & MC13783_PWRB_B3_EMULATE_CAD)
> +		kill_cad_pid(SIGINT, 1);
> +
> +	input_report_key(priv->pwr, priv->b3on_key, val);
> +	input_sync(priv->pwr);
> +	return IRQ_HANDLED;

I am pretty sure these 3 functions can be combined.

> +}
> +
> +static int __devinit mc13783_pwrbutton_probe(struct platform_device *pdev)
> +{
> +	struct mc13783_buttons_platform_data *pdata;
> +	struct mc13783 *mc13783 = dev_get_drvdata(pdev->dev.parent);
> +	struct input_dev *pwr;
> +	struct mc13783_pwrb *priv;
> +	int err = 0;
> +	int reg = 0;
> +
> +	pdata = dev_get_platdata(&pdev->dev);
> +	if (pdata == NULL) {
> +		dev_err(&pdev->dev, "missing platform data\n");
> +		return -ENODEV;
> +	}
> +
> +	pwr = input_allocate_device();
> +	if (!pwr) {
> +		dev_dbg(&pdev->dev, "Can't allocate power button\n");
> +		return -ENOMEM;
> +	}
> +
> +	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> +
> +	if (!priv) {
> +		dev_dbg(&pdev->dev, "Can't allocate power button\n");
> +		goto free_input_dev;
> +	}
> +
> +	pwr->evbit[0] = BIT_MASK(EV_KEY);
> +
> +	reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
> +	reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
> +	reg |= (pdata->b3on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC;
> +
> +	priv->pwr = pwr;
> +	priv->mc13783 = mc13783;
> +
> +	mc13783_lock(mc13783);
> +
> +	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) {
> +		priv->b1on_key = pdata->b1on_key;
> +		if (pdata->b1on_key != KEY_RESERVED)
> +			pwr->keybit[BIT_WORD(pdata->b1on_key)] |=
> +						BIT_MASK(pdata->b1on_key);

Just use __set_bit().

> +
> +		if (pdata->b1on_flags & MC13783_BUTTON_POL_INVERT)
> +			priv->flags |= MC13783_PWRB_B1_POL_INVERT;
> +		if (pdata->b1on_flags & MC13783_BUTTON_EMUL_CAD)
> +			priv->flags |= MC13783_PWRB_B1_EMULATE_CAD;
> +
> +		if (pdata->b1on_flags & MC13783_BUTTON_RESET_EN)
> +			reg |= MC13783_POWER_CONTROL_2_ON1BRSTEN;
> +
> +		mc13783_irq_request(mc13783, MC13783_IRQ_ONOFD1, b1on_irq,
> +							"b1on", priv);

No error handling here?

> +	}
> +
> +	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) {
> +		priv->b2on_key = pdata->b2on_key;
> +		if (pdata->b2on_key != KEY_RESERVED)
> +			pwr->keybit[BIT_WORD(pdata->b2on_key)] |=
> +						BIT_MASK(pdata->b2on_key);
> +
> +		if (pdata->b2on_flags & MC13783_BUTTON_POL_INVERT)
> +			priv->flags |= MC13783_PWRB_B2_POL_INVERT;
> +		if (pdata->b2on_flags & MC13783_BUTTON_EMUL_CAD)
> +			priv->flags |= MC13783_PWRB_B2_EMULATE_CAD;
> +
> +		if (pdata->b2on_flags & MC13783_BUTTON_RESET_EN)
> +			reg |= MC13783_POWER_CONTROL_2_ON2BRSTEN;
> +
> +		mc13783_irq_request(mc13783, MC13783_IRQ_ONOFD2, b2on_irq,
> +							"b2on", priv);
> +	}
> +
> +	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) {
> +		priv->b3on_key = pdata->b3on_key;
> +		if (pdata->b3on_key != KEY_RESERVED)
> +			pwr->keybit[BIT_WORD(pdata->b3on_key)] |=
> +						BIT_MASK(pdata->b3on_key);
> +
> +		if (pdata->b3on_flags & MC13783_BUTTON_POL_INVERT)
> +			priv->flags |= MC13783_PWRB_B3_POL_INVERT;
> +		if (pdata->b3on_flags & MC13783_BUTTON_EMUL_CAD)
> +			priv->flags |= MC13783_PWRB_B3_EMULATE_CAD;
> +
> +		if (pdata->b3on_flags & MC13783_BUTTON_RESET_EN)
> +			reg |= MC13783_POWER_CONTROL_2_ON3BRSTEN;
> +
> +		mc13783_irq_request(mc13783, MC13783_IRQ_ONOFD3, b3on_irq,
> +							"b3on", priv);
> +	}
> +
> +	mc13783_reg_rmw(mc13783, MC13783_REG_POWER_CONTROL_2, 0x3FE, reg);
> +
> +	mc13783_unlock(mc13783);
> +
> +	pwr->name = "mc13783_pwrbutton";
> +	pwr->phys = "mc13783_pwrbutton/input0";
> +	pwr->dev.parent = &pdev->dev;
> +
> +	err = input_register_device(pwr);
> +	if (err) {
> +		dev_dbg(&pdev->dev, "Can't register power button: %d\n", err);
> +		goto free_irq;
> +	}
> +
> +	platform_set_drvdata(pdev, priv);
> +
> +	return 0;
> +
> +free_irq:
> +	mc13783_lock(mc13783);
> +	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
> +		mc13783_irq_free(mc13783, MC13783_IRQ_ONOFD3, priv);
> +	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
> +		mc13783_irq_free(mc13783, MC13783_IRQ_ONOFD2, priv);
> +	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
> +		mc13783_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);
> +	mc13783_unlock(mc13783);
> +
> +	kfree(priv);
> +
> +free_input_dev:
> +	input_free_device(pwr);
> +	return err;
> +}
> +
> +static int __devexit mc13783_pwrbutton_remove(struct platform_device *pdev)
> +{
> +	struct mc13783_pwrb *priv = platform_get_drvdata(pdev);
> +	struct mc13783_buttons_platform_data *pdata;
> +	pdata = dev_get_platdata(&pdev->dev);
> +
> +	mc13783_lock(priv->mc13783);
> +	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
> +		mc13783_irq_free(priv->mc13783, MC13783_IRQ_ONOFD3, priv);
> +	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
> +		mc13783_irq_free(priv->mc13783, MC13783_IRQ_ONOFD2, priv);
> +	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
> +		mc13783_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv);
> +	mc13783_unlock(priv->mc13783);

Looks like this can be factored into a separate function.

> +
> +	input_unregister_device(priv->pwr);
> +
> +	kfree(priv);
> +
> +	return 0;
> +}
> +
> +struct platform_driver mc13783_pwrbutton_driver = {
> +	.probe		= mc13783_pwrbutton_probe,
> +	.remove		= __devexit_p(mc13783_pwrbutton_remove),
> +	.driver		= {
> +		.name	= "mc13783-pwrbutton",
> +		.owner	= THIS_MODULE,
> +	},
> +};
> +
> +static int __init mc13783_pwrbutton_init(void)
> +{
> +	return platform_driver_register(&mc13783_pwrbutton_driver);
> +}
> +module_init(mc13783_pwrbutton_init);
> +
> +static void __exit mc13783_pwrbutton_exit(void)
> +{
> +	platform_driver_unregister(&mc13783_pwrbutton_driver);
> +}
> +module_exit(mc13783_pwrbutton_exit);
> +
> +MODULE_ALIAS("platform:mc13783-pwrbutton");
> +MODULE_DESCRIPTION("MC13783 Power Button");
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Philippe Retornaz");
> +
> diff --git a/drivers/mfd/mc13783-core.c b/drivers/mfd/mc13783-core.c
> index fecf38a..fb3e98b 100644
> --- a/drivers/mfd/mc13783-core.c
> +++ b/drivers/mfd/mc13783-core.c
> @@ -683,6 +683,10 @@ err_revision:
>  		mc13783_add_subdevice_pdata(mc13783, "mc13783-led",
>  					pdata->leds, sizeof(*pdata->leds));
>  
> +	if (pdata->flags & MC13783_USE_BUTTON)
> +		mc13783_add_subdevice_pdata(mc13783, "mc13783-pwrbutton",
> +				pdata->buttons, sizeof(*pdata->buttons));
> +
>  	return 0;
>  }
>  
> diff --git a/include/linux/mfd/mc13783.h b/include/linux/mfd/mc13783.h
> index 4a894f6..66981a5 100644
> --- a/include/linux/mfd/mc13783.h
> +++ b/include/linux/mfd/mc13783.h
> @@ -128,6 +128,23 @@ struct mc13783_leds_platform_data {
>  	char tc3_period;
>  };
>  
> +struct mc13783_buttons_platform_data {
> +#define MC13783_BUTTON_DBNC_0MS		0
> +#define MC13783_BUTTON_DBNC_30MS	1
> +#define MC13783_BUTTON_DBNC_150MS	2
> +#define MC13783_BUTTON_DBNC_750MS	3
> +#define MC13783_BUTTON_ENABLE		(1 << 2)
> +#define MC13783_BUTTON_POL_INVERT	(1 << 3)
> +#define MC13783_BUTTON_RESET_EN		(1 << 4)
> +#define MC13783_BUTTON_EMUL_CAD		(1 << 5)
> +	int b1on_flags;
> +	unsigned int b1on_key;
> +	int b2on_flags;
> +	unsigned int b2on_key;
> +	int b3on_flags;
> +	unsigned int b3on_key;
> +};
> +
>  /* to be cleaned up */
>  struct regulator_init_data;
>  
> @@ -145,6 +162,7 @@ struct mc13783_platform_data {
>  	int num_regulators;
>  	struct mc13783_regulator_init_data *regulators;
>  	struct mc13783_leds_platform_data *leds;
> +	struct mc13783_buttons_platform_data *buttons;
>  
>  #define MC13783_USE_TOUCHSCREEN (1 << 0)
>  #define MC13783_USE_CODEC	(1 << 1)
> @@ -152,6 +170,7 @@ struct mc13783_platform_data {
>  #define MC13783_USE_RTC		(1 << 3)
>  #define MC13783_USE_REGULATOR	(1 << 4)
>  #define MC13783_USE_LED		(1 << 5)
> +#define MC13783_USE_BUTTON	(1 << 6)
>  	unsigned int flags;
>  };
>  
> -- 
> 1.6.3.3
> 

-- 
Dmitry

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/2] mx31moboard: Add MC13783 power button support
  2010-05-31 19:29     ` Philippe Rétornaz
@ 2010-06-03  8:31       ` Sascha Hauer
  -1 siblings, 0 replies; 20+ messages in thread
From: Sascha Hauer @ 2010-06-03  8:31 UTC (permalink / raw)
  To: Philippe Rétornaz
  Cc: linux-arm-kernel, dmitry.torokhov, sameo, linux-input, broonie,
	u.kleine-koenig, ext-jari.vanhala, valentin.longchamp

Hi Philippe,

Please ping me once the LED/Power button support is merged. I'll take
care of the platform patches.

Sascha

On Mon, May 31, 2010 at 09:29:00PM +0200, Philippe Rétornaz wrote:
> Add the power-on button on mx31moboard using MC13783 PMIC.
> 
> Signed-off-by: Philippe Rétornaz <philippe.retornaz@epfl.ch>
> ---
>  arch/arm/mach-mx3/mach-mx31moboard.c |   10 +++++++++-
>  1 files changed, 9 insertions(+), 1 deletions(-)
> 
> diff --git a/arch/arm/mach-mx3/mach-mx31moboard.c b/arch/arm/mach-mx3/mach-mx31moboard.c
> index 62b5e40..7a8f078 100644
> --- a/arch/arm/mach-mx3/mach-mx31moboard.c
> +++ b/arch/arm/mach-mx3/mach-mx31moboard.c
> @@ -31,6 +31,7 @@
>  #include <linux/mfd/mc13783.h>
>  #include <linux/spi/spi.h>
>  #include <linux/types.h>
> +#include <linux/input.h>
>  
>  #include <linux/usb/otg.h>
>  #include <linux/usb/ulpi.h>
> @@ -262,12 +263,19 @@ static struct mc13783_leds_platform_data moboard_leds = {
>  	.tc2_period = MC13783_LED_PERIOD_10MS,
>  };
>  
> +static struct mc13783_buttons_platform_data moboard_buttons = {
> +	.b1on_flags = MC13783_BUTTON_DBNC_750MS | MC13783_BUTTON_ENABLE |
> +			MC13783_BUTTON_POL_INVERT | MC13783_BUTTON_EMUL_CAD,
> +	.b1on_key = KEY_POWER,
> +};
> +
>  static struct mc13783_platform_data moboard_pmic = {
>  	.regulators = moboard_regulators,
>  	.num_regulators = ARRAY_SIZE(moboard_regulators),
>  	.leds = &moboard_leds,
> +	.buttons = &moboard_buttons,
>  	.flags = MC13783_USE_REGULATOR | MC13783_USE_RTC |
> -		MC13783_USE_ADC | MC13783_USE_LED,
> +		MC13783_USE_ADC | MC13783_USE_LED | MC13783_USE_BUTTON,
>  };
>  
>  static struct spi_board_info moboard_spi_board_info[] __initdata = {
> -- 
> 1.6.3.3
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 2/2] mx31moboard: Add MC13783 power button support
@ 2010-06-03  8:31       ` Sascha Hauer
  0 siblings, 0 replies; 20+ messages in thread
From: Sascha Hauer @ 2010-06-03  8:31 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Philippe,

Please ping me once the LED/Power button support is merged. I'll take
care of the platform patches.

Sascha

On Mon, May 31, 2010 at 09:29:00PM +0200, Philippe R?tornaz wrote:
> Add the power-on button on mx31moboard using MC13783 PMIC.
> 
> Signed-off-by: Philippe R?tornaz <philippe.retornaz@epfl.ch>
> ---
>  arch/arm/mach-mx3/mach-mx31moboard.c |   10 +++++++++-
>  1 files changed, 9 insertions(+), 1 deletions(-)
> 
> diff --git a/arch/arm/mach-mx3/mach-mx31moboard.c b/arch/arm/mach-mx3/mach-mx31moboard.c
> index 62b5e40..7a8f078 100644
> --- a/arch/arm/mach-mx3/mach-mx31moboard.c
> +++ b/arch/arm/mach-mx3/mach-mx31moboard.c
> @@ -31,6 +31,7 @@
>  #include <linux/mfd/mc13783.h>
>  #include <linux/spi/spi.h>
>  #include <linux/types.h>
> +#include <linux/input.h>
>  
>  #include <linux/usb/otg.h>
>  #include <linux/usb/ulpi.h>
> @@ -262,12 +263,19 @@ static struct mc13783_leds_platform_data moboard_leds = {
>  	.tc2_period = MC13783_LED_PERIOD_10MS,
>  };
>  
> +static struct mc13783_buttons_platform_data moboard_buttons = {
> +	.b1on_flags = MC13783_BUTTON_DBNC_750MS | MC13783_BUTTON_ENABLE |
> +			MC13783_BUTTON_POL_INVERT | MC13783_BUTTON_EMUL_CAD,
> +	.b1on_key = KEY_POWER,
> +};
> +
>  static struct mc13783_platform_data moboard_pmic = {
>  	.regulators = moboard_regulators,
>  	.num_regulators = ARRAY_SIZE(moboard_regulators),
>  	.leds = &moboard_leds,
> +	.buttons = &moboard_buttons,
>  	.flags = MC13783_USE_REGULATOR | MC13783_USE_RTC |
> -		MC13783_USE_ADC | MC13783_USE_LED,
> +		MC13783_USE_ADC | MC13783_USE_LED | MC13783_USE_BUTTON,
>  };
>  
>  static struct spi_board_info moboard_spi_board_info[] __initdata = {
> -- 
> 1.6.3.3
> 
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 2/2] mx31moboard: Add MC13783 power button support
  2010-06-03  8:31       ` Sascha Hauer
@ 2010-06-03  9:23         ` Philippe Rétornaz
  -1 siblings, 0 replies; 20+ messages in thread
From: Philippe Rétornaz @ 2010-06-03  9:23 UTC (permalink / raw)
  To: Sascha Hauer
  Cc: linux-arm-kernel, dmitry.torokhov, sameo, linux-input, broonie,
	u.kleine-koenig, ext-jari.vanhala, Longchamp Valentin

Le jeudi, 3 juin 2010 10.31:55, Sascha Hauer a écrit :
> Hi Philippe,
> 
> Please ping me once the LED/Power button support is merged. I'll take
> care of the platform patches.

Thanks, I'll try to produce a new patch ASAP (maybe next week).

Regards,

Philippe
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 2/2] mx31moboard: Add MC13783 power button support
@ 2010-06-03  9:23         ` Philippe Rétornaz
  0 siblings, 0 replies; 20+ messages in thread
From: Philippe Rétornaz @ 2010-06-03  9:23 UTC (permalink / raw)
  To: linux-arm-kernel

Le jeudi, 3 juin 2010 10.31:55, Sascha Hauer a ?crit :
> Hi Philippe,
> 
> Please ping me once the LED/Power button support is merged. I'll take
> care of the platform patches.

Thanks, I'll try to produce a new patch ASAP (maybe next week).

Regards,

Philippe

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/2] mc13783: add power button support
  2011-07-08 14:45       ` Philippe Rétornaz
@ 2011-07-08 15:25         ` Uwe Kleine-König
  -1 siblings, 0 replies; 20+ messages in thread
From: Uwe Kleine-König @ 2011-07-08 15:25 UTC (permalink / raw)
  To: Philippe Rétornaz
  Cc: s.hauer, linux-arm-kernel, dmitry.torokhov, sameo, linux-input, broonie

Hello Philippe,

On Fri, Jul 08, 2011 at 04:45:00PM +0200, Philippe Rétornaz wrote:
> > > +config INPUT_MC13783_ON
> > > +	tristate "MC13783 ON buttons"
> > > +	depends on MFD_MC13783
> > > +	help
> > > +	  Support the ON buttons of MC13783 PMIC as an input device
> > > +	  reporting power button status.
> > > +
> > > +	  To compile this driver as a module, choose M here: the module
> > > +	  will be called mc13783-pwrbutton.
> > 
> > Why not use INPUT_MC13783_PWRBUTTON to match the source file (and so
> > module) name.
> 
> Ok.
> 
> > 
> > > +
> > > +
> > 
> > one empty line should be enough
> 
> Ok.
> 
> > > diff --git a/drivers/input/misc/mc13783-pwrbutton.c
> > > b/drivers/input/misc/mc13783-pwrbutton.c new file mode 100644
> > > index 0000000..6aee01c
> > > --- /dev/null
> > > +++ b/drivers/input/misc/mc13783-pwrbutton.c
> > > @@ -0,0 +1,288 @@
> > > +/**
> > > + * mc13783-pwrbutton.c - MC13783 Power Button Input Driver
> > > + *
> > > + * Copyright (C) 2011 Philippe Rétornaz
> > > + *
> > > + * Based on twl4030-pwrbutton driver by:
> > > + *     Peter De Schrijver <peter.de-schrijver@nokia.com>
> > > + *     Felipe Balbi <felipe.balbi@nokia.com>
> > > + *
> > > + * This file is subject to the terms and conditions of the GNU General
> > > + * Public License. See the file "COPYING" in the main directory of this
> > > + * archive for more details.
> > 
> > This implies GPL v2 only? So you either need to clearify here or you
> > need to adapt the MODULE_LICENSE line below to read
> > 
> > 	MODULE_LICENSE("GPL v2");
> 
> Well, I took exactly the same license than the twl4030-pwrbutton. 
> This driver is: MODULE_LICENSE("GPL"), why should I change it ?
So this driver is wrong, too. According to include/linux/module.h, "GPL"
means "GNU Public License v2 or later" and "GPL v2" means "GNU Public
License v2".

> > > --- a/drivers/mfd/mc13xxx-core.c
> > > +++ b/drivers/mfd/mc13xxx-core.c
> > > 
> > > @@ -778,6 +778,10 @@ err_revision:
> > >  		mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led",
> > >  		
> > >  				pdata->leds, sizeof(*pdata->leds));
> > > 
> > > +	if (pdata->flags & MC13XXX_USE_BUTTON)
> > 
> > Why not use
> > 
> > 	if (pdata->buttons)
> > 
> > to detect if the pwrbutton device should be registered?
> 
> To keep consistancy as the others sub-device are registered the same way 
> (regulator, led). I can do it as you propose for the button but IMHO it's a 
> bit strange to have a MC13XXX_USE_* for all the subdevice except the buttons. 
> So should I change ?
It would be a third patch for your commit count to convert regulator and
led, too ;-)

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 1/2] mc13783: add power button support
@ 2011-07-08 15:25         ` Uwe Kleine-König
  0 siblings, 0 replies; 20+ messages in thread
From: Uwe Kleine-König @ 2011-07-08 15:25 UTC (permalink / raw)
  To: linux-arm-kernel

Hello Philippe,

On Fri, Jul 08, 2011 at 04:45:00PM +0200, Philippe R?tornaz wrote:
> > > +config INPUT_MC13783_ON
> > > +	tristate "MC13783 ON buttons"
> > > +	depends on MFD_MC13783
> > > +	help
> > > +	  Support the ON buttons of MC13783 PMIC as an input device
> > > +	  reporting power button status.
> > > +
> > > +	  To compile this driver as a module, choose M here: the module
> > > +	  will be called mc13783-pwrbutton.
> > 
> > Why not use INPUT_MC13783_PWRBUTTON to match the source file (and so
> > module) name.
> 
> Ok.
> 
> > 
> > > +
> > > +
> > 
> > one empty line should be enough
> 
> Ok.
> 
> > > diff --git a/drivers/input/misc/mc13783-pwrbutton.c
> > > b/drivers/input/misc/mc13783-pwrbutton.c new file mode 100644
> > > index 0000000..6aee01c
> > > --- /dev/null
> > > +++ b/drivers/input/misc/mc13783-pwrbutton.c
> > > @@ -0,0 +1,288 @@
> > > +/**
> > > + * mc13783-pwrbutton.c - MC13783 Power Button Input Driver
> > > + *
> > > + * Copyright (C) 2011 Philippe R?tornaz
> > > + *
> > > + * Based on twl4030-pwrbutton driver by:
> > > + *     Peter De Schrijver <peter.de-schrijver@nokia.com>
> > > + *     Felipe Balbi <felipe.balbi@nokia.com>
> > > + *
> > > + * This file is subject to the terms and conditions of the GNU General
> > > + * Public License. See the file "COPYING" in the main directory of this
> > > + * archive for more details.
> > 
> > This implies GPL v2 only? So you either need to clearify here or you
> > need to adapt the MODULE_LICENSE line below to read
> > 
> > 	MODULE_LICENSE("GPL v2");
> 
> Well, I took exactly the same license than the twl4030-pwrbutton. 
> This driver is: MODULE_LICENSE("GPL"), why should I change it ?
So this driver is wrong, too. According to include/linux/module.h, "GPL"
means "GNU Public License v2 or later" and "GPL v2" means "GNU Public
License v2".

> > > --- a/drivers/mfd/mc13xxx-core.c
> > > +++ b/drivers/mfd/mc13xxx-core.c
> > > 
> > > @@ -778,6 +778,10 @@ err_revision:
> > >  		mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led",
> > >  		
> > >  				pdata->leds, sizeof(*pdata->leds));
> > > 
> > > +	if (pdata->flags & MC13XXX_USE_BUTTON)
> > 
> > Why not use
> > 
> > 	if (pdata->buttons)
> > 
> > to detect if the pwrbutton device should be registered?
> 
> To keep consistancy as the others sub-device are registered the same way 
> (regulator, led). I can do it as you propose for the button but IMHO it's a 
> bit strange to have a MC13XXX_USE_* for all the subdevice except the buttons. 
> So should I change ?
It would be a third patch for your commit count to convert regulator and
led, too ;-)

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/2] mc13783: add power button support
  2011-07-08 14:30     ` Uwe Kleine-König
@ 2011-07-08 14:45       ` Philippe Rétornaz
  -1 siblings, 0 replies; 20+ messages in thread
From: Philippe Rétornaz @ 2011-07-08 14:45 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: s.hauer, linux-arm-kernel, dmitry.torokhov, sameo, linux-input, broonie

Hi

> > +config INPUT_MC13783_ON
> > +	tristate "MC13783 ON buttons"
> > +	depends on MFD_MC13783
> > +	help
> > +	  Support the ON buttons of MC13783 PMIC as an input device
> > +	  reporting power button status.
> > +
> > +	  To compile this driver as a module, choose M here: the module
> > +	  will be called mc13783-pwrbutton.
> 
> Why not use INPUT_MC13783_PWRBUTTON to match the source file (and so
> module) name.

Ok.

> 
> > +
> > +
> 
> one empty line should be enough

Ok.

> > diff --git a/drivers/input/misc/mc13783-pwrbutton.c
> > b/drivers/input/misc/mc13783-pwrbutton.c new file mode 100644
> > index 0000000..6aee01c
> > --- /dev/null
> > +++ b/drivers/input/misc/mc13783-pwrbutton.c
> > @@ -0,0 +1,288 @@
> > +/**
> > + * mc13783-pwrbutton.c - MC13783 Power Button Input Driver
> > + *
> > + * Copyright (C) 2011 Philippe Rétornaz
> > + *
> > + * Based on twl4030-pwrbutton driver by:
> > + *     Peter De Schrijver <peter.de-schrijver@nokia.com>
> > + *     Felipe Balbi <felipe.balbi@nokia.com>
> > + *
> > + * This file is subject to the terms and conditions of the GNU General
> > + * Public License. See the file "COPYING" in the main directory of this
> > + * archive for more details.
> 
> This implies GPL v2 only? So you either need to clearify here or you
> need to adapt the MODULE_LICENSE line below to read
> 
> 	MODULE_LICENSE("GPL v2");

Well, I took exactly the same license than the twl4030-pwrbutton. 
This driver is: MODULE_LICENSE("GPL"), why should I change it ?

> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program; if not, write to the Free Software
> > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 
> > USA
> 
> This is not the recent address of the FSF.

Ok, will update to 51 Franklin Street, Suite 500, Boston, MA 02110-1335


> > --- a/drivers/mfd/mc13xxx-core.c
> > +++ b/drivers/mfd/mc13xxx-core.c
> > 
> > @@ -778,6 +778,10 @@ err_revision:
> >  		mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led",
> >  		
> >  				pdata->leds, sizeof(*pdata->leds));
> > 
> > +	if (pdata->flags & MC13XXX_USE_BUTTON)
> 
> Why not use
> 
> 	if (pdata->buttons)
> 
> to detect if the pwrbutton device should be registered?

To keep consistancy as the others sub-device are registered the same way 
(regulator, led). I can do it as you propose for the button but IMHO it's a 
bit strange to have a MC13XXX_USE_* for all the subdevice except the buttons. 
So should I change ?

Thanks for the review ! 

Philippe

--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 1/2] mc13783: add power button support
@ 2011-07-08 14:45       ` Philippe Rétornaz
  0 siblings, 0 replies; 20+ messages in thread
From: Philippe Rétornaz @ 2011-07-08 14:45 UTC (permalink / raw)
  To: linux-arm-kernel

Hi

> > +config INPUT_MC13783_ON
> > +	tristate "MC13783 ON buttons"
> > +	depends on MFD_MC13783
> > +	help
> > +	  Support the ON buttons of MC13783 PMIC as an input device
> > +	  reporting power button status.
> > +
> > +	  To compile this driver as a module, choose M here: the module
> > +	  will be called mc13783-pwrbutton.
> 
> Why not use INPUT_MC13783_PWRBUTTON to match the source file (and so
> module) name.

Ok.

> 
> > +
> > +
> 
> one empty line should be enough

Ok.

> > diff --git a/drivers/input/misc/mc13783-pwrbutton.c
> > b/drivers/input/misc/mc13783-pwrbutton.c new file mode 100644
> > index 0000000..6aee01c
> > --- /dev/null
> > +++ b/drivers/input/misc/mc13783-pwrbutton.c
> > @@ -0,0 +1,288 @@
> > +/**
> > + * mc13783-pwrbutton.c - MC13783 Power Button Input Driver
> > + *
> > + * Copyright (C) 2011 Philippe R?tornaz
> > + *
> > + * Based on twl4030-pwrbutton driver by:
> > + *     Peter De Schrijver <peter.de-schrijver@nokia.com>
> > + *     Felipe Balbi <felipe.balbi@nokia.com>
> > + *
> > + * This file is subject to the terms and conditions of the GNU General
> > + * Public License. See the file "COPYING" in the main directory of this
> > + * archive for more details.
> 
> This implies GPL v2 only? So you either need to clearify here or you
> need to adapt the MODULE_LICENSE line below to read
> 
> 	MODULE_LICENSE("GPL v2");

Well, I took exactly the same license than the twl4030-pwrbutton. 
This driver is: MODULE_LICENSE("GPL"), why should I change it ?

> > + *
> > + * This program is distributed in the hope that it will be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program; if not, write to the Free Software
> > + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 
> > USA
> 
> This is not the recent address of the FSF.

Ok, will update to 51 Franklin Street, Suite 500, Boston, MA 02110-1335


> > --- a/drivers/mfd/mc13xxx-core.c
> > +++ b/drivers/mfd/mc13xxx-core.c
> > 
> > @@ -778,6 +778,10 @@ err_revision:
> >  		mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led",
> >  		
> >  				pdata->leds, sizeof(*pdata->leds));
> > 
> > +	if (pdata->flags & MC13XXX_USE_BUTTON)
> 
> Why not use
> 
> 	if (pdata->buttons)
> 
> to detect if the pwrbutton device should be registered?

To keep consistancy as the others sub-device are registered the same way 
(regulator, led). I can do it as you propose for the button but IMHO it's a 
bit strange to have a MC13XXX_USE_* for all the subdevice except the buttons. 
So should I change ?

Thanks for the review ! 

Philippe

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 1/2] mc13783: add power button support
  2011-07-08 14:23   ` Philippe Rétornaz
@ 2011-07-08 14:30     ` Uwe Kleine-König
  -1 siblings, 0 replies; 20+ messages in thread
From: Uwe Kleine-König @ 2011-07-08 14:30 UTC (permalink / raw)
  To: Philippe Rétornaz
  Cc: s.hauer, linux-arm-kernel, dmitry.torokhov, sameo, linux-input, broonie

Hello Philippe,

On Fri, Jul 08, 2011 at 04:23:56PM +0200, Philippe Rétornaz wrote:
> This adds support for the power-on buttons of MC13783 PMIC.
> This is done using a misc input device.
> 
> Signed-off-by: Philippe Rétornaz <philippe.retornaz@epfl.ch>
> ---
>  drivers/input/misc/Kconfig             |   11 ++
>  drivers/input/misc/Makefile            |    1 +
>  drivers/input/misc/mc13783-pwrbutton.c |  288 ++++++++++++++++++++++++++++++++
>  drivers/mfd/mc13xxx-core.c             |    4 +
>  include/linux/mfd/mc13783.h            |    1 +
>  include/linux/mfd/mc13xxx.h            |   18 ++
>  6 files changed, 323 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/input/misc/mc13783-pwrbutton.c
> 
> diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
> index 45dc6aa..87d595c 100644
> --- a/drivers/input/misc/Kconfig
> +++ b/drivers/input/misc/Kconfig
> @@ -100,6 +100,17 @@ config INPUT_MAX8925_ONKEY
>  	  To compile this driver as a module, choose M here: the module
>  	  will be called max8925_onkey.
>  
> +config INPUT_MC13783_ON
> +	tristate "MC13783 ON buttons"
> +	depends on MFD_MC13783
> +	help
> +	  Support the ON buttons of MC13783 PMIC as an input device
> +	  reporting power button status.
> +
> +	  To compile this driver as a module, choose M here: the module
> +	  will be called mc13783-pwrbutton.
Why not use INPUT_MC13783_PWRBUTTON to match the source file (and so
module) name.
> +
> +
one empty line should be enough
>  config INPUT_APANEL
>  	tristate "Fujitsu Lifebook Application Panel buttons"
>  	depends on X86 && I2C && LEDS_CLASS
> diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
> index 38efb2c..fdc6ab9 100644
> --- a/drivers/input/misc/Makefile
> +++ b/drivers/input/misc/Makefile
> @@ -27,6 +27,7 @@ obj-$(CONFIG_INPUT_IXP4XX_BEEPER)	+= ixp4xx-beeper.o
>  obj-$(CONFIG_INPUT_KEYSPAN_REMOTE)	+= keyspan_remote.o
>  obj-$(CONFIG_INPUT_M68K_BEEP)		+= m68kspkr.o
>  obj-$(CONFIG_INPUT_MAX8925_ONKEY)	+= max8925_onkey.o
> +obj-$(CONFIG_INPUT_MC13783_ON)		+= mc13783-pwrbutton.o
>  obj-$(CONFIG_INPUT_PCAP)		+= pcap_keys.o
>  obj-$(CONFIG_INPUT_PCF50633_PMU)	+= pcf50633-input.o
>  obj-$(CONFIG_INPUT_PCF8574)		+= pcf8574_keypad.o
> diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
> new file mode 100644
> index 0000000..6aee01c
> --- /dev/null
> +++ b/drivers/input/misc/mc13783-pwrbutton.c
> @@ -0,0 +1,288 @@
> +/**
> + * mc13783-pwrbutton.c - MC13783 Power Button Input Driver
> + *
> + * Copyright (C) 2011 Philippe Rétornaz
> + *
> + * Based on twl4030-pwrbutton driver by:
> + *     Peter De Schrijver <peter.de-schrijver@nokia.com>
> + *     Felipe Balbi <felipe.balbi@nokia.com>
> + *
> + * This file is subject to the terms and conditions of the GNU General
> + * Public License. See the file "COPYING" in the main directory of this
> + * archive for more details.
This implies GPL v2 only? So you either need to clearify here or you
need to adapt the MODULE_LICENSE line below to read

	MODULE_LICENSE("GPL v2");

> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
This is not the recent address of the FSF.

> + */
> +
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/errno.h>
> +#include <linux/input.h>
> +#include <linux/interrupt.h>
> +#include <linux/platform_device.h>
> +#include <linux/mfd/mc13783.h>
> +#include <linux/sched.h>
> +#include <linux/slab.h>
> +
> +struct mc13783_pwrb {
> +	struct input_dev *pwr;
> +	struct mc13xxx *mc13783;
> +#define MC13783_PWRB_B1_POL_INVERT	(1 << 0)
> +#define MC13783_PWRB_B2_POL_INVERT	(1 << 1)
> +#define MC13783_PWRB_B3_POL_INVERT	(1 << 2)
> +	int flags;
> +	unsigned short keymap[3];
> +};
> +
> +#define MC13783_REG_INTERRUPT_SENSE_1		5
> +#define MC13783_IRQSENSE1_ONOFD1S		(1 << 3)
> +#define MC13783_IRQSENSE1_ONOFD2S		(1 << 4)
> +#define MC13783_IRQSENSE1_ONOFD3S		(1 << 5)
> +
> +#define MC13783_REG_POWER_CONTROL_2		15
> +#define MC13783_POWER_CONTROL_2_ON1BDBNC	4
> +#define MC13783_POWER_CONTROL_2_ON2BDBNC	6
> +#define MC13783_POWER_CONTROL_2_ON3BDBNC	8
> +#define MC13783_POWER_CONTROL_2_ON1BRSTEN	(1 << 1)
> +#define MC13783_POWER_CONTROL_2_ON2BRSTEN	(1 << 2)
> +#define MC13783_POWER_CONTROL_2_ON3BRSTEN	(1 << 3)
> +
> +static irqreturn_t button_irq(int irq, void *_priv)
> +{
> +	struct mc13783_pwrb *priv = _priv;
> +	int val;
> +	mc13xxx_irq_ack(priv->mc13783, irq);
> +	mc13xxx_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
> +
> +	switch (irq) {
> +	case MC13783_IRQ_ONOFD1:
> +		val = val & MC13783_IRQSENSE1_ONOFD1S ? 1 : 0;
> +		if (priv->flags & MC13783_PWRB_B1_POL_INVERT)
> +			val ^= 1;
> +		input_report_key(priv->pwr, priv->keymap[0], val);
> +		break;
> +
> +	case MC13783_IRQ_ONOFD2:
> +		val = val & MC13783_IRQSENSE1_ONOFD2S ? 1 : 0;
> +		if (priv->flags & MC13783_PWRB_B2_POL_INVERT)
> +			val ^= 1;
> +		input_report_key(priv->pwr, priv->keymap[1], val);
> +		break;
> +
> +	case MC13783_IRQ_ONOFD3:
> +		val = val & MC13783_IRQSENSE1_ONOFD3S ? 1 : 0;
> +		if (priv->flags & MC13783_PWRB_B3_POL_INVERT)
> +			val ^= 1;
> +		input_report_key(priv->pwr, priv->keymap[2], val);
> +		break;
> +	}
> +
> +	input_sync(priv->pwr);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static int __devinit mc13783_pwrbutton_probe(struct platform_device *pdev)
> +{
> +	struct mc13xxx_buttons_platform_data *pdata;
> +	struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent);
> +	struct input_dev *pwr;
> +	struct mc13783_pwrb *priv;
> +	int err = 0;
> +	int reg = 0;
> +
> +	pdata = dev_get_platdata(&pdev->dev);
> +	if (pdata == NULL) {
> +		dev_err(&pdev->dev, "missing platform data\n");
> +		return -ENODEV;
> +	}
> +
> +	pwr = input_allocate_device();
> +	if (!pwr) {
> +		dev_dbg(&pdev->dev, "Can't allocate power button\n");
> +		return -ENOMEM;
> +	}
> +
> +	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> +
> +	if (!priv) {
> +		err = -ENOMEM;
> +		dev_dbg(&pdev->dev, "Can't allocate power button\n");
> +		goto free_input_dev;
> +	}
> +
> +	pwr->evbit[0] = BIT_MASK(EV_KEY);
> +
> +	reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
> +	reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
> +	reg |= (pdata->b3on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC;
> +
> +	priv->pwr = pwr;
> +	priv->mc13783 = mc13783;
> +
> +	mc13xxx_lock(mc13783);
> +
> +	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) {
> +		priv->keymap[0] = pdata->b1on_key;
> +		if (pdata->b1on_key != KEY_RESERVED)
> +			__set_bit(pdata->b1on_key, pwr->keybit);
> +
> +		if (pdata->b1on_flags & MC13783_BUTTON_POL_INVERT)
> +			priv->flags |= MC13783_PWRB_B1_POL_INVERT;
> +
> +		if (pdata->b1on_flags & MC13783_BUTTON_RESET_EN)
> +			reg |= MC13783_POWER_CONTROL_2_ON1BRSTEN;
> +
> +		err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD1,
> +					  button_irq, "b1on", priv);
> +
> +		if (err) {
> +			mc13xxx_unlock(mc13783);
> +
> +			dev_dbg(&pdev->dev, "Can't request irq\n");
> +			goto free_priv;
> +		}
> +	}
> +
> +	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) {
> +		priv->keymap[0] = pdata->b2on_key;
> +		if (pdata->b2on_key != KEY_RESERVED)
> +			__set_bit(pdata->b2on_key, pwr->keybit);
> +
> +		if (pdata->b2on_flags & MC13783_BUTTON_POL_INVERT)
> +			priv->flags |= MC13783_PWRB_B2_POL_INVERT;
> +
> +		if (pdata->b2on_flags & MC13783_BUTTON_RESET_EN)
> +			reg |= MC13783_POWER_CONTROL_2_ON2BRSTEN;
> +
> +		err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD2,
> +					  button_irq, "b2on", priv);
> +
> +		if (err) {
> +			dev_dbg(&pdev->dev, "Can't request irq\n");
> +			goto free_irq_b1;
> +		}
> +	}
> +
> +	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) {
> +		priv->keymap[0] = pdata->b3on_key;
> +		if (pdata->b3on_key != KEY_RESERVED)
> +			__set_bit(pdata->b3on_key, pwr->keybit);
> +
> +		if (pdata->b3on_flags & MC13783_BUTTON_POL_INVERT)
> +			priv->flags |= MC13783_PWRB_B3_POL_INVERT;
> +
> +		if (pdata->b3on_flags & MC13783_BUTTON_RESET_EN)
> +			reg |= MC13783_POWER_CONTROL_2_ON3BRSTEN;
> +
> +		err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD3,
> +					  button_irq, "b3on", priv);
> +
> +		if (err) {
> +			dev_dbg(&pdev->dev, "Can't request irq: %d\n", err);
> +			goto free_irq_b2;
> +		}
> +	}
> +
> +	mc13xxx_reg_rmw(mc13783, MC13783_REG_POWER_CONTROL_2, 0x3FE, reg);
> +
> +	mc13xxx_unlock(mc13783);
> +
> +	pwr->name = "mc13783_pwrbutton";
> +	pwr->phys = "mc13783_pwrbutton/input0";
> +	pwr->dev.parent = &pdev->dev;
> +
> +	pwr->keycode = priv->keymap;
> +	pwr->keycodemax = ARRAY_SIZE(priv->keymap);
> +	pwr->keycodesize = sizeof(priv->keymap[0]);
> +
> +	err = input_register_device(pwr);
> +	if (err) {
> +		dev_dbg(&pdev->dev, "Can't register power button: %d\n", err);
> +		goto free_irq;
> +	}
> +
> +	platform_set_drvdata(pdev, priv);
> +
> +	return 0;
> +
> +free_irq:
> +	mc13xxx_lock(mc13783);
> +
> +	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
> +		mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD3, priv);
> +free_irq_b2:
> +	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
> +		mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD2, priv);
> +
> +free_irq_b1:
> +	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
> +		mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);
> +
> +	mc13xxx_unlock(mc13783);
> +
> +free_priv:
> +	kfree(priv);
> +
> +free_input_dev:
> +	input_free_device(pwr);
> +
> +	return err;
> +}
> +
> +static int __devexit mc13783_pwrbutton_remove(struct platform_device *pdev)
> +{
> +	struct mc13783_pwrb *priv = platform_get_drvdata(pdev);
> +	struct mc13xxx_buttons_platform_data *pdata;
> +	pdata = dev_get_platdata(&pdev->dev);
> +
> +	mc13xxx_lock(priv->mc13783);
> +
> +	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
> +		mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD3, priv);
> +	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
> +		mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD2, priv);
> +	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
> +		mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv);
> +
> +	mc13xxx_unlock(priv->mc13783);
> +
> +	input_unregister_device(priv->pwr);
> +	kfree(priv);
> +
> +	return 0;
> +}
> +
> +struct platform_driver mc13783_pwrbutton_driver = {
> +	.probe		= mc13783_pwrbutton_probe,
> +	.remove		= __devexit_p(mc13783_pwrbutton_remove),
> +	.driver		= {
> +		.name	= "mc13783-pwrbutton",
> +		.owner	= THIS_MODULE,
> +	},
> +};
> +
> +static int __init mc13783_pwrbutton_init(void)
> +{
> +	return platform_driver_register(&mc13783_pwrbutton_driver);
> +}
> +module_init(mc13783_pwrbutton_init);
> +
> +static void __exit mc13783_pwrbutton_exit(void)
> +{
> +	platform_driver_unregister(&mc13783_pwrbutton_driver);
> +}
> +module_exit(mc13783_pwrbutton_exit);
> +
> +MODULE_ALIAS("platform:mc13783-pwrbutton");
> +MODULE_DESCRIPTION("MC13783 Power Button");
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Philippe Retornaz");
> diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
> index 7e4d44b..44edf78 100644
> --- a/drivers/mfd/mc13xxx-core.c
> +++ b/drivers/mfd/mc13xxx-core.c
> @@ -778,6 +778,10 @@ err_revision:
>  		mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led",
>  				pdata->leds, sizeof(*pdata->leds));
>  
> +	if (pdata->flags & MC13XXX_USE_BUTTON)
Why not use

	if (pdata->buttons)

to detect if the pwrbutton device should be registered?

> +		mc13xxx_add_subdevice_pdata(mc13xxx, "%s-pwrbutton",
> +				pdata->buttons, sizeof(*pdata->buttons));
> +
>  	return 0;
>  }
>  
> diff --git a/include/linux/mfd/mc13783.h b/include/linux/mfd/mc13783.h
> index 7d0f3d6..bd4fbac 100644
> --- a/include/linux/mfd/mc13783.h
> +++ b/include/linux/mfd/mc13783.h
> @@ -106,6 +106,7 @@ static inline int mc13783_irq_ack(struct mc13783 *mc13783, int irq)
>  #define mc13783_regulator_platform_data mc13xxx_regulator_platform_data
>  #define mc13783_led_platform_data mc13xxx_led_platform_data
>  #define mc13783_leds_platform_data mc13xxx_leds_platform_data
> +#define mc13783_buttons_platform_data mc13xxx_buttons_platform_data
>  
>  #define mc13783_platform_data mc13xxx_platform_data
>  #define MC13783_USE_TOUCHSCREEN	MC13XXX_USE_TOUCHSCREEN
> diff --git a/include/linux/mfd/mc13xxx.h b/include/linux/mfd/mc13xxx.h
> index c064bea..22d8930 100644
> --- a/include/linux/mfd/mc13xxx.h
> +++ b/include/linux/mfd/mc13xxx.h
> @@ -137,6 +137,22 @@ struct mc13xxx_leds_platform_data {
>  	char tc3_period;
>  };
>  
> +struct mc13xxx_buttons_platform_data {
> +#define MC13783_BUTTON_DBNC_0MS		0
> +#define MC13783_BUTTON_DBNC_30MS	1
> +#define MC13783_BUTTON_DBNC_150MS	2
> +#define MC13783_BUTTON_DBNC_750MS	3
> +#define MC13783_BUTTON_ENABLE		(1 << 2)
> +#define MC13783_BUTTON_POL_INVERT	(1 << 3)
> +#define MC13783_BUTTON_RESET_EN		(1 << 4)
> +	int b1on_flags;
> +	unsigned short b1on_key;
> +	int b2on_flags;
> +	unsigned short b2on_key;
> +	int b3on_flags;
> +	unsigned short b3on_key;
> +};
> +
>  struct mc13xxx_platform_data {
>  #define MC13XXX_USE_TOUCHSCREEN (1 << 0)
>  #define MC13XXX_USE_CODEC	(1 << 1)
> @@ -144,10 +160,12 @@ struct mc13xxx_platform_data {
>  #define MC13XXX_USE_RTC		(1 << 3)
>  #define MC13XXX_USE_REGULATOR	(1 << 4)
>  #define MC13XXX_USE_LED		(1 << 5)
> +#define MC13XXX_USE_BUTTON	(1 << 6)
>  	unsigned int flags;
>  
>  	struct mc13xxx_regulator_platform_data regulators;
>  	struct mc13xxx_leds_platform_data *leds;
> +	struct mc13xxx_buttons_platform_data *buttons;
>  };
>  
>  #endif /* ifndef __LINUX_MFD_MC13XXX_H */

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 1/2] mc13783: add power button support
@ 2011-07-08 14:30     ` Uwe Kleine-König
  0 siblings, 0 replies; 20+ messages in thread
From: Uwe Kleine-König @ 2011-07-08 14:30 UTC (permalink / raw)
  To: linux-arm-kernel

Hello Philippe,

On Fri, Jul 08, 2011 at 04:23:56PM +0200, Philippe R?tornaz wrote:
> This adds support for the power-on buttons of MC13783 PMIC.
> This is done using a misc input device.
> 
> Signed-off-by: Philippe R?tornaz <philippe.retornaz@epfl.ch>
> ---
>  drivers/input/misc/Kconfig             |   11 ++
>  drivers/input/misc/Makefile            |    1 +
>  drivers/input/misc/mc13783-pwrbutton.c |  288 ++++++++++++++++++++++++++++++++
>  drivers/mfd/mc13xxx-core.c             |    4 +
>  include/linux/mfd/mc13783.h            |    1 +
>  include/linux/mfd/mc13xxx.h            |   18 ++
>  6 files changed, 323 insertions(+), 0 deletions(-)
>  create mode 100644 drivers/input/misc/mc13783-pwrbutton.c
> 
> diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
> index 45dc6aa..87d595c 100644
> --- a/drivers/input/misc/Kconfig
> +++ b/drivers/input/misc/Kconfig
> @@ -100,6 +100,17 @@ config INPUT_MAX8925_ONKEY
>  	  To compile this driver as a module, choose M here: the module
>  	  will be called max8925_onkey.
>  
> +config INPUT_MC13783_ON
> +	tristate "MC13783 ON buttons"
> +	depends on MFD_MC13783
> +	help
> +	  Support the ON buttons of MC13783 PMIC as an input device
> +	  reporting power button status.
> +
> +	  To compile this driver as a module, choose M here: the module
> +	  will be called mc13783-pwrbutton.
Why not use INPUT_MC13783_PWRBUTTON to match the source file (and so
module) name.
> +
> +
one empty line should be enough
>  config INPUT_APANEL
>  	tristate "Fujitsu Lifebook Application Panel buttons"
>  	depends on X86 && I2C && LEDS_CLASS
> diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
> index 38efb2c..fdc6ab9 100644
> --- a/drivers/input/misc/Makefile
> +++ b/drivers/input/misc/Makefile
> @@ -27,6 +27,7 @@ obj-$(CONFIG_INPUT_IXP4XX_BEEPER)	+= ixp4xx-beeper.o
>  obj-$(CONFIG_INPUT_KEYSPAN_REMOTE)	+= keyspan_remote.o
>  obj-$(CONFIG_INPUT_M68K_BEEP)		+= m68kspkr.o
>  obj-$(CONFIG_INPUT_MAX8925_ONKEY)	+= max8925_onkey.o
> +obj-$(CONFIG_INPUT_MC13783_ON)		+= mc13783-pwrbutton.o
>  obj-$(CONFIG_INPUT_PCAP)		+= pcap_keys.o
>  obj-$(CONFIG_INPUT_PCF50633_PMU)	+= pcf50633-input.o
>  obj-$(CONFIG_INPUT_PCF8574)		+= pcf8574_keypad.o
> diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
> new file mode 100644
> index 0000000..6aee01c
> --- /dev/null
> +++ b/drivers/input/misc/mc13783-pwrbutton.c
> @@ -0,0 +1,288 @@
> +/**
> + * mc13783-pwrbutton.c - MC13783 Power Button Input Driver
> + *
> + * Copyright (C) 2011 Philippe R?tornaz
> + *
> + * Based on twl4030-pwrbutton driver by:
> + *     Peter De Schrijver <peter.de-schrijver@nokia.com>
> + *     Felipe Balbi <felipe.balbi@nokia.com>
> + *
> + * This file is subject to the terms and conditions of the GNU General
> + * Public License. See the file "COPYING" in the main directory of this
> + * archive for more details.
This implies GPL v2 only? So you either need to clearify here or you
need to adapt the MODULE_LICENSE line below to read

	MODULE_LICENSE("GPL v2");

> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
This is not the recent address of the FSF.

> + */
> +
> +#include <linux/module.h>
> +#include <linux/init.h>
> +#include <linux/kernel.h>
> +#include <linux/errno.h>
> +#include <linux/input.h>
> +#include <linux/interrupt.h>
> +#include <linux/platform_device.h>
> +#include <linux/mfd/mc13783.h>
> +#include <linux/sched.h>
> +#include <linux/slab.h>
> +
> +struct mc13783_pwrb {
> +	struct input_dev *pwr;
> +	struct mc13xxx *mc13783;
> +#define MC13783_PWRB_B1_POL_INVERT	(1 << 0)
> +#define MC13783_PWRB_B2_POL_INVERT	(1 << 1)
> +#define MC13783_PWRB_B3_POL_INVERT	(1 << 2)
> +	int flags;
> +	unsigned short keymap[3];
> +};
> +
> +#define MC13783_REG_INTERRUPT_SENSE_1		5
> +#define MC13783_IRQSENSE1_ONOFD1S		(1 << 3)
> +#define MC13783_IRQSENSE1_ONOFD2S		(1 << 4)
> +#define MC13783_IRQSENSE1_ONOFD3S		(1 << 5)
> +
> +#define MC13783_REG_POWER_CONTROL_2		15
> +#define MC13783_POWER_CONTROL_2_ON1BDBNC	4
> +#define MC13783_POWER_CONTROL_2_ON2BDBNC	6
> +#define MC13783_POWER_CONTROL_2_ON3BDBNC	8
> +#define MC13783_POWER_CONTROL_2_ON1BRSTEN	(1 << 1)
> +#define MC13783_POWER_CONTROL_2_ON2BRSTEN	(1 << 2)
> +#define MC13783_POWER_CONTROL_2_ON3BRSTEN	(1 << 3)
> +
> +static irqreturn_t button_irq(int irq, void *_priv)
> +{
> +	struct mc13783_pwrb *priv = _priv;
> +	int val;
> +	mc13xxx_irq_ack(priv->mc13783, irq);
> +	mc13xxx_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
> +
> +	switch (irq) {
> +	case MC13783_IRQ_ONOFD1:
> +		val = val & MC13783_IRQSENSE1_ONOFD1S ? 1 : 0;
> +		if (priv->flags & MC13783_PWRB_B1_POL_INVERT)
> +			val ^= 1;
> +		input_report_key(priv->pwr, priv->keymap[0], val);
> +		break;
> +
> +	case MC13783_IRQ_ONOFD2:
> +		val = val & MC13783_IRQSENSE1_ONOFD2S ? 1 : 0;
> +		if (priv->flags & MC13783_PWRB_B2_POL_INVERT)
> +			val ^= 1;
> +		input_report_key(priv->pwr, priv->keymap[1], val);
> +		break;
> +
> +	case MC13783_IRQ_ONOFD3:
> +		val = val & MC13783_IRQSENSE1_ONOFD3S ? 1 : 0;
> +		if (priv->flags & MC13783_PWRB_B3_POL_INVERT)
> +			val ^= 1;
> +		input_report_key(priv->pwr, priv->keymap[2], val);
> +		break;
> +	}
> +
> +	input_sync(priv->pwr);
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static int __devinit mc13783_pwrbutton_probe(struct platform_device *pdev)
> +{
> +	struct mc13xxx_buttons_platform_data *pdata;
> +	struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent);
> +	struct input_dev *pwr;
> +	struct mc13783_pwrb *priv;
> +	int err = 0;
> +	int reg = 0;
> +
> +	pdata = dev_get_platdata(&pdev->dev);
> +	if (pdata == NULL) {
> +		dev_err(&pdev->dev, "missing platform data\n");
> +		return -ENODEV;
> +	}
> +
> +	pwr = input_allocate_device();
> +	if (!pwr) {
> +		dev_dbg(&pdev->dev, "Can't allocate power button\n");
> +		return -ENOMEM;
> +	}
> +
> +	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
> +
> +	if (!priv) {
> +		err = -ENOMEM;
> +		dev_dbg(&pdev->dev, "Can't allocate power button\n");
> +		goto free_input_dev;
> +	}
> +
> +	pwr->evbit[0] = BIT_MASK(EV_KEY);
> +
> +	reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
> +	reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
> +	reg |= (pdata->b3on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC;
> +
> +	priv->pwr = pwr;
> +	priv->mc13783 = mc13783;
> +
> +	mc13xxx_lock(mc13783);
> +
> +	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) {
> +		priv->keymap[0] = pdata->b1on_key;
> +		if (pdata->b1on_key != KEY_RESERVED)
> +			__set_bit(pdata->b1on_key, pwr->keybit);
> +
> +		if (pdata->b1on_flags & MC13783_BUTTON_POL_INVERT)
> +			priv->flags |= MC13783_PWRB_B1_POL_INVERT;
> +
> +		if (pdata->b1on_flags & MC13783_BUTTON_RESET_EN)
> +			reg |= MC13783_POWER_CONTROL_2_ON1BRSTEN;
> +
> +		err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD1,
> +					  button_irq, "b1on", priv);
> +
> +		if (err) {
> +			mc13xxx_unlock(mc13783);
> +
> +			dev_dbg(&pdev->dev, "Can't request irq\n");
> +			goto free_priv;
> +		}
> +	}
> +
> +	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) {
> +		priv->keymap[0] = pdata->b2on_key;
> +		if (pdata->b2on_key != KEY_RESERVED)
> +			__set_bit(pdata->b2on_key, pwr->keybit);
> +
> +		if (pdata->b2on_flags & MC13783_BUTTON_POL_INVERT)
> +			priv->flags |= MC13783_PWRB_B2_POL_INVERT;
> +
> +		if (pdata->b2on_flags & MC13783_BUTTON_RESET_EN)
> +			reg |= MC13783_POWER_CONTROL_2_ON2BRSTEN;
> +
> +		err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD2,
> +					  button_irq, "b2on", priv);
> +
> +		if (err) {
> +			dev_dbg(&pdev->dev, "Can't request irq\n");
> +			goto free_irq_b1;
> +		}
> +	}
> +
> +	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) {
> +		priv->keymap[0] = pdata->b3on_key;
> +		if (pdata->b3on_key != KEY_RESERVED)
> +			__set_bit(pdata->b3on_key, pwr->keybit);
> +
> +		if (pdata->b3on_flags & MC13783_BUTTON_POL_INVERT)
> +			priv->flags |= MC13783_PWRB_B3_POL_INVERT;
> +
> +		if (pdata->b3on_flags & MC13783_BUTTON_RESET_EN)
> +			reg |= MC13783_POWER_CONTROL_2_ON3BRSTEN;
> +
> +		err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD3,
> +					  button_irq, "b3on", priv);
> +
> +		if (err) {
> +			dev_dbg(&pdev->dev, "Can't request irq: %d\n", err);
> +			goto free_irq_b2;
> +		}
> +	}
> +
> +	mc13xxx_reg_rmw(mc13783, MC13783_REG_POWER_CONTROL_2, 0x3FE, reg);
> +
> +	mc13xxx_unlock(mc13783);
> +
> +	pwr->name = "mc13783_pwrbutton";
> +	pwr->phys = "mc13783_pwrbutton/input0";
> +	pwr->dev.parent = &pdev->dev;
> +
> +	pwr->keycode = priv->keymap;
> +	pwr->keycodemax = ARRAY_SIZE(priv->keymap);
> +	pwr->keycodesize = sizeof(priv->keymap[0]);
> +
> +	err = input_register_device(pwr);
> +	if (err) {
> +		dev_dbg(&pdev->dev, "Can't register power button: %d\n", err);
> +		goto free_irq;
> +	}
> +
> +	platform_set_drvdata(pdev, priv);
> +
> +	return 0;
> +
> +free_irq:
> +	mc13xxx_lock(mc13783);
> +
> +	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
> +		mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD3, priv);
> +free_irq_b2:
> +	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
> +		mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD2, priv);
> +
> +free_irq_b1:
> +	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
> +		mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);
> +
> +	mc13xxx_unlock(mc13783);
> +
> +free_priv:
> +	kfree(priv);
> +
> +free_input_dev:
> +	input_free_device(pwr);
> +
> +	return err;
> +}
> +
> +static int __devexit mc13783_pwrbutton_remove(struct platform_device *pdev)
> +{
> +	struct mc13783_pwrb *priv = platform_get_drvdata(pdev);
> +	struct mc13xxx_buttons_platform_data *pdata;
> +	pdata = dev_get_platdata(&pdev->dev);
> +
> +	mc13xxx_lock(priv->mc13783);
> +
> +	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
> +		mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD3, priv);
> +	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
> +		mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD2, priv);
> +	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
> +		mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv);
> +
> +	mc13xxx_unlock(priv->mc13783);
> +
> +	input_unregister_device(priv->pwr);
> +	kfree(priv);
> +
> +	return 0;
> +}
> +
> +struct platform_driver mc13783_pwrbutton_driver = {
> +	.probe		= mc13783_pwrbutton_probe,
> +	.remove		= __devexit_p(mc13783_pwrbutton_remove),
> +	.driver		= {
> +		.name	= "mc13783-pwrbutton",
> +		.owner	= THIS_MODULE,
> +	},
> +};
> +
> +static int __init mc13783_pwrbutton_init(void)
> +{
> +	return platform_driver_register(&mc13783_pwrbutton_driver);
> +}
> +module_init(mc13783_pwrbutton_init);
> +
> +static void __exit mc13783_pwrbutton_exit(void)
> +{
> +	platform_driver_unregister(&mc13783_pwrbutton_driver);
> +}
> +module_exit(mc13783_pwrbutton_exit);
> +
> +MODULE_ALIAS("platform:mc13783-pwrbutton");
> +MODULE_DESCRIPTION("MC13783 Power Button");
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Philippe Retornaz");
> diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
> index 7e4d44b..44edf78 100644
> --- a/drivers/mfd/mc13xxx-core.c
> +++ b/drivers/mfd/mc13xxx-core.c
> @@ -778,6 +778,10 @@ err_revision:
>  		mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led",
>  				pdata->leds, sizeof(*pdata->leds));
>  
> +	if (pdata->flags & MC13XXX_USE_BUTTON)
Why not use

	if (pdata->buttons)

to detect if the pwrbutton device should be registered?

> +		mc13xxx_add_subdevice_pdata(mc13xxx, "%s-pwrbutton",
> +				pdata->buttons, sizeof(*pdata->buttons));
> +
>  	return 0;
>  }
>  
> diff --git a/include/linux/mfd/mc13783.h b/include/linux/mfd/mc13783.h
> index 7d0f3d6..bd4fbac 100644
> --- a/include/linux/mfd/mc13783.h
> +++ b/include/linux/mfd/mc13783.h
> @@ -106,6 +106,7 @@ static inline int mc13783_irq_ack(struct mc13783 *mc13783, int irq)
>  #define mc13783_regulator_platform_data mc13xxx_regulator_platform_data
>  #define mc13783_led_platform_data mc13xxx_led_platform_data
>  #define mc13783_leds_platform_data mc13xxx_leds_platform_data
> +#define mc13783_buttons_platform_data mc13xxx_buttons_platform_data
>  
>  #define mc13783_platform_data mc13xxx_platform_data
>  #define MC13783_USE_TOUCHSCREEN	MC13XXX_USE_TOUCHSCREEN
> diff --git a/include/linux/mfd/mc13xxx.h b/include/linux/mfd/mc13xxx.h
> index c064bea..22d8930 100644
> --- a/include/linux/mfd/mc13xxx.h
> +++ b/include/linux/mfd/mc13xxx.h
> @@ -137,6 +137,22 @@ struct mc13xxx_leds_platform_data {
>  	char tc3_period;
>  };
>  
> +struct mc13xxx_buttons_platform_data {
> +#define MC13783_BUTTON_DBNC_0MS		0
> +#define MC13783_BUTTON_DBNC_30MS	1
> +#define MC13783_BUTTON_DBNC_150MS	2
> +#define MC13783_BUTTON_DBNC_750MS	3
> +#define MC13783_BUTTON_ENABLE		(1 << 2)
> +#define MC13783_BUTTON_POL_INVERT	(1 << 3)
> +#define MC13783_BUTTON_RESET_EN		(1 << 4)
> +	int b1on_flags;
> +	unsigned short b1on_key;
> +	int b2on_flags;
> +	unsigned short b2on_key;
> +	int b3on_flags;
> +	unsigned short b3on_key;
> +};
> +
>  struct mc13xxx_platform_data {
>  #define MC13XXX_USE_TOUCHSCREEN (1 << 0)
>  #define MC13XXX_USE_CODEC	(1 << 1)
> @@ -144,10 +160,12 @@ struct mc13xxx_platform_data {
>  #define MC13XXX_USE_RTC		(1 << 3)
>  #define MC13XXX_USE_REGULATOR	(1 << 4)
>  #define MC13XXX_USE_LED		(1 << 5)
> +#define MC13XXX_USE_BUTTON	(1 << 6)
>  	unsigned int flags;
>  
>  	struct mc13xxx_regulator_platform_data regulators;
>  	struct mc13xxx_leds_platform_data *leds;
> +	struct mc13xxx_buttons_platform_data *buttons;
>  };
>  
>  #endif /* ifndef __LINUX_MFD_MC13XXX_H */

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-K?nig            |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 1/2] mc13783: add power button support
  2011-07-08 14:23 [PATCH v2 0/2] mc13783: add pwr " Philippe Rétornaz
@ 2011-07-08 14:23   ` Philippe Rétornaz
  0 siblings, 0 replies; 20+ messages in thread
From: Philippe Rétornaz @ 2011-07-08 14:23 UTC (permalink / raw)
  To: s.hauer
  Cc: linux-input, broonie, sameo, dmitry.torokhov, u.kleine-koenig,
	philippe.retornaz, linux-arm-kernel

This adds support for the power-on buttons of MC13783 PMIC.
This is done using a misc input device.

Signed-off-by: Philippe Rétornaz <philippe.retornaz@epfl.ch>
---
 drivers/input/misc/Kconfig             |   11 ++
 drivers/input/misc/Makefile            |    1 +
 drivers/input/misc/mc13783-pwrbutton.c |  288 ++++++++++++++++++++++++++++++++
 drivers/mfd/mc13xxx-core.c             |    4 +
 include/linux/mfd/mc13783.h            |    1 +
 include/linux/mfd/mc13xxx.h            |   18 ++
 6 files changed, 323 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/misc/mc13783-pwrbutton.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 45dc6aa..87d595c 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -100,6 +100,17 @@ config INPUT_MAX8925_ONKEY
 	  To compile this driver as a module, choose M here: the module
 	  will be called max8925_onkey.
 
+config INPUT_MC13783_ON
+	tristate "MC13783 ON buttons"
+	depends on MFD_MC13783
+	help
+	  Support the ON buttons of MC13783 PMIC as an input device
+	  reporting power button status.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mc13783-pwrbutton.
+
+
 config INPUT_APANEL
 	tristate "Fujitsu Lifebook Application Panel buttons"
 	depends on X86 && I2C && LEDS_CLASS
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 38efb2c..fdc6ab9 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_INPUT_IXP4XX_BEEPER)	+= ixp4xx-beeper.o
 obj-$(CONFIG_INPUT_KEYSPAN_REMOTE)	+= keyspan_remote.o
 obj-$(CONFIG_INPUT_M68K_BEEP)		+= m68kspkr.o
 obj-$(CONFIG_INPUT_MAX8925_ONKEY)	+= max8925_onkey.o
+obj-$(CONFIG_INPUT_MC13783_ON)		+= mc13783-pwrbutton.o
 obj-$(CONFIG_INPUT_PCAP)		+= pcap_keys.o
 obj-$(CONFIG_INPUT_PCF50633_PMU)	+= pcf50633-input.o
 obj-$(CONFIG_INPUT_PCF8574)		+= pcf8574_keypad.o
diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
new file mode 100644
index 0000000..6aee01c
--- /dev/null
+++ b/drivers/input/misc/mc13783-pwrbutton.c
@@ -0,0 +1,288 @@
+/**
+ * mc13783-pwrbutton.c - MC13783 Power Button Input Driver
+ *
+ * Copyright (C) 2011 Philippe Rétornaz
+ *
+ * Based on twl4030-pwrbutton driver by:
+ *     Peter De Schrijver <peter.de-schrijver@nokia.com>
+ *     Felipe Balbi <felipe.balbi@nokia.com>
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file "COPYING" in the main directory of this
+ * archive for more details.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/mfd/mc13783.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+
+struct mc13783_pwrb {
+	struct input_dev *pwr;
+	struct mc13xxx *mc13783;
+#define MC13783_PWRB_B1_POL_INVERT	(1 << 0)
+#define MC13783_PWRB_B2_POL_INVERT	(1 << 1)
+#define MC13783_PWRB_B3_POL_INVERT	(1 << 2)
+	int flags;
+	unsigned short keymap[3];
+};
+
+#define MC13783_REG_INTERRUPT_SENSE_1		5
+#define MC13783_IRQSENSE1_ONOFD1S		(1 << 3)
+#define MC13783_IRQSENSE1_ONOFD2S		(1 << 4)
+#define MC13783_IRQSENSE1_ONOFD3S		(1 << 5)
+
+#define MC13783_REG_POWER_CONTROL_2		15
+#define MC13783_POWER_CONTROL_2_ON1BDBNC	4
+#define MC13783_POWER_CONTROL_2_ON2BDBNC	6
+#define MC13783_POWER_CONTROL_2_ON3BDBNC	8
+#define MC13783_POWER_CONTROL_2_ON1BRSTEN	(1 << 1)
+#define MC13783_POWER_CONTROL_2_ON2BRSTEN	(1 << 2)
+#define MC13783_POWER_CONTROL_2_ON3BRSTEN	(1 << 3)
+
+static irqreturn_t button_irq(int irq, void *_priv)
+{
+	struct mc13783_pwrb *priv = _priv;
+	int val;
+	mc13xxx_irq_ack(priv->mc13783, irq);
+	mc13xxx_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
+
+	switch (irq) {
+	case MC13783_IRQ_ONOFD1:
+		val = val & MC13783_IRQSENSE1_ONOFD1S ? 1 : 0;
+		if (priv->flags & MC13783_PWRB_B1_POL_INVERT)
+			val ^= 1;
+		input_report_key(priv->pwr, priv->keymap[0], val);
+		break;
+
+	case MC13783_IRQ_ONOFD2:
+		val = val & MC13783_IRQSENSE1_ONOFD2S ? 1 : 0;
+		if (priv->flags & MC13783_PWRB_B2_POL_INVERT)
+			val ^= 1;
+		input_report_key(priv->pwr, priv->keymap[1], val);
+		break;
+
+	case MC13783_IRQ_ONOFD3:
+		val = val & MC13783_IRQSENSE1_ONOFD3S ? 1 : 0;
+		if (priv->flags & MC13783_PWRB_B3_POL_INVERT)
+			val ^= 1;
+		input_report_key(priv->pwr, priv->keymap[2], val);
+		break;
+	}
+
+	input_sync(priv->pwr);
+
+	return IRQ_HANDLED;
+}
+
+static int __devinit mc13783_pwrbutton_probe(struct platform_device *pdev)
+{
+	struct mc13xxx_buttons_platform_data *pdata;
+	struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent);
+	struct input_dev *pwr;
+	struct mc13783_pwrb *priv;
+	int err = 0;
+	int reg = 0;
+
+	pdata = dev_get_platdata(&pdev->dev);
+	if (pdata == NULL) {
+		dev_err(&pdev->dev, "missing platform data\n");
+		return -ENODEV;
+	}
+
+	pwr = input_allocate_device();
+	if (!pwr) {
+		dev_dbg(&pdev->dev, "Can't allocate power button\n");
+		return -ENOMEM;
+	}
+
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+
+	if (!priv) {
+		err = -ENOMEM;
+		dev_dbg(&pdev->dev, "Can't allocate power button\n");
+		goto free_input_dev;
+	}
+
+	pwr->evbit[0] = BIT_MASK(EV_KEY);
+
+	reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
+	reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
+	reg |= (pdata->b3on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC;
+
+	priv->pwr = pwr;
+	priv->mc13783 = mc13783;
+
+	mc13xxx_lock(mc13783);
+
+	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) {
+		priv->keymap[0] = pdata->b1on_key;
+		if (pdata->b1on_key != KEY_RESERVED)
+			__set_bit(pdata->b1on_key, pwr->keybit);
+
+		if (pdata->b1on_flags & MC13783_BUTTON_POL_INVERT)
+			priv->flags |= MC13783_PWRB_B1_POL_INVERT;
+
+		if (pdata->b1on_flags & MC13783_BUTTON_RESET_EN)
+			reg |= MC13783_POWER_CONTROL_2_ON1BRSTEN;
+
+		err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD1,
+					  button_irq, "b1on", priv);
+
+		if (err) {
+			mc13xxx_unlock(mc13783);
+
+			dev_dbg(&pdev->dev, "Can't request irq\n");
+			goto free_priv;
+		}
+	}
+
+	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) {
+		priv->keymap[0] = pdata->b2on_key;
+		if (pdata->b2on_key != KEY_RESERVED)
+			__set_bit(pdata->b2on_key, pwr->keybit);
+
+		if (pdata->b2on_flags & MC13783_BUTTON_POL_INVERT)
+			priv->flags |= MC13783_PWRB_B2_POL_INVERT;
+
+		if (pdata->b2on_flags & MC13783_BUTTON_RESET_EN)
+			reg |= MC13783_POWER_CONTROL_2_ON2BRSTEN;
+
+		err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD2,
+					  button_irq, "b2on", priv);
+
+		if (err) {
+			dev_dbg(&pdev->dev, "Can't request irq\n");
+			goto free_irq_b1;
+		}
+	}
+
+	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) {
+		priv->keymap[0] = pdata->b3on_key;
+		if (pdata->b3on_key != KEY_RESERVED)
+			__set_bit(pdata->b3on_key, pwr->keybit);
+
+		if (pdata->b3on_flags & MC13783_BUTTON_POL_INVERT)
+			priv->flags |= MC13783_PWRB_B3_POL_INVERT;
+
+		if (pdata->b3on_flags & MC13783_BUTTON_RESET_EN)
+			reg |= MC13783_POWER_CONTROL_2_ON3BRSTEN;
+
+		err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD3,
+					  button_irq, "b3on", priv);
+
+		if (err) {
+			dev_dbg(&pdev->dev, "Can't request irq: %d\n", err);
+			goto free_irq_b2;
+		}
+	}
+
+	mc13xxx_reg_rmw(mc13783, MC13783_REG_POWER_CONTROL_2, 0x3FE, reg);
+
+	mc13xxx_unlock(mc13783);
+
+	pwr->name = "mc13783_pwrbutton";
+	pwr->phys = "mc13783_pwrbutton/input0";
+	pwr->dev.parent = &pdev->dev;
+
+	pwr->keycode = priv->keymap;
+	pwr->keycodemax = ARRAY_SIZE(priv->keymap);
+	pwr->keycodesize = sizeof(priv->keymap[0]);
+
+	err = input_register_device(pwr);
+	if (err) {
+		dev_dbg(&pdev->dev, "Can't register power button: %d\n", err);
+		goto free_irq;
+	}
+
+	platform_set_drvdata(pdev, priv);
+
+	return 0;
+
+free_irq:
+	mc13xxx_lock(mc13783);
+
+	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
+		mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD3, priv);
+free_irq_b2:
+	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
+		mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD2, priv);
+
+free_irq_b1:
+	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
+		mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);
+
+	mc13xxx_unlock(mc13783);
+
+free_priv:
+	kfree(priv);
+
+free_input_dev:
+	input_free_device(pwr);
+
+	return err;
+}
+
+static int __devexit mc13783_pwrbutton_remove(struct platform_device *pdev)
+{
+	struct mc13783_pwrb *priv = platform_get_drvdata(pdev);
+	struct mc13xxx_buttons_platform_data *pdata;
+	pdata = dev_get_platdata(&pdev->dev);
+
+	mc13xxx_lock(priv->mc13783);
+
+	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
+		mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD3, priv);
+	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
+		mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD2, priv);
+	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
+		mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv);
+
+	mc13xxx_unlock(priv->mc13783);
+
+	input_unregister_device(priv->pwr);
+	kfree(priv);
+
+	return 0;
+}
+
+struct platform_driver mc13783_pwrbutton_driver = {
+	.probe		= mc13783_pwrbutton_probe,
+	.remove		= __devexit_p(mc13783_pwrbutton_remove),
+	.driver		= {
+		.name	= "mc13783-pwrbutton",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init mc13783_pwrbutton_init(void)
+{
+	return platform_driver_register(&mc13783_pwrbutton_driver);
+}
+module_init(mc13783_pwrbutton_init);
+
+static void __exit mc13783_pwrbutton_exit(void)
+{
+	platform_driver_unregister(&mc13783_pwrbutton_driver);
+}
+module_exit(mc13783_pwrbutton_exit);
+
+MODULE_ALIAS("platform:mc13783-pwrbutton");
+MODULE_DESCRIPTION("MC13783 Power Button");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Philippe Retornaz");
diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
index 7e4d44b..44edf78 100644
--- a/drivers/mfd/mc13xxx-core.c
+++ b/drivers/mfd/mc13xxx-core.c
@@ -778,6 +778,10 @@ err_revision:
 		mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led",
 				pdata->leds, sizeof(*pdata->leds));
 
+	if (pdata->flags & MC13XXX_USE_BUTTON)
+		mc13xxx_add_subdevice_pdata(mc13xxx, "%s-pwrbutton",
+				pdata->buttons, sizeof(*pdata->buttons));
+
 	return 0;
 }
 
diff --git a/include/linux/mfd/mc13783.h b/include/linux/mfd/mc13783.h
index 7d0f3d6..bd4fbac 100644
--- a/include/linux/mfd/mc13783.h
+++ b/include/linux/mfd/mc13783.h
@@ -106,6 +106,7 @@ static inline int mc13783_irq_ack(struct mc13783 *mc13783, int irq)
 #define mc13783_regulator_platform_data mc13xxx_regulator_platform_data
 #define mc13783_led_platform_data mc13xxx_led_platform_data
 #define mc13783_leds_platform_data mc13xxx_leds_platform_data
+#define mc13783_buttons_platform_data mc13xxx_buttons_platform_data
 
 #define mc13783_platform_data mc13xxx_platform_data
 #define MC13783_USE_TOUCHSCREEN	MC13XXX_USE_TOUCHSCREEN
diff --git a/include/linux/mfd/mc13xxx.h b/include/linux/mfd/mc13xxx.h
index c064bea..22d8930 100644
--- a/include/linux/mfd/mc13xxx.h
+++ b/include/linux/mfd/mc13xxx.h
@@ -137,6 +137,22 @@ struct mc13xxx_leds_platform_data {
 	char tc3_period;
 };
 
+struct mc13xxx_buttons_platform_data {
+#define MC13783_BUTTON_DBNC_0MS		0
+#define MC13783_BUTTON_DBNC_30MS	1
+#define MC13783_BUTTON_DBNC_150MS	2
+#define MC13783_BUTTON_DBNC_750MS	3
+#define MC13783_BUTTON_ENABLE		(1 << 2)
+#define MC13783_BUTTON_POL_INVERT	(1 << 3)
+#define MC13783_BUTTON_RESET_EN		(1 << 4)
+	int b1on_flags;
+	unsigned short b1on_key;
+	int b2on_flags;
+	unsigned short b2on_key;
+	int b3on_flags;
+	unsigned short b3on_key;
+};
+
 struct mc13xxx_platform_data {
 #define MC13XXX_USE_TOUCHSCREEN (1 << 0)
 #define MC13XXX_USE_CODEC	(1 << 1)
@@ -144,10 +160,12 @@ struct mc13xxx_platform_data {
 #define MC13XXX_USE_RTC		(1 << 3)
 #define MC13XXX_USE_REGULATOR	(1 << 4)
 #define MC13XXX_USE_LED		(1 << 5)
+#define MC13XXX_USE_BUTTON	(1 << 6)
 	unsigned int flags;
 
 	struct mc13xxx_regulator_platform_data regulators;
 	struct mc13xxx_leds_platform_data *leds;
+	struct mc13xxx_buttons_platform_data *buttons;
 };
 
 #endif /* ifndef __LINUX_MFD_MC13XXX_H */
-- 
1.6.3.3


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 1/2] mc13783: add power button support
@ 2011-07-08 14:23   ` Philippe Rétornaz
  0 siblings, 0 replies; 20+ messages in thread
From: Philippe Rétornaz @ 2011-07-08 14:23 UTC (permalink / raw)
  To: linux-arm-kernel

This adds support for the power-on buttons of MC13783 PMIC.
This is done using a misc input device.

Signed-off-by: Philippe R?tornaz <philippe.retornaz@epfl.ch>
---
 drivers/input/misc/Kconfig             |   11 ++
 drivers/input/misc/Makefile            |    1 +
 drivers/input/misc/mc13783-pwrbutton.c |  288 ++++++++++++++++++++++++++++++++
 drivers/mfd/mc13xxx-core.c             |    4 +
 include/linux/mfd/mc13783.h            |    1 +
 include/linux/mfd/mc13xxx.h            |   18 ++
 6 files changed, 323 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/misc/mc13783-pwrbutton.c

diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index 45dc6aa..87d595c 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -100,6 +100,17 @@ config INPUT_MAX8925_ONKEY
 	  To compile this driver as a module, choose M here: the module
 	  will be called max8925_onkey.
 
+config INPUT_MC13783_ON
+	tristate "MC13783 ON buttons"
+	depends on MFD_MC13783
+	help
+	  Support the ON buttons of MC13783 PMIC as an input device
+	  reporting power button status.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called mc13783-pwrbutton.
+
+
 config INPUT_APANEL
 	tristate "Fujitsu Lifebook Application Panel buttons"
 	depends on X86 && I2C && LEDS_CLASS
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index 38efb2c..fdc6ab9 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_INPUT_IXP4XX_BEEPER)	+= ixp4xx-beeper.o
 obj-$(CONFIG_INPUT_KEYSPAN_REMOTE)	+= keyspan_remote.o
 obj-$(CONFIG_INPUT_M68K_BEEP)		+= m68kspkr.o
 obj-$(CONFIG_INPUT_MAX8925_ONKEY)	+= max8925_onkey.o
+obj-$(CONFIG_INPUT_MC13783_ON)		+= mc13783-pwrbutton.o
 obj-$(CONFIG_INPUT_PCAP)		+= pcap_keys.o
 obj-$(CONFIG_INPUT_PCF50633_PMU)	+= pcf50633-input.o
 obj-$(CONFIG_INPUT_PCF8574)		+= pcf8574_keypad.o
diff --git a/drivers/input/misc/mc13783-pwrbutton.c b/drivers/input/misc/mc13783-pwrbutton.c
new file mode 100644
index 0000000..6aee01c
--- /dev/null
+++ b/drivers/input/misc/mc13783-pwrbutton.c
@@ -0,0 +1,288 @@
+/**
+ * mc13783-pwrbutton.c - MC13783 Power Button Input Driver
+ *
+ * Copyright (C) 2011 Philippe R?tornaz
+ *
+ * Based on twl4030-pwrbutton driver by:
+ *     Peter De Schrijver <peter.de-schrijver@nokia.com>
+ *     Felipe Balbi <felipe.balbi@nokia.com>
+ *
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License. See the file "COPYING" in the main directory of this
+ * archive for more details.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/mfd/mc13783.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+
+struct mc13783_pwrb {
+	struct input_dev *pwr;
+	struct mc13xxx *mc13783;
+#define MC13783_PWRB_B1_POL_INVERT	(1 << 0)
+#define MC13783_PWRB_B2_POL_INVERT	(1 << 1)
+#define MC13783_PWRB_B3_POL_INVERT	(1 << 2)
+	int flags;
+	unsigned short keymap[3];
+};
+
+#define MC13783_REG_INTERRUPT_SENSE_1		5
+#define MC13783_IRQSENSE1_ONOFD1S		(1 << 3)
+#define MC13783_IRQSENSE1_ONOFD2S		(1 << 4)
+#define MC13783_IRQSENSE1_ONOFD3S		(1 << 5)
+
+#define MC13783_REG_POWER_CONTROL_2		15
+#define MC13783_POWER_CONTROL_2_ON1BDBNC	4
+#define MC13783_POWER_CONTROL_2_ON2BDBNC	6
+#define MC13783_POWER_CONTROL_2_ON3BDBNC	8
+#define MC13783_POWER_CONTROL_2_ON1BRSTEN	(1 << 1)
+#define MC13783_POWER_CONTROL_2_ON2BRSTEN	(1 << 2)
+#define MC13783_POWER_CONTROL_2_ON3BRSTEN	(1 << 3)
+
+static irqreturn_t button_irq(int irq, void *_priv)
+{
+	struct mc13783_pwrb *priv = _priv;
+	int val;
+	mc13xxx_irq_ack(priv->mc13783, irq);
+	mc13xxx_reg_read(priv->mc13783, MC13783_REG_INTERRUPT_SENSE_1, &val);
+
+	switch (irq) {
+	case MC13783_IRQ_ONOFD1:
+		val = val & MC13783_IRQSENSE1_ONOFD1S ? 1 : 0;
+		if (priv->flags & MC13783_PWRB_B1_POL_INVERT)
+			val ^= 1;
+		input_report_key(priv->pwr, priv->keymap[0], val);
+		break;
+
+	case MC13783_IRQ_ONOFD2:
+		val = val & MC13783_IRQSENSE1_ONOFD2S ? 1 : 0;
+		if (priv->flags & MC13783_PWRB_B2_POL_INVERT)
+			val ^= 1;
+		input_report_key(priv->pwr, priv->keymap[1], val);
+		break;
+
+	case MC13783_IRQ_ONOFD3:
+		val = val & MC13783_IRQSENSE1_ONOFD3S ? 1 : 0;
+		if (priv->flags & MC13783_PWRB_B3_POL_INVERT)
+			val ^= 1;
+		input_report_key(priv->pwr, priv->keymap[2], val);
+		break;
+	}
+
+	input_sync(priv->pwr);
+
+	return IRQ_HANDLED;
+}
+
+static int __devinit mc13783_pwrbutton_probe(struct platform_device *pdev)
+{
+	struct mc13xxx_buttons_platform_data *pdata;
+	struct mc13xxx *mc13783 = dev_get_drvdata(pdev->dev.parent);
+	struct input_dev *pwr;
+	struct mc13783_pwrb *priv;
+	int err = 0;
+	int reg = 0;
+
+	pdata = dev_get_platdata(&pdev->dev);
+	if (pdata == NULL) {
+		dev_err(&pdev->dev, "missing platform data\n");
+		return -ENODEV;
+	}
+
+	pwr = input_allocate_device();
+	if (!pwr) {
+		dev_dbg(&pdev->dev, "Can't allocate power button\n");
+		return -ENOMEM;
+	}
+
+	priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+
+	if (!priv) {
+		err = -ENOMEM;
+		dev_dbg(&pdev->dev, "Can't allocate power button\n");
+		goto free_input_dev;
+	}
+
+	pwr->evbit[0] = BIT_MASK(EV_KEY);
+
+	reg |= (pdata->b1on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON1BDBNC;
+	reg |= (pdata->b2on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON2BDBNC;
+	reg |= (pdata->b3on_flags & 0x3) << MC13783_POWER_CONTROL_2_ON3BDBNC;
+
+	priv->pwr = pwr;
+	priv->mc13783 = mc13783;
+
+	mc13xxx_lock(mc13783);
+
+	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE) {
+		priv->keymap[0] = pdata->b1on_key;
+		if (pdata->b1on_key != KEY_RESERVED)
+			__set_bit(pdata->b1on_key, pwr->keybit);
+
+		if (pdata->b1on_flags & MC13783_BUTTON_POL_INVERT)
+			priv->flags |= MC13783_PWRB_B1_POL_INVERT;
+
+		if (pdata->b1on_flags & MC13783_BUTTON_RESET_EN)
+			reg |= MC13783_POWER_CONTROL_2_ON1BRSTEN;
+
+		err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD1,
+					  button_irq, "b1on", priv);
+
+		if (err) {
+			mc13xxx_unlock(mc13783);
+
+			dev_dbg(&pdev->dev, "Can't request irq\n");
+			goto free_priv;
+		}
+	}
+
+	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE) {
+		priv->keymap[0] = pdata->b2on_key;
+		if (pdata->b2on_key != KEY_RESERVED)
+			__set_bit(pdata->b2on_key, pwr->keybit);
+
+		if (pdata->b2on_flags & MC13783_BUTTON_POL_INVERT)
+			priv->flags |= MC13783_PWRB_B2_POL_INVERT;
+
+		if (pdata->b2on_flags & MC13783_BUTTON_RESET_EN)
+			reg |= MC13783_POWER_CONTROL_2_ON2BRSTEN;
+
+		err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD2,
+					  button_irq, "b2on", priv);
+
+		if (err) {
+			dev_dbg(&pdev->dev, "Can't request irq\n");
+			goto free_irq_b1;
+		}
+	}
+
+	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE) {
+		priv->keymap[0] = pdata->b3on_key;
+		if (pdata->b3on_key != KEY_RESERVED)
+			__set_bit(pdata->b3on_key, pwr->keybit);
+
+		if (pdata->b3on_flags & MC13783_BUTTON_POL_INVERT)
+			priv->flags |= MC13783_PWRB_B3_POL_INVERT;
+
+		if (pdata->b3on_flags & MC13783_BUTTON_RESET_EN)
+			reg |= MC13783_POWER_CONTROL_2_ON3BRSTEN;
+
+		err = mc13xxx_irq_request(mc13783, MC13783_IRQ_ONOFD3,
+					  button_irq, "b3on", priv);
+
+		if (err) {
+			dev_dbg(&pdev->dev, "Can't request irq: %d\n", err);
+			goto free_irq_b2;
+		}
+	}
+
+	mc13xxx_reg_rmw(mc13783, MC13783_REG_POWER_CONTROL_2, 0x3FE, reg);
+
+	mc13xxx_unlock(mc13783);
+
+	pwr->name = "mc13783_pwrbutton";
+	pwr->phys = "mc13783_pwrbutton/input0";
+	pwr->dev.parent = &pdev->dev;
+
+	pwr->keycode = priv->keymap;
+	pwr->keycodemax = ARRAY_SIZE(priv->keymap);
+	pwr->keycodesize = sizeof(priv->keymap[0]);
+
+	err = input_register_device(pwr);
+	if (err) {
+		dev_dbg(&pdev->dev, "Can't register power button: %d\n", err);
+		goto free_irq;
+	}
+
+	platform_set_drvdata(pdev, priv);
+
+	return 0;
+
+free_irq:
+	mc13xxx_lock(mc13783);
+
+	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
+		mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD3, priv);
+free_irq_b2:
+	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
+		mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD2, priv);
+
+free_irq_b1:
+	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
+		mc13xxx_irq_free(mc13783, MC13783_IRQ_ONOFD1, priv);
+
+	mc13xxx_unlock(mc13783);
+
+free_priv:
+	kfree(priv);
+
+free_input_dev:
+	input_free_device(pwr);
+
+	return err;
+}
+
+static int __devexit mc13783_pwrbutton_remove(struct platform_device *pdev)
+{
+	struct mc13783_pwrb *priv = platform_get_drvdata(pdev);
+	struct mc13xxx_buttons_platform_data *pdata;
+	pdata = dev_get_platdata(&pdev->dev);
+
+	mc13xxx_lock(priv->mc13783);
+
+	if (pdata->b3on_flags & MC13783_BUTTON_ENABLE)
+		mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD3, priv);
+	if (pdata->b2on_flags & MC13783_BUTTON_ENABLE)
+		mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD2, priv);
+	if (pdata->b1on_flags & MC13783_BUTTON_ENABLE)
+		mc13xxx_irq_free(priv->mc13783, MC13783_IRQ_ONOFD1, priv);
+
+	mc13xxx_unlock(priv->mc13783);
+
+	input_unregister_device(priv->pwr);
+	kfree(priv);
+
+	return 0;
+}
+
+struct platform_driver mc13783_pwrbutton_driver = {
+	.probe		= mc13783_pwrbutton_probe,
+	.remove		= __devexit_p(mc13783_pwrbutton_remove),
+	.driver		= {
+		.name	= "mc13783-pwrbutton",
+		.owner	= THIS_MODULE,
+	},
+};
+
+static int __init mc13783_pwrbutton_init(void)
+{
+	return platform_driver_register(&mc13783_pwrbutton_driver);
+}
+module_init(mc13783_pwrbutton_init);
+
+static void __exit mc13783_pwrbutton_exit(void)
+{
+	platform_driver_unregister(&mc13783_pwrbutton_driver);
+}
+module_exit(mc13783_pwrbutton_exit);
+
+MODULE_ALIAS("platform:mc13783-pwrbutton");
+MODULE_DESCRIPTION("MC13783 Power Button");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Philippe Retornaz");
diff --git a/drivers/mfd/mc13xxx-core.c b/drivers/mfd/mc13xxx-core.c
index 7e4d44b..44edf78 100644
--- a/drivers/mfd/mc13xxx-core.c
+++ b/drivers/mfd/mc13xxx-core.c
@@ -778,6 +778,10 @@ err_revision:
 		mc13xxx_add_subdevice_pdata(mc13xxx, "%s-led",
 				pdata->leds, sizeof(*pdata->leds));
 
+	if (pdata->flags & MC13XXX_USE_BUTTON)
+		mc13xxx_add_subdevice_pdata(mc13xxx, "%s-pwrbutton",
+				pdata->buttons, sizeof(*pdata->buttons));
+
 	return 0;
 }
 
diff --git a/include/linux/mfd/mc13783.h b/include/linux/mfd/mc13783.h
index 7d0f3d6..bd4fbac 100644
--- a/include/linux/mfd/mc13783.h
+++ b/include/linux/mfd/mc13783.h
@@ -106,6 +106,7 @@ static inline int mc13783_irq_ack(struct mc13783 *mc13783, int irq)
 #define mc13783_regulator_platform_data mc13xxx_regulator_platform_data
 #define mc13783_led_platform_data mc13xxx_led_platform_data
 #define mc13783_leds_platform_data mc13xxx_leds_platform_data
+#define mc13783_buttons_platform_data mc13xxx_buttons_platform_data
 
 #define mc13783_platform_data mc13xxx_platform_data
 #define MC13783_USE_TOUCHSCREEN	MC13XXX_USE_TOUCHSCREEN
diff --git a/include/linux/mfd/mc13xxx.h b/include/linux/mfd/mc13xxx.h
index c064bea..22d8930 100644
--- a/include/linux/mfd/mc13xxx.h
+++ b/include/linux/mfd/mc13xxx.h
@@ -137,6 +137,22 @@ struct mc13xxx_leds_platform_data {
 	char tc3_period;
 };
 
+struct mc13xxx_buttons_platform_data {
+#define MC13783_BUTTON_DBNC_0MS		0
+#define MC13783_BUTTON_DBNC_30MS	1
+#define MC13783_BUTTON_DBNC_150MS	2
+#define MC13783_BUTTON_DBNC_750MS	3
+#define MC13783_BUTTON_ENABLE		(1 << 2)
+#define MC13783_BUTTON_POL_INVERT	(1 << 3)
+#define MC13783_BUTTON_RESET_EN		(1 << 4)
+	int b1on_flags;
+	unsigned short b1on_key;
+	int b2on_flags;
+	unsigned short b2on_key;
+	int b3on_flags;
+	unsigned short b3on_key;
+};
+
 struct mc13xxx_platform_data {
 #define MC13XXX_USE_TOUCHSCREEN (1 << 0)
 #define MC13XXX_USE_CODEC	(1 << 1)
@@ -144,10 +160,12 @@ struct mc13xxx_platform_data {
 #define MC13XXX_USE_RTC		(1 << 3)
 #define MC13XXX_USE_REGULATOR	(1 << 4)
 #define MC13XXX_USE_LED		(1 << 5)
+#define MC13XXX_USE_BUTTON	(1 << 6)
 	unsigned int flags;
 
 	struct mc13xxx_regulator_platform_data regulators;
 	struct mc13xxx_leds_platform_data *leds;
+	struct mc13xxx_buttons_platform_data *buttons;
 };
 
 #endif /* ifndef __LINUX_MFD_MC13XXX_H */
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2011-07-08 15:25 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-31 19:28 [PATCH 0/2] mc13783: add pwr button support Philippe Rétornaz
2010-05-31 19:28 ` Philippe Rétornaz
2010-05-31 19:28 ` [PATCH 1/2] mc13783: add power " Philippe Rétornaz
2010-05-31 19:28   ` Philippe Rétornaz
2010-05-31 19:29   ` [PATCH 2/2] mx31moboard: Add MC13783 " Philippe Rétornaz
2010-05-31 19:29     ` Philippe Rétornaz
2010-06-03  8:31     ` Sascha Hauer
2010-06-03  8:31       ` Sascha Hauer
2010-06-03  9:23       ` Philippe Rétornaz
2010-06-03  9:23         ` Philippe Rétornaz
2010-06-02  7:52   ` [PATCH 1/2] mc13783: add " Dmitry Torokhov
2010-06-02  7:52     ` Dmitry Torokhov
2011-07-08 14:23 [PATCH v2 0/2] mc13783: add pwr " Philippe Rétornaz
2011-07-08 14:23 ` [PATCH 1/2] mc13783: add power " Philippe Rétornaz
2011-07-08 14:23   ` Philippe Rétornaz
2011-07-08 14:30   ` Uwe Kleine-König
2011-07-08 14:30     ` Uwe Kleine-König
2011-07-08 14:45     ` Philippe Rétornaz
2011-07-08 14:45       ` Philippe Rétornaz
2011-07-08 15:25       ` Uwe Kleine-König
2011-07-08 15:25         ` Uwe Kleine-König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.