lcd_dma.c 11 KB

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