dma_lib.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  1. /*
  2. * Copyright (C) 2006-2007 PA Semi, Inc
  3. *
  4. * Common functions for DMA access on PA Semi PWRficient
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/init.h>
  21. #include <linux/module.h>
  22. #include <linux/pci.h>
  23. #include <linux/of.h>
  24. #include <asm/pasemi_dma.h>
  25. #define MAX_TXCH 64
  26. #define MAX_RXCH 64
  27. #define MAX_FLAGS 64
  28. #define MAX_FUN 8
  29. static struct pasdma_status *dma_status;
  30. static void __iomem *iob_regs;
  31. static void __iomem *mac_regs[6];
  32. static void __iomem *dma_regs;
  33. static int base_hw_irq;
  34. static int num_txch, num_rxch;
  35. static struct pci_dev *dma_pdev;
  36. /* Bitmaps to handle allocation of channels */
  37. static DECLARE_BITMAP(txch_free, MAX_TXCH);
  38. static DECLARE_BITMAP(rxch_free, MAX_RXCH);
  39. static DECLARE_BITMAP(flags_free, MAX_FLAGS);
  40. static DECLARE_BITMAP(fun_free, MAX_FUN);
  41. /* pasemi_read_iob_reg - read IOB register
  42. * @reg: Register to read (offset into PCI CFG space)
  43. */
  44. unsigned int pasemi_read_iob_reg(unsigned int reg)
  45. {
  46. return in_le32(iob_regs+reg);
  47. }
  48. EXPORT_SYMBOL(pasemi_read_iob_reg);
  49. /* pasemi_write_iob_reg - write IOB register
  50. * @reg: Register to write to (offset into PCI CFG space)
  51. * @val: Value to write
  52. */
  53. void pasemi_write_iob_reg(unsigned int reg, unsigned int val)
  54. {
  55. out_le32(iob_regs+reg, val);
  56. }
  57. EXPORT_SYMBOL(pasemi_write_iob_reg);
  58. /* pasemi_read_mac_reg - read MAC register
  59. * @intf: MAC interface
  60. * @reg: Register to read (offset into PCI CFG space)
  61. */
  62. unsigned int pasemi_read_mac_reg(int intf, unsigned int reg)
  63. {
  64. return in_le32(mac_regs[intf]+reg);
  65. }
  66. EXPORT_SYMBOL(pasemi_read_mac_reg);
  67. /* pasemi_write_mac_reg - write MAC register
  68. * @intf: MAC interface
  69. * @reg: Register to write to (offset into PCI CFG space)
  70. * @val: Value to write
  71. */
  72. void pasemi_write_mac_reg(int intf, unsigned int reg, unsigned int val)
  73. {
  74. out_le32(mac_regs[intf]+reg, val);
  75. }
  76. EXPORT_SYMBOL(pasemi_write_mac_reg);
  77. /* pasemi_read_dma_reg - read DMA register
  78. * @reg: Register to read (offset into PCI CFG space)
  79. */
  80. unsigned int pasemi_read_dma_reg(unsigned int reg)
  81. {
  82. return in_le32(dma_regs+reg);
  83. }
  84. EXPORT_SYMBOL(pasemi_read_dma_reg);
  85. /* pasemi_write_dma_reg - write DMA register
  86. * @reg: Register to write to (offset into PCI CFG space)
  87. * @val: Value to write
  88. */
  89. void pasemi_write_dma_reg(unsigned int reg, unsigned int val)
  90. {
  91. out_le32(dma_regs+reg, val);
  92. }
  93. EXPORT_SYMBOL(pasemi_write_dma_reg);
  94. static int pasemi_alloc_tx_chan(enum pasemi_dmachan_type type)
  95. {
  96. int bit;
  97. int start, limit;
  98. switch (type & (TXCHAN_EVT0|TXCHAN_EVT1)) {
  99. case TXCHAN_EVT0:
  100. start = 0;
  101. limit = 10;
  102. break;
  103. case TXCHAN_EVT1:
  104. start = 10;
  105. limit = MAX_TXCH;
  106. break;
  107. default:
  108. start = 0;
  109. limit = MAX_TXCH;
  110. break;
  111. }
  112. retry:
  113. bit = find_next_bit(txch_free, MAX_TXCH, start);
  114. if (bit >= limit)
  115. return -ENOSPC;
  116. if (!test_and_clear_bit(bit, txch_free))
  117. goto retry;
  118. return bit;
  119. }
  120. static void pasemi_free_tx_chan(int chan)
  121. {
  122. BUG_ON(test_bit(chan, txch_free));
  123. set_bit(chan, txch_free);
  124. }
  125. static int pasemi_alloc_rx_chan(void)
  126. {
  127. int bit;
  128. retry:
  129. bit = find_first_bit(rxch_free, MAX_RXCH);
  130. if (bit >= MAX_TXCH)
  131. return -ENOSPC;
  132. if (!test_and_clear_bit(bit, rxch_free))
  133. goto retry;
  134. return bit;
  135. }
  136. static void pasemi_free_rx_chan(int chan)
  137. {
  138. BUG_ON(test_bit(chan, rxch_free));
  139. set_bit(chan, rxch_free);
  140. }
  141. /* pasemi_dma_alloc_chan - Allocate a DMA channel
  142. * @type: Type of channel to allocate
  143. * @total_size: Total size of structure to allocate (to allow for more
  144. * room behind the structure to be used by the client)
  145. * @offset: Offset in bytes from start of the total structure to the beginning
  146. * of struct pasemi_dmachan. Needed when struct pasemi_dmachan is
  147. * not the first member of the client structure.
  148. *
  149. * pasemi_dma_alloc_chan allocates a DMA channel for use by a client. The
  150. * type argument specifies whether it's a RX or TX channel, and in the case
  151. * of TX channels which group it needs to belong to (if any).
  152. *
  153. * Returns a pointer to the total structure allocated on success, NULL
  154. * on failure.
  155. */
  156. void *pasemi_dma_alloc_chan(enum pasemi_dmachan_type type,
  157. int total_size, int offset)
  158. {
  159. void *buf;
  160. struct pasemi_dmachan *chan;
  161. int chno;
  162. BUG_ON(total_size < sizeof(struct pasemi_dmachan));
  163. buf = kzalloc(total_size, GFP_KERNEL);
  164. if (!buf)
  165. return NULL;
  166. chan = buf + offset;
  167. chan->priv = buf;
  168. switch (type & (TXCHAN|RXCHAN)) {
  169. case RXCHAN:
  170. chno = pasemi_alloc_rx_chan();
  171. chan->chno = chno;
  172. chan->irq = irq_create_mapping(NULL,
  173. base_hw_irq + num_txch + chno);
  174. chan->status = &dma_status->rx_sta[chno];
  175. break;
  176. case TXCHAN:
  177. chno = pasemi_alloc_tx_chan(type);
  178. chan->chno = chno;
  179. chan->irq = irq_create_mapping(NULL, base_hw_irq + chno);
  180. chan->status = &dma_status->tx_sta[chno];
  181. break;
  182. }
  183. chan->chan_type = type;
  184. return chan;
  185. }
  186. EXPORT_SYMBOL(pasemi_dma_alloc_chan);
  187. /* pasemi_dma_free_chan - Free a previously allocated channel
  188. * @chan: Channel to free
  189. *
  190. * Frees a previously allocated channel. It will also deallocate any
  191. * descriptor ring associated with the channel, if allocated.
  192. */
  193. void pasemi_dma_free_chan(struct pasemi_dmachan *chan)
  194. {
  195. if (chan->ring_virt)
  196. pasemi_dma_free_ring(chan);
  197. switch (chan->chan_type & (RXCHAN|TXCHAN)) {
  198. case RXCHAN:
  199. pasemi_free_rx_chan(chan->chno);
  200. break;
  201. case TXCHAN:
  202. pasemi_free_tx_chan(chan->chno);
  203. break;
  204. }
  205. kfree(chan->priv);
  206. }
  207. EXPORT_SYMBOL(pasemi_dma_free_chan);
  208. /* pasemi_dma_alloc_ring - Allocate descriptor ring for a channel
  209. * @chan: Channel for which to allocate
  210. * @ring_size: Ring size in 64-bit (8-byte) words
  211. *
  212. * Allocate a descriptor ring for a channel. Returns 0 on success, errno
  213. * on failure. The passed in struct pasemi_dmachan is updated with the
  214. * virtual and DMA addresses of the ring.
  215. */
  216. int pasemi_dma_alloc_ring(struct pasemi_dmachan *chan, int ring_size)
  217. {
  218. BUG_ON(chan->ring_virt);
  219. chan->ring_size = ring_size;
  220. chan->ring_virt = dma_alloc_coherent(&dma_pdev->dev,
  221. ring_size * sizeof(u64),
  222. &chan->ring_dma, GFP_KERNEL);
  223. if (!chan->ring_virt)
  224. return -ENOMEM;
  225. memset(chan->ring_virt, 0, ring_size * sizeof(u64));
  226. return 0;
  227. }
  228. EXPORT_SYMBOL(pasemi_dma_alloc_ring);
  229. /* pasemi_dma_free_ring - Free an allocated descriptor ring for a channel
  230. * @chan: Channel for which to free the descriptor ring
  231. *
  232. * Frees a previously allocated descriptor ring for a channel.
  233. */
  234. void pasemi_dma_free_ring(struct pasemi_dmachan *chan)
  235. {
  236. BUG_ON(!chan->ring_virt);
  237. dma_free_coherent(&dma_pdev->dev, chan->ring_size * sizeof(u64),
  238. chan->ring_virt, chan->ring_dma);
  239. chan->ring_virt = NULL;
  240. chan->ring_size = 0;
  241. chan->ring_dma = 0;
  242. }
  243. EXPORT_SYMBOL(pasemi_dma_free_ring);
  244. /* pasemi_dma_start_chan - Start a DMA channel
  245. * @chan: Channel to start
  246. * @cmdsta: Additional CCMDSTA/TCMDSTA bits to write
  247. *
  248. * Enables (starts) a DMA channel with optional additional arguments.
  249. */
  250. void pasemi_dma_start_chan(const struct pasemi_dmachan *chan, const u32 cmdsta)
  251. {
  252. if (chan->chan_type == RXCHAN)
  253. pasemi_write_dma_reg(PAS_DMA_RXCHAN_CCMDSTA(chan->chno),
  254. cmdsta | PAS_DMA_RXCHAN_CCMDSTA_EN);
  255. else
  256. pasemi_write_dma_reg(PAS_DMA_TXCHAN_TCMDSTA(chan->chno),
  257. cmdsta | PAS_DMA_TXCHAN_TCMDSTA_EN);
  258. }
  259. EXPORT_SYMBOL(pasemi_dma_start_chan);
  260. /* pasemi_dma_stop_chan - Stop a DMA channel
  261. * @chan: Channel to stop
  262. *
  263. * Stops (disables) a DMA channel. This is done by setting the ST bit in the
  264. * CMDSTA register and waiting on the ACT (active) bit to clear, then
  265. * finally disabling the whole channel.
  266. *
  267. * This function will only try for a short while for the channel to stop, if
  268. * it doesn't it will return failure.
  269. *
  270. * Returns 1 on success, 0 on failure.
  271. */
  272. #define MAX_RETRIES 5000
  273. int pasemi_dma_stop_chan(const struct pasemi_dmachan *chan)
  274. {
  275. int reg, retries;
  276. u32 sta;
  277. if (chan->chan_type == RXCHAN) {
  278. reg = PAS_DMA_RXCHAN_CCMDSTA(chan->chno);
  279. pasemi_write_dma_reg(reg, PAS_DMA_RXCHAN_CCMDSTA_ST);
  280. for (retries = 0; retries < MAX_RETRIES; retries++) {
  281. sta = pasemi_read_dma_reg(reg);
  282. if (!(sta & PAS_DMA_RXCHAN_CCMDSTA_ACT)) {
  283. pasemi_write_dma_reg(reg, 0);
  284. return 1;
  285. }
  286. cond_resched();
  287. }
  288. } else {
  289. reg = PAS_DMA_TXCHAN_TCMDSTA(chan->chno);
  290. pasemi_write_dma_reg(reg, PAS_DMA_TXCHAN_TCMDSTA_ST);
  291. for (retries = 0; retries < MAX_RETRIES; retries++) {
  292. sta = pasemi_read_dma_reg(reg);
  293. if (!(sta & PAS_DMA_TXCHAN_TCMDSTA_ACT)) {
  294. pasemi_write_dma_reg(reg, 0);
  295. return 1;
  296. }
  297. cond_resched();
  298. }
  299. }
  300. return 0;
  301. }
  302. EXPORT_SYMBOL(pasemi_dma_stop_chan);
  303. /* pasemi_dma_alloc_buf - Allocate a buffer to use for DMA
  304. * @chan: Channel to allocate for
  305. * @size: Size of buffer in bytes
  306. * @handle: DMA handle
  307. *
  308. * Allocate a buffer to be used by the DMA engine for read/write,
  309. * similar to dma_alloc_coherent().
  310. *
  311. * Returns the virtual address of the buffer, or NULL in case of failure.
  312. */
  313. void *pasemi_dma_alloc_buf(struct pasemi_dmachan *chan, int size,
  314. dma_addr_t *handle)
  315. {
  316. return dma_alloc_coherent(&dma_pdev->dev, size, handle, GFP_KERNEL);
  317. }
  318. EXPORT_SYMBOL(pasemi_dma_alloc_buf);
  319. /* pasemi_dma_free_buf - Free a buffer used for DMA
  320. * @chan: Channel the buffer was allocated for
  321. * @size: Size of buffer in bytes
  322. * @handle: DMA handle
  323. *
  324. * Frees a previously allocated buffer.
  325. */
  326. void pasemi_dma_free_buf(struct pasemi_dmachan *chan, int size,
  327. dma_addr_t *handle)
  328. {
  329. dma_free_coherent(&dma_pdev->dev, size, handle, GFP_KERNEL);
  330. }
  331. EXPORT_SYMBOL(pasemi_dma_free_buf);
  332. /* pasemi_dma_alloc_flag - Allocate a flag (event) for channel syncronization
  333. *
  334. * Allocates a flag for use with channel syncronization (event descriptors).
  335. * Returns allocated flag (0-63), < 0 on error.
  336. */
  337. int pasemi_dma_alloc_flag(void)
  338. {
  339. int bit;
  340. retry:
  341. bit = find_next_bit(flags_free, MAX_FLAGS, 0);
  342. if (bit >= MAX_FLAGS)
  343. return -ENOSPC;
  344. if (!test_and_clear_bit(bit, flags_free))
  345. goto retry;
  346. return bit;
  347. }
  348. EXPORT_SYMBOL(pasemi_dma_alloc_flag);
  349. /* pasemi_dma_free_flag - Deallocates a flag (event)
  350. * @flag: Flag number to deallocate
  351. *
  352. * Frees up a flag so it can be reused for other purposes.
  353. */
  354. void pasemi_dma_free_flag(int flag)
  355. {
  356. BUG_ON(test_bit(flag, flags_free));
  357. BUG_ON(flag >= MAX_FLAGS);
  358. set_bit(flag, flags_free);
  359. }
  360. EXPORT_SYMBOL(pasemi_dma_free_flag);
  361. /* pasemi_dma_set_flag - Sets a flag (event) to 1
  362. * @flag: Flag number to set active
  363. *
  364. * Sets the flag provided to 1.
  365. */
  366. void pasemi_dma_set_flag(int flag)
  367. {
  368. BUG_ON(flag >= MAX_FLAGS);
  369. if (flag < 32)
  370. pasemi_write_dma_reg(PAS_DMA_TXF_SFLG0, 1 << flag);
  371. else
  372. pasemi_write_dma_reg(PAS_DMA_TXF_SFLG1, 1 << flag);
  373. }
  374. EXPORT_SYMBOL(pasemi_dma_set_flag);
  375. /* pasemi_dma_clear_flag - Sets a flag (event) to 0
  376. * @flag: Flag number to set inactive
  377. *
  378. * Sets the flag provided to 0.
  379. */
  380. void pasemi_dma_clear_flag(int flag)
  381. {
  382. BUG_ON(flag >= MAX_FLAGS);
  383. if (flag < 32)
  384. pasemi_write_dma_reg(PAS_DMA_TXF_CFLG0, 1 << flag);
  385. else
  386. pasemi_write_dma_reg(PAS_DMA_TXF_CFLG1, 1 << flag);
  387. }
  388. EXPORT_SYMBOL(pasemi_dma_clear_flag);
  389. /* pasemi_dma_alloc_fun - Allocate a function engine
  390. *
  391. * Allocates a function engine to use for crypto/checksum offload
  392. * Returns allocated engine (0-8), < 0 on error.
  393. */
  394. int pasemi_dma_alloc_fun(void)
  395. {
  396. int bit;
  397. retry:
  398. bit = find_next_bit(fun_free, MAX_FLAGS, 0);
  399. if (bit >= MAX_FLAGS)
  400. return -ENOSPC;
  401. if (!test_and_clear_bit(bit, fun_free))
  402. goto retry;
  403. return bit;
  404. }
  405. EXPORT_SYMBOL(pasemi_dma_alloc_fun);
  406. /* pasemi_dma_free_fun - Deallocates a function engine
  407. * @flag: Engine number to deallocate
  408. *
  409. * Frees up a function engine so it can be used for other purposes.
  410. */
  411. void pasemi_dma_free_fun(int fun)
  412. {
  413. BUG_ON(test_bit(fun, fun_free));
  414. BUG_ON(fun >= MAX_FLAGS);
  415. set_bit(fun, fun_free);
  416. }
  417. EXPORT_SYMBOL(pasemi_dma_free_fun);
  418. static void *map_onedev(struct pci_dev *p, int index)
  419. {
  420. struct device_node *dn;
  421. void __iomem *ret;
  422. dn = pci_device_to_OF_node(p);
  423. if (!dn)
  424. goto fallback;
  425. ret = of_iomap(dn, index);
  426. if (!ret)
  427. goto fallback;
  428. return ret;
  429. fallback:
  430. /* This is hardcoded and ugly, but we have some firmware versions
  431. * that don't provide the register space in the device tree. Luckily
  432. * they are at well-known locations so we can just do the math here.
  433. */
  434. return ioremap(0xe0000000 + (p->devfn << 12), 0x2000);
  435. }
  436. /* pasemi_dma_init - Initialize the PA Semi DMA library
  437. *
  438. * This function initializes the DMA library. It must be called before
  439. * any other function in the library.
  440. *
  441. * Returns 0 on success, errno on failure.
  442. */
  443. int pasemi_dma_init(void)
  444. {
  445. static DEFINE_SPINLOCK(init_lock);
  446. struct pci_dev *iob_pdev;
  447. struct pci_dev *pdev;
  448. struct resource res;
  449. struct device_node *dn;
  450. int i, intf, err = 0;
  451. unsigned long timeout;
  452. u32 tmp;
  453. if (!machine_is(pasemi))
  454. return -ENODEV;
  455. spin_lock(&init_lock);
  456. /* Make sure we haven't already initialized */
  457. if (dma_pdev)
  458. goto out;
  459. iob_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa001, NULL);
  460. if (!iob_pdev) {
  461. BUG();
  462. printk(KERN_WARNING "Can't find I/O Bridge\n");
  463. err = -ENODEV;
  464. goto out;
  465. }
  466. iob_regs = map_onedev(iob_pdev, 0);
  467. dma_pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa007, NULL);
  468. if (!dma_pdev) {
  469. BUG();
  470. printk(KERN_WARNING "Can't find DMA controller\n");
  471. err = -ENODEV;
  472. goto out;
  473. }
  474. dma_regs = map_onedev(dma_pdev, 0);
  475. base_hw_irq = virq_to_hw(dma_pdev->irq);
  476. pci_read_config_dword(dma_pdev, PAS_DMA_CAP_TXCH, &tmp);
  477. num_txch = (tmp & PAS_DMA_CAP_TXCH_TCHN_M) >> PAS_DMA_CAP_TXCH_TCHN_S;
  478. pci_read_config_dword(dma_pdev, PAS_DMA_CAP_RXCH, &tmp);
  479. num_rxch = (tmp & PAS_DMA_CAP_RXCH_RCHN_M) >> PAS_DMA_CAP_RXCH_RCHN_S;
  480. intf = 0;
  481. for (pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa006, NULL);
  482. pdev;
  483. pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa006, pdev))
  484. mac_regs[intf++] = map_onedev(pdev, 0);
  485. pci_dev_put(pdev);
  486. for (pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa005, NULL);
  487. pdev;
  488. pdev = pci_get_device(PCI_VENDOR_ID_PASEMI, 0xa005, pdev))
  489. mac_regs[intf++] = map_onedev(pdev, 0);
  490. pci_dev_put(pdev);
  491. dn = pci_device_to_OF_node(iob_pdev);
  492. if (dn)
  493. err = of_address_to_resource(dn, 1, &res);
  494. if (!dn || err) {
  495. /* Fallback for old firmware */
  496. res.start = 0xfd800000;
  497. res.end = res.start + 0x1000;
  498. }
  499. dma_status = __ioremap(res.start, res.end-res.start, 0);
  500. pci_dev_put(iob_pdev);
  501. for (i = 0; i < MAX_TXCH; i++)
  502. __set_bit(i, txch_free);
  503. for (i = 0; i < MAX_RXCH; i++)
  504. __set_bit(i, rxch_free);
  505. timeout = jiffies + HZ;
  506. pasemi_write_dma_reg(PAS_DMA_COM_RXCMD, 0);
  507. while (pasemi_read_dma_reg(PAS_DMA_COM_RXSTA) & 1) {
  508. if (time_after(jiffies, timeout)) {
  509. pr_warning("Warning: Could not disable RX section\n");
  510. break;
  511. }
  512. }
  513. timeout = jiffies + HZ;
  514. pasemi_write_dma_reg(PAS_DMA_COM_TXCMD, 0);
  515. while (pasemi_read_dma_reg(PAS_DMA_COM_TXSTA) & 1) {
  516. if (time_after(jiffies, timeout)) {
  517. pr_warning("Warning: Could not disable TX section\n");
  518. break;
  519. }
  520. }
  521. /* setup resource allocations for the different DMA sections */
  522. tmp = pasemi_read_dma_reg(PAS_DMA_COM_CFG);
  523. pasemi_write_dma_reg(PAS_DMA_COM_CFG, tmp | 0x18000000);
  524. /* enable tx section */
  525. pasemi_write_dma_reg(PAS_DMA_COM_TXCMD, PAS_DMA_COM_TXCMD_EN);
  526. /* enable rx section */
  527. pasemi_write_dma_reg(PAS_DMA_COM_RXCMD, PAS_DMA_COM_RXCMD_EN);
  528. for (i = 0; i < MAX_FLAGS; i++)
  529. __set_bit(i, flags_free);
  530. for (i = 0; i < MAX_FUN; i++)
  531. __set_bit(i, fun_free);
  532. /* clear all status flags */
  533. pasemi_write_dma_reg(PAS_DMA_TXF_CFLG0, 0xffffffff);
  534. pasemi_write_dma_reg(PAS_DMA_TXF_CFLG1, 0xffffffff);
  535. printk(KERN_INFO "PA Semi PWRficient DMA library initialized "
  536. "(%d tx, %d rx channels)\n", num_txch, num_rxch);
  537. out:
  538. spin_unlock(&init_lock);
  539. return err;
  540. }
  541. EXPORT_SYMBOL(pasemi_dma_init);