019-m5445x_spi.patch 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345
  1. From bc755a3b8859e7307a8b10f39ca4cb6401c51987 Mon Sep 17 00:00:00 2001
  2. From: Kurt Mahan <[email protected]>
  3. Date: Tue, 27 Nov 2007 14:39:37 -0700
  4. Subject: [PATCH] Add M5445x SPI support.
  5. LTIBName: m5445x-spi
  6. Signed-off-by: Kurt Mahan <[email protected]>
  7. ---
  8. arch/m68k/configs/m54455evb_defconfig | 24 +-
  9. drivers/spi/Kconfig | 36 +
  10. drivers/spi/Makefile | 4 +
  11. drivers/spi/coldfire_edma.c | 358 ++++++++
  12. drivers/spi/spi-m5445x.c | 156 ++++
  13. drivers/spi/spi_coldfire.c | 1552 +++++++++++++++++++++++++++++++++
  14. drivers/spi/ssi_audio.c | 906 +++++++++++++++++++
  15. include/asm-m68k/coldfire_edma.h | 101 ++-
  16. include/linux/spi/mcfqspi.h | 80 ++
  17. 9 files changed, 3196 insertions(+), 21 deletions(-)
  18. create mode 100644 drivers/spi/coldfire_edma.c
  19. create mode 100644 drivers/spi/spi-m5445x.c
  20. create mode 100644 drivers/spi/spi_coldfire.c
  21. create mode 100644 drivers/spi/ssi_audio.c
  22. create mode 100644 include/linux/spi/mcfqspi.h
  23. --- a/arch/m68k/configs/m54455evb_defconfig
  24. +++ b/arch/m68k/configs/m54455evb_defconfig
  25. @@ -321,6 +321,8 @@ CONFIG_MTD_PHYSMAP_BANKWIDTH=1
  26. #
  27. # Self-contained MTD device drivers
  28. #
  29. +# CONFIG_MTD_DATAFLASH is not set
  30. +# CONFIG_MTD_M25P80 is not set
  31. # CONFIG_MTD_SLRAM is not set
  32. # CONFIG_MTD_PHRAM is not set
  33. # CONFIG_MTD_MTDRAM is not set
  34. @@ -497,8 +499,26 @@ CONFIG_UNIX98_PTYS=y
  35. #
  36. # SPI support
  37. #
  38. -# CONFIG_SPI is not set
  39. -# CONFIG_SPI_MASTER is not set
  40. +CONFIG_SPI=y
  41. +# CONFIG_SPI_DEBUG is not set
  42. +CONFIG_COLDFIRE_EDMA=y
  43. +CONFIG_SPI_MASTER=y
  44. +
  45. +#
  46. +# SPI Master Controller Drivers
  47. +#
  48. +# CONFIG_SPI_BITBANG is not set
  49. +CONFIG_SPI_COLDFIRE=y
  50. +CONFIG_SPI_COLDFIRE_DSPI_EDMA=y
  51. +
  52. +#
  53. +# SPI Protocol Masters
  54. +#
  55. +# CONFIG_SPI_AT25 is not set
  56. +# CONFIG_SPI_SPIDEV is not set
  57. +# CONFIG_SPI_TLE62X0 is not set
  58. +CONFIG_SPI_COLDFIRE_SSI_AUDIO=y
  59. +# CONFIG_SSIAUDIO_USE_EDMA is not set
  60. # CONFIG_W1 is not set
  61. # CONFIG_POWER_SUPPLY is not set
  62. # CONFIG_HWMON is not set
  63. --- a/drivers/spi/Kconfig
  64. +++ b/drivers/spi/Kconfig
  65. @@ -35,6 +35,15 @@ config SPI_DEBUG
  66. Say "yes" to enable debug messaging (like dev_dbg and pr_debug),
  67. sysfs, and debugfs support in SPI controller and protocol drivers.
  68. +config COLDFIRE_EDMA
  69. + tristate "Coldfire eDMA"
  70. + depends on COLDFIRE && EXPERIMENTAL
  71. + help
  72. + Support for Coldfire eDMA controller. Required for example
  73. + by SSI audio device driver.
  74. +
  75. +
  76. +
  77. #
  78. # MASTER side ... talking to discrete SPI slave chips including microcontrollers
  79. #
  80. @@ -113,6 +122,21 @@ config SPI_GPIO
  81. If unsure, say N.
  82. +config SPI_COLDFIRE
  83. + tristate "Coldfire QSPI/DSPI SPI Master"
  84. + depends on SPI_MASTER && COLDFIRE && EXPERIMENTAL
  85. + help
  86. + SPI driver for Freescale Coldfire QSPI module in master mode.
  87. + Tested with the 5282 processor, but should also work with other
  88. + Coldfire variants.
  89. +
  90. +config SPI_COLDFIRE_DSPI_EDMA
  91. + boolean "Coldfire DSPI master driver uses eDMA"
  92. + depends on SPI_MASTER && COLDFIRE && SPI_COLDFIRE && EXPERIMENTAL && COLDFIRE_EDMA
  93. + default n
  94. + help
  95. + Say "yes" if you want DSPI master driver to use eDMA for transfers.
  96. +
  97. config SPI_IMX
  98. tristate "Freescale iMX SPI controller"
  99. depends on SPI_MASTER && ARCH_IMX && EXPERIMENTAL
  100. @@ -255,6 +279,18 @@ config SPI_TLE62X0
  101. #
  102. # Add new SPI protocol masters in alphabetical order above this line
  103. #
  104. +config SPI_COLDFIRE_SSI_AUDIO
  105. + tristate "Coldfire SSI AUDIO"
  106. + depends on SPI_MASTER && SPI_COLDFIRE && EXPERIMENTAL
  107. + help
  108. + SSI audio device driver
  109. +
  110. +config SSIAUDIO_USE_EDMA
  111. + boolean "Coldfire DSPI master driver uses eDMA"
  112. + default y
  113. + depends on EXPERIMENTAL && COLDFIRE_EDMA && SPI_COLDFIRE_SSI_AUDIO
  114. + help
  115. + Say "yes" if you want SSI audio driver to use eDMA for SSI transfers.
  116. # (slave support would go here)
  117. --- a/drivers/spi/Makefile
  118. +++ b/drivers/spi/Makefile
  119. @@ -6,6 +6,8 @@ ifeq ($(CONFIG_SPI_DEBUG),y)
  120. EXTRA_CFLAGS += -DDEBUG
  121. endif
  122. +obj-$(CONFIG_COLDFIRE_EDMA) += coldfire_edma.o
  123. +
  124. # small core, mostly translating board-specific
  125. # config declarations into driver model code
  126. obj-$(CONFIG_SPI_MASTER) += spi.o
  127. @@ -16,6 +18,7 @@ obj-$(CONFIG_SPI_BFIN) += spi_bfin5xx.
  128. obj-$(CONFIG_SPI_BITBANG) += spi_bitbang.o
  129. obj-$(CONFIG_SPI_AU1550) += au1550_spi.o
  130. obj-$(CONFIG_SPI_BUTTERFLY) += spi_butterfly.o
  131. +obj-$(CONFIG_SPI_COLDFIRE) += spi_coldfire.o spi-m5445x.o
  132. obj-$(CONFIG_SPI_GPIO) += spi_gpio.o
  133. obj-$(CONFIG_SPI_IMX) += spi_imx.o
  134. obj-$(CONFIG_SPI_LM70_LLP) += spi_lm70llp.o
  135. @@ -35,6 +38,7 @@ obj-$(CONFIG_SPI_SH_SCI) += spi_sh_sci.
  136. obj-$(CONFIG_SPI_AT25) += at25.o
  137. obj-$(CONFIG_SPI_SPIDEV) += spidev.o
  138. obj-$(CONFIG_SPI_TLE62X0) += tle62x0.o
  139. +obj-$(CONFIG_SPI_COLDFIRE_SSI_AUDIO) += ssi_audio.o
  140. # ... add above this line ...
  141. # SPI slave controller drivers (upstream link)
  142. --- /dev/null
  143. +++ b/drivers/spi/coldfire_edma.c
  144. @@ -0,0 +1,358 @@
  145. +/*
  146. + *
  147. + * coldfire_edma.c - eDMA driver for Coldfire MCF5445x
  148. + *
  149. + * Yaroslav Vinogradov [email protected]
  150. + *
  151. + * Copyright Freescale Semiconductor, Inc. 2007
  152. + *
  153. + * This program is free software; you can redistribute it and/or modify it
  154. + * under the terms of the GNU General Public License as published by the
  155. + * Free Software Foundation; either version 2 of the License, or (at your
  156. + * option) any later version.
  157. + */
  158. +
  159. +#include <linux/init.h>
  160. +#include <linux/module.h>
  161. +#include <asm/virtconvert.h>
  162. +#include <asm/coldfire.h>
  163. +#include <linux/fs.h>
  164. +#include <linux/cdev.h>
  165. +#include <linux/seq_file.h>
  166. +#include <linux/proc_fs.h>
  167. +#include <asm/mcf5445x_edma.h>
  168. +#include <asm/mcf5445x_intc.h>
  169. +#include <asm/coldfire_edma.h>
  170. +
  171. +
  172. +/* callback handler data for each TCD */
  173. +struct edma_isr_record {
  174. + edma_irq_handler irq_handler; /* interrupt handler */
  175. + edma_error_handler error_handler; /* error interrupt handler */
  176. + void* dev; /* device used for the channel */
  177. + int allocated; /* busy flag */
  178. + spinlock_t *lock; /* spin lock (if needs to be locked in interrupt) */
  179. + const char* device_id; /* device id string, used in proc file system */
  180. +};
  181. +
  182. +/* device structure */
  183. +struct coldfire_edma_dev {
  184. + struct cdev cdev; /* character device */
  185. + struct edma_isr_record dma_interrupt_handlers[EDMA_CHANNELS]; /* channel handlers */
  186. +};
  187. +
  188. +/* allocated major device number */
  189. +static int coldfire_dma_major;
  190. +/* device driver structure */
  191. +static struct coldfire_edma_dev* devp = NULL;
  192. +
  193. +/* device driver file operations */
  194. +struct file_operations coldfire_edma_fops = {
  195. + .owner = THIS_MODULE,
  196. +};
  197. +
  198. +/* eDMA channel interrupt handler */
  199. +static int dmaisr(int irq, void *dev_id)
  200. +{
  201. + int channel = irq - EDMA_INT_CONTROLLER_BASE - EDMA_INT_CHANNEL_BASE;
  202. + int result = IRQ_HANDLED;
  203. +
  204. + if (devp!=NULL && devp->dma_interrupt_handlers[channel].lock) {
  205. + spin_lock(devp->dma_interrupt_handlers[channel].lock);
  206. + }
  207. +
  208. + if (devp!=NULL && devp->dma_interrupt_handlers[channel].irq_handler) {
  209. + result = devp->dma_interrupt_handlers[channel].irq_handler(channel,
  210. + devp->dma_interrupt_handlers[channel].dev);
  211. + } else {
  212. + confirm_edma_interrupt_handled(channel);
  213. + printk(EDMA_DRIVER_NAME ": No handler for DMA channel %d\n", channel);
  214. + }
  215. +
  216. + if (devp!=NULL && devp->dma_interrupt_handlers[channel].lock) {
  217. + spin_unlock(devp->dma_interrupt_handlers[channel].lock);
  218. + }
  219. +
  220. + return result;
  221. +}
  222. +
  223. +/* eDMA error interrupt handler */
  224. +static int dma_error_isr(int irq, void* dev_id)
  225. +{
  226. + u16 err;
  227. + int i;
  228. +
  229. + err = MCF_EDMA_ERR;
  230. + for (i=0;i<EDMA_CHANNELS;i++) {
  231. + if (err & (1<<i)) {
  232. + if (devp!=NULL && devp->dma_interrupt_handlers[i].error_handler) {
  233. + devp->dma_interrupt_handlers[i].error_handler(i, devp->dma_interrupt_handlers[i].dev);
  234. + } else {
  235. + printk(KERN_WARNING EDMA_DRIVER_NAME ": DMA error on channel %d\n", i);
  236. + }
  237. + }
  238. + }
  239. +
  240. + MCF_EDMA_CERR = MCF_EDMA_CERR_CAER;
  241. + return IRQ_HANDLED;
  242. +}
  243. +
  244. +/* sets channel parameters */
  245. +void set_edma_params(int channel, u32 source, u32 dest,
  246. + u32 attr, u32 soff, u32 nbytes, u32 slast,
  247. + u32 citer, u32 biter, u32 doff, u32 dlast_sga,
  248. + int major_int, int disable_req)
  249. +{
  250. +
  251. + if (channel<0 || channel>EDMA_CHANNELS)
  252. + return;
  253. +
  254. + MCF_EDMA_TCD_SADDR(channel) = source;
  255. + MCF_EDMA_TCD_DADDR(channel) = dest;
  256. + MCF_EDMA_TCD_ATTR(channel) = attr;
  257. + MCF_EDMA_TCD_SOFF(channel) = MCF_EDMA_TCD_SOFF_SOFF(soff);
  258. + MCF_EDMA_TCD_NBYTES(channel) = MCF_EDMA_TCD_NBYTES_NBYTES(nbytes);
  259. + MCF_EDMA_TCD_SLAST(channel) = MCF_EDMA_TCD_SLAST_SLAST(slast);
  260. + MCF_EDMA_TCD_CITER(channel) = MCF_EDMA_TCD_CITER_CITER(citer);
  261. + MCF_EDMA_TCD_BITER(channel)=MCF_EDMA_TCD_BITER_BITER(biter);
  262. + MCF_EDMA_TCD_DOFF(channel) = MCF_EDMA_TCD_DOFF_DOFF(doff);
  263. + MCF_EDMA_TCD_DLAST_SGA(channel) = MCF_EDMA_TCD_DLAST_SGA_DLAST_SGA(dlast_sga);
  264. + /* interrupt at the end of major loop */
  265. + if (major_int) {
  266. + MCF_EDMA_TCD_CSR(channel) |= MCF_EDMA_TCD_CSR_INT_MAJOR;
  267. + } else {
  268. + MCF_EDMA_TCD_CSR(channel) &= ~MCF_EDMA_TCD_CSR_INT_MAJOR;
  269. + }
  270. + /* disable request at the end of major loop of transfer or not*/
  271. + if (disable_req) {
  272. + MCF_EDMA_TCD_CSR(channel) |= MCF_EDMA_TCD_CSR_D_REQ;
  273. + } else {
  274. + MCF_EDMA_TCD_CSR(channel) &= ~MCF_EDMA_TCD_CSR_D_REQ;
  275. + }
  276. +
  277. +}
  278. +EXPORT_SYMBOL(set_edma_params);
  279. +
  280. +/* init eDMA controller */
  281. +void init_edma(void)
  282. +{
  283. + MCF_EDMA_CR = 0;
  284. +}
  285. +EXPORT_SYMBOL(init_edma);
  286. +
  287. +/* request eDMA channel */
  288. +int request_edma_channel(int channel,
  289. + edma_irq_handler handler,
  290. + edma_error_handler error_handler,
  291. + void* dev,
  292. + spinlock_t *lock,
  293. + const char* device_id )
  294. +{
  295. + if (devp!=NULL && channel>=0 && channel<=EDMA_CHANNELS) {
  296. + if (devp->dma_interrupt_handlers[channel].allocated) {
  297. + return -EBUSY;
  298. + }
  299. + devp->dma_interrupt_handlers[channel].allocated = 1;
  300. + devp->dma_interrupt_handlers[channel].irq_handler = handler;
  301. + devp->dma_interrupt_handlers[channel].error_handler = error_handler;
  302. + devp->dma_interrupt_handlers[channel].dev = dev;
  303. + devp->dma_interrupt_handlers[channel].lock = lock;
  304. + devp->dma_interrupt_handlers[channel].device_id = device_id;
  305. + return 0;
  306. + }
  307. + return -EINVAL;
  308. +}
  309. +EXPORT_SYMBOL(request_edma_channel);
  310. +
  311. +/* free eDMA channel */
  312. +int free_edma_channel(int channel, void* dev)
  313. +{
  314. + if (devp!=NULL && channel>=0 && channel<=EDMA_CHANNELS) {
  315. + if (devp->dma_interrupt_handlers[channel].allocated) {
  316. + if (devp->dma_interrupt_handlers[channel].dev != dev) {
  317. + return -EBUSY;
  318. + }
  319. + devp->dma_interrupt_handlers[channel].allocated = 0;
  320. + devp->dma_interrupt_handlers[channel].dev = NULL;
  321. + devp->dma_interrupt_handlers[channel].irq_handler = NULL;
  322. + devp->dma_interrupt_handlers[channel].error_handler = NULL;
  323. + devp->dma_interrupt_handlers[channel].lock = NULL;
  324. + }
  325. + return 0;
  326. + }
  327. + return -EINVAL;
  328. +}
  329. +EXPORT_SYMBOL(free_edma_channel);
  330. +
  331. +/* clean-up device driver allocated resources */
  332. +static void coldfire_edma_cleanup(void)
  333. +{
  334. + dev_t devno;
  335. + int i;
  336. +
  337. + /* free interrupts/memory */
  338. + if (devp) {
  339. + for (i=0;i<EDMA_CHANNELS;i++)
  340. + {
  341. + MCF_INTC0_SIMR = EDMA_INT_CHANNEL_BASE+i;
  342. + free_irq(EDMA_INT_CHANNEL_BASE+EDMA_INT_CONTROLLER_BASE+i, devp);
  343. + }
  344. + MCF_INTC0_SIMR = EDMA_INT_CHANNEL_BASE+EDMA_CHANNELS;
  345. + free_irq(EDMA_INT_CHANNEL_BASE+EDMA_INT_CONTROLLER_BASE+EDMA_CHANNELS, devp);
  346. + cdev_del(&devp->cdev);
  347. + kfree(devp);
  348. + }
  349. +
  350. + /* unregister character device */
  351. + devno = MKDEV(coldfire_dma_major, 0);
  352. + unregister_chrdev_region(devno, 1);
  353. +}
  354. +
  355. +#ifdef CONFIG_PROC_FS
  356. +/* proc file system support */
  357. +
  358. +#define FREE_CHANNEL "free"
  359. +#define DEVICE_UNKNOWN "device unknown"
  360. +
  361. +static int proc_edma_show(struct seq_file *m, void *v)
  362. +{
  363. + int i;
  364. +
  365. + if (devp==NULL) return 0;
  366. +
  367. + for (i = 0 ; i < EDMA_CHANNELS ; i++) {
  368. + if (devp->dma_interrupt_handlers[i].allocated) {
  369. + if (devp->dma_interrupt_handlers[i].device_id)
  370. + seq_printf(m, "%2d: %s\n", i, devp->dma_interrupt_handlers[i].device_id);
  371. + else
  372. + seq_printf(m, "%2d: %s\n", i, DEVICE_UNKNOWN);
  373. + } else {
  374. + seq_printf(m, "%2d: %s\n", i, FREE_CHANNEL);
  375. + }
  376. + }
  377. + return 0;
  378. +}
  379. +
  380. +static int proc_edma_open(struct inode *inode, struct file *file)
  381. +{
  382. + return single_open(file, proc_edma_show, NULL);
  383. +}
  384. +
  385. +static const struct file_operations proc_edma_operations = {
  386. + .open = proc_edma_open,
  387. + .read = seq_read,
  388. + .llseek = seq_lseek,
  389. + .release = single_release,
  390. +};
  391. +
  392. +static int __init proc_edma_init(void)
  393. +{
  394. + struct proc_dir_entry *e;
  395. +
  396. + e = create_proc_entry("edma", 0, NULL);
  397. + if (e)
  398. + e->proc_fops = &proc_edma_operations;
  399. +
  400. + return 0;
  401. +}
  402. +
  403. +#endif
  404. +
  405. +/* initializes device driver */
  406. +static int __init coldfire_edma_init(void)
  407. +{
  408. + dev_t dev;
  409. + int result;
  410. + int i;
  411. +
  412. + /* allocate free major number */
  413. + result = alloc_chrdev_region(&dev, DMA_DEV_MINOR, 1, EDMA_DRIVER_NAME);
  414. + if (result<0) {
  415. + printk(KERN_WARNING EDMA_DRIVER_NAME": can't get major %d\n", result);
  416. + return result;
  417. + }
  418. + coldfire_dma_major = MAJOR(dev);
  419. +
  420. + /* allocate device driver structure */
  421. + devp = kmalloc(sizeof(struct coldfire_edma_dev), GFP_KERNEL);
  422. + if (!devp) {
  423. + result = -ENOMEM;
  424. + goto fail;
  425. + }
  426. +
  427. + /* init handlers (no handlers for beggining) */
  428. + for (i=0;i<EDMA_CHANNELS;i++) {
  429. + devp->dma_interrupt_handlers[i].irq_handler = NULL;
  430. + devp->dma_interrupt_handlers[i].error_handler = NULL;
  431. + devp->dma_interrupt_handlers[i].dev = NULL;
  432. + devp->dma_interrupt_handlers[i].allocated = 0;
  433. + devp->dma_interrupt_handlers[i].lock = NULL;
  434. + devp->dma_interrupt_handlers[i].device_id = NULL;
  435. + }
  436. +
  437. + /* register char device */
  438. + cdev_init(&devp->cdev, &coldfire_edma_fops);
  439. + devp->cdev.owner = THIS_MODULE;
  440. + devp->cdev.ops = &coldfire_edma_fops;
  441. + result = cdev_add(&devp->cdev, dev, 1);
  442. + if (result) {
  443. + printk(KERN_NOTICE EDMA_DRIVER_NAME": Error %d adding coldfire-dma device\n", result);
  444. + result = -ENODEV;
  445. + goto fail;
  446. + }
  447. +
  448. + /* request/enable irq for each eDMA channel */
  449. + for (i=0;i<EDMA_CHANNELS;i++)
  450. + {
  451. + result = request_irq(EDMA_INT_CHANNEL_BASE+EDMA_INT_CONTROLLER_BASE+i,
  452. + dmaisr, SA_INTERRUPT, EDMA_DRIVER_NAME, devp);
  453. + if (result) {
  454. + printk(KERN_WARNING EDMA_DRIVER_NAME": Cannot request irq %d\n",
  455. + EDMA_INT_CHANNEL_BASE+EDMA_INT_CONTROLLER_BASE+i);
  456. + result = -EBUSY;
  457. + goto fail;
  458. + }
  459. +
  460. + MCF_INTC0_ICR(EDMA_INT_CHANNEL_BASE+i) = EDMA_IRQ_LEVEL;
  461. + MCF_INTC0_CIMR = EDMA_INT_CHANNEL_BASE+i;
  462. +
  463. + }
  464. +
  465. + /* request error interrupt */
  466. + result = request_irq(EDMA_INT_CHANNEL_BASE + EDMA_INT_CONTROLLER_BASE + EDMA_CHANNELS,
  467. + dma_error_isr, SA_INTERRUPT, EDMA_DRIVER_NAME, devp);
  468. + if (result) {
  469. + printk(KERN_WARNING EDMA_DRIVER_NAME": Cannot request irq %d\n",
  470. + EDMA_INT_CHANNEL_BASE+EDMA_INT_CONTROLLER_BASE+EDMA_CHANNELS);
  471. + result = -EBUSY;
  472. + goto fail;
  473. + }
  474. +
  475. + /* enable error interrupt in interrupt controller */
  476. + MCF_INTC0_ICR(EDMA_INT_CHANNEL_BASE+EDMA_CHANNELS) = EDMA_IRQ_LEVEL;
  477. + MCF_INTC0_CIMR = EDMA_INT_CHANNEL_BASE+EDMA_CHANNELS;
  478. +
  479. +#ifdef CONFIG_PROC_FS
  480. + proc_edma_init();
  481. +#endif
  482. +
  483. + printk(EDMA_DRIVER_NAME ": initialized successfully\n");
  484. +
  485. + return 0;
  486. +fail:
  487. + coldfire_edma_cleanup();
  488. + return result;
  489. +
  490. +}
  491. +
  492. +static void __exit coldfire_edma_exit(void)
  493. +{
  494. + coldfire_edma_cleanup();
  495. +}
  496. +
  497. +module_init(coldfire_edma_init);
  498. +module_exit(coldfire_edma_exit);
  499. +
  500. +MODULE_LICENSE("GPL");
  501. +MODULE_AUTHOR("Yaroslav Vinogradov, Freescale Inc.");
  502. +MODULE_DESCRIPTION("eDMA library for Coldfire 5445x");
  503. --- /dev/null
  504. +++ b/drivers/spi/spi-m5445x.c
  505. @@ -0,0 +1,156 @@
  506. +/***************************************************************************/
  507. +/*
  508. + * linux/arch/m68k/coldfire/spi-m5445x.c
  509. + *
  510. + * Sub-architcture dependant initialization code for the Freescale
  511. + * 5445x SPI module
  512. + *
  513. + * Yaroslav Vinogradov [email protected]
  514. + * Copyright Freescale Semiconductor, Inc 2007
  515. + *
  516. + * This program is free software; you can redistribute it and/or modify
  517. + * it under the terms of the GNU General Public License as published by
  518. + * the Free Software Foundation; either version 2 of the License, or
  519. + * (at your option) any later version.
  520. + */
  521. +/***************************************************************************/
  522. +
  523. +
  524. +#include <linux/kernel.h>
  525. +#include <linux/sched.h>
  526. +#include <linux/param.h>
  527. +#include <linux/init.h>
  528. +#include <linux/interrupt.h>
  529. +#include <linux/device.h>
  530. +#include <linux/platform_device.h>
  531. +#include <linux/spi/spi.h>
  532. +
  533. +#include <asm/dma.h>
  534. +#include <asm/traps.h>
  535. +#include <asm/machdep.h>
  536. +#include <asm/coldfire.h>
  537. +#include <asm/mcfsim.h>
  538. +#include <asm/mcfqspi.h>
  539. +#include <asm/mcf5445x_gpio.h>
  540. +
  541. +#define SPI_NUM_CHIPSELECTS 0x10
  542. +#define SPI_PAR_VAL (0 | MCF_GPIO_PAR_DSPI_PCS5_PCS5 | MCF_GPIO_PAR_DSPI_PCS2_PCS2 \
  543. + | MCF_GPIO_PAR_DSPI_PCS1_PCS1 | MCF_GPIO_PAR_DSPI_PCS0_PCS0 | MCF_GPIO_PAR_DSPI_SIN_SIN \
  544. + | MCF_GPIO_PAR_DSPI_SOUT_SOUT | MCF_GPIO_PAR_DSPI_SCK_SCK)
  545. +
  546. +#define MCF5445x_DSPI_IRQ_SOURCE (31)
  547. +#define MCF5445x_DSPI_IRQ_VECTOR (64 + MCF5445x_DSPI_IRQ_SOURCE)
  548. +
  549. +#define MCF5445x_DSPI_PAR (0xFC0A4063)
  550. +#define MCF5445x_DSPI_MCR (0xFC05C000)
  551. +#define MCF5445x_INTC0_ICR (0xFC048040)
  552. +#define MCF5445x_INTC0_IMRL (0xFC04800C)
  553. +
  554. +
  555. +#define M5445x_AUDIO_IRQ_SOURCE 49
  556. +#define M5445x_AUDIO_IRQ_VECTOR (128+M5445x_AUDIO_IRQ_SOURCE)
  557. +#define M5445x_AUDIO_IRQ_LEVEL 4
  558. +
  559. +void coldfire_qspi_cs_control(u8 cs, u8 command)
  560. +{
  561. +}
  562. +
  563. +#if defined(CONFIG_SPI_COLDFIRE_SSI_AUDIO)
  564. +static struct coldfire_spi_chip ssi_audio_chip_info = {
  565. + .mode = SPI_MODE_0,
  566. + .bits_per_word = 16,
  567. + .del_cs_to_clk = 16,
  568. + .del_after_trans = 16,
  569. + .void_write_data = 0
  570. +};
  571. +
  572. +#endif
  573. +
  574. +static struct spi_board_info spi_board_info[] = {
  575. +
  576. +#if defined(CONFIG_SPI_COLDFIRE_SSI_AUDIO)
  577. + {
  578. + .modalias = "ssi_audio",
  579. + .max_speed_hz = 300000,
  580. + .bus_num = 1,
  581. + .chip_select = 5,
  582. + .irq = M5445x_AUDIO_IRQ_VECTOR,
  583. + .platform_data = NULL,
  584. + .controller_data = &ssi_audio_chip_info
  585. + }
  586. +#endif
  587. +
  588. +};
  589. +
  590. +static struct coldfire_spi_master coldfire_master_info = {
  591. + .bus_num = 1,
  592. + .num_chipselect = SPI_NUM_CHIPSELECTS,
  593. + .irq_source = MCF5445x_DSPI_IRQ_SOURCE,
  594. + .irq_vector = MCF5445x_DSPI_IRQ_VECTOR,
  595. + .irq_mask = (0x01 << MCF5445x_DSPI_IRQ_SOURCE),
  596. + .irq_lp = 0x2, /* Level */
  597. + .par_val = SPI_PAR_VAL,
  598. +// .par_val16 = SPI_PAR_VAL,
  599. + .cs_control = coldfire_qspi_cs_control,
  600. +};
  601. +
  602. +static struct resource coldfire_spi_resources[] = {
  603. + [0] = {
  604. + .name = "qspi-par",
  605. + .start = MCF5445x_DSPI_PAR,
  606. + .end = MCF5445x_DSPI_PAR,
  607. + .flags = IORESOURCE_MEM
  608. + },
  609. +
  610. + [1] = {
  611. + .name = "qspi-module",
  612. + .start = MCF5445x_DSPI_MCR,
  613. + .end = MCF5445x_DSPI_MCR + 0xB8,
  614. + .flags = IORESOURCE_MEM
  615. + },
  616. +
  617. + [2] = {
  618. + .name = "qspi-int-level",
  619. + .start = MCF5445x_INTC0_ICR + MCF5445x_DSPI_IRQ_SOURCE,
  620. + .end = MCF5445x_INTC0_ICR + MCF5445x_DSPI_IRQ_SOURCE,
  621. + .flags = IORESOURCE_MEM
  622. + },
  623. +
  624. + [3] = {
  625. + .name = "qspi-int-mask",
  626. + .start = MCF5445x_INTC0_IMRL,
  627. + .end = MCF5445x_INTC0_IMRL,
  628. + .flags = IORESOURCE_MEM
  629. + }
  630. +};
  631. +
  632. +static struct platform_device coldfire_spi = {
  633. + .name = "spi_coldfire", //"coldfire-qspi",
  634. + .id = -1,
  635. + .resource = coldfire_spi_resources,
  636. + .num_resources = ARRAY_SIZE(coldfire_spi_resources),
  637. + .dev = {
  638. + .platform_data = &coldfire_master_info,
  639. + }
  640. +};
  641. +
  642. +static int __init spi_dev_init(void)
  643. +{
  644. + int retval = 0;
  645. +
  646. + retval = platform_device_register(&coldfire_spi);
  647. +
  648. + if (retval < 0) {
  649. + printk(KERN_ERR "SPI-m5445x: platform_device_register failed with code=%d\n", retval);
  650. + goto out;
  651. + }
  652. +
  653. + if (ARRAY_SIZE(spi_board_info))
  654. + retval = spi_register_board_info(spi_board_info, ARRAY_SIZE(spi_board_info));
  655. +
  656. +
  657. +out:
  658. + return retval;
  659. +}
  660. +
  661. +arch_initcall(spi_dev_init);
  662. --- /dev/null
  663. +++ b/drivers/spi/spi_coldfire.c
  664. @@ -0,0 +1,1552 @@
  665. +/****************************************************************************/
  666. +
  667. +/*
  668. + * spi_coldfire.c - Master QSPI/DSPI controller for the ColdFire processors
  669. + *
  670. + * (C) Copyright 2005, Intec Automation,
  671. + * Mike Lavender (mike@steroidmicros)
  672. + *
  673. + * (C) Copyright 2007, Freescale Inc,
  674. + * Yaroslav Vinogradov ([email protected])
  675. + *
  676. +
  677. + This program is free software; you can redistribute it and/or modify
  678. + it under the terms of the GNU General Public License as published by
  679. + the Free Software Foundation; either version 2 of the License, or
  680. + (at your option) any later version.
  681. +
  682. + This program is distributed in the hope that it will be useful,
  683. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  684. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  685. + GNU General Public License for more details.
  686. +
  687. + You should have received a copy of the GNU General Public License
  688. + along with this program; if not, write to the Free Software
  689. + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  690. +/* ------------------------------------------------------------------------- */
  691. +
  692. +
  693. +/****************************************************************************/
  694. +
  695. +/*
  696. + * Includes
  697. + */
  698. +
  699. +#include <linux/autoconf.h>
  700. +#include <linux/init.h>
  701. +#include <linux/module.h>
  702. +#include <linux/device.h>
  703. +#include <linux/interrupt.h>
  704. +#include <linux/platform_device.h>
  705. +#include <linux/spi/spi.h>
  706. +#include <linux/workqueue.h>
  707. +#include <linux/delay.h>
  708. +
  709. +#include <asm/delay.h>
  710. +#include <asm/mcfsim.h>
  711. +#include <asm/mcfqspi.h>
  712. +#include <asm/coldfire.h>
  713. +#include <asm/virtconvert.h>
  714. +
  715. +#if defined(CONFIG_M54455)
  716. + #define SPI_DSPI
  717. + #if defined(CONFIG_SPI_COLDFIRE_DSPI_EDMA)
  718. + #define SPI_DSPI_EDMA
  719. + #ifdef CONFIG_MMU
  720. + #define SPI_USE_MMU
  721. + #endif
  722. + #endif
  723. +#endif
  724. +
  725. +#ifdef SPI_DSPI
  726. +#include <asm/mcf5445x_dspi.h>
  727. +
  728. +
  729. +#endif
  730. +
  731. +#if defined(SPI_DSPI_EDMA)
  732. +
  733. +/* edma buffer size in transfer units (32bits) */
  734. +#define EDMA_BUFFER_SIZE (PAGE_SIZE/4)
  735. +#define EDMA_BUFSIZE_KMALLOC (EDMA_BUFFER_SIZE*4)
  736. +
  737. +#define DSPI_DMA_RX_TCD 12
  738. +#define DSPI_DMA_TX_TCD 13
  739. +
  740. +
  741. +#include <asm/coldfire_edma.h>
  742. +#include <asm/mcf5445x_edma.h>
  743. +#endif
  744. +
  745. +
  746. +MODULE_AUTHOR("Mike Lavender");
  747. +MODULE_DESCRIPTION("ColdFire QSPI Contoller");
  748. +MODULE_LICENSE("GPL");
  749. +
  750. +#define DRIVER_NAME "Coldfire QSPI/DSPI"
  751. +
  752. +/****************************************************************************/
  753. +
  754. +/*
  755. + * Local constants and macros
  756. + */
  757. +
  758. +#define QSPI_RAM_SIZE 0x10 /* 16 word table */
  759. +
  760. +#define QSPI_TRANSMIT_RAM 0x00
  761. +#define QSPI_RECEIVE_RAM 0x10
  762. +#define QSPI_COMMAND_RAM 0x20
  763. +
  764. +#define QSPI_COMMAND 0x7000 /* 15: X = Continuous CS
  765. + * 14: 1 = Get BITSE from QMR[BITS]
  766. + * 13: 1 = Get DT from QDLYR[DTL]
  767. + * 12: 1 = Get DSK from QDLYR[QCD]
  768. + * 8-11: XXXX = next 4 bytes for CS
  769. + * 0-7: 0000 0000 Reserved
  770. + */
  771. +
  772. +#define QIR_WCEF 0x0008 /* write collison */
  773. +#define QIR_ABRT 0x0004 /* abort */
  774. +#define QIR_SPIF 0x0001 /* finished */
  775. +
  776. +#define QIR_WCEFE 0x0800
  777. +#define QIR_ABRTE 0x0400
  778. +#define QIR_SPIFE 0x0100
  779. +
  780. +#define QIR_WCEFB 0x8000
  781. +#define QIR_ABRTB 0x4000
  782. +#define QIR_ABRTL 0x1000
  783. +
  784. +#define QMR_BITS 0x3C00
  785. +#define QMR_BITS_8 0x2000
  786. +
  787. +#define QCR_CONT 0x8000
  788. +
  789. +#define QDLYR_SPE 0x8000
  790. +
  791. +#define QWR_ENDQP_MASK 0x0F00
  792. +#define QWR_CSIV 0x1000 /* 1 = active low chip selects */
  793. +
  794. +
  795. +#define START_STATE ((void*)0)
  796. +#define RUNNING_STATE ((void*)1)
  797. +#define DONE_STATE ((void*)2)
  798. +#define ERROR_STATE ((void*)-1)
  799. +
  800. +#define QUEUE_RUNNING 0
  801. +#define QUEUE_STOPPED 1
  802. +
  803. +/****************************************************************************/
  804. +
  805. +/*
  806. + * Local Data Structures
  807. + */
  808. +
  809. +struct transfer_state {
  810. + u32 index;
  811. + u32 len;
  812. + void *tx;
  813. + void *tx_end;
  814. + void *rx;
  815. + void *rx_end;
  816. + char flags;
  817. +#define TRAN_STATE_RX_VOID 0x01
  818. +#define TRAN_STATE_TX_VOID 0x02
  819. +#define TRAN_STATE_WORD_ODD_NUM 0x04
  820. + u8 cs;
  821. + u16 void_write_data;
  822. + unsigned cs_change:1;
  823. +};
  824. +
  825. +typedef struct {
  826. + unsigned master:1;
  827. + unsigned dohie:1;
  828. + unsigned bits:4;
  829. + unsigned cpol:1;
  830. + unsigned cpha:1;
  831. + unsigned baud:8;
  832. +} QMR;
  833. +
  834. +typedef struct {
  835. + unsigned spe:1;
  836. + unsigned qcd:7;
  837. + unsigned dtl:8;
  838. +} QDLYR;
  839. +
  840. +typedef struct {
  841. + unsigned halt:1;
  842. + unsigned wren:1;
  843. + unsigned wrto:1;
  844. + unsigned csiv:1;
  845. + unsigned endqp:4;
  846. + unsigned cptqp:4;
  847. + unsigned newqp:4;
  848. +} QWR;
  849. +
  850. +
  851. +typedef struct {
  852. + unsigned master:1;
  853. + unsigned cont_scke:1;
  854. + unsigned dconf:2;
  855. + unsigned frz:1;
  856. + unsigned mtfe:1;
  857. + unsigned pcsse:1;
  858. + unsigned rooe:1;
  859. + unsigned pcsis:8;
  860. + unsigned reserved15:1;
  861. + unsigned mdis:1;
  862. + unsigned dis_tx:1;
  863. + unsigned dis_rxf:1;
  864. + unsigned clr_tx:1;
  865. + unsigned clr_rxf:1;
  866. + unsigned smpl_pt:2;
  867. + unsigned reserved71:7;
  868. + unsigned halt:1;
  869. +} DSPI_MCR;
  870. +
  871. +typedef struct {
  872. + unsigned dbr:1;
  873. + unsigned fmsz:4;
  874. + unsigned cpol:1;
  875. + unsigned cpha:1;
  876. + unsigned lsbfe:1;
  877. + unsigned pcssck:2;
  878. + unsigned pasc:2;
  879. + unsigned pdt:2;
  880. + unsigned pbr:2;
  881. + unsigned cssck:4;
  882. + unsigned asc:4;
  883. + unsigned dt:4;
  884. + unsigned br:4;
  885. +} DSPI_CTAR;
  886. +
  887. +struct chip_data {
  888. +#if defined(SPI_DSPI)
  889. + /* dspi data */
  890. + union {
  891. + u32 mcr_val;
  892. + DSPI_MCR mcr;
  893. + };
  894. + union {
  895. + u32 ctar_val;
  896. + DSPI_CTAR ctar;
  897. + };
  898. +#else
  899. + union {
  900. + u16 qmr_val;
  901. + QMR qmr;
  902. + };
  903. + union {
  904. + u16 qdlyr_val;
  905. + QDLYR qdlyr;
  906. + };
  907. + union {
  908. + u16 qwr_val;
  909. + QWR qwr;
  910. + };
  911. +#endif
  912. +
  913. + u16 void_write_data;
  914. +};
  915. +
  916. +
  917. +struct driver_data {
  918. + /* Driver model hookup */
  919. + struct platform_device *pdev;
  920. +
  921. + /* SPI framework hookup */
  922. + struct spi_master *master;
  923. +
  924. + /* Driver message queue */
  925. + struct workqueue_struct *workqueue;
  926. + struct work_struct pump_messages;
  927. + spinlock_t lock;
  928. + struct list_head queue;
  929. + int busy;
  930. + int run;
  931. +
  932. + /* Message Transfer pump */
  933. + struct tasklet_struct pump_transfers;
  934. +
  935. + /* Current message transfer state info */
  936. + struct spi_message* cur_msg;
  937. + struct spi_transfer* cur_transfer;
  938. + struct chip_data *cur_chip;
  939. + size_t len;
  940. + void *tx;
  941. + void *tx_end;
  942. + void *rx;
  943. + void *rx_end;
  944. + char flags;
  945. +#define TRAN_STATE_RX_VOID 0x01
  946. +#define TRAN_STATE_TX_VOID 0x02
  947. +#define TRAN_STATE_WORD_ODD_NUM 0x04
  948. + u8 cs;
  949. + u16 void_write_data;
  950. + unsigned cs_change:1;
  951. +
  952. + u32 trans_cnt;
  953. + u32 wce_cnt;
  954. + u32 abrt_cnt;
  955. +#if defined(SPI_DSPI)
  956. + u32 *mcr; /* DSPI MCR register */
  957. + u32 *ctar; /* DSPI CTAR register */
  958. + u32 *dspi_dtfr; /* DSPI DTFR register */
  959. + u32 *dspi_drfr; /* DSPI DRFR register */
  960. + u32 *dspi_rser; /* DSPI RSER register */
  961. + u32 *dspi_sr; /* DSPI status register */
  962. + u8 dspi_ctas; /* DSPI CTAS value*/
  963. +
  964. +#if defined(SPI_DSPI_EDMA)
  965. + void* edma_tx_buf;
  966. + void* edma_rx_buf;
  967. +#endif
  968. +
  969. +
  970. +#else
  971. + u16 *qmr; /* QSPI mode register */
  972. + u16 *qdlyr; /* QSPI delay register */
  973. + u16 *qwr; /* QSPI wrap register */
  974. + u16 *qir; /* QSPI interrupt register */
  975. + u16 *qar; /* QSPI address register */
  976. + u16 *qdr; /* QSPI data register */
  977. + u16 *qcr; /* QSPI command register */
  978. +#endif
  979. + u8 *par; /* Pin assignment register */
  980. + u8 *int_icr; /* Interrupt level and priority register */
  981. + u32 *int_mr; /* Interrupt mask register */
  982. + void (*cs_control)(u8 cs, u8 command);
  983. +};
  984. +
  985. +#define DSPI_CS(cs) ((1<<(cs))<<16)
  986. +
  987. +
  988. +/****************************************************************************/
  989. +
  990. +/*
  991. + * SPI local functions
  992. + */
  993. +
  994. +//#define SPI_COLDFIRE_DEBUG
  995. +
  996. +static void *next_transfer(struct driver_data *drv_data)
  997. +{
  998. + struct spi_message *msg = drv_data->cur_msg;
  999. + struct spi_transfer *trans = drv_data->cur_transfer;
  1000. +
  1001. + /* Move to next transfer */
  1002. + if (trans->transfer_list.next != &msg->transfers) {
  1003. + drv_data->cur_transfer =
  1004. + list_entry(trans->transfer_list.next,
  1005. + struct spi_transfer,
  1006. + transfer_list);
  1007. + return RUNNING_STATE;
  1008. + } else
  1009. + return DONE_STATE;
  1010. +}
  1011. +
  1012. +
  1013. +#define DSPI_BITS MCF_DSPI_DCTAR_FMSZ(15)
  1014. +#define DSPI_BITS_16 MCF_DSPI_DCTAR_FMSZ(15)
  1015. +#define DSPI_BITS_8 MCF_DSPI_DCTAR_FMSZ(7)
  1016. +#define DSPI_FIFO_SIZE 16
  1017. +
  1018. +static inline int is_word_transfer(struct driver_data *drv_data)
  1019. +{
  1020. +#if defined(SPI_DSPI)
  1021. + return ((*drv_data->ctar & DSPI_BITS_16) == DSPI_BITS_8) ? 0 : 1;
  1022. +#else
  1023. + return ((*drv_data->qmr & QMR_BITS) == QMR_BITS_8) ? 0 : 1;
  1024. +#endif
  1025. +}
  1026. +
  1027. +static void inline set_8bit_transfer_mode(struct driver_data *drv_data)
  1028. +{
  1029. +#if defined(SPI_DSPI)
  1030. + *drv_data->ctar |= (*drv_data->ctar & ~DSPI_BITS) | DSPI_BITS_8;
  1031. +#else
  1032. + *drv_data->qmr |= (*drv_data->qmr & ~QMR_BITS) | QMR_BITS_8;
  1033. +#endif
  1034. +}
  1035. +
  1036. +static void inline set_16bit_transfer_mode(struct driver_data *drv_data)
  1037. +{
  1038. +#if defined(SPI_DSPI)
  1039. + *drv_data->ctar |= (*drv_data->ctar & ~DSPI_BITS) | DSPI_BITS_16;
  1040. +#else
  1041. + *drv_data->qmr |= (*drv_data->qmr & ~QMR_BITS);
  1042. +#endif
  1043. +}
  1044. +
  1045. +static int write(struct driver_data *drv_data)
  1046. +{
  1047. + int tx_count = 0;
  1048. +#ifndef SPI_DSPI
  1049. + int cmd_count = 0;
  1050. +#endif
  1051. + int tx_word;
  1052. +
  1053. +#if defined(SPI_DSPI)
  1054. +
  1055. +#if defined(SPI_DSPI_EDMA)
  1056. + u32* edma_wr;
  1057. +#endif
  1058. +
  1059. + u16 d16;
  1060. + u8 d8;
  1061. + u32 dspi_pushr;
  1062. + int first = 1;
  1063. +#endif
  1064. +
  1065. + tx_word = is_word_transfer(drv_data);
  1066. +
  1067. + // If we are in word mode, but only have a single byte to transfer
  1068. + // then switch to byte mode temporarily. Will switch back at the
  1069. + // end of the transfer.
  1070. + if (tx_word && ((drv_data->tx_end - drv_data->tx) == 1)) {
  1071. + drv_data->flags |= TRAN_STATE_WORD_ODD_NUM;
  1072. + set_8bit_transfer_mode(drv_data);
  1073. + tx_word = 0;
  1074. + }
  1075. +
  1076. +
  1077. +#if defined(SPI_DSPI)
  1078. +
  1079. +#if defined(SPI_DSPI_EDMA)
  1080. + edma_wr = (u32*)(drv_data->edma_tx_buf);
  1081. +#endif
  1082. +
  1083. +
  1084. +#if defined(SPI_DSPI_EDMA)
  1085. + while ((drv_data->tx < drv_data->tx_end) && (tx_count < EDMA_BUFFER_SIZE)) {
  1086. +#else
  1087. + while ((drv_data->tx < drv_data->tx_end) && (tx_count < DSPI_FIFO_SIZE)) {
  1088. +#endif
  1089. + if (tx_word) {
  1090. + if ((drv_data->tx_end - drv_data->tx) == 1)
  1091. + break;
  1092. + if (!(drv_data->flags & TRAN_STATE_TX_VOID)) {
  1093. + d16 = *(u16 *)drv_data->tx;
  1094. + } else {
  1095. + d16 = drv_data->void_write_data;
  1096. + }
  1097. +
  1098. + dspi_pushr = MCF_DSPI_DTFR_TXDATA(d16)
  1099. + | DSPI_CS(drv_data->cs)
  1100. + | MCF_DSPI_DTFR_CTAS(drv_data->dspi_ctas)
  1101. + //| MCF_DSPI_DTFR_CONT
  1102. + ;
  1103. +
  1104. + drv_data->tx += 2;
  1105. +
  1106. +#if defined(SPI_DSPI_EDMA)
  1107. + if (drv_data->tx == drv_data->tx_end || tx_count==EDMA_BUFFER_SIZE-1) {
  1108. +#else
  1109. + if (drv_data->tx == drv_data->tx_end || tx_count==DSPI_FIFO_SIZE-1) {
  1110. +#endif
  1111. + // last transfer in queue
  1112. + dspi_pushr |= MCF_DSPI_DTFR_EOQ;
  1113. + if (drv_data->cs_change) {
  1114. + dspi_pushr &= ~MCF_DSPI_DTFR_CONT;
  1115. + }
  1116. + }
  1117. +
  1118. + if (first) {
  1119. + first = 0;
  1120. + dspi_pushr |= MCF_DSPI_DTFR_CTCNT; // clear counter
  1121. + }
  1122. +#if defined(SPI_DSPI_EDMA)
  1123. + *edma_wr = dspi_pushr;
  1124. + edma_wr++;
  1125. +#else
  1126. + *drv_data->dspi_dtfr = dspi_pushr;
  1127. + //MCF_DSPI_DTFR = dspi_pushr;
  1128. +#endif
  1129. +
  1130. +
  1131. + } else {
  1132. + if (!(drv_data->flags & TRAN_STATE_TX_VOID)) {
  1133. + d8 = *(u8 *)drv_data->tx;
  1134. + } else {
  1135. + d8 = *(u8 *)&drv_data->void_write_data;
  1136. + }
  1137. +
  1138. + dspi_pushr = MCF_DSPI_DTFR_TXDATA(d8)
  1139. + | DSPI_CS(drv_data->cs)
  1140. + /* | MCF_DSPI_DTFR_PCS5 | */
  1141. + | MCF_DSPI_DTFR_CTAS(drv_data->dspi_ctas)
  1142. + | MCF_DSPI_DTFR_CONT;
  1143. +
  1144. + drv_data->tx++;
  1145. +
  1146. + if (drv_data->tx == drv_data->tx_end || tx_count==DSPI_FIFO_SIZE-1) {
  1147. + // last transfer in queue
  1148. + dspi_pushr |= MCF_DSPI_DTFR_EOQ;
  1149. + if (drv_data->cs_change) {
  1150. + dspi_pushr &= ~MCF_DSPI_DTFR_CONT;
  1151. + }
  1152. + }
  1153. +
  1154. + if (first) {
  1155. + first = 0;
  1156. + dspi_pushr |= MCF_DSPI_DTFR_CTCNT; // clear counter
  1157. + }
  1158. +
  1159. +#if defined(SPI_DSPI_EDMA)
  1160. + *edma_wr = dspi_pushr;
  1161. + edma_wr++;
  1162. +#else
  1163. + *drv_data->dspi_dtfr = dspi_pushr;
  1164. + //MCF_DSPI_DTFR = dspi_pushr;
  1165. +#endif
  1166. +
  1167. + }
  1168. + tx_count++;
  1169. + }
  1170. +
  1171. +#if defined(SPI_DSPI_EDMA)
  1172. +
  1173. + if (tx_count>0) {
  1174. +
  1175. + // TODO: initiate eDMA transfer
  1176. + set_edma_params(DSPI_DMA_TX_TCD,
  1177. +#ifdef SPI_USE_MMU
  1178. + virt_to_phys(drv_data->edma_tx_buf),
  1179. +#else
  1180. + drv_data->edma_tx_buf,
  1181. +#endif
  1182. + (u32)drv_data->dspi_dtfr,
  1183. + MCF_EDMA_TCD_ATTR_SSIZE_32BIT | MCF_EDMA_TCD_ATTR_DSIZE_32BIT,
  1184. + 4, // soff
  1185. + 4, // nbytes
  1186. + 0, // slast
  1187. + tx_count, // citer
  1188. + tx_count, // biter
  1189. + 0, // doff
  1190. + 0, // dlastsga
  1191. + 0, // major_int
  1192. + 1 // disable_req
  1193. + );
  1194. +
  1195. + set_edma_params(DSPI_DMA_RX_TCD,
  1196. + (u32)drv_data->dspi_drfr,
  1197. +#ifdef SPI_USE_MMU
  1198. + virt_to_phys(drv_data->edma_rx_buf),
  1199. +#else
  1200. + drv_data->edma_rx_buf,
  1201. +#endif
  1202. + MCF_EDMA_TCD_ATTR_SSIZE_32BIT | MCF_EDMA_TCD_ATTR_DSIZE_32BIT,
  1203. + 0, // soff
  1204. + 4, // nbytes
  1205. + 0, // slast
  1206. + tx_count, // citer
  1207. + tx_count, // biter
  1208. + 4, // doff
  1209. + 0, // dlastsga
  1210. + 0, // major_int
  1211. + 1 // disable_req
  1212. + );
  1213. +
  1214. +
  1215. + start_edma_transfer(DSPI_DMA_TX_TCD); // transmit SPI data
  1216. + start_edma_transfer(DSPI_DMA_RX_TCD); // receive SPI data
  1217. + }
  1218. +#endif
  1219. +
  1220. +#else
  1221. +
  1222. + *drv_data->qar = QSPI_TRANSMIT_RAM;
  1223. + while ((drv_data->tx < drv_data->tx_end) && (tx_count < QSPI_RAM_SIZE)) {
  1224. + if (tx_word) {
  1225. + if ((drv_data->tx_end - drv_data->tx) == 1)
  1226. + break;
  1227. +
  1228. + if (!(drv_data->flags & TRAN_STATE_TX_VOID))
  1229. + *drv_data->qdr = *(u16 *)drv_data->tx;
  1230. + else
  1231. + *drv_data->qdr = drv_data->void_write_data;
  1232. + drv_data->tx += 2;
  1233. + } else {
  1234. + if (!(drv_data->flags & TRAN_STATE_TX_VOID))
  1235. + *drv_data->qdr = *(u8 *)drv_data->tx;
  1236. + else
  1237. + *drv_data->qdr = *(u8 *)&drv_data->void_write_data;
  1238. + drv_data->tx++;
  1239. + }
  1240. + tx_count++;
  1241. + }
  1242. +
  1243. +
  1244. + *drv_data->qar = QSPI_COMMAND_RAM;
  1245. + while (cmd_count < tx_count) {
  1246. + u16 qcr = QSPI_COMMAND
  1247. + | QCR_CONT
  1248. + | (~((0x01 << drv_data->cs) << 8) & 0x0F00);
  1249. +
  1250. + if ( (cmd_count == tx_count - 1)
  1251. + && (drv_data->tx == drv_data->tx_end)
  1252. + && (drv_data->cs_change) ) {
  1253. + qcr &= ~QCR_CONT;
  1254. + }
  1255. + *drv_data->qcr = qcr;
  1256. + cmd_count++;
  1257. + }
  1258. +
  1259. + *drv_data->qwr = (*drv_data->qwr & ~QWR_ENDQP_MASK) | ((cmd_count - 1) << 8);
  1260. +
  1261. + /* Fire it up! */
  1262. + *drv_data->qdlyr |= QDLYR_SPE;
  1263. +#endif
  1264. +
  1265. + return tx_count;
  1266. +}
  1267. +
  1268. +
  1269. +static int read(struct driver_data *drv_data)
  1270. +{
  1271. + int rx_count = 0;
  1272. + int rx_word;
  1273. +#if defined(SPI_DSPI_EDMA)
  1274. + u32* rx_edma;
  1275. +#endif
  1276. + u16 d;
  1277. + rx_word = is_word_transfer(drv_data);
  1278. +
  1279. +#if defined(SPI_DSPI)
  1280. +
  1281. +#if defined(SPI_DSPI_EDMA)
  1282. + rx_edma = (u32*) drv_data->edma_tx_buf;
  1283. + while ((drv_data->rx < drv_data->rx_end) && (rx_count < EDMA_BUFFER_SIZE)) {
  1284. +#else
  1285. + while ((drv_data->rx < drv_data->rx_end) && (rx_count < DSPI_FIFO_SIZE)) {
  1286. +#endif
  1287. + if (rx_word) {
  1288. + if ((drv_data->rx_end - drv_data->rx) == 1)
  1289. + break;
  1290. +#if defined(SPI_DSPI_EDMA)
  1291. + d = MCF_DSPI_DRFR_RXDATA(*rx_edma);
  1292. + rx_edma++;
  1293. +#else
  1294. + d = MCF_DSPI_DRFR_RXDATA(*drv_data->dspi_drfr);
  1295. +#endif
  1296. +
  1297. + if (!(drv_data->flags & TRAN_STATE_RX_VOID))
  1298. + *(u16 *)drv_data->rx = d;
  1299. + drv_data->rx += 2;
  1300. + } else {
  1301. +#if defined(SPI_DSPI_EDMA)
  1302. + d = MCF_DSPI_DRFR_RXDATA(*rx_edma);
  1303. + rx_edma++;
  1304. +#else
  1305. + d = MCF_DSPI_DRFR_RXDATA(*drv_data->dspi_drfr);
  1306. +#endif
  1307. + if (!(drv_data->flags & TRAN_STATE_RX_VOID))
  1308. + *(u8 *)drv_data->rx = d;
  1309. + drv_data->rx++;
  1310. + }
  1311. + rx_count++;
  1312. + }
  1313. +
  1314. +
  1315. +#else
  1316. +
  1317. + *drv_data->qar = QSPI_RECEIVE_RAM;
  1318. + while ((drv_data->rx < drv_data->rx_end) && (rx_count < QSPI_RAM_SIZE)) {
  1319. + if (rx_word) {
  1320. + if ((drv_data->rx_end - drv_data->rx) == 1)
  1321. + break;
  1322. +
  1323. + if (!(drv_data->flags & TRAN_STATE_RX_VOID))
  1324. + *(u16 *)drv_data->rx = *drv_data->qdr;
  1325. + drv_data->rx += 2;
  1326. + } else {
  1327. + if (!(drv_data->flags & TRAN_STATE_RX_VOID))
  1328. + *(u8 *)drv_data->rx = *drv_data->qdr;
  1329. + drv_data->rx++;
  1330. + }
  1331. + rx_count++;
  1332. + }
  1333. +#endif
  1334. +
  1335. + return rx_count;
  1336. +}
  1337. +
  1338. +
  1339. +static inline void qspi_setup_chip(struct driver_data *drv_data)
  1340. +{
  1341. + struct chip_data *chip = drv_data->cur_chip;
  1342. +
  1343. +#if defined(SPI_DSPI)
  1344. +
  1345. + *drv_data->mcr = chip->mcr_val;
  1346. +
  1347. + // TODO: remove later
  1348. + chip->ctar_val = 0x78560118;
  1349. +
  1350. + *drv_data->ctar = chip->ctar_val;
  1351. + *drv_data->dspi_rser = 0
  1352. + | MCF_DSPI_DRSER_EOQFE
  1353. +#if defined(SPI_DSPI_EDMA)
  1354. + | MCF_DSPI_DRSER_TFFFE
  1355. + | MCF_DSPI_DRSER_TFFFS
  1356. +#endif
  1357. + ;
  1358. +
  1359. +
  1360. +#else
  1361. + *drv_data->qmr = chip->qmr_val;
  1362. + *drv_data->qdlyr = chip->qdlyr_val;
  1363. + *drv_data->qwr = chip->qwr_val;
  1364. +
  1365. + /*
  1366. + * Enable all the interrupts and clear all the flags
  1367. + */
  1368. + *drv_data->qir = (QIR_SPIFE | QIR_ABRTE | QIR_WCEFE)
  1369. + | (QIR_WCEFB | QIR_ABRTB | QIR_ABRTL)
  1370. + | (QIR_SPIF | QIR_ABRT | QIR_WCEF);
  1371. +#endif
  1372. +}
  1373. +
  1374. +#if defined(SPI_DSPI_EDMA)
  1375. +static int edma_tx_handler(int channel, void* dev)
  1376. +{
  1377. + if (channel == DSPI_DMA_TX_TCD) {
  1378. + stop_edma_transfer(DSPI_DMA_TX_TCD);
  1379. + }
  1380. + return IRQ_HANDLED;
  1381. +}
  1382. +
  1383. +static int edma_rx_handler(int channel, void* dev)
  1384. +{
  1385. + if (channel == DSPI_DMA_RX_TCD) {
  1386. + stop_edma_transfer(DSPI_DMA_RX_TCD);
  1387. + }
  1388. +
  1389. + return IRQ_HANDLED;
  1390. +}
  1391. +#endif
  1392. +
  1393. +static irqreturn_t qspi_interrupt(int irq, void *dev_id)
  1394. +{
  1395. + struct driver_data *drv_data = (struct driver_data *)dev_id;
  1396. + struct spi_message *msg = drv_data->cur_msg;
  1397. +#if defined(SPI_DSPI)
  1398. +#if !defined(SPI_DSPI_EDMA)
  1399. + u32 irq_status = *drv_data->dspi_sr;
  1400. +#endif
  1401. +#else
  1402. + u16 irq_status = *drv_data->qir;
  1403. +#endif
  1404. +
  1405. + /* Clear all flags immediately */
  1406. +#if defined(SPI_DSPI)
  1407. + *drv_data->dspi_sr = MCF_DSPI_DSR_EOQF;
  1408. +#else
  1409. + *drv_data->qir |= (QIR_SPIF | QIR_ABRT | QIR_WCEF);
  1410. +#endif
  1411. +
  1412. + if (!drv_data->cur_msg || !drv_data->cur_msg->state) {
  1413. +#if !defined(SPI_DSPI_EDMA)
  1414. + /* if eDMA is used it happens some time (at least once)*/
  1415. + printk(KERN_ERR "coldfire-qspi: bad message or transfer "
  1416. + "state in interrupt handler. IRQ status=%x\n", irq_status);
  1417. +#endif
  1418. + return IRQ_NONE;
  1419. + }
  1420. +
  1421. +#if !defined(SPI_DSPI)
  1422. + if (irq_status & QIR_SPIF) {
  1423. +#endif
  1424. + /*
  1425. + * Read the data into the buffer and reload and start
  1426. + * queue with new data if not finished. If finished
  1427. + * then setup the next transfer
  1428. + */
  1429. + read(drv_data);
  1430. +
  1431. + if (drv_data->rx == drv_data->rx_end) {
  1432. + /*
  1433. + * Finished now - fall through and schedule next
  1434. + * transfer tasklet
  1435. + */
  1436. + if (drv_data->flags & TRAN_STATE_WORD_ODD_NUM) {
  1437. + //*drv_data->qmr &= ~QMR_BITS;
  1438. + set_16bit_transfer_mode(drv_data);
  1439. + }
  1440. +
  1441. + msg->state = next_transfer(drv_data);
  1442. + msg->actual_length += drv_data->len;
  1443. + } else {
  1444. + /* not finished yet - keep going */
  1445. + write(drv_data);
  1446. + return IRQ_HANDLED;
  1447. + }
  1448. +#if !defined(SPI_DSPI)
  1449. + } else {
  1450. + if (irq_status & QIR_WCEF)
  1451. + drv_data->wce_cnt++;
  1452. +
  1453. + if (irq_status & QIR_ABRT)
  1454. + drv_data->abrt_cnt++;
  1455. +
  1456. + msg->state = ERROR_STATE;
  1457. + }
  1458. +#endif
  1459. +
  1460. + tasklet_schedule(&drv_data->pump_transfers);
  1461. +
  1462. + return IRQ_HANDLED;
  1463. +}
  1464. +
  1465. +/* caller already set message->status; dma and pio irqs are blocked */
  1466. +static void giveback(struct driver_data *drv_data)
  1467. +{
  1468. + struct spi_transfer* last_transfer;
  1469. + unsigned long flags;
  1470. + struct spi_message *msg;
  1471. +
  1472. + spin_lock_irqsave(&drv_data->lock, flags);
  1473. + msg = drv_data->cur_msg;
  1474. + drv_data->cur_msg = NULL;
  1475. + drv_data->cur_transfer = NULL;
  1476. + drv_data->cur_chip = NULL;
  1477. + queue_work(drv_data->workqueue, &drv_data->pump_messages);
  1478. + spin_unlock_irqrestore(&drv_data->lock, flags);
  1479. +
  1480. + last_transfer = list_entry(msg->transfers.prev,
  1481. + struct spi_transfer,
  1482. + transfer_list);
  1483. +
  1484. + if (!last_transfer->cs_change)
  1485. + drv_data->cs_control(drv_data->cs, QSPI_CS_DROP);
  1486. +
  1487. + msg->state = NULL;
  1488. + if (msg->complete)
  1489. + msg->complete(msg->context);
  1490. +}
  1491. +
  1492. +
  1493. +static void pump_transfers(unsigned long data)
  1494. +{
  1495. + struct driver_data *drv_data = (struct driver_data *)data;
  1496. + struct spi_message *message = NULL;
  1497. + struct spi_transfer *transfer = NULL;
  1498. + struct spi_transfer *previous = NULL;
  1499. + struct chip_data *chip = NULL;
  1500. + unsigned long flags;
  1501. +
  1502. + /* Get current state information */
  1503. + message = drv_data->cur_msg;
  1504. + transfer = drv_data->cur_transfer;
  1505. + chip = drv_data->cur_chip;
  1506. +
  1507. + /* Handle for abort */
  1508. + if (message->state == ERROR_STATE) {
  1509. + message->status = -EIO;
  1510. + giveback(drv_data);
  1511. + return;
  1512. + }
  1513. +
  1514. + /* Handle end of message */
  1515. + if (message->state == DONE_STATE) {
  1516. + message->status = 0;
  1517. + giveback(drv_data);
  1518. + return;
  1519. + }
  1520. +
  1521. + if (message->state == START_STATE) {
  1522. + qspi_setup_chip(drv_data);
  1523. +
  1524. + if (drv_data->cs_control) {
  1525. + //printk( "m s\n" );
  1526. + drv_data->cs_control(message->spi->chip_select, QSPI_CS_ASSERT);
  1527. + }
  1528. + }
  1529. +
  1530. + /* Delay if requested at end of transfer*/
  1531. + if (message->state == RUNNING_STATE) {
  1532. + previous = list_entry(transfer->transfer_list.prev,
  1533. + struct spi_transfer,
  1534. + transfer_list);
  1535. +
  1536. + if (drv_data->cs_control && transfer->cs_change)
  1537. + drv_data->cs_control(message->spi->chip_select, QSPI_CS_DROP);
  1538. +
  1539. + if (previous->delay_usecs)
  1540. + udelay(previous->delay_usecs);
  1541. +
  1542. + if (drv_data->cs_control && transfer->cs_change)
  1543. + drv_data->cs_control(message->spi->chip_select, QSPI_CS_ASSERT);
  1544. + }
  1545. +
  1546. + drv_data->flags = 0;
  1547. + drv_data->tx = (void *)transfer->tx_buf;
  1548. + drv_data->tx_end = drv_data->tx + transfer->len;
  1549. + drv_data->rx = transfer->rx_buf;
  1550. + drv_data->rx_end = drv_data->rx + transfer->len;
  1551. + drv_data->len = transfer->len;
  1552. + if (!drv_data->rx)
  1553. + drv_data->flags |= TRAN_STATE_RX_VOID;
  1554. + if (!drv_data->tx)
  1555. + drv_data->flags |= TRAN_STATE_TX_VOID;
  1556. + drv_data->cs = message->spi->chip_select;
  1557. + drv_data->cs_change = transfer->cs_change;
  1558. + drv_data->void_write_data = chip->void_write_data;
  1559. +
  1560. + message->state = RUNNING_STATE;
  1561. +
  1562. + /* Go baby, go */
  1563. + local_irq_save(flags);
  1564. + write(drv_data);
  1565. + local_irq_restore(flags);
  1566. +}
  1567. +
  1568. +
  1569. +static void pump_messages(struct work_struct * work)
  1570. +{
  1571. + struct driver_data *drv_data;
  1572. + unsigned long flags;
  1573. +
  1574. + drv_data = container_of(work, struct driver_data, pump_messages);
  1575. +
  1576. + /* Lock queue and check for queue work */
  1577. + spin_lock_irqsave(&drv_data->lock, flags);
  1578. + if (list_empty(&drv_data->queue) || drv_data->run == QUEUE_STOPPED) {
  1579. + drv_data->busy = 0;
  1580. + spin_unlock_irqrestore(&drv_data->lock, flags);
  1581. + return;
  1582. + }
  1583. +
  1584. + /* Make sure we are not already running a message */
  1585. + if (drv_data->cur_msg) {
  1586. + spin_unlock_irqrestore(&drv_data->lock, flags);
  1587. + return;
  1588. + }
  1589. +
  1590. + /* Extract head of queue */
  1591. + drv_data->cur_msg = list_entry(drv_data->queue.next,
  1592. + struct spi_message, queue);
  1593. + list_del_init(&drv_data->cur_msg->queue);
  1594. +
  1595. + /* Initial message state*/
  1596. + drv_data->cur_msg->state = START_STATE;
  1597. + drv_data->cur_transfer = list_entry(drv_data->cur_msg->transfers.next,
  1598. + struct spi_transfer,
  1599. + transfer_list);
  1600. +
  1601. + /* Setup the SPI Registers using the per chip configuration */
  1602. + drv_data->cur_chip = spi_get_ctldata(drv_data->cur_msg->spi);
  1603. +
  1604. + /* Mark as busy and launch transfers */
  1605. + tasklet_schedule(&drv_data->pump_transfers);
  1606. +
  1607. + drv_data->busy = 1;
  1608. + spin_unlock_irqrestore(&drv_data->lock, flags);
  1609. +}
  1610. +
  1611. +/****************************************************************************/
  1612. +
  1613. +/*
  1614. + * SPI master implementation
  1615. + */
  1616. +
  1617. +static int transfer(struct spi_device *spi, struct spi_message *msg)
  1618. +{
  1619. + struct driver_data *drv_data = spi_master_get_devdata(spi->master);
  1620. + unsigned long flags;
  1621. +
  1622. + spin_lock_irqsave(&drv_data->lock, flags);
  1623. +
  1624. + if (drv_data->run == QUEUE_STOPPED) {
  1625. + spin_unlock_irqrestore(&drv_data->lock, flags);
  1626. + return -ESHUTDOWN;
  1627. + }
  1628. +
  1629. + msg->actual_length = 0;
  1630. + msg->status = -EINPROGRESS;
  1631. + msg->state = START_STATE;
  1632. +
  1633. + list_add_tail(&msg->queue, &drv_data->queue);
  1634. +
  1635. + if (drv_data->run == QUEUE_RUNNING && !drv_data->busy)
  1636. + queue_work(drv_data->workqueue, &drv_data->pump_messages);
  1637. +
  1638. + spin_unlock_irqrestore(&drv_data->lock, flags);
  1639. +
  1640. + return 0;
  1641. +}
  1642. +
  1643. +
  1644. +static int setup(struct spi_device *spi)
  1645. +{
  1646. + struct coldfire_spi_chip *chip_info;
  1647. + struct chip_data *chip;
  1648. +#ifndef SPI_DSPI
  1649. + u32 baud_divisor = 255;
  1650. +#endif
  1651. +
  1652. + chip_info = (struct coldfire_spi_chip *)spi->controller_data;
  1653. +
  1654. + /* Only alloc on first setup */
  1655. + chip = spi_get_ctldata(spi);
  1656. + if (chip == NULL) {
  1657. + chip = kcalloc(1, sizeof(struct chip_data), GFP_KERNEL);
  1658. + if (!chip)
  1659. + return -ENOMEM;
  1660. + spi->mode = chip_info->mode;
  1661. + spi->bits_per_word = chip_info->bits_per_word;
  1662. + }
  1663. +
  1664. +#if defined(SPI_DSPI)
  1665. + chip->mcr.master = 1;
  1666. + chip->mcr.cont_scke = 0;
  1667. + chip->mcr.dconf = 0;
  1668. + chip->mcr.frz = 0;
  1669. + chip->mcr.mtfe = 1;
  1670. + chip->mcr.pcsse = 0;
  1671. + chip->mcr.rooe = 0;
  1672. + chip->mcr.pcsis = 0xFF;
  1673. + chip->mcr.reserved15 = 0;
  1674. + chip->mcr.mdis = 0;
  1675. + chip->mcr.dis_tx = 0;
  1676. + chip->mcr.dis_rxf = 0;
  1677. + chip->mcr.clr_tx = 1;
  1678. + chip->mcr.clr_rxf = 1;
  1679. + chip->mcr.smpl_pt = 0;
  1680. + chip->mcr.reserved71 = 0;
  1681. + chip->mcr.halt = 0;
  1682. +
  1683. + if ((spi->bits_per_word >= 4) && (spi->bits_per_word <= 16)) {
  1684. + chip->ctar.fmsz = spi->bits_per_word-1;
  1685. + } else {
  1686. + printk(KERN_ERR "coldfire-qspi: invalid wordsize\n");
  1687. + kfree(chip);
  1688. + return -ENODEV;
  1689. + }
  1690. +
  1691. + if (spi->mode & SPI_CPHA)
  1692. + chip->ctar.cpha = 1;
  1693. + else
  1694. + chip->ctar.cpha = 0;
  1695. +
  1696. + if (spi->mode & SPI_CPOL)
  1697. + chip->ctar.cpol = 1;
  1698. + else
  1699. + chip->ctar.cpol = 0;
  1700. +
  1701. + if (spi->mode & SPI_LSB_FIRST)
  1702. + chip->ctar.lsbfe = 1;
  1703. + else
  1704. + chip->ctar.lsbfe = 0;
  1705. +
  1706. + /* This values are default for audio device */
  1707. + chip->ctar.dbr = 0;
  1708. + chip->ctar.pbr = 2;
  1709. + chip->ctar.br = 8;
  1710. +
  1711. + /* This values are default for audio device */
  1712. + chip->ctar.pcssck = 1;
  1713. + chip->ctar.pasc = 1;
  1714. + chip->ctar.pdt = 1;
  1715. + chip->ctar.cssck = 0;
  1716. + chip->ctar.asc = 1;
  1717. + chip->ctar.dt = 1;
  1718. +
  1719. + chip->void_write_data = chip_info->void_write_data;
  1720. +
  1721. +#else
  1722. +
  1723. + chip->qwr.csiv = 1; // Chip selects are active low
  1724. + chip->qmr.master = 1; // Must set to master mode
  1725. + chip->qmr.dohie = 1; // Data output high impediance enabled
  1726. + chip->void_write_data = chip_info->void_write_data;
  1727. +
  1728. + chip->qdlyr.qcd = chip_info->del_cs_to_clk;
  1729. + chip->qdlyr.dtl = chip_info->del_after_trans;
  1730. +
  1731. + if (spi->max_speed_hz != 0)
  1732. + baud_divisor = (MCF_CLK/(2*spi->max_speed_hz));
  1733. +
  1734. + if (baud_divisor < 2)
  1735. + baud_divisor = 2;
  1736. +
  1737. + if (baud_divisor > 255)
  1738. + baud_divisor = 255;
  1739. +
  1740. + chip->qmr.baud = baud_divisor;
  1741. +
  1742. + //printk( "QSPI: spi->max_speed_hz %d\n", spi->max_speed_hz );
  1743. + //printk( "QSPI: Baud set to %d\n", chip->qmr.baud );
  1744. +
  1745. + if (spi->mode & SPI_CPHA)
  1746. + chip->qmr.cpha = 1;
  1747. +
  1748. + if (spi->mode & SPI_CPOL)
  1749. + chip->qmr.cpol = 1;
  1750. +
  1751. + if (spi->bits_per_word == 16) {
  1752. + chip->qmr.bits = 0;
  1753. + } else if ((spi->bits_per_word >= 8) && (spi->bits_per_word <= 15)) {
  1754. + chip->qmr.bits = spi->bits_per_word;
  1755. + } else {
  1756. + printk(KERN_ERR "coldfire-qspi: invalid wordsize\n");
  1757. + kfree(chip);
  1758. + return -ENODEV;
  1759. + }
  1760. +
  1761. +#endif
  1762. +
  1763. + spi_set_ctldata(spi, chip);
  1764. +
  1765. + return 0;
  1766. +}
  1767. +
  1768. +static int init_queue(struct driver_data *drv_data)
  1769. +{
  1770. + INIT_LIST_HEAD(&drv_data->queue);
  1771. + spin_lock_init(&drv_data->lock);
  1772. +
  1773. + drv_data->run = QUEUE_STOPPED;
  1774. + drv_data->busy = 0;
  1775. +
  1776. + tasklet_init(&drv_data->pump_transfers,
  1777. + pump_transfers, (unsigned long)drv_data);
  1778. +
  1779. + INIT_WORK(&drv_data->pump_messages, pump_messages/*, drv_data*/);
  1780. +
  1781. + drv_data->workqueue = create_singlethread_workqueue(
  1782. + drv_data->master->cdev.dev->bus_id);
  1783. + if (drv_data->workqueue == NULL)
  1784. + return -EBUSY;
  1785. +
  1786. + return 0;
  1787. +}
  1788. +
  1789. +static int start_queue(struct driver_data *drv_data)
  1790. +{
  1791. + unsigned long flags;
  1792. +
  1793. + spin_lock_irqsave(&drv_data->lock, flags);
  1794. +
  1795. + if (drv_data->run == QUEUE_RUNNING || drv_data->busy) {
  1796. + spin_unlock_irqrestore(&drv_data->lock, flags);
  1797. + return -EBUSY;
  1798. + }
  1799. +
  1800. + drv_data->run = QUEUE_RUNNING;
  1801. + drv_data->cur_msg = NULL;
  1802. + drv_data->cur_transfer = NULL;
  1803. + drv_data->cur_chip = NULL;
  1804. + spin_unlock_irqrestore(&drv_data->lock, flags);
  1805. +
  1806. + queue_work(drv_data->workqueue, &drv_data->pump_messages);
  1807. +
  1808. + return 0;
  1809. +}
  1810. +
  1811. +static int stop_queue(struct driver_data *drv_data)
  1812. +{
  1813. + unsigned long flags;
  1814. + unsigned limit = 500;
  1815. + int status = 0;
  1816. +
  1817. + spin_lock_irqsave(&drv_data->lock, flags);
  1818. +
  1819. + /* This is a bit lame, but is optimized for the common execution path.
  1820. + * A wait_queue on the drv_data->busy could be used, but then the common
  1821. + * execution path (pump_messages) would be required to call wake_up or
  1822. + * friends on every SPI message. Do this instead */
  1823. + drv_data->run = QUEUE_STOPPED;
  1824. + while (!list_empty(&drv_data->queue) && drv_data->busy && limit--) {
  1825. + spin_unlock_irqrestore(&drv_data->lock, flags);
  1826. + msleep(10);
  1827. + spin_lock_irqsave(&drv_data->lock, flags);
  1828. + }
  1829. +
  1830. + if (!list_empty(&drv_data->queue) || drv_data->busy)
  1831. + status = -EBUSY;
  1832. +
  1833. + spin_unlock_irqrestore(&drv_data->lock, flags);
  1834. +
  1835. + return status;
  1836. +}
  1837. +
  1838. +static int destroy_queue(struct driver_data *drv_data)
  1839. +{
  1840. + int status;
  1841. +
  1842. + status = stop_queue(drv_data);
  1843. + if (status != 0)
  1844. + return status;
  1845. +
  1846. + destroy_workqueue(drv_data->workqueue);
  1847. +
  1848. + return 0;
  1849. +}
  1850. +
  1851. +
  1852. +static void cleanup(const struct spi_device *spi)
  1853. +{
  1854. + struct chip_data *chip = spi_get_ctldata((struct spi_device *)spi);
  1855. +
  1856. + dev_dbg(&spi->dev, "spi_device %u.%u cleanup\n",
  1857. + spi->master->bus_num, spi->chip_select);
  1858. +
  1859. + kfree(chip);
  1860. +}
  1861. +
  1862. +
  1863. +/****************************************************************************/
  1864. +
  1865. +/*
  1866. + * Generic Device driver routines and interface implementation
  1867. + */
  1868. +
  1869. +static int coldfire_spi_probe(struct platform_device *pdev)
  1870. +{
  1871. + struct device *dev = &pdev->dev;
  1872. + struct coldfire_spi_master *platform_info;
  1873. + struct spi_master *master;
  1874. + struct driver_data *drv_data = 0;
  1875. + struct resource *memory_resource;
  1876. + int irq;
  1877. + int status = 0;
  1878. + int i;
  1879. +
  1880. +#if defined(SPI_DSPI_EDMA)
  1881. + init_edma();
  1882. +#endif
  1883. +
  1884. + platform_info = (struct coldfire_spi_master *)pdev->dev.platform_data;
  1885. +
  1886. + master = spi_alloc_master(dev, sizeof(struct driver_data));
  1887. + if (!master)
  1888. + return -ENOMEM;
  1889. +
  1890. + drv_data = class_get_devdata(&master->cdev);
  1891. + drv_data->master = master;
  1892. +
  1893. + INIT_LIST_HEAD(&drv_data->queue);
  1894. + spin_lock_init(&drv_data->lock);
  1895. +
  1896. + master->bus_num = platform_info->bus_num;
  1897. + master->num_chipselect = platform_info->num_chipselect;
  1898. + master->cleanup = cleanup;
  1899. + master->setup = setup;
  1900. + master->transfer = transfer;
  1901. +
  1902. + drv_data->cs_control = platform_info->cs_control;
  1903. + if (drv_data->cs_control)
  1904. + for(i = 0; i < master->num_chipselect; i++)
  1905. + drv_data->cs_control(i, QSPI_CS_INIT | QSPI_CS_DROP);
  1906. +
  1907. + /* Setup register addresses */
  1908. + memory_resource = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qspi-module");
  1909. + if (!memory_resource) {
  1910. + dev_dbg(dev, "can not find platform module memory\n");
  1911. + goto out_error_master_alloc;
  1912. + }
  1913. +
  1914. +#if defined(SPI_DSPI_EDMA)
  1915. + drv_data->edma_tx_buf = kmalloc(EDMA_BUFSIZE_KMALLOC, GFP_DMA);
  1916. + if (!drv_data->edma_tx_buf) {
  1917. + dev_dbg(dev, "cannot allocate eDMA TX memory\n");
  1918. + goto out_error_master_alloc;
  1919. + }
  1920. + drv_data->edma_rx_buf = kmalloc(EDMA_BUFSIZE_KMALLOC, GFP_DMA);
  1921. + if (!drv_data->edma_rx_buf) {
  1922. + kfree(drv_data->edma_tx_buf);
  1923. + dev_dbg(dev, "cannot allocate eDMA RX memory\n");
  1924. + goto out_error_master_alloc;
  1925. + }
  1926. +#endif
  1927. +
  1928. +#if defined(SPI_DSPI)
  1929. +
  1930. + drv_data->mcr = (void *)(memory_resource->start + 0x00000000);
  1931. + drv_data->ctar = (void *)(memory_resource->start + 0x0000000C);
  1932. + drv_data->dspi_sr = (void *)(memory_resource->start + 0x0000002C);
  1933. + drv_data->dspi_rser = (void *)(memory_resource->start + 0x00000030);
  1934. + drv_data->dspi_dtfr = (void *)(memory_resource->start + 0x00000034);
  1935. + drv_data->dspi_drfr = (void *)(memory_resource->start + 0x00000038);
  1936. +
  1937. +#else
  1938. +
  1939. + drv_data->qmr = (void *)(memory_resource->start + 0x00000000);
  1940. + drv_data->qdlyr = (void *)(memory_resource->start + 0x00000004);
  1941. + drv_data->qwr = (void *)(memory_resource->start + 0x00000008);
  1942. + drv_data->qir = (void *)(memory_resource->start + 0x0000000c);
  1943. + drv_data->qar = (void *)(memory_resource->start + 0x00000010);
  1944. + drv_data->qdr = (void *)(memory_resource->start + 0x00000014);
  1945. + drv_data->qcr = (void *)(memory_resource->start + 0x00000014);
  1946. +
  1947. +#endif
  1948. +
  1949. + /* Setup register addresses */
  1950. + memory_resource = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qspi-par");
  1951. + if (!memory_resource) {
  1952. + dev_dbg(dev, "can not find platform par memory\n");
  1953. + goto out_error_master_alloc;
  1954. + }
  1955. +
  1956. + drv_data->par = (void *)memory_resource->start;
  1957. +
  1958. + /* Setup register addresses */
  1959. + memory_resource = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qspi-int-level");
  1960. + if (!memory_resource) {
  1961. + dev_dbg(dev, "can not find platform par memory\n");
  1962. + goto out_error_master_alloc;
  1963. + }
  1964. +
  1965. + drv_data->int_icr = (void *)memory_resource->start;
  1966. +
  1967. + /* Setup register addresses */
  1968. + memory_resource = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qspi-int-mask");
  1969. + if (!memory_resource) {
  1970. + dev_dbg(dev, "can not find platform par memory\n");
  1971. + goto out_error_master_alloc;
  1972. + }
  1973. +
  1974. + drv_data->int_mr = (void *)memory_resource->start;
  1975. +
  1976. + irq = platform_info->irq_vector;
  1977. +
  1978. + status = request_irq(platform_info->irq_vector, qspi_interrupt, SA_INTERRUPT, dev->bus_id, drv_data);
  1979. + if (status < 0) {
  1980. + dev_err(&pdev->dev, "unable to attach ColdFire QSPI interrupt\n");
  1981. + goto out_error_master_alloc;
  1982. + }
  1983. +
  1984. + /* Now that we have all the addresses etc. Let's set it up */
  1985. + // TODO:
  1986. + //*drv_data->par = platform_info->par_val;
  1987. +
  1988. + MCF_GPIO_PAR_DSPI = 0
  1989. + | MCF_GPIO_PAR_DSPI_PCS5_PCS5
  1990. + | MCF_GPIO_PAR_DSPI_PCS2_PCS2
  1991. + | MCF_GPIO_PAR_DSPI_PCS1_PCS1
  1992. + | MCF_GPIO_PAR_DSPI_PCS0_PCS0
  1993. + | MCF_GPIO_PAR_DSPI_SIN_SIN
  1994. + | MCF_GPIO_PAR_DSPI_SOUT_SOUT
  1995. + | MCF_GPIO_PAR_DSPI_SCK_SCK;
  1996. +
  1997. + *drv_data->int_icr = platform_info->irq_lp;
  1998. + *drv_data->int_mr &= ~platform_info->irq_mask;
  1999. +
  2000. +#ifdef SPI_DSPI
  2001. + drv_data->dspi_ctas = 0; // TODO: change later
  2002. +#endif
  2003. +
  2004. + /* Initial and start queue */
  2005. + status = init_queue(drv_data);
  2006. + if (status != 0) {
  2007. + dev_err(&pdev->dev, "problem initializing queue\n");
  2008. + goto out_error_irq_alloc;
  2009. + }
  2010. + status = start_queue(drv_data);
  2011. + if (status != 0) {
  2012. + dev_err(&pdev->dev, "problem starting queue\n");
  2013. + goto out_error_irq_alloc;
  2014. + }
  2015. +
  2016. + /* Register with the SPI framework */
  2017. + platform_set_drvdata(pdev, drv_data);
  2018. + status = spi_register_master(master);
  2019. + if (status != 0) {
  2020. + dev_err(&pdev->dev, "problem registering spi master\n");
  2021. + status = -EINVAL;
  2022. + goto out_error_queue_alloc;
  2023. + }
  2024. +
  2025. +#if defined(SPI_DSPI_EDMA)
  2026. + if (request_edma_channel(DSPI_DMA_TX_TCD,
  2027. + edma_tx_handler,
  2028. + NULL,
  2029. + pdev,
  2030. + NULL, /* spinlock */
  2031. + DRIVER_NAME
  2032. + )!=0)
  2033. + {
  2034. + dev_err(&pdev->dev, "problem requesting edma transmit channel\n");
  2035. + status = -EINVAL;
  2036. + goto out_error_queue_alloc;
  2037. + }
  2038. +
  2039. + if (request_edma_channel(DSPI_DMA_RX_TCD,
  2040. + edma_rx_handler,
  2041. + NULL,
  2042. + pdev,
  2043. + NULL, /* spinlock */
  2044. + DRIVER_NAME
  2045. + )!=0)
  2046. + {
  2047. + dev_err(&pdev->dev, "problem requesting edma receive channel\n");
  2048. + status = -EINVAL;
  2049. + goto out_edma_transmit;
  2050. + }
  2051. +#endif
  2052. +
  2053. + printk( "SPI: Coldfire master initialized\n" );
  2054. + //dev_info(&pdev->dev, "driver initialized\n");
  2055. + return status;
  2056. +
  2057. +#if defined(SPI_DSPI_EDMA)
  2058. +out_edma_transmit:
  2059. + free_edma_channel(DSPI_DMA_TX_TCD, pdev);
  2060. +#endif
  2061. +
  2062. +out_error_queue_alloc:
  2063. + destroy_queue(drv_data);
  2064. +
  2065. +out_error_irq_alloc:
  2066. + free_irq(irq, drv_data);
  2067. +
  2068. +out_error_master_alloc:
  2069. + spi_master_put(master);
  2070. + return status;
  2071. +
  2072. +}
  2073. +
  2074. +static int coldfire_spi_remove(struct platform_device *pdev)
  2075. +{
  2076. + struct driver_data *drv_data = platform_get_drvdata(pdev);
  2077. + int irq;
  2078. + int status = 0;
  2079. +
  2080. + if (!drv_data)
  2081. + return 0;
  2082. +
  2083. +#if defined(SPI_DSPI_EDMA)
  2084. + free_edma_channel(DSPI_DMA_TX_TCD, pdev);
  2085. + free_edma_channel(DSPI_DMA_RX_TCD, pdev);
  2086. +#endif
  2087. +
  2088. + /* Remove the queue */
  2089. + status = destroy_queue(drv_data);
  2090. + if (status != 0)
  2091. + return status;
  2092. +
  2093. + /* Disable the SSP at the peripheral and SOC level */
  2094. + /*write_SSCR0(0, drv_data->ioaddr);
  2095. + pxa_set_cken(drv_data->master_info->clock_enable, 0);*/
  2096. +
  2097. + /* Release DMA */
  2098. + /*if (drv_data->master_info->enable_dma) {
  2099. + if (drv_data->ioaddr == SSP1_VIRT) {
  2100. + DRCMRRXSSDR = 0;
  2101. + DRCMRTXSSDR = 0;
  2102. + } else if (drv_data->ioaddr == SSP2_VIRT) {
  2103. + DRCMRRXSS2DR = 0;
  2104. + DRCMRTXSS2DR = 0;
  2105. + } else if (drv_data->ioaddr == SSP3_VIRT) {
  2106. + DRCMRRXSS3DR = 0;
  2107. + DRCMRTXSS3DR = 0;
  2108. + }
  2109. + pxa_free_dma(drv_data->tx_channel);
  2110. + pxa_free_dma(drv_data->rx_channel);
  2111. + }*/
  2112. +
  2113. + /* Release IRQ */
  2114. + irq = platform_get_irq(pdev, 0);
  2115. + if (irq >= 0)
  2116. + free_irq(irq, drv_data);
  2117. +
  2118. + /* Disconnect from the SPI framework */
  2119. + spi_unregister_master(drv_data->master);
  2120. +
  2121. + /* Prevent double remove */
  2122. + platform_set_drvdata(pdev, NULL);
  2123. +
  2124. + return 0;
  2125. +}
  2126. +
  2127. +static void coldfire_spi_shutdown(struct platform_device *pdev)
  2128. +{
  2129. + int status = 0;
  2130. +
  2131. + if ((status = coldfire_spi_remove(pdev)) != 0)
  2132. + dev_err(&pdev->dev, "shutdown failed with %d\n", status);
  2133. +}
  2134. +
  2135. +
  2136. +#ifdef CONFIG_PM
  2137. +static int suspend_devices(struct device *dev, void *pm_message)
  2138. +{
  2139. + pm_message_t *state = pm_message;
  2140. +
  2141. + if (dev->power.power_state.event != state->event) {
  2142. + dev_warn(dev, "pm state does not match request\n");
  2143. + return -1;
  2144. + }
  2145. +
  2146. + return 0;
  2147. +}
  2148. +
  2149. +static int coldfire_spi_suspend(struct platform_device *pdev, pm_message_t state)
  2150. +{
  2151. + struct driver_data *drv_data = platform_get_drvdata(pdev);
  2152. + int status = 0;
  2153. +
  2154. + /* Check all childern for current power state */
  2155. + if (device_for_each_child(&pdev->dev, &state, suspend_devices) != 0) {
  2156. + dev_warn(&pdev->dev, "suspend aborted\n");
  2157. + return -1;
  2158. + }
  2159. +
  2160. + status = stop_queue(drv_data);
  2161. + if (status != 0)
  2162. + return status;
  2163. + /*write_SSCR0(0, drv_data->ioaddr);
  2164. + pxa_set_cken(drv_data->master_info->clock_enable, 0);*/
  2165. +
  2166. + return 0;
  2167. +}
  2168. +
  2169. +static int coldfire_spi_resume(struct platform_device *pdev)
  2170. +{
  2171. + struct driver_data *drv_data = platform_get_drvdata(pdev);
  2172. + int status = 0;
  2173. +
  2174. + /* Enable the SSP clock */
  2175. + /*pxa_set_cken(drv_data->master_info->clock_enable, 1);*/
  2176. +
  2177. + /* Start the queue running */
  2178. + status = start_queue(drv_data);
  2179. + if (status != 0) {
  2180. + dev_err(&pdev->dev, "problem starting queue (%d)\n", status);
  2181. + return status;
  2182. + }
  2183. +
  2184. + return 0;
  2185. +}
  2186. +#else
  2187. +#define coldfire_spi_suspend NULL
  2188. +#define coldfire_spi_resume NULL
  2189. +#endif /* CONFIG_PM */
  2190. +
  2191. +static struct platform_driver driver = {
  2192. + .driver = {
  2193. + .name = "spi_coldfire",
  2194. + .bus = &platform_bus_type,
  2195. + .owner = THIS_MODULE,
  2196. + },
  2197. + .probe = coldfire_spi_probe,
  2198. + .remove = __devexit_p(coldfire_spi_remove),
  2199. + .shutdown = coldfire_spi_shutdown,
  2200. + .suspend = coldfire_spi_suspend,
  2201. + .resume = coldfire_spi_resume,
  2202. +};
  2203. +
  2204. +static int __init coldfire_spi_init(void)
  2205. +{
  2206. + platform_driver_register(&driver);
  2207. +
  2208. + return 0;
  2209. +}
  2210. +module_init(coldfire_spi_init);
  2211. +
  2212. +static void __exit coldfire_spi_exit(void)
  2213. +{
  2214. + platform_driver_unregister(&driver);
  2215. +}
  2216. +module_exit(coldfire_spi_exit);
  2217. --- /dev/null
  2218. +++ b/drivers/spi/ssi_audio.c
  2219. @@ -0,0 +1,906 @@
  2220. +/*
  2221. + * MCF5445x audio driver.
  2222. + *
  2223. + * Yaroslav Vinogradov [email protected]
  2224. + * Copyright Freescale Semiconductor, Inc. 2006
  2225. + *
  2226. + * This program is free software; you can redistribute it and/or modify
  2227. + * it under the terms of the GNU General Public License as published by
  2228. + * the Free Software Foundation; either version 2 of the License, or
  2229. + * (at your option) any later version.
  2230. + */
  2231. +
  2232. +#include <linux/device.h>
  2233. +#include <linux/init.h>
  2234. +#include <linux/delay.h>
  2235. +#include <linux/spi/spi.h>
  2236. +#include <linux/fs.h>
  2237. +#include <linux/kernel.h>
  2238. +#include <linux/major.h>
  2239. +#include <asm/mcfsim.h>
  2240. +#include <linux/interrupt.h>
  2241. +#include <linux/soundcard.h>
  2242. +#include <asm/uaccess.h>
  2243. +#include <asm/virtconvert.h>
  2244. +
  2245. +#include <asm/coldfire.h>
  2246. +#include <asm/coldfire_edma.h>
  2247. +#include <asm/mcf5445x_ssi.h>
  2248. +#include <asm/mcf5445x_ccm.h>
  2249. +#include <asm/mcf5445x_gpio.h>
  2250. +
  2251. +#define SOUND_DEVICE_NAME "sound"
  2252. +#define DRIVER_NAME "ssi_audio"
  2253. +
  2254. +
  2255. +/* #define AUDIO_DEBUG */
  2256. +
  2257. +#ifdef CONFIG_MMU
  2258. +#define USE_MMU
  2259. +#endif
  2260. +
  2261. +#define MAX_SPEED_HZ 12000000
  2262. +
  2263. +#define M5445x_AUDIO_IRQ_SOURCE 49
  2264. +#define M5445x_AUDIO_IRQ_VECTOR (128+M5445x_AUDIO_IRQ_SOURCE)
  2265. +#define M5445x_AUDIO_IRQ_LEVEL 5
  2266. +
  2267. +/* TLV320DAC23 audio chip registers */
  2268. +
  2269. +#define CODEC_LEFT_IN_REG (0x00)
  2270. +#define CODEC_RIGHT_IN_REG (0x01)
  2271. +#define CODEC_LEFT_HP_VOL_REG (0x02)
  2272. +#define CODEC_RIGHT_HP_VOL_REG (0x03)
  2273. +#define CODEC_ANALOG_APATH_REG (0x04)
  2274. +#define CODEC_DIGITAL_APATH_REG (0x05)
  2275. +#define CODEC_POWER_DOWN_REG (0x06)
  2276. +#define CODEC_DIGITAL_IF_FMT_REG (0x07)
  2277. +#define CODEC_SAMPLE_RATE_REG (0x08)
  2278. +#define CODEC_DIGITAL_IF_ACT_REG (0x09)
  2279. +#define CODEC_RESET_REG (0x0f)
  2280. +
  2281. +#define CODEC_SAMPLE_8KHZ (0x0C)
  2282. +#define CODEC_SAMPLE_16KHZ (0x58)
  2283. +#define CODEC_SAMPLE_22KHZ (0x62)
  2284. +#define CODEC_SAMPLE_32KHZ (0x18)
  2285. +#define CODEC_SAMPLE_44KHZ (0x22)
  2286. +#define CODEC_SAMPLE_48KHZ (0x00)
  2287. +
  2288. +/* Audio buffer data size */
  2289. +#define BUFSIZE (64*1024)
  2290. +/* DMA transfer size */
  2291. +#define DMASIZE (16*1024)
  2292. +
  2293. +/* transmit eDMA channel for SSI channel 0 */
  2294. +#define DMA_TCD 10
  2295. +/* transmit eDMA channel for SSI channel 1 */
  2296. +#define DMA_TCD2 11
  2297. +
  2298. +struct ssi_audio {
  2299. + struct spi_device *spi;
  2300. + u32 speed;
  2301. + u32 stereo;
  2302. + u32 bits;
  2303. + u32 format;
  2304. + u8 isopen;
  2305. + u8 dmaing;
  2306. + u8 ssi_enabled;
  2307. + u8 channel;
  2308. + spinlock_t lock;
  2309. + u8* audio_buf;
  2310. +};
  2311. +
  2312. +static struct ssi_audio* audio_device = NULL;
  2313. +volatile u32 audio_start;
  2314. +volatile u32 audio_count;
  2315. +volatile u32 audio_append;
  2316. +volatile u32 audio_appstart;
  2317. +volatile u32 audio_txbusy;
  2318. +
  2319. +struct ssi_audio_format {
  2320. + unsigned int format;
  2321. + unsigned int bits;
  2322. +} ssi_audio_formattable[] = {
  2323. + { AFMT_MU_LAW, 8 },
  2324. + { AFMT_A_LAW, 8 },
  2325. + { AFMT_IMA_ADPCM, 8 },
  2326. + { AFMT_U8, 8 },
  2327. + { AFMT_S16_LE, 16 },
  2328. + { AFMT_S16_BE, 16 },
  2329. + { AFMT_S8, 8 },
  2330. + { AFMT_U16_LE, 16 },
  2331. + { AFMT_U16_BE, 16 },
  2332. +};
  2333. +
  2334. +#define FORMATSIZE (sizeof(ssi_audio_formattable) / sizeof(struct ssi_audio_format))
  2335. +
  2336. +static void ssi_audio_setsamplesize(int val)
  2337. +{
  2338. + int i;
  2339. +
  2340. + if (audio_device == NULL) return;
  2341. +
  2342. + for (i = 0; (i < FORMATSIZE); i++) {
  2343. + if (ssi_audio_formattable[i].format == val) {
  2344. + audio_device->format = ssi_audio_formattable[i].format;
  2345. + audio_device->bits = ssi_audio_formattable[i].bits;
  2346. + break;
  2347. + }
  2348. + }
  2349. +
  2350. +#ifdef AUDIO_DEBUG
  2351. + printk(DRIVER_NAME ":ssi_audio_setsamplesize %d %d\n", audio_device->format, audio_device->bits);
  2352. +#endif
  2353. +}
  2354. +
  2355. +static void ssi_audio_txdrain(void)
  2356. +{
  2357. +#ifdef AUDIO_DEBUG
  2358. + printk(DRIVER_NAME ":ssi_audio_txdrain()\n");
  2359. +#endif
  2360. +
  2361. + if (audio_device == NULL) return;
  2362. +
  2363. + while (!signal_pending(current)) {
  2364. + if (audio_txbusy == 0)
  2365. + break;
  2366. + current->state = TASK_INTERRUPTIBLE;
  2367. + schedule_timeout(1);
  2368. + }
  2369. +}
  2370. +
  2371. +#ifdef CONFIG_SSIAUDIO_USE_EDMA
  2372. +/*
  2373. + * Configure and start DMA engine.
  2374. + */
  2375. +void __inline__ ssi_audio_dmarun(void)
  2376. +{
  2377. + set_edma_params(DMA_TCD,
  2378. +#ifdef USE_MMU
  2379. + virt_to_phys(&(audio_device->audio_buf[audio_start])),
  2380. +#else
  2381. + (u32)&(audio_device->audio_buf[audio_start]),
  2382. +#endif
  2383. + (u32)&MCF_SSI_TX0,
  2384. + MCF_EDMA_TCD_ATTR_SSIZE_32BIT | MCF_EDMA_TCD_ATTR_DSIZE_32BIT,
  2385. + 8,
  2386. + 4,
  2387. + 0,
  2388. + audio_count/8,
  2389. + audio_count/8,
  2390. + 0,
  2391. + 0,
  2392. + 0, // major_int
  2393. + 0 // disable_req
  2394. + );
  2395. +
  2396. + set_edma_params(DMA_TCD2,
  2397. +#ifdef USE_MMU
  2398. + virt_to_phys(&(audio_device->audio_buf[audio_start+4])),
  2399. +#else
  2400. + (u32)&(audio_device->audio_buf[audio_start+4]),
  2401. +#endif
  2402. + (u32)&MCF_SSI_TX1,
  2403. + MCF_EDMA_TCD_ATTR_SSIZE_32BIT | MCF_EDMA_TCD_ATTR_DSIZE_32BIT,
  2404. + 8,
  2405. + 4,
  2406. + 0,
  2407. + audio_count/8,
  2408. + audio_count/8,
  2409. + 0,
  2410. + 0,
  2411. + 1, // major_int
  2412. + 0 // disable_req
  2413. + );
  2414. +
  2415. + audio_device->dmaing = 1;
  2416. + audio_txbusy = 1;
  2417. +
  2418. + start_edma_transfer(DMA_TCD);
  2419. + start_edma_transfer(DMA_TCD2);
  2420. +#if 0
  2421. + MCF_EDMA_ERQ |= (1<<DMA_TCD) | (1<<DMA_TCD2);
  2422. + MCF_EDMA_SSRT = DMA_TCD;
  2423. + MCF_EDMA_SSRT = DMA_TCD2;
  2424. +#endif
  2425. +
  2426. +}
  2427. +
  2428. +/*
  2429. + * Start DMA'ing a new buffer of data if any available.
  2430. + */
  2431. +static void ssi_audio_dmabuf(void)
  2432. +{
  2433. +#ifdef AUDIO_DEBUG
  2434. + printk(DRIVER_NAME ":ssi_audio_dmabuf(): append=%x start=%x\n", audio_append, audio_appstart);
  2435. +#endif
  2436. +
  2437. + /* If already running then nothing to do... */
  2438. + if (audio_device->dmaing)
  2439. + return;
  2440. +
  2441. + /* Set DMA buffer size */
  2442. + audio_count = (audio_append >= audio_appstart) ?
  2443. + (audio_append - audio_appstart) :
  2444. + (BUFSIZE - audio_appstart);
  2445. + if (audio_count > DMASIZE)
  2446. + audio_count = DMASIZE;
  2447. +
  2448. + /* Adjust pointers and counters accordingly */
  2449. + audio_appstart += audio_count;
  2450. + if (audio_appstart >= BUFSIZE)
  2451. + audio_appstart = 0;
  2452. +
  2453. + if (audio_count > 0)
  2454. + ssi_audio_dmarun();
  2455. + else {
  2456. + audio_txbusy = 0;
  2457. +#ifdef AUDIO_DEBUG
  2458. + printk(DRIVER_NAME ":DMA buffer is empty!\n");
  2459. +#endif
  2460. + }
  2461. +}
  2462. +
  2463. +void __inline__ stop_dma(void) {
  2464. + stop_edma_transfer(DMA_TCD);
  2465. + stop_edma_transfer(DMA_TCD2);
  2466. +}
  2467. +
  2468. +static int ssi_audio_dma_handler_empty(int channel, void *dev_id)
  2469. +{
  2470. + return IRQ_HANDLED;
  2471. +}
  2472. +
  2473. +static int ssi_audio_dma_handler(int channel, void *dev_id)
  2474. +{
  2475. +#ifdef AUDIO_DEBUG
  2476. + printk(DRIVER_NAME ":ssi_audio_dma_handler(channel=%d)\n", channel);
  2477. +#endif
  2478. +
  2479. + /* Clear DMA interrupt */
  2480. + stop_dma();
  2481. +
  2482. + audio_device->dmaing = 0;
  2483. +
  2484. + /* Update data pointers and counts */
  2485. + audio_start += audio_count;
  2486. + if (audio_start >= BUFSIZE)
  2487. + audio_start = 0;
  2488. + audio_count = 0;
  2489. +
  2490. + /* Start new DMA buffer if we can */
  2491. + ssi_audio_dmabuf();
  2492. +
  2493. + return IRQ_HANDLED;
  2494. +}
  2495. +
  2496. +static void init_dma(void)
  2497. +{
  2498. + /* SSI DMA Signals mapped to DMA request */
  2499. + MCF_CCM_MISCCR &= ~MCF_CCM_MISCCR_TIMDMA;
  2500. + init_edma();
  2501. +}
  2502. +
  2503. +#endif /* CONFIG_SSIAUDIO_USE_EDMA */
  2504. +
  2505. +
  2506. +/* Write CODEC register using SPI
  2507. + * address - CODEC register address
  2508. + * data - data to be written into register
  2509. + */
  2510. +static int codec_write(u8 addr, u16 data)
  2511. +{
  2512. + u16 spi_word;
  2513. +
  2514. + if (audio_device==NULL || audio_device->spi==NULL)
  2515. + return -ENODEV;
  2516. +
  2517. + spi_word = ((addr & 0x7F)<<9)|(data & 0x1FF);
  2518. + return spi_write(audio_device->spi, (const u8*)&spi_word, sizeof(spi_word));
  2519. +}
  2520. +
  2521. +static inline void enable_ssi(void)
  2522. +{
  2523. + if (audio_device==NULL || audio_device->ssi_enabled) return;
  2524. + audio_device->ssi_enabled = 1;
  2525. + MCF_SSI_CR |= MCF_SSI_CR_SSI_EN; /* enable SSI module */
  2526. + MCF_SSI_CR |= MCF_SSI_CR_TE; /* enable tranmitter */
  2527. +}
  2528. +
  2529. +static inline void disable_ssi(void)
  2530. +{
  2531. + if (audio_device==NULL || audio_device->ssi_enabled==0) return;
  2532. + MCF_SSI_CR &= ~MCF_SSI_CR_TE; /* disable transmitter */
  2533. + MCF_SSI_CR &= ~MCF_SSI_CR_SSI_EN; /* disable SSI module */
  2534. + audio_device->ssi_enabled = 0;
  2535. +}
  2536. +
  2537. +/* Audio CODEC initialization */
  2538. +/* TODO: also the SSI frequency/dividers must be adjusted */
  2539. +static void adjust_codec_speed(void) {
  2540. +#ifdef AUDIO_DEBUG
  2541. + printk(DRIVER_NAME ":adjust_codec_speed: %d\n", audio_device->speed);
  2542. +#endif
  2543. +
  2544. + if (audio_device->speed == 8000) {
  2545. + codec_write(CODEC_SAMPLE_RATE_REG,CODEC_SAMPLE_8KHZ);
  2546. + } else if (audio_device->speed == 16000) {
  2547. + codec_write(CODEC_SAMPLE_RATE_REG,CODEC_SAMPLE_16KHZ);
  2548. + } else if (audio_device->speed == 22000) {
  2549. + codec_write(CODEC_SAMPLE_RATE_REG,CODEC_SAMPLE_22KHZ);
  2550. + } else if (audio_device->speed == 44000 || audio_device->speed == 44100) {
  2551. + codec_write(CODEC_SAMPLE_RATE_REG,CODEC_SAMPLE_44KHZ);
  2552. + } else if (audio_device->speed == 48000) {
  2553. + codec_write(CODEC_SAMPLE_RATE_REG,CODEC_SAMPLE_48KHZ);
  2554. + } else {
  2555. + /* default 44KHz */
  2556. + codec_write(CODEC_SAMPLE_RATE_REG,CODEC_SAMPLE_44KHZ);
  2557. + }
  2558. +}
  2559. +
  2560. +static void codec_reset(void)
  2561. +{
  2562. + codec_write(CODEC_RESET_REG, 0); /* reset the audio chip */
  2563. + udelay(1500); /* wait for reset */
  2564. +}
  2565. +
  2566. +static void init_audio_codec(void)
  2567. +{
  2568. +#ifdef AUDIO_DEBUG
  2569. + printk(DRIVER_NAME ":init_audio_codec()\n");
  2570. +#endif
  2571. + codec_reset();
  2572. +
  2573. + codec_write(CODEC_LEFT_IN_REG, 0x017);
  2574. + codec_write(CODEC_RIGHT_IN_REG, 0x017);
  2575. + codec_write(CODEC_POWER_DOWN_REG, 0x000); /* Turn off line input */
  2576. + codec_write(CODEC_DIGITAL_IF_FMT_REG, 0x00A); /* I2S slave mode */
  2577. + /* codec_write(CODEC_DIGITAL_IF_FMT_REG, 0x042); // I2S master mode */
  2578. + codec_write(CODEC_DIGITAL_APATH_REG, 0x007); /* Set A path */
  2579. +
  2580. + /* set sample rate */
  2581. + adjust_codec_speed();
  2582. +
  2583. + codec_write(CODEC_LEFT_HP_VOL_REG, 0x075); /* set volume */
  2584. + codec_write(CODEC_RIGHT_HP_VOL_REG, 0x075); /* set volume */
  2585. + codec_write(CODEC_DIGITAL_IF_ACT_REG, 1); /* Activate digital interface */
  2586. + codec_write(CODEC_ANALOG_APATH_REG, 0x0F2);
  2587. +}
  2588. +
  2589. +
  2590. +static void chip_init(void)
  2591. +{
  2592. +#ifdef CONFIG_SSIAUDIO_USE_EDMA
  2593. + init_dma();
  2594. +#endif
  2595. +
  2596. + /* Enable the SSI pins */
  2597. + MCF_GPIO_PAR_SSI = ( 0
  2598. + | MCF_GPIO_PAR_SSI_MCLK
  2599. + | MCF_GPIO_PAR_SSI_STXD(3)
  2600. + | MCF_GPIO_PAR_SSI_SRXD(3)
  2601. + | MCF_GPIO_PAR_SSI_FS(3)
  2602. + | MCF_GPIO_PAR_SSI_BCLK(3) );
  2603. +
  2604. +}
  2605. +
  2606. +static void init_ssi(void)
  2607. +{
  2608. +#ifdef AUDIO_DEBUG
  2609. + printk(DRIVER_NAME ":init_ssi()\n");
  2610. +#endif
  2611. +
  2612. + /* Dividers are for MCF54445 on 266Mhz, the output is 44.1Khz*/
  2613. + /* Enable SSI clock in CCM */
  2614. + MCF_CCM_CDR = MCF_CCM_CDR_SSIDIV(47);
  2615. +
  2616. + /* Issue a SSI reset */
  2617. + MCF_SSI_CR &= ~MCF_SSI_CR_SSI_EN; /* disable SSI module */
  2618. +
  2619. + /* SSI module uses internal CPU clock */
  2620. + MCF_CCM_MISCCR |= MCF_CCM_MISCCR_SSISRC;
  2621. +
  2622. + MCF_CCM_MISCCR |= MCF_CCM_MISCCR_SSIPUE;
  2623. + MCF_CCM_MISCCR |= MCF_CCM_MISCCR_SSIPUS_UP;
  2624. +
  2625. + MCF_SSI_CR = 0
  2626. + | MCF_SSI_CR_CIS
  2627. + | MCF_SSI_CR_TCH /* Enable two channel mode */
  2628. + | MCF_SSI_CR_MCE /* Set clock out on SSI_MCLK pin */
  2629. + | MCF_SSI_CR_I2S_MASTER /* Set I2S master mode */
  2630. + | MCF_SSI_CR_SYN /* Enable synchronous mode */
  2631. + | MCF_SSI_CR_NET
  2632. + ;
  2633. +
  2634. + MCF_SSI_TCR = 0
  2635. + | MCF_SSI_TCR_TXDIR /* internally generated bit clock */
  2636. + | MCF_SSI_TCR_TFDIR /* internally generated frame sync */
  2637. + | MCF_SSI_TCR_TSCKP /* Clock data on falling edge of bit clock */
  2638. + | MCF_SSI_TCR_TFSI /* Frame sync active low */
  2639. + | MCF_SSI_TCR_TEFS /* TX frame sync 1 bit before data */
  2640. + | MCF_SSI_TCR_TFEN0 /* TX FIFO 0 enabled */
  2641. + | MCF_SSI_TCR_TFEN1 /* TX FIFO 1 enabled */
  2642. + | MCF_SSI_TCR_TXBIT0
  2643. + ;
  2644. +
  2645. + MCF_SSI_CCR = MCF_SSI_CCR_WL(7) /* 16 bit word length */
  2646. + | MCF_SSI_CCR_DC(1) /* Frame rate divider */
  2647. + | MCF_SSI_CCR_PM(0)
  2648. + | MCF_SSI_CCR_DIV2
  2649. + ;
  2650. +
  2651. + MCF_SSI_FCSR = 0
  2652. + | MCF_SSI_FCSR_TFWM0(0)
  2653. + | MCF_SSI_FCSR_TFWM1(0)
  2654. + ;
  2655. +
  2656. + MCF_SSI_IER = 0 // interrupts
  2657. +#ifndef CONFIG_SSIAUDIO_USE_EDMA
  2658. + | MCF_SSI_IER_TIE /* transmit interrupts */
  2659. + | MCF_SSI_IER_TFE0 /* transmit FIFO 0 empty */
  2660. + | MCF_SSI_IER_TFE1 /* transmit FIFO 1 empty */
  2661. +#else
  2662. + | MCF_SSI_IER_TDMAE /* DMA request enabled */
  2663. + | MCF_SSI_IER_TFE0 /* transmit FIFO 0 empty */
  2664. + | MCF_SSI_IER_TFE1 /* transmit FIFO 1 empty */
  2665. +#endif
  2666. + ;
  2667. +
  2668. +#ifndef CONFIG_SSIAUDIO_USE_EDMA
  2669. + /* enable IRQ: SSI interrupt */
  2670. + MCF_INTC1_ICR(M5445x_AUDIO_IRQ_SOURCE) = M5445x_AUDIO_IRQ_LEVEL;
  2671. + MCF_INTC1_CIMR = M5445x_AUDIO_IRQ_SOURCE;
  2672. +#endif
  2673. +}
  2674. +
  2675. +#ifndef CONFIG_SSIAUDIO_USE_EDMA
  2676. +/* interrupt for SSI */
  2677. +static int ssi_audio_isr(int irq, void *dev_id)
  2678. +{
  2679. + unsigned long *bp;
  2680. +
  2681. + if (audio_txbusy==0) {
  2682. + return IRQ_HANDLED;
  2683. + }
  2684. +
  2685. + spin_lock(&(audio_device->lock));
  2686. +
  2687. + if (audio_start == audio_append) {
  2688. + disable_ssi();
  2689. + audio_txbusy = 0;
  2690. + } else {
  2691. + if (MCF_SSI_ISR & (MCF_SSI_ISR_TFE0|MCF_SSI_ISR_TFE1)) {
  2692. + bp = (unsigned long *) &audio_device->audio_buf[audio_start];
  2693. + if (audio_device->channel) {
  2694. + MCF_SSI_TX1 = *bp;
  2695. + audio_device->channel = 0;
  2696. + } else {
  2697. + MCF_SSI_TX0 = *bp;
  2698. + audio_device->channel = 1;
  2699. + }
  2700. + audio_start += 4;
  2701. + if (audio_start >= BUFSIZE)
  2702. + audio_start = 0;
  2703. + }
  2704. + }
  2705. +
  2706. + spin_unlock(&(audio_device->lock));
  2707. +
  2708. + return IRQ_HANDLED;
  2709. +}
  2710. +#endif
  2711. +
  2712. +/* Set initial driver playback defaults. */
  2713. +static void init_driver_variables(void)
  2714. +{
  2715. + audio_device->speed = 44100;
  2716. + audio_device->format = AFMT_S16_LE;
  2717. + audio_device->bits = 16;
  2718. + audio_device->stereo = 1;
  2719. + audio_device->ssi_enabled = 0;
  2720. +
  2721. + audio_start = 0;
  2722. + audio_count = 0;
  2723. + audio_append = 0;
  2724. + audio_appstart = 0;
  2725. + audio_txbusy = 0;
  2726. + audio_device->dmaing = 0;
  2727. +}
  2728. +
  2729. +/* open audio device */
  2730. +static int ssi_audio_open(struct inode *inode, struct file *filp)
  2731. +{
  2732. +#ifdef AUDIO_DEBUG
  2733. + printk(DRIVER_NAME ":ssi_audio_open()\n");
  2734. +#endif
  2735. +
  2736. + if (audio_device==NULL) return (-ENODEV);
  2737. +
  2738. + if (audio_device->isopen)
  2739. + return(-EBUSY);
  2740. +
  2741. + spin_lock(&(audio_device->lock));
  2742. +
  2743. + audio_device->isopen = 1;
  2744. +
  2745. + init_driver_variables();
  2746. + init_ssi();
  2747. + init_audio_codec();
  2748. +
  2749. + spin_unlock(&(audio_device->lock));
  2750. +
  2751. + udelay(100);
  2752. +
  2753. + return 0;
  2754. +}
  2755. +
  2756. +/* close audio device */
  2757. +static int ssi_audio_close(struct inode *inode, struct file *filp)
  2758. +{
  2759. +#ifdef AUDIO_DEBUG
  2760. + printk(DRIVER_NAME ":ssi_audio_close()\n");
  2761. +#endif
  2762. +
  2763. + if (audio_device==NULL) return (-ENODEV);
  2764. +
  2765. + ssi_audio_txdrain();
  2766. +
  2767. + spin_lock(&(audio_device->lock));
  2768. +
  2769. +#ifdef CONFIG_SSIAUDIO_USE_EDMA
  2770. + stop_dma();
  2771. +#endif
  2772. + disable_ssi();
  2773. + codec_reset();
  2774. + init_driver_variables();
  2775. + audio_device->isopen = 0;
  2776. +
  2777. + spin_unlock(&(audio_device->lock));
  2778. + return 0;
  2779. +}
  2780. +
  2781. +/* write to audio device */
  2782. +static ssize_t ssi_audio_write(struct file *filp, const char *buf, size_t count, loff_t *ppos)
  2783. +{
  2784. + unsigned long *dp, *buflp;
  2785. + unsigned short *bufwp;
  2786. + unsigned char *bufbp;
  2787. + unsigned int slen, bufcnt, i, s, e;
  2788. +
  2789. +#ifdef AUDIO_DEBUG
  2790. + printk(DRIVER_NAME ":ssi_audio_write(buf=%x,count=%d)\n", (int) buf, count);
  2791. +#endif
  2792. +
  2793. + if (audio_device==NULL) return (-ENODEV);
  2794. +
  2795. + if (count <= 0)
  2796. + return 0;
  2797. +
  2798. + spin_lock(&(audio_device->lock));
  2799. +
  2800. + buflp = (unsigned long *) buf;
  2801. + bufwp = (unsigned short *) buf;
  2802. + bufbp = (unsigned char *) buf;
  2803. +
  2804. + bufcnt = count & ~0x3;
  2805. +
  2806. + bufcnt <<= 1;
  2807. + if (audio_device->stereo == 0)
  2808. + bufcnt <<= 1;
  2809. + if (audio_device->bits == 8)
  2810. + bufcnt <<= 1;
  2811. +
  2812. +tryagain:
  2813. + /*
  2814. + * Get a snapshot of buffer, so we can figure out how
  2815. + * much data we can fit in...
  2816. + */
  2817. + s = audio_start;
  2818. + e = audio_append;
  2819. + dp = (unsigned long *) &(audio_device->audio_buf[e]);
  2820. +
  2821. + slen = ((s > e) ? (s - e) : (BUFSIZE - (e - s))) - 4;
  2822. + if (slen > bufcnt)
  2823. + slen = bufcnt;
  2824. + if ((BUFSIZE - e) < slen)
  2825. + slen = BUFSIZE - e;
  2826. +
  2827. + if (slen == 0) {
  2828. + if (signal_pending(current))
  2829. + return(-ERESTARTSYS);
  2830. + set_current_state(TASK_INTERRUPTIBLE);
  2831. + schedule_timeout(1);
  2832. + goto tryagain;
  2833. + }
  2834. +
  2835. + /* For DMA we need to have data as 32 bit
  2836. + values (since SSI TX register is 32 bit).
  2837. + So, the incomming 16 bit data must be put to buffer as 32 bit values.
  2838. + Also, the endianess is converted if needed
  2839. + */
  2840. + if (audio_device->stereo) {
  2841. + if (audio_device->bits == 16) {
  2842. + if (audio_device->format==AFMT_S16_LE) {
  2843. + /*- convert endianess, probably could be done by SSI also */
  2844. + for (i = 0; (i < slen); i += 4) {
  2845. + unsigned short val = le16_to_cpu((*bufwp++));
  2846. + *dp++ = val;
  2847. + }
  2848. + } else {
  2849. + for (i = 0; (i < slen); i += 4) {
  2850. + *dp++ = *bufwp++;
  2851. + }
  2852. + }
  2853. + } else {
  2854. + for (i = 0; (i < slen); i += 4) {
  2855. + *dp = (((unsigned long) *bufbp++) << 24);
  2856. + *dp++ |= (((unsigned long) *bufbp++) << 8);
  2857. + }
  2858. + }
  2859. + } else {
  2860. + if (audio_device->bits == 16) {
  2861. + for (i = 0; (i < slen); i += 4) {
  2862. + *dp++ = (((unsigned long)*bufwp)<<16) | *bufwp;
  2863. + bufwp++;
  2864. + }
  2865. + } else {
  2866. + for (i = 0; (i < slen); i += 4) {
  2867. + *dp++ = (((unsigned long) *bufbp) << 24) |
  2868. + (((unsigned long) *bufbp) << 8);
  2869. + bufbp++;
  2870. + }
  2871. + }
  2872. + }
  2873. +
  2874. + e += slen;
  2875. + if (e >= BUFSIZE)
  2876. + e = 0;
  2877. + audio_append = e;
  2878. +
  2879. + /* If not outputing audio, then start now */
  2880. + if (audio_txbusy == 0) {
  2881. + audio_txbusy++;
  2882. + audio_device->channel = 0;
  2883. + enable_ssi();
  2884. +#ifdef CONFIG_SSIAUDIO_USE_EDMA
  2885. + ssi_audio_dmabuf(); /* start first DMA transfer */
  2886. +#endif
  2887. + }
  2888. +
  2889. + bufcnt -= slen;
  2890. +
  2891. + if (bufcnt > 0)
  2892. + goto tryagain;
  2893. +
  2894. + spin_unlock(&(audio_device->lock));
  2895. +
  2896. + return count;
  2897. +}
  2898. +
  2899. +/* ioctl: control the driver */
  2900. +static int ssi_audio_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
  2901. +{
  2902. + long val;
  2903. + int rc = 0;
  2904. +
  2905. +#ifdef AUDIO_DEBUG
  2906. + printk(DRIVER_NAME ":ssi_audio_ioctl(cmd=%x,arg=%x)\n", (int) cmd, (int) arg);
  2907. +#endif
  2908. +
  2909. + if (audio_device==NULL) return (-ENODEV);
  2910. +
  2911. + switch (cmd) {
  2912. +
  2913. + case SNDCTL_DSP_SPEED:
  2914. + if (access_ok(VERIFY_READ, (void *) arg, sizeof(val))) {
  2915. + get_user(val, (unsigned long *) arg);
  2916. +#ifdef AUDIO_DEBUG
  2917. + printk(DRIVER_NAME ":ssi_audio_ioctl: SNDCTL_DSP_SPEED: %ld\n", val);
  2918. +#endif
  2919. + ssi_audio_txdrain();
  2920. + audio_device->speed = val;
  2921. + init_audio_codec();
  2922. + } else {
  2923. + rc = -EINVAL;
  2924. + }
  2925. + break;
  2926. +
  2927. + case SNDCTL_DSP_SAMPLESIZE:
  2928. + if (access_ok(VERIFY_READ, (void *) arg, sizeof(val))) {
  2929. + get_user(val, (unsigned long *) arg);
  2930. + ssi_audio_txdrain();
  2931. + ssi_audio_setsamplesize(val);
  2932. + } else {
  2933. + rc = -EINVAL;
  2934. + }
  2935. + break;
  2936. +
  2937. + case SNDCTL_DSP_STEREO:
  2938. + if (access_ok(VERIFY_READ, (void *) arg, sizeof(val))) {
  2939. + get_user(val, (unsigned long *) arg);
  2940. + ssi_audio_txdrain();
  2941. + audio_device->stereo = val;
  2942. + } else {
  2943. + rc = -EINVAL;
  2944. + }
  2945. + break;
  2946. +
  2947. + case SNDCTL_DSP_GETBLKSIZE:
  2948. + if (access_ok(VERIFY_WRITE, (void *) arg, sizeof(long)))
  2949. + put_user(BUFSIZE, (long *) arg);
  2950. + else
  2951. + rc = -EINVAL;
  2952. + break;
  2953. +
  2954. + case SNDCTL_DSP_SYNC:
  2955. + ssi_audio_txdrain();
  2956. + break;
  2957. +
  2958. + default:
  2959. + rc = -EINVAL;
  2960. + break;
  2961. + }
  2962. +
  2963. + return rc;
  2964. +}
  2965. +
  2966. +/****************************************************************************/
  2967. +
  2968. +struct file_operations ssi_audio_fops = {
  2969. + open: ssi_audio_open, /* open */
  2970. + release: ssi_audio_close, /* close */
  2971. + write: ssi_audio_write, /* write */
  2972. + ioctl: ssi_audio_ioctl, /* ioctl */
  2973. +};
  2974. +
  2975. +/* initialize audio driver */
  2976. +static int __devinit ssi_audio_probe(struct spi_device *spi)
  2977. +{
  2978. + struct ssi_audio *audio;
  2979. + int err;
  2980. +
  2981. +#ifdef AUDIO_DEBUG
  2982. + printk(DRIVER_NAME": probe\n");
  2983. +#endif
  2984. +
  2985. + if (!spi->irq) {
  2986. + dev_dbg(&spi->dev, "no IRQ?\n");
  2987. + return -ENODEV;
  2988. + }
  2989. +
  2990. + /* don't exceed max specified sample rate */
  2991. + if (spi->max_speed_hz > MAX_SPEED_HZ) {
  2992. + dev_dbg(&spi->dev, "f(sample) %d KHz?\n",
  2993. + (spi->max_speed_hz)/1000);
  2994. + return -EINVAL;
  2995. + }
  2996. +
  2997. + /* register charcter device */
  2998. + if (register_chrdev(SOUND_MAJOR, SOUND_DEVICE_NAME, &ssi_audio_fops) < 0) {
  2999. + printk(KERN_WARNING DRIVER_NAME ": failed to register major %d\n", SOUND_MAJOR);
  3000. + dev_dbg(&spi->dev, DRIVER_NAME ": failed to register major %d\n", SOUND_MAJOR);
  3001. + return -ENODEV;
  3002. + }
  3003. +
  3004. + audio = kzalloc(sizeof(struct ssi_audio), GFP_KERNEL);
  3005. + if (!audio) {
  3006. + err = -ENOMEM;
  3007. + goto err_out;
  3008. + }
  3009. +
  3010. + /* DMA buffer must be from GFP_DMA zone, so it will not be cached */
  3011. + audio->audio_buf = kmalloc(BUFSIZE, GFP_DMA);
  3012. + if (audio->audio_buf == NULL) {
  3013. + dev_dbg(&spi->dev, DRIVER_NAME ": failed to allocate DMA[%d] buffer\n", BUFSIZE);
  3014. + err = -ENOMEM;
  3015. + goto err_free_mem;
  3016. + }
  3017. +
  3018. + audio_device = audio;
  3019. +
  3020. + dev_set_drvdata(&spi->dev, audio);
  3021. + spi->dev.power.power_state = PMSG_ON;
  3022. +
  3023. + audio->spi = spi;
  3024. +
  3025. +#ifndef CONFIG_SSIAUDIO_USE_EDMA
  3026. + if (request_irq(spi->irq, ssi_audio_isr, SA_INTERRUPT, spi->dev.bus_id, audio)) {
  3027. + dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
  3028. + err = -EBUSY;
  3029. + goto err_free_mem;
  3030. + }
  3031. +
  3032. +#else
  3033. + /* request 2 eDMA channels since two channel output mode is used */
  3034. + if (request_edma_channel(DMA_TCD,
  3035. + ssi_audio_dma_handler_empty,
  3036. + NULL,
  3037. + audio,
  3038. + &(audio_device->lock),
  3039. + DRIVER_NAME
  3040. + )!=0)
  3041. + {
  3042. + dev_dbg(&spi->dev, "DMA channel %d busy?\n", DMA_TCD);
  3043. + err = -EBUSY;
  3044. + goto err_free_mem;
  3045. + }
  3046. + if (request_edma_channel(DMA_TCD2,
  3047. + ssi_audio_dma_handler,
  3048. + NULL,
  3049. + audio,
  3050. + &(audio_device->lock),
  3051. + DRIVER_NAME
  3052. + )!=0)
  3053. + {
  3054. + dev_dbg(&spi->dev, "DMA channel %d busy?\n", DMA_TCD2);
  3055. + err = -EBUSY;
  3056. + goto err_free_mem;
  3057. + }
  3058. +
  3059. +#endif
  3060. + chip_init();
  3061. + printk(DRIVER_NAME ": Probed successfully\n");
  3062. +
  3063. + return 0;
  3064. +
  3065. + err_free_mem:
  3066. + kfree(audio);
  3067. + audio_device = NULL;
  3068. + err_out:
  3069. + unregister_chrdev(SOUND_MAJOR, SOUND_DEVICE_NAME);
  3070. + return err;
  3071. +}
  3072. +
  3073. +static int __devexit ssi_audio_remove(struct spi_device *spi)
  3074. +{
  3075. + struct ssi_audio *audio = dev_get_drvdata(&spi->dev);
  3076. +
  3077. + ssi_audio_txdrain();
  3078. +#ifndef CONFIG_SSIAUDIO_USE_EDMA
  3079. + free_irq(spi->irq, audio);
  3080. +#else
  3081. + free_edma_channel(DMA_TCD, audio);
  3082. + free_edma_channel(DMA_TCD2, audio);
  3083. +#endif
  3084. + kfree(audio->audio_buf);
  3085. + kfree(audio);
  3086. + audio_device = NULL;
  3087. + unregister_chrdev(SOUND_MAJOR, SOUND_DEVICE_NAME);
  3088. + dev_dbg(&spi->dev, "unregistered audio\n");
  3089. + return 0;
  3090. +}
  3091. +
  3092. +static int ssi_audio_suspend(struct spi_device *spi, pm_message_t message) {
  3093. + return 0;
  3094. +}
  3095. +
  3096. +static int ssi_audio_resume(struct spi_device *spi) {
  3097. + return 0;
  3098. +}
  3099. +
  3100. +static struct spi_driver ssi_audio_driver = {
  3101. + .driver = {
  3102. + .name = DRIVER_NAME,
  3103. + .bus = &spi_bus_type,
  3104. + .owner = THIS_MODULE,
  3105. + },
  3106. + .probe = ssi_audio_probe,
  3107. + .remove = __devexit_p(ssi_audio_remove),
  3108. + .suspend = ssi_audio_suspend,
  3109. + .resume = ssi_audio_resume,
  3110. +};
  3111. +
  3112. +static int __init ssi_audio_init(void)
  3113. +{
  3114. + return spi_register_driver(&ssi_audio_driver);
  3115. +}
  3116. +module_init(ssi_audio_init);
  3117. +
  3118. +static void __exit ssi_audio_exit(void)
  3119. +{
  3120. + spi_unregister_driver(&ssi_audio_driver);
  3121. +}
  3122. +module_exit(ssi_audio_exit);
  3123. +
  3124. +MODULE_DESCRIPTION("SSI/I2S Audio Driver");
  3125. +MODULE_LICENSE("GPL");
  3126. --- a/include/asm-m68k/coldfire_edma.h
  3127. +++ b/include/asm-m68k/coldfire_edma.h
  3128. @@ -1,39 +1,102 @@
  3129. +/*
  3130. + * coldfire_edma.h - eDMA driver for Coldfire MCF5445x
  3131. + *
  3132. + * Yaroslav Vinogradov [email protected]
  3133. + *
  3134. + * Copyright Freescale Semiconductor, Inc. 2007
  3135. + *
  3136. + * This program is free software; you can redistribute it and/or modify it
  3137. + * under the terms of the GNU General Public License as published by the
  3138. + * Free Software Foundation; either version 2 of the License, or (at your
  3139. + * option) any later version.
  3140. + */
  3141. +
  3142. #ifndef _LINUX_COLDFIRE_DMA_H
  3143. #define _LINUX_COLDFIRE_DMA_H
  3144. #include <linux/interrupt.h>
  3145. +#include <asm/mcf5445x_edma.h>
  3146. -#define EDMA_DRIVER_NAME "ColdFire-eDMA"
  3147. -#define DMA_DEV_MINOR 1
  3148. +#define EDMA_DRIVER_NAME "ColdFire-eDMA"
  3149. +#define DMA_DEV_MINOR 1
  3150. #define EDMA_INT_CHANNEL_BASE 8
  3151. #define EDMA_INT_CONTROLLER_BASE 64
  3152. #define EDMA_CHANNELS 16
  3153. -
  3154. +
  3155. #define EDMA_IRQ_LEVEL 5
  3156. -
  3157. +
  3158. typedef irqreturn_t (*edma_irq_handler)(int, void *);
  3159. typedef void (*edma_error_handler)(int, void *);
  3160. -
  3161. +
  3162. +/* Setup transfer control descriptor (TCD)
  3163. + * channel - descriptor number
  3164. + * source - source address
  3165. + * dest - destination address
  3166. + * attr - attributes
  3167. + * soff - source offset
  3168. + * nbytes - number of bytes to be transfered in minor loop
  3169. + * slast - last source address adjustment
  3170. + * citer - major loop count
  3171. + * biter - beggining minor loop count
  3172. + * doff - destination offset
  3173. + * dlast_sga - last destination address adjustment
  3174. + * major_int - generate interrupt after each major loop
  3175. + * disable_req - disable DMA request after major loop
  3176. + */
  3177. void set_edma_params(int channel, u32 source, u32 dest,
  3178. - u32 attr, u32 soff, u32 nbytes, u32 slast,
  3179. - u32 citer, u32 biter, u32 doff, u32 dlast_sga);
  3180. -
  3181. -void start_edma_transfer(int channel, int major_int);
  3182. -
  3183. -void stop_edma_transfer(int channel);
  3184. -
  3185. -void confirm_edma_interrupt_handled(int channel);
  3186. -
  3187. + u32 attr, u32 soff, u32 nbytes, u32 slast,
  3188. + u32 citer, u32 biter, u32 doff, u32 dlast_sga,
  3189. + int major_int, int disable_req);
  3190. +
  3191. +/* Starts eDMA transfer on specified channel
  3192. + * channel - eDMA TCD number
  3193. + */
  3194. +static inline void start_edma_transfer(int channel)
  3195. +{
  3196. + MCF_EDMA_SERQ = channel;
  3197. + MCF_EDMA_SSRT = channel;
  3198. +}
  3199. +
  3200. +/* Stops eDMA transfer
  3201. + * channel - eDMA TCD number
  3202. + */
  3203. +static inline void stop_edma_transfer(int channel)
  3204. +{
  3205. + MCF_EDMA_CINT = channel;
  3206. + MCF_EDMA_CERQ = channel;
  3207. +}
  3208. +
  3209. +
  3210. +/* Confirm that interrupt has been handled
  3211. + * channel - eDMA TCD number
  3212. + */
  3213. +static inline void confirm_edma_interrupt_handled(int channel)
  3214. +{
  3215. + MCF_EDMA_CINT = channel;
  3216. +}
  3217. +
  3218. +/* Initialize eDMA controller */
  3219. void init_edma(void);
  3220. -
  3221. -int request_edma_channel(int channel,
  3222. - edma_irq_handler handler,
  3223. - edma_error_handler error_handler,
  3224. - void *dev,
  3225. - spinlock_t *lock,
  3226. - const char *device_id);
  3227. -
  3228. +
  3229. +/* Request eDMA channel:
  3230. + * channel - eDMA TCD number
  3231. + * handler - channel IRQ callback
  3232. + * error_handler - error interrupt handler callback for channel
  3233. + * dev - device
  3234. + * lock - spinlock to be locked (can be NULL)
  3235. + * device_id - device driver name for proc file system output
  3236. + */
  3237. +int request_edma_channel(int channel,
  3238. + edma_irq_handler handler,
  3239. + edma_error_handler error_handler,
  3240. + void *dev,
  3241. + spinlock_t *lock,
  3242. + const char *device_id);
  3243. +
  3244. +/* Free eDMA channel
  3245. + * channel - eDMA TCD number
  3246. + * dev - device
  3247. + */
  3248. int free_edma_channel(int channel, void *dev);
  3249. -
  3250. #endif
  3251. --- /dev/null
  3252. +++ b/include/linux/spi/mcfqspi.h
  3253. @@ -0,0 +1,80 @@
  3254. +/****************************************************************************/
  3255. +
  3256. +/*
  3257. + * mcfqspi.c - Master QSPI controller for the ColdFire processors
  3258. + *
  3259. + * (C) Copyright 2005, Intec Automation,
  3260. + * Mike Lavender (mike@steroidmicros)
  3261. + *
  3262. +
  3263. + This program is free software; you can redistribute it and/or modify
  3264. + it under the terms of the GNU General Public License as published by
  3265. + the Free Software Foundation; either version 2 of the License, or
  3266. + (at your option) any later version.
  3267. +
  3268. + This program is distributed in the hope that it will be useful,
  3269. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  3270. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3271. + GNU General Public License for more details.
  3272. +
  3273. + You should have received a copy of the GNU General Public License
  3274. + along with this program; if not, write to the Free Software
  3275. + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
  3276. +/* ------------------------------------------------------------------------- */
  3277. +
  3278. +#ifndef MCFQSPI_H_
  3279. +#define MCFQSPI_H_
  3280. +
  3281. +#define QSPI_CS_INIT 0x01
  3282. +#define QSPI_CS_ASSERT 0x02
  3283. +#define QSPI_CS_DROP 0x04
  3284. +
  3285. +#define QSPIIOCS_DOUT_HIZ 1 /* QMR[DOHIE] set hi-z dout between transfers */
  3286. +#define QSPIIOCS_BITS 2 /* QMR[BITS] set transfer size */
  3287. +#define QSPIIOCG_BITS 3 /* QMR[BITS] get transfer size */
  3288. +#define QSPIIOCS_CPOL 4 /* QMR[CPOL] set SCK inactive state */
  3289. +#define QSPIIOCS_CPHA 5 /* QMR[CPHA] set SCK phase, 1=rising edge */
  3290. +#define QSPIIOCS_BAUD 6 /* QMR[BAUD] set SCK baud rate divider */
  3291. +#define QSPIIOCS_QCD 7 /* QDLYR[QCD] set start delay */
  3292. +#define QSPIIOCS_DTL 8 /* QDLYR[DTL] set after delay */
  3293. +#define QSPIIOCS_CONT 9 /* continuous CS asserted during transfer */
  3294. +#define QSPIIOCS_READDATA 10 /* set data send during read */
  3295. +#define QSPIIOCS_ODD_MOD 11 /* if length of buffer is a odd number, 16-bit transfers */
  3296. + /* are finalized with a 8-bit transfer */
  3297. +#define QSPIIOCS_DSP_MOD 12 /* transfers are bounded to 15/30 bytes (a multiple of 3 bytes = 1 DSPword) */
  3298. +#define QSPIIOCS_POLL_MOD 13 /* driver uses polling instead of interrupts */
  3299. +
  3300. +#define QSPIIOCS_SET_CSIV 14 /* sets CSIV flag (cs inactive level) */
  3301. +
  3302. +#ifdef CONFIG_M520x
  3303. +#undef MCF_GPIO_PAR_QSPI
  3304. +#define MCF_GPIO_PAR_QSPI (0xA4034)
  3305. +#endif
  3306. +
  3307. +struct coldfire_spi_master {
  3308. + u16 bus_num;
  3309. + u16 num_chipselect;
  3310. + u8 irq_source;
  3311. + u32 irq_vector;
  3312. + u32 irq_mask;
  3313. + u8 irq_lp;
  3314. + u8 par_val;
  3315. + u16 par_val16;
  3316. + void (*cs_control)(u8 cs, u8 command);
  3317. +};
  3318. +
  3319. +
  3320. +struct coldfire_spi_chip {
  3321. + u8 mode;
  3322. + u8 bits_per_word;
  3323. + u8 del_cs_to_clk;
  3324. + u8 del_after_trans;
  3325. + u16 void_write_data;
  3326. +};
  3327. +
  3328. +typedef struct qspi_read_data {
  3329. + __u32 length;
  3330. + __u8 *buf; /* data to send during read */
  3331. + unsigned int loop : 1;
  3332. +} qspi_read_data;
  3333. +#endif /*MCFQSPI_H_*/