dma.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /*
  2. * OMAP2+ 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) 2009 Texas Instruments
  13. * Added OMAP4 support - Santosh Shilimkar <santosh.shilimkar@ti.com>
  14. *
  15. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  16. * Converted DMA library into platform driver
  17. * - G, Manjunath Kondaiah <manjugk@ti.com>
  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. #include <linux/err.h>
  24. #include <linux/io.h>
  25. #include <linux/slab.h>
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/device.h>
  29. #include <linux/dma-mapping.h>
  30. #include <linux/of.h>
  31. #include <linux/omap-dma.h>
  32. #include "soc.h"
  33. #include "omap_hwmod.h"
  34. #include "omap_device.h"
  35. static enum omap_reg_offsets dma_common_ch_end;
  36. static const struct omap_dma_reg reg_map[] = {
  37. [REVISION] = { 0x0000, 0x00, OMAP_DMA_REG_32BIT },
  38. [GCR] = { 0x0078, 0x00, OMAP_DMA_REG_32BIT },
  39. [IRQSTATUS_L0] = { 0x0008, 0x00, OMAP_DMA_REG_32BIT },
  40. [IRQSTATUS_L1] = { 0x000c, 0x00, OMAP_DMA_REG_32BIT },
  41. [IRQSTATUS_L2] = { 0x0010, 0x00, OMAP_DMA_REG_32BIT },
  42. [IRQSTATUS_L3] = { 0x0014, 0x00, OMAP_DMA_REG_32BIT },
  43. [IRQENABLE_L0] = { 0x0018, 0x00, OMAP_DMA_REG_32BIT },
  44. [IRQENABLE_L1] = { 0x001c, 0x00, OMAP_DMA_REG_32BIT },
  45. [IRQENABLE_L2] = { 0x0020, 0x00, OMAP_DMA_REG_32BIT },
  46. [IRQENABLE_L3] = { 0x0024, 0x00, OMAP_DMA_REG_32BIT },
  47. [SYSSTATUS] = { 0x0028, 0x00, OMAP_DMA_REG_32BIT },
  48. [OCP_SYSCONFIG] = { 0x002c, 0x00, OMAP_DMA_REG_32BIT },
  49. [CAPS_0] = { 0x0064, 0x00, OMAP_DMA_REG_32BIT },
  50. [CAPS_2] = { 0x006c, 0x00, OMAP_DMA_REG_32BIT },
  51. [CAPS_3] = { 0x0070, 0x00, OMAP_DMA_REG_32BIT },
  52. [CAPS_4] = { 0x0074, 0x00, OMAP_DMA_REG_32BIT },
  53. /* Common register offsets */
  54. [CCR] = { 0x0080, 0x60, OMAP_DMA_REG_32BIT },
  55. [CLNK_CTRL] = { 0x0084, 0x60, OMAP_DMA_REG_32BIT },
  56. [CICR] = { 0x0088, 0x60, OMAP_DMA_REG_32BIT },
  57. [CSR] = { 0x008c, 0x60, OMAP_DMA_REG_32BIT },
  58. [CSDP] = { 0x0090, 0x60, OMAP_DMA_REG_32BIT },
  59. [CEN] = { 0x0094, 0x60, OMAP_DMA_REG_32BIT },
  60. [CFN] = { 0x0098, 0x60, OMAP_DMA_REG_32BIT },
  61. [CSEI] = { 0x00a4, 0x60, OMAP_DMA_REG_32BIT },
  62. [CSFI] = { 0x00a8, 0x60, OMAP_DMA_REG_32BIT },
  63. [CDEI] = { 0x00ac, 0x60, OMAP_DMA_REG_32BIT },
  64. [CDFI] = { 0x00b0, 0x60, OMAP_DMA_REG_32BIT },
  65. [CSAC] = { 0x00b4, 0x60, OMAP_DMA_REG_32BIT },
  66. [CDAC] = { 0x00b8, 0x60, OMAP_DMA_REG_32BIT },
  67. /* Channel specific register offsets */
  68. [CSSA] = { 0x009c, 0x60, OMAP_DMA_REG_32BIT },
  69. [CDSA] = { 0x00a0, 0x60, OMAP_DMA_REG_32BIT },
  70. [CCEN] = { 0x00bc, 0x60, OMAP_DMA_REG_32BIT },
  71. [CCFN] = { 0x00c0, 0x60, OMAP_DMA_REG_32BIT },
  72. [COLOR] = { 0x00c4, 0x60, OMAP_DMA_REG_32BIT },
  73. /* OMAP4 specific registers */
  74. [CDP] = { 0x00d0, 0x60, OMAP_DMA_REG_32BIT },
  75. [CNDP] = { 0x00d4, 0x60, OMAP_DMA_REG_32BIT },
  76. [CCDN] = { 0x00d8, 0x60, OMAP_DMA_REG_32BIT },
  77. };
  78. static void __iomem *dma_base;
  79. static inline void dma_write(u32 val, int reg, int lch)
  80. {
  81. void __iomem *addr = dma_base;
  82. addr += reg_map[reg].offset;
  83. addr += reg_map[reg].stride * lch;
  84. writel_relaxed(val, addr);
  85. }
  86. static inline u32 dma_read(int reg, int lch)
  87. {
  88. void __iomem *addr = dma_base;
  89. addr += reg_map[reg].offset;
  90. addr += reg_map[reg].stride * lch;
  91. return readl_relaxed(addr);
  92. }
  93. static void omap2_clear_dma(int lch)
  94. {
  95. int i;
  96. for (i = CSDP; i <= dma_common_ch_end; i += 1)
  97. dma_write(0, i, lch);
  98. }
  99. static void omap2_show_dma_caps(void)
  100. {
  101. u8 revision = dma_read(REVISION, 0) & 0xff;
  102. printk(KERN_INFO "OMAP DMA hardware revision %d.%d\n",
  103. revision >> 4, revision & 0xf);
  104. }
  105. static unsigned configure_dma_errata(void)
  106. {
  107. unsigned errata = 0;
  108. /*
  109. * Errata applicable for OMAP2430ES1.0 and all omap2420
  110. *
  111. * I.
  112. * Erratum ID: Not Available
  113. * Inter Frame DMA buffering issue DMA will wrongly
  114. * buffer elements if packing and bursting is enabled. This might
  115. * result in data gets stalled in FIFO at the end of the block.
  116. * Workaround: DMA channels must have BUFFERING_DISABLED bit set to
  117. * guarantee no data will stay in the DMA FIFO in case inter frame
  118. * buffering occurs
  119. *
  120. * II.
  121. * Erratum ID: Not Available
  122. * DMA may hang when several channels are used in parallel
  123. * In the following configuration, DMA channel hanging can occur:
  124. * a. Channel i, hardware synchronized, is enabled
  125. * b. Another channel (Channel x), software synchronized, is enabled.
  126. * c. Channel i is disabled before end of transfer
  127. * d. Channel i is reenabled.
  128. * e. Steps 1 to 4 are repeated a certain number of times.
  129. * f. A third channel (Channel y), software synchronized, is enabled.
  130. * Channel x and Channel y may hang immediately after step 'f'.
  131. * Workaround:
  132. * For any channel used - make sure NextLCH_ID is set to the value j.
  133. */
  134. if (cpu_is_omap2420() || (cpu_is_omap2430() &&
  135. (omap_type() == OMAP2430_REV_ES1_0))) {
  136. SET_DMA_ERRATA(DMA_ERRATA_IFRAME_BUFFERING);
  137. SET_DMA_ERRATA(DMA_ERRATA_PARALLEL_CHANNELS);
  138. }
  139. /*
  140. * Erratum ID: i378: OMAP2+: sDMA Channel is not disabled
  141. * after a transaction error.
  142. * Workaround: SW should explicitely disable the channel.
  143. */
  144. if (cpu_class_is_omap2())
  145. SET_DMA_ERRATA(DMA_ERRATA_i378);
  146. /*
  147. * Erratum ID: i541: sDMA FIFO draining does not finish
  148. * If sDMA channel is disabled on the fly, sDMA enters standby even
  149. * through FIFO Drain is still in progress
  150. * Workaround: Put sDMA in NoStandby more before a logical channel is
  151. * disabled, then put it back to SmartStandby right after the channel
  152. * finishes FIFO draining.
  153. */
  154. if (cpu_is_omap34xx())
  155. SET_DMA_ERRATA(DMA_ERRATA_i541);
  156. /*
  157. * Erratum ID: i88 : Special programming model needed to disable DMA
  158. * before end of block.
  159. * Workaround: software must ensure that the DMA is configured in No
  160. * Standby mode(DMAx_OCP_SYSCONFIG.MIDLEMODE = "01")
  161. */
  162. if (omap_type() == OMAP3430_REV_ES1_0)
  163. SET_DMA_ERRATA(DMA_ERRATA_i88);
  164. /*
  165. * Erratum 3.2/3.3: sometimes 0 is returned if CSAC/CDAC is
  166. * read before the DMA controller finished disabling the channel.
  167. */
  168. SET_DMA_ERRATA(DMA_ERRATA_3_3);
  169. /*
  170. * Erratum ID: Not Available
  171. * A bug in ROM code leaves IRQ status for channels 0 and 1 uncleared
  172. * after secure sram context save and restore.
  173. * Work around: Hence we need to manually clear those IRQs to avoid
  174. * spurious interrupts. This affects only secure devices.
  175. */
  176. if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
  177. SET_DMA_ERRATA(DMA_ROMCODE_BUG);
  178. return errata;
  179. }
  180. static struct omap_system_dma_plat_info dma_plat_info __initdata = {
  181. .reg_map = reg_map,
  182. .channel_stride = 0x60,
  183. .show_dma_caps = omap2_show_dma_caps,
  184. .clear_dma = omap2_clear_dma,
  185. .dma_write = dma_write,
  186. .dma_read = dma_read,
  187. };
  188. static struct platform_device_info omap_dma_dev_info = {
  189. .name = "omap-dma-engine",
  190. .id = -1,
  191. .dma_mask = DMA_BIT_MASK(32),
  192. };
  193. /* One time initializations */
  194. static int __init omap2_system_dma_init_dev(struct omap_hwmod *oh, void *unused)
  195. {
  196. struct platform_device *pdev;
  197. struct omap_system_dma_plat_info p;
  198. struct omap_dma_dev_attr *d;
  199. struct resource *mem;
  200. char *name = "omap_dma_system";
  201. p = dma_plat_info;
  202. p.dma_attr = (struct omap_dma_dev_attr *)oh->dev_attr;
  203. p.errata = configure_dma_errata();
  204. pdev = omap_device_build(name, 0, oh, &p, sizeof(p));
  205. if (IS_ERR(pdev)) {
  206. pr_err("%s: Can't build omap_device for %s:%s.\n",
  207. __func__, name, oh->name);
  208. return PTR_ERR(pdev);
  209. }
  210. omap_dma_dev_info.res = pdev->resource;
  211. omap_dma_dev_info.num_res = pdev->num_resources;
  212. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  213. if (!mem) {
  214. dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
  215. return -EINVAL;
  216. }
  217. dma_base = ioremap(mem->start, resource_size(mem));
  218. if (!dma_base) {
  219. dev_err(&pdev->dev, "%s: ioremap fail\n", __func__);
  220. return -ENOMEM;
  221. }
  222. d = oh->dev_attr;
  223. if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
  224. d->dev_caps |= HS_CHANNELS_RESERVED;
  225. if (platform_get_irq_byname(pdev, "0") < 0)
  226. d->dev_caps |= DMA_ENGINE_HANDLE_IRQ;
  227. /* Check the capabilities register for descriptor loading feature */
  228. if (dma_read(CAPS_0, 0) & DMA_HAS_DESCRIPTOR_CAPS)
  229. dma_common_ch_end = CCDN;
  230. else
  231. dma_common_ch_end = CCFN;
  232. return 0;
  233. }
  234. static int __init omap2_system_dma_init(void)
  235. {
  236. struct platform_device *pdev;
  237. int res;
  238. res = omap_hwmod_for_each_by_class("dma",
  239. omap2_system_dma_init_dev, NULL);
  240. if (res)
  241. return res;
  242. if (of_have_populated_dt())
  243. return res;
  244. pdev = platform_device_register_full(&omap_dma_dev_info);
  245. if (IS_ERR(pdev))
  246. return PTR_ERR(pdev);
  247. return res;
  248. }
  249. omap_arch_initcall(omap2_system_dma_init);