xref: /freebsd/sys/dev/rtwn/rtl8188e/r88e_rom.c (revision 0e33efe4e4b5d24e2d416938af8bc6e6e4160ec8)
1 /*	$OpenBSD: if_urtwn.c,v 1.16 2011/02/10 17:26:40 jakemsr Exp $	*/
2 
3 /*-
4  * Copyright (c) 2010 Damien Bergamini <damien.bergamini@free.fr>
5  * Copyright (c) 2014 Kevin Lo <kevlo@FreeBSD.org>
6  * Copyright (c) 2015-2016 Andriy Voskoboinyk <avos@FreeBSD.org>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #include <sys/cdefs.h>
22 __FBSDID("$FreeBSD$");
23 
24 #include "opt_wlan.h"
25 
26 #include <sys/param.h>
27 #include <sys/lock.h>
28 #include <sys/mutex.h>
29 #include <sys/mbuf.h>
30 #include <sys/kernel.h>
31 #include <sys/socket.h>
32 #include <sys/systm.h>
33 #include <sys/malloc.h>
34 #include <sys/queue.h>
35 #include <sys/taskqueue.h>
36 #include <sys/bus.h>
37 #include <sys/endian.h>
38 #include <sys/linker.h>
39 
40 #include <net/if.h>
41 #include <net/ethernet.h>
42 #include <net/if_media.h>
43 
44 #include <net80211/ieee80211_var.h>
45 #include <net80211/ieee80211_radiotap.h>
46 
47 #include <dev/rtwn/if_rtwnreg.h>
48 #include <dev/rtwn/if_rtwnvar.h>
49 
50 #include <dev/rtwn/if_rtwn_debug.h>
51 
52 #include <dev/rtwn/rtl8192c/r92c_var.h>
53 
54 #include <dev/rtwn/rtl8188e/r88e.h>
55 #include <dev/rtwn/rtl8188e/r88e_priv.h>
56 #include <dev/rtwn/rtl8188e/r88e_rom_image.h>
57 
58 
59 void
60 r88e_parse_rom(struct rtwn_softc *sc, uint8_t *buf)
61 {
62 	struct r92c_softc *rs = sc->sc_priv;
63 	struct rtwn_r88e_txpwr *rt = rs->rs_txpwr;
64 	struct r88e_rom *rom = (struct r88e_rom *)buf;
65 	int i;
66 
67 	rt->bw20_tx_pwr_diff = RTWN_SIGN4TO8(MS(rom->tx_pwr_diff, HIGH_PART));
68 	rt->ofdm_tx_pwr_diff = RTWN_SIGN4TO8(MS(rom->tx_pwr_diff, LOW_PART));
69 	for (i = 0; i < nitems(rom->cck_tx_pwr); i++)
70 		rt->cck_tx_pwr[i] = rom->cck_tx_pwr[i];
71 	for (i = 0; i < nitems(rom->ht40_tx_pwr); i++)
72 		rt->ht40_tx_pwr[i] = rom->ht40_tx_pwr[i];
73 
74 	rs->crystalcap = RTWN_GET_ROM_VAR(rom->crystalcap,
75 	    R88E_ROM_CRYSTALCAP_DEF);
76 	rs->regulatory = MS(rom->rf_board_opt, R92C_ROM_RF1_REGULATORY);
77 	rs->board_type =
78 	    MS(RTWN_GET_ROM_VAR(rom->rf_board_opt, R92C_BOARD_TYPE_DONGLE),
79 		R92C_ROM_RF1_BOARD_TYPE);
80 	RTWN_DPRINTF(sc, RTWN_DEBUG_ROM, "%s: regulatory type %d\n",
81 	    __func__,rs->regulatory);
82 
83 	sc->thermal_meter = rom->thermal_meter;
84 	IEEE80211_ADDR_COPY(sc->sc_ic.ic_macaddr, rom->macaddr);
85 }
86