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.

May I install my SPI Device driver with SPI1, chip select0 ?

I'm using BeagleBone Black platform which is basded on AM335x processor. And I know that I can use /dev/spidev1.0 to read/write spi device. And spidev is configured by device tree source(.dts file) as follow:

/dts-v1/;
/plugin/;

/ {
compatible = "ti,beaglebone", "ti,beaglebone-black";

/* identification */
part-number = "spi0pinmux";

fragment@0 {
target = <&am33xx_pinmux>;
__overlay__ {
spi0_pins_s0: spi0_pins_s0 {
pinctrl-single,pins = <
0x150 0x30 /* spi0_sclk, INPUT_PULLUP | MODE0 */
0x154 0x10 /* spi0_d0, OUTPUT_PULLUP | MODE0 */
0x158 0x30 /* spi0_d1, INPUT_PULLUP | MODE0 */
0x15c 0x10 /* spi0_cs0, OUTPUT_PULLUP | MODE0 */
>;
};
};
};

fragment@1 {
target = <&spi0>;
__overlay__ {
#address-cells = <1>;
#size-cells = <0>;

status = "okay";
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins_s0>;
ti,pindir-d0-out-d1-in = <1>;


spidev@0 {
spi-max-frequency = <24000000>;
reg = <0>;
compatible = "linux,spidev";
};
};
};
};

And now I want to use my own driver, instead of spidev. So, I removed the following from the above .dts file, in order to remove spidev.

spidev@0 {
spi-max-frequency = <24000000>;
reg = <0>;
compatible = "linux,spidev";
};

And then, I can register my spi device driver with SPI1 and CS0.

But I cannot read/write registers of spi device anymore. I checked the timing. It seems that CS is always in low level when my board powers up without any reading/writing operation. Is it a problem? I suspect that the SPI1 with CS0 is not configured correctly.

Could you please give some suggestions? Or tell me how to configure SPI1 CS0 without spidev installed?

Thanks a lot.

Mian Tang

  • Hi,

    I will ask the software team, but reply can be delayed due to the holidays.
  • Hi, 

    You are muxing the SPI0 pins on BBB expansion header, and then you are trying to use SPI1_CS0. IMO, this is why you don't see the SPI1_CS0 signal pulling up on kernel bootup. 

    Best Regards, 

    Yordan

  • Hi Yordan,

    Thank you for your quickly reply. I'm sorry, I'm not sure that I understand it. I just modified .dts file. Could you please tell me whether my .dts file is wrong? Or is there anything else I need to do in my spi device driver?

     I know it's holiday, and maybe I need to wait for the next year. It's OK.

    Thanks a lot.

    Best Regards,

    Mian Tang

  • Hi,

    Try with the following pinmux for SPI1:
    spi1_pins: spi1_pins {
    pinctrl-single,pins = <
    0x190 (PIN_INPUT_PULLUP | MUX_MODE3) /*MCASP0_ACLKX.spi1_clk -> expansion P9 - pin 31*/
    0x194 (PIN_INPUT_PULLUP | MUX_MODE3) /*MCASP0_FSX.spi1_d0 -> expansion P9 - pin 29*/
    0x198 (PIN_OUTPUT_PULLUP | MUX_MODE3) /*MCASP0_AXR0.spi1_d1 -> expansion P9 - pin 30*/
    0x19c (PIN_OUTPUT_PULLUP | MUX_MODE3) /*MCASP0_AHCLKR.spi1_cs0 -> expansion P9 - pin 28*/
    >;
    };

    Best Regards,
    Yordan
  • Dear Yordan,

    I'll try it. Thanks a lot.

    Happy New Year.

    Best Regards,

    Mian Tang

  • Dear Yordan,

    I'll try it. Thanks a lot.

    Happy New Year.

    Best Regards,

  • Hi,

    Sorry, it's for SPI1 which is "spidev2" in Linux user space. I know this configuration. Please let me say "spidev1" which is SPI0 controller, and the configuration is below:

    spi0_pins_s0: spi0_pins_s0 {
    pinctrl-single,pins = <
    0x150 0x30 /* spi0_sclk, INPUT_PULLUP | MODE0 */
    0x154 0x10 /* spi0_d0, OUTPUT_PULLUP | MODE0 */
    0x158 0x30 /* spi0_d1, INPUT_PULLUP | MODE0 */
    0x15c 0x10 /* spi0_cs0, OUTPUT_PULLUP | MODE0 */
    >;
    };

    I have this configuration in .dts file, and compile it to get .dtbo file, and copy it to /lib/firmware. After that, I restart the BBB. And when the board boots up, the CS is in low level, and so is MISO. That's my question. Here is my .dts file:

    /dts-v1/;
    /plugin/;

    / {
    compatible = "ti,beaglebone", "ti,beaglebone-black";

    /* identification */
    part-number = "spi0pinmux";

    fragment@0 {
    target = <&am33xx_pinmux>;
    __overlay__ {
    spi0_pins_s0: spi0_pins_s0 {
    pinctrl-single,pins = <
    0x150 0x30 /* spi0_sclk, INPUT_PULLUP | MODE0 */
    0x154 0x10 /* spi0_d0, OUTPUT_PULLUP | MODE0 */
    0x158 0x30 /* spi0_d1, INPUT_PULLUP | MODE0 */
    0x15c 0x10 /* spi0_cs0, OUTPUT_PULLUP | MODE0 */
    >;
    };
    };
    };

    fragment@1 {
    target = <&spi0>;
    __overlay__ {
    #address-cells = <1>;
    #size-cells = <0>;

    status = "okay";
    pinctrl-names = "default";
    pinctrl-0 = <&spi0_pins_s0>;
    ti,pindir-d0-out-d1-in = <1>;

    };
    };
    };

    BTW, I removed "spidev" section becuase I want to use my own SPI device driver.

    Is there something wrong?

    Best Regards,

  • Hi,

    Mian Tang said:
    Is there something wrong?

     

    Can you try and remove the ti,pindir-d0-out-d1-in = <1>; part. I don't think it is necessary, since you set 

    0x154 0x10 /* spi0_d0, OUTPUT_PULLUP | MODE0 */
    0x158 0x30 /* spi0_d1, INPUT_PULLUP | MODE0 */

    Could you perform the following test & share the console output:

    1. stop the board at u-boot stage

    2. execute printenv

    This is to verify that your board is set to use the .dtb file that you compile. 

    Can you verify that the pins you mux are NOT used by any other dts node? 

    Best Regards,

    Yordan

  • Hi Yordan,

    I remove the ti,pindir-d0-out-d1-in = <1>; part. And it doesn't work too. And I don't have console output, so I cannot verify it during u-boot stage.

    I checked the timing, and it seems each time the SPI0 chip select hold on low level after the board boots up.
    And if I call my driver do spi write (data could be anything), and after that the chip select comes back to high level.

    Is that a problem?

    All what I did is just update the .dtbo file under /lib/firmware. Basically, I just remove the following for the original file:
    spidev@0 {
    spi-max-frequency = <24000000>;
    reg = <0>;
    compatible = "linux,spidev";
    };

    By removing the above, I can remove spidev from Linux kernel. Then my spi device driver can be installed by insmod.

    Is there any that I can read the SPI registers in user space under linux?

    If you have any other ideas, please let me know.

    Thanks a lot.
  • Hi Yordan,

    It's fixed. Thank you.

    Best Regards,