Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7abea617 authored by Nishanth Menon's avatar Nishanth Menon Committed by Alexandre Belloni
Browse files

rtc: ds1307: 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 4990d4fe ("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 2a0b965c ("serial: omap: Add
support for optional wake-up") + ee83bd3b ("serial: omap: Switch
wake-up interrupt to generic wakeirq")

Signed-off-by: default avatarNishanth Menon <nm@ti.com>
Reviewed-by: default avatarGrygorii Strashko <grygorii.strashko@ti.com>
Acked-by: default avatarTony Lindgren <tony@atomide.com>
Acked-by: default avatarFelipe Balbi <balbi@ti.com>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@free-electrons.com>
parent eac7237f
Loading
Loading
Loading
Loading
+33 −3
Original line number Original line Diff line number Diff line
@@ -15,6 +15,9 @@
#include <linux/i2c.h>
#include <linux/i2c.h>
#include <linux/init.h>
#include <linux/init.h>
#include <linux/module.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/ds1307.h>
#include <linux/rtc.h>
#include <linux/rtc.h>
#include <linux/slab.h>
#include <linux/slab.h>
@@ -114,6 +117,7 @@ struct ds1307 {
#define HAS_ALARM	1		/* bit 1 == irq claimed */
#define HAS_ALARM	1		/* bit 1 == irq claimed */
	struct i2c_client	*client;
	struct i2c_client	*client;
	struct rtc_device	*rtc;
	struct rtc_device	*rtc;
	int			wakeirq;
	s32 (*read_block_data)(const struct i2c_client *client, u8 command,
	s32 (*read_block_data)(const struct i2c_client *client, u8 command,
			       u8 length, u8 *values);
			       u8 length, u8 *values);
	s32 (*write_block_data)(const struct i2c_client *client, u8 command,
	s32 (*write_block_data)(const struct i2c_client *client, u8 command,
@@ -1156,6 +1160,8 @@ static int ds1307_probe(struct i2c_client *client,
	}
	}


	if (want_irq) {
	if (want_irq) {
		struct device_node *node = client->dev.of_node;

		err = devm_request_threaded_irq(&client->dev,
		err = devm_request_threaded_irq(&client->dev,
						client->irq, NULL, irq_handler,
						client->irq, NULL, irq_handler,
						IRQF_SHARED | IRQF_ONESHOT,
						IRQF_SHARED | IRQF_ONESHOT,
@@ -1163,13 +1169,34 @@ static int ds1307_probe(struct i2c_client *client,
		if (err) {
		if (err) {
			client->irq = 0;
			client->irq = 0;
			dev_err(&client->dev, "unable to request IRQ!\n");
			dev_err(&client->dev, "unable to request IRQ!\n");
		} else {
			goto no_irq;
		}


		set_bit(HAS_ALARM, &ds1307->flags);
		set_bit(HAS_ALARM, &ds1307->flags);
		dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
		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) {
	if (chip->nvram_size) {


		ds1307->nvram = devm_kzalloc(&client->dev,
		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);
	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))
	if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags))
		sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram);
		sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram);