0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/device.h>
0010 #include <linux/module.h>
0011 #include <linux/string.h>
0012 #include <linux/pps_kernel.h>
0013
0014
0015
0016
0017
0018 static ssize_t assert_show(struct device *dev, struct device_attribute *attr,
0019 char *buf)
0020 {
0021 struct pps_device *pps = dev_get_drvdata(dev);
0022
0023 if (!(pps->info.mode & PPS_CAPTUREASSERT))
0024 return 0;
0025
0026 return sprintf(buf, "%lld.%09d#%d\n",
0027 (long long) pps->assert_tu.sec, pps->assert_tu.nsec,
0028 pps->assert_sequence);
0029 }
0030 static DEVICE_ATTR_RO(assert);
0031
0032 static ssize_t clear_show(struct device *dev, struct device_attribute *attr,
0033 char *buf)
0034 {
0035 struct pps_device *pps = dev_get_drvdata(dev);
0036
0037 if (!(pps->info.mode & PPS_CAPTURECLEAR))
0038 return 0;
0039
0040 return sprintf(buf, "%lld.%09d#%d\n",
0041 (long long) pps->clear_tu.sec, pps->clear_tu.nsec,
0042 pps->clear_sequence);
0043 }
0044 static DEVICE_ATTR_RO(clear);
0045
0046 static ssize_t mode_show(struct device *dev, struct device_attribute *attr,
0047 char *buf)
0048 {
0049 struct pps_device *pps = dev_get_drvdata(dev);
0050
0051 return sprintf(buf, "%4x\n", pps->info.mode);
0052 }
0053 static DEVICE_ATTR_RO(mode);
0054
0055 static ssize_t echo_show(struct device *dev, struct device_attribute *attr,
0056 char *buf)
0057 {
0058 struct pps_device *pps = dev_get_drvdata(dev);
0059
0060 return sprintf(buf, "%d\n", !!pps->info.echo);
0061 }
0062 static DEVICE_ATTR_RO(echo);
0063
0064 static ssize_t name_show(struct device *dev, struct device_attribute *attr,
0065 char *buf)
0066 {
0067 struct pps_device *pps = dev_get_drvdata(dev);
0068
0069 return sprintf(buf, "%s\n", pps->info.name);
0070 }
0071 static DEVICE_ATTR_RO(name);
0072
0073 static ssize_t path_show(struct device *dev, struct device_attribute *attr,
0074 char *buf)
0075 {
0076 struct pps_device *pps = dev_get_drvdata(dev);
0077
0078 return sprintf(buf, "%s\n", pps->info.path);
0079 }
0080 static DEVICE_ATTR_RO(path);
0081
0082 static struct attribute *pps_attrs[] = {
0083 &dev_attr_assert.attr,
0084 &dev_attr_clear.attr,
0085 &dev_attr_mode.attr,
0086 &dev_attr_echo.attr,
0087 &dev_attr_name.attr,
0088 &dev_attr_path.attr,
0089 NULL,
0090 };
0091
0092 static const struct attribute_group pps_group = {
0093 .attrs = pps_attrs,
0094 };
0095
0096 const struct attribute_group *pps_groups[] = {
0097 &pps_group,
0098 NULL,
0099 };