dma.c 7.7 KB

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