2 * RTC subsystem, proc interface
4 * Copyright (C) 2005-06 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
7 * based on arch/arm/common/rtctime.c
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
14 #include <linux/module.h>
15 #include <linux/rtc.h>
16 #include <linux/proc_fs.h>
17 #include <linux/seq_file.h>
22 static struct class_device *rtc_dev = NULL;
23 static DEFINE_MUTEX(rtc_lock);
25 static int rtc_proc_show(struct seq_file *seq, void *offset)
28 struct rtc_device *rtc = seq->private;
29 const struct rtc_class_ops *ops = rtc->ops;
30 struct rtc_wkalrm alrm;
33 err = rtc_read_time(rtc, &tm);
36 "rtc_time\t: %02d:%02d:%02d\n"
37 "rtc_date\t: %04d-%02d-%02d\n",
38 tm.tm_hour, tm.tm_min, tm.tm_sec,
39 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
42 err = rtc_read_alarm(rtc, &alrm);
44 seq_printf(seq, "alrm_time\t: ");
45 if ((unsigned int)alrm.time.tm_hour <= 24)
46 seq_printf(seq, "%02d:", alrm.time.tm_hour);
48 seq_printf(seq, "**:");
49 if ((unsigned int)alrm.time.tm_min <= 59)
50 seq_printf(seq, "%02d:", alrm.time.tm_min);
52 seq_printf(seq, "**:");
53 if ((unsigned int)alrm.time.tm_sec <= 59)
54 seq_printf(seq, "%02d\n", alrm.time.tm_sec);
56 seq_printf(seq, "**\n");
58 seq_printf(seq, "alrm_date\t: ");
59 if ((unsigned int)alrm.time.tm_year <= 200)
60 seq_printf(seq, "%04d-", alrm.time.tm_year + 1900);
62 seq_printf(seq, "****-");
63 if ((unsigned int)alrm.time.tm_mon <= 11)
64 seq_printf(seq, "%02d-", alrm.time.tm_mon + 1);
66 seq_printf(seq, "**-");
67 if (alrm.time.tm_mday && (unsigned int)alrm.time.tm_mday <= 31)
68 seq_printf(seq, "%02d\n", alrm.time.tm_mday);
70 seq_printf(seq, "**\n");
71 seq_printf(seq, "alarm_IRQ\t: %s\n",
72 alrm.enabled ? "yes" : "no");
73 seq_printf(seq, "alrm_pending\t: %s\n",
74 alrm.pending ? "yes" : "no");
77 seq_printf(seq, "24hr\t\t: yes\n");
80 ops->proc(rtc->class_dev.dev, seq);
85 static int rtc_proc_open(struct inode *inode, struct file *file)
87 struct rtc_device *rtc = PDE(inode)->data;
89 if (!try_module_get(THIS_MODULE))
92 return single_open(file, rtc_proc_show, rtc);
95 static int rtc_proc_release(struct inode *inode, struct file *file)
97 int res = single_release(inode, file);
98 module_put(THIS_MODULE);
102 static const struct file_operations rtc_proc_fops = {
103 .open = rtc_proc_open,
106 .release = rtc_proc_release,
109 static int rtc_proc_add_device(struct class_device *class_dev,
110 struct class_interface *class_intf)
112 mutex_lock(&rtc_lock);
113 if (rtc_dev == NULL) {
114 struct proc_dir_entry *ent;
118 ent = create_proc_entry("driver/rtc", 0, NULL);
120 struct rtc_device *rtc = to_rtc_device(class_dev);
122 ent->proc_fops = &rtc_proc_fops;
123 ent->owner = rtc->owner;
126 dev_dbg(class_dev->dev, "rtc intf: proc\n");
131 mutex_unlock(&rtc_lock);
136 static void rtc_proc_remove_device(struct class_device *class_dev,
137 struct class_interface *class_intf)
139 mutex_lock(&rtc_lock);
140 if (rtc_dev == class_dev) {
141 remove_proc_entry("driver/rtc", NULL);
144 mutex_unlock(&rtc_lock);
147 static struct class_interface rtc_proc_interface = {
148 .add = &rtc_proc_add_device,
149 .remove = &rtc_proc_remove_device,
152 static int __init rtc_proc_init(void)
154 return rtc_interface_register(&rtc_proc_interface);
157 static void __exit rtc_proc_exit(void)
159 class_interface_unregister(&rtc_proc_interface);
162 subsys_initcall(rtc_proc_init);
163 module_exit(rtc_proc_exit);
165 MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
166 MODULE_DESCRIPTION("RTC class proc interface");
167 MODULE_LICENSE("GPL");