bfin_dma_5xx.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. /*
  2. * File: arch/blackfin/kernel/bfin_dma_5xx.c
  3. * Based on:
  4. * Author:
  5. *
  6. * Created:
  7. * Description: This file contains the simple DMA Implementation for Blackfin
  8. *
  9. * Modified:
  10. * Copyright 2004-2006 Analog Devices Inc.
  11. *
  12. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, see the file COPYING, or write
  26. * to the Free Software Foundation, Inc.,
  27. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  28. */
  29. #include <linux/errno.h>
  30. #include <linux/module.h>
  31. #include <linux/proc_fs.h>
  32. #include <linux/sched.h>
  33. #include <linux/seq_file.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/kernel.h>
  36. #include <linux/param.h>
  37. #include <asm/blackfin.h>
  38. #include <asm/dma.h>
  39. #include <asm/cacheflush.h>
  40. /**************************************************************************
  41. * Global Variables
  42. ***************************************************************************/
  43. static struct dma_channel dma_ch[MAX_BLACKFIN_DMA_CHANNEL];
  44. /*------------------------------------------------------------------------------
  45. * Set the Buffer Clear bit in the Configuration register of specific DMA
  46. * channel. This will stop the descriptor based DMA operation.
  47. *-----------------------------------------------------------------------------*/
  48. static void clear_dma_buffer(unsigned int channel)
  49. {
  50. dma_ch[channel].regs->cfg |= RESTART;
  51. SSYNC();
  52. dma_ch[channel].regs->cfg &= ~RESTART;
  53. }
  54. static int __init blackfin_dma_init(void)
  55. {
  56. int i;
  57. printk(KERN_INFO "Blackfin DMA Controller\n");
  58. for (i = 0; i < MAX_BLACKFIN_DMA_CHANNEL; i++) {
  59. dma_ch[i].chan_status = DMA_CHANNEL_FREE;
  60. dma_ch[i].regs = dma_io_base_addr[i];
  61. mutex_init(&(dma_ch[i].dmalock));
  62. }
  63. /* Mark MEMDMA Channel 0 as requested since we're using it internally */
  64. request_dma(CH_MEM_STREAM0_DEST, "Blackfin dma_memcpy");
  65. request_dma(CH_MEM_STREAM0_SRC, "Blackfin dma_memcpy");
  66. #if defined(CONFIG_DEB_DMA_URGENT)
  67. bfin_write_EBIU_DDRQUE(bfin_read_EBIU_DDRQUE()
  68. | DEB1_URGENT | DEB2_URGENT | DEB3_URGENT);
  69. #endif
  70. return 0;
  71. }
  72. arch_initcall(blackfin_dma_init);
  73. #ifdef CONFIG_PROC_FS
  74. static int proc_dma_show(struct seq_file *m, void *v)
  75. {
  76. int i;
  77. for (i = 0 ; i < MAX_BLACKFIN_DMA_CHANNEL; ++i)
  78. if (dma_ch[i].chan_status != DMA_CHANNEL_FREE)
  79. seq_printf(m, "%2d: %s\n", i, dma_ch[i].device_id);
  80. return 0;
  81. }
  82. static int proc_dma_open(struct inode *inode, struct file *file)
  83. {
  84. return single_open(file, proc_dma_show, NULL);
  85. }
  86. static const struct file_operations proc_dma_operations = {
  87. .open = proc_dma_open,
  88. .read = seq_read,
  89. .llseek = seq_lseek,
  90. .release = single_release,
  91. };
  92. static int __init proc_dma_init(void)
  93. {
  94. return proc_create("dma", 0, NULL, &proc_dma_operations) != NULL;
  95. }
  96. late_initcall(proc_dma_init);
  97. #endif
  98. /*------------------------------------------------------------------------------
  99. * Request the specific DMA channel from the system.
  100. *-----------------------------------------------------------------------------*/
  101. int request_dma(unsigned int channel, char *device_id)
  102. {
  103. pr_debug("request_dma() : BEGIN \n");
  104. if (device_id == NULL)
  105. printk(KERN_WARNING "request_dma(%u): no device_id given\n", channel);
  106. #if defined(CONFIG_BF561) && ANOMALY_05000182
  107. if (channel >= CH_IMEM_STREAM0_DEST && channel <= CH_IMEM_STREAM1_DEST) {
  108. if (get_cclk() > 500000000) {
  109. printk(KERN_WARNING
  110. "Request IMDMA failed due to ANOMALY 05000182\n");
  111. return -EFAULT;
  112. }
  113. }
  114. #endif
  115. mutex_lock(&(dma_ch[channel].dmalock));
  116. if ((dma_ch[channel].chan_status == DMA_CHANNEL_REQUESTED)
  117. || (dma_ch[channel].chan_status == DMA_CHANNEL_ENABLED)) {
  118. mutex_unlock(&(dma_ch[channel].dmalock));
  119. pr_debug("DMA CHANNEL IN USE \n");
  120. return -EBUSY;
  121. } else {
  122. dma_ch[channel].chan_status = DMA_CHANNEL_REQUESTED;
  123. pr_debug("DMA CHANNEL IS ALLOCATED \n");
  124. }
  125. mutex_unlock(&(dma_ch[channel].dmalock));
  126. #ifdef CONFIG_BF54x
  127. if (channel >= CH_UART2_RX && channel <= CH_UART3_TX) {
  128. unsigned int per_map;
  129. per_map = dma_ch[channel].regs->peripheral_map & 0xFFF;
  130. if (strncmp(device_id, "BFIN_UART", 9) == 0)
  131. dma_ch[channel].regs->peripheral_map = per_map |
  132. ((channel - CH_UART2_RX + 0xC)<<12);
  133. else
  134. dma_ch[channel].regs->peripheral_map = per_map |
  135. ((channel - CH_UART2_RX + 0x6)<<12);
  136. }
  137. #endif
  138. dma_ch[channel].device_id = device_id;
  139. dma_ch[channel].irq_callback = NULL;
  140. /* This is to be enabled by putting a restriction -
  141. * you have to request DMA, before doing any operations on
  142. * descriptor/channel
  143. */
  144. pr_debug("request_dma() : END \n");
  145. return channel;
  146. }
  147. EXPORT_SYMBOL(request_dma);
  148. int set_dma_callback(unsigned int channel, dma_interrupt_t callback, void *data)
  149. {
  150. BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
  151. && channel < MAX_BLACKFIN_DMA_CHANNEL));
  152. if (callback != NULL) {
  153. int ret_val;
  154. dma_ch[channel].irq = channel2irq(channel);
  155. dma_ch[channel].data = data;
  156. ret_val =
  157. request_irq(dma_ch[channel].irq, callback, IRQF_DISABLED,
  158. dma_ch[channel].device_id, data);
  159. if (ret_val) {
  160. printk(KERN_NOTICE
  161. "Request irq in DMA engine failed.\n");
  162. return -EPERM;
  163. }
  164. dma_ch[channel].irq_callback = callback;
  165. }
  166. return 0;
  167. }
  168. EXPORT_SYMBOL(set_dma_callback);
  169. void free_dma(unsigned int channel)
  170. {
  171. pr_debug("freedma() : BEGIN \n");
  172. BUG_ON(!(dma_ch[channel].chan_status != DMA_CHANNEL_FREE
  173. && channel < MAX_BLACKFIN_DMA_CHANNEL));
  174. /* Halt the DMA */
  175. disable_dma(channel);
  176. clear_dma_buffer(channel);
  177. if (dma_ch[channel].irq_callback != NULL)
  178. free_irq(dma_ch[channel].irq, dma_ch[channel].data);
  179. /* Clear the DMA Variable in the Channel */
  180. mutex_lock(&(dma_ch[channel].dmalock));
  181. dma_ch[channel].chan_status = DMA_CHANNEL_FREE;
  182. mutex_unlock(&(dma_ch[channel].dmalock));
  183. pr_debug("freedma() : END \n");
  184. }
  185. EXPORT_SYMBOL(free_dma);
  186. void dma_enable_irq(unsigned int channel)
  187. {
  188. pr_debug("dma_enable_irq() : BEGIN \n");
  189. enable_irq(dma_ch[channel].irq);
  190. }
  191. EXPORT_SYMBOL(dma_enable_irq);
  192. void dma_disable_irq(unsigned int channel)
  193. {
  194. pr_debug("dma_disable_irq() : BEGIN \n");
  195. disable_irq(dma_ch[channel].irq);
  196. }
  197. EXPORT_SYMBOL(dma_disable_irq);
  198. int dma_channel_active(unsigned int channel)
  199. {
  200. if (dma_ch[channel].chan_status == DMA_CHANNEL_FREE) {
  201. return 0;
  202. } else {
  203. return 1;
  204. }
  205. }
  206. EXPORT_SYMBOL(dma_channel_active);
  207. /*------------------------------------------------------------------------------
  208. * stop the specific DMA channel.
  209. *-----------------------------------------------------------------------------*/
  210. void disable_dma(unsigned int channel)
  211. {
  212. pr_debug("stop_dma() : BEGIN \n");
  213. dma_ch[channel].regs->cfg &= ~DMAEN; /* Clean the enable bit */
  214. SSYNC();
  215. dma_ch[channel].chan_status = DMA_CHANNEL_REQUESTED;
  216. /* Needs to be enabled Later */
  217. pr_debug("stop_dma() : END \n");
  218. return;
  219. }
  220. EXPORT_SYMBOL(disable_dma);
  221. void enable_dma(unsigned int channel)
  222. {
  223. pr_debug("enable_dma() : BEGIN \n");
  224. dma_ch[channel].chan_status = DMA_CHANNEL_ENABLED;
  225. dma_ch[channel].regs->curr_x_count = 0;
  226. dma_ch[channel].regs->curr_y_count = 0;
  227. dma_ch[channel].regs->cfg |= DMAEN; /* Set the enable bit */
  228. pr_debug("enable_dma() : END \n");
  229. return;
  230. }
  231. EXPORT_SYMBOL(enable_dma);
  232. /*------------------------------------------------------------------------------
  233. * Set the Start Address register for the specific DMA channel
  234. * This function can be used for register based DMA,
  235. * to setup the start address
  236. * addr: Starting address of the DMA Data to be transferred.
  237. *-----------------------------------------------------------------------------*/
  238. void set_dma_start_addr(unsigned int channel, unsigned long addr)
  239. {
  240. pr_debug("set_dma_start_addr() : BEGIN \n");
  241. dma_ch[channel].regs->start_addr = addr;
  242. pr_debug("set_dma_start_addr() : END\n");
  243. }
  244. EXPORT_SYMBOL(set_dma_start_addr);
  245. void set_dma_next_desc_addr(unsigned int channel, unsigned long addr)
  246. {
  247. pr_debug("set_dma_next_desc_addr() : BEGIN \n");
  248. dma_ch[channel].regs->next_desc_ptr = addr;
  249. pr_debug("set_dma_next_desc_addr() : END\n");
  250. }
  251. EXPORT_SYMBOL(set_dma_next_desc_addr);
  252. void set_dma_curr_desc_addr(unsigned int channel, unsigned long addr)
  253. {
  254. pr_debug("set_dma_curr_desc_addr() : BEGIN \n");
  255. dma_ch[channel].regs->curr_desc_ptr = addr;
  256. pr_debug("set_dma_curr_desc_addr() : END\n");
  257. }
  258. EXPORT_SYMBOL(set_dma_curr_desc_addr);
  259. void set_dma_x_count(unsigned int channel, unsigned short x_count)
  260. {
  261. dma_ch[channel].regs->x_count = x_count;
  262. }
  263. EXPORT_SYMBOL(set_dma_x_count);
  264. void set_dma_y_count(unsigned int channel, unsigned short y_count)
  265. {
  266. dma_ch[channel].regs->y_count = y_count;
  267. }
  268. EXPORT_SYMBOL(set_dma_y_count);
  269. void set_dma_x_modify(unsigned int channel, short x_modify)
  270. {
  271. dma_ch[channel].regs->x_modify = x_modify;
  272. }
  273. EXPORT_SYMBOL(set_dma_x_modify);
  274. void set_dma_y_modify(unsigned int channel, short y_modify)
  275. {
  276. dma_ch[channel].regs->y_modify = y_modify;
  277. }
  278. EXPORT_SYMBOL(set_dma_y_modify);
  279. void set_dma_config(unsigned int channel, unsigned short config)
  280. {
  281. dma_ch[channel].regs->cfg = config;
  282. }
  283. EXPORT_SYMBOL(set_dma_config);
  284. unsigned short
  285. set_bfin_dma_config(char direction, char flow_mode,
  286. char intr_mode, char dma_mode, char width, char syncmode)
  287. {
  288. unsigned short config;
  289. config =
  290. ((direction << 1) | (width << 2) | (dma_mode << 4) |
  291. (intr_mode << 6) | (flow_mode << 12) | (syncmode << 5));
  292. return config;
  293. }
  294. EXPORT_SYMBOL(set_bfin_dma_config);
  295. void set_dma_sg(unsigned int channel, struct dmasg *sg, int nr_sg)
  296. {
  297. dma_ch[channel].regs->cfg |= ((nr_sg & 0x0F) << 8);
  298. dma_ch[channel].regs->next_desc_ptr = (unsigned int)sg;
  299. }
  300. EXPORT_SYMBOL(set_dma_sg);
  301. void set_dma_curr_addr(unsigned int channel, unsigned long addr)
  302. {
  303. dma_ch[channel].regs->curr_addr_ptr = addr;
  304. }
  305. EXPORT_SYMBOL(set_dma_curr_addr);
  306. /*------------------------------------------------------------------------------
  307. * Get the DMA status of a specific DMA channel from the system.
  308. *-----------------------------------------------------------------------------*/
  309. unsigned short get_dma_curr_irqstat(unsigned int channel)
  310. {
  311. return dma_ch[channel].regs->irq_status;
  312. }
  313. EXPORT_SYMBOL(get_dma_curr_irqstat);
  314. /*------------------------------------------------------------------------------
  315. * Clear the DMA_DONE bit in DMA status. Stop the DMA completion interrupt.
  316. *-----------------------------------------------------------------------------*/
  317. void clear_dma_irqstat(unsigned int channel)
  318. {
  319. dma_ch[channel].regs->irq_status |= 3;
  320. }
  321. EXPORT_SYMBOL(clear_dma_irqstat);
  322. /*------------------------------------------------------------------------------
  323. * Get current DMA xcount of a specific DMA channel from the system.
  324. *-----------------------------------------------------------------------------*/
  325. unsigned short get_dma_curr_xcount(unsigned int channel)
  326. {
  327. return dma_ch[channel].regs->curr_x_count;
  328. }
  329. EXPORT_SYMBOL(get_dma_curr_xcount);
  330. /*------------------------------------------------------------------------------
  331. * Get current DMA ycount of a specific DMA channel from the system.
  332. *-----------------------------------------------------------------------------*/
  333. unsigned short get_dma_curr_ycount(unsigned int channel)
  334. {
  335. return dma_ch[channel].regs->curr_y_count;
  336. }
  337. EXPORT_SYMBOL(get_dma_curr_ycount);
  338. unsigned long get_dma_next_desc_ptr(unsigned int channel)
  339. {
  340. return dma_ch[channel].regs->next_desc_ptr;
  341. }
  342. EXPORT_SYMBOL(get_dma_next_desc_ptr);
  343. unsigned long get_dma_curr_desc_ptr(unsigned int channel)
  344. {
  345. return dma_ch[channel].regs->curr_desc_ptr;
  346. }
  347. EXPORT_SYMBOL(get_dma_curr_desc_ptr);
  348. unsigned long get_dma_curr_addr(unsigned int channel)
  349. {
  350. return dma_ch[channel].regs->curr_addr_ptr;
  351. }
  352. EXPORT_SYMBOL(get_dma_curr_addr);
  353. #ifdef CONFIG_PM
  354. int blackfin_dma_suspend(void)
  355. {
  356. int i;
  357. #ifdef CONFIG_BF561 /* IMDMA channels doesn't have a PERIPHERAL_MAP */
  358. for (i = 0; i <= CH_MEM_STREAM3_SRC; i++) {
  359. #else
  360. for (i = 0; i < MAX_BLACKFIN_DMA_CHANNEL; i++) {
  361. #endif
  362. if (dma_ch[i].chan_status == DMA_CHANNEL_ENABLED) {
  363. printk(KERN_ERR "DMA Channel %d failed to suspend\n", i);
  364. return -EBUSY;
  365. }
  366. dma_ch[i].saved_peripheral_map = dma_ch[i].regs->peripheral_map;
  367. }
  368. return 0;
  369. }
  370. void blackfin_dma_resume(void)
  371. {
  372. int i;
  373. #ifdef CONFIG_BF561 /* IMDMA channels doesn't have a PERIPHERAL_MAP */
  374. for (i = 0; i <= CH_MEM_STREAM3_SRC; i++)
  375. #else
  376. for (i = 0; i < MAX_BLACKFIN_DMA_CHANNEL; i++)
  377. #endif
  378. dma_ch[i].regs->peripheral_map = dma_ch[i].saved_peripheral_map;
  379. }
  380. #endif
  381. static void *__dma_memcpy(void *dest, const void *src, size_t size)
  382. {
  383. int direction; /* 1 - address decrease, 0 - address increase */
  384. int flag_align; /* 1 - address aligned, 0 - address unaligned */
  385. int flag_2D; /* 1 - 2D DMA needed, 0 - 1D DMA needed */
  386. unsigned long flags;
  387. if (size <= 0)
  388. return NULL;
  389. local_irq_save(flags);
  390. if ((unsigned long)src < memory_end)
  391. blackfin_dcache_flush_range((unsigned int)src,
  392. (unsigned int)(src + size));
  393. if ((unsigned long)dest < memory_end)
  394. blackfin_dcache_invalidate_range((unsigned int)dest,
  395. (unsigned int)(dest + size));
  396. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  397. if ((unsigned long)src < (unsigned long)dest)
  398. direction = 1;
  399. else
  400. direction = 0;
  401. if ((((unsigned long)dest % 2) == 0) && (((unsigned long)src % 2) == 0)
  402. && ((size % 2) == 0))
  403. flag_align = 1;
  404. else
  405. flag_align = 0;
  406. if (size > 0x10000) /* size > 64K */
  407. flag_2D = 1;
  408. else
  409. flag_2D = 0;
  410. /* Setup destination and source start address */
  411. if (direction) {
  412. if (flag_align) {
  413. bfin_write_MDMA_D0_START_ADDR(dest + size - 2);
  414. bfin_write_MDMA_S0_START_ADDR(src + size - 2);
  415. } else {
  416. bfin_write_MDMA_D0_START_ADDR(dest + size - 1);
  417. bfin_write_MDMA_S0_START_ADDR(src + size - 1);
  418. }
  419. } else {
  420. bfin_write_MDMA_D0_START_ADDR(dest);
  421. bfin_write_MDMA_S0_START_ADDR(src);
  422. }
  423. /* Setup destination and source xcount */
  424. if (flag_2D) {
  425. if (flag_align) {
  426. bfin_write_MDMA_D0_X_COUNT(1024 / 2);
  427. bfin_write_MDMA_S0_X_COUNT(1024 / 2);
  428. } else {
  429. bfin_write_MDMA_D0_X_COUNT(1024);
  430. bfin_write_MDMA_S0_X_COUNT(1024);
  431. }
  432. bfin_write_MDMA_D0_Y_COUNT(size >> 10);
  433. bfin_write_MDMA_S0_Y_COUNT(size >> 10);
  434. } else {
  435. if (flag_align) {
  436. bfin_write_MDMA_D0_X_COUNT(size / 2);
  437. bfin_write_MDMA_S0_X_COUNT(size / 2);
  438. } else {
  439. bfin_write_MDMA_D0_X_COUNT(size);
  440. bfin_write_MDMA_S0_X_COUNT(size);
  441. }
  442. }
  443. /* Setup destination and source xmodify and ymodify */
  444. if (direction) {
  445. if (flag_align) {
  446. bfin_write_MDMA_D0_X_MODIFY(-2);
  447. bfin_write_MDMA_S0_X_MODIFY(-2);
  448. if (flag_2D) {
  449. bfin_write_MDMA_D0_Y_MODIFY(-2);
  450. bfin_write_MDMA_S0_Y_MODIFY(-2);
  451. }
  452. } else {
  453. bfin_write_MDMA_D0_X_MODIFY(-1);
  454. bfin_write_MDMA_S0_X_MODIFY(-1);
  455. if (flag_2D) {
  456. bfin_write_MDMA_D0_Y_MODIFY(-1);
  457. bfin_write_MDMA_S0_Y_MODIFY(-1);
  458. }
  459. }
  460. } else {
  461. if (flag_align) {
  462. bfin_write_MDMA_D0_X_MODIFY(2);
  463. bfin_write_MDMA_S0_X_MODIFY(2);
  464. if (flag_2D) {
  465. bfin_write_MDMA_D0_Y_MODIFY(2);
  466. bfin_write_MDMA_S0_Y_MODIFY(2);
  467. }
  468. } else {
  469. bfin_write_MDMA_D0_X_MODIFY(1);
  470. bfin_write_MDMA_S0_X_MODIFY(1);
  471. if (flag_2D) {
  472. bfin_write_MDMA_D0_Y_MODIFY(1);
  473. bfin_write_MDMA_S0_Y_MODIFY(1);
  474. }
  475. }
  476. }
  477. /* Enable source DMA */
  478. if (flag_2D) {
  479. if (flag_align) {
  480. bfin_write_MDMA_S0_CONFIG(DMAEN | DMA2D | WDSIZE_16);
  481. bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | DMA2D | WDSIZE_16);
  482. } else {
  483. bfin_write_MDMA_S0_CONFIG(DMAEN | DMA2D);
  484. bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | DMA2D);
  485. }
  486. } else {
  487. if (flag_align) {
  488. bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16);
  489. bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16);
  490. } else {
  491. bfin_write_MDMA_S0_CONFIG(DMAEN);
  492. bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN);
  493. }
  494. }
  495. SSYNC();
  496. while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE))
  497. ;
  498. bfin_write_MDMA_D0_IRQ_STATUS(bfin_read_MDMA_D0_IRQ_STATUS() |
  499. (DMA_DONE | DMA_ERR));
  500. bfin_write_MDMA_S0_CONFIG(0);
  501. bfin_write_MDMA_D0_CONFIG(0);
  502. local_irq_restore(flags);
  503. return dest;
  504. }
  505. void *dma_memcpy(void *dest, const void *src, size_t size)
  506. {
  507. size_t bulk;
  508. size_t rest;
  509. void * addr;
  510. bulk = (size >> 16) << 16;
  511. rest = size - bulk;
  512. if (bulk)
  513. __dma_memcpy(dest, src, bulk);
  514. addr = __dma_memcpy(dest+bulk, src+bulk, rest);
  515. return addr;
  516. }
  517. EXPORT_SYMBOL(dma_memcpy);
  518. void *safe_dma_memcpy(void *dest, const void *src, size_t size)
  519. {
  520. void *addr;
  521. addr = dma_memcpy(dest, src, size);
  522. return addr;
  523. }
  524. EXPORT_SYMBOL(safe_dma_memcpy);
  525. void dma_outsb(unsigned long addr, const void *buf, unsigned short len)
  526. {
  527. unsigned long flags;
  528. local_irq_save(flags);
  529. blackfin_dcache_flush_range((unsigned int)buf,
  530. (unsigned int)(buf) + len);
  531. bfin_write_MDMA_D0_START_ADDR(addr);
  532. bfin_write_MDMA_D0_X_COUNT(len);
  533. bfin_write_MDMA_D0_X_MODIFY(0);
  534. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  535. bfin_write_MDMA_S0_START_ADDR(buf);
  536. bfin_write_MDMA_S0_X_COUNT(len);
  537. bfin_write_MDMA_S0_X_MODIFY(1);
  538. bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  539. bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_8);
  540. bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_8);
  541. SSYNC();
  542. while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
  543. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  544. bfin_write_MDMA_S0_CONFIG(0);
  545. bfin_write_MDMA_D0_CONFIG(0);
  546. local_irq_restore(flags);
  547. }
  548. EXPORT_SYMBOL(dma_outsb);
  549. void dma_insb(unsigned long addr, void *buf, unsigned short len)
  550. {
  551. unsigned long flags;
  552. blackfin_dcache_invalidate_range((unsigned int)buf,
  553. (unsigned int)(buf) + len);
  554. local_irq_save(flags);
  555. bfin_write_MDMA_D0_START_ADDR(buf);
  556. bfin_write_MDMA_D0_X_COUNT(len);
  557. bfin_write_MDMA_D0_X_MODIFY(1);
  558. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  559. bfin_write_MDMA_S0_START_ADDR(addr);
  560. bfin_write_MDMA_S0_X_COUNT(len);
  561. bfin_write_MDMA_S0_X_MODIFY(0);
  562. bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  563. bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_8);
  564. bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_8);
  565. SSYNC();
  566. while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
  567. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  568. bfin_write_MDMA_S0_CONFIG(0);
  569. bfin_write_MDMA_D0_CONFIG(0);
  570. local_irq_restore(flags);
  571. }
  572. EXPORT_SYMBOL(dma_insb);
  573. void dma_outsw(unsigned long addr, const void *buf, unsigned short len)
  574. {
  575. unsigned long flags;
  576. local_irq_save(flags);
  577. blackfin_dcache_flush_range((unsigned int)buf,
  578. (unsigned int)(buf) + len * sizeof(short));
  579. bfin_write_MDMA_D0_START_ADDR(addr);
  580. bfin_write_MDMA_D0_X_COUNT(len);
  581. bfin_write_MDMA_D0_X_MODIFY(0);
  582. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  583. bfin_write_MDMA_S0_START_ADDR(buf);
  584. bfin_write_MDMA_S0_X_COUNT(len);
  585. bfin_write_MDMA_S0_X_MODIFY(2);
  586. bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  587. bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16);
  588. bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16);
  589. SSYNC();
  590. while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
  591. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  592. bfin_write_MDMA_S0_CONFIG(0);
  593. bfin_write_MDMA_D0_CONFIG(0);
  594. local_irq_restore(flags);
  595. }
  596. EXPORT_SYMBOL(dma_outsw);
  597. void dma_insw(unsigned long addr, void *buf, unsigned short len)
  598. {
  599. unsigned long flags;
  600. blackfin_dcache_invalidate_range((unsigned int)buf,
  601. (unsigned int)(buf) + len * sizeof(short));
  602. local_irq_save(flags);
  603. bfin_write_MDMA_D0_START_ADDR(buf);
  604. bfin_write_MDMA_D0_X_COUNT(len);
  605. bfin_write_MDMA_D0_X_MODIFY(2);
  606. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  607. bfin_write_MDMA_S0_START_ADDR(addr);
  608. bfin_write_MDMA_S0_X_COUNT(len);
  609. bfin_write_MDMA_S0_X_MODIFY(0);
  610. bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  611. bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_16);
  612. bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_16);
  613. SSYNC();
  614. while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
  615. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  616. bfin_write_MDMA_S0_CONFIG(0);
  617. bfin_write_MDMA_D0_CONFIG(0);
  618. local_irq_restore(flags);
  619. }
  620. EXPORT_SYMBOL(dma_insw);
  621. void dma_outsl(unsigned long addr, const void *buf, unsigned short len)
  622. {
  623. unsigned long flags;
  624. local_irq_save(flags);
  625. blackfin_dcache_flush_range((unsigned int)buf,
  626. (unsigned int)(buf) + len * sizeof(long));
  627. bfin_write_MDMA_D0_START_ADDR(addr);
  628. bfin_write_MDMA_D0_X_COUNT(len);
  629. bfin_write_MDMA_D0_X_MODIFY(0);
  630. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  631. bfin_write_MDMA_S0_START_ADDR(buf);
  632. bfin_write_MDMA_S0_X_COUNT(len);
  633. bfin_write_MDMA_S0_X_MODIFY(4);
  634. bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  635. bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_32);
  636. bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_32);
  637. SSYNC();
  638. while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
  639. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  640. bfin_write_MDMA_S0_CONFIG(0);
  641. bfin_write_MDMA_D0_CONFIG(0);
  642. local_irq_restore(flags);
  643. }
  644. EXPORT_SYMBOL(dma_outsl);
  645. void dma_insl(unsigned long addr, void *buf, unsigned short len)
  646. {
  647. unsigned long flags;
  648. blackfin_dcache_invalidate_range((unsigned int)buf,
  649. (unsigned int)(buf) + len * sizeof(long));
  650. local_irq_save(flags);
  651. bfin_write_MDMA_D0_START_ADDR(buf);
  652. bfin_write_MDMA_D0_X_COUNT(len);
  653. bfin_write_MDMA_D0_X_MODIFY(4);
  654. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  655. bfin_write_MDMA_S0_START_ADDR(addr);
  656. bfin_write_MDMA_S0_X_COUNT(len);
  657. bfin_write_MDMA_S0_X_MODIFY(0);
  658. bfin_write_MDMA_S0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  659. bfin_write_MDMA_S0_CONFIG(DMAEN | WDSIZE_32);
  660. bfin_write_MDMA_D0_CONFIG(WNR | DI_EN | DMAEN | WDSIZE_32);
  661. SSYNC();
  662. while (!(bfin_read_MDMA_D0_IRQ_STATUS() & DMA_DONE));
  663. bfin_write_MDMA_D0_IRQ_STATUS(DMA_DONE | DMA_ERR);
  664. bfin_write_MDMA_S0_CONFIG(0);
  665. bfin_write_MDMA_D0_CONFIG(0);
  666. local_irq_restore(flags);
  667. }
  668. EXPORT_SYMBOL(dma_insl);