dma.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399
  1. /*
  2. * linux/arch/arm/plat-omap/dma.c
  3. *
  4. * Copyright (C) 2003 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 support Copyright (C) 2004-2005 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. * Support functions for the OMAP internal DMA channels.
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License version 2 as
  17. * published by the Free Software Foundation.
  18. *
  19. */
  20. #include <linux/module.h>
  21. #include <linux/init.h>
  22. #include <linux/sched.h>
  23. #include <linux/spinlock.h>
  24. #include <linux/errno.h>
  25. #include <linux/interrupt.h>
  26. #include <asm/system.h>
  27. #include <asm/irq.h>
  28. #include <asm/hardware.h>
  29. #include <asm/dma.h>
  30. #include <asm/io.h>
  31. #include <asm/arch/tc.h>
  32. #define DEBUG_PRINTS
  33. #undef DEBUG_PRINTS
  34. #ifdef DEBUG_PRINTS
  35. #define debug_printk(x) printk x
  36. #else
  37. #define debug_printk(x)
  38. #endif
  39. #define OMAP_DMA_ACTIVE 0x01
  40. #define OMAP_DMA_CCR_EN (1 << 7)
  41. #define OMAP_FUNC_MUX_ARM_BASE (0xfffe1000 + 0xec)
  42. static int enable_1510_mode = 0;
  43. struct omap_dma_lch {
  44. int next_lch;
  45. int dev_id;
  46. u16 saved_csr;
  47. u16 enabled_irqs;
  48. const char *dev_name;
  49. void (* callback)(int lch, u16 ch_status, void *data);
  50. void *data;
  51. long flags;
  52. };
  53. static int dma_chan_count;
  54. static spinlock_t dma_chan_lock;
  55. static struct omap_dma_lch dma_chan[OMAP_LOGICAL_DMA_CH_COUNT];
  56. static const u8 omap1_dma_irq[OMAP_LOGICAL_DMA_CH_COUNT] = {
  57. INT_DMA_CH0_6, INT_DMA_CH1_7, INT_DMA_CH2_8, INT_DMA_CH3,
  58. INT_DMA_CH4, INT_DMA_CH5, INT_1610_DMA_CH6, INT_1610_DMA_CH7,
  59. INT_1610_DMA_CH8, INT_1610_DMA_CH9, INT_1610_DMA_CH10,
  60. INT_1610_DMA_CH11, INT_1610_DMA_CH12, INT_1610_DMA_CH13,
  61. INT_1610_DMA_CH14, INT_1610_DMA_CH15, INT_DMA_LCD
  62. };
  63. #define REVISIT_24XX() printk(KERN_ERR "FIXME: no %s on 24xx\n", \
  64. __FUNCTION__);
  65. #ifdef CONFIG_ARCH_OMAP15XX
  66. /* Returns 1 if the DMA module is in OMAP1510-compatible mode, 0 otherwise */
  67. int omap_dma_in_1510_mode(void)
  68. {
  69. return enable_1510_mode;
  70. }
  71. #else
  72. #define omap_dma_in_1510_mode() 0
  73. #endif
  74. #ifdef CONFIG_ARCH_OMAP1
  75. static inline int get_gdma_dev(int req)
  76. {
  77. u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4;
  78. int shift = ((req - 1) % 5) * 6;
  79. return ((omap_readl(reg) >> shift) & 0x3f) + 1;
  80. }
  81. static inline void set_gdma_dev(int req, int dev)
  82. {
  83. u32 reg = OMAP_FUNC_MUX_ARM_BASE + ((req - 1) / 5) * 4;
  84. int shift = ((req - 1) % 5) * 6;
  85. u32 l;
  86. l = omap_readl(reg);
  87. l &= ~(0x3f << shift);
  88. l |= (dev - 1) << shift;
  89. omap_writel(l, reg);
  90. }
  91. #else
  92. #define set_gdma_dev(req, dev) do {} while (0)
  93. #endif
  94. static void clear_lch_regs(int lch)
  95. {
  96. int i;
  97. u32 lch_base = OMAP_DMA_BASE + lch * 0x40;
  98. for (i = 0; i < 0x2c; i += 2)
  99. omap_writew(0, lch_base + i);
  100. }
  101. void omap_set_dma_priority(int dst_port, int priority)
  102. {
  103. unsigned long reg;
  104. u32 l;
  105. switch (dst_port) {
  106. case OMAP_DMA_PORT_OCP_T1: /* FFFECC00 */
  107. reg = OMAP_TC_OCPT1_PRIOR;
  108. break;
  109. case OMAP_DMA_PORT_OCP_T2: /* FFFECCD0 */
  110. reg = OMAP_TC_OCPT2_PRIOR;
  111. break;
  112. case OMAP_DMA_PORT_EMIFF: /* FFFECC08 */
  113. reg = OMAP_TC_EMIFF_PRIOR;
  114. break;
  115. case OMAP_DMA_PORT_EMIFS: /* FFFECC04 */
  116. reg = OMAP_TC_EMIFS_PRIOR;
  117. break;
  118. default:
  119. BUG();
  120. return;
  121. }
  122. l = omap_readl(reg);
  123. l &= ~(0xf << 8);
  124. l |= (priority & 0xf) << 8;
  125. omap_writel(l, reg);
  126. }
  127. void omap_set_dma_transfer_params(int lch, int data_type, int elem_count,
  128. int frame_count, int sync_mode,
  129. int dma_trigger, int src_or_dst_synch)
  130. {
  131. OMAP_DMA_CSDP_REG(lch) &= ~0x03;
  132. OMAP_DMA_CSDP_REG(lch) |= data_type;
  133. if (cpu_class_is_omap1()) {
  134. OMAP_DMA_CCR_REG(lch) &= ~(1 << 5);
  135. if (sync_mode == OMAP_DMA_SYNC_FRAME)
  136. OMAP_DMA_CCR_REG(lch) |= 1 << 5;
  137. OMAP1_DMA_CCR2_REG(lch) &= ~(1 << 2);
  138. if (sync_mode == OMAP_DMA_SYNC_BLOCK)
  139. OMAP1_DMA_CCR2_REG(lch) |= 1 << 2;
  140. }
  141. if (cpu_is_omap24xx() && dma_trigger) {
  142. u32 val = OMAP_DMA_CCR_REG(lch);
  143. if (dma_trigger > 63)
  144. val |= 1 << 20;
  145. if (dma_trigger > 31)
  146. val |= 1 << 19;
  147. val |= (dma_trigger & 0x1f);
  148. if (sync_mode & OMAP_DMA_SYNC_FRAME)
  149. val |= 1 << 5;
  150. if (sync_mode & OMAP_DMA_SYNC_BLOCK)
  151. val |= 1 << 18;
  152. if (src_or_dst_synch)
  153. val |= 1 << 24; /* source synch */
  154. else
  155. val &= ~(1 << 24); /* dest synch */
  156. OMAP_DMA_CCR_REG(lch) = val;
  157. }
  158. OMAP_DMA_CEN_REG(lch) = elem_count;
  159. OMAP_DMA_CFN_REG(lch) = frame_count;
  160. }
  161. void omap_set_dma_color_mode(int lch, enum omap_dma_color_mode mode, u32 color)
  162. {
  163. u16 w;
  164. BUG_ON(omap_dma_in_1510_mode());
  165. if (cpu_is_omap24xx()) {
  166. REVISIT_24XX();
  167. return;
  168. }
  169. w = OMAP1_DMA_CCR2_REG(lch) & ~0x03;
  170. switch (mode) {
  171. case OMAP_DMA_CONSTANT_FILL:
  172. w |= 0x01;
  173. break;
  174. case OMAP_DMA_TRANSPARENT_COPY:
  175. w |= 0x02;
  176. break;
  177. case OMAP_DMA_COLOR_DIS:
  178. break;
  179. default:
  180. BUG();
  181. }
  182. OMAP1_DMA_CCR2_REG(lch) = w;
  183. w = OMAP1_DMA_LCH_CTRL_REG(lch) & ~0x0f;
  184. /* Default is channel type 2D */
  185. if (mode) {
  186. OMAP1_DMA_COLOR_L_REG(lch) = (u16)color;
  187. OMAP1_DMA_COLOR_U_REG(lch) = (u16)(color >> 16);
  188. w |= 1; /* Channel type G */
  189. }
  190. OMAP1_DMA_LCH_CTRL_REG(lch) = w;
  191. }
  192. /* Note that src_port is only for omap1 */
  193. void omap_set_dma_src_params(int lch, int src_port, int src_amode,
  194. unsigned long src_start,
  195. int src_ei, int src_fi)
  196. {
  197. if (cpu_class_is_omap1()) {
  198. OMAP_DMA_CSDP_REG(lch) &= ~(0x1f << 2);
  199. OMAP_DMA_CSDP_REG(lch) |= src_port << 2;
  200. }
  201. OMAP_DMA_CCR_REG(lch) &= ~(0x03 << 12);
  202. OMAP_DMA_CCR_REG(lch) |= src_amode << 12;
  203. if (cpu_class_is_omap1()) {
  204. OMAP1_DMA_CSSA_U_REG(lch) = src_start >> 16;
  205. OMAP1_DMA_CSSA_L_REG(lch) = src_start;
  206. }
  207. if (cpu_is_omap24xx())
  208. OMAP2_DMA_CSSA_REG(lch) = src_start;
  209. OMAP_DMA_CSEI_REG(lch) = src_ei;
  210. OMAP_DMA_CSFI_REG(lch) = src_fi;
  211. }
  212. void omap_set_dma_params(int lch, struct omap_dma_channel_params * params)
  213. {
  214. omap_set_dma_transfer_params(lch, params->data_type,
  215. params->elem_count, params->frame_count,
  216. params->sync_mode, params->trigger,
  217. params->src_or_dst_synch);
  218. omap_set_dma_src_params(lch, params->src_port,
  219. params->src_amode, params->src_start,
  220. params->src_ei, params->src_fi);
  221. omap_set_dma_dest_params(lch, params->dst_port,
  222. params->dst_amode, params->dst_start,
  223. params->dst_ei, params->dst_fi);
  224. }
  225. void omap_set_dma_src_index(int lch, int eidx, int fidx)
  226. {
  227. if (cpu_is_omap24xx()) {
  228. REVISIT_24XX();
  229. return;
  230. }
  231. OMAP_DMA_CSEI_REG(lch) = eidx;
  232. OMAP_DMA_CSFI_REG(lch) = fidx;
  233. }
  234. void omap_set_dma_src_data_pack(int lch, int enable)
  235. {
  236. OMAP_DMA_CSDP_REG(lch) &= ~(1 << 6);
  237. if (enable)
  238. OMAP_DMA_CSDP_REG(lch) |= (1 << 6);
  239. }
  240. void omap_set_dma_src_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
  241. {
  242. OMAP_DMA_CSDP_REG(lch) &= ~(0x03 << 7);
  243. switch (burst_mode) {
  244. case OMAP_DMA_DATA_BURST_DIS:
  245. break;
  246. case OMAP_DMA_DATA_BURST_4:
  247. OMAP_DMA_CSDP_REG(lch) |= (0x02 << 7);
  248. break;
  249. case OMAP_DMA_DATA_BURST_8:
  250. /* not supported by current hardware
  251. * w |= (0x03 << 7);
  252. * fall through
  253. */
  254. default:
  255. BUG();
  256. }
  257. }
  258. /* Note that dest_port is only for OMAP1 */
  259. void omap_set_dma_dest_params(int lch, int dest_port, int dest_amode,
  260. unsigned long dest_start,
  261. int dst_ei, int dst_fi)
  262. {
  263. if (cpu_class_is_omap1()) {
  264. OMAP_DMA_CSDP_REG(lch) &= ~(0x1f << 9);
  265. OMAP_DMA_CSDP_REG(lch) |= dest_port << 9;
  266. }
  267. OMAP_DMA_CCR_REG(lch) &= ~(0x03 << 14);
  268. OMAP_DMA_CCR_REG(lch) |= dest_amode << 14;
  269. if (cpu_class_is_omap1()) {
  270. OMAP1_DMA_CDSA_U_REG(lch) = dest_start >> 16;
  271. OMAP1_DMA_CDSA_L_REG(lch) = dest_start;
  272. }
  273. if (cpu_is_omap24xx())
  274. OMAP2_DMA_CDSA_REG(lch) = dest_start;
  275. OMAP_DMA_CDEI_REG(lch) = dst_ei;
  276. OMAP_DMA_CDFI_REG(lch) = dst_fi;
  277. }
  278. void omap_set_dma_dest_index(int lch, int eidx, int fidx)
  279. {
  280. if (cpu_is_omap24xx()) {
  281. REVISIT_24XX();
  282. return;
  283. }
  284. OMAP_DMA_CDEI_REG(lch) = eidx;
  285. OMAP_DMA_CDFI_REG(lch) = fidx;
  286. }
  287. void omap_set_dma_dest_data_pack(int lch, int enable)
  288. {
  289. OMAP_DMA_CSDP_REG(lch) &= ~(1 << 13);
  290. if (enable)
  291. OMAP_DMA_CSDP_REG(lch) |= 1 << 13;
  292. }
  293. void omap_set_dma_dest_burst_mode(int lch, enum omap_dma_burst_mode burst_mode)
  294. {
  295. OMAP_DMA_CSDP_REG(lch) &= ~(0x03 << 14);
  296. switch (burst_mode) {
  297. case OMAP_DMA_DATA_BURST_DIS:
  298. break;
  299. case OMAP_DMA_DATA_BURST_4:
  300. OMAP_DMA_CSDP_REG(lch) |= (0x02 << 14);
  301. break;
  302. case OMAP_DMA_DATA_BURST_8:
  303. OMAP_DMA_CSDP_REG(lch) |= (0x03 << 14);
  304. break;
  305. default:
  306. printk(KERN_ERR "Invalid DMA burst mode\n");
  307. BUG();
  308. return;
  309. }
  310. }
  311. static inline void omap_enable_channel_irq(int lch)
  312. {
  313. u32 status;
  314. /* Read CSR to make sure it's cleared. */
  315. status = OMAP_DMA_CSR_REG(lch);
  316. /* Enable some nice interrupts. */
  317. OMAP_DMA_CICR_REG(lch) = dma_chan[lch].enabled_irqs;
  318. dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
  319. }
  320. static void omap_disable_channel_irq(int lch)
  321. {
  322. if (cpu_is_omap24xx())
  323. OMAP_DMA_CICR_REG(lch) = 0;
  324. }
  325. void omap_enable_dma_irq(int lch, u16 bits)
  326. {
  327. dma_chan[lch].enabled_irqs |= bits;
  328. }
  329. void omap_disable_dma_irq(int lch, u16 bits)
  330. {
  331. dma_chan[lch].enabled_irqs &= ~bits;
  332. }
  333. static inline void enable_lnk(int lch)
  334. {
  335. if (cpu_class_is_omap1())
  336. OMAP_DMA_CLNK_CTRL_REG(lch) &= ~(1 << 14);
  337. /* Set the ENABLE_LNK bits */
  338. if (dma_chan[lch].next_lch != -1)
  339. OMAP_DMA_CLNK_CTRL_REG(lch) =
  340. dma_chan[lch].next_lch | (1 << 15);
  341. }
  342. static inline void disable_lnk(int lch)
  343. {
  344. /* Disable interrupts */
  345. if (cpu_class_is_omap1()) {
  346. OMAP_DMA_CICR_REG(lch) = 0;
  347. /* Set the STOP_LNK bit */
  348. OMAP_DMA_CLNK_CTRL_REG(lch) |= 1 << 14;
  349. }
  350. if (cpu_is_omap24xx()) {
  351. omap_disable_channel_irq(lch);
  352. /* Clear the ENABLE_LNK bit */
  353. OMAP_DMA_CLNK_CTRL_REG(lch) &= ~(1 << 15);
  354. }
  355. dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
  356. }
  357. static inline void omap2_enable_irq_lch(int lch)
  358. {
  359. u32 val;
  360. if (!cpu_is_omap24xx())
  361. return;
  362. val = omap_readl(OMAP_DMA4_IRQENABLE_L0);
  363. val |= 1 << lch;
  364. omap_writel(val, OMAP_DMA4_IRQENABLE_L0);
  365. }
  366. int omap_request_dma(int dev_id, const char *dev_name,
  367. void (* callback)(int lch, u16 ch_status, void *data),
  368. void *data, int *dma_ch_out)
  369. {
  370. int ch, free_ch = -1;
  371. unsigned long flags;
  372. struct omap_dma_lch *chan;
  373. spin_lock_irqsave(&dma_chan_lock, flags);
  374. for (ch = 0; ch < dma_chan_count; ch++) {
  375. if (free_ch == -1 && dma_chan[ch].dev_id == -1) {
  376. free_ch = ch;
  377. if (dev_id == 0)
  378. break;
  379. }
  380. }
  381. if (free_ch == -1) {
  382. spin_unlock_irqrestore(&dma_chan_lock, flags);
  383. return -EBUSY;
  384. }
  385. chan = dma_chan + free_ch;
  386. chan->dev_id = dev_id;
  387. if (cpu_class_is_omap1())
  388. clear_lch_regs(free_ch);
  389. if (cpu_is_omap24xx())
  390. omap_clear_dma(free_ch);
  391. spin_unlock_irqrestore(&dma_chan_lock, flags);
  392. chan->dev_name = dev_name;
  393. chan->callback = callback;
  394. chan->data = data;
  395. chan->enabled_irqs = OMAP_DMA_TOUT_IRQ | OMAP_DMA_DROP_IRQ |
  396. OMAP_DMA_BLOCK_IRQ;
  397. if (cpu_is_omap24xx())
  398. chan->enabled_irqs |= OMAP2_DMA_TRANS_ERR_IRQ;
  399. if (cpu_is_omap16xx()) {
  400. /* If the sync device is set, configure it dynamically. */
  401. if (dev_id != 0) {
  402. set_gdma_dev(free_ch + 1, dev_id);
  403. dev_id = free_ch + 1;
  404. }
  405. /* Disable the 1510 compatibility mode and set the sync device
  406. * id. */
  407. OMAP_DMA_CCR_REG(free_ch) = dev_id | (1 << 10);
  408. } else if (cpu_is_omap730() || cpu_is_omap15xx()) {
  409. OMAP_DMA_CCR_REG(free_ch) = dev_id;
  410. }
  411. if (cpu_is_omap24xx()) {
  412. omap2_enable_irq_lch(free_ch);
  413. omap_enable_channel_irq(free_ch);
  414. /* Clear the CSR register and IRQ status register */
  415. OMAP_DMA_CSR_REG(free_ch) = 0x0;
  416. omap_writel(~0x0, OMAP_DMA4_IRQSTATUS_L0);
  417. }
  418. *dma_ch_out = free_ch;
  419. return 0;
  420. }
  421. void omap_free_dma(int lch)
  422. {
  423. unsigned long flags;
  424. spin_lock_irqsave(&dma_chan_lock, flags);
  425. if (dma_chan[lch].dev_id == -1) {
  426. printk("omap_dma: trying to free nonallocated DMA channel %d\n",
  427. lch);
  428. spin_unlock_irqrestore(&dma_chan_lock, flags);
  429. return;
  430. }
  431. dma_chan[lch].dev_id = -1;
  432. dma_chan[lch].next_lch = -1;
  433. dma_chan[lch].callback = NULL;
  434. spin_unlock_irqrestore(&dma_chan_lock, flags);
  435. if (cpu_class_is_omap1()) {
  436. /* Disable all DMA interrupts for the channel. */
  437. OMAP_DMA_CICR_REG(lch) = 0;
  438. /* Make sure the DMA transfer is stopped. */
  439. OMAP_DMA_CCR_REG(lch) = 0;
  440. }
  441. if (cpu_is_omap24xx()) {
  442. u32 val;
  443. /* Disable interrupts */
  444. val = omap_readl(OMAP_DMA4_IRQENABLE_L0);
  445. val &= ~(1 << lch);
  446. omap_writel(val, OMAP_DMA4_IRQENABLE_L0);
  447. /* Clear the CSR register and IRQ status register */
  448. OMAP_DMA_CSR_REG(lch) = 0x0;
  449. val = omap_readl(OMAP_DMA4_IRQSTATUS_L0);
  450. val |= 1 << lch;
  451. omap_writel(val, OMAP_DMA4_IRQSTATUS_L0);
  452. /* Disable all DMA interrupts for the channel. */
  453. OMAP_DMA_CICR_REG(lch) = 0;
  454. /* Make sure the DMA transfer is stopped. */
  455. OMAP_DMA_CCR_REG(lch) = 0;
  456. omap_clear_dma(lch);
  457. }
  458. }
  459. /*
  460. * Clears any DMA state so the DMA engine is ready to restart with new buffers
  461. * through omap_start_dma(). Any buffers in flight are discarded.
  462. */
  463. void omap_clear_dma(int lch)
  464. {
  465. unsigned long flags;
  466. local_irq_save(flags);
  467. if (cpu_class_is_omap1()) {
  468. int status;
  469. OMAP_DMA_CCR_REG(lch) &= ~OMAP_DMA_CCR_EN;
  470. /* Clear pending interrupts */
  471. status = OMAP_DMA_CSR_REG(lch);
  472. }
  473. if (cpu_is_omap24xx()) {
  474. int i;
  475. u32 lch_base = OMAP24XX_DMA_BASE + lch * 0x60 + 0x80;
  476. for (i = 0; i < 0x44; i += 4)
  477. omap_writel(0, lch_base + i);
  478. }
  479. local_irq_restore(flags);
  480. }
  481. void omap_start_dma(int lch)
  482. {
  483. if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
  484. int next_lch, cur_lch;
  485. char dma_chan_link_map[OMAP_LOGICAL_DMA_CH_COUNT];
  486. dma_chan_link_map[lch] = 1;
  487. /* Set the link register of the first channel */
  488. enable_lnk(lch);
  489. memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
  490. cur_lch = dma_chan[lch].next_lch;
  491. do {
  492. next_lch = dma_chan[cur_lch].next_lch;
  493. /* The loop case: we've been here already */
  494. if (dma_chan_link_map[cur_lch])
  495. break;
  496. /* Mark the current channel */
  497. dma_chan_link_map[cur_lch] = 1;
  498. enable_lnk(cur_lch);
  499. omap_enable_channel_irq(cur_lch);
  500. cur_lch = next_lch;
  501. } while (next_lch != -1);
  502. } else if (cpu_is_omap24xx()) {
  503. /* Errata: Need to write lch even if not using chaining */
  504. OMAP_DMA_CLNK_CTRL_REG(lch) = lch;
  505. }
  506. omap_enable_channel_irq(lch);
  507. /* Errata: On ES2.0 BUFFERING disable must be set.
  508. * This will always fail on ES1.0 */
  509. if (cpu_is_omap24xx()) {
  510. OMAP_DMA_CCR_REG(lch) |= OMAP_DMA_CCR_EN;
  511. }
  512. OMAP_DMA_CCR_REG(lch) |= OMAP_DMA_CCR_EN;
  513. dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
  514. }
  515. void omap_stop_dma(int lch)
  516. {
  517. if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
  518. int next_lch, cur_lch = lch;
  519. char dma_chan_link_map[OMAP_LOGICAL_DMA_CH_COUNT];
  520. memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
  521. do {
  522. /* The loop case: we've been here already */
  523. if (dma_chan_link_map[cur_lch])
  524. break;
  525. /* Mark the current channel */
  526. dma_chan_link_map[cur_lch] = 1;
  527. disable_lnk(cur_lch);
  528. next_lch = dma_chan[cur_lch].next_lch;
  529. cur_lch = next_lch;
  530. } while (next_lch != -1);
  531. return;
  532. }
  533. /* Disable all interrupts on the channel */
  534. if (cpu_class_is_omap1())
  535. OMAP_DMA_CICR_REG(lch) = 0;
  536. OMAP_DMA_CCR_REG(lch) &= ~OMAP_DMA_CCR_EN;
  537. dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
  538. }
  539. /*
  540. * Returns current physical source address for the given DMA channel.
  541. * If the channel is running the caller must disable interrupts prior calling
  542. * this function and process the returned value before re-enabling interrupt to
  543. * prevent races with the interrupt handler. Note that in continuous mode there
  544. * is a chance for CSSA_L register overflow inbetween the two reads resulting
  545. * in incorrect return value.
  546. */
  547. dma_addr_t omap_get_dma_src_pos(int lch)
  548. {
  549. dma_addr_t offset;
  550. if (cpu_class_is_omap1())
  551. offset = (dma_addr_t) (OMAP1_DMA_CSSA_L_REG(lch) |
  552. (OMAP1_DMA_CSSA_U_REG(lch) << 16));
  553. if (cpu_is_omap24xx())
  554. offset = OMAP_DMA_CSAC_REG(lch);
  555. return offset;
  556. }
  557. /*
  558. * Returns current physical destination address for the given DMA channel.
  559. * If the channel is running the caller must disable interrupts prior calling
  560. * this function and process the returned value before re-enabling interrupt to
  561. * prevent races with the interrupt handler. Note that in continuous mode there
  562. * is a chance for CDSA_L register overflow inbetween the two reads resulting
  563. * in incorrect return value.
  564. */
  565. dma_addr_t omap_get_dma_dst_pos(int lch)
  566. {
  567. dma_addr_t offset;
  568. if (cpu_class_is_omap1())
  569. offset = (dma_addr_t) (OMAP1_DMA_CDSA_L_REG(lch) |
  570. (OMAP1_DMA_CDSA_U_REG(lch) << 16));
  571. if (cpu_is_omap24xx())
  572. offset = OMAP2_DMA_CDSA_REG(lch);
  573. return offset;
  574. }
  575. /*
  576. * Returns current source transfer counting for the given DMA channel.
  577. * Can be used to monitor the progress of a transfer inside a block.
  578. * It must be called with disabled interrupts.
  579. */
  580. int omap_get_dma_src_addr_counter(int lch)
  581. {
  582. return (dma_addr_t) OMAP_DMA_CSAC_REG(lch);
  583. }
  584. int omap_dma_running(void)
  585. {
  586. int lch;
  587. /* Check if LCD DMA is running */
  588. if (cpu_is_omap16xx())
  589. if (omap_readw(OMAP1610_DMA_LCD_CCR) & OMAP_DMA_CCR_EN)
  590. return 1;
  591. for (lch = 0; lch < dma_chan_count; lch++)
  592. if (OMAP_DMA_CCR_REG(lch) & OMAP_DMA_CCR_EN)
  593. return 1;
  594. return 0;
  595. }
  596. /*
  597. * lch_queue DMA will start right after lch_head one is finished.
  598. * For this DMA link to start, you still need to start (see omap_start_dma)
  599. * the first one. That will fire up the entire queue.
  600. */
  601. void omap_dma_link_lch (int lch_head, int lch_queue)
  602. {
  603. if (omap_dma_in_1510_mode()) {
  604. printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
  605. BUG();
  606. return;
  607. }
  608. if ((dma_chan[lch_head].dev_id == -1) ||
  609. (dma_chan[lch_queue].dev_id == -1)) {
  610. printk(KERN_ERR "omap_dma: trying to link "
  611. "non requested channels\n");
  612. dump_stack();
  613. }
  614. dma_chan[lch_head].next_lch = lch_queue;
  615. }
  616. /*
  617. * Once the DMA queue is stopped, we can destroy it.
  618. */
  619. void omap_dma_unlink_lch (int lch_head, int lch_queue)
  620. {
  621. if (omap_dma_in_1510_mode()) {
  622. printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
  623. BUG();
  624. return;
  625. }
  626. if (dma_chan[lch_head].next_lch != lch_queue ||
  627. dma_chan[lch_head].next_lch == -1) {
  628. printk(KERN_ERR "omap_dma: trying to unlink "
  629. "non linked channels\n");
  630. dump_stack();
  631. }
  632. if ((dma_chan[lch_head].flags & OMAP_DMA_ACTIVE) ||
  633. (dma_chan[lch_head].flags & OMAP_DMA_ACTIVE)) {
  634. printk(KERN_ERR "omap_dma: You need to stop the DMA channels "
  635. "before unlinking\n");
  636. dump_stack();
  637. }
  638. dma_chan[lch_head].next_lch = -1;
  639. }
  640. /*----------------------------------------------------------------------------*/
  641. #ifdef CONFIG_ARCH_OMAP1
  642. static int omap1_dma_handle_ch(int ch)
  643. {
  644. u16 csr;
  645. if (enable_1510_mode && ch >= 6) {
  646. csr = dma_chan[ch].saved_csr;
  647. dma_chan[ch].saved_csr = 0;
  648. } else
  649. csr = OMAP_DMA_CSR_REG(ch);
  650. if (enable_1510_mode && ch <= 2 && (csr >> 7) != 0) {
  651. dma_chan[ch + 6].saved_csr = csr >> 7;
  652. csr &= 0x7f;
  653. }
  654. if ((csr & 0x3f) == 0)
  655. return 0;
  656. if (unlikely(dma_chan[ch].dev_id == -1)) {
  657. printk(KERN_WARNING "Spurious interrupt from DMA channel "
  658. "%d (CSR %04x)\n", ch, csr);
  659. return 0;
  660. }
  661. if (unlikely(csr & OMAP_DMA_TOUT_IRQ))
  662. printk(KERN_WARNING "DMA timeout with device %d\n",
  663. dma_chan[ch].dev_id);
  664. if (unlikely(csr & OMAP_DMA_DROP_IRQ))
  665. printk(KERN_WARNING "DMA synchronization event drop occurred "
  666. "with device %d\n", dma_chan[ch].dev_id);
  667. if (likely(csr & OMAP_DMA_BLOCK_IRQ))
  668. dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
  669. if (likely(dma_chan[ch].callback != NULL))
  670. dma_chan[ch].callback(ch, csr, dma_chan[ch].data);
  671. return 1;
  672. }
  673. static irqreturn_t omap1_dma_irq_handler(int irq, void *dev_id,
  674. struct pt_regs *regs)
  675. {
  676. int ch = ((int) dev_id) - 1;
  677. int handled = 0;
  678. for (;;) {
  679. int handled_now = 0;
  680. handled_now += omap1_dma_handle_ch(ch);
  681. if (enable_1510_mode && dma_chan[ch + 6].saved_csr)
  682. handled_now += omap1_dma_handle_ch(ch + 6);
  683. if (!handled_now)
  684. break;
  685. handled += handled_now;
  686. }
  687. return handled ? IRQ_HANDLED : IRQ_NONE;
  688. }
  689. #else
  690. #define omap1_dma_irq_handler NULL
  691. #endif
  692. #ifdef CONFIG_ARCH_OMAP2
  693. static int omap2_dma_handle_ch(int ch)
  694. {
  695. u32 status = OMAP_DMA_CSR_REG(ch);
  696. u32 val;
  697. if (!status)
  698. return 0;
  699. if (unlikely(dma_chan[ch].dev_id == -1))
  700. return 0;
  701. /* REVISIT: According to 24xx TRM, there's no TOUT_IE */
  702. if (unlikely(status & OMAP_DMA_TOUT_IRQ))
  703. printk(KERN_INFO "DMA timeout with device %d\n",
  704. dma_chan[ch].dev_id);
  705. if (unlikely(status & OMAP_DMA_DROP_IRQ))
  706. printk(KERN_INFO
  707. "DMA synchronization event drop occurred with device "
  708. "%d\n", dma_chan[ch].dev_id);
  709. if (unlikely(status & OMAP2_DMA_TRANS_ERR_IRQ))
  710. printk(KERN_INFO "DMA transaction error with device %d\n",
  711. dma_chan[ch].dev_id);
  712. OMAP_DMA_CSR_REG(ch) = 0x20;
  713. val = omap_readl(OMAP_DMA4_IRQSTATUS_L0);
  714. /* ch in this function is from 0-31 while in register it is 1-32 */
  715. val = 1 << (ch);
  716. omap_writel(val, OMAP_DMA4_IRQSTATUS_L0);
  717. if (likely(dma_chan[ch].callback != NULL))
  718. dma_chan[ch].callback(ch, status, dma_chan[ch].data);
  719. return 0;
  720. }
  721. /* STATUS register count is from 1-32 while our is 0-31 */
  722. static irqreturn_t omap2_dma_irq_handler(int irq, void *dev_id,
  723. struct pt_regs *regs)
  724. {
  725. u32 val;
  726. int i;
  727. val = omap_readl(OMAP_DMA4_IRQSTATUS_L0);
  728. for (i = 1; i <= OMAP_LOGICAL_DMA_CH_COUNT; i++) {
  729. int active = val & (1 << (i - 1));
  730. if (active)
  731. omap2_dma_handle_ch(i - 1);
  732. }
  733. return IRQ_HANDLED;
  734. }
  735. static struct irqaction omap24xx_dma_irq = {
  736. .name = "DMA",
  737. .handler = omap2_dma_irq_handler,
  738. .flags = SA_INTERRUPT
  739. };
  740. #else
  741. static struct irqaction omap24xx_dma_irq;
  742. #endif
  743. /*----------------------------------------------------------------------------*/
  744. static struct lcd_dma_info {
  745. spinlock_t lock;
  746. int reserved;
  747. void (* callback)(u16 status, void *data);
  748. void *cb_data;
  749. int active;
  750. unsigned long addr, size;
  751. int rotate, data_type, xres, yres;
  752. int vxres;
  753. int mirror;
  754. int xscale, yscale;
  755. int ext_ctrl;
  756. int src_port;
  757. int single_transfer;
  758. } lcd_dma;
  759. void omap_set_lcd_dma_b1(unsigned long addr, u16 fb_xres, u16 fb_yres,
  760. int data_type)
  761. {
  762. lcd_dma.addr = addr;
  763. lcd_dma.data_type = data_type;
  764. lcd_dma.xres = fb_xres;
  765. lcd_dma.yres = fb_yres;
  766. }
  767. void omap_set_lcd_dma_src_port(int port)
  768. {
  769. lcd_dma.src_port = port;
  770. }
  771. void omap_set_lcd_dma_ext_controller(int external)
  772. {
  773. lcd_dma.ext_ctrl = external;
  774. }
  775. void omap_set_lcd_dma_single_transfer(int single)
  776. {
  777. lcd_dma.single_transfer = single;
  778. }
  779. void omap_set_lcd_dma_b1_rotation(int rotate)
  780. {
  781. if (omap_dma_in_1510_mode()) {
  782. printk(KERN_ERR "DMA rotation is not supported in 1510 mode\n");
  783. BUG();
  784. return;
  785. }
  786. lcd_dma.rotate = rotate;
  787. }
  788. void omap_set_lcd_dma_b1_mirror(int mirror)
  789. {
  790. if (omap_dma_in_1510_mode()) {
  791. printk(KERN_ERR "DMA mirror is not supported in 1510 mode\n");
  792. BUG();
  793. }
  794. lcd_dma.mirror = mirror;
  795. }
  796. void omap_set_lcd_dma_b1_vxres(unsigned long vxres)
  797. {
  798. if (omap_dma_in_1510_mode()) {
  799. printk(KERN_ERR "DMA virtual resulotion is not supported "
  800. "in 1510 mode\n");
  801. BUG();
  802. }
  803. lcd_dma.vxres = vxres;
  804. }
  805. void omap_set_lcd_dma_b1_scale(unsigned int xscale, unsigned int yscale)
  806. {
  807. if (omap_dma_in_1510_mode()) {
  808. printk(KERN_ERR "DMA scale is not supported in 1510 mode\n");
  809. BUG();
  810. }
  811. lcd_dma.xscale = xscale;
  812. lcd_dma.yscale = yscale;
  813. }
  814. static void set_b1_regs(void)
  815. {
  816. unsigned long top, bottom;
  817. int es;
  818. u16 w;
  819. unsigned long en, fn;
  820. long ei, fi;
  821. unsigned long vxres;
  822. unsigned int xscale, yscale;
  823. switch (lcd_dma.data_type) {
  824. case OMAP_DMA_DATA_TYPE_S8:
  825. es = 1;
  826. break;
  827. case OMAP_DMA_DATA_TYPE_S16:
  828. es = 2;
  829. break;
  830. case OMAP_DMA_DATA_TYPE_S32:
  831. es = 4;
  832. break;
  833. default:
  834. BUG();
  835. return;
  836. }
  837. vxres = lcd_dma.vxres ? lcd_dma.vxres : lcd_dma.xres;
  838. xscale = lcd_dma.xscale ? lcd_dma.xscale : 1;
  839. yscale = lcd_dma.yscale ? lcd_dma.yscale : 1;
  840. BUG_ON(vxres < lcd_dma.xres);
  841. #define PIXADDR(x,y) (lcd_dma.addr + ((y) * vxres * yscale + (x) * xscale) * es)
  842. #define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
  843. switch (lcd_dma.rotate) {
  844. case 0:
  845. if (!lcd_dma.mirror) {
  846. top = PIXADDR(0, 0);
  847. bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  848. /* 1510 DMA requires the bottom address to be 2 more
  849. * than the actual last memory access location. */
  850. if (omap_dma_in_1510_mode() &&
  851. lcd_dma.data_type == OMAP_DMA_DATA_TYPE_S32)
  852. bottom += 2;
  853. ei = PIXSTEP(0, 0, 1, 0);
  854. fi = PIXSTEP(lcd_dma.xres - 1, 0, 0, 1);
  855. } else {
  856. top = PIXADDR(lcd_dma.xres - 1, 0);
  857. bottom = PIXADDR(0, lcd_dma.yres - 1);
  858. ei = PIXSTEP(1, 0, 0, 0);
  859. fi = PIXSTEP(0, 0, lcd_dma.xres - 1, 1);
  860. }
  861. en = lcd_dma.xres;
  862. fn = lcd_dma.yres;
  863. break;
  864. case 90:
  865. if (!lcd_dma.mirror) {
  866. top = PIXADDR(0, lcd_dma.yres - 1);
  867. bottom = PIXADDR(lcd_dma.xres - 1, 0);
  868. ei = PIXSTEP(0, 1, 0, 0);
  869. fi = PIXSTEP(0, 0, 1, lcd_dma.yres - 1);
  870. } else {
  871. top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  872. bottom = PIXADDR(0, 0);
  873. ei = PIXSTEP(0, 1, 0, 0);
  874. fi = PIXSTEP(1, 0, 0, lcd_dma.yres - 1);
  875. }
  876. en = lcd_dma.yres;
  877. fn = lcd_dma.xres;
  878. break;
  879. case 180:
  880. if (!lcd_dma.mirror) {
  881. top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  882. bottom = PIXADDR(0, 0);
  883. ei = PIXSTEP(1, 0, 0, 0);
  884. fi = PIXSTEP(0, 1, lcd_dma.xres - 1, 0);
  885. } else {
  886. top = PIXADDR(0, lcd_dma.yres - 1);
  887. bottom = PIXADDR(lcd_dma.xres - 1, 0);
  888. ei = PIXSTEP(0, 0, 1, 0);
  889. fi = PIXSTEP(lcd_dma.xres - 1, 1, 0, 0);
  890. }
  891. en = lcd_dma.xres;
  892. fn = lcd_dma.yres;
  893. break;
  894. case 270:
  895. if (!lcd_dma.mirror) {
  896. top = PIXADDR(lcd_dma.xres - 1, 0);
  897. bottom = PIXADDR(0, lcd_dma.yres - 1);
  898. ei = PIXSTEP(0, 0, 0, 1);
  899. fi = PIXSTEP(1, lcd_dma.yres - 1, 0, 0);
  900. } else {
  901. top = PIXADDR(0, 0);
  902. bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  903. ei = PIXSTEP(0, 0, 0, 1);
  904. fi = PIXSTEP(0, lcd_dma.yres - 1, 1, 0);
  905. }
  906. en = lcd_dma.yres;
  907. fn = lcd_dma.xres;
  908. break;
  909. default:
  910. BUG();
  911. return; /* Supress warning about uninitialized vars */
  912. }
  913. if (omap_dma_in_1510_mode()) {
  914. omap_writew(top >> 16, OMAP1510_DMA_LCD_TOP_F1_U);
  915. omap_writew(top, OMAP1510_DMA_LCD_TOP_F1_L);
  916. omap_writew(bottom >> 16, OMAP1510_DMA_LCD_BOT_F1_U);
  917. omap_writew(bottom, OMAP1510_DMA_LCD_BOT_F1_L);
  918. return;
  919. }
  920. /* 1610 regs */
  921. omap_writew(top >> 16, OMAP1610_DMA_LCD_TOP_B1_U);
  922. omap_writew(top, OMAP1610_DMA_LCD_TOP_B1_L);
  923. omap_writew(bottom >> 16, OMAP1610_DMA_LCD_BOT_B1_U);
  924. omap_writew(bottom, OMAP1610_DMA_LCD_BOT_B1_L);
  925. omap_writew(en, OMAP1610_DMA_LCD_SRC_EN_B1);
  926. omap_writew(fn, OMAP1610_DMA_LCD_SRC_FN_B1);
  927. w = omap_readw(OMAP1610_DMA_LCD_CSDP);
  928. w &= ~0x03;
  929. w |= lcd_dma.data_type;
  930. omap_writew(w, OMAP1610_DMA_LCD_CSDP);
  931. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  932. /* Always set the source port as SDRAM for now*/
  933. w &= ~(0x03 << 6);
  934. if (lcd_dma.callback != NULL)
  935. w |= 1 << 1; /* Block interrupt enable */
  936. else
  937. w &= ~(1 << 1);
  938. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  939. if (!(lcd_dma.rotate || lcd_dma.mirror ||
  940. lcd_dma.vxres || lcd_dma.xscale || lcd_dma.yscale))
  941. return;
  942. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  943. /* Set the double-indexed addressing mode */
  944. w |= (0x03 << 12);
  945. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  946. omap_writew(ei, OMAP1610_DMA_LCD_SRC_EI_B1);
  947. omap_writew(fi >> 16, OMAP1610_DMA_LCD_SRC_FI_B1_U);
  948. omap_writew(fi, OMAP1610_DMA_LCD_SRC_FI_B1_L);
  949. }
  950. static irqreturn_t lcd_dma_irq_handler(int irq, void *dev_id,
  951. struct pt_regs *regs)
  952. {
  953. u16 w;
  954. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  955. if (unlikely(!(w & (1 << 3)))) {
  956. printk(KERN_WARNING "Spurious LCD DMA IRQ\n");
  957. return IRQ_NONE;
  958. }
  959. /* Ack the IRQ */
  960. w |= (1 << 3);
  961. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  962. lcd_dma.active = 0;
  963. if (lcd_dma.callback != NULL)
  964. lcd_dma.callback(w, lcd_dma.cb_data);
  965. return IRQ_HANDLED;
  966. }
  967. int omap_request_lcd_dma(void (* callback)(u16 status, void *data),
  968. void *data)
  969. {
  970. spin_lock_irq(&lcd_dma.lock);
  971. if (lcd_dma.reserved) {
  972. spin_unlock_irq(&lcd_dma.lock);
  973. printk(KERN_ERR "LCD DMA channel already reserved\n");
  974. BUG();
  975. return -EBUSY;
  976. }
  977. lcd_dma.reserved = 1;
  978. spin_unlock_irq(&lcd_dma.lock);
  979. lcd_dma.callback = callback;
  980. lcd_dma.cb_data = data;
  981. lcd_dma.active = 0;
  982. lcd_dma.single_transfer = 0;
  983. lcd_dma.rotate = 0;
  984. lcd_dma.vxres = 0;
  985. lcd_dma.mirror = 0;
  986. lcd_dma.xscale = 0;
  987. lcd_dma.yscale = 0;
  988. lcd_dma.ext_ctrl = 0;
  989. lcd_dma.src_port = 0;
  990. return 0;
  991. }
  992. void omap_free_lcd_dma(void)
  993. {
  994. spin_lock(&lcd_dma.lock);
  995. if (!lcd_dma.reserved) {
  996. spin_unlock(&lcd_dma.lock);
  997. printk(KERN_ERR "LCD DMA is not reserved\n");
  998. BUG();
  999. return;
  1000. }
  1001. if (!enable_1510_mode)
  1002. omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR) & ~1,
  1003. OMAP1610_DMA_LCD_CCR);
  1004. lcd_dma.reserved = 0;
  1005. spin_unlock(&lcd_dma.lock);
  1006. }
  1007. void omap_enable_lcd_dma(void)
  1008. {
  1009. u16 w;
  1010. /* Set the Enable bit only if an external controller is
  1011. * connected. Otherwise the OMAP internal controller will
  1012. * start the transfer when it gets enabled.
  1013. */
  1014. if (enable_1510_mode || !lcd_dma.ext_ctrl)
  1015. return;
  1016. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1017. w |= 1 << 8;
  1018. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1019. lcd_dma.active = 1;
  1020. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1021. w |= 1 << 7;
  1022. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1023. }
  1024. void omap_setup_lcd_dma(void)
  1025. {
  1026. BUG_ON(lcd_dma.active);
  1027. if (!enable_1510_mode) {
  1028. /* Set some reasonable defaults */
  1029. omap_writew(0x5440, OMAP1610_DMA_LCD_CCR);
  1030. omap_writew(0x9102, OMAP1610_DMA_LCD_CSDP);
  1031. omap_writew(0x0004, OMAP1610_DMA_LCD_LCH_CTRL);
  1032. }
  1033. set_b1_regs();
  1034. if (!enable_1510_mode) {
  1035. u16 w;
  1036. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1037. /* If DMA was already active set the end_prog bit to have
  1038. * the programmed register set loaded into the active
  1039. * register set.
  1040. */
  1041. w |= 1 << 11; /* End_prog */
  1042. if (!lcd_dma.single_transfer)
  1043. w |= (3 << 8); /* Auto_init, repeat */
  1044. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1045. }
  1046. }
  1047. void omap_stop_lcd_dma(void)
  1048. {
  1049. u16 w;
  1050. lcd_dma.active = 0;
  1051. if (enable_1510_mode || !lcd_dma.ext_ctrl)
  1052. return;
  1053. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1054. w &= ~(1 << 7);
  1055. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1056. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1057. w &= ~(1 << 8);
  1058. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1059. }
  1060. /*----------------------------------------------------------------------------*/
  1061. static int __init omap_init_dma(void)
  1062. {
  1063. int ch, r;
  1064. if (cpu_is_omap15xx()) {
  1065. printk(KERN_INFO "DMA support for OMAP15xx initialized\n");
  1066. dma_chan_count = 9;
  1067. enable_1510_mode = 1;
  1068. } else if (cpu_is_omap16xx() || cpu_is_omap730()) {
  1069. printk(KERN_INFO "OMAP DMA hardware version %d\n",
  1070. omap_readw(OMAP_DMA_HW_ID));
  1071. printk(KERN_INFO "DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
  1072. (omap_readw(OMAP_DMA_CAPS_0_U) << 16) |
  1073. omap_readw(OMAP_DMA_CAPS_0_L),
  1074. (omap_readw(OMAP_DMA_CAPS_1_U) << 16) |
  1075. omap_readw(OMAP_DMA_CAPS_1_L),
  1076. omap_readw(OMAP_DMA_CAPS_2), omap_readw(OMAP_DMA_CAPS_3),
  1077. omap_readw(OMAP_DMA_CAPS_4));
  1078. if (!enable_1510_mode) {
  1079. u16 w;
  1080. /* Disable OMAP 3.0/3.1 compatibility mode. */
  1081. w = omap_readw(OMAP_DMA_GSCR);
  1082. w |= 1 << 3;
  1083. omap_writew(w, OMAP_DMA_GSCR);
  1084. dma_chan_count = 16;
  1085. } else
  1086. dma_chan_count = 9;
  1087. } else if (cpu_is_omap24xx()) {
  1088. u8 revision = omap_readb(OMAP_DMA4_REVISION);
  1089. printk(KERN_INFO "OMAP DMA hardware revision %d.%d\n",
  1090. revision >> 4, revision & 0xf);
  1091. dma_chan_count = OMAP_LOGICAL_DMA_CH_COUNT;
  1092. } else {
  1093. dma_chan_count = 0;
  1094. return 0;
  1095. }
  1096. memset(&lcd_dma, 0, sizeof(lcd_dma));
  1097. spin_lock_init(&lcd_dma.lock);
  1098. spin_lock_init(&dma_chan_lock);
  1099. memset(&dma_chan, 0, sizeof(dma_chan));
  1100. for (ch = 0; ch < dma_chan_count; ch++) {
  1101. omap_clear_dma(ch);
  1102. dma_chan[ch].dev_id = -1;
  1103. dma_chan[ch].next_lch = -1;
  1104. if (ch >= 6 && enable_1510_mode)
  1105. continue;
  1106. if (cpu_class_is_omap1()) {
  1107. /* request_irq() doesn't like dev_id (ie. ch) being
  1108. * zero, so we have to kludge around this. */
  1109. r = request_irq(omap1_dma_irq[ch],
  1110. omap1_dma_irq_handler, 0, "DMA",
  1111. (void *) (ch + 1));
  1112. if (r != 0) {
  1113. int i;
  1114. printk(KERN_ERR "unable to request IRQ %d "
  1115. "for DMA (error %d)\n",
  1116. omap1_dma_irq[ch], r);
  1117. for (i = 0; i < ch; i++)
  1118. free_irq(omap1_dma_irq[i],
  1119. (void *) (i + 1));
  1120. return r;
  1121. }
  1122. }
  1123. }
  1124. if (cpu_is_omap24xx())
  1125. setup_irq(INT_24XX_SDMA_IRQ0, &omap24xx_dma_irq);
  1126. /* FIXME: Update LCD DMA to work on 24xx */
  1127. if (cpu_class_is_omap1()) {
  1128. r = request_irq(INT_DMA_LCD, lcd_dma_irq_handler, 0,
  1129. "LCD DMA", NULL);
  1130. if (r != 0) {
  1131. int i;
  1132. printk(KERN_ERR "unable to request IRQ for LCD DMA "
  1133. "(error %d)\n", r);
  1134. for (i = 0; i < dma_chan_count; i++)
  1135. free_irq(omap1_dma_irq[i], (void *) (i + 1));
  1136. return r;
  1137. }
  1138. }
  1139. return 0;
  1140. }
  1141. arch_initcall(omap_init_dma);
  1142. EXPORT_SYMBOL(omap_get_dma_src_pos);
  1143. EXPORT_SYMBOL(omap_get_dma_dst_pos);
  1144. EXPORT_SYMBOL(omap_get_dma_src_addr_counter);
  1145. EXPORT_SYMBOL(omap_clear_dma);
  1146. EXPORT_SYMBOL(omap_set_dma_priority);
  1147. EXPORT_SYMBOL(omap_request_dma);
  1148. EXPORT_SYMBOL(omap_free_dma);
  1149. EXPORT_SYMBOL(omap_start_dma);
  1150. EXPORT_SYMBOL(omap_stop_dma);
  1151. EXPORT_SYMBOL(omap_enable_dma_irq);
  1152. EXPORT_SYMBOL(omap_disable_dma_irq);
  1153. EXPORT_SYMBOL(omap_set_dma_transfer_params);
  1154. EXPORT_SYMBOL(omap_set_dma_color_mode);
  1155. EXPORT_SYMBOL(omap_set_dma_src_params);
  1156. EXPORT_SYMBOL(omap_set_dma_src_index);
  1157. EXPORT_SYMBOL(omap_set_dma_src_data_pack);
  1158. EXPORT_SYMBOL(omap_set_dma_src_burst_mode);
  1159. EXPORT_SYMBOL(omap_set_dma_dest_params);
  1160. EXPORT_SYMBOL(omap_set_dma_dest_index);
  1161. EXPORT_SYMBOL(omap_set_dma_dest_data_pack);
  1162. EXPORT_SYMBOL(omap_set_dma_dest_burst_mode);
  1163. EXPORT_SYMBOL(omap_set_dma_params);
  1164. EXPORT_SYMBOL(omap_dma_link_lch);
  1165. EXPORT_SYMBOL(omap_dma_unlink_lch);
  1166. EXPORT_SYMBOL(omap_request_lcd_dma);
  1167. EXPORT_SYMBOL(omap_free_lcd_dma);
  1168. EXPORT_SYMBOL(omap_enable_lcd_dma);
  1169. EXPORT_SYMBOL(omap_setup_lcd_dma);
  1170. EXPORT_SYMBOL(omap_stop_lcd_dma);
  1171. EXPORT_SYMBOL(omap_set_lcd_dma_b1);
  1172. EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer);
  1173. EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller);
  1174. EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation);
  1175. EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres);
  1176. EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale);
  1177. EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror);