您现在的位置: 主页 > MCU > 单片机技术应用 > 基于S3C2440的嵌入式Linux驱动——SPI子系统解读(一) -
本文所属标签:
为本文创立个标签吧:

基于S3C2440的嵌入式Linux驱动——SPI子系统解读(一) -

来源: 网络用户发布,如有版权联系网管删除 2018-09-06 

[导读]本文将介绍SPI子系统。内核版本为2.6.30。如有错误欢迎指正。预备知识要求:1.SPI总线 2. platfrom平台 3. sysfs子系统 4. 阅读过LDD3第3,5,6,7,9,10,11章的内容。NOTE:如果没有看过LDD3的相关内容,直接看内

本文将介绍SPI子系统。内核版本为2.6.30。如有错误欢迎指正。

本文引用地址: http://www.21ic.com/app/mcu/201807/780965.htm

预备知识要求:1.SPI总线

2. platfrom平台

3. sysfs子系统

4. 阅读过LDD3第3,5,6,7,9,10,11章的内容。

NOTE:如果没有看过LDD3的相关内容,直接看内核源码将非常吃力!!!

PC主机:Ubuntu 和 redhat 9.0

目标板:TQ2440开发板 cpu:s3c2440 linux内核:2.6.30


0.引言

本系列文章对Linux设备模型中的SPI子系统进行讲解。SPI子系统的讲解将分为4个部分。

第一部分,即本篇文章,将对SPI子系统整体进行描述,同时给出SPI的相关数据结构,最后描述SPI总线的注册。

第二部分,该文将对SPI的主控制器(master)驱动进行描述。 基于S3C2440的嵌入式Linux驱动——SPI子系统解读(二)

第三部分,该文将对SPI设备驱动,也称protocol 驱动,进行讲解。基于S3C2440的嵌入式Linux驱动——SPI子系统解读(三)

第四部分,通过SPI设备驱动留给用户层的API,我们将从上到下描述数据是如何通过SPI的protocol 驱动,由bitbang中转,最后由master驱动将数据传输出去。

基于S3C2440的嵌入式Linux驱动——SPI子系统解读(四)

1.SPI子系统综述

SPI子系统从上到下分为:spi设备驱动层,核心层和master驱动层。其中master驱动抽象出spi控制器的相关操作,而spi设备驱动层抽象出了用户空间API。

platform_device结构中描述了SPI控制器的相关资源,同时在板级信息中将会添加spi设备的相关信息。master驱动将以platform_driver形式体现出来,也就是说

在主控制器(master)和主控制器驱动将挂载到platform总线上。platform_driver的probe函数中将注册spi_master,同时将会获取在板级信息中添加的spi设备,将该

信息转换成spi_device,然后注册spi_device到spi总线上。spi_driver结构用于描述spi设备驱动,也将挂载到spi总线上。连同spi_driver一起注册的是字符设备,该

字符设备将提供5个API给用户空间。通过API,用户空间可以执行半双工读、半双工写和全双工读写。

2. SPI的相关数据结构

这里将介绍内核所用到的关键数据结构,还有些结构将在用到时加以说明。

2.1 spi_master

该结构用于描述SOC的SPI控制器,S3C2440共有两个SPI控制器。


/**

*structspi_master-interfacetoSPImastercontroller

*@dev:deviceinterfacetothisdriver

*@bus_num:board-specific(andoftenSOC-specific)identifierfora

*givenSPIcontroller.

*@num_chipselect:chipselectsareusedtodistinguishindividual

*SPIslaves,andarenumberedfromzerotonum_chipselects.

*eachslavehasachipselectsignal,butit'scommonthatnot

*everychipselectisconnectedtoaslave.

*@dma_alignment:SPIcontrollerconstraintonDMAbuffersalignment.

*@setup:updatesthedevicemodeandclockingrecordsusedbya

*device'sSPIcontroller;protocolcodemaycallthis.This

*mustfailifanunrecognizedorunsupportedmodeisrequested.

*It'salwayssafetocallthisunlesstransfersarependingon

*thedevicewhosesettingsarebeingmodified.

*@transfer:addsamessagetothecontroller'stransferqueue.

*@cleanup:freescontroller-specificstate

*

*EachSPImastercontrollercancommunicatewithoneormore@spi_device

*children.Thesemakeasmallbus,sharingMOSI,MISOandSCKsignals

*butnotchipselectsignals.Eachdevicemaybeconfiguredtousea

*differentclockrate,sincethosesharedsignalsareignoredunless

*thechipisselected.

*

*ThedriverforanSPIcontrollermanagesaccesstothosedevicesthrough

*aqueueofspi_messagetransactions,copyingdatabetweenCPUmemoryand

*anSPIslavedevice.Foreachsuchmessageitqueues,itcallsthe

*message'scompletionfunctionwhenthetransactioncompletes.

*/

structspi_master{

structdevicedev;

/*otherthannegative(==assignonedynamically),bus_numisfully

*board-specific.usuallythatsimplifiestobeingSOC-specific.

*example:oneSOChasthreeSPIcontrollers,numbered0..2,

*andoneboard'sschematicsmightshowitusingSPI-2.software

*wouldnormallyusebus_num=2forthatcontroller.

*/

s16bus_num;

/*chipselectswillbeintegraltomanycontrollers;someothers

*mightuseboard-specificGPIOs.

*/

u16num_chipselect;//该值不能为0,否则会注册失败

/*someSPIcontrollersposealignmentrequirementsonDMAable

*buffers;letprotocoldriversknowabouttheserequirements.

*/

u16dma_alignment;

/*Setupmodeandclock,etc(spidrivermaycallmanytimes).

*

*IMPORTANT:thismaybecalledwhentransferstoanother

*deviceareactive.DONOTUPDATESHAREDREGISTERSinways

*whichcouldbreakthosetransfers.

*/

int(*setup)(structspi_device*spi);

/*bidirectionalbulktransfers

*

*+Thetransfer()methodmaynotsleep;itsmainroleis

*justtoaddthemessagetothequeue.

*+Fornowthere'snoremove-from-queueoperation,or

*anyotherrequestmanagement

*+Toagivenspi_device,messagequeueingispurefifo

*

*+Themaster'smainjobistoprocessitsmessagequeue,

*selectingachipthentransferringdata

*+Iftherearemultiplespi_devicechildren,thei/oqueue

* arbitration algorithm is unspecified (round



              查看评论 回复



嵌入式交流网主页 > MCU > 单片机技术应用 > 基于S3C2440的嵌入式Linux驱动——SPI子系统解读(一) -
 

"基于S3C2440的嵌入式Linux驱动——SPI子系统解读(一) -"的相关文章

网站地图

围观()