007-Add-eDMA-support-for-MCF5445x.patch 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639
  1. From cd07e01d0c6c207a6138e9d5229dfa8c88ab3879 Mon Sep 17 00:00:00 2001
  2. From: Alison Wang <[email protected]>
  3. Date: Thu, 4 Aug 2011 09:59:40 +0800
  4. Subject: [PATCH 07/52] Add eDMA support for MCF5445x
  5. Add MCF5445x on-chip eDMA controller driver.
  6. Signed-off-by: Alison Wang <[email protected]>
  7. ---
  8. arch/m68k/include/asm/mcf_edma.h | 246 +++++++++
  9. drivers/Makefile | 2 +
  10. drivers/dma/Kconfig | 15 +
  11. drivers/dma/Makefile | 4 +
  12. drivers/dma/mcf_edma.c | 1029 ++++++++++++++++++++++++++++++++++++++
  13. drivers/dma/mcf_edma_test.c | 276 ++++++++++
  14. 6 files changed, 1572 insertions(+), 0 deletions(-)
  15. create mode 100644 arch/m68k/include/asm/mcf_edma.h
  16. create mode 100644 drivers/dma/mcf_edma.c
  17. create mode 100644 drivers/dma/mcf_edma_test.c
  18. --- /dev/null
  19. +++ b/arch/m68k/include/asm/mcf_edma.h
  20. @@ -0,0 +1,246 @@
  21. +/*
  22. + * mcf_edma.h - Coldfire eDMA driver header file.
  23. + *
  24. + * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All Rights Reserved.
  25. + *
  26. + * Add support for m5441x platform ([email protected])
  27. + *
  28. + * This program is free software; you can redistribute it and/or modify it
  29. + * under the terms of the GNU General Public License as published by the
  30. + * Free Software Foundation; either version 2 of the License, or (at your
  31. + * option) any later version.
  32. + */
  33. +
  34. +#ifndef _MCF_EDMA_H
  35. +#define _MCF_EDMA_H
  36. +
  37. +#include <asm/mcfsim.h>
  38. +#include <linux/interrupt.h>
  39. +#if defined(CONFIG_M5445X)
  40. +#include <asm/mcf5445x_edma.h>
  41. +#elif defined(CONFIG_M5441X)
  42. +#include <asm/mcf5441x_edma.h>
  43. +#endif
  44. +#include <linux/scatterlist.h>
  45. +
  46. +#define MCF_EDMA_INT0_CHANNEL_BASE (8)
  47. +#define MCF_EDMA_INT0_CONTROLLER_BASE (64)
  48. +#define MCF_EDMA_INT0_BASE (MCF_EDMA_INT0_CHANNEL_BASE + \
  49. + MCF_EDMA_INT0_CONTROLLER_BASE)
  50. +#define MCF_EDMA_INT0_NUM (16)
  51. +#define MCF_EDMA_INT0_END (MCF_EDMA_INT0_NUM)
  52. +
  53. +#if defined(CONFIG_M5441X)
  54. +#define MCF_EDMA_INT1_CHANNEL_BASE (8)
  55. +#define MCF_EDMA_INT1_CONTROLLER_BASE (128)
  56. +#define MCF_EDMA_INT1_BASE (MCF_EDMA_INT1_CHANNEL_BASE + \
  57. + MCF_EDMA_INT1_CONTROLLER_BASE)
  58. +#define MCF_EDMA_INT1_NUM (40)
  59. +#define MCF_EDMA_INT1_END (MCF_EDMA_INT0_END + MCF_EDMA_INT1_NUM)
  60. +
  61. +#define MCF_EDMA_INT2_CHANNEL_BASE (0)
  62. +#define MCF_EDMA_INT2_CONTROLLER_BASE (192)
  63. +#define MCF_EDMA_INT2_BASE (MCF_EDMA_INT2_CHANNEL_BASE + \
  64. + MCF_EDMA_INT2_CONTROLLER_BASE)
  65. +#define MCF_EDMA_INT2_NUM (8)
  66. +#define MCF_EDMA_INT2_END (MCF_EDMA_INT1_END + MCF_EDMA_INT2_NUM)
  67. +
  68. +#endif
  69. +
  70. +#if defined(CONFIG_M5445X)
  71. +#define MCF_EDMA_CHANNELS (16) /* 0-15 */
  72. +#elif defined(CONFIG_M5441X)
  73. +#define MCF_EDMA_CHANNELS (64) /* 0-63 */
  74. +#endif
  75. +
  76. +#define MCF_EDMA_CHANNEL_ANY (0xFF)
  77. +#define MCF_EDMA_INT_ERR (16) /* edma error interrupt */
  78. +
  79. +#define MCF_EDMA_TCD_PER_CHAN 256
  80. +
  81. +#ifdef CONFIG_M54455
  82. +/* eDMA engine TCD memory description */
  83. +
  84. +struct TCD {
  85. + u32 saddr;
  86. + u16 attr;
  87. + u16 soff;
  88. + u32 nbytes;
  89. + u32 slast;
  90. + u32 daddr;
  91. + u16 citer;
  92. + u16 doff;
  93. + u32 dlast_sga;
  94. + u16 biter;
  95. + u16 csr;
  96. +} __packed;
  97. +
  98. +struct fsl_edma_requestbuf {
  99. + dma_addr_t saddr;
  100. + dma_addr_t daddr;
  101. + u32 soff;
  102. + u32 doff;
  103. + u32 attr;
  104. + u32 minor_loop;
  105. + u32 len;
  106. +};
  107. +
  108. +/*
  109. + * config the eDMA to use the TCD sg feature
  110. + *
  111. + * @channel: which channel. in fact this function is designed to satisfy
  112. + * the ATA driver TCD SG need, i.e. by now it is a special
  113. + * func, because it need prev alloc channel TCD physical memory
  114. + * first, we add the ATA's in the eDMA init only
  115. + * @buf: buffer array to fill the TCDs
  116. + * @nents: the size of the buf
  117. + */
  118. +void mcf_edma_sg_config(int channel, struct fsl_edma_requestbuf *buf,
  119. + int nents);
  120. +
  121. +/*
  122. + * The zero-copy version of mcf_edma_sg_config()
  123. + */
  124. +void mcf_edma_sglist_config(int channel, struct scatterlist *sgl, int n_elem,
  125. + int dma_dir, u32 addr, u32 attr,
  126. + u32 soff, u32 doff, u32 nbytes);
  127. +#endif
  128. +
  129. +/* Setup transfer control descriptor (TCD)
  130. + * channel - descriptor number
  131. + * source - source address
  132. + * dest - destination address
  133. + * attr - attributes
  134. + * soff - source offset
  135. + * nbytes - number of bytes to be transfered in minor loop
  136. + * slast - last source address adjustment
  137. + * citer - major loop count
  138. + * biter - begining minor loop count
  139. + * doff - destination offset
  140. + * dlast_sga - last destination address adjustment
  141. + * major_int - generate interrupt after each major loop
  142. + * disable_req - disable DMA request after major loop
  143. + */
  144. +void mcf_edma_set_tcd_params(int channel, u32 source, u32 dest,
  145. + u32 attr, u32 soff, u32 nbytes, u32 slast,
  146. + u32 citer, u32 biter, u32 doff, u32 dlast_sga,
  147. + int major_int, int disable_req);
  148. +
  149. +/* Setup transfer control descriptor (TCD) and enable halfway irq
  150. + * channel - descriptor number
  151. + * source - source address
  152. + * dest - destination address
  153. + * attr - attributes
  154. + * soff - source offset
  155. + * nbytes - number of bytes to be transfered in minor loop
  156. + * slast - last source address adjustment
  157. + * biter - major loop count
  158. + * doff - destination offset
  159. + * dlast_sga - last destination address adjustment
  160. + * disable_req - disable DMA request after major loop
  161. + */
  162. +void mcf_edma_set_tcd_params_halfirq(int channel, u32 source, u32 dest,
  163. + u32 attr, u32 soff, u32 nbytes, u32 slast,
  164. + u32 biter, u32 doff, u32 dlast_sga,
  165. + int disable_req);
  166. +
  167. +/* check if dma is done
  168. + * channel - descriptor number
  169. + * return 1 if done
  170. + */
  171. +int mcf_edma_check_done(int channel);
  172. +
  173. +/* Starts eDMA transfer on specified channel
  174. + * channel - eDMA TCD number
  175. + */
  176. +static inline void
  177. +mcf_edma_start_transfer(int channel)
  178. +{
  179. + MCF_EDMA_SERQ = channel;
  180. + MCF_EDMA_SSRT = channel;
  181. +}
  182. +
  183. +/* Restart eDMA transfer from halfirq
  184. + * channel - eDMA TCD number
  185. + */
  186. +static inline void
  187. +mcf_edma_confirm_halfirq(int channel)
  188. +{
  189. + /*MCF_EDMA_TCD_CSR(channel) = 7;*/
  190. + MCF_EDMA_SSRT = channel;
  191. +}
  192. +
  193. +/* Starts eDMA transfer on specified channel based on peripheral request
  194. + * channel - eDMA TCD number
  195. + */
  196. +static inline void mcf_edma_enable_transfer(int channel)
  197. +{
  198. + MCF_EDMA_SERQ = channel;
  199. +}
  200. +
  201. +
  202. +/* Stops eDMA transfer
  203. + * channel - eDMA TCD number
  204. + */
  205. +static inline void
  206. +mcf_edma_stop_transfer(int channel)
  207. +{
  208. + MCF_EDMA_CINT = channel;
  209. + MCF_EDMA_CERQ = channel;
  210. +}
  211. +
  212. +/* Confirm that interrupt has been handled
  213. + * channel - eDMA TCD number
  214. + */
  215. +static inline void
  216. +mcf_edma_confirm_interrupt_handled(int channel)
  217. +{
  218. + MCF_EDMA_CINT = channel;
  219. +}
  220. +
  221. +/**
  222. + * mcf_edma_request_channel - Request an eDMA channel
  223. + * @channel: channel number. In case it is equal to EDMA_CHANNEL_ANY
  224. + * it will be allocated a first free eDMA channel.
  225. + * @handler: dma handler
  226. + * @error_handler: dma error handler
  227. + * @irq_level: irq level for the dma handler
  228. + * @arg: argument to pass back
  229. + * @lock: optional spinlock to hold over interrupt
  230. + * @device_id: device id
  231. + *
  232. + * Returns allocatedd channel number if success or
  233. + * a negative value if failure.
  234. + */
  235. +int mcf_edma_request_channel(int channel,
  236. + irqreturn_t(*handler) (int, void *),
  237. + void (*error_handler) (int, void *),
  238. + u8 irq_level,
  239. + void *arg,
  240. + spinlock_t *lock, const char *device_id);
  241. +
  242. +/**
  243. + * Update the channel callback/arg
  244. + * @channel: channel number
  245. + * @handler: dma handler
  246. + * @error_handler: dma error handler
  247. + * @arg: argument to pass back
  248. + *
  249. + * Returns 0 if success or a negative value if failure
  250. + */
  251. +int mcf_edma_set_callback(int channel,
  252. + irqreturn_t(*handler) (int, void *),
  253. + void (*error_handler) (int, void *), void *arg);
  254. +
  255. +/**
  256. + * Free the edma channel
  257. + * @channel: channel number
  258. + * @arg: argument created with
  259. + *
  260. + * Returns 0 if success or a negative value if failure
  261. + */
  262. +int mcf_edma_free_channel(int channel, void *arg);
  263. +
  264. +void mcf_edma_dump_channel(int channel);
  265. +
  266. +#endif /* _MCF_EDMA_H */
  267. --- a/drivers/Makefile
  268. +++ b/drivers/Makefile
  269. @@ -39,6 +39,7 @@ obj-$(CONFIG_FB_I810) += video
  270. obj-$(CONFIG_FB_INTEL) += video/intelfb/
  271. obj-$(CONFIG_PARPORT) += parport/
  272. +obj-$(CONFIG_COLDFIRE_EDMA) += dma/
  273. obj-y += base/ block/ misc/ mfd/ nfc/
  274. obj-$(CONFIG_NUBUS) += nubus/
  275. obj-y += macintosh/
  276. @@ -114,6 +115,7 @@ obj-$(CONFIG_BCMA) += bcma/
  277. obj-$(CONFIG_VHOST_NET) += vhost/
  278. obj-$(CONFIG_VLYNQ) += vlynq/
  279. obj-$(CONFIG_STAGING) += staging/
  280. +obj-$(CONFIG_MCD_DMA) += dma/
  281. obj-y += platform/
  282. obj-y += ieee802154/
  283. #common clk code
  284. --- a/drivers/dma/Kconfig
  285. +++ b/drivers/dma/Kconfig
  286. @@ -114,6 +114,21 @@ config MPC512X_DMA
  287. ---help---
  288. Enable support for the Freescale MPC512x built-in DMA engine.
  289. +config COLDFIRE_EDMA
  290. + tristate "Coldfire eDMA support"
  291. + default y
  292. + depends on COLDFIRE && (M5445X || M5441X)
  293. + help
  294. + Enable support for Coldfire eDMA controller. For example
  295. + used by Coldfire SSI Audio device driver.
  296. +
  297. +config COLDFIRE_EDMA_TEST
  298. + tristate "Coldfire eDMA simple test module"
  299. + default m
  300. + depends on COLDFIRE_EDMA
  301. + help
  302. + This is simple eDMA test module.
  303. +
  304. config MV_XOR
  305. bool "Marvell XOR engine support"
  306. depends on PLAT_ORION
  307. --- a/drivers/dma/Makefile
  308. +++ b/drivers/dma/Makefile
  309. @@ -13,10 +13,14 @@ obj-$(CONFIG_INTEL_IOATDMA) += ioat/
  310. obj-$(CONFIG_INTEL_IOP_ADMA) += iop-adma.o
  311. obj-$(CONFIG_FSL_DMA) += fsldma.o
  312. obj-$(CONFIG_MPC512X_DMA) += mpc512x_dma.o
  313. +obj-$(CONFIG_COLDFIRE_EDMA) += mcf_edma.o
  314. +obj-$(CONFIG_COLDFIRE_EDMA_TEST) += mcf_edma_test.o
  315. obj-$(CONFIG_MV_XOR) += mv_xor.o
  316. obj-$(CONFIG_DW_DMAC) += dw_dmac.o
  317. obj-$(CONFIG_AT_HDMAC) += at_hdmac.o
  318. obj-$(CONFIG_MX3_IPU) += ipu/
  319. +obj-$(CONFIG_MCD_DMA) += mcddma.o
  320. +mcddma-objs := MCD_dmaApi.o MCD_tasks.o MCD_tasksInit.o
  321. obj-$(CONFIG_TXX9_DMAC) += txx9dmac.o
  322. obj-$(CONFIG_SH_DMAE) += shdma.o
  323. obj-$(CONFIG_COH901318) += coh901318.o coh901318_lli.o
  324. --- /dev/null
  325. +++ b/drivers/dma/mcf_edma.c
  326. @@ -0,0 +1,1029 @@
  327. +/*
  328. + * mcf_edma.c - eDMA driver for Coldfire.
  329. + *
  330. + * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All Rights Reserved.
  331. + * Author: Andrey Butok
  332. + * Yaroslav Vinogradov
  333. + * [email protected] add m5441x platform support.
  334. + *
  335. + * This program is free software; you can redistribute it and/or modify it
  336. + * under the terms of the GNU General Public License as published by the
  337. + * Free Software Foundation; either version 2 of the License, or (at your
  338. + * option) any later version.
  339. + *
  340. + * This program is distributed in the hope that it will be useful,
  341. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  342. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  343. + * GNU General Public License for more details.
  344. + *
  345. + * You should have received a copy of the GNU General Public License
  346. + * along with this program; if not, write to the Free Software
  347. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  348. + *
  349. + ***************************************************************************
  350. + * Changes:
  351. + * v0.002 29 February 2008 Andrey Butok, Freescale Semiconductor
  352. + * Added support of atomatic channel allocation from the
  353. + * channel pool.
  354. + * v0.001 12 February 2008 Andrey Butok
  355. + * Initial Release - developed on uClinux with 2.6.23 kernel.
  356. + * Based on coldfire_edma.c code
  357. + * of Yaroslav Vinogradov (Freescale Semiconductor, Inc.)
  358. + *
  359. + * NOTE: This driver was tested on MCF52277 platform.
  360. + * It should also work on other Coldfire platdorms with eDMA module.
  361. + *
  362. + * TBD: Try to make it more general.
  363. + * Try to integrate with current <asm/dma.h> <kernel/dma.c> API
  364. + * or use Intel DMA API
  365. + */
  366. +
  367. +#include <linux/dma-mapping.h>
  368. +#include <asm/mcf_edma.h>
  369. +#include <linux/init.h>
  370. +#include <linux/module.h>
  371. +#include <asm/coldfire.h>
  372. +#include <linux/fs.h>
  373. +#include <linux/cdev.h>
  374. +#include <linux/seq_file.h>
  375. +#include <linux/proc_fs.h>
  376. +
  377. +/* Please add here processors that were tested with this driver */
  378. +#if !defined(CONFIG_M5227x) && !defined(CONFIG_M5445X) && \
  379. + !defined(CONFIG_M5441X)
  380. +#error "The driver is not tested/designed for your processor!"
  381. +#endif
  382. +
  383. +#define MCF_EDMA_DRIVER_VERSION "Revision: 0.003"
  384. +#define MCF_EDMA_DRIVER_AUTHOR "Freescale Semiconductor Inc, Andrey Butok"
  385. +#define MCF_EDMA_DRIVER_DESC "Coldfire EDMA driver."
  386. +#define MCF_EDMA_DRIVER_INFO DRIVER_VERSION " " DRIVER_DESC
  387. +#define MCF_EDMA_DRIVER_LICENSE "GPL"
  388. +#define MCF_EDMA_DRIVER_NAME "mcf_edma"
  389. +
  390. +#define MCF_EDMA_DEV_MINOR (1)
  391. +
  392. +#undef MCF_EDMA_DEBUG
  393. +
  394. +#ifdef MCF_EDMA_DEBUG
  395. +#define DBG(fmt, args...) printk(KERN_INFO "[%s] " fmt, \
  396. + __func__, ## args)
  397. +#else
  398. +#define DBG(fmt, args...) do {} while (0)
  399. +#endif
  400. +
  401. +#define ERR(format, arg...) printk(KERN_ERR "%s:%s: " format "\n", \
  402. + __FILE__, __func__ , ## arg)
  403. +#define INFO(stuff...) printk(KERN_INFO MCF_EDMA_DRIVER_NAME \
  404. + ": " stuff)
  405. +
  406. +/* DMA channel pool used for atomtic channel allocation.
  407. + * You can edit this list. First candidates are "Not used/Reserved" channels */
  408. +u8 mcf_edma_channel_pool[] = { 1, /* Not used */
  409. + 0, /* External DMA request */
  410. + 5, /* UART1 Receive */
  411. + 6, /* UART1 Transmit */
  412. + 7, /* UART2 Receive */
  413. + 8, /* UART2 Transmit */
  414. +#if defined(CONFIG_M5441X)
  415. + 16,
  416. + 55,
  417. + 56,
  418. + 63,
  419. +#endif
  420. +};
  421. +
  422. +/*
  423. + * Callback handler data for each TCD
  424. + */
  425. +struct mcf_edma_isr_record {
  426. + irqreturn_t(*irq_handler) (int, void *); /* interrupt handler */
  427. + void (*error_handler) (int, void *); /* error interrupt handler */
  428. + void *arg; /* argument to pass back */
  429. + int allocated; /* busy flag */
  430. + spinlock_t *lock; /* spin lock (optional) */
  431. + const char *device_id; /* dev id string, used in procfs */
  432. +};
  433. +
  434. +/*
  435. + * Device structure
  436. + */
  437. +struct mcf_edma_dev {
  438. + struct cdev cdev; /* character device */
  439. + struct mcf_edma_isr_record dma_interrupt_handlers[MCF_EDMA_CHANNELS];
  440. +};
  441. +
  442. +/* allocated major device number */
  443. +static int mcf_edma_major;
  444. +
  445. +/* device driver structure */
  446. +static struct mcf_edma_dev *mcf_edma_devp;
  447. +
  448. +#ifdef CONFIG_M54455
  449. +/* PATA controller structure */
  450. +static struct {
  451. + struct TCD *pata_tcd_va;
  452. + dma_addr_t pata_tcd_pa;
  453. +} fsl_pata_dma_tcd;
  454. +#endif
  455. +
  456. +/* device driver file operations */
  457. +const struct file_operations mcf_edma_fops = {
  458. + .owner = THIS_MODULE,
  459. +};
  460. +
  461. +/**
  462. + * mcf_edma_isr - eDMA channel interrupt handler
  463. + * @irq: interrupt number
  464. + * @dev_id: argument
  465. + */
  466. +static irqreturn_t
  467. +mcf_edma_isr(int irq, void *dev_id)
  468. +{
  469. + int channel = -1;
  470. + int result = IRQ_HANDLED;
  471. +
  472. +#if defined(CONFIG_M5445X)
  473. + channel = irq - MCF_EDMA_INT0_BASE;
  474. +#elif defined(CONFIG_M5441X)
  475. + if (irq >= MCF_EDMA_INT0_BASE &&
  476. + irq < MCF_EDMA_INT0_BASE + MCF_EDMA_INT0_NUM)
  477. + channel = irq - MCF_EDMA_INT0_BASE;
  478. + else if (irq >= MCF_EDMA_INT1_BASE &&
  479. + irq < MCF_EDMA_INT1_BASE + MCF_EDMA_INT1_NUM)
  480. + channel = irq - MCF_EDMA_INT1_BASE + MCF_EDMA_INT0_END;
  481. + else if (irq == MCF_EDMA_INT2_BASE &&
  482. + irq < MCF_EDMA_INT2_BASE + MCF_EDMA_INT2_NUM) {
  483. + int i;
  484. + for (i = 0; i < MCF_EDMA_INT2_NUM; i++) {
  485. + if ((MCF_EDMA_INTH >> 24) & (0x1 << i)) {
  486. + channel = irq - MCF_EDMA_INT2_BASE +
  487. + MCF_EDMA_INT1_END + i;
  488. + break;
  489. + }
  490. + }
  491. + } else {
  492. + ERR("Bad irq number at isr!\n");
  493. + return result;
  494. + }
  495. +#endif
  496. +
  497. + DBG("\n");
  498. +
  499. + if ((mcf_edma_devp != NULL) &&
  500. + (mcf_edma_devp->dma_interrupt_handlers[channel].irq_handler)) {
  501. + /* call user irq handler */
  502. + if (mcf_edma_devp->dma_interrupt_handlers[channel].lock)
  503. + spin_lock(mcf_edma_devp->
  504. + dma_interrupt_handlers[channel].lock);
  505. +
  506. + result =
  507. + mcf_edma_devp->dma_interrupt_handlers[channel].
  508. + irq_handler(channel,
  509. + mcf_edma_devp->dma_interrupt_handlers[channel].
  510. + arg);
  511. +
  512. + if (mcf_edma_devp->dma_interrupt_handlers[channel].lock)
  513. + spin_unlock(mcf_edma_devp->
  514. + dma_interrupt_handlers[channel].lock);
  515. + } else {
  516. + /* no irq handler so just ack it */
  517. + mcf_edma_confirm_interrupt_handled(channel);
  518. + ERR(" No handler for DMA channel (%d)\n", channel);
  519. + }
  520. +
  521. + return result;
  522. +}
  523. +
  524. +/**
  525. + * mcf_edma_error_isr - eDMA error interrupt handler
  526. + * @irq: interrupt number
  527. + * @dev_id: argument
  528. + */
  529. +static irqreturn_t
  530. +mcf_edma_error_isr(int irq, void *dev_id)
  531. +{
  532. + int i;
  533. +
  534. +#if defined(CONFIG_M5445X)
  535. + u16 err;
  536. +
  537. + err = MCF_EDMA_ERR;
  538. + for (i = 0; i < MCF_EDMA_CHANNELS; i++) {
  539. + if (err & (1 << i)) {
  540. + if (mcf_edma_devp != NULL &&
  541. + mcf_edma_devp->dma_interrupt_handlers[i].
  542. + error_handler)
  543. + mcf_edma_devp->dma_interrupt_handlers[i].
  544. + error_handler(i,
  545. + mcf_edma_devp->
  546. + dma_interrupt_handlers[i].
  547. + arg);
  548. + else
  549. + ERR(" DMA error on channel (%d)\n", i);
  550. + }
  551. + }
  552. +#elif defined(CONFIG_M5441X)
  553. + u32 errl, errh;
  554. +
  555. + errl = MCF_EDMA_ERRL;
  556. + errh = MCF_EDMA_ERRH;
  557. +
  558. + for (i = 0; i < MCF_EDMA_CHANNELS; i++) {
  559. + if ((errl & (1 << i)) || (errh & (1 << (i - 32)))) {
  560. + if (mcf_edma_devp != NULL &&
  561. + mcf_edma_devp->dma_interrupt_handlers[i].
  562. + error_handler)
  563. + mcf_edma_devp->dma_interrupt_handlers[i].
  564. + error_handler(i, mcf_edma_devp->
  565. + dma_interrupt_handlers[i].arg);
  566. + else
  567. + ERR(" DMA error on channel (%d)\n", i);
  568. + }
  569. + }
  570. +#endif
  571. + MCF_EDMA_CERR = MCF_EDMA_CERR_CAER;
  572. + return IRQ_HANDLED;
  573. +}
  574. +
  575. +/**
  576. + * mcf_edma_check_done - Check if channel is finished or not
  577. + * @channel: channel number
  578. + * return: 0 if not done yet
  579. + */
  580. +int
  581. +mcf_edma_check_done(int channel)
  582. +{
  583. + if (channel < 0 || channel > MCF_EDMA_CHANNELS)
  584. + return 1;
  585. +
  586. + return MCF_EDMA_TCD_CSR(channel) & MCF_EDMA_TCD_CSR_DONE;
  587. +}
  588. +EXPORT_SYMBOL(mcf_edma_check_done);
  589. +
  590. +/**
  591. + * mcf_edma_set_tcd_params - Set transfer control descriptor (TCD)
  592. + * @channel: channel number
  593. + * @source: source address
  594. + * @dest: destination address
  595. + * @attr: attributes
  596. + * @soff: source offset
  597. + * @nbytes: number of bytes to be transfered in minor loop
  598. + * @slast: last source address adjustment
  599. + * @citer: major loop count
  600. + * @biter: beginning major loop count
  601. + * @doff: destination offset
  602. + * @dlast_sga: last destination address adjustment
  603. + * @major_int: generate interrupt after each major loop
  604. + * @disable_req: disable DMA request after major loop
  605. + */
  606. +void
  607. +mcf_edma_set_tcd_params(int channel, u32 source, u32 dest,
  608. + u32 attr, u32 soff, u32 nbytes, u32 slast,
  609. + u32 citer, u32 biter, u32 doff, u32 dlast_sga,
  610. + int major_int, int disable_req)
  611. +{
  612. + DBG("(%d)\n", channel);
  613. +
  614. + if (channel < 0 || channel > MCF_EDMA_CHANNELS)
  615. + return;
  616. +
  617. + MCF_EDMA_TCD_SADDR(channel) = source;
  618. + MCF_EDMA_TCD_DADDR(channel) = dest;
  619. + MCF_EDMA_TCD_ATTR(channel) = attr;
  620. + MCF_EDMA_TCD_SOFF(channel) = MCF_EDMA_TCD_SOFF_SOFF(soff);
  621. + MCF_EDMA_TCD_NBYTES(channel) = MCF_EDMA_TCD_NBYTES_NBYTES(nbytes);
  622. + MCF_EDMA_TCD_SLAST(channel) = MCF_EDMA_TCD_SLAST_SLAST(slast);
  623. + MCF_EDMA_TCD_CITER(channel) = MCF_EDMA_TCD_CITER_CITER(citer);
  624. + MCF_EDMA_TCD_BITER(channel) = MCF_EDMA_TCD_BITER_BITER(biter);
  625. + MCF_EDMA_TCD_DOFF(channel) = MCF_EDMA_TCD_DOFF_DOFF(doff);
  626. + MCF_EDMA_TCD_DLAST_SGA(channel) =
  627. + MCF_EDMA_TCD_DLAST_SGA_DLAST_SGA(dlast_sga);
  628. + MCF_EDMA_TCD_CSR(channel) = 0x0000;
  629. +
  630. + /* interrupt at the end of major loop */
  631. + if (major_int)
  632. + MCF_EDMA_TCD_CSR(channel) |= MCF_EDMA_TCD_CSR_INT_MAJOR;
  633. + else
  634. + MCF_EDMA_TCD_CSR(channel) &= ~MCF_EDMA_TCD_CSR_INT_MAJOR;
  635. +
  636. + /* disable request at the end of major loop of transfer or not */
  637. + if (disable_req)
  638. + MCF_EDMA_TCD_CSR(channel) |= MCF_EDMA_TCD_CSR_D_REQ;
  639. + else
  640. + MCF_EDMA_TCD_CSR(channel) &= ~MCF_EDMA_TCD_CSR_D_REQ;
  641. +
  642. + /* enable error interrupt */
  643. + MCF_EDMA_SEEI = MCF_EDMA_SEEI_SEEI(channel);
  644. +}
  645. +EXPORT_SYMBOL(mcf_edma_set_tcd_params);
  646. +#ifdef CONFIG_M54455
  647. +/**
  648. + * mcf_edma_sg_config - config an eDMA channel to use the S/G tcd feature
  649. + * @channel: channel number
  650. + * @buf: the array of tcd sg
  651. + * @nents: number of tcd sg array, the max is 256 set but can modify
  652. + *
  653. + * limitation:
  654. + * currently this function is only for PATA RX/TX on MCF54455,
  655. + * so eDMA init does not allocate TCD memory for other memory
  656. + *
  657. + * TODO:
  658. + * any one who need this feature shoule add his own TCD memory init
  659. + */
  660. +void mcf_edma_sg_config(int channel, struct fsl_edma_requestbuf *buf,
  661. + int nents)
  662. +{
  663. + struct TCD *vtcd = (struct TCD *)fsl_pata_dma_tcd.pata_tcd_va;
  664. + u32 ptcd = fsl_pata_dma_tcd.pata_tcd_pa;
  665. + struct fsl_edma_requestbuf *pb = buf;
  666. + int i;
  667. +
  668. + if (channel < MCF_EDMA_CHAN_ATA_RX || channel > MCF_EDMA_CHAN_ATA_TX) {
  669. + printk(KERN_ERR "mcf edma sg config err, not support\n");
  670. + return;
  671. + }
  672. + if (nents > MCF_EDMA_TCD_PER_CHAN) {
  673. + printk(KERN_ERR "Too many SGs, please confirm.%d > %d\n",
  674. + nents, MCF_EDMA_TCD_PER_CHAN);
  675. + return;
  676. + }
  677. +
  678. + /* build our tcd sg array */
  679. + for (i = 0; i < nents; i++) {
  680. + memset(vtcd, 0 , sizeof(struct TCD));
  681. + vtcd->saddr = pb->saddr;
  682. + vtcd->daddr = pb->daddr;
  683. + vtcd->attr = pb->attr;
  684. + vtcd->soff = pb->soff;
  685. + vtcd->doff = pb->doff;
  686. + vtcd->nbytes = pb->minor_loop;
  687. + vtcd->citer = vtcd->biter = pb->len/pb->minor_loop;
  688. +
  689. + if (i != nents - 1) {
  690. + vtcd->csr |= MCF_EDMA_TCD_CSR_E_SG;/* we are tcd sg */
  691. + vtcd->dlast_sga =
  692. + (u32)(ptcd + (i + 1)*sizeof(struct TCD));
  693. + } else {
  694. + /*this is the last sg, so enable the major int*/
  695. + vtcd->csr |= MCF_EDMA_TCD_CSR_INT_MAJOR
  696. + |MCF_EDMA_TCD_CSR_D_REQ;
  697. + }
  698. + pb++;
  699. + vtcd++;
  700. + }
  701. +
  702. + /* Now setup the firset TCD for this sg to the edma enginee */
  703. + vtcd = fsl_pata_dma_tcd.pata_tcd_va;
  704. +
  705. + MCF_EDMA_TCD_CSR(channel) = 0x0000;
  706. + MCF_EDMA_TCD_SADDR(channel) = vtcd->saddr;
  707. + MCF_EDMA_TCD_DADDR(channel) = vtcd->daddr;
  708. + MCF_EDMA_TCD_ATTR(channel) = vtcd->attr;
  709. + MCF_EDMA_TCD_SOFF(channel) = MCF_EDMA_TCD_SOFF_SOFF(vtcd->soff);
  710. + MCF_EDMA_TCD_NBYTES(channel) = MCF_EDMA_TCD_NBYTES_NBYTES(vtcd->nbytes);
  711. + MCF_EDMA_TCD_SLAST(channel) = MCF_EDMA_TCD_SLAST_SLAST(vtcd->slast);
  712. + MCF_EDMA_TCD_CITER(channel) = MCF_EDMA_TCD_CITER_CITER(vtcd->citer);
  713. + MCF_EDMA_TCD_BITER(channel) = MCF_EDMA_TCD_BITER_BITER(vtcd->biter);
  714. + MCF_EDMA_TCD_DOFF(channel) = MCF_EDMA_TCD_DOFF_DOFF(vtcd->doff);
  715. + MCF_EDMA_TCD_DLAST_SGA(channel) =
  716. + MCF_EDMA_TCD_DLAST_SGA_DLAST_SGA(vtcd->dlast_sga);
  717. + MCF_EDMA_TCD_CSR(channel) |= vtcd->csr;
  718. +}
  719. +EXPORT_SYMBOL(mcf_edma_sg_config);
  720. +
  721. +/**
  722. + * The zero-copy version of mcf_edma_sg_config
  723. + * dma_dir : indicate teh addr direction
  724. + */
  725. +void mcf_edma_sglist_config(int channel, struct scatterlist *sgl, int n_elem,
  726. + int dma_dir, u32 addr, u32 attr,
  727. + u32 soff, u32 doff, u32 nbytes)
  728. +{
  729. + struct TCD *vtcd = (struct TCD *)fsl_pata_dma_tcd.pata_tcd_va;
  730. + u32 ptcd = fsl_pata_dma_tcd.pata_tcd_pa;
  731. + struct scatterlist *sg;
  732. + u32 si;
  733. +
  734. + if (channel < MCF_EDMA_CHAN_ATA_RX || channel > MCF_EDMA_CHAN_ATA_TX) {
  735. + printk(KERN_ERR "mcf edma sg config err, not support\n");
  736. + return;
  737. + }
  738. + if (n_elem > MCF_EDMA_TCD_PER_CHAN) {
  739. + printk(KERN_ERR "Too many SGs, please confirm.%d > %d\n",
  740. + n_elem, MCF_EDMA_TCD_PER_CHAN);
  741. + return;
  742. + }
  743. +
  744. + /* build our tcd sg array */
  745. + if (dma_dir == DMA_TO_DEVICE) { /* write */
  746. + for_each_sg(sgl, sg, n_elem, si) {
  747. + memset(vtcd, 0 , sizeof(struct TCD));
  748. + vtcd->saddr = sg_dma_address(sg);
  749. + vtcd->daddr = addr;
  750. + vtcd->attr = attr;
  751. + vtcd->soff = soff;
  752. + vtcd->doff = doff;
  753. + vtcd->nbytes = nbytes;
  754. + vtcd->citer = vtcd->biter = sg_dma_len(sg)/nbytes;
  755. +
  756. + if (si != n_elem - 1) {
  757. + /* we are tcd sg */
  758. + vtcd->csr |= MCF_EDMA_TCD_CSR_E_SG;
  759. + vtcd->dlast_sga = (u32)(ptcd + (si + 1) * \
  760. + sizeof(struct TCD));
  761. + } else {
  762. + /*this is the last sg, so enable the major int*/
  763. + vtcd->csr |= MCF_EDMA_TCD_CSR_INT_MAJOR
  764. + |MCF_EDMA_TCD_CSR_D_REQ;
  765. + }
  766. + vtcd++;
  767. + }
  768. + } else {
  769. + for_each_sg(sgl, sg, n_elem, si) {
  770. + memset(vtcd, 0 , sizeof(struct TCD));
  771. + vtcd->daddr = sg_dma_address(sg);
  772. + vtcd->saddr = addr;
  773. + vtcd->attr = attr;
  774. + vtcd->soff = soff;
  775. + vtcd->doff = doff;
  776. + vtcd->nbytes = nbytes;
  777. + vtcd->citer = vtcd->biter = sg_dma_len(sg)/nbytes;
  778. +
  779. + if (si != n_elem - 1) {
  780. + /* we are tcd sg */
  781. + vtcd->csr |= MCF_EDMA_TCD_CSR_E_SG;
  782. + vtcd->dlast_sga = (u32)(ptcd + (si + 1) * \
  783. + sizeof(struct TCD));
  784. + } else {
  785. + /*this is the last sg, so enable the major int*/
  786. + vtcd->csr |= MCF_EDMA_TCD_CSR_INT_MAJOR
  787. + |MCF_EDMA_TCD_CSR_D_REQ;
  788. + }
  789. + vtcd++;
  790. + }
  791. + }
  792. +
  793. + /* Now setup the firset TCD for this sg to the edma enginee */
  794. + vtcd = fsl_pata_dma_tcd.pata_tcd_va;
  795. +
  796. + MCF_EDMA_TCD_CSR(channel) = 0x0000;
  797. + MCF_EDMA_TCD_SADDR(channel) = vtcd->saddr;
  798. + MCF_EDMA_TCD_DADDR(channel) = vtcd->daddr;
  799. + MCF_EDMA_TCD_ATTR(channel) = vtcd->attr;
  800. + MCF_EDMA_TCD_SOFF(channel) = MCF_EDMA_TCD_SOFF_SOFF(vtcd->soff);
  801. + MCF_EDMA_TCD_NBYTES(channel) = MCF_EDMA_TCD_NBYTES_NBYTES(vtcd->nbytes);
  802. + MCF_EDMA_TCD_SLAST(channel) = MCF_EDMA_TCD_SLAST_SLAST(vtcd->slast);
  803. + MCF_EDMA_TCD_CITER(channel) = MCF_EDMA_TCD_CITER_CITER(vtcd->citer);
  804. + MCF_EDMA_TCD_BITER(channel) = MCF_EDMA_TCD_BITER_BITER(vtcd->biter);
  805. + MCF_EDMA_TCD_DOFF(channel) = MCF_EDMA_TCD_DOFF_DOFF(vtcd->doff);
  806. + MCF_EDMA_TCD_DLAST_SGA(channel) =
  807. + MCF_EDMA_TCD_DLAST_SGA_DLAST_SGA(vtcd->dlast_sga);
  808. +
  809. + MCF_EDMA_TCD_CSR(channel) |= vtcd->csr;
  810. +}
  811. +EXPORT_SYMBOL(mcf_edma_sglist_config);
  812. +#endif
  813. +/**
  814. + * mcf_edma_set_tcd_params_halfirq - Set TCD AND enable half irq
  815. + * @channel: channel number
  816. + * @source: source address
  817. + * @dest: destination address
  818. + * @attr: attributes
  819. + * @soff: source offset
  820. + * @nbytes: number of bytes to be transfered in minor loop
  821. + * @slast: last source address adjustment
  822. + * @biter: beginning major loop count
  823. + * @doff: destination offset
  824. + * @dlast_sga: last destination address adjustment
  825. + * @disable_req: disable DMA request after major loop
  826. + */
  827. +void
  828. +mcf_edma_set_tcd_params_halfirq(int channel, u32 source, u32 dest,
  829. + u32 attr, u32 soff, u32 nbytes, u32 slast,
  830. + u32 biter, u32 doff, u32 dlast_sga,
  831. + int disable_req)
  832. +{
  833. + DBG("(%d)\n", channel);
  834. +
  835. + if (channel < 0 || channel > MCF_EDMA_CHANNELS)
  836. + return;
  837. +
  838. + mcf_edma_set_tcd_params(channel, source, dest,
  839. + attr, soff, nbytes, slast,
  840. + biter, biter, doff, dlast_sga,
  841. + 1/*0*/, disable_req);
  842. +
  843. + if (biter < 2)
  844. + printk(KERN_ERR "MCF_EDMA: Request for halfway irq denied\n");
  845. +
  846. + /* interrupt midway through major loop */
  847. + MCF_EDMA_TCD_CSR(channel) |= MCF_EDMA_TCD_CSR_INT_HALF;
  848. +}
  849. +EXPORT_SYMBOL(mcf_edma_set_tcd_params_halfirq);
  850. +
  851. +/**
  852. + * mcf_edma_request_channel - Request an eDMA channel
  853. + * @channel: channel number. In case it is equal to EDMA_CHANNEL_ANY
  854. + * it will be allocated a first free eDMA channel.
  855. + * @handler: dma handler
  856. + * @error_handler: dma error handler
  857. + * @irq_level: irq level for the dma handler
  858. + * @arg: argument to pass back
  859. + * @lock: optional spinlock to hold over interrupt
  860. + * @device_id: device id
  861. + *
  862. + * Returns allocatedd channel number if success or
  863. + * a negative value if failure.
  864. + */
  865. +int
  866. +mcf_edma_request_channel(int channel,
  867. + irqreturn_t(*handler) (int, void *),
  868. + void (*error_handler) (int, void *),
  869. + u8 irq_level,
  870. + void *arg, spinlock_t *lock, const char *device_id)
  871. +{
  872. + DBG("\n channel=%d\n", channel);
  873. +
  874. + if (mcf_edma_devp != NULL
  875. + && ((channel >= 0 && channel <= MCF_EDMA_CHANNELS)
  876. + || (channel == MCF_EDMA_CHANNEL_ANY))) {
  877. + if (channel == MCF_EDMA_CHANNEL_ANY) {
  878. + int i;
  879. + for (i = 0; i < sizeof(mcf_edma_channel_pool); i++) {
  880. + if (mcf_edma_devp->dma_interrupt_handlers
  881. + [mcf_edma_channel_pool[i]].allocated ==
  882. + 0) {
  883. + channel = mcf_edma_channel_pool[i];
  884. + break;
  885. + }
  886. + };
  887. + if (channel == MCF_EDMA_CHANNEL_ANY)
  888. + return -EBUSY;
  889. + } else {
  890. + if (mcf_edma_devp->dma_interrupt_handlers[channel].
  891. + allocated)
  892. + return -EBUSY;
  893. + }
  894. +
  895. + mcf_edma_devp->dma_interrupt_handlers[channel].allocated = 1;
  896. + mcf_edma_devp->dma_interrupt_handlers[channel].irq_handler =
  897. + handler;
  898. + mcf_edma_devp->dma_interrupt_handlers[channel].error_handler =
  899. + error_handler;
  900. + mcf_edma_devp->dma_interrupt_handlers[channel].arg = arg;
  901. + mcf_edma_devp->dma_interrupt_handlers[channel].lock = lock;
  902. + mcf_edma_devp->dma_interrupt_handlers[channel].device_id =
  903. + device_id;
  904. +
  905. + /* Initalize interrupt controller to allow eDMA interrupts */
  906. +#if defined(CONFIG_M5445X)
  907. + MCF_INTC0_ICR(MCF_EDMA_INT0_CHANNEL_BASE + channel) = irq_level;
  908. + MCF_INTC0_CIMR = MCF_EDMA_INT0_CHANNEL_BASE + channel;
  909. +#elif defined(CONFIG_M5441X)
  910. + if (channel >= 0 && channel < MCF_EDMA_INT0_END) {
  911. + MCF_INTC0_ICR(MCF_EDMA_INT0_CHANNEL_BASE + channel) =
  912. + irq_level;
  913. + MCF_INTC0_CIMR = MCF_EDMA_INT0_CHANNEL_BASE + channel;
  914. + } else if (channel >= MCF_EDMA_INT0_END &&
  915. + channel < MCF_EDMA_INT1_END) {
  916. + MCF_INTC1_ICR(MCF_EDMA_INT1_CHANNEL_BASE +
  917. + (channel - MCF_EDMA_INT0_END)) = irq_level;
  918. + MCF_INTC1_CIMR = MCF_EDMA_INT1_CHANNEL_BASE +
  919. + (channel - MCF_EDMA_INT0_END);
  920. + } else if (channel >= MCF_EDMA_INT1_END &&
  921. + channel < MCF_EDMA_INT2_END) {
  922. + MCF_INTC2_ICR(MCF_EDMA_INT2_CHANNEL_BASE) = irq_level;
  923. + MCF_INTC2_CIMR = MCF_EDMA_INT2_CHANNEL_BASE;
  924. + } else
  925. + ERR("Bad channel number!\n");
  926. +#endif
  927. + return channel;
  928. + }
  929. + return -EINVAL;
  930. +}
  931. +EXPORT_SYMBOL(mcf_edma_request_channel);
  932. +
  933. +/**
  934. + * mcf_edma_set_callback - Update the channel callback/arg
  935. + * @channel: channel number
  936. + * @handler: dma handler
  937. + * @error_handler: dma error handler
  938. + * @arg: argument to pass back
  939. + *
  940. + * Returns 0 if success or a negative value if failure
  941. + */
  942. +int
  943. +mcf_edma_set_callback(int channel,
  944. + irqreturn_t(*handler) (int, void *),
  945. + void (*error_handler) (int, void *), void *arg)
  946. +{
  947. + DBG("\n");
  948. +
  949. + if (mcf_edma_devp != NULL && channel >= 0
  950. + && channel <= MCF_EDMA_CHANNELS
  951. + && mcf_edma_devp->dma_interrupt_handlers[channel].allocated) {
  952. + mcf_edma_devp->dma_interrupt_handlers[channel].irq_handler =
  953. + handler;
  954. + mcf_edma_devp->dma_interrupt_handlers[channel].error_handler =
  955. + error_handler;
  956. + mcf_edma_devp->dma_interrupt_handlers[channel].arg = arg;
  957. + return 0;
  958. + }
  959. + return -EINVAL;
  960. +}
  961. +EXPORT_SYMBOL(mcf_edma_set_callback);
  962. +
  963. +/**
  964. + * mcf_edma_free_channel - Free the edma channel
  965. + * @channel: channel number
  966. + * @arg: argument created with
  967. + *
  968. + * Returns 0 if success or a negative value if failure
  969. + */
  970. +int
  971. +mcf_edma_free_channel(int channel, void *arg)
  972. +{
  973. + DBG("\n");
  974. +
  975. + if (mcf_edma_devp != NULL && channel >= 0
  976. + && channel <= MCF_EDMA_CHANNELS) {
  977. + if (mcf_edma_devp->dma_interrupt_handlers[channel].allocated) {
  978. +#if 1
  979. + if (mcf_edma_devp->dma_interrupt_handlers[channel].
  980. + arg != arg)
  981. + return -EBUSY;
  982. +#endif
  983. +
  984. + mcf_edma_devp->dma_interrupt_handlers[channel].
  985. + allocated = 0;
  986. + mcf_edma_devp->dma_interrupt_handlers[channel].arg =
  987. + NULL;
  988. + mcf_edma_devp->dma_interrupt_handlers[channel].
  989. + irq_handler = NULL;
  990. + mcf_edma_devp->dma_interrupt_handlers[channel].
  991. + error_handler = NULL;
  992. + mcf_edma_devp->dma_interrupt_handlers[channel].lock =
  993. + NULL;
  994. + }
  995. +
  996. + /* make sure error interrupt is disabled */
  997. + MCF_EDMA_CEEI = MCF_EDMA_CEEI_CEEI(channel);
  998. +
  999. + return 0;
  1000. + }
  1001. + return -EINVAL;
  1002. +}
  1003. +EXPORT_SYMBOL(mcf_edma_free_channel);
  1004. +
  1005. +/**
  1006. + * mcf_edma_cleanup - cleanup driver allocated resources
  1007. + */
  1008. +static void
  1009. +mcf_edma_cleanup(void)
  1010. +{
  1011. + dev_t devno;
  1012. + int i;
  1013. +
  1014. + DBG("\n");
  1015. +
  1016. + /* disable all error ints */
  1017. + MCF_EDMA_CEEI = MCF_EDMA_CEEI_CAEE;
  1018. +
  1019. + /* free interrupts/memory */
  1020. + if (mcf_edma_devp) {
  1021. + for (i = 0; i < MCF_EDMA_CHANNELS; i++) {
  1022. + #if defined(CONFIG_M5445X)
  1023. + free_irq(MCF_EDMA_INT0_BASE + i, mcf_edma_devp);
  1024. + #elif defined(CONFIG_M5441X)
  1025. + if (i >= 0 && i < MCF_EDMA_INT0_END)
  1026. + free_irq(MCF_EDMA_INT0_BASE + i, mcf_edma_devp);
  1027. + else if (i >= MCF_EDMA_INT0_END &&
  1028. + i <= MCF_EDMA_INT1_END)
  1029. + free_irq(MCF_EDMA_INT1_BASE +
  1030. + (i - MCF_EDMA_INT0_END), mcf_edma_devp);
  1031. + else if (i >= MCF_EDMA_INT1_END &&
  1032. + i < MCF_EDMA_INT2_END) {
  1033. + free_irq(MCF_EDMA_INT2_BASE, mcf_edma_devp);
  1034. + break;
  1035. + } else {
  1036. + ERR("Bad irq number!\n");
  1037. + return;
  1038. + }
  1039. + #endif
  1040. + }
  1041. +
  1042. + free_irq(MCF_EDMA_INT0_BASE + MCF_EDMA_INT_ERR, mcf_edma_devp);
  1043. + cdev_del(&mcf_edma_devp->cdev);
  1044. + kfree(mcf_edma_devp);
  1045. + }
  1046. +
  1047. + /* unregister character device */
  1048. + devno = MKDEV(mcf_edma_major, 0);
  1049. + unregister_chrdev_region(devno, 1);
  1050. +}
  1051. +
  1052. +/**
  1053. + * mcf_edma_dump_channel - dump a channel information
  1054. + */
  1055. +void
  1056. +mcf_edma_dump_channel(int channel)
  1057. +{
  1058. + printk(KERN_DEBUG "EDMA Channel %d\n", channel);
  1059. + printk(KERN_DEBUG " TCD Base = 0x%x\n",
  1060. + (int)&MCF_EDMA_TCD_SADDR(channel));
  1061. + printk(KERN_DEBUG " SRCADDR = 0x%lx\n",
  1062. + MCF_EDMA_TCD_SADDR(channel));
  1063. + printk(KERN_DEBUG " SRCOFF = 0x%x\n",
  1064. + MCF_EDMA_TCD_SOFF(channel));
  1065. + printk(KERN_DEBUG " XFR ATTRIB = 0x%x\n",
  1066. + MCF_EDMA_TCD_ATTR(channel));
  1067. + printk(KERN_DEBUG " SRCLAST = 0x%lx\n",
  1068. + MCF_EDMA_TCD_SLAST(channel));
  1069. + printk(KERN_DEBUG " DSTADDR = 0x%lx\n",
  1070. + MCF_EDMA_TCD_DADDR(channel));
  1071. + printk(KERN_DEBUG " MINOR BCNT = 0x%lx\n",
  1072. + MCF_EDMA_TCD_NBYTES(channel));
  1073. + printk(KERN_DEBUG " CUR_LOOP_CNT = 0x%x\n",
  1074. + MCF_EDMA_TCD_CITER(channel)&0x1ff);
  1075. + printk(KERN_DEBUG " BEG_LOOP_CNT = 0x%x\n",
  1076. + MCF_EDMA_TCD_BITER(channel)&0x1ff);
  1077. + printk(KERN_DEBUG " STATUS = 0x%x\n",
  1078. + MCF_EDMA_TCD_CSR(channel));
  1079. +
  1080. +}
  1081. +EXPORT_SYMBOL(mcf_edma_dump_channel);
  1082. +
  1083. +#ifdef CONFIG_PROC_FS
  1084. +/*
  1085. + * proc file system support
  1086. + */
  1087. +
  1088. +#define FREE_CHANNEL "free"
  1089. +#define DEVICE_UNKNOWN "device unknown"
  1090. +
  1091. +/**
  1092. + * mcf_edma_proc_show - print out proc info
  1093. + * @m: seq_file
  1094. + * @v:
  1095. + */
  1096. +static int
  1097. +mcf_edma_proc_show(struct seq_file *m, void *v)
  1098. +{
  1099. + int i;
  1100. +
  1101. + if (mcf_edma_devp == NULL)
  1102. + return 0;
  1103. +
  1104. + for (i = 0; i < MCF_EDMA_CHANNELS; i++) {
  1105. + if (mcf_edma_devp->dma_interrupt_handlers[i].allocated) {
  1106. + if (mcf_edma_devp->dma_interrupt_handlers[i].device_id)
  1107. + seq_printf(m, "%2d: %s\n", i,
  1108. + mcf_edma_devp->
  1109. + dma_interrupt_handlers[i].
  1110. + device_id);
  1111. + else
  1112. + seq_printf(m, "%2d: %s\n", i, DEVICE_UNKNOWN);
  1113. + } else
  1114. + seq_printf(m, "%2d: %s\n", i, FREE_CHANNEL);
  1115. + }
  1116. + return 0;
  1117. +}
  1118. +
  1119. +/**
  1120. + * mcf_edma_proc_open - open the proc file
  1121. + * @inode: inode ptr
  1122. + * @file: file ptr
  1123. + */
  1124. +static int
  1125. +mcf_edma_proc_open(struct inode *inode, struct file *file)
  1126. +{
  1127. + return single_open(file, mcf_edma_proc_show, NULL);
  1128. +}
  1129. +
  1130. +static const struct file_operations mcf_edma_proc_operations = {
  1131. + .open = mcf_edma_proc_open,
  1132. + .read = seq_read,
  1133. + .llseek = seq_lseek,
  1134. + .release = single_release,
  1135. +};
  1136. +
  1137. +/**
  1138. + * mcf_edma_proc_init - initialize proc filesystem
  1139. + */
  1140. +static int __init
  1141. +mcf_edma_proc_init(void)
  1142. +{
  1143. + struct proc_dir_entry *e;
  1144. +
  1145. + e = create_proc_entry("edma", 0, NULL);
  1146. + if (e)
  1147. + e->proc_fops = &mcf_edma_proc_operations;
  1148. +
  1149. + return 0;
  1150. +}
  1151. +
  1152. +#endif
  1153. +
  1154. +/**
  1155. + * mcf_edma_init - eDMA module init
  1156. + */
  1157. +static int __init
  1158. +mcf_edma_init(void)
  1159. +{
  1160. + dev_t dev;
  1161. + int result;
  1162. + int i;
  1163. +#ifdef CONFIG_M54455
  1164. + u32 offset;
  1165. +#endif
  1166. +
  1167. +#if defined(CONFIG_M5441X)
  1168. + /* edma group priority, default grp0 > grp1 > grp2 > grp3 */
  1169. + u32 grp0_pri = MCF_EDMA_CR_GRP0PRI(0x00);
  1170. + u32 grp1_pri = MCF_EDMA_CR_GRP1PRI(0x01);
  1171. + u32 grp2_pri = MCF_EDMA_CR_GRP2PRI(0x02);
  1172. + u32 grp3_pri = MCF_EDMA_CR_GRP3PRI(0x03);
  1173. +#endif
  1174. +
  1175. + DBG("Entry\n");
  1176. +
  1177. + /* allocate free major number */
  1178. + result =
  1179. + alloc_chrdev_region(&dev, MCF_EDMA_DEV_MINOR, 1,
  1180. + MCF_EDMA_DRIVER_NAME);
  1181. + if (result < 0) {
  1182. + ERR("Error %d can't get major number.\n", result);
  1183. + return result;
  1184. + }
  1185. + mcf_edma_major = MAJOR(dev);
  1186. +
  1187. + /* allocate device driver structure */
  1188. + mcf_edma_devp = kmalloc(sizeof(struct mcf_edma_dev), GFP_KERNEL);
  1189. + if (!mcf_edma_devp) {
  1190. + result = -ENOMEM;
  1191. + goto fail;
  1192. + }
  1193. +
  1194. + /* init handlers (no handlers for beginning) */
  1195. + for (i = 0; i < MCF_EDMA_CHANNELS; i++) {
  1196. + mcf_edma_devp->dma_interrupt_handlers[i].irq_handler = NULL;
  1197. + mcf_edma_devp->dma_interrupt_handlers[i].error_handler = NULL;
  1198. + mcf_edma_devp->dma_interrupt_handlers[i].arg = NULL;
  1199. + mcf_edma_devp->dma_interrupt_handlers[i].allocated = 0;
  1200. + mcf_edma_devp->dma_interrupt_handlers[i].lock = NULL;
  1201. + mcf_edma_devp->dma_interrupt_handlers[i].device_id = NULL;
  1202. + MCF_EDMA_TCD_CSR(i) = 0x0000;
  1203. + }
  1204. +
  1205. + /* register char device */
  1206. + cdev_init(&mcf_edma_devp->cdev, &mcf_edma_fops);
  1207. + mcf_edma_devp->cdev.owner = THIS_MODULE;
  1208. + mcf_edma_devp->cdev.ops = &mcf_edma_fops;
  1209. + result = cdev_add(&mcf_edma_devp->cdev, dev, 1);
  1210. + if (result) {
  1211. + ERR("Error %d adding coldfire-dma device.\n", result);
  1212. + result = -ENODEV;
  1213. + goto fail;
  1214. + }
  1215. +
  1216. + /* request/enable irq for each eDMA channel */
  1217. +#if defined(CONFIG_M5445X)
  1218. + for (i = 0; i < MCF_EDMA_CHANNELS; i++) {
  1219. + result = request_irq(MCF_EDMA_INT0_BASE + i,
  1220. + mcf_edma_isr, IRQF_DISABLED,
  1221. + MCF_EDMA_DRIVER_NAME, mcf_edma_devp);
  1222. + if (result) {
  1223. + ERR("Cannot request irq %d\n",
  1224. + (MCF_EDMA_INT0_BASE + i));
  1225. + result = -EBUSY;
  1226. + goto fail;
  1227. + }
  1228. + }
  1229. +#elif defined(CONFIG_M5441X)
  1230. + for (i = 0; i < MCF_EDMA_CHANNELS; i++) {
  1231. + if (i >= 0 && i < MCF_EDMA_INT0_END) {
  1232. + result = request_irq(MCF_EDMA_INT0_BASE + i,
  1233. + mcf_edma_isr, IRQF_DISABLED,
  1234. + MCF_EDMA_DRIVER_NAME,
  1235. + mcf_edma_devp);
  1236. +
  1237. + if (result) {
  1238. + ERR("Cannot request irq %d\n",
  1239. + (MCF_EDMA_INT0_BASE + i));
  1240. + result = -EBUSY;
  1241. + goto fail;
  1242. + }
  1243. + } else if (i >= MCF_EDMA_INT0_END && i < MCF_EDMA_INT1_END) {
  1244. + result = request_irq(MCF_EDMA_INT1_BASE +
  1245. + (i - MCF_EDMA_INT0_END),
  1246. + mcf_edma_isr, IRQF_DISABLED,
  1247. + MCF_EDMA_DRIVER_NAME,
  1248. + mcf_edma_devp);
  1249. +
  1250. + if (result) {
  1251. + ERR("Cannot request irq %d\n",
  1252. + (MCF_EDMA_INT1_BASE +
  1253. + (i - MCF_EDMA_INT0_END)));
  1254. + result = -EBUSY;
  1255. + goto fail;
  1256. + }
  1257. + } else if (i >= MCF_EDMA_INT1_END && MCF_EDMA_INT2_END) {
  1258. + result = request_irq(MCF_EDMA_INT2_BASE,
  1259. + mcf_edma_isr, IRQF_DISABLED,
  1260. + MCF_EDMA_DRIVER_NAME,
  1261. + mcf_edma_devp);
  1262. + if (result) {
  1263. + ERR("Cannot request irq %d\n",
  1264. + MCF_EDMA_INT2_BASE);
  1265. + result = -EBUSY;
  1266. + goto fail;
  1267. + }
  1268. + break;
  1269. + } else {
  1270. + ERR(" Cannot request irq because of wrong number!\n");
  1271. + result = -EBUSY;
  1272. + goto fail;
  1273. + }
  1274. + }
  1275. +#endif
  1276. +
  1277. + /* request error interrupt */
  1278. + result = request_irq(MCF_EDMA_INT0_BASE + MCF_EDMA_INT_ERR,
  1279. + mcf_edma_error_isr, IRQF_DISABLED,
  1280. + MCF_EDMA_DRIVER_NAME, mcf_edma_devp);
  1281. + if (result) {
  1282. + ERR("Cannot request irq %d\n",
  1283. + (MCF_EDMA_INT0_BASE + MCF_EDMA_INT_ERR));
  1284. + result = -EBUSY;
  1285. + goto fail;
  1286. + }
  1287. +
  1288. +#if defined(CONFIG_M5445X)
  1289. + MCF_EDMA_CR = 0;
  1290. +#elif defined(CONFIG_M5441X)
  1291. + MCF_EDMA_CR = (0 | grp0_pri | grp1_pri | grp2_pri | grp3_pri);
  1292. + DBG("MCF_EDMA_CR = %lx\n", MCF_EDMA_CR);
  1293. +#endif
  1294. +
  1295. +#ifdef CONFIG_M54455
  1296. + fsl_pata_dma_tcd.pata_tcd_va = (struct TCD *) dma_alloc_coherent(NULL,
  1297. + MCF_EDMA_TCD_PER_CHAN + 1,
  1298. + &fsl_pata_dma_tcd.pata_tcd_pa,
  1299. + GFP_KERNEL);
  1300. +
  1301. + if (!fsl_pata_dma_tcd.pata_tcd_va) {
  1302. + printk(KERN_INFO "MCF eDMA alllocate tcd memeory failed\n");
  1303. + goto fail;
  1304. + }
  1305. +
  1306. +
  1307. + offset = (fsl_pata_dma_tcd.pata_tcd_pa & (sizeof(struct TCD)-1)) ;
  1308. + if (offset) {
  1309. + /*
  1310. + * up align the addr to 32B to match the eDMA enginee require,
  1311. + * ie. sizeof tcd boundary
  1312. + * */
  1313. + printk(KERN_INFO "pata tcd original:pa-%x[%x]\n",
  1314. + fsl_pata_dma_tcd.pata_tcd_pa,
  1315. + (u32)fsl_pata_dma_tcd.pata_tcd_va);
  1316. +
  1317. + fsl_pata_dma_tcd.pata_tcd_pa += sizeof(struct TCD) - offset;
  1318. + fsl_pata_dma_tcd.pata_tcd_va += sizeof(struct TCD) - offset;
  1319. +
  1320. + printk(KERN_INFO "pata tcd realigned:pa-%x[%x]\n",
  1321. + fsl_pata_dma_tcd.pata_tcd_pa,
  1322. + (u32)fsl_pata_dma_tcd.pata_tcd_va);
  1323. + }
  1324. +#endif
  1325. +#ifdef CONFIG_PROC_FS
  1326. + mcf_edma_proc_init();
  1327. +#endif
  1328. +
  1329. + INFO("Initialized successfully\n");
  1330. + return 0;
  1331. +fail:
  1332. + mcf_edma_cleanup();
  1333. + return result;
  1334. +}
  1335. +
  1336. +/**
  1337. + * mcf_edma_exit - eDMA module exit
  1338. + */
  1339. +static void __exit
  1340. +mcf_edma_exit(void)
  1341. +{
  1342. + mcf_edma_cleanup();
  1343. +}
  1344. +
  1345. +#ifdef CONFIG_COLDFIRE_EDMA_MODULE
  1346. +module_init(mcf_edma_init);
  1347. +module_exit(mcf_edma_exit);
  1348. +#else
  1349. +/* get us in early */
  1350. +postcore_initcall(mcf_edma_init);
  1351. +#endif
  1352. +
  1353. +MODULE_DESCRIPTION(MCF_EDMA_DRIVER_INFO);
  1354. +MODULE_AUTHOR(MCF_EDMA_DRIVER_AUTHOR);
  1355. +MODULE_LICENSE(MCF_EDMA_DRIVER_LICENSE);
  1356. --- /dev/null
  1357. +++ b/drivers/dma/mcf_edma_test.c
  1358. @@ -0,0 +1,276 @@
  1359. +/*
  1360. + * mcf_edma_test.c - simple test/example module for Coldfire eDMA.
  1361. + *
  1362. + * Copyright (C) 2008-2011 Freescale Semiconductor, Inc. All Rights Reserved.
  1363. + * Author: Andrey Butok
  1364. + *
  1365. + * This program is free software; you can redistribute it and/or modify it
  1366. + * under the terms of the GNU General Public License as published by the
  1367. + * Free Software Foundation; either version 2 of the License, or (at your
  1368. + * option) any later version.
  1369. + *
  1370. + * This program is distributed in the hope that it will be useful,
  1371. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1372. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1373. + * GNU General Public License for more details.
  1374. + *
  1375. + * You should have received a copy of the GNU General Public License
  1376. + * along with this program; if not, write to the Free Software
  1377. + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  1378. + *
  1379. + ***************************************************************************
  1380. + * Changes:
  1381. + * v0.001 29 February 2008 Andrey Butok
  1382. + * Initial Release
  1383. + *
  1384. + * NOTE: This module tests eDMA driver performing
  1385. + * a simple memory to memory transfer with a 32 bit
  1386. + * source and destination transfer size that generates
  1387. + * an interrupt when the transfer is complete.
  1388. + */
  1389. +
  1390. +#include <linux/dma-mapping.h>
  1391. +#include <linux/init.h>
  1392. +#include <linux/fs.h>
  1393. +#include <linux/cdev.h>
  1394. +#include <linux/seq_file.h>
  1395. +#include <linux/proc_fs.h>
  1396. +#include <asm/mcfsim.h>
  1397. +#include <asm/coldfire.h>
  1398. +#include <asm/mcf_edma.h>
  1399. +#include <asm/cacheflush.h>
  1400. +
  1401. +#define MCF_EDMA_TEST_DRIVER_VERSION "Revision: 0.001"
  1402. +#define MCF_EDMA_TEST_DRIVER_AUTHOR \
  1403. + "Freescale Semiconductor Inc, Andrey Butok"
  1404. +#define MCF_EDMA_TEST_DRIVER_DESC \
  1405. + "Simple testing module for Coldfire eDMA "
  1406. +#define MCF_EDMA_TEST_DRIVER_INFO \
  1407. + MCF_EDMA_TEST_DRIVER_VERSION " " MCF_EDMA_TEST_DRIVER_DESC
  1408. +#define MCF_EDMA_TEST_DRIVER_LICENSE "GPL"
  1409. +#define MCF_EDMA_TEST_DRIVER_NAME "mcf_edma_test"
  1410. +
  1411. +#ifndef TRUE
  1412. +#define TRUE 1
  1413. +#define FALSE 0
  1414. +#endif
  1415. +
  1416. +#define TEST_HALFIRQ
  1417. +
  1418. +/* Global variable used to signal main process when interrupt is recognized */
  1419. +static volatile int mcf_edma_test_interrupt;
  1420. +volatile int *mcf_edma_test_interrupt_p =
  1421. + (volatile int *) &mcf_edma_test_interrupt;
  1422. +
  1423. +/********************************************************************/
  1424. +static irqreturn_t
  1425. +mcf_edma_test_handler(int channel, void *dev_id)
  1426. +{
  1427. + int done = mcf_edma_check_done(channel);
  1428. +
  1429. + /* Clear interrupt flag */
  1430. + mcf_edma_confirm_interrupt_handled(channel);
  1431. +
  1432. + if (done) {
  1433. + printk(KERN_INFO "DMA Finished\n");
  1434. +
  1435. + /* Set interrupt status flag to TRUE */
  1436. + mcf_edma_test_interrupt = TRUE;
  1437. + } else {
  1438. + printk(KERN_INFO "DMA Halfway Done\n");
  1439. +
  1440. + /* restart DMA. */
  1441. + mcf_edma_confirm_halfirq(channel);
  1442. + }
  1443. +
  1444. + return IRQ_HANDLED;
  1445. +}
  1446. +
  1447. +static void
  1448. +mcf_edma_test_error_handler(int channel, void *dev_id)
  1449. +{
  1450. + printk(KERN_INFO "DMA ERROR: Channel = %d\n", channel);
  1451. + printk(KERN_INFO " EDMA_ES = 0x%lx\n", (MCF_EDMA_ES));
  1452. + mcf_edma_dump_channel(channel);
  1453. +}
  1454. +
  1455. +/********************************************************************/
  1456. +
  1457. +int
  1458. +mcf_edma_test_block_compare(u8 *block1, u8 *block2, u32 size)
  1459. +{
  1460. + u32 i;
  1461. +
  1462. + for (i = 0; i < (size); i++) {
  1463. + if ((*(u8 *) (block1 + i)) != (*(u8 *) (block2 + i))) {
  1464. + printk(KERN_INFO "Data Mismatch index=0x%x len=0x%x "
  1465. + "block1=0x%p block2=0x%p\n",
  1466. + i, size, block1, block2);
  1467. + return FALSE;
  1468. + }
  1469. + }
  1470. +
  1471. + return TRUE;
  1472. +}
  1473. +
  1474. +/********************************************************************/
  1475. +
  1476. +void
  1477. +mcf_edma_test_run(void)
  1478. +{
  1479. + u16 byte_count;
  1480. + u32 i, j;
  1481. + u8 *start_address;
  1482. + u8 *dest_address;
  1483. + u32 test_data;
  1484. + int channel;
  1485. + u32 allocated_channels_low = 0;
  1486. + u32 allocated_channels_high = 0;
  1487. +
  1488. + printk(KERN_INFO "\n===============================================\n");
  1489. + printk(KERN_INFO "\nStarting eDMA transfer test!\n");
  1490. +
  1491. + /* Initialize test variables */
  1492. + byte_count = 0x2000;
  1493. + test_data = 0xA5A5A5A5;
  1494. +
  1495. + /* DMA buffer must be from GFP_DMA zone, so it will not be cached */
  1496. + start_address = kmalloc(byte_count, GFP_DMA);
  1497. + if (start_address == NULL) {
  1498. + printk(KERN_INFO MCF_EDMA_TEST_DRIVER_NAME
  1499. + ": failed to allocate DMA[%d] buffer\n", byte_count);
  1500. + goto err_out;
  1501. + }
  1502. + dest_address = kmalloc(byte_count, /*GFP_KERNEL*/GFP_DMA);
  1503. + if (dest_address == NULL) {
  1504. + printk(KERN_INFO MCF_EDMA_TEST_DRIVER_NAME
  1505. + ": failed to allocate DMA[%d] buffer\n", byte_count);
  1506. + goto err_free_mem;
  1507. + }
  1508. +
  1509. + /* Test all automatically allocated DMA channels. The test data is
  1510. + * complemented at the end of the loop, so that the testData value
  1511. + * isn't the same twice in a row */
  1512. + for (i = 0; i < MCF_EDMA_CHANNELS; i++) {
  1513. + /* request eDMA channel */
  1514. + channel = mcf_edma_request_channel(MCF_EDMA_CHANNEL_ANY,
  1515. + mcf_edma_test_handler,
  1516. + mcf_edma_test_error_handler,
  1517. + 0x6,
  1518. + NULL,
  1519. + NULL,
  1520. + MCF_EDMA_TEST_DRIVER_NAME);
  1521. + if (channel < 0)
  1522. + goto test_end;
  1523. +
  1524. +
  1525. + if (channel >= 0 && channel < 32)
  1526. + allocated_channels_low |= (1 << channel);
  1527. + else if (channel >= 32 && channel < 64)
  1528. + allocated_channels_high |= (1 << (channel - 32));
  1529. +
  1530. + /* Initialize data for DMA to move */
  1531. + for (j = 0; j < byte_count; j = j + 4) {
  1532. + *((u32 *) (start_address + j)) = test_data;
  1533. + *((u32 *) (dest_address + j)) = ~test_data;
  1534. + }
  1535. +
  1536. + /* Clear interrupt status indicator */
  1537. + mcf_edma_test_interrupt = FALSE;
  1538. +
  1539. + /* Configure DMA Channel TCD */
  1540. +#ifndef TEST_HALFIRQ
  1541. + /* regular irq on completion */
  1542. + mcf_edma_set_tcd_params(channel,
  1543. + (u32)virt_to_phys(start_address),
  1544. + (u32)virt_to_phys(dest_address),
  1545. + (0 | MCF_EDMA_TCD_ATTR_SSIZE_32BIT |
  1546. + MCF_EDMA_TCD_ATTR_DSIZE_32BIT), 0x04,
  1547. + byte_count, 0x0, 1, 1, 0x04, 0x0, 0x1,
  1548. + 0x0);
  1549. +#else
  1550. + /* half completion irq */
  1551. + mcf_edma_set_tcd_params_halfirq(channel,
  1552. + (u32)virt_to_phys(start_address),
  1553. + (u32)virt_to_phys(dest_address),
  1554. + (MCF_EDMA_TCD_ATTR_SSIZE_32BIT |
  1555. + MCF_EDMA_TCD_ATTR_DSIZE_32BIT),
  1556. + 0x04, /* soff */
  1557. + byte_count/2, /* bytes/loop */
  1558. + 0x0, /* slast */
  1559. + 2, /* loop count */
  1560. + 0x04, /* doff */
  1561. + 0x0, /* dlast_sga */
  1562. + 0x0); /* req dis */
  1563. +#endif
  1564. +
  1565. + printk(KERN_INFO "DMA Channel %d Bytes = 0x%x\n",
  1566. + channel, byte_count);
  1567. + /* Start DMA. */
  1568. + mcf_edma_start_transfer(channel);
  1569. +
  1570. + printk(KERN_INFO "DMA channel %d started.\n", channel);
  1571. +
  1572. + /* Wait for DMA to complete */
  1573. + while (!*mcf_edma_test_interrupt_p)
  1574. + ;
  1575. +
  1576. + /* Test data */
  1577. + if (mcf_edma_test_block_compare
  1578. + (start_address, dest_address, byte_count))
  1579. + printk(KERN_INFO "Data are moved correctly.\n");
  1580. + else
  1581. + printk(KERN_INFO "ERROR!!! Data error!\n");
  1582. +
  1583. + printk(KERN_INFO "DMA channel %d test complete.\n", channel);
  1584. + printk(KERN_INFO "-------------------------------\n");
  1585. +
  1586. + /* Complement test data so next channel test does not
  1587. + * use same values */
  1588. + test_data = ~test_data;
  1589. + }
  1590. +
  1591. +test_end:
  1592. + printk(KERN_INFO "All tests are complete\n\n");
  1593. + printk(KERN_INFO
  1594. + "It has been automatically allocated %d eDMA channels:\n", i);
  1595. + for (i = 0; i < MCF_EDMA_CHANNELS; i++) {
  1596. + if ((allocated_channels_low & (1 << i)) ||
  1597. + (allocated_channels_high & (1 << (i - 32)))) {
  1598. + printk(KERN_INFO "%d,\n", i);
  1599. + mcf_edma_free_channel(i, NULL);
  1600. + }
  1601. + }
  1602. + printk(KERN_INFO "===============================================\n\n");
  1603. +
  1604. + kfree(dest_address);
  1605. +err_free_mem:
  1606. + kfree(start_address);
  1607. +err_out:
  1608. + return;
  1609. +}
  1610. +
  1611. +/********************************************************************/
  1612. +
  1613. +static int __init
  1614. +mcf_edma_test_init(void)
  1615. +{
  1616. + mcf_edma_test_run();
  1617. +
  1618. + /* We intentionaly return -EAGAIN to prevent keeping
  1619. + * the module. It does all its work from init()
  1620. + * and doesn't offer any runtime functionality */
  1621. + return -EAGAIN;
  1622. +}
  1623. +
  1624. +static void __exit
  1625. +mcf_edma_test_exit(void)
  1626. +{
  1627. +}
  1628. +
  1629. +module_init(mcf_edma_test_init);
  1630. +module_exit(mcf_edma_test_exit);
  1631. +
  1632. +MODULE_DESCRIPTION(MCF_EDMA_TEST_DRIVER_INFO);
  1633. +MODULE_AUTHOR(MCF_EDMA_TEST_DRIVER_AUTHOR);
  1634. +MODULE_LICENSE(MCF_EDMA_TEST_DRIVER_LICENSE);