tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Kernel doesn't call spi driver's _match() and _attach()



On Tue Sep 17, 2024 at 12:07 AM MSK, Valery Ushakov wrote:
> On Mon, Sep 16, 2024 at 23:16:18 +0300, Nikita Donskov wrote:
>
> > Spi is configured by default in sys/arch/evbarm/conf/RPI config file nearly
> > the same way, as i2c:
> >         # Broadcom Serial Control (I2C)
> >         bsciic* at fdt?
> >         iic* at i2cbus?
> >         ...
> >
> >         # SPI controller
> >         bcmspi* at fdt?
> >         spi* at spibus?
>
> I don't know much about SPI and FDT (my mental model is that FDT is
> kinda like an externalized OFW device tree :), but the fact that
> bcmspi is not attached might indicate that the FDT blob that you used
> to boot your board doesn't declare that it's there.  You might want to
> cross-check it.
>
> If I'm not mistaken, the sources are in sys/external/gpl2/dts/dist
>
>
> > What I've tried to do is creating /dev/spiu device node manually:
>
> Nodes in /dev are just a way for userland programs to open the devices
> and don't affect the autoconfiguration process in any way.
>
>
> -uwe

Thank you very much, the problem was exactly what you pointed out.  To be
honest, I didn't know anything about FDT before.  Below are the steps I
performed in order to tell kernel about bcmspi existance on evbarm/RPI.
(for those, who are facing the same issue).

* Identify your RPI model. It can be done through dmesg(8):
        $ dmesg | grep Raspberry
        [     1.000000] simplebus0 at armfdt0: Raspberry Pi Model B Rev 2

* Find appropriate FDT blob in /boot/dtb. There are a bunch of blobs for
  different RPI models:
        $ ls /boot/dtb
	bcm2711-rpi-4-b.dtb         bcm2835-rpi-b-rev2.dtb
	bcm2836-rpi-2-b.dtb         bcm2711-rpi-400.dtb
        ...

  Then copy it to some directory in your $HOME in order to safely
manipulate or change this file:
	$ mkdir $HOME/dt
	$ cp /boot/dtb/bcm2835-rpi-b-rev2.dtb $HOME/dt/target.dtb
	$ cd $HOME/dt

* "Decompile" device tree via dtc (doesn't seem to have man page, use `dtc
  -h`):
        $ dtc -I dtb -O dts -o target.dts target.dtb

  dtc will then generate source file target.dts from FDT blob target.dtb.

* Edit source file. In there you'll find mentions of spi, that look like
  this:

        spi@7e2150c0 {
                compatible = "brcm,bcm2835-aux-spi";
                reg = <0x7e2150c0 0x40>;
                interrupts = <0x01 0x1d>;
                clocks = <0x0f 0x02>;
                #address-cells = <0x01>;
                #size-cells = <0x00>;
                status = "disable";
                phandle = <0x4c>;
        };

  Just change `status` from "disable" to "okay" for every spi entry.

* "Recompile" and install new device tree, once you finished editing. Make
  sure to save old FDT blob in case something goes wrong:
        # cp /boot/dtb/bcm2835-rpi-b-rev2.dtb /boot/dtb/bcm2835-rpi-b-rev2.dtb.old
        # dtc -I dts -O dtb -o /boot/dtb/bcm2835-rpi-b-rev2.dtb target.dts
        # echo $?
        0

* Reboot and give it a chance! If everything succeeded, you should now see
  bcmspi is being attached to whatever root bus you have.
        $  dmesg | grep spi
        [     1.000000] bcmspi0 at simplebus1: SPI
        [     1.000000] bcmspi0: interrupting on icu irq 54
        [     1.000000] spi0 at bcmspi0: SPI bus
        [     1.000000] /soc/spi@7e215080 at simplebus1 not configured
        [     1.000000] /soc/spi@7e2150c0 at simplebus1 not configured
        [     1.000000] bcmspi0 at simplebus1: SPI
        [     1.000000] bcmspi0: interrupting on icu irq 54
        [     1.000000] spi0 at bcmspi0: SPI bus
-->     [     1.000000] mydev0 at spi0 slave 0mydev_attach() called.
        [     1.000000] /soc/spi@7e215080 at simplebus1 not configured
        [     1.000000] /soc/spi@7e2150c0 at simplebus1 not configured

And kernel eventually calls mydev_attach()!

-Nikita


Home | Main Index | Thread Index | Old Index