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

rtc: rtc-isl12057: add isil,irq2-can-wakeup-machine property for in-tree users

Current in-tree users of ISL12057 RTC chip (NETGEAR ReadyNAS 102, 104 and
2120) do not have the IRQ#2 pin of the chip (associated w/ the Alarm1
mechanism) connected to their SoC, but to a PMIC (TPS65251 FWIW). This
specific hardware configuration allows the NAS to wake up when the alarms
rings.

Recently introduced alarm support for ISL12057 relies on the provision of
an "interrupts" property in system .dts file, which previous three users
will never get. For that reason, alarm support on those devices is not
function. To support this use case, this patch adds a new DT property for
ISL12057 (isil,irq2-can-wakeup-machine) to indicate that the chip is
capable of waking up the device using its IRQ#2 pin (even though it does
not have its IRQ#2 pin connected directly to the SoC).

This specific configuration was tested on a ReadyNAS 102 by setting an
alarm, powering off the device and see it reboot as expected when the
alarm rang w/:

# echo `date '+%s' -d '+ 1 minutes'` > /sys/class/rtc/rtc0/wakealarm
# shutdown -h now

As a side note, the ISL12057 remains in the list of trivial devices,
because the property is not per se required by the device to work but can
help handle system w/ specific requirements. In exchange, the new feature
is described in details in a specific documentation file.

Signed-off-by: Arnaud Ebalard <arno@natisbad.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Peter Huewe <peter.huewe@infineon.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Thierry Reding <treding@nvidia.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Darshana Padmadas <darshanapadmadas@gmail.com>
Cc: Rob Herring <rob.herring@calxeda.com>
Cc: Pawel Moll <pawel.moll@arm.com>
Cc: Stephen Warren <swarren@wwwdotorg.org>
Cc: Ian Campbell <ijc+devicetree@hellion.org.uk>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: Rob Landley <rob@landley.net>
Cc: Jason Cooper <jason@lakedaemon.net>
Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Jason Gunthorpe <jgunthorpe@obsidianresearch.com>
Cc: Kumar Gala <galak@codeaurora.org>
Cc: Uwe Kleine-König <uwe@kleine-koenig.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Arnaud Ebalard and committed by
Linus Torvalds
298ff012 fd71493d

