rtc-proc.c 3.6 KB

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