xref: /linux/drivers/pps/sysfs.c (revision 2da68a77)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * PPS sysfs support
4  *
5  * Copyright (C) 2007-2009   Rodolfo Giometti <giometti@linux.it>
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 
18 static ssize_t assert_show(struct device *dev, struct device_attribute *attr,
19 			   char *buf)
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 }
30 static DEVICE_ATTR_RO(assert);
31 
32 static ssize_t clear_show(struct device *dev, struct device_attribute *attr,
33 			  char *buf)
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 }
44 static DEVICE_ATTR_RO(clear);
45 
46 static ssize_t mode_show(struct device *dev, struct device_attribute *attr,
47 			 char *buf)
48 {
49 	struct pps_device *pps = dev_get_drvdata(dev);
50 
51 	return sprintf(buf, "%4x\n", pps->info.mode);
52 }
53 static DEVICE_ATTR_RO(mode);
54 
55 static ssize_t echo_show(struct device *dev, struct device_attribute *attr,
56 			 char *buf)
57 {
58 	struct pps_device *pps = dev_get_drvdata(dev);
59 
60 	return sprintf(buf, "%d\n", !!pps->info.echo);
61 }
62 static DEVICE_ATTR_RO(echo);
63 
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 
69 	return sprintf(buf, "%s\n", pps->info.name);
70 }
71 static DEVICE_ATTR_RO(name);
72 
73 static ssize_t path_show(struct device *dev, struct device_attribute *attr,
74 			 char *buf)
75 {
76 	struct pps_device *pps = dev_get_drvdata(dev);
77 
78 	return sprintf(buf, "%s\n", pps->info.path);
79 }
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 };
95 
96 const struct attribute_group *pps_groups[] = {
97 	&pps_group,
98 	NULL,
99 };
100