lcd_dma.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  2. * linux/arch/arm/mach-omap1/lcd_dma.c
  3. *
  4. * Extracted from arch/arm/plat-omap/dma.c
  5. * Copyright (C) 2003 - 2008 Nokia Corporation
  6. * Author: Juha Yrjölä <juha.yrjola@nokia.com>
  7. * DMA channel linking for 1610 by Samuel Ortiz <samuel.ortiz@nokia.com>
  8. * Graphics DMA and LCD DMA graphics tranformations
  9. * by Imre Deak <imre.deak@nokia.com>
  10. * OMAP2/3 support Copyright (C) 2004-2007 Texas Instruments, Inc.
  11. * Merged to support both OMAP1 and OMAP2 by Tony Lindgren <tony@atomide.com>
  12. * Some functions based on earlier dma-omap.c Copyright (C) 2001 RidgeRun, Inc.
  13. *
  14. * Copyright (C) 2009 Texas Instruments
  15. * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
  16. *
  17. * Support functions for the OMAP internal DMA channels.
  18. *
  19. * This program is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License version 2 as
  21. * published by the Free Software Foundation.
  22. *
  23. */
  24. #include <linux/module.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/io.h>
  28. #include <mach/hardware.h>
  29. #include <plat/dma.h>
  30. int omap_lcd_dma_running(void)
  31. {
  32. /*
  33. * On OMAP1510, internal LCD controller will start the transfer
  34. * when it gets enabled, so assume DMA running if LCD enabled.
  35. */
  36. if (cpu_is_omap1510())
  37. if (omap_readw(0xfffec000 + 0x00) & (1 << 0))
  38. return 1;
  39. /* Check if LCD DMA is running */
  40. if (cpu_is_omap16xx())
  41. if (omap_readw(OMAP1610_DMA_LCD_CCR) & OMAP_DMA_CCR_EN)
  42. return 1;
  43. return 0;
  44. }
  45. static struct lcd_dma_info {
  46. spinlock_t lock;
  47. int reserved;
  48. void (*callback)(u16 status, void *data);
  49. void *cb_data;
  50. int active;
  51. unsigned long addr, size;
  52. int rotate, data_type, xres, yres;
  53. int vxres;
  54. int mirror;
  55. int xscale, yscale;
  56. int ext_ctrl;
  57. int src_port;
  58. int single_transfer;
  59. } lcd_dma;
  60. void omap_set_lcd_dma_b1(unsigned long addr, u16 fb_xres, u16 fb_yres,
  61. int data_type)
  62. {
  63. lcd_dma.addr = addr;
  64. lcd_dma.data_type = data_type;
  65. lcd_dma.xres = fb_xres;
  66. lcd_dma.yres = fb_yres;
  67. }
  68. EXPORT_SYMBOL(omap_set_lcd_dma_b1);
  69. void omap_set_lcd_dma_src_port(int port)
  70. {
  71. lcd_dma.src_port = port;
  72. }
  73. void omap_set_lcd_dma_ext_controller(int external)
  74. {
  75. lcd_dma.ext_ctrl = external;
  76. }
  77. EXPORT_SYMBOL(omap_set_lcd_dma_ext_controller);
  78. void omap_set_lcd_dma_single_transfer(int single)
  79. {
  80. lcd_dma.single_transfer = single;
  81. }
  82. EXPORT_SYMBOL(omap_set_lcd_dma_single_transfer);
  83. void omap_set_lcd_dma_b1_rotation(int rotate)
  84. {
  85. if (cpu_is_omap1510()) {
  86. printk(KERN_ERR "DMA rotation is not supported in 1510 mode\n");
  87. BUG();
  88. return;
  89. }
  90. lcd_dma.rotate = rotate;
  91. }
  92. EXPORT_SYMBOL(omap_set_lcd_dma_b1_rotation);
  93. void omap_set_lcd_dma_b1_mirror(int mirror)
  94. {
  95. if (cpu_is_omap1510()) {
  96. printk(KERN_ERR "DMA mirror is not supported in 1510 mode\n");
  97. BUG();
  98. }
  99. lcd_dma.mirror = mirror;
  100. }
  101. EXPORT_SYMBOL(omap_set_lcd_dma_b1_mirror);
  102. void omap_set_lcd_dma_b1_vxres(unsigned long vxres)
  103. {
  104. if (cpu_is_omap1510()) {
  105. printk(KERN_ERR "DMA virtual resulotion is not supported "
  106. "in 1510 mode\n");
  107. BUG();
  108. }
  109. lcd_dma.vxres = vxres;
  110. }
  111. EXPORT_SYMBOL(omap_set_lcd_dma_b1_vxres);
  112. void omap_set_lcd_dma_b1_scale(unsigned int xscale, unsigned int yscale)
  113. {
  114. if (cpu_is_omap1510()) {
  115. printk(KERN_ERR "DMA scale is not supported in 1510 mode\n");
  116. BUG();
  117. }
  118. lcd_dma.xscale = xscale;
  119. lcd_dma.yscale = yscale;
  120. }
  121. EXPORT_SYMBOL(omap_set_lcd_dma_b1_scale);
  122. static void set_b1_regs(void)
  123. {
  124. unsigned long top, bottom;
  125. int es;
  126. u16 w;
  127. unsigned long en, fn;
  128. long ei, fi;
  129. unsigned long vxres;
  130. unsigned int xscale, yscale;
  131. switch (lcd_dma.data_type) {
  132. case OMAP_DMA_DATA_TYPE_S8:
  133. es = 1;
  134. break;
  135. case OMAP_DMA_DATA_TYPE_S16:
  136. es = 2;
  137. break;
  138. case OMAP_DMA_DATA_TYPE_S32:
  139. es = 4;
  140. break;
  141. default:
  142. BUG();
  143. return;
  144. }
  145. vxres = lcd_dma.vxres ? lcd_dma.vxres : lcd_dma.xres;
  146. xscale = lcd_dma.xscale ? lcd_dma.xscale : 1;
  147. yscale = lcd_dma.yscale ? lcd_dma.yscale : 1;
  148. BUG_ON(vxres < lcd_dma.xres);
  149. #define PIXADDR(x, y) (lcd_dma.addr + \
  150. ((y) * vxres * yscale + (x) * xscale) * es)
  151. #define PIXSTEP(sx, sy, dx, dy) (PIXADDR(dx, dy) - PIXADDR(sx, sy) - es + 1)
  152. switch (lcd_dma.rotate) {
  153. case 0:
  154. if (!lcd_dma.mirror) {
  155. top = PIXADDR(0, 0);
  156. bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  157. /* 1510 DMA requires the bottom address to be 2 more
  158. * than the actual last memory access location. */
  159. if (cpu_is_omap1510() &&
  160. lcd_dma.data_type == OMAP_DMA_DATA_TYPE_S32)
  161. bottom += 2;
  162. ei = PIXSTEP(0, 0, 1, 0);
  163. fi = PIXSTEP(lcd_dma.xres - 1, 0, 0, 1);
  164. } else {
  165. top = PIXADDR(lcd_dma.xres - 1, 0);
  166. bottom = PIXADDR(0, lcd_dma.yres - 1);
  167. ei = PIXSTEP(1, 0, 0, 0);
  168. fi = PIXSTEP(0, 0, lcd_dma.xres - 1, 1);
  169. }
  170. en = lcd_dma.xres;
  171. fn = lcd_dma.yres;
  172. break;
  173. case 90:
  174. if (!lcd_dma.mirror) {
  175. top = PIXADDR(0, lcd_dma.yres - 1);
  176. bottom = PIXADDR(lcd_dma.xres - 1, 0);
  177. ei = PIXSTEP(0, 1, 0, 0);
  178. fi = PIXSTEP(0, 0, 1, lcd_dma.yres - 1);
  179. } else {
  180. top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  181. bottom = PIXADDR(0, 0);
  182. ei = PIXSTEP(0, 1, 0, 0);
  183. fi = PIXSTEP(1, 0, 0, lcd_dma.yres - 1);
  184. }
  185. en = lcd_dma.yres;
  186. fn = lcd_dma.xres;
  187. break;
  188. case 180:
  189. if (!lcd_dma.mirror) {
  190. top = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  191. bottom = PIXADDR(0, 0);
  192. ei = PIXSTEP(1, 0, 0, 0);
  193. fi = PIXSTEP(0, 1, lcd_dma.xres - 1, 0);
  194. } else {
  195. top = PIXADDR(0, lcd_dma.yres - 1);
  196. bottom = PIXADDR(lcd_dma.xres - 1, 0);
  197. ei = PIXSTEP(0, 0, 1, 0);
  198. fi = PIXSTEP(lcd_dma.xres - 1, 1, 0, 0);
  199. }
  200. en = lcd_dma.xres;
  201. fn = lcd_dma.yres;
  202. break;
  203. case 270:
  204. if (!lcd_dma.mirror) {
  205. top = PIXADDR(lcd_dma.xres - 1, 0);
  206. bottom = PIXADDR(0, lcd_dma.yres - 1);
  207. ei = PIXSTEP(0, 0, 0, 1);
  208. fi = PIXSTEP(1, lcd_dma.yres - 1, 0, 0);
  209. } else {
  210. top = PIXADDR(0, 0);
  211. bottom = PIXADDR(lcd_dma.xres - 1, lcd_dma.yres - 1);
  212. ei = PIXSTEP(0, 0, 0, 1);
  213. fi = PIXSTEP(0, lcd_dma.yres - 1, 1, 0);
  214. }
  215. en = lcd_dma.yres;
  216. fn = lcd_dma.xres;
  217. break;
  218. default:
  219. BUG();
  220. return; /* Suppress warning about uninitialized vars */
  221. }
  222. if (cpu_is_omap1510()) {
  223. omap_writew(top >> 16, OMAP1510_DMA_LCD_TOP_F1_U);
  224. omap_writew(top, OMAP1510_DMA_LCD_TOP_F1_L);
  225. omap_writew(bottom >> 16, OMAP1510_DMA_LCD_BOT_F1_U);
  226. omap_writew(bottom, OMAP1510_DMA_LCD_BOT_F1_L);
  227. return;
  228. }
  229. /* 1610 regs */
  230. omap_writew(top >> 16, OMAP1610_DMA_LCD_TOP_B1_U);
  231. omap_writew(top, OMAP1610_DMA_LCD_TOP_B1_L);
  232. omap_writew(bottom >> 16, OMAP1610_DMA_LCD_BOT_B1_U);
  233. omap_writew(bottom, OMAP1610_DMA_LCD_BOT_B1_L);
  234. omap_writew(en, OMAP1610_DMA_LCD_SRC_EN_B1);
  235. omap_writew(fn, OMAP1610_DMA_LCD_SRC_FN_B1);
  236. w = omap_readw(OMAP1610_DMA_LCD_CSDP);
  237. w &= ~0x03;
  238. w |= lcd_dma.data_type;
  239. omap_writew(w, OMAP1610_DMA_LCD_CSDP);
  240. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  241. /* Always set the source port as SDRAM for now*/
  242. w &= ~(0x03 << 6);
  243. if (lcd_dma.callback != NULL)
  244. w |= 1 << 1; /* Block interrupt enable */
  245. else
  246. w &= ~(1 << 1);
  247. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  248. if (!(lcd_dma.rotate || lcd_dma.mirror ||
  249. lcd_dma.vxres || lcd_dma.xscale || lcd_dma.yscale))
  250. return;
  251. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  252. /* Set the double-indexed addressing mode */
  253. w |= (0x03 << 12);
  254. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  255. omap_writew(ei, OMAP1610_DMA_LCD_SRC_EI_B1);
  256. omap_writew(fi >> 16, OMAP1610_DMA_LCD_SRC_FI_B1_U);
  257. omap_writew(fi, OMAP1610_DMA_LCD_SRC_FI_B1_L);
  258. }
  259. static irqreturn_t lcd_dma_irq_handler(int irq, void *dev_id)
  260. {
  261. u16 w;
  262. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  263. if (unlikely(!(w & (1 << 3)))) {
  264. printk(KERN_WARNING "Spurious LCD DMA IRQ\n");
  265. return IRQ_NONE;
  266. }
  267. /* Ack the IRQ */
  268. w |= (1 << 3);
  269. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  270. lcd_dma.active = 0;
  271. if (lcd_dma.callback != NULL)
  272. lcd_dma.callback(w, lcd_dma.cb_data);
  273. return IRQ_HANDLED;
  274. }
  275. int omap_request_lcd_dma(void (*callback)(u16 status, void *data),
  276. void *data)
  277. {
  278. spin_lock_irq(&lcd_dma.lock);
  279. if (lcd_dma.reserved) {
  280. spin_unlock_irq(&lcd_dma.lock);
  281. printk(KERN_ERR "LCD DMA channel already reserved\n");
  282. BUG();
  283. return -EBUSY;
  284. }
  285. lcd_dma.reserved = 1;
  286. spin_unlock_irq(&lcd_dma.lock);
  287. lcd_dma.callback = callback;
  288. lcd_dma.cb_data = data;
  289. lcd_dma.active = 0;
  290. lcd_dma.single_transfer = 0;
  291. lcd_dma.rotate = 0;
  292. lcd_dma.vxres = 0;
  293. lcd_dma.mirror = 0;
  294. lcd_dma.xscale = 0;
  295. lcd_dma.yscale = 0;
  296. lcd_dma.ext_ctrl = 0;
  297. lcd_dma.src_port = 0;
  298. return 0;
  299. }
  300. EXPORT_SYMBOL(omap_request_lcd_dma);
  301. void omap_free_lcd_dma(void)
  302. {
  303. spin_lock(&lcd_dma.lock);
  304. if (!lcd_dma.reserved) {
  305. spin_unlock(&lcd_dma.lock);
  306. printk(KERN_ERR "LCD DMA is not reserved\n");
  307. BUG();
  308. return;
  309. }
  310. if (!cpu_is_omap1510())
  311. omap_writew(omap_readw(OMAP1610_DMA_LCD_CCR) & ~1,
  312. OMAP1610_DMA_LCD_CCR);
  313. lcd_dma.reserved = 0;
  314. spin_unlock(&lcd_dma.lock);
  315. }
  316. EXPORT_SYMBOL(omap_free_lcd_dma);
  317. void omap_enable_lcd_dma(void)
  318. {
  319. u16 w;
  320. /*
  321. * Set the Enable bit only if an external controller is
  322. * connected. Otherwise the OMAP internal controller will
  323. * start the transfer when it gets enabled.
  324. */
  325. if (cpu_is_omap1510() || !lcd_dma.ext_ctrl)
  326. return;
  327. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  328. w |= 1 << 8;
  329. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  330. lcd_dma.active = 1;
  331. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  332. w |= 1 << 7;
  333. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  334. }
  335. EXPORT_SYMBOL(omap_enable_lcd_dma);
  336. void omap_setup_lcd_dma(void)
  337. {
  338. BUG_ON(lcd_dma.active);
  339. if (!cpu_is_omap1510()) {
  340. /* Set some reasonable defaults */
  341. omap_writew(0x5440, OMAP1610_DMA_LCD_CCR);
  342. omap_writew(0x9102, OMAP1610_DMA_LCD_CSDP);
  343. omap_writew(0x0004, OMAP1610_DMA_LCD_LCH_CTRL);
  344. }
  345. set_b1_regs();
  346. if (!cpu_is_omap1510()) {
  347. u16 w;
  348. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  349. /*
  350. * If DMA was already active set the end_prog bit to have
  351. * the programmed register set loaded into the active
  352. * register set.
  353. */
  354. w |= 1 << 11; /* End_prog */
  355. if (!lcd_dma.single_transfer)
  356. w |= (3 << 8); /* Auto_init, repeat */
  357. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  358. }
  359. }
  360. EXPORT_SYMBOL(omap_setup_lcd_dma);
  361. void omap_stop_lcd_dma(void)
  362. {
  363. u16 w;
  364. lcd_dma.active = 0;
  365. if (cpu_is_omap1510() || !lcd_dma.ext_ctrl)
  366. return;
  367. w = omap_readw(OMAP1610_DMA_LCD_CCR);
  368. w &= ~(1 << 7);
  369. omap_writew(w, OMAP1610_DMA_LCD_CCR);
  370. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  371. w &= ~(1 << 8);
  372. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  373. }
  374. EXPORT_SYMBOL(omap_stop_lcd_dma);
  375. static int __init omap_init_lcd_dma(void)
  376. {
  377. int r;
  378. if (cpu_is_omap16xx()) {
  379. u16 w;
  380. /* this would prevent OMAP sleep */
  381. w = omap_readw(OMAP1610_DMA_LCD_CTRL);
  382. w &= ~(1 << 8);
  383. omap_writew(w, OMAP1610_DMA_LCD_CTRL);
  384. }
  385. spin_lock_init(&lcd_dma.lock);
  386. r = request_irq(INT_DMA_LCD, lcd_dma_irq_handler, 0,
  387. "LCD DMA", NULL);
  388. if (r != 0)
  389. printk(KERN_ERR "unable to request IRQ for LCD DMA "
  390. "(error %d)\n", r);
  391. return r;
  392. }
  393. arch_initcall(omap_init_lcd_dma);