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