Blame view

drivers/rtc/rtc-proc.c 3.2 KB
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  /*
   * RTC subsystem, proc interface
   *
   * Copyright (C) 2005-06 Tower Technologies
   * Author: Alessandro Zummo <a.zummo@towertech.it>
   *
   * based on arch/arm/common/rtctime.c
   *
   * This program is free software; you can redistribute it and/or modify
   * it under the terms of the GNU General Public License version 2 as
   * published by the Free Software Foundation.
  */
  
  #include <linux/module.h>
  #include <linux/rtc.h>
  #include <linux/proc_fs.h>
  #include <linux/seq_file.h>
ab6a2d70d   David Brownell   rtc: rtc interfac...
18
  #include "rtc-core.h"
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
19
20
21
  static int rtc_proc_show(struct seq_file *seq, void *offset)
  {
  	int err;
ab6a2d70d   David Brownell   rtc: rtc interfac...
22
23
  	struct rtc_device *rtc = seq->private;
  	const struct rtc_class_ops *ops = rtc->ops;
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
24
25
  	struct rtc_wkalrm alrm;
  	struct rtc_time tm;
ab6a2d70d   David Brownell   rtc: rtc interfac...
26
  	err = rtc_read_time(rtc, &tm);
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
27
28
29
30
31
32
33
34
35
  	if (err == 0) {
  		seq_printf(seq,
  			"rtc_time\t: %02d:%02d:%02d
  "
  			"rtc_date\t: %04d-%02d-%02d
  ",
  			tm.tm_hour, tm.tm_min, tm.tm_sec,
  			tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
  	}
ab6a2d70d   David Brownell   rtc: rtc interfac...
36
  	err = rtc_read_alarm(rtc, &alrm);
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  	if (err == 0) {
  		seq_printf(seq, "alrm_time\t: ");
  		if ((unsigned int)alrm.time.tm_hour <= 24)
  			seq_printf(seq, "%02d:", alrm.time.tm_hour);
  		else
  			seq_printf(seq, "**:");
  		if ((unsigned int)alrm.time.tm_min <= 59)
  			seq_printf(seq, "%02d:", alrm.time.tm_min);
  		else
  			seq_printf(seq, "**:");
  		if ((unsigned int)alrm.time.tm_sec <= 59)
  			seq_printf(seq, "%02d
  ", alrm.time.tm_sec);
  		else
  			seq_printf(seq, "**
  ");
  
  		seq_printf(seq, "alrm_date\t: ");
  		if ((unsigned int)alrm.time.tm_year <= 200)
  			seq_printf(seq, "%04d-", alrm.time.tm_year + 1900);
  		else
  			seq_printf(seq, "****-");
  		if ((unsigned int)alrm.time.tm_mon <= 11)
  			seq_printf(seq, "%02d-", alrm.time.tm_mon + 1);
  		else
  			seq_printf(seq, "**-");
db621f174   David Brownell   [PATCH] RTC class...
63
  		if (alrm.time.tm_mday && (unsigned int)alrm.time.tm_mday <= 31)
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
64
65
66
67
68
  			seq_printf(seq, "%02d
  ", alrm.time.tm_mday);
  		else
  			seq_printf(seq, "**
  ");
a2db8dfce   David Brownell   [PATCH] rtc frame...
69
70
  		seq_printf(seq, "alarm_IRQ\t: %s
  ",
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
71
72
73
74
  				alrm.enabled ? "yes" : "no");
  		seq_printf(seq, "alrm_pending\t: %s
  ",
  				alrm.pending ? "yes" : "no");
bca8521c5   Marcelo Roberto Jimenez   RTC: Include info...
75
76
77
78
79
80
81
82
83
84
85
86
  		seq_printf(seq, "update IRQ enabled\t: %s
  ",
  			(rtc->uie_rtctimer.enabled) ? "yes" : "no");
  		seq_printf(seq, "periodic IRQ enabled\t: %s
  ",
  			(rtc->pie_enabled) ? "yes" : "no");
  		seq_printf(seq, "periodic IRQ frequency\t: %d
  ",
  			rtc->irq_freq);
  		seq_printf(seq, "max user IRQ frequency\t: %d
  ",
  			rtc->max_user_freq);
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
87
  	}
adfb43412   Alessandro Zummo   [PATCH] RTC subsy...
88
89
  	seq_printf(seq, "24hr\t\t: yes
  ");
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
90
  	if (ops->proc)
cd9662094   David Brownell   rtc: remove rest ...
91
  		ops->proc(rtc->dev.parent, seq);
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
92
93
94
95
96
97
  
  	return 0;
  }
  
  static int rtc_proc_open(struct inode *inode, struct file *file)
  {
24a6f5b85   Alexander Strakh   drivers/rtc/rtc-p...
98
  	int ret;
ab6a2d70d   David Brownell   rtc: rtc interfac...
99
  	struct rtc_device *rtc = PDE(inode)->data;
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
100
101
102
  
  	if (!try_module_get(THIS_MODULE))
  		return -ENODEV;
24a6f5b85   Alexander Strakh   drivers/rtc/rtc-p...
103
104
105
106
  	ret = single_open(file, rtc_proc_show, rtc);
  	if (ret)
  		module_put(THIS_MODULE);
  	return ret;
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
107
108
109
110
111
112
113
114
  }
  
  static int rtc_proc_release(struct inode *inode, struct file *file)
  {
  	int res = single_release(inode, file);
  	module_put(THIS_MODULE);
  	return res;
  }
d54b1fdb1   Arjan van de Ven   [PATCH] mark stru...
115
  static const struct file_operations rtc_proc_fops = {
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
116
117
118
119
120
  	.open		= rtc_proc_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= rtc_proc_release,
  };
7d9f99ecc   David Brownell   rtc: simplified /...
121
  void rtc_proc_add_device(struct rtc_device *rtc)
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
122
  {
99b762338   Alexey Dobriyan   proc 2/2: remove ...
123
124
  	if (rtc->id == 0)
  		proc_create_data("driver/rtc", 0, NULL, &rtc_proc_fops, rtc);
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
125
  }
7d9f99ecc   David Brownell   rtc: simplified /...
126
  void rtc_proc_del_device(struct rtc_device *rtc)
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
127
  {
7d9f99ecc   David Brownell   rtc: simplified /...
128
  	if (rtc->id == 0)
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
129
  		remove_proc_entry("driver/rtc", NULL);
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
130
  }