aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/ptp
diff options
context:
space:
mode:
authorRichard Cochran <richardcochran@gmail.com>2014-03-20 17:21:53 -0400
committerDavid S. Miller <davem@davemloft.net>2014-03-21 14:21:14 -0400
commit888a36871e1924a235ad88198d903382151e4ac5 (patch)
tree1c6807575fc49c8463d53c366bf33c14d77d1ba7 /Documentation/ptp
parent6092315dfdec5185881605d15a0e200d6e90eb66 (diff)
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: Richard Cochran <richardcochran@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'Documentation/ptp')
-rw-r--r--Documentation/ptp/testptp.c58
1 files changed, 55 insertions, 3 deletions
diff --git a/Documentation/ptp/testptp.c b/Documentation/ptp/testptp.c
index 4aba0436da65..e9eaee622032 100644
--- a/Documentation/ptp/testptp.c
+++ b/Documentation/ptp/testptp.c
@@ -120,6 +120,13 @@ static void usage(char *progname)
120 " -i val index for event/trigger\n" 120 " -i val index for event/trigger\n"
121 " -k val measure the time offset between system and phc clock\n" 121 " -k val measure the time offset between system and phc clock\n"
122 " for 'val' times (Maximum 25)\n" 122 " for 'val' times (Maximum 25)\n"
123 " -l list the current pin configuration\n"
124 " -L pin,val configure pin index 'pin' with function 'val'\n"
125 " the channel index is taken from the '-i' option\n"
126 " 'val' specifies the auxiliary function:\n"
127 " 0 - none\n"
128 " 1 - external time stamp\n"
129 " 2 - periodic output\n"
123 " -p val enable output with a period of 'val' nanoseconds\n" 130 " -p val enable output with a period of 'val' nanoseconds\n"
124 " -P val enable or disable (val=1|0) the system clock PPS\n" 131 " -P val enable or disable (val=1|0) the system clock PPS\n"
125 " -s set the ptp clock time from the system time\n" 132 " -s set the ptp clock time from the system time\n"
@@ -134,6 +141,7 @@ int main(int argc, char *argv[])
134 struct ptp_extts_event event; 141 struct ptp_extts_event event;
135 struct ptp_extts_request extts_request; 142 struct ptp_extts_request extts_request;
136 struct ptp_perout_request perout_request; 143 struct ptp_perout_request perout_request;
144 struct ptp_pin_desc desc;
137 struct timespec ts; 145 struct timespec ts;
138 struct timex tx; 146 struct timex tx;
139 147
@@ -156,11 +164,13 @@ int main(int argc, char *argv[])
156 int extts = 0; 164 int extts = 0;
157 int gettime = 0; 165 int gettime = 0;
158 int index = 0; 166 int index = 0;
167 int list_pins = 0;
159 int oneshot = 0; 168 int oneshot = 0;
160 int pct_offset = 0; 169 int pct_offset = 0;
161 int n_samples = 0; 170 int n_samples = 0;
162 int periodic = 0; 171 int periodic = 0;
163 int perout = -1; 172 int perout = -1;
173 int pin_index = -1, pin_func;
164 int pps = -1; 174 int pps = -1;
165 int settime = 0; 175 int settime = 0;
166 176
@@ -169,7 +179,7 @@ int main(int argc, char *argv[])
169 179
170 progname = strrchr(argv[0], '/'); 180 progname = strrchr(argv[0], '/');
171 progname = progname ? 1+progname : argv[0]; 181 progname = progname ? 1+progname : argv[0];
172 while (EOF != (c = getopt(argc, argv, "a:A:cd:e:f:ghi:k:p:P:sSt:v"))) { 182 while (EOF != (c = getopt(argc, argv, "a:A:cd:e:f:ghi:k:lL:p:P:sSt:v"))) {
173 switch (c) { 183 switch (c) {
174 case 'a': 184 case 'a':
175 oneshot = atoi(optarg); 185 oneshot = atoi(optarg);
@@ -199,6 +209,16 @@ int main(int argc, char *argv[])
199 pct_offset = 1; 209 pct_offset = 1;
200 n_samples = atoi(optarg); 210 n_samples = atoi(optarg);
201 break; 211 break;
212 case 'l':
213 list_pins = 1;
214 break;
215 case 'L':
216 cnt = sscanf(optarg, "%d,%d", &pin_index, &pin_func);
217 if (cnt != 2) {
218 usage(progname);
219 return -1;
220 }
221 break;
202 case 'p': 222 case 'p':
203 perout = atoi(optarg); 223 perout = atoi(optarg);
204 break; 224 break;
@@ -245,12 +265,14 @@ int main(int argc, char *argv[])
245 " %d programmable alarms\n" 265 " %d programmable alarms\n"
246 " %d external time stamp channels\n" 266 " %d external time stamp channels\n"
247 " %d programmable periodic signals\n" 267 " %d programmable periodic signals\n"
248 " %d pulse per second\n", 268 " %d pulse per second\n"
269 " %d programmable pins\n",
249 caps.max_adj, 270 caps.max_adj,
250 caps.n_alarm, 271 caps.n_alarm,
251 caps.n_ext_ts, 272 caps.n_ext_ts,
252 caps.n_per_out, 273 caps.n_per_out,
253 caps.pps); 274 caps.pps,
275 caps.n_pins);
254 } 276 }
255 } 277 }
256 278
@@ -331,6 +353,24 @@ int main(int argc, char *argv[])
331 } 353 }
332 } 354 }
333 355
356 if (list_pins) {
357 int n_pins = 0;
358 if (ioctl(fd, PTP_CLOCK_GETCAPS, &caps)) {
359 perror("PTP_CLOCK_GETCAPS");
360 } else {
361 n_pins = caps.n_pins;
362 }
363 for (i = 0; i < n_pins; i++) {
364 desc.index = i;
365 if (ioctl(fd, PTP_PIN_GETFUNC, &desc)) {
366 perror("PTP_PIN_GETFUNC");
367 break;
368 }
369 printf("name %s index %u func %u chan %u\n",
370 desc.name, desc.index, desc.func, desc.chan);
371 }
372 }
373
334 if (oneshot) { 374 if (oneshot) {
335 install_handler(SIGALRM, handle_alarm); 375 install_handler(SIGALRM, handle_alarm);
336 /* Create a timer. */ 376 /* Create a timer. */
@@ -392,6 +432,18 @@ int main(int argc, char *argv[])
392 } 432 }
393 } 433 }
394 434
435 if (pin_index >= 0) {
436 memset(&desc, 0, sizeof(desc));
437 desc.index = pin_index;
438 desc.func = pin_func;
439 desc.chan = index;
440 if (ioctl(fd, PTP_PIN_SETFUNC, &desc)) {
441 perror("PTP_PIN_SETFUNC");
442 } else {
443 puts("set pin function okay");
444 }
445 }
446
395 if (pps != -1) { 447 if (pps != -1) {
396 int enable = pps ? 1 : 0; 448 int enable = pps ? 1 : 0;
397 if (ioctl(fd, PTP_ENABLE_PPS, enable)) { 449 if (ioctl(fd, PTP_ENABLE_PPS, enable)) {