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/BEAGLEBK: Beaglebone Black enable SPI1

Part Number: BEAGLEBK

Tool/software: Linux

Hi

I was trying to enable SPI1 on Beaglebone Black following these two posts:

https://e2e.ti.com/support/processors/f/791/t/737397

https://e2e.ti.com/support/processors/f/791/t/455854

An spidev user space driver will be used to control the device. I was able to see the "spidev1.0" device node in /dev. However, there are two warning/error messages when the Linux boots:

First:

[    0.931554] spidev spi1.0: buggy DT: spidev listed directly in DT
[    0.937859] ------------[ cut here ]------------
[    0.942592] WARNING: CPU: 0 PID: 1 at .../am335x-evm/kernel-source/drivers/spi/spidev.c:730 spidev_probe+0x1a4/0x1d4
[    0.956056] Modules linked in:
[    0.959131] CPU: 0 PID: 1 Comm: swapper Not tainted 4.14.67... #2
[    0.967178] Hardware name: Generic AM33XX (Flattened Device Tree)
[    0.973304] Backtrace:
[    0.975782] [<c010bcac>] (dump_backtrace) from [<c010bf90>] (show_stack+0x18/0x1c)
[    0.983397]  r7:00000009 r6:00000000 r5:c0af3d2c r4:00000000
[    0.989090] [<c010bf78>] (show_stack) from [<c0825e24>] (dump_stack+0x24/0x28)
[    0.996363] [<c0825e00>] (dump_stack) from [<c0128d24>] (__warn+0xe8/0x100)
[    1.003372] [<c0128c3c>] (__warn) from [<c0128df4>] (warn_slowpath_null+0x28/0x30)
...
[    1.404855] ---[ end trace dd0b292e7edbf342 ]---

Second:

[    1.741176] pinctrl-single 44e10800.pinmux: pin PIN103 already requested by 481a0000.spi; cannot claim for 48038000.mcasp
[    1.752361] pinctrl-single 44e10800.pinmux: pin-103 (48038000.mcasp) status -22
[    1.759770] pinctrl-single 44e10800.pinmux: could not request pin 103 (PIN103) from group mcasp0_pins on device pinctrl-single
[    1.771381] davinci-mcasp 48038000.mcasp: Error applying setting, reverse things back
[    1.779394] davinci-mcasp: probe of 48038000.mcasp failed with error -22

Here are what I did:

1. Enable CONFIG_SPI_SPIDEV in the kernel.

2. Patch Linux kernel in driver/spi/spidev.c:

 static const struct of_device_id spidev_dt_ids[] = {
        { .compatible = "rohm,dh2228fv" },
+       { .compatible = "linux,spidev" },
        { .compatible = "lineartechnology,ltc2488" },
        { .compatible = "ge,achc" },
        { .compatible = "semtech,sx1301" },

3. Patch device tree in arch/arm/boot/dts/am335x-boneblack.dts:

+        spi1_pins: spi1_pins {
+                pinctrl-single,pins = <
+                        AM33XX_IOPAD(0x990, PIN_OUTPUT_PULLUP | MUX_MODE3)      /* spi1_sclk */
+                        AM33XX_IOPAD(0x994, PIN_INPUT_PULLUP | MUX_MODE3)       /* spi1_d0 */
+                        AM33XX_IOPAD(0x998, PIN_INPUT_PULLUP | MUX_MODE3)       /* spi1_d1 */
+                        AM33XX_IOPAD(0x99C, PIN_OUTPUT_PULLUP | MUX_MODE3)      /* spi1_cs0 */
+                >;
+        };
+
 };


+&spi1 {
+        status = "okay";
+        pinctrl-names = "default";
+        pinctrl-0 = <&spi1_pins>;
+        spidev@0 {
+                  spi-max-frequency = <48000000>;
+                  reg = <0>;
+                  compatible = "linux,spidev";
+        };
+};
+
+

Questions:

1. I suspect there are mistakes in the device tree. What is the proper way to do it? Why?

2. Is the patch in spidev.c also correct?

Thank you!

  • Hi Matt,

    Do you use BEAGLEBK board or AM335x custom board that is based on BEAGLEBK?

    Do you use AM335x TI PSDK Linux? The latest version is v5.03:

    software-dl.ti.com/.../index_FDS.html


    I don't think you need to patch spidev.c with "linux,spidev". The official recommendation is to use "rohm,dh2228fv". Check below user guide for details:

    software-dl.ti.com/.../Foundational_Components_Kernel_Drivers.html

    Regards,
    Pavel
  • Hi Pavel,

    I am using the BEAGLEBK board and the Yocto recipes from meta-ti and poky (both rocko branches) to build.

    Thank you for the pointers. After I disable the patch in spidev.c, the first error message goes away. The second error still exists:

    [ 1.741176] pinctrl-single 44e10800.pinmux: pin PIN103 already requested by 481a0000.spi; cannot claim for 48038000.mcasp
    [ 1.752361] pinctrl-single 44e10800.pinmux: pin-103 (48038000.mcasp) status -22
    [ 1.759770] pinctrl-single 44e10800.pinmux: could not request pin 103 (PIN103) from group mcasp0_pins on device pinctrl-single
    [ 1.771381] davinci-mcasp 48038000.mcasp: Error applying setting, reverse things back
    [ 1.779394] davinci-mcasp: probe of 48038000.mcasp failed with error -22

    I believe this is caused by the mcasp0_pins pinmux in am335x-boneblack-common.dtsi. My guess is removing "mcasp0" related device tree nodes in am335x-boneblack-common.dtsi will probably work. However, I wonder if there is a proper way to disable/override it from am335x-boneblack.dts? This will make the overall solution cleaner. Or, if this not the proper way to solve this error, please help with the solution.

    Thank you,

    Matt
  • Hi Pavel,

    I have further questions after I tried the spidev_test.c program:
    1. For some reason, the spi1_sclk needs to be configured as "INPUT" in the pinmux for the spidev_test.c work. It seems to me that spi1_sclk should be an output signal. Could you please explain why it needs to be an "INPUT"?

    Here is the snippet of my pinmux for SPI1, note spi1_sclk is set as "INPUT":
    spi1_pins: pinmux_spi1_pins {
    pinctrl-single,pins = <
    AM33XX_IOPAD(0x990, PIN_INPUT_PULLUP | MUX_MODE3) /* spi1_sclk */
    AM33XX_IOPAD(0x994, PIN_INPUT_PULLUP | MUX_MODE3) /* spi1_d0 */
    AM33XX_IOPAD(0x998, PIN_OUTPUT_PULLUP | MUX_MODE3) /* spi1_d1 */
    AM33XX_IOPAD(0x99C, PIN_OUTPUT_PULLUP | MUX_MODE3) /* spi1_cs0 */
    >;
    };

    2. Can you explain why spi-max-frequency needs to be <24000000> in the device tree?


    Thank you very much!
  • Matt,

    Matt Tsai52 said:
    I am using the BEAGLEBK board and the Yocto recipes from meta-ti and poky (both rocko branches) to build.

    I would suggest you to use kernel that comes with AM335x PSDK Linux (latest version is 5.03, kernel v4.14.79) or fetch it from the git tree:

    Linux Kernel

    The kernel git repository, branch and commit id can be found below:
    Based on Version: 4.14.79
    URL: git://git.ti.com/processor-sdk/processor-sdk-linux.git
    Branch: processor-sdk-linux-4.14.y
    Commit ID: e669d52447df61f9d7b8ef72c9f22f4feed04d38
    Only this kernel is tested and verified by TI at TI platform (AM335x EVM, BEAGLEBK, etc)
    Matt Tsai52 said:
    [ 1.741176] pinctrl-single 44e10800.pinmux: pin PIN103 already requested by 481a0000.spi; cannot claim for 48038000.mcasp
    [ 1.752361] pinctrl-single 44e10800.pinmux: pin-103 (48038000.mcasp) status -22
    [ 1.759770] pinctrl-single 44e10800.pinmux: could not request pin 103 (PIN103) from group mcasp0_pins on device pinctrl-single
    [ 1.771381] davinci-mcasp 48038000.mcasp: Error applying setting, reverse things back
    [ 1.779394] davinci-mcasp: probe of 48038000.mcasp failed with error -22
    I believe this is caused by the mcasp0_pins pinmux in am335x-boneblack-common.dtsi. My guess is removing "mcasp0" related device tree nodes in am335x-boneblack-common.dtsi will probably work. However, I wonder if there is a proper way to disable/override it from am335x-boneblack.dts? This will make the overall solution cleaner. Or, if this not the proper way to solve this error, please help with the solution.
    By default BEAGLEBK is using McSPI0, pinmux described in below DTS file:
    am335x-boneblack-spi0.dtsi
    If you need to use McSPI1 and still able to use McASP0, you need to use another McSPI1 pins (not C12, B13, A13). Refer to AM335x datasheet for available options, Table 4-54. SPI/SPI1 Signals Description.
    If you don't need McASP0, you can edit am335x-boneblack-common.dtsi file, remove McASP, sound and tda19988 related nodes.
    Regards,
    Pavel
  • Matt Tsai52 said:
    1. For some reason, the spi1_sclk needs to be configured as "INPUT" in the pinmux for the spidev_test.c work. It seems to me that spi1_sclk should be an output signal. Could you please explain why it needs to be an "INPUT"?

    When you configure it as "INPUT", you are making it INPUT/OUTPUT. This pin ca be OUTPUT only or INPUT/OUTPUT. Refer to AM335x TRM, section 24.2.3 McSPI Pin List

    SPIx_SCLK  -  I/O

    This output signal is also used as a re-timing input. The associated CONF_<module>_<pin>_RXACTIVE bit for the output clock must be set to 1 to enable the clock input back to the module.

     

    Matt Tsai52 said:
    2. Can you explain why spi-max-frequency needs to be <24000000> in the device tree?

     

    This is one possible value, 24MHz. The max possible value is 48MHz, and BEAGLEBK McSPI0 is using 16MHz:

    spi-max-frequency = <16000000>;

    spi-max-frequency - Maximum SPI clocking speed of device in Hz

     

    The max 48MHz value comes from AM335 datasheet, 7.12.1 McSPI Electrical Data and Timing

    tc(SPICLK) - Cycle time, SPI_CLK - 20.8ns min

     

    Regards,
    Pavel

  • Hi Pavel,

    Thank you for your answers. That helps me a lot.

    We have spent some efforts to customize our recipes based on meta-ti and poky. So moving to a different branch and build system will cost significant development efforts. However, would you recommend the meta-ti to poky branches/tag to upgrade to? We will consider that if time allowed.

    Thank you,
    Matt