^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * RTC subsystem, proc interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2005-06 Tower Technologies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Author: Alessandro Zummo <a.zummo@towertech.it>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * based on arch/arm/common/rtctime.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/rtc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include "rtc-core.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define NAME_SIZE 10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #if defined(CONFIG_RTC_HCTOSYS_DEVICE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static bool is_rtc_hctosys(struct rtc_device *rtc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) int size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) char name[NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) size = snprintf(name, NAME_SIZE, "rtc%d", rtc->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if (size >= NAME_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) return !strncmp(name, CONFIG_RTC_HCTOSYS_DEVICE, NAME_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static bool is_rtc_hctosys(struct rtc_device *rtc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return (rtc->id == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int rtc_proc_show(struct seq_file *seq, void *offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct rtc_device *rtc = seq->private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) const struct rtc_class_ops *ops = rtc->ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct rtc_wkalrm alrm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct rtc_time tm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) err = rtc_read_time(rtc, &tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (err == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) seq_printf(seq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) "rtc_time\t: %ptRt\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) "rtc_date\t: %ptRd\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) &tm, &tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) err = rtc_read_alarm(rtc, &alrm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (err == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) seq_printf(seq, "alarm_IRQ\t: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) alrm.enabled ? "yes" : "no");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) seq_printf(seq, "alrm_pending\t: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) alrm.pending ? "yes" : "no");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) seq_printf(seq, "update IRQ enabled\t: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) (rtc->uie_rtctimer.enabled) ? "yes" : "no");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) seq_printf(seq, "periodic IRQ enabled\t: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) (rtc->pie_enabled) ? "yes" : "no");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) seq_printf(seq, "periodic IRQ frequency\t: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) rtc->irq_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) seq_printf(seq, "max user IRQ frequency\t: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) rtc->max_user_freq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) seq_printf(seq, "24hr\t\t: yes\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (ops->proc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) ops->proc(rtc->dev.parent, seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) void rtc_proc_add_device(struct rtc_device *rtc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (is_rtc_hctosys(rtc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) proc_create_single_data("driver/rtc", 0, NULL, rtc_proc_show,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) rtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) void rtc_proc_del_device(struct rtc_device *rtc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (is_rtc_hctosys(rtc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) remove_proc_entry("driver/rtc", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }