1 | #include <machine/rtems-bsd-kernel-space.h> |
---|
2 | |
---|
3 | /*- |
---|
4 | * Copyright (c) 2016 Andriy Voskoboinyk <avos@FreeBSD.org> |
---|
5 | * All rights reserved. |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that the following conditions |
---|
9 | * are met: |
---|
10 | * 1. Redistributions of source code must retain the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer. |
---|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
13 | * notice, this list of conditions and the following disclaimer in the |
---|
14 | * documentation and/or other materials provided with the distribution. |
---|
15 | * |
---|
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
---|
17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
---|
20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
---|
22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
---|
24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
---|
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
---|
26 | * SUCH DAMAGE. |
---|
27 | */ |
---|
28 | |
---|
29 | #include <sys/cdefs.h> |
---|
30 | __FBSDID("$FreeBSD$"); |
---|
31 | |
---|
32 | #include <rtems/bsd/local/opt_wlan.h> |
---|
33 | |
---|
34 | #include <rtems/bsd/sys/param.h> |
---|
35 | #include <rtems/bsd/sys/lock.h> |
---|
36 | #include <sys/mutex.h> |
---|
37 | #include <sys/mbuf.h> |
---|
38 | #include <sys/kernel.h> |
---|
39 | #include <sys/socket.h> |
---|
40 | #include <sys/systm.h> |
---|
41 | #include <sys/malloc.h> |
---|
42 | #include <sys/queue.h> |
---|
43 | #include <sys/taskqueue.h> |
---|
44 | #include <sys/bus.h> |
---|
45 | #include <sys/endian.h> |
---|
46 | #include <sys/linker.h> |
---|
47 | |
---|
48 | #include <net/if.h> |
---|
49 | #include <net/ethernet.h> |
---|
50 | #include <net/if_media.h> |
---|
51 | |
---|
52 | #include <net80211/ieee80211_var.h> |
---|
53 | #include <net80211/ieee80211_radiotap.h> |
---|
54 | |
---|
55 | #include <dev/rtwn/if_rtwnreg.h> |
---|
56 | #include <dev/rtwn/if_rtwnvar.h> |
---|
57 | |
---|
58 | #include <dev/rtwn/if_rtwn_debug.h> |
---|
59 | |
---|
60 | #include <dev/rtwn/rtl8812a/r12a.h> |
---|
61 | |
---|
62 | #include <dev/rtwn/rtl8821a/r21a.h> |
---|
63 | #include <dev/rtwn/rtl8821a/r21a_reg.h> |
---|
64 | #include <dev/rtwn/rtl8821a/r21a_priv.h> |
---|
65 | |
---|
66 | |
---|
67 | #ifndef RTWN_WITHOUT_UCODE |
---|
68 | int |
---|
69 | r21a_iq_calib_fw_supported(struct rtwn_softc *sc) |
---|
70 | { |
---|
71 | if (sc->fwver == 0x16) |
---|
72 | return (1); |
---|
73 | |
---|
74 | return (0); |
---|
75 | } |
---|
76 | #endif |
---|
77 | |
---|
78 | void |
---|
79 | r21a_iq_calib_sw(struct rtwn_softc *sc) |
---|
80 | { |
---|
81 | #define R21A_MAX_NRXCHAINS 2 |
---|
82 | uint32_t saved_bb_vals[nitems(r21a_iq_bb_regs)]; |
---|
83 | uint32_t saved_afe_vals[nitems(r21a_iq_afe_regs)]; |
---|
84 | uint32_t saved_rf_vals[nitems(r21a_iq_rf_regs) * R21A_MAX_NRXCHAINS]; |
---|
85 | |
---|
86 | KASSERT(sc->nrxchains <= R21A_MAX_NRXCHAINS, |
---|
87 | ("nrxchains > %d (%d)\n", R21A_MAX_NRXCHAINS, sc->nrxchains)); |
---|
88 | |
---|
89 | RTWN_DPRINTF(sc, RTWN_DEBUG_CALIB, "%s: SW IQ calibration: TODO\n", |
---|
90 | __func__); |
---|
91 | |
---|
92 | /* Save registers. */ |
---|
93 | r12a_save_bb_afe_vals(sc, saved_bb_vals, r21a_iq_bb_regs, |
---|
94 | nitems(r21a_iq_bb_regs)); |
---|
95 | r12a_save_bb_afe_vals(sc, saved_afe_vals, r21a_iq_afe_regs, |
---|
96 | nitems(r21a_iq_afe_regs)); |
---|
97 | r12a_save_rf_vals(sc, saved_rf_vals, r21a_iq_rf_regs, |
---|
98 | nitems(r21a_iq_rf_regs)); |
---|
99 | |
---|
100 | #ifdef RTWN_TODO |
---|
101 | /* Configure MAC. */ |
---|
102 | r12a_iq_config_mac(sc); |
---|
103 | r21a_iq_tx(sc); |
---|
104 | #endif |
---|
105 | |
---|
106 | /* Restore registers. */ |
---|
107 | r12a_restore_rf_vals(sc, saved_rf_vals, r21a_iq_rf_regs, |
---|
108 | nitems(r21a_iq_rf_regs)); |
---|
109 | r12a_restore_bb_afe_vals(sc, saved_afe_vals, r21a_iq_afe_regs, |
---|
110 | nitems(r21a_iq_afe_regs)); |
---|
111 | |
---|
112 | /* Select page C1. */ |
---|
113 | rtwn_bb_setbits(sc, R12A_TXAGC_TABLE_SELECT, 0, 0x80000000); |
---|
114 | |
---|
115 | rtwn_bb_write(sc, R12A_SLEEP_NAV(0), 0); |
---|
116 | rtwn_bb_write(sc, R12A_PMPD(0), 0); |
---|
117 | rtwn_bb_write(sc, 0xc88, 0); |
---|
118 | rtwn_bb_write(sc, 0xc8c, 0x3c000000); |
---|
119 | rtwn_bb_write(sc, 0xc90, 0x80); |
---|
120 | rtwn_bb_write(sc, 0xc94, 0); |
---|
121 | rtwn_bb_write(sc, 0xcc4, 0x20040000); |
---|
122 | rtwn_bb_write(sc, 0xcc8, 0x20000000); |
---|
123 | rtwn_bb_write(sc, 0xcb8, 0); |
---|
124 | |
---|
125 | r12a_restore_bb_afe_vals(sc, saved_bb_vals, r21a_iq_bb_regs, |
---|
126 | nitems(r21a_iq_bb_regs)); |
---|
127 | #undef R21A_MAX_NRXCHAINS |
---|
128 | } |
---|