edma.c 51 KB

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