This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Linux/AM3352: mcp251x can driver integration

Part Number: AM3352

Tool/software: Linux

Hello,

We have our own board design based on am3352 processor and we use kernel 4.4.19 from TI SDK 03.01.00.06

We also want to integrate mcp251x can driver. Could you please help us to find out how to make configuration in our .dts file?

Any configuration example would be wellcome.

Best regards

  • Sorry, In case it can help I forgot to mention that we are using spi0, cs0 and gpio2_6 as can interrupt.

    Best regards
  • Hi Angel,

    The driver for mcp251x is ..<Linux-folder>/drivers/net/can/spi/mcp251x.c
    You should enable CONFIG_CAN_MCP251X setting in your kernel config file.
    Also you can find MCP251x device tree example at:
    ..<Linux-folder>/Documentation/devicetree/bindings/net/can/microchip,mcp251x.txt

    BR
    Tsvetolin Shulev
  • Hi,

    Thank you for your help.
    I am also using internal can0 and can1 from am335s, so I added to my .dts file

    can2: can@0 {
    compatible = "microchip,mcp2515";
    reg = <0>;
    clocks = <16000000>;
    interrupt-parent = <&gpio2>;
    interrupts = <6 0x2>;
    };

    When I boot the dice I see that mcp251x driver is loaded
    root@arm:~# lsmod
    Module Size Used by Not tainted
    musb_dsps 8235 0
    musb_hdrc 71102 1 musb_dsps
    udc_core 12063 1 musb_hdrc
    usbcore 193909 1 musb_hdrc
    pru_rproc 11582 0
    ecb 1909 0
    pruss_intc 7163 1 pru_rproc
    sha256_generic 9503 0
    snd_soc_simple_card 8001 0
    hmac 2735 0
    md5 1897 0
    sha1_generic 2621 0
    sha1_arm_neon 6261 0
    sha1_arm 3862 1 sha1_arm_neon
    omap_aes_driver 19430 0
    pruss 10892 1 pru_rproc
    omap_sham 21513 0
    omap_rng 4482 0
    rng_core 7538 1 omap_rng
    c_can_platform 6590 0
    c_can 9514 1 c_can_platform
    snd_soc_tlv320aic31xx 32164 1
    musb_am335x 1426 0 [permanent]
    omap_wdt 4634 0
    mcp251x 9991 0
    can_dev 12154 2 c_can,mcp251x

    I can set internal on chip can0 and can1, but not external mcp251x based can2

    root@arm:~# ip link set can0 type can bitrate 125000
    root@arm:~# ip link set up can0
    [ 593.216341] c_can_platform 481cc000.can can0: setting BTR=1c0b BRPE=0000
    root@arm:~#
    root@arm:~# ip link set can1 type can bitrate 125000
    root@arm:~# ip link set up can1
    [ 604.696594] c_can_platform 481d0000.can can1: setting BTR=1c0b BRPE=0000
    root@arm:~#
    root@arm:~# ifconfig
    can0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
    UP RUNNING NOARP MTU:16 Metric:1
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:10
    RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
    Interrupt:165

    can1 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
    UP RUNNING NOARP MTU:16 Metric:1
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:10
    RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
    Interrupt:166

    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:65536 Metric:1
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1
    RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)


    root@arm:~# ip link set can2 type can bitrate 125000
    Cannot find device "can2"

    Can you please help to find what I am missing?

    Best regards
  • Hello again,

    I am still working on this, and I am not able to read data from mcp2515 registers. Always read 0x00.
    I have checked with oscilloscope and sclk(spi0_sclk), cs(spi0_cs0), mosi(spi0_d0) and miso(spi0_d1) are OK. When I try to read different data registers I see that data coming from mcp2515 on MISO line is as expected, but driver always reads 0x00.

    This is my .dts configuration

    mcp2515_clock: mcp2515_clock {
    compatible = "fixed-clock";
    #clock-cells = <0>;
    clock-frequency = <16000000>;
    };

    can2_pins: pinmux_can2_pins {
    pinctrl-single,pins = <
    0x150 ( PIN_OUTPUT | MUX_MODE0 ) /* (A17) spi0_sclk.spi0_sclk */
    0x154 ( PIN_OUTPUT | MUX_MODE0 ) /* (B17) spi0_d0.spi0_d0 */
    0x158 ( PIN_INPUT | MUX_MODE0 ) /* (B16) spi0_d1.spi0_d1 */
    0x15c ( PIN_OUTPUT | MUX_MODE0 ) /* (A16) spi0_cs0.spi0_cs0 */
    0x160 ( PIN_OUTPUT | MUX_MODE0 ) /* (C15) spi0_cs1.spi0_cs1 */
    >;

    &spi0 {
    status = "okay";
    pinctrl-names = "default";
    pinctrl-0 = <&can2_pins>;
    ti,pindir-d0-out-d1-in;
    can@0 {
    compatible = "microchip,mcp2515";
    reg = <0>;
    spi-max-frequency = <5000000>; // 5 MHz
    interrupt-parent = <&gpio2>;//interrupt on port 2
    interrupts = <6 IRQ_TYPE_EDGE_FALLING>;//port 2-6
    clocks = <&mcp2515_clock>;
    };
    };

    Could you please help us?

    Best regards
  • Hi,

    Finally we got it working. Just this change

    0x150 ( PIN_INPUT_PULLDOWN | MUX_MODE0 ) /* (A17) spi0_sclk.spi0_sclk */

    Regards
  • Thank you for solution sharing.

    BR
    Tsvetolin Shulev