blob: f7a3283dd02947962ce5c71d3a221b121231a728 [file] [log] [blame]
Alessandro Zummofd507e22006-03-27 01:16:45 -08001/*
2 * A driver for the RTC embedded in the Cirrus Logic EP93XX processors
3 * Copyright (c) 2006 Tower Technologies
4 *
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/rtc.h>
14#include <linux/platform_device.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010015#include <mach/hardware.h>
Alessandro Zummofd507e22006-03-27 01:16:45 -080016
17#define EP93XX_RTC_REG(x) (EP93XX_RTC_BASE + (x))
18#define EP93XX_RTC_DATA EP93XX_RTC_REG(0x0000)
19#define EP93XX_RTC_LOAD EP93XX_RTC_REG(0x000C)
20#define EP93XX_RTC_SWCOMP EP93XX_RTC_REG(0x0108)
21
22#define DRV_VERSION "0.2"
23
24static int ep93xx_get_swcomp(struct device *dev, unsigned short *preload,
25 unsigned short *delete)
26{
27 unsigned short comp = __raw_readl(EP93XX_RTC_SWCOMP);
28
29 if (preload)
30 *preload = comp & 0xffff;
31
32 if (delete)
33 *delete = (comp >> 16) & 0x1f;
34
35 return 0;
36}
37
38static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
39{
40 unsigned long time = __raw_readl(EP93XX_RTC_DATA);
41
42 rtc_time_to_tm(time, tm);
43 return 0;
44}
45
46static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs)
47{
48 __raw_writel(secs + 1, EP93XX_RTC_LOAD);
49 return 0;
50}
51
Alessandro Zummofd507e22006-03-27 01:16:45 -080052static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq)
53{
54 unsigned short preload, delete;
55
56 ep93xx_get_swcomp(dev, &preload, &delete);
57
Alessandro Zummofd507e22006-03-27 01:16:45 -080058 seq_printf(seq, "preload\t\t: %d\n", preload);
59 seq_printf(seq, "delete\t\t: %d\n", delete);
60
61 return 0;
62}
63
David Brownellff8371a2006-09-30 23:28:17 -070064static const struct rtc_class_ops ep93xx_rtc_ops = {
Alessandro Zummofd507e22006-03-27 01:16:45 -080065 .read_time = ep93xx_rtc_read_time,
Alessandro Zummofd507e22006-03-27 01:16:45 -080066 .set_mmss = ep93xx_rtc_set_mmss,
67 .proc = ep93xx_rtc_proc,
68};
69
70static ssize_t ep93xx_sysfs_show_comp_preload(struct device *dev,
71 struct device_attribute *attr, char *buf)
72{
73 unsigned short preload;
74
75 ep93xx_get_swcomp(dev, &preload, NULL);
76
77 return sprintf(buf, "%d\n", preload);
78}
79static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_sysfs_show_comp_preload, NULL);
80
81static ssize_t ep93xx_sysfs_show_comp_delete(struct device *dev,
82 struct device_attribute *attr, char *buf)
83{
84 unsigned short delete;
85
86 ep93xx_get_swcomp(dev, NULL, &delete);
87
88 return sprintf(buf, "%d\n", delete);
89}
90static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_sysfs_show_comp_delete, NULL);
91
92
93static int __devinit ep93xx_rtc_probe(struct platform_device *dev)
94{
95 struct rtc_device *rtc = rtc_device_register("ep93xx",
96 &dev->dev, &ep93xx_rtc_ops, THIS_MODULE);
97
98 if (IS_ERR(rtc)) {
Alessandro Zummofd507e22006-03-27 01:16:45 -080099 return PTR_ERR(rtc);
100 }
101
102 platform_set_drvdata(dev, rtc);
103
104 device_create_file(&dev->dev, &dev_attr_comp_preload);
105 device_create_file(&dev->dev, &dev_attr_comp_delete);
106
107 return 0;
108}
109
110static int __devexit ep93xx_rtc_remove(struct platform_device *dev)
111{
112 struct rtc_device *rtc = platform_get_drvdata(dev);
113
114 if (rtc)
115 rtc_device_unregister(rtc);
116
117 platform_set_drvdata(dev, NULL);
118
119 return 0;
120}
121
Kay Sieversad28a072008-04-10 21:29:25 -0700122/* work with hotplug and coldplug */
123MODULE_ALIAS("platform:ep93xx-rtc");
124
Alessandro Zummofd507e22006-03-27 01:16:45 -0800125static struct platform_driver ep93xx_rtc_platform_driver = {
126 .driver = {
127 .name = "ep93xx-rtc",
128 .owner = THIS_MODULE,
129 },
130 .probe = ep93xx_rtc_probe,
131 .remove = __devexit_p(ep93xx_rtc_remove),
132};
133
134static int __init ep93xx_rtc_init(void)
135{
136 return platform_driver_register(&ep93xx_rtc_platform_driver);
137}
138
139static void __exit ep93xx_rtc_exit(void)
140{
141 platform_driver_unregister(&ep93xx_rtc_platform_driver);
142}
143
144MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
145MODULE_DESCRIPTION("EP93XX RTC driver");
146MODULE_LICENSE("GPL");
147MODULE_VERSION(DRV_VERSION);
148
149module_init(ep93xx_rtc_init);
150module_exit(ep93xx_rtc_exit);