Skip to contentSkip to conversation

drivers/rtc/rtc-ds1307.c: Basic cleanups and support for wakeupirq

PATCH In review Nishanth Menon 5 participants 16 messages Jun 23, 2015 – Jul 2, 2015

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

v2 cover drivers/rtc/rtc-ds1307.c: Basic cleanups and support for wakeupirq

Hi,

Here is the revamp of the patch posted eariler to support wakeupirq. This series does a few cleanups as well prior to introducing the generic apis required to support the wakeirq mechanism used on certain TI SoCs. Cleanups done here are just minimal set of the cleanups we discussed in [2].

Series is based on next-20150623

Test log: http://pastebin.ubuntu.com/11763002/

NOTE1: I have only tested in mcp79410 device, and not on other ds1307-rtc driver compatbile devices as I dont have any other. additional testing might be nice to have.
NOTE2: there are additional fixes that linux-next seems to need but those are in omap-rtc, cpufreq etc, but those are not related by the ds-1307.

V1: https://patchwork.kernel.org/patch/4759171/

NOTE: Patch 5/5 of the series is meant to indicate the usage, and will be reposted along with other wakeup sources to be enabled once the driver changes are accepted.

Felipe Balbi (1):
drivers/rtc/rtc-ds1307.c: Convert to threaded IRQ

Nishanth Menon (4):
drivers/rtc/rtc-ds1307.c: Switch to managed irq allocation drivers/rtc/rtc-ds1307.c: Sort the headers drivers/rtc/rtc-ds1307.c: Support optional wakeup interrupt source (TMP) ARM: dts: am57xx-beagle-x15: Add wakeup irq for mcp79410

 arch/arm/boot/dts/am57xx-beagle-x15.dts |    3 +-
 drivers/rtc/rtc-ds1307.c                |  110 +++++++++++++++++--------------
 2 files changed, 63 insertions(+), 50 deletions(-)
Signature · 3 lines
1.7.9.5

[2] https://patchwork.kernel.org/patch/6245101/
#1 lore raw

PATCH v2 1/5 drivers/rtc/rtc-ds1307.c: Convert to threaded IRQ

From: Felipe Balbi <[email protected]>

The driver currently emulates the concept of threaded IRQ using a workqueue, which it really does not need to. Instead, switch over to threaded_irq handlers which is meant precisely for the same purpose.

---
 drivers/rtc/rtc-ds1307.c |   59 +++++++++++++++-------------------------------
 1 file changed, 19 insertions(+), 40 deletions(-)
