Skip to contentSkip to conversation

move retu to threaded IRQ

PATCH In review Felipe Balbi 2 participants 23 messages Jan 3, 2011 – Jan 7, 2011

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

cover move retu to threaded IRQ

Hi Tony,

here are a few more patches to retu. It converts it (hopefully successfuly) to threaded IRQ and adds an IRQ chip to retu.c core driver.

Anyone with an N810 available, please give it a shot. Patches are also available for pulling from [1]

[1] git://gitorious.org/usb/usb.git cbus

Felipe Balbi (10):
cbus: retu: give it a context structure
cbus: retu: get rid of retu-user.c
cbus: retu: move module_* close to the matching symbol
cbus: retu: cleanup error path
cbus: retu: move to threaded IRQ and GENIRQ
cbus: retu: headset: convert to threaded_irq
cbus: retu-pwrbutton: convert to threaded irq
cbus: retu-rtc: move to threaded irq
cbus: retu-rtc: drop the reset_occurred flag
cbus: Makefile: re-enable retu-wdt

 drivers/cbus/Kconfig          |    7 -
 drivers/cbus/Makefile         |    4 +-
 drivers/cbus/retu-headset.c   |   22 ++-
 drivers/cbus/retu-pwrbutton.c |   37 +---
 drivers/cbus/retu-rtc.c       |  130 ++-----------
 drivers/cbus/retu-user.c      |  424 -----------------------------------------
 drivers/cbus/retu.c           |  388 ++++++++++++++++++--------------------
 drivers/cbus/retu.h           |   12 --
 8 files changed, 223 insertions(+), 801 deletions(-)
 delete mode 100644 drivers/cbus/retu-user.c
Signature · 1 line
1.7.3.4.598.g85356
#1 lore raw

PATCH 1/10 cbus: retu: give it a context structure

This is pretty much a cleanup patch just adding a context structure for Retu, to avoid all the globals it had.

Note that this breaks retu-user.c due to moving the lock around, but that retu-user.c has to go anyway as it's completely non-standard way of accessing Retu children.

---
 drivers/cbus/retu.c |  126 ++++++++++++++++++++++++++++++++++-----------------
 drivers/cbus/retu.h |    2 -
 2 files changed, 85 insertions(+), 43 deletions(-)
drivers/cbus/retu.c +85 -41
index a2977c9..6e130bf 100644
@@ -26,6 +26,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 
+#include <linux/slab.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/device.h>
@@ -49,11 +50,18 @@
 #define RETU_ID			0x01
 #define PFX			"retu: "
 
