2 * A driver for the RTC embedded in the Cirrus Logic EP93XX processors
3 * Copyright (c) 2006 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
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.
12 #include <linux/module.h>
13 #include <linux/rtc.h>
14 #include <linux/platform_device.h>
17 #define EP93XX_RTC_DATA 0x000
18 #define EP93XX_RTC_MATCH 0x004
19 #define EP93XX_RTC_STATUS 0x008
20 #define EP93XX_RTC_STATUS_INTR (1<<0)
21 #define EP93XX_RTC_LOAD 0x00C
22 #define EP93XX_RTC_CONTROL 0x010
23 #define EP93XX_RTC_CONTROL_MIE (1<<0)
24 #define EP93XX_RTC_SWCOMP 0x108
25 #define EP93XX_RTC_SWCOMP_DEL_MASK 0x001f0000
26 #define EP93XX_RTC_SWCOMP_DEL_SHIFT 16
27 #define EP93XX_RTC_SWCOMP_INT_MASK 0x0000ffff
28 #define EP93XX_RTC_SWCOMP_INT_SHIFT 0
30 #define DRV_VERSION "0.3"
33 * struct device dev.platform_data is used to store our private data
34 * because struct rtc_device does not have a variable to hold it.
37 void __iomem
*mmio_base
;
40 static int ep93xx_rtc_get_swcomp(struct device
*dev
, unsigned short *preload
,
41 unsigned short *delete)
43 struct ep93xx_rtc
*ep93xx_rtc
= dev
->platform_data
;
46 comp
= __raw_readl(ep93xx_rtc
->mmio_base
+ EP93XX_RTC_SWCOMP
);
49 *preload
= (comp
& EP93XX_RTC_SWCOMP_INT_MASK
)
50 >> EP93XX_RTC_SWCOMP_INT_SHIFT
;
53 *delete = (comp
& EP93XX_RTC_SWCOMP_DEL_MASK
)
54 >> EP93XX_RTC_SWCOMP_DEL_SHIFT
;
59 static int ep93xx_rtc_read_time(struct device
*dev
, struct rtc_time
*tm
)
61 struct ep93xx_rtc
*ep93xx_rtc
= dev
->platform_data
;
64 time
= __raw_readl(ep93xx_rtc
->mmio_base
+ EP93XX_RTC_DATA
);
66 rtc_time_to_tm(time
, tm
);
70 static int ep93xx_rtc_set_mmss(struct device
*dev
, unsigned long secs
)
72 struct ep93xx_rtc
*ep93xx_rtc
= dev
->platform_data
;
74 __raw_writel(secs
+ 1, ep93xx_rtc
->mmio_base
+ EP93XX_RTC_LOAD
);
78 static int ep93xx_rtc_proc(struct device
*dev
, struct seq_file
*seq
)
80 unsigned short preload
, delete;
82 ep93xx_rtc_get_swcomp(dev
, &preload
, &delete);
84 seq_printf(seq
, "preload\t\t: %d\n", preload
);
85 seq_printf(seq
, "delete\t\t: %d\n", delete);
90 static const struct rtc_class_ops ep93xx_rtc_ops
= {
91 .read_time
= ep93xx_rtc_read_time
,
92 .set_mmss
= ep93xx_rtc_set_mmss
,
93 .proc
= ep93xx_rtc_proc
,
96 static ssize_t
ep93xx_rtc_show_comp_preload(struct device
*dev
,
97 struct device_attribute
*attr
, char *buf
)
99 unsigned short preload
;
101 ep93xx_rtc_get_swcomp(dev
, &preload
, NULL
);
103 return sprintf(buf
, "%d\n", preload
);
105 static DEVICE_ATTR(comp_preload
, S_IRUGO
, ep93xx_rtc_show_comp_preload
, NULL
);
107 static ssize_t
ep93xx_rtc_show_comp_delete(struct device
*dev
,
108 struct device_attribute
*attr
, char *buf
)
110 unsigned short delete;
112 ep93xx_rtc_get_swcomp(dev
, NULL
, &delete);
114 return sprintf(buf
, "%d\n", delete);
116 static DEVICE_ATTR(comp_delete
, S_IRUGO
, ep93xx_rtc_show_comp_delete
, NULL
);
119 static int __init
ep93xx_rtc_probe(struct platform_device
*pdev
)
121 struct ep93xx_rtc
*ep93xx_rtc
;
122 struct resource
*res
;
123 struct rtc_device
*rtc
;
126 ep93xx_rtc
= kzalloc(sizeof(struct ep93xx_rtc
), GFP_KERNEL
);
127 if (ep93xx_rtc
== NULL
)
130 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
134 res
= request_mem_region(res
->start
, resource_size(res
), pdev
->name
);
138 ep93xx_rtc
->mmio_base
= ioremap(res
->start
, resource_size(res
));
139 if (ep93xx_rtc
->mmio_base
== NULL
) {
144 pdev
->dev
.platform_data
= ep93xx_rtc
;
146 rtc
= rtc_device_register(pdev
->name
,
147 &pdev
->dev
, &ep93xx_rtc_ops
, THIS_MODULE
);
153 platform_set_drvdata(pdev
, rtc
);
155 err
= device_create_file(&pdev
->dev
, &dev_attr_comp_preload
);
158 err
= device_create_file(&pdev
->dev
, &dev_attr_comp_delete
);
160 device_remove_file(&pdev
->dev
, &dev_attr_comp_preload
);
167 if (ep93xx_rtc
->mmio_base
) {
168 iounmap(ep93xx_rtc
->mmio_base
);
169 pdev
->dev
.platform_data
= NULL
;
171 release_mem_region(res
->start
, resource_size(res
));
175 static int __exit
ep93xx_rtc_remove(struct platform_device
*pdev
)
177 struct rtc_device
*rtc
= platform_get_drvdata(pdev
);
178 struct ep93xx_rtc
*ep93xx_rtc
= pdev
->dev
.platform_data
;
179 struct resource
*res
;
182 device_remove_file(&pdev
->dev
, &dev_attr_comp_delete
);
183 device_remove_file(&pdev
->dev
, &dev_attr_comp_preload
);
185 rtc_device_unregister(rtc
);
187 iounmap(ep93xx_rtc
->mmio_base
);
188 pdev
->dev
.platform_data
= NULL
;
190 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
191 release_mem_region(res
->start
, resource_size(res
));
193 platform_set_drvdata(pdev
, NULL
);
198 /* work with hotplug and coldplug */
199 MODULE_ALIAS("platform:ep93xx-rtc");
201 static struct platform_driver ep93xx_rtc_driver
= {
203 .name
= "ep93xx-rtc",
204 .owner
= THIS_MODULE
,
206 .remove
= __exit_p(ep93xx_rtc_remove
),
209 static int __init
ep93xx_rtc_init(void)
211 return platform_driver_probe(&ep93xx_rtc_driver
, ep93xx_rtc_probe
);
214 static void __exit
ep93xx_rtc_exit(void)
216 platform_driver_unregister(&ep93xx_rtc_driver
);
219 MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
220 MODULE_DESCRIPTION("EP93XX RTC driver");
221 MODULE_LICENSE("GPL");
222 MODULE_VERSION(DRV_VERSION
);
224 module_init(ep93xx_rtc_init
);
225 module_exit(ep93xx_rtc_exit
);