edma.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813
  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. /*
  1235. * edma_assign_channel_eventq - move given channel to desired eventq
  1236. * Arguments:
  1237. * channel - channel number
  1238. * eventq_no - queue to move the channel
  1239. *
  1240. * Can be used to move a channel to a selected event queue.
  1241. */
  1242. void edma_assign_channel_eventq(unsigned channel, enum dma_event_q eventq_no)
  1243. {
  1244. unsigned ctlr;
  1245. ctlr = EDMA_CTLR(channel);
  1246. channel = EDMA_CHAN_SLOT(channel);
  1247. if (channel >= edma_cc[ctlr]->num_channels)
  1248. return;
  1249. /* default to low priority queue */
  1250. if (eventq_no == EVENTQ_DEFAULT)
  1251. eventq_no = edma_cc[ctlr]->default_queue;
  1252. if (eventq_no >= edma_cc[ctlr]->num_tc)
  1253. return;
  1254. map_dmach_queue(ctlr, channel, eventq_no);
  1255. }
  1256. EXPORT_SYMBOL(edma_assign_channel_eventq);
  1257. static int edma_setup_from_hw(struct device *dev, struct edma_soc_info *pdata,
  1258. struct edma *edma_cc)
  1259. {
  1260. int i;
  1261. u32 value, cccfg;
  1262. s8 (*queue_priority_map)[2];
  1263. /* Decode the eDMA3 configuration from CCCFG register */
  1264. cccfg = edma_read(0, EDMA_CCCFG);
  1265. value = GET_NUM_REGN(cccfg);
  1266. edma_cc->num_region = BIT(value);
  1267. value = GET_NUM_DMACH(cccfg);
  1268. edma_cc->num_channels = BIT(value + 1);
  1269. value = GET_NUM_PAENTRY(cccfg);
  1270. edma_cc->num_slots = BIT(value + 4);
  1271. value = GET_NUM_EVQUE(cccfg);
  1272. edma_cc->num_tc = value + 1;
  1273. dev_dbg(dev, "eDMA3 HW configuration (cccfg: 0x%08x):\n", cccfg);
  1274. dev_dbg(dev, "num_region: %u\n", edma_cc->num_region);
  1275. dev_dbg(dev, "num_channel: %u\n", edma_cc->num_channels);
  1276. dev_dbg(dev, "num_slot: %u\n", edma_cc->num_slots);
  1277. dev_dbg(dev, "num_tc: %u\n", edma_cc->num_tc);
  1278. /* Nothing need to be done if queue priority is provided */
  1279. if (pdata->queue_priority_mapping)
  1280. return 0;
  1281. /*
  1282. * Configure TC/queue priority as follows:
  1283. * Q0 - priority 0
  1284. * Q1 - priority 1
  1285. * Q2 - priority 2
  1286. * ...
  1287. * The meaning of priority numbers: 0 highest priority, 7 lowest
  1288. * priority. So Q0 is the highest priority queue and the last queue has
  1289. * the lowest priority.
  1290. */
  1291. queue_priority_map = devm_kzalloc(dev,
  1292. (edma_cc->num_tc + 1) * sizeof(s8),
  1293. GFP_KERNEL);
  1294. if (!queue_priority_map)
  1295. return -ENOMEM;
  1296. for (i = 0; i < edma_cc->num_tc; i++) {
  1297. queue_priority_map[i][0] = i;
  1298. queue_priority_map[i][1] = i;
  1299. }
  1300. queue_priority_map[i][0] = -1;
  1301. queue_priority_map[i][1] = -1;
  1302. pdata->queue_priority_mapping = queue_priority_map;
  1303. /* Default queue has the lowest priority */
  1304. pdata->default_queue = i - 1;
  1305. return 0;
  1306. }
  1307. #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_DMADEVICES)
  1308. static int edma_xbar_event_map(struct device *dev, struct device_node *node,
  1309. struct edma_soc_info *pdata, size_t sz)
  1310. {
  1311. const char pname[] = "ti,edma-xbar-event-map";
  1312. struct resource res;
  1313. void __iomem *xbar;
  1314. s16 (*xbar_chans)[2];
  1315. size_t nelm = sz / sizeof(s16);
  1316. u32 shift, offset, mux;
  1317. int ret, i;
  1318. xbar_chans = devm_kzalloc(dev, (nelm + 2) * sizeof(s16), GFP_KERNEL);
  1319. if (!xbar_chans)
  1320. return -ENOMEM;
  1321. ret = of_address_to_resource(node, 1, &res);
  1322. if (ret)
  1323. return -ENOMEM;
  1324. xbar = devm_ioremap(dev, res.start, resource_size(&res));
  1325. if (!xbar)
  1326. return -ENOMEM;
  1327. ret = of_property_read_u16_array(node, pname, (u16 *)xbar_chans, nelm);
  1328. if (ret)
  1329. return -EIO;
  1330. /* Invalidate last entry for the other user of this mess */
  1331. nelm >>= 1;
  1332. xbar_chans[nelm][0] = xbar_chans[nelm][1] = -1;
  1333. for (i = 0; i < nelm; i++) {
  1334. shift = (xbar_chans[i][1] & 0x03) << 3;
  1335. offset = xbar_chans[i][1] & 0xfffffffc;
  1336. mux = readl(xbar + offset);
  1337. mux &= ~(0xff << shift);
  1338. mux |= xbar_chans[i][0] << shift;
  1339. writel(mux, (xbar + offset));
  1340. }
  1341. pdata->xbar_chans = (const s16 (*)[2]) xbar_chans;
  1342. return 0;
  1343. }
  1344. static int edma_of_parse_dt(struct device *dev,
  1345. struct device_node *node,
  1346. struct edma_soc_info *pdata)
  1347. {
  1348. int ret = 0;
  1349. struct property *prop;
  1350. size_t sz;
  1351. struct edma_rsv_info *rsv_info;
  1352. rsv_info = devm_kzalloc(dev, sizeof(struct edma_rsv_info), GFP_KERNEL);
  1353. if (!rsv_info)
  1354. return -ENOMEM;
  1355. pdata->rsv = rsv_info;
  1356. prop = of_find_property(node, "ti,edma-xbar-event-map", &sz);
  1357. if (prop)
  1358. ret = edma_xbar_event_map(dev, node, pdata, sz);
  1359. return ret;
  1360. }
  1361. static struct of_dma_filter_info edma_filter_info = {
  1362. .filter_fn = edma_filter_fn,
  1363. };
  1364. static struct edma_soc_info *edma_setup_info_from_dt(struct device *dev,
  1365. struct device_node *node)
  1366. {
  1367. struct edma_soc_info *info;
  1368. int ret;
  1369. info = devm_kzalloc(dev, sizeof(struct edma_soc_info), GFP_KERNEL);
  1370. if (!info)
  1371. return ERR_PTR(-ENOMEM);
  1372. ret = edma_of_parse_dt(dev, node, info);
  1373. if (ret)
  1374. return ERR_PTR(ret);
  1375. dma_cap_set(DMA_SLAVE, edma_filter_info.dma_cap);
  1376. dma_cap_set(DMA_CYCLIC, edma_filter_info.dma_cap);
  1377. of_dma_controller_register(dev->of_node, of_dma_simple_xlate,
  1378. &edma_filter_info);
  1379. return info;
  1380. }
  1381. #else
  1382. static struct edma_soc_info *edma_setup_info_from_dt(struct device *dev,
  1383. struct device_node *node)
  1384. {
  1385. return ERR_PTR(-ENOSYS);
  1386. }
  1387. #endif
  1388. static int edma_probe(struct platform_device *pdev)
  1389. {
  1390. struct edma_soc_info **info = pdev->dev.platform_data;
  1391. struct edma_soc_info *ninfo[EDMA_MAX_CC] = {NULL};
  1392. s8 (*queue_priority_mapping)[2];
  1393. int i, j, off, ln, found = 0;
  1394. int status = -1;
  1395. const s16 (*rsv_chans)[2];
  1396. const s16 (*rsv_slots)[2];
  1397. const s16 (*xbar_chans)[2];
  1398. int irq[EDMA_MAX_CC] = {0, 0};
  1399. int err_irq[EDMA_MAX_CC] = {0, 0};
  1400. struct resource *r[EDMA_MAX_CC] = {NULL};
  1401. struct resource res[EDMA_MAX_CC];
  1402. char res_name[10];
  1403. struct device_node *node = pdev->dev.of_node;
  1404. struct device *dev = &pdev->dev;
  1405. int ret;
  1406. if (node) {
  1407. /* Check if this is a second instance registered */
  1408. if (arch_num_cc) {
  1409. dev_err(dev, "only one EDMA instance is supported via DT\n");
  1410. return -ENODEV;
  1411. }
  1412. ninfo[0] = edma_setup_info_from_dt(dev, node);
  1413. if (IS_ERR(ninfo[0])) {
  1414. dev_err(dev, "failed to get DT data\n");
  1415. return PTR_ERR(ninfo[0]);
  1416. }
  1417. info = ninfo;
  1418. }
  1419. if (!info)
  1420. return -ENODEV;
  1421. pm_runtime_enable(dev);
  1422. ret = pm_runtime_get_sync(dev);
  1423. if (ret < 0) {
  1424. dev_err(dev, "pm_runtime_get_sync() failed\n");
  1425. return ret;
  1426. }
  1427. for (j = 0; j < EDMA_MAX_CC; j++) {
  1428. if (!info[j]) {
  1429. if (!found)
  1430. return -ENODEV;
  1431. break;
  1432. }
  1433. if (node) {
  1434. ret = of_address_to_resource(node, j, &res[j]);
  1435. if (!ret)
  1436. r[j] = &res[j];
  1437. } else {
  1438. sprintf(res_name, "edma_cc%d", j);
  1439. r[j] = platform_get_resource_byname(pdev,
  1440. IORESOURCE_MEM,
  1441. res_name);
  1442. }
  1443. if (!r[j]) {
  1444. if (found)
  1445. break;
  1446. else
  1447. return -ENODEV;
  1448. } else {
  1449. found = 1;
  1450. }
  1451. edmacc_regs_base[j] = devm_ioremap_resource(&pdev->dev, r[j]);
  1452. if (IS_ERR(edmacc_regs_base[j]))
  1453. return PTR_ERR(edmacc_regs_base[j]);
  1454. edma_cc[j] = devm_kzalloc(&pdev->dev, sizeof(struct edma),
  1455. GFP_KERNEL);
  1456. if (!edma_cc[j])
  1457. return -ENOMEM;
  1458. /* Get eDMA3 configuration from IP */
  1459. ret = edma_setup_from_hw(dev, info[j], edma_cc[j]);
  1460. if (ret)
  1461. return ret;
  1462. edma_cc[j]->default_queue = info[j]->default_queue;
  1463. dev_dbg(&pdev->dev, "DMA REG BASE ADDR=%p\n",
  1464. edmacc_regs_base[j]);
  1465. for (i = 0; i < edma_cc[j]->num_slots; i++)
  1466. memcpy_toio(edmacc_regs_base[j] + PARM_OFFSET(i),
  1467. &dummy_paramset, PARM_SIZE);
  1468. /* Mark all channels as unused */
  1469. memset(edma_cc[j]->edma_unused, 0xff,
  1470. sizeof(edma_cc[j]->edma_unused));
  1471. if (info[j]->rsv) {
  1472. /* Clear the reserved channels in unused list */
  1473. rsv_chans = info[j]->rsv->rsv_chans;
  1474. if (rsv_chans) {
  1475. for (i = 0; rsv_chans[i][0] != -1; i++) {
  1476. off = rsv_chans[i][0];
  1477. ln = rsv_chans[i][1];
  1478. clear_bits(off, ln,
  1479. edma_cc[j]->edma_unused);
  1480. }
  1481. }
  1482. /* Set the reserved slots in inuse list */
  1483. rsv_slots = info[j]->rsv->rsv_slots;
  1484. if (rsv_slots) {
  1485. for (i = 0; rsv_slots[i][0] != -1; i++) {
  1486. off = rsv_slots[i][0];
  1487. ln = rsv_slots[i][1];
  1488. set_bits(off, ln,
  1489. edma_cc[j]->edma_inuse);
  1490. }
  1491. }
  1492. }
  1493. /* Clear the xbar mapped channels in unused list */
  1494. xbar_chans = info[j]->xbar_chans;
  1495. if (xbar_chans) {
  1496. for (i = 0; xbar_chans[i][1] != -1; i++) {
  1497. off = xbar_chans[i][1];
  1498. clear_bits(off, 1,
  1499. edma_cc[j]->edma_unused);
  1500. }
  1501. }
  1502. if (node) {
  1503. irq[j] = irq_of_parse_and_map(node, 0);
  1504. err_irq[j] = irq_of_parse_and_map(node, 2);
  1505. } else {
  1506. char irq_name[10];
  1507. sprintf(irq_name, "edma%d", j);
  1508. irq[j] = platform_get_irq_byname(pdev, irq_name);
  1509. sprintf(irq_name, "edma%d_err", j);
  1510. err_irq[j] = platform_get_irq_byname(pdev, irq_name);
  1511. }
  1512. edma_cc[j]->irq_res_start = irq[j];
  1513. edma_cc[j]->irq_res_end = err_irq[j];
  1514. status = devm_request_irq(dev, irq[j], dma_irq_handler, 0,
  1515. "edma", dev);
  1516. if (status < 0) {
  1517. dev_dbg(&pdev->dev,
  1518. "devm_request_irq %d failed --> %d\n",
  1519. irq[j], status);
  1520. return status;
  1521. }
  1522. status = devm_request_irq(dev, err_irq[j], dma_ccerr_handler, 0,
  1523. "edma_error", dev);
  1524. if (status < 0) {
  1525. dev_dbg(&pdev->dev,
  1526. "devm_request_irq %d failed --> %d\n",
  1527. err_irq[j], status);
  1528. return status;
  1529. }
  1530. for (i = 0; i < edma_cc[j]->num_channels; i++)
  1531. map_dmach_queue(j, i, info[j]->default_queue);
  1532. queue_priority_mapping = info[j]->queue_priority_mapping;
  1533. /* Event queue priority mapping */
  1534. for (i = 0; queue_priority_mapping[i][0] != -1; i++)
  1535. assign_priority_to_queue(j,
  1536. queue_priority_mapping[i][0],
  1537. queue_priority_mapping[i][1]);
  1538. /* Map the channel to param entry if channel mapping logic
  1539. * exist
  1540. */
  1541. if (edma_read(j, EDMA_CCCFG) & CHMAP_EXIST)
  1542. map_dmach_param(j);
  1543. for (i = 0; i < edma_cc[j]->num_region; i++) {
  1544. edma_write_array2(j, EDMA_DRAE, i, 0, 0x0);
  1545. edma_write_array2(j, EDMA_DRAE, i, 1, 0x0);
  1546. edma_write_array(j, EDMA_QRAE, i, 0x0);
  1547. }
  1548. arch_num_cc++;
  1549. }
  1550. return 0;
  1551. }
  1552. static struct platform_driver edma_driver = {
  1553. .driver = {
  1554. .name = "edma",
  1555. .of_match_table = edma_of_ids,
  1556. },
  1557. .probe = edma_probe,
  1558. };
  1559. static int __init edma_init(void)
  1560. {
  1561. return platform_driver_probe(&edma_driver, edma_probe);
  1562. }
  1563. arch_initcall(edma_init);