-static int retu_initialized;
-static int retu_is_vilma;
+struct retu {
+	/* Device lock */
+	spinlock_t		lock;
+	struct tasklet_struct	tasklet;
+	struct device		*dev;
 
-static struct tasklet_struct retu_tasklet;
-spinlock_t retu_lock = SPIN_LOCK_UNLOCKED;
+	int			irq;
+
+	bool			is_vilma;
+};
+
+static struct retu *the_retu;
 
 struct retu_irq_handler_desc {
 	int (*func)(unsigned long);
@@ -65,7 +73,7 @@ static struct retu_irq_handler_desc retu_irq_handlers[MAX_RETU_IRQ_HANDLERS];
 
 int retu_get_status(void)
 {
-	return retu_initialized;
+	return the_retu ? 1 : 0;
 }
 EXPORT_SYMBOL(retu_get_status);
 
@@ -77,7 +85,7 @@ EXPORT_SYMBOL(retu_get_status);
  */
 int retu_read_reg(unsigned reg)
 {
-	BUG_ON(!retu_initialized);
+	BUG_ON(!the_retu);
 	return cbus_read_reg(RETU_ID, reg);
 }
 EXPORT_SYMBOL(retu_read_reg);
@@ -91,22 +99,23 @@ EXPORT_SYMBOL(retu_read_reg);
  */
 void retu_write_reg(unsigned reg, u16 val)
 {
-	BUG_ON(!retu_initialized);
+	BUG_ON(!the_retu);
 	cbus_write_reg(RETU_ID, reg, val);
 }
 EXPORT_SYMBOL(retu_write_reg);
 
 void retu_set_clear_reg_bits(unsigned reg, u16 set, u16 clear)
 {
-	unsigned long flags;
-	u16 w;
+	struct retu		*retu = the_retu;
+	unsigned long		flags;
+	u16			w;
 
-	spin_lock_irqsave(&retu_lock, flags);
+	spin_lock_irqsave(&retu->lock, flags);
 	w = retu_read_reg(reg);
 	w &= ~clear;
 	w |= set;
 	retu_write_reg(reg, w);
-	spin_unlock_irqrestore(&retu_lock, flags);
+	spin_unlock_irqrestore(&retu->lock, flags);
 }
 EXPORT_SYMBOL_GPL(retu_set_clear_reg_bits);
 
@@ -114,15 +123,19 @@ EXPORT_SYMBOL_GPL(retu_set_clear_reg_bits);
 
 int retu_read_adc(int channel)
 {
-	unsigned long flags;
-	int res;
+	struct retu		*retu = the_retu;
+	unsigned long		flags;
+	int			res;
+
+	if (!retu)
+		return -ENODEV;
 
 	if (channel < 0 || channel > ADC_MAX_CHAN_NUMBER)
 		return -EINVAL;
 
-	spin_lock_irqsave(&retu_lock, flags);
+	spin_lock_irqsave(&retu->lock, flags);
 
-	if ((channel == 8) && retu_is_vilma) {
+	if ((channel == 8) && retu->is_vilma) {
 		int scr = retu_read_reg(RETU_REG_ADCSCR);
 		int ch = (retu_read_reg(RETU_REG_ADCR) >> 10) & 0xf;
 		if (((scr & 0xff) != 0) && (ch != 8))
@@ -133,11 +146,11 @@ int retu_read_adc(int channel)
 	retu_write_reg(RETU_REG_ADCR, channel << 10);
 	res = retu_read_reg(RETU_REG_ADCR) & 0x3ff;
 
-	if (retu_is_vilma)
+	if (retu->is_vilma)
 		retu_write_reg(RETU_REG_ADCR, (1 << 13));
 
 	/* Unlock retu */
-	spin_unlock_irqrestore(&retu_lock, flags);
+	spin_unlock_irqrestore(&retu->lock, flags);
 
 	return res;
 }
@@ -164,15 +177,16 @@ static u16 retu_disable_bogus_irqs(u16 mask)
  */
 void retu_disable_irq(int id)
 {
-	unsigned long flags;
-	u16 mask;
+	struct retu		*retu = the_retu;
+	unsigned long		flags;
+	u16			mask;
 
-	spin_lock_irqsave(&retu_lock, flags);
+	spin_lock_irqsave(&retu->lock, flags);
 	mask = retu_read_reg(RETU_REG_IMR);
 	mask |= 1 << id;
 	mask = retu_disable_bogus_irqs(mask);
 	retu_write_reg(RETU_REG_IMR, mask);
-	spin_unlock_irqrestore(&retu_lock, flags);
+	spin_unlock_irqrestore(&retu->lock, flags);
 }
 EXPORT_SYMBOL(retu_disable_irq);
 
@@ -181,19 +195,21 @@ EXPORT_SYMBOL(retu_disable_irq);
  */
 void retu_enable_irq(int id)
 {
-	unsigned long flags;
-	u16 mask;
+	struct retu		*retu = the_retu;
+	unsigned long		flags;
+	u16			mask;
 
 	if (id == 3) {
 		printk("Enabling Retu IRQ %d\n", id);
 		dump_stack();
 	}
-	spin_lock_irqsave(&retu_lock, flags);
+
+	spin_lock_irqsave(&retu->lock, flags);
 	mask = retu_read_reg(RETU_REG_IMR);
 	mask &= ~(1 << id);
 	mask = retu_disable_bogus_irqs(mask);
 	retu_write_reg(RETU_REG_IMR, mask);
-	spin_unlock_irqrestore(&retu_lock, flags);
+	spin_unlock_irqrestore(&retu->lock, flags);
 }
 EXPORT_SYMBOL(retu_enable_irq);
 
@@ -209,9 +225,12 @@ EXPORT_SYMBOL(retu_ack_irq);
 /*
  * RETU interrupt handler. Only schedules the tasklet.
  */
-static irqreturn_t retu_irq_handler(int irq, void *dev_id)
+static irqreturn_t retu_irq_handler(int irq, void *_retu)
 {
-	tasklet_schedule(&retu_tasklet);
+	struct retu		*retu = _retu;
+
+	tasklet_schedule(&retu->tasklet);
+
 	return IRQ_HANDLED;
 }
 
@@ -259,9 +278,10 @@ static void retu_tasklet_handler(unsigned long data)
  */
 int retu_request_irq(int id, void *irq_handler, unsigned long arg, char *name)
 {
-	struct retu_irq_handler_desc *hnd;
+	struct retu			*retu = the_retu;
+	struct retu_irq_handler_desc	*hnd;
 
-	if (!retu_initialized)
+	if (!retu)
 		return -ENODEV;
 
 	if (irq_handler == NULL || id >= MAX_RETU_IRQ_HANDLERS ||
@@ -396,30 +416,46 @@ static int retu_allocate_children(struct device *parent)
  */
 static int __init retu_probe(struct platform_device *pdev)
 {
-	int rev, ret;
-	int irq;
+	struct retu	*retu;
+	int		rev;
+	int		ret;
+	int		irq;
+
+	retu = kzalloc(sizeof(*retu), GFP_KERNEL);
+	if (!retu) {
+		dev_err(&pdev->dev, "not enough memory\n");
+		return -ENOMEM;
+	}
+
+	platform_set_drvdata(pdev, retu);
+	the_retu = retu;
 
 	/* Prepare tasklet */
-	tasklet_init(&retu_tasklet, retu_tasklet_handler, 0);
+	tasklet_init(&retu->tasklet, retu_tasklet_handler, 0);
+	spin_lock_init(&retu->lock);
 
 	irq = platform_get_irq(pdev, 0);
 
-	retu_initialized = 1;
+	retu->irq = irq;
 
 	rev = retu_read_reg(RETU_REG_ASICR) & 0xff;
 	if (rev & (1 << 7))
-		retu_is_vilma = 1;
+		retu->is_vilma = true;
 
-	dev_info(&pdev->dev, "%s v%d.%d found\n", retu_is_vilma ? "Vilma" : "Retu",
-	       (rev >> 4) & 0x07, rev & 0x0f);
+	dev_info(&pdev->dev, "%s v%d.%d found\n",
+			retu->is_vilma ? "Vilma" : "Retu",
+			(rev >> 4) & 0x07, rev & 0x0f);
 
 	/* Mask all RETU interrupts */
 	retu_write_reg(RETU_REG_IMR, 0xffff);
 
 	ret = request_irq(irq, retu_irq_handler, 0,
-			  "retu", 0);
+			  "retu", retu);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Unable to register IRQ handler\n");
+		tasklet_kill(&retu->tasklet);
+		kfree(retu);
+		the_retu = NULL;
 		return ret;
 	}
 
@@ -432,7 +468,10 @@ static int __init retu_probe(struct platform_device *pdev)
 	/* Initialize user-space interface */
 	if (retu_user_init() < 0) {
 		dev_err(&pdev->dev, "Unable to initialize driver\n");
+		tasklet_kill(&retu->tasklet);
 		free_irq(irq, 0);
+		kfree(retu);
+		the_retu = NULL;
 		return ret;
 	}
 #endif
@@ -445,7 +484,9 @@ static int __init retu_probe(struct platform_device *pdev)
 #endif
 		retu_write_reg(RETU_REG_IMR, 0xffff);
 		free_irq(irq, 0);
-		tasklet_kill(&retu_tasklet);
+		tasklet_kill(&retu->tasklet);
+		kfree(retu);
+		the_retu = NULL;
 		return ret;
 	}
 
@@ -454,7 +495,8 @@ static int __init retu_probe(struct platform_device *pdev)
 
 static int __exit retu_remove(struct platform_device *pdev)
 {
-	int irq;
+	struct retu		*retu = platform_get_drvdata(pdev);
+	int			irq;
 
 	irq = platform_get_irq(pdev, 0);
 
@@ -463,8 +505,10 @@ static int __exit retu_remove(struct platform_device *pdev)
 #endif
 	/* Mask all RETU interrupts */
 	retu_write_reg(RETU_REG_IMR, 0xffff);
-	free_irq(irq, 0);
-	tasklet_kill(&retu_tasklet);
+	free_irq(irq, retu);
+	tasklet_kill(&retu->tasklet);
+	kfree(retu);
+	the_retu = NULL;
 
 	return 0;
 }
drivers/cbus/retu.h +0 -2
index cf3cf20..1cc486e 100644
@@ -73,6 +73,4 @@ int retu_user_init(void);
 void retu_user_cleanup(void);
 #endif
 
-extern spinlock_t retu_lock;
-
 #endif /* __DRIVERS_CBUS_RETU_H */
Signature · 1 line
1.7.3.4.598.g85356
maintainer
#2 lore raw

Re: [RFT/PATCH 01/10] cbus: retu: give it a context structure

Quoted 8 lines · Felipe Balbi

This is pretty much a cleanup patch just adding a context structure for Retu, to avoid all the globals it had.

Note that this breaks retu-user.c due to moving the lock around, but that retu-user.c has to go anyway as it's completely non-standard way of accessing Retu children.

FYI, this one alone fails to compile with:

drivers/cbus/retu-user.c: In function 'retu_user_write_with_mask':
drivers/cbus/retu-user.c:208: error: 'retu_lock' undeclared (first use in this function) drivers/cbus/retu-user.c:208: error: (Each undeclared identifier is reported only once drivers/cbus/retu-user.c:208: error: for each function it appears in.)

Regards,

Tony

#3 lore raw

Re: [RFT/PATCH 01/10] cbus: retu: give it a context structure

Quoted 11 lines · Tony Lindgren
Quoted 8 lines · Felipe Balbi

This is pretty much a cleanup patch just adding a context structure for Retu, to avoid all the globals it had.

Note that this breaks retu-user.c due to moving the lock around, but that retu-user.c has to go anyway as it's completely non-standard way of accessing Retu children.

FYI, this one alone fails to compile with:

Yeah, there's a note on commit log about it. Anyway, I don't know what I had in mind, I'll drop retu-user.c before this patch and there won't be problems.

Signature · 1 line
balbi
#4 lore raw

PATCH 2/10 cbus: retu: get rid of retu-user.c

In reply to Felipe Balbi

Drop that non-standard of accessing Retu
as it's bypassing all the correct layers.

---
 drivers/cbus/Kconfig     |    7 -
 drivers/cbus/Makefile    |    1 -
 drivers/cbus/retu-user.c |  424 ----------------------------------------------
 drivers/cbus/retu.c      |   22 ---
 drivers/cbus/retu.h      |    5 -
 5 files changed, 0 insertions(+), 459 deletions(-)
 delete mode 100644 drivers/cbus/retu-user.c
drivers/cbus/Kconfig +0 -7
index c6b39fb..9a827a2 100644
@@ -49,13 +49,6 @@ config CBUS_RETU
 
 	  If you want Retu support, you should say Y here.
 
-config CBUS_RETU_USER
-	depends on CBUS_RETU
-	bool "Support for Retu user space functions"
-	---help---
-	  If you want support for Retu's user space read/write etc. functions,
-	  you should say Y here.
-
 config CBUS_RETU_POWERBUTTON
 	depends on CBUS_RETU
 	bool "Support for Retu power button"
drivers/cbus/Makefile +0 -1
index 347c2a4..0ad112f 100644
@@ -10,5 +10,4 @@ obj-$(CONFIG_CBUS_RETU_POWERBUTTON) += retu-pwrbutton.o
 obj-$(CONFIG_CBUS_RETU_RTC)	+= retu-rtc.o
 obj-$(CONFIG_CBUS_RETU_WDT)	+= retu-wdt.o
 obj-$(CONFIG_CBUS_TAHVO_USER)	+= tahvo-user.o
-obj-$(CONFIG_CBUS_RETU_USER)	+= retu-user.o
 obj-$(CONFIG_CBUS_RETU_HEADSET)	+= retu-headset.o
drivers/cbus/retu-user.c deleted +0 -424

424 lines not on this page · raw message

drivers/cbus/retu.c +0 -22
index 6e130bf..39d4fa4 100644
@@ -396,10 +396,6 @@ static int retu_allocate_children(struct device *parent)
 	if (!child)
 		return -ENOMEM;
 
-	child = retu_allocate_child("retu-user", parent);
-	if (!child)
-		return -ENOMEM;
-
 	child = retu_allocate_child("retu-wdt", parent);
 	if (!child)
 		return -ENOMEM;
@@ -464,24 +460,9 @@ static int __init retu_probe(struct platform_device *pdev)
 	/* Register power off function */
 	pm_power_off = retu_power_off;
 
-#ifdef CONFIG_CBUS_RETU_USER
-	/* Initialize user-space interface */
-	if (retu_user_init() < 0) {
-		dev_err(&pdev->dev, "Unable to initialize driver\n");
-		tasklet_kill(&retu->tasklet);
-		free_irq(irq, 0);
-		kfree(retu);
-		the_retu = NULL;
-		return ret;
-	}
-#endif
-
 	ret = retu_allocate_children(&pdev->dev);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Unable to allocate Retu children\n");
-#ifdef CONFIG_CBUS_RETU_USER
-		retu_user_cleanup();
-#endif
 		retu_write_reg(RETU_REG_IMR, 0xffff);
 		free_irq(irq, 0);
 		tasklet_kill(&retu->tasklet);
@@ -500,9 +481,6 @@ static int __exit retu_remove(struct platform_device *pdev)
 
 	irq = platform_get_irq(pdev, 0);
 
-#ifdef CONFIG_CBUS_RETU_USER
-	retu_user_cleanup();
-#endif
 	/* Mask all RETU interrupts */
 	retu_write_reg(RETU_REG_IMR, 0xffff);
 	free_irq(irq, retu);
drivers/cbus/retu.h +0 -5
index 1cc486e..ada7f2e 100644
@@ -68,9 +68,4 @@ void retu_enable_irq(int id);
 void retu_disable_irq(int id);
 void retu_ack_irq(int id);
 
-#ifdef CONFIG_CBUS_RETU_USER
-int retu_user_init(void);
-void retu_user_cleanup(void);
-#endif
-
 #endif /* __DRIVERS_CBUS_RETU_H */
Signature · 1 line
1.7.3.4.598.g85356
#5 lore raw

PATCH 3/10 cbus: retu: move module_* close to the matching symbol

In reply to Felipe Balbi

Just to make checkpatch.pl a bit happier, move
subsys_initcall() and module_exit() closer to
the init and exit functions of the driver.

---
 drivers/cbus/retu.c |   11 +----------
 1 files changed, 1 insertions(+), 10 deletions(-)
drivers/cbus/retu.c +1 -10
index 39d4fa4..0053d43 100644
@@ -498,25 +498,16 @@ static struct platform_driver retu_driver = {
 	},
 };
 
-/**
- * retu_init - initialise Retu driver
- *
- * Initialise the Retu driver and return 0 if everything worked ok
- */
 static int __init retu_init(void)
 {
 	return platform_driver_probe(&retu_driver, retu_probe);
 }
+subsys_initcall(retu_init);
 
-/*
- * Cleanup
- */
 static void __exit retu_exit(void)
 {
 	platform_driver_unregister(&retu_driver);
 }
-
-subsys_initcall(retu_init);
 module_exit(retu_exit);
 
 MODULE_DESCRIPTION("Retu ASIC control");
Signature · 1 line
1.7.3.4.598.g85356
#6 lore raw

PATCH 4/10 cbus: retu: cleanup error path

In reply to Felipe Balbi

Trivial cleanup patch shuffling error path
around.

---
 drivers/cbus/retu.c |   29 +++++++++++++++++------------
 1 files changed, 17 insertions(+), 12 deletions(-)
drivers/cbus/retu.c +17 -12
index 0053d43..7e67e1a 100644
@@ -413,14 +413,15 @@ static int retu_allocate_children(struct device *parent)
 static int __init retu_probe(struct platform_device *pdev)
 {
 	struct retu	*retu;
+
+	int		ret = -ENOMEM;
 	int		rev;
-	int		ret;
 	int		irq;
 
 	retu = kzalloc(sizeof(*retu), GFP_KERNEL);
 	if (!retu) {
 		dev_err(&pdev->dev, "not enough memory\n");
-		return -ENOMEM;
+		goto err0;
 	}
 
 	platform_set_drvdata(pdev, retu);
@@ -449,10 +450,7 @@ static int __init retu_probe(struct platform_device *pdev)
 			  "retu", retu);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Unable to register IRQ handler\n");
-		tasklet_kill(&retu->tasklet);
-		kfree(retu);
-		the_retu = NULL;
-		return ret;
+		goto err1;
 	}
 
 	set_irq_wake(irq, 1);
@@ -463,15 +461,22 @@ static int __init retu_probe(struct platform_device *pdev)
 	ret = retu_allocate_children(&pdev->dev);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Unable to allocate Retu children\n");
-		retu_write_reg(RETU_REG_IMR, 0xffff);
-		free_irq(irq, 0);
-		tasklet_kill(&retu->tasklet);
-		kfree(retu);
-		the_retu = NULL;
-		return ret;
+		goto err2;
 	}
 
 	return 0;
