]>
Commit | Line | Data |
---|---|---|
74ba9207 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
eae9d2ba RG |
2 | /* |
3 | * PPS sysfs support | |
4 | * | |
eae9d2ba | 5 | * Copyright (C) 2007-2009 Rodolfo Giometti <[email protected]> |
eae9d2ba RG |
6 | */ |
7 | ||
8 | ||
9 | #include <linux/device.h> | |
10 | #include <linux/module.h> | |
11 | #include <linux/string.h> | |
12 | #include <linux/pps_kernel.h> | |
13 | ||
14 | /* | |
15 | * Attribute functions | |
16 | */ | |
17 | ||
bd0eae4e GKH |
18 | static ssize_t assert_show(struct device *dev, struct device_attribute *attr, |
19 | char *buf) | |
eae9d2ba RG |
20 | { |
21 | struct pps_device *pps = dev_get_drvdata(dev); | |
22 | ||
23 | if (!(pps->info.mode & PPS_CAPTUREASSERT)) | |
24 | return 0; | |
25 | ||
26 | return sprintf(buf, "%lld.%09d#%d\n", | |
27 | (long long) pps->assert_tu.sec, pps->assert_tu.nsec, | |
28 | pps->assert_sequence); | |
29 | } | |
bd0eae4e | 30 | static DEVICE_ATTR_RO(assert); |
eae9d2ba | 31 | |
bd0eae4e GKH |
32 | static ssize_t clear_show(struct device *dev, struct device_attribute *attr, |
33 | char *buf) | |
eae9d2ba RG |
34 | { |
35 | struct pps_device *pps = dev_get_drvdata(dev); | |
36 | ||
37 | if (!(pps->info.mode & PPS_CAPTURECLEAR)) | |
38 | return 0; | |
39 | ||
40 | return sprintf(buf, "%lld.%09d#%d\n", | |
41 | (long long) pps->clear_tu.sec, pps->clear_tu.nsec, | |
42 | pps->clear_sequence); | |
43 | } | |
bd0eae4e | 44 | static DEVICE_ATTR_RO(clear); |
eae9d2ba | 45 | |
bd0eae4e GKH |
46 | static ssize_t mode_show(struct device *dev, struct device_attribute *attr, |
47 | char *buf) | |
eae9d2ba RG |
48 | { |
49 | struct pps_device *pps = dev_get_drvdata(dev); | |
50 | ||
51 | return sprintf(buf, "%4x\n", pps->info.mode); | |
52 | } | |
bd0eae4e | 53 | static DEVICE_ATTR_RO(mode); |
eae9d2ba | 54 | |
bd0eae4e GKH |
55 | static ssize_t echo_show(struct device *dev, struct device_attribute *attr, |
56 | char *buf) | |
eae9d2ba RG |
57 | { |
58 | struct pps_device *pps = dev_get_drvdata(dev); | |
59 | ||
60 | return sprintf(buf, "%d\n", !!pps->info.echo); | |
61 | } | |
bd0eae4e | 62 | static DEVICE_ATTR_RO(echo); |
eae9d2ba | 63 | |
bd0eae4e GKH |
64 | static ssize_t name_show(struct device *dev, struct device_attribute *attr, |
65 | char *buf) | |
eae9d2ba RG |
66 | { |
67 | struct pps_device *pps = dev_get_drvdata(dev); | |
68 | ||
69 | return sprintf(buf, "%s\n", pps->info.name); | |
70 | } | |
bd0eae4e | 71 | static DEVICE_ATTR_RO(name); |
eae9d2ba | 72 | |
bd0eae4e GKH |
73 | static ssize_t path_show(struct device *dev, struct device_attribute *attr, |
74 | char *buf) | |
eae9d2ba RG |
75 | { |
76 | struct pps_device *pps = dev_get_drvdata(dev); | |
77 | ||
78 | return sprintf(buf, "%s\n", pps->info.path); | |
79 | } | |
bd0eae4e GKH |
80 | static DEVICE_ATTR_RO(path); |
81 | ||
82 | static struct attribute *pps_attrs[] = { | |
83 | &dev_attr_assert.attr, | |
84 | &dev_attr_clear.attr, | |
85 | &dev_attr_mode.attr, | |
86 | &dev_attr_echo.attr, | |
87 | &dev_attr_name.attr, | |
88 | &dev_attr_path.attr, | |
89 | NULL, | |
90 | }; | |
91 | ||
92 | static const struct attribute_group pps_group = { | |
93 | .attrs = pps_attrs, | |
94 | }; | |
eae9d2ba | 95 | |
bd0eae4e GKH |
96 | const struct attribute_group *pps_groups[] = { |
97 | &pps_group, | |
98 | NULL, | |
eae9d2ba | 99 | }; |