Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Merge enough FreeBSD code to make RT5592 work.
details: https://anonhg.NetBSD.org/src/rev/c90ffcfbb9b3
branches: trunk
changeset: 347774:c90ffcfbb9b3
user: mlelstv <mlelstv%NetBSD.org@localhost>
date: Fri Sep 16 09:25:30 2016 +0000
description:
Merge enough FreeBSD code to make RT5592 work.
diffstat:
sys/dev/ic/rt2860reg.h | 10 +-
sys/dev/usb/if_run.c | 1339 +++++++++++++++++++++++++++++++++++++++++----
sys/dev/usb/if_runvar.h | 5 +-
sys/net80211/ieee80211.h | 11 +-
4 files changed, 1244 insertions(+), 121 deletions(-)
diffs (truncated from 1887 to 300 lines):
diff -r 61a2bd68c895 -r c90ffcfbb9b3 sys/dev/ic/rt2860reg.h
--- a/sys/dev/ic/rt2860reg.h Fri Sep 16 08:26:16 2016 +0000
+++ b/sys/dev/ic/rt2860reg.h Fri Sep 16 09:25:30 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rt2860reg.h,v 1.5 2016/07/08 01:24:53 christos Exp $ */
+/* $NetBSD: rt2860reg.h,v 1.6 2016/09/16 09:25:30 mlelstv Exp $ */
/* $OpenBSD: rt2860reg.h,v 1.32 2014/05/24 10:10:17 stsp Exp $ */
/*-
@@ -83,6 +83,8 @@
#define RT3070_LDO_CFG0 0x05d4
#define RT3070_GPIO_SWITCH 0x05dc
+
+
/* RT5592 registers */
#define RT5592_DEBUG_INDEX 0x05e8
@@ -783,6 +785,12 @@
/* possible flags for RT3053 RF register 51 */
#define RT3593_TX_LO1 (1U << 4)
+/* Possible flags for RT5390 RF register 2. */
+#define RT5390_RESCAL (1 << 7)
+
+/* Possible flags for RT5390 RF register 3. */
+#define RT5390_VCOCAL (1 << 7)
+
/* Possible flags for RT5390 BBP register 4. */
#define RT5390_MAC_IF_CTRL (1U << 6)
diff -r 61a2bd68c895 -r c90ffcfbb9b3 sys/dev/usb/if_run.c
--- a/sys/dev/usb/if_run.c Fri Sep 16 08:26:16 2016 +0000
+++ b/sys/dev/usb/if_run.c Fri Sep 16 09:25:30 2016 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_run.c,v 1.15 2016/06/10 13:27:15 ozaki-r Exp $ */
+/* $NetBSD: if_run.c,v 1.16 2016/09/16 09:25:30 mlelstv Exp $ */
/* $OpenBSD: if_run.c,v 1.90 2012/03/24 15:11:04 jsg Exp $ */
/*-
@@ -23,7 +23,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_run.c,v 1.15 2016/06/10 13:27:15 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_run.c,v 1.16 2016/09/16 09:25:30 mlelstv Exp $");
#include <sys/param.h>
#include <sys/sockio.h>
@@ -74,6 +74,8 @@
#define DPRINTFN(n, x)
#endif
+#define IEEE80211_HAS_ADDR4(wh) IEEE80211_IS_DSTODS(wh)
+
#define USB_ID(v, p) { USB_VENDOR_##v, USB_PRODUCT_##v##_##p }
static const struct usb_devno run_devs[] = {
USB_ID(ABOCOM, RT2770),
@@ -251,6 +253,7 @@
USB_ID(RALINK, RT3072),
USB_ID(RALINK, RT3370),
USB_ID(RALINK, RT3572),
+ USB_ID(RALINK, RT5572),
USB_ID(RALINK, RT8070),
USB_ID(SAMSUNG, RT2870_1),
USB_ID(SENAO, RT2870_1),
@@ -329,6 +332,8 @@
const uint8_t *, int);
static int run_set_region_4(struct run_softc *, uint16_t,
uint32_t, int);
+static int run_efuse_read(struct run_softc *, uint16_t,
+ uint16_t *, int);
static int run_efuse_read_2(struct run_softc *, uint16_t,
uint16_t *);
static int run_eeprom_read_2(struct run_softc *, uint16_t,
@@ -343,6 +348,8 @@
static int run_bbp_write(struct run_softc *, uint8_t, uint8_t);
static int run_mcu_cmd(struct run_softc *, uint8_t, uint16_t);
static const char * run_get_rf(int);
+static void run_rt3593_get_txpower(struct run_softc *);
+static void run_get_txpower(struct run_softc *);
static int run_read_eeprom(struct run_softc *);
static struct ieee80211_node *
run_node_alloc(struct ieee80211_node_table *);
@@ -378,13 +385,18 @@
static void run_watchdog(struct ifnet *);
static int run_ioctl(struct ifnet *, u_long, void *);
static void run_select_chan_group(struct run_softc *, int);
+static void run_iq_calib(struct run_softc *, u_int);
static void run_set_agc(struct run_softc *, uint8_t);
static void run_set_rx_antenna(struct run_softc *, int);
static void run_rt2870_set_chan(struct run_softc *, u_int);
static void run_rt3070_set_chan(struct run_softc *, u_int);
static void run_rt3572_set_chan(struct run_softc *, u_int);
+static void run_rt3593_set_chan(struct run_softc *, u_int);
+static void run_rt5390_set_chan(struct run_softc *, u_int);
+static void run_rt5592_set_chan(struct run_softc *, u_int);
static int run_set_chan(struct run_softc *,
struct ieee80211_channel *);
+static void run_updateprot(struct run_softc *);
static void run_enable_tsf_sync(struct run_softc *);
static void run_enable_mrr(struct run_softc *);
static void run_set_txpreamble(struct run_softc *);
@@ -395,12 +407,18 @@
static void run_updateslot(struct ifnet *);
static void run_updateslot_cb(struct run_softc *, void *);
static int8_t run_rssi2dbm(struct run_softc *, uint8_t, uint8_t);
+static void run_rt5390_bbp_init(struct run_softc *);
static int run_bbp_init(struct run_softc *);
static int run_rt3070_rf_init(struct run_softc *);
+static int run_rt3593_rf_init(struct run_softc *);
+static int run_rt5390_rf_init(struct run_softc *);
static int run_rt3070_filter_calib(struct run_softc *, uint8_t,
uint8_t, uint8_t *);
static void run_rt3070_rf_setup(struct run_softc *);
+static void run_rt3593_rf_setup(struct run_softc *);
+static void run_rt5390_rf_setup(struct run_softc *);
static int run_txrx_enable(struct run_softc *);
+static int run_adjust_freq_offset(struct run_softc *);
static int run_init(struct ifnet *);
static void run_stop(struct ifnet *, int);
#ifndef IEEE80211_STA_ONLY
@@ -419,6 +437,25 @@
uint8_t val;
} rt2860_def_bbp[] = {
RT2860_DEF_BBP
+}, rt5390_def_bbp[] = {
+ RT5390_DEF_BBP
+}, rt5592_def_bbp[] = {
+ RT5592_DEF_BBP
+};
+
+/*
+ * Default values for BBP register R196 for RT5592.
+ */
+static const uint8_t rt5592_bbp_r196[] = {
+ 0xe0, 0x1f, 0x38, 0x32, 0x08, 0x28, 0x19, 0x0a, 0xff, 0x00,
+ 0x16, 0x10, 0x10, 0x0b, 0x36, 0x2c, 0x26, 0x24, 0x42, 0x36,
+ 0x30, 0x2d, 0x4c, 0x46, 0x3d, 0x40, 0x3e, 0x42, 0x3d, 0x40,
+ 0x3c, 0x34, 0x2c, 0x2f, 0x3c, 0x35, 0x2e, 0x2a, 0x49, 0x41,
+ 0x36, 0x31, 0x30, 0x30, 0x0e, 0x0d, 0x28, 0x21, 0x1c, 0x16,
+ 0x50, 0x4a, 0x43, 0x40, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x7d, 0x14, 0x32, 0x2c, 0x36, 0x4c, 0x43, 0x2c,
+ 0x2e, 0x36, 0x30, 0x6e
};
static const struct rfprog {
@@ -434,6 +471,15 @@
RT3070_RF3052
};
+static const struct rt5592_freqs {
+ uint16_t n;
+ uint8_t k, m, r;
+} rt5592_freqs_20mhz[] = {
+ RT5592_RF5592_20MHZ
+},rt5592_freqs_40mhz[] = {
+ RT5592_RF5592_40MHZ
+};
+
static const struct {
uint8_t reg;
uint8_t val;
@@ -441,6 +487,27 @@
RT3070_DEF_RF
}, rt3572_def_rf[] = {
RT3572_DEF_RF
+},rt3593_def_rf[] = {
+ RT3593_DEF_RF
+},rt5390_def_rf[] = {
+ RT5390_DEF_RF
+},rt5392_def_rf[] = {
+ RT5392_DEF_RF
+},rt5592_def_rf[] = {
+ RT5592_DEF_RF
+},rt5592_2ghz_def_rf[] = {
+ RT5592_2GHZ_DEF_RF
+},rt5592_5ghz_def_rf[] = {
+ RT5592_5GHZ_DEF_RF
+};
+
+static const struct {
+ u_int firstchan;
+ u_int lastchan;
+ uint8_t reg;
+ uint8_t val;
+} rt5592_chan_5ghz[] = {
+ RT5592_CHAN_5GHZ
};
static int
@@ -596,7 +663,9 @@
if (sc->rf_rev == RT2860_RF_2750 ||
sc->rf_rev == RT2860_RF_2850 ||
- sc->rf_rev == RT3070_RF_3052) {
+ sc->rf_rev == RT3070_RF_3052 ||
+ sc->rf_rev == RT3070_RF_3053 ||
+ sc->rf_rev == RT5592_RF_5592) {
/* set supported .11a rates */
ic->ic_sup_rates[IEEE80211_MODE_11A] =
ieee80211_std_rateset_11a;
@@ -698,6 +767,9 @@
usbd_add_drv_event(USB_EVENT_DRIVER_DETACH, sc->sc_udev, sc->sc_dev);
+ callout_stop(&sc->scan_to);
+ callout_stop(&sc->calib_to);
+
callout_destroy(&sc->scan_to);
callout_destroy(&sc->calib_to);
@@ -872,7 +944,7 @@
return error;
if (tmp & RT2860_MCU_READY)
break;
- DELAY(1000);
+ usbd_delay_ms(sc->sc_udev, 10);
}
if (ntries == 1000) {
aprint_error_dev(sc->sc_dev,
@@ -985,9 +1057,8 @@
return error;
}
-/* Read 16-bit from eFUSE ROM (RT3070 only.) */
static int
-run_efuse_read_2(struct run_softc *sc, uint16_t addr, uint16_t *val)
+run_efuse_read(struct run_softc *sc, uint16_t addr, uint16_t *val, int count)
{
uint32_t tmp;
uint16_t reg;
@@ -996,7 +1067,8 @@
if ((error = run_read(sc, RT3070_EFUSE_CTRL, &tmp)) != 0)
return error;
- addr *= 2;
+ if (count == 2)
+ addr *= 2;
/*-
* Read one 16-byte block into registers EFUSE_DATA[0-3]:
* DATA0: F E D C
@@ -1012,7 +1084,7 @@
return error;
if (!(tmp & RT3070_EFSROM_KICK))
break;
- DELAY(2);
+ usbd_delay_ms(sc->sc_udev, 2);
}
if (ntries == 100)
return ETIMEDOUT;
@@ -1026,10 +1098,17 @@
if ((error = run_read(sc, reg, &tmp)) != 0)
return error;
- *val = (addr & 2) ? tmp >> 16 : tmp & 0xffff;
+ *val = (addr & 1) ? tmp >> 16 : tmp & 0xffff;
return 0;
}
+/* Read 16-bit from eFUSE ROM for RT3xxxx. */
+static int
+run_efuse_read_2(struct run_softc *sc, uint16_t addr, uint16_t *val)
+{
+ return (run_efuse_read(sc, addr, val, 2));
+}
+
static int
run_eeprom_read_2(struct run_softc *sc, uint16_t addr, uint16_t *val)
{
@@ -1240,10 +1319,133 @@
case RT3070_RF_3021: return "RT3021";
case RT3070_RF_3022: return "RT3022";
case RT3070_RF_3052: return "RT3052";
+ case RT3070_RF_3053: return "RT3053";
+ case RT5592_RF_5592: return "RT5592";
+ case RT5390_RF_5370: return "RT5370";
+ case RT5390_RF_5372: return "RT5372";
}
return "unknown";
}
+static void
+run_rt3593_get_txpower(struct run_softc *sc)
+{
+ uint16_t addr, val;
+ int i;
+
+ /* Read power settings for 2GHz channels. */
+ for (i = 0; i < 14; i += 2) {
+ addr = (sc->ntxchains == 3) ? RT3593_EEPROM_PWR2GHZ_BASE1 :
+ RT2860_EEPROM_PWR2GHZ_BASE1;
+ run_srom_read(sc, addr + i / 2, &val);
+ sc->txpow1[i + 0] = (int8_t)(val & 0xff);
+ sc->txpow1[i + 1] = (int8_t)(val >> 8);
+
+ addr = (sc->ntxchains == 3) ? RT3593_EEPROM_PWR2GHZ_BASE2 :
+ RT2860_EEPROM_PWR2GHZ_BASE2;
+ run_srom_read(sc, addr + i / 2, &val);
Home |
Main Index |
Thread Index |
Old Index