dma.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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/omap-dma.h>
  31. #include "soc.h"
  32. #include "omap_hwmod.h"
  33. #include "omap_device.h"
  34. #define OMAP2_DMA_STRIDE 0x60
  35. static u32 errata;
  36. static u8 dma_stride;
  37. static struct omap_dma_dev_attr *d;
  38. static enum omap_reg_offsets dma_common_ch_start, dma_common_ch_end;
  39. static u16 reg_map[] = {
  40. [REVISION] = 0x00,
  41. [GCR] = 0x78,
  42. [IRQSTATUS_L0] = 0x08,
  43. [IRQSTATUS_L1] = 0x0c,
  44. [IRQSTATUS_L2] = 0x10,
  45. [IRQSTATUS_L3] = 0x14,
  46. [IRQENABLE_L0] = 0x18,
  47. [IRQENABLE_L1] = 0x1c,
  48. [IRQENABLE_L2] = 0x20,
  49. [IRQENABLE_L3] = 0x24,
  50. [SYSSTATUS] = 0x28,
  51. [OCP_SYSCONFIG] = 0x2c,
  52. [CAPS_0] = 0x64,
  53. [CAPS_2] = 0x6c,
  54. [CAPS_3] = 0x70,
  55. [CAPS_4] = 0x74,
  56. /* Common register offsets */
  57. [CCR] = 0x80,
  58. [CLNK_CTRL] = 0x84,
  59. [CICR] = 0x88,
  60. [CSR] = 0x8c,
  61. [CSDP] = 0x90,
  62. [CEN] = 0x94,
  63. [CFN] = 0x98,
  64. [CSEI] = 0xa4,
  65. [CSFI] = 0xa8,
  66. [CDEI] = 0xac,
  67. [CDFI] = 0xb0,
  68. [CSAC] = 0xb4,
  69. [CDAC] = 0xb8,
  70. /* Channel specific register offsets */
  71. [CSSA] = 0x9c,
  72. [CDSA] = 0xa0,
  73. [CCEN] = 0xbc,
  74. [CCFN] = 0xc0,
  75. [COLOR] = 0xc4,
  76. /* OMAP4 specific registers */
  77. [CDP] = 0xd0,
  78. [CNDP] = 0xd4,
  79. [CCDN] = 0xd8,
  80. };
  81. static void __iomem *dma_base;
  82. static inline void dma_write(u32 val, int reg, int lch)
  83. {
  84. u8 stride;
  85. u32 offset;
  86. stride = (reg >= dma_common_ch_start) ? dma_stride : 0;
  87. offset = reg_map[reg] + (stride * lch);
  88. __raw_writel(val, dma_base + offset);
  89. }
  90. static inline u32 dma_read(int reg, int lch)
  91. {
  92. u8 stride;
  93. u32 offset, val;
  94. stride = (reg >= dma_common_ch_start) ? dma_stride : 0;
  95. offset = reg_map[reg] + (stride * lch);
  96. val = __raw_readl(dma_base + offset);
  97. return val;
  98. }
  99. static inline void omap2_disable_irq_lch(int lch)
  100. {
  101. u32 val;
  102. val = dma_read(IRQENABLE_L0, lch);
  103. val &= ~(1 << lch);
  104. dma_write(val, IRQENABLE_L0, lch);
  105. }
  106. static void omap2_clear_dma(int lch)
  107. {
  108. int i = dma_common_ch_start;
  109. for (; i <= dma_common_ch_end; i += 1)
  110. dma_write(0, i, lch);
  111. }
  112. static void omap2_show_dma_caps(void)
  113. {
  114. u8 revision = dma_read(REVISION, 0) & 0xff;
  115. printk(KERN_INFO "OMAP DMA hardware revision %d.%d\n",
  116. revision >> 4, revision & 0xf);
  117. return;
  118. }
  119. static u32 configure_dma_errata(void)
  120. {
  121. /*
  122. * Errata applicable for OMAP2430ES1.0 and all omap2420
  123. *
  124. * I.
  125. * Erratum ID: Not Available
  126. * Inter Frame DMA buffering issue DMA will wrongly
  127. * buffer elements if packing and bursting is enabled. This might
  128. * result in data gets stalled in FIFO at the end of the block.
  129. * Workaround: DMA channels must have BUFFERING_DISABLED bit set to
  130. * guarantee no data will stay in the DMA FIFO in case inter frame
  131. * buffering occurs
  132. *
  133. * II.
  134. * Erratum ID: Not Available
  135. * DMA may hang when several channels are used in parallel
  136. * In the following configuration, DMA channel hanging can occur:
  137. * a. Channel i, hardware synchronized, is enabled
  138. * b. Another channel (Channel x), software synchronized, is enabled.
  139. * c. Channel i is disabled before end of transfer
  140. * d. Channel i is reenabled.
  141. * e. Steps 1 to 4 are repeated a certain number of times.
  142. * f. A third channel (Channel y), software synchronized, is enabled.
  143. * Channel x and Channel y may hang immediately after step 'f'.
  144. * Workaround:
  145. * For any channel used - make sure NextLCH_ID is set to the value j.
  146. */
  147. if (cpu_is_omap2420() || (cpu_is_omap2430() &&
  148. (omap_type() == OMAP2430_REV_ES1_0))) {
  149. SET_DMA_ERRATA(DMA_ERRATA_IFRAME_BUFFERING);
  150. SET_DMA_ERRATA(DMA_ERRATA_PARALLEL_CHANNELS);
  151. }
  152. /*
  153. * Erratum ID: i378: OMAP2+: sDMA Channel is not disabled
  154. * after a transaction error.
  155. * Workaround: SW should explicitely disable the channel.
  156. */
  157. if (cpu_class_is_omap2())
  158. SET_DMA_ERRATA(DMA_ERRATA_i378);
  159. /*
  160. * Erratum ID: i541: sDMA FIFO draining does not finish
  161. * If sDMA channel is disabled on the fly, sDMA enters standby even
  162. * through FIFO Drain is still in progress
  163. * Workaround: Put sDMA in NoStandby more before a logical channel is
  164. * disabled, then put it back to SmartStandby right after the channel
  165. * finishes FIFO draining.
  166. */
  167. if (cpu_is_omap34xx())
  168. SET_DMA_ERRATA(DMA_ERRATA_i541);
  169. /*
  170. * Erratum ID: i88 : Special programming model needed to disable DMA
  171. * before end of block.
  172. * Workaround: software must ensure that the DMA is configured in No
  173. * Standby mode(DMAx_OCP_SYSCONFIG.MIDLEMODE = "01")
  174. */
  175. if (omap_type() == OMAP3430_REV_ES1_0)
  176. SET_DMA_ERRATA(DMA_ERRATA_i88);
  177. /*
  178. * Erratum 3.2/3.3: sometimes 0 is returned if CSAC/CDAC is
  179. * read before the DMA controller finished disabling the channel.
  180. */
  181. SET_DMA_ERRATA(DMA_ERRATA_3_3);
  182. /*
  183. * Erratum ID: Not Available
  184. * A bug in ROM code leaves IRQ status for channels 0 and 1 uncleared
  185. * after secure sram context save and restore.
  186. * Work around: Hence we need to manually clear those IRQs to avoid
  187. * spurious interrupts. This affects only secure devices.
  188. */
  189. if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
  190. SET_DMA_ERRATA(DMA_ROMCODE_BUG);
  191. return errata;
  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 resource *mem;
  199. char *name = "omap_dma_system";
  200. dma_stride = OMAP2_DMA_STRIDE;
  201. dma_common_ch_start = CSDP;
  202. p = kzalloc(sizeof(struct omap_system_dma_plat_info), GFP_KERNEL);
  203. if (!p) {
  204. pr_err("%s: Unable to allocate pdata for %s:%s\n",
  205. __func__, name, oh->name);
  206. return -ENOMEM;
  207. }
  208. p->dma_attr = (struct omap_dma_dev_attr *)oh->dev_attr;
  209. p->disable_irq_lch = omap2_disable_irq_lch;
  210. p->show_dma_caps = omap2_show_dma_caps;
  211. p->clear_dma = omap2_clear_dma;
  212. p->dma_write = dma_write;
  213. p->dma_read = dma_read;
  214. p->clear_lch_regs = NULL;
  215. p->errata = configure_dma_errata();
  216. pdev = omap_device_build(name, 0, oh, p, sizeof(*p));
  217. kfree(p);
  218. if (IS_ERR(pdev)) {
  219. pr_err("%s: Can't build omap_device for %s:%s.\n",
  220. __func__, name, oh->name);
  221. return PTR_ERR(pdev);
  222. }
  223. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  224. if (!mem) {
  225. dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
  226. return -EINVAL;
  227. }
  228. dma_base = ioremap(mem->start, resource_size(mem));
  229. if (!dma_base) {
  230. dev_err(&pdev->dev, "%s: ioremap fail\n", __func__);
  231. return -ENOMEM;
  232. }
  233. d = oh->dev_attr;
  234. d->chan = kzalloc(sizeof(struct omap_dma_lch) *
  235. (d->lch_count), GFP_KERNEL);
  236. if (!d->chan) {
  237. dev_err(&pdev->dev, "%s: kzalloc fail\n", __func__);
  238. return -ENOMEM;
  239. }
  240. if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
  241. d->dev_caps |= HS_CHANNELS_RESERVED;
  242. /* Check the capabilities register for descriptor loading feature */
  243. if (dma_read(CAPS_0, 0) & DMA_HAS_DESCRIPTOR_CAPS)
  244. dma_common_ch_end = CCDN;
  245. else
  246. dma_common_ch_end = CCFN;
  247. return 0;
  248. }
  249. static const struct platform_device_info omap_dma_dev_info = {
  250. .name = "omap-dma-engine",
  251. .id = -1,
  252. .dma_mask = DMA_BIT_MASK(32),
  253. };
  254. static int __init omap2_system_dma_init(void)
  255. {
  256. struct platform_device *pdev;
  257. int res;
  258. res = omap_hwmod_for_each_by_class("dma",
  259. omap2_system_dma_init_dev, NULL);
  260. if (res)
  261. return res;
  262. pdev = platform_device_register_full(&omap_dma_dev_info);
  263. if (IS_ERR(pdev))
  264. return PTR_ERR(pdev);
  265. return res;
  266. }
  267. omap_arch_initcall(omap2_system_dma_init);