dma.c 34 KB

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