dma.c 59 KB

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