dma.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  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(~0x0, 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. val = omap_readl(OMAP_DMA4_IRQSTATUS_L0);
  510. val |= 1 << lch;
  511. omap_writel(val, OMAP_DMA4_IRQSTATUS_L0);
  512. /* Disable all DMA interrupts for the channel. */
  513. OMAP_DMA_CICR_REG(lch) = 0;
  514. /* Make sure the DMA transfer is stopped. */
  515. OMAP_DMA_CCR_REG(lch) = 0;
  516. omap_clear_dma(lch);
  517. }
  518. }
  519. /*
  520. * Clears any DMA state so the DMA engine is ready to restart with new buffers
  521. * through omap_start_dma(). Any buffers in flight are discarded.
  522. */
  523. void omap_clear_dma(int lch)
  524. {
  525. unsigned long flags;
  526. local_irq_save(flags);
  527. if (cpu_class_is_omap1()) {
  528. int status;
  529. OMAP_DMA_CCR_REG(lch) &= ~OMAP_DMA_CCR_EN;
  530. /* Clear pending interrupts */
  531. status = OMAP_DMA_CSR_REG(lch);
  532. }
  533. if (cpu_is_omap24xx()) {
  534. int i;
  535. u32 lch_base = OMAP24XX_DMA_BASE + lch * 0x60 + 0x80;
  536. for (i = 0; i < 0x44; i += 4)
  537. omap_writel(0, lch_base + i);
  538. }
  539. local_irq_restore(flags);
  540. }
  541. void omap_start_dma(int lch)
  542. {
  543. if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
  544. int next_lch, cur_lch;
  545. char dma_chan_link_map[OMAP_LOGICAL_DMA_CH_COUNT];
  546. dma_chan_link_map[lch] = 1;
  547. /* Set the link register of the first channel */
  548. enable_lnk(lch);
  549. memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
  550. cur_lch = dma_chan[lch].next_lch;
  551. do {
  552. next_lch = dma_chan[cur_lch].next_lch;
  553. /* The loop case: we've been here already */
  554. if (dma_chan_link_map[cur_lch])
  555. break;
  556. /* Mark the current channel */
  557. dma_chan_link_map[cur_lch] = 1;
  558. enable_lnk(cur_lch);
  559. omap_enable_channel_irq(cur_lch);
  560. cur_lch = next_lch;
  561. } while (next_lch != -1);
  562. } else if (cpu_is_omap24xx()) {
  563. /* Errata: Need to write lch even if not using chaining */
  564. OMAP_DMA_CLNK_CTRL_REG(lch) = lch;
  565. }
  566. omap_enable_channel_irq(lch);
  567. /* Errata: On ES2.0 BUFFERING disable must be set.
  568. * This will always fail on ES1.0 */
  569. if (cpu_is_omap24xx()) {
  570. OMAP_DMA_CCR_REG(lch) |= OMAP_DMA_CCR_EN;
  571. }
  572. OMAP_DMA_CCR_REG(lch) |= OMAP_DMA_CCR_EN;
  573. dma_chan[lch].flags |= OMAP_DMA_ACTIVE;
  574. }
  575. void omap_stop_dma(int lch)
  576. {
  577. if (!omap_dma_in_1510_mode() && dma_chan[lch].next_lch != -1) {
  578. int next_lch, cur_lch = lch;
  579. char dma_chan_link_map[OMAP_LOGICAL_DMA_CH_COUNT];
  580. memset(dma_chan_link_map, 0, sizeof(dma_chan_link_map));
  581. do {
  582. /* The loop case: we've been here already */
  583. if (dma_chan_link_map[cur_lch])
  584. break;
  585. /* Mark the current channel */
  586. dma_chan_link_map[cur_lch] = 1;
  587. disable_lnk(cur_lch);
  588. next_lch = dma_chan[cur_lch].next_lch;
  589. cur_lch = next_lch;
  590. } while (next_lch != -1);
  591. return;
  592. }
  593. /* Disable all interrupts on the channel */
  594. if (cpu_class_is_omap1())
  595. OMAP_DMA_CICR_REG(lch) = 0;
  596. OMAP_DMA_CCR_REG(lch) &= ~OMAP_DMA_CCR_EN;
  597. dma_chan[lch].flags &= ~OMAP_DMA_ACTIVE;
  598. }
  599. /*
  600. * Allows changing the DMA callback function or data. This may be needed if
  601. * the driver shares a single DMA channel for multiple dma triggers.
  602. */
  603. int omap_set_dma_callback(int lch,
  604. void (* callback)(int lch, u16 ch_status, void *data),
  605. void *data)
  606. {
  607. unsigned long flags;
  608. if (lch < 0)
  609. return -ENODEV;
  610. spin_lock_irqsave(&dma_chan_lock, flags);
  611. if (dma_chan[lch].dev_id == -1) {
  612. printk(KERN_ERR "DMA callback for not set for free channel\n");
  613. spin_unlock_irqrestore(&dma_chan_lock, flags);
  614. return -EINVAL;
  615. }
  616. dma_chan[lch].callback = callback;
  617. dma_chan[lch].data = data;
  618. spin_unlock_irqrestore(&dma_chan_lock, flags);
  619. return 0;
  620. }
  621. /*
  622. * Returns current physical source address for the given DMA channel.
  623. * If the channel is running the caller must disable interrupts prior calling
  624. * this function and process the returned value before re-enabling interrupt to
  625. * prevent races with the interrupt handler. Note that in continuous mode there
  626. * is a chance for CSSA_L register overflow inbetween the two reads resulting
  627. * in incorrect return value.
  628. */
  629. dma_addr_t omap_get_dma_src_pos(int lch)
  630. {
  631. dma_addr_t offset;
  632. if (cpu_class_is_omap1())
  633. offset = (dma_addr_t) (OMAP1_DMA_CSSA_L_REG(lch) |
  634. (OMAP1_DMA_CSSA_U_REG(lch) << 16));
  635. if (cpu_is_omap24xx())
  636. offset = OMAP_DMA_CSAC_REG(lch);
  637. return offset;
  638. }
  639. /*
  640. * Returns current physical destination address for the given DMA channel.
  641. * If the channel is running the caller must disable interrupts prior calling
  642. * this function and process the returned value before re-enabling interrupt to
  643. * prevent races with the interrupt handler. Note that in continuous mode there
  644. * is a chance for CDSA_L register overflow inbetween the two reads resulting
  645. * in incorrect return value.
  646. */
  647. dma_addr_t omap_get_dma_dst_pos(int lch)
  648. {
  649. dma_addr_t offset;
  650. if (cpu_class_is_omap1())
  651. offset = (dma_addr_t) (OMAP1_DMA_CDSA_L_REG(lch) |
  652. (OMAP1_DMA_CDSA_U_REG(lch) << 16));
  653. if (cpu_is_omap24xx())
  654. offset = OMAP2_DMA_CDSA_REG(lch);
  655. return offset;
  656. }
  657. /*
  658. * Returns current source transfer counting for the given DMA channel.
  659. * Can be used to monitor the progress of a transfer inside a block.
  660. * It must be called with disabled interrupts.
  661. */
  662. int omap_get_dma_src_addr_counter(int lch)
  663. {
  664. return (dma_addr_t) OMAP_DMA_CSAC_REG(lch);
  665. }
  666. int omap_dma_running(void)
  667. {
  668. int lch;
  669. /* Check if LCD DMA is running */
  670. if (cpu_is_omap16xx())
  671. if (omap_readw(OMAP1610_DMA_LCD_CCR) & OMAP_DMA_CCR_EN)
  672. return 1;
  673. for (lch = 0; lch < dma_chan_count; lch++)
  674. if (OMAP_DMA_CCR_REG(lch) & OMAP_DMA_CCR_EN)
  675. return 1;
  676. return 0;
  677. }
  678. /*
  679. * lch_queue DMA will start right after lch_head one is finished.
  680. * For this DMA link to start, you still need to start (see omap_start_dma)
  681. * the first one. That will fire up the entire queue.
  682. */
  683. void omap_dma_link_lch (int lch_head, int lch_queue)
  684. {
  685. if (omap_dma_in_1510_mode()) {
  686. printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
  687. BUG();
  688. return;
  689. }
  690. if ((dma_chan[lch_head].dev_id == -1) ||
  691. (dma_chan[lch_queue].dev_id == -1)) {
  692. printk(KERN_ERR "omap_dma: trying to link "
  693. "non requested channels\n");
  694. dump_stack();
  695. }
  696. dma_chan[lch_head].next_lch = lch_queue;
  697. }
  698. /*
  699. * Once the DMA queue is stopped, we can destroy it.
  700. */
  701. void omap_dma_unlink_lch (int lch_head, int lch_queue)
  702. {
  703. if (omap_dma_in_1510_mode()) {
  704. printk(KERN_ERR "DMA linking is not supported in 1510 mode\n");
  705. BUG();
  706. return;
  707. }
  708. if (dma_chan[lch_head].next_lch != lch_queue ||
  709. dma_chan[lch_head].next_lch == -1) {
  710. printk(KERN_ERR "omap_dma: trying to unlink "
  711. "non linked channels\n");
  712. dump_stack();
  713. }
  714. if ((dma_chan[lch_head].flags & OMAP_DMA_ACTIVE) ||
  715. (dma_chan[lch_head].flags & OMAP_DMA_ACTIVE)) {
  716. printk(KERN_ERR "omap_dma: You need to stop the DMA channels "
  717. "before unlinking\n");
  718. dump_stack();
  719. }
  720. dma_chan[lch_head].next_lch = -1;
  721. }
  722. /*----------------------------------------------------------------------------*/
  723. #ifdef CONFIG_ARCH_OMAP1
  724. static int omap1_dma_handle_ch(int ch)
  725. {
  726. u16 csr;
  727. if (enable_1510_mode && ch >= 6) {
  728. csr = dma_chan[ch].saved_csr;
  729. dma_chan[ch].saved_csr = 0;
  730. } else
  731. csr = OMAP_DMA_CSR_REG(ch);
  732. if (enable_1510_mode && ch <= 2 && (csr >> 7) != 0) {
  733. dma_chan[ch + 6].saved_csr = csr >> 7;
  734. csr &= 0x7f;
  735. }
  736. if ((csr & 0x3f) == 0)
  737. return 0;
  738. if (unlikely(dma_chan[ch].dev_id == -1)) {
  739. printk(KERN_WARNING "Spurious interrupt from DMA channel "
  740. "%d (CSR %04x)\n", ch, csr);
  741. return 0;
  742. }
  743. if (unlikely(csr & OMAP1_DMA_TOUT_IRQ))
  744. printk(KERN_WARNING "DMA timeout with device %d\n",
  745. dma_chan[ch].dev_id);
  746. if (unlikely(csr & OMAP_DMA_DROP_IRQ))
  747. printk(KERN_WARNING "DMA synchronization event drop occurred "
  748. "with device %d\n", dma_chan[ch].dev_id);
  749. if (likely(csr & OMAP_DMA_BLOCK_IRQ))
  750. dma_chan[ch].flags &= ~OMAP_DMA_ACTIVE;
  751. if (likely(dma_chan[ch].callback != NULL))
  752. dma_chan[ch].callback(ch, csr, dma_chan[ch].data);
  753. return 1;
  754. }
  755. static irqreturn_t omap1_dma_irq_handler(int irq, void *dev_id)
  756. {
  757. int ch = ((int) dev_id) - 1;
  758. int handled = 0;
  759. for (;;) {
  760. int handled_now = 0;
  761. handled_now += omap1_dma_handle_ch(ch);
  762. if (enable_1510_mode && dma_chan[ch + 6].saved_csr)
  763. handled_now += omap1_dma_handle_ch(ch + 6);
  764. if (!handled_now)
  765. break;
  766. handled += handled_now;
  767. }
  768. return handled ? IRQ_HANDLED : IRQ_NONE;
  769. }
  770. #else
  771. #define omap1_dma_irq_handler NULL
  772. #endif
  773. #ifdef CONFIG_ARCH_OMAP2
  774. static int omap2_dma_handle_ch(int ch)
  775. {
  776. u32 status = OMAP_DMA_CSR_REG(ch);
  777. u32 val;
  778. if (!status)
  779. return 0;
  780. if (unlikely(dma_chan[ch].dev_id == -1))
  781. return 0;
  782. if (unlikely(status & OMAP_DMA_DROP_IRQ))
  783. printk(KERN_INFO
  784. "DMA synchronization event drop occurred with device "
  785. "%d\n", dma_chan[ch].dev_id);
  786. if (unlikely(status & OMAP2_DMA_TRANS_ERR_IRQ))
  787. printk(KERN_INFO "DMA transaction error with device %d\n",
  788. dma_chan[ch].dev_id);
  789. if (unlikely(status & OMAP2_DMA_SECURE_ERR_IRQ))
  790. printk(KERN_INFO "DMA secure error with device %d\n",
  791. dma_chan[ch].dev_id);
  792. if (unlikely(status & OMAP2_DMA_MISALIGNED_ERR_IRQ))
  793. printk(KERN_INFO "DMA misaligned error with device %d\n",
  794. dma_chan[ch].dev_id);
  795. OMAP_DMA_CSR_REG(ch) = OMAP2_DMA_CSR_CLEAR_MASK;
  796. val = omap_readl(OMAP_DMA4_IRQSTATUS_L0);
  797. /* ch in this function is from 0-31 while in register it is 1-32 */
  798. val = 1 << (ch);
  799. omap_writel(val, OMAP_DMA4_IRQSTATUS_L0);
  800. if (likely(dma_chan[ch].callback != NULL))
  801. dma_chan[ch].callback(ch, status, dma_chan[ch].data);
  802. return 0;
  803. }
  804. /* STATUS register count is from 1-32 while our is 0-31 */
  805. static irqreturn_t omap2_dma_irq_handler(int irq, void *dev_id)
  806. {
  807. u32 val;
  808. int i;
  809. val = omap_readl(OMAP_DMA4_IRQSTATUS_L0);
  810. for (i = 1; i <= OMAP_LOGICAL_DMA_CH_COUNT; i++) {
  811. int active = val & (1 << (i - 1));
  812. if (active)
  813. omap2_dma_handle_ch(i - 1);
  814. }
  815. return IRQ_HANDLED;
  816. }
  817. static struct irqaction omap24xx_dma_irq = {
  818. .name = "DMA",
  819. .handler = omap2_dma_irq_handler,
  820. .flags = IRQF_DISABLED
  821. };
  822. #else
  823. static struct irqaction omap24xx_dma_irq;
  824. #endif
  825. /*----------------------------------------------------------------------------*/
  826. static struct lcd_dma_info {
  827. spinlock_t lock;
  828. int reserved;
  829. void (* callback)(u16 status, void *data);
  830. void *cb_data;
  831. int active;
  832. unsigned long addr, size;
  833. int rotate, data_type, xres, yres;
  834. int vxres;
  835. int mirror;
  836. int xscale, yscale;
  837. int ext_ctrl;
  838. int src_port;
  839. int single_transfer;
  840. } lcd_dma;
  841. void omap_set_lcd_dma_b1(unsigned long addr, u16 fb_xres, u16 fb_yres,
  842. int data_type)
  843. {
  844. lcd_dma.addr = addr;
  845. lcd_dma.data_type = data_type;
  846. lcd_dma.xres = fb_xres;
  847. lcd_dma.yres = fb_yres;
  848. }
  849. void omap_set_lcd_dma_src_port(int port)
  850. {
  851. lcd_dma.src_port = port;
  852. }
  853. void omap_set_lcd_dma_ext_controller(int external)
  854. {
  855. lcd_dma.ext_ctrl = external;
  856. }
  857. void omap_set_lcd_dma_single_transfer(int single)
  858. {
  859. lcd_dma.single_transfer = single;
  860. }
  861. void omap_set_lcd_dma_b1_rotation(int rotate)
  862. {
  863. if (omap_dma_in_1510_mode()) {
  864. printk(KERN_ERR "DMA rotation is not supported in 1510 mode\n");
  865. BUG();
  866. return;
  867. }
  868. lcd_dma.rotate = rotate;
  869. }
  870. void omap_set_lcd_dma_b1_mirror(int mirror)
  871. {
  872. if (omap_dma_in_1510_mode()) {
  873. printk(KERN_ERR "DMA mirror is not supported in 1510 mode\n");
  874. BUG();
  875. }
  876. lcd_dma.mirror = mirror;
  877. }
  878. void omap_set_lcd_dma_b1_vxres(unsigned long vxres)
  879. {
  880. if (omap_dma_in_1510_mode()) {
  881. printk(KERN_ERR "DMA virtual resulotion is not supported "
  882. "in 1510 mode\n");
  883. BUG();
  884. }
  885. lcd_dma.vxres = vxres;
  886. }
  887. void omap_set_lcd_dma_b1_scale(unsigned int xscale, unsigned int yscale)
  888. {
  889. if (omap_dma_in_1510_mode()) {
  890. printk(KERN_ERR "DMA scale is not supported in 1510 mode\n");
  891. BUG();
  892. }
  893. lcd_dma.xscale = xscale;
  894. lcd_dma.yscale = yscale;
  895. }
  896. static void set_b1_regs(void)
  897. {
  898. unsigned long top, bottom;
  899. int es;
  900. u16 w;
  901. unsigned long en, fn;
  902. long ei, fi;
  903. unsigned long vxres;
  904. unsigned int xscale, yscale;
  905. switch (lcd_dma.data_type) {
  906. case OMAP_DMA_DATA_TYPE_S8:
  907. es = 1;
  908. break;
  909. case OMAP_DMA_DATA_TYPE_S16:
  910. es = 2;
  911. break;
  912. case OMAP_DMA_DATA_TYPE_S32:
  913. es = 4;
  914. break;
  915. default:
  916. BUG();
  917. return;
  918. }
  919. vxres = lcd_dma.vxres ? lcd_dma.vxres : lcd_dma.xres;
  920. xscale = lcd_dma.xscale ? lcd_dma.xscale : 1;
  921. yscale = lcd_dma.yscale ? lcd_dma.yscale : 1;
  922. BUG_ON(vxres < lcd_dma.xres);
  923. #define PIXADDR(x,y) (lcd_dma.addr + ((y) * vxres * yscale + (x) * xscale) * es)
  924. #define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
  925. switch (lcd_dma.rotate) {
  926. case 0:
  927. if (!lcd_dma.mirror) {
  928. top = PIXADDR(0, 0);
  929. bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  930. /* 1510 DMA requires the bottom address to be 2 more
  931. * than the actual last memory access location. */
  932. if (omap_dma_in_1510_mode() &&
  933. lcd_dma.data_type == OMAP_DMA_DATA_TYPE_S32)
  934. bottom += 2;
  935. ei = PIXSTEP(0, 0, 1, 0);
  936. fi = PIXSTEP(lcd_dma.xres - 1, 0, 0, 1);
  937. } else {
  938. top = PIXADDR(lcd_dma.xres - 1, 0);
  939. bottom = PIXADDR(0, lcd_dma.yres - 1);
  940. ei = PIXSTEP(1, 0, 0, 0);
  941. fi = PIXSTEP(0, 0, lcd_dma.xres - 1, 1);
  942. }
  943. en = lcd_dma.xres;
  944. fn = lcd_dma.yres;
  945. break;
  946. case 90:
  947. if (!lcd_dma.mirror) {
  948. top = PIXADDR(0, lcd_dma.yres - 1);
  949. bottom = PIXADDR(lcd_dma.xres - 1, 0);
  950. ei = PIXSTEP(0, 1, 0, 0);
  951. fi = PIXSTEP(0, 0, 1, lcd_dma.yres - 1);
  952. } else {
  953. top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  954. bottom = PIXADDR(0, 0);
  955. ei = PIXSTEP(0, 1, 0, 0);
  956. fi = PIXSTEP(1, 0, 0, lcd_dma.yres - 1);
  957. }
  958. en = lcd_dma.yres;
  959. fn = lcd_dma.xres;
  960. break;
  961. case 180:
  962. if (!lcd_dma.mirror) {
  963. top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  964. bottom = PIXADDR(0, 0);
  965. ei = PIXSTEP(1, 0, 0, 0);
  966. fi = PIXSTEP(0, 1, lcd_dma.xres - 1, 0);
  967. } else {
  968. top = PIXADDR(0, lcd_dma.yres - 1);
  969. bottom = PIXADDR(lcd_dma.xres - 1, 0);
  970. ei = PIXSTEP(0, 0, 1, 0);
  971. fi = PIXSTEP(lcd_dma.xres - 1, 1, 0, 0);
  972. }
  973. en = lcd_dma.xres;
  974. fn = lcd_dma.yres;
  975. break;
  976. case 270:
  977. if (!lcd_dma.mirror) {
  978. top = PIXADDR(lcd_dma.xres - 1, 0);
  979. bottom = PIXADDR(0, lcd_dma.yres - 1);
  980. ei = PIXSTEP(0, 0, 0, 1);
  981. fi = PIXSTEP(1, lcd_dma.yres - 1, 0, 0);
  982. } else {
  983. top = PIXADDR(0, 0);
  984. bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  985. ei = PIXSTEP(0, 0, 0, 1);
  986. fi = PIXSTEP(0, lcd_dma.yres - 1, 1, 0);
  987. }
  988. en = lcd_dma.yres;
  989. fn = lcd_dma.xres;
  990. break;
  991. default:
  992. BUG();
  993. return; /* Supress warning about uninitialized vars */
  994. }
  995. if (omap_dma_in_1510_mode()) {
  996. omap_writew(top >> 16, OMAP1510_DMA_LCD_TOP_F1_U);
  997. omap_writew(top, OMAP1510_DMA_LCD_TOP_F1_L);
  998. omap_writew(bottom >> 16, OMAP1510_DMA_LCD_BOT_F1_U);
  999. omap_writew(bottom, OMAP1510_DMA_LCD_BOT_F1_L);
  1000. return;
  1001. }
  1002. /* 1610 regs */
  1003. omap_writew(top >> 16, OMAP1610_DMA_LCD_TOP_B1_U);
  1004. omap_writew(top, OMAP1610_DMA_LCD_TOP_B1_L);
  1005. omap_writew(bottom >> 16, OMAP1610_DMA_LCD_BOT_B1_U);
  1006. omap_writew(bottom, OMAP1610_DMA_LCD_BOT_B1_L);
  1007. omap_writew(en, OMAP1610_DMA_LCD_SRC_EN_B1);
  1008. omap_writew(fn, OMAP1610_DMA_LCD_SRC_FN_B1);
  1009. w = omap_readw(OMAP1610_DMA_LCD_CSDP);
  1010. w &= ~0x03;
  1011. w |= lcd_dma.data_type;
  1012. omap_writew(w, OMAP1610_DMA_LCD_CSDP);
  1013. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1014. /* Always set the source port as SDRAM for now*/
  1015. w &= ~(0x03 << 6);
  1016. if (lcd_dma.callback != NULL)
  1017. w |= 1 << 1; /* Block interrupt enable */
  1018. else
  1019. w &= ~(1 << 1);
  1020. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1021. if (!(lcd_dma.rotate || lcd_dma.mirror ||
  1022. lcd_dma.vxres || lcd_dma.xscale || lcd_dma.yscale))
  1023. return;
  1024. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1025. /* Set the double-indexed addressing mode */
  1026. w |= (0x03 << 12);
  1027. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1028. omap_writew(ei, OMAP1610_DMA_LCD_SRC_EI_B1);
  1029. omap_writew(fi >> 16, OMAP1610_DMA_LCD_SRC_FI_B1_U);
  1030. omap_writew(fi, OMAP1610_DMA_LCD_SRC_FI_B1_L);
  1031. }
  1032. static irqreturn_t lcd_dma_irq_handler(int irq, void *dev_id)
  1033. {
  1034. u16 w;
  1035. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1036. if (unlikely(!(w & (1 << 3)))) {
  1037. printk(KERN_WARNING "Spurious LCD DMA IRQ\n");
  1038. return IRQ_NONE;
  1039. }
  1040. /* Ack the IRQ */
  1041. w |= (1 << 3);
  1042. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1043. lcd_dma.active = 0;
  1044. if (lcd_dma.callback != NULL)
  1045. lcd_dma.callback(w, lcd_dma.cb_data);
  1046. return IRQ_HANDLED;
  1047. }
  1048. int omap_request_lcd_dma(void (* callback)(u16 status, void *data),
  1049. void *data)
  1050. {
  1051. spin_lock_irq(&lcd_dma.lock);
  1052. if (lcd_dma.reserved) {
  1053. spin_unlock_irq(&lcd_dma.lock);
  1054. printk(KERN_ERR "LCD DMA channel already reserved\n");
  1055. BUG();
  1056. return -EBUSY;
  1057. }
  1058. lcd_dma.reserved = 1;
  1059. spin_unlock_irq(&lcd_dma.lock);
  1060. lcd_dma.callback = callback;
  1061. lcd_dma.cb_data = data;
  1062. lcd_dma.active = 0;
  1063. lcd_dma.single_transfer = 0;
  1064. lcd_dma.rotate = 0;
  1065. lcd_dma.vxres = 0;
  1066. lcd_dma.mirror = 0;
  1067. lcd_dma.xscale = 0;
  1068. lcd_dma.yscale = 0;
  1069. lcd_dma.ext_ctrl = 0;
  1070. lcd_dma.src_port = 0;
  1071. return 0;
  1072. }
  1073. void omap_free_lcd_dma(void)
  1074. {
  1075. spin_lock(&lcd_dma.lock);
  1076. if (!lcd_dma.reserved) {
  1077. spin_unlock(&lcd_dma.lock);
  1078. printk(KERN_ERR "LCD DMA is not reserved\n");
  1079. BUG();
  1080. return;
  1081. }
  1082. if (!enable_1510_mode)
  1083. omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR) & ~1,
  1084. OMAP1610_DMA_LCD_CCR);
  1085. lcd_dma.reserved = 0;
  1086. spin_unlock(&lcd_dma.lock);
  1087. }
  1088. void omap_enable_lcd_dma(void)
  1089. {
  1090. u16 w;
  1091. /* Set the Enable bit only if an external controller is
  1092. * connected. Otherwise the OMAP internal controller will
  1093. * start the transfer when it gets enabled.
  1094. */
  1095. if (enable_1510_mode || !lcd_dma.ext_ctrl)
  1096. return;
  1097. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1098. w |= 1 << 8;
  1099. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1100. lcd_dma.active = 1;
  1101. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1102. w |= 1 << 7;
  1103. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1104. }
  1105. void omap_setup_lcd_dma(void)
  1106. {
  1107. BUG_ON(lcd_dma.active);
  1108. if (!enable_1510_mode) {
  1109. /* Set some reasonable defaults */
  1110. omap_writew(0x5440, OMAP1610_DMA_LCD_CCR);
  1111. omap_writew(0x9102, OMAP1610_DMA_LCD_CSDP);
  1112. omap_writew(0x0004, OMAP1610_DMA_LCD_LCH_CTRL);
  1113. }
  1114. set_b1_regs();
  1115. if (!enable_1510_mode) {
  1116. u16 w;
  1117. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1118. /* If DMA was already active set the end_prog bit to have
  1119. * the programmed register set loaded into the active
  1120. * register set.
  1121. */
  1122. w |= 1 << 11; /* End_prog */
  1123. if (!lcd_dma.single_transfer)
  1124. w |= (3 << 8); /* Auto_init, repeat */
  1125. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1126. }
  1127. }
  1128. void omap_stop_lcd_dma(void)
  1129. {
  1130. u16 w;
  1131. lcd_dma.active = 0;
  1132. if (enable_1510_mode || !lcd_dma.ext_ctrl)
  1133. return;
  1134. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1135. w &= ~(1 << 7);
  1136. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1137. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1138. w &= ~(1 << 8);
  1139. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1140. }
  1141. int omap_lcd_dma_ext_running(void)
  1142. {
  1143. return lcd_dma.ext_ctrl && lcd_dma.active;
  1144. }
  1145. /*----------------------------------------------------------------------------*/
  1146. static int __init omap_init_dma(void)
  1147. {
  1148. int ch, r;
  1149. if (cpu_is_omap15xx()) {
  1150. printk(KERN_INFO "DMA support for OMAP15xx initialized\n");
  1151. dma_chan_count = 9;
  1152. enable_1510_mode = 1;
  1153. } else if (cpu_is_omap16xx() || cpu_is_omap730()) {
  1154. printk(KERN_INFO "OMAP DMA hardware version %d\n",
  1155. omap_readw(OMAP_DMA_HW_ID));
  1156. printk(KERN_INFO "DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
  1157. (omap_readw(OMAP_DMA_CAPS_0_U) << 16) |
  1158. omap_readw(OMAP_DMA_CAPS_0_L),
  1159. (omap_readw(OMAP_DMA_CAPS_1_U) << 16) |
  1160. omap_readw(OMAP_DMA_CAPS_1_L),
  1161. omap_readw(OMAP_DMA_CAPS_2), omap_readw(OMAP_DMA_CAPS_3),
  1162. omap_readw(OMAP_DMA_CAPS_4));
  1163. if (!enable_1510_mode) {
  1164. u16 w;
  1165. /* Disable OMAP 3.0/3.1 compatibility mode. */
  1166. w = omap_readw(OMAP_DMA_GSCR);
  1167. w |= 1 << 3;
  1168. omap_writew(w, OMAP_DMA_GSCR);
  1169. dma_chan_count = 16;
  1170. } else
  1171. dma_chan_count = 9;
  1172. if (cpu_is_omap16xx()) {
  1173. u16 w;
  1174. /* this would prevent OMAP sleep */
  1175. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1176. w &= ~(1 << 8);
  1177. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1178. }
  1179. } else if (cpu_is_omap24xx()) {
  1180. u8 revision = omap_readb(OMAP_DMA4_REVISION);
  1181. printk(KERN_INFO "OMAP DMA hardware revision %d.%d\n",
  1182. revision >> 4, revision & 0xf);
  1183. dma_chan_count = OMAP_LOGICAL_DMA_CH_COUNT;
  1184. } else {
  1185. dma_chan_count = 0;
  1186. return 0;
  1187. }
  1188. memset(&lcd_dma, 0, sizeof(lcd_dma));
  1189. spin_lock_init(&lcd_dma.lock);
  1190. spin_lock_init(&dma_chan_lock);
  1191. memset(&dma_chan, 0, sizeof(dma_chan));
  1192. for (ch = 0; ch < dma_chan_count; ch++) {
  1193. omap_clear_dma(ch);
  1194. dma_chan[ch].dev_id = -1;
  1195. dma_chan[ch].next_lch = -1;
  1196. if (ch >= 6 && enable_1510_mode)
  1197. continue;
  1198. if (cpu_class_is_omap1()) {
  1199. /* request_irq() doesn't like dev_id (ie. ch) being
  1200. * zero, so we have to kludge around this. */
  1201. r = request_irq(omap1_dma_irq[ch],
  1202. omap1_dma_irq_handler, 0, "DMA",
  1203. (void *) (ch + 1));
  1204. if (r != 0) {
  1205. int i;
  1206. printk(KERN_ERR "unable to request IRQ %d "
  1207. "for DMA (error %d)\n",
  1208. omap1_dma_irq[ch], r);
  1209. for (i = 0; i < ch; i++)
  1210. free_irq(omap1_dma_irq[i],
  1211. (void *) (i + 1));
  1212. return r;
  1213. }
  1214. }
  1215. }
  1216. if (cpu_is_omap24xx())
  1217. setup_irq(INT_24XX_SDMA_IRQ0, &omap24xx_dma_irq);
  1218. /* FIXME: Update LCD DMA to work on 24xx */
  1219. if (cpu_class_is_omap1()) {
  1220. r = request_irq(INT_DMA_LCD, lcd_dma_irq_handler, 0,
  1221. "LCD DMA", NULL);
  1222. if (r != 0) {
  1223. int i;
  1224. printk(KERN_ERR "unable to request IRQ for LCD DMA "
  1225. "(error %d)\n", r);
  1226. for (i = 0; i < dma_chan_count; i++)
  1227. free_irq(omap1_dma_irq[i], (void *) (i + 1));
  1228. return r;
  1229. }
  1230. }
  1231. return 0;
  1232. }
  1233. arch_initcall(omap_init_dma);
  1234. EXPORT_SYMBOL(omap_get_dma_src_pos);
  1235. EXPORT_SYMBOL(omap_get_dma_dst_pos);
  1236. EXPORT_SYMBOL(omap_get_dma_src_addr_counter);
  1237. EXPORT_SYMBOL(omap_clear_dma);
  1238. EXPORT_SYMBOL(omap_set_dma_priority);
  1239. EXPORT_SYMBOL(omap_request_dma);
  1240. EXPORT_SYMBOL(omap_free_dma);
  1241. EXPORT_SYMBOL(omap_start_dma);
  1242. EXPORT_SYMBOL(omap_stop_dma);
  1243. EXPORT_SYMBOL(omap_set_dma_callback);
  1244. EXPORT_SYMBOL(omap_enable_dma_irq);
  1245. EXPORT_SYMBOL(omap_disable_dma_irq);
  1246. EXPORT_SYMBOL(omap_set_dma_transfer_params);
  1247. EXPORT_SYMBOL(omap_set_dma_color_mode);
  1248. EXPORT_SYMBOL(omap_set_dma_write_mode);
  1249. EXPORT_SYMBOL(omap_set_dma_src_params);
  1250. EXPORT_SYMBOL(omap_set_dma_src_index);
  1251. EXPORT_SYMBOL(omap_set_dma_src_data_pack);
  1252. EXPORT_SYMBOL(omap_set_dma_src_burst_mode);
  1253. EXPORT_SYMBOL(omap_set_dma_dest_params);
  1254. EXPORT_SYMBOL(omap_set_dma_dest_index);
  1255. EXPORT_SYMBOL(omap_set_dma_dest_data_pack);
  1256. EXPORT_SYMBOL(omap_set_dma_dest_burst_mode);
  1257. EXPORT_SYMBOL(omap_set_dma_params);
  1258. EXPORT_SYMBOL(omap_dma_link_lch);
  1259. EXPORT_SYMBOL(omap_dma_unlink_lch);
  1260. EXPORT_SYMBOL(omap_request_lcd_dma);
  1261. EXPORT_SYMBOL(omap_free_lcd_dma);
  1262. EXPORT_SYMBOL(omap_enable_lcd_dma);
  1263. EXPORT_SYMBOL(omap_setup_lcd_dma);
  1264. EXPORT_SYMBOL(omap_stop_lcd_dma);
  1265. EXPORT_SYMBOL(omap_lcd_dma_ext_running);
  1266. EXPORT_SYMBOL(omap_set_lcd_dma_b1);
  1267. EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer);
  1268. EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller);
  1269. EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation);
  1270. EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres);
  1271. EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale);
  1272. EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror);