2019-05-27 14:55:01 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2006-06-25 20:47:38 +08:00
|
|
|
/*
|
|
|
|
* drivers/rtc/rtc-pl031.c
|
|
|
|
*
|
|
|
|
* Real Time Clock interface for ARM AMBA PrimeCell 031 RTC
|
|
|
|
*
|
|
|
|
* Author: Deepak Saxena <dsaxena@plexity.net>
|
|
|
|
*
|
|
|
|
* Copyright 2006 (c) MontaVista Software, Inc.
|
|
|
|
*
|
2010-02-04 19:50:13 +08:00
|
|
|
* Author: Mian Yousaf Kaukab <mian.yousaf.kaukab@stericsson.com>
|
|
|
|
* Copyright 2010 (c) ST-Ericsson AB
|
2006-06-25 20:47:38 +08:00
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/rtc.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/amba/bus.h>
|
2008-04-20 19:08:04 +08:00
|
|
|
#include <linux/io.h>
|
2010-02-04 19:50:13 +08:00
|
|
|
#include <linux/bcd.h>
|
|
|
|
#include <linux/delay.h>
|
2015-09-21 23:46:57 +08:00
|
|
|
#include <linux/pm_wakeirq.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>
|
2006-06-25 20:47:38 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register definitions
|
|
|
|
*/
|
|
|
|
#define RTC_DR 0x00 /* Data read register */
|
|
|
|
#define RTC_MR 0x04 /* Match register */
|
|
|
|
#define RTC_LR 0x08 /* Data load register */
|
|
|
|
#define RTC_CR 0x0c /* Control register */
|
|
|
|
#define RTC_IMSC 0x10 /* Interrupt mask and set register */
|
|
|
|
#define RTC_RIS 0x14 /* Raw interrupt status register */
|
|
|
|
#define RTC_MIS 0x18 /* Masked interrupt status register */
|
|
|
|
#define RTC_ICR 0x1c /* Interrupt clear register */
|
2010-02-04 19:50:13 +08:00
|
|
|
/* ST variants have additional timer functionality */
|
|
|
|
#define RTC_TDR 0x20 /* Timer data read register */
|
|
|
|
#define RTC_TLR 0x24 /* Timer data load register */
|
|
|
|
#define RTC_TCR 0x28 /* Timer control register */
|
|
|
|
#define RTC_YDR 0x30 /* Year data read register */
|
|
|
|
#define RTC_YMR 0x34 /* Year match register */
|
|
|
|
#define RTC_YLR 0x38 /* Year data load register */
|
|
|
|
|
2013-02-05 06:28:54 +08:00
|
|
|
#define RTC_CR_EN (1 << 0) /* counter enable bit */
|
2010-02-04 19:50:13 +08:00
|
|
|
#define RTC_CR_CWEN (1 << 26) /* Clockwatch enable bit */
|
|
|
|
|
|
|
|
#define RTC_TCR_EN (1 << 1) /* Periodic timer enable bit */
|
|
|
|
|
|
|
|
/* Common bit definitions for Interrupt status and control registers */
|
|
|
|
#define RTC_BIT_AI (1 << 0) /* Alarm interrupt bit */
|
|
|
|
#define RTC_BIT_PI (1 << 1) /* Periodic interrupt bit. ST variants only. */
|
|
|
|
|
|
|
|
/* Common bit definations for ST v2 for reading/writing time */
|
|
|
|
#define RTC_SEC_SHIFT 0
|
|
|
|
#define RTC_SEC_MASK (0x3F << RTC_SEC_SHIFT) /* Second [0-59] */
|
|
|
|
#define RTC_MIN_SHIFT 6
|
|
|
|
#define RTC_MIN_MASK (0x3F << RTC_MIN_SHIFT) /* Minute [0-59] */
|
|
|
|
#define RTC_HOUR_SHIFT 12
|
|
|
|
#define RTC_HOUR_MASK (0x1F << RTC_HOUR_SHIFT) /* Hour [0-23] */
|
|
|
|
#define RTC_WDAY_SHIFT 17
|
|
|
|
#define RTC_WDAY_MASK (0x7 << RTC_WDAY_SHIFT) /* Day of Week [1-7] 1=Sunday */
|
|
|
|
#define RTC_MDAY_SHIFT 20
|
|
|
|
#define RTC_MDAY_MASK (0x1F << RTC_MDAY_SHIFT) /* Day of Month [1-31] */
|
|
|
|
#define RTC_MON_SHIFT 25
|
|
|
|
#define RTC_MON_MASK (0xF << RTC_MON_SHIFT) /* Month [1-12] 1=January */
|
|
|
|
|
|
|
|
#define RTC_TIMER_FREQ 32768
|
2006-06-25 20:47:38 +08:00
|
|
|
|
2012-07-31 05:41:34 +08:00
|
|
|
/**
|
|
|
|
* struct pl031_vendor_data - per-vendor variations
|
|
|
|
* @ops: the vendor-specific operations used on this silicon version
|
2012-07-31 05:41:36 +08:00
|
|
|
* @clockwatch: if this is an ST Microelectronics silicon version with a
|
|
|
|
* clockwatch function
|
|
|
|
* @st_weekday: if this is an ST Microelectronics silicon version that need
|
|
|
|
* the weekday fix
|
2012-07-31 05:41:39 +08:00
|
|
|
* @irqflags: special IRQ flags per variant
|
2012-07-31 05:41:34 +08:00
|
|
|
*/
|
|
|
|
struct pl031_vendor_data {
|
|
|
|
struct rtc_class_ops ops;
|
2012-07-31 05:41:36 +08:00
|
|
|
bool clockwatch;
|
|
|
|
bool st_weekday;
|
2012-07-31 05:41:39 +08:00
|
|
|
unsigned long irqflags;
|
2020-03-06 08:58:08 +08:00
|
|
|
time64_t range_min;
|
|
|
|
timeu64_t range_max;
|
2012-07-31 05:41:34 +08:00
|
|
|
};
|
|
|
|
|
2006-06-25 20:47:38 +08:00
|
|
|
struct pl031_local {
|
2012-07-31 05:41:34 +08:00
|
|
|
struct pl031_vendor_data *vendor;
|
2006-06-25 20:47:38 +08:00
|
|
|
struct rtc_device *rtc;
|
|
|
|
void __iomem *base;
|
|
|
|
};
|
|
|
|
|
2010-02-04 19:50:13 +08:00
|
|
|
static int pl031_alarm_irq_enable(struct device *dev,
|
|
|
|
unsigned int enabled)
|
|
|
|
{
|
|
|
|
struct pl031_local *ldata = dev_get_drvdata(dev);
|
|
|
|
unsigned long imsc;
|
|
|
|
|
|
|
|
/* Clear any pending alarm interrupts. */
|
|
|
|
writel(RTC_BIT_AI, ldata->base + RTC_ICR);
|
|
|
|
|
|
|
|
imsc = readl(ldata->base + RTC_IMSC);
|
|
|
|
|
|
|
|
if (enabled == 1)
|
|
|
|
writel(imsc | RTC_BIT_AI, ldata->base + RTC_IMSC);
|
|
|
|
else
|
|
|
|
writel(imsc & ~RTC_BIT_AI, ldata->base + RTC_IMSC);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert Gregorian date to ST v2 RTC format.
|
|
|
|
*/
|
|
|
|
static int pl031_stv2_tm_to_time(struct device *dev,
|
|
|
|
struct rtc_time *tm, unsigned long *st_time,
|
|
|
|
unsigned long *bcd_year)
|
|
|
|
{
|
|
|
|
int year = tm->tm_year + 1900;
|
|
|
|
int wday = tm->tm_wday;
|
|
|
|
|
|
|
|
/* wday masking is not working in hardware so wday must be valid */
|
|
|
|
if (wday < -1 || wday > 6) {
|
|
|
|
dev_err(dev, "invalid wday value %d\n", tm->tm_wday);
|
|
|
|
return -EINVAL;
|
|
|
|
} else if (wday == -1) {
|
|
|
|
/* wday is not provided, calculate it here */
|
|
|
|
struct rtc_time calc_tm;
|
|
|
|
|
2020-03-06 08:58:09 +08:00
|
|
|
rtc_time64_to_tm(rtc_tm_to_time64(tm), &calc_tm);
|
2010-02-04 19:50:13 +08:00
|
|
|
wday = calc_tm.tm_wday;
|
|
|
|
}
|
|
|
|
|
|
|
|
*bcd_year = (bin2bcd(year % 100) | bin2bcd(year / 100) << 8);
|
|
|
|
|
|
|
|
*st_time = ((tm->tm_mon + 1) << RTC_MON_SHIFT)
|
|
|
|
| (tm->tm_mday << RTC_MDAY_SHIFT)
|
|
|
|
| ((wday + 1) << RTC_WDAY_SHIFT)
|
|
|
|
| (tm->tm_hour << RTC_HOUR_SHIFT)
|
|
|
|
| (tm->tm_min << RTC_MIN_SHIFT)
|
|
|
|
| (tm->tm_sec << RTC_SEC_SHIFT);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert ST v2 RTC format to Gregorian date.
|
|
|
|
*/
|
|
|
|
static int pl031_stv2_time_to_tm(unsigned long st_time, unsigned long bcd_year,
|
|
|
|
struct rtc_time *tm)
|
|
|
|
{
|
|
|
|
tm->tm_year = bcd2bin(bcd_year) + (bcd2bin(bcd_year >> 8) * 100);
|
|
|
|
tm->tm_mon = ((st_time & RTC_MON_MASK) >> RTC_MON_SHIFT) - 1;
|
|
|
|
tm->tm_mday = ((st_time & RTC_MDAY_MASK) >> RTC_MDAY_SHIFT);
|
|
|
|
tm->tm_wday = ((st_time & RTC_WDAY_MASK) >> RTC_WDAY_SHIFT) - 1;
|
|
|
|
tm->tm_hour = ((st_time & RTC_HOUR_MASK) >> RTC_HOUR_SHIFT);
|
|
|
|
tm->tm_min = ((st_time & RTC_MIN_MASK) >> RTC_MIN_SHIFT);
|
|
|
|
tm->tm_sec = ((st_time & RTC_SEC_MASK) >> RTC_SEC_SHIFT);
|
|
|
|
|
|
|
|
tm->tm_yday = rtc_year_days(tm->tm_mday, tm->tm_mon, tm->tm_year);
|
|
|
|
tm->tm_year -= 1900;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pl031_stv2_read_time(struct device *dev, struct rtc_time *tm)
|
|
|
|
{
|
|
|
|
struct pl031_local *ldata = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
pl031_stv2_time_to_tm(readl(ldata->base + RTC_DR),
|
|
|
|
readl(ldata->base + RTC_YDR), tm);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pl031_stv2_set_time(struct device *dev, struct rtc_time *tm)
|
|
|
|
{
|
|
|
|
unsigned long time;
|
|
|
|
unsigned long bcd_year;
|
|
|
|
struct pl031_local *ldata = dev_get_drvdata(dev);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = pl031_stv2_tm_to_time(dev, tm, &time, &bcd_year);
|
|
|
|
if (ret == 0) {
|
|
|
|
writel(bcd_year, ldata->base + RTC_YLR);
|
|
|
|
writel(time, ldata->base + RTC_LR);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pl031_stv2_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
|
2006-06-25 20:47:38 +08:00
|
|
|
{
|
2010-02-04 19:50:13 +08:00
|
|
|
struct pl031_local *ldata = dev_get_drvdata(dev);
|
|
|
|
int ret;
|
2006-06-25 20:47:38 +08:00
|
|
|
|
2010-02-04 19:50:13 +08:00
|
|
|
ret = pl031_stv2_time_to_tm(readl(ldata->base + RTC_MR),
|
|
|
|
readl(ldata->base + RTC_YMR), &alarm->time);
|
2006-06-25 20:47:38 +08:00
|
|
|
|
2010-02-04 19:50:13 +08:00
|
|
|
alarm->pending = readl(ldata->base + RTC_RIS) & RTC_BIT_AI;
|
|
|
|
alarm->enabled = readl(ldata->base + RTC_IMSC) & RTC_BIT_AI;
|
|
|
|
|
|
|
|
return ret;
|
2006-06-25 20:47:38 +08:00
|
|
|
}
|
|
|
|
|
2010-02-04 19:50:13 +08:00
|
|
|
static int pl031_stv2_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
|
2006-06-25 20:47:38 +08:00
|
|
|
{
|
|
|
|
struct pl031_local *ldata = dev_get_drvdata(dev);
|
2010-02-04 19:50:13 +08:00
|
|
|
unsigned long time;
|
|
|
|
unsigned long bcd_year;
|
|
|
|
int ret;
|
|
|
|
|
2020-03-06 08:58:07 +08:00
|
|
|
ret = pl031_stv2_tm_to_time(dev, &alarm->time,
|
|
|
|
&time, &bcd_year);
|
2010-02-04 19:50:13 +08:00
|
|
|
if (ret == 0) {
|
2020-03-06 08:58:07 +08:00
|
|
|
writel(bcd_year, ldata->base + RTC_YMR);
|
|
|
|
writel(time, ldata->base + RTC_MR);
|
|
|
|
|
|
|
|
pl031_alarm_irq_enable(dev, alarm->enabled);
|
2010-02-04 19:50:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t pl031_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct pl031_local *ldata = dev_id;
|
|
|
|
unsigned long rtcmis;
|
|
|
|
unsigned long events = 0;
|
|
|
|
|
|
|
|
rtcmis = readl(ldata->base + RTC_MIS);
|
2012-05-30 06:07:40 +08:00
|
|
|
if (rtcmis & RTC_BIT_AI) {
|
|
|
|
writel(RTC_BIT_AI, ldata->base + RTC_ICR);
|
|
|
|
events |= (RTC_AF | RTC_IRQF);
|
2010-02-04 19:50:13 +08:00
|
|
|
rtc_update_irq(ldata->rtc, 1, events);
|
2006-06-25 20:47:38 +08:00
|
|
|
|
2010-02-04 19:50:13 +08:00
|
|
|
return IRQ_HANDLED;
|
2006-06-25 20:47:38 +08:00
|
|
|
}
|
|
|
|
|
2010-02-04 19:50:13 +08:00
|
|
|
return IRQ_NONE;
|
2006-06-25 20:47:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pl031_read_time(struct device *dev, struct rtc_time *tm)
|
|
|
|
{
|
|
|
|
struct pl031_local *ldata = dev_get_drvdata(dev);
|
|
|
|
|
2020-03-06 08:58:09 +08:00
|
|
|
rtc_time64_to_tm(readl(ldata->base + RTC_DR), tm);
|
2006-06-25 20:47:38 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pl031_set_time(struct device *dev, struct rtc_time *tm)
|
|
|
|
{
|
|
|
|
struct pl031_local *ldata = dev_get_drvdata(dev);
|
|
|
|
|
2020-03-06 08:58:09 +08:00
|
|
|
writel(rtc_tm_to_time64(tm), ldata->base + RTC_LR);
|
2010-02-04 19:50:13 +08:00
|
|
|
|
2020-03-06 08:58:09 +08:00
|
|
|
return 0;
|
2006-06-25 20:47:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pl031_read_alarm(struct device *dev, struct rtc_wkalrm *alarm)
|
|
|
|
{
|
|
|
|
struct pl031_local *ldata = dev_get_drvdata(dev);
|
|
|
|
|
2020-03-06 08:58:09 +08:00
|
|
|
rtc_time64_to_tm(readl(ldata->base + RTC_MR), &alarm->time);
|
2010-02-04 19:50:13 +08:00
|
|
|
|
|
|
|
alarm->pending = readl(ldata->base + RTC_RIS) & RTC_BIT_AI;
|
|
|
|
alarm->enabled = readl(ldata->base + RTC_IMSC) & RTC_BIT_AI;
|
2006-06-25 20:47:38 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pl031_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
|
|
|
|
{
|
|
|
|
struct pl031_local *ldata = dev_get_drvdata(dev);
|
2010-02-04 19:50:13 +08:00
|
|
|
|
2020-03-06 08:58:09 +08:00
|
|
|
writel(rtc_tm_to_time64(&alarm->time), ldata->base + RTC_MR);
|
2020-07-14 20:45:56 +08:00
|
|
|
pl031_alarm_irq_enable(dev, alarm->enabled);
|
2010-02-04 19:50:13 +08:00
|
|
|
|
2020-03-06 08:58:09 +08:00
|
|
|
return 0;
|
2010-02-04 19:50:13 +08:00
|
|
|
}
|
|
|
|
|
2021-01-27 00:58:34 +08:00
|
|
|
static void pl031_remove(struct amba_device *adev)
|
2006-06-25 20:47:38 +08:00
|
|
|
{
|
|
|
|
struct pl031_local *ldata = dev_get_drvdata(&adev->dev);
|
|
|
|
|
2015-09-21 23:46:57 +08:00
|
|
|
dev_pm_clear_wake_irq(&adev->dev);
|
|
|
|
device_init_wakeup(&adev->dev, false);
|
2017-09-29 18:22:15 +08:00
|
|
|
if (adev->irq[0])
|
|
|
|
free_irq(adev->irq[0], ldata);
|
2008-04-20 19:08:04 +08:00
|
|
|
amba_release_regions(adev);
|
2006-06-25 20:47:38 +08:00
|
|
|
}
|
|
|
|
|
2011-02-19 23:55:00 +08:00
|
|
|
static int pl031_probe(struct amba_device *adev, const struct amba_id *id)
|
2006-06-25 20:47:38 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct pl031_local *ldata;
|
2012-07-31 05:41:34 +08:00
|
|
|
struct pl031_vendor_data *vendor = id->data;
|
2017-09-29 18:22:10 +08:00
|
|
|
struct rtc_class_ops *ops;
|
2013-02-05 06:28:54 +08:00
|
|
|
unsigned long time, data;
|
2006-06-25 20:47:38 +08:00
|
|
|
|
2008-04-20 19:08:04 +08:00
|
|
|
ret = amba_request_regions(adev, NULL);
|
|
|
|
if (ret)
|
|
|
|
goto err_req;
|
2006-06-25 20:47:38 +08:00
|
|
|
|
2017-09-29 18:22:05 +08:00
|
|
|
ldata = devm_kzalloc(&adev->dev, sizeof(struct pl031_local),
|
|
|
|
GFP_KERNEL);
|
2017-09-29 18:22:10 +08:00
|
|
|
ops = devm_kmemdup(&adev->dev, &vendor->ops, sizeof(vendor->ops),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!ldata || !ops) {
|
2006-06-25 20:47:38 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2017-09-29 18:22:10 +08:00
|
|
|
ldata->vendor = vendor;
|
2017-09-29 18:22:05 +08:00
|
|
|
ldata->base = devm_ioremap(&adev->dev, adev->res.start,
|
|
|
|
resource_size(&adev->res));
|
2006-06-25 20:47:38 +08:00
|
|
|
if (!ldata->base) {
|
|
|
|
ret = -ENOMEM;
|
2017-09-29 18:22:05 +08:00
|
|
|
goto out;
|
2006-06-25 20:47:38 +08:00
|
|
|
}
|
|
|
|
|
2008-04-20 19:08:04 +08:00
|
|
|
amba_set_drvdata(adev, ldata);
|
|
|
|
|
2012-07-31 05:41:36 +08:00
|
|
|
dev_dbg(&adev->dev, "designer ID = 0x%02x\n", amba_manf(adev));
|
|
|
|
dev_dbg(&adev->dev, "revision = 0x%01x\n", amba_rev(adev));
|
2006-06-25 20:47:38 +08:00
|
|
|
|
2013-02-05 06:28:54 +08:00
|
|
|
data = readl(ldata->base + RTC_CR);
|
2010-02-04 19:50:13 +08:00
|
|
|
/* Enable the clockwatch on ST Variants */
|
2012-07-31 05:41:36 +08:00
|
|
|
if (vendor->clockwatch)
|
2013-02-05 06:28:54 +08:00
|
|
|
data |= RTC_CR_CWEN;
|
2013-02-13 05:46:19 +08:00
|
|
|
else
|
|
|
|
data |= RTC_CR_EN;
|
|
|
|
writel(data, ldata->base + RTC_CR);
|
2010-02-04 19:50:13 +08:00
|
|
|
|
2012-05-18 08:03:24 +08:00
|
|
|
/*
|
|
|
|
* On ST PL031 variants, the RTC reset value does not provide correct
|
|
|
|
* weekday for 2000-01-01. Correct the erroneous sunday to saturday.
|
|
|
|
*/
|
2012-07-31 05:41:36 +08:00
|
|
|
if (vendor->st_weekday) {
|
2012-05-18 08:03:24 +08:00
|
|
|
if (readl(ldata->base + RTC_YDR) == 0x2000) {
|
|
|
|
time = readl(ldata->base + RTC_DR);
|
|
|
|
if ((time &
|
|
|
|
(RTC_MON_MASK | RTC_MDAY_MASK | RTC_WDAY_MASK))
|
|
|
|
== 0x02120000) {
|
|
|
|
time = time | (0x7 << RTC_WDAY_SHIFT);
|
|
|
|
writel(0x2000, ldata->base + RTC_YLR);
|
|
|
|
writel(time, ldata->base + RTC_LR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-21 23:46:57 +08:00
|
|
|
device_init_wakeup(&adev->dev, true);
|
2018-09-10 04:38:48 +08:00
|
|
|
ldata->rtc = devm_rtc_allocate_device(&adev->dev);
|
2020-11-12 17:31:39 +08:00
|
|
|
if (IS_ERR(ldata->rtc)) {
|
|
|
|
ret = PTR_ERR(ldata->rtc);
|
|
|
|
goto out;
|
|
|
|
}
|
2018-09-10 04:38:48 +08:00
|
|
|
|
2022-02-26 00:19:24 +08:00
|
|
|
if (!adev->irq[0])
|
|
|
|
clear_bit(RTC_FEATURE_ALARM, ldata->rtc->features);
|
|
|
|
|
2018-09-10 04:38:48 +08:00
|
|
|
ldata->rtc->ops = ops;
|
2020-03-06 08:58:08 +08:00
|
|
|
ldata->rtc->range_min = vendor->range_min;
|
|
|
|
ldata->rtc->range_max = vendor->range_max;
|
2018-09-10 04:38:48 +08:00
|
|
|
|
2020-11-10 00:34:08 +08:00
|
|
|
ret = devm_rtc_register_device(ldata->rtc);
|
2018-09-10 04:38:48 +08:00
|
|
|
if (ret)
|
2017-09-29 18:22:05 +08:00
|
|
|
goto out;
|
2006-06-25 20:47:38 +08:00
|
|
|
|
2017-09-29 18:22:15 +08:00
|
|
|
if (adev->irq[0]) {
|
|
|
|
ret = request_irq(adev->irq[0], pl031_interrupt,
|
|
|
|
vendor->irqflags, "rtc-pl031", ldata);
|
|
|
|
if (ret)
|
2018-09-10 04:38:48 +08:00
|
|
|
goto out;
|
2017-09-29 18:22:15 +08:00
|
|
|
dev_pm_set_wake_irq(&adev->dev, adev->irq[0]);
|
2010-02-04 19:50:13 +08:00
|
|
|
}
|
2006-06-25 20:47:38 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
out:
|
2008-04-20 19:08:04 +08:00
|
|
|
amba_release_regions(adev);
|
|
|
|
err_req:
|
2010-02-04 19:50:13 +08:00
|
|
|
|
2006-06-25 20:47:38 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-02-04 19:50:13 +08:00
|
|
|
/* Operations for the original ARM version */
|
2012-07-31 05:41:34 +08:00
|
|
|
static struct pl031_vendor_data arm_pl031 = {
|
|
|
|
.ops = {
|
|
|
|
.read_time = pl031_read_time,
|
|
|
|
.set_time = pl031_set_time,
|
|
|
|
.read_alarm = pl031_read_alarm,
|
|
|
|
.set_alarm = pl031_set_alarm,
|
|
|
|
.alarm_irq_enable = pl031_alarm_irq_enable,
|
|
|
|
},
|
2020-03-06 08:58:08 +08:00
|
|
|
.range_max = U32_MAX,
|
2010-02-04 19:50:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* The First ST derivative */
|
2012-07-31 05:41:34 +08:00
|
|
|
static struct pl031_vendor_data stv1_pl031 = {
|
|
|
|
.ops = {
|
|
|
|
.read_time = pl031_read_time,
|
|
|
|
.set_time = pl031_set_time,
|
|
|
|
.read_alarm = pl031_read_alarm,
|
|
|
|
.set_alarm = pl031_set_alarm,
|
|
|
|
.alarm_irq_enable = pl031_alarm_irq_enable,
|
|
|
|
},
|
2012-07-31 05:41:36 +08:00
|
|
|
.clockwatch = true,
|
|
|
|
.st_weekday = true,
|
2020-03-06 08:58:08 +08:00
|
|
|
.range_max = U32_MAX,
|
2010-02-04 19:50:13 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* And the second ST derivative */
|
2012-07-31 05:41:34 +08:00
|
|
|
static struct pl031_vendor_data stv2_pl031 = {
|
|
|
|
.ops = {
|
|
|
|
.read_time = pl031_stv2_read_time,
|
|
|
|
.set_time = pl031_stv2_set_time,
|
|
|
|
.read_alarm = pl031_stv2_read_alarm,
|
|
|
|
.set_alarm = pl031_stv2_set_alarm,
|
|
|
|
.alarm_irq_enable = pl031_alarm_irq_enable,
|
|
|
|
},
|
2012-07-31 05:41:36 +08:00
|
|
|
.clockwatch = true,
|
|
|
|
.st_weekday = true,
|
2012-07-31 05:41:39 +08:00
|
|
|
/*
|
|
|
|
* This variant shares the IRQ with another block and must not
|
|
|
|
* suspend that IRQ line.
|
2015-09-21 23:46:57 +08:00
|
|
|
* TODO check if it shares with IRQF_NO_SUSPEND user, else we can
|
|
|
|
* remove IRQF_COND_SUSPEND
|
2012-07-31 05:41:39 +08:00
|
|
|
*/
|
2015-09-21 23:46:57 +08:00
|
|
|
.irqflags = IRQF_SHARED | IRQF_COND_SUSPEND,
|
2020-03-06 08:58:08 +08:00
|
|
|
.range_min = RTC_TIMESTAMP_BEGIN_0000,
|
|
|
|
.range_max = RTC_TIMESTAMP_END_9999,
|
2010-02-04 19:50:13 +08:00
|
|
|
};
|
|
|
|
|
2017-09-29 18:22:00 +08:00
|
|
|
static const struct amba_id pl031_ids[] = {
|
2006-06-25 20:47:38 +08:00
|
|
|
{
|
2009-12-16 08:46:13 +08:00
|
|
|
.id = 0x00041031,
|
|
|
|
.mask = 0x000fffff,
|
2012-07-31 05:41:34 +08:00
|
|
|
.data = &arm_pl031,
|
2010-02-04 19:50:13 +08:00
|
|
|
},
|
|
|
|
/* ST Micro variants */
|
|
|
|
{
|
|
|
|
.id = 0x00180031,
|
|
|
|
.mask = 0x00ffffff,
|
2012-07-31 05:41:34 +08:00
|
|
|
.data = &stv1_pl031,
|
2010-02-04 19:50:13 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.id = 0x00280031,
|
|
|
|
.mask = 0x00ffffff,
|
2012-07-31 05:41:34 +08:00
|
|
|
.data = &stv2_pl031,
|
2009-12-16 08:46:13 +08:00
|
|
|
},
|
2006-06-25 20:47:38 +08:00
|
|
|
{0, 0},
|
|
|
|
};
|
|
|
|
|
2011-10-05 22:15:22 +08:00
|
|
|
MODULE_DEVICE_TABLE(amba, pl031_ids);
|
|
|
|
|
2006-06-25 20:47:38 +08:00
|
|
|
static struct amba_driver pl031_driver = {
|
|
|
|
.drv = {
|
|
|
|
.name = "rtc-pl031",
|
|
|
|
},
|
|
|
|
.id_table = pl031_ids,
|
|
|
|
.probe = pl031_probe,
|
|
|
|
.remove = pl031_remove,
|
|
|
|
};
|
|
|
|
|
2012-03-15 17:40:38 +08:00
|
|
|
module_amba_driver(pl031_driver);
|
2006-06-25 20:47:38 +08:00
|
|
|
|
2015-07-29 14:13:40 +08:00
|
|
|
MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
|
2006-06-25 20:47:38 +08:00
|
|
|
MODULE_DESCRIPTION("ARM AMBA PL031 RTC Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|