proc.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // SPDX-License-Identifier: GPL-2.0
  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
  9. */
  10. #include <linux/module.h>
  11. #include <linux/rtc.h>
  12. #include <linux/proc_fs.h>
  13. #include <linux/seq_file.h>
  14. #include "rtc-core.h"
  15. #define NAME_SIZE 10
  16. #if defined(CONFIG_RTC_HCTOSYS_DEVICE)
  17. static bool is_rtc_hctosys(struct rtc_device *rtc)
  18. {
  19. int size;
  20. char name[NAME_SIZE];
  21. size = snprintf(name, NAME_SIZE, "rtc%d", rtc->id);
  22. if (size >= NAME_SIZE)
  23. return false;
  24. return !strncmp(name, CONFIG_RTC_HCTOSYS_DEVICE, NAME_SIZE);
  25. }
  26. #else
  27. static bool is_rtc_hctosys(struct rtc_device *rtc)
  28. {
  29. return (rtc->id == 0);
  30. }
  31. #endif
  32. static int rtc_proc_show(struct seq_file *seq, void *offset)
  33. {
  34. int err;
  35. struct rtc_device *rtc = seq->private;
  36. const struct rtc_class_ops *ops = rtc->ops;
  37. struct rtc_wkalrm alrm;
  38. struct rtc_time tm;
  39. err = rtc_read_time(rtc, &tm);
  40. if (err == 0) {
  41. seq_printf(seq,
  42. "rtc_time\t: %ptRt\n"
  43. "rtc_date\t: %ptRd\n",
  44. &tm, &tm);
  45. }
  46. err = rtc_read_alarm(rtc, &alrm);
  47. if (err == 0) {
  48. seq_printf(seq, "alrm_time\t: %ptRt\n", &alrm.time);
  49. seq_printf(seq, "alrm_date\t: %ptRd\n", &alrm.time);
  50. seq_printf(seq, "alarm_IRQ\t: %s\n",
  51. alrm.enabled ? "yes" : "no");
  52. seq_printf(seq, "alrm_pending\t: %s\n",
  53. alrm.pending ? "yes" : "no");
  54. seq_printf(seq, "update IRQ enabled\t: %s\n",
  55. (rtc->uie_rtctimer.enabled) ? "yes" : "no");
  56. seq_printf(seq, "periodic IRQ enabled\t: %s\n",
  57. (rtc->pie_enabled) ? "yes" : "no");
  58. seq_printf(seq, "periodic IRQ frequency\t: %d\n",
  59. rtc->irq_freq);
  60. seq_printf(seq, "max user IRQ frequency\t: %d\n",
  61. rtc->max_user_freq);
  62. }
  63. seq_printf(seq, "24hr\t\t: yes\n");
  64. if (ops->proc)
  65. ops->proc(rtc->dev.parent, seq);
  66. return 0;
  67. }
  68. void rtc_proc_add_device(struct rtc_device *rtc)
  69. {
  70. if (is_rtc_hctosys(rtc))
  71. proc_create_single_data("driver/rtc", 0, NULL, rtc_proc_show,
  72. rtc);
  73. }
  74. void rtc_proc_del_device(struct rtc_device *rtc)
  75. {
  76. if (is_rtc_hctosys(rtc))
  77. remove_proc_entry("driver/rtc", NULL);
  78. }