Blame view

drivers/rtc/proc.c 2.09 KB
cdf7545ae   Alexandre Belloni   rtc: convert core...
1
  // SPDX-License-Identifier: GPL-2.0
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
2
3
4
5
6
7
8
  /*
   * RTC subsystem, proc interface
   *
   * Copyright (C) 2005-06 Tower Technologies
   * Author: Alessandro Zummo <a.zummo@towertech.it>
   *
   * based on arch/arm/common/rtctime.c
cdf7545ae   Alexandre Belloni   rtc: convert core...
9
   */
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
10
11
12
13
14
  
  #include <linux/module.h>
  #include <linux/rtc.h>
  #include <linux/proc_fs.h>
  #include <linux/seq_file.h>
ab6a2d70d   David Brownell   rtc: rtc interfac...
15
  #include "rtc-core.h"
92589c986   Kim, Milo   rtc-proc: permit ...
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
  #define NAME_SIZE	10
  
  #if defined(CONFIG_RTC_HCTOSYS_DEVICE)
  static bool is_rtc_hctosys(struct rtc_device *rtc)
  {
  	int size;
  	char name[NAME_SIZE];
  
  	size = scnprintf(name, NAME_SIZE, "rtc%d", rtc->id);
  	if (size > NAME_SIZE)
  		return false;
  
  	return !strncmp(name, CONFIG_RTC_HCTOSYS_DEVICE, NAME_SIZE);
  }
  #else
  static bool is_rtc_hctosys(struct rtc_device *rtc)
  {
  	return (rtc->id == 0);
  }
  #endif
ab6a2d70d   David Brownell   rtc: rtc interfac...
36

728a29478   Alessandro Zummo   [PATCH] RTC subsy...
37
38
39
  static int rtc_proc_show(struct seq_file *seq, void *offset)
  {
  	int err;
ab6a2d70d   David Brownell   rtc: rtc interfac...
40
41
  	struct rtc_device *rtc = seq->private;
  	const struct rtc_class_ops *ops = rtc->ops;
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
42
43
  	struct rtc_wkalrm alrm;
  	struct rtc_time tm;
ab6a2d70d   David Brownell   rtc: rtc interfac...
44
  	err = rtc_read_time(rtc, &tm);
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
45
46
  	if (err == 0) {
  		seq_printf(seq,
5548cbf7f   Andy Shevchenko   rtc: Switch to us...
47
48
49
50
51
  			   "rtc_time\t: %ptRt
  "
  			   "rtc_date\t: %ptRd
  ",
  			   &tm, &tm);
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
52
  	}
ab6a2d70d   David Brownell   rtc: rtc interfac...
53
  	err = rtc_read_alarm(rtc, &alrm);
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
54
  	if (err == 0) {
5548cbf7f   Andy Shevchenko   rtc: Switch to us...
55
56
57
58
  		seq_printf(seq, "alrm_time\t: %ptRt
  ", &alrm.time);
  		seq_printf(seq, "alrm_date\t: %ptRd
  ", &alrm.time);
a2db8dfce   David Brownell   [PATCH] rtc frame...
59
60
  		seq_printf(seq, "alarm_IRQ\t: %s
  ",
606cc43c7   Alexandre Belloni   rtc: core: correc...
61
  			   alrm.enabled ? "yes" : "no");
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
62
63
  		seq_printf(seq, "alrm_pending\t: %s
  ",
606cc43c7   Alexandre Belloni   rtc: core: correc...
64
  			   alrm.pending ? "yes" : "no");
bca8521c5   Marcelo Roberto Jimenez   RTC: Include info...
65
66
  		seq_printf(seq, "update IRQ enabled\t: %s
  ",
606cc43c7   Alexandre Belloni   rtc: core: correc...
67
  			   (rtc->uie_rtctimer.enabled) ? "yes" : "no");
bca8521c5   Marcelo Roberto Jimenez   RTC: Include info...
68
69
  		seq_printf(seq, "periodic IRQ enabled\t: %s
  ",
606cc43c7   Alexandre Belloni   rtc: core: correc...
70
  			   (rtc->pie_enabled) ? "yes" : "no");
bca8521c5   Marcelo Roberto Jimenez   RTC: Include info...
71
72
  		seq_printf(seq, "periodic IRQ frequency\t: %d
  ",
606cc43c7   Alexandre Belloni   rtc: core: correc...
73
  			   rtc->irq_freq);
bca8521c5   Marcelo Roberto Jimenez   RTC: Include info...
74
75
  		seq_printf(seq, "max user IRQ frequency\t: %d
  ",
606cc43c7   Alexandre Belloni   rtc: core: correc...
76
  			   rtc->max_user_freq);
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
77
  	}
adfb43412   Alessandro Zummo   [PATCH] RTC subsy...
78
79
  	seq_printf(seq, "24hr\t\t: yes
  ");
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
80
  	if (ops->proc)
cd9662094   David Brownell   rtc: remove rest ...
81
  		ops->proc(rtc->dev.parent, seq);
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
82
83
84
  
  	return 0;
  }
7d9f99ecc   David Brownell   rtc: simplified /...
85
  void rtc_proc_add_device(struct rtc_device *rtc)
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
86
  {
92589c986   Kim, Milo   rtc-proc: permit ...
87
  	if (is_rtc_hctosys(rtc))
59cacb8dd   Christoph Hellwig   rtc/proc: switch ...
88
  		proc_create_single_data("driver/rtc", 0, NULL, rtc_proc_show,
606cc43c7   Alexandre Belloni   rtc: core: correc...
89
  					rtc);
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
90
  }
7d9f99ecc   David Brownell   rtc: simplified /...
91
  void rtc_proc_del_device(struct rtc_device *rtc)
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
92
  {
92589c986   Kim, Milo   rtc-proc: permit ...
93
  	if (is_rtc_hctosys(rtc))
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
94
  		remove_proc_entry("driver/rtc", NULL);
728a29478   Alessandro Zummo   [PATCH] RTC subsy...
95
  }