Skip to contentSkip to conversation

Microchip mcp25xxfd can controller driver

PATCH Superseded [email protected] 4 participants 7 messages Jan 19, 2018 – Jan 29, 2018 1 message not in the archive

Subsystems (2)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v2 cover Microchip mcp25xxfd can controller driver

From: Martin Sperl <[email protected]>

This patchset adds a driver for the mcp25xxfd CanFD controller.

Most of the features of the controller are supported by this driver release.

The controller includes a few features that the current core Can(FD) implementation does not support:
* Transmit Bandwidth Sharing bits
- this waits for a configurable number of syncronization bits before atempting to transmit the next frame - for the moment controllable via a module parameter
* SID11 with CanFD frames
- at this moment not supported by driver
* 3 transmit attempts in addition to ONE_SHOT
* transmitter delay compensation configurations
* micro second exact transmission and reception timestamps
- used internally by driver
* variable number of tx-fifos
- exposed via module parameter at this moment

The driver has been heavily optimized so that it can handle a 100% utilized 1MHz Can-bus (with 11 bit can frames with DLC=0) even on less powerfull SOCs like the raspberry pi 1 without dropping frames due to driver/spi latencies (still dropps are observed in the can/network stack).

To achive this the driver includes several code optimization Two of which prefers continuous long spi transfers over multiple small individual spi transfers of variable length.
This is an optimization that would favour spi dma transfers instead of more expensive PIO in typical SPI controllers.
Both of them can get explicitly enabled by the use of a module parameter. One of those is automatically used in the case of Can2.0 only bus configurations.

Finer details of the implementation and rational is included with the driver code it self for future reference.

The driver has also been tested for basic CanFD transfers with BRS up to 5.7Mhz data bitrates - the available transceiver did not allow for faster rates...

The driver itself exposes lots of internal data/statistics via debugfs.

The driver implements a lock-less design for transmissions making use instead of prepared spi messages submitted via spi_async for transmission in the start_xmit_start code without requireing an extra workqueue and the corresponding latencies.

Note that there is an extra patch in the pipeline to implement pinctrl but this still shows some issues, so it is not included in this patchset.

Changelog:
V1 -> V2: new more generic name based on feedback from microchip
cleanup of code (checkpatch)
address all feedback on code
handle (HW) systemerrors in a much better/reliable way cleanup of dt custom properties removing (most) gpio related properties implemented GPIOLIB support as per feedback

Martin Sperl (3):
dt-binding: can: mcp25xxfd: document device tree bindings
can: mcp25xxfd: Add Microchip mcp25xxfd CAN FD driver
can: mcp25xxfd: add gpiolib support for GPIO0/1 (aka. INT0/INT1)

 .../bindings/net/can/microchip,mcp25xxfd.txt       |   31 +
 drivers/net/can/spi/Kconfig                        |    6 +
 drivers/net/can/spi/Makefile                       |    1 +
 drivers/net/can/spi/mcp25xxfd.c                    | 4509 ++++++++++++++++++++
 4 files changed, 4547 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.txt
 create mode 100644 drivers/net/can/spi/mcp25xxfd.c

--
2.11.0

#1 lore raw

PATCH v2 1/3 dt-binding: can: mcp25xxfd: document device tree bindings

From: Martin Sperl <[email protected]>

Add device-tree bindings for Microcip CanFD Controller mcp2517fd

---
Changelog:
V1 -> V2: new more generic name based on feedback from microchip
cleanup of dt custom properties removing (most) gpio functions

---
 .../bindings/net/can/microchip,mcp25xxfd.txt       | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.txt
Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.txt new file +29 -0
new file mode 100644
index 000000000000..691dd6220bd7
@@ -0,0 +1,29 @@
+* Microchip MCP2517 stand-alone CAN controller device tree bindings
+
+Required properties:
+ - compatible: Should be one of the following:
+   - "microchip,mcp2517fd" for MCP2517fd.
+ - reg: SPI chip select.
+ - clocks: The clock feeding the CAN controller.
+ - interrupt-parent: The parent interrupt controller.
+ - interrupts: Should contain IRQ line for the CAN controller.
+
+Optional properties:
+ - vdd-supply: Regulator that powers the CAN controller.
+ - xceiver-supply: Regulator that powers the CAN transceiver.
+ - microchip,clock_out_div = <0|1|2|4|10>: Clock output pin divider
+					   0 = Start of Frame output
+					   default: 10
+ - microchip,clock_div2: bool: divide the internal clock by 2
+ - gpio_opendrain: bool: enable open-drain for all pins (except cantx)
+
+Example:
+	can0: can@1 {
+		compatible = "microchip,mcp2515";
+		reg = <1>;
+		clocks = <&clk24m>;
+		interrupt-parent = <&gpio4>;
+		interrupts = <13 0x8>;
+		vdd-supply = <&reg5v0>;
+		xceiver-supply = <&reg5v0>;
+	};

