dma.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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/dmaengine.h>
  31. #include <linux/of.h>
  32. #include <linux/omap-dma.h>
  33. #include "soc.h"
  34. #include "omap_hwmod.h"
  35. #include "omap_device.h"
  36. static enum omap_reg_offsets dma_common_ch_end;
  37. static const struct omap_dma_reg reg_map[] = {
  38. [REVISION] = { 0x0000, 0x00, OMAP_DMA_REG_32BIT },
  39. [GCR] = { 0x0078, 0x00, OMAP_DMA_REG_32BIT },
  40. [IRQSTATUS_L0] = { 0x0008, 0x00, OMAP_DMA_REG_32BIT },
  41. [IRQSTATUS_L1] = { 0x000c, 0x00, OMAP_DMA_REG_32BIT },
  42. [IRQSTATUS_L2] = { 0x0010, 0x00, OMAP_DMA_REG_32BIT },
  43. [IRQSTATUS_L3] = { 0x0014, 0x00, OMAP_DMA_REG_32BIT },
  44. [IRQENABLE_L0] = { 0x0018, 0x00, OMAP_DMA_REG_32BIT },
  45. [IRQENABLE_L1] = { 0x001c, 0x00, OMAP_DMA_REG_32BIT },
  46. [IRQENABLE_L2] = { 0x0020, 0x00, OMAP_DMA_REG_32BIT },
  47. [IRQENABLE_L3] = { 0x0024, 0x00, OMAP_DMA_REG_32BIT },
  48. [SYSSTATUS] = { 0x0028, 0x00, OMAP_DMA_REG_32BIT },
  49. [OCP_SYSCONFIG] = { 0x002c, 0x00, OMAP_DMA_REG_32BIT },
  50. [CAPS_0] = { 0x0064, 0x00, OMAP_DMA_REG_32BIT },
  51. [CAPS_2] = { 0x006c, 0x00, OMAP_DMA_REG_32BIT },
  52. [CAPS_3] = { 0x0070, 0x00, OMAP_DMA_REG_32BIT },
  53. [CAPS_4] = { 0x0074, 0x00, OMAP_DMA_REG_32BIT },
  54. /* Common register offsets */
  55. [CCR] = { 0x0080, 0x60, OMAP_DMA_REG_32BIT },
  56. [CLNK_CTRL] = { 0x0084, 0x60, OMAP_DMA_REG_32BIT },
  57. [CICR] = { 0x0088, 0x60, OMAP_DMA_REG_32BIT },
  58. [CSR] = { 0x008c, 0x60, OMAP_DMA_REG_32BIT },
  59. [CSDP] = { 0x0090, 0x60, OMAP_DMA_REG_32BIT },
  60. [CEN] = { 0x0094, 0x60, OMAP_DMA_REG_32BIT },
  61. [CFN] = { 0x0098, 0x60, OMAP_DMA_REG_32BIT },
  62. [CSEI] = { 0x00a4, 0x60, OMAP_DMA_REG_32BIT },
  63. [CSFI] = { 0x00a8, 0x60, OMAP_DMA_REG_32BIT },
  64. [CDEI] = { 0x00ac, 0x60, OMAP_DMA_REG_32BIT },
  65. [CDFI] = { 0x00b0, 0x60, OMAP_DMA_REG_32BIT },
  66. [CSAC] = { 0x00b4, 0x60, OMAP_DMA_REG_32BIT },
  67. [CDAC] = { 0x00b8, 0x60, OMAP_DMA_REG_32BIT },
  68. /* Channel specific register offsets */
  69. [CSSA] = { 0x009c, 0x60, OMAP_DMA_REG_32BIT },
  70. [CDSA] = { 0x00a0, 0x60, OMAP_DMA_REG_32BIT },
  71. [CCEN] = { 0x00bc, 0x60, OMAP_DMA_REG_32BIT },
  72. [CCFN] = { 0x00c0, 0x60, OMAP_DMA_REG_32BIT },
  73. [COLOR] = { 0x00c4, 0x60, OMAP_DMA_REG_32BIT },
  74. /* OMAP4 specific registers */
  75. [CDP] = { 0x00d0, 0x60, OMAP_DMA_REG_32BIT },
  76. [CNDP] = { 0x00d4, 0x60, OMAP_DMA_REG_32BIT },
  77. [CCDN] = { 0x00d8, 0x60, OMAP_DMA_REG_32BIT },
  78. };
  79. static void __iomem *dma_base;
  80. static inline void dma_write(u32 val, int reg, int lch)
  81. {
  82. void __iomem *addr = dma_base;
  83. addr += reg_map[reg].offset;
  84. addr += reg_map[reg].stride * lch;
  85. writel_relaxed(val, addr);
  86. }
  87. static inline u32 dma_read(int reg, int lch)
  88. {
  89. void __iomem *addr = dma_base;
  90. addr += reg_map[reg].offset;
  91. addr += reg_map[reg].stride * lch;
  92. return readl_relaxed(addr);
  93. }
  94. static void omap2_clear_dma(int lch)
  95. {
  96. int i;
  97. for (i = CSDP; i <= dma_common_ch_end; i += 1)
  98. dma_write(0, i, lch);
  99. }
  100. static void omap2_show_dma_caps(void)
  101. {
  102. u8 revision = dma_read(REVISION, 0) & 0xff;
  103. printk(KERN_INFO "OMAP DMA hardware revision %d.%d\n",
  104. revision >> 4, revision & 0xf);
  105. }
  106. static unsigned configure_dma_errata(void)
  107. {
  108. unsigned errata = 0;
  109. /*
  110. * Errata applicable for OMAP2430ES1.0 and all omap2420
  111. *
  112. * I.
  113. * Erratum ID: Not Available
  114. * Inter Frame DMA buffering issue DMA will wrongly
  115. * buffer elements if packing and bursting is enabled. This might
  116. * result in data gets stalled in FIFO at the end of the block.
  117. * Workaround: DMA channels must have BUFFERING_DISABLED bit set to
  118. * guarantee no data will stay in the DMA FIFO in case inter frame
  119. * buffering occurs
  120. *
  121. * II.
  122. * Erratum ID: Not Available
  123. * DMA may hang when several channels are used in parallel
  124. * In the following configuration, DMA channel hanging can occur:
  125. * a. Channel i, hardware synchronized, is enabled
  126. * b. Another channel (Channel x), software synchronized, is enabled.
  127. * c. Channel i is disabled before end of transfer
  128. * d. Channel i is reenabled.
  129. * e. Steps 1 to 4 are repeated a certain number of times.
  130. * f. A third channel (Channel y), software synchronized, is enabled.
  131. * Channel x and Channel y may hang immediately after step 'f'.
  132. * Workaround:
  133. * For any channel used - make sure NextLCH_ID is set to the value j.
  134. */
  135. if (cpu_is_omap2420() || (cpu_is_omap2430() &&
  136. (omap_type() == OMAP2430_REV_ES1_0))) {
  137. SET_DMA_ERRATA(DMA_ERRATA_IFRAME_BUFFERING);
  138. SET_DMA_ERRATA(DMA_ERRATA_PARALLEL_CHANNELS);
  139. }
  140. /*
  141. * Erratum ID: i378: OMAP2+: sDMA Channel is not disabled
  142. * after a transaction error.
  143. * Workaround: SW should explicitely disable the channel.
  144. */
  145. if (cpu_class_is_omap2())
  146. SET_DMA_ERRATA(DMA_ERRATA_i378);
  147. /*
  148. * Erratum ID: i541: sDMA FIFO draining does not finish
  149. * If sDMA channel is disabled on the fly, sDMA enters standby even
  150. * through FIFO Drain is still in progress
  151. * Workaround: Put sDMA in NoStandby more before a logical channel is
  152. * disabled, then put it back to SmartStandby right after the channel
  153. * finishes FIFO draining.
  154. */
  155. if (cpu_is_omap34xx())
  156. SET_DMA_ERRATA(DMA_ERRATA_i541);
  157. /*
  158. * Erratum ID: i88 : Special programming model needed to disable DMA
  159. * before end of block.
  160. * Workaround: software must ensure that the DMA is configured in No
  161. * Standby mode(DMAx_OCP_SYSCONFIG.MIDLEMODE = "01")
  162. */
  163. if (omap_type() == OMAP3430_REV_ES1_0)
  164. SET_DMA_ERRATA(DMA_ERRATA_i88);
  165. /*
  166. * Erratum 3.2/3.3: sometimes 0 is returned if CSAC/CDAC is
  167. * read before the DMA controller finished disabling the channel.
  168. */
  169. SET_DMA_ERRATA(DMA_ERRATA_3_3);
  170. /*
  171. * Erratum ID: Not Available
  172. * A bug in ROM code leaves IRQ status for channels 0 and 1 uncleared
  173. * after secure sram context save and restore.
  174. * Work around: Hence we need to manually clear those IRQs to avoid
  175. * spurious interrupts. This affects only secure devices.
  176. */
  177. if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
  178. SET_DMA_ERRATA(DMA_ROMCODE_BUG);
  179. return errata;
  180. }
  181. static const struct dma_slave_map omap24xx_sdma_map[] = {
  182. { "omap-gpmc", "rxtx", SDMA_FILTER_PARAM(4) },
  183. { "omap-aes", "tx", SDMA_FILTER_PARAM(9) },
  184. { "omap-aes", "rx", SDMA_FILTER_PARAM(10) },
  185. { "omap-sham", "rx", SDMA_FILTER_PARAM(13) },
  186. { "omap2_mcspi.2", "tx0", SDMA_FILTER_PARAM(15) },
  187. { "omap2_mcspi.2", "rx0", SDMA_FILTER_PARAM(16) },
  188. { "omap-mcbsp.3", "tx", SDMA_FILTER_PARAM(17) },
  189. { "omap-mcbsp.3", "rx", SDMA_FILTER_PARAM(18) },
  190. { "omap-mcbsp.4", "tx", SDMA_FILTER_PARAM(19) },
  191. { "omap-mcbsp.4", "rx", SDMA_FILTER_PARAM(20) },
  192. { "omap-mcbsp.5", "tx", SDMA_FILTER_PARAM(21) },
  193. { "omap-mcbsp.5", "rx", SDMA_FILTER_PARAM(22) },
  194. { "omap2_mcspi.2", "tx1", SDMA_FILTER_PARAM(23) },
  195. { "omap2_mcspi.2", "rx1", SDMA_FILTER_PARAM(24) },
  196. { "omap_i2c.1", "tx", SDMA_FILTER_PARAM(27) },
  197. { "omap_i2c.1", "rx", SDMA_FILTER_PARAM(28) },
  198. { "omap_i2c.2", "tx", SDMA_FILTER_PARAM(29) },
  199. { "omap_i2c.2", "rx", SDMA_FILTER_PARAM(30) },
  200. { "omap-mcbsp.1", "tx", SDMA_FILTER_PARAM(31) },
  201. { "omap-mcbsp.1", "rx", SDMA_FILTER_PARAM(32) },
  202. { "omap-mcbsp.2", "tx", SDMA_FILTER_PARAM(33) },
  203. { "omap-mcbsp.2", "rx", SDMA_FILTER_PARAM(34) },
  204. { "omap2_mcspi.0", "tx0", SDMA_FILTER_PARAM(35) },
  205. { "omap2_mcspi.0", "rx0", SDMA_FILTER_PARAM(36) },
  206. { "omap2_mcspi.0", "tx1", SDMA_FILTER_PARAM(37) },
  207. { "omap2_mcspi.0", "rx1", SDMA_FILTER_PARAM(38) },
  208. { "omap2_mcspi.0", "tx2", SDMA_FILTER_PARAM(39) },
  209. { "omap2_mcspi.0", "rx2", SDMA_FILTER_PARAM(40) },
  210. { "omap2_mcspi.0", "tx3", SDMA_FILTER_PARAM(41) },
  211. { "omap2_mcspi.0", "rx3", SDMA_FILTER_PARAM(42) },
  212. { "omap2_mcspi.1", "tx0", SDMA_FILTER_PARAM(43) },
  213. { "omap2_mcspi.1", "rx0", SDMA_FILTER_PARAM(44) },
  214. { "omap2_mcspi.1", "tx1", SDMA_FILTER_PARAM(45) },
  215. { "omap2_mcspi.1", "rx1", SDMA_FILTER_PARAM(46) },
  216. { "omap_hsmmc.1", "tx", SDMA_FILTER_PARAM(47) },
  217. { "omap_hsmmc.1", "rx", SDMA_FILTER_PARAM(48) },
  218. { "omap_uart.0", "tx", SDMA_FILTER_PARAM(49) },
  219. { "omap_uart.0", "rx", SDMA_FILTER_PARAM(50) },
  220. { "omap_uart.1", "tx", SDMA_FILTER_PARAM(51) },
  221. { "omap_uart.1", "rx", SDMA_FILTER_PARAM(52) },
  222. { "omap_uart.2", "tx", SDMA_FILTER_PARAM(53) },
  223. { "omap_uart.2", "rx", SDMA_FILTER_PARAM(54) },
  224. { "omap_hsmmc.0", "tx", SDMA_FILTER_PARAM(61) },
  225. { "omap_hsmmc.0", "rx", SDMA_FILTER_PARAM(62) },
  226. };
  227. static const struct dma_slave_map omap3xxx_sdma_map[] = {
  228. { "omap-gpmc", "rxtx", SDMA_FILTER_PARAM(4) },
  229. { "omap2_mcspi.2", "tx0", SDMA_FILTER_PARAM(15) },
  230. { "omap2_mcspi.2", "rx0", SDMA_FILTER_PARAM(16) },
  231. { "omap-mcbsp.3", "tx", SDMA_FILTER_PARAM(17) },
  232. { "omap-mcbsp.3", "rx", SDMA_FILTER_PARAM(18) },
  233. { "omap-mcbsp.4", "tx", SDMA_FILTER_PARAM(19) },
  234. { "omap-mcbsp.4", "rx", SDMA_FILTER_PARAM(20) },
  235. { "omap-mcbsp.5", "tx", SDMA_FILTER_PARAM(21) },
  236. { "omap-mcbsp.5", "rx", SDMA_FILTER_PARAM(22) },
  237. { "omap2_mcspi.2", "tx1", SDMA_FILTER_PARAM(23) },
  238. { "omap2_mcspi.2", "rx1", SDMA_FILTER_PARAM(24) },
  239. { "omap_i2c.3", "tx", SDMA_FILTER_PARAM(25) },
  240. { "omap_i2c.3", "rx", SDMA_FILTER_PARAM(26) },
  241. { "omap_i2c.1", "tx", SDMA_FILTER_PARAM(27) },
  242. { "omap_i2c.1", "rx", SDMA_FILTER_PARAM(28) },
  243. { "omap_i2c.2", "tx", SDMA_FILTER_PARAM(29) },
  244. { "omap_i2c.2", "rx", SDMA_FILTER_PARAM(30) },
  245. { "omap-mcbsp.1", "tx", SDMA_FILTER_PARAM(31) },
  246. { "omap-mcbsp.1", "rx", SDMA_FILTER_PARAM(32) },
  247. { "omap-mcbsp.2", "tx", SDMA_FILTER_PARAM(33) },
  248. { "omap-mcbsp.2", "rx", SDMA_FILTER_PARAM(34) },
  249. { "omap2_mcspi.0", "tx0", SDMA_FILTER_PARAM(35) },
  250. { "omap2_mcspi.0", "rx0", SDMA_FILTER_PARAM(36) },
  251. { "omap2_mcspi.0", "tx1", SDMA_FILTER_PARAM(37) },
  252. { "omap2_mcspi.0", "rx1", SDMA_FILTER_PARAM(38) },
  253. { "omap2_mcspi.0", "tx2", SDMA_FILTER_PARAM(39) },
  254. { "omap2_mcspi.0", "rx2", SDMA_FILTER_PARAM(40) },
  255. { "omap2_mcspi.0", "tx3", SDMA_FILTER_PARAM(41) },
  256. { "omap2_mcspi.0", "rx3", SDMA_FILTER_PARAM(42) },
  257. { "omap2_mcspi.1", "tx0", SDMA_FILTER_PARAM(43) },
  258. { "omap2_mcspi.1", "rx0", SDMA_FILTER_PARAM(44) },
  259. { "omap2_mcspi.1", "tx1", SDMA_FILTER_PARAM(45) },
  260. { "omap2_mcspi.1", "rx1", SDMA_FILTER_PARAM(46) },
  261. { "omap_hsmmc.1", "tx", SDMA_FILTER_PARAM(47) },
  262. { "omap_hsmmc.1", "rx", SDMA_FILTER_PARAM(48) },
  263. { "omap_uart.0", "tx", SDMA_FILTER_PARAM(49) },
  264. { "omap_uart.0", "rx", SDMA_FILTER_PARAM(50) },
  265. { "omap_uart.1", "tx", SDMA_FILTER_PARAM(51) },
  266. { "omap_uart.1", "rx", SDMA_FILTER_PARAM(52) },
  267. { "omap_uart.2", "tx", SDMA_FILTER_PARAM(53) },
  268. { "omap_uart.2", "rx", SDMA_FILTER_PARAM(54) },
  269. { "omap_hsmmc.0", "tx", SDMA_FILTER_PARAM(61) },
  270. { "omap_hsmmc.0", "rx", SDMA_FILTER_PARAM(62) },
  271. { "omap-aes", "tx", SDMA_FILTER_PARAM(65) },
  272. { "omap-aes", "rx", SDMA_FILTER_PARAM(66) },
  273. { "omap-sham", "rx", SDMA_FILTER_PARAM(69) },
  274. { "omap2_mcspi.3", "tx0", SDMA_FILTER_PARAM(70) },
  275. { "omap2_mcspi.3", "rx0", SDMA_FILTER_PARAM(71) },
  276. { "omap_hsmmc.2", "tx", SDMA_FILTER_PARAM(77) },
  277. { "omap_hsmmc.2", "rx", SDMA_FILTER_PARAM(78) },
  278. { "omap_uart.3", "tx", SDMA_FILTER_PARAM(81) },
  279. { "omap_uart.3", "rx", SDMA_FILTER_PARAM(82) },
  280. };
  281. static struct omap_system_dma_plat_info dma_plat_info __initdata = {
  282. .reg_map = reg_map,
  283. .channel_stride = 0x60,
  284. .show_dma_caps = omap2_show_dma_caps,
  285. .clear_dma = omap2_clear_dma,
  286. .dma_write = dma_write,
  287. .dma_read = dma_read,
  288. };
  289. static struct platform_device_info omap_dma_dev_info = {
  290. .name = "omap-dma-engine",
  291. .id = -1,
  292. .dma_mask = DMA_BIT_MASK(32),
  293. };
  294. /* One time initializations */
  295. static int __init omap2_system_dma_init_dev(struct omap_hwmod *oh, void *unused)
  296. {
  297. struct platform_device *pdev;
  298. struct omap_system_dma_plat_info p;
  299. struct omap_dma_dev_attr *d;
  300. struct resource *mem;
  301. char *name = "omap_dma_system";
  302. p = dma_plat_info;
  303. p.dma_attr = (struct omap_dma_dev_attr *)oh->dev_attr;
  304. p.errata = configure_dma_errata();
  305. if (!of_have_populated_dt()) {
  306. if (soc_is_omap24xx()) {
  307. p.slave_map = omap24xx_sdma_map;
  308. p.slavecnt = ARRAY_SIZE(omap24xx_sdma_map);
  309. } else if (soc_is_omap34xx() || soc_is_omap3630()) {
  310. p.slave_map = omap3xxx_sdma_map;
  311. p.slavecnt = ARRAY_SIZE(omap3xxx_sdma_map);
  312. } else {
  313. pr_err("%s: The legacy DMA map is not provided!\n",
  314. __func__);
  315. return -ENODEV;
  316. }
  317. }
  318. pdev = omap_device_build(name, 0, oh, &p, sizeof(p));
  319. if (IS_ERR(pdev)) {
  320. pr_err("%s: Can't build omap_device for %s:%s.\n",
  321. __func__, name, oh->name);
  322. return PTR_ERR(pdev);
  323. }
  324. omap_dma_dev_info.res = pdev->resource;
  325. omap_dma_dev_info.num_res = pdev->num_resources;
  326. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  327. if (!mem) {
  328. dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
  329. return -EINVAL;
  330. }
  331. dma_base = ioremap(mem->start, resource_size(mem));
  332. if (!dma_base) {
  333. dev_err(&pdev->dev, "%s: ioremap fail\n", __func__);
  334. return -ENOMEM;
  335. }
  336. d = oh->dev_attr;
  337. if (cpu_is_omap34xx() && (omap_type() != OMAP2_DEVICE_TYPE_GP))
  338. d->dev_caps |= HS_CHANNELS_RESERVED;
  339. if (platform_get_irq_byname(pdev, "0") < 0)
  340. d->dev_caps |= DMA_ENGINE_HANDLE_IRQ;
  341. /* Check the capabilities register for descriptor loading feature */
  342. if (dma_read(CAPS_0, 0) & DMA_HAS_DESCRIPTOR_CAPS)
  343. dma_common_ch_end = CCDN;
  344. else
  345. dma_common_ch_end = CCFN;
  346. return 0;
  347. }
  348. static int __init omap2_system_dma_init(void)
  349. {
  350. struct platform_device *pdev;
  351. int res;
  352. res = omap_hwmod_for_each_by_class("dma",
  353. omap2_system_dma_init_dev, NULL);
  354. if (res)
  355. return res;
  356. if (of_have_populated_dt())
  357. return res;
  358. pdev = platform_device_register_full(&omap_dma_dev_info);
  359. if (IS_ERR(pdev))
  360. return PTR_ERR(pdev);
  361. return res;
  362. }
  363. omap_arch_initcall(omap2_system_dma_init);