sysfs.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * PPS sysfs support
  3. *
  4. *
  5. * Copyright (C) 2007-2009 Rodolfo Giometti <giometti@linux.it>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <linux/device.h>
  22. #include <linux/module.h>
  23. #include <linux/string.h>
  24. #include <linux/pps_kernel.h>
  25. /*
  26. * Attribute functions
  27. */
  28. static ssize_t assert_show(struct device *dev, struct device_attribute *attr,
  29. char *buf)
  30. {
  31. struct pps_device *pps = dev_get_drvdata(dev);
  32. if (!(pps->info.mode & PPS_CAPTUREASSERT))
  33. return 0;
  34. return sprintf(buf, "%lld.%09d#%d\n",
  35. (long long) pps->assert_tu.sec, pps->assert_tu.nsec,
  36. pps->assert_sequence);
  37. }
  38. static DEVICE_ATTR_RO(assert);
  39. static ssize_t clear_show(struct device *dev, struct device_attribute *attr,
  40. char *buf)
  41. {
  42. struct pps_device *pps = dev_get_drvdata(dev);
  43. if (!(pps->info.mode & PPS_CAPTURECLEAR))
  44. return 0;
  45. return sprintf(buf, "%lld.%09d#%d\n",
  46. (long long) pps->clear_tu.sec, pps->clear_tu.nsec,
  47. pps->clear_sequence);
  48. }
  49. static DEVICE_ATTR_RO(clear);
  50. static ssize_t mode_show(struct device *dev, struct device_attribute *attr,
  51. char *buf)
  52. {
  53. struct pps_device *pps = dev_get_drvdata(dev);
  54. return sprintf(buf, "%4x\n", pps->info.mode);
  55. }
  56. static DEVICE_ATTR_RO(mode);
  57. static ssize_t echo_show(struct device *dev, struct device_attribute *attr,
  58. char *buf)
  59. {
  60. struct pps_device *pps = dev_get_drvdata(dev);
  61. return sprintf(buf, "%d\n", !!pps->info.echo);
  62. }
  63. static DEVICE_ATTR_RO(echo);
  64. static ssize_t name_show(struct device *dev, struct device_attribute *attr,
  65. char *buf)
  66. {
  67. struct pps_device *pps = dev_get_drvdata(dev);
  68. return sprintf(buf, "%s\n", pps->info.name);
  69. }
  70. static DEVICE_ATTR_RO(name);
  71. static ssize_t path_show(struct device *dev, struct device_attribute *attr,
  72. char *buf)
  73. {
  74. struct pps_device *pps = dev_get_drvdata(dev);
  75. return sprintf(buf, "%s\n", pps->info.path);
  76. }
  77. static DEVICE_ATTR_RO(path);
  78. static struct attribute *pps_attrs[] = {
  79. &dev_attr_assert.attr,
  80. &dev_attr_clear.attr,
  81. &dev_attr_mode.attr,
  82. &dev_attr_echo.attr,
  83. &dev_attr_name.attr,
  84. &dev_attr_path.attr,
  85. NULL,
  86. };
  87. static const struct attribute_group pps_group = {
  88. .attrs = pps_attrs,
  89. };
  90. const struct attribute_group *pps_groups[] = {
  91. &pps_group,
  92. NULL,
  93. };