In anticipation of support for external time stamping in PHC devices, this
patch adds wrapper functions around the pin functionality.

Signed-off-by: Richard Cochran <richardcoch...@gmail.com>
---
 phc.c | 23 +++++++++++++++++++++--
 phc.h | 21 +++++++++++++++++++++
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/phc.c b/phc.c
index a90d13e..14132db 100644
--- a/phc.c
+++ b/phc.c
@@ -16,7 +16,9 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
+#include <errno.h>
 #include <fcntl.h>
+#include <linux/ptp_clock.h>
 #include <stdio.h>
 #include <string.h>
 #include <sys/ioctl.h>
@@ -24,8 +26,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include <linux/ptp_clock.h>
-
 #include "phc.h"
 
 /*
@@ -100,6 +100,25 @@ int phc_max_adj(clockid_t clkid)
        return max;
 }
 
+int phc_number_pins(clockid_t clkid)
+{
+       struct ptp_clock_caps caps;
+
+       if (phc_get_caps(clkid, &caps)) {
+               return 0;
+       }
+       return caps.n_pins;
+}
+
+int phc_pin_setfunc(clockid_t clkid, struct ptp_pin_desc *desc)
+{
+       int err = ioctl(CLOCKID_TO_FD(clkid), PTP_PIN_SETFUNC2, desc);
+       if (err) {
+               fprintf(stderr, PTP_PIN_SETFUNC_FAILED "\n");
+       }
+       return err;
+}
+
 int phc_has_pps(clockid_t clkid)
 {
        struct ptp_clock_caps caps;
diff --git a/phc.h b/phc.h
index c0c5996..4dbc374 100644
--- a/phc.h
+++ b/phc.h
@@ -46,6 +46,27 @@ void phc_close(clockid_t clkid);
  */
 int phc_max_adj(clockid_t clkid);
 
+/**
+ * Queries the number of programmable pins of a PTP hardware clock device.
+ *
+ * @param clkid A clock ID obtained using phc_open().
+ *
+ * @return The number of pins supported by the clock.
+ */
+int phc_number_pins(clockid_t clkid);
+
+/**
+ * Configures a pin of a PTP hardware clock device.
+ *
+ * @param clkid  A clock ID obtained using phc_open().
+ *
+ * @param desc   Pointer to a pin descriptor with the 'index', 'func',
+ *               and 'chan' fields set.
+ *
+ * @return Zero on success, non-zero otherwise.
+ */
+int phc_pin_setfunc(clockid_t clkid, struct ptp_pin_desc *desc);
+
 /**
  * Checks whether the given PTP hardware clock device supports PPS output.
  *
-- 
2.20.1



_______________________________________________
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel

Reply via email to