dma.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 struct omap_device_pm_latency omap2_dma_latency[] = {
  80. {
  81. .deactivate_func = omap_device_idle_hwmods,
  82. .activate_func = omap_device_enable_hwmods,
  83. .flags = OMAP_DEVICE_LATENCY_AUTO_ADJUST,
  84. },
  85. };
  86. static void __iomem *dma_base;
  87. static inline void dma_write(u32 val, int reg, int lch)
  88. {
  89. u8 stride;
  90. u32 offset;
  91. stride = (reg >= dma_common_ch_start) ? dma_stride : 0;
  92. offset = reg_map[reg] + (stride * lch);
  93. __raw_writel(val, dma_base + offset);
  94. }
  95. static inline u32 dma_read(int reg, int lch)
  96. {
  97. u8 stride;
  98. u32 offset, val;
  99. stride = (reg >= dma_common_ch_start) ? dma_stride : 0;
  100. offset = reg_map[reg] + (stride * lch);
  101. val = __raw_readl(dma_base + offset);
  102. return val;
  103. }
  104. static inline void omap2_disable_irq_lch(int lch)
  105. {
  106. u32 val;
  107. val = dma_read(IRQENABLE_L0, lch);
  108. val &= ~(1 << lch);
  109. dma_write(val, IRQENABLE_L0, lch);
  110. }
  111. static void omap2_clear_dma(int lch)
  112. {
  113. int i = dma_common_ch_start;
  114. for (; i <= dma_common_ch_end; i += 1)
  115. dma_write(0, i, lch);
  116. }
  117. static void omap2_show_dma_caps(void)
  118. {
  119. u8 revision = dma_read(REVISION, 0) & 0xff;
  120. printk(KERN_INFO "OMAP DMA hardware revision %d.%d\n",
  121. revision >> 4, revision & 0xf);
  122. return;
  123. }
  124. static u32 configure_dma_errata(void)
  125. {
  126. /*
  127. * Errata applicable for OMAP2430ES1.0 and all omap2420
  128. *
  129. * I.
  130. * Erratum ID: Not Available
  131. * Inter Frame DMA buffering issue DMA will wrongly
  132. * buffer elements if packing and bursting is enabled. This might
  133. * result in data gets stalled in FIFO at the end of the block.
  134. * Workaround: DMA channels must have BUFFERING_DISABLED bit set to
  135. * guarantee no data will stay in the DMA FIFO in case inter frame
  136. * buffering occurs
  137. *
  138. * II.
  139. * Erratum ID: Not Available
  140. * DMA may hang when several channels are used in parallel
  141. * In the following configuration, DMA channel hanging can occur:
  142. * a. Channel i, hardware synchronized, is enabled
  143. * b. Another channel (Channel x), software synchronized, is enabled.
  144. * c. Channel i is disabled before end of transfer
  145. * d. Channel i is reenabled.
  146. * e. Steps 1 to 4 are repeated a certain number of times.
  147. * f. A third channel (Channel y), software synchronized, is enabled.
  148. * Channel x and Channel y may hang immediately after step 'f'.
  149. * Workaround:
  150. * For any channel used - make sure NextLCH_ID is set to the value j.
  151. */
  152. if (cpu_is_omap2420() || (cpu_is_omap2430() &&
  153. (omap_type() == OMAP2430_REV_ES1_0))) {
  154. SET_DMA_ERRATA(DMA_ERRATA_IFRAME_BUFFERING);
  155. SET_DMA_ERRATA(DMA_ERRATA_PARALLEL_CHANNELS);
  156. }
  157. /*
  158. * Erratum ID: i378: OMAP2+: sDMA Channel is not disabled
  159. * after a transaction error.
  160. * Workaround: SW should explicitely disable the channel.
  161. */
  162. if (cpu_class_is_omap2())
  163. SET_DMA_ERRATA(DMA_ERRATA_i378);
  164. /*
  165. * Erratum ID: i541: sDMA FIFO draining does not finish
  166. * If sDMA channel is disabled on the fly, sDMA enters standby even
  167. * through FIFO Drain is still in progress
  168. * Workaround: Put sDMA in NoStandby more before a logical channel is
  169. * disabled, then put it back to SmartStandby right after the channel
  170. * finishes FIFO draining.
  171. */
  172. if (cpu_is_omap34xx())
  173. SET_DMA_ERRATA(DMA_ERRATA_i541);
  174. /*
  175. * Erratum ID: i88 : Special programming model needed to disable DMA
  176. * before end of block.
  177. * Workaround: software must ensure that the DMA is configured in No
  178. * Standby mode(DMAx_OCP_SYSCONFIG.MIDLEMODE = "01")
  179. */
  180. if (omap_type() == OMAP3430_REV_ES1_0)
  181. SET_DMA_ERRATA(DMA_ERRATA_i88);
  182. /*
  183. * Erratum 3.2/3.3: sometimes 0 is returned if CSAC/CDAC is
  184. * read before the DMA controller finished disabling the channel.
  185. */
  186. SET_DMA_ERRATA(DMA_ERRATA_3_3);
  187. /*
  188. * Erratum ID: Not Available
  189. * A bug in ROM code leaves IRQ status for channels 0 and 1 uncleared
  190. * after secure sram context save and restore.
  191. * Work around: Hence we need to manually clear those IRQs to avoid
  192. * spurious interrupts. This affects only secure devices.
  193. */
  194. if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
  195. SET_DMA_ERRATA(DMA_ROMCODE_BUG);
  196. return errata;
  197. }
  198. /* One time initializations */
  199. static int __init omap2_system_dma_init_dev(struct omap_hwmod *oh, void *unused)
  200. {
  201. struct omap_device *od;
  202. struct omap_system_dma_plat_info *p;
  203. struct resource *mem;
  204. char *name = "omap_dma_system";
  205. dma_stride = OMAP2_DMA_STRIDE;
  206. dma_common_ch_start = CSDP;
  207. if (cpu_is_omap3630() || cpu_is_omap4430())
  208. dma_common_ch_end = CCDN;
  209. else
  210. dma_common_ch_end = CCFN;
  211. p = kzalloc(sizeof(struct omap_system_dma_plat_info), GFP_KERNEL);
  212. if (!p) {
  213. pr_err("%s: Unable to allocate pdata for %s:%s\n",
  214. __func__, name, oh->name);
  215. return -ENOMEM;
  216. }
  217. p->dma_attr = (struct omap_dma_dev_attr *)oh->dev_attr;
  218. p->disable_irq_lch = omap2_disable_irq_lch;
  219. p->show_dma_caps = omap2_show_dma_caps;
  220. p->clear_dma = omap2_clear_dma;
  221. p->dma_write = dma_write;
  222. p->dma_read = dma_read;
  223. p->clear_lch_regs = NULL;
  224. p->errata = configure_dma_errata();
  225. od = omap_device_build(name, 0, oh, p, sizeof(*p),
  226. omap2_dma_latency, ARRAY_SIZE(omap2_dma_latency), 0);
  227. kfree(p);
  228. if (IS_ERR(od)) {
  229. pr_err("%s: Can't build omap_device for %s:%s.\n",
  230. __func__, name, oh->name);
  231. return PTR_ERR(od);
  232. }
  233. mem = platform_get_resource(&od->pdev, IORESOURCE_MEM, 0);
  234. if (!mem) {
  235. dev_err(&od->pdev.dev, "%s: no mem resource\n", __func__);
  236. return -EINVAL;
  237. }
  238. dma_base = ioremap(mem->start, resource_size(mem));
  239. if (!dma_base) {
  240. dev_err(&od->pdev.dev, "%s: ioremap fail\n", __func__);
  241. return -ENOMEM;
  242. }
  243. d = oh->dev_attr;
  244. d->chan = kzalloc(sizeof(struct omap_dma_lch) *
  245. (d->lch_count), GFP_KERNEL);
  246. if (!d->chan) {
  247. dev_err(&od->pdev.dev, "%s: kzalloc fail\n", __func__);
  248. return -ENOMEM;
  249. }
  250. return 0;
  251. }
  252. static int __init omap2_system_dma_init(void)
  253. {
  254. return omap_hwmod_for_each_by_class("dma",
  255. omap2_system_dma_init_dev, NULL);
  256. }
  257. arch_initcall(omap2_system_dma_init);