imx-mailbox.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2018 Pengutronix, Oleksij Rempel <o.rempel@pengutronix.de>
  4. * Copyright 2022 NXP, Peng Fan <peng.fan@nxp.com>
  5. */
  6. #include <linux/bitfield.h>
  7. #include <linux/clk.h>
  8. #include <linux/firmware/imx/ipc.h>
  9. #include <linux/firmware/imx/s4.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/io.h>
  12. #include <linux/iopoll.h>
  13. #include <linux/jiffies.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mailbox_controller.h>
  16. #include <linux/module.h>
  17. #include <linux/of.h>
  18. #include <linux/of_platform.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/pm_runtime.h>
  21. #include <linux/suspend.h>
  22. #include <linux/slab.h>
  23. #include <linux/workqueue.h>
  24. #include "mailbox.h"
  25. #define IMX_MU_CHANS 24
  26. /* TX0/RX0/RXDB[0-3] */
  27. #define IMX_MU_SCU_CHANS 6
  28. /* TX0/RX0 */
  29. #define IMX_MU_S4_CHANS 2
  30. #define IMX_MU_CHAN_NAME_SIZE 32
  31. #define IMX_MU_V2_PAR_OFF 0x4
  32. #define IMX_MU_V2_TR_MASK GENMASK(7, 0)
  33. #define IMX_MU_V2_RR_MASK GENMASK(15, 8)
  34. #define IMX_MU_SECO_TX_TOUT (msecs_to_jiffies(3000))
  35. #define IMX_MU_SECO_RX_TOUT (msecs_to_jiffies(3000))
  36. /* Please not change TX & RX */
  37. enum imx_mu_chan_type {
  38. IMX_MU_TYPE_TX = 0, /* Tx */
  39. IMX_MU_TYPE_RX = 1, /* Rx */
  40. IMX_MU_TYPE_TXDB = 2, /* Tx doorbell */
  41. IMX_MU_TYPE_RXDB = 3, /* Rx doorbell */
  42. IMX_MU_TYPE_RST = 4, /* Reset */
  43. IMX_MU_TYPE_TXDB_V2 = 5, /* Tx doorbell with S/W ACK */
  44. };
  45. enum imx_mu_xcr {
  46. IMX_MU_CR,
  47. IMX_MU_GIER,
  48. IMX_MU_GCR,
  49. IMX_MU_TCR,
  50. IMX_MU_RCR,
  51. IMX_MU_xCR_MAX,
  52. };
  53. enum imx_mu_xsr {
  54. IMX_MU_SR,
  55. IMX_MU_GSR,
  56. IMX_MU_TSR,
  57. IMX_MU_RSR,
  58. IMX_MU_xSR_MAX,
  59. };
  60. struct imx_sc_rpc_msg_max {
  61. struct imx_sc_rpc_msg hdr;
  62. u32 data[30];
  63. };
  64. struct imx_s4_rpc_msg_max {
  65. struct imx_s4_rpc_msg hdr;
  66. u32 data[254];
  67. };
  68. struct imx_mu_con_priv {
  69. unsigned int idx;
  70. char irq_desc[IMX_MU_CHAN_NAME_SIZE];
  71. enum imx_mu_chan_type type;
  72. struct mbox_chan *chan;
  73. struct work_struct txdb_work;
  74. };
  75. struct imx_mu_priv {
  76. struct device *dev;
  77. void __iomem *base;
  78. void *msg;
  79. spinlock_t xcr_lock; /* control register lock */
  80. struct mbox_controller mbox;
  81. struct mbox_chan mbox_chans[IMX_MU_CHANS];
  82. struct imx_mu_con_priv con_priv[IMX_MU_CHANS];
  83. const struct imx_mu_dcfg *dcfg;
  84. struct clk *clk;
  85. int irq[IMX_MU_CHANS];
  86. bool suspend;
  87. bool side_b;
  88. u32 xcr[IMX_MU_xCR_MAX];
  89. u32 num_tr;
  90. u32 num_rr;
  91. };
  92. enum imx_mu_type {
  93. IMX_MU_V1,
  94. IMX_MU_V2 = BIT(1),
  95. IMX_MU_V2_S4 = BIT(15),
  96. IMX_MU_V2_IRQ = BIT(16),
  97. };
  98. struct imx_mu_dcfg {
  99. int (*tx)(struct imx_mu_priv *priv, struct imx_mu_con_priv *cp, void *data);
  100. int (*rx)(struct imx_mu_priv *priv, struct imx_mu_con_priv *cp);
  101. int (*rxdb)(struct imx_mu_priv *priv, struct imx_mu_con_priv *cp);
  102. int (*init)(struct imx_mu_priv *priv);
  103. enum imx_mu_type type;
  104. u32 xTR; /* Transmit Register0 */
  105. u32 xRR; /* Receive Register0 */
  106. u32 xSR[IMX_MU_xSR_MAX]; /* Status Registers */
  107. u32 xCR[IMX_MU_xCR_MAX]; /* Control Registers */
  108. bool skip_suspend_flag;
  109. };
  110. #define IMX_MU_xSR_GIPn(type, x) (type & IMX_MU_V2 ? BIT(x) : BIT(28 + (3 - (x))))
  111. #define IMX_MU_xSR_RFn(type, x) (type & IMX_MU_V2 ? BIT(x) : BIT(24 + (3 - (x))))
  112. #define IMX_MU_xSR_TEn(type, x) (type & IMX_MU_V2 ? BIT(x) : BIT(20 + (3 - (x))))
  113. /* General Purpose Interrupt Enable */
  114. #define IMX_MU_xCR_GIEn(type, x) (type & IMX_MU_V2 ? BIT(x) : BIT(28 + (3 - (x))))
  115. /* Receive Interrupt Enable */
  116. #define IMX_MU_xCR_RIEn(type, x) (type & IMX_MU_V2 ? BIT(x) : BIT(24 + (3 - (x))))
  117. /* Transmit Interrupt Enable */
  118. #define IMX_MU_xCR_TIEn(type, x) (type & IMX_MU_V2 ? BIT(x) : BIT(20 + (3 - (x))))
  119. /* General Purpose Interrupt Request */
  120. #define IMX_MU_xCR_GIRn(type, x) (type & IMX_MU_V2 ? BIT(x) : BIT(16 + (3 - (x))))
  121. /* MU reset */
  122. #define IMX_MU_xCR_RST(type) (type & IMX_MU_V2 ? BIT(0) : BIT(5))
  123. #define IMX_MU_xSR_RST(type) (type & IMX_MU_V2 ? BIT(0) : BIT(7))
  124. static struct imx_mu_priv *to_imx_mu_priv(struct mbox_controller *mbox)
  125. {
  126. return container_of(mbox, struct imx_mu_priv, mbox);
  127. }
  128. static void imx_mu_write(struct imx_mu_priv *priv, u32 val, u32 offs)
  129. {
  130. iowrite32(val, priv->base + offs);
  131. }
  132. static u32 imx_mu_read(struct imx_mu_priv *priv, u32 offs)
  133. {
  134. return ioread32(priv->base + offs);
  135. }
  136. static int imx_mu_tx_waiting_write(struct imx_mu_priv *priv, u32 val, u32 idx)
  137. {
  138. u64 timeout_time = get_jiffies_64() + IMX_MU_SECO_TX_TOUT;
  139. u32 status;
  140. u32 can_write;
  141. dev_dbg(priv->dev, "Trying to write %.8x to idx %d\n", val, idx);
  142. do {
  143. status = imx_mu_read(priv, priv->dcfg->xSR[IMX_MU_TSR]);
  144. can_write = status & IMX_MU_xSR_TEn(priv->dcfg->type, idx % 4);
  145. } while (!can_write && time_is_after_jiffies64(timeout_time));
  146. if (!can_write) {
  147. dev_err(priv->dev, "timeout trying to write %.8x at %d(%.8x)\n",
  148. val, idx, status);
  149. return -ETIME;
  150. }
  151. imx_mu_write(priv, val, priv->dcfg->xTR + (idx % 4) * 4);
  152. return 0;
  153. }
  154. static int imx_mu_rx_waiting_read(struct imx_mu_priv *priv, u32 *val, u32 idx)
  155. {
  156. u64 timeout_time = get_jiffies_64() + IMX_MU_SECO_RX_TOUT;
  157. u32 status;
  158. u32 can_read;
  159. dev_dbg(priv->dev, "Trying to read from idx %d\n", idx);
  160. do {
  161. status = imx_mu_read(priv, priv->dcfg->xSR[IMX_MU_RSR]);
  162. can_read = status & IMX_MU_xSR_RFn(priv->dcfg->type, idx % 4);
  163. } while (!can_read && time_is_after_jiffies64(timeout_time));
  164. if (!can_read) {
  165. dev_err(priv->dev, "timeout trying to read idx %d (%.8x)\n",
  166. idx, status);
  167. return -ETIME;
  168. }
  169. *val = imx_mu_read(priv, priv->dcfg->xRR + (idx % 4) * 4);
  170. dev_dbg(priv->dev, "Read %.8x\n", *val);
  171. return 0;
  172. }
  173. static u32 imx_mu_xcr_rmw(struct imx_mu_priv *priv, enum imx_mu_xcr type, u32 set, u32 clr)
  174. {
  175. unsigned long flags;
  176. u32 val;
  177. spin_lock_irqsave(&priv->xcr_lock, flags);
  178. val = imx_mu_read(priv, priv->dcfg->xCR[type]);
  179. val &= ~clr;
  180. val |= set;
  181. imx_mu_write(priv, val, priv->dcfg->xCR[type]);
  182. spin_unlock_irqrestore(&priv->xcr_lock, flags);
  183. return val;
  184. }
  185. static int imx_mu_generic_tx(struct imx_mu_priv *priv,
  186. struct imx_mu_con_priv *cp,
  187. void *data)
  188. {
  189. u32 *arg = data;
  190. u32 val;
  191. int ret, count;
  192. switch (cp->type) {
  193. case IMX_MU_TYPE_TX:
  194. imx_mu_write(priv, *arg, priv->dcfg->xTR + cp->idx * 4);
  195. imx_mu_xcr_rmw(priv, IMX_MU_TCR, IMX_MU_xCR_TIEn(priv->dcfg->type, cp->idx), 0);
  196. break;
  197. case IMX_MU_TYPE_TXDB:
  198. imx_mu_xcr_rmw(priv, IMX_MU_GCR, IMX_MU_xCR_GIRn(priv->dcfg->type, cp->idx), 0);
  199. queue_work(system_bh_wq, &cp->txdb_work);
  200. break;
  201. case IMX_MU_TYPE_TXDB_V2:
  202. imx_mu_write(priv, IMX_MU_xCR_GIRn(priv->dcfg->type, cp->idx),
  203. priv->dcfg->xCR[IMX_MU_GCR]);
  204. ret = -ETIMEDOUT;
  205. count = 0;
  206. while (ret && (count < 10)) {
  207. ret =
  208. readl_poll_timeout(priv->base + priv->dcfg->xCR[IMX_MU_GCR], val,
  209. !(val & IMX_MU_xCR_GIRn(priv->dcfg->type, cp->idx)),
  210. 0, 10000);
  211. if (ret) {
  212. dev_warn_ratelimited(priv->dev,
  213. "channel type: %d timeout, %d times, retry\n",
  214. cp->type, ++count);
  215. }
  216. }
  217. break;
  218. default:
  219. dev_warn_ratelimited(priv->dev, "Send data on wrong channel type: %d\n", cp->type);
  220. return -EINVAL;
  221. }
  222. return 0;
  223. }
  224. static int imx_mu_generic_rx(struct imx_mu_priv *priv,
  225. struct imx_mu_con_priv *cp)
  226. {
  227. u32 dat;
  228. dat = imx_mu_read(priv, priv->dcfg->xRR + (cp->idx) * 4);
  229. mbox_chan_received_data(cp->chan, (void *)&dat);
  230. return 0;
  231. }
  232. static int imx_mu_generic_rxdb(struct imx_mu_priv *priv,
  233. struct imx_mu_con_priv *cp)
  234. {
  235. imx_mu_write(priv, IMX_MU_xSR_GIPn(priv->dcfg->type, cp->idx),
  236. priv->dcfg->xSR[IMX_MU_GSR]);
  237. mbox_chan_received_data(cp->chan, NULL);
  238. return 0;
  239. }
  240. static int imx_mu_specific_tx(struct imx_mu_priv *priv, struct imx_mu_con_priv *cp, void *data)
  241. {
  242. u32 *arg = data;
  243. u32 num_tr = priv->num_tr;
  244. int i, ret;
  245. u32 xsr;
  246. u32 size, max_size;
  247. if (priv->dcfg->type & IMX_MU_V2_S4) {
  248. size = ((struct imx_s4_rpc_msg_max *)data)->hdr.size;
  249. max_size = sizeof(struct imx_s4_rpc_msg_max);
  250. } else {
  251. size = ((struct imx_sc_rpc_msg_max *)data)->hdr.size;
  252. max_size = sizeof(struct imx_sc_rpc_msg_max);
  253. }
  254. switch (cp->type) {
  255. case IMX_MU_TYPE_TX:
  256. /*
  257. * msg->hdr.size specifies the number of u32 words while
  258. * sizeof yields bytes.
  259. */
  260. if (size > max_size / 4) {
  261. /*
  262. * The real message size can be different to
  263. * struct imx_sc_rpc_msg_max/imx_s4_rpc_msg_max size
  264. */
  265. dev_err(priv->dev, "Maximal message size (%u bytes) exceeded on TX; got: %i bytes\n", max_size, size << 2);
  266. return -EINVAL;
  267. }
  268. for (i = 0; i < num_tr && i < size; i++)
  269. imx_mu_write(priv, *arg++, priv->dcfg->xTR + (i % num_tr) * 4);
  270. for (; i < size; i++) {
  271. ret = readl_poll_timeout(priv->base + priv->dcfg->xSR[IMX_MU_TSR],
  272. xsr,
  273. xsr & IMX_MU_xSR_TEn(priv->dcfg->type, i % num_tr),
  274. 0, 5 * USEC_PER_SEC);
  275. if (ret) {
  276. dev_err(priv->dev, "Send data index: %d timeout\n", i);
  277. return ret;
  278. }
  279. imx_mu_write(priv, *arg++, priv->dcfg->xTR + (i % num_tr) * 4);
  280. }
  281. imx_mu_xcr_rmw(priv, IMX_MU_TCR, IMX_MU_xCR_TIEn(priv->dcfg->type, cp->idx), 0);
  282. break;
  283. default:
  284. dev_warn_ratelimited(priv->dev, "Send data on wrong channel type: %d\n", cp->type);
  285. return -EINVAL;
  286. }
  287. return 0;
  288. }
  289. static int imx_mu_specific_rx(struct imx_mu_priv *priv, struct imx_mu_con_priv *cp)
  290. {
  291. u32 *data;
  292. int i, ret;
  293. u32 xsr;
  294. u32 size, max_size;
  295. u32 num_rr = priv->num_rr;
  296. data = (u32 *)priv->msg;
  297. imx_mu_xcr_rmw(priv, IMX_MU_RCR, 0, IMX_MU_xCR_RIEn(priv->dcfg->type, 0));
  298. *data++ = imx_mu_read(priv, priv->dcfg->xRR);
  299. if (priv->dcfg->type & IMX_MU_V2_S4) {
  300. size = ((struct imx_s4_rpc_msg_max *)priv->msg)->hdr.size;
  301. max_size = sizeof(struct imx_s4_rpc_msg_max);
  302. } else {
  303. size = ((struct imx_sc_rpc_msg_max *)priv->msg)->hdr.size;
  304. max_size = sizeof(struct imx_sc_rpc_msg_max);
  305. }
  306. if (size > max_size / 4) {
  307. dev_err(priv->dev, "Maximal message size (%u bytes) exceeded on RX; got: %i bytes\n", max_size, size << 2);
  308. return -EINVAL;
  309. }
  310. for (i = 1; i < size; i++) {
  311. ret = readl_poll_timeout(priv->base + priv->dcfg->xSR[IMX_MU_RSR], xsr,
  312. xsr & IMX_MU_xSR_RFn(priv->dcfg->type, i % num_rr), 0,
  313. 5 * USEC_PER_SEC);
  314. if (ret) {
  315. dev_err(priv->dev, "timeout read idx %d\n", i);
  316. return ret;
  317. }
  318. *data++ = imx_mu_read(priv, priv->dcfg->xRR + (i % num_rr) * 4);
  319. }
  320. imx_mu_xcr_rmw(priv, IMX_MU_RCR, IMX_MU_xCR_RIEn(priv->dcfg->type, 0), 0);
  321. mbox_chan_received_data(cp->chan, (void *)priv->msg);
  322. return 0;
  323. }
  324. static int imx_mu_seco_tx(struct imx_mu_priv *priv, struct imx_mu_con_priv *cp,
  325. void *data)
  326. {
  327. struct imx_sc_rpc_msg_max *msg = data;
  328. u32 *arg = data;
  329. u32 byte_size;
  330. int err;
  331. int i;
  332. dev_dbg(priv->dev, "Sending message\n");
  333. switch (cp->type) {
  334. case IMX_MU_TYPE_TXDB:
  335. byte_size = msg->hdr.size * sizeof(u32);
  336. if (byte_size > sizeof(*msg)) {
  337. /*
  338. * The real message size can be different to
  339. * struct imx_sc_rpc_msg_max size
  340. */
  341. dev_err(priv->dev,
  342. "Exceed max msg size (%zu) on TX, got: %i\n",
  343. sizeof(*msg), byte_size);
  344. return -EINVAL;
  345. }
  346. print_hex_dump_debug("from client ", DUMP_PREFIX_OFFSET, 4, 4,
  347. data, byte_size, false);
  348. /* Send first word */
  349. dev_dbg(priv->dev, "Sending header\n");
  350. imx_mu_write(priv, *arg++, priv->dcfg->xTR);
  351. /* Send signaling */
  352. dev_dbg(priv->dev, "Sending signaling\n");
  353. imx_mu_xcr_rmw(priv, IMX_MU_GCR,
  354. IMX_MU_xCR_GIRn(priv->dcfg->type, cp->idx), 0);
  355. /* Send words to fill the mailbox */
  356. for (i = 1; i < 4 && i < msg->hdr.size; i++) {
  357. dev_dbg(priv->dev, "Sending word %d\n", i);
  358. imx_mu_write(priv, *arg++,
  359. priv->dcfg->xTR + (i % 4) * 4);
  360. }
  361. /* Send rest of message waiting for remote read */
  362. for (; i < msg->hdr.size; i++) {
  363. dev_dbg(priv->dev, "Sending word %d\n", i);
  364. err = imx_mu_tx_waiting_write(priv, *arg++, i);
  365. if (err) {
  366. dev_err(priv->dev, "Timeout tx %d\n", i);
  367. return err;
  368. }
  369. }
  370. /* Simulate hack for mbox framework */
  371. queue_work(system_bh_wq, &cp->txdb_work);
  372. break;
  373. default:
  374. dev_warn_ratelimited(priv->dev,
  375. "Send data on wrong channel type: %d\n",
  376. cp->type);
  377. return -EINVAL;
  378. }
  379. return 0;
  380. }
  381. static int imx_mu_seco_rxdb(struct imx_mu_priv *priv, struct imx_mu_con_priv *cp)
  382. {
  383. struct imx_sc_rpc_msg_max msg;
  384. u32 *data = (u32 *)&msg;
  385. u32 byte_size;
  386. int err = 0;
  387. int i;
  388. dev_dbg(priv->dev, "Receiving message\n");
  389. /* Read header */
  390. dev_dbg(priv->dev, "Receiving header\n");
  391. *data++ = imx_mu_read(priv, priv->dcfg->xRR);
  392. byte_size = msg.hdr.size * sizeof(u32);
  393. if (byte_size > sizeof(msg)) {
  394. dev_err(priv->dev, "Exceed max msg size (%zu) on RX, got: %i\n",
  395. sizeof(msg), byte_size);
  396. err = -EINVAL;
  397. goto error;
  398. }
  399. /* Read message waiting they are written */
  400. for (i = 1; i < msg.hdr.size; i++) {
  401. dev_dbg(priv->dev, "Receiving word %d\n", i);
  402. err = imx_mu_rx_waiting_read(priv, data++, i);
  403. if (err) {
  404. dev_err(priv->dev, "Timeout rx %d\n", i);
  405. goto error;
  406. }
  407. }
  408. /* Clear GIP */
  409. imx_mu_write(priv, IMX_MU_xSR_GIPn(priv->dcfg->type, cp->idx),
  410. priv->dcfg->xSR[IMX_MU_GSR]);
  411. print_hex_dump_debug("to client ", DUMP_PREFIX_OFFSET, 4, 4,
  412. &msg, byte_size, false);
  413. /* send data to client */
  414. dev_dbg(priv->dev, "Sending message to client\n");
  415. mbox_chan_received_data(cp->chan, (void *)&msg);
  416. goto exit;
  417. error:
  418. mbox_chan_received_data(cp->chan, ERR_PTR(err));
  419. exit:
  420. return err;
  421. }
  422. static void imx_mu_txdb_work(struct work_struct *t)
  423. {
  424. struct imx_mu_con_priv *cp = from_work(cp, t, txdb_work);
  425. mbox_chan_txdone(cp->chan, 0);
  426. }
  427. static irqreturn_t imx_mu_isr(int irq, void *p)
  428. {
  429. struct mbox_chan *chan = p;
  430. struct imx_mu_priv *priv = to_imx_mu_priv(chan->mbox);
  431. struct imx_mu_con_priv *cp = chan->con_priv;
  432. u32 val, ctrl;
  433. switch (cp->type) {
  434. case IMX_MU_TYPE_TX:
  435. ctrl = imx_mu_read(priv, priv->dcfg->xCR[IMX_MU_TCR]);
  436. val = imx_mu_read(priv, priv->dcfg->xSR[IMX_MU_TSR]);
  437. val &= IMX_MU_xSR_TEn(priv->dcfg->type, cp->idx) &
  438. (ctrl & IMX_MU_xCR_TIEn(priv->dcfg->type, cp->idx));
  439. break;
  440. case IMX_MU_TYPE_RX:
  441. ctrl = imx_mu_read(priv, priv->dcfg->xCR[IMX_MU_RCR]);
  442. val = imx_mu_read(priv, priv->dcfg->xSR[IMX_MU_RSR]);
  443. val &= IMX_MU_xSR_RFn(priv->dcfg->type, cp->idx) &
  444. (ctrl & IMX_MU_xCR_RIEn(priv->dcfg->type, cp->idx));
  445. break;
  446. case IMX_MU_TYPE_RXDB:
  447. ctrl = imx_mu_read(priv, priv->dcfg->xCR[IMX_MU_GIER]);
  448. val = imx_mu_read(priv, priv->dcfg->xSR[IMX_MU_GSR]);
  449. val &= IMX_MU_xSR_GIPn(priv->dcfg->type, cp->idx) &
  450. (ctrl & IMX_MU_xCR_GIEn(priv->dcfg->type, cp->idx));
  451. break;
  452. case IMX_MU_TYPE_RST:
  453. return IRQ_NONE;
  454. default:
  455. dev_warn_ratelimited(priv->dev, "Unhandled channel type %d\n",
  456. cp->type);
  457. return IRQ_NONE;
  458. }
  459. if (!val)
  460. return IRQ_NONE;
  461. if ((val == IMX_MU_xSR_TEn(priv->dcfg->type, cp->idx)) &&
  462. (cp->type == IMX_MU_TYPE_TX)) {
  463. imx_mu_xcr_rmw(priv, IMX_MU_TCR, 0, IMX_MU_xCR_TIEn(priv->dcfg->type, cp->idx));
  464. mbox_chan_txdone(chan, 0);
  465. } else if ((val == IMX_MU_xSR_RFn(priv->dcfg->type, cp->idx)) &&
  466. (cp->type == IMX_MU_TYPE_RX)) {
  467. priv->dcfg->rx(priv, cp);
  468. } else if ((val == IMX_MU_xSR_GIPn(priv->dcfg->type, cp->idx)) &&
  469. (cp->type == IMX_MU_TYPE_RXDB)) {
  470. priv->dcfg->rxdb(priv, cp);
  471. } else {
  472. dev_warn_ratelimited(priv->dev, "Not handled interrupt\n");
  473. return IRQ_NONE;
  474. }
  475. if (priv->suspend)
  476. pm_system_wakeup();
  477. return IRQ_HANDLED;
  478. }
  479. static int imx_mu_send_data(struct mbox_chan *chan, void *data)
  480. {
  481. struct imx_mu_priv *priv = to_imx_mu_priv(chan->mbox);
  482. struct imx_mu_con_priv *cp = chan->con_priv;
  483. return priv->dcfg->tx(priv, cp, data);
  484. }
  485. static int imx_mu_startup(struct mbox_chan *chan)
  486. {
  487. struct imx_mu_priv *priv = to_imx_mu_priv(chan->mbox);
  488. struct imx_mu_con_priv *cp = chan->con_priv;
  489. unsigned long irq_flag = 0;
  490. int ret;
  491. pm_runtime_get_sync(priv->dev);
  492. if (cp->type == IMX_MU_TYPE_TXDB_V2)
  493. return 0;
  494. if (cp->type == IMX_MU_TYPE_TXDB) {
  495. /* Tx doorbell don't have ACK support */
  496. INIT_WORK(&cp->txdb_work, imx_mu_txdb_work);
  497. return 0;
  498. }
  499. /* IPC MU should be with IRQF_NO_SUSPEND set */
  500. if (!priv->dev->pm_domain)
  501. irq_flag |= IRQF_NO_SUSPEND;
  502. if (!(priv->dcfg->type & IMX_MU_V2_IRQ))
  503. irq_flag |= IRQF_SHARED;
  504. ret = request_irq(priv->irq[cp->type], imx_mu_isr, irq_flag, cp->irq_desc, chan);
  505. if (ret) {
  506. dev_err(priv->dev, "Unable to acquire IRQ %d\n", priv->irq[cp->type]);
  507. return ret;
  508. }
  509. switch (cp->type) {
  510. case IMX_MU_TYPE_RX:
  511. imx_mu_xcr_rmw(priv, IMX_MU_RCR, IMX_MU_xCR_RIEn(priv->dcfg->type, cp->idx), 0);
  512. break;
  513. case IMX_MU_TYPE_RXDB:
  514. imx_mu_xcr_rmw(priv, IMX_MU_GIER, IMX_MU_xCR_GIEn(priv->dcfg->type, cp->idx), 0);
  515. break;
  516. default:
  517. break;
  518. }
  519. return 0;
  520. }
  521. static void imx_mu_shutdown(struct mbox_chan *chan)
  522. {
  523. struct imx_mu_priv *priv = to_imx_mu_priv(chan->mbox);
  524. struct imx_mu_con_priv *cp = chan->con_priv;
  525. int ret;
  526. u32 sr;
  527. if (cp->type == IMX_MU_TYPE_TXDB_V2) {
  528. pm_runtime_put_sync(priv->dev);
  529. return;
  530. }
  531. if (cp->type == IMX_MU_TYPE_TXDB) {
  532. cancel_work_sync(&cp->txdb_work);
  533. pm_runtime_put_sync(priv->dev);
  534. return;
  535. }
  536. switch (cp->type) {
  537. case IMX_MU_TYPE_TX:
  538. imx_mu_xcr_rmw(priv, IMX_MU_TCR, 0, IMX_MU_xCR_TIEn(priv->dcfg->type, cp->idx));
  539. break;
  540. case IMX_MU_TYPE_RX:
  541. imx_mu_xcr_rmw(priv, IMX_MU_RCR, 0, IMX_MU_xCR_RIEn(priv->dcfg->type, cp->idx));
  542. break;
  543. case IMX_MU_TYPE_RXDB:
  544. imx_mu_xcr_rmw(priv, IMX_MU_GIER, 0, IMX_MU_xCR_GIEn(priv->dcfg->type, cp->idx));
  545. break;
  546. case IMX_MU_TYPE_RST:
  547. imx_mu_xcr_rmw(priv, IMX_MU_CR, IMX_MU_xCR_RST(priv->dcfg->type), 0);
  548. ret = readl_poll_timeout(priv->base + priv->dcfg->xSR[IMX_MU_SR], sr,
  549. !(sr & IMX_MU_xSR_RST(priv->dcfg->type)), 1, 5);
  550. if (ret)
  551. dev_warn(priv->dev, "RST channel timeout\n");
  552. break;
  553. default:
  554. break;
  555. }
  556. free_irq(priv->irq[cp->type], chan);
  557. pm_runtime_put_sync(priv->dev);
  558. }
  559. static const struct mbox_chan_ops imx_mu_ops = {
  560. .send_data = imx_mu_send_data,
  561. .startup = imx_mu_startup,
  562. .shutdown = imx_mu_shutdown,
  563. };
  564. static struct mbox_chan *imx_mu_specific_xlate(struct mbox_controller *mbox,
  565. const struct of_phandle_args *sp)
  566. {
  567. u32 type, idx, chan;
  568. if (sp->args_count != 2) {
  569. dev_err(mbox->dev, "Invalid argument count %d\n", sp->args_count);
  570. return ERR_PTR(-EINVAL);
  571. }
  572. type = sp->args[0]; /* channel type */
  573. idx = sp->args[1]; /* index */
  574. switch (type) {
  575. case IMX_MU_TYPE_TX:
  576. case IMX_MU_TYPE_RX:
  577. if (idx != 0)
  578. dev_err(mbox->dev, "Invalid chan idx: %d\n", idx);
  579. chan = type;
  580. break;
  581. case IMX_MU_TYPE_RXDB:
  582. chan = 2 + idx;
  583. break;
  584. default:
  585. dev_err(mbox->dev, "Invalid chan type: %d\n", type);
  586. return ERR_PTR(-EINVAL);
  587. }
  588. if (chan >= mbox->num_chans) {
  589. dev_err(mbox->dev, "Not supported channel number: %d. (type: %d, idx: %d)\n", chan, type, idx);
  590. return ERR_PTR(-EINVAL);
  591. }
  592. return &mbox->chans[chan];
  593. }
  594. static struct mbox_chan * imx_mu_xlate(struct mbox_controller *mbox,
  595. const struct of_phandle_args *sp)
  596. {
  597. struct mbox_chan *p_chan;
  598. u32 type, idx, chan;
  599. if (sp->args_count != 2) {
  600. dev_err(mbox->dev, "Invalid argument count %d\n", sp->args_count);
  601. return ERR_PTR(-EINVAL);
  602. }
  603. type = sp->args[0]; /* channel type */
  604. idx = sp->args[1]; /* index */
  605. /* RST only supports 1 channel */
  606. if ((type == IMX_MU_TYPE_RST) && idx) {
  607. dev_err(mbox->dev, "Invalid RST channel %d\n", idx);
  608. return ERR_PTR(-EINVAL);
  609. }
  610. chan = type * 4 + idx;
  611. if (chan >= mbox->num_chans) {
  612. dev_err(mbox->dev, "Not supported channel number: %d. (type: %d, idx: %d)\n", chan, type, idx);
  613. return ERR_PTR(-EINVAL);
  614. }
  615. p_chan = &mbox->chans[chan];
  616. if (type == IMX_MU_TYPE_TXDB_V2)
  617. p_chan->txdone_method = TXDONE_BY_ACK;
  618. return p_chan;
  619. }
  620. static struct mbox_chan *imx_mu_seco_xlate(struct mbox_controller *mbox,
  621. const struct of_phandle_args *sp)
  622. {
  623. u32 type;
  624. if (sp->args_count < 1) {
  625. dev_err(mbox->dev, "Invalid argument count %d\n", sp->args_count);
  626. return ERR_PTR(-EINVAL);
  627. }
  628. type = sp->args[0]; /* channel type */
  629. /* Only supports TXDB and RXDB */
  630. if (type == IMX_MU_TYPE_TX || type == IMX_MU_TYPE_RX) {
  631. dev_err(mbox->dev, "Invalid type: %d\n", type);
  632. return ERR_PTR(-EINVAL);
  633. }
  634. return imx_mu_xlate(mbox, sp);
  635. }
  636. static void imx_mu_get_tr_rr(struct imx_mu_priv *priv)
  637. {
  638. u32 val;
  639. if (priv->dcfg->type & IMX_MU_V2) {
  640. val = imx_mu_read(priv, IMX_MU_V2_PAR_OFF);
  641. priv->num_tr = FIELD_GET(IMX_MU_V2_TR_MASK, val);
  642. priv->num_rr = FIELD_GET(IMX_MU_V2_RR_MASK, val);
  643. } else {
  644. priv->num_tr = 4;
  645. priv->num_rr = 4;
  646. }
  647. }
  648. static int imx_mu_init_generic(struct imx_mu_priv *priv)
  649. {
  650. unsigned int i;
  651. unsigned int val;
  652. if (priv->num_rr > 4 || priv->num_tr > 4) {
  653. WARN_ONCE(true, "%s not support TR/RR larger than 4\n", __func__);
  654. return -EOPNOTSUPP;
  655. }
  656. for (i = 0; i < IMX_MU_CHANS; i++) {
  657. struct imx_mu_con_priv *cp = &priv->con_priv[i];
  658. cp->idx = i % 4;
  659. cp->type = i >> 2;
  660. cp->chan = &priv->mbox_chans[i];
  661. priv->mbox_chans[i].con_priv = cp;
  662. snprintf(cp->irq_desc, sizeof(cp->irq_desc),
  663. "%s[%i-%u]", dev_name(priv->dev), cp->type, cp->idx);
  664. }
  665. priv->mbox.num_chans = IMX_MU_CHANS;
  666. priv->mbox.of_xlate = imx_mu_xlate;
  667. if (priv->side_b)
  668. return 0;
  669. /* Set default MU configuration */
  670. for (i = 0; i < IMX_MU_xCR_MAX; i++)
  671. imx_mu_write(priv, 0, priv->dcfg->xCR[i]);
  672. /* Clear any pending GIP */
  673. val = imx_mu_read(priv, priv->dcfg->xSR[IMX_MU_GSR]);
  674. imx_mu_write(priv, val, priv->dcfg->xSR[IMX_MU_GSR]);
  675. /* Clear any pending RSR */
  676. for (i = 0; i < priv->num_rr; i++)
  677. imx_mu_read(priv, priv->dcfg->xRR + i * 4);
  678. return 0;
  679. }
  680. static int imx_mu_init_specific(struct imx_mu_priv *priv)
  681. {
  682. unsigned int i;
  683. int num_chans = priv->dcfg->type & IMX_MU_V2_S4 ? IMX_MU_S4_CHANS : IMX_MU_SCU_CHANS;
  684. for (i = 0; i < num_chans; i++) {
  685. struct imx_mu_con_priv *cp = &priv->con_priv[i];
  686. cp->idx = i < 2 ? 0 : i - 2;
  687. cp->type = i < 2 ? i : IMX_MU_TYPE_RXDB;
  688. cp->chan = &priv->mbox_chans[i];
  689. priv->mbox_chans[i].con_priv = cp;
  690. snprintf(cp->irq_desc, sizeof(cp->irq_desc),
  691. "%s[%i-%u]", dev_name(priv->dev), cp->type, cp->idx);
  692. }
  693. priv->mbox.num_chans = num_chans;
  694. priv->mbox.of_xlate = imx_mu_specific_xlate;
  695. /* Set default MU configuration */
  696. for (i = 0; i < IMX_MU_xCR_MAX; i++)
  697. imx_mu_write(priv, 0, priv->dcfg->xCR[i]);
  698. return 0;
  699. }
  700. static int imx_mu_init_seco(struct imx_mu_priv *priv)
  701. {
  702. int ret;
  703. ret = imx_mu_init_generic(priv);
  704. if (ret)
  705. return ret;
  706. priv->mbox.of_xlate = imx_mu_seco_xlate;
  707. return 0;
  708. }
  709. static int imx_mu_probe(struct platform_device *pdev)
  710. {
  711. struct device *dev = &pdev->dev;
  712. struct device_node *np = dev->of_node;
  713. struct imx_mu_priv *priv;
  714. const struct imx_mu_dcfg *dcfg;
  715. int i, ret;
  716. u32 size;
  717. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  718. if (!priv)
  719. return -ENOMEM;
  720. priv->dev = dev;
  721. priv->base = devm_platform_ioremap_resource(pdev, 0);
  722. if (IS_ERR(priv->base))
  723. return PTR_ERR(priv->base);
  724. dcfg = of_device_get_match_data(dev);
  725. if (!dcfg)
  726. return -EINVAL;
  727. priv->dcfg = dcfg;
  728. if (priv->dcfg->type & IMX_MU_V2_IRQ) {
  729. priv->irq[IMX_MU_TYPE_TX] = platform_get_irq_byname(pdev, "tx");
  730. if (priv->irq[IMX_MU_TYPE_TX] < 0)
  731. return priv->irq[IMX_MU_TYPE_TX];
  732. priv->irq[IMX_MU_TYPE_RX] = platform_get_irq_byname(pdev, "rx");
  733. if (priv->irq[IMX_MU_TYPE_RX] < 0)
  734. return priv->irq[IMX_MU_TYPE_RX];
  735. } else {
  736. ret = platform_get_irq(pdev, 0);
  737. if (ret < 0)
  738. return ret;
  739. for (i = 0; i < IMX_MU_CHANS; i++)
  740. priv->irq[i] = ret;
  741. }
  742. if (priv->dcfg->type & IMX_MU_V2_S4)
  743. size = sizeof(struct imx_s4_rpc_msg_max);
  744. else
  745. size = sizeof(struct imx_sc_rpc_msg_max);
  746. priv->msg = devm_kzalloc(dev, size, GFP_KERNEL);
  747. if (!priv->msg)
  748. return -ENOMEM;
  749. priv->clk = devm_clk_get(dev, NULL);
  750. if (IS_ERR(priv->clk)) {
  751. if (PTR_ERR(priv->clk) != -ENOENT)
  752. return PTR_ERR(priv->clk);
  753. priv->clk = NULL;
  754. }
  755. ret = clk_prepare_enable(priv->clk);
  756. if (ret) {
  757. dev_err(dev, "Failed to enable clock\n");
  758. return ret;
  759. }
  760. imx_mu_get_tr_rr(priv);
  761. priv->side_b = of_property_read_bool(np, "fsl,mu-side-b");
  762. ret = priv->dcfg->init(priv);
  763. if (ret) {
  764. dev_err(dev, "Failed to init MU\n");
  765. goto disable_clk;
  766. }
  767. spin_lock_init(&priv->xcr_lock);
  768. priv->mbox.dev = dev;
  769. priv->mbox.ops = &imx_mu_ops;
  770. priv->mbox.chans = priv->mbox_chans;
  771. priv->mbox.txdone_irq = true;
  772. platform_set_drvdata(pdev, priv);
  773. ret = devm_mbox_controller_register(dev, &priv->mbox);
  774. if (ret)
  775. goto disable_clk;
  776. of_platform_populate(dev->of_node, NULL, NULL, dev);
  777. pm_runtime_enable(dev);
  778. ret = pm_runtime_resume_and_get(dev);
  779. if (ret < 0)
  780. goto disable_runtime_pm;
  781. ret = pm_runtime_put_sync(dev);
  782. if (ret < 0)
  783. goto disable_runtime_pm;
  784. clk_disable_unprepare(priv->clk);
  785. return 0;
  786. disable_runtime_pm:
  787. pm_runtime_disable(dev);
  788. disable_clk:
  789. clk_disable_unprepare(priv->clk);
  790. return ret;
  791. }
  792. static void imx_mu_remove(struct platform_device *pdev)
  793. {
  794. struct imx_mu_priv *priv = platform_get_drvdata(pdev);
  795. pm_runtime_disable(priv->dev);
  796. }
  797. static const struct imx_mu_dcfg imx_mu_cfg_imx6sx = {
  798. .tx = imx_mu_generic_tx,
  799. .rx = imx_mu_generic_rx,
  800. .rxdb = imx_mu_generic_rxdb,
  801. .init = imx_mu_init_generic,
  802. .xTR = 0x0,
  803. .xRR = 0x10,
  804. .xSR = {0x20, 0x20, 0x20, 0x20},
  805. .xCR = {0x24, 0x24, 0x24, 0x24, 0x24},
  806. };
  807. static const struct imx_mu_dcfg imx_mu_cfg_imx7ulp = {
  808. .tx = imx_mu_generic_tx,
  809. .rx = imx_mu_generic_rx,
  810. .rxdb = imx_mu_generic_rxdb,
  811. .init = imx_mu_init_generic,
  812. .xTR = 0x20,
  813. .xRR = 0x40,
  814. .xSR = {0x60, 0x60, 0x60, 0x60},
  815. .xCR = {0x64, 0x64, 0x64, 0x64, 0x64},
  816. .skip_suspend_flag = true,
  817. };
  818. static const struct imx_mu_dcfg imx_mu_cfg_imx8ulp = {
  819. .tx = imx_mu_generic_tx,
  820. .rx = imx_mu_generic_rx,
  821. .rxdb = imx_mu_generic_rxdb,
  822. .init = imx_mu_init_generic,
  823. .type = IMX_MU_V2,
  824. .xTR = 0x200,
  825. .xRR = 0x280,
  826. .xSR = {0xC, 0x118, 0x124, 0x12C},
  827. .xCR = {0x8, 0x110, 0x114, 0x120, 0x128},
  828. };
  829. static const struct imx_mu_dcfg imx_mu_cfg_imx8ulp_s4 = {
  830. .tx = imx_mu_specific_tx,
  831. .rx = imx_mu_specific_rx,
  832. .init = imx_mu_init_specific,
  833. .type = IMX_MU_V2 | IMX_MU_V2_S4,
  834. .xTR = 0x200,
  835. .xRR = 0x280,
  836. .xSR = {0xC, 0x118, 0x124, 0x12C},
  837. .xCR = {0x8, 0x110, 0x114, 0x120, 0x128},
  838. };
  839. static const struct imx_mu_dcfg imx_mu_cfg_imx93_s4 = {
  840. .tx = imx_mu_specific_tx,
  841. .rx = imx_mu_specific_rx,
  842. .init = imx_mu_init_specific,
  843. .type = IMX_MU_V2 | IMX_MU_V2_S4 | IMX_MU_V2_IRQ,
  844. .xTR = 0x200,
  845. .xRR = 0x280,
  846. .xSR = {0xC, 0x118, 0x124, 0x12C},
  847. .xCR = {0x8, 0x110, 0x114, 0x120, 0x128},
  848. };
  849. static const struct imx_mu_dcfg imx_mu_cfg_imx8_scu = {
  850. .tx = imx_mu_specific_tx,
  851. .rx = imx_mu_specific_rx,
  852. .init = imx_mu_init_specific,
  853. .rxdb = imx_mu_generic_rxdb,
  854. .xTR = 0x0,
  855. .xRR = 0x10,
  856. .xSR = {0x20, 0x20, 0x20, 0x20},
  857. .xCR = {0x24, 0x24, 0x24, 0x24, 0x24},
  858. };
  859. static const struct imx_mu_dcfg imx_mu_cfg_imx8_seco = {
  860. .tx = imx_mu_seco_tx,
  861. .rx = imx_mu_generic_rx,
  862. .rxdb = imx_mu_seco_rxdb,
  863. .init = imx_mu_init_seco,
  864. .xTR = 0x0,
  865. .xRR = 0x10,
  866. .xSR = {0x20, 0x20, 0x20, 0x20},
  867. .xCR = {0x24, 0x24, 0x24, 0x24, 0x24},
  868. };
  869. static const struct of_device_id imx_mu_dt_ids[] = {
  870. { .compatible = "fsl,imx7ulp-mu", .data = &imx_mu_cfg_imx7ulp },
  871. { .compatible = "fsl,imx6sx-mu", .data = &imx_mu_cfg_imx6sx },
  872. { .compatible = "fsl,imx8ulp-mu", .data = &imx_mu_cfg_imx8ulp },
  873. { .compatible = "fsl,imx8ulp-mu-s4", .data = &imx_mu_cfg_imx8ulp_s4 },
  874. { .compatible = "fsl,imx93-mu-s4", .data = &imx_mu_cfg_imx93_s4 },
  875. { .compatible = "fsl,imx95-mu", .data = &imx_mu_cfg_imx8ulp },
  876. { .compatible = "fsl,imx95-mu-ele", .data = &imx_mu_cfg_imx8ulp_s4 },
  877. { .compatible = "fsl,imx95-mu-v2x", .data = &imx_mu_cfg_imx8ulp_s4 },
  878. { .compatible = "fsl,imx8-mu-scu", .data = &imx_mu_cfg_imx8_scu },
  879. { .compatible = "fsl,imx8-mu-seco", .data = &imx_mu_cfg_imx8_seco },
  880. { },
  881. };
  882. MODULE_DEVICE_TABLE(of, imx_mu_dt_ids);
  883. static int __maybe_unused imx_mu_suspend_noirq(struct device *dev)
  884. {
  885. struct imx_mu_priv *priv = dev_get_drvdata(dev);
  886. int i;
  887. if (!priv->clk) {
  888. for (i = 0; i < IMX_MU_xCR_MAX; i++)
  889. priv->xcr[i] = imx_mu_read(priv, priv->dcfg->xCR[i]);
  890. }
  891. if (!priv->dcfg->skip_suspend_flag)
  892. priv->suspend = true;
  893. return 0;
  894. }
  895. static int __maybe_unused imx_mu_resume_noirq(struct device *dev)
  896. {
  897. struct imx_mu_priv *priv = dev_get_drvdata(dev);
  898. int i;
  899. /*
  900. * ONLY restore MU when context lost, the TIE could
  901. * be set during noirq resume as there is MU data
  902. * communication going on, and restore the saved
  903. * value will overwrite the TIE and cause MU data
  904. * send failed, may lead to system freeze. This issue
  905. * is observed by testing freeze mode suspend.
  906. */
  907. if (!priv->clk && !imx_mu_read(priv, priv->dcfg->xCR[0])) {
  908. for (i = 0; i < IMX_MU_xCR_MAX; i++)
  909. imx_mu_write(priv, priv->xcr[i], priv->dcfg->xCR[i]);
  910. }
  911. if (!priv->dcfg->skip_suspend_flag)
  912. priv->suspend = false;
  913. return 0;
  914. }
  915. static int __maybe_unused imx_mu_runtime_suspend(struct device *dev)
  916. {
  917. struct imx_mu_priv *priv = dev_get_drvdata(dev);
  918. clk_disable_unprepare(priv->clk);
  919. return 0;
  920. }
  921. static int __maybe_unused imx_mu_runtime_resume(struct device *dev)
  922. {
  923. struct imx_mu_priv *priv = dev_get_drvdata(dev);
  924. int ret;
  925. ret = clk_prepare_enable(priv->clk);
  926. if (ret)
  927. dev_err(dev, "failed to enable clock\n");
  928. return ret;
  929. }
  930. static const struct dev_pm_ops imx_mu_pm_ops = {
  931. SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(imx_mu_suspend_noirq,
  932. imx_mu_resume_noirq)
  933. SET_RUNTIME_PM_OPS(imx_mu_runtime_suspend,
  934. imx_mu_runtime_resume, NULL)
  935. };
  936. static struct platform_driver imx_mu_driver = {
  937. .probe = imx_mu_probe,
  938. .remove = imx_mu_remove,
  939. .driver = {
  940. .name = "imx_mu",
  941. .of_match_table = imx_mu_dt_ids,
  942. .pm = &imx_mu_pm_ops,
  943. },
  944. };
  945. module_platform_driver(imx_mu_driver);
  946. MODULE_AUTHOR("Oleksij Rempel <o.rempel@pengutronix.de>");
  947. MODULE_DESCRIPTION("Message Unit driver for i.MX");
  948. MODULE_LICENSE("GPL v2");