Commit a190901c authored by Russell King's avatar Russell King Committed by Russell King

[RTC] rtc-pl030: add driver, remove old non-rtc lib driver

Convert Integrator PL030 RTC driver to use the RTC class interfaces.
Acked-by: default avatarAlessandro Zummo <a.zummo@towertech.it>
Signed-off-by: default avatarRussell King <rmk+kernel@arm.linux.org.uk>
parent 2dba8518
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# Object file lists. # Object file lists.
obj-y := clock.o core.o lm.o time.o obj-y := clock.o core.o lm.o
obj-$(CONFIG_ARCH_INTEGRATOR_AP) += integrator_ap.o obj-$(CONFIG_ARCH_INTEGRATOR_AP) += integrator_ap.o
obj-$(CONFIG_ARCH_INTEGRATOR_CP) += integrator_cp.o obj-$(CONFIG_ARCH_INTEGRATOR_CP) += integrator_cp.o
......
...@@ -458,6 +458,16 @@ config RTC_DRV_VR41XX ...@@ -458,6 +458,16 @@ config RTC_DRV_VR41XX
To compile this driver as a module, choose M here: the To compile this driver as a module, choose M here: the
module will be called rtc-vr41xx. module will be called rtc-vr41xx.
config RTC_DRV_PL030
tristate "ARM AMBA PL030 RTC"
depends on ARM_AMBA
help
If you say Y here you will get access to ARM AMBA
PrimeCell PL030 RTC found on certain ARM SOCs.
To compile this driver as a module, choose M here: the
module will be called rtc-pl030.
config RTC_DRV_PL031 config RTC_DRV_PL031
tristate "ARM AMBA PL031 RTC" tristate "ARM AMBA PL031 RTC"
depends on ARM_AMBA depends on ARM_AMBA
......
...@@ -40,6 +40,7 @@ obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o ...@@ -40,6 +40,7 @@ obj-$(CONFIG_RTC_DRV_MAX6902) += rtc-max6902.o
obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o
obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o
obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o
obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o
obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o
obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o
obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o
......
/* /*
* linux/arch/arm/mach-integrator/time.c * linux/drivers/rtc/rtc-pl030.c
* *
* Copyright (C) 2000-2001 Deep Blue Solutions Ltd. * Copyright (C) 2000-2001 Deep Blue Solutions Ltd.
* *
...@@ -8,20 +8,11 @@ ...@@ -8,20 +8,11 @@
* published by the Free Software Foundation. * published by the Free Software Foundation.
*/ */
#include <linux/module.h> #include <linux/module.h>
#include <linux/kernel.h> #include <linux/rtc.h>
#include <linux/time.h>
#include <linux/mc146818rtc.h>
#include <linux/interrupt.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/device.h> #include <linux/interrupt.h>
#include <linux/amba/bus.h> #include <linux/amba/bus.h>
#include <linux/io.h>
#include <asm/hardware.h>
#include <asm/io.h>
#include <asm/uaccess.h>
#include <asm/rtc.h>
#include <asm/mach/time.h>
#define RTC_DR (0) #define RTC_DR (0)
#define RTC_MR (4) #define RTC_MR (4)
...@@ -31,23 +22,43 @@ ...@@ -31,23 +22,43 @@
#define RTC_CR (16) #define RTC_CR (16)
#define RTC_CR_MIE (1 << 0) #define RTC_CR_MIE (1 << 0)
extern int (*set_rtc)(void); struct pl030_rtc {
static void __iomem *rtc_base; struct rtc_device *rtc;
void __iomem *base;
};
static irqreturn_t pl030_interrupt(int irq, void *dev_id)
{
struct pl030_rtc *rtc = dev_id;
writel(0, rtc->base + RTC_EOI);
return IRQ_HANDLED;
}
static int pl030_open(struct device *dev)
{
return 0;
}
static void pl030_release(struct device *dev)
{
}
static int integrator_set_rtc(void) static int pl030_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
{ {
__raw_writel(xtime.tv_sec, rtc_base + RTC_LR); return -ENOIOCTLCMD;
return 1;
} }
static int integrator_rtc_read_alarm(struct rtc_wkalrm *alrm) static int pl030_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{ {
rtc_time_to_tm(readl(rtc_base + RTC_MR), &alrm->time); struct pl030_rtc *rtc = dev_get_drvdata(dev);
rtc_time_to_tm(readl(rtc->base + RTC_MR), &alrm->time);
return 0; return 0;
} }
static inline int integrator_rtc_set_alarm(struct rtc_wkalrm *alrm) static int pl030_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
{ {
struct pl030_rtc *rtc = dev_get_drvdata(dev);
unsigned long time; unsigned long time;
int ret; int ret;
...@@ -58,13 +69,16 @@ static inline int integrator_rtc_set_alarm(struct rtc_wkalrm *alrm) ...@@ -58,13 +69,16 @@ static inline int integrator_rtc_set_alarm(struct rtc_wkalrm *alrm)
if (ret == 0) if (ret == 0)
ret = rtc_tm_to_time(&alrm->time, &time); ret = rtc_tm_to_time(&alrm->time, &time);
if (ret == 0) if (ret == 0)
writel(time, rtc_base + RTC_MR); writel(time, rtc->base + RTC_MR);
return ret; return ret;
} }
static int integrator_rtc_read_time(struct rtc_time *tm) static int pl030_read_time(struct device *dev, struct rtc_time *tm)
{ {
rtc_time_to_tm(readl(rtc_base + RTC_DR), tm); struct pl030_rtc *rtc = dev_get_drvdata(dev);
rtc_time_to_tm(readl(rtc->base + RTC_DR), tm);
return 0; return 0;
} }
...@@ -76,121 +90,99 @@ static int integrator_rtc_read_time(struct rtc_time *tm) ...@@ -76,121 +90,99 @@ static int integrator_rtc_read_time(struct rtc_time *tm)
* edge of the 1Hz clock, we must write the time one second * edge of the 1Hz clock, we must write the time one second
* in advance. * in advance.
*/ */
static inline int integrator_rtc_set_time(struct rtc_time *tm) static int pl030_set_time(struct device *dev, struct rtc_time *tm)
{ {
struct pl030_rtc *rtc = dev_get_drvdata(dev);
unsigned long time; unsigned long time;
int ret; int ret;
ret = rtc_tm_to_time(tm, &time); ret = rtc_tm_to_time(tm, &time);
if (ret == 0) if (ret == 0)
writel(time + 1, rtc_base + RTC_LR); writel(time + 1, rtc->base + RTC_LR);
return ret; return ret;
} }
static struct rtc_ops rtc_ops = { static const struct rtc_class_ops pl030_ops = {
.owner = THIS_MODULE, .open = pl030_open,
.read_time = integrator_rtc_read_time, .release = pl030_release,
.set_time = integrator_rtc_set_time, .ioctl = pl030_ioctl,
.read_alarm = integrator_rtc_read_alarm, .read_time = pl030_read_time,
.set_alarm = integrator_rtc_set_alarm, .set_time = pl030_set_time,
.read_alarm = pl030_read_alarm,
.set_alarm = pl030_set_alarm,
}; };
static irqreturn_t arm_rtc_interrupt(int irq, void *dev_id) static int pl030_probe(struct amba_device *dev, void *id)
{
writel(0, rtc_base + RTC_EOI);
return IRQ_HANDLED;
}
static int rtc_probe(struct amba_device *dev, void *id)
{ {
struct pl030_rtc *rtc;
int ret; int ret;
if (rtc_base)
return -EBUSY;
ret = amba_request_regions(dev, NULL); ret = amba_request_regions(dev, NULL);
if (ret) if (ret)
goto out; goto err_req;
rtc_base = ioremap(dev->res.start, SZ_4K); rtc = kmalloc(sizeof(*rtc), GFP_KERNEL);
if (!rtc_base) { if (!rtc) {
ret = -ENOMEM; ret = -ENOMEM;
goto res_out; goto err_rtc;
} }
__raw_writel(0, rtc_base + RTC_CR); rtc->base = ioremap(dev->res.start, SZ_4K);
__raw_writel(0, rtc_base + RTC_EOI); if (!rtc->base) {
ret = -ENOMEM;
goto err_map;
}
xtime.tv_sec = __raw_readl(rtc_base + RTC_DR); __raw_writel(0, rtc->base + RTC_CR);
__raw_writel(0, rtc->base + RTC_EOI);
/* note that 'dev' is merely used for irq disambiguation; amba_set_drvdata(dev, rtc);
* it is not actually referenced in the irq handler
*/
ret = request_irq(dev->irq[0], arm_rtc_interrupt, IRQF_DISABLED,
"rtc-pl030", dev);
if (ret)
goto map_out;
ret = register_rtc(&rtc_ops); ret = request_irq(dev->irq[0], pl030_interrupt, IRQF_DISABLED,
"rtc-pl030", rtc);
if (ret) if (ret)
goto irq_out; goto err_irq;
rtc->rtc = rtc_device_register("pl030", &dev->dev, &pl030_ops,
THIS_MODULE);
if (IS_ERR(rtc->rtc)) {
ret = PTR_ERR(rtc->rtc);
goto err_reg;
}
set_rtc = integrator_set_rtc;
return 0; return 0;
irq_out: err_reg:
free_irq(dev->irq[0], dev); free_irq(dev->irq[0], rtc);
map_out: err_irq:
iounmap(rtc_base); iounmap(rtc->base);
rtc_base = NULL; err_map:
res_out: kfree(rtc);
err_rtc:
amba_release_regions(dev); amba_release_regions(dev);
out: err_req:
return ret; return ret;
} }
static int rtc_remove(struct amba_device *dev) static int pl030_remove(struct amba_device *dev)
{ {
set_rtc = NULL; struct pl030_rtc *rtc = amba_get_drvdata(dev);
writel(0, rtc_base + RTC_CR); amba_set_drvdata(dev, NULL);
free_irq(dev->irq[0], dev); writel(0, rtc->base + RTC_CR);
unregister_rtc(&rtc_ops);
iounmap(rtc_base); free_irq(dev->irq[0], rtc);
rtc_base = NULL; rtc_device_unregister(rtc->rtc);
iounmap(rtc->base);
kfree(rtc);
amba_release_regions(dev); amba_release_regions(dev);
return 0; return 0;
} }
static struct timespec rtc_delta; static struct amba_id pl030_ids[] = {
static int rtc_suspend(struct amba_device *dev, pm_message_t state)
{
struct timespec rtc;
rtc.tv_sec = readl(rtc_base + RTC_DR);
rtc.tv_nsec = 0;
save_time_delta(&rtc_delta, &rtc);
return 0;
}
static int rtc_resume(struct amba_device *dev)
{
struct timespec rtc;
rtc.tv_sec = readl(rtc_base + RTC_DR);
rtc.tv_nsec = 0;
restore_time_delta(&rtc_delta, &rtc);
return 0;
}
static struct amba_id rtc_ids[] = {
{ {
.id = 0x00041030, .id = 0x00041030,
.mask = 0x000fffff, .mask = 0x000fffff,
...@@ -198,26 +190,28 @@ static struct amba_id rtc_ids[] = { ...@@ -198,26 +190,28 @@ static struct amba_id rtc_ids[] = {
{ 0, 0 }, { 0, 0 },
}; };
static struct amba_driver rtc_driver = { static struct amba_driver pl030_driver = {
.drv = { .drv = {
.name = "rtc-pl030", .name = "rtc-pl030",
}, },
.probe = rtc_probe, .probe = pl030_probe,
.remove = rtc_remove, .remove = pl030_remove,
.suspend = rtc_suspend, .id_table = pl030_ids,
.resume = rtc_resume,
.id_table = rtc_ids,
}; };
static int __init integrator_rtc_init(void) static int __init pl030_init(void)
{ {
return amba_driver_register(&rtc_driver); return amba_driver_register(&pl030_driver);
} }
static void __exit integrator_rtc_exit(void) static void __exit pl030_exit(void)
{ {
amba_driver_unregister(&rtc_driver); amba_driver_unregister(&pl030_driver);
} }
module_init(integrator_rtc_init); module_init(pl030_init);
module_exit(integrator_rtc_exit); module_exit(pl030_exit);
MODULE_AUTHOR("Russell King <rmk@arm.linux.org.uk>");
MODULE_DESCRIPTION("ARM AMBA PL030 RTC Driver");
MODULE_LICENSE("GPL");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment