ti-msgmgr.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Texas Instruments' Message Manager Driver
  4. *
  5. * Copyright (C) 2015-2017 Texas Instruments Incorporated - http://www.ti.com/
  6. * Nishanth Menon
  7. */
  8. #define pr_fmt(fmt) "%s: " fmt, __func__
  9. #include <linux/device.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/io.h>
  12. #include <linux/kernel.h>
  13. #include <linux/mailbox_controller.h>
  14. #include <linux/module.h>
  15. #include <linux/of_device.h>
  16. #include <linux/of.h>
  17. #include <linux/of_irq.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/soc/ti/ti-msgmgr.h>
  20. #define Q_DATA_OFFSET(proxy, queue, reg) \
  21. ((0x10000 * (proxy)) + (0x80 * (queue)) + ((reg) * 4))
  22. #define Q_STATE_OFFSET(queue) ((queue) * 0x4)
  23. #define Q_STATE_ENTRY_COUNT_MASK (0xFFF000)
  24. /**
  25. * struct ti_msgmgr_valid_queue_desc - SoC valid queues meant for this processor
  26. * @queue_id: Queue Number for this path
  27. * @proxy_id: Proxy ID representing the processor in SoC
  28. * @is_tx: Is this a receive path?
  29. */
  30. struct ti_msgmgr_valid_queue_desc {
  31. u8 queue_id;
  32. u8 proxy_id;
  33. bool is_tx;
  34. };
  35. /**
  36. * struct ti_msgmgr_desc - Description of message manager integration
  37. * @queue_count: Number of Queues
  38. * @max_message_size: Message size in bytes
  39. * @max_messages: Number of messages
  40. * @q_slices: Number of queue engines
  41. * @q_proxies: Number of queue proxies per page
  42. * @data_first_reg: First data register for proxy data region
  43. * @data_last_reg: Last data register for proxy data region
  44. * @tx_polled: Do I need to use polled mechanism for tx
  45. * @tx_poll_timeout_ms: Timeout in ms if polled
  46. * @valid_queues: List of Valid queues that the processor can access
  47. * @num_valid_queues: Number of valid queues
  48. *
  49. * This structure is used in of match data to describe how integration
  50. * for a specific compatible SoC is done.
  51. */
  52. struct ti_msgmgr_desc {
  53. u8 queue_count;
  54. u8 max_message_size;
  55. u8 max_messages;
  56. u8 q_slices;
  57. u8 q_proxies;
  58. u8 data_first_reg;
  59. u8 data_last_reg;
  60. bool tx_polled;
  61. int tx_poll_timeout_ms;
  62. const struct ti_msgmgr_valid_queue_desc *valid_queues;
  63. int num_valid_queues;
  64. };
  65. /**
  66. * struct ti_queue_inst - Description of a queue instance
  67. * @name: Queue Name
  68. * @queue_id: Queue Identifier as mapped on SoC
  69. * @proxy_id: Proxy Identifier as mapped on SoC
  70. * @irq: IRQ for Rx Queue
  71. * @is_tx: 'true' if transmit queue, else, 'false'
  72. * @queue_buff_start: First register of Data Buffer
  73. * @queue_buff_end: Last (or confirmation) register of Data buffer
  74. * @queue_state: Queue status register
  75. * @chan: Mailbox channel
  76. * @rx_buff: Receive buffer pointer allocated at probe, max_message_size
  77. */
  78. struct ti_queue_inst {
  79. char name[30];
  80. u8 queue_id;
  81. u8 proxy_id;
  82. int irq;
  83. bool is_tx;
  84. void __iomem *queue_buff_start;
  85. void __iomem *queue_buff_end;
  86. void __iomem *queue_state;
  87. struct mbox_chan *chan;
  88. u32 *rx_buff;
  89. };
  90. /**
  91. * struct ti_msgmgr_inst - Description of a Message Manager Instance
  92. * @dev: device pointer corresponding to the Message Manager instance
  93. * @desc: Description of the SoC integration
  94. * @queue_proxy_region: Queue proxy region where queue buffers are located
  95. * @queue_state_debug_region: Queue status register regions
  96. * @num_valid_queues: Number of valid queues defined for the processor
  97. * Note: other queues are probably reserved for other processors
  98. * in the SoC.
  99. * @qinsts: Array of valid Queue Instances for the Processor
  100. * @mbox: Mailbox Controller
  101. * @chans: Array for channels corresponding to the Queue Instances.
  102. */
  103. struct ti_msgmgr_inst {
  104. struct device *dev;
  105. const struct ti_msgmgr_desc *desc;
  106. void __iomem *queue_proxy_region;
  107. void __iomem *queue_state_debug_region;
  108. u8 num_valid_queues;
  109. struct ti_queue_inst *qinsts;
  110. struct mbox_controller mbox;
  111. struct mbox_chan *chans;
  112. };
  113. /**
  114. * ti_msgmgr_queue_get_num_messages() - Get the number of pending messages
  115. * @qinst: Queue instance for which we check the number of pending messages
  116. *
  117. * Return: number of messages pending in the queue (0 == no pending messages)
  118. */
  119. static inline int ti_msgmgr_queue_get_num_messages(struct ti_queue_inst *qinst)
  120. {
  121. u32 val;
  122. /*
  123. * We cannot use relaxed operation here - update may happen
  124. * real-time.
  125. */
  126. val = readl(qinst->queue_state) & Q_STATE_ENTRY_COUNT_MASK;
  127. val >>= __ffs(Q_STATE_ENTRY_COUNT_MASK);
  128. return val;
  129. }
  130. /**
  131. * ti_msgmgr_queue_rx_interrupt() - Interrupt handler for receive Queue
  132. * @irq: Interrupt number
  133. * @p: Channel Pointer
  134. *
  135. * Return: -EINVAL if there is no instance
  136. * IRQ_NONE if the interrupt is not ours.
  137. * IRQ_HANDLED if the rx interrupt was successfully handled.
  138. */
  139. static irqreturn_t ti_msgmgr_queue_rx_interrupt(int irq, void *p)
  140. {
  141. struct mbox_chan *chan = p;
  142. struct device *dev = chan->mbox->dev;
  143. struct ti_msgmgr_inst *inst = dev_get_drvdata(dev);
  144. struct ti_queue_inst *qinst = chan->con_priv;
  145. const struct ti_msgmgr_desc *desc;
  146. int msg_count, num_words;
  147. struct ti_msgmgr_message message;
  148. void __iomem *data_reg;
  149. u32 *word_data;
  150. if (WARN_ON(!inst)) {
  151. dev_err(dev, "no platform drv data??\n");
  152. return -EINVAL;
  153. }
  154. /* Do I have an invalid interrupt source? */
  155. if (qinst->is_tx) {
  156. dev_err(dev, "Cannot handle rx interrupt on tx channel %s\n",
  157. qinst->name);
  158. return IRQ_NONE;
  159. }
  160. /* Do I actually have messages to read? */
  161. msg_count = ti_msgmgr_queue_get_num_messages(qinst);
  162. if (!msg_count) {
  163. /* Shared IRQ? */
  164. dev_dbg(dev, "Spurious event - 0 pending data!\n");
  165. return IRQ_NONE;
  166. }
  167. /*
  168. * I have no idea about the protocol being used to communicate with the
  169. * remote producer - 0 could be valid data, so I wont make a judgement
  170. * of how many bytes I should be reading. Let the client figure this
  171. * out.. I just read the full message and pass it on..
  172. */
  173. desc = inst->desc;
  174. message.len = desc->max_message_size;
  175. message.buf = (u8 *)qinst->rx_buff;
  176. /*
  177. * NOTE about register access involved here:
  178. * the hardware block is implemented with 32bit access operations and no
  179. * support for data splitting. We don't want the hardware to misbehave
  180. * with sub 32bit access - For example: if the last register read is
  181. * split into byte wise access, it can result in the queue getting
  182. * stuck or indeterminate behavior. An out of order read operation may
  183. * result in weird data results as well.
  184. * Hence, we do not use memcpy_fromio or __ioread32_copy here, instead
  185. * we depend on readl for the purpose.
  186. *
  187. * Also note that the final register read automatically marks the
  188. * queue message as read.
  189. */
  190. for (data_reg = qinst->queue_buff_start, word_data = qinst->rx_buff,
  191. num_words = (desc->max_message_size / sizeof(u32));
  192. num_words; num_words--, data_reg += sizeof(u32), word_data++)
  193. *word_data = readl(data_reg);
  194. /*
  195. * Last register read automatically clears the IRQ if only 1 message
  196. * is pending - so send the data up the stack..
  197. * NOTE: Client is expected to be as optimal as possible, since
  198. * we invoke the handler in IRQ context.
  199. */
  200. mbox_chan_received_data(chan, (void *)&message);
  201. return IRQ_HANDLED;
  202. }
  203. /**
  204. * ti_msgmgr_queue_peek_data() - Peek to see if there are any rx messages.
  205. * @chan: Channel Pointer
  206. *
  207. * Return: 'true' if there is pending rx data, 'false' if there is none.
  208. */
  209. static bool ti_msgmgr_queue_peek_data(struct mbox_chan *chan)
  210. {
  211. struct ti_queue_inst *qinst = chan->con_priv;
  212. int msg_count;
  213. if (qinst->is_tx)
  214. return false;
  215. msg_count = ti_msgmgr_queue_get_num_messages(qinst);
  216. return msg_count ? true : false;
  217. }
  218. /**
  219. * ti_msgmgr_last_tx_done() - See if all the tx messages are sent
  220. * @chan: Channel pointer
  221. *
  222. * Return: 'true' is no pending tx data, 'false' if there are any.
  223. */
  224. static bool ti_msgmgr_last_tx_done(struct mbox_chan *chan)
  225. {
  226. struct ti_queue_inst *qinst = chan->con_priv;
  227. int msg_count;
  228. if (!qinst->is_tx)
  229. return false;
  230. msg_count = ti_msgmgr_queue_get_num_messages(qinst);
  231. /* if we have any messages pending.. */
  232. return msg_count ? false : true;
  233. }
  234. /**
  235. * ti_msgmgr_send_data() - Send data
  236. * @chan: Channel Pointer
  237. * @data: ti_msgmgr_message * Message Pointer
  238. *
  239. * Return: 0 if all goes good, else appropriate error messages.
  240. */
  241. static int ti_msgmgr_send_data(struct mbox_chan *chan, void *data)
  242. {
  243. struct device *dev = chan->mbox->dev;
  244. struct ti_msgmgr_inst *inst = dev_get_drvdata(dev);
  245. const struct ti_msgmgr_desc *desc;
  246. struct ti_queue_inst *qinst = chan->con_priv;
  247. int num_words, trail_bytes;
  248. struct ti_msgmgr_message *message = data;
  249. void __iomem *data_reg;
  250. u32 *word_data;
  251. if (WARN_ON(!inst)) {
  252. dev_err(dev, "no platform drv data??\n");
  253. return -EINVAL;
  254. }
  255. desc = inst->desc;
  256. if (desc->max_message_size < message->len) {
  257. dev_err(dev, "Queue %s message length %zu > max %d\n",
  258. qinst->name, message->len, desc->max_message_size);
  259. return -EINVAL;
  260. }
  261. /* NOTE: Constraints similar to rx path exists here as well */
  262. for (data_reg = qinst->queue_buff_start,
  263. num_words = message->len / sizeof(u32),
  264. word_data = (u32 *)message->buf;
  265. num_words; num_words--, data_reg += sizeof(u32), word_data++)
  266. writel(*word_data, data_reg);
  267. trail_bytes = message->len % sizeof(u32);
  268. if (trail_bytes) {
  269. u32 data_trail = *word_data;
  270. /* Ensure all unused data is 0 */
  271. data_trail &= 0xFFFFFFFF >> (8 * (sizeof(u32) - trail_bytes));
  272. writel(data_trail, data_reg);
  273. data_reg++;
  274. }
  275. /*
  276. * 'data_reg' indicates next register to write. If we did not already
  277. * write on tx complete reg(last reg), we must do so for transmit
  278. */
  279. if (data_reg <= qinst->queue_buff_end)
  280. writel(0, qinst->queue_buff_end);
  281. return 0;
  282. }
  283. /**
  284. * ti_msgmgr_queue_startup() - Startup queue
  285. * @chan: Channel pointer
  286. *
  287. * Return: 0 if all goes good, else return corresponding error message
  288. */
  289. static int ti_msgmgr_queue_startup(struct mbox_chan *chan)
  290. {
  291. struct ti_queue_inst *qinst = chan->con_priv;
  292. struct device *dev = chan->mbox->dev;
  293. int ret;
  294. if (!qinst->is_tx) {
  295. /*
  296. * With the expectation that the IRQ might be shared in SoC
  297. */
  298. ret = request_irq(qinst->irq, ti_msgmgr_queue_rx_interrupt,
  299. IRQF_SHARED, qinst->name, chan);
  300. if (ret) {
  301. dev_err(dev, "Unable to get IRQ %d on %s(res=%d)\n",
  302. qinst->irq, qinst->name, ret);
  303. return ret;
  304. }
  305. }
  306. return 0;
  307. }
  308. /**
  309. * ti_msgmgr_queue_shutdown() - Shutdown the queue
  310. * @chan: Channel pointer
  311. */
  312. static void ti_msgmgr_queue_shutdown(struct mbox_chan *chan)
  313. {
  314. struct ti_queue_inst *qinst = chan->con_priv;
  315. if (!qinst->is_tx)
  316. free_irq(qinst->irq, chan);
  317. }
  318. /**
  319. * ti_msgmgr_of_xlate() - Translation of phandle to queue
  320. * @mbox: Mailbox controller
  321. * @p: phandle pointer
  322. *
  323. * Return: Mailbox channel corresponding to the queue, else return error
  324. * pointer.
  325. */
  326. static struct mbox_chan *ti_msgmgr_of_xlate(struct mbox_controller *mbox,
  327. const struct of_phandle_args *p)
  328. {
  329. struct ti_msgmgr_inst *inst;
  330. int req_qid, req_pid;
  331. struct ti_queue_inst *qinst;
  332. int i;
  333. inst = container_of(mbox, struct ti_msgmgr_inst, mbox);
  334. if (WARN_ON(!inst))
  335. return ERR_PTR(-EINVAL);
  336. /* #mbox-cells is 2 */
  337. if (p->args_count != 2) {
  338. dev_err(inst->dev, "Invalid arguments in dt[%d] instead of 2\n",
  339. p->args_count);
  340. return ERR_PTR(-EINVAL);
  341. }
  342. req_qid = p->args[0];
  343. req_pid = p->args[1];
  344. for (qinst = inst->qinsts, i = 0; i < inst->num_valid_queues;
  345. i++, qinst++) {
  346. if (req_qid == qinst->queue_id && req_pid == qinst->proxy_id)
  347. return qinst->chan;
  348. }
  349. dev_err(inst->dev, "Queue ID %d, Proxy ID %d is wrong on %s\n",
  350. req_qid, req_pid, p->np->name);
  351. return ERR_PTR(-ENOENT);
  352. }
  353. /**
  354. * ti_msgmgr_queue_setup() - Setup data structures for each queue instance
  355. * @idx: index of the queue
  356. * @dev: pointer to the message manager device
  357. * @np: pointer to the of node
  358. * @inst: Queue instance pointer
  359. * @d: Message Manager instance description data
  360. * @qd: Queue description data
  361. * @qinst: Queue instance pointer
  362. * @chan: pointer to mailbox channel
  363. *
  364. * Return: 0 if all went well, else return corresponding error
  365. */
  366. static int ti_msgmgr_queue_setup(int idx, struct device *dev,
  367. struct device_node *np,
  368. struct ti_msgmgr_inst *inst,
  369. const struct ti_msgmgr_desc *d,
  370. const struct ti_msgmgr_valid_queue_desc *qd,
  371. struct ti_queue_inst *qinst,
  372. struct mbox_chan *chan)
  373. {
  374. qinst->proxy_id = qd->proxy_id;
  375. qinst->queue_id = qd->queue_id;
  376. if (qinst->queue_id > d->queue_count) {
  377. dev_err(dev, "Queue Data [idx=%d] queuid %d > %d\n",
  378. idx, qinst->queue_id, d->queue_count);
  379. return -ERANGE;
  380. }
  381. qinst->is_tx = qd->is_tx;
  382. snprintf(qinst->name, sizeof(qinst->name), "%s %s_%03d_%03d",
  383. dev_name(dev), qinst->is_tx ? "tx" : "rx", qinst->queue_id,
  384. qinst->proxy_id);
  385. if (!qinst->is_tx) {
  386. char of_rx_irq_name[7];
  387. snprintf(of_rx_irq_name, sizeof(of_rx_irq_name),
  388. "rx_%03d", qinst->queue_id);
  389. qinst->irq = of_irq_get_byname(np, of_rx_irq_name);
  390. if (qinst->irq < 0) {
  391. dev_crit(dev,
  392. "[%d]QID %d PID %d:No IRQ[%s]: %d\n",
  393. idx, qinst->queue_id, qinst->proxy_id,
  394. of_rx_irq_name, qinst->irq);
  395. return qinst->irq;
  396. }
  397. /* Allocate usage buffer for rx */
  398. qinst->rx_buff = devm_kzalloc(dev,
  399. d->max_message_size, GFP_KERNEL);
  400. if (!qinst->rx_buff)
  401. return -ENOMEM;
  402. }
  403. qinst->queue_buff_start = inst->queue_proxy_region +
  404. Q_DATA_OFFSET(qinst->proxy_id, qinst->queue_id, d->data_first_reg);
  405. qinst->queue_buff_end = inst->queue_proxy_region +
  406. Q_DATA_OFFSET(qinst->proxy_id, qinst->queue_id, d->data_last_reg);
  407. qinst->queue_state = inst->queue_state_debug_region +
  408. Q_STATE_OFFSET(qinst->queue_id);
  409. qinst->chan = chan;
  410. chan->con_priv = qinst;
  411. dev_dbg(dev, "[%d] qidx=%d pidx=%d irq=%d q_s=%p q_e = %p\n",
  412. idx, qinst->queue_id, qinst->proxy_id, qinst->irq,
  413. qinst->queue_buff_start, qinst->queue_buff_end);
  414. return 0;
  415. }
  416. /* Queue operations */
  417. static const struct mbox_chan_ops ti_msgmgr_chan_ops = {
  418. .startup = ti_msgmgr_queue_startup,
  419. .shutdown = ti_msgmgr_queue_shutdown,
  420. .peek_data = ti_msgmgr_queue_peek_data,
  421. .last_tx_done = ti_msgmgr_last_tx_done,
  422. .send_data = ti_msgmgr_send_data,
  423. };
  424. /* Keystone K2G SoC integration details */
  425. static const struct ti_msgmgr_valid_queue_desc k2g_valid_queues[] = {
  426. {.queue_id = 0, .proxy_id = 0, .is_tx = true,},
  427. {.queue_id = 1, .proxy_id = 0, .is_tx = true,},
  428. {.queue_id = 2, .proxy_id = 0, .is_tx = true,},
  429. {.queue_id = 3, .proxy_id = 0, .is_tx = true,},
  430. {.queue_id = 5, .proxy_id = 2, .is_tx = false,},
  431. {.queue_id = 56, .proxy_id = 1, .is_tx = true,},
  432. {.queue_id = 57, .proxy_id = 2, .is_tx = false,},
  433. {.queue_id = 58, .proxy_id = 3, .is_tx = true,},
  434. {.queue_id = 59, .proxy_id = 4, .is_tx = true,},
  435. {.queue_id = 60, .proxy_id = 5, .is_tx = true,},
  436. {.queue_id = 61, .proxy_id = 6, .is_tx = true,},
  437. };
  438. static const struct ti_msgmgr_desc k2g_desc = {
  439. .queue_count = 64,
  440. .max_message_size = 64,
  441. .max_messages = 128,
  442. .q_slices = 1,
  443. .q_proxies = 1,
  444. .data_first_reg = 16,
  445. .data_last_reg = 31,
  446. .tx_polled = false,
  447. .valid_queues = k2g_valid_queues,
  448. .num_valid_queues = ARRAY_SIZE(k2g_valid_queues),
  449. };
  450. static const struct of_device_id ti_msgmgr_of_match[] = {
  451. {.compatible = "ti,k2g-message-manager", .data = &k2g_desc},
  452. { /* Sentinel */ }
  453. };
  454. MODULE_DEVICE_TABLE(of, ti_msgmgr_of_match);
  455. static int ti_msgmgr_probe(struct platform_device *pdev)
  456. {
  457. struct device *dev = &pdev->dev;
  458. const struct of_device_id *of_id;
  459. struct device_node *np;
  460. struct resource *res;
  461. const struct ti_msgmgr_desc *desc;
  462. struct ti_msgmgr_inst *inst;
  463. struct ti_queue_inst *qinst;
  464. struct mbox_controller *mbox;
  465. struct mbox_chan *chans;
  466. int queue_count;
  467. int i;
  468. int ret = -EINVAL;
  469. const struct ti_msgmgr_valid_queue_desc *queue_desc;
  470. if (!dev->of_node) {
  471. dev_err(dev, "no OF information\n");
  472. return -EINVAL;
  473. }
  474. np = dev->of_node;
  475. of_id = of_match_device(ti_msgmgr_of_match, dev);
  476. if (!of_id) {
  477. dev_err(dev, "OF data missing\n");
  478. return -EINVAL;
  479. }
  480. desc = of_id->data;
  481. inst = devm_kzalloc(dev, sizeof(*inst), GFP_KERNEL);
  482. if (!inst)
  483. return -ENOMEM;
  484. inst->dev = dev;
  485. inst->desc = desc;
  486. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  487. "queue_proxy_region");
  488. inst->queue_proxy_region = devm_ioremap_resource(dev, res);
  489. if (IS_ERR(inst->queue_proxy_region))
  490. return PTR_ERR(inst->queue_proxy_region);
  491. res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
  492. "queue_state_debug_region");
  493. inst->queue_state_debug_region = devm_ioremap_resource(dev, res);
  494. if (IS_ERR(inst->queue_state_debug_region))
  495. return PTR_ERR(inst->queue_state_debug_region);
  496. dev_dbg(dev, "proxy region=%p, queue_state=%p\n",
  497. inst->queue_proxy_region, inst->queue_state_debug_region);
  498. queue_count = desc->num_valid_queues;
  499. if (!queue_count || queue_count > desc->queue_count) {
  500. dev_crit(dev, "Invalid Number of queues %d. Max %d\n",
  501. queue_count, desc->queue_count);
  502. return -ERANGE;
  503. }
  504. inst->num_valid_queues = queue_count;
  505. qinst = devm_kzalloc(dev, sizeof(*qinst) * queue_count, GFP_KERNEL);
  506. if (!qinst)
  507. return -ENOMEM;
  508. inst->qinsts = qinst;
  509. chans = devm_kzalloc(dev, sizeof(*chans) * queue_count, GFP_KERNEL);
  510. if (!chans)
  511. return -ENOMEM;
  512. inst->chans = chans;
  513. for (i = 0, queue_desc = desc->valid_queues;
  514. i < queue_count; i++, qinst++, chans++, queue_desc++) {
  515. ret = ti_msgmgr_queue_setup(i, dev, np, inst,
  516. desc, queue_desc, qinst, chans);
  517. if (ret)
  518. return ret;
  519. }
  520. mbox = &inst->mbox;
  521. mbox->dev = dev;
  522. mbox->ops = &ti_msgmgr_chan_ops;
  523. mbox->chans = inst->chans;
  524. mbox->num_chans = inst->num_valid_queues;
  525. mbox->txdone_irq = false;
  526. mbox->txdone_poll = desc->tx_polled;
  527. if (desc->tx_polled)
  528. mbox->txpoll_period = desc->tx_poll_timeout_ms;
  529. mbox->of_xlate = ti_msgmgr_of_xlate;
  530. platform_set_drvdata(pdev, inst);
  531. ret = mbox_controller_register(mbox);
  532. if (ret)
  533. dev_err(dev, "Failed to register mbox_controller(%d)\n", ret);
  534. return ret;
  535. }
  536. static int ti_msgmgr_remove(struct platform_device *pdev)
  537. {
  538. struct ti_msgmgr_inst *inst;
  539. inst = platform_get_drvdata(pdev);
  540. mbox_controller_unregister(&inst->mbox);
  541. return 0;
  542. }
  543. static struct platform_driver ti_msgmgr_driver = {
  544. .probe = ti_msgmgr_probe,
  545. .remove = ti_msgmgr_remove,
  546. .driver = {
  547. .name = "ti-msgmgr",
  548. .of_match_table = of_match_ptr(ti_msgmgr_of_match),
  549. },
  550. };
  551. module_platform_driver(ti_msgmgr_driver);
  552. MODULE_LICENSE("GPL v2");
  553. MODULE_DESCRIPTION("TI message manager driver");
  554. MODULE_AUTHOR("Nishanth Menon");
  555. MODULE_ALIAS("platform:ti-msgmgr");