cppi41.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  1. #include <linux/delay.h>
  2. #include <linux/dmaengine.h>
  3. #include <linux/dma-mapping.h>
  4. #include <linux/platform_device.h>
  5. #include <linux/module.h>
  6. #include <linux/of.h>
  7. #include <linux/slab.h>
  8. #include <linux/of_dma.h>
  9. #include <linux/of_irq.h>
  10. #include <linux/dmapool.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/of_address.h>
  13. #include <linux/pm_runtime.h>
  14. #include "../dmaengine.h"
  15. #define DESC_TYPE 27
  16. #define DESC_TYPE_HOST 0x10
  17. #define DESC_TYPE_TEARD 0x13
  18. #define TD_DESC_IS_RX (1 << 16)
  19. #define TD_DESC_DMA_NUM 10
  20. #define DESC_LENGTH_BITS_NUM 21
  21. #define DESC_TYPE_USB (5 << 26)
  22. #define DESC_PD_COMPLETE (1 << 31)
  23. /* DMA engine */
  24. #define DMA_TDFDQ 4
  25. #define DMA_TXGCR(x) (0x800 + (x) * 0x20)
  26. #define DMA_RXGCR(x) (0x808 + (x) * 0x20)
  27. #define RXHPCRA0 4
  28. #define GCR_CHAN_ENABLE (1 << 31)
  29. #define GCR_TEARDOWN (1 << 30)
  30. #define GCR_STARV_RETRY (1 << 24)
  31. #define GCR_DESC_TYPE_HOST (1 << 14)
  32. /* DMA scheduler */
  33. #define DMA_SCHED_CTRL 0
  34. #define DMA_SCHED_CTRL_EN (1 << 31)
  35. #define DMA_SCHED_WORD(x) ((x) * 4 + 0x800)
  36. #define SCHED_ENTRY0_CHAN(x) ((x) << 0)
  37. #define SCHED_ENTRY0_IS_RX (1 << 7)
  38. #define SCHED_ENTRY1_CHAN(x) ((x) << 8)
  39. #define SCHED_ENTRY1_IS_RX (1 << 15)
  40. #define SCHED_ENTRY2_CHAN(x) ((x) << 16)
  41. #define SCHED_ENTRY2_IS_RX (1 << 23)
  42. #define SCHED_ENTRY3_CHAN(x) ((x) << 24)
  43. #define SCHED_ENTRY3_IS_RX (1 << 31)
  44. /* Queue manager */
  45. /* 4 KiB of memory for descriptors, 2 for each endpoint */
  46. #define ALLOC_DECS_NUM 128
  47. #define DESCS_AREAS 1
  48. #define TOTAL_DESCS_NUM (ALLOC_DECS_NUM * DESCS_AREAS)
  49. #define QMGR_SCRATCH_SIZE (TOTAL_DESCS_NUM * 4)
  50. #define QMGR_LRAM0_BASE 0x80
  51. #define QMGR_LRAM_SIZE 0x84
  52. #define QMGR_LRAM1_BASE 0x88
  53. #define QMGR_MEMBASE(x) (0x1000 + (x) * 0x10)
  54. #define QMGR_MEMCTRL(x) (0x1004 + (x) * 0x10)
  55. #define QMGR_MEMCTRL_IDX_SH 16
  56. #define QMGR_MEMCTRL_DESC_SH 8
  57. #define QMGR_PEND(x) (0x90 + (x) * 4)
  58. #define QMGR_PENDING_SLOT_Q(x) (x / 32)
  59. #define QMGR_PENDING_BIT_Q(x) (x % 32)
  60. #define QMGR_QUEUE_A(n) (0x2000 + (n) * 0x10)
  61. #define QMGR_QUEUE_B(n) (0x2004 + (n) * 0x10)
  62. #define QMGR_QUEUE_C(n) (0x2008 + (n) * 0x10)
  63. #define QMGR_QUEUE_D(n) (0x200c + (n) * 0x10)
  64. /* Packet Descriptor */
  65. #define PD2_ZERO_LENGTH (1 << 19)
  66. struct cppi41_channel {
  67. struct dma_chan chan;
  68. struct dma_async_tx_descriptor txd;
  69. struct cppi41_dd *cdd;
  70. struct cppi41_desc *desc;
  71. dma_addr_t desc_phys;
  72. void __iomem *gcr_reg;
  73. int is_tx;
  74. u32 residue;
  75. unsigned int q_num;
  76. unsigned int q_comp_num;
  77. unsigned int port_num;
  78. unsigned td_retry;
  79. unsigned td_queued:1;
  80. unsigned td_seen:1;
  81. unsigned td_desc_seen:1;
  82. struct list_head node; /* Node for pending list */
  83. };
  84. struct cppi41_desc {
  85. u32 pd0;
  86. u32 pd1;
  87. u32 pd2;
  88. u32 pd3;
  89. u32 pd4;
  90. u32 pd5;
  91. u32 pd6;
  92. u32 pd7;
  93. } __aligned(32);
  94. struct chan_queues {
  95. u16 submit;
  96. u16 complete;
  97. };
  98. struct cppi41_dd {
  99. struct dma_device ddev;
  100. void *qmgr_scratch;
  101. dma_addr_t scratch_phys;
  102. struct cppi41_desc *cd;
  103. dma_addr_t descs_phys;
  104. u32 first_td_desc;
  105. struct cppi41_channel *chan_busy[ALLOC_DECS_NUM];
  106. void __iomem *ctrl_mem;
  107. void __iomem *sched_mem;
  108. void __iomem *qmgr_mem;
  109. unsigned int irq;
  110. const struct chan_queues *queues_rx;
  111. const struct chan_queues *queues_tx;
  112. struct chan_queues td_queue;
  113. u16 first_completion_queue;
  114. u16 qmgr_num_pend;
  115. u32 n_chans;
  116. u8 platform;
  117. struct list_head pending; /* Pending queued transfers */
  118. spinlock_t lock; /* Lock for pending list */
  119. /* context for suspend/resume */
  120. unsigned int dma_tdfdq;
  121. bool is_suspended;
  122. };
  123. static struct chan_queues am335x_usb_queues_tx[] = {
  124. /* USB0 ENDP 1 */
  125. [ 0] = { .submit = 32, .complete = 93},
  126. [ 1] = { .submit = 34, .complete = 94},
  127. [ 2] = { .submit = 36, .complete = 95},
  128. [ 3] = { .submit = 38, .complete = 96},
  129. [ 4] = { .submit = 40, .complete = 97},
  130. [ 5] = { .submit = 42, .complete = 98},
  131. [ 6] = { .submit = 44, .complete = 99},
  132. [ 7] = { .submit = 46, .complete = 100},
  133. [ 8] = { .submit = 48, .complete = 101},
  134. [ 9] = { .submit = 50, .complete = 102},
  135. [10] = { .submit = 52, .complete = 103},
  136. [11] = { .submit = 54, .complete = 104},
  137. [12] = { .submit = 56, .complete = 105},
  138. [13] = { .submit = 58, .complete = 106},
  139. [14] = { .submit = 60, .complete = 107},
  140. /* USB1 ENDP1 */
  141. [15] = { .submit = 62, .complete = 125},
  142. [16] = { .submit = 64, .complete = 126},
  143. [17] = { .submit = 66, .complete = 127},
  144. [18] = { .submit = 68, .complete = 128},
  145. [19] = { .submit = 70, .complete = 129},
  146. [20] = { .submit = 72, .complete = 130},
  147. [21] = { .submit = 74, .complete = 131},
  148. [22] = { .submit = 76, .complete = 132},
  149. [23] = { .submit = 78, .complete = 133},
  150. [24] = { .submit = 80, .complete = 134},
  151. [25] = { .submit = 82, .complete = 135},
  152. [26] = { .submit = 84, .complete = 136},
  153. [27] = { .submit = 86, .complete = 137},
  154. [28] = { .submit = 88, .complete = 138},
  155. [29] = { .submit = 90, .complete = 139},
  156. };
  157. static const struct chan_queues am335x_usb_queues_rx[] = {
  158. /* USB0 ENDP 1 */
  159. [ 0] = { .submit = 1, .complete = 109},
  160. [ 1] = { .submit = 2, .complete = 110},
  161. [ 2] = { .submit = 3, .complete = 111},
  162. [ 3] = { .submit = 4, .complete = 112},
  163. [ 4] = { .submit = 5, .complete = 113},
  164. [ 5] = { .submit = 6, .complete = 114},
  165. [ 6] = { .submit = 7, .complete = 115},
  166. [ 7] = { .submit = 8, .complete = 116},
  167. [ 8] = { .submit = 9, .complete = 117},
  168. [ 9] = { .submit = 10, .complete = 118},
  169. [10] = { .submit = 11, .complete = 119},
  170. [11] = { .submit = 12, .complete = 120},
  171. [12] = { .submit = 13, .complete = 121},
  172. [13] = { .submit = 14, .complete = 122},
  173. [14] = { .submit = 15, .complete = 123},
  174. /* USB1 ENDP 1 */
  175. [15] = { .submit = 16, .complete = 141},
  176. [16] = { .submit = 17, .complete = 142},
  177. [17] = { .submit = 18, .complete = 143},
  178. [18] = { .submit = 19, .complete = 144},
  179. [19] = { .submit = 20, .complete = 145},
  180. [20] = { .submit = 21, .complete = 146},
  181. [21] = { .submit = 22, .complete = 147},
  182. [22] = { .submit = 23, .complete = 148},
  183. [23] = { .submit = 24, .complete = 149},
  184. [24] = { .submit = 25, .complete = 150},
  185. [25] = { .submit = 26, .complete = 151},
  186. [26] = { .submit = 27, .complete = 152},
  187. [27] = { .submit = 28, .complete = 153},
  188. [28] = { .submit = 29, .complete = 154},
  189. [29] = { .submit = 30, .complete = 155},
  190. };
  191. static const struct chan_queues da8xx_usb_queues_tx[] = {
  192. [0] = { .submit = 16, .complete = 24},
  193. [1] = { .submit = 18, .complete = 24},
  194. [2] = { .submit = 20, .complete = 24},
  195. [3] = { .submit = 22, .complete = 24},
  196. };
  197. static const struct chan_queues da8xx_usb_queues_rx[] = {
  198. [0] = { .submit = 1, .complete = 26},
  199. [1] = { .submit = 3, .complete = 26},
  200. [2] = { .submit = 5, .complete = 26},
  201. [3] = { .submit = 7, .complete = 26},
  202. };
  203. struct cppi_glue_infos {
  204. const struct chan_queues *queues_rx;
  205. const struct chan_queues *queues_tx;
  206. struct chan_queues td_queue;
  207. u16 first_completion_queue;
  208. u16 qmgr_num_pend;
  209. };
  210. static struct cppi41_channel *to_cpp41_chan(struct dma_chan *c)
  211. {
  212. return container_of(c, struct cppi41_channel, chan);
  213. }
  214. static struct cppi41_channel *desc_to_chan(struct cppi41_dd *cdd, u32 desc)
  215. {
  216. struct cppi41_channel *c;
  217. u32 descs_size;
  218. u32 desc_num;
  219. descs_size = sizeof(struct cppi41_desc) * ALLOC_DECS_NUM;
  220. if (!((desc >= cdd->descs_phys) &&
  221. (desc < (cdd->descs_phys + descs_size)))) {
  222. return NULL;
  223. }
  224. desc_num = (desc - cdd->descs_phys) / sizeof(struct cppi41_desc);
  225. BUG_ON(desc_num >= ALLOC_DECS_NUM);
  226. c = cdd->chan_busy[desc_num];
  227. cdd->chan_busy[desc_num] = NULL;
  228. /* Usecount for chan_busy[], paired with push_desc_queue() */
  229. pm_runtime_put(cdd->ddev.dev);
  230. return c;
  231. }
  232. static void cppi_writel(u32 val, void *__iomem *mem)
  233. {
  234. __raw_writel(val, mem);
  235. }
  236. static u32 cppi_readl(void *__iomem *mem)
  237. {
  238. return __raw_readl(mem);
  239. }
  240. static u32 pd_trans_len(u32 val)
  241. {
  242. return val & ((1 << (DESC_LENGTH_BITS_NUM + 1)) - 1);
  243. }
  244. static u32 cppi41_pop_desc(struct cppi41_dd *cdd, unsigned queue_num)
  245. {
  246. u32 desc;
  247. desc = cppi_readl(cdd->qmgr_mem + QMGR_QUEUE_D(queue_num));
  248. desc &= ~0x1f;
  249. return desc;
  250. }
  251. static irqreturn_t cppi41_irq(int irq, void *data)
  252. {
  253. struct cppi41_dd *cdd = data;
  254. u16 first_completion_queue = cdd->first_completion_queue;
  255. u16 qmgr_num_pend = cdd->qmgr_num_pend;
  256. struct cppi41_channel *c;
  257. int i;
  258. for (i = QMGR_PENDING_SLOT_Q(first_completion_queue); i < qmgr_num_pend;
  259. i++) {
  260. u32 val;
  261. u32 q_num;
  262. val = cppi_readl(cdd->qmgr_mem + QMGR_PEND(i));
  263. if (i == QMGR_PENDING_SLOT_Q(first_completion_queue) && val) {
  264. u32 mask;
  265. /* set corresponding bit for completetion Q 93 */
  266. mask = 1 << QMGR_PENDING_BIT_Q(first_completion_queue);
  267. /* not set all bits for queues less than Q 93 */
  268. mask--;
  269. /* now invert and keep only Q 93+ set */
  270. val &= ~mask;
  271. }
  272. if (val)
  273. __iormb();
  274. while (val) {
  275. u32 desc, len;
  276. /*
  277. * This should never trigger, see the comments in
  278. * push_desc_queue()
  279. */
  280. WARN_ON(cdd->is_suspended);
  281. q_num = __fls(val);
  282. val &= ~(1 << q_num);
  283. q_num += 32 * i;
  284. desc = cppi41_pop_desc(cdd, q_num);
  285. c = desc_to_chan(cdd, desc);
  286. if (WARN_ON(!c)) {
  287. pr_err("%s() q %d desc %08x\n", __func__,
  288. q_num, desc);
  289. continue;
  290. }
  291. if (c->desc->pd2 & PD2_ZERO_LENGTH)
  292. len = 0;
  293. else
  294. len = pd_trans_len(c->desc->pd0);
  295. c->residue = pd_trans_len(c->desc->pd6) - len;
  296. dma_cookie_complete(&c->txd);
  297. dmaengine_desc_get_callback_invoke(&c->txd, NULL);
  298. }
  299. }
  300. return IRQ_HANDLED;
  301. }
  302. static dma_cookie_t cppi41_tx_submit(struct dma_async_tx_descriptor *tx)
  303. {
  304. dma_cookie_t cookie;
  305. cookie = dma_cookie_assign(tx);
  306. return cookie;
  307. }
  308. static int cppi41_dma_alloc_chan_resources(struct dma_chan *chan)
  309. {
  310. struct cppi41_channel *c = to_cpp41_chan(chan);
  311. struct cppi41_dd *cdd = c->cdd;
  312. int error;
  313. error = pm_runtime_get_sync(cdd->ddev.dev);
  314. if (error < 0) {
  315. dev_err(cdd->ddev.dev, "%s pm runtime get: %i\n",
  316. __func__, error);
  317. pm_runtime_put_noidle(cdd->ddev.dev);
  318. return error;
  319. }
  320. dma_cookie_init(chan);
  321. dma_async_tx_descriptor_init(&c->txd, chan);
  322. c->txd.tx_submit = cppi41_tx_submit;
  323. if (!c->is_tx)
  324. cppi_writel(c->q_num, c->gcr_reg + RXHPCRA0);
  325. pm_runtime_mark_last_busy(cdd->ddev.dev);
  326. pm_runtime_put_autosuspend(cdd->ddev.dev);
  327. return 0;
  328. }
  329. static void cppi41_dma_free_chan_resources(struct dma_chan *chan)
  330. {
  331. struct cppi41_channel *c = to_cpp41_chan(chan);
  332. struct cppi41_dd *cdd = c->cdd;
  333. int error;
  334. error = pm_runtime_get_sync(cdd->ddev.dev);
  335. if (error < 0) {
  336. pm_runtime_put_noidle(cdd->ddev.dev);
  337. return;
  338. }
  339. WARN_ON(!list_empty(&cdd->pending));
  340. pm_runtime_mark_last_busy(cdd->ddev.dev);
  341. pm_runtime_put_autosuspend(cdd->ddev.dev);
  342. }
  343. static enum dma_status cppi41_dma_tx_status(struct dma_chan *chan,
  344. dma_cookie_t cookie, struct dma_tx_state *txstate)
  345. {
  346. struct cppi41_channel *c = to_cpp41_chan(chan);
  347. enum dma_status ret;
  348. ret = dma_cookie_status(chan, cookie, txstate);
  349. dma_set_residue(txstate, c->residue);
  350. return ret;
  351. }
  352. static void push_desc_queue(struct cppi41_channel *c)
  353. {
  354. struct cppi41_dd *cdd = c->cdd;
  355. u32 desc_num;
  356. u32 desc_phys;
  357. u32 reg;
  358. c->residue = 0;
  359. reg = GCR_CHAN_ENABLE;
  360. if (!c->is_tx) {
  361. reg |= GCR_STARV_RETRY;
  362. reg |= GCR_DESC_TYPE_HOST;
  363. reg |= c->q_comp_num;
  364. }
  365. cppi_writel(reg, c->gcr_reg);
  366. /*
  367. * We don't use writel() but __raw_writel() so we have to make sure
  368. * that the DMA descriptor in coherent memory made to the main memory
  369. * before starting the dma engine.
  370. */
  371. __iowmb();
  372. /*
  373. * DMA transfers can take at least 200ms to complete with USB mass
  374. * storage connected. To prevent autosuspend timeouts, we must use
  375. * pm_runtime_get/put() when chan_busy[] is modified. This will get
  376. * cleared in desc_to_chan() or cppi41_stop_chan() depending on the
  377. * outcome of the transfer.
  378. */
  379. pm_runtime_get(cdd->ddev.dev);
  380. desc_phys = lower_32_bits(c->desc_phys);
  381. desc_num = (desc_phys - cdd->descs_phys) / sizeof(struct cppi41_desc);
  382. WARN_ON(cdd->chan_busy[desc_num]);
  383. cdd->chan_busy[desc_num] = c;
  384. reg = (sizeof(struct cppi41_desc) - 24) / 4;
  385. reg |= desc_phys;
  386. cppi_writel(reg, cdd->qmgr_mem + QMGR_QUEUE_D(c->q_num));
  387. }
  388. /*
  389. * Caller must hold cdd->lock to prevent push_desc_queue()
  390. * getting called out of order. We have both cppi41_dma_issue_pending()
  391. * and cppi41_runtime_resume() call this function.
  392. */
  393. static void cppi41_run_queue(struct cppi41_dd *cdd)
  394. {
  395. struct cppi41_channel *c, *_c;
  396. list_for_each_entry_safe(c, _c, &cdd->pending, node) {
  397. push_desc_queue(c);
  398. list_del(&c->node);
  399. }
  400. }
  401. static void cppi41_dma_issue_pending(struct dma_chan *chan)
  402. {
  403. struct cppi41_channel *c = to_cpp41_chan(chan);
  404. struct cppi41_dd *cdd = c->cdd;
  405. unsigned long flags;
  406. int error;
  407. error = pm_runtime_get(cdd->ddev.dev);
  408. if ((error != -EINPROGRESS) && error < 0) {
  409. pm_runtime_put_noidle(cdd->ddev.dev);
  410. dev_err(cdd->ddev.dev, "Failed to pm_runtime_get: %i\n",
  411. error);
  412. return;
  413. }
  414. spin_lock_irqsave(&cdd->lock, flags);
  415. list_add_tail(&c->node, &cdd->pending);
  416. if (!cdd->is_suspended)
  417. cppi41_run_queue(cdd);
  418. spin_unlock_irqrestore(&cdd->lock, flags);
  419. pm_runtime_mark_last_busy(cdd->ddev.dev);
  420. pm_runtime_put_autosuspend(cdd->ddev.dev);
  421. }
  422. static u32 get_host_pd0(u32 length)
  423. {
  424. u32 reg;
  425. reg = DESC_TYPE_HOST << DESC_TYPE;
  426. reg |= length;
  427. return reg;
  428. }
  429. static u32 get_host_pd1(struct cppi41_channel *c)
  430. {
  431. u32 reg;
  432. reg = 0;
  433. return reg;
  434. }
  435. static u32 get_host_pd2(struct cppi41_channel *c)
  436. {
  437. u32 reg;
  438. reg = DESC_TYPE_USB;
  439. reg |= c->q_comp_num;
  440. return reg;
  441. }
  442. static u32 get_host_pd3(u32 length)
  443. {
  444. u32 reg;
  445. /* PD3 = packet size */
  446. reg = length;
  447. return reg;
  448. }
  449. static u32 get_host_pd6(u32 length)
  450. {
  451. u32 reg;
  452. /* PD6 buffer size */
  453. reg = DESC_PD_COMPLETE;
  454. reg |= length;
  455. return reg;
  456. }
  457. static u32 get_host_pd4_or_7(u32 addr)
  458. {
  459. u32 reg;
  460. reg = addr;
  461. return reg;
  462. }
  463. static u32 get_host_pd5(void)
  464. {
  465. u32 reg;
  466. reg = 0;
  467. return reg;
  468. }
  469. static struct dma_async_tx_descriptor *cppi41_dma_prep_slave_sg(
  470. struct dma_chan *chan, struct scatterlist *sgl, unsigned sg_len,
  471. enum dma_transfer_direction dir, unsigned long tx_flags, void *context)
  472. {
  473. struct cppi41_channel *c = to_cpp41_chan(chan);
  474. struct cppi41_desc *d;
  475. struct scatterlist *sg;
  476. unsigned int i;
  477. d = c->desc;
  478. for_each_sg(sgl, sg, sg_len, i) {
  479. u32 addr;
  480. u32 len;
  481. /* We need to use more than one desc once musb supports sg */
  482. addr = lower_32_bits(sg_dma_address(sg));
  483. len = sg_dma_len(sg);
  484. d->pd0 = get_host_pd0(len);
  485. d->pd1 = get_host_pd1(c);
  486. d->pd2 = get_host_pd2(c);
  487. d->pd3 = get_host_pd3(len);
  488. d->pd4 = get_host_pd4_or_7(addr);
  489. d->pd5 = get_host_pd5();
  490. d->pd6 = get_host_pd6(len);
  491. d->pd7 = get_host_pd4_or_7(addr);
  492. d++;
  493. }
  494. return &c->txd;
  495. }
  496. static void cppi41_compute_td_desc(struct cppi41_desc *d)
  497. {
  498. d->pd0 = DESC_TYPE_TEARD << DESC_TYPE;
  499. }
  500. static int cppi41_tear_down_chan(struct cppi41_channel *c)
  501. {
  502. struct dmaengine_result abort_result;
  503. struct cppi41_dd *cdd = c->cdd;
  504. struct cppi41_desc *td;
  505. u32 reg;
  506. u32 desc_phys;
  507. u32 td_desc_phys;
  508. td = cdd->cd;
  509. td += cdd->first_td_desc;
  510. td_desc_phys = cdd->descs_phys;
  511. td_desc_phys += cdd->first_td_desc * sizeof(struct cppi41_desc);
  512. if (!c->td_queued) {
  513. cppi41_compute_td_desc(td);
  514. __iowmb();
  515. reg = (sizeof(struct cppi41_desc) - 24) / 4;
  516. reg |= td_desc_phys;
  517. cppi_writel(reg, cdd->qmgr_mem +
  518. QMGR_QUEUE_D(cdd->td_queue.submit));
  519. reg = GCR_CHAN_ENABLE;
  520. if (!c->is_tx) {
  521. reg |= GCR_STARV_RETRY;
  522. reg |= GCR_DESC_TYPE_HOST;
  523. reg |= cdd->td_queue.complete;
  524. }
  525. reg |= GCR_TEARDOWN;
  526. cppi_writel(reg, c->gcr_reg);
  527. c->td_queued = 1;
  528. c->td_retry = 500;
  529. }
  530. if (!c->td_seen || !c->td_desc_seen) {
  531. desc_phys = cppi41_pop_desc(cdd, cdd->td_queue.complete);
  532. if (!desc_phys && c->is_tx)
  533. desc_phys = cppi41_pop_desc(cdd, c->q_comp_num);
  534. if (desc_phys == c->desc_phys) {
  535. c->td_desc_seen = 1;
  536. } else if (desc_phys == td_desc_phys) {
  537. u32 pd0;
  538. __iormb();
  539. pd0 = td->pd0;
  540. WARN_ON((pd0 >> DESC_TYPE) != DESC_TYPE_TEARD);
  541. WARN_ON(!c->is_tx && !(pd0 & TD_DESC_IS_RX));
  542. WARN_ON((pd0 & 0x1f) != c->port_num);
  543. c->td_seen = 1;
  544. } else if (desc_phys) {
  545. WARN_ON_ONCE(1);
  546. }
  547. }
  548. c->td_retry--;
  549. /*
  550. * If the TX descriptor / channel is in use, the caller needs to poke
  551. * his TD bit multiple times. After that he hardware releases the
  552. * transfer descriptor followed by TD descriptor. Waiting seems not to
  553. * cause any difference.
  554. * RX seems to be thrown out right away. However once the TearDown
  555. * descriptor gets through we are done. If we have seens the transfer
  556. * descriptor before the TD we fetch it from enqueue, it has to be
  557. * there waiting for us.
  558. */
  559. if (!c->td_seen && c->td_retry) {
  560. udelay(1);
  561. return -EAGAIN;
  562. }
  563. WARN_ON(!c->td_retry);
  564. if (!c->td_desc_seen) {
  565. desc_phys = cppi41_pop_desc(cdd, c->q_num);
  566. if (!desc_phys)
  567. desc_phys = cppi41_pop_desc(cdd, c->q_comp_num);
  568. WARN_ON(!desc_phys);
  569. }
  570. c->td_queued = 0;
  571. c->td_seen = 0;
  572. c->td_desc_seen = 0;
  573. cppi_writel(0, c->gcr_reg);
  574. /* Invoke the callback to do the necessary clean-up */
  575. abort_result.result = DMA_TRANS_ABORTED;
  576. dma_cookie_complete(&c->txd);
  577. dmaengine_desc_get_callback_invoke(&c->txd, &abort_result);
  578. return 0;
  579. }
  580. static int cppi41_stop_chan(struct dma_chan *chan)
  581. {
  582. struct cppi41_channel *c = to_cpp41_chan(chan);
  583. struct cppi41_dd *cdd = c->cdd;
  584. u32 desc_num;
  585. u32 desc_phys;
  586. int ret;
  587. desc_phys = lower_32_bits(c->desc_phys);
  588. desc_num = (desc_phys - cdd->descs_phys) / sizeof(struct cppi41_desc);
  589. if (!cdd->chan_busy[desc_num]) {
  590. struct cppi41_channel *cc, *_ct;
  591. /*
  592. * channels might still be in the pendling list if
  593. * cppi41_dma_issue_pending() is called after
  594. * cppi41_runtime_suspend() is called
  595. */
  596. list_for_each_entry_safe(cc, _ct, &cdd->pending, node) {
  597. if (cc != c)
  598. continue;
  599. list_del(&cc->node);
  600. break;
  601. }
  602. return 0;
  603. }
  604. ret = cppi41_tear_down_chan(c);
  605. if (ret)
  606. return ret;
  607. WARN_ON(!cdd->chan_busy[desc_num]);
  608. cdd->chan_busy[desc_num] = NULL;
  609. /* Usecount for chan_busy[], paired with push_desc_queue() */
  610. pm_runtime_put(cdd->ddev.dev);
  611. return 0;
  612. }
  613. static int cppi41_add_chans(struct device *dev, struct cppi41_dd *cdd)
  614. {
  615. struct cppi41_channel *cchan, *chans;
  616. int i;
  617. u32 n_chans = cdd->n_chans;
  618. /*
  619. * The channels can only be used as TX or as RX. So we add twice
  620. * that much dma channels because USB can only do RX or TX.
  621. */
  622. n_chans *= 2;
  623. chans = devm_kcalloc(dev, n_chans, sizeof(*chans), GFP_KERNEL);
  624. if (!chans)
  625. return -ENOMEM;
  626. for (i = 0; i < n_chans; i++) {
  627. cchan = &chans[i];
  628. cchan->cdd = cdd;
  629. if (i & 1) {
  630. cchan->gcr_reg = cdd->ctrl_mem + DMA_TXGCR(i >> 1);
  631. cchan->is_tx = 1;
  632. } else {
  633. cchan->gcr_reg = cdd->ctrl_mem + DMA_RXGCR(i >> 1);
  634. cchan->is_tx = 0;
  635. }
  636. cchan->port_num = i >> 1;
  637. cchan->desc = &cdd->cd[i];
  638. cchan->desc_phys = cdd->descs_phys;
  639. cchan->desc_phys += i * sizeof(struct cppi41_desc);
  640. cchan->chan.device = &cdd->ddev;
  641. list_add_tail(&cchan->chan.device_node, &cdd->ddev.channels);
  642. }
  643. cdd->first_td_desc = n_chans;
  644. return 0;
  645. }
  646. static void purge_descs(struct device *dev, struct cppi41_dd *cdd)
  647. {
  648. unsigned int mem_decs;
  649. int i;
  650. mem_decs = ALLOC_DECS_NUM * sizeof(struct cppi41_desc);
  651. for (i = 0; i < DESCS_AREAS; i++) {
  652. cppi_writel(0, cdd->qmgr_mem + QMGR_MEMBASE(i));
  653. cppi_writel(0, cdd->qmgr_mem + QMGR_MEMCTRL(i));
  654. dma_free_coherent(dev, mem_decs, cdd->cd,
  655. cdd->descs_phys);
  656. }
  657. }
  658. static void disable_sched(struct cppi41_dd *cdd)
  659. {
  660. cppi_writel(0, cdd->sched_mem + DMA_SCHED_CTRL);
  661. }
  662. static void deinit_cppi41(struct device *dev, struct cppi41_dd *cdd)
  663. {
  664. disable_sched(cdd);
  665. purge_descs(dev, cdd);
  666. cppi_writel(0, cdd->qmgr_mem + QMGR_LRAM0_BASE);
  667. cppi_writel(0, cdd->qmgr_mem + QMGR_LRAM0_BASE);
  668. dma_free_coherent(dev, QMGR_SCRATCH_SIZE, cdd->qmgr_scratch,
  669. cdd->scratch_phys);
  670. }
  671. static int init_descs(struct device *dev, struct cppi41_dd *cdd)
  672. {
  673. unsigned int desc_size;
  674. unsigned int mem_decs;
  675. int i;
  676. u32 reg;
  677. u32 idx;
  678. BUILD_BUG_ON(sizeof(struct cppi41_desc) &
  679. (sizeof(struct cppi41_desc) - 1));
  680. BUILD_BUG_ON(sizeof(struct cppi41_desc) < 32);
  681. BUILD_BUG_ON(ALLOC_DECS_NUM < 32);
  682. desc_size = sizeof(struct cppi41_desc);
  683. mem_decs = ALLOC_DECS_NUM * desc_size;
  684. idx = 0;
  685. for (i = 0; i < DESCS_AREAS; i++) {
  686. reg = idx << QMGR_MEMCTRL_IDX_SH;
  687. reg |= (ilog2(desc_size) - 5) << QMGR_MEMCTRL_DESC_SH;
  688. reg |= ilog2(ALLOC_DECS_NUM) - 5;
  689. BUILD_BUG_ON(DESCS_AREAS != 1);
  690. cdd->cd = dma_alloc_coherent(dev, mem_decs,
  691. &cdd->descs_phys, GFP_KERNEL);
  692. if (!cdd->cd)
  693. return -ENOMEM;
  694. cppi_writel(cdd->descs_phys, cdd->qmgr_mem + QMGR_MEMBASE(i));
  695. cppi_writel(reg, cdd->qmgr_mem + QMGR_MEMCTRL(i));
  696. idx += ALLOC_DECS_NUM;
  697. }
  698. return 0;
  699. }
  700. static void init_sched(struct cppi41_dd *cdd)
  701. {
  702. unsigned ch;
  703. unsigned word;
  704. u32 reg;
  705. word = 0;
  706. cppi_writel(0, cdd->sched_mem + DMA_SCHED_CTRL);
  707. for (ch = 0; ch < cdd->n_chans; ch += 2) {
  708. reg = SCHED_ENTRY0_CHAN(ch);
  709. reg |= SCHED_ENTRY1_CHAN(ch) | SCHED_ENTRY1_IS_RX;
  710. reg |= SCHED_ENTRY2_CHAN(ch + 1);
  711. reg |= SCHED_ENTRY3_CHAN(ch + 1) | SCHED_ENTRY3_IS_RX;
  712. cppi_writel(reg, cdd->sched_mem + DMA_SCHED_WORD(word));
  713. word++;
  714. }
  715. reg = cdd->n_chans * 2 - 1;
  716. reg |= DMA_SCHED_CTRL_EN;
  717. cppi_writel(reg, cdd->sched_mem + DMA_SCHED_CTRL);
  718. }
  719. static int init_cppi41(struct device *dev, struct cppi41_dd *cdd)
  720. {
  721. int ret;
  722. BUILD_BUG_ON(QMGR_SCRATCH_SIZE > ((1 << 14) - 1));
  723. cdd->qmgr_scratch = dma_alloc_coherent(dev, QMGR_SCRATCH_SIZE,
  724. &cdd->scratch_phys, GFP_KERNEL);
  725. if (!cdd->qmgr_scratch)
  726. return -ENOMEM;
  727. cppi_writel(cdd->scratch_phys, cdd->qmgr_mem + QMGR_LRAM0_BASE);
  728. cppi_writel(TOTAL_DESCS_NUM, cdd->qmgr_mem + QMGR_LRAM_SIZE);
  729. cppi_writel(0, cdd->qmgr_mem + QMGR_LRAM1_BASE);
  730. ret = init_descs(dev, cdd);
  731. if (ret)
  732. goto err_td;
  733. cppi_writel(cdd->td_queue.submit, cdd->ctrl_mem + DMA_TDFDQ);
  734. init_sched(cdd);
  735. return 0;
  736. err_td:
  737. deinit_cppi41(dev, cdd);
  738. return ret;
  739. }
  740. static struct platform_driver cpp41_dma_driver;
  741. /*
  742. * The param format is:
  743. * X Y
  744. * X: Port
  745. * Y: 0 = RX else TX
  746. */
  747. #define INFO_PORT 0
  748. #define INFO_IS_TX 1
  749. static bool cpp41_dma_filter_fn(struct dma_chan *chan, void *param)
  750. {
  751. struct cppi41_channel *cchan;
  752. struct cppi41_dd *cdd;
  753. const struct chan_queues *queues;
  754. u32 *num = param;
  755. if (chan->device->dev->driver != &cpp41_dma_driver.driver)
  756. return false;
  757. cchan = to_cpp41_chan(chan);
  758. if (cchan->port_num != num[INFO_PORT])
  759. return false;
  760. if (cchan->is_tx && !num[INFO_IS_TX])
  761. return false;
  762. cdd = cchan->cdd;
  763. if (cchan->is_tx)
  764. queues = cdd->queues_tx;
  765. else
  766. queues = cdd->queues_rx;
  767. BUILD_BUG_ON(ARRAY_SIZE(am335x_usb_queues_rx) !=
  768. ARRAY_SIZE(am335x_usb_queues_tx));
  769. if (WARN_ON(cchan->port_num >= ARRAY_SIZE(am335x_usb_queues_rx)))
  770. return false;
  771. cchan->q_num = queues[cchan->port_num].submit;
  772. cchan->q_comp_num = queues[cchan->port_num].complete;
  773. return true;
  774. }
  775. static struct of_dma_filter_info cpp41_dma_info = {
  776. .filter_fn = cpp41_dma_filter_fn,
  777. };
  778. static struct dma_chan *cppi41_dma_xlate(struct of_phandle_args *dma_spec,
  779. struct of_dma *ofdma)
  780. {
  781. int count = dma_spec->args_count;
  782. struct of_dma_filter_info *info = ofdma->of_dma_data;
  783. if (!info || !info->filter_fn)
  784. return NULL;
  785. if (count != 2)
  786. return NULL;
  787. return dma_request_channel(info->dma_cap, info->filter_fn,
  788. &dma_spec->args[0]);
  789. }
  790. static const struct cppi_glue_infos am335x_usb_infos = {
  791. .queues_rx = am335x_usb_queues_rx,
  792. .queues_tx = am335x_usb_queues_tx,
  793. .td_queue = { .submit = 31, .complete = 0 },
  794. .first_completion_queue = 93,
  795. .qmgr_num_pend = 5,
  796. };
  797. static const struct cppi_glue_infos da8xx_usb_infos = {
  798. .queues_rx = da8xx_usb_queues_rx,
  799. .queues_tx = da8xx_usb_queues_tx,
  800. .td_queue = { .submit = 31, .complete = 0 },
  801. .first_completion_queue = 24,
  802. .qmgr_num_pend = 2,
  803. };
  804. static const struct of_device_id cppi41_dma_ids[] = {
  805. { .compatible = "ti,am3359-cppi41", .data = &am335x_usb_infos},
  806. { .compatible = "ti,da830-cppi41", .data = &da8xx_usb_infos},
  807. {},
  808. };
  809. MODULE_DEVICE_TABLE(of, cppi41_dma_ids);
  810. static const struct cppi_glue_infos *get_glue_info(struct device *dev)
  811. {
  812. const struct of_device_id *of_id;
  813. of_id = of_match_node(cppi41_dma_ids, dev->of_node);
  814. if (!of_id)
  815. return NULL;
  816. return of_id->data;
  817. }
  818. #define CPPI41_DMA_BUSWIDTHS (BIT(DMA_SLAVE_BUSWIDTH_1_BYTE) | \
  819. BIT(DMA_SLAVE_BUSWIDTH_2_BYTES) | \
  820. BIT(DMA_SLAVE_BUSWIDTH_3_BYTES) | \
  821. BIT(DMA_SLAVE_BUSWIDTH_4_BYTES))
  822. static int cppi41_dma_probe(struct platform_device *pdev)
  823. {
  824. struct cppi41_dd *cdd;
  825. struct device *dev = &pdev->dev;
  826. const struct cppi_glue_infos *glue_info;
  827. struct resource *mem;
  828. int index;
  829. int irq;
  830. int ret;
  831. glue_info = get_glue_info(dev);
  832. if (!glue_info)
  833. return -EINVAL;
  834. cdd = devm_kzalloc(&pdev->dev, sizeof(*cdd), GFP_KERNEL);
  835. if (!cdd)
  836. return -ENOMEM;
  837. dma_cap_set(DMA_SLAVE, cdd->ddev.cap_mask);
  838. cdd->ddev.device_alloc_chan_resources = cppi41_dma_alloc_chan_resources;
  839. cdd->ddev.device_free_chan_resources = cppi41_dma_free_chan_resources;
  840. cdd->ddev.device_tx_status = cppi41_dma_tx_status;
  841. cdd->ddev.device_issue_pending = cppi41_dma_issue_pending;
  842. cdd->ddev.device_prep_slave_sg = cppi41_dma_prep_slave_sg;
  843. cdd->ddev.device_terminate_all = cppi41_stop_chan;
  844. cdd->ddev.directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV);
  845. cdd->ddev.src_addr_widths = CPPI41_DMA_BUSWIDTHS;
  846. cdd->ddev.dst_addr_widths = CPPI41_DMA_BUSWIDTHS;
  847. cdd->ddev.residue_granularity = DMA_RESIDUE_GRANULARITY_BURST;
  848. cdd->ddev.dev = dev;
  849. INIT_LIST_HEAD(&cdd->ddev.channels);
  850. cpp41_dma_info.dma_cap = cdd->ddev.cap_mask;
  851. index = of_property_match_string(dev->of_node,
  852. "reg-names", "controller");
  853. if (index < 0)
  854. return index;
  855. mem = platform_get_resource(pdev, IORESOURCE_MEM, index);
  856. cdd->ctrl_mem = devm_ioremap_resource(dev, mem);
  857. if (IS_ERR(cdd->ctrl_mem))
  858. return PTR_ERR(cdd->ctrl_mem);
  859. mem = platform_get_resource(pdev, IORESOURCE_MEM, index + 1);
  860. cdd->sched_mem = devm_ioremap_resource(dev, mem);
  861. if (IS_ERR(cdd->sched_mem))
  862. return PTR_ERR(cdd->sched_mem);
  863. mem = platform_get_resource(pdev, IORESOURCE_MEM, index + 2);
  864. cdd->qmgr_mem = devm_ioremap_resource(dev, mem);
  865. if (IS_ERR(cdd->qmgr_mem))
  866. return PTR_ERR(cdd->qmgr_mem);
  867. spin_lock_init(&cdd->lock);
  868. INIT_LIST_HEAD(&cdd->pending);
  869. platform_set_drvdata(pdev, cdd);
  870. pm_runtime_enable(dev);
  871. pm_runtime_set_autosuspend_delay(dev, 100);
  872. pm_runtime_use_autosuspend(dev);
  873. ret = pm_runtime_get_sync(dev);
  874. if (ret < 0)
  875. goto err_get_sync;
  876. cdd->queues_rx = glue_info->queues_rx;
  877. cdd->queues_tx = glue_info->queues_tx;
  878. cdd->td_queue = glue_info->td_queue;
  879. cdd->qmgr_num_pend = glue_info->qmgr_num_pend;
  880. cdd->first_completion_queue = glue_info->first_completion_queue;
  881. ret = of_property_read_u32(dev->of_node,
  882. "#dma-channels", &cdd->n_chans);
  883. if (ret)
  884. goto err_get_n_chans;
  885. ret = init_cppi41(dev, cdd);
  886. if (ret)
  887. goto err_init_cppi;
  888. ret = cppi41_add_chans(dev, cdd);
  889. if (ret)
  890. goto err_chans;
  891. irq = irq_of_parse_and_map(dev->of_node, 0);
  892. if (!irq) {
  893. ret = -EINVAL;
  894. goto err_chans;
  895. }
  896. ret = devm_request_irq(&pdev->dev, irq, cppi41_irq, IRQF_SHARED,
  897. dev_name(dev), cdd);
  898. if (ret)
  899. goto err_chans;
  900. cdd->irq = irq;
  901. ret = dma_async_device_register(&cdd->ddev);
  902. if (ret)
  903. goto err_chans;
  904. ret = of_dma_controller_register(dev->of_node,
  905. cppi41_dma_xlate, &cpp41_dma_info);
  906. if (ret)
  907. goto err_of;
  908. pm_runtime_mark_last_busy(dev);
  909. pm_runtime_put_autosuspend(dev);
  910. return 0;
  911. err_of:
  912. dma_async_device_unregister(&cdd->ddev);
  913. err_chans:
  914. deinit_cppi41(dev, cdd);
  915. err_init_cppi:
  916. pm_runtime_dont_use_autosuspend(dev);
  917. err_get_n_chans:
  918. err_get_sync:
  919. pm_runtime_put_sync(dev);
  920. pm_runtime_disable(dev);
  921. return ret;
  922. }
  923. static int cppi41_dma_remove(struct platform_device *pdev)
  924. {
  925. struct cppi41_dd *cdd = platform_get_drvdata(pdev);
  926. int error;
  927. error = pm_runtime_get_sync(&pdev->dev);
  928. if (error < 0)
  929. dev_err(&pdev->dev, "%s could not pm_runtime_get: %i\n",
  930. __func__, error);
  931. of_dma_controller_free(pdev->dev.of_node);
  932. dma_async_device_unregister(&cdd->ddev);
  933. devm_free_irq(&pdev->dev, cdd->irq, cdd);
  934. deinit_cppi41(&pdev->dev, cdd);
  935. pm_runtime_dont_use_autosuspend(&pdev->dev);
  936. pm_runtime_put_sync(&pdev->dev);
  937. pm_runtime_disable(&pdev->dev);
  938. return 0;
  939. }
  940. static int __maybe_unused cppi41_suspend(struct device *dev)
  941. {
  942. struct cppi41_dd *cdd = dev_get_drvdata(dev);
  943. cdd->dma_tdfdq = cppi_readl(cdd->ctrl_mem + DMA_TDFDQ);
  944. disable_sched(cdd);
  945. return 0;
  946. }
  947. static int __maybe_unused cppi41_resume(struct device *dev)
  948. {
  949. struct cppi41_dd *cdd = dev_get_drvdata(dev);
  950. struct cppi41_channel *c;
  951. int i;
  952. for (i = 0; i < DESCS_AREAS; i++)
  953. cppi_writel(cdd->descs_phys, cdd->qmgr_mem + QMGR_MEMBASE(i));
  954. list_for_each_entry(c, &cdd->ddev.channels, chan.device_node)
  955. if (!c->is_tx)
  956. cppi_writel(c->q_num, c->gcr_reg + RXHPCRA0);
  957. init_sched(cdd);
  958. cppi_writel(cdd->dma_tdfdq, cdd->ctrl_mem + DMA_TDFDQ);
  959. cppi_writel(cdd->scratch_phys, cdd->qmgr_mem + QMGR_LRAM0_BASE);
  960. cppi_writel(QMGR_SCRATCH_SIZE, cdd->qmgr_mem + QMGR_LRAM_SIZE);
  961. cppi_writel(0, cdd->qmgr_mem + QMGR_LRAM1_BASE);
  962. return 0;
  963. }
  964. static int __maybe_unused cppi41_runtime_suspend(struct device *dev)
  965. {
  966. struct cppi41_dd *cdd = dev_get_drvdata(dev);
  967. unsigned long flags;
  968. spin_lock_irqsave(&cdd->lock, flags);
  969. cdd->is_suspended = true;
  970. WARN_ON(!list_empty(&cdd->pending));
  971. spin_unlock_irqrestore(&cdd->lock, flags);
  972. return 0;
  973. }
  974. static int __maybe_unused cppi41_runtime_resume(struct device *dev)
  975. {
  976. struct cppi41_dd *cdd = dev_get_drvdata(dev);
  977. unsigned long flags;
  978. spin_lock_irqsave(&cdd->lock, flags);
  979. cdd->is_suspended = false;
  980. cppi41_run_queue(cdd);
  981. spin_unlock_irqrestore(&cdd->lock, flags);
  982. return 0;
  983. }
  984. static const struct dev_pm_ops cppi41_pm_ops = {
  985. SET_LATE_SYSTEM_SLEEP_PM_OPS(cppi41_suspend, cppi41_resume)
  986. SET_RUNTIME_PM_OPS(cppi41_runtime_suspend,
  987. cppi41_runtime_resume,
  988. NULL)
  989. };
  990. static struct platform_driver cpp41_dma_driver = {
  991. .probe = cppi41_dma_probe,
  992. .remove = cppi41_dma_remove,
  993. .driver = {
  994. .name = "cppi41-dma-engine",
  995. .pm = &cppi41_pm_ops,
  996. .of_match_table = of_match_ptr(cppi41_dma_ids),
  997. },
  998. };
  999. module_platform_driver(cpp41_dma_driver);
  1000. MODULE_LICENSE("GPL");
  1001. MODULE_AUTHOR("Sebastian Andrzej Siewior <bigeasy@linutronix.de>");