]> rtime.felk.cvut.cz Git - can-utils.git/blobdiff - can-calc-bit-timing.c
can-calc-bit-timing: fix checkpatch warnings
[can-utils.git] / can-calc-bit-timing.c
index d97ebe6bcfa2374d654dd10bddb2fcbe4a4a4be0..6e9fc39eaa2d98b8f615089e16fa33ca542b3bf1 100644 (file)
@@ -9,7 +9,10 @@
  *   Copyright 2005      Stanislav Marek
  *   email:pisa@cmp.felk.cvut.cz
  *
- *   This software is released under the GPL-License.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
  */
 
 #include <errno.h>
@@ -26,7 +29,7 @@
 #define ENOTSUPP       524     /* Operation is not supported */
 #endif
 
-/* usefull defines */
+/* useful defines */
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
 #define do_div(a,b) a = (a) / (b)
@@ -127,7 +130,7 @@ static inline void *netdev_priv(const struct net_device *dev)
        return (void *)&dev->priv;
 }
 
-static void print_usage(charcmd)
+static void print_usage(char *cmd)
 {
        printf("Usage: %s [options] [<CAN-contoller-name>]\n"
               "\tOptions:\n"
@@ -192,13 +195,51 @@ static void printf_btr_mcp251x(struct can_bittiming *bt, int hdr)
        if (hdr) {
                printf("CNF1 CNF2 CNF3");
        } else {
-               cnf1 = ((bt->sjw - 1) << 6) | bt->brp;
+               cnf1 = ((bt->sjw - 1) << 6) | (bt->brp - 1);
                cnf2 = 0x80 | ((bt->phase_seg1 - 1) << 3) | (bt->prop_seg - 1);
                cnf3 = bt->phase_seg2 - 1;
                printf("0x%02x 0x%02x 0x%02x", cnf1, cnf2, cnf3);
        }
 }
 
+static void printf_btr_ti_hecc(struct can_bittiming *bt, int hdr)
+{
+       if (hdr) {
+               printf("%10s", "CANBTC");
+       } else {
+               uint32_t can_btc;
+
+               can_btc = (bt->phase_seg2 - 1) & 0x7;
+               can_btc |= ((bt->phase_seg1 + bt->prop_seg - 1)
+                           & 0xF) << 3;
+               can_btc |= ((bt->sjw - 1) & 0x3) << 8;
+               can_btc |= ((bt->brp - 1) & 0xFF) << 16;
+
+               printf("0x%08x", can_btc);
+       }
+}
+
+#define RCAR_CAN_BCR_TSEG1(x)  (((x) & 0x0f) << 20)
+#define RCAR_CAN_BCR_BPR(x)    (((x) & 0x3ff) << 8)
+#define RCAR_CAN_BCR_SJW(x)    (((x) & 0x3) << 4)
+#define RCAR_CAN_BCR_TSEG2(x)  ((x) & 0x07)
+
+static void printf_btr_rcar_can(struct can_bittiming *bt, int hdr)
+{
+       if (hdr) {
+               printf("%10s", "CiBCR");
+       } else {
+               uint32_t bcr;
+
+               bcr = RCAR_CAN_BCR_TSEG1(bt->phase_seg1 + bt->prop_seg - 1) |
+                       RCAR_CAN_BCR_BPR(bt->brp - 1) |
+                       RCAR_CAN_BCR_SJW(bt->sjw - 1) |
+                       RCAR_CAN_BCR_TSEG2(bt->phase_seg2 - 1);
+
+               printf("0x%08x", bcr << 8);
+       }
+}
+
 static struct can_bittiming_const can_calc_consts[] = {
        {
                .name = "sja1000",
@@ -284,6 +325,20 @@ static struct can_bittiming_const can_calc_consts[] = {
                .ref_clk = 66660000,    /* mpc5121 */
                .printf_btr = printf_btr_sja1000,
        },
+       {
+               .name = "mscan",
+               .tseg1_min = 4,
+               .tseg1_max = 16,
+               .tseg2_min = 2,
+               .tseg2_max = 8,
+               .sjw_max = 4,
+               .brp_min = 1,
+               .brp_max = 64,
+               .brp_inc = 1,
+
+               .ref_clk = 66666666,    /* mpc5121 */
+               .printf_btr = printf_btr_sja1000,
+       },
        {
                .name = "at91",
                .tseg1_min = 4,
@@ -338,6 +393,20 @@ static struct can_bittiming_const can_calc_consts[] = {
                .brp_max = 256,
                .brp_inc = 1,
 
+               .ref_clk = 30000000,    /* mx6 */
+               .printf_btr = printf_btr_flexcan,
+       },
+       {
+               .name = "flexcan",
+               .tseg1_min = 4,
+               .tseg1_max = 16,
+               .tseg2_min = 2,
+               .tseg2_max = 8,
+               .sjw_max = 4,
+               .brp_min = 1,
+               .brp_max = 256,
+               .brp_inc = 1,
+
                .ref_clk = 49875000,
                .printf_btr = printf_btr_flexcan,
        },
@@ -369,6 +438,34 @@ static struct can_bittiming_const can_calc_consts[] = {
                .ref_clk = 66500000,
                .printf_btr = printf_btr_flexcan,
        },
+       {
+               .name = "flexcan",
+               .tseg1_min = 4,
+               .tseg1_max = 16,
+               .tseg2_min = 2,
+               .tseg2_max = 8,
+               .sjw_max = 4,
+               .brp_min = 1,
+               .brp_max = 256,
+               .brp_inc = 1,
+
+               .ref_clk = 66666666,
+               .printf_btr = printf_btr_flexcan,
+       },
+       {
+               .name = "flexcan",
+               .tseg1_min = 4,
+               .tseg1_max = 16,
+               .tseg2_min = 2,
+               .tseg2_max = 8,
+               .sjw_max = 4,
+               .brp_min = 1,
+               .brp_max = 256,
+               .brp_inc = 1,
+
+               .ref_clk = 83368421,
+               .printf_btr = printf_btr_flexcan, /* vybrid */
+       },
        {
                .name = "mcp251x",
                .tseg1_min = 3,
@@ -397,6 +494,34 @@ static struct can_bittiming_const can_calc_consts[] = {
                .ref_clk = 16000000,
                .printf_btr = printf_btr_mcp251x,
        },
+       {
+               .name = "ti_hecc",
+               .tseg1_min = 1,
+               .tseg1_max = 16,
+               .tseg2_min = 1,
+               .tseg2_max = 8,
+               .sjw_max = 4,
+               .brp_min = 1,
+               .brp_max = 256,
+               .brp_inc = 1,
+
+               .ref_clk = 13000000,
+               .printf_btr = printf_btr_ti_hecc,
+       },
+       {
+               .name = "rcar_can",
+               .tseg1_min = 4,
+               .tseg1_max = 16,
+               .tseg2_min = 2,
+               .tseg2_max = 8,
+               .sjw_max = 4,
+               .brp_min = 1,
+               .brp_max = 1024,
+               .brp_inc = 1,
+
+               .ref_clk = 65000000,
+               .printf_btr = printf_btr_rcar_can,
+       },
 };
 
 static long common_bitrates[] = {