source: rtems-libbsd/freebsd/sys/dev/rtwn/rtl8192c/r92c_rom.c @ 0cbb715

55-freebsd-126-freebsd-12
Last change on this file since 0cbb715 was 0cbb715, checked in by Christian Mauderer <Christian.Mauderer@…>, on 11/22/16 at 09:41:47

rtwn: Import from FreeBSD.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1#include <machine/rtems-bsd-kernel-space.h>
2
3/*      $OpenBSD: if_urtwn.c,v 1.16 2011/02/10 17:26:40 jakemsr Exp $   */
4
5/*-
6 * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
7 * Copyright (c) 2014 Kevin Lo <kevlo@FreeBSD.org>
8 * Copyright (c) 2015-2016 Andriy Voskoboinyk <avos@FreeBSD.org>
9 *
10 * Permission to use, copy, modify, and distribute this software for any
11 * purpose with or without fee is hereby granted, provided that the above
12 * copyright notice and this permission notice appear in all copies.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 */
22
23#include <sys/cdefs.h>
24__FBSDID("$FreeBSD$");
25
26#include <rtems/bsd/local/opt_wlan.h>
27
28#include <rtems/bsd/sys/param.h>
29#include <rtems/bsd/sys/lock.h>
30#include <sys/mutex.h>
31#include <sys/mbuf.h>
32#include <sys/kernel.h>
33#include <sys/socket.h>
34#include <sys/systm.h>
35#include <sys/malloc.h>
36#include <sys/queue.h>
37#include <sys/taskqueue.h>
38#include <sys/bus.h>
39#include <sys/endian.h>
40#include <sys/linker.h>
41
42#include <net/if.h>
43#include <net/ethernet.h>
44#include <net/if_media.h>
45
46#include <net80211/ieee80211_var.h>
47#include <net80211/ieee80211_radiotap.h>
48
49#include <dev/rtwn/if_rtwnreg.h>
50#include <dev/rtwn/if_rtwnvar.h>
51
52#include <dev/rtwn/if_rtwn_debug.h>
53#include <dev/rtwn/if_rtwn_efuse.h>
54
55#include <dev/rtwn/rtl8192c/r92c.h>
56#include <dev/rtwn/rtl8192c/r92c_priv.h>
57#include <dev/rtwn/rtl8192c/r92c_var.h>
58#include <dev/rtwn/rtl8192c/r92c_rom_image.h>
59
60
61static void
62r92c_set_chains(struct rtwn_softc *sc)
63{
64        struct r92c_softc *rs = sc->sc_priv;
65
66        if (rs->chip & R92C_CHIP_92C) {
67                sc->ntxchains = (rs->chip & R92C_CHIP_92C_1T2R) ? 1 : 2;
68                sc->nrxchains = 2;
69        } else {
70                sc->ntxchains = 1;
71                sc->nrxchains = 1;
72        }
73}
74
75void
76r92c_efuse_postread(struct rtwn_softc *sc)
77{
78        struct r92c_softc *rs = sc->sc_priv;
79
80        /* XXX Weird but this is what the vendor driver does. */
81        sc->next_rom_addr = 0x1fa;
82        (void) rtwn_efuse_read_next(sc, &rs->pa_setting);
83        RTWN_DPRINTF(sc, RTWN_DEBUG_ROM, "%s: PA setting=0x%x\n", __func__,
84            rs->pa_setting);
85}
86
87void
88r92c_parse_rom(struct rtwn_softc *sc, uint8_t *buf)
89{
90        struct r92c_softc *rs = sc->sc_priv;
91        struct rtwn_r92c_txpwr *rt = rs->rs_txpwr;
92        struct r92c_rom *rom = (struct r92c_rom *)buf;
93        int i, j;
94
95        rs->board_type = MS(rom->rf_opt1, R92C_ROM_RF1_BOARD_TYPE);
96        rs->regulatory = MS(rom->rf_opt1, R92C_ROM_RF1_REGULATORY);
97        RTWN_DPRINTF(sc, RTWN_DEBUG_ROM, "%s: regulatory type=%d\n",
98            __func__, rs->regulatory);
99
100        /* Need to be set before postinit() (but after preinit()). */
101        rtwn_r92c_set_name(sc);
102        r92c_set_chains(sc);
103
104        for (j = 0; j < R92C_GROUP_2G; j++) {
105                for (i = 0; i < sc->ntxchains; i++) {
106                        rt->cck_tx_pwr[i][j] = rom->cck_tx_pwr[i][j];
107                        rt->ht40_1s_tx_pwr[i][j] = rom->ht40_1s_tx_pwr[i][j];
108                }
109
110                rt->ht40_2s_tx_pwr_diff[0][j] =
111                    MS(rom->ht40_2s_tx_pwr_diff[j], LOW_PART);
112                rt->ht20_tx_pwr_diff[0][j] =
113                    RTWN_SIGN4TO8(MS(rom->ht20_tx_pwr_diff[j],
114                        LOW_PART));
115                rt->ofdm_tx_pwr_diff[0][j] =
116                    MS(rom->ofdm_tx_pwr_diff[j], LOW_PART);
117                rt->ht40_max_pwr[0][j] =
118                    MS(rom->ht40_max_pwr[j], LOW_PART);
119                rt->ht20_max_pwr[0][j] =
120                    MS(rom->ht20_max_pwr[j], LOW_PART);
121
122                if (sc->ntxchains > 1) {
123                        rt->ht40_2s_tx_pwr_diff[1][j] =
124                            MS(rom->ht40_2s_tx_pwr_diff[j], HIGH_PART);
125                        rt->ht20_tx_pwr_diff[1][j] =
126                            RTWN_SIGN4TO8(MS(rom->ht20_tx_pwr_diff[j],
127                                HIGH_PART));
128                        rt->ofdm_tx_pwr_diff[1][j] =
129                            MS(rom->ofdm_tx_pwr_diff[j], HIGH_PART);
130                        rt->ht40_max_pwr[1][j] =
131                            MS(rom->ht40_max_pwr[j], HIGH_PART);
132                        rt->ht20_max_pwr[1][j] =
133                            MS(rom->ht20_max_pwr[j], HIGH_PART);
134                }
135        }
136
137        sc->thermal_meter = MS(rom->thermal_meter, R92C_ROM_THERMAL_METER);
138        if (sc->thermal_meter == R92C_ROM_THERMAL_METER_M)
139                sc->thermal_meter = 0xff;
140        IEEE80211_ADDR_COPY(sc->sc_ic.ic_macaddr, rom->macaddr);
141}
Note: See TracBrowser for help on using the repository browser.