edma.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807
  1. /*
  2. * EDMA3 support for DaVinci
  3. *
  4. * Copyright (C) 2006-2009 Texas Instruments.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20. #include <linux/err.h>
  21. #include <linux/kernel.h>
  22. #include <linux/init.h>
  23. #include <linux/module.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/io.h>
  27. #include <linux/slab.h>
  28. #include <linux/edma.h>
  29. #include <linux/of_address.h>
  30. #include <linux/of_device.h>
  31. #include <linux/of_dma.h>
  32. #include <linux/of_irq.h>
  33. #include <linux/pm_runtime.h>
  34. #include <linux/platform_data/edma.h>
  35. /* Offsets matching "struct edmacc_param" */
  36. #define PARM_OPT 0x00
  37. #define PARM_SRC 0x04
  38. #define PARM_A_B_CNT 0x08
  39. #define PARM_DST 0x0c
  40. #define PARM_SRC_DST_BIDX 0x10
  41. #define PARM_LINK_BCNTRLD 0x14
  42. #define PARM_SRC_DST_CIDX 0x18
  43. #define PARM_CCNT 0x1c
  44. #define PARM_SIZE 0x20
  45. /* Offsets for EDMA CC global channel registers and their shadows */
  46. #define SH_ER 0x00 /* 64 bits */
  47. #define SH_ECR 0x08 /* 64 bits */
  48. #define SH_ESR 0x10 /* 64 bits */
  49. #define SH_CER 0x18 /* 64 bits */
  50. #define SH_EER 0x20 /* 64 bits */
  51. #define SH_EECR 0x28 /* 64 bits */
  52. #define SH_EESR 0x30 /* 64 bits */
  53. #define SH_SER 0x38 /* 64 bits */
  54. #define SH_SECR 0x40 /* 64 bits */
  55. #define SH_IER 0x50 /* 64 bits */
  56. #define SH_IECR 0x58 /* 64 bits */
  57. #define SH_IESR 0x60 /* 64 bits */
  58. #define SH_IPR 0x68 /* 64 bits */
  59. #define SH_ICR 0x70 /* 64 bits */
  60. #define SH_IEVAL 0x78
  61. #define SH_QER 0x80
  62. #define SH_QEER 0x84
  63. #define SH_QEECR 0x88
  64. #define SH_QEESR 0x8c
  65. #define SH_QSER 0x90
  66. #define SH_QSECR 0x94
  67. #define SH_SIZE 0x200
  68. /* Offsets for EDMA CC global registers */
  69. #define EDMA_REV 0x0000
  70. #define EDMA_CCCFG 0x0004
  71. #define EDMA_QCHMAP 0x0200 /* 8 registers */
  72. #define EDMA_DMAQNUM 0x0240 /* 8 registers (4 on OMAP-L1xx) */
  73. #define EDMA_QDMAQNUM 0x0260
  74. #define EDMA_QUETCMAP 0x0280
  75. #define EDMA_QUEPRI 0x0284
  76. #define EDMA_EMR 0x0300 /* 64 bits */
  77. #define EDMA_EMCR 0x0308 /* 64 bits */
  78. #define EDMA_QEMR 0x0310
  79. #define EDMA_QEMCR 0x0314
  80. #define EDMA_CCERR 0x0318
  81. #define EDMA_CCERRCLR 0x031c
  82. #define EDMA_EEVAL 0x0320
  83. #define EDMA_DRAE 0x0340 /* 4 x 64 bits*/
  84. #define EDMA_QRAE 0x0380 /* 4 registers */
  85. #define EDMA_QUEEVTENTRY 0x0400 /* 2 x 16 registers */
  86. #define EDMA_QSTAT 0x0600 /* 2 registers */
  87. #define EDMA_QWMTHRA 0x0620
  88. #define EDMA_QWMTHRB 0x0624
  89. #define EDMA_CCSTAT 0x0640
  90. #define EDMA_M 0x1000 /* global channel registers */
  91. #define EDMA_ECR 0x1008
  92. #define EDMA_ECRH 0x100C
  93. #define EDMA_SHADOW0 0x2000 /* 4 regions shadowing global channels */
  94. #define EDMA_PARM 0x4000 /* 128 param entries */
  95. #define PARM_OFFSET(param_no) (EDMA_PARM + ((param_no) << 5))
  96. #define EDMA_DCHMAP 0x0100 /* 64 registers */
  97. #define CHMAP_EXIST BIT(24)
  98. #define EDMA_MAX_DMACH 64
  99. #define EDMA_MAX_PARAMENTRY 512
  100. /*****************************************************************************/
  101. static void __iomem *edmacc_regs_base[EDMA_MAX_CC];
  102. static inline unsigned int edma_read(unsigned ctlr, int offset)
  103. {
  104. return (unsigned int)__raw_readl(edmacc_regs_base[ctlr] + offset);
  105. }
  106. static inline void edma_write(unsigned ctlr, int offset, int val)
  107. {
  108. __raw_writel(val, edmacc_regs_base[ctlr] + offset);
  109. }
  110. static inline void edma_modify(unsigned ctlr, int offset, unsigned and,
  111. unsigned or)
  112. {
  113. unsigned val = edma_read(ctlr, offset);
  114. val &= and;
  115. val |= or;
  116. edma_write(ctlr, offset, val);
  117. }
  118. static inline void edma_and(unsigned ctlr, int offset, unsigned and)
  119. {
  120. unsigned val = edma_read(ctlr, offset);
  121. val &= and;
  122. edma_write(ctlr, offset, val);
  123. }
  124. static inline void edma_or(unsigned ctlr, int offset, unsigned or)
  125. {
  126. unsigned val = edma_read(ctlr, offset);
  127. val |= or;
  128. edma_write(ctlr, offset, val);
  129. }
  130. static inline unsigned int edma_read_array(unsigned ctlr, int offset, int i)
  131. {
  132. return edma_read(ctlr, offset + (i << 2));
  133. }
  134. static inline void edma_write_array(unsigned ctlr, int offset, int i,
  135. unsigned val)
  136. {
  137. edma_write(ctlr, offset + (i << 2), val);
  138. }
  139. static inline void edma_modify_array(unsigned ctlr, int offset, int i,
  140. unsigned and, unsigned or)
  141. {
  142. edma_modify(ctlr, offset + (i << 2), and, or);
  143. }
  144. static inline void edma_or_array(unsigned ctlr, int offset, int i, unsigned or)
  145. {
  146. edma_or(ctlr, offset + (i << 2), or);
  147. }
  148. static inline void edma_or_array2(unsigned ctlr, int offset, int i, int j,
  149. unsigned or)
  150. {
  151. edma_or(ctlr, offset + ((i*2 + j) << 2), or);
  152. }
  153. static inline void edma_write_array2(unsigned ctlr, int offset, int i, int j,
  154. unsigned val)
  155. {
  156. edma_write(ctlr, offset + ((i*2 + j) << 2), val);
  157. }
  158. static inline unsigned int edma_shadow0_read(unsigned ctlr, int offset)
  159. {
  160. return edma_read(ctlr, EDMA_SHADOW0 + offset);
  161. }
  162. static inline unsigned int edma_shadow0_read_array(unsigned ctlr, int offset,
  163. int i)
  164. {
  165. return edma_read(ctlr, EDMA_SHADOW0 + offset + (i << 2));
  166. }
  167. static inline void edma_shadow0_write(unsigned ctlr, int offset, unsigned val)
  168. {
  169. edma_write(ctlr, EDMA_SHADOW0 + offset, val);
  170. }
  171. static inline void edma_shadow0_write_array(unsigned ctlr, int offset, int i,
  172. unsigned val)
  173. {
  174. edma_write(ctlr, EDMA_SHADOW0 + offset + (i << 2), val);
  175. }
  176. static inline unsigned int edma_parm_read(unsigned ctlr, int offset,
  177. int param_no)
  178. {
  179. return edma_read(ctlr, EDMA_PARM + offset + (param_no << 5));
  180. }
  181. static inline void edma_parm_write(unsigned ctlr, int offset, int param_no,
  182. unsigned val)
  183. {
  184. edma_write(ctlr, EDMA_PARM + offset + (param_no << 5), val);
  185. }
  186. static inline void edma_parm_modify(unsigned ctlr, int offset, int param_no,
  187. unsigned and, unsigned or)
  188. {
  189. edma_modify(ctlr, EDMA_PARM + offset + (param_no << 5), and, or);
  190. }
  191. static inline void edma_parm_and(unsigned ctlr, int offset, int param_no,
  192. unsigned and)
  193. {
  194. edma_and(ctlr, EDMA_PARM + offset + (param_no << 5), and);
  195. }
  196. static inline void edma_parm_or(unsigned ctlr, int offset, int param_no,
  197. unsigned or)
  198. {
  199. edma_or(ctlr, EDMA_PARM + offset + (param_no << 5), or);
  200. }
  201. static inline void set_bits(int offset, int len, unsigned long *p)
  202. {
  203. for (; len > 0; len--)
  204. set_bit(offset + (len - 1), p);
  205. }
  206. static inline void clear_bits(int offset, int len, unsigned long *p)
  207. {
  208. for (; len > 0; len--)
  209. clear_bit(offset + (len - 1), p);
  210. }
  211. /*****************************************************************************/
  212. /* actual number of DMA channels and slots on this silicon */
  213. struct edma {
  214. /* how many dma resources of each type */
  215. unsigned num_channels;
  216. unsigned num_region;
  217. unsigned num_slots;
  218. unsigned num_tc;
  219. unsigned num_cc;
  220. enum dma_event_q default_queue;
  221. /* list of channels with no even trigger; terminated by "-1" */
  222. const s8 *noevent;
  223. /* The edma_inuse bit for each PaRAM slot is clear unless the
  224. * channel is in use ... by ARM or DSP, for QDMA, or whatever.
  225. */
  226. DECLARE_BITMAP(edma_inuse, EDMA_MAX_PARAMENTRY);
  227. /* The edma_unused bit for each channel is clear unless
  228. * it is not being used on this platform. It uses a bit
  229. * of SOC-specific initialization code.
  230. */
  231. DECLARE_BITMAP(edma_unused, EDMA_MAX_DMACH);
  232. unsigned irq_res_start;
  233. unsigned irq_res_end;
  234. struct dma_interrupt_data {
  235. void (*callback)(unsigned channel, unsigned short ch_status,
  236. void *data);
  237. void *data;
  238. } intr_data[EDMA_MAX_DMACH];
  239. };
  240. static struct edma *edma_cc[EDMA_MAX_CC];
  241. static int arch_num_cc;
  242. /* dummy param set used to (re)initialize parameter RAM slots */
  243. static const struct edmacc_param dummy_paramset = {
  244. .link_bcntrld = 0xffff,
  245. .ccnt = 1,
  246. };
  247. static const struct of_device_id edma_of_ids[] = {
  248. { .compatible = "ti,edma3", },
  249. {}
  250. };
  251. /*****************************************************************************/
  252. static void map_dmach_queue(unsigned ctlr, unsigned ch_no,
  253. enum dma_event_q queue_no)
  254. {
  255. int bit = (ch_no & 0x7) * 4;
  256. /* default to low priority queue */
  257. if (queue_no == EVENTQ_DEFAULT)
  258. queue_no = edma_cc[ctlr]->default_queue;
  259. queue_no &= 7;
  260. edma_modify_array(ctlr, EDMA_DMAQNUM, (ch_no >> 3),
  261. ~(0x7 << bit), queue_no << bit);
  262. }
  263. static void __init map_queue_tc(unsigned ctlr, int queue_no, int tc_no)
  264. {
  265. int bit = queue_no * 4;
  266. edma_modify(ctlr, EDMA_QUETCMAP, ~(0x7 << bit), ((tc_no & 0x7) << bit));
  267. }
  268. static void __init assign_priority_to_queue(unsigned ctlr, int queue_no,
  269. int priority)
  270. {
  271. int bit = queue_no * 4;
  272. edma_modify(ctlr, EDMA_QUEPRI, ~(0x7 << bit),
  273. ((priority & 0x7) << bit));
  274. }
  275. /**
  276. * map_dmach_param - Maps channel number to param entry number
  277. *
  278. * This maps the dma channel number to param entry numberter. In
  279. * other words using the DMA channel mapping registers a param entry
  280. * can be mapped to any channel
  281. *
  282. * Callers are responsible for ensuring the channel mapping logic is
  283. * included in that particular EDMA variant (Eg : dm646x)
  284. *
  285. */
  286. static void __init map_dmach_param(unsigned ctlr)
  287. {
  288. int i;
  289. for (i = 0; i < EDMA_MAX_DMACH; i++)
  290. edma_write_array(ctlr, EDMA_DCHMAP , i , (i << 5));
  291. }
  292. static inline void
  293. setup_dma_interrupt(unsigned lch,
  294. void (*callback)(unsigned channel, u16 ch_status, void *data),
  295. void *data)
  296. {
  297. unsigned ctlr;
  298. ctlr = EDMA_CTLR(lch);
  299. lch = EDMA_CHAN_SLOT(lch);
  300. if (!callback)
  301. edma_shadow0_write_array(ctlr, SH_IECR, lch >> 5,
  302. BIT(lch & 0x1f));
  303. edma_cc[ctlr]->intr_data[lch].callback = callback;
  304. edma_cc[ctlr]->intr_data[lch].data = data;
  305. if (callback) {
  306. edma_shadow0_write_array(ctlr, SH_ICR, lch >> 5,
  307. BIT(lch & 0x1f));
  308. edma_shadow0_write_array(ctlr, SH_IESR, lch >> 5,
  309. BIT(lch & 0x1f));
  310. }
  311. }
  312. static int irq2ctlr(int irq)
  313. {
  314. if (irq >= edma_cc[0]->irq_res_start && irq <= edma_cc[0]->irq_res_end)
  315. return 0;
  316. else if (irq >= edma_cc[1]->irq_res_start &&
  317. irq <= edma_cc[1]->irq_res_end)
  318. return 1;
  319. return -1;
  320. }
  321. /******************************************************************************
  322. *
  323. * DMA interrupt handler
  324. *
  325. *****************************************************************************/
  326. static irqreturn_t dma_irq_handler(int irq, void *data)
  327. {
  328. int ctlr;
  329. u32 sh_ier;
  330. u32 sh_ipr;
  331. u32 bank;
  332. ctlr = irq2ctlr(irq);
  333. if (ctlr < 0)
  334. return IRQ_NONE;
  335. dev_dbg(data, "dma_irq_handler\n");
  336. sh_ipr = edma_shadow0_read_array(ctlr, SH_IPR, 0);
  337. if (!sh_ipr) {
  338. sh_ipr = edma_shadow0_read_array(ctlr, SH_IPR, 1);
  339. if (!sh_ipr)
  340. return IRQ_NONE;
  341. sh_ier = edma_shadow0_read_array(ctlr, SH_IER, 1);
  342. bank = 1;
  343. } else {
  344. sh_ier = edma_shadow0_read_array(ctlr, SH_IER, 0);
  345. bank = 0;
  346. }
  347. do {
  348. u32 slot;
  349. u32 channel;
  350. dev_dbg(data, "IPR%d %08x\n", bank, sh_ipr);
  351. slot = __ffs(sh_ipr);
  352. sh_ipr &= ~(BIT(slot));
  353. if (sh_ier & BIT(slot)) {
  354. channel = (bank << 5) | slot;
  355. /* Clear the corresponding IPR bits */
  356. edma_shadow0_write_array(ctlr, SH_ICR, bank,
  357. BIT(slot));
  358. if (edma_cc[ctlr]->intr_data[channel].callback)
  359. edma_cc[ctlr]->intr_data[channel].callback(
  360. channel, DMA_COMPLETE,
  361. edma_cc[ctlr]->intr_data[channel].data);
  362. }
  363. } while (sh_ipr);
  364. edma_shadow0_write(ctlr, SH_IEVAL, 1);
  365. return IRQ_HANDLED;
  366. }
  367. /******************************************************************************
  368. *
  369. * DMA error interrupt handler
  370. *
  371. *****************************************************************************/
  372. static irqreturn_t dma_ccerr_handler(int irq, void *data)
  373. {
  374. int i;
  375. int ctlr;
  376. unsigned int cnt = 0;
  377. ctlr = irq2ctlr(irq);
  378. if (ctlr < 0)
  379. return IRQ_NONE;
  380. dev_dbg(data, "dma_ccerr_handler\n");
  381. if ((edma_read_array(ctlr, EDMA_EMR, 0) == 0) &&
  382. (edma_read_array(ctlr, EDMA_EMR, 1) == 0) &&
  383. (edma_read(ctlr, EDMA_QEMR) == 0) &&
  384. (edma_read(ctlr, EDMA_CCERR) == 0))
  385. return IRQ_NONE;
  386. while (1) {
  387. int j = -1;
  388. if (edma_read_array(ctlr, EDMA_EMR, 0))
  389. j = 0;
  390. else if (edma_read_array(ctlr, EDMA_EMR, 1))
  391. j = 1;
  392. if (j >= 0) {
  393. dev_dbg(data, "EMR%d %08x\n", j,
  394. edma_read_array(ctlr, EDMA_EMR, j));
  395. for (i = 0; i < 32; i++) {
  396. int k = (j << 5) + i;
  397. if (edma_read_array(ctlr, EDMA_EMR, j) &
  398. BIT(i)) {
  399. /* Clear the corresponding EMR bits */
  400. edma_write_array(ctlr, EDMA_EMCR, j,
  401. BIT(i));
  402. /* Clear any SER */
  403. edma_shadow0_write_array(ctlr, SH_SECR,
  404. j, BIT(i));
  405. if (edma_cc[ctlr]->intr_data[k].
  406. callback) {
  407. edma_cc[ctlr]->intr_data[k].
  408. callback(k,
  409. DMA_CC_ERROR,
  410. edma_cc[ctlr]->intr_data
  411. [k].data);
  412. }
  413. }
  414. }
  415. } else if (edma_read(ctlr, EDMA_QEMR)) {
  416. dev_dbg(data, "QEMR %02x\n",
  417. edma_read(ctlr, EDMA_QEMR));
  418. for (i = 0; i < 8; i++) {
  419. if (edma_read(ctlr, EDMA_QEMR) & BIT(i)) {
  420. /* Clear the corresponding IPR bits */
  421. edma_write(ctlr, EDMA_QEMCR, BIT(i));
  422. edma_shadow0_write(ctlr, SH_QSECR,
  423. BIT(i));
  424. /* NOTE: not reported!! */
  425. }
  426. }
  427. } else if (edma_read(ctlr, EDMA_CCERR)) {
  428. dev_dbg(data, "CCERR %08x\n",
  429. edma_read(ctlr, EDMA_CCERR));
  430. /* FIXME: CCERR.BIT(16) ignored! much better
  431. * to just write CCERRCLR with CCERR value...
  432. */
  433. for (i = 0; i < 8; i++) {
  434. if (edma_read(ctlr, EDMA_CCERR) & BIT(i)) {
  435. /* Clear the corresponding IPR bits */
  436. edma_write(ctlr, EDMA_CCERRCLR, BIT(i));
  437. /* NOTE: not reported!! */
  438. }
  439. }
  440. }
  441. if ((edma_read_array(ctlr, EDMA_EMR, 0) == 0) &&
  442. (edma_read_array(ctlr, EDMA_EMR, 1) == 0) &&
  443. (edma_read(ctlr, EDMA_QEMR) == 0) &&
  444. (edma_read(ctlr, EDMA_CCERR) == 0))
  445. break;
  446. cnt++;
  447. if (cnt > 10)
  448. break;
  449. }
  450. edma_write(ctlr, EDMA_EEVAL, 1);
  451. return IRQ_HANDLED;
  452. }
  453. static int reserve_contiguous_slots(int ctlr, unsigned int id,
  454. unsigned int num_slots,
  455. unsigned int start_slot)
  456. {
  457. int i, j;
  458. unsigned int count = num_slots;
  459. int stop_slot = start_slot;
  460. DECLARE_BITMAP(tmp_inuse, EDMA_MAX_PARAMENTRY);
  461. for (i = start_slot; i < edma_cc[ctlr]->num_slots; ++i) {
  462. j = EDMA_CHAN_SLOT(i);
  463. if (!test_and_set_bit(j, edma_cc[ctlr]->edma_inuse)) {
  464. /* Record our current beginning slot */
  465. if (count == num_slots)
  466. stop_slot = i;
  467. count--;
  468. set_bit(j, tmp_inuse);
  469. if (count == 0)
  470. break;
  471. } else {
  472. clear_bit(j, tmp_inuse);
  473. if (id == EDMA_CONT_PARAMS_FIXED_EXACT) {
  474. stop_slot = i;
  475. break;
  476. } else {
  477. count = num_slots;
  478. }
  479. }
  480. }
  481. /*
  482. * We have to clear any bits that we set
  483. * if we run out parameter RAM slots, i.e we do find a set
  484. * of contiguous parameter RAM slots but do not find the exact number
  485. * requested as we may reach the total number of parameter RAM slots
  486. */
  487. if (i == edma_cc[ctlr]->num_slots)
  488. stop_slot = i;
  489. j = start_slot;
  490. for_each_set_bit_from(j, tmp_inuse, stop_slot)
  491. clear_bit(j, edma_cc[ctlr]->edma_inuse);
  492. if (count)
  493. return -EBUSY;
  494. for (j = i - num_slots + 1; j <= i; ++j)
  495. memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(j),
  496. &dummy_paramset, PARM_SIZE);
  497. return EDMA_CTLR_CHAN(ctlr, i - num_slots + 1);
  498. }
  499. static int prepare_unused_channel_list(struct device *dev, void *data)
  500. {
  501. struct platform_device *pdev = to_platform_device(dev);
  502. int i, count, ctlr;
  503. struct of_phandle_args dma_spec;
  504. if (dev->of_node) {
  505. count = of_property_count_strings(dev->of_node, "dma-names");
  506. if (count < 0)
  507. return 0;
  508. for (i = 0; i < count; i++) {
  509. if (of_parse_phandle_with_args(dev->of_node, "dmas",
  510. "#dma-cells", i,
  511. &dma_spec))
  512. continue;
  513. if (!of_match_node(edma_of_ids, dma_spec.np)) {
  514. of_node_put(dma_spec.np);
  515. continue;
  516. }
  517. clear_bit(EDMA_CHAN_SLOT(dma_spec.args[0]),
  518. edma_cc[0]->edma_unused);
  519. of_node_put(dma_spec.np);
  520. }
  521. return 0;
  522. }
  523. /* For non-OF case */
  524. for (i = 0; i < pdev->num_resources; i++) {
  525. if ((pdev->resource[i].flags & IORESOURCE_DMA) &&
  526. (int)pdev->resource[i].start >= 0) {
  527. ctlr = EDMA_CTLR(pdev->resource[i].start);
  528. clear_bit(EDMA_CHAN_SLOT(pdev->resource[i].start),
  529. edma_cc[ctlr]->edma_unused);
  530. }
  531. }
  532. return 0;
  533. }
  534. /*-----------------------------------------------------------------------*/
  535. static bool unused_chan_list_done;
  536. /* Resource alloc/free: dma channels, parameter RAM slots */
  537. /**
  538. * edma_alloc_channel - allocate DMA channel and paired parameter RAM
  539. * @channel: specific channel to allocate; negative for "any unmapped channel"
  540. * @callback: optional; to be issued on DMA completion or errors
  541. * @data: passed to callback
  542. * @eventq_no: an EVENTQ_* constant, used to choose which Transfer
  543. * Controller (TC) executes requests using this channel. Use
  544. * EVENTQ_DEFAULT unless you really need a high priority queue.
  545. *
  546. * This allocates a DMA channel and its associated parameter RAM slot.
  547. * The parameter RAM is initialized to hold a dummy transfer.
  548. *
  549. * Normal use is to pass a specific channel number as @channel, to make
  550. * use of hardware events mapped to that channel. When the channel will
  551. * be used only for software triggering or event chaining, channels not
  552. * mapped to hardware events (or mapped to unused events) are preferable.
  553. *
  554. * DMA transfers start from a channel using edma_start(), or by
  555. * chaining. When the transfer described in that channel's parameter RAM
  556. * slot completes, that slot's data may be reloaded through a link.
  557. *
  558. * DMA errors are only reported to the @callback associated with the
  559. * channel driving that transfer, but transfer completion callbacks can
  560. * be sent to another channel under control of the TCC field in
  561. * the option word of the transfer's parameter RAM set. Drivers must not
  562. * use DMA transfer completion callbacks for channels they did not allocate.
  563. * (The same applies to TCC codes used in transfer chaining.)
  564. *
  565. * Returns the number of the channel, else negative errno.
  566. */
  567. int edma_alloc_channel(int channel,
  568. void (*callback)(unsigned channel, u16 ch_status, void *data),
  569. void *data,
  570. enum dma_event_q eventq_no)
  571. {
  572. unsigned i, done = 0, ctlr = 0;
  573. int ret = 0;
  574. if (!unused_chan_list_done) {
  575. /*
  576. * Scan all the platform devices to find out the EDMA channels
  577. * used and clear them in the unused list, making the rest
  578. * available for ARM usage.
  579. */
  580. ret = bus_for_each_dev(&platform_bus_type, NULL, NULL,
  581. prepare_unused_channel_list);
  582. if (ret < 0)
  583. return ret;
  584. unused_chan_list_done = true;
  585. }
  586. if (channel >= 0) {
  587. ctlr = EDMA_CTLR(channel);
  588. channel = EDMA_CHAN_SLOT(channel);
  589. }
  590. if (channel < 0) {
  591. for (i = 0; i < arch_num_cc; i++) {
  592. channel = 0;
  593. for (;;) {
  594. channel = find_next_bit(edma_cc[i]->edma_unused,
  595. edma_cc[i]->num_channels,
  596. channel);
  597. if (channel == edma_cc[i]->num_channels)
  598. break;
  599. if (!test_and_set_bit(channel,
  600. edma_cc[i]->edma_inuse)) {
  601. done = 1;
  602. ctlr = i;
  603. break;
  604. }
  605. channel++;
  606. }
  607. if (done)
  608. break;
  609. }
  610. if (!done)
  611. return -ENOMEM;
  612. } else if (channel >= edma_cc[ctlr]->num_channels) {
  613. return -EINVAL;
  614. } else if (test_and_set_bit(channel, edma_cc[ctlr]->edma_inuse)) {
  615. return -EBUSY;
  616. }
  617. /* ensure access through shadow region 0 */
  618. edma_or_array2(ctlr, EDMA_DRAE, 0, channel >> 5, BIT(channel & 0x1f));
  619. /* ensure no events are pending */
  620. edma_stop(EDMA_CTLR_CHAN(ctlr, channel));
  621. memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(channel),
  622. &dummy_paramset, PARM_SIZE);
  623. if (callback)
  624. setup_dma_interrupt(EDMA_CTLR_CHAN(ctlr, channel),
  625. callback, data);
  626. map_dmach_queue(ctlr, channel, eventq_no);
  627. return EDMA_CTLR_CHAN(ctlr, channel);
  628. }
  629. EXPORT_SYMBOL(edma_alloc_channel);
  630. /**
  631. * edma_free_channel - deallocate DMA channel
  632. * @channel: dma channel returned from edma_alloc_channel()
  633. *
  634. * This deallocates the DMA channel and associated parameter RAM slot
  635. * allocated by edma_alloc_channel().
  636. *
  637. * Callers are responsible for ensuring the channel is inactive, and
  638. * will not be reactivated by linking, chaining, or software calls to
  639. * edma_start().
  640. */
  641. void edma_free_channel(unsigned channel)
  642. {
  643. unsigned ctlr;
  644. ctlr = EDMA_CTLR(channel);
  645. channel = EDMA_CHAN_SLOT(channel);
  646. if (channel >= edma_cc[ctlr]->num_channels)
  647. return;
  648. setup_dma_interrupt(channel, NULL, NULL);
  649. /* REVISIT should probably take out of shadow region 0 */
  650. memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(channel),
  651. &dummy_paramset, PARM_SIZE);
  652. clear_bit(channel, edma_cc[ctlr]->edma_inuse);
  653. }
  654. EXPORT_SYMBOL(edma_free_channel);
  655. /**
  656. * edma_alloc_slot - allocate DMA parameter RAM
  657. * @slot: specific slot to allocate; negative for "any unused slot"
  658. *
  659. * This allocates a parameter RAM slot, initializing it to hold a
  660. * dummy transfer. Slots allocated using this routine have not been
  661. * mapped to a hardware DMA channel, and will normally be used by
  662. * linking to them from a slot associated with a DMA channel.
  663. *
  664. * Normal use is to pass EDMA_SLOT_ANY as the @slot, but specific
  665. * slots may be allocated on behalf of DSP firmware.
  666. *
  667. * Returns the number of the slot, else negative errno.
  668. */
  669. int edma_alloc_slot(unsigned ctlr, int slot)
  670. {
  671. if (!edma_cc[ctlr])
  672. return -EINVAL;
  673. if (slot >= 0)
  674. slot = EDMA_CHAN_SLOT(slot);
  675. if (slot < 0) {
  676. slot = edma_cc[ctlr]->num_channels;
  677. for (;;) {
  678. slot = find_next_zero_bit(edma_cc[ctlr]->edma_inuse,
  679. edma_cc[ctlr]->num_slots, slot);
  680. if (slot == edma_cc[ctlr]->num_slots)
  681. return -ENOMEM;
  682. if (!test_and_set_bit(slot, edma_cc[ctlr]->edma_inuse))
  683. break;
  684. }
  685. } else if (slot < edma_cc[ctlr]->num_channels ||
  686. slot >= edma_cc[ctlr]->num_slots) {
  687. return -EINVAL;
  688. } else if (test_and_set_bit(slot, edma_cc[ctlr]->edma_inuse)) {
  689. return -EBUSY;
  690. }
  691. memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(slot),
  692. &dummy_paramset, PARM_SIZE);
  693. return EDMA_CTLR_CHAN(ctlr, slot);
  694. }
  695. EXPORT_SYMBOL(edma_alloc_slot);
  696. /**
  697. * edma_free_slot - deallocate DMA parameter RAM
  698. * @slot: parameter RAM slot returned from edma_alloc_slot()
  699. *
  700. * This deallocates the parameter RAM slot allocated by edma_alloc_slot().
  701. * Callers are responsible for ensuring the slot is inactive, and will
  702. * not be activated.
  703. */
  704. void edma_free_slot(unsigned slot)
  705. {
  706. unsigned ctlr;
  707. ctlr = EDMA_CTLR(slot);
  708. slot = EDMA_CHAN_SLOT(slot);
  709. if (slot < edma_cc[ctlr]->num_channels ||
  710. slot >= edma_cc[ctlr]->num_slots)
  711. return;
  712. memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(slot),
  713. &dummy_paramset, PARM_SIZE);
  714. clear_bit(slot, edma_cc[ctlr]->edma_inuse);
  715. }
  716. EXPORT_SYMBOL(edma_free_slot);
  717. /**
  718. * edma_alloc_cont_slots- alloc contiguous parameter RAM slots
  719. * The API will return the starting point of a set of
  720. * contiguous parameter RAM slots that have been requested
  721. *
  722. * @id: can only be EDMA_CONT_PARAMS_ANY or EDMA_CONT_PARAMS_FIXED_EXACT
  723. * or EDMA_CONT_PARAMS_FIXED_NOT_EXACT
  724. * @count: number of contiguous Paramter RAM slots
  725. * @slot - the start value of Parameter RAM slot that should be passed if id
  726. * is EDMA_CONT_PARAMS_FIXED_EXACT or EDMA_CONT_PARAMS_FIXED_NOT_EXACT
  727. *
  728. * If id is EDMA_CONT_PARAMS_ANY then the API starts looking for a set of
  729. * contiguous Parameter RAM slots from parameter RAM 64 in the case of
  730. * DaVinci SOCs and 32 in the case of DA8xx SOCs.
  731. *
  732. * If id is EDMA_CONT_PARAMS_FIXED_EXACT then the API starts looking for a
  733. * set of contiguous parameter RAM slots from the "slot" that is passed as an
  734. * argument to the API.
  735. *
  736. * If id is EDMA_CONT_PARAMS_FIXED_NOT_EXACT then the API initially tries
  737. * starts looking for a set of contiguous parameter RAMs from the "slot"
  738. * that is passed as an argument to the API. On failure the API will try to
  739. * find a set of contiguous Parameter RAM slots from the remaining Parameter
  740. * RAM slots
  741. */
  742. int edma_alloc_cont_slots(unsigned ctlr, unsigned int id, int slot, int count)
  743. {
  744. /*
  745. * The start slot requested should be greater than
  746. * the number of channels and lesser than the total number
  747. * of slots
  748. */
  749. if ((id != EDMA_CONT_PARAMS_ANY) &&
  750. (slot < edma_cc[ctlr]->num_channels ||
  751. slot >= edma_cc[ctlr]->num_slots))
  752. return -EINVAL;
  753. /*
  754. * The number of parameter RAM slots requested cannot be less than 1
  755. * and cannot be more than the number of slots minus the number of
  756. * channels
  757. */
  758. if (count < 1 || count >
  759. (edma_cc[ctlr]->num_slots - edma_cc[ctlr]->num_channels))
  760. return -EINVAL;
  761. switch (id) {
  762. case EDMA_CONT_PARAMS_ANY:
  763. return reserve_contiguous_slots(ctlr, id, count,
  764. edma_cc[ctlr]->num_channels);
  765. case EDMA_CONT_PARAMS_FIXED_EXACT:
  766. case EDMA_CONT_PARAMS_FIXED_NOT_EXACT:
  767. return reserve_contiguous_slots(ctlr, id, count, slot);
  768. default:
  769. return -EINVAL;
  770. }
  771. }
  772. EXPORT_SYMBOL(edma_alloc_cont_slots);
  773. /**
  774. * edma_free_cont_slots - deallocate DMA parameter RAM slots
  775. * @slot: first parameter RAM of a set of parameter RAM slots to be freed
  776. * @count: the number of contiguous parameter RAM slots to be freed
  777. *
  778. * This deallocates the parameter RAM slots allocated by
  779. * edma_alloc_cont_slots.
  780. * Callers/applications need to keep track of sets of contiguous
  781. * parameter RAM slots that have been allocated using the edma_alloc_cont_slots
  782. * API.
  783. * Callers are responsible for ensuring the slots are inactive, and will
  784. * not be activated.
  785. */
  786. int edma_free_cont_slots(unsigned slot, int count)
  787. {
  788. unsigned ctlr, slot_to_free;
  789. int i;
  790. ctlr = EDMA_CTLR(slot);
  791. slot = EDMA_CHAN_SLOT(slot);
  792. if (slot < edma_cc[ctlr]->num_channels ||
  793. slot >= edma_cc[ctlr]->num_slots ||
  794. count < 1)
  795. return -EINVAL;
  796. for (i = slot; i < slot + count; ++i) {
  797. ctlr = EDMA_CTLR(i);
  798. slot_to_free = EDMA_CHAN_SLOT(i);
  799. memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(slot_to_free),
  800. &dummy_paramset, PARM_SIZE);
  801. clear_bit(slot_to_free, edma_cc[ctlr]->edma_inuse);
  802. }
  803. return 0;
  804. }
  805. EXPORT_SYMBOL(edma_free_cont_slots);
  806. /*-----------------------------------------------------------------------*/
  807. /* Parameter RAM operations (i) -- read/write partial slots */
  808. /**
  809. * edma_set_src - set initial DMA source address in parameter RAM slot
  810. * @slot: parameter RAM slot being configured
  811. * @src_port: physical address of source (memory, controller FIFO, etc)
  812. * @addressMode: INCR, except in very rare cases
  813. * @fifoWidth: ignored unless @addressMode is FIFO, else specifies the
  814. * width to use when addressing the fifo (e.g. W8BIT, W32BIT)
  815. *
  816. * Note that the source address is modified during the DMA transfer
  817. * according to edma_set_src_index().
  818. */
  819. void edma_set_src(unsigned slot, dma_addr_t src_port,
  820. enum address_mode mode, enum fifo_width width)
  821. {
  822. unsigned ctlr;
  823. ctlr = EDMA_CTLR(slot);
  824. slot = EDMA_CHAN_SLOT(slot);
  825. if (slot < edma_cc[ctlr]->num_slots) {
  826. unsigned int i = edma_parm_read(ctlr, PARM_OPT, slot);
  827. if (mode) {
  828. /* set SAM and program FWID */
  829. i = (i & ~(EDMA_FWID)) | (SAM | ((width & 0x7) << 8));
  830. } else {
  831. /* clear SAM */
  832. i &= ~SAM;
  833. }
  834. edma_parm_write(ctlr, PARM_OPT, slot, i);
  835. /* set the source port address
  836. in source register of param structure */
  837. edma_parm_write(ctlr, PARM_SRC, slot, src_port);
  838. }
  839. }
  840. EXPORT_SYMBOL(edma_set_src);
  841. /**
  842. * edma_set_dest - set initial DMA destination address in parameter RAM slot
  843. * @slot: parameter RAM slot being configured
  844. * @dest_port: physical address of destination (memory, controller FIFO, etc)
  845. * @addressMode: INCR, except in very rare cases
  846. * @fifoWidth: ignored unless @addressMode is FIFO, else specifies the
  847. * width to use when addressing the fifo (e.g. W8BIT, W32BIT)
  848. *
  849. * Note that the destination address is modified during the DMA transfer
  850. * according to edma_set_dest_index().
  851. */
  852. void edma_set_dest(unsigned slot, dma_addr_t dest_port,
  853. enum address_mode mode, enum fifo_width width)
  854. {
  855. unsigned ctlr;
  856. ctlr = EDMA_CTLR(slot);
  857. slot = EDMA_CHAN_SLOT(slot);
  858. if (slot < edma_cc[ctlr]->num_slots) {
  859. unsigned int i = edma_parm_read(ctlr, PARM_OPT, slot);
  860. if (mode) {
  861. /* set DAM and program FWID */
  862. i = (i & ~(EDMA_FWID)) | (DAM | ((width & 0x7) << 8));
  863. } else {
  864. /* clear DAM */
  865. i &= ~DAM;
  866. }
  867. edma_parm_write(ctlr, PARM_OPT, slot, i);
  868. /* set the destination port address
  869. in dest register of param structure */
  870. edma_parm_write(ctlr, PARM_DST, slot, dest_port);
  871. }
  872. }
  873. EXPORT_SYMBOL(edma_set_dest);
  874. /**
  875. * edma_get_position - returns the current transfer points
  876. * @slot: parameter RAM slot being examined
  877. * @src: pointer to source port position
  878. * @dst: pointer to destination port position
  879. *
  880. * Returns current source and destination addresses for a particular
  881. * parameter RAM slot. Its channel should not be active when this is called.
  882. */
  883. void edma_get_position(unsigned slot, dma_addr_t *src, dma_addr_t *dst)
  884. {
  885. struct edmacc_param temp;
  886. unsigned ctlr;
  887. ctlr = EDMA_CTLR(slot);
  888. slot = EDMA_CHAN_SLOT(slot);
  889. edma_read_slot(EDMA_CTLR_CHAN(ctlr, slot), &temp);
  890. if (src != NULL)
  891. *src = temp.src;
  892. if (dst != NULL)
  893. *dst = temp.dst;
  894. }
  895. EXPORT_SYMBOL(edma_get_position);
  896. /**
  897. * edma_set_src_index - configure DMA source address indexing
  898. * @slot: parameter RAM slot being configured
  899. * @src_bidx: byte offset between source arrays in a frame
  900. * @src_cidx: byte offset between source frames in a block
  901. *
  902. * Offsets are specified to support either contiguous or discontiguous
  903. * memory transfers, or repeated access to a hardware register, as needed.
  904. * When accessing hardware registers, both offsets are normally zero.
  905. */
  906. void edma_set_src_index(unsigned slot, s16 src_bidx, s16 src_cidx)
  907. {
  908. unsigned ctlr;
  909. ctlr = EDMA_CTLR(slot);
  910. slot = EDMA_CHAN_SLOT(slot);
  911. if (slot < edma_cc[ctlr]->num_slots) {
  912. edma_parm_modify(ctlr, PARM_SRC_DST_BIDX, slot,
  913. 0xffff0000, src_bidx);
  914. edma_parm_modify(ctlr, PARM_SRC_DST_CIDX, slot,
  915. 0xffff0000, src_cidx);
  916. }
  917. }
  918. EXPORT_SYMBOL(edma_set_src_index);
  919. /**
  920. * edma_set_dest_index - configure DMA destination address indexing
  921. * @slot: parameter RAM slot being configured
  922. * @dest_bidx: byte offset between destination arrays in a frame
  923. * @dest_cidx: byte offset between destination frames in a block
  924. *
  925. * Offsets are specified to support either contiguous or discontiguous
  926. * memory transfers, or repeated access to a hardware register, as needed.
  927. * When accessing hardware registers, both offsets are normally zero.
  928. */
  929. void edma_set_dest_index(unsigned slot, s16 dest_bidx, s16 dest_cidx)
  930. {
  931. unsigned ctlr;
  932. ctlr = EDMA_CTLR(slot);
  933. slot = EDMA_CHAN_SLOT(slot);
  934. if (slot < edma_cc[ctlr]->num_slots) {
  935. edma_parm_modify(ctlr, PARM_SRC_DST_BIDX, slot,
  936. 0x0000ffff, dest_bidx << 16);
  937. edma_parm_modify(ctlr, PARM_SRC_DST_CIDX, slot,
  938. 0x0000ffff, dest_cidx << 16);
  939. }
  940. }
  941. EXPORT_SYMBOL(edma_set_dest_index);
  942. /**
  943. * edma_set_transfer_params - configure DMA transfer parameters
  944. * @slot: parameter RAM slot being configured
  945. * @acnt: how many bytes per array (at least one)
  946. * @bcnt: how many arrays per frame (at least one)
  947. * @ccnt: how many frames per block (at least one)
  948. * @bcnt_rld: used only for A-Synchronized transfers; this specifies
  949. * the value to reload into bcnt when it decrements to zero
  950. * @sync_mode: ASYNC or ABSYNC
  951. *
  952. * See the EDMA3 documentation to understand how to configure and link
  953. * transfers using the fields in PaRAM slots. If you are not doing it
  954. * all at once with edma_write_slot(), you will use this routine
  955. * plus two calls each for source and destination, setting the initial
  956. * address and saying how to index that address.
  957. *
  958. * An example of an A-Synchronized transfer is a serial link using a
  959. * single word shift register. In that case, @acnt would be equal to
  960. * that word size; the serial controller issues a DMA synchronization
  961. * event to transfer each word, and memory access by the DMA transfer
  962. * controller will be word-at-a-time.
  963. *
  964. * An example of an AB-Synchronized transfer is a device using a FIFO.
  965. * In that case, @acnt equals the FIFO width and @bcnt equals its depth.
  966. * The controller with the FIFO issues DMA synchronization events when
  967. * the FIFO threshold is reached, and the DMA transfer controller will
  968. * transfer one frame to (or from) the FIFO. It will probably use
  969. * efficient burst modes to access memory.
  970. */
  971. void edma_set_transfer_params(unsigned slot,
  972. u16 acnt, u16 bcnt, u16 ccnt,
  973. u16 bcnt_rld, enum sync_dimension sync_mode)
  974. {
  975. unsigned ctlr;
  976. ctlr = EDMA_CTLR(slot);
  977. slot = EDMA_CHAN_SLOT(slot);
  978. if (slot < edma_cc[ctlr]->num_slots) {
  979. edma_parm_modify(ctlr, PARM_LINK_BCNTRLD, slot,
  980. 0x0000ffff, bcnt_rld << 16);
  981. if (sync_mode == ASYNC)
  982. edma_parm_and(ctlr, PARM_OPT, slot, ~SYNCDIM);
  983. else
  984. edma_parm_or(ctlr, PARM_OPT, slot, SYNCDIM);
  985. /* Set the acount, bcount, ccount registers */
  986. edma_parm_write(ctlr, PARM_A_B_CNT, slot, (bcnt << 16) | acnt);
  987. edma_parm_write(ctlr, PARM_CCNT, slot, ccnt);
  988. }
  989. }
  990. EXPORT_SYMBOL(edma_set_transfer_params);
  991. /**
  992. * edma_link - link one parameter RAM slot to another
  993. * @from: parameter RAM slot originating the link
  994. * @to: parameter RAM slot which is the link target
  995. *
  996. * The originating slot should not be part of any active DMA transfer.
  997. */
  998. void edma_link(unsigned from, unsigned to)
  999. {
  1000. unsigned ctlr_from, ctlr_to;
  1001. ctlr_from = EDMA_CTLR(from);
  1002. from = EDMA_CHAN_SLOT(from);
  1003. ctlr_to = EDMA_CTLR(to);
  1004. to = EDMA_CHAN_SLOT(to);
  1005. if (from >= edma_cc[ctlr_from]->num_slots)
  1006. return;
  1007. if (to >= edma_cc[ctlr_to]->num_slots)
  1008. return;
  1009. edma_parm_modify(ctlr_from, PARM_LINK_BCNTRLD, from, 0xffff0000,
  1010. PARM_OFFSET(to));
  1011. }
  1012. EXPORT_SYMBOL(edma_link);
  1013. /**
  1014. * edma_unlink - cut link from one parameter RAM slot
  1015. * @from: parameter RAM slot originating the link
  1016. *
  1017. * The originating slot should not be part of any active DMA transfer.
  1018. * Its link is set to 0xffff.
  1019. */
  1020. void edma_unlink(unsigned from)
  1021. {
  1022. unsigned ctlr;
  1023. ctlr = EDMA_CTLR(from);
  1024. from = EDMA_CHAN_SLOT(from);
  1025. if (from >= edma_cc[ctlr]->num_slots)
  1026. return;
  1027. edma_parm_or(ctlr, PARM_LINK_BCNTRLD, from, 0xffff);
  1028. }
  1029. EXPORT_SYMBOL(edma_unlink);
  1030. /*-----------------------------------------------------------------------*/
  1031. /* Parameter RAM operations (ii) -- read/write whole parameter sets */
  1032. /**
  1033. * edma_write_slot - write parameter RAM data for slot
  1034. * @slot: number of parameter RAM slot being modified
  1035. * @param: data to be written into parameter RAM slot
  1036. *
  1037. * Use this to assign all parameters of a transfer at once. This
  1038. * allows more efficient setup of transfers than issuing multiple
  1039. * calls to set up those parameters in small pieces, and provides
  1040. * complete control over all transfer options.
  1041. */
  1042. void edma_write_slot(unsigned slot, const struct edmacc_param *param)
  1043. {
  1044. unsigned ctlr;
  1045. ctlr = EDMA_CTLR(slot);
  1046. slot = EDMA_CHAN_SLOT(slot);
  1047. if (slot >= edma_cc[ctlr]->num_slots)
  1048. return;
  1049. memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(slot), param,
  1050. PARM_SIZE);
  1051. }
  1052. EXPORT_SYMBOL(edma_write_slot);
  1053. /**
  1054. * edma_read_slot - read parameter RAM data from slot
  1055. * @slot: number of parameter RAM slot being copied
  1056. * @param: where to store copy of parameter RAM data
  1057. *
  1058. * Use this to read data from a parameter RAM slot, perhaps to
  1059. * save them as a template for later reuse.
  1060. */
  1061. void edma_read_slot(unsigned slot, struct edmacc_param *param)
  1062. {
  1063. unsigned ctlr;
  1064. ctlr = EDMA_CTLR(slot);
  1065. slot = EDMA_CHAN_SLOT(slot);
  1066. if (slot >= edma_cc[ctlr]->num_slots)
  1067. return;
  1068. memcpy_fromio(param, edmacc_regs_base[ctlr] + PARM_OFFSET(slot),
  1069. PARM_SIZE);
  1070. }
  1071. EXPORT_SYMBOL(edma_read_slot);
  1072. /*-----------------------------------------------------------------------*/
  1073. /* Various EDMA channel control operations */
  1074. /**
  1075. * edma_pause - pause dma on a channel
  1076. * @channel: on which edma_start() has been called
  1077. *
  1078. * This temporarily disables EDMA hardware events on the specified channel,
  1079. * preventing them from triggering new transfers on its behalf
  1080. */
  1081. void edma_pause(unsigned channel)
  1082. {
  1083. unsigned ctlr;
  1084. ctlr = EDMA_CTLR(channel);
  1085. channel = EDMA_CHAN_SLOT(channel);
  1086. if (channel < edma_cc[ctlr]->num_channels) {
  1087. unsigned int mask = BIT(channel & 0x1f);
  1088. edma_shadow0_write_array(ctlr, SH_EECR, channel >> 5, mask);
  1089. }
  1090. }
  1091. EXPORT_SYMBOL(edma_pause);
  1092. /**
  1093. * edma_resume - resumes dma on a paused channel
  1094. * @channel: on which edma_pause() has been called
  1095. *
  1096. * This re-enables EDMA hardware events on the specified channel.
  1097. */
  1098. void edma_resume(unsigned channel)
  1099. {
  1100. unsigned ctlr;
  1101. ctlr = EDMA_CTLR(channel);
  1102. channel = EDMA_CHAN_SLOT(channel);
  1103. if (channel < edma_cc[ctlr]->num_channels) {
  1104. unsigned int mask = BIT(channel & 0x1f);
  1105. edma_shadow0_write_array(ctlr, SH_EESR, channel >> 5, mask);
  1106. }
  1107. }
  1108. EXPORT_SYMBOL(edma_resume);
  1109. int edma_trigger_channel(unsigned channel)
  1110. {
  1111. unsigned ctlr;
  1112. unsigned int mask;
  1113. ctlr = EDMA_CTLR(channel);
  1114. channel = EDMA_CHAN_SLOT(channel);
  1115. mask = BIT(channel & 0x1f);
  1116. edma_shadow0_write_array(ctlr, SH_ESR, (channel >> 5), mask);
  1117. pr_debug("EDMA: ESR%d %08x\n", (channel >> 5),
  1118. edma_shadow0_read_array(ctlr, SH_ESR, (channel >> 5)));
  1119. return 0;
  1120. }
  1121. EXPORT_SYMBOL(edma_trigger_channel);
  1122. /**
  1123. * edma_start - start dma on a channel
  1124. * @channel: channel being activated
  1125. *
  1126. * Channels with event associations will be triggered by their hardware
  1127. * events, and channels without such associations will be triggered by
  1128. * software. (At this writing there is no interface for using software
  1129. * triggers except with channels that don't support hardware triggers.)
  1130. *
  1131. * Returns zero on success, else negative errno.
  1132. */
  1133. int edma_start(unsigned channel)
  1134. {
  1135. unsigned ctlr;
  1136. ctlr = EDMA_CTLR(channel);
  1137. channel = EDMA_CHAN_SLOT(channel);
  1138. if (channel < edma_cc[ctlr]->num_channels) {
  1139. int j = channel >> 5;
  1140. unsigned int mask = BIT(channel & 0x1f);
  1141. /* EDMA channels without event association */
  1142. if (test_bit(channel, edma_cc[ctlr]->edma_unused)) {
  1143. pr_debug("EDMA: ESR%d %08x\n", j,
  1144. edma_shadow0_read_array(ctlr, SH_ESR, j));
  1145. edma_shadow0_write_array(ctlr, SH_ESR, j, mask);
  1146. return 0;
  1147. }
  1148. /* EDMA channel with event association */
  1149. pr_debug("EDMA: ER%d %08x\n", j,
  1150. edma_shadow0_read_array(ctlr, SH_ER, j));
  1151. /* Clear any pending event or error */
  1152. edma_write_array(ctlr, EDMA_ECR, j, mask);
  1153. edma_write_array(ctlr, EDMA_EMCR, j, mask);
  1154. /* Clear any SER */
  1155. edma_shadow0_write_array(ctlr, SH_SECR, j, mask);
  1156. edma_shadow0_write_array(ctlr, SH_EESR, j, mask);
  1157. pr_debug("EDMA: EER%d %08x\n", j,
  1158. edma_shadow0_read_array(ctlr, SH_EER, j));
  1159. return 0;
  1160. }
  1161. return -EINVAL;
  1162. }
  1163. EXPORT_SYMBOL(edma_start);
  1164. /**
  1165. * edma_stop - stops dma on the channel passed
  1166. * @channel: channel being deactivated
  1167. *
  1168. * When @lch is a channel, any active transfer is paused and
  1169. * all pending hardware events are cleared. The current transfer
  1170. * may not be resumed, and the channel's Parameter RAM should be
  1171. * reinitialized before being reused.
  1172. */
  1173. void edma_stop(unsigned channel)
  1174. {
  1175. unsigned ctlr;
  1176. ctlr = EDMA_CTLR(channel);
  1177. channel = EDMA_CHAN_SLOT(channel);
  1178. if (channel < edma_cc[ctlr]->num_channels) {
  1179. int j = channel >> 5;
  1180. unsigned int mask = BIT(channel & 0x1f);
  1181. edma_shadow0_write_array(ctlr, SH_EECR, j, mask);
  1182. edma_shadow0_write_array(ctlr, SH_ECR, j, mask);
  1183. edma_shadow0_write_array(ctlr, SH_SECR, j, mask);
  1184. edma_write_array(ctlr, EDMA_EMCR, j, mask);
  1185. pr_debug("EDMA: EER%d %08x\n", j,
  1186. edma_shadow0_read_array(ctlr, SH_EER, j));
  1187. /* REVISIT: consider guarding against inappropriate event
  1188. * chaining by overwriting with dummy_paramset.
  1189. */
  1190. }
  1191. }
  1192. EXPORT_SYMBOL(edma_stop);
  1193. /******************************************************************************
  1194. *
  1195. * It cleans ParamEntry qand bring back EDMA to initial state if media has
  1196. * been removed before EDMA has finished.It is usedful for removable media.
  1197. * Arguments:
  1198. * ch_no - channel no
  1199. *
  1200. * Return: zero on success, or corresponding error no on failure
  1201. *
  1202. * FIXME this should not be needed ... edma_stop() should suffice.
  1203. *
  1204. *****************************************************************************/
  1205. void edma_clean_channel(unsigned channel)
  1206. {
  1207. unsigned ctlr;
  1208. ctlr = EDMA_CTLR(channel);
  1209. channel = EDMA_CHAN_SLOT(channel);
  1210. if (channel < edma_cc[ctlr]->num_channels) {
  1211. int j = (channel >> 5);
  1212. unsigned int mask = BIT(channel & 0x1f);
  1213. pr_debug("EDMA: EMR%d %08x\n", j,
  1214. edma_read_array(ctlr, EDMA_EMR, j));
  1215. edma_shadow0_write_array(ctlr, SH_ECR, j, mask);
  1216. /* Clear the corresponding EMR bits */
  1217. edma_write_array(ctlr, EDMA_EMCR, j, mask);
  1218. /* Clear any SER */
  1219. edma_shadow0_write_array(ctlr, SH_SECR, j, mask);
  1220. edma_write(ctlr, EDMA_CCERRCLR, BIT(16) | BIT(1) | BIT(0));
  1221. }
  1222. }
  1223. EXPORT_SYMBOL(edma_clean_channel);
  1224. /*
  1225. * edma_clear_event - clear an outstanding event on the DMA channel
  1226. * Arguments:
  1227. * channel - channel number
  1228. */
  1229. void edma_clear_event(unsigned channel)
  1230. {
  1231. unsigned ctlr;
  1232. ctlr = EDMA_CTLR(channel);
  1233. channel = EDMA_CHAN_SLOT(channel);
  1234. if (channel >= edma_cc[ctlr]->num_channels)
  1235. return;
  1236. if (channel < 32)
  1237. edma_write(ctlr, EDMA_ECR, BIT(channel));
  1238. else
  1239. edma_write(ctlr, EDMA_ECRH, BIT(channel - 32));
  1240. }
  1241. EXPORT_SYMBOL(edma_clear_event);
  1242. #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DMADEVICES)
  1243. static int edma_of_read_u32_to_s16_array(const struct device_node *np,
  1244. const char *propname, s16 *out_values,
  1245. size_t sz)
  1246. {
  1247. int ret;
  1248. ret = of_property_read_u16_array(np, propname, out_values, sz);
  1249. if (ret)
  1250. return ret;
  1251. /* Terminate it */
  1252. *out_values++ = -1;
  1253. *out_values++ = -1;
  1254. return 0;
  1255. }
  1256. static int edma_xbar_event_map(struct device *dev,
  1257. struct device_node *node,
  1258. struct edma_soc_info *pdata, int len)
  1259. {
  1260. int ret, i;
  1261. struct resource res;
  1262. void __iomem *xbar;
  1263. const s16 (*xbar_chans)[2];
  1264. u32 shift, offset, mux;
  1265. xbar_chans = devm_kzalloc(dev,
  1266. len/sizeof(s16) + 2*sizeof(s16),
  1267. GFP_KERNEL);
  1268. if (!xbar_chans)
  1269. return -ENOMEM;
  1270. ret = of_address_to_resource(node, 1, &res);
  1271. if (ret)
  1272. return -EIO;
  1273. xbar = devm_ioremap(dev, res.start, resource_size(&res));
  1274. if (!xbar)
  1275. return -ENOMEM;
  1276. ret = edma_of_read_u32_to_s16_array(node,
  1277. "ti,edma-xbar-event-map",
  1278. (s16 *)xbar_chans,
  1279. len/sizeof(u32));
  1280. if (ret)
  1281. return -EIO;
  1282. for (i = 0; xbar_chans[i][0] != -1; i++) {
  1283. shift = (xbar_chans[i][1] & 0x03) << 3;
  1284. offset = xbar_chans[i][1] & 0xfffffffc;
  1285. mux = readl(xbar + offset);
  1286. mux &= ~(0xff << shift);
  1287. mux |= xbar_chans[i][0] << shift;
  1288. writel(mux, (xbar + offset));
  1289. }
  1290. pdata->xbar_chans = xbar_chans;
  1291. return 0;
  1292. }
  1293. static int edma_of_parse_dt(struct device *dev,
  1294. struct device_node *node,
  1295. struct edma_soc_info *pdata)
  1296. {
  1297. int ret = 0, i;
  1298. u32 value;
  1299. struct property *prop;
  1300. size_t sz;
  1301. struct edma_rsv_info *rsv_info;
  1302. s8 (*queue_tc_map)[2], (*queue_priority_map)[2];
  1303. memset(pdata, 0, sizeof(struct edma_soc_info));
  1304. ret = of_property_read_u32(node, "dma-channels", &value);
  1305. if (ret < 0)
  1306. return ret;
  1307. pdata->n_channel = value;
  1308. ret = of_property_read_u32(node, "ti,edma-regions", &value);
  1309. if (ret < 0)
  1310. return ret;
  1311. pdata->n_region = value;
  1312. ret = of_property_read_u32(node, "ti,edma-slots", &value);
  1313. if (ret < 0)
  1314. return ret;
  1315. pdata->n_slot = value;
  1316. pdata->n_cc = 1;
  1317. rsv_info = devm_kzalloc(dev, sizeof(struct edma_rsv_info), GFP_KERNEL);
  1318. if (!rsv_info)
  1319. return -ENOMEM;
  1320. pdata->rsv = rsv_info;
  1321. queue_tc_map = devm_kzalloc(dev, 8*sizeof(s8), GFP_KERNEL);
  1322. if (!queue_tc_map)
  1323. return -ENOMEM;
  1324. for (i = 0; i < 3; i++) {
  1325. queue_tc_map[i][0] = i;
  1326. queue_tc_map[i][1] = i;
  1327. }
  1328. queue_tc_map[i][0] = -1;
  1329. queue_tc_map[i][1] = -1;
  1330. pdata->queue_tc_mapping = queue_tc_map;
  1331. queue_priority_map = devm_kzalloc(dev, 8*sizeof(s8), GFP_KERNEL);
  1332. if (!queue_priority_map)
  1333. return -ENOMEM;
  1334. for (i = 0; i < 3; i++) {
  1335. queue_priority_map[i][0] = i;
  1336. queue_priority_map[i][1] = i;
  1337. }
  1338. queue_priority_map[i][0] = -1;
  1339. queue_priority_map[i][1] = -1;
  1340. pdata->queue_priority_mapping = queue_priority_map;
  1341. pdata->default_queue = 0;
  1342. prop = of_find_property(node, "ti,edma-xbar-event-map", &sz);
  1343. if (prop)
  1344. ret = edma_xbar_event_map(dev, node, pdata, sz);
  1345. return ret;
  1346. }
  1347. static struct of_dma_filter_info edma_filter_info = {
  1348. .filter_fn = edma_filter_fn,
  1349. };
  1350. static struct edma_soc_info *edma_setup_info_from_dt(struct device *dev,
  1351. struct device_node *node)
  1352. {
  1353. struct edma_soc_info *info;
  1354. int ret;
  1355. info = devm_kzalloc(dev, sizeof(struct edma_soc_info), GFP_KERNEL);
  1356. if (!info)
  1357. return ERR_PTR(-ENOMEM);
  1358. ret = edma_of_parse_dt(dev, node, info);
  1359. if (ret)
  1360. return ERR_PTR(ret);
  1361. dma_cap_set(DMA_SLAVE, edma_filter_info.dma_cap);
  1362. of_dma_controller_register(dev->of_node, of_dma_simple_xlate,
  1363. &edma_filter_info);
  1364. return info;
  1365. }
  1366. #else
  1367. static struct edma_soc_info *edma_setup_info_from_dt(struct device *dev,
  1368. struct device_node *node)
  1369. {
  1370. return ERR_PTR(-ENOSYS);
  1371. }
  1372. #endif
  1373. static int edma_probe(struct platform_device *pdev)
  1374. {
  1375. struct edma_soc_info **info = pdev->dev.platform_data;
  1376. struct edma_soc_info *ninfo[EDMA_MAX_CC] = {NULL};
  1377. s8 (*queue_priority_mapping)[2];
  1378. s8 (*queue_tc_mapping)[2];
  1379. int i, j, off, ln, found = 0;
  1380. int status = -1;
  1381. const s16 (*rsv_chans)[2];
  1382. const s16 (*rsv_slots)[2];
  1383. const s16 (*xbar_chans)[2];
  1384. int irq[EDMA_MAX_CC] = {0, 0};
  1385. int err_irq[EDMA_MAX_CC] = {0, 0};
  1386. struct resource *r[EDMA_MAX_CC] = {NULL};
  1387. struct resource res[EDMA_MAX_CC];
  1388. char res_name[10];
  1389. char irq_name[10];
  1390. struct device_node *node = pdev->dev.of_node;
  1391. struct device *dev = &pdev->dev;
  1392. int ret;
  1393. if (node) {
  1394. /* Check if this is a second instance registered */
  1395. if (arch_num_cc) {
  1396. dev_err(dev, "only one EDMA instance is supported via DT\n");
  1397. return -ENODEV;
  1398. }
  1399. ninfo[0] = edma_setup_info_from_dt(dev, node);
  1400. if (IS_ERR(ninfo[0])) {
  1401. dev_err(dev, "failed to get DT data\n");
  1402. return PTR_ERR(ninfo[0]);
  1403. }
  1404. info = ninfo;
  1405. }
  1406. if (!info)
  1407. return -ENODEV;
  1408. pm_runtime_enable(dev);
  1409. ret = pm_runtime_get_sync(dev);
  1410. if (ret < 0) {
  1411. dev_err(dev, "pm_runtime_get_sync() failed\n");
  1412. return ret;
  1413. }
  1414. for (j = 0; j < EDMA_MAX_CC; j++) {
  1415. if (!info[j]) {
  1416. if (!found)
  1417. return -ENODEV;
  1418. break;
  1419. }
  1420. if (node) {
  1421. ret = of_address_to_resource(node, j, &res[j]);
  1422. if (!ret)
  1423. r[j] = &res[j];
  1424. } else {
  1425. sprintf(res_name, "edma_cc%d", j);
  1426. r[j] = platform_get_resource_byname(pdev,
  1427. IORESOURCE_MEM,
  1428. res_name);
  1429. }
  1430. if (!r[j]) {
  1431. if (found)
  1432. break;
  1433. else
  1434. return -ENODEV;
  1435. } else {
  1436. found = 1;
  1437. }
  1438. edmacc_regs_base[j] = devm_ioremap_resource(&pdev->dev, r[j]);
  1439. if (IS_ERR(edmacc_regs_base[j]))
  1440. return PTR_ERR(edmacc_regs_base[j]);
  1441. edma_cc[j] = devm_kzalloc(&pdev->dev, sizeof(struct edma),
  1442. GFP_KERNEL);
  1443. if (!edma_cc[j])
  1444. return -ENOMEM;
  1445. edma_cc[j]->num_channels = min_t(unsigned, info[j]->n_channel,
  1446. EDMA_MAX_DMACH);
  1447. edma_cc[j]->num_slots = min_t(unsigned, info[j]->n_slot,
  1448. EDMA_MAX_PARAMENTRY);
  1449. edma_cc[j]->num_cc = min_t(unsigned, info[j]->n_cc,
  1450. EDMA_MAX_CC);
  1451. edma_cc[j]->default_queue = info[j]->default_queue;
  1452. dev_dbg(&pdev->dev, "DMA REG BASE ADDR=%p\n",
  1453. edmacc_regs_base[j]);
  1454. for (i = 0; i < edma_cc[j]->num_slots; i++)
  1455. memcpy_toio(edmacc_regs_base[j] + PARM_OFFSET(i),
  1456. &dummy_paramset, PARM_SIZE);
  1457. /* Mark all channels as unused */
  1458. memset(edma_cc[j]->edma_unused, 0xff,
  1459. sizeof(edma_cc[j]->edma_unused));
  1460. if (info[j]->rsv) {
  1461. /* Clear the reserved channels in unused list */
  1462. rsv_chans = info[j]->rsv->rsv_chans;
  1463. if (rsv_chans) {
  1464. for (i = 0; rsv_chans[i][0] != -1; i++) {
  1465. off = rsv_chans[i][0];
  1466. ln = rsv_chans[i][1];
  1467. clear_bits(off, ln,
  1468. edma_cc[j]->edma_unused);
  1469. }
  1470. }
  1471. /* Set the reserved slots in inuse list */
  1472. rsv_slots = info[j]->rsv->rsv_slots;
  1473. if (rsv_slots) {
  1474. for (i = 0; rsv_slots[i][0] != -1; i++) {
  1475. off = rsv_slots[i][0];
  1476. ln = rsv_slots[i][1];
  1477. set_bits(off, ln,
  1478. edma_cc[j]->edma_inuse);
  1479. }
  1480. }
  1481. }
  1482. /* Clear the xbar mapped channels in unused list */
  1483. xbar_chans = info[j]->xbar_chans;
  1484. if (xbar_chans) {
  1485. for (i = 0; xbar_chans[i][1] != -1; i++) {
  1486. off = xbar_chans[i][1];
  1487. clear_bits(off, 1,
  1488. edma_cc[j]->edma_unused);
  1489. }
  1490. }
  1491. if (node) {
  1492. irq[j] = irq_of_parse_and_map(node, 0);
  1493. } else {
  1494. sprintf(irq_name, "edma%d", j);
  1495. irq[j] = platform_get_irq_byname(pdev, irq_name);
  1496. }
  1497. edma_cc[j]->irq_res_start = irq[j];
  1498. status = devm_request_irq(&pdev->dev, irq[j],
  1499. dma_irq_handler, 0, "edma",
  1500. &pdev->dev);
  1501. if (status < 0) {
  1502. dev_dbg(&pdev->dev,
  1503. "devm_request_irq %d failed --> %d\n",
  1504. irq[j], status);
  1505. return status;
  1506. }
  1507. if (node) {
  1508. err_irq[j] = irq_of_parse_and_map(node, 2);
  1509. } else {
  1510. sprintf(irq_name, "edma%d_err", j);
  1511. err_irq[j] = platform_get_irq_byname(pdev, irq_name);
  1512. }
  1513. edma_cc[j]->irq_res_end = err_irq[j];
  1514. status = devm_request_irq(&pdev->dev, err_irq[j],
  1515. dma_ccerr_handler, 0,
  1516. "edma_error", &pdev->dev);
  1517. if (status < 0) {
  1518. dev_dbg(&pdev->dev,
  1519. "devm_request_irq %d failed --> %d\n",
  1520. err_irq[j], status);
  1521. return status;
  1522. }
  1523. for (i = 0; i < edma_cc[j]->num_channels; i++)
  1524. map_dmach_queue(j, i, info[j]->default_queue);
  1525. queue_tc_mapping = info[j]->queue_tc_mapping;
  1526. queue_priority_mapping = info[j]->queue_priority_mapping;
  1527. /* Event queue to TC mapping */
  1528. for (i = 0; queue_tc_mapping[i][0] != -1; i++)
  1529. map_queue_tc(j, queue_tc_mapping[i][0],
  1530. queue_tc_mapping[i][1]);
  1531. /* Event queue priority mapping */
  1532. for (i = 0; queue_priority_mapping[i][0] != -1; i++)
  1533. assign_priority_to_queue(j,
  1534. queue_priority_mapping[i][0],
  1535. queue_priority_mapping[i][1]);
  1536. /* Map the channel to param entry if channel mapping logic
  1537. * exist
  1538. */
  1539. if (edma_read(j, EDMA_CCCFG) & CHMAP_EXIST)
  1540. map_dmach_param(j);
  1541. for (i = 0; i < info[j]->n_region; i++) {
  1542. edma_write_array2(j, EDMA_DRAE, i, 0, 0x0);
  1543. edma_write_array2(j, EDMA_DRAE, i, 1, 0x0);
  1544. edma_write_array(j, EDMA_QRAE, i, 0x0);
  1545. }
  1546. arch_num_cc++;
  1547. }
  1548. return 0;
  1549. }
  1550. static struct platform_driver edma_driver = {
  1551. .driver = {
  1552. .name = "edma",
  1553. .of_match_table = edma_of_ids,
  1554. },
  1555. .probe = edma_probe,
  1556. };
  1557. static int __init edma_init(void)
  1558. {
  1559. return platform_driver_probe(&edma_driver, edma_probe);
  1560. }
  1561. arch_initcall(edma_init);