--
2.11.0

maintainer
#2 lore raw

Re: [PATCH V2 1/3] dt-binding: can: mcp25xxfd: document device tree bindings

Quoted 29 lines · On Fri, Jan 19, 2018 at 07:41:38AM +0000, [email protected] wrote:

From: Martin Sperl <[email protected]>

Add device-tree bindings for Microcip CanFD Controller mcp2517fd

---
Changelog:
V1 -> V2: new more generic name based on feedback from microchip
cleanup of dt custom properties removing (most) gpio functions

---
 .../bindings/net/can/microchip,mcp25xxfd.txt       | 29 ++++++++++++++++++++++
 1 file changed, 29 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.txt
Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.txt new file +8 -0
new file mode 100644
index 000000000000..691dd6220bd7
@@ -0,0 +1,29 @@
+* Microchip MCP2517 stand-alone CAN controller device tree bindings
+
+Required properties:
+ - compatible: Should be one of the following:
+   - "microchip,mcp2517fd" for MCP2517fd.
+ - reg: SPI chip select.
+ - clocks: The clock feeding the CAN controller.
+ - interrupt-parent: The parent interrupt controller.

Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.txt line 17

Quoted 10 lines
Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.txt new file +9 -0
+ - interrupts: Should contain IRQ line for the CAN controller.
+
+Optional properties:
+ - vdd-supply: Regulator that powers the CAN controller.
+ - xceiver-supply: Regulator that powers the CAN transceiver.
 
+ - microchip,clock_out_div = <0|1|2|4|10>: Clock output pin divider
+					   0 = Start of Frame output
+					   default: 10
+ - microchip,clock_div2: bool: divide the internal clock by 2

s/_/-/

Quoted 1 line

+ - gpio_opendrain: bool: enable open-drain for all pins (except cantx)

Needs a vendor prefix.

Quoted 17 lines
Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.txt new file +11 -1
+
+Example:
+	can0: can@1 {
+		compatible = "microchip,mcp2515";
+		reg = <1>;
+		clocks = <&clk24m>;
+		interrupt-parent = <&gpio4>;
+		interrupts = <13 0x8>;
+		vdd-supply = <&reg5v0>;
+		xceiver-supply = <&reg5v0>;
+	};
--

2.11.0
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

A message that is not in the archive (sent off-list or not yet received): 20180119074140.25931-1-kernel-TqfNSX0MhmxHKSADF0wUEw@public.gmane.org

#4 lore raw

PATCH v2 2/3 can: mcp25xxfd: Add Microchip mcp25xxfd CAN FD driver

From: Martin Sperl <[email protected]>

This patch adds support for the Microchip mcp2517fd CAN-FD controller. The mcp2517fd is capable of transmitting and receiving standard data frames, extended data frames, remote frames and Can-FD frames. The mcp2517fd interfaces with the host over SPI.

Datasheet:
* http://ww1.microchip.com/downloads/en/DeviceDoc/20005688A.pdf
Reference manual:
* http://ww1.microchip.com/downloads/en/DeviceDoc/20005678A.pdf

---
Changelog:
V1 -> V2: new more generic name based on feedback from microchip
cleanup of code (checkpatch)
address all feedback on code
prepare code for GPIO handling (separate patches) handle systemerrors in a much better/reliable way

---
 drivers/net/can/spi/Kconfig     |    6 +
 drivers/net/can/spi/Makefile    |    1 +
 drivers/net/can/spi/mcp25xxfd.c | 4324 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 4331 insertions(+)
 create mode 100644 drivers/net/can/spi/mcp25xxfd.c
drivers/net/can/spi/Kconfig +6 -0
index 8f2e0dd7b756..06d588e28c35 100644
@@ -13,4 +13,10 @@ config CAN_MCP251X
 	---help---
 	  Driver for the Microchip MCP251x SPI CAN controllers.
 
+config CAN_MCP25XXFD
+	tristate "Microchip MCP25xxFD SPI CAN controllers"
+	depends on HAS_DMA
+	---help---
+	  Driver for the Microchip MCP25XXFD SPI FD-CAN controller family.
+
 endmenu
drivers/net/can/spi/Makefile +1 -0
index f59fa3731073..805643e0a01e 100644
@@ -5,3 +5,4 @@
 
 obj-$(CONFIG_CAN_HI311X)	+= hi311x.o
 obj-$(CONFIG_CAN_MCP251X)	+= mcp251x.o
+obj-$(CONFIG_CAN_MCP25XXFD)	+= mcp25xxfd.o
drivers/net/can/spi/mcp25xxfd.c new file +4324 -0

2,986 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

--
2.11.0
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

Part of the diff is not shown here. View the raw message.

#5 lore raw

PATCH v2 3/3 can: mcp25xxfd: add gpiolib support for GPIO0/1 (aka. INT0/INT1)

In reply to [email protected]

From: Martin Sperl <[email protected]>

