SPI bus (2) SPI subsystem

1. Mode Features

Three lines: SS, CLK, MOSI and MISO are the same data line, half duplex

Four-wire: SS, CLK, MOSI, MISO, full duplex

CPOL: Clock polarity , =0 Low level when the clock is idle =1 High level when the clock is idle

CPHA: Clock Phase , =0 Data will be read on the 1st edge of the clock =1 Data will be read on the 2nd edge of the clock

2. SPI driver model : SPI core layer, SPI host controller layer, SPI (slave) device driver layer.

1. The SPI core
is the link between the SPI controller driver and the device driver. It provides the registration and deregistration methods of the SPI controller driver and the device driver.
2. The SPI bus driver
implements the driver to the controller.
3. The SPI device
driver implements the driver implementation of the SPI slave device, such as spi flash

1. SPI core layer

1.1 Related files: devices/spi/spi.c, include/linux/spi/spi.h

1.2 Function

1) Provides registration and deregistration methods for SPI bus drivers and device drivers.

2) Enable the SPI device driver to access the methods and functions used to transfer data to the SPI bus provided by the SPI controller driver

1.3 SPI Controller Layer Interface

//Allocate the spi_master structure
struct spi_master *spi_alloc_master(struct device *dev, unsigned size)

//Register the spi_master structure
int spi_register_master(struct spi_master *master)

//Log out the spi_master structure
void spi_unregister_master(struct spi_master *master)
1.3 SPI device driver layer interface
// Assign the spi_driver structure to the spi bus
int spi_register_driver(struct spi_driver *sdrv)

// Log out of the spi_driver bus
static inline void spi_unregister_driver(struct spi_driver *sdrv)

//Allocate and add the spi_device structure to the spi bus;
struct spi_device *spi_new_device(struct spi_master *master, struct spi_board_info *chip)
1.4 Build the spi bus (already done in the kernel)
static int __init spi_init(void)
{
    int    status;

    buf = kmalloc(SPI_BUFSIZ, GFP_KERNEL);
    if (!buf) {
        status = -ENOMEM;
        goto err0;
    }

    status = bus_register(&spi_bus_type);
    if (status < 0)
        goto err1;

    status = class_register(&spi_master_class);
    if (status < 0)
        goto err2;
    return 0;

err2:
    bus_unregister(&spi_bus_type);
err1:
    kfree(buf);
    buf = NULL;
err0:
    return status;
}

postcore_initcall(spi_init);
2. SPI host controller layer construction (based on platform bus)

struct spi_master: master controller interface, used to describe the controller driver


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325731321&siteId=291194637
SPI