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, |
| 53 | "rtc_time\t: %02d:%02d:%02d\n" |
| 54 | "rtc_date\t: %04d-%02d-%02d\n", |
| 55 | tm.tm_hour, tm.tm_min, tm.tm_sec, |
| 56 | tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); |
| 57 | } |
| 58 | |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 59 | err = rtc_read_alarm(rtc, &alrm); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 60 | if (err == 0) { |
| 61 | seq_printf(seq, "alrm_time\t: "); |
| 62 | if ((unsigned int)alrm.time.tm_hour <= 24) |
| 63 | seq_printf(seq, "%02d:", alrm.time.tm_hour); |
| 64 | else |
| 65 | seq_printf(seq, "**:"); |
| 66 | if ((unsigned int)alrm.time.tm_min <= 59) |
| 67 | seq_printf(seq, "%02d:", alrm.time.tm_min); |
| 68 | else |
| 69 | seq_printf(seq, "**:"); |
| 70 | if ((unsigned int)alrm.time.tm_sec <= 59) |
| 71 | seq_printf(seq, "%02d\n", alrm.time.tm_sec); |
| 72 | else |
| 73 | seq_printf(seq, "**\n"); |
| 74 | |
| 75 | seq_printf(seq, "alrm_date\t: "); |
| 76 | if ((unsigned int)alrm.time.tm_year <= 200) |
| 77 | seq_printf(seq, "%04d-", alrm.time.tm_year + 1900); |
| 78 | else |
| 79 | seq_printf(seq, "****-"); |
| 80 | if ((unsigned int)alrm.time.tm_mon <= 11) |
| 81 | seq_printf(seq, "%02d-", alrm.time.tm_mon + 1); |
| 82 | else |
| 83 | seq_printf(seq, "**-"); |
David Brownell | db621f1 | 2006-09-30 23:28:16 -0700 | [diff] [blame] | 84 | if (alrm.time.tm_mday && (unsigned int)alrm.time.tm_mday <= 31) |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 85 | seq_printf(seq, "%02d\n", alrm.time.tm_mday); |
| 86 | else |
| 87 | seq_printf(seq, "**\n"); |
David Brownell | a2db8df | 2006-12-13 00:35:08 -0800 | [diff] [blame] | 88 | seq_printf(seq, "alarm_IRQ\t: %s\n", |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 89 | alrm.enabled ? "yes" : "no"); |
| 90 | seq_printf(seq, "alrm_pending\t: %s\n", |
| 91 | alrm.pending ? "yes" : "no"); |
Marcelo Roberto Jimenez | bca8521c5 | 2011-02-11 11:50:24 -0200 | [diff] [blame] | 92 | seq_printf(seq, "update IRQ enabled\t: %s\n", |
| 93 | (rtc->uie_rtctimer.enabled) ? "yes" : "no"); |
| 94 | seq_printf(seq, "periodic IRQ enabled\t: %s\n", |
| 95 | (rtc->pie_enabled) ? "yes" : "no"); |
| 96 | seq_printf(seq, "periodic IRQ frequency\t: %d\n", |
| 97 | rtc->irq_freq); |
| 98 | seq_printf(seq, "max user IRQ frequency\t: %d\n", |
| 99 | rtc->max_user_freq); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 100 | } |
| 101 | |
Alessandro Zummo | adfb434 | 2006-04-10 22:54:43 -0700 | [diff] [blame] | 102 | seq_printf(seq, "24hr\t\t: yes\n"); |
| 103 | |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 104 | if (ops->proc) |
David Brownell | cd96620 | 2007-05-08 00:33:40 -0700 | [diff] [blame] | 105 | ops->proc(rtc->dev.parent, seq); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 106 | |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | static int rtc_proc_open(struct inode *inode, struct file *file) |
| 111 | { |
Alexander Strakh | 24a6f5b | 2011-02-10 15:01:25 -0800 | [diff] [blame] | 112 | int ret; |
David Brownell | ab6a2d7 | 2007-05-08 00:33:30 -0700 | [diff] [blame] | 113 | struct rtc_device *rtc = PDE(inode)->data; |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 114 | |
| 115 | if (!try_module_get(THIS_MODULE)) |
| 116 | return -ENODEV; |
| 117 | |
Alexander Strakh | 24a6f5b | 2011-02-10 15:01:25 -0800 | [diff] [blame] | 118 | ret = single_open(file, rtc_proc_show, rtc); |
| 119 | if (ret) |
| 120 | module_put(THIS_MODULE); |
| 121 | return ret; |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static int rtc_proc_release(struct inode *inode, struct file *file) |
| 125 | { |
| 126 | int res = single_release(inode, file); |
| 127 | module_put(THIS_MODULE); |
| 128 | return res; |
| 129 | } |
| 130 | |
Arjan van de Ven | d54b1fd | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 131 | static const struct file_operations rtc_proc_fops = { |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 132 | .open = rtc_proc_open, |
| 133 | .read = seq_read, |
| 134 | .llseek = seq_lseek, |
| 135 | .release = rtc_proc_release, |
| 136 | }; |
| 137 | |
David Brownell | 7d9f99e | 2007-05-08 00:33:38 -0700 | [diff] [blame] | 138 | void rtc_proc_add_device(struct rtc_device *rtc) |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 139 | { |
Kim, Milo | 92589c9 | 2012-10-04 17:13:45 -0700 | [diff] [blame] | 140 | if (is_rtc_hctosys(rtc)) |
Alexey Dobriyan | 99b7623 | 2009-03-25 22:48:06 +0300 | [diff] [blame] | 141 | proc_create_data("driver/rtc", 0, NULL, &rtc_proc_fops, rtc); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 142 | } |
| 143 | |
David Brownell | 7d9f99e | 2007-05-08 00:33:38 -0700 | [diff] [blame] | 144 | void rtc_proc_del_device(struct rtc_device *rtc) |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 145 | { |
Kim, Milo | 92589c9 | 2012-10-04 17:13:45 -0700 | [diff] [blame] | 146 | if (is_rtc_hctosys(rtc)) |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 147 | remove_proc_entry("driver/rtc", NULL); |
Alessandro Zummo | 728a294 | 2006-03-27 01:16:40 -0800 | [diff] [blame] | 148 | } |