the difference between /drivers/spi and /drivers/mtd

Luca Ceresoli luca at lucaceresoli.net
Thu Dec 19 05:15:24 EST 2019


Hi Tomek,

On 10/12/19 16:01, Tomek Domek wrote:
> Hi
> I have in device tree node:
> 
> qspi: somename at 0 {
>     compatible = "nameOfDriverFrom/drivers/spi";
>     reg = <someAddr size>;
>     clocks = <reference to clock>;
>     clock-names = "some names";
>     #address-cells = <1>;
>     #size-cells = <0>;
>     status = "disabled";
> };
> 
> and then I have such thing:
> &qspi {
>     pinctrl-names="default";
>     pinctrl-0 = <&reference to some pin controller>;
>     status = "okay";
>     spi-max-frequency = <11000000>;
> 
>     flash at 0 {
>         compatible = "spi-flash (this is driver from /drivers/mtd/)";
>         #address-cells = <1>;
>         #size-cells = <1>;
>         reg = <0x0>;
>         spi-max-frequency = <22000000>;
>      };
> };
> 
> Why just one node isn't enough? And what frequency driver have at all -
> 11MHz or 22MHz?
> What is the difference between drivers defined in /drivers/spi and
> /drivers/mtd?

The qspi node is the Quad SPI master (=controller), i.e. the piece of
hardware, usually in the the SoC, that drives the (Quad) SPI bus.

The flash at 0 node is the flash chip, external to the SoC, it's a SPI
slave that is driven by the SPI master.

Device tree describes the hardware. It is possible that the flash chip
supports up to 22 MHz but the SPI master supports up to 11 MHz. Using
the highest possible speed, 11 MHz in this case, is up to the driver
implementation.

> Does it mean that driver in /drivers/mtd can use somehow driver or the
> code from /drivers/spi?

Yes, absolutely. MTD is a kernel layer to drive memory chips. In order
to reach the memory chip it uses a communication bus. Typical
communication busses for MTD chips include [Quad] SPI, I2C and parallel.

Layering in Linux drivers is absolutely normal. E.g. when you connect a
pendrive to your PC you probably have the mass storage driver use the
USB controller driver, because the pendrive uses USB to connect. And the
USB controller driver uses the PCIe controller driver because the USB
controller is connected to the CPU via PCI express.

-- 
Luca



More information about the Kernelnewbies mailing list