dma.c 7.8 KB

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