Commit f765e349 authored by Sebastian Reichel's avatar Sebastian Reichel Committed by Alexandre Belloni

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: default avatarSaravana Kannan <saravanak@google.com>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
Reviewed-by: default avatarSaravana Kannan <saravanak@google.com>
Reviewed-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarAlexandre Belloni <alexandre.belloni@bootlin.com>
Link: https://lore.kernel.org/r/20210428222953.235280-2-sebastian.reichel@collabora.com
parent b0ddc5b1
...@@ -21,10 +21,19 @@ Optional properties: ...@@ -21,10 +21,19 @@ Optional properties:
clock name clock name
- wakeup-source: Enables wake up of host system on alarm - wakeup-source: Enables wake up of host system on alarm
Optional child node:
- clock: Provide this if the square wave pin is used as boot-enabled fixed clock.
Example: Example:
rtc@68 { rtc@68 {
compatible = "st,m41t80"; compatible = "st,m41t80";
reg = <0x68>; reg = <0x68>;
interrupt-parent = <&UIC0>; interrupt-parent = <&UIC0>;
interrupts = <0x9 0x8>; interrupts = <0x9 0x8>;
clock {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <32768>;
};
}; };
...@@ -544,10 +544,22 @@ static struct clk *m41t80_sqw_register_clk(struct m41t80_data *m41t80) ...@@ -544,10 +544,22 @@ static struct clk *m41t80_sqw_register_clk(struct m41t80_data *m41t80)
{ {
struct i2c_client *client = m41t80->client; struct i2c_client *client = m41t80->client;
struct device_node *node = client->dev.of_node; struct device_node *node = client->dev.of_node;
struct device_node *fixed_clock;
struct clk *clk; struct clk *clk;
struct clk_init_data init; struct clk_init_data init;
int ret; int ret;
fixed_clock = of_get_child_by_name(node, "clock");
if (fixed_clock) {
/*
* skip registering square wave clock when a fixed
* clock has been registered. The fixed clock is
* registered automatically when being referenced.
*/
of_node_put(fixed_clock);
return 0;
}
/* First disable the clock */ /* First disable the clock */
ret = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON); ret = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON);
if (ret < 0) if (ret < 0)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment