1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2016-2017 Qualcomm Atheros, Inc. All rights reserved.
4 * Copyright (c) 2015 The Linux Foundation. All rights reserved.
6 #include <linux/module.h>
8 #include <linux/of_device.h>
10 #include <linux/reset.h>
16 static const struct of_device_id ath10k_ahb_of_match
[] = {
17 { .compatible
= "qcom,ipq4019-wifi",
18 .data
= (void *)ATH10K_HW_QCA4019
23 MODULE_DEVICE_TABLE(of
, ath10k_ahb_of_match
);
25 #define QCA4019_SRAM_ADDR 0x000C0000
26 #define QCA4019_SRAM_LEN 0x00040000 /* 256 kb */
28 static inline struct ath10k_ahb
*ath10k_ahb_priv(struct ath10k
*ar
)
30 return &((struct ath10k_pci
*)ar
->drv_priv
)->ahb
[0];
33 static void ath10k_ahb_write32(struct ath10k
*ar
, u32 offset
, u32 value
)
35 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
37 iowrite32(value
, ar_ahb
->mem
+ offset
);
40 static u32
ath10k_ahb_read32(struct ath10k
*ar
, u32 offset
)
42 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
44 return ioread32(ar_ahb
->mem
+ offset
);
47 static u32
ath10k_ahb_gcc_read32(struct ath10k
*ar
, u32 offset
)
49 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
51 return ioread32(ar_ahb
->gcc_mem
+ offset
);
54 static void ath10k_ahb_tcsr_write32(struct ath10k
*ar
, u32 offset
, u32 value
)
56 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
58 iowrite32(value
, ar_ahb
->tcsr_mem
+ offset
);
61 static u32
ath10k_ahb_tcsr_read32(struct ath10k
*ar
, u32 offset
)
63 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
65 return ioread32(ar_ahb
->tcsr_mem
+ offset
);
68 static u32
ath10k_ahb_soc_read32(struct ath10k
*ar
, u32 addr
)
70 return ath10k_ahb_read32(ar
, RTC_SOC_BASE_ADDRESS
+ addr
);
73 static int ath10k_ahb_get_num_banks(struct ath10k
*ar
)
75 if (ar
->hw_rev
== ATH10K_HW_QCA4019
)
78 ath10k_warn(ar
, "unknown number of banks, assuming 1\n");
82 static int ath10k_ahb_clock_init(struct ath10k
*ar
)
84 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
87 dev
= &ar_ahb
->pdev
->dev
;
89 ar_ahb
->cmd_clk
= devm_clk_get(dev
, "wifi_wcss_cmd");
90 if (IS_ERR_OR_NULL(ar_ahb
->cmd_clk
)) {
91 ath10k_err(ar
, "failed to get cmd clk: %ld\n",
92 PTR_ERR(ar_ahb
->cmd_clk
));
93 return ar_ahb
->cmd_clk
? PTR_ERR(ar_ahb
->cmd_clk
) : -ENODEV
;
96 ar_ahb
->ref_clk
= devm_clk_get(dev
, "wifi_wcss_ref");
97 if (IS_ERR_OR_NULL(ar_ahb
->ref_clk
)) {
98 ath10k_err(ar
, "failed to get ref clk: %ld\n",
99 PTR_ERR(ar_ahb
->ref_clk
));
100 return ar_ahb
->ref_clk
? PTR_ERR(ar_ahb
->ref_clk
) : -ENODEV
;
103 ar_ahb
->rtc_clk
= devm_clk_get(dev
, "wifi_wcss_rtc");
104 if (IS_ERR_OR_NULL(ar_ahb
->rtc_clk
)) {
105 ath10k_err(ar
, "failed to get rtc clk: %ld\n",
106 PTR_ERR(ar_ahb
->rtc_clk
));
107 return ar_ahb
->rtc_clk
? PTR_ERR(ar_ahb
->rtc_clk
) : -ENODEV
;
113 static void ath10k_ahb_clock_deinit(struct ath10k
*ar
)
115 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
117 ar_ahb
->cmd_clk
= NULL
;
118 ar_ahb
->ref_clk
= NULL
;
119 ar_ahb
->rtc_clk
= NULL
;
122 static int ath10k_ahb_clock_enable(struct ath10k
*ar
)
124 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
127 if (IS_ERR_OR_NULL(ar_ahb
->cmd_clk
) ||
128 IS_ERR_OR_NULL(ar_ahb
->ref_clk
) ||
129 IS_ERR_OR_NULL(ar_ahb
->rtc_clk
)) {
130 ath10k_err(ar
, "clock(s) is/are not initialized\n");
135 ret
= clk_prepare_enable(ar_ahb
->cmd_clk
);
137 ath10k_err(ar
, "failed to enable cmd clk: %d\n", ret
);
141 ret
= clk_prepare_enable(ar_ahb
->ref_clk
);
143 ath10k_err(ar
, "failed to enable ref clk: %d\n", ret
);
144 goto err_cmd_clk_disable
;
147 ret
= clk_prepare_enable(ar_ahb
->rtc_clk
);
149 ath10k_err(ar
, "failed to enable rtc clk: %d\n", ret
);
150 goto err_ref_clk_disable
;
156 clk_disable_unprepare(ar_ahb
->ref_clk
);
159 clk_disable_unprepare(ar_ahb
->cmd_clk
);
165 static void ath10k_ahb_clock_disable(struct ath10k
*ar
)
167 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
169 clk_disable_unprepare(ar_ahb
->cmd_clk
);
171 clk_disable_unprepare(ar_ahb
->ref_clk
);
173 clk_disable_unprepare(ar_ahb
->rtc_clk
);
176 static int ath10k_ahb_rst_ctrl_init(struct ath10k
*ar
)
178 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
181 dev
= &ar_ahb
->pdev
->dev
;
183 ar_ahb
->core_cold_rst
= devm_reset_control_get_exclusive(dev
,
185 if (IS_ERR(ar_ahb
->core_cold_rst
)) {
186 ath10k_err(ar
, "failed to get core cold rst ctrl: %ld\n",
187 PTR_ERR(ar_ahb
->core_cold_rst
));
188 return PTR_ERR(ar_ahb
->core_cold_rst
);
191 ar_ahb
->radio_cold_rst
= devm_reset_control_get_exclusive(dev
,
193 if (IS_ERR(ar_ahb
->radio_cold_rst
)) {
194 ath10k_err(ar
, "failed to get radio cold rst ctrl: %ld\n",
195 PTR_ERR(ar_ahb
->radio_cold_rst
));
196 return PTR_ERR(ar_ahb
->radio_cold_rst
);
199 ar_ahb
->radio_warm_rst
= devm_reset_control_get_exclusive(dev
,
201 if (IS_ERR(ar_ahb
->radio_warm_rst
)) {
202 ath10k_err(ar
, "failed to get radio warm rst ctrl: %ld\n",
203 PTR_ERR(ar_ahb
->radio_warm_rst
));
204 return PTR_ERR(ar_ahb
->radio_warm_rst
);
207 ar_ahb
->radio_srif_rst
= devm_reset_control_get_exclusive(dev
,
209 if (IS_ERR(ar_ahb
->radio_srif_rst
)) {
210 ath10k_err(ar
, "failed to get radio srif rst ctrl: %ld\n",
211 PTR_ERR(ar_ahb
->radio_srif_rst
));
212 return PTR_ERR(ar_ahb
->radio_srif_rst
);
215 ar_ahb
->cpu_init_rst
= devm_reset_control_get_exclusive(dev
,
217 if (IS_ERR(ar_ahb
->cpu_init_rst
)) {
218 ath10k_err(ar
, "failed to get cpu init rst ctrl: %ld\n",
219 PTR_ERR(ar_ahb
->cpu_init_rst
));
220 return PTR_ERR(ar_ahb
->cpu_init_rst
);
226 static void ath10k_ahb_rst_ctrl_deinit(struct ath10k
*ar
)
228 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
230 ar_ahb
->core_cold_rst
= NULL
;
231 ar_ahb
->radio_cold_rst
= NULL
;
232 ar_ahb
->radio_warm_rst
= NULL
;
233 ar_ahb
->radio_srif_rst
= NULL
;
234 ar_ahb
->cpu_init_rst
= NULL
;
237 static int ath10k_ahb_release_reset(struct ath10k
*ar
)
239 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
242 if (IS_ERR_OR_NULL(ar_ahb
->radio_cold_rst
) ||
243 IS_ERR_OR_NULL(ar_ahb
->radio_warm_rst
) ||
244 IS_ERR_OR_NULL(ar_ahb
->radio_srif_rst
) ||
245 IS_ERR_OR_NULL(ar_ahb
->cpu_init_rst
)) {
246 ath10k_err(ar
, "rst ctrl(s) is/are not initialized\n");
250 ret
= reset_control_deassert(ar_ahb
->radio_cold_rst
);
252 ath10k_err(ar
, "failed to deassert radio cold rst: %d\n", ret
);
256 ret
= reset_control_deassert(ar_ahb
->radio_warm_rst
);
258 ath10k_err(ar
, "failed to deassert radio warm rst: %d\n", ret
);
262 ret
= reset_control_deassert(ar_ahb
->radio_srif_rst
);
264 ath10k_err(ar
, "failed to deassert radio srif rst: %d\n", ret
);
268 ret
= reset_control_deassert(ar_ahb
->cpu_init_rst
);
270 ath10k_err(ar
, "failed to deassert cpu init rst: %d\n", ret
);
277 static void ath10k_ahb_halt_axi_bus(struct ath10k
*ar
, u32 haltreq_reg
,
280 unsigned long timeout
;
283 /* Issue halt axi bus request */
284 val
= ath10k_ahb_tcsr_read32(ar
, haltreq_reg
);
285 val
|= AHB_AXI_BUS_HALT_REQ
;
286 ath10k_ahb_tcsr_write32(ar
, haltreq_reg
, val
);
288 /* Wait for axi bus halted ack */
289 timeout
= jiffies
+ msecs_to_jiffies(ATH10K_AHB_AXI_BUS_HALT_TIMEOUT
);
291 val
= ath10k_ahb_tcsr_read32(ar
, haltack_reg
);
292 if (val
& AHB_AXI_BUS_HALT_ACK
)
296 } while (time_before(jiffies
, timeout
));
298 if (!(val
& AHB_AXI_BUS_HALT_ACK
)) {
299 ath10k_err(ar
, "failed to halt axi bus: %d\n", val
);
303 ath10k_dbg(ar
, ATH10K_DBG_AHB
, "axi bus halted\n");
306 static void ath10k_ahb_halt_chip(struct ath10k
*ar
)
308 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
309 u32 core_id
, glb_cfg_reg
, haltreq_reg
, haltack_reg
;
313 if (IS_ERR_OR_NULL(ar_ahb
->core_cold_rst
) ||
314 IS_ERR_OR_NULL(ar_ahb
->radio_cold_rst
) ||
315 IS_ERR_OR_NULL(ar_ahb
->radio_warm_rst
) ||
316 IS_ERR_OR_NULL(ar_ahb
->radio_srif_rst
) ||
317 IS_ERR_OR_NULL(ar_ahb
->cpu_init_rst
)) {
318 ath10k_err(ar
, "rst ctrl(s) is/are not initialized\n");
322 core_id
= ath10k_ahb_read32(ar
, ATH10K_AHB_WLAN_CORE_ID_REG
);
326 glb_cfg_reg
= ATH10K_AHB_TCSR_WIFI0_GLB_CFG
;
327 haltreq_reg
= ATH10K_AHB_TCSR_WCSS0_HALTREQ
;
328 haltack_reg
= ATH10K_AHB_TCSR_WCSS0_HALTACK
;
331 glb_cfg_reg
= ATH10K_AHB_TCSR_WIFI1_GLB_CFG
;
332 haltreq_reg
= ATH10K_AHB_TCSR_WCSS1_HALTREQ
;
333 haltack_reg
= ATH10K_AHB_TCSR_WCSS1_HALTACK
;
336 ath10k_err(ar
, "invalid core id %d found, skipping reset sequence\n",
341 ath10k_ahb_halt_axi_bus(ar
, haltreq_reg
, haltack_reg
);
343 val
= ath10k_ahb_tcsr_read32(ar
, glb_cfg_reg
);
344 val
|= TCSR_WIFIX_GLB_CFG_DISABLE_CORE_CLK
;
345 ath10k_ahb_tcsr_write32(ar
, glb_cfg_reg
, val
);
347 ret
= reset_control_assert(ar_ahb
->core_cold_rst
);
349 ath10k_err(ar
, "failed to assert core cold rst: %d\n", ret
);
352 ret
= reset_control_assert(ar_ahb
->radio_cold_rst
);
354 ath10k_err(ar
, "failed to assert radio cold rst: %d\n", ret
);
357 ret
= reset_control_assert(ar_ahb
->radio_warm_rst
);
359 ath10k_err(ar
, "failed to assert radio warm rst: %d\n", ret
);
362 ret
= reset_control_assert(ar_ahb
->radio_srif_rst
);
364 ath10k_err(ar
, "failed to assert radio srif rst: %d\n", ret
);
367 ret
= reset_control_assert(ar_ahb
->cpu_init_rst
);
369 ath10k_err(ar
, "failed to assert cpu init rst: %d\n", ret
);
372 /* Clear halt req and core clock disable req before
373 * deasserting wifi core reset.
375 val
= ath10k_ahb_tcsr_read32(ar
, haltreq_reg
);
376 val
&= ~AHB_AXI_BUS_HALT_REQ
;
377 ath10k_ahb_tcsr_write32(ar
, haltreq_reg
, val
);
379 val
= ath10k_ahb_tcsr_read32(ar
, glb_cfg_reg
);
380 val
&= ~TCSR_WIFIX_GLB_CFG_DISABLE_CORE_CLK
;
381 ath10k_ahb_tcsr_write32(ar
, glb_cfg_reg
, val
);
383 ret
= reset_control_deassert(ar_ahb
->core_cold_rst
);
385 ath10k_err(ar
, "failed to deassert core cold rst: %d\n", ret
);
387 ath10k_dbg(ar
, ATH10K_DBG_AHB
, "core %d reset done\n", core_id
);
390 static irqreturn_t
ath10k_ahb_interrupt_handler(int irq
, void *arg
)
392 struct ath10k
*ar
= arg
;
394 if (!ath10k_pci_irq_pending(ar
))
397 ath10k_pci_disable_and_clear_legacy_irq(ar
);
398 ath10k_pci_irq_msi_fw_mask(ar
);
399 napi_schedule(&ar
->napi
);
404 static int ath10k_ahb_request_irq_legacy(struct ath10k
*ar
)
406 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
407 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
410 ret
= request_irq(ar_ahb
->irq
,
411 ath10k_ahb_interrupt_handler
,
412 IRQF_SHARED
, "ath10k_ahb", ar
);
414 ath10k_warn(ar
, "failed to request legacy irq %d: %d\n",
418 ar_pci
->oper_irq_mode
= ATH10K_PCI_IRQ_LEGACY
;
423 static void ath10k_ahb_release_irq_legacy(struct ath10k
*ar
)
425 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
427 free_irq(ar_ahb
->irq
, ar
);
430 static void ath10k_ahb_irq_disable(struct ath10k
*ar
)
432 ath10k_ce_disable_interrupts(ar
);
433 ath10k_pci_disable_and_clear_legacy_irq(ar
);
436 static int ath10k_ahb_resource_init(struct ath10k
*ar
)
438 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
439 struct platform_device
*pdev
;
440 struct resource
*res
;
445 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
447 ath10k_err(ar
, "failed to get memory resource\n");
452 ar_ahb
->mem
= devm_ioremap_resource(&pdev
->dev
, res
);
453 if (IS_ERR(ar_ahb
->mem
)) {
454 ath10k_err(ar
, "mem ioremap error\n");
455 ret
= PTR_ERR(ar_ahb
->mem
);
459 ar_ahb
->mem_len
= resource_size(res
);
461 ar_ahb
->gcc_mem
= ioremap(ATH10K_GCC_REG_BASE
,
462 ATH10K_GCC_REG_SIZE
);
463 if (!ar_ahb
->gcc_mem
) {
464 ath10k_err(ar
, "gcc mem ioremap error\n");
469 ar_ahb
->tcsr_mem
= ioremap(ATH10K_TCSR_REG_BASE
,
470 ATH10K_TCSR_REG_SIZE
);
471 if (!ar_ahb
->tcsr_mem
) {
472 ath10k_err(ar
, "tcsr mem ioremap error\n");
474 goto err_gcc_mem_unmap
;
477 ret
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
479 ath10k_err(ar
, "failed to set 32-bit dma mask: %d\n", ret
);
480 goto err_tcsr_mem_unmap
;
483 ret
= dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(32));
485 ath10k_err(ar
, "failed to set 32-bit consistent dma: %d\n",
487 goto err_tcsr_mem_unmap
;
490 ret
= ath10k_ahb_clock_init(ar
);
492 goto err_tcsr_mem_unmap
;
494 ret
= ath10k_ahb_rst_ctrl_init(ar
);
496 goto err_clock_deinit
;
498 ar_ahb
->irq
= platform_get_irq_byname(pdev
, "legacy");
499 if (ar_ahb
->irq
< 0) {
500 ath10k_err(ar
, "failed to get irq number: %d\n", ar_ahb
->irq
);
502 goto err_clock_deinit
;
505 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "irq: %d\n", ar_ahb
->irq
);
507 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "mem: 0x%pK mem_len: %lu gcc mem: 0x%pK tcsr_mem: 0x%pK\n",
508 ar_ahb
->mem
, ar_ahb
->mem_len
,
509 ar_ahb
->gcc_mem
, ar_ahb
->tcsr_mem
);
513 ath10k_ahb_clock_deinit(ar
);
516 iounmap(ar_ahb
->tcsr_mem
);
519 ar_ahb
->tcsr_mem
= NULL
;
520 iounmap(ar_ahb
->gcc_mem
);
523 ar_ahb
->gcc_mem
= NULL
;
524 devm_iounmap(&pdev
->dev
, ar_ahb
->mem
);
531 static void ath10k_ahb_resource_deinit(struct ath10k
*ar
)
533 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
536 dev
= &ar_ahb
->pdev
->dev
;
539 devm_iounmap(dev
, ar_ahb
->mem
);
542 iounmap(ar_ahb
->gcc_mem
);
544 if (ar_ahb
->tcsr_mem
)
545 iounmap(ar_ahb
->tcsr_mem
);
548 ar_ahb
->gcc_mem
= NULL
;
549 ar_ahb
->tcsr_mem
= NULL
;
551 ath10k_ahb_clock_deinit(ar
);
552 ath10k_ahb_rst_ctrl_deinit(ar
);
555 static int ath10k_ahb_prepare_device(struct ath10k
*ar
)
560 ret
= ath10k_ahb_clock_enable(ar
);
562 ath10k_err(ar
, "failed to enable clocks\n");
566 /* Clock for the target is supplied from outside of target (ie,
567 * external clock module controlled by the host). Target needs
568 * to know what frequency target cpu is configured which is needed
569 * for target internal use. Read target cpu frequency info from
570 * gcc register and write into target's scratch register where
571 * target expects this information.
573 val
= ath10k_ahb_gcc_read32(ar
, ATH10K_AHB_GCC_FEPLL_PLL_DIV
);
574 ath10k_ahb_write32(ar
, ATH10K_AHB_WIFI_SCRATCH_5_REG
, val
);
576 ret
= ath10k_ahb_release_reset(ar
);
578 goto err_clk_disable
;
580 ath10k_ahb_irq_disable(ar
);
582 ath10k_ahb_write32(ar
, FW_INDICATOR_ADDRESS
, FW_IND_HOST_READY
);
584 ret
= ath10k_pci_wait_for_target_init(ar
);
591 ath10k_ahb_halt_chip(ar
);
594 ath10k_ahb_clock_disable(ar
);
599 static int ath10k_ahb_chip_reset(struct ath10k
*ar
)
603 ath10k_ahb_halt_chip(ar
);
604 ath10k_ahb_clock_disable(ar
);
606 ret
= ath10k_ahb_prepare_device(ar
);
613 static int ath10k_ahb_wake_target_cpu(struct ath10k
*ar
)
617 addr
= SOC_CORE_BASE_ADDRESS
| CORE_CTRL_ADDRESS
;
618 val
= ath10k_ahb_read32(ar
, addr
);
619 val
|= ATH10K_AHB_CORE_CTRL_CPU_INTR_MASK
;
620 ath10k_ahb_write32(ar
, addr
, val
);
625 static int ath10k_ahb_hif_start(struct ath10k
*ar
)
627 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot ahb hif start\n");
629 napi_enable(&ar
->napi
);
630 ath10k_ce_enable_interrupts(ar
);
631 ath10k_pci_enable_legacy_irq(ar
);
633 ath10k_pci_rx_post(ar
);
638 static void ath10k_ahb_hif_stop(struct ath10k
*ar
)
640 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
642 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot ahb hif stop\n");
644 ath10k_ahb_irq_disable(ar
);
645 synchronize_irq(ar_ahb
->irq
);
647 napi_synchronize(&ar
->napi
);
648 napi_disable(&ar
->napi
);
650 ath10k_pci_flush(ar
);
653 static int ath10k_ahb_hif_power_up(struct ath10k
*ar
,
654 enum ath10k_firmware_mode fw_mode
)
658 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot ahb hif power up\n");
660 ret
= ath10k_ahb_chip_reset(ar
);
662 ath10k_err(ar
, "failed to reset chip: %d\n", ret
);
666 ret
= ath10k_pci_init_pipes(ar
);
668 ath10k_err(ar
, "failed to initialize CE: %d\n", ret
);
672 ret
= ath10k_pci_init_config(ar
);
674 ath10k_err(ar
, "failed to setup init config: %d\n", ret
);
678 ret
= ath10k_ahb_wake_target_cpu(ar
);
680 ath10k_err(ar
, "could not wake up target CPU: %d\n", ret
);
687 ath10k_pci_ce_deinit(ar
);
692 static u32
ath10k_ahb_qca4019_targ_cpu_to_ce_addr(struct ath10k
*ar
, u32 addr
)
694 u32 val
= 0, region
= addr
& 0xfffff;
696 val
= ath10k_pci_read32(ar
, PCIE_BAR_REG_ADDRESS
);
698 if (region
>= QCA4019_SRAM_ADDR
&& region
<=
699 (QCA4019_SRAM_ADDR
+ QCA4019_SRAM_LEN
)) {
700 /* SRAM contents for QCA4019 can be directly accessed and
701 * no conversions are required
705 val
|= 0x100000 | region
;
711 static const struct ath10k_hif_ops ath10k_ahb_hif_ops
= {
712 .tx_sg
= ath10k_pci_hif_tx_sg
,
713 .diag_read
= ath10k_pci_hif_diag_read
,
714 .diag_write
= ath10k_pci_diag_write_mem
,
715 .exchange_bmi_msg
= ath10k_pci_hif_exchange_bmi_msg
,
716 .start
= ath10k_ahb_hif_start
,
717 .stop
= ath10k_ahb_hif_stop
,
718 .map_service_to_pipe
= ath10k_pci_hif_map_service_to_pipe
,
719 .get_default_pipe
= ath10k_pci_hif_get_default_pipe
,
720 .send_complete_check
= ath10k_pci_hif_send_complete_check
,
721 .get_free_queue_number
= ath10k_pci_hif_get_free_queue_number
,
722 .power_up
= ath10k_ahb_hif_power_up
,
723 .power_down
= ath10k_pci_hif_power_down
,
724 .read32
= ath10k_ahb_read32
,
725 .write32
= ath10k_ahb_write32
,
728 static const struct ath10k_bus_ops ath10k_ahb_bus_ops
= {
729 .read32
= ath10k_ahb_read32
,
730 .write32
= ath10k_ahb_write32
,
731 .get_num_banks
= ath10k_ahb_get_num_banks
,
734 static int ath10k_ahb_probe(struct platform_device
*pdev
)
737 struct ath10k_ahb
*ar_ahb
;
738 struct ath10k_pci
*ar_pci
;
739 const struct of_device_id
*of_id
;
740 enum ath10k_hw_rev hw_rev
;
743 struct ath10k_bus_params bus_params
= {};
745 of_id
= of_match_device(ath10k_ahb_of_match
, &pdev
->dev
);
747 dev_err(&pdev
->dev
, "failed to find matching device tree id\n");
751 hw_rev
= (enum ath10k_hw_rev
)of_id
->data
;
753 size
= sizeof(*ar_pci
) + sizeof(*ar_ahb
);
754 ar
= ath10k_core_create(size
, &pdev
->dev
, ATH10K_BUS_AHB
,
755 hw_rev
, &ath10k_ahb_hif_ops
);
757 dev_err(&pdev
->dev
, "failed to allocate core\n");
761 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "ahb probe\n");
763 ar_pci
= ath10k_pci_priv(ar
);
764 ar_ahb
= ath10k_ahb_priv(ar
);
767 platform_set_drvdata(pdev
, ar
);
769 ret
= ath10k_ahb_resource_init(ar
);
771 goto err_core_destroy
;
774 ar_pci
->mem
= ar_ahb
->mem
;
775 ar_pci
->mem_len
= ar_ahb
->mem_len
;
777 ar_pci
->ce
.bus_ops
= &ath10k_ahb_bus_ops
;
778 ar_pci
->targ_cpu_to_ce_addr
= ath10k_ahb_qca4019_targ_cpu_to_ce_addr
;
779 ar
->ce_priv
= &ar_pci
->ce
;
781 ret
= ath10k_pci_setup_resource(ar
);
783 ath10k_err(ar
, "failed to setup resource: %d\n", ret
);
784 goto err_resource_deinit
;
787 ath10k_pci_init_napi(ar
);
789 ret
= ath10k_ahb_request_irq_legacy(ar
);
793 ret
= ath10k_ahb_prepare_device(ar
);
797 ath10k_pci_ce_deinit(ar
);
799 bus_params
.dev_type
= ATH10K_DEV_TYPE_LL
;
800 bus_params
.chip_id
= ath10k_ahb_soc_read32(ar
, SOC_CHIP_ID_ADDRESS
);
801 if (bus_params
.chip_id
== 0xffffffff) {
802 ath10k_err(ar
, "failed to get chip id\n");
804 goto err_halt_device
;
807 ret
= ath10k_core_register(ar
, &bus_params
);
809 ath10k_err(ar
, "failed to register driver core: %d\n", ret
);
810 goto err_halt_device
;
816 ath10k_ahb_halt_chip(ar
);
817 ath10k_ahb_clock_disable(ar
);
820 ath10k_ahb_release_irq_legacy(ar
);
823 ath10k_pci_release_resource(ar
);
826 ath10k_ahb_resource_deinit(ar
);
829 ath10k_core_destroy(ar
);
830 platform_set_drvdata(pdev
, NULL
);
835 static int ath10k_ahb_remove(struct platform_device
*pdev
)
837 struct ath10k
*ar
= platform_get_drvdata(pdev
);
838 struct ath10k_ahb
*ar_ahb
;
843 ar_ahb
= ath10k_ahb_priv(ar
);
848 ath10k_dbg(ar
, ATH10K_DBG_AHB
, "ahb remove\n");
850 ath10k_core_unregister(ar
);
851 ath10k_ahb_irq_disable(ar
);
852 ath10k_ahb_release_irq_legacy(ar
);
853 ath10k_pci_release_resource(ar
);
854 ath10k_ahb_halt_chip(ar
);
855 ath10k_ahb_clock_disable(ar
);
856 ath10k_ahb_resource_deinit(ar
);
857 ath10k_core_destroy(ar
);
859 platform_set_drvdata(pdev
, NULL
);
864 static struct platform_driver ath10k_ahb_driver
= {
866 .name
= "ath10k_ahb",
867 .of_match_table
= ath10k_ahb_of_match
,
869 .probe
= ath10k_ahb_probe
,
870 .remove
= ath10k_ahb_remove
,
873 int ath10k_ahb_init(void)
877 ret
= platform_driver_register(&ath10k_ahb_driver
);
879 printk(KERN_ERR
"failed to register ath10k ahb driver: %d\n",
884 void ath10k_ahb_exit(void)
886 platform_driver_unregister(&ath10k_ahb_driver
);