Skip to content

Commit 9eb1686

Browse files
jkkmKyle McMartin
authored andcommitted
parisc: add rtc platform driver
Signed-off-by: Kyle McMartin <kyle@mcmartin.ca>
1 parent f0514ae commit 9eb1686

5 files changed

Lines changed: 141 additions & 1 deletion

File tree

‎arch/parisc/Kconfig‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ config PARISC
99
def_bool y
1010
select HAVE_IDE
1111
select HAVE_OPROFILE
12+
select RTC_CLASS
13+
select RTC_DRV_PARISC
1214
help
1315
The PA-RISC microprocessor is designed by Hewlett-Packard and used
1416
in many of their workstations & servers (HP9000 700 and 800 series,

‎arch/parisc/kernel/time.c‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/smp.h>
2424
#include <linux/profile.h>
2525
#include <linux/clocksource.h>
26+
#include <linux/platform_device.h>
2627

2728
#include <asm/uaccess.h>
2829
#include <asm/io.h>
@@ -215,6 +216,24 @@ void __init start_cpu_itimer(void)
215216
cpu_data[cpu].it_value = next_tick;
216217
}
217218

219+
struct platform_device rtc_parisc_dev = {
220+
.name = "rtc-parisc",
221+
.id = -1,
222+
};
223+
224+
static int __init rtc_init(void)
225+
{
226+
int ret;
227+
228+
ret = platform_device_register(&rtc_parisc_dev);
229+
if (ret < 0)
230+
printk(KERN_ERR "unable to register rtc device...\n");
231+
232+
/* not necessarily an error */
233+
return 0;
234+
}
235+
module_init(rtc_init);
236+
218237
void __init time_init(void)
219238
{
220239
static struct pdc_tod tod_data;
@@ -245,4 +264,3 @@ void __init time_init(void)
245264
xtime.tv_nsec = 0;
246265
}
247266
}
248-

‎drivers/rtc/Kconfig‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,14 @@ config RTC_DRV_RS5C313
575575
help
576576
If you say yes here you get support for the Ricoh RS5C313 RTC chips.
577577

578+
config RTC_DRV_PARISC
579+
tristate "PA-RISC firmware RTC support"
580+
depends on PARISC
581+
help
582+
Say Y or M here to enable RTC support on PA-RISC systems using
583+
firmware calls. If you do not know what you are doing, you should
584+
just say Y.
585+
578586
config RTC_DRV_PPC
579587
tristate "PowerPC machine dependent RTC support"
580588
depends on PPC_MERGE

‎drivers/rtc/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o
4545
obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o
4646
obj-$(CONFIG_RTC_DRV_PL030) += rtc-pl030.o
4747
obj-$(CONFIG_RTC_DRV_PL031) += rtc-pl031.o
48+
obj-$(CONFIG_RTC_DRV_PARISC) += rtc-parisc.o
4849
obj-$(CONFIG_RTC_DRV_PPC) += rtc-ppc.o
4950
obj-$(CONFIG_RTC_DRV_R9701) += rtc-r9701.o
5051
obj-$(CONFIG_RTC_DRV_RS5C313) += rtc-rs5c313.o

‎drivers/rtc/rtc-parisc.c‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/* rtc-parisc: RTC for HP PA-RISC firmware
2+
*
3+
* Copyright (C) 2008 Kyle McMartin <kyle@mcmartin.ca>
4+
*/
5+
6+
#include <linux/kernel.h>
7+
#include <linux/module.h>
8+
#include <linux/time.h>
9+
#include <linux/platform_device.h>
10+
11+
#include <asm/rtc.h>
12+
13+
/* as simple as can be, and no simpler. */
14+
struct parisc_rtc {
15+
struct rtc_device *rtc;
16+
spinlock_t lock;
17+
};
18+
19+
static int parisc_get_time(struct device *dev, struct rtc_time *tm)
20+
{
21+
struct parisc_rtc *p = dev_get_drvdata(dev);
22+
unsigned long flags, ret;
23+
24+
spin_lock_irqsave(&p->lock, flags);
25+
ret = get_rtc_time(tm);
26+
spin_unlock_irqrestore(&p->lock, flags);
27+
28+
if (ret & RTC_BATT_BAD)
29+
return -EOPNOTSUPP;
30+
31+
return 0;
32+
}
33+
34+
static int parisc_set_time(struct device *dev, struct rtc_time *tm)
35+
{
36+
struct parisc_rtc *p = dev_get_drvdata(dev);
37+
unsigned long flags, ret;
38+
39+
spin_lock_irqsave(&p->lock, flags);
40+
ret = set_rtc_time(tm);
41+
spin_unlock_irqrestore(&p->lock, flags);
42+
43+
if (ret < 0)
44+
return -EOPNOTSUPP;
45+
46+
return 0;
47+
}
48+
49+
static const struct rtc_class_ops parisc_rtc_ops = {
50+
.read_time = parisc_get_time,
51+
.set_time = parisc_set_time,
52+
};
53+
54+
static int __devinit parisc_rtc_probe(struct platform_device *dev)
55+
{
56+
struct parisc_rtc *p;
57+
58+
p = kzalloc(sizeof (*p), GFP_KERNEL);
59+
if (!p)
60+
return -ENOMEM;
61+
62+
spin_lock_init(&p->lock);
63+
64+
p->rtc = rtc_device_register("rtc-parisc", &dev->dev, &parisc_rtc_ops,
65+
THIS_MODULE);
66+
if (IS_ERR(p->rtc)) {
67+
int err = PTR_ERR(p->rtc);
68+
kfree(p);
69+
return err;
70+
}
71+
72+
platform_set_drvdata(dev, p);
73+
74+
return 0;
75+
}
76+
77+
static int __devexit parisc_rtc_remove(struct platform_device *dev)
78+
{
79+
struct parisc_rtc *p = platform_get_drvdata(dev);
80+
81+
rtc_device_unregister(p->rtc);
82+
kfree(p);
83+
84+
return 0;
85+
}
86+
87+
static struct platform_driver parisc_rtc_driver = {
88+
.driver = {
89+
.name = "rtc-parisc",
90+
.owner = THIS_MODULE,
91+
},
92+
.probe = parisc_rtc_probe,
93+
.remove = __devexit_p(parisc_rtc_remove),
94+
};
95+
96+
static int __init parisc_rtc_init(void)
97+
{
98+
return platform_driver_register(&parisc_rtc_driver);
99+
}
100+
101+
static void __exit parisc_rtc_fini(void)
102+
{
103+
platform_driver_unregister(&parisc_rtc_driver);
104+
}
105+
106+
module_init(parisc_rtc_init);
107+
module_exit(parisc_rtc_fini);
108+
109+
MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>");
110+
MODULE_LICENSE("GPL");
111+
MODULE_DESCRIPTION("HP PA-RISC RTC driver");

0 commit comments

Comments
 (0)