dma.c 8.9 KB

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