dma.c 57 KB

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