mmp_tdma.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /*
  2. * Driver For Marvell Two-channel DMA Engine
  3. *
  4. * Copyright: Marvell International Ltd.
  5. *
  6. * The code contained herein is licensed under the GNU General Public
  7. * License. You may obtain a copy of the GNU General Public License
  8. * Version 2 or later at the following locations:
  9. *
  10. */
  11. #include <linux/err.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/types.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/dma-mapping.h>
  17. #include <linux/slab.h>
  18. #include <linux/dmaengine.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/device.h>
  21. #include <mach/regs-icu.h>
  22. #include <linux/platform_data/dma-mmp_tdma.h>
  23. #include <linux/of_device.h>
  24. #include "dmaengine.h"
  25. /*
  26. * Two-Channel DMA registers
  27. */
  28. #define TDBCR 0x00 /* Byte Count */
  29. #define TDSAR 0x10 /* Src Addr */
  30. #define TDDAR 0x20 /* Dst Addr */
  31. #define TDNDPR 0x30 /* Next Desc */
  32. #define TDCR 0x40 /* Control */
  33. #define TDCP 0x60 /* Priority*/
  34. #define TDCDPR 0x70 /* Current Desc */
  35. #define TDIMR 0x80 /* Int Mask */
  36. #define TDISR 0xa0 /* Int Status */
  37. /* Two-Channel DMA Control Register */
  38. #define TDCR_SSZ_8_BITS (0x0 << 22) /* Sample Size */
  39. #define TDCR_SSZ_12_BITS (0x1 << 22)
  40. #define TDCR_SSZ_16_BITS (0x2 << 22)
  41. #define TDCR_SSZ_20_BITS (0x3 << 22)
  42. #define TDCR_SSZ_24_BITS (0x4 << 22)
  43. #define TDCR_SSZ_32_BITS (0x5 << 22)
  44. #define TDCR_SSZ_SHIFT (0x1 << 22)
  45. #define TDCR_SSZ_MASK (0x7 << 22)
  46. #define TDCR_SSPMOD (0x1 << 21) /* SSP MOD */
  47. #define TDCR_ABR (0x1 << 20) /* Channel Abort */
  48. #define TDCR_CDE (0x1 << 17) /* Close Desc Enable */
  49. #define TDCR_PACKMOD (0x1 << 16) /* Pack Mode (ADMA Only) */
  50. #define TDCR_CHANACT (0x1 << 14) /* Channel Active */
  51. #define TDCR_FETCHND (0x1 << 13) /* Fetch Next Desc */
  52. #define TDCR_CHANEN (0x1 << 12) /* Channel Enable */
  53. #define TDCR_INTMODE (0x1 << 10) /* Interrupt Mode */
  54. #define TDCR_CHAINMOD (0x1 << 9) /* Chain Mode */
  55. #define TDCR_BURSTSZ_MSK (0x7 << 6) /* Burst Size */
  56. #define TDCR_BURSTSZ_4B (0x0 << 6)
  57. #define TDCR_BURSTSZ_8B (0x1 << 6)
  58. #define TDCR_BURSTSZ_16B (0x3 << 6)
  59. #define TDCR_BURSTSZ_32B (0x6 << 6)
  60. #define TDCR_BURSTSZ_64B (0x7 << 6)
  61. #define TDCR_BURSTSZ_SQU_1B (0x5 << 6)
  62. #define TDCR_BURSTSZ_SQU_2B (0x6 << 6)
  63. #define TDCR_BURSTSZ_SQU_4B (0x0 << 6)
  64. #define TDCR_BURSTSZ_SQU_8B (0x1 << 6)
  65. #define TDCR_BURSTSZ_SQU_16B (0x3 << 6)
  66. #define TDCR_BURSTSZ_SQU_32B (0x7 << 6)
  67. #define TDCR_BURSTSZ_128B (0x5 << 6)
  68. #define TDCR_DSTDIR_MSK (0x3 << 4) /* Dst Direction */
  69. #define TDCR_DSTDIR_ADDR_HOLD (0x2 << 4) /* Dst Addr Hold */
  70. #define TDCR_DSTDIR_ADDR_INC (0x0 << 4) /* Dst Addr Increment */
  71. #define TDCR_SRCDIR_MSK (0x3 << 2) /* Src Direction */
  72. #define TDCR_SRCDIR_ADDR_HOLD (0x2 << 2) /* Src Addr Hold */
  73. #define TDCR_SRCDIR_ADDR_INC (0x0 << 2) /* Src Addr Increment */
  74. #define TDCR_DSTDESCCONT (0x1 << 1)
  75. #define TDCR_SRCDESTCONT (0x1 << 0)
  76. /* Two-Channel DMA Int Mask Register */
  77. #define TDIMR_COMP (0x1 << 0)
  78. /* Two-Channel DMA Int Status Register */
  79. #define TDISR_COMP (0x1 << 0)
  80. /*
  81. * Two-Channel DMA Descriptor Struct
  82. * NOTE: desc's buf must be aligned to 16 bytes.
  83. */
  84. struct mmp_tdma_desc {
  85. u32 byte_cnt;
  86. u32 src_addr;
  87. u32 dst_addr;
  88. u32 nxt_desc;
  89. };
  90. enum mmp_tdma_type {
  91. MMP_AUD_TDMA = 0,
  92. PXA910_SQU,
  93. };
  94. #define TDMA_ALIGNMENT 3
  95. #define TDMA_MAX_XFER_BYTES SZ_64K
  96. struct mmp_tdma_chan {
  97. struct device *dev;
  98. struct dma_chan chan;
  99. struct dma_async_tx_descriptor desc;
  100. struct tasklet_struct tasklet;
  101. struct mmp_tdma_desc *desc_arr;
  102. phys_addr_t desc_arr_phys;
  103. int desc_num;
  104. enum dma_transfer_direction dir;
  105. dma_addr_t dev_addr;
  106. u32 burst_sz;
  107. enum dma_slave_buswidth buswidth;
  108. enum dma_status status;
  109. int idx;
  110. enum mmp_tdma_type type;
  111. int irq;
  112. unsigned long reg_base;
  113. size_t buf_len;
  114. size_t period_len;
  115. size_t pos;
  116. };
  117. #define TDMA_CHANNEL_NUM 2
  118. struct mmp_tdma_device {
  119. struct device *dev;
  120. void __iomem *base;
  121. struct dma_device device;
  122. struct mmp_tdma_chan *tdmac[TDMA_CHANNEL_NUM];
  123. };
  124. #define to_mmp_tdma_chan(dchan) container_of(dchan, struct mmp_tdma_chan, chan)
  125. static void mmp_tdma_chan_set_desc(struct mmp_tdma_chan *tdmac, dma_addr_t phys)
  126. {
  127. writel(phys, tdmac->reg_base + TDNDPR);
  128. writel(readl(tdmac->reg_base + TDCR) | TDCR_FETCHND,
  129. tdmac->reg_base + TDCR);
  130. }
  131. static void mmp_tdma_enable_chan(struct mmp_tdma_chan *tdmac)
  132. {
  133. /* enable irq */
  134. writel(TDIMR_COMP, tdmac->reg_base + TDIMR);
  135. /* enable dma chan */
  136. writel(readl(tdmac->reg_base + TDCR) | TDCR_CHANEN,
  137. tdmac->reg_base + TDCR);
  138. tdmac->status = DMA_IN_PROGRESS;
  139. }
  140. static void mmp_tdma_disable_chan(struct mmp_tdma_chan *tdmac)
  141. {
  142. writel(readl(tdmac->reg_base + TDCR) & ~TDCR_CHANEN,
  143. tdmac->reg_base + TDCR);
  144. /* disable irq */
  145. writel(0, tdmac->reg_base + TDIMR);
  146. tdmac->status = DMA_SUCCESS;
  147. }
  148. static void mmp_tdma_resume_chan(struct mmp_tdma_chan *tdmac)
  149. {
  150. writel(readl(tdmac->reg_base + TDCR) | TDCR_CHANEN,
  151. tdmac->reg_base + TDCR);
  152. tdmac->status = DMA_IN_PROGRESS;
  153. }
  154. static void mmp_tdma_pause_chan(struct mmp_tdma_chan *tdmac)
  155. {
  156. writel(readl(tdmac->reg_base + TDCR) & ~TDCR_CHANEN,
  157. tdmac->reg_base + TDCR);
  158. tdmac->status = DMA_PAUSED;
  159. }
  160. static int mmp_tdma_config_chan(struct mmp_tdma_chan *tdmac)
  161. {
  162. unsigned int tdcr;
  163. mmp_tdma_disable_chan(tdmac);
  164. if (tdmac->dir == DMA_MEM_TO_DEV)
  165. tdcr = TDCR_DSTDIR_ADDR_HOLD | TDCR_SRCDIR_ADDR_INC;
  166. else if (tdmac->dir == DMA_DEV_TO_MEM)
  167. tdcr = TDCR_SRCDIR_ADDR_HOLD | TDCR_DSTDIR_ADDR_INC;
  168. if (tdmac->type == MMP_AUD_TDMA) {
  169. tdcr |= TDCR_PACKMOD;
  170. switch (tdmac->burst_sz) {
  171. case 4:
  172. tdcr |= TDCR_BURSTSZ_4B;
  173. break;
  174. case 8:
  175. tdcr |= TDCR_BURSTSZ_8B;
  176. break;
  177. case 16:
  178. tdcr |= TDCR_BURSTSZ_16B;
  179. break;
  180. case 32:
  181. tdcr |= TDCR_BURSTSZ_32B;
  182. break;
  183. case 64:
  184. tdcr |= TDCR_BURSTSZ_64B;
  185. break;
  186. case 128:
  187. tdcr |= TDCR_BURSTSZ_128B;
  188. break;
  189. default:
  190. dev_err(tdmac->dev, "mmp_tdma: unknown burst size.\n");
  191. return -EINVAL;
  192. }
  193. switch (tdmac->buswidth) {
  194. case DMA_SLAVE_BUSWIDTH_1_BYTE:
  195. tdcr |= TDCR_SSZ_8_BITS;
  196. break;
  197. case DMA_SLAVE_BUSWIDTH_2_BYTES:
  198. tdcr |= TDCR_SSZ_16_BITS;
  199. break;
  200. case DMA_SLAVE_BUSWIDTH_4_BYTES:
  201. tdcr |= TDCR_SSZ_32_BITS;
  202. break;
  203. default:
  204. dev_err(tdmac->dev, "mmp_tdma: unknown bus size.\n");
  205. return -EINVAL;
  206. }
  207. } else if (tdmac->type == PXA910_SQU) {
  208. tdcr |= TDCR_SSPMOD;
  209. switch (tdmac->burst_sz) {
  210. case 1:
  211. tdcr |= TDCR_BURSTSZ_SQU_1B;
  212. break;
  213. case 2:
  214. tdcr |= TDCR_BURSTSZ_SQU_2B;
  215. break;
  216. case 4:
  217. tdcr |= TDCR_BURSTSZ_SQU_4B;
  218. break;
  219. case 8:
  220. tdcr |= TDCR_BURSTSZ_SQU_8B;
  221. break;
  222. case 16:
  223. tdcr |= TDCR_BURSTSZ_SQU_16B;
  224. break;
  225. case 32:
  226. tdcr |= TDCR_BURSTSZ_SQU_32B;
  227. break;
  228. default:
  229. dev_err(tdmac->dev, "mmp_tdma: unknown burst size.\n");
  230. return -EINVAL;
  231. }
  232. }
  233. writel(tdcr, tdmac->reg_base + TDCR);
  234. return 0;
  235. }
  236. static int mmp_tdma_clear_chan_irq(struct mmp_tdma_chan *tdmac)
  237. {
  238. u32 reg = readl(tdmac->reg_base + TDISR);
  239. if (reg & TDISR_COMP) {
  240. /* clear irq */
  241. reg &= ~TDISR_COMP;
  242. writel(reg, tdmac->reg_base + TDISR);
  243. return 0;
  244. }
  245. return -EAGAIN;
  246. }
  247. static irqreturn_t mmp_tdma_chan_handler(int irq, void *dev_id)
  248. {
  249. struct mmp_tdma_chan *tdmac = dev_id;
  250. if (mmp_tdma_clear_chan_irq(tdmac) == 0) {
  251. tdmac->pos = (tdmac->pos + tdmac->period_len) % tdmac->buf_len;
  252. tasklet_schedule(&tdmac->tasklet);
  253. return IRQ_HANDLED;
  254. } else
  255. return IRQ_NONE;
  256. }
  257. static irqreturn_t mmp_tdma_int_handler(int irq, void *dev_id)
  258. {
  259. struct mmp_tdma_device *tdev = dev_id;
  260. int i, ret;
  261. int irq_num = 0;
  262. for (i = 0; i < TDMA_CHANNEL_NUM; i++) {
  263. struct mmp_tdma_chan *tdmac = tdev->tdmac[i];
  264. ret = mmp_tdma_chan_handler(irq, tdmac);
  265. if (ret == IRQ_HANDLED)
  266. irq_num++;
  267. }
  268. if (irq_num)
  269. return IRQ_HANDLED;
  270. else
  271. return IRQ_NONE;
  272. }
  273. static void dma_do_tasklet(unsigned long data)
  274. {
  275. struct mmp_tdma_chan *tdmac = (struct mmp_tdma_chan *)data;
  276. if (tdmac->desc.callback)
  277. tdmac->desc.callback(tdmac->desc.callback_param);
  278. }
  279. static void mmp_tdma_free_descriptor(struct mmp_tdma_chan *tdmac)
  280. {
  281. struct gen_pool *gpool;
  282. int size = tdmac->desc_num * sizeof(struct mmp_tdma_desc);
  283. gpool = sram_get_gpool("asram");
  284. if (tdmac->desc_arr)
  285. gen_pool_free(gpool, (unsigned long)tdmac->desc_arr,
  286. size);
  287. tdmac->desc_arr = NULL;
  288. return;
  289. }
  290. static dma_cookie_t mmp_tdma_tx_submit(struct dma_async_tx_descriptor *tx)
  291. {
  292. struct mmp_tdma_chan *tdmac = to_mmp_tdma_chan(tx->chan);
  293. mmp_tdma_chan_set_desc(tdmac, tdmac->desc_arr_phys);
  294. return 0;
  295. }
  296. static int mmp_tdma_alloc_chan_resources(struct dma_chan *chan)
  297. {
  298. struct mmp_tdma_chan *tdmac = to_mmp_tdma_chan(chan);
  299. int ret;
  300. dma_async_tx_descriptor_init(&tdmac->desc, chan);
  301. tdmac->desc.tx_submit = mmp_tdma_tx_submit;
  302. if (tdmac->irq) {
  303. ret = devm_request_irq(tdmac->dev, tdmac->irq,
  304. mmp_tdma_chan_handler, 0, "tdma", tdmac);
  305. if (ret)
  306. return ret;
  307. }
  308. return 1;
  309. }
  310. static void mmp_tdma_free_chan_resources(struct dma_chan *chan)
  311. {
  312. struct mmp_tdma_chan *tdmac = to_mmp_tdma_chan(chan);
  313. if (tdmac->irq)
  314. devm_free_irq(tdmac->dev, tdmac->irq, tdmac);
  315. mmp_tdma_free_descriptor(tdmac);
  316. return;
  317. }
  318. struct mmp_tdma_desc *mmp_tdma_alloc_descriptor(struct mmp_tdma_chan *tdmac)
  319. {
  320. struct gen_pool *gpool;
  321. int size = tdmac->desc_num * sizeof(struct mmp_tdma_desc);
  322. gpool = sram_get_gpool("asram");
  323. if (!gpool)
  324. return NULL;
  325. tdmac->desc_arr = (void *)gen_pool_alloc(gpool, size);
  326. if (!tdmac->desc_arr)
  327. return NULL;
  328. tdmac->desc_arr_phys = gen_pool_virt_to_phys(gpool,
  329. (unsigned long)tdmac->desc_arr);
  330. return tdmac->desc_arr;
  331. }
  332. static struct dma_async_tx_descriptor *mmp_tdma_prep_dma_cyclic(
  333. struct dma_chan *chan, dma_addr_t dma_addr, size_t buf_len,
  334. size_t period_len, enum dma_transfer_direction direction,
  335. unsigned long flags, void *context)
  336. {
  337. struct mmp_tdma_chan *tdmac = to_mmp_tdma_chan(chan);
  338. struct mmp_tdma_desc *desc;
  339. int num_periods = buf_len / period_len;
  340. int i = 0, buf = 0;
  341. if (tdmac->status != DMA_SUCCESS)
  342. return NULL;
  343. if (period_len > TDMA_MAX_XFER_BYTES) {
  344. dev_err(tdmac->dev,
  345. "maximum period size exceeded: %d > %d\n",
  346. period_len, TDMA_MAX_XFER_BYTES);
  347. goto err_out;
  348. }
  349. tdmac->status = DMA_IN_PROGRESS;
  350. tdmac->desc_num = num_periods;
  351. desc = mmp_tdma_alloc_descriptor(tdmac);
  352. if (!desc)
  353. goto err_out;
  354. while (buf < buf_len) {
  355. desc = &tdmac->desc_arr[i];
  356. if (i + 1 == num_periods)
  357. desc->nxt_desc = tdmac->desc_arr_phys;
  358. else
  359. desc->nxt_desc = tdmac->desc_arr_phys +
  360. sizeof(*desc) * (i + 1);
  361. if (direction == DMA_MEM_TO_DEV) {
  362. desc->src_addr = dma_addr;
  363. desc->dst_addr = tdmac->dev_addr;
  364. } else {
  365. desc->src_addr = tdmac->dev_addr;
  366. desc->dst_addr = dma_addr;
  367. }
  368. desc->byte_cnt = period_len;
  369. dma_addr += period_len;
  370. buf += period_len;
  371. i++;
  372. }
  373. tdmac->buf_len = buf_len;
  374. tdmac->period_len = period_len;
  375. tdmac->pos = 0;
  376. return &tdmac->desc;
  377. err_out:
  378. tdmac->status = DMA_ERROR;
  379. return NULL;
  380. }
  381. static int mmp_tdma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
  382. unsigned long arg)
  383. {
  384. struct mmp_tdma_chan *tdmac = to_mmp_tdma_chan(chan);
  385. struct dma_slave_config *dmaengine_cfg = (void *)arg;
  386. int ret = 0;
  387. switch (cmd) {
  388. case DMA_TERMINATE_ALL:
  389. mmp_tdma_disable_chan(tdmac);
  390. break;
  391. case DMA_PAUSE:
  392. mmp_tdma_pause_chan(tdmac);
  393. break;
  394. case DMA_RESUME:
  395. mmp_tdma_resume_chan(tdmac);
  396. break;
  397. case DMA_SLAVE_CONFIG:
  398. if (dmaengine_cfg->direction == DMA_DEV_TO_MEM) {
  399. tdmac->dev_addr = dmaengine_cfg->src_addr;
  400. tdmac->burst_sz = dmaengine_cfg->src_maxburst;
  401. tdmac->buswidth = dmaengine_cfg->src_addr_width;
  402. } else {
  403. tdmac->dev_addr = dmaengine_cfg->dst_addr;
  404. tdmac->burst_sz = dmaengine_cfg->dst_maxburst;
  405. tdmac->buswidth = dmaengine_cfg->dst_addr_width;
  406. }
  407. tdmac->dir = dmaengine_cfg->direction;
  408. return mmp_tdma_config_chan(tdmac);
  409. default:
  410. ret = -ENOSYS;
  411. }
  412. return ret;
  413. }
  414. static enum dma_status mmp_tdma_tx_status(struct dma_chan *chan,
  415. dma_cookie_t cookie, struct dma_tx_state *txstate)
  416. {
  417. struct mmp_tdma_chan *tdmac = to_mmp_tdma_chan(chan);
  418. dma_set_tx_state(txstate, chan->completed_cookie, chan->cookie,
  419. tdmac->buf_len - tdmac->pos);
  420. return tdmac->status;
  421. }
  422. static void mmp_tdma_issue_pending(struct dma_chan *chan)
  423. {
  424. struct mmp_tdma_chan *tdmac = to_mmp_tdma_chan(chan);
  425. mmp_tdma_enable_chan(tdmac);
  426. }
  427. static int mmp_tdma_remove(struct platform_device *pdev)
  428. {
  429. struct mmp_tdma_device *tdev = platform_get_drvdata(pdev);
  430. dma_async_device_unregister(&tdev->device);
  431. return 0;
  432. }
  433. static int mmp_tdma_chan_init(struct mmp_tdma_device *tdev,
  434. int idx, int irq, int type)
  435. {
  436. struct mmp_tdma_chan *tdmac;
  437. if (idx >= TDMA_CHANNEL_NUM) {
  438. dev_err(tdev->dev, "too many channels for device!\n");
  439. return -EINVAL;
  440. }
  441. /* alloc channel */
  442. tdmac = devm_kzalloc(tdev->dev, sizeof(*tdmac), GFP_KERNEL);
  443. if (!tdmac) {
  444. dev_err(tdev->dev, "no free memory for DMA channels!\n");
  445. return -ENOMEM;
  446. }
  447. if (irq)
  448. tdmac->irq = irq;
  449. tdmac->dev = tdev->dev;
  450. tdmac->chan.device = &tdev->device;
  451. tdmac->idx = idx;
  452. tdmac->type = type;
  453. tdmac->reg_base = (unsigned long)tdev->base + idx * 4;
  454. tdmac->status = DMA_SUCCESS;
  455. tdev->tdmac[tdmac->idx] = tdmac;
  456. tasklet_init(&tdmac->tasklet, dma_do_tasklet, (unsigned long)tdmac);
  457. /* add the channel to tdma_chan list */
  458. list_add_tail(&tdmac->chan.device_node,
  459. &tdev->device.channels);
  460. return 0;
  461. }
  462. static struct of_device_id mmp_tdma_dt_ids[] = {
  463. { .compatible = "marvell,adma-1.0", .data = (void *)MMP_AUD_TDMA},
  464. { .compatible = "marvell,pxa910-squ", .data = (void *)PXA910_SQU},
  465. {}
  466. };
  467. MODULE_DEVICE_TABLE(of, mmp_tdma_dt_ids);
  468. static int mmp_tdma_probe(struct platform_device *pdev)
  469. {
  470. enum mmp_tdma_type type;
  471. const struct of_device_id *of_id;
  472. struct mmp_tdma_device *tdev;
  473. struct resource *iores;
  474. int i, ret;
  475. int irq = 0, irq_num = 0;
  476. int chan_num = TDMA_CHANNEL_NUM;
  477. of_id = of_match_device(mmp_tdma_dt_ids, &pdev->dev);
  478. if (of_id)
  479. type = (enum mmp_tdma_type) of_id->data;
  480. else
  481. type = platform_get_device_id(pdev)->driver_data;
  482. /* always have couple channels */
  483. tdev = devm_kzalloc(&pdev->dev, sizeof(*tdev), GFP_KERNEL);
  484. if (!tdev)
  485. return -ENOMEM;
  486. tdev->dev = &pdev->dev;
  487. for (i = 0; i < chan_num; i++) {
  488. if (platform_get_irq(pdev, i) > 0)
  489. irq_num++;
  490. }
  491. iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  492. tdev->base = devm_ioremap_resource(&pdev->dev, iores);
  493. if (IS_ERR(tdev->base))
  494. return PTR_ERR(tdev->base);
  495. INIT_LIST_HEAD(&tdev->device.channels);
  496. if (irq_num != chan_num) {
  497. irq = platform_get_irq(pdev, 0);
  498. ret = devm_request_irq(&pdev->dev, irq,
  499. mmp_tdma_int_handler, 0, "tdma", tdev);
  500. if (ret)
  501. return ret;
  502. }
  503. /* initialize channel parameters */
  504. for (i = 0; i < chan_num; i++) {
  505. irq = (irq_num != chan_num) ? 0 : platform_get_irq(pdev, i);
  506. ret = mmp_tdma_chan_init(tdev, i, irq, type);
  507. if (ret)
  508. return ret;
  509. }
  510. dma_cap_set(DMA_SLAVE, tdev->device.cap_mask);
  511. dma_cap_set(DMA_CYCLIC, tdev->device.cap_mask);
  512. tdev->device.dev = &pdev->dev;
  513. tdev->device.device_alloc_chan_resources =
  514. mmp_tdma_alloc_chan_resources;
  515. tdev->device.device_free_chan_resources =
  516. mmp_tdma_free_chan_resources;
  517. tdev->device.device_prep_dma_cyclic = mmp_tdma_prep_dma_cyclic;
  518. tdev->device.device_tx_status = mmp_tdma_tx_status;
  519. tdev->device.device_issue_pending = mmp_tdma_issue_pending;
  520. tdev->device.device_control = mmp_tdma_control;
  521. tdev->device.copy_align = TDMA_ALIGNMENT;
  522. dma_set_mask(&pdev->dev, DMA_BIT_MASK(64));
  523. platform_set_drvdata(pdev, tdev);
  524. ret = dma_async_device_register(&tdev->device);
  525. if (ret) {
  526. dev_err(tdev->device.dev, "unable to register\n");
  527. return ret;
  528. }
  529. dev_info(tdev->device.dev, "initialized\n");
  530. return 0;
  531. }
  532. static const struct platform_device_id mmp_tdma_id_table[] = {
  533. { "mmp-adma", MMP_AUD_TDMA },
  534. { "pxa910-squ", PXA910_SQU },
  535. { },
  536. };
  537. static struct platform_driver mmp_tdma_driver = {
  538. .driver = {
  539. .name = "mmp-tdma",
  540. .owner = THIS_MODULE,
  541. .of_match_table = mmp_tdma_dt_ids,
  542. },
  543. .id_table = mmp_tdma_id_table,
  544. .probe = mmp_tdma_probe,
  545. .remove = mmp_tdma_remove,
  546. };
  547. module_platform_driver(mmp_tdma_driver);
  548. MODULE_LICENSE("GPL");
  549. MODULE_DESCRIPTION("MMP Two-Channel DMA Driver");
  550. MODULE_ALIAS("platform:mmp-tdma");
  551. MODULE_AUTHOR("Leo Yan <leoy@marvell.com>");
  552. MODULE_AUTHOR("Zhangfei Gao <zhangfei.gao@marvell.com>");