idma64.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*
  2. * Core driver for the Intel integrated DMA 64-bit
  3. *
  4. * Copyright (C) 2015 Intel Corporation
  5. * Author: Andy Shevchenko <andriy.shevchenko@linux.intel.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/bitops.h>
  12. #include <linux/delay.h>
  13. #include <linux/dmaengine.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/dmapool.h>
  16. #include <linux/init.h>
  17. #include <linux/module.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/slab.h>
  20. #include "idma64.h"
  21. /* Platform driver name */
  22. #define DRV_NAME "idma64"
  23. /* For now we support only two channels */
  24. #define IDMA64_NR_CHAN 2
  25. /* ---------------------------------------------------------------------- */
  26. static struct device *chan2dev(struct dma_chan *chan)
  27. {
  28. return &chan->dev->device;
  29. }
  30. /* ---------------------------------------------------------------------- */
  31. static void idma64_off(struct idma64 *idma64)
  32. {
  33. unsigned short count = 100;
  34. dma_writel(idma64, CFG, 0);
  35. channel_clear_bit(idma64, MASK(XFER), idma64->all_chan_mask);
  36. channel_clear_bit(idma64, MASK(BLOCK), idma64->all_chan_mask);
  37. channel_clear_bit(idma64, MASK(SRC_TRAN), idma64->all_chan_mask);
  38. channel_clear_bit(idma64, MASK(DST_TRAN), idma64->all_chan_mask);
  39. channel_clear_bit(idma64, MASK(ERROR), idma64->all_chan_mask);
  40. do {
  41. cpu_relax();
  42. } while (dma_readl(idma64, CFG) & IDMA64_CFG_DMA_EN && --count);
  43. }
  44. static void idma64_on(struct idma64 *idma64)
  45. {
  46. dma_writel(idma64, CFG, IDMA64_CFG_DMA_EN);
  47. }
  48. /* ---------------------------------------------------------------------- */
  49. static void idma64_chan_init(struct idma64 *idma64, struct idma64_chan *idma64c)
  50. {
  51. u32 cfghi = IDMA64C_CFGH_SRC_PER(1) | IDMA64C_CFGH_DST_PER(0);
  52. u32 cfglo = 0;
  53. /* Set default burst alignment */
  54. cfglo |= IDMA64C_CFGL_DST_BURST_ALIGN | IDMA64C_CFGL_SRC_BURST_ALIGN;
  55. channel_writel(idma64c, CFG_LO, cfglo);
  56. channel_writel(idma64c, CFG_HI, cfghi);
  57. /* Enable interrupts */
  58. channel_set_bit(idma64, MASK(XFER), idma64c->mask);
  59. channel_set_bit(idma64, MASK(ERROR), idma64c->mask);
  60. /*
  61. * Enforce the controller to be turned on.
  62. *
  63. * The iDMA is turned off in ->probe() and looses context during system
  64. * suspend / resume cycle. That's why we have to enable it each time we
  65. * use it.
  66. */
  67. idma64_on(idma64);
  68. }
  69. static void idma64_chan_stop(struct idma64 *idma64, struct idma64_chan *idma64c)
  70. {
  71. channel_clear_bit(idma64, CH_EN, idma64c->mask);
  72. }
  73. static void idma64_chan_start(struct idma64 *idma64, struct idma64_chan *idma64c)
  74. {
  75. struct idma64_desc *desc = idma64c->desc;
  76. struct idma64_hw_desc *hw = &desc->hw[0];
  77. channel_writeq(idma64c, SAR, 0);
  78. channel_writeq(idma64c, DAR, 0);
  79. channel_writel(idma64c, CTL_HI, IDMA64C_CTLH_BLOCK_TS(~0UL));
  80. channel_writel(idma64c, CTL_LO, IDMA64C_CTLL_LLP_S_EN | IDMA64C_CTLL_LLP_D_EN);
  81. channel_writeq(idma64c, LLP, hw->llp);
  82. channel_set_bit(idma64, CH_EN, idma64c->mask);
  83. }
  84. static void idma64_stop_transfer(struct idma64_chan *idma64c)
  85. {
  86. struct idma64 *idma64 = to_idma64(idma64c->vchan.chan.device);
  87. idma64_chan_stop(idma64, idma64c);
  88. }
  89. static void idma64_start_transfer(struct idma64_chan *idma64c)
  90. {
  91. struct idma64 *idma64 = to_idma64(idma64c->vchan.chan.device);
  92. struct virt_dma_desc *vdesc;
  93. /* Get the next descriptor */
  94. vdesc = vchan_next_desc(&idma64c->vchan);
  95. if (!vdesc) {
  96. idma64c->desc = NULL;
  97. return;
  98. }
  99. list_del(&vdesc->node);
  100. idma64c->desc = to_idma64_desc(vdesc);
  101. /* Configure the channel */
  102. idma64_chan_init(idma64, idma64c);
  103. /* Start the channel with a new descriptor */
  104. idma64_chan_start(idma64, idma64c);
  105. }
  106. /* ---------------------------------------------------------------------- */
  107. static void idma64_chan_irq(struct idma64 *idma64, unsigned short c,
  108. u32 status_err, u32 status_xfer)
  109. {
  110. struct idma64_chan *idma64c = &idma64->chan[c];
  111. struct idma64_desc *desc;
  112. unsigned long flags;
  113. spin_lock_irqsave(&idma64c->vchan.lock, flags);
  114. desc = idma64c->desc;
  115. if (desc) {
  116. if (status_err & (1 << c)) {
  117. dma_writel(idma64, CLEAR(ERROR), idma64c->mask);
  118. desc->status = DMA_ERROR;
  119. } else if (status_xfer & (1 << c)) {
  120. dma_writel(idma64, CLEAR(XFER), idma64c->mask);
  121. desc->status = DMA_COMPLETE;
  122. vchan_cookie_complete(&desc->vdesc);
  123. idma64_start_transfer(idma64c);
  124. }
  125. /* idma64_start_transfer() updates idma64c->desc */
  126. if (idma64c->desc == NULL || desc->status == DMA_ERROR)
  127. idma64_stop_transfer(idma64c);
  128. }
  129. spin_unlock_irqrestore(&idma64c->vchan.lock, flags);
  130. }
  131. static irqreturn_t idma64_irq(int irq, void *dev)
  132. {
  133. struct idma64 *idma64 = dev;
  134. u32 status = dma_readl(idma64, STATUS_INT);
  135. u32 status_xfer;
  136. u32 status_err;
  137. unsigned short i;
  138. dev_vdbg(idma64->dma.dev, "%s: status=%#x\n", __func__, status);
  139. /* Check if we have any interrupt from the DMA controller */
  140. if (!status)
  141. return IRQ_NONE;
  142. /* Disable interrupts */
  143. channel_clear_bit(idma64, MASK(XFER), idma64->all_chan_mask);
  144. channel_clear_bit(idma64, MASK(ERROR), idma64->all_chan_mask);
  145. status_xfer = dma_readl(idma64, RAW(XFER));
  146. status_err = dma_readl(idma64, RAW(ERROR));
  147. for (i = 0; i < idma64->dma.chancnt; i++)
  148. idma64_chan_irq(idma64, i, status_err, status_xfer);
  149. /* Re-enable interrupts */
  150. channel_set_bit(idma64, MASK(XFER), idma64->all_chan_mask);
  151. channel_set_bit(idma64, MASK(ERROR), idma64->all_chan_mask);
  152. return IRQ_HANDLED;
  153. }
  154. /* ---------------------------------------------------------------------- */
  155. static struct idma64_desc *idma64_alloc_desc(unsigned int ndesc)
  156. {
  157. struct idma64_desc *desc;
  158. desc = kzalloc(sizeof(*desc), GFP_NOWAIT);
  159. if (!desc)
  160. return NULL;
  161. desc->hw = kcalloc(ndesc, sizeof(*desc->hw), GFP_NOWAIT);
  162. if (!desc->hw) {
  163. kfree(desc);
  164. return NULL;
  165. }
  166. return desc;
  167. }
  168. static void idma64_desc_free(struct idma64_chan *idma64c,
  169. struct idma64_desc *desc)
  170. {
  171. struct idma64_hw_desc *hw;
  172. if (desc->ndesc) {
  173. unsigned int i = desc->ndesc;
  174. do {
  175. hw = &desc->hw[--i];
  176. dma_pool_free(idma64c->pool, hw->lli, hw->llp);
  177. } while (i);
  178. }
  179. kfree(desc->hw);
  180. kfree(desc);
  181. }
  182. static void idma64_vdesc_free(struct virt_dma_desc *vdesc)
  183. {
  184. struct idma64_chan *idma64c = to_idma64_chan(vdesc->tx.chan);
  185. idma64_desc_free(idma64c, to_idma64_desc(vdesc));
  186. }
  187. static u64 idma64_hw_desc_fill(struct idma64_hw_desc *hw,
  188. struct dma_slave_config *config,
  189. enum dma_transfer_direction direction, u64 llp)
  190. {
  191. struct idma64_lli *lli = hw->lli;
  192. u64 sar, dar;
  193. u32 ctlhi = IDMA64C_CTLH_BLOCK_TS(hw->len);
  194. u32 ctllo = IDMA64C_CTLL_LLP_S_EN | IDMA64C_CTLL_LLP_D_EN;
  195. u32 src_width, dst_width;
  196. if (direction == DMA_MEM_TO_DEV) {
  197. sar = hw->phys;
  198. dar = config->dst_addr;
  199. ctllo |= IDMA64C_CTLL_DST_FIX | IDMA64C_CTLL_SRC_INC |
  200. IDMA64C_CTLL_FC_M2P;
  201. src_width = __ffs(sar | hw->len | 4);
  202. dst_width = __ffs(config->dst_addr_width);
  203. } else { /* DMA_DEV_TO_MEM */
  204. sar = config->src_addr;
  205. dar = hw->phys;
  206. ctllo |= IDMA64C_CTLL_DST_INC | IDMA64C_CTLL_SRC_FIX |
  207. IDMA64C_CTLL_FC_P2M;
  208. src_width = __ffs(config->src_addr_width);
  209. dst_width = __ffs(dar | hw->len | 4);
  210. }
  211. lli->sar = sar;
  212. lli->dar = dar;
  213. lli->ctlhi = ctlhi;
  214. lli->ctllo = ctllo |
  215. IDMA64C_CTLL_SRC_MSIZE(config->src_maxburst) |
  216. IDMA64C_CTLL_DST_MSIZE(config->dst_maxburst) |
  217. IDMA64C_CTLL_DST_WIDTH(dst_width) |
  218. IDMA64C_CTLL_SRC_WIDTH(src_width);
  219. lli->llp = llp;
  220. return hw->llp;
  221. }
  222. static void idma64_desc_fill(struct idma64_chan *idma64c,
  223. struct idma64_desc *desc)
  224. {
  225. struct dma_slave_config *config = &idma64c->config;
  226. struct idma64_hw_desc *hw = &desc->hw[desc->ndesc - 1];
  227. struct idma64_lli *lli = hw->lli;
  228. u64 llp = 0;
  229. unsigned int i = desc->ndesc;
  230. /* Fill the hardware descriptors and link them to a list */
  231. do {
  232. hw = &desc->hw[--i];
  233. llp = idma64_hw_desc_fill(hw, config, desc->direction, llp);
  234. desc->length += hw->len;
  235. } while (i);
  236. /* Trigger interrupt after last block */
  237. lli->ctllo |= IDMA64C_CTLL_INT_EN;
  238. }
  239. static struct dma_async_tx_descriptor *idma64_prep_slave_sg(
  240. struct dma_chan *chan, struct scatterlist *sgl,
  241. unsigned int sg_len, enum dma_transfer_direction direction,
  242. unsigned long flags, void *context)
  243. {
  244. struct idma64_chan *idma64c = to_idma64_chan(chan);
  245. struct idma64_desc *desc;
  246. struct scatterlist *sg;
  247. unsigned int i;
  248. desc = idma64_alloc_desc(sg_len);
  249. if (!desc)
  250. return NULL;
  251. for_each_sg(sgl, sg, sg_len, i) {
  252. struct idma64_hw_desc *hw = &desc->hw[i];
  253. /* Allocate DMA capable memory for hardware descriptor */
  254. hw->lli = dma_pool_alloc(idma64c->pool, GFP_NOWAIT, &hw->llp);
  255. if (!hw->lli) {
  256. desc->ndesc = i;
  257. idma64_desc_free(idma64c, desc);
  258. return NULL;
  259. }
  260. hw->phys = sg_dma_address(sg);
  261. hw->len = sg_dma_len(sg);
  262. }
  263. desc->ndesc = sg_len;
  264. desc->direction = direction;
  265. desc->status = DMA_IN_PROGRESS;
  266. idma64_desc_fill(idma64c, desc);
  267. return vchan_tx_prep(&idma64c->vchan, &desc->vdesc, flags);
  268. }
  269. static void idma64_issue_pending(struct dma_chan *chan)
  270. {
  271. struct idma64_chan *idma64c = to_idma64_chan(chan);
  272. unsigned long flags;
  273. spin_lock_irqsave(&idma64c->vchan.lock, flags);
  274. if (vchan_issue_pending(&idma64c->vchan) && !idma64c->desc)
  275. idma64_start_transfer(idma64c);
  276. spin_unlock_irqrestore(&idma64c->vchan.lock, flags);
  277. }
  278. static size_t idma64_active_desc_size(struct idma64_chan *idma64c)
  279. {
  280. struct idma64_desc *desc = idma64c->desc;
  281. struct idma64_hw_desc *hw;
  282. size_t bytes = desc->length;
  283. u64 llp = channel_readq(idma64c, LLP);
  284. u32 ctlhi = channel_readl(idma64c, CTL_HI);
  285. unsigned int i = 0;
  286. do {
  287. hw = &desc->hw[i];
  288. if (hw->llp == llp)
  289. break;
  290. bytes -= hw->len;
  291. } while (++i < desc->ndesc);
  292. if (!i)
  293. return bytes;
  294. /* The current chunk is not fully transfered yet */
  295. bytes += desc->hw[--i].len;
  296. return bytes - IDMA64C_CTLH_BLOCK_TS(ctlhi);
  297. }
  298. static enum dma_status idma64_tx_status(struct dma_chan *chan,
  299. dma_cookie_t cookie, struct dma_tx_state *state)
  300. {
  301. struct idma64_chan *idma64c = to_idma64_chan(chan);
  302. struct virt_dma_desc *vdesc;
  303. enum dma_status status;
  304. size_t bytes;
  305. unsigned long flags;
  306. status = dma_cookie_status(chan, cookie, state);
  307. if (status == DMA_COMPLETE)
  308. return status;
  309. spin_lock_irqsave(&idma64c->vchan.lock, flags);
  310. vdesc = vchan_find_desc(&idma64c->vchan, cookie);
  311. if (idma64c->desc && cookie == idma64c->desc->vdesc.tx.cookie) {
  312. bytes = idma64_active_desc_size(idma64c);
  313. dma_set_residue(state, bytes);
  314. status = idma64c->desc->status;
  315. } else if (vdesc) {
  316. bytes = to_idma64_desc(vdesc)->length;
  317. dma_set_residue(state, bytes);
  318. }
  319. spin_unlock_irqrestore(&idma64c->vchan.lock, flags);
  320. return status;
  321. }
  322. static void convert_burst(u32 *maxburst)
  323. {
  324. if (*maxburst)
  325. *maxburst = __fls(*maxburst);
  326. else
  327. *maxburst = 0;
  328. }
  329. static int idma64_slave_config(struct dma_chan *chan,
  330. struct dma_slave_config *config)
  331. {
  332. struct idma64_chan *idma64c = to_idma64_chan(chan);
  333. /* Check if chan will be configured for slave transfers */
  334. if (!is_slave_direction(config->direction))
  335. return -EINVAL;
  336. memcpy(&idma64c->config, config, sizeof(idma64c->config));
  337. convert_burst(&idma64c->config.src_maxburst);
  338. convert_burst(&idma64c->config.dst_maxburst);
  339. return 0;
  340. }
  341. static void idma64_chan_deactivate(struct idma64_chan *idma64c, bool drain)
  342. {
  343. unsigned short count = 100;
  344. u32 cfglo;
  345. cfglo = channel_readl(idma64c, CFG_LO);
  346. if (drain)
  347. cfglo |= IDMA64C_CFGL_CH_DRAIN;
  348. else
  349. cfglo &= ~IDMA64C_CFGL_CH_DRAIN;
  350. channel_writel(idma64c, CFG_LO, cfglo | IDMA64C_CFGL_CH_SUSP);
  351. do {
  352. udelay(1);
  353. cfglo = channel_readl(idma64c, CFG_LO);
  354. } while (!(cfglo & IDMA64C_CFGL_FIFO_EMPTY) && --count);
  355. }
  356. static void idma64_chan_activate(struct idma64_chan *idma64c)
  357. {
  358. u32 cfglo;
  359. cfglo = channel_readl(idma64c, CFG_LO);
  360. channel_writel(idma64c, CFG_LO, cfglo & ~IDMA64C_CFGL_CH_SUSP);
  361. }
  362. static int idma64_pause(struct dma_chan *chan)
  363. {
  364. struct idma64_chan *idma64c = to_idma64_chan(chan);
  365. unsigned long flags;
  366. spin_lock_irqsave(&idma64c->vchan.lock, flags);
  367. if (idma64c->desc && idma64c->desc->status == DMA_IN_PROGRESS) {
  368. idma64_chan_deactivate(idma64c, false);
  369. idma64c->desc->status = DMA_PAUSED;
  370. }
  371. spin_unlock_irqrestore(&idma64c->vchan.lock, flags);
  372. return 0;
  373. }
  374. static int idma64_resume(struct dma_chan *chan)
  375. {
  376. struct idma64_chan *idma64c = to_idma64_chan(chan);
  377. unsigned long flags;
  378. spin_lock_irqsave(&idma64c->vchan.lock, flags);
  379. if (idma64c->desc && idma64c->desc->status == DMA_PAUSED) {
  380. idma64c->desc->status = DMA_IN_PROGRESS;
  381. idma64_chan_activate(idma64c);
  382. }
  383. spin_unlock_irqrestore(&idma64c->vchan.lock, flags);
  384. return 0;
  385. }
  386. static int idma64_terminate_all(struct dma_chan *chan)
  387. {
  388. struct idma64_chan *idma64c = to_idma64_chan(chan);
  389. unsigned long flags;
  390. LIST_HEAD(head);
  391. spin_lock_irqsave(&idma64c->vchan.lock, flags);
  392. idma64_chan_deactivate(idma64c, true);
  393. idma64_stop_transfer(idma64c);
  394. if (idma64c->desc) {
  395. idma64_vdesc_free(&idma64c->desc->vdesc);
  396. idma64c->desc = NULL;
  397. }
  398. vchan_get_all_descriptors(&idma64c->vchan, &head);
  399. spin_unlock_irqrestore(&idma64c->vchan.lock, flags);
  400. vchan_dma_desc_free_list(&idma64c->vchan, &head);
  401. return 0;
  402. }
  403. static int idma64_alloc_chan_resources(struct dma_chan *chan)
  404. {
  405. struct idma64_chan *idma64c = to_idma64_chan(chan);
  406. /* Create a pool of consistent memory blocks for hardware descriptors */
  407. idma64c->pool = dma_pool_create(dev_name(chan2dev(chan)),
  408. chan->device->dev,
  409. sizeof(struct idma64_lli), 8, 0);
  410. if (!idma64c->pool) {
  411. dev_err(chan2dev(chan), "No memory for descriptors\n");
  412. return -ENOMEM;
  413. }
  414. return 0;
  415. }
  416. static void idma64_free_chan_resources(struct dma_chan *chan)
  417. {
  418. struct idma64_chan *idma64c = to_idma64_chan(chan);
  419. vchan_free_chan_resources(to_virt_chan(chan));
  420. dma_pool_destroy(idma64c->pool);
  421. idma64c->pool = NULL;
  422. }
  423. /* ---------------------------------------------------------------------- */
  424. #define IDMA64_BUSWIDTHS \
  425. BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \
  426. BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \
  427. BIT(DMA_SLAVE_BUSWIDTH_4_BYTES)
  428. static int idma64_probe(struct idma64_chip *chip)
  429. {
  430. struct idma64 *idma64;
  431. unsigned short nr_chan = IDMA64_NR_CHAN;
  432. unsigned short i;
  433. int ret;
  434. idma64 = devm_kzalloc(chip->dev, sizeof(*idma64), GFP_KERNEL);
  435. if (!idma64)
  436. return -ENOMEM;
  437. idma64->regs = chip->regs;
  438. chip->idma64 = idma64;
  439. idma64->chan = devm_kcalloc(chip->dev, nr_chan, sizeof(*idma64->chan),
  440. GFP_KERNEL);
  441. if (!idma64->chan)
  442. return -ENOMEM;
  443. idma64->all_chan_mask = (1 << nr_chan) - 1;
  444. /* Turn off iDMA controller */
  445. idma64_off(idma64);
  446. ret = devm_request_irq(chip->dev, chip->irq, idma64_irq, IRQF_SHARED,
  447. dev_name(chip->dev), idma64);
  448. if (ret)
  449. return ret;
  450. INIT_LIST_HEAD(&idma64->dma.channels);
  451. for (i = 0; i < nr_chan; i++) {
  452. struct idma64_chan *idma64c = &idma64->chan[i];
  453. idma64c->vchan.desc_free = idma64_vdesc_free;
  454. vchan_init(&idma64c->vchan, &idma64->dma);
  455. idma64c->regs = idma64->regs + i * IDMA64_CH_LENGTH;
  456. idma64c->mask = BIT(i);
  457. }
  458. dma_cap_set(DMA_SLAVE, idma64->dma.cap_mask);
  459. dma_cap_set(DMA_PRIVATE, idma64->dma.cap_mask);
  460. idma64->dma.device_alloc_chan_resources = idma64_alloc_chan_resources;
  461. idma64->dma.device_free_chan_resources = idma64_free_chan_resources;
  462. idma64->dma.device_prep_slave_sg = idma64_prep_slave_sg;
  463. idma64->dma.device_issue_pending = idma64_issue_pending;
  464. idma64->dma.device_tx_status = idma64_tx_status;
  465. idma64->dma.device_config = idma64_slave_config;
  466. idma64->dma.device_pause = idma64_pause;
  467. idma64->dma.device_resume = idma64_resume;
  468. idma64->dma.device_terminate_all = idma64_terminate_all;
  469. idma64->dma.src_addr_widths = IDMA64_BUSWIDTHS;
  470. idma64->dma.dst_addr_widths = IDMA64_BUSWIDTHS;
  471. idma64->dma.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
  472. idma64->dma.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
  473. idma64->dma.dev = chip->dev;
  474. ret = dma_async_device_register(&idma64->dma);
  475. if (ret)
  476. return ret;
  477. dev_info(chip->dev, "Found Intel integrated DMA 64-bit\n");
  478. return 0;
  479. }
  480. static int idma64_remove(struct idma64_chip *chip)
  481. {
  482. struct idma64 *idma64 = chip->idma64;
  483. unsigned short i;
  484. dma_async_device_unregister(&idma64->dma);
  485. /*
  486. * Explicitly call devm_request_irq() to avoid the side effects with
  487. * the scheduled tasklets.
  488. */
  489. devm_free_irq(chip->dev, chip->irq, idma64);
  490. for (i = 0; i < idma64->dma.chancnt; i++) {
  491. struct idma64_chan *idma64c = &idma64->chan[i];
  492. tasklet_kill(&idma64c->vchan.task);
  493. }
  494. return 0;
  495. }
  496. /* ---------------------------------------------------------------------- */
  497. static int idma64_platform_probe(struct platform_device *pdev)
  498. {
  499. struct idma64_chip *chip;
  500. struct device *dev = &pdev->dev;
  501. struct resource *mem;
  502. int ret;
  503. chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
  504. if (!chip)
  505. return -ENOMEM;
  506. chip->irq = platform_get_irq(pdev, 0);
  507. if (chip->irq < 0)
  508. return chip->irq;
  509. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  510. chip->regs = devm_ioremap_resource(dev, mem);
  511. if (IS_ERR(chip->regs))
  512. return PTR_ERR(chip->regs);
  513. ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  514. if (ret)
  515. return ret;
  516. chip->dev = dev;
  517. ret = idma64_probe(chip);
  518. if (ret)
  519. return ret;
  520. platform_set_drvdata(pdev, chip);
  521. return 0;
  522. }
  523. static int idma64_platform_remove(struct platform_device *pdev)
  524. {
  525. struct idma64_chip *chip = platform_get_drvdata(pdev);
  526. return idma64_remove(chip);
  527. }
  528. #ifdef CONFIG_PM_SLEEP
  529. static int idma64_pm_suspend(struct device *dev)
  530. {
  531. struct platform_device *pdev = to_platform_device(dev);
  532. struct idma64_chip *chip = platform_get_drvdata(pdev);
  533. idma64_off(chip->idma64);
  534. return 0;
  535. }
  536. static int idma64_pm_resume(struct device *dev)
  537. {
  538. struct platform_device *pdev = to_platform_device(dev);
  539. struct idma64_chip *chip = platform_get_drvdata(pdev);
  540. idma64_on(chip->idma64);
  541. return 0;
  542. }
  543. #endif /* CONFIG_PM_SLEEP */
  544. static const struct dev_pm_ops idma64_dev_pm_ops = {
  545. SET_SYSTEM_SLEEP_PM_OPS(idma64_pm_suspend, idma64_pm_resume)
  546. };
  547. static struct platform_driver idma64_platform_driver = {
  548. .probe = idma64_platform_probe,
  549. .remove = idma64_platform_remove,
  550. .driver = {
  551. .name = DRV_NAME,
  552. .pm = &idma64_dev_pm_ops,
  553. },
  554. };
  555. module_platform_driver(idma64_platform_driver);
  556. MODULE_LICENSE("GPL v2");
  557. MODULE_DESCRIPTION("iDMA64 core driver");
  558. MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
  559. MODULE_ALIAS("platform:" DRV_NAME);