Commit 888a3687 authored by Richard Cochran's avatar Richard Cochran Committed by David S. Miller

ptp: add the pin GET/SETFUNC ioctls to the testptp program.

This patch adds a option to the test program that lists the
programmable pins on a PTP Hardware Clock device, assuming there
are any such pins. A second option lets the user reprogram the
auxiliary function of a single pin.
Signed-off-by: default avatarRichard Cochran <richardcochran@gmail.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6092315d
...@@ -120,6 +120,13 @@ static void usage(char *progname) ...@@ -120,6 +120,13 @@ static void usage(char *progname)
" -i val index for event/trigger\n" " -i val index for event/trigger\n"
" -k val measure the time offset between system and phc clock\n" " -k val measure the time offset between system and phc clock\n"
" for 'val' times (Maximum 25)\n" " for 'val' times (Maximum 25)\n"
" -l list the current pin configuration\n"
" -L pin,val configure pin index 'pin' with function 'val'\n"
" the channel index is taken from the '-i' option\n"
" 'val' specifies the auxiliary function:\n"
" 0 - none\n"
" 1 - external time stamp\n"
" 2 - periodic output\n"
" -p val enable output with a period of 'val' nanoseconds\n" " -p val enable output with a period of 'val' nanoseconds\n"
" -P val enable or disable (val=1|0) the system clock PPS\n" " -P val enable or disable (val=1|0) the system clock PPS\n"
" -s set the ptp clock time from the system time\n" " -s set the ptp clock time from the system time\n"
...@@ -134,6 +141,7 @@ int main(int argc, char *argv[]) ...@@ -134,6 +141,7 @@ int main(int argc, char *argv[])
struct ptp_extts_event event; struct ptp_extts_event event;
struct ptp_extts_request extts_request; struct ptp_extts_request extts_request;
struct ptp_perout_request perout_request; struct ptp_perout_request perout_request;
struct ptp_pin_desc desc;
struct timespec ts; struct timespec ts;
struct timex tx; struct timex tx;
...@@ -156,11 +164,13 @@ int main(int argc, char *argv[]) ...@@ -156,11 +164,13 @@ int main(int argc, char *argv[])
int extts = 0; int extts = 0;
int gettime = 0; int gettime = 0;
int index = 0; int index = 0;
int list_pins = 0;
int oneshot = 0; int oneshot = 0;
int pct_offset = 0; int pct_offset = 0;
int n_samples = 0; int n_samples = 0;
int periodic = 0; int periodic = 0;
int perout = -1; int perout = -1;
int pin_index = -1, pin_func;
int pps = -1; int pps = -1;
int settime = 0; int settime = 0;
...@@ -169,7 +179,7 @@ int main(int argc, char *argv[]) ...@@ -169,7 +179,7 @@ int main(int argc, char *argv[])
progname = strrchr(argv[0], '/'); progname = strrchr(argv[0], '/');
progname = progname ? 1+progname : argv[0]; progname = progname ? 1+progname : argv[0];
while (EOF != (c = getopt(argc, argv, "a:A:cd:e:f:ghi:k:p:P:sSt:v"))) { while (EOF != (c = getopt(argc, argv, "a:A:cd:e:f:ghi:k:lL:p:P:sSt:v"))) {
switch (c) { switch (c) {
case 'a': case 'a':
oneshot = atoi(optarg); oneshot = atoi(optarg);
...@@ -199,6 +209,16 @@ int main(int argc, char *argv[]) ...@@ -199,6 +209,16 @@ int main(int argc, char *argv[])
pct_offset = 1; pct_offset = 1;
n_samples = atoi(optarg); n_samples = atoi(optarg);
break; break;
case 'l':
list_pins = 1;
break;
case 'L':
cnt = sscanf(optarg, "%d,%d", &pin_index, &pin_func);
if (cnt != 2) {
usage(progname);
return -1;
}
break;
case 'p': case 'p':
perout = atoi(optarg); perout = atoi(optarg);
break; break;
...@@ -245,12 +265,14 @@ int main(int argc, char *argv[]) ...@@ -245,12 +265,14 @@ int main(int argc, char *argv[])
" %d programmable alarms\n" " %d programmable alarms\n"
" %d external time stamp channels\n" " %d external time stamp channels\n"
" %d programmable periodic signals\n" " %d programmable periodic signals\n"
" %d pulse per second\n", " %d pulse per second\n"
" %d programmable pins\n",
caps.max_adj, caps.max_adj,
caps.n_alarm, caps.n_alarm,
caps.n_ext_ts, caps.n_ext_ts,
caps.n_per_out, caps.n_per_out,
caps.pps); caps.pps,
caps.n_pins);
} }
} }
...@@ -331,6 +353,24 @@ int main(int argc, char *argv[]) ...@@ -331,6 +353,24 @@ int main(int argc, char *argv[])
} }
} }
if (list_pins) {
int n_pins = 0;
if (ioctl(fd, PTP_CLOCK_GETCAPS, &caps)) {
perror("PTP_CLOCK_GETCAPS");
} else {
n_pins = caps.n_pins;
}
for (i = 0; i < n_pins; i++) {
desc.index = i;
if (ioctl(fd, PTP_PIN_GETFUNC, &desc)) {
perror("PTP_PIN_GETFUNC");
break;
}
printf("name %s index %u func %u chan %u\n",
desc.name, desc.index, desc.func, desc.chan);
}
}
if (oneshot) { if (oneshot) {
install_handler(SIGALRM, handle_alarm); install_handler(SIGALRM, handle_alarm);
/* Create a timer. */ /* Create a timer. */
...@@ -392,6 +432,18 @@ int main(int argc, char *argv[]) ...@@ -392,6 +432,18 @@ int main(int argc, char *argv[])
} }
} }
if (pin_index >= 0) {
memset(&desc, 0, sizeof(desc));
desc.index = pin_index;
desc.func = pin_func;
desc.chan = index;
if (ioctl(fd, PTP_PIN_SETFUNC, &desc)) {
perror("PTP_PIN_SETFUNC");
} else {
puts("set pin function okay");
}
}
if (pps != -1) { if (pps != -1) {
int enable = pps ? 1 : 0; int enable = pps ? 1 : 0;
if (ioctl(fd, PTP_ENABLE_PPS, enable)) { if (ioctl(fd, PTP_ENABLE_PPS, enable)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment