smsm.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015, Sony Mobile Communications Inc.
  4. * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  5. */
  6. #include <linux/interrupt.h>
  7. #include <linux/mailbox_client.h>
  8. #include <linux/mfd/syscon.h>
  9. #include <linux/module.h>
  10. #include <linux/of_irq.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/regmap.h>
  14. #include <linux/soc/qcom/smem.h>
  15. #include <linux/soc/qcom/smem_state.h>
  16. /*
  17. * This driver implements the Qualcomm Shared Memory State Machine, a mechanism
  18. * for communicating single bit state information to remote processors.
  19. *
  20. * The implementation is based on two sections of shared memory; the first
  21. * holding the state bits and the second holding a matrix of subscription bits.
  22. *
  23. * The state bits are structured in entries of 32 bits, each belonging to one
  24. * system in the SoC. The entry belonging to the local system is considered
  25. * read-write, while the rest should be considered read-only.
  26. *
  27. * The subscription matrix consists of N bitmaps per entry, denoting interest
  28. * in updates of the entry for each of the N hosts. Upon updating a state bit
  29. * each host's subscription bitmap should be queried and the remote system
  30. * should be interrupted if they request so.
  31. *
  32. * The subscription matrix is laid out in entry-major order:
  33. * entry0: [host0 ... hostN]
  34. * .
  35. * .
  36. * entryM: [host0 ... hostN]
  37. *
  38. * A third, optional, shared memory region might contain information regarding
  39. * the number of entries in the state bitmap as well as number of columns in
  40. * the subscription matrix.
  41. */
  42. /*
  43. * Shared memory identifiers, used to acquire handles to respective memory
  44. * region.
  45. */
  46. #define SMEM_SMSM_SHARED_STATE 85
  47. #define SMEM_SMSM_CPU_INTR_MASK 333
  48. #define SMEM_SMSM_SIZE_INFO 419
  49. /*
  50. * Default sizes, in case SMEM_SMSM_SIZE_INFO is not found.
  51. */
  52. #define SMSM_DEFAULT_NUM_ENTRIES 8
  53. #define SMSM_DEFAULT_NUM_HOSTS 3
  54. struct smsm_entry;
  55. struct smsm_host;
  56. /**
  57. * struct qcom_smsm - smsm driver context
  58. * @dev: smsm device pointer
  59. * @local_host: column in the subscription matrix representing this system
  60. * @num_hosts: number of columns in the subscription matrix
  61. * @num_entries: number of entries in the state map and rows in the subscription
  62. * matrix
  63. * @local_state: pointer to the local processor's state bits
  64. * @subscription: pointer to local processor's row in subscription matrix
  65. * @state: smem state handle
  66. * @lock: spinlock for read-modify-write of the outgoing state
  67. * @entries: context for each of the entries
  68. * @hosts: context for each of the hosts
  69. * @mbox_client: mailbox client handle
  70. */
  71. struct qcom_smsm {
  72. struct device *dev;
  73. u32 local_host;
  74. u32 num_hosts;
  75. u32 num_entries;
  76. u32 *local_state;
  77. u32 *subscription;
  78. struct qcom_smem_state *state;
  79. spinlock_t lock;
  80. struct smsm_entry *entries;
  81. struct smsm_host *hosts;
  82. struct mbox_client mbox_client;
  83. };
  84. /**
  85. * struct smsm_entry - per remote processor entry context
  86. * @smsm: back-reference to driver context
  87. * @domain: IRQ domain for this entry, if representing a remote system
  88. * @irq_enabled: bitmap of which state bits IRQs are enabled
  89. * @irq_rising: bitmap tracking if rising bits should be propagated
  90. * @irq_falling: bitmap tracking if falling bits should be propagated
  91. * @last_value: snapshot of state bits last time the interrupts where propagated
  92. * @remote_state: pointer to this entry's state bits
  93. * @subscription: pointer to a row in the subscription matrix representing this
  94. * entry
  95. */
  96. struct smsm_entry {
  97. struct qcom_smsm *smsm;
  98. struct irq_domain *domain;
  99. DECLARE_BITMAP(irq_enabled, 32);
  100. DECLARE_BITMAP(irq_rising, 32);
  101. DECLARE_BITMAP(irq_falling, 32);
  102. unsigned long last_value;
  103. u32 *remote_state;
  104. u32 *subscription;
  105. };
  106. /**
  107. * struct smsm_host - representation of a remote host
  108. * @ipc_regmap: regmap for outgoing interrupt
  109. * @ipc_offset: offset in @ipc_regmap for outgoing interrupt
  110. * @ipc_bit: bit in @ipc_regmap + @ipc_offset for outgoing interrupt
  111. * @mbox_chan: apcs ipc mailbox channel handle
  112. */
  113. struct smsm_host {
  114. struct regmap *ipc_regmap;
  115. int ipc_offset;
  116. int ipc_bit;
  117. struct mbox_chan *mbox_chan;
  118. };
  119. /**
  120. * smsm_update_bits() - change bit in outgoing entry and inform subscribers
  121. * @data: smsm context pointer
  122. * @mask: value mask
  123. * @value: new value
  124. *
  125. * Used to set and clear the bits in the outgoing/local entry and inform
  126. * subscribers about the change.
  127. */
  128. static int smsm_update_bits(void *data, u32 mask, u32 value)
  129. {
  130. struct qcom_smsm *smsm = data;
  131. struct smsm_host *hostp;
  132. unsigned long flags;
  133. u32 changes;
  134. u32 host;
  135. u32 orig;
  136. u32 val;
  137. spin_lock_irqsave(&smsm->lock, flags);
  138. /* Update the entry */
  139. val = orig = readl(smsm->local_state);
  140. val &= ~mask;
  141. val |= value;
  142. /* Don't signal if we didn't change the value */
  143. changes = val ^ orig;
  144. if (!changes) {
  145. spin_unlock_irqrestore(&smsm->lock, flags);
  146. goto done;
  147. }
  148. /* Write out the new value */
  149. writel(val, smsm->local_state);
  150. spin_unlock_irqrestore(&smsm->lock, flags);
  151. /* Make sure the value update is ordered before any kicks */
  152. wmb();
  153. /* Iterate over all hosts to check whom wants a kick */
  154. for (host = 0; host < smsm->num_hosts; host++) {
  155. hostp = &smsm->hosts[host];
  156. val = readl(smsm->subscription + host);
  157. if (!(val & changes))
  158. continue;
  159. if (hostp->mbox_chan) {
  160. mbox_send_message(hostp->mbox_chan, NULL);
  161. mbox_client_txdone(hostp->mbox_chan, 0);
  162. } else if (hostp->ipc_regmap) {
  163. regmap_write(hostp->ipc_regmap,
  164. hostp->ipc_offset,
  165. BIT(hostp->ipc_bit));
  166. }
  167. }
  168. done:
  169. return 0;
  170. }
  171. static const struct qcom_smem_state_ops smsm_state_ops = {
  172. .update_bits = smsm_update_bits,
  173. };
  174. /**
  175. * smsm_intr() - cascading IRQ handler for SMSM
  176. * @irq: unused
  177. * @data: entry related to this IRQ
  178. *
  179. * This function cascades an incoming interrupt from a remote system, based on
  180. * the state bits and configuration.
  181. */
  182. static irqreturn_t smsm_intr(int irq, void *data)
  183. {
  184. struct smsm_entry *entry = data;
  185. unsigned i;
  186. int irq_pin;
  187. u32 changed;
  188. u32 val;
  189. val = readl(entry->remote_state);
  190. changed = val ^ xchg(&entry->last_value, val);
  191. for_each_set_bit(i, entry->irq_enabled, 32) {
  192. if (!(changed & BIT(i)))
  193. continue;
  194. if (val & BIT(i)) {
  195. if (test_bit(i, entry->irq_rising)) {
  196. irq_pin = irq_find_mapping(entry->domain, i);
  197. handle_nested_irq(irq_pin);
  198. }
  199. } else {
  200. if (test_bit(i, entry->irq_falling)) {
  201. irq_pin = irq_find_mapping(entry->domain, i);
  202. handle_nested_irq(irq_pin);
  203. }
  204. }
  205. }
  206. return IRQ_HANDLED;
  207. }
  208. /**
  209. * smsm_mask_irq() - un-subscribe from cascades of IRQs of a certain staus bit
  210. * @irqd: IRQ handle to be masked
  211. *
  212. * This un-subscribes the local CPU from interrupts upon changes to the defines
  213. * status bit. The bit is also cleared from cascading.
  214. */
  215. static void smsm_mask_irq(struct irq_data *irqd)
  216. {
  217. struct smsm_entry *entry = irq_data_get_irq_chip_data(irqd);
  218. irq_hw_number_t irq = irqd_to_hwirq(irqd);
  219. struct qcom_smsm *smsm = entry->smsm;
  220. u32 val;
  221. if (entry->subscription) {
  222. val = readl(entry->subscription + smsm->local_host);
  223. val &= ~BIT(irq);
  224. writel(val, entry->subscription + smsm->local_host);
  225. }
  226. clear_bit(irq, entry->irq_enabled);
  227. }
  228. /**
  229. * smsm_unmask_irq() - subscribe to cascades of IRQs of a certain status bit
  230. * @irqd: IRQ handle to be unmasked
  231. *
  232. * This subscribes the local CPU to interrupts upon changes to the defined
  233. * status bit. The bit is also marked for cascading.
  234. */
  235. static void smsm_unmask_irq(struct irq_data *irqd)
  236. {
  237. struct smsm_entry *entry = irq_data_get_irq_chip_data(irqd);
  238. irq_hw_number_t irq = irqd_to_hwirq(irqd);
  239. struct qcom_smsm *smsm = entry->smsm;
  240. u32 val;
  241. /* Make sure our last cached state is up-to-date */
  242. if (readl(entry->remote_state) & BIT(irq))
  243. set_bit(irq, &entry->last_value);
  244. else
  245. clear_bit(irq, &entry->last_value);
  246. set_bit(irq, entry->irq_enabled);
  247. if (entry->subscription) {
  248. val = readl(entry->subscription + smsm->local_host);
  249. val |= BIT(irq);
  250. writel(val, entry->subscription + smsm->local_host);
  251. }
  252. }
  253. /**
  254. * smsm_set_irq_type() - updates the requested IRQ type for the cascading
  255. * @irqd: consumer interrupt handle
  256. * @type: requested flags
  257. */
  258. static int smsm_set_irq_type(struct irq_data *irqd, unsigned int type)
  259. {
  260. struct smsm_entry *entry = irq_data_get_irq_chip_data(irqd);
  261. irq_hw_number_t irq = irqd_to_hwirq(irqd);
  262. if (!(type & IRQ_TYPE_EDGE_BOTH))
  263. return -EINVAL;
  264. if (type & IRQ_TYPE_EDGE_RISING)
  265. set_bit(irq, entry->irq_rising);
  266. else
  267. clear_bit(irq, entry->irq_rising);
  268. if (type & IRQ_TYPE_EDGE_FALLING)
  269. set_bit(irq, entry->irq_falling);
  270. else
  271. clear_bit(irq, entry->irq_falling);
  272. return 0;
  273. }
  274. static int smsm_get_irqchip_state(struct irq_data *irqd,
  275. enum irqchip_irq_state which, bool *state)
  276. {
  277. struct smsm_entry *entry = irq_data_get_irq_chip_data(irqd);
  278. irq_hw_number_t irq = irqd_to_hwirq(irqd);
  279. u32 val;
  280. if (which != IRQCHIP_STATE_LINE_LEVEL)
  281. return -EINVAL;
  282. val = readl(entry->remote_state);
  283. *state = !!(val & BIT(irq));
  284. return 0;
  285. }
  286. static struct irq_chip smsm_irq_chip = {
  287. .name = "smsm",
  288. .irq_mask = smsm_mask_irq,
  289. .irq_unmask = smsm_unmask_irq,
  290. .irq_set_type = smsm_set_irq_type,
  291. .irq_get_irqchip_state = smsm_get_irqchip_state,
  292. };
  293. /**
  294. * smsm_irq_map() - sets up a mapping for a cascaded IRQ
  295. * @d: IRQ domain representing an entry
  296. * @irq: IRQ to set up
  297. * @hw: unused
  298. */
  299. static int smsm_irq_map(struct irq_domain *d,
  300. unsigned int irq,
  301. irq_hw_number_t hw)
  302. {
  303. struct smsm_entry *entry = d->host_data;
  304. irq_set_chip_and_handler(irq, &smsm_irq_chip, handle_level_irq);
  305. irq_set_chip_data(irq, entry);
  306. irq_set_nested_thread(irq, 1);
  307. return 0;
  308. }
  309. static const struct irq_domain_ops smsm_irq_ops = {
  310. .map = smsm_irq_map,
  311. .xlate = irq_domain_xlate_twocell,
  312. };
  313. /**
  314. * smsm_parse_mbox() - requests an mbox channel
  315. * @smsm: smsm driver context
  316. * @host_id: index of the remote host to be resolved
  317. *
  318. * Requests the desired channel using the mbox interface which is needed for
  319. * sending the outgoing interrupts to a remove hosts - identified by @host_id.
  320. */
  321. static int smsm_parse_mbox(struct qcom_smsm *smsm, unsigned int host_id)
  322. {
  323. struct smsm_host *host = &smsm->hosts[host_id];
  324. int ret = 0;
  325. host->mbox_chan = mbox_request_channel(&smsm->mbox_client, host_id);
  326. if (IS_ERR(host->mbox_chan)) {
  327. ret = PTR_ERR(host->mbox_chan);
  328. host->mbox_chan = NULL;
  329. }
  330. return ret;
  331. }
  332. /**
  333. * smsm_parse_ipc() - parses a qcom,ipc-%d device tree property
  334. * @smsm: smsm driver context
  335. * @host_id: index of the remote host to be resolved
  336. *
  337. * Parses device tree to acquire the information needed for sending the
  338. * outgoing interrupts to a remote host - identified by @host_id.
  339. */
  340. static int smsm_parse_ipc(struct qcom_smsm *smsm, unsigned host_id)
  341. {
  342. struct device_node *syscon;
  343. struct device_node *node = smsm->dev->of_node;
  344. struct smsm_host *host = &smsm->hosts[host_id];
  345. char key[16];
  346. int ret;
  347. snprintf(key, sizeof(key), "qcom,ipc-%d", host_id);
  348. syscon = of_parse_phandle(node, key, 0);
  349. if (!syscon)
  350. return 0;
  351. host->ipc_regmap = syscon_node_to_regmap(syscon);
  352. of_node_put(syscon);
  353. if (IS_ERR(host->ipc_regmap))
  354. return PTR_ERR(host->ipc_regmap);
  355. ret = of_property_read_u32_index(node, key, 1, &host->ipc_offset);
  356. if (ret < 0) {
  357. dev_err(smsm->dev, "no offset in %s\n", key);
  358. return -EINVAL;
  359. }
  360. ret = of_property_read_u32_index(node, key, 2, &host->ipc_bit);
  361. if (ret < 0) {
  362. dev_err(smsm->dev, "no bit in %s\n", key);
  363. return -EINVAL;
  364. }
  365. return 0;
  366. }
  367. /**
  368. * smsm_inbound_entry() - parse DT and set up an entry representing a remote system
  369. * @smsm: smsm driver context
  370. * @entry: entry context to be set up
  371. * @node: dt node containing the entry's properties
  372. */
  373. static int smsm_inbound_entry(struct qcom_smsm *smsm,
  374. struct smsm_entry *entry,
  375. struct device_node *node)
  376. {
  377. int ret;
  378. int irq;
  379. irq = irq_of_parse_and_map(node, 0);
  380. if (!irq) {
  381. dev_err(smsm->dev, "failed to parse smsm interrupt\n");
  382. return -EINVAL;
  383. }
  384. ret = devm_request_threaded_irq(smsm->dev, irq,
  385. NULL, smsm_intr,
  386. IRQF_ONESHOT,
  387. "smsm", (void *)entry);
  388. if (ret) {
  389. dev_err(smsm->dev, "failed to request interrupt\n");
  390. return ret;
  391. }
  392. entry->domain = irq_domain_create_linear(of_fwnode_handle(node), 32, &smsm_irq_ops, entry);
  393. if (!entry->domain) {
  394. dev_err(smsm->dev, "failed to add irq_domain\n");
  395. return -ENOMEM;
  396. }
  397. return 0;
  398. }
  399. /**
  400. * smsm_get_size_info() - parse the optional memory segment for sizes
  401. * @smsm: smsm driver context
  402. *
  403. * Attempt to acquire the number of hosts and entries from the optional shared
  404. * memory location. Not being able to find this segment should indicate that
  405. * we're on a older system where these values was hard coded to
  406. * SMSM_DEFAULT_NUM_ENTRIES and SMSM_DEFAULT_NUM_HOSTS.
  407. *
  408. * Returns 0 on success, negative errno on failure.
  409. */
  410. static int smsm_get_size_info(struct qcom_smsm *smsm)
  411. {
  412. size_t size;
  413. struct {
  414. u32 num_hosts;
  415. u32 num_entries;
  416. u32 reserved0;
  417. u32 reserved1;
  418. } *info;
  419. info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_SMSM_SIZE_INFO, &size);
  420. if (IS_ERR(info) && PTR_ERR(info) != -ENOENT)
  421. return dev_err_probe(smsm->dev, PTR_ERR(info),
  422. "unable to retrieve smsm size info\n");
  423. else if (IS_ERR(info) || size != sizeof(*info)) {
  424. dev_warn(smsm->dev, "no smsm size info, using defaults\n");
  425. smsm->num_entries = SMSM_DEFAULT_NUM_ENTRIES;
  426. smsm->num_hosts = SMSM_DEFAULT_NUM_HOSTS;
  427. return 0;
  428. }
  429. smsm->num_entries = info->num_entries;
  430. smsm->num_hosts = info->num_hosts;
  431. dev_dbg(smsm->dev,
  432. "found custom size of smsm: %d entries %d hosts\n",
  433. smsm->num_entries, smsm->num_hosts);
  434. return 0;
  435. }
  436. static int qcom_smsm_probe(struct platform_device *pdev)
  437. {
  438. struct device_node *local_node;
  439. struct device_node *node;
  440. struct smsm_entry *entry;
  441. struct qcom_smsm *smsm;
  442. u32 *intr_mask;
  443. size_t size;
  444. u32 *states;
  445. u32 id;
  446. int ret;
  447. smsm = devm_kzalloc(&pdev->dev, sizeof(*smsm), GFP_KERNEL);
  448. if (!smsm)
  449. return -ENOMEM;
  450. smsm->dev = &pdev->dev;
  451. spin_lock_init(&smsm->lock);
  452. ret = smsm_get_size_info(smsm);
  453. if (ret)
  454. return ret;
  455. smsm->entries = devm_kcalloc(&pdev->dev,
  456. smsm->num_entries,
  457. sizeof(struct smsm_entry),
  458. GFP_KERNEL);
  459. if (!smsm->entries)
  460. return -ENOMEM;
  461. smsm->hosts = devm_kcalloc(&pdev->dev,
  462. smsm->num_hosts,
  463. sizeof(struct smsm_host),
  464. GFP_KERNEL);
  465. if (!smsm->hosts)
  466. return -ENOMEM;
  467. for_each_child_of_node(pdev->dev.of_node, local_node) {
  468. if (of_property_present(local_node, "#qcom,smem-state-cells"))
  469. break;
  470. }
  471. if (!local_node) {
  472. dev_err(&pdev->dev, "no state entry\n");
  473. return -EINVAL;
  474. }
  475. of_property_read_u32(pdev->dev.of_node,
  476. "qcom,local-host",
  477. &smsm->local_host);
  478. smsm->mbox_client.dev = &pdev->dev;
  479. smsm->mbox_client.knows_txdone = true;
  480. /* Parse the host properties */
  481. for (id = 0; id < smsm->num_hosts; id++) {
  482. /* Try using mbox interface first, otherwise fall back to syscon */
  483. ret = smsm_parse_mbox(smsm, id);
  484. if (!ret)
  485. continue;
  486. ret = smsm_parse_ipc(smsm, id);
  487. if (ret < 0)
  488. goto out_put;
  489. }
  490. /* Acquire the main SMSM state vector */
  491. ret = qcom_smem_alloc(QCOM_SMEM_HOST_ANY, SMEM_SMSM_SHARED_STATE,
  492. smsm->num_entries * sizeof(u32));
  493. if (ret < 0 && ret != -EEXIST) {
  494. dev_err(&pdev->dev, "unable to allocate shared state entry\n");
  495. goto out_put;
  496. }
  497. states = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_SMSM_SHARED_STATE, NULL);
  498. if (IS_ERR(states)) {
  499. dev_err(&pdev->dev, "Unable to acquire shared state entry\n");
  500. ret = PTR_ERR(states);
  501. goto out_put;
  502. }
  503. /* Acquire the list of interrupt mask vectors */
  504. size = smsm->num_entries * smsm->num_hosts * sizeof(u32);
  505. ret = qcom_smem_alloc(QCOM_SMEM_HOST_ANY, SMEM_SMSM_CPU_INTR_MASK, size);
  506. if (ret < 0 && ret != -EEXIST) {
  507. dev_err(&pdev->dev, "unable to allocate smsm interrupt mask\n");
  508. goto out_put;
  509. }
  510. intr_mask = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_SMSM_CPU_INTR_MASK, NULL);
  511. if (IS_ERR(intr_mask)) {
  512. dev_err(&pdev->dev, "unable to acquire shared memory interrupt mask\n");
  513. ret = PTR_ERR(intr_mask);
  514. goto out_put;
  515. }
  516. /* Setup the reference to the local state bits */
  517. smsm->local_state = states + smsm->local_host;
  518. smsm->subscription = intr_mask + smsm->local_host * smsm->num_hosts;
  519. /* Register the outgoing state */
  520. smsm->state = qcom_smem_state_register(local_node, &smsm_state_ops, smsm);
  521. if (IS_ERR(smsm->state)) {
  522. dev_err(smsm->dev, "failed to register qcom_smem_state\n");
  523. ret = PTR_ERR(smsm->state);
  524. goto out_put;
  525. }
  526. /* Register handlers for remote processor entries of interest. */
  527. for_each_available_child_of_node(pdev->dev.of_node, node) {
  528. if (!of_property_read_bool(node, "interrupt-controller"))
  529. continue;
  530. ret = of_property_read_u32(node, "reg", &id);
  531. if (ret || id >= smsm->num_entries) {
  532. dev_err(&pdev->dev, "invalid reg of entry\n");
  533. if (!ret)
  534. ret = -EINVAL;
  535. goto unwind_interfaces;
  536. }
  537. entry = &smsm->entries[id];
  538. entry->smsm = smsm;
  539. entry->remote_state = states + id;
  540. /* Setup subscription pointers and unsubscribe to any kicks */
  541. entry->subscription = intr_mask + id * smsm->num_hosts;
  542. writel(0, entry->subscription + smsm->local_host);
  543. ret = smsm_inbound_entry(smsm, entry, node);
  544. if (ret < 0)
  545. goto unwind_interfaces;
  546. }
  547. platform_set_drvdata(pdev, smsm);
  548. of_node_put(local_node);
  549. return 0;
  550. unwind_interfaces:
  551. of_node_put(node);
  552. for (id = 0; id < smsm->num_entries; id++)
  553. if (smsm->entries[id].domain)
  554. irq_domain_remove(smsm->entries[id].domain);
  555. qcom_smem_state_unregister(smsm->state);
  556. out_put:
  557. for (id = 0; id < smsm->num_hosts; id++)
  558. mbox_free_channel(smsm->hosts[id].mbox_chan);
  559. of_node_put(local_node);
  560. return ret;
  561. }
  562. static void qcom_smsm_remove(struct platform_device *pdev)
  563. {
  564. struct qcom_smsm *smsm = platform_get_drvdata(pdev);
  565. unsigned id;
  566. for (id = 0; id < smsm->num_entries; id++)
  567. if (smsm->entries[id].domain)
  568. irq_domain_remove(smsm->entries[id].domain);
  569. for (id = 0; id < smsm->num_hosts; id++)
  570. mbox_free_channel(smsm->hosts[id].mbox_chan);
  571. qcom_smem_state_unregister(smsm->state);
  572. }
  573. static const struct of_device_id qcom_smsm_of_match[] = {
  574. { .compatible = "qcom,smsm" },
  575. {}
  576. };
  577. MODULE_DEVICE_TABLE(of, qcom_smsm_of_match);
  578. static struct platform_driver qcom_smsm_driver = {
  579. .probe = qcom_smsm_probe,
  580. .remove = qcom_smsm_remove,
  581. .driver = {
  582. .name = "qcom-smsm",
  583. .of_match_table = qcom_smsm_of_match,
  584. },
  585. };
  586. module_platform_driver(qcom_smsm_driver);
  587. MODULE_DESCRIPTION("Qualcomm Shared Memory State Machine driver");
  588. MODULE_LICENSE("GPL v2");