Skip to content

Commit 4f72e5f

Browse files
grandwolfdavem330
authored andcommitted
flexcan: disable bus error interrupts for the i.MX28
Due to a bug in most Flexcan cores, the bus error interrupt needs to be enabled. Otherwise we don't get any error warning or passive interrupts. This is _not_ necessary for the i.MX28 and this patch disables bus error interrupts if "berr-reporting" is not requested. This avoids bus error flooding, which might harm, especially on low-end systems. To handle such quirks of the Flexcan cores, a hardware feature flag has been introduced, also replacing the "hw_ver" variable. So far nobody could tell what Flexcan core version is available on what Freescale SOC, apart from the i.MX6Q and P1010, and which bugs or features are present on the various "hw_rev". CC: Hui Wang <[email protected]> CC: Shawn Guo <[email protected]> Signed-off-by: Wolfgang Grandegger <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f674e72 commit 4f72e5f

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

drivers/net/can/flexcan.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@
144144

145145
#define FLEXCAN_MB_CODE_MASK (0xf0ffffff)
146146

147+
/* FLEXCAN hardware feature flags */
148+
#define FLEXCAN_HAS_V10_FEATURES BIT(1) /* For core version >= 10 */
149+
#define FLEXCAN_HAS_BROKEN_ERR_STATE BIT(2) /* Broken error state handling */
150+
147151
/* Structure of the message buffer */
148152
struct flexcan_mb {
149153
u32 can_ctrl;
@@ -178,7 +182,7 @@ struct flexcan_regs {
178182
};
179183

180184
struct flexcan_devtype_data {
181-
u32 hw_ver; /* hardware controller version */
185+
u32 features; /* hardware controller features */
182186
};
183187

184188
struct flexcan_priv {
@@ -197,11 +201,11 @@ struct flexcan_priv {
197201
};
198202

199203
static struct flexcan_devtype_data fsl_p1010_devtype_data = {
200-
.hw_ver = 3,
204+
.features = FLEXCAN_HAS_BROKEN_ERR_STATE,
201205
};
202-
206+
static struct flexcan_devtype_data fsl_imx28_devtype_data;
203207
static struct flexcan_devtype_data fsl_imx6q_devtype_data = {
204-
.hw_ver = 10,
208+
.features = FLEXCAN_HAS_V10_FEATURES | FLEXCAN_HAS_BROKEN_ERR_STATE,
205209
};
206210

207211
static const struct can_bittiming_const flexcan_bittiming_const = {
@@ -741,15 +745,19 @@ static int flexcan_chip_start(struct net_device *dev)
741745
* enable tx and rx warning interrupt
742746
* enable bus off interrupt
743747
* (== FLEXCAN_CTRL_ERR_STATE)
744-
*
745-
* _note_: we enable the "error interrupt"
746-
* (FLEXCAN_CTRL_ERR_MSK), too. Otherwise we don't get any
747-
* warning or bus passive interrupts.
748748
*/
749749
reg_ctrl = flexcan_read(&regs->ctrl);
750750
reg_ctrl &= ~FLEXCAN_CTRL_TSYN;
751751
reg_ctrl |= FLEXCAN_CTRL_BOFF_REC | FLEXCAN_CTRL_LBUF |
752-
FLEXCAN_CTRL_ERR_STATE | FLEXCAN_CTRL_ERR_MSK;
752+
FLEXCAN_CTRL_ERR_STATE;
753+
/*
754+
* enable the "error interrupt" (FLEXCAN_CTRL_ERR_MSK),
755+
* on most Flexcan cores, too. Otherwise we don't get
756+
* any error warning or passive interrupts.
757+
*/
758+
if (priv->devtype_data->features & FLEXCAN_HAS_BROKEN_ERR_STATE ||
759+
priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
760+
reg_ctrl |= FLEXCAN_CTRL_ERR_MSK;
753761

754762
/* save for later use */
755763
priv->reg_ctrl_default = reg_ctrl;
@@ -772,7 +780,7 @@ static int flexcan_chip_start(struct net_device *dev)
772780
flexcan_write(0x0, &regs->rx14mask);
773781
flexcan_write(0x0, &regs->rx15mask);
774782

775-
if (priv->devtype_data->hw_ver >= 10)
783+
if (priv->devtype_data->features & FLEXCAN_HAS_V10_FEATURES)
776784
flexcan_write(0x0, &regs->rxfgmask);
777785

778786
flexcan_transceiver_switch(priv, 1);
@@ -954,6 +962,7 @@ static void __devexit unregister_flexcandev(struct net_device *dev)
954962

955963
static const struct of_device_id flexcan_of_match[] = {
956964
{ .compatible = "fsl,p1010-flexcan", .data = &fsl_p1010_devtype_data, },
965+
{ .compatible = "fsl,imx28-flexcan", .data = &fsl_imx28_devtype_data, },
957966
{ .compatible = "fsl,imx6q-flexcan", .data = &fsl_imx6q_devtype_data, },
958967
{ /* sentinel */ },
959968
};

0 commit comments

Comments
 (0)