Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
1
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
57963a9
Documentation
LICENSES
arch
block
certs
crypto
drivers
accessibility
acpi
amba
android
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cdrom
char
clk
clocksource
Kconfig
Makefile
acpi_pm.c
arc_timer.c
arm_arch_timer.c
arm_global_timer.c
armv7m_systick.c
asm9260_timer.c
bcm2835_timer.c
bcm_kona_timer.c
clksrc-dbx500-prcmu.c
clksrc_st_lpc.c
clps711x-timer.c
dummy_timer.c
dw_apb_timer.c
dw_apb_timer_of.c
em_sti.c
exynos_mct.c
h8300_timer16.c
h8300_timer8.c
h8300_tpu.c
hyperv_timer.c
i8253.c
ingenic-ost.c
ingenic-sysost.c
ingenic-timer.c
jcore-pit.c
mips-gic-timer.c
mmio.c
mps2-timer.c
mxs_timer.c
nomadik-mtu.c
numachip.c
renesas-ostm.c
samsung_pwm_timer.c
scx200_hrt.c
sh_cmt.c
sh_mtu2.c
sh_tmu.c
timer-armada-370-xp.c
timer-atmel-pit.c
timer-atmel-st.c
timer-atmel-tcb.c
timer-cadence-ttc.c
timer-clint.c
timer-cs5535.c
timer-davinci.c
timer-digicolor.c
timer-fsl-ftm.c
timer-fttmr010.c
timer-gx6605s.c
timer-imx-gpt.c
timer-imx-sysctr.c
timer-imx-tpm.c
timer-integrator-ap.c
timer-ixp4xx.c
timer-keystone.c
timer-lpc32xx.c
timer-mediatek.c
timer-meson6.c
timer-microchip-pit64b.c
timer-milbeaut.c
timer-mp-csky.c
timer-msc313e.c
timer-npcm7xx.c
timer-of.c
timer-of.h
timer-orion.c
timer-owl.c
timer-oxnas-rps.c
timer-pistachio.c
timer-probe.c
timer-pxa.c
timer-qcom.c
timer-rda.c
timer-riscv.c
timer-rockchip.c
timer-sp.h
timer-sp804.c
timer-sprd.c
timer-stm32-lp.c
timer-stm32.c
timer-sun4i.c
timer-sun5i.c
timer-tegra.c
timer-ti-32k.c
timer-ti-dm-systimer.c
timer-ti-dm.c
timer-versatile.c
timer-vf-pit.c
timer-vt8500.c
timer-zevio.c
comedi
connector
counter
cpufreq
cpuidle
crypto
cxl
dax
dca
devfreq
dio
dma-buf
dma
edac
eisa
extcon
firewire
firmware
fpga
fsi
gnss
gpio
gpu
greybus
hid
hsi
hv
hwmon
hwspinlock
hwtracing
i2c
i3c
idle
iio
infiniband
input
interconnect
iommu
ipack
irqchip
isdn
leds
macintosh
mailbox
mcb
md
media
memory
memstick
message
mfd
misc
mmc
most
mtd
mux
net
nfc
ntb
nubus
nvdimm
nvme
nvmem
of
opp
parisc
parport
pci
pcmcia
peci
perf
phy
pinctrl
platform
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
s390
sbus
scsi
sh
siox
slimbus
soc
soundwire
spi
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty
uio
usb
vdpa
vfio
vhost
video
virt
virtio
visorbus
vlynq
vme
w1
watchdog
xen
zorro
Kconfig
Makefile
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.clang-format
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
drivers
/
clocksource
/
timer-lpc32xx.c
Copy path
Blame
Blame
Latest commit
History
History
310 lines (261 loc) · 7.97 KB
Breadcrumbs
linux
/
drivers
/
clocksource
/
timer-lpc32xx.c
Top
File metadata and controls
Code
Blame
310 lines (261 loc) · 7.97 KB
Raw
// SPDX-License-Identifier: GPL-2.0 /* * Clocksource driver for NXP LPC32xx/18xx/43xx timer * * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com> * * Based on: * time-efm32 Copyright (C) 2013 Pengutronix * mach-lpc32xx/timer.c Copyright (C) 2009 - 2010 NXP Semiconductors */ #define pr_fmt(fmt) "%s: " fmt, __func__ #include <linux/clk.h> #include <linux/clockchips.h> #include <linux/clocksource.h> #include <linux/delay.h> #include <linux/interrupt.h> #include <linux/irq.h> #include <linux/kernel.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/of_irq.h> #include <linux/sched_clock.h> #define LPC32XX_TIMER_IR 0x000 #define LPC32XX_TIMER_IR_MR0INT BIT(0) #define LPC32XX_TIMER_TCR 0x004 #define LPC32XX_TIMER_TCR_CEN BIT(0) #define LPC32XX_TIMER_TCR_CRST BIT(1) #define LPC32XX_TIMER_TC 0x008 #define LPC32XX_TIMER_PR 0x00c #define LPC32XX_TIMER_MCR 0x014 #define LPC32XX_TIMER_MCR_MR0I BIT(0) #define LPC32XX_TIMER_MCR_MR0R BIT(1) #define LPC32XX_TIMER_MCR_MR0S BIT(2) #define LPC32XX_TIMER_MR0 0x018 #define LPC32XX_TIMER_CTCR 0x070 struct lpc32xx_clock_event_ddata { struct clock_event_device evtdev; void __iomem *base; u32 ticks_per_jiffy; }; /* Needed for the sched clock */ static void __iomem *clocksource_timer_counter; static u64 notrace lpc32xx_read_sched_clock(void) { return readl(clocksource_timer_counter); } static unsigned long lpc32xx_delay_timer_read(void) { return readl(clocksource_timer_counter); } static struct delay_timer lpc32xx_delay_timer = { .read_current_timer = lpc32xx_delay_timer_read, }; static int lpc32xx_clkevt_next_event(unsigned long delta, struct clock_event_device *evtdev) { struct lpc32xx_clock_event_ddata *ddata = container_of(evtdev, struct lpc32xx_clock_event_ddata, evtdev); /* * Place timer in reset and program the delta in the match * channel 0 (MR0). When the timer counter matches the value * in MR0 register the match will trigger an interrupt. * After setup the timer is released from reset and enabled. */ writel_relaxed(LPC32XX_TIMER_TCR_CRST, ddata->base + LPC32XX_TIMER_TCR); writel_relaxed(delta, ddata->base + LPC32XX_TIMER_MR0); writel_relaxed(LPC32XX_TIMER_TCR_CEN, ddata->base + LPC32XX_TIMER_TCR); return 0; } static int lpc32xx_clkevt_shutdown(struct clock_event_device *evtdev) { struct lpc32xx_clock_event_ddata *ddata = container_of(evtdev, struct lpc32xx_clock_event_ddata, evtdev); /* Disable the timer */ writel_relaxed(0, ddata->base + LPC32XX_TIMER_TCR); return 0; } static int lpc32xx_clkevt_oneshot(struct clock_event_device *evtdev) { struct lpc32xx_clock_event_ddata *ddata = container_of(evtdev, struct lpc32xx_clock_event_ddata, evtdev); /* * When using oneshot, we must also disable the timer * to wait for the first call to set_next_event(). */ writel_relaxed(0, ddata->base + LPC32XX_TIMER_TCR); /* Enable interrupt, reset on match and stop on match (MCR). */ writel_relaxed(LPC32XX_TIMER_MCR_MR0I | LPC32XX_TIMER_MCR_MR0R | LPC32XX_TIMER_MCR_MR0S, ddata->base + LPC32XX_TIMER_MCR); return 0; } static int lpc32xx_clkevt_periodic(struct clock_event_device *evtdev) { struct lpc32xx_clock_event_ddata *ddata = container_of(evtdev, struct lpc32xx_clock_event_ddata, evtdev); /* Enable interrupt and reset on match. */ writel_relaxed(LPC32XX_TIMER_MCR_MR0I | LPC32XX_TIMER_MCR_MR0R, ddata->base + LPC32XX_TIMER_MCR); /* * Place timer in reset and program the delta in the match * channel 0 (MR0). */ writel_relaxed(LPC32XX_TIMER_TCR_CRST, ddata->base + LPC32XX_TIMER_TCR); writel_relaxed(ddata->ticks_per_jiffy, ddata->base + LPC32XX_TIMER_MR0); writel_relaxed(LPC32XX_TIMER_TCR_CEN, ddata->base + LPC32XX_TIMER_TCR); return 0; } static irqreturn_t lpc32xx_clock_event_handler(int irq, void *dev_id) { struct lpc32xx_clock_event_ddata *ddata = dev_id; /* Clear match on channel 0 */ writel_relaxed(LPC32XX_TIMER_IR_MR0INT, ddata->base + LPC32XX_TIMER_IR); ddata->evtdev.event_handler(&ddata->evtdev); return IRQ_HANDLED; } static struct lpc32xx_clock_event_ddata lpc32xx_clk_event_ddata = { .evtdev = { .name = "lpc3220 clockevent", .features = CLOCK_EVT_FEAT_ONESHOT | CLOCK_EVT_FEAT_PERIODIC, .rating = 300, .set_next_event = lpc32xx_clkevt_next_event, .set_state_shutdown = lpc32xx_clkevt_shutdown, .set_state_oneshot = lpc32xx_clkevt_oneshot, .set_state_periodic = lpc32xx_clkevt_periodic, }, }; static int __init lpc32xx_clocksource_init(struct device_node *np) { void __iomem *base; unsigned long rate; struct clk *clk; int ret; clk = of_clk_get_by_name(np, "timerclk"); if (IS_ERR(clk)) { pr_err("clock get failed (%ld)\n", PTR_ERR(clk)); return PTR_ERR(clk); } ret = clk_prepare_enable(clk); if (ret) { pr_err("clock enable failed (%d)\n", ret); goto err_clk_enable; } base = of_iomap(np, 0); if (!base) { pr_err("unable to map registers\n"); ret = -EADDRNOTAVAIL; goto err_iomap; } /* * Disable and reset timer then set it to free running timer * mode (CTCR) with no prescaler (PR) or match operations (MCR). * After setup the timer is released from reset and enabled. */ writel_relaxed(LPC32XX_TIMER_TCR_CRST, base + LPC32XX_TIMER_TCR); writel_relaxed(0, base + LPC32XX_TIMER_PR); writel_relaxed(0, base + LPC32XX_TIMER_MCR); writel_relaxed(0, base + LPC32XX_TIMER_CTCR); writel_relaxed(LPC32XX_TIMER_TCR_CEN, base + LPC32XX_TIMER_TCR); rate = clk_get_rate(clk); ret = clocksource_mmio_init(base + LPC32XX_TIMER_TC, "lpc3220 timer", rate, 300, 32, clocksource_mmio_readl_up); if (ret) { pr_err("failed to init clocksource (%d)\n", ret); goto err_clocksource_init; } clocksource_timer_counter = base + LPC32XX_TIMER_TC; lpc32xx_delay_timer.freq = rate; register_current_timer_delay(&lpc32xx_delay_timer); sched_clock_register(lpc32xx_read_sched_clock, 32, rate); return 0; err_clocksource_init: iounmap(base); err_iomap: clk_disable_unprepare(clk); err_clk_enable: clk_put(clk); return ret; } static int __init lpc32xx_clockevent_init(struct device_node *np) { void __iomem *base; unsigned long rate; struct clk *clk; int ret, irq; clk = of_clk_get_by_name(np, "timerclk"); if (IS_ERR(clk)) { pr_err("clock get failed (%ld)\n", PTR_ERR(clk)); return PTR_ERR(clk); } ret = clk_prepare_enable(clk); if (ret) { pr_err("clock enable failed (%d)\n", ret); goto err_clk_enable; } base = of_iomap(np, 0); if (!base) { pr_err("unable to map registers\n"); ret = -EADDRNOTAVAIL; goto err_iomap; } irq = irq_of_parse_and_map(np, 0); if (!irq) { pr_err("get irq failed\n"); ret = -ENOENT; goto err_irq; } /* * Disable timer and clear any pending interrupt (IR) on match * channel 0 (MR0). Clear the prescaler as it's not used. */ writel_relaxed(0, base + LPC32XX_TIMER_TCR); writel_relaxed(0, base + LPC32XX_TIMER_PR); writel_relaxed(0, base + LPC32XX_TIMER_CTCR); writel_relaxed(LPC32XX_TIMER_IR_MR0INT, base + LPC32XX_TIMER_IR); rate = clk_get_rate(clk); lpc32xx_clk_event_ddata.base = base; lpc32xx_clk_event_ddata.ticks_per_jiffy = DIV_ROUND_CLOSEST(rate, HZ); clockevents_config_and_register(&lpc32xx_clk_event_ddata.evtdev, rate, 1, -1); ret = request_irq(irq, lpc32xx_clock_event_handler, IRQF_TIMER | IRQF_IRQPOLL, "lpc3220 clockevent", &lpc32xx_clk_event_ddata); if (ret) { pr_err("request irq failed\n"); goto err_irq; } return 0; err_irq: iounmap(base); err_iomap: clk_disable_unprepare(clk); err_clk_enable: clk_put(clk); return ret; } /* * This function asserts that we have exactly one clocksource and one * clock_event_device in the end. */ static int __init lpc32xx_timer_init(struct device_node *np) { static int has_clocksource, has_clockevent; int ret = 0; if (!has_clocksource) { ret = lpc32xx_clocksource_init(np); if (!ret) { has_clocksource = 1; return 0; } } if (!has_clockevent) { ret = lpc32xx_clockevent_init(np); if (!ret) { has_clockevent = 1; return 0; } } return ret; } TIMER_OF_DECLARE(lpc32xx_timer, "nxp,lpc3220-timer", lpc32xx_timer_init);
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
You can’t perform that action at this time.