2 * Copyright (c) 2016 Qualcomm Atheros, Inc. All rights reserved.
3 * Copyright (c) 2015 The Linux Foundation. All rights reserved.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/module.h>
19 #include <linux/of_device.h>
20 #include <linux/clk.h>
21 #include <linux/reset.h>
27 static const struct of_device_id ath10k_ahb_of_match
[] = {
28 { .compatible
= "qcom,ipq4019-wifi",
29 .data
= (void *)ATH10K_HW_QCA4019
34 MODULE_DEVICE_TABLE(of
, ath10k_ahb_of_match
);
36 static inline struct ath10k_ahb
*ath10k_ahb_priv(struct ath10k
*ar
)
38 return &((struct ath10k_pci
*)ar
->drv_priv
)->ahb
[0];
41 static void ath10k_ahb_write32(struct ath10k
*ar
, u32 offset
, u32 value
)
43 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
45 iowrite32(value
, ar_ahb
->mem
+ offset
);
48 static u32
ath10k_ahb_read32(struct ath10k
*ar
, u32 offset
)
50 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
52 return ioread32(ar_ahb
->mem
+ offset
);
55 static u32
ath10k_ahb_gcc_read32(struct ath10k
*ar
, u32 offset
)
57 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
59 return ioread32(ar_ahb
->gcc_mem
+ offset
);
62 static void ath10k_ahb_tcsr_write32(struct ath10k
*ar
, u32 offset
, u32 value
)
64 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
66 iowrite32(value
, ar_ahb
->tcsr_mem
+ offset
);
69 static u32
ath10k_ahb_tcsr_read32(struct ath10k
*ar
, u32 offset
)
71 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
73 return ioread32(ar_ahb
->tcsr_mem
+ offset
);
76 static u32
ath10k_ahb_soc_read32(struct ath10k
*ar
, u32 addr
)
78 return ath10k_ahb_read32(ar
, RTC_SOC_BASE_ADDRESS
+ addr
);
81 static int ath10k_ahb_get_num_banks(struct ath10k
*ar
)
83 if (ar
->hw_rev
== ATH10K_HW_QCA4019
)
86 ath10k_warn(ar
, "unknown number of banks, assuming 1\n");
90 static int ath10k_ahb_clock_init(struct ath10k
*ar
)
92 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
96 dev
= &ar_ahb
->pdev
->dev
;
98 ar_ahb
->cmd_clk
= clk_get(dev
, "wifi_wcss_cmd");
99 if (IS_ERR_OR_NULL(ar_ahb
->cmd_clk
)) {
100 ath10k_err(ar
, "failed to get cmd clk: %ld\n",
101 PTR_ERR(ar_ahb
->cmd_clk
));
102 ret
= ar_ahb
->cmd_clk
? PTR_ERR(ar_ahb
->cmd_clk
) : -ENODEV
;
106 ar_ahb
->ref_clk
= clk_get(dev
, "wifi_wcss_ref");
107 if (IS_ERR_OR_NULL(ar_ahb
->ref_clk
)) {
108 ath10k_err(ar
, "failed to get ref clk: %ld\n",
109 PTR_ERR(ar_ahb
->ref_clk
));
110 ret
= ar_ahb
->ref_clk
? PTR_ERR(ar_ahb
->ref_clk
) : -ENODEV
;
111 goto err_cmd_clk_put
;
114 ar_ahb
->rtc_clk
= clk_get(dev
, "wifi_wcss_rtc");
115 if (IS_ERR_OR_NULL(ar_ahb
->rtc_clk
)) {
116 ath10k_err(ar
, "failed to get rtc clk: %ld\n",
117 PTR_ERR(ar_ahb
->rtc_clk
));
118 ret
= ar_ahb
->rtc_clk
? PTR_ERR(ar_ahb
->rtc_clk
) : -ENODEV
;
119 goto err_ref_clk_put
;
125 clk_put(ar_ahb
->ref_clk
);
128 clk_put(ar_ahb
->cmd_clk
);
134 static void ath10k_ahb_clock_deinit(struct ath10k
*ar
)
136 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
138 if (!IS_ERR_OR_NULL(ar_ahb
->cmd_clk
))
139 clk_put(ar_ahb
->cmd_clk
);
141 if (!IS_ERR_OR_NULL(ar_ahb
->ref_clk
))
142 clk_put(ar_ahb
->ref_clk
);
144 if (!IS_ERR_OR_NULL(ar_ahb
->rtc_clk
))
145 clk_put(ar_ahb
->rtc_clk
);
147 ar_ahb
->cmd_clk
= NULL
;
148 ar_ahb
->ref_clk
= NULL
;
149 ar_ahb
->rtc_clk
= NULL
;
152 static int ath10k_ahb_clock_enable(struct ath10k
*ar
)
154 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
158 dev
= &ar_ahb
->pdev
->dev
;
160 if (IS_ERR_OR_NULL(ar_ahb
->cmd_clk
) ||
161 IS_ERR_OR_NULL(ar_ahb
->ref_clk
) ||
162 IS_ERR_OR_NULL(ar_ahb
->rtc_clk
)) {
163 ath10k_err(ar
, "clock(s) is/are not initialized\n");
168 ret
= clk_prepare_enable(ar_ahb
->cmd_clk
);
170 ath10k_err(ar
, "failed to enable cmd clk: %d\n", ret
);
174 ret
= clk_prepare_enable(ar_ahb
->ref_clk
);
176 ath10k_err(ar
, "failed to enable ref clk: %d\n", ret
);
177 goto err_cmd_clk_disable
;
180 ret
= clk_prepare_enable(ar_ahb
->rtc_clk
);
182 ath10k_err(ar
, "failed to enable rtc clk: %d\n", ret
);
183 goto err_ref_clk_disable
;
189 clk_disable_unprepare(ar_ahb
->ref_clk
);
192 clk_disable_unprepare(ar_ahb
->cmd_clk
);
198 static void ath10k_ahb_clock_disable(struct ath10k
*ar
)
200 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
202 if (!IS_ERR_OR_NULL(ar_ahb
->cmd_clk
))
203 clk_disable_unprepare(ar_ahb
->cmd_clk
);
205 if (!IS_ERR_OR_NULL(ar_ahb
->ref_clk
))
206 clk_disable_unprepare(ar_ahb
->ref_clk
);
208 if (!IS_ERR_OR_NULL(ar_ahb
->rtc_clk
))
209 clk_disable_unprepare(ar_ahb
->rtc_clk
);
212 static int ath10k_ahb_rst_ctrl_init(struct ath10k
*ar
)
214 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
218 dev
= &ar_ahb
->pdev
->dev
;
220 ar_ahb
->core_cold_rst
= reset_control_get(dev
, "wifi_core_cold");
221 if (IS_ERR_OR_NULL(ar_ahb
->core_cold_rst
)) {
222 ath10k_err(ar
, "failed to get core cold rst ctrl: %ld\n",
223 PTR_ERR(ar_ahb
->core_cold_rst
));
224 ret
= ar_ahb
->core_cold_rst
?
225 PTR_ERR(ar_ahb
->core_cold_rst
) : -ENODEV
;
229 ar_ahb
->radio_cold_rst
= reset_control_get(dev
, "wifi_radio_cold");
230 if (IS_ERR_OR_NULL(ar_ahb
->radio_cold_rst
)) {
231 ath10k_err(ar
, "failed to get radio cold rst ctrl: %ld\n",
232 PTR_ERR(ar_ahb
->radio_cold_rst
));
233 ret
= ar_ahb
->radio_cold_rst
?
234 PTR_ERR(ar_ahb
->radio_cold_rst
) : -ENODEV
;
235 goto err_core_cold_rst_put
;
238 ar_ahb
->radio_warm_rst
= reset_control_get(dev
, "wifi_radio_warm");
239 if (IS_ERR_OR_NULL(ar_ahb
->radio_warm_rst
)) {
240 ath10k_err(ar
, "failed to get radio warm rst ctrl: %ld\n",
241 PTR_ERR(ar_ahb
->radio_warm_rst
));
242 ret
= ar_ahb
->radio_warm_rst
?
243 PTR_ERR(ar_ahb
->radio_warm_rst
) : -ENODEV
;
244 goto err_radio_cold_rst_put
;
247 ar_ahb
->radio_srif_rst
= reset_control_get(dev
, "wifi_radio_srif");
248 if (IS_ERR_OR_NULL(ar_ahb
->radio_srif_rst
)) {
249 ath10k_err(ar
, "failed to get radio srif rst ctrl: %ld\n",
250 PTR_ERR(ar_ahb
->radio_srif_rst
));
251 ret
= ar_ahb
->radio_srif_rst
?
252 PTR_ERR(ar_ahb
->radio_srif_rst
) : -ENODEV
;
253 goto err_radio_warm_rst_put
;
256 ar_ahb
->cpu_init_rst
= reset_control_get(dev
, "wifi_cpu_init");
257 if (IS_ERR_OR_NULL(ar_ahb
->cpu_init_rst
)) {
258 ath10k_err(ar
, "failed to get cpu init rst ctrl: %ld\n",
259 PTR_ERR(ar_ahb
->cpu_init_rst
));
260 ret
= ar_ahb
->cpu_init_rst
?
261 PTR_ERR(ar_ahb
->cpu_init_rst
) : -ENODEV
;
262 goto err_radio_srif_rst_put
;
267 err_radio_srif_rst_put
:
268 reset_control_put(ar_ahb
->radio_srif_rst
);
270 err_radio_warm_rst_put
:
271 reset_control_put(ar_ahb
->radio_warm_rst
);
273 err_radio_cold_rst_put
:
274 reset_control_put(ar_ahb
->radio_cold_rst
);
276 err_core_cold_rst_put
:
277 reset_control_put(ar_ahb
->core_cold_rst
);
283 static void ath10k_ahb_rst_ctrl_deinit(struct ath10k
*ar
)
285 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
287 if (!IS_ERR_OR_NULL(ar_ahb
->core_cold_rst
))
288 reset_control_put(ar_ahb
->core_cold_rst
);
290 if (!IS_ERR_OR_NULL(ar_ahb
->radio_cold_rst
))
291 reset_control_put(ar_ahb
->radio_cold_rst
);
293 if (!IS_ERR_OR_NULL(ar_ahb
->radio_warm_rst
))
294 reset_control_put(ar_ahb
->radio_warm_rst
);
296 if (!IS_ERR_OR_NULL(ar_ahb
->radio_srif_rst
))
297 reset_control_put(ar_ahb
->radio_srif_rst
);
299 if (!IS_ERR_OR_NULL(ar_ahb
->cpu_init_rst
))
300 reset_control_put(ar_ahb
->cpu_init_rst
);
302 ar_ahb
->core_cold_rst
= NULL
;
303 ar_ahb
->radio_cold_rst
= NULL
;
304 ar_ahb
->radio_warm_rst
= NULL
;
305 ar_ahb
->radio_srif_rst
= NULL
;
306 ar_ahb
->cpu_init_rst
= NULL
;
309 static int ath10k_ahb_release_reset(struct ath10k
*ar
)
311 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
314 if (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 ret
= reset_control_deassert(ar_ahb
->radio_cold_rst
);
324 ath10k_err(ar
, "failed to deassert radio cold rst: %d\n", ret
);
328 ret
= reset_control_deassert(ar_ahb
->radio_warm_rst
);
330 ath10k_err(ar
, "failed to deassert radio warm rst: %d\n", ret
);
334 ret
= reset_control_deassert(ar_ahb
->radio_srif_rst
);
336 ath10k_err(ar
, "failed to deassert radio srif rst: %d\n", ret
);
340 ret
= reset_control_deassert(ar_ahb
->cpu_init_rst
);
342 ath10k_err(ar
, "failed to deassert cpu init rst: %d\n", ret
);
349 static void ath10k_ahb_halt_axi_bus(struct ath10k
*ar
, u32 haltreq_reg
,
352 unsigned long timeout
;
355 /* Issue halt axi bus request */
356 val
= ath10k_ahb_tcsr_read32(ar
, haltreq_reg
);
357 val
|= AHB_AXI_BUS_HALT_REQ
;
358 ath10k_ahb_tcsr_write32(ar
, haltreq_reg
, val
);
360 /* Wait for axi bus halted ack */
361 timeout
= jiffies
+ msecs_to_jiffies(ATH10K_AHB_AXI_BUS_HALT_TIMEOUT
);
363 val
= ath10k_ahb_tcsr_read32(ar
, haltack_reg
);
364 if (val
& AHB_AXI_BUS_HALT_ACK
)
368 } while (time_before(jiffies
, timeout
));
370 if (!(val
& AHB_AXI_BUS_HALT_ACK
)) {
371 ath10k_err(ar
, "failed to halt axi bus: %d\n", val
);
375 ath10k_dbg(ar
, ATH10K_DBG_AHB
, "axi bus halted\n");
378 static void ath10k_ahb_halt_chip(struct ath10k
*ar
)
380 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
381 u32 core_id
, glb_cfg_reg
, haltreq_reg
, haltack_reg
;
385 if (IS_ERR_OR_NULL(ar_ahb
->core_cold_rst
) ||
386 IS_ERR_OR_NULL(ar_ahb
->radio_cold_rst
) ||
387 IS_ERR_OR_NULL(ar_ahb
->radio_warm_rst
) ||
388 IS_ERR_OR_NULL(ar_ahb
->radio_srif_rst
) ||
389 IS_ERR_OR_NULL(ar_ahb
->cpu_init_rst
)) {
390 ath10k_err(ar
, "rst ctrl(s) is/are not initialized\n");
394 core_id
= ath10k_ahb_read32(ar
, ATH10K_AHB_WLAN_CORE_ID_REG
);
398 glb_cfg_reg
= ATH10K_AHB_TCSR_WIFI0_GLB_CFG
;
399 haltreq_reg
= ATH10K_AHB_TCSR_WCSS0_HALTREQ
;
400 haltack_reg
= ATH10K_AHB_TCSR_WCSS0_HALTACK
;
403 glb_cfg_reg
= ATH10K_AHB_TCSR_WIFI1_GLB_CFG
;
404 haltreq_reg
= ATH10K_AHB_TCSR_WCSS1_HALTREQ
;
405 haltack_reg
= ATH10K_AHB_TCSR_WCSS1_HALTACK
;
408 ath10k_err(ar
, "invalid core id %d found, skipping reset sequence\n",
413 ath10k_ahb_halt_axi_bus(ar
, haltreq_reg
, haltack_reg
);
415 val
= ath10k_ahb_tcsr_read32(ar
, glb_cfg_reg
);
416 val
|= TCSR_WIFIX_GLB_CFG_DISABLE_CORE_CLK
;
417 ath10k_ahb_tcsr_write32(ar
, glb_cfg_reg
, val
);
419 ret
= reset_control_assert(ar_ahb
->core_cold_rst
);
421 ath10k_err(ar
, "failed to assert core cold rst: %d\n", ret
);
424 ret
= reset_control_assert(ar_ahb
->radio_cold_rst
);
426 ath10k_err(ar
, "failed to assert radio cold rst: %d\n", ret
);
429 ret
= reset_control_assert(ar_ahb
->radio_warm_rst
);
431 ath10k_err(ar
, "failed to assert radio warm rst: %d\n", ret
);
434 ret
= reset_control_assert(ar_ahb
->radio_srif_rst
);
436 ath10k_err(ar
, "failed to assert radio srif rst: %d\n", ret
);
439 ret
= reset_control_assert(ar_ahb
->cpu_init_rst
);
441 ath10k_err(ar
, "failed to assert cpu init rst: %d\n", ret
);
444 /* Clear halt req and core clock disable req before
445 * deasserting wifi core reset.
447 val
= ath10k_ahb_tcsr_read32(ar
, haltreq_reg
);
448 val
&= ~AHB_AXI_BUS_HALT_REQ
;
449 ath10k_ahb_tcsr_write32(ar
, haltreq_reg
, val
);
451 val
= ath10k_ahb_tcsr_read32(ar
, glb_cfg_reg
);
452 val
&= ~TCSR_WIFIX_GLB_CFG_DISABLE_CORE_CLK
;
453 ath10k_ahb_tcsr_write32(ar
, glb_cfg_reg
, val
);
455 ret
= reset_control_deassert(ar_ahb
->core_cold_rst
);
457 ath10k_err(ar
, "failed to deassert core cold rst: %d\n", ret
);
459 ath10k_dbg(ar
, ATH10K_DBG_AHB
, "core %d reset done\n", core_id
);
462 static irqreturn_t
ath10k_ahb_interrupt_handler(int irq
, void *arg
)
464 struct ath10k
*ar
= arg
;
465 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
467 if (!ath10k_pci_irq_pending(ar
))
470 ath10k_pci_disable_and_clear_legacy_irq(ar
);
471 tasklet_schedule(&ar_pci
->intr_tq
);
476 static int ath10k_ahb_request_irq_legacy(struct ath10k
*ar
)
478 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
479 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
482 ret
= request_irq(ar_ahb
->irq
,
483 ath10k_ahb_interrupt_handler
,
484 IRQF_SHARED
, "ath10k_ahb", ar
);
486 ath10k_warn(ar
, "failed to request legacy irq %d: %d\n",
490 ar_pci
->oper_irq_mode
= ATH10K_PCI_IRQ_LEGACY
;
495 static void ath10k_ahb_release_irq_legacy(struct ath10k
*ar
)
497 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
499 free_irq(ar_ahb
->irq
, ar
);
502 static void ath10k_ahb_irq_disable(struct ath10k
*ar
)
504 ath10k_ce_disable_interrupts(ar
);
505 ath10k_pci_disable_and_clear_legacy_irq(ar
);
508 static int ath10k_ahb_resource_init(struct ath10k
*ar
)
510 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
511 struct platform_device
*pdev
;
513 struct resource
*res
;
519 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
521 ath10k_err(ar
, "failed to get memory resource\n");
526 ar_ahb
->mem
= devm_ioremap_resource(&pdev
->dev
, res
);
527 if (IS_ERR(ar_ahb
->mem
)) {
528 ath10k_err(ar
, "mem ioremap error\n");
529 ret
= PTR_ERR(ar_ahb
->mem
);
533 ar_ahb
->mem_len
= resource_size(res
);
535 ar_ahb
->gcc_mem
= ioremap_nocache(ATH10K_GCC_REG_BASE
,
536 ATH10K_GCC_REG_SIZE
);
537 if (!ar_ahb
->gcc_mem
) {
538 ath10k_err(ar
, "gcc mem ioremap error\n");
543 ar_ahb
->tcsr_mem
= ioremap_nocache(ATH10K_TCSR_REG_BASE
,
544 ATH10K_TCSR_REG_SIZE
);
545 if (!ar_ahb
->tcsr_mem
) {
546 ath10k_err(ar
, "tcsr mem ioremap error\n");
548 goto err_gcc_mem_unmap
;
551 ret
= dma_set_mask(&pdev
->dev
, DMA_BIT_MASK(32));
553 ath10k_err(ar
, "failed to set 32-bit dma mask: %d\n", ret
);
554 goto err_tcsr_mem_unmap
;
557 ret
= dma_set_coherent_mask(&pdev
->dev
, DMA_BIT_MASK(32));
559 ath10k_err(ar
, "failed to set 32-bit consistent dma: %d\n",
561 goto err_tcsr_mem_unmap
;
564 ret
= ath10k_ahb_clock_init(ar
);
566 goto err_tcsr_mem_unmap
;
568 ret
= ath10k_ahb_rst_ctrl_init(ar
);
570 goto err_clock_deinit
;
572 ar_ahb
->irq
= platform_get_irq_byname(pdev
, "legacy");
573 if (ar_ahb
->irq
< 0) {
574 ath10k_err(ar
, "failed to get irq number: %d\n", ar_ahb
->irq
);
575 goto err_clock_deinit
;
578 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "irq: %d\n", ar_ahb
->irq
);
580 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "mem: 0x%p mem_len: %lu gcc mem: 0x%p tcsr_mem: 0x%p\n",
581 ar_ahb
->mem
, ar_ahb
->mem_len
,
582 ar_ahb
->gcc_mem
, ar_ahb
->tcsr_mem
);
586 ath10k_ahb_clock_deinit(ar
);
589 iounmap(ar_ahb
->tcsr_mem
);
592 ar_ahb
->tcsr_mem
= NULL
;
593 iounmap(ar_ahb
->gcc_mem
);
596 ar_ahb
->gcc_mem
= NULL
;
597 devm_iounmap(&pdev
->dev
, ar_ahb
->mem
);
604 static void ath10k_ahb_resource_deinit(struct ath10k
*ar
)
606 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
609 dev
= &ar_ahb
->pdev
->dev
;
612 devm_iounmap(dev
, ar_ahb
->mem
);
615 iounmap(ar_ahb
->gcc_mem
);
617 if (ar_ahb
->tcsr_mem
)
618 iounmap(ar_ahb
->tcsr_mem
);
621 ar_ahb
->gcc_mem
= NULL
;
622 ar_ahb
->tcsr_mem
= NULL
;
624 ath10k_ahb_clock_deinit(ar
);
625 ath10k_ahb_rst_ctrl_deinit(ar
);
628 static int ath10k_ahb_prepare_device(struct ath10k
*ar
)
633 ret
= ath10k_ahb_clock_enable(ar
);
635 ath10k_err(ar
, "failed to enable clocks\n");
639 /* Clock for the target is supplied from outside of target (ie,
640 * external clock module controlled by the host). Target needs
641 * to know what frequency target cpu is configured which is needed
642 * for target internal use. Read target cpu frequency info from
643 * gcc register and write into target's scratch register where
644 * target expects this information.
646 val
= ath10k_ahb_gcc_read32(ar
, ATH10K_AHB_GCC_FEPLL_PLL_DIV
);
647 ath10k_ahb_write32(ar
, ATH10K_AHB_WIFI_SCRATCH_5_REG
, val
);
649 ret
= ath10k_ahb_release_reset(ar
);
651 goto err_clk_disable
;
653 ath10k_ahb_irq_disable(ar
);
655 ath10k_ahb_write32(ar
, FW_INDICATOR_ADDRESS
, FW_IND_HOST_READY
);
657 ret
= ath10k_pci_wait_for_target_init(ar
);
664 ath10k_ahb_halt_chip(ar
);
667 ath10k_ahb_clock_disable(ar
);
672 static int ath10k_ahb_chip_reset(struct ath10k
*ar
)
676 ath10k_ahb_halt_chip(ar
);
677 ath10k_ahb_clock_disable(ar
);
679 ret
= ath10k_ahb_prepare_device(ar
);
686 static int ath10k_ahb_wake_target_cpu(struct ath10k
*ar
)
690 addr
= SOC_CORE_BASE_ADDRESS
| CORE_CTRL_ADDRESS
;
691 val
= ath10k_ahb_read32(ar
, addr
);
692 val
|= ATH10K_AHB_CORE_CTRL_CPU_INTR_MASK
;
693 ath10k_ahb_write32(ar
, addr
, val
);
698 static int ath10k_ahb_hif_start(struct ath10k
*ar
)
700 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot ahb hif start\n");
702 ath10k_ce_enable_interrupts(ar
);
703 ath10k_pci_enable_legacy_irq(ar
);
705 ath10k_pci_rx_post(ar
);
710 static void ath10k_ahb_hif_stop(struct ath10k
*ar
)
712 struct ath10k_ahb
*ar_ahb
= ath10k_ahb_priv(ar
);
714 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot ahb hif stop\n");
716 ath10k_ahb_irq_disable(ar
);
717 synchronize_irq(ar_ahb
->irq
);
719 ath10k_pci_flush(ar
);
722 static int ath10k_ahb_hif_power_up(struct ath10k
*ar
)
726 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot ahb hif power up\n");
728 ret
= ath10k_ahb_chip_reset(ar
);
730 ath10k_err(ar
, "failed to reset chip: %d\n", ret
);
734 ret
= ath10k_pci_init_pipes(ar
);
736 ath10k_err(ar
, "failed to initialize CE: %d\n", ret
);
740 ret
= ath10k_pci_init_config(ar
);
742 ath10k_err(ar
, "failed to setup init config: %d\n", ret
);
746 ret
= ath10k_ahb_wake_target_cpu(ar
);
748 ath10k_err(ar
, "could not wake up target CPU: %d\n", ret
);
755 ath10k_pci_ce_deinit(ar
);
760 static const struct ath10k_hif_ops ath10k_ahb_hif_ops
= {
761 .tx_sg
= ath10k_pci_hif_tx_sg
,
762 .diag_read
= ath10k_pci_hif_diag_read
,
763 .diag_write
= ath10k_pci_diag_write_mem
,
764 .exchange_bmi_msg
= ath10k_pci_hif_exchange_bmi_msg
,
765 .start
= ath10k_ahb_hif_start
,
766 .stop
= ath10k_ahb_hif_stop
,
767 .map_service_to_pipe
= ath10k_pci_hif_map_service_to_pipe
,
768 .get_default_pipe
= ath10k_pci_hif_get_default_pipe
,
769 .send_complete_check
= ath10k_pci_hif_send_complete_check
,
770 .get_free_queue_number
= ath10k_pci_hif_get_free_queue_number
,
771 .power_up
= ath10k_ahb_hif_power_up
,
772 .power_down
= ath10k_pci_hif_power_down
,
773 .read32
= ath10k_ahb_read32
,
774 .write32
= ath10k_ahb_write32
,
777 static const struct ath10k_bus_ops ath10k_ahb_bus_ops
= {
778 .read32
= ath10k_ahb_read32
,
779 .write32
= ath10k_ahb_write32
,
780 .get_num_banks
= ath10k_ahb_get_num_banks
,
783 static int ath10k_ahb_probe(struct platform_device
*pdev
)
786 struct ath10k_ahb
*ar_ahb
;
787 struct ath10k_pci
*ar_pci
;
788 const struct of_device_id
*of_id
;
789 enum ath10k_hw_rev hw_rev
;
794 of_id
= of_match_device(ath10k_ahb_of_match
, &pdev
->dev
);
796 dev_err(&pdev
->dev
, "failed to find matching device tree id\n");
800 hw_rev
= (enum ath10k_hw_rev
)of_id
->data
;
802 size
= sizeof(*ar_pci
) + sizeof(*ar_ahb
);
803 ar
= ath10k_core_create(size
, &pdev
->dev
, ATH10K_BUS_AHB
,
804 hw_rev
, &ath10k_ahb_hif_ops
);
806 dev_err(&pdev
->dev
, "failed to allocate core\n");
810 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "ahb probe\n");
812 ar_pci
= ath10k_pci_priv(ar
);
813 ar_ahb
= ath10k_ahb_priv(ar
);
816 platform_set_drvdata(pdev
, ar
);
818 ret
= ath10k_ahb_resource_init(ar
);
820 goto err_core_destroy
;
823 ar_pci
->mem
= ar_ahb
->mem
;
824 ar_pci
->mem_len
= ar_ahb
->mem_len
;
826 ar_pci
->bus_ops
= &ath10k_ahb_bus_ops
;
828 ret
= ath10k_pci_setup_resource(ar
);
830 ath10k_err(ar
, "failed to setup resource: %d\n", ret
);
831 goto err_resource_deinit
;
834 ath10k_pci_init_irq_tasklets(ar
);
836 ret
= ath10k_ahb_request_irq_legacy(ar
);
840 ret
= ath10k_ahb_prepare_device(ar
);
844 ath10k_pci_ce_deinit(ar
);
846 chip_id
= ath10k_ahb_soc_read32(ar
, SOC_CHIP_ID_ADDRESS
);
847 if (chip_id
== 0xffffffff) {
848 ath10k_err(ar
, "failed to get chip id\n");
849 goto err_halt_device
;
852 ret
= ath10k_core_register(ar
, chip_id
);
854 ath10k_err(ar
, "failed to register driver core: %d\n", ret
);
855 goto err_halt_device
;
861 ath10k_ahb_halt_chip(ar
);
862 ath10k_ahb_clock_disable(ar
);
865 ath10k_ahb_release_irq_legacy(ar
);
868 ath10k_pci_free_pipes(ar
);
871 ath10k_ahb_resource_deinit(ar
);
874 ath10k_core_destroy(ar
);
875 platform_set_drvdata(pdev
, NULL
);
880 static int ath10k_ahb_remove(struct platform_device
*pdev
)
882 struct ath10k
*ar
= platform_get_drvdata(pdev
);
883 struct ath10k_ahb
*ar_ahb
;
888 ar_ahb
= ath10k_ahb_priv(ar
);
893 ath10k_dbg(ar
, ATH10K_DBG_AHB
, "ahb remove\n");
895 ath10k_core_unregister(ar
);
896 ath10k_ahb_irq_disable(ar
);
897 ath10k_ahb_release_irq_legacy(ar
);
898 ath10k_pci_release_resource(ar
);
899 ath10k_ahb_halt_chip(ar
);
900 ath10k_ahb_clock_disable(ar
);
901 ath10k_ahb_resource_deinit(ar
);
902 ath10k_core_destroy(ar
);
904 platform_set_drvdata(pdev
, NULL
);
909 static struct platform_driver ath10k_ahb_driver
= {
911 .name
= "ath10k_ahb",
912 .of_match_table
= ath10k_ahb_of_match
,
914 .probe
= ath10k_ahb_probe
,
915 .remove
= ath10k_ahb_remove
,
918 int ath10k_ahb_init(void)
922 ret
= platform_driver_register(&ath10k_ahb_driver
);
924 printk(KERN_ERR
"failed to register ath10k ahb driver: %d\n",
929 void ath10k_ahb_exit(void)
931 platform_driver_unregister(&ath10k_ahb_driver
);