dma.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508
  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. if (!cpu_class_is_omap2())
  583. return;
  584. val = dma_read(IRQENABLE_L0);
  585. val |= 1 << lch;
  586. dma_write(val, IRQENABLE_L0);
  587. }
  588. int omap_request_dma(int dev_id, const char *dev_name,
  589. void (*callback)(int lch, u16 ch_status, void *data),
  590. void *data, int *dma_ch_out)
  591. {
  592. int ch, free_ch = -1;
  593. unsigned long flags;
  594. struct omap_dma_lch *chan;
  595. spin_lock_irqsave(&dma_chan_lock, flags);
  596. for (ch = 0; ch < dma_chan_count; ch++) {
  597. if (free_ch == -1 && dma_chan[ch].dev_id == -1) {
  598. free_ch = ch;
  599. if (dev_id == 0)
  600. break;
  601. }
  602. }
  603. if (free_ch == -1) {
  604. spin_unlock_irqrestore(&dma_chan_lock, flags);
  605. return -EBUSY;
  606. }
  607. chan = dma_chan + free_ch;
  608. chan->dev_id = dev_id;
  609. if (cpu_class_is_omap1())
  610. clear_lch_regs(free_ch);
  611. if (cpu_class_is_omap2())
  612. omap_clear_dma(free_ch);
  613. spin_unlock_irqrestore(&dma_chan_lock, flags);
  614. chan->dev_name = dev_name;
  615. chan->callback = callback;
  616. chan->data = data;
  617. chan->flags = 0;
  618. #ifndef CONFIG_ARCH_OMAP1
  619. if (cpu_class_is_omap2()) {
  620. chan->chain_id = -1;
  621. chan->next_linked_ch = -1;
  622. }
  623. #endif
  624. chan->enabled_irqs = OMAP_DMA_DROP_IRQ | OMAP_DMA_BLOCK_IRQ;
  625. if (cpu_class_is_omap1())
  626. chan->enabled_irqs |= OMAP1_DMA_TOUT_IRQ;
  627. else if (cpu_class_is_omap2())
  628. chan->enabled_irqs |= OMAP2_DMA_MISALIGNED_ERR_IRQ |
  629. OMAP2_DMA_TRANS_ERR_IRQ;
  630. if (cpu_is_omap16xx()) {
  631. /* If the sync device is set, configure it dynamically. */
  632. if (dev_id != 0) {
  633. set_gdma_dev(free_ch + 1, dev_id);
  634. dev_id = free_ch + 1;
  635. }
  636. /*
  637. * Disable the 1510 compatibility mode and set the sync device
  638. * id.
  639. */
  640. dma_write(dev_id | (1 << 10), CCR(free_ch));
  641. } else if (cpu_is_omap7xx() || cpu_is_omap15xx()) {
  642. dma_write(dev_id, CCR(free_ch));
  643. }
  644. if (cpu_class_is_omap2()) {
  645. omap2_enable_irq_lch(free_ch);
  646. omap_enable_channel_irq(free_ch);
  647. /* Clear the CSR register and IRQ status register */
  648. dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(free_ch));
  649. dma_write(1 << free_ch, IRQSTATUS_L0);
  650. }
  651. *dma_ch_out = free_ch;
  652. return 0;
  653. }
  654. EXPORT_SYMBOL(omap_request_dma);
  655. void omap_free_dma(int lch)
  656. {
  657. unsigned long flags;
  658. if (dma_chan[lch].dev_id == -1) {
  659. pr_err("omap_dma: trying to free unallocated DMA channel %d\n",
  660. lch);
  661. return;
  662. }
  663. if (cpu_class_is_omap1()) {
  664. /* Disable all DMA interrupts for the channel. */
  665. dma_write(0, CICR(lch));
  666. /* Make sure the DMA transfer is stopped. */
  667. dma_write(0, CCR(lch));
  668. }
  669. if (cpu_class_is_omap2()) {
  670. u32 val;
  671. /* Disable interrupts */
  672. val = dma_read(IRQENABLE_L0);
  673. val &= ~(1 << lch);
  674. dma_write(val, IRQENABLE_L0);
  675. /* Clear the CSR register and IRQ status register */
  676. dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(lch));
  677. dma_write(1 << lch, IRQSTATUS_L0);
  678. /* Disable all DMA interrupts for the channel. */
  679. dma_write(0, CICR(lch));
  680. /* Make sure the DMA transfer is stopped. */
  681. dma_write(0, CCR(lch));
  682. omap_clear_dma(lch);
  683. }
  684. spin_lock_irqsave(&dma_chan_lock, flags);
  685. dma_chan[lch].dev_id = -1;
  686. dma_chan[lch].next_lch = -1;
  687. dma_chan[lch].callback = NULL;
  688. spin_unlock_irqrestore(&dma_chan_lock, flags);
  689. }
  690. EXPORT_SYMBOL(omap_free_dma);
  691. /**
  692. * @brief omap_dma_set_global_params : Set global priority settings for dma
  693. *
  694. * @param arb_rate
  695. * @param max_fifo_depth
  696. * @param tparams - Number of thereads to reserve : DMA_THREAD_RESERVE_NORM
  697. * DMA_THREAD_RESERVE_ONET
  698. * DMA_THREAD_RESERVE_TWOT
  699. * DMA_THREAD_RESERVE_THREET
  700. */
  701. void
  702. omap_dma_set_global_params(int arb_rate, int max_fifo_depth, int tparams)
  703. {
  704. u32 reg;
  705. if (!cpu_class_is_omap2()) {
  706. printk(KERN_ERR "FIXME: no %s on 15xx/16xx\n", __func__);
  707. return;
  708. }
  709. if (arb_rate == 0)
  710. arb_rate = 1;
  711. reg = (arb_rate & 0xff) << 16;
  712. reg |= (0xff & max_fifo_depth);
  713. dma_write(reg, GCR);
  714. }
  715. EXPORT_SYMBOL(omap_dma_set_global_params);
  716. /**
  717. * @brief omap_dma_set_prio_lch : Set channel wise priority settings
  718. *
  719. * @param lch
  720. * @param read_prio - Read priority
  721. * @param write_prio - Write priority
  722. * Both of the above can be set with one of the following values :
  723. * DMA_CH_PRIO_HIGH/DMA_CH_PRIO_LOW
  724. */
  725. int
  726. omap_dma_set_prio_lch(int lch, unsigned char read_prio,
  727. unsigned char write_prio)
  728. {
  729. u32 l;
  730. if (unlikely((lch < 0 || lch >= dma_lch_count))) {
  731. printk(KERN_ERR "Invalid channel id\n");
  732. return -EINVAL;
  733. }
  734. l = dma_read(CCR(lch));
  735. l &= ~((1 << 6) | (1 << 26));
  736. if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx())
  737. l |= ((read_prio & 0x1) << 6) | ((write_prio & 0x1) << 26);
  738. else
  739. l |= ((read_prio & 0x1) << 6);
  740. dma_write(l, CCR(lch));
  741. return 0;
  742. }
  743. EXPORT_SYMBOL(omap_dma_set_prio_lch);
  744. /*
  745. * Clears any DMA state so the DMA engine is ready to restart with new buffers
  746. * through omap_start_dma(). Any buffers in flight are discarded.
  747. */
  748. void omap_clear_dma(int lch)
  749. {
  750. unsigned long flags;
  751. local_irq_save(flags);
  752. if (cpu_class_is_omap1()) {
  753. u32 l;
  754. l = dma_read(CCR(lch));
  755. l &= ~OMAP_DMA_CCR_EN;
  756. dma_write(l, CCR(lch));
  757. /* Clear pending interrupts */
  758. l = dma_read(CSR(lch));
  759. }
  760. if (cpu_class_is_omap2()) {
  761. int i;
  762. void __iomem *lch_base = omap_dma_base + OMAP_DMA4_CH_BASE(lch);
  763. for (i = 0; i < 0x44; i += 4)
  764. __raw_writel(0, lch_base + i);
  765. }
  766. local_irq_restore(flags);
  767. }
  768. EXPORT_SYMBOL(omap_clear_dma);
  769. void omap_start_dma(int lch)
  770. {
  771. u32 l;
  772. if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
  773. int next_lch, cur_lch;
  774. char dma_chan_link_map[OMAP_DMA4_LOGICAL_DMA_CH_COUNT];
  775. dma_chan_link_map[lch] = 1;
  776. /* Set the link register of the first channel */
  777. enable_lnk(lch);
  778. memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
  779. cur_lch = dma_chan[lch].next_lch;
  780. do {
  781. next_lch = dma_chan[cur_lch].next_lch;
  782. /* The loop case: we've been here already */
  783. if (dma_chan_link_map[cur_lch])
  784. break;
  785. /* Mark the current channel */
  786. dma_chan_link_map[cur_lch] = 1;
  787. enable_lnk(cur_lch);
  788. omap_enable_channel_irq(cur_lch);
  789. cur_lch = next_lch;
  790. } while (next_lch != -1);
  791. } else if (cpu_is_omap242x() ||
  792. (cpu_is_omap243x() && omap_type() <= OMAP2430_REV_ES1_0)) {
  793. /* Errata: Need to write lch even if not using chaining */
  794. dma_write(lch, CLNK_CTRL(lch));
  795. }
  796. omap_enable_channel_irq(lch);
  797. l = dma_read(CCR(lch));
  798. /*
  799. * Errata: On ES2.0 BUFFERING disable must be set.
  800. * This will always fail on ES1.0
  801. */
  802. if (cpu_is_omap24xx())
  803. l |= OMAP_DMA_CCR_EN;
  804. l |= OMAP_DMA_CCR_EN;
  805. dma_write(l, CCR(lch));
  806. dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
  807. }
  808. EXPORT_SYMBOL(omap_start_dma);
  809. void omap_stop_dma(int lch)
  810. {
  811. u32 l;
  812. if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
  813. int next_lch, cur_lch = lch;
  814. char dma_chan_link_map[OMAP_DMA4_LOGICAL_DMA_CH_COUNT];
  815. memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
  816. do {
  817. /* The loop case: we've been here already */
  818. if (dma_chan_link_map[cur_lch])
  819. break;
  820. /* Mark the current channel */
  821. dma_chan_link_map[cur_lch] = 1;
  822. disable_lnk(cur_lch);
  823. next_lch = dma_chan[cur_lch].next_lch;
  824. cur_lch = next_lch;
  825. } while (next_lch != -1);
  826. return;
  827. }
  828. /* Disable all interrupts on the channel */
  829. if (cpu_class_is_omap1())
  830. dma_write(0, CICR(lch));
  831. l = dma_read(CCR(lch));
  832. l &= ~OMAP_DMA_CCR_EN;
  833. dma_write(l, CCR(lch));
  834. dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
  835. }
  836. EXPORT_SYMBOL(omap_stop_dma);
  837. /*
  838. * Allows changing the DMA callback function or data. This may be needed if
  839. * the driver shares a single DMA channel for multiple dma triggers.
  840. */
  841. int omap_set_dma_callback(int lch,
  842. void (*callback)(int lch, u16 ch_status, void *data),
  843. void *data)
  844. {
  845. unsigned long flags;
  846. if (lch < 0)
  847. return -ENODEV;
  848. spin_lock_irqsave(&dma_chan_lock, flags);
  849. if (dma_chan[lch].dev_id == -1) {
  850. printk(KERN_ERR "DMA callback for not set for free channel\n");
  851. spin_unlock_irqrestore(&dma_chan_lock, flags);
  852. return -EINVAL;
  853. }
  854. dma_chan[lch].callback = callback;
  855. dma_chan[lch].data = data;
  856. spin_unlock_irqrestore(&dma_chan_lock, flags);
  857. return 0;
  858. }
  859. EXPORT_SYMBOL(omap_set_dma_callback);
  860. /*
  861. * Returns current physical source address for the given DMA channel.
  862. * If the channel is running the caller must disable interrupts prior calling
  863. * this function and process the returned value before re-enabling interrupt to
  864. * prevent races with the interrupt handler. Note that in continuous mode there
  865. * is a chance for CSSA_L register overflow inbetween the two reads resulting
  866. * in incorrect return value.
  867. */
  868. dma_addr_t omap_get_dma_src_pos(int lch)
  869. {
  870. dma_addr_t offset = 0;
  871. if (cpu_is_omap15xx())
  872. offset = dma_read(CPC(lch));
  873. else
  874. offset = dma_read(CSAC(lch));
  875. /*
  876. * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
  877. * read before the DMA controller finished disabling the channel.
  878. */
  879. if (!cpu_is_omap15xx() && offset == 0)
  880. offset = dma_read(CSAC(lch));
  881. if (cpu_class_is_omap1())
  882. offset |= (dma_read(CSSA_U(lch)) << 16);
  883. return offset;
  884. }
  885. EXPORT_SYMBOL(omap_get_dma_src_pos);
  886. /*
  887. * Returns current physical destination address for the given DMA channel.
  888. * If the channel is running the caller must disable interrupts prior calling
  889. * this function and process the returned value before re-enabling interrupt to
  890. * prevent races with the interrupt handler. Note that in continuous mode there
  891. * is a chance for CDSA_L register overflow inbetween the two reads resulting
  892. * in incorrect return value.
  893. */
  894. dma_addr_t omap_get_dma_dst_pos(int lch)
  895. {
  896. dma_addr_t offset = 0;
  897. if (cpu_is_omap15xx())
  898. offset = dma_read(CPC(lch));
  899. else
  900. offset = dma_read(CDAC(lch));
  901. /*
  902. * omap 3.2/3.3 erratum: sometimes 0 is returned if CSAC/CDAC is
  903. * read before the DMA controller finished disabling the channel.
  904. */
  905. if (!cpu_is_omap15xx() && offset == 0)
  906. offset = dma_read(CDAC(lch));
  907. if (cpu_class_is_omap1())
  908. offset |= (dma_read(CDSA_U(lch)) << 16);
  909. return offset;
  910. }
  911. EXPORT_SYMBOL(omap_get_dma_dst_pos);
  912. int omap_get_dma_active_status(int lch)
  913. {
  914. return (dma_read(CCR(lch)) & OMAP_DMA_CCR_EN) != 0;
  915. }
  916. EXPORT_SYMBOL(omap_get_dma_active_status);
  917. int omap_dma_running(void)
  918. {
  919. int lch;
  920. /* Check if LCD DMA is running */
  921. if (cpu_is_omap16xx())
  922. if (omap_readw(OMAP1610_DMA_LCD_CCR) & OMAP_DMA_CCR_EN)
  923. return 1;
  924. for (lch = 0; lch < dma_chan_count; lch++)
  925. if (dma_read(CCR(lch)) & OMAP_DMA_CCR_EN)
  926. return 1;
  927. return 0;
  928. }
  929. /*
  930. * lch_queue DMA will start right after lch_head one is finished.
  931. * For this DMA link to start, you still need to start (see omap_start_dma)
  932. * the first one. That will fire up the entire queue.
  933. */
  934. void omap_dma_link_lch(int lch_head, int lch_queue)
  935. {
  936. if (omap_dma_in_1510_mode()) {
  937. printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
  938. BUG();
  939. return;
  940. }
  941. if ((dma_chan[lch_head].dev_id == -1) ||
  942. (dma_chan[lch_queue].dev_id == -1)) {
  943. printk(KERN_ERR "omap_dma: trying to link "
  944. "non requested channels\n");
  945. dump_stack();
  946. }
  947. dma_chan[lch_head].next_lch = lch_queue;
  948. }
  949. EXPORT_SYMBOL(omap_dma_link_lch);
  950. /*
  951. * Once the DMA queue is stopped, we can destroy it.
  952. */
  953. void omap_dma_unlink_lch(int lch_head, int lch_queue)
  954. {
  955. if (omap_dma_in_1510_mode()) {
  956. printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
  957. BUG();
  958. return;
  959. }
  960. if (dma_chan[lch_head].next_lch != lch_queue ||
  961. dma_chan[lch_head].next_lch == -1) {
  962. printk(KERN_ERR "omap_dma: trying to unlink "
  963. "non linked channels\n");
  964. dump_stack();
  965. }
  966. if ((dma_chan[lch_head].flags & OMAP_DMA_ACTIVE) ||
  967. (dma_chan[lch_head].flags & OMAP_DMA_ACTIVE)) {
  968. printk(KERN_ERR "omap_dma: You need to stop the DMA channels "
  969. "before unlinking\n");
  970. dump_stack();
  971. }
  972. dma_chan[lch_head].next_lch = -1;
  973. }
  974. EXPORT_SYMBOL(omap_dma_unlink_lch);
  975. /*----------------------------------------------------------------------------*/
  976. #ifndef CONFIG_ARCH_OMAP1
  977. /* Create chain of DMA channesls */
  978. static void create_dma_lch_chain(int lch_head, int lch_queue)
  979. {
  980. u32 l;
  981. /* Check if this is the first link in chain */
  982. if (dma_chan[lch_head].next_linked_ch == -1) {
  983. dma_chan[lch_head].next_linked_ch = lch_queue;
  984. dma_chan[lch_head].prev_linked_ch = lch_queue;
  985. dma_chan[lch_queue].next_linked_ch = lch_head;
  986. dma_chan[lch_queue].prev_linked_ch = lch_head;
  987. }
  988. /* a link exists, link the new channel in circular chain */
  989. else {
  990. dma_chan[lch_queue].next_linked_ch =
  991. dma_chan[lch_head].next_linked_ch;
  992. dma_chan[lch_queue].prev_linked_ch = lch_head;
  993. dma_chan[lch_head].next_linked_ch = lch_queue;
  994. dma_chan[dma_chan[lch_queue].next_linked_ch].prev_linked_ch =
  995. lch_queue;
  996. }
  997. l = dma_read(CLNK_CTRL(lch_head));
  998. l &= ~(0x1f);
  999. l |= lch_queue;
  1000. dma_write(l, CLNK_CTRL(lch_head));
  1001. l = dma_read(CLNK_CTRL(lch_queue));
  1002. l &= ~(0x1f);
  1003. l |= (dma_chan[lch_queue].next_linked_ch);
  1004. dma_write(l, CLNK_CTRL(lch_queue));
  1005. }
  1006. /**
  1007. * @brief omap_request_dma_chain : Request a chain of DMA channels
  1008. *
  1009. * @param dev_id - Device id using the dma channel
  1010. * @param dev_name - Device name
  1011. * @param callback - Call back function
  1012. * @chain_id -
  1013. * @no_of_chans - Number of channels requested
  1014. * @chain_mode - Dynamic or static chaining : OMAP_DMA_STATIC_CHAIN
  1015. * OMAP_DMA_DYNAMIC_CHAIN
  1016. * @params - Channel parameters
  1017. *
  1018. * @return - Succes : 0
  1019. * Failure: -EINVAL/-ENOMEM
  1020. */
  1021. int omap_request_dma_chain(int dev_id, const char *dev_name,
  1022. void (*callback) (int lch, u16 ch_status,
  1023. void *data),
  1024. int *chain_id, int no_of_chans, int chain_mode,
  1025. struct omap_dma_channel_params params)
  1026. {
  1027. int *channels;
  1028. int i, err;
  1029. /* Is the chain mode valid ? */
  1030. if (chain_mode != OMAP_DMA_STATIC_CHAIN
  1031. && chain_mode != OMAP_DMA_DYNAMIC_CHAIN) {
  1032. printk(KERN_ERR "Invalid chain mode requested\n");
  1033. return -EINVAL;
  1034. }
  1035. if (unlikely((no_of_chans < 1
  1036. || no_of_chans > dma_lch_count))) {
  1037. printk(KERN_ERR "Invalid Number of channels requested\n");
  1038. return -EINVAL;
  1039. }
  1040. /* Allocate a queue to maintain the status of the channels
  1041. * in the chain */
  1042. channels = kmalloc(sizeof(*channels) * no_of_chans, GFP_KERNEL);
  1043. if (channels == NULL) {
  1044. printk(KERN_ERR "omap_dma: No memory for channel queue\n");
  1045. return -ENOMEM;
  1046. }
  1047. /* request and reserve DMA channels for the chain */
  1048. for (i = 0; i < no_of_chans; i++) {
  1049. err = omap_request_dma(dev_id, dev_name,
  1050. callback, NULL, &channels[i]);
  1051. if (err < 0) {
  1052. int j;
  1053. for (j = 0; j < i; j++)
  1054. omap_free_dma(channels[j]);
  1055. kfree(channels);
  1056. printk(KERN_ERR "omap_dma: Request failed %d\n", err);
  1057. return err;
  1058. }
  1059. dma_chan[channels[i]].prev_linked_ch = -1;
  1060. dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
  1061. /*
  1062. * Allowing client drivers to set common parameters now,
  1063. * so that later only relevant (src_start, dest_start
  1064. * and element count) can be set
  1065. */
  1066. omap_set_dma_params(channels[i], &params);
  1067. }
  1068. *chain_id = channels[0];
  1069. dma_linked_lch[*chain_id].linked_dmach_q = channels;
  1070. dma_linked_lch[*chain_id].chain_mode = chain_mode;
  1071. dma_linked_lch[*chain_id].chain_state = DMA_CHAIN_NOTSTARTED;
  1072. dma_linked_lch[*chain_id].no_of_lchs_linked = no_of_chans;
  1073. for (i = 0; i < no_of_chans; i++)
  1074. dma_chan[channels[i]].chain_id = *chain_id;
  1075. /* Reset the Queue pointers */
  1076. OMAP_DMA_CHAIN_QINIT(*chain_id);
  1077. /* Set up the chain */
  1078. if (no_of_chans == 1)
  1079. create_dma_lch_chain(channels[0], channels[0]);
  1080. else {
  1081. for (i = 0; i < (no_of_chans - 1); i++)
  1082. create_dma_lch_chain(channels[i], channels[i + 1]);
  1083. }
  1084. return 0;
  1085. }
  1086. EXPORT_SYMBOL(omap_request_dma_chain);
  1087. /**
  1088. * @brief omap_modify_dma_chain_param : Modify the chain's params - Modify the
  1089. * params after setting it. Dont do this while dma is running!!
  1090. *
  1091. * @param chain_id - Chained logical channel id.
  1092. * @param params
  1093. *
  1094. * @return - Success : 0
  1095. * Failure : -EINVAL
  1096. */
  1097. int omap_modify_dma_chain_params(int chain_id,
  1098. struct omap_dma_channel_params params)
  1099. {
  1100. int *channels;
  1101. u32 i;
  1102. /* Check for input params */
  1103. if (unlikely((chain_id < 0
  1104. || chain_id >= dma_lch_count))) {
  1105. printk(KERN_ERR "Invalid chain id\n");
  1106. return -EINVAL;
  1107. }
  1108. /* Check if the chain exists */
  1109. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1110. printk(KERN_ERR "Chain doesn't exists\n");
  1111. return -EINVAL;
  1112. }
  1113. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1114. for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
  1115. /*
  1116. * Allowing client drivers to set common parameters now,
  1117. * so that later only relevant (src_start, dest_start
  1118. * and element count) can be set
  1119. */
  1120. omap_set_dma_params(channels[i], &params);
  1121. }
  1122. return 0;
  1123. }
  1124. EXPORT_SYMBOL(omap_modify_dma_chain_params);
  1125. /**
  1126. * @brief omap_free_dma_chain - Free all the logical channels in a chain.
  1127. *
  1128. * @param chain_id
  1129. *
  1130. * @return - Success : 0
  1131. * Failure : -EINVAL
  1132. */
  1133. int omap_free_dma_chain(int chain_id)
  1134. {
  1135. int *channels;
  1136. u32 i;
  1137. /* Check for input params */
  1138. if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
  1139. printk(KERN_ERR "Invalid chain id\n");
  1140. return -EINVAL;
  1141. }
  1142. /* Check if the chain exists */
  1143. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1144. printk(KERN_ERR "Chain doesn't exists\n");
  1145. return -EINVAL;
  1146. }
  1147. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1148. for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
  1149. dma_chan[channels[i]].next_linked_ch = -1;
  1150. dma_chan[channels[i]].prev_linked_ch = -1;
  1151. dma_chan[channels[i]].chain_id = -1;
  1152. dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
  1153. omap_free_dma(channels[i]);
  1154. }
  1155. kfree(channels);
  1156. dma_linked_lch[chain_id].linked_dmach_q = NULL;
  1157. dma_linked_lch[chain_id].chain_mode = -1;
  1158. dma_linked_lch[chain_id].chain_state = -1;
  1159. return (0);
  1160. }
  1161. EXPORT_SYMBOL(omap_free_dma_chain);
  1162. /**
  1163. * @brief omap_dma_chain_status - Check if the chain is in
  1164. * active / inactive state.
  1165. * @param chain_id
  1166. *
  1167. * @return - Success : OMAP_DMA_CHAIN_ACTIVE/OMAP_DMA_CHAIN_INACTIVE
  1168. * Failure : -EINVAL
  1169. */
  1170. int omap_dma_chain_status(int chain_id)
  1171. {
  1172. /* Check for input params */
  1173. if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
  1174. printk(KERN_ERR "Invalid chain id\n");
  1175. return -EINVAL;
  1176. }
  1177. /* Check if the chain exists */
  1178. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1179. printk(KERN_ERR "Chain doesn't exists\n");
  1180. return -EINVAL;
  1181. }
  1182. pr_debug("CHAINID=%d, qcnt=%d\n", chain_id,
  1183. dma_linked_lch[chain_id].q_count);
  1184. if (OMAP_DMA_CHAIN_QEMPTY(chain_id))
  1185. return OMAP_DMA_CHAIN_INACTIVE;
  1186. return OMAP_DMA_CHAIN_ACTIVE;
  1187. }
  1188. EXPORT_SYMBOL(omap_dma_chain_status);
  1189. /**
  1190. * @brief omap_dma_chain_a_transfer - Get a free channel from a chain,
  1191. * set the params and start the transfer.
  1192. *
  1193. * @param chain_id
  1194. * @param src_start - buffer start address
  1195. * @param dest_start - Dest address
  1196. * @param elem_count
  1197. * @param frame_count
  1198. * @param callbk_data - channel callback parameter data.
  1199. *
  1200. * @return - Success : 0
  1201. * Failure: -EINVAL/-EBUSY
  1202. */
  1203. int omap_dma_chain_a_transfer(int chain_id, int src_start, int dest_start,
  1204. int elem_count, int frame_count, void *callbk_data)
  1205. {
  1206. int *channels;
  1207. u32 l, lch;
  1208. int start_dma = 0;
  1209. /*
  1210. * if buffer size is less than 1 then there is
  1211. * no use of starting the chain
  1212. */
  1213. if (elem_count < 1) {
  1214. printk(KERN_ERR "Invalid buffer size\n");
  1215. return -EINVAL;
  1216. }
  1217. /* Check for input params */
  1218. if (unlikely((chain_id < 0
  1219. || chain_id >= dma_lch_count))) {
  1220. printk(KERN_ERR "Invalid chain id\n");
  1221. return -EINVAL;
  1222. }
  1223. /* Check if the chain exists */
  1224. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1225. printk(KERN_ERR "Chain doesn't exist\n");
  1226. return -EINVAL;
  1227. }
  1228. /* Check if all the channels in chain are in use */
  1229. if (OMAP_DMA_CHAIN_QFULL(chain_id))
  1230. return -EBUSY;
  1231. /* Frame count may be negative in case of indexed transfers */
  1232. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1233. /* Get a free channel */
  1234. lch = channels[dma_linked_lch[chain_id].q_tail];
  1235. /* Store the callback data */
  1236. dma_chan[lch].data = callbk_data;
  1237. /* Increment the q_tail */
  1238. OMAP_DMA_CHAIN_INCQTAIL(chain_id);
  1239. /* Set the params to the free channel */
  1240. if (src_start != 0)
  1241. dma_write(src_start, CSSA(lch));
  1242. if (dest_start != 0)
  1243. dma_write(dest_start, CDSA(lch));
  1244. /* Write the buffer size */
  1245. dma_write(elem_count, CEN(lch));
  1246. dma_write(frame_count, CFN(lch));
  1247. /*
  1248. * If the chain is dynamically linked,
  1249. * then we may have to start the chain if its not active
  1250. */
  1251. if (dma_linked_lch[chain_id].chain_mode == OMAP_DMA_DYNAMIC_CHAIN) {
  1252. /*
  1253. * In Dynamic chain, if the chain is not started,
  1254. * queue the channel
  1255. */
  1256. if (dma_linked_lch[chain_id].chain_state ==
  1257. DMA_CHAIN_NOTSTARTED) {
  1258. /* Enable the link in previous channel */
  1259. if (dma_chan[dma_chan[lch].prev_linked_ch].state ==
  1260. DMA_CH_QUEUED)
  1261. enable_lnk(dma_chan[lch].prev_linked_ch);
  1262. dma_chan[lch].state = DMA_CH_QUEUED;
  1263. }
  1264. /*
  1265. * Chain is already started, make sure its active,
  1266. * if not then start the chain
  1267. */
  1268. else {
  1269. start_dma = 1;
  1270. if (dma_chan[dma_chan[lch].prev_linked_ch].state ==
  1271. DMA_CH_STARTED) {
  1272. enable_lnk(dma_chan[lch].prev_linked_ch);
  1273. dma_chan[lch].state = DMA_CH_QUEUED;
  1274. start_dma = 0;
  1275. if (0 == ((1 << 7) & dma_read(
  1276. CCR(dma_chan[lch].prev_linked_ch)))) {
  1277. disable_lnk(dma_chan[lch].
  1278. prev_linked_ch);
  1279. pr_debug("\n prev ch is stopped\n");
  1280. start_dma = 1;
  1281. }
  1282. }
  1283. else if (dma_chan[dma_chan[lch].prev_linked_ch].state
  1284. == DMA_CH_QUEUED) {
  1285. enable_lnk(dma_chan[lch].prev_linked_ch);
  1286. dma_chan[lch].state = DMA_CH_QUEUED;
  1287. start_dma = 0;
  1288. }
  1289. omap_enable_channel_irq(lch);
  1290. l = dma_read(CCR(lch));
  1291. if ((0 == (l & (1 << 24))))
  1292. l &= ~(1 << 25);
  1293. else
  1294. l |= (1 << 25);
  1295. if (start_dma == 1) {
  1296. if (0 == (l & (1 << 7))) {
  1297. l |= (1 << 7);
  1298. dma_chan[lch].state = DMA_CH_STARTED;
  1299. pr_debug("starting %d\n", lch);
  1300. dma_write(l, CCR(lch));
  1301. } else
  1302. start_dma = 0;
  1303. } else {
  1304. if (0 == (l & (1 << 7)))
  1305. dma_write(l, CCR(lch));
  1306. }
  1307. dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
  1308. }
  1309. }
  1310. return 0;
  1311. }
  1312. EXPORT_SYMBOL(omap_dma_chain_a_transfer);
  1313. /**
  1314. * @brief omap_start_dma_chain_transfers - Start the chain
  1315. *
  1316. * @param chain_id
  1317. *
  1318. * @return - Success : 0
  1319. * Failure : -EINVAL/-EBUSY
  1320. */
  1321. int omap_start_dma_chain_transfers(int chain_id)
  1322. {
  1323. int *channels;
  1324. u32 l, i;
  1325. if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
  1326. printk(KERN_ERR "Invalid chain id\n");
  1327. return -EINVAL;
  1328. }
  1329. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1330. if (dma_linked_lch[channels[0]].chain_state == DMA_CHAIN_STARTED) {
  1331. printk(KERN_ERR "Chain is already started\n");
  1332. return -EBUSY;
  1333. }
  1334. if (dma_linked_lch[chain_id].chain_mode == OMAP_DMA_STATIC_CHAIN) {
  1335. for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked;
  1336. i++) {
  1337. enable_lnk(channels[i]);
  1338. omap_enable_channel_irq(channels[i]);
  1339. }
  1340. } else {
  1341. omap_enable_channel_irq(channels[0]);
  1342. }
  1343. l = dma_read(CCR(channels[0]));
  1344. l |= (1 << 7);
  1345. dma_linked_lch[chain_id].chain_state = DMA_CHAIN_STARTED;
  1346. dma_chan[channels[0]].state = DMA_CH_STARTED;
  1347. if ((0 == (l & (1 << 24))))
  1348. l &= ~(1 << 25);
  1349. else
  1350. l |= (1 << 25);
  1351. dma_write(l, CCR(channels[0]));
  1352. dma_chan[channels[0]].flags |= OMAP_DMA_ACTIVE;
  1353. return 0;
  1354. }
  1355. EXPORT_SYMBOL(omap_start_dma_chain_transfers);
  1356. /**
  1357. * @brief omap_stop_dma_chain_transfers - Stop the dma transfer of a chain.
  1358. *
  1359. * @param chain_id
  1360. *
  1361. * @return - Success : 0
  1362. * Failure : EINVAL
  1363. */
  1364. int omap_stop_dma_chain_transfers(int chain_id)
  1365. {
  1366. int *channels;
  1367. u32 l, i;
  1368. u32 sys_cf;
  1369. /* Check for input params */
  1370. if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
  1371. printk(KERN_ERR "Invalid chain id\n");
  1372. return -EINVAL;
  1373. }
  1374. /* Check if the chain exists */
  1375. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1376. printk(KERN_ERR "Chain doesn't exists\n");
  1377. return -EINVAL;
  1378. }
  1379. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1380. /*
  1381. * DMA Errata:
  1382. * Special programming model needed to disable DMA before end of block
  1383. */
  1384. sys_cf = dma_read(OCP_SYSCONFIG);
  1385. l = sys_cf;
  1386. /* Middle mode reg set no Standby */
  1387. l &= ~((1 << 12)|(1 << 13));
  1388. dma_write(l, OCP_SYSCONFIG);
  1389. for (i = 0; i < dma_linked_lch[chain_id].no_of_lchs_linked; i++) {
  1390. /* Stop the Channel transmission */
  1391. l = dma_read(CCR(channels[i]));
  1392. l &= ~(1 << 7);
  1393. dma_write(l, CCR(channels[i]));
  1394. /* Disable the link in all the channels */
  1395. disable_lnk(channels[i]);
  1396. dma_chan[channels[i]].state = DMA_CH_NOTSTARTED;
  1397. }
  1398. dma_linked_lch[chain_id].chain_state = DMA_CHAIN_NOTSTARTED;
  1399. /* Reset the Queue pointers */
  1400. OMAP_DMA_CHAIN_QINIT(chain_id);
  1401. /* Errata - put in the old value */
  1402. dma_write(sys_cf, OCP_SYSCONFIG);
  1403. return 0;
  1404. }
  1405. EXPORT_SYMBOL(omap_stop_dma_chain_transfers);
  1406. /* Get the index of the ongoing DMA in chain */
  1407. /**
  1408. * @brief omap_get_dma_chain_index - Get the element and frame index
  1409. * of the ongoing DMA in chain
  1410. *
  1411. * @param chain_id
  1412. * @param ei - Element index
  1413. * @param fi - Frame index
  1414. *
  1415. * @return - Success : 0
  1416. * Failure : -EINVAL
  1417. */
  1418. int omap_get_dma_chain_index(int chain_id, int *ei, int *fi)
  1419. {
  1420. int lch;
  1421. int *channels;
  1422. /* Check for input params */
  1423. if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
  1424. printk(KERN_ERR "Invalid chain id\n");
  1425. return -EINVAL;
  1426. }
  1427. /* Check if the chain exists */
  1428. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1429. printk(KERN_ERR "Chain doesn't exists\n");
  1430. return -EINVAL;
  1431. }
  1432. if ((!ei) || (!fi))
  1433. return -EINVAL;
  1434. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1435. /* Get the current channel */
  1436. lch = channels[dma_linked_lch[chain_id].q_head];
  1437. *ei = dma_read(CCEN(lch));
  1438. *fi = dma_read(CCFN(lch));
  1439. return 0;
  1440. }
  1441. EXPORT_SYMBOL(omap_get_dma_chain_index);
  1442. /**
  1443. * @brief omap_get_dma_chain_dst_pos - Get the destination position of the
  1444. * ongoing DMA in chain
  1445. *
  1446. * @param chain_id
  1447. *
  1448. * @return - Success : Destination position
  1449. * Failure : -EINVAL
  1450. */
  1451. int omap_get_dma_chain_dst_pos(int chain_id)
  1452. {
  1453. int lch;
  1454. int *channels;
  1455. /* Check for input params */
  1456. if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
  1457. printk(KERN_ERR "Invalid chain id\n");
  1458. return -EINVAL;
  1459. }
  1460. /* Check if the chain exists */
  1461. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1462. printk(KERN_ERR "Chain doesn't exists\n");
  1463. return -EINVAL;
  1464. }
  1465. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1466. /* Get the current channel */
  1467. lch = channels[dma_linked_lch[chain_id].q_head];
  1468. return dma_read(CDAC(lch));
  1469. }
  1470. EXPORT_SYMBOL(omap_get_dma_chain_dst_pos);
  1471. /**
  1472. * @brief omap_get_dma_chain_src_pos - Get the source position
  1473. * of the ongoing DMA in chain
  1474. * @param chain_id
  1475. *
  1476. * @return - Success : Destination position
  1477. * Failure : -EINVAL
  1478. */
  1479. int omap_get_dma_chain_src_pos(int chain_id)
  1480. {
  1481. int lch;
  1482. int *channels;
  1483. /* Check for input params */
  1484. if (unlikely((chain_id < 0 || chain_id >= dma_lch_count))) {
  1485. printk(KERN_ERR "Invalid chain id\n");
  1486. return -EINVAL;
  1487. }
  1488. /* Check if the chain exists */
  1489. if (dma_linked_lch[chain_id].linked_dmach_q == NULL) {
  1490. printk(KERN_ERR "Chain doesn't exists\n");
  1491. return -EINVAL;
  1492. }
  1493. channels = dma_linked_lch[chain_id].linked_dmach_q;
  1494. /* Get the current channel */
  1495. lch = channels[dma_linked_lch[chain_id].q_head];
  1496. return dma_read(CSAC(lch));
  1497. }
  1498. EXPORT_SYMBOL(omap_get_dma_chain_src_pos);
  1499. #endif /* ifndef CONFIG_ARCH_OMAP1 */
  1500. /*----------------------------------------------------------------------------*/
  1501. #ifdef CONFIG_ARCH_OMAP1
  1502. static int omap1_dma_handle_ch(int ch)
  1503. {
  1504. u32 csr;
  1505. if (enable_1510_mode && ch >= 6) {
  1506. csr = dma_chan[ch].saved_csr;
  1507. dma_chan[ch].saved_csr = 0;
  1508. } else
  1509. csr = dma_read(CSR(ch));
  1510. if (enable_1510_mode && ch <= 2 && (csr >> 7) != 0) {
  1511. dma_chan[ch + 6].saved_csr = csr >> 7;
  1512. csr &= 0x7f;
  1513. }
  1514. if ((csr & 0x3f) == 0)
  1515. return 0;
  1516. if (unlikely(dma_chan[ch].dev_id == -1)) {
  1517. printk(KERN_WARNING "Spurious interrupt from DMA channel "
  1518. "%d (CSR %04x)\n", ch, csr);
  1519. return 0;
  1520. }
  1521. if (unlikely(csr & OMAP1_DMA_TOUT_IRQ))
  1522. printk(KERN_WARNING "DMA timeout with device %d\n",
  1523. dma_chan[ch].dev_id);
  1524. if (unlikely(csr & OMAP_DMA_DROP_IRQ))
  1525. printk(KERN_WARNING "DMA synchronization event drop occurred "
  1526. "with device %d\n", dma_chan[ch].dev_id);
  1527. if (likely(csr & OMAP_DMA_BLOCK_IRQ))
  1528. dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
  1529. if (likely(dma_chan[ch].callback != NULL))
  1530. dma_chan[ch].callback(ch, csr, dma_chan[ch].data);
  1531. return 1;
  1532. }
  1533. static irqreturn_t omap1_dma_irq_handler(int irq, void *dev_id)
  1534. {
  1535. int ch = ((int) dev_id) - 1;
  1536. int handled = 0;
  1537. for (;;) {
  1538. int handled_now = 0;
  1539. handled_now += omap1_dma_handle_ch(ch);
  1540. if (enable_1510_mode && dma_chan[ch + 6].saved_csr)
  1541. handled_now += omap1_dma_handle_ch(ch + 6);
  1542. if (!handled_now)
  1543. break;
  1544. handled += handled_now;
  1545. }
  1546. return handled ? IRQ_HANDLED : IRQ_NONE;
  1547. }
  1548. #else
  1549. #define omap1_dma_irq_handler NULL
  1550. #endif
  1551. #if defined(CONFIG_ARCH_OMAP2) || defined(CONFIG_ARCH_OMAP3) || \
  1552. defined(CONFIG_ARCH_OMAP4)
  1553. static int omap2_dma_handle_ch(int ch)
  1554. {
  1555. u32 status = dma_read(CSR(ch));
  1556. if (!status) {
  1557. if (printk_ratelimit())
  1558. printk(KERN_WARNING "Spurious DMA IRQ for lch %d\n",
  1559. ch);
  1560. dma_write(1 << ch, IRQSTATUS_L0);
  1561. return 0;
  1562. }
  1563. if (unlikely(dma_chan[ch].dev_id == -1)) {
  1564. if (printk_ratelimit())
  1565. printk(KERN_WARNING "IRQ %04x for non-allocated DMA"
  1566. "channel %d\n", status, ch);
  1567. return 0;
  1568. }
  1569. if (unlikely(status & OMAP_DMA_DROP_IRQ))
  1570. printk(KERN_INFO
  1571. "DMA synchronization event drop occurred with device "
  1572. "%d\n", dma_chan[ch].dev_id);
  1573. if (unlikely(status & OMAP2_DMA_TRANS_ERR_IRQ)) {
  1574. printk(KERN_INFO "DMA transaction error with device %d\n",
  1575. dma_chan[ch].dev_id);
  1576. if (cpu_class_is_omap2()) {
  1577. /* Errata: sDMA Channel is not disabled
  1578. * after a transaction error. So we explicitely
  1579. * disable the channel
  1580. */
  1581. u32 ccr;
  1582. ccr = dma_read(CCR(ch));
  1583. ccr &= ~OMAP_DMA_CCR_EN;
  1584. dma_write(ccr, CCR(ch));
  1585. dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
  1586. }
  1587. }
  1588. if (unlikely(status & OMAP2_DMA_SECURE_ERR_IRQ))
  1589. printk(KERN_INFO "DMA secure error with device %d\n",
  1590. dma_chan[ch].dev_id);
  1591. if (unlikely(status & OMAP2_DMA_MISALIGNED_ERR_IRQ))
  1592. printk(KERN_INFO "DMA misaligned error with device %d\n",
  1593. dma_chan[ch].dev_id);
  1594. dma_write(OMAP2_DMA_CSR_CLEAR_MASK, CSR(ch));
  1595. dma_write(1 << ch, IRQSTATUS_L0);
  1596. /* If the ch is not chained then chain_id will be -1 */
  1597. if (dma_chan[ch].chain_id != -1) {
  1598. int chain_id = dma_chan[ch].chain_id;
  1599. dma_chan[ch].state = DMA_CH_NOTSTARTED;
  1600. if (dma_read(CLNK_CTRL(ch)) & (1 << 15))
  1601. dma_chan[dma_chan[ch].next_linked_ch].state =
  1602. DMA_CH_STARTED;
  1603. if (dma_linked_lch[chain_id].chain_mode ==
  1604. OMAP_DMA_DYNAMIC_CHAIN)
  1605. disable_lnk(ch);
  1606. if (!OMAP_DMA_CHAIN_QEMPTY(chain_id))
  1607. OMAP_DMA_CHAIN_INCQHEAD(chain_id);
  1608. status = dma_read(CSR(ch));
  1609. }
  1610. dma_write(status, CSR(ch));
  1611. if (likely(dma_chan[ch].callback != NULL))
  1612. dma_chan[ch].callback(ch, status, dma_chan[ch].data);
  1613. return 0;
  1614. }
  1615. /* STATUS register count is from 1-32 while our is 0-31 */
  1616. static irqreturn_t omap2_dma_irq_handler(int irq, void *dev_id)
  1617. {
  1618. u32 val, enable_reg;
  1619. int i;
  1620. val = dma_read(IRQSTATUS_L0);
  1621. if (val == 0) {
  1622. if (printk_ratelimit())
  1623. printk(KERN_WARNING "Spurious DMA IRQ\n");
  1624. return IRQ_HANDLED;
  1625. }
  1626. enable_reg = dma_read(IRQENABLE_L0);
  1627. val &= enable_reg; /* Dispatch only relevant interrupts */
  1628. for (i = 0; i < dma_lch_count && val != 0; i++) {
  1629. if (val & 1)
  1630. omap2_dma_handle_ch(i);
  1631. val >>= 1;
  1632. }
  1633. return IRQ_HANDLED;
  1634. }
  1635. static struct irqaction omap24xx_dma_irq = {
  1636. .name = "DMA",
  1637. .handler = omap2_dma_irq_handler,
  1638. .flags = IRQF_DISABLED
  1639. };
  1640. #else
  1641. static struct irqaction omap24xx_dma_irq;
  1642. #endif
  1643. /*----------------------------------------------------------------------------*/
  1644. static struct lcd_dma_info {
  1645. spinlock_t lock;
  1646. int reserved;
  1647. void (*callback)(u16 status, void *data);
  1648. void *cb_data;
  1649. int active;
  1650. unsigned long addr, size;
  1651. int rotate, data_type, xres, yres;
  1652. int vxres;
  1653. int mirror;
  1654. int xscale, yscale;
  1655. int ext_ctrl;
  1656. int src_port;
  1657. int single_transfer;
  1658. } lcd_dma;
  1659. void omap_set_lcd_dma_b1(unsigned long addr, u16 fb_xres, u16 fb_yres,
  1660. int data_type)
  1661. {
  1662. lcd_dma.addr = addr;
  1663. lcd_dma.data_type = data_type;
  1664. lcd_dma.xres = fb_xres;
  1665. lcd_dma.yres = fb_yres;
  1666. }
  1667. EXPORT_SYMBOL(omap_set_lcd_dma_b1);
  1668. void omap_set_lcd_dma_src_port(int port)
  1669. {
  1670. lcd_dma.src_port = port;
  1671. }
  1672. void omap_set_lcd_dma_ext_controller(int external)
  1673. {
  1674. lcd_dma.ext_ctrl = external;
  1675. }
  1676. EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller);
  1677. void omap_set_lcd_dma_single_transfer(int single)
  1678. {
  1679. lcd_dma.single_transfer = single;
  1680. }
  1681. EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer);
  1682. void omap_set_lcd_dma_b1_rotation(int rotate)
  1683. {
  1684. if (omap_dma_in_1510_mode()) {
  1685. printk(KERN_ERR "DMA rotation is not supported in 1510 mode\n");
  1686. BUG();
  1687. return;
  1688. }
  1689. lcd_dma.rotate = rotate;
  1690. }
  1691. EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation);
  1692. void omap_set_lcd_dma_b1_mirror(int mirror)
  1693. {
  1694. if (omap_dma_in_1510_mode()) {
  1695. printk(KERN_ERR "DMA mirror is not supported in 1510 mode\n");
  1696. BUG();
  1697. }
  1698. lcd_dma.mirror = mirror;
  1699. }
  1700. EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror);
  1701. void omap_set_lcd_dma_b1_vxres(unsigned long vxres)
  1702. {
  1703. if (omap_dma_in_1510_mode()) {
  1704. printk(KERN_ERR "DMA virtual resulotion is not supported "
  1705. "in 1510 mode\n");
  1706. BUG();
  1707. }
  1708. lcd_dma.vxres = vxres;
  1709. }
  1710. EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres);
  1711. void omap_set_lcd_dma_b1_scale(unsigned int xscale, unsigned int yscale)
  1712. {
  1713. if (omap_dma_in_1510_mode()) {
  1714. printk(KERN_ERR "DMA scale is not supported in 1510 mode\n");
  1715. BUG();
  1716. }
  1717. lcd_dma.xscale = xscale;
  1718. lcd_dma.yscale = yscale;
  1719. }
  1720. EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale);
  1721. static void set_b1_regs(void)
  1722. {
  1723. unsigned long top, bottom;
  1724. int es;
  1725. u16 w;
  1726. unsigned long en, fn;
  1727. long ei, fi;
  1728. unsigned long vxres;
  1729. unsigned int xscale, yscale;
  1730. switch (lcd_dma.data_type) {
  1731. case OMAP_DMA_DATA_TYPE_S8:
  1732. es = 1;
  1733. break;
  1734. case OMAP_DMA_DATA_TYPE_S16:
  1735. es = 2;
  1736. break;
  1737. case OMAP_DMA_DATA_TYPE_S32:
  1738. es = 4;
  1739. break;
  1740. default:
  1741. BUG();
  1742. return;
  1743. }
  1744. vxres = lcd_dma.vxres ? lcd_dma.vxres : lcd_dma.xres;
  1745. xscale = lcd_dma.xscale ? lcd_dma.xscale : 1;
  1746. yscale = lcd_dma.yscale ? lcd_dma.yscale : 1;
  1747. BUG_ON(vxres < lcd_dma.xres);
  1748. #define PIXADDR(x, y) (lcd_dma.addr + \
  1749. ((y) * vxres * yscale + (x) * xscale) * es)
  1750. #define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
  1751. switch (lcd_dma.rotate) {
  1752. case 0:
  1753. if (!lcd_dma.mirror) {
  1754. top = PIXADDR(0, 0);
  1755. bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  1756. /* 1510 DMA requires the bottom address to be 2 more
  1757. * than the actual last memory access location. */
  1758. if (omap_dma_in_1510_mode() &&
  1759. lcd_dma.data_type == OMAP_DMA_DATA_TYPE_S32)
  1760. bottom += 2;
  1761. ei = PIXSTEP(0, 0, 1, 0);
  1762. fi = PIXSTEP(lcd_dma.xres - 1, 0, 0, 1);
  1763. } else {
  1764. top = PIXADDR(lcd_dma.xres - 1, 0);
  1765. bottom = PIXADDR(0, lcd_dma.yres - 1);
  1766. ei = PIXSTEP(1, 0, 0, 0);
  1767. fi = PIXSTEP(0, 0, lcd_dma.xres - 1, 1);
  1768. }
  1769. en = lcd_dma.xres;
  1770. fn = lcd_dma.yres;
  1771. break;
  1772. case 90:
  1773. if (!lcd_dma.mirror) {
  1774. top = PIXADDR(0, lcd_dma.yres - 1);
  1775. bottom = PIXADDR(lcd_dma.xres - 1, 0);
  1776. ei = PIXSTEP(0, 1, 0, 0);
  1777. fi = PIXSTEP(0, 0, 1, lcd_dma.yres - 1);
  1778. } else {
  1779. top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  1780. bottom = PIXADDR(0, 0);
  1781. ei = PIXSTEP(0, 1, 0, 0);
  1782. fi = PIXSTEP(1, 0, 0, lcd_dma.yres - 1);
  1783. }
  1784. en = lcd_dma.yres;
  1785. fn = lcd_dma.xres;
  1786. break;
  1787. case 180:
  1788. if (!lcd_dma.mirror) {
  1789. top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  1790. bottom = PIXADDR(0, 0);
  1791. ei = PIXSTEP(1, 0, 0, 0);
  1792. fi = PIXSTEP(0, 1, lcd_dma.xres - 1, 0);
  1793. } else {
  1794. top = PIXADDR(0, lcd_dma.yres - 1);
  1795. bottom = PIXADDR(lcd_dma.xres - 1, 0);
  1796. ei = PIXSTEP(0, 0, 1, 0);
  1797. fi = PIXSTEP(lcd_dma.xres - 1, 1, 0, 0);
  1798. }
  1799. en = lcd_dma.xres;
  1800. fn = lcd_dma.yres;
  1801. break;
  1802. case 270:
  1803. if (!lcd_dma.mirror) {
  1804. top = PIXADDR(lcd_dma.xres - 1, 0);
  1805. bottom = PIXADDR(0, lcd_dma.yres - 1);
  1806. ei = PIXSTEP(0, 0, 0, 1);
  1807. fi = PIXSTEP(1, lcd_dma.yres - 1, 0, 0);
  1808. } else {
  1809. top = PIXADDR(0, 0);
  1810. bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  1811. ei = PIXSTEP(0, 0, 0, 1);
  1812. fi = PIXSTEP(0, lcd_dma.yres - 1, 1, 0);
  1813. }
  1814. en = lcd_dma.yres;
  1815. fn = lcd_dma.xres;
  1816. break;
  1817. default:
  1818. BUG();
  1819. return; /* Suppress warning about uninitialized vars */
  1820. }
  1821. if (omap_dma_in_1510_mode()) {
  1822. omap_writew(top >> 16, OMAP1510_DMA_LCD_TOP_F1_U);
  1823. omap_writew(top, OMAP1510_DMA_LCD_TOP_F1_L);
  1824. omap_writew(bottom >> 16, OMAP1510_DMA_LCD_BOT_F1_U);
  1825. omap_writew(bottom, OMAP1510_DMA_LCD_BOT_F1_L);
  1826. return;
  1827. }
  1828. /* 1610 regs */
  1829. omap_writew(top >> 16, OMAP1610_DMA_LCD_TOP_B1_U);
  1830. omap_writew(top, OMAP1610_DMA_LCD_TOP_B1_L);
  1831. omap_writew(bottom >> 16, OMAP1610_DMA_LCD_BOT_B1_U);
  1832. omap_writew(bottom, OMAP1610_DMA_LCD_BOT_B1_L);
  1833. omap_writew(en, OMAP1610_DMA_LCD_SRC_EN_B1);
  1834. omap_writew(fn, OMAP1610_DMA_LCD_SRC_FN_B1);
  1835. w = omap_readw(OMAP1610_DMA_LCD_CSDP);
  1836. w &= ~0x03;
  1837. w |= lcd_dma.data_type;
  1838. omap_writew(w, OMAP1610_DMA_LCD_CSDP);
  1839. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1840. /* Always set the source port as SDRAM for now*/
  1841. w &= ~(0x03 << 6);
  1842. if (lcd_dma.callback != NULL)
  1843. w |= 1 << 1; /* Block interrupt enable */
  1844. else
  1845. w &= ~(1 << 1);
  1846. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1847. if (!(lcd_dma.rotate || lcd_dma.mirror ||
  1848. lcd_dma.vxres || lcd_dma.xscale || lcd_dma.yscale))
  1849. return;
  1850. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1851. /* Set the double-indexed addressing mode */
  1852. w |= (0x03 << 12);
  1853. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1854. omap_writew(ei, OMAP1610_DMA_LCD_SRC_EI_B1);
  1855. omap_writew(fi >> 16, OMAP1610_DMA_LCD_SRC_FI_B1_U);
  1856. omap_writew(fi, OMAP1610_DMA_LCD_SRC_FI_B1_L);
  1857. }
  1858. static irqreturn_t lcd_dma_irq_handler(int irq, void *dev_id)
  1859. {
  1860. u16 w;
  1861. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1862. if (unlikely(!(w & (1 << 3)))) {
  1863. printk(KERN_WARNING "Spurious LCD DMA IRQ\n");
  1864. return IRQ_NONE;
  1865. }
  1866. /* Ack the IRQ */
  1867. w |= (1 << 3);
  1868. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1869. lcd_dma.active = 0;
  1870. if (lcd_dma.callback != NULL)
  1871. lcd_dma.callback(w, lcd_dma.cb_data);
  1872. return IRQ_HANDLED;
  1873. }
  1874. int omap_request_lcd_dma(void (*callback)(u16 status, void *data),
  1875. void *data)
  1876. {
  1877. spin_lock_irq(&lcd_dma.lock);
  1878. if (lcd_dma.reserved) {
  1879. spin_unlock_irq(&lcd_dma.lock);
  1880. printk(KERN_ERR "LCD DMA channel already reserved\n");
  1881. BUG();
  1882. return -EBUSY;
  1883. }
  1884. lcd_dma.reserved = 1;
  1885. spin_unlock_irq(&lcd_dma.lock);
  1886. lcd_dma.callback = callback;
  1887. lcd_dma.cb_data = data;
  1888. lcd_dma.active = 0;
  1889. lcd_dma.single_transfer = 0;
  1890. lcd_dma.rotate = 0;
  1891. lcd_dma.vxres = 0;
  1892. lcd_dma.mirror = 0;
  1893. lcd_dma.xscale = 0;
  1894. lcd_dma.yscale = 0;
  1895. lcd_dma.ext_ctrl = 0;
  1896. lcd_dma.src_port = 0;
  1897. return 0;
  1898. }
  1899. EXPORT_SYMBOL(omap_request_lcd_dma);
  1900. void omap_free_lcd_dma(void)
  1901. {
  1902. spin_lock(&lcd_dma.lock);
  1903. if (!lcd_dma.reserved) {
  1904. spin_unlock(&lcd_dma.lock);
  1905. printk(KERN_ERR "LCD DMA is not reserved\n");
  1906. BUG();
  1907. return;
  1908. }
  1909. if (!enable_1510_mode)
  1910. omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR) & ~1,
  1911. OMAP1610_DMA_LCD_CCR);
  1912. lcd_dma.reserved = 0;
  1913. spin_unlock(&lcd_dma.lock);
  1914. }
  1915. EXPORT_SYMBOL(omap_free_lcd_dma);
  1916. void omap_enable_lcd_dma(void)
  1917. {
  1918. u16 w;
  1919. /*
  1920. * Set the Enable bit only if an external controller is
  1921. * connected. Otherwise the OMAP internal controller will
  1922. * start the transfer when it gets enabled.
  1923. */
  1924. if (enable_1510_mode || !lcd_dma.ext_ctrl)
  1925. return;
  1926. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1927. w |= 1 << 8;
  1928. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1929. lcd_dma.active = 1;
  1930. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1931. w |= 1 << 7;
  1932. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1933. }
  1934. EXPORT_SYMBOL(omap_enable_lcd_dma);
  1935. void omap_setup_lcd_dma(void)
  1936. {
  1937. BUG_ON(lcd_dma.active);
  1938. if (!enable_1510_mode) {
  1939. /* Set some reasonable defaults */
  1940. omap_writew(0x5440, OMAP1610_DMA_LCD_CCR);
  1941. omap_writew(0x9102, OMAP1610_DMA_LCD_CSDP);
  1942. omap_writew(0x0004, OMAP1610_DMA_LCD_LCH_CTRL);
  1943. }
  1944. set_b1_regs();
  1945. if (!enable_1510_mode) {
  1946. u16 w;
  1947. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1948. /*
  1949. * If DMA was already active set the end_prog bit to have
  1950. * the programmed register set loaded into the active
  1951. * register set.
  1952. */
  1953. w |= 1 << 11; /* End_prog */
  1954. if (!lcd_dma.single_transfer)
  1955. w |= (3 << 8); /* Auto_init, repeat */
  1956. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1957. }
  1958. }
  1959. EXPORT_SYMBOL(omap_setup_lcd_dma);
  1960. void omap_stop_lcd_dma(void)
  1961. {
  1962. u16 w;
  1963. lcd_dma.active = 0;
  1964. if (enable_1510_mode || !lcd_dma.ext_ctrl)
  1965. return;
  1966. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1967. w &= ~(1 << 7);
  1968. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1969. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1970. w &= ~(1 << 8);
  1971. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1972. }
  1973. EXPORT_SYMBOL(omap_stop_lcd_dma);
  1974. /*----------------------------------------------------------------------------*/
  1975. static int __init omap_init_dma(void)
  1976. {
  1977. int ch, r;
  1978. if (cpu_class_is_omap1()) {
  1979. omap_dma_base = IO_ADDRESS(OMAP1_DMA_BASE);
  1980. dma_lch_count = OMAP1_LOGICAL_DMA_CH_COUNT;
  1981. } else if (cpu_is_omap24xx()) {
  1982. omap_dma_base = IO_ADDRESS(OMAP24XX_DMA4_BASE);
  1983. dma_lch_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
  1984. } else if (cpu_is_omap34xx()) {
  1985. omap_dma_base = IO_ADDRESS(OMAP34XX_DMA4_BASE);
  1986. dma_lch_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
  1987. } else if (cpu_is_omap44xx()) {
  1988. omap_dma_base = IO_ADDRESS(OMAP44XX_DMA4_BASE);
  1989. dma_lch_count = OMAP_DMA4_LOGICAL_DMA_CH_COUNT;
  1990. } else {
  1991. pr_err("DMA init failed for unsupported omap\n");
  1992. return -ENODEV;
  1993. }
  1994. if (cpu_class_is_omap2() && omap_dma_reserve_channels
  1995. && (omap_dma_reserve_channels <= dma_lch_count))
  1996. dma_lch_count = omap_dma_reserve_channels;
  1997. dma_chan = kzalloc(sizeof(struct omap_dma_lch) * dma_lch_count,
  1998. GFP_KERNEL);
  1999. if (!dma_chan)
  2000. return -ENOMEM;
  2001. if (cpu_class_is_omap2()) {
  2002. dma_linked_lch = kzalloc(sizeof(struct dma_link_info) *
  2003. dma_lch_count, GFP_KERNEL);
  2004. if (!dma_linked_lch) {
  2005. kfree(dma_chan);
  2006. return -ENOMEM;
  2007. }
  2008. }
  2009. if (cpu_is_omap15xx()) {
  2010. printk(KERN_INFO "DMA support for OMAP15xx initialized\n");
  2011. dma_chan_count = 9;
  2012. enable_1510_mode = 1;
  2013. } else if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
  2014. printk(KERN_INFO "OMAP DMA hardware version %d\n",
  2015. dma_read(HW_ID));
  2016. printk(KERN_INFO "DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
  2017. (dma_read(CAPS_0_U) << 16) |
  2018. dma_read(CAPS_0_L),
  2019. (dma_read(CAPS_1_U) << 16) |
  2020. dma_read(CAPS_1_L),
  2021. dma_read(CAPS_2), dma_read(CAPS_3),
  2022. dma_read(CAPS_4));
  2023. if (!enable_1510_mode) {
  2024. u16 w;
  2025. /* Disable OMAP 3.0/3.1 compatibility mode. */
  2026. w = dma_read(GSCR);
  2027. w |= 1 << 3;
  2028. dma_write(w, GSCR);
  2029. dma_chan_count = 16;
  2030. } else
  2031. dma_chan_count = 9;
  2032. if (cpu_is_omap16xx()) {
  2033. u16 w;
  2034. /* this would prevent OMAP sleep */
  2035. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  2036. w &= ~(1 << 8);
  2037. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  2038. }
  2039. } else if (cpu_class_is_omap2()) {
  2040. u8 revision = dma_read(REVISION) & 0xff;
  2041. printk(KERN_INFO "OMAP DMA hardware revision %d.%d\n",
  2042. revision >> 4, revision & 0xf);
  2043. dma_chan_count = dma_lch_count;
  2044. } else {
  2045. dma_chan_count = 0;
  2046. return 0;
  2047. }
  2048. spin_lock_init(&lcd_dma.lock);
  2049. spin_lock_init(&dma_chan_lock);
  2050. for (ch = 0; ch < dma_chan_count; ch++) {
  2051. omap_clear_dma(ch);
  2052. dma_chan[ch].dev_id = -1;
  2053. dma_chan[ch].next_lch = -1;
  2054. if (ch >= 6 && enable_1510_mode)
  2055. continue;
  2056. if (cpu_class_is_omap1()) {
  2057. /*
  2058. * request_irq() doesn't like dev_id (ie. ch) being
  2059. * zero, so we have to kludge around this.
  2060. */
  2061. r = request_irq(omap1_dma_irq[ch],
  2062. omap1_dma_irq_handler, 0, "DMA",
  2063. (void *) (ch + 1));
  2064. if (r != 0) {
  2065. int i;
  2066. printk(KERN_ERR "unable to request IRQ %d "
  2067. "for DMA (error %d)\n",
  2068. omap1_dma_irq[ch], r);
  2069. for (i = 0; i < ch; i++)
  2070. free_irq(omap1_dma_irq[i],
  2071. (void *) (i + 1));
  2072. return r;
  2073. }
  2074. }
  2075. }
  2076. if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx())
  2077. omap_dma_set_global_params(DMA_DEFAULT_ARB_RATE,
  2078. DMA_DEFAULT_FIFO_DEPTH, 0);
  2079. if (cpu_class_is_omap2()) {
  2080. int irq;
  2081. if (cpu_is_omap44xx())
  2082. irq = INT_44XX_SDMA_IRQ0;
  2083. else
  2084. irq = INT_24XX_SDMA_IRQ0;
  2085. setup_irq(irq, &omap24xx_dma_irq);
  2086. }
  2087. /* Enable smartidle idlemodes and autoidle */
  2088. if (cpu_is_omap34xx()) {
  2089. u32 v = dma_read(OCP_SYSCONFIG);
  2090. v &= ~(DMA_SYSCONFIG_MIDLEMODE_MASK |
  2091. DMA_SYSCONFIG_SIDLEMODE_MASK |
  2092. DMA_SYSCONFIG_AUTOIDLE);
  2093. v |= (DMA_SYSCONFIG_MIDLEMODE(DMA_IDLEMODE_SMARTIDLE) |
  2094. DMA_SYSCONFIG_SIDLEMODE(DMA_IDLEMODE_SMARTIDLE) |
  2095. DMA_SYSCONFIG_AUTOIDLE);
  2096. dma_write(v , OCP_SYSCONFIG);
  2097. }
  2098. /* FIXME: Update LCD DMA to work on 24xx */
  2099. if (cpu_class_is_omap1()) {
  2100. r = request_irq(INT_DMA_LCD, lcd_dma_irq_handler, 0,
  2101. "LCD DMA", NULL);
  2102. if (r != 0) {
  2103. int i;
  2104. printk(KERN_ERR "unable to request IRQ for LCD DMA "
  2105. "(error %d)\n", r);
  2106. for (i = 0; i < dma_chan_count; i++)
  2107. free_irq(omap1_dma_irq[i], (void *) (i + 1));
  2108. return r;
  2109. }
  2110. }
  2111. return 0;
  2112. }
  2113. arch_initcall(omap_init_dma);
  2114. /*
  2115. * Reserve the omap SDMA channels using cmdline bootarg
  2116. * "omap_dma_reserve_ch=". The valid range is 1 to 32
  2117. */
  2118. static int __init omap_dma_cmdline_reserve_ch(char *str)
  2119. {
  2120. if (get_option(&str, &omap_dma_reserve_channels) != 1)
  2121. omap_dma_reserve_channels = 0;
  2122. return 1;
  2123. }
  2124. __setup("omap_dma_reserve_ch=", omap_dma_cmdline_reserve_ch);