1cdf7545aSAlexandre Belloni // SPDX-License-Identifier: GPL-2.0
236e14f5fSAlexandre Belloni /*
336e14f5fSAlexandre Belloni * RTC subsystem, proc interface
436e14f5fSAlexandre Belloni *
536e14f5fSAlexandre Belloni * Copyright (C) 2005-06 Tower Technologies
636e14f5fSAlexandre Belloni * Author: Alessandro Zummo <[email protected]>
736e14f5fSAlexandre Belloni *
836e14f5fSAlexandre Belloni * based on arch/arm/common/rtctime.c
936e14f5fSAlexandre Belloni */
1036e14f5fSAlexandre Belloni
1136e14f5fSAlexandre Belloni #include <linux/module.h>
1236e14f5fSAlexandre Belloni #include <linux/rtc.h>
1336e14f5fSAlexandre Belloni #include <linux/proc_fs.h>
1436e14f5fSAlexandre Belloni #include <linux/seq_file.h>
1536e14f5fSAlexandre Belloni
1636e14f5fSAlexandre Belloni #include "rtc-core.h"
1736e14f5fSAlexandre Belloni
1836e14f5fSAlexandre Belloni #define NAME_SIZE 10
1936e14f5fSAlexandre Belloni
2036e14f5fSAlexandre Belloni #if defined(CONFIG_RTC_HCTOSYS_DEVICE)
is_rtc_hctosys(struct rtc_device * rtc)2136e14f5fSAlexandre Belloni static bool is_rtc_hctosys(struct rtc_device *rtc)
2236e14f5fSAlexandre Belloni {
2336e14f5fSAlexandre Belloni int size;
2436e14f5fSAlexandre Belloni char name[NAME_SIZE];
2536e14f5fSAlexandre Belloni
26*54b90943SDan Carpenter size = snprintf(name, NAME_SIZE, "rtc%d", rtc->id);
27*54b90943SDan Carpenter if (size >= NAME_SIZE)
2836e14f5fSAlexandre Belloni return false;
2936e14f5fSAlexandre Belloni
3036e14f5fSAlexandre Belloni return !strncmp(name, CONFIG_RTC_HCTOSYS_DEVICE, NAME_SIZE);
3136e14f5fSAlexandre Belloni }
3236e14f5fSAlexandre Belloni #else
is_rtc_hctosys(struct rtc_device * rtc)3336e14f5fSAlexandre Belloni static bool is_rtc_hctosys(struct rtc_device *rtc)
3436e14f5fSAlexandre Belloni {
3536e14f5fSAlexandre Belloni return (rtc->id == 0);
3636e14f5fSAlexandre Belloni }
3736e14f5fSAlexandre Belloni #endif
3836e14f5fSAlexandre Belloni
rtc_proc_show(struct seq_file * seq,void * offset)3936e14f5fSAlexandre Belloni static int rtc_proc_show(struct seq_file *seq, void *offset)
4036e14f5fSAlexandre Belloni {
4136e14f5fSAlexandre Belloni int err;
4236e14f5fSAlexandre Belloni struct rtc_device *rtc = seq->private;
4336e14f5fSAlexandre Belloni const struct rtc_class_ops *ops = rtc->ops;
4436e14f5fSAlexandre Belloni struct rtc_wkalrm alrm;
4536e14f5fSAlexandre Belloni struct rtc_time tm;
4636e14f5fSAlexandre Belloni
4736e14f5fSAlexandre Belloni err = rtc_read_time(rtc, &tm);
4836e14f5fSAlexandre Belloni if (err == 0) {
4936e14f5fSAlexandre Belloni seq_printf(seq,
5036e14f5fSAlexandre Belloni "rtc_time\t: %ptRt\n"
5136e14f5fSAlexandre Belloni "rtc_date\t: %ptRd\n",
5236e14f5fSAlexandre Belloni &tm, &tm);
5336e14f5fSAlexandre Belloni }
5436e14f5fSAlexandre Belloni
5536e14f5fSAlexandre Belloni err = rtc_read_alarm(rtc, &alrm);
5636e14f5fSAlexandre Belloni if (err == 0) {
5736e14f5fSAlexandre Belloni seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time);
5836e14f5fSAlexandre Belloni seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time);
5936e14f5fSAlexandre Belloni seq_printf(seq, "alarm_IRQ\t: %s\n",
6036e14f5fSAlexandre Belloni alrm.enabled ? "yes" : "no");
6136e14f5fSAlexandre Belloni seq_printf(seq, "alrm_pending\t: %s\n",
6236e14f5fSAlexandre Belloni alrm.pending ? "yes" : "no");
6336e14f5fSAlexandre Belloni seq_printf(seq, "update IRQ enabled\t: %s\n",
6436e14f5fSAlexandre Belloni (rtc->uie_rtctimer.enabled) ? "yes" : "no");
6536e14f5fSAlexandre Belloni seq_printf(seq, "periodic IRQ enabled\t: %s\n",
6636e14f5fSAlexandre Belloni (rtc->pie_enabled) ? "yes" : "no");
6736e14f5fSAlexandre Belloni seq_printf(seq, "periodic IRQ frequency\t: %d\n",
6836e14f5fSAlexandre Belloni rtc->irq_freq);
6936e14f5fSAlexandre Belloni seq_printf(seq, "max user IRQ frequency\t: %d\n",
7036e14f5fSAlexandre Belloni rtc->max_user_freq);
7136e14f5fSAlexandre Belloni }
7236e14f5fSAlexandre Belloni
7336e14f5fSAlexandre Belloni seq_printf(seq, "24hr\t\t: yes\n");
7436e14f5fSAlexandre Belloni
7536e14f5fSAlexandre Belloni if (ops->proc)
7636e14f5fSAlexandre Belloni ops->proc(rtc->dev.parent, seq);
7736e14f5fSAlexandre Belloni
7836e14f5fSAlexandre Belloni return 0;
7936e14f5fSAlexandre Belloni }
8036e14f5fSAlexandre Belloni
rtc_proc_add_device(struct rtc_device * rtc)8136e14f5fSAlexandre Belloni void rtc_proc_add_device(struct rtc_device *rtc)
8236e14f5fSAlexandre Belloni {
8336e14f5fSAlexandre Belloni if (is_rtc_hctosys(rtc))
8436e14f5fSAlexandre Belloni proc_create_single_data("driver/rtc", 0, NULL, rtc_proc_show,
8536e14f5fSAlexandre Belloni rtc);
8636e14f5fSAlexandre Belloni }
8736e14f5fSAlexandre Belloni
rtc_proc_del_device(struct rtc_device * rtc)8836e14f5fSAlexandre Belloni void rtc_proc_del_device(struct rtc_device *rtc)
8936e14f5fSAlexandre Belloni {
9036e14f5fSAlexandre Belloni if (is_rtc_hctosys(rtc))
9136e14f5fSAlexandre Belloni remove_proc_entry("driver/rtc", NULL);
9236e14f5fSAlexandre Belloni }
93