lcd_dma.c 11 KB

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