2 * Copyright (c) 2018 The Linux Foundation. All rights reserved.
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.
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.
17 #include <linux/clk.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
21 #include <linux/of_device.h>
22 #include <linux/platform_device.h>
23 #include <linux/regulator/consumer.h>
31 #define ATH10K_SNOC_RX_POST_RETRY_MS 50
32 #define CE_POLL_PIPE 4
33 #define ATH10K_SNOC_WAKE_IRQ 2
35 static char *const ce_name[] = {
50 static struct ath10k_vreg_info vreg_cfg[] = {
51 {NULL, "vdd-0.8-cx-mx", 800000, 850000, 0, 0, false},
52 {NULL, "vdd-1.8-xo", 1800000, 1850000, 0, 0, false},
53 {NULL, "vdd-1.3-rfa", 1300000, 1350000, 0, 0, false},
54 {NULL, "vdd-3.3-ch0", 3300000, 3350000, 0, 0, false},
57 static struct ath10k_clk_info clk_cfg[] = {
58 {NULL, "cxo_ref_clk_pin", 0, false},
61 static void ath10k_snoc_htc_tx_cb(struct ath10k_ce_pipe *ce_state);
62 static void ath10k_snoc_htt_tx_cb(struct ath10k_ce_pipe *ce_state);
63 static void ath10k_snoc_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
64 static void ath10k_snoc_htt_rx_cb(struct ath10k_ce_pipe *ce_state);
65 static void ath10k_snoc_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
66 static void ath10k_snoc_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state);
68 static const struct ath10k_snoc_drv_priv drv_priv = {
69 .hw_rev = ATH10K_HW_WCN3990,
70 .dma_mask = DMA_BIT_MASK(35),
74 #define WCN3990_SRC_WR_IDX_OFFSET 0x3C
75 #define WCN3990_DST_WR_IDX_OFFSET 0x40
77 static struct ath10k_shadow_reg_cfg target_shadow_reg_cfg_map[] = {
79 .ce_id = __cpu_to_le16(0),
80 .reg_offset = __cpu_to_le16(WCN3990_SRC_WR_IDX_OFFSET),
84 .ce_id = __cpu_to_le16(3),
85 .reg_offset = __cpu_to_le16(WCN3990_SRC_WR_IDX_OFFSET),
89 .ce_id = __cpu_to_le16(4),
90 .reg_offset = __cpu_to_le16(WCN3990_SRC_WR_IDX_OFFSET),
94 .ce_id = __cpu_to_le16(5),
95 .reg_offset = __cpu_to_le16(WCN3990_SRC_WR_IDX_OFFSET),
99 .ce_id = __cpu_to_le16(7),
100 .reg_offset = __cpu_to_le16(WCN3990_SRC_WR_IDX_OFFSET),
104 .ce_id = __cpu_to_le16(1),
105 .reg_offset = __cpu_to_le16(WCN3990_DST_WR_IDX_OFFSET),
109 .ce_id = __cpu_to_le16(2),
110 .reg_offset = __cpu_to_le16(WCN3990_DST_WR_IDX_OFFSET),
114 .ce_id = __cpu_to_le16(7),
115 .reg_offset = __cpu_to_le16(WCN3990_DST_WR_IDX_OFFSET),
119 .ce_id = __cpu_to_le16(8),
120 .reg_offset = __cpu_to_le16(WCN3990_DST_WR_IDX_OFFSET),
124 .ce_id = __cpu_to_le16(9),
125 .reg_offset = __cpu_to_le16(WCN3990_DST_WR_IDX_OFFSET),
129 .ce_id = __cpu_to_le16(10),
130 .reg_offset = __cpu_to_le16(WCN3990_DST_WR_IDX_OFFSET),
134 .ce_id = __cpu_to_le16(11),
135 .reg_offset = __cpu_to_le16(WCN3990_DST_WR_IDX_OFFSET),
139 static struct ce_attr host_ce_config_wlan[] = {
140 /* CE0: host->target HTC control streams */
142 .flags = CE_ATTR_FLAGS,
146 .send_cb = ath10k_snoc_htc_tx_cb,
149 /* CE1: target->host HTT + HTC control */
151 .flags = CE_ATTR_FLAGS,
154 .dest_nentries = 512,
155 .recv_cb = ath10k_snoc_htt_htc_rx_cb,
158 /* CE2: target->host WMI */
160 .flags = CE_ATTR_FLAGS,
164 .recv_cb = ath10k_snoc_htc_rx_cb,
167 /* CE3: host->target WMI */
169 .flags = CE_ATTR_FLAGS,
173 .send_cb = ath10k_snoc_htc_tx_cb,
176 /* CE4: host->target HTT */
178 .flags = CE_ATTR_FLAGS | CE_ATTR_DIS_INTR,
182 .send_cb = ath10k_snoc_htt_tx_cb,
185 /* CE5: target->host HTT (ipa_uc->target ) */
187 .flags = CE_ATTR_FLAGS,
190 .dest_nentries = 512,
191 .recv_cb = ath10k_snoc_htt_rx_cb,
194 /* CE6: target autonomous hif_memcpy */
196 .flags = CE_ATTR_FLAGS,
202 /* CE7: ce_diag, the Diagnostic Window */
204 .flags = CE_ATTR_FLAGS,
210 /* CE8: Target to uMC */
212 .flags = CE_ATTR_FLAGS,
215 .dest_nentries = 128,
218 /* CE9 target->host HTT */
220 .flags = CE_ATTR_FLAGS,
223 .dest_nentries = 512,
224 .recv_cb = ath10k_snoc_htt_htc_rx_cb,
227 /* CE10: target->host HTT */
229 .flags = CE_ATTR_FLAGS,
232 .dest_nentries = 512,
233 .recv_cb = ath10k_snoc_htt_htc_rx_cb,
236 /* CE11: target -> host PKTLOG */
238 .flags = CE_ATTR_FLAGS,
241 .dest_nentries = 512,
242 .recv_cb = ath10k_snoc_pktlog_rx_cb,
246 static struct ce_pipe_config target_ce_config_wlan[] = {
247 /* CE0: host->target HTC control and raw streams */
249 .pipenum = __cpu_to_le32(0),
250 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
251 .nentries = __cpu_to_le32(32),
252 .nbytes_max = __cpu_to_le32(2048),
253 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
254 .reserved = __cpu_to_le32(0),
257 /* CE1: target->host HTT + HTC control */
259 .pipenum = __cpu_to_le32(1),
260 .pipedir = __cpu_to_le32(PIPEDIR_IN),
261 .nentries = __cpu_to_le32(32),
262 .nbytes_max = __cpu_to_le32(2048),
263 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
264 .reserved = __cpu_to_le32(0),
267 /* CE2: target->host WMI */
269 .pipenum = __cpu_to_le32(2),
270 .pipedir = __cpu_to_le32(PIPEDIR_IN),
271 .nentries = __cpu_to_le32(64),
272 .nbytes_max = __cpu_to_le32(2048),
273 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
274 .reserved = __cpu_to_le32(0),
277 /* CE3: host->target WMI */
279 .pipenum = __cpu_to_le32(3),
280 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
281 .nentries = __cpu_to_le32(32),
282 .nbytes_max = __cpu_to_le32(2048),
283 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
284 .reserved = __cpu_to_le32(0),
287 /* CE4: host->target HTT */
289 .pipenum = __cpu_to_le32(4),
290 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
291 .nentries = __cpu_to_le32(256),
292 .nbytes_max = __cpu_to_le32(256),
293 .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR),
294 .reserved = __cpu_to_le32(0),
297 /* CE5: target->host HTT (HIF->HTT) */
299 .pipenum = __cpu_to_le32(5),
300 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
301 .nentries = __cpu_to_le32(1024),
302 .nbytes_max = __cpu_to_le32(64),
303 .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR),
304 .reserved = __cpu_to_le32(0),
307 /* CE6: Reserved for target autonomous hif_memcpy */
309 .pipenum = __cpu_to_le32(6),
310 .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
311 .nentries = __cpu_to_le32(32),
312 .nbytes_max = __cpu_to_le32(16384),
313 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
314 .reserved = __cpu_to_le32(0),
317 /* CE7 used only by Host */
319 .pipenum = __cpu_to_le32(7),
320 .pipedir = __cpu_to_le32(4),
321 .nentries = __cpu_to_le32(0),
322 .nbytes_max = __cpu_to_le32(0),
323 .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR),
324 .reserved = __cpu_to_le32(0),
327 /* CE8 Target to uMC */
329 .pipenum = __cpu_to_le32(8),
330 .pipedir = __cpu_to_le32(PIPEDIR_IN),
331 .nentries = __cpu_to_le32(32),
332 .nbytes_max = __cpu_to_le32(2048),
333 .flags = __cpu_to_le32(0),
334 .reserved = __cpu_to_le32(0),
337 /* CE9 target->host HTT */
339 .pipenum = __cpu_to_le32(9),
340 .pipedir = __cpu_to_le32(PIPEDIR_IN),
341 .nentries = __cpu_to_le32(32),
342 .nbytes_max = __cpu_to_le32(2048),
343 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
344 .reserved = __cpu_to_le32(0),
347 /* CE10 target->host HTT */
349 .pipenum = __cpu_to_le32(10),
350 .pipedir = __cpu_to_le32(PIPEDIR_IN),
351 .nentries = __cpu_to_le32(32),
352 .nbytes_max = __cpu_to_le32(2048),
353 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
354 .reserved = __cpu_to_le32(0),
357 /* CE11 target autonomous qcache memcpy */
359 .pipenum = __cpu_to_le32(11),
360 .pipedir = __cpu_to_le32(PIPEDIR_IN),
361 .nentries = __cpu_to_le32(32),
362 .nbytes_max = __cpu_to_le32(2048),
363 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
364 .reserved = __cpu_to_le32(0),
368 static struct service_to_pipe target_service_to_ce_map_wlan[] = {
370 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
371 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
375 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
376 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
380 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
381 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
385 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
386 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
390 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
391 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
395 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
396 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
400 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
401 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
405 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
406 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
410 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
411 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
415 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
416 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
420 __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
421 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
425 __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
426 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
430 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
431 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
435 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
436 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
440 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
441 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
445 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
446 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
450 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
451 __cpu_to_le32(PIPEDIR_OUT),
454 { /* in = DL = target -> host */
455 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA2_MSG),
456 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
459 { /* in = DL = target -> host */
460 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA3_MSG),
461 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
464 { /* in = DL = target -> host pktlog */
465 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_LOG_MSG),
466 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
469 /* (Additions here) */
478 static void ath10k_snoc_write32(struct ath10k *ar, u32 offset, u32 value)
480 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
482 iowrite32(value, ar_snoc->mem + offset);
485 static u32 ath10k_snoc_read32(struct ath10k *ar, u32 offset)
487 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
490 val = ioread32(ar_snoc->mem + offset);
495 static int __ath10k_snoc_rx_post_buf(struct ath10k_snoc_pipe *pipe)
497 struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
498 struct ath10k *ar = pipe->hif_ce_state;
499 struct ath10k_ce *ce = ath10k_ce_priv(ar);
504 skb = dev_alloc_skb(pipe->buf_sz);
508 WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb");
510 paddr = dma_map_single(ar->dev, skb->data,
511 skb->len + skb_tailroom(skb),
513 if (unlikely(dma_mapping_error(ar->dev, paddr))) {
514 ath10k_warn(ar, "failed to dma map snoc rx buf\n");
515 dev_kfree_skb_any(skb);
519 ATH10K_SKB_RXCB(skb)->paddr = paddr;
521 spin_lock_bh(&ce->ce_lock);
522 ret = ce_pipe->ops->ce_rx_post_buf(ce_pipe, skb, paddr);
523 spin_unlock_bh(&ce->ce_lock);
525 dma_unmap_single(ar->dev, paddr, skb->len + skb_tailroom(skb),
527 dev_kfree_skb_any(skb);
534 static void ath10k_snoc_rx_post_pipe(struct ath10k_snoc_pipe *pipe)
536 struct ath10k *ar = pipe->hif_ce_state;
537 struct ath10k_ce *ce = ath10k_ce_priv(ar);
538 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
539 struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
542 if (pipe->buf_sz == 0)
545 if (!ce_pipe->dest_ring)
548 spin_lock_bh(&ce->ce_lock);
549 num = __ath10k_ce_rx_num_free_bufs(ce_pipe);
550 spin_unlock_bh(&ce->ce_lock);
552 ret = __ath10k_snoc_rx_post_buf(pipe);
556 ath10k_warn(ar, "failed to post rx buf: %d\n", ret);
557 mod_timer(&ar_snoc->rx_post_retry, jiffies +
558 ATH10K_SNOC_RX_POST_RETRY_MS);
564 static void ath10k_snoc_rx_post(struct ath10k *ar)
566 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
569 for (i = 0; i < CE_COUNT; i++)
570 ath10k_snoc_rx_post_pipe(&ar_snoc->pipe_info[i]);
573 static void ath10k_snoc_process_rx_cb(struct ath10k_ce_pipe *ce_state,
574 void (*callback)(struct ath10k *ar,
575 struct sk_buff *skb))
577 struct ath10k *ar = ce_state->ar;
578 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
579 struct ath10k_snoc_pipe *pipe_info = &ar_snoc->pipe_info[ce_state->id];
581 struct sk_buff_head list;
582 void *transfer_context;
583 unsigned int nbytes, max_nbytes;
585 __skb_queue_head_init(&list);
586 while (ath10k_ce_completed_recv_next(ce_state, &transfer_context,
588 skb = transfer_context;
589 max_nbytes = skb->len + skb_tailroom(skb);
590 dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
591 max_nbytes, DMA_FROM_DEVICE);
593 if (unlikely(max_nbytes < nbytes)) {
594 ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
596 dev_kfree_skb_any(skb);
600 skb_put(skb, nbytes);
601 __skb_queue_tail(&list, skb);
604 while ((skb = __skb_dequeue(&list))) {
605 ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc rx ce pipe %d len %d\n",
606 ce_state->id, skb->len);
611 ath10k_snoc_rx_post_pipe(pipe_info);
614 static void ath10k_snoc_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
616 ath10k_snoc_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
619 static void ath10k_snoc_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
621 /* CE4 polling needs to be done whenever CE pipe which transports
622 * HTT Rx (target->host) is processed.
624 ath10k_ce_per_engine_service(ce_state->ar, CE_POLL_PIPE);
626 ath10k_snoc_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
629 /* Called by lower (CE) layer when data is received from the Target.
630 * WCN3990 firmware uses separate CE(CE11) to transfer pktlog data.
632 static void ath10k_snoc_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state)
634 ath10k_snoc_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
637 static void ath10k_snoc_htt_rx_deliver(struct ath10k *ar, struct sk_buff *skb)
639 skb_pull(skb, sizeof(struct ath10k_htc_hdr));
640 ath10k_htt_t2h_msg_handler(ar, skb);
643 static void ath10k_snoc_htt_rx_cb(struct ath10k_ce_pipe *ce_state)
645 ath10k_ce_per_engine_service(ce_state->ar, CE_POLL_PIPE);
646 ath10k_snoc_process_rx_cb(ce_state, ath10k_snoc_htt_rx_deliver);
649 static void ath10k_snoc_rx_replenish_retry(struct timer_list *t)
651 struct ath10k_snoc *ar_snoc = from_timer(ar_snoc, t, rx_post_retry);
652 struct ath10k *ar = ar_snoc->ar;
654 ath10k_snoc_rx_post(ar);
657 static void ath10k_snoc_htc_tx_cb(struct ath10k_ce_pipe *ce_state)
659 struct ath10k *ar = ce_state->ar;
660 struct sk_buff_head list;
663 __skb_queue_head_init(&list);
664 while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
668 __skb_queue_tail(&list, skb);
671 while ((skb = __skb_dequeue(&list)))
672 ath10k_htc_tx_completion_handler(ar, skb);
675 static void ath10k_snoc_htt_tx_cb(struct ath10k_ce_pipe *ce_state)
677 struct ath10k *ar = ce_state->ar;
680 while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
684 dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
685 skb->len, DMA_TO_DEVICE);
686 ath10k_htt_hif_tx_complete(ar, skb);
690 static int ath10k_snoc_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
691 struct ath10k_hif_sg_item *items, int n_items)
693 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
694 struct ath10k_ce *ce = ath10k_ce_priv(ar);
695 struct ath10k_snoc_pipe *snoc_pipe;
696 struct ath10k_ce_pipe *ce_pipe;
699 snoc_pipe = &ar_snoc->pipe_info[pipe_id];
700 ce_pipe = snoc_pipe->ce_hdl;
701 spin_lock_bh(&ce->ce_lock);
703 for (i = 0; i < n_items - 1; i++) {
704 ath10k_dbg(ar, ATH10K_DBG_SNOC,
705 "snoc tx item %d paddr %pad len %d n_items %d\n",
706 i, &items[i].paddr, items[i].len, n_items);
708 err = ath10k_ce_send_nolock(ce_pipe,
709 items[i].transfer_context,
712 items[i].transfer_id,
713 CE_SEND_FLAG_GATHER);
718 ath10k_dbg(ar, ATH10K_DBG_SNOC,
719 "snoc tx item %d paddr %pad len %d n_items %d\n",
720 i, &items[i].paddr, items[i].len, n_items);
722 err = ath10k_ce_send_nolock(ce_pipe,
723 items[i].transfer_context,
726 items[i].transfer_id,
731 spin_unlock_bh(&ce->ce_lock);
737 __ath10k_ce_send_revert(ce_pipe);
739 spin_unlock_bh(&ce->ce_lock);
743 static int ath10k_snoc_hif_get_target_info(struct ath10k *ar,
744 struct bmi_target_info *target_info)
746 target_info->version = ATH10K_HW_WCN3990;
747 target_info->type = ATH10K_HW_WCN3990;
752 static u16 ath10k_snoc_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
754 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
756 ath10k_dbg(ar, ATH10K_DBG_SNOC, "hif get free queue number\n");
758 return ath10k_ce_num_free_src_entries(ar_snoc->pipe_info[pipe].ce_hdl);
761 static void ath10k_snoc_hif_send_complete_check(struct ath10k *ar, u8 pipe,
766 ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc hif send complete check\n");
769 resources = ath10k_snoc_hif_get_free_queue_number(ar, pipe);
771 if (resources > (host_ce_config_wlan[pipe].src_nentries >> 1))
774 ath10k_ce_per_engine_service(ar, pipe);
777 static int ath10k_snoc_hif_map_service_to_pipe(struct ath10k *ar,
779 u8 *ul_pipe, u8 *dl_pipe)
781 const struct service_to_pipe *entry;
782 bool ul_set = false, dl_set = false;
785 ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc hif map service\n");
787 for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) {
788 entry = &target_service_to_ce_map_wlan[i];
790 if (__le32_to_cpu(entry->service_id) != service_id)
793 switch (__le32_to_cpu(entry->pipedir)) {
798 *dl_pipe = __le32_to_cpu(entry->pipenum);
803 *ul_pipe = __le32_to_cpu(entry->pipenum);
809 *dl_pipe = __le32_to_cpu(entry->pipenum);
810 *ul_pipe = __le32_to_cpu(entry->pipenum);
817 if (!ul_set || !dl_set)
823 static void ath10k_snoc_hif_get_default_pipe(struct ath10k *ar,
824 u8 *ul_pipe, u8 *dl_pipe)
826 ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc hif get default pipe\n");
828 (void)ath10k_snoc_hif_map_service_to_pipe(ar,
829 ATH10K_HTC_SVC_ID_RSVD_CTRL,
833 static inline void ath10k_snoc_irq_disable(struct ath10k *ar)
835 ath10k_ce_disable_interrupts(ar);
838 static inline void ath10k_snoc_irq_enable(struct ath10k *ar)
840 ath10k_ce_enable_interrupts(ar);
843 static void ath10k_snoc_rx_pipe_cleanup(struct ath10k_snoc_pipe *snoc_pipe)
845 struct ath10k_ce_pipe *ce_pipe;
846 struct ath10k_ce_ring *ce_ring;
851 ar = snoc_pipe->hif_ce_state;
852 ce_pipe = snoc_pipe->ce_hdl;
853 ce_ring = ce_pipe->dest_ring;
858 if (!snoc_pipe->buf_sz)
861 for (i = 0; i < ce_ring->nentries; i++) {
862 skb = ce_ring->per_transfer_context[i];
866 ce_ring->per_transfer_context[i] = NULL;
868 dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
869 skb->len + skb_tailroom(skb),
871 dev_kfree_skb_any(skb);
875 static void ath10k_snoc_tx_pipe_cleanup(struct ath10k_snoc_pipe *snoc_pipe)
877 struct ath10k_ce_pipe *ce_pipe;
878 struct ath10k_ce_ring *ce_ring;
883 ar = snoc_pipe->hif_ce_state;
884 ce_pipe = snoc_pipe->ce_hdl;
885 ce_ring = ce_pipe->src_ring;
890 if (!snoc_pipe->buf_sz)
893 for (i = 0; i < ce_ring->nentries; i++) {
894 skb = ce_ring->per_transfer_context[i];
898 ce_ring->per_transfer_context[i] = NULL;
900 ath10k_htc_tx_completion_handler(ar, skb);
904 static void ath10k_snoc_buffer_cleanup(struct ath10k *ar)
906 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
907 struct ath10k_snoc_pipe *pipe_info;
910 del_timer_sync(&ar_snoc->rx_post_retry);
911 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
912 pipe_info = &ar_snoc->pipe_info[pipe_num];
913 ath10k_snoc_rx_pipe_cleanup(pipe_info);
914 ath10k_snoc_tx_pipe_cleanup(pipe_info);
918 static void ath10k_snoc_hif_stop(struct ath10k *ar)
920 if (!test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags))
921 ath10k_snoc_irq_disable(ar);
923 napi_synchronize(&ar->napi);
924 napi_disable(&ar->napi);
925 ath10k_snoc_buffer_cleanup(ar);
926 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n");
929 static int ath10k_snoc_hif_start(struct ath10k *ar)
931 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
933 napi_enable(&ar->napi);
934 ath10k_snoc_irq_enable(ar);
935 ath10k_snoc_rx_post(ar);
937 clear_bit(ATH10K_SNOC_FLAG_RECOVERY, &ar_snoc->flags);
939 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n");
944 static int ath10k_snoc_init_pipes(struct ath10k *ar)
948 for (i = 0; i < CE_COUNT; i++) {
949 ret = ath10k_ce_init_pipe(ar, i, &host_ce_config_wlan[i]);
951 ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n",
960 static int ath10k_snoc_wlan_enable(struct ath10k *ar,
961 enum ath10k_firmware_mode fw_mode)
963 struct ath10k_tgt_pipe_cfg tgt_cfg[CE_COUNT_MAX];
964 struct ath10k_qmi_wlan_enable_cfg cfg;
965 enum wlfw_driver_mode_enum_v01 mode;
968 for (pipe_num = 0; pipe_num < CE_COUNT_MAX; pipe_num++) {
969 tgt_cfg[pipe_num].pipe_num =
970 target_ce_config_wlan[pipe_num].pipenum;
971 tgt_cfg[pipe_num].pipe_dir =
972 target_ce_config_wlan[pipe_num].pipedir;
973 tgt_cfg[pipe_num].nentries =
974 target_ce_config_wlan[pipe_num].nentries;
975 tgt_cfg[pipe_num].nbytes_max =
976 target_ce_config_wlan[pipe_num].nbytes_max;
977 tgt_cfg[pipe_num].flags =
978 target_ce_config_wlan[pipe_num].flags;
979 tgt_cfg[pipe_num].reserved = 0;
982 cfg.num_ce_tgt_cfg = sizeof(target_ce_config_wlan) /
983 sizeof(struct ath10k_tgt_pipe_cfg);
984 cfg.ce_tgt_cfg = (struct ath10k_tgt_pipe_cfg *)
986 cfg.num_ce_svc_pipe_cfg = sizeof(target_service_to_ce_map_wlan) /
987 sizeof(struct ath10k_svc_pipe_cfg);
988 cfg.ce_svc_cfg = (struct ath10k_svc_pipe_cfg *)
989 &target_service_to_ce_map_wlan;
990 cfg.num_shadow_reg_cfg = sizeof(target_shadow_reg_cfg_map) /
991 sizeof(struct ath10k_shadow_reg_cfg);
992 cfg.shadow_reg_cfg = (struct ath10k_shadow_reg_cfg *)
993 &target_shadow_reg_cfg_map;
996 case ATH10K_FIRMWARE_MODE_NORMAL:
997 mode = QMI_WLFW_MISSION_V01;
999 case ATH10K_FIRMWARE_MODE_UTF:
1000 mode = QMI_WLFW_FTM_V01;
1003 ath10k_err(ar, "invalid firmware mode %d\n", fw_mode);
1007 return ath10k_qmi_wlan_enable(ar, &cfg, mode,
1011 static void ath10k_snoc_wlan_disable(struct ath10k *ar)
1013 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1015 /* If both ATH10K_FLAG_CRASH_FLUSH and ATH10K_SNOC_FLAG_RECOVERY
1016 * flags are not set, it means that the driver has restarted
1017 * due to a crash inject via debugfs. In this case, the driver
1018 * needs to restart the firmware and hence send qmi wlan disable,
1019 * during the driver restart sequence.
1021 if (!test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags) ||
1022 !test_bit(ATH10K_SNOC_FLAG_RECOVERY, &ar_snoc->flags))
1023 ath10k_qmi_wlan_disable(ar);
1026 static void ath10k_snoc_hif_power_down(struct ath10k *ar)
1028 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n");
1030 ath10k_snoc_wlan_disable(ar);
1031 ath10k_ce_free_rri(ar);
1034 static int ath10k_snoc_hif_power_up(struct ath10k *ar,
1035 enum ath10k_firmware_mode fw_mode)
1039 ath10k_dbg(ar, ATH10K_DBG_SNOC, "%s:WCN3990 driver state = %d\n",
1040 __func__, ar->state);
1042 ret = ath10k_snoc_wlan_enable(ar, fw_mode);
1044 ath10k_err(ar, "failed to enable wcn3990: %d\n", ret);
1048 ath10k_ce_alloc_rri(ar);
1050 ret = ath10k_snoc_init_pipes(ar);
1052 ath10k_err(ar, "failed to initialize CE: %d\n", ret);
1053 goto err_wlan_enable;
1059 ath10k_snoc_wlan_disable(ar);
1065 static int ath10k_snoc_hif_suspend(struct ath10k *ar)
1067 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1070 if (!device_may_wakeup(ar->dev))
1073 ret = enable_irq_wake(ar_snoc->ce_irqs[ATH10K_SNOC_WAKE_IRQ].irq_line);
1075 ath10k_err(ar, "failed to enable wakeup irq :%d\n", ret);
1079 ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc device suspended\n");
1084 static int ath10k_snoc_hif_resume(struct ath10k *ar)
1086 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1089 if (!device_may_wakeup(ar->dev))
1092 ret = disable_irq_wake(ar_snoc->ce_irqs[ATH10K_SNOC_WAKE_IRQ].irq_line);
1094 ath10k_err(ar, "failed to disable wakeup irq: %d\n", ret);
1098 ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc device resumed\n");
1104 static const struct ath10k_hif_ops ath10k_snoc_hif_ops = {
1105 .read32 = ath10k_snoc_read32,
1106 .write32 = ath10k_snoc_write32,
1107 .start = ath10k_snoc_hif_start,
1108 .stop = ath10k_snoc_hif_stop,
1109 .map_service_to_pipe = ath10k_snoc_hif_map_service_to_pipe,
1110 .get_default_pipe = ath10k_snoc_hif_get_default_pipe,
1111 .power_up = ath10k_snoc_hif_power_up,
1112 .power_down = ath10k_snoc_hif_power_down,
1113 .tx_sg = ath10k_snoc_hif_tx_sg,
1114 .send_complete_check = ath10k_snoc_hif_send_complete_check,
1115 .get_free_queue_number = ath10k_snoc_hif_get_free_queue_number,
1116 .get_target_info = ath10k_snoc_hif_get_target_info,
1118 .suspend = ath10k_snoc_hif_suspend,
1119 .resume = ath10k_snoc_hif_resume,
1123 static const struct ath10k_bus_ops ath10k_snoc_bus_ops = {
1124 .read32 = ath10k_snoc_read32,
1125 .write32 = ath10k_snoc_write32,
1128 static int ath10k_snoc_get_ce_id_from_irq(struct ath10k *ar, int irq)
1130 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1133 for (i = 0; i < CE_COUNT_MAX; i++) {
1134 if (ar_snoc->ce_irqs[i].irq_line == irq)
1137 ath10k_err(ar, "No matching CE id for irq %d\n", irq);
1142 static irqreturn_t ath10k_snoc_per_engine_handler(int irq, void *arg)
1144 struct ath10k *ar = arg;
1145 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1146 int ce_id = ath10k_snoc_get_ce_id_from_irq(ar, irq);
1148 if (ce_id < 0 || ce_id >= ARRAY_SIZE(ar_snoc->pipe_info)) {
1149 ath10k_warn(ar, "unexpected/invalid irq %d ce_id %d\n", irq,
1154 ath10k_snoc_irq_disable(ar);
1155 napi_schedule(&ar->napi);
1160 static int ath10k_snoc_napi_poll(struct napi_struct *ctx, int budget)
1162 struct ath10k *ar = container_of(ctx, struct ath10k, napi);
1165 if (test_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags)) {
1170 ath10k_ce_per_engine_service_any(ar);
1171 done = ath10k_htt_txrx_compl_task(ar, budget);
1173 if (done < budget) {
1175 ath10k_snoc_irq_enable(ar);
1181 static void ath10k_snoc_init_napi(struct ath10k *ar)
1183 netif_napi_add(&ar->napi_dev, &ar->napi, ath10k_snoc_napi_poll,
1184 ATH10K_NAPI_BUDGET);
1187 static int ath10k_snoc_request_irq(struct ath10k *ar)
1189 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1190 int irqflags = IRQF_TRIGGER_RISING;
1193 for (id = 0; id < CE_COUNT_MAX; id++) {
1194 ret = request_irq(ar_snoc->ce_irqs[id].irq_line,
1195 ath10k_snoc_per_engine_handler,
1196 irqflags, ce_name[id], ar);
1199 "failed to register IRQ handler for CE %d: %d",
1208 for (id -= 1; id >= 0; id--)
1209 free_irq(ar_snoc->ce_irqs[id].irq_line, ar);
1214 static void ath10k_snoc_free_irq(struct ath10k *ar)
1216 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1219 for (id = 0; id < CE_COUNT_MAX; id++)
1220 free_irq(ar_snoc->ce_irqs[id].irq_line, ar);
1223 static int ath10k_snoc_resource_init(struct ath10k *ar)
1225 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1226 struct platform_device *pdev;
1227 struct resource *res;
1230 pdev = ar_snoc->dev;
1231 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "membase");
1233 ath10k_err(ar, "Memory base not found in DT\n");
1237 ar_snoc->mem_pa = res->start;
1238 ar_snoc->mem = devm_ioremap(&pdev->dev, ar_snoc->mem_pa,
1239 resource_size(res));
1240 if (!ar_snoc->mem) {
1241 ath10k_err(ar, "Memory base ioremap failed with physical address %pa\n",
1246 for (i = 0; i < CE_COUNT; i++) {
1247 res = platform_get_resource(ar_snoc->dev, IORESOURCE_IRQ, i);
1249 ath10k_err(ar, "failed to get IRQ%d\n", i);
1253 ar_snoc->ce_irqs[i].irq_line = res->start;
1260 int ath10k_snoc_fw_indication(struct ath10k *ar, u64 type)
1262 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1263 struct ath10k_bus_params bus_params;
1266 if (test_bit(ATH10K_SNOC_FLAG_UNREGISTERING, &ar_snoc->flags))
1270 case ATH10K_QMI_EVENT_FW_READY_IND:
1271 if (test_bit(ATH10K_SNOC_FLAG_REGISTERED, &ar_snoc->flags)) {
1272 queue_work(ar->workqueue, &ar->restart_work);
1276 bus_params.dev_type = ATH10K_DEV_TYPE_LL;
1277 bus_params.chip_id = ar_snoc->target_info.soc_version;
1278 ret = ath10k_core_register(ar, &bus_params);
1280 ath10k_err(ar, "Failed to register driver core: %d\n",
1284 set_bit(ATH10K_SNOC_FLAG_REGISTERED, &ar_snoc->flags);
1286 case ATH10K_QMI_EVENT_FW_DOWN_IND:
1287 set_bit(ATH10K_SNOC_FLAG_RECOVERY, &ar_snoc->flags);
1288 set_bit(ATH10K_FLAG_CRASH_FLUSH, &ar->dev_flags);
1291 ath10k_err(ar, "invalid fw indication: %llx\n", type);
1298 static int ath10k_snoc_setup_resource(struct ath10k *ar)
1300 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1301 struct ath10k_ce *ce = ath10k_ce_priv(ar);
1302 struct ath10k_snoc_pipe *pipe;
1305 timer_setup(&ar_snoc->rx_post_retry, ath10k_snoc_rx_replenish_retry, 0);
1306 spin_lock_init(&ce->ce_lock);
1307 for (i = 0; i < CE_COUNT; i++) {
1308 pipe = &ar_snoc->pipe_info[i];
1309 pipe->ce_hdl = &ce->ce_states[i];
1311 pipe->hif_ce_state = ar;
1313 ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i]);
1315 ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n",
1320 pipe->buf_sz = host_ce_config_wlan[i].src_sz_max;
1322 ath10k_snoc_init_napi(ar);
1327 static void ath10k_snoc_release_resource(struct ath10k *ar)
1331 netif_napi_del(&ar->napi);
1332 for (i = 0; i < CE_COUNT; i++)
1333 ath10k_ce_free_pipe(ar, i);
1336 static int ath10k_get_vreg_info(struct ath10k *ar, struct device *dev,
1337 struct ath10k_vreg_info *vreg_info)
1339 struct regulator *reg;
1342 reg = devm_regulator_get_optional(dev, vreg_info->name);
1347 if (ret == -EPROBE_DEFER) {
1348 ath10k_err(ar, "EPROBE_DEFER for regulator: %s\n",
1352 if (vreg_info->required) {
1353 ath10k_err(ar, "Regulator %s doesn't exist: %d\n",
1354 vreg_info->name, ret);
1357 ath10k_dbg(ar, ATH10K_DBG_SNOC,
1358 "Optional regulator %s doesn't exist: %d\n",
1359 vreg_info->name, ret);
1363 vreg_info->reg = reg;
1366 ath10k_dbg(ar, ATH10K_DBG_SNOC,
1367 "snog vreg %s min_v %u max_v %u load_ua %u settle_delay %lu\n",
1368 vreg_info->name, vreg_info->min_v, vreg_info->max_v,
1369 vreg_info->load_ua, vreg_info->settle_delay);
1374 static int ath10k_get_clk_info(struct ath10k *ar, struct device *dev,
1375 struct ath10k_clk_info *clk_info)
1380 handle = devm_clk_get(dev, clk_info->name);
1381 if (IS_ERR(handle)) {
1382 ret = PTR_ERR(handle);
1383 if (clk_info->required) {
1384 ath10k_err(ar, "snoc clock %s isn't available: %d\n",
1385 clk_info->name, ret);
1388 ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc ignoring clock %s: %d\n",
1394 ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc clock %s freq %u\n",
1395 clk_info->name, clk_info->freq);
1397 clk_info->handle = handle;
1402 static int __ath10k_snoc_vreg_on(struct ath10k *ar,
1403 struct ath10k_vreg_info *vreg_info)
1407 ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc regulator %s being enabled\n",
1410 ret = regulator_set_voltage(vreg_info->reg, vreg_info->min_v,
1414 "failed to set regulator %s voltage-min: %d voltage-max: %d\n",
1415 vreg_info->name, vreg_info->min_v, vreg_info->max_v);
1419 if (vreg_info->load_ua) {
1420 ret = regulator_set_load(vreg_info->reg, vreg_info->load_ua);
1422 ath10k_err(ar, "failed to set regulator %s load: %d\n",
1423 vreg_info->name, vreg_info->load_ua);
1428 ret = regulator_enable(vreg_info->reg);
1430 ath10k_err(ar, "failed to enable regulator %s\n",
1435 if (vreg_info->settle_delay)
1436 udelay(vreg_info->settle_delay);
1441 regulator_set_load(vreg_info->reg, 0);
1443 regulator_set_voltage(vreg_info->reg, 0, vreg_info->max_v);
1448 static int __ath10k_snoc_vreg_off(struct ath10k *ar,
1449 struct ath10k_vreg_info *vreg_info)
1453 ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc regulator %s being disabled\n",
1456 ret = regulator_disable(vreg_info->reg);
1458 ath10k_err(ar, "failed to disable regulator %s\n",
1461 ret = regulator_set_load(vreg_info->reg, 0);
1463 ath10k_err(ar, "failed to set load %s\n", vreg_info->name);
1465 ret = regulator_set_voltage(vreg_info->reg, 0, vreg_info->max_v);
1467 ath10k_err(ar, "failed to set voltage %s\n", vreg_info->name);
1472 static int ath10k_snoc_vreg_on(struct ath10k *ar)
1474 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1475 struct ath10k_vreg_info *vreg_info;
1479 for (i = 0; i < ARRAY_SIZE(vreg_cfg); i++) {
1480 vreg_info = &ar_snoc->vreg[i];
1482 if (!vreg_info->reg)
1485 ret = __ath10k_snoc_vreg_on(ar, vreg_info);
1487 goto err_reg_config;
1493 for (i = i - 1; i >= 0; i--) {
1494 vreg_info = &ar_snoc->vreg[i];
1496 if (!vreg_info->reg)
1499 __ath10k_snoc_vreg_off(ar, vreg_info);
1505 static int ath10k_snoc_vreg_off(struct ath10k *ar)
1507 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1508 struct ath10k_vreg_info *vreg_info;
1512 for (i = ARRAY_SIZE(vreg_cfg) - 1; i >= 0; i--) {
1513 vreg_info = &ar_snoc->vreg[i];
1515 if (!vreg_info->reg)
1518 ret = __ath10k_snoc_vreg_off(ar, vreg_info);
1524 static int ath10k_snoc_clk_init(struct ath10k *ar)
1526 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1527 struct ath10k_clk_info *clk_info;
1531 for (i = 0; i < ARRAY_SIZE(clk_cfg); i++) {
1532 clk_info = &ar_snoc->clk[i];
1534 if (!clk_info->handle)
1537 ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc clock %s being enabled\n",
1540 if (clk_info->freq) {
1541 ret = clk_set_rate(clk_info->handle, clk_info->freq);
1544 ath10k_err(ar, "failed to set clock %s freq %u\n",
1545 clk_info->name, clk_info->freq);
1546 goto err_clock_config;
1550 ret = clk_prepare_enable(clk_info->handle);
1552 ath10k_err(ar, "failed to enable clock %s\n",
1554 goto err_clock_config;
1561 for (i = i - 1; i >= 0; i--) {
1562 clk_info = &ar_snoc->clk[i];
1564 if (!clk_info->handle)
1567 clk_disable_unprepare(clk_info->handle);
1573 static int ath10k_snoc_clk_deinit(struct ath10k *ar)
1575 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1576 struct ath10k_clk_info *clk_info;
1579 for (i = 0; i < ARRAY_SIZE(clk_cfg); i++) {
1580 clk_info = &ar_snoc->clk[i];
1582 if (!clk_info->handle)
1585 ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc clock %s being disabled\n",
1588 clk_disable_unprepare(clk_info->handle);
1594 static int ath10k_hw_power_on(struct ath10k *ar)
1598 ath10k_dbg(ar, ATH10K_DBG_SNOC, "soc power on\n");
1600 ret = ath10k_snoc_vreg_on(ar);
1604 ret = ath10k_snoc_clk_init(ar);
1611 ath10k_snoc_vreg_off(ar);
1615 static int ath10k_hw_power_off(struct ath10k *ar)
1619 ath10k_dbg(ar, ATH10K_DBG_SNOC, "soc power off\n");
1621 ath10k_snoc_clk_deinit(ar);
1623 ret = ath10k_snoc_vreg_off(ar);
1628 static const struct of_device_id ath10k_snoc_dt_match[] = {
1629 { .compatible = "qcom,wcn3990-wifi",
1634 MODULE_DEVICE_TABLE(of, ath10k_snoc_dt_match);
1636 static int ath10k_snoc_probe(struct platform_device *pdev)
1638 const struct ath10k_snoc_drv_priv *drv_data;
1639 const struct of_device_id *of_id;
1640 struct ath10k_snoc *ar_snoc;
1647 of_id = of_match_device(ath10k_snoc_dt_match, &pdev->dev);
1649 dev_err(&pdev->dev, "failed to find matching device tree id\n");
1653 drv_data = of_id->data;
1656 ret = dma_set_mask_and_coherent(dev, drv_data->dma_mask);
1658 dev_err(dev, "failed to set dma mask: %d", ret);
1662 ar = ath10k_core_create(sizeof(*ar_snoc), dev, ATH10K_BUS_SNOC,
1663 drv_data->hw_rev, &ath10k_snoc_hif_ops);
1665 dev_err(dev, "failed to allocate core\n");
1669 ar_snoc = ath10k_snoc_priv(ar);
1670 ar_snoc->dev = pdev;
1671 platform_set_drvdata(pdev, ar);
1673 ar_snoc->ce.bus_ops = &ath10k_snoc_bus_ops;
1674 ar->ce_priv = &ar_snoc->ce;
1675 msa_size = drv_data->msa_size;
1677 ret = ath10k_snoc_resource_init(ar);
1679 ath10k_warn(ar, "failed to initialize resource: %d\n", ret);
1680 goto err_core_destroy;
1683 ret = ath10k_snoc_setup_resource(ar);
1685 ath10k_warn(ar, "failed to setup resource: %d\n", ret);
1686 goto err_core_destroy;
1688 ret = ath10k_snoc_request_irq(ar);
1690 ath10k_warn(ar, "failed to request irqs: %d\n", ret);
1691 goto err_release_resource;
1694 ar_snoc->vreg = vreg_cfg;
1695 for (i = 0; i < ARRAY_SIZE(vreg_cfg); i++) {
1696 ret = ath10k_get_vreg_info(ar, dev, &ar_snoc->vreg[i]);
1701 ar_snoc->clk = clk_cfg;
1702 for (i = 0; i < ARRAY_SIZE(clk_cfg); i++) {
1703 ret = ath10k_get_clk_info(ar, dev, &ar_snoc->clk[i]);
1708 ret = ath10k_hw_power_on(ar);
1710 ath10k_err(ar, "failed to power on device: %d\n", ret);
1714 ret = ath10k_qmi_init(ar, msa_size);
1716 ath10k_warn(ar, "failed to register wlfw qmi client: %d\n", ret);
1717 goto err_core_destroy;
1720 ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc probe\n");
1725 ath10k_snoc_free_irq(ar);
1727 err_release_resource:
1728 ath10k_snoc_release_resource(ar);
1731 ath10k_core_destroy(ar);
1736 static int ath10k_snoc_remove(struct platform_device *pdev)
1738 struct ath10k *ar = platform_get_drvdata(pdev);
1739 struct ath10k_snoc *ar_snoc = ath10k_snoc_priv(ar);
1741 ath10k_dbg(ar, ATH10K_DBG_SNOC, "snoc remove\n");
1743 reinit_completion(&ar->driver_recovery);
1745 if (test_bit(ATH10K_SNOC_FLAG_RECOVERY, &ar_snoc->flags))
1746 wait_for_completion_timeout(&ar->driver_recovery, 3 * HZ);
1748 set_bit(ATH10K_SNOC_FLAG_UNREGISTERING, &ar_snoc->flags);
1750 ath10k_core_unregister(ar);
1751 ath10k_hw_power_off(ar);
1752 ath10k_snoc_free_irq(ar);
1753 ath10k_snoc_release_resource(ar);
1754 ath10k_qmi_deinit(ar);
1755 ath10k_core_destroy(ar);
1760 static struct platform_driver ath10k_snoc_driver = {
1761 .probe = ath10k_snoc_probe,
1762 .remove = ath10k_snoc_remove,
1764 .name = "ath10k_snoc",
1765 .of_match_table = ath10k_snoc_dt_match,
1768 module_platform_driver(ath10k_snoc_driver);
1770 MODULE_AUTHOR("Qualcomm");
1771 MODULE_LICENSE("Dual BSD/GPL");
1772 MODULE_DESCRIPTION("Driver support for Atheros WCN3990 SNOC devices");