2007-07-21 15:37:58 +04:00
|
|
|
/*
|
|
|
|
* A RTC driver for the Simtek STK17TA8
|
|
|
|
*
|
2010-04-14 15:08:28 +04:00
|
|
|
* By Thomas Hommel <thomas.hommel@ge.com>
|
2007-07-21 15:37:58 +04:00
|
|
|
*
|
|
|
|
* Based on the DS1553 driver from
|
|
|
|
* Atsushi Nemoto <anemo@mba.ocn.ne.jp>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/bcd.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kernel.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 11:04:11 +03:00
|
|
|
#include <linux/gfp.h>
|
2007-07-21 15:37:58 +04:00
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/rtc.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/io.h>
|
2011-05-27 17:57:25 +04:00
|
|
|
#include <linux/module.h>
|
2007-07-21 15:37:58 +04:00
|
|
|
|
|
|
|
#define RTC_REG_SIZE 0x20000
|
|
|
|
#define RTC_OFFSET 0x1fff0
|
|
|
|
|
|
|
|
#define RTC_FLAGS (RTC_OFFSET + 0)
|
|
|
|
#define RTC_CENTURY (RTC_OFFSET + 1)
|
|
|
|
#define RTC_SECONDS_ALARM (RTC_OFFSET + 2)
|
|
|
|
#define RTC_MINUTES_ALARM (RTC_OFFSET + 3)
|
|
|
|
#define RTC_HOURS_ALARM (RTC_OFFSET + 4)
|
|
|
|
#define RTC_DATE_ALARM (RTC_OFFSET + 5)
|
|
|
|
#define RTC_INTERRUPTS (RTC_OFFSET + 6)
|
|
|
|
#define RTC_WATCHDOG (RTC_OFFSET + 7)
|
|
|
|
#define RTC_CALIBRATION (RTC_OFFSET + 8)
|
|
|
|
#define RTC_SECONDS (RTC_OFFSET + 9)
|
|
|
|
#define RTC_MINUTES (RTC_OFFSET + 10)
|
|
|
|
#define RTC_HOURS (RTC_OFFSET + 11)
|
|
|
|
#define RTC_DAY (RTC_OFFSET + 12)
|
|
|
|
#define RTC_DATE (RTC_OFFSET + 13)
|
|
|
|
#define RTC_MONTH (RTC_OFFSET + 14)
|
|
|
|
#define RTC_YEAR (RTC_OFFSET + 15)
|
|
|
|
|
|
|
|
#define RTC_SECONDS_MASK 0x7f
|
|
|
|
#define RTC_DAY_MASK 0x07
|
|
|
|
#define RTC_CAL_MASK 0x3f
|
|
|
|
|
|
|
|
/* Bits in the Calibration register */
|
|
|
|
#define RTC_STOP 0x80
|
|
|
|
|
|
|
|
/* Bits in the Flags register */
|
|
|
|
#define RTC_FLAGS_AF 0x40
|
|
|
|
#define RTC_FLAGS_PF 0x20
|
|
|
|
#define RTC_WRITE 0x02
|
|
|
|
#define RTC_READ 0x01
|
|
|
|
|
|
|
|
/* Bits in the Interrupts register */
|
|
|
|
#define RTC_INTS_AIE 0x40
|
|
|
|
|
|
|
|
struct rtc_plat_data {
|
|
|
|
struct rtc_device *rtc;
|
|
|
|
void __iomem *ioaddr;
|
|
|
|
unsigned long last_jiffies;
|
|
|
|
int irq;
|
|
|
|
unsigned int irqen;
|
|
|
|
int alrm_sec;
|
|
|
|
int alrm_min;
|
|
|
|
int alrm_hour;
|
|
|
|
int alrm_mday;
|
2009-12-16 03:46:04 +03:00
|
|
|
spinlock_t lock;
|
2007-07-21 15:37:58 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static int stk17ta8_rtc_set_time(struct device *dev, struct rtc_time *tm)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
|
|
|
|
void __iomem *ioaddr = pdata->ioaddr;
|
|
|
|
u8 flags;
|
|
|
|
|
|
|
|
flags = readb(pdata->ioaddr + RTC_FLAGS);
|
|
|
|
writeb(flags | RTC_WRITE, pdata->ioaddr + RTC_FLAGS);
|
|
|
|
|
2008-10-19 07:28:41 +04:00
|
|
|
writeb(bin2bcd(tm->tm_year % 100), ioaddr + RTC_YEAR);
|
|
|
|
writeb(bin2bcd(tm->tm_mon + 1), ioaddr + RTC_MONTH);
|
|
|
|
writeb(bin2bcd(tm->tm_wday) & RTC_DAY_MASK, ioaddr + RTC_DAY);
|
|
|
|
writeb(bin2bcd(tm->tm_mday), ioaddr + RTC_DATE);
|
|
|
|
writeb(bin2bcd(tm->tm_hour), ioaddr + RTC_HOURS);
|
|
|
|
writeb(bin2bcd(tm->tm_min), ioaddr + RTC_MINUTES);
|
|
|
|
writeb(bin2bcd(tm->tm_sec) & RTC_SECONDS_MASK, ioaddr + RTC_SECONDS);
|
|
|
|
writeb(bin2bcd((tm->tm_year + 1900) / 100), ioaddr + RTC_CENTURY);
|
2007-07-21 15:37:58 +04:00
|
|
|
|
|
|
|
writeb(flags & ~RTC_WRITE, pdata->ioaddr + RTC_FLAGS);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stk17ta8_rtc_read_time(struct device *dev, struct rtc_time *tm)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
|
|
|
|
void __iomem *ioaddr = pdata->ioaddr;
|
|
|
|
unsigned int year, month, day, hour, minute, second, week;
|
|
|
|
unsigned int century;
|
|
|
|
u8 flags;
|
|
|
|
|
|
|
|
/* give enough time to update RTC in case of continuous read */
|
|
|
|
if (pdata->last_jiffies == jiffies)
|
|
|
|
msleep(1);
|
|
|
|
pdata->last_jiffies = jiffies;
|
|
|
|
|
|
|
|
flags = readb(pdata->ioaddr + RTC_FLAGS);
|
|
|
|
writeb(flags | RTC_READ, ioaddr + RTC_FLAGS);
|
|
|
|
second = readb(ioaddr + RTC_SECONDS) & RTC_SECONDS_MASK;
|
|
|
|
minute = readb(ioaddr + RTC_MINUTES);
|
|
|
|
hour = readb(ioaddr + RTC_HOURS);
|
|
|
|
day = readb(ioaddr + RTC_DATE);
|
|
|
|
week = readb(ioaddr + RTC_DAY) & RTC_DAY_MASK;
|
|
|
|
month = readb(ioaddr + RTC_MONTH);
|
|
|
|
year = readb(ioaddr + RTC_YEAR);
|
|
|
|
century = readb(ioaddr + RTC_CENTURY);
|
|
|
|
writeb(flags & ~RTC_READ, ioaddr + RTC_FLAGS);
|
2008-10-19 07:28:41 +04:00
|
|
|
tm->tm_sec = bcd2bin(second);
|
|
|
|
tm->tm_min = bcd2bin(minute);
|
|
|
|
tm->tm_hour = bcd2bin(hour);
|
|
|
|
tm->tm_mday = bcd2bin(day);
|
|
|
|
tm->tm_wday = bcd2bin(week);
|
|
|
|
tm->tm_mon = bcd2bin(month) - 1;
|
2007-07-21 15:37:58 +04:00
|
|
|
/* year is 1900 + tm->tm_year */
|
2008-10-19 07:28:41 +04:00
|
|
|
tm->tm_year = bcd2bin(year) + bcd2bin(century) * 100 - 1900;
|
2007-07-21 15:37:58 +04:00
|
|
|
|
|
|
|
if (rtc_valid_tm(tm) < 0) {
|
|
|
|
dev_err(dev, "retrieved date/time is not valid.\n");
|
|
|
|
rtc_time_to_tm(0, tm);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stk17ta8_rtc_update_alarm(struct rtc_plat_data *pdata)
|
|
|
|
{
|
|
|
|
void __iomem *ioaddr = pdata->ioaddr;
|
|
|
|
unsigned long irqflags;
|
|
|
|
u8 flags;
|
|
|
|
|
2009-12-16 03:46:04 +03:00
|
|
|
spin_lock_irqsave(&pdata->lock, irqflags);
|
2007-07-21 15:37:58 +04:00
|
|
|
|
|
|
|
flags = readb(ioaddr + RTC_FLAGS);
|
|
|
|
writeb(flags | RTC_WRITE, ioaddr + RTC_FLAGS);
|
|
|
|
|
|
|
|
writeb(pdata->alrm_mday < 0 || (pdata->irqen & RTC_UF) ?
|
2008-10-19 07:28:41 +04:00
|
|
|
0x80 : bin2bcd(pdata->alrm_mday),
|
2007-07-21 15:37:58 +04:00
|
|
|
ioaddr + RTC_DATE_ALARM);
|
|
|
|
writeb(pdata->alrm_hour < 0 || (pdata->irqen & RTC_UF) ?
|
2008-10-19 07:28:41 +04:00
|
|
|
0x80 : bin2bcd(pdata->alrm_hour),
|
2007-07-21 15:37:58 +04:00
|
|
|
ioaddr + RTC_HOURS_ALARM);
|
|
|
|
writeb(pdata->alrm_min < 0 || (pdata->irqen & RTC_UF) ?
|
2008-10-19 07:28:41 +04:00
|
|
|
0x80 : bin2bcd(pdata->alrm_min),
|
2007-07-21 15:37:58 +04:00
|
|
|
ioaddr + RTC_MINUTES_ALARM);
|
|
|
|
writeb(pdata->alrm_sec < 0 || (pdata->irqen & RTC_UF) ?
|
2008-10-19 07:28:41 +04:00
|
|
|
0x80 : bin2bcd(pdata->alrm_sec),
|
2007-07-21 15:37:58 +04:00
|
|
|
ioaddr + RTC_SECONDS_ALARM);
|
|
|
|
writeb(pdata->irqen ? RTC_INTS_AIE : 0, ioaddr + RTC_INTERRUPTS);
|
|
|
|
readb(ioaddr + RTC_FLAGS); /* clear interrupts */
|
|
|
|
writeb(flags & ~RTC_WRITE, ioaddr + RTC_FLAGS);
|
2009-12-16 03:46:04 +03:00
|
|
|
spin_unlock_irqrestore(&pdata->lock, irqflags);
|
2007-07-21 15:37:58 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int stk17ta8_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
|
|
|
|
|
2009-01-07 01:42:11 +03:00
|
|
|
if (pdata->irq <= 0)
|
2007-07-21 15:37:58 +04:00
|
|
|
return -EINVAL;
|
|
|
|
pdata->alrm_mday = alrm->time.tm_mday;
|
|
|
|
pdata->alrm_hour = alrm->time.tm_hour;
|
|
|
|
pdata->alrm_min = alrm->time.tm_min;
|
|
|
|
pdata->alrm_sec = alrm->time.tm_sec;
|
|
|
|
if (alrm->enabled)
|
|
|
|
pdata->irqen |= RTC_AF;
|
|
|
|
stk17ta8_rtc_update_alarm(pdata);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stk17ta8_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
|
|
|
|
|
2009-01-07 01:42:11 +03:00
|
|
|
if (pdata->irq <= 0)
|
2007-07-21 15:37:58 +04:00
|
|
|
return -EINVAL;
|
|
|
|
alrm->time.tm_mday = pdata->alrm_mday < 0 ? 0 : pdata->alrm_mday;
|
|
|
|
alrm->time.tm_hour = pdata->alrm_hour < 0 ? 0 : pdata->alrm_hour;
|
|
|
|
alrm->time.tm_min = pdata->alrm_min < 0 ? 0 : pdata->alrm_min;
|
|
|
|
alrm->time.tm_sec = pdata->alrm_sec < 0 ? 0 : pdata->alrm_sec;
|
|
|
|
alrm->enabled = (pdata->irqen & RTC_AF) ? 1 : 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t stk17ta8_rtc_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = dev_id;
|
|
|
|
struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
|
|
|
|
void __iomem *ioaddr = pdata->ioaddr;
|
2009-12-16 03:46:04 +03:00
|
|
|
unsigned long events = 0;
|
2007-07-21 15:37:58 +04:00
|
|
|
|
2009-12-16 03:46:04 +03:00
|
|
|
spin_lock(&pdata->lock);
|
2007-07-21 15:37:58 +04:00
|
|
|
/* read and clear interrupt */
|
2009-12-16 03:46:04 +03:00
|
|
|
if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_AF) {
|
|
|
|
events = RTC_IRQF;
|
|
|
|
if (readb(ioaddr + RTC_SECONDS_ALARM) & 0x80)
|
|
|
|
events |= RTC_UF;
|
|
|
|
else
|
|
|
|
events |= RTC_AF;
|
2014-04-04 01:50:20 +04:00
|
|
|
rtc_update_irq(pdata->rtc, 1, events);
|
2009-12-16 03:46:04 +03:00
|
|
|
}
|
|
|
|
spin_unlock(&pdata->lock);
|
|
|
|
return events ? IRQ_HANDLED : IRQ_NONE;
|
2007-07-21 15:37:58 +04:00
|
|
|
}
|
|
|
|
|
2009-12-16 03:46:04 +03:00
|
|
|
static int stk17ta8_rtc_alarm_irq_enable(struct device *dev,
|
|
|
|
unsigned int enabled)
|
2007-07-21 15:37:58 +04:00
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
|
|
|
|
|
2009-01-07 01:42:11 +03:00
|
|
|
if (pdata->irq <= 0)
|
2009-12-16 03:46:04 +03:00
|
|
|
return -EINVAL;
|
|
|
|
if (enabled)
|
2007-07-21 15:37:58 +04:00
|
|
|
pdata->irqen |= RTC_AF;
|
2009-12-16 03:46:04 +03:00
|
|
|
else
|
|
|
|
pdata->irqen &= ~RTC_AF;
|
|
|
|
stk17ta8_rtc_update_alarm(pdata);
|
2007-07-21 15:37:58 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct rtc_class_ops stk17ta8_rtc_ops = {
|
2009-12-16 03:46:04 +03:00
|
|
|
.read_time = stk17ta8_rtc_read_time,
|
|
|
|
.set_time = stk17ta8_rtc_set_time,
|
|
|
|
.read_alarm = stk17ta8_rtc_read_alarm,
|
|
|
|
.set_alarm = stk17ta8_rtc_set_alarm,
|
|
|
|
.alarm_irq_enable = stk17ta8_rtc_alarm_irq_enable,
|
2007-07-21 15:37:58 +04:00
|
|
|
};
|
|
|
|
|
2010-05-13 05:28:57 +04:00
|
|
|
static ssize_t stk17ta8_nvram_read(struct file *filp, struct kobject *kobj,
|
2007-07-26 20:32:49 +04:00
|
|
|
struct bin_attribute *attr, char *buf,
|
2007-07-21 15:37:58 +04:00
|
|
|
loff_t pos, size_t size)
|
|
|
|
{
|
2009-12-16 03:46:04 +03:00
|
|
|
struct device *dev = container_of(kobj, struct device, kobj);
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
2007-07-21 15:37:58 +04:00
|
|
|
struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
|
|
|
|
void __iomem *ioaddr = pdata->ioaddr;
|
|
|
|
ssize_t count;
|
|
|
|
|
2015-07-27 00:48:35 +03:00
|
|
|
for (count = 0; count < size; count++)
|
2007-07-21 15:37:58 +04:00
|
|
|
*buf++ = readb(ioaddr + pos++);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2010-05-13 05:28:57 +04:00
|
|
|
static ssize_t stk17ta8_nvram_write(struct file *filp, struct kobject *kobj,
|
2007-07-26 20:32:49 +04:00
|
|
|
struct bin_attribute *attr, char *buf,
|
2007-07-21 15:37:58 +04:00
|
|
|
loff_t pos, size_t size)
|
|
|
|
{
|
2009-12-16 03:46:04 +03:00
|
|
|
struct device *dev = container_of(kobj, struct device, kobj);
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
2007-07-21 15:37:58 +04:00
|
|
|
struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
|
|
|
|
void __iomem *ioaddr = pdata->ioaddr;
|
|
|
|
ssize_t count;
|
|
|
|
|
2015-07-27 00:48:35 +03:00
|
|
|
for (count = 0; count < size; count++)
|
2007-07-21 15:37:58 +04:00
|
|
|
writeb(*buf++, ioaddr + pos++);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct bin_attribute stk17ta8_nvram_attr = {
|
|
|
|
.attr = {
|
|
|
|
.name = "nvram",
|
2007-11-15 03:58:30 +03:00
|
|
|
.mode = S_IRUGO | S_IWUSR,
|
2007-07-21 15:37:58 +04:00
|
|
|
},
|
|
|
|
.size = RTC_OFFSET,
|
|
|
|
.read = stk17ta8_nvram_read,
|
|
|
|
.write = stk17ta8_nvram_write,
|
|
|
|
};
|
|
|
|
|
2012-12-22 01:09:38 +04:00
|
|
|
static int stk17ta8_rtc_probe(struct platform_device *pdev)
|
2007-07-21 15:37:58 +04:00
|
|
|
{
|
|
|
|
struct resource *res;
|
|
|
|
unsigned int cal;
|
|
|
|
unsigned int flags;
|
|
|
|
struct rtc_plat_data *pdata;
|
2009-12-16 03:46:04 +03:00
|
|
|
void __iomem *ioaddr;
|
2007-07-21 15:37:58 +04:00
|
|
|
int ret = 0;
|
|
|
|
|
2009-12-16 03:46:04 +03:00
|
|
|
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
|
2007-07-21 15:37:58 +04:00
|
|
|
if (!pdata)
|
|
|
|
return -ENOMEM;
|
2013-09-12 01:24:27 +04:00
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
ioaddr = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(ioaddr))
|
|
|
|
return PTR_ERR(ioaddr);
|
2007-07-21 15:37:58 +04:00
|
|
|
pdata->ioaddr = ioaddr;
|
|
|
|
pdata->irq = platform_get_irq(pdev, 0);
|
|
|
|
|
|
|
|
/* turn RTC on if it was not on */
|
|
|
|
cal = readb(ioaddr + RTC_CALIBRATION);
|
|
|
|
if (cal & RTC_STOP) {
|
|
|
|
cal &= RTC_CAL_MASK;
|
|
|
|
flags = readb(ioaddr + RTC_FLAGS);
|
|
|
|
writeb(flags | RTC_WRITE, ioaddr + RTC_FLAGS);
|
|
|
|
writeb(cal, ioaddr + RTC_CALIBRATION);
|
|
|
|
writeb(flags & ~RTC_WRITE, ioaddr + RTC_FLAGS);
|
|
|
|
}
|
|
|
|
if (readb(ioaddr + RTC_FLAGS) & RTC_FLAGS_PF)
|
|
|
|
dev_warn(&pdev->dev, "voltage-low detected.\n");
|
|
|
|
|
2009-12-16 03:46:04 +03:00
|
|
|
spin_lock_init(&pdata->lock);
|
|
|
|
pdata->last_jiffies = jiffies;
|
|
|
|
platform_set_drvdata(pdev, pdata);
|
2009-01-07 01:42:11 +03:00
|
|
|
if (pdata->irq > 0) {
|
2007-07-21 15:37:58 +04:00
|
|
|
writeb(0, ioaddr + RTC_INTERRUPTS);
|
2009-12-16 03:46:04 +03:00
|
|
|
if (devm_request_irq(&pdev->dev, pdata->irq,
|
|
|
|
stk17ta8_rtc_interrupt,
|
2012-03-24 02:02:34 +04:00
|
|
|
IRQF_SHARED,
|
2007-07-21 15:37:58 +04:00
|
|
|
pdev->name, pdev) < 0) {
|
|
|
|
dev_warn(&pdev->dev, "interrupt not available.\n");
|
2009-01-07 01:42:11 +03:00
|
|
|
pdata->irq = 0;
|
2007-07-21 15:37:58 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-30 03:19:14 +04:00
|
|
|
pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
|
2007-07-21 15:37:58 +04:00
|
|
|
&stk17ta8_rtc_ops, THIS_MODULE);
|
2009-12-16 03:46:04 +03:00
|
|
|
if (IS_ERR(pdata->rtc))
|
|
|
|
return PTR_ERR(pdata->rtc);
|
2009-12-16 03:45:53 +03:00
|
|
|
|
2007-07-21 15:37:58 +04:00
|
|
|
ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
|
2013-04-30 03:19:14 +04:00
|
|
|
|
2007-07-21 15:37:58 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-22 01:09:38 +04:00
|
|
|
static int stk17ta8_rtc_remove(struct platform_device *pdev)
|
2007-07-21 15:37:58 +04:00
|
|
|
{
|
|
|
|
struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
sysfs_remove_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
|
2009-12-16 03:46:04 +03:00
|
|
|
if (pdata->irq > 0)
|
2007-07-21 15:37:58 +04:00
|
|
|
writeb(0, pdata->ioaddr + RTC_INTERRUPTS);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-04-11 08:29:25 +04:00
|
|
|
/* work with hotplug and coldplug */
|
|
|
|
MODULE_ALIAS("platform:stk17ta8");
|
|
|
|
|
2007-07-21 15:37:58 +04:00
|
|
|
static struct platform_driver stk17ta8_rtc_driver = {
|
|
|
|
.probe = stk17ta8_rtc_probe,
|
2012-12-22 01:09:38 +04:00
|
|
|
.remove = stk17ta8_rtc_remove,
|
2007-07-21 15:37:58 +04:00
|
|
|
.driver = {
|
|
|
|
.name = "stk17ta8",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2012-01-11 03:10:48 +04:00
|
|
|
module_platform_driver(stk17ta8_rtc_driver);
|
2007-07-21 15:37:58 +04:00
|
|
|
|
2010-04-14 15:08:28 +04:00
|
|
|
MODULE_AUTHOR("Thomas Hommel <thomas.hommel@ge.com>");
|
2007-07-21 15:37:58 +04:00
|
|
|
MODULE_DESCRIPTION("Simtek STK17TA8 RTC driver");
|
|
|
|
MODULE_LICENSE("GPL");
|