edma.c 49 KB

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