Thomas Gleixner | 74ba920 | 2019-05-20 09:19:02 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 2 | /* |
| 3 | * PPS sysfs support |
| 4 | * |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 5 | * Copyright (C) 2007-2009 Rodolfo Giometti <giometti@linux.it> |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 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 | |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 18 | static ssize_t assert_show(struct device *dev, struct device_attribute *attr, |
| 19 | char *buf) |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 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 | } |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 30 | static DEVICE_ATTR_RO(assert); |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 31 | |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 32 | static ssize_t clear_show(struct device *dev, struct device_attribute *attr, |
| 33 | char *buf) |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 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 | } |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 44 | static DEVICE_ATTR_RO(clear); |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 45 | |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 46 | static ssize_t mode_show(struct device *dev, struct device_attribute *attr, |
| 47 | char *buf) |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 48 | { |
| 49 | struct pps_device *pps = dev_get_drvdata(dev); |
| 50 | |
| 51 | return sprintf(buf, "%4x\n", pps->info.mode); |
| 52 | } |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 53 | static DEVICE_ATTR_RO(mode); |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 54 | |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 55 | static ssize_t echo_show(struct device *dev, struct device_attribute *attr, |
| 56 | char *buf) |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 57 | { |
| 58 | struct pps_device *pps = dev_get_drvdata(dev); |
| 59 | |
| 60 | return sprintf(buf, "%d\n", !!pps->info.echo); |
| 61 | } |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 62 | static DEVICE_ATTR_RO(echo); |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 63 | |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 64 | static ssize_t name_show(struct device *dev, struct device_attribute *attr, |
| 65 | char *buf) |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 66 | { |
| 67 | struct pps_device *pps = dev_get_drvdata(dev); |
| 68 | |
| 69 | return sprintf(buf, "%s\n", pps->info.name); |
| 70 | } |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 71 | static DEVICE_ATTR_RO(name); |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 72 | |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 73 | static ssize_t path_show(struct device *dev, struct device_attribute *attr, |
| 74 | char *buf) |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 75 | { |
| 76 | struct pps_device *pps = dev_get_drvdata(dev); |
| 77 | |
| 78 | return sprintf(buf, "%s\n", pps->info.path); |
| 79 | } |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 80 | static DEVICE_ATTR_RO(path); |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 81 | |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 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, |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 99 | }; |