+
+err2:
+	retu_write_reg(RETU_REG_IMR, 0xffff);
+	free_irq(irq, retu);
+
+err1:
+	tasklet_kill(&retu->tasklet);
+	kfree(retu);
+	the_retu = NULL;
+
+err0:
+	return ret;
 }
 
 static int __exit retu_remove(struct platform_device *pdev)
Signature · 1 line
1.7.3.4.598.g85356
#7 lore raw

PATCH 5/10 cbus: retu: move to threaded IRQ and GENIRQ

In reply to Felipe Balbi

Start moving retu to threaded IRQ and while
at that also give retu an irq_chip so children
can use generic request_threaded_irq() calls.

---
 drivers/cbus/Makefile |   10 +-
 drivers/cbus/retu.c   |  264 +++++++++++++++++++++----------------------------
 drivers/cbus/retu.h   |    5 -
 3 files changed, 117 insertions(+), 162 deletions(-)
drivers/cbus/Makefile +6 -4
index 0ad112f..3375b82 100644
@@ -6,8 +6,10 @@ obj-$(CONFIG_CBUS)		+= cbus.o
 obj-$(CONFIG_CBUS_TAHVO)	+= tahvo.o
 obj-$(CONFIG_CBUS_RETU)		+= retu.o
 obj-$(CONFIG_CBUS_TAHVO_USB)	+= tahvo-usb.o
