2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-10-22 14:28:53 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2000-2002
|
|
|
|
* Wolfgang Denk, DENX Software Engineering, wd@denx.de.
|
|
|
|
*
|
|
|
|
* (C) Copyright 2004, Psyent Corporation <www.psyent.com>
|
|
|
|
* Scott McNutt <smcnutt@psyent.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <timer.h>
|
|
|
|
#include <asm/io.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2015-10-22 14:28:53 +00:00
|
|
|
|
2015-10-31 12:54:16 +00:00
|
|
|
/* control register */
|
|
|
|
#define ALTERA_TIMER_CONT BIT(1) /* Continuous mode */
|
|
|
|
#define ALTERA_TIMER_START BIT(2) /* Start timer */
|
|
|
|
#define ALTERA_TIMER_STOP BIT(3) /* Stop timer */
|
|
|
|
|
2015-10-22 14:28:53 +00:00
|
|
|
struct altera_timer_regs {
|
|
|
|
u32 status; /* Timer status reg */
|
|
|
|
u32 control; /* Timer control reg */
|
|
|
|
u32 periodl; /* Timeout period low */
|
|
|
|
u32 periodh; /* Timeout period high */
|
|
|
|
u32 snapl; /* Snapshot low */
|
|
|
|
u32 snaph; /* Snapshot high */
|
|
|
|
};
|
|
|
|
|
2020-12-03 23:55:23 +00:00
|
|
|
struct altera_timer_plat {
|
2015-10-22 14:28:53 +00:00
|
|
|
struct altera_timer_regs *regs;
|
|
|
|
};
|
|
|
|
|
2020-10-07 18:37:44 +00:00
|
|
|
static u64 altera_timer_get_count(struct udevice *dev)
|
2015-10-22 14:28:53 +00:00
|
|
|
{
|
2020-12-23 02:30:28 +00:00
|
|
|
struct altera_timer_plat *plat = dev_get_plat(dev);
|
2015-10-22 14:28:53 +00:00
|
|
|
struct altera_timer_regs *const regs = plat->regs;
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
/* Trigger update */
|
|
|
|
writel(0x0, ®s->snapl);
|
|
|
|
|
|
|
|
/* Read timer value */
|
|
|
|
val = readl(®s->snapl) & 0xffff;
|
|
|
|
val |= (readl(®s->snaph) & 0xffff) << 16;
|
2020-10-07 18:37:44 +00:00
|
|
|
return timer_conv_64(~val);
|
2015-10-22 14:28:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int altera_timer_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-23 02:30:28 +00:00
|
|
|
struct altera_timer_plat *plat = dev_get_plat(dev);
|
2015-10-22 14:28:53 +00:00
|
|
|
struct altera_timer_regs *const regs = plat->regs;
|
|
|
|
|
|
|
|
writel(0, ®s->status);
|
|
|
|
writel(0, ®s->control);
|
|
|
|
writel(ALTERA_TIMER_STOP, ®s->control);
|
|
|
|
|
|
|
|
writel(0xffff, ®s->periodl);
|
|
|
|
writel(0xffff, ®s->periodh);
|
|
|
|
writel(ALTERA_TIMER_CONT | ALTERA_TIMER_START, ®s->control);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int altera_timer_of_to_plat(struct udevice *dev)
|
2015-10-22 14:28:53 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct altera_timer_plat *plat = dev_get_plat(dev);
|
2015-10-22 14:28:53 +00:00
|
|
|
|
2020-07-17 05:36:48 +00:00
|
|
|
plat->regs = map_physmem(dev_read_addr(dev),
|
2015-11-14 03:15:31 +00:00
|
|
|
sizeof(struct altera_timer_regs),
|
|
|
|
MAP_NOCACHE);
|
2015-10-22 14:28:53 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct timer_ops altera_timer_ops = {
|
|
|
|
.get_count = altera_timer_get_count,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id altera_timer_ids[] = {
|
2015-10-31 12:54:16 +00:00
|
|
|
{ .compatible = "altr,timer-1.0" },
|
|
|
|
{}
|
2015-10-22 14:28:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(altera_timer) = {
|
|
|
|
.name = "altera_timer",
|
|
|
|
.id = UCLASS_TIMER,
|
|
|
|
.of_match = altera_timer_ids,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = altera_timer_of_to_plat,
|
2020-12-03 23:55:23 +00:00
|
|
|
.plat_auto = sizeof(struct altera_timer_plat),
|
2015-10-22 14:28:53 +00:00
|
|
|
.probe = altera_timer_probe,
|
|
|
|
.ops = &altera_timer_ops,
|
|
|
|
};
|