dma.c 36 KB

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