Add a new function to phc_ctl to display the devices pin configuration data. First, obtain the device capabilities to determine the number of pins. Then, for each pin, print the name, function, and channel information.
Signed-off-by: Jacob Keller <jacob.e.kel...@intel.com> --- phc_ctl.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/phc_ctl.c b/phc_ctl.c index 5a01e9d69b0f..a619d9203472 100644 --- a/phc_ctl.c +++ b/phc_ctl.c @@ -134,6 +134,7 @@ static void usage(const char *progname) " freq [ppb] adjust PHC frequency (default returns current offset)\n" " cmp compare PHC offset to CLOCK_REALTIME\n" " caps display device capabilities (default if no command given)\n" + " pin_cfg display device pin configuration\n" " wait <seconds> pause between commands\n" "\n", progname); @@ -333,6 +334,77 @@ static int do_caps(clockid_t clkid, int cmdc, char *cmdv[]) return 0; } +static const char *pin_func_string(unsigned int func) +{ + switch (func) { + case PTP_PF_NONE: + return "no function"; + case PTP_PF_EXTTS: + return "external timestamping"; + case PTP_PF_PEROUT: + return "periodic output"; + case PTP_PF_PHYSYNC: + return "phy sync"; + default: + return "unknown function"; + } +} + +static int do_pin_cfg(clockid_t clkid, int cmdc, char *cmdv[]) +{ + struct ptp_clock_caps caps; + struct ptp_pin_desc pin_desc; + unsigned int index; + + if (clkid == CLOCK_REALTIME) { + pr_warning("CLOCK_REALTIME is not a PHC device."); + return 0; + } + + /* Get device capabilities first */ + if (ioctl(CLOCKID_TO_FD(clkid), PTP_CLOCK_GETCAPS, &caps)) { + pr_err("get capabilities failed: %s", + strerror(errno)); + return -1; + } + + if (caps.n_pins == 0) { + pr_notice("device has no configurable pins"); + return (0); + } + + pr_notice("device has %d configurable input/output pins", + caps.n_pins); + + /* For each pin, read its configuration */ + for (index = 0; index < caps.n_pins; index++) { + memset(&pin_desc, 0, sizeof(pin_desc)); + pin_desc.index = index; + + if (ioctl(CLOCKID_TO_FD(clkid), PTP_PIN_GETFUNC, &pin_desc)) { + pr_warning("get pin configuration for pin %d failed: %s", + index, + strerror(errno)); + /* keep going */ + continue; + } + + if (pin_desc.func == PTP_PF_NONE) { + pr_notice("pin %d [%s] is not configured", + pin_desc.index, + pin_desc.name); + } else { + pr_notice("pin %d [%s] performing %s using channel %d", + pin_desc.index, + pin_desc.name, + pin_func_string(pin_desc.func), + pin_desc.chan); + } + } + + return 0; +} + static int do_cmp(clockid_t clkid, int cmdc, char *cmdv[]) { struct timespec ts, rta, rtb; @@ -418,6 +490,7 @@ static const struct cmd_t all_commands[] = { { "freq", &do_freq }, { "cmp", &do_cmp }, { "caps", &do_caps }, + { "pin_cfg", &do_pin_cfg }, { "wait", &do_wait }, { 0, 0 } }; -- 2.23.0.245.gf157bbb9169d _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel