1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
// SPDX-License-Identifier: GPL-2.0-or-later
/**
* @file
* @brief Support DMTimer counter
*
* FileName: arch/arm/mach-omap/dmtimer.c
*/
/*
* This File is based on arch/arm/mach-omap/s32k_clksource.c
* (C) Copyright 2008
* Texas Instruments, <www.ti.com>
* Nishanth Menon <x0nishan@ti.com>
*
* (C) Copyright 2012 Phytec Messtechnik GmbH
* Author: Teresa Gámez <t.gamez@phytec.de>
* (C) Copyright 2015 Phytec Messtechnik GmbH
* Author: Daniel Schultz <d.schultz@phytec.de>
*/
#include <common.h>
#include <clock.h>
#include <init.h>
#include <io.h>
#include <mach/omap/am33xx-silicon.h>
#include <mach/omap/am33xx-clock.h>
#include <stdio.h>
#define CLK_RC32K 32768
#define TIDR 0x0
#define TIOCP_CFG 0x10
#define IRQ_EOI 0x20
#define IRQSTATUS_RAW 0x24
#define IRQSTATUS 0x28
#define IRQSTATUS_SET 0x2c
#define IRQSTATUS_CLR 0x30
#define IRQWAKEEN 0x34
#define TCLR 0x38
#define TCRR 0x3C
#define TLDR 0x40
#define TTGR 0x44
#define TWPS 0x48
#define TMAR 0x4C
#define TCAR1 0x50
#define TSICR 0x54
#define TCAR2 0x58
static void *base;
/**
* @brief Provide a simple counter read
*
* @return DMTimer counter
*/
static uint64_t dmtimer_read(void)
{
return readl(base + TCRR);
}
static struct clocksource dmtimer_cs = {
.read = dmtimer_read,
.mask = CLOCKSOURCE_MASK(32),
.shift = 10,
.priority = 70,
};
static int omap_dmtimer_probe(struct device *dev)
{
struct resource *iores;
u64 clk_speed;
/* one timer is enough */
if (base)
return 0;
iores = dev_request_mem_resource(dev, 0);
if (IS_ERR(iores))
return PTR_ERR(iores);
base = IOMEM(iores->start);
clk_speed = am33xx_get_osc_clock();
clk_speed *= 1000;
dmtimer_cs.mult = clocksource_hz2mult(clk_speed, dmtimer_cs.shift);
/* Enable counter */
writel(0x3, base + TCLR);
return init_clock(&dmtimer_cs);
}
static __maybe_unused struct of_device_id omap_dmtimer_dt_ids[] = {
{
.compatible = "ti,am335x-timer",
}, {
/* sentinel */
}
};
static struct driver omap_dmtimer_driver = {
.name = "omap-dmtimer",
.probe = omap_dmtimer_probe,
.of_compatible = DRV_OF_COMPAT(omap_dmtimer_dt_ids),
};
postcore_platform_driver(omap_dmtimer_driver);
|