idma64.c 18 KB

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