ARM: SAMSUNG: Move s3c64xx dev-ts.c to plat-samsung and rename configuration
[linux-2.6-block.git] / drivers / rtc / rtc-proc.c
CommitLineData
728a2947
AZ
1/*
2 * RTC subsystem, proc interface
3 *
4 * Copyright (C) 2005-06 Tower Technologies
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 *
7 * based on arch/arm/common/rtctime.c
8 *
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.
12*/
13
14#include <linux/module.h>
15#include <linux/rtc.h>
16#include <linux/proc_fs.h>
17#include <linux/seq_file.h>
18
ab6a2d70
DB
19#include "rtc-core.h"
20
21
728a2947
AZ
22static int rtc_proc_show(struct seq_file *seq, void *offset)
23{
24 int err;
ab6a2d70
DB
25 struct rtc_device *rtc = seq->private;
26 const struct rtc_class_ops *ops = rtc->ops;
728a2947
AZ
27 struct rtc_wkalrm alrm;
28 struct rtc_time tm;
29
ab6a2d70 30 err = rtc_read_time(rtc, &tm);
728a2947
AZ
31 if (err == 0) {
32 seq_printf(seq,
33 "rtc_time\t: %02d:%02d:%02d\n"
34 "rtc_date\t: %04d-%02d-%02d\n",
35 tm.tm_hour, tm.tm_min, tm.tm_sec,
36 tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
37 }
38
ab6a2d70 39 err = rtc_read_alarm(rtc, &alrm);
728a2947
AZ
40 if (err == 0) {
41 seq_printf(seq, "alrm_time\t: ");
42 if ((unsigned int)alrm.time.tm_hour <= 24)
43 seq_printf(seq, "%02d:", alrm.time.tm_hour);
44 else
45 seq_printf(seq, "**:");
46 if ((unsigned int)alrm.time.tm_min <= 59)
47 seq_printf(seq, "%02d:", alrm.time.tm_min);
48 else
49 seq_printf(seq, "**:");
50 if ((unsigned int)alrm.time.tm_sec <= 59)
51 seq_printf(seq, "%02d\n", alrm.time.tm_sec);
52 else
53 seq_printf(seq, "**\n");
54
55 seq_printf(seq, "alrm_date\t: ");
56 if ((unsigned int)alrm.time.tm_year <= 200)
57 seq_printf(seq, "%04d-", alrm.time.tm_year + 1900);
58 else
59 seq_printf(seq, "****-");
60 if ((unsigned int)alrm.time.tm_mon <= 11)
61 seq_printf(seq, "%02d-", alrm.time.tm_mon + 1);
62 else
63 seq_printf(seq, "**-");
db621f17 64 if (alrm.time.tm_mday && (unsigned int)alrm.time.tm_mday <= 31)
728a2947
AZ
65 seq_printf(seq, "%02d\n", alrm.time.tm_mday);
66 else
67 seq_printf(seq, "**\n");
a2db8dfc 68 seq_printf(seq, "alarm_IRQ\t: %s\n",
728a2947
AZ
69 alrm.enabled ? "yes" : "no");
70 seq_printf(seq, "alrm_pending\t: %s\n",
71 alrm.pending ? "yes" : "no");
72 }
73
adfb4341
AZ
74 seq_printf(seq, "24hr\t\t: yes\n");
75
728a2947 76 if (ops->proc)
cd966209 77 ops->proc(rtc->dev.parent, seq);
728a2947
AZ
78
79 return 0;
80}
81
82static int rtc_proc_open(struct inode *inode, struct file *file)
83{
ab6a2d70 84 struct rtc_device *rtc = PDE(inode)->data;
728a2947
AZ
85
86 if (!try_module_get(THIS_MODULE))
87 return -ENODEV;
88
ab6a2d70 89 return single_open(file, rtc_proc_show, rtc);
728a2947
AZ
90}
91
92static int rtc_proc_release(struct inode *inode, struct file *file)
93{
94 int res = single_release(inode, file);
95 module_put(THIS_MODULE);
96 return res;
97}
98
d54b1fdb 99static const struct file_operations rtc_proc_fops = {
728a2947
AZ
100 .open = rtc_proc_open,
101 .read = seq_read,
102 .llseek = seq_lseek,
103 .release = rtc_proc_release,
104};
105
7d9f99ec 106void rtc_proc_add_device(struct rtc_device *rtc)
728a2947 107{
99b76233
AD
108 if (rtc->id == 0)
109 proc_create_data("driver/rtc", 0, NULL, &rtc_proc_fops, rtc);
728a2947
AZ
110}
111
7d9f99ec 112void rtc_proc_del_device(struct rtc_device *rtc)
728a2947 113{
7d9f99ec 114 if (rtc->id == 0)
728a2947 115 remove_proc_entry("driver/rtc", NULL);
728a2947 116}