-obj-$(CONFIG_CBUS_RETU_POWERBUTTON) += retu-pwrbutton.o
-obj-$(CONFIG_CBUS_RETU_RTC)	+= retu-rtc.o
-obj-$(CONFIG_CBUS_RETU_WDT)	+= retu-wdt.o
 obj-$(CONFIG_CBUS_TAHVO_USER)	+= tahvo-user.o
-obj-$(CONFIG_CBUS_RETU_HEADSET)	+= retu-headset.o
+
+## Disable Retu children until converted to threaded IRQ
+#obj-$(CONFIG_CBUS_RETU_POWERBUTTON) += retu-pwrbutton.o
+#obj-$(CONFIG_CBUS_RETU_RTC)	+= retu-rtc.o
+#obj-$(CONFIG_CBUS_RETU_WDT)	+= retu-wdt.o
+#obj-$(CONFIG_CBUS_RETU_HEADSET)	+= retu-headset.o
drivers/cbus/retu.c +111 -153

353 lines not on this page · raw message

drivers/cbus/retu.h +0 -5
index ada7f2e..1b05f3e 100644
@@ -62,10 +62,5 @@ int retu_read_reg(unsigned reg);
 void retu_write_reg(unsigned reg, u16 val);
 void retu_set_clear_reg_bits(unsigned reg, u16 set, u16 clear);
 int retu_read_adc(int channel);
-int retu_request_irq(int id, void *irq_handler, unsigned long arg, char *name);
-void retu_free_irq(int id);
-void retu_enable_irq(int id);
-void retu_disable_irq(int id);
-void retu_ack_irq(int id);
 
 #endif /* __DRIVERS_CBUS_RETU_H */
Signature · 1 line
1.7.3.4.598.g85356
maintainer
#8 lore raw

Re: [RFT/PATCH 05/10] cbus: retu: move to threaded IRQ and GENIRQ

drivers/cbus/retu.c line 62

