SPI驅(qū)動(dòng)的移植
-> Device Drivers
-> SPI support
SPI support
*** SPI Master Controller Drivers ***
-*- Bitbanging SPI master
<*> Samsung S3C24XX series SPI
< > Samsung S3C24XX series SPI by GPIO
*** SPI Protocol Masters ***
< > SPI EEPROMs from most vendors
<*> User mode SPI device driver support
< > Infineon TLE62X0 (for power switching)
選擇SPI support 是使Linux內(nèi)核提供SPI 支持,選擇該選項(xiàng)會(huì)默認(rèn)選擇Bitbanging SPImaster,還需選擇SamsungS3C24XX series SPI,告訴內(nèi)核使用S3C2440A的SPI 控制器驅(qū)動(dòng)。
首先在 devs.c中,增加板子信息
- /* 2009/06/30 jwpan add by spi begin */
- static struct spi_board_info s3c2410_spi0_board[] = {
- [0] = {
- .modalias = "spidev", /*跟spidev.ko驅(qū)動(dòng)名要相同,不然掛載不上*/
- .platform_data = NULL,
- .bus_num = 0, /*使用的第一條BUS線,2410支持0,1兩根*/
- .chip_select = 1, /*片選信號(hào),和上面結(jié)合,在/dev 里面可以看到spidev0.1*/
- .max_speed_hz = 500*1000, /CLK頻率*/
- },
- };
- static struct s3c2410_spi_info s3c2410_spi0_platdata = {
- .pin_cs = S3C2410_GPB1,
- .board_info = s3c2410_spi0_board,
- .board_size = ARRAY_SIZE(s3c2410_spi0_board),
- };
- /* 2009/06/30 jwpan add by spi end */
- struct platform_device s3c_device_spi0 = {
- .name = "s3c2410-spi",
- .id = 0,
- .num_resources = ARRAY_SIZE(s3c_spi0_resource),
- .resource = s3c_spi0_resource,
- .dev = {
- .dma_mask = &s3c_device_spi0_dmamask,
- /* 2009/06/30 jwpan add by spi begin */
- //.coherent_dma_mask = 0xffffffffUL
- .coherent_dma_mask = 0xffffffffUL,
- .platform_data = &s3c2410_spi0_platdata,
- /* 2009/06/30 jwpan add by spi end */
- }
- };
- static struct platform_device __initdata *smdk_devs[] = {
- &s3c_device_nand,
- &smdk_led4,
- &smdk_led5,
- &smdk_led6,
- &smdk_led7,
- /* 2009/06/30 jwpan add by dm9000 spi begin */
- &s3c_device_spi0,
- /* 2009/06/30 jwpan add by dm9000 spi end */
- };
- if(master->num_chipselect == 0)
- return -EINVAL;
萬萬沒有想到,這個(gè)值就是沒有初始化.
需要在spi_s3c24xx.c里面增加一句代碼:
- hw->bitbang.txrx_bufs = s3c24xx_spi_txrx;
- hw->bitbang.master->num_chipselect = 2;/* add */
- dev_dbg(hw->dev,"bitbang at %pn",hw->bitbang);
- //if (chip->chip_select >= master->num_chipselect) {
- if (chip->chip_select > master->num_chipselect) {
之后,就可以使用spidev_test ,spidev_fdx程序進(jìn)行測(cè)試了,這兩個(gè)文件在linux2.6.30的Documentation/Spi目錄下面有。
最后,提示一下:
I2C/SPI支持“線與”,允許多個(gè)設(shè)備互連。所以協(xié)議規(guī)定:在無數(shù)據(jù)傳輸(開始前、結(jié)束后)時(shí),時(shí)鐘和數(shù)據(jù)線都處于“釋放”狀態(tài),也就是“高阻”狀態(tài)。
在“釋放”狀態(tài),如果有上拉電阻(內(nèi)部或外部的),用外用表測(cè)會(huì)是高電平(1);如果沒有上拉電阻,用萬用表測(cè)是低電平(0)。
簡單一點(diǎn)就是說:SPI的CLK只有在有數(shù)據(jù)通信時(shí),才會(huì)測(cè)得出波形,千萬別以為SPI出問題了。
評(píng)論