dma.c 11 KB

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