SPI-------------LINUX----------驅動中的幾個關鍵結構體
阿新 • • 發佈:2019-02-19
struct spi_board_info { char modalias[SPI_NAME_SIZE]; const void * platform_data; void * controller_data; int irq; u32 max_speed_hz; u16 bus_num; u16 chip_select; u16 mode; }; struct spi_board_info info[] = { { .modalias = "spidev", .max_speed_hz = 3000000, .bus_num = 1, .chip_select = 0, //<---使用哪個spi,例如SoC上有兩個spi匯流排,則這裡是選擇第一個 }, { .modalias = "spidev", .max_speed_hz = 3000000, .bus_num = 1, .chip_select = 1, //<---使用哪個spi,例如SoC上有兩個spi匯流排,則這裡是選擇第二個 }, };
</pre><pre name="code" class="cpp">//------------關於mode這個成員變數, 在別的網站找到如下說明(經測試,如果不加.mode後的引數,預設是CS腳是低電平。
SPI_MODE_x說明在:</pre><pre name="code" class="cpp"><p style="margin-top: 0.5em; margin-bottom: 0.5em; line-height: 22.399999618530273px; color: rgb(37, 37, 37); font-family: sans-serif; font-size: 14px;">ome devices expect that the CS lines are active-high (instead of the more common active-low). This can be accomplished by modifying spi_board_info in the board file as follows,</p><pre style="font-family: monospace, Courier; border: 1px solid rgb(221, 221, 221); padding: 1em; line-height: 1.3em; font-size: 14px; background-color: rgb(249, 249, 249);">diff --git a/arch/arm/mach-omap2/board-omap3beagle.c b/arch/arm/mach-omap2/board-omap3beagle.c index 58bacb6..44643b7 100644 --- a/arch/arm/mach-omap2/board-omap3beagle.c +++ b/arch/arm/mach-omap2/board-omap3beagle.c @@ -526,7 +526,7 @@ static struct spi_board_info beagle_mcspi_board_info[] = { .max_speed_hz = 48000000, //48 Mbps .bus_num = 3, .chip_select = 0, - .mode = SPI_MODE_1, + .mode = SPI_MODE_1 | SPI_CS_HIGH, },
或者可以看http://lxr.free-electrons.com/source/include/uapi/linux/spi/spidev.h#L35。