blob: 0f36eafe3ac16d5ba55432608acfd12eee0dd8e0 [file] [log] [blame]
Fabio Estevam5b749be2018-07-06 14:35:12 -03001// SPDX-License-Identifier: GPL-2.0
2//
3// flexcan.c - FLEXCAN CAN controller driver
4//
5// Copyright (c) 2005-2006 Varma Electronics Oy
6// Copyright (c) 2009 Sascha Hauer, Pengutronix
7// Copyright (c) 2010-2017 Pengutronix, Marc Kleine-Budde <kernel@pengutronix.de>
8// Copyright (c) 2014 David Jander, Protonic Holland
9//
10// Based on code originally by Andrey Volkov <avolkov@varma-el.com>
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020011
12#include <linux/netdevice.h>
13#include <linux/can.h>
14#include <linux/can/dev.h>
15#include <linux/can/error.h>
Fabio Baltieriadccadb2012-12-18 18:50:58 +010016#include <linux/can/led.h>
Marc Kleine-Budde30164752015-05-10 15:26:58 +020017#include <linux/can/rx-offload.h>
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020018#include <linux/clk.h>
19#include <linux/delay.h>
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020020#include <linux/interrupt.h>
21#include <linux/io.h>
Aisheng Dongde3578c2018-11-23 08:35:33 +000022#include <linux/mfd/syscon.h>
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020023#include <linux/module.h>
holt@sgi.com97efe9a2011-08-16 17:32:23 +000024#include <linux/of.h>
Hui Wang30c1e672012-06-28 16:21:35 +080025#include <linux/of_device.h>
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020026#include <linux/platform_device.h>
Fabio Estevamb7c41142013-06-10 23:12:57 -030027#include <linux/regulator/consumer.h>
Aisheng Dongde3578c2018-11-23 08:35:33 +000028#include <linux/regmap.h>
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020029
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020030#define DRV_NAME "flexcan"
31
32/* 8 for RX fifo and 2 error handling */
33#define FLEXCAN_NAPI_WEIGHT (8 + 2)
34
35/* FLEXCAN module configuration register (CANMCR) bits */
36#define FLEXCAN_MCR_MDIS BIT(31)
37#define FLEXCAN_MCR_FRZ BIT(30)
38#define FLEXCAN_MCR_FEN BIT(29)
39#define FLEXCAN_MCR_HALT BIT(28)
40#define FLEXCAN_MCR_NOT_RDY BIT(27)
41#define FLEXCAN_MCR_WAK_MSK BIT(26)
42#define FLEXCAN_MCR_SOFTRST BIT(25)
43#define FLEXCAN_MCR_FRZ_ACK BIT(24)
44#define FLEXCAN_MCR_SUPV BIT(23)
45#define FLEXCAN_MCR_SLF_WAK BIT(22)
46#define FLEXCAN_MCR_WRN_EN BIT(21)
47#define FLEXCAN_MCR_LPM_ACK BIT(20)
48#define FLEXCAN_MCR_WAK_SRC BIT(19)
49#define FLEXCAN_MCR_DOZE BIT(18)
50#define FLEXCAN_MCR_SRX_DIS BIT(17)
Marc Kleine-Budde62d10862015-08-27 16:01:27 +020051#define FLEXCAN_MCR_IRMQ BIT(16)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020052#define FLEXCAN_MCR_LPRIO_EN BIT(13)
53#define FLEXCAN_MCR_AEN BIT(12)
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +020054/* MCR_MAXMB: maximum used MBs is MAXMB + 1 */
Marc Kleine-Budde4c728d82014-09-02 16:54:17 +020055#define FLEXCAN_MCR_MAXMB(x) ((x) & 0x7f)
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +020056#define FLEXCAN_MCR_IDAM_A (0x0 << 8)
57#define FLEXCAN_MCR_IDAM_B (0x1 << 8)
58#define FLEXCAN_MCR_IDAM_C (0x2 << 8)
59#define FLEXCAN_MCR_IDAM_D (0x3 << 8)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020060
61/* FLEXCAN control register (CANCTRL) bits */
62#define FLEXCAN_CTRL_PRESDIV(x) (((x) & 0xff) << 24)
63#define FLEXCAN_CTRL_RJW(x) (((x) & 0x03) << 22)
64#define FLEXCAN_CTRL_PSEG1(x) (((x) & 0x07) << 19)
65#define FLEXCAN_CTRL_PSEG2(x) (((x) & 0x07) << 16)
66#define FLEXCAN_CTRL_BOFF_MSK BIT(15)
67#define FLEXCAN_CTRL_ERR_MSK BIT(14)
68#define FLEXCAN_CTRL_CLK_SRC BIT(13)
69#define FLEXCAN_CTRL_LPB BIT(12)
70#define FLEXCAN_CTRL_TWRN_MSK BIT(11)
71#define FLEXCAN_CTRL_RWRN_MSK BIT(10)
72#define FLEXCAN_CTRL_SMP BIT(7)
73#define FLEXCAN_CTRL_BOFF_REC BIT(6)
74#define FLEXCAN_CTRL_TSYN BIT(5)
75#define FLEXCAN_CTRL_LBUF BIT(4)
76#define FLEXCAN_CTRL_LOM BIT(3)
77#define FLEXCAN_CTRL_PROPSEG(x) ((x) & 0x07)
78#define FLEXCAN_CTRL_ERR_BUS (FLEXCAN_CTRL_ERR_MSK)
79#define FLEXCAN_CTRL_ERR_STATE \
80 (FLEXCAN_CTRL_TWRN_MSK | FLEXCAN_CTRL_RWRN_MSK | \
81 FLEXCAN_CTRL_BOFF_MSK)
82#define FLEXCAN_CTRL_ERR_ALL \
83 (FLEXCAN_CTRL_ERR_BUS | FLEXCAN_CTRL_ERR_STATE)
84
Stefan Agnercdce8442014-07-15 14:56:21 +020085/* FLEXCAN control register 2 (CTRL2) bits */
Marc Kleine-Budde6f75fce2014-09-23 11:03:01 +020086#define FLEXCAN_CTRL2_ECRWRE BIT(29)
87#define FLEXCAN_CTRL2_WRMFRZ BIT(28)
88#define FLEXCAN_CTRL2_RFFN(x) (((x) & 0x0f) << 24)
89#define FLEXCAN_CTRL2_TASD(x) (((x) & 0x1f) << 19)
90#define FLEXCAN_CTRL2_MRP BIT(18)
91#define FLEXCAN_CTRL2_RRS BIT(17)
92#define FLEXCAN_CTRL2_EACEN BIT(16)
Stefan Agnercdce8442014-07-15 14:56:21 +020093
94/* FLEXCAN memory error control register (MECR) bits */
95#define FLEXCAN_MECR_ECRWRDIS BIT(31)
96#define FLEXCAN_MECR_HANCEI_MSK BIT(19)
97#define FLEXCAN_MECR_FANCEI_MSK BIT(18)
98#define FLEXCAN_MECR_CEI_MSK BIT(16)
99#define FLEXCAN_MECR_HAERRIE BIT(15)
100#define FLEXCAN_MECR_FAERRIE BIT(14)
101#define FLEXCAN_MECR_EXTERRIE BIT(13)
102#define FLEXCAN_MECR_RERRDIS BIT(9)
103#define FLEXCAN_MECR_ECCDIS BIT(8)
104#define FLEXCAN_MECR_NCEFAFRZ BIT(7)
105
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200106/* FLEXCAN error and status register (ESR) bits */
107#define FLEXCAN_ESR_TWRN_INT BIT(17)
108#define FLEXCAN_ESR_RWRN_INT BIT(16)
109#define FLEXCAN_ESR_BIT1_ERR BIT(15)
110#define FLEXCAN_ESR_BIT0_ERR BIT(14)
111#define FLEXCAN_ESR_ACK_ERR BIT(13)
112#define FLEXCAN_ESR_CRC_ERR BIT(12)
113#define FLEXCAN_ESR_FRM_ERR BIT(11)
114#define FLEXCAN_ESR_STF_ERR BIT(10)
115#define FLEXCAN_ESR_TX_WRN BIT(9)
116#define FLEXCAN_ESR_RX_WRN BIT(8)
117#define FLEXCAN_ESR_IDLE BIT(7)
118#define FLEXCAN_ESR_TXRX BIT(6)
119#define FLEXCAN_EST_FLT_CONF_SHIFT (4)
120#define FLEXCAN_ESR_FLT_CONF_MASK (0x3 << FLEXCAN_EST_FLT_CONF_SHIFT)
121#define FLEXCAN_ESR_FLT_CONF_ACTIVE (0x0 << FLEXCAN_EST_FLT_CONF_SHIFT)
122#define FLEXCAN_ESR_FLT_CONF_PASSIVE (0x1 << FLEXCAN_EST_FLT_CONF_SHIFT)
123#define FLEXCAN_ESR_BOFF_INT BIT(2)
124#define FLEXCAN_ESR_ERR_INT BIT(1)
125#define FLEXCAN_ESR_WAK_INT BIT(0)
126#define FLEXCAN_ESR_ERR_BUS \
127 (FLEXCAN_ESR_BIT1_ERR | FLEXCAN_ESR_BIT0_ERR | \
128 FLEXCAN_ESR_ACK_ERR | FLEXCAN_ESR_CRC_ERR | \
129 FLEXCAN_ESR_FRM_ERR | FLEXCAN_ESR_STF_ERR)
130#define FLEXCAN_ESR_ERR_STATE \
131 (FLEXCAN_ESR_TWRN_INT | FLEXCAN_ESR_RWRN_INT | FLEXCAN_ESR_BOFF_INT)
132#define FLEXCAN_ESR_ERR_ALL \
133 (FLEXCAN_ESR_ERR_BUS | FLEXCAN_ESR_ERR_STATE)
Wolfgang Grandegger6e9d5542011-12-12 16:09:28 +0100134#define FLEXCAN_ESR_ALL_INT \
135 (FLEXCAN_ESR_TWRN_INT | FLEXCAN_ESR_RWRN_INT | \
Aisheng Dongde3578c2018-11-23 08:35:33 +0000136 FLEXCAN_ESR_BOFF_INT | FLEXCAN_ESR_ERR_INT | \
137 FLEXCAN_ESR_WAK_INT)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200138
139/* FLEXCAN interrupt flag register (IFLAG) bits */
David Jander25e92442014-09-03 16:47:22 +0200140/* Errata ERR005829 step7: Reserve first valid MB */
Alexander Steincbffaf72018-10-11 17:01:25 +0200141#define FLEXCAN_TX_MB_RESERVED_OFF_FIFO 8
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200142#define FLEXCAN_TX_MB_RESERVED_OFF_TIMESTAMP 0
Alexander Steincbffaf72018-10-11 17:01:25 +0200143#define FLEXCAN_RX_MB_OFF_TIMESTAMP_FIRST (FLEXCAN_TX_MB_RESERVED_OFF_TIMESTAMP + 1)
Marc Kleine-Budde22233f72018-11-28 15:31:37 +0100144#define FLEXCAN_IFLAG_MB(x) BIT((x) & 0x1f)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200145#define FLEXCAN_IFLAG_RX_FIFO_OVERFLOW BIT(7)
146#define FLEXCAN_IFLAG_RX_FIFO_WARN BIT(6)
147#define FLEXCAN_IFLAG_RX_FIFO_AVAILABLE BIT(5)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200148
149/* FLEXCAN message buffers */
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200150#define FLEXCAN_MB_CODE_MASK (0xf << 24)
151#define FLEXCAN_MB_CODE_RX_BUSY_BIT (0x1 << 24)
Marc Kleine-Buddec32fe4a2014-09-16 12:39:28 +0200152#define FLEXCAN_MB_CODE_RX_INACTIVE (0x0 << 24)
153#define FLEXCAN_MB_CODE_RX_EMPTY (0x4 << 24)
154#define FLEXCAN_MB_CODE_RX_FULL (0x2 << 24)
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200155#define FLEXCAN_MB_CODE_RX_OVERRUN (0x6 << 24)
Marc Kleine-Buddec32fe4a2014-09-16 12:39:28 +0200156#define FLEXCAN_MB_CODE_RX_RANSWER (0xa << 24)
157
158#define FLEXCAN_MB_CODE_TX_INACTIVE (0x8 << 24)
159#define FLEXCAN_MB_CODE_TX_ABORT (0x9 << 24)
160#define FLEXCAN_MB_CODE_TX_DATA (0xc << 24)
161#define FLEXCAN_MB_CODE_TX_TANSWER (0xe << 24)
162
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200163#define FLEXCAN_MB_CNT_SRR BIT(22)
164#define FLEXCAN_MB_CNT_IDE BIT(21)
165#define FLEXCAN_MB_CNT_RTR BIT(20)
166#define FLEXCAN_MB_CNT_LENGTH(x) (((x) & 0xf) << 16)
167#define FLEXCAN_MB_CNT_TIMESTAMP(x) ((x) & 0xffff)
168
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200169#define FLEXCAN_TIMEOUT_US (50)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200170
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200171/* FLEXCAN hardware feature flags
Wolfgang Grandeggerbb698ca2012-10-10 21:10:42 +0200172 *
173 * Below is some version info we got:
ZHU Yi (ST-FIR/ENG1-Zhu)da49a802017-09-15 07:03:58 +0000174 * SOC Version IP-Version Glitch- [TR]WRN_INT IRQ Err Memory err RTR re-
175 * Filter? connected? Passive detection ception in MB
Marc Kleine-Budde658f5342017-11-22 13:01:08 +0100176 * MX25 FlexCAN2 03.00.00.00 no no no no no
ZHU Yi (ST-FIR/ENG1-Zhu)da49a802017-09-15 07:03:58 +0000177 * MX28 FlexCAN2 03.00.04.00 yes yes no no no
Marc Kleine-Budde658f5342017-11-22 13:01:08 +0100178 * MX35 FlexCAN2 03.00.00.00 no no no no no
ZHU Yi (ST-FIR/ENG1-Zhu)da49a802017-09-15 07:03:58 +0000179 * MX53 FlexCAN2 03.00.00.00 yes no no no no
180 * MX6s FlexCAN3 10.00.12.00 yes yes no no yes
Marc Kleine-Budde29c64b12017-11-27 09:18:21 +0100181 * VF610 FlexCAN3 ? no yes no yes yes?
Pankaj Bansal99b76682017-11-24 18:52:09 +0530182 * LS1021A FlexCAN2 03.00.04.00 no yes no no yes
Wolfgang Grandeggerbb698ca2012-10-10 21:10:42 +0200183 *
184 * Some SOCs do not have the RX_WARN & TX_WARN interrupt line connected.
185 */
ZHU Yi (ST-FIR/ENG1-Zhu)2f8639b2017-09-15 07:01:23 +0000186#define FLEXCAN_QUIRK_BROKEN_WERR_STATE BIT(1) /* [TR]WRN_INT not connected */
Marc Kleine-Buddef377bff2015-05-08 15:22:36 +0200187#define FLEXCAN_QUIRK_DISABLE_RXFG BIT(2) /* Disable RX FIFO Global mask */
Marc Kleine-Budde9eb7aa82015-09-01 08:57:55 +0200188#define FLEXCAN_QUIRK_ENABLE_EACEN_RRS BIT(3) /* Enable EACEN and RRS bit in ctrl2 */
Marc Kleine-Budde66ddb822017-03-02 15:42:49 +0100189#define FLEXCAN_QUIRK_DISABLE_MECR BIT(4) /* Disable Memory error detection */
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200190#define FLEXCAN_QUIRK_USE_OFF_TIMESTAMP BIT(5) /* Use timestamp based offloading */
ZHU Yi (ST-FIR/ENG1-Zhu)da49a802017-09-15 07:03:58 +0000191#define FLEXCAN_QUIRK_BROKEN_PERR_STATE BIT(6) /* No interrupt for error passive */
Uwe Kleine-König0e030a32018-04-25 16:50:39 +0200192#define FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN BIT(7) /* default to BE register access */
Aisheng Dongde3578c2018-11-23 08:35:33 +0000193#define FLEXCAN_QUIRK_SETUP_STOP_MODE BIT(8) /* Setup stop mode to support wakeup */
Wolfgang Grandegger4f72e5f2012-09-28 03:17:15 +0000194
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200195/* Structure of the message buffer */
196struct flexcan_mb {
197 u32 can_ctrl;
198 u32 can_id;
Pankaj Bansal05179612018-11-23 22:18:44 +0100199 u32 data[];
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200200};
201
202/* Structure of the hardware registers */
203struct flexcan_regs {
204 u32 mcr; /* 0x00 */
205 u32 ctrl; /* 0x04 */
206 u32 timer; /* 0x08 */
207 u32 _reserved1; /* 0x0c */
208 u32 rxgmask; /* 0x10 */
209 u32 rx14mask; /* 0x14 */
210 u32 rx15mask; /* 0x18 */
211 u32 ecr; /* 0x1c */
212 u32 esr; /* 0x20 */
213 u32 imask2; /* 0x24 */
214 u32 imask1; /* 0x28 */
215 u32 iflag2; /* 0x2c */
216 u32 iflag1; /* 0x30 */
Marc Kleine-Budde62d10862015-08-27 16:01:27 +0200217 union { /* 0x34 */
218 u32 gfwr_mx28; /* MX28, MX53 */
219 u32 ctrl2; /* MX6, VF610 */
220 };
Hui Wang30c1e672012-06-28 16:21:35 +0800221 u32 esr2; /* 0x38 */
222 u32 imeur; /* 0x3c */
223 u32 lrfr; /* 0x40 */
224 u32 crcr; /* 0x44 */
225 u32 rxfgmask; /* 0x48 */
226 u32 rxfir; /* 0x4c */
Stefan Agnercdce8442014-07-15 14:56:21 +0200227 u32 _reserved3[12]; /* 0x50 */
Pankaj Bansal6cbf7602018-08-28 23:19:12 +0530228 u8 mb[2][512]; /* 0x80 */
Marc Kleine-Budde66a6ef02014-09-17 12:50:48 +0200229 /* FIFO-mode:
230 * MB
231 * 0x080...0x08f 0 RX message buffer
232 * 0x090...0x0df 1-5 reserverd
233 * 0x0e0...0x0ff 6-7 8 entry ID table
234 * (mx25, mx28, mx35, mx53)
235 * 0x0e0...0x2df 6-7..37 8..128 entry ID table
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200236 * size conf'ed via ctrl2::RFFN
Marc Kleine-Budde66a6ef02014-09-17 12:50:48 +0200237 * (mx6, vf610)
238 */
Marc Kleine-Budde62d10862015-08-27 16:01:27 +0200239 u32 _reserved4[256]; /* 0x480 */
240 u32 rximr[64]; /* 0x880 */
241 u32 _reserved5[24]; /* 0x980 */
242 u32 gfwr_mx6; /* 0x9e0 - MX6 */
243 u32 _reserved6[63]; /* 0x9e4 */
Stefan Agnercdce8442014-07-15 14:56:21 +0200244 u32 mecr; /* 0xae0 */
245 u32 erriar; /* 0xae4 */
246 u32 erridpr; /* 0xae8 */
247 u32 errippr; /* 0xaec */
248 u32 rerrar; /* 0xaf0 */
249 u32 rerrdr; /* 0xaf4 */
250 u32 rerrsynr; /* 0xaf8 */
251 u32 errsr; /* 0xafc */
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200252};
253
Hui Wang30c1e672012-06-28 16:21:35 +0800254struct flexcan_devtype_data {
Marc Kleine-Buddef377bff2015-05-08 15:22:36 +0200255 u32 quirks; /* quirks needed for different IP cores */
Hui Wang30c1e672012-06-28 16:21:35 +0800256};
257
Aisheng Dongde3578c2018-11-23 08:35:33 +0000258struct flexcan_stop_mode {
259 struct regmap *gpr;
260 u8 req_gpr;
261 u8 req_bit;
262 u8 ack_gpr;
263 u8 ack_bit;
264};
265
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200266struct flexcan_priv {
267 struct can_priv can;
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200268 struct can_rx_offload offload;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200269
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200270 struct flexcan_regs __iomem *regs;
Pankaj Bansal05179612018-11-23 22:18:44 +0100271 struct flexcan_mb __iomem *tx_mb;
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +0200272 struct flexcan_mb __iomem *tx_mb_reserved;
Pankaj Bansal05179612018-11-23 22:18:44 +0100273 u8 tx_mb_idx;
274 u8 mb_count;
275 u8 mb_size;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200276 u32 reg_ctrl_default;
Marc Kleine-Budde28ac7dc2015-08-04 13:46:10 +0200277 u32 reg_imask1_default;
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200278 u32 reg_imask2_default;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200279
Steffen Trumtrar3d42a372012-07-17 16:14:34 +0200280 struct clk *clk_ipg;
281 struct clk *clk_per;
Marc Kleine-Buddedda0b3b2012-07-13 14:52:48 +0200282 const struct flexcan_devtype_data *devtype_data;
Fabio Estevamb7c41142013-06-10 23:12:57 -0300283 struct regulator *reg_xceiver;
Aisheng Dongde3578c2018-11-23 08:35:33 +0000284 struct flexcan_stop_mode stm;
Pankaj Bansal88462d22017-11-24 18:52:08 +0530285
286 /* Read and Write APIs */
287 u32 (*read)(void __iomem *addr);
288 void (*write)(u32 val, void __iomem *addr);
Hui Wang30c1e672012-06-28 16:21:35 +0800289};
290
Marc Kleine-Buddea3c11a72016-07-04 14:45:44 +0200291static const struct flexcan_devtype_data fsl_p1010_devtype_data = {
ZHU Yi (ST-FIR/ENG1-Zhu)fb5b91d62017-09-15 07:09:37 +0000292 .quirks = FLEXCAN_QUIRK_BROKEN_WERR_STATE |
Uwe Kleine-König0e030a32018-04-25 16:50:39 +0200293 FLEXCAN_QUIRK_BROKEN_PERR_STATE |
294 FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN,
295};
296
297static const struct flexcan_devtype_data fsl_imx25_devtype_data = {
298 .quirks = FLEXCAN_QUIRK_BROKEN_WERR_STATE |
ZHU Yi (ST-FIR/ENG1-Zhu)fb5b91d62017-09-15 07:09:37 +0000299 FLEXCAN_QUIRK_BROKEN_PERR_STATE,
Hui Wang30c1e672012-06-28 16:21:35 +0800300};
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200301
ZHU Yi (ST-FIR/ENG1-Zhu)083c5572017-09-15 07:08:23 +0000302static const struct flexcan_devtype_data fsl_imx28_devtype_data = {
303 .quirks = FLEXCAN_QUIRK_BROKEN_PERR_STATE,
304};
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200305
Marc Kleine-Buddea3c11a72016-07-04 14:45:44 +0200306static const struct flexcan_devtype_data fsl_imx6q_devtype_data = {
Marc Kleine-Budde096de072015-09-01 10:28:46 +0200307 .quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
Aisheng Dongde3578c2018-11-23 08:35:33 +0000308 FLEXCAN_QUIRK_USE_OFF_TIMESTAMP | FLEXCAN_QUIRK_BROKEN_PERR_STATE |
309 FLEXCAN_QUIRK_SETUP_STOP_MODE,
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200310};
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200311
Marc Kleine-Buddea3c11a72016-07-04 14:45:44 +0200312static const struct flexcan_devtype_data fsl_vf610_devtype_data = {
Marc Kleine-Budde9eb7aa82015-09-01 08:57:55 +0200313 .quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
Marc Kleine-Budde29c64b12017-11-27 09:18:21 +0100314 FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_USE_OFF_TIMESTAMP |
315 FLEXCAN_QUIRK_BROKEN_PERR_STATE,
Stefan Agnercdce8442014-07-15 14:56:21 +0200316};
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200317
Pankaj Bansal99b76682017-11-24 18:52:09 +0530318static const struct flexcan_devtype_data fsl_ls1021a_r2_devtype_data = {
319 .quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
320 FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_BROKEN_PERR_STATE |
321 FLEXCAN_QUIRK_USE_OFF_TIMESTAMP,
322};
323
Marc Kleine-Budde194b9a42012-07-16 12:58:31 +0200324static const struct can_bittiming_const flexcan_bittiming_const = {
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200325 .name = DRV_NAME,
326 .tseg1_min = 4,
327 .tseg1_max = 16,
328 .tseg2_min = 2,
329 .tseg2_max = 8,
330 .sjw_max = 4,
331 .brp_min = 1,
332 .brp_max = 256,
333 .brp_inc = 1,
334};
335
Pankaj Bansal88462d22017-11-24 18:52:08 +0530336/* FlexCAN module is essentially modelled as a little-endian IP in most
337 * SoCs, i.e the registers as well as the message buffer areas are
338 * implemented in a little-endian fashion.
339 *
340 * However there are some SoCs (e.g. LS1021A) which implement the FlexCAN
341 * module in a big-endian fashion (i.e the registers as well as the
342 * message buffer areas are implemented in a big-endian way).
343 *
344 * In addition, the FlexCAN module can be found on SoCs having ARM or
345 * PPC cores. So, we need to abstract off the register read/write
346 * functions, ensuring that these cater to all the combinations of module
347 * endianness and underlying CPU endianness.
holt@sgi.com61e271e2011-08-16 17:32:20 +0000348 */
Pankaj Bansal88462d22017-11-24 18:52:08 +0530349static inline u32 flexcan_read_be(void __iomem *addr)
holt@sgi.com61e271e2011-08-16 17:32:20 +0000350{
Pankaj Bansal88462d22017-11-24 18:52:08 +0530351 return ioread32be(addr);
holt@sgi.com61e271e2011-08-16 17:32:20 +0000352}
353
Pankaj Bansal88462d22017-11-24 18:52:08 +0530354static inline void flexcan_write_be(u32 val, void __iomem *addr)
holt@sgi.com61e271e2011-08-16 17:32:20 +0000355{
Pankaj Bansal88462d22017-11-24 18:52:08 +0530356 iowrite32be(val, addr);
holt@sgi.com61e271e2011-08-16 17:32:20 +0000357}
358
Pankaj Bansal88462d22017-11-24 18:52:08 +0530359static inline u32 flexcan_read_le(void __iomem *addr)
holt@sgi.com61e271e2011-08-16 17:32:20 +0000360{
Pankaj Bansal88462d22017-11-24 18:52:08 +0530361 return ioread32(addr);
holt@sgi.com61e271e2011-08-16 17:32:20 +0000362}
Pankaj Bansal88462d22017-11-24 18:52:08 +0530363
364static inline void flexcan_write_le(u32 val, void __iomem *addr)
365{
366 iowrite32(val, addr);
367}
holt@sgi.com61e271e2011-08-16 17:32:20 +0000368
Pankaj Bansal05179612018-11-23 22:18:44 +0100369static struct flexcan_mb __iomem *flexcan_get_mb(const struct flexcan_priv *priv,
370 u8 mb_index)
371{
Pankaj Bansal6cbf7602018-08-28 23:19:12 +0530372 u8 bank_size;
373 bool bank;
374
Pankaj Bansal05179612018-11-23 22:18:44 +0100375 if (WARN_ON(mb_index >= priv->mb_count))
376 return NULL;
377
Pankaj Bansal6cbf7602018-08-28 23:19:12 +0530378 bank_size = sizeof(priv->regs->mb[0]) / priv->mb_size;
379
380 bank = mb_index >= bank_size;
381 if (bank)
382 mb_index -= bank_size;
383
Pankaj Bansal05179612018-11-23 22:18:44 +0100384 return (struct flexcan_mb __iomem *)
Pankaj Bansal6cbf7602018-08-28 23:19:12 +0530385 (&priv->regs->mb[bank][priv->mb_size * mb_index]);
Pankaj Bansal05179612018-11-23 22:18:44 +0100386}
387
Aisheng Dongde3578c2018-11-23 08:35:33 +0000388static void flexcan_enable_wakeup_irq(struct flexcan_priv *priv, bool enable)
389{
390 struct flexcan_regs __iomem *regs = priv->regs;
391 u32 reg_mcr;
392
393 reg_mcr = priv->read(&regs->mcr);
394
395 if (enable)
396 reg_mcr |= FLEXCAN_MCR_WAK_MSK;
397 else
398 reg_mcr &= ~FLEXCAN_MCR_WAK_MSK;
399
400 priv->write(reg_mcr, &regs->mcr);
401}
402
403static inline void flexcan_enter_stop_mode(struct flexcan_priv *priv)
404{
405 struct flexcan_regs __iomem *regs = priv->regs;
406 u32 reg_mcr;
407
408 reg_mcr = priv->read(&regs->mcr);
409 reg_mcr |= FLEXCAN_MCR_SLF_WAK;
410 priv->write(reg_mcr, &regs->mcr);
411
412 /* enable stop request */
413 regmap_update_bits(priv->stm.gpr, priv->stm.req_gpr,
414 1 << priv->stm.req_bit, 1 << priv->stm.req_bit);
415}
416
417static inline void flexcan_exit_stop_mode(struct flexcan_priv *priv)
418{
419 struct flexcan_regs __iomem *regs = priv->regs;
420 u32 reg_mcr;
421
422 /* remove stop request */
423 regmap_update_bits(priv->stm.gpr, priv->stm.req_gpr,
424 1 << priv->stm.req_bit, 0);
425
426 reg_mcr = priv->read(&regs->mcr);
427 reg_mcr &= ~FLEXCAN_MCR_SLF_WAK;
428 priv->write(reg_mcr, &regs->mcr);
429}
430
ZHU Yi (ST-FIR/ENG1-Zhu)da49a802017-09-15 07:03:58 +0000431static inline void flexcan_error_irq_enable(const struct flexcan_priv *priv)
432{
433 struct flexcan_regs __iomem *regs = priv->regs;
434 u32 reg_ctrl = (priv->reg_ctrl_default | FLEXCAN_CTRL_ERR_MSK);
435
Pankaj Bansal88462d22017-11-24 18:52:08 +0530436 priv->write(reg_ctrl, &regs->ctrl);
ZHU Yi (ST-FIR/ENG1-Zhu)da49a802017-09-15 07:03:58 +0000437}
438
439static inline void flexcan_error_irq_disable(const struct flexcan_priv *priv)
440{
441 struct flexcan_regs __iomem *regs = priv->regs;
442 u32 reg_ctrl = (priv->reg_ctrl_default & ~FLEXCAN_CTRL_ERR_MSK);
443
Pankaj Bansal88462d22017-11-24 18:52:08 +0530444 priv->write(reg_ctrl, &regs->ctrl);
ZHU Yi (ST-FIR/ENG1-Zhu)da49a802017-09-15 07:03:58 +0000445}
446
Marc Kleine-Buddef0036982014-02-28 17:18:27 +0100447static inline int flexcan_transceiver_enable(const struct flexcan_priv *priv)
448{
449 if (!priv->reg_xceiver)
450 return 0;
451
452 return regulator_enable(priv->reg_xceiver);
453}
454
455static inline int flexcan_transceiver_disable(const struct flexcan_priv *priv)
456{
457 if (!priv->reg_xceiver)
458 return 0;
459
460 return regulator_disable(priv->reg_xceiver);
461}
462
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100463static int flexcan_chip_enable(struct flexcan_priv *priv)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200464{
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200465 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100466 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200467 u32 reg;
468
Pankaj Bansal88462d22017-11-24 18:52:08 +0530469 reg = priv->read(&regs->mcr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200470 reg &= ~FLEXCAN_MCR_MDIS;
Pankaj Bansal88462d22017-11-24 18:52:08 +0530471 priv->write(reg, &regs->mcr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200472
Pankaj Bansal88462d22017-11-24 18:52:08 +0530473 while (timeout-- && (priv->read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK))
David Jander8badd652014-08-27 12:02:16 +0200474 udelay(10);
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100475
Pankaj Bansal88462d22017-11-24 18:52:08 +0530476 if (priv->read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK)
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100477 return -ETIMEDOUT;
478
479 return 0;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200480}
481
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100482static int flexcan_chip_disable(struct flexcan_priv *priv)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200483{
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200484 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100485 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200486 u32 reg;
487
Pankaj Bansal88462d22017-11-24 18:52:08 +0530488 reg = priv->read(&regs->mcr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200489 reg |= FLEXCAN_MCR_MDIS;
Pankaj Bansal88462d22017-11-24 18:52:08 +0530490 priv->write(reg, &regs->mcr);
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100491
Pankaj Bansal88462d22017-11-24 18:52:08 +0530492 while (timeout-- && !(priv->read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK))
David Jander8badd652014-08-27 12:02:16 +0200493 udelay(10);
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100494
Pankaj Bansal88462d22017-11-24 18:52:08 +0530495 if (!(priv->read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK))
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100496 return -ETIMEDOUT;
497
498 return 0;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200499}
500
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100501static int flexcan_chip_freeze(struct flexcan_priv *priv)
502{
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200503 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100504 unsigned int timeout = 1000 * 1000 * 10 / priv->can.bittiming.bitrate;
505 u32 reg;
506
Pankaj Bansal88462d22017-11-24 18:52:08 +0530507 reg = priv->read(&regs->mcr);
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100508 reg |= FLEXCAN_MCR_HALT;
Pankaj Bansal88462d22017-11-24 18:52:08 +0530509 priv->write(reg, &regs->mcr);
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100510
Pankaj Bansal88462d22017-11-24 18:52:08 +0530511 while (timeout-- && !(priv->read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
David Jander8badd652014-08-27 12:02:16 +0200512 udelay(100);
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100513
Pankaj Bansal88462d22017-11-24 18:52:08 +0530514 if (!(priv->read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100515 return -ETIMEDOUT;
516
517 return 0;
518}
519
520static int flexcan_chip_unfreeze(struct flexcan_priv *priv)
521{
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200522 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100523 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
524 u32 reg;
525
Pankaj Bansal88462d22017-11-24 18:52:08 +0530526 reg = priv->read(&regs->mcr);
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100527 reg &= ~FLEXCAN_MCR_HALT;
Pankaj Bansal88462d22017-11-24 18:52:08 +0530528 priv->write(reg, &regs->mcr);
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100529
Pankaj Bansal88462d22017-11-24 18:52:08 +0530530 while (timeout-- && (priv->read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
David Jander8badd652014-08-27 12:02:16 +0200531 udelay(10);
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100532
Pankaj Bansal88462d22017-11-24 18:52:08 +0530533 if (priv->read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK)
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100534 return -ETIMEDOUT;
535
536 return 0;
537}
538
Marc Kleine-Budde4b5b8222014-02-28 15:16:59 +0100539static int flexcan_chip_softreset(struct flexcan_priv *priv)
540{
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200541 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Budde4b5b8222014-02-28 15:16:59 +0100542 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
543
Pankaj Bansal88462d22017-11-24 18:52:08 +0530544 priv->write(FLEXCAN_MCR_SOFTRST, &regs->mcr);
545 while (timeout-- && (priv->read(&regs->mcr) & FLEXCAN_MCR_SOFTRST))
David Jander8badd652014-08-27 12:02:16 +0200546 udelay(10);
Marc Kleine-Budde4b5b8222014-02-28 15:16:59 +0100547
Pankaj Bansal88462d22017-11-24 18:52:08 +0530548 if (priv->read(&regs->mcr) & FLEXCAN_MCR_SOFTRST)
Marc Kleine-Budde4b5b8222014-02-28 15:16:59 +0100549 return -ETIMEDOUT;
550
551 return 0;
552}
553
Stefan Agnerec56acf2014-07-15 14:56:20 +0200554static int __flexcan_get_berr_counter(const struct net_device *dev,
555 struct can_berr_counter *bec)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200556{
557 const struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200558 struct flexcan_regs __iomem *regs = priv->regs;
Pankaj Bansal88462d22017-11-24 18:52:08 +0530559 u32 reg = priv->read(&regs->ecr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200560
561 bec->txerr = (reg >> 0) & 0xff;
562 bec->rxerr = (reg >> 8) & 0xff;
563
564 return 0;
565}
566
Stefan Agnerec56acf2014-07-15 14:56:20 +0200567static int flexcan_get_berr_counter(const struct net_device *dev,
568 struct can_berr_counter *bec)
569{
570 const struct flexcan_priv *priv = netdev_priv(dev);
571 int err;
572
573 err = clk_prepare_enable(priv->clk_ipg);
574 if (err)
575 return err;
576
577 err = clk_prepare_enable(priv->clk_per);
578 if (err)
579 goto out_disable_ipg;
580
581 err = __flexcan_get_berr_counter(dev, bec);
582
583 clk_disable_unprepare(priv->clk_per);
584 out_disable_ipg:
585 clk_disable_unprepare(priv->clk_ipg);
586
587 return err;
588}
589
Marc Kleine-Buddefb1e13e62018-04-26 23:13:38 +0200590static netdev_tx_t flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200591{
592 const struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200593 struct can_frame *cf = (struct can_frame *)skb->data;
594 u32 can_id;
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200595 u32 data;
Marc Kleine-Budde10d089b2014-09-23 11:18:11 +0200596 u32 ctrl = FLEXCAN_MB_CODE_TX_DATA | (cf->can_dlc << 16);
Pankaj Bansal05179612018-11-23 22:18:44 +0100597 int i;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200598
599 if (can_dropped_invalid_skb(dev, skb))
600 return NETDEV_TX_OK;
601
602 netif_stop_queue(dev);
603
604 if (cf->can_id & CAN_EFF_FLAG) {
605 can_id = cf->can_id & CAN_EFF_MASK;
606 ctrl |= FLEXCAN_MB_CNT_IDE | FLEXCAN_MB_CNT_SRR;
607 } else {
608 can_id = (cf->can_id & CAN_SFF_MASK) << 18;
609 }
610
611 if (cf->can_id & CAN_RTR_FLAG)
612 ctrl |= FLEXCAN_MB_CNT_RTR;
613
Pankaj Bansal05179612018-11-23 22:18:44 +0100614 for (i = 0; i < cf->can_dlc; i += sizeof(u32)) {
615 data = be32_to_cpup((__be32 *)&cf->data[i]);
616 priv->write(data, &priv->tx_mb->data[i / sizeof(u32)]);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200617 }
618
Reuben Dowle9a123492011-11-01 11:18:03 +1300619 can_put_echo_skb(skb, dev, 0);
620
Pankaj Bansal05179612018-11-23 22:18:44 +0100621 priv->write(can_id, &priv->tx_mb->can_id);
622 priv->write(ctrl, &priv->tx_mb->can_ctrl);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200623
David Jander25e92442014-09-03 16:47:22 +0200624 /* Errata ERR005829 step8:
625 * Write twice INACTIVE(0x8) code to first MB.
626 */
Pankaj Bansal88462d22017-11-24 18:52:08 +0530627 priv->write(FLEXCAN_MB_CODE_TX_INACTIVE,
Marc Kleine-Budde9dc1ee12018-11-12 15:33:57 +0100628 &priv->tx_mb_reserved->can_ctrl);
Pankaj Bansal88462d22017-11-24 18:52:08 +0530629 priv->write(FLEXCAN_MB_CODE_TX_INACTIVE,
Marc Kleine-Budde9dc1ee12018-11-12 15:33:57 +0100630 &priv->tx_mb_reserved->can_ctrl);
David Jander25e92442014-09-03 16:47:22 +0200631
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200632 return NETDEV_TX_OK;
633}
634
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200635static void flexcan_irq_bus_err(struct net_device *dev, u32 reg_esr)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200636{
637 struct flexcan_priv *priv = netdev_priv(dev);
Oleksij Rempeld788905f2018-09-18 11:40:41 +0200638 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Buddea5c02f662017-01-18 11:38:26 +0100639 struct sk_buff *skb;
640 struct can_frame *cf;
Marc Kleine-Budded166f562017-01-17 17:33:46 +0100641 bool rx_errors = false, tx_errors = false;
Oleksij Rempeld788905f2018-09-18 11:40:41 +0200642 u32 timestamp;
643
644 timestamp = priv->read(&regs->timer) << 16;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200645
Marc Kleine-Buddea5c02f662017-01-18 11:38:26 +0100646 skb = alloc_can_err_skb(dev, &cf);
647 if (unlikely(!skb))
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200648 return;
Marc Kleine-Buddea5c02f662017-01-18 11:38:26 +0100649
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200650 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
651
652 if (reg_esr & FLEXCAN_ESR_BIT1_ERR) {
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100653 netdev_dbg(dev, "BIT1_ERR irq\n");
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200654 cf->data[2] |= CAN_ERR_PROT_BIT1;
Marc Kleine-Budded166f562017-01-17 17:33:46 +0100655 tx_errors = true;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200656 }
657 if (reg_esr & FLEXCAN_ESR_BIT0_ERR) {
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100658 netdev_dbg(dev, "BIT0_ERR irq\n");
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200659 cf->data[2] |= CAN_ERR_PROT_BIT0;
Marc Kleine-Budded166f562017-01-17 17:33:46 +0100660 tx_errors = true;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200661 }
662 if (reg_esr & FLEXCAN_ESR_ACK_ERR) {
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100663 netdev_dbg(dev, "ACK_ERR irq\n");
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200664 cf->can_id |= CAN_ERR_ACK;
Oliver Hartkoppffd461f2015-11-21 18:41:20 +0100665 cf->data[3] = CAN_ERR_PROT_LOC_ACK;
Marc Kleine-Budded166f562017-01-17 17:33:46 +0100666 tx_errors = true;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200667 }
668 if (reg_esr & FLEXCAN_ESR_CRC_ERR) {
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100669 netdev_dbg(dev, "CRC_ERR irq\n");
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200670 cf->data[2] |= CAN_ERR_PROT_BIT;
Oliver Hartkoppffd461f2015-11-21 18:41:20 +0100671 cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ;
Marc Kleine-Budded166f562017-01-17 17:33:46 +0100672 rx_errors = true;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200673 }
674 if (reg_esr & FLEXCAN_ESR_FRM_ERR) {
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100675 netdev_dbg(dev, "FRM_ERR irq\n");
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200676 cf->data[2] |= CAN_ERR_PROT_FORM;
Marc Kleine-Budded166f562017-01-17 17:33:46 +0100677 rx_errors = true;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200678 }
679 if (reg_esr & FLEXCAN_ESR_STF_ERR) {
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100680 netdev_dbg(dev, "STF_ERR irq\n");
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200681 cf->data[2] |= CAN_ERR_PROT_STUFF;
Marc Kleine-Budded166f562017-01-17 17:33:46 +0100682 rx_errors = true;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200683 }
684
685 priv->can.can_stats.bus_error++;
686 if (rx_errors)
687 dev->stats.rx_errors++;
688 if (tx_errors)
689 dev->stats.tx_errors++;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200690
Oleksij Rempeld788905f2018-09-18 11:40:41 +0200691 can_rx_offload_queue_sorted(&priv->offload, skb, timestamp);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200692}
693
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200694static void flexcan_irq_state(struct net_device *dev, u32 reg_esr)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200695{
696 struct flexcan_priv *priv = netdev_priv(dev);
Oleksij Rempeld788905f2018-09-18 11:40:41 +0200697 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200698 struct sk_buff *skb;
699 struct can_frame *cf;
Marc Kleine-Budde238443d2017-01-18 11:25:41 +0100700 enum can_state new_state, rx_state, tx_state;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200701 int flt;
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000702 struct can_berr_counter bec;
Oleksij Rempeld788905f2018-09-18 11:40:41 +0200703 u32 timestamp;
704
705 timestamp = priv->read(&regs->timer) << 16;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200706
707 flt = reg_esr & FLEXCAN_ESR_FLT_CONF_MASK;
708 if (likely(flt == FLEXCAN_ESR_FLT_CONF_ACTIVE)) {
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000709 tx_state = unlikely(reg_esr & FLEXCAN_ESR_TX_WRN) ?
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200710 CAN_STATE_ERROR_WARNING : CAN_STATE_ERROR_ACTIVE;
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000711 rx_state = unlikely(reg_esr & FLEXCAN_ESR_RX_WRN) ?
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200712 CAN_STATE_ERROR_WARNING : CAN_STATE_ERROR_ACTIVE;
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000713 new_state = max(tx_state, rx_state);
Andri Yngvason258ce802015-03-17 13:03:09 +0000714 } else {
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000715 __flexcan_get_berr_counter(dev, &bec);
Andri Yngvason258ce802015-03-17 13:03:09 +0000716 new_state = flt == FLEXCAN_ESR_FLT_CONF_PASSIVE ?
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200717 CAN_STATE_ERROR_PASSIVE : CAN_STATE_BUS_OFF;
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000718 rx_state = bec.rxerr >= bec.txerr ? new_state : 0;
719 tx_state = bec.rxerr <= bec.txerr ? new_state : 0;
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000720 }
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200721
722 /* state hasn't changed */
723 if (likely(new_state == priv->can.state))
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200724 return;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200725
726 skb = alloc_can_err_skb(dev, &cf);
727 if (unlikely(!skb))
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200728 return;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200729
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000730 can_change_state(dev, cf, tx_state, rx_state);
731
732 if (unlikely(new_state == CAN_STATE_BUS_OFF))
733 can_bus_off(dev);
734
Oleksij Rempeld788905f2018-09-18 11:40:41 +0200735 can_rx_offload_queue_sorted(&priv->offload, skb, timestamp);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200736}
737
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200738static inline struct flexcan_priv *rx_offload_to_priv(struct can_rx_offload *offload)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200739{
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200740 return container_of(offload, struct flexcan_priv, offload);
741}
742
743static unsigned int flexcan_mailbox_read(struct can_rx_offload *offload,
744 struct can_frame *cf,
745 u32 *timestamp, unsigned int n)
746{
747 struct flexcan_priv *priv = rx_offload_to_priv(offload);
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200748 struct flexcan_regs __iomem *regs = priv->regs;
Pankaj Bansal05179612018-11-23 22:18:44 +0100749 struct flexcan_mb __iomem *mb;
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200750 u32 reg_ctrl, reg_id, reg_iflag1;
Pankaj Bansal05179612018-11-23 22:18:44 +0100751 int i;
752
753 mb = flexcan_get_mb(priv, n);
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200754
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200755 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
756 u32 code;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200757
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200758 do {
Pankaj Bansal88462d22017-11-24 18:52:08 +0530759 reg_ctrl = priv->read(&mb->can_ctrl);
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200760 } while (reg_ctrl & FLEXCAN_MB_CODE_RX_BUSY_BIT);
761
762 /* is this MB empty? */
763 code = reg_ctrl & FLEXCAN_MB_CODE_MASK;
764 if ((code != FLEXCAN_MB_CODE_RX_FULL) &&
765 (code != FLEXCAN_MB_CODE_RX_OVERRUN))
766 return 0;
767
768 if (code == FLEXCAN_MB_CODE_RX_OVERRUN) {
769 /* This MB was overrun, we lost data */
770 offload->dev->stats.rx_over_errors++;
771 offload->dev->stats.rx_errors++;
772 }
773 } else {
Pankaj Bansal88462d22017-11-24 18:52:08 +0530774 reg_iflag1 = priv->read(&regs->iflag1);
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200775 if (!(reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_AVAILABLE))
776 return 0;
777
Pankaj Bansal88462d22017-11-24 18:52:08 +0530778 reg_ctrl = priv->read(&mb->can_ctrl);
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200779 }
780
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200781 /* increase timstamp to full 32 bit */
782 *timestamp = reg_ctrl << 16;
783
Pankaj Bansal88462d22017-11-24 18:52:08 +0530784 reg_id = priv->read(&mb->can_id);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200785 if (reg_ctrl & FLEXCAN_MB_CNT_IDE)
786 cf->can_id = ((reg_id >> 0) & CAN_EFF_MASK) | CAN_EFF_FLAG;
787 else
788 cf->can_id = (reg_id >> 18) & CAN_SFF_MASK;
789
790 if (reg_ctrl & FLEXCAN_MB_CNT_RTR)
791 cf->can_id |= CAN_RTR_FLAG;
792 cf->can_dlc = get_can_dlc((reg_ctrl >> 16) & 0xf);
793
Pankaj Bansal05179612018-11-23 22:18:44 +0100794 for (i = 0; i < cf->can_dlc; i += sizeof(u32)) {
795 __be32 data = cpu_to_be32(priv->read(&mb->data[i / sizeof(u32)]));
796 *(__be32 *)(cf->data + i) = data;
797 }
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200798
799 /* mark as read */
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200800 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
801 /* Clear IRQ */
802 if (n < 32)
Pankaj Bansal88462d22017-11-24 18:52:08 +0530803 priv->write(BIT(n), &regs->iflag1);
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200804 else
Pankaj Bansal88462d22017-11-24 18:52:08 +0530805 priv->write(BIT(n - 32), &regs->iflag2);
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200806 } else {
Pankaj Bansal88462d22017-11-24 18:52:08 +0530807 priv->write(FLEXCAN_IFLAG_RX_FIFO_AVAILABLE, &regs->iflag1);
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200808 }
Fabio Baltieriadccadb2012-12-18 18:50:58 +0100809
Pankaj Bansal5178b7c2018-08-01 19:36:46 +0530810 /* Read the Free Running Timer. It is optional but recommended
811 * to unlock Mailbox as soon as possible and make it available
812 * for reception.
813 */
814 priv->read(&regs->timer);
815
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200816 return 1;
817}
818
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200819
820static inline u64 flexcan_read_reg_iflag_rx(struct flexcan_priv *priv)
821{
822 struct flexcan_regs __iomem *regs = priv->regs;
823 u32 iflag1, iflag2;
824
Alexander Steincbffaf72018-10-11 17:01:25 +0200825 iflag2 = priv->read(&regs->iflag2) & priv->reg_imask2_default &
Pankaj Bansal05179612018-11-23 22:18:44 +0100826 ~FLEXCAN_IFLAG_MB(priv->tx_mb_idx);
Alexander Steincbffaf72018-10-11 17:01:25 +0200827 iflag1 = priv->read(&regs->iflag1) & priv->reg_imask1_default;
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200828
829 return (u64)iflag2 << 32 | iflag1;
830}
831
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200832static irqreturn_t flexcan_irq(int irq, void *dev_id)
833{
834 struct net_device *dev = dev_id;
835 struct net_device_stats *stats = &dev->stats;
836 struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200837 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Buddedd2f1222017-01-18 11:45:14 +0100838 irqreturn_t handled = IRQ_NONE;
Alexander Steincbffaf72018-10-11 17:01:25 +0200839 u32 reg_iflag2, reg_esr;
ZHU Yi (ST-FIR/ENG1-Zhu)da49a802017-09-15 07:03:58 +0000840 enum can_state last_state = priv->can.state;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200841
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200842 /* reception interrupt */
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200843 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
844 u64 reg_iflag;
845 int ret;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200846
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200847 while ((reg_iflag = flexcan_read_reg_iflag_rx(priv))) {
848 handled = IRQ_HANDLED;
849 ret = can_rx_offload_irq_offload_timestamp(&priv->offload,
850 reg_iflag);
851 if (!ret)
852 break;
853 }
854 } else {
Alexander Steincbffaf72018-10-11 17:01:25 +0200855 u32 reg_iflag1;
856
857 reg_iflag1 = priv->read(&regs->iflag1);
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200858 if (reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_AVAILABLE) {
859 handled = IRQ_HANDLED;
860 can_rx_offload_irq_offload_fifo(&priv->offload);
861 }
862
863 /* FIFO overflow interrupt */
864 if (reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_OVERFLOW) {
865 handled = IRQ_HANDLED;
Pankaj Bansal88462d22017-11-24 18:52:08 +0530866 priv->write(FLEXCAN_IFLAG_RX_FIFO_OVERFLOW,
867 &regs->iflag1);
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200868 dev->stats.rx_over_errors++;
869 dev->stats.rx_errors++;
870 }
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200871 }
872
Alexander Steincbffaf72018-10-11 17:01:25 +0200873 reg_iflag2 = priv->read(&regs->iflag2);
874
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200875 /* transmission complete interrupt */
Pankaj Bansal05179612018-11-23 22:18:44 +0100876 if (reg_iflag2 & FLEXCAN_IFLAG_MB(priv->tx_mb_idx)) {
877 u32 reg_ctrl = priv->read(&priv->tx_mb->can_ctrl);
Oleksij Rempeled72bc82018-09-18 11:40:39 +0200878
Marc Kleine-Buddedd2f1222017-01-18 11:45:14 +0100879 handled = IRQ_HANDLED;
Oleksij Rempeled72bc82018-09-18 11:40:39 +0200880 stats->tx_bytes += can_rx_offload_get_echo_skb(&priv->offload,
881 0, reg_ctrl << 16);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200882 stats->tx_packets++;
Fabio Baltieriadccadb2012-12-18 18:50:58 +0100883 can_led_event(dev, CAN_LED_EVENT_TX);
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200884
885 /* after sending a RTR frame MB is in RX mode */
Pankaj Bansal88462d22017-11-24 18:52:08 +0530886 priv->write(FLEXCAN_MB_CODE_TX_INACTIVE,
Pankaj Bansal05179612018-11-23 22:18:44 +0100887 &priv->tx_mb->can_ctrl);
888 priv->write(FLEXCAN_IFLAG_MB(priv->tx_mb_idx), &regs->iflag2);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200889 netif_wake_queue(dev);
890 }
891
Pankaj Bansal88462d22017-11-24 18:52:08 +0530892 reg_esr = priv->read(&regs->esr);
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200893
Marc Kleine-Buddedd2f1222017-01-18 11:45:14 +0100894 /* ACK all bus error and state change IRQ sources */
895 if (reg_esr & FLEXCAN_ESR_ALL_INT) {
896 handled = IRQ_HANDLED;
Pankaj Bansal88462d22017-11-24 18:52:08 +0530897 priv->write(reg_esr & FLEXCAN_ESR_ALL_INT, &regs->esr);
Marc Kleine-Buddedd2f1222017-01-18 11:45:14 +0100898 }
899
ZHU Yi (ST-FIR/ENG1-Zhu)ad230232017-09-15 06:59:15 +0000900 /* state change interrupt or broken error state quirk fix is enabled */
901 if ((reg_esr & FLEXCAN_ESR_ERR_STATE) ||
ZHU Yi (ST-FIR/ENG1-Zhu)da49a802017-09-15 07:03:58 +0000902 (priv->devtype_data->quirks & (FLEXCAN_QUIRK_BROKEN_WERR_STATE |
Marc Kleine-Buddebc8ad652018-11-28 15:45:27 +0100903 FLEXCAN_QUIRK_BROKEN_PERR_STATE)))
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200904 flexcan_irq_state(dev, reg_esr);
905
906 /* bus error IRQ - handle if bus error reporting is activated */
907 if ((reg_esr & FLEXCAN_ESR_ERR_BUS) &&
908 (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING))
909 flexcan_irq_bus_err(dev, reg_esr);
910
ZHU Yi (ST-FIR/ENG1-Zhu)da49a802017-09-15 07:03:58 +0000911 /* availability of error interrupt among state transitions in case
912 * bus error reporting is de-activated and
913 * FLEXCAN_QUIRK_BROKEN_PERR_STATE is enabled:
914 * +--------------------------------------------------------------+
915 * | +----------------------------------------------+ [stopped / |
916 * | | | sleeping] -+
917 * +-+-> active <-> warning <-> passive -> bus off -+
918 * ___________^^^^^^^^^^^^_______________________________
919 * disabled(1) enabled disabled
920 *
921 * (1): enabled if FLEXCAN_QUIRK_BROKEN_WERR_STATE is enabled
922 */
923 if ((last_state != priv->can.state) &&
924 (priv->devtype_data->quirks & FLEXCAN_QUIRK_BROKEN_PERR_STATE) &&
925 !(priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)) {
926 switch (priv->can.state) {
927 case CAN_STATE_ERROR_ACTIVE:
928 if (priv->devtype_data->quirks &
929 FLEXCAN_QUIRK_BROKEN_WERR_STATE)
930 flexcan_error_irq_enable(priv);
931 else
932 flexcan_error_irq_disable(priv);
933 break;
934
935 case CAN_STATE_ERROR_WARNING:
936 flexcan_error_irq_enable(priv);
937 break;
938
939 case CAN_STATE_ERROR_PASSIVE:
940 case CAN_STATE_BUS_OFF:
941 flexcan_error_irq_disable(priv);
942 break;
943
944 default:
945 break;
946 }
947 }
948
Marc Kleine-Buddedd2f1222017-01-18 11:45:14 +0100949 return handled;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200950}
951
952static void flexcan_set_bittiming(struct net_device *dev)
953{
954 const struct flexcan_priv *priv = netdev_priv(dev);
955 const struct can_bittiming *bt = &priv->can.bittiming;
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200956 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200957 u32 reg;
958
Pankaj Bansal88462d22017-11-24 18:52:08 +0530959 reg = priv->read(&regs->ctrl);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200960 reg &= ~(FLEXCAN_CTRL_PRESDIV(0xff) |
961 FLEXCAN_CTRL_RJW(0x3) |
962 FLEXCAN_CTRL_PSEG1(0x7) |
963 FLEXCAN_CTRL_PSEG2(0x7) |
964 FLEXCAN_CTRL_PROPSEG(0x7) |
965 FLEXCAN_CTRL_LPB |
966 FLEXCAN_CTRL_SMP |
967 FLEXCAN_CTRL_LOM);
968
969 reg |= FLEXCAN_CTRL_PRESDIV(bt->brp - 1) |
970 FLEXCAN_CTRL_PSEG1(bt->phase_seg1 - 1) |
971 FLEXCAN_CTRL_PSEG2(bt->phase_seg2 - 1) |
972 FLEXCAN_CTRL_RJW(bt->sjw - 1) |
973 FLEXCAN_CTRL_PROPSEG(bt->prop_seg - 1);
974
975 if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK)
976 reg |= FLEXCAN_CTRL_LPB;
977 if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
978 reg |= FLEXCAN_CTRL_LOM;
979 if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
980 reg |= FLEXCAN_CTRL_SMP;
981
Lucas Stach7a4b6c82015-08-07 17:16:03 +0200982 netdev_dbg(dev, "writing ctrl=0x%08x\n", reg);
Pankaj Bansal88462d22017-11-24 18:52:08 +0530983 priv->write(reg, &regs->ctrl);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200984
985 /* print chip status */
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100986 netdev_dbg(dev, "%s: mcr=0x%08x ctrl=0x%08x\n", __func__,
Pankaj Bansal88462d22017-11-24 18:52:08 +0530987 priv->read(&regs->mcr), priv->read(&regs->ctrl));
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200988}
989
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200990/* flexcan_chip_start
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200991 *
992 * this functions is entered with clocks enabled
993 *
994 */
995static int flexcan_chip_start(struct net_device *dev)
996{
997 struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200998 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Budde6f75fce2014-09-23 11:03:01 +0200999 u32 reg_mcr, reg_ctrl, reg_ctrl2, reg_mecr;
David S. Miller1f6d8032014-09-23 12:09:27 -04001000 int err, i;
Pankaj Bansal05179612018-11-23 22:18:44 +01001001 struct flexcan_mb __iomem *mb;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001002
1003 /* enable module */
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +01001004 err = flexcan_chip_enable(priv);
1005 if (err)
1006 return err;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001007
1008 /* soft reset */
Marc Kleine-Budde4b5b8222014-02-28 15:16:59 +01001009 err = flexcan_chip_softreset(priv);
1010 if (err)
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +01001011 goto out_chip_disable;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001012
1013 flexcan_set_bittiming(dev);
1014
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +02001015 /* MCR
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001016 *
1017 * enable freeze
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001018 * halt now
1019 * only supervisor access
1020 * enable warning int
Marc Kleine-Budde4bd888a2015-08-31 21:03:29 +02001021 * enable individual RX masking
Marc Kleine-Budde749de6f2015-08-31 21:32:34 +02001022 * choose format C
1023 * set max mailbox number
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001024 */
Pankaj Bansal88462d22017-11-24 18:52:08 +05301025 reg_mcr = priv->read(&regs->mcr);
Marc Kleine-Budded5a7b402013-10-04 10:52:36 +02001026 reg_mcr &= ~FLEXCAN_MCR_MAXMB(0xff);
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +02001027 reg_mcr |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT | FLEXCAN_MCR_SUPV |
Pankaj Bansal7ad0f532018-08-13 23:50:48 +05301028 FLEXCAN_MCR_WRN_EN | FLEXCAN_MCR_IRMQ | FLEXCAN_MCR_IDAM_C |
Pankaj Bansal05179612018-11-23 22:18:44 +01001029 FLEXCAN_MCR_MAXMB(priv->tx_mb_idx);
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +02001030
Marc Kleine-Buddec982a3ca2018-08-17 14:52:58 +02001031 /* MCR
1032 *
1033 * FIFO:
1034 * - disable for timestamp mode
1035 * - enable for FIFO mode
1036 */
Alexander Steincbffaf72018-10-11 17:01:25 +02001037 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP)
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +02001038 reg_mcr &= ~FLEXCAN_MCR_FEN;
Alexander Steincbffaf72018-10-11 17:01:25 +02001039 else
1040 reg_mcr |= FLEXCAN_MCR_FEN;
1041
Pankaj Bansal7ad0f532018-08-13 23:50:48 +05301042 /* MCR
1043 *
1044 * NOTE: In loopback mode, the CAN_MCR[SRXDIS] cannot be
1045 * asserted because this will impede the self reception
1046 * of a transmitted message. This is not documented in
1047 * earlier versions of flexcan block guide.
1048 *
1049 * Self Reception:
1050 * - enable Self Reception for loopback mode
1051 * (by clearing "Self Reception Disable" bit)
1052 * - disable for normal operation
1053 */
1054 if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK)
1055 reg_mcr &= ~FLEXCAN_MCR_SRX_DIS;
1056 else
1057 reg_mcr |= FLEXCAN_MCR_SRX_DIS;
1058
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +01001059 netdev_dbg(dev, "%s: writing mcr=0x%08x", __func__, reg_mcr);
Pankaj Bansal88462d22017-11-24 18:52:08 +05301060 priv->write(reg_mcr, &regs->mcr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001061
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +02001062 /* CTRL
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001063 *
1064 * disable timer sync feature
1065 *
1066 * disable auto busoff recovery
1067 * transmit lowest buffer first
1068 *
1069 * enable tx and rx warning interrupt
1070 * enable bus off interrupt
1071 * (== FLEXCAN_CTRL_ERR_STATE)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001072 */
Pankaj Bansal88462d22017-11-24 18:52:08 +05301073 reg_ctrl = priv->read(&regs->ctrl);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001074 reg_ctrl &= ~FLEXCAN_CTRL_TSYN;
1075 reg_ctrl |= FLEXCAN_CTRL_BOFF_REC | FLEXCAN_CTRL_LBUF |
Wolfgang Grandegger4f72e5f2012-09-28 03:17:15 +00001076 FLEXCAN_CTRL_ERR_STATE;
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +02001077
1078 /* enable the "error interrupt" (FLEXCAN_CTRL_ERR_MSK),
Wolfgang Grandegger4f72e5f2012-09-28 03:17:15 +00001079 * on most Flexcan cores, too. Otherwise we don't get
1080 * any error warning or passive interrupts.
1081 */
ZHU Yi (ST-FIR/ENG1-Zhu)2f8639b2017-09-15 07:01:23 +00001082 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_BROKEN_WERR_STATE ||
Wolfgang Grandegger4f72e5f2012-09-28 03:17:15 +00001083 priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
1084 reg_ctrl |= FLEXCAN_CTRL_ERR_MSK;
Alexander Steinbc03a542014-08-12 10:47:21 +02001085 else
1086 reg_ctrl &= ~FLEXCAN_CTRL_ERR_MSK;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001087
1088 /* save for later use */
1089 priv->reg_ctrl_default = reg_ctrl;
Marc Kleine-Budde6fa7da22015-08-27 14:24:48 +02001090 /* leave interrupts disabled for now */
1091 reg_ctrl &= ~FLEXCAN_CTRL_ERR_ALL;
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +01001092 netdev_dbg(dev, "%s: writing ctrl=0x%08x", __func__, reg_ctrl);
Pankaj Bansal88462d22017-11-24 18:52:08 +05301093 priv->write(reg_ctrl, &regs->ctrl);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001094
Marc Kleine-Budde9eb7aa82015-09-01 08:57:55 +02001095 if ((priv->devtype_data->quirks & FLEXCAN_QUIRK_ENABLE_EACEN_RRS)) {
Pankaj Bansal88462d22017-11-24 18:52:08 +05301096 reg_ctrl2 = priv->read(&regs->ctrl2);
Marc Kleine-Budde9eb7aa82015-09-01 08:57:55 +02001097 reg_ctrl2 |= FLEXCAN_CTRL2_EACEN | FLEXCAN_CTRL2_RRS;
Pankaj Bansal88462d22017-11-24 18:52:08 +05301098 priv->write(reg_ctrl2, &regs->ctrl2);
Marc Kleine-Budde9eb7aa82015-09-01 08:57:55 +02001099 }
1100
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +02001101 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
Alexander Steincbffaf72018-10-11 17:01:25 +02001102 for (i = priv->offload.mb_first; i <= priv->offload.mb_last; i++) {
Pankaj Bansal05179612018-11-23 22:18:44 +01001103 mb = flexcan_get_mb(priv, i);
Pankaj Bansal88462d22017-11-24 18:52:08 +05301104 priv->write(FLEXCAN_MB_CODE_RX_EMPTY,
Pankaj Bansal05179612018-11-23 22:18:44 +01001105 &mb->can_ctrl);
Alexander Steincbffaf72018-10-11 17:01:25 +02001106 }
1107 } else {
1108 /* clear and invalidate unused mailboxes first */
Pankaj Bansal05179612018-11-23 22:18:44 +01001109 for (i = FLEXCAN_TX_MB_RESERVED_OFF_FIFO; i <= priv->mb_count; i++) {
1110 mb = flexcan_get_mb(priv, i);
Alexander Steincbffaf72018-10-11 17:01:25 +02001111 priv->write(FLEXCAN_MB_CODE_RX_INACTIVE,
Pankaj Bansal05179612018-11-23 22:18:44 +01001112 &mb->can_ctrl);
Alexander Steincbffaf72018-10-11 17:01:25 +02001113 }
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +02001114 }
1115
David Jander25e92442014-09-03 16:47:22 +02001116 /* Errata ERR005829: mark first TX mailbox as INACTIVE */
Pankaj Bansal88462d22017-11-24 18:52:08 +05301117 priv->write(FLEXCAN_MB_CODE_TX_INACTIVE,
1118 &priv->tx_mb_reserved->can_ctrl);
David Jander25e92442014-09-03 16:47:22 +02001119
Marc Kleine-Buddec32fe4a2014-09-16 12:39:28 +02001120 /* mark TX mailbox as INACTIVE */
Pankaj Bansal88462d22017-11-24 18:52:08 +05301121 priv->write(FLEXCAN_MB_CODE_TX_INACTIVE,
Pankaj Bansal05179612018-11-23 22:18:44 +01001122 &priv->tx_mb->can_ctrl);
Marc Kleine-Budded5a7b402013-10-04 10:52:36 +02001123
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001124 /* acceptance mask/acceptance code (accept everything) */
Pankaj Bansal88462d22017-11-24 18:52:08 +05301125 priv->write(0x0, &regs->rxgmask);
1126 priv->write(0x0, &regs->rx14mask);
1127 priv->write(0x0, &regs->rx15mask);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001128
Marc Kleine-Buddef377bff2015-05-08 15:22:36 +02001129 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_DISABLE_RXFG)
Pankaj Bansal88462d22017-11-24 18:52:08 +05301130 priv->write(0x0, &regs->rxfgmask);
Hui Wang30c1e672012-06-28 16:21:35 +08001131
Marc Kleine-Budde4bd888a2015-08-31 21:03:29 +02001132 /* clear acceptance filters */
Pankaj Bansal05179612018-11-23 22:18:44 +01001133 for (i = 0; i < priv->mb_count; i++)
Pankaj Bansal88462d22017-11-24 18:52:08 +05301134 priv->write(0, &regs->rximr[i]);
Marc Kleine-Budde4bd888a2015-08-31 21:03:29 +02001135
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +02001136 /* On Vybrid, disable memory error detection interrupts
Stefan Agnercdce8442014-07-15 14:56:21 +02001137 * and freeze mode.
1138 * This also works around errata e5295 which generates
1139 * false positive memory errors and put the device in
1140 * freeze mode.
1141 */
Marc Kleine-Buddef377bff2015-05-08 15:22:36 +02001142 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_DISABLE_MECR) {
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +02001143 /* Follow the protocol as described in "Detection
Stefan Agnercdce8442014-07-15 14:56:21 +02001144 * and Correction of Memory Errors" to write to
1145 * MECR register
1146 */
Pankaj Bansal88462d22017-11-24 18:52:08 +05301147 reg_ctrl2 = priv->read(&regs->ctrl2);
Marc Kleine-Budde6f75fce2014-09-23 11:03:01 +02001148 reg_ctrl2 |= FLEXCAN_CTRL2_ECRWRE;
Pankaj Bansal88462d22017-11-24 18:52:08 +05301149 priv->write(reg_ctrl2, &regs->ctrl2);
Stefan Agnercdce8442014-07-15 14:56:21 +02001150
Pankaj Bansal88462d22017-11-24 18:52:08 +05301151 reg_mecr = priv->read(&regs->mecr);
Stefan Agnercdce8442014-07-15 14:56:21 +02001152 reg_mecr &= ~FLEXCAN_MECR_ECRWRDIS;
Pankaj Bansal88462d22017-11-24 18:52:08 +05301153 priv->write(reg_mecr, &regs->mecr);
Stefan Agnercdce8442014-07-15 14:56:21 +02001154 reg_mecr &= ~(FLEXCAN_MECR_NCEFAFRZ | FLEXCAN_MECR_HANCEI_MSK |
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +02001155 FLEXCAN_MECR_FANCEI_MSK);
Pankaj Bansal88462d22017-11-24 18:52:08 +05301156 priv->write(reg_mecr, &regs->mecr);
Stefan Agnercdce8442014-07-15 14:56:21 +02001157 }
1158
Marc Kleine-Buddef0036982014-02-28 17:18:27 +01001159 err = flexcan_transceiver_enable(priv);
1160 if (err)
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +01001161 goto out_chip_disable;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001162
1163 /* synchronize with the can bus */
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +01001164 err = flexcan_chip_unfreeze(priv);
1165 if (err)
1166 goto out_transceiver_disable;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001167
1168 priv->can.state = CAN_STATE_ERROR_ACTIVE;
1169
Marc Kleine-Budde6fa7da22015-08-27 14:24:48 +02001170 /* enable interrupts atomically */
1171 disable_irq(dev->irq);
Pankaj Bansal88462d22017-11-24 18:52:08 +05301172 priv->write(priv->reg_ctrl_default, &regs->ctrl);
1173 priv->write(priv->reg_imask1_default, &regs->imask1);
1174 priv->write(priv->reg_imask2_default, &regs->imask2);
Marc Kleine-Budde6fa7da22015-08-27 14:24:48 +02001175 enable_irq(dev->irq);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001176
1177 /* print chip status */
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +01001178 netdev_dbg(dev, "%s: reading mcr=0x%08x ctrl=0x%08x\n", __func__,
Pankaj Bansal88462d22017-11-24 18:52:08 +05301179 priv->read(&regs->mcr), priv->read(&regs->ctrl));
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001180
1181 return 0;
1182
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +01001183 out_transceiver_disable:
1184 flexcan_transceiver_disable(priv);
1185 out_chip_disable:
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001186 flexcan_chip_disable(priv);
1187 return err;
1188}
1189
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +02001190/* flexcan_chip_stop
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001191 *
1192 * this functions is entered with clocks enabled
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001193 */
1194static void flexcan_chip_stop(struct net_device *dev)
1195{
1196 struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Budde89af8742015-05-08 09:32:58 +02001197 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001198
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +01001199 /* freeze + disable module */
1200 flexcan_chip_freeze(priv);
1201 flexcan_chip_disable(priv);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001202
Marc Kleine-Budde5be93bd2014-02-19 12:00:51 +01001203 /* Disable all interrupts */
Pankaj Bansal88462d22017-11-24 18:52:08 +05301204 priv->write(0, &regs->imask2);
1205 priv->write(0, &regs->imask1);
1206 priv->write(priv->reg_ctrl_default & ~FLEXCAN_CTRL_ERR_ALL,
1207 &regs->ctrl);
Marc Kleine-Budde5be93bd2014-02-19 12:00:51 +01001208
Marc Kleine-Buddef0036982014-02-28 17:18:27 +01001209 flexcan_transceiver_disable(priv);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001210 priv->can.state = CAN_STATE_STOPPED;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001211}
1212
1213static int flexcan_open(struct net_device *dev)
1214{
1215 struct flexcan_priv *priv = netdev_priv(dev);
1216 int err;
1217
Fabio Estevamaa101812013-07-22 12:41:40 -03001218 err = clk_prepare_enable(priv->clk_ipg);
1219 if (err)
1220 return err;
1221
1222 err = clk_prepare_enable(priv->clk_per);
1223 if (err)
1224 goto out_disable_ipg;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001225
1226 err = open_candev(dev);
1227 if (err)
Fabio Estevamaa101812013-07-22 12:41:40 -03001228 goto out_disable_per;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001229
1230 err = request_irq(dev->irq, flexcan_irq, IRQF_SHARED, dev->name, dev);
1231 if (err)
1232 goto out_close;
1233
Pankaj Bansal05179612018-11-23 22:18:44 +01001234 priv->mb_size = sizeof(struct flexcan_mb) + CAN_MAX_DLEN;
Pankaj Bansal6cbf7602018-08-28 23:19:12 +05301235 priv->mb_count = (sizeof(priv->regs->mb[0]) / priv->mb_size) +
1236 (sizeof(priv->regs->mb[1]) / priv->mb_size);
Pankaj Bansal05179612018-11-23 22:18:44 +01001237
Pankaj Bansal5156c7b2018-08-13 23:50:49 +05301238 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP)
Pankaj Bansal05179612018-11-23 22:18:44 +01001239 priv->tx_mb_reserved =
1240 flexcan_get_mb(priv, FLEXCAN_TX_MB_RESERVED_OFF_TIMESTAMP);
Pankaj Bansal5156c7b2018-08-13 23:50:49 +05301241 else
Pankaj Bansal05179612018-11-23 22:18:44 +01001242 priv->tx_mb_reserved =
1243 flexcan_get_mb(priv, FLEXCAN_TX_MB_RESERVED_OFF_FIFO);
1244 priv->tx_mb_idx = priv->mb_count - 1;
1245 priv->tx_mb = flexcan_get_mb(priv, priv->tx_mb_idx);
Pankaj Bansal5156c7b2018-08-13 23:50:49 +05301246
1247 priv->reg_imask1_default = 0;
Pankaj Bansal05179612018-11-23 22:18:44 +01001248 priv->reg_imask2_default = FLEXCAN_IFLAG_MB(priv->tx_mb_idx);
Pankaj Bansal5156c7b2018-08-13 23:50:49 +05301249
1250 priv->offload.mailbox_read = flexcan_mailbox_read;
1251
1252 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
1253 u64 imask;
1254
1255 priv->offload.mb_first = FLEXCAN_RX_MB_OFF_TIMESTAMP_FIRST;
Pankaj Bansal05179612018-11-23 22:18:44 +01001256 priv->offload.mb_last = priv->mb_count - 2;
Pankaj Bansal5156c7b2018-08-13 23:50:49 +05301257
1258 imask = GENMASK_ULL(priv->offload.mb_last,
1259 priv->offload.mb_first);
1260 priv->reg_imask1_default |= imask;
1261 priv->reg_imask2_default |= imask >> 32;
1262
1263 err = can_rx_offload_add_timestamp(dev, &priv->offload);
1264 } else {
1265 priv->reg_imask1_default |= FLEXCAN_IFLAG_RX_FIFO_OVERFLOW |
1266 FLEXCAN_IFLAG_RX_FIFO_AVAILABLE;
1267 err = can_rx_offload_add_fifo(dev, &priv->offload,
1268 FLEXCAN_NAPI_WEIGHT);
1269 }
1270 if (err)
1271 goto out_free_irq;
1272
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001273 /* start chip and queuing */
1274 err = flexcan_chip_start(dev);
1275 if (err)
Pankaj Bansal5156c7b2018-08-13 23:50:49 +05301276 goto out_offload_del;
Fabio Baltieriadccadb2012-12-18 18:50:58 +01001277
1278 can_led_event(dev, CAN_LED_EVENT_OPEN);
1279
Marc Kleine-Budde30164752015-05-10 15:26:58 +02001280 can_rx_offload_enable(&priv->offload);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001281 netif_start_queue(dev);
1282
1283 return 0;
1284
Pankaj Bansal5156c7b2018-08-13 23:50:49 +05301285 out_offload_del:
1286 can_rx_offload_del(&priv->offload);
Marc Kleine-Budde7e9e1482014-02-28 14:52:01 +01001287 out_free_irq:
1288 free_irq(dev->irq, dev);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001289 out_close:
1290 close_candev(dev);
Fabio Estevamaa101812013-07-22 12:41:40 -03001291 out_disable_per:
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001292 clk_disable_unprepare(priv->clk_per);
Fabio Estevamaa101812013-07-22 12:41:40 -03001293 out_disable_ipg:
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001294 clk_disable_unprepare(priv->clk_ipg);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001295
1296 return err;
1297}
1298
1299static int flexcan_close(struct net_device *dev)
1300{
1301 struct flexcan_priv *priv = netdev_priv(dev);
1302
1303 netif_stop_queue(dev);
Marc Kleine-Budde30164752015-05-10 15:26:58 +02001304 can_rx_offload_disable(&priv->offload);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001305 flexcan_chip_stop(dev);
1306
Pankaj Bansal5156c7b2018-08-13 23:50:49 +05301307 can_rx_offload_del(&priv->offload);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001308 free_irq(dev->irq, dev);
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001309 clk_disable_unprepare(priv->clk_per);
1310 clk_disable_unprepare(priv->clk_ipg);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001311
1312 close_candev(dev);
1313
Fabio Baltieriadccadb2012-12-18 18:50:58 +01001314 can_led_event(dev, CAN_LED_EVENT_STOP);
1315
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001316 return 0;
1317}
1318
1319static int flexcan_set_mode(struct net_device *dev, enum can_mode mode)
1320{
1321 int err;
1322
1323 switch (mode) {
1324 case CAN_MODE_START:
1325 err = flexcan_chip_start(dev);
1326 if (err)
1327 return err;
1328
1329 netif_wake_queue(dev);
1330 break;
1331
1332 default:
1333 return -EOPNOTSUPP;
1334 }
1335
1336 return 0;
1337}
1338
1339static const struct net_device_ops flexcan_netdev_ops = {
1340 .ndo_open = flexcan_open,
1341 .ndo_stop = flexcan_close,
1342 .ndo_start_xmit = flexcan_start_xmit,
Oliver Hartkoppc971fa22014-03-07 09:23:41 +01001343 .ndo_change_mtu = can_change_mtu,
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001344};
1345
Bill Pemberton3c8ac0f2012-12-03 09:22:44 -05001346static int register_flexcandev(struct net_device *dev)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001347{
1348 struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Budde89af8742015-05-08 09:32:58 +02001349 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001350 u32 reg, err;
1351
Fabio Estevamaa101812013-07-22 12:41:40 -03001352 err = clk_prepare_enable(priv->clk_ipg);
1353 if (err)
1354 return err;
1355
1356 err = clk_prepare_enable(priv->clk_per);
1357 if (err)
1358 goto out_disable_ipg;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001359
1360 /* select "bus clock", chip must be disabled */
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +01001361 err = flexcan_chip_disable(priv);
1362 if (err)
1363 goto out_disable_per;
Pankaj Bansal88462d22017-11-24 18:52:08 +05301364 reg = priv->read(&regs->ctrl);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001365 reg |= FLEXCAN_CTRL_CLK_SRC;
Pankaj Bansal88462d22017-11-24 18:52:08 +05301366 priv->write(reg, &regs->ctrl);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001367
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +01001368 err = flexcan_chip_enable(priv);
1369 if (err)
1370 goto out_chip_disable;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001371
1372 /* set freeze, halt and activate FIFO, restrict register access */
Pankaj Bansal88462d22017-11-24 18:52:08 +05301373 reg = priv->read(&regs->mcr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001374 reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT |
1375 FLEXCAN_MCR_FEN | FLEXCAN_MCR_SUPV;
Pankaj Bansal88462d22017-11-24 18:52:08 +05301376 priv->write(reg, &regs->mcr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001377
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +02001378 /* Currently we only support newer versions of this core
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +02001379 * featuring a RX hardware FIFO (although this driver doesn't
1380 * make use of it on some cores). Older cores, found on some
1381 * Coldfire derivates are not tested.
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001382 */
Pankaj Bansal88462d22017-11-24 18:52:08 +05301383 reg = priv->read(&regs->mcr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001384 if (!(reg & FLEXCAN_MCR_FEN)) {
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +01001385 netdev_err(dev, "Could not enable RX FIFO, unsupported core\n");
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001386 err = -ENODEV;
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +01001387 goto out_chip_disable;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001388 }
1389
1390 err = register_candev(dev);
1391
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001392 /* disable core and turn off clocks */
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +01001393 out_chip_disable:
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001394 flexcan_chip_disable(priv);
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +01001395 out_disable_per:
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001396 clk_disable_unprepare(priv->clk_per);
Fabio Estevamaa101812013-07-22 12:41:40 -03001397 out_disable_ipg:
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001398 clk_disable_unprepare(priv->clk_ipg);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001399
1400 return err;
1401}
1402
Bill Pemberton3c8ac0f2012-12-03 09:22:44 -05001403static void unregister_flexcandev(struct net_device *dev)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001404{
1405 unregister_candev(dev);
1406}
1407
Aisheng Dongde3578c2018-11-23 08:35:33 +00001408static int flexcan_setup_stop_mode(struct platform_device *pdev)
1409{
1410 struct net_device *dev = platform_get_drvdata(pdev);
1411 struct device_node *np = pdev->dev.of_node;
1412 struct device_node *gpr_np;
1413 struct flexcan_priv *priv;
1414 phandle phandle;
1415 u32 out_val[5];
1416 int ret;
1417
1418 if (!np)
1419 return -EINVAL;
1420
1421 /* stop mode property format is:
1422 * <&gpr req_gpr req_bit ack_gpr ack_bit>.
1423 */
1424 ret = of_property_read_u32_array(np, "fsl,stop-mode", out_val,
1425 ARRAY_SIZE(out_val));
1426 if (ret) {
1427 dev_dbg(&pdev->dev, "no stop-mode property\n");
1428 return ret;
1429 }
1430 phandle = *out_val;
1431
1432 gpr_np = of_find_node_by_phandle(phandle);
1433 if (!gpr_np) {
1434 dev_dbg(&pdev->dev, "could not find gpr node by phandle\n");
1435 return PTR_ERR(gpr_np);
1436 }
1437
1438 priv = netdev_priv(dev);
1439 priv->stm.gpr = syscon_node_to_regmap(gpr_np);
1440 of_node_put(gpr_np);
1441 if (IS_ERR(priv->stm.gpr)) {
1442 dev_dbg(&pdev->dev, "could not find gpr regmap\n");
1443 return PTR_ERR(priv->stm.gpr);
1444 }
1445
1446 priv->stm.req_gpr = out_val[1];
1447 priv->stm.req_bit = out_val[2];
1448 priv->stm.ack_gpr = out_val[3];
1449 priv->stm.ack_bit = out_val[4];
1450
1451 dev_dbg(&pdev->dev,
1452 "gpr %s req_gpr=0x02%x req_bit=%u ack_gpr=0x02%x ack_bit=%u\n",
1453 gpr_np->full_name, priv->stm.req_gpr, priv->stm.req_bit,
1454 priv->stm.ack_gpr, priv->stm.ack_bit);
1455
1456 device_set_wakeup_capable(&pdev->dev, true);
1457
1458 return 0;
1459}
1460
Hui Wang30c1e672012-06-28 16:21:35 +08001461static const struct of_device_id flexcan_of_match[] = {
Hui Wang30c1e672012-06-28 16:21:35 +08001462 { .compatible = "fsl,imx6q-flexcan", .data = &fsl_imx6q_devtype_data, },
Marc Kleine-Buddee3587842013-10-03 23:51:55 +02001463 { .compatible = "fsl,imx28-flexcan", .data = &fsl_imx28_devtype_data, },
Uwe Kleine-König0e030a32018-04-25 16:50:39 +02001464 { .compatible = "fsl,imx53-flexcan", .data = &fsl_imx25_devtype_data, },
1465 { .compatible = "fsl,imx35-flexcan", .data = &fsl_imx25_devtype_data, },
1466 { .compatible = "fsl,imx25-flexcan", .data = &fsl_imx25_devtype_data, },
Marc Kleine-Buddee3587842013-10-03 23:51:55 +02001467 { .compatible = "fsl,p1010-flexcan", .data = &fsl_p1010_devtype_data, },
Stefan Agnercdce8442014-07-15 14:56:21 +02001468 { .compatible = "fsl,vf610-flexcan", .data = &fsl_vf610_devtype_data, },
Pankaj Bansal99b76682017-11-24 18:52:09 +05301469 { .compatible = "fsl,ls1021ar2-flexcan", .data = &fsl_ls1021a_r2_devtype_data, },
Hui Wang30c1e672012-06-28 16:21:35 +08001470 { /* sentinel */ },
1471};
Marc Kleine-Budde4358a9d2012-10-04 10:55:35 +02001472MODULE_DEVICE_TABLE(of, flexcan_of_match);
Hui Wang30c1e672012-06-28 16:21:35 +08001473
1474static const struct platform_device_id flexcan_id_table[] = {
1475 { .name = "flexcan", .driver_data = (kernel_ulong_t)&fsl_p1010_devtype_data, },
1476 { /* sentinel */ },
1477};
Marc Kleine-Budde4358a9d2012-10-04 10:55:35 +02001478MODULE_DEVICE_TABLE(platform, flexcan_id_table);
Hui Wang30c1e672012-06-28 16:21:35 +08001479
Bill Pemberton3c8ac0f2012-12-03 09:22:44 -05001480static int flexcan_probe(struct platform_device *pdev)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001481{
Hui Wang30c1e672012-06-28 16:21:35 +08001482 const struct of_device_id *of_id;
Marc Kleine-Buddedda0b3b2012-07-13 14:52:48 +02001483 const struct flexcan_devtype_data *devtype_data;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001484 struct net_device *dev;
1485 struct flexcan_priv *priv;
Andreas Werner555828e2015-03-22 17:35:52 +01001486 struct regulator *reg_xceiver;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001487 struct resource *mem;
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001488 struct clk *clk_ipg = NULL, *clk_per = NULL;
Marc Kleine-Budde89af8742015-05-08 09:32:58 +02001489 struct flexcan_regs __iomem *regs;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001490 int err, irq;
holt@sgi.com97efe9a2011-08-16 17:32:23 +00001491 u32 clock_freq = 0;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001492
Andreas Werner555828e2015-03-22 17:35:52 +01001493 reg_xceiver = devm_regulator_get(&pdev->dev, "xceiver");
1494 if (PTR_ERR(reg_xceiver) == -EPROBE_DEFER)
1495 return -EPROBE_DEFER;
1496 else if (IS_ERR(reg_xceiver))
1497 reg_xceiver = NULL;
1498
Hui Wangafc016d2012-06-28 16:21:34 +08001499 if (pdev->dev.of_node)
1500 of_property_read_u32(pdev->dev.of_node,
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +02001501 "clock-frequency", &clock_freq);
holt@sgi.com97efe9a2011-08-16 17:32:23 +00001502
1503 if (!clock_freq) {
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001504 clk_ipg = devm_clk_get(&pdev->dev, "ipg");
1505 if (IS_ERR(clk_ipg)) {
1506 dev_err(&pdev->dev, "no ipg clock defined\n");
Fabio Estevam933e4af2013-07-22 12:41:39 -03001507 return PTR_ERR(clk_ipg);
holt@sgi.com97efe9a2011-08-16 17:32:23 +00001508 }
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001509
1510 clk_per = devm_clk_get(&pdev->dev, "per");
1511 if (IS_ERR(clk_per)) {
1512 dev_err(&pdev->dev, "no per clock defined\n");
Fabio Estevam933e4af2013-07-22 12:41:39 -03001513 return PTR_ERR(clk_per);
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001514 }
Marc Kleine-Budde1a3e5172013-11-25 22:15:20 +01001515 clock_freq = clk_get_rate(clk_per);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001516 }
1517
1518 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1519 irq = platform_get_irq(pdev, 0);
Fabio Estevam933e4af2013-07-22 12:41:39 -03001520 if (irq <= 0)
1521 return -ENODEV;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001522
Marc Kleine-Budde89af8742015-05-08 09:32:58 +02001523 regs = devm_ioremap_resource(&pdev->dev, mem);
1524 if (IS_ERR(regs))
1525 return PTR_ERR(regs);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001526
Hui Wang30c1e672012-06-28 16:21:35 +08001527 of_id = of_match_device(flexcan_of_match, &pdev->dev);
1528 if (of_id) {
1529 devtype_data = of_id->data;
Marc Kleine-Budded0873e62014-03-04 22:04:22 +01001530 } else if (platform_get_device_id(pdev)->driver_data) {
Hui Wang30c1e672012-06-28 16:21:35 +08001531 devtype_data = (struct flexcan_devtype_data *)
Marc Kleine-Budded0873e62014-03-04 22:04:22 +01001532 platform_get_device_id(pdev)->driver_data;
Hui Wang30c1e672012-06-28 16:21:35 +08001533 } else {
Fabio Estevam933e4af2013-07-22 12:41:39 -03001534 return -ENODEV;
Hui Wang30c1e672012-06-28 16:21:35 +08001535 }
1536
Fabio Estevam933e4af2013-07-22 12:41:39 -03001537 dev = alloc_candev(sizeof(struct flexcan_priv), 1);
1538 if (!dev)
1539 return -ENOMEM;
1540
Marc Kleine-Budde30164752015-05-10 15:26:58 +02001541 platform_set_drvdata(pdev, dev);
1542 SET_NETDEV_DEV(dev, &pdev->dev);
1543
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001544 dev->netdev_ops = &flexcan_netdev_ops;
1545 dev->irq = irq;
Reuben Dowle9a123492011-11-01 11:18:03 +13001546 dev->flags |= IFF_ECHO;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001547
1548 priv = netdev_priv(dev);
Pankaj Bansal88462d22017-11-24 18:52:08 +05301549
Uwe Kleine-König0e030a32018-04-25 16:50:39 +02001550 if (of_property_read_bool(pdev->dev.of_node, "big-endian") ||
1551 devtype_data->quirks & FLEXCAN_QUIRK_DEFAULT_BIG_ENDIAN) {
Pankaj Bansal88462d22017-11-24 18:52:08 +05301552 priv->read = flexcan_read_be;
1553 priv->write = flexcan_write_be;
1554 } else {
Uwe Kleine-König0e030a32018-04-25 16:50:39 +02001555 priv->read = flexcan_read_le;
1556 priv->write = flexcan_write_le;
Pankaj Bansal88462d22017-11-24 18:52:08 +05301557 }
1558
holt@sgi.com97efe9a2011-08-16 17:32:23 +00001559 priv->can.clock.freq = clock_freq;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001560 priv->can.bittiming_const = &flexcan_bittiming_const;
1561 priv->can.do_set_mode = flexcan_set_mode;
1562 priv->can.do_get_berr_counter = flexcan_get_berr_counter;
1563 priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK |
1564 CAN_CTRLMODE_LISTENONLY | CAN_CTRLMODE_3_SAMPLES |
1565 CAN_CTRLMODE_BERR_REPORTING;
Marc Kleine-Budde89af8742015-05-08 09:32:58 +02001566 priv->regs = regs;
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001567 priv->clk_ipg = clk_ipg;
1568 priv->clk_per = clk_per;
Hui Wang30c1e672012-06-28 16:21:35 +08001569 priv->devtype_data = devtype_data;
Andreas Werner555828e2015-03-22 17:35:52 +01001570 priv->reg_xceiver = reg_xceiver;
Fabio Estevamb7c41142013-06-10 23:12:57 -03001571
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001572 err = register_flexcandev(dev);
1573 if (err) {
1574 dev_err(&pdev->dev, "registering netdev failed\n");
1575 goto failed_register;
1576 }
1577
Fabio Baltieriadccadb2012-12-18 18:50:58 +01001578 devm_can_led_init(dev);
1579
Aisheng Dongde3578c2018-11-23 08:35:33 +00001580 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_SETUP_STOP_MODE) {
1581 err = flexcan_setup_stop_mode(pdev);
1582 if (err)
1583 dev_dbg(&pdev->dev, "failed to setup stop-mode\n");
1584 }
1585
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001586 dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%d)\n",
Marc Kleine-Budde89af8742015-05-08 09:32:58 +02001587 priv->regs, dev->irq);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001588
1589 return 0;
1590
1591 failed_register:
1592 free_candev(dev);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001593 return err;
1594}
1595
Bill Pemberton3c8ac0f2012-12-03 09:22:44 -05001596static int flexcan_remove(struct platform_device *pdev)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001597{
1598 struct net_device *dev = platform_get_drvdata(pdev);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001599
1600 unregister_flexcandev(dev);
Marc Kleine-Budde9a275862010-10-21 05:07:58 +00001601 free_candev(dev);
1602
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001603 return 0;
1604}
1605
Marc Kleine-Budde08c6d352014-03-05 19:10:44 +01001606static int __maybe_unused flexcan_suspend(struct device *device)
Eric Bénard8b5e2182012-05-08 17:12:17 +02001607{
Fabio Estevam588e7a82013-05-20 15:43:43 -03001608 struct net_device *dev = dev_get_drvdata(device);
Eric Bénard8b5e2182012-05-08 17:12:17 +02001609 struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +01001610 int err;
Eric Bénard8b5e2182012-05-08 17:12:17 +02001611
Eric Bénard8b5e2182012-05-08 17:12:17 +02001612 if (netif_running(dev)) {
Aisheng Dongde3578c2018-11-23 08:35:33 +00001613 /* if wakeup is enabled, enter stop mode
1614 * else enter disabled mode.
1615 */
1616 if (device_may_wakeup(device)) {
1617 enable_irq_wake(dev->irq);
1618 flexcan_enter_stop_mode(priv);
1619 } else {
1620 err = flexcan_chip_disable(priv);
1621 if (err)
1622 return err;
1623 }
Eric Bénard8b5e2182012-05-08 17:12:17 +02001624 netif_stop_queue(dev);
1625 netif_device_detach(dev);
1626 }
1627 priv->can.state = CAN_STATE_SLEEPING;
1628
1629 return 0;
1630}
1631
Marc Kleine-Budde08c6d352014-03-05 19:10:44 +01001632static int __maybe_unused flexcan_resume(struct device *device)
Eric Bénard8b5e2182012-05-08 17:12:17 +02001633{
Fabio Estevam588e7a82013-05-20 15:43:43 -03001634 struct net_device *dev = dev_get_drvdata(device);
Eric Bénard8b5e2182012-05-08 17:12:17 +02001635 struct flexcan_priv *priv = netdev_priv(dev);
Fabio Estevam4de349e2016-08-17 12:41:08 -03001636 int err;
Eric Bénard8b5e2182012-05-08 17:12:17 +02001637
1638 priv->can.state = CAN_STATE_ERROR_ACTIVE;
1639 if (netif_running(dev)) {
1640 netif_device_attach(dev);
1641 netif_start_queue(dev);
Aisheng Dongde3578c2018-11-23 08:35:33 +00001642 if (device_may_wakeup(device)) {
1643 disable_irq_wake(dev->irq);
1644 } else {
1645 err = flexcan_chip_enable(priv);
1646 if (err)
1647 return err;
1648 }
Eric Bénard8b5e2182012-05-08 17:12:17 +02001649 }
Fabio Estevam4de349e2016-08-17 12:41:08 -03001650 return 0;
Eric Bénard8b5e2182012-05-08 17:12:17 +02001651}
Fabio Estevam588e7a82013-05-20 15:43:43 -03001652
Aisheng Dongde3578c2018-11-23 08:35:33 +00001653static int __maybe_unused flexcan_noirq_suspend(struct device *device)
1654{
1655 struct net_device *dev = dev_get_drvdata(device);
1656 struct flexcan_priv *priv = netdev_priv(dev);
1657
1658 if (netif_running(dev) && device_may_wakeup(device))
1659 flexcan_enable_wakeup_irq(priv, true);
1660
1661 return 0;
1662}
1663
1664static int __maybe_unused flexcan_noirq_resume(struct device *device)
1665{
1666 struct net_device *dev = dev_get_drvdata(device);
1667 struct flexcan_priv *priv = netdev_priv(dev);
1668
1669 if (netif_running(dev) && device_may_wakeup(device)) {
1670 flexcan_enable_wakeup_irq(priv, false);
1671 flexcan_exit_stop_mode(priv);
1672 }
1673
1674 return 0;
1675}
1676
1677static const struct dev_pm_ops flexcan_pm_ops = {
1678 SET_SYSTEM_SLEEP_PM_OPS(flexcan_suspend, flexcan_resume)
1679 SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(flexcan_noirq_suspend, flexcan_noirq_resume)
1680};
Eric Bénard8b5e2182012-05-08 17:12:17 +02001681
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001682static struct platform_driver flexcan_driver = {
holt@sgi.comc8aef4c2011-08-16 17:32:22 +00001683 .driver = {
1684 .name = DRV_NAME,
Fabio Estevam588e7a82013-05-20 15:43:43 -03001685 .pm = &flexcan_pm_ops,
holt@sgi.comc8aef4c2011-08-16 17:32:22 +00001686 .of_match_table = flexcan_of_match,
1687 },
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001688 .probe = flexcan_probe,
Bill Pemberton3c8ac0f2012-12-03 09:22:44 -05001689 .remove = flexcan_remove,
Hui Wang30c1e672012-06-28 16:21:35 +08001690 .id_table = flexcan_id_table,
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001691};
1692
Axel Lin871d3372011-11-27 15:42:31 +00001693module_platform_driver(flexcan_driver);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001694
1695MODULE_AUTHOR("Sascha Hauer <kernel@pengutronix.de>, "
1696 "Marc Kleine-Budde <kernel@pengutronix.de>");
1697MODULE_LICENSE("GPL v2");
1698MODULE_DESCRIPTION("CAN port driver for flexcan based chip");