snoc.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396
  1. /*
  2. * Copyright (c) 2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/clk.h>
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/of.h>
  20. #include <linux/of_device.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/regulator/consumer.h>
  23. #include "ce.h"
  24. #include "debug.h"
  25. #include "hif.h"
  26. #include "htc.h"
  27. #include "snoc.h"
  28. #define ATH10K_SNOC_RX_POST_RETRY_MS 50
  29. #define CE_POLL_PIPE 4
  30. static char *const ce_name[] = {
  31. "WLAN_CE_0",
  32. "WLAN_CE_1",
  33. "WLAN_CE_2",
  34. "WLAN_CE_3",
  35. "WLAN_CE_4",
  36. "WLAN_CE_5",
  37. "WLAN_CE_6",
  38. "WLAN_CE_7",
  39. "WLAN_CE_8",
  40. "WLAN_CE_9",
  41. "WLAN_CE_10",
  42. "WLAN_CE_11",
  43. };
  44. static struct ath10k_wcn3990_vreg_info vreg_cfg[] = {
  45. {NULL, "vdd-0.8-cx-mx", 800000, 800000, 0, 0, false},
  46. {NULL, "vdd-1.8-xo", 1800000, 1800000, 0, 0, false},
  47. {NULL, "vdd-1.3-rfa", 1304000, 1304000, 0, 0, false},
  48. {NULL, "vdd-3.3-ch0", 3312000, 3312000, 0, 0, false},
  49. };
  50. static struct ath10k_wcn3990_clk_info clk_cfg[] = {
  51. {NULL, "cxo_ref_clk_pin", 0, false},
  52. };
  53. static void ath10k_snoc_htc_tx_cb(struct ath10k_ce_pipe *ce_state);
  54. static void ath10k_snoc_htt_tx_cb(struct ath10k_ce_pipe *ce_state);
  55. static void ath10k_snoc_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
  56. static void ath10k_snoc_htt_rx_cb(struct ath10k_ce_pipe *ce_state);
  57. static void ath10k_snoc_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
  58. static const struct ath10k_snoc_drv_priv drv_priv = {
  59. .hw_rev = ATH10K_HW_WCN3990,
  60. .dma_mask = DMA_BIT_MASK(37),
  61. };
  62. static struct ce_attr host_ce_config_wlan[] = {
  63. /* CE0: host->target HTC control streams */
  64. {
  65. .flags = CE_ATTR_FLAGS,
  66. .src_nentries = 16,
  67. .src_sz_max = 2048,
  68. .dest_nentries = 0,
  69. .send_cb = ath10k_snoc_htc_tx_cb,
  70. },
  71. /* CE1: target->host HTT + HTC control */
  72. {
  73. .flags = CE_ATTR_FLAGS,
  74. .src_nentries = 0,
  75. .src_sz_max = 2048,
  76. .dest_nentries = 512,
  77. .recv_cb = ath10k_snoc_htt_htc_rx_cb,
  78. },
  79. /* CE2: target->host WMI */
  80. {
  81. .flags = CE_ATTR_FLAGS,
  82. .src_nentries = 0,
  83. .src_sz_max = 2048,
  84. .dest_nentries = 64,
  85. .recv_cb = ath10k_snoc_htc_rx_cb,
  86. },
  87. /* CE3: host->target WMI */
  88. {
  89. .flags = CE_ATTR_FLAGS,
  90. .src_nentries = 32,
  91. .src_sz_max = 2048,
  92. .dest_nentries = 0,
  93. .send_cb = ath10k_snoc_htc_tx_cb,
  94. },
  95. /* CE4: host->target HTT */
  96. {
  97. .flags = CE_ATTR_FLAGS | CE_ATTR_DIS_INTR,
  98. .src_nentries = 256,
  99. .src_sz_max = 256,
  100. .dest_nentries = 0,
  101. .send_cb = ath10k_snoc_htt_tx_cb,
  102. },
  103. /* CE5: target->host HTT (ipa_uc->target ) */
  104. {
  105. .flags = CE_ATTR_FLAGS,
  106. .src_nentries = 0,
  107. .src_sz_max = 512,
  108. .dest_nentries = 512,
  109. .recv_cb = ath10k_snoc_htt_rx_cb,
  110. },
  111. /* CE6: target autonomous hif_memcpy */
  112. {
  113. .flags = CE_ATTR_FLAGS,
  114. .src_nentries = 0,
  115. .src_sz_max = 0,
  116. .dest_nentries = 0,
  117. },
  118. /* CE7: ce_diag, the Diagnostic Window */
  119. {
  120. .flags = CE_ATTR_FLAGS,
  121. .src_nentries = 2,
  122. .src_sz_max = 2048,
  123. .dest_nentries = 2,
  124. },
  125. /* CE8: Target to uMC */
  126. {
  127. .flags = CE_ATTR_FLAGS,
  128. .src_nentries = 0,
  129. .src_sz_max = 2048,
  130. .dest_nentries = 128,
  131. },
  132. /* CE9 target->host HTT */
  133. {
  134. .flags = CE_ATTR_FLAGS,
  135. .src_nentries = 0,
  136. .src_sz_max = 2048,
  137. .dest_nentries = 512,
  138. .recv_cb = ath10k_snoc_htt_htc_rx_cb,
  139. },
  140. /* CE10: target->host HTT */
  141. {
  142. .flags = CE_ATTR_FLAGS,
  143. .src_nentries = 0,
  144. .src_sz_max = 2048,
  145. .dest_nentries = 512,
  146. .recv_cb = ath10k_snoc_htt_htc_rx_cb,
  147. },
  148. /* CE11: target -> host PKTLOG */
  149. {
  150. .flags = CE_ATTR_FLAGS,
  151. .src_nentries = 0,
  152. .src_sz_max = 2048,
  153. .dest_nentries = 512,
  154. .recv_cb = ath10k_snoc_htt_htc_rx_cb,
  155. },
  156. };
  157. static struct service_to_pipe target_service_to_ce_map_wlan[] = {
  158. {
  159. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
  160. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  161. __cpu_to_le32(3),
  162. },
  163. {
  164. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
  165. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  166. __cpu_to_le32(2),
  167. },
  168. {
  169. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
  170. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  171. __cpu_to_le32(3),
  172. },
  173. {
  174. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
  175. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  176. __cpu_to_le32(2),
  177. },
  178. {
  179. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
  180. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  181. __cpu_to_le32(3),
  182. },
  183. {
  184. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
  185. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  186. __cpu_to_le32(2),
  187. },
  188. {
  189. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
  190. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  191. __cpu_to_le32(3),
  192. },
  193. {
  194. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
  195. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  196. __cpu_to_le32(2),
  197. },
  198. {
  199. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
  200. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  201. __cpu_to_le32(3),
  202. },
  203. {
  204. __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
  205. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  206. __cpu_to_le32(2),
  207. },
  208. {
  209. __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
  210. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  211. __cpu_to_le32(0),
  212. },
  213. {
  214. __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
  215. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  216. __cpu_to_le32(2),
  217. },
  218. { /* not used */
  219. __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
  220. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  221. __cpu_to_le32(0),
  222. },
  223. { /* not used */
  224. __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
  225. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  226. __cpu_to_le32(2),
  227. },
  228. {
  229. __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
  230. __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
  231. __cpu_to_le32(4),
  232. },
  233. {
  234. __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
  235. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  236. __cpu_to_le32(1),
  237. },
  238. { /* not used */
  239. __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
  240. __cpu_to_le32(PIPEDIR_OUT),
  241. __cpu_to_le32(5),
  242. },
  243. { /* in = DL = target -> host */
  244. __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA2_MSG),
  245. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  246. __cpu_to_le32(9),
  247. },
  248. { /* in = DL = target -> host */
  249. __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA3_MSG),
  250. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  251. __cpu_to_le32(10),
  252. },
  253. { /* in = DL = target -> host pktlog */
  254. __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_LOG_MSG),
  255. __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
  256. __cpu_to_le32(11),
  257. },
  258. /* (Additions here) */
  259. { /* must be last */
  260. __cpu_to_le32(0),
  261. __cpu_to_le32(0),
  262. __cpu_to_le32(0),
  263. },
  264. };
  265. void ath10k_snoc_write32(struct ath10k *ar, u32 offset, u32 value)
  266. {
  267. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  268. iowrite32(value, ar_snoc->mem + offset);
  269. }
  270. u32 ath10k_snoc_read32(struct ath10k *ar, u32 offset)
  271. {
  272. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  273. u32 val;
  274. val = ioread32(ar_snoc->mem + offset);
  275. return val;
  276. }
  277. static int __ath10k_snoc_rx_post_buf(struct ath10k_snoc_pipe *pipe)
  278. {
  279. struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
  280. struct ath10k *ar = pipe->hif_ce_state;
  281. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  282. struct sk_buff *skb;
  283. dma_addr_t paddr;
  284. int ret;
  285. skb = dev_alloc_skb(pipe->buf_sz);
  286. if (!skb)
  287. return -ENOMEM;
  288. WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb");
  289. paddr = dma_map_single(ar->dev, skb->data,
  290. skb->len + skb_tailroom(skb),
  291. DMA_FROM_DEVICE);
  292. if (unlikely(dma_mapping_error(ar->dev, paddr))) {
  293. ath10k_warn(ar, "failed to dma map snoc rx buf\n");
  294. dev_kfree_skb_any(skb);
  295. return -EIO;
  296. }
  297. ATH10K_SKB_RXCB(skb)->paddr = paddr;
  298. spin_lock_bh(&ce->ce_lock);
  299. ret = ce_pipe->ops->ce_rx_post_buf(ce_pipe, skb, paddr);
  300. spin_unlock_bh(&ce->ce_lock);
  301. if (ret) {
  302. dma_unmap_single(ar->dev, paddr, skb->len + skb_tailroom(skb),
  303. DMA_FROM_DEVICE);
  304. dev_kfree_skb_any(skb);
  305. return ret;
  306. }
  307. return 0;
  308. }
  309. static void ath10k_snoc_rx_post_pipe(struct ath10k_snoc_pipe *pipe)
  310. {
  311. struct ath10k *ar = pipe->hif_ce_state;
  312. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  313. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  314. struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
  315. int ret, num;
  316. if (pipe->buf_sz == 0)
  317. return;
  318. if (!ce_pipe->dest_ring)
  319. return;
  320. spin_lock_bh(&ce->ce_lock);
  321. num = __ath10k_ce_rx_num_free_bufs(ce_pipe);
  322. spin_unlock_bh(&ce->ce_lock);
  323. while (num--) {
  324. ret = __ath10k_snoc_rx_post_buf(pipe);
  325. if (ret) {
  326. if (ret == -ENOSPC)
  327. break;
  328. ath10k_warn(ar, "failed to post rx buf: %d\n", ret);
  329. mod_timer(&ar_snoc->rx_post_retry, jiffies +
  330. ATH10K_SNOC_RX_POST_RETRY_MS);
  331. break;
  332. }
  333. }
  334. }
  335. static void ath10k_snoc_rx_post(struct ath10k *ar)
  336. {
  337. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  338. int i;
  339. for (i = 0; i < CE_COUNT; i++)
  340. ath10k_snoc_rx_post_pipe(&ar_snoc->pipe_info[i]);
  341. }
  342. static void ath10k_snoc_process_rx_cb(struct ath10k_ce_pipe *ce_state,
  343. void (*callback)(struct ath10k *ar,
  344. struct sk_buff *skb))
  345. {
  346. struct ath10k *ar = ce_state->ar;
  347. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  348. struct ath10k_snoc_pipe *pipe_info = &ar_snoc->pipe_info[ce_state->id];
  349. struct sk_buff *skb;
  350. struct sk_buff_head list;
  351. void *transfer_context;
  352. unsigned int nbytes, max_nbytes;
  353. __skb_queue_head_init(&list);
  354. while (ath10k_ce_completed_recv_next(ce_state, &transfer_context,
  355. &nbytes) == 0) {
  356. skb = transfer_context;
  357. max_nbytes = skb->len + skb_tailroom(skb);
  358. dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  359. max_nbytes, DMA_FROM_DEVICE);
  360. if (unlikely(max_nbytes < nbytes)) {
  361. ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
  362. nbytes, max_nbytes);
  363. dev_kfree_skb_any(skb);
  364. continue;
  365. }
  366. skb_put(skb, nbytes);
  367. __skb_queue_tail(&list, skb);
  368. }
  369. while ((skb = __skb_dequeue(&list))) {
  370. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc rx ce pipe %d len %d\n",
  371. ce_state->id, skb->len);
  372. callback(ar, skb);
  373. }
  374. ath10k_snoc_rx_post_pipe(pipe_info);
  375. }
  376. static void ath10k_snoc_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
  377. {
  378. ath10k_snoc_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
  379. }
  380. static void ath10k_snoc_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
  381. {
  382. /* CE4 polling needs to be done whenever CE pipe which transports
  383. * HTT Rx (target->host) is processed.
  384. */
  385. ath10k_ce_per_engine_service(ce_state->ar, CE_POLL_PIPE);
  386. ath10k_snoc_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
  387. }
  388. static void ath10k_snoc_htt_rx_deliver(struct ath10k *ar, struct sk_buff *skb)
  389. {
  390. skb_pull(skb, sizeof(struct ath10k_htc_hdr));
  391. ath10k_htt_t2h_msg_handler(ar, skb);
  392. }
  393. static void ath10k_snoc_htt_rx_cb(struct ath10k_ce_pipe *ce_state)
  394. {
  395. ath10k_ce_per_engine_service(ce_state->ar, CE_POLL_PIPE);
  396. ath10k_snoc_process_rx_cb(ce_state, ath10k_snoc_htt_rx_deliver);
  397. }
  398. static void ath10k_snoc_rx_replenish_retry(struct timer_list *t)
  399. {
  400. struct ath10k_snoc *ar_snoc = from_timer(ar_snoc, t, rx_post_retry);
  401. struct ath10k *ar = ar_snoc->ar;
  402. ath10k_snoc_rx_post(ar);
  403. }
  404. static void ath10k_snoc_htc_tx_cb(struct ath10k_ce_pipe *ce_state)
  405. {
  406. struct ath10k *ar = ce_state->ar;
  407. struct sk_buff_head list;
  408. struct sk_buff *skb;
  409. __skb_queue_head_init(&list);
  410. while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
  411. if (!skb)
  412. continue;
  413. __skb_queue_tail(&list, skb);
  414. }
  415. while ((skb = __skb_dequeue(&list)))
  416. ath10k_htc_tx_completion_handler(ar, skb);
  417. }
  418. static void ath10k_snoc_htt_tx_cb(struct ath10k_ce_pipe *ce_state)
  419. {
  420. struct ath10k *ar = ce_state->ar;
  421. struct sk_buff *skb;
  422. while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
  423. if (!skb)
  424. continue;
  425. dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
  426. skb->len, DMA_TO_DEVICE);
  427. ath10k_htt_hif_tx_complete(ar, skb);
  428. }
  429. }
  430. static int ath10k_snoc_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
  431. struct ath10k_hif_sg_item *items, int n_items)
  432. {
  433. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  434. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  435. struct ath10k_snoc_pipe *snoc_pipe;
  436. struct ath10k_ce_pipe *ce_pipe;
  437. int err, i = 0;
  438. snoc_pipe = &ar_snoc->pipe_info[pipe_id];
  439. ce_pipe = snoc_pipe->ce_hdl;
  440. spin_lock_bh(&ce->ce_lock);
  441. for (i = 0; i < n_items - 1; i++) {
  442. ath10k_dbg(ar, ATH10K_DBG_SNOC,
  443. "snoc tx item %d paddr %pad len %d n_items %d\n",
  444. i, &items[i].paddr, items[i].len, n_items);
  445. err = ath10k_ce_send_nolock(ce_pipe,
  446. items[i].transfer_context,
  447. items[i].paddr,
  448. items[i].len,
  449. items[i].transfer_id,
  450. CE_SEND_FLAG_GATHER);
  451. if (err)
  452. goto err;
  453. }
  454. ath10k_dbg(ar, ATH10K_DBG_SNOC,
  455. "snoc tx item %d paddr %pad len %d n_items %d\n",
  456. i, &items[i].paddr, items[i].len, n_items);
  457. err = ath10k_ce_send_nolock(ce_pipe,
  458. items[i].transfer_context,
  459. items[i].paddr,
  460. items[i].len,
  461. items[i].transfer_id,
  462. 0);
  463. if (err)
  464. goto err;
  465. spin_unlock_bh(&ce->ce_lock);
  466. return 0;
  467. err:
  468. for (; i > 0; i--)
  469. __ath10k_ce_send_revert(ce_pipe);
  470. spin_unlock_bh(&ce->ce_lock);
  471. return err;
  472. }
  473. static int ath10k_snoc_hif_get_target_info(struct ath10k *ar,
  474. struct bmi_target_info *target_info)
  475. {
  476. target_info->version = ATH10K_HW_WCN3990;
  477. target_info->type = ATH10K_HW_WCN3990;
  478. return 0;
  479. }
  480. static u16 ath10k_snoc_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
  481. {
  482. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  483. ath10k_dbg(ar, ATH10K_DBG_SNOC, "hif get free queue number\n");
  484. return ath10k_ce_num_free_src_entries(ar_snoc->pipe_info[pipe].ce_hdl);
  485. }
  486. static void ath10k_snoc_hif_send_complete_check(struct ath10k *ar, u8 pipe,
  487. int force)
  488. {
  489. int resources;
  490. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc hif send complete check\n");
  491. if (!force) {
  492. resources = ath10k_snoc_hif_get_free_queue_number(ar, pipe);
  493. if (resources > (host_ce_config_wlan[pipe].src_nentries >> 1))
  494. return;
  495. }
  496. ath10k_ce_per_engine_service(ar, pipe);
  497. }
  498. static int ath10k_snoc_hif_map_service_to_pipe(struct ath10k *ar,
  499. u16 service_id,
  500. u8 *ul_pipe, u8 *dl_pipe)
  501. {
  502. const struct service_to_pipe *entry;
  503. bool ul_set = false, dl_set = false;
  504. int i;
  505. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc hif map service\n");
  506. for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) {
  507. entry = &target_service_to_ce_map_wlan[i];
  508. if (__le32_to_cpu(entry->service_id) != service_id)
  509. continue;
  510. switch (__le32_to_cpu(entry->pipedir)) {
  511. case PIPEDIR_NONE:
  512. break;
  513. case PIPEDIR_IN:
  514. WARN_ON(dl_set);
  515. *dl_pipe = __le32_to_cpu(entry->pipenum);
  516. dl_set = true;
  517. break;
  518. case PIPEDIR_OUT:
  519. WARN_ON(ul_set);
  520. *ul_pipe = __le32_to_cpu(entry->pipenum);
  521. ul_set = true;
  522. break;
  523. case PIPEDIR_INOUT:
  524. WARN_ON(dl_set);
  525. WARN_ON(ul_set);
  526. *dl_pipe = __le32_to_cpu(entry->pipenum);
  527. *ul_pipe = __le32_to_cpu(entry->pipenum);
  528. dl_set = true;
  529. ul_set = true;
  530. break;
  531. }
  532. }
  533. if (WARN_ON(!ul_set || !dl_set))
  534. return -ENOENT;
  535. return 0;
  536. }
  537. static void ath10k_snoc_hif_get_default_pipe(struct ath10k *ar,
  538. u8 *ul_pipe, u8 *dl_pipe)
  539. {
  540. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc hif get default pipe\n");
  541. (void)ath10k_snoc_hif_map_service_to_pipe(ar,
  542. ATH10K_HTC_SVC_ID_RSVD_CTRL,
  543. ul_pipe, dl_pipe);
  544. }
  545. static inline void ath10k_snoc_irq_disable(struct ath10k *ar)
  546. {
  547. ath10k_ce_disable_interrupts(ar);
  548. }
  549. static inline void ath10k_snoc_irq_enable(struct ath10k *ar)
  550. {
  551. ath10k_ce_enable_interrupts(ar);
  552. }
  553. static void ath10k_snoc_rx_pipe_cleanup(struct ath10k_snoc_pipe *snoc_pipe)
  554. {
  555. struct ath10k_ce_pipe *ce_pipe;
  556. struct ath10k_ce_ring *ce_ring;
  557. struct sk_buff *skb;
  558. struct ath10k *ar;
  559. int i;
  560. ar = snoc_pipe->hif_ce_state;
  561. ce_pipe = snoc_pipe->ce_hdl;
  562. ce_ring = ce_pipe->dest_ring;
  563. if (!ce_ring)
  564. return;
  565. if (!snoc_pipe->buf_sz)
  566. return;
  567. for (i = 0; i < ce_ring->nentries; i++) {
  568. skb = ce_ring->per_transfer_context[i];
  569. if (!skb)
  570. continue;
  571. ce_ring->per_transfer_context[i] = NULL;
  572. dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
  573. skb->len + skb_tailroom(skb),
  574. DMA_FROM_DEVICE);
  575. dev_kfree_skb_any(skb);
  576. }
  577. }
  578. static void ath10k_snoc_tx_pipe_cleanup(struct ath10k_snoc_pipe *snoc_pipe)
  579. {
  580. struct ath10k_ce_pipe *ce_pipe;
  581. struct ath10k_ce_ring *ce_ring;
  582. struct ath10k_snoc *ar_snoc;
  583. struct sk_buff *skb;
  584. struct ath10k *ar;
  585. int i;
  586. ar = snoc_pipe->hif_ce_state;
  587. ar_snoc = ath10k_snoc_priv(ar);
  588. ce_pipe = snoc_pipe->ce_hdl;
  589. ce_ring = ce_pipe->src_ring;
  590. if (!ce_ring)
  591. return;
  592. if (!snoc_pipe->buf_sz)
  593. return;
  594. for (i = 0; i < ce_ring->nentries; i++) {
  595. skb = ce_ring->per_transfer_context[i];
  596. if (!skb)
  597. continue;
  598. ce_ring->per_transfer_context[i] = NULL;
  599. ath10k_htc_tx_completion_handler(ar, skb);
  600. }
  601. }
  602. static void ath10k_snoc_buffer_cleanup(struct ath10k *ar)
  603. {
  604. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  605. struct ath10k_snoc_pipe *pipe_info;
  606. int pipe_num;
  607. del_timer_sync(&ar_snoc->rx_post_retry);
  608. for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
  609. pipe_info = &ar_snoc->pipe_info[pipe_num];
  610. ath10k_snoc_rx_pipe_cleanup(pipe_info);
  611. ath10k_snoc_tx_pipe_cleanup(pipe_info);
  612. }
  613. }
  614. static void ath10k_snoc_hif_stop(struct ath10k *ar)
  615. {
  616. ath10k_snoc_irq_disable(ar);
  617. ath10k_snoc_buffer_cleanup(ar);
  618. napi_synchronize(&ar->napi);
  619. napi_disable(&ar->napi);
  620. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n");
  621. }
  622. static int ath10k_snoc_hif_start(struct ath10k *ar)
  623. {
  624. ath10k_snoc_irq_enable(ar);
  625. ath10k_snoc_rx_post(ar);
  626. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n");
  627. return 0;
  628. }
  629. static int ath10k_snoc_init_pipes(struct ath10k *ar)
  630. {
  631. int i, ret;
  632. for (i = 0; i < CE_COUNT; i++) {
  633. ret = ath10k_ce_init_pipe(ar, i, &host_ce_config_wlan[i]);
  634. if (ret) {
  635. ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n",
  636. i, ret);
  637. return ret;
  638. }
  639. }
  640. return 0;
  641. }
  642. static int ath10k_snoc_wlan_enable(struct ath10k *ar)
  643. {
  644. return 0;
  645. }
  646. static void ath10k_snoc_wlan_disable(struct ath10k *ar)
  647. {
  648. }
  649. static void ath10k_snoc_hif_power_down(struct ath10k *ar)
  650. {
  651. ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n");
  652. ath10k_snoc_wlan_disable(ar);
  653. ath10k_ce_free_rri(ar);
  654. }
  655. static int ath10k_snoc_hif_power_up(struct ath10k *ar)
  656. {
  657. int ret;
  658. ath10k_dbg(ar, ATH10K_DBG_SNOC, "%s:WCN3990 driver state = %d\n",
  659. __func__, ar->state);
  660. ret = ath10k_snoc_wlan_enable(ar);
  661. if (ret) {
  662. ath10k_err(ar, "failed to enable wcn3990: %d\n", ret);
  663. return ret;
  664. }
  665. ath10k_ce_alloc_rri(ar);
  666. ret = ath10k_snoc_init_pipes(ar);
  667. if (ret) {
  668. ath10k_err(ar, "failed to initialize CE: %d\n", ret);
  669. goto err_wlan_enable;
  670. }
  671. napi_enable(&ar->napi);
  672. return 0;
  673. err_wlan_enable:
  674. ath10k_snoc_wlan_disable(ar);
  675. return ret;
  676. }
  677. static const struct ath10k_hif_ops ath10k_snoc_hif_ops = {
  678. .read32 = ath10k_snoc_read32,
  679. .write32 = ath10k_snoc_write32,
  680. .start = ath10k_snoc_hif_start,
  681. .stop = ath10k_snoc_hif_stop,
  682. .map_service_to_pipe = ath10k_snoc_hif_map_service_to_pipe,
  683. .get_default_pipe = ath10k_snoc_hif_get_default_pipe,
  684. .power_up = ath10k_snoc_hif_power_up,
  685. .power_down = ath10k_snoc_hif_power_down,
  686. .tx_sg = ath10k_snoc_hif_tx_sg,
  687. .send_complete_check = ath10k_snoc_hif_send_complete_check,
  688. .get_free_queue_number = ath10k_snoc_hif_get_free_queue_number,
  689. .get_target_info = ath10k_snoc_hif_get_target_info,
  690. };
  691. static const struct ath10k_bus_ops ath10k_snoc_bus_ops = {
  692. .read32 = ath10k_snoc_read32,
  693. .write32 = ath10k_snoc_write32,
  694. };
  695. static int ath10k_snoc_get_ce_id_from_irq(struct ath10k *ar, int irq)
  696. {
  697. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  698. int i;
  699. for (i = 0; i < CE_COUNT_MAX; i++) {
  700. if (ar_snoc->ce_irqs[i].irq_line == irq)
  701. return i;
  702. }
  703. ath10k_err(ar, "No matching CE id for irq %d\n", irq);
  704. return -EINVAL;
  705. }
  706. static irqreturn_t ath10k_snoc_per_engine_handler(int irq, void *arg)
  707. {
  708. struct ath10k *ar = arg;
  709. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  710. int ce_id = ath10k_snoc_get_ce_id_from_irq(ar, irq);
  711. if (ce_id < 0 || ce_id >= ARRAY_SIZE(ar_snoc->pipe_info)) {
  712. ath10k_warn(ar, "unexpected/invalid irq %d ce_id %d\n", irq,
  713. ce_id);
  714. return IRQ_HANDLED;
  715. }
  716. ath10k_snoc_irq_disable(ar);
  717. napi_schedule(&ar->napi);
  718. return IRQ_HANDLED;
  719. }
  720. static int ath10k_snoc_napi_poll(struct napi_struct *ctx, int budget)
  721. {
  722. struct ath10k *ar = container_of(ctx, struct ath10k, napi);
  723. int done = 0;
  724. ath10k_ce_per_engine_service_any(ar);
  725. done = ath10k_htt_txrx_compl_task(ar, budget);
  726. if (done < budget) {
  727. napi_complete(ctx);
  728. ath10k_snoc_irq_enable(ar);
  729. }
  730. return done;
  731. }
  732. static void ath10k_snoc_init_napi(struct ath10k *ar)
  733. {
  734. netif_napi_add(&ar->napi_dev, &ar->napi, ath10k_snoc_napi_poll,
  735. ATH10K_NAPI_BUDGET);
  736. }
  737. static int ath10k_snoc_request_irq(struct ath10k *ar)
  738. {
  739. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  740. int irqflags = IRQF_TRIGGER_RISING;
  741. int ret, id;
  742. for (id = 0; id < CE_COUNT_MAX; id++) {
  743. ret = request_irq(ar_snoc->ce_irqs[id].irq_line,
  744. ath10k_snoc_per_engine_handler,
  745. irqflags, ce_name[id], ar);
  746. if (ret) {
  747. ath10k_err(ar,
  748. "failed to register IRQ handler for CE %d: %d",
  749. id, ret);
  750. goto err_irq;
  751. }
  752. }
  753. return 0;
  754. err_irq:
  755. for (id -= 1; id >= 0; id--)
  756. free_irq(ar_snoc->ce_irqs[id].irq_line, ar);
  757. return ret;
  758. }
  759. static void ath10k_snoc_free_irq(struct ath10k *ar)
  760. {
  761. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  762. int id;
  763. for (id = 0; id < CE_COUNT_MAX; id++)
  764. free_irq(ar_snoc->ce_irqs[id].irq_line, ar);
  765. }
  766. static int ath10k_snoc_resource_init(struct ath10k *ar)
  767. {
  768. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  769. struct platform_device *pdev;
  770. struct resource *res;
  771. int i, ret = 0;
  772. pdev = ar_snoc->dev;
  773. res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "membase");
  774. if (!res) {
  775. ath10k_err(ar, "Memory base not found in DT\n");
  776. return -EINVAL;
  777. }
  778. ar_snoc->mem_pa = res->start;
  779. ar_snoc->mem = devm_ioremap(&pdev->dev, ar_snoc->mem_pa,
  780. resource_size(res));
  781. if (!ar_snoc->mem) {
  782. ath10k_err(ar, "Memory base ioremap failed with physical address %pa\n",
  783. &ar_snoc->mem_pa);
  784. return -EINVAL;
  785. }
  786. for (i = 0; i < CE_COUNT; i++) {
  787. res = platform_get_resource(ar_snoc->dev, IORESOURCE_IRQ, i);
  788. if (!res) {
  789. ath10k_err(ar, "failed to get IRQ%d\n", i);
  790. ret = -ENODEV;
  791. goto out;
  792. }
  793. ar_snoc->ce_irqs[i].irq_line = res->start;
  794. }
  795. out:
  796. return ret;
  797. }
  798. static int ath10k_snoc_setup_resource(struct ath10k *ar)
  799. {
  800. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  801. struct ath10k_ce *ce = ath10k_ce_priv(ar);
  802. struct ath10k_snoc_pipe *pipe;
  803. int i, ret;
  804. timer_setup(&ar_snoc->rx_post_retry, ath10k_snoc_rx_replenish_retry, 0);
  805. spin_lock_init(&ce->ce_lock);
  806. for (i = 0; i < CE_COUNT; i++) {
  807. pipe = &ar_snoc->pipe_info[i];
  808. pipe->ce_hdl = &ce->ce_states[i];
  809. pipe->pipe_num = i;
  810. pipe->hif_ce_state = ar;
  811. ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i]);
  812. if (ret) {
  813. ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n",
  814. i, ret);
  815. return ret;
  816. }
  817. pipe->buf_sz = host_ce_config_wlan[i].src_sz_max;
  818. }
  819. ath10k_snoc_init_napi(ar);
  820. return 0;
  821. }
  822. static void ath10k_snoc_release_resource(struct ath10k *ar)
  823. {
  824. int i;
  825. netif_napi_del(&ar->napi);
  826. for (i = 0; i < CE_COUNT; i++)
  827. ath10k_ce_free_pipe(ar, i);
  828. }
  829. static int ath10k_get_vreg_info(struct ath10k *ar, struct device *dev,
  830. struct ath10k_wcn3990_vreg_info *vreg_info)
  831. {
  832. struct regulator *reg;
  833. int ret = 0;
  834. reg = devm_regulator_get_optional(dev, vreg_info->name);
  835. if (IS_ERR(reg)) {
  836. ret = PTR_ERR(reg);
  837. if (ret == -EPROBE_DEFER) {
  838. ath10k_err(ar, "EPROBE_DEFER for regulator: %s\n",
  839. vreg_info->name);
  840. return ret;
  841. }
  842. if (vreg_info->required) {
  843. ath10k_err(ar, "Regulator %s doesn't exist: %d\n",
  844. vreg_info->name, ret);
  845. return ret;
  846. }
  847. ath10k_dbg(ar, ATH10K_DBG_SNOC,
  848. "Optional regulator %s doesn't exist: %d\n",
  849. vreg_info->name, ret);
  850. goto done;
  851. }
  852. vreg_info->reg = reg;
  853. done:
  854. ath10k_dbg(ar, ATH10K_DBG_SNOC,
  855. "snog vreg %s min_v %u max_v %u load_ua %u settle_delay %lu\n",
  856. vreg_info->name, vreg_info->min_v, vreg_info->max_v,
  857. vreg_info->load_ua, vreg_info->settle_delay);
  858. return 0;
  859. }
  860. static int ath10k_get_clk_info(struct ath10k *ar, struct device *dev,
  861. struct ath10k_wcn3990_clk_info *clk_info)
  862. {
  863. struct clk *handle;
  864. int ret = 0;
  865. handle = devm_clk_get(dev, clk_info->name);
  866. if (IS_ERR(handle)) {
  867. ret = PTR_ERR(handle);
  868. if (clk_info->required) {
  869. ath10k_err(ar, "snoc clock %s isn't available: %d\n",
  870. clk_info->name, ret);
  871. return ret;
  872. }
  873. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc ignoring clock %s: %d\n",
  874. clk_info->name,
  875. ret);
  876. return 0;
  877. }
  878. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc clock %s freq %u\n",
  879. clk_info->name, clk_info->freq);
  880. clk_info->handle = handle;
  881. return ret;
  882. }
  883. static int ath10k_wcn3990_vreg_on(struct ath10k *ar)
  884. {
  885. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  886. struct ath10k_wcn3990_vreg_info *vreg_info;
  887. int ret = 0;
  888. int i;
  889. for (i = 0; i < ARRAY_SIZE(vreg_cfg); i++) {
  890. vreg_info = &ar_snoc->vreg[i];
  891. if (!vreg_info->reg)
  892. continue;
  893. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc regulator %s being enabled\n",
  894. vreg_info->name);
  895. ret = regulator_set_voltage(vreg_info->reg, vreg_info->min_v,
  896. vreg_info->max_v);
  897. if (ret) {
  898. ath10k_err(ar,
  899. "failed to set regulator %s voltage-min: %d voltage-max: %d\n",
  900. vreg_info->name, vreg_info->min_v, vreg_info->max_v);
  901. goto err_reg_config;
  902. }
  903. if (vreg_info->load_ua) {
  904. ret = regulator_set_load(vreg_info->reg,
  905. vreg_info->load_ua);
  906. if (ret < 0) {
  907. ath10k_err(ar,
  908. "failed to set regulator %s load: %d\n",
  909. vreg_info->name,
  910. vreg_info->load_ua);
  911. goto err_reg_config;
  912. }
  913. }
  914. ret = regulator_enable(vreg_info->reg);
  915. if (ret) {
  916. ath10k_err(ar, "failed to enable regulator %s\n",
  917. vreg_info->name);
  918. goto err_reg_config;
  919. }
  920. if (vreg_info->settle_delay)
  921. udelay(vreg_info->settle_delay);
  922. }
  923. return 0;
  924. err_reg_config:
  925. for (; i >= 0; i--) {
  926. vreg_info = &ar_snoc->vreg[i];
  927. if (!vreg_info->reg)
  928. continue;
  929. regulator_disable(vreg_info->reg);
  930. regulator_set_load(vreg_info->reg, 0);
  931. regulator_set_voltage(vreg_info->reg, 0, vreg_info->max_v);
  932. }
  933. return ret;
  934. }
  935. static int ath10k_wcn3990_vreg_off(struct ath10k *ar)
  936. {
  937. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  938. struct ath10k_wcn3990_vreg_info *vreg_info;
  939. int ret = 0;
  940. int i;
  941. for (i = ARRAY_SIZE(vreg_cfg) - 1; i >= 0; i--) {
  942. vreg_info = &ar_snoc->vreg[i];
  943. if (!vreg_info->reg)
  944. continue;
  945. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc regulator %s being disabled\n",
  946. vreg_info->name);
  947. ret = regulator_disable(vreg_info->reg);
  948. if (ret)
  949. ath10k_err(ar, "failed to disable regulator %s\n",
  950. vreg_info->name);
  951. ret = regulator_set_load(vreg_info->reg, 0);
  952. if (ret < 0)
  953. ath10k_err(ar, "failed to set load %s\n",
  954. vreg_info->name);
  955. ret = regulator_set_voltage(vreg_info->reg, 0,
  956. vreg_info->max_v);
  957. if (ret)
  958. ath10k_err(ar, "failed to set voltage %s\n",
  959. vreg_info->name);
  960. }
  961. return ret;
  962. }
  963. static int ath10k_wcn3990_clk_init(struct ath10k *ar)
  964. {
  965. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  966. struct ath10k_wcn3990_clk_info *clk_info;
  967. int ret = 0;
  968. int i;
  969. for (i = 0; i < ARRAY_SIZE(clk_cfg); i++) {
  970. clk_info = &ar_snoc->clk[i];
  971. if (!clk_info->handle)
  972. continue;
  973. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc clock %s being enabled\n",
  974. clk_info->name);
  975. if (clk_info->freq) {
  976. ret = clk_set_rate(clk_info->handle, clk_info->freq);
  977. if (ret) {
  978. ath10k_err(ar, "failed to set clock %s freq %u\n",
  979. clk_info->name, clk_info->freq);
  980. goto err_clock_config;
  981. }
  982. }
  983. ret = clk_prepare_enable(clk_info->handle);
  984. if (ret) {
  985. ath10k_err(ar, "failed to enable clock %s\n",
  986. clk_info->name);
  987. goto err_clock_config;
  988. }
  989. }
  990. return 0;
  991. err_clock_config:
  992. for (; i >= 0; i--) {
  993. clk_info = &ar_snoc->clk[i];
  994. if (!clk_info->handle)
  995. continue;
  996. clk_disable_unprepare(clk_info->handle);
  997. }
  998. return ret;
  999. }
  1000. static int ath10k_wcn3990_clk_deinit(struct ath10k *ar)
  1001. {
  1002. struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
  1003. struct ath10k_wcn3990_clk_info *clk_info;
  1004. int i;
  1005. for (i = 0; i < ARRAY_SIZE(clk_cfg); i++) {
  1006. clk_info = &ar_snoc->clk[i];
  1007. if (!clk_info->handle)
  1008. continue;
  1009. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc clock %s being disabled\n",
  1010. clk_info->name);
  1011. clk_disable_unprepare(clk_info->handle);
  1012. }
  1013. return 0;
  1014. }
  1015. static int ath10k_hw_power_on(struct ath10k *ar)
  1016. {
  1017. int ret;
  1018. ath10k_dbg(ar, ATH10K_DBG_SNOC, "soc power on\n");
  1019. ret = ath10k_wcn3990_vreg_on(ar);
  1020. if (ret)
  1021. return ret;
  1022. ret = ath10k_wcn3990_clk_init(ar);
  1023. if (ret)
  1024. goto vreg_off;
  1025. return ret;
  1026. vreg_off:
  1027. ath10k_wcn3990_vreg_off(ar);
  1028. return ret;
  1029. }
  1030. static int ath10k_hw_power_off(struct ath10k *ar)
  1031. {
  1032. int ret;
  1033. ath10k_dbg(ar, ATH10K_DBG_SNOC, "soc power off\n");
  1034. ath10k_wcn3990_clk_deinit(ar);
  1035. ret = ath10k_wcn3990_vreg_off(ar);
  1036. return ret;
  1037. }
  1038. static const struct of_device_id ath10k_snoc_dt_match[] = {
  1039. { .compatible = "qcom,wcn3990-wifi",
  1040. .data = &drv_priv,
  1041. },
  1042. { }
  1043. };
  1044. MODULE_DEVICE_TABLE(of, ath10k_snoc_dt_match);
  1045. static int ath10k_snoc_probe(struct platform_device *pdev)
  1046. {
  1047. const struct ath10k_snoc_drv_priv *drv_data;
  1048. const struct of_device_id *of_id;
  1049. struct ath10k_snoc *ar_snoc;
  1050. struct device *dev;
  1051. struct ath10k *ar;
  1052. int ret;
  1053. u32 i;
  1054. of_id = of_match_device(ath10k_snoc_dt_match, &pdev->dev);
  1055. if (!of_id) {
  1056. dev_err(&pdev->dev, "failed to find matching device tree id\n");
  1057. return -EINVAL;
  1058. }
  1059. drv_data = of_id->data;
  1060. dev = &pdev->dev;
  1061. ret = dma_set_mask_and_coherent(dev, drv_data->dma_mask);
  1062. if (ret) {
  1063. dev_err(dev, "failed to set dma mask: %d", ret);
  1064. return ret;
  1065. }
  1066. ar = ath10k_core_create(sizeof(*ar_snoc), dev, ATH10K_BUS_SNOC,
  1067. drv_data->hw_rev, &ath10k_snoc_hif_ops);
  1068. if (!ar) {
  1069. dev_err(dev, "failed to allocate core\n");
  1070. return -ENOMEM;
  1071. }
  1072. ar_snoc = ath10k_snoc_priv(ar);
  1073. ar_snoc->dev = pdev;
  1074. platform_set_drvdata(pdev, ar);
  1075. ar_snoc->ar = ar;
  1076. ar_snoc->ce.bus_ops = &ath10k_snoc_bus_ops;
  1077. ar->ce_priv = &ar_snoc->ce;
  1078. ret = ath10k_snoc_resource_init(ar);
  1079. if (ret) {
  1080. ath10k_warn(ar, "failed to initialize resource: %d\n", ret);
  1081. goto err_core_destroy;
  1082. }
  1083. ret = ath10k_snoc_setup_resource(ar);
  1084. if (ret) {
  1085. ath10k_warn(ar, "failed to setup resource: %d\n", ret);
  1086. goto err_core_destroy;
  1087. }
  1088. ret = ath10k_snoc_request_irq(ar);
  1089. if (ret) {
  1090. ath10k_warn(ar, "failed to request irqs: %d\n", ret);
  1091. goto err_release_resource;
  1092. }
  1093. ar_snoc->vreg = vreg_cfg;
  1094. for (i = 0; i < ARRAY_SIZE(vreg_cfg); i++) {
  1095. ret = ath10k_get_vreg_info(ar, dev, &ar_snoc->vreg[i]);
  1096. if (ret)
  1097. goto err_free_irq;
  1098. }
  1099. ar_snoc->clk = clk_cfg;
  1100. for (i = 0; i < ARRAY_SIZE(clk_cfg); i++) {
  1101. ret = ath10k_get_clk_info(ar, dev, &ar_snoc->clk[i]);
  1102. if (ret)
  1103. goto err_free_irq;
  1104. }
  1105. ret = ath10k_hw_power_on(ar);
  1106. if (ret) {
  1107. ath10k_err(ar, "failed to power on device: %d\n", ret);
  1108. goto err_free_irq;
  1109. }
  1110. ret = ath10k_core_register(ar, drv_data->hw_rev);
  1111. if (ret) {
  1112. ath10k_err(ar, "failed to register driver core: %d\n", ret);
  1113. goto err_hw_power_off;
  1114. }
  1115. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc probe\n");
  1116. ath10k_warn(ar, "Warning: SNOC support is still work-in-progress, it will not work properly!");
  1117. return 0;
  1118. err_hw_power_off:
  1119. ath10k_hw_power_off(ar);
  1120. err_free_irq:
  1121. ath10k_snoc_free_irq(ar);
  1122. err_release_resource:
  1123. ath10k_snoc_release_resource(ar);
  1124. err_core_destroy:
  1125. ath10k_core_destroy(ar);
  1126. return ret;
  1127. }
  1128. static int ath10k_snoc_remove(struct platform_device *pdev)
  1129. {
  1130. struct ath10k *ar = platform_get_drvdata(pdev);
  1131. ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc remove\n");
  1132. ath10k_core_unregister(ar);
  1133. ath10k_hw_power_off(ar);
  1134. ath10k_snoc_free_irq(ar);
  1135. ath10k_snoc_release_resource(ar);
  1136. ath10k_core_destroy(ar);
  1137. return 0;
  1138. }
  1139. static struct platform_driver ath10k_snoc_driver = {
  1140. .probe = ath10k_snoc_probe,
  1141. .remove = ath10k_snoc_remove,
  1142. .driver = {
  1143. .name = "ath10k_snoc",
  1144. .of_match_table = ath10k_snoc_dt_match,
  1145. },
  1146. };
  1147. module_platform_driver(ath10k_snoc_driver);
  1148. MODULE_AUTHOR("Qualcomm");
  1149. MODULE_LICENSE("Dual BSD/GPL");
  1150. MODULE_DESCRIPTION("Driver support for Atheros WCN3990 SNOC devices");