2019-05-27 14:55:05 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2009-01-07 06:42:14 +08:00
|
|
|
/*
|
|
|
|
* Real Time Clock interface for XScale PXA27x and PXA3xx
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Robert Jarzmik
|
|
|
|
*/
|
|
|
|
|
2009-01-07 06:42:15 +08:00
|
|
|
#include <linux/init.h>
|
2009-01-07 06:42:14 +08:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/rtc.h>
|
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/interrupt.h>
|
2009-01-07 06:42:15 +08:00
|
|
|
#include <linux/io.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2012-07-20 01:58:39 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2009-01-07 06:42:14 +08:00
|
|
|
|
2009-01-16 05:50:54 +08:00
|
|
|
#include <mach/hardware.h>
|
|
|
|
|
2015-05-13 22:20:04 +08:00
|
|
|
#include "rtc-sa1100.h"
|
|
|
|
|
2009-01-07 06:42:14 +08:00
|
|
|
#define RTC_DEF_DIVIDER (32768 - 1)
|
|
|
|
#define RTC_DEF_TRIM 0
|
|
|
|
#define MAXFREQ_PERIODIC 1000
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PXA Registers and bits definitions
|
|
|
|
*/
|
|
|
|
#define RTSR_PICE (1 << 15) /* Periodic interrupt count enable */
|
|
|
|
#define RTSR_PIALE (1 << 14) /* Periodic interrupt Alarm enable */
|
|
|
|
#define RTSR_PIAL (1 << 13) /* Periodic interrupt detected */
|
|
|
|
#define RTSR_SWALE2 (1 << 11) /* RTC stopwatch alarm2 enable */
|
|
|
|
#define RTSR_SWAL2 (1 << 10) /* RTC stopwatch alarm2 detected */
|
|
|
|
#define RTSR_SWALE1 (1 << 9) /* RTC stopwatch alarm1 enable */
|
|
|
|
#define RTSR_SWAL1 (1 << 8) /* RTC stopwatch alarm1 detected */
|
|
|
|
#define RTSR_RDALE2 (1 << 7) /* RTC alarm2 enable */
|
|
|
|
#define RTSR_RDAL2 (1 << 6) /* RTC alarm2 detected */
|
|
|
|
#define RTSR_RDALE1 (1 << 5) /* RTC alarm1 enable */
|
|
|
|
#define RTSR_RDAL1 (1 << 4) /* RTC alarm1 detected */
|
|
|
|
#define RTSR_HZE (1 << 3) /* HZ interrupt enable */
|
|
|
|
#define RTSR_ALE (1 << 2) /* RTC alarm interrupt enable */
|
|
|
|
#define RTSR_HZ (1 << 1) /* HZ rising-edge detected */
|
|
|
|
#define RTSR_AL (1 << 0) /* RTC alarm detected */
|
|
|
|
#define RTSR_TRIG_MASK (RTSR_AL | RTSR_HZ | RTSR_RDAL1 | RTSR_RDAL2\
|
|
|
|
| RTSR_SWAL1 | RTSR_SWAL2)
|
|
|
|
#define RYxR_YEAR_S 9
|
|
|
|
#define RYxR_YEAR_MASK (0xfff << RYxR_YEAR_S)
|
|
|
|
#define RYxR_MONTH_S 5
|
|
|
|
#define RYxR_MONTH_MASK (0xf << RYxR_MONTH_S)
|
|
|
|
#define RYxR_DAY_MASK 0x1f
|
2013-02-22 08:44:23 +08:00
|
|
|
#define RDxR_WOM_S 20
|
|
|
|
#define RDxR_WOM_MASK (0x7 << RDxR_WOM_S)
|
|
|
|
#define RDxR_DOW_S 17
|
|
|
|
#define RDxR_DOW_MASK (0x7 << RDxR_DOW_S)
|
2009-01-07 06:42:14 +08:00
|
|
|
#define RDxR_HOUR_S 12
|
|
|
|
#define RDxR_HOUR_MASK (0x1f << RDxR_HOUR_S)
|
|
|
|
#define RDxR_MIN_S 6
|
|
|
|
#define RDxR_MIN_MASK (0x3f << RDxR_MIN_S)
|
|
|
|
#define RDxR_SEC_MASK 0x3f
|
|
|
|
|
|
|
|
#define RTSR 0x08
|
|
|
|
#define RTTR 0x0c
|
|
|
|
#define RDCR 0x10
|
|
|
|
#define RYCR 0x14
|
|
|
|
#define RDAR1 0x18
|
|
|
|
#define RYAR1 0x1c
|
|
|
|
#define RTCPICR 0x34
|
|
|
|
#define PIAR 0x38
|
|
|
|
|
|
|
|
#define rtc_readl(pxa_rtc, reg) \
|
|
|
|
__raw_readl((pxa_rtc)->base + (reg))
|
|
|
|
#define rtc_writel(pxa_rtc, reg, value) \
|
|
|
|
__raw_writel((value), (pxa_rtc)->base + (reg))
|
|
|
|
|
|
|
|
struct pxa_rtc {
|
2015-05-13 22:20:04 +08:00
|
|
|
struct sa1100_rtc sa1100_rtc;
|
2009-01-07 06:42:14 +08:00
|
|
|
struct resource *ress;
|
|
|
|
void __iomem *base;
|
|
|
|
struct rtc_device *rtc;
|
|
|
|
spinlock_t lock; /* Protects this structure */
|
|
|
|
};
|
|
|
|
|
2013-02-22 08:44:23 +08:00
|
|
|
|
2009-01-07 06:42:14 +08:00
|
|
|
static u32 ryxr_calc(struct rtc_time *tm)
|
|
|
|
{
|
|
|
|
return ((tm->tm_year + 1900) << RYxR_YEAR_S)
|
|
|
|
| ((tm->tm_mon + 1) << RYxR_MONTH_S)
|
|
|
|
| tm->tm_mday;
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 rdxr_calc(struct rtc_time *tm)
|
|
|
|
{
|
2013-02-22 08:44:23 +08:00
|
|
|
return ((((tm->tm_mday + 6) / 7) << RDxR_WOM_S) & RDxR_WOM_MASK)
|
|
|
|
| (((tm->tm_wday + 1) << RDxR_DOW_S) & RDxR_DOW_MASK)
|
|
|
|
| (tm->tm_hour << RDxR_HOUR_S)
|
|
|
|
| (tm->tm_min << RDxR_MIN_S)
|
2009-01-07 06:42:14 +08:00
|
|
|
| tm->tm_sec;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void tm_calc(u32 rycr, u32 rdcr, struct rtc_time *tm)
|
|
|
|
{
|
|
|
|
tm->tm_year = ((rycr & RYxR_YEAR_MASK) >> RYxR_YEAR_S) - 1900;
|
|
|
|
tm->tm_mon = (((rycr & RYxR_MONTH_MASK) >> RYxR_MONTH_S)) - 1;
|
|
|
|
tm->tm_mday = (rycr & RYxR_DAY_MASK);
|
2013-02-22 08:44:23 +08:00
|
|
|
tm->tm_wday = ((rycr & RDxR_DOW_MASK) >> RDxR_DOW_S) - 1;
|
2009-01-07 06:42:14 +08:00
|
|
|
tm->tm_hour = (rdcr & RDxR_HOUR_MASK) >> RDxR_HOUR_S;
|
|
|
|
tm->tm_min = (rdcr & RDxR_MIN_MASK) >> RDxR_MIN_S;
|
|
|
|
tm->tm_sec = rdcr & RDxR_SEC_MASK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rtsr_clear_bits(struct pxa_rtc *pxa_rtc, u32 mask)
|
|
|
|
{
|
|
|
|
u32 rtsr;
|
|
|
|
|
|
|
|
rtsr = rtc_readl(pxa_rtc, RTSR);
|
|
|
|
rtsr &= ~RTSR_TRIG_MASK;
|
|
|
|
rtsr &= ~mask;
|
|
|
|
rtc_writel(pxa_rtc, RTSR, rtsr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rtsr_set_bits(struct pxa_rtc *pxa_rtc, u32 mask)
|
|
|
|
{
|
|
|
|
u32 rtsr;
|
|
|
|
|
|
|
|
rtsr = rtc_readl(pxa_rtc, RTSR);
|
|
|
|
rtsr &= ~RTSR_TRIG_MASK;
|
|
|
|
rtsr |= mask;
|
|
|
|
rtc_writel(pxa_rtc, RTSR, rtsr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t pxa_rtc_irq(int irq, void *dev_id)
|
|
|
|
{
|
2019-04-23 15:50:16 +08:00
|
|
|
struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev_id);
|
2009-01-07 06:42:14 +08:00
|
|
|
u32 rtsr;
|
|
|
|
unsigned long events = 0;
|
|
|
|
|
|
|
|
spin_lock(&pxa_rtc->lock);
|
|
|
|
|
|
|
|
/* clear interrupt sources */
|
|
|
|
rtsr = rtc_readl(pxa_rtc, RTSR);
|
|
|
|
rtc_writel(pxa_rtc, RTSR, rtsr);
|
|
|
|
|
|
|
|
/* temporary disable rtc interrupts */
|
|
|
|
rtsr_clear_bits(pxa_rtc, RTSR_RDALE1 | RTSR_PIALE | RTSR_HZE);
|
|
|
|
|
|
|
|
/* clear alarm interrupt if it has occurred */
|
|
|
|
if (rtsr & RTSR_RDAL1)
|
|
|
|
rtsr &= ~RTSR_RDALE1;
|
|
|
|
|
|
|
|
/* update irq data & counter */
|
|
|
|
if (rtsr & RTSR_RDAL1)
|
|
|
|
events |= RTC_AF | RTC_IRQF;
|
|
|
|
if (rtsr & RTSR_HZ)
|
|
|
|
events |= RTC_UF | RTC_IRQF;
|
|
|
|
if (rtsr & RTSR_PIAL)
|
|
|
|
events |= RTC_PF | RTC_IRQF;
|
|
|
|
|
|
|
|
rtc_update_irq(pxa_rtc->rtc, 1, events);
|
|
|
|
|
|
|
|
/* enable back rtc interrupts */
|
|
|
|
rtc_writel(pxa_rtc, RTSR, rtsr & ~RTSR_TRIG_MASK);
|
|
|
|
|
|
|
|
spin_unlock(&pxa_rtc->lock);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pxa_rtc_open(struct device *dev)
|
|
|
|
{
|
|
|
|
struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
|
|
|
|
int ret;
|
|
|
|
|
2015-05-13 22:20:04 +08:00
|
|
|
ret = request_irq(pxa_rtc->sa1100_rtc.irq_1hz, pxa_rtc_irq, 0,
|
2009-01-07 06:42:14 +08:00
|
|
|
"rtc 1Hz", dev);
|
|
|
|
if (ret < 0) {
|
2015-05-13 22:20:04 +08:00
|
|
|
dev_err(dev, "can't get irq %i, err %d\n",
|
|
|
|
pxa_rtc->sa1100_rtc.irq_1hz, ret);
|
2009-01-07 06:42:14 +08:00
|
|
|
goto err_irq_1Hz;
|
|
|
|
}
|
2015-05-13 22:20:04 +08:00
|
|
|
ret = request_irq(pxa_rtc->sa1100_rtc.irq_alarm, pxa_rtc_irq, 0,
|
2009-01-07 06:42:14 +08:00
|
|
|
"rtc Alrm", dev);
|
|
|
|
if (ret < 0) {
|
2015-05-13 22:20:04 +08:00
|
|
|
dev_err(dev, "can't get irq %i, err %d\n",
|
|
|
|
pxa_rtc->sa1100_rtc.irq_alarm, ret);
|
2009-01-07 06:42:14 +08:00
|
|
|
goto err_irq_Alrm;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_irq_Alrm:
|
2015-05-13 22:20:04 +08:00
|
|
|
free_irq(pxa_rtc->sa1100_rtc.irq_1hz, dev);
|
2009-01-07 06:42:14 +08:00
|
|
|
err_irq_1Hz:
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pxa_rtc_release(struct device *dev)
|
|
|
|
{
|
|
|
|
struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
spin_lock_irq(&pxa_rtc->lock);
|
|
|
|
rtsr_clear_bits(pxa_rtc, RTSR_PIALE | RTSR_RDALE1 | RTSR_HZE);
|
|
|
|
spin_unlock_irq(&pxa_rtc->lock);
|
|
|
|
|
2015-05-13 22:20:04 +08:00
|
|
|
free_irq(pxa_rtc->sa1100_rtc.irq_1hz, dev);
|
|
|
|
free_irq(pxa_rtc->sa1100_rtc.irq_alarm, dev);
|
2009-01-07 06:42:14 +08:00
|
|
|
}
|
|
|
|
|
2010-08-11 09:02:11 +08:00
|
|
|
static int pxa_alarm_irq_enable(struct device *dev, unsigned int enabled)
|
2009-01-07 06:42:14 +08:00
|
|
|
{
|
|
|
|
struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
spin_lock_irq(&pxa_rtc->lock);
|
2010-08-11 09:02:11 +08:00
|
|
|
|
|
|
|
if (enabled)
|
2009-01-07 06:42:14 +08:00
|
|
|
rtsr_set_bits(pxa_rtc, RTSR_RDALE1);
|
2010-08-11 09:02:11 +08:00
|
|
|
else
|
|
|
|
rtsr_clear_bits(pxa_rtc, RTSR_RDALE1);
|
|
|
|
|
|
|
|
spin_unlock_irq(&pxa_rtc->lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-07 06:42:14 +08:00
|
|
|
static int pxa_rtc_read_time(struct device *dev, struct rtc_time *tm)
|
|
|
|
{
|
|
|
|
struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
|
|
|
|
u32 rycr, rdcr;
|
|
|
|
|
|
|
|
rycr = rtc_readl(pxa_rtc, RYCR);
|
|
|
|
rdcr = rtc_readl(pxa_rtc, RDCR);
|
|
|
|
|
|
|
|
tm_calc(rycr, rdcr, tm);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pxa_rtc_set_time(struct device *dev, struct rtc_time *tm)
|
|
|
|
{
|
|
|
|
struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
rtc_writel(pxa_rtc, RYCR, ryxr_calc(tm));
|
|
|
|
rtc_writel(pxa_rtc, RDCR, rdxr_calc(tm));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pxa_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
|
|
|
|
{
|
|
|
|
struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
|
|
|
|
u32 rtsr, ryar, rdar;
|
|
|
|
|
|
|
|
ryar = rtc_readl(pxa_rtc, RYAR1);
|
|
|
|
rdar = rtc_readl(pxa_rtc, RDAR1);
|
|
|
|
tm_calc(ryar, rdar, &alrm->time);
|
|
|
|
|
|
|
|
rtsr = rtc_readl(pxa_rtc, RTSR);
|
|
|
|
alrm->enabled = (rtsr & RTSR_RDALE1) ? 1 : 0;
|
|
|
|
alrm->pending = (rtsr & RTSR_RDAL1) ? 1 : 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pxa_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
|
|
|
|
{
|
|
|
|
struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
|
|
|
|
u32 rtsr;
|
|
|
|
|
|
|
|
spin_lock_irq(&pxa_rtc->lock);
|
|
|
|
|
|
|
|
rtc_writel(pxa_rtc, RYAR1, ryxr_calc(&alrm->time));
|
|
|
|
rtc_writel(pxa_rtc, RDAR1, rdxr_calc(&alrm->time));
|
|
|
|
|
|
|
|
rtsr = rtc_readl(pxa_rtc, RTSR);
|
|
|
|
if (alrm->enabled)
|
|
|
|
rtsr |= RTSR_RDALE1;
|
|
|
|
else
|
|
|
|
rtsr &= ~RTSR_RDALE1;
|
|
|
|
rtc_writel(pxa_rtc, RTSR, rtsr);
|
|
|
|
|
|
|
|
spin_unlock_irq(&pxa_rtc->lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pxa_rtc_proc(struct device *dev, struct seq_file *seq)
|
|
|
|
{
|
|
|
|
struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
seq_printf(seq, "trim/divider\t: 0x%08x\n", rtc_readl(pxa_rtc, RTTR));
|
|
|
|
seq_printf(seq, "update_IRQ\t: %s\n",
|
|
|
|
(rtc_readl(pxa_rtc, RTSR) & RTSR_HZE) ? "yes" : "no");
|
|
|
|
seq_printf(seq, "periodic_IRQ\t: %s\n",
|
|
|
|
(rtc_readl(pxa_rtc, RTSR) & RTSR_PIALE) ? "yes" : "no");
|
|
|
|
seq_printf(seq, "periodic_freq\t: %u\n", rtc_readl(pxa_rtc, PIAR));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct rtc_class_ops pxa_rtc_ops = {
|
|
|
|
.read_time = pxa_rtc_read_time,
|
|
|
|
.set_time = pxa_rtc_set_time,
|
|
|
|
.read_alarm = pxa_rtc_read_alarm,
|
|
|
|
.set_alarm = pxa_rtc_set_alarm,
|
2010-08-11 09:02:11 +08:00
|
|
|
.alarm_irq_enable = pxa_alarm_irq_enable,
|
2009-01-07 06:42:14 +08:00
|
|
|
.proc = pxa_rtc_proc,
|
|
|
|
};
|
|
|
|
|
2009-01-07 06:42:15 +08:00
|
|
|
static int __init pxa_rtc_probe(struct platform_device *pdev)
|
2009-01-07 06:42:14 +08:00
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct pxa_rtc *pxa_rtc;
|
2015-05-13 22:20:04 +08:00
|
|
|
struct sa1100_rtc *sa1100_rtc;
|
2009-01-07 06:42:14 +08:00
|
|
|
int ret;
|
|
|
|
|
2013-07-04 06:07:09 +08:00
|
|
|
pxa_rtc = devm_kzalloc(dev, sizeof(*pxa_rtc), GFP_KERNEL);
|
2009-01-07 06:42:14 +08:00
|
|
|
if (!pxa_rtc)
|
2009-01-07 06:42:15 +08:00
|
|
|
return -ENOMEM;
|
2015-05-13 22:20:04 +08:00
|
|
|
sa1100_rtc = &pxa_rtc->sa1100_rtc;
|
2009-01-07 06:42:15 +08:00
|
|
|
|
|
|
|
spin_lock_init(&pxa_rtc->lock);
|
|
|
|
platform_set_drvdata(pdev, pxa_rtc);
|
2009-01-07 06:42:14 +08:00
|
|
|
|
|
|
|
pxa_rtc->ress = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!pxa_rtc->ress) {
|
|
|
|
dev_err(dev, "No I/O memory resource defined\n");
|
2013-07-04 06:07:09 +08:00
|
|
|
return -ENXIO;
|
2009-01-07 06:42:14 +08:00
|
|
|
}
|
|
|
|
|
2015-05-13 22:20:04 +08:00
|
|
|
sa1100_rtc->irq_1hz = platform_get_irq(pdev, 0);
|
2019-07-31 02:15:39 +08:00
|
|
|
if (sa1100_rtc->irq_1hz < 0)
|
2013-07-04 06:07:09 +08:00
|
|
|
return -ENXIO;
|
2015-05-13 22:20:04 +08:00
|
|
|
sa1100_rtc->irq_alarm = platform_get_irq(pdev, 1);
|
2019-07-31 02:15:39 +08:00
|
|
|
if (sa1100_rtc->irq_alarm < 0)
|
2013-07-04 06:07:09 +08:00
|
|
|
return -ENXIO;
|
2017-08-21 23:57:42 +08:00
|
|
|
|
2013-07-04 06:07:09 +08:00
|
|
|
pxa_rtc->base = devm_ioremap(dev, pxa_rtc->ress->start,
|
2009-01-07 06:42:15 +08:00
|
|
|
resource_size(pxa_rtc->ress));
|
2009-01-07 06:42:14 +08:00
|
|
|
if (!pxa_rtc->base) {
|
2013-07-04 06:07:09 +08:00
|
|
|
dev_err(dev, "Unable to map pxa RTC I/O memory\n");
|
|
|
|
return -ENOMEM;
|
2009-01-07 06:42:14 +08:00
|
|
|
}
|
|
|
|
|
2017-08-21 23:57:42 +08:00
|
|
|
pxa_rtc_open(dev);
|
|
|
|
|
2015-02-04 04:44:51 +08:00
|
|
|
sa1100_rtc->rcnr = pxa_rtc->base + 0x0;
|
|
|
|
sa1100_rtc->rtsr = pxa_rtc->base + 0x8;
|
|
|
|
sa1100_rtc->rtar = pxa_rtc->base + 0x4;
|
|
|
|
sa1100_rtc->rttr = pxa_rtc->base + 0xc;
|
2015-05-13 22:20:04 +08:00
|
|
|
ret = sa1100_rtc_init(pdev, sa1100_rtc);
|
2018-06-07 16:29:09 +08:00
|
|
|
if (ret) {
|
2015-05-13 22:20:04 +08:00
|
|
|
dev_err(dev, "Unable to init SA1100 RTC sub-device\n");
|
|
|
|
return ret;
|
2009-01-07 06:42:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rtsr_clear_bits(pxa_rtc, RTSR_PIALE | RTSR_RDALE1 | RTSR_HZE);
|
2009-01-07 06:42:15 +08:00
|
|
|
|
2013-07-04 06:07:09 +08:00
|
|
|
pxa_rtc->rtc = devm_rtc_device_register(&pdev->dev, "pxa-rtc",
|
|
|
|
&pxa_rtc_ops, THIS_MODULE);
|
2009-01-07 06:42:15 +08:00
|
|
|
if (IS_ERR(pxa_rtc->rtc)) {
|
2013-07-04 06:07:09 +08:00
|
|
|
ret = PTR_ERR(pxa_rtc->rtc);
|
2009-01-07 06:42:15 +08:00
|
|
|
dev_err(dev, "Failed to register RTC device -> %d\n", ret);
|
2013-07-04 06:07:09 +08:00
|
|
|
return ret;
|
2009-01-07 06:42:15 +08:00
|
|
|
}
|
|
|
|
|
2009-01-07 06:42:14 +08:00
|
|
|
device_init_wakeup(dev, 1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-07 06:42:15 +08:00
|
|
|
static int __exit pxa_rtc_remove(struct platform_device *pdev)
|
2009-01-07 06:42:14 +08:00
|
|
|
{
|
2013-02-22 08:44:24 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
2009-01-07 06:42:14 +08:00
|
|
|
|
2013-07-04 06:07:09 +08:00
|
|
|
pxa_rtc_release(dev);
|
2009-01-07 06:42:14 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-20 01:58:39 +08:00
|
|
|
#ifdef CONFIG_OF
|
2014-06-07 05:36:14 +08:00
|
|
|
static const struct of_device_id pxa_rtc_dt_ids[] = {
|
2012-07-20 01:58:39 +08:00
|
|
|
{ .compatible = "marvell,pxa-rtc" },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, pxa_rtc_dt_ids);
|
|
|
|
#endif
|
|
|
|
|
2013-04-30 07:19:57 +08:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2009-07-22 04:47:32 +08:00
|
|
|
static int pxa_rtc_suspend(struct device *dev)
|
2009-01-07 06:42:14 +08:00
|
|
|
{
|
2009-07-22 04:47:32 +08:00
|
|
|
struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
|
2009-01-07 06:42:14 +08:00
|
|
|
|
2009-07-22 04:47:32 +08:00
|
|
|
if (device_may_wakeup(dev))
|
2015-05-13 22:20:04 +08:00
|
|
|
enable_irq_wake(pxa_rtc->sa1100_rtc.irq_alarm);
|
2009-01-07 06:42:14 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-07-22 04:47:32 +08:00
|
|
|
static int pxa_rtc_resume(struct device *dev)
|
2009-01-07 06:42:14 +08:00
|
|
|
{
|
2009-07-22 04:47:32 +08:00
|
|
|
struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
|
2009-01-07 06:42:14 +08:00
|
|
|
|
2009-07-22 04:47:32 +08:00
|
|
|
if (device_may_wakeup(dev))
|
2015-05-13 22:20:04 +08:00
|
|
|
disable_irq_wake(pxa_rtc->sa1100_rtc.irq_alarm);
|
2009-01-07 06:42:14 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-04-30 07:19:57 +08:00
|
|
|
static SIMPLE_DEV_PM_OPS(pxa_rtc_pm_ops, pxa_rtc_suspend, pxa_rtc_resume);
|
|
|
|
|
2009-01-07 06:42:14 +08:00
|
|
|
static struct platform_driver pxa_rtc_driver = {
|
|
|
|
.remove = __exit_p(pxa_rtc_remove),
|
|
|
|
.driver = {
|
2009-07-22 04:47:32 +08:00
|
|
|
.name = "pxa-rtc",
|
2012-07-20 01:58:39 +08:00
|
|
|
.of_match_table = of_match_ptr(pxa_rtc_dt_ids),
|
2009-07-22 04:47:32 +08:00
|
|
|
.pm = &pxa_rtc_pm_ops,
|
2009-01-07 06:42:14 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2013-04-30 07:18:49 +08:00
|
|
|
module_platform_driver_probe(pxa_rtc_driver, pxa_rtc_probe);
|
2009-01-07 06:42:14 +08:00
|
|
|
|
2009-02-12 05:04:19 +08:00
|
|
|
MODULE_AUTHOR("Robert Jarzmik <robert.jarzmik@free.fr>");
|
2009-01-07 06:42:14 +08:00
|
|
|
MODULE_DESCRIPTION("PXA27x/PXA3xx Realtime Clock Driver (RTC)");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:pxa-rtc");
|