dma.c 59 KB

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