dma.c 60 KB

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