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
eadc4e4
Documentation
LICENSES
arch
block
certs
crypto
drivers
accessibility
acpi
amba
android
ata
atm
auxdisplay
base
bcma
block
bluetooth
bus
cdrom
char
clk
clocksource
connector
counter
cpufreq
cpuidle
crypto
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
ide
idle
iio
infiniband
input
interconnect
iommu
ipack
irqchip
isdn
leds
lightnvm
macintosh
mailbox
mcb
md
media
memory
memstick
message
mfd
misc
mmc
mtd
mux
net
nfc
ntb
nubus
nvdimm
nvme
nvmem
of
opp
oprofile
parisc
parport
pci
pcmcia
perf
phy
pinctrl
platform
pnp
power
powercap
pps
ps3
ptp
pwm
rapidio
ras
regulator
remoteproc
reset
rpmsg
rtc
Kconfig
Makefile
class.c
dev.c
hctosys.c
interface.c
lib.c
nvmem.c
proc.c
rtc-88pm80x.c
rtc-88pm860x.c
rtc-ab-b5ze-s3.c
rtc-ab-eoz9.c
rtc-ab3100.c
rtc-ab8500.c
rtc-abx80x.c
rtc-ac100.c
rtc-armada38x.c
rtc-as3722.c
rtc-asm9260.c
rtc-aspeed.c
rtc-at91rm9200.c
rtc-at91sam9.c
rtc-au1xxx.c
rtc-bd70528.c
rtc-bq32k.c
rtc-bq4802.c
rtc-brcmstb-waketimer.c
rtc-cadence.c
rtc-cmos.c
rtc-coh901331.c
rtc-core.h
rtc-cpcap.c
rtc-cros-ec.c
rtc-da9052.c
rtc-da9055.c
rtc-da9063.c
rtc-davinci.c
rtc-digicolor.c
rtc-dm355evm.c
rtc-ds1216.c
rtc-ds1286.c
rtc-ds1302.c
rtc-ds1305.c
rtc-ds1307.c
rtc-ds1343.c
rtc-ds1347.c
rtc-ds1374.c
rtc-ds1390.c
rtc-ds1511.c
rtc-ds1553.c
rtc-ds1672.c
rtc-ds1685.c
rtc-ds1742.c
rtc-ds2404.c
rtc-ds3232.c
rtc-efi-platform.c
rtc-efi.c
rtc-em3027.c
rtc-ep93xx.c
rtc-fm3130.c
rtc-fsl-ftm-alarm.c
rtc-ftrtc010.c
rtc-generic.c
rtc-goldfish.c
rtc-hid-sensor-time.c
rtc-hym8563.c
rtc-imx-sc.c
rtc-imxdi.c
rtc-isl12022.c
rtc-isl12026.c
rtc-isl1208.c
rtc-jz4740.c
rtc-lp8788.c
rtc-lpc24xx.c
rtc-lpc32xx.c
rtc-ls1x.c
rtc-m41t80.c
rtc-m41t93.c
rtc-m41t94.c
rtc-m48t35.c
rtc-m48t59.c
rtc-m48t86.c
rtc-max6900.c
rtc-max6902.c
rtc-max6916.c
rtc-max77686.c
rtc-max8907.c
rtc-max8925.c
rtc-max8997.c
rtc-max8998.c
rtc-mc13xxx.c
rtc-mc146818-lib.c
rtc-mcp795.c
rtc-meson-vrtc.c
rtc-meson.c
rtc-moxart.c
rtc-mpc5121.c
rtc-mrst.c
rtc-msm6242.c
rtc-mt6397.c
rtc-mt7622.c
rtc-mv.c
rtc-mxc.c
rtc-mxc_v2.c
rtc-omap.c
rtc-opal.c
rtc-palmas.c
rtc-pcap.c
rtc-pcf2123.c
rtc-pcf2127.c
rtc-pcf50633.c
rtc-pcf85063.c
rtc-pcf8523.c
rtc-pcf85363.c
rtc-pcf8563.c
rtc-pcf8583.c
rtc-pic32.c
rtc-pl030.c
rtc-pl031.c
rtc-pm8xxx.c
rtc-ps3.c
rtc-puv3.c
rtc-pxa.c
rtc-r7301.c
rtc-r9701.c
rtc-rc5t583.c
rtc-rk808.c
rtc-rp5c01.c
rtc-rs5c313.c
rtc-rs5c348.c
rtc-rs5c372.c
rtc-rtd119x.c
rtc-rv3028.c
rtc-rv3029c2.c
rtc-rv8803.c
rtc-rx4581.c
rtc-rx6110.c
rtc-rx8010.c
rtc-rx8025.c
rtc-rx8581.c
rtc-s35390a.c
rtc-s3c.c
rtc-s3c.h
rtc-s5m.c
rtc-sa1100.c
rtc-sa1100.h
rtc-sc27xx.c
rtc-sd3078.c
rtc-sh.c
rtc-sirfsoc.c
rtc-snvs.c
rtc-spear.c
rtc-st-lpc.c
rtc-starfire.c
rtc-stk17ta8.c
rtc-stm32.c
rtc-stmp3xxx.c
rtc-sun4v.c
rtc-sun6i.c
rtc-sunxi.c
rtc-tegra.c
rtc-test.c
rtc-tps6586x.c
rtc-tps65910.c
rtc-tps80031.c
rtc-twl.c
rtc-tx4939.c
rtc-v3020.c
rtc-vr41xx.c
rtc-vt8500.c
rtc-wilco-ec.c
rtc-wm831x.c
rtc-wm8350.c
rtc-x1205.c
rtc-xgene.c
rtc-zynqmp.c
sysfs.c
systohc.c
s390
sbus
scsi
sfi
sh
siox
slimbus
soc
soundwire
spi
spmi
ssb
staging
target
tc
tee
thermal
thunderbolt
tty
uio
usb
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
/
rtc
/
rtc-asm9260.c
Blame
Blame
Latest commit
Chuhong Yuan
and
Alexandre Belloni
rtc: asm9260: add the missed check for devm_clk_get
Dec 23, 2019
62cbe63
·
Dec 23, 2019
History
History
340 lines (280 loc) · 8.97 KB
Breadcrumbs
linux
/
drivers
/
rtc
/
rtc-asm9260.c
Top
File metadata and controls
Code
Blame
340 lines (280 loc) · 8.97 KB
Raw
// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (C) 2016 Oleksij Rempel <linux@rempel-privat.de> */ #include <linux/clk.h> #include <linux/interrupt.h> #include <linux/io.h> #include <linux/module.h> #include <linux/of.h> #include <linux/platform_device.h> #include <linux/rtc.h> /* Miscellaneous registers */ /* Interrupt Location Register */ #define HW_ILR 0x00 #define BM_RTCALF BIT(1) #define BM_RTCCIF BIT(0) /* Clock Control Register */ #define HW_CCR 0x08 /* Calibration counter disable */ #define BM_CCALOFF BIT(4) /* Reset internal oscillator divider */ #define BM_CTCRST BIT(1) /* Clock Enable */ #define BM_CLKEN BIT(0) /* Counter Increment Interrupt Register */ #define HW_CIIR 0x0C #define BM_CIIR_IMYEAR BIT(7) #define BM_CIIR_IMMON BIT(6) #define BM_CIIR_IMDOY BIT(5) #define BM_CIIR_IMDOW BIT(4) #define BM_CIIR_IMDOM BIT(3) #define BM_CIIR_IMHOUR BIT(2) #define BM_CIIR_IMMIN BIT(1) #define BM_CIIR_IMSEC BIT(0) /* Alarm Mask Register */ #define HW_AMR 0x10 #define BM_AMR_IMYEAR BIT(7) #define BM_AMR_IMMON BIT(6) #define BM_AMR_IMDOY BIT(5) #define BM_AMR_IMDOW BIT(4) #define BM_AMR_IMDOM BIT(3) #define BM_AMR_IMHOUR BIT(2) #define BM_AMR_IMMIN BIT(1) #define BM_AMR_IMSEC BIT(0) #define BM_AMR_OFF 0xff /* Consolidated time registers */ #define HW_CTIME0 0x14 #define BM_CTIME0_DOW_S 24 #define BM_CTIME0_DOW_M 0x7 #define BM_CTIME0_HOUR_S 16 #define BM_CTIME0_HOUR_M 0x1f #define BM_CTIME0_MIN_S 8 #define BM_CTIME0_MIN_M 0x3f #define BM_CTIME0_SEC_S 0 #define BM_CTIME0_SEC_M 0x3f #define HW_CTIME1 0x18 #define BM_CTIME1_YEAR_S 16 #define BM_CTIME1_YEAR_M 0xfff #define BM_CTIME1_MON_S 8 #define BM_CTIME1_MON_M 0xf #define BM_CTIME1_DOM_S 0 #define BM_CTIME1_DOM_M 0x1f #define HW_CTIME2 0x1C #define BM_CTIME2_DOY_S 0 #define BM_CTIME2_DOY_M 0xfff /* Time counter registers */ #define HW_SEC 0x20 #define HW_MIN 0x24 #define HW_HOUR 0x28 #define HW_DOM 0x2C #define HW_DOW 0x30 #define HW_DOY 0x34 #define HW_MONTH 0x38 #define HW_YEAR 0x3C #define HW_CALIBRATION 0x40 #define BM_CALDIR_BACK BIT(17) #define BM_CALVAL_M 0x1ffff /* General purpose registers */ #define HW_GPREG0 0x44 #define HW_GPREG1 0x48 #define HW_GPREG2 0x4C #define HW_GPREG3 0x50 #define HW_GPREG4 0x54 /* Alarm register group */ #define HW_ALSEC 0x60 #define HW_ALMIN 0x64 #define HW_ALHOUR 0x68 #define HW_ALDOM 0x6C #define HW_ALDOW 0x70 #define HW_ALDOY 0x74 #define HW_ALMON 0x78 #define HW_ALYEAR 0x7C struct asm9260_rtc_priv { struct device *dev; void __iomem *iobase; struct rtc_device *rtc; struct clk *clk; }; static irqreturn_t asm9260_rtc_irq(int irq, void *dev_id) { struct asm9260_rtc_priv *priv = dev_id; u32 isr; unsigned long events = 0; mutex_lock(&priv->rtc->ops_lock); isr = ioread32(priv->iobase + HW_CIIR); if (!isr) { mutex_unlock(&priv->rtc->ops_lock); return IRQ_NONE; } iowrite32(0, priv->iobase + HW_CIIR); mutex_unlock(&priv->rtc->ops_lock); events |= RTC_AF | RTC_IRQF; rtc_update_irq(priv->rtc, 1, events); return IRQ_HANDLED; } static int asm9260_rtc_read_time(struct device *dev, struct rtc_time *tm) { struct asm9260_rtc_priv *priv = dev_get_drvdata(dev); u32 ctime0, ctime1, ctime2; ctime0 = ioread32(priv->iobase + HW_CTIME0); ctime1 = ioread32(priv->iobase + HW_CTIME1); ctime2 = ioread32(priv->iobase + HW_CTIME2); if (ctime1 != ioread32(priv->iobase + HW_CTIME1)) { /* * woops, counter flipped right now. Now we are safe * to reread. */ ctime0 = ioread32(priv->iobase + HW_CTIME0); ctime1 = ioread32(priv->iobase + HW_CTIME1); ctime2 = ioread32(priv->iobase + HW_CTIME2); } tm->tm_sec = (ctime0 >> BM_CTIME0_SEC_S) & BM_CTIME0_SEC_M; tm->tm_min = (ctime0 >> BM_CTIME0_MIN_S) & BM_CTIME0_MIN_M; tm->tm_hour = (ctime0 >> BM_CTIME0_HOUR_S) & BM_CTIME0_HOUR_M; tm->tm_wday = (ctime0 >> BM_CTIME0_DOW_S) & BM_CTIME0_DOW_M; tm->tm_mday = (ctime1 >> BM_CTIME1_DOM_S) & BM_CTIME1_DOM_M; tm->tm_mon = (ctime1 >> BM_CTIME1_MON_S) & BM_CTIME1_MON_M; tm->tm_year = (ctime1 >> BM_CTIME1_YEAR_S) & BM_CTIME1_YEAR_M; tm->tm_yday = (ctime2 >> BM_CTIME2_DOY_S) & BM_CTIME2_DOY_M; return 0; } static int asm9260_rtc_set_time(struct device *dev, struct rtc_time *tm) { struct asm9260_rtc_priv *priv = dev_get_drvdata(dev); /* * make sure SEC counter will not flip other counter on write time, * real value will be written at the enf of sequence. */ iowrite32(0, priv->iobase + HW_SEC); iowrite32(tm->tm_year, priv->iobase + HW_YEAR); iowrite32(tm->tm_mon, priv->iobase + HW_MONTH); iowrite32(tm->tm_mday, priv->iobase + HW_DOM); iowrite32(tm->tm_wday, priv->iobase + HW_DOW); iowrite32(tm->tm_yday, priv->iobase + HW_DOY); iowrite32(tm->tm_hour, priv->iobase + HW_HOUR); iowrite32(tm->tm_min, priv->iobase + HW_MIN); iowrite32(tm->tm_sec, priv->iobase + HW_SEC); return 0; } static int asm9260_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) { struct asm9260_rtc_priv *priv = dev_get_drvdata(dev); alrm->time.tm_year = ioread32(priv->iobase + HW_ALYEAR); alrm->time.tm_mon = ioread32(priv->iobase + HW_ALMON); alrm->time.tm_mday = ioread32(priv->iobase + HW_ALDOM); alrm->time.tm_wday = ioread32(priv->iobase + HW_ALDOW); alrm->time.tm_yday = ioread32(priv->iobase + HW_ALDOY); alrm->time.tm_hour = ioread32(priv->iobase + HW_ALHOUR); alrm->time.tm_min = ioread32(priv->iobase + HW_ALMIN); alrm->time.tm_sec = ioread32(priv->iobase + HW_ALSEC); alrm->enabled = ioread32(priv->iobase + HW_AMR) ? 1 : 0; alrm->pending = ioread32(priv->iobase + HW_CIIR) ? 1 : 0; return rtc_valid_tm(&alrm->time); } static int asm9260_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) { struct asm9260_rtc_priv *priv = dev_get_drvdata(dev); iowrite32(alrm->time.tm_year, priv->iobase + HW_ALYEAR); iowrite32(alrm->time.tm_mon, priv->iobase + HW_ALMON); iowrite32(alrm->time.tm_mday, priv->iobase + HW_ALDOM); iowrite32(alrm->time.tm_wday, priv->iobase + HW_ALDOW); iowrite32(alrm->time.tm_yday, priv->iobase + HW_ALDOY); iowrite32(alrm->time.tm_hour, priv->iobase + HW_ALHOUR); iowrite32(alrm->time.tm_min, priv->iobase + HW_ALMIN); iowrite32(alrm->time.tm_sec, priv->iobase + HW_ALSEC); iowrite32(alrm->enabled ? 0 : BM_AMR_OFF, priv->iobase + HW_AMR); return 0; } static int asm9260_alarm_irq_enable(struct device *dev, unsigned int enabled) { struct asm9260_rtc_priv *priv = dev_get_drvdata(dev); iowrite32(enabled ? 0 : BM_AMR_OFF, priv->iobase + HW_AMR); return 0; } static const struct rtc_class_ops asm9260_rtc_ops = { .read_time = asm9260_rtc_read_time, .set_time = asm9260_rtc_set_time, .read_alarm = asm9260_rtc_read_alarm, .set_alarm = asm9260_rtc_set_alarm, .alarm_irq_enable = asm9260_alarm_irq_enable, }; static int asm9260_rtc_probe(struct platform_device *pdev) { struct asm9260_rtc_priv *priv; struct device *dev = &pdev->dev; int irq_alarm, ret; u32 ccr; priv = devm_kzalloc(dev, sizeof(struct asm9260_rtc_priv), GFP_KERNEL); if (!priv) return -ENOMEM; priv->dev = &pdev->dev; platform_set_drvdata(pdev, priv); irq_alarm = platform_get_irq(pdev, 0); if (irq_alarm < 0) return irq_alarm; priv->iobase = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(priv->iobase)) return PTR_ERR(priv->iobase); priv->clk = devm_clk_get(dev, "ahb"); if (IS_ERR(priv->clk)) return PTR_ERR(priv->clk); ret = clk_prepare_enable(priv->clk); if (ret) { dev_err(dev, "Failed to enable clk!\n"); return ret; } ccr = ioread32(priv->iobase + HW_CCR); /* if dev is not enabled, reset it */ if ((ccr & (BM_CLKEN | BM_CTCRST)) != BM_CLKEN) { iowrite32(BM_CTCRST, priv->iobase + HW_CCR); ccr = 0; } iowrite32(BM_CLKEN | ccr, priv->iobase + HW_CCR); iowrite32(0, priv->iobase + HW_CIIR); iowrite32(BM_AMR_OFF, priv->iobase + HW_AMR); priv->rtc = devm_rtc_device_register(dev, dev_name(dev), &asm9260_rtc_ops, THIS_MODULE); if (IS_ERR(priv->rtc)) { ret = PTR_ERR(priv->rtc); dev_err(dev, "Failed to register RTC device: %d\n", ret); goto err_return; } ret = devm_request_threaded_irq(dev, irq_alarm, NULL, asm9260_rtc_irq, IRQF_ONESHOT, dev_name(dev), priv); if (ret < 0) { dev_err(dev, "can't get irq %i, err %d\n", irq_alarm, ret); goto err_return; } return 0; err_return: clk_disable_unprepare(priv->clk); return ret; } static int asm9260_rtc_remove(struct platform_device *pdev) { struct asm9260_rtc_priv *priv = platform_get_drvdata(pdev); /* Disable alarm matching */ iowrite32(BM_AMR_OFF, priv->iobase + HW_AMR); clk_disable_unprepare(priv->clk); return 0; } static const struct of_device_id asm9260_dt_ids[] = { { .compatible = "alphascale,asm9260-rtc", }, {} }; MODULE_DEVICE_TABLE(of, asm9260_dt_ids); static struct platform_driver asm9260_rtc_driver = { .probe = asm9260_rtc_probe, .remove = asm9260_rtc_remove, .driver = { .name = "asm9260-rtc", .of_match_table = asm9260_dt_ids, }, }; module_platform_driver(asm9260_rtc_driver); MODULE_AUTHOR("Oleksij Rempel <linux@rempel-privat.de>"); MODULE_DESCRIPTION("Alphascale asm9260 SoC Realtime Clock Driver (RTC)"); MODULE_LICENSE("GPL");
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
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
You can’t perform that action at this time.