2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2008-08-25 09:30:29 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2008
|
|
|
|
* Gururaja Hebbar gururajakr@sanyo.co.in
|
|
|
|
*
|
|
|
|
* reference linux-2.6.20.6/drivers/rtc/rtc-pl031.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <command.h>
|
2018-09-14 08:06:53 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2008-08-25 09:30:29 +00:00
|
|
|
#include <rtc.h>
|
2018-09-14 08:06:53 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/types.h>
|
2008-08-25 09:30:29 +00: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 */
|
|
|
|
|
|
|
|
#define RTC_CR_START (1 << 0)
|
|
|
|
|
2020-12-03 23:55:23 +00:00
|
|
|
struct pl031_plat {
|
2018-09-14 08:06:53 +00:00
|
|
|
phys_addr_t base;
|
|
|
|
};
|
2008-08-25 09:30:29 +00:00
|
|
|
|
2018-09-14 08:06:53 +00:00
|
|
|
static inline u32 pl031_read_reg(struct udevice *dev, int reg)
|
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct pl031_plat *pdata = dev_get_plat(dev);
|
2008-08-25 09:30:29 +00:00
|
|
|
|
2018-09-14 08:06:53 +00:00
|
|
|
return readl(pdata->base + reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u32 pl031_write_reg(struct udevice *dev, int reg, u32 value)
|
2008-08-25 09:30:29 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct pl031_plat *pdata = dev_get_plat(dev);
|
2008-08-25 09:30:29 +00:00
|
|
|
|
2018-09-14 08:06:53 +00:00
|
|
|
return writel(value, pdata->base + reg);
|
2008-08-25 09:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-09-14 08:06:53 +00:00
|
|
|
* Probe RTC device
|
|
|
|
*/
|
|
|
|
static int pl031_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
/* Enable RTC Start in Control register*/
|
|
|
|
pl031_write_reg(dev, RTC_CR, RTC_CR_START);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the current time from the RTC
|
2008-08-25 09:30:29 +00:00
|
|
|
*/
|
2018-09-14 08:06:53 +00:00
|
|
|
static int pl031_get(struct udevice *dev, struct rtc_time *tm)
|
2008-08-25 09:30:29 +00:00
|
|
|
{
|
2018-09-14 08:06:53 +00:00
|
|
|
unsigned long tim;
|
|
|
|
|
|
|
|
if (!tm)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
tim = pl031_read_reg(dev, RTC_DR);
|
|
|
|
|
|
|
|
rtc_to_tm(tim, tm);
|
|
|
|
|
|
|
|
debug("Get DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
|
|
|
|
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday,
|
|
|
|
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
|
|
|
|
|
|
|
return 0;
|
2008-08-25 09:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the RTC
|
2018-09-14 08:06:53 +00:00
|
|
|
*/
|
|
|
|
static int pl031_set(struct udevice *dev, const struct rtc_time *tm)
|
2008-08-25 09:30:29 +00:00
|
|
|
{
|
|
|
|
unsigned long tim;
|
|
|
|
|
2018-09-14 08:06:53 +00:00
|
|
|
if (!tm)
|
|
|
|
return -EINVAL;
|
2008-08-25 09:30:29 +00:00
|
|
|
|
2018-09-14 08:06:53 +00:00
|
|
|
debug("Set DATE: %4d-%02d-%02d (wday=%d) TIME: %2d:%02d:%02d\n",
|
|
|
|
tm->tm_year, tm->tm_mon, tm->tm_mday, tm->tm_wday,
|
|
|
|
tm->tm_hour, tm->tm_min, tm->tm_sec);
|
2008-08-25 09:30:29 +00:00
|
|
|
|
|
|
|
/* Calculate number of seconds this incoming time represents */
|
2018-09-14 08:06:53 +00:00
|
|
|
tim = rtc_mktime(tm);
|
2008-08-25 09:30:29 +00:00
|
|
|
|
2018-09-14 08:06:53 +00:00
|
|
|
pl031_write_reg(dev, RTC_LR, tim);
|
2008-09-01 21:06:23 +00:00
|
|
|
|
2018-09-14 08:06:53 +00:00
|
|
|
return 0;
|
2008-08-25 09:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-09-14 08:06:53 +00:00
|
|
|
* Reset the RTC. We set the date back to 1970-01-01.
|
2008-08-25 09:30:29 +00:00
|
|
|
*/
|
2018-09-14 08:06:53 +00:00
|
|
|
static int pl031_reset(struct udevice *dev)
|
2008-08-25 09:30:29 +00:00
|
|
|
{
|
2018-09-14 08:06:53 +00:00
|
|
|
pl031_write_reg(dev, RTC_LR, 0);
|
2008-08-25 09:30:29 +00:00
|
|
|
|
2018-09-14 08:06:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2008-08-25 09:30:29 +00:00
|
|
|
|
2018-09-14 08:06:53 +00:00
|
|
|
static const struct rtc_ops pl031_ops = {
|
|
|
|
.get = pl031_get,
|
|
|
|
.set = pl031_set,
|
|
|
|
.reset = pl031_reset,
|
|
|
|
};
|
2008-08-25 09:30:29 +00:00
|
|
|
|
2018-09-14 08:06:53 +00:00
|
|
|
static const struct udevice_id pl031_ids[] = {
|
|
|
|
{ .compatible = "arm,pl031" },
|
|
|
|
{ }
|
|
|
|
};
|
2008-08-25 09:30:29 +00:00
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int pl031_of_to_plat(struct udevice *dev)
|
2018-09-14 08:06:53 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct pl031_plat *pdata = dev_get_plat(dev);
|
2008-08-25 09:30:29 +00:00
|
|
|
|
2018-09-14 08:06:53 +00:00
|
|
|
pdata->base = dev_read_addr(dev);
|
2008-08-25 09:30:29 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-14 08:06:53 +00:00
|
|
|
U_BOOT_DRIVER(rtc_pl031) = {
|
|
|
|
.name = "rtc-pl031",
|
|
|
|
.id = UCLASS_RTC,
|
|
|
|
.of_match = pl031_ids,
|
|
|
|
.probe = pl031_probe,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = pl031_of_to_plat,
|
2020-12-03 23:55:23 +00:00
|
|
|
.plat_auto = sizeof(struct pl031_plat),
|
2018-09-14 08:06:53 +00:00
|
|
|
.ops = &pl031_ops,
|
|
|
|
};
|