blob: 13f0f219d8aa83ab0ce52823f6ddb697d58c316b [file] [log] [blame]
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001/*
2 * flexcan.c - FLEXCAN CAN controller driver
3 *
4 * Copyright (c) 2005-2006 Varma Electronics Oy
5 * Copyright (c) 2009 Sascha Hauer, Pengutronix
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +02006 * Copyright (c) 2010-2017 Pengutronix, Marc Kleine-Budde <kernel@pengutronix.de>
7 * Copyright (c) 2014 David Jander, Protonic Holland
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02008 *
9 * Based on code originally by Andrey Volkov <avolkov@varma-el.com>
10 *
11 * LICENCE:
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation version 2.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 */
22
23#include <linux/netdevice.h>
24#include <linux/can.h>
25#include <linux/can/dev.h>
26#include <linux/can/error.h>
Fabio Baltieriadccadb2012-12-18 18:50:58 +010027#include <linux/can/led.h>
Marc Kleine-Budde30164752015-05-10 15:26:58 +020028#include <linux/can/rx-offload.h>
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020029#include <linux/clk.h>
30#include <linux/delay.h>
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020031#include <linux/interrupt.h>
32#include <linux/io.h>
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020033#include <linux/module.h>
holt@sgi.com97efe9a2011-08-16 17:32:23 +000034#include <linux/of.h>
Hui Wang30c1e672012-06-28 16:21:35 +080035#include <linux/of_device.h>
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020036#include <linux/platform_device.h>
Fabio Estevamb7c41142013-06-10 23:12:57 -030037#include <linux/regulator/consumer.h>
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020038
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020039#define DRV_NAME "flexcan"
40
41/* 8 for RX fifo and 2 error handling */
42#define FLEXCAN_NAPI_WEIGHT (8 + 2)
43
44/* FLEXCAN module configuration register (CANMCR) bits */
45#define FLEXCAN_MCR_MDIS BIT(31)
46#define FLEXCAN_MCR_FRZ BIT(30)
47#define FLEXCAN_MCR_FEN BIT(29)
48#define FLEXCAN_MCR_HALT BIT(28)
49#define FLEXCAN_MCR_NOT_RDY BIT(27)
50#define FLEXCAN_MCR_WAK_MSK BIT(26)
51#define FLEXCAN_MCR_SOFTRST BIT(25)
52#define FLEXCAN_MCR_FRZ_ACK BIT(24)
53#define FLEXCAN_MCR_SUPV BIT(23)
54#define FLEXCAN_MCR_SLF_WAK BIT(22)
55#define FLEXCAN_MCR_WRN_EN BIT(21)
56#define FLEXCAN_MCR_LPM_ACK BIT(20)
57#define FLEXCAN_MCR_WAK_SRC BIT(19)
58#define FLEXCAN_MCR_DOZE BIT(18)
59#define FLEXCAN_MCR_SRX_DIS BIT(17)
Marc Kleine-Budde62d10862015-08-27 16:01:27 +020060#define FLEXCAN_MCR_IRMQ BIT(16)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020061#define FLEXCAN_MCR_LPRIO_EN BIT(13)
62#define FLEXCAN_MCR_AEN BIT(12)
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +020063/* MCR_MAXMB: maximum used MBs is MAXMB + 1 */
Marc Kleine-Budde4c728d82014-09-02 16:54:17 +020064#define FLEXCAN_MCR_MAXMB(x) ((x) & 0x7f)
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +020065#define FLEXCAN_MCR_IDAM_A (0x0 << 8)
66#define FLEXCAN_MCR_IDAM_B (0x1 << 8)
67#define FLEXCAN_MCR_IDAM_C (0x2 << 8)
68#define FLEXCAN_MCR_IDAM_D (0x3 << 8)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +020069
70/* FLEXCAN control register (CANCTRL) bits */
71#define FLEXCAN_CTRL_PRESDIV(x) (((x) & 0xff) << 24)
72#define FLEXCAN_CTRL_RJW(x) (((x) & 0x03) << 22)
73#define FLEXCAN_CTRL_PSEG1(x) (((x) & 0x07) << 19)
74#define FLEXCAN_CTRL_PSEG2(x) (((x) & 0x07) << 16)
75#define FLEXCAN_CTRL_BOFF_MSK BIT(15)
76#define FLEXCAN_CTRL_ERR_MSK BIT(14)
77#define FLEXCAN_CTRL_CLK_SRC BIT(13)
78#define FLEXCAN_CTRL_LPB BIT(12)
79#define FLEXCAN_CTRL_TWRN_MSK BIT(11)
80#define FLEXCAN_CTRL_RWRN_MSK BIT(10)
81#define FLEXCAN_CTRL_SMP BIT(7)
82#define FLEXCAN_CTRL_BOFF_REC BIT(6)
83#define FLEXCAN_CTRL_TSYN BIT(5)
84#define FLEXCAN_CTRL_LBUF BIT(4)
85#define FLEXCAN_CTRL_LOM BIT(3)
86#define FLEXCAN_CTRL_PROPSEG(x) ((x) & 0x07)
87#define FLEXCAN_CTRL_ERR_BUS (FLEXCAN_CTRL_ERR_MSK)
88#define FLEXCAN_CTRL_ERR_STATE \
89 (FLEXCAN_CTRL_TWRN_MSK | FLEXCAN_CTRL_RWRN_MSK | \
90 FLEXCAN_CTRL_BOFF_MSK)
91#define FLEXCAN_CTRL_ERR_ALL \
92 (FLEXCAN_CTRL_ERR_BUS | FLEXCAN_CTRL_ERR_STATE)
93
Stefan Agnercdce8442014-07-15 14:56:21 +020094/* FLEXCAN control register 2 (CTRL2) bits */
Marc Kleine-Budde6f75fce2014-09-23 11:03:01 +020095#define FLEXCAN_CTRL2_ECRWRE BIT(29)
96#define FLEXCAN_CTRL2_WRMFRZ BIT(28)
97#define FLEXCAN_CTRL2_RFFN(x) (((x) & 0x0f) << 24)
98#define FLEXCAN_CTRL2_TASD(x) (((x) & 0x1f) << 19)
99#define FLEXCAN_CTRL2_MRP BIT(18)
100#define FLEXCAN_CTRL2_RRS BIT(17)
101#define FLEXCAN_CTRL2_EACEN BIT(16)
Stefan Agnercdce8442014-07-15 14:56:21 +0200102
103/* FLEXCAN memory error control register (MECR) bits */
104#define FLEXCAN_MECR_ECRWRDIS BIT(31)
105#define FLEXCAN_MECR_HANCEI_MSK BIT(19)
106#define FLEXCAN_MECR_FANCEI_MSK BIT(18)
107#define FLEXCAN_MECR_CEI_MSK BIT(16)
108#define FLEXCAN_MECR_HAERRIE BIT(15)
109#define FLEXCAN_MECR_FAERRIE BIT(14)
110#define FLEXCAN_MECR_EXTERRIE BIT(13)
111#define FLEXCAN_MECR_RERRDIS BIT(9)
112#define FLEXCAN_MECR_ECCDIS BIT(8)
113#define FLEXCAN_MECR_NCEFAFRZ BIT(7)
114
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200115/* FLEXCAN error and status register (ESR) bits */
116#define FLEXCAN_ESR_TWRN_INT BIT(17)
117#define FLEXCAN_ESR_RWRN_INT BIT(16)
118#define FLEXCAN_ESR_BIT1_ERR BIT(15)
119#define FLEXCAN_ESR_BIT0_ERR BIT(14)
120#define FLEXCAN_ESR_ACK_ERR BIT(13)
121#define FLEXCAN_ESR_CRC_ERR BIT(12)
122#define FLEXCAN_ESR_FRM_ERR BIT(11)
123#define FLEXCAN_ESR_STF_ERR BIT(10)
124#define FLEXCAN_ESR_TX_WRN BIT(9)
125#define FLEXCAN_ESR_RX_WRN BIT(8)
126#define FLEXCAN_ESR_IDLE BIT(7)
127#define FLEXCAN_ESR_TXRX BIT(6)
128#define FLEXCAN_EST_FLT_CONF_SHIFT (4)
129#define FLEXCAN_ESR_FLT_CONF_MASK (0x3 << FLEXCAN_EST_FLT_CONF_SHIFT)
130#define FLEXCAN_ESR_FLT_CONF_ACTIVE (0x0 << FLEXCAN_EST_FLT_CONF_SHIFT)
131#define FLEXCAN_ESR_FLT_CONF_PASSIVE (0x1 << FLEXCAN_EST_FLT_CONF_SHIFT)
132#define FLEXCAN_ESR_BOFF_INT BIT(2)
133#define FLEXCAN_ESR_ERR_INT BIT(1)
134#define FLEXCAN_ESR_WAK_INT BIT(0)
135#define FLEXCAN_ESR_ERR_BUS \
136 (FLEXCAN_ESR_BIT1_ERR | FLEXCAN_ESR_BIT0_ERR | \
137 FLEXCAN_ESR_ACK_ERR | FLEXCAN_ESR_CRC_ERR | \
138 FLEXCAN_ESR_FRM_ERR | FLEXCAN_ESR_STF_ERR)
139#define FLEXCAN_ESR_ERR_STATE \
140 (FLEXCAN_ESR_TWRN_INT | FLEXCAN_ESR_RWRN_INT | FLEXCAN_ESR_BOFF_INT)
141#define FLEXCAN_ESR_ERR_ALL \
142 (FLEXCAN_ESR_ERR_BUS | FLEXCAN_ESR_ERR_STATE)
Wolfgang Grandegger6e9d5542011-12-12 16:09:28 +0100143#define FLEXCAN_ESR_ALL_INT \
144 (FLEXCAN_ESR_TWRN_INT | FLEXCAN_ESR_RWRN_INT | \
145 FLEXCAN_ESR_BOFF_INT | FLEXCAN_ESR_ERR_INT)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200146
147/* FLEXCAN interrupt flag register (IFLAG) bits */
David Jander25e92442014-09-03 16:47:22 +0200148/* Errata ERR005829 step7: Reserve first valid MB */
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +0200149#define FLEXCAN_TX_MB_RESERVED_OFF_FIFO 8
150#define FLEXCAN_TX_MB_OFF_FIFO 9
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200151#define FLEXCAN_TX_MB_RESERVED_OFF_TIMESTAMP 0
152#define FLEXCAN_TX_MB_OFF_TIMESTAMP 1
153#define FLEXCAN_RX_MB_OFF_TIMESTAMP_FIRST (FLEXCAN_TX_MB_OFF_TIMESTAMP + 1)
154#define FLEXCAN_RX_MB_OFF_TIMESTAMP_LAST 63
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +0200155#define FLEXCAN_IFLAG_MB(x) BIT(x)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200156#define FLEXCAN_IFLAG_RX_FIFO_OVERFLOW BIT(7)
157#define FLEXCAN_IFLAG_RX_FIFO_WARN BIT(6)
158#define FLEXCAN_IFLAG_RX_FIFO_AVAILABLE BIT(5)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200159
160/* FLEXCAN message buffers */
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200161#define FLEXCAN_MB_CODE_MASK (0xf << 24)
162#define FLEXCAN_MB_CODE_RX_BUSY_BIT (0x1 << 24)
Marc Kleine-Buddec32fe4a2014-09-16 12:39:28 +0200163#define FLEXCAN_MB_CODE_RX_INACTIVE (0x0 << 24)
164#define FLEXCAN_MB_CODE_RX_EMPTY (0x4 << 24)
165#define FLEXCAN_MB_CODE_RX_FULL (0x2 << 24)
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200166#define FLEXCAN_MB_CODE_RX_OVERRUN (0x6 << 24)
Marc Kleine-Buddec32fe4a2014-09-16 12:39:28 +0200167#define FLEXCAN_MB_CODE_RX_RANSWER (0xa << 24)
168
169#define FLEXCAN_MB_CODE_TX_INACTIVE (0x8 << 24)
170#define FLEXCAN_MB_CODE_TX_ABORT (0x9 << 24)
171#define FLEXCAN_MB_CODE_TX_DATA (0xc << 24)
172#define FLEXCAN_MB_CODE_TX_TANSWER (0xe << 24)
173
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200174#define FLEXCAN_MB_CNT_SRR BIT(22)
175#define FLEXCAN_MB_CNT_IDE BIT(21)
176#define FLEXCAN_MB_CNT_RTR BIT(20)
177#define FLEXCAN_MB_CNT_LENGTH(x) (((x) & 0xf) << 16)
178#define FLEXCAN_MB_CNT_TIMESTAMP(x) ((x) & 0xffff)
179
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200180#define FLEXCAN_TIMEOUT_US (50)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200181
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200182/* FLEXCAN hardware feature flags
Wolfgang Grandeggerbb698ca2012-10-10 21:10:42 +0200183 *
184 * Below is some version info we got:
David Jander8a1ce7e2014-10-10 15:04:03 +0200185 * SOC Version IP-Version Glitch- [TR]WRN_INT Memory err RTR re-
186 * Filter? connected? detection ception in MB
187 * MX25 FlexCAN2 03.00.00.00 no no no no
188 * MX28 FlexCAN2 03.00.04.00 yes yes no no
189 * MX35 FlexCAN2 03.00.00.00 no no no no
190 * MX53 FlexCAN2 03.00.00.00 yes no no no
191 * MX6s FlexCAN3 10.00.12.00 yes yes no yes
192 * VF610 FlexCAN3 ? no yes yes yes?
Wolfgang Grandeggerbb698ca2012-10-10 21:10:42 +0200193 *
194 * Some SOCs do not have the RX_WARN & TX_WARN interrupt line connected.
195 */
Marc Kleine-Buddef377bff2015-05-08 15:22:36 +0200196#define FLEXCAN_QUIRK_BROKEN_ERR_STATE BIT(1) /* [TR]WRN_INT not connected */
197#define FLEXCAN_QUIRK_DISABLE_RXFG BIT(2) /* Disable RX FIFO Global mask */
Marc Kleine-Budde9eb7aa82015-09-01 08:57:55 +0200198#define FLEXCAN_QUIRK_ENABLE_EACEN_RRS BIT(3) /* Enable EACEN and RRS bit in ctrl2 */
Marc Kleine-Budde66ddb822017-03-02 15:42:49 +0100199#define FLEXCAN_QUIRK_DISABLE_MECR BIT(4) /* Disable Memory error detection */
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200200#define FLEXCAN_QUIRK_USE_OFF_TIMESTAMP BIT(5) /* Use timestamp based offloading */
Wolfgang Grandegger4f72e5f2012-09-28 03:17:15 +0000201
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200202/* Structure of the message buffer */
203struct flexcan_mb {
204 u32 can_ctrl;
205 u32 can_id;
206 u32 data[2];
207};
208
209/* Structure of the hardware registers */
210struct flexcan_regs {
211 u32 mcr; /* 0x00 */
212 u32 ctrl; /* 0x04 */
213 u32 timer; /* 0x08 */
214 u32 _reserved1; /* 0x0c */
215 u32 rxgmask; /* 0x10 */
216 u32 rx14mask; /* 0x14 */
217 u32 rx15mask; /* 0x18 */
218 u32 ecr; /* 0x1c */
219 u32 esr; /* 0x20 */
220 u32 imask2; /* 0x24 */
221 u32 imask1; /* 0x28 */
222 u32 iflag2; /* 0x2c */
223 u32 iflag1; /* 0x30 */
Marc Kleine-Budde62d10862015-08-27 16:01:27 +0200224 union { /* 0x34 */
225 u32 gfwr_mx28; /* MX28, MX53 */
226 u32 ctrl2; /* MX6, VF610 */
227 };
Hui Wang30c1e672012-06-28 16:21:35 +0800228 u32 esr2; /* 0x38 */
229 u32 imeur; /* 0x3c */
230 u32 lrfr; /* 0x40 */
231 u32 crcr; /* 0x44 */
232 u32 rxfgmask; /* 0x48 */
233 u32 rxfir; /* 0x4c */
Stefan Agnercdce8442014-07-15 14:56:21 +0200234 u32 _reserved3[12]; /* 0x50 */
Marc Kleine-Budde1ba763d2015-08-25 10:39:19 +0200235 struct flexcan_mb mb[64]; /* 0x80 */
Marc Kleine-Budde66a6ef02014-09-17 12:50:48 +0200236 /* FIFO-mode:
237 * MB
238 * 0x080...0x08f 0 RX message buffer
239 * 0x090...0x0df 1-5 reserverd
240 * 0x0e0...0x0ff 6-7 8 entry ID table
241 * (mx25, mx28, mx35, mx53)
242 * 0x0e0...0x2df 6-7..37 8..128 entry ID table
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200243 * size conf'ed via ctrl2::RFFN
Marc Kleine-Budde66a6ef02014-09-17 12:50:48 +0200244 * (mx6, vf610)
245 */
Marc Kleine-Budde62d10862015-08-27 16:01:27 +0200246 u32 _reserved4[256]; /* 0x480 */
247 u32 rximr[64]; /* 0x880 */
248 u32 _reserved5[24]; /* 0x980 */
249 u32 gfwr_mx6; /* 0x9e0 - MX6 */
250 u32 _reserved6[63]; /* 0x9e4 */
Stefan Agnercdce8442014-07-15 14:56:21 +0200251 u32 mecr; /* 0xae0 */
252 u32 erriar; /* 0xae4 */
253 u32 erridpr; /* 0xae8 */
254 u32 errippr; /* 0xaec */
255 u32 rerrar; /* 0xaf0 */
256 u32 rerrdr; /* 0xaf4 */
257 u32 rerrsynr; /* 0xaf8 */
258 u32 errsr; /* 0xafc */
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200259};
260
Hui Wang30c1e672012-06-28 16:21:35 +0800261struct flexcan_devtype_data {
Marc Kleine-Buddef377bff2015-05-08 15:22:36 +0200262 u32 quirks; /* quirks needed for different IP cores */
Hui Wang30c1e672012-06-28 16:21:35 +0800263};
264
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200265struct flexcan_priv {
266 struct can_priv can;
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200267 struct can_rx_offload offload;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200268
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200269 struct flexcan_regs __iomem *regs;
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +0200270 struct flexcan_mb __iomem *tx_mb;
271 struct flexcan_mb __iomem *tx_mb_reserved;
272 u8 tx_mb_idx;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200273 u32 reg_ctrl_default;
Marc Kleine-Budde28ac7dc2015-08-04 13:46:10 +0200274 u32 reg_imask1_default;
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200275 u32 reg_imask2_default;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200276
Steffen Trumtrar3d42a372012-07-17 16:14:34 +0200277 struct clk *clk_ipg;
278 struct clk *clk_per;
Marc Kleine-Buddedda0b3b2012-07-13 14:52:48 +0200279 const struct flexcan_devtype_data *devtype_data;
Fabio Estevamb7c41142013-06-10 23:12:57 -0300280 struct regulator *reg_xceiver;
Hui Wang30c1e672012-06-28 16:21:35 +0800281};
282
Marc Kleine-Buddea3c11a72016-07-04 14:45:44 +0200283static const struct flexcan_devtype_data fsl_p1010_devtype_data = {
Marc Kleine-Buddef377bff2015-05-08 15:22:36 +0200284 .quirks = FLEXCAN_QUIRK_BROKEN_ERR_STATE,
Hui Wang30c1e672012-06-28 16:21:35 +0800285};
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200286
Marc Kleine-Buddea3c11a72016-07-04 14:45:44 +0200287static const struct flexcan_devtype_data fsl_imx28_devtype_data;
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200288
Marc Kleine-Buddea3c11a72016-07-04 14:45:44 +0200289static const struct flexcan_devtype_data fsl_imx6q_devtype_data = {
Marc Kleine-Budde096de072015-09-01 10:28:46 +0200290 .quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
291 FLEXCAN_QUIRK_USE_OFF_TIMESTAMP,
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200292};
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200293
Marc Kleine-Buddea3c11a72016-07-04 14:45:44 +0200294static const struct flexcan_devtype_data fsl_vf610_devtype_data = {
Marc Kleine-Budde9eb7aa82015-09-01 08:57:55 +0200295 .quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS |
Marc Kleine-Budde096de072015-09-01 10:28:46 +0200296 FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_USE_OFF_TIMESTAMP,
Stefan Agnercdce8442014-07-15 14:56:21 +0200297};
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200298
Marc Kleine-Budde194b9a42012-07-16 12:58:31 +0200299static const struct can_bittiming_const flexcan_bittiming_const = {
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200300 .name = DRV_NAME,
301 .tseg1_min = 4,
302 .tseg1_max = 16,
303 .tseg2_min = 2,
304 .tseg2_max = 8,
305 .sjw_max = 4,
306 .brp_min = 1,
307 .brp_max = 256,
308 .brp_inc = 1,
309};
310
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200311/* Abstract off the read/write for arm versus ppc. This
Arnd Bergmann0e4b9492014-01-14 11:44:09 +0100312 * assumes that PPC uses big-endian registers and everything
313 * else uses little-endian registers, independent of CPU
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200314 * endianness.
holt@sgi.com61e271e2011-08-16 17:32:20 +0000315 */
Arnd Bergmann0e4b9492014-01-14 11:44:09 +0100316#if defined(CONFIG_PPC)
holt@sgi.com61e271e2011-08-16 17:32:20 +0000317static inline u32 flexcan_read(void __iomem *addr)
318{
319 return in_be32(addr);
320}
321
322static inline void flexcan_write(u32 val, void __iomem *addr)
323{
324 out_be32(addr, val);
325}
326#else
327static inline u32 flexcan_read(void __iomem *addr)
328{
329 return readl(addr);
330}
331
332static inline void flexcan_write(u32 val, void __iomem *addr)
333{
334 writel(val, addr);
335}
336#endif
337
Marc Kleine-Buddef0036982014-02-28 17:18:27 +0100338static inline int flexcan_transceiver_enable(const struct flexcan_priv *priv)
339{
340 if (!priv->reg_xceiver)
341 return 0;
342
343 return regulator_enable(priv->reg_xceiver);
344}
345
346static inline int flexcan_transceiver_disable(const struct flexcan_priv *priv)
347{
348 if (!priv->reg_xceiver)
349 return 0;
350
351 return regulator_disable(priv->reg_xceiver);
352}
353
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100354static int flexcan_chip_enable(struct flexcan_priv *priv)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200355{
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200356 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100357 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200358 u32 reg;
359
holt@sgi.com61e271e2011-08-16 17:32:20 +0000360 reg = flexcan_read(&regs->mcr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200361 reg &= ~FLEXCAN_MCR_MDIS;
holt@sgi.com61e271e2011-08-16 17:32:20 +0000362 flexcan_write(reg, &regs->mcr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200363
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100364 while (timeout-- && (flexcan_read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK))
David Jander8badd652014-08-27 12:02:16 +0200365 udelay(10);
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100366
367 if (flexcan_read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK)
368 return -ETIMEDOUT;
369
370 return 0;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200371}
372
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100373static int flexcan_chip_disable(struct flexcan_priv *priv)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200374{
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200375 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100376 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200377 u32 reg;
378
holt@sgi.com61e271e2011-08-16 17:32:20 +0000379 reg = flexcan_read(&regs->mcr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200380 reg |= FLEXCAN_MCR_MDIS;
holt@sgi.com61e271e2011-08-16 17:32:20 +0000381 flexcan_write(reg, &regs->mcr);
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100382
383 while (timeout-- && !(flexcan_read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK))
David Jander8badd652014-08-27 12:02:16 +0200384 udelay(10);
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100385
386 if (!(flexcan_read(&regs->mcr) & FLEXCAN_MCR_LPM_ACK))
387 return -ETIMEDOUT;
388
389 return 0;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200390}
391
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100392static int flexcan_chip_freeze(struct flexcan_priv *priv)
393{
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200394 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100395 unsigned int timeout = 1000 * 1000 * 10 / priv->can.bittiming.bitrate;
396 u32 reg;
397
398 reg = flexcan_read(&regs->mcr);
399 reg |= FLEXCAN_MCR_HALT;
400 flexcan_write(reg, &regs->mcr);
401
402 while (timeout-- && !(flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
David Jander8badd652014-08-27 12:02:16 +0200403 udelay(100);
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100404
405 if (!(flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
406 return -ETIMEDOUT;
407
408 return 0;
409}
410
411static int flexcan_chip_unfreeze(struct flexcan_priv *priv)
412{
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200413 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100414 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
415 u32 reg;
416
417 reg = flexcan_read(&regs->mcr);
418 reg &= ~FLEXCAN_MCR_HALT;
419 flexcan_write(reg, &regs->mcr);
420
421 while (timeout-- && (flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK))
David Jander8badd652014-08-27 12:02:16 +0200422 udelay(10);
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100423
424 if (flexcan_read(&regs->mcr) & FLEXCAN_MCR_FRZ_ACK)
425 return -ETIMEDOUT;
426
427 return 0;
428}
429
Marc Kleine-Budde4b5b8222014-02-28 15:16:59 +0100430static int flexcan_chip_softreset(struct flexcan_priv *priv)
431{
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200432 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Budde4b5b8222014-02-28 15:16:59 +0100433 unsigned int timeout = FLEXCAN_TIMEOUT_US / 10;
434
435 flexcan_write(FLEXCAN_MCR_SOFTRST, &regs->mcr);
436 while (timeout-- && (flexcan_read(&regs->mcr) & FLEXCAN_MCR_SOFTRST))
David Jander8badd652014-08-27 12:02:16 +0200437 udelay(10);
Marc Kleine-Budde4b5b8222014-02-28 15:16:59 +0100438
439 if (flexcan_read(&regs->mcr) & FLEXCAN_MCR_SOFTRST)
440 return -ETIMEDOUT;
441
442 return 0;
443}
444
Stefan Agnerec56acf2014-07-15 14:56:20 +0200445static int __flexcan_get_berr_counter(const struct net_device *dev,
446 struct can_berr_counter *bec)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200447{
448 const struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200449 struct flexcan_regs __iomem *regs = priv->regs;
holt@sgi.com61e271e2011-08-16 17:32:20 +0000450 u32 reg = flexcan_read(&regs->ecr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200451
452 bec->txerr = (reg >> 0) & 0xff;
453 bec->rxerr = (reg >> 8) & 0xff;
454
455 return 0;
456}
457
Stefan Agnerec56acf2014-07-15 14:56:20 +0200458static int flexcan_get_berr_counter(const struct net_device *dev,
459 struct can_berr_counter *bec)
460{
461 const struct flexcan_priv *priv = netdev_priv(dev);
462 int err;
463
464 err = clk_prepare_enable(priv->clk_ipg);
465 if (err)
466 return err;
467
468 err = clk_prepare_enable(priv->clk_per);
469 if (err)
470 goto out_disable_ipg;
471
472 err = __flexcan_get_berr_counter(dev, bec);
473
474 clk_disable_unprepare(priv->clk_per);
475 out_disable_ipg:
476 clk_disable_unprepare(priv->clk_ipg);
477
478 return err;
479}
480
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200481static int flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev)
482{
483 const struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200484 struct can_frame *cf = (struct can_frame *)skb->data;
485 u32 can_id;
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200486 u32 data;
Marc Kleine-Budde10d089b2014-09-23 11:18:11 +0200487 u32 ctrl = FLEXCAN_MB_CODE_TX_DATA | (cf->can_dlc << 16);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200488
489 if (can_dropped_invalid_skb(dev, skb))
490 return NETDEV_TX_OK;
491
492 netif_stop_queue(dev);
493
494 if (cf->can_id & CAN_EFF_FLAG) {
495 can_id = cf->can_id & CAN_EFF_MASK;
496 ctrl |= FLEXCAN_MB_CNT_IDE | FLEXCAN_MB_CNT_SRR;
497 } else {
498 can_id = (cf->can_id & CAN_SFF_MASK) << 18;
499 }
500
501 if (cf->can_id & CAN_RTR_FLAG)
502 ctrl |= FLEXCAN_MB_CNT_RTR;
503
504 if (cf->can_dlc > 0) {
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200505 data = be32_to_cpup((__be32 *)&cf->data[0]);
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +0200506 flexcan_write(data, &priv->tx_mb->data[0]);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200507 }
508 if (cf->can_dlc > 3) {
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200509 data = be32_to_cpup((__be32 *)&cf->data[4]);
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +0200510 flexcan_write(data, &priv->tx_mb->data[1]);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200511 }
512
Reuben Dowle9a123492011-11-01 11:18:03 +1300513 can_put_echo_skb(skb, dev, 0);
514
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +0200515 flexcan_write(can_id, &priv->tx_mb->can_id);
516 flexcan_write(ctrl, &priv->tx_mb->can_ctrl);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200517
David Jander25e92442014-09-03 16:47:22 +0200518 /* Errata ERR005829 step8:
519 * Write twice INACTIVE(0x8) code to first MB.
520 */
521 flexcan_write(FLEXCAN_MB_CODE_TX_INACTIVE,
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +0200522 &priv->tx_mb_reserved->can_ctrl);
David Jander25e92442014-09-03 16:47:22 +0200523 flexcan_write(FLEXCAN_MB_CODE_TX_INACTIVE,
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +0200524 &priv->tx_mb_reserved->can_ctrl);
David Jander25e92442014-09-03 16:47:22 +0200525
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200526 return NETDEV_TX_OK;
527}
528
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200529static void flexcan_irq_bus_err(struct net_device *dev, u32 reg_esr)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200530{
531 struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Buddea5c02f662017-01-18 11:38:26 +0100532 struct sk_buff *skb;
533 struct can_frame *cf;
Marc Kleine-Budded166f562017-01-17 17:33:46 +0100534 bool rx_errors = false, tx_errors = false;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200535
Marc Kleine-Buddea5c02f662017-01-18 11:38:26 +0100536 skb = alloc_can_err_skb(dev, &cf);
537 if (unlikely(!skb))
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200538 return;
Marc Kleine-Buddea5c02f662017-01-18 11:38:26 +0100539
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200540 cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR;
541
542 if (reg_esr & FLEXCAN_ESR_BIT1_ERR) {
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100543 netdev_dbg(dev, "BIT1_ERR irq\n");
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200544 cf->data[2] |= CAN_ERR_PROT_BIT1;
Marc Kleine-Budded166f562017-01-17 17:33:46 +0100545 tx_errors = true;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200546 }
547 if (reg_esr & FLEXCAN_ESR_BIT0_ERR) {
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100548 netdev_dbg(dev, "BIT0_ERR irq\n");
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200549 cf->data[2] |= CAN_ERR_PROT_BIT0;
Marc Kleine-Budded166f562017-01-17 17:33:46 +0100550 tx_errors = true;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200551 }
552 if (reg_esr & FLEXCAN_ESR_ACK_ERR) {
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100553 netdev_dbg(dev, "ACK_ERR irq\n");
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200554 cf->can_id |= CAN_ERR_ACK;
Oliver Hartkoppffd461f2015-11-21 18:41:20 +0100555 cf->data[3] = CAN_ERR_PROT_LOC_ACK;
Marc Kleine-Budded166f562017-01-17 17:33:46 +0100556 tx_errors = true;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200557 }
558 if (reg_esr & FLEXCAN_ESR_CRC_ERR) {
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100559 netdev_dbg(dev, "CRC_ERR irq\n");
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200560 cf->data[2] |= CAN_ERR_PROT_BIT;
Oliver Hartkoppffd461f2015-11-21 18:41:20 +0100561 cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ;
Marc Kleine-Budded166f562017-01-17 17:33:46 +0100562 rx_errors = true;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200563 }
564 if (reg_esr & FLEXCAN_ESR_FRM_ERR) {
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100565 netdev_dbg(dev, "FRM_ERR irq\n");
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200566 cf->data[2] |= CAN_ERR_PROT_FORM;
Marc Kleine-Budded166f562017-01-17 17:33:46 +0100567 rx_errors = true;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200568 }
569 if (reg_esr & FLEXCAN_ESR_STF_ERR) {
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100570 netdev_dbg(dev, "STF_ERR irq\n");
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200571 cf->data[2] |= CAN_ERR_PROT_STUFF;
Marc Kleine-Budded166f562017-01-17 17:33:46 +0100572 rx_errors = true;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200573 }
574
575 priv->can.can_stats.bus_error++;
576 if (rx_errors)
577 dev->stats.rx_errors++;
578 if (tx_errors)
579 dev->stats.tx_errors++;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200580
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200581 can_rx_offload_irq_queue_err_skb(&priv->offload, skb);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200582}
583
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200584static void flexcan_irq_state(struct net_device *dev, u32 reg_esr)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200585{
586 struct flexcan_priv *priv = netdev_priv(dev);
587 struct sk_buff *skb;
588 struct can_frame *cf;
Marc Kleine-Budde238443d2017-01-18 11:25:41 +0100589 enum can_state new_state, rx_state, tx_state;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200590 int flt;
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000591 struct can_berr_counter bec;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200592
593 flt = reg_esr & FLEXCAN_ESR_FLT_CONF_MASK;
594 if (likely(flt == FLEXCAN_ESR_FLT_CONF_ACTIVE)) {
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000595 tx_state = unlikely(reg_esr & FLEXCAN_ESR_TX_WRN) ?
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200596 CAN_STATE_ERROR_WARNING : CAN_STATE_ERROR_ACTIVE;
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000597 rx_state = unlikely(reg_esr & FLEXCAN_ESR_RX_WRN) ?
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200598 CAN_STATE_ERROR_WARNING : CAN_STATE_ERROR_ACTIVE;
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000599 new_state = max(tx_state, rx_state);
Andri Yngvason258ce802015-03-17 13:03:09 +0000600 } else {
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000601 __flexcan_get_berr_counter(dev, &bec);
Andri Yngvason258ce802015-03-17 13:03:09 +0000602 new_state = flt == FLEXCAN_ESR_FLT_CONF_PASSIVE ?
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200603 CAN_STATE_ERROR_PASSIVE : CAN_STATE_BUS_OFF;
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000604 rx_state = bec.rxerr >= bec.txerr ? new_state : 0;
605 tx_state = bec.rxerr <= bec.txerr ? new_state : 0;
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000606 }
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200607
608 /* state hasn't changed */
609 if (likely(new_state == priv->can.state))
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200610 return;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200611
612 skb = alloc_can_err_skb(dev, &cf);
613 if (unlikely(!skb))
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200614 return;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200615
Andri Yngvason71a3aed2014-12-03 17:54:15 +0000616 can_change_state(dev, cf, tx_state, rx_state);
617
618 if (unlikely(new_state == CAN_STATE_BUS_OFF))
619 can_bus_off(dev);
620
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200621 can_rx_offload_irq_queue_err_skb(&priv->offload, skb);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200622}
623
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200624static inline struct flexcan_priv *rx_offload_to_priv(struct can_rx_offload *offload)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200625{
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200626 return container_of(offload, struct flexcan_priv, offload);
627}
628
629static unsigned int flexcan_mailbox_read(struct can_rx_offload *offload,
630 struct can_frame *cf,
631 u32 *timestamp, unsigned int n)
632{
633 struct flexcan_priv *priv = rx_offload_to_priv(offload);
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200634 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200635 struct flexcan_mb __iomem *mb = &regs->mb[n];
636 u32 reg_ctrl, reg_id, reg_iflag1;
637
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200638 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
639 u32 code;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200640
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200641 do {
642 reg_ctrl = flexcan_read(&mb->can_ctrl);
643 } while (reg_ctrl & FLEXCAN_MB_CODE_RX_BUSY_BIT);
644
645 /* is this MB empty? */
646 code = reg_ctrl & FLEXCAN_MB_CODE_MASK;
647 if ((code != FLEXCAN_MB_CODE_RX_FULL) &&
648 (code != FLEXCAN_MB_CODE_RX_OVERRUN))
649 return 0;
650
651 if (code == FLEXCAN_MB_CODE_RX_OVERRUN) {
652 /* This MB was overrun, we lost data */
653 offload->dev->stats.rx_over_errors++;
654 offload->dev->stats.rx_errors++;
655 }
656 } else {
657 reg_iflag1 = flexcan_read(&regs->iflag1);
658 if (!(reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_AVAILABLE))
659 return 0;
660
661 reg_ctrl = flexcan_read(&mb->can_ctrl);
662 }
663
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200664 /* increase timstamp to full 32 bit */
665 *timestamp = reg_ctrl << 16;
666
holt@sgi.com61e271e2011-08-16 17:32:20 +0000667 reg_id = flexcan_read(&mb->can_id);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200668 if (reg_ctrl & FLEXCAN_MB_CNT_IDE)
669 cf->can_id = ((reg_id >> 0) & CAN_EFF_MASK) | CAN_EFF_FLAG;
670 else
671 cf->can_id = (reg_id >> 18) & CAN_SFF_MASK;
672
673 if (reg_ctrl & FLEXCAN_MB_CNT_RTR)
674 cf->can_id |= CAN_RTR_FLAG;
675 cf->can_dlc = get_can_dlc((reg_ctrl >> 16) & 0xf);
676
holt@sgi.com61e271e2011-08-16 17:32:20 +0000677 *(__be32 *)(cf->data + 0) = cpu_to_be32(flexcan_read(&mb->data[0]));
678 *(__be32 *)(cf->data + 4) = cpu_to_be32(flexcan_read(&mb->data[1]));
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200679
680 /* mark as read */
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200681 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
682 /* Clear IRQ */
683 if (n < 32)
684 flexcan_write(BIT(n), &regs->iflag1);
685 else
686 flexcan_write(BIT(n - 32), &regs->iflag2);
687 } else {
688 flexcan_write(FLEXCAN_IFLAG_RX_FIFO_AVAILABLE, &regs->iflag1);
689 flexcan_read(&regs->timer);
690 }
Fabio Baltieriadccadb2012-12-18 18:50:58 +0100691
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200692 return 1;
693}
694
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200695
696static inline u64 flexcan_read_reg_iflag_rx(struct flexcan_priv *priv)
697{
698 struct flexcan_regs __iomem *regs = priv->regs;
699 u32 iflag1, iflag2;
700
701 iflag2 = flexcan_read(&regs->iflag2) & priv->reg_imask2_default;
702 iflag1 = flexcan_read(&regs->iflag1) & priv->reg_imask1_default &
703 ~FLEXCAN_IFLAG_MB(priv->tx_mb_idx);
704
705 return (u64)iflag2 << 32 | iflag1;
706}
707
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200708static irqreturn_t flexcan_irq(int irq, void *dev_id)
709{
710 struct net_device *dev = dev_id;
711 struct net_device_stats *stats = &dev->stats;
712 struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200713 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Buddedd2f1222017-01-18 11:45:14 +0100714 irqreturn_t handled = IRQ_NONE;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200715 u32 reg_iflag1, reg_esr;
716
holt@sgi.com61e271e2011-08-16 17:32:20 +0000717 reg_iflag1 = flexcan_read(&regs->iflag1);
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200718
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200719 /* reception interrupt */
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200720 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
721 u64 reg_iflag;
722 int ret;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200723
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200724 while ((reg_iflag = flexcan_read_reg_iflag_rx(priv))) {
725 handled = IRQ_HANDLED;
726 ret = can_rx_offload_irq_offload_timestamp(&priv->offload,
727 reg_iflag);
728 if (!ret)
729 break;
730 }
731 } else {
732 if (reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_AVAILABLE) {
733 handled = IRQ_HANDLED;
734 can_rx_offload_irq_offload_fifo(&priv->offload);
735 }
736
737 /* FIFO overflow interrupt */
738 if (reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_OVERFLOW) {
739 handled = IRQ_HANDLED;
740 flexcan_write(FLEXCAN_IFLAG_RX_FIFO_OVERFLOW, &regs->iflag1);
741 dev->stats.rx_over_errors++;
742 dev->stats.rx_errors++;
743 }
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200744 }
745
746 /* transmission complete interrupt */
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +0200747 if (reg_iflag1 & FLEXCAN_IFLAG_MB(priv->tx_mb_idx)) {
Marc Kleine-Buddedd2f1222017-01-18 11:45:14 +0100748 handled = IRQ_HANDLED;
Reuben Dowle9a123492011-11-01 11:18:03 +1300749 stats->tx_bytes += can_get_echo_skb(dev, 0);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200750 stats->tx_packets++;
Fabio Baltieriadccadb2012-12-18 18:50:58 +0100751 can_led_event(dev, CAN_LED_EVENT_TX);
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200752
753 /* after sending a RTR frame MB is in RX mode */
Marc Kleine-Buddede594482014-09-16 15:31:27 +0200754 flexcan_write(FLEXCAN_MB_CODE_TX_INACTIVE,
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +0200755 &priv->tx_mb->can_ctrl);
756 flexcan_write(FLEXCAN_IFLAG_MB(priv->tx_mb_idx), &regs->iflag1);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200757 netif_wake_queue(dev);
758 }
759
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200760 reg_esr = flexcan_read(&regs->esr);
761
Marc Kleine-Buddedd2f1222017-01-18 11:45:14 +0100762 /* ACK all bus error and state change IRQ sources */
763 if (reg_esr & FLEXCAN_ESR_ALL_INT) {
764 handled = IRQ_HANDLED;
765 flexcan_write(reg_esr & FLEXCAN_ESR_ALL_INT, &regs->esr);
766 }
767
Marc Kleine-Budde30164752015-05-10 15:26:58 +0200768 /* state change interrupt */
769 if (reg_esr & FLEXCAN_ESR_ERR_STATE)
770 flexcan_irq_state(dev, reg_esr);
771
772 /* bus error IRQ - handle if bus error reporting is activated */
773 if ((reg_esr & FLEXCAN_ESR_ERR_BUS) &&
774 (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING))
775 flexcan_irq_bus_err(dev, reg_esr);
776
Marc Kleine-Buddedd2f1222017-01-18 11:45:14 +0100777 return handled;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200778}
779
780static void flexcan_set_bittiming(struct net_device *dev)
781{
782 const struct flexcan_priv *priv = netdev_priv(dev);
783 const struct can_bittiming *bt = &priv->can.bittiming;
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200784 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200785 u32 reg;
786
holt@sgi.com61e271e2011-08-16 17:32:20 +0000787 reg = flexcan_read(&regs->ctrl);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200788 reg &= ~(FLEXCAN_CTRL_PRESDIV(0xff) |
789 FLEXCAN_CTRL_RJW(0x3) |
790 FLEXCAN_CTRL_PSEG1(0x7) |
791 FLEXCAN_CTRL_PSEG2(0x7) |
792 FLEXCAN_CTRL_PROPSEG(0x7) |
793 FLEXCAN_CTRL_LPB |
794 FLEXCAN_CTRL_SMP |
795 FLEXCAN_CTRL_LOM);
796
797 reg |= FLEXCAN_CTRL_PRESDIV(bt->brp - 1) |
798 FLEXCAN_CTRL_PSEG1(bt->phase_seg1 - 1) |
799 FLEXCAN_CTRL_PSEG2(bt->phase_seg2 - 1) |
800 FLEXCAN_CTRL_RJW(bt->sjw - 1) |
801 FLEXCAN_CTRL_PROPSEG(bt->prop_seg - 1);
802
803 if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK)
804 reg |= FLEXCAN_CTRL_LPB;
805 if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
806 reg |= FLEXCAN_CTRL_LOM;
807 if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES)
808 reg |= FLEXCAN_CTRL_SMP;
809
Lucas Stach7a4b6c82015-08-07 17:16:03 +0200810 netdev_dbg(dev, "writing ctrl=0x%08x\n", reg);
holt@sgi.com61e271e2011-08-16 17:32:20 +0000811 flexcan_write(reg, &regs->ctrl);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200812
813 /* print chip status */
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100814 netdev_dbg(dev, "%s: mcr=0x%08x ctrl=0x%08x\n", __func__,
815 flexcan_read(&regs->mcr), flexcan_read(&regs->ctrl));
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200816}
817
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200818/* flexcan_chip_start
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200819 *
820 * this functions is entered with clocks enabled
821 *
822 */
823static int flexcan_chip_start(struct net_device *dev)
824{
825 struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Budde89af8742015-05-08 09:32:58 +0200826 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Budde6f75fce2014-09-23 11:03:01 +0200827 u32 reg_mcr, reg_ctrl, reg_ctrl2, reg_mecr;
David S. Miller1f6d8032014-09-23 12:09:27 -0400828 int err, i;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200829
830 /* enable module */
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +0100831 err = flexcan_chip_enable(priv);
832 if (err)
833 return err;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200834
835 /* soft reset */
Marc Kleine-Budde4b5b8222014-02-28 15:16:59 +0100836 err = flexcan_chip_softreset(priv);
837 if (err)
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100838 goto out_chip_disable;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200839
840 flexcan_set_bittiming(dev);
841
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200842 /* MCR
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200843 *
844 * enable freeze
845 * enable fifo
846 * halt now
847 * only supervisor access
848 * enable warning int
Reuben Dowle9a123492011-11-01 11:18:03 +1300849 * disable local echo
Marc Kleine-Budde4bd888a2015-08-31 21:03:29 +0200850 * enable individual RX masking
Marc Kleine-Budde749de6f2015-08-31 21:32:34 +0200851 * choose format C
852 * set max mailbox number
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200853 */
holt@sgi.com61e271e2011-08-16 17:32:20 +0000854 reg_mcr = flexcan_read(&regs->mcr);
Marc Kleine-Budded5a7b402013-10-04 10:52:36 +0200855 reg_mcr &= ~FLEXCAN_MCR_MAXMB(0xff);
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200856 reg_mcr |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT | FLEXCAN_MCR_SUPV |
857 FLEXCAN_MCR_WRN_EN | FLEXCAN_MCR_SRX_DIS | FLEXCAN_MCR_IRMQ |
858 FLEXCAN_MCR_IDAM_C;
859
860 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
861 reg_mcr &= ~FLEXCAN_MCR_FEN;
862 reg_mcr |= FLEXCAN_MCR_MAXMB(priv->offload.mb_last);
863 } else {
864 reg_mcr |= FLEXCAN_MCR_FEN |
865 FLEXCAN_MCR_MAXMB(priv->tx_mb_idx);
866 }
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100867 netdev_dbg(dev, "%s: writing mcr=0x%08x", __func__, reg_mcr);
holt@sgi.com61e271e2011-08-16 17:32:20 +0000868 flexcan_write(reg_mcr, &regs->mcr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200869
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200870 /* CTRL
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200871 *
872 * disable timer sync feature
873 *
874 * disable auto busoff recovery
875 * transmit lowest buffer first
876 *
877 * enable tx and rx warning interrupt
878 * enable bus off interrupt
879 * (== FLEXCAN_CTRL_ERR_STATE)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200880 */
holt@sgi.com61e271e2011-08-16 17:32:20 +0000881 reg_ctrl = flexcan_read(&regs->ctrl);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200882 reg_ctrl &= ~FLEXCAN_CTRL_TSYN;
883 reg_ctrl |= FLEXCAN_CTRL_BOFF_REC | FLEXCAN_CTRL_LBUF |
Wolfgang Grandegger4f72e5f2012-09-28 03:17:15 +0000884 FLEXCAN_CTRL_ERR_STATE;
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200885
886 /* enable the "error interrupt" (FLEXCAN_CTRL_ERR_MSK),
Wolfgang Grandegger4f72e5f2012-09-28 03:17:15 +0000887 * on most Flexcan cores, too. Otherwise we don't get
888 * any error warning or passive interrupts.
889 */
Marc Kleine-Buddef377bff2015-05-08 15:22:36 +0200890 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_BROKEN_ERR_STATE ||
Wolfgang Grandegger4f72e5f2012-09-28 03:17:15 +0000891 priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)
892 reg_ctrl |= FLEXCAN_CTRL_ERR_MSK;
Alexander Steinbc03a542014-08-12 10:47:21 +0200893 else
894 reg_ctrl &= ~FLEXCAN_CTRL_ERR_MSK;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200895
896 /* save for later use */
897 priv->reg_ctrl_default = reg_ctrl;
Marc Kleine-Budde6fa7da22015-08-27 14:24:48 +0200898 /* leave interrupts disabled for now */
899 reg_ctrl &= ~FLEXCAN_CTRL_ERR_ALL;
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100900 netdev_dbg(dev, "%s: writing ctrl=0x%08x", __func__, reg_ctrl);
holt@sgi.com61e271e2011-08-16 17:32:20 +0000901 flexcan_write(reg_ctrl, &regs->ctrl);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200902
Marc Kleine-Budde9eb7aa82015-09-01 08:57:55 +0200903 if ((priv->devtype_data->quirks & FLEXCAN_QUIRK_ENABLE_EACEN_RRS)) {
904 reg_ctrl2 = flexcan_read(&regs->ctrl2);
905 reg_ctrl2 |= FLEXCAN_CTRL2_EACEN | FLEXCAN_CTRL2_RRS;
906 flexcan_write(reg_ctrl2, &regs->ctrl2);
907 }
908
David Janderfc05b882014-08-27 11:58:05 +0200909 /* clear and invalidate all mailboxes first */
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +0200910 for (i = priv->tx_mb_idx; i < ARRAY_SIZE(regs->mb); i++) {
David Janderfc05b882014-08-27 11:58:05 +0200911 flexcan_write(FLEXCAN_MB_CODE_RX_INACTIVE,
Marc Kleine-Budde1ba763d2015-08-25 10:39:19 +0200912 &regs->mb[i].can_ctrl);
David Janderfc05b882014-08-27 11:58:05 +0200913 }
914
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200915 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
916 for (i = priv->offload.mb_first; i <= priv->offload.mb_last; i++)
917 flexcan_write(FLEXCAN_MB_CODE_RX_EMPTY,
918 &regs->mb[i].can_ctrl);
919 }
920
David Jander25e92442014-09-03 16:47:22 +0200921 /* Errata ERR005829: mark first TX mailbox as INACTIVE */
922 flexcan_write(FLEXCAN_MB_CODE_TX_INACTIVE,
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +0200923 &priv->tx_mb_reserved->can_ctrl);
David Jander25e92442014-09-03 16:47:22 +0200924
Marc Kleine-Buddec32fe4a2014-09-16 12:39:28 +0200925 /* mark TX mailbox as INACTIVE */
926 flexcan_write(FLEXCAN_MB_CODE_TX_INACTIVE,
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +0200927 &priv->tx_mb->can_ctrl);
Marc Kleine-Budded5a7b402013-10-04 10:52:36 +0200928
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200929 /* acceptance mask/acceptance code (accept everything) */
holt@sgi.com61e271e2011-08-16 17:32:20 +0000930 flexcan_write(0x0, &regs->rxgmask);
931 flexcan_write(0x0, &regs->rx14mask);
932 flexcan_write(0x0, &regs->rx15mask);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200933
Marc Kleine-Buddef377bff2015-05-08 15:22:36 +0200934 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_DISABLE_RXFG)
Hui Wang30c1e672012-06-28 16:21:35 +0800935 flexcan_write(0x0, &regs->rxfgmask);
936
Marc Kleine-Budde4bd888a2015-08-31 21:03:29 +0200937 /* clear acceptance filters */
938 for (i = 0; i < ARRAY_SIZE(regs->mb); i++)
939 flexcan_write(0, &regs->rximr[i]);
940
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200941 /* On Vybrid, disable memory error detection interrupts
Stefan Agnercdce8442014-07-15 14:56:21 +0200942 * and freeze mode.
943 * This also works around errata e5295 which generates
944 * false positive memory errors and put the device in
945 * freeze mode.
946 */
Marc Kleine-Buddef377bff2015-05-08 15:22:36 +0200947 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_DISABLE_MECR) {
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200948 /* Follow the protocol as described in "Detection
Stefan Agnercdce8442014-07-15 14:56:21 +0200949 * and Correction of Memory Errors" to write to
950 * MECR register
951 */
Marc Kleine-Budde6f75fce2014-09-23 11:03:01 +0200952 reg_ctrl2 = flexcan_read(&regs->ctrl2);
953 reg_ctrl2 |= FLEXCAN_CTRL2_ECRWRE;
954 flexcan_write(reg_ctrl2, &regs->ctrl2);
Stefan Agnercdce8442014-07-15 14:56:21 +0200955
956 reg_mecr = flexcan_read(&regs->mecr);
957 reg_mecr &= ~FLEXCAN_MECR_ECRWRDIS;
958 flexcan_write(reg_mecr, &regs->mecr);
959 reg_mecr &= ~(FLEXCAN_MECR_NCEFAFRZ | FLEXCAN_MECR_HANCEI_MSK |
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200960 FLEXCAN_MECR_FANCEI_MSK);
Stefan Agnercdce8442014-07-15 14:56:21 +0200961 flexcan_write(reg_mecr, &regs->mecr);
962 }
963
Marc Kleine-Buddef0036982014-02-28 17:18:27 +0100964 err = flexcan_transceiver_enable(priv);
965 if (err)
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100966 goto out_chip_disable;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200967
968 /* synchronize with the can bus */
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100969 err = flexcan_chip_unfreeze(priv);
970 if (err)
971 goto out_transceiver_disable;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200972
973 priv->can.state = CAN_STATE_ERROR_ACTIVE;
974
Marc Kleine-Budde6fa7da22015-08-27 14:24:48 +0200975 /* enable interrupts atomically */
976 disable_irq(dev->irq);
977 flexcan_write(priv->reg_ctrl_default, &regs->ctrl);
Marc Kleine-Budde28ac7dc2015-08-04 13:46:10 +0200978 flexcan_write(priv->reg_imask1_default, &regs->imask1);
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +0200979 flexcan_write(priv->reg_imask2_default, &regs->imask2);
Marc Kleine-Budde6fa7da22015-08-27 14:24:48 +0200980 enable_irq(dev->irq);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200981
982 /* print chip status */
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +0100983 netdev_dbg(dev, "%s: reading mcr=0x%08x ctrl=0x%08x\n", __func__,
984 flexcan_read(&regs->mcr), flexcan_read(&regs->ctrl));
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200985
986 return 0;
987
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +0100988 out_transceiver_disable:
989 flexcan_transceiver_disable(priv);
990 out_chip_disable:
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200991 flexcan_chip_disable(priv);
992 return err;
993}
994
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +0200995/* flexcan_chip_stop
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200996 *
997 * this functions is entered with clocks enabled
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +0200998 */
999static void flexcan_chip_stop(struct net_device *dev)
1000{
1001 struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Budde89af8742015-05-08 09:32:58 +02001002 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001003
Marc Kleine-Buddeb1aa1c72014-02-28 17:08:21 +01001004 /* freeze + disable module */
1005 flexcan_chip_freeze(priv);
1006 flexcan_chip_disable(priv);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001007
Marc Kleine-Budde5be93bd2014-02-19 12:00:51 +01001008 /* Disable all interrupts */
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +02001009 flexcan_write(0, &regs->imask2);
Marc Kleine-Budde5be93bd2014-02-19 12:00:51 +01001010 flexcan_write(0, &regs->imask1);
1011 flexcan_write(priv->reg_ctrl_default & ~FLEXCAN_CTRL_ERR_ALL,
1012 &regs->ctrl);
1013
Marc Kleine-Buddef0036982014-02-28 17:18:27 +01001014 flexcan_transceiver_disable(priv);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001015 priv->can.state = CAN_STATE_STOPPED;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001016}
1017
1018static int flexcan_open(struct net_device *dev)
1019{
1020 struct flexcan_priv *priv = netdev_priv(dev);
1021 int err;
1022
Fabio Estevamaa101812013-07-22 12:41:40 -03001023 err = clk_prepare_enable(priv->clk_ipg);
1024 if (err)
1025 return err;
1026
1027 err = clk_prepare_enable(priv->clk_per);
1028 if (err)
1029 goto out_disable_ipg;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001030
1031 err = open_candev(dev);
1032 if (err)
Fabio Estevamaa101812013-07-22 12:41:40 -03001033 goto out_disable_per;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001034
1035 err = request_irq(dev->irq, flexcan_irq, IRQF_SHARED, dev->name, dev);
1036 if (err)
1037 goto out_close;
1038
1039 /* start chip and queuing */
1040 err = flexcan_chip_start(dev);
1041 if (err)
Marc Kleine-Budde7e9e1482014-02-28 14:52:01 +01001042 goto out_free_irq;
Fabio Baltieriadccadb2012-12-18 18:50:58 +01001043
1044 can_led_event(dev, CAN_LED_EVENT_OPEN);
1045
Marc Kleine-Budde30164752015-05-10 15:26:58 +02001046 can_rx_offload_enable(&priv->offload);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001047 netif_start_queue(dev);
1048
1049 return 0;
1050
Marc Kleine-Budde7e9e1482014-02-28 14:52:01 +01001051 out_free_irq:
1052 free_irq(dev->irq, dev);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001053 out_close:
1054 close_candev(dev);
Fabio Estevamaa101812013-07-22 12:41:40 -03001055 out_disable_per:
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001056 clk_disable_unprepare(priv->clk_per);
Fabio Estevamaa101812013-07-22 12:41:40 -03001057 out_disable_ipg:
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001058 clk_disable_unprepare(priv->clk_ipg);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001059
1060 return err;
1061}
1062
1063static int flexcan_close(struct net_device *dev)
1064{
1065 struct flexcan_priv *priv = netdev_priv(dev);
1066
1067 netif_stop_queue(dev);
Marc Kleine-Budde30164752015-05-10 15:26:58 +02001068 can_rx_offload_disable(&priv->offload);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001069 flexcan_chip_stop(dev);
1070
1071 free_irq(dev->irq, dev);
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001072 clk_disable_unprepare(priv->clk_per);
1073 clk_disable_unprepare(priv->clk_ipg);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001074
1075 close_candev(dev);
1076
Fabio Baltieriadccadb2012-12-18 18:50:58 +01001077 can_led_event(dev, CAN_LED_EVENT_STOP);
1078
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001079 return 0;
1080}
1081
1082static int flexcan_set_mode(struct net_device *dev, enum can_mode mode)
1083{
1084 int err;
1085
1086 switch (mode) {
1087 case CAN_MODE_START:
1088 err = flexcan_chip_start(dev);
1089 if (err)
1090 return err;
1091
1092 netif_wake_queue(dev);
1093 break;
1094
1095 default:
1096 return -EOPNOTSUPP;
1097 }
1098
1099 return 0;
1100}
1101
1102static const struct net_device_ops flexcan_netdev_ops = {
1103 .ndo_open = flexcan_open,
1104 .ndo_stop = flexcan_close,
1105 .ndo_start_xmit = flexcan_start_xmit,
Oliver Hartkoppc971fa22014-03-07 09:23:41 +01001106 .ndo_change_mtu = can_change_mtu,
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001107};
1108
Bill Pemberton3c8ac0f2012-12-03 09:22:44 -05001109static int register_flexcandev(struct net_device *dev)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001110{
1111 struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Budde89af8742015-05-08 09:32:58 +02001112 struct flexcan_regs __iomem *regs = priv->regs;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001113 u32 reg, err;
1114
Fabio Estevamaa101812013-07-22 12:41:40 -03001115 err = clk_prepare_enable(priv->clk_ipg);
1116 if (err)
1117 return err;
1118
1119 err = clk_prepare_enable(priv->clk_per);
1120 if (err)
1121 goto out_disable_ipg;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001122
1123 /* select "bus clock", chip must be disabled */
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +01001124 err = flexcan_chip_disable(priv);
1125 if (err)
1126 goto out_disable_per;
holt@sgi.com61e271e2011-08-16 17:32:20 +00001127 reg = flexcan_read(&regs->ctrl);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001128 reg |= FLEXCAN_CTRL_CLK_SRC;
holt@sgi.com61e271e2011-08-16 17:32:20 +00001129 flexcan_write(reg, &regs->ctrl);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001130
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +01001131 err = flexcan_chip_enable(priv);
1132 if (err)
1133 goto out_chip_disable;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001134
1135 /* set freeze, halt and activate FIFO, restrict register access */
holt@sgi.com61e271e2011-08-16 17:32:20 +00001136 reg = flexcan_read(&regs->mcr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001137 reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT |
1138 FLEXCAN_MCR_FEN | FLEXCAN_MCR_SUPV;
holt@sgi.com61e271e2011-08-16 17:32:20 +00001139 flexcan_write(reg, &regs->mcr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001140
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +02001141 /* Currently we only support newer versions of this core
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +02001142 * featuring a RX hardware FIFO (although this driver doesn't
1143 * make use of it on some cores). Older cores, found on some
1144 * Coldfire derivates are not tested.
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001145 */
holt@sgi.com61e271e2011-08-16 17:32:20 +00001146 reg = flexcan_read(&regs->mcr);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001147 if (!(reg & FLEXCAN_MCR_FEN)) {
Wolfgang Grandeggeraabdfd62012-02-01 11:02:05 +01001148 netdev_err(dev, "Could not enable RX FIFO, unsupported core\n");
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001149 err = -ENODEV;
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +01001150 goto out_chip_disable;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001151 }
1152
1153 err = register_candev(dev);
1154
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001155 /* disable core and turn off clocks */
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +01001156 out_chip_disable:
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001157 flexcan_chip_disable(priv);
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +01001158 out_disable_per:
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001159 clk_disable_unprepare(priv->clk_per);
Fabio Estevamaa101812013-07-22 12:41:40 -03001160 out_disable_ipg:
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001161 clk_disable_unprepare(priv->clk_ipg);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001162
1163 return err;
1164}
1165
Bill Pemberton3c8ac0f2012-12-03 09:22:44 -05001166static void unregister_flexcandev(struct net_device *dev)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001167{
1168 unregister_candev(dev);
1169}
1170
Hui Wang30c1e672012-06-28 16:21:35 +08001171static const struct of_device_id flexcan_of_match[] = {
Hui Wang30c1e672012-06-28 16:21:35 +08001172 { .compatible = "fsl,imx6q-flexcan", .data = &fsl_imx6q_devtype_data, },
Marc Kleine-Buddee3587842013-10-03 23:51:55 +02001173 { .compatible = "fsl,imx28-flexcan", .data = &fsl_imx28_devtype_data, },
1174 { .compatible = "fsl,p1010-flexcan", .data = &fsl_p1010_devtype_data, },
Stefan Agnercdce8442014-07-15 14:56:21 +02001175 { .compatible = "fsl,vf610-flexcan", .data = &fsl_vf610_devtype_data, },
Hui Wang30c1e672012-06-28 16:21:35 +08001176 { /* sentinel */ },
1177};
Marc Kleine-Budde4358a9d2012-10-04 10:55:35 +02001178MODULE_DEVICE_TABLE(of, flexcan_of_match);
Hui Wang30c1e672012-06-28 16:21:35 +08001179
1180static const struct platform_device_id flexcan_id_table[] = {
1181 { .name = "flexcan", .driver_data = (kernel_ulong_t)&fsl_p1010_devtype_data, },
1182 { /* sentinel */ },
1183};
Marc Kleine-Budde4358a9d2012-10-04 10:55:35 +02001184MODULE_DEVICE_TABLE(platform, flexcan_id_table);
Hui Wang30c1e672012-06-28 16:21:35 +08001185
Bill Pemberton3c8ac0f2012-12-03 09:22:44 -05001186static int flexcan_probe(struct platform_device *pdev)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001187{
Hui Wang30c1e672012-06-28 16:21:35 +08001188 const struct of_device_id *of_id;
Marc Kleine-Buddedda0b3b2012-07-13 14:52:48 +02001189 const struct flexcan_devtype_data *devtype_data;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001190 struct net_device *dev;
1191 struct flexcan_priv *priv;
Andreas Werner555828e2015-03-22 17:35:52 +01001192 struct regulator *reg_xceiver;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001193 struct resource *mem;
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001194 struct clk *clk_ipg = NULL, *clk_per = NULL;
Marc Kleine-Budde89af8742015-05-08 09:32:58 +02001195 struct flexcan_regs __iomem *regs;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001196 int err, irq;
holt@sgi.com97efe9a2011-08-16 17:32:23 +00001197 u32 clock_freq = 0;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001198
Andreas Werner555828e2015-03-22 17:35:52 +01001199 reg_xceiver = devm_regulator_get(&pdev->dev, "xceiver");
1200 if (PTR_ERR(reg_xceiver) == -EPROBE_DEFER)
1201 return -EPROBE_DEFER;
1202 else if (IS_ERR(reg_xceiver))
1203 reg_xceiver = NULL;
1204
Hui Wangafc016d2012-06-28 16:21:34 +08001205 if (pdev->dev.of_node)
1206 of_property_read_u32(pdev->dev.of_node,
Marc Kleine-Budde0012e5c2015-08-06 14:53:57 +02001207 "clock-frequency", &clock_freq);
holt@sgi.com97efe9a2011-08-16 17:32:23 +00001208
1209 if (!clock_freq) {
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001210 clk_ipg = devm_clk_get(&pdev->dev, "ipg");
1211 if (IS_ERR(clk_ipg)) {
1212 dev_err(&pdev->dev, "no ipg clock defined\n");
Fabio Estevam933e4af2013-07-22 12:41:39 -03001213 return PTR_ERR(clk_ipg);
holt@sgi.com97efe9a2011-08-16 17:32:23 +00001214 }
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001215
1216 clk_per = devm_clk_get(&pdev->dev, "per");
1217 if (IS_ERR(clk_per)) {
1218 dev_err(&pdev->dev, "no per clock defined\n");
Fabio Estevam933e4af2013-07-22 12:41:39 -03001219 return PTR_ERR(clk_per);
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001220 }
Marc Kleine-Budde1a3e5172013-11-25 22:15:20 +01001221 clock_freq = clk_get_rate(clk_per);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001222 }
1223
1224 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1225 irq = platform_get_irq(pdev, 0);
Fabio Estevam933e4af2013-07-22 12:41:39 -03001226 if (irq <= 0)
1227 return -ENODEV;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001228
Marc Kleine-Budde89af8742015-05-08 09:32:58 +02001229 regs = devm_ioremap_resource(&pdev->dev, mem);
1230 if (IS_ERR(regs))
1231 return PTR_ERR(regs);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001232
Hui Wang30c1e672012-06-28 16:21:35 +08001233 of_id = of_match_device(flexcan_of_match, &pdev->dev);
1234 if (of_id) {
1235 devtype_data = of_id->data;
Marc Kleine-Budded0873e62014-03-04 22:04:22 +01001236 } else if (platform_get_device_id(pdev)->driver_data) {
Hui Wang30c1e672012-06-28 16:21:35 +08001237 devtype_data = (struct flexcan_devtype_data *)
Marc Kleine-Budded0873e62014-03-04 22:04:22 +01001238 platform_get_device_id(pdev)->driver_data;
Hui Wang30c1e672012-06-28 16:21:35 +08001239 } else {
Fabio Estevam933e4af2013-07-22 12:41:39 -03001240 return -ENODEV;
Hui Wang30c1e672012-06-28 16:21:35 +08001241 }
1242
Fabio Estevam933e4af2013-07-22 12:41:39 -03001243 dev = alloc_candev(sizeof(struct flexcan_priv), 1);
1244 if (!dev)
1245 return -ENOMEM;
1246
Marc Kleine-Budde30164752015-05-10 15:26:58 +02001247 platform_set_drvdata(pdev, dev);
1248 SET_NETDEV_DEV(dev, &pdev->dev);
1249
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001250 dev->netdev_ops = &flexcan_netdev_ops;
1251 dev->irq = irq;
Reuben Dowle9a123492011-11-01 11:18:03 +13001252 dev->flags |= IFF_ECHO;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001253
1254 priv = netdev_priv(dev);
holt@sgi.com97efe9a2011-08-16 17:32:23 +00001255 priv->can.clock.freq = clock_freq;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001256 priv->can.bittiming_const = &flexcan_bittiming_const;
1257 priv->can.do_set_mode = flexcan_set_mode;
1258 priv->can.do_get_berr_counter = flexcan_get_berr_counter;
1259 priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK |
1260 CAN_CTRLMODE_LISTENONLY | CAN_CTRLMODE_3_SAMPLES |
1261 CAN_CTRLMODE_BERR_REPORTING;
Marc Kleine-Budde89af8742015-05-08 09:32:58 +02001262 priv->regs = regs;
Steffen Trumtrar3d42a372012-07-17 16:14:34 +02001263 priv->clk_ipg = clk_ipg;
1264 priv->clk_per = clk_per;
Hui Wang30c1e672012-06-28 16:21:35 +08001265 priv->devtype_data = devtype_data;
Andreas Werner555828e2015-03-22 17:35:52 +01001266 priv->reg_xceiver = reg_xceiver;
Fabio Estevamb7c41142013-06-10 23:12:57 -03001267
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +02001268 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
1269 priv->tx_mb_idx = FLEXCAN_TX_MB_OFF_TIMESTAMP;
1270 priv->tx_mb_reserved = &regs->mb[FLEXCAN_TX_MB_RESERVED_OFF_TIMESTAMP];
1271 } else {
1272 priv->tx_mb_idx = FLEXCAN_TX_MB_OFF_FIFO;
1273 priv->tx_mb_reserved = &regs->mb[FLEXCAN_TX_MB_RESERVED_OFF_FIFO];
1274 }
Marc Kleine-Buddeb93917c2015-07-12 00:47:47 +02001275 priv->tx_mb = &regs->mb[priv->tx_mb_idx];
1276
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +02001277 priv->reg_imask1_default = FLEXCAN_IFLAG_MB(priv->tx_mb_idx);
1278 priv->reg_imask2_default = 0;
Marc Kleine-Budde28ac7dc2015-08-04 13:46:10 +02001279
Marc Kleine-Budde30164752015-05-10 15:26:58 +02001280 priv->offload.mailbox_read = flexcan_mailbox_read;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001281
Marc Kleine-Buddeb3cf53e2015-09-01 09:00:13 +02001282 if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) {
1283 u64 imask;
1284
1285 priv->offload.mb_first = FLEXCAN_RX_MB_OFF_TIMESTAMP_FIRST;
1286 priv->offload.mb_last = FLEXCAN_RX_MB_OFF_TIMESTAMP_LAST;
1287
1288 imask = GENMASK_ULL(priv->offload.mb_last, priv->offload.mb_first);
1289 priv->reg_imask1_default |= imask;
1290 priv->reg_imask2_default |= imask >> 32;
1291
1292 err = can_rx_offload_add_timestamp(dev, &priv->offload);
1293 } else {
1294 priv->reg_imask1_default |= FLEXCAN_IFLAG_RX_FIFO_OVERFLOW |
1295 FLEXCAN_IFLAG_RX_FIFO_AVAILABLE;
1296 err = can_rx_offload_add_fifo(dev, &priv->offload, FLEXCAN_NAPI_WEIGHT);
1297 }
Marc Kleine-Budde30164752015-05-10 15:26:58 +02001298 if (err)
1299 goto failed_offload;
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001300
1301 err = register_flexcandev(dev);
1302 if (err) {
1303 dev_err(&pdev->dev, "registering netdev failed\n");
1304 goto failed_register;
1305 }
1306
Fabio Baltieriadccadb2012-12-18 18:50:58 +01001307 devm_can_led_init(dev);
1308
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001309 dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%d)\n",
Marc Kleine-Budde89af8742015-05-08 09:32:58 +02001310 priv->regs, dev->irq);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001311
1312 return 0;
1313
Marc Kleine-Budde30164752015-05-10 15:26:58 +02001314 failed_offload:
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001315 failed_register:
1316 free_candev(dev);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001317 return err;
1318}
1319
Bill Pemberton3c8ac0f2012-12-03 09:22:44 -05001320static int flexcan_remove(struct platform_device *pdev)
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001321{
1322 struct net_device *dev = platform_get_drvdata(pdev);
Marc Kleine-Budded96e43e2014-02-28 20:48:36 +01001323 struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001324
1325 unregister_flexcandev(dev);
Marc Kleine-Budde30164752015-05-10 15:26:58 +02001326 can_rx_offload_del(&priv->offload);
Marc Kleine-Budde9a275862010-10-21 05:07:58 +00001327 free_candev(dev);
1328
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001329 return 0;
1330}
1331
Marc Kleine-Budde08c6d352014-03-05 19:10:44 +01001332static int __maybe_unused flexcan_suspend(struct device *device)
Eric Bénard8b5e2182012-05-08 17:12:17 +02001333{
Fabio Estevam588e7a82013-05-20 15:43:43 -03001334 struct net_device *dev = dev_get_drvdata(device);
Eric Bénard8b5e2182012-05-08 17:12:17 +02001335 struct flexcan_priv *priv = netdev_priv(dev);
Marc Kleine-Budde9b00b302014-02-28 15:30:18 +01001336 int err;
Eric Bénard8b5e2182012-05-08 17:12:17 +02001337
Eric Bénard8b5e2182012-05-08 17:12:17 +02001338 if (netif_running(dev)) {
Fabio Estevam4de349e2016-08-17 12:41:08 -03001339 err = flexcan_chip_disable(priv);
1340 if (err)
1341 return err;
Eric Bénard8b5e2182012-05-08 17:12:17 +02001342 netif_stop_queue(dev);
1343 netif_device_detach(dev);
1344 }
1345 priv->can.state = CAN_STATE_SLEEPING;
1346
1347 return 0;
1348}
1349
Marc Kleine-Budde08c6d352014-03-05 19:10:44 +01001350static int __maybe_unused flexcan_resume(struct device *device)
Eric Bénard8b5e2182012-05-08 17:12:17 +02001351{
Fabio Estevam588e7a82013-05-20 15:43:43 -03001352 struct net_device *dev = dev_get_drvdata(device);
Eric Bénard8b5e2182012-05-08 17:12:17 +02001353 struct flexcan_priv *priv = netdev_priv(dev);
Fabio Estevam4de349e2016-08-17 12:41:08 -03001354 int err;
Eric Bénard8b5e2182012-05-08 17:12:17 +02001355
1356 priv->can.state = CAN_STATE_ERROR_ACTIVE;
1357 if (netif_running(dev)) {
1358 netif_device_attach(dev);
1359 netif_start_queue(dev);
Fabio Estevam4de349e2016-08-17 12:41:08 -03001360 err = flexcan_chip_enable(priv);
1361 if (err)
1362 return err;
Eric Bénard8b5e2182012-05-08 17:12:17 +02001363 }
Fabio Estevam4de349e2016-08-17 12:41:08 -03001364 return 0;
Eric Bénard8b5e2182012-05-08 17:12:17 +02001365}
Fabio Estevam588e7a82013-05-20 15:43:43 -03001366
1367static SIMPLE_DEV_PM_OPS(flexcan_pm_ops, flexcan_suspend, flexcan_resume);
Eric Bénard8b5e2182012-05-08 17:12:17 +02001368
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001369static struct platform_driver flexcan_driver = {
holt@sgi.comc8aef4c2011-08-16 17:32:22 +00001370 .driver = {
1371 .name = DRV_NAME,
Fabio Estevam588e7a82013-05-20 15:43:43 -03001372 .pm = &flexcan_pm_ops,
holt@sgi.comc8aef4c2011-08-16 17:32:22 +00001373 .of_match_table = flexcan_of_match,
1374 },
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001375 .probe = flexcan_probe,
Bill Pemberton3c8ac0f2012-12-03 09:22:44 -05001376 .remove = flexcan_remove,
Hui Wang30c1e672012-06-28 16:21:35 +08001377 .id_table = flexcan_id_table,
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001378};
1379
Axel Lin871d3372011-11-27 15:42:31 +00001380module_platform_driver(flexcan_driver);
Marc Kleine-Buddee955cea2009-07-29 10:20:10 +02001381
1382MODULE_AUTHOR("Sascha Hauer <kernel@pengutronix.de>, "
1383 "Marc Kleine-Budde <kernel@pengutronix.de>");
1384MODULE_LICENSE("GPL v2");
1385MODULE_DESCRIPTION("CAN port driver for flexcan based chip");