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(~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. struct pt_regs *regs)
  757. {
  758. int ch = ((int) dev_id) - 1;
  759. int handled = 0;
  760. for (;;) {
  761. int handled_now = 0;
  762. handled_now += omap1_dma_handle_ch(ch);
  763. if (enable_1510_mode && dma_chan[ch + 6].saved_csr)
  764. handled_now += omap1_dma_handle_ch(ch + 6);
  765. if (!handled_now)
  766. break;
  767. handled += handled_now;
  768. }
  769. return handled ? IRQ_HANDLED : IRQ_NONE;
  770. }
  771. #else
  772. #define omap1_dma_irq_handler NULL
  773. #endif
  774. #ifdef CONFIG_ARCH_OMAP2
  775. static int omap2_dma_handle_ch(int ch)
  776. {
  777. u32 status = OMAP_DMA_CSR_REG(ch);
  778. u32 val;
  779. if (!status)
  780. return 0;
  781. if (unlikely(dma_chan[ch].dev_id == -1))
  782. return 0;
  783. if (unlikely(status & OMAP_DMA_DROP_IRQ))
  784. printk(KERN_INFO
  785. "DMA synchronization event drop occurred with device "
  786. "%d\n", dma_chan[ch].dev_id);
  787. if (unlikely(status & OMAP2_DMA_TRANS_ERR_IRQ))
  788. printk(KERN_INFO "DMA transaction error with device %d\n",
  789. dma_chan[ch].dev_id);
  790. if (unlikely(status & OMAP2_DMA_SECURE_ERR_IRQ))
  791. printk(KERN_INFO "DMA secure error with device %d\n",
  792. dma_chan[ch].dev_id);
  793. if (unlikely(status & OMAP2_DMA_MISALIGNED_ERR_IRQ))
  794. printk(KERN_INFO "DMA misaligned error with device %d\n",
  795. dma_chan[ch].dev_id);
  796. OMAP_DMA_CSR_REG(ch) = OMAP2_DMA_CSR_CLEAR_MASK;
  797. val = omap_readl(OMAP_DMA4_IRQSTATUS_L0);
  798. /* ch in this function is from 0-31 while in register it is 1-32 */
  799. val = 1 << (ch);
  800. omap_writel(val, 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. struct pt_regs *regs)
  808. {
  809. u32 val;
  810. int i;
  811. val = omap_readl(OMAP_DMA4_IRQSTATUS_L0);
  812. for (i = 1; i <= OMAP_LOGICAL_DMA_CH_COUNT; i++) {
  813. int active = val & (1 << (i - 1));
  814. if (active)
  815. omap2_dma_handle_ch(i - 1);
  816. }
  817. return IRQ_HANDLED;
  818. }
  819. static struct irqaction omap24xx_dma_irq = {
  820. .name = "DMA",
  821. .handler = omap2_dma_irq_handler,
  822. .flags = IRQF_DISABLED
  823. };
  824. #else
  825. static struct irqaction omap24xx_dma_irq;
  826. #endif
  827. /*----------------------------------------------------------------------------*/
  828. static struct lcd_dma_info {
  829. spinlock_t lock;
  830. int reserved;
  831. void (* callback)(u16 status, void *data);
  832. void *cb_data;
  833. int active;
  834. unsigned long addr, size;
  835. int rotate, data_type, xres, yres;
  836. int vxres;
  837. int mirror;
  838. int xscale, yscale;
  839. int ext_ctrl;
  840. int src_port;
  841. int single_transfer;
  842. } lcd_dma;
  843. void omap_set_lcd_dma_b1(unsigned long addr, u16 fb_xres, u16 fb_yres,
  844. int data_type)
  845. {
  846. lcd_dma.addr = addr;
  847. lcd_dma.data_type = data_type;
  848. lcd_dma.xres = fb_xres;
  849. lcd_dma.yres = fb_yres;
  850. }
  851. void omap_set_lcd_dma_src_port(int port)
  852. {
  853. lcd_dma.src_port = port;
  854. }
  855. void omap_set_lcd_dma_ext_controller(int external)
  856. {
  857. lcd_dma.ext_ctrl = external;
  858. }
  859. void omap_set_lcd_dma_single_transfer(int single)
  860. {
  861. lcd_dma.single_transfer = single;
  862. }
  863. void omap_set_lcd_dma_b1_rotation(int rotate)
  864. {
  865. if (omap_dma_in_1510_mode()) {
  866. printk(KERN_ERR "DMA rotation is not supported in 1510 mode\n");
  867. BUG();
  868. return;
  869. }
  870. lcd_dma.rotate = rotate;
  871. }
  872. void omap_set_lcd_dma_b1_mirror(int mirror)
  873. {
  874. if (omap_dma_in_1510_mode()) {
  875. printk(KERN_ERR "DMA mirror is not supported in 1510 mode\n");
  876. BUG();
  877. }
  878. lcd_dma.mirror = mirror;
  879. }
  880. void omap_set_lcd_dma_b1_vxres(unsigned long vxres)
  881. {
  882. if (omap_dma_in_1510_mode()) {
  883. printk(KERN_ERR "DMA virtual resulotion is not supported "
  884. "in 1510 mode\n");
  885. BUG();
  886. }
  887. lcd_dma.vxres = vxres;
  888. }
  889. void omap_set_lcd_dma_b1_scale(unsigned int xscale, unsigned int yscale)
  890. {
  891. if (omap_dma_in_1510_mode()) {
  892. printk(KERN_ERR "DMA scale is not supported in 1510 mode\n");
  893. BUG();
  894. }
  895. lcd_dma.xscale = xscale;
  896. lcd_dma.yscale = yscale;
  897. }
  898. static void set_b1_regs(void)
  899. {
  900. unsigned long top, bottom;
  901. int es;
  902. u16 w;
  903. unsigned long en, fn;
  904. long ei, fi;
  905. unsigned long vxres;
  906. unsigned int xscale, yscale;
  907. switch (lcd_dma.data_type) {
  908. case OMAP_DMA_DATA_TYPE_S8:
  909. es = 1;
  910. break;
  911. case OMAP_DMA_DATA_TYPE_S16:
  912. es = 2;
  913. break;
  914. case OMAP_DMA_DATA_TYPE_S32:
  915. es = 4;
  916. break;
  917. default:
  918. BUG();
  919. return;
  920. }
  921. vxres = lcd_dma.vxres ? lcd_dma.vxres : lcd_dma.xres;
  922. xscale = lcd_dma.xscale ? lcd_dma.xscale : 1;
  923. yscale = lcd_dma.yscale ? lcd_dma.yscale : 1;
  924. BUG_ON(vxres < lcd_dma.xres);
  925. #define PIXADDR(x,y) (lcd_dma.addr + ((y) * vxres * yscale + (x) * xscale) * es)
  926. #define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
  927. switch (lcd_dma.rotate) {
  928. case 0:
  929. if (!lcd_dma.mirror) {
  930. top = PIXADDR(0, 0);
  931. bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  932. /* 1510 DMA requires the bottom address to be 2 more
  933. * than the actual last memory access location. */
  934. if (omap_dma_in_1510_mode() &&
  935. lcd_dma.data_type == OMAP_DMA_DATA_TYPE_S32)
  936. bottom += 2;
  937. ei = PIXSTEP(0, 0, 1, 0);
  938. fi = PIXSTEP(lcd_dma.xres - 1, 0, 0, 1);
  939. } else {
  940. top = PIXADDR(lcd_dma.xres - 1, 0);
  941. bottom = PIXADDR(0, lcd_dma.yres - 1);
  942. ei = PIXSTEP(1, 0, 0, 0);
  943. fi = PIXSTEP(0, 0, lcd_dma.xres - 1, 1);
  944. }
  945. en = lcd_dma.xres;
  946. fn = lcd_dma.yres;
  947. break;
  948. case 90:
  949. if (!lcd_dma.mirror) {
  950. top = PIXADDR(0, lcd_dma.yres - 1);
  951. bottom = PIXADDR(lcd_dma.xres - 1, 0);
  952. ei = PIXSTEP(0, 1, 0, 0);
  953. fi = PIXSTEP(0, 0, 1, lcd_dma.yres - 1);
  954. } else {
  955. top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  956. bottom = PIXADDR(0, 0);
  957. ei = PIXSTEP(0, 1, 0, 0);
  958. fi = PIXSTEP(1, 0, 0, lcd_dma.yres - 1);
  959. }
  960. en = lcd_dma.yres;
  961. fn = lcd_dma.xres;
  962. break;
  963. case 180:
  964. if (!lcd_dma.mirror) {
  965. top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  966. bottom = PIXADDR(0, 0);
  967. ei = PIXSTEP(1, 0, 0, 0);
  968. fi = PIXSTEP(0, 1, lcd_dma.xres - 1, 0);
  969. } else {
  970. top = PIXADDR(0, lcd_dma.yres - 1);
  971. bottom = PIXADDR(lcd_dma.xres - 1, 0);
  972. ei = PIXSTEP(0, 0, 1, 0);
  973. fi = PIXSTEP(lcd_dma.xres - 1, 1, 0, 0);
  974. }
  975. en = lcd_dma.xres;
  976. fn = lcd_dma.yres;
  977. break;
  978. case 270:
  979. if (!lcd_dma.mirror) {
  980. top = PIXADDR(lcd_dma.xres - 1, 0);
  981. bottom = PIXADDR(0, lcd_dma.yres - 1);
  982. ei = PIXSTEP(0, 0, 0, 1);
  983. fi = PIXSTEP(1, lcd_dma.yres - 1, 0, 0);
  984. } else {
  985. top = PIXADDR(0, 0);
  986. bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  987. ei = PIXSTEP(0, 0, 0, 1);
  988. fi = PIXSTEP(0, lcd_dma.yres - 1, 1, 0);
  989. }
  990. en = lcd_dma.yres;
  991. fn = lcd_dma.xres;
  992. break;
  993. default:
  994. BUG();
  995. return; /* Supress warning about uninitialized vars */
  996. }
  997. if (omap_dma_in_1510_mode()) {
  998. omap_writew(top >> 16, OMAP1510_DMA_LCD_TOP_F1_U);
  999. omap_writew(top, OMAP1510_DMA_LCD_TOP_F1_L);
  1000. omap_writew(bottom >> 16, OMAP1510_DMA_LCD_BOT_F1_U);
  1001. omap_writew(bottom, OMAP1510_DMA_LCD_BOT_F1_L);
  1002. return;
  1003. }
  1004. /* 1610 regs */
  1005. omap_writew(top >> 16, OMAP1610_DMA_LCD_TOP_B1_U);
  1006. omap_writew(top, OMAP1610_DMA_LCD_TOP_B1_L);
  1007. omap_writew(bottom >> 16, OMAP1610_DMA_LCD_BOT_B1_U);
  1008. omap_writew(bottom, OMAP1610_DMA_LCD_BOT_B1_L);
  1009. omap_writew(en, OMAP1610_DMA_LCD_SRC_EN_B1);
  1010. omap_writew(fn, OMAP1610_DMA_LCD_SRC_FN_B1);
  1011. w = omap_readw(OMAP1610_DMA_LCD_CSDP);
  1012. w &= ~0x03;
  1013. w |= lcd_dma.data_type;
  1014. omap_writew(w, OMAP1610_DMA_LCD_CSDP);
  1015. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1016. /* Always set the source port as SDRAM for now*/
  1017. w &= ~(0x03 << 6);
  1018. if (lcd_dma.callback != NULL)
  1019. w |= 1 << 1; /* Block interrupt enable */
  1020. else
  1021. w &= ~(1 << 1);
  1022. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1023. if (!(lcd_dma.rotate || lcd_dma.mirror ||
  1024. lcd_dma.vxres || lcd_dma.xscale || lcd_dma.yscale))
  1025. return;
  1026. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1027. /* Set the double-indexed addressing mode */
  1028. w |= (0x03 << 12);
  1029. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1030. omap_writew(ei, OMAP1610_DMA_LCD_SRC_EI_B1);
  1031. omap_writew(fi >> 16, OMAP1610_DMA_LCD_SRC_FI_B1_U);
  1032. omap_writew(fi, OMAP1610_DMA_LCD_SRC_FI_B1_L);
  1033. }
  1034. static irqreturn_t lcd_dma_irq_handler(int irq, void *dev_id,
  1035. struct pt_regs *regs)
  1036. {
  1037. u16 w;
  1038. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1039. if (unlikely(!(w & (1 << 3)))) {
  1040. printk(KERN_WARNING "Spurious LCD DMA IRQ\n");
  1041. return IRQ_NONE;
  1042. }
  1043. /* Ack the IRQ */
  1044. w |= (1 << 3);
  1045. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1046. lcd_dma.active = 0;
  1047. if (lcd_dma.callback != NULL)
  1048. lcd_dma.callback(w, lcd_dma.cb_data);
  1049. return IRQ_HANDLED;
  1050. }
  1051. int omap_request_lcd_dma(void (* callback)(u16 status, void *data),
  1052. void *data)
  1053. {
  1054. spin_lock_irq(&lcd_dma.lock);
  1055. if (lcd_dma.reserved) {
  1056. spin_unlock_irq(&lcd_dma.lock);
  1057. printk(KERN_ERR "LCD DMA channel already reserved\n");
  1058. BUG();
  1059. return -EBUSY;
  1060. }
  1061. lcd_dma.reserved = 1;
  1062. spin_unlock_irq(&lcd_dma.lock);
  1063. lcd_dma.callback = callback;
  1064. lcd_dma.cb_data = data;
  1065. lcd_dma.active = 0;
  1066. lcd_dma.single_transfer = 0;
  1067. lcd_dma.rotate = 0;
  1068. lcd_dma.vxres = 0;
  1069. lcd_dma.mirror = 0;
  1070. lcd_dma.xscale = 0;
  1071. lcd_dma.yscale = 0;
  1072. lcd_dma.ext_ctrl = 0;
  1073. lcd_dma.src_port = 0;
  1074. return 0;
  1075. }
  1076. void omap_free_lcd_dma(void)
  1077. {
  1078. spin_lock(&lcd_dma.lock);
  1079. if (!lcd_dma.reserved) {
  1080. spin_unlock(&lcd_dma.lock);
  1081. printk(KERN_ERR "LCD DMA is not reserved\n");
  1082. BUG();
  1083. return;
  1084. }
  1085. if (!enable_1510_mode)
  1086. omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR) & ~1,
  1087. OMAP1610_DMA_LCD_CCR);
  1088. lcd_dma.reserved = 0;
  1089. spin_unlock(&lcd_dma.lock);
  1090. }
  1091. void omap_enable_lcd_dma(void)
  1092. {
  1093. u16 w;
  1094. /* Set the Enable bit only if an external controller is
  1095. * connected. Otherwise the OMAP internal controller will
  1096. * start the transfer when it gets enabled.
  1097. */
  1098. if (enable_1510_mode || !lcd_dma.ext_ctrl)
  1099. return;
  1100. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1101. w |= 1 << 8;
  1102. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1103. lcd_dma.active = 1;
  1104. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1105. w |= 1 << 7;
  1106. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1107. }
  1108. void omap_setup_lcd_dma(void)
  1109. {
  1110. BUG_ON(lcd_dma.active);
  1111. if (!enable_1510_mode) {
  1112. /* Set some reasonable defaults */
  1113. omap_writew(0x5440, OMAP1610_DMA_LCD_CCR);
  1114. omap_writew(0x9102, OMAP1610_DMA_LCD_CSDP);
  1115. omap_writew(0x0004, OMAP1610_DMA_LCD_LCH_CTRL);
  1116. }
  1117. set_b1_regs();
  1118. if (!enable_1510_mode) {
  1119. u16 w;
  1120. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1121. /* If DMA was already active set the end_prog bit to have
  1122. * the programmed register set loaded into the active
  1123. * register set.
  1124. */
  1125. w |= 1 << 11; /* End_prog */
  1126. if (!lcd_dma.single_transfer)
  1127. w |= (3 << 8); /* Auto_init, repeat */
  1128. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1129. }
  1130. }
  1131. void omap_stop_lcd_dma(void)
  1132. {
  1133. u16 w;
  1134. lcd_dma.active = 0;
  1135. if (enable_1510_mode || !lcd_dma.ext_ctrl)
  1136. return;
  1137. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  1138. w &= ~(1 << 7);
  1139. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  1140. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1141. w &= ~(1 << 8);
  1142. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1143. }
  1144. int omap_lcd_dma_ext_running(void)
  1145. {
  1146. return lcd_dma.ext_ctrl && lcd_dma.active;
  1147. }
  1148. /*----------------------------------------------------------------------------*/
  1149. static int __init omap_init_dma(void)
  1150. {
  1151. int ch, r;
  1152. if (cpu_is_omap15xx()) {
  1153. printk(KERN_INFO "DMA support for OMAP15xx initialized\n");
  1154. dma_chan_count = 9;
  1155. enable_1510_mode = 1;
  1156. } else if (cpu_is_omap16xx() || cpu_is_omap730()) {
  1157. printk(KERN_INFO "OMAP DMA hardware version %d\n",
  1158. omap_readw(OMAP_DMA_HW_ID));
  1159. printk(KERN_INFO "DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
  1160. (omap_readw(OMAP_DMA_CAPS_0_U) << 16) |
  1161. omap_readw(OMAP_DMA_CAPS_0_L),
  1162. (omap_readw(OMAP_DMA_CAPS_1_U) << 16) |
  1163. omap_readw(OMAP_DMA_CAPS_1_L),
  1164. omap_readw(OMAP_DMA_CAPS_2), omap_readw(OMAP_DMA_CAPS_3),
  1165. omap_readw(OMAP_DMA_CAPS_4));
  1166. if (!enable_1510_mode) {
  1167. u16 w;
  1168. /* Disable OMAP 3.0/3.1 compatibility mode. */
  1169. w = omap_readw(OMAP_DMA_GSCR);
  1170. w |= 1 << 3;
  1171. omap_writew(w, OMAP_DMA_GSCR);
  1172. dma_chan_count = 16;
  1173. } else
  1174. dma_chan_count = 9;
  1175. if (cpu_is_omap16xx()) {
  1176. u16 w;
  1177. /* this would prevent OMAP sleep */
  1178. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  1179. w &= ~(1 << 8);
  1180. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  1181. }
  1182. } else if (cpu_is_omap24xx()) {
  1183. u8 revision = omap_readb(OMAP_DMA4_REVISION);
  1184. printk(KERN_INFO "OMAP DMA hardware revision %d.%d\n",
  1185. revision >> 4, revision & 0xf);
  1186. dma_chan_count = OMAP_LOGICAL_DMA_CH_COUNT;
  1187. } else {
  1188. dma_chan_count = 0;
  1189. return 0;
  1190. }
  1191. memset(&lcd_dma, 0, sizeof(lcd_dma));
  1192. spin_lock_init(&lcd_dma.lock);
  1193. spin_lock_init(&dma_chan_lock);
  1194. memset(&dma_chan, 0, sizeof(dma_chan));
  1195. for (ch = 0; ch < dma_chan_count; ch++) {
  1196. omap_clear_dma(ch);
  1197. dma_chan[ch].dev_id = -1;
  1198. dma_chan[ch].next_lch = -1;
  1199. if (ch >= 6 && enable_1510_mode)
  1200. continue;
  1201. if (cpu_class_is_omap1()) {
  1202. /* request_irq() doesn't like dev_id (ie. ch) being
  1203. * zero, so we have to kludge around this. */
  1204. r = request_irq(omap1_dma_irq[ch],
  1205. omap1_dma_irq_handler, 0, "DMA",
  1206. (void *) (ch + 1));
  1207. if (r != 0) {
  1208. int i;
  1209. printk(KERN_ERR "unable to request IRQ %d "
  1210. "for DMA (error %d)\n",
  1211. omap1_dma_irq[ch], r);
  1212. for (i = 0; i < ch; i++)
  1213. free_irq(omap1_dma_irq[i],
  1214. (void *) (i + 1));
  1215. return r;
  1216. }
  1217. }
  1218. }
  1219. if (cpu_is_omap24xx())
  1220. setup_irq(INT_24XX_SDMA_IRQ0, &omap24xx_dma_irq);
  1221. /* FIXME: Update LCD DMA to work on 24xx */
  1222. if (cpu_class_is_omap1()) {
  1223. r = request_irq(INT_DMA_LCD, lcd_dma_irq_handler, 0,
  1224. "LCD DMA", NULL);
  1225. if (r != 0) {
  1226. int i;
  1227. printk(KERN_ERR "unable to request IRQ for LCD DMA "
  1228. "(error %d)\n", r);
  1229. for (i = 0; i < dma_chan_count; i++)
  1230. free_irq(omap1_dma_irq[i], (void *) (i + 1));
  1231. return r;
  1232. }
  1233. }
  1234. return 0;
  1235. }
  1236. arch_initcall(omap_init_dma);
  1237. EXPORT_SYMBOL(omap_get_dma_src_pos);
  1238. EXPORT_SYMBOL(omap_get_dma_dst_pos);
  1239. EXPORT_SYMBOL(omap_get_dma_src_addr_counter);
  1240. EXPORT_SYMBOL(omap_clear_dma);
  1241. EXPORT_SYMBOL(omap_set_dma_priority);
  1242. EXPORT_SYMBOL(omap_request_dma);
  1243. EXPORT_SYMBOL(omap_free_dma);
  1244. EXPORT_SYMBOL(omap_start_dma);
  1245. EXPORT_SYMBOL(omap_stop_dma);
  1246. EXPORT_SYMBOL(omap_set_dma_callback);
  1247. EXPORT_SYMBOL(omap_enable_dma_irq);
  1248. EXPORT_SYMBOL(omap_disable_dma_irq);
  1249. EXPORT_SYMBOL(omap_set_dma_transfer_params);
  1250. EXPORT_SYMBOL(omap_set_dma_color_mode);
  1251. EXPORT_SYMBOL(omap_set_dma_write_mode);
  1252. EXPORT_SYMBOL(omap_set_dma_src_params);
  1253. EXPORT_SYMBOL(omap_set_dma_src_index);
  1254. EXPORT_SYMBOL(omap_set_dma_src_data_pack);
  1255. EXPORT_SYMBOL(omap_set_dma_src_burst_mode);
  1256. EXPORT_SYMBOL(omap_set_dma_dest_params);
  1257. EXPORT_SYMBOL(omap_set_dma_dest_index);
  1258. EXPORT_SYMBOL(omap_set_dma_dest_data_pack);
  1259. EXPORT_SYMBOL(omap_set_dma_dest_burst_mode);
  1260. EXPORT_SYMBOL(omap_set_dma_params);
  1261. EXPORT_SYMBOL(omap_dma_link_lch);
  1262. EXPORT_SYMBOL(omap_dma_unlink_lch);
  1263. EXPORT_SYMBOL(omap_request_lcd_dma);
  1264. EXPORT_SYMBOL(omap_free_lcd_dma);
  1265. EXPORT_SYMBOL(omap_enable_lcd_dma);
  1266. EXPORT_SYMBOL(omap_setup_lcd_dma);
  1267. EXPORT_SYMBOL(omap_stop_lcd_dma);
  1268. EXPORT_SYMBOL(omap_lcd_dma_ext_running);
  1269. EXPORT_SYMBOL(omap_set_lcd_dma_b1);
  1270. EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer);
  1271. EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller);
  1272. EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation);
  1273. EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres);
  1274. EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale);
  1275. EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror);