dma.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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. }
  222. static unsigned configure_dma_errata(void)
  223. {
  224. unsigned errata = 0;
  225. /*
  226. * Erratum 3.2/3.3: sometimes 0 is returned if CSAC/CDAC is
  227. * read before the DMA controller finished disabling the channel.
  228. */
  229. if (!cpu_is_omap15xx())
  230. SET_DMA_ERRATA(DMA_ERRATA_3_3);
  231. return errata;
  232. }
  233. static const struct platform_device_info omap_dma_dev_info = {
  234. .name = "omap-dma-engine",
  235. .id = -1,
  236. .dma_mask = DMA_BIT_MASK(32),
  237. .res = res,
  238. .num_res = 1,
  239. };
  240. /* OMAP730, OMAP850 */
  241. static const struct dma_slave_map omap7xx_sdma_map[] = {
  242. { "omap-mcbsp.1", "tx", SDMA_FILTER_PARAM(8) },
  243. { "omap-mcbsp.1", "rx", SDMA_FILTER_PARAM(9) },
  244. { "omap-mcbsp.2", "tx", SDMA_FILTER_PARAM(10) },
  245. { "omap-mcbsp.2", "rx", SDMA_FILTER_PARAM(11) },
  246. { "mmci-omap.0", "tx", SDMA_FILTER_PARAM(21) },
  247. { "mmci-omap.0", "rx", SDMA_FILTER_PARAM(22) },
  248. { "omap_udc", "rx0", SDMA_FILTER_PARAM(26) },
  249. { "omap_udc", "rx1", SDMA_FILTER_PARAM(27) },
  250. { "omap_udc", "rx2", SDMA_FILTER_PARAM(28) },
  251. { "omap_udc", "tx0", SDMA_FILTER_PARAM(29) },
  252. { "omap_udc", "tx1", SDMA_FILTER_PARAM(30) },
  253. { "omap_udc", "tx2", SDMA_FILTER_PARAM(31) },
  254. };
  255. /* OMAP1510, OMAP1610*/
  256. static const struct dma_slave_map omap1xxx_sdma_map[] = {
  257. { "omap-mcbsp.1", "tx", SDMA_FILTER_PARAM(8) },
  258. { "omap-mcbsp.1", "rx", SDMA_FILTER_PARAM(9) },
  259. { "omap-mcbsp.3", "tx", SDMA_FILTER_PARAM(10) },
  260. { "omap-mcbsp.3", "rx", SDMA_FILTER_PARAM(11) },
  261. { "omap-mcbsp.2", "tx", SDMA_FILTER_PARAM(16) },
  262. { "omap-mcbsp.2", "rx", SDMA_FILTER_PARAM(17) },
  263. { "mmci-omap.0", "tx", SDMA_FILTER_PARAM(21) },
  264. { "mmci-omap.0", "rx", SDMA_FILTER_PARAM(22) },
  265. { "omap_udc", "rx0", SDMA_FILTER_PARAM(26) },
  266. { "omap_udc", "rx1", SDMA_FILTER_PARAM(27) },
  267. { "omap_udc", "rx2", SDMA_FILTER_PARAM(28) },
  268. { "omap_udc", "tx0", SDMA_FILTER_PARAM(29) },
  269. { "omap_udc", "tx1", SDMA_FILTER_PARAM(30) },
  270. { "omap_udc", "tx2", SDMA_FILTER_PARAM(31) },
  271. { "mmci-omap.1", "tx", SDMA_FILTER_PARAM(54) },
  272. { "mmci-omap.1", "rx", SDMA_FILTER_PARAM(55) },
  273. };
  274. static struct omap_system_dma_plat_info dma_plat_info __initdata = {
  275. .reg_map = reg_map,
  276. .channel_stride = 0x40,
  277. .show_dma_caps = omap1_show_dma_caps,
  278. .clear_lch_regs = omap1_clear_lch_regs,
  279. .clear_dma = omap1_clear_dma,
  280. .dma_write = dma_write,
  281. .dma_read = dma_read,
  282. };
  283. static int __init omap1_system_dma_init(void)
  284. {
  285. struct omap_system_dma_plat_info p;
  286. struct omap_dma_dev_attr *d;
  287. struct platform_device *pdev, *dma_pdev;
  288. int ret;
  289. pdev = platform_device_alloc("omap_dma_system", 0);
  290. if (!pdev) {
  291. pr_err("%s: Unable to device alloc for dma\n",
  292. __func__);
  293. return -ENOMEM;
  294. }
  295. dma_base = ioremap(res[0].start, resource_size(&res[0]));
  296. if (!dma_base) {
  297. pr_err("%s: Unable to ioremap\n", __func__);
  298. ret = -ENODEV;
  299. goto exit_device_put;
  300. }
  301. ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
  302. if (ret) {
  303. dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
  304. __func__, pdev->name, pdev->id);
  305. goto exit_iounmap;
  306. }
  307. d = kzalloc(sizeof(*d), GFP_KERNEL);
  308. if (!d) {
  309. ret = -ENOMEM;
  310. goto exit_iounmap;
  311. }
  312. /* Valid attributes for omap1 plus processors */
  313. if (cpu_is_omap15xx())
  314. d->dev_caps = ENABLE_1510_MODE;
  315. enable_1510_mode = d->dev_caps & ENABLE_1510_MODE;
  316. if (cpu_is_omap16xx())
  317. d->dev_caps = ENABLE_16XX_MODE;
  318. d->dev_caps |= SRC_PORT;
  319. d->dev_caps |= DST_PORT;
  320. d->dev_caps |= SRC_INDEX;
  321. d->dev_caps |= DST_INDEX;
  322. d->dev_caps |= IS_BURST_ONLY4;
  323. d->dev_caps |= CLEAR_CSR_ON_READ;
  324. d->dev_caps |= IS_WORD_16;
  325. /* available logical channels */
  326. if (cpu_is_omap15xx()) {
  327. d->lch_count = 9;
  328. } else {
  329. if (d->dev_caps & ENABLE_1510_MODE)
  330. d->lch_count = 9;
  331. else
  332. d->lch_count = 16;
  333. }
  334. p = dma_plat_info;
  335. p.dma_attr = d;
  336. p.errata = configure_dma_errata();
  337. if (cpu_is_omap7xx()) {
  338. p.slave_map = omap7xx_sdma_map;
  339. p.slavecnt = ARRAY_SIZE(omap7xx_sdma_map);
  340. } else {
  341. p.slave_map = omap1xxx_sdma_map;
  342. p.slavecnt = ARRAY_SIZE(omap1xxx_sdma_map);
  343. }
  344. ret = platform_device_add_data(pdev, &p, sizeof(p));
  345. if (ret) {
  346. dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
  347. __func__, pdev->name, pdev->id);
  348. goto exit_release_d;
  349. }
  350. ret = platform_device_add(pdev);
  351. if (ret) {
  352. dev_err(&pdev->dev, "%s: Unable to add resources for %s%d\n",
  353. __func__, pdev->name, pdev->id);
  354. goto exit_release_d;
  355. }
  356. dma_pdev = platform_device_register_full(&omap_dma_dev_info);
  357. if (IS_ERR(dma_pdev)) {
  358. ret = PTR_ERR(dma_pdev);
  359. goto exit_release_pdev;
  360. }
  361. return ret;
  362. exit_release_pdev:
  363. platform_device_del(pdev);
  364. exit_release_d:
  365. kfree(d);
  366. exit_iounmap:
  367. iounmap(dma_base);
  368. exit_device_put:
  369. platform_device_put(pdev);
  370. return ret;
  371. }
  372. arch_initcall(omap1_system_dma_init);