+117 -6
+78
Documentation/devicetree/bindings/rtc/isil,isl12057.txt
··· 1 + Intersil ISL12057 I2C RTC/Alarm chip 2 + 3 + ISL12057 is a trivial I2C device (it has simple device tree bindings, 4 + consisting of a compatible field, an address and possibly an interrupt 5 + line). 6 + 7 + Nonetheless, it also supports an option boolean property 8 + ("isil,irq2-can-wakeup-machine") to handle the specific use-case found 9 + on at least three in-tree users of the chip (NETGEAR ReadyNAS 102, 104 10 + and 2120 ARM-based NAS); On those devices, the IRQ#2 pin of the chip 11 + (associated with the alarm supported by the driver) is not connected 12 + to the SoC but to a PMIC. It allows the device to be powered up when 13 + RTC alarm rings. In order to mark the device has a wakeup source and 14 + get access to the 'wakealarm' sysfs entry, this specific property can 15 + be set when the IRQ#2 pin of the chip is not connected to the SoC but 16 + can wake up the device. 17 + 18 + Required properties supported by the device: 19 + 20 + - "compatible": must be "isil,isl12057" 21 + - "reg": I2C bus address of the device 22 + 23 + Optional properties: 24 + 25 + - "isil,irq2-can-wakeup-machine": mark the chip as a wakeup source, 26 + independently of the availability of an IRQ line connected to the 27 + SoC. 28 + 29 + - "interrupt-parent", "interrupts": for passing the interrupt line 30 + of the SoC connected to IRQ#2 of the RTC chip. 31 + 32 + 33 + Example isl12057 node without IRQ#2 pin connected (no alarm support): 34 + 35 + isl12057: isl12057@68 { 36 + compatible = "isil,isl12057"; 37 + reg = <0x68>; 38 + }; 39 + 40 + 41 + Example isl12057 node with IRQ#2 pin connected to main SoC via MPP6 (note 42 + that the pinctrl-related properties below are given for completeness and 43 + may not be required or may be different depending on your system or 44 + SoC, and the main function of the MPP used as IRQ line, i.e. 45 + "interrupt-parent" and "interrupts" are usually sufficient): 46 + 47 + pinctrl { 48 + ... 49 + 50 + rtc_alarm_pin: rtc_alarm_pin { 51 + marvell,pins = "mpp6"; 52 + marvell,function = "gpio"; 53 + }; 54 + 55 + ... 56 + 57 + }; 58 + 59 + ... 60 + 61 + isl12057: isl12057@68 { 62 + compatible = "isil,isl12057"; 63 + reg = <0x68>; 64 + pinctrl-0 = <&rtc_alarm_pin>; 65 + pinctrl-names = "default"; 66 + interrupt-parent = <&gpio0>; 67 + interrupts = <6 IRQ_TYPE_EDGE_FALLING>; 68 + }; 69 + 70 + 71 + Example isl12057 node without IRQ#2 pin connected to the SoC but to a 72 + PMIC, allowing the device to be started based on configured alarm: 73 + 74 + isl12057: isl12057@68 { 75 + compatible = "isil,isl12057"; 76 + reg = <0x68>; 77 + isil,irq2-can-wakeup-machine; 78 + };
+39 -6
drivers/rtc/rtc-isl12057.c
··· 457 457 return 0; 458 458 } 459 459 460 + #ifdef CONFIG_OF 461 + /* 462 + * One would expect the device to be marked as a wakeup source only 463 + * when an IRQ pin of the RTC is routed to an interrupt line of the 464 + * CPU. In practice, such an IRQ pin can be connected to a PMIC and 465 + * this allows the device to be powered up when RTC alarm rings. This 466 + * is for instance the case on ReadyNAS 102, 104 and 2120. On those 467 + * devices with no IRQ driectly connected to the SoC, the RTC chip 468 + * can be forced as a wakeup source by stating that explicitly in 469 + * the device's .dts file using the "isil,irq2-can-wakeup-machine" 470 + * boolean property. This will guarantee 'wakealarm' sysfs entry is 471 + * available on the device. 472 + * 473 + * The function below returns 1, i.e. the capability of the chip to 474 + * wakeup the device, based on IRQ availability or if the boolean 475 + * property has been set in the .dts file. Otherwise, it returns 0. 476 + */ 477 + 478 + static bool isl12057_can_wakeup_machine(struct device *dev) 479 + { 480 + struct isl12057_rtc_data *data = dev_get_drvdata(dev); 481 + 482 + return (data->irq || of_property_read_bool(dev->of_node, 483 + "isil,irq2-can-wakeup-machine")); 484 + } 485 + #else 486 + static bool isl12057_can_wakeup_machine(struct device *dev) 487 + { 488 + struct isl12057_rtc_data *data = dev_get_drvdata(dev); 489 + 490 + return !!data->irq; 491 + } 492 + #endif 493 + 460 494 static int isl12057_rtc_alarm_irq_enable(struct device *dev, 461 495 unsigned int enable) 462 496 { ··· 589 555 client->irq, ret); 590 556 } 591 557 592 - device_init_wakeup(dev, !!data->irq); 558 + if (isl12057_can_wakeup_machine(dev)) 559 + device_init_wakeup(dev, true); 593 560 594 561 data->rtc = devm_rtc_device_register(dev, DRV_NAME, &rtc_ops, 595 562 THIS_MODULE); ··· 611 576 612 577 static int isl12057_remove(struct i2c_client *client) 613 578 { 614 - struct isl12057_rtc_data *rtc_data = dev_get_drvdata(&client->dev); 615 - 616 - if (rtc_data->irq) 579 + if (isl12057_can_wakeup_machine(&client->dev)) 617 580 device_init_wakeup(&client->dev, false); 618 581 619 582 return 0; ··· 622 589 { 623 590 struct isl12057_rtc_data *rtc_data = dev_get_drvdata(dev); 624 591 625 - if (device_may_wakeup(dev)) 592 + if (rtc_data->irq && device_may_wakeup(dev)) 626 593 return enable_irq_wake(rtc_data->irq); 627 594 628 595 return 0; ··· 632 599 { 633 600 struct isl12057_rtc_data *rtc_data = dev_get_drvdata(dev); 634 601 635 - if (device_may_wakeup(dev)) 602 + if (rtc_data->irq && device_may_wakeup(dev)) 636 603 return disable_irq_wake(rtc_data->irq); 637 604 638 605 return 0;