bfin_dma_5xx.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. /*
  2. * bfin_dma_5xx.c - Blackfin DMA implementation
  3. *
  4. * Copyright 2004-2006 Analog Devices Inc.
  5. * Licensed under the GPL-2 or later.
  6. */
  7. #include <linux/errno.h>
  8. #include <linux/interrupt.h>
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/param.h>
  12. #include <linux/proc_fs.h>
  13. #include <linux/sched.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/spinlock.h>
  16. #include <asm/blackfin.h>
  17. #include <asm/cacheflush.h>
  18. #include <asm/dma.h>
  19. #include <asm/uaccess.h>
  20. /**************************************************************************
  21. * Global Variables
  22. ***************************************************************************/
  23. static struct dma_channel dma_ch[MAX_DMA_CHANNELS];
  24. /*------------------------------------------------------------------------------
  25. * Set the Buffer Clear bit in the Configuration register of specific DMA
  26. * channel. This will stop the descriptor based DMA operation.
  27. *-----------------------------------------------------------------------------*/
  28. static void clear_dma_buffer(unsigned int channel)
  29. {
  30. dma_ch[channel].regs->cfg |= RESTART;
  31. SSYNC();
  32. dma_ch[channel].regs->cfg &= ~RESTART;
  33. }
  34. static int __init blackfin_dma_init(void)
  35. {
  36. int i;
  37. printk(KERN_INFO "Blackfin DMA Controller\n");
  38. for (i = 0; i < MAX_DMA_CHANNELS; i++) {
  39. dma_ch[i].chan_status = DMA_CHANNEL_FREE;
  40. dma_ch[i].regs = dma_io_base_addr[i];
  41. mutex_init(&(dma_ch[i].dmalock));
  42. }
  43. /* Mark MEMDMA Channel 0 as requested since we're using it internally */
  44. request_dma(CH_MEM_STREAM0_DEST, "Blackfin dma_memcpy");
  45. request_dma(CH_MEM_STREAM0_SRC, "Blackfin dma_memcpy");
  46. #if defined(CONFIG_DEB_DMA_URGENT)
  47. bfin_write_EBIU_DDRQUE(bfin_read_EBIU_DDRQUE()
  48. | DEB1_URGENT | DEB2_URGENT | DEB3_URGENT);
  49. #endif
  50. return 0;
  51. }
  52. arch_initcall(blackfin_dma_init);
  53. #ifdef CONFIG_PROC_FS
  54. static int proc_dma_show(struct seq_file *m, void *v)
  55. {
  56. int i;
  57. for (i = 0; i < MAX_DMA_CHANNELS; ++i)
  58. if (dma_ch[i].chan_status != DMA_CHANNEL_FREE)
  59. seq_printf(m, "%2d: %s\n", i, dma_ch[i].device_id);
  60. return 0;
  61. }
  62. static int proc_dma_open(struct inode *inode, struct file *file)
  63. {
  64. return single_open(file, proc_dma_show, NULL);
  65. }
  66. static const struct file_operations proc_dma_operations = {
  67. .open = proc_dma_open,
  68. .read = seq_read,
  69. .llseek = seq_lseek,
  70. .release = single_release,
  71. };
  72. static int __init proc_dma_init(void)
  73. {
  74. return proc_create("dma", 0, NULL, &proc_dma_operations) != NULL;
  75. }
  76. late_initcall(proc_dma_init);
  77. #endif
  78. /*------------------------------------------------------------------------------
  79. * Request the specific DMA channel from the system.
  80. *-----------------------------------------------------------------------------*/
  81. int request_dma(unsigned int channel, const char *device_id)
  82. {
  83. pr_debug("request_dma() : BEGIN \n");
  84. if (device_id == NULL)
  85. printk(KERN_WARNING "request_dma(%u): no device_id given\n", channel);
  86. #if defined(CONFIG_BF561) && ANOMALY_05000182
  87. if (channel >= CH_IMEM_STREAM0_DEST && channel <= CH_IMEM_STREAM1_DEST) {
  88. if (get_cclk() > 500000000) {
  89. printk(KERN_WARNING
  90. "Request IMDMA failed due to ANOMALY 05000182\n");
  91. return -EFAULT;
  92. }
  93. }
  94. #endif
  95. mutex_lock(&(dma_ch[channel].dmalock));
  96. if ((dma_ch[channel].chan_status == DMA_CHANNEL_REQUESTED)
  97. || (dma_ch[channel].chan_status == DMA_CHANNEL_ENABLED)) {
  98. mutex_unlock(&(dma_ch[channel].dmalock));
  99. pr_debug("DMA CHANNEL IN USE \n");
  100. return -EBUSY;
  101. } else {
  102. dma_ch[channel].chan_status = DMA_CHANNEL_REQUESTED;
  103. pr_debug("DMA CHANNEL IS ALLOCATED \n");
  104. }
  105. mutex_unlock(&(dma_ch[channel].dmalock));
  106. #ifdef CONFIG_BF54x
  107. if (channel >= CH_UART2_RX && channel <= CH_UART3_TX) {
  108. unsigned int per_map;
  109. per_map = dma_ch[channel].regs->peripheral_map & 0xFFF;
  110. if (strncmp(device_id, "BFIN_UART", 9) == 0)
  111. dma_ch[channel].regs->peripheral_map = per_map |
  112. ((channel - CH_UART2_RX + 0xC)<<12);
  113. else
  114. dma_ch[channel].regs->peripheral_map = per_map |
  115. ((channel - CH_UART2_RX + 0x6)<<12);
  116. }
  117. #endif
  118. dma_ch[channel].device_id = device_id;
  119. dma_ch[channel].irq_callback = NULL;
  120. /* This is to be enabled by putting a restriction -
  121. * you have to request DMA, before doing any operations on
  122. * descriptor/channel
  123. */
  124. pr_debug("request_dma() : END \n");
  125. return channel;
  126. }
  127. EXPORT_SYMBOL(request_dma);
  128. int set_dma_callback(unsigned int channel, dma_interrupt_t callback, void *data)
  129. {
  130. BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
  131. && channel < MAX_DMA_CHANNELS));
  132. if (callback != NULL) {
  133. int ret_val;
  134. dma_ch[channel].irq = channel2irq(channel);
  135. dma_ch[channel].data = data;
  136. ret_val =
  137. request_irq(dma_ch[channel].irq, callback, IRQF_DISABLED,
  138. dma_ch[channel].device_id, data);
  139. if (ret_val) {
  140. printk(KERN_NOTICE
  141. "Request irq in DMA engine failed.\n");
  142. return -EPERM;
  143. }
  144. dma_ch[channel].irq_callback = callback;
  145. }
  146. return 0;
  147. }
  148. EXPORT_SYMBOL(set_dma_callback);
  149. void free_dma(unsigned int channel)
  150. {
  151. pr_debug("freedma() : BEGIN \n");
  152. BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
  153. && channel < MAX_DMA_CHANNELS));
  154. /* Halt the DMA */
  155. disable_dma(channel);
  156. clear_dma_buffer(channel);
  157. if (dma_ch[channel].irq_callback != NULL)
  158. free_irq(dma_ch[channel].irq, dma_ch[channel].data);
  159. /* Clear the DMA Variable in the Channel */
  160. mutex_lock(&(dma_ch[channel].dmalock));
  161. dma_ch[channel].chan_status = DMA_CHANNEL_FREE;
  162. mutex_unlock(&(dma_ch[channel].dmalock));
  163. pr_debug("freedma() : END \n");
  164. }
  165. EXPORT_SYMBOL(free_dma);
  166. void dma_enable_irq(unsigned int channel)
  167. {
  168. pr_debug("dma_enable_irq() : BEGIN \n");
  169. enable_irq(dma_ch[channel].irq);
  170. }
  171. EXPORT_SYMBOL(dma_enable_irq);
  172. void dma_disable_irq(unsigned int channel)
  173. {
  174. pr_debug("dma_disable_irq() : BEGIN \n");
  175. disable_irq(dma_ch[channel].irq);
  176. }
  177. EXPORT_SYMBOL(dma_disable_irq);
  178. int dma_channel_active(unsigned int channel)
  179. {
  180. if (dma_ch[channel].chan_status == DMA_CHANNEL_FREE) {
  181. return 0;
  182. } else {
  183. return 1;
  184. }
  185. }
  186. EXPORT_SYMBOL(dma_channel_active);
  187. /*------------------------------------------------------------------------------
  188. * stop the specific DMA channel.
  189. *-----------------------------------------------------------------------------*/
  190. void disable_dma(unsigned int channel)
  191. {
  192. pr_debug("stop_dma() : BEGIN \n");
  193. dma_ch[channel].regs->cfg &= ~DMAEN; /* Clean the enable bit */
  194. SSYNC();
  195. dma_ch[channel].chan_status = DMA_CHANNEL_REQUESTED;
  196. /* Needs to be enabled Later */
  197. pr_debug("stop_dma() : END \n");
  198. return;
  199. }
  200. EXPORT_SYMBOL(disable_dma);
  201. void enable_dma(unsigned int channel)
  202. {
  203. pr_debug("enable_dma() : BEGIN \n");
  204. dma_ch[channel].chan_status = DMA_CHANNEL_ENABLED;
  205. dma_ch[channel].regs->curr_x_count = 0;
  206. dma_ch[channel].regs->curr_y_count = 0;
  207. dma_ch[channel].regs->cfg |= DMAEN; /* Set the enable bit */
  208. pr_debug("enable_dma() : END \n");
  209. return;
  210. }
  211. EXPORT_SYMBOL(enable_dma);
  212. /*------------------------------------------------------------------------------
  213. * Set the Start Address register for the specific DMA channel
  214. * This function can be used for register based DMA,
  215. * to setup the start address
  216. * addr: Starting address of the DMA Data to be transferred.
  217. *-----------------------------------------------------------------------------*/
  218. void set_dma_start_addr(unsigned int channel, unsigned long addr)
  219. {
  220. pr_debug("set_dma_start_addr() : BEGIN \n");
  221. dma_ch[channel].regs->start_addr = addr;
  222. pr_debug("set_dma_start_addr() : END\n");
  223. }
  224. EXPORT_SYMBOL(set_dma_start_addr);
  225. void set_dma_next_desc_addr(unsigned int channel, unsigned long addr)
  226. {
  227. pr_debug("set_dma_next_desc_addr() : BEGIN \n");
  228. dma_ch[channel].regs->next_desc_ptr = addr;
  229. pr_debug("set_dma_next_desc_addr() : END\n");
  230. }
  231. EXPORT_SYMBOL(set_dma_next_desc_addr);
  232. void set_dma_curr_desc_addr(unsigned int channel, unsigned long addr)
  233. {
  234. pr_debug("set_dma_curr_desc_addr() : BEGIN \n");
  235. dma_ch[channel].regs->curr_desc_ptr = addr;
  236. pr_debug("set_dma_curr_desc_addr() : END\n");
  237. }
  238. EXPORT_SYMBOL(set_dma_curr_desc_addr);
  239. void set_dma_x_count(unsigned int channel, unsigned short x_count)
  240. {
  241. dma_ch[channel].regs->x_count = x_count;
  242. }
  243. EXPORT_SYMBOL(set_dma_x_count);
  244. void set_dma_y_count(unsigned int channel, unsigned short y_count)
  245. {
  246. dma_ch[channel].regs->y_count = y_count;
  247. }
  248. EXPORT_SYMBOL(set_dma_y_count);
  249. void set_dma_x_modify(unsigned int channel, short x_modify)
  250. {
  251. dma_ch[channel].regs->x_modify = x_modify;
  252. }
  253. EXPORT_SYMBOL(set_dma_x_modify);
  254. void set_dma_y_modify(unsigned int channel, short y_modify)
  255. {
  256. dma_ch[channel].regs->y_modify = y_modify;
  257. }
  258. EXPORT_SYMBOL(set_dma_y_modify);
  259. void set_dma_config(unsigned int channel, unsigned short config)
  260. {
  261. dma_ch[channel].regs->cfg = config;
  262. }
  263. EXPORT_SYMBOL(set_dma_config);
  264. unsigned short
  265. set_bfin_dma_config(char direction, char flow_mode,
  266. char intr_mode, char dma_mode, char width, char syncmode)
  267. {
  268. unsigned short config;
  269. config =
  270. ((direction << 1) | (width << 2) | (dma_mode << 4) |
  271. (intr_mode << 6) | (flow_mode << 12) | (syncmode << 5));
  272. return config;
  273. }
  274. EXPORT_SYMBOL(set_bfin_dma_config);
  275. void set_dma_sg(unsigned int channel, struct dmasg *sg, int nr_sg)
  276. {
  277. dma_ch[channel].regs->cfg |= ((nr_sg & 0x0F) << 8);
  278. dma_ch[channel].regs->next_desc_ptr = (unsigned int)sg;
  279. }
  280. EXPORT_SYMBOL(set_dma_sg);
  281. void set_dma_curr_addr(unsigned int channel, unsigned long addr)
  282. {
  283. dma_ch[channel].regs->curr_addr_ptr = addr;
  284. }
  285. EXPORT_SYMBOL(set_dma_curr_addr);
  286. /*------------------------------------------------------------------------------
  287. * Get the DMA status of a specific DMA channel from the system.
  288. *-----------------------------------------------------------------------------*/
  289. unsigned short get_dma_curr_irqstat(unsigned int channel)
  290. {
  291. return dma_ch[channel].regs->irq_status;
  292. }
  293. EXPORT_SYMBOL(get_dma_curr_irqstat);
  294. /*------------------------------------------------------------------------------
  295. * Clear the DMA_DONE bit in DMA status. Stop the DMA completion interrupt.
  296. *-----------------------------------------------------------------------------*/
  297. void clear_dma_irqstat(unsigned int channel)
  298. {
  299. dma_ch[channel].regs->irq_status |= 3;
  300. }
  301. EXPORT_SYMBOL(clear_dma_irqstat);
  302. /*------------------------------------------------------------------------------
  303. * Get current DMA xcount of a specific DMA channel from the system.
  304. *-----------------------------------------------------------------------------*/
  305. unsigned short get_dma_curr_xcount(unsigned int channel)
  306. {
  307. return dma_ch[channel].regs->curr_x_count;
  308. }
  309. EXPORT_SYMBOL(get_dma_curr_xcount);
  310. /*------------------------------------------------------------------------------
  311. * Get current DMA ycount of a specific DMA channel from the system.
  312. *-----------------------------------------------------------------------------*/
  313. unsigned short get_dma_curr_ycount(unsigned int channel)
  314. {
  315. return dma_ch[channel].regs->curr_y_count;
  316. }
  317. EXPORT_SYMBOL(get_dma_curr_ycount);
  318. unsigned long get_dma_next_desc_ptr(unsigned int channel)
  319. {
  320. return dma_ch[channel].regs->next_desc_ptr;
  321. }
  322. EXPORT_SYMBOL(get_dma_next_desc_ptr);
  323. unsigned long get_dma_curr_desc_ptr(unsigned int channel)
  324. {
  325. return dma_ch[channel].regs->curr_desc_ptr;
  326. }
  327. EXPORT_SYMBOL(get_dma_curr_desc_ptr);
  328. unsigned long get_dma_curr_addr(unsigned int channel)
  329. {
  330. return dma_ch[channel].regs->curr_addr_ptr;
  331. }
  332. EXPORT_SYMBOL(get_dma_curr_addr);
  333. #ifdef CONFIG_PM
  334. # ifndef MAX_DMA_SUSPEND_CHANNELS
  335. # define MAX_DMA_SUSPEND_CHANNELS MAX_DMA_CHANNELS
  336. # endif
  337. int blackfin_dma_suspend(void)
  338. {
  339. int i;
  340. for (i = 0; i < MAX_DMA_SUSPEND_CHANNELS; ++i) {
  341. if (dma_ch[i].chan_status == DMA_CHANNEL_ENABLED) {
  342. printk(KERN_ERR "DMA Channel %d failed to suspend\n", i);
  343. return -EBUSY;
  344. }
  345. dma_ch[i].saved_peripheral_map = dma_ch[i].regs->peripheral_map;
  346. }
  347. return 0;
  348. }
  349. void blackfin_dma_resume(void)
  350. {
  351. int i;
  352. for (i = 0; i < MAX_DMA_SUSPEND_CHANNELS; ++i)
  353. dma_ch[i].regs->peripheral_map = dma_ch[i].saved_peripheral_map;
  354. }
  355. #endif
  356. /**
  357. * blackfin_dma_early_init - minimal DMA init
  358. *
  359. * Setup a few DMA registers so we can safely do DMA transfers early on in
  360. * the kernel booting process. Really this just means using dma_memcpy().
  361. */
  362. void __init blackfin_dma_early_init(void)
  363. {
  364. bfin_write_MDMA_S0_CONFIG(0);
  365. }
  366. /**
  367. * __dma_memcpy - program the MDMA registers
  368. *
  369. * Actually program MDMA0 and wait for the transfer to finish. Disable IRQs
  370. * while programming registers so that everything is fully configured. Wait
  371. * for DMA to finish with IRQs enabled. If interrupted, the initial DMA_DONE
  372. * check will make sure we don't clobber any existing transfer.
  373. */
  374. static void __dma_memcpy(u32 daddr, s16 dmod, u32 saddr, s16 smod, size_t cnt, u32 conf)
  375. {
  376. static DEFINE_SPINLOCK(mdma_lock);
  377. unsigned long flags;
  378. spin_lock_irqsave(&mdma_lock, flags);
  379. if (bfin_read_MDMA_S0_CONFIG())
  380. while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE))
  381. continue;
  382. if (conf & DMA2D) {
  383. /* For larger bit sizes, we've already divided down cnt so it
  384. * is no longer a multiple of 64k. So we have to break down
  385. * the limit here so it is a multiple of the incoming size.
  386. * There is no limitation here in terms of total size other
  387. * than the hardware though as the bits lost in the shift are
  388. * made up by MODIFY (== we can hit the whole address space).
  389. * X: (2^(16 - 0)) * 1 == (2^(16 - 1)) * 2 == (2^(16 - 2)) * 4
  390. */
  391. u32 shift = abs(dmod) >> 1;
  392. size_t ycnt = cnt >> (16 - shift);
  393. cnt = 1 << (16 - shift);
  394. bfin_write_MDMA_D0_Y_COUNT(ycnt);
  395. bfin_write_MDMA_S0_Y_COUNT(ycnt);
  396. bfin_write_MDMA_D0_Y_MODIFY(dmod);
  397. bfin_write_MDMA_S0_Y_MODIFY(smod);
  398. }
  399. bfin_write_MDMA_D0_START_ADDR(daddr);
  400. bfin_write_MDMA_D0_X_COUNT(cnt);
  401. bfin_write_MDMA_D0_X_MODIFY(dmod);
  402. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  403. bfin_write_MDMA_S0_START_ADDR(saddr);
  404. bfin_write_MDMA_S0_X_COUNT(cnt);
  405. bfin_write_MDMA_S0_X_MODIFY(smod);
  406. bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  407. bfin_write_MDMA_S0_CONFIG(DMAEN | conf);
  408. bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | conf);
  409. spin_unlock_irqrestore(&mdma_lock, flags);
  410. SSYNC();
  411. while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE))
  412. if (bfin_read_MDMA_S0_CONFIG())
  413. continue;
  414. else
  415. return;
  416. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  417. bfin_write_MDMA_S0_CONFIG(0);
  418. bfin_write_MDMA_D0_CONFIG(0);
  419. }
  420. /**
  421. * _dma_memcpy - translate C memcpy settings into MDMA settings
  422. *
  423. * Handle all the high level steps before we touch the MDMA registers. So
  424. * handle caching, tweaking of sizes, and formatting of addresses.
  425. */
  426. static void *_dma_memcpy(void *pdst, const void *psrc, size_t size)
  427. {
  428. u32 conf, shift;
  429. s16 mod;
  430. unsigned long dst = (unsigned long)pdst;
  431. unsigned long src = (unsigned long)psrc;
  432. if (size == 0)
  433. return NULL;
  434. if (bfin_addr_dcachable(src))
  435. blackfin_dcache_flush_range(src, src + size);
  436. if (bfin_addr_dcachable(dst))
  437. blackfin_dcache_invalidate_range(dst, dst + size);
  438. if (dst % 4 == 0 && src % 4 == 0 && size % 4 == 0) {
  439. conf = WDSIZE_32;
  440. shift = 2;
  441. } else if (dst % 2 == 0 && src % 2 == 0 && size % 2 == 0) {
  442. conf = WDSIZE_16;
  443. shift = 1;
  444. } else {
  445. conf = WDSIZE_8;
  446. shift = 0;
  447. }
  448. /* If the two memory regions have a chance of overlapping, make
  449. * sure the memcpy still works as expected. Do this by having the
  450. * copy run backwards instead.
  451. */
  452. mod = 1 << shift;
  453. if (src < dst) {
  454. mod *= -1;
  455. dst += size + mod;
  456. src += size + mod;
  457. }
  458. size >>= shift;
  459. if (size > 0x10000)
  460. conf |= DMA2D;
  461. __dma_memcpy(dst, mod, src, mod, size, conf);
  462. return pdst;
  463. }
  464. /**
  465. * dma_memcpy - DMA memcpy under mutex lock
  466. *
  467. * Do not check arguments before starting the DMA memcpy. Break the transfer
  468. * up into two pieces. The first transfer is in multiples of 64k and the
  469. * second transfer is the piece smaller than 64k.
  470. */
  471. void *dma_memcpy(void *dst, const void *src, size_t size)
  472. {
  473. size_t bulk, rest;
  474. bulk = size & ~0xffff;
  475. rest = size - bulk;
  476. if (bulk)
  477. _dma_memcpy(dst, src, bulk);
  478. _dma_memcpy(dst + bulk, src + bulk, rest);
  479. return dst;
  480. }
  481. EXPORT_SYMBOL(dma_memcpy);
  482. /**
  483. * safe_dma_memcpy - DMA memcpy w/argument checking
  484. *
  485. * Verify arguments are safe before heading to dma_memcpy().
  486. */
  487. void *safe_dma_memcpy(void *dst, const void *src, size_t size)
  488. {
  489. if (!access_ok(VERIFY_WRITE, dst, size))
  490. return NULL;
  491. if (!access_ok(VERIFY_READ, src, size))
  492. return NULL;
  493. return dma_memcpy(dst, src, size);
  494. }
  495. EXPORT_SYMBOL(safe_dma_memcpy);
  496. static void _dma_out(unsigned long addr, unsigned long buf, unsigned short len,
  497. u16 size, u16 dma_size)
  498. {
  499. blackfin_dcache_flush_range(buf, buf + len * size);
  500. __dma_memcpy(addr, 0, buf, size, len, dma_size);
  501. }
  502. static void _dma_in(unsigned long addr, unsigned long buf, unsigned short len,
  503. u16 size, u16 dma_size)
  504. {
  505. blackfin_dcache_invalidate_range(buf, buf + len * size);
  506. __dma_memcpy(buf, size, addr, 0, len, dma_size);
  507. }
  508. #define MAKE_DMA_IO(io, bwl, isize, dmasize, cnst) \
  509. void dma_##io##s##bwl(unsigned long addr, cnst void *buf, unsigned short len) \
  510. { \
  511. _dma_##io(addr, (unsigned long)buf, len, isize, WDSIZE_##dmasize); \
  512. } \
  513. EXPORT_SYMBOL(dma_##io##s##bwl)
  514. MAKE_DMA_IO(out, b, 1, 8, const);
  515. MAKE_DMA_IO(in, b, 1, 8, );
  516. MAKE_DMA_IO(out, w, 2, 16, const);
  517. MAKE_DMA_IO(in, w, 2, 16, );
  518. MAKE_DMA_IO(out, l, 4, 32, const);
  519. MAKE_DMA_IO(in, l, 4, 32, );