Quoted 11 lines · Felipe Balbi
drivers/cbus/retu.c +3 -1
@@ -53,23 +54,23 @@
 struct retu {
 	/* Device lock */
 	spinlock_t		lock;
-	struct tasklet_struct	tasklet;
+	struct mutex		irq_lock;
 	struct device		*dev;
 
+	int			irq_base;
+	int			nirqs;
 	int			irq;

This one oopses, looks like irq_base is not initialized?

Regards,

Tony

#9 lore raw

Re: [RFT/PATCH 05/10] cbus: retu: move to threaded IRQ and GENIRQ

Quoted 9 lines · Tony Lindgren
Quoted 8 lines · Felipe Balbi
drivers/cbus/retu.c +1 -1
@@ -53,23 +54,23 @@
 struct retu {
 	/* Device lock */
 	spinlock_t		lock;
-	struct tasklet_struct	tasklet;
+	struct mutex		irq_lock;
 	struct device		*dev;
 
Quoted 5 lines

drivers/cbus/retu.c line 62

Quoted 3 lines
drivers/cbus/retu.c +2 -0
+	int			irq_base;
+	int			nirqs;
 	int			irq;

This one oopses, looks like irq_base is not initialized?

Aaa, good catch. Sorry for that. Gotta add a platform_data for passing that around. Will do it on V2.

Signature · 1 line
balbi
#10 lore raw

Re: [RFT/PATCH 05/10] cbus: retu: move to threaded IRQ and GENIRQ

Hi,

Quoted 10 lines · Felipe Balbi
Quoted 9 lines · Tony Lindgren
Quoted 8 lines · Felipe Balbi
(quoted diff) +1 -1
@@ -53,23 +54,23 @@
 struct retu {
 	/* Device lock */
 	spinlock_t		lock;
-	struct tasklet_struct	tasklet;
+	struct mutex		irq_lock;
 	struct device		*dev;
 
Quoted 8 lines
Quoted 5 lines

Review line 62

Quoted 3 lines
(quoted diff) +2 -0
+	int			irq_base;
+	int			nirqs;
 	int			irq;

This one oopses, looks like irq_base is not initialized?

Aaa, good catch. Sorry for that. Gotta add a platform_data for passing that around. Will do it on V2.

Looking into <plat/irqs.h> it seems like there will be quite some ifdeffery added to have support for Retu irq_base (and later Tahvo, menelaus, ISP, etc etc); so, would you be willing to accept an atomic counter to keep track of that ?

Something like the following:

static atomic_t omap_irq_base;

int omap_irq_get_base(void)

{
	return atomic_read(&omap_irq_base);
}

void omap_irq_set_base(int base)

{
	atomic_set(&omap_irq_base, base);
}

void omap_irq_add(int nirqs)

{
	atomic_add(nirqs, &omap_irq_base);
}

void omap_irq_sub(int nirqs)

{
	atomic_sub(nirqs, &omap_irq_base);
}

static int __init omap_irq_init(void)

{
	atomic_set(&omap_irq_base, 0);

	return 0;
}

postcore_initcall(omap_irq_init);

Then, INTC will always be the first one to call omap_irq_add():

arch/arm/mach-omap2/irq.c +3 -0
index 85bf8ca..3d91a11 100644
@@ -14,6 +14,7 @@
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
+#include <plat/irqs.h>
 #include <mach/hardware.h>
 #include <asm/mach/irq.h>
 
@@ -224,6 +225,8 @@ void __init omap_init_irq(void)
                set_irq_handler(i, handle_level_irq);
                set_irq_flags(i, IRQF_VALID);
        }
+
+       omap_irq_add(nr_of_irqs);
 }
 
 #ifdef CONFIG_ARCH_OMAP3

and when adding e.g. twl4030, we could:

arch/arm/mach-omap2/board-3430sdp.c +12 -2
index 3b39ef1..3ae342b 100644
@@ -31,6 +31,7 @@
 #include <asm/mach/arch.h>
 #include <asm/mach/map.h>
 
+#include <plat/irqs.h>
 #include <plat/mcspi.h>
 #include <plat/board.h>
 #include <plat/usb.h>
@@ -571,8 +572,8 @@ static struct twl4030_codec_data sdp3430_codec = {
 };
 
 static struct twl4030_platform_data sdp3430_twldata = {
-       .irq_base       = TWL4030_IRQ_BASE,
-       .irq_end        = TWL4030_IRQ_END,
+       .irq_base       = -EINVAL,      /* fixed up later */
+       .irq_end        = -EINVAL,      /* fixed up later */
 
        /* platform_data for children goes here */
        .bci            = &sdp3430_bci_data,
@@ -593,6 +594,14 @@ static struct twl4030_platform_data sdp3430_twldata = {
        .vpll2          = &sdp3430_vpll2,
 };
 
+static void __init sdp3430_twl_init(void)
+{
+       int             irq_base = omap_irq_get_base();
+
+       sdp3430_twldata.irq_base = irq_base;
+       sdp3430_twldata.irq_end = irq_base + TWL4030_BASE_NR_IRQS;
+}
+
 static struct i2c_board_info __initdata sdp3430_i2c_boardinfo[] = {
        {
                I2C_BOARD_INFO("twl4030", 0x48),
@@ -794,6 +803,7 @@ static struct omap_musb_board_data musb_board_data = {
 static void __init omap_3430sdp_init(void)
 {
        omap3_mux_init(board_mux, OMAP_PACKAGE_CBB);
+       sdp3430_twl_init();
        omap3430_i2c_init();
        platform_add_devices(sdp3430_devices, ARRAY_SIZE(sdp3430_devices));
        if (omap_rev() > OMAP3430_REV_ES1_0)

either that, or we add several ifdefs to <plat/irqs.h> and maintain that over time. What do you think ?

Signature · 1 line
balbi
#11 lore raw

Re: [RFT/PATCH 05/10] cbus: retu: move to threaded IRQ and GENIRQ

Quoted 4 lines · Felipe Balbi
arch/arm/mach-omap2/board-3430sdp.c +1 -0
@@ -593,6 +594,14 @@ static struct twl4030_platform_data sdp3430_twldata = {
       .vpll2          = &sdp3430_vpll2,
 };
+static void __init sdp3430_twl_init(void)

arch/arm/mach-omap2/board-3430sdp.c static struct twl4030_platform_data sdp3430_twldata = { · line 606

Quoted 10 lines
arch/arm/mach-omap2/board-3430sdp.c +7 -0
+{
+       int             irq_base = omap_irq_get_base();
+
+       sdp3430_twldata.irq_base = irq_base;
+       sdp3430_twldata.irq_end = irq_base + TWL4030_BASE_NR_IRQS;
+}
+
 static struct i2c_board_info __initdata sdp3430_i2c_boardinfo[] = {
       {
               I2C_BOARD_INFO("twl4030", 0x48),

this hunk should be:

@@ -593,6 +594,16 @@ static struct twl4030_platform_data sdp3430_twldata = {
        .vpll2          = &sdp3430_vpll2,

};

+static void __init sdp3430_twl_init(void)
+{
+ int irq_base = omap_irq_get_base();
+
+ sdp3430_twldata.irq_base = irq_base;
+ sdp3430_twldata.irq_end = irq_base + TWL4030_BASE_NR_IRQS;
+
+ omap_irq_add(TWL4030_BASE_NR_IRQS);
+}
+

 static struct i2c_board_info __initdata sdp3430_i2c_boardinfo[] = {
        {
                I2C_BOARD_INFO("twl4030", 0x48),

otherwise it won't work for other irq_chips

Signature · 1 line
balbi
maintainer
#12 lore raw

Re: [RFT/PATCH 05/10] cbus: retu: move to threaded IRQ and GENIRQ

Quoted 35 lines · Felipe Balbi
Quoted 4 lines · Felipe Balbi
arch/arm/mach-omap2/board-3430sdp.c +1 -0
@@ -593,6 +594,14 @@ static struct twl4030_platform_data sdp3430_twldata = {
      .vpll2          = &sdp3430_vpll2,
 };
+static void __init sdp3430_twl_init(void)

arch/arm/mach-omap2/board-3430sdp.c static struct twl4030_platform_data sdp3430_twldata = { · line 606

Quoted 10 lines
arch/arm/mach-omap2/board-3430sdp.c +7 -0
+{
+       int             irq_base = omap_irq_get_base();
+
+       sdp3430_twldata.irq_base = irq_base;
+       sdp3430_twldata.irq_end = irq_base + TWL4030_BASE_NR_IRQS;
+}
+
 static struct i2c_board_info __initdata sdp3430_i2c_boardinfo[] = {
      {
              I2C_BOARD_INFO("twl4030", 0x48),

this hunk should be:

arch/arm/mach-omap2/board-3430sdp.c +10 -0
@@ -593,6 +594,16 @@ static struct twl4030_platform_data sdp3430_twldata = {
        .vpll2          = &sdp3430_vpll2,
 };
+static void __init sdp3430_twl_init(void)
+{
+       int             irq_base = omap_irq_get_base();
+
+       sdp3430_twldata.irq_base = irq_base;
+       sdp3430_twldata.irq_end = irq_base + TWL4030_BASE_NR_IRQS;
+
+       omap_irq_add(TWL4030_BASE_NR_IRQS);
+}
+
 static struct i2c_board_info __initdata sdp3430_i2c_boardinfo[] = {
        {
                I2C_BOARD_INFO("twl4030", 0x48),
 
Quoted 1 line

otherwise it won't work for other irq_chips

I think there's been some patches related to this to get rid of NR_IRQS? Might be worth taking a look at those first as it's a generic solution.

Regards,

Tony

#13 lore raw

Re: [RFT/PATCH 05/10] cbus: retu: move to threaded IRQ and GENIRQ

Hi,

Quoted 3 lines · Tony Lindgren

I think there's been some patches related to this to get rid of NR_IRQS? Might be worth taking a look at those first as it's a generic solution.

Yeah, one way would be to use Sparse IRQ numbering scheme and define different bases for different IRQ chips. We could use for example, something like:

IRQ | Chip
=====================
0-299 | INTC

300-499	|	TWL4030
500-599	|	MENELAUS
600-799	|	RETU
800-999	|	TAHVO

and so on. But I'm not sure that's good enough (numbers are just from the top of my head, didn't really check how many IRQs each one have).

The only problem I see is with INTC, what happens if we give it an interval which ends up not being big enough for next OMAP versions ?

Signature · 1 line
balbi
maintainer
#14 lore raw

Re: [RFT/PATCH 05/10] cbus: retu: move to threaded IRQ and GENIRQ

Quoted 19 lines · Felipe Balbi

Hi,

Quoted 3 lines · Tony Lindgren

I think there's been some patches related to this to get rid of NR_IRQS? Might be worth taking a look at those first as it's a generic solution.

Yeah, one way would be to use Sparse IRQ numbering scheme and define different bases for different IRQ chips. We could use for example, something like:

IRQ | Chip
=====================
0-299 | INTC

300-499	|	TWL4030
500-599	|	MENELAUS
600-799	|	RETU
800-999	|	TAHVO
Quoted 5 lines

and so on. But I'm not sure that's good enough (numbers are just from the top of my head, didn't really check how many IRQs each one have).

The only problem I see is with INTC, what happens if we give it an interval which ends up not being big enough for next OMAP versions ?

I think that's the way to go, but we should not allocate that many irqs.. We can define the ranges like we already do in irqs.h based on what gets compiled in. There are few more blocks though:

INTC
GPIO
MPUIO
GIC
FPGA
RETU
TAHVO
MENELAUS
TWL4030

The numbers for INTC we know assuming new omaps will use GIC. The external chips rarely have more than few interrupts.

Regards,

Tony

#15 lore raw

Re: [RFT/PATCH 05/10] cbus: retu: move to threaded IRQ and GENIRQ

Quoted 23 lines · Tony Lindgren
Quoted 22 lines · Felipe Balbi

Hi,

Quoted 3 lines · Tony Lindgren

I think there's been some patches related to this to get rid of NR_IRQS? Might be worth taking a look at those first as it's a generic solution.

Yeah, one way would be to use Sparse IRQ numbering scheme and define different bases for different IRQ chips. We could use for example, something like:

IRQ | Chip
=====================
0-299 | INTC

300-499	|	TWL4030
500-599	|	MENELAUS
600-799	|	RETU
800-999	|	TAHVO

and so on. But I'm not sure that's good enough (numbers are just from the top of my head, didn't really check how many IRQs each one have).

Quoted 6 lines
Quoted 2 lines

The only problem I see is with INTC, what happens if we give it an interval which ends up not being big enough for next OMAP versions ?

I think that's the way to go, but we should not allocate that many irqs.. We can define the ranges like we already do in irqs.h based on what gets compiled in. There are few more blocks though:

The main point of using Sparse IRQ numbering is exactly avoiding pre-processor branches. Instead of defining ranges only when a device is compile, we can always keep the range allocated no matter if the device probes or not. So, I suggest dropping the ifdeffery on <plat/irqs.h> and move that to something like below:

arch/arm/plat-omap/include/plat/irqs.h +1 -22
index 65e20a6..c4fcd9d 100644
@@ -367,49 +367,28 @@
 
 /* External FPGA handles interrupts on Innovator boards */
 #define        OMAP_FPGA_IRQ_BASE      (OMAP_IRQ_END)
-#ifdef CONFIG_MACH_OMAP_INNOVATOR
 #define OMAP_FPGA_NR_IRQS      24
-#else
-#define OMAP_FPGA_NR_IRQS      0
-#endif
 #define OMAP_FPGA_IRQ_END      (OMAP_FPGA_IRQ_BASE + OMAP_FPGA_NR_IRQS)
 
 /* External TWL4030 can handle interrupts on 2430 and 34xx boards */
 #define        TWL4030_IRQ_BASE        (OMAP_FPGA_IRQ_END)
-#ifdef CONFIG_TWL4030_CORE
 #define        TWL4030_BASE_NR_IRQS    8
 #define        TWL4030_PWR_NR_IRQS     8
-#else
-#define        TWL4030_BASE_NR_IRQS    0
-#define        TWL4030_PWR_NR_IRQS     0
-#endif
 #define TWL4030_IRQ_END                (TWL4030_IRQ_BASE + TWL4030_BASE_NR_IRQS)
 #define TWL4030_PWR_IRQ_BASE   TWL4030_IRQ_END
 #define        TWL4030_PWR_IRQ_END     (TWL4030_PWR_IRQ_BASE + TWL4030_PWR_NR_IRQS)
 
 /* External TWL4030 gpio interrupts are optional */
 #define TWL4030_GPIO_IRQ_BASE  TWL4030_PWR_IRQ_END
-#ifdef CONFIG_GPIO_TWL4030
 #define TWL4030_GPIO_NR_IRQS   18
-#else
-#define        TWL4030_GPIO_NR_IRQS    0
-#endif
 #define TWL4030_GPIO_IRQ_END   (TWL4030_GPIO_IRQ_BASE + TWL4030_GPIO_NR_IRQS)
 
 #define        TWL6030_IRQ_BASE        (OMAP_FPGA_IRQ_END)
-#ifdef CONFIG_TWL4030_CORE
 #define        TWL6030_BASE_NR_IRQS    20
-#else
-#define        TWL6030_BASE_NR_IRQS    0
-#endif
 #define TWL6030_IRQ_END                (TWL6030_IRQ_BASE + TWL6030_BASE_NR_IRQS)
 
 /* Total number of interrupts depends on the enabled blocks above */
-#if (TWL4030_GPIO_IRQ_END > TWL6030_IRQ_END)
-#define TWL_IRQ_END            TWL4030_GPIO_IRQ_END
-#else
-#define TWL_IRQ_END            TWL6030_IRQ_END
-#endif
+#define TWL_IRQ_END            TWL4030_GPIO_IRQ_END
 
 #define NR_IRQS                        TWL_IRQ_END
 
Signature · 1 line
balbi
maintainer
#16 lore raw

Re: [RFT/PATCH 05/10] cbus: retu: move to threaded IRQ and GENIRQ

Quoted 6 lines · Felipe Balbi

The main point of using Sparse IRQ numbering is exactly avoiding pre-processor branches. Instead of defining ranges only when a device is compile, we can always keep the range allocated no matter if the device probes or not. So, I suggest dropping the ifdeffery on <plat/irqs.h> and move that to something like below:

This is fine as long as we we don't run out of allocated IRQs before switching over to sparse IRQ. The original reason for the ifdeffery was to keep NR_IRQS below 256 when possible as it optimizes the interrupt handling in that case. See NR_IRQS in arch/arm/include/asm/hardirq.h for more info.

Regards,

Tony

#17 lore raw

Re: [RFT/PATCH 05/10] cbus: retu: move to threaded IRQ and GENIRQ

Quoted 8 lines · Tony Lindgren
Quoted 6 lines · Felipe Balbi

The main point of using Sparse IRQ numbering is exactly avoiding pre-processor branches. Instead of defining ranges only when a device is compile, we can always keep the range allocated no matter if the device probes or not. So, I suggest dropping the ifdeffery on <plat/irqs.h> and move that to something like below:

Quoted 5 lines

This is fine as long as we we don't run out of allocated IRQs before switching over to sparse IRQ. The original reason for the ifdeffery was to keep NR_IRQS below 256 when possible as it optimizes the interrupt handling in that case. See NR_IRQS in arch/arm/include/asm/hardirq.h for more info.

I've sent patches (you're in Cc) enabling SPARSE_IRQ on OMAP. I boot tested on panda and overo and it was working fine.

Signature · 1 line
balbi
#18 lore raw

PATCH 6/10 cbus: retu: headset: convert to threaded_irq

In reply to Felipe Balbi

use the new irq_chip added to retu.c.

---
 drivers/cbus/Makefile       |    2 +-
 drivers/cbus/retu-headset.c |   22 ++++++++++++----------
 2 files changed, 13 insertions(+), 11 deletions(-)
drivers/cbus/Makefile +1 -1
index 3375b82..841bed5 100644
@@ -12,4 +12,4 @@ obj-$(CONFIG_CBUS_TAHVO_USER)	+= tahvo-user.o
 #obj-$(CONFIG_CBUS_RETU_POWERBUTTON) += retu-pwrbutton.o
 #obj-$(CONFIG_CBUS_RETU_RTC)	+= retu-rtc.o
 #obj-$(CONFIG_CBUS_RETU_WDT)	+= retu-wdt.o
-#obj-$(CONFIG_CBUS_RETU_HEADSET)	+= retu-headset.o
+obj-$(CONFIG_CBUS_RETU_HEADSET)	+= retu-headset.o
drivers/cbus/retu-headset.c +12 -10
index f5fb50c..2aa4d30 100644
@@ -22,6 +22,8 @@
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
 #include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/input.h>
@@ -84,7 +86,6 @@ static void retu_headset_det_enable(struct retu_headset *hs)
 	if (!hs->detection_enabled) {
 		hs->detection_enabled = 1;
 		retu_set_clear_reg_bits(RETU_REG_CC1, (1 << 10) | (1 << 8), 0);
-		retu_enable_irq(RETU_INT_HOOK);
 	}
 	mutex_unlock(&hs->mutex);
 }
@@ -96,7 +97,6 @@ static void retu_headset_det_disable(struct retu_headset *hs)
 	mutex_lock(&hs->mutex);
 	if (hs->detection_enabled) {
 		hs->detection_enabled = 0;
-		retu_disable_irq(RETU_INT_HOOK);
 		del_timer_sync(&hs->enable_timer);
 		del_timer_sync(&hs->detect_timer);
 		spin_lock_irqsave(&hs->lock, flags);
@@ -177,12 +177,11 @@ static DEVICE_ATTR(enable_det, S_IRUGO | S_IWUSR | S_IWGRP,
 		   retu_headset_enable_det_show,
 		   retu_headset_enable_det_store);
 
-static void retu_headset_hook_interrupt(unsigned long arg)
+static irqreturn_t retu_headset_hook_interrupt(int irq, void *_hs)
 {
-	struct retu_headset *hs = (struct retu_headset *) arg;
-	unsigned long flags;
+	struct retu_headset	*hs = _hs;
+	unsigned long		flags;
 
-	retu_ack_irq(RETU_INT_HOOK);
 	spin_lock_irqsave(&hs->lock, flags);
 	if (!hs->pressed) {
 		/* Headset button was just pressed down. */
@@ -192,6 +191,8 @@ static void retu_headset_hook_interrupt(unsigned long arg)
 	spin_unlock_irqrestore(&hs->lock, flags);
 	retu_set_clear_reg_bits(RETU_REG_CC1, 0, (1 << 10) | (1 << 8));
 	mod_timer(&hs->enable_timer, jiffies + msecs_to_jiffies(50));
+
+	return IRQ_HANDLED;
 }
 
 static void retu_headset_enable_timer(unsigned long arg)
@@ -257,13 +258,13 @@ static int __init retu_headset_probe(struct platform_device *pdev)
 	setup_timer(&hs->detect_timer, retu_headset_detect_timer,
 		    (unsigned long) hs);
 
-	r = retu_request_irq(RETU_INT_HOOK, retu_headset_hook_interrupt,
-			     (unsigned long) hs, "hookdet");
+	r = request_threaded_irq(RETU_INT_HOOK, NULL,
+			retu_headset_hook_interrupt, 0, "hookdet", hs);
 	if (r != 0) {
 		dev_err(&pdev->dev, "hookdet IRQ not available\n");
 		goto err6;
 	}
-	retu_disable_irq(RETU_INT_HOOK);
+
 	return 0;
 err6:
 	device_remove_file(&pdev->dev, &dev_attr_enable_det);
@@ -289,9 +290,10 @@ static int retu_headset_remove(struct platform_device *pdev)
 	device_remove_file(&pdev->dev, &dev_attr_enable_det);
 	retu_headset_disable(hs);
 	retu_headset_det_disable(hs);
-	retu_free_irq(RETU_INT_HOOK);
+	free_irq(RETU_INT_HOOK, hs);
 	input_unregister_device(hs->idev);
 	input_free_device(hs->idev);
+
 	return 0;
 }
 
Signature · 1 line
1.7.3.4.598.g85356
#19 lore raw

PATCH 7/10 cbus: retu-pwrbutton: convert to threaded irq

In reply to Felipe Balbi

Drop the timer function and move to threaded
irq infrastructure.

---
 drivers/cbus/Makefile         |    2 +-
 drivers/cbus/retu-pwrbutton.c |   37 +++++++++----------------------------
 2 files changed, 10 insertions(+), 29 deletions(-)
drivers/cbus/Makefile +1 -1
index 841bed5..23f82b4 100644
@@ -9,7 +9,7 @@ obj-$(CONFIG_CBUS_TAHVO_USB)	+= tahvo-usb.o
 obj-$(CONFIG_CBUS_TAHVO_USER)	+= tahvo-user.o
 
 ## Disable Retu children until converted to threaded IRQ
-#obj-$(CONFIG_CBUS_RETU_POWERBUTTON) += retu-pwrbutton.o
+obj-$(CONFIG_CBUS_RETU_POWERBUTTON) += retu-pwrbutton.o
 #obj-$(CONFIG_CBUS_RETU_RTC)	+= retu-rtc.o
 #obj-$(CONFIG_CBUS_RETU_WDT)	+= retu-wdt.o
 obj-$(CONFIG_CBUS_RETU_HEADSET)	+= retu-headset.o
drivers/cbus/retu-pwrbutton.c +9 -28
index 6b8dfa9..2a5ccb0 100644
@@ -30,9 +30,10 @@
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/input.h>
-#include <linux/timer.h>
 #include <linux/jiffies.h>
 #include <linux/bitops.h>
+#include <linux/irq.h>
+#include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 
@@ -46,15 +47,14 @@
 
 struct retu_pwrbutton {
 	struct input_dev	*idev;
-	struct timer_list	timer;
 
 	int			state;
 	int			irq;
 };
 
-static void retubutton_timer_func(unsigned long arg)
+static irqreturn_t retubutton_irq(int irq, void *_pwr)
 {
-	struct retu_pwrbutton *pwr = (struct retu_pwrbutton *) arg;
+	struct retu_pwrbutton *pwr = _pwr;
 	int state;
 
 	if (retu_read_reg(RETU_REG_STATUS) & RETU_STATUS_PWRONX)
@@ -67,24 +67,10 @@ static void retubutton_timer_func(unsigned long arg)
 		input_sync(pwr->idev);
 		pwr->state = state;
 	}
-}
-
-/**
- * Interrupt function is called whenever power button key is pressed
- * or released.
- */
-static void retubutton_irq(unsigned long arg)
-{
-	struct retu_pwrbutton *pwr = (struct retu_pwrbutton *) arg;
 
-	retu_ack_irq(RETU_INT_PWR);
-	mod_timer(&pwr->timer, jiffies + msecs_to_jiffies(PWRBTN_DELAY));
+	return IRQ_HANDLED;
 }
 
-/**
- * Init function.
- * Allocates interrupt for power button and registers itself to input layer.
- */
 static int __init retubutton_probe(struct platform_device *pdev)
 {
 	struct retu_pwrbutton		*pwr;
@@ -99,10 +85,9 @@ static int __init retubutton_probe(struct platform_device *pdev)
 
 	pwr->irq = RETU_INT_PWR;
 	platform_set_drvdata(pdev, pwr);
-	setup_timer(&pwr->timer, retubutton_timer_func, (unsigned long) pwr);
 
-	ret = retu_request_irq(pwr->irq, retubutton_irq, (unsigned long) pwr,
-			"PwrOnX");
+	ret = request_threaded_irq(pwr->irq, NULL, retubutton_irq, 0,
+			"retu-pwrbutton", pwr);
 	if (ret < 0) {
 		dev_err(&pdev->dev, "Cannot allocate irq\n");
 		goto err1;
@@ -131,7 +116,7 @@ err3:
 	input_free_device(pwr->idev);
 
 err2:
-	retu_free_irq(pwr->irq);
+	free_irq(pwr->irq, pwr);
 
 err1:
 	kfree(pwr);
@@ -140,15 +125,11 @@ err0:
 	return ret;
 }
 
-/**
- * Cleanup function which is called when driver is unloaded
- */
 static int __exit retubutton_remove(struct platform_device *pdev)
 {
 	struct retu_pwrbutton		*pwr = platform_get_drvdata(pdev);
 
-	retu_free_irq(pwr->irq);
-	del_timer_sync(&pwr->timer);
+	free_irq(pwr->irq, pwr);
 	input_unregister_device(pwr->idev);
 	input_free_device(pwr->idev);
 	kfree(pwr);
Signature · 1 line
1.7.3.4.598.g85356
#20 lore raw

PATCH 8/10 cbus: retu-rtc: move to threaded irq

In reply to Felipe Balbi

Move to the generic threaded irq infrastructure and drop all the retu-specific magic.

Unfortunately, due to the conversion and lack of docs, retu_rtc_ioctl() had to be dropped, someone else with access to docs is free to implement it later considering the new style of the driver.

---
 drivers/cbus/Makefile   |    2 +-
 drivers/cbus/retu-rtc.c |  120 ++++++----------------------------------------
 2 files changed, 17 insertions(+), 105 deletions(-)
drivers/cbus/Makefile +1 -1
index 23f82b4..7bfd997 100644
@@ -10,6 +10,6 @@ obj-$(CONFIG_CBUS_TAHVO_USER)	+= tahvo-user.o
 
 ## Disable Retu children until converted to threaded IRQ
 obj-$(CONFIG_CBUS_RETU_POWERBUTTON) += retu-pwrbutton.o
-#obj-$(CONFIG_CBUS_RETU_RTC)	+= retu-rtc.o
+obj-$(CONFIG_CBUS_RETU_RTC)	+= retu-rtc.o
 #obj-$(CONFIG_CBUS_RETU_WDT)	+= retu-wdt.o
 obj-$(CONFIG_CBUS_RETU_HEADSET)	+= retu-headset.o
drivers/cbus/retu-rtc.c +16 -104

206 lines not on this page · raw message

Signature · 1 line
1.7.3.4.598.g85356
#21 lore raw

PATCH 9/10 cbus: retu-rtc: drop the reset_occurred flag

In reply to Felipe Balbi

that flag is never read anyway, only written,
so we can drop it.

---
 drivers/cbus/retu-rtc.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)
drivers/cbus/retu-rtc.c +2 -8
index 6e201aa..b2b9472 100644
@@ -52,7 +52,6 @@ struct retu_rtc {
 	struct rtc_device	*rtc;
 
 	u16			alarm_expired;
-	u16			reset_occurred;
 };
 
 static void retu_rtc_do_reset(struct retu_rtc *rtc)
@@ -71,7 +70,6 @@ static void retu_rtc_do_reset(struct retu_rtc *rtc)
 	retu_write_reg(RETU_REG_RTCCALR, 0x00c0);
 
 	rtc->alarm_expired = 0;
-	rtc->reset_occurred = 1;
 }
 
 static irqreturn_t retu_rtc_interrupt(int irq, void *_rtc)
@@ -223,14 +221,10 @@ static int __init retu_rtc_probe(struct platform_device *pdev)
 		goto err1;
 	}
 
-	/* If the calibration register is zero, we've probably lost
-	 * power */
-	if (retu_read_reg(RETU_REG_RTCCALR) & 0x00ff)
-		rtc->reset_occurred = 0;
-	else
+	/* If the calibration register is zero, we've probably lost power */
+	if (!(retu_read_reg(RETU_REG_RTCCALR) & 0x00ff))
 		retu_rtc_do_reset(rtc);
 
-
 	rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, &
 			retu_rtc_ops, THIS_MODULE);
 	if (IS_ERR(rtc->rtc)) {
Signature · 1 line
1.7.3.4.598.g85356
#22 lore raw

PATCH 10/10 cbus: Makefile: re-enable retu-wdt

In reply to Felipe Balbi

Now that all conversions have been made,
reenable retu-wdt driver.

---
 drivers/cbus/Makefile |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/cbus/Makefile +1 -2
index 7bfd997..c5c3940 100644
@@ -8,8 +8,7 @@ obj-$(CONFIG_CBUS_RETU)		+= retu.o
 obj-$(CONFIG_CBUS_TAHVO_USB)	+= tahvo-usb.o
 obj-$(CONFIG_CBUS_TAHVO_USER)	+= tahvo-user.o
 
-## Disable Retu children until converted to threaded IRQ
 obj-$(CONFIG_CBUS_RETU_POWERBUTTON) += retu-pwrbutton.o
 obj-$(CONFIG_CBUS_RETU_RTC)	+= retu-rtc.o
-#obj-$(CONFIG_CBUS_RETU_WDT)	+= retu-wdt.o
+obj-$(CONFIG_CBUS_RETU_WDT)	+= retu-wdt.o
 obj-$(CONFIG_CBUS_RETU_HEADSET)	+= retu-headset.o
Signature · 1 line
1.7.3.4.598.g85356