158c92990SAlexandre Belloni // SPDX-License-Identifier: GPL-2.0+
2db68b189SDavid Brownell /*
310211ae3SJohan Hovold * TI OMAP Real Time Clock interface for Linux
4db68b189SDavid Brownell *
5db68b189SDavid Brownell * Copyright (C) 2003 MontaVista Software, Inc.
6db68b189SDavid Brownell * Author: George G. Davis <gdavis@mvista.com> or <source@mvista.com>
7db68b189SDavid Brownell *
8db68b189SDavid Brownell * Copyright (C) 2006 David Brownell (new RTC framework)
90125138dSJohan Hovold * Copyright (C) 2014 Johan Hovold <johan@kernel.org>
10db68b189SDavid Brownell */
11db68b189SDavid Brownell
12db68b189SDavid Brownell #include <linux/bcd.h>
1397ea1906SMarcin Niestroj #include <linux/clk.h>
1497ea1906SMarcin Niestroj #include <linux/delay.h>
1597ea1906SMarcin Niestroj #include <linux/init.h>
1697ea1906SMarcin Niestroj #include <linux/io.h>
1797ea1906SMarcin Niestroj #include <linux/ioport.h>
1897ea1906SMarcin Niestroj #include <linux/kernel.h>
1997ea1906SMarcin Niestroj #include <linux/module.h>
209e0344dcSAfzal Mohammed #include <linux/of.h>
219e0344dcSAfzal Mohammed #include <linux/of_device.h>
2297ea1906SMarcin Niestroj #include <linux/pinctrl/pinctrl.h>
2397ea1906SMarcin Niestroj #include <linux/pinctrl/pinconf.h>
2497ea1906SMarcin Niestroj #include <linux/pinctrl/pinconf-generic.h>
2597ea1906SMarcin Niestroj #include <linux/platform_device.h>
26fc9bd902SVaibhav Hiremath #include <linux/pm_runtime.h>
2797ea1906SMarcin Niestroj #include <linux/rtc.h>
28f69c2b54SKrzysztof Kozlowski #include <linux/rtc/rtc-omap.h>
29db68b189SDavid Brownell
3010211ae3SJohan Hovold /*
3110211ae3SJohan Hovold * The OMAP RTC is a year/month/day/hours/minutes/seconds BCD clock
32db68b189SDavid Brownell * with century-range alarm matching, driven by the 32kHz clock.
33db68b189SDavid Brownell *
34db68b189SDavid Brownell * The main user-visible ways it differs from PC RTCs are by omitting
35db68b189SDavid Brownell * "don't care" alarm fields and sub-second periodic IRQs, and having
36db68b189SDavid Brownell * an autoadjust mechanism to calibrate to the true oscillator rate.
37db68b189SDavid Brownell *
38db68b189SDavid Brownell * Board-specific wiring options include using split power mode with
39db68b189SDavid Brownell * RTC_OFF_NOFF used as the reset signal (so the RTC won't be reset),
40db68b189SDavid Brownell * and wiring RTC_WAKE_INT (so the RTC alarm can wake the system from
41fa5b0782SSekhar Nori * low power modes) for OMAP1 boards (OMAP-L138 has this built into
42fa5b0782SSekhar Nori * the SoC). See the BOARD-SPECIFIC CUSTOMIZATION comment.
43db68b189SDavid Brownell */
44db68b189SDavid Brownell
45db68b189SDavid Brownell /* RTC registers */
46db68b189SDavid Brownell #define OMAP_RTC_SECONDS_REG 0x00
47db68b189SDavid Brownell #define OMAP_RTC_MINUTES_REG 0x04
48db68b189SDavid Brownell #define OMAP_RTC_HOURS_REG 0x08
49db68b189SDavid Brownell #define OMAP_RTC_DAYS_REG 0x0C
50db68b189SDavid Brownell #define OMAP_RTC_MONTHS_REG 0x10
51db68b189SDavid Brownell #define OMAP_RTC_YEARS_REG 0x14
52db68b189SDavid Brownell #define OMAP_RTC_WEEKS_REG 0x18
53db68b189SDavid Brownell
54db68b189SDavid Brownell #define OMAP_RTC_ALARM_SECONDS_REG 0x20
55db68b189SDavid Brownell #define OMAP_RTC_ALARM_MINUTES_REG 0x24
56db68b189SDavid Brownell #define OMAP_RTC_ALARM_HOURS_REG 0x28
57db68b189SDavid Brownell #define OMAP_RTC_ALARM_DAYS_REG 0x2c
58db68b189SDavid Brownell #define OMAP_RTC_ALARM_MONTHS_REG 0x30
59db68b189SDavid Brownell #define OMAP_RTC_ALARM_YEARS_REG 0x34
60db68b189SDavid Brownell
61db68b189SDavid Brownell #define OMAP_RTC_CTRL_REG 0x40
62db68b189SDavid Brownell #define OMAP_RTC_STATUS_REG 0x44
63db68b189SDavid Brownell #define OMAP_RTC_INTERRUPTS_REG 0x48
64db68b189SDavid Brownell
65db68b189SDavid Brownell #define OMAP_RTC_COMP_LSB_REG 0x4c
66db68b189SDavid Brownell #define OMAP_RTC_COMP_MSB_REG 0x50
67db68b189SDavid Brownell #define OMAP_RTC_OSC_REG 0x54
68db68b189SDavid Brownell
69b6ee15efSAlexandre Belloni #define OMAP_RTC_SCRATCH0_REG 0x60
70b6ee15efSAlexandre Belloni #define OMAP_RTC_SCRATCH1_REG 0x64
71b6ee15efSAlexandre Belloni #define OMAP_RTC_SCRATCH2_REG 0x68
72b6ee15efSAlexandre Belloni
73cab1458cSAfzal Mohammed #define OMAP_RTC_KICK0_REG 0x6c
74cab1458cSAfzal Mohammed #define OMAP_RTC_KICK1_REG 0x70
75cab1458cSAfzal Mohammed
768af750e3SHebbar Gururaja #define OMAP_RTC_IRQWAKEEN 0x7c
778af750e3SHebbar Gururaja
78222a12fcSJohan Hovold #define OMAP_RTC_ALARM2_SECONDS_REG 0x80
79222a12fcSJohan Hovold #define OMAP_RTC_ALARM2_MINUTES_REG 0x84
80222a12fcSJohan Hovold #define OMAP_RTC_ALARM2_HOURS_REG 0x88
81222a12fcSJohan Hovold #define OMAP_RTC_ALARM2_DAYS_REG 0x8c
82222a12fcSJohan Hovold #define OMAP_RTC_ALARM2_MONTHS_REG 0x90
83222a12fcSJohan Hovold #define OMAP_RTC_ALARM2_YEARS_REG 0x94
84222a12fcSJohan Hovold
85222a12fcSJohan Hovold #define OMAP_RTC_PMIC_REG 0x98
86222a12fcSJohan Hovold
87db68b189SDavid Brownell /* OMAP_RTC_CTRL_REG bit fields: */
8892adb96aSSekhar Nori #define OMAP_RTC_CTRL_SPLIT BIT(7)
8992adb96aSSekhar Nori #define OMAP_RTC_CTRL_DISABLE BIT(6)
9092adb96aSSekhar Nori #define OMAP_RTC_CTRL_SET_32_COUNTER BIT(5)
9192adb96aSSekhar Nori #define OMAP_RTC_CTRL_TEST BIT(4)
9292adb96aSSekhar Nori #define OMAP_RTC_CTRL_MODE_12_24 BIT(3)
9392adb96aSSekhar Nori #define OMAP_RTC_CTRL_AUTO_COMP BIT(2)
9492adb96aSSekhar Nori #define OMAP_RTC_CTRL_ROUND_30S BIT(1)
9592adb96aSSekhar Nori #define OMAP_RTC_CTRL_STOP BIT(0)
96db68b189SDavid Brownell
97db68b189SDavid Brownell /* OMAP_RTC_STATUS_REG bit fields: */
9892adb96aSSekhar Nori #define OMAP_RTC_STATUS_POWER_UP BIT(7)
99222a12fcSJohan Hovold #define OMAP_RTC_STATUS_ALARM2 BIT(7)
10092adb96aSSekhar Nori #define OMAP_RTC_STATUS_ALARM BIT(6)
10192adb96aSSekhar Nori #define OMAP_RTC_STATUS_1D_EVENT BIT(5)
10292adb96aSSekhar Nori #define OMAP_RTC_STATUS_1H_EVENT BIT(4)
10392adb96aSSekhar Nori #define OMAP_RTC_STATUS_1M_EVENT BIT(3)
10492adb96aSSekhar Nori #define OMAP_RTC_STATUS_1S_EVENT BIT(2)
10592adb96aSSekhar Nori #define OMAP_RTC_STATUS_RUN BIT(1)
10692adb96aSSekhar Nori #define OMAP_RTC_STATUS_BUSY BIT(0)
107db68b189SDavid Brownell
108db68b189SDavid Brownell /* OMAP_RTC_INTERRUPTS_REG bit fields: */
109222a12fcSJohan Hovold #define OMAP_RTC_INTERRUPTS_IT_ALARM2 BIT(4)
11092adb96aSSekhar Nori #define OMAP_RTC_INTERRUPTS_IT_ALARM BIT(3)
11192adb96aSSekhar Nori #define OMAP_RTC_INTERRUPTS_IT_TIMER BIT(2)
112db68b189SDavid Brownell
113cd914bbaSSekhar Nori /* OMAP_RTC_OSC_REG bit fields: */
114cd914bbaSSekhar Nori #define OMAP_RTC_OSC_32KCLK_EN BIT(6)
115399cf0f6SKeerthy #define OMAP_RTC_OSC_SEL_32KCLK_SRC BIT(3)
1163984903aSLokesh Vutla #define OMAP_RTC_OSC_OSC32K_GZ_DISABLE BIT(4)
117cd914bbaSSekhar Nori
1188af750e3SHebbar Gururaja /* OMAP_RTC_IRQWAKEEN bit fields: */
11992adb96aSSekhar Nori #define OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN BIT(1)
1208af750e3SHebbar Gururaja
121222a12fcSJohan Hovold /* OMAP_RTC_PMIC bit fields: */
122222a12fcSJohan Hovold #define OMAP_RTC_PMIC_POWER_EN_EN BIT(16)
12397ea1906SMarcin Niestroj #define OMAP_RTC_PMIC_EXT_WKUP_EN(x) BIT(x)
12497ea1906SMarcin Niestroj #define OMAP_RTC_PMIC_EXT_WKUP_POL(x) BIT(4 + x)
125222a12fcSJohan Hovold
126cab1458cSAfzal Mohammed /* OMAP_RTC_KICKER values */
127cab1458cSAfzal Mohammed #define KICK0_VALUE 0x83e70b13
128cab1458cSAfzal Mohammed #define KICK1_VALUE 0x95a4f1e0
129cab1458cSAfzal Mohammed
1309c28bd07SLokesh Vutla struct omap_rtc;
1319c28bd07SLokesh Vutla
1322153f949SJohan Hovold struct omap_rtc_device_type {
1332153f949SJohan Hovold bool has_32kclk_en;
1342153f949SJohan Hovold bool has_irqwakeen;
135222a12fcSJohan Hovold bool has_pmic_mode;
1369291e340SJohan Hovold bool has_power_up_reset;
1379c28bd07SLokesh Vutla void (*lock)(struct omap_rtc *rtc);
1389c28bd07SLokesh Vutla void (*unlock)(struct omap_rtc *rtc);
1392153f949SJohan Hovold };
140cd914bbaSSekhar Nori
14155ba953aSJohan Hovold struct omap_rtc {
14255ba953aSJohan Hovold struct rtc_device *rtc;
14355ba953aSJohan Hovold void __iomem *base;
144532409aaSKeerthy struct clk *clk;
14555ba953aSJohan Hovold int irq_alarm;
14655ba953aSJohan Hovold int irq_timer;
14755ba953aSJohan Hovold u8 interrupts_reg;
148222a12fcSJohan Hovold bool is_pmic_controller;
149399cf0f6SKeerthy bool has_ext_clk;
150efce21fcSTero Kristo bool is_suspending;
1512153f949SJohan Hovold const struct omap_rtc_device_type *type;
15297ea1906SMarcin Niestroj struct pinctrl_dev *pctldev;
15355ba953aSJohan Hovold };
154db68b189SDavid Brownell
rtc_read(struct omap_rtc * rtc,unsigned int reg)15555ba953aSJohan Hovold static inline u8 rtc_read(struct omap_rtc *rtc, unsigned int reg)
15655ba953aSJohan Hovold {
15755ba953aSJohan Hovold return readb(rtc->base + reg);
15855ba953aSJohan Hovold }
159cab1458cSAfzal Mohammed
rtc_readl(struct omap_rtc * rtc,unsigned int reg)160c253a896SJohan Hovold static inline u32 rtc_readl(struct omap_rtc *rtc, unsigned int reg)
161c253a896SJohan Hovold {
162c253a896SJohan Hovold return readl(rtc->base + reg);
163c253a896SJohan Hovold }
164c253a896SJohan Hovold
rtc_write(struct omap_rtc * rtc,unsigned int reg,u8 val)16555ba953aSJohan Hovold static inline void rtc_write(struct omap_rtc *rtc, unsigned int reg, u8 val)
16655ba953aSJohan Hovold {
16755ba953aSJohan Hovold writeb(val, rtc->base + reg);
16855ba953aSJohan Hovold }
169db68b189SDavid Brownell
rtc_writel(struct omap_rtc * rtc,unsigned int reg,u32 val)17055ba953aSJohan Hovold static inline void rtc_writel(struct omap_rtc *rtc, unsigned int reg, u32 val)
17155ba953aSJohan Hovold {
17255ba953aSJohan Hovold writel(val, rtc->base + reg);
17355ba953aSJohan Hovold }
174db68b189SDavid Brownell
am3352_rtc_unlock(struct omap_rtc * rtc)1759c28bd07SLokesh Vutla static void am3352_rtc_unlock(struct omap_rtc *rtc)
1769c28bd07SLokesh Vutla {
1779c28bd07SLokesh Vutla rtc_writel(rtc, OMAP_RTC_KICK0_REG, KICK0_VALUE);
1789c28bd07SLokesh Vutla rtc_writel(rtc, OMAP_RTC_KICK1_REG, KICK1_VALUE);
1799c28bd07SLokesh Vutla }
1809c28bd07SLokesh Vutla
am3352_rtc_lock(struct omap_rtc * rtc)1819c28bd07SLokesh Vutla static void am3352_rtc_lock(struct omap_rtc *rtc)
1829c28bd07SLokesh Vutla {
1839c28bd07SLokesh Vutla rtc_writel(rtc, OMAP_RTC_KICK0_REG, 0);
1849c28bd07SLokesh Vutla rtc_writel(rtc, OMAP_RTC_KICK1_REG, 0);
1859c28bd07SLokesh Vutla }
1869c28bd07SLokesh Vutla
default_rtc_unlock(struct omap_rtc * rtc)1879c28bd07SLokesh Vutla static void default_rtc_unlock(struct omap_rtc *rtc)
1889c28bd07SLokesh Vutla {
1899c28bd07SLokesh Vutla }
1909c28bd07SLokesh Vutla
default_rtc_lock(struct omap_rtc * rtc)1919c28bd07SLokesh Vutla static void default_rtc_lock(struct omap_rtc *rtc)
1929c28bd07SLokesh Vutla {
1939c28bd07SLokesh Vutla }
1949c28bd07SLokesh Vutla
19510211ae3SJohan Hovold /*
19610211ae3SJohan Hovold * We rely on the rtc framework to handle locking (rtc->ops_lock),
197db68b189SDavid Brownell * so the only other requirement is that register accesses which
198db68b189SDavid Brownell * require BUSY to be clear are made with IRQs locally disabled
199db68b189SDavid Brownell */
rtc_wait_not_busy(struct omap_rtc * rtc)20055ba953aSJohan Hovold static void rtc_wait_not_busy(struct omap_rtc *rtc)
201db68b189SDavid Brownell {
20210211ae3SJohan Hovold int count;
203db68b189SDavid Brownell u8 status;
204db68b189SDavid Brownell
205db68b189SDavid Brownell /* BUSY may stay active for 1/32768 second (~30 usec) */
206db68b189SDavid Brownell for (count = 0; count < 50; count++) {
20755ba953aSJohan Hovold status = rtc_read(rtc, OMAP_RTC_STATUS_REG);
20810211ae3SJohan Hovold if (!(status & OMAP_RTC_STATUS_BUSY))
209db68b189SDavid Brownell break;
210db68b189SDavid Brownell udelay(1);
211db68b189SDavid Brownell }
212db68b189SDavid Brownell /* now we have ~15 usec to read/write various registers */
213db68b189SDavid Brownell }
214db68b189SDavid Brownell
rtc_irq(int irq,void * dev_id)21555ba953aSJohan Hovold static irqreturn_t rtc_irq(int irq, void *dev_id)
216db68b189SDavid Brownell {
21755ba953aSJohan Hovold struct omap_rtc *rtc = dev_id;
218db68b189SDavid Brownell unsigned long events = 0;
219db68b189SDavid Brownell u8 irq_data;
220db68b189SDavid Brownell
22155ba953aSJohan Hovold irq_data = rtc_read(rtc, OMAP_RTC_STATUS_REG);
222db68b189SDavid Brownell
223db68b189SDavid Brownell /* alarm irq? */
224db68b189SDavid Brownell if (irq_data & OMAP_RTC_STATUS_ALARM) {
2259c28bd07SLokesh Vutla rtc->type->unlock(rtc);
22655ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_STATUS_REG, OMAP_RTC_STATUS_ALARM);
2279c28bd07SLokesh Vutla rtc->type->lock(rtc);
228db68b189SDavid Brownell events |= RTC_IRQF | RTC_AF;
229db68b189SDavid Brownell }
230db68b189SDavid Brownell
231db68b189SDavid Brownell /* 1/sec periodic/update irq? */
232db68b189SDavid Brownell if (irq_data & OMAP_RTC_STATUS_1S_EVENT)
233db68b189SDavid Brownell events |= RTC_IRQF | RTC_UF;
234db68b189SDavid Brownell
23555ba953aSJohan Hovold rtc_update_irq(rtc->rtc, 1, events);
236db68b189SDavid Brownell
237db68b189SDavid Brownell return IRQ_HANDLED;
238db68b189SDavid Brownell }
239db68b189SDavid Brownell
omap_rtc_alarm_irq_enable(struct device * dev,unsigned int enabled)24016380c15SJohn Stultz static int omap_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
24116380c15SJohn Stultz {
24255ba953aSJohan Hovold struct omap_rtc *rtc = dev_get_drvdata(dev);
243ab7f580bSLokesh Vutla u8 reg, irqwake_reg = 0;
24416380c15SJohn Stultz
24516380c15SJohn Stultz local_irq_disable();
24655ba953aSJohan Hovold rtc_wait_not_busy(rtc);
24755ba953aSJohan Hovold reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG);
2482153f949SJohan Hovold if (rtc->type->has_irqwakeen)
24955ba953aSJohan Hovold irqwake_reg = rtc_read(rtc, OMAP_RTC_IRQWAKEEN);
250ab7f580bSLokesh Vutla
251ab7f580bSLokesh Vutla if (enabled) {
25216380c15SJohn Stultz reg |= OMAP_RTC_INTERRUPTS_IT_ALARM;
253ab7f580bSLokesh Vutla irqwake_reg |= OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN;
254ab7f580bSLokesh Vutla } else {
25516380c15SJohn Stultz reg &= ~OMAP_RTC_INTERRUPTS_IT_ALARM;
256ab7f580bSLokesh Vutla irqwake_reg &= ~OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN;
257ab7f580bSLokesh Vutla }
25855ba953aSJohan Hovold rtc_wait_not_busy(rtc);
2599c28bd07SLokesh Vutla rtc->type->unlock(rtc);
26055ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg);
2612153f949SJohan Hovold if (rtc->type->has_irqwakeen)
26255ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg);
2639c28bd07SLokesh Vutla rtc->type->lock(rtc);
26416380c15SJohn Stultz local_irq_enable();
26516380c15SJohn Stultz
26616380c15SJohn Stultz return 0;
26716380c15SJohn Stultz }
26816380c15SJohn Stultz
269db68b189SDavid Brownell /* this hardware doesn't support "don't care" alarm fields */
tm2bcd(struct rtc_time * tm)27035118b7aSAlexandre Belloni static void tm2bcd(struct rtc_time *tm)
271db68b189SDavid Brownell {
272fe20ba70SAdrian Bunk tm->tm_sec = bin2bcd(tm->tm_sec);
273fe20ba70SAdrian Bunk tm->tm_min = bin2bcd(tm->tm_min);
274fe20ba70SAdrian Bunk tm->tm_hour = bin2bcd(tm->tm_hour);
275fe20ba70SAdrian Bunk tm->tm_mday = bin2bcd(tm->tm_mday);
276db68b189SDavid Brownell
277fe20ba70SAdrian Bunk tm->tm_mon = bin2bcd(tm->tm_mon + 1);
278fe20ba70SAdrian Bunk tm->tm_year = bin2bcd(tm->tm_year - 100);
279db68b189SDavid Brownell }
280db68b189SDavid Brownell
bcd2tm(struct rtc_time * tm)281db68b189SDavid Brownell static void bcd2tm(struct rtc_time *tm)
282db68b189SDavid Brownell {
283fe20ba70SAdrian Bunk tm->tm_sec = bcd2bin(tm->tm_sec);
284fe20ba70SAdrian Bunk tm->tm_min = bcd2bin(tm->tm_min);
285fe20ba70SAdrian Bunk tm->tm_hour = bcd2bin(tm->tm_hour);
286fe20ba70SAdrian Bunk tm->tm_mday = bcd2bin(tm->tm_mday);
287fe20ba70SAdrian Bunk tm->tm_mon = bcd2bin(tm->tm_mon) - 1;
288db68b189SDavid Brownell /* epoch == 1900 */
289fe20ba70SAdrian Bunk tm->tm_year = bcd2bin(tm->tm_year) + 100;
290db68b189SDavid Brownell }
291db68b189SDavid Brownell
omap_rtc_read_time_raw(struct omap_rtc * rtc,struct rtc_time * tm)292cbbe326fSJohan Hovold static void omap_rtc_read_time_raw(struct omap_rtc *rtc, struct rtc_time *tm)
293cbbe326fSJohan Hovold {
294cbbe326fSJohan Hovold tm->tm_sec = rtc_read(rtc, OMAP_RTC_SECONDS_REG);
295cbbe326fSJohan Hovold tm->tm_min = rtc_read(rtc, OMAP_RTC_MINUTES_REG);
296cbbe326fSJohan Hovold tm->tm_hour = rtc_read(rtc, OMAP_RTC_HOURS_REG);
297cbbe326fSJohan Hovold tm->tm_mday = rtc_read(rtc, OMAP_RTC_DAYS_REG);
298cbbe326fSJohan Hovold tm->tm_mon = rtc_read(rtc, OMAP_RTC_MONTHS_REG);
299cbbe326fSJohan Hovold tm->tm_year = rtc_read(rtc, OMAP_RTC_YEARS_REG);
300cbbe326fSJohan Hovold }
301db68b189SDavid Brownell
omap_rtc_read_time(struct device * dev,struct rtc_time * tm)302db68b189SDavid Brownell static int omap_rtc_read_time(struct device *dev, struct rtc_time *tm)
303db68b189SDavid Brownell {
30455ba953aSJohan Hovold struct omap_rtc *rtc = dev_get_drvdata(dev);
30555ba953aSJohan Hovold
306db68b189SDavid Brownell /* we don't report wday/yday/isdst ... */
307db68b189SDavid Brownell local_irq_disable();
30855ba953aSJohan Hovold rtc_wait_not_busy(rtc);
309cbbe326fSJohan Hovold omap_rtc_read_time_raw(rtc, tm);
310db68b189SDavid Brownell local_irq_enable();
311db68b189SDavid Brownell
312db68b189SDavid Brownell bcd2tm(tm);
31310211ae3SJohan Hovold
314db68b189SDavid Brownell return 0;
315db68b189SDavid Brownell }
316db68b189SDavid Brownell
omap_rtc_set_time(struct device * dev,struct rtc_time * tm)317db68b189SDavid Brownell static int omap_rtc_set_time(struct device *dev, struct rtc_time *tm)
318db68b189SDavid Brownell {
31955ba953aSJohan Hovold struct omap_rtc *rtc = dev_get_drvdata(dev);
32055ba953aSJohan Hovold
32135118b7aSAlexandre Belloni tm2bcd(tm);
32210211ae3SJohan Hovold
323db68b189SDavid Brownell local_irq_disable();
32455ba953aSJohan Hovold rtc_wait_not_busy(rtc);
325db68b189SDavid Brownell
3269c28bd07SLokesh Vutla rtc->type->unlock(rtc);
32755ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_YEARS_REG, tm->tm_year);
32855ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_MONTHS_REG, tm->tm_mon);
32955ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_DAYS_REG, tm->tm_mday);
33055ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_HOURS_REG, tm->tm_hour);
33155ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_MINUTES_REG, tm->tm_min);
33255ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_SECONDS_REG, tm->tm_sec);
3339c28bd07SLokesh Vutla rtc->type->lock(rtc);
334db68b189SDavid Brownell
335db68b189SDavid Brownell local_irq_enable();
336db68b189SDavid Brownell
337db68b189SDavid Brownell return 0;
338db68b189SDavid Brownell }
339db68b189SDavid Brownell
omap_rtc_read_alarm(struct device * dev,struct rtc_wkalrm * alm)340db68b189SDavid Brownell static int omap_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
341db68b189SDavid Brownell {
34255ba953aSJohan Hovold struct omap_rtc *rtc = dev_get_drvdata(dev);
34310211ae3SJohan Hovold u8 interrupts;
344db68b189SDavid Brownell
34555ba953aSJohan Hovold local_irq_disable();
34655ba953aSJohan Hovold rtc_wait_not_busy(rtc);
34755ba953aSJohan Hovold
34855ba953aSJohan Hovold alm->time.tm_sec = rtc_read(rtc, OMAP_RTC_ALARM_SECONDS_REG);
34955ba953aSJohan Hovold alm->time.tm_min = rtc_read(rtc, OMAP_RTC_ALARM_MINUTES_REG);
35055ba953aSJohan Hovold alm->time.tm_hour = rtc_read(rtc, OMAP_RTC_ALARM_HOURS_REG);
35155ba953aSJohan Hovold alm->time.tm_mday = rtc_read(rtc, OMAP_RTC_ALARM_DAYS_REG);
35255ba953aSJohan Hovold alm->time.tm_mon = rtc_read(rtc, OMAP_RTC_ALARM_MONTHS_REG);
35355ba953aSJohan Hovold alm->time.tm_year = rtc_read(rtc, OMAP_RTC_ALARM_YEARS_REG);
354db68b189SDavid Brownell
355db68b189SDavid Brownell local_irq_enable();
356db68b189SDavid Brownell
357db68b189SDavid Brownell bcd2tm(&alm->time);
35810211ae3SJohan Hovold
35910211ae3SJohan Hovold interrupts = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG);
36010211ae3SJohan Hovold alm->enabled = !!(interrupts & OMAP_RTC_INTERRUPTS_IT_ALARM);
361db68b189SDavid Brownell
362db68b189SDavid Brownell return 0;
363db68b189SDavid Brownell }
364db68b189SDavid Brownell
omap_rtc_set_alarm(struct device * dev,struct rtc_wkalrm * alm)365db68b189SDavid Brownell static int omap_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
366db68b189SDavid Brownell {
36755ba953aSJohan Hovold struct omap_rtc *rtc = dev_get_drvdata(dev);
368ab7f580bSLokesh Vutla u8 reg, irqwake_reg = 0;
369db68b189SDavid Brownell
37035118b7aSAlexandre Belloni tm2bcd(&alm->time);
371db68b189SDavid Brownell
372db68b189SDavid Brownell local_irq_disable();
37355ba953aSJohan Hovold rtc_wait_not_busy(rtc);
374db68b189SDavid Brownell
3759c28bd07SLokesh Vutla rtc->type->unlock(rtc);
37655ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_ALARM_YEARS_REG, alm->time.tm_year);
37755ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_ALARM_MONTHS_REG, alm->time.tm_mon);
37855ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_ALARM_DAYS_REG, alm->time.tm_mday);
37955ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_ALARM_HOURS_REG, alm->time.tm_hour);
38055ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_ALARM_MINUTES_REG, alm->time.tm_min);
38155ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_ALARM_SECONDS_REG, alm->time.tm_sec);
382db68b189SDavid Brownell
38355ba953aSJohan Hovold reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG);
3842153f949SJohan Hovold if (rtc->type->has_irqwakeen)
38555ba953aSJohan Hovold irqwake_reg = rtc_read(rtc, OMAP_RTC_IRQWAKEEN);
386ab7f580bSLokesh Vutla
387ab7f580bSLokesh Vutla if (alm->enabled) {
388db68b189SDavid Brownell reg |= OMAP_RTC_INTERRUPTS_IT_ALARM;
389ab7f580bSLokesh Vutla irqwake_reg |= OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN;
390ab7f580bSLokesh Vutla } else {
391db68b189SDavid Brownell reg &= ~OMAP_RTC_INTERRUPTS_IT_ALARM;
392ab7f580bSLokesh Vutla irqwake_reg &= ~OMAP_RTC_IRQWAKEEN_ALARM_WAKEEN;
393ab7f580bSLokesh Vutla }
39455ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, reg);
3952153f949SJohan Hovold if (rtc->type->has_irqwakeen)
39655ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_IRQWAKEEN, irqwake_reg);
3979c28bd07SLokesh Vutla rtc->type->lock(rtc);
398db68b189SDavid Brownell
399db68b189SDavid Brownell local_irq_enable();
400db68b189SDavid Brownell
401db68b189SDavid Brownell return 0;
402db68b189SDavid Brownell }
403db68b189SDavid Brownell
404222a12fcSJohan Hovold static struct omap_rtc *omap_rtc_power_off_rtc;
405222a12fcSJohan Hovold
4066256f7f7SKeerthy /**
4076256f7f7SKeerthy * omap_rtc_power_off_program: Set the pmic power off sequence. The RTC
4086256f7f7SKeerthy * generates pmic_pwr_enable control, which can be used to control an external
4096256f7f7SKeerthy * PMIC.
410222a12fcSJohan Hovold */
omap_rtc_power_off_program(struct device * dev)4116256f7f7SKeerthy int omap_rtc_power_off_program(struct device *dev)
412222a12fcSJohan Hovold {
413222a12fcSJohan Hovold struct omap_rtc *rtc = omap_rtc_power_off_rtc;
414222a12fcSJohan Hovold struct rtc_time tm;
415222a12fcSJohan Hovold unsigned long now;
41609058eabSKeerthy int seconds;
417222a12fcSJohan Hovold u32 val;
418222a12fcSJohan Hovold
4199c28bd07SLokesh Vutla rtc->type->unlock(rtc);
420222a12fcSJohan Hovold /* enable pmic_power_en control */
421222a12fcSJohan Hovold val = rtc_readl(rtc, OMAP_RTC_PMIC_REG);
422222a12fcSJohan Hovold rtc_writel(rtc, OMAP_RTC_PMIC_REG, val | OMAP_RTC_PMIC_POWER_EN_EN);
423222a12fcSJohan Hovold
42409058eabSKeerthy again:
4256256f7f7SKeerthy /* Clear any existing ALARM2 event */
4266256f7f7SKeerthy rtc_writel(rtc, OMAP_RTC_STATUS_REG, OMAP_RTC_STATUS_ALARM2);
4276256f7f7SKeerthy
42809058eabSKeerthy /* set alarm one second from now */
429222a12fcSJohan Hovold omap_rtc_read_time_raw(rtc, &tm);
43009058eabSKeerthy seconds = tm.tm_sec;
431222a12fcSJohan Hovold bcd2tm(&tm);
43228c6852eSAlexandre Belloni now = rtc_tm_to_time64(&tm);
43328c6852eSAlexandre Belloni rtc_time64_to_tm(now + 1, &tm);
434222a12fcSJohan Hovold
43535118b7aSAlexandre Belloni tm2bcd(&tm);
436222a12fcSJohan Hovold
437222a12fcSJohan Hovold rtc_wait_not_busy(rtc);
438222a12fcSJohan Hovold
439222a12fcSJohan Hovold rtc_write(rtc, OMAP_RTC_ALARM2_SECONDS_REG, tm.tm_sec);
440222a12fcSJohan Hovold rtc_write(rtc, OMAP_RTC_ALARM2_MINUTES_REG, tm.tm_min);
441222a12fcSJohan Hovold rtc_write(rtc, OMAP_RTC_ALARM2_HOURS_REG, tm.tm_hour);
442222a12fcSJohan Hovold rtc_write(rtc, OMAP_RTC_ALARM2_DAYS_REG, tm.tm_mday);
443222a12fcSJohan Hovold rtc_write(rtc, OMAP_RTC_ALARM2_MONTHS_REG, tm.tm_mon);
444222a12fcSJohan Hovold rtc_write(rtc, OMAP_RTC_ALARM2_YEARS_REG, tm.tm_year);
445222a12fcSJohan Hovold
446222a12fcSJohan Hovold /*
447222a12fcSJohan Hovold * enable ALARM2 interrupt
448222a12fcSJohan Hovold *
449222a12fcSJohan Hovold * NOTE: this fails on AM3352 if rtc_write (writeb) is used
450222a12fcSJohan Hovold */
451222a12fcSJohan Hovold val = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG);
452222a12fcSJohan Hovold rtc_writel(rtc, OMAP_RTC_INTERRUPTS_REG,
453222a12fcSJohan Hovold val | OMAP_RTC_INTERRUPTS_IT_ALARM2);
45409058eabSKeerthy
45509058eabSKeerthy /* Retry in case roll over happened before alarm was armed. */
45609058eabSKeerthy if (rtc_read(rtc, OMAP_RTC_SECONDS_REG) != seconds) {
45709058eabSKeerthy val = rtc_read(rtc, OMAP_RTC_STATUS_REG);
45809058eabSKeerthy if (!(val & OMAP_RTC_STATUS_ALARM2))
45909058eabSKeerthy goto again;
46009058eabSKeerthy }
46109058eabSKeerthy
4629c28bd07SLokesh Vutla rtc->type->lock(rtc);
463222a12fcSJohan Hovold
4646256f7f7SKeerthy return 0;
4656256f7f7SKeerthy }
4666256f7f7SKeerthy EXPORT_SYMBOL(omap_rtc_power_off_program);
4676256f7f7SKeerthy
4686256f7f7SKeerthy /*
4696256f7f7SKeerthy * omap_rtc_poweroff: RTC-controlled power off
4706256f7f7SKeerthy *
4716256f7f7SKeerthy * The RTC can be used to control an external PMIC via the pmic_power_en pin,
4726256f7f7SKeerthy * which can be configured to transition to OFF on ALARM2 events.
4736256f7f7SKeerthy *
4746256f7f7SKeerthy * Notes:
4756256f7f7SKeerthy * The one-second alarm offset is the shortest offset possible as the alarm
4766256f7f7SKeerthy * registers must be set before the next timer update and the offset
4776256f7f7SKeerthy * calculation is too heavy for everything to be done within a single access
4786256f7f7SKeerthy * period (~15 us).
4796256f7f7SKeerthy *
4806256f7f7SKeerthy * Called with local interrupts disabled.
4816256f7f7SKeerthy */
omap_rtc_power_off(void)4826256f7f7SKeerthy static void omap_rtc_power_off(void)
4836256f7f7SKeerthy {
4846256f7f7SKeerthy struct rtc_device *rtc = omap_rtc_power_off_rtc->rtc;
4856256f7f7SKeerthy u32 val;
4866256f7f7SKeerthy
4876256f7f7SKeerthy omap_rtc_power_off_program(rtc->dev.parent);
4886256f7f7SKeerthy
4896256f7f7SKeerthy /* Set PMIC power enable and EXT_WAKEUP in case PB power on is used */
4906256f7f7SKeerthy omap_rtc_power_off_rtc->type->unlock(omap_rtc_power_off_rtc);
4916256f7f7SKeerthy val = rtc_readl(omap_rtc_power_off_rtc, OMAP_RTC_PMIC_REG);
4926256f7f7SKeerthy val |= OMAP_RTC_PMIC_POWER_EN_EN | OMAP_RTC_PMIC_EXT_WKUP_POL(0) |
4936256f7f7SKeerthy OMAP_RTC_PMIC_EXT_WKUP_EN(0);
4946256f7f7SKeerthy rtc_writel(omap_rtc_power_off_rtc, OMAP_RTC_PMIC_REG, val);
4956256f7f7SKeerthy omap_rtc_power_off_rtc->type->lock(omap_rtc_power_off_rtc);
4966256f7f7SKeerthy
497222a12fcSJohan Hovold /*
49809058eabSKeerthy * Wait for alarm to trigger (within one second) and external PMIC to
499222a12fcSJohan Hovold * power off the system. Add a 500 ms margin for external latencies
500222a12fcSJohan Hovold * (e.g. debounce circuits).
501222a12fcSJohan Hovold */
50209058eabSKeerthy mdelay(1500);
503222a12fcSJohan Hovold }
504222a12fcSJohan Hovold
50534c7b3acSJulia Lawall static const struct rtc_class_ops omap_rtc_ops = {
506db68b189SDavid Brownell .read_time = omap_rtc_read_time,
507db68b189SDavid Brownell .set_time = omap_rtc_set_time,
508db68b189SDavid Brownell .read_alarm = omap_rtc_read_alarm,
509db68b189SDavid Brownell .set_alarm = omap_rtc_set_alarm,
51016380c15SJohn Stultz .alarm_irq_enable = omap_rtc_alarm_irq_enable,
511db68b189SDavid Brownell };
512db68b189SDavid Brownell
5132153f949SJohan Hovold static const struct omap_rtc_device_type omap_rtc_default_type = {
5149291e340SJohan Hovold .has_power_up_reset = true,
5159c28bd07SLokesh Vutla .lock = default_rtc_lock,
5169c28bd07SLokesh Vutla .unlock = default_rtc_unlock,
5172153f949SJohan Hovold };
5189e0344dcSAfzal Mohammed
5192153f949SJohan Hovold static const struct omap_rtc_device_type omap_rtc_am3352_type = {
5202153f949SJohan Hovold .has_32kclk_en = true,
5212153f949SJohan Hovold .has_irqwakeen = true,
522222a12fcSJohan Hovold .has_pmic_mode = true,
5239c28bd07SLokesh Vutla .lock = am3352_rtc_lock,
5249c28bd07SLokesh Vutla .unlock = am3352_rtc_unlock,
5252153f949SJohan Hovold };
5262153f949SJohan Hovold
5272153f949SJohan Hovold static const struct omap_rtc_device_type omap_rtc_da830_type = {
5289c28bd07SLokesh Vutla .lock = am3352_rtc_lock,
5299c28bd07SLokesh Vutla .unlock = am3352_rtc_unlock,
5302153f949SJohan Hovold };
5312153f949SJohan Hovold
5322153f949SJohan Hovold static const struct platform_device_id omap_rtc_id_table[] = {
533cab1458cSAfzal Mohammed {
534a430ca22SJohan Hovold .name = "omap_rtc",
5352153f949SJohan Hovold .driver_data = (kernel_ulong_t)&omap_rtc_default_type,
5362153f949SJohan Hovold }, {
5378af750e3SHebbar Gururaja .name = "am3352-rtc",
5382153f949SJohan Hovold .driver_data = (kernel_ulong_t)&omap_rtc_am3352_type,
5392153f949SJohan Hovold }, {
540cab1458cSAfzal Mohammed .name = "da830-rtc",
5412153f949SJohan Hovold .driver_data = (kernel_ulong_t)&omap_rtc_da830_type,
5422153f949SJohan Hovold }, {
5432153f949SJohan Hovold /* sentinel */
5442153f949SJohan Hovold }
545cab1458cSAfzal Mohammed };
5462153f949SJohan Hovold MODULE_DEVICE_TABLE(platform, omap_rtc_id_table);
547cab1458cSAfzal Mohammed
5489e0344dcSAfzal Mohammed static const struct of_device_id omap_rtc_of_match[] = {
5492153f949SJohan Hovold {
5502153f949SJohan Hovold .compatible = "ti,am3352-rtc",
5512153f949SJohan Hovold .data = &omap_rtc_am3352_type,
5522153f949SJohan Hovold }, {
5532153f949SJohan Hovold .compatible = "ti,da830-rtc",
5542153f949SJohan Hovold .data = &omap_rtc_da830_type,
5552153f949SJohan Hovold }, {
5562153f949SJohan Hovold /* sentinel */
5572153f949SJohan Hovold }
5589e0344dcSAfzal Mohammed };
5599e0344dcSAfzal Mohammed MODULE_DEVICE_TABLE(of, omap_rtc_of_match);
5609e0344dcSAfzal Mohammed
56197ea1906SMarcin Niestroj static const struct pinctrl_pin_desc rtc_pins_desc[] = {
56297ea1906SMarcin Niestroj PINCTRL_PIN(0, "ext_wakeup0"),
56397ea1906SMarcin Niestroj PINCTRL_PIN(1, "ext_wakeup1"),
56497ea1906SMarcin Niestroj PINCTRL_PIN(2, "ext_wakeup2"),
56597ea1906SMarcin Niestroj PINCTRL_PIN(3, "ext_wakeup3"),
56697ea1906SMarcin Niestroj };
56797ea1906SMarcin Niestroj
rtc_pinctrl_get_groups_count(struct pinctrl_dev * pctldev)56897ea1906SMarcin Niestroj static int rtc_pinctrl_get_groups_count(struct pinctrl_dev *pctldev)
56997ea1906SMarcin Niestroj {
57097ea1906SMarcin Niestroj return 0;
57197ea1906SMarcin Niestroj }
57297ea1906SMarcin Niestroj
rtc_pinctrl_get_group_name(struct pinctrl_dev * pctldev,unsigned int group)57397ea1906SMarcin Niestroj static const char *rtc_pinctrl_get_group_name(struct pinctrl_dev *pctldev,
57497ea1906SMarcin Niestroj unsigned int group)
57597ea1906SMarcin Niestroj {
57697ea1906SMarcin Niestroj return NULL;
57797ea1906SMarcin Niestroj }
57897ea1906SMarcin Niestroj
57997ea1906SMarcin Niestroj static const struct pinctrl_ops rtc_pinctrl_ops = {
58097ea1906SMarcin Niestroj .get_groups_count = rtc_pinctrl_get_groups_count,
58197ea1906SMarcin Niestroj .get_group_name = rtc_pinctrl_get_group_name,
58297ea1906SMarcin Niestroj .dt_node_to_map = pinconf_generic_dt_node_to_map_pin,
58397ea1906SMarcin Niestroj .dt_free_map = pinconf_generic_dt_free_map,
58497ea1906SMarcin Niestroj };
58597ea1906SMarcin Niestroj
586c5015652SNathan Chancellor #define PIN_CONFIG_ACTIVE_HIGH (PIN_CONFIG_END + 1)
58797ea1906SMarcin Niestroj
58897ea1906SMarcin Niestroj static const struct pinconf_generic_params rtc_params[] = {
58997ea1906SMarcin Niestroj {"ti,active-high", PIN_CONFIG_ACTIVE_HIGH, 0},
59097ea1906SMarcin Niestroj };
59197ea1906SMarcin Niestroj
59297ea1906SMarcin Niestroj #ifdef CONFIG_DEBUG_FS
59397ea1906SMarcin Niestroj static const struct pin_config_item rtc_conf_items[ARRAY_SIZE(rtc_params)] = {
59497ea1906SMarcin Niestroj PCONFDUMP(PIN_CONFIG_ACTIVE_HIGH, "input active high", NULL, false),
59597ea1906SMarcin Niestroj };
59697ea1906SMarcin Niestroj #endif
59797ea1906SMarcin Niestroj
rtc_pinconf_get(struct pinctrl_dev * pctldev,unsigned int pin,unsigned long * config)59897ea1906SMarcin Niestroj static int rtc_pinconf_get(struct pinctrl_dev *pctldev,
59997ea1906SMarcin Niestroj unsigned int pin, unsigned long *config)
60097ea1906SMarcin Niestroj {
60197ea1906SMarcin Niestroj struct omap_rtc *rtc = pinctrl_dev_get_drvdata(pctldev);
60297ea1906SMarcin Niestroj unsigned int param = pinconf_to_config_param(*config);
60397ea1906SMarcin Niestroj u32 val;
60497ea1906SMarcin Niestroj u16 arg = 0;
60597ea1906SMarcin Niestroj
60697ea1906SMarcin Niestroj val = rtc_readl(rtc, OMAP_RTC_PMIC_REG);
60797ea1906SMarcin Niestroj
60897ea1906SMarcin Niestroj switch (param) {
60997ea1906SMarcin Niestroj case PIN_CONFIG_INPUT_ENABLE:
61097ea1906SMarcin Niestroj if (!(val & OMAP_RTC_PMIC_EXT_WKUP_EN(pin)))
61197ea1906SMarcin Niestroj return -EINVAL;
61297ea1906SMarcin Niestroj break;
61397ea1906SMarcin Niestroj case PIN_CONFIG_ACTIVE_HIGH:
61497ea1906SMarcin Niestroj if (val & OMAP_RTC_PMIC_EXT_WKUP_POL(pin))
61597ea1906SMarcin Niestroj return -EINVAL;
61697ea1906SMarcin Niestroj break;
61797ea1906SMarcin Niestroj default:
61897ea1906SMarcin Niestroj return -ENOTSUPP;
619de050566Szhengbin }
62097ea1906SMarcin Niestroj
62197ea1906SMarcin Niestroj *config = pinconf_to_config_packed(param, arg);
62297ea1906SMarcin Niestroj
62397ea1906SMarcin Niestroj return 0;
62497ea1906SMarcin Niestroj }
62597ea1906SMarcin Niestroj
rtc_pinconf_set(struct pinctrl_dev * pctldev,unsigned int pin,unsigned long * configs,unsigned int num_configs)62697ea1906SMarcin Niestroj static int rtc_pinconf_set(struct pinctrl_dev *pctldev,
62797ea1906SMarcin Niestroj unsigned int pin, unsigned long *configs,
62897ea1906SMarcin Niestroj unsigned int num_configs)
62997ea1906SMarcin Niestroj {
63097ea1906SMarcin Niestroj struct omap_rtc *rtc = pinctrl_dev_get_drvdata(pctldev);
63197ea1906SMarcin Niestroj u32 val;
63297ea1906SMarcin Niestroj unsigned int param;
63358957d2eSMika Westerberg u32 param_val;
63497ea1906SMarcin Niestroj int i;
63597ea1906SMarcin Niestroj
63697ea1906SMarcin Niestroj val = rtc_readl(rtc, OMAP_RTC_PMIC_REG);
63797ea1906SMarcin Niestroj
63897ea1906SMarcin Niestroj /* active low by default */
63997ea1906SMarcin Niestroj val |= OMAP_RTC_PMIC_EXT_WKUP_POL(pin);
64097ea1906SMarcin Niestroj
64197ea1906SMarcin Niestroj for (i = 0; i < num_configs; i++) {
64297ea1906SMarcin Niestroj param = pinconf_to_config_param(configs[i]);
64397ea1906SMarcin Niestroj param_val = pinconf_to_config_argument(configs[i]);
64497ea1906SMarcin Niestroj
64597ea1906SMarcin Niestroj switch (param) {
64697ea1906SMarcin Niestroj case PIN_CONFIG_INPUT_ENABLE:
64797ea1906SMarcin Niestroj if (param_val)
64897ea1906SMarcin Niestroj val |= OMAP_RTC_PMIC_EXT_WKUP_EN(pin);
64997ea1906SMarcin Niestroj else
65097ea1906SMarcin Niestroj val &= ~OMAP_RTC_PMIC_EXT_WKUP_EN(pin);
65197ea1906SMarcin Niestroj break;
65297ea1906SMarcin Niestroj case PIN_CONFIG_ACTIVE_HIGH:
65397ea1906SMarcin Niestroj val &= ~OMAP_RTC_PMIC_EXT_WKUP_POL(pin);
65497ea1906SMarcin Niestroj break;
65597ea1906SMarcin Niestroj default:
65697ea1906SMarcin Niestroj dev_err(&rtc->rtc->dev, "Property %u not supported\n",
65797ea1906SMarcin Niestroj param);
65897ea1906SMarcin Niestroj return -ENOTSUPP;
65997ea1906SMarcin Niestroj }
66097ea1906SMarcin Niestroj }
66197ea1906SMarcin Niestroj
66297ea1906SMarcin Niestroj rtc->type->unlock(rtc);
66397ea1906SMarcin Niestroj rtc_writel(rtc, OMAP_RTC_PMIC_REG, val);
66497ea1906SMarcin Niestroj rtc->type->lock(rtc);
66597ea1906SMarcin Niestroj
66697ea1906SMarcin Niestroj return 0;
66797ea1906SMarcin Niestroj }
66897ea1906SMarcin Niestroj
66997ea1906SMarcin Niestroj static const struct pinconf_ops rtc_pinconf_ops = {
67097ea1906SMarcin Niestroj .is_generic = true,
67197ea1906SMarcin Niestroj .pin_config_get = rtc_pinconf_get,
67297ea1906SMarcin Niestroj .pin_config_set = rtc_pinconf_set,
67397ea1906SMarcin Niestroj };
67497ea1906SMarcin Niestroj
67597ea1906SMarcin Niestroj static struct pinctrl_desc rtc_pinctrl_desc = {
67697ea1906SMarcin Niestroj .pins = rtc_pins_desc,
67797ea1906SMarcin Niestroj .npins = ARRAY_SIZE(rtc_pins_desc),
67897ea1906SMarcin Niestroj .pctlops = &rtc_pinctrl_ops,
67997ea1906SMarcin Niestroj .confops = &rtc_pinconf_ops,
68097ea1906SMarcin Niestroj .custom_params = rtc_params,
68197ea1906SMarcin Niestroj .num_custom_params = ARRAY_SIZE(rtc_params),
68297ea1906SMarcin Niestroj #ifdef CONFIG_DEBUG_FS
68397ea1906SMarcin Niestroj .custom_conf_items = rtc_conf_items,
68497ea1906SMarcin Niestroj #endif
68597ea1906SMarcin Niestroj .owner = THIS_MODULE,
68697ea1906SMarcin Niestroj };
68797ea1906SMarcin Niestroj
omap_rtc_scratch_read(void * priv,unsigned int offset,void * _val,size_t bytes)688b6ee15efSAlexandre Belloni static int omap_rtc_scratch_read(void *priv, unsigned int offset, void *_val,
689b6ee15efSAlexandre Belloni size_t bytes)
690b6ee15efSAlexandre Belloni {
691b6ee15efSAlexandre Belloni struct omap_rtc *rtc = priv;
692b6ee15efSAlexandre Belloni u32 *val = _val;
693b6ee15efSAlexandre Belloni int i;
694b6ee15efSAlexandre Belloni
695b6ee15efSAlexandre Belloni for (i = 0; i < bytes / 4; i++)
696b6ee15efSAlexandre Belloni val[i] = rtc_readl(rtc,
697b6ee15efSAlexandre Belloni OMAP_RTC_SCRATCH0_REG + offset + (i * 4));
698b6ee15efSAlexandre Belloni
699b6ee15efSAlexandre Belloni return 0;
700b6ee15efSAlexandre Belloni }
701b6ee15efSAlexandre Belloni
omap_rtc_scratch_write(void * priv,unsigned int offset,void * _val,size_t bytes)702b6ee15efSAlexandre Belloni static int omap_rtc_scratch_write(void *priv, unsigned int offset, void *_val,
703b6ee15efSAlexandre Belloni size_t bytes)
704b6ee15efSAlexandre Belloni {
705b6ee15efSAlexandre Belloni struct omap_rtc *rtc = priv;
706b6ee15efSAlexandre Belloni u32 *val = _val;
707b6ee15efSAlexandre Belloni int i;
708b6ee15efSAlexandre Belloni
709b6ee15efSAlexandre Belloni rtc->type->unlock(rtc);
710b6ee15efSAlexandre Belloni for (i = 0; i < bytes / 4; i++)
711b6ee15efSAlexandre Belloni rtc_writel(rtc,
712b6ee15efSAlexandre Belloni OMAP_RTC_SCRATCH0_REG + offset + (i * 4), val[i]);
713b6ee15efSAlexandre Belloni rtc->type->lock(rtc);
714b6ee15efSAlexandre Belloni
715b6ee15efSAlexandre Belloni return 0;
716b6ee15efSAlexandre Belloni }
717b6ee15efSAlexandre Belloni
718b6ee15efSAlexandre Belloni static struct nvmem_config omap_rtc_nvmem_config = {
719b6ee15efSAlexandre Belloni .name = "omap_rtc_scratch",
720b6ee15efSAlexandre Belloni .word_size = 4,
721b6ee15efSAlexandre Belloni .stride = 4,
722b6ee15efSAlexandre Belloni .size = OMAP_RTC_KICK0_REG - OMAP_RTC_SCRATCH0_REG,
723b6ee15efSAlexandre Belloni .reg_read = omap_rtc_scratch_read,
724b6ee15efSAlexandre Belloni .reg_write = omap_rtc_scratch_write,
725b6ee15efSAlexandre Belloni };
726b6ee15efSAlexandre Belloni
omap_rtc_probe(struct platform_device * pdev)7275d9094b6SLokesh Vutla static int omap_rtc_probe(struct platform_device *pdev)
728db68b189SDavid Brownell {
72955ba953aSJohan Hovold struct omap_rtc *rtc;
7309291e340SJohan Hovold u8 reg, mask, new_ctrl;
731cab1458cSAfzal Mohammed const struct platform_device_id *id_entry;
7329e0344dcSAfzal Mohammed const struct of_device_id *of_id;
733437b37a6SJohan Hovold int ret;
7349e0344dcSAfzal Mohammed
73555ba953aSJohan Hovold rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
73655ba953aSJohan Hovold if (!rtc)
73755ba953aSJohan Hovold return -ENOMEM;
73855ba953aSJohan Hovold
7399e0344dcSAfzal Mohammed of_id = of_match_device(omap_rtc_of_match, &pdev->dev);
7402153f949SJohan Hovold if (of_id) {
7412153f949SJohan Hovold rtc->type = of_id->data;
742222a12fcSJohan Hovold rtc->is_pmic_controller = rtc->type->has_pmic_mode &&
7430438002aSKeerthy of_device_is_system_power_controller(pdev->dev.of_node);
7442153f949SJohan Hovold } else {
745337b600fSSekhar Nori id_entry = platform_get_device_id(pdev);
7462153f949SJohan Hovold rtc->type = (void *)id_entry->driver_data;
747337b600fSSekhar Nori }
748337b600fSSekhar Nori
74955ba953aSJohan Hovold rtc->irq_timer = platform_get_irq(pdev, 0);
750*4d349a57SRuan Jinjie if (rtc->irq_timer < 0)
751*4d349a57SRuan Jinjie return rtc->irq_timer;
752db68b189SDavid Brownell
75355ba953aSJohan Hovold rtc->irq_alarm = platform_get_irq(pdev, 1);
754*4d349a57SRuan Jinjie if (rtc->irq_alarm < 0)
755*4d349a57SRuan Jinjie return rtc->irq_alarm;
756db68b189SDavid Brownell
757399cf0f6SKeerthy rtc->clk = devm_clk_get(&pdev->dev, "ext-clk");
758399cf0f6SKeerthy if (!IS_ERR(rtc->clk))
759399cf0f6SKeerthy rtc->has_ext_clk = true;
760399cf0f6SKeerthy else
761532409aaSKeerthy rtc->clk = devm_clk_get(&pdev->dev, "int-clk");
762532409aaSKeerthy
763532409aaSKeerthy if (!IS_ERR(rtc->clk))
764532409aaSKeerthy clk_prepare_enable(rtc->clk);
765532409aaSKeerthy
76609ef18bcSYueHaibing rtc->base = devm_platform_ioremap_resource(pdev, 0);
7672da6877fSAndreas Platschek if (IS_ERR(rtc->base)) {
7682da6877fSAndreas Platschek clk_disable_unprepare(rtc->clk);
76955ba953aSJohan Hovold return PTR_ERR(rtc->base);
7702da6877fSAndreas Platschek }
77155ba953aSJohan Hovold
77255ba953aSJohan Hovold platform_set_drvdata(pdev, rtc);
7738cfde8c1SMark A. Greer
774fc9bd902SVaibhav Hiremath /* Enable the clock/module so that we can access the registers */
775fc9bd902SVaibhav Hiremath pm_runtime_enable(&pdev->dev);
776fc9bd902SVaibhav Hiremath pm_runtime_get_sync(&pdev->dev);
777fc9bd902SVaibhav Hiremath
7789c28bd07SLokesh Vutla rtc->type->unlock(rtc);
779cab1458cSAfzal Mohammed
7801ed8b5d2SJohan Hovold /*
7811ed8b5d2SJohan Hovold * disable interrupts
7821ed8b5d2SJohan Hovold *
7831ed8b5d2SJohan Hovold * NOTE: ALARM2 is not cleared on AM3352 if rtc_write (writeb) is used
784db68b189SDavid Brownell */
78555ba953aSJohan Hovold rtc_writel(rtc, OMAP_RTC_INTERRUPTS_REG, 0);
786db68b189SDavid Brownell
787cd914bbaSSekhar Nori /* enable RTC functional clock */
7882153f949SJohan Hovold if (rtc->type->has_32kclk_en) {
78955ba953aSJohan Hovold reg = rtc_read(rtc, OMAP_RTC_OSC_REG);
790e463786fSDario Binacchi rtc_write(rtc, OMAP_RTC_OSC_REG, reg | OMAP_RTC_OSC_32KCLK_EN);
79144c63a57SJohan Hovold }
792cd914bbaSSekhar Nori
793db68b189SDavid Brownell /* clear old status */
79455ba953aSJohan Hovold reg = rtc_read(rtc, OMAP_RTC_STATUS_REG);
7959291e340SJohan Hovold
7969291e340SJohan Hovold mask = OMAP_RTC_STATUS_ALARM;
7979291e340SJohan Hovold
798222a12fcSJohan Hovold if (rtc->type->has_pmic_mode)
799222a12fcSJohan Hovold mask |= OMAP_RTC_STATUS_ALARM2;
800222a12fcSJohan Hovold
8019291e340SJohan Hovold if (rtc->type->has_power_up_reset) {
8029291e340SJohan Hovold mask |= OMAP_RTC_STATUS_POWER_UP;
8039291e340SJohan Hovold if (reg & OMAP_RTC_STATUS_POWER_UP)
804397b630aSJohan Hovold dev_info(&pdev->dev, "RTC power up reset detected\n");
805db68b189SDavid Brownell }
8069291e340SJohan Hovold
8079291e340SJohan Hovold if (reg & mask)
8089291e340SJohan Hovold rtc_write(rtc, OMAP_RTC_STATUS_REG, reg & mask);
809db68b189SDavid Brownell
810db68b189SDavid Brownell /* On boards with split power, RTC_ON_NOFF won't reset the RTC */
81155ba953aSJohan Hovold reg = rtc_read(rtc, OMAP_RTC_CTRL_REG);
81210211ae3SJohan Hovold if (reg & OMAP_RTC_CTRL_STOP)
813397b630aSJohan Hovold dev_info(&pdev->dev, "already running\n");
814db68b189SDavid Brownell
815db68b189SDavid Brownell /* force to 24 hour mode */
81612b3e038SDaniel Glöckner new_ctrl = reg & (OMAP_RTC_CTRL_SPLIT | OMAP_RTC_CTRL_AUTO_COMP);
817db68b189SDavid Brownell new_ctrl |= OMAP_RTC_CTRL_STOP;
818db68b189SDavid Brownell
81910211ae3SJohan Hovold /*
82010211ae3SJohan Hovold * BOARD-SPECIFIC CUSTOMIZATION CAN GO HERE:
821db68b189SDavid Brownell *
822fa5b0782SSekhar Nori * - Device wake-up capability setting should come through chip
823fa5b0782SSekhar Nori * init logic. OMAP1 boards should initialize the "wakeup capable"
824fa5b0782SSekhar Nori * flag in the platform device if the board is wired right for
825fa5b0782SSekhar Nori * being woken up by RTC alarm. For OMAP-L138, this capability
826fa5b0782SSekhar Nori * is built into the SoC by the "Deep Sleep" capability.
827db68b189SDavid Brownell *
828db68b189SDavid Brownell * - Boards wired so RTC_ON_nOFF is used as the reset signal,
829db68b189SDavid Brownell * rather than nPWRON_RESET, should forcibly enable split
830db68b189SDavid Brownell * power mode. (Some chip errata report that RTC_CTRL_SPLIT
831db68b189SDavid Brownell * is write-only, and always reads as zero...)
832db68b189SDavid Brownell */
833db68b189SDavid Brownell
83410211ae3SJohan Hovold if (new_ctrl & OMAP_RTC_CTRL_SPLIT)
835397b630aSJohan Hovold dev_info(&pdev->dev, "split power mode\n");
836db68b189SDavid Brownell
837db68b189SDavid Brownell if (reg != new_ctrl)
83855ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_CTRL_REG, new_ctrl);
839db68b189SDavid Brownell
840399cf0f6SKeerthy /*
841399cf0f6SKeerthy * If we have the external clock then switch to it so we can keep
842399cf0f6SKeerthy * ticking across suspend.
843399cf0f6SKeerthy */
844399cf0f6SKeerthy if (rtc->has_ext_clk) {
845399cf0f6SKeerthy reg = rtc_read(rtc, OMAP_RTC_OSC_REG);
8463984903aSLokesh Vutla reg &= ~OMAP_RTC_OSC_OSC32K_GZ_DISABLE;
8473984903aSLokesh Vutla reg |= OMAP_RTC_OSC_32KCLK_EN | OMAP_RTC_OSC_SEL_32KCLK_SRC;
848e463786fSDario Binacchi rtc_write(rtc, OMAP_RTC_OSC_REG, reg);
849399cf0f6SKeerthy }
850399cf0f6SKeerthy
8519c28bd07SLokesh Vutla rtc->type->lock(rtc);
8529c28bd07SLokesh Vutla
8534390ce00SJohan Hovold device_init_wakeup(&pdev->dev, true);
8544390ce00SJohan Hovold
85557072758SAlexandre Belloni rtc->rtc = devm_rtc_allocate_device(&pdev->dev);
85655ba953aSJohan Hovold if (IS_ERR(rtc->rtc)) {
85755ba953aSJohan Hovold ret = PTR_ERR(rtc->rtc);
8584390ce00SJohan Hovold goto err;
8594390ce00SJohan Hovold }
8604390ce00SJohan Hovold
86157072758SAlexandre Belloni rtc->rtc->ops = &omap_rtc_ops;
86235118b7aSAlexandre Belloni rtc->rtc->range_min = RTC_TIMESTAMP_BEGIN_2000;
86335118b7aSAlexandre Belloni rtc->rtc->range_max = RTC_TIMESTAMP_END_2099;
864b6ee15efSAlexandre Belloni omap_rtc_nvmem_config.priv = rtc;
86557072758SAlexandre Belloni
8664390ce00SJohan Hovold /* handle periodic and alarm irqs */
86755ba953aSJohan Hovold ret = devm_request_irq(&pdev->dev, rtc->irq_timer, rtc_irq, 0,
86855ba953aSJohan Hovold dev_name(&rtc->rtc->dev), rtc);
8694390ce00SJohan Hovold if (ret)
8704390ce00SJohan Hovold goto err;
8714390ce00SJohan Hovold
87255ba953aSJohan Hovold if (rtc->irq_timer != rtc->irq_alarm) {
87355ba953aSJohan Hovold ret = devm_request_irq(&pdev->dev, rtc->irq_alarm, rtc_irq, 0,
87455ba953aSJohan Hovold dev_name(&rtc->rtc->dev), rtc);
8754390ce00SJohan Hovold if (ret)
8764390ce00SJohan Hovold goto err;
8774390ce00SJohan Hovold }
8784390ce00SJohan Hovold
87997ea1906SMarcin Niestroj /* Support ext_wakeup pinconf */
88097ea1906SMarcin Niestroj rtc_pinctrl_desc.name = dev_name(&pdev->dev);
88197ea1906SMarcin Niestroj
8827c45c974SBartosz Golaszewski rtc->pctldev = devm_pinctrl_register(&pdev->dev, &rtc_pinctrl_desc, rtc);
88397ea1906SMarcin Niestroj if (IS_ERR(rtc->pctldev)) {
88497ea1906SMarcin Niestroj dev_err(&pdev->dev, "Couldn't register pinctrl driver\n");
88526e480f7SAlexandre Belloni ret = PTR_ERR(rtc->pctldev);
88626e480f7SAlexandre Belloni goto err;
88797ea1906SMarcin Niestroj }
88897ea1906SMarcin Niestroj
889fdcfd854SBartosz Golaszewski ret = devm_rtc_register_device(rtc->rtc);
89057072758SAlexandre Belloni if (ret)
8917c45c974SBartosz Golaszewski goto err;
89257072758SAlexandre Belloni
8933a905c2dSBartosz Golaszewski devm_rtc_nvmem_register(rtc->rtc, &omap_rtc_nvmem_config);
894ce603842SAlexandre Belloni
8955c8b84f4SJohan Hovold if (rtc->is_pmic_controller) {
8965c8b84f4SJohan Hovold if (!pm_power_off) {
8975c8b84f4SJohan Hovold omap_rtc_power_off_rtc = rtc;
8985c8b84f4SJohan Hovold pm_power_off = omap_rtc_power_off;
8995c8b84f4SJohan Hovold }
9005c8b84f4SJohan Hovold }
9015c8b84f4SJohan Hovold
902db68b189SDavid Brownell return 0;
903db68b189SDavid Brownell
904437b37a6SJohan Hovold err:
9052da6877fSAndreas Platschek clk_disable_unprepare(rtc->clk);
9067ecd9a3fSJohan Hovold device_init_wakeup(&pdev->dev, false);
9079c28bd07SLokesh Vutla rtc->type->lock(rtc);
908fc9bd902SVaibhav Hiremath pm_runtime_put_sync(&pdev->dev);
909fc9bd902SVaibhav Hiremath pm_runtime_disable(&pdev->dev);
910437b37a6SJohan Hovold
911437b37a6SJohan Hovold return ret;
912db68b189SDavid Brownell }
913db68b189SDavid Brownell
omap_rtc_remove(struct platform_device * pdev)914578afdb9SUwe Kleine-König static void omap_rtc_remove(struct platform_device *pdev)
915db68b189SDavid Brownell {
91655ba953aSJohan Hovold struct omap_rtc *rtc = platform_get_drvdata(pdev);
917399cf0f6SKeerthy u8 reg;
918db68b189SDavid Brownell
919222a12fcSJohan Hovold if (pm_power_off == omap_rtc_power_off &&
920222a12fcSJohan Hovold omap_rtc_power_off_rtc == rtc) {
921222a12fcSJohan Hovold pm_power_off = NULL;
922222a12fcSJohan Hovold omap_rtc_power_off_rtc = NULL;
923222a12fcSJohan Hovold }
924222a12fcSJohan Hovold
925db68b189SDavid Brownell device_init_wakeup(&pdev->dev, 0);
926db68b189SDavid Brownell
927532409aaSKeerthy if (!IS_ERR(rtc->clk))
928532409aaSKeerthy clk_disable_unprepare(rtc->clk);
929532409aaSKeerthy
9309c28bd07SLokesh Vutla rtc->type->unlock(rtc);
931db68b189SDavid Brownell /* leave rtc running, but disable irqs */
93255ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0);
933db68b189SDavid Brownell
934399cf0f6SKeerthy if (rtc->has_ext_clk) {
935399cf0f6SKeerthy reg = rtc_read(rtc, OMAP_RTC_OSC_REG);
936399cf0f6SKeerthy reg &= ~OMAP_RTC_OSC_SEL_32KCLK_SRC;
937399cf0f6SKeerthy rtc_write(rtc, OMAP_RTC_OSC_REG, reg);
938399cf0f6SKeerthy }
939399cf0f6SKeerthy
9409c28bd07SLokesh Vutla rtc->type->lock(rtc);
941fc9bd902SVaibhav Hiremath
942fc9bd902SVaibhav Hiremath /* Disable the clock/module */
943fc9bd902SVaibhav Hiremath pm_runtime_put_sync(&pdev->dev);
944fc9bd902SVaibhav Hiremath pm_runtime_disable(&pdev->dev);
945db68b189SDavid Brownell }
946db68b189SDavid Brownell
omap_rtc_suspend(struct device * dev)9470c749eacSDmitry Torokhov static int __maybe_unused omap_rtc_suspend(struct device *dev)
948db68b189SDavid Brownell {
94955ba953aSJohan Hovold struct omap_rtc *rtc = dev_get_drvdata(dev);
95055ba953aSJohan Hovold
95155ba953aSJohan Hovold rtc->interrupts_reg = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG);
952db68b189SDavid Brownell
9539c28bd07SLokesh Vutla rtc->type->unlock(rtc);
95410211ae3SJohan Hovold /*
95510211ae3SJohan Hovold * FIXME: the RTC alarm is not currently acting as a wakeup event
9568af750e3SHebbar Gururaja * source on some platforms, and in fact this enable() call is just
9578af750e3SHebbar Gururaja * saving a flag that's never used...
958db68b189SDavid Brownell */
959ab7f580bSLokesh Vutla if (device_may_wakeup(dev))
96055ba953aSJohan Hovold enable_irq_wake(rtc->irq_alarm);
961ab7f580bSLokesh Vutla else
96255ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, 0);
9639c28bd07SLokesh Vutla rtc->type->lock(rtc);
964db68b189SDavid Brownell
965efce21fcSTero Kristo rtc->is_suspending = true;
966fc9bd902SVaibhav Hiremath
967db68b189SDavid Brownell return 0;
968db68b189SDavid Brownell }
969db68b189SDavid Brownell
omap_rtc_resume(struct device * dev)9700c749eacSDmitry Torokhov static int __maybe_unused omap_rtc_resume(struct device *dev)
971db68b189SDavid Brownell {
97255ba953aSJohan Hovold struct omap_rtc *rtc = dev_get_drvdata(dev);
97355ba953aSJohan Hovold
9749c28bd07SLokesh Vutla rtc->type->unlock(rtc);
975ab7f580bSLokesh Vutla if (device_may_wakeup(dev))
97655ba953aSJohan Hovold disable_irq_wake(rtc->irq_alarm);
977ab7f580bSLokesh Vutla else
97855ba953aSJohan Hovold rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, rtc->interrupts_reg);
9799c28bd07SLokesh Vutla rtc->type->lock(rtc);
980ab7f580bSLokesh Vutla
981efce21fcSTero Kristo rtc->is_suspending = false;
982efce21fcSTero Kristo
983db68b189SDavid Brownell return 0;
984db68b189SDavid Brownell }
985db68b189SDavid Brownell
omap_rtc_runtime_suspend(struct device * dev)9860c749eacSDmitry Torokhov static int __maybe_unused omap_rtc_runtime_suspend(struct device *dev)
987efce21fcSTero Kristo {
988efce21fcSTero Kristo struct omap_rtc *rtc = dev_get_drvdata(dev);
989efce21fcSTero Kristo
990efce21fcSTero Kristo if (rtc->is_suspending && !rtc->has_ext_clk)
991efce21fcSTero Kristo return -EBUSY;
992efce21fcSTero Kristo
993efce21fcSTero Kristo return 0;
994efce21fcSTero Kristo }
995efce21fcSTero Kristo
996efce21fcSTero Kristo static const struct dev_pm_ops omap_rtc_pm_ops = {
997efce21fcSTero Kristo SET_SYSTEM_SLEEP_PM_OPS(omap_rtc_suspend, omap_rtc_resume)
9980c749eacSDmitry Torokhov SET_RUNTIME_PM_OPS(omap_rtc_runtime_suspend, NULL, NULL)
999efce21fcSTero Kristo };
100004ebc359SJingoo Han
omap_rtc_shutdown(struct platform_device * pdev)1001db68b189SDavid Brownell static void omap_rtc_shutdown(struct platform_device *pdev)
1002db68b189SDavid Brownell {
100355ba953aSJohan Hovold struct omap_rtc *rtc = platform_get_drvdata(pdev);
10048ad5c722SJohan Hovold u8 mask;
100555ba953aSJohan Hovold
10068ad5c722SJohan Hovold /*
10078ad5c722SJohan Hovold * Keep the ALARM interrupt enabled to allow the system to power up on
10088ad5c722SJohan Hovold * alarm events.
10098ad5c722SJohan Hovold */
10109c28bd07SLokesh Vutla rtc->type->unlock(rtc);
10118ad5c722SJohan Hovold mask = rtc_read(rtc, OMAP_RTC_INTERRUPTS_REG);
10128ad5c722SJohan Hovold mask &= OMAP_RTC_INTERRUPTS_IT_ALARM;
10138ad5c722SJohan Hovold rtc_write(rtc, OMAP_RTC_INTERRUPTS_REG, mask);
10149c28bd07SLokesh Vutla rtc->type->lock(rtc);
1015db68b189SDavid Brownell }
1016db68b189SDavid Brownell
1017db68b189SDavid Brownell static struct platform_driver omap_rtc_driver = {
10185d9094b6SLokesh Vutla .probe = omap_rtc_probe,
1019578afdb9SUwe Kleine-König .remove_new = omap_rtc_remove,
1020db68b189SDavid Brownell .shutdown = omap_rtc_shutdown,
1021db68b189SDavid Brownell .driver = {
1022a430ca22SJohan Hovold .name = "omap_rtc",
102304ebc359SJingoo Han .pm = &omap_rtc_pm_ops,
1024616b7341SSachin Kamat .of_match_table = omap_rtc_of_match,
1025db68b189SDavid Brownell },
10262153f949SJohan Hovold .id_table = omap_rtc_id_table,
1027db68b189SDavid Brownell };
1028db68b189SDavid Brownell
10295d9094b6SLokesh Vutla module_platform_driver(omap_rtc_driver);
1030db68b189SDavid Brownell
1031db68b189SDavid Brownell MODULE_AUTHOR("George G. Davis (and others)");
1032db68b189SDavid Brownell MODULE_LICENSE("GPL");
1033