drivers/rtc/rtc-ds1307.c +19 -40
index 6e76de1856fc..8ea496e54a2e 100644
@@ -114,7 +114,6 @@ struct ds1307 {
 #define HAS_ALARM	1		/* bit 1 == irq claimed */
 	struct i2c_client	*client;
 	struct rtc_device	*rtc;
-	struct work_struct	work;
 	s32 (*read_block_data)(const struct i2c_client *client, u8 command,
 			       u8 length, u8 *values);
 	s32 (*write_block_data)(const struct i2c_client *client, u8 command,
@@ -311,27 +310,17 @@ static s32 ds1307_native_smbus_read_block_data(const struct i2c_client *client,
 /*----------------------------------------------------------------------*/
 
 /*
- * The IRQ logic includes a "real" handler running in IRQ context just
- * long enough to schedule this workqueue entry.   We need a task context
- * to talk to the RTC, since I2C I/O calls require that; and disable the
- * IRQ until we clear its status on the chip, so that this handler can
- * work with any type of triggering (not just falling edge).
- *
  * The ds1337 and ds1339 both have two alarms, but we only use the first
  * one (with a "seconds" field).  For ds1337 we expect nINTA is our alarm
  * signal; ds1339 chips have only one alarm signal.
  */
-static void ds1307_work(struct work_struct *work)
+static irqreturn_t ds1307_irq(int irq, void *dev_id)
 {
-	struct ds1307		*ds1307;
-	struct i2c_client	*client;
-	struct mutex		*lock;
+	struct i2c_client	*client = dev_id;
+	struct ds1307		*ds1307 = i2c_get_clientdata(client);
+	struct mutex		*lock = &ds1307->rtc->ops_lock;
 	int			stat, control;
 
-	ds1307 = container_of(work, struct ds1307, work);
-	client = ds1307->client;
-	lock = &ds1307->rtc->ops_lock;
-
 	mutex_lock(lock);
 	stat = i2c_smbus_read_byte_data(client, DS1337_REG_STATUS);
 	if (stat < 0)
@@ -352,18 +341,8 @@ static void ds1307_work(struct work_struct *work)
 	}
 
 out:
-	if (test_bit(HAS_ALARM, &ds1307->flags))
-		enable_irq(client->irq);
 	mutex_unlock(lock);
-}
-
-static irqreturn_t ds1307_irq(int irq, void *dev_id)
-{
-	struct i2c_client	*client = dev_id;
-	struct ds1307		*ds1307 = i2c_get_clientdata(client);
 
-	disable_irq_nosync(irq);
-	schedule_work(&ds1307->work);
 	return IRQ_HANDLED;
 }
 
@@ -634,13 +613,14 @@ static const struct rtc_class_ops ds13xx_rtc_ops = {
 					 MCP794XX_BIT_ALMX_C1 | \
 					 MCP794XX_BIT_ALMX_C2)
 
-static void mcp794xx_work(struct work_struct *work)
+static irqreturn_t mcp794xx_irq(int irq, void *dev_id)
 {
-	struct ds1307 *ds1307 = container_of(work, struct ds1307, work);
-	struct i2c_client *client = ds1307->client;
+	struct i2c_client       *client = dev_id;
+	struct ds1307           *ds1307 = i2c_get_clientdata(client);
+	struct mutex            *lock = &ds1307->rtc->ops_lock;
 	int reg, ret;
 
-	mutex_lock(&ds1307->rtc->ops_lock);
+	mutex_lock(lock);
 
 	/* Check and clear alarm 0 interrupt flag. */
 	reg = i2c_smbus_read_byte_data(client, MCP794XX_REG_ALARM0_CTRL);
@@ -665,9 +645,9 @@ static void mcp794xx_work(struct work_struct *work)
 	rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF);
 
 out:
-	if (test_bit(HAS_ALARM, &ds1307->flags))
-		enable_irq(client->irq);
-	mutex_unlock(&ds1307->rtc->ops_lock);
+	mutex_unlock(lock);
+
+	return IRQ_HANDLED;
 }
 
 static int mcp794xx_read_alarm(struct device *dev, struct rtc_wkalrm *t)
@@ -896,6 +876,8 @@ static int ds1307_probe(struct i2c_client *client,
 	bool			want_irq = false;
 	unsigned char		*buf;
 	struct ds1307_platform_data *pdata = dev_get_platdata(&client->dev);
+	irq_handler_t	irq_handler = ds1307_irq;
+
 	static const int	bbsqi_bitpos[] = {
 		[ds_1337] = 0,
 		[ds_1339] = DS1339_BIT_BBSQI,
@@ -962,8 +944,6 @@ static int ds1307_probe(struct i2c_client *client,
 		 * running on Vbackup (BBSQI/BBSQW)
 		 */
 		if (ds1307->client->irq > 0 && chip->alarm) {
-			INIT_WORK(&ds1307->work, ds1307_work);
-
 			ds1307->regs[0] |= DS1337_BIT_INTCN
 					| bbsqi_bitpos[ds1307->type];
 			ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE);
@@ -1053,7 +1033,7 @@ static int ds1307_probe(struct i2c_client *client,
 	case mcp794xx:
 		rtc_ops = &mcp794xx_rtc_ops;
 		if (ds1307->client->irq > 0 && chip->alarm) {
-			INIT_WORK(&ds1307->work, mcp794xx_work);
+			irq_handler = mcp794xx_irq;
 			want_irq = true;
 		}
 		break;
@@ -1176,8 +1156,9 @@ read_rtc:
 	}
 
 	if (want_irq) {
-		err = request_irq(client->irq, ds1307_irq, IRQF_SHARED,
-			  ds1307->rtc->name, client);
+		err = request_threaded_irq(client->irq, NULL, irq_handler,
+					   IRQF_SHARED | IRQF_ONESHOT,
+					   ds1307->rtc->name, client);
 		if (err) {
 			client->irq = 0;
 			dev_err(&client->dev, "unable to request IRQ!\n");
@@ -1231,10 +1212,8 @@ static int ds1307_remove(struct i2c_client *client)
 {
 	struct ds1307 *ds1307 = i2c_get_clientdata(client);
 
-	if (test_and_clear_bit(HAS_ALARM, &ds1307->flags)) {
+	if (test_and_clear_bit(HAS_ALARM, &ds1307->flags))
 		free_irq(client->irq, client);
-		cancel_work_sync(&ds1307->work);
-	}
 
 	if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags))
 		sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram);
Signature · 1 line
1.7.9.5
#2 lore raw

PATCH v2 2/5 drivers/rtc/rtc-ds1307.c: Switch to managed irq allocation

In reply to Nishanth Menon

Since we are not doing anything fancy in remove function that requires us to sequence IRQ free operation, we might as well switch over to devm_ equivalent of managed IRQ allocation and remove the explicit free_irq since it'd be done automatically at remove.

---
 drivers/rtc/rtc-ds1307.c |   10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/rtc/rtc-ds1307.c +4 -6
index 8ea496e54a2e..0a98d8a52791 100644
@@ -1156,9 +1156,10 @@ read_rtc:
 	}
 
 	if (want_irq) {
-		err = request_threaded_irq(client->irq, NULL, irq_handler,
-					   IRQF_SHARED | IRQF_ONESHOT,
-					   ds1307->rtc->name, client);
+		err = devm_request_threaded_irq(&client->dev,
+						client->irq, NULL, irq_handler,
+						IRQF_SHARED | IRQF_ONESHOT,
+						ds1307->rtc->name, client);
 		if (err) {
 			client->irq = 0;
 			dev_err(&client->dev, "unable to request IRQ!\n");
@@ -1212,9 +1213,6 @@ static int ds1307_remove(struct i2c_client *client)
 {
 	struct ds1307 *ds1307 = i2c_get_clientdata(client);
 
-	if (test_and_clear_bit(HAS_ALARM, &ds1307->flags))
-		free_irq(client->irq, client);
-
 	if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags))
 		sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram);
 
Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v2 3/5 drivers/rtc/rtc-ds1307.c: Sort the headers

In reply to Nishanth Menon

It is always a good practice to keep the #includes sorted

---
 drivers/rtc/rtc-ds1307.c |   10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/rtc/rtc-ds1307.c +5 -5
index 0a98d8a52791..b03880fc32b5 100644
@@ -11,14 +11,14 @@
  * published by the Free Software Foundation.
  */
 
-#include <linux/module.h>
+#include <linux/bcd.h>
+#include <linux/i2c.h>
 #include <linux/init.h>
+#include <linux/module.h>
+#include <linux/rtc/ds1307.h>
+#include <linux/rtc.h>
 #include <linux/slab.h>
-#include <linux/i2c.h>
 #include <linux/string.h>
-#include <linux/rtc.h>
-#include <linux/bcd.h>
-#include <linux/rtc/ds1307.h>
 
 /*
  * We can't determine type by probing, but if we expect pre-Linux code
Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v2 4/5 drivers/rtc/rtc-ds1307.c: Support optional wakeup interrupt source

In reply to Nishanth Menon

With the recent pinctrl-single changes, SoCs such as Texas Instrument's OMAP processors can treat wake-up events from deeper idle states as interrupts.

Let's add support for the optional second interrupt for wake-up using the generic wakeirq support added in commit 4990d4fe327b ("PM /
Wakeirq: Add automated device wake IRQ handling")

Finally, to pass the wake-up interrupt in the dts file, interrupts-extended property needs to be passed.

This is similar in approach to commit 2a0b965cfb6e ("serial: omap: Add support for optional wake-up") + ee83bd3b6483 ("serial: omap: Switch wake-up interrupt to generic wakeirq")

---
Changes since V1:
- dropped the need for specific suspend-resume handlers generic api has adequate hooks for those
- little more code flow cleanups.

V1: https://patchwork.kernel.org/patch/4759171/

 drivers/rtc/rtc-ds1307.c |   41 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 38 insertions(+), 3 deletions(-)
drivers/rtc/rtc-ds1307.c +38 -3
index b03880fc32b5..b00d97dbf955 100644
@@ -15,6 +15,9 @@
 #include <linux/i2c.h>
 #include <linux/init.h>
 #include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/of_irq.h>
+#include <linux/pm_wakeirq.h>
 #include <linux/rtc/ds1307.h>
 #include <linux/rtc.h>
 #include <linux/slab.h>
@@ -114,6 +117,7 @@ struct ds1307 {
 #define HAS_ALARM	1		/* bit 1 == irq claimed */
 	struct i2c_client	*client;
 	struct rtc_device	*rtc;
+	int			wakeirq;
 	s32 (*read_block_data)(const struct i2c_client *client, u8 command,
 			       u8 length, u8 *values);
 	s32 (*write_block_data)(const struct i2c_client *client, u8 command,
@@ -1156,6 +1160,8 @@ read_rtc:
 	}
 
 	if (want_irq) {
+		struct device_node *node = client->dev.of_node;
+
 		err = devm_request_threaded_irq(&client->dev,
 						client->irq, NULL, irq_handler,
 						IRQF_SHARED | IRQF_ONESHOT,
@@ -1163,13 +1169,36 @@ read_rtc:
 		if (err) {
 			client->irq = 0;
 			dev_err(&client->dev, "unable to request IRQ!\n");
-		} else {
+			goto no_irq;
+		}
+
+		set_bit(HAS_ALARM, &ds1307->flags);
+		dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
 
-			set_bit(HAS_ALARM, &ds1307->flags);
-			dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
+		/* Currently supported by OF code only! */
+		if (!node)
+			goto no_irq;
+
+		ds1307->wakeirq = of_irq_get(node, 1);
+		if (ds1307->wakeirq <= 0) {
+			if (ds1307->wakeirq == -EPROBE_DEFER) {
+				err = ds1307->wakeirq;
+				goto exit;
+			}
+			ds1307->wakeirq = 0;
+			goto no_irq;
+		}
+
+		err = dev_pm_set_dedicated_wake_irq(&client->dev,
+						    ds1307->wakeirq);
+		if (err) {
+			dev_err(&client->dev, "unable to setup wakeIRQ %d\n",
+				err);
+			goto exit;
 		}
 	}
 
+no_irq:
 	if (chip->nvram_size) {
 
 		ds1307->nvram = devm_kzalloc(&client->dev,
@@ -1206,6 +1235,9 @@ read_rtc:
 	return 0;
 
 exit:
+	if (ds1307->wakeirq)
+		dev_pm_clear_wake_irq(&client->dev);
+
 	return err;
 }
 
@@ -1213,6 +1245,9 @@ static int ds1307_remove(struct i2c_client *client)
 {
 	struct ds1307 *ds1307 = i2c_get_clientdata(client);
 
+	if (ds1307->wakeirq)
+		dev_pm_clear_wake_irq(&client->dev);
+
 	if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags))
 		sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram);
 
Signature · 1 line
1.7.9.5
#12 lore raw

PATCH v2 5/5 ARM: dts: am57xx-beagle-x15: Add wakeup irq for mcp79410

In reply to Nishanth Menon

With the support in the generic PM framework for wakeirq and capability added to the rtc-ds1307 driver to support this, we can now define the optional wakeup irq to allow the RTC to wakeup the system from low power modes as part of suspend.

---

Please do not merge this patch -> since this needs to come via linux-omap tree and also needs to be done with a few other changes on other peripherals. This is meant for illustration only.

 arch/arm/boot/dts/am57xx-beagle-x15.dts |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm/boot/dts/am57xx-beagle-x15.dts +2 -1
index a42cc377a862..5c9ce2df260a 100644
@@ -517,7 +517,8 @@
 	mcp_rtc: rtc at 6f {
 		compatible = "microchip,mcp7941x";
 		reg = <0x6f>;
-		interrupts = <GIC_SPI 2 IRQ_TYPE_EDGE_RISING>;  /* IRQ_SYS_1N */
+		interrupts-extended = <&crossbar_mpu GIC_SPI 2 IRQ_TYPE_EDGE_RISING>,
+				      <&dra7_pmx_core 0x424>;
 
 		pinctrl-names = "default";
 		pinctrl-0 = <&mcp79410_pins_default>;
Signature · 1 line
1.7.9.5
Acked-by on v2 4/5
#5 lore raw

Re: [PATCH V2 4/5] drivers/rtc/rtc-ds1307.c: Support optional wakeup interrupt source

In reply to Nishanth Menon
Quoted 8 lines · Nishanth Menon

With the recent pinctrl-single changes, SoCs such as Texas Instrument's OMAP processors can treat wake-up events from deeper idle states as interrupts.

Let's add support for the optional second interrupt for wake-up using the generic wakeirq support added in commit 4990d4fe327b ("PM /
Wakeirq: Add automated device wake IRQ handling")

Quoted 6 lines

Finally, to pass the wake-up interrupt in the dts file, interrupts-extended property needs to be passed.

This is similar in approach to commit 2a0b965cfb6e ("serial: omap: Add support for optional wake-up") + ee83bd3b6483 ("serial: omap: Switch wake-up interrupt to generic wakeirq")

The wakeirq related changes look good to me:

Acked-by on the v2 series
#13 lore raw
In reply to Nishanth Menon

Hi,

Quoted 25 lines · Nishanth Menon

Hi,

Here is the revamp of the patch posted eariler to support wakeupirq. This series does a few cleanups as well prior to introducing the generic apis required to support the wakeirq mechanism used on certain TI SoCs. Cleanups done here are just minimal set of the cleanups we discussed in [2].

Series is based on next-20150623

Test log: http://pastebin.ubuntu.com/11763002/

NOTE1: I have only tested in mcp79410 device, and not on other ds1307-rtc driver compatbile devices as I dont have any other. additional testing might be nice to have.
NOTE2: there are additional fixes that linux-next seems to need but those are in omap-rtc, cpufreq etc, but those are not related by the ds-1307.

V1: https://patchwork.kernel.org/patch/4759171/

NOTE: Patch 5/5 of the series is meant to indicate the usage, and will be reposted along with other wakeup sources to be enabled once the driver changes are accepted.

Quoted 7 lines

Felipe Balbi (1):
drivers/rtc/rtc-ds1307.c: Convert to threaded IRQ

Nishanth Menon (4):
drivers/rtc/rtc-ds1307.c: Switch to managed irq allocation drivers/rtc/rtc-ds1307.c: Sort the headers drivers/rtc/rtc-ds1307.c: Support optional wakeup interrupt source

for the series, except the patch which I wrote :

Signature · 8 lines
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150624/b96e0f2f/attachment.sig>
#6 lore raw

Re: [PATCH V2 4/5] drivers/rtc/rtc-ds1307.c: Support optional wakeup interrupt source

In reply to Nishanth Menon
Quoted 74 lines · Nishanth Menon

With the recent pinctrl-single changes, SoCs such as Texas Instrument's OMAP processors can treat wake-up events from deeper idle states as interrupts.

Let's add support for the optional second interrupt for wake-up using the generic wakeirq support added in commit 4990d4fe327b ("PM /
Wakeirq: Add automated device wake IRQ handling")

Finally, to pass the wake-up interrupt in the dts file, interrupts-extended property needs to be passed.

This is similar in approach to commit 2a0b965cfb6e ("serial: omap: Add support for optional wake-up") + ee83bd3b6483 ("serial: omap: Switch wake-up interrupt to generic wakeirq")

---
Changes since V1:
- dropped the need for specific suspend-resume handlers generic api has adequate hooks for those
- little more code flow cleanups.

V1: https://patchwork.kernel.org/patch/4759171/

  drivers/rtc/rtc-ds1307.c |   41 ++++++++++++++++++++++++++++++++++++++---
  1 file changed, 38 insertions(+), 3 deletions(-)
drivers/rtc/rtc-ds1307.c +14 -3
index b03880fc32b5..b00d97dbf955 100644
@@ -15,6 +15,9 @@
  #include <linux/i2c.h>
  #include <linux/init.h>
  #include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/of_irq.h>
+#include <linux/pm_wakeirq.h>
  #include <linux/rtc/ds1307.h>
  #include <linux/rtc.h>
  #include <linux/slab.h>
@@ -114,6 +117,7 @@ struct ds1307 {
  #define HAS_ALARM	1		/* bit 1 == irq claimed */
  	struct i2c_client	*client;
  	struct rtc_device	*rtc;
+	int			wakeirq;
  	s32 (*read_block_data)(const struct i2c_client *client, u8 command,
  			       u8 length, u8 *values);
  	s32 (*write_block_data)(const struct i2c_client *client, u8 command,
@@ -1156,6 +1160,8 @@ read_rtc:
  	}
 
  	if (want_irq) {
+		struct device_node *node = client->dev.of_node;
+
  		err = devm_request_threaded_irq(&client->dev,
  						client->irq, NULL, irq_handler,
  						IRQF_SHARED | IRQF_ONESHOT,
@@ -1163,13 +1169,36 @@ read_rtc:
  		if (err) {
  			client->irq = 0;
  			dev_err(&client->dev, "unable to request IRQ!\n");
-		} else {
+			goto no_irq;
+		}
+
+		set_bit(HAS_ALARM, &ds1307->flags);
+		dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
 
-			set_bit(HAS_ALARM, &ds1307->flags);
-			dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
+		/* Currently supported by OF code only! */
+		if (!node)
+			goto no_irq;

drivers/rtc/rtc-ds1307.c read_rtc: · line 1190

Quoted 10 lines
drivers/rtc/rtc-ds1307.c +10 -0
+
+		ds1307->wakeirq = of_irq_get(node, 1);
+		if (ds1307->wakeirq <= 0) {
+			if (ds1307->wakeirq == -EPROBE_DEFER) {
+				err = ds1307->wakeirq;
+				goto exit;
+			}
+			ds1307->wakeirq = 0;
+			goto no_irq;
+		}

Might be above code could be done a little bit simpler?

		err = of_irq_get(node, 1);
		if (err <= 0) {
			if (err == -EPROBE_DEFER)
				goto exit;
			goto no_irq;
		}
		ds1307->wakeirq = err;
Quoted 35 lines
drivers/rtc/rtc-ds1307.c +14 -0
+
+		err = dev_pm_set_dedicated_wake_irq(&client->dev,
+						    ds1307->wakeirq);
+		if (err) {
+			dev_err(&client->dev, "unable to setup wakeIRQ %d\n",
+				err);
+			goto exit;
  		}
  	}
 
+no_irq:
  	if (chip->nvram_size) {
 
  		ds1307->nvram = devm_kzalloc(&client->dev,
@@ -1206,6 +1235,9 @@ read_rtc:
  	return 0;
 
  exit:
+	if (ds1307->wakeirq)
+		dev_pm_clear_wake_irq(&client->dev);
+
  	return err;
  }
 
@@ -1213,6 +1245,9 @@ static int ds1307_remove(struct i2c_client *client)
  {
  	struct ds1307 *ds1307 = i2c_get_clientdata(client);
 
+	if (ds1307->wakeirq)
+		dev_pm_clear_wake_irq(&client->dev);
+
  	if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags))
  		sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram);
 
Signature · 2 lines
regards,
-grygorii
Reviewed-by
#14 lore raw
In reply to Felipe Balbi
Quoted 31 lines · Felipe Balbi

Hi,

Quoted 28 lines · Nishanth Menon

Hi,

Here is the revamp of the patch posted eariler to support wakeupirq. This series does a few cleanups as well prior to introducing the generic apis required to support the wakeirq mechanism used on certain TI SoCs. Cleanups done here are just minimal set of the cleanups we discussed in [2].

Series is based on next-20150623

Test log: http://pastebin.ubuntu.com/11763002/

NOTE1: I have only tested in mcp79410 device, and not on other ds1307-rtc driver compatbile devices as I dont have any other. additional testing might be nice to have.
NOTE2: there are additional fixes that linux-next seems to need but those are in omap-rtc, cpufreq etc, but those are not related by the ds-1307.

V1: https://patchwork.kernel.org/patch/4759171/

NOTE: Patch 5/5 of the series is meant to indicate the usage, and will be reposted along with other wakeup sources to be enabled once the driver changes are accepted.

Felipe Balbi (1):
drivers/rtc/rtc-ds1307.c: Convert to threaded IRQ

Quoted 9 lines
Quoted 4 lines

Nishanth Menon (4):
drivers/rtc/rtc-ds1307.c: Switch to managed irq allocation drivers/rtc/rtc-ds1307.c: Sort the headers drivers/rtc/rtc-ds1307.c: Support optional wakeup interrupt source

for the series, except the patch which I wrote :

With minor comment to patch 4:

Signature · 2 lines
regards,
-grygorii
#7 lore raw

Re: [PATCH V2 4/5] drivers/rtc/rtc-ds1307.c: Support optional wakeup interrupt source

In reply to Grygorii Strashko
Quoted 1 line · Grygorii Strashko

On 06/23/2015 07:15 PM, Nishanth Menon wrote:

[...]

Quoted 12 lines

drivers/rtc/rtc-ds1307.c read_rtc: · line 1190

Quoted 9 lines
drivers/rtc/rtc-ds1307.c +9 -0
+		ds1307->wakeirq = of_irq_get(node, 1);
+		if (ds1307->wakeirq <= 0) {
+			if (ds1307->wakeirq == -EPROBE_DEFER) {
+				err = ds1307->wakeirq;
+				goto exit;
+			}
+			ds1307->wakeirq = 0;
+			goto no_irq;
+		}

Might be above code could be done a little bit simpler?

Quoted 5 lines
		err = of_irq_get(node, 1);
		if (err <= 0) {
			if (err == -EPROBE_DEFER)
				goto exit;
			goto no_irq;

I had considered it, but problem with this approach is that is err does not get reset back to 0 and probe will fail as it flows through the rest of the code.. which is not our intent.

Quoted 3 lines
		}
		ds1307->wakeirq = err;
Signature · 2 lines
Regards,
Nishanth Menon
#8 lore raw

Re: [PATCH V2 4/5] drivers/rtc/rtc-ds1307.c: Support optional wakeup interrupt source

Quoted 22 lines · Nishanth Menon
Quoted 1 line · Grygorii Strashko

On 06/23/2015 07:15 PM, Nishanth Menon wrote:

[...]

Quoted 12 lines

drivers/rtc/rtc-ds1307.c read_rtc: · line 1190

Quoted 9 lines
drivers/rtc/rtc-ds1307.c +9 -0
+		ds1307->wakeirq = of_irq_get(node, 1);
+		if (ds1307->wakeirq <= 0) {
+			if (ds1307->wakeirq == -EPROBE_DEFER) {
+				err = ds1307->wakeirq;
+				goto exit;
+			}
+			ds1307->wakeirq = 0;
+			goto no_irq;
+		}

Might be above code could be done a little bit simpler?

Quoted 5 lines
		err = of_irq_get(node, 1);
		if (err <= 0) {
			if (err == -EPROBE_DEFER)
				goto exit;
			goto no_irq;
Quoted 6 lines

I had considered it, but problem with this approach is that is err does not get reset back to 0 and probe will fail as it flows through the rest of the code.. which is not our intent.

Quoted 2 lines
		}
		ds1307->wakeirq = err;

As I can see from final code (after applying all patches) - It should work. But I will not insist :)

Signature · 2 lines
regards,
-grygorii
author Acked-by Tony Lindgren Acked-by Felipe Balbi
#9 lore raw

Re: [PATCH V2 4/5] drivers/rtc/rtc-ds1307.c: Support optional wakeup interrupt source

In reply to Nishanth Menon
Quoted 22 lines · Nishanth Menon
Quoted 1 line · Grygorii Strashko

On 06/23/2015 07:15 PM, Nishanth Menon wrote:

[...]

Quoted 12 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+		ds1307->wakeirq = of_irq_get(node, 1);
+		if (ds1307->wakeirq <= 0) {
+			if (ds1307->wakeirq == -EPROBE_DEFER) {
+				err = ds1307->wakeirq;
+				goto exit;
+			}
+			ds1307->wakeirq = 0;
+			goto no_irq;
+		}

Might be above code could be done a little bit simpler?

Quoted 5 lines
		err = of_irq_get(node, 1);
		if (err <= 0) {
			if (err == -EPROBE_DEFER)
				goto exit;
			goto no_irq;
Quoted 3 lines

I had considered it, but problem with this approach is that is err does not get reset back to 0 and probe will fail as it flows through the rest of the code.. which is not our intent.

I am wrong here - code just returns 0 and ignores err. So, how about the following patch instead: (Alexandre, please do let me know if the entire series needs to be reposted):
- improvement as suggested
- Picked up previous acks
- cleanup in probe does not need dev_pm_clear_wake_irq.
-->8<---

Quoted 1 line

From 12367f8edffc25613f6f920d9bd7b69dfed57ce1 Mon Sep 17 00:00:00 2001

From: Nishanth Menon <[email protected]>
Date: Mon, 22 Jun 2015 14:13:19 -0500
Subject: [PATCH V3] drivers/rtc/rtc-ds1307.c: Support optional wakeup interrupt
source

With the recent pinctrl-single changes, SoCs such as Texas Instrument's OMAP processors can treat wake-up events from deeper idle states as interrupts.

Let's add support for the optional second interrupt for wake-up using the generic wakeirq support added in commit 4990d4fe327b ("PM /
Wakeirq: Add automated device wake IRQ handling")

Finally, to pass the wake-up interrupt in the dts file, interrupts-extended property needs to be passed.

This is similar in approach to commit 2a0b965cfb6e ("serial: omap: Add support for optional wake-up") + ee83bd3b6483 ("serial: omap: Switch wake-up interrupt to generic wakeirq")

---
 drivers/rtc/rtc-ds1307.c |   36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)
drivers/rtc/rtc-ds1307.c +33 -3
index b03880fc32b5..e16989c48a90 100644
@@ -15,6 +15,9 @@
 #include <linux/i2c.h>
 #include <linux/init.h>
 #include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/of_irq.h>
+#include <linux/pm_wakeirq.h>
 #include <linux/rtc/ds1307.h>
 #include <linux/rtc.h>
 #include <linux/slab.h>
@@ -114,6 +117,7 @@ struct ds1307 {
 #define HAS_ALARM	1		/* bit 1 == irq claimed */
 	struct i2c_client	*client;
 	struct rtc_device	*rtc;
+	int			wakeirq;
 	s32 (*read_block_data)(const struct i2c_client *client, u8 command,
 			       u8 length, u8 *values);
 	s32 (*write_block_data)(const struct i2c_client *client, u8 command,
@@ -1156,6 +1160,8 @@ read_rtc:
 	}
 
 	if (want_irq) {
+		struct device_node *node = client->dev.of_node;
+
 		err = devm_request_threaded_irq(&client->dev,
 						client->irq, NULL, irq_handler,
 						IRQF_SHARED | IRQF_ONESHOT,
@@ -1163,13 +1169,34 @@ read_rtc:
 		if (err) {
 			client->irq = 0;
 			dev_err(&client->dev, "unable to request IRQ!\n");
-		} else {
+			goto no_irq;
+		}
 
-			set_bit(HAS_ALARM, &ds1307->flags);
-			dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
+		set_bit(HAS_ALARM, &ds1307->flags);
+		dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
+
+		/* Currently supported by OF code only! */
+		if (!node)
+			goto no_irq;
+
+		err = of_irq_get(node, 1);
+		if (err <= 0) {
+			if (err == -EPROBE_DEFER)
+				goto exit;
+			goto no_irq;
+		}
+		ds1307->wakeirq = err;
+
+		err = dev_pm_set_dedicated_wake_irq(&client->dev,
+						    ds1307->wakeirq);
+		if (err) {
+			dev_err(&client->dev, "unable to setup wakeIRQ %d!\n",
+				err);
+			goto exit;
 		}
 	}
 
+no_irq:
 	if (chip->nvram_size) {
 
 		ds1307->nvram = devm_kzalloc(&client->dev,
@@ -1213,6 +1240,9 @@ static int ds1307_remove(struct i2c_client *client)
 {
 	struct ds1307 *ds1307 = i2c_get_clientdata(client);
 
+	if (ds1307->wakeirq)
+		dev_pm_clear_wake_irq(&client->dev);
+
 	if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags))
 		sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram);
 
Signature · 5 lines
1.7.9.5

-- 
Regards,
Nishanth Menon
Reviewed-by
#10 lore raw

Re: [PATCH V2 4/5] drivers/rtc/rtc-ds1307.c: Support optional wakeup interrupt source

Quoted 27 lines · Nishanth Menon
Quoted 22 lines · Nishanth Menon
Quoted 1 line · Grygorii Strashko

On 06/23/2015 07:15 PM, Nishanth Menon wrote:

[...]

Quoted 12 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+		ds1307->wakeirq = of_irq_get(node, 1);
+		if (ds1307->wakeirq <= 0) {
+			if (ds1307->wakeirq == -EPROBE_DEFER) {
+				err = ds1307->wakeirq;
+				goto exit;
+			}
+			ds1307->wakeirq = 0;
+			goto no_irq;
+		}

Might be above code could be done a little bit simpler?

Quoted 5 lines
		err = of_irq_get(node, 1);
		if (err <= 0) {
			if (err == -EPROBE_DEFER)
				goto exit;
			goto no_irq;
Quoted 3 lines

I had considered it, but problem with this approach is that is err does not get reset back to 0 and probe will fail as it flows through the rest of the code.. which is not our intent.

Quoted 6 lines

I am wrong here - code just returns 0 and ignores err. So, how about the following patch instead: (Alexandre, please do let me know if the entire series needs to be reposted):
- improvement as suggested
- Picked up previous acks
- cleanup in probe does not need dev_pm_clear_wake_irq.

Quoted 109 lines

-->8<---
From 12367f8edffc25613f6f920d9bd7b69dfed57ce1 Mon Sep 17 00:00:00 2001
From: Nishanth Menon <[email protected]>
Date: Mon, 22 Jun 2015 14:13:19 -0500
Subject: [PATCH V3] drivers/rtc/rtc-ds1307.c: Support optional wakeup interrupt
source

With the recent pinctrl-single changes, SoCs such as Texas Instrument's OMAP processors can treat wake-up events from deeper idle states as interrupts.

Let's add support for the optional second interrupt for wake-up using the generic wakeirq support added in commit 4990d4fe327b ("PM /
Wakeirq: Add automated device wake IRQ handling")

Finally, to pass the wake-up interrupt in the dts file, interrupts-extended property needs to be passed.

This is similar in approach to commit 2a0b965cfb6e ("serial: omap: Add support for optional wake-up") + ee83bd3b6483 ("serial: omap: Switch wake-up interrupt to generic wakeirq")

---
  drivers/rtc/rtc-ds1307.c |   36 +++++++++++++++++++++++++++++++++---
  1 file changed, 33 insertions(+), 3 deletions(-)
drivers/rtc/rtc-ds1307.c +33 -3
index b03880fc32b5..e16989c48a90 100644
@@ -15,6 +15,9 @@
  #include <linux/i2c.h>
  #include <linux/init.h>
  #include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/of_irq.h>
+#include <linux/pm_wakeirq.h>
  #include <linux/rtc/ds1307.h>
  #include <linux/rtc.h>
  #include <linux/slab.h>
@@ -114,6 +117,7 @@ struct ds1307 {
  #define HAS_ALARM	1		/* bit 1 == irq claimed */
  	struct i2c_client	*client;
  	struct rtc_device	*rtc;
+	int			wakeirq;
  	s32 (*read_block_data)(const struct i2c_client *client, u8 command,
  			       u8 length, u8 *values);
  	s32 (*write_block_data)(const struct i2c_client *client, u8 command,
@@ -1156,6 +1160,8 @@ read_rtc:
  	}
 
  	if (want_irq) {
+		struct device_node *node = client->dev.of_node;
+
  		err = devm_request_threaded_irq(&client->dev,
  						client->irq, NULL, irq_handler,
  						IRQF_SHARED | IRQF_ONESHOT,
@@ -1163,13 +1169,34 @@ read_rtc:
  		if (err) {
  			client->irq = 0;
  			dev_err(&client->dev, "unable to request IRQ!\n");
-		} else {
+			goto no_irq;
+		}
 
-			set_bit(HAS_ALARM, &ds1307->flags);
-			dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
+		set_bit(HAS_ALARM, &ds1307->flags);
+		dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
+
+		/* Currently supported by OF code only! */
+		if (!node)
+			goto no_irq;
+
+		err = of_irq_get(node, 1);
+		if (err <= 0) {
+			if (err == -EPROBE_DEFER)
+				goto exit;
+			goto no_irq;
+		}
+		ds1307->wakeirq = err;
+
+		err = dev_pm_set_dedicated_wake_irq(&client->dev,
+						    ds1307->wakeirq);
+		if (err) {
+			dev_err(&client->dev, "unable to setup wakeIRQ %d!\n",
+				err);
+			goto exit;
  		}
  	}
 
+no_irq:
  	if (chip->nvram_size) {
 
  		ds1307->nvram = devm_kzalloc(&client->dev,
@@ -1213,6 +1240,9 @@ static int ds1307_remove(struct i2c_client *client)
  {
  	struct ds1307 *ds1307 = i2c_get_clientdata(client);
 
+	if (ds1307->wakeirq)
+		dev_pm_clear_wake_irq(&client->dev);
+
  	if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags))
  		sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram);
 
Signature · 2 lines
regards,
-grygorii
#11 lore raw

Re: [PATCH V2 4/5] drivers/rtc/rtc-ds1307.c: Support optional wakeup interrupt source

In reply to Nishanth Menon

Hi,

Quoted 3 lines · Nishanth Menon

I am wrong here - code just returns 0 and ignores err. So, how about the following patch instead: (Alexandre, please do let me know if the entire series needs to be reposted):

Can you resend just that one as v3? I'll take it right away. Thanks!

Quoted 117 lines

- improvement as suggested
- Picked up previous acks
- cleanup in probe does not need dev_pm_clear_wake_irq.
-->8<---
From 12367f8edffc25613f6f920d9bd7b69dfed57ce1 Mon Sep 17 00:00:00 2001
From: Nishanth Menon <[email protected]>
Date: Mon, 22 Jun 2015 14:13:19 -0500
Subject: [PATCH V3] drivers/rtc/rtc-ds1307.c: Support optional wakeup interrupt
source

With the recent pinctrl-single changes, SoCs such as Texas Instrument's OMAP processors can treat wake-up events from deeper idle states as interrupts.

Let's add support for the optional second interrupt for wake-up using the generic wakeirq support added in commit 4990d4fe327b ("PM /
Wakeirq: Add automated device wake IRQ handling")

Finally, to pass the wake-up interrupt in the dts file, interrupts-extended property needs to be passed.

This is similar in approach to commit 2a0b965cfb6e ("serial: omap: Add support for optional wake-up") + ee83bd3b6483 ("serial: omap: Switch wake-up interrupt to generic wakeirq")

---
 drivers/rtc/rtc-ds1307.c |   36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)
drivers/rtc/rtc-ds1307.c +33 -3
index b03880fc32b5..e16989c48a90 100644
@@ -15,6 +15,9 @@
 #include <linux/i2c.h>
 #include <linux/init.h>
 #include <linux/module.h>
+#include <linux/of_device.h>
+#include <linux/of_irq.h>
+#include <linux/pm_wakeirq.h>
 #include <linux/rtc/ds1307.h>
 #include <linux/rtc.h>
 #include <linux/slab.h>
@@ -114,6 +117,7 @@ struct ds1307 {
 #define HAS_ALARM	1		/* bit 1 == irq claimed */
 	struct i2c_client	*client;
 	struct rtc_device	*rtc;
+	int			wakeirq;
 	s32 (*read_block_data)(const struct i2c_client *client, u8 command,
 			       u8 length, u8 *values);
 	s32 (*write_block_data)(const struct i2c_client *client, u8 command,
@@ -1156,6 +1160,8 @@ read_rtc:
 	}
 
 	if (want_irq) {
+		struct device_node *node = client->dev.of_node;
+
 		err = devm_request_threaded_irq(&client->dev,
 						client->irq, NULL, irq_handler,
 						IRQF_SHARED | IRQF_ONESHOT,
@@ -1163,13 +1169,34 @@ read_rtc:
 		if (err) {
 			client->irq = 0;
 			dev_err(&client->dev, "unable to request IRQ!\n");
-		} else {
+			goto no_irq;
+		}
 
-			set_bit(HAS_ALARM, &ds1307->flags);
-			dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
+		set_bit(HAS_ALARM, &ds1307->flags);
+		dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
+
+		/* Currently supported by OF code only! */
+		if (!node)
+			goto no_irq;
+
+		err = of_irq_get(node, 1);
+		if (err <= 0) {
+			if (err == -EPROBE_DEFER)
+				goto exit;
+			goto no_irq;
+		}
+		ds1307->wakeirq = err;
+
+		err = dev_pm_set_dedicated_wake_irq(&client->dev,
+						    ds1307->wakeirq);
+		if (err) {
+			dev_err(&client->dev, "unable to setup wakeIRQ %d!\n",
+				err);
+			goto exit;
 		}
 	}
 
+no_irq:
 	if (chip->nvram_size) {
 
 		ds1307->nvram = devm_kzalloc(&client->dev,
@@ -1213,6 +1240,9 @@ static int ds1307_remove(struct i2c_client *client)
 {
 	struct ds1307 *ds1307 = i2c_get_clientdata(client);
 
+	if (ds1307->wakeirq)
+		dev_pm_clear_wake_irq(&client->dev);
+
 	if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags))
 		sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram);
 
Signature · 5 lines
1.7.9.5

-- 
Regards,
Nishanth Menon
Signature · 3 lines
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#15 lore raw
In reply to Nishanth Menon

Hi,

Quoted 3 lines · Nishanth Menon

NOTE1: I have only tested in mcp79410 device, and not on other ds1307-rtc driver compatbile devices as I dont have any other. additional testing might be nice to have.

Patchwork picked up V3 of 4/5 correctly so I have applied the series and pushed it in rtc-next. It will land in linux-next tomorrow so hopefully, this will see more testing.

Quoted 10 lines

NOTE2: there are additional fixes that linux-next seems to need but those are in omap-rtc, cpufreq etc, but those are not related by the ds-1307.

V1: https://patchwork.kernel.org/patch/4759171/

NOTE: Patch 5/5 of the series is meant to indicate the usage, and will be reposted along with other wakeup sources to be enabled once the driver changes are accepted.

I've left that one out so you can send it to the omap maintainers when ready.

Thanks!

Signature · 3 lines
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com