David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * TI OMAP1 Real Time Clock interface for Linux |
| 3 | * |
| 4 | * Copyright (C) 2003 MontaVista Software, Inc. |
| 5 | * Author: George G. Davis <gdavis@mvista.com> or <source@mvista.com> |
| 6 | * |
| 7 | * Copyright (C) 2006 David Brownell (new RTC framework) |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or |
| 10 | * modify it under the terms of the GNU General Public License |
| 11 | * as published by the Free Software Foundation; either version |
| 12 | * 2 of the License, or (at your option) any later version. |
| 13 | */ |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/ioport.h> |
| 19 | #include <linux/delay.h> |
| 20 | #include <linux/rtc.h> |
| 21 | #include <linux/bcd.h> |
| 22 | #include <linux/platform_device.h> |
Afzal Mohammed | 9e0344d | 2012-12-17 16:02:15 -0800 | [diff] [blame] | 23 | #include <linux/of.h> |
| 24 | #include <linux/of_device.h> |
Vaibhav Hiremath | fc9bd90 | 2012-12-17 16:02:18 -0800 | [diff] [blame] | 25 | #include <linux/pm_runtime.h> |
Sachin Kamat | 4b30c9f | 2013-07-03 15:06:00 -0700 | [diff] [blame] | 26 | #include <linux/io.h> |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 27 | |
| 28 | /* The OMAP1 RTC is a year/month/day/hours/minutes/seconds BCD clock |
| 29 | * with century-range alarm matching, driven by the 32kHz clock. |
| 30 | * |
| 31 | * The main user-visible ways it differs from PC RTCs are by omitting |
| 32 | * "don't care" alarm fields and sub-second periodic IRQs, and having |
| 33 | * an autoadjust mechanism to calibrate to the true oscillator rate. |
| 34 | * |
| 35 | * Board-specific wiring options include using split power mode with |
| 36 | * RTC_OFF_NOFF used as the reset signal (so the RTC won't be reset), |
| 37 | * and wiring RTC_WAKE_INT (so the RTC alarm can wake the system from |
Sekhar Nori | fa5b078 | 2010-10-27 15:33:05 -0700 | [diff] [blame] | 38 | * low power modes) for OMAP1 boards (OMAP-L138 has this built into |
| 39 | * the SoC). See the BOARD-SPECIFIC CUSTOMIZATION comment. |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 40 | */ |
| 41 | |
Afzal Mohammed | cab1458 | 2012-12-17 16:02:11 -0800 | [diff] [blame] | 42 | #define DRIVER_NAME "omap_rtc" |
| 43 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 44 | /* RTC registers */ |
| 45 | #define OMAP_RTC_SECONDS_REG 0x00 |
| 46 | #define OMAP_RTC_MINUTES_REG 0x04 |
| 47 | #define OMAP_RTC_HOURS_REG 0x08 |
| 48 | #define OMAP_RTC_DAYS_REG 0x0C |
| 49 | #define OMAP_RTC_MONTHS_REG 0x10 |
| 50 | #define OMAP_RTC_YEARS_REG 0x14 |
| 51 | #define OMAP_RTC_WEEKS_REG 0x18 |
| 52 | |
| 53 | #define OMAP_RTC_ALARM_SECONDS_REG 0x20 |
| 54 | #define OMAP_RTC_ALARM_MINUTES_REG 0x24 |
| 55 | #define OMAP_RTC_ALARM_HOURS_REG 0x28 |
| 56 | #define OMAP_RTC_ALARM_DAYS_REG 0x2c |
| 57 | #define OMAP_RTC_ALARM_MONTHS_REG 0x30 |
| 58 | #define OMAP_RTC_ALARM_YEARS_REG 0x34 |
| 59 | |
| 60 | #define OMAP_RTC_CTRL_REG 0x40 |
| 61 | #define OMAP_RTC_STATUS_REG 0x44 |
| 62 | #define OMAP_RTC_INTERRUPTS_REG 0x48 |
| 63 | |
| 64 | #define OMAP_RTC_COMP_LSB_REG 0x4c |
| 65 | #define OMAP_RTC_COMP_MSB_REG 0x50 |
| 66 | #define OMAP_RTC_OSC_REG 0x54 |
| 67 | |
Afzal Mohammed | cab1458 | 2012-12-17 16:02:11 -0800 | [diff] [blame] | 68 | #define OMAP_RTC_KICK0_REG 0x6c |
| 69 | #define OMAP_RTC_KICK1_REG 0x70 |
| 70 | |
Hebbar Gururaja | 8af750e | 2013-09-11 14:24:18 -0700 | [diff] [blame] | 71 | #define OMAP_RTC_IRQWAKEEN 0x7c |
| 72 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 73 | /* OMAP_RTC_CTRL_REG bit fields: */ |
Sekhar Nori | 92adb96 | 2014-06-06 14:36:05 -0700 | [diff] [blame] | 74 | #define OMAP_RTC_CTRL_SPLIT BIT(7) |
| 75 | #define OMAP_RTC_CTRL_DISABLE BIT(6) |
| 76 | #define OMAP_RTC_CTRL_SET_32_COUNTER BIT(5) |
| 77 | #define OMAP_RTC_CTRL_TEST BIT(4) |
| 78 | #define OMAP_RTC_CTRL_MODE_12_24 BIT(3) |
| 79 | #define OMAP_RTC_CTRL_AUTO_COMP BIT(2) |
| 80 | #define OMAP_RTC_CTRL_ROUND_30S BIT(1) |
| 81 | #define OMAP_RTC_CTRL_STOP BIT(0) |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 82 | |
| 83 | /* OMAP_RTC_STATUS_REG bit fields: */ |
Sekhar Nori | 92adb96 | 2014-06-06 14:36:05 -0700 | [diff] [blame] | 84 | #define OMAP_RTC_STATUS_POWER_UP BIT(7) |
| 85 | #define OMAP_RTC_STATUS_ALARM BIT(6) |
| 86 | #define OMAP_RTC_STATUS_1D_EVENT BIT(5) |
| 87 | #define OMAP_RTC_STATUS_1H_EVENT BIT(4) |
| 88 | #define OMAP_RTC_STATUS_1M_EVENT BIT(3) |
| 89 | #define OMAP_RTC_STATUS_1S_EVENT BIT(2) |
| 90 | #define OMAP_RTC_STATUS_RUN BIT(1) |
| 91 | #define OMAP_RTC_STATUS_BUSY BIT(0) |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 92 | |
| 93 | /* OMAP_RTC_INTERRUPTS_REG bit fields: */ |
Sekhar Nori | 92adb96 | 2014-06-06 14:36:05 -0700 | [diff] [blame] | 94 | #define OMAP_RTC_INTERRUPTS_IT_ALARM BIT(3) |
| 95 | #define OMAP_RTC_INTERRUPTS_IT_TIMER BIT(2) |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 96 | |
Sekhar Nori | cd914bb | 2014-06-06 14:36:06 -0700 | [diff] [blame] | 97 | /* OMAP_RTC_OSC_REG bit fields: */ |
| 98 | #define OMAP_RTC_OSC_32KCLK_EN BIT(6) |
| 99 | |
Hebbar Gururaja | 8af750e | 2013-09-11 14:24:18 -0700 | [diff] [blame] | 100 | /* OMAP_RTC_IRQWAKEEN bit fields: */ |
Sekhar Nori | 92adb96 | 2014-06-06 14:36:05 -0700 | [diff] [blame] | 101 | #define OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN BIT(1) |
Hebbar Gururaja | 8af750e | 2013-09-11 14:24:18 -0700 | [diff] [blame] | 102 | |
Afzal Mohammed | cab1458 | 2012-12-17 16:02:11 -0800 | [diff] [blame] | 103 | /* OMAP_RTC_KICKER values */ |
| 104 | #define KICK0_VALUE 0x83e70b13 |
| 105 | #define KICK1_VALUE 0x95a4f1e0 |
| 106 | |
Sekhar Nori | 92adb96 | 2014-06-06 14:36:05 -0700 | [diff] [blame] | 107 | #define OMAP_RTC_HAS_KICKER BIT(0) |
Afzal Mohammed | cab1458 | 2012-12-17 16:02:11 -0800 | [diff] [blame] | 108 | |
Hebbar Gururaja | 8af750e | 2013-09-11 14:24:18 -0700 | [diff] [blame] | 109 | /* |
| 110 | * Few RTC IP revisions has special WAKE-EN Register to enable Wakeup |
| 111 | * generation for event Alarm. |
| 112 | */ |
Sekhar Nori | 92adb96 | 2014-06-06 14:36:05 -0700 | [diff] [blame] | 113 | #define OMAP_RTC_HAS_IRQWAKEEN BIT(1) |
Hebbar Gururaja | 8af750e | 2013-09-11 14:24:18 -0700 | [diff] [blame] | 114 | |
Sekhar Nori | cd914bb | 2014-06-06 14:36:06 -0700 | [diff] [blame] | 115 | /* |
| 116 | * Some RTC IP revisions (like those in AM335x and DRA7x) need |
| 117 | * the 32KHz clock to be explicitly enabled. |
| 118 | */ |
| 119 | #define OMAP_RTC_HAS_32KCLK_EN BIT(2) |
| 120 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 121 | struct omap_rtc { |
| 122 | struct rtc_device *rtc; |
| 123 | void __iomem *base; |
| 124 | int irq_alarm; |
| 125 | int irq_timer; |
| 126 | u8 interrupts_reg; |
| 127 | unsigned long flags; |
| 128 | }; |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 129 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 130 | static inline u8 rtc_read(struct omap_rtc *rtc, unsigned int reg) |
| 131 | { |
| 132 | return readb(rtc->base + reg); |
| 133 | } |
Afzal Mohammed | cab1458 | 2012-12-17 16:02:11 -0800 | [diff] [blame] | 134 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 135 | static inline void rtc_write(struct omap_rtc *rtc, unsigned int reg, u8 val) |
| 136 | { |
| 137 | writeb(val, rtc->base + reg); |
| 138 | } |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 139 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 140 | static inline void rtc_writel(struct omap_rtc *rtc, unsigned int reg, u32 val) |
| 141 | { |
| 142 | writel(val, rtc->base + reg); |
| 143 | } |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 144 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 145 | /* we rely on the rtc framework to handle locking (rtc->ops_lock), |
| 146 | * so the only other requirement is that register accesses which |
| 147 | * require BUSY to be clear are made with IRQs locally disabled |
| 148 | */ |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 149 | static void rtc_wait_not_busy(struct omap_rtc *rtc) |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 150 | { |
| 151 | int count = 0; |
| 152 | u8 status; |
| 153 | |
| 154 | /* BUSY may stay active for 1/32768 second (~30 usec) */ |
| 155 | for (count = 0; count < 50; count++) { |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 156 | status = rtc_read(rtc, OMAP_RTC_STATUS_REG); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 157 | if ((status & (u8)OMAP_RTC_STATUS_BUSY) == 0) |
| 158 | break; |
| 159 | udelay(1); |
| 160 | } |
| 161 | /* now we have ~15 usec to read/write various registers */ |
| 162 | } |
| 163 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 164 | static irqreturn_t rtc_irq(int irq, void *dev_id) |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 165 | { |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 166 | struct omap_rtc *rtc = dev_id; |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 167 | unsigned long events = 0; |
| 168 | u8 irq_data; |
| 169 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 170 | irq_data = rtc_read(rtc, OMAP_RTC_STATUS_REG); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 171 | |
| 172 | /* alarm irq? */ |
| 173 | if (irq_data & OMAP_RTC_STATUS_ALARM) { |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 174 | rtc_write(rtc, OMAP_RTC_STATUS_REG, OMAP_RTC_STATUS_ALARM); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 175 | events |= RTC_IRQF | RTC_AF; |
| 176 | } |
| 177 | |
| 178 | /* 1/sec periodic/update irq? */ |
| 179 | if (irq_data & OMAP_RTC_STATUS_1S_EVENT) |
| 180 | events |= RTC_IRQF | RTC_UF; |
| 181 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 182 | rtc_update_irq(rtc->rtc, 1, events); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 183 | |
| 184 | return IRQ_HANDLED; |
| 185 | } |
| 186 | |
John Stultz | 16380c1 | 2011-02-02 17:02:41 -0800 | [diff] [blame] | 187 | static int omap_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled) |
| 188 | { |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 189 | struct omap_rtc *rtc = dev_get_drvdata(dev); |
Lokesh Vutla | ab7f580 | 2014-06-06 14:36:12 -0700 | [diff] [blame] | 190 | u8 reg, irqwake_reg = 0; |
John Stultz | 16380c1 | 2011-02-02 17:02:41 -0800 | [diff] [blame] | 191 | |
| 192 | local_irq_disable(); |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 193 | rtc_wait_not_busy(rtc); |
| 194 | reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); |
| 195 | if (rtc->flags & OMAP_RTC_HAS_IRQWAKEEN) |
| 196 | irqwake_reg = rtc_read(rtc, OMAP_RTC_IRQWAKEEN); |
Lokesh Vutla | ab7f580 | 2014-06-06 14:36:12 -0700 | [diff] [blame] | 197 | |
| 198 | if (enabled) { |
John Stultz | 16380c1 | 2011-02-02 17:02:41 -0800 | [diff] [blame] | 199 | reg |= OMAP_RTC_INTERRUPTS_IT_ALARM; |
Lokesh Vutla | ab7f580 | 2014-06-06 14:36:12 -0700 | [diff] [blame] | 200 | irqwake_reg |= OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN; |
| 201 | } else { |
John Stultz | 16380c1 | 2011-02-02 17:02:41 -0800 | [diff] [blame] | 202 | reg &= ~OMAP_RTC_INTERRUPTS_IT_ALARM; |
Lokesh Vutla | ab7f580 | 2014-06-06 14:36:12 -0700 | [diff] [blame] | 203 | irqwake_reg &= ~OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN; |
| 204 | } |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 205 | rtc_wait_not_busy(rtc); |
| 206 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); |
| 207 | if (rtc->flags & OMAP_RTC_HAS_IRQWAKEEN) |
| 208 | rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); |
John Stultz | 16380c1 | 2011-02-02 17:02:41 -0800 | [diff] [blame] | 209 | local_irq_enable(); |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 214 | /* this hardware doesn't support "don't care" alarm fields */ |
| 215 | static int tm2bcd(struct rtc_time *tm) |
| 216 | { |
| 217 | if (rtc_valid_tm(tm) != 0) |
| 218 | return -EINVAL; |
| 219 | |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 220 | tm->tm_sec = bin2bcd(tm->tm_sec); |
| 221 | tm->tm_min = bin2bcd(tm->tm_min); |
| 222 | tm->tm_hour = bin2bcd(tm->tm_hour); |
| 223 | tm->tm_mday = bin2bcd(tm->tm_mday); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 224 | |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 225 | tm->tm_mon = bin2bcd(tm->tm_mon + 1); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 226 | |
| 227 | /* epoch == 1900 */ |
| 228 | if (tm->tm_year < 100 || tm->tm_year > 199) |
| 229 | return -EINVAL; |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 230 | tm->tm_year = bin2bcd(tm->tm_year - 100); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static void bcd2tm(struct rtc_time *tm) |
| 236 | { |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 237 | tm->tm_sec = bcd2bin(tm->tm_sec); |
| 238 | tm->tm_min = bcd2bin(tm->tm_min); |
| 239 | tm->tm_hour = bcd2bin(tm->tm_hour); |
| 240 | tm->tm_mday = bcd2bin(tm->tm_mday); |
| 241 | tm->tm_mon = bcd2bin(tm->tm_mon) - 1; |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 242 | /* epoch == 1900 */ |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 243 | tm->tm_year = bcd2bin(tm->tm_year) + 100; |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | |
| 247 | static int omap_rtc_read_time(struct device *dev, struct rtc_time *tm) |
| 248 | { |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 249 | struct omap_rtc *rtc = dev_get_drvdata(dev); |
| 250 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 251 | /* we don't report wday/yday/isdst ... */ |
| 252 | local_irq_disable(); |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 253 | rtc_wait_not_busy(rtc); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 254 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 255 | tm->tm_sec = rtc_read(rtc, OMAP_RTC_SECONDS_REG); |
| 256 | tm->tm_min = rtc_read(rtc, OMAP_RTC_MINUTES_REG); |
| 257 | tm->tm_hour = rtc_read(rtc, OMAP_RTC_HOURS_REG); |
| 258 | tm->tm_mday = rtc_read(rtc, OMAP_RTC_DAYS_REG); |
| 259 | tm->tm_mon = rtc_read(rtc, OMAP_RTC_MONTHS_REG); |
| 260 | tm->tm_year = rtc_read(rtc, OMAP_RTC_YEARS_REG); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 261 | |
| 262 | local_irq_enable(); |
| 263 | |
| 264 | bcd2tm(tm); |
| 265 | return 0; |
| 266 | } |
| 267 | |
| 268 | static int omap_rtc_set_time(struct device *dev, struct rtc_time *tm) |
| 269 | { |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 270 | struct omap_rtc *rtc = dev_get_drvdata(dev); |
| 271 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 272 | if (tm2bcd(tm) < 0) |
| 273 | return -EINVAL; |
| 274 | local_irq_disable(); |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 275 | rtc_wait_not_busy(rtc); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 276 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 277 | rtc_write(rtc, OMAP_RTC_YEARS_REG, tm->tm_year); |
| 278 | rtc_write(rtc, OMAP_RTC_MONTHS_REG, tm->tm_mon); |
| 279 | rtc_write(rtc, OMAP_RTC_DAYS_REG, tm->tm_mday); |
| 280 | rtc_write(rtc, OMAP_RTC_HOURS_REG, tm->tm_hour); |
| 281 | rtc_write(rtc, OMAP_RTC_MINUTES_REG, tm->tm_min); |
| 282 | rtc_write(rtc, OMAP_RTC_SECONDS_REG, tm->tm_sec); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 283 | |
| 284 | local_irq_enable(); |
| 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | static int omap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm) |
| 290 | { |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 291 | struct omap_rtc *rtc = dev_get_drvdata(dev); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 292 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 293 | local_irq_disable(); |
| 294 | rtc_wait_not_busy(rtc); |
| 295 | |
| 296 | alm->time.tm_sec = rtc_read(rtc, OMAP_RTC_ALARM_SECONDS_REG); |
| 297 | alm->time.tm_min = rtc_read(rtc, OMAP_RTC_ALARM_MINUTES_REG); |
| 298 | alm->time.tm_hour = rtc_read(rtc, OMAP_RTC_ALARM_HOURS_REG); |
| 299 | alm->time.tm_mday = rtc_read(rtc, OMAP_RTC_ALARM_DAYS_REG); |
| 300 | alm->time.tm_mon = rtc_read(rtc, OMAP_RTC_ALARM_MONTHS_REG); |
| 301 | alm->time.tm_year = rtc_read(rtc, OMAP_RTC_ALARM_YEARS_REG); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 302 | |
| 303 | local_irq_enable(); |
| 304 | |
| 305 | bcd2tm(&alm->time); |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 306 | alm->enabled = !!(rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG) |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 307 | & OMAP_RTC_INTERRUPTS_IT_ALARM); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 308 | |
| 309 | return 0; |
| 310 | } |
| 311 | |
| 312 | static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm) |
| 313 | { |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 314 | struct omap_rtc *rtc = dev_get_drvdata(dev); |
Lokesh Vutla | ab7f580 | 2014-06-06 14:36:12 -0700 | [diff] [blame] | 315 | u8 reg, irqwake_reg = 0; |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 316 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 317 | if (tm2bcd(&alm->time) < 0) |
| 318 | return -EINVAL; |
| 319 | |
| 320 | local_irq_disable(); |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 321 | rtc_wait_not_busy(rtc); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 322 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 323 | rtc_write(rtc, OMAP_RTC_ALARM_YEARS_REG, alm->time.tm_year); |
| 324 | rtc_write(rtc, OMAP_RTC_ALARM_MONTHS_REG, alm->time.tm_mon); |
| 325 | rtc_write(rtc, OMAP_RTC_ALARM_DAYS_REG, alm->time.tm_mday); |
| 326 | rtc_write(rtc, OMAP_RTC_ALARM_HOURS_REG, alm->time.tm_hour); |
| 327 | rtc_write(rtc, OMAP_RTC_ALARM_MINUTES_REG, alm->time.tm_min); |
| 328 | rtc_write(rtc, OMAP_RTC_ALARM_SECONDS_REG, alm->time.tm_sec); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 329 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 330 | reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); |
| 331 | if (rtc->flags & OMAP_RTC_HAS_IRQWAKEEN) |
| 332 | irqwake_reg = rtc_read(rtc, OMAP_RTC_IRQWAKEEN); |
Lokesh Vutla | ab7f580 | 2014-06-06 14:36:12 -0700 | [diff] [blame] | 333 | |
| 334 | if (alm->enabled) { |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 335 | reg |= OMAP_RTC_INTERRUPTS_IT_ALARM; |
Lokesh Vutla | ab7f580 | 2014-06-06 14:36:12 -0700 | [diff] [blame] | 336 | irqwake_reg |= OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN; |
| 337 | } else { |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 338 | reg &= ~OMAP_RTC_INTERRUPTS_IT_ALARM; |
Lokesh Vutla | ab7f580 | 2014-06-06 14:36:12 -0700 | [diff] [blame] | 339 | irqwake_reg &= ~OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN; |
| 340 | } |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 341 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg); |
| 342 | if (rtc->flags & OMAP_RTC_HAS_IRQWAKEEN) |
| 343 | rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 344 | |
| 345 | local_irq_enable(); |
| 346 | |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | static struct rtc_class_ops omap_rtc_ops = { |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 351 | .read_time = omap_rtc_read_time, |
| 352 | .set_time = omap_rtc_set_time, |
| 353 | .read_alarm = omap_rtc_read_alarm, |
| 354 | .set_alarm = omap_rtc_set_alarm, |
John Stultz | 16380c1 | 2011-02-02 17:02:41 -0800 | [diff] [blame] | 355 | .alarm_irq_enable = omap_rtc_alarm_irq_enable, |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 356 | }; |
| 357 | |
Hebbar Gururaja | 8af750e | 2013-09-11 14:24:18 -0700 | [diff] [blame] | 358 | #define OMAP_RTC_DATA_AM3352_IDX 1 |
| 359 | #define OMAP_RTC_DATA_DA830_IDX 2 |
Afzal Mohammed | 9e0344d | 2012-12-17 16:02:15 -0800 | [diff] [blame] | 360 | |
Johan Hovold | d17a82e | 2014-12-10 15:52:52 -0800 | [diff] [blame] | 361 | static const struct platform_device_id omap_rtc_devtype[] = { |
Afzal Mohammed | cab1458 | 2012-12-17 16:02:11 -0800 | [diff] [blame] | 362 | { |
| 363 | .name = DRIVER_NAME, |
Hebbar Gururaja | 8af750e | 2013-09-11 14:24:18 -0700 | [diff] [blame] | 364 | }, |
| 365 | [OMAP_RTC_DATA_AM3352_IDX] = { |
| 366 | .name = "am3352-rtc", |
Sekhar Nori | cd914bb | 2014-06-06 14:36:06 -0700 | [diff] [blame] | 367 | .driver_data = OMAP_RTC_HAS_KICKER | OMAP_RTC_HAS_IRQWAKEEN | |
| 368 | OMAP_RTC_HAS_32KCLK_EN, |
Hebbar Gururaja | 8af750e | 2013-09-11 14:24:18 -0700 | [diff] [blame] | 369 | }, |
| 370 | [OMAP_RTC_DATA_DA830_IDX] = { |
Afzal Mohammed | cab1458 | 2012-12-17 16:02:11 -0800 | [diff] [blame] | 371 | .name = "da830-rtc", |
| 372 | .driver_data = OMAP_RTC_HAS_KICKER, |
| 373 | }, |
| 374 | {}, |
| 375 | }; |
| 376 | MODULE_DEVICE_TABLE(platform, omap_rtc_devtype); |
| 377 | |
Afzal Mohammed | 9e0344d | 2012-12-17 16:02:15 -0800 | [diff] [blame] | 378 | static const struct of_device_id omap_rtc_of_match[] = { |
| 379 | { .compatible = "ti,da830-rtc", |
| 380 | .data = &omap_rtc_devtype[OMAP_RTC_DATA_DA830_IDX], |
| 381 | }, |
Hebbar Gururaja | 8af750e | 2013-09-11 14:24:18 -0700 | [diff] [blame] | 382 | { .compatible = "ti,am3352-rtc", |
| 383 | .data = &omap_rtc_devtype[OMAP_RTC_DATA_AM3352_IDX], |
| 384 | }, |
Afzal Mohammed | 9e0344d | 2012-12-17 16:02:15 -0800 | [diff] [blame] | 385 | {}, |
| 386 | }; |
| 387 | MODULE_DEVICE_TABLE(of, omap_rtc_of_match); |
| 388 | |
David Brownell | 71fc822 | 2008-07-23 21:30:38 -0700 | [diff] [blame] | 389 | static int __init omap_rtc_probe(struct platform_device *pdev) |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 390 | { |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 391 | struct omap_rtc *rtc; |
Vishwanathrao Badarkhe, Manish | 3765e8f | 2013-04-29 16:20:04 -0700 | [diff] [blame] | 392 | struct resource *res; |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 393 | u8 reg, new_ctrl; |
Afzal Mohammed | cab1458 | 2012-12-17 16:02:11 -0800 | [diff] [blame] | 394 | const struct platform_device_id *id_entry; |
Afzal Mohammed | 9e0344d | 2012-12-17 16:02:15 -0800 | [diff] [blame] | 395 | const struct of_device_id *of_id; |
Johan Hovold | 437b37a | 2014-12-10 15:52:40 -0800 | [diff] [blame] | 396 | int ret; |
Afzal Mohammed | 9e0344d | 2012-12-17 16:02:15 -0800 | [diff] [blame] | 397 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 398 | rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL); |
| 399 | if (!rtc) |
| 400 | return -ENOMEM; |
| 401 | |
Afzal Mohammed | 9e0344d | 2012-12-17 16:02:15 -0800 | [diff] [blame] | 402 | of_id = of_match_device(omap_rtc_of_match, &pdev->dev); |
| 403 | if (of_id) |
| 404 | pdev->id_entry = of_id->data; |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 405 | |
Sekhar Nori | 337b600 | 2014-06-06 14:36:04 -0700 | [diff] [blame] | 406 | id_entry = platform_get_device_id(pdev); |
| 407 | if (!id_entry) { |
| 408 | dev_err(&pdev->dev, "no matching device entry\n"); |
| 409 | return -ENODEV; |
| 410 | } |
| 411 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 412 | rtc->flags = id_entry->driver_data; |
| 413 | |
| 414 | rtc->irq_timer = platform_get_irq(pdev, 0); |
| 415 | if (rtc->irq_timer <= 0) |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 416 | return -ENOENT; |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 417 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 418 | rtc->irq_alarm = platform_get_irq(pdev, 1); |
| 419 | if (rtc->irq_alarm <= 0) |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 420 | return -ENOENT; |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 421 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 422 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 423 | rtc->base = devm_ioremap_resource(&pdev->dev, res); |
| 424 | if (IS_ERR(rtc->base)) |
| 425 | return PTR_ERR(rtc->base); |
| 426 | |
| 427 | platform_set_drvdata(pdev, rtc); |
Mark A. Greer | 8cfde8c | 2009-12-15 16:46:11 -0800 | [diff] [blame] | 428 | |
Vaibhav Hiremath | fc9bd90 | 2012-12-17 16:02:18 -0800 | [diff] [blame] | 429 | /* Enable the clock/module so that we can access the registers */ |
| 430 | pm_runtime_enable(&pdev->dev); |
| 431 | pm_runtime_get_sync(&pdev->dev); |
| 432 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 433 | if (rtc->flags & OMAP_RTC_HAS_KICKER) { |
| 434 | rtc_writel(rtc, OMAP_RTC_KICK0_REG, KICK0_VALUE); |
| 435 | rtc_writel(rtc, OMAP_RTC_KICK1_REG, KICK1_VALUE); |
Afzal Mohammed | cab1458 | 2012-12-17 16:02:11 -0800 | [diff] [blame] | 436 | } |
| 437 | |
Johan Hovold | 1ed8b5d | 2014-12-10 15:52:36 -0800 | [diff] [blame] | 438 | /* |
| 439 | * disable interrupts |
| 440 | * |
| 441 | * NOTE: ALARM2 is not cleared on AM3352 if rtc_write (writeb) is used |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 442 | */ |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 443 | rtc_writel(rtc, OMAP_RTC_INTERRUPTS_REG, 0); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 444 | |
Sekhar Nori | cd914bb | 2014-06-06 14:36:06 -0700 | [diff] [blame] | 445 | /* enable RTC functional clock */ |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 446 | if (rtc->flags & OMAP_RTC_HAS_32KCLK_EN) { |
| 447 | reg = rtc_read(rtc, OMAP_RTC_OSC_REG); |
| 448 | rtc_writel(rtc, OMAP_RTC_OSC_REG, |
| 449 | reg | OMAP_RTC_OSC_32KCLK_EN); |
Johan Hovold | 44c63a5 | 2014-12-10 15:52:30 -0800 | [diff] [blame] | 450 | } |
Sekhar Nori | cd914bb | 2014-06-06 14:36:06 -0700 | [diff] [blame] | 451 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 452 | /* clear old status */ |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 453 | reg = rtc_read(rtc, OMAP_RTC_STATUS_REG); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 454 | if (reg & (u8) OMAP_RTC_STATUS_POWER_UP) { |
Johan Hovold | 397b630 | 2014-12-10 15:52:49 -0800 | [diff] [blame] | 455 | dev_info(&pdev->dev, "RTC power up reset detected\n"); |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 456 | rtc_write(rtc, OMAP_RTC_STATUS_REG, OMAP_RTC_STATUS_POWER_UP); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 457 | } |
| 458 | if (reg & (u8) OMAP_RTC_STATUS_ALARM) |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 459 | rtc_write(rtc, OMAP_RTC_STATUS_REG, OMAP_RTC_STATUS_ALARM); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 460 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 461 | /* On boards with split power, RTC_ON_NOFF won't reset the RTC */ |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 462 | reg = rtc_read(rtc, OMAP_RTC_CTRL_REG); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 463 | if (reg & (u8) OMAP_RTC_CTRL_STOP) |
Johan Hovold | 397b630 | 2014-12-10 15:52:49 -0800 | [diff] [blame] | 464 | dev_info(&pdev->dev, "already running\n"); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 465 | |
| 466 | /* force to 24 hour mode */ |
Daniel Glöckner | 12b3e03 | 2011-08-03 16:21:02 -0700 | [diff] [blame] | 467 | new_ctrl = reg & (OMAP_RTC_CTRL_SPLIT|OMAP_RTC_CTRL_AUTO_COMP); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 468 | new_ctrl |= OMAP_RTC_CTRL_STOP; |
| 469 | |
| 470 | /* BOARD-SPECIFIC CUSTOMIZATION CAN GO HERE: |
| 471 | * |
Sekhar Nori | fa5b078 | 2010-10-27 15:33:05 -0700 | [diff] [blame] | 472 | * - Device wake-up capability setting should come through chip |
| 473 | * init logic. OMAP1 boards should initialize the "wakeup capable" |
| 474 | * flag in the platform device if the board is wired right for |
| 475 | * being woken up by RTC alarm. For OMAP-L138, this capability |
| 476 | * is built into the SoC by the "Deep Sleep" capability. |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 477 | * |
| 478 | * - Boards wired so RTC_ON_nOFF is used as the reset signal, |
| 479 | * rather than nPWRON_RESET, should forcibly enable split |
| 480 | * power mode. (Some chip errata report that RTC_CTRL_SPLIT |
| 481 | * is write-only, and always reads as zero...) |
| 482 | */ |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 483 | |
| 484 | if (new_ctrl & (u8) OMAP_RTC_CTRL_SPLIT) |
Johan Hovold | 397b630 | 2014-12-10 15:52:49 -0800 | [diff] [blame] | 485 | dev_info(&pdev->dev, "split power mode\n"); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 486 | |
| 487 | if (reg != new_ctrl) |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 488 | rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 489 | |
Johan Hovold | 4390ce0 | 2014-12-10 15:52:43 -0800 | [diff] [blame] | 490 | device_init_wakeup(&pdev->dev, true); |
| 491 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 492 | rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, |
Johan Hovold | 4390ce0 | 2014-12-10 15:52:43 -0800 | [diff] [blame] | 493 | &omap_rtc_ops, THIS_MODULE); |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 494 | if (IS_ERR(rtc->rtc)) { |
| 495 | ret = PTR_ERR(rtc->rtc); |
Johan Hovold | 4390ce0 | 2014-12-10 15:52:43 -0800 | [diff] [blame] | 496 | goto err; |
| 497 | } |
Johan Hovold | 4390ce0 | 2014-12-10 15:52:43 -0800 | [diff] [blame] | 498 | |
| 499 | /* handle periodic and alarm irqs */ |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 500 | ret = devm_request_irq(&pdev->dev, rtc->irq_timer, rtc_irq, 0, |
| 501 | dev_name(&rtc->rtc->dev), rtc); |
Johan Hovold | 4390ce0 | 2014-12-10 15:52:43 -0800 | [diff] [blame] | 502 | if (ret) |
| 503 | goto err; |
| 504 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 505 | if (rtc->irq_timer != rtc->irq_alarm) { |
| 506 | ret = devm_request_irq(&pdev->dev, rtc->irq_alarm, rtc_irq, 0, |
| 507 | dev_name(&rtc->rtc->dev), rtc); |
Johan Hovold | 4390ce0 | 2014-12-10 15:52:43 -0800 | [diff] [blame] | 508 | if (ret) |
| 509 | goto err; |
| 510 | } |
| 511 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 512 | return 0; |
| 513 | |
Johan Hovold | 437b37a | 2014-12-10 15:52:40 -0800 | [diff] [blame] | 514 | err: |
Johan Hovold | 7ecd9a3 | 2014-12-10 15:52:33 -0800 | [diff] [blame] | 515 | device_init_wakeup(&pdev->dev, false); |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 516 | if (rtc->flags & OMAP_RTC_HAS_KICKER) |
| 517 | rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0); |
Vaibhav Hiremath | fc9bd90 | 2012-12-17 16:02:18 -0800 | [diff] [blame] | 518 | pm_runtime_put_sync(&pdev->dev); |
| 519 | pm_runtime_disable(&pdev->dev); |
Johan Hovold | 437b37a | 2014-12-10 15:52:40 -0800 | [diff] [blame] | 520 | |
| 521 | return ret; |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 522 | } |
| 523 | |
David Brownell | 71fc822 | 2008-07-23 21:30:38 -0700 | [diff] [blame] | 524 | static int __exit omap_rtc_remove(struct platform_device *pdev) |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 525 | { |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 526 | struct omap_rtc *rtc = platform_get_drvdata(pdev); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 527 | |
| 528 | device_init_wakeup(&pdev->dev, 0); |
| 529 | |
| 530 | /* leave rtc running, but disable irqs */ |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 531 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 532 | |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 533 | if (rtc->flags & OMAP_RTC_HAS_KICKER) |
| 534 | rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0); |
Vaibhav Hiremath | fc9bd90 | 2012-12-17 16:02:18 -0800 | [diff] [blame] | 535 | |
| 536 | /* Disable the clock/module */ |
| 537 | pm_runtime_put_sync(&pdev->dev); |
| 538 | pm_runtime_disable(&pdev->dev); |
| 539 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 540 | return 0; |
| 541 | } |
| 542 | |
Jingoo Han | 04ebc35 | 2013-04-29 16:21:01 -0700 | [diff] [blame] | 543 | #ifdef CONFIG_PM_SLEEP |
Jingoo Han | 04ebc35 | 2013-04-29 16:21:01 -0700 | [diff] [blame] | 544 | static int omap_rtc_suspend(struct device *dev) |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 545 | { |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 546 | struct omap_rtc *rtc = dev_get_drvdata(dev); |
| 547 | |
| 548 | rtc->interrupts_reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 549 | |
| 550 | /* FIXME the RTC alarm is not currently acting as a wakeup event |
Hebbar Gururaja | 8af750e | 2013-09-11 14:24:18 -0700 | [diff] [blame] | 551 | * source on some platforms, and in fact this enable() call is just |
| 552 | * saving a flag that's never used... |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 553 | */ |
Lokesh Vutla | ab7f580 | 2014-06-06 14:36:12 -0700 | [diff] [blame] | 554 | if (device_may_wakeup(dev)) |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 555 | enable_irq_wake(rtc->irq_alarm); |
Lokesh Vutla | ab7f580 | 2014-06-06 14:36:12 -0700 | [diff] [blame] | 556 | else |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 557 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 558 | |
Vaibhav Hiremath | fc9bd90 | 2012-12-17 16:02:18 -0800 | [diff] [blame] | 559 | /* Disable the clock/module */ |
Jingoo Han | 04ebc35 | 2013-04-29 16:21:01 -0700 | [diff] [blame] | 560 | pm_runtime_put_sync(dev); |
Vaibhav Hiremath | fc9bd90 | 2012-12-17 16:02:18 -0800 | [diff] [blame] | 561 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 562 | return 0; |
| 563 | } |
| 564 | |
Jingoo Han | 04ebc35 | 2013-04-29 16:21:01 -0700 | [diff] [blame] | 565 | static int omap_rtc_resume(struct device *dev) |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 566 | { |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 567 | struct omap_rtc *rtc = dev_get_drvdata(dev); |
| 568 | |
Vaibhav Hiremath | fc9bd90 | 2012-12-17 16:02:18 -0800 | [diff] [blame] | 569 | /* Enable the clock/module so that we can access the registers */ |
Jingoo Han | 04ebc35 | 2013-04-29 16:21:01 -0700 | [diff] [blame] | 570 | pm_runtime_get_sync(dev); |
Vaibhav Hiremath | fc9bd90 | 2012-12-17 16:02:18 -0800 | [diff] [blame] | 571 | |
Lokesh Vutla | ab7f580 | 2014-06-06 14:36:12 -0700 | [diff] [blame] | 572 | if (device_may_wakeup(dev)) |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 573 | disable_irq_wake(rtc->irq_alarm); |
Lokesh Vutla | ab7f580 | 2014-06-06 14:36:12 -0700 | [diff] [blame] | 574 | else |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 575 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, rtc->interrupts_reg); |
Lokesh Vutla | ab7f580 | 2014-06-06 14:36:12 -0700 | [diff] [blame] | 576 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 577 | return 0; |
| 578 | } |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 579 | #endif |
| 580 | |
Jingoo Han | 04ebc35 | 2013-04-29 16:21:01 -0700 | [diff] [blame] | 581 | static SIMPLE_DEV_PM_OPS(omap_rtc_pm_ops, omap_rtc_suspend, omap_rtc_resume); |
| 582 | |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 583 | static void omap_rtc_shutdown(struct platform_device *pdev) |
| 584 | { |
Johan Hovold | 55ba953 | 2014-12-10 15:52:55 -0800 | [diff] [blame^] | 585 | struct omap_rtc *rtc = platform_get_drvdata(pdev); |
| 586 | |
| 587 | rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 588 | } |
| 589 | |
Kay Sievers | ad28a07 | 2008-04-10 21:29:25 -0700 | [diff] [blame] | 590 | MODULE_ALIAS("platform:omap_rtc"); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 591 | static struct platform_driver omap_rtc_driver = { |
David Brownell | 71fc822 | 2008-07-23 21:30:38 -0700 | [diff] [blame] | 592 | .remove = __exit_p(omap_rtc_remove), |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 593 | .shutdown = omap_rtc_shutdown, |
| 594 | .driver = { |
Afzal Mohammed | cab1458 | 2012-12-17 16:02:11 -0800 | [diff] [blame] | 595 | .name = DRIVER_NAME, |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 596 | .owner = THIS_MODULE, |
Jingoo Han | 04ebc35 | 2013-04-29 16:21:01 -0700 | [diff] [blame] | 597 | .pm = &omap_rtc_pm_ops, |
Sachin Kamat | 616b734 | 2013-11-12 15:10:55 -0800 | [diff] [blame] | 598 | .of_match_table = omap_rtc_of_match, |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 599 | }, |
Afzal Mohammed | cab1458 | 2012-12-17 16:02:11 -0800 | [diff] [blame] | 600 | .id_table = omap_rtc_devtype, |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 601 | }; |
| 602 | |
Jingoo Han | 09c5a36 | 2013-04-29 16:18:46 -0700 | [diff] [blame] | 603 | module_platform_driver_probe(omap_rtc_driver, omap_rtc_probe); |
David Brownell | db68b18 | 2006-12-06 20:38:36 -0800 | [diff] [blame] | 604 | |
| 605 | MODULE_AUTHOR("George G. Davis (and others)"); |
| 606 | MODULE_LICENSE("GPL"); |