]> rtime.felk.cvut.cz Git - can-utils.git/blob - can-calc-bit-timing.c
slcan: added listen-only flag
[can-utils.git] / can-calc-bit-timing.c
1 /* can-calc-bit-timing.c: Calculate CAN bit timing parameters
2  *
3  * Copyright (C) 2008 Wolfgang Grandegger <wg@grandegger.com>
4  *
5  * Derived from:
6  *   can_baud.c - CAN baudrate calculation
7  *   Code based on LinCAN sources and H8S2638 project
8  *   Copyright 2004-2006 Pavel Pisa - DCE FELK CVUT cz
9  *   Copyright 2005      Stanislav Marek
10  *   email:pisa@cmp.felk.cvut.cz
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * any later version.
16  */
17
18 #include <errno.h>
19 #include <getopt.h>
20 #include <stdint.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24
25 #include <linux/types.h>
26
27 /* seems not to be defined in errno.h */
28 #ifndef ENOTSUPP
29 #define ENOTSUPP        524     /* Operation is not supported */
30 #endif
31
32 /* useful defines */
33 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
34
35 #define do_div(a,b) a = (a) / (b)
36
37 #define abs(x) ({                               \
38                 long __x = (x);                 \
39                 (__x < 0) ? -__x : __x;         \
40         })
41
42 /**
43  * clamp - return a value clamped to a given range with strict typechecking
44  * @val: current value
45  * @min: minimum allowable value
46  * @max: maximum allowable value
47  *
48  * This macro does strict typechecking of min/max to make sure they are of the
49  * same type as val.  See the unnecessary pointer comparisons.
50  */
51 #define clamp(val, min, max) ({                 \
52         typeof(val) __val = (val);              \
53         typeof(min) __min = (min);              \
54         typeof(max) __max = (max);              \
55         (void) (&__val == &__min);              \
56         (void) (&__val == &__max);              \
57         __val = __val < __min ? __min: __val;   \
58         __val > __max ? __max: __val; })
59
60 /* we don't want to see these prints */
61 #define dev_err(dev, format, arg...)    do { } while (0)
62 #define dev_warn(dev, format, arg...)   do { } while (0)
63
64 /* define in-kernel-types */
65 typedef __u64 u64;
66 typedef __u32 u32;
67
68
69 /*
70  * CAN bit-timing parameters
71  *
72  * For futher information, please read chapter "8 BIT TIMING
73  * REQUIREMENTS" of the "Bosch CAN Specification version 2.0"
74  * at http://www.semiconductors.bosch.de/pdf/can2spec.pdf.
75  */
76 struct can_bittiming {
77         __u32 bitrate;          /* Bit-rate in bits/second */
78         __u32 sample_point;     /* Sample point in one-tenth of a percent */
79         __u32 tq;               /* Time quanta (TQ) in nanoseconds */
80         __u32 prop_seg;         /* Propagation segment in TQs */
81         __u32 phase_seg1;       /* Phase buffer segment 1 in TQs */
82         __u32 phase_seg2;       /* Phase buffer segment 2 in TQs */
83         __u32 sjw;              /* Synchronisation jump width in TQs */
84         __u32 brp;              /* Bit-rate prescaler */
85 };
86
87 /*
88  * CAN harware-dependent bit-timing constant
89  *
90  * Used for calculating and checking bit-timing parameters
91  */
92 struct can_bittiming_const {
93         char name[16];          /* Name of the CAN controller hardware */
94         __u32 tseg1_min;        /* Time segement 1 = prop_seg + phase_seg1 */
95         __u32 tseg1_max;
96         __u32 tseg2_min;        /* Time segement 2 = phase_seg2 */
97         __u32 tseg2_max;
98         __u32 sjw_max;          /* Synchronisation jump width */
99         __u32 brp_min;          /* Bit-rate prescaler */
100         __u32 brp_max;
101         __u32 brp_inc;
102
103         /* added for can-calc-bit-timing utility */
104         __u32 ref_clk;          /* CAN system clock frequency in Hz */
105         void (*printf_btr)(struct can_bittiming *bt, int hdr);
106 };
107
108 /*
109  * CAN clock parameters
110  */
111 struct can_clock {
112         __u32 freq;             /* CAN system clock frequency in Hz */
113 };
114
115
116 /*
117  * minimal structs, just enough to be source level compatible
118  */
119 struct can_priv {
120         const struct can_bittiming_const *bittiming_const;
121         struct can_clock clock;
122 };
123
124 struct net_device {
125         struct can_priv priv;
126 };
127
128 static inline void *netdev_priv(const struct net_device *dev)
129 {
130         return (void *)&dev->priv;
131 }
132
133 static void print_usage(char* cmd)
134 {
135         printf("Usage: %s [options] [<CAN-contoller-name>]\n"
136                "\tOptions:\n"
137                "\t-q           : don't print header line\n"
138                "\t-l           : list all support CAN controller names\n"
139                "\t-b <bitrate> : bit-rate in bits/sec\n"
140                "\t-s <samp_pt> : sample-point in one-tenth of a percent\n"
141                "\t               or 0 for CIA recommended sample points\n"
142                "\t-c <clock>   : real CAN system clock in Hz\n",
143                cmd);
144
145         exit(EXIT_FAILURE);
146 }
147
148 static void printf_btr_sja1000(struct can_bittiming *bt, int hdr)
149 {
150         uint8_t btr0, btr1;
151
152         if (hdr) {
153                 printf("BTR0 BTR1");
154         } else {
155                 btr0 = ((bt->brp - 1) & 0x3f) | (((bt->sjw - 1) & 0x3) << 6);
156                 btr1 = ((bt->prop_seg + bt->phase_seg1 - 1) & 0xf) |
157                         (((bt->phase_seg2 - 1) & 0x7) << 4);
158                 printf("0x%02x 0x%02x", btr0, btr1);
159         }
160 }
161
162 static void printf_btr_at91(struct can_bittiming *bt, int hdr)
163 {
164         if (hdr) {
165                 printf("%10s", "CAN_BR");
166         } else {
167                 uint32_t br = ((bt->phase_seg2 - 1) |
168                                ((bt->phase_seg1 - 1) << 4) |
169                                ((bt->prop_seg - 1) << 8) |
170                                ((bt->sjw - 1) << 12) |
171                                ((bt->brp - 1) << 16));
172                 printf("0x%08x", br);
173         }
174 }
175
176 static void printf_btr_flexcan(struct can_bittiming *bt, int hdr)
177 {
178         if (hdr) {
179                 printf("%10s", "CAN_CTRL");
180         } else {
181                 uint32_t ctrl = (((bt->brp        - 1) << 24) |
182                                  ((bt->sjw        - 1) << 22) |
183                                  ((bt->phase_seg1 - 1) << 19) |
184                                  ((bt->phase_seg2 - 1) << 16) |
185                                  ((bt->prop_seg   - 1) <<  0));
186
187                 printf("0x%08x", ctrl);
188         }
189 }
190
191 static void printf_btr_mcp251x(struct can_bittiming *bt, int hdr)
192 {
193         uint8_t cnf1, cnf2, cnf3;
194
195         if (hdr) {
196                 printf("CNF1 CNF2 CNF3");
197         } else {
198                 cnf1 = ((bt->sjw - 1) << 6) | (bt->brp - 1);
199                 cnf2 = 0x80 | ((bt->phase_seg1 - 1) << 3) | (bt->prop_seg - 1);
200                 cnf3 = bt->phase_seg2 - 1;
201                 printf("0x%02x 0x%02x 0x%02x", cnf1, cnf2, cnf3);
202         }
203 }
204
205 static void printf_btr_ti_hecc(struct can_bittiming *bt, int hdr)
206 {
207         if (hdr) {
208                 printf("%10s", "CANBTC");
209         } else {
210                 uint32_t can_btc;
211
212                 can_btc = (bt->phase_seg2 - 1) & 0x7;
213                 can_btc |= ((bt->phase_seg1 + bt->prop_seg - 1)
214                             & 0xF) << 3;
215                 can_btc |= ((bt->sjw - 1) & 0x3) << 8;
216                 can_btc |= ((bt->brp - 1) & 0xFF) << 16;
217
218                 printf("0x%08x", can_btc);
219         }
220 }
221
222 static struct can_bittiming_const can_calc_consts[] = {
223         {
224                 .name = "sja1000",
225                 .tseg1_min = 1,
226                 .tseg1_max = 16,
227                 .tseg2_min = 1,
228                 .tseg2_max = 8,
229                 .sjw_max = 4,
230                 .brp_min = 1,
231                 .brp_max = 64,
232                 .brp_inc = 1,
233
234                 .ref_clk = 8000000,
235                 .printf_btr = printf_btr_sja1000,
236         },
237         {
238                 .name = "mscan",
239                 .tseg1_min = 4,
240                 .tseg1_max = 16,
241                 .tseg2_min = 2,
242                 .tseg2_max = 8,
243                 .sjw_max = 4,
244                 .brp_min = 1,
245                 .brp_max = 64,
246                 .brp_inc = 1,
247
248                 .ref_clk = 32000000,
249                 .printf_btr = printf_btr_sja1000,
250         },
251         {
252                 .name = "mscan",
253                 .tseg1_min = 4,
254                 .tseg1_max = 16,
255                 .tseg2_min = 2,
256                 .tseg2_max = 8,
257                 .sjw_max = 4,
258                 .brp_min = 1,
259                 .brp_max = 64,
260                 .brp_inc = 1,
261
262                 .ref_clk = 33000000,
263                 .printf_btr = printf_btr_sja1000,
264         },
265         {
266                 .name = "mscan",
267                 .tseg1_min = 4,
268                 .tseg1_max = 16,
269                 .tseg2_min = 2,
270                 .tseg2_max = 8,
271                 .sjw_max = 4,
272                 .brp_min = 1,
273                 .brp_max = 64,
274                 .brp_inc = 1,
275
276                 .ref_clk = 33300000,
277                 .printf_btr = printf_btr_sja1000,
278         },
279         {
280                 .name = "mscan",
281                 .tseg1_min = 4,
282                 .tseg1_max = 16,
283                 .tseg2_min = 2,
284                 .tseg2_max = 8,
285                 .sjw_max = 4,
286                 .brp_min = 1,
287                 .brp_max = 64,
288                 .brp_inc = 1,
289
290                 .ref_clk = 33333333,
291                 .printf_btr = printf_btr_sja1000,
292         },
293         {
294                 .name = "mscan",
295                 .tseg1_min = 4,
296                 .tseg1_max = 16,
297                 .tseg2_min = 2,
298                 .tseg2_max = 8,
299                 .sjw_max = 4,
300                 .brp_min = 1,
301                 .brp_max = 64,
302                 .brp_inc = 1,
303
304                 .ref_clk = 66660000,    /* mpc5121 */
305                 .printf_btr = printf_btr_sja1000,
306         },
307         {
308                 .name = "mscan",
309                 .tseg1_min = 4,
310                 .tseg1_max = 16,
311                 .tseg2_min = 2,
312                 .tseg2_max = 8,
313                 .sjw_max = 4,
314                 .brp_min = 1,
315                 .brp_max = 64,
316                 .brp_inc = 1,
317
318                 .ref_clk = 66666666,    /* mpc5121 */
319                 .printf_btr = printf_btr_sja1000,
320         },
321         {
322                 .name = "at91",
323                 .tseg1_min = 4,
324                 .tseg1_max = 16,
325                 .tseg2_min = 2,
326                 .tseg2_max = 8,
327                 .sjw_max = 4,
328                 .brp_min = 2,
329                 .brp_max = 128,
330                 .brp_inc = 1,
331
332                 .ref_clk = 100000000,
333                 .printf_btr = printf_btr_at91,
334         },
335         {
336                 .name = "at91",
337                 .tseg1_min = 4,
338                 .tseg1_max = 16,
339                 .tseg2_min = 2,
340                 .tseg2_max = 8,
341                 .sjw_max = 4,
342                 .brp_min = 2,
343                 .brp_max = 128,
344                 .brp_inc = 1,
345
346                 /* real world clock as found on the ronetix PM9263 */
347                 .ref_clk = 99532800,
348                 .printf_btr = printf_btr_at91,
349         },
350         {
351                 .name = "flexcan",
352                 .tseg1_min = 4,
353                 .tseg1_max = 16,
354                 .tseg2_min = 2,
355                 .tseg2_max = 8,
356                 .sjw_max = 4,
357                 .brp_min = 1,
358                 .brp_max = 256,
359                 .brp_inc = 1,
360
361                 .ref_clk = 24000000,    /* mx28 */
362                 .printf_btr = printf_btr_flexcan,
363         },
364         {
365                 .name = "flexcan",
366                 .tseg1_min = 4,
367                 .tseg1_max = 16,
368                 .tseg2_min = 2,
369                 .tseg2_max = 8,
370                 .sjw_max = 4,
371                 .brp_min = 1,
372                 .brp_max = 256,
373                 .brp_inc = 1,
374
375                 .ref_clk = 49875000,
376                 .printf_btr = printf_btr_flexcan,
377         },
378         {
379                 .name = "flexcan",
380                 .tseg1_min = 4,
381                 .tseg1_max = 16,
382                 .tseg2_min = 2,
383                 .tseg2_max = 8,
384                 .sjw_max = 4,
385                 .brp_min = 1,
386                 .brp_max = 256,
387                 .brp_inc = 1,
388
389                 .ref_clk = 66000000,
390                 .printf_btr = printf_btr_flexcan,
391         },
392         {
393                 .name = "flexcan",
394                 .tseg1_min = 4,
395                 .tseg1_max = 16,
396                 .tseg2_min = 2,
397                 .tseg2_max = 8,
398                 .sjw_max = 4,
399                 .brp_min = 1,
400                 .brp_max = 256,
401                 .brp_inc = 1,
402
403                 .ref_clk = 66500000,
404                 .printf_btr = printf_btr_flexcan,
405         },
406         {
407                 .name = "flexcan",
408                 .tseg1_min = 4,
409                 .tseg1_max = 16,
410                 .tseg2_min = 2,
411                 .tseg2_max = 8,
412                 .sjw_max = 4,
413                 .brp_min = 1,
414                 .brp_max = 256,
415                 .brp_inc = 1,
416
417                 .ref_clk = 66666666,
418                 .printf_btr = printf_btr_flexcan,
419         },
420         {
421                 .name = "flexcan",
422                 .tseg1_min = 4,
423                 .tseg1_max = 16,
424                 .tseg2_min = 2,
425                 .tseg2_max = 8,
426                 .sjw_max = 4,
427                 .brp_min = 1,
428                 .brp_max = 256,
429                 .brp_inc = 1,
430
431                 .ref_clk = 83368421,
432                 .printf_btr = printf_btr_flexcan, /* vybrid */
433         },
434         {
435                 .name = "mcp251x",
436                 .tseg1_min = 3,
437                 .tseg1_max = 16,
438                 .tseg2_min = 2,
439                 .tseg2_max = 8,
440                 .sjw_max = 4,
441                 .brp_min = 1,
442                 .brp_max = 64,
443                 .brp_inc = 1,
444
445                 .ref_clk = 8000000,
446                 .printf_btr = printf_btr_mcp251x,
447         },
448         {
449                 .name = "mcp251x",
450                 .tseg1_min = 3,
451                 .tseg1_max = 16,
452                 .tseg2_min = 2,
453                 .tseg2_max = 8,
454                 .sjw_max = 4,
455                 .brp_min = 1,
456                 .brp_max = 64,
457                 .brp_inc = 1,
458
459                 .ref_clk = 16000000,
460                 .printf_btr = printf_btr_mcp251x,
461         },
462         {
463                 .name = "ti_hecc",
464                 .tseg1_min = 1,
465                 .tseg1_max = 16,
466                 .tseg2_min = 1,
467                 .tseg2_max = 8,
468                 .sjw_max = 4,
469                 .brp_min = 1,
470                 .brp_max = 256,
471                 .brp_inc = 1,
472
473                 .ref_clk = 13000000,
474                 .printf_btr = printf_btr_ti_hecc,
475         }
476 };
477
478 static long common_bitrates[] = {
479         1000000,
480         800000,
481         500000,
482         250000,
483         125000,
484         100000,
485         50000,
486         20000,
487         10000,
488 };
489
490 #define CAN_CALC_MAX_ERROR 50 /* in one-tenth of a percent */
491
492 static int can_update_spt(const struct can_bittiming_const *btc,
493                           int sampl_pt, int tseg, int *tseg1, int *tseg2)
494 {
495         *tseg2 = tseg + 1 - (sampl_pt * (tseg + 1)) / 1000;
496         if (*tseg2 < btc->tseg2_min)
497                 *tseg2 = btc->tseg2_min;
498         if (*tseg2 > btc->tseg2_max)
499                 *tseg2 = btc->tseg2_max;
500         *tseg1 = tseg - *tseg2;
501         if (*tseg1 > btc->tseg1_max) {
502                 *tseg1 = btc->tseg1_max;
503                 *tseg2 = tseg - *tseg1;
504         }
505         return 1000 * (tseg + 1 - *tseg2) / (tseg + 1);
506 }
507
508 static int can_calc_bittiming(struct net_device *dev, struct can_bittiming *bt)
509 {
510         struct can_priv *priv = netdev_priv(dev);
511         const struct can_bittiming_const *btc = priv->bittiming_const;
512         long rate = 0;
513         long best_error = 1000000000, error = 0;
514         int best_tseg = 0, best_brp = 0, brp = 0;
515         int tsegall, tseg = 0, tseg1 = 0, tseg2 = 0;
516         int spt_error = 1000, spt = 0, sampl_pt;
517         u64 v64;
518
519         if (!priv->bittiming_const)
520                 return -ENOTSUPP;
521
522         /* Use CIA recommended sample points */
523         if (bt->sample_point) {
524                 sampl_pt = bt->sample_point;
525         } else {
526                 if (bt->bitrate > 800000)
527                         sampl_pt = 750;
528                 else if (bt->bitrate > 500000)
529                         sampl_pt = 800;
530                 else
531                         sampl_pt = 875;
532         }
533
534         /* tseg even = round down, odd = round up */
535         for (tseg = (btc->tseg1_max + btc->tseg2_max) * 2 + 1;
536              tseg >= (btc->tseg1_min + btc->tseg2_min) * 2; tseg--) {
537                 tsegall = 1 + tseg / 2;
538                 /* Compute all possible tseg choices (tseg=tseg1+tseg2) */
539                 brp = priv->clock.freq / (tsegall * bt->bitrate) + tseg % 2;
540                 /* chose brp step which is possible in system */
541                 brp = (brp / btc->brp_inc) * btc->brp_inc;
542                 if ((brp < btc->brp_min) || (brp > btc->brp_max))
543                         continue;
544                 rate = priv->clock.freq / (brp * tsegall);
545                 error = bt->bitrate - rate;
546                 /* tseg brp biterror */
547                 if (error < 0)
548                         error = -error;
549                 if (error > best_error)
550                         continue;
551                 best_error = error;
552                 if (error == 0) {
553                         spt = can_update_spt(btc, sampl_pt, tseg / 2,
554                                              &tseg1, &tseg2);
555                         error = sampl_pt - spt;
556                         if (error < 0)
557                                 error = -error;
558                         if (error > spt_error)
559                                 continue;
560                         spt_error = error;
561                 }
562                 best_tseg = tseg / 2;
563                 best_brp = brp;
564                 if (error == 0)
565                         break;
566         }
567
568         if (best_error) {
569                 /* Error in one-tenth of a percent */
570                 error = (best_error * 1000) / bt->bitrate;
571                 if (error > CAN_CALC_MAX_ERROR) {
572                         dev_err(dev->dev.parent,
573                                 "bitrate error %ld.%ld%% too high\n",
574                                 error / 10, error % 10);
575                         return -EDOM;
576                 } else {
577                         dev_warn(dev->dev.parent, "bitrate error %ld.%ld%%\n",
578                                  error / 10, error % 10);
579                 }
580         }
581
582         /* real sample point */
583         bt->sample_point = can_update_spt(btc, sampl_pt, best_tseg,
584                                           &tseg1, &tseg2);
585
586         v64 = (u64)best_brp * 1000000000UL;
587         do_div(v64, priv->clock.freq);
588         bt->tq = (u32)v64;
589         bt->prop_seg = tseg1 / 2;
590         bt->phase_seg1 = tseg1 - bt->prop_seg;
591         bt->phase_seg2 = tseg2;
592         bt->sjw = 1;
593         bt->brp = best_brp;
594
595         /* real bit-rate */
596         bt->bitrate = priv->clock.freq / (bt->brp * (tseg1 + tseg2 + 1));
597
598         return 0;
599 }
600
601 static __u32 get_cia_sample_point(__u32 bitrate)
602 {
603         __u32 sampl_pt;
604
605         if (bitrate > 800000)
606                 sampl_pt = 750;
607         else if (bitrate > 500000)
608                 sampl_pt = 800;
609         else
610                 sampl_pt = 875;
611
612         return sampl_pt;
613 }
614
615 static void print_bit_timing(const struct can_bittiming_const *btc,
616                              __u32 bitrate, __u32 sample_point, __u32 ref_clk,
617                              int quiet)
618 {
619         struct net_device dev = {
620                 .priv.bittiming_const = btc,
621                 .priv.clock.freq = ref_clk,
622         };
623         struct can_bittiming bt = {
624                 .bitrate = bitrate,
625                 .sample_point = sample_point,
626         };
627         long rate_error, spt_error;
628
629         if (!quiet) {
630                 printf("Bit timing parameters for %s with %.6f MHz ref clock\n"
631                        "nominal                                 real Bitrt   nom  real SampP\n"
632                        "Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error ",
633                        btc->name,
634                        ref_clk / 1000000.0);
635
636                 btc->printf_btr(&bt, 1);
637                 printf("\n");
638         }
639
640         if (can_calc_bittiming(&dev, &bt)) {
641                 printf("%7d ***bitrate not possible***\n", bitrate);
642                 return;
643         }
644
645         /* get nominal sample point */
646         if (!sample_point)
647                 sample_point = get_cia_sample_point(bitrate);
648
649         rate_error = abs((__s32)(bitrate - bt.bitrate));
650         spt_error = abs((__s32)(sample_point - bt.sample_point));
651
652         printf("%7d "
653                "%6d %3d %4d %4d "
654                "%3d %3d "
655                "%7d %4.1f%% "
656                "%4.1f%% %4.1f%% %4.1f%% ",
657                bitrate,
658                bt.tq, bt.prop_seg, bt.phase_seg1, bt.phase_seg2,
659                bt.sjw, bt.brp,
660
661                bt.bitrate,
662                100.0 * rate_error / bitrate,
663
664                sample_point / 10.0,
665                bt.sample_point / 10.0,
666                100.0 * spt_error / sample_point);
667
668         btc->printf_btr(&bt, 0);
669         printf("\n");
670 }
671
672 static void do_list(void)
673 {
674         unsigned int i;
675
676         for (i = 0; i < ARRAY_SIZE(can_calc_consts); i++)
677                 printf("%s\n", can_calc_consts[i].name);
678 }
679
680 int main(int argc, char *argv[])
681 {
682         __u32 bitrate = 0;
683         __u32 opt_ref_clk = 0, ref_clk;
684         int sampl_pt = 0;
685         int quiet = 0;
686         int list = 0;
687         char *name = NULL;
688         unsigned int i, j;
689         int opt, found = 0;
690
691         const struct can_bittiming_const *btc = NULL;
692
693         while ((opt = getopt(argc, argv, "b:c:lps:")) != -1) {
694                 switch (opt) {
695                 case 'b':
696                         bitrate = atoi(optarg);
697                         break;
698
699                 case 'c':
700                         opt_ref_clk = atoi(optarg);
701                         break;
702
703                 case 'l':
704                         list = 1;
705                         break;
706
707                 case 'q':
708                         quiet = 1;
709                         break;
710
711                 case 's':
712                         sampl_pt = atoi(optarg);
713                         break;
714
715                 default:
716                         print_usage(argv[0]);
717                         break;
718                 }
719         }
720
721         if (argc > optind + 1)
722                 print_usage(argv[0]);
723
724         if (argc == optind + 1)
725                 name = argv[optind];
726
727         if (list) {
728                 do_list();
729                 exit(EXIT_SUCCESS);
730         }
731
732         if (sampl_pt && (sampl_pt >= 1000 || sampl_pt < 100))
733                 print_usage(argv[0]);
734
735         for (i = 0; i < ARRAY_SIZE(can_calc_consts); i++) {
736                 if (name && strcmp(can_calc_consts[i].name, name))
737                         continue;
738
739                 found = 1;
740                 btc = &can_calc_consts[i];
741
742                 if (opt_ref_clk)
743                         ref_clk = opt_ref_clk;
744                 else
745                         ref_clk = btc->ref_clk;
746
747                 if (bitrate) {
748                         print_bit_timing(btc, bitrate, sampl_pt, ref_clk, quiet);
749                 } else {
750                         for (j = 0; j < ARRAY_SIZE(common_bitrates); j++)
751                                 print_bit_timing(btc, common_bitrates[j],
752                                                  sampl_pt, ref_clk, j);
753                 }
754                 printf("\n");
755         }
756
757         if (!found) {
758                 printf("error: unknown CAN controller '%s', try one of these:\n\n", name);
759                 do_list();
760                 exit(EXIT_FAILURE);
761         }
762
763         exit(EXIT_SUCCESS);
764 }