dma.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * OMAP1/OMAP7xx - specific DMA driver
  4. *
  5. * Copyright (C) 2003 - 2008 Nokia Corporation
  6. * Author: Juha Yrjölä <juha.yrjola@nokia.com>
  7. * DMA channel linking for 1610 by Samuel Ortiz <samuel.ortiz@nokia.com>
  8. * Graphics DMA and LCD DMA graphics tranformations
  9. * by Imre Deak <imre.deak@nokia.com>
  10. * OMAP2/3 support Copyright (C) 2004-2007 Texas Instruments, Inc.
  11. * Some functions based on earlier dma-omap.c Copyright (C) 2001 RidgeRun, Inc.
  12. *
  13. * Copyright (C) 2010 Texas Instruments Incorporated - https://www.ti.com/
  14. * Converted DMA library into platform driver
  15. * - G, Manjunath Kondaiah <manjugk@ti.com>
  16. */
  17. #include <linux/err.h>
  18. #include <linux/slab.h>
  19. #include <linux/module.h>
  20. #include <linux/init.h>
  21. #include <linux/device.h>
  22. #include <linux/io.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/dmaengine.h>
  25. #include <linux/omap-dma.h>
  26. #include "tc.h"
  27. #include "soc.h"
  28. #define OMAP1_DMA_BASE (0xfffed800)
  29. static u32 enable_1510_mode;
  30. static const struct omap_dma_reg reg_map[] = {
  31. [GCR] = { 0x0400, 0x00, OMAP_DMA_REG_16BIT },
  32. [GSCR] = { 0x0404, 0x00, OMAP_DMA_REG_16BIT },
  33. [GRST1] = { 0x0408, 0x00, OMAP_DMA_REG_16BIT },
  34. [HW_ID] = { 0x0442, 0x00, OMAP_DMA_REG_16BIT },
  35. [PCH2_ID] = { 0x0444, 0x00, OMAP_DMA_REG_16BIT },
  36. [PCH0_ID] = { 0x0446, 0x00, OMAP_DMA_REG_16BIT },
  37. [PCH1_ID] = { 0x0448, 0x00, OMAP_DMA_REG_16BIT },
  38. [PCHG_ID] = { 0x044a, 0x00, OMAP_DMA_REG_16BIT },
  39. [PCHD_ID] = { 0x044c, 0x00, OMAP_DMA_REG_16BIT },
  40. [CAPS_0] = { 0x044e, 0x00, OMAP_DMA_REG_2X16BIT },
  41. [CAPS_1] = { 0x0452, 0x00, OMAP_DMA_REG_2X16BIT },
  42. [CAPS_2] = { 0x0456, 0x00, OMAP_DMA_REG_16BIT },
  43. [CAPS_3] = { 0x0458, 0x00, OMAP_DMA_REG_16BIT },
  44. [CAPS_4] = { 0x045a, 0x00, OMAP_DMA_REG_16BIT },
  45. [PCH2_SR] = { 0x0460, 0x00, OMAP_DMA_REG_16BIT },
  46. [PCH0_SR] = { 0x0480, 0x00, OMAP_DMA_REG_16BIT },
  47. [PCH1_SR] = { 0x0482, 0x00, OMAP_DMA_REG_16BIT },
  48. [PCHD_SR] = { 0x04c0, 0x00, OMAP_DMA_REG_16BIT },
  49. /* Common Registers */
  50. [CSDP] = { 0x0000, 0x40, OMAP_DMA_REG_16BIT },
  51. [CCR] = { 0x0002, 0x40, OMAP_DMA_REG_16BIT },
  52. [CICR] = { 0x0004, 0x40, OMAP_DMA_REG_16BIT },
  53. [CSR] = { 0x0006, 0x40, OMAP_DMA_REG_16BIT },
  54. [CEN] = { 0x0010, 0x40, OMAP_DMA_REG_16BIT },
  55. [CFN] = { 0x0012, 0x40, OMAP_DMA_REG_16BIT },
  56. [CSFI] = { 0x0014, 0x40, OMAP_DMA_REG_16BIT },
  57. [CSEI] = { 0x0016, 0x40, OMAP_DMA_REG_16BIT },
  58. [CPC] = { 0x0018, 0x40, OMAP_DMA_REG_16BIT }, /* 15xx only */
  59. [CSAC] = { 0x0018, 0x40, OMAP_DMA_REG_16BIT },
  60. [CDAC] = { 0x001a, 0x40, OMAP_DMA_REG_16BIT },
  61. [CDEI] = { 0x001c, 0x40, OMAP_DMA_REG_16BIT },
  62. [CDFI] = { 0x001e, 0x40, OMAP_DMA_REG_16BIT },
  63. [CLNK_CTRL] = { 0x0028, 0x40, OMAP_DMA_REG_16BIT },
  64. /* Channel specific register offsets */
  65. [CSSA] = { 0x0008, 0x40, OMAP_DMA_REG_2X16BIT },
  66. [CDSA] = { 0x000c, 0x40, OMAP_DMA_REG_2X16BIT },
  67. [COLOR] = { 0x0020, 0x40, OMAP_DMA_REG_2X16BIT },
  68. [CCR2] = { 0x0024, 0x40, OMAP_DMA_REG_16BIT },
  69. [LCH_CTRL] = { 0x002a, 0x40, OMAP_DMA_REG_16BIT },
  70. };
  71. static struct resource res[] __initdata = {
  72. [0] = {
  73. .start = OMAP1_DMA_BASE,
  74. .end = OMAP1_DMA_BASE + SZ_2K - 1,
  75. .flags = IORESOURCE_MEM,
  76. },
  77. [1] = {
  78. .name = "0",
  79. .start = INT_DMA_CH0_6,
  80. .flags = IORESOURCE_IRQ,
  81. },
  82. [2] = {
  83. .name = "1",
  84. .start = INT_DMA_CH1_7,
  85. .flags = IORESOURCE_IRQ,
  86. },
  87. [3] = {
  88. .name = "2",
  89. .start = INT_DMA_CH2_8,
  90. .flags = IORESOURCE_IRQ,
  91. },
  92. [4] = {
  93. .name = "3",
  94. .start = INT_DMA_CH3,
  95. .flags = IORESOURCE_IRQ,
  96. },
  97. [5] = {
  98. .name = "4",
  99. .start = INT_DMA_CH4,
  100. .flags = IORESOURCE_IRQ,
  101. },
  102. [6] = {
  103. .name = "5",
  104. .start = INT_DMA_CH5,
  105. .flags = IORESOURCE_IRQ,
  106. },
  107. /* Handled in lcd_dma.c */
  108. [7] = {
  109. .name = "6",
  110. .start = INT_1610_DMA_CH6,
  111. .flags = IORESOURCE_IRQ,
  112. },
  113. /* irq's for omap16xx and omap7xx */
  114. [8] = {
  115. .name = "7",
  116. .start = INT_1610_DMA_CH7,
  117. .flags = IORESOURCE_IRQ,
  118. },
  119. [9] = {
  120. .name = "8",
  121. .start = INT_1610_DMA_CH8,
  122. .flags = IORESOURCE_IRQ,
  123. },
  124. [10] = {
  125. .name = "9",
  126. .start = INT_1610_DMA_CH9,
  127. .flags = IORESOURCE_IRQ,
  128. },
  129. [11] = {
  130. .name = "10",
  131. .start = INT_1610_DMA_CH10,
  132. .flags = IORESOURCE_IRQ,
  133. },
  134. [12] = {
  135. .name = "11",
  136. .start = INT_1610_DMA_CH11,
  137. .flags = IORESOURCE_IRQ,
  138. },
  139. [13] = {
  140. .name = "12",
  141. .start = INT_1610_DMA_CH12,
  142. .flags = IORESOURCE_IRQ,
  143. },
  144. [14] = {
  145. .name = "13",
  146. .start = INT_1610_DMA_CH13,
  147. .flags = IORESOURCE_IRQ,
  148. },
  149. [15] = {
  150. .name = "14",
  151. .start = INT_1610_DMA_CH14,
  152. .flags = IORESOURCE_IRQ,
  153. },
  154. [16] = {
  155. .name = "15",
  156. .start = INT_1610_DMA_CH15,
  157. .flags = IORESOURCE_IRQ,
  158. },
  159. [17] = {
  160. .name = "16",
  161. .start = INT_DMA_LCD,
  162. .flags = IORESOURCE_IRQ,
  163. },
  164. };
  165. static void __iomem *dma_base;
  166. static inline void dma_write(u32 val, int reg, int lch)
  167. {
  168. void __iomem *addr = dma_base;
  169. addr += reg_map[reg].offset;
  170. addr += reg_map[reg].stride * lch;
  171. __raw_writew(val, addr);
  172. if (reg_map[reg].type == OMAP_DMA_REG_2X16BIT)
  173. __raw_writew(val >> 16, addr + 2);
  174. }
  175. static inline u32 dma_read(int reg, int lch)
  176. {
  177. void __iomem *addr = dma_base;
  178. uint32_t val;
  179. addr += reg_map[reg].offset;
  180. addr += reg_map[reg].stride * lch;
  181. val = __raw_readw(addr);
  182. if (reg_map[reg].type == OMAP_DMA_REG_2X16BIT)
  183. val |= __raw_readw(addr + 2) << 16;
  184. return val;
  185. }
  186. static void omap1_clear_lch_regs(int lch)
  187. {
  188. int i;
  189. for (i = CPC; i <= COLOR; i += 1)
  190. dma_write(0, i, lch);
  191. }
  192. static void omap1_clear_dma(int lch)
  193. {
  194. u32 l;
  195. l = dma_read(CCR, lch);
  196. l &= ~OMAP_DMA_CCR_EN;
  197. dma_write(l, CCR, lch);
  198. /* Clear pending interrupts */
  199. l = dma_read(CSR, lch);
  200. }
  201. static void omap1_show_dma_caps(void)
  202. {
  203. if (enable_1510_mode) {
  204. printk(KERN_INFO "DMA support for OMAP15xx initialized\n");
  205. } else {
  206. u16 w;
  207. printk(KERN_INFO "OMAP DMA hardware version %d\n",
  208. dma_read(HW_ID, 0));
  209. printk(KERN_INFO "DMA capabilities: %08x:%08x:%04x:%04x:%04x\n",
  210. dma_read(CAPS_0, 0), dma_read(CAPS_1, 0),
  211. dma_read(CAPS_2, 0), dma_read(CAPS_3, 0),
  212. dma_read(CAPS_4, 0));
  213. /* Disable OMAP 3.0/3.1 compatibility mode. */
  214. w = dma_read(GSCR, 0);
  215. w |= 1 << 3;
  216. dma_write(w, GSCR, 0);
  217. }
  218. }
  219. static unsigned configure_dma_errata(void)
  220. {
  221. unsigned errata = 0;
  222. /*
  223. * Erratum 3.2/3.3: sometimes 0 is returned if CSAC/CDAC is
  224. * read before the DMA controller finished disabling the channel.
  225. */
  226. if (!cpu_is_omap15xx())
  227. SET_DMA_ERRATA(DMA_ERRATA_3_3);
  228. return errata;
  229. }
  230. static const struct platform_device_info omap_dma_dev_info = {
  231. .name = "omap-dma-engine",
  232. .id = -1,
  233. .dma_mask = DMA_BIT_MASK(32),
  234. .res = res,
  235. .num_res = 1,
  236. };
  237. /* OMAP1510, OMAP1610*/
  238. static const struct dma_slave_map omap1xxx_sdma_map[] = {
  239. { "omap-mcbsp.1", "tx", SDMA_FILTER_PARAM(8) },
  240. { "omap-mcbsp.1", "rx", SDMA_FILTER_PARAM(9) },
  241. { "omap-mcbsp.3", "tx", SDMA_FILTER_PARAM(10) },
  242. { "omap-mcbsp.3", "rx", SDMA_FILTER_PARAM(11) },
  243. { "omap-mcbsp.2", "tx", SDMA_FILTER_PARAM(16) },
  244. { "omap-mcbsp.2", "rx", SDMA_FILTER_PARAM(17) },
  245. { "mmci-omap.0", "tx", SDMA_FILTER_PARAM(21) },
  246. { "mmci-omap.0", "rx", SDMA_FILTER_PARAM(22) },
  247. { "omap_udc", "rx0", SDMA_FILTER_PARAM(26) },
  248. { "omap_udc", "rx1", SDMA_FILTER_PARAM(27) },
  249. { "omap_udc", "rx2", SDMA_FILTER_PARAM(28) },
  250. { "omap_udc", "tx0", SDMA_FILTER_PARAM(29) },
  251. { "omap_udc", "tx1", SDMA_FILTER_PARAM(30) },
  252. { "omap_udc", "tx2", SDMA_FILTER_PARAM(31) },
  253. { "mmci-omap.1", "tx", SDMA_FILTER_PARAM(54) },
  254. { "mmci-omap.1", "rx", SDMA_FILTER_PARAM(55) },
  255. };
  256. static struct omap_system_dma_plat_info dma_plat_info __initdata = {
  257. .reg_map = reg_map,
  258. .channel_stride = 0x40,
  259. .show_dma_caps = omap1_show_dma_caps,
  260. .clear_lch_regs = omap1_clear_lch_regs,
  261. .clear_dma = omap1_clear_dma,
  262. .dma_write = dma_write,
  263. .dma_read = dma_read,
  264. };
  265. static int __init omap1_system_dma_init(void)
  266. {
  267. struct omap_system_dma_plat_info p;
  268. struct omap_dma_dev_attr *d;
  269. struct platform_device *pdev, *dma_pdev;
  270. int ret;
  271. pdev = platform_device_alloc("omap_dma_system", 0);
  272. if (!pdev) {
  273. pr_err("%s: Unable to device alloc for dma\n",
  274. __func__);
  275. return -ENOMEM;
  276. }
  277. dma_base = ioremap(res[0].start, resource_size(&res[0]));
  278. if (!dma_base) {
  279. pr_err("%s: Unable to ioremap\n", __func__);
  280. ret = -ENODEV;
  281. goto exit_device_put;
  282. }
  283. ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
  284. if (ret) {
  285. dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
  286. __func__, pdev->name, pdev->id);
  287. goto exit_iounmap;
  288. }
  289. d = kzalloc_obj(*d);
  290. if (!d) {
  291. ret = -ENOMEM;
  292. goto exit_iounmap;
  293. }
  294. /* Valid attributes for omap1 plus processors */
  295. if (cpu_is_omap15xx())
  296. d->dev_caps = ENABLE_1510_MODE;
  297. enable_1510_mode = d->dev_caps & ENABLE_1510_MODE;
  298. if (cpu_is_omap16xx())
  299. d->dev_caps = ENABLE_16XX_MODE;
  300. d->dev_caps |= SRC_PORT;
  301. d->dev_caps |= DST_PORT;
  302. d->dev_caps |= SRC_INDEX;
  303. d->dev_caps |= DST_INDEX;
  304. d->dev_caps |= IS_BURST_ONLY4;
  305. d->dev_caps |= CLEAR_CSR_ON_READ;
  306. d->dev_caps |= IS_WORD_16;
  307. /* available logical channels */
  308. if (cpu_is_omap15xx()) {
  309. d->lch_count = 9;
  310. } else {
  311. if (d->dev_caps & ENABLE_1510_MODE)
  312. d->lch_count = 9;
  313. else
  314. d->lch_count = 16;
  315. }
  316. p = dma_plat_info;
  317. p.dma_attr = d;
  318. p.errata = configure_dma_errata();
  319. p.slave_map = omap1xxx_sdma_map;
  320. p.slavecnt = ARRAY_SIZE(omap1xxx_sdma_map);
  321. ret = platform_device_add_data(pdev, &p, sizeof(p));
  322. if (ret) {
  323. dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
  324. __func__, pdev->name, pdev->id);
  325. goto exit_release_d;
  326. }
  327. ret = platform_device_add(pdev);
  328. if (ret) {
  329. dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
  330. __func__, pdev->name, pdev->id);
  331. goto exit_release_d;
  332. }
  333. dma_pdev = platform_device_register_full(&omap_dma_dev_info);
  334. if (IS_ERR(dma_pdev)) {
  335. ret = PTR_ERR(dma_pdev);
  336. goto exit_release_pdev;
  337. }
  338. return ret;
  339. exit_release_pdev:
  340. platform_device_del(pdev);
  341. exit_release_d:
  342. kfree(d);
  343. exit_iounmap:
  344. iounmap(dma_base);
  345. exit_device_put:
  346. platform_device_put(pdev);
  347. return ret;
  348. }
  349. arch_initcall(omap1_system_dma_init);