2.2 spi_device
该结构用于描述SPI设备,也就是从设备的相关信息。
NOTE:SPI子系统只支持主模式,也就是说S3C2440的SPI只能工作在master模式,外围设备只能为slave模式。
- /**
- * struct spi_device - Master side proxy for an SPI slave device
- * @dev: Driver model representation of the device.
- * @master: SPI controller used with the device.
- * @max_speed_hz: Maximum clock rate to be used with this chip
- * (on this board); may be changed by the device's driver.
- * The spi_transfer.speed_hz can override this for each transfer.
- * @chip_select: Chipselect, distinguishing chips handled by @master.
- * @mode: The spi mode defines how data is clocked out and in.
- * This may be changed by the device's driver.
- * The "active low" default for chipselect mode can be overridden
- * (by specifying SPI_CS_HIGH) as can the "MSB first" default for
- * each word in a transfer (by specifying SPI_LSB_FIRST).
- * @bits_per_word: Data transfers involve one or more words; word sizes
- * like eight or 12 bits are common. In-memory wordsizes are
- * powers of two bytes (e.g. 20 bit samples use 32 bits).
- * This may be changed by the device's driver, or left at the
- * default (0) indicating protocol words are eight bit bytes.
- * The spi_transfer.bits_per_word can override this for each transfer.
- * @irq: Negative, or the number passed to request_irq() to receive
- * interrupts from this device.
- * @controller_state: Controller's runtime state
- * @controller_data: Board-specific definitions for controller, such as
- * FIFO initialization parameters; from board_info.controller_data
- * @modalias: Name of the driver to use with this device, or an alias
- * for that name. This appears in the sysfs "modalias" attribute
- * for driver coldplugging, and in uevents used for hotplugging
- *
- * A @spi_device is used to interchange data between an SPI slave
- * (usually a discrete chip) and CPU memory.
- *
- * In @dev, the platform_data is used to hold information about this
- * device that's meaningful to the device's protocol driver, but not
- * to its controller. One example might be an identifier for a chip
- * variant with slightly different functionality; another might be
- * information about how this particular board wires the chip's pins.
- */
- struct spi_device {
- struct device dev;
- struct spi_master *master;
- u32 max_speed_hz;
- u8 chip_select;
- u8 mode;
- #define SPI_CPHA 0x01 /* clock phase */
- #define SPI_CPOL 0x02 /* clock polarity */
- #define SPI_MODE_0 (0|0) /* (original MicroWire) */
- #define SPI_MODE_1 (0|SPI_CPHA)
- #define SPI_MODE_2 (SPI_CPOL|0)
- #define SPI_MODE_3 (SPI_CPOL|SPI_CPHA)
- #define SPI_CS_HIGH 0x04 /* chipselect active high? */
- #define SPI_LSB_FIRST 0x08 /* per-word bits-on-wire */
- #define SPI_3WIRE 0x10 /* SI/SO signals shared */
- #define SPI_LOOP 0x20 /* loopback mode */
- u8 bits_per_word;
- int irq;
- void *controller_state;
- void *controller_data;
- char modalias[32];
- /*
- * likely need more hooks for more protocol options affecting how
- * the controller talks to each chip, like:
- * - memory packing (12 bit samples into low bits, others zeroed)
- * - priority
- * - drop chipselect after each word
- * - chipselect delays
- * - ...
- */
- };
2.3 spi_board_info
该结构也是对从设备的描述,只不过它是板级信息,最终该结构的所有信息将复制给spi_device。
- * INTERFACE between board init code and SPI infrastructure.
- *
- * No SPI driver ever sees these SPI device table segments, but
- * it's how the SPI core (or adapters that get hotplugged) grows
- * the driver model tree.
- *
- * As a rule, SPI devices can't be probed. Instead, board init code
- * provides a table listing the devices which are present, with enough
- * information to bind and set up the device's driver. There's basic
- * support for nonstatic configurations too; enough to handle adding
- * parport adapters, or microcontrollers acting as USB-to-SPI bridges.
- */
- /**
- * struct spi_board_info - board-specific template for a SPI device
- * @modalias: Initializes spi_device.modalias; identifies the driver.
- * @platform_data: Initializes spi_device.platform_data; the particular
- * data stored there is driver-specific.
- * @controller_data: Initializes spi_device.controller_data; some
- * controllers need hints about hardware setup, e.g. for DMA.
- * @irq: Initializes spi_device.irq; depends on how the board is wired.
- * @max_speed_hz: Initializes spi_device.max_speed_hz; based on limits
- * from the chip datasheet and board-specific signal quality issues.
- * @bus_num: Identifies which spi_master parents the spi_device; unused
- * by spi_new_device(), and otherwise depends on board wiring.
- * @chip_select: Initializes spi_device.chip_select; depends on how
- * the board is wired.
- * @mode: Initializes spi_device.mode; based on the chip datasheet, board
- * wiring (some devices support both 3WIRE and standard modes), and
- * possibly presence of an inverter in the chipselect path.
- *
- * When adding new SPI devices to the device tree, these structures serve
- * as a partial device template. They hold information which can't always
- * be determined by drivers. Information that probe() can establish (such
- * as the default transfer wordsize) is not included here.
- *
- * These structures are used in two places. Their primary role is to
- * be stored in tables of board-specific device descriptors, which are
- * declared early in board initialization and then used (much later) to
- * populate a controller's device tree after the that controller's driver
- * initializes. A secondary (and atypical) role is as a parameter to
- * spi_new_device() call, which happens after those controller drivers
- * are active in some dynamic board configuration models.
- */
- struct spi_board_info {
- /* the device name and module name are coupled, like platform_bus;
- * "modalias" is normally the driver name.
- *
- * platform_data goes to spi_device.dev.platform_data,
- * controller_data goes to spi_device.controller_data,
- * irq is copied too
- */
- char modalias[32];
- const void *platform_data;
- void *controller_data;
- int irq;
- /* slower signaling on noisy or low voltage boards */
- u32 max_speed_hz;
- /* bus_num is board specific and matches the bus_num of some
- * spi_master that will probably be registered later.
- *
- * chip_select reflects how this chip is wired to that master;
- * it's less than num_chipselect.
- */
- u16 bus_num;
- u16 chip_select;
- /* mode becomes spi_device.mode, and is essential for chips
- * where the default of SPI_CS_HIGH = 0 is wrong.
- */
- u8 mode;
- /* ... may need additional spi_device chip config data here.
- * avoid stuff protocol drivers can set; but include stuff
- * needed to behave without being bound to a driver:
- * - quirks like clock rate mattering when not selected
- */
- };
2.4 spi_driver
该结构用于描述SPI设备驱动。驱动核心将根据driver.name和spi_board_info 的modalias进行匹配,如过modalia和name相等,则绑定驱动程序和SPI设备。
- /**
- * struct spi_driver - Host side "protocol" driver
- * @probe: Binds this driver to the spi device. Drivers can verify
- * that the device is actually present, and may need to configure
- * characteristics (such as bits_per_word) which weren't needed for
- * the initial configuration done during system setup.
- * @remove: Unbinds this driver from the spi device
- * @shutdown: Standard shutdown callback used during system state
- * transitions such as powerdown/halt and kexec
- * @suspend: Standard suspend callback used during system state transitions
- * @resume: Standard resume callback used during system state transitions
- * @driver: SPI device drivers should initialize the name and owner
- * field of this structure.
- *
- * This represents the kind of device driver that uses SPI messages to
- * interact with the hardware at the other end of a SPI link. It's called
- * a "protocol" driver because it works through messages rather than talking
- * directly to SPI hardware (which is what the underlying SPI controller
- * driver does to pass those messages). These protocols are defined in the
- * specification for the device(s) supported by the driver.
- *
- * As a rule, those device protocols represent the lowest level interface
- * supported by a driver, and it will support upper level interfaces too.
- * Examples of such upper levels include frameworks like MTD, networking,
- * MMC, RTC, filesystem character device nodes, and hardware monitoring.
- */
- struct spi_driver {
- int (*probe)(struct spi_device *spi);
- int (*remove)(struct spi_device *spi);
- void (*shutdown)(struct spi_device *spi);
- int (*suspend)(struct spi_device *spi, pm_message_t mesg);
- int (*resume)(struct spi_device *spi);
- struct device_driver driver;
- };
