dma.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429
  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. * Support functions for the OMAP internal DMA channels.
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License version 2 as
  17. * published by the Free Software Foundation.
  18. *
  19. */
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/sched.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/errno.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/irq.h>
  27. #include <linux/io.h>
  28. #include <asm/system.h>
  29. #include <mach/hardware.h>
  30. #include <asm/dma.h>
  31. #include <mach/tc.h>
  32. #undef DEBUG
  33. #ifndef CONFIG_ARCH_OMAP1
  34. enum { DMA_CH_ALLOC_DONE, DMA_CH_PARAMS_SET_DONE, DMA_CH_STARTED,
  35. DMA_CH_QUEUED, DMA_CH_NOTSTARTED, DMA_CH_PAUSED, DMA_CH_LINK_ENABLED
  36. };
  37. enum { DMA_CHAIN_STARTED, DMA_CHAIN_NOTSTARTED };
  38. #endif
  39. #define OMAP_DMA_ACTIVE 0x01
  40. #define OMAP_DMA_CCR_EN (1 << 7)
  41. #define OMAP2_DMA_CSR_CLEAR_MASK 0xffe
  42. #define OMAP_FUNC_MUX_ARM_BASE (0xfffe1000 + 0xec)
  43. static int enable_1510_mode;
  44. struct omap_dma_lch {
  45. int next_lch;
  46. int dev_id;
  47. u16 saved_csr;
  48. u16 enabled_irqs;
  49. const char *dev_name;
  50. void (*callback)(int lch, u16 ch_status, void *data);
  51. void *data;
  52. #ifndef CONFIG_ARCH_OMAP1
  53. /* required for Dynamic chaining */
  54. int prev_linked_ch;
  55. int next_linked_ch;
  56. int state;
  57. int chain_id;
  58. int status;
  59. #endif
  60. long flags;
  61. };
  62. struct dma_link_info {
  63. int *linked_dmach_q;
  64. int no_of_lchs_linked;
  65. int q_count;
  66. int q_tail;
  67. int q_head;
  68. int chain_state;
  69. int chain_mode;
  70. };
  71. static struct dma_link_info *dma_linked_lch;
  72. #ifndef CONFIG_ARCH_OMAP1
  73. /* Chain handling macros */
  74. #define OMAP_DMA_CHAIN_QINIT(chain_id) \
  75. do { \
  76. dma_linked_lch[chain_id].q_head = \
  77. dma_linked_lch[chain_id].q_tail = \
  78. dma_linked_lch[chain_id].q_count = 0; \
  79. } while (0)
  80. #define OMAP_DMA_CHAIN_QFULL(chain_id) \
  81. (dma_linked_lch[chain_id].no_of_lchs_linked == \
  82. dma_linked_lch[chain_id].q_count)
  83. #define OMAP_DMA_CHAIN_QLAST(chain_id) \
  84. do { \
  85. ((dma_linked_lch[chain_id].no_of_lchs_linked-1) == \
  86. dma_linked_lch[chain_id].q_count) \
  87. } while (0)
  88. #define OMAP_DMA_CHAIN_QEMPTY(chain_id) \
  89. (0 == dma_linked_lch[chain_id].q_count)
  90. #define __OMAP_DMA_CHAIN_INCQ(end) \
  91. ((end) = ((end)+1) % dma_linked_lch[chain_id].no_of_lchs_linked)
  92. #define OMAP_DMA_CHAIN_INCQHEAD(chain_id) \
  93. do { \
  94. __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_head); \
  95. dma_linked_lch[chain_id].q_count--; \
  96. } while (0)
  97. #define OMAP_DMA_CHAIN_INCQTAIL(chain_id) \
  98. do { \
  99. __OMAP_DMA_CHAIN_INCQ(dma_linked_lch[chain_id].q_tail); \
  100. dma_linked_lch[chain_id].q_count++; \
  101. } while (0)
  102. #endif
  103. static int dma_lch_count;
  104. static int dma_chan_count;
  105. static spinlock_t dma_chan_lock;
  106. static struct omap_dma_lch *dma_chan;
  107. static void __iomem *omap_dma_base;
  108. static const u8 omap1_dma_irq[OMAP1_LOGICAL_DMA_CH_COUNT] = {
  109. INT_DMA_CH0_6, INT_DMA_CH1_7, INT_DMA_CH2_8, INT_DMA_CH3,
  110. INT_DMA_CH4, INT_DMA_CH5, INT_1610_DMA_CH6, INT_1610_DMA_CH7,
  111. INT_1610_DMA_CH8, INT_1610_DMA_CH9, INT_1610_DMA_CH10,
  112. INT_1610_DMA_CH11, INT_1610_DMA_CH12, INT_1610_DMA_CH13,
  113. INT_1610_DMA_CH14, INT_1610_DMA_CH15, INT_DMA_LCD
  114. };
  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. #define dma_read(reg) \
  121. ({ \
  122. u32 __val; \
  123. if (cpu_class_is_omap1()) \
  124. __val = __raw_readw(omap_dma_base + OMAP1_DMA_##reg); \
  125. else \
  126. __val = __raw_readl(omap_dma_base + OMAP_DMA4_##reg); \
  127. __val; \
  128. })
  129. #define dma_write(val, reg) \
  130. ({ \
  131. if (cpu_class_is_omap1()) \
  132. __raw_writew((u16)(val), omap_dma_base + OMAP1_DMA_##reg); \
  133. else \
  134. __raw_writel((val), omap_dma_base + OMAP_DMA4_##reg); \
  135. })
  136. #ifdef CONFIG_ARCH_OMAP15XX
  137. /* Returns 1 if the DMA module is in OMAP1510-compatible mode, 0 otherwise */
  138. int omap_dma_in_1510_mode(void)
  139. {
  140. return enable_1510_mode;
  141. }
  142. #else
  143. #define omap_dma_in_1510_mode() 0
  144. #endif
  145. #ifdef CONFIG_ARCH_OMAP1
  146. static inline int get_gdma_dev(int req)
  147. {
  148. u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4;
  149. int shift = ((req - 1) % 5) * 6;
  150. return ((omap_readl(reg) >> shift) & 0x3f) + 1;
  151. }
  152. static inline void set_gdma_dev(int req, int dev)
  153. {
  154. u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4;
  155. int shift = ((req - 1) % 5) * 6;
  156. u32 l;
  157. l = omap_readl(reg);
  158. l &= ~(0x3f << shift);
  159. l |= (dev - 1) << shift;
  160. omap_writel(l, reg);
  161. }
  162. #else
  163. #define set_gdma_dev(req, dev) do {} while (0)
  164. #endif
  165. /* Omap1 only */
  166. static void clear_lch_regs(int lch)
  167. {
  168. int i;
  169. void __iomem *lch_base = omap_dma_base + OMAP1_DMA_CH_BASE(lch);
  170. for (i = 0; i < 0x2c; i += 2)
  171. __raw_writew(0, lch_base + i);
  172. }
  173. void omap_set_dma_priority(int lch, int dst_port, int priority)
  174. {
  175. unsigned long reg;
  176. u32 l;
  177. if (cpu_class_is_omap1()) {
  178. switch (dst_port) {
  179. case OMAP_DMA_PORT_OCP_T1: /* FFFECC00 */
  180. reg = OMAP_TC_OCPT1_PRIOR;
  181. break;
  182. case OMAP_DMA_PORT_OCP_T2: /* FFFECCD0 */
  183. reg = OMAP_TC_OCPT2_PRIOR;
  184. break;
  185. case OMAP_DMA_PORT_EMIFF: /* FFFECC08 */
  186. reg = OMAP_TC_EMIFF_PRIOR;
  187. break;
  188. case OMAP_DMA_PORT_EMIFS: /* FFFECC04 */
  189. reg = OMAP_TC_EMIFS_PRIOR;
  190. break;
  191. default:
  192. BUG();
  193. return;
  194. }
  195. l = omap_readl(reg);
  196. l &= ~(0xf << 8);
  197. l |= (priority & 0xf) << 8;
  198. omap_writel(l, reg);
  199. }
  200. if (cpu_class_is_omap2()) {
  201. u32 ccr;
  202. ccr = dma_read(CCR(lch));
  203. if (priority)
  204. ccr |= (1 << 6);
  205. else
  206. ccr &= ~(1 << 6);
  207. dma_write(ccr, CCR(lch));
  208. }
  209. }
  210. EXPORT_SYMBOL(omap_set_dma_priority);
  211. void omap_set_dma_transfer_params(int lch, int data_type, int elem_count,
  212. int frame_count, int sync_mode,
  213. int dma_trigger, int src_or_dst_synch)
  214. {
  215. u32 l;
  216. l = dma_read(CSDP(lch));
  217. l &= ~0x03;
  218. l |= data_type;
  219. dma_write(l, CSDP(lch));
  220. if (cpu_class_is_omap1()) {
  221. u16 ccr;
  222. ccr = dma_read(CCR(lch));
  223. ccr &= ~(1 << 5);
  224. if (sync_mode == OMAP_DMA_SYNC_FRAME)
  225. ccr |= 1 << 5;
  226. dma_write(ccr, CCR(lch));
  227. ccr = dma_read(CCR2(lch));
  228. ccr &= ~(1 << 2);
  229. if (sync_mode == OMAP_DMA_SYNC_BLOCK)
  230. ccr |= 1 << 2;
  231. dma_write(ccr, CCR2(lch));
  232. }
  233. if (cpu_class_is_omap2() && dma_trigger) {
  234. u32 val;
  235. val = dma_read(CCR(lch));
  236. val &= ~(3 << 19);
  237. if (dma_trigger > 63)
  238. val |= 1 << 20;
  239. if (dma_trigger > 31)
  240. val |= 1 << 19;
  241. val &= ~(0x1f);
  242. val |= (dma_trigger & 0x1f);
  243. if (sync_mode & OMAP_DMA_SYNC_FRAME)
  244. val |= 1 << 5;
  245. else
  246. val &= ~(1 << 5);
  247. if (sync_mode & OMAP_DMA_SYNC_BLOCK)
  248. val |= 1 << 18;
  249. else
  250. val &= ~(1 << 18);
  251. if (src_or_dst_synch)
  252. val |= 1 << 24; /* source synch */
  253. else
  254. val &= ~(1 << 24); /* dest synch */
  255. dma_write(val, CCR(lch));
  256. }
  257. dma_write(elem_count, CEN(lch));
  258. dma_write(frame_count, CFN(lch));
  259. }
  260. EXPORT_SYMBOL(omap_set_dma_transfer_params);
  261. void omap_set_dma_color_mode(int lch, enum omap_dma_color_mode mode, u32 color)
  262. {
  263. u16 w;
  264. BUG_ON(omap_dma_in_1510_mode());
  265. if (cpu_class_is_omap2()) {
  266. REVISIT_24XX();
  267. return;
  268. }
  269. w = dma_read(CCR2(lch));
  270. w &= ~0x03;
  271. switch (mode) {
  272. case OMAP_DMA_CONSTANT_FILL:
  273. w |= 0x01;
  274. break;
  275. case OMAP_DMA_TRANSPARENT_COPY:
  276. w |= 0x02;
  277. break;
  278. case OMAP_DMA_COLOR_DIS:
  279. break;
  280. default:
  281. BUG();
  282. }
  283. dma_write(w, CCR2(lch));
  284. w = dma_read(LCH_CTRL(lch));
  285. w &= ~0x0f;
  286. /* Default is channel type 2D */
  287. if (mode) {
  288. dma_write((u16)color, COLOR_L(lch));
  289. dma_write((u16)(color >> 16), COLOR_U(lch));
  290. w |= 1; /* Channel type G */
  291. }
  292. dma_write(w, LCH_CTRL(lch));
  293. }
  294. EXPORT_SYMBOL(omap_set_dma_color_mode);
  295. void omap_set_dma_write_mode(int lch, enum omap_dma_write_mode mode)
  296. {
  297. if (cpu_class_is_omap2()) {
  298. u32 csdp;
  299. csdp = dma_read(CSDP(lch));
  300. csdp &= ~(0x3 << 16);
  301. csdp |= (mode << 16);
  302. dma_write(csdp, CSDP(lch));
  303. }
  304. }
  305. EXPORT_SYMBOL(omap_set_dma_write_mode);
  306. void omap_set_dma_channel_mode(int lch, enum omap_dma_channel_mode mode)
  307. {
  308. if (cpu_class_is_omap1() && !cpu_is_omap15xx()) {
  309. u32 l;
  310. l = dma_read(LCH_CTRL(lch));
  311. l &= ~0x7;
  312. l |= mode;
  313. dma_write(l, LCH_CTRL(lch));
  314. }
  315. }
  316. EXPORT_SYMBOL(omap_set_dma_channel_mode);
  317. /* Note that src_port is only for omap1 */
  318. void omap_set_dma_src_params(int lch, int src_port, int src_amode,
  319. unsigned long src_start,
  320. int src_ei, int src_fi)
  321. {
  322. u32 l;
  323. if (cpu_class_is_omap1()) {
  324. u16 w;
  325. w = dma_read(CSDP(lch));
  326. w &= ~(0x1f << 2);
  327. w |= src_port << 2;
  328. dma_write(w, CSDP(lch));
  329. }
  330. l = dma_read(CCR(lch));
  331. l &= ~(0x03 << 12);
  332. l |= src_amode << 12;
  333. dma_write(l, CCR(lch));
  334. if (cpu_class_is_omap1()) {
  335. dma_write(src_start >> 16, CSSA_U(lch));
  336. dma_write((u16)src_start, CSSA_L(lch));
  337. }
  338. if (cpu_class_is_omap2())
  339. dma_write(src_start, CSSA(lch));
  340. dma_write(src_ei, CSEI(lch));
  341. dma_write(src_fi, CSFI(lch));
  342. }
  343. EXPORT_SYMBOL(omap_set_dma_src_params);
  344. void omap_set_dma_params(int lch, struct omap_dma_channel_params *params)
  345. {
  346. omap_set_dma_transfer_params(lch, params->data_type,
  347. params->elem_count, params->frame_count,
  348. params->sync_mode, params->trigger,
  349. params->src_or_dst_synch);
  350. omap_set_dma_src_params(lch, params->src_port,
  351. params->src_amode, params->src_start,
  352. params->src_ei, params->src_fi);
  353. omap_set_dma_dest_params(lch, params->dst_port,
  354. params->dst_amode, params->dst_start,
  355. params->dst_ei, params->dst_fi);
  356. if (params->read_prio || params->write_prio)
  357. omap_dma_set_prio_lch(lch, params->read_prio,
  358. params->write_prio);
  359. }
  360. EXPORT_SYMBOL(omap_set_dma_params);
  361. void omap_set_dma_src_index(int lch, int eidx, int fidx)
  362. {
  363. if (cpu_class_is_omap2())
  364. return;
  365. dma_write(eidx, CSEI(lch));
  366. dma_write(fidx, CSFI(lch));
  367. }
  368. EXPORT_SYMBOL(omap_set_dma_src_index);
  369. void omap_set_dma_src_data_pack(int lch, int enable)
  370. {
  371. u32 l;
  372. l = dma_read(CSDP(lch));
  373. l &= ~(1 << 6);
  374. if (enable)
  375. l |= (1 << 6);
  376. dma_write(l, CSDP(lch));
  377. }
  378. EXPORT_SYMBOL(omap_set_dma_src_data_pack);
  379. void omap_set_dma_src_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
  380. {
  381. unsigned int burst = 0;
  382. u32 l;
  383. l = dma_read(CSDP(lch));
  384. l &= ~(0x03 << 7);
  385. switch (burst_mode) {
  386. case OMAP_DMA_DATA_BURST_DIS:
  387. break;
  388. case OMAP_DMA_DATA_BURST_4:
  389. if (cpu_class_is_omap2())
  390. burst = 0x1;
  391. else
  392. burst = 0x2;
  393. break;
  394. case OMAP_DMA_DATA_BURST_8:
  395. if (cpu_class_is_omap2()) {
  396. burst = 0x2;
  397. break;
  398. }
  399. /* not supported by current hardware on OMAP1
  400. * w |= (0x03 << 7);
  401. * fall through
  402. */
  403. case OMAP_DMA_DATA_BURST_16:
  404. if (cpu_class_is_omap2()) {
  405. burst = 0x3;
  406. break;
  407. }
  408. /* OMAP1 don't support burst 16
  409. * fall through
  410. */
  411. default:
  412. BUG();
  413. }
  414. l |= (burst << 7);
  415. dma_write(l, CSDP(lch));
  416. }
  417. EXPORT_SYMBOL(omap_set_dma_src_burst_mode);
  418. /* Note that dest_port is only for OMAP1 */
  419. void omap_set_dma_dest_params(int lch, int dest_port, int dest_amode,
  420. unsigned long dest_start,
  421. int dst_ei, int dst_fi)
  422. {
  423. u32 l;
  424. if (cpu_class_is_omap1()) {
  425. l = dma_read(CSDP(lch));
  426. l &= ~(0x1f << 9);
  427. l |= dest_port << 9;
  428. dma_write(l, CSDP(lch));
  429. }
  430. l = dma_read(CCR(lch));
  431. l &= ~(0x03 << 14);
  432. l |= dest_amode << 14;
  433. dma_write(l, CCR(lch));
  434. if (cpu_class_is_omap1()) {
  435. dma_write(dest_start >> 16, CDSA_U(lch));
  436. dma_write(dest_start, CDSA_L(lch));
  437. }
  438. if (cpu_class_is_omap2())
  439. dma_write(dest_start, CDSA(lch));
  440. dma_write(dst_ei, CDEI(lch));
  441. dma_write(dst_fi, CDFI(lch));
  442. }
  443. EXPORT_SYMBOL(omap_set_dma_dest_params);
  444. void omap_set_dma_dest_index(int lch, int eidx, int fidx)
  445. {
  446. if (cpu_class_is_omap2())
  447. return;
  448. dma_write(eidx, CDEI(lch));
  449. dma_write(fidx, CDFI(lch));
  450. }
  451. EXPORT_SYMBOL(omap_set_dma_dest_index);
  452. void omap_set_dma_dest_data_pack(int lch, int enable)
  453. {
  454. u32 l;
  455. l = dma_read(CSDP(lch));
  456. l &= ~(1 << 13);
  457. if (enable)
  458. l |= 1 << 13;
  459. dma_write(l, CSDP(lch));
  460. }
  461. EXPORT_SYMBOL(omap_set_dma_dest_data_pack);
  462. void omap_set_dma_dest_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
  463. {
  464. unsigned int burst = 0;
  465. u32 l;
  466. l = dma_read(CSDP(lch));
  467. l &= ~(0x03 << 14);
  468. switch (burst_mode) {
  469. case OMAP_DMA_DATA_BURST_DIS:
  470. break;
  471. case OMAP_DMA_DATA_BURST_4:
  472. if (cpu_class_is_omap2())
  473. burst = 0x1;
  474. else
  475. burst = 0x2;
  476. break;
  477. case OMAP_DMA_DATA_BURST_8:
  478. if (cpu_class_is_omap2())
  479. burst = 0x2;
  480. else
  481. burst = 0x3;
  482. break;
  483. case OMAP_DMA_DATA_BURST_16:
  484. if (cpu_class_is_omap2()) {
  485. burst = 0x3;
  486. break;
  487. }
  488. /* OMAP1 don't support burst 16
  489. * fall through
  490. */
  491. default:
  492. printk(KERN_ERR "Invalid DMA burst mode\n");
  493. BUG();
  494. return;
  495. }
  496. l |= (burst << 14);
  497. dma_write(l, CSDP(lch));
  498. }
  499. EXPORT_SYMBOL(omap_set_dma_dest_burst_mode);
  500. static inline void omap_enable_channel_irq(int lch)
  501. {
  502. u32 status;
  503. /* Clear CSR */
  504. if (cpu_class_is_omap1())
  505. status = dma_read(CSR(lch));
  506. else if (cpu_class_is_omap2())
  507. dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(lch));
  508. /* Enable some nice interrupts. */
  509. dma_write(dma_chan[lch].enabled_irqs, CICR(lch));
  510. }
  511. static void omap_disable_channel_irq(int lch)
  512. {
  513. if (cpu_class_is_omap2())
  514. dma_write(0, CICR(lch));
  515. }
  516. void omap_enable_dma_irq(int lch, u16 bits)
  517. {
  518. dma_chan[lch].enabled_irqs |= bits;
  519. }
  520. EXPORT_SYMBOL(omap_enable_dma_irq);
  521. void omap_disable_dma_irq(int lch, u16 bits)
  522. {
  523. dma_chan[lch].enabled_irqs &= ~bits;
  524. }
  525. EXPORT_SYMBOL(omap_disable_dma_irq);
  526. static inline void enable_lnk(int lch)
  527. {
  528. u32 l;
  529. l = dma_read(CLNK_CTRL(lch));
  530. if (cpu_class_is_omap1())
  531. l &= ~(1 << 14);
  532. /* Set the ENABLE_LNK bits */
  533. if (dma_chan[lch].next_lch != -1)
  534. l = dma_chan[lch].next_lch | (1 << 15);
  535. #ifndef CONFIG_ARCH_OMAP1
  536. if (cpu_class_is_omap2())
  537. if (dma_chan[lch].next_linked_ch != -1)
  538. l = dma_chan[lch].next_linked_ch | (1 << 15);
  539. #endif
  540. dma_write(l, CLNK_CTRL(lch));
  541. }
  542. static inline void disable_lnk(int lch)
  543. {
  544. u32 l;
  545. l = dma_read(CLNK_CTRL(lch));
  546. /* Disable interrupts */
  547. if (cpu_class_is_omap1()) {
  548. dma_write(0, CICR(lch));
  549. /* Set the STOP_LNK bit */
  550. l |= 1 << 14;
  551. }
  552. if (cpu_class_is_omap2()) {
  553. omap_disable_channel_irq(lch);
  554. /* Clear the ENABLE_LNK bit */
  555. l &= ~(1 << 15);
  556. }
  557. dma_write(l, CLNK_CTRL(lch));
  558. dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
  559. }
  560. static inline void omap2_enable_irq_lch(int lch)
  561. {
  562. u32 val;
  563. if (!cpu_class_is_omap2())
  564. return;
  565. val = dma_read(IRQENABLE_L0);
  566. val |= 1 << lch;
  567. dma_write(val, IRQENABLE_L0);
  568. }
  569. int omap_request_dma(int dev_id, const char *dev_name,
  570. void (*callback)(int lch, u16 ch_status, void *data),
  571. void *data, int *dma_ch_out)
  572. {
  573. int ch, free_ch = -1;
  574. unsigned long flags;
  575. struct omap_dma_lch *chan;
  576. spin_lock_irqsave(&dma_chan_lock, flags);
  577. for (ch = 0; ch < dma_chan_count; ch++) {
  578. if (free_ch == -1 && dma_chan[ch].dev_id == -1) {
  579. free_ch = ch;
  580. if (dev_id == 0)
  581. break;
  582. }
  583. }
  584. if (free_ch == -1) {
  585. spin_unlock_irqrestore(&dma_chan_lock, flags);
  586. return -EBUSY;
  587. }
  588. chan = dma_chan + free_ch;
  589. chan->dev_id = dev_id;
  590. if (cpu_class_is_omap1())
  591. clear_lch_regs(free_ch);
  592. if (cpu_class_is_omap2())
  593. omap_clear_dma(free_ch);
  594. spin_unlock_irqrestore(&dma_chan_lock, flags);
  595. chan->dev_name = dev_name;
  596. chan->callback = callback;
  597. chan->data = data;
  598. #ifndef CONFIG_ARCH_OMAP1
  599. if (cpu_class_is_omap2()) {
  600. chan->chain_id = -1;
  601. chan->next_linked_ch = -1;
  602. }
  603. #endif
  604. chan->enabled_irqs = OMAP_DMA_DROP_IRQ | OMAP_DMA_BLOCK_IRQ;
  605. if (cpu_class_is_omap1())
  606. chan->enabled_irqs |= OMAP1_DMA_TOUT_IRQ;
  607. else if (cpu_class_is_omap2())
  608. chan->enabled_irqs |= OMAP2_DMA_MISALIGNED_ERR_IRQ |
  609. OMAP2_DMA_TRANS_ERR_IRQ;
  610. if (cpu_is_omap16xx()) {
  611. /* If the sync device is set, configure it dynamically. */
  612. if (dev_id != 0) {
  613. set_gdma_dev(free_ch + 1, dev_id);
  614. dev_id = free_ch + 1;
  615. }
  616. /*
  617. * Disable the 1510 compatibility mode and set the sync device
  618. * id.
  619. */
  620. dma_write(dev_id | (1 << 10), CCR(free_ch));
  621. } else if (cpu_is_omap730() || cpu_is_omap15xx()) {
  622. dma_write(dev_id, CCR(free_ch));
  623. }
  624. if (cpu_class_is_omap2()) {
  625. omap2_enable_irq_lch(free_ch);
  626. omap_enable_channel_irq(free_ch);
  627. /* Clear the CSR register and IRQ status register */
  628. dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(free_ch));
  629. dma_write(1 << free_ch, IRQSTATUS_L0);
  630. }
  631. *dma_ch_out = free_ch;
  632. return 0;
  633. }
  634. EXPORT_SYMBOL(omap_request_dma);
  635. void omap_free_dma(int lch)
  636. {
  637. unsigned long flags;
  638. spin_lock_irqsave(&dma_chan_lock, flags);
  639. if (dma_chan[lch].dev_id == -1) {
  640. pr_err("omap_dma: trying to free unallocated DMA channel %d\n",
  641. lch);
  642. spin_unlock_irqrestore(&dma_chan_lock, flags);
  643. return;
  644. }
  645. dma_chan[lch].dev_id = -1;
  646. dma_chan[lch].next_lch = -1;
  647. dma_chan[lch].callback = NULL;
  648. spin_unlock_irqrestore(&dma_chan_lock, flags);
  649. if (cpu_class_is_omap1()) {
  650. /* Disable all DMA interrupts for the channel. */
  651. dma_write(0, CICR(lch));
  652. /* Make sure the DMA transfer is stopped. */
  653. dma_write(0, CCR(lch));
  654. }
  655. if (cpu_class_is_omap2()) {
  656. u32 val;
  657. /* Disable interrupts */
  658. val = dma_read(IRQENABLE_L0);
  659. val &= ~(1 << lch);
  660. dma_write(val, IRQENABLE_L0);
  661. /* Clear the CSR register and IRQ status register */
  662. dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(lch));
  663. dma_write(1 << lch, IRQSTATUS_L0);
  664. /* Disable all DMA interrupts for the channel. */
  665. dma_write(0, CICR(lch));
  666. /* Make sure the DMA transfer is stopped. */
  667. dma_write(0, CCR(lch));
  668. omap_clear_dma(lch);
  669. }
  670. }
  671. EXPORT_SYMBOL(omap_free_dma);
  672. /**
  673. * @brief omap_dma_set_global_params : Set global priority settings for dma
  674. *
  675. * @param arb_rate
  676. * @param max_fifo_depth
  677. * @param tparams - Number of thereads to reserve : DMA_THREAD_RESERVE_NORM
  678. * DMA_THREAD_RESERVE_ONET
  679. * DMA_THREAD_RESERVE_TWOT
  680. * DMA_THREAD_RESERVE_THREET
  681. */
  682. void
  683. omap_dma_set_global_params(int arb_rate, int max_fifo_depth, int tparams)
  684. {
  685. u32 reg;
  686. if (!cpu_class_is_omap2()) {
  687. printk(KERN_ERR "FIXME: no %s on 15xx/16xx\n", __func__);
  688. return;
  689. }
  690. if (arb_rate == 0)
  691. arb_rate = 1;
  692. reg = (arb_rate & 0xff) << 16;
  693. reg |= (0xff & max_fifo_depth);
  694. dma_write(reg, GCR);
  695. }
  696. EXPORT_SYMBOL(omap_dma_set_global_params);
  697. /**
  698. * @brief omap_dma_set_prio_lch : Set channel wise priority settings
  699. *
  700. * @param lch
  701. * @param read_prio - Read priority
  702. * @param write_prio - Write priority
  703. * Both of the above can be set with one of the following values :
  704. * DMA_CH_PRIO_HIGH/DMA_CH_PRIO_LOW
  705. */
  706. int
  707. omap_dma_set_prio_lch(int lch, unsigned char read_prio,
  708. unsigned char write_prio)
  709. {
  710. u32 l;
  711. if (unlikely((lch < 0 || lch >= dma_lch_count))) {
  712. printk(KERN_ERR "Invalid channel id\n");
  713. return -EINVAL;
  714. }
  715. l = dma_read(CCR(lch));
  716. l &= ~((1 << 6) | (1 << 26));
  717. if (cpu_is_omap2430() || cpu_is_omap34xx())
  718. l |= ((read_prio & 0x1) << 6) | ((write_prio & 0x1) << 26);
  719. else
  720. l |= ((read_prio & 0x1) << 6);
  721. dma_write(l, CCR(lch));
  722. return 0;
  723. }
  724. EXPORT_SYMBOL(omap_dma_set_prio_lch);
  725. /*
  726. * Clears any DMA state so the DMA engine is ready to restart with new buffers
  727. * through omap_start_dma(). Any buffers in flight are discarded.
  728. */
  729. void omap_clear_dma(int lch)
  730. {
  731. unsigned long flags;
  732. local_irq_save(flags);
  733. if (cpu_class_is_omap1()) {
  734. u32 l;
  735. l = dma_read(CCR(lch));
  736. l &= ~OMAP_DMA_CCR_EN;
  737. dma_write(l, CCR(lch));
  738. /* Clear pending interrupts */
  739. l = dma_read(CSR(lch));
  740. }
  741. if (cpu_class_is_omap2()) {
  742. int i;
  743. void __iomem *lch_base = omap_dma_base + OMAP_DMA4_CH_BASE(lch);
  744. for (i = 0; i < 0x44; i += 4)
  745. __raw_writel(0, lch_base + i);
  746. }
  747. local_irq_restore(flags);
  748. }
  749. EXPORT_SYMBOL(omap_clear_dma);
  750. void omap_start_dma(int lch)
  751. {
  752. u32 l;
  753. if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
  754. int next_lch, cur_lch;
  755. char dma_chan_link_map[OMAP_DMA4_LOGICAL_DMA_CH_COUNT];
  756. dma_chan_link_map[lch] = 1;
  757. /* Set the link register of the first channel */
  758. enable_lnk(lch);
  759. memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
  760. cur_lch = dma_chan[lch].next_lch;
  761. do {
  762. next_lch = dma_chan[cur_lch].next_lch;
  763. /* The loop case: we've been here already */
  764. if (dma_chan_link_map[cur_lch])
  765. break;
  766. /* Mark the current channel */
  767. dma_chan_link_map[cur_lch] = 1;
  768. enable_lnk(cur_lch);
  769. omap_enable_channel_irq(cur_lch);
  770. cur_lch = next_lch;
  771. } while (next_lch != -1);
  772. } else if (cpu_class_is_omap2()) {
  773. /* Errata: Need to write lch even if not using chaining */
  774. dma_write(lch, CLNK_CTRL(lch));
  775. }
  776. omap_enable_channel_irq(lch);
  777. l = dma_read(CCR(lch));
  778. /*
  779. * Errata: On ES2.0 BUFFERING disable must be set.
  780. * This will always fail on ES1.0
  781. */
  782. if (cpu_is_omap24xx())
  783. l |= OMAP_DMA_CCR_EN;
  784. l |= OMAP_DMA_CCR_EN;
  785. dma_write(l, CCR(lch));
  786. dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
  787. }
  788. EXPORT_SYMBOL(omap_start_dma);
  789. void omap_stop_dma(int lch)
  790. {
  791. u32 l;
  792. if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
  793. int next_lch, cur_lch = lch;
  794. char dma_chan_link_map[OMAP_DMA4_LOGICAL_DMA_CH_COUNT];
  795. memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
  796. do {
  797. /* The loop case: we've been here already */
  798. if (dma_chan_link_map[cur_lch])
  799. break;
  800. /* Mark the current channel */
  801. dma_chan_link_map[cur_lch] = 1;
  802. disable_lnk(cur_lch);
  803. next_lch = dma_chan[cur_lch].next_lch;
  804. cur_lch = next_lch;
  805. } while (next_lch != -1);
  806. return;
  807. }
  808. /* Disable all interrupts on the channel */
  809. if (cpu_class_is_omap1())
  810. dma_write(0, CICR(lch));
  811. l = dma_read(CCR(lch));
  812. l &= ~OMAP_DMA_CCR_EN;
  813. dma_write(l, CCR(lch));
  814. dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
  815. }
  816. EXPORT_SYMBOL(omap_stop_dma);
  817. /*
  818. * Allows changing the DMA callback function or data. This may be needed if
  819. * the driver shares a single DMA channel for multiple dma triggers.
  820. */
  821. int omap_set_dma_callback(int lch,
  822. void (*callback)(int lch, u16 ch_status, void *data),
  823. void *data)
  824. {
  825. unsigned long flags;
  826. if (lch < 0)
  827. return -ENODEV;
  828. spin_lock_irqsave(&dma_chan_lock, flags);
  829. if (dma_chan[lch].dev_id == -1) {
  830. printk(KERN_ERR "DMA callback for not set for free channel\n");
  831. spin_unlock_irqrestore(&dma_chan_lock, flags);
  832. return -EINVAL;
  833. }
  834. dma_chan[lch].callback = callback;
  835. dma_chan[lch].data = data;
  836. spin_unlock_irqrestore(&dma_chan_lock, flags);
  837. return 0;
  838. }
  839. EXPORT_SYMBOL(omap_set_dma_callback);
  840. /*
  841. * Returns current physical source address for the given DMA channel.
  842. * If the channel is running the caller must disable interrupts prior calling
  843. * this function and process the returned value before re-enabling interrupt to
  844. * prevent races with the interrupt handler. Note that in continuous mode there
  845. * is a chance for CSSA_L register overflow inbetween the two reads resulting
  846. * in incorrect return value.
  847. */
  848. dma_addr_t omap_get_dma_src_pos(int lch)
  849. {
  850. dma_addr_t offset = 0;
  851. if (cpu_is_omap15xx())
  852. offset = dma_read(CPC(lch));
  853. else
  854. offset = dma_read(CSAC(lch));
  855. /*
  856. * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
  857. * read before the DMA controller finished disabling the channel.
  858. */
  859. if (!cpu_is_omap15xx() && offset == 0)
  860. offset = dma_read(CSAC(lch));
  861. if (cpu_class_is_omap1())
  862. offset |= (dma_read(CSSA_U(lch)) << 16);
  863. return offset;
  864. }
  865. EXPORT_SYMBOL(omap_get_dma_src_pos);
  866. /*
  867. * Returns current physical destination address for the given DMA channel.
  868. * If the channel is running the caller must disable interrupts prior calling
  869. * this function and process the returned value before re-enabling interrupt to
  870. * prevent races with the interrupt handler. Note that in continuous mode there
  871. * is a chance for CDSA_L register overflow inbetween the two reads resulting
  872. * in incorrect return value.
  873. */
  874. dma_addr_t omap_get_dma_dst_pos(int lch)
  875. {
  876. dma_addr_t offset = 0;
  877. if (cpu_is_omap15xx())
  878. offset = dma_read(CPC(lch));
  879. else
  880. offset = dma_read(CDAC(lch));
  881. /*
  882. * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
  883. * read before the DMA controller finished disabling the channel.
  884. */
  885. if (!cpu_is_omap15xx() && offset == 0)
  886. offset = dma_read(CDAC(lch));
  887. if (cpu_class_is_omap1())
  888. offset |= (dma_read(CDSA_U(lch)) << 16);
  889. return offset;
  890. }
  891. EXPORT_SYMBOL(omap_get_dma_dst_pos);
  892. int omap_get_dma_active_status(int lch)
  893. {
  894. return (dma_read(CCR(lch)) & OMAP_DMA_CCR_EN) != 0;
  895. }
  896. EXPORT_SYMBOL(omap_get_dma_active_status);
  897. int omap_dma_running(void)
  898. {
  899. int lch;
  900. /* Check if LCD DMA is running */
  901. if (cpu_is_omap16xx())
  902. if (omap_readw(OMAP1610_DMA_LCD_CCR) & OMAP_DMA_CCR_EN)
  903. return 1;
  904. for (lch = 0; lch < dma_chan_count; lch++)
  905. if (dma_read(CCR(lch)) & OMAP_DMA_CCR_EN)
  906. return 1;
  907. return 0;
  908. }
  909. /*
  910. * lch_queue DMA will start right after lch_head one is finished.
  911. * For this DMA link to start, you still need to start (see omap_start_dma)
  912. * the first one. That will fire up the entire queue.
  913. */
  914. void omap_dma_link_lch(int lch_head, int lch_queue)
  915. {
  916. if (omap_dma_in_1510_mode()) {
  917. printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
  918. BUG();
  919. return;
  920. }
  921. if ((dma_chan[lch_head].dev_id == -1) ||
  922. (dma_chan[lch_queue].dev_id == -1)) {
  923. printk(KERN_ERR "omap_dma: trying to link "
  924. "non requested channels\n");
  925. dump_stack();
  926. }
  927. dma_chan[lch_head].next_lch = lch_queue;
  928. }
  929. EXPORT_SYMBOL(omap_dma_link_lch);
  930. /*
  931. * Once the DMA queue is stopped, we can destroy it.
  932. */
  933. void omap_dma_unlink_lch(int lch_head, int lch_queue)
  934. {
  935. if (omap_dma_in_1510_mode()) {
  936. printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
  937. BUG();
  938. return;
  939. }
  940. if (dma_chan[lch_head].next_lch != lch_queue ||
  941. dma_chan[lch_head].next_lch == -1) {
  942. printk(KERN_ERR "omap_dma: trying to unlink "
  943. "non linked channels\n");
  944. dump_stack();
  945. }
  946. if ((dma_chan[lch_head].flags & OMAP_DMA_ACTIVE) ||
  947. (dma_chan[lch_head].flags & OMAP_DMA_ACTIVE)) {
  948. printk(KERN_ERR "omap_dma: You need to stop the DMA channels "
  949. "before unlinking\n");
  950. dump_stack();
  951. }
  952. dma_chan[lch_head].next_lch = -1;
  953. }
  954. EXPORT_SYMBOL(omap_dma_unlink_lch);
  955. /*----------------------------------------------------------------------------*/
  956. #ifndef CONFIG_ARCH_OMAP1
  957. /* Create chain of DMA channesls */
  958. static void create_dma_lch_chain(int lch_head, int lch_queue)
  959. {
  960. u32 l;
  961. /* Check if this is the first link in chain */
  962. if (dma_chan[lch_head].next_linked_ch == -1) {
  963. dma_chan[lch_head].next_linked_ch = lch_queue;
  964. dma_chan[lch_head].prev_linked_ch = lch_queue;
  965. dma_chan[lch_queue].next_linked_ch = lch_head;
  966. dma_chan[lch_queue].prev_linked_ch = lch_head;
  967. }
  968. /* a link exists, link the new channel in circular chain */
  969. else {
  970. dma_chan[lch_queue].next_linked_ch =
  971. dma_chan[lch_head].next_linked_ch;
  972. dma_chan[lch_queue].prev_linked_ch = lch_head;
  973. dma_chan[lch_head].next_linked_ch = lch_queue;
  974. dma_chan[dma_chan[lch_queue].next_linked_ch].prev_linked_ch =
  975. lch_queue;
  976. }
  977. l = dma_read(CLNK_CTRL(lch_head));
  978. l &= ~(0x1f);
  979. l |= lch_queue;
  980. dma_write(l, CLNK_CTRL(lch_head));
  981. l = dma_read(CLNK_CTRL(lch_queue));
  982. l &= ~(0x1f);
  983. l |= (dma_chan[lch_queue].next_linked_ch);
  984. dma_write(l, CLNK_CTRL(lch_queue));
  985. }
  986. /**
  987. * @brief omap_request_dma_chain : Request a chain of DMA channels
  988. *
  989. * @param dev_id - Device id using the dma channel
  990. * @param dev_name - Device name
  991. * @param callback - Call back function
  992. * @chain_id -
  993. * @no_of_chans - Number of channels requested
  994. * @chain_mode - Dynamic or static chaining : OMAP_DMA_STATIC_CHAIN
  995. * OMAP_DMA_DYNAMIC_CHAIN
  996. * @params - Channel parameters
  997. *
  998. * @return - Succes : 0
  999. * Failure: -EINVAL/-ENOMEM
  1000. */
  1001. int omap_request_dma_chain(int dev_id, const char *dev_name,
  1002. void (*callback) (int chain_id, u16 ch_status,
  1003. void *data),
  1004. int *chain_id, int no_of_chans, int chain_mode,
  1005. struct omap_dma_channel_params params)
  1006. {
  1007. int *channels;
  1008. int i, err;
  1009. /* Is the chain mode valid ? */
  1010. if (chain_mode != OMAP_DMA_STATIC_CHAIN
  1011. && chain_mode != OMAP_DMA_DYNAMIC_CHAIN) {
  1012. printk(KERN_ERR "Invalid chain mode requested\n");
  1013. return -EINVAL;
  1014. }
  1015. if (unlikely((no_of_chans < 1
  1016. || no_of_chans > dma_lch_count))) {
  1017. printk(KERN_ERR "Invalid Number of channels requested\n");
  1018. return -EINVAL;
  1019. }
  1020. /* Allocate a queue to maintain the status of the channels
  1021. * in the chain */
  1022. channels = kmalloc(sizeof(*channels) * no_of_chans, GFP_KERNEL);
  1023. if (channels == NULL) {
  1024. printk(KERN_ERR "omap_dma: No memory for channel queue\n");
  1025. return -ENOMEM;
  1026. }
  1027. /* request and reserve DMA channels for the chain */
  1028. for (i = 0; i < no_of_chans; i++) {
  1029. err = omap_request_dma(dev_id, dev_name,
  1030. callback, 0, &channels[i]);
  1031. if (err < 0) {
  1032. int j;
  1033. for (j = 0; j < i; j++)
  1034. omap_free_dma(channels[j]);
  1035. kfree(channels);
  1036. printk(KERN_ERR "omap_dma: Request failed %d\n", err);
  1037. return err;
  1038. }
  1039. dma_chan[channels[i]].prev_linked_ch = -1;
  1040. dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
  1041. /*
  1042. * Allowing client drivers to set common parameters now,
  1043. * so that later only relevant (src_start, dest_start
  1044. * and element count) can be set
  1045. */
  1046. omap_set_dma_params(channels[i], &params);
  1047. }
  1048. *chain_id = channels[0];
  1049. dma_linked_lch[*chain_id].linked_dmach_q = channels;
  1050. dma_linked_lch[*chain_id].chain_mode = chain_mode;
  1051. dma_linked_lch[*chain_id].chain_state = DMA_CHAIN_NOTSTARTED;
  1052. dma_linked_lch[*chain_id].no_of_lchs_linked = no_of_chans;
  1053. for (i = 0; i < no_of_chans; i++)
  1054. dma_chan[channels[i]].chain_id = *chain_id;
  1055. /* Reset the Queue pointers */
  1056. OMAP_DMA_CHAIN_QINIT(*chain_id);
  1057. /* Set up the chain */
  1058. if (no_of_chans == 1)
  1059. create_dma_lch_chain(channels[0], channels[0]);
  1060. else {
  1061. for (i = 0; i < (no_of_chans - 1); i++)
  1062. create_dma_lch_chain(channels[i], channels[i + 1]);
  1063. }
  1064. return 0;
  1065. }
  1066. EXPORT_SYMBOL(omap_request_dma_chain);
  1067. /**
  1068. * @brief omap_modify_dma_chain_param : Modify the chain's params - Modify the
  1069. * params after setting it. Dont do this while dma is running!!
  1070. *
  1071. * @param chain_id - Chained logical channel id.
  1072. * @param params
  1073. *
  1074. * @return - Success : 0
  1075. * Failure : -EINVAL
  1076. */
  1077. int omap_modify_dma_chain_params(int chain_id,
  1078. struct omap_dma_channel_params params)
  1079. {
  1080. int *channels;
  1081. u32 i;
  1082. /* Check for input params */
  1083. if (unlikely((chain_id < 0
  1084. || chain_id >= dma_lch_count))) {
  1085. printk(KERN_ERR "Invalid chain id\n");
  1086. return -EINVAL;
  1087. }
  1088. /* Check if the chain exists */
  1089. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1090. printk(KERN_ERR "Chain doesn't exists\n");
  1091. return -EINVAL;
  1092. }
  1093. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1094. for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
  1095. /*
  1096. * Allowing client drivers to set common parameters now,
  1097. * so that later only relevant (src_start, dest_start
  1098. * and element count) can be set
  1099. */
  1100. omap_set_dma_params(channels[i], &params);
  1101. }
  1102. return 0;
  1103. }
  1104. EXPORT_SYMBOL(omap_modify_dma_chain_params);
  1105. /**
  1106. * @brief omap_free_dma_chain - Free all the logical channels in a chain.
  1107. *
  1108. * @param chain_id
  1109. *
  1110. * @return - Success : 0
  1111. * Failure : -EINVAL
  1112. */
  1113. int omap_free_dma_chain(int chain_id)
  1114. {
  1115. int *channels;
  1116. u32 i;
  1117. /* Check for input params */
  1118. if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
  1119. printk(KERN_ERR "Invalid chain id\n");
  1120. return -EINVAL;
  1121. }
  1122. /* Check if the chain exists */
  1123. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1124. printk(KERN_ERR "Chain doesn't exists\n");
  1125. return -EINVAL;
  1126. }
  1127. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1128. for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
  1129. dma_chan[channels[i]].next_linked_ch = -1;
  1130. dma_chan[channels[i]].prev_linked_ch = -1;
  1131. dma_chan[channels[i]].chain_id = -1;
  1132. dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
  1133. omap_free_dma(channels[i]);
  1134. }
  1135. kfree(channels);
  1136. dma_linked_lch[chain_id].linked_dmach_q = NULL;
  1137. dma_linked_lch[chain_id].chain_mode = -1;
  1138. dma_linked_lch[chain_id].chain_state = -1;
  1139. return (0);
  1140. }
  1141. EXPORT_SYMBOL(omap_free_dma_chain);
  1142. /**
  1143. * @brief omap_dma_chain_status - Check if the chain is in
  1144. * active / inactive state.
  1145. * @param chain_id
  1146. *
  1147. * @return - Success : OMAP_DMA_CHAIN_ACTIVE/OMAP_DMA_CHAIN_INACTIVE
  1148. * Failure : -EINVAL
  1149. */
  1150. int omap_dma_chain_status(int chain_id)
  1151. {
  1152. /* Check for input params */
  1153. if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
  1154. printk(KERN_ERR "Invalid chain id\n");
  1155. return -EINVAL;
  1156. }
  1157. /* Check if the chain exists */
  1158. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1159. printk(KERN_ERR "Chain doesn't exists\n");
  1160. return -EINVAL;
  1161. }
  1162. pr_debug("CHAINID=%d, qcnt=%d\n", chain_id,
  1163. dma_linked_lch[chain_id].q_count);
  1164. if (OMAP_DMA_CHAIN_QEMPTY(chain_id))
  1165. return OMAP_DMA_CHAIN_INACTIVE;
  1166. return OMAP_DMA_CHAIN_ACTIVE;
  1167. }
  1168. EXPORT_SYMBOL(omap_dma_chain_status);
  1169. /**
  1170. * @brief omap_dma_chain_a_transfer - Get a free channel from a chain,
  1171. * set the params and start the transfer.
  1172. *
  1173. * @param chain_id
  1174. * @param src_start - buffer start address
  1175. * @param dest_start - Dest address
  1176. * @param elem_count
  1177. * @param frame_count
  1178. * @param callbk_data - channel callback parameter data.
  1179. *
  1180. * @return - Success : 0
  1181. * Failure: -EINVAL/-EBUSY
  1182. */
  1183. int omap_dma_chain_a_transfer(int chain_id, int src_start, int dest_start,
  1184. int elem_count, int frame_count, void *callbk_data)
  1185. {
  1186. int *channels;
  1187. u32 l, lch;
  1188. int start_dma = 0;
  1189. /*
  1190. * if buffer size is less than 1 then there is
  1191. * no use of starting the chain
  1192. */
  1193. if (elem_count < 1) {
  1194. printk(KERN_ERR "Invalid buffer size\n");
  1195. return -EINVAL;
  1196. }
  1197. /* Check for input params */
  1198. if (unlikely((chain_id < 0
  1199. || chain_id >= dma_lch_count))) {
  1200. printk(KERN_ERR "Invalid chain id\n");
  1201. return -EINVAL;
  1202. }
  1203. /* Check if the chain exists */
  1204. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1205. printk(KERN_ERR "Chain doesn't exist\n");
  1206. return -EINVAL;
  1207. }
  1208. /* Check if all the channels in chain are in use */
  1209. if (OMAP_DMA_CHAIN_QFULL(chain_id))
  1210. return -EBUSY;
  1211. /* Frame count may be negative in case of indexed transfers */
  1212. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1213. /* Get a free channel */
  1214. lch = channels[dma_linked_lch[chain_id].q_tail];
  1215. /* Store the callback data */
  1216. dma_chan[lch].data = callbk_data;
  1217. /* Increment the q_tail */
  1218. OMAP_DMA_CHAIN_INCQTAIL(chain_id);
  1219. /* Set the params to the free channel */
  1220. if (src_start != 0)
  1221. dma_write(src_start, CSSA(lch));
  1222. if (dest_start != 0)
  1223. dma_write(dest_start, CDSA(lch));
  1224. /* Write the buffer size */
  1225. dma_write(elem_count, CEN(lch));
  1226. dma_write(frame_count, CFN(lch));
  1227. /*
  1228. * If the chain is dynamically linked,
  1229. * then we may have to start the chain if its not active
  1230. */
  1231. if (dma_linked_lch[chain_id].chain_mode == OMAP_DMA_DYNAMIC_CHAIN) {
  1232. /*
  1233. * In Dynamic chain, if the chain is not started,
  1234. * queue the channel
  1235. */
  1236. if (dma_linked_lch[chain_id].chain_state ==
  1237. DMA_CHAIN_NOTSTARTED) {
  1238. /* Enable the link in previous channel */
  1239. if (dma_chan[dma_chan[lch].prev_linked_ch].state ==
  1240. DMA_CH_QUEUED)
  1241. enable_lnk(dma_chan[lch].prev_linked_ch);
  1242. dma_chan[lch].state = DMA_CH_QUEUED;
  1243. }
  1244. /*
  1245. * Chain is already started, make sure its active,
  1246. * if not then start the chain
  1247. */
  1248. else {
  1249. start_dma = 1;
  1250. if (dma_chan[dma_chan[lch].prev_linked_ch].state ==
  1251. DMA_CH_STARTED) {
  1252. enable_lnk(dma_chan[lch].prev_linked_ch);
  1253. dma_chan[lch].state = DMA_CH_QUEUED;
  1254. start_dma = 0;
  1255. if (0 == ((1 << 7) & dma_read(
  1256. CCR(dma_chan[lch].prev_linked_ch)))) {
  1257. disable_lnk(dma_chan[lch].
  1258. prev_linked_ch);
  1259. pr_debug("\n prev ch is stopped\n");
  1260. start_dma = 1;
  1261. }
  1262. }
  1263. else if (dma_chan[dma_chan[lch].prev_linked_ch].state
  1264. == DMA_CH_QUEUED) {
  1265. enable_lnk(dma_chan[lch].prev_linked_ch);
  1266. dma_chan[lch].state = DMA_CH_QUEUED;
  1267. start_dma = 0;
  1268. }
  1269. omap_enable_channel_irq(lch);
  1270. l = dma_read(CCR(lch));
  1271. if ((0 == (l & (1 << 24))))
  1272. l &= ~(1 << 25);
  1273. else
  1274. l |= (1 << 25);
  1275. if (start_dma == 1) {
  1276. if (0 == (l & (1 << 7))) {
  1277. l |= (1 << 7);
  1278. dma_chan[lch].state = DMA_CH_STARTED;
  1279. pr_debug("starting %d\n", lch);
  1280. dma_write(l, CCR(lch));
  1281. } else
  1282. start_dma = 0;
  1283. } else {
  1284. if (0 == (l & (1 << 7)))
  1285. dma_write(l, CCR(lch));
  1286. }
  1287. dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
  1288. }
  1289. }
  1290. return 0;
  1291. }
  1292. EXPORT_SYMBOL(omap_dma_chain_a_transfer);
  1293. /**
  1294. * @brief omap_start_dma_chain_transfers - Start the chain
  1295. *
  1296. * @param chain_id
  1297. *
  1298. * @return - Success : 0
  1299. * Failure : -EINVAL/-EBUSY
  1300. */
  1301. int omap_start_dma_chain_transfers(int chain_id)
  1302. {
  1303. int *channels;
  1304. u32 l, i;
  1305. if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
  1306. printk(KERN_ERR "Invalid chain id\n");
  1307. return -EINVAL;
  1308. }
  1309. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1310. if (dma_linked_lch[channels[0]].chain_state == DMA_CHAIN_STARTED) {
  1311. printk(KERN_ERR "Chain is already started\n");
  1312. return -EBUSY;
  1313. }
  1314. if (dma_linked_lch[chain_id].chain_mode == OMAP_DMA_STATIC_CHAIN) {
  1315. for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked;
  1316. i++) {
  1317. enable_lnk(channels[i]);
  1318. omap_enable_channel_irq(channels[i]);
  1319. }
  1320. } else {
  1321. omap_enable_channel_irq(channels[0]);
  1322. }
  1323. l = dma_read(CCR(channels[0]));
  1324. l |= (1 << 7);
  1325. dma_linked_lch[chain_id].chain_state = DMA_CHAIN_STARTED;
  1326. dma_chan[channels[0]].state = DMA_CH_STARTED;
  1327. if ((0 == (l & (1 << 24))))
  1328. l &= ~(1 << 25);
  1329. else
  1330. l |= (1 << 25);
  1331. dma_write(l, CCR(channels[0]));
  1332. dma_chan[channels[0]].flags |= OMAP_DMA_ACTIVE;
  1333. return 0;
  1334. }
  1335. EXPORT_SYMBOL(omap_start_dma_chain_transfers);
  1336. /**
  1337. * @brief omap_stop_dma_chain_transfers - Stop the dma transfer of a chain.
  1338. *
  1339. * @param chain_id
  1340. *
  1341. * @return - Success : 0
  1342. * Failure : EINVAL
  1343. */
  1344. int omap_stop_dma_chain_transfers(int chain_id)
  1345. {
  1346. int *channels;
  1347. u32 l, i;
  1348. u32 sys_cf;
  1349. /* Check for input params */
  1350. if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
  1351. printk(KERN_ERR "Invalid chain id\n");
  1352. return -EINVAL;
  1353. }
  1354. /* Check if the chain exists */
  1355. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1356. printk(KERN_ERR "Chain doesn't exists\n");
  1357. return -EINVAL;
  1358. }
  1359. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1360. /*
  1361. * DMA Errata:
  1362. * Special programming model needed to disable DMA before end of block
  1363. */
  1364. sys_cf = dma_read(OCP_SYSCONFIG);
  1365. l = sys_cf;
  1366. /* Middle mode reg set no Standby */
  1367. l &= ~((1 << 12)|(1 << 13));
  1368. dma_write(l, OCP_SYSCONFIG);
  1369. for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
  1370. /* Stop the Channel transmission */
  1371. l = dma_read(CCR(channels[i]));
  1372. l &= ~(1 << 7);
  1373. dma_write(l, CCR(channels[i]));
  1374. /* Disable the link in all the channels */
  1375. disable_lnk(channels[i]);
  1376. dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
  1377. }
  1378. dma_linked_lch[chain_id].chain_state = DMA_CHAIN_NOTSTARTED;
  1379. /* Reset the Queue pointers */
  1380. OMAP_DMA_CHAIN_QINIT(chain_id);
  1381. /* Errata - put in the old value */
  1382. dma_write(sys_cf, OCP_SYSCONFIG);
  1383. return 0;
  1384. }
  1385. EXPORT_SYMBOL(omap_stop_dma_chain_transfers);
  1386. /* Get the index of the ongoing DMA in chain */
  1387. /**
  1388. * @brief omap_get_dma_chain_index - Get the element and frame index
  1389. * of the ongoing DMA in chain
  1390. *
  1391. * @param chain_id
  1392. * @param ei - Element index
  1393. * @param fi - Frame index
  1394. *
  1395. * @return - Success : 0
  1396. * Failure : -EINVAL
  1397. */
  1398. int omap_get_dma_chain_index(int chain_id, int *ei, int *fi)
  1399. {
  1400. int lch;
  1401. int *channels;
  1402. /* Check for input params */
  1403. if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
  1404. printk(KERN_ERR "Invalid chain id\n");
  1405. return -EINVAL;
  1406. }
  1407. /* Check if the chain exists */
  1408. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1409. printk(KERN_ERR "Chain doesn't exists\n");
  1410. return -EINVAL;
  1411. }
  1412. if ((!ei) || (!fi))
  1413. return -EINVAL;
  1414. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1415. /* Get the current channel */
  1416. lch = channels[dma_linked_lch[chain_id].q_head];
  1417. *ei = dma_read(CCEN(lch));
  1418. *fi = dma_read(CCFN(lch));
  1419. return 0;
  1420. }
  1421. EXPORT_SYMBOL(omap_get_dma_chain_index);
  1422. /**
  1423. * @brief omap_get_dma_chain_dst_pos - Get the destination position of the
  1424. * ongoing DMA in chain
  1425. *
  1426. * @param chain_id
  1427. *
  1428. * @return - Success : Destination position
  1429. * Failure : -EINVAL
  1430. */
  1431. int omap_get_dma_chain_dst_pos(int chain_id)
  1432. {
  1433. int lch;
  1434. int *channels;
  1435. /* Check for input params */
  1436. if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
  1437. printk(KERN_ERR "Invalid chain id\n");
  1438. return -EINVAL;
  1439. }
  1440. /* Check if the chain exists */
  1441. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1442. printk(KERN_ERR "Chain doesn't exists\n");
  1443. return -EINVAL;
  1444. }
  1445. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1446. /* Get the current channel */
  1447. lch = channels[dma_linked_lch[chain_id].q_head];
  1448. return dma_read(CDAC(lch));
  1449. }
  1450. EXPORT_SYMBOL(omap_get_dma_chain_dst_pos);
  1451. /**
  1452. * @brief omap_get_dma_chain_src_pos - Get the source position
  1453. * of the ongoing DMA in chain
  1454. * @param chain_id
  1455. *
  1456. * @return - Success : Destination position
  1457. * Failure : -EINVAL
  1458. */
  1459. int omap_get_dma_chain_src_pos(int chain_id)
  1460. {
  1461. int lch;
  1462. int *channels;
  1463. /* Check for input params */
  1464. if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
  1465. printk(KERN_ERR "Invalid chain id\n");
  1466. return -EINVAL;
  1467. }
  1468. /* Check if the chain exists */
  1469. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1470. printk(KERN_ERR "Chain doesn't exists\n");
  1471. return -EINVAL;
  1472. }
  1473. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1474. /* Get the current channel */
  1475. lch = channels[dma_linked_lch[chain_id].q_head];
  1476. return dma_read(CSAC(lch));
  1477. }
  1478. EXPORT_SYMBOL(omap_get_dma_chain_src_pos);
  1479. #endif /* ifndef CONFIG_ARCH_OMAP1 */
  1480. /*----------------------------------------------------------------------------*/
  1481. #ifdef CONFIG_ARCH_OMAP1
  1482. static int omap1_dma_handle_ch(int ch)
  1483. {
  1484. u32 csr;
  1485. if (enable_1510_mode && ch >= 6) {
  1486. csr = dma_chan[ch].saved_csr;
  1487. dma_chan[ch].saved_csr = 0;
  1488. } else
  1489. csr = dma_read(CSR(ch));
  1490. if (enable_1510_mode && ch <= 2 && (csr >> 7) != 0) {
  1491. dma_chan[ch + 6].saved_csr = csr >> 7;
  1492. csr &= 0x7f;
  1493. }
  1494. if ((csr & 0x3f) == 0)
  1495. return 0;
  1496. if (unlikely(dma_chan[ch].dev_id == -1)) {
  1497. printk(KERN_WARNING "Spurious interrupt from DMA channel "
  1498. "%d (CSR %04x)\n", ch, csr);
  1499. return 0;
  1500. }
  1501. if (unlikely(csr & OMAP1_DMA_TOUT_IRQ))
  1502. printk(KERN_WARNING "DMA timeout with device %d\n",
  1503. dma_chan[ch].dev_id);
  1504. if (unlikely(csr & OMAP_DMA_DROP_IRQ))
  1505. printk(KERN_WARNING "DMA synchronization event drop occurred "
  1506. "with device %d\n", dma_chan[ch].dev_id);
  1507. if (likely(csr & OMAP_DMA_BLOCK_IRQ))
  1508. dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
  1509. if (likely(dma_chan[ch].callback != NULL))
  1510. dma_chan[ch].callback(ch, csr, dma_chan[ch].data);
  1511. return 1;
  1512. }
  1513. static irqreturn_t omap1_dma_irq_handler(int irq, void *dev_id)
  1514. {
  1515. int ch = ((int) dev_id) - 1;
  1516. int handled = 0;
  1517. for (;;) {
  1518. int handled_now = 0;
  1519. handled_now += omap1_dma_handle_ch(ch);
  1520. if (enable_1510_mode && dma_chan[ch + 6].saved_csr)
  1521. handled_now += omap1_dma_handle_ch(ch + 6);
  1522. if (!handled_now)
  1523. break;
  1524. handled += handled_now;
  1525. }
  1526. return handled ? IRQ_HANDLED : IRQ_NONE;
  1527. }
  1528. #else
  1529. #define omap1_dma_irq_handler NULL
  1530. #endif
  1531. #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3)
  1532. static int omap2_dma_handle_ch(int ch)
  1533. {
  1534. u32 status = dma_read(CSR(ch));
  1535. if (!status) {
  1536. if (printk_ratelimit())
  1537. printk(KERN_WARNING "Spurious DMA IRQ for lch %d\n",
  1538. ch);
  1539. dma_write(1 << ch, IRQSTATUS_L0);
  1540. return 0;
  1541. }
  1542. if (unlikely(dma_chan[ch].dev_id == -1)) {
  1543. if (printk_ratelimit())
  1544. printk(KERN_WARNING "IRQ %04x for non-allocated DMA"
  1545. "channel %d\n", status, ch);
  1546. return 0;
  1547. }
  1548. if (unlikely(status & OMAP_DMA_DROP_IRQ))
  1549. printk(KERN_INFO
  1550. "DMA synchronization event drop occurred with device "
  1551. "%d\n", dma_chan[ch].dev_id);
  1552. if (unlikely(status & OMAP2_DMA_TRANS_ERR_IRQ))
  1553. printk(KERN_INFO "DMA transaction error with device %d\n",
  1554. dma_chan[ch].dev_id);
  1555. if (unlikely(status & OMAP2_DMA_SECURE_ERR_IRQ))
  1556. printk(KERN_INFO "DMA secure error with device %d\n",
  1557. dma_chan[ch].dev_id);
  1558. if (unlikely(status & OMAP2_DMA_MISALIGNED_ERR_IRQ))
  1559. printk(KERN_INFO "DMA misaligned error with device %d\n",
  1560. dma_chan[ch].dev_id);
  1561. dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(ch));
  1562. dma_write(1 << ch, IRQSTATUS_L0);
  1563. /* If the ch is not chained then chain_id will be -1 */
  1564. if (dma_chan[ch].chain_id != -1) {
  1565. int chain_id = dma_chan[ch].chain_id;
  1566. dma_chan[ch].state = DMA_CH_NOTSTARTED;
  1567. if (dma_read(CLNK_CTRL(ch)) & (1 << 15))
  1568. dma_chan[dma_chan[ch].next_linked_ch].state =
  1569. DMA_CH_STARTED;
  1570. if (dma_linked_lch[chain_id].chain_mode ==
  1571. OMAP_DMA_DYNAMIC_CHAIN)
  1572. disable_lnk(ch);
  1573. if (!OMAP_DMA_CHAIN_QEMPTY(chain_id))
  1574. OMAP_DMA_CHAIN_INCQHEAD(chain_id);
  1575. status = dma_read(CSR(ch));
  1576. }
  1577. if (likely(dma_chan[ch].callback != NULL))
  1578. dma_chan[ch].callback(ch, status, dma_chan[ch].data);
  1579. dma_write(status, CSR(ch));
  1580. return 0;
  1581. }
  1582. /* STATUS register count is from 1-32 while our is 0-31 */
  1583. static irqreturn_t omap2_dma_irq_handler(int irq, void *dev_id)
  1584. {
  1585. u32 val;
  1586. int i;
  1587. val = dma_read(IRQSTATUS_L0);
  1588. if (val == 0) {
  1589. if (printk_ratelimit())
  1590. printk(KERN_WARNING "Spurious DMA IRQ\n");
  1591. return IRQ_HANDLED;
  1592. }
  1593. for (i = 0; i < dma_lch_count && val != 0; i++) {
  1594. if (val & 1)
  1595. omap2_dma_handle_ch(i);
  1596. val >>= 1;
  1597. }
  1598. return IRQ_HANDLED;
  1599. }
  1600. static struct irqaction omap24xx_dma_irq = {
  1601. .name = "DMA",
  1602. .handler = omap2_dma_irq_handler,
  1603. .flags = IRQF_DISABLED
  1604. };
  1605. #else
  1606. static struct irqaction omap24xx_dma_irq;
  1607. #endif
  1608. /*----------------------------------------------------------------------------*/
  1609. static struct lcd_dma_info {
  1610. spinlock_t lock;
  1611. int reserved;
  1612. void (*callback)(u16 status, void *data);
  1613. void *cb_data;
  1614. int active;
  1615. unsigned long addr, size;
  1616. int rotate, data_type, xres, yres;
  1617. int vxres;
  1618. int mirror;
  1619. int xscale, yscale;
  1620. int ext_ctrl;
  1621. int src_port;
  1622. int single_transfer;
  1623. } lcd_dma;
  1624. void omap_set_lcd_dma_b1(unsigned long addr, u16 fb_xres, u16 fb_yres,
  1625. int data_type)
  1626. {
  1627. lcd_dma.addr = addr;
  1628. lcd_dma.data_type = data_type;
  1629. lcd_dma.xres = fb_xres;
  1630. lcd_dma.yres = fb_yres;
  1631. }
  1632. EXPORT_SYMBOL(omap_set_lcd_dma_b1);
  1633. void omap_set_lcd_dma_src_port(int port)
  1634. {
  1635. lcd_dma.src_port = port;
  1636. }
  1637. void omap_set_lcd_dma_ext_controller(int external)
  1638. {
  1639. lcd_dma.ext_ctrl = external;
  1640. }
  1641. EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller);
  1642. void omap_set_lcd_dma_single_transfer(int single)
  1643. {
  1644. lcd_dma.single_transfer = single;
  1645. }
  1646. EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer);
  1647. void omap_set_lcd_dma_b1_rotation(int rotate)
  1648. {
  1649. if (omap_dma_in_1510_mode()) {
  1650. printk(KERN_ERR "DMA rotation is not supported in 1510 mode\n");
  1651. BUG();
  1652. return;
  1653. }
  1654. lcd_dma.rotate = rotate;
  1655. }
  1656. EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation);
  1657. void omap_set_lcd_dma_b1_mirror(int mirror)
  1658. {
  1659. if (omap_dma_in_1510_mode()) {
  1660. printk(KERN_ERR "DMA mirror is not supported in 1510 mode\n");
  1661. BUG();
  1662. }
  1663. lcd_dma.mirror = mirror;
  1664. }
  1665. EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror);
  1666. void omap_set_lcd_dma_b1_vxres(unsigned long vxres)
  1667. {
  1668. if (omap_dma_in_1510_mode()) {
  1669. printk(KERN_ERR "DMA virtual resulotion is not supported "
  1670. "in 1510 mode\n");
  1671. BUG();
  1672. }
  1673. lcd_dma.vxres = vxres;
  1674. }
  1675. EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres);
  1676. void omap_set_lcd_dma_b1_scale(unsigned int xscale, unsigned int yscale)
  1677. {
  1678. if (omap_dma_in_1510_mode()) {
  1679. printk(KERN_ERR "DMA scale is not supported in 1510 mode\n");
  1680. BUG();
  1681. }
  1682. lcd_dma.xscale = xscale;
  1683. lcd_dma.yscale = yscale;
  1684. }
  1685. EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale);
  1686. static void set_b1_regs(void)
  1687. {
  1688. unsigned long top, bottom;
  1689. int es;
  1690. u16 w;
  1691. unsigned long en, fn;
  1692. long ei, fi;
  1693. unsigned long vxres;
  1694. unsigned int xscale, yscale;
  1695. switch (lcd_dma.data_type) {
  1696. case OMAP_DMA_DATA_TYPE_S8:
  1697. es = 1;
  1698. break;
  1699. case OMAP_DMA_DATA_TYPE_S16:
  1700. es = 2;
  1701. break;
  1702. case OMAP_DMA_DATA_TYPE_S32:
  1703. es = 4;
  1704. break;
  1705. default:
  1706. BUG();
  1707. return;
  1708. }
  1709. vxres = lcd_dma.vxres ? lcd_dma.vxres : lcd_dma.xres;
  1710. xscale = lcd_dma.xscale ? lcd_dma.xscale : 1;
  1711. yscale = lcd_dma.yscale ? lcd_dma.yscale : 1;
  1712. BUG_ON(vxres < lcd_dma.xres);
  1713. #define PIXADDR(x, y) (lcd_dma.addr + \
  1714. ((y) * vxres * yscale + (x) * xscale) * es)
  1715. #define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
  1716. switch (lcd_dma.rotate) {
  1717. case 0:
  1718. if (!lcd_dma.mirror) {
  1719. top = PIXADDR(0, 0);
  1720. bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  1721. /* 1510 DMA requires the bottom address to be 2 more
  1722. * than the actual last memory access location. */
  1723. if (omap_dma_in_1510_mode() &&
  1724. lcd_dma.data_type == OMAP_DMA_DATA_TYPE_S32)
  1725. bottom += 2;
  1726. ei = PIXSTEP(0, 0, 1, 0);
  1727. fi = PIXSTEP(lcd_dma.xres - 1, 0, 0, 1);
  1728. } else {
  1729. top = PIXADDR(lcd_dma.xres - 1, 0);
  1730. bottom = PIXADDR(0, lcd_dma.yres - 1);
  1731. ei = PIXSTEP(1, 0, 0, 0);
  1732. fi = PIXSTEP(0, 0, lcd_dma.xres - 1, 1);
  1733. }
  1734. en = lcd_dma.xres;
  1735. fn = lcd_dma.yres;
  1736. break;
  1737. case 90:
  1738. if (!lcd_dma.mirror) {
  1739. top = PIXADDR(0, lcd_dma.yres - 1);
  1740. bottom = PIXADDR(lcd_dma.xres - 1, 0);
  1741. ei = PIXSTEP(0, 1, 0, 0);
  1742. fi = PIXSTEP(0, 0, 1, lcd_dma.yres - 1);
  1743. } else {
  1744. top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  1745. bottom = PIXADDR(0, 0);
  1746. ei = PIXSTEP(0, 1, 0, 0);
  1747. fi = PIXSTEP(1, 0, 0, lcd_dma.yres - 1);
  1748. }
  1749. en = lcd_dma.yres;
  1750. fn = lcd_dma.xres;
  1751. break;
  1752. case 180:
  1753. if (!lcd_dma.mirror) {
  1754. top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  1755. bottom = PIXADDR(0, 0);
  1756. ei = PIXSTEP(1, 0, 0, 0);
  1757. fi = PIXSTEP(0, 1, lcd_dma.xres - 1, 0);
  1758. } else {
  1759. top = PIXADDR(0, lcd_dma.yres - 1);
  1760. bottom = PIXADDR(lcd_dma.xres - 1, 0);
  1761. ei = PIXSTEP(0, 0, 1, 0);
  1762. fi = PIXSTEP(lcd_dma.xres - 1, 1, 0, 0);
  1763. }
  1764. en = lcd_dma.xres;
  1765. fn = lcd_dma.yres;
  1766. break;
  1767. case 270:
  1768. if (!lcd_dma.mirror) {
  1769. top = PIXADDR(lcd_dma.xres - 1, 0);
  1770. bottom = PIXADDR(0, lcd_dma.yres - 1);
  1771. ei = PIXSTEP(0, 0, 0, 1);
  1772. fi = PIXSTEP(1, lcd_dma.yres - 1, 0, 0);
  1773. } else {
  1774. top = PIXADDR(0, 0);
  1775. bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  1776. ei = PIXSTEP(0, 0, 0, 1);
  1777. fi = PIXSTEP(0, lcd_dma.yres - 1, 1, 0);
  1778. }
  1779. en = lcd_dma.yres;
  1780. fn = lcd_dma.xres;
  1781. break;
  1782. default:
  1783. BUG();
  1784. return; /* Suppress warning about uninitialized vars */
  1785. }
  1786. if (omap_dma_in_1510_mode()) {
  1787. omap_writew(top >> 16, OMAP1510_DMA_LCD_TOP_F1_U);
  1788. omap_writew(top, OMAP1510_DMA_LCD_TOP_F1_L);
  1789. omap_writew(bottom >> 16, OMAP1510_DMA_LCD_BOT_F1_U);
  1790. omap_writew(bottom, OMAP1510_DMA_LCD_BOT_F1_L);
  1791. return;
  1792. }
  1793. /* 1610 regs */
  1794. omap_writew(top >> 16, OMAP1610_DMA_LCD_TOP_B1_U);
  1795. omap_writew(top, OMAP1610_DMA_LCD_TOP_B1_L);
  1796. omap_writew(bottom >> 16, OMAP1610_DMA_LCD_BOT_B1_U);
  1797. omap_writew(bottom, OMAP1610_DMA_LCD_BOT_B1_L);
  1798. omap_writew(en, OMAP1610_DMA_LCD_SRC_EN_B1);
  1799. omap_writew(fn, OMAP1610_DMA_LCD_SRC_FN_B1);
  1800. w = omap_readw(OMAP1610_DMA_LCD_CSDP);
  1801. w &= ~0x03;
  1802. w |= lcd_dma.data_type;
  1803. omap_writew(w, OMAP1610_DMA_LCD_CSDP);
  1804. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1805. /* Always set the source port as SDRAM for now*/
  1806. w &= ~(0x03 << 6);
  1807. if (lcd_dma.callback != NULL)
  1808. w |= 1 << 1; /* Block interrupt enable */
  1809. else
  1810. w &= ~(1 << 1);
  1811. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1812. if (!(lcd_dma.rotate || lcd_dma.mirror ||
  1813. lcd_dma.vxres || lcd_dma.xscale || lcd_dma.yscale))
  1814. return;
  1815. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1816. /* Set the double-indexed addressing mode */
  1817. w |= (0x03 << 12);
  1818. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1819. omap_writew(ei, OMAP1610_DMA_LCD_SRC_EI_B1);
  1820. omap_writew(fi >> 16, OMAP1610_DMA_LCD_SRC_FI_B1_U);
  1821. omap_writew(fi, OMAP1610_DMA_LCD_SRC_FI_B1_L);
  1822. }
  1823. static irqreturn_t lcd_dma_irq_handler(int irq, void *dev_id)
  1824. {
  1825. u16 w;
  1826. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1827. if (unlikely(!(w & (1 << 3)))) {
  1828. printk(KERN_WARNING "Spurious LCD DMA IRQ\n");
  1829. return IRQ_NONE;
  1830. }
  1831. /* Ack the IRQ */
  1832. w |= (1 << 3);
  1833. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1834. lcd_dma.active = 0;
  1835. if (lcd_dma.callback != NULL)
  1836. lcd_dma.callback(w, lcd_dma.cb_data);
  1837. return IRQ_HANDLED;
  1838. }
  1839. int omap_request_lcd_dma(void (*callback)(u16 status, void *data),
  1840. void *data)
  1841. {
  1842. spin_lock_irq(&lcd_dma.lock);
  1843. if (lcd_dma.reserved) {
  1844. spin_unlock_irq(&lcd_dma.lock);
  1845. printk(KERN_ERR "LCD DMA channel already reserved\n");
  1846. BUG();
  1847. return -EBUSY;
  1848. }
  1849. lcd_dma.reserved = 1;
  1850. spin_unlock_irq(&lcd_dma.lock);
  1851. lcd_dma.callback = callback;
  1852. lcd_dma.cb_data = data;
  1853. lcd_dma.active = 0;
  1854. lcd_dma.single_transfer = 0;
  1855. lcd_dma.rotate = 0;
  1856. lcd_dma.vxres = 0;
  1857. lcd_dma.mirror = 0;
  1858. lcd_dma.xscale = 0;
  1859. lcd_dma.yscale = 0;
  1860. lcd_dma.ext_ctrl = 0;
  1861. lcd_dma.src_port = 0;
  1862. return 0;
  1863. }
  1864. EXPORT_SYMBOL(omap_request_lcd_dma);
  1865. void omap_free_lcd_dma(void)
  1866. {
  1867. spin_lock(&lcd_dma.lock);
  1868. if (!lcd_dma.reserved) {
  1869. spin_unlock(&lcd_dma.lock);
  1870. printk(KERN_ERR "LCD DMA is not reserved\n");
  1871. BUG();
  1872. return;
  1873. }
  1874. if (!enable_1510_mode)
  1875. omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR) & ~1,
  1876. OMAP1610_DMA_LCD_CCR);
  1877. lcd_dma.reserved = 0;
  1878. spin_unlock(&lcd_dma.lock);
  1879. }
  1880. EXPORT_SYMBOL(omap_free_lcd_dma);
  1881. void omap_enable_lcd_dma(void)
  1882. {
  1883. u16 w;
  1884. /*
  1885. * Set the Enable bit only if an external controller is
  1886. * connected. Otherwise the OMAP internal controller will
  1887. * start the transfer when it gets enabled.
  1888. */
  1889. if (enable_1510_mode || !lcd_dma.ext_ctrl)
  1890. return;
  1891. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1892. w |= 1 << 8;
  1893. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1894. lcd_dma.active = 1;
  1895. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1896. w |= 1 << 7;
  1897. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1898. }
  1899. EXPORT_SYMBOL(omap_enable_lcd_dma);
  1900. void omap_setup_lcd_dma(void)
  1901. {
  1902. BUG_ON(lcd_dma.active);
  1903. if (!enable_1510_mode) {
  1904. /* Set some reasonable defaults */
  1905. omap_writew(0x5440, OMAP1610_DMA_LCD_CCR);
  1906. omap_writew(0x9102, OMAP1610_DMA_LCD_CSDP);
  1907. omap_writew(0x0004, OMAP1610_DMA_LCD_LCH_CTRL);
  1908. }
  1909. set_b1_regs();
  1910. if (!enable_1510_mode) {
  1911. u16 w;
  1912. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1913. /*
  1914. * If DMA was already active set the end_prog bit to have
  1915. * the programmed register set loaded into the active
  1916. * register set.
  1917. */
  1918. w |= 1 << 11; /* End_prog */
  1919. if (!lcd_dma.single_transfer)
  1920. w |= (3 << 8); /* Auto_init, repeat */
  1921. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1922. }
  1923. }
  1924. EXPORT_SYMBOL(omap_setup_lcd_dma);
  1925. void omap_stop_lcd_dma(void)
  1926. {
  1927. u16 w;
  1928. lcd_dma.active = 0;
  1929. if (enable_1510_mode || !lcd_dma.ext_ctrl)
  1930. return;
  1931. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1932. w &= ~(1 << 7);
  1933. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1934. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1935. w &= ~(1 << 8);
  1936. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1937. }
  1938. EXPORT_SYMBOL(omap_stop_lcd_dma);
  1939. /*----------------------------------------------------------------------------*/
  1940. static int __init omap_init_dma(void)
  1941. {
  1942. int ch, r;
  1943. if (cpu_class_is_omap1()) {
  1944. omap_dma_base = (void __iomem *)IO_ADDRESS(OMAP1_DMA_BASE);
  1945. dma_lch_count = OMAP1_LOGICAL_DMA_CH_COUNT;
  1946. } else if (cpu_is_omap24xx()) {
  1947. omap_dma_base = (void __iomem *)IO_ADDRESS(OMAP24XX_DMA4_BASE);
  1948. dma_lch_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
  1949. } else if (cpu_is_omap34xx()) {
  1950. omap_dma_base = (void __iomem *)IO_ADDRESS(OMAP34XX_DMA4_BASE);
  1951. dma_lch_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
  1952. } else {
  1953. pr_err("DMA init failed for unsupported omap\n");
  1954. return -ENODEV;
  1955. }
  1956. dma_chan = kzalloc(sizeof(struct omap_dma_lch) * dma_lch_count,
  1957. GFP_KERNEL);
  1958. if (!dma_chan)
  1959. return -ENOMEM;
  1960. if (cpu_class_is_omap2()) {
  1961. dma_linked_lch = kzalloc(sizeof(struct dma_link_info) *
  1962. dma_lch_count, GFP_KERNEL);
  1963. if (!dma_linked_lch) {
  1964. kfree(dma_chan);
  1965. return -ENOMEM;
  1966. }
  1967. }
  1968. if (cpu_is_omap15xx()) {
  1969. printk(KERN_INFO "DMA support for OMAP15xx initialized\n");
  1970. dma_chan_count = 9;
  1971. enable_1510_mode = 1;
  1972. } else if (cpu_is_omap16xx() || cpu_is_omap730()) {
  1973. printk(KERN_INFO "OMAP DMA hardware version %d\n",
  1974. dma_read(HW_ID));
  1975. printk(KERN_INFO "DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
  1976. (dma_read(CAPS_0_U) << 16) |
  1977. dma_read(CAPS_0_L),
  1978. (dma_read(CAPS_1_U) << 16) |
  1979. dma_read(CAPS_1_L),
  1980. dma_read(CAPS_2), dma_read(CAPS_3),
  1981. dma_read(CAPS_4));
  1982. if (!enable_1510_mode) {
  1983. u16 w;
  1984. /* Disable OMAP 3.0/3.1 compatibility mode. */
  1985. w = dma_read(GSCR);
  1986. w |= 1 << 3;
  1987. dma_write(w, GSCR);
  1988. dma_chan_count = 16;
  1989. } else
  1990. dma_chan_count = 9;
  1991. if (cpu_is_omap16xx()) {
  1992. u16 w;
  1993. /* this would prevent OMAP sleep */
  1994. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1995. w &= ~(1 << 8);
  1996. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1997. }
  1998. } else if (cpu_class_is_omap2()) {
  1999. u8 revision = dma_read(REVISION) & 0xff;
  2000. printk(KERN_INFO "OMAP DMA hardware revision %d.%d\n",
  2001. revision >> 4, revision & 0xf);
  2002. dma_chan_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
  2003. } else {
  2004. dma_chan_count = 0;
  2005. return 0;
  2006. }
  2007. spin_lock_init(&lcd_dma.lock);
  2008. spin_lock_init(&dma_chan_lock);
  2009. for (ch = 0; ch < dma_chan_count; ch++) {
  2010. omap_clear_dma(ch);
  2011. dma_chan[ch].dev_id = -1;
  2012. dma_chan[ch].next_lch = -1;
  2013. if (ch >= 6 && enable_1510_mode)
  2014. continue;
  2015. if (cpu_class_is_omap1()) {
  2016. /*
  2017. * request_irq() doesn't like dev_id (ie. ch) being
  2018. * zero, so we have to kludge around this.
  2019. */
  2020. r = request_irq(omap1_dma_irq[ch],
  2021. omap1_dma_irq_handler, 0, "DMA",
  2022. (void *) (ch + 1));
  2023. if (r != 0) {
  2024. int i;
  2025. printk(KERN_ERR "unable to request IRQ %d "
  2026. "for DMA (error %d)\n",
  2027. omap1_dma_irq[ch], r);
  2028. for (i = 0; i < ch; i++)
  2029. free_irq(omap1_dma_irq[i],
  2030. (void *) (i + 1));
  2031. return r;
  2032. }
  2033. }
  2034. }
  2035. if (cpu_is_omap2430() || cpu_is_omap34xx())
  2036. omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE,
  2037. DMA_DEFAULT_FIFO_DEPTH, 0);
  2038. if (cpu_class_is_omap2())
  2039. setup_irq(INT_24XX_SDMA_IRQ0, &omap24xx_dma_irq);
  2040. /* FIXME: Update LCD DMA to work on 24xx */
  2041. if (cpu_class_is_omap1()) {
  2042. r = request_irq(INT_DMA_LCD, lcd_dma_irq_handler, 0,
  2043. "LCD DMA", NULL);
  2044. if (r != 0) {
  2045. int i;
  2046. printk(KERN_ERR "unable to request IRQ for LCD DMA "
  2047. "(error %d)\n", r);
  2048. for (i = 0; i < dma_chan_count; i++)
  2049. free_irq(omap1_dma_irq[i], (void *) (i + 1));
  2050. return r;
  2051. }
  2052. }
  2053. return 0;
  2054. }
  2055. arch_initcall(omap_init_dma);