Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 1 | /* |
| 2 | * PPS sysfs support |
| 3 | * |
| 4 | * |
| 5 | * Copyright (C) 2007-2009 Rodolfo Giometti <giometti@linux.it> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | |
| 23 | #include <linux/device.h> |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/string.h> |
| 26 | #include <linux/pps_kernel.h> |
| 27 | |
| 28 | /* |
| 29 | * Attribute functions |
| 30 | */ |
| 31 | |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 32 | static ssize_t assert_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_CAPTUREASSERT)) |
| 38 | return 0; |
| 39 | |
| 40 | return sprintf(buf, "%lld.%09d#%d\n", |
| 41 | (long long) pps->assert_tu.sec, pps->assert_tu.nsec, |
| 42 | pps->assert_sequence); |
| 43 | } |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 44 | static DEVICE_ATTR_RO(assert); |
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 clear_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 | if (!(pps->info.mode & PPS_CAPTURECLEAR)) |
| 52 | return 0; |
| 53 | |
| 54 | return sprintf(buf, "%lld.%09d#%d\n", |
| 55 | (long long) pps->clear_tu.sec, pps->clear_tu.nsec, |
| 56 | pps->clear_sequence); |
| 57 | } |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 58 | static DEVICE_ATTR_RO(clear); |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 59 | |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 60 | static ssize_t mode_show(struct device *dev, struct device_attribute *attr, |
| 61 | char *buf) |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 62 | { |
| 63 | struct pps_device *pps = dev_get_drvdata(dev); |
| 64 | |
| 65 | return sprintf(buf, "%4x\n", pps->info.mode); |
| 66 | } |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 67 | static DEVICE_ATTR_RO(mode); |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 68 | |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 69 | static ssize_t echo_show(struct device *dev, struct device_attribute *attr, |
| 70 | char *buf) |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 71 | { |
| 72 | struct pps_device *pps = dev_get_drvdata(dev); |
| 73 | |
| 74 | return sprintf(buf, "%d\n", !!pps->info.echo); |
| 75 | } |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 76 | static DEVICE_ATTR_RO(echo); |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 77 | |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 78 | static ssize_t name_show(struct device *dev, struct device_attribute *attr, |
| 79 | char *buf) |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 80 | { |
| 81 | struct pps_device *pps = dev_get_drvdata(dev); |
| 82 | |
| 83 | return sprintf(buf, "%s\n", pps->info.name); |
| 84 | } |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 85 | static DEVICE_ATTR_RO(name); |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 86 | |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 87 | static ssize_t path_show(struct device *dev, struct device_attribute *attr, |
| 88 | char *buf) |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 89 | { |
| 90 | struct pps_device *pps = dev_get_drvdata(dev); |
| 91 | |
| 92 | return sprintf(buf, "%s\n", pps->info.path); |
| 93 | } |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 94 | static DEVICE_ATTR_RO(path); |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 95 | |
Greg Kroah-Hartman | bd0eae4 | 2013-07-24 15:05:19 -0700 | [diff] [blame] | 96 | static struct attribute *pps_attrs[] = { |
| 97 | &dev_attr_assert.attr, |
| 98 | &dev_attr_clear.attr, |
| 99 | &dev_attr_mode.attr, |
| 100 | &dev_attr_echo.attr, |
| 101 | &dev_attr_name.attr, |
| 102 | &dev_attr_path.attr, |
| 103 | NULL, |
| 104 | }; |
| 105 | |
| 106 | static const struct attribute_group pps_group = { |
| 107 | .attrs = pps_attrs, |
| 108 | }; |
| 109 | |
| 110 | const struct attribute_group *pps_groups[] = { |
| 111 | &pps_group, |
| 112 | NULL, |
Rodolfo Giometti | eae9d2b | 2009-06-17 16:28:37 -0700 | [diff] [blame] | 113 | }; |