dma.c 8.5 KB

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