rtc-proc.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #include <linux/module.h>
  14. #include <linux/rtc.h>
  15. #include <linux/proc_fs.h>
  16. #include <linux/seq_file.h>
  17. #include "rtc-core.h"
  18. static int rtc_proc_show(struct seq_file *seq, void *offset)
  19. {
  20. int err;
  21. struct rtc_device *rtc = seq->private;
  22. const struct rtc_class_ops *ops = rtc->ops;
  23. struct rtc_wkalrm alrm;
  24. struct rtc_time tm;
  25. err = rtc_read_time(rtc, &tm);
  26. if (err == 0) {
  27. seq_printf(seq,
  28. "rtc_time\t: %02d:%02d:%02d\n"
  29. "rtc_date\t: %04d-%02d-%02d\n",
  30. tm.tm_hour, tm.tm_min, tm.tm_sec,
  31. tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
  32. }
  33. err = rtc_read_alarm(rtc, &alrm);
  34. if (err == 0) {
  35. seq_printf(seq, "alrm_time\t: ");
  36. if ((unsigned int)alrm.time.tm_hour <= 24)
  37. seq_printf(seq, "%02d:", alrm.time.tm_hour);
  38. else
  39. seq_printf(seq, "**:");
  40. if ((unsigned int)alrm.time.tm_min <= 59)
  41. seq_printf(seq, "%02d:", alrm.time.tm_min);
  42. else
  43. seq_printf(seq, "**:");
  44. if ((unsigned int)alrm.time.tm_sec <= 59)
  45. seq_printf(seq, "%02d\n", alrm.time.tm_sec);
  46. else
  47. seq_printf(seq, "**\n");
  48. seq_printf(seq, "alrm_date\t: ");
  49. if ((unsigned int)alrm.time.tm_year <= 200)
  50. seq_printf(seq, "%04d-", alrm.time.tm_year + 1900);
  51. else
  52. seq_printf(seq, "****-");
  53. if ((unsigned int)alrm.time.tm_mon <= 11)
  54. seq_printf(seq, "%02d-", alrm.time.tm_mon + 1);
  55. else
  56. seq_printf(seq, "**-");
  57. if (alrm.time.tm_mday && (unsigned int)alrm.time.tm_mday <= 31)
  58. seq_printf(seq, "%02d\n", alrm.time.tm_mday);
  59. else
  60. seq_printf(seq, "**\n");
  61. seq_printf(seq, "alarm_IRQ\t: %s\n",
  62. alrm.enabled ? "yes" : "no");
  63. seq_printf(seq, "alrm_pending\t: %s\n",
  64. alrm.pending ? "yes" : "no");
  65. seq_printf(seq, "update IRQ enabled\t: %s\n",
  66. (rtc->uie_rtctimer.enabled) ? "yes" : "no");
  67. seq_printf(seq, "periodic IRQ enabled\t: %s\n",
  68. (rtc->pie_enabled) ? "yes" : "no");
  69. seq_printf(seq, "periodic IRQ frequency\t: %d\n",
  70. rtc->irq_freq);
  71. seq_printf(seq, "max user IRQ frequency\t: %d\n",
  72. rtc->max_user_freq);
  73. }
  74. seq_printf(seq, "24hr\t\t: yes\n");
  75. if (ops->proc)
  76. ops->proc(rtc->dev.parent, seq);
  77. return 0;
  78. }
  79. static int rtc_proc_open(struct inode *inode, struct file *file)
  80. {
  81. int ret;
  82. struct rtc_device *rtc = PDE(inode)->data;
  83. if (!try_module_get(THIS_MODULE))
  84. return -ENODEV;
  85. ret = single_open(file, rtc_proc_show, rtc);
  86. if (ret)
  87. module_put(THIS_MODULE);
  88. return ret;
  89. }
  90. static int rtc_proc_release(struct inode *inode, struct file *file)
  91. {
  92. int res = single_release(inode, file);
  93. module_put(THIS_MODULE);
  94. return res;
  95. }
  96. static const struct file_operations rtc_proc_fops = {
  97. .open = rtc_proc_open,
  98. .read = seq_read,
  99. .llseek = seq_lseek,
  100. .release = rtc_proc_release,
  101. };
  102. void rtc_proc_add_device(struct rtc_device *rtc)
  103. {
  104. if (rtc->id == 0)
  105. proc_create_data("driver/rtc", 0, NULL, &rtc_proc_fops, rtc);
  106. }
  107. void rtc_proc_del_device(struct rtc_device *rtc)
  108. {
  109. if (rtc->id == 0)
  110. remove_proc_entry("driver/rtc", NULL);
  111. }