blob: 134bc33f6ad0056e4c4ddc6f56c58d43197535fa [file] [log] [blame]
Thomas Gleixner74ba9202019-05-20 09:19:02 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -07002/*
3 * PPS sysfs support
4 *
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -07005 * Copyright (C) 2007-2009 Rodolfo Giometti <giometti@linux.it>
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -07006 */
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
Greg Kroah-Hartmanbd0eae42013-07-24 15:05:19 -070018static ssize_t assert_show(struct device *dev, struct device_attribute *attr,
19 char *buf)
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -070020{
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}
Greg Kroah-Hartmanbd0eae42013-07-24 15:05:19 -070030static DEVICE_ATTR_RO(assert);
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -070031
Greg Kroah-Hartmanbd0eae42013-07-24 15:05:19 -070032static ssize_t clear_show(struct device *dev, struct device_attribute *attr,
33 char *buf)
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -070034{
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}
Greg Kroah-Hartmanbd0eae42013-07-24 15:05:19 -070044static DEVICE_ATTR_RO(clear);
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -070045
Greg Kroah-Hartmanbd0eae42013-07-24 15:05:19 -070046static ssize_t mode_show(struct device *dev, struct device_attribute *attr,
47 char *buf)
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -070048{
49 struct pps_device *pps = dev_get_drvdata(dev);
50
51 return sprintf(buf, "%4x\n", pps->info.mode);
52}
Greg Kroah-Hartmanbd0eae42013-07-24 15:05:19 -070053static DEVICE_ATTR_RO(mode);
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -070054
Greg Kroah-Hartmanbd0eae42013-07-24 15:05:19 -070055static ssize_t echo_show(struct device *dev, struct device_attribute *attr,
56 char *buf)
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -070057{
58 struct pps_device *pps = dev_get_drvdata(dev);
59
60 return sprintf(buf, "%d\n", !!pps->info.echo);
61}
Greg Kroah-Hartmanbd0eae42013-07-24 15:05:19 -070062static DEVICE_ATTR_RO(echo);
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -070063
Greg Kroah-Hartmanbd0eae42013-07-24 15:05:19 -070064static ssize_t name_show(struct device *dev, struct device_attribute *attr,
65 char *buf)
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -070066{
67 struct pps_device *pps = dev_get_drvdata(dev);
68
69 return sprintf(buf, "%s\n", pps->info.name);
70}
Greg Kroah-Hartmanbd0eae42013-07-24 15:05:19 -070071static DEVICE_ATTR_RO(name);
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -070072
Greg Kroah-Hartmanbd0eae42013-07-24 15:05:19 -070073static ssize_t path_show(struct device *dev, struct device_attribute *attr,
74 char *buf)
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -070075{
76 struct pps_device *pps = dev_get_drvdata(dev);
77
78 return sprintf(buf, "%s\n", pps->info.path);
79}
Greg Kroah-Hartmanbd0eae42013-07-24 15:05:19 -070080static DEVICE_ATTR_RO(path);
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -070081
Greg Kroah-Hartmanbd0eae42013-07-24 15:05:19 -070082static 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
92static const struct attribute_group pps_group = {
93 .attrs = pps_attrs,
94};
95
96const struct attribute_group *pps_groups[] = {
97 &pps_group,
98 NULL,
Rodolfo Giomettieae9d2b2009-06-17 16:28:37 -070099};