public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support
@ 2008-04-03 13:44 Felipe Balbi
  2008-04-03 13:44 ` [PATCH 2/3] I2C: TWL4030: Kconfig and Makefile changes Felipe Balbi
  2008-04-03 13:47 ` [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support Felipe Balbi
  0 siblings, 2 replies; 8+ messages in thread
From: Felipe Balbi @ 2008-04-03 13:44 UTC (permalink / raw)
  To: linux-omap; +Cc: Peter 'p2' De Schrijver, Felipe Balbi

From: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>

The following patch implements power button and IRQ support
for triton2 power block.

Signed-off-by: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
---
 drivers/i2c/chips/twl4030-pwrbutton.c     |  160 ++++++++++++++++++++
 drivers/i2c/chips/twl4030-pwrirq.c        |  224 +++++++++++++++++++++++++++++
 include/asm-arm/arch-omap/board-3430sdp.h |    9 +-
 3 files changed, 390 insertions(+), 3 deletions(-)
 create mode 100644 drivers/i2c/chips/twl4030-pwrbutton.c
 create mode 100644 drivers/i2c/chips/twl4030-pwrirq.c

diff --git a/drivers/i2c/chips/twl4030-pwrbutton.c b/drivers/i2c/chips/twl4030-pwrbutton.c
new file mode 100644
index 0000000..a541ed6
--- /dev/null
+++ b/drivers/i2c/chips/twl4030-pwrbutton.c
@@ -0,0 +1,160 @@
+/**
+ * drivers/i2c/chips/twl4030-pwrbutton.c
+ *
+ * Driver for sending triton2 power button event to input-layer
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * Written by Peter De Schrijver <peter.de-schrijver@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/timer.h>
+#include <linux/jiffies.h>
+#include <linux/kthread.h>
+#include <linux/interrupt.h>
+#include <linux/i2c/twl4030.h>
+
+#define PWR_ISR1 0
+#define PWR_IMR1 1
+#define PWR_PWRON_IRQ (1<<0)
+
+#define PWR_EDR1 5
+#define PWR_PWRON_RISING (1<<1)
+#define PWR_PWRON_FALLING  (1<<0)
+#define PWR_PWRON_BOTH (PWR_PWRON_RISING | PWR_PWRON_FALLING)
+
+#define PWR_SIH_CTRL 7
+
+#define STS_HW_CONDITIONS 0xf
+
+static struct input_dev *powerbutton_dev;
+
+/*
+ * Note : the following function runs in kernel thread context
+ * with IRQs enabled
+ */
+
+static irqreturn_t powerbutton_irq(int irq, void *dev_id)
+{
+	int err;
+	u8 value;
+
+	err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &value,
+				  STS_HW_CONDITIONS);
+	if (!err)  {
+		input_report_key(powerbutton_dev, KEY_POWER,
+				 value & PWR_PWRON_IRQ);
+	} else {
+		printk(KERN_WARNING "I2C error %d while reading TWL4030"
+			"PM_MASTER STS_HW_CONDITIONS register\n", err);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static int __init twl4030_pwrbutton_init(void)
+{
+	int err = 0;
+	u8 value;
+
+	if (request_irq(TWL4030_PWRIRQ_PWRBTN, powerbutton_irq, 0,
+			"PwrButton", NULL) < 0) {
+		printk(KERN_ERR "Unable to allocate IRQ for power button\n");
+		err = -EBUSY;
+		goto out;
+	}
+
+	powerbutton_dev = input_allocate_device();
+	if (!powerbutton_dev) {
+		printk(KERN_ERR
+			"Unable to allocate input device for power button\n");
+		err = -ENOMEM;
+		goto free_irq_and_out;
+	}
+
+	powerbutton_dev->evbit[0] = BIT_MASK(EV_KEY);
+	powerbutton_dev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
+	powerbutton_dev->name = "triton2-pwrbutton";
+
+	err = input_register_device(powerbutton_dev);
+	if (err)
+		goto free_input_dev;
+
+	err = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &value, PWR_IMR1);
+	if (err) {
+		printk(KERN_WARNING "I2C error %d while reading TWL4030"
+					"INT PWR_IMR1 register\n", err);
+
+		goto free_input_dev;
+	}
+
+	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT,
+				   value & (~PWR_PWRON_IRQ), PWR_IMR1);
+	if (err) {
+		printk(KERN_WARNING "I2C error %d while writing TWL4030"
+				    "INT PWR_IMR1 register\n", err);
+		goto free_input_dev;
+	}
+
+	err = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &value, PWR_EDR1);
+	if (err) {
+		printk(KERN_WARNING "I2C error %d while reading TWL4030"
+					"INT PWR_EDR1 register\n", err);
+		goto free_input_dev;
+	}
+
+	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT,
+				   value | PWR_PWRON_BOTH , PWR_EDR1);
+
+	if (err) {
+		printk(KERN_WARNING "I2C error %d while writing TWL4030"
+					"INT PWR_EDR1 register\n", err);
+		goto free_input_dev;
+	}
+
+	printk(KERN_INFO "triton2 power button driver initialized\n");
+
+	return 0;
+
+
+free_input_dev:
+	input_free_device(powerbutton_dev);
+free_irq_and_out:
+	free_irq(TWL4030_PWRIRQ_PWRBTN, NULL);
+out:
+	return err;
+}
+
+static void __exit twl4030_pwrbutton_exit(void)
+{
+	free_irq(TWL4030_PWRIRQ_PWRBTN, NULL);
+	input_unregister_device(powerbutton_dev);
+	input_free_device(powerbutton_dev);
+
+}
+
+module_init(twl4030_pwrbutton_init);
+module_exit(twl4030_pwrbutton_exit);
+
+MODULE_DESCRIPTION("Triton2 Power Button");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Peter De Schrijver");
+
diff --git a/drivers/i2c/chips/twl4030-pwrirq.c b/drivers/i2c/chips/twl4030-pwrirq.c
new file mode 100644
index 0000000..d6098ad
--- /dev/null
+++ b/drivers/i2c/chips/twl4030-pwrirq.c
@@ -0,0 +1,224 @@
+/*
+ * twl4030-pwrirq.c - handle power interrupts from TWL3040
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * Written by Peter De Schrijver <peter.de-schrijver@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/kernel_stat.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/i2c.h>
+#include <linux/random.h>
+#include <linux/kthread.h>
+#include <linux/i2c/twl4030.h>
+
+#define PWR_ISR1 0
+#define PWR_IMR1 1
+#define PWR_SIH_CTRL 7
+#define PWR_SIH_CTRL_COR (1<<2)
+
+static u8 twl4030_pwrirq_mask;
+static u8 twl4030_pwrirq_pending_unmask;
+
+static struct task_struct *twl4030_pwrirq_unmask_thread;
+
+static void twl4030_pwrirq_ack(unsigned int irq) {}
+
+static void twl4030_pwrirq_disableint(unsigned int irq) {}
+
+static void twl4030_pwrirq_enableint(unsigned int irq)
+{
+	twl4030_pwrirq_pending_unmask |= 1 << (irq - IH_TWL4030_PWRBASE);
+	if (twl4030_pwrirq_unmask_thread &&
+		twl4030_pwrirq_unmask_thread->state != TASK_RUNNING)
+		wake_up_process(twl4030_pwrirq_unmask_thread);
+}
+
+static struct irq_chip twl4030_pwrirq_chip = {
+	.name	= "twl4030-pwr",
+	.ack	= twl4030_pwrirq_ack,
+	.mask	= twl4030_pwrirq_disableint,
+	.unmask	= twl4030_pwrirq_enableint,
+};
+
+static void do_twl4030_pwrmodule_irq(unsigned int irq, irq_desc_t *desc)
+{
+	struct irqaction *action;
+	const unsigned int cpu = smp_processor_id();
+
+	desc->status |= IRQ_LEVEL;
+
+	if (!desc->depth) {
+		kstat_cpu(cpu).irqs[irq]++;
+
+		action = desc->action;
+		if (action) {
+			int ret;
+			int status = 0;
+			int retval = 0;
+
+			do {
+				ret = action->handler(irq, action->dev_id);
+				if (ret == IRQ_HANDLED)
+					status |= action->flags;
+				retval |= ret;
+				action = action->next;
+			} while (action);
+
+			if (status & IRQF_SAMPLE_RANDOM)
+				add_interrupt_randomness(irq);
+
+			if (retval != IRQ_HANDLED)
+				printk(KERN_ERR "ISR for TWL4030 power module"
+					" irq %d can't handle interrupt\n",
+					irq);
+		} else {
+			local_irq_disable();
+			twl4030_pwrirq_mask |= 1 << (irq - IH_TWL4030_PWRBASE);
+			local_irq_enable();
+			twl4030_i2c_write_u8(TWL4030_MODULE_INT,
+						twl4030_pwrirq_mask, PWR_IMR1);
+		}
+	}
+}
+
+static void do_twl4030_pwrirq(unsigned int irq, irq_desc_t *desc)
+{
+	const unsigned int cpu = smp_processor_id();
+
+	desc->status |= IRQ_LEVEL;
+
+	desc->chip->ack(irq);
+
+	if (!desc->depth) {
+		int ret;
+		int module_irq;
+		u8 pwr_isr;
+
+		kstat_cpu(cpu).irqs[irq]++;
+
+		local_irq_enable();
+		ret = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &pwr_isr,
+						PWR_ISR1);
+		if (ret) {
+			printk(KERN_WARNING
+				"I2C error %d while reading TWL4030"
+				"INT PWR_ISR1 register\n", ret);
+			return;
+		}
+
+		for (module_irq = IH_TWL4030_PWRBASE; pwr_isr != 0;
+			module_irq++, pwr_isr >>= 1) {
+			if (pwr_isr & 1)
+				irq_desc_t *d = irq_desc + module_irq;
+		}
+
+		local_irq_disable();
+		desc->chip->unmask(irq);
+	}
+}
+
+static int twl4030_pwrirq_thread(void *data)
+{
+	current->flags |= PF_NOFREEZE;
+
+	while (!kthread_should_stop()) {
+		u8 local_unmask;
+
+		local_irq_disable();
+		local_unmask = twl4030_pwrirq_pending_unmask;
+		twl4030_pwrirq_pending_unmask = 0;
+		local_irq_enable();
+
+		twl4030_pwrirq_mask &= ~local_unmask;
+
+		twl4030_i2c_write_u8(TWL4030_MODULE_INT, twl4030_pwrirq_mask,
+					PWR_IMR1);
+
+		local_irq_disable();
+		if (!twl4030_pwrirq_pending_unmask)
+			set_current_state(TASK_INTERRUPTIBLE);
+		local_irq_enable();
+
+		schedule();
+	}
+	set_current_state(TASK_RUNNING);
+	return 0;
+}
+
+static int __init twl4030_pwrirq_init(void)
+{
+	int i, err;
+
+	twl4030_pwrirq_mask = 0xff;
+	twl4030_pwrirq_pending_unmask = 0;
+
+	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT, twl4030_pwrirq_mask,
+					PWR_IMR1);
+	if (err)
+		return err;
+
+	/* Enable clear on read */
+
+	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT, PWR_SIH_CTRL_COR,
+					PWR_SIH_CTRL);
+	if (err)
+		return err;
+
+	twl4030_pwrirq_unmask_thread = kthread_create(twl4030_pwrirq_thread,
+		NULL, "twl4030 pwrirq");
+	if (!twl4030_pwrirq_unmask_thread) {
+		printk(KERN_ERR
+			"%s: could not create twl4030 pwrirq unmask thread!\n",
+				__func__);
+		return -ENOMEM;
+	}
+
+	for (i = IH_TWL4030_PWRBASE; i < IH_TWL4030_PWRBASE_END; i++) {
+		set_irq_chip(i, &twl4030_pwrirq_chip);
+		set_irq_handler(i, do_twl4030_pwrmodule_irq);
+		set_irq_flags(i, IRQF_VALID);
+	}
+
+	set_irq_chained_handler(TWL4030_MODIRQ_PWR, do_twl4030_pwrirq);
+
+	return 0;
+}
+
+static void __exit twl4030_pwrirq_exit(void)
+{
+
+	int i;
+
+	set_irq_handler(TWL4030_MODIRQ_PWR, NULL);
+	set_irq_flags(TWL4030_MODIRQ_PWR, 0);
+
+	for (i = IH_TWL4030_PWRBASE; i < IH_TWL4030_PWRBASE_END; i++) {
+		set_irq_handler(i, NULL);
+		set_irq_flags(i, 0);
+	}
+
+	if (twl4030_pwrirq_unmask_thread) {
+		kthread_stop(twl4030_pwrirq_unmask_thread);
+		twl4030_pwrirq_unmask_thread = NULL;
+	}
+}
+
+subsys_initcall(twl4030_pwrirq_init);
+module_exit(twl4030_pwrirq_exit);
diff --git a/include/asm-arm/arch-omap/board-3430sdp.h b/include/asm-arm/arch-omap/board-3430sdp.h
index 06379cf..87f47e5 100644
--- a/include/asm-arm/arch-omap/board-3430sdp.h
+++ b/include/asm-arm/arch-omap/board-3430sdp.h
@@ -75,14 +75,17 @@ extern void sdp_mmc_init(void);
 #define	IH_TWL4030_BASE		IH_BOARD_BASE
 #define	IH_TWL4030_END		(IH_TWL4030_BASE+8)
 
