Você está na página 1de 20

katix.

org
Katix Embedded Linux SPI subsystem 1
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
Katix Embedded Linux SPI
Subsystem description
Change history
'ersion Date Author (omments
#!#!1 #$%1#%#& Kate Alhola initial dra)t
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem +
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
Table of Contents
Introduction!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$
-erms. acronyms and abbreviations!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem $
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
Overvie
Introduction
Linux SPI subsystem is desi"ned to makin" "eneric pro"rammin" )rame/ork )or
various peripherals /ith SPI inter)ace! It is derived )rom I+( subsystem /ith lot o) SPI
speci)ic additions! Desi"n is divided in )our layers. cpu architecture independent
tar"et driver and spi subsystem. spi controller device speci)ic spi al"orithm layers and
board speci)ic spi adapter layer! Above SPI subsystem layer there is various tar"et
drivers that inter)aces to upper level subsystems dependin" o) their type! As example
SPI011( driver inter)aces to 11( subsystem and SPI0touch screen inter)aces to 2ID
subsystem!
SPI subsystem contais derived codes )rom 3ri"inal un)inished SPI subsystem )rom
Hamey Hicks. I+( subsystem )rom Simon G. Vogl. Denx PP( linux )rom Wolfgang
Denk
License
-his pro"ram is )ree so)t/are4 you can redistribute it and%or modi)y it under the
terms o) the G56 General Public License as published by the 7ree So)t/are
7oundation4 either version + o) the License. or 8at your option9 any later version!
-his pro"ram is distributed in the hope that it /ill be use)ul. but :I-236- A5;
:A<<A5-;4 /ithout even the implied /arranty o) 1E<(2A5-A=ILI-; or 7I-5ESS
73< A PA<-I(6LA< P6<P3SE! See the G56 General Public License )or more details!
;ou should have received a copy o) the G56 General Public License alon" /ith this
pro"ram4 i) not. /rite to the 7ree So)t/are 7oundation. Inc!. >?@ 1ass Ave.
(ambrid"e. 1A #+1$A. 6SA! his pro"ram is licensed under the terms o) the
G56 General Public License version +! -his pro"ram is licensed Bas isB /ithout any
/arranty o) any kind. /hether express or implied!
Terms! acronyms and abbreviations
-erm Explanation
SPI Serial Peripheral Inter)ace
I+( Inter I( bus
PS( 1P(@+## Pro"rammable Serial (ontroller
11( 1ultimedia (ard
2ID 2uman Inter)ace Device
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem &
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
-erm Explanation
SPI (lient SPI tar"et driver utiliCin" SPI subsystem
SPI Driver SPI inter)ace driver
SPI Adapter SPI adapter that contains SPI Inter)ace and chip
select lo"ic
SPI tar"et SPI connected periphereal like A%D converter
"eferences
<e) ID. Document 5ame. Author. 'ersion Location % :eblink
#rchitecture
Subsystem level architecture
SPI Subsystem dia"ram
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem @
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
Interfaces
Interfaces used
LinuxKernel API
Interfaces provided
%proc )ilesystem
%dev%spi
SPI subsystem API
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem >
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
$ependencies
Scenarios
Linux SPI subsystem initiali%ation se&uence

Principles of operation
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem ?
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
SPI 8synchronous Peripheral Inter)ace 9 is bi0directional )ull duplex data trans)er /ith
separate bit and )rame synchroniCation si"nals!
Data is trans)erred via t/o unidirectional data lines called 1IS3 8 1aster In Slave 3ut
9 and 13SI 8 1aster 3ut Slave In 9! 1osi is sometimes called in master SD3 8 Serial
Data 3ut 9 and 1IS3 called as SDI 8 Serial DataIn 9! 13SI is al/ays driven by master
and is al/ays input in slaves! 1IS3 is al/ays input in master and it is three state
si"nal in slaves! 3nly slave addressed /ith its representative (S si"nal asserted /ill
drive 1IS3 ! SPI trans)er has al/ays read 8 1IS3 9 and /rite 8 13SI 9 si"nals an
al/ays operate as simultaneous )ull duplex data trans)er! I case /e have simple :rite
only devices like simple di"ital%analo" converters 8 DA( 9 that have only 13SI si"nal.
the master still samples 1IS3 si"nal and reads meani"less data that should be
discarded! Similary /ith input only devices. master still trans)ers data out )rom 13SI
si"nal but it is i"nored or not connected to slave device!
=it clockin" and synchroniCation is provided /ith S(LK si"nal! S(LK is 53- )ree
runnin" clock. it is "ated clock and it is "ated /ith data trans)er! S(LK is al/ays
driven by master!
-rans)erred )rames are synchroniCed /ith (S 8 (hip Select si"nals 9! (S lines are
al/ays driven by master! 5ormally there is least one but not al/ays Dust one separate
(S si"nal per tar"et device! (hip select si"nals does double )unction! It /orks as
tar"et device select issued by master and also /orks as )rame synchroniCation si"nal!
I case that master needs to send successive trans)ers to same slave. it /ill indicate it
releasin" and assertin" (S line bet/een )rames!
Chip Select handling
SPI "reatly di))ers )rom other peripheral busses like I+(. 6S=. Sin"le /ire etc by
tar"et selection lo"ic! 3ther busses use tar"et address trans)erred at be"innin" o) the
)rame!SPI uses dedicated (hip Select lines that )unctions as both tar"et select and
)rame synchroniCation lines! Every tar"et has itEs dedicated uniFue (S line that
indicates that )rame is intended )or it and /here )rame be"ins and ends!
Even di))erent boards utiliCin" same processor 8 or SPI inter)ace 9 circuit. the schip
select lines may be implemented completelly di))erent /ay! 7or this reason the actual
SPI inter)ace driver 8 spi0al"o0xxxx9 is separated )rom board inter)ace drivr like spi0
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem G
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
iti@+##9! SPI tar"et drivers 8 spi clients 9 are completelly independent to lo/er SPI
subsystem layer implementation as they are in I+( subsystem! Di))erence to I+( is
that every spi client must be able to attach itEs tar"et and itEs dedicated chip select
line! As /e kno/. same type tar"et 8 like tsc+$#1 or 11( card 9 may be connected in
di))erent boards to completelly di))erent chip select lines! Also. in SPI there is no
hard/are method to identi)y tar"et type!
-o met these desi"n criterias )ollo/in" chip select handlin" is implemented to Linux
SPI subsystem!
Every SPI board driver has chip select assi"ment table struct spi_cs that contains
names and assi"ned numbers o) (S lines! SPI subsystem spi0core o))ers )unctions
spi_get_named_cs and spi_get_cs )or clients to locate tar"et chips and thei chip
select lines!
Chip select behavior
-here is also a lot o) di))erence chip select behavior bet/en tar"ets! Simples /ay is
basic Spi method like used in )ollo/in" tsc+$#1 example! In basic method there is one
lo/ active chip select that is asserted in be"innin" o) )rame and is released in end o)
)rame! 1ore complicated handlin" is in )ollo/in" 11( and L(D examples! :ith 11(
there is be)ore actual )rame. initial clock pulses /ithout (S asserted and then
command. /ait and data phases all /ithout releasin" (S bet/een them! 11( need
that )irst dummy )rame is "iven /ithout assertin" (S and then command )rame is
"iven /ithout releasin" chip select a)ter it! -hen undetermined number o) status read
)rames /hen (S remains asserted and )inally data trans)er phase! -he (S is released
a)ter all these phases!
L(D 8 )or displaytech and similar L(D displays 9 has similar behavior that it also has
multiple phases /ith (S asserted but di))ers )rom 11( that it has t/o chip select
lines. one is actual chip select and other is command%data select!

#pplication examples
Simple user level program ith direct access to SPI target via '
dev'spi interface(
In this example /e )irst )orm spi messa"e struct spi_msg that contains data to be
trans)erred and read results. tar"et chip select address and trans)er mode read
8SPI_M_D9 and%or /rite 8SPI_M_W9! SpiHms" can contain multiple messa"es
/ith all o/n chip select si"nalin". data bu))ers. read%/rite mode etc! As a special case
devices that have non0standard chip0select behavior can use Cero0len"th messa"es
Dust )or handlin" chip select si"nal! As example some output only shi)t re"isters does
not have normal chip select but instead have one that should be pulsed a)ter data
trans)er! In this example /e are usin" normal SPI behavior! :e send data out tcat
contains command to tar"et device and read itEs response!
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem A
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
struct spi_rd!r_ioctl_data is used to pass spi_msg as a parameter to spi ioctl
command!
In be"innin" o) actual code /e open "de#"spi$ device to "et access )rom userland
pro"ram to kernel mode spi subsystem! A)ter /e have opened spi device. /e can use
ioctl system call to pass commands to spi subsystem! 5ormally /hen /e like to use
simultaneous read%/rite or multiple spi messa"es or other spi special )eatures /e
need to use most )lexible /ay. ioctl! In case /e need to do Dust simple read /ithout
/ritin" or /rite /ithout read /e can use normal read and /rite system calls!
#include <linux/spi/spi.h>
#define DEV_SPI "/dev/spi0" /* Create device with 'mknod /dev/spi0 c 228 0' */
#define LEN 10
/* Trasfer one message via SPI */
int spi_xfer(char addr, char offset, char *buf, int len)
{
struct spi_msg msgs[] = {
{ addr: addr, flags: SPI_M_RD| SPI_M_WR, len: len, buf: buf }
};
struct spi_rdwr_ioctl_data data = { msgs: msgs, nmsgs: 1 };
int fd;
if ((fd = open(DEV_SPI, O_RDWR)) < 0) {
perror(DEV_SPI " open");
return -1;
}
if (ioctl(fd, SPI_RDWR, &data) < 0) {
perror(DEV_SPI " ioctl");
return -1;
}
close(fd);
return 0;
}
TSC)*+, example
7ollo/in" example demonstrates ho/ to access iti%&$$ board 'S(&)$* system
codec AD( )rom user space process /ith %dev%spi inter)ace! -he tsc+$#1read and
tsc+$#1/rite )unctions are Dust made to easier access tsc+$#1 re"isters! In this
example all tsc+$#1 re"isters are acessed usin" $+ bit spi )rame containin" 1> bit
command and 1> bit data!
1@ 1& 1$ 1+ 11 1# A G ? > @ & $ + 1 #
<%:I
# #
p"
1
p"
#
addr
@
addr
&
addr
$
addr
+
addr
1
addr
#
x x x x x
-he tsc+$#1read and tsc+$#1/rite )unctions build $+ bit spi )rame )rom parameters
and send it usin" spiHx)er )unction to spi device! -S(+$#1read )unction sends 1> bit
data part o) )rame as Cero and then in return it returns value read )rom spi!
<eader should notice that no in)ormation about is this command device read or /rite
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem 1#
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
is "iven to spiHx)er )unction! SPI x)er passes all )rames as read%/rite attributes to spi
driver! I) operation is /rite. the returned )rame is Dust not used! In read the tsc+$#1
chip Dust uses )irst bit o) command to see that operation is read and it should pass
output data a)ter command /ord and discards all data a)ter read command! -he
dummy /ritedata is still mandatory to "ive to the device because in spi readin" is
only possible /hen bit clock pulses are "iven )or this dummy data!
void tsc2301write(int addr,int pg,int reg,unsigned short val)
{
unsigned short buf[6]={0,0,0,0,0,0};
buf[0]=(pg<<11) | (reg << 5);
buf[1]=val;
hexdump((unsigned char*)buf,4);
spi_xfer(0,(unsigned char *)buf,4);
}

int tsc2301read(int addr,int pg,int reg)
{
unsigned short buf[6]={0,0,0,0,0,0};
buf[0]=0x8000 | (pg<<11) | (reg << 5);
spi_xfer(0,(unsigned char *)buf,4);
hexdump((unsigned char *)buf,4);
return(buf[1]);
}
#define VREF 1.2
int main(int argc, char* argv[])
{
unsigned short buf[256]={0x8000,0x2f30,0,0,0};
float bat1,bat2,aux1,aux2;

tsc2301write(0,1,3,0x1000); /* bank1 reg 3 Ref int 1.2v */
tsc2301write(0,1,0,0x2f30); /* bank1 reg 0,scan bat1,bat2,aux1,aux2,12bit,1MHz int
clock */
bat1=VREF*tsc2301read(0,0,5)/4096*20*4; /* bat 1 voltage divider 1/80*/
bat2=VREF*tsc2301read(0,0,6)/4096; /* bat 2 */
aux1=VREF*tsc2301read(0,0,7)/4096; /* aux 1 */
aux2=VREF*tsc2301read(0,0,8)/4096; /* aux 2 */
printf("bat1=%f bat2=%f aux1=%f aux2=%f\n",bat1,bat2,aux1,aux2);
return 0;
}
<unnin" our example ! 5otice that only bat1 is connected to measure board input
volta"e. other AD( inputs are )loatin"!
bash-2.05b# /tmp/tsc2301
08 60 10 00 .`..
08 00 2f 30 ../0
ff ff 02 10 ....
ff ff 00 05 ....
ff ff 04 43 ...C
ff ff 05 9f ....
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem 11
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
bat1=12.375000 bat2=0.001465 aux1=0.319629 aux2=0.421582
-rame list example
-o make more optimiCed application there is possible to do everytihin" in that /as in
previous application done /ith multiple SPI ioctl calls /ith one SPI ioctl call /ith
multiple messa"e list! 6sin" sin"le call /e "et only one call overhead but )ot result
may not be as easy to read! 5ext example demonstrates ho/ to do it!
In multiple messa"e list extensive care should be taken )or (S operations bet/een
)rames! I) (S is not ne"ated bet/een )rames. all )rames are typically considered by
devices same as one concatenated )rame! I) they are liked to be treated as separate
)rames they should be marked so that (S is ne"ated bet/een )rames!
In some rare cases special chip select behavior is needed like /ith SPI L(D display
/here other (S is used as (ommand%Data selector and so needs to be to""led
bet/een command and data part /hen actual chip select is kept asserted! 3ther case
is some AD( chips and shi)t re"isters that does have load strobe instead o) chip
select!
Internal design
SPI subsystem is divided to )ollo/in" main modules,
10 SPI0(ore
SPI core is responsible as brooker and device inter)ace )unctions bet/een clients.
drivers and adapters! :hen ne/ inter)ace is added to system.
-unctional description
spi0core!c 7ile <e)erence
SPI 8 Serial Periphereal Inter)ace 9 subsystem core module! -his module is
responsible to re"isterin" and controllin" spi al"orithm drivers. adapters and tar"et
drivers! 1ore!!!
#include <linux/module.h>
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/proc_fs.h>
#include <linux/kmod.h>
#include <linux/init.h>
#include <linux/spi/spi.h>
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem 1+
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
#include <asm/uaccess.h>
Include dependency "raph )or spi0core!c,
-unctions
int spiHaddHadapter 8struct spiHadapter Iadap9

1ake the adapter available )or use by clients usin" name adap0Jname! -he adap0Jadapters list
is initialised by this )unction!
int spiHdelHadapter 8struct spiHadapter Iadap9
<emove an adapter )rom the list o) available SPI =us adapters!
spiHadapter
I spiH"etHadapter 8const char Iname9

3btain a spiHadapter structure )or the speci)ied adapter! I) the adapter is not currently load.
then load it! -he adapter /ill be locked in core until all re)erences are released via
spiHputHadapter!
void spiHputHadapter 8struct spiHadapter Iadap9
int spiHaddHdriver 8struct spiHdriver Idriver9
int spiHdelHdriver 8struct spiHdriver Idriver9
spiHdriver I spiH"etHdriver 8const char Iname9
void spiHputHdriver 8struct spiHdriver Idrv9
int spiHattachHclient 8struct spiHclient Iclient. const char Iadap. const char Idrv9
int spiHdetachHclient 8struct spiHclient Iclient9
int spiHtrans)er 8struct spiHadapter Iadap. struct spiHms" ms"sKL. int num9
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem 1$
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
int spiH/rite 8struct spiHclient Iclient. int addr. const char Ibu). int len9
int spiHread 8struct spiHclient Iclient. int addr. char Ibu). int len9
int spiHadapterHid 8struct spiHadapter Iadap9
+,P-'_S.M/-0 8spiHaddHadapter9
+,P-'_S.M/-0 8spiHdelHadapter9
+,P-'_S.M/-0 8spiH"etHadapter9
+,P-'_S.M/-0 8spiHputHadapter9
+,P-'_S.M/-0 8spiHaddHdriver9
+,P-'_S.M/-0 8spiHdelHdriver9
+,P-'_S.M/-0 8spiH"etHdriver9
+,P-'_S.M/-0 8spiHputHdriver9
+,P-'_S.M/-0 8spiHattachHclient9
+,P-'_S.M/-0 8spiHdetachHclient9
+,P-'_S.M/-0 8spiHtrans)er9
+,P-'_S.M/-0 8spiH/rite9
+,P-'_S.M/-0 8spiHread9
M-D10+_0I(+2S+ 8BGPLB9
M-D10+_31'H- 8BKate Alhola kate8at9 katix!or"B9
M-D10+_D+S(IP'I-2 8BSPI0=us main moduleB9
$etailed $escription
SPI 8 Serial Periphereal Inter)ace 9 subsystem core module! -his module is
responsible to re"isterin" and controllin" spi al"orithm drivers. adapters and tar"et
drivers!
-unction $ocumentation
int spiHadapterHid8 struct spiHadapter
I
adap 9

spiHadapterHid -his call returns a uniFue lo/ identi)ier )or each re"istered
adapter
Parameters4
adap:spi_adapter
eturns4
uniFue id or 01 i) the adapter /as not re"istered!
int spiHaddHadapter8 struct spiHadapter
I
adap 9
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem 1&
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public

1ake the adapter available )or use by clients usin" name adap0Jname! -he adap0Jadapters list is initialised
by this )unction!
spiHaddHadapter 0 re"ister a ne/ SPI bus adapter
Parameters4
adap: spiHadapter structure )or the re"isterin"
adapter
eturns4
#4
int spiHaddHdriver 8 struct spiHdriver
I
driver 9

spiHaddHdriver 0 re"ister a ne/ SPI device driver
Parameters4
driver 0 driver structure to make
available
1ake the driver available )or use by clients usin" name driver0Jname! -he driver0Jdrivers list is initialised
by this )unction!
<eturns #4
int
spiHattachHclient
8 struct spiHclient
I
client.
const char I adap.
const char I drv
9

spiHattachHclient 0 attach a client to an adapter and driver
Parameters4
client: client structure to
attach
adap: adapter 8module9 name
drv: driver 8module9 name
Attempt to attach a client 8a user o) a device driver9 to a particular driver and adapter! I) the speci)ied driver
or adapter arenEt re"istered. reFuestHmodule is used to load the relevant modules!
<eturns # on success. or ne"ative error code!
2ere is the call "raph )or this )unction,
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem 1@
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
int spiHdelHadapter8 struct spiHadapter
I
adap 9

<emove an adapter )rom the list o) available SPI =us
adapters!
spiHdelHadapter 0 unre"ister a SPI bus adapter
Parameters4
adap: spiHadapter structure to
unre"ister
eturns4
#4
int spiHdelHdriver 8 struct spiHdriver
I
driver 9

spiHdelHdriver 0 unre"ister a SPI device driver
Parameters4
driver: driver to remove
<emove an driver )rom the list o) available SPI =us device
drivers!
<eturns #4
int
spiHdetachHclient
8 struct spiHclient
I
client 9

spiHdetachHclient 0 detach a client )rom an adapter and
driver
Parameters4
client: client structure to
detach
Detach the client )rom the adapter and driver!
2ere is the call "raph )or this )unction,
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem 1>
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
struct spiHadapterI
spiH"etHadapter
8 const char
I
name 9

3btain a spiHadapter structure )or the speci)ied adapter! I) the adapter is not currently load. then load it! -he
adapter /ill be locked in core until all re)erences are released via spiHputHadapter!
spiH"etHadapter 0 "et a re)erence to an adapter
Parameters4
name: driver name
eturns4
pointer to spiHadapter struct or 56LL i) no adapter )ound
struct spiHdriverI
spiH"etHdriver
8 const char
I
name 9

spiH"etHdriver 0 "et a re)erence to a driver
Parameters4
name: driver name
3btain a spiHdriver structure )or the speci)ied driver! I) the driver is not currently load. then load it! -he
driver /ill be locked in core until all re)erences are released via spiHputHdriver!
void spiHputHadapter 8 struct spiHadapter
I
adap 9

spiHputHadapter 0 release a re)erence to an adapter
Parameters4
adap: driver to release re)erence
Indicate to the SPI core that you no lon"er reFuire the adapter re)erence! -he adapter module may be
unloaded /hen there are no re)erences to its data structure!
;ou must not use the re)erence a)ter callin" this )unction!
void spiHputHdriver 8 struct spiHdriver
I
drv 9

spiHputHdriver 0 release a re)erence to a driver
Parameters4
drv: driver to release re)erence
Indicate to the SPI core that you no lon"er reFuire the driver re)erence! -he driver module may be unloaded
/hen there are no re)erences to its data structure!
;ou must not use the re)erence a)ter callin" this )unction!
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem 1?
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
int spiHread8 struct spiHclient
I
client.
int addr.
char I buf.
int len
9

spiHread 0 receive data )rom a device on an SPI bus
Parameters4
client: re"istered client structure
addr: SPI bus address
buf: bu))er )or bytes to receive
len: number o) bytes to receive
<eceive len bytes )rom device address addr on the SPI bus described by client to a bu))er pointed to by
bu)!
<eturns the number o) bytes trans)erred. or ne"ative error code!
2ere is the call "raph )or this )unction,
int
spiHtrans)er
8 struct spiHadapter
I
adap.
struct spiHms" msgsKL.
int num
9

spiHtrans)er 0 trans)er in)ormation on an SPI bus
Parameters4
adap: adapter structure to per)orm trans)er on
msgs: array o) spiHms" structures describin"
trans)er
num: number o) spiHms" structures
-rans)er the speci)ied messa"es to%)rom a device on the SPI bus!
<eturns number o) messa"es success)ully trans)erred. other/ise ne"ative error
code!
int spiH/rite8 struct spiHclient
I
client.
int addr.
const char I buf.
int len
9
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem 1G
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public

spiH/rite 0 send data to a device on an SPI bus
Parameters4
client: re"istered client structure
addr: SPI bus address
buf: bu))er )or bytes to send
len: number o) bytes to send
Send len bytes pointed to by bu) to device address addr on the SPI bus described by
client!
eturns4
the number o) bytes trans)erred. or ne"ative error code!
2ere is the call "raph )or this )unction,
spi.iti/)++(c -ile "eference
SPI adapter driver )or iti@+## board /ith 1P(@xxx! 1ore!!!
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/string.h>
#include <asm/mpc5xxx.h>
#include <linux/spi/spi.h>
#include "spi-algo-mpc5xxx.h"
Include dependency "raph )or spi0iti@+##!c,
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem 1A
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
$efines
Mde)ine MP(%xxx_SPI_+23/0+ 1 %I Disable I%
Mde)ine GPI-_PS()_5 #x1###
Mde)ine GPI-_SI2'$ 1
Mde)ine GPI-_SI2'* +
-unctions
int setHspiHiti@+##Hcs 8struct spiHadapter I. int id. int val9
module_init 8spiHiti@+##Hinit9
module_exit 8spiHiti@+##Hexit9
M-D10+_0I(+2S+ 8BGPLB9
M-D10+_31'H- 8BKate Alhola kate8at9 katix!or"B9
M-D10+_D+S(IP'I-2 8Biti@+## SPI adapterB9
0ariables
mpc@xxxH"pio
I
itipo!er%&$$_gpio N 8struct mpc@xxxH"pio I9
1P(@xxxHGPI3
mpc@xxxH"p/
I
itipo!er%&$$_gp! N 8struct mpc@xxxH"p/ I9
1P(@xxxHGP:
$etailed $escription
SPI adapter driver )or iti@+## board /ith 1P(@xxx!
-unction $ocumentation
int
setHspiHiti@+##Hcs
8 struct spiHadapter
I
adap.
int id.
int val
9

setHspiHiti@+##Hcs set adapter spi cs line
Parameters4
adap spiHadapter structure
id chip select line id
val chip select line value
eturns4
#
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL
katix.org
Katix Embedded Linux SPI subsystem +#
Kate Alhola Driver subsystem description GPL
katekatix!or" #$%1#%#& Public
12L model
* (opyri"ht +##& Kate Alhola % Katix!or"! All ri"hts reserved! License, GPL

Você também pode gostar