sysfs.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 pps_show_assert(struct device *dev,
  29. struct device_attribute *attr, 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 ssize_t pps_show_clear(struct device *dev,
  39. struct device_attribute *attr, char *buf)
  40. {
  41. struct pps_device *pps = dev_get_drvdata(dev);
  42. if (!(pps->info.mode & PPS_CAPTURECLEAR))
  43. return 0;
  44. return sprintf(buf, "%lld.%09d#%d\n",
  45. (long long) pps->clear_tu.sec, pps->clear_tu.nsec,
  46. pps->clear_sequence);
  47. }
  48. static ssize_t pps_show_mode(struct device *dev,
  49. struct device_attribute *attr, char *buf)
  50. {
  51. struct pps_device *pps = dev_get_drvdata(dev);
  52. return sprintf(buf, "%4x\n", pps->info.mode);
  53. }
  54. static ssize_t pps_show_echo(struct device *dev,
  55. struct device_attribute *attr, char *buf)
  56. {
  57. struct pps_device *pps = dev_get_drvdata(dev);
  58. return sprintf(buf, "%d\n", !!pps->info.echo);
  59. }
  60. static ssize_t pps_show_name(struct device *dev,
  61. struct device_attribute *attr, char *buf)
  62. {
  63. struct pps_device *pps = dev_get_drvdata(dev);
  64. return sprintf(buf, "%s\n", pps->info.name);
  65. }
  66. static ssize_t pps_show_path(struct device *dev,
  67. struct device_attribute *attr, char *buf)
  68. {
  69. struct pps_device *pps = dev_get_drvdata(dev);
  70. return sprintf(buf, "%s\n", pps->info.path);
  71. }
  72. struct device_attribute pps_attrs[] = {
  73. __ATTR(assert, S_IRUGO, pps_show_assert, NULL),
  74. __ATTR(clear, S_IRUGO, pps_show_clear, NULL),
  75. __ATTR(mode, S_IRUGO, pps_show_mode, NULL),
  76. __ATTR(echo, S_IRUGO, pps_show_echo, NULL),
  77. __ATTR(name, S_IRUGO, pps_show_name, NULL),
  78. __ATTR(path, S_IRUGO, pps_show_path, NULL),
  79. __ATTR_NULL,
  80. };