All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch added to 3.12-stable] rtc: tegra: Implement clock handling
@ 2017-05-03 12:22 Jiri Slaby
  2017-05-03 12:22 ` [patch added to 3.12-stable] mm: Tighten x86 /dev/mem with zeroing reads Jiri Slaby
                   ` (47 more replies)
  0 siblings, 48 replies; 52+ messages in thread
From: Jiri Slaby @ 2017-05-03 12:22 UTC (permalink / raw)
  To: stable; +Cc: Thierry Reding, Alexandre Belloni, Ben Hutchings, Jiri Slaby

From: Thierry Reding <treding@nvidia.com>

This patch has been added to the 3.12 stable tree. If you have any
objections, please let us know.

===============

commit 5fa4086987506b2ab8c92f8f99f2295db9918856 upstream.

Accessing the registers of the RTC block on Tegra requires the module
clock to be enabled. This only works because the RTC module clock will
be enabled by default during early boot. However, because the clock is
unused, the CCF will disable it at late_init time. This causes the RTC
to become unusable afterwards. This can easily be reproduced by trying
to use the RTC:

	$ hwclock --rtc /dev/rtc1

This will hang the system. I ran into this by following up on a report
by Martin Michlmayr that reboot wasn't working on Tegra210 systems. It
turns out that the rtc-tegra driver's ->shutdown() implementation will
hang the CPU, because of the disabled clock, before the system can be
rebooted.

What confused me for a while is that the same driver is used on prior
Tegra generations where the hang can not be observed. However, as Peter
De Schrijver pointed out, this is because on 32-bit Tegra chips the RTC
clock is enabled by the tegra20_timer.c clocksource driver, which uses
the RTC to provide a persistent clock. This code is never enabled on
64-bit Tegra because the persistent clock infrastructure does not exist
on 64-bit ARM.

The proper fix for this is to add proper clock handling to the RTC
driver in order to ensure that the clock is enabled when the driver
requires it. All device trees contain the clock already, therefore
no additional changes are required.

Reported-by: Martin Michlmayr <tbm@cyrius.com>
Acked-By Peter De Schrijver <pdeschrijver@nvidia.com>
Signed-off-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
[bwh: Backported to 4.9: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 drivers/rtc/rtc-tegra.c | 28 ++++++++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/drivers/rtc/rtc-tegra.c b/drivers/rtc/rtc-tegra.c
index 76af92ad5a8a..1a79a5f20f67 100644
--- a/drivers/rtc/rtc-tegra.c
+++ b/drivers/rtc/rtc-tegra.c
@@ -18,6 +18,7 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 #include <linux/kernel.h>
+#include <linux/clk.h>
 #include <linux/init.h>
 #include <linux/module.h>
 #include <linux/slab.h>
@@ -59,6 +60,7 @@ struct tegra_rtc_info {
 	struct platform_device	*pdev;
 	struct rtc_device	*rtc_dev;
 	void __iomem		*rtc_base; /* NULL if not initialized. */
+	struct clk		*clk;
 	int			tegra_rtc_irq; /* alarm and periodic irq */
 	spinlock_t		tegra_rtc_lock;
 };
@@ -330,6 +332,14 @@ static int __init tegra_rtc_probe(struct platform_device *pdev)
 	if (info->tegra_rtc_irq <= 0)
 		return -EBUSY;
 
+	info->clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(info->clk))
+		return PTR_ERR(info->clk);
+
+	ret = clk_prepare_enable(info->clk);
+	if (ret < 0)
+		return ret;
+
 	/* set context info. */
 	info->pdev = pdev;
 	spin_lock_init(&info->tegra_rtc_lock);
@@ -350,7 +360,7 @@ static int __init tegra_rtc_probe(struct platform_device *pdev)
 		ret = PTR_ERR(info->rtc_dev);
 		dev_err(&pdev->dev, "Unable to register device (err=%d).\n",
 			ret);
-		return ret;
+		goto disable_clk;
 	}
 
 	ret = devm_request_irq(&pdev->dev, info->tegra_rtc_irq,
@@ -360,12 +370,25 @@ static int __init tegra_rtc_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev,
 			"Unable to request interrupt for device (err=%d).\n",
 			ret);
-		return ret;
+		goto disable_clk;
 	}
 
 	dev_notice(&pdev->dev, "Tegra internal Real Time Clock\n");
 
 	return 0;
+
+disable_clk:
+	clk_disable_unprepare(info->clk);
+	return ret;
+}
+
+static int tegra_rtc_remove(struct platform_device *pdev)
+{
+	struct tegra_rtc_info *info = platform_get_drvdata(pdev);
+
+	clk_disable_unprepare(info->clk);
+
+	return 0;
 }
 
 #ifdef CONFIG_PM_SLEEP
@@ -417,6 +440,7 @@ static void tegra_rtc_shutdown(struct platform_device *pdev)
 
 MODULE_ALIAS("platform:tegra_rtc");
 static struct platform_driver tegra_rtc_driver = {
+	.remove		= tegra_rtc_remove,
 	.shutdown	= tegra_rtc_shutdown,
 	.driver		= {
 		.name	= "tegra_rtc",
-- 
2.12.2

^ permalink raw reply related	[flat|nested] 52+ messages in thread

end of thread, other threads:[~2017-05-03 13:31 UTC | newest]

Thread overview: 52+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-03 12:22 [patch added to 3.12-stable] rtc: tegra: Implement clock handling Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] mm: Tighten x86 /dev/mem with zeroing reads Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] virtio-console: avoid DMA from stack Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] pegasus: Use heap buffers for all register access Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] rtl8150: " Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] catc: Combine failure cleanup code in catc_probe() Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] catc: Use heap buffer for memory size test Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] net: ipv6: check route protocol when deleting routes Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] KEYS: Disallow keyrings beginning with '.' to be joined as session keyrings Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] KEYS: Change the name of the dead type to ".dead" to prevent user access Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] KEYS: fix keyctl_set_reqkey_keyring() to not leak thread keyrings Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] tracing: Allocate the snapshot buffer before enabling probe Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] ring-buffer: Have ring_buffer_iter_empty() return true when empty Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] cifs: Do not send echoes before Negotiate is complete Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] CIFS: remove bad_network_name flag Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] Drivers: hv: don't leak memory in vmbus_establish_gpadl() Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] Drivers: hv: get rid of timeout in vmbus_open() Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] Input: elantech - add Fujitsu Lifebook E547 to force crc_enabled Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] ACPI / power: Avoid maybe-uninitialized warning Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] ubi/upd: Always flush after prepared for an update Jiri Slaby
2017-05-03 12:22 ` [patch added to 3.12-stable] x86/mce/AMD: Give a name to MCA bank 3 when accessed with legacy MSRs Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] kvm: arm/arm64: Fix locking for kvm_free_stage2_pgd Jiri Slaby
2017-05-03 12:39   ` Suzuki K Poulose
2017-05-03 13:21     ` Jiri Slaby
2017-05-03 13:31       ` Suzuki K Poulose
2017-05-03 12:23 ` [patch added to 3.12-stable] block: fix del_gendisk() vs blkdev_ioctl crash Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] powerpc: Reject binutils 2.24 when building little endian Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] ping: implement proper locking Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] net/packet: fix overflow in check for tp_frame_nr Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] net/packet: fix overflow in check for tp_reserve Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] netfilter: arp_tables: fix invoking 32bit "iptable -P INPUT ACCEPT" failed in 64bit kernel Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] tty: nozomi: avoid a harmless gcc warning Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] hostap: avoid uninitialized variable use in hfa384x_get_rid Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] gfs2: avoid uninitialized variable warning Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] net: neigh: guard against NULL solicit() method Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] net: phy: handle state correctly in phy_stop_machine Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] l2tp: take reference on sessions being dumped Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] net: ipv4: fix multipath RTM_GETROUTE behavior when iif is given Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] sctp: listen on the sock only when it's state is listening or closed Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] ip6mr: fix notification device destruction Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] ipv6: check raw payload size correctly in ioctl Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] ext4: check if in-inode xattr is corrupted in ext4_expand_extra_isize_ea() Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] md:raid1: fix a dead loop when read from a WriteMostly disk Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] MIPS: Fix crash registers on non-crashing CPUs Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] RDS: Fix the atomicity for congestion map update Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] xen/x86: don't lose event interrupts Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] ALSA: seq: Don't break snd_use_lock_sync() loop by timeout Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] MIPS: KGDB: Use kernel context for sleeping threads Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] p9_client_readdir() fix Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] Input: i8042 - add Clevo P650RS to the i8042 reset list Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] nfsd: check for oversized NFSv2/v3 arguments Jiri Slaby
2017-05-03 12:23 ` [patch added to 3.12-stable] ftrace/x86: Fix triple fault with graph tracing and suspend-to-ram Jiri Slaby

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.