dma.c 60 KB

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