Skip to content

Commit 99312c3

Browse files
Marek Vasutmarckleinebudde
authored andcommitted
can: ifi: Fix clock generator configuration
The clock generation does not match reality when using the CAN IP core outside of the FPGA design. This patch fixes the computation of values which are programmed into the clock generator registers. First, there are some off-by-one errors which manifest themselves only when communicating with different controller, so those are fixed. Second, the bits in the clock generator registers have different meaning depending on whether the core is in ISO CANFD mode or any of the other modes (BOSCH CANFD or CAN2.0). Detect the ISO CANFD mode and fix handling of this special case of clock configuration. Finally, the CAN clock speed is in CANCLOCK register, not SYSCLOCK register, so fix this as well. Signed-off-by: Marek Vasut <[email protected]> Cc: Marc Kleine-Budde <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Oliver Hartkopp <[email protected]> Cc: Wolfgang Grandegger <[email protected]> Reviewed-by: Oliver Hartkopp <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 3b8377d commit 99312c3

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

drivers/net/can/ifi_canfd/ifi_canfd.c

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -514,25 +514,25 @@ static irqreturn_t ifi_canfd_isr(int irq, void *dev_id)
514514

515515
static const struct can_bittiming_const ifi_canfd_bittiming_const = {
516516
.name = KBUILD_MODNAME,
517-
.tseg1_min = 2, /* Time segment 1 = prop_seg + phase_seg1 */
517+
.tseg1_min = 1, /* Time segment 1 = prop_seg + phase_seg1 */
518518
.tseg1_max = 64,
519-
.tseg2_min = 1, /* Time segment 2 = phase_seg2 */
520-
.tseg2_max = 16,
519+
.tseg2_min = 2, /* Time segment 2 = phase_seg2 */
520+
.tseg2_max = 64,
521521
.sjw_max = 16,
522-
.brp_min = 1,
523-
.brp_max = 1024,
522+
.brp_min = 2,
523+
.brp_max = 256,
524524
.brp_inc = 1,
525525
};
526526

527527
static const struct can_bittiming_const ifi_canfd_data_bittiming_const = {
528528
.name = KBUILD_MODNAME,
529-
.tseg1_min = 2, /* Time segment 1 = prop_seg + phase_seg1 */
530-
.tseg1_max = 16,
531-
.tseg2_min = 1, /* Time segment 2 = phase_seg2 */
532-
.tseg2_max = 8,
533-
.sjw_max = 4,
534-
.brp_min = 1,
535-
.brp_max = 32,
529+
.tseg1_min = 1, /* Time segment 1 = prop_seg + phase_seg1 */
530+
.tseg1_max = 64,
531+
.tseg2_min = 2, /* Time segment 2 = phase_seg2 */
532+
.tseg2_max = 64,
533+
.sjw_max = 16,
534+
.brp_min = 2,
535+
.brp_max = 256,
536536
.brp_inc = 1,
537537
};
538538

@@ -545,32 +545,34 @@ static void ifi_canfd_set_bittiming(struct net_device *ndev)
545545
u32 noniso_arg = 0;
546546
u32 time_off;
547547

548-
if (priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO) {
548+
if ((priv->can.ctrlmode & CAN_CTRLMODE_FD) &&
549+
!(priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO)) {
550+
time_off = IFI_CANFD_TIME_SJW_OFF_ISO;
551+
} else {
549552
noniso_arg = IFI_CANFD_TIME_SET_TIMEB_BOSCH |
550553
IFI_CANFD_TIME_SET_TIMEA_BOSCH |
551554
IFI_CANFD_TIME_SET_PRESC_BOSCH |
552555
IFI_CANFD_TIME_SET_SJW_BOSCH;
553556
time_off = IFI_CANFD_TIME_SJW_OFF_BOSCH;
554-
} else {
555-
time_off = IFI_CANFD_TIME_SJW_OFF_ISO;
556557
}
557558

558559
/* Configure bit timing */
559-
brp = bt->brp - 1;
560+
brp = bt->brp - 2;
560561
sjw = bt->sjw - 1;
561562
tseg1 = bt->prop_seg + bt->phase_seg1 - 1;
562-
tseg2 = bt->phase_seg2 - 1;
563+
tseg2 = bt->phase_seg2 - 2;
563564
writel((tseg2 << IFI_CANFD_TIME_TIMEB_OFF) |
564565
(tseg1 << IFI_CANFD_TIME_TIMEA_OFF) |
565566
(brp << IFI_CANFD_TIME_PRESCALE_OFF) |
566-
(sjw << time_off),
567+
(sjw << time_off) |
568+
noniso_arg,
567569
priv->base + IFI_CANFD_TIME);
568570

569571
/* Configure data bit timing */
570-
brp = dbt->brp - 1;
572+
brp = dbt->brp - 2;
571573
sjw = dbt->sjw - 1;
572574
tseg1 = dbt->prop_seg + dbt->phase_seg1 - 1;
573-
tseg2 = dbt->phase_seg2 - 1;
575+
tseg2 = dbt->phase_seg2 - 2;
574576
writel((tseg2 << IFI_CANFD_TIME_TIMEB_OFF) |
575577
(tseg1 << IFI_CANFD_TIME_TIMEA_OFF) |
576578
(brp << IFI_CANFD_TIME_PRESCALE_OFF) |
@@ -847,7 +849,7 @@ static int ifi_canfd_plat_probe(struct platform_device *pdev)
847849

848850
priv->can.state = CAN_STATE_STOPPED;
849851

850-
priv->can.clock.freq = readl(addr + IFI_CANFD_SYSCLOCK);
852+
priv->can.clock.freq = readl(addr + IFI_CANFD_CANCLOCK);
851853

852854
priv->can.bittiming_const = &ifi_canfd_bittiming_const;
853855
priv->can.data_bittiming_const = &ifi_canfd_data_bittiming_const;

0 commit comments

Comments
 (0)