dma.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. return;
  105. }
  106. static unsigned configure_dma_errata(void)
  107. {
  108. unsigned errata = 0;
  109. /*
  110. * Errata applicable for OMAP2430ES1.0 and all omap2420
  111. *
  112. * I.
  113. * Erratum ID: Not Available
  114. * Inter Frame DMA buffering issue DMA will wrongly
  115. * buffer elements if packing and bursting is enabled. This might
  116. * result in data gets stalled in FIFO at the end of the block.
  117. * Workaround: DMA channels must have BUFFERING_DISABLED bit set to
  118. * guarantee no data will stay in the DMA FIFO in case inter frame
  119. * buffering occurs
  120. *
  121. * II.
  122. * Erratum ID: Not Available
  123. * DMA may hang when several channels are used in parallel
  124. * In the following configuration, DMA channel hanging can occur:
  125. * a. Channel i, hardware synchronized, is enabled
  126. * b. Another channel (Channel x), software synchronized, is enabled.
  127. * c. Channel i is disabled before end of transfer
  128. * d. Channel i is reenabled.
  129. * e. Steps 1 to 4 are repeated a certain number of times.
  130. * f. A third channel (Channel y), software synchronized, is enabled.
  131. * Channel x and Channel y may hang immediately after step 'f'.
  132. * Workaround:
  133. * For any channel used - make sure NextLCH_ID is set to the value j.
  134. */
  135. if (cpu_is_omap2420() || (cpu_is_omap2430() &&
  136. (omap_type() == OMAP2430_REV_ES1_0))) {
  137. SET_DMA_ERRATA(DMA_ERRATA_IFRAME_BUFFERING);
  138. SET_DMA_ERRATA(DMA_ERRATA_PARALLEL_CHANNELS);
  139. }
  140. /*
  141. * Erratum ID: i378: OMAP2+: sDMA Channel is not disabled
  142. * after a transaction error.
  143. * Workaround: SW should explicitely disable the channel.
  144. */
  145. if (cpu_class_is_omap2())
  146. SET_DMA_ERRATA(DMA_ERRATA_i378);
  147. /*
  148. * Erratum ID: i541: sDMA FIFO draining does not finish
  149. * If sDMA channel is disabled on the fly, sDMA enters standby even
  150. * through FIFO Drain is still in progress
  151. * Workaround: Put sDMA in NoStandby more before a logical channel is
  152. * disabled, then put it back to SmartStandby right after the channel
  153. * finishes FIFO draining.
  154. */
  155. if (cpu_is_omap34xx())
  156. SET_DMA_ERRATA(DMA_ERRATA_i541);
  157. /*
  158. * Erratum ID: i88 : Special programming model needed to disable DMA
  159. * before end of block.
  160. * Workaround: software must ensure that the DMA is configured in No
  161. * Standby mode(DMAx_OCP_SYSCONFIG.MIDLEMODE = "01")
  162. */
  163. if (omap_type() == OMAP3430_REV_ES1_0)
  164. SET_DMA_ERRATA(DMA_ERRATA_i88);
  165. /*
  166. * Erratum 3.2/3.3: sometimes 0 is returned if CSAC/CDAC is
  167. * read before the DMA controller finished disabling the channel.
  168. */
  169. SET_DMA_ERRATA(DMA_ERRATA_3_3);
  170. /*
  171. * Erratum ID: Not Available
  172. * A bug in ROM code leaves IRQ status for channels 0 and 1 uncleared
  173. * after secure sram context save and restore.
  174. * Work around: Hence we need to manually clear those IRQs to avoid
  175. * spurious interrupts. This affects only secure devices.
  176. */
  177. if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
  178. SET_DMA_ERRATA(DMA_ROMCODE_BUG);
  179. return errata;
  180. }
  181. static struct omap_system_dma_plat_info dma_plat_info __initdata = {
  182. .reg_map = reg_map,
  183. .channel_stride = 0x60,
  184. .show_dma_caps = omap2_show_dma_caps,
  185. .clear_dma = omap2_clear_dma,
  186. .dma_write = dma_write,
  187. .dma_read = dma_read,
  188. };
  189. static struct platform_device_info omap_dma_dev_info = {
  190. .name = "omap-dma-engine",
  191. .id = -1,
  192. .dma_mask = DMA_BIT_MASK(32),
  193. };
  194. /* One time initializations */
  195. static int __init omap2_system_dma_init_dev(struct omap_hwmod *oh, void *unused)
  196. {
  197. struct platform_device *pdev;
  198. struct omap_system_dma_plat_info p;
  199. struct omap_dma_dev_attr *d;
  200. struct resource *mem;
  201. char *name = "omap_dma_system";
  202. p = dma_plat_info;
  203. p.dma_attr = (struct omap_dma_dev_attr *)oh->dev_attr;
  204. p.errata = configure_dma_errata();
  205. pdev = omap_device_build(name, 0, oh, &p, sizeof(p));
  206. if (IS_ERR(pdev)) {
  207. pr_err("%s: Can't build omap_device for %s:%s.\n",
  208. __func__, name, oh->name);
  209. return PTR_ERR(pdev);
  210. }
  211. omap_dma_dev_info.res = pdev->resource;
  212. omap_dma_dev_info.num_res = pdev->num_resources;
  213. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  214. if (!mem) {
  215. dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
  216. return -EINVAL;
  217. }
  218. dma_base = ioremap(mem->start, resource_size(mem));
  219. if (!dma_base) {
  220. dev_err(&pdev->dev, "%s: ioremap fail\n", __func__);
  221. return -ENOMEM;
  222. }
  223. d = oh->dev_attr;
  224. if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
  225. d->dev_caps |= HS_CHANNELS_RESERVED;
  226. if (platform_get_irq_byname(pdev, "0") < 0)
  227. d->dev_caps |= DMA_ENGINE_HANDLE_IRQ;
  228. /* Check the capabilities register for descriptor loading feature */
  229. if (dma_read(CAPS_0, 0) & DMA_HAS_DESCRIPTOR_CAPS)
  230. dma_common_ch_end = CCDN;
  231. else
  232. dma_common_ch_end = CCFN;
  233. return 0;
  234. }
  235. static int __init omap2_system_dma_init(void)
  236. {
  237. struct platform_device *pdev;
  238. int res;
  239. res = omap_hwmod_for_each_by_class("dma",
  240. omap2_system_dma_init_dev, NULL);
  241. if (res)
  242. return res;
  243. if (of_have_populated_dt())
  244. return res;
  245. pdev = platform_device_register_full(&omap_dma_dev_info);
  246. if (IS_ERR(pdev))
  247. return PTR_ERR(pdev);
  248. return res;
  249. }
  250. omap_arch_initcall(omap2_system_dma_init);