edma.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823
  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/dma-mapping.h>
  30. #include <linux/of_address.h>
  31. #include <linux/of_device.h>
  32. #include <linux/of_dma.h>
  33. #include <linux/of_irq.h>
  34. #include <linux/pm_runtime.h>
  35. #include <linux/platform_data/edma.h>
  36. /* Offsets matching "struct edmacc_param" */
  37. #define PARM_OPT 0x00
  38. #define PARM_SRC 0x04
  39. #define PARM_A_B_CNT 0x08
  40. #define PARM_DST 0x0c
  41. #define PARM_SRC_DST_BIDX 0x10
  42. #define PARM_LINK_BCNTRLD 0x14
  43. #define PARM_SRC_DST_CIDX 0x18
  44. #define PARM_CCNT 0x1c
  45. #define PARM_SIZE 0x20
  46. /* Offsets for EDMA CC global channel registers and their shadows */
  47. #define SH_ER 0x00 /* 64 bits */
  48. #define SH_ECR 0x08 /* 64 bits */
  49. #define SH_ESR 0x10 /* 64 bits */
  50. #define SH_CER 0x18 /* 64 bits */
  51. #define SH_EER 0x20 /* 64 bits */
  52. #define SH_EECR 0x28 /* 64 bits */
  53. #define SH_EESR 0x30 /* 64 bits */
  54. #define SH_SER 0x38 /* 64 bits */
  55. #define SH_SECR 0x40 /* 64 bits */
  56. #define SH_IER 0x50 /* 64 bits */
  57. #define SH_IECR 0x58 /* 64 bits */
  58. #define SH_IESR 0x60 /* 64 bits */
  59. #define SH_IPR 0x68 /* 64 bits */
  60. #define SH_ICR 0x70 /* 64 bits */
  61. #define SH_IEVAL 0x78
  62. #define SH_QER 0x80
  63. #define SH_QEER 0x84
  64. #define SH_QEECR 0x88
  65. #define SH_QEESR 0x8c
  66. #define SH_QSER 0x90
  67. #define SH_QSECR 0x94
  68. #define SH_SIZE 0x200
  69. /* Offsets for EDMA CC global registers */
  70. #define EDMA_REV 0x0000
  71. #define EDMA_CCCFG 0x0004
  72. #define EDMA_QCHMAP 0x0200 /* 8 registers */
  73. #define EDMA_DMAQNUM 0x0240 /* 8 registers (4 on OMAP-L1xx) */
  74. #define EDMA_QDMAQNUM 0x0260
  75. #define EDMA_QUETCMAP 0x0280
  76. #define EDMA_QUEPRI 0x0284
  77. #define EDMA_EMR 0x0300 /* 64 bits */
  78. #define EDMA_EMCR 0x0308 /* 64 bits */
  79. #define EDMA_QEMR 0x0310
  80. #define EDMA_QEMCR 0x0314
  81. #define EDMA_CCERR 0x0318
  82. #define EDMA_CCERRCLR 0x031c
  83. #define EDMA_EEVAL 0x0320
  84. #define EDMA_DRAE 0x0340 /* 4 x 64 bits*/
  85. #define EDMA_QRAE 0x0380 /* 4 registers */
  86. #define EDMA_QUEEVTENTRY 0x0400 /* 2 x 16 registers */
  87. #define EDMA_QSTAT 0x0600 /* 2 registers */
  88. #define EDMA_QWMTHRA 0x0620
  89. #define EDMA_QWMTHRB 0x0624
  90. #define EDMA_CCSTAT 0x0640
  91. #define EDMA_M 0x1000 /* global channel registers */
  92. #define EDMA_ECR 0x1008
  93. #define EDMA_ECRH 0x100C
  94. #define EDMA_SHADOW0 0x2000 /* 4 regions shadowing global channels */
  95. #define EDMA_PARM 0x4000 /* 128 param entries */
  96. #define PARM_OFFSET(param_no) (EDMA_PARM + ((param_no) << 5))
  97. #define EDMA_DCHMAP 0x0100 /* 64 registers */
  98. /* CCCFG register */
  99. #define GET_NUM_DMACH(x) (x & 0x7) /* bits 0-2 */
  100. #define GET_NUM_PAENTRY(x) ((x & 0x7000) >> 12) /* bits 12-14 */
  101. #define GET_NUM_EVQUE(x) ((x & 0x70000) >> 16) /* bits 16-18 */
  102. #define GET_NUM_REGN(x) ((x & 0x300000) >> 20) /* bits 20-21 */
  103. #define CHMAP_EXIST BIT(24)
  104. #define EDMA_MAX_DMACH 64
  105. #define EDMA_MAX_PARAMENTRY 512
  106. /*****************************************************************************/
  107. static void __iomem *edmacc_regs_base[EDMA_MAX_CC];
  108. static inline unsigned int edma_read(unsigned ctlr, int offset)
  109. {
  110. return (unsigned int)__raw_readl(edmacc_regs_base[ctlr] + offset);
  111. }
  112. static inline void edma_write(unsigned ctlr, int offset, int val)
  113. {
  114. __raw_writel(val, edmacc_regs_base[ctlr] + offset);
  115. }
  116. static inline void edma_modify(unsigned ctlr, int offset, unsigned and,
  117. unsigned or)
  118. {
  119. unsigned val = edma_read(ctlr, offset);
  120. val &= and;
  121. val |= or;
  122. edma_write(ctlr, offset, val);
  123. }
  124. static inline void edma_and(unsigned ctlr, int offset, unsigned and)
  125. {
  126. unsigned val = edma_read(ctlr, offset);
  127. val &= and;
  128. edma_write(ctlr, offset, val);
  129. }
  130. static inline void edma_or(unsigned ctlr, int offset, unsigned or)
  131. {
  132. unsigned val = edma_read(ctlr, offset);
  133. val |= or;
  134. edma_write(ctlr, offset, val);
  135. }
  136. static inline unsigned int edma_read_array(unsigned ctlr, int offset, int i)
  137. {
  138. return edma_read(ctlr, offset + (i << 2));
  139. }
  140. static inline void edma_write_array(unsigned ctlr, int offset, int i,
  141. unsigned val)
  142. {
  143. edma_write(ctlr, offset + (i << 2), val);
  144. }
  145. static inline void edma_modify_array(unsigned ctlr, int offset, int i,
  146. unsigned and, unsigned or)
  147. {
  148. edma_modify(ctlr, offset + (i << 2), and, or);
  149. }
  150. static inline void edma_or_array(unsigned ctlr, int offset, int i, unsigned or)
  151. {
  152. edma_or(ctlr, offset + (i << 2), or);
  153. }
  154. static inline void edma_or_array2(unsigned ctlr, int offset, int i, int j,
  155. unsigned or)
  156. {
  157. edma_or(ctlr, offset + ((i*2 + j) << 2), or);
  158. }
  159. static inline void edma_write_array2(unsigned ctlr, int offset, int i, int j,
  160. unsigned val)
  161. {
  162. edma_write(ctlr, offset + ((i*2 + j) << 2), val);
  163. }
  164. static inline unsigned int edma_shadow0_read(unsigned ctlr, int offset)
  165. {
  166. return edma_read(ctlr, EDMA_SHADOW0 + offset);
  167. }
  168. static inline unsigned int edma_shadow0_read_array(unsigned ctlr, int offset,
  169. int i)
  170. {
  171. return edma_read(ctlr, EDMA_SHADOW0 + offset + (i << 2));
  172. }
  173. static inline void edma_shadow0_write(unsigned ctlr, int offset, unsigned val)
  174. {
  175. edma_write(ctlr, EDMA_SHADOW0 + offset, val);
  176. }
  177. static inline void edma_shadow0_write_array(unsigned ctlr, int offset, int i,
  178. unsigned val)
  179. {
  180. edma_write(ctlr, EDMA_SHADOW0 + offset + (i << 2), val);
  181. }
  182. static inline unsigned int edma_parm_read(unsigned ctlr, int offset,
  183. int param_no)
  184. {
  185. return edma_read(ctlr, EDMA_PARM + offset + (param_no << 5));
  186. }
  187. static inline void edma_parm_write(unsigned ctlr, int offset, int param_no,
  188. unsigned val)
  189. {
  190. edma_write(ctlr, EDMA_PARM + offset + (param_no << 5), val);
  191. }
  192. static inline void edma_parm_modify(unsigned ctlr, int offset, int param_no,
  193. unsigned and, unsigned or)
  194. {
  195. edma_modify(ctlr, EDMA_PARM + offset + (param_no << 5), and, or);
  196. }
  197. static inline void edma_parm_and(unsigned ctlr, int offset, int param_no,
  198. unsigned and)
  199. {
  200. edma_and(ctlr, EDMA_PARM + offset + (param_no << 5), and);
  201. }
  202. static inline void edma_parm_or(unsigned ctlr, int offset, int param_no,
  203. unsigned or)
  204. {
  205. edma_or(ctlr, EDMA_PARM + offset + (param_no << 5), or);
  206. }
  207. static inline void set_bits(int offset, int len, unsigned long *p)
  208. {
  209. for (; len > 0; len--)
  210. set_bit(offset + (len - 1), p);
  211. }
  212. static inline void clear_bits(int offset, int len, unsigned long *p)
  213. {
  214. for (; len > 0; len--)
  215. clear_bit(offset + (len - 1), p);
  216. }
  217. /*****************************************************************************/
  218. /* actual number of DMA channels and slots on this silicon */
  219. struct edma {
  220. /* how many dma resources of each type */
  221. unsigned num_channels;
  222. unsigned num_region;
  223. unsigned num_slots;
  224. unsigned num_tc;
  225. enum dma_event_q default_queue;
  226. /* list of channels with no even trigger; terminated by "-1" */
  227. const s8 *noevent;
  228. /* The edma_inuse bit for each PaRAM slot is clear unless the
  229. * channel is in use ... by ARM or DSP, for QDMA, or whatever.
  230. */
  231. DECLARE_BITMAP(edma_inuse, EDMA_MAX_PARAMENTRY);
  232. /* The edma_unused bit for each channel is clear unless
  233. * it is not being used on this platform. It uses a bit
  234. * of SOC-specific initialization code.
  235. */
  236. DECLARE_BITMAP(edma_unused, EDMA_MAX_DMACH);
  237. unsigned irq_res_start;
  238. unsigned irq_res_end;
  239. struct dma_interrupt_data {
  240. void (*callback)(unsigned channel, unsigned short ch_status,
  241. void *data);
  242. void *data;
  243. } intr_data[EDMA_MAX_DMACH];
  244. };
  245. static struct edma *edma_cc[EDMA_MAX_CC];
  246. static int arch_num_cc;
  247. /* dummy param set used to (re)initialize parameter RAM slots */
  248. static const struct edmacc_param dummy_paramset = {
  249. .link_bcntrld = 0xffff,
  250. .ccnt = 1,
  251. };
  252. static const struct of_device_id edma_of_ids[] = {
  253. { .compatible = "ti,edma3", },
  254. {}
  255. };
  256. /*****************************************************************************/
  257. static void map_dmach_queue(unsigned ctlr, unsigned ch_no,
  258. enum dma_event_q queue_no)
  259. {
  260. int bit = (ch_no & 0x7) * 4;
  261. /* default to low priority queue */
  262. if (queue_no == EVENTQ_DEFAULT)
  263. queue_no = edma_cc[ctlr]->default_queue;
  264. queue_no &= 7;
  265. edma_modify_array(ctlr, EDMA_DMAQNUM, (ch_no >> 3),
  266. ~(0x7 << bit), queue_no << 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, EDMA_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. EDMA_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 point
  876. * @slot: parameter RAM slot being examined
  877. * @dst: true selects the dest position, false the source
  878. *
  879. * Returns the position of the current active slot
  880. */
  881. dma_addr_t edma_get_position(unsigned slot, bool dst)
  882. {
  883. u32 offs, ctlr = EDMA_CTLR(slot);
  884. slot = EDMA_CHAN_SLOT(slot);
  885. offs = PARM_OFFSET(slot);
  886. offs += dst ? PARM_DST : PARM_SRC;
  887. return edma_read(ctlr, offs);
  888. }
  889. /**
  890. * edma_set_src_index - configure DMA source address indexing
  891. * @slot: parameter RAM slot being configured
  892. * @src_bidx: byte offset between source arrays in a frame
  893. * @src_cidx: byte offset between source frames in a block
  894. *
  895. * Offsets are specified to support either contiguous or discontiguous
  896. * memory transfers, or repeated access to a hardware register, as needed.
  897. * When accessing hardware registers, both offsets are normally zero.
  898. */
  899. void edma_set_src_index(unsigned slot, s16 src_bidx, s16 src_cidx)
  900. {
  901. unsigned ctlr;
  902. ctlr = EDMA_CTLR(slot);
  903. slot = EDMA_CHAN_SLOT(slot);
  904. if (slot < edma_cc[ctlr]->num_slots) {
  905. edma_parm_modify(ctlr, PARM_SRC_DST_BIDX, slot,
  906. 0xffff0000, src_bidx);
  907. edma_parm_modify(ctlr, PARM_SRC_DST_CIDX, slot,
  908. 0xffff0000, src_cidx);
  909. }
  910. }
  911. EXPORT_SYMBOL(edma_set_src_index);
  912. /**
  913. * edma_set_dest_index - configure DMA destination address indexing
  914. * @slot: parameter RAM slot being configured
  915. * @dest_bidx: byte offset between destination arrays in a frame
  916. * @dest_cidx: byte offset between destination frames in a block
  917. *
  918. * Offsets are specified to support either contiguous or discontiguous
  919. * memory transfers, or repeated access to a hardware register, as needed.
  920. * When accessing hardware registers, both offsets are normally zero.
  921. */
  922. void edma_set_dest_index(unsigned slot, s16 dest_bidx, s16 dest_cidx)
  923. {
  924. unsigned ctlr;
  925. ctlr = EDMA_CTLR(slot);
  926. slot = EDMA_CHAN_SLOT(slot);
  927. if (slot < edma_cc[ctlr]->num_slots) {
  928. edma_parm_modify(ctlr, PARM_SRC_DST_BIDX, slot,
  929. 0x0000ffff, dest_bidx << 16);
  930. edma_parm_modify(ctlr, PARM_SRC_DST_CIDX, slot,
  931. 0x0000ffff, dest_cidx << 16);
  932. }
  933. }
  934. EXPORT_SYMBOL(edma_set_dest_index);
  935. /**
  936. * edma_set_transfer_params - configure DMA transfer parameters
  937. * @slot: parameter RAM slot being configured
  938. * @acnt: how many bytes per array (at least one)
  939. * @bcnt: how many arrays per frame (at least one)
  940. * @ccnt: how many frames per block (at least one)
  941. * @bcnt_rld: used only for A-Synchronized transfers; this specifies
  942. * the value to reload into bcnt when it decrements to zero
  943. * @sync_mode: ASYNC or ABSYNC
  944. *
  945. * See the EDMA3 documentation to understand how to configure and link
  946. * transfers using the fields in PaRAM slots. If you are not doing it
  947. * all at once with edma_write_slot(), you will use this routine
  948. * plus two calls each for source and destination, setting the initial
  949. * address and saying how to index that address.
  950. *
  951. * An example of an A-Synchronized transfer is a serial link using a
  952. * single word shift register. In that case, @acnt would be equal to
  953. * that word size; the serial controller issues a DMA synchronization
  954. * event to transfer each word, and memory access by the DMA transfer
  955. * controller will be word-at-a-time.
  956. *
  957. * An example of an AB-Synchronized transfer is a device using a FIFO.
  958. * In that case, @acnt equals the FIFO width and @bcnt equals its depth.
  959. * The controller with the FIFO issues DMA synchronization events when
  960. * the FIFO threshold is reached, and the DMA transfer controller will
  961. * transfer one frame to (or from) the FIFO. It will probably use
  962. * efficient burst modes to access memory.
  963. */
  964. void edma_set_transfer_params(unsigned slot,
  965. u16 acnt, u16 bcnt, u16 ccnt,
  966. u16 bcnt_rld, enum sync_dimension sync_mode)
  967. {
  968. unsigned ctlr;
  969. ctlr = EDMA_CTLR(slot);
  970. slot = EDMA_CHAN_SLOT(slot);
  971. if (slot < edma_cc[ctlr]->num_slots) {
  972. edma_parm_modify(ctlr, PARM_LINK_BCNTRLD, slot,
  973. 0x0000ffff, bcnt_rld << 16);
  974. if (sync_mode == ASYNC)
  975. edma_parm_and(ctlr, PARM_OPT, slot, ~SYNCDIM);
  976. else
  977. edma_parm_or(ctlr, PARM_OPT, slot, SYNCDIM);
  978. /* Set the acount, bcount, ccount registers */
  979. edma_parm_write(ctlr, PARM_A_B_CNT, slot, (bcnt << 16) | acnt);
  980. edma_parm_write(ctlr, PARM_CCNT, slot, ccnt);
  981. }
  982. }
  983. EXPORT_SYMBOL(edma_set_transfer_params);
  984. /**
  985. * edma_link - link one parameter RAM slot to another
  986. * @from: parameter RAM slot originating the link
  987. * @to: parameter RAM slot which is the link target
  988. *
  989. * The originating slot should not be part of any active DMA transfer.
  990. */
  991. void edma_link(unsigned from, unsigned to)
  992. {
  993. unsigned ctlr_from, ctlr_to;
  994. ctlr_from = EDMA_CTLR(from);
  995. from = EDMA_CHAN_SLOT(from);
  996. ctlr_to = EDMA_CTLR(to);
  997. to = EDMA_CHAN_SLOT(to);
  998. if (from >= edma_cc[ctlr_from]->num_slots)
  999. return;
  1000. if (to >= edma_cc[ctlr_to]->num_slots)
  1001. return;
  1002. edma_parm_modify(ctlr_from, PARM_LINK_BCNTRLD, from, 0xffff0000,
  1003. PARM_OFFSET(to));
  1004. }
  1005. EXPORT_SYMBOL(edma_link);
  1006. /**
  1007. * edma_unlink - cut link from one parameter RAM slot
  1008. * @from: parameter RAM slot originating the link
  1009. *
  1010. * The originating slot should not be part of any active DMA transfer.
  1011. * Its link is set to 0xffff.
  1012. */
  1013. void edma_unlink(unsigned from)
  1014. {
  1015. unsigned ctlr;
  1016. ctlr = EDMA_CTLR(from);
  1017. from = EDMA_CHAN_SLOT(from);
  1018. if (from >= edma_cc[ctlr]->num_slots)
  1019. return;
  1020. edma_parm_or(ctlr, PARM_LINK_BCNTRLD, from, 0xffff);
  1021. }
  1022. EXPORT_SYMBOL(edma_unlink);
  1023. /*-----------------------------------------------------------------------*/
  1024. /* Parameter RAM operations (ii) -- read/write whole parameter sets */
  1025. /**
  1026. * edma_write_slot - write parameter RAM data for slot
  1027. * @slot: number of parameter RAM slot being modified
  1028. * @param: data to be written into parameter RAM slot
  1029. *
  1030. * Use this to assign all parameters of a transfer at once. This
  1031. * allows more efficient setup of transfers than issuing multiple
  1032. * calls to set up those parameters in small pieces, and provides
  1033. * complete control over all transfer options.
  1034. */
  1035. void edma_write_slot(unsigned slot, const struct edmacc_param *param)
  1036. {
  1037. unsigned ctlr;
  1038. ctlr = EDMA_CTLR(slot);
  1039. slot = EDMA_CHAN_SLOT(slot);
  1040. if (slot >= edma_cc[ctlr]->num_slots)
  1041. return;
  1042. memcpy_toio(edmacc_regs_base[ctlr] + PARM_OFFSET(slot), param,
  1043. PARM_SIZE);
  1044. }
  1045. EXPORT_SYMBOL(edma_write_slot);
  1046. /**
  1047. * edma_read_slot - read parameter RAM data from slot
  1048. * @slot: number of parameter RAM slot being copied
  1049. * @param: where to store copy of parameter RAM data
  1050. *
  1051. * Use this to read data from a parameter RAM slot, perhaps to
  1052. * save them as a template for later reuse.
  1053. */
  1054. void edma_read_slot(unsigned slot, struct edmacc_param *param)
  1055. {
  1056. unsigned ctlr;
  1057. ctlr = EDMA_CTLR(slot);
  1058. slot = EDMA_CHAN_SLOT(slot);
  1059. if (slot >= edma_cc[ctlr]->num_slots)
  1060. return;
  1061. memcpy_fromio(param, edmacc_regs_base[ctlr] + PARM_OFFSET(slot),
  1062. PARM_SIZE);
  1063. }
  1064. EXPORT_SYMBOL(edma_read_slot);
  1065. /*-----------------------------------------------------------------------*/
  1066. /* Various EDMA channel control operations */
  1067. /**
  1068. * edma_pause - pause dma on a channel
  1069. * @channel: on which edma_start() has been called
  1070. *
  1071. * This temporarily disables EDMA hardware events on the specified channel,
  1072. * preventing them from triggering new transfers on its behalf
  1073. */
  1074. void edma_pause(unsigned channel)
  1075. {
  1076. unsigned ctlr;
  1077. ctlr = EDMA_CTLR(channel);
  1078. channel = EDMA_CHAN_SLOT(channel);
  1079. if (channel < edma_cc[ctlr]->num_channels) {
  1080. unsigned int mask = BIT(channel & 0x1f);
  1081. edma_shadow0_write_array(ctlr, SH_EECR, channel >> 5, mask);
  1082. }
  1083. }
  1084. EXPORT_SYMBOL(edma_pause);
  1085. /**
  1086. * edma_resume - resumes dma on a paused channel
  1087. * @channel: on which edma_pause() has been called
  1088. *
  1089. * This re-enables EDMA hardware events on the specified channel.
  1090. */
  1091. void edma_resume(unsigned channel)
  1092. {
  1093. unsigned ctlr;
  1094. ctlr = EDMA_CTLR(channel);
  1095. channel = EDMA_CHAN_SLOT(channel);
  1096. if (channel < edma_cc[ctlr]->num_channels) {
  1097. unsigned int mask = BIT(channel & 0x1f);
  1098. edma_shadow0_write_array(ctlr, SH_EESR, channel >> 5, mask);
  1099. }
  1100. }
  1101. EXPORT_SYMBOL(edma_resume);
  1102. int edma_trigger_channel(unsigned channel)
  1103. {
  1104. unsigned ctlr;
  1105. unsigned int mask;
  1106. ctlr = EDMA_CTLR(channel);
  1107. channel = EDMA_CHAN_SLOT(channel);
  1108. mask = BIT(channel & 0x1f);
  1109. edma_shadow0_write_array(ctlr, SH_ESR, (channel >> 5), mask);
  1110. pr_debug("EDMA: ESR%d %08x\n", (channel >> 5),
  1111. edma_shadow0_read_array(ctlr, SH_ESR, (channel >> 5)));
  1112. return 0;
  1113. }
  1114. EXPORT_SYMBOL(edma_trigger_channel);
  1115. /**
  1116. * edma_start - start dma on a channel
  1117. * @channel: channel being activated
  1118. *
  1119. * Channels with event associations will be triggered by their hardware
  1120. * events, and channels without such associations will be triggered by
  1121. * software. (At this writing there is no interface for using software
  1122. * triggers except with channels that don't support hardware triggers.)
  1123. *
  1124. * Returns zero on success, else negative errno.
  1125. */
  1126. int edma_start(unsigned channel)
  1127. {
  1128. unsigned ctlr;
  1129. ctlr = EDMA_CTLR(channel);
  1130. channel = EDMA_CHAN_SLOT(channel);
  1131. if (channel < edma_cc[ctlr]->num_channels) {
  1132. int j = channel >> 5;
  1133. unsigned int mask = BIT(channel & 0x1f);
  1134. /* EDMA channels without event association */
  1135. if (test_bit(channel, edma_cc[ctlr]->edma_unused)) {
  1136. pr_debug("EDMA: ESR%d %08x\n", j,
  1137. edma_shadow0_read_array(ctlr, SH_ESR, j));
  1138. edma_shadow0_write_array(ctlr, SH_ESR, j, mask);
  1139. return 0;
  1140. }
  1141. /* EDMA channel with event association */
  1142. pr_debug("EDMA: ER%d %08x\n", j,
  1143. edma_shadow0_read_array(ctlr, SH_ER, j));
  1144. /* Clear any pending event or error */
  1145. edma_write_array(ctlr, EDMA_ECR, j, mask);
  1146. edma_write_array(ctlr, EDMA_EMCR, j, mask);
  1147. /* Clear any SER */
  1148. edma_shadow0_write_array(ctlr, SH_SECR, j, mask);
  1149. edma_shadow0_write_array(ctlr, SH_EESR, j, mask);
  1150. pr_debug("EDMA: EER%d %08x\n", j,
  1151. edma_shadow0_read_array(ctlr, SH_EER, j));
  1152. return 0;
  1153. }
  1154. return -EINVAL;
  1155. }
  1156. EXPORT_SYMBOL(edma_start);
  1157. /**
  1158. * edma_stop - stops dma on the channel passed
  1159. * @channel: channel being deactivated
  1160. *
  1161. * When @lch is a channel, any active transfer is paused and
  1162. * all pending hardware events are cleared. The current transfer
  1163. * may not be resumed, and the channel's Parameter RAM should be
  1164. * reinitialized before being reused.
  1165. */
  1166. void edma_stop(unsigned channel)
  1167. {
  1168. unsigned ctlr;
  1169. ctlr = EDMA_CTLR(channel);
  1170. channel = EDMA_CHAN_SLOT(channel);
  1171. if (channel < edma_cc[ctlr]->num_channels) {
  1172. int j = channel >> 5;
  1173. unsigned int mask = BIT(channel & 0x1f);
  1174. edma_shadow0_write_array(ctlr, SH_EECR, j, mask);
  1175. edma_shadow0_write_array(ctlr, SH_ECR, j, mask);
  1176. edma_shadow0_write_array(ctlr, SH_SECR, j, mask);
  1177. edma_write_array(ctlr, EDMA_EMCR, j, mask);
  1178. pr_debug("EDMA: EER%d %08x\n", j,
  1179. edma_shadow0_read_array(ctlr, SH_EER, j));
  1180. /* REVISIT: consider guarding against inappropriate event
  1181. * chaining by overwriting with dummy_paramset.
  1182. */
  1183. }
  1184. }
  1185. EXPORT_SYMBOL(edma_stop);
  1186. /******************************************************************************
  1187. *
  1188. * It cleans ParamEntry qand bring back EDMA to initial state if media has
  1189. * been removed before EDMA has finished.It is usedful for removable media.
  1190. * Arguments:
  1191. * ch_no - channel no
  1192. *
  1193. * Return: zero on success, or corresponding error no on failure
  1194. *
  1195. * FIXME this should not be needed ... edma_stop() should suffice.
  1196. *
  1197. *****************************************************************************/
  1198. void edma_clean_channel(unsigned channel)
  1199. {
  1200. unsigned ctlr;
  1201. ctlr = EDMA_CTLR(channel);
  1202. channel = EDMA_CHAN_SLOT(channel);
  1203. if (channel < edma_cc[ctlr]->num_channels) {
  1204. int j = (channel >> 5);
  1205. unsigned int mask = BIT(channel & 0x1f);
  1206. pr_debug("EDMA: EMR%d %08x\n", j,
  1207. edma_read_array(ctlr, EDMA_EMR, j));
  1208. edma_shadow0_write_array(ctlr, SH_ECR, j, mask);
  1209. /* Clear the corresponding EMR bits */
  1210. edma_write_array(ctlr, EDMA_EMCR, j, mask);
  1211. /* Clear any SER */
  1212. edma_shadow0_write_array(ctlr, SH_SECR, j, mask);
  1213. edma_write(ctlr, EDMA_CCERRCLR, BIT(16) | BIT(1) | BIT(0));
  1214. }
  1215. }
  1216. EXPORT_SYMBOL(edma_clean_channel);
  1217. /*
  1218. * edma_clear_event - clear an outstanding event on the DMA channel
  1219. * Arguments:
  1220. * channel - channel number
  1221. */
  1222. void edma_clear_event(unsigned channel)
  1223. {
  1224. unsigned ctlr;
  1225. ctlr = EDMA_CTLR(channel);
  1226. channel = EDMA_CHAN_SLOT(channel);
  1227. if (channel >= edma_cc[ctlr]->num_channels)
  1228. return;
  1229. if (channel < 32)
  1230. edma_write(ctlr, EDMA_ECR, BIT(channel));
  1231. else
  1232. edma_write(ctlr, EDMA_ECRH, BIT(channel - 32));
  1233. }
  1234. EXPORT_SYMBOL(edma_clear_event);
  1235. /*
  1236. * edma_assign_channel_eventq - move given channel to desired eventq
  1237. * Arguments:
  1238. * channel - channel number
  1239. * eventq_no - queue to move the channel
  1240. *
  1241. * Can be used to move a channel to a selected event queue.
  1242. */
  1243. void edma_assign_channel_eventq(unsigned channel, enum dma_event_q eventq_no)
  1244. {
  1245. unsigned ctlr;
  1246. ctlr = EDMA_CTLR(channel);
  1247. channel = EDMA_CHAN_SLOT(channel);
  1248. if (channel >= edma_cc[ctlr]->num_channels)
  1249. return;
  1250. /* default to low priority queue */
  1251. if (eventq_no == EVENTQ_DEFAULT)
  1252. eventq_no = edma_cc[ctlr]->default_queue;
  1253. if (eventq_no >= edma_cc[ctlr]->num_tc)
  1254. return;
  1255. map_dmach_queue(ctlr, channel, eventq_no);
  1256. }
  1257. EXPORT_SYMBOL(edma_assign_channel_eventq);
  1258. static int edma_setup_from_hw(struct device *dev, struct edma_soc_info *pdata,
  1259. struct edma *edma_cc, int cc_id)
  1260. {
  1261. int i;
  1262. u32 value, cccfg;
  1263. s8 (*queue_priority_map)[2];
  1264. /* Decode the eDMA3 configuration from CCCFG register */
  1265. cccfg = edma_read(cc_id, EDMA_CCCFG);
  1266. value = GET_NUM_REGN(cccfg);
  1267. edma_cc->num_region = BIT(value);
  1268. value = GET_NUM_DMACH(cccfg);
  1269. edma_cc->num_channels = BIT(value + 1);
  1270. value = GET_NUM_PAENTRY(cccfg);
  1271. edma_cc->num_slots = BIT(value + 4);
  1272. value = GET_NUM_EVQUE(cccfg);
  1273. edma_cc->num_tc = value + 1;
  1274. dev_dbg(dev, "eDMA3 CC%d HW configuration (cccfg: 0x%08x):\n", cc_id,
  1275. cccfg);
  1276. dev_dbg(dev, "num_region: %u\n", edma_cc->num_region);
  1277. dev_dbg(dev, "num_channel: %u\n", edma_cc->num_channels);
  1278. dev_dbg(dev, "num_slot: %u\n", edma_cc->num_slots);
  1279. dev_dbg(dev, "num_tc: %u\n", edma_cc->num_tc);
  1280. /* Nothing need to be done if queue priority is provided */
  1281. if (pdata->queue_priority_mapping)
  1282. return 0;
  1283. /*
  1284. * Configure TC/queue priority as follows:
  1285. * Q0 - priority 0
  1286. * Q1 - priority 1
  1287. * Q2 - priority 2
  1288. * ...
  1289. * The meaning of priority numbers: 0 highest priority, 7 lowest
  1290. * priority. So Q0 is the highest priority queue and the last queue has
  1291. * the lowest priority.
  1292. */
  1293. queue_priority_map = devm_kzalloc(dev,
  1294. (edma_cc->num_tc + 1) * sizeof(s8),
  1295. GFP_KERNEL);
  1296. if (!queue_priority_map)
  1297. return -ENOMEM;
  1298. for (i = 0; i < edma_cc->num_tc; i++) {
  1299. queue_priority_map[i][0] = i;
  1300. queue_priority_map[i][1] = i;
  1301. }
  1302. queue_priority_map[i][0] = -1;
  1303. queue_priority_map[i][1] = -1;
  1304. pdata->queue_priority_mapping = queue_priority_map;
  1305. /* Default queue has the lowest priority */
  1306. pdata->default_queue = i - 1;
  1307. return 0;
  1308. }
  1309. #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DMADEVICES)
  1310. static int edma_xbar_event_map(struct device *dev, struct device_node *node,
  1311. struct edma_soc_info *pdata, size_t sz)
  1312. {
  1313. const char pname[] = "ti,edma-xbar-event-map";
  1314. struct resource res;
  1315. void __iomem *xbar;
  1316. s16 (*xbar_chans)[2];
  1317. size_t nelm = sz / sizeof(s16);
  1318. u32 shift, offset, mux;
  1319. int ret, i;
  1320. xbar_chans = devm_kzalloc(dev, (nelm + 2) * sizeof(s16), GFP_KERNEL);
  1321. if (!xbar_chans)
  1322. return -ENOMEM;
  1323. ret = of_address_to_resource(node, 1, &res);
  1324. if (ret)
  1325. return -ENOMEM;
  1326. xbar = devm_ioremap(dev, res.start, resource_size(&res));
  1327. if (!xbar)
  1328. return -ENOMEM;
  1329. ret = of_property_read_u16_array(node, pname, (u16 *)xbar_chans, nelm);
  1330. if (ret)
  1331. return -EIO;
  1332. /* Invalidate last entry for the other user of this mess */
  1333. nelm >>= 1;
  1334. xbar_chans[nelm][0] = xbar_chans[nelm][1] = -1;
  1335. for (i = 0; i < nelm; i++) {
  1336. shift = (xbar_chans[i][1] & 0x03) << 3;
  1337. offset = xbar_chans[i][1] & 0xfffffffc;
  1338. mux = readl(xbar + offset);
  1339. mux &= ~(0xff << shift);
  1340. mux |= xbar_chans[i][0] << shift;
  1341. writel(mux, (xbar + offset));
  1342. }
  1343. pdata->xbar_chans = (const s16 (*)[2]) xbar_chans;
  1344. return 0;
  1345. }
  1346. static int edma_of_parse_dt(struct device *dev,
  1347. struct device_node *node,
  1348. struct edma_soc_info *pdata)
  1349. {
  1350. int ret = 0;
  1351. struct property *prop;
  1352. size_t sz;
  1353. struct edma_rsv_info *rsv_info;
  1354. rsv_info = devm_kzalloc(dev, sizeof(struct edma_rsv_info), GFP_KERNEL);
  1355. if (!rsv_info)
  1356. return -ENOMEM;
  1357. pdata->rsv = rsv_info;
  1358. prop = of_find_property(node, "ti,edma-xbar-event-map", &sz);
  1359. if (prop)
  1360. ret = edma_xbar_event_map(dev, node, pdata, sz);
  1361. return ret;
  1362. }
  1363. static struct of_dma_filter_info edma_filter_info = {
  1364. .filter_fn = edma_filter_fn,
  1365. };
  1366. static struct edma_soc_info *edma_setup_info_from_dt(struct device *dev,
  1367. struct device_node *node)
  1368. {
  1369. struct edma_soc_info *info;
  1370. int ret;
  1371. info = devm_kzalloc(dev, sizeof(struct edma_soc_info), GFP_KERNEL);
  1372. if (!info)
  1373. return ERR_PTR(-ENOMEM);
  1374. ret = edma_of_parse_dt(dev, node, info);
  1375. if (ret)
  1376. return ERR_PTR(ret);
  1377. dma_cap_set(DMA_SLAVE, edma_filter_info.dma_cap);
  1378. dma_cap_set(DMA_CYCLIC, edma_filter_info.dma_cap);
  1379. of_dma_controller_register(dev->of_node, of_dma_simple_xlate,
  1380. &edma_filter_info);
  1381. return info;
  1382. }
  1383. #else
  1384. static struct edma_soc_info *edma_setup_info_from_dt(struct device *dev,
  1385. struct device_node *node)
  1386. {
  1387. return ERR_PTR(-ENOSYS);
  1388. }
  1389. #endif
  1390. static int edma_probe(struct platform_device *pdev)
  1391. {
  1392. struct edma_soc_info **info = pdev->dev.platform_data;
  1393. struct edma_soc_info *ninfo[EDMA_MAX_CC] = {NULL};
  1394. s8 (*queue_priority_mapping)[2];
  1395. int i, j, off, ln, found = 0;
  1396. int status = -1;
  1397. const s16 (*rsv_chans)[2];
  1398. const s16 (*rsv_slots)[2];
  1399. const s16 (*xbar_chans)[2];
  1400. int irq[EDMA_MAX_CC] = {0, 0};
  1401. int err_irq[EDMA_MAX_CC] = {0, 0};
  1402. struct resource *r[EDMA_MAX_CC] = {NULL};
  1403. struct resource res[EDMA_MAX_CC];
  1404. char res_name[10];
  1405. struct device_node *node = pdev->dev.of_node;
  1406. struct device *dev = &pdev->dev;
  1407. int ret;
  1408. struct platform_device_info edma_dev_info = {
  1409. .name = "edma-dma-engine",
  1410. .dma_mask = DMA_BIT_MASK(32),
  1411. .parent = &pdev->dev,
  1412. };
  1413. if (node) {
  1414. /* Check if this is a second instance registered */
  1415. if (arch_num_cc) {
  1416. dev_err(dev, "only one EDMA instance is supported via DT\n");
  1417. return -ENODEV;
  1418. }
  1419. ninfo[0] = edma_setup_info_from_dt(dev, node);
  1420. if (IS_ERR(ninfo[0])) {
  1421. dev_err(dev, "failed to get DT data\n");
  1422. return PTR_ERR(ninfo[0]);
  1423. }
  1424. info = ninfo;
  1425. }
  1426. if (!info)
  1427. return -ENODEV;
  1428. pm_runtime_enable(dev);
  1429. ret = pm_runtime_get_sync(dev);
  1430. if (ret < 0) {
  1431. dev_err(dev, "pm_runtime_get_sync() failed\n");
  1432. return ret;
  1433. }
  1434. for (j = 0; j < EDMA_MAX_CC; j++) {
  1435. if (!info[j]) {
  1436. if (!found)
  1437. return -ENODEV;
  1438. break;
  1439. }
  1440. if (node) {
  1441. ret = of_address_to_resource(node, j, &res[j]);
  1442. if (!ret)
  1443. r[j] = &res[j];
  1444. } else {
  1445. sprintf(res_name, "edma_cc%d", j);
  1446. r[j] = platform_get_resource_byname(pdev,
  1447. IORESOURCE_MEM,
  1448. res_name);
  1449. }
  1450. if (!r[j]) {
  1451. if (found)
  1452. break;
  1453. else
  1454. return -ENODEV;
  1455. } else {
  1456. found = 1;
  1457. }
  1458. edmacc_regs_base[j] = devm_ioremap_resource(&pdev->dev, r[j]);
  1459. if (IS_ERR(edmacc_regs_base[j]))
  1460. return PTR_ERR(edmacc_regs_base[j]);
  1461. edma_cc[j] = devm_kzalloc(&pdev->dev, sizeof(struct edma),
  1462. GFP_KERNEL);
  1463. if (!edma_cc[j])
  1464. return -ENOMEM;
  1465. /* Get eDMA3 configuration from IP */
  1466. ret = edma_setup_from_hw(dev, info[j], edma_cc[j], j);
  1467. if (ret)
  1468. return ret;
  1469. edma_cc[j]->default_queue = info[j]->default_queue;
  1470. dev_dbg(&pdev->dev, "DMA REG BASE ADDR=%p\n",
  1471. edmacc_regs_base[j]);
  1472. for (i = 0; i < edma_cc[j]->num_slots; i++)
  1473. memcpy_toio(edmacc_regs_base[j] + PARM_OFFSET(i),
  1474. &dummy_paramset, PARM_SIZE);
  1475. /* Mark all channels as unused */
  1476. memset(edma_cc[j]->edma_unused, 0xff,
  1477. sizeof(edma_cc[j]->edma_unused));
  1478. if (info[j]->rsv) {
  1479. /* Clear the reserved channels in unused list */
  1480. rsv_chans = info[j]->rsv->rsv_chans;
  1481. if (rsv_chans) {
  1482. for (i = 0; rsv_chans[i][0] != -1; i++) {
  1483. off = rsv_chans[i][0];
  1484. ln = rsv_chans[i][1];
  1485. clear_bits(off, ln,
  1486. edma_cc[j]->edma_unused);
  1487. }
  1488. }
  1489. /* Set the reserved slots in inuse list */
  1490. rsv_slots = info[j]->rsv->rsv_slots;
  1491. if (rsv_slots) {
  1492. for (i = 0; rsv_slots[i][0] != -1; i++) {
  1493. off = rsv_slots[i][0];
  1494. ln = rsv_slots[i][1];
  1495. set_bits(off, ln,
  1496. edma_cc[j]->edma_inuse);
  1497. }
  1498. }
  1499. }
  1500. /* Clear the xbar mapped channels in unused list */
  1501. xbar_chans = info[j]->xbar_chans;
  1502. if (xbar_chans) {
  1503. for (i = 0; xbar_chans[i][1] != -1; i++) {
  1504. off = xbar_chans[i][1];
  1505. clear_bits(off, 1,
  1506. edma_cc[j]->edma_unused);
  1507. }
  1508. }
  1509. if (node) {
  1510. irq[j] = irq_of_parse_and_map(node, 0);
  1511. err_irq[j] = irq_of_parse_and_map(node, 2);
  1512. } else {
  1513. char irq_name[10];
  1514. sprintf(irq_name, "edma%d", j);
  1515. irq[j] = platform_get_irq_byname(pdev, irq_name);
  1516. sprintf(irq_name, "edma%d_err", j);
  1517. err_irq[j] = platform_get_irq_byname(pdev, irq_name);
  1518. }
  1519. edma_cc[j]->irq_res_start = irq[j];
  1520. edma_cc[j]->irq_res_end = err_irq[j];
  1521. status = devm_request_irq(dev, irq[j], dma_irq_handler, 0,
  1522. "edma", dev);
  1523. if (status < 0) {
  1524. dev_dbg(&pdev->dev,
  1525. "devm_request_irq %d failed --> %d\n",
  1526. irq[j], status);
  1527. return status;
  1528. }
  1529. status = devm_request_irq(dev, err_irq[j], dma_ccerr_handler, 0,
  1530. "edma_error", dev);
  1531. if (status < 0) {
  1532. dev_dbg(&pdev->dev,
  1533. "devm_request_irq %d failed --> %d\n",
  1534. err_irq[j], status);
  1535. return status;
  1536. }
  1537. for (i = 0; i < edma_cc[j]->num_channels; i++)
  1538. map_dmach_queue(j, i, info[j]->default_queue);
  1539. queue_priority_mapping = info[j]->queue_priority_mapping;
  1540. /* Event queue priority mapping */
  1541. for (i = 0; queue_priority_mapping[i][0] != -1; i++)
  1542. assign_priority_to_queue(j,
  1543. queue_priority_mapping[i][0],
  1544. queue_priority_mapping[i][1]);
  1545. /* Map the channel to param entry if channel mapping logic
  1546. * exist
  1547. */
  1548. if (edma_read(j, EDMA_CCCFG) & CHMAP_EXIST)
  1549. map_dmach_param(j);
  1550. for (i = 0; i < edma_cc[j]->num_region; i++) {
  1551. edma_write_array2(j, EDMA_DRAE, i, 0, 0x0);
  1552. edma_write_array2(j, EDMA_DRAE, i, 1, 0x0);
  1553. edma_write_array(j, EDMA_QRAE, i, 0x0);
  1554. }
  1555. arch_num_cc++;
  1556. edma_dev_info.id = j;
  1557. platform_device_register_full(&edma_dev_info);
  1558. }
  1559. return 0;
  1560. }
  1561. static struct platform_driver edma_driver = {
  1562. .driver = {
  1563. .name = "edma",
  1564. .of_match_table = edma_of_ids,
  1565. },
  1566. .probe = edma_probe,
  1567. };
  1568. static int __init edma_init(void)
  1569. {
  1570. return platform_driver_probe(&edma_driver, edma_probe);
  1571. }
  1572. arch_initcall(edma_init);