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

rtc: m41t80: add support for fixed clock

Congatec's QMX6 system on module (SoM) uses a m41t62 as RTC. The
modules SQW clock output defaults to 32768 Hz. This behaviour is
used to provide the i.MX6 CKIL clock. Once the RTC driver is probed,
the clock is disabled and all i.MX6 functionality depending on
the 32 KHz clock has undefined behaviour. For example when using
the hardware watchdog the system will likely do arbitrary reboots.

Referencing the m41t62 directly results in a deadlock. The kernel
will see, that i.MX6 system clock needs the RTC clock and do probe
deferral. But the i.MX6 I2C module never becomes usable without the
i.MX6 CKIL clock and thus the RTC's clock will not be probed. So
from the kernel's perspective this is a chicken-and-egg problem.

Technically everything is fine by not touching anything, since
the RTC clock correctly enables the clock on reset (i.e. on
battery backup power loss) and also the bootloader enables it
in case an something (e.g. an unpatched kernel) disabled this
incorrectly.

A workaround for this issue is describing the square wave pin
as fixed-clock, which is registered early and basically how
this pin is used on the i.MX6.

Suggested-by: Saravana Kannan <saravanak@google.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Reviewed-by: Saravana Kannan <saravanak@google.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210428222953.235280-2-sebastian.reichel@collabora.com

authored by

Sebastian Reichel and committed by
Alexandre Belloni
f765e349 b0ddc5b1

+21
+9
Documentation/devicetree/bindings/rtc/rtc-m41t80.txt
··· 21 21 clock name 22 22 - wakeup-source: Enables wake up of host system on alarm 23 23 24 + Optional child node: 25 + - clock: Provide this if the square wave pin is used as boot-enabled fixed clock. 26 + 24 27 Example: 25 28 rtc@68 { 26 29 compatible = "st,m41t80"; 27 30 reg = <0x68>; 28 31 interrupt-parent = <&UIC0>; 29 32 interrupts = <0x9 0x8>; 33 + 34 + clock { 35 + compatible = "fixed-clock"; 36 + #clock-cells = <0>; 37 + clock-frequency = <32768>; 38 + }; 30 39 };
+12
drivers/rtc/rtc-m41t80.c
··· 544 544 { 545 545 struct i2c_client *client = m41t80->client; 546 546 struct device_node *node = client->dev.of_node; 547 + struct device_node *fixed_clock; 547 548 struct clk *clk; 548 549 struct clk_init_data init; 549 550 int ret; 551 + 552 + fixed_clock = of_get_child_by_name(node, "clock"); 553 + if (fixed_clock) { 554 + /* 555 + * skip registering square wave clock when a fixed 556 + * clock has been registered. The fixed clock is 557 + * registered automatically when being referenced. 558 + */ 559 + of_node_put(fixed_clock); 560 + return 0; 561 + } 550 562 551 563 /* First disable the clock */ 552 564 ret = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON);