tusb6010_omap.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*
  2. * TUSB6010 USB 2.0 OTG Dual Role controller OMAP DMA interface
  3. *
  4. * Copyright (C) 2006 Nokia Corporation
  5. * Tony Lindgren <tony@atomide.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/errno.h>
  14. #include <linux/usb.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/slab.h>
  18. #include <linux/dmaengine.h>
  19. #include "musb_core.h"
  20. #include "tusb6010.h"
  21. #define to_chdat(c) ((struct tusb_omap_dma_ch *)(c)->private_data)
  22. #define MAX_DMAREQ 5 /* REVISIT: Really 6, but req5 not OK */
  23. struct tusb_dma_data {
  24. s8 dmareq;
  25. struct dma_chan *chan;
  26. };
  27. struct tusb_omap_dma_ch {
  28. struct musb *musb;
  29. void __iomem *tbase;
  30. unsigned long phys_offset;
  31. int epnum;
  32. u8 tx;
  33. struct musb_hw_ep *hw_ep;
  34. struct tusb_dma_data *dma_data;
  35. struct tusb_omap_dma *tusb_dma;
  36. dma_addr_t dma_addr;
  37. u32 len;
  38. u16 packet_sz;
  39. u16 transfer_packet_sz;
  40. u32 transfer_len;
  41. u32 completed_len;
  42. };
  43. struct tusb_omap_dma {
  44. struct dma_controller controller;
  45. void __iomem *tbase;
  46. struct tusb_dma_data dma_pool[MAX_DMAREQ];
  47. unsigned multichannel:1;
  48. };
  49. /*
  50. * Allocate dmareq0 to the current channel unless it's already taken
  51. */
  52. static inline int tusb_omap_use_shared_dmareq(struct tusb_omap_dma_ch *chdat)
  53. {
  54. u32 reg = musb_readl(chdat->tbase, TUSB_DMA_EP_MAP);
  55. if (reg != 0) {
  56. dev_dbg(chdat->musb->controller, "ep%i dmareq0 is busy for ep%i\n",
  57. chdat->epnum, reg & 0xf);
  58. return -EAGAIN;
  59. }
  60. if (chdat->tx)
  61. reg = (1 << 4) | chdat->epnum;
  62. else
  63. reg = chdat->epnum;
  64. musb_writel(chdat->tbase, TUSB_DMA_EP_MAP, reg);
  65. return 0;
  66. }
  67. static inline void tusb_omap_free_shared_dmareq(struct tusb_omap_dma_ch *chdat)
  68. {
  69. u32 reg = musb_readl(chdat->tbase, TUSB_DMA_EP_MAP);
  70. if ((reg & 0xf) != chdat->epnum) {
  71. printk(KERN_ERR "ep%i trying to release dmareq0 for ep%i\n",
  72. chdat->epnum, reg & 0xf);
  73. return;
  74. }
  75. musb_writel(chdat->tbase, TUSB_DMA_EP_MAP, 0);
  76. }
  77. /*
  78. * See also musb_dma_completion in plat_uds.c and musb_g_[tx|rx]() in
  79. * musb_gadget.c.
  80. */
  81. static void tusb_omap_dma_cb(void *data)
  82. {
  83. struct dma_channel *channel = (struct dma_channel *)data;
  84. struct tusb_omap_dma_ch *chdat = to_chdat(channel);
  85. struct tusb_omap_dma *tusb_dma = chdat->tusb_dma;
  86. struct musb *musb = chdat->musb;
  87. struct device *dev = musb->controller;
  88. struct musb_hw_ep *hw_ep = chdat->hw_ep;
  89. void __iomem *ep_conf = hw_ep->conf;
  90. void __iomem *mbase = musb->mregs;
  91. unsigned long remaining, flags, pio;
  92. spin_lock_irqsave(&musb->lock, flags);
  93. dev_dbg(musb->controller, "ep%i %s dma callback\n",
  94. chdat->epnum, chdat->tx ? "tx" : "rx");
  95. if (chdat->tx)
  96. remaining = musb_readl(ep_conf, TUSB_EP_TX_OFFSET);
  97. else
  98. remaining = musb_readl(ep_conf, TUSB_EP_RX_OFFSET);
  99. remaining = TUSB_EP_CONFIG_XFR_SIZE(remaining);
  100. /* HW issue #10: XFR_SIZE may get corrupt on DMA (both async & sync) */
  101. if (unlikely(remaining > chdat->transfer_len)) {
  102. dev_dbg(musb->controller, "Corrupt %s XFR_SIZE: 0x%08lx\n",
  103. chdat->tx ? "tx" : "rx", remaining);
  104. remaining = 0;
  105. }
  106. channel->actual_len = chdat->transfer_len - remaining;
  107. pio = chdat->len - channel->actual_len;
  108. dev_dbg(musb->controller, "DMA remaining %lu/%u\n", remaining, chdat->transfer_len);
  109. /* Transfer remaining 1 - 31 bytes */
  110. if (pio > 0 && pio < 32) {
  111. u8 *buf;
  112. dev_dbg(musb->controller, "Using PIO for remaining %lu bytes\n", pio);
  113. buf = phys_to_virt((u32)chdat->dma_addr) + chdat->transfer_len;
  114. if (chdat->tx) {
  115. dma_unmap_single(dev, chdat->dma_addr,
  116. chdat->transfer_len,
  117. DMA_TO_DEVICE);
  118. musb_write_fifo(hw_ep, pio, buf);
  119. } else {
  120. dma_unmap_single(dev, chdat->dma_addr,
  121. chdat->transfer_len,
  122. DMA_FROM_DEVICE);
  123. musb_read_fifo(hw_ep, pio, buf);
  124. }
  125. channel->actual_len += pio;
  126. }
  127. if (!tusb_dma->multichannel)
  128. tusb_omap_free_shared_dmareq(chdat);
  129. channel->status = MUSB_DMA_STATUS_FREE;
  130. musb_dma_completion(musb, chdat->epnum, chdat->tx);
  131. /* We must terminate short tx transfers manually by setting TXPKTRDY.
  132. * REVISIT: This same problem may occur with other MUSB dma as well.
  133. * Easy to test with g_ether by pinging the MUSB board with ping -s54.
  134. */
  135. if ((chdat->transfer_len < chdat->packet_sz)
  136. || (chdat->transfer_len % chdat->packet_sz != 0)) {
  137. u16 csr;
  138. if (chdat->tx) {
  139. dev_dbg(musb->controller, "terminating short tx packet\n");
  140. musb_ep_select(mbase, chdat->epnum);
  141. csr = musb_readw(hw_ep->regs, MUSB_TXCSR);
  142. csr |= MUSB_TXCSR_MODE | MUSB_TXCSR_TXPKTRDY
  143. | MUSB_TXCSR_P_WZC_BITS;
  144. musb_writew(hw_ep->regs, MUSB_TXCSR, csr);
  145. }
  146. }
  147. spin_unlock_irqrestore(&musb->lock, flags);
  148. }
  149. static int tusb_omap_dma_program(struct dma_channel *channel, u16 packet_sz,
  150. u8 rndis_mode, dma_addr_t dma_addr, u32 len)
  151. {
  152. struct tusb_omap_dma_ch *chdat = to_chdat(channel);
  153. struct tusb_omap_dma *tusb_dma = chdat->tusb_dma;
  154. struct musb *musb = chdat->musb;
  155. struct device *dev = musb->controller;
  156. struct musb_hw_ep *hw_ep = chdat->hw_ep;
  157. void __iomem *mbase = musb->mregs;
  158. void __iomem *ep_conf = hw_ep->conf;
  159. dma_addr_t fifo_addr = hw_ep->fifo_sync;
  160. u32 dma_remaining;
  161. u16 csr;
  162. u32 psize;
  163. struct tusb_dma_data *dma_data;
  164. struct dma_async_tx_descriptor *dma_desc;
  165. struct dma_slave_config dma_cfg;
  166. enum dma_transfer_direction dma_dir;
  167. u32 port_window;
  168. int ret;
  169. if (unlikely(dma_addr & 0x1) || (len < 32) || (len > packet_sz))
  170. return false;
  171. /*
  172. * HW issue #10: Async dma will eventually corrupt the XFR_SIZE
  173. * register which will cause missed DMA interrupt. We could try to
  174. * use a timer for the callback, but it is unsafe as the XFR_SIZE
  175. * register is corrupt, and we won't know if the DMA worked.
  176. */
  177. if (dma_addr & 0x2)
  178. return false;
  179. /*
  180. * Because of HW issue #10, it seems like mixing sync DMA and async
  181. * PIO access can confuse the DMA. Make sure XFR_SIZE is reset before
  182. * using the channel for DMA.
  183. */
  184. if (chdat->tx)
  185. dma_remaining = musb_readl(ep_conf, TUSB_EP_TX_OFFSET);
  186. else
  187. dma_remaining = musb_readl(ep_conf, TUSB_EP_RX_OFFSET);
  188. dma_remaining = TUSB_EP_CONFIG_XFR_SIZE(dma_remaining);
  189. if (dma_remaining) {
  190. dev_dbg(musb->controller, "Busy %s dma, not using: %08x\n",
  191. chdat->tx ? "tx" : "rx", dma_remaining);
  192. return false;
  193. }
  194. chdat->transfer_len = len & ~0x1f;
  195. if (len < packet_sz)
  196. chdat->transfer_packet_sz = chdat->transfer_len;
  197. else
  198. chdat->transfer_packet_sz = packet_sz;
  199. dma_data = chdat->dma_data;
  200. if (!tusb_dma->multichannel) {
  201. if (tusb_omap_use_shared_dmareq(chdat) != 0) {
  202. dev_dbg(musb->controller, "could not get dma for ep%i\n", chdat->epnum);
  203. return false;
  204. }
  205. if (dma_data->dmareq < 0) {
  206. /* REVISIT: This should get blocked earlier, happens
  207. * with MSC ErrorRecoveryTest
  208. */
  209. WARN_ON(1);
  210. return false;
  211. }
  212. }
  213. chdat->packet_sz = packet_sz;
  214. chdat->len = len;
  215. channel->actual_len = 0;
  216. chdat->dma_addr = dma_addr;
  217. channel->status = MUSB_DMA_STATUS_BUSY;
  218. /* Since we're recycling dma areas, we need to clean or invalidate */
  219. if (chdat->tx) {
  220. dma_dir = DMA_MEM_TO_DEV;
  221. dma_map_single(dev, phys_to_virt(dma_addr), len,
  222. DMA_TO_DEVICE);
  223. } else {
  224. dma_dir = DMA_DEV_TO_MEM;
  225. dma_map_single(dev, phys_to_virt(dma_addr), len,
  226. DMA_FROM_DEVICE);
  227. }
  228. memset(&dma_cfg, 0, sizeof(dma_cfg));
  229. /* Use 16-bit transfer if dma_addr is not 32-bit aligned */
  230. if ((dma_addr & 0x3) == 0) {
  231. dma_cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  232. dma_cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES;
  233. port_window = 8;
  234. } else {
  235. dma_cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
  236. dma_cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES;
  237. port_window = 16;
  238. fifo_addr = hw_ep->fifo_async;
  239. }
  240. dev_dbg(musb->controller,
  241. "ep%i %s dma: %pad len: %u(%u) packet_sz: %i(%i)\n",
  242. chdat->epnum, chdat->tx ? "tx" : "rx", &dma_addr,
  243. chdat->transfer_len, len, chdat->transfer_packet_sz, packet_sz);
  244. dma_cfg.src_addr = fifo_addr;
  245. dma_cfg.dst_addr = fifo_addr;
  246. dma_cfg.src_port_window_size = port_window;
  247. dma_cfg.src_maxburst = port_window;
  248. dma_cfg.dst_port_window_size = port_window;
  249. dma_cfg.dst_maxburst = port_window;
  250. ret = dmaengine_slave_config(dma_data->chan, &dma_cfg);
  251. if (ret) {
  252. dev_err(musb->controller, "DMA slave config failed: %d\n", ret);
  253. return false;
  254. }
  255. dma_desc = dmaengine_prep_slave_single(dma_data->chan, dma_addr,
  256. chdat->transfer_len, dma_dir,
  257. DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
  258. if (!dma_desc) {
  259. dev_err(musb->controller, "DMA prep_slave_single failed\n");
  260. return false;
  261. }
  262. dma_desc->callback = tusb_omap_dma_cb;
  263. dma_desc->callback_param = channel;
  264. dmaengine_submit(dma_desc);
  265. dev_dbg(musb->controller,
  266. "ep%i %s using %i-bit %s dma from %pad to %pad\n",
  267. chdat->epnum, chdat->tx ? "tx" : "rx",
  268. dma_cfg.src_addr_width * 8,
  269. ((dma_addr & 0x3) == 0) ? "sync" : "async",
  270. (dma_dir == DMA_MEM_TO_DEV) ? &dma_addr : &fifo_addr,
  271. (dma_dir == DMA_MEM_TO_DEV) ? &fifo_addr : &dma_addr);
  272. /*
  273. * Prepare MUSB for DMA transfer
  274. */
  275. musb_ep_select(mbase, chdat->epnum);
  276. if (chdat->tx) {
  277. csr = musb_readw(hw_ep->regs, MUSB_TXCSR);
  278. csr |= (MUSB_TXCSR_AUTOSET | MUSB_TXCSR_DMAENAB
  279. | MUSB_TXCSR_DMAMODE | MUSB_TXCSR_MODE);
  280. csr &= ~MUSB_TXCSR_P_UNDERRUN;
  281. musb_writew(hw_ep->regs, MUSB_TXCSR, csr);
  282. } else {
  283. csr = musb_readw(hw_ep->regs, MUSB_RXCSR);
  284. csr |= MUSB_RXCSR_DMAENAB;
  285. csr &= ~(MUSB_RXCSR_AUTOCLEAR | MUSB_RXCSR_DMAMODE);
  286. musb_writew(hw_ep->regs, MUSB_RXCSR,
  287. csr | MUSB_RXCSR_P_WZC_BITS);
  288. }
  289. /* Start DMA transfer */
  290. dma_async_issue_pending(dma_data->chan);
  291. if (chdat->tx) {
  292. /* Send transfer_packet_sz packets at a time */
  293. psize = musb_readl(ep_conf, TUSB_EP_MAX_PACKET_SIZE_OFFSET);
  294. psize &= ~0x7ff;
  295. psize |= chdat->transfer_packet_sz;
  296. musb_writel(ep_conf, TUSB_EP_MAX_PACKET_SIZE_OFFSET, psize);
  297. musb_writel(ep_conf, TUSB_EP_TX_OFFSET,
  298. TUSB_EP_CONFIG_XFR_SIZE(chdat->transfer_len));
  299. } else {
  300. /* Receive transfer_packet_sz packets at a time */
  301. psize = musb_readl(ep_conf, TUSB_EP_MAX_PACKET_SIZE_OFFSET);
  302. psize &= ~(0x7ff << 16);
  303. psize |= (chdat->transfer_packet_sz << 16);
  304. musb_writel(ep_conf, TUSB_EP_MAX_PACKET_SIZE_OFFSET, psize);
  305. musb_writel(ep_conf, TUSB_EP_RX_OFFSET,
  306. TUSB_EP_CONFIG_XFR_SIZE(chdat->transfer_len));
  307. }
  308. return true;
  309. }
  310. static int tusb_omap_dma_abort(struct dma_channel *channel)
  311. {
  312. struct tusb_omap_dma_ch *chdat = to_chdat(channel);
  313. if (chdat->dma_data)
  314. dmaengine_terminate_all(chdat->dma_data->chan);
  315. channel->status = MUSB_DMA_STATUS_FREE;
  316. return 0;
  317. }
  318. static inline int tusb_omap_dma_allocate_dmareq(struct tusb_omap_dma_ch *chdat)
  319. {
  320. u32 reg = musb_readl(chdat->tbase, TUSB_DMA_EP_MAP);
  321. int i, dmareq_nr = -1;
  322. for (i = 0; i < MAX_DMAREQ; i++) {
  323. int cur = (reg & (0xf << (i * 5))) >> (i * 5);
  324. if (cur == 0) {
  325. dmareq_nr = i;
  326. break;
  327. }
  328. }
  329. if (dmareq_nr == -1)
  330. return -EAGAIN;
  331. reg |= (chdat->epnum << (dmareq_nr * 5));
  332. if (chdat->tx)
  333. reg |= ((1 << 4) << (dmareq_nr * 5));
  334. musb_writel(chdat->tbase, TUSB_DMA_EP_MAP, reg);
  335. chdat->dma_data = &chdat->tusb_dma->dma_pool[dmareq_nr];
  336. return 0;
  337. }
  338. static inline void tusb_omap_dma_free_dmareq(struct tusb_omap_dma_ch *chdat)
  339. {
  340. u32 reg;
  341. if (!chdat || !chdat->dma_data || chdat->dma_data->dmareq < 0)
  342. return;
  343. reg = musb_readl(chdat->tbase, TUSB_DMA_EP_MAP);
  344. reg &= ~(0x1f << (chdat->dma_data->dmareq * 5));
  345. musb_writel(chdat->tbase, TUSB_DMA_EP_MAP, reg);
  346. chdat->dma_data = NULL;
  347. }
  348. static struct dma_channel *dma_channel_pool[MAX_DMAREQ];
  349. static struct dma_channel *
  350. tusb_omap_dma_allocate(struct dma_controller *c,
  351. struct musb_hw_ep *hw_ep,
  352. u8 tx)
  353. {
  354. int ret, i;
  355. struct tusb_omap_dma *tusb_dma;
  356. struct musb *musb;
  357. struct dma_channel *channel = NULL;
  358. struct tusb_omap_dma_ch *chdat = NULL;
  359. struct tusb_dma_data *dma_data = NULL;
  360. tusb_dma = container_of(c, struct tusb_omap_dma, controller);
  361. musb = tusb_dma->controller.musb;
  362. /* REVISIT: Why does dmareq5 not work? */
  363. if (hw_ep->epnum == 0) {
  364. dev_dbg(musb->controller, "Not allowing DMA for ep0 %s\n", tx ? "tx" : "rx");
  365. return NULL;
  366. }
  367. for (i = 0; i < MAX_DMAREQ; i++) {
  368. struct dma_channel *ch = dma_channel_pool[i];
  369. if (ch->status == MUSB_DMA_STATUS_UNKNOWN) {
  370. ch->status = MUSB_DMA_STATUS_FREE;
  371. channel = ch;
  372. chdat = ch->private_data;
  373. break;
  374. }
  375. }
  376. if (!channel)
  377. return NULL;
  378. chdat->musb = tusb_dma->controller.musb;
  379. chdat->tbase = tusb_dma->tbase;
  380. chdat->hw_ep = hw_ep;
  381. chdat->epnum = hw_ep->epnum;
  382. chdat->completed_len = 0;
  383. chdat->tusb_dma = tusb_dma;
  384. if (tx)
  385. chdat->tx = 1;
  386. else
  387. chdat->tx = 0;
  388. channel->max_len = 0x7fffffff;
  389. channel->desired_mode = 0;
  390. channel->actual_len = 0;
  391. if (!chdat->dma_data) {
  392. if (tusb_dma->multichannel) {
  393. ret = tusb_omap_dma_allocate_dmareq(chdat);
  394. if (ret != 0)
  395. goto free_dmareq;
  396. } else {
  397. chdat->dma_data = &tusb_dma->dma_pool[0];
  398. }
  399. }
  400. dma_data = chdat->dma_data;
  401. dev_dbg(musb->controller, "ep%i %s dma: %s dmareq%i\n",
  402. chdat->epnum,
  403. chdat->tx ? "tx" : "rx",
  404. tusb_dma->multichannel ? "shared" : "dedicated",
  405. dma_data->dmareq);
  406. return channel;
  407. free_dmareq:
  408. tusb_omap_dma_free_dmareq(chdat);
  409. dev_dbg(musb->controller, "ep%i: Could not get a DMA channel\n", chdat->epnum);
  410. channel->status = MUSB_DMA_STATUS_UNKNOWN;
  411. return NULL;
  412. }
  413. static void tusb_omap_dma_release(struct dma_channel *channel)
  414. {
  415. struct tusb_omap_dma_ch *chdat = to_chdat(channel);
  416. struct musb *musb = chdat->musb;
  417. dev_dbg(musb->controller, "Release for ep%i\n", chdat->epnum);
  418. channel->status = MUSB_DMA_STATUS_UNKNOWN;
  419. dmaengine_terminate_sync(chdat->dma_data->chan);
  420. tusb_omap_dma_free_dmareq(chdat);
  421. channel = NULL;
  422. }
  423. void tusb_dma_controller_destroy(struct dma_controller *c)
  424. {
  425. struct tusb_omap_dma *tusb_dma;
  426. int i;
  427. tusb_dma = container_of(c, struct tusb_omap_dma, controller);
  428. for (i = 0; i < MAX_DMAREQ; i++) {
  429. struct dma_channel *ch = dma_channel_pool[i];
  430. if (ch) {
  431. kfree(ch->private_data);
  432. kfree(ch);
  433. }
  434. /* Free up the DMA channels */
  435. if (tusb_dma && tusb_dma->dma_pool[i].chan)
  436. dma_release_channel(tusb_dma->dma_pool[i].chan);
  437. }
  438. kfree(tusb_dma);
  439. }
  440. EXPORT_SYMBOL_GPL(tusb_dma_controller_destroy);
  441. static int tusb_omap_allocate_dma_pool(struct tusb_omap_dma *tusb_dma)
  442. {
  443. struct musb *musb = tusb_dma->controller.musb;
  444. int i;
  445. int ret = 0;
  446. for (i = 0; i < MAX_DMAREQ; i++) {
  447. struct tusb_dma_data *dma_data = &tusb_dma->dma_pool[i];
  448. /*
  449. * Request DMA channels:
  450. * - one channel in case of non multichannel mode
  451. * - MAX_DMAREQ number of channels in multichannel mode
  452. */
  453. if (i == 0 || tusb_dma->multichannel) {
  454. char ch_name[8];
  455. sprintf(ch_name, "dmareq%d", i);
  456. dma_data->chan = dma_request_chan(musb->controller,
  457. ch_name);
  458. if (IS_ERR(dma_data->chan)) {
  459. dev_err(musb->controller,
  460. "Failed to request %s\n", ch_name);
  461. ret = PTR_ERR(dma_data->chan);
  462. goto dma_error;
  463. }
  464. dma_data->dmareq = i;
  465. } else {
  466. dma_data->dmareq = -1;
  467. }
  468. }
  469. return 0;
  470. dma_error:
  471. for (; i >= 0; i--) {
  472. struct tusb_dma_data *dma_data = &tusb_dma->dma_pool[i];
  473. if (dma_data->dmareq >= 0)
  474. dma_release_channel(dma_data->chan);
  475. }
  476. return ret;
  477. }
  478. struct dma_controller *
  479. tusb_dma_controller_create(struct musb *musb, void __iomem *base)
  480. {
  481. void __iomem *tbase = musb->ctrl_base;
  482. struct tusb_omap_dma *tusb_dma;
  483. int i;
  484. /* REVISIT: Get dmareq lines used from board-*.c */
  485. musb_writel(musb->ctrl_base, TUSB_DMA_INT_MASK, 0x7fffffff);
  486. musb_writel(musb->ctrl_base, TUSB_DMA_EP_MAP, 0);
  487. musb_writel(tbase, TUSB_DMA_REQ_CONF,
  488. TUSB_DMA_REQ_CONF_BURST_SIZE(2)
  489. | TUSB_DMA_REQ_CONF_DMA_REQ_EN(0x3f)
  490. | TUSB_DMA_REQ_CONF_DMA_REQ_ASSER(2));
  491. tusb_dma = kzalloc(sizeof(struct tusb_omap_dma), GFP_KERNEL);
  492. if (!tusb_dma)
  493. goto out;
  494. tusb_dma->controller.musb = musb;
  495. tusb_dma->tbase = musb->ctrl_base;
  496. tusb_dma->controller.channel_alloc = tusb_omap_dma_allocate;
  497. tusb_dma->controller.channel_release = tusb_omap_dma_release;
  498. tusb_dma->controller.channel_program = tusb_omap_dma_program;
  499. tusb_dma->controller.channel_abort = tusb_omap_dma_abort;
  500. if (musb->tusb_revision >= TUSB_REV_30)
  501. tusb_dma->multichannel = 1;
  502. for (i = 0; i < MAX_DMAREQ; i++) {
  503. struct dma_channel *ch;
  504. struct tusb_omap_dma_ch *chdat;
  505. ch = kzalloc(sizeof(struct dma_channel), GFP_KERNEL);
  506. if (!ch)
  507. goto cleanup;
  508. dma_channel_pool[i] = ch;
  509. chdat = kzalloc(sizeof(struct tusb_omap_dma_ch), GFP_KERNEL);
  510. if (!chdat)
  511. goto cleanup;
  512. ch->status = MUSB_DMA_STATUS_UNKNOWN;
  513. ch->private_data = chdat;
  514. }
  515. if (tusb_omap_allocate_dma_pool(tusb_dma))
  516. goto cleanup;
  517. return &tusb_dma->controller;
  518. cleanup:
  519. musb_dma_controller_destroy(&tusb_dma->controller);
  520. out:
  521. return NULL;
  522. }
  523. EXPORT_SYMBOL_GPL(tusb_dma_controller_create);