apr.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2010-2014, 2016-2020 The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/kernel.h>
  6. #include <linux/module.h>
  7. #include <linux/types.h>
  8. #include <linux/uaccess.h>
  9. #include <linux/spinlock.h>
  10. #include <linux/list.h>
  11. #include <linux/sched.h>
  12. #include <linux/wait.h>
  13. #include <linux/errno.h>
  14. #include <linux/fs.h>
  15. #include <linux/delay.h>
  16. #include <linux/debugfs.h>
  17. #include <linux/platform_device.h>
  18. #include <linux/sysfs.h>
  19. #include <linux/device.h>
  20. #include <linux/of.h>
  21. #include <linux/slab.h>
  22. #include <linux/ipc_logging.h>
  23. #include <linux/of_platform.h>
  24. #include <soc/qcom/subsystem_restart.h>
  25. #include <linux/qcom_scm.h>
  26. #include <soc/snd_event.h>
  27. #include <dsp/apr_audio-v2.h>
  28. #include <dsp/audio_notifier.h>
  29. #include <ipc/apr.h>
  30. #include <ipc/apr_tal.h>
  31. #define APR_PKT_IPC_LOG_PAGE_CNT 2
  32. static int apr_pkt_cnt_adsp_restart = 20;
  33. module_param(apr_pkt_cnt_adsp_restart, int, 0664);
  34. MODULE_PARM_DESC(apr_pkt_cnt_adsp_restart, "set apr pktcount for adsp restart feature");
  35. static struct apr_q6 q6;
  36. static struct apr_client client[APR_DEST_MAX][APR_CLIENT_MAX];
  37. static void *apr_pkt_ctx;
  38. static int apr_send_pkt_count;
  39. static wait_queue_head_t modem_wait;
  40. static bool is_modem_up;
  41. static char *subsys_name = NULL;
  42. /* Subsystem restart: QDSP6 data, functions */
  43. static struct workqueue_struct *apr_reset_workqueue;
  44. static void apr_reset_deregister(struct work_struct *work);
  45. static void dispatch_event(unsigned long code, uint16_t proc);
  46. struct apr_reset_work {
  47. void *handle;
  48. struct work_struct work;
  49. };
  50. struct apr_chld_device {
  51. struct platform_device *pdev;
  52. struct list_head node;
  53. };
  54. struct apr_private {
  55. struct device *dev;
  56. spinlock_t apr_lock;
  57. bool is_initial_boot;
  58. struct work_struct add_chld_dev_work;
  59. };
  60. static struct apr_private *apr_priv;
  61. static bool apr_cf_debug;
  62. static struct work_struct apr_cb_work;
  63. static void state_notify_cb(struct work_struct *work);
  64. #ifdef CONFIG_DEBUG_FS
  65. static struct dentry *debugfs_apr_debug;
  66. static ssize_t apr_debug_write(struct file *filp, const char __user *ubuf,
  67. size_t cnt, loff_t *ppos)
  68. {
  69. char cmd;
  70. if (copy_from_user(&cmd, ubuf, 1))
  71. return -EFAULT;
  72. apr_cf_debug = (cmd == '1') ? true : false;
  73. return cnt;
  74. }
  75. static const struct file_operations apr_debug_ops = {
  76. .write = apr_debug_write,
  77. };
  78. #endif
  79. #define APR_PKT_INFO(x...) \
  80. do { \
  81. if (apr_pkt_ctx) \
  82. ipc_log_string(apr_pkt_ctx, "<APR>: "x); \
  83. } while (0)
  84. struct apr_svc_table {
  85. char name[64];
  86. int idx;
  87. int id;
  88. int client_id;
  89. };
  90. static const struct apr_svc_table svc_tbl_qdsp6[] = {
  91. {
  92. .name = "AFE",
  93. .idx = 0,
  94. .id = APR_SVC_AFE,
  95. .client_id = APR_CLIENT_AUDIO,
  96. },
  97. {
  98. .name = "ASM",
  99. .idx = 1,
  100. .id = APR_SVC_ASM,
  101. .client_id = APR_CLIENT_AUDIO,
  102. },
  103. {
  104. .name = "ADM",
  105. .idx = 2,
  106. .id = APR_SVC_ADM,
  107. .client_id = APR_CLIENT_AUDIO,
  108. },
  109. {
  110. .name = "CORE",
  111. .idx = 3,
  112. .id = APR_SVC_ADSP_CORE,
  113. .client_id = APR_CLIENT_AUDIO,
  114. },
  115. {
  116. .name = "TEST",
  117. .idx = 4,
  118. .id = APR_SVC_TEST_CLIENT,
  119. .client_id = APR_CLIENT_AUDIO,
  120. },
  121. {
  122. .name = "MVM",
  123. .idx = 5,
  124. .id = APR_SVC_ADSP_MVM,
  125. .client_id = APR_CLIENT_AUDIO,
  126. },
  127. {
  128. .name = "CVS",
  129. .idx = 6,
  130. .id = APR_SVC_ADSP_CVS,
  131. .client_id = APR_CLIENT_AUDIO,
  132. },
  133. {
  134. .name = "CVP",
  135. .idx = 7,
  136. .id = APR_SVC_ADSP_CVP,
  137. .client_id = APR_CLIENT_AUDIO,
  138. },
  139. {
  140. .name = "USM",
  141. .idx = 8,
  142. .id = APR_SVC_USM,
  143. .client_id = APR_CLIENT_AUDIO,
  144. },
  145. {
  146. .name = "VIDC",
  147. .idx = 9,
  148. .id = APR_SVC_VIDC,
  149. },
  150. {
  151. .name = "LSM",
  152. .idx = 10,
  153. .id = APR_SVC_LSM,
  154. .client_id = APR_CLIENT_AUDIO,
  155. },
  156. };
  157. static struct apr_svc_table svc_tbl_voice[] = {
  158. {
  159. .name = "VSM",
  160. .idx = 0,
  161. .id = APR_SVC_VSM,
  162. .client_id = APR_CLIENT_VOICE,
  163. },
  164. {
  165. .name = "VPM",
  166. .idx = 1,
  167. .id = APR_SVC_VPM,
  168. .client_id = APR_CLIENT_VOICE,
  169. },
  170. {
  171. .name = "MVS",
  172. .idx = 2,
  173. .id = APR_SVC_MVS,
  174. .client_id = APR_CLIENT_VOICE,
  175. },
  176. {
  177. .name = "MVM",
  178. .idx = 3,
  179. .id = APR_SVC_MVM,
  180. .client_id = APR_CLIENT_VOICE,
  181. },
  182. {
  183. .name = "CVS",
  184. .idx = 4,
  185. .id = APR_SVC_CVS,
  186. .client_id = APR_CLIENT_VOICE,
  187. },
  188. {
  189. .name = "CVP",
  190. .idx = 5,
  191. .id = APR_SVC_CVP,
  192. .client_id = APR_CLIENT_VOICE,
  193. },
  194. {
  195. .name = "SRD",
  196. .idx = 6,
  197. .id = APR_SVC_SRD,
  198. .client_id = APR_CLIENT_VOICE,
  199. },
  200. {
  201. .name = "TEST",
  202. .idx = 7,
  203. .id = APR_SVC_TEST_CLIENT,
  204. .client_id = APR_CLIENT_VOICE,
  205. },
  206. };
  207. /**
  208. * apr_get_modem_state:
  209. *
  210. * Returns current modem load status
  211. *
  212. */
  213. enum apr_subsys_state apr_get_modem_state(void)
  214. {
  215. return atomic_read(&q6.modem_state);
  216. }
  217. EXPORT_SYMBOL(apr_get_modem_state);
  218. /**
  219. * apr_set_modem_state - Update modem load status.
  220. *
  221. * @state: State to update modem load status
  222. *
  223. */
  224. void apr_set_modem_state(enum apr_subsys_state state)
  225. {
  226. atomic_set(&q6.modem_state, state);
  227. }
  228. EXPORT_SYMBOL(apr_set_modem_state);
  229. enum apr_subsys_state apr_cmpxchg_modem_state(enum apr_subsys_state prev,
  230. enum apr_subsys_state new)
  231. {
  232. return atomic_cmpxchg(&q6.modem_state, prev, new);
  233. }
  234. static void apr_modem_down(unsigned long opcode)
  235. {
  236. apr_set_modem_state(APR_SUBSYS_DOWN);
  237. dispatch_event(opcode, APR_DEST_MODEM);
  238. }
  239. static void apr_modem_up(void)
  240. {
  241. if (apr_cmpxchg_modem_state(APR_SUBSYS_DOWN, APR_SUBSYS_UP) ==
  242. APR_SUBSYS_DOWN)
  243. wake_up(&modem_wait);
  244. is_modem_up = 1;
  245. }
  246. enum apr_subsys_state apr_get_q6_state(void)
  247. {
  248. return atomic_read(&q6.q6_state);
  249. }
  250. EXPORT_SYMBOL(apr_get_q6_state);
  251. int apr_set_q6_state(enum apr_subsys_state state)
  252. {
  253. pr_debug("%s: setting adsp state %d\n", __func__, state);
  254. if (state < APR_SUBSYS_DOWN || state > APR_SUBSYS_LOADED)
  255. return -EINVAL;
  256. atomic_set(&q6.q6_state, state);
  257. return 0;
  258. }
  259. EXPORT_SYMBOL(apr_set_q6_state);
  260. static void apr_ssr_disable(struct device *dev, void *data)
  261. {
  262. apr_set_q6_state(APR_SUBSYS_DOWN);
  263. }
  264. static const struct snd_event_ops apr_ssr_ops = {
  265. .disable = apr_ssr_disable,
  266. };
  267. static void apr_adsp_down(unsigned long opcode)
  268. {
  269. pr_info("%s: Q6 is Down\n", __func__);
  270. snd_event_notify(apr_priv->dev, SND_EVENT_DOWN);
  271. apr_set_q6_state(APR_SUBSYS_DOWN);
  272. dispatch_event(opcode, APR_DEST_QDSP6);
  273. }
  274. static void apr_add_child_devices(struct work_struct *work)
  275. {
  276. int ret;
  277. ret = of_platform_populate(apr_priv->dev->of_node,
  278. NULL, NULL, apr_priv->dev);
  279. if (ret)
  280. dev_err(apr_priv->dev, "%s: failed to add child nodes, ret=%d\n",
  281. __func__, ret);
  282. }
  283. static void apr_adsp_up(void)
  284. {
  285. pr_info("%s: Q6 is Up\n", __func__);
  286. apr_set_q6_state(APR_SUBSYS_LOADED);
  287. spin_lock(&apr_priv->apr_lock);
  288. if (apr_priv->is_initial_boot)
  289. schedule_work(&apr_priv->add_chld_dev_work);
  290. spin_unlock(&apr_priv->apr_lock);
  291. snd_event_notify(apr_priv->dev, SND_EVENT_UP);
  292. cancel_work_sync(&apr_cb_work);
  293. }
  294. int apr_load_adsp_image(void)
  295. {
  296. int rc = 0;
  297. mutex_lock(&q6.lock);
  298. if (apr_get_q6_state() == APR_SUBSYS_UP) {
  299. q6.pil = subsystem_get("adsp");
  300. if (IS_ERR(q6.pil)) {
  301. rc = PTR_ERR(q6.pil);
  302. pr_err("APR: Unable to load q6 image, error:%d\n", rc);
  303. } else {
  304. apr_set_q6_state(APR_SUBSYS_LOADED);
  305. pr_debug("APR: Image is loaded, stated\n");
  306. }
  307. } else if (apr_get_q6_state() == APR_SUBSYS_LOADED) {
  308. pr_debug("APR: q6 image already loaded\n");
  309. } else {
  310. pr_debug("APR: cannot load state %d\n", apr_get_q6_state());
  311. }
  312. mutex_unlock(&q6.lock);
  313. return rc;
  314. }
  315. struct apr_client *apr_get_client(int dest_id, int client_id)
  316. {
  317. return &client[dest_id][client_id];
  318. }
  319. /**
  320. * apr_send_pkt - Clients call to send packet
  321. * to destination processor.
  322. *
  323. * @handle: APR service handle
  324. * @buf: payload to send to destination processor.
  325. *
  326. * Returns Bytes(>0)pkt_size on success or error on failure.
  327. */
  328. int apr_send_pkt(void *handle, uint32_t *buf)
  329. {
  330. struct apr_svc *svc = handle;
  331. struct apr_client *clnt;
  332. struct apr_hdr *hdr;
  333. uint16_t dest_id;
  334. uint16_t client_id;
  335. uint16_t w_len;
  336. int rc;
  337. unsigned long flags;
  338. if (!handle || !buf) {
  339. pr_err("APR: Wrong parameters for %s\n",
  340. !handle ? "handle" : "buf");
  341. return -EINVAL;
  342. }
  343. if (svc->need_reset) {
  344. pr_err_ratelimited("apr: send_pkt service need reset\n");
  345. return -ENETRESET;
  346. }
  347. if ((svc->dest_id == APR_DEST_QDSP6) &&
  348. (apr_get_q6_state() != APR_SUBSYS_LOADED)) {
  349. pr_err_ratelimited("%s: Still dsp is not Up\n", __func__);
  350. return -ENETRESET;
  351. } else if ((svc->dest_id == APR_DEST_MODEM) &&
  352. (apr_get_modem_state() == APR_SUBSYS_DOWN)) {
  353. pr_err("apr: Still Modem is not Up\n");
  354. return -ENETRESET;
  355. }
  356. spin_lock_irqsave(&svc->w_lock, flags);
  357. dest_id = svc->dest_id;
  358. client_id = svc->client_id;
  359. clnt = &client[dest_id][client_id];
  360. if (!client[dest_id][client_id].handle) {
  361. pr_err_ratelimited("APR: Still service is not yet opened\n");
  362. spin_unlock_irqrestore(&svc->w_lock, flags);
  363. return -EINVAL;
  364. }
  365. hdr = (struct apr_hdr *)buf;
  366. hdr->src_domain = APR_DOMAIN_APPS;
  367. hdr->src_svc = svc->id;
  368. hdr->dest_domain = svc->dest_domain;
  369. hdr->dest_svc = svc->id;
  370. if (unlikely(apr_cf_debug)) {
  371. APR_PKT_INFO(
  372. "Tx: src_addr[0x%X] dest_addr[0x%X] opcode[0x%X] token[0x%X]",
  373. (hdr->src_domain << 8) | hdr->src_svc,
  374. (hdr->dest_domain << 8) | hdr->dest_svc, hdr->opcode,
  375. hdr->token);
  376. }
  377. rc = apr_tal_write(clnt->handle, buf,
  378. (struct apr_pkt_priv *)&svc->pkt_owner,
  379. hdr->pkt_size);
  380. if (rc >= 0) {
  381. w_len = rc;
  382. if (w_len != hdr->pkt_size) {
  383. pr_err("%s: Unable to write whole APR pkt successfully: %d\n",
  384. __func__, rc);
  385. rc = -EINVAL;
  386. }
  387. } else {
  388. pr_err_ratelimited("%s: Write APR pkt failed with error %d\n",
  389. __func__, rc);
  390. if (rc == -ECONNRESET) {
  391. pr_err_ratelimited("%s: Received reset error from tal\n",
  392. __func__);
  393. if (svc->dest_id == APR_DEST_QDSP6)
  394. apr_set_q6_state(APR_SUBSYS_DOWN);
  395. rc = -ENETRESET;
  396. }
  397. if (rc == -EAGAIN || rc == -ETIMEDOUT) {
  398. apr_send_pkt_count++;
  399. pr_err("%s:: send pkt timedout apr_send_pkt_count %d\n",
  400. __func__, apr_send_pkt_count);
  401. }
  402. }
  403. if (apr_send_pkt_count == apr_pkt_cnt_adsp_restart) {
  404. pr_debug("%s:: schedule work for adsp loader restart cb\n",
  405. __func__);
  406. schedule_work(&apr_cb_work);
  407. apr_send_pkt_count = 0;
  408. }
  409. spin_unlock_irqrestore(&svc->w_lock, flags);
  410. return rc;
  411. }
  412. EXPORT_SYMBOL(apr_send_pkt);
  413. int apr_pkt_config(void *handle, struct apr_pkt_cfg *cfg)
  414. {
  415. struct apr_svc *svc = (struct apr_svc *)handle;
  416. uint16_t dest_id;
  417. uint16_t client_id;
  418. struct apr_client *clnt;
  419. if (!handle) {
  420. pr_err("%s: Invalid handle\n", __func__);
  421. return -EINVAL;
  422. }
  423. if (svc->need_reset) {
  424. pr_err("%s: service need reset\n", __func__);
  425. return -ENETRESET;
  426. }
  427. svc->pkt_owner = cfg->pkt_owner;
  428. dest_id = svc->dest_id;
  429. client_id = svc->client_id;
  430. clnt = &client[dest_id][client_id];
  431. return apr_tal_rx_intents_config(clnt->handle,
  432. cfg->intents.num_of_intents, cfg->intents.size);
  433. }
  434. /**
  435. * apr_register - Clients call to register
  436. * to APR.
  437. *
  438. * @dest: destination processor
  439. * @svc_name: name of service to register as
  440. * @svc_fn: callback function to trigger when response
  441. * ack or packets received from destination processor.
  442. * @src_port: Port number within a service
  443. * @priv: private data of client, passed back in cb fn.
  444. *
  445. * Returns apr_svc handle on success or NULL on failure.
  446. */
  447. struct apr_svc *apr_register(char *dest, char *svc_name, apr_fn svc_fn,
  448. uint32_t src_port, void *priv)
  449. {
  450. struct apr_client *clnt;
  451. int client_id = 0;
  452. int svc_idx = 0;
  453. int svc_id = 0;
  454. int dest_id = 0;
  455. int domain_id = 0;
  456. int temp_port = 0;
  457. struct apr_svc *svc = NULL;
  458. int rc = 0;
  459. bool can_open_channel = true;
  460. if (!dest || !svc_name || !svc_fn)
  461. return NULL;
  462. if (!strcmp(dest, "ADSP"))
  463. domain_id = APR_DOMAIN_ADSP;
  464. else if (!strcmp(dest, "MODEM")) {
  465. /* Don't request for SMD channels if destination is MODEM,
  466. * as these channels are no longer used and these clients
  467. * are to listen only for MODEM SSR events
  468. */
  469. can_open_channel = false;
  470. domain_id = APR_DOMAIN_MODEM;
  471. } else {
  472. pr_err("APR: wrong destination\n");
  473. goto done;
  474. }
  475. dest_id = apr_get_dest_id(dest);
  476. if (dest_id == APR_DEST_QDSP6) {
  477. if (apr_get_q6_state() != APR_SUBSYS_LOADED) {
  478. pr_err_ratelimited("%s: adsp not up\n", __func__);
  479. return NULL;
  480. }
  481. pr_debug("%s: adsp Up\n", __func__);
  482. } else if (dest_id == APR_DEST_MODEM) {
  483. if (apr_get_modem_state() == APR_SUBSYS_DOWN) {
  484. if (is_modem_up) {
  485. pr_err("%s: modem shutdown due to SSR, ret",
  486. __func__);
  487. return NULL;
  488. }
  489. pr_debug("%s: Wait for modem to bootup\n", __func__);
  490. rc = wait_event_interruptible_timeout(modem_wait,
  491. (apr_get_modem_state() == APR_SUBSYS_UP),
  492. (1 * HZ));
  493. if (rc == 0) {
  494. pr_err("%s: Modem is not Up\n", __func__);
  495. return NULL;
  496. }
  497. }
  498. pr_debug("%s: modem Up\n", __func__);
  499. }
  500. if (apr_get_svc(svc_name, domain_id, &client_id, &svc_idx, &svc_id)) {
  501. pr_err_ratelimited("%s: apr_get_svc failed\n", __func__);
  502. goto done;
  503. }
  504. clnt = &client[dest_id][client_id];
  505. mutex_lock(&clnt->m_lock);
  506. if (!clnt->handle && can_open_channel) {
  507. clnt->handle = apr_tal_open(client_id, dest_id,
  508. APR_DL_SMD, apr_cb_func, NULL);
  509. if (!clnt->handle) {
  510. svc = NULL;
  511. pr_err_ratelimited("APR: Unable to open handle\n");
  512. mutex_unlock(&clnt->m_lock);
  513. goto done;
  514. }
  515. }
  516. mutex_unlock(&clnt->m_lock);
  517. svc = &clnt->svc[svc_idx];
  518. mutex_lock(&svc->m_lock);
  519. clnt->id = client_id;
  520. if (svc->need_reset) {
  521. mutex_unlock(&svc->m_lock);
  522. pr_err_ratelimited("APR: Service needs reset\n");
  523. svc = NULL;
  524. goto done;
  525. }
  526. svc->id = svc_id;
  527. svc->dest_id = dest_id;
  528. svc->client_id = client_id;
  529. svc->dest_domain = domain_id;
  530. svc->pkt_owner = APR_PKT_OWNER_DRIVER;
  531. if (src_port != 0xFFFFFFFF) {
  532. temp_port = ((src_port >> 8) * 8) + (src_port & 0xFF);
  533. pr_debug("port = %d t_port = %d\n", src_port, temp_port);
  534. if (temp_port >= APR_MAX_PORTS || temp_port < 0) {
  535. pr_err("APR: temp_port out of bounds\n");
  536. mutex_unlock(&svc->m_lock);
  537. return NULL;
  538. }
  539. if (!svc->svc_cnt)
  540. clnt->svc_cnt++;
  541. svc->port_cnt++;
  542. svc->port_fn[temp_port] = svc_fn;
  543. svc->port_priv[temp_port] = priv;
  544. svc->svc_cnt++;
  545. } else {
  546. if (!svc->fn) {
  547. if (!svc->svc_cnt)
  548. clnt->svc_cnt++;
  549. svc->fn = svc_fn;
  550. svc->priv = priv;
  551. svc->svc_cnt++;
  552. }
  553. }
  554. mutex_unlock(&svc->m_lock);
  555. done:
  556. return svc;
  557. }
  558. EXPORT_SYMBOL(apr_register);
  559. void apr_cb_func(void *buf, int len, void *priv)
  560. {
  561. struct apr_client_data data;
  562. struct apr_client *apr_client;
  563. struct apr_svc *c_svc;
  564. struct apr_hdr *hdr;
  565. uint16_t hdr_size;
  566. uint16_t msg_type;
  567. uint16_t ver;
  568. uint16_t src;
  569. uint16_t svc;
  570. uint16_t clnt;
  571. int i;
  572. int temp_port = 0;
  573. uint32_t *ptr;
  574. pr_debug("APR2: len = %d\n", len);
  575. ptr = buf;
  576. pr_debug("\n*****************\n");
  577. for (i = 0; i < len/4; i++)
  578. pr_debug("%x ", ptr[i]);
  579. pr_debug("\n");
  580. pr_debug("\n*****************\n");
  581. if (!buf || len <= APR_HDR_SIZE) {
  582. pr_err("APR: Improper apr pkt received:%pK %d\n", buf, len);
  583. return;
  584. }
  585. hdr = buf;
  586. ver = hdr->hdr_field;
  587. ver = (ver & 0x000F);
  588. if (ver > APR_PKT_VER + 1) {
  589. pr_err("APR: Wrong version: %d\n", ver);
  590. return;
  591. }
  592. hdr_size = hdr->hdr_field;
  593. hdr_size = ((hdr_size & 0x00F0) >> 0x4) * 4;
  594. if (hdr_size < APR_HDR_SIZE) {
  595. pr_err("APR: Wrong hdr size:%d\n", hdr_size);
  596. return;
  597. }
  598. if (hdr->pkt_size < APR_HDR_SIZE) {
  599. pr_err("APR: Wrong paket size\n");
  600. return;
  601. }
  602. if (hdr->pkt_size < hdr_size) {
  603. pr_err("APR: Packet size less than header size\n");
  604. return;
  605. }
  606. msg_type = hdr->hdr_field;
  607. msg_type = (msg_type >> 0x08) & 0x0003;
  608. if (msg_type >= APR_MSG_TYPE_MAX && msg_type != APR_BASIC_RSP_RESULT) {
  609. pr_err("APR: Wrong message type: %d\n", msg_type);
  610. return;
  611. }
  612. if (hdr->src_domain >= APR_DOMAIN_MAX ||
  613. hdr->dest_domain >= APR_DOMAIN_MAX ||
  614. hdr->src_svc >= APR_SVC_MAX ||
  615. hdr->dest_svc >= APR_SVC_MAX) {
  616. pr_err("APR: Wrong APR header\n");
  617. return;
  618. }
  619. svc = hdr->dest_svc;
  620. if (hdr->src_domain == APR_DOMAIN_MODEM) {
  621. if (svc == APR_SVC_MVS || svc == APR_SVC_MVM ||
  622. svc == APR_SVC_CVS || svc == APR_SVC_CVP ||
  623. svc == APR_SVC_TEST_CLIENT)
  624. clnt = APR_CLIENT_VOICE;
  625. else {
  626. pr_err("APR: Wrong svc :%d\n", svc);
  627. return;
  628. }
  629. } else if (hdr->src_domain == APR_DOMAIN_ADSP) {
  630. if (svc == APR_SVC_AFE || svc == APR_SVC_ASM ||
  631. svc == APR_SVC_VSM || svc == APR_SVC_VPM ||
  632. svc == APR_SVC_ADM || svc == APR_SVC_ADSP_CORE ||
  633. svc == APR_SVC_USM ||
  634. svc == APR_SVC_TEST_CLIENT || svc == APR_SVC_ADSP_MVM ||
  635. svc == APR_SVC_ADSP_CVS || svc == APR_SVC_ADSP_CVP ||
  636. svc == APR_SVC_LSM)
  637. clnt = APR_CLIENT_AUDIO;
  638. else if (svc == APR_SVC_VIDC)
  639. clnt = APR_CLIENT_AUDIO;
  640. else {
  641. pr_err("APR: Wrong svc :%d\n", svc);
  642. return;
  643. }
  644. } else {
  645. pr_err("APR: Pkt from wrong source: %d\n", hdr->src_domain);
  646. return;
  647. }
  648. src = apr_get_data_src(hdr);
  649. if (src == APR_DEST_MAX)
  650. return;
  651. pr_debug("src =%d clnt = %d\n", src, clnt);
  652. apr_client = &client[src][clnt];
  653. for (i = 0; i < APR_SVC_MAX; i++)
  654. if (apr_client->svc[i].id == svc) {
  655. pr_debug("%d\n", apr_client->svc[i].id);
  656. c_svc = &apr_client->svc[i];
  657. break;
  658. }
  659. if (i == APR_SVC_MAX) {
  660. pr_err("APR: service is not registered\n");
  661. return;
  662. }
  663. pr_debug("svc_idx = %d\n", i);
  664. pr_debug("%x %x %x %pK %pK\n", c_svc->id, c_svc->dest_id,
  665. c_svc->client_id, c_svc->fn, c_svc->priv);
  666. data.payload_size = hdr->pkt_size - hdr_size;
  667. data.opcode = hdr->opcode;
  668. data.src = src;
  669. data.src_port = hdr->src_port;
  670. data.dest_port = hdr->dest_port;
  671. data.token = hdr->token;
  672. data.msg_type = msg_type;
  673. data.payload = NULL;
  674. if (data.payload_size > 0)
  675. data.payload = (char *)hdr + hdr_size;
  676. if (unlikely(apr_cf_debug)) {
  677. if (hdr->opcode == APR_BASIC_RSP_RESULT && data.payload) {
  678. uint32_t *ptr = data.payload;
  679. APR_PKT_INFO(
  680. "Rx: src_addr[0x%X] dest_addr[0x%X] opcode[0x%X] token[0x%X] rc[0x%X]",
  681. (hdr->src_domain << 8) | hdr->src_svc,
  682. (hdr->dest_domain << 8) | hdr->dest_svc,
  683. hdr->opcode, hdr->token, ptr[1]);
  684. } else {
  685. APR_PKT_INFO(
  686. "Rx: src_addr[0x%X] dest_addr[0x%X] opcode[0x%X] token[0x%X]",
  687. (hdr->src_domain << 8) | hdr->src_svc,
  688. (hdr->dest_domain << 8) | hdr->dest_svc, hdr->opcode,
  689. hdr->token);
  690. }
  691. }
  692. temp_port = ((data.dest_port >> 8) * 8) + (data.dest_port & 0xFF);
  693. if (((temp_port >= 0) && (temp_port < APR_MAX_PORTS))
  694. && (c_svc->port_cnt && c_svc->port_fn[temp_port]))
  695. c_svc->port_fn[temp_port](&data,
  696. c_svc->port_priv[temp_port]);
  697. else if (c_svc->fn)
  698. c_svc->fn(&data, c_svc->priv);
  699. else
  700. pr_err("APR: Rxed a packet for NULL callback\n");
  701. }
  702. int apr_get_svc(const char *svc_name, int domain_id, int *client_id,
  703. int *svc_idx, int *svc_id)
  704. {
  705. int i;
  706. int size;
  707. struct apr_svc_table *tbl;
  708. int ret = 0;
  709. if (domain_id == APR_DOMAIN_ADSP) {
  710. tbl = (struct apr_svc_table *)&svc_tbl_qdsp6;
  711. size = ARRAY_SIZE(svc_tbl_qdsp6);
  712. } else {
  713. tbl = (struct apr_svc_table *)&svc_tbl_voice;
  714. size = ARRAY_SIZE(svc_tbl_voice);
  715. }
  716. for (i = 0; i < size; i++) {
  717. if (!strcmp(svc_name, tbl[i].name)) {
  718. *client_id = tbl[i].client_id;
  719. *svc_idx = tbl[i].idx;
  720. *svc_id = tbl[i].id;
  721. break;
  722. }
  723. }
  724. pr_debug("%s: svc_name = %s c_id = %d domain_id = %d\n",
  725. __func__, svc_name, *client_id, domain_id);
  726. if (i == size) {
  727. pr_err("%s: APR: Wrong svc name %s\n", __func__, svc_name);
  728. ret = -EINVAL;
  729. }
  730. return ret;
  731. }
  732. static void apr_reset_deregister(struct work_struct *work)
  733. {
  734. struct apr_svc *handle = NULL;
  735. struct apr_reset_work *apr_reset =
  736. container_of(work, struct apr_reset_work, work);
  737. handle = apr_reset->handle;
  738. pr_debug("%s:handle[%pK]\n", __func__, handle);
  739. apr_deregister(handle);
  740. kfree(apr_reset);
  741. }
  742. static void state_notify_cb(struct work_struct *work)
  743. {
  744. if (q6.state_notify_cb)
  745. q6.state_notify_cb(APR_SUBSYS_UNKNOWN, q6.client_handle);
  746. }
  747. void apr_register_adsp_state_cb(void *adsp_cb, void *client_handle)
  748. {
  749. q6.state_notify_cb = adsp_cb;
  750. q6.client_handle = client_handle;
  751. }
  752. EXPORT_SYMBOL(apr_register_adsp_state_cb);
  753. /**
  754. * apr_start_rx_rt - Clients call to vote for thread
  755. * priority upgrade whenever needed.
  756. *
  757. * @handle: APR service handle
  758. *
  759. * Returns 0 on success or error otherwise.
  760. */
  761. int apr_start_rx_rt(void *handle)
  762. {
  763. int rc = 0;
  764. struct apr_svc *svc = handle;
  765. uint16_t dest_id = 0;
  766. uint16_t client_id = 0;
  767. if (!svc) {
  768. pr_err("%s: Invalid APR handle\n", __func__);
  769. return -EINVAL;
  770. }
  771. mutex_lock(&svc->m_lock);
  772. dest_id = svc->dest_id;
  773. client_id = svc->client_id;
  774. if ((client_id >= APR_CLIENT_MAX) || (dest_id >= APR_DEST_MAX)) {
  775. pr_err("%s: %s invalid. client_id = %u, dest_id = %u\n",
  776. __func__,
  777. client_id >= APR_CLIENT_MAX ? "Client ID" : "Dest ID",
  778. client_id, dest_id);
  779. rc = -EINVAL;
  780. goto exit;
  781. }
  782. if (!client[dest_id][client_id].handle) {
  783. pr_err("%s: Client handle is NULL\n", __func__);
  784. rc = -EINVAL;
  785. goto exit;
  786. }
  787. rc = apr_tal_start_rx_rt(client[dest_id][client_id].handle);
  788. if (rc)
  789. pr_err("%s: failed to set RT thread priority for APR RX. rc = %d\n",
  790. __func__, rc);
  791. exit:
  792. mutex_unlock(&svc->m_lock);
  793. return rc;
  794. }
  795. EXPORT_SYMBOL(apr_start_rx_rt);
  796. /**
  797. * apr_end_rx_rt - Clients call to unvote for thread
  798. * priority upgrade (perviously voted with
  799. * apr_start_rx_rt()).
  800. *
  801. * @handle: APR service handle
  802. *
  803. * Returns 0 on success or error otherwise.
  804. */
  805. int apr_end_rx_rt(void *handle)
  806. {
  807. int rc = 0;
  808. struct apr_svc *svc = handle;
  809. uint16_t dest_id = 0;
  810. uint16_t client_id = 0;
  811. if (!svc) {
  812. pr_err("%s: Invalid APR handle\n", __func__);
  813. return -EINVAL;
  814. }
  815. mutex_lock(&svc->m_lock);
  816. dest_id = svc->dest_id;
  817. client_id = svc->client_id;
  818. if ((client_id >= APR_CLIENT_MAX) || (dest_id >= APR_DEST_MAX)) {
  819. pr_err("%s: %s invalid. client_id = %u, dest_id = %u\n",
  820. __func__,
  821. client_id >= APR_CLIENT_MAX ? "Client ID" : "Dest ID",
  822. client_id, dest_id);
  823. rc = -EINVAL;
  824. goto exit;
  825. }
  826. if (!client[dest_id][client_id].handle) {
  827. pr_err("%s: Client handle is NULL\n", __func__);
  828. rc = -EINVAL;
  829. goto exit;
  830. }
  831. rc = apr_tal_end_rx_rt(client[dest_id][client_id].handle);
  832. if (rc)
  833. pr_err("%s: failed to reset RT thread priority for APR RX. rc = %d\n",
  834. __func__, rc);
  835. exit:
  836. mutex_unlock(&svc->m_lock);
  837. return rc;
  838. }
  839. EXPORT_SYMBOL(apr_end_rx_rt);
  840. /**
  841. * apr_deregister - Clients call to de-register
  842. * from APR.
  843. *
  844. * @handle: APR service handle to de-register
  845. *
  846. * Returns 0 on success or -EINVAL on error.
  847. */
  848. int apr_deregister(void *handle)
  849. {
  850. struct apr_svc *svc = handle;
  851. struct apr_client *clnt;
  852. uint16_t dest_id;
  853. uint16_t client_id;
  854. if (!handle)
  855. return -EINVAL;
  856. mutex_lock(&svc->m_lock);
  857. if (!svc->svc_cnt) {
  858. pr_err("%s: svc already deregistered. svc = %pK\n",
  859. __func__, svc);
  860. mutex_unlock(&svc->m_lock);
  861. return -EINVAL;
  862. }
  863. dest_id = svc->dest_id;
  864. client_id = svc->client_id;
  865. clnt = &client[dest_id][client_id];
  866. if (svc->svc_cnt > 0) {
  867. if (svc->port_cnt)
  868. svc->port_cnt--;
  869. svc->svc_cnt--;
  870. if (!svc->svc_cnt) {
  871. client[dest_id][client_id].svc_cnt--;
  872. pr_debug("%s: service is reset %pK\n", __func__, svc);
  873. }
  874. }
  875. if (!svc->svc_cnt) {
  876. svc->priv = NULL;
  877. svc->id = 0;
  878. svc->fn = NULL;
  879. svc->dest_id = 0;
  880. svc->client_id = 0;
  881. svc->need_reset = 0x0;
  882. }
  883. if (client[dest_id][client_id].handle &&
  884. !client[dest_id][client_id].svc_cnt) {
  885. apr_tal_close(client[dest_id][client_id].handle);
  886. client[dest_id][client_id].handle = NULL;
  887. }
  888. mutex_unlock(&svc->m_lock);
  889. return 0;
  890. }
  891. EXPORT_SYMBOL(apr_deregister);
  892. /**
  893. * apr_reset - sets up workqueue to de-register
  894. * the given APR service handle.
  895. *
  896. * @handle: APR service handle
  897. *
  898. */
  899. void apr_reset(void *handle)
  900. {
  901. struct apr_reset_work *apr_reset_worker = NULL;
  902. if (!handle)
  903. return;
  904. pr_debug("%s: handle[%pK]\n", __func__, handle);
  905. if (apr_reset_workqueue == NULL) {
  906. pr_err("%s: apr_reset_workqueue is NULL\n", __func__);
  907. return;
  908. }
  909. apr_reset_worker = kzalloc(sizeof(struct apr_reset_work),
  910. GFP_ATOMIC);
  911. if (apr_reset_worker == NULL) {
  912. pr_err("%s: mem failure\n", __func__);
  913. return;
  914. }
  915. apr_reset_worker->handle = handle;
  916. INIT_WORK(&apr_reset_worker->work, apr_reset_deregister);
  917. queue_work(apr_reset_workqueue, &apr_reset_worker->work);
  918. }
  919. EXPORT_SYMBOL(apr_reset);
  920. /* Dispatch the Reset events to Modem and audio clients */
  921. static void dispatch_event(unsigned long code, uint16_t proc)
  922. {
  923. struct apr_client *apr_client;
  924. struct apr_client_data data;
  925. struct apr_svc *svc;
  926. uint16_t clnt;
  927. int i, j;
  928. memset(&data, 0, sizeof(data));
  929. data.opcode = RESET_EVENTS;
  930. data.reset_event = code;
  931. /* Service domain can be different from the processor */
  932. data.reset_proc = apr_get_reset_domain(proc);
  933. clnt = APR_CLIENT_AUDIO;
  934. apr_client = &client[proc][clnt];
  935. for (i = 0; i < APR_SVC_MAX; i++) {
  936. mutex_lock(&apr_client->svc[i].m_lock);
  937. if (apr_client->svc[i].fn) {
  938. apr_client->svc[i].need_reset = 0x1;
  939. apr_client->svc[i].fn(&data, apr_client->svc[i].priv);
  940. }
  941. if (apr_client->svc[i].port_cnt) {
  942. svc = &(apr_client->svc[i]);
  943. svc->need_reset = 0x1;
  944. for (j = 0; j < APR_MAX_PORTS; j++)
  945. if (svc->port_fn[j])
  946. svc->port_fn[j](&data,
  947. svc->port_priv[j]);
  948. }
  949. mutex_unlock(&apr_client->svc[i].m_lock);
  950. }
  951. clnt = APR_CLIENT_VOICE;
  952. apr_client = &client[proc][clnt];
  953. for (i = 0; i < APR_SVC_MAX; i++) {
  954. mutex_lock(&apr_client->svc[i].m_lock);
  955. if (apr_client->svc[i].fn) {
  956. apr_client->svc[i].need_reset = 0x1;
  957. apr_client->svc[i].fn(&data, apr_client->svc[i].priv);
  958. }
  959. if (apr_client->svc[i].port_cnt) {
  960. svc = &(apr_client->svc[i]);
  961. svc->need_reset = 0x1;
  962. for (j = 0; j < APR_MAX_PORTS; j++)
  963. if (svc->port_fn[j])
  964. svc->port_fn[j](&data,
  965. svc->port_priv[j]);
  966. }
  967. mutex_unlock(&apr_client->svc[i].m_lock);
  968. }
  969. }
  970. static int apr_notifier_service_cb(struct notifier_block *this,
  971. unsigned long opcode, void *data)
  972. {
  973. struct audio_notifier_cb_data *cb_data = data;
  974. if (cb_data == NULL) {
  975. pr_err("%s: Callback data is NULL!\n", __func__);
  976. goto done;
  977. }
  978. pr_debug("%s: Service opcode 0x%lx, domain %d\n",
  979. __func__, opcode, cb_data->domain);
  980. switch (opcode) {
  981. case AUDIO_NOTIFIER_SERVICE_DOWN:
  982. /*
  983. * Use flag to ignore down notifications during
  984. * initial boot. There is no benefit from error
  985. * recovery notifications during initial boot
  986. * up since everything is expected to be down.
  987. */
  988. spin_lock(&apr_priv->apr_lock);
  989. if (apr_priv->is_initial_boot) {
  990. spin_unlock(&apr_priv->apr_lock);
  991. break;
  992. }
  993. spin_unlock(&apr_priv->apr_lock);
  994. if (cb_data->domain == AUDIO_NOTIFIER_MODEM_DOMAIN)
  995. apr_modem_down(opcode);
  996. else
  997. apr_adsp_down(opcode);
  998. break;
  999. case AUDIO_NOTIFIER_SERVICE_UP:
  1000. if (cb_data->domain == AUDIO_NOTIFIER_MODEM_DOMAIN)
  1001. apr_modem_up();
  1002. else
  1003. apr_adsp_up();
  1004. spin_lock(&apr_priv->apr_lock);
  1005. apr_priv->is_initial_boot = false;
  1006. spin_unlock(&apr_priv->apr_lock);
  1007. break;
  1008. default:
  1009. break;
  1010. }
  1011. done:
  1012. return NOTIFY_OK;
  1013. }
  1014. static struct notifier_block adsp_service_nb = {
  1015. .notifier_call = apr_notifier_service_cb,
  1016. .priority = 0,
  1017. };
  1018. static struct notifier_block modem_service_nb = {
  1019. .notifier_call = apr_notifier_service_cb,
  1020. .priority = 0,
  1021. };
  1022. #ifdef CONFIG_DEBUG_FS
  1023. static int __init apr_debug_init(void)
  1024. {
  1025. debugfs_apr_debug = debugfs_create_file("msm_apr_debug",
  1026. S_IFREG | 0444, NULL, NULL,
  1027. &apr_debug_ops);
  1028. return 0;
  1029. }
  1030. #else
  1031. static int __init apr_debug_init(void)
  1032. {
  1033. return 0;
  1034. }
  1035. #endif
  1036. static void apr_cleanup(void)
  1037. {
  1038. int i, j, k;
  1039. of_platform_depopulate(apr_priv->dev);
  1040. subsys_notif_deregister(subsys_name);
  1041. if (apr_reset_workqueue) {
  1042. flush_workqueue(apr_reset_workqueue);
  1043. destroy_workqueue(apr_reset_workqueue);
  1044. }
  1045. mutex_destroy(&q6.lock);
  1046. for (i = 0; i < APR_DEST_MAX; i++) {
  1047. for (j = 0; j < APR_CLIENT_MAX; j++) {
  1048. mutex_destroy(&client[i][j].m_lock);
  1049. for (k = 0; k < APR_SVC_MAX; k++)
  1050. mutex_destroy(&client[i][j].svc[k].m_lock);
  1051. }
  1052. }
  1053. #ifdef CONFIG_DEBUG_FS
  1054. debugfs_remove(debugfs_apr_debug);
  1055. #endif
  1056. }
  1057. static int apr_probe(struct platform_device *pdev)
  1058. {
  1059. int i, j, k, ret = 0;
  1060. init_waitqueue_head(&modem_wait);
  1061. apr_priv = devm_kzalloc(&pdev->dev, sizeof(*apr_priv), GFP_KERNEL);
  1062. if (!apr_priv)
  1063. return -ENOMEM;
  1064. apr_priv->dev = &pdev->dev;
  1065. spin_lock_init(&apr_priv->apr_lock);
  1066. INIT_WORK(&apr_priv->add_chld_dev_work, apr_add_child_devices);
  1067. for (i = 0; i < APR_DEST_MAX; i++)
  1068. for (j = 0; j < APR_CLIENT_MAX; j++) {
  1069. mutex_init(&client[i][j].m_lock);
  1070. for (k = 0; k < APR_SVC_MAX; k++) {
  1071. mutex_init(&client[i][j].svc[k].m_lock);
  1072. spin_lock_init(&client[i][j].svc[k].w_lock);
  1073. }
  1074. }
  1075. apr_set_subsys_state();
  1076. mutex_init(&q6.lock);
  1077. apr_reset_workqueue = create_singlethread_workqueue("apr_driver");
  1078. if (!apr_reset_workqueue) {
  1079. apr_priv = NULL;
  1080. return -ENOMEM;
  1081. }
  1082. apr_pkt_ctx = ipc_log_context_create(APR_PKT_IPC_LOG_PAGE_CNT,
  1083. "apr", 0);
  1084. if (!apr_pkt_ctx)
  1085. pr_err("%s: Unable to create ipc log context\n", __func__);
  1086. spin_lock(&apr_priv->apr_lock);
  1087. apr_priv->is_initial_boot = true;
  1088. spin_unlock(&apr_priv->apr_lock);
  1089. ret = of_property_read_string(pdev->dev.of_node,
  1090. "qcom,subsys-name",
  1091. (const char **)(&subsys_name));
  1092. if (ret) {
  1093. pr_err("%s: missing subsys-name entry in dt node\n", __func__);
  1094. return -EINVAL;
  1095. }
  1096. if (!strcmp(subsys_name, "apr_adsp")) {
  1097. subsys_notif_register("apr_adsp",
  1098. AUDIO_NOTIFIER_ADSP_DOMAIN,
  1099. &adsp_service_nb);
  1100. } else if (!strcmp(subsys_name, "apr_modem")) {
  1101. subsys_notif_register("apr_modem",
  1102. AUDIO_NOTIFIER_MODEM_DOMAIN,
  1103. &modem_service_nb);
  1104. } else {
  1105. pr_err("%s: invalid subsys-name %s\n", __func__, subsys_name);
  1106. return -EINVAL;
  1107. }
  1108. apr_tal_init();
  1109. ret = snd_event_client_register(&pdev->dev, &apr_ssr_ops, NULL);
  1110. if (ret) {
  1111. pr_err("%s: Registration with SND event fwk failed ret = %d\n",
  1112. __func__, ret);
  1113. ret = 0;
  1114. }
  1115. INIT_WORK(&apr_cb_work, state_notify_cb);
  1116. return apr_debug_init();
  1117. }
  1118. static int apr_remove(struct platform_device *pdev)
  1119. {
  1120. snd_event_client_deregister(&pdev->dev);
  1121. apr_cleanup();
  1122. apr_tal_exit();
  1123. apr_priv = NULL;
  1124. return 0;
  1125. }
  1126. static const struct of_device_id apr_machine_of_match[] = {
  1127. { .compatible = "qcom,msm-audio-apr", },
  1128. {},
  1129. };
  1130. static struct platform_driver apr_driver = {
  1131. .probe = apr_probe,
  1132. .remove = apr_remove,
  1133. .driver = {
  1134. .name = "audio_apr",
  1135. .owner = THIS_MODULE,
  1136. .of_match_table = apr_machine_of_match,
  1137. .suppress_bind_attrs = true,
  1138. }
  1139. };
  1140. module_platform_driver(apr_driver);
  1141. MODULE_DESCRIPTION("APR DRIVER");
  1142. MODULE_LICENSE("GPL v2");
  1143. MODULE_DEVICE_TABLE(of, apr_machine_of_match);