Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Richard Cochran and committed by
David S. Miller
888a3687 6092315d

+55 -3
+55 -3
Documentation/ptp/testptp.c
··· 120 120 " -i val index for event/trigger\n" 121 121 " -k val measure the time offset between system and phc clock\n" 122 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 130 " -p val enable output with a period of 'val' nanoseconds\n" 124 131 " -P val enable or disable (val=1|0) the system clock PPS\n" 125 132 " -s set the ptp clock time from the system time\n" ··· 141 134 struct ptp_extts_event event; 142 135 struct ptp_extts_request extts_request; 143 136 struct ptp_perout_request perout_request; 137 + struct ptp_pin_desc desc; 144 138 struct timespec ts; 145 139 struct timex tx; 146 140 ··· 164 156 int extts = 0; 165 157 int gettime = 0; 166 158 int index = 0; 159 + int list_pins = 0; 167 160 int oneshot = 0; 168 161 int pct_offset = 0; 169 162 int n_samples = 0; 170 163 int periodic = 0; 171 164 int perout = -1; 165 + int pin_index = -1, pin_func; 172 166 int pps = -1; 173 167 int settime = 0; 174 168 ··· 179 169 180 170 progname = strrchr(argv[0], '/'); 181 171 progname = progname ? 1+progname : argv[0]; 182 - while (EOF != (c = getopt(argc, argv, "a:A:cd:e:f:ghi:k:p:P:sSt:v"))) { 172 + while (EOF != (c = getopt(argc, argv, "a:A:cd:e:f:ghi:k:lL:p:P:sSt:v"))) { 183 173 switch (c) { 184 174 case 'a': 185 175 oneshot = atoi(optarg); ··· 208 198 case 'k': 209 199 pct_offset = 1; 210 200 n_samples = atoi(optarg); 201 + break; 202 + case 'l': 203 + list_pins = 1; 204 + break; 205 + case 'L': 206 + cnt = sscanf(optarg, "%d,%d", &pin_index, &pin_func); 207 + if (cnt != 2) { 208 + usage(progname); 209 + return -1; 210 + } 211 211 break; 212 212 case 'p': 213 213 perout = atoi(optarg); ··· 265 245 " %d programmable alarms\n" 266 246 " %d external time stamp channels\n" 267 247 " %d programmable periodic signals\n" 268 - " %d pulse per second\n", 248 + " %d pulse per second\n" 249 + " %d programmable pins\n", 269 250 caps.max_adj, 270 251 caps.n_alarm, 271 252 caps.n_ext_ts, 272 253 caps.n_per_out, 273 - caps.pps); 254 + caps.pps, 255 + caps.n_pins); 274 256 } 275 257 } 276 258 ··· 353 331 } 354 332 } 355 333 334 + if (list_pins) { 335 + int n_pins = 0; 336 + if (ioctl(fd, PTP_CLOCK_GETCAPS, &caps)) { 337 + perror("PTP_CLOCK_GETCAPS"); 338 + } else { 339 + n_pins = caps.n_pins; 340 + } 341 + for (i = 0; i < n_pins; i++) { 342 + desc.index = i; 343 + if (ioctl(fd, PTP_PIN_GETFUNC, &desc)) { 344 + perror("PTP_PIN_GETFUNC"); 345 + break; 346 + } 347 + printf("name %s index %u func %u chan %u\n", 348 + desc.name, desc.index, desc.func, desc.chan); 349 + } 350 + } 351 + 356 352 if (oneshot) { 357 353 install_handler(SIGALRM, handle_alarm); 358 354 /* Create a timer. */ ··· 429 389 perror("PTP_PEROUT_REQUEST"); 430 390 } else { 431 391 puts("periodic output request okay"); 392 + } 393 + } 394 + 395 + if (pin_index >= 0) { 396 + memset(&desc, 0, sizeof(desc)); 397 + desc.index = pin_index; 398 + desc.func = pin_func; 399 + desc.chan = index; 400 + if (ioctl(fd, PTP_PIN_SETFUNC, &desc)) { 401 + perror("PTP_PIN_SETFUNC"); 402 + } else { 403 + puts("set pin function okay"); 432 404 } 433 405 } 434 406