Add GPIOLIB support to mcp25xxfd.

---
Changelog:
V1 -> V2: implemented GPIOLIB support as per feedback

---
.../bindings/net/can/microchip,mcp25xxfd.txt | 2 +

 drivers/net/can/spi/mcp25xxfd.c                    | 185 +++++++++++++++++++++
 2 files changed, 187 insertions(+)
Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.txt +2 -0
index 691dd6220bd7..716b0a16ecb2 100644
@@ -7,6 +7,7 @@ Required properties:
  - clocks: The clock feeding the CAN controller.
  - interrupt-parent: The parent interrupt controller.
  - interrupts: Should contain IRQ line for the CAN controller.
+ - gpio-controller: Marks the device node as a GPIO controller
 
 Optional properties:
  - vdd-supply: Regulator that powers the CAN controller.
@@ -26,4 +27,5 @@ Example:
 		interrupts = <13 0x8>;
 		vdd-supply = <&reg5v0>;
 		xceiver-supply = <&reg5v0>;
+		gpio-controller;
 	};
drivers/net/can/spi/mcp25xxfd.c +185 -0

212 lines not on this page · raw message

--
2.11.0

maintainer
#6 lore raw

Re: [PATCH V2 3/3] can: mcp25xxfd: add gpiolib support for GPIO0/1 (aka. INT0/INT1)

Quoted 20 lines · On Fri, Jan 19, 2018 at 07:41:40AM +0000, [email protected] wrote:

From: Martin Sperl <[email protected]>

Add GPIOLIB support to mcp25xxfd.

---
Changelog:
V1 -> V2: implemented GPIOLIB support as per feedback

---
.../bindings/net/can/microchip,mcp25xxfd.txt | 2 +

 drivers/net/can/spi/mcp25xxfd.c                    | 185 +++++++++++++++++++++
 2 files changed, 187 insertions(+)
Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.txt +0 -0
index 691dd6220bd7..716b0a16ecb2 100644

Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.txt Required properties: · line 10

Quoted 4 lines
Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.txt +1 -0
@@ -7,6 +7,7 @@ Required properties:
  - clocks: The clock feeding the CAN controller.
  - interrupt-parent: The parent interrupt controller.
  - interrupts: Should contain IRQ line for the CAN controller.
+ - gpio-controller: Marks the device node as a GPIO controller

This belongs in patch 1. The binding describes the h/w, not what a driver currently supports.

Quoted 9 lines
Documentation/devicetree/bindings/net/can/microchip,mcp25xxfd.txt +1 -0
 Optional properties:
  - vdd-supply: Regulator that powers the CAN controller.
@@ -26,4 +27,5 @@ Example:
 		interrupts = <13 0x8>;
 		vdd-supply = <&reg5v0>;
 		xceiver-supply = <&reg5v0>;
+		gpio-controller;
 	};
Tested-by on the v2 series
#7 lore raw
In reply to [email protected]

Hi,

many thanks Martin for the update. The code works flawlesly here in a mixed environment with a manual setup of the timing parameters. I had to setup the timing by hand to get it working with all my CAN bus members (250kb):

ip link set can0 up type can tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1

I need to do this because the kernel CAN bit timing calculation has imho a problem with wide range timing parameters. Here the calculation based on the Kernel algorithm (used an extended can-calc-bit-timnig):

Bit timing parameters for mcp2517fd with 40.000000 MHz ref clock
nominal real Bitrt nom real SampP
Bitrate TQ[ns] PrS PhS1 PhS2 SJW BRP Bitrate Error SampP SampP Error CiNBTCFG

1000000     25  14   15   10   1   1 1000000  0.0% 75.0% 75.0%  0.0% 0x001c0900
 800000     25  19   20   10   1   1  800000  0.0% 80.0% 80.0%  0.0% 

0x00260900
500000 25 34 35 10 1 1 500000 0.0% 87.5% 87.5% 0.0%
0x00440900
250000 25 69 70 20 1 1 250000 0.0% 87.5% 87.5% 0.0%
0x008a1300
125000 50 69 70 20 1 2 125000 0.0% 87.5% 87.5% 0.0%
0x018a1300
100000 50 87 87 25 1 2 100000 0.0% 87.5% 87.5% 0.0%
0x01ad1800
50000 100 87 87 25 1 4 50000 0.0% 87.5% 87.5% 0.0%
0x03ad1800
20000 250 87 87 25 1 10 20000 0.0% 87.5% 87.5% 0.0%
0x09ad1800
10000 500 87 87 25 1 20 10000 0.0% 87.5% 87.5% 0.0%
0x13ad1800

The kernel algorithm try to use the smallest SYNC_SEG (-> SJW) to calculate the other values. But a tq of 25 ns seems to be to small for the synchonization segment on a mixed 50kb environment. I've read a bunch of different CAN bit timing docs and they are talking about 16 or 20 time quantas.

Anyway the mcp25xxfd kernel module works: