aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2016-02-21 22:39:32 -0500
committerDavid S. Miller <davem@davemloft.net>2016-02-21 22:39:32 -0500
commit86310cc42ddf300a9482c613720e7811abec2c4c (patch)
tree5a1958645f28e47bff39bce50cf9f8da6c9eeae6
parent9c572dc4835aaca7a2f81db184dc25833980bb9c (diff)
parent0c4d9c94a1303008b32079991360cea7ab849ef3 (diff)
Merge tag 'linux-can-next-for-4.6-20160220' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next
Marc Kleine-Budde says: ==================== pull-request: can-next 2016-02-20 this is a pull request of 9 patch for net-next/master. The first 3 patches are from Damien Riegel, they add support for Technologic Systems IP core to tje sja100 driver. The next patches 6 by Marek Vasut (including one my me) first clean sort the CAN driver's Kconfig and Makefiles and then add support for the IFI CANFD IP core. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--Documentation/devicetree/bindings/net/can/ifi_canfd.txt15
-rw-r--r--Documentation/devicetree/bindings/net/can/sja1000.txt3
-rw-r--r--Documentation/devicetree/bindings/vendor-prefixes.txt1
-rw-r--r--drivers/net/can/Kconfig64
-rw-r--r--drivers/net/can/Makefile17
-rw-r--r--drivers/net/can/ifi_canfd/Kconfig8
-rw-r--r--drivers/net/can/ifi_canfd/Makefile5
-rw-r--r--drivers/net/can/ifi_canfd/ifi_canfd.c917
-rw-r--r--drivers/net/can/sja1000/sja1000_platform.c87
9 files changed, 1064 insertions, 53 deletions
diff --git a/Documentation/devicetree/bindings/net/can/ifi_canfd.txt b/Documentation/devicetree/bindings/net/can/ifi_canfd.txt
new file mode 100644
index 000000000000..20ea5c70ab82
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/can/ifi_canfd.txt
@@ -0,0 +1,15 @@
1IFI CANFD controller
2--------------------
3
4Required properties:
5 - compatible: Should be "ifi,canfd-1.0"
6 - reg: Should contain CAN controller registers location and length
7 - interrupts: Should contain IRQ line for the CAN controller
8
9Example:
10
11 canfd0: canfd@ff220000 {
12 compatible = "ifi,canfd-1.0";
13 reg = <0xff220000 0x00001000>;
14 interrupts = <0 43 0>;
15 };
diff --git a/Documentation/devicetree/bindings/net/can/sja1000.txt b/Documentation/devicetree/bindings/net/can/sja1000.txt
index b4a6d53fb01a..ac3160eca96a 100644
--- a/Documentation/devicetree/bindings/net/can/sja1000.txt
+++ b/Documentation/devicetree/bindings/net/can/sja1000.txt
@@ -2,7 +2,7 @@ Memory mapped SJA1000 CAN controller from NXP (formerly Philips)
2 2
3Required properties: 3Required properties:
4 4
5- compatible : should be "nxp,sja1000". 5- compatible : should be one of "nxp,sja1000", "technologic,sja1000".
6 6
7- reg : should specify the chip select, address offset and size required 7- reg : should specify the chip select, address offset and size required
8 to map the registers of the SJA1000. The size is usually 0x80. 8 to map the registers of the SJA1000. The size is usually 0x80.
@@ -14,6 +14,7 @@ Optional properties:
14 14
15- reg-io-width : Specify the size (in bytes) of the IO accesses that 15- reg-io-width : Specify the size (in bytes) of the IO accesses that
16 should be performed on the device. Valid value is 1, 2 or 4. 16 should be performed on the device. Valid value is 1, 2 or 4.
17 This property is ignored for technologic version.
17 Default to 1 (8 bits). 18 Default to 1 (8 bits).
18 19
19- nxp,external-clock-frequency : Frequency of the external oscillator 20- nxp,external-clock-frequency : Frequency of the external oscillator
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.txt b/Documentation/devicetree/bindings/vendor-prefixes.txt
index 72e2c5a2b327..c6134dcd2e04 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.txt
+++ b/Documentation/devicetree/bindings/vendor-prefixes.txt
@@ -111,6 +111,7 @@ hp Hewlett Packard
111i2se I2SE GmbH 111i2se I2SE GmbH
112ibm International Business Machines (IBM) 112ibm International Business Machines (IBM)
113idt Integrated Device Technologies, Inc. 113idt Integrated Device Technologies, Inc.
114ifi Ingenieurburo Fur Ic-Technologie (I/F/I)
114iom Iomega Corporation 115iom Iomega Corporation
115img Imagination Technologies Ltd. 116img Imagination Technologies Ltd.
116ingenic Ingenic Semiconductor 117ingenic Ingenic Semiconductor
diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
index 6d04183ed955..164ccdeca663 100644
--- a/drivers/net/can/Kconfig
+++ b/drivers/net/can/Kconfig
@@ -70,13 +70,6 @@ config CAN_AT91
70 This is a driver for the SoC CAN controller in Atmel's AT91SAM9263 70 This is a driver for the SoC CAN controller in Atmel's AT91SAM9263
71 and AT91SAM9X5 processors. 71 and AT91SAM9X5 processors.
72 72
73config CAN_TI_HECC
74 depends on ARM
75 tristate "TI High End CAN Controller"
76 ---help---
77 Driver for TI HECC (High End CAN Controller) module found on many
78 TI devices. The device specifications are available from www.ti.com
79
80config CAN_BFIN 73config CAN_BFIN
81 depends on BF534 || BF536 || BF537 || BF538 || BF539 || BF54x 74 depends on BF534 || BF536 || BF537 || BF538 || BF539 || BF54x
82 tristate "Analog Devices Blackfin on-chip CAN" 75 tristate "Analog Devices Blackfin on-chip CAN"
@@ -86,30 +79,12 @@ config CAN_BFIN
86 To compile this driver as a module, choose M here: the 79 To compile this driver as a module, choose M here: the
87 module will be called bfin_can. 80 module will be called bfin_can.
88 81
89config CAN_JANZ_ICAN3
90 tristate "Janz VMOD-ICAN3 Intelligent CAN controller"
91 depends on MFD_JANZ_CMODIO
92 ---help---
93 Driver for Janz VMOD-ICAN3 Intelligent CAN controller module, which
94 connects to a MODULbus carrier board.
95
96 This driver can also be built as a module. If so, the module will be
97 called janz-ican3.ko.
98
99config CAN_FLEXCAN 82config CAN_FLEXCAN
100 tristate "Support for Freescale FLEXCAN based chips" 83 tristate "Support for Freescale FLEXCAN based chips"
101 depends on ARM || PPC 84 depends on ARM || PPC
102 ---help--- 85 ---help---
103 Say Y here if you want to support for Freescale FlexCAN. 86 Say Y here if you want to support for Freescale FlexCAN.
104 87
105config PCH_CAN
106 tristate "Intel EG20T PCH CAN controller"
107 depends on PCI && (X86_32 || COMPILE_TEST)
108 ---help---
109 This driver is for PCH CAN of Topcliff (Intel EG20T PCH) which
110 is an IOH for x86 embedded processor (Intel Atom E6xx series).
111 This driver can access CAN bus.
112
113config CAN_GRCAN 88config CAN_GRCAN
114 tristate "Aeroflex Gaisler GRCAN and GRHCAN CAN devices" 89 tristate "Aeroflex Gaisler GRCAN and GRHCAN CAN devices"
115 depends on OF && HAS_DMA 90 depends on OF && HAS_DMA
@@ -119,6 +94,16 @@ config CAN_GRCAN
119 endian syntheses of the cores would need some modifications on 94 endian syntheses of the cores would need some modifications on
120 the hardware level to work. 95 the hardware level to work.
121 96
97config CAN_JANZ_ICAN3
98 tristate "Janz VMOD-ICAN3 Intelligent CAN controller"
99 depends on MFD_JANZ_CMODIO
100 ---help---
101 Driver for Janz VMOD-ICAN3 Intelligent CAN controller module, which
102 connects to a MODULbus carrier board.
103
104 This driver can also be built as a module. If so, the module will be
105 called janz-ican3.ko.
106
122config CAN_RCAR 107config CAN_RCAR
123 tristate "Renesas R-Car CAN controller" 108 tristate "Renesas R-Car CAN controller"
124 depends on ARM 109 depends on ARM
@@ -139,6 +124,13 @@ config CAN_SUN4I
139 To compile this driver as a module, choose M here: the module will 124 To compile this driver as a module, choose M here: the module will
140 be called sun4i_can. 125 be called sun4i_can.
141 126
127config CAN_TI_HECC
128 depends on ARM
129 tristate "TI High End CAN Controller"
130 ---help---
131 Driver for TI HECC (High End CAN Controller) module found on many
132 TI devices. The device specifications are available from www.ti.com
133
142config CAN_XILINXCAN 134config CAN_XILINXCAN
143 tristate "Xilinx CAN" 135 tristate "Xilinx CAN"
144 depends on ARCH_ZYNQ || ARM64 || MICROBLAZE || COMPILE_TEST 136 depends on ARCH_ZYNQ || ARM64 || MICROBLAZE || COMPILE_TEST
@@ -147,22 +139,24 @@ config CAN_XILINXCAN
147 Xilinx CAN driver. This driver supports both soft AXI CAN IP and 139 Xilinx CAN driver. This driver supports both soft AXI CAN IP and
148 Zynq CANPS IP. 140 Zynq CANPS IP.
149 141
150source "drivers/net/can/mscan/Kconfig" 142config PCH_CAN
151 143 tristate "Intel EG20T PCH CAN controller"
152source "drivers/net/can/sja1000/Kconfig" 144 depends on PCI && (X86_32 || COMPILE_TEST)
145 ---help---
146 This driver is for PCH CAN of Topcliff (Intel EG20T PCH) which
147 is an IOH for x86 embedded processor (Intel Atom E6xx series).
148 This driver can access CAN bus.
153 149
154source "drivers/net/can/c_can/Kconfig" 150source "drivers/net/can/c_can/Kconfig"
155
156source "drivers/net/can/m_can/Kconfig"
157
158source "drivers/net/can/cc770/Kconfig" 151source "drivers/net/can/cc770/Kconfig"
159 152source "drivers/net/can/ifi_canfd/Kconfig"
153source "drivers/net/can/m_can/Kconfig"
154source "drivers/net/can/mscan/Kconfig"
155source "drivers/net/can/sja1000/Kconfig"
156source "drivers/net/can/softing/Kconfig"
160source "drivers/net/can/spi/Kconfig" 157source "drivers/net/can/spi/Kconfig"
161
162source "drivers/net/can/usb/Kconfig" 158source "drivers/net/can/usb/Kconfig"
163 159
164source "drivers/net/can/softing/Kconfig"
165
166endif 160endif
167 161
168config CAN_DEBUG_DEVICES 162config CAN_DEBUG_DEVICES
diff --git a/drivers/net/can/Makefile b/drivers/net/can/Makefile
index 1f21cef1d458..e3db0c807f55 100644
--- a/drivers/net/can/Makefile
+++ b/drivers/net/can/Makefile
@@ -14,21 +14,22 @@ obj-y += spi/
14obj-y += usb/ 14obj-y += usb/
15obj-y += softing/ 15obj-y += softing/
16 16
17obj-$(CONFIG_CAN_SJA1000) += sja1000/
18obj-$(CONFIG_CAN_MSCAN) += mscan/
19obj-$(CONFIG_CAN_C_CAN) += c_can/
20obj-$(CONFIG_CAN_M_CAN) += m_can/
21obj-$(CONFIG_CAN_CC770) += cc770/
22obj-$(CONFIG_CAN_AT91) += at91_can.o 17obj-$(CONFIG_CAN_AT91) += at91_can.o
23obj-$(CONFIG_CAN_TI_HECC) += ti_hecc.o
24obj-$(CONFIG_CAN_BFIN) += bfin_can.o 18obj-$(CONFIG_CAN_BFIN) += bfin_can.o
25obj-$(CONFIG_CAN_JANZ_ICAN3) += janz-ican3.o 19obj-$(CONFIG_CAN_CC770) += cc770/
20obj-$(CONFIG_CAN_C_CAN) += c_can/
26obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o 21obj-$(CONFIG_CAN_FLEXCAN) += flexcan.o
27obj-$(CONFIG_PCH_CAN) += pch_can.o
28obj-$(CONFIG_CAN_GRCAN) += grcan.o 22obj-$(CONFIG_CAN_GRCAN) += grcan.o
23obj-$(CONFIG_CAN_IFI_CANFD) += ifi_canfd/
24obj-$(CONFIG_CAN_JANZ_ICAN3) += janz-ican3.o
25obj-$(CONFIG_CAN_MSCAN) += mscan/
26obj-$(CONFIG_CAN_M_CAN) += m_can/
29obj-$(CONFIG_CAN_RCAR) += rcar_can.o 27obj-$(CONFIG_CAN_RCAR) += rcar_can.o
28obj-$(CONFIG_CAN_SJA1000) += sja1000/
30obj-$(CONFIG_CAN_SUN4I) += sun4i_can.o 29obj-$(CONFIG_CAN_SUN4I) += sun4i_can.o
30obj-$(CONFIG_CAN_TI_HECC) += ti_hecc.o
31obj-$(CONFIG_CAN_XILINXCAN) += xilinx_can.o 31obj-$(CONFIG_CAN_XILINXCAN) += xilinx_can.o
32obj-$(CONFIG_PCH_CAN) += pch_can.o
32 33
33subdir-ccflags-y += -D__CHECK_ENDIAN__ 34subdir-ccflags-y += -D__CHECK_ENDIAN__
34subdir-ccflags-$(CONFIG_CAN_DEBUG_DEVICES) += -DDEBUG 35subdir-ccflags-$(CONFIG_CAN_DEBUG_DEVICES) += -DDEBUG
diff --git a/drivers/net/can/ifi_canfd/Kconfig b/drivers/net/can/ifi_canfd/Kconfig
new file mode 100644
index 000000000000..9e8934ff63a7
--- /dev/null
+++ b/drivers/net/can/ifi_canfd/Kconfig
@@ -0,0 +1,8 @@
1config CAN_IFI_CANFD
2 depends on HAS_IOMEM
3 tristate "IFI CAN_FD IP"
4 ---help---
5 This driver adds support for the I/F/I CAN_FD soft IP block
6 connected to the "platform bus" (Linux abstraction for directly
7 to the processor attached devices). The CAN_FD is most often
8 synthesised into an FPGA or CPLD.
diff --git a/drivers/net/can/ifi_canfd/Makefile b/drivers/net/can/ifi_canfd/Makefile
new file mode 100644
index 000000000000..b229960cdf39
--- /dev/null
+++ b/drivers/net/can/ifi_canfd/Makefile
@@ -0,0 +1,5 @@
1#
2# Makefile for the IFI CANFD controller driver.
3#
4
5obj-$(CONFIG_CAN_IFI_CANFD) += ifi_canfd.o
diff --git a/drivers/net/can/ifi_canfd/ifi_canfd.c b/drivers/net/can/ifi_canfd/ifi_canfd.c
new file mode 100644
index 000000000000..0d1c164374b7
--- /dev/null
+++ b/drivers/net/can/ifi_canfd/ifi_canfd.c
@@ -0,0 +1,917 @@
1/*
2 * CAN bus driver for IFI CANFD controller
3 *
4 * Copyright (C) 2016 Marek Vasut <marex@denx.de>
5 *
6 * Details about this controller can be found at
7 * http://www.ifi-pld.de/IP/CANFD/canfd.html
8 *
9 * This file is licensed under the terms of the GNU General Public
10 * License version 2. This program is licensed "as is" without any
11 * warranty of any kind, whether express or implied.
12 */
13
14#include <linux/clk.h>
15#include <linux/delay.h>
16#include <linux/interrupt.h>
17#include <linux/io.h>
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/netdevice.h>
21#include <linux/of.h>
22#include <linux/of_device.h>
23#include <linux/platform_device.h>
24
25#include <linux/can/dev.h>
26
27#define IFI_CANFD_STCMD 0x0
28#define IFI_CANFD_STCMD_HARDRESET 0xDEADCAFD
29#define IFI_CANFD_STCMD_ENABLE BIT(0)
30#define IFI_CANFD_STCMD_ERROR_ACTIVE BIT(2)
31#define IFI_CANFD_STCMD_ERROR_PASSIVE BIT(3)
32#define IFI_CANFD_STCMD_BUSOFF BIT(4)
33#define IFI_CANFD_STCMD_BUSMONITOR BIT(16)
34#define IFI_CANFD_STCMD_LOOPBACK BIT(18)
35#define IFI_CANFD_STCMD_DISABLE_CANFD BIT(24)
36#define IFI_CANFD_STCMD_ENABLE_ISO BIT(25)
37#define IFI_CANFD_STCMD_NORMAL_MODE ((u32)BIT(31))
38
39#define IFI_CANFD_RXSTCMD 0x4
40#define IFI_CANFD_RXSTCMD_REMOVE_MSG BIT(0)
41#define IFI_CANFD_RXSTCMD_RESET BIT(7)
42#define IFI_CANFD_RXSTCMD_EMPTY BIT(8)
43#define IFI_CANFD_RXSTCMD_OVERFLOW BIT(13)
44
45#define IFI_CANFD_TXSTCMD 0x8
46#define IFI_CANFD_TXSTCMD_ADD_MSG BIT(0)
47#define IFI_CANFD_TXSTCMD_HIGH_PRIO BIT(1)
48#define IFI_CANFD_TXSTCMD_RESET BIT(7)
49#define IFI_CANFD_TXSTCMD_EMPTY BIT(8)
50#define IFI_CANFD_TXSTCMD_FULL BIT(12)
51#define IFI_CANFD_TXSTCMD_OVERFLOW BIT(13)
52
53#define IFI_CANFD_INTERRUPT 0xc
54#define IFI_CANFD_INTERRUPT_ERROR_WARNING ((u32)BIT(1))
55#define IFI_CANFD_INTERRUPT_TXFIFO_EMPTY BIT(16)
56#define IFI_CANFD_INTERRUPT_TXFIFO_REMOVE BIT(22)
57#define IFI_CANFD_INTERRUPT_RXFIFO_NEMPTY BIT(24)
58#define IFI_CANFD_INTERRUPT_RXFIFO_NEMPTY_PER BIT(25)
59#define IFI_CANFD_INTERRUPT_SET_IRQ ((u32)BIT(31))
60
61#define IFI_CANFD_IRQMASK 0x10
62#define IFI_CANFD_IRQMASK_SET_ERR BIT(7)
63#define IFI_CANFD_IRQMASK_SET_TS BIT(15)
64#define IFI_CANFD_IRQMASK_TXFIFO_EMPTY BIT(16)
65#define IFI_CANFD_IRQMASK_SET_TX BIT(23)
66#define IFI_CANFD_IRQMASK_RXFIFO_NEMPTY BIT(24)
67#define IFI_CANFD_IRQMASK_SET_RX ((u32)BIT(31))
68
69#define IFI_CANFD_TIME 0x14
70#define IFI_CANFD_FTIME 0x18
71#define IFI_CANFD_TIME_TIMEB_OFF 0
72#define IFI_CANFD_TIME_TIMEA_OFF 8
73#define IFI_CANFD_TIME_PRESCALE_OFF 16
74#define IFI_CANFD_TIME_SJW_OFF_ISO 25
75#define IFI_CANFD_TIME_SJW_OFF_BOSCH 28
76#define IFI_CANFD_TIME_SET_SJW_BOSCH BIT(6)
77#define IFI_CANFD_TIME_SET_TIMEB_BOSCH BIT(7)
78#define IFI_CANFD_TIME_SET_PRESC_BOSCH BIT(14)
79#define IFI_CANFD_TIME_SET_TIMEA_BOSCH BIT(15)
80
81#define IFI_CANFD_TDELAY 0x1c
82
83#define IFI_CANFD_ERROR 0x20
84#define IFI_CANFD_ERROR_TX_OFFSET 0
85#define IFI_CANFD_ERROR_TX_MASK 0xff
86#define IFI_CANFD_ERROR_RX_OFFSET 16
87#define IFI_CANFD_ERROR_RX_MASK 0xff
88
89#define IFI_CANFD_ERRCNT 0x24
90
91#define IFI_CANFD_SUSPEND 0x28
92
93#define IFI_CANFD_REPEAT 0x2c
94
95#define IFI_CANFD_TRAFFIC 0x30
96
97#define IFI_CANFD_TSCONTROL 0x34
98
99#define IFI_CANFD_TSC 0x38
100
101#define IFI_CANFD_TST 0x3c
102
103#define IFI_CANFD_RES1 0x40
104
105#define IFI_CANFD_RES2 0x44
106
107#define IFI_CANFD_PAR 0x48
108
109#define IFI_CANFD_CANCLOCK 0x4c
110
111#define IFI_CANFD_SYSCLOCK 0x50
112
113#define IFI_CANFD_VER 0x54
114
115#define IFI_CANFD_IP_ID 0x58
116#define IFI_CANFD_IP_ID_VALUE 0xD073CAFD
117
118#define IFI_CANFD_TEST 0x5c
119
120#define IFI_CANFD_RXFIFO_TS_63_32 0x60
121
122#define IFI_CANFD_RXFIFO_TS_31_0 0x64
123
124#define IFI_CANFD_RXFIFO_DLC 0x68
125#define IFI_CANFD_RXFIFO_DLC_DLC_OFFSET 0
126#define IFI_CANFD_RXFIFO_DLC_DLC_MASK 0xf
127#define IFI_CANFD_RXFIFO_DLC_RTR BIT(4)
128#define IFI_CANFD_RXFIFO_DLC_EDL BIT(5)
129#define IFI_CANFD_RXFIFO_DLC_BRS BIT(6)
130#define IFI_CANFD_RXFIFO_DLC_ESI BIT(7)
131#define IFI_CANFD_RXFIFO_DLC_OBJ_OFFSET 8
132#define IFI_CANFD_RXFIFO_DLC_OBJ_MASK 0x1ff
133#define IFI_CANFD_RXFIFO_DLC_FNR_OFFSET 24
134#define IFI_CANFD_RXFIFO_DLC_FNR_MASK 0xff
135
136#define IFI_CANFD_RXFIFO_ID 0x6c
137#define IFI_CANFD_RXFIFO_ID_ID_OFFSET 0
138#define IFI_CANFD_RXFIFO_ID_ID_STD_MASK 0x3ff
139#define IFI_CANFD_RXFIFO_ID_ID_XTD_MASK 0x1fffffff
140#define IFI_CANFD_RXFIFO_ID_IDE BIT(29)
141
142#define IFI_CANFD_RXFIFO_DATA 0x70 /* 0x70..0xac */
143
144#define IFI_CANFD_TXFIFO_SUSPEND_US 0xb0
145
146#define IFI_CANFD_TXFIFO_REPEATCOUNT 0xb4
147
148#define IFI_CANFD_TXFIFO_DLC 0xb8
149#define IFI_CANFD_TXFIFO_DLC_DLC_OFFSET 0
150#define IFI_CANFD_TXFIFO_DLC_DLC_MASK 0xf
151#define IFI_CANFD_TXFIFO_DLC_RTR BIT(4)
152#define IFI_CANFD_TXFIFO_DLC_EDL BIT(5)
153#define IFI_CANFD_TXFIFO_DLC_BRS BIT(6)
154#define IFI_CANFD_TXFIFO_DLC_FNR_OFFSET 24
155#define IFI_CANFD_TXFIFO_DLC_FNR_MASK 0xff
156
157#define IFI_CANFD_TXFIFO_ID 0xbc
158#define IFI_CANFD_TXFIFO_ID_ID_OFFSET 0
159#define IFI_CANFD_TXFIFO_ID_ID_STD_MASK 0x3ff
160#define IFI_CANFD_TXFIFO_ID_ID_XTD_MASK 0x1fffffff
161#define IFI_CANFD_TXFIFO_ID_IDE BIT(29)
162
163#define IFI_CANFD_TXFIFO_DATA 0xc0 /* 0xb0..0xfc */
164
165#define IFI_CANFD_FILTER_MASK(n) (0x800 + ((n) * 8) + 0)
166#define IFI_CANFD_FILTER_MASK_EXT BIT(29)
167#define IFI_CANFD_FILTER_MASK_EDL BIT(30)
168#define IFI_CANFD_FILTER_MASK_VALID ((u32)BIT(31))
169
170#define IFI_CANFD_FILTER_IDENT(n) (0x800 + ((n) * 8) + 4)
171#define IFI_CANFD_FILTER_IDENT_IDE BIT(29)
172#define IFI_CANFD_FILTER_IDENT_CANFD BIT(30)
173#define IFI_CANFD_FILTER_IDENT_VALID ((u32)BIT(31))
174
175/* IFI CANFD private data structure */
176struct ifi_canfd_priv {
177 struct can_priv can; /* must be the first member */
178 struct napi_struct napi;
179 struct net_device *ndev;
180 void __iomem *base;
181};
182
183static void ifi_canfd_irq_enable(struct net_device *ndev, bool enable)
184{
185 struct ifi_canfd_priv *priv = netdev_priv(ndev);
186 u32 enirq = 0;
187
188 if (enable) {
189 enirq = IFI_CANFD_IRQMASK_TXFIFO_EMPTY |
190 IFI_CANFD_IRQMASK_RXFIFO_NEMPTY;
191 }
192
193 writel(IFI_CANFD_IRQMASK_SET_ERR |
194 IFI_CANFD_IRQMASK_SET_TS |
195 IFI_CANFD_IRQMASK_SET_TX |
196 IFI_CANFD_IRQMASK_SET_RX | enirq,
197 priv->base + IFI_CANFD_IRQMASK);
198}
199
200static void ifi_canfd_read_fifo(struct net_device *ndev)
201{
202 struct net_device_stats *stats = &ndev->stats;
203 struct ifi_canfd_priv *priv = netdev_priv(ndev);
204 struct canfd_frame *cf;
205 struct sk_buff *skb;
206 const u32 rx_irq_mask = IFI_CANFD_INTERRUPT_RXFIFO_NEMPTY |
207 IFI_CANFD_INTERRUPT_RXFIFO_NEMPTY_PER;
208 u32 rxdlc, rxid;
209 u32 dlc, id;
210 int i;
211
212 rxdlc = readl(priv->base + IFI_CANFD_RXFIFO_DLC);
213 if (rxdlc & IFI_CANFD_RXFIFO_DLC_EDL)
214 skb = alloc_canfd_skb(ndev, &cf);
215 else
216 skb = alloc_can_skb(ndev, (struct can_frame **)&cf);
217
218 if (!skb) {
219 stats->rx_dropped++;
220 return;
221 }
222
223 dlc = (rxdlc >> IFI_CANFD_RXFIFO_DLC_DLC_OFFSET) &
224 IFI_CANFD_RXFIFO_DLC_DLC_MASK;
225 if (rxdlc & IFI_CANFD_RXFIFO_DLC_EDL)
226 cf->len = can_dlc2len(dlc);
227 else
228 cf->len = get_can_dlc(dlc);
229
230 rxid = readl(priv->base + IFI_CANFD_RXFIFO_ID);
231 id = (rxid >> IFI_CANFD_RXFIFO_ID_ID_OFFSET);
232 if (id & IFI_CANFD_RXFIFO_ID_IDE)
233 id &= IFI_CANFD_RXFIFO_ID_ID_XTD_MASK;
234 else
235 id &= IFI_CANFD_RXFIFO_ID_ID_STD_MASK;
236 cf->can_id = id;
237
238 if (rxdlc & IFI_CANFD_RXFIFO_DLC_ESI) {
239 cf->flags |= CANFD_ESI;
240 netdev_dbg(ndev, "ESI Error\n");
241 }
242
243 if (!(rxdlc & IFI_CANFD_RXFIFO_DLC_EDL) &&
244 (rxdlc & IFI_CANFD_RXFIFO_DLC_RTR)) {
245 cf->can_id |= CAN_RTR_FLAG;
246 } else {
247 if (rxdlc & IFI_CANFD_RXFIFO_DLC_BRS)
248 cf->flags |= CANFD_BRS;
249
250 for (i = 0; i < cf->len; i += 4) {
251 *(u32 *)(cf->data + i) =
252 readl(priv->base + IFI_CANFD_RXFIFO_DATA + i);
253 }
254 }
255
256 /* Remove the packet from FIFO */
257 writel(IFI_CANFD_RXSTCMD_REMOVE_MSG, priv->base + IFI_CANFD_RXSTCMD);
258 writel(rx_irq_mask, priv->base + IFI_CANFD_INTERRUPT);
259
260 stats->rx_packets++;
261 stats->rx_bytes += cf->len;
262
263 netif_receive_skb(skb);
264}
265
266static int ifi_canfd_do_rx_poll(struct net_device *ndev, int quota)
267{
268 struct ifi_canfd_priv *priv = netdev_priv(ndev);
269 u32 pkts = 0;
270 u32 rxst;
271
272 rxst = readl(priv->base + IFI_CANFD_RXSTCMD);
273 if (rxst & IFI_CANFD_RXSTCMD_EMPTY) {
274 netdev_dbg(ndev, "No messages in RX FIFO\n");
275 return 0;
276 }
277
278 for (;;) {
279 if (rxst & IFI_CANFD_RXSTCMD_EMPTY)
280 break;
281 if (quota <= 0)
282 break;
283
284 ifi_canfd_read_fifo(ndev);
285 quota--;
286 pkts++;
287 rxst = readl(priv->base + IFI_CANFD_RXSTCMD);
288 }
289
290 if (pkts)
291 can_led_event(ndev, CAN_LED_EVENT_RX);
292
293 return pkts;
294}
295
296static int ifi_canfd_handle_lost_msg(struct net_device *ndev)
297{
298 struct net_device_stats *stats = &ndev->stats;
299 struct sk_buff *skb;
300 struct can_frame *frame;
301
302 netdev_err(ndev, "RX FIFO overflow, message(s) lost.\n");
303
304 stats->rx_errors++;
305 stats->rx_over_errors++;
306
307 skb = alloc_can_err_skb(ndev, &frame);
308 if (unlikely(!skb))
309 return 0;
310
311 frame->can_id |= CAN_ERR_CRTL;
312 frame->data[1] = CAN_ERR_CRTL_RX_OVERFLOW;
313
314 netif_receive_skb(skb);
315
316 return 1;
317}
318
319static int ifi_canfd_get_berr_counter(const struct net_device *ndev,
320 struct can_berr_counter *bec)
321{
322 struct ifi_canfd_priv *priv = netdev_priv(ndev);
323 u32 err;
324
325 err = readl(priv->base + IFI_CANFD_ERROR);
326 bec->rxerr = (err >> IFI_CANFD_ERROR_RX_OFFSET) &
327 IFI_CANFD_ERROR_RX_MASK;
328 bec->txerr = (err >> IFI_CANFD_ERROR_TX_OFFSET) &
329 IFI_CANFD_ERROR_TX_MASK;
330
331 return 0;
332}
333
334static int ifi_canfd_handle_state_change(struct net_device *ndev,
335 enum can_state new_state)
336{
337 struct ifi_canfd_priv *priv = netdev_priv(ndev);
338 struct net_device_stats *stats = &ndev->stats;
339 struct can_frame *cf;
340 struct sk_buff *skb;
341 struct can_berr_counter bec;
342
343 switch (new_state) {
344 case CAN_STATE_ERROR_ACTIVE:
345 /* error warning state */
346 priv->can.can_stats.error_warning++;
347 priv->can.state = CAN_STATE_ERROR_WARNING;
348 break;
349 case CAN_STATE_ERROR_PASSIVE:
350 /* error passive state */
351 priv->can.can_stats.error_passive++;
352 priv->can.state = CAN_STATE_ERROR_PASSIVE;
353 break;
354 case CAN_STATE_BUS_OFF:
355 /* bus-off state */
356 priv->can.state = CAN_STATE_BUS_OFF;
357 ifi_canfd_irq_enable(ndev, 0);
358 priv->can.can_stats.bus_off++;
359 can_bus_off(ndev);
360 break;
361 default:
362 break;
363 }
364
365 /* propagate the error condition to the CAN stack */
366 skb = alloc_can_err_skb(ndev, &cf);
367 if (unlikely(!skb))
368 return 0;
369
370 ifi_canfd_get_berr_counter(ndev, &bec);
371
372 switch (new_state) {
373 case CAN_STATE_ERROR_ACTIVE:
374 /* error warning state */
375 cf->can_id |= CAN_ERR_CRTL;
376 cf->data[1] = (bec.txerr > bec.rxerr) ?
377 CAN_ERR_CRTL_TX_WARNING :
378 CAN_ERR_CRTL_RX_WARNING;
379 cf->data[6] = bec.txerr;
380 cf->data[7] = bec.rxerr;
381 break;
382 case CAN_STATE_ERROR_PASSIVE:
383 /* error passive state */
384 cf->can_id |= CAN_ERR_CRTL;
385 cf->data[1] |= CAN_ERR_CRTL_RX_PASSIVE;
386 if (bec.txerr > 127)
387 cf->data[1] |= CAN_ERR_CRTL_TX_PASSIVE;
388 cf->data[6] = bec.txerr;
389 cf->data[7] = bec.rxerr;
390 break;
391 case CAN_STATE_BUS_OFF:
392 /* bus-off state */
393 cf->can_id |= CAN_ERR_BUSOFF;
394 break;
395 default:
396 break;
397 }
398
399 stats->rx_packets++;
400 stats->rx_bytes += cf->can_dlc;
401 netif_receive_skb(skb);
402
403 return 1;
404}
405
406static int ifi_canfd_handle_state_errors(struct net_device *ndev, u32 stcmd)
407{
408 struct ifi_canfd_priv *priv = netdev_priv(ndev);
409 int work_done = 0;
410 u32 isr;
411
412 /*
413 * The ErrWarn condition is a little special, since the bit is
414 * located in the INTERRUPT register instead of STCMD register.
415 */
416 isr = readl(priv->base + IFI_CANFD_INTERRUPT);
417 if ((isr & IFI_CANFD_INTERRUPT_ERROR_WARNING) &&
418 (priv->can.state != CAN_STATE_ERROR_WARNING)) {
419 /* Clear the interrupt */
420 writel(IFI_CANFD_INTERRUPT_ERROR_WARNING,
421 priv->base + IFI_CANFD_INTERRUPT);
422 netdev_dbg(ndev, "Error, entered warning state\n");
423 work_done += ifi_canfd_handle_state_change(ndev,
424 CAN_STATE_ERROR_WARNING);
425 }
426
427 if ((stcmd & IFI_CANFD_STCMD_ERROR_PASSIVE) &&
428 (priv->can.state != CAN_STATE_ERROR_PASSIVE)) {
429 netdev_dbg(ndev, "Error, entered passive state\n");
430 work_done += ifi_canfd_handle_state_change(ndev,
431 CAN_STATE_ERROR_PASSIVE);
432 }
433
434 if ((stcmd & IFI_CANFD_STCMD_BUSOFF) &&
435 (priv->can.state != CAN_STATE_BUS_OFF)) {
436 netdev_dbg(ndev, "Error, entered bus-off state\n");
437 work_done += ifi_canfd_handle_state_change(ndev,
438 CAN_STATE_BUS_OFF);
439 }
440
441 return work_done;
442}
443
444static int ifi_canfd_poll(struct napi_struct *napi, int quota)
445{
446 struct net_device *ndev = napi->dev;
447 struct ifi_canfd_priv *priv = netdev_priv(ndev);
448 const u32 stcmd_state_mask = IFI_CANFD_STCMD_ERROR_PASSIVE |
449 IFI_CANFD_STCMD_BUSOFF;
450 int work_done = 0;
451
452 u32 stcmd = readl(priv->base + IFI_CANFD_STCMD);
453 u32 rxstcmd = readl(priv->base + IFI_CANFD_STCMD);
454
455 /* Handle bus state changes */
456 if ((stcmd & stcmd_state_mask) ||
457 ((stcmd & IFI_CANFD_STCMD_ERROR_ACTIVE) == 0))
458 work_done += ifi_canfd_handle_state_errors(ndev, stcmd);
459
460 /* Handle lost messages on RX */
461 if (rxstcmd & IFI_CANFD_RXSTCMD_OVERFLOW)
462 work_done += ifi_canfd_handle_lost_msg(ndev);
463
464 /* Handle normal messages on RX */
465 if (!(rxstcmd & IFI_CANFD_RXSTCMD_EMPTY))
466 work_done += ifi_canfd_do_rx_poll(ndev, quota - work_done);
467
468 if (work_done < quota) {
469 napi_complete(napi);
470 ifi_canfd_irq_enable(ndev, 1);
471 }
472
473 return work_done;
474}
475
476static irqreturn_t ifi_canfd_isr(int irq, void *dev_id)
477{
478 struct net_device *ndev = (struct net_device *)dev_id;
479 struct ifi_canfd_priv *priv = netdev_priv(ndev);
480 struct net_device_stats *stats = &ndev->stats;
481 const u32 rx_irq_mask = IFI_CANFD_INTERRUPT_RXFIFO_NEMPTY |
482 IFI_CANFD_INTERRUPT_RXFIFO_NEMPTY_PER;
483 const u32 tx_irq_mask = IFI_CANFD_INTERRUPT_TXFIFO_EMPTY |
484 IFI_CANFD_INTERRUPT_TXFIFO_REMOVE;
485 const u32 clr_irq_mask = ~(IFI_CANFD_INTERRUPT_SET_IRQ |
486 IFI_CANFD_INTERRUPT_ERROR_WARNING);
487 u32 isr;
488
489 isr = readl(priv->base + IFI_CANFD_INTERRUPT);
490
491 /* No interrupt */
492 if (isr == 0)
493 return IRQ_NONE;
494
495 /* Clear all pending interrupts but ErrWarn */
496 writel(clr_irq_mask, priv->base + IFI_CANFD_INTERRUPT);
497
498 /* RX IRQ, start NAPI */
499 if (isr & rx_irq_mask) {
500 ifi_canfd_irq_enable(ndev, 0);
501 napi_schedule(&priv->napi);
502 }
503
504 /* TX IRQ */
505 if (isr & tx_irq_mask) {
506 stats->tx_bytes += can_get_echo_skb(ndev, 0);
507 stats->tx_packets++;
508 can_led_event(ndev, CAN_LED_EVENT_TX);
509 netif_wake_queue(ndev);
510 }
511
512 return IRQ_HANDLED;
513}
514
515static const struct can_bittiming_const ifi_canfd_bittiming_const = {
516 .name = KBUILD_MODNAME,
517 .tseg1_min = 2, /* Time segment 1 = prop_seg + phase_seg1 */
518 .tseg1_max = 64,
519 .tseg2_min = 1, /* Time segment 2 = phase_seg2 */
520 .tseg2_max = 16,
521 .sjw_max = 16,
522 .brp_min = 1,
523 .brp_max = 1024,
524 .brp_inc = 1,
525};
526
527static const struct can_bittiming_const ifi_canfd_data_bittiming_const = {
528 .name = KBUILD_MODNAME,
529 .tseg1_min = 2, /* Time segment 1 = prop_seg + phase_seg1 */
530 .tseg1_max = 16,
531 .tseg2_min = 1, /* Time segment 2 = phase_seg2 */
532 .tseg2_max = 8,
533 .sjw_max = 4,
534 .brp_min = 1,
535 .brp_max = 32,
536 .brp_inc = 1,
537};
538
539static void ifi_canfd_set_bittiming(struct net_device *ndev)
540{
541 struct ifi_canfd_priv *priv = netdev_priv(ndev);
542 const struct can_bittiming *bt = &priv->can.bittiming;
543 const struct can_bittiming *dbt = &priv->can.data_bittiming;
544 u16 brp, sjw, tseg1, tseg2;
545 u32 noniso_arg = 0;
546 u32 time_off;
547
548 if (priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO) {
549 noniso_arg = IFI_CANFD_TIME_SET_TIMEB_BOSCH |
550 IFI_CANFD_TIME_SET_TIMEA_BOSCH |
551 IFI_CANFD_TIME_SET_PRESC_BOSCH |
552 IFI_CANFD_TIME_SET_SJW_BOSCH;
553 time_off = IFI_CANFD_TIME_SJW_OFF_BOSCH;
554 } else {
555 time_off = IFI_CANFD_TIME_SJW_OFF_ISO;
556 }
557
558 /* Configure bit timing */
559 brp = bt->brp - 1;
560 sjw = bt->sjw - 1;
561 tseg1 = bt->prop_seg + bt->phase_seg1 - 1;
562 tseg2 = bt->phase_seg2 - 1;
563 writel((tseg2 << IFI_CANFD_TIME_TIMEB_OFF) |
564 (tseg1 << IFI_CANFD_TIME_TIMEA_OFF) |
565 (brp << IFI_CANFD_TIME_PRESCALE_OFF) |
566 (sjw << time_off),
567 priv->base + IFI_CANFD_TIME);
568
569 /* Configure data bit timing */
570 brp = dbt->brp - 1;
571 sjw = dbt->sjw - 1;
572 tseg1 = dbt->prop_seg + dbt->phase_seg1 - 1;
573 tseg2 = dbt->phase_seg2 - 1;
574 writel((tseg2 << IFI_CANFD_TIME_TIMEB_OFF) |
575 (tseg1 << IFI_CANFD_TIME_TIMEA_OFF) |
576 (brp << IFI_CANFD_TIME_PRESCALE_OFF) |
577 (sjw << time_off) |
578 noniso_arg,
579 priv->base + IFI_CANFD_FTIME);
580}
581
582static void ifi_canfd_set_filter(struct net_device *ndev, const u32 id,
583 const u32 mask, const u32 ident)
584{
585 struct ifi_canfd_priv *priv = netdev_priv(ndev);
586
587 writel(mask, priv->base + IFI_CANFD_FILTER_MASK(id));
588 writel(ident, priv->base + IFI_CANFD_FILTER_IDENT(id));
589}
590
591static void ifi_canfd_set_filters(struct net_device *ndev)
592{
593 /* Receive all CAN frames (standard ID) */
594 ifi_canfd_set_filter(ndev, 0,
595 IFI_CANFD_FILTER_MASK_VALID |
596 IFI_CANFD_FILTER_MASK_EXT,
597 IFI_CANFD_FILTER_IDENT_VALID);
598
599 /* Receive all CAN frames (extended ID) */
600 ifi_canfd_set_filter(ndev, 1,
601 IFI_CANFD_FILTER_MASK_VALID |
602 IFI_CANFD_FILTER_MASK_EXT,
603 IFI_CANFD_FILTER_IDENT_VALID |
604 IFI_CANFD_FILTER_IDENT_IDE);
605
606 /* Receive all CANFD frames */
607 ifi_canfd_set_filter(ndev, 2,
608 IFI_CANFD_FILTER_MASK_VALID |
609 IFI_CANFD_FILTER_MASK_EDL |
610 IFI_CANFD_FILTER_MASK_EXT,
611 IFI_CANFD_FILTER_IDENT_VALID |
612 IFI_CANFD_FILTER_IDENT_CANFD |
613 IFI_CANFD_FILTER_IDENT_IDE);
614}
615
616static void ifi_canfd_start(struct net_device *ndev)
617{
618 struct ifi_canfd_priv *priv = netdev_priv(ndev);
619 u32 stcmd;
620
621 /* Reset the IP */
622 writel(IFI_CANFD_STCMD_HARDRESET, priv->base + IFI_CANFD_STCMD);
623 writel(0, priv->base + IFI_CANFD_STCMD);
624
625 ifi_canfd_set_bittiming(ndev);
626 ifi_canfd_set_filters(ndev);
627
628 /* Reset FIFOs */
629 writel(IFI_CANFD_RXSTCMD_RESET, priv->base + IFI_CANFD_RXSTCMD);
630 writel(0, priv->base + IFI_CANFD_RXSTCMD);
631 writel(IFI_CANFD_TXSTCMD_RESET, priv->base + IFI_CANFD_TXSTCMD);
632 writel(0, priv->base + IFI_CANFD_TXSTCMD);
633
634 /* Repeat transmission until successful */
635 writel(0, priv->base + IFI_CANFD_REPEAT);
636 writel(0, priv->base + IFI_CANFD_SUSPEND);
637
638 /* Clear all pending interrupts */
639 writel((u32)(~IFI_CANFD_INTERRUPT_SET_IRQ),
640 priv->base + IFI_CANFD_INTERRUPT);
641
642 stcmd = IFI_CANFD_STCMD_ENABLE | IFI_CANFD_STCMD_NORMAL_MODE;
643
644 if (priv->can.ctrlmode & CAN_CTRLMODE_LISTENONLY)
645 stcmd |= IFI_CANFD_STCMD_BUSMONITOR;
646
647 if (priv->can.ctrlmode & CAN_CTRLMODE_LOOPBACK)
648 stcmd |= IFI_CANFD_STCMD_LOOPBACK;
649
650 if (priv->can.ctrlmode & CAN_CTRLMODE_FD)
651 stcmd |= IFI_CANFD_STCMD_ENABLE_ISO;
652
653 if (!(priv->can.ctrlmode & (CAN_CTRLMODE_FD | CAN_CTRLMODE_FD_NON_ISO)))
654 stcmd |= IFI_CANFD_STCMD_DISABLE_CANFD;
655
656 priv->can.state = CAN_STATE_ERROR_ACTIVE;
657
658 ifi_canfd_irq_enable(ndev, 1);
659
660 /* Enable controller */
661 writel(stcmd, priv->base + IFI_CANFD_STCMD);
662}
663
664static void ifi_canfd_stop(struct net_device *ndev)
665{
666 struct ifi_canfd_priv *priv = netdev_priv(ndev);
667
668 /* Reset the IP */
669 writel(IFI_CANFD_STCMD_HARDRESET, priv->base + IFI_CANFD_STCMD);
670
671 /* Mask all interrupts */
672 writel(~0, priv->base + IFI_CANFD_IRQMASK);
673
674 /* Clear all pending interrupts */
675 writel((u32)(~IFI_CANFD_INTERRUPT_SET_IRQ),
676 priv->base + IFI_CANFD_INTERRUPT);
677
678 /* Set the state as STOPPED */
679 priv->can.state = CAN_STATE_STOPPED;
680}
681
682static int ifi_canfd_set_mode(struct net_device *ndev, enum can_mode mode)
683{
684 switch (mode) {
685 case CAN_MODE_START:
686 ifi_canfd_start(ndev);
687 netif_wake_queue(ndev);
688 break;
689 default:
690 return -EOPNOTSUPP;
691 }
692
693 return 0;
694}
695
696static int ifi_canfd_open(struct net_device *ndev)
697{
698 struct ifi_canfd_priv *priv = netdev_priv(ndev);
699 int ret;
700
701 ret = open_candev(ndev);
702 if (ret) {
703 netdev_err(ndev, "Failed to open CAN device\n");
704 return ret;
705 }
706
707 /* Register interrupt handler */
708 ret = request_irq(ndev->irq, ifi_canfd_isr, IRQF_SHARED,
709 ndev->name, ndev);
710 if (ret < 0) {
711 netdev_err(ndev, "Failed to request interrupt\n");
712 goto err_irq;
713 }
714
715 ifi_canfd_start(ndev);
716
717 can_led_event(ndev, CAN_LED_EVENT_OPEN);
718 napi_enable(&priv->napi);
719 netif_start_queue(ndev);
720
721 return 0;
722err_irq:
723 close_candev(ndev);
724 return ret;
725}
726
727static int ifi_canfd_close(struct net_device *ndev)
728{
729 struct ifi_canfd_priv *priv = netdev_priv(ndev);
730
731 netif_stop_queue(ndev);
732 napi_disable(&priv->napi);
733
734 ifi_canfd_stop(ndev);
735
736 free_irq(ndev->irq, ndev);
737
738 close_candev(ndev);
739
740 can_led_event(ndev, CAN_LED_EVENT_STOP);
741
742 return 0;
743}
744
745static netdev_tx_t ifi_canfd_start_xmit(struct sk_buff *skb,
746 struct net_device *ndev)
747{
748 struct ifi_canfd_priv *priv = netdev_priv(ndev);
749 struct canfd_frame *cf = (struct canfd_frame *)skb->data;
750 u32 txst, txid;
751 u32 txdlc = 0;
752 int i;
753
754 if (can_dropped_invalid_skb(ndev, skb))
755 return NETDEV_TX_OK;
756
757 /* Check if the TX buffer is full */
758 txst = readl(priv->base + IFI_CANFD_TXSTCMD);
759 if (txst & IFI_CANFD_TXSTCMD_FULL) {
760 netif_stop_queue(ndev);
761 netdev_err(ndev, "BUG! TX FIFO full when queue awake!\n");
762 return NETDEV_TX_BUSY;
763 }
764
765 netif_stop_queue(ndev);
766
767 if (cf->can_id & CAN_EFF_FLAG) {
768 txid = cf->can_id & CAN_EFF_MASK;
769 txid |= IFI_CANFD_TXFIFO_ID_IDE;
770 } else {
771 txid = cf->can_id & CAN_SFF_MASK;
772 }
773
774 if (priv->can.ctrlmode & (CAN_CTRLMODE_FD | CAN_CTRLMODE_FD_NON_ISO)) {
775 if (can_is_canfd_skb(skb)) {
776 txdlc |= IFI_CANFD_TXFIFO_DLC_EDL;
777 if (cf->flags & CANFD_BRS)
778 txdlc |= IFI_CANFD_TXFIFO_DLC_BRS;
779 }
780 }
781
782 if (cf->can_id & CAN_RTR_FLAG)
783 txdlc |= IFI_CANFD_TXFIFO_DLC_RTR;
784
785 /* message ram configuration */
786 writel(txid, priv->base + IFI_CANFD_TXFIFO_ID);
787 writel(txdlc, priv->base + IFI_CANFD_TXFIFO_DLC);
788
789 for (i = 0; i < cf->len; i += 4) {
790 writel(*(u32 *)(cf->data + i),
791 priv->base + IFI_CANFD_TXFIFO_DATA + i);
792 }
793
794 writel(0, priv->base + IFI_CANFD_TXFIFO_REPEATCOUNT);
795 writel(0, priv->base + IFI_CANFD_TXFIFO_SUSPEND_US);
796
797 can_put_echo_skb(skb, ndev, 0);
798
799 /* Start the transmission */
800 writel(IFI_CANFD_TXSTCMD_ADD_MSG, priv->base + IFI_CANFD_TXSTCMD);
801
802 return NETDEV_TX_OK;
803}
804
805static const struct net_device_ops ifi_canfd_netdev_ops = {
806 .ndo_open = ifi_canfd_open,
807 .ndo_stop = ifi_canfd_close,
808 .ndo_start_xmit = ifi_canfd_start_xmit,
809 .ndo_change_mtu = can_change_mtu,
810};
811
812static int ifi_canfd_plat_probe(struct platform_device *pdev)
813{
814 struct device *dev = &pdev->dev;
815 struct net_device *ndev;
816 struct ifi_canfd_priv *priv;
817 struct resource *res;
818 void __iomem *addr;
819 int irq, ret;
820 u32 id;
821
822 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
823 addr = devm_ioremap_resource(dev, res);
824 irq = platform_get_irq(pdev, 0);
825 if (IS_ERR(addr) || irq < 0)
826 return -EINVAL;
827
828 id = readl(addr + IFI_CANFD_IP_ID);
829 if (id != IFI_CANFD_IP_ID_VALUE) {
830 dev_err(dev, "This block is not IFI CANFD, id=%08x\n", id);
831 return -EINVAL;
832 }
833
834 ndev = alloc_candev(sizeof(*priv), 1);
835 if (!ndev)
836 return -ENOMEM;
837
838 ndev->irq = irq;
839 ndev->flags |= IFF_ECHO; /* we support local echo */
840 ndev->netdev_ops = &ifi_canfd_netdev_ops;
841
842 priv = netdev_priv(ndev);
843 priv->ndev = ndev;
844 priv->base = addr;
845
846 netif_napi_add(ndev, &priv->napi, ifi_canfd_poll, 64);
847
848 priv->can.state = CAN_STATE_STOPPED;
849
850 priv->can.clock.freq = readl(addr + IFI_CANFD_SYSCLOCK);
851
852 priv->can.bittiming_const = &ifi_canfd_bittiming_const;
853 priv->can.data_bittiming_const = &ifi_canfd_data_bittiming_const;
854 priv->can.do_set_mode = ifi_canfd_set_mode;
855 priv->can.do_get_berr_counter = ifi_canfd_get_berr_counter;
856
857 /* IFI CANFD can do both Bosch FD and ISO FD */
858 priv->can.ctrlmode = CAN_CTRLMODE_FD;
859
860 /* IFI CANFD can do both Bosch FD and ISO FD */
861 priv->can.ctrlmode_supported = CAN_CTRLMODE_LOOPBACK |
862 CAN_CTRLMODE_LISTENONLY |
863 CAN_CTRLMODE_FD |
864 CAN_CTRLMODE_FD_NON_ISO;
865
866 platform_set_drvdata(pdev, ndev);
867 SET_NETDEV_DEV(ndev, dev);
868
869 ret = register_candev(ndev);
870 if (ret) {
871 dev_err(dev, "Failed to register (ret=%d)\n", ret);
872 goto err_reg;
873 }
874
875 devm_can_led_init(ndev);
876
877 dev_info(dev, "Driver registered: regs=%p, irq=%d, clock=%d\n",
878 priv->base, ndev->irq, priv->can.clock.freq);
879
880 return 0;
881
882err_reg:
883 free_candev(ndev);
884 return ret;
885}
886
887static int ifi_canfd_plat_remove(struct platform_device *pdev)
888{
889 struct net_device *ndev = platform_get_drvdata(pdev);
890
891 unregister_candev(ndev);
892 platform_set_drvdata(pdev, NULL);
893 free_candev(ndev);
894
895 return 0;
896}
897
898static const struct of_device_id ifi_canfd_of_table[] = {
899 { .compatible = "ifi,canfd-1.0", .data = NULL },
900 { /* sentinel */ },
901};
902MODULE_DEVICE_TABLE(of, ifi_canfd_of_table);
903
904static struct platform_driver ifi_canfd_plat_driver = {
905 .driver = {
906 .name = KBUILD_MODNAME,
907 .of_match_table = ifi_canfd_of_table,
908 },
909 .probe = ifi_canfd_plat_probe,
910 .remove = ifi_canfd_plat_remove,
911};
912
913module_platform_driver(ifi_canfd_plat_driver);
914
915MODULE_AUTHOR("Marek Vasut <marex@denx.de>");
916MODULE_LICENSE("GPL v2");
917MODULE_DESCRIPTION("CAN bus driver for IFI CANFD controller");
diff --git a/drivers/net/can/sja1000/sja1000_platform.c b/drivers/net/can/sja1000/sja1000_platform.c
index 0552ed46a206..dc9c6db96c3c 100644
--- a/drivers/net/can/sja1000/sja1000_platform.c
+++ b/drivers/net/can/sja1000/sja1000_platform.c
@@ -27,6 +27,7 @@
27#include <linux/can/platform/sja1000.h> 27#include <linux/can/platform/sja1000.h>
28#include <linux/io.h> 28#include <linux/io.h>
29#include <linux/of.h> 29#include <linux/of.h>
30#include <linux/of_device.h>
30#include <linux/of_irq.h> 31#include <linux/of_irq.h>
31 32
32#include "sja1000.h" 33#include "sja1000.h"
@@ -40,6 +41,15 @@ MODULE_DESCRIPTION("Socket-CAN driver for SJA1000 on the platform bus");
40MODULE_ALIAS("platform:" DRV_NAME); 41MODULE_ALIAS("platform:" DRV_NAME);
41MODULE_LICENSE("GPL v2"); 42MODULE_LICENSE("GPL v2");
42 43
44struct sja1000_of_data {
45 size_t priv_sz;
46 int (*init)(struct sja1000_priv *priv, struct device_node *of);
47};
48
49struct technologic_priv {
50 spinlock_t io_lock;
51};
52
43static u8 sp_read_reg8(const struct sja1000_priv *priv, int reg) 53static u8 sp_read_reg8(const struct sja1000_priv *priv, int reg)
44{ 54{
45 return ioread8(priv->reg_base + reg); 55 return ioread8(priv->reg_base + reg);
@@ -70,6 +80,43 @@ static void sp_write_reg32(const struct sja1000_priv *priv, int reg, u8 val)
70 iowrite8(val, priv->reg_base + reg * 4); 80 iowrite8(val, priv->reg_base + reg * 4);
71} 81}
72 82
83static u8 sp_technologic_read_reg16(const struct sja1000_priv *priv, int reg)
84{
85 struct technologic_priv *tp = priv->priv;
86 unsigned long flags;
87 u8 val;
88
89 spin_lock_irqsave(&tp->io_lock, flags);
90 iowrite16(reg, priv->reg_base + 0);
91 val = ioread16(priv->reg_base + 2);
92 spin_unlock_irqrestore(&tp->io_lock, flags);
93
94 return val;
95}
96
97static void sp_technologic_write_reg16(const struct sja1000_priv *priv,
98 int reg, u8 val)
99{
100 struct technologic_priv *tp = priv->priv;
101 unsigned long flags;
102
103 spin_lock_irqsave(&tp->io_lock, flags);
104 iowrite16(reg, priv->reg_base + 0);
105 iowrite16(val, priv->reg_base + 2);
106 spin_unlock_irqrestore(&tp->io_lock, flags);
107}
108
109static int sp_technologic_init(struct sja1000_priv *priv, struct device_node *of)
110{
111 struct technologic_priv *tp = priv->priv;
112
113 priv->read_reg = sp_technologic_read_reg16;
114 priv->write_reg = sp_technologic_write_reg16;
115 spin_lock_init(&tp->io_lock);
116
117 return 0;
118}
119
73static void sp_populate(struct sja1000_priv *priv, 120static void sp_populate(struct sja1000_priv *priv,
74 struct sja1000_platform_data *pdata, 121 struct sja1000_platform_data *pdata,
75 unsigned long resource_mem_flags) 122 unsigned long resource_mem_flags)
@@ -154,6 +201,18 @@ static void sp_populate_of(struct sja1000_priv *priv, struct device_node *of)
154 priv->cdr |= CDR_CBP; /* default */ 201 priv->cdr |= CDR_CBP; /* default */
155} 202}
156 203
204static struct sja1000_of_data technologic_data = {
205 .priv_sz = sizeof(struct technologic_priv),
206 .init = sp_technologic_init,
207};
208
209static const struct of_device_id sp_of_table[] = {
210 { .compatible = "nxp,sja1000", .data = NULL, },
211 { .compatible = "technologic,sja1000", .data = &technologic_data, },
212 { /* sentinel */ },
213};
214MODULE_DEVICE_TABLE(of, sp_of_table);
215
157static int sp_probe(struct platform_device *pdev) 216static int sp_probe(struct platform_device *pdev)
158{ 217{
159 int err, irq = 0; 218 int err, irq = 0;
@@ -163,6 +222,9 @@ static int sp_probe(struct platform_device *pdev)
163 struct resource *res_mem, *res_irq = NULL; 222 struct resource *res_mem, *res_irq = NULL;
164 struct sja1000_platform_data *pdata; 223 struct sja1000_platform_data *pdata;
165 struct device_node *of = pdev->dev.of_node; 224 struct device_node *of = pdev->dev.of_node;
225 const struct of_device_id *of_id;
226 const struct sja1000_of_data *of_data = NULL;
227 size_t priv_sz = 0;
166 228
167 pdata = dev_get_platdata(&pdev->dev); 229 pdata = dev_get_platdata(&pdev->dev);
168 if (!pdata && !of) { 230 if (!pdata && !of) {
@@ -191,7 +253,13 @@ static int sp_probe(struct platform_device *pdev)
191 if (!irq && !res_irq) 253 if (!irq && !res_irq)
192 return -ENODEV; 254 return -ENODEV;
193 255
194 dev = alloc_sja1000dev(0); 256 of_id = of_match_device(sp_of_table, &pdev->dev);
257 if (of_id && of_id->data) {
258 of_data = of_id->data;
259 priv_sz = of_data->priv_sz;
260 }
261
262 dev = alloc_sja1000dev(priv_sz);
195 if (!dev) 263 if (!dev)
196 return -ENOMEM; 264 return -ENOMEM;
197 priv = netdev_priv(dev); 265 priv = netdev_priv(dev);
@@ -208,10 +276,17 @@ static int sp_probe(struct platform_device *pdev)
208 dev->irq = irq; 276 dev->irq = irq;
209 priv->reg_base = addr; 277 priv->reg_base = addr;
210 278
211 if (of) 279 if (of) {
212 sp_populate_of(priv, of); 280 sp_populate_of(priv, of);
213 else 281
282 if (of_data && of_data->init) {
283 err = of_data->init(priv, of);
284 if (err)
285 goto exit_free;
286 }
287 } else {
214 sp_populate(priv, pdata, res_mem->flags); 288 sp_populate(priv, pdata, res_mem->flags);
289 }
215 290
216 platform_set_drvdata(pdev, dev); 291 platform_set_drvdata(pdev, dev);
217 SET_NETDEV_DEV(dev, &pdev->dev); 292 SET_NETDEV_DEV(dev, &pdev->dev);
@@ -242,12 +317,6 @@ static int sp_remove(struct platform_device *pdev)
242 return 0; 317 return 0;
243} 318}
244 319
245static const struct of_device_id sp_of_table[] = {
246 {.compatible = "nxp,sja1000"},
247 {},
248};
249MODULE_DEVICE_TABLE(of, sp_of_table);
250
251static struct platform_driver sp_driver = { 320static struct platform_driver sp_driver = {
252 .probe = sp_probe, 321 .probe = sp_probe,
253 .remove = sp_remove, 322 .remove = sp_remove,