Skip to content

Commit 8d93022

Browse files
geertumarckleinebudde
authored andcommitted
can: rcar_can: BCR bitfield conversion
Convert CAN Bit Configuration Register field accesses to use the FIELD_PREP() bitfield access macro. While at it, fix the misspelling of BRP. This gets rid of custom function-like field preparation macros. Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be> Reviewed-by: Biju Das <biju.das.jz@bp.renesas.com> Link: https://patch.msgid.link/01cfaedba2be22515ba8700893ea7f113df959c0.1755857536.git.geert+renesas@glider.be Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent 75f3194 commit 8d93022

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

drivers/net/can/rcar/rcar_can.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,10 +152,10 @@ static const struct can_bittiming_const rcar_can_bittiming_const = {
152152
#define RCAR_CAN_N_RX_MKREGS2 8
153153

154154
/* Bit Configuration Register settings */
155-
#define RCAR_CAN_BCR_TSEG1(x) (((x) & 0x0f) << 20)
156-
#define RCAR_CAN_BCR_BPR(x) (((x) & 0x3ff) << 8)
157-
#define RCAR_CAN_BCR_SJW(x) (((x) & 0x3) << 4)
158-
#define RCAR_CAN_BCR_TSEG2(x) ((x) & 0x07)
155+
#define RCAR_CAN_BCR_TSEG1 GENMASK(23, 20)
156+
#define RCAR_CAN_BCR_BRP GENMASK(17, 8)
157+
#define RCAR_CAN_BCR_SJW GENMASK(5, 4)
158+
#define RCAR_CAN_BCR_TSEG2 GENMASK(2, 0)
159159

160160
/* Mailbox and Mask Registers bits */
161161
#define RCAR_CAN_IDE BIT(31) /* ID Extension */
@@ -428,9 +428,10 @@ static void rcar_can_set_bittiming(struct net_device *ndev)
428428
struct can_bittiming *bt = &priv->can.bittiming;
429429
u32 bcr;
430430

431-
bcr = RCAR_CAN_BCR_TSEG1(bt->phase_seg1 + bt->prop_seg - 1) |
432-
RCAR_CAN_BCR_BPR(bt->brp - 1) | RCAR_CAN_BCR_SJW(bt->sjw - 1) |
433-
RCAR_CAN_BCR_TSEG2(bt->phase_seg2 - 1);
431+
bcr = FIELD_PREP(RCAR_CAN_BCR_TSEG1, bt->phase_seg1 + bt->prop_seg - 1) |
432+
FIELD_PREP(RCAR_CAN_BCR_BRP, bt->brp - 1) |
433+
FIELD_PREP(RCAR_CAN_BCR_SJW, bt->sjw - 1) |
434+
FIELD_PREP(RCAR_CAN_BCR_TSEG2, bt->phase_seg2 - 1);
434435
/* Don't overwrite CLKR with 32-bit BCR access; CLKR has 8-bit access.
435436
* All the registers are big-endian but they get byte-swapped on 32-bit
436437
* read/write (but not on 8-bit, contrary to the manuals)...

0 commit comments

Comments
 (0)