dma.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. /*
  2. * OMAP1/OMAP7xx - specific DMA driver
  3. *
  4. * Copyright (C) 2003 - 2008 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/3 support Copyright (C) 2004-2007 Texas Instruments, Inc.
  10. * Some functions based on earlier dma-omap.c Copyright (C) 2001 RidgeRun, Inc.
  11. *
  12. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  13. * Converted DMA library into platform driver
  14. * - G, Manjunath Kondaiah <manjugk@ti.com>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License version 2 as
  18. * published by the Free Software Foundation.
  19. */
  20. #include <linux/err.h>
  21. #include <linux/slab.h>
  22. #include <linux/module.h>
  23. #include <linux/init.h>
  24. #include <linux/device.h>
  25. #include <linux/io.h>
  26. #include <plat/dma.h>
  27. #include <plat/tc.h>
  28. #include <plat/irqs.h>
  29. #define OMAP1_DMA_BASE (0xfffed800)
  30. #define OMAP1_LOGICAL_DMA_CH_COUNT 17
  31. #define OMAP1_DMA_STRIDE 0x40
  32. static u32 errata;
  33. static u32 enable_1510_mode;
  34. static u8 dma_stride;
  35. static enum omap_reg_offsets dma_common_ch_start, dma_common_ch_end;
  36. static u16 reg_map[] = {
  37. [GCR] = 0x400,
  38. [GSCR] = 0x404,
  39. [GRST1] = 0x408,
  40. [HW_ID] = 0x442,
  41. [PCH2_ID] = 0x444,
  42. [PCH0_ID] = 0x446,
  43. [PCH1_ID] = 0x448,
  44. [PCHG_ID] = 0x44a,
  45. [PCHD_ID] = 0x44c,
  46. [CAPS_0] = 0x44e,
  47. [CAPS_1] = 0x452,
  48. [CAPS_2] = 0x456,
  49. [CAPS_3] = 0x458,
  50. [CAPS_4] = 0x45a,
  51. [PCH2_SR] = 0x460,
  52. [PCH0_SR] = 0x480,
  53. [PCH1_SR] = 0x482,
  54. [PCHD_SR] = 0x4c0,
  55. /* Common Registers */
  56. [CSDP] = 0x00,
  57. [CCR] = 0x02,
  58. [CICR] = 0x04,
  59. [CSR] = 0x06,
  60. [CEN] = 0x10,
  61. [CFN] = 0x12,
  62. [CSFI] = 0x14,
  63. [CSEI] = 0x16,
  64. [CPC] = 0x18, /* 15xx only */
  65. [CSAC] = 0x18,
  66. [CDAC] = 0x1a,
  67. [CDEI] = 0x1c,
  68. [CDFI] = 0x1e,
  69. [CLNK_CTRL] = 0x28,
  70. /* Channel specific register offsets */
  71. [CSSA] = 0x08,
  72. [CDSA] = 0x0c,
  73. [COLOR] = 0x20,
  74. [CCR2] = 0x24,
  75. [LCH_CTRL] = 0x2a,
  76. };
  77. static struct resource res[] __initdata = {
  78. [0] = {
  79. .start = OMAP1_DMA_BASE,
  80. .end = OMAP1_DMA_BASE + SZ_2K - 1,
  81. .flags = IORESOURCE_MEM,
  82. },
  83. [1] = {
  84. .name = "0",
  85. .start = INT_DMA_CH0_6,
  86. .flags = IORESOURCE_IRQ,
  87. },
  88. [2] = {
  89. .name = "1",
  90. .start = INT_DMA_CH1_7,
  91. .flags = IORESOURCE_IRQ,
  92. },
  93. [3] = {
  94. .name = "2",
  95. .start = INT_DMA_CH2_8,
  96. .flags = IORESOURCE_IRQ,
  97. },
  98. [4] = {
  99. .name = "3",
  100. .start = INT_DMA_CH3,
  101. .flags = IORESOURCE_IRQ,
  102. },
  103. [5] = {
  104. .name = "4",
  105. .start = INT_DMA_CH4,
  106. .flags = IORESOURCE_IRQ,
  107. },
  108. [6] = {
  109. .name = "5",
  110. .start = INT_DMA_CH5,
  111. .flags = IORESOURCE_IRQ,
  112. },
  113. /* Handled in lcd_dma.c */
  114. [7] = {
  115. .name = "6",
  116. .start = INT_1610_DMA_CH6,
  117. .flags = IORESOURCE_IRQ,
  118. },
  119. /* irq's for omap16xx and omap7xx */
  120. [8] = {
  121. .name = "7",
  122. .start = INT_1610_DMA_CH7,
  123. .flags = IORESOURCE_IRQ,
  124. },
  125. [9] = {
  126. .name = "8",
  127. .start = INT_1610_DMA_CH8,
  128. .flags = IORESOURCE_IRQ,
  129. },
  130. [10] = {
  131. .name = "9",
  132. .start = INT_1610_DMA_CH9,
  133. .flags = IORESOURCE_IRQ,
  134. },
  135. [11] = {
  136. .name = "10",
  137. .start = INT_1610_DMA_CH10,
  138. .flags = IORESOURCE_IRQ,
  139. },
  140. [12] = {
  141. .name = "11",
  142. .start = INT_1610_DMA_CH11,
  143. .flags = IORESOURCE_IRQ,
  144. },
  145. [13] = {
  146. .name = "12",
  147. .start = INT_1610_DMA_CH12,
  148. .flags = IORESOURCE_IRQ,
  149. },
  150. [14] = {
  151. .name = "13",
  152. .start = INT_1610_DMA_CH13,
  153. .flags = IORESOURCE_IRQ,
  154. },
  155. [15] = {
  156. .name = "14",
  157. .start = INT_1610_DMA_CH14,
  158. .flags = IORESOURCE_IRQ,
  159. },
  160. [16] = {
  161. .name = "15",
  162. .start = INT_1610_DMA_CH15,
  163. .flags = IORESOURCE_IRQ,
  164. },
  165. [17] = {
  166. .name = "16",
  167. .start = INT_DMA_LCD,
  168. .flags = IORESOURCE_IRQ,
  169. },
  170. };
  171. static void __iomem *dma_base;
  172. static inline void dma_write(u32 val, int reg, int lch)
  173. {
  174. u8 stride;
  175. u32 offset;
  176. stride = (reg >= dma_common_ch_start) ? dma_stride : 0;
  177. offset = reg_map[reg] + (stride * lch);
  178. __raw_writew(val, dma_base + offset);
  179. if ((reg > CLNK_CTRL && reg < CCEN) ||
  180. (reg > PCHD_ID && reg < CAPS_2)) {
  181. u32 offset2 = reg_map[reg] + 2 + (stride * lch);
  182. __raw_writew(val >> 16, dma_base + offset2);
  183. }
  184. }
  185. static inline u32 dma_read(int reg, int lch)
  186. {
  187. u8 stride;
  188. u32 offset, val;
  189. stride = (reg >= dma_common_ch_start) ? dma_stride : 0;
  190. offset = reg_map[reg] + (stride * lch);
  191. val = __raw_readw(dma_base + offset);
  192. if ((reg > CLNK_CTRL && reg < CCEN) ||
  193. (reg > PCHD_ID && reg < CAPS_2)) {
  194. u16 upper;
  195. u32 offset2 = reg_map[reg] + 2 + (stride * lch);
  196. upper = __raw_readw(dma_base + offset2);
  197. val |= (upper << 16);
  198. }
  199. return val;
  200. }
  201. static void omap1_clear_lch_regs(int lch)
  202. {
  203. int i = dma_common_ch_start;
  204. for (; i <= dma_common_ch_end; i += 1)
  205. dma_write(0, i, lch);
  206. }
  207. static void omap1_clear_dma(int lch)
  208. {
  209. u32 l;
  210. l = dma_read(CCR, lch);
  211. l &= ~OMAP_DMA_CCR_EN;
  212. dma_write(l, CCR, lch);
  213. /* Clear pending interrupts */
  214. l = dma_read(CSR, lch);
  215. }
  216. static void omap1_show_dma_caps(void)
  217. {
  218. if (enable_1510_mode) {
  219. printk(KERN_INFO "DMA support for OMAP15xx initialized\n");
  220. } else {
  221. u16 w;
  222. printk(KERN_INFO "OMAP DMA hardware version %d\n",
  223. dma_read(HW_ID, 0));
  224. printk(KERN_INFO "DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
  225. dma_read(CAPS_0, 0), dma_read(CAPS_1, 0),
  226. dma_read(CAPS_2, 0), dma_read(CAPS_3, 0),
  227. dma_read(CAPS_4, 0));
  228. /* Disable OMAP 3.0/3.1 compatibility mode. */
  229. w = dma_read(GSCR, 0);
  230. w |= 1 << 3;
  231. dma_write(w, GSCR, 0);
  232. }
  233. return;
  234. }
  235. static u32 configure_dma_errata(void)
  236. {
  237. /*
  238. * Erratum 3.2/3.3: sometimes 0 is returned if CSAC/CDAC is
  239. * read before the DMA controller finished disabling the channel.
  240. */
  241. if (!cpu_is_omap15xx())
  242. SET_DMA_ERRATA(DMA_ERRATA_3_3);
  243. return errata;
  244. }
  245. static int __init omap1_system_dma_init(void)
  246. {
  247. struct omap_system_dma_plat_info *p;
  248. struct omap_dma_dev_attr *d;
  249. struct platform_device *pdev;
  250. int ret;
  251. pdev = platform_device_alloc("omap_dma_system", 0);
  252. if (!pdev) {
  253. pr_err("%s: Unable to device alloc for dma\n",
  254. __func__);
  255. return -ENOMEM;
  256. }
  257. dma_base = ioremap(res[0].start, resource_size(&res[0]));
  258. if (!dma_base) {
  259. pr_err("%s: Unable to ioremap\n", __func__);
  260. ret = -ENODEV;
  261. goto exit_device_put;
  262. }
  263. ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
  264. if (ret) {
  265. dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
  266. __func__, pdev->name, pdev->id);
  267. goto exit_device_put;
  268. }
  269. p = kzalloc(sizeof(struct omap_system_dma_plat_info), GFP_KERNEL);
  270. if (!p) {
  271. dev_err(&pdev->dev, "%s: Unable to allocate 'p' for %s\n",
  272. __func__, pdev->name);
  273. ret = -ENOMEM;
  274. goto exit_device_del;
  275. }
  276. d = kzalloc(sizeof(struct omap_dma_dev_attr), GFP_KERNEL);
  277. if (!d) {
  278. dev_err(&pdev->dev, "%s: Unable to allocate 'd' for %s\n",
  279. __func__, pdev->name);
  280. ret = -ENOMEM;
  281. goto exit_release_p;
  282. }
  283. d->lch_count = OMAP1_LOGICAL_DMA_CH_COUNT;
  284. /* Valid attributes for omap1 plus processors */
  285. if (cpu_is_omap15xx())
  286. d->dev_caps = ENABLE_1510_MODE;
  287. enable_1510_mode = d->dev_caps & ENABLE_1510_MODE;
  288. d->dev_caps |= SRC_PORT;
  289. d->dev_caps |= DST_PORT;
  290. d->dev_caps |= SRC_INDEX;
  291. d->dev_caps |= DST_INDEX;
  292. d->dev_caps |= IS_BURST_ONLY4;
  293. d->dev_caps |= CLEAR_CSR_ON_READ;
  294. d->dev_caps |= IS_WORD_16;
  295. d->chan = kzalloc(sizeof(struct omap_dma_lch) *
  296. (d->lch_count), GFP_KERNEL);
  297. if (!d->chan) {
  298. dev_err(&pdev->dev, "%s: Memory allocation failed"
  299. "for d->chan!!!\n", __func__);
  300. goto exit_release_d;
  301. }
  302. if (cpu_is_omap15xx())
  303. d->chan_count = 9;
  304. else if (cpu_is_omap16xx() || cpu_is_omap7xx()) {
  305. if (!(d->dev_caps & ENABLE_1510_MODE))
  306. d->chan_count = 16;
  307. else
  308. d->chan_count = 9;
  309. }
  310. p->dma_attr = d;
  311. p->show_dma_caps = omap1_show_dma_caps;
  312. p->clear_lch_regs = omap1_clear_lch_regs;
  313. p->clear_dma = omap1_clear_dma;
  314. p->dma_write = dma_write;
  315. p->dma_read = dma_read;
  316. p->disable_irq_lch = NULL;
  317. p->errata = configure_dma_errata();
  318. ret = platform_device_add_data(pdev, p, sizeof(*p));
  319. if (ret) {
  320. dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
  321. __func__, pdev->name, pdev->id);
  322. goto exit_release_chan;
  323. }
  324. ret = platform_device_add(pdev);
  325. if (ret) {
  326. dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
  327. __func__, pdev->name, pdev->id);
  328. goto exit_release_chan;
  329. }
  330. dma_stride = OMAP1_DMA_STRIDE;
  331. dma_common_ch_start = CPC;
  332. dma_common_ch_end = COLOR;
  333. return ret;
  334. exit_release_chan:
  335. kfree(d->chan);
  336. exit_release_d:
  337. kfree(d);
  338. exit_release_p:
  339. kfree(p);
  340. exit_device_del:
  341. platform_device_del(pdev);
  342. exit_device_put:
  343. platform_device_put(pdev);
  344. return ret;
  345. }
  346. arch_initcall(omap1_system_dma_init);