dma.c 8.2 KB

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