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