idma64.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  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. status_xfer = dma_readl(idma64, RAW(XFER));
  143. status_err = dma_readl(idma64, RAW(ERROR));
  144. for (i = 0; i < idma64->dma.chancnt; i++)
  145. idma64_chan_irq(idma64, i, status_err, status_xfer);
  146. return IRQ_HANDLED;
  147. }
  148. /* ---------------------------------------------------------------------- */
  149. static struct idma64_desc *idma64_alloc_desc(unsigned int ndesc)
  150. {
  151. struct idma64_desc *desc;
  152. desc = kzalloc(sizeof(*desc), GFP_NOWAIT);
  153. if (!desc)
  154. return NULL;
  155. desc->hw = kcalloc(ndesc, sizeof(*desc->hw), GFP_NOWAIT);
  156. if (!desc->hw) {
  157. kfree(desc);
  158. return NULL;
  159. }
  160. return desc;
  161. }
  162. static void idma64_desc_free(struct idma64_chan *idma64c,
  163. struct idma64_desc *desc)
  164. {
  165. struct idma64_hw_desc *hw;
  166. if (desc->ndesc) {
  167. unsigned int i = desc->ndesc;
  168. do {
  169. hw = &desc->hw[--i];
  170. dma_pool_free(idma64c->pool, hw->lli, hw->llp);
  171. } while (i);
  172. }
  173. kfree(desc->hw);
  174. kfree(desc);
  175. }
  176. static void idma64_vdesc_free(struct virt_dma_desc *vdesc)
  177. {
  178. struct idma64_chan *idma64c = to_idma64_chan(vdesc->tx.chan);
  179. idma64_desc_free(idma64c, to_idma64_desc(vdesc));
  180. }
  181. static void idma64_hw_desc_fill(struct idma64_hw_desc *hw,
  182. struct dma_slave_config *config,
  183. enum dma_transfer_direction direction, u64 llp)
  184. {
  185. struct idma64_lli *lli = hw->lli;
  186. u64 sar, dar;
  187. u32 ctlhi = IDMA64C_CTLH_BLOCK_TS(hw->len);
  188. u32 ctllo = IDMA64C_CTLL_LLP_S_EN | IDMA64C_CTLL_LLP_D_EN;
  189. u32 src_width, dst_width;
  190. if (direction == DMA_MEM_TO_DEV) {
  191. sar = hw->phys;
  192. dar = config->dst_addr;
  193. ctllo |= IDMA64C_CTLL_DST_FIX | IDMA64C_CTLL_SRC_INC |
  194. IDMA64C_CTLL_FC_M2P;
  195. src_width = __ffs(sar | hw->len | 4);
  196. dst_width = __ffs(config->dst_addr_width);
  197. } else { /* DMA_DEV_TO_MEM */
  198. sar = config->src_addr;
  199. dar = hw->phys;
  200. ctllo |= IDMA64C_CTLL_DST_INC | IDMA64C_CTLL_SRC_FIX |
  201. IDMA64C_CTLL_FC_P2M;
  202. src_width = __ffs(config->src_addr_width);
  203. dst_width = __ffs(dar | hw->len | 4);
  204. }
  205. lli->sar = sar;
  206. lli->dar = dar;
  207. lli->ctlhi = ctlhi;
  208. lli->ctllo = ctllo |
  209. IDMA64C_CTLL_SRC_MSIZE(config->src_maxburst) |
  210. IDMA64C_CTLL_DST_MSIZE(config->dst_maxburst) |
  211. IDMA64C_CTLL_DST_WIDTH(dst_width) |
  212. IDMA64C_CTLL_SRC_WIDTH(src_width);
  213. lli->llp = llp;
  214. }
  215. static void idma64_desc_fill(struct idma64_chan *idma64c,
  216. struct idma64_desc *desc)
  217. {
  218. struct dma_slave_config *config = &idma64c->config;
  219. unsigned int i = desc->ndesc;
  220. struct idma64_hw_desc *hw = &desc->hw[i - 1];
  221. struct idma64_lli *lli = hw->lli;
  222. u64 llp = 0;
  223. /* Fill the hardware descriptors and link them to a list */
  224. do {
  225. hw = &desc->hw[--i];
  226. idma64_hw_desc_fill(hw, config, desc->direction, llp);
  227. llp = hw->llp;
  228. desc->length += hw->len;
  229. } while (i);
  230. /* Trigger an interrupt after the last block is transfered */
  231. lli->ctllo |= IDMA64C_CTLL_INT_EN;
  232. /* Disable LLP transfer in the last block */
  233. lli->ctllo &= ~(IDMA64C_CTLL_LLP_S_EN | IDMA64C_CTLL_LLP_D_EN);
  234. }
  235. static struct dma_async_tx_descriptor *idma64_prep_slave_sg(
  236. struct dma_chan *chan, struct scatterlist *sgl,
  237. unsigned int sg_len, enum dma_transfer_direction direction,
  238. unsigned long flags, void *context)
  239. {
  240. struct idma64_chan *idma64c = to_idma64_chan(chan);
  241. struct idma64_desc *desc;
  242. struct scatterlist *sg;
  243. unsigned int i;
  244. desc = idma64_alloc_desc(sg_len);
  245. if (!desc)
  246. return NULL;
  247. for_each_sg(sgl, sg, sg_len, i) {
  248. struct idma64_hw_desc *hw = &desc->hw[i];
  249. /* Allocate DMA capable memory for hardware descriptor */
  250. hw->lli = dma_pool_alloc(idma64c->pool, GFP_NOWAIT, &hw->llp);
  251. if (!hw->lli) {
  252. desc->ndesc = i;
  253. idma64_desc_free(idma64c, desc);
  254. return NULL;
  255. }
  256. hw->phys = sg_dma_address(sg);
  257. hw->len = sg_dma_len(sg);
  258. }
  259. desc->ndesc = sg_len;
  260. desc->direction = direction;
  261. desc->status = DMA_IN_PROGRESS;
  262. idma64_desc_fill(idma64c, desc);
  263. return vchan_tx_prep(&idma64c->vchan, &desc->vdesc, flags);
  264. }
  265. static void idma64_issue_pending(struct dma_chan *chan)
  266. {
  267. struct idma64_chan *idma64c = to_idma64_chan(chan);
  268. unsigned long flags;
  269. spin_lock_irqsave(&idma64c->vchan.lock, flags);
  270. if (vchan_issue_pending(&idma64c->vchan) && !idma64c->desc)
  271. idma64_start_transfer(idma64c);
  272. spin_unlock_irqrestore(&idma64c->vchan.lock, flags);
  273. }
  274. static size_t idma64_active_desc_size(struct idma64_chan *idma64c)
  275. {
  276. struct idma64_desc *desc = idma64c->desc;
  277. struct idma64_hw_desc *hw;
  278. size_t bytes = desc->length;
  279. u64 llp = channel_readq(idma64c, LLP);
  280. u32 ctlhi = channel_readl(idma64c, CTL_HI);
  281. unsigned int i = 0;
  282. do {
  283. hw = &desc->hw[i];
  284. if (hw->llp == llp)
  285. break;
  286. bytes -= hw->len;
  287. } while (++i < desc->ndesc);
  288. if (!i)
  289. return bytes;
  290. /* The current chunk is not fully transfered yet */
  291. bytes += desc->hw[--i].len;
  292. return bytes - IDMA64C_CTLH_BLOCK_TS(ctlhi);
  293. }
  294. static enum dma_status idma64_tx_status(struct dma_chan *chan,
  295. dma_cookie_t cookie, struct dma_tx_state *state)
  296. {
  297. struct idma64_chan *idma64c = to_idma64_chan(chan);
  298. struct virt_dma_desc *vdesc;
  299. enum dma_status status;
  300. size_t bytes;
  301. unsigned long flags;
  302. status = dma_cookie_status(chan, cookie, state);
  303. if (status == DMA_COMPLETE)
  304. return status;
  305. spin_lock_irqsave(&idma64c->vchan.lock, flags);
  306. vdesc = vchan_find_desc(&idma64c->vchan, cookie);
  307. if (idma64c->desc && cookie == idma64c->desc->vdesc.tx.cookie) {
  308. bytes = idma64_active_desc_size(idma64c);
  309. dma_set_residue(state, bytes);
  310. status = idma64c->desc->status;
  311. } else if (vdesc) {
  312. bytes = to_idma64_desc(vdesc)->length;
  313. dma_set_residue(state, bytes);
  314. }
  315. spin_unlock_irqrestore(&idma64c->vchan.lock, flags);
  316. return status;
  317. }
  318. static void convert_burst(u32 *maxburst)
  319. {
  320. if (*maxburst)
  321. *maxburst = __fls(*maxburst);
  322. else
  323. *maxburst = 0;
  324. }
  325. static int idma64_slave_config(struct dma_chan *chan,
  326. struct dma_slave_config *config)
  327. {
  328. struct idma64_chan *idma64c = to_idma64_chan(chan);
  329. /* Check if chan will be configured for slave transfers */
  330. if (!is_slave_direction(config->direction))
  331. return -EINVAL;
  332. memcpy(&idma64c->config, config, sizeof(idma64c->config));
  333. convert_burst(&idma64c->config.src_maxburst);
  334. convert_burst(&idma64c->config.dst_maxburst);
  335. return 0;
  336. }
  337. static void idma64_chan_deactivate(struct idma64_chan *idma64c, bool drain)
  338. {
  339. unsigned short count = 100;
  340. u32 cfglo;
  341. cfglo = channel_readl(idma64c, CFG_LO);
  342. if (drain)
  343. cfglo |= IDMA64C_CFGL_CH_DRAIN;
  344. else
  345. cfglo &= ~IDMA64C_CFGL_CH_DRAIN;
  346. channel_writel(idma64c, CFG_LO, cfglo | IDMA64C_CFGL_CH_SUSP);
  347. do {
  348. udelay(1);
  349. cfglo = channel_readl(idma64c, CFG_LO);
  350. } while (!(cfglo & IDMA64C_CFGL_FIFO_EMPTY) && --count);
  351. }
  352. static void idma64_chan_activate(struct idma64_chan *idma64c)
  353. {
  354. u32 cfglo;
  355. cfglo = channel_readl(idma64c, CFG_LO);
  356. channel_writel(idma64c, CFG_LO, cfglo & ~IDMA64C_CFGL_CH_SUSP);
  357. }
  358. static int idma64_pause(struct dma_chan *chan)
  359. {
  360. struct idma64_chan *idma64c = to_idma64_chan(chan);
  361. unsigned long flags;
  362. spin_lock_irqsave(&idma64c->vchan.lock, flags);
  363. if (idma64c->desc && idma64c->desc->status == DMA_IN_PROGRESS) {
  364. idma64_chan_deactivate(idma64c, false);
  365. idma64c->desc->status = DMA_PAUSED;
  366. }
  367. spin_unlock_irqrestore(&idma64c->vchan.lock, flags);
  368. return 0;
  369. }
  370. static int idma64_resume(struct dma_chan *chan)
  371. {
  372. struct idma64_chan *idma64c = to_idma64_chan(chan);
  373. unsigned long flags;
  374. spin_lock_irqsave(&idma64c->vchan.lock, flags);
  375. if (idma64c->desc && idma64c->desc->status == DMA_PAUSED) {
  376. idma64c->desc->status = DMA_IN_PROGRESS;
  377. idma64_chan_activate(idma64c);
  378. }
  379. spin_unlock_irqrestore(&idma64c->vchan.lock, flags);
  380. return 0;
  381. }
  382. static int idma64_terminate_all(struct dma_chan *chan)
  383. {
  384. struct idma64_chan *idma64c = to_idma64_chan(chan);
  385. unsigned long flags;
  386. LIST_HEAD(head);
  387. spin_lock_irqsave(&idma64c->vchan.lock, flags);
  388. idma64_chan_deactivate(idma64c, true);
  389. idma64_stop_transfer(idma64c);
  390. if (idma64c->desc) {
  391. idma64_vdesc_free(&idma64c->desc->vdesc);
  392. idma64c->desc = NULL;
  393. }
  394. vchan_get_all_descriptors(&idma64c->vchan, &head);
  395. spin_unlock_irqrestore(&idma64c->vchan.lock, flags);
  396. vchan_dma_desc_free_list(&idma64c->vchan, &head);
  397. return 0;
  398. }
  399. static int idma64_alloc_chan_resources(struct dma_chan *chan)
  400. {
  401. struct idma64_chan *idma64c = to_idma64_chan(chan);
  402. /* Create a pool of consistent memory blocks for hardware descriptors */
  403. idma64c->pool = dma_pool_create(dev_name(chan2dev(chan)),
  404. chan->device->dev,
  405. sizeof(struct idma64_lli), 8, 0);
  406. if (!idma64c->pool) {
  407. dev_err(chan2dev(chan), "No memory for descriptors\n");
  408. return -ENOMEM;
  409. }
  410. return 0;
  411. }
  412. static void idma64_free_chan_resources(struct dma_chan *chan)
  413. {
  414. struct idma64_chan *idma64c = to_idma64_chan(chan);
  415. vchan_free_chan_resources(to_virt_chan(chan));
  416. dma_pool_destroy(idma64c->pool);
  417. idma64c->pool = NULL;
  418. }
  419. /* ---------------------------------------------------------------------- */
  420. #define IDMA64_BUSWIDTHS \
  421. BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \
  422. BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \
  423. BIT(DMA_SLAVE_BUSWIDTH_4_BYTES)
  424. static int idma64_probe(struct idma64_chip *chip)
  425. {
  426. struct idma64 *idma64;
  427. unsigned short nr_chan = IDMA64_NR_CHAN;
  428. unsigned short i;
  429. int ret;
  430. idma64 = devm_kzalloc(chip->dev, sizeof(*idma64), GFP_KERNEL);
  431. if (!idma64)
  432. return -ENOMEM;
  433. idma64->regs = chip->regs;
  434. chip->idma64 = idma64;
  435. idma64->chan = devm_kcalloc(chip->dev, nr_chan, sizeof(*idma64->chan),
  436. GFP_KERNEL);
  437. if (!idma64->chan)
  438. return -ENOMEM;
  439. idma64->all_chan_mask = (1 << nr_chan) - 1;
  440. /* Turn off iDMA controller */
  441. idma64_off(idma64);
  442. ret = devm_request_irq(chip->dev, chip->irq, idma64_irq, IRQF_SHARED,
  443. dev_name(chip->dev), idma64);
  444. if (ret)
  445. return ret;
  446. INIT_LIST_HEAD(&idma64->dma.channels);
  447. for (i = 0; i < nr_chan; i++) {
  448. struct idma64_chan *idma64c = &idma64->chan[i];
  449. idma64c->vchan.desc_free = idma64_vdesc_free;
  450. vchan_init(&idma64c->vchan, &idma64->dma);
  451. idma64c->regs = idma64->regs + i * IDMA64_CH_LENGTH;
  452. idma64c->mask = BIT(i);
  453. }
  454. dma_cap_set(DMA_SLAVE, idma64->dma.cap_mask);
  455. dma_cap_set(DMA_PRIVATE, idma64->dma.cap_mask);
  456. idma64->dma.device_alloc_chan_resources = idma64_alloc_chan_resources;
  457. idma64->dma.device_free_chan_resources = idma64_free_chan_resources;
  458. idma64->dma.device_prep_slave_sg = idma64_prep_slave_sg;
  459. idma64->dma.device_issue_pending = idma64_issue_pending;
  460. idma64->dma.device_tx_status = idma64_tx_status;
  461. idma64->dma.device_config = idma64_slave_config;
  462. idma64->dma.device_pause = idma64_pause;
  463. idma64->dma.device_resume = idma64_resume;
  464. idma64->dma.device_terminate_all = idma64_terminate_all;
  465. idma64->dma.src_addr_widths = IDMA64_BUSWIDTHS;
  466. idma64->dma.dst_addr_widths = IDMA64_BUSWIDTHS;
  467. idma64->dma.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
  468. idma64->dma.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
  469. idma64->dma.dev = chip->dev;
  470. dma_set_max_seg_size(idma64->dma.dev, IDMA64C_CTLH_BLOCK_TS_MASK);
  471. ret = dma_async_device_register(&idma64->dma);
  472. if (ret)
  473. return ret;
  474. dev_info(chip->dev, "Found Intel integrated DMA 64-bit\n");
  475. return 0;
  476. }
  477. static int idma64_remove(struct idma64_chip *chip)
  478. {
  479. struct idma64 *idma64 = chip->idma64;
  480. unsigned short i;
  481. dma_async_device_unregister(&idma64->dma);
  482. /*
  483. * Explicitly call devm_request_irq() to avoid the side effects with
  484. * the scheduled tasklets.
  485. */
  486. devm_free_irq(chip->dev, chip->irq, idma64);
  487. for (i = 0; i < idma64->dma.chancnt; i++) {
  488. struct idma64_chan *idma64c = &idma64->chan[i];
  489. tasklet_kill(&idma64c->vchan.task);
  490. }
  491. return 0;
  492. }
  493. /* ---------------------------------------------------------------------- */
  494. static int idma64_platform_probe(struct platform_device *pdev)
  495. {
  496. struct idma64_chip *chip;
  497. struct device *dev = &pdev->dev;
  498. struct resource *mem;
  499. int ret;
  500. chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
  501. if (!chip)
  502. return -ENOMEM;
  503. chip->irq = platform_get_irq(pdev, 0);
  504. if (chip->irq < 0)
  505. return chip->irq;
  506. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  507. chip->regs = devm_ioremap_resource(dev, mem);
  508. if (IS_ERR(chip->regs))
  509. return PTR_ERR(chip->regs);
  510. ret = dma_coerce_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
  511. if (ret)
  512. return ret;
  513. chip->dev = dev;
  514. ret = idma64_probe(chip);
  515. if (ret)
  516. return ret;
  517. platform_set_drvdata(pdev, chip);
  518. return 0;
  519. }
  520. static int idma64_platform_remove(struct platform_device *pdev)
  521. {
  522. struct idma64_chip *chip = platform_get_drvdata(pdev);
  523. return idma64_remove(chip);
  524. }
  525. #ifdef CONFIG_PM_SLEEP
  526. static int idma64_pm_suspend(struct device *dev)
  527. {
  528. struct platform_device *pdev = to_platform_device(dev);
  529. struct idma64_chip *chip = platform_get_drvdata(pdev);
  530. idma64_off(chip->idma64);
  531. return 0;
  532. }
  533. static int idma64_pm_resume(struct device *dev)
  534. {
  535. struct platform_device *pdev = to_platform_device(dev);
  536. struct idma64_chip *chip = platform_get_drvdata(pdev);
  537. idma64_on(chip->idma64);
  538. return 0;
  539. }
  540. #endif /* CONFIG_PM_SLEEP */
  541. static const struct dev_pm_ops idma64_dev_pm_ops = {
  542. SET_SYSTEM_SLEEP_PM_OPS(idma64_pm_suspend, idma64_pm_resume)
  543. };
  544. static struct platform_driver idma64_platform_driver = {
  545. .probe = idma64_platform_probe,
  546. .remove = idma64_platform_remove,
  547. .driver = {
  548. .name = DRV_NAME,
  549. .pm = &idma64_dev_pm_ops,
  550. },
  551. };
  552. module_platform_driver(idma64_platform_driver);
  553. MODULE_LICENSE("GPL v2");
  554. MODULE_DESCRIPTION("iDMA64 core driver");
  555. MODULE_AUTHOR("Andy Shevchenko <andriy.shevchenko@linux.intel.com>");
  556. MODULE_ALIAS("platform:" DRV_NAME);