dma.c 34 KB

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