Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1 | /* |
| 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-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 6 | * Copyright (c) 2010-2017 Pengutronix, Marc Kleine-Budde <kernel@pengutronix.de> |
| 7 | * Copyright (c) 2014 David Jander, Protonic Holland |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 8 | * |
| 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 Baltieri | adccadb | 2012-12-18 18:50:58 +0100 | [diff] [blame] | 27 | #include <linux/can/led.h> |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 28 | #include <linux/can/rx-offload.h> |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 29 | #include <linux/clk.h> |
| 30 | #include <linux/delay.h> |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 31 | #include <linux/interrupt.h> |
| 32 | #include <linux/io.h> |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 33 | #include <linux/module.h> |
holt@sgi.com | 97efe9a | 2011-08-16 17:32:23 +0000 | [diff] [blame] | 34 | #include <linux/of.h> |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 35 | #include <linux/of_device.h> |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 36 | #include <linux/platform_device.h> |
Fabio Estevam | b7c4114 | 2013-06-10 23:12:57 -0300 | [diff] [blame] | 37 | #include <linux/regulator/consumer.h> |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 38 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 39 | #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-Budde | 62d1086 | 2015-08-27 16:01:27 +0200 | [diff] [blame] | 60 | #define FLEXCAN_MCR_IRMQ BIT(16) |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 61 | #define FLEXCAN_MCR_LPRIO_EN BIT(13) |
| 62 | #define FLEXCAN_MCR_AEN BIT(12) |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 63 | /* MCR_MAXMB: maximum used MBs is MAXMB + 1 */ |
Marc Kleine-Budde | 4c728d8 | 2014-09-02 16:54:17 +0200 | [diff] [blame] | 64 | #define FLEXCAN_MCR_MAXMB(x) ((x) & 0x7f) |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 65 | #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-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 69 | |
| 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 Agner | cdce844 | 2014-07-15 14:56:21 +0200 | [diff] [blame] | 94 | /* FLEXCAN control register 2 (CTRL2) bits */ |
Marc Kleine-Budde | 6f75fce | 2014-09-23 11:03:01 +0200 | [diff] [blame] | 95 | #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 Agner | cdce844 | 2014-07-15 14:56:21 +0200 | [diff] [blame] | 102 | |
| 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-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 115 | /* 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 Grandegger | 6e9d554 | 2011-12-12 16:09:28 +0100 | [diff] [blame] | 143 | #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-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 146 | |
| 147 | /* FLEXCAN interrupt flag register (IFLAG) bits */ |
David Jander | 25e9244 | 2014-09-03 16:47:22 +0200 | [diff] [blame] | 148 | /* Errata ERR005829 step7: Reserve first valid MB */ |
Marc Kleine-Budde | b93917c | 2015-07-12 00:47:47 +0200 | [diff] [blame] | 149 | #define FLEXCAN_TX_MB_RESERVED_OFF_FIFO 8 |
| 150 | #define FLEXCAN_TX_MB_OFF_FIFO 9 |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 151 | #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-Budde | b93917c | 2015-07-12 00:47:47 +0200 | [diff] [blame] | 155 | #define FLEXCAN_IFLAG_MB(x) BIT(x) |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 156 | #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-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 159 | |
| 160 | /* FLEXCAN message buffers */ |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 161 | #define FLEXCAN_MB_CODE_MASK (0xf << 24) |
| 162 | #define FLEXCAN_MB_CODE_RX_BUSY_BIT (0x1 << 24) |
Marc Kleine-Budde | c32fe4a | 2014-09-16 12:39:28 +0200 | [diff] [blame] | 163 | #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-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 166 | #define FLEXCAN_MB_CODE_RX_OVERRUN (0x6 << 24) |
Marc Kleine-Budde | c32fe4a | 2014-09-16 12:39:28 +0200 | [diff] [blame] | 167 | #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-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 174 | #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-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 180 | #define FLEXCAN_TIMEOUT_US (50) |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 181 | |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 182 | /* FLEXCAN hardware feature flags |
Wolfgang Grandegger | bb698ca | 2012-10-10 21:10:42 +0200 | [diff] [blame] | 183 | * |
| 184 | * Below is some version info we got: |
ZHU Yi (ST-FIR/ENG1-Zhu) | da49a80 | 2017-09-15 07:03:58 +0000 | [diff] [blame] | 185 | * SOC Version IP-Version Glitch- [TR]WRN_INT IRQ Err Memory err RTR re- |
| 186 | * Filter? connected? Passive 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 no |
| 189 | * MX35 FlexCAN2 03.00.00.00 no no ? no no |
| 190 | * MX53 FlexCAN2 03.00.00.00 yes no no no no |
| 191 | * MX6s FlexCAN3 10.00.12.00 yes yes no no yes |
| 192 | * VF610 FlexCAN3 ? no yes ? yes yes? |
Wolfgang Grandegger | bb698ca | 2012-10-10 21:10:42 +0200 | [diff] [blame] | 193 | * |
| 194 | * Some SOCs do not have the RX_WARN & TX_WARN interrupt line connected. |
| 195 | */ |
ZHU Yi (ST-FIR/ENG1-Zhu) | 2f8639b | 2017-09-15 07:01:23 +0000 | [diff] [blame] | 196 | #define FLEXCAN_QUIRK_BROKEN_WERR_STATE BIT(1) /* [TR]WRN_INT not connected */ |
Marc Kleine-Budde | f377bff | 2015-05-08 15:22:36 +0200 | [diff] [blame] | 197 | #define FLEXCAN_QUIRK_DISABLE_RXFG BIT(2) /* Disable RX FIFO Global mask */ |
Marc Kleine-Budde | 9eb7aa8 | 2015-09-01 08:57:55 +0200 | [diff] [blame] | 198 | #define FLEXCAN_QUIRK_ENABLE_EACEN_RRS BIT(3) /* Enable EACEN and RRS bit in ctrl2 */ |
Marc Kleine-Budde | 66ddb82 | 2017-03-02 15:42:49 +0100 | [diff] [blame] | 199 | #define FLEXCAN_QUIRK_DISABLE_MECR BIT(4) /* Disable Memory error detection */ |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 200 | #define FLEXCAN_QUIRK_USE_OFF_TIMESTAMP BIT(5) /* Use timestamp based offloading */ |
ZHU Yi (ST-FIR/ENG1-Zhu) | da49a80 | 2017-09-15 07:03:58 +0000 | [diff] [blame] | 201 | #define FLEXCAN_QUIRK_BROKEN_PERR_STATE BIT(6) /* No interrupt for error passive */ |
Wolfgang Grandegger | 4f72e5f | 2012-09-28 03:17:15 +0000 | [diff] [blame] | 202 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 203 | /* Structure of the message buffer */ |
| 204 | struct flexcan_mb { |
| 205 | u32 can_ctrl; |
| 206 | u32 can_id; |
| 207 | u32 data[2]; |
| 208 | }; |
| 209 | |
| 210 | /* Structure of the hardware registers */ |
| 211 | struct flexcan_regs { |
| 212 | u32 mcr; /* 0x00 */ |
| 213 | u32 ctrl; /* 0x04 */ |
| 214 | u32 timer; /* 0x08 */ |
| 215 | u32 _reserved1; /* 0x0c */ |
| 216 | u32 rxgmask; /* 0x10 */ |
| 217 | u32 rx14mask; /* 0x14 */ |
| 218 | u32 rx15mask; /* 0x18 */ |
| 219 | u32 ecr; /* 0x1c */ |
| 220 | u32 esr; /* 0x20 */ |
| 221 | u32 imask2; /* 0x24 */ |
| 222 | u32 imask1; /* 0x28 */ |
| 223 | u32 iflag2; /* 0x2c */ |
| 224 | u32 iflag1; /* 0x30 */ |
Marc Kleine-Budde | 62d1086 | 2015-08-27 16:01:27 +0200 | [diff] [blame] | 225 | union { /* 0x34 */ |
| 226 | u32 gfwr_mx28; /* MX28, MX53 */ |
| 227 | u32 ctrl2; /* MX6, VF610 */ |
| 228 | }; |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 229 | u32 esr2; /* 0x38 */ |
| 230 | u32 imeur; /* 0x3c */ |
| 231 | u32 lrfr; /* 0x40 */ |
| 232 | u32 crcr; /* 0x44 */ |
| 233 | u32 rxfgmask; /* 0x48 */ |
| 234 | u32 rxfir; /* 0x4c */ |
Stefan Agner | cdce844 | 2014-07-15 14:56:21 +0200 | [diff] [blame] | 235 | u32 _reserved3[12]; /* 0x50 */ |
Marc Kleine-Budde | 1ba763d | 2015-08-25 10:39:19 +0200 | [diff] [blame] | 236 | struct flexcan_mb mb[64]; /* 0x80 */ |
Marc Kleine-Budde | 66a6ef0 | 2014-09-17 12:50:48 +0200 | [diff] [blame] | 237 | /* FIFO-mode: |
| 238 | * MB |
| 239 | * 0x080...0x08f 0 RX message buffer |
| 240 | * 0x090...0x0df 1-5 reserverd |
| 241 | * 0x0e0...0x0ff 6-7 8 entry ID table |
| 242 | * (mx25, mx28, mx35, mx53) |
| 243 | * 0x0e0...0x2df 6-7..37 8..128 entry ID table |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 244 | * size conf'ed via ctrl2::RFFN |
Marc Kleine-Budde | 66a6ef0 | 2014-09-17 12:50:48 +0200 | [diff] [blame] | 245 | * (mx6, vf610) |
| 246 | */ |
Marc Kleine-Budde | 62d1086 | 2015-08-27 16:01:27 +0200 | [diff] [blame] | 247 | u32 _reserved4[256]; /* 0x480 */ |
| 248 | u32 rximr[64]; /* 0x880 */ |
| 249 | u32 _reserved5[24]; /* 0x980 */ |
| 250 | u32 gfwr_mx6; /* 0x9e0 - MX6 */ |
| 251 | u32 _reserved6[63]; /* 0x9e4 */ |
Stefan Agner | cdce844 | 2014-07-15 14:56:21 +0200 | [diff] [blame] | 252 | u32 mecr; /* 0xae0 */ |
| 253 | u32 erriar; /* 0xae4 */ |
| 254 | u32 erridpr; /* 0xae8 */ |
| 255 | u32 errippr; /* 0xaec */ |
| 256 | u32 rerrar; /* 0xaf0 */ |
| 257 | u32 rerrdr; /* 0xaf4 */ |
| 258 | u32 rerrsynr; /* 0xaf8 */ |
| 259 | u32 errsr; /* 0xafc */ |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 260 | }; |
| 261 | |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 262 | struct flexcan_devtype_data { |
Marc Kleine-Budde | f377bff | 2015-05-08 15:22:36 +0200 | [diff] [blame] | 263 | u32 quirks; /* quirks needed for different IP cores */ |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 264 | }; |
| 265 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 266 | struct flexcan_priv { |
| 267 | struct can_priv can; |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 268 | struct can_rx_offload offload; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 269 | |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 270 | struct flexcan_regs __iomem *regs; |
Marc Kleine-Budde | b93917c | 2015-07-12 00:47:47 +0200 | [diff] [blame] | 271 | struct flexcan_mb __iomem *tx_mb; |
| 272 | struct flexcan_mb __iomem *tx_mb_reserved; |
| 273 | u8 tx_mb_idx; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 274 | u32 reg_ctrl_default; |
Marc Kleine-Budde | 28ac7dc | 2015-08-04 13:46:10 +0200 | [diff] [blame] | 275 | u32 reg_imask1_default; |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 276 | u32 reg_imask2_default; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 277 | |
Steffen Trumtrar | 3d42a37 | 2012-07-17 16:14:34 +0200 | [diff] [blame] | 278 | struct clk *clk_ipg; |
| 279 | struct clk *clk_per; |
Marc Kleine-Budde | dda0b3b | 2012-07-13 14:52:48 +0200 | [diff] [blame] | 280 | const struct flexcan_devtype_data *devtype_data; |
Fabio Estevam | b7c4114 | 2013-06-10 23:12:57 -0300 | [diff] [blame] | 281 | struct regulator *reg_xceiver; |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 282 | |
| 283 | /* Read and Write APIs */ |
| 284 | u32 (*read)(void __iomem *addr); |
| 285 | void (*write)(u32 val, void __iomem *addr); |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 286 | }; |
| 287 | |
Marc Kleine-Budde | a3c11a7 | 2016-07-04 14:45:44 +0200 | [diff] [blame] | 288 | static const struct flexcan_devtype_data fsl_p1010_devtype_data = { |
ZHU Yi (ST-FIR/ENG1-Zhu) | fb5b91d6 | 2017-09-15 07:09:37 +0000 | [diff] [blame] | 289 | .quirks = FLEXCAN_QUIRK_BROKEN_WERR_STATE | |
| 290 | FLEXCAN_QUIRK_BROKEN_PERR_STATE, |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 291 | }; |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 292 | |
ZHU Yi (ST-FIR/ENG1-Zhu) | 083c557 | 2017-09-15 07:08:23 +0000 | [diff] [blame] | 293 | static const struct flexcan_devtype_data fsl_imx28_devtype_data = { |
| 294 | .quirks = FLEXCAN_QUIRK_BROKEN_PERR_STATE, |
| 295 | }; |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 296 | |
Marc Kleine-Budde | a3c11a7 | 2016-07-04 14:45:44 +0200 | [diff] [blame] | 297 | static const struct flexcan_devtype_data fsl_imx6q_devtype_data = { |
Marc Kleine-Budde | 096de07 | 2015-09-01 10:28:46 +0200 | [diff] [blame] | 298 | .quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS | |
ZHU Yi (ST-FIR/ENG1-Zhu) | cf9c046 | 2017-09-15 07:05:50 +0000 | [diff] [blame] | 299 | FLEXCAN_QUIRK_USE_OFF_TIMESTAMP | FLEXCAN_QUIRK_BROKEN_PERR_STATE, |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 300 | }; |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 301 | |
Marc Kleine-Budde | a3c11a7 | 2016-07-04 14:45:44 +0200 | [diff] [blame] | 302 | static const struct flexcan_devtype_data fsl_vf610_devtype_data = { |
Marc Kleine-Budde | 9eb7aa8 | 2015-09-01 08:57:55 +0200 | [diff] [blame] | 303 | .quirks = FLEXCAN_QUIRK_DISABLE_RXFG | FLEXCAN_QUIRK_ENABLE_EACEN_RRS | |
Marc Kleine-Budde | 096de07 | 2015-09-01 10:28:46 +0200 | [diff] [blame] | 304 | FLEXCAN_QUIRK_DISABLE_MECR | FLEXCAN_QUIRK_USE_OFF_TIMESTAMP, |
Stefan Agner | cdce844 | 2014-07-15 14:56:21 +0200 | [diff] [blame] | 305 | }; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 306 | |
Marc Kleine-Budde | 194b9a4 | 2012-07-16 12:58:31 +0200 | [diff] [blame] | 307 | static const struct can_bittiming_const flexcan_bittiming_const = { |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 308 | .name = DRV_NAME, |
| 309 | .tseg1_min = 4, |
| 310 | .tseg1_max = 16, |
| 311 | .tseg2_min = 2, |
| 312 | .tseg2_max = 8, |
| 313 | .sjw_max = 4, |
| 314 | .brp_min = 1, |
| 315 | .brp_max = 256, |
| 316 | .brp_inc = 1, |
| 317 | }; |
| 318 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 319 | /* FlexCAN module is essentially modelled as a little-endian IP in most |
| 320 | * SoCs, i.e the registers as well as the message buffer areas are |
| 321 | * implemented in a little-endian fashion. |
| 322 | * |
| 323 | * However there are some SoCs (e.g. LS1021A) which implement the FlexCAN |
| 324 | * module in a big-endian fashion (i.e the registers as well as the |
| 325 | * message buffer areas are implemented in a big-endian way). |
| 326 | * |
| 327 | * In addition, the FlexCAN module can be found on SoCs having ARM or |
| 328 | * PPC cores. So, we need to abstract off the register read/write |
| 329 | * functions, ensuring that these cater to all the combinations of module |
| 330 | * endianness and underlying CPU endianness. |
holt@sgi.com | 61e271e | 2011-08-16 17:32:20 +0000 | [diff] [blame] | 331 | */ |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 332 | static inline u32 flexcan_read_be(void __iomem *addr) |
holt@sgi.com | 61e271e | 2011-08-16 17:32:20 +0000 | [diff] [blame] | 333 | { |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 334 | return ioread32be(addr); |
holt@sgi.com | 61e271e | 2011-08-16 17:32:20 +0000 | [diff] [blame] | 335 | } |
| 336 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 337 | static inline void flexcan_write_be(u32 val, void __iomem *addr) |
holt@sgi.com | 61e271e | 2011-08-16 17:32:20 +0000 | [diff] [blame] | 338 | { |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 339 | iowrite32be(val, addr); |
holt@sgi.com | 61e271e | 2011-08-16 17:32:20 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 342 | static inline u32 flexcan_read_le(void __iomem *addr) |
holt@sgi.com | 61e271e | 2011-08-16 17:32:20 +0000 | [diff] [blame] | 343 | { |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 344 | return ioread32(addr); |
holt@sgi.com | 61e271e | 2011-08-16 17:32:20 +0000 | [diff] [blame] | 345 | } |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 346 | |
| 347 | static inline void flexcan_write_le(u32 val, void __iomem *addr) |
| 348 | { |
| 349 | iowrite32(val, addr); |
| 350 | } |
holt@sgi.com | 61e271e | 2011-08-16 17:32:20 +0000 | [diff] [blame] | 351 | |
ZHU Yi (ST-FIR/ENG1-Zhu) | da49a80 | 2017-09-15 07:03:58 +0000 | [diff] [blame] | 352 | static inline void flexcan_error_irq_enable(const struct flexcan_priv *priv) |
| 353 | { |
| 354 | struct flexcan_regs __iomem *regs = priv->regs; |
| 355 | u32 reg_ctrl = (priv->reg_ctrl_default | FLEXCAN_CTRL_ERR_MSK); |
| 356 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 357 | priv->write(reg_ctrl, ®s->ctrl); |
ZHU Yi (ST-FIR/ENG1-Zhu) | da49a80 | 2017-09-15 07:03:58 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | static inline void flexcan_error_irq_disable(const struct flexcan_priv *priv) |
| 361 | { |
| 362 | struct flexcan_regs __iomem *regs = priv->regs; |
| 363 | u32 reg_ctrl = (priv->reg_ctrl_default & ~FLEXCAN_CTRL_ERR_MSK); |
| 364 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 365 | priv->write(reg_ctrl, ®s->ctrl); |
ZHU Yi (ST-FIR/ENG1-Zhu) | da49a80 | 2017-09-15 07:03:58 +0000 | [diff] [blame] | 366 | } |
| 367 | |
Marc Kleine-Budde | f003698 | 2014-02-28 17:18:27 +0100 | [diff] [blame] | 368 | static inline int flexcan_transceiver_enable(const struct flexcan_priv *priv) |
| 369 | { |
| 370 | if (!priv->reg_xceiver) |
| 371 | return 0; |
| 372 | |
| 373 | return regulator_enable(priv->reg_xceiver); |
| 374 | } |
| 375 | |
| 376 | static inline int flexcan_transceiver_disable(const struct flexcan_priv *priv) |
| 377 | { |
| 378 | if (!priv->reg_xceiver) |
| 379 | return 0; |
| 380 | |
| 381 | return regulator_disable(priv->reg_xceiver); |
| 382 | } |
| 383 | |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 384 | static int flexcan_chip_enable(struct flexcan_priv *priv) |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 385 | { |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 386 | struct flexcan_regs __iomem *regs = priv->regs; |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 387 | unsigned int timeout = FLEXCAN_TIMEOUT_US / 10; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 388 | u32 reg; |
| 389 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 390 | reg = priv->read(®s->mcr); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 391 | reg &= ~FLEXCAN_MCR_MDIS; |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 392 | priv->write(reg, ®s->mcr); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 393 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 394 | while (timeout-- && (priv->read(®s->mcr) & FLEXCAN_MCR_LPM_ACK)) |
David Jander | 8badd65 | 2014-08-27 12:02:16 +0200 | [diff] [blame] | 395 | udelay(10); |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 396 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 397 | if (priv->read(®s->mcr) & FLEXCAN_MCR_LPM_ACK) |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 398 | return -ETIMEDOUT; |
| 399 | |
| 400 | return 0; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 401 | } |
| 402 | |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 403 | static int flexcan_chip_disable(struct flexcan_priv *priv) |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 404 | { |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 405 | struct flexcan_regs __iomem *regs = priv->regs; |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 406 | unsigned int timeout = FLEXCAN_TIMEOUT_US / 10; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 407 | u32 reg; |
| 408 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 409 | reg = priv->read(®s->mcr); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 410 | reg |= FLEXCAN_MCR_MDIS; |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 411 | priv->write(reg, ®s->mcr); |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 412 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 413 | while (timeout-- && !(priv->read(®s->mcr) & FLEXCAN_MCR_LPM_ACK)) |
David Jander | 8badd65 | 2014-08-27 12:02:16 +0200 | [diff] [blame] | 414 | udelay(10); |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 415 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 416 | if (!(priv->read(®s->mcr) & FLEXCAN_MCR_LPM_ACK)) |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 417 | return -ETIMEDOUT; |
| 418 | |
| 419 | return 0; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 420 | } |
| 421 | |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 422 | static int flexcan_chip_freeze(struct flexcan_priv *priv) |
| 423 | { |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 424 | struct flexcan_regs __iomem *regs = priv->regs; |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 425 | unsigned int timeout = 1000 * 1000 * 10 / priv->can.bittiming.bitrate; |
| 426 | u32 reg; |
| 427 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 428 | reg = priv->read(®s->mcr); |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 429 | reg |= FLEXCAN_MCR_HALT; |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 430 | priv->write(reg, ®s->mcr); |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 431 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 432 | while (timeout-- && !(priv->read(®s->mcr) & FLEXCAN_MCR_FRZ_ACK)) |
David Jander | 8badd65 | 2014-08-27 12:02:16 +0200 | [diff] [blame] | 433 | udelay(100); |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 434 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 435 | if (!(priv->read(®s->mcr) & FLEXCAN_MCR_FRZ_ACK)) |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 436 | return -ETIMEDOUT; |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
| 441 | static int flexcan_chip_unfreeze(struct flexcan_priv *priv) |
| 442 | { |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 443 | struct flexcan_regs __iomem *regs = priv->regs; |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 444 | unsigned int timeout = FLEXCAN_TIMEOUT_US / 10; |
| 445 | u32 reg; |
| 446 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 447 | reg = priv->read(®s->mcr); |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 448 | reg &= ~FLEXCAN_MCR_HALT; |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 449 | priv->write(reg, ®s->mcr); |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 450 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 451 | while (timeout-- && (priv->read(®s->mcr) & FLEXCAN_MCR_FRZ_ACK)) |
David Jander | 8badd65 | 2014-08-27 12:02:16 +0200 | [diff] [blame] | 452 | udelay(10); |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 453 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 454 | if (priv->read(®s->mcr) & FLEXCAN_MCR_FRZ_ACK) |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 455 | return -ETIMEDOUT; |
| 456 | |
| 457 | return 0; |
| 458 | } |
| 459 | |
Marc Kleine-Budde | 4b5b822 | 2014-02-28 15:16:59 +0100 | [diff] [blame] | 460 | static int flexcan_chip_softreset(struct flexcan_priv *priv) |
| 461 | { |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 462 | struct flexcan_regs __iomem *regs = priv->regs; |
Marc Kleine-Budde | 4b5b822 | 2014-02-28 15:16:59 +0100 | [diff] [blame] | 463 | unsigned int timeout = FLEXCAN_TIMEOUT_US / 10; |
| 464 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 465 | priv->write(FLEXCAN_MCR_SOFTRST, ®s->mcr); |
| 466 | while (timeout-- && (priv->read(®s->mcr) & FLEXCAN_MCR_SOFTRST)) |
David Jander | 8badd65 | 2014-08-27 12:02:16 +0200 | [diff] [blame] | 467 | udelay(10); |
Marc Kleine-Budde | 4b5b822 | 2014-02-28 15:16:59 +0100 | [diff] [blame] | 468 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 469 | if (priv->read(®s->mcr) & FLEXCAN_MCR_SOFTRST) |
Marc Kleine-Budde | 4b5b822 | 2014-02-28 15:16:59 +0100 | [diff] [blame] | 470 | return -ETIMEDOUT; |
| 471 | |
| 472 | return 0; |
| 473 | } |
| 474 | |
Stefan Agner | ec56acf | 2014-07-15 14:56:20 +0200 | [diff] [blame] | 475 | static int __flexcan_get_berr_counter(const struct net_device *dev, |
| 476 | struct can_berr_counter *bec) |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 477 | { |
| 478 | const struct flexcan_priv *priv = netdev_priv(dev); |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 479 | struct flexcan_regs __iomem *regs = priv->regs; |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 480 | u32 reg = priv->read(®s->ecr); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 481 | |
| 482 | bec->txerr = (reg >> 0) & 0xff; |
| 483 | bec->rxerr = (reg >> 8) & 0xff; |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
Stefan Agner | ec56acf | 2014-07-15 14:56:20 +0200 | [diff] [blame] | 488 | static int flexcan_get_berr_counter(const struct net_device *dev, |
| 489 | struct can_berr_counter *bec) |
| 490 | { |
| 491 | const struct flexcan_priv *priv = netdev_priv(dev); |
| 492 | int err; |
| 493 | |
| 494 | err = clk_prepare_enable(priv->clk_ipg); |
| 495 | if (err) |
| 496 | return err; |
| 497 | |
| 498 | err = clk_prepare_enable(priv->clk_per); |
| 499 | if (err) |
| 500 | goto out_disable_ipg; |
| 501 | |
| 502 | err = __flexcan_get_berr_counter(dev, bec); |
| 503 | |
| 504 | clk_disable_unprepare(priv->clk_per); |
| 505 | out_disable_ipg: |
| 506 | clk_disable_unprepare(priv->clk_ipg); |
| 507 | |
| 508 | return err; |
| 509 | } |
| 510 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 511 | static int flexcan_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 512 | { |
| 513 | const struct flexcan_priv *priv = netdev_priv(dev); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 514 | struct can_frame *cf = (struct can_frame *)skb->data; |
| 515 | u32 can_id; |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 516 | u32 data; |
Marc Kleine-Budde | 10d089b | 2014-09-23 11:18:11 +0200 | [diff] [blame] | 517 | u32 ctrl = FLEXCAN_MB_CODE_TX_DATA | (cf->can_dlc << 16); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 518 | |
| 519 | if (can_dropped_invalid_skb(dev, skb)) |
| 520 | return NETDEV_TX_OK; |
| 521 | |
| 522 | netif_stop_queue(dev); |
| 523 | |
| 524 | if (cf->can_id & CAN_EFF_FLAG) { |
| 525 | can_id = cf->can_id & CAN_EFF_MASK; |
| 526 | ctrl |= FLEXCAN_MB_CNT_IDE | FLEXCAN_MB_CNT_SRR; |
| 527 | } else { |
| 528 | can_id = (cf->can_id & CAN_SFF_MASK) << 18; |
| 529 | } |
| 530 | |
| 531 | if (cf->can_id & CAN_RTR_FLAG) |
| 532 | ctrl |= FLEXCAN_MB_CNT_RTR; |
| 533 | |
| 534 | if (cf->can_dlc > 0) { |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 535 | data = be32_to_cpup((__be32 *)&cf->data[0]); |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 536 | priv->write(data, &priv->tx_mb->data[0]); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 537 | } |
| 538 | if (cf->can_dlc > 3) { |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 539 | data = be32_to_cpup((__be32 *)&cf->data[4]); |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 540 | priv->write(data, &priv->tx_mb->data[1]); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 541 | } |
| 542 | |
Reuben Dowle | 9a12349 | 2011-11-01 11:18:03 +1300 | [diff] [blame] | 543 | can_put_echo_skb(skb, dev, 0); |
| 544 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 545 | priv->write(can_id, &priv->tx_mb->can_id); |
| 546 | priv->write(ctrl, &priv->tx_mb->can_ctrl); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 547 | |
David Jander | 25e9244 | 2014-09-03 16:47:22 +0200 | [diff] [blame] | 548 | /* Errata ERR005829 step8: |
| 549 | * Write twice INACTIVE(0x8) code to first MB. |
| 550 | */ |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 551 | priv->write(FLEXCAN_MB_CODE_TX_INACTIVE, |
Marc Kleine-Budde | b93917c | 2015-07-12 00:47:47 +0200 | [diff] [blame] | 552 | &priv->tx_mb_reserved->can_ctrl); |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 553 | priv->write(FLEXCAN_MB_CODE_TX_INACTIVE, |
Marc Kleine-Budde | b93917c | 2015-07-12 00:47:47 +0200 | [diff] [blame] | 554 | &priv->tx_mb_reserved->can_ctrl); |
David Jander | 25e9244 | 2014-09-03 16:47:22 +0200 | [diff] [blame] | 555 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 556 | return NETDEV_TX_OK; |
| 557 | } |
| 558 | |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 559 | static void flexcan_irq_bus_err(struct net_device *dev, u32 reg_esr) |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 560 | { |
| 561 | struct flexcan_priv *priv = netdev_priv(dev); |
Marc Kleine-Budde | a5c02f66 | 2017-01-18 11:38:26 +0100 | [diff] [blame] | 562 | struct sk_buff *skb; |
| 563 | struct can_frame *cf; |
Marc Kleine-Budde | d166f56 | 2017-01-17 17:33:46 +0100 | [diff] [blame] | 564 | bool rx_errors = false, tx_errors = false; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 565 | |
Marc Kleine-Budde | a5c02f66 | 2017-01-18 11:38:26 +0100 | [diff] [blame] | 566 | skb = alloc_can_err_skb(dev, &cf); |
| 567 | if (unlikely(!skb)) |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 568 | return; |
Marc Kleine-Budde | a5c02f66 | 2017-01-18 11:38:26 +0100 | [diff] [blame] | 569 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 570 | cf->can_id |= CAN_ERR_PROT | CAN_ERR_BUSERROR; |
| 571 | |
| 572 | if (reg_esr & FLEXCAN_ESR_BIT1_ERR) { |
Wolfgang Grandegger | aabdfd6 | 2012-02-01 11:02:05 +0100 | [diff] [blame] | 573 | netdev_dbg(dev, "BIT1_ERR irq\n"); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 574 | cf->data[2] |= CAN_ERR_PROT_BIT1; |
Marc Kleine-Budde | d166f56 | 2017-01-17 17:33:46 +0100 | [diff] [blame] | 575 | tx_errors = true; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 576 | } |
| 577 | if (reg_esr & FLEXCAN_ESR_BIT0_ERR) { |
Wolfgang Grandegger | aabdfd6 | 2012-02-01 11:02:05 +0100 | [diff] [blame] | 578 | netdev_dbg(dev, "BIT0_ERR irq\n"); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 579 | cf->data[2] |= CAN_ERR_PROT_BIT0; |
Marc Kleine-Budde | d166f56 | 2017-01-17 17:33:46 +0100 | [diff] [blame] | 580 | tx_errors = true; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 581 | } |
| 582 | if (reg_esr & FLEXCAN_ESR_ACK_ERR) { |
Wolfgang Grandegger | aabdfd6 | 2012-02-01 11:02:05 +0100 | [diff] [blame] | 583 | netdev_dbg(dev, "ACK_ERR irq\n"); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 584 | cf->can_id |= CAN_ERR_ACK; |
Oliver Hartkopp | ffd461f | 2015-11-21 18:41:20 +0100 | [diff] [blame] | 585 | cf->data[3] = CAN_ERR_PROT_LOC_ACK; |
Marc Kleine-Budde | d166f56 | 2017-01-17 17:33:46 +0100 | [diff] [blame] | 586 | tx_errors = true; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 587 | } |
| 588 | if (reg_esr & FLEXCAN_ESR_CRC_ERR) { |
Wolfgang Grandegger | aabdfd6 | 2012-02-01 11:02:05 +0100 | [diff] [blame] | 589 | netdev_dbg(dev, "CRC_ERR irq\n"); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 590 | cf->data[2] |= CAN_ERR_PROT_BIT; |
Oliver Hartkopp | ffd461f | 2015-11-21 18:41:20 +0100 | [diff] [blame] | 591 | cf->data[3] = CAN_ERR_PROT_LOC_CRC_SEQ; |
Marc Kleine-Budde | d166f56 | 2017-01-17 17:33:46 +0100 | [diff] [blame] | 592 | rx_errors = true; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 593 | } |
| 594 | if (reg_esr & FLEXCAN_ESR_FRM_ERR) { |
Wolfgang Grandegger | aabdfd6 | 2012-02-01 11:02:05 +0100 | [diff] [blame] | 595 | netdev_dbg(dev, "FRM_ERR irq\n"); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 596 | cf->data[2] |= CAN_ERR_PROT_FORM; |
Marc Kleine-Budde | d166f56 | 2017-01-17 17:33:46 +0100 | [diff] [blame] | 597 | rx_errors = true; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 598 | } |
| 599 | if (reg_esr & FLEXCAN_ESR_STF_ERR) { |
Wolfgang Grandegger | aabdfd6 | 2012-02-01 11:02:05 +0100 | [diff] [blame] | 600 | netdev_dbg(dev, "STF_ERR irq\n"); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 601 | cf->data[2] |= CAN_ERR_PROT_STUFF; |
Marc Kleine-Budde | d166f56 | 2017-01-17 17:33:46 +0100 | [diff] [blame] | 602 | rx_errors = true; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | priv->can.can_stats.bus_error++; |
| 606 | if (rx_errors) |
| 607 | dev->stats.rx_errors++; |
| 608 | if (tx_errors) |
| 609 | dev->stats.tx_errors++; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 610 | |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 611 | can_rx_offload_irq_queue_err_skb(&priv->offload, skb); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 612 | } |
| 613 | |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 614 | static void flexcan_irq_state(struct net_device *dev, u32 reg_esr) |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 615 | { |
| 616 | struct flexcan_priv *priv = netdev_priv(dev); |
| 617 | struct sk_buff *skb; |
| 618 | struct can_frame *cf; |
Marc Kleine-Budde | 238443d | 2017-01-18 11:25:41 +0100 | [diff] [blame] | 619 | enum can_state new_state, rx_state, tx_state; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 620 | int flt; |
Andri Yngvason | 71a3aed | 2014-12-03 17:54:15 +0000 | [diff] [blame] | 621 | struct can_berr_counter bec; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 622 | |
| 623 | flt = reg_esr & FLEXCAN_ESR_FLT_CONF_MASK; |
| 624 | if (likely(flt == FLEXCAN_ESR_FLT_CONF_ACTIVE)) { |
Andri Yngvason | 71a3aed | 2014-12-03 17:54:15 +0000 | [diff] [blame] | 625 | tx_state = unlikely(reg_esr & FLEXCAN_ESR_TX_WRN) ? |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 626 | CAN_STATE_ERROR_WARNING : CAN_STATE_ERROR_ACTIVE; |
Andri Yngvason | 71a3aed | 2014-12-03 17:54:15 +0000 | [diff] [blame] | 627 | rx_state = unlikely(reg_esr & FLEXCAN_ESR_RX_WRN) ? |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 628 | CAN_STATE_ERROR_WARNING : CAN_STATE_ERROR_ACTIVE; |
Andri Yngvason | 71a3aed | 2014-12-03 17:54:15 +0000 | [diff] [blame] | 629 | new_state = max(tx_state, rx_state); |
Andri Yngvason | 258ce80 | 2015-03-17 13:03:09 +0000 | [diff] [blame] | 630 | } else { |
Andri Yngvason | 71a3aed | 2014-12-03 17:54:15 +0000 | [diff] [blame] | 631 | __flexcan_get_berr_counter(dev, &bec); |
Andri Yngvason | 258ce80 | 2015-03-17 13:03:09 +0000 | [diff] [blame] | 632 | new_state = flt == FLEXCAN_ESR_FLT_CONF_PASSIVE ? |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 633 | CAN_STATE_ERROR_PASSIVE : CAN_STATE_BUS_OFF; |
Andri Yngvason | 71a3aed | 2014-12-03 17:54:15 +0000 | [diff] [blame] | 634 | rx_state = bec.rxerr >= bec.txerr ? new_state : 0; |
| 635 | tx_state = bec.rxerr <= bec.txerr ? new_state : 0; |
Andri Yngvason | 71a3aed | 2014-12-03 17:54:15 +0000 | [diff] [blame] | 636 | } |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 637 | |
| 638 | /* state hasn't changed */ |
| 639 | if (likely(new_state == priv->can.state)) |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 640 | return; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 641 | |
| 642 | skb = alloc_can_err_skb(dev, &cf); |
| 643 | if (unlikely(!skb)) |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 644 | return; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 645 | |
Andri Yngvason | 71a3aed | 2014-12-03 17:54:15 +0000 | [diff] [blame] | 646 | can_change_state(dev, cf, tx_state, rx_state); |
| 647 | |
| 648 | if (unlikely(new_state == CAN_STATE_BUS_OFF)) |
| 649 | can_bus_off(dev); |
| 650 | |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 651 | can_rx_offload_irq_queue_err_skb(&priv->offload, skb); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 652 | } |
| 653 | |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 654 | static inline struct flexcan_priv *rx_offload_to_priv(struct can_rx_offload *offload) |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 655 | { |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 656 | return container_of(offload, struct flexcan_priv, offload); |
| 657 | } |
| 658 | |
| 659 | static unsigned int flexcan_mailbox_read(struct can_rx_offload *offload, |
| 660 | struct can_frame *cf, |
| 661 | u32 *timestamp, unsigned int n) |
| 662 | { |
| 663 | struct flexcan_priv *priv = rx_offload_to_priv(offload); |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 664 | struct flexcan_regs __iomem *regs = priv->regs; |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 665 | struct flexcan_mb __iomem *mb = ®s->mb[n]; |
| 666 | u32 reg_ctrl, reg_id, reg_iflag1; |
| 667 | |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 668 | if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) { |
| 669 | u32 code; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 670 | |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 671 | do { |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 672 | reg_ctrl = priv->read(&mb->can_ctrl); |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 673 | } while (reg_ctrl & FLEXCAN_MB_CODE_RX_BUSY_BIT); |
| 674 | |
| 675 | /* is this MB empty? */ |
| 676 | code = reg_ctrl & FLEXCAN_MB_CODE_MASK; |
| 677 | if ((code != FLEXCAN_MB_CODE_RX_FULL) && |
| 678 | (code != FLEXCAN_MB_CODE_RX_OVERRUN)) |
| 679 | return 0; |
| 680 | |
| 681 | if (code == FLEXCAN_MB_CODE_RX_OVERRUN) { |
| 682 | /* This MB was overrun, we lost data */ |
| 683 | offload->dev->stats.rx_over_errors++; |
| 684 | offload->dev->stats.rx_errors++; |
| 685 | } |
| 686 | } else { |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 687 | reg_iflag1 = priv->read(®s->iflag1); |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 688 | if (!(reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_AVAILABLE)) |
| 689 | return 0; |
| 690 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 691 | reg_ctrl = priv->read(&mb->can_ctrl); |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 692 | } |
| 693 | |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 694 | /* increase timstamp to full 32 bit */ |
| 695 | *timestamp = reg_ctrl << 16; |
| 696 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 697 | reg_id = priv->read(&mb->can_id); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 698 | if (reg_ctrl & FLEXCAN_MB_CNT_IDE) |
| 699 | cf->can_id = ((reg_id >> 0) & CAN_EFF_MASK) | CAN_EFF_FLAG; |
| 700 | else |
| 701 | cf->can_id = (reg_id >> 18) & CAN_SFF_MASK; |
| 702 | |
| 703 | if (reg_ctrl & FLEXCAN_MB_CNT_RTR) |
| 704 | cf->can_id |= CAN_RTR_FLAG; |
| 705 | cf->can_dlc = get_can_dlc((reg_ctrl >> 16) & 0xf); |
| 706 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 707 | *(__be32 *)(cf->data + 0) = cpu_to_be32(priv->read(&mb->data[0])); |
| 708 | *(__be32 *)(cf->data + 4) = cpu_to_be32(priv->read(&mb->data[1])); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 709 | |
| 710 | /* mark as read */ |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 711 | if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) { |
| 712 | /* Clear IRQ */ |
| 713 | if (n < 32) |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 714 | priv->write(BIT(n), ®s->iflag1); |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 715 | else |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 716 | priv->write(BIT(n - 32), ®s->iflag2); |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 717 | } else { |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 718 | priv->write(FLEXCAN_IFLAG_RX_FIFO_AVAILABLE, ®s->iflag1); |
| 719 | priv->read(®s->timer); |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 720 | } |
Fabio Baltieri | adccadb | 2012-12-18 18:50:58 +0100 | [diff] [blame] | 721 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 722 | return 1; |
| 723 | } |
| 724 | |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 725 | |
| 726 | static inline u64 flexcan_read_reg_iflag_rx(struct flexcan_priv *priv) |
| 727 | { |
| 728 | struct flexcan_regs __iomem *regs = priv->regs; |
| 729 | u32 iflag1, iflag2; |
| 730 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 731 | iflag2 = priv->read(®s->iflag2) & priv->reg_imask2_default; |
| 732 | iflag1 = priv->read(®s->iflag1) & priv->reg_imask1_default & |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 733 | ~FLEXCAN_IFLAG_MB(priv->tx_mb_idx); |
| 734 | |
| 735 | return (u64)iflag2 << 32 | iflag1; |
| 736 | } |
| 737 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 738 | static irqreturn_t flexcan_irq(int irq, void *dev_id) |
| 739 | { |
| 740 | struct net_device *dev = dev_id; |
| 741 | struct net_device_stats *stats = &dev->stats; |
| 742 | struct flexcan_priv *priv = netdev_priv(dev); |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 743 | struct flexcan_regs __iomem *regs = priv->regs; |
Marc Kleine-Budde | dd2f122 | 2017-01-18 11:45:14 +0100 | [diff] [blame] | 744 | irqreturn_t handled = IRQ_NONE; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 745 | u32 reg_iflag1, reg_esr; |
ZHU Yi (ST-FIR/ENG1-Zhu) | da49a80 | 2017-09-15 07:03:58 +0000 | [diff] [blame] | 746 | enum can_state last_state = priv->can.state; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 747 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 748 | reg_iflag1 = priv->read(®s->iflag1); |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 749 | |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 750 | /* reception interrupt */ |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 751 | if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) { |
| 752 | u64 reg_iflag; |
| 753 | int ret; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 754 | |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 755 | while ((reg_iflag = flexcan_read_reg_iflag_rx(priv))) { |
| 756 | handled = IRQ_HANDLED; |
| 757 | ret = can_rx_offload_irq_offload_timestamp(&priv->offload, |
| 758 | reg_iflag); |
| 759 | if (!ret) |
| 760 | break; |
| 761 | } |
| 762 | } else { |
| 763 | if (reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_AVAILABLE) { |
| 764 | handled = IRQ_HANDLED; |
| 765 | can_rx_offload_irq_offload_fifo(&priv->offload); |
| 766 | } |
| 767 | |
| 768 | /* FIFO overflow interrupt */ |
| 769 | if (reg_iflag1 & FLEXCAN_IFLAG_RX_FIFO_OVERFLOW) { |
| 770 | handled = IRQ_HANDLED; |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 771 | priv->write(FLEXCAN_IFLAG_RX_FIFO_OVERFLOW, |
| 772 | ®s->iflag1); |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 773 | dev->stats.rx_over_errors++; |
| 774 | dev->stats.rx_errors++; |
| 775 | } |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | /* transmission complete interrupt */ |
Marc Kleine-Budde | b93917c | 2015-07-12 00:47:47 +0200 | [diff] [blame] | 779 | if (reg_iflag1 & FLEXCAN_IFLAG_MB(priv->tx_mb_idx)) { |
Marc Kleine-Budde | dd2f122 | 2017-01-18 11:45:14 +0100 | [diff] [blame] | 780 | handled = IRQ_HANDLED; |
Reuben Dowle | 9a12349 | 2011-11-01 11:18:03 +1300 | [diff] [blame] | 781 | stats->tx_bytes += can_get_echo_skb(dev, 0); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 782 | stats->tx_packets++; |
Fabio Baltieri | adccadb | 2012-12-18 18:50:58 +0100 | [diff] [blame] | 783 | can_led_event(dev, CAN_LED_EVENT_TX); |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 784 | |
| 785 | /* after sending a RTR frame MB is in RX mode */ |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 786 | priv->write(FLEXCAN_MB_CODE_TX_INACTIVE, |
| 787 | &priv->tx_mb->can_ctrl); |
| 788 | priv->write(FLEXCAN_IFLAG_MB(priv->tx_mb_idx), ®s->iflag1); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 789 | netif_wake_queue(dev); |
| 790 | } |
| 791 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 792 | reg_esr = priv->read(®s->esr); |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 793 | |
Marc Kleine-Budde | dd2f122 | 2017-01-18 11:45:14 +0100 | [diff] [blame] | 794 | /* ACK all bus error and state change IRQ sources */ |
| 795 | if (reg_esr & FLEXCAN_ESR_ALL_INT) { |
| 796 | handled = IRQ_HANDLED; |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 797 | priv->write(reg_esr & FLEXCAN_ESR_ALL_INT, ®s->esr); |
Marc Kleine-Budde | dd2f122 | 2017-01-18 11:45:14 +0100 | [diff] [blame] | 798 | } |
| 799 | |
ZHU Yi (ST-FIR/ENG1-Zhu) | ad23023 | 2017-09-15 06:59:15 +0000 | [diff] [blame] | 800 | /* state change interrupt or broken error state quirk fix is enabled */ |
| 801 | if ((reg_esr & FLEXCAN_ESR_ERR_STATE) || |
ZHU Yi (ST-FIR/ENG1-Zhu) | da49a80 | 2017-09-15 07:03:58 +0000 | [diff] [blame] | 802 | (priv->devtype_data->quirks & (FLEXCAN_QUIRK_BROKEN_WERR_STATE | |
| 803 | FLEXCAN_QUIRK_BROKEN_PERR_STATE))) |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 804 | flexcan_irq_state(dev, reg_esr); |
| 805 | |
| 806 | /* bus error IRQ - handle if bus error reporting is activated */ |
| 807 | if ((reg_esr & FLEXCAN_ESR_ERR_BUS) && |
| 808 | (priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)) |
| 809 | flexcan_irq_bus_err(dev, reg_esr); |
| 810 | |
ZHU Yi (ST-FIR/ENG1-Zhu) | da49a80 | 2017-09-15 07:03:58 +0000 | [diff] [blame] | 811 | /* availability of error interrupt among state transitions in case |
| 812 | * bus error reporting is de-activated and |
| 813 | * FLEXCAN_QUIRK_BROKEN_PERR_STATE is enabled: |
| 814 | * +--------------------------------------------------------------+ |
| 815 | * | +----------------------------------------------+ [stopped / | |
| 816 | * | | | sleeping] -+ |
| 817 | * +-+-> active <-> warning <-> passive -> bus off -+ |
| 818 | * ___________^^^^^^^^^^^^_______________________________ |
| 819 | * disabled(1) enabled disabled |
| 820 | * |
| 821 | * (1): enabled if FLEXCAN_QUIRK_BROKEN_WERR_STATE is enabled |
| 822 | */ |
| 823 | if ((last_state != priv->can.state) && |
| 824 | (priv->devtype_data->quirks & FLEXCAN_QUIRK_BROKEN_PERR_STATE) && |
| 825 | !(priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING)) { |
| 826 | switch (priv->can.state) { |
| 827 | case CAN_STATE_ERROR_ACTIVE: |
| 828 | if (priv->devtype_data->quirks & |
| 829 | FLEXCAN_QUIRK_BROKEN_WERR_STATE) |
| 830 | flexcan_error_irq_enable(priv); |
| 831 | else |
| 832 | flexcan_error_irq_disable(priv); |
| 833 | break; |
| 834 | |
| 835 | case CAN_STATE_ERROR_WARNING: |
| 836 | flexcan_error_irq_enable(priv); |
| 837 | break; |
| 838 | |
| 839 | case CAN_STATE_ERROR_PASSIVE: |
| 840 | case CAN_STATE_BUS_OFF: |
| 841 | flexcan_error_irq_disable(priv); |
| 842 | break; |
| 843 | |
| 844 | default: |
| 845 | break; |
| 846 | } |
| 847 | } |
| 848 | |
Marc Kleine-Budde | dd2f122 | 2017-01-18 11:45:14 +0100 | [diff] [blame] | 849 | return handled; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | static void flexcan_set_bittiming(struct net_device *dev) |
| 853 | { |
| 854 | const struct flexcan_priv *priv = netdev_priv(dev); |
| 855 | const struct can_bittiming *bt = &priv->can.bittiming; |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 856 | struct flexcan_regs __iomem *regs = priv->regs; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 857 | u32 reg; |
| 858 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 859 | reg = priv->read(®s->ctrl); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 860 | reg &= ~(FLEXCAN_CTRL_PRESDIV(0xff) | |
| 861 | FLEXCAN_CTRL_RJW(0x3) | |
| 862 | FLEXCAN_CTRL_PSEG1(0x7) | |
| 863 | FLEXCAN_CTRL_PSEG2(0x7) | |
| 864 | FLEXCAN_CTRL_PROPSEG(0x7) | |
| 865 | FLEXCAN_CTRL_LPB | |
| 866 | FLEXCAN_CTRL_SMP | |
| 867 | FLEXCAN_CTRL_LOM); |
| 868 | |
| 869 | reg |= FLEXCAN_CTRL_PRESDIV(bt->brp - 1) | |
| 870 | FLEXCAN_CTRL_PSEG1(bt->phase_seg1 - 1) | |
| 871 | FLEXCAN_CTRL_PSEG2(bt->phase_seg2 - 1) | |
| 872 | FLEXCAN_CTRL_RJW(bt->sjw - 1) | |
| 873 | FLEXCAN_CTRL_PROPSEG(bt->prop_seg - 1); |
| 874 | |
| 875 | if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK) |
| 876 | reg |= FLEXCAN_CTRL_LPB; |
| 877 | if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY) |
| 878 | reg |= FLEXCAN_CTRL_LOM; |
| 879 | if (priv->can.ctrlmode & CAN_CTRLMODE_3_SAMPLES) |
| 880 | reg |= FLEXCAN_CTRL_SMP; |
| 881 | |
Lucas Stach | 7a4b6c8 | 2015-08-07 17:16:03 +0200 | [diff] [blame] | 882 | netdev_dbg(dev, "writing ctrl=0x%08x\n", reg); |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 883 | priv->write(reg, ®s->ctrl); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 884 | |
| 885 | /* print chip status */ |
Wolfgang Grandegger | aabdfd6 | 2012-02-01 11:02:05 +0100 | [diff] [blame] | 886 | netdev_dbg(dev, "%s: mcr=0x%08x ctrl=0x%08x\n", __func__, |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 887 | priv->read(®s->mcr), priv->read(®s->ctrl)); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 888 | } |
| 889 | |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 890 | /* flexcan_chip_start |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 891 | * |
| 892 | * this functions is entered with clocks enabled |
| 893 | * |
| 894 | */ |
| 895 | static int flexcan_chip_start(struct net_device *dev) |
| 896 | { |
| 897 | struct flexcan_priv *priv = netdev_priv(dev); |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 898 | struct flexcan_regs __iomem *regs = priv->regs; |
Marc Kleine-Budde | 6f75fce | 2014-09-23 11:03:01 +0200 | [diff] [blame] | 899 | u32 reg_mcr, reg_ctrl, reg_ctrl2, reg_mecr; |
David S. Miller | 1f6d803 | 2014-09-23 12:09:27 -0400 | [diff] [blame] | 900 | int err, i; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 901 | |
| 902 | /* enable module */ |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 903 | err = flexcan_chip_enable(priv); |
| 904 | if (err) |
| 905 | return err; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 906 | |
| 907 | /* soft reset */ |
Marc Kleine-Budde | 4b5b822 | 2014-02-28 15:16:59 +0100 | [diff] [blame] | 908 | err = flexcan_chip_softreset(priv); |
| 909 | if (err) |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 910 | goto out_chip_disable; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 911 | |
| 912 | flexcan_set_bittiming(dev); |
| 913 | |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 914 | /* MCR |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 915 | * |
| 916 | * enable freeze |
| 917 | * enable fifo |
| 918 | * halt now |
| 919 | * only supervisor access |
| 920 | * enable warning int |
Reuben Dowle | 9a12349 | 2011-11-01 11:18:03 +1300 | [diff] [blame] | 921 | * disable local echo |
Marc Kleine-Budde | 4bd888a | 2015-08-31 21:03:29 +0200 | [diff] [blame] | 922 | * enable individual RX masking |
Marc Kleine-Budde | 749de6f | 2015-08-31 21:32:34 +0200 | [diff] [blame] | 923 | * choose format C |
| 924 | * set max mailbox number |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 925 | */ |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 926 | reg_mcr = priv->read(®s->mcr); |
Marc Kleine-Budde | d5a7b40 | 2013-10-04 10:52:36 +0200 | [diff] [blame] | 927 | reg_mcr &= ~FLEXCAN_MCR_MAXMB(0xff); |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 928 | reg_mcr |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT | FLEXCAN_MCR_SUPV | |
| 929 | FLEXCAN_MCR_WRN_EN | FLEXCAN_MCR_SRX_DIS | FLEXCAN_MCR_IRMQ | |
| 930 | FLEXCAN_MCR_IDAM_C; |
| 931 | |
| 932 | if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) { |
| 933 | reg_mcr &= ~FLEXCAN_MCR_FEN; |
| 934 | reg_mcr |= FLEXCAN_MCR_MAXMB(priv->offload.mb_last); |
| 935 | } else { |
| 936 | reg_mcr |= FLEXCAN_MCR_FEN | |
| 937 | FLEXCAN_MCR_MAXMB(priv->tx_mb_idx); |
| 938 | } |
Wolfgang Grandegger | aabdfd6 | 2012-02-01 11:02:05 +0100 | [diff] [blame] | 939 | netdev_dbg(dev, "%s: writing mcr=0x%08x", __func__, reg_mcr); |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 940 | priv->write(reg_mcr, ®s->mcr); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 941 | |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 942 | /* CTRL |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 943 | * |
| 944 | * disable timer sync feature |
| 945 | * |
| 946 | * disable auto busoff recovery |
| 947 | * transmit lowest buffer first |
| 948 | * |
| 949 | * enable tx and rx warning interrupt |
| 950 | * enable bus off interrupt |
| 951 | * (== FLEXCAN_CTRL_ERR_STATE) |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 952 | */ |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 953 | reg_ctrl = priv->read(®s->ctrl); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 954 | reg_ctrl &= ~FLEXCAN_CTRL_TSYN; |
| 955 | reg_ctrl |= FLEXCAN_CTRL_BOFF_REC | FLEXCAN_CTRL_LBUF | |
Wolfgang Grandegger | 4f72e5f | 2012-09-28 03:17:15 +0000 | [diff] [blame] | 956 | FLEXCAN_CTRL_ERR_STATE; |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 957 | |
| 958 | /* enable the "error interrupt" (FLEXCAN_CTRL_ERR_MSK), |
Wolfgang Grandegger | 4f72e5f | 2012-09-28 03:17:15 +0000 | [diff] [blame] | 959 | * on most Flexcan cores, too. Otherwise we don't get |
| 960 | * any error warning or passive interrupts. |
| 961 | */ |
ZHU Yi (ST-FIR/ENG1-Zhu) | 2f8639b | 2017-09-15 07:01:23 +0000 | [diff] [blame] | 962 | if (priv->devtype_data->quirks & FLEXCAN_QUIRK_BROKEN_WERR_STATE || |
Wolfgang Grandegger | 4f72e5f | 2012-09-28 03:17:15 +0000 | [diff] [blame] | 963 | priv->can.ctrlmode & CAN_CTRLMODE_BERR_REPORTING) |
| 964 | reg_ctrl |= FLEXCAN_CTRL_ERR_MSK; |
Alexander Stein | bc03a54 | 2014-08-12 10:47:21 +0200 | [diff] [blame] | 965 | else |
| 966 | reg_ctrl &= ~FLEXCAN_CTRL_ERR_MSK; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 967 | |
| 968 | /* save for later use */ |
| 969 | priv->reg_ctrl_default = reg_ctrl; |
Marc Kleine-Budde | 6fa7da2 | 2015-08-27 14:24:48 +0200 | [diff] [blame] | 970 | /* leave interrupts disabled for now */ |
| 971 | reg_ctrl &= ~FLEXCAN_CTRL_ERR_ALL; |
Wolfgang Grandegger | aabdfd6 | 2012-02-01 11:02:05 +0100 | [diff] [blame] | 972 | netdev_dbg(dev, "%s: writing ctrl=0x%08x", __func__, reg_ctrl); |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 973 | priv->write(reg_ctrl, ®s->ctrl); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 974 | |
Marc Kleine-Budde | 9eb7aa8 | 2015-09-01 08:57:55 +0200 | [diff] [blame] | 975 | if ((priv->devtype_data->quirks & FLEXCAN_QUIRK_ENABLE_EACEN_RRS)) { |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 976 | reg_ctrl2 = priv->read(®s->ctrl2); |
Marc Kleine-Budde | 9eb7aa8 | 2015-09-01 08:57:55 +0200 | [diff] [blame] | 977 | reg_ctrl2 |= FLEXCAN_CTRL2_EACEN | FLEXCAN_CTRL2_RRS; |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 978 | priv->write(reg_ctrl2, ®s->ctrl2); |
Marc Kleine-Budde | 9eb7aa8 | 2015-09-01 08:57:55 +0200 | [diff] [blame] | 979 | } |
| 980 | |
David Jander | fc05b88 | 2014-08-27 11:58:05 +0200 | [diff] [blame] | 981 | /* clear and invalidate all mailboxes first */ |
Marc Kleine-Budde | b93917c | 2015-07-12 00:47:47 +0200 | [diff] [blame] | 982 | for (i = priv->tx_mb_idx; i < ARRAY_SIZE(regs->mb); i++) { |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 983 | priv->write(FLEXCAN_MB_CODE_RX_INACTIVE, |
| 984 | ®s->mb[i].can_ctrl); |
David Jander | fc05b88 | 2014-08-27 11:58:05 +0200 | [diff] [blame] | 985 | } |
| 986 | |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 987 | if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) { |
| 988 | for (i = priv->offload.mb_first; i <= priv->offload.mb_last; i++) |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 989 | priv->write(FLEXCAN_MB_CODE_RX_EMPTY, |
| 990 | ®s->mb[i].can_ctrl); |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 991 | } |
| 992 | |
David Jander | 25e9244 | 2014-09-03 16:47:22 +0200 | [diff] [blame] | 993 | /* Errata ERR005829: mark first TX mailbox as INACTIVE */ |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 994 | priv->write(FLEXCAN_MB_CODE_TX_INACTIVE, |
| 995 | &priv->tx_mb_reserved->can_ctrl); |
David Jander | 25e9244 | 2014-09-03 16:47:22 +0200 | [diff] [blame] | 996 | |
Marc Kleine-Budde | c32fe4a | 2014-09-16 12:39:28 +0200 | [diff] [blame] | 997 | /* mark TX mailbox as INACTIVE */ |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 998 | priv->write(FLEXCAN_MB_CODE_TX_INACTIVE, |
| 999 | &priv->tx_mb->can_ctrl); |
Marc Kleine-Budde | d5a7b40 | 2013-10-04 10:52:36 +0200 | [diff] [blame] | 1000 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1001 | /* acceptance mask/acceptance code (accept everything) */ |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1002 | priv->write(0x0, ®s->rxgmask); |
| 1003 | priv->write(0x0, ®s->rx14mask); |
| 1004 | priv->write(0x0, ®s->rx15mask); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1005 | |
Marc Kleine-Budde | f377bff | 2015-05-08 15:22:36 +0200 | [diff] [blame] | 1006 | if (priv->devtype_data->quirks & FLEXCAN_QUIRK_DISABLE_RXFG) |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1007 | priv->write(0x0, ®s->rxfgmask); |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 1008 | |
Marc Kleine-Budde | 4bd888a | 2015-08-31 21:03:29 +0200 | [diff] [blame] | 1009 | /* clear acceptance filters */ |
| 1010 | for (i = 0; i < ARRAY_SIZE(regs->mb); i++) |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1011 | priv->write(0, ®s->rximr[i]); |
Marc Kleine-Budde | 4bd888a | 2015-08-31 21:03:29 +0200 | [diff] [blame] | 1012 | |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 1013 | /* On Vybrid, disable memory error detection interrupts |
Stefan Agner | cdce844 | 2014-07-15 14:56:21 +0200 | [diff] [blame] | 1014 | * and freeze mode. |
| 1015 | * This also works around errata e5295 which generates |
| 1016 | * false positive memory errors and put the device in |
| 1017 | * freeze mode. |
| 1018 | */ |
Marc Kleine-Budde | f377bff | 2015-05-08 15:22:36 +0200 | [diff] [blame] | 1019 | if (priv->devtype_data->quirks & FLEXCAN_QUIRK_DISABLE_MECR) { |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 1020 | /* Follow the protocol as described in "Detection |
Stefan Agner | cdce844 | 2014-07-15 14:56:21 +0200 | [diff] [blame] | 1021 | * and Correction of Memory Errors" to write to |
| 1022 | * MECR register |
| 1023 | */ |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1024 | reg_ctrl2 = priv->read(®s->ctrl2); |
Marc Kleine-Budde | 6f75fce | 2014-09-23 11:03:01 +0200 | [diff] [blame] | 1025 | reg_ctrl2 |= FLEXCAN_CTRL2_ECRWRE; |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1026 | priv->write(reg_ctrl2, ®s->ctrl2); |
Stefan Agner | cdce844 | 2014-07-15 14:56:21 +0200 | [diff] [blame] | 1027 | |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1028 | reg_mecr = priv->read(®s->mecr); |
Stefan Agner | cdce844 | 2014-07-15 14:56:21 +0200 | [diff] [blame] | 1029 | reg_mecr &= ~FLEXCAN_MECR_ECRWRDIS; |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1030 | priv->write(reg_mecr, ®s->mecr); |
Stefan Agner | cdce844 | 2014-07-15 14:56:21 +0200 | [diff] [blame] | 1031 | reg_mecr &= ~(FLEXCAN_MECR_NCEFAFRZ | FLEXCAN_MECR_HANCEI_MSK | |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 1032 | FLEXCAN_MECR_FANCEI_MSK); |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1033 | priv->write(reg_mecr, ®s->mecr); |
Stefan Agner | cdce844 | 2014-07-15 14:56:21 +0200 | [diff] [blame] | 1034 | } |
| 1035 | |
Marc Kleine-Budde | f003698 | 2014-02-28 17:18:27 +0100 | [diff] [blame] | 1036 | err = flexcan_transceiver_enable(priv); |
| 1037 | if (err) |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 1038 | goto out_chip_disable; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1039 | |
| 1040 | /* synchronize with the can bus */ |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 1041 | err = flexcan_chip_unfreeze(priv); |
| 1042 | if (err) |
| 1043 | goto out_transceiver_disable; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1044 | |
| 1045 | priv->can.state = CAN_STATE_ERROR_ACTIVE; |
| 1046 | |
Marc Kleine-Budde | 6fa7da2 | 2015-08-27 14:24:48 +0200 | [diff] [blame] | 1047 | /* enable interrupts atomically */ |
| 1048 | disable_irq(dev->irq); |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1049 | priv->write(priv->reg_ctrl_default, ®s->ctrl); |
| 1050 | priv->write(priv->reg_imask1_default, ®s->imask1); |
| 1051 | priv->write(priv->reg_imask2_default, ®s->imask2); |
Marc Kleine-Budde | 6fa7da2 | 2015-08-27 14:24:48 +0200 | [diff] [blame] | 1052 | enable_irq(dev->irq); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1053 | |
| 1054 | /* print chip status */ |
Wolfgang Grandegger | aabdfd6 | 2012-02-01 11:02:05 +0100 | [diff] [blame] | 1055 | netdev_dbg(dev, "%s: reading mcr=0x%08x ctrl=0x%08x\n", __func__, |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1056 | priv->read(®s->mcr), priv->read(®s->ctrl)); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1057 | |
| 1058 | return 0; |
| 1059 | |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 1060 | out_transceiver_disable: |
| 1061 | flexcan_transceiver_disable(priv); |
| 1062 | out_chip_disable: |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1063 | flexcan_chip_disable(priv); |
| 1064 | return err; |
| 1065 | } |
| 1066 | |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 1067 | /* flexcan_chip_stop |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1068 | * |
| 1069 | * this functions is entered with clocks enabled |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1070 | */ |
| 1071 | static void flexcan_chip_stop(struct net_device *dev) |
| 1072 | { |
| 1073 | struct flexcan_priv *priv = netdev_priv(dev); |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 1074 | struct flexcan_regs __iomem *regs = priv->regs; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1075 | |
Marc Kleine-Budde | b1aa1c7 | 2014-02-28 17:08:21 +0100 | [diff] [blame] | 1076 | /* freeze + disable module */ |
| 1077 | flexcan_chip_freeze(priv); |
| 1078 | flexcan_chip_disable(priv); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1079 | |
Marc Kleine-Budde | 5be93bd | 2014-02-19 12:00:51 +0100 | [diff] [blame] | 1080 | /* Disable all interrupts */ |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1081 | priv->write(0, ®s->imask2); |
| 1082 | priv->write(0, ®s->imask1); |
| 1083 | priv->write(priv->reg_ctrl_default & ~FLEXCAN_CTRL_ERR_ALL, |
| 1084 | ®s->ctrl); |
Marc Kleine-Budde | 5be93bd | 2014-02-19 12:00:51 +0100 | [diff] [blame] | 1085 | |
Marc Kleine-Budde | f003698 | 2014-02-28 17:18:27 +0100 | [diff] [blame] | 1086 | flexcan_transceiver_disable(priv); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1087 | priv->can.state = CAN_STATE_STOPPED; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | static int flexcan_open(struct net_device *dev) |
| 1091 | { |
| 1092 | struct flexcan_priv *priv = netdev_priv(dev); |
| 1093 | int err; |
| 1094 | |
Fabio Estevam | aa10181 | 2013-07-22 12:41:40 -0300 | [diff] [blame] | 1095 | err = clk_prepare_enable(priv->clk_ipg); |
| 1096 | if (err) |
| 1097 | return err; |
| 1098 | |
| 1099 | err = clk_prepare_enable(priv->clk_per); |
| 1100 | if (err) |
| 1101 | goto out_disable_ipg; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1102 | |
| 1103 | err = open_candev(dev); |
| 1104 | if (err) |
Fabio Estevam | aa10181 | 2013-07-22 12:41:40 -0300 | [diff] [blame] | 1105 | goto out_disable_per; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1106 | |
| 1107 | err = request_irq(dev->irq, flexcan_irq, IRQF_SHARED, dev->name, dev); |
| 1108 | if (err) |
| 1109 | goto out_close; |
| 1110 | |
| 1111 | /* start chip and queuing */ |
| 1112 | err = flexcan_chip_start(dev); |
| 1113 | if (err) |
Marc Kleine-Budde | 7e9e148 | 2014-02-28 14:52:01 +0100 | [diff] [blame] | 1114 | goto out_free_irq; |
Fabio Baltieri | adccadb | 2012-12-18 18:50:58 +0100 | [diff] [blame] | 1115 | |
| 1116 | can_led_event(dev, CAN_LED_EVENT_OPEN); |
| 1117 | |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 1118 | can_rx_offload_enable(&priv->offload); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1119 | netif_start_queue(dev); |
| 1120 | |
| 1121 | return 0; |
| 1122 | |
Marc Kleine-Budde | 7e9e148 | 2014-02-28 14:52:01 +0100 | [diff] [blame] | 1123 | out_free_irq: |
| 1124 | free_irq(dev->irq, dev); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1125 | out_close: |
| 1126 | close_candev(dev); |
Fabio Estevam | aa10181 | 2013-07-22 12:41:40 -0300 | [diff] [blame] | 1127 | out_disable_per: |
Steffen Trumtrar | 3d42a37 | 2012-07-17 16:14:34 +0200 | [diff] [blame] | 1128 | clk_disable_unprepare(priv->clk_per); |
Fabio Estevam | aa10181 | 2013-07-22 12:41:40 -0300 | [diff] [blame] | 1129 | out_disable_ipg: |
Steffen Trumtrar | 3d42a37 | 2012-07-17 16:14:34 +0200 | [diff] [blame] | 1130 | clk_disable_unprepare(priv->clk_ipg); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1131 | |
| 1132 | return err; |
| 1133 | } |
| 1134 | |
| 1135 | static int flexcan_close(struct net_device *dev) |
| 1136 | { |
| 1137 | struct flexcan_priv *priv = netdev_priv(dev); |
| 1138 | |
| 1139 | netif_stop_queue(dev); |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 1140 | can_rx_offload_disable(&priv->offload); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1141 | flexcan_chip_stop(dev); |
| 1142 | |
| 1143 | free_irq(dev->irq, dev); |
Steffen Trumtrar | 3d42a37 | 2012-07-17 16:14:34 +0200 | [diff] [blame] | 1144 | clk_disable_unprepare(priv->clk_per); |
| 1145 | clk_disable_unprepare(priv->clk_ipg); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1146 | |
| 1147 | close_candev(dev); |
| 1148 | |
Fabio Baltieri | adccadb | 2012-12-18 18:50:58 +0100 | [diff] [blame] | 1149 | can_led_event(dev, CAN_LED_EVENT_STOP); |
| 1150 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1151 | return 0; |
| 1152 | } |
| 1153 | |
| 1154 | static int flexcan_set_mode(struct net_device *dev, enum can_mode mode) |
| 1155 | { |
| 1156 | int err; |
| 1157 | |
| 1158 | switch (mode) { |
| 1159 | case CAN_MODE_START: |
| 1160 | err = flexcan_chip_start(dev); |
| 1161 | if (err) |
| 1162 | return err; |
| 1163 | |
| 1164 | netif_wake_queue(dev); |
| 1165 | break; |
| 1166 | |
| 1167 | default: |
| 1168 | return -EOPNOTSUPP; |
| 1169 | } |
| 1170 | |
| 1171 | return 0; |
| 1172 | } |
| 1173 | |
| 1174 | static const struct net_device_ops flexcan_netdev_ops = { |
| 1175 | .ndo_open = flexcan_open, |
| 1176 | .ndo_stop = flexcan_close, |
| 1177 | .ndo_start_xmit = flexcan_start_xmit, |
Oliver Hartkopp | c971fa2 | 2014-03-07 09:23:41 +0100 | [diff] [blame] | 1178 | .ndo_change_mtu = can_change_mtu, |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1179 | }; |
| 1180 | |
Bill Pemberton | 3c8ac0f | 2012-12-03 09:22:44 -0500 | [diff] [blame] | 1181 | static int register_flexcandev(struct net_device *dev) |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1182 | { |
| 1183 | struct flexcan_priv *priv = netdev_priv(dev); |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 1184 | struct flexcan_regs __iomem *regs = priv->regs; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1185 | u32 reg, err; |
| 1186 | |
Fabio Estevam | aa10181 | 2013-07-22 12:41:40 -0300 | [diff] [blame] | 1187 | err = clk_prepare_enable(priv->clk_ipg); |
| 1188 | if (err) |
| 1189 | return err; |
| 1190 | |
| 1191 | err = clk_prepare_enable(priv->clk_per); |
| 1192 | if (err) |
| 1193 | goto out_disable_ipg; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1194 | |
| 1195 | /* select "bus clock", chip must be disabled */ |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 1196 | err = flexcan_chip_disable(priv); |
| 1197 | if (err) |
| 1198 | goto out_disable_per; |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1199 | reg = priv->read(®s->ctrl); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1200 | reg |= FLEXCAN_CTRL_CLK_SRC; |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1201 | priv->write(reg, ®s->ctrl); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1202 | |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 1203 | err = flexcan_chip_enable(priv); |
| 1204 | if (err) |
| 1205 | goto out_chip_disable; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1206 | |
| 1207 | /* set freeze, halt and activate FIFO, restrict register access */ |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1208 | reg = priv->read(®s->mcr); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1209 | reg |= FLEXCAN_MCR_FRZ | FLEXCAN_MCR_HALT | |
| 1210 | FLEXCAN_MCR_FEN | FLEXCAN_MCR_SUPV; |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1211 | priv->write(reg, ®s->mcr); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1212 | |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 1213 | /* Currently we only support newer versions of this core |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 1214 | * featuring a RX hardware FIFO (although this driver doesn't |
| 1215 | * make use of it on some cores). Older cores, found on some |
| 1216 | * Coldfire derivates are not tested. |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1217 | */ |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1218 | reg = priv->read(®s->mcr); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1219 | if (!(reg & FLEXCAN_MCR_FEN)) { |
Wolfgang Grandegger | aabdfd6 | 2012-02-01 11:02:05 +0100 | [diff] [blame] | 1220 | netdev_err(dev, "Could not enable RX FIFO, unsupported core\n"); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1221 | err = -ENODEV; |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 1222 | goto out_chip_disable; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | err = register_candev(dev); |
| 1226 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1227 | /* disable core and turn off clocks */ |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 1228 | out_chip_disable: |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1229 | flexcan_chip_disable(priv); |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 1230 | out_disable_per: |
Steffen Trumtrar | 3d42a37 | 2012-07-17 16:14:34 +0200 | [diff] [blame] | 1231 | clk_disable_unprepare(priv->clk_per); |
Fabio Estevam | aa10181 | 2013-07-22 12:41:40 -0300 | [diff] [blame] | 1232 | out_disable_ipg: |
Steffen Trumtrar | 3d42a37 | 2012-07-17 16:14:34 +0200 | [diff] [blame] | 1233 | clk_disable_unprepare(priv->clk_ipg); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1234 | |
| 1235 | return err; |
| 1236 | } |
| 1237 | |
Bill Pemberton | 3c8ac0f | 2012-12-03 09:22:44 -0500 | [diff] [blame] | 1238 | static void unregister_flexcandev(struct net_device *dev) |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1239 | { |
| 1240 | unregister_candev(dev); |
| 1241 | } |
| 1242 | |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 1243 | static const struct of_device_id flexcan_of_match[] = { |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 1244 | { .compatible = "fsl,imx6q-flexcan", .data = &fsl_imx6q_devtype_data, }, |
Marc Kleine-Budde | e358784 | 2013-10-03 23:51:55 +0200 | [diff] [blame] | 1245 | { .compatible = "fsl,imx28-flexcan", .data = &fsl_imx28_devtype_data, }, |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1246 | { .compatible = "fsl,imx53-flexcan", .data = &fsl_p1010_devtype_data, }, |
| 1247 | { .compatible = "fsl,imx35-flexcan", .data = &fsl_p1010_devtype_data, }, |
| 1248 | { .compatible = "fsl,imx25-flexcan", .data = &fsl_p1010_devtype_data, }, |
Marc Kleine-Budde | e358784 | 2013-10-03 23:51:55 +0200 | [diff] [blame] | 1249 | { .compatible = "fsl,p1010-flexcan", .data = &fsl_p1010_devtype_data, }, |
Stefan Agner | cdce844 | 2014-07-15 14:56:21 +0200 | [diff] [blame] | 1250 | { .compatible = "fsl,vf610-flexcan", .data = &fsl_vf610_devtype_data, }, |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 1251 | { /* sentinel */ }, |
| 1252 | }; |
Marc Kleine-Budde | 4358a9d | 2012-10-04 10:55:35 +0200 | [diff] [blame] | 1253 | MODULE_DEVICE_TABLE(of, flexcan_of_match); |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 1254 | |
| 1255 | static const struct platform_device_id flexcan_id_table[] = { |
| 1256 | { .name = "flexcan", .driver_data = (kernel_ulong_t)&fsl_p1010_devtype_data, }, |
| 1257 | { /* sentinel */ }, |
| 1258 | }; |
Marc Kleine-Budde | 4358a9d | 2012-10-04 10:55:35 +0200 | [diff] [blame] | 1259 | MODULE_DEVICE_TABLE(platform, flexcan_id_table); |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 1260 | |
Bill Pemberton | 3c8ac0f | 2012-12-03 09:22:44 -0500 | [diff] [blame] | 1261 | static int flexcan_probe(struct platform_device *pdev) |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1262 | { |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 1263 | const struct of_device_id *of_id; |
Marc Kleine-Budde | dda0b3b | 2012-07-13 14:52:48 +0200 | [diff] [blame] | 1264 | const struct flexcan_devtype_data *devtype_data; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1265 | struct net_device *dev; |
| 1266 | struct flexcan_priv *priv; |
Andreas Werner | 555828e | 2015-03-22 17:35:52 +0100 | [diff] [blame] | 1267 | struct regulator *reg_xceiver; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1268 | struct resource *mem; |
Steffen Trumtrar | 3d42a37 | 2012-07-17 16:14:34 +0200 | [diff] [blame] | 1269 | struct clk *clk_ipg = NULL, *clk_per = NULL; |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 1270 | struct flexcan_regs __iomem *regs; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1271 | int err, irq; |
holt@sgi.com | 97efe9a | 2011-08-16 17:32:23 +0000 | [diff] [blame] | 1272 | u32 clock_freq = 0; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1273 | |
Andreas Werner | 555828e | 2015-03-22 17:35:52 +0100 | [diff] [blame] | 1274 | reg_xceiver = devm_regulator_get(&pdev->dev, "xceiver"); |
| 1275 | if (PTR_ERR(reg_xceiver) == -EPROBE_DEFER) |
| 1276 | return -EPROBE_DEFER; |
| 1277 | else if (IS_ERR(reg_xceiver)) |
| 1278 | reg_xceiver = NULL; |
| 1279 | |
Hui Wang | afc016d | 2012-06-28 16:21:34 +0800 | [diff] [blame] | 1280 | if (pdev->dev.of_node) |
| 1281 | of_property_read_u32(pdev->dev.of_node, |
Marc Kleine-Budde | 0012e5c | 2015-08-06 14:53:57 +0200 | [diff] [blame] | 1282 | "clock-frequency", &clock_freq); |
holt@sgi.com | 97efe9a | 2011-08-16 17:32:23 +0000 | [diff] [blame] | 1283 | |
| 1284 | if (!clock_freq) { |
Steffen Trumtrar | 3d42a37 | 2012-07-17 16:14:34 +0200 | [diff] [blame] | 1285 | clk_ipg = devm_clk_get(&pdev->dev, "ipg"); |
| 1286 | if (IS_ERR(clk_ipg)) { |
| 1287 | dev_err(&pdev->dev, "no ipg clock defined\n"); |
Fabio Estevam | 933e4af | 2013-07-22 12:41:39 -0300 | [diff] [blame] | 1288 | return PTR_ERR(clk_ipg); |
holt@sgi.com | 97efe9a | 2011-08-16 17:32:23 +0000 | [diff] [blame] | 1289 | } |
Steffen Trumtrar | 3d42a37 | 2012-07-17 16:14:34 +0200 | [diff] [blame] | 1290 | |
| 1291 | clk_per = devm_clk_get(&pdev->dev, "per"); |
| 1292 | if (IS_ERR(clk_per)) { |
| 1293 | dev_err(&pdev->dev, "no per clock defined\n"); |
Fabio Estevam | 933e4af | 2013-07-22 12:41:39 -0300 | [diff] [blame] | 1294 | return PTR_ERR(clk_per); |
Steffen Trumtrar | 3d42a37 | 2012-07-17 16:14:34 +0200 | [diff] [blame] | 1295 | } |
Marc Kleine-Budde | 1a3e517 | 2013-11-25 22:15:20 +0100 | [diff] [blame] | 1296 | clock_freq = clk_get_rate(clk_per); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1300 | irq = platform_get_irq(pdev, 0); |
Fabio Estevam | 933e4af | 2013-07-22 12:41:39 -0300 | [diff] [blame] | 1301 | if (irq <= 0) |
| 1302 | return -ENODEV; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1303 | |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 1304 | regs = devm_ioremap_resource(&pdev->dev, mem); |
| 1305 | if (IS_ERR(regs)) |
| 1306 | return PTR_ERR(regs); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1307 | |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 1308 | of_id = of_match_device(flexcan_of_match, &pdev->dev); |
| 1309 | if (of_id) { |
| 1310 | devtype_data = of_id->data; |
Marc Kleine-Budde | d0873e6 | 2014-03-04 22:04:22 +0100 | [diff] [blame] | 1311 | } else if (platform_get_device_id(pdev)->driver_data) { |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 1312 | devtype_data = (struct flexcan_devtype_data *) |
Marc Kleine-Budde | d0873e6 | 2014-03-04 22:04:22 +0100 | [diff] [blame] | 1313 | platform_get_device_id(pdev)->driver_data; |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 1314 | } else { |
Fabio Estevam | 933e4af | 2013-07-22 12:41:39 -0300 | [diff] [blame] | 1315 | return -ENODEV; |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 1316 | } |
| 1317 | |
Fabio Estevam | 933e4af | 2013-07-22 12:41:39 -0300 | [diff] [blame] | 1318 | dev = alloc_candev(sizeof(struct flexcan_priv), 1); |
| 1319 | if (!dev) |
| 1320 | return -ENOMEM; |
| 1321 | |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 1322 | platform_set_drvdata(pdev, dev); |
| 1323 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 1324 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1325 | dev->netdev_ops = &flexcan_netdev_ops; |
| 1326 | dev->irq = irq; |
Reuben Dowle | 9a12349 | 2011-11-01 11:18:03 +1300 | [diff] [blame] | 1327 | dev->flags |= IFF_ECHO; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1328 | |
| 1329 | priv = netdev_priv(dev); |
Pankaj Bansal | 88462d2 | 2017-11-24 18:52:08 +0530 | [diff] [blame^] | 1330 | |
| 1331 | if (of_property_read_bool(pdev->dev.of_node, "big-endian")) { |
| 1332 | priv->read = flexcan_read_be; |
| 1333 | priv->write = flexcan_write_be; |
| 1334 | } else { |
| 1335 | if (of_device_is_compatible(pdev->dev.of_node, |
| 1336 | "fsl,p1010-flexcan")) { |
| 1337 | priv->read = flexcan_read_be; |
| 1338 | priv->write = flexcan_write_be; |
| 1339 | } else { |
| 1340 | priv->read = flexcan_read_le; |
| 1341 | priv->write = flexcan_write_le; |
| 1342 | } |
| 1343 | } |
| 1344 | |
holt@sgi.com | 97efe9a | 2011-08-16 17:32:23 +0000 | [diff] [blame] | 1345 | priv->can.clock.freq = clock_freq; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1346 | priv->can.bittiming_const = &flexcan_bittiming_const; |
| 1347 | priv->can.do_set_mode = flexcan_set_mode; |
| 1348 | priv->can.do_get_berr_counter = flexcan_get_berr_counter; |
| 1349 | priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK | |
| 1350 | CAN_CTRLMODE_LISTENONLY | CAN_CTRLMODE_3_SAMPLES | |
| 1351 | CAN_CTRLMODE_BERR_REPORTING; |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 1352 | priv->regs = regs; |
Steffen Trumtrar | 3d42a37 | 2012-07-17 16:14:34 +0200 | [diff] [blame] | 1353 | priv->clk_ipg = clk_ipg; |
| 1354 | priv->clk_per = clk_per; |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 1355 | priv->devtype_data = devtype_data; |
Andreas Werner | 555828e | 2015-03-22 17:35:52 +0100 | [diff] [blame] | 1356 | priv->reg_xceiver = reg_xceiver; |
Fabio Estevam | b7c4114 | 2013-06-10 23:12:57 -0300 | [diff] [blame] | 1357 | |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 1358 | if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) { |
| 1359 | priv->tx_mb_idx = FLEXCAN_TX_MB_OFF_TIMESTAMP; |
| 1360 | priv->tx_mb_reserved = ®s->mb[FLEXCAN_TX_MB_RESERVED_OFF_TIMESTAMP]; |
| 1361 | } else { |
| 1362 | priv->tx_mb_idx = FLEXCAN_TX_MB_OFF_FIFO; |
| 1363 | priv->tx_mb_reserved = ®s->mb[FLEXCAN_TX_MB_RESERVED_OFF_FIFO]; |
| 1364 | } |
Marc Kleine-Budde | b93917c | 2015-07-12 00:47:47 +0200 | [diff] [blame] | 1365 | priv->tx_mb = ®s->mb[priv->tx_mb_idx]; |
| 1366 | |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 1367 | priv->reg_imask1_default = FLEXCAN_IFLAG_MB(priv->tx_mb_idx); |
| 1368 | priv->reg_imask2_default = 0; |
Marc Kleine-Budde | 28ac7dc | 2015-08-04 13:46:10 +0200 | [diff] [blame] | 1369 | |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 1370 | priv->offload.mailbox_read = flexcan_mailbox_read; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1371 | |
Marc Kleine-Budde | b3cf53e | 2015-09-01 09:00:13 +0200 | [diff] [blame] | 1372 | if (priv->devtype_data->quirks & FLEXCAN_QUIRK_USE_OFF_TIMESTAMP) { |
| 1373 | u64 imask; |
| 1374 | |
| 1375 | priv->offload.mb_first = FLEXCAN_RX_MB_OFF_TIMESTAMP_FIRST; |
| 1376 | priv->offload.mb_last = FLEXCAN_RX_MB_OFF_TIMESTAMP_LAST; |
| 1377 | |
| 1378 | imask = GENMASK_ULL(priv->offload.mb_last, priv->offload.mb_first); |
| 1379 | priv->reg_imask1_default |= imask; |
| 1380 | priv->reg_imask2_default |= imask >> 32; |
| 1381 | |
| 1382 | err = can_rx_offload_add_timestamp(dev, &priv->offload); |
| 1383 | } else { |
| 1384 | priv->reg_imask1_default |= FLEXCAN_IFLAG_RX_FIFO_OVERFLOW | |
| 1385 | FLEXCAN_IFLAG_RX_FIFO_AVAILABLE; |
| 1386 | err = can_rx_offload_add_fifo(dev, &priv->offload, FLEXCAN_NAPI_WEIGHT); |
| 1387 | } |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 1388 | if (err) |
| 1389 | goto failed_offload; |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1390 | |
| 1391 | err = register_flexcandev(dev); |
| 1392 | if (err) { |
| 1393 | dev_err(&pdev->dev, "registering netdev failed\n"); |
| 1394 | goto failed_register; |
| 1395 | } |
| 1396 | |
Fabio Baltieri | adccadb | 2012-12-18 18:50:58 +0100 | [diff] [blame] | 1397 | devm_can_led_init(dev); |
| 1398 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1399 | dev_info(&pdev->dev, "device registered (reg_base=%p, irq=%d)\n", |
Marc Kleine-Budde | 89af874 | 2015-05-08 09:32:58 +0200 | [diff] [blame] | 1400 | priv->regs, dev->irq); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1401 | |
| 1402 | return 0; |
| 1403 | |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 1404 | failed_offload: |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1405 | failed_register: |
| 1406 | free_candev(dev); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1407 | return err; |
| 1408 | } |
| 1409 | |
Bill Pemberton | 3c8ac0f | 2012-12-03 09:22:44 -0500 | [diff] [blame] | 1410 | static int flexcan_remove(struct platform_device *pdev) |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1411 | { |
| 1412 | struct net_device *dev = platform_get_drvdata(pdev); |
Marc Kleine-Budde | d96e43e | 2014-02-28 20:48:36 +0100 | [diff] [blame] | 1413 | struct flexcan_priv *priv = netdev_priv(dev); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1414 | |
| 1415 | unregister_flexcandev(dev); |
Marc Kleine-Budde | 3016475 | 2015-05-10 15:26:58 +0200 | [diff] [blame] | 1416 | can_rx_offload_del(&priv->offload); |
Marc Kleine-Budde | 9a27586 | 2010-10-21 05:07:58 +0000 | [diff] [blame] | 1417 | free_candev(dev); |
| 1418 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1419 | return 0; |
| 1420 | } |
| 1421 | |
Marc Kleine-Budde | 08c6d35 | 2014-03-05 19:10:44 +0100 | [diff] [blame] | 1422 | static int __maybe_unused flexcan_suspend(struct device *device) |
Eric Bénard | 8b5e218 | 2012-05-08 17:12:17 +0200 | [diff] [blame] | 1423 | { |
Fabio Estevam | 588e7a8 | 2013-05-20 15:43:43 -0300 | [diff] [blame] | 1424 | struct net_device *dev = dev_get_drvdata(device); |
Eric Bénard | 8b5e218 | 2012-05-08 17:12:17 +0200 | [diff] [blame] | 1425 | struct flexcan_priv *priv = netdev_priv(dev); |
Marc Kleine-Budde | 9b00b30 | 2014-02-28 15:30:18 +0100 | [diff] [blame] | 1426 | int err; |
Eric Bénard | 8b5e218 | 2012-05-08 17:12:17 +0200 | [diff] [blame] | 1427 | |
Eric Bénard | 8b5e218 | 2012-05-08 17:12:17 +0200 | [diff] [blame] | 1428 | if (netif_running(dev)) { |
Fabio Estevam | 4de349e | 2016-08-17 12:41:08 -0300 | [diff] [blame] | 1429 | err = flexcan_chip_disable(priv); |
| 1430 | if (err) |
| 1431 | return err; |
Eric Bénard | 8b5e218 | 2012-05-08 17:12:17 +0200 | [diff] [blame] | 1432 | netif_stop_queue(dev); |
| 1433 | netif_device_detach(dev); |
| 1434 | } |
| 1435 | priv->can.state = CAN_STATE_SLEEPING; |
| 1436 | |
| 1437 | return 0; |
| 1438 | } |
| 1439 | |
Marc Kleine-Budde | 08c6d35 | 2014-03-05 19:10:44 +0100 | [diff] [blame] | 1440 | static int __maybe_unused flexcan_resume(struct device *device) |
Eric Bénard | 8b5e218 | 2012-05-08 17:12:17 +0200 | [diff] [blame] | 1441 | { |
Fabio Estevam | 588e7a8 | 2013-05-20 15:43:43 -0300 | [diff] [blame] | 1442 | struct net_device *dev = dev_get_drvdata(device); |
Eric Bénard | 8b5e218 | 2012-05-08 17:12:17 +0200 | [diff] [blame] | 1443 | struct flexcan_priv *priv = netdev_priv(dev); |
Fabio Estevam | 4de349e | 2016-08-17 12:41:08 -0300 | [diff] [blame] | 1444 | int err; |
Eric Bénard | 8b5e218 | 2012-05-08 17:12:17 +0200 | [diff] [blame] | 1445 | |
| 1446 | priv->can.state = CAN_STATE_ERROR_ACTIVE; |
| 1447 | if (netif_running(dev)) { |
| 1448 | netif_device_attach(dev); |
| 1449 | netif_start_queue(dev); |
Fabio Estevam | 4de349e | 2016-08-17 12:41:08 -0300 | [diff] [blame] | 1450 | err = flexcan_chip_enable(priv); |
| 1451 | if (err) |
| 1452 | return err; |
Eric Bénard | 8b5e218 | 2012-05-08 17:12:17 +0200 | [diff] [blame] | 1453 | } |
Fabio Estevam | 4de349e | 2016-08-17 12:41:08 -0300 | [diff] [blame] | 1454 | return 0; |
Eric Bénard | 8b5e218 | 2012-05-08 17:12:17 +0200 | [diff] [blame] | 1455 | } |
Fabio Estevam | 588e7a8 | 2013-05-20 15:43:43 -0300 | [diff] [blame] | 1456 | |
| 1457 | static SIMPLE_DEV_PM_OPS(flexcan_pm_ops, flexcan_suspend, flexcan_resume); |
Eric Bénard | 8b5e218 | 2012-05-08 17:12:17 +0200 | [diff] [blame] | 1458 | |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1459 | static struct platform_driver flexcan_driver = { |
holt@sgi.com | c8aef4c | 2011-08-16 17:32:22 +0000 | [diff] [blame] | 1460 | .driver = { |
| 1461 | .name = DRV_NAME, |
Fabio Estevam | 588e7a8 | 2013-05-20 15:43:43 -0300 | [diff] [blame] | 1462 | .pm = &flexcan_pm_ops, |
holt@sgi.com | c8aef4c | 2011-08-16 17:32:22 +0000 | [diff] [blame] | 1463 | .of_match_table = flexcan_of_match, |
| 1464 | }, |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1465 | .probe = flexcan_probe, |
Bill Pemberton | 3c8ac0f | 2012-12-03 09:22:44 -0500 | [diff] [blame] | 1466 | .remove = flexcan_remove, |
Hui Wang | 30c1e67 | 2012-06-28 16:21:35 +0800 | [diff] [blame] | 1467 | .id_table = flexcan_id_table, |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1468 | }; |
| 1469 | |
Axel Lin | 871d337 | 2011-11-27 15:42:31 +0000 | [diff] [blame] | 1470 | module_platform_driver(flexcan_driver); |
Marc Kleine-Budde | e955cea | 2009-07-29 10:20:10 +0200 | [diff] [blame] | 1471 | |
| 1472 | MODULE_AUTHOR("Sascha Hauer <kernel@pengutronix.de>, " |
| 1473 | "Marc Kleine-Budde <kernel@pengutronix.de>"); |
| 1474 | MODULE_LICENSE("GPL v2"); |
| 1475 | MODULE_DESCRIPTION("CAN port driver for flexcan based chip"); |