blob: 0a59fda5c09d176c5fa0af1f90625c04a29232c4 [file] [log] [blame]
Alessandro Zummo728a2942006-03-27 01:16:40 -08001/*
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
David Brownellab6a2d72007-05-08 00:33:30 -070019#include "rtc-core.h"
20
21
Alessandro Zummo728a2942006-03-27 01:16:40 -080022static int rtc_proc_show(struct seq_file *seq, void *offset)
23{
24 int err;
David Brownellab6a2d72007-05-08 00:33:30 -070025 struct rtc_device *rtc = seq->private;
26 const struct rtc_class_ops *ops = rtc->ops;
Alessandro Zummo728a2942006-03-27 01:16:40 -080027 struct rtc_wkalrm alrm;
28 struct rtc_time tm;
29
David Brownellab6a2d72007-05-08 00:33:30 -070030 err = rtc_read_time(rtc, &tm);
Alessandro Zummo728a2942006-03-27 01:16:40 -080031 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
David Brownellab6a2d72007-05-08 00:33:30 -070039 err = rtc_read_alarm(rtc, &alrm);
Alessandro Zummo728a2942006-03-27 01:16:40 -080040 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, "**-");
David Brownelldb621f12006-09-30 23:28:16 -070064 if (alrm.time.tm_mday && (unsigned int)alrm.time.tm_mday <= 31)
Alessandro Zummo728a2942006-03-27 01:16:40 -080065 seq_printf(seq, "%02d\n", alrm.time.tm_mday);
66 else
67 seq_printf(seq, "**\n");
David Brownella2db8df2006-12-13 00:35:08 -080068 seq_printf(seq, "alarm_IRQ\t: %s\n",
Alessandro Zummo728a2942006-03-27 01:16:40 -080069 alrm.enabled ? "yes" : "no");
70 seq_printf(seq, "alrm_pending\t: %s\n",
71 alrm.pending ? "yes" : "no");
Marcelo Roberto Jimenezbca85212011-02-11 11:50:24 -020072 seq_printf(seq, "update IRQ enabled\t: %s\n",
73 (rtc->uie_rtctimer.enabled) ? "yes" : "no");
74 seq_printf(seq, "periodic IRQ enabled\t: %s\n",
75 (rtc->pie_enabled) ? "yes" : "no");
76 seq_printf(seq, "periodic IRQ frequency\t: %d\n",
77 rtc->irq_freq);
78 seq_printf(seq, "max user IRQ frequency\t: %d\n",
79 rtc->max_user_freq);
Alessandro Zummo728a2942006-03-27 01:16:40 -080080 }
81
Alessandro Zummoadfb4342006-04-10 22:54:43 -070082 seq_printf(seq, "24hr\t\t: yes\n");
83
Alessandro Zummo728a2942006-03-27 01:16:40 -080084 if (ops->proc)
David Brownellcd966202007-05-08 00:33:40 -070085 ops->proc(rtc->dev.parent, seq);
Alessandro Zummo728a2942006-03-27 01:16:40 -080086
87 return 0;
88}
89
90static int rtc_proc_open(struct inode *inode, struct file *file)
91{
Alexander Strakh24a6f5b2011-02-10 15:01:25 -080092 int ret;
David Brownellab6a2d72007-05-08 00:33:30 -070093 struct rtc_device *rtc = PDE(inode)->data;
Alessandro Zummo728a2942006-03-27 01:16:40 -080094
95 if (!try_module_get(THIS_MODULE))
96 return -ENODEV;
97
Alexander Strakh24a6f5b2011-02-10 15:01:25 -080098 ret = single_open(file, rtc_proc_show, rtc);
99 if (ret)
100 module_put(THIS_MODULE);
101 return ret;
Alessandro Zummo728a2942006-03-27 01:16:40 -0800102}
103
104static int rtc_proc_release(struct inode *inode, struct file *file)
105{
106 int res = single_release(inode, file);
107 module_put(THIS_MODULE);
108 return res;
109}
110
Arjan van de Vend54b1fd2007-02-12 00:55:34 -0800111static const struct file_operations rtc_proc_fops = {
Alessandro Zummo728a2942006-03-27 01:16:40 -0800112 .open = rtc_proc_open,
113 .read = seq_read,
114 .llseek = seq_lseek,
115 .release = rtc_proc_release,
116};
117
David Brownell7d9f99e2007-05-08 00:33:38 -0700118void rtc_proc_add_device(struct rtc_device *rtc)
Alessandro Zummo728a2942006-03-27 01:16:40 -0800119{
Alexey Dobriyan99b76232009-03-25 22:48:06 +0300120 if (rtc->id == 0)
121 proc_create_data("driver/rtc", 0, NULL, &rtc_proc_fops, rtc);
Alessandro Zummo728a2942006-03-27 01:16:40 -0800122}
123
David Brownell7d9f99e2007-05-08 00:33:38 -0700124void rtc_proc_del_device(struct rtc_device *rtc)
Alessandro Zummo728a2942006-03-27 01:16:40 -0800125{
David Brownell7d9f99e2007-05-08 00:33:38 -0700126 if (rtc->id == 0)
Alessandro Zummo728a2942006-03-27 01:16:40 -0800127 remove_proc_entry("driver/rtc", NULL);
Alessandro Zummo728a2942006-03-27 01:16:40 -0800128}