Alexandre Belloni | cdf7545 | 2019-03-13 23:02:48 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 2 | /* |
| 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 Belloni | cdf7545 | 2019-03-13 23:02:48 +0100 | [diff] [blame] | 9 | */ |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 10 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/rtc.h> |
| 13 | #include <linux/proc_fs.h> |
| 14 | #include <linux/seq_file.h> |
| 15 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 16 | #include "rtc-core.h" |
| 17 | |
Kim, Milo | 92589c9 | 2012-10-04 17:13:45 -0700 | [diff] [blame] | 18 | #define NAME_SIZE 10 |
| 19 | |
| 20 | #if defined(CONFIG_RTC_HCTOSYS_DEVICE) |
| 21 | static 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 |
| 33 | static bool is_rtc_hctosys(struct rtc_device *rtc) |
| 34 | { |
| 35 | return (rtc->id == 0); |
| 36 | } |
| 37 | #endif |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 38 | |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 39 | static int rtc_proc_show(struct seq_file *seq, void *offset) |
| 40 | { |
| 41 | int err; |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 42 | struct rtc_device *rtc = seq->private; |
| 43 | const struct rtc_class_ops *ops = rtc->ops; |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 44 | struct rtc_wkalrm alrm; |
| 45 | struct rtc_time tm; |
| 46 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 47 | err = rtc_read_time(rtc, &tm); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 48 | if (err == 0) { |
| 49 | seq_printf(seq, |
Andy Shevchenko | 5548cbf | 2018-12-04 23:23:12 +0200 | [diff] [blame] | 50 | "rtc_time\t: %ptRt\n" |
| 51 | "rtc_date\t: %ptRd\n", |
| 52 | &tm, &tm); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 53 | } |
| 54 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 55 | err = rtc_read_alarm(rtc, &alrm); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 56 | if (err == 0) { |
Andy Shevchenko | 5548cbf | 2018-12-04 23:23:12 +0200 | [diff] [blame] | 57 | seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time); |
| 58 | seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time); |
David Brownell | a2db8df | 2006-12-13 00:35:08 -0800 | [diff] [blame] | 59 | seq_printf(seq, "alarm_IRQ\t: %s\n", |
Alexandre Belloni | 606cc43 | 2019-03-20 12:59:09 +0100 | [diff] [blame] | 60 | alrm.enabled ? "yes" : "no"); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 61 | seq_printf(seq, "alrm_pending\t: %s\n", |
Alexandre Belloni | 606cc43 | 2019-03-20 12:59:09 +0100 | [diff] [blame] | 62 | alrm.pending ? "yes" : "no"); |
Marcelo Roberto Jimenez | bca8521c5 | 2011-02-11 11:50:24 -0200 | [diff] [blame] | 63 | seq_printf(seq, "update IRQ enabled\t: %s\n", |
Alexandre Belloni | 606cc43 | 2019-03-20 12:59:09 +0100 | [diff] [blame] | 64 | (rtc->uie_rtctimer.enabled) ? "yes" : "no"); |
Marcelo Roberto Jimenez | bca8521c5 | 2011-02-11 11:50:24 -0200 | [diff] [blame] | 65 | seq_printf(seq, "periodic IRQ enabled\t: %s\n", |
Alexandre Belloni | 606cc43 | 2019-03-20 12:59:09 +0100 | [diff] [blame] | 66 | (rtc->pie_enabled) ? "yes" : "no"); |
Marcelo Roberto Jimenez | bca8521c5 | 2011-02-11 11:50:24 -0200 | [diff] [blame] | 67 | seq_printf(seq, "periodic IRQ frequency\t: %d\n", |
Alexandre Belloni | 606cc43 | 2019-03-20 12:59:09 +0100 | [diff] [blame] | 68 | rtc->irq_freq); |
Marcelo Roberto Jimenez | bca8521c5 | 2011-02-11 11:50:24 -0200 | [diff] [blame] | 69 | seq_printf(seq, "max user IRQ frequency\t: %d\n", |
Alexandre Belloni | 606cc43 | 2019-03-20 12:59:09 +0100 | [diff] [blame] | 70 | rtc->max_user_freq); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Alessandro Zummo | adfb434 | 2006-04-10 22:54:43 -0700 | [diff] [blame] | 73 | seq_printf(seq, "24hr\t\t: yes\n"); |
| 74 | |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 75 | if (ops->proc) |
David Brownell | cd96620 | 2007-05-08 00:33:40 -0700 | [diff] [blame] | 76 | ops->proc(rtc->dev.parent, seq); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
David Brownell | 7d9f99e | 2007-05-08 00:33:38 -0700 | [diff] [blame] | 81 | void rtc_proc_add_device(struct rtc_device *rtc) |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 82 | { |
Kim, Milo | 92589c9 | 2012-10-04 17:13:45 -0700 | [diff] [blame] | 83 | if (is_rtc_hctosys(rtc)) |
Christoph Hellwig | 59cacb8 | 2018-04-11 18:22:20 +0200 | [diff] [blame] | 84 | proc_create_single_data("driver/rtc", 0, NULL, rtc_proc_show, |
Alexandre Belloni | 606cc43 | 2019-03-20 12:59:09 +0100 | [diff] [blame] | 85 | rtc); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 86 | } |
| 87 | |
David Brownell | 7d9f99e | 2007-05-08 00:33:38 -0700 | [diff] [blame] | 88 | void rtc_proc_del_device(struct rtc_device *rtc) |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 89 | { |
Kim, Milo | 92589c9 | 2012-10-04 17:13:45 -0700 | [diff] [blame] | 90 | if (is_rtc_hctosys(rtc)) |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 91 | remove_proc_entry("driver/rtc", NULL); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 92 | } |