Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 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")

Signed-off-by: Nishanth Menon <nm@ti.com>
Reviewed-by: Grygorii Strashko <grygorii.strashko@ti.com>
Acked-by: Tony Lindgren <tony@atomide.com>
Acked-by: Felipe Balbi <balbi@ti.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

authored by

Nishanth Menon and committed by
Alexandre Belloni
7abea617 eac7237f

+33 -3
+33 -3
drivers/rtc/rtc-ds1307.c
··· 15 15 #include <linux/i2c.h> 16 16 #include <linux/init.h> 17 17 #include <linux/module.h> 18 + #include <linux/of_device.h> 19 + #include <linux/of_irq.h> 20 + #include <linux/pm_wakeirq.h> 18 21 #include <linux/rtc/ds1307.h> 19 22 #include <linux/rtc.h> 20 23 #include <linux/slab.h> ··· 117 114 #define HAS_ALARM 1 /* bit 1 == irq claimed */ 118 115 struct i2c_client *client; 119 116 struct rtc_device *rtc; 117 + int wakeirq; 120 118 s32 (*read_block_data)(const struct i2c_client *client, u8 command, 121 119 u8 length, u8 *values); 122 120 s32 (*write_block_data)(const struct i2c_client *client, u8 command, ··· 1160 1156 } 1161 1157 1162 1158 if (want_irq) { 1159 + struct device_node *node = client->dev.of_node; 1160 + 1163 1161 err = devm_request_threaded_irq(&client->dev, 1164 1162 client->irq, NULL, irq_handler, 1165 1163 IRQF_SHARED | IRQF_ONESHOT, ··· 1169 1163 if (err) { 1170 1164 client->irq = 0; 1171 1165 dev_err(&client->dev, "unable to request IRQ!\n"); 1172 - } else { 1166 + goto no_irq; 1167 + } 1173 1168 1174 - set_bit(HAS_ALARM, &ds1307->flags); 1175 - dev_dbg(&client->dev, "got IRQ %d\n", client->irq); 1169 + set_bit(HAS_ALARM, &ds1307->flags); 1170 + dev_dbg(&client->dev, "got IRQ %d\n", client->irq); 1171 + 1172 + /* Currently supported by OF code only! */ 1173 + if (!node) 1174 + goto no_irq; 1175 + 1176 + err = of_irq_get(node, 1); 1177 + if (err <= 0) { 1178 + if (err == -EPROBE_DEFER) 1179 + goto exit; 1180 + goto no_irq; 1181 + } 1182 + ds1307->wakeirq = err; 1183 + 1184 + err = dev_pm_set_dedicated_wake_irq(&client->dev, 1185 + ds1307->wakeirq); 1186 + if (err) { 1187 + dev_err(&client->dev, "unable to setup wakeIRQ %d!\n", 1188 + err); 1189 + goto exit; 1176 1190 } 1177 1191 } 1178 1192 1193 + no_irq: 1179 1194 if (chip->nvram_size) { 1180 1195 1181 1196 ds1307->nvram = devm_kzalloc(&client->dev, ··· 1239 1212 static int ds1307_remove(struct i2c_client *client) 1240 1213 { 1241 1214 struct ds1307 *ds1307 = i2c_get_clientdata(client); 1215 + 1216 + if (ds1307->wakeirq) 1217 + dev_pm_clear_wake_irq(&client->dev); 1242 1218 1243 1219 if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags)) 1244 1220 sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram);