smp2p.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015, Sony Mobile Communications AB.
  4. * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  5. */
  6. #include <linux/interrupt.h>
  7. #include <linux/list.h>
  8. #include <linux/io.h>
  9. #include <linux/of.h>
  10. #include <linux/irq.h>
  11. #include <linux/irqdomain.h>
  12. #include <linux/mailbox_client.h>
  13. #include <linux/mfd/syscon.h>
  14. #include <linux/module.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/pm_wakeirq.h>
  17. #include <linux/regmap.h>
  18. #include <linux/seq_file.h>
  19. #include <linux/soc/qcom/smem.h>
  20. #include <linux/soc/qcom/smem_state.h>
  21. #include <linux/spinlock.h>
  22. /*
  23. * The Shared Memory Point to Point (SMP2P) protocol facilitates communication
  24. * of a single 32-bit value between two processors. Each value has a single
  25. * writer (the local side) and a single reader (the remote side). Values are
  26. * uniquely identified in the system by the directed edge (local processor ID
  27. * to remote processor ID) and a string identifier.
  28. *
  29. * Each processor is responsible for creating the outgoing SMEM items and each
  30. * item is writable by the local processor and readable by the remote
  31. * processor. By using two separate SMEM items that are single-reader and
  32. * single-writer, SMP2P does not require any remote locking mechanisms.
  33. *
  34. * The driver uses the Linux GPIO and interrupt framework to expose a virtual
  35. * GPIO for each outbound entry and a virtual interrupt controller for each
  36. * inbound entry.
  37. */
  38. #define SMP2P_MAX_ENTRY 16
  39. #define SMP2P_MAX_ENTRY_NAME 16
  40. #define SMP2P_FEATURE_SSR_ACK 0x1
  41. #define SMP2P_FLAGS_RESTART_DONE_BIT 0
  42. #define SMP2P_FLAGS_RESTART_ACK_BIT 1
  43. #define SMP2P_MAGIC 0x504d5324
  44. #define SMP2P_ALL_FEATURES SMP2P_FEATURE_SSR_ACK
  45. /**
  46. * struct smp2p_smem_item - in memory communication structure
  47. * @magic: magic number
  48. * @version: version - must be 1
  49. * @features: features flag - currently unused
  50. * @local_pid: processor id of sending end
  51. * @remote_pid: processor id of receiving end
  52. * @total_entries: number of entries - always SMP2P_MAX_ENTRY
  53. * @valid_entries: number of allocated entries
  54. * @flags:
  55. * @entries: individual communication entries
  56. * @entries.name: name of the entry
  57. * @entries.value: content of the entry
  58. */
  59. struct smp2p_smem_item {
  60. u32 magic;
  61. u8 version;
  62. unsigned features:24;
  63. u16 local_pid;
  64. u16 remote_pid;
  65. u16 total_entries;
  66. u16 valid_entries;
  67. u32 flags;
  68. struct {
  69. u8 name[SMP2P_MAX_ENTRY_NAME];
  70. u32 value;
  71. } entries[SMP2P_MAX_ENTRY];
  72. } __packed;
  73. /**
  74. * struct smp2p_entry - driver context matching one entry
  75. * @node: list entry to keep track of allocated entries
  76. * @smp2p: reference to the device driver context
  77. * @name: name of the entry, to match against smp2p_smem_item
  78. * @value: pointer to smp2p_smem_item entry value
  79. * @last_value: last handled value
  80. * @domain: irq_domain for inbound entries
  81. * @irq_enabled:bitmap to track enabled irq bits
  82. * @irq_rising: bitmap to mark irq bits for rising detection
  83. * @irq_falling:bitmap to mark irq bits for falling detection
  84. * @state: smem state handle
  85. * @lock: spinlock to protect read-modify-write of the value
  86. */
  87. struct smp2p_entry {
  88. struct list_head node;
  89. struct qcom_smp2p *smp2p;
  90. const char *name;
  91. u32 *value;
  92. u32 last_value;
  93. struct irq_domain *domain;
  94. DECLARE_BITMAP(irq_enabled, 32);
  95. DECLARE_BITMAP(irq_rising, 32);
  96. DECLARE_BITMAP(irq_falling, 32);
  97. struct qcom_smem_state *state;
  98. spinlock_t lock;
  99. };
  100. #define SMP2P_INBOUND 0
  101. #define SMP2P_OUTBOUND 1
  102. /**
  103. * struct qcom_smp2p - device driver context
  104. * @dev: device driver handle
  105. * @in: pointer to the inbound smem item
  106. * @out: pointer to the outbound smem item
  107. * @smem_items: ids of the two smem items
  108. * @valid_entries: already scanned inbound entries
  109. * @ssr_ack_enabled: SMP2P_FEATURE_SSR_ACK feature is supported and was enabled
  110. * @ssr_ack: current cached state of the local ack bit
  111. * @negotiation_done: whether negotiating finished
  112. * @local_pid: processor id of the inbound edge
  113. * @remote_pid: processor id of the outbound edge
  114. * @ipc_regmap: regmap for the outbound ipc
  115. * @ipc_offset: offset within the regmap
  116. * @ipc_bit: bit in regmap@offset to kick to signal remote processor
  117. * @mbox_client: mailbox client handle
  118. * @mbox_chan: apcs ipc mailbox channel handle
  119. * @inbound: list of inbound entries
  120. * @outbound: list of outbound entries
  121. */
  122. struct qcom_smp2p {
  123. struct device *dev;
  124. struct smp2p_smem_item *in;
  125. struct smp2p_smem_item *out;
  126. unsigned smem_items[SMP2P_OUTBOUND + 1];
  127. unsigned valid_entries;
  128. bool ssr_ack_enabled;
  129. bool ssr_ack;
  130. bool negotiation_done;
  131. unsigned local_pid;
  132. unsigned remote_pid;
  133. struct regmap *ipc_regmap;
  134. int ipc_offset;
  135. int ipc_bit;
  136. struct mbox_client mbox_client;
  137. struct mbox_chan *mbox_chan;
  138. struct list_head inbound;
  139. struct list_head outbound;
  140. };
  141. #define CREATE_TRACE_POINTS
  142. #include "trace-smp2p.h"
  143. static void qcom_smp2p_kick(struct qcom_smp2p *smp2p)
  144. {
  145. /* Make sure any updated data is written before the kick */
  146. wmb();
  147. if (smp2p->mbox_chan) {
  148. mbox_send_message(smp2p->mbox_chan, NULL);
  149. mbox_client_txdone(smp2p->mbox_chan, 0);
  150. } else {
  151. regmap_write(smp2p->ipc_regmap, smp2p->ipc_offset, BIT(smp2p->ipc_bit));
  152. }
  153. }
  154. static bool qcom_smp2p_check_ssr(struct qcom_smp2p *smp2p)
  155. {
  156. struct smp2p_smem_item *in = smp2p->in;
  157. bool restart;
  158. if (!smp2p->ssr_ack_enabled)
  159. return false;
  160. restart = in->flags & BIT(SMP2P_FLAGS_RESTART_DONE_BIT);
  161. return restart != smp2p->ssr_ack;
  162. }
  163. static void qcom_smp2p_do_ssr_ack(struct qcom_smp2p *smp2p)
  164. {
  165. struct smp2p_smem_item *out = smp2p->out;
  166. u32 val;
  167. trace_smp2p_ssr_ack(smp2p->dev);
  168. smp2p->ssr_ack = !smp2p->ssr_ack;
  169. val = out->flags & ~BIT(SMP2P_FLAGS_RESTART_ACK_BIT);
  170. if (smp2p->ssr_ack)
  171. val |= BIT(SMP2P_FLAGS_RESTART_ACK_BIT);
  172. out->flags = val;
  173. qcom_smp2p_kick(smp2p);
  174. }
  175. static void qcom_smp2p_negotiate(struct qcom_smp2p *smp2p)
  176. {
  177. struct smp2p_smem_item *out = smp2p->out;
  178. struct smp2p_smem_item *in = smp2p->in;
  179. if (in->version == out->version) {
  180. out->features &= in->features;
  181. if (out->features & SMP2P_FEATURE_SSR_ACK)
  182. smp2p->ssr_ack_enabled = true;
  183. smp2p->negotiation_done = true;
  184. trace_smp2p_negotiate(smp2p->dev, out->features);
  185. }
  186. }
  187. static void qcom_smp2p_notify_in(struct qcom_smp2p *smp2p)
  188. {
  189. struct smp2p_smem_item *in;
  190. struct smp2p_entry *entry;
  191. int irq_pin;
  192. u32 status;
  193. char buf[SMP2P_MAX_ENTRY_NAME];
  194. u32 val;
  195. int i;
  196. in = smp2p->in;
  197. /* Match newly created entries */
  198. for (i = smp2p->valid_entries; i < in->valid_entries; i++) {
  199. list_for_each_entry(entry, &smp2p->inbound, node) {
  200. memcpy(buf, in->entries[i].name, sizeof(buf));
  201. if (!strcmp(buf, entry->name)) {
  202. entry->value = &in->entries[i].value;
  203. break;
  204. }
  205. }
  206. }
  207. smp2p->valid_entries = i;
  208. /* Fire interrupts based on any value changes */
  209. list_for_each_entry(entry, &smp2p->inbound, node) {
  210. /* Ignore entries not yet allocated by the remote side */
  211. if (!entry->value)
  212. continue;
  213. val = readl(entry->value);
  214. status = val ^ entry->last_value;
  215. entry->last_value = val;
  216. trace_smp2p_notify_in(entry, status, val);
  217. /* No changes of this entry? */
  218. if (!status)
  219. continue;
  220. for_each_set_bit(i, entry->irq_enabled, 32) {
  221. if (!(status & BIT(i)))
  222. continue;
  223. if ((val & BIT(i) && test_bit(i, entry->irq_rising)) ||
  224. (!(val & BIT(i)) && test_bit(i, entry->irq_falling))) {
  225. irq_pin = irq_find_mapping(entry->domain, i);
  226. handle_nested_irq(irq_pin);
  227. }
  228. }
  229. }
  230. }
  231. /**
  232. * qcom_smp2p_intr() - interrupt handler for incoming notifications
  233. * @irq: unused
  234. * @data: smp2p driver context
  235. *
  236. * Handle notifications from the remote side to handle newly allocated entries
  237. * or any changes to the state bits of existing entries.
  238. *
  239. * Return: %IRQ_HANDLED
  240. */
  241. static irqreturn_t qcom_smp2p_intr(int irq, void *data)
  242. {
  243. struct smp2p_smem_item *in;
  244. struct qcom_smp2p *smp2p = data;
  245. unsigned int smem_id = smp2p->smem_items[SMP2P_INBOUND];
  246. unsigned int pid = smp2p->remote_pid;
  247. bool ack_restart;
  248. size_t size;
  249. in = smp2p->in;
  250. /* Acquire smem item, if not already found */
  251. if (!in) {
  252. in = qcom_smem_get(pid, smem_id, &size);
  253. if (IS_ERR(in)) {
  254. dev_err(smp2p->dev,
  255. "Unable to acquire remote smp2p item\n");
  256. goto out;
  257. }
  258. smp2p->in = in;
  259. }
  260. if (!smp2p->negotiation_done)
  261. qcom_smp2p_negotiate(smp2p);
  262. if (smp2p->negotiation_done) {
  263. ack_restart = qcom_smp2p_check_ssr(smp2p);
  264. qcom_smp2p_notify_in(smp2p);
  265. if (ack_restart)
  266. qcom_smp2p_do_ssr_ack(smp2p);
  267. }
  268. out:
  269. return IRQ_HANDLED;
  270. }
  271. static void smp2p_mask_irq(struct irq_data *irqd)
  272. {
  273. struct smp2p_entry *entry = irq_data_get_irq_chip_data(irqd);
  274. irq_hw_number_t irq = irqd_to_hwirq(irqd);
  275. clear_bit(irq, entry->irq_enabled);
  276. }
  277. static void smp2p_unmask_irq(struct irq_data *irqd)
  278. {
  279. struct smp2p_entry *entry = irq_data_get_irq_chip_data(irqd);
  280. irq_hw_number_t irq = irqd_to_hwirq(irqd);
  281. set_bit(irq, entry->irq_enabled);
  282. }
  283. static int smp2p_set_irq_type(struct irq_data *irqd, unsigned int type)
  284. {
  285. struct smp2p_entry *entry = irq_data_get_irq_chip_data(irqd);
  286. irq_hw_number_t irq = irqd_to_hwirq(irqd);
  287. if (!(type & IRQ_TYPE_EDGE_BOTH))
  288. return -EINVAL;
  289. if (type & IRQ_TYPE_EDGE_RISING)
  290. set_bit(irq, entry->irq_rising);
  291. else
  292. clear_bit(irq, entry->irq_rising);
  293. if (type & IRQ_TYPE_EDGE_FALLING)
  294. set_bit(irq, entry->irq_falling);
  295. else
  296. clear_bit(irq, entry->irq_falling);
  297. return 0;
  298. }
  299. static void smp2p_irq_print_chip(struct irq_data *irqd, struct seq_file *p)
  300. {
  301. struct smp2p_entry *entry = irq_data_get_irq_chip_data(irqd);
  302. seq_printf(p, " %8s", dev_name(entry->smp2p->dev));
  303. }
  304. static struct irq_chip smp2p_irq_chip = {
  305. .name = "smp2p",
  306. .irq_mask = smp2p_mask_irq,
  307. .irq_unmask = smp2p_unmask_irq,
  308. .irq_set_type = smp2p_set_irq_type,
  309. .irq_print_chip = smp2p_irq_print_chip,
  310. };
  311. static int smp2p_irq_map(struct irq_domain *d,
  312. unsigned int irq,
  313. irq_hw_number_t hw)
  314. {
  315. struct smp2p_entry *entry = d->host_data;
  316. irq_set_chip_and_handler(irq, &smp2p_irq_chip, handle_level_irq);
  317. irq_set_chip_data(irq, entry);
  318. irq_set_nested_thread(irq, 1);
  319. irq_set_noprobe(irq);
  320. return 0;
  321. }
  322. static const struct irq_domain_ops smp2p_irq_ops = {
  323. .map = smp2p_irq_map,
  324. .xlate = irq_domain_xlate_twocell,
  325. };
  326. static int qcom_smp2p_inbound_entry(struct qcom_smp2p *smp2p,
  327. struct smp2p_entry *entry,
  328. struct device_node *node)
  329. {
  330. entry->domain = irq_domain_add_linear(node, 32, &smp2p_irq_ops, entry);
  331. if (!entry->domain) {
  332. dev_err(smp2p->dev, "failed to add irq_domain\n");
  333. return -ENOMEM;
  334. }
  335. return 0;
  336. }
  337. static int smp2p_update_bits(void *data, u32 mask, u32 value)
  338. {
  339. struct smp2p_entry *entry = data;
  340. unsigned long flags;
  341. u32 orig;
  342. u32 val;
  343. spin_lock_irqsave(&entry->lock, flags);
  344. val = orig = readl(entry->value);
  345. val &= ~mask;
  346. val |= value;
  347. writel(val, entry->value);
  348. spin_unlock_irqrestore(&entry->lock, flags);
  349. trace_smp2p_update_bits(entry, orig, val);
  350. if (val != orig)
  351. qcom_smp2p_kick(entry->smp2p);
  352. return 0;
  353. }
  354. static const struct qcom_smem_state_ops smp2p_state_ops = {
  355. .update_bits = smp2p_update_bits,
  356. };
  357. static int qcom_smp2p_outbound_entry(struct qcom_smp2p *smp2p,
  358. struct smp2p_entry *entry,
  359. struct device_node *node)
  360. {
  361. struct smp2p_smem_item *out = smp2p->out;
  362. char buf[SMP2P_MAX_ENTRY_NAME] = {};
  363. /* Allocate an entry from the smem item */
  364. strscpy(buf, entry->name, SMP2P_MAX_ENTRY_NAME);
  365. memcpy(out->entries[out->valid_entries].name, buf, SMP2P_MAX_ENTRY_NAME);
  366. /* Make the logical entry reference the physical value */
  367. entry->value = &out->entries[out->valid_entries].value;
  368. out->valid_entries++;
  369. entry->state = qcom_smem_state_register(node, &smp2p_state_ops, entry);
  370. if (IS_ERR(entry->state)) {
  371. dev_err(smp2p->dev, "failed to register qcom_smem_state\n");
  372. return PTR_ERR(entry->state);
  373. }
  374. return 0;
  375. }
  376. static int qcom_smp2p_alloc_outbound_item(struct qcom_smp2p *smp2p)
  377. {
  378. struct smp2p_smem_item *out;
  379. unsigned smem_id = smp2p->smem_items[SMP2P_OUTBOUND];
  380. unsigned pid = smp2p->remote_pid;
  381. int ret;
  382. ret = qcom_smem_alloc(pid, smem_id, sizeof(*out));
  383. if (ret < 0 && ret != -EEXIST) {
  384. if (ret != -EPROBE_DEFER)
  385. dev_err(smp2p->dev,
  386. "unable to allocate local smp2p item\n");
  387. return ret;
  388. }
  389. out = qcom_smem_get(pid, smem_id, NULL);
  390. if (IS_ERR(out)) {
  391. dev_err(smp2p->dev, "Unable to acquire local smp2p item\n");
  392. return PTR_ERR(out);
  393. }
  394. memset(out, 0, sizeof(*out));
  395. out->magic = SMP2P_MAGIC;
  396. out->local_pid = smp2p->local_pid;
  397. out->remote_pid = smp2p->remote_pid;
  398. out->total_entries = SMP2P_MAX_ENTRY;
  399. out->valid_entries = 0;
  400. out->features = SMP2P_ALL_FEATURES;
  401. /*
  402. * Make sure the rest of the header is written before we validate the
  403. * item by writing a valid version number.
  404. */
  405. wmb();
  406. out->version = 1;
  407. qcom_smp2p_kick(smp2p);
  408. smp2p->out = out;
  409. return 0;
  410. }
  411. static int smp2p_parse_ipc(struct qcom_smp2p *smp2p)
  412. {
  413. struct device_node *syscon;
  414. struct device *dev = smp2p->dev;
  415. const char *key;
  416. int ret;
  417. syscon = of_parse_phandle(dev->of_node, "qcom,ipc", 0);
  418. if (!syscon) {
  419. dev_err(dev, "no qcom,ipc node\n");
  420. return -ENODEV;
  421. }
  422. smp2p->ipc_regmap = syscon_node_to_regmap(syscon);
  423. of_node_put(syscon);
  424. if (IS_ERR(smp2p->ipc_regmap))
  425. return PTR_ERR(smp2p->ipc_regmap);
  426. key = "qcom,ipc";
  427. ret = of_property_read_u32_index(dev->of_node, key, 1, &smp2p->ipc_offset);
  428. if (ret < 0) {
  429. dev_err(dev, "no offset in %s\n", key);
  430. return -EINVAL;
  431. }
  432. ret = of_property_read_u32_index(dev->of_node, key, 2, &smp2p->ipc_bit);
  433. if (ret < 0) {
  434. dev_err(dev, "no bit in %s\n", key);
  435. return -EINVAL;
  436. }
  437. return 0;
  438. }
  439. static int qcom_smp2p_probe(struct platform_device *pdev)
  440. {
  441. struct smp2p_entry *entry;
  442. struct qcom_smp2p *smp2p;
  443. const char *key;
  444. int irq;
  445. int ret;
  446. smp2p = devm_kzalloc(&pdev->dev, sizeof(*smp2p), GFP_KERNEL);
  447. if (!smp2p)
  448. return -ENOMEM;
  449. smp2p->dev = &pdev->dev;
  450. INIT_LIST_HEAD(&smp2p->inbound);
  451. INIT_LIST_HEAD(&smp2p->outbound);
  452. platform_set_drvdata(pdev, smp2p);
  453. key = "qcom,smem";
  454. ret = of_property_read_u32_array(pdev->dev.of_node, key,
  455. smp2p->smem_items, 2);
  456. if (ret)
  457. return ret;
  458. key = "qcom,local-pid";
  459. ret = of_property_read_u32(pdev->dev.of_node, key, &smp2p->local_pid);
  460. if (ret)
  461. goto report_read_failure;
  462. key = "qcom,remote-pid";
  463. ret = of_property_read_u32(pdev->dev.of_node, key, &smp2p->remote_pid);
  464. if (ret)
  465. goto report_read_failure;
  466. irq = platform_get_irq(pdev, 0);
  467. if (irq < 0)
  468. return irq;
  469. smp2p->mbox_client.dev = &pdev->dev;
  470. smp2p->mbox_client.knows_txdone = true;
  471. smp2p->mbox_chan = mbox_request_channel(&smp2p->mbox_client, 0);
  472. if (IS_ERR(smp2p->mbox_chan)) {
  473. if (PTR_ERR(smp2p->mbox_chan) != -ENOENT)
  474. return PTR_ERR(smp2p->mbox_chan);
  475. smp2p->mbox_chan = NULL;
  476. ret = smp2p_parse_ipc(smp2p);
  477. if (ret)
  478. return ret;
  479. }
  480. ret = qcom_smp2p_alloc_outbound_item(smp2p);
  481. if (ret < 0)
  482. goto release_mbox;
  483. for_each_available_child_of_node_scoped(pdev->dev.of_node, node) {
  484. entry = devm_kzalloc(&pdev->dev, sizeof(*entry), GFP_KERNEL);
  485. if (!entry) {
  486. ret = -ENOMEM;
  487. goto unwind_interfaces;
  488. }
  489. entry->smp2p = smp2p;
  490. spin_lock_init(&entry->lock);
  491. ret = of_property_read_string(node, "qcom,entry-name", &entry->name);
  492. if (ret < 0)
  493. goto unwind_interfaces;
  494. if (of_property_read_bool(node, "interrupt-controller")) {
  495. ret = qcom_smp2p_inbound_entry(smp2p, entry, node);
  496. if (ret < 0)
  497. goto unwind_interfaces;
  498. list_add(&entry->node, &smp2p->inbound);
  499. } else {
  500. ret = qcom_smp2p_outbound_entry(smp2p, entry, node);
  501. if (ret < 0)
  502. goto unwind_interfaces;
  503. list_add(&entry->node, &smp2p->outbound);
  504. }
  505. }
  506. /* Kick the outgoing edge after allocating entries */
  507. qcom_smp2p_kick(smp2p);
  508. ret = devm_request_threaded_irq(&pdev->dev, irq,
  509. NULL, qcom_smp2p_intr,
  510. IRQF_ONESHOT,
  511. NULL, (void *)smp2p);
  512. if (ret) {
  513. dev_err(&pdev->dev, "failed to request interrupt\n");
  514. goto unwind_interfaces;
  515. }
  516. /*
  517. * Treat smp2p interrupt as wakeup source, but keep it disabled
  518. * by default. User space can decide enabling it depending on its
  519. * use cases. For example if remoteproc crashes and device wants
  520. * to handle it immediatedly (e.g. to not miss phone calls) it can
  521. * enable wakeup source from user space, while other devices which
  522. * do not have proper autosleep feature may want to handle it with
  523. * other wakeup events (e.g. Power button) instead waking up immediately.
  524. */
  525. device_set_wakeup_capable(&pdev->dev, true);
  526. ret = dev_pm_set_wake_irq(&pdev->dev, irq);
  527. if (ret)
  528. goto set_wake_irq_fail;
  529. return 0;
  530. set_wake_irq_fail:
  531. dev_pm_clear_wake_irq(&pdev->dev);
  532. unwind_interfaces:
  533. list_for_each_entry(entry, &smp2p->inbound, node)
  534. irq_domain_remove(entry->domain);
  535. list_for_each_entry(entry, &smp2p->outbound, node)
  536. qcom_smem_state_unregister(entry->state);
  537. smp2p->out->valid_entries = 0;
  538. release_mbox:
  539. mbox_free_channel(smp2p->mbox_chan);
  540. return ret;
  541. report_read_failure:
  542. dev_err(&pdev->dev, "failed to read %s\n", key);
  543. return -EINVAL;
  544. }
  545. static void qcom_smp2p_remove(struct platform_device *pdev)
  546. {
  547. struct qcom_smp2p *smp2p = platform_get_drvdata(pdev);
  548. struct smp2p_entry *entry;
  549. dev_pm_clear_wake_irq(&pdev->dev);
  550. list_for_each_entry(entry, &smp2p->inbound, node)
  551. irq_domain_remove(entry->domain);
  552. list_for_each_entry(entry, &smp2p->outbound, node)
  553. qcom_smem_state_unregister(entry->state);
  554. mbox_free_channel(smp2p->mbox_chan);
  555. smp2p->out->valid_entries = 0;
  556. }
  557. static const struct of_device_id qcom_smp2p_of_match[] = {
  558. { .compatible = "qcom,smp2p" },
  559. {}
  560. };
  561. MODULE_DEVICE_TABLE(of, qcom_smp2p_of_match);
  562. static struct platform_driver qcom_smp2p_driver = {
  563. .probe = qcom_smp2p_probe,
  564. .remove_new = qcom_smp2p_remove,
  565. .driver = {
  566. .name = "qcom_smp2p",
  567. .of_match_table = qcom_smp2p_of_match,
  568. },
  569. };
  570. module_platform_driver(qcom_smp2p_driver);
  571. MODULE_DESCRIPTION("Qualcomm Shared Memory Point to Point driver");
  572. MODULE_LICENSE("GPL v2");