blob: 73344598fc1bef235f6341d2bcc5f4da3482e9a9 [file] [log] [blame]
Alexandre Bellonicdf75452019-03-13 23:02:48 +01001// SPDX-License-Identifier: GPL-2.0
Alessandro Zummo728a2942006-03-27 01:16:40 -08002/*
3 * RTC subsystem, proc interface
4 *
5 * Copyright (C) 2005-06 Tower Technologies
6 * Author: Alessandro Zummo <a.zummo@towertech.it>
7 *
8 * based on arch/arm/common/rtctime.c
Alexandre Bellonicdf75452019-03-13 23:02:48 +01009 */
Alessandro Zummo728a2942006-03-27 01:16:40 -080010
11#include <linux/module.h>
12#include <linux/rtc.h>
13#include <linux/proc_fs.h>
14#include <linux/seq_file.h>
15
David Brownellab6a2d72007-05-08 00:33:30 -070016#include "rtc-core.h"
17
Kim, Milo92589c92012-10-04 17:13:45 -070018#define NAME_SIZE 10
19
20#if defined(CONFIG_RTC_HCTOSYS_DEVICE)
21static bool is_rtc_hctosys(struct rtc_device *rtc)
22{
23 int size;
24 char name[NAME_SIZE];
25
26 size = scnprintf(name, NAME_SIZE, "rtc%d", rtc->id);
27 if (size > NAME_SIZE)
28 return false;
29
30 return !strncmp(name, CONFIG_RTC_HCTOSYS_DEVICE, NAME_SIZE);
31}
32#else
33static bool is_rtc_hctosys(struct rtc_device *rtc)
34{
35 return (rtc->id == 0);
36}
37#endif
David Brownellab6a2d72007-05-08 00:33:30 -070038
Alessandro Zummo728a2942006-03-27 01:16:40 -080039static int rtc_proc_show(struct seq_file *seq, void *offset)
40{
41 int err;
David Brownellab6a2d72007-05-08 00:33:30 -070042 struct rtc_device *rtc = seq->private;
43 const struct rtc_class_ops *ops = rtc->ops;
Alessandro Zummo728a2942006-03-27 01:16:40 -080044 struct rtc_wkalrm alrm;
45 struct rtc_time tm;
46
David Brownellab6a2d72007-05-08 00:33:30 -070047 err = rtc_read_time(rtc, &tm);
Alessandro Zummo728a2942006-03-27 01:16:40 -080048 if (err == 0) {
49 seq_printf(seq,
Andy Shevchenko5548cbf2018-12-04 23:23:12 +020050 "rtc_time\t: %ptRt\n"
51 "rtc_date\t: %ptRd\n",
52 &tm, &tm);
Alessandro Zummo728a2942006-03-27 01:16:40 -080053 }
54
David Brownellab6a2d72007-05-08 00:33:30 -070055 err = rtc_read_alarm(rtc, &alrm);
Alessandro Zummo728a2942006-03-27 01:16:40 -080056 if (err == 0) {
Andy Shevchenko5548cbf2018-12-04 23:23:12 +020057 seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time);
58 seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time);
David Brownella2db8df2006-12-13 00:35:08 -080059 seq_printf(seq, "alarm_IRQ\t: %s\n",
Alexandre Belloni606cc432019-03-20 12:59:09 +010060 alrm.enabled ? "yes" : "no");
Alessandro Zummo728a2942006-03-27 01:16:40 -080061 seq_printf(seq, "alrm_pending\t: %s\n",
Alexandre Belloni606cc432019-03-20 12:59:09 +010062 alrm.pending ? "yes" : "no");
Marcelo Roberto Jimenezbca8521c52011-02-11 11:50:24 -020063 seq_printf(seq, "update IRQ enabled\t: %s\n",
Alexandre Belloni606cc432019-03-20 12:59:09 +010064 (rtc->uie_rtctimer.enabled) ? "yes" : "no");
Marcelo Roberto Jimenezbca8521c52011-02-11 11:50:24 -020065 seq_printf(seq, "periodic IRQ enabled\t: %s\n",
Alexandre Belloni606cc432019-03-20 12:59:09 +010066 (rtc->pie_enabled) ? "yes" : "no");
Marcelo Roberto Jimenezbca8521c52011-02-11 11:50:24 -020067 seq_printf(seq, "periodic IRQ frequency\t: %d\n",
Alexandre Belloni606cc432019-03-20 12:59:09 +010068 rtc->irq_freq);
Marcelo Roberto Jimenezbca8521c52011-02-11 11:50:24 -020069 seq_printf(seq, "max user IRQ frequency\t: %d\n",
Alexandre Belloni606cc432019-03-20 12:59:09 +010070 rtc->max_user_freq);
Alessandro Zummo728a2942006-03-27 01:16:40 -080071 }
72
Alessandro Zummoadfb4342006-04-10 22:54:43 -070073 seq_printf(seq, "24hr\t\t: yes\n");
74
Alessandro Zummo728a2942006-03-27 01:16:40 -080075 if (ops->proc)
David Brownellcd966202007-05-08 00:33:40 -070076 ops->proc(rtc->dev.parent, seq);
Alessandro Zummo728a2942006-03-27 01:16:40 -080077
78 return 0;
79}
80
David Brownell7d9f99e2007-05-08 00:33:38 -070081void rtc_proc_add_device(struct rtc_device *rtc)
Alessandro Zummo728a2942006-03-27 01:16:40 -080082{
Kim, Milo92589c92012-10-04 17:13:45 -070083 if (is_rtc_hctosys(rtc))
Christoph Hellwig59cacb82018-04-11 18:22:20 +020084 proc_create_single_data("driver/rtc", 0, NULL, rtc_proc_show,
Alexandre Belloni606cc432019-03-20 12:59:09 +010085 rtc);
Alessandro Zummo728a2942006-03-27 01:16:40 -080086}
87
David Brownell7d9f99e2007-05-08 00:33:38 -070088void rtc_proc_del_device(struct rtc_device *rtc)
Alessandro Zummo728a2942006-03-27 01:16:40 -080089{
Kim, Milo92589c92012-10-04 17:13:45 -070090 if (is_rtc_hctosys(rtc))
Alessandro Zummo728a2942006-03-27 01:16:40 -080091 remove_proc_entry("driver/rtc", NULL);
Alessandro Zummo728a2942006-03-27 01:16:40 -080092}