Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * RTC subsystem, proc interface |
| 3 | * |
| 4 | * Copyright (C) 2005-06 Tower Technologies |
| 5 | * Author: Alessandro Zummo <a.zummo@towertech.it> |
| 6 | * |
| 7 | * based on arch/arm/common/rtctime.c |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/rtc.h> |
| 16 | #include <linux/proc_fs.h> |
| 17 | #include <linux/seq_file.h> |
| 18 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 19 | #include "rtc-core.h" |
| 20 | |
Kim, Milo | 92589c9 | 2012-10-04 17:13:45 -0700 | [diff] [blame] | 21 | #define NAME_SIZE 10 |
| 22 | |
| 23 | #if defined(CONFIG_RTC_HCTOSYS_DEVICE) |
| 24 | static bool is_rtc_hctosys(struct rtc_device *rtc) |
| 25 | { |
| 26 | int size; |
| 27 | char name[NAME_SIZE]; |
| 28 | |
| 29 | size = scnprintf(name, NAME_SIZE, "rtc%d", rtc->id); |
| 30 | if (size > NAME_SIZE) |
| 31 | return false; |
| 32 | |
| 33 | return !strncmp(name, CONFIG_RTC_HCTOSYS_DEVICE, NAME_SIZE); |
| 34 | } |
| 35 | #else |
| 36 | static bool is_rtc_hctosys(struct rtc_device *rtc) |
| 37 | { |
| 38 | return (rtc->id == 0); |
| 39 | } |
| 40 | #endif |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 41 | |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 42 | static int rtc_proc_show(struct seq_file *seq, void *offset) |
| 43 | { |
| 44 | int err; |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 45 | struct rtc_device *rtc = seq->private; |
| 46 | const struct rtc_class_ops *ops = rtc->ops; |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 47 | struct rtc_wkalrm alrm; |
| 48 | struct rtc_time tm; |
| 49 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 50 | err = rtc_read_time(rtc, &tm); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 51 | if (err == 0) { |
| 52 | seq_printf(seq, |
Andy Shevchenko | 5548cbf | 2018-12-04 23:23:12 +0200 | [diff] [blame] | 53 | "rtc_time\t: %ptRt\n" |
| 54 | "rtc_date\t: %ptRd\n", |
| 55 | &tm, &tm); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 56 | } |
| 57 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 58 | err = rtc_read_alarm(rtc, &alrm); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 59 | if (err == 0) { |
Andy Shevchenko | 5548cbf | 2018-12-04 23:23:12 +0200 | [diff] [blame] | 60 | seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time); |
| 61 | seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time); |
David Brownell | a2db8df | 2006-12-13 00:35:08 -0800 | [diff] [blame] | 62 | seq_printf(seq, "alarm_IRQ\t: %s\n", |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 63 | alrm.enabled ? "yes" : "no"); |
| 64 | seq_printf(seq, "alrm_pending\t: %s\n", |
| 65 | alrm.pending ? "yes" : "no"); |
Marcelo Roberto Jimenez | bca8521c5 | 2011-02-11 11:50:24 -0200 | [diff] [blame] | 66 | seq_printf(seq, "update IRQ enabled\t: %s\n", |
| 67 | (rtc->uie_rtctimer.enabled) ? "yes" : "no"); |
| 68 | seq_printf(seq, "periodic IRQ enabled\t: %s\n", |
| 69 | (rtc->pie_enabled) ? "yes" : "no"); |
| 70 | seq_printf(seq, "periodic IRQ frequency\t: %d\n", |
| 71 | rtc->irq_freq); |
| 72 | seq_printf(seq, "max user IRQ frequency\t: %d\n", |
| 73 | rtc->max_user_freq); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Alessandro Zummo | adfb434 | 2006-04-10 22:54:43 -0700 | [diff] [blame] | 76 | seq_printf(seq, "24hr\t\t: yes\n"); |
| 77 | |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 78 | if (ops->proc) |
David Brownell | cd96620 | 2007-05-08 00:33:40 -0700 | [diff] [blame] | 79 | ops->proc(rtc->dev.parent, seq); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
David Brownell | 7d9f99e | 2007-05-08 00:33:38 -0700 | [diff] [blame] | 84 | void rtc_proc_add_device(struct rtc_device *rtc) |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 85 | { |
Kim, Milo | 92589c9 | 2012-10-04 17:13:45 -0700 | [diff] [blame] | 86 | if (is_rtc_hctosys(rtc)) |
Christoph Hellwig | 59cacb8 | 2018-04-11 18:22:20 +0200 | [diff] [blame] | 87 | proc_create_single_data("driver/rtc", 0, NULL, rtc_proc_show, |
| 88 | rtc); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 89 | } |
| 90 | |
David Brownell | 7d9f99e | 2007-05-08 00:33:38 -0700 | [diff] [blame] | 91 | void rtc_proc_del_device(struct rtc_device *rtc) |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 92 | { |
Kim, Milo | 92589c9 | 2012-10-04 17:13:45 -0700 | [diff] [blame] | 93 | if (is_rtc_hctosys(rtc)) |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 94 | remove_proc_entry("driver/rtc", NULL); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 95 | } |