+#define IH_TWL4030_PWRBASE     (IH_TWL4030_END)
+#define IH_TWL4030_PWRBASE_END (IH_TWL4030_PWRBASE+8)
+
 #ifdef CONFIG_TWL4030_GPIO
 
 /* TWL4030 GPIO Interrupts */
-#define IH_TWL4030_GPIO_BASE	(IH_TWL4030_END)
-#define IH_TWL4030_GPIO_END	(IH_TWL4030_BASE+18)
+#define IH_TWL4030_GPIO_BASE	(IH_TWL4030_PWRBASE_END)
+#define IH_TWL4030_GPIO_END	(IH_TWL4030_GPIO_BASE+18)
 #define NR_IRQS			(IH_TWL4030_GPIO_END)
 #else
-#define NR_IRQS			(IH_TWL4030_END)
+#define NR_IRQS			(IH_TWL4030_PWRBASE_END)
 #endif /* CONFIG_I2C_TWL4030_GPIO */
 #endif /* End of support for TWL4030 */
 #endif /*  __ASM_ARCH_OMAP_3430SDP_H */
-- 
1.5.5.rc2.25.g5fbd


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

* [PATCH 2/3] I2C: TWL4030: Kconfig and Makefile changes
  2008-04-03 13:44 [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support Felipe Balbi
@ 2008-04-03 13:44 ` Felipe Balbi
  2008-04-03 13:44   ` [PATCH 3/3] I2C: TWL4030: Adapt existing drivers to power IRQ Felipe Balbi
  2008-04-03 13:47 ` [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support Felipe Balbi
  1 sibling, 1 reply; 8+ messages in thread
From: Felipe Balbi @ 2008-04-03 13:44 UTC (permalink / raw)
  To: linux-omap; +Cc: Peter 'p2' De Schrijver, Felipe Balbi

From: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>

Kconfig and Makefile changes

Signed-off-by: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
---
 drivers/i2c/chips/Kconfig  |    4 ++++
 drivers/i2c/chips/Makefile |    3 ++-
 2 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index bc7717f..3730448 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -136,6 +136,10 @@ config TWL4030_USB
 	bool "TWL4030 USB Transceiver Driver"
 	depends on TWL4030_CORE
 
+config TWL4030_PWRBUTTON
+        bool "TWL4030 Power button Driver"
+	depends on TWL4030_CORE
+
 choice
 	prompt "Transceiver mode"
 	depends on TWL4030_USB
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index 6431675..7c47fc4 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -22,10 +22,11 @@ obj-$(CONFIG_SENSORS_TLV320AIC23) += tlv320aic23.o
 obj-$(CONFIG_GPIOEXPANDER_OMAP)	+= gpio_expander_omap.o
 obj-$(CONFIG_MENELAUS)		+= menelaus.o
 obj-$(CONFIG_SENSORS_TSL2550)	+= tsl2550.o
-obj-$(CONFIG_TWL4030_CORE)	+= twl4030-core.o
+obj-$(CONFIG_TWL4030_CORE)	+= twl4030-core.o twl4030-pwrirq.o
 obj-$(CONFIG_TWL4030_GPIO)	+= twl4030-gpio.o
 obj-$(CONFIG_TWL4030_USB)	+= twl4030-usb.o
 obj-$(CONFIG_TWL4030_POWEROFF)	+= twl4030-poweroff.o
+obj-$(CONFIG_TWL4030_PWRBUTTON)	+= twl4030-pwrbutton.o
 obj-$(CONFIG_TWL4030_MADC)	+= twl4030-madc.o
 obj-$(CONFIG_RTC_X1205_I2C)	+= x1205.o
 
-- 
1.5.5.rc2.25.g5fbd


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

* [PATCH 3/3] I2C: TWL4030: Adapt existing drivers to power IRQ
  2008-04-03 13:44 ` [PATCH 2/3] I2C: TWL4030: Kconfig and Makefile changes Felipe Balbi
@ 2008-04-03 13:44   ` Felipe Balbi
  0 siblings, 0 replies; 8+ messages in thread
From: Felipe Balbi @ 2008-04-03 13:44 UTC (permalink / raw)
  To: linux-omap; +Cc: Peter 'p2' De Schrijver, Felipe Balbi

From: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>

This patch adapts the existing driver to use the power IRQ handler. This
patch superseeds any previous version.

Signed-off-by: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
---
 drivers/i2c/chips/twl4030-usb.c |   18 ++----------------
 drivers/rtc/rtc-twl4030.c       |   17 ++---------------
 include/linux/i2c/twl4030.h     |   10 ++++++++++
 3 files changed, 14 insertions(+), 31 deletions(-)

diff --git a/drivers/i2c/chips/twl4030-usb.c b/drivers/i2c/chips/twl4030-usb.c
index 2db1c63..a238904 100644
--- a/drivers/i2c/chips/twl4030-usb.c
+++ b/drivers/i2c/chips/twl4030-usb.c
@@ -593,19 +593,6 @@ static irqreturn_t twl4030_usb_irq(int irq, void *_twl)
 	int ret = IRQ_NONE;
 	u8 val;
 
-	if (twl4030_i2c_read_u8(TWL4030_MODULE_INT, &val, REG_PWR_ISR1) < 0) {
-		printk(KERN_ERR "twl4030_usb: i2c read failed,"
-				" line %d\n", __LINE__);
-		goto done;
-	}
-
-	/* this interrupt line may be shared */
-	if (!(val & USB_PRES))
-		goto done;
-
-	/* clear the interrupt */
-	twl4030_i2c_write_u8(TWL4030_MODULE_INT, USB_PRES, REG_PWR_ISR1);
-
 	/* action based on cable attach or detach */
 	if (twl4030_i2c_read_u8(TWL4030_MODULE_INT, &val, REG_PWR_EDR1) < 0) {
 		printk(KERN_ERR "twl4030_usb: i2c read failed,"
@@ -708,14 +695,13 @@ static int __init twl4030_usb_init(void)
 
 	the_transceiver = twl;
 
-	twl->irq		= TWL4030_MODIRQ_PWR;
+	twl->irq		= TWL4030_PWRIRQ_USB_PRES;
 	twl->otg.set_host	= twl4030_set_host;
 	twl->otg.set_peripheral	= twl4030_set_peripheral;
 	twl->otg.set_suspend	= twl4030_set_suspend;
 
 	usb_irq_disable();
-	status = request_irq(twl->irq, twl4030_usb_irq,
-		IRQF_DISABLED | IRQF_SHARED, "twl4030_usb", twl);
+	status = request_irq(twl->irq, twl4030_usb_irq, 0, "twl4030_usb", twl);
 	if (status < 0) {
 		printk(KERN_DEBUG "can't get IRQ %d, err %d\n",
 			twl->irq, status);
diff --git a/drivers/rtc/rtc-twl4030.c b/drivers/rtc/rtc-twl4030.c
index 929a788..ca026b1 100644
--- a/drivers/rtc/rtc-twl4030.c
+++ b/drivers/rtc/rtc-twl4030.c
@@ -426,19 +426,6 @@ static irqreturn_t twl4030_rtc_interrupt(int irq, void *rtc)
 	int res;
 	u8 rd_reg;
 	
-	/* clear the RTC interrupt in TWL4030 power module */
-	res = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &rd_reg, REG_PWR_ISR1);
-	if (res)
-		goto out;
-
-	/* Check if interrupt is sourced by RTC */
-	if (!(rd_reg & PWR_RTC_INT_CLR))
-		goto out;
-
-	res = twl4030_i2c_write_u8(TWL4030_MODULE_INT, PWR_RTC_INT_CLR, REG_PWR_ISR1);
-	if (res)
-		goto out;
-
 	res = twl4030_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
 	if (res)
 		goto out;
@@ -528,8 +515,8 @@ static int __devinit twl4030_rtc_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto out1;
 
-	ret = request_irq(TWL4030_MODIRQ_PWR, twl4030_rtc_interrupt,
-			  IRQF_DISABLED | IRQF_SHARED, rtc->dev.bus_id, rtc);
+	ret = request_irq(TWL4030_PWRIRQ_RTC, twl4030_rtc_interrupt,
+				0, rtc->dev.bus_id, rtc);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "IRQ is not free.\n");
 		goto out1;
diff --git a/include/linux/i2c/twl4030.h b/include/linux/i2c/twl4030.h
index 7f9b90d..fc11fd0 100644
--- a/include/linux/i2c/twl4030.h
+++ b/include/linux/i2c/twl4030.h
@@ -62,6 +62,16 @@
 #define TWL4030_MODIRQ_MADC		(IH_TWL4030_BASE + 3)
 #define TWL4030_MODIRQ_USB		(IH_TWL4030_BASE + 4)
 #define TWL4030_MODIRQ_PWR		(IH_TWL4030_BASE + 5)
+
+#define TWL4030_PWRIRQ_PWRBTN		(IH_TWL4030_PWRBASE + 0)
+#define TWL4030_PWRIRQ_CHG_PRES		(IH_TWL4030_PWRBASE + 1)
+#define TWL4030_PWRIRQ_USB_PRES		(IH_TWL4030_PWRBASE + 2)
+#define TWL4030_PWRIRQ_RTC		(IH_TWL4030_PWRBASE + 3)
+#define TWL4030_PWRIRQ_HOT_DIE		(IH_TWL4030_PWRBASE + 4)
+#define TWL4030_PWRIRQ_PWROK_TIMEOUT	(IH_TWL4030_PWRBASE + 5)
+#define TWL4030_PWRIRQ_MBCHG		(IH_TWL4030_PWRBASE + 6)
+#define TWL4030_PWRIRQ_SC_DETECT	(IH_TWL4030_PWRBASE + 7)
+
 /* Rest are unsued currently*/
 
 /* Offsets to Power Registers */
-- 
1.5.5.rc2.25.g5fbd


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

* Re: [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support
  2008-04-03 13:44 [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support Felipe Balbi
  2008-04-03 13:44 ` [PATCH 2/3] I2C: TWL4030: Kconfig and Makefile changes Felipe Balbi
@ 2008-04-03 13:47 ` Felipe Balbi
  2008-04-03 13:57   ` Peter 'p2' De Schrijver
  1 sibling, 1 reply; 8+ messages in thread
From: Felipe Balbi @ 2008-04-03 13:47 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: linux-omap, Peter 'p2' De Schrijver

On Thu, Apr 03, 2008 at 04:44:22PM +0300, Felipe Balbi wrote:
> From: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>

Missing d->handle_irq();


>From 10b0fa72ded443a8d89ef3676f9ea08b3b87f8c0 Mon Sep 17 00:00:00 2001
From: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>
Date: Wed, 2 Apr 2008 20:57:58 +0300
Subject: [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support

The following patch implements power button and IRQ support
for triton2 power block.

Signed-off-by: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
---
 drivers/i2c/chips/twl4030-pwrbutton.c     |  160 ++++++++++++++++++++
 drivers/i2c/chips/twl4030-pwrirq.c        |  224 +++++++++++++++++++++++++++++
 include/asm-arm/arch-omap/board-3430sdp.h |    9 +-
 3 files changed, 390 insertions(+), 3 deletions(-)
 create mode 100644 drivers/i2c/chips/twl4030-pwrbutton.c
 create mode 100644 drivers/i2c/chips/twl4030-pwrirq.c

diff --git a/drivers/i2c/chips/twl4030-pwrbutton.c b/drivers/i2c/chips/twl4030-pwrbutton.c
new file mode 100644
index 0000000..a541ed6
--- /dev/null
+++ b/drivers/i2c/chips/twl4030-pwrbutton.c
@@ -0,0 +1,160 @@
+/**
+ * drivers/i2c/chips/twl4030-pwrbutton.c
+ *
+ * Driver for sending triton2 power button event to input-layer
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * Written by Peter De Schrijver <peter.de-schrijver@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/timer.h>
+#include <linux/jiffies.h>
+#include <linux/kthread.h>
+#include <linux/interrupt.h>
+#include <linux/i2c/twl4030.h>
+
+#define PWR_ISR1 0
+#define PWR_IMR1 1
+#define PWR_PWRON_IRQ (1<<0)
+
+#define PWR_EDR1 5
+#define PWR_PWRON_RISING (1<<1)
+#define PWR_PWRON_FALLING  (1<<0)
+#define PWR_PWRON_BOTH (PWR_PWRON_RISING | PWR_PWRON_FALLING)
+
+#define PWR_SIH_CTRL 7
+
+#define STS_HW_CONDITIONS 0xf
+
+static struct input_dev *powerbutton_dev;
+
+/*
+ * Note : the following function runs in kernel thread context
+ * with IRQs enabled
+ */
+
+static irqreturn_t powerbutton_irq(int irq, void *dev_id)
+{
+	int err;
+	u8 value;
+
+	err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &value,
+				  STS_HW_CONDITIONS);
+	if (!err)  {
+		input_report_key(powerbutton_dev, KEY_POWER,
+				 value & PWR_PWRON_IRQ);
+	} else {
+		printk(KERN_WARNING "I2C error %d while reading TWL4030"
+			"PM_MASTER STS_HW_CONDITIONS register\n", err);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static int __init twl4030_pwrbutton_init(void)
+{
+	int err = 0;
+	u8 value;
+
+	if (request_irq(TWL4030_PWRIRQ_PWRBTN, powerbutton_irq, 0,
+			"PwrButton", NULL) < 0) {
+		printk(KERN_ERR "Unable to allocate IRQ for power button\n");
+		err = -EBUSY;
+		goto out;
+	}
+
+	powerbutton_dev = input_allocate_device();
+	if (!powerbutton_dev) {
+		printk(KERN_ERR
+			"Unable to allocate input device for power button\n");
+		err = -ENOMEM;
+		goto free_irq_and_out;
+	}
+
+	powerbutton_dev->evbit[0] = BIT_MASK(EV_KEY);
+	powerbutton_dev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
+	powerbutton_dev->name = "triton2-pwrbutton";
+
+	err = input_register_device(powerbutton_dev);
+	if (err)
+		goto free_input_dev;
+
+	err = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &value, PWR_IMR1);
+	if (err) {
+		printk(KERN_WARNING "I2C error %d while reading TWL4030"
+					"INT PWR_IMR1 register\n", err);
+
+		goto free_input_dev;
+	}
+
+	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT,
+				   value & (~PWR_PWRON_IRQ), PWR_IMR1);
+	if (err) {
+		printk(KERN_WARNING "I2C error %d while writing TWL4030"
+				    "INT PWR_IMR1 register\n", err);
+		goto free_input_dev;
+	}
+
+	err = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &value, PWR_EDR1);
+	if (err) {
+		printk(KERN_WARNING "I2C error %d while reading TWL4030"
+					"INT PWR_EDR1 register\n", err);
+		goto free_input_dev;
+	}
+
+	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT,
+				   value | PWR_PWRON_BOTH , PWR_EDR1);
+
+	if (err) {
+		printk(KERN_WARNING "I2C error %d while writing TWL4030"
+					"INT PWR_EDR1 register\n", err);
+		goto free_input_dev;
+	}
+
+	printk(KERN_INFO "triton2 power button driver initialized\n");
+
+	return 0;
+
+
+free_input_dev:
+	input_free_device(powerbutton_dev);
+free_irq_and_out:
+	free_irq(TWL4030_PWRIRQ_PWRBTN, NULL);
+out:
+	return err;
+}
+
+static void __exit twl4030_pwrbutton_exit(void)
+{
+	free_irq(TWL4030_PWRIRQ_PWRBTN, NULL);
+	input_unregister_device(powerbutton_dev);
+	input_free_device(powerbutton_dev);
+
+}
+
+module_init(twl4030_pwrbutton_init);
+module_exit(twl4030_pwrbutton_exit);
+
+MODULE_DESCRIPTION("Triton2 Power Button");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Peter De Schrijver");
+
diff --git a/drivers/i2c/chips/twl4030-pwrirq.c b/drivers/i2c/chips/twl4030-pwrirq.c
new file mode 100644
index 0000000..d6098ad
--- /dev/null
+++ b/drivers/i2c/chips/twl4030-pwrirq.c
@@ -0,0 +1,224 @@
+/*
+ * twl4030-pwrirq.c - handle power interrupts from TWL3040
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * Written by Peter De Schrijver <peter.de-schrijver@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/kernel_stat.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/i2c.h>
+#include <linux/random.h>
+#include <linux/kthread.h>
+#include <linux/i2c/twl4030.h>
+
+#define PWR_ISR1 0
+#define PWR_IMR1 1
+#define PWR_SIH_CTRL 7
+#define PWR_SIH_CTRL_COR (1<<2)
+
+static u8 twl4030_pwrirq_mask;
+static u8 twl4030_pwrirq_pending_unmask;
+
+static struct task_struct *twl4030_pwrirq_unmask_thread;
+
+static void twl4030_pwrirq_ack(unsigned int irq) {}
+
+static void twl4030_pwrirq_disableint(unsigned int irq) {}
+
+static void twl4030_pwrirq_enableint(unsigned int irq)
+{
+	twl4030_pwrirq_pending_unmask |= 1 << (irq - IH_TWL4030_PWRBASE);
+	if (twl4030_pwrirq_unmask_thread &&
+		twl4030_pwrirq_unmask_thread->state != TASK_RUNNING)
+		wake_up_process(twl4030_pwrirq_unmask_thread);
+}
+
+static struct irq_chip twl4030_pwrirq_chip = {
+	.name	= "twl4030-pwr",
+	.ack	= twl4030_pwrirq_ack,
+	.mask	= twl4030_pwrirq_disableint,
+	.unmask	= twl4030_pwrirq_enableint,
+};
+
+static void do_twl4030_pwrmodule_irq(unsigned int irq, irq_desc_t *desc)
+{
+	struct irqaction *action;
+	const unsigned int cpu = smp_processor_id();
+
+	desc->status |= IRQ_LEVEL;
+
+	if (!desc->depth) {
+		kstat_cpu(cpu).irqs[irq]++;
+
+		action = desc->action;
+		if (action) {
+			int ret;
+			int status = 0;
+			int retval = 0;
+
+			do {
+				ret = action->handler(irq, action->dev_id);
+				if (ret == IRQ_HANDLED)
+					status |= action->flags;
+				retval |= ret;
+				action = action->next;
+			} while (action);
+
+			if (status & IRQF_SAMPLE_RANDOM)
+				add_interrupt_randomness(irq);
+
+			if (retval != IRQ_HANDLED)
+				printk(KERN_ERR "ISR for TWL4030 power module"
+					" irq %d can't handle interrupt\n",
+					irq);
+		} else {
+			local_irq_disable();
+			twl4030_pwrirq_mask |= 1 << (irq - IH_TWL4030_PWRBASE);
+			local_irq_enable();
+			twl4030_i2c_write_u8(TWL4030_MODULE_INT,
+						twl4030_pwrirq_mask, PWR_IMR1);
+		}
+	}
+}
+
+static void do_twl4030_pwrirq(unsigned int irq, irq_desc_t *desc)
+{
+	const unsigned int cpu = smp_processor_id();
+
+	desc->status |= IRQ_LEVEL;
+
+	desc->chip->ack(irq);
+
+	if (!desc->depth) {
+		int ret;
+		int module_irq;
+		u8 pwr_isr;
+
+		kstat_cpu(cpu).irqs[irq]++;
+
+		local_irq_enable();
+		ret = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &pwr_isr,
+						PWR_ISR1);
+		if (ret) {
+			printk(KERN_WARNING
+				"I2C error %d while reading TWL4030"
+				"INT PWR_ISR1 register\n", ret);
+			return;
+		}
+
+		for (module_irq = IH_TWL4030_PWRBASE; pwr_isr != 0;
+			module_irq++, pwr_isr >>= 1) {
+			if (pwr_isr & 1) {
+				irq_desc_t *d = irq_desc + module_irq;
+				d->handle_irq(module_irq, d);
+		}
+
+		local_irq_disable();
+		desc->chip->unmask(irq);
+	}
+}
+
+static int twl4030_pwrirq_thread(void *data)
+{
+	current->flags |= PF_NOFREEZE;
+
+	while (!kthread_should_stop()) {
+		u8 local_unmask;
+
+		local_irq_disable();
+		local_unmask = twl4030_pwrirq_pending_unmask;
+		twl4030_pwrirq_pending_unmask = 0;
+		local_irq_enable();
+
+		twl4030_pwrirq_mask &= ~local_unmask;
+
+		twl4030_i2c_write_u8(TWL4030_MODULE_INT, twl4030_pwrirq_mask,
+					PWR_IMR1);
+
+		local_irq_disable();
+		if (!twl4030_pwrirq_pending_unmask)
+			set_current_state(TASK_INTERRUPTIBLE);
+		local_irq_enable();
+
+		schedule();
+	}
+	set_current_state(TASK_RUNNING);
+	return 0;
+}
+
+static int __init twl4030_pwrirq_init(void)
+{
+	int i, err;
+
+	twl4030_pwrirq_mask = 0xff;
+	twl4030_pwrirq_pending_unmask = 0;
+
+	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT, twl4030_pwrirq_mask,
+					PWR_IMR1);
+	if (err)
+		return err;
+
+	/* Enable clear on read */
+
+	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT, PWR_SIH_CTRL_COR,
+					PWR_SIH_CTRL);
+	if (err)
+		return err;
+
+	twl4030_pwrirq_unmask_thread = kthread_create(twl4030_pwrirq_thread,
+		NULL, "twl4030 pwrirq");
+	if (!twl4030_pwrirq_unmask_thread) {
+		printk(KERN_ERR
+			"%s: could not create twl4030 pwrirq unmask thread!\n",
+				__func__);
+		return -ENOMEM;
+	}
+
+	for (i = IH_TWL4030_PWRBASE; i < IH_TWL4030_PWRBASE_END; i++) {
+		set_irq_chip(i, &twl4030_pwrirq_chip);
+		set_irq_handler(i, do_twl4030_pwrmodule_irq);
+		set_irq_flags(i, IRQF_VALID);
+	}
+
+	set_irq_chained_handler(TWL4030_MODIRQ_PWR, do_twl4030_pwrirq);
+
+	return 0;
+}
+
+static void __exit twl4030_pwrirq_exit(void)
+{
+
+	int i;
+
+	set_irq_handler(TWL4030_MODIRQ_PWR, NULL);
+	set_irq_flags(TWL4030_MODIRQ_PWR, 0);
+
+	for (i = IH_TWL4030_PWRBASE; i < IH_TWL4030_PWRBASE_END; i++) {
+		set_irq_handler(i, NULL);
+		set_irq_flags(i, 0);
+	}
+
+	if (twl4030_pwrirq_unmask_thread) {
+		kthread_stop(twl4030_pwrirq_unmask_thread);
+		twl4030_pwrirq_unmask_thread = NULL;
+	}
+}
+
+subsys_initcall(twl4030_pwrirq_init);
+module_exit(twl4030_pwrirq_exit);
diff --git a/include/asm-arm/arch-omap/board-3430sdp.h b/include/asm-arm/arch-omap/board-3430sdp.h
index 06379cf..87f47e5 100644
--- a/include/asm-arm/arch-omap/board-3430sdp.h
+++ b/include/asm-arm/arch-omap/board-3430sdp.h
@@ -75,14 +75,17 @@ extern void sdp_mmc_init(void);
 #define	IH_TWL4030_BASE		IH_BOARD_BASE
 #define	IH_TWL4030_END		(IH_TWL4030_BASE+8)
 
+#define IH_TWL4030_PWRBASE     (IH_TWL4030_END)
+#define IH_TWL4030_PWRBASE_END (IH_TWL4030_PWRBASE+8)
+
 #ifdef CONFIG_TWL4030_GPIO
 
 /* TWL4030 GPIO Interrupts */
-#define IH_TWL4030_GPIO_BASE	(IH_TWL4030_END)
-#define IH_TWL4030_GPIO_END	(IH_TWL4030_BASE+18)
+#define IH_TWL4030_GPIO_BASE	(IH_TWL4030_PWRBASE_END)
+#define IH_TWL4030_GPIO_END	(IH_TWL4030_GPIO_BASE+18)
 #define NR_IRQS			(IH_TWL4030_GPIO_END)
 #else
-#define NR_IRQS			(IH_TWL4030_END)
+#define NR_IRQS			(IH_TWL4030_PWRBASE_END)
 #endif /* CONFIG_I2C_TWL4030_GPIO */
 #endif /* End of support for TWL4030 */
 #endif /*  __ASM_ARCH_OMAP_3430SDP_H */
-- 
1.5.5.rc2.25.g5fbd



-- 
	- Balbi

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

* Re: [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support
  2008-04-03 13:47 ` [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support Felipe Balbi
@ 2008-04-03 13:57   ` Peter 'p2' De Schrijver
  2008-04-03 14:04     ` Felipe Balbi
  0 siblings, 1 reply; 8+ messages in thread
From: Peter 'p2' De Schrijver @ 2008-04-03 13:57 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: linux-omap

Felipe,

> +
> +		for (module_irq = IH_TWL4030_PWRBASE; pwr_isr != 0;
> +			module_irq++, pwr_isr >>= 1) {
> +			if (pwr_isr & 1) {
> +				irq_desc_t *d = irq_desc + module_irq;
> +				d->handle_irq(module_irq, d);

There is a missing } here.

> +		}
> +
> +		local_irq_disable();
> +		desc->chip->unmask(irq);
> +	}
> +}
> +

Cheers,

Peter.

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

* Re: [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support
  2008-04-03 13:57   ` Peter 'p2' De Schrijver
@ 2008-04-03 14:04     ` Felipe Balbi
  2008-04-04  9:44       ` Tony Lindgren
  0 siblings, 1 reply; 8+ messages in thread
From: Felipe Balbi @ 2008-04-03 14:04 UTC (permalink / raw)
  To: Peter 'p2' De Schrijver; +Cc: Felipe Balbi, linux-omap

On Thu, Apr 03, 2008 at 04:57:33PM +0300, Peter 'p2' De Schrijver wrote:
> Felipe,
> 
> > +
> > +		for (module_irq = IH_TWL4030_PWRBASE; pwr_isr != 0;
> > +			module_irq++, pwr_isr >>= 1) {
> > +			if (pwr_isr & 1) {
> > +				irq_desc_t *d = irq_desc + module_irq;
> > +				d->handle_irq(module_irq, d);
> 
> There is a missing } here.
> 
> > +		}
> > +
> > +		local_irq_disable();
> > +		desc->chip->unmask(irq);
> > +	}
> > +}
> > +
> 
> Cheers,
> 
> Peter.

Ugh, edited by hand and forgot it.

hopefully the final version:

>From 10b0fa72ded443a8d89ef3676f9ea08b3b87f8c0 Mon Sep 17 00:00:00 2001
From: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>
Date: Wed, 2 Apr 2008 20:57:58 +0300
Subject: [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support

The following patch implements power button and IRQ support
for triton2 power block.

Signed-off-by: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>
Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
---
 drivers/i2c/chips/twl4030-pwrbutton.c     |  160 ++++++++++++++++++++
 drivers/i2c/chips/twl4030-pwrirq.c        |  224 +++++++++++++++++++++++++++++
 include/asm-arm/arch-omap/board-3430sdp.h |    9 +-
 3 files changed, 390 insertions(+), 3 deletions(-)
 create mode 100644 drivers/i2c/chips/twl4030-pwrbutton.c
 create mode 100644 drivers/i2c/chips/twl4030-pwrirq.c

diff --git a/drivers/i2c/chips/twl4030-pwrbutton.c b/drivers/i2c/chips/twl4030-pwrbutton.c
new file mode 100644
index 0000000..a541ed6
--- /dev/null
+++ b/drivers/i2c/chips/twl4030-pwrbutton.c
@@ -0,0 +1,160 @@
+/**
+ * drivers/i2c/chips/twl4030-pwrbutton.c
+ *
+ * Driver for sending triton2 power button event to input-layer
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * Written by Peter De Schrijver <peter.de-schrijver@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/timer.h>
+#include <linux/jiffies.h>
+#include <linux/kthread.h>
+#include <linux/interrupt.h>
+#include <linux/i2c/twl4030.h>
+
+#define PWR_ISR1 0
+#define PWR_IMR1 1
+#define PWR_PWRON_IRQ (1<<0)
+
+#define PWR_EDR1 5
+#define PWR_PWRON_RISING (1<<1)
+#define PWR_PWRON_FALLING  (1<<0)
+#define PWR_PWRON_BOTH (PWR_PWRON_RISING | PWR_PWRON_FALLING)
+
+#define PWR_SIH_CTRL 7
+
+#define STS_HW_CONDITIONS 0xf
+
+static struct input_dev *powerbutton_dev;
+
+/*
+ * Note : the following function runs in kernel thread context
+ * with IRQs enabled
+ */
+
+static irqreturn_t powerbutton_irq(int irq, void *dev_id)
+{
+	int err;
+	u8 value;
+
+	err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &value,
+				  STS_HW_CONDITIONS);
+	if (!err)  {
+		input_report_key(powerbutton_dev, KEY_POWER,
+				 value & PWR_PWRON_IRQ);
+	} else {
+		printk(KERN_WARNING "I2C error %d while reading TWL4030"
+			"PM_MASTER STS_HW_CONDITIONS register\n", err);
+	}
+
+	return IRQ_HANDLED;
+}
+
+static int __init twl4030_pwrbutton_init(void)
+{
+	int err = 0;
+	u8 value;
+
+	if (request_irq(TWL4030_PWRIRQ_PWRBTN, powerbutton_irq, 0,
+			"PwrButton", NULL) < 0) {
+		printk(KERN_ERR "Unable to allocate IRQ for power button\n");
+		err = -EBUSY;
+		goto out;
+	}
+
+	powerbutton_dev = input_allocate_device();
+	if (!powerbutton_dev) {
+		printk(KERN_ERR
+			"Unable to allocate input device for power button\n");
+		err = -ENOMEM;
+		goto free_irq_and_out;
+	}
+
+	powerbutton_dev->evbit[0] = BIT_MASK(EV_KEY);
+	powerbutton_dev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
+	powerbutton_dev->name = "triton2-pwrbutton";
+
+	err = input_register_device(powerbutton_dev);
+	if (err)
+		goto free_input_dev;
+
+	err = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &value, PWR_IMR1);
+	if (err) {
+		printk(KERN_WARNING "I2C error %d while reading TWL4030"
+					"INT PWR_IMR1 register\n", err);
+
+		goto free_input_dev;
+	}
+
+	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT,
+				   value & (~PWR_PWRON_IRQ), PWR_IMR1);
+	if (err) {
+		printk(KERN_WARNING "I2C error %d while writing TWL4030"
+				    "INT PWR_IMR1 register\n", err);
+		goto free_input_dev;
+	}
+
+	err = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &value, PWR_EDR1);
+	if (err) {
+		printk(KERN_WARNING "I2C error %d while reading TWL4030"
+					"INT PWR_EDR1 register\n", err);
+		goto free_input_dev;
+	}
+
+	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT,
+				   value | PWR_PWRON_BOTH , PWR_EDR1);
+
+	if (err) {
+		printk(KERN_WARNING "I2C error %d while writing TWL4030"
+					"INT PWR_EDR1 register\n", err);
+		goto free_input_dev;
+	}
+
+	printk(KERN_INFO "triton2 power button driver initialized\n");
+
+	return 0;
+
+
+free_input_dev:
+	input_free_device(powerbutton_dev);
+free_irq_and_out:
+	free_irq(TWL4030_PWRIRQ_PWRBTN, NULL);
+out:
+	return err;
+}
+
+static void __exit twl4030_pwrbutton_exit(void)
+{
+	free_irq(TWL4030_PWRIRQ_PWRBTN, NULL);
+	input_unregister_device(powerbutton_dev);
+	input_free_device(powerbutton_dev);
+
+}
+
+module_init(twl4030_pwrbutton_init);
+module_exit(twl4030_pwrbutton_exit);
+
+MODULE_DESCRIPTION("Triton2 Power Button");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Peter De Schrijver");
+
diff --git a/drivers/i2c/chips/twl4030-pwrirq.c b/drivers/i2c/chips/twl4030-pwrirq.c
new file mode 100644
index 0000000..d6098ad
--- /dev/null
+++ b/drivers/i2c/chips/twl4030-pwrirq.c
@@ -0,0 +1,224 @@
+/*
+ * twl4030-pwrirq.c - handle power interrupts from TWL3040
+ *
+ * Copyright (C) 2008 Nokia Corporation
+ *
+ * Written by Peter De Schrijver <peter.de-schrijver@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/kernel_stat.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/i2c.h>
+#include <linux/random.h>
+#include <linux/kthread.h>
+#include <linux/i2c/twl4030.h>
+
+#define PWR_ISR1 0
+#define PWR_IMR1 1
+#define PWR_SIH_CTRL 7
+#define PWR_SIH_CTRL_COR (1<<2)
+
+static u8 twl4030_pwrirq_mask;
+static u8 twl4030_pwrirq_pending_unmask;
+
+static struct task_struct *twl4030_pwrirq_unmask_thread;
+
+static void twl4030_pwrirq_ack(unsigned int irq) {}
+
+static void twl4030_pwrirq_disableint(unsigned int irq) {}
+
+static void twl4030_pwrirq_enableint(unsigned int irq)
+{
+	twl4030_pwrirq_pending_unmask |= 1 << (irq - IH_TWL4030_PWRBASE);
+	if (twl4030_pwrirq_unmask_thread &&
+		twl4030_pwrirq_unmask_thread->state != TASK_RUNNING)
+		wake_up_process(twl4030_pwrirq_unmask_thread);
+}
+
+static struct irq_chip twl4030_pwrirq_chip = {
+	.name	= "twl4030-pwr",
+	.ack	= twl4030_pwrirq_ack,
+	.mask	= twl4030_pwrirq_disableint,
+	.unmask	= twl4030_pwrirq_enableint,
+};
+
+static void do_twl4030_pwrmodule_irq(unsigned int irq, irq_desc_t *desc)
+{
+	struct irqaction *action;
+	const unsigned int cpu = smp_processor_id();
+
+	desc->status |= IRQ_LEVEL;
+
+	if (!desc->depth) {
+		kstat_cpu(cpu).irqs[irq]++;
+
+		action = desc->action;
+		if (action) {
+			int ret;
+			int status = 0;
+			int retval = 0;
+
+			do {
+				ret = action->handler(irq, action->dev_id);
+				if (ret == IRQ_HANDLED)
+					status |= action->flags;
+				retval |= ret;
+				action = action->next;
+			} while (action);
+
+			if (status & IRQF_SAMPLE_RANDOM)
+				add_interrupt_randomness(irq);
+
+			if (retval != IRQ_HANDLED)
+				printk(KERN_ERR "ISR for TWL4030 power module"
+					" irq %d can't handle interrupt\n",
+					irq);
+		} else {
+			local_irq_disable();
+			twl4030_pwrirq_mask |= 1 << (irq - IH_TWL4030_PWRBASE);
+			local_irq_enable();
+			twl4030_i2c_write_u8(TWL4030_MODULE_INT,
+						twl4030_pwrirq_mask, PWR_IMR1);
+		}
+	}
+}
+
+static void do_twl4030_pwrirq(unsigned int irq, irq_desc_t *desc)
+{
+	const unsigned int cpu = smp_processor_id();
+
+	desc->status |= IRQ_LEVEL;
+
+	desc->chip->ack(irq);
+
+	if (!desc->depth) {
+		int ret;
+		int module_irq;
+		u8 pwr_isr;
+
+		kstat_cpu(cpu).irqs[irq]++;
+
+		local_irq_enable();
+		ret = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &pwr_isr,
+						PWR_ISR1);
+		if (ret) {
+			printk(KERN_WARNING
+				"I2C error %d while reading TWL4030"
+				"INT PWR_ISR1 register\n", ret);
+			return;
+		}
+
+		for (module_irq = IH_TWL4030_PWRBASE; pwr_isr != 0;
+			module_irq++, pwr_isr >>= 1) {
+			if (pwr_isr & 1)
+				irq_desc_t *d = irq_desc + module_irq;
+		}
+
+		local_irq_disable();
+		desc->chip->unmask(irq);
+	}
+}
+
+static int twl4030_pwrirq_thread(void *data)
+{
+	current->flags |= PF_NOFREEZE;
+
+	while (!kthread_should_stop()) {
+		u8 local_unmask;
+
+		local_irq_disable();
+		local_unmask = twl4030_pwrirq_pending_unmask;
+		twl4030_pwrirq_pending_unmask = 0;
+		local_irq_enable();
+
+		twl4030_pwrirq_mask &= ~local_unmask;
+
+		twl4030_i2c_write_u8(TWL4030_MODULE_INT, twl4030_pwrirq_mask,
+					PWR_IMR1);
+
+		local_irq_disable();
+		if (!twl4030_pwrirq_pending_unmask)
+			set_current_state(TASK_INTERRUPTIBLE);
+		local_irq_enable();
+
+		schedule();
+	}
+	set_current_state(TASK_RUNNING);
+	return 0;
+}
+
+static int __init twl4030_pwrirq_init(void)
+{
+	int i, err;
+
+	twl4030_pwrirq_mask = 0xff;
+	twl4030_pwrirq_pending_unmask = 0;
+
+	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT, twl4030_pwrirq_mask,
+					PWR_IMR1);
+	if (err)
+		return err;
+
+	/* Enable clear on read */
+
+	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT, PWR_SIH_CTRL_COR,
+					PWR_SIH_CTRL);
+	if (err)
+		return err;
+
+	twl4030_pwrirq_unmask_thread = kthread_create(twl4030_pwrirq_thread,
+		NULL, "twl4030 pwrirq");
+	if (!twl4030_pwrirq_unmask_thread) {
+		printk(KERN_ERR
+			"%s: could not create twl4030 pwrirq unmask thread!\n",
+				__func__);
+		return -ENOMEM;
+	}
+
+	for (i = IH_TWL4030_PWRBASE; i < IH_TWL4030_PWRBASE_END; i++) {
+		set_irq_chip(i, &twl4030_pwrirq_chip);
+		set_irq_handler(i, do_twl4030_pwrmodule_irq);
+		set_irq_flags(i, IRQF_VALID);
+	}
+
+	set_irq_chained_handler(TWL4030_MODIRQ_PWR, do_twl4030_pwrirq);
+
+	return 0;
+}
+
+static void __exit twl4030_pwrirq_exit(void)
+{
+
+	int i;
+
+	set_irq_handler(TWL4030_MODIRQ_PWR, NULL);
+	set_irq_flags(TWL4030_MODIRQ_PWR, 0);
+
+	for (i = IH_TWL4030_PWRBASE; i < IH_TWL4030_PWRBASE_END; i++) {
+		set_irq_handler(i, NULL);
+		set_irq_flags(i, 0);
+	}
+
+	if (twl4030_pwrirq_unmask_thread) {
+		kthread_stop(twl4030_pwrirq_unmask_thread);
+		twl4030_pwrirq_unmask_thread = NULL;
+	}
+}
+
+subsys_initcall(twl4030_pwrirq_init);
+module_exit(twl4030_pwrirq_exit);
diff --git a/include/asm-arm/arch-omap/board-3430sdp.h b/include/asm-arm/arch-omap/board-3430sdp.h
index 06379cf..87f47e5 100644
--- a/include/asm-arm/arch-omap/board-3430sdp.h
+++ b/include/asm-arm/arch-omap/board-3430sdp.h
@@ -75,14 +75,17 @@ extern void sdp_mmc_init(void);
 #define	IH_TWL4030_BASE		IH_BOARD_BASE
 #define	IH_TWL4030_END		(IH_TWL4030_BASE+8)
 
+#define IH_TWL4030_PWRBASE     (IH_TWL4030_END)
+#define IH_TWL4030_PWRBASE_END (IH_TWL4030_PWRBASE+8)
+
 #ifdef CONFIG_TWL4030_GPIO
 
 /* TWL4030 GPIO Interrupts */
-#define IH_TWL4030_GPIO_BASE	(IH_TWL4030_END)
-#define IH_TWL4030_GPIO_END	(IH_TWL4030_BASE+18)
+#define IH_TWL4030_GPIO_BASE	(IH_TWL4030_PWRBASE_END)
+#define IH_TWL4030_GPIO_END	(IH_TWL4030_GPIO_BASE+18)
 #define NR_IRQS			(IH_TWL4030_GPIO_END)
 #else
-#define NR_IRQS			(IH_TWL4030_END)
+#define NR_IRQS			(IH_TWL4030_PWRBASE_END)
 #endif /* CONFIG_I2C_TWL4030_GPIO */
 #endif /* End of support for TWL4030 */
 #endif /*  __ASM_ARCH_OMAP_3430SDP_H */
-- 
1.5.5.rc2.25.g5fbd



-- 
	- Balbi

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

* Re: [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support
  2008-04-03 14:04     ` Felipe Balbi
@ 2008-04-04  9:44       ` Tony Lindgren
  2008-04-04 10:09         ` Tony Lindgren
  0 siblings, 1 reply; 8+ messages in thread
From: Tony Lindgren @ 2008-04-04  9:44 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Peter 'p2' De Schrijver, linux-omap

* Felipe Balbi <felipe.balbi@nokia.com> [080403 17:10]:
> On Thu, Apr 03, 2008 at 04:57:33PM +0300, Peter 'p2' De Schrijver wrote:
> > Felipe,
> > 
> > > +
> > > +		for (module_irq = IH_TWL4030_PWRBASE; pwr_isr != 0;
> > > +			module_irq++, pwr_isr >>= 1) {
> > > +			if (pwr_isr & 1) {
> > > +				irq_desc_t *d = irq_desc + module_irq;
> > > +				d->handle_irq(module_irq, d);
> > 
> > There is a missing } here.
> > 
> > > +		}
> > > +
> > > +		local_irq_disable();
> > > +		desc->chip->unmask(irq);
> > > +	}
> > > +}
> > > +
> > 
> > Cheers,
> > 
> > Peter.
> 
> Ugh, edited by hand and forgot it.
> 
> hopefully the final version:

Pushing this series today.

Tony


> From 10b0fa72ded443a8d89ef3676f9ea08b3b87f8c0 Mon Sep 17 00:00:00 2001
> From: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>
> Date: Wed, 2 Apr 2008 20:57:58 +0300
> Subject: [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support
> 
> The following patch implements power button and IRQ support
> for triton2 power block.
> 
> Signed-off-by: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>
> Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
> ---
>  drivers/i2c/chips/twl4030-pwrbutton.c     |  160 ++++++++++++++++++++
>  drivers/i2c/chips/twl4030-pwrirq.c        |  224 +++++++++++++++++++++++++++++
>  include/asm-arm/arch-omap/board-3430sdp.h |    9 +-
>  3 files changed, 390 insertions(+), 3 deletions(-)
>  create mode 100644 drivers/i2c/chips/twl4030-pwrbutton.c
>  create mode 100644 drivers/i2c/chips/twl4030-pwrirq.c
> 
> diff --git a/drivers/i2c/chips/twl4030-pwrbutton.c b/drivers/i2c/chips/twl4030-pwrbutton.c
> new file mode 100644
> index 0000000..a541ed6
> --- /dev/null
> +++ b/drivers/i2c/chips/twl4030-pwrbutton.c
> @@ -0,0 +1,160 @@
> +/**
> + * drivers/i2c/chips/twl4030-pwrbutton.c
> + *
> + * Driver for sending triton2 power button event to input-layer
> + *
> + * Copyright (C) 2008 Nokia Corporation
> + *
> + * Written by Peter De Schrijver <peter.de-schrijver@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/timer.h>
> +#include <linux/jiffies.h>
> +#include <linux/kthread.h>
> +#include <linux/interrupt.h>
> +#include <linux/i2c/twl4030.h>
> +
> +#define PWR_ISR1 0
> +#define PWR_IMR1 1
> +#define PWR_PWRON_IRQ (1<<0)
> +
> +#define PWR_EDR1 5
> +#define PWR_PWRON_RISING (1<<1)
> +#define PWR_PWRON_FALLING  (1<<0)
> +#define PWR_PWRON_BOTH (PWR_PWRON_RISING | PWR_PWRON_FALLING)
> +
> +#define PWR_SIH_CTRL 7
> +
> +#define STS_HW_CONDITIONS 0xf
> +
> +static struct input_dev *powerbutton_dev;
> +
> +/*
> + * Note : the following function runs in kernel thread context
> + * with IRQs enabled
> + */
> +
> +static irqreturn_t powerbutton_irq(int irq, void *dev_id)
> +{
> +	int err;
> +	u8 value;
> +
> +	err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &value,
> +				  STS_HW_CONDITIONS);
> +	if (!err)  {
> +		input_report_key(powerbutton_dev, KEY_POWER,
> +				 value & PWR_PWRON_IRQ);
> +	} else {
> +		printk(KERN_WARNING "I2C error %d while reading TWL4030"
> +			"PM_MASTER STS_HW_CONDITIONS register\n", err);
> +	}
> +
> +	return IRQ_HANDLED;
> +}
> +
> +static int __init twl4030_pwrbutton_init(void)
> +{
> +	int err = 0;
> +	u8 value;
> +
> +	if (request_irq(TWL4030_PWRIRQ_PWRBTN, powerbutton_irq, 0,
> +			"PwrButton", NULL) < 0) {
> +		printk(KERN_ERR "Unable to allocate IRQ for power button\n");
> +		err = -EBUSY;
> +		goto out;
> +	}
> +
> +	powerbutton_dev = input_allocate_device();
> +	if (!powerbutton_dev) {
> +		printk(KERN_ERR
> +			"Unable to allocate input device for power button\n");
> +		err = -ENOMEM;
> +		goto free_irq_and_out;
> +	}
> +
> +	powerbutton_dev->evbit[0] = BIT_MASK(EV_KEY);
> +	powerbutton_dev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
> +	powerbutton_dev->name = "triton2-pwrbutton";
> +
> +	err = input_register_device(powerbutton_dev);
> +	if (err)
> +		goto free_input_dev;
> +
> +	err = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &value, PWR_IMR1);
> +	if (err) {
> +		printk(KERN_WARNING "I2C error %d while reading TWL4030"
> +					"INT PWR_IMR1 register\n", err);
> +
> +		goto free_input_dev;
> +	}
> +
> +	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT,
> +				   value & (~PWR_PWRON_IRQ), PWR_IMR1);
> +	if (err) {
> +		printk(KERN_WARNING "I2C error %d while writing TWL4030"
> +				    "INT PWR_IMR1 register\n", err);
> +		goto free_input_dev;
> +	}
> +
> +	err = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &value, PWR_EDR1);
> +	if (err) {
> +		printk(KERN_WARNING "I2C error %d while reading TWL4030"
> +					"INT PWR_EDR1 register\n", err);
> +		goto free_input_dev;
> +	}
> +
> +	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT,
> +				   value | PWR_PWRON_BOTH , PWR_EDR1);
> +
> +	if (err) {
> +		printk(KERN_WARNING "I2C error %d while writing TWL4030"
> +					"INT PWR_EDR1 register\n", err);
> +		goto free_input_dev;
> +	}
> +
> +	printk(KERN_INFO "triton2 power button driver initialized\n");
> +
> +	return 0;
> +
> +
> +free_input_dev:
> +	input_free_device(powerbutton_dev);
> +free_irq_and_out:
> +	free_irq(TWL4030_PWRIRQ_PWRBTN, NULL);
> +out:
> +	return err;
> +}
> +
> +static void __exit twl4030_pwrbutton_exit(void)
> +{
> +	free_irq(TWL4030_PWRIRQ_PWRBTN, NULL);
> +	input_unregister_device(powerbutton_dev);
> +	input_free_device(powerbutton_dev);
> +
> +}
> +
> +module_init(twl4030_pwrbutton_init);
> +module_exit(twl4030_pwrbutton_exit);
> +
> +MODULE_DESCRIPTION("Triton2 Power Button");
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("Peter De Schrijver");
> +
> diff --git a/drivers/i2c/chips/twl4030-pwrirq.c b/drivers/i2c/chips/twl4030-pwrirq.c
> new file mode 100644
> index 0000000..d6098ad
> --- /dev/null
> +++ b/drivers/i2c/chips/twl4030-pwrirq.c
> @@ -0,0 +1,224 @@
> +/*
> + * twl4030-pwrirq.c - handle power interrupts from TWL3040
> + *
> + * Copyright (C) 2008 Nokia Corporation
> + *
> + * Written by Peter De Schrijver <peter.de-schrijver@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/kernel_stat.h>
> +#include <linux/module.h>
> +#include <linux/interrupt.h>
> +#include <linux/irq.h>
> +#include <linux/i2c.h>
> +#include <linux/random.h>
> +#include <linux/kthread.h>
> +#include <linux/i2c/twl4030.h>
> +
> +#define PWR_ISR1 0
> +#define PWR_IMR1 1
> +#define PWR_SIH_CTRL 7
> +#define PWR_SIH_CTRL_COR (1<<2)
> +
> +static u8 twl4030_pwrirq_mask;
> +static u8 twl4030_pwrirq_pending_unmask;
> +
> +static struct task_struct *twl4030_pwrirq_unmask_thread;
> +
> +static void twl4030_pwrirq_ack(unsigned int irq) {}
> +
> +static void twl4030_pwrirq_disableint(unsigned int irq) {}
> +
> +static void twl4030_pwrirq_enableint(unsigned int irq)
> +{
> +	twl4030_pwrirq_pending_unmask |= 1 << (irq - IH_TWL4030_PWRBASE);
> +	if (twl4030_pwrirq_unmask_thread &&
> +		twl4030_pwrirq_unmask_thread->state != TASK_RUNNING)
> +		wake_up_process(twl4030_pwrirq_unmask_thread);
> +}
> +
> +static struct irq_chip twl4030_pwrirq_chip = {
> +	.name	= "twl4030-pwr",
> +	.ack	= twl4030_pwrirq_ack,
> +	.mask	= twl4030_pwrirq_disableint,
> +	.unmask	= twl4030_pwrirq_enableint,
> +};
> +
> +static void do_twl4030_pwrmodule_irq(unsigned int irq, irq_desc_t *desc)
> +{
> +	struct irqaction *action;
> +	const unsigned int cpu = smp_processor_id();
> +
> +	desc->status |= IRQ_LEVEL;
> +
> +	if (!desc->depth) {
> +		kstat_cpu(cpu).irqs[irq]++;
> +
> +		action = desc->action;
> +		if (action) {
> +			int ret;
> +			int status = 0;
> +			int retval = 0;
> +
> +			do {
> +				ret = action->handler(irq, action->dev_id);
> +				if (ret == IRQ_HANDLED)
> +					status |= action->flags;
> +				retval |= ret;
> +				action = action->next;
> +			} while (action);
> +
> +			if (status & IRQF_SAMPLE_RANDOM)
> +				add_interrupt_randomness(irq);
> +
> +			if (retval != IRQ_HANDLED)
> +				printk(KERN_ERR "ISR for TWL4030 power module"
> +					" irq %d can't handle interrupt\n",
> +					irq);
> +		} else {
> +			local_irq_disable();
> +			twl4030_pwrirq_mask |= 1 << (irq - IH_TWL4030_PWRBASE);
> +			local_irq_enable();
> +			twl4030_i2c_write_u8(TWL4030_MODULE_INT,
> +						twl4030_pwrirq_mask, PWR_IMR1);
> +		}
> +	}
> +}
> +
> +static void do_twl4030_pwrirq(unsigned int irq, irq_desc_t *desc)
> +{
> +	const unsigned int cpu = smp_processor_id();
> +
> +	desc->status |= IRQ_LEVEL;
> +
> +	desc->chip->ack(irq);
> +
> +	if (!desc->depth) {
> +		int ret;
> +		int module_irq;
> +		u8 pwr_isr;
> +
> +		kstat_cpu(cpu).irqs[irq]++;
> +
> +		local_irq_enable();
> +		ret = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &pwr_isr,
> +						PWR_ISR1);
> +		if (ret) {
> +			printk(KERN_WARNING
> +				"I2C error %d while reading TWL4030"
> +				"INT PWR_ISR1 register\n", ret);
> +			return;
> +		}
> +
> +		for (module_irq = IH_TWL4030_PWRBASE; pwr_isr != 0;
> +			module_irq++, pwr_isr >>= 1) {
> +			if (pwr_isr & 1)
> +				irq_desc_t *d = irq_desc + module_irq;
> +		}
> +
> +		local_irq_disable();
> +		desc->chip->unmask(irq);
> +	}
> +}
> +
> +static int twl4030_pwrirq_thread(void *data)
> +{
> +	current->flags |= PF_NOFREEZE;
> +
> +	while (!kthread_should_stop()) {
> +		u8 local_unmask;
> +
> +		local_irq_disable();
> +		local_unmask = twl4030_pwrirq_pending_unmask;
> +		twl4030_pwrirq_pending_unmask = 0;
> +		local_irq_enable();
> +
> +		twl4030_pwrirq_mask &= ~local_unmask;
> +
> +		twl4030_i2c_write_u8(TWL4030_MODULE_INT, twl4030_pwrirq_mask,
> +					PWR_IMR1);
> +
> +		local_irq_disable();
> +		if (!twl4030_pwrirq_pending_unmask)
> +			set_current_state(TASK_INTERRUPTIBLE);
> +		local_irq_enable();
> +
> +		schedule();
> +	}
> +	set_current_state(TASK_RUNNING);
> +	return 0;
> +}
> +
> +static int __init twl4030_pwrirq_init(void)
> +{
> +	int i, err;
> +
> +	twl4030_pwrirq_mask = 0xff;
> +	twl4030_pwrirq_pending_unmask = 0;
> +
> +	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT, twl4030_pwrirq_mask,
> +					PWR_IMR1);
> +	if (err)
> +		return err;
> +
> +	/* Enable clear on read */
> +
> +	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT, PWR_SIH_CTRL_COR,
> +					PWR_SIH_CTRL);
> +	if (err)
> +		return err;
> +
> +	twl4030_pwrirq_unmask_thread = kthread_create(twl4030_pwrirq_thread,
> +		NULL, "twl4030 pwrirq");
> +	if (!twl4030_pwrirq_unmask_thread) {
> +		printk(KERN_ERR
> +			"%s: could not create twl4030 pwrirq unmask thread!\n",
> +				__func__);
> +		return -ENOMEM;
> +	}
> +
> +	for (i = IH_TWL4030_PWRBASE; i < IH_TWL4030_PWRBASE_END; i++) {
> +		set_irq_chip(i, &twl4030_pwrirq_chip);
> +		set_irq_handler(i, do_twl4030_pwrmodule_irq);
> +		set_irq_flags(i, IRQF_VALID);
> +	}
> +
> +	set_irq_chained_handler(TWL4030_MODIRQ_PWR, do_twl4030_pwrirq);
> +
> +	return 0;
> +}
> +
> +static void __exit twl4030_pwrirq_exit(void)
> +{
> +
> +	int i;
> +
> +	set_irq_handler(TWL4030_MODIRQ_PWR, NULL);
> +	set_irq_flags(TWL4030_MODIRQ_PWR, 0);
> +
> +	for (i = IH_TWL4030_PWRBASE; i < IH_TWL4030_PWRBASE_END; i++) {
> +		set_irq_handler(i, NULL);
> +		set_irq_flags(i, 0);
> +	}
> +
> +	if (twl4030_pwrirq_unmask_thread) {
> +		kthread_stop(twl4030_pwrirq_unmask_thread);
> +		twl4030_pwrirq_unmask_thread = NULL;
> +	}
> +}
> +
> +subsys_initcall(twl4030_pwrirq_init);
> +module_exit(twl4030_pwrirq_exit);
> diff --git a/include/asm-arm/arch-omap/board-3430sdp.h b/include/asm-arm/arch-omap/board-3430sdp.h
> index 06379cf..87f47e5 100644
> --- a/include/asm-arm/arch-omap/board-3430sdp.h
> +++ b/include/asm-arm/arch-omap/board-3430sdp.h
> @@ -75,14 +75,17 @@ extern void sdp_mmc_init(void);
>  #define	IH_TWL4030_BASE		IH_BOARD_BASE
>  #define	IH_TWL4030_END		(IH_TWL4030_BASE+8)
>  
> +#define IH_TWL4030_PWRBASE     (IH_TWL4030_END)
> +#define IH_TWL4030_PWRBASE_END (IH_TWL4030_PWRBASE+8)
> +
>  #ifdef CONFIG_TWL4030_GPIO
>  
>  /* TWL4030 GPIO Interrupts */
> -#define IH_TWL4030_GPIO_BASE	(IH_TWL4030_END)
> -#define IH_TWL4030_GPIO_END	(IH_TWL4030_BASE+18)
> +#define IH_TWL4030_GPIO_BASE	(IH_TWL4030_PWRBASE_END)
> +#define IH_TWL4030_GPIO_END	(IH_TWL4030_GPIO_BASE+18)
>  #define NR_IRQS			(IH_TWL4030_GPIO_END)
>  #else
> -#define NR_IRQS			(IH_TWL4030_END)
> +#define NR_IRQS			(IH_TWL4030_PWRBASE_END)
>  #endif /* CONFIG_I2C_TWL4030_GPIO */
>  #endif /* End of support for TWL4030 */
>  #endif /*  __ASM_ARCH_OMAP_3430SDP_H */
> -- 
> 1.5.5.rc2.25.g5fbd
> 
> 
> 
> -- 
> 	- Balbi
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" 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] 8+ messages in thread

* Re: [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support
  2008-04-04  9:44       ` Tony Lindgren
@ 2008-04-04 10:09         ` Tony Lindgren
  0 siblings, 0 replies; 8+ messages in thread
From: Tony Lindgren @ 2008-04-04 10:09 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: Peter 'p2' De Schrijver, linux-omap

* Tony Lindgren <tony@atomide.com> [080404 12:44]:
> * Felipe Balbi <felipe.balbi@nokia.com> [080403 17:10]:
> > On Thu, Apr 03, 2008 at 04:57:33PM +0300, Peter 'p2' De Schrijver wrote:
> > > Felipe,
> > > 
> > > > +
> > > > +		for (module_irq = IH_TWL4030_PWRBASE; pwr_isr != 0;
> > > > +			module_irq++, pwr_isr >>= 1) {
> > > > +			if (pwr_isr & 1) {
> > > > +				irq_desc_t *d = irq_desc + module_irq;
> > > > +				d->handle_irq(module_irq, d);
> > > 
> > > There is a missing } here.
> > > 
> > > > +		}
> > > > +
> > > > +		local_irq_disable();
> > > > +		desc->chip->unmask(irq);
> > > > +	}
> > > > +}
> > > > +
> > > 
> > > Cheers,
> > > 
> > > Peter.
> > 
> > Ugh, edited by hand and forgot it.
> > 
> > hopefully the final version:
> 
> Pushing this series today.

Actually now your patch was missing d->handle line and did not
compile.. I added those and pushed, can you please check?

> Tony
> 
> 
> > From 10b0fa72ded443a8d89ef3676f9ea08b3b87f8c0 Mon Sep 17 00:00:00 2001
> > From: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>
> > Date: Wed, 2 Apr 2008 20:57:58 +0300
> > Subject: [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support
> > 
> > The following patch implements power button and IRQ support
> > for triton2 power block.
> > 
> > Signed-off-by: Peter 'p2' De Schrijver <peter.de-schrijver@nokia.com>
> > Signed-off-by: Felipe Balbi <felipe.balbi@nokia.com>
> > ---
> >  drivers/i2c/chips/twl4030-pwrbutton.c     |  160 ++++++++++++++++++++
> >  drivers/i2c/chips/twl4030-pwrirq.c        |  224 +++++++++++++++++++++++++++++
> >  include/asm-arm/arch-omap/board-3430sdp.h |    9 +-
> >  3 files changed, 390 insertions(+), 3 deletions(-)
> >  create mode 100644 drivers/i2c/chips/twl4030-pwrbutton.c
> >  create mode 100644 drivers/i2c/chips/twl4030-pwrirq.c
> > 
> > diff --git a/drivers/i2c/chips/twl4030-pwrbutton.c b/drivers/i2c/chips/twl4030-pwrbutton.c
> > new file mode 100644
> > index 0000000..a541ed6
> > --- /dev/null
> > +++ b/drivers/i2c/chips/twl4030-pwrbutton.c
> > @@ -0,0 +1,160 @@
> > +/**
> > + * drivers/i2c/chips/twl4030-pwrbutton.c
> > + *
> > + * Driver for sending triton2 power button event to input-layer
> > + *
> > + * Copyright (C) 2008 Nokia Corporation
> > + *
> > + * Written by Peter De Schrijver <peter.de-schrijver@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/timer.h>
> > +#include <linux/jiffies.h>
> > +#include <linux/kthread.h>
> > +#include <linux/interrupt.h>
> > +#include <linux/i2c/twl4030.h>
> > +
> > +#define PWR_ISR1 0
> > +#define PWR_IMR1 1
> > +#define PWR_PWRON_IRQ (1<<0)
> > +
> > +#define PWR_EDR1 5
> > +#define PWR_PWRON_RISING (1<<1)
> > +#define PWR_PWRON_FALLING  (1<<0)
> > +#define PWR_PWRON_BOTH (PWR_PWRON_RISING | PWR_PWRON_FALLING)
> > +
> > +#define PWR_SIH_CTRL 7
> > +
> > +#define STS_HW_CONDITIONS 0xf
> > +
> > +static struct input_dev *powerbutton_dev;
> > +
> > +/*
> > + * Note : the following function runs in kernel thread context
> > + * with IRQs enabled
> > + */
> > +
> > +static irqreturn_t powerbutton_irq(int irq, void *dev_id)
> > +{
> > +	int err;
> > +	u8 value;
> > +
> > +	err = twl4030_i2c_read_u8(TWL4030_MODULE_PM_MASTER, &value,
> > +				  STS_HW_CONDITIONS);
> > +	if (!err)  {
> > +		input_report_key(powerbutton_dev, KEY_POWER,
> > +				 value & PWR_PWRON_IRQ);
> > +	} else {
> > +		printk(KERN_WARNING "I2C error %d while reading TWL4030"
> > +			"PM_MASTER STS_HW_CONDITIONS register\n", err);
> > +	}
> > +
> > +	return IRQ_HANDLED;
> > +}
> > +
> > +static int __init twl4030_pwrbutton_init(void)
> > +{
> > +	int err = 0;
> > +	u8 value;
> > +
> > +	if (request_irq(TWL4030_PWRIRQ_PWRBTN, powerbutton_irq, 0,
> > +			"PwrButton", NULL) < 0) {
> > +		printk(KERN_ERR "Unable to allocate IRQ for power button\n");
> > +		err = -EBUSY;
> > +		goto out;
> > +	}
> > +
> > +	powerbutton_dev = input_allocate_device();
> > +	if (!powerbutton_dev) {
> > +		printk(KERN_ERR
> > +			"Unable to allocate input device for power button\n");
> > +		err = -ENOMEM;
> > +		goto free_irq_and_out;
> > +	}
> > +
> > +	powerbutton_dev->evbit[0] = BIT_MASK(EV_KEY);
> > +	powerbutton_dev->keybit[BIT_WORD(KEY_POWER)] = BIT_MASK(KEY_POWER);
> > +	powerbutton_dev->name = "triton2-pwrbutton";
> > +
> > +	err = input_register_device(powerbutton_dev);
> > +	if (err)
> > +		goto free_input_dev;
> > +
> > +	err = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &value, PWR_IMR1);
> > +	if (err) {
> > +		printk(KERN_WARNING "I2C error %d while reading TWL4030"
> > +					"INT PWR_IMR1 register\n", err);
> > +
> > +		goto free_input_dev;
> > +	}
> > +
> > +	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT,
> > +				   value & (~PWR_PWRON_IRQ), PWR_IMR1);
> > +	if (err) {
> > +		printk(KERN_WARNING "I2C error %d while writing TWL4030"
> > +				    "INT PWR_IMR1 register\n", err);
> > +		goto free_input_dev;
> > +	}
> > +
> > +	err = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &value, PWR_EDR1);
> > +	if (err) {
> > +		printk(KERN_WARNING "I2C error %d while reading TWL4030"
> > +					"INT PWR_EDR1 register\n", err);
> > +		goto free_input_dev;
> > +	}
> > +
> > +	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT,
> > +				   value | PWR_PWRON_BOTH , PWR_EDR1);
> > +
> > +	if (err) {
> > +		printk(KERN_WARNING "I2C error %d while writing TWL4030"
> > +					"INT PWR_EDR1 register\n", err);
> > +		goto free_input_dev;
> > +	}
> > +
> > +	printk(KERN_INFO "triton2 power button driver initialized\n");
> > +
> > +	return 0;
> > +
> > +
> > +free_input_dev:
> > +	input_free_device(powerbutton_dev);
> > +free_irq_and_out:
> > +	free_irq(TWL4030_PWRIRQ_PWRBTN, NULL);
> > +out:
> > +	return err;
> > +}
> > +
> > +static void __exit twl4030_pwrbutton_exit(void)
> > +{
> > +	free_irq(TWL4030_PWRIRQ_PWRBTN, NULL);
> > +	input_unregister_device(powerbutton_dev);
> > +	input_free_device(powerbutton_dev);
> > +
> > +}
> > +
> > +module_init(twl4030_pwrbutton_init);
> > +module_exit(twl4030_pwrbutton_exit);
> > +
> > +MODULE_DESCRIPTION("Triton2 Power Button");
> > +MODULE_LICENSE("GPL");
> > +MODULE_AUTHOR("Peter De Schrijver");
> > +
> > diff --git a/drivers/i2c/chips/twl4030-pwrirq.c b/drivers/i2c/chips/twl4030-pwrirq.c
> > new file mode 100644
> > index 0000000..d6098ad
> > --- /dev/null
> > +++ b/drivers/i2c/chips/twl4030-pwrirq.c
> > @@ -0,0 +1,224 @@
> > +/*
> > + * twl4030-pwrirq.c - handle power interrupts from TWL3040
> > + *
> > + * Copyright (C) 2008 Nokia Corporation
> > + *
> > + * Written by Peter De Schrijver <peter.de-schrijver@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/kernel_stat.h>
> > +#include <linux/module.h>
> > +#include <linux/interrupt.h>
> > +#include <linux/irq.h>
> > +#include <linux/i2c.h>
> > +#include <linux/random.h>
> > +#include <linux/kthread.h>
> > +#include <linux/i2c/twl4030.h>
> > +
> > +#define PWR_ISR1 0
> > +#define PWR_IMR1 1
> > +#define PWR_SIH_CTRL 7
> > +#define PWR_SIH_CTRL_COR (1<<2)
> > +
> > +static u8 twl4030_pwrirq_mask;
> > +static u8 twl4030_pwrirq_pending_unmask;
> > +
> > +static struct task_struct *twl4030_pwrirq_unmask_thread;
> > +
> > +static void twl4030_pwrirq_ack(unsigned int irq) {}
> > +
> > +static void twl4030_pwrirq_disableint(unsigned int irq) {}
> > +
> > +static void twl4030_pwrirq_enableint(unsigned int irq)
> > +{
> > +	twl4030_pwrirq_pending_unmask |= 1 << (irq - IH_TWL4030_PWRBASE);
> > +	if (twl4030_pwrirq_unmask_thread &&
> > +		twl4030_pwrirq_unmask_thread->state != TASK_RUNNING)
> > +		wake_up_process(twl4030_pwrirq_unmask_thread);
> > +}
> > +
> > +static struct irq_chip twl4030_pwrirq_chip = {
> > +	.name	= "twl4030-pwr",
> > +	.ack	= twl4030_pwrirq_ack,
> > +	.mask	= twl4030_pwrirq_disableint,
> > +	.unmask	= twl4030_pwrirq_enableint,
> > +};
> > +
> > +static void do_twl4030_pwrmodule_irq(unsigned int irq, irq_desc_t *desc)
> > +{
> > +	struct irqaction *action;
> > +	const unsigned int cpu = smp_processor_id();
> > +
> > +	desc->status |= IRQ_LEVEL;
> > +
> > +	if (!desc->depth) {
> > +		kstat_cpu(cpu).irqs[irq]++;
> > +
> > +		action = desc->action;
> > +		if (action) {
> > +			int ret;
> > +			int status = 0;
> > +			int retval = 0;
> > +
> > +			do {
> > +				ret = action->handler(irq, action->dev_id);
> > +				if (ret == IRQ_HANDLED)
> > +					status |= action->flags;
> > +				retval |= ret;
> > +				action = action->next;
> > +			} while (action);
> > +
> > +			if (status & IRQF_SAMPLE_RANDOM)
> > +				add_interrupt_randomness(irq);
> > +
> > +			if (retval != IRQ_HANDLED)
> > +				printk(KERN_ERR "ISR for TWL4030 power module"
> > +					" irq %d can't handle interrupt\n",
> > +					irq);
> > +		} else {
> > +			local_irq_disable();
> > +			twl4030_pwrirq_mask |= 1 << (irq - IH_TWL4030_PWRBASE);
> > +			local_irq_enable();
> > +			twl4030_i2c_write_u8(TWL4030_MODULE_INT,
> > +						twl4030_pwrirq_mask, PWR_IMR1);
> > +		}
> > +	}
> > +}
> > +
> > +static void do_twl4030_pwrirq(unsigned int irq, irq_desc_t *desc)
> > +{
> > +	const unsigned int cpu = smp_processor_id();
> > +
> > +	desc->status |= IRQ_LEVEL;
> > +
> > +	desc->chip->ack(irq);
> > +
> > +	if (!desc->depth) {
> > +		int ret;
> > +		int module_irq;
> > +		u8 pwr_isr;
> > +
> > +		kstat_cpu(cpu).irqs[irq]++;
> > +
> > +		local_irq_enable();
> > +		ret = twl4030_i2c_read_u8(TWL4030_MODULE_INT, &pwr_isr,
> > +						PWR_ISR1);
> > +		if (ret) {
> > +			printk(KERN_WARNING
> > +				"I2C error %d while reading TWL4030"
> > +				"INT PWR_ISR1 register\n", ret);
> > +			return;
> > +		}
> > +
> > +		for (module_irq = IH_TWL4030_PWRBASE; pwr_isr != 0;
> > +			module_irq++, pwr_isr >>= 1) {
> > +			if (pwr_isr & 1)
> > +				irq_desc_t *d = irq_desc + module_irq;
> > +		}
> > +
> > +		local_irq_disable();
> > +		desc->chip->unmask(irq);
> > +	}
> > +}
> > +
> > +static int twl4030_pwrirq_thread(void *data)
> > +{
> > +	current->flags |= PF_NOFREEZE;
> > +
> > +	while (!kthread_should_stop()) {
> > +		u8 local_unmask;
> > +
> > +		local_irq_disable();
> > +		local_unmask = twl4030_pwrirq_pending_unmask;
> > +		twl4030_pwrirq_pending_unmask = 0;
> > +		local_irq_enable();
> > +
> > +		twl4030_pwrirq_mask &= ~local_unmask;
> > +
> > +		twl4030_i2c_write_u8(TWL4030_MODULE_INT, twl4030_pwrirq_mask,
> > +					PWR_IMR1);
> > +
> > +		local_irq_disable();
> > +		if (!twl4030_pwrirq_pending_unmask)
> > +			set_current_state(TASK_INTERRUPTIBLE);
> > +		local_irq_enable();
> > +
> > +		schedule();
> > +	}
> > +	set_current_state(TASK_RUNNING);
> > +	return 0;
> > +}
> > +
> > +static int __init twl4030_pwrirq_init(void)
> > +{
> > +	int i, err;
> > +
> > +	twl4030_pwrirq_mask = 0xff;
> > +	twl4030_pwrirq_pending_unmask = 0;
> > +
> > +	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT, twl4030_pwrirq_mask,
> > +					PWR_IMR1);
> > +	if (err)
> > +		return err;
> > +
> > +	/* Enable clear on read */
> > +
> > +	err = twl4030_i2c_write_u8(TWL4030_MODULE_INT, PWR_SIH_CTRL_COR,
> > +					PWR_SIH_CTRL);
> > +	if (err)
> > +		return err;
> > +
> > +	twl4030_pwrirq_unmask_thread = kthread_create(twl4030_pwrirq_thread,
> > +		NULL, "twl4030 pwrirq");
> > +	if (!twl4030_pwrirq_unmask_thread) {
> > +		printk(KERN_ERR
> > +			"%s: could not create twl4030 pwrirq unmask thread!\n",
> > +				__func__);
> > +		return -ENOMEM;
> > +	}
> > +
> > +	for (i = IH_TWL4030_PWRBASE; i < IH_TWL4030_PWRBASE_END; i++) {
> > +		set_irq_chip(i, &twl4030_pwrirq_chip);
> > +		set_irq_handler(i, do_twl4030_pwrmodule_irq);
> > +		set_irq_flags(i, IRQF_VALID);
> > +	}
> > +
> > +	set_irq_chained_handler(TWL4030_MODIRQ_PWR, do_twl4030_pwrirq);
> > +
> > +	return 0;
> > +}
> > +
> > +static void __exit twl4030_pwrirq_exit(void)
> > +{
> > +
> > +	int i;
> > +
> > +	set_irq_handler(TWL4030_MODIRQ_PWR, NULL);
> > +	set_irq_flags(TWL4030_MODIRQ_PWR, 0);
> > +
> > +	for (i = IH_TWL4030_PWRBASE; i < IH_TWL4030_PWRBASE_END; i++) {
> > +		set_irq_handler(i, NULL);
> > +		set_irq_flags(i, 0);
> > +	}
> > +
> > +	if (twl4030_pwrirq_unmask_thread) {
> > +		kthread_stop(twl4030_pwrirq_unmask_thread);
> > +		twl4030_pwrirq_unmask_thread = NULL;
> > +	}
> > +}
> > +
> > +subsys_initcall(twl4030_pwrirq_init);
> > +module_exit(twl4030_pwrirq_exit);
> > diff --git a/include/asm-arm/arch-omap/board-3430sdp.h b/include/asm-arm/arch-omap/board-3430sdp.h
> > index 06379cf..87f47e5 100644
> > --- a/include/asm-arm/arch-omap/board-3430sdp.h
> > +++ b/include/asm-arm/arch-omap/board-3430sdp.h
> > @@ -75,14 +75,17 @@ extern void sdp_mmc_init(void);
> >  #define	IH_TWL4030_BASE		IH_BOARD_BASE
> >  #define	IH_TWL4030_END		(IH_TWL4030_BASE+8)
> >  
> > +#define IH_TWL4030_PWRBASE     (IH_TWL4030_END)
> > +#define IH_TWL4030_PWRBASE_END (IH_TWL4030_PWRBASE+8)
> > +
> >  #ifdef CONFIG_TWL4030_GPIO
> >  
> >  /* TWL4030 GPIO Interrupts */
> > -#define IH_TWL4030_GPIO_BASE	(IH_TWL4030_END)
> > -#define IH_TWL4030_GPIO_END	(IH_TWL4030_BASE+18)
> > +#define IH_TWL4030_GPIO_BASE	(IH_TWL4030_PWRBASE_END)
> > +#define IH_TWL4030_GPIO_END	(IH_TWL4030_GPIO_BASE+18)
> >  #define NR_IRQS			(IH_TWL4030_GPIO_END)
> >  #else
> > -#define NR_IRQS			(IH_TWL4030_END)
> > +#define NR_IRQS			(IH_TWL4030_PWRBASE_END)
> >  #endif /* CONFIG_I2C_TWL4030_GPIO */
> >  #endif /* End of support for TWL4030 */
> >  #endif /*  __ASM_ARCH_OMAP_3430SDP_H */
> > -- 
> > 1.5.5.rc2.25.g5fbd
> > 
> > 
> > 
> > -- 
> > 	- Balbi
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-omap" 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] 8+ messages in thread

end of thread, other threads:[~2008-04-04 10:09 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-03 13:44 [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support Felipe Balbi
2008-04-03 13:44 ` [PATCH 2/3] I2C: TWL4030: Kconfig and Makefile changes Felipe Balbi
2008-04-03 13:44   ` [PATCH 3/3] I2C: TWL4030: Adapt existing drivers to power IRQ Felipe Balbi
2008-04-03 13:47 ` [PATCH 1/3] I2C: TWL4030: Add power button and power IRQ support Felipe Balbi
2008-04-03 13:57   ` Peter 'p2' De Schrijver
2008-04-03 14:04     ` Felipe Balbi
2008-04-04  9:44       ` Tony Lindgren
2008-04-04 10:09         ` Tony Lindgren

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox