16de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold/* 26de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * sysirq_mask.c - System-interrupt masking 36de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * 46de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * Copyright (C) 2013 Johan Hovold <jhovold@gmail.com> 56de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * 66de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * Functions to disable system interrupts from backup-powered peripherals. 76de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * 86de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * The RTC and RTT-peripherals are generally powered by backup power (VDDBU) 96de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * and are not reset on wake-up, user, watchdog or software reset. This means 106de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * that their interrupts may be enabled during early boot (e.g. after a user 116de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * reset). 126de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * 136de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * As the RTC and RTT share the system-interrupt line with the PIT, an 146de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * interrupt occurring before a handler has been installed would lead to the 156de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * system interrupt being disabled and prevent the system from booting. 166de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * 176de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * This program is free software; you can redistribute it and/or modify 186de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * it under the terms of the GNU General Public License as published by 196de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * the Free Software Foundation; either version 2 of the License, or 206de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold * (at your option) any later version. 216de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold */ 226de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold 236de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold#include <linux/io.h> 2494c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold#include <mach/at91_rtt.h> 256de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold 266de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold#include "generic.h" 276de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold 289dcc87fec8947308e0111c65dcd881e6aa5b1673Boris BREZILLON#define AT91_RTC_IDR 0x24 /* Interrupt Disable Register */ 299dcc87fec8947308e0111c65dcd881e6aa5b1673Boris BREZILLON#define AT91_RTC_IMR 0x28 /* Interrupt Mask Register */ 309dcc87fec8947308e0111c65dcd881e6aa5b1673Boris BREZILLON#define AT91_RTC_IRQ_MASK 0x1f /* Available IRQs mask */ 316de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold 326de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovoldvoid __init at91_sysirq_mask_rtc(u32 rtc_base) 336de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold{ 346de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold void __iomem *base; 356de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold 366de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold base = ioremap(rtc_base, 64); 376de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold if (!base) 386de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold return; 396de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold 409dcc87fec8947308e0111c65dcd881e6aa5b1673Boris BREZILLON /* 419dcc87fec8947308e0111c65dcd881e6aa5b1673Boris BREZILLON * sam9x5 SoCs have the following errata: 429dcc87fec8947308e0111c65dcd881e6aa5b1673Boris BREZILLON * "RTC: Interrupt Mask Register cannot be used 439dcc87fec8947308e0111c65dcd881e6aa5b1673Boris BREZILLON * Interrupt Mask Register read always returns 0." 449dcc87fec8947308e0111c65dcd881e6aa5b1673Boris BREZILLON * 459dcc87fec8947308e0111c65dcd881e6aa5b1673Boris BREZILLON * Hence we're not relying on IMR values to disable 469dcc87fec8947308e0111c65dcd881e6aa5b1673Boris BREZILLON * interrupts. 479dcc87fec8947308e0111c65dcd881e6aa5b1673Boris BREZILLON */ 489dcc87fec8947308e0111c65dcd881e6aa5b1673Boris BREZILLON writel_relaxed(AT91_RTC_IRQ_MASK, base + AT91_RTC_IDR); 499dcc87fec8947308e0111c65dcd881e6aa5b1673Boris BREZILLON (void)readl_relaxed(base + AT91_RTC_IMR); /* flush */ 506de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold 516de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold iounmap(base); 526de714c21a8ea315fffba6a93bbe537f4c1bf4f0Johan Hovold} 5394c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold 5494c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovoldvoid __init at91_sysirq_mask_rtt(u32 rtt_base) 5594c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold{ 5694c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold void __iomem *base; 5794c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold void __iomem *reg; 5894c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold u32 mode; 5994c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold 6094c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold base = ioremap(rtt_base, 16); 6194c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold if (!base) 6294c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold return; 6394c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold 6494c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold reg = base + AT91_RTT_MR; 6594c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold 6694c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold mode = readl_relaxed(reg); 6794c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold if (mode & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)) { 6894c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold pr_info("AT91: Disabling rtt irq\n"); 6994c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold mode &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN); 7094c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold writel_relaxed(mode, reg); 7194c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold (void)readl_relaxed(reg); /* flush */ 7294c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold } 7394c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold 7494c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold iounmap(base); 7594c4c79f2f1acca6e69a50bff5a7d9027509c16bJohan Hovold} 76