Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * RTC subsystem, proc interface
0004  *
0005  * Copyright (C) 2005-06 Tower Technologies
0006  * Author: Alessandro Zummo <a.zummo@towertech.it>
0007  *
0008  * based on arch/arm/common/rtctime.c
0009  */
0010 
0011 #include <linux/module.h>
0012 #include <linux/rtc.h>
0013 #include <linux/proc_fs.h>
0014 #include <linux/seq_file.h>
0015 
0016 #include "rtc-core.h"
0017 
0018 #define NAME_SIZE   10
0019 
0020 #if defined(CONFIG_RTC_HCTOSYS_DEVICE)
0021 static bool is_rtc_hctosys(struct rtc_device *rtc)
0022 {
0023     int size;
0024     char name[NAME_SIZE];
0025 
0026     size = snprintf(name, NAME_SIZE, "rtc%d", rtc->id);
0027     if (size >= NAME_SIZE)
0028         return false;
0029 
0030     return !strncmp(name, CONFIG_RTC_HCTOSYS_DEVICE, NAME_SIZE);
0031 }
0032 #else
0033 static bool is_rtc_hctosys(struct rtc_device *rtc)
0034 {
0035     return (rtc->id == 0);
0036 }
0037 #endif
0038 
0039 static int rtc_proc_show(struct seq_file *seq, void *offset)
0040 {
0041     int err;
0042     struct rtc_device *rtc = seq->private;
0043     const struct rtc_class_ops *ops = rtc->ops;
0044     struct rtc_wkalrm alrm;
0045     struct rtc_time tm;
0046 
0047     err = rtc_read_time(rtc, &tm);
0048     if (err == 0) {
0049         seq_printf(seq,
0050                "rtc_time\t: %ptRt\n"
0051                "rtc_date\t: %ptRd\n",
0052                &tm, &tm);
0053     }
0054 
0055     err = rtc_read_alarm(rtc, &alrm);
0056     if (err == 0) {
0057         seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time);
0058         seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time);
0059         seq_printf(seq, "alarm_IRQ\t: %s\n",
0060                alrm.enabled ? "yes" : "no");
0061         seq_printf(seq, "alrm_pending\t: %s\n",
0062                alrm.pending ? "yes" : "no");
0063         seq_printf(seq, "update IRQ enabled\t: %s\n",
0064                (rtc->uie_rtctimer.enabled) ? "yes" : "no");
0065         seq_printf(seq, "periodic IRQ enabled\t: %s\n",
0066                (rtc->pie_enabled) ? "yes" : "no");
0067         seq_printf(seq, "periodic IRQ frequency\t: %d\n",
0068                rtc->irq_freq);
0069         seq_printf(seq, "max user IRQ frequency\t: %d\n",
0070                rtc->max_user_freq);
0071     }
0072 
0073     seq_printf(seq, "24hr\t\t: yes\n");
0074 
0075     if (ops->proc)
0076         ops->proc(rtc->dev.parent, seq);
0077 
0078     return 0;
0079 }
0080 
0081 void rtc_proc_add_device(struct rtc_device *rtc)
0082 {
0083     if (is_rtc_hctosys(rtc))
0084         proc_create_single_data("driver/rtc", 0, NULL, rtc_proc_show,
0085                     rtc);
0086 }
0087 
0088 void rtc_proc_del_device(struct rtc_device *rtc)
0089 {
0090     if (is_rtc_hctosys(rtc))
0091         remove_proc_entry("driver/rtc", NULL);
0092 }