dma.c 58 KB

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