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
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
c92e7ef
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-goldfish.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-goldfish.c
Blame
Blame
Latest commit
History
History
153 lines (119 loc) · 3.57 KB
Breadcrumbs
linux
/
drivers
/
clocksource
/
timer-goldfish.c
Top
File metadata and controls
Code
Blame
153 lines (119 loc) · 3.57 KB
Raw
// SPDX-License-Identifier: GPL-2.0 #include <linux/interrupt.h> #include <linux/ioport.h> #include <linux/clocksource.h> #include <linux/clockchips.h> #include <linux/module.h> #include <linux/slab.h> #include <linux/goldfish.h> #include <clocksource/timer-goldfish.h> struct goldfish_timer { struct clocksource cs; struct clock_event_device ced; struct resource res; void __iomem *base; }; static struct goldfish_timer *ced_to_gf(struct clock_event_device *ced) { return container_of(ced, struct goldfish_timer, ced); } static struct goldfish_timer *cs_to_gf(struct clocksource *cs) { return container_of(cs, struct goldfish_timer, cs); } static u64 goldfish_timer_read(struct clocksource *cs) { struct goldfish_timer *timerdrv = cs_to_gf(cs); void __iomem *base = timerdrv->base; u32 time_low, time_high; u64 ticks; /* * time_low: get low bits of current time and update time_high * time_high: get high bits of time at last time_low read */ time_low = gf_ioread32(base + TIMER_TIME_LOW); time_high = gf_ioread32(base + TIMER_TIME_HIGH); ticks = ((u64)time_high << 32) | time_low; return ticks; } static int goldfish_timer_set_oneshot(struct clock_event_device *evt) { struct goldfish_timer *timerdrv = ced_to_gf(evt); void __iomem *base = timerdrv->base; gf_iowrite32(0, base + TIMER_ALARM_HIGH); gf_iowrite32(0, base + TIMER_ALARM_LOW); gf_iowrite32(1, base + TIMER_IRQ_ENABLED); return 0; } static int goldfish_timer_shutdown(struct clock_event_device *evt) { struct goldfish_timer *timerdrv = ced_to_gf(evt); void __iomem *base = timerdrv->base; gf_iowrite32(0, base + TIMER_IRQ_ENABLED); return 0; } static int goldfish_timer_next_event(unsigned long delta, struct clock_event_device *evt) { struct goldfish_timer *timerdrv = ced_to_gf(evt); void __iomem *base = timerdrv->base; u64 now; now = goldfish_timer_read(&timerdrv->cs); now += delta; gf_iowrite32(upper_32_bits(now), base + TIMER_ALARM_HIGH); gf_iowrite32(lower_32_bits(now), base + TIMER_ALARM_LOW); return 0; } static irqreturn_t goldfish_timer_irq(int irq, void *dev_id) { struct goldfish_timer *timerdrv = dev_id; struct clock_event_device *evt = &timerdrv->ced; void __iomem *base = timerdrv->base; gf_iowrite32(1, base + TIMER_CLEAR_INTERRUPT); evt->event_handler(evt); return IRQ_HANDLED; } int __init goldfish_timer_init(int irq, void __iomem *base) { struct goldfish_timer *timerdrv; int ret; timerdrv = kzalloc(sizeof(*timerdrv), GFP_KERNEL); if (!timerdrv) return -ENOMEM; timerdrv->base = base; timerdrv->ced = (struct clock_event_device){ .name = "goldfish_timer", .features = CLOCK_EVT_FEAT_ONESHOT, .set_state_shutdown = goldfish_timer_shutdown, .set_state_oneshot = goldfish_timer_set_oneshot, .set_next_event = goldfish_timer_next_event, }; timerdrv->res = (struct resource){ .name = "goldfish_timer", .start = (unsigned long)base, .end = (unsigned long)base + 0xfff, }; ret = request_resource(&iomem_resource, &timerdrv->res); if (ret) { pr_err("Cannot allocate '%s' resource\n", timerdrv->res.name); return ret; } timerdrv->cs = (struct clocksource){ .name = "goldfish_timer", .rating = 400, .read = goldfish_timer_read, .mask = CLOCKSOURCE_MASK(64), .flags = 0, .max_idle_ns = LONG_MAX, }; clocksource_register_hz(&timerdrv->cs, NSEC_PER_SEC); ret = request_irq(irq, goldfish_timer_irq, IRQF_TIMER, "goldfish_timer", timerdrv); if (ret) { pr_err("Couldn't register goldfish-timer interrupt\n"); return ret; } clockevents_config_and_register(&timerdrv->ced, NSEC_PER_SEC, 1, 0xffffffff); return 0; }
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
You can’t perform that action at this time.