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

rtc: sa1100/pxa: convert to run-time register mapping

SA1100 and PXA differ only in register offsets which are currently
hardcoded in a machine specific header. Some arm64 platforms (PXA1928)
have this RTC block as well (and not the PXA270 variant).

Convert the driver to use ioremap and set the register offsets dynamically.
Since we are touching all the register accesses, convert them all to
readl_relaxed/writel_relaxed.

Signed-off-by: Rob Herring <robh@kernel.org>
Acked-by: Robert Jarzmik <robert.jarzmik@free.fr>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Cc: rtc-linux@googlegroups.com
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>

authored by

Rob Herring and committed by
Alexandre Belloni
90d0ae8e 2c4fabec

+63 -27
+4
drivers/rtc/rtc-pxa.c
··· 356 356 return -ENOMEM; 357 357 } 358 358 359 + sa1100_rtc->rcnr = pxa_rtc->base + 0x0; 360 + sa1100_rtc->rtsr = pxa_rtc->base + 0x8; 361 + sa1100_rtc->rtar = pxa_rtc->base + 0x4; 362 + sa1100_rtc->rttr = pxa_rtc->base + 0xc; 359 363 ret = sa1100_rtc_init(pdev, sa1100_rtc); 360 364 if (!ret) { 361 365 dev_err(dev, "Unable to init SA1100 RTC sub-device\n");
+55 -27
drivers/rtc/rtc-sa1100.c
··· 35 35 #include <linux/bitops.h> 36 36 #include <linux/io.h> 37 37 38 - #include <mach/hardware.h> 39 - #include <mach/irqs.h> 40 - 41 - #if defined(CONFIG_ARCH_PXA) || defined(CONFIG_ARCH_MMP) 42 - #include <mach/regs-rtc.h> 43 - #endif 38 + #define RTSR_HZE BIT(3) /* HZ interrupt enable */ 39 + #define RTSR_ALE BIT(2) /* RTC alarm interrupt enable */ 40 + #define RTSR_HZ BIT(1) /* HZ rising-edge detected */ 41 + #define RTSR_AL BIT(0) /* RTC alarm detected */ 44 42 45 43 #include "rtc-sa1100.h" 46 44 ··· 56 58 57 59 spin_lock(&info->lock); 58 60 59 - rtsr = RTSR; 61 + rtsr = readl_relaxed(info->rtsr); 60 62 /* clear interrupt sources */ 61 - RTSR = 0; 63 + writel_relaxed(0, info->rtsr); 62 64 /* Fix for a nasty initialization problem the in SA11xx RTSR register. 63 65 * See also the comments in sa1100_rtc_probe(). */ 64 66 if (rtsr & (RTSR_ALE | RTSR_HZE)) { 65 67 /* This is the original code, before there was the if test 66 68 * above. This code does not clear interrupts that were not 67 69 * enabled. */ 68 - RTSR = (RTSR_AL | RTSR_HZ) & (rtsr >> 2); 70 + writel_relaxed((RTSR_AL | RTSR_HZ) & (rtsr >> 2), info->rtsr); 69 71 } else { 70 72 /* For some reason, it is possible to enter this routine 71 73 * without interruptions enabled, it has been tested with ··· 74 76 * This situation leads to an infinite "loop" of interrupt 75 77 * routine calling and as a result the processor seems to 76 78 * lock on its first call to open(). */ 77 - RTSR = RTSR_AL | RTSR_HZ; 79 + writel_relaxed(RTSR_AL | RTSR_HZ, info->rtsr); 78 80 } 79 81 80 82 /* clear alarm interrupt if it has occurred */ 81 83 if (rtsr & RTSR_AL) 82 84 rtsr &= ~RTSR_ALE; 83 - RTSR = rtsr & (RTSR_ALE | RTSR_HZE); 85 + writel_relaxed(rtsr & (RTSR_ALE | RTSR_HZE), info->rtsr); 84 86 85 87 /* update irq data & counter */ 86 88 if (rtsr & RTSR_AL) ··· 128 130 struct sa1100_rtc *info = dev_get_drvdata(dev); 129 131 130 132 spin_lock_irq(&info->lock); 131 - RTSR = 0; 133 + writel_relaxed(0, info->rtsr); 132 134 spin_unlock_irq(&info->lock); 133 135 134 136 free_irq(info->irq_alarm, dev); ··· 137 139 138 140 static int sa1100_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) 139 141 { 142 + u32 rtsr; 140 143 struct sa1100_rtc *info = dev_get_drvdata(dev); 141 144 142 145 spin_lock_irq(&info->lock); 146 + rtsr = readl_relaxed(info->rtsr); 143 147 if (enabled) 144 - RTSR |= RTSR_ALE; 148 + rtsr |= RTSR_ALE; 145 149 else 146 - RTSR &= ~RTSR_ALE; 150 + rtsr &= ~RTSR_ALE; 151 + writel_relaxed(rtsr, info->rtsr); 147 152 spin_unlock_irq(&info->lock); 148 153 return 0; 149 154 } 150 155 151 156 static int sa1100_rtc_read_time(struct device *dev, struct rtc_time *tm) 152 157 { 153 - rtc_time_to_tm(RCNR, tm); 158 + struct sa1100_rtc *info = dev_get_drvdata(dev); 159 + 160 + rtc_time_to_tm(readl_relaxed(info->rcnr), tm); 154 161 return 0; 155 162 } 156 163 157 164 static int sa1100_rtc_set_time(struct device *dev, struct rtc_time *tm) 158 165 { 166 + struct sa1100_rtc *info = dev_get_drvdata(dev); 159 167 unsigned long time; 160 168 int ret; 161 169 162 170 ret = rtc_tm_to_time(tm, &time); 163 171 if (ret == 0) 164 - RCNR = time; 172 + writel_relaxed(time, info->rcnr); 165 173 return ret; 166 174 } 167 175 168 176 static int sa1100_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) 169 177 { 170 178 u32 rtsr; 179 + struct sa1100_rtc *info = dev_get_drvdata(dev); 171 180 172 - rtsr = RTSR; 181 + rtsr = readl_relaxed(info->rtsr); 173 182 alrm->enabled = (rtsr & RTSR_ALE) ? 1 : 0; 174 183 alrm->pending = (rtsr & RTSR_AL) ? 1 : 0; 175 184 return 0; ··· 192 187 ret = rtc_tm_to_time(&alrm->time, &time); 193 188 if (ret != 0) 194 189 goto out; 195 - RTSR = RTSR & (RTSR_HZE|RTSR_ALE|RTSR_AL); 196 - RTAR = time; 190 + writel_relaxed(readl_relaxed(info->rtsr) & 191 + (RTSR_HZE | RTSR_ALE | RTSR_AL), info->rtsr); 192 + writel_relaxed(time, info->rtar); 197 193 if (alrm->enabled) 198 - RTSR |= RTSR_ALE; 194 + writel_relaxed(readl_relaxed(info->rtsr) | RTSR_ALE, info->rtsr); 199 195 else 200 - RTSR &= ~RTSR_ALE; 196 + writel_relaxed(readl_relaxed(info->rtsr) & ~RTSR_ALE, info->rtsr); 201 197 out: 202 198 spin_unlock_irq(&info->lock); 203 199 ··· 207 201 208 202 static int sa1100_rtc_proc(struct device *dev, struct seq_file *seq) 209 203 { 210 - seq_printf(seq, "trim/divider\t\t: 0x%08x\n", (u32) RTTR); 211 - seq_printf(seq, "RTSR\t\t\t: 0x%08x\n", (u32)RTSR); 204 + struct sa1100_rtc *info = dev_get_drvdata(dev); 205 + 206 + seq_printf(seq, "trim/divider\t\t: 0x%08x\n", readl_relaxed(info->rttr)); 207 + seq_printf(seq, "RTSR\t\t\t: 0x%08x\n", readl_relaxed(info->rtsr)); 212 208 213 209 return 0; 214 210 } ··· 249 241 * If the clock divider is uninitialized then reset it to the 250 242 * default value to get the 1Hz clock. 251 243 */ 252 - if (RTTR == 0) { 253 - RTTR = RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16); 244 + if (readl_relaxed(info->rttr) == 0) { 245 + writel_relaxed(RTC_DEF_DIVIDER + (RTC_DEF_TRIM << 16), info->rttr); 254 246 dev_warn(&pdev->dev, "warning: " 255 247 "initializing default clock divider/trim value\n"); 256 248 /* The current RTC value probably doesn't make sense either */ 257 - RCNR = 0; 249 + writel_relaxed(0, info->rcnr); 258 250 } 259 251 260 252 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &sa1100_rtc_ops, ··· 287 279 * 288 280 * Notice that clearing bit 1 and 0 is accomplished by writting ONES to 289 281 * the corresponding bits in RTSR. */ 290 - RTSR = RTSR_AL | RTSR_HZ; 282 + writel_relaxed(RTSR_AL | RTSR_HZ, info->rtsr); 291 283 292 284 return 0; 293 285 } ··· 296 288 static int sa1100_rtc_probe(struct platform_device *pdev) 297 289 { 298 290 struct sa1100_rtc *info; 291 + struct resource *iores; 292 + void __iomem *base; 299 293 int irq_1hz, irq_alarm; 300 294 301 295 irq_1hz = platform_get_irq_byname(pdev, "rtc 1Hz"); ··· 310 300 return -ENOMEM; 311 301 info->irq_1hz = irq_1hz; 312 302 info->irq_alarm = irq_alarm; 303 + 304 + iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); 305 + base = devm_ioremap_resource(&pdev->dev, iores); 306 + if (IS_ERR(base)) 307 + return PTR_ERR(base); 308 + 309 + if (IS_ENABLED(CONFIG_ARCH_SA1100) || 310 + of_device_is_compatible(pdev->dev.of_node, "mrvl,sa1100-rtc")) { 311 + info->rcnr = base + 0x04; 312 + info->rtsr = base + 0x10; 313 + info->rtar = base + 0x00; 314 + info->rttr = base + 0x08; 315 + } else { 316 + info->rcnr = base + 0x0; 317 + info->rtsr = base + 0x8; 318 + info->rtar = base + 0x4; 319 + info->rttr = base + 0xc; 320 + } 313 321 314 322 platform_set_drvdata(pdev, info); 315 323 device_init_wakeup(&pdev->dev, 1);
+4
drivers/rtc/rtc-sa1100.h
··· 8 8 9 9 struct sa1100_rtc { 10 10 spinlock_t lock; 11 + void __iomem *rcnr; 12 + void __iomem *rtar; 13 + void __iomem *rtsr; 14 + void __iomem *rttr; 11 15 int irq_1hz; 12 16 int irq_alarm; 13 17 struct rtc_device *rtc;