dma.c 11 KB

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