dma.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  1. /*
  2. * linux/arch/arm/plat-omap/dma.c
  3. *
  4. * Copyright (C) 2003 - 2008 Nokia Corporation
  5. * Author: Juha Yrjölä <juha.yrjola@nokia.com>
  6. * DMA channel linking for 1610 by Samuel Ortiz <samuel.ortiz@nokia.com>
  7. * Graphics DMA and LCD DMA graphics tranformations
  8. * by Imre Deak <imre.deak@nokia.com>
  9. * OMAP2/3 support Copyright (C) 2004-2007 Texas Instruments, Inc.
  10. * Merged to support both OMAP1 and OMAP2 by Tony Lindgren <tony@atomide.com>
  11. * Some functions based on earlier dma-omap.c Copyright (C) 2001 RidgeRun, Inc.
  12. *
  13. * Copyright (C) 2009 Texas Instruments
  14. * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
  15. *
  16. * Support functions for the OMAP internal DMA channels.
  17. *
  18. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  19. * Converted DMA library into DMA platform driver.
  20. * - G, Manjunath Kondaiah <manjugk@ti.com>
  21. *
  22. * This program is free software; you can redistribute it and/or modify
  23. * it under the terms of the GNU General Public License version 2 as
  24. * published by the Free Software Foundation.
  25. *
  26. */
  27. #include <linux/module.h>
  28. #include <linux/init.h>
  29. #include <linux/sched.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/errno.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/irq.h>
  34. #include <linux/io.h>
  35. #include <linux/slab.h>
  36. #include <linux/delay.h>
  37. #include <linux/omap-dma.h>
  38. /*
  39. * MAX_LOGICAL_DMA_CH_COUNT: the maximum number of logical DMA
  40. * channels that an instance of the SDMA IP block can support. Used
  41. * to size arrays. (The actual maximum on a particular SoC may be less
  42. * than this -- for example, OMAP1 SDMA instances only support 17 logical
  43. * DMA channels.)
  44. */
  45. #define MAX_LOGICAL_DMA_CH_COUNT 32
  46. #undef DEBUG
  47. #ifndef CONFIG_ARCH_OMAP1
  48. enum { DMA_CH_ALLOC_DONE, DMA_CH_PARAMS_SET_DONE, DMA_CH_STARTED,
  49. DMA_CH_QUEUED, DMA_CH_NOTSTARTED, DMA_CH_PAUSED, DMA_CH_LINK_ENABLED
  50. };
  51. enum { DMA_CHAIN_STARTED, DMA_CHAIN_NOTSTARTED };
  52. #endif
  53. #define OMAP_DMA_ACTIVE 0x01
  54. #define OMAP2_DMA_CSR_CLEAR_MASK 0xffffffff
  55. #define OMAP_FUNC_MUX_ARM_BASE (0xfffe1000 + 0xec)
  56. static struct omap_system_dma_plat_info *p;
  57. static struct omap_dma_dev_attr *d;
  58. static void omap_clear_dma(int lch);
  59. static int omap_dma_set_prio_lch(int lch, unsigned char read_prio,
  60. unsigned char write_prio);
  61. static int enable_1510_mode;
  62. static u32 errata;
  63. static struct omap_dma_global_context_registers {
  64. u32 dma_irqenable_l0;
  65. u32 dma_irqenable_l1;
  66. u32 dma_ocp_sysconfig;
  67. u32 dma_gcr;
  68. } omap_dma_global_context;
  69. struct dma_link_info {
  70. int *linked_dmach_q;
  71. int no_of_lchs_linked;
  72. int q_count;
  73. int q_tail;
  74. int q_head;
  75. int chain_state;
  76. int chain_mode;
  77. };
  78. static struct dma_link_info *dma_linked_lch;
  79. #ifndef CONFIG_ARCH_OMAP1
  80. /* Chain handling macros */
  81. #define OMAP_DMA_CHAIN_QINIT(chain_id) \
  82. do { \
  83. dma_linked_lch[chain_id].q_head = \
  84. dma_linked_lch[chain_id].q_tail = \
  85. dma_linked_lch[chain_id].q_count = 0; \
  86. } while (0)
  87. #define OMAP_DMA_CHAIN_QFULL(chain_id) \
  88. (dma_linked_lch[chain_id].no_of_lchs_linked == \
  89. dma_linked_lch[chain_id].q_count)
  90. #define OMAP_DMA_CHAIN_QLAST(chain_id) \
  91. do { \
  92. ((dma_linked_lch[chain_id].no_of_lchs_linked-1) == \
  93. dma_linked_lch[chain_id].q_count) \
  94. } while (0)
  95. #define OMAP_DMA_CHAIN_QEMPTY(chain_id) \
  96. (0 == dma_linked_lch[chain_id].q_count)
  97. #define __OMAP_DMA_CHAIN_INCQ(end) \
  98. ((end) = ((end)+1) % dma_linked_lch[chain_id].no_of_lchs_linked)
  99. #define OMAP_DMA_CHAIN_INCQHEAD(chain_id) \
  100. do { \
  101. __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_head); \
  102. dma_linked_lch[chain_id].q_count--; \
  103. } while (0)
  104. #define OMAP_DMA_CHAIN_INCQTAIL(chain_id) \
  105. do { \
  106. __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_tail); \
  107. dma_linked_lch[chain_id].q_count++; \
  108. } while (0)
  109. #endif
  110. static int dma_lch_count;
  111. static int dma_chan_count;
  112. static int omap_dma_reserve_channels;
  113. static spinlock_t dma_chan_lock;
  114. static struct omap_dma_lch *dma_chan;
  115. static inline void disable_lnk(int lch);
  116. static void omap_disable_channel_irq(int lch);
  117. static inline void omap_enable_channel_irq(int lch);
  118. #define REVISIT_24XX() printk(KERN_ERR "FIXME: no %s on 24xx\n", \
  119. __func__);
  120. #ifdef CONFIG_ARCH_OMAP15XX
  121. /* Returns 1 if the DMA module is in OMAP1510-compatible mode, 0 otherwise */
  122. static int omap_dma_in_1510_mode(void)
  123. {
  124. return enable_1510_mode;
  125. }
  126. #else
  127. #define omap_dma_in_1510_mode() 0
  128. #endif
  129. #ifdef CONFIG_ARCH_OMAP1
  130. static inline int get_gdma_dev(int req)
  131. {
  132. u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4;
  133. int shift = ((req - 1) % 5) * 6;
  134. return ((omap_readl(reg) >> shift) & 0x3f) + 1;
  135. }
  136. static inline void set_gdma_dev(int req, int dev)
  137. {
  138. u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4;
  139. int shift = ((req - 1) % 5) * 6;
  140. u32 l;
  141. l = omap_readl(reg);
  142. l &= ~(0x3f << shift);
  143. l |= (dev - 1) << shift;
  144. omap_writel(l, reg);
  145. }
  146. #else
  147. #define set_gdma_dev(req, dev) do {} while (0)
  148. #define omap_readl(reg) 0
  149. #define omap_writel(val, reg) do {} while (0)
  150. #endif
  151. #ifdef CONFIG_ARCH_OMAP1
  152. void omap_set_dma_priority(int lch, int dst_port, int priority)
  153. {
  154. unsigned long reg;
  155. u32 l;
  156. if (dma_omap1()) {
  157. switch (dst_port) {
  158. case OMAP_DMA_PORT_OCP_T1: /* FFFECC00 */
  159. reg = OMAP_TC_OCPT1_PRIOR;
  160. break;
  161. case OMAP_DMA_PORT_OCP_T2: /* FFFECCD0 */
  162. reg = OMAP_TC_OCPT2_PRIOR;
  163. break;
  164. case OMAP_DMA_PORT_EMIFF: /* FFFECC08 */
  165. reg = OMAP_TC_EMIFF_PRIOR;
  166. break;
  167. case OMAP_DMA_PORT_EMIFS: /* FFFECC04 */
  168. reg = OMAP_TC_EMIFS_PRIOR;
  169. break;
  170. default:
  171. BUG();
  172. return;
  173. }
  174. l = omap_readl(reg);
  175. l &= ~(0xf << 8);
  176. l |= (priority & 0xf) << 8;
  177. omap_writel(l, reg);
  178. }
  179. }
  180. #endif
  181. #ifdef CONFIG_ARCH_OMAP2PLUS
  182. void omap_set_dma_priority(int lch, int dst_port, int priority)
  183. {
  184. u32 ccr;
  185. ccr = p->dma_read(CCR, lch);
  186. if (priority)
  187. ccr |= (1 << 6);
  188. else
  189. ccr &= ~(1 << 6);
  190. p->dma_write(ccr, CCR, lch);
  191. }
  192. #endif
  193. EXPORT_SYMBOL(omap_set_dma_priority);
  194. void omap_set_dma_transfer_params(int lch, int data_type, int elem_count,
  195. int frame_count, int sync_mode,
  196. int dma_trigger, int src_or_dst_synch)
  197. {
  198. u32 l;
  199. l = p->dma_read(CSDP, lch);
  200. l &= ~0x03;
  201. l |= data_type;
  202. p->dma_write(l, CSDP, lch);
  203. if (dma_omap1()) {
  204. u16 ccr;
  205. ccr = p->dma_read(CCR, lch);
  206. ccr &= ~(1 << 5);
  207. if (sync_mode == OMAP_DMA_SYNC_FRAME)
  208. ccr |= 1 << 5;
  209. p->dma_write(ccr, CCR, lch);
  210. ccr = p->dma_read(CCR2, lch);
  211. ccr &= ~(1 << 2);
  212. if (sync_mode == OMAP_DMA_SYNC_BLOCK)
  213. ccr |= 1 << 2;
  214. p->dma_write(ccr, CCR2, lch);
  215. }
  216. if (dma_omap2plus() && dma_trigger) {
  217. u32 val;
  218. val = p->dma_read(CCR, lch);
  219. /* DMA_SYNCHRO_CONTROL_UPPER depends on the channel number */
  220. val &= ~((1 << 23) | (3 << 19) | 0x1f);
  221. val |= (dma_trigger & ~0x1f) << 14;
  222. val |= dma_trigger & 0x1f;
  223. if (sync_mode & OMAP_DMA_SYNC_FRAME)
  224. val |= 1 << 5;
  225. else
  226. val &= ~(1 << 5);
  227. if (sync_mode & OMAP_DMA_SYNC_BLOCK)
  228. val |= 1 << 18;
  229. else
  230. val &= ~(1 << 18);
  231. if (src_or_dst_synch == OMAP_DMA_DST_SYNC_PREFETCH) {
  232. val &= ~(1 << 24); /* dest synch */
  233. val |= (1 << 23); /* Prefetch */
  234. } else if (src_or_dst_synch) {
  235. val |= 1 << 24; /* source synch */
  236. } else {
  237. val &= ~(1 << 24); /* dest synch */
  238. }
  239. p->dma_write(val, CCR, lch);
  240. }
  241. p->dma_write(elem_count, CEN, lch);
  242. p->dma_write(frame_count, CFN, lch);
  243. }
  244. EXPORT_SYMBOL(omap_set_dma_transfer_params);
  245. void omap_set_dma_write_mode(int lch, enum omap_dma_write_mode mode)
  246. {
  247. if (dma_omap2plus()) {
  248. u32 csdp;
  249. csdp = p->dma_read(CSDP, lch);
  250. csdp &= ~(0x3 << 16);
  251. csdp |= (mode << 16);
  252. p->dma_write(csdp, CSDP, lch);
  253. }
  254. }
  255. EXPORT_SYMBOL(omap_set_dma_write_mode);
  256. void omap_set_dma_channel_mode(int lch, enum omap_dma_channel_mode mode)
  257. {
  258. if (dma_omap1() && !dma_omap15xx()) {
  259. u32 l;
  260. l = p->dma_read(LCH_CTRL, lch);
  261. l &= ~0x7;
  262. l |= mode;
  263. p->dma_write(l, LCH_CTRL, lch);
  264. }
  265. }
  266. EXPORT_SYMBOL(omap_set_dma_channel_mode);
  267. /* Note that src_port is only for omap1 */
  268. void omap_set_dma_src_params(int lch, int src_port, int src_amode,
  269. unsigned long src_start,
  270. int src_ei, int src_fi)
  271. {
  272. u32 l;
  273. if (dma_omap1()) {
  274. u16 w;
  275. w = p->dma_read(CSDP, lch);
  276. w &= ~(0x1f << 2);
  277. w |= src_port << 2;
  278. p->dma_write(w, CSDP, lch);
  279. }
  280. l = p->dma_read(CCR, lch);
  281. l &= ~(0x03 << 12);
  282. l |= src_amode << 12;
  283. p->dma_write(l, CCR, lch);
  284. p->dma_write(src_start, CSSA, lch);
  285. p->dma_write(src_ei, CSEI, lch);
  286. p->dma_write(src_fi, CSFI, lch);
  287. }
  288. EXPORT_SYMBOL(omap_set_dma_src_params);
  289. void omap_set_dma_params(int lch, struct omap_dma_channel_params *params)
  290. {
  291. omap_set_dma_transfer_params(lch, params->data_type,
  292. params->elem_count, params->frame_count,
  293. params->sync_mode, params->trigger,
  294. params->src_or_dst_synch);
  295. omap_set_dma_src_params(lch, params->src_port,
  296. params->src_amode, params->src_start,
  297. params->src_ei, params->src_fi);
  298. omap_set_dma_dest_params(lch, params->dst_port,
  299. params->dst_amode, params->dst_start,
  300. params->dst_ei, params->dst_fi);
  301. if (params->read_prio || params->write_prio)
  302. omap_dma_set_prio_lch(lch, params->read_prio,
  303. params->write_prio);
  304. }
  305. EXPORT_SYMBOL(omap_set_dma_params);
  306. void omap_set_dma_src_data_pack(int lch, int enable)
  307. {
  308. u32 l;
  309. l = p->dma_read(CSDP, lch);
  310. l &= ~(1 << 6);
  311. if (enable)
  312. l |= (1 << 6);
  313. p->dma_write(l, CSDP, lch);
  314. }
  315. EXPORT_SYMBOL(omap_set_dma_src_data_pack);
  316. void omap_set_dma_src_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
  317. {
  318. unsigned int burst = 0;
  319. u32 l;
  320. l = p->dma_read(CSDP, lch);
  321. l &= ~(0x03 << 7);
  322. switch (burst_mode) {
  323. case OMAP_DMA_DATA_BURST_DIS:
  324. break;
  325. case OMAP_DMA_DATA_BURST_4:
  326. if (dma_omap2plus())
  327. burst = 0x1;
  328. else
  329. burst = 0x2;
  330. break;
  331. case OMAP_DMA_DATA_BURST_8:
  332. if (dma_omap2plus()) {
  333. burst = 0x2;
  334. break;
  335. }
  336. /*
  337. * not supported by current hardware on OMAP1
  338. * w |= (0x03 << 7);
  339. * fall through
  340. */
  341. case OMAP_DMA_DATA_BURST_16:
  342. if (dma_omap2plus()) {
  343. burst = 0x3;
  344. break;
  345. }
  346. /*
  347. * OMAP1 don't support burst 16
  348. * fall through
  349. */
  350. default:
  351. BUG();
  352. }
  353. l |= (burst << 7);
  354. p->dma_write(l, CSDP, lch);
  355. }
  356. EXPORT_SYMBOL(omap_set_dma_src_burst_mode);
  357. /* Note that dest_port is only for OMAP1 */
  358. void omap_set_dma_dest_params(int lch, int dest_port, int dest_amode,
  359. unsigned long dest_start,
  360. int dst_ei, int dst_fi)
  361. {
  362. u32 l;
  363. if (dma_omap1()) {
  364. l = p->dma_read(CSDP, lch);
  365. l &= ~(0x1f << 9);
  366. l |= dest_port << 9;
  367. p->dma_write(l, CSDP, lch);
  368. }
  369. l = p->dma_read(CCR, lch);
  370. l &= ~(0x03 << 14);
  371. l |= dest_amode << 14;
  372. p->dma_write(l, CCR, lch);
  373. p->dma_write(dest_start, CDSA, lch);
  374. p->dma_write(dst_ei, CDEI, lch);
  375. p->dma_write(dst_fi, CDFI, lch);
  376. }
  377. EXPORT_SYMBOL(omap_set_dma_dest_params);
  378. void omap_set_dma_dest_data_pack(int lch, int enable)
  379. {
  380. u32 l;
  381. l = p->dma_read(CSDP, lch);
  382. l &= ~(1 << 13);
  383. if (enable)
  384. l |= 1 << 13;
  385. p->dma_write(l, CSDP, lch);
  386. }
  387. EXPORT_SYMBOL(omap_set_dma_dest_data_pack);
  388. void omap_set_dma_dest_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
  389. {
  390. unsigned int burst = 0;
  391. u32 l;
  392. l = p->dma_read(CSDP, lch);
  393. l &= ~(0x03 << 14);
  394. switch (burst_mode) {
  395. case OMAP_DMA_DATA_BURST_DIS:
  396. break;
  397. case OMAP_DMA_DATA_BURST_4:
  398. if (dma_omap2plus())
  399. burst = 0x1;
  400. else
  401. burst = 0x2;
  402. break;
  403. case OMAP_DMA_DATA_BURST_8:
  404. if (dma_omap2plus())
  405. burst = 0x2;
  406. else
  407. burst = 0x3;
  408. break;
  409. case OMAP_DMA_DATA_BURST_16:
  410. if (dma_omap2plus()) {
  411. burst = 0x3;
  412. break;
  413. }
  414. /*
  415. * OMAP1 don't support burst 16
  416. * fall through
  417. */
  418. default:
  419. printk(KERN_ERR "Invalid DMA burst mode\n");
  420. BUG();
  421. return;
  422. }
  423. l |= (burst << 14);
  424. p->dma_write(l, CSDP, lch);
  425. }
  426. EXPORT_SYMBOL(omap_set_dma_dest_burst_mode);
  427. static inline void omap_enable_channel_irq(int lch)
  428. {
  429. /* Clear CSR */
  430. if (dma_omap1())
  431. p->dma_read(CSR, lch);
  432. else
  433. p->dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR, lch);
  434. /* Enable some nice interrupts. */
  435. p->dma_write(dma_chan[lch].enabled_irqs, CICR, lch);
  436. }
  437. static inline void omap_disable_channel_irq(int lch)
  438. {
  439. /* disable channel interrupts */
  440. p->dma_write(0, CICR, lch);
  441. /* Clear CSR */
  442. if (dma_omap1())
  443. p->dma_read(CSR, lch);
  444. else
  445. p->dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR, lch);
  446. }
  447. void omap_enable_dma_irq(int lch, u16 bits)
  448. {
  449. dma_chan[lch].enabled_irqs |= bits;
  450. }
  451. EXPORT_SYMBOL(omap_enable_dma_irq);
  452. void omap_disable_dma_irq(int lch, u16 bits)
  453. {
  454. dma_chan[lch].enabled_irqs &= ~bits;
  455. }
  456. EXPORT_SYMBOL(omap_disable_dma_irq);
  457. static inline void enable_lnk(int lch)
  458. {
  459. u32 l;
  460. l = p->dma_read(CLNK_CTRL, lch);
  461. if (dma_omap1())
  462. l &= ~(1 << 14);
  463. /* Set the ENABLE_LNK bits */
  464. if (dma_chan[lch].next_lch != -1)
  465. l = dma_chan[lch].next_lch | (1 << 15);
  466. #ifndef CONFIG_ARCH_OMAP1
  467. if (dma_omap2plus())
  468. if (dma_chan[lch].next_linked_ch != -1)
  469. l = dma_chan[lch].next_linked_ch | (1 << 15);
  470. #endif
  471. p->dma_write(l, CLNK_CTRL, lch);
  472. }
  473. static inline void disable_lnk(int lch)
  474. {
  475. u32 l;
  476. l = p->dma_read(CLNK_CTRL, lch);
  477. /* Disable interrupts */
  478. omap_disable_channel_irq(lch);
  479. if (dma_omap1()) {
  480. /* Set the STOP_LNK bit */
  481. l |= 1 << 14;
  482. }
  483. if (dma_omap2plus()) {
  484. /* Clear the ENABLE_LNK bit */
  485. l &= ~(1 << 15);
  486. }
  487. p->dma_write(l, CLNK_CTRL, lch);
  488. dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
  489. }
  490. static inline void omap2_enable_irq_lch(int lch)
  491. {
  492. u32 val;
  493. unsigned long flags;
  494. if (dma_omap1())
  495. return;
  496. spin_lock_irqsave(&dma_chan_lock, flags);
  497. /* clear IRQ STATUS */
  498. p->dma_write(1 << lch, IRQSTATUS_L0, lch);
  499. /* Enable interrupt */
  500. val = p->dma_read(IRQENABLE_L0, lch);
  501. val |= 1 << lch;
  502. p->dma_write(val, IRQENABLE_L0, lch);
  503. spin_unlock_irqrestore(&dma_chan_lock, flags);
  504. }
  505. static inline void omap2_disable_irq_lch(int lch)
  506. {
  507. u32 val;
  508. unsigned long flags;
  509. if (dma_omap1())
  510. return;
  511. spin_lock_irqsave(&dma_chan_lock, flags);
  512. /* Disable interrupt */
  513. val = p->dma_read(IRQENABLE_L0, lch);
  514. val &= ~(1 << lch);
  515. p->dma_write(val, IRQENABLE_L0, lch);
  516. /* clear IRQ STATUS */
  517. p->dma_write(1 << lch, IRQSTATUS_L0, lch);
  518. spin_unlock_irqrestore(&dma_chan_lock, flags);
  519. }
  520. int omap_request_dma(int dev_id, const char *dev_name,
  521. void (*callback)(int lch, u16 ch_status, void *data),
  522. void *data, int *dma_ch_out)
  523. {
  524. int ch, free_ch = -1;
  525. unsigned long flags;
  526. struct omap_dma_lch *chan;
  527. WARN(strcmp(dev_name, "DMA engine"), "Using deprecated platform DMA API - please update to DMA engine");
  528. spin_lock_irqsave(&dma_chan_lock, flags);
  529. for (ch = 0; ch < dma_chan_count; ch++) {
  530. if (free_ch == -1 && dma_chan[ch].dev_id == -1) {
  531. free_ch = ch;
  532. /* Exit after first free channel found */
  533. break;
  534. }
  535. }
  536. if (free_ch == -1) {
  537. spin_unlock_irqrestore(&dma_chan_lock, flags);
  538. return -EBUSY;
  539. }
  540. chan = dma_chan + free_ch;
  541. chan->dev_id = dev_id;
  542. if (p->clear_lch_regs)
  543. p->clear_lch_regs(free_ch);
  544. if (dma_omap2plus())
  545. omap_clear_dma(free_ch);
  546. spin_unlock_irqrestore(&dma_chan_lock, flags);
  547. chan->dev_name = dev_name;
  548. chan->callback = callback;
  549. chan->data = data;
  550. chan->flags = 0;
  551. #ifndef CONFIG_ARCH_OMAP1
  552. if (dma_omap2plus()) {
  553. chan->chain_id = -1;
  554. chan->next_linked_ch = -1;
  555. }
  556. #endif
  557. chan->enabled_irqs = OMAP_DMA_DROP_IRQ | OMAP_DMA_BLOCK_IRQ;
  558. if (dma_omap1())
  559. chan->enabled_irqs |= OMAP1_DMA_TOUT_IRQ;
  560. else if (dma_omap2plus())
  561. chan->enabled_irqs |= OMAP2_DMA_MISALIGNED_ERR_IRQ |
  562. OMAP2_DMA_TRANS_ERR_IRQ;
  563. if (dma_omap16xx()) {
  564. /* If the sync device is set, configure it dynamically. */
  565. if (dev_id != 0) {
  566. set_gdma_dev(free_ch + 1, dev_id);
  567. dev_id = free_ch + 1;
  568. }
  569. /*
  570. * Disable the 1510 compatibility mode and set the sync device
  571. * id.
  572. */
  573. p->dma_write(dev_id | (1 << 10), CCR, free_ch);
  574. } else if (dma_omap1()) {
  575. p->dma_write(dev_id, CCR, free_ch);
  576. }
  577. if (dma_omap2plus()) {
  578. omap_enable_channel_irq(free_ch);
  579. omap2_enable_irq_lch(free_ch);
  580. }
  581. *dma_ch_out = free_ch;
  582. return 0;
  583. }
  584. EXPORT_SYMBOL(omap_request_dma);
  585. void omap_free_dma(int lch)
  586. {
  587. unsigned long flags;
  588. if (dma_chan[lch].dev_id == -1) {
  589. pr_err("omap_dma: trying to free unallocated DMA channel %d\n",
  590. lch);
  591. return;
  592. }
  593. /* Disable interrupt for logical channel */
  594. if (dma_omap2plus())
  595. omap2_disable_irq_lch(lch);
  596. /* Disable all DMA interrupts for the channel. */
  597. omap_disable_channel_irq(lch);
  598. /* Make sure the DMA transfer is stopped. */
  599. p->dma_write(0, CCR, lch);
  600. /* Clear registers */
  601. if (dma_omap2plus())
  602. omap_clear_dma(lch);
  603. spin_lock_irqsave(&dma_chan_lock, flags);
  604. dma_chan[lch].dev_id = -1;
  605. dma_chan[lch].next_lch = -1;
  606. dma_chan[lch].callback = NULL;
  607. spin_unlock_irqrestore(&dma_chan_lock, flags);
  608. }
  609. EXPORT_SYMBOL(omap_free_dma);
  610. /**
  611. * @brief omap_dma_set_global_params : Set global priority settings for dma
  612. *
  613. * @param arb_rate
  614. * @param max_fifo_depth
  615. * @param tparams - Number of threads to reserve : DMA_THREAD_RESERVE_NORM
  616. * DMA_THREAD_RESERVE_ONET
  617. * DMA_THREAD_RESERVE_TWOT
  618. * DMA_THREAD_RESERVE_THREET
  619. */
  620. void
  621. omap_dma_set_global_params(int arb_rate, int max_fifo_depth, int tparams)
  622. {
  623. u32 reg;
  624. if (dma_omap1()) {
  625. printk(KERN_ERR "FIXME: no %s on 15xx/16xx\n", __func__);
  626. return;
  627. }
  628. if (max_fifo_depth == 0)
  629. max_fifo_depth = 1;
  630. if (arb_rate == 0)
  631. arb_rate = 1;
  632. reg = 0xff & max_fifo_depth;
  633. reg |= (0x3 & tparams) << 12;
  634. reg |= (arb_rate & 0xff) << 16;
  635. p->dma_write(reg, GCR, 0);
  636. }
  637. EXPORT_SYMBOL(omap_dma_set_global_params);
  638. /**
  639. * @brief omap_dma_set_prio_lch : Set channel wise priority settings
  640. *
  641. * @param lch
  642. * @param read_prio - Read priority
  643. * @param write_prio - Write priority
  644. * Both of the above can be set with one of the following values :
  645. * DMA_CH_PRIO_HIGH/DMA_CH_PRIO_LOW
  646. */
  647. static int
  648. omap_dma_set_prio_lch(int lch, unsigned char read_prio,
  649. unsigned char write_prio)
  650. {
  651. u32 l;
  652. if (unlikely((lch < 0 || lch >= dma_lch_count))) {
  653. printk(KERN_ERR "Invalid channel id\n");
  654. return -EINVAL;
  655. }
  656. l = p->dma_read(CCR, lch);
  657. l &= ~((1 << 6) | (1 << 26));
  658. if (d->dev_caps & IS_RW_PRIORITY)
  659. l |= ((read_prio & 0x1) << 6) | ((write_prio & 0x1) << 26);
  660. else
  661. l |= ((read_prio & 0x1) << 6);
  662. p->dma_write(l, CCR, lch);
  663. return 0;
  664. }
  665. /*
  666. * Clears any DMA state so the DMA engine is ready to restart with new buffers
  667. * through omap_start_dma(). Any buffers in flight are discarded.
  668. */
  669. static void omap_clear_dma(int lch)
  670. {
  671. unsigned long flags;
  672. local_irq_save(flags);
  673. p->clear_dma(lch);
  674. local_irq_restore(flags);
  675. }
  676. void omap_start_dma(int lch)
  677. {
  678. u32 l;
  679. /*
  680. * The CPC/CDAC register needs to be initialized to zero
  681. * before starting dma transfer.
  682. */
  683. if (dma_omap15xx())
  684. p->dma_write(0, CPC, lch);
  685. else
  686. p->dma_write(0, CDAC, lch);
  687. if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
  688. int next_lch, cur_lch;
  689. char dma_chan_link_map[MAX_LOGICAL_DMA_CH_COUNT];
  690. /* Set the link register of the first channel */
  691. enable_lnk(lch);
  692. memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
  693. dma_chan_link_map[lch] = 1;
  694. cur_lch = dma_chan[lch].next_lch;
  695. do {
  696. next_lch = dma_chan[cur_lch].next_lch;
  697. /* The loop case: we've been here already */
  698. if (dma_chan_link_map[cur_lch])
  699. break;
  700. /* Mark the current channel */
  701. dma_chan_link_map[cur_lch] = 1;
  702. enable_lnk(cur_lch);
  703. omap_enable_channel_irq(cur_lch);
  704. cur_lch = next_lch;
  705. } while (next_lch != -1);
  706. } else if (IS_DMA_ERRATA(DMA_ERRATA_PARALLEL_CHANNELS))
  707. p->dma_write(lch, CLNK_CTRL, lch);
  708. omap_enable_channel_irq(lch);
  709. l = p->dma_read(CCR, lch);
  710. if (IS_DMA_ERRATA(DMA_ERRATA_IFRAME_BUFFERING))
  711. l |= OMAP_DMA_CCR_BUFFERING_DISABLE;
  712. l |= OMAP_DMA_CCR_EN;
  713. /*
  714. * As dma_write() uses IO accessors which are weakly ordered, there
  715. * is no guarantee that data in coherent DMA memory will be visible
  716. * to the DMA device. Add a memory barrier here to ensure that any
  717. * such data is visible prior to enabling DMA.
  718. */
  719. mb();
  720. p->dma_write(l, CCR, lch);
  721. dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
  722. }
  723. EXPORT_SYMBOL(omap_start_dma);
  724. void omap_stop_dma(int lch)
  725. {
  726. u32 l;
  727. /* Disable all interrupts on the channel */
  728. omap_disable_channel_irq(lch);
  729. l = p->dma_read(CCR, lch);
  730. if (IS_DMA_ERRATA(DMA_ERRATA_i541) &&
  731. (l & OMAP_DMA_CCR_SEL_SRC_DST_SYNC)) {
  732. int i = 0;
  733. u32 sys_cf;
  734. /* Configure No-Standby */
  735. l = p->dma_read(OCP_SYSCONFIG, lch);
  736. sys_cf = l;
  737. l &= ~DMA_SYSCONFIG_MIDLEMODE_MASK;
  738. l |= DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_NO_IDLE);
  739. p->dma_write(l , OCP_SYSCONFIG, 0);
  740. l = p->dma_read(CCR, lch);
  741. l &= ~OMAP_DMA_CCR_EN;
  742. p->dma_write(l, CCR, lch);
  743. /* Wait for sDMA FIFO drain */
  744. l = p->dma_read(CCR, lch);
  745. while (i < 100 && (l & (OMAP_DMA_CCR_RD_ACTIVE |
  746. OMAP_DMA_CCR_WR_ACTIVE))) {
  747. udelay(5);
  748. i++;
  749. l = p->dma_read(CCR, lch);
  750. }
  751. if (i >= 100)
  752. pr_err("DMA drain did not complete on lch %d\n", lch);
  753. /* Restore OCP_SYSCONFIG */
  754. p->dma_write(sys_cf, OCP_SYSCONFIG, lch);
  755. } else {
  756. l &= ~OMAP_DMA_CCR_EN;
  757. p->dma_write(l, CCR, lch);
  758. }
  759. /*
  760. * Ensure that data transferred by DMA is visible to any access
  761. * after DMA has been disabled. This is important for coherent
  762. * DMA regions.
  763. */
  764. mb();
  765. if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
  766. int next_lch, cur_lch = lch;
  767. char dma_chan_link_map[MAX_LOGICAL_DMA_CH_COUNT];
  768. memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
  769. do {
  770. /* The loop case: we've been here already */
  771. if (dma_chan_link_map[cur_lch])
  772. break;
  773. /* Mark the current channel */
  774. dma_chan_link_map[cur_lch] = 1;
  775. disable_lnk(cur_lch);
  776. next_lch = dma_chan[cur_lch].next_lch;
  777. cur_lch = next_lch;
  778. } while (next_lch != -1);
  779. }
  780. dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
  781. }
  782. EXPORT_SYMBOL(omap_stop_dma);
  783. /*
  784. * Allows changing the DMA callback function or data. This may be needed if
  785. * the driver shares a single DMA channel for multiple dma triggers.
  786. */
  787. int omap_set_dma_callback(int lch,
  788. void (*callback)(int lch, u16 ch_status, void *data),
  789. void *data)
  790. {
  791. unsigned long flags;
  792. if (lch < 0)
  793. return -ENODEV;
  794. spin_lock_irqsave(&dma_chan_lock, flags);
  795. if (dma_chan[lch].dev_id == -1) {
  796. printk(KERN_ERR "DMA callback for not set for free channel\n");
  797. spin_unlock_irqrestore(&dma_chan_lock, flags);
  798. return -EINVAL;
  799. }
  800. dma_chan[lch].callback = callback;
  801. dma_chan[lch].data = data;
  802. spin_unlock_irqrestore(&dma_chan_lock, flags);
  803. return 0;
  804. }
  805. EXPORT_SYMBOL(omap_set_dma_callback);
  806. /*
  807. * Returns current physical source address for the given DMA channel.
  808. * If the channel is running the caller must disable interrupts prior calling
  809. * this function and process the returned value before re-enabling interrupt to
  810. * prevent races with the interrupt handler. Note that in continuous mode there
  811. * is a chance for CSSA_L register overflow between the two reads resulting
  812. * in incorrect return value.
  813. */
  814. dma_addr_t omap_get_dma_src_pos(int lch)
  815. {
  816. dma_addr_t offset = 0;
  817. if (dma_omap15xx())
  818. offset = p->dma_read(CPC, lch);
  819. else
  820. offset = p->dma_read(CSAC, lch);
  821. if (IS_DMA_ERRATA(DMA_ERRATA_3_3) && offset == 0)
  822. offset = p->dma_read(CSAC, lch);
  823. if (!dma_omap15xx()) {
  824. /*
  825. * CDAC == 0 indicates that the DMA transfer on the channel has
  826. * not been started (no data has been transferred so far).
  827. * Return the programmed source start address in this case.
  828. */
  829. if (likely(p->dma_read(CDAC, lch)))
  830. offset = p->dma_read(CSAC, lch);
  831. else
  832. offset = p->dma_read(CSSA, lch);
  833. }
  834. if (dma_omap1())
  835. offset |= (p->dma_read(CSSA, lch) & 0xFFFF0000);
  836. return offset;
  837. }
  838. EXPORT_SYMBOL(omap_get_dma_src_pos);
  839. /*
  840. * Returns current physical destination address for the given DMA channel.
  841. * If the channel is running the caller must disable interrupts prior calling
  842. * this function and process the returned value before re-enabling interrupt to
  843. * prevent races with the interrupt handler. Note that in continuous mode there
  844. * is a chance for CDSA_L register overflow between the two reads resulting
  845. * in incorrect return value.
  846. */
  847. dma_addr_t omap_get_dma_dst_pos(int lch)
  848. {
  849. dma_addr_t offset = 0;
  850. if (dma_omap15xx())
  851. offset = p->dma_read(CPC, lch);
  852. else
  853. offset = p->dma_read(CDAC, lch);
  854. /*
  855. * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
  856. * read before the DMA controller finished disabling the channel.
  857. */
  858. if (!dma_omap15xx() && offset == 0) {
  859. offset = p->dma_read(CDAC, lch);
  860. /*
  861. * CDAC == 0 indicates that the DMA transfer on the channel has
  862. * not been started (no data has been transferred so far).
  863. * Return the programmed destination start address in this case.
  864. */
  865. if (unlikely(!offset))
  866. offset = p->dma_read(CDSA, lch);
  867. }
  868. if (dma_omap1())
  869. offset |= (p->dma_read(CDSA, lch) & 0xFFFF0000);
  870. return offset;
  871. }
  872. EXPORT_SYMBOL(omap_get_dma_dst_pos);
  873. int omap_get_dma_active_status(int lch)
  874. {
  875. return (p->dma_read(CCR, lch) & OMAP_DMA_CCR_EN) != 0;
  876. }
  877. EXPORT_SYMBOL(omap_get_dma_active_status);
  878. int omap_dma_running(void)
  879. {
  880. int lch;
  881. if (dma_omap1())
  882. if (omap_lcd_dma_running())
  883. return 1;
  884. for (lch = 0; lch < dma_chan_count; lch++)
  885. if (p->dma_read(CCR, lch) & OMAP_DMA_CCR_EN)
  886. return 1;
  887. return 0;
  888. }
  889. /*
  890. * lch_queue DMA will start right after lch_head one is finished.
  891. * For this DMA link to start, you still need to start (see omap_start_dma)
  892. * the first one. That will fire up the entire queue.
  893. */
  894. void omap_dma_link_lch(int lch_head, int lch_queue)
  895. {
  896. if (omap_dma_in_1510_mode()) {
  897. if (lch_head == lch_queue) {
  898. p->dma_write(p->dma_read(CCR, lch_head) | (3 << 8),
  899. CCR, lch_head);
  900. return;
  901. }
  902. printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
  903. BUG();
  904. return;
  905. }
  906. if ((dma_chan[lch_head].dev_id == -1) ||
  907. (dma_chan[lch_queue].dev_id == -1)) {
  908. pr_err("omap_dma: trying to link non requested channels\n");
  909. dump_stack();
  910. }
  911. dma_chan[lch_head].next_lch = lch_queue;
  912. }
  913. EXPORT_SYMBOL(omap_dma_link_lch);
  914. /*----------------------------------------------------------------------------*/
  915. #ifdef CONFIG_ARCH_OMAP1
  916. static int omap1_dma_handle_ch(int ch)
  917. {
  918. u32 csr;
  919. if (enable_1510_mode && ch >= 6) {
  920. csr = dma_chan[ch].saved_csr;
  921. dma_chan[ch].saved_csr = 0;
  922. } else
  923. csr = p->dma_read(CSR, ch);
  924. if (enable_1510_mode && ch <= 2 && (csr >> 7) != 0) {
  925. dma_chan[ch + 6].saved_csr = csr >> 7;
  926. csr &= 0x7f;
  927. }
  928. if ((csr & 0x3f) == 0)
  929. return 0;
  930. if (unlikely(dma_chan[ch].dev_id == -1)) {
  931. pr_warn("Spurious interrupt from DMA channel %d (CSR %04x)\n",
  932. ch, csr);
  933. return 0;
  934. }
  935. if (unlikely(csr & OMAP1_DMA_TOUT_IRQ))
  936. pr_warn("DMA timeout with device %d\n", dma_chan[ch].dev_id);
  937. if (unlikely(csr & OMAP_DMA_DROP_IRQ))
  938. pr_warn("DMA synchronization event drop occurred with device %d\n",
  939. dma_chan[ch].dev_id);
  940. if (likely(csr & OMAP_DMA_BLOCK_IRQ))
  941. dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
  942. if (likely(dma_chan[ch].callback != NULL))
  943. dma_chan[ch].callback(ch, csr, dma_chan[ch].data);
  944. return 1;
  945. }
  946. static irqreturn_t omap1_dma_irq_handler(int irq, void *dev_id)
  947. {
  948. int ch = ((int) dev_id) - 1;
  949. int handled = 0;
  950. for (;;) {
  951. int handled_now = 0;
  952. handled_now += omap1_dma_handle_ch(ch);
  953. if (enable_1510_mode && dma_chan[ch + 6].saved_csr)
  954. handled_now += omap1_dma_handle_ch(ch + 6);
  955. if (!handled_now)
  956. break;
  957. handled += handled_now;
  958. }
  959. return handled ? IRQ_HANDLED : IRQ_NONE;
  960. }
  961. #else
  962. #define omap1_dma_irq_handler NULL
  963. #endif
  964. #ifdef CONFIG_ARCH_OMAP2PLUS
  965. static int omap2_dma_handle_ch(int ch)
  966. {
  967. u32 status = p->dma_read(CSR, ch);
  968. if (!status) {
  969. if (printk_ratelimit())
  970. pr_warn("Spurious DMA IRQ for lch %d\n", ch);
  971. p->dma_write(1 << ch, IRQSTATUS_L0, ch);
  972. return 0;
  973. }
  974. if (unlikely(dma_chan[ch].dev_id == -1)) {
  975. if (printk_ratelimit())
  976. pr_warn("IRQ %04x for non-allocated DMA channel %d\n",
  977. status, ch);
  978. return 0;
  979. }
  980. if (unlikely(status & OMAP_DMA_DROP_IRQ))
  981. pr_info("DMA synchronization event drop occurred with device %d\n",
  982. dma_chan[ch].dev_id);
  983. if (unlikely(status & OMAP2_DMA_TRANS_ERR_IRQ)) {
  984. printk(KERN_INFO "DMA transaction error with device %d\n",
  985. dma_chan[ch].dev_id);
  986. if (IS_DMA_ERRATA(DMA_ERRATA_i378)) {
  987. u32 ccr;
  988. ccr = p->dma_read(CCR, ch);
  989. ccr &= ~OMAP_DMA_CCR_EN;
  990. p->dma_write(ccr, CCR, ch);
  991. dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
  992. }
  993. }
  994. if (unlikely(status & OMAP2_DMA_SECURE_ERR_IRQ))
  995. printk(KERN_INFO "DMA secure error with device %d\n",
  996. dma_chan[ch].dev_id);
  997. if (unlikely(status & OMAP2_DMA_MISALIGNED_ERR_IRQ))
  998. printk(KERN_INFO "DMA misaligned error with device %d\n",
  999. dma_chan[ch].dev_id);
  1000. p->dma_write(status, CSR, ch);
  1001. p->dma_write(1 << ch, IRQSTATUS_L0, ch);
  1002. /* read back the register to flush the write */
  1003. p->dma_read(IRQSTATUS_L0, ch);
  1004. /* If the ch is not chained then chain_id will be -1 */
  1005. if (dma_chan[ch].chain_id != -1) {
  1006. int chain_id = dma_chan[ch].chain_id;
  1007. dma_chan[ch].state = DMA_CH_NOTSTARTED;
  1008. if (p->dma_read(CLNK_CTRL, ch) & (1 << 15))
  1009. dma_chan[dma_chan[ch].next_linked_ch].state =
  1010. DMA_CH_STARTED;
  1011. if (dma_linked_lch[chain_id].chain_mode ==
  1012. OMAP_DMA_DYNAMIC_CHAIN)
  1013. disable_lnk(ch);
  1014. if (!OMAP_DMA_CHAIN_QEMPTY(chain_id))
  1015. OMAP_DMA_CHAIN_INCQHEAD(chain_id);
  1016. status = p->dma_read(CSR, ch);
  1017. p->dma_write(status, CSR, ch);
  1018. }
  1019. if (likely(dma_chan[ch].callback != NULL))
  1020. dma_chan[ch].callback(ch, status, dma_chan[ch].data);
  1021. return 0;
  1022. }
  1023. /* STATUS register count is from 1-32 while our is 0-31 */
  1024. static irqreturn_t omap2_dma_irq_handler(int irq, void *dev_id)
  1025. {
  1026. u32 val, enable_reg;
  1027. int i;
  1028. val = p->dma_read(IRQSTATUS_L0, 0);
  1029. if (val == 0) {
  1030. if (printk_ratelimit())
  1031. printk(KERN_WARNING "Spurious DMA IRQ\n");
  1032. return IRQ_HANDLED;
  1033. }
  1034. enable_reg = p->dma_read(IRQENABLE_L0, 0);
  1035. val &= enable_reg; /* Dispatch only relevant interrupts */
  1036. for (i = 0; i < dma_lch_count && val != 0; i++) {
  1037. if (val & 1)
  1038. omap2_dma_handle_ch(i);
  1039. val >>= 1;
  1040. }
  1041. return IRQ_HANDLED;
  1042. }
  1043. static struct irqaction omap24xx_dma_irq = {
  1044. .name = "DMA",
  1045. .handler = omap2_dma_irq_handler,
  1046. };
  1047. #else
  1048. static struct irqaction omap24xx_dma_irq;
  1049. #endif
  1050. /*----------------------------------------------------------------------------*/
  1051. /*
  1052. * Note that we are currently using only IRQENABLE_L0 and L1.
  1053. * As the DSP may be using IRQENABLE_L2 and L3, let's not
  1054. * touch those for now.
  1055. */
  1056. void omap_dma_global_context_save(void)
  1057. {
  1058. omap_dma_global_context.dma_irqenable_l0 =
  1059. p->dma_read(IRQENABLE_L0, 0);
  1060. omap_dma_global_context.dma_irqenable_l1 =
  1061. p->dma_read(IRQENABLE_L1, 0);
  1062. omap_dma_global_context.dma_ocp_sysconfig =
  1063. p->dma_read(OCP_SYSCONFIG, 0);
  1064. omap_dma_global_context.dma_gcr = p->dma_read(GCR, 0);
  1065. }
  1066. void omap_dma_global_context_restore(void)
  1067. {
  1068. int ch;
  1069. p->dma_write(omap_dma_global_context.dma_gcr, GCR, 0);
  1070. p->dma_write(omap_dma_global_context.dma_ocp_sysconfig,
  1071. OCP_SYSCONFIG, 0);
  1072. p->dma_write(omap_dma_global_context.dma_irqenable_l0,
  1073. IRQENABLE_L0, 0);
  1074. p->dma_write(omap_dma_global_context.dma_irqenable_l1,
  1075. IRQENABLE_L1, 0);
  1076. if (IS_DMA_ERRATA(DMA_ROMCODE_BUG))
  1077. p->dma_write(0x3 , IRQSTATUS_L0, 0);
  1078. for (ch = 0; ch < dma_chan_count; ch++)
  1079. if (dma_chan[ch].dev_id != -1)
  1080. omap_clear_dma(ch);
  1081. }
  1082. struct omap_system_dma_plat_info *omap_get_plat_info(void)
  1083. {
  1084. return p;
  1085. }
  1086. EXPORT_SYMBOL_GPL(omap_get_plat_info);
  1087. static int omap_system_dma_probe(struct platform_device *pdev)
  1088. {
  1089. int ch, ret = 0;
  1090. int dma_irq;
  1091. char irq_name[4];
  1092. int irq_rel;
  1093. p = pdev->dev.platform_data;
  1094. if (!p) {
  1095. dev_err(&pdev->dev,
  1096. "%s: System DMA initialized without platform data\n",
  1097. __func__);
  1098. return -EINVAL;
  1099. }
  1100. d = p->dma_attr;
  1101. errata = p->errata;
  1102. if ((d->dev_caps & RESERVE_CHANNEL) && omap_dma_reserve_channels
  1103. && (omap_dma_reserve_channels < d->lch_count))
  1104. d->lch_count = omap_dma_reserve_channels;
  1105. dma_lch_count = d->lch_count;
  1106. dma_chan_count = dma_lch_count;
  1107. enable_1510_mode = d->dev_caps & ENABLE_1510_MODE;
  1108. dma_chan = devm_kcalloc(&pdev->dev, dma_lch_count,
  1109. sizeof(struct omap_dma_lch), GFP_KERNEL);
  1110. if (!dma_chan) {
  1111. dev_err(&pdev->dev, "%s: kzalloc fail\n", __func__);
  1112. return -ENOMEM;
  1113. }
  1114. if (dma_omap2plus()) {
  1115. dma_linked_lch = kzalloc(sizeof(struct dma_link_info) *
  1116. dma_lch_count, GFP_KERNEL);
  1117. if (!dma_linked_lch) {
  1118. ret = -ENOMEM;
  1119. goto exit_dma_lch_fail;
  1120. }
  1121. }
  1122. spin_lock_init(&dma_chan_lock);
  1123. for (ch = 0; ch < dma_chan_count; ch++) {
  1124. omap_clear_dma(ch);
  1125. if (dma_omap2plus())
  1126. omap2_disable_irq_lch(ch);
  1127. dma_chan[ch].dev_id = -1;
  1128. dma_chan[ch].next_lch = -1;
  1129. if (ch >= 6 && enable_1510_mode)
  1130. continue;
  1131. if (dma_omap1()) {
  1132. /*
  1133. * request_irq() doesn't like dev_id (ie. ch) being
  1134. * zero, so we have to kludge around this.
  1135. */
  1136. sprintf(&irq_name[0], "%d", ch);
  1137. dma_irq = platform_get_irq_byname(pdev, irq_name);
  1138. if (dma_irq < 0) {
  1139. ret = dma_irq;
  1140. goto exit_dma_irq_fail;
  1141. }
  1142. /* INT_DMA_LCD is handled in lcd_dma.c */
  1143. if (dma_irq == INT_DMA_LCD)
  1144. continue;
  1145. ret = request_irq(dma_irq,
  1146. omap1_dma_irq_handler, 0, "DMA",
  1147. (void *) (ch + 1));
  1148. if (ret != 0)
  1149. goto exit_dma_irq_fail;
  1150. }
  1151. }
  1152. if (d->dev_caps & IS_RW_PRIORITY)
  1153. omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE,
  1154. DMA_DEFAULT_FIFO_DEPTH, 0);
  1155. if (dma_omap2plus() && !(d->dev_caps & DMA_ENGINE_HANDLE_IRQ)) {
  1156. strcpy(irq_name, "0");
  1157. dma_irq = platform_get_irq_byname(pdev, irq_name);
  1158. if (dma_irq < 0) {
  1159. dev_err(&pdev->dev, "failed: request IRQ %d", dma_irq);
  1160. ret = dma_irq;
  1161. goto exit_dma_lch_fail;
  1162. }
  1163. ret = setup_irq(dma_irq, &omap24xx_dma_irq);
  1164. if (ret) {
  1165. dev_err(&pdev->dev, "set_up failed for IRQ %d for DMA (error %d)\n",
  1166. dma_irq, ret);
  1167. goto exit_dma_lch_fail;
  1168. }
  1169. }
  1170. /* reserve dma channels 0 and 1 in high security devices on 34xx */
  1171. if (d->dev_caps & HS_CHANNELS_RESERVED) {
  1172. pr_info("Reserving DMA channels 0 and 1 for HS ROM code\n");
  1173. dma_chan[0].dev_id = 0;
  1174. dma_chan[1].dev_id = 1;
  1175. }
  1176. p->show_dma_caps();
  1177. return 0;
  1178. exit_dma_irq_fail:
  1179. dev_err(&pdev->dev, "unable to request IRQ %d for DMA (error %d)\n",
  1180. dma_irq, ret);
  1181. for (irq_rel = 0; irq_rel < ch; irq_rel++) {
  1182. dma_irq = platform_get_irq(pdev, irq_rel);
  1183. free_irq(dma_irq, (void *)(irq_rel + 1));
  1184. }
  1185. exit_dma_lch_fail:
  1186. return ret;
  1187. }
  1188. static int omap_system_dma_remove(struct platform_device *pdev)
  1189. {
  1190. int dma_irq;
  1191. if (dma_omap2plus()) {
  1192. char irq_name[4];
  1193. strcpy(irq_name, "0");
  1194. dma_irq = platform_get_irq_byname(pdev, irq_name);
  1195. if (dma_irq >= 0)
  1196. remove_irq(dma_irq, &omap24xx_dma_irq);
  1197. } else {
  1198. int irq_rel = 0;
  1199. for ( ; irq_rel < dma_chan_count; irq_rel++) {
  1200. dma_irq = platform_get_irq(pdev, irq_rel);
  1201. free_irq(dma_irq, (void *)(irq_rel + 1));
  1202. }
  1203. }
  1204. return 0;
  1205. }
  1206. static struct platform_driver omap_system_dma_driver = {
  1207. .probe = omap_system_dma_probe,
  1208. .remove = omap_system_dma_remove,
  1209. .driver = {
  1210. .name = "omap_dma_system"
  1211. },
  1212. };
  1213. static int __init omap_system_dma_init(void)
  1214. {
  1215. return platform_driver_register(&omap_system_dma_driver);
  1216. }
  1217. arch_initcall(omap_system_dma_init);
  1218. static void __exit omap_system_dma_exit(void)
  1219. {
  1220. platform_driver_unregister(&omap_system_dma_driver);
  1221. }
  1222. MODULE_DESCRIPTION("OMAP SYSTEM DMA DRIVER");
  1223. MODULE_LICENSE("GPL");
  1224. MODULE_ALIAS("platform:" DRIVER_NAME);
  1225. MODULE_AUTHOR("Texas Instruments Inc");
  1226. /*
  1227. * Reserve the omap SDMA channels using cmdline bootarg
  1228. * "omap_dma_reserve_ch=". The valid range is 1 to 32
  1229. */
  1230. static int __init omap_dma_cmdline_reserve_ch(char *str)
  1231. {
  1232. if (get_option(&str, &omap_dma_reserve_channels) != 1)
  1233. omap_dma_reserve_channels = 0;
  1234. return 1;
  1235. }
  1236. __setup("omap_dma_reserve_ch=", omap_dma_cmdline_reserve_ch);