block: fix bug in ptbl lookup cache
[linux-2.6/mini2440.git] / drivers / rtc / rtc-ep93xx.c
blobf7a3283dd02947962ce5c71d3a221b121231a728
1 /*
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>
15 #include <mach/hardware.h>
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)
22 #define DRV_VERSION "0.2"
24 static int ep93xx_get_swcomp(struct device *dev, unsigned short *preload,
25 unsigned short *delete)
27 unsigned short comp = __raw_readl(EP93XX_RTC_SWCOMP);
29 if (preload)
30 *preload = comp & 0xffff;
32 if (delete)
33 *delete = (comp >> 16) & 0x1f;
35 return 0;
38 static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
40 unsigned long time = __raw_readl(EP93XX_RTC_DATA);
42 rtc_time_to_tm(time, tm);
43 return 0;
46 static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs)
48 __raw_writel(secs + 1, EP93XX_RTC_LOAD);
49 return 0;
52 static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq)
54 unsigned short preload, delete;
56 ep93xx_get_swcomp(dev, &preload, &delete);
58 seq_printf(seq, "preload\t\t: %d\n", preload);
59 seq_printf(seq, "delete\t\t: %d\n", delete);
61 return 0;
64 static const struct rtc_class_ops ep93xx_rtc_ops = {
65 .read_time = ep93xx_rtc_read_time,
66 .set_mmss = ep93xx_rtc_set_mmss,
67 .proc = ep93xx_rtc_proc,
70 static ssize_t ep93xx_sysfs_show_comp_preload(struct device *dev,
71 struct device_attribute *attr, char *buf)
73 unsigned short preload;
75 ep93xx_get_swcomp(dev, &preload, NULL);
77 return sprintf(buf, "%d\n", preload);
79 static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_sysfs_show_comp_preload, NULL);
81 static ssize_t ep93xx_sysfs_show_comp_delete(struct device *dev,
82 struct device_attribute *attr, char *buf)
84 unsigned short delete;
86 ep93xx_get_swcomp(dev, NULL, &delete);
88 return sprintf(buf, "%d\n", delete);
90 static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_sysfs_show_comp_delete, NULL);
93 static int __devinit ep93xx_rtc_probe(struct platform_device *dev)
95 struct rtc_device *rtc = rtc_device_register("ep93xx",
96 &dev->dev, &ep93xx_rtc_ops, THIS_MODULE);
98 if (IS_ERR(rtc)) {
99 return PTR_ERR(rtc);
102 platform_set_drvdata(dev, rtc);
104 device_create_file(&dev->dev, &dev_attr_comp_preload);
105 device_create_file(&dev->dev, &dev_attr_comp_delete);
107 return 0;
110 static int __devexit ep93xx_rtc_remove(struct platform_device *dev)
112 struct rtc_device *rtc = platform_get_drvdata(dev);
114 if (rtc)
115 rtc_device_unregister(rtc);
117 platform_set_drvdata(dev, NULL);
119 return 0;
122 /* work with hotplug and coldplug */
123 MODULE_ALIAS("platform:ep93xx-rtc");
125 static struct platform_driver ep93xx_rtc_platform_driver = {
126 .driver = {
127 .name = "ep93xx-rtc",
128 .owner = THIS_MODULE,
130 .probe = ep93xx_rtc_probe,
131 .remove = __devexit_p(ep93xx_rtc_remove),
134 static int __init ep93xx_rtc_init(void)
136 return platform_driver_register(&ep93xx_rtc_platform_driver);
139 static void __exit ep93xx_rtc_exit(void)
141 platform_driver_unregister(&ep93xx_rtc_platform_driver);
144 MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
145 MODULE_DESCRIPTION("EP93XX RTC driver");
146 MODULE_LICENSE("GPL");
147 MODULE_VERSION(DRV_VERSION);
149 module_init(ep93xx_rtc_init);
150 module_exit(ep93xx_rtc_exit);