Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/ic add 539x support from FreeBSD (not working)
details: https://anonhg.NetBSD.org/src/rev/a3bfdcd482c0
branches: trunk
changeset: 346316:a3bfdcd482c0
user: christos <christos%NetBSD.org@localhost>
date: Thu Jul 07 01:24:16 2016 +0000
description:
add 539x support from FreeBSD (not working)
diffstat:
sys/dev/ic/rt2860.c | 340 +++++++++++++++++++++++++++++++++++++++++++++---
sys/dev/ic/rt2860reg.h | 7 +-
2 files changed, 321 insertions(+), 26 deletions(-)
diffs (truncated from 576 to 300 lines):
diff -r 05010ad9cd41 -r a3bfdcd482c0 sys/dev/ic/rt2860.c
--- a/sys/dev/ic/rt2860.c Wed Jul 06 18:03:27 2016 +0000
+++ b/sys/dev/ic/rt2860.c Thu Jul 07 01:24:16 2016 +0000
@@ -1,8 +1,10 @@
-/* $NetBSD: rt2860.c,v 1.17 2016/06/24 16:08:54 christos Exp $ */
+/* $NetBSD: rt2860.c,v 1.18 2016/07/07 01:24:16 christos Exp $ */
/* $OpenBSD: rt2860.c,v 1.90 2016/04/13 10:49:26 mpi Exp $ */
+/* $FreeBSD: head/sys/dev/ral/rt2860.c 297793 2016-04-10 23:07:00Z pfg $ */
/*-
* Copyright (c) 2007-2010 Damien Bergamini <damien.bergamini%free.fr@localhost>
+ * Copyright (c) 2012 Bernhard Schmidt <bschmidt%FreeBSD.org@localhost>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -18,12 +20,12 @@
*/
/*-
- * Ralink Technology RT2860/RT3090/RT3390/RT3562 chipset driver
+ * Ralink Technology RT2860/RT3090/RT3390/RT3562/RT5390/RT5392 chipset driver
* http://www.ralinktech.com/
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rt2860.c,v 1.17 2016/06/24 16:08:54 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rt2860.c,v 1.18 2016/07/07 01:24:16 christos Exp $");
#include <sys/param.h>
#include <sys/sockio.h>
@@ -61,6 +63,7 @@
#include <dev/pci/pcidevs.h>
+#define RAL_DEBUG
#ifdef RAL_DEBUG
#define DPRINTF(x) do { if (rt2860_debug > 0) printf x; } while (0)
#define DPRINTFN(n, x) do { if (rt2860_debug >= (n)) printf x; } while (0)
@@ -125,8 +128,11 @@
static void rt2860_select_chan_group(struct rt2860_softc *, int);
static void rt2860_set_chan(struct rt2860_softc *, u_int);
static void rt3090_set_chan(struct rt2860_softc *, u_int);
-static int rt3090_rf_init(struct rt2860_softc *);
+static void rt5390_set_chan(struct rt2860_softc *, u_int);
+static void rt3090_rf_init(struct rt2860_softc *);
+static void rt5390_rf_init(struct rt2860_softc *);
static void rt3090_rf_wakeup(struct rt2860_softc *);
+static void rt5390_rf_wakeup(struct rt2860_softc *);
static int rt3090_filter_calib(struct rt2860_softc *, uint8_t, uint8_t,
uint8_t *);
static void rt3090_rf_setup(struct rt2860_softc *);
@@ -147,6 +153,7 @@
static const char * rt2860_get_rf(uint8_t);
static int rt2860_read_eeprom(struct rt2860_softc *);
static int rt2860_bbp_init(struct rt2860_softc *);
+static int rt5390_bbp_init(struct rt2860_softc *);
static int rt2860_txrx_enable(struct rt2860_softc *);
static int rt2860_init(struct ifnet *);
static void rt2860_stop(struct ifnet *, int);
@@ -174,6 +181,8 @@
uint8_t val;
} rt2860_def_bbp[] = {
RT2860_DEF_BBP
+}, rt5390_def_bbp[] = {
+ RT5390_DEF_BBP
};
static const struct rfprog {
@@ -196,6 +205,10 @@
RT3070_DEF_RF
}, rt3572_def_rf[] = {
RT3572_DEF_RF
+}, rt5390_def_rf[] = {
+ RT5390_DEF_RF
+}, rt5392_def_rf[] = {
+ RT5392_DEF_RF
};
int
@@ -975,6 +988,7 @@
ostate = ic->ic_state;
+ DPRINTF(("ostate = %d nstate = %d\n", ostate, nstate));
if (ostate == IEEE80211_S_RUN) {
/* turn link LED off */
rt2860_set_leds(sc, RT2860_LED_RADIO);
@@ -1273,6 +1287,7 @@
uint16_t phy;
hw = RAL_READ(sc, RT2860_FS_DRX_IDX) & 0xfff;
+ DPRINTF(("rx mbuf %#x\n", hw));
while (sc->rxq.cur != hw) {
struct rt2860_rx_data *data = &sc->rxq.data[sc->rxq.cur];
struct rt2860_rxd *rxd = &sc->rxq.rxd[sc->rxq.cur];
@@ -1289,6 +1304,7 @@
if (__predict_false(rxd->flags &
htole32(RT2860_RX_CRCERR | RT2860_RX_ICVERR))) {
+ DPRINTF(("error %#x\n", rxd->flags));
ifp->if_ierrors++;
goto skip;
}
@@ -1297,6 +1313,7 @@
if (__predict_false(rxd->flags & htole32(RT2860_RX_MICERR))) {
/* report MIC failures to net80211 for TKIP */
ieee80211_notify_michael_failure(ic, wh, 0/* XXX */);
+ DPRINTF(("error2 %#x\n", rxd->flags));
ifp->if_ierrors++;
goto skip;
}
@@ -1304,11 +1321,13 @@
MGETHDR(m1, M_DONTWAIT, MT_DATA);
if (__predict_false(m1 == NULL)) {
+ DPRINTF(("error2 %#x\n", rxd->flags));
ifp->if_ierrors++;
goto skip;
}
MCLGET(m1, M_DONTWAIT);
if (__predict_false((m1->m_flags & M_EXT) == 0)) {
+ DPRINTF(("no mbuf\n"));
m_freem(m1);
ifp->if_ierrors++;
goto skip;
@@ -1322,6 +1341,7 @@
mtod(m1, void *), MCLBYTES, NULL,
BUS_DMA_READ | BUS_DMA_NOWAIT);
if (__predict_false(error != 0)) {
+ DPRINTF(("dma error %d\n", error));
m_freem(m1);
/* try to reload the old mbuf */
@@ -1485,6 +1505,7 @@
uint32_t r;
r = RAL_READ(sc, RT2860_INT_STATUS);
+ DPRINTF(("intr %#x\n", r));
if (__predict_false(r == 0xffffffff))
return 0; /* device likely went away */
if (r == 0)
@@ -2353,7 +2374,108 @@
rt3090_rf_write(sc, 7, rf | RT3070_TUNE);
}
-static int
+static void
+rt5390_set_chan(struct rt2860_softc *sc, u_int chan)
+{
+ uint8_t h20mhz, rf, tmp;
+ int8_t txpow1, txpow2;
+ int i;
+
+ /* RT5390 is 2GHz only */
+ KASSERT(chan >= 1 && chan <= 14);
+
+ /* find the settings for this channel (we know it exists) */
+ for (i = 0; rt2860_rf2850[i].chan != chan; i++);
+
+ /* use Tx power values from EEPROM */
+ txpow1 = sc->txpow1[i];
+ txpow2 = sc->txpow2[i];
+
+ rt3090_rf_write(sc, 8, rt3090_freqs[i].n);
+ rt3090_rf_write(sc, 9, rt3090_freqs[i].k & 0x0f);
+ rf = rt3090_rf_read(sc, 11);
+ rf = (rf & ~0x03) | (rt3090_freqs[i].r & 0x03);
+ rt3090_rf_write(sc, 11, rf);
+
+ rf = rt3090_rf_read(sc, 49);
+ rf = (rf & ~0x3f) | (txpow1 & 0x3f);
+ /* the valid range of the RF R49 is 0x00~0x27 */
+ if ((rf & 0x3f) > 0x27)
+ rf = (rf & ~0x3f) | 0x27;
+ rt3090_rf_write(sc, 49, rf);
+ if (sc->mac_ver == 0x5392) {
+ rf = rt3090_rf_read(sc, 50);
+ rf = (rf & ~0x3f) | (txpow2 & 0x3f);
+ /* the valid range of the RF R50 is 0x00~0x27 */
+ if ((rf & 0x3f) > 0x27)
+ rf = (rf & ~0x3f) | 0x27;
+ rt3090_rf_write(sc, 50, rf);
+ }
+
+ rf = rt3090_rf_read(sc, 1);
+ rf |= RT3070_RF_BLOCK | RT3070_PLL_PD | RT3070_RX0_PD | RT3070_TX0_PD;
+ if (sc->mac_ver == 0x5392)
+ rf |= RT3070_RX1_PD | RT3070_TX1_PD;
+ rt3090_rf_write(sc, 1, rf);
+
+ rf = rt3090_rf_read(sc, 2);
+ rt3090_rf_write(sc, 2, rf | RT3593_RESCAL);
+ DELAY(1000);
+ rt3090_rf_write(sc, 2, rf & ~RT3593_RESCAL);
+
+ rf = rt3090_rf_read(sc, 17);
+ tmp = rf;
+ rf = (rf & ~0x7f) | (sc->freq & 0x7f);
+ rf = MIN(rf, 0x5f);
+ if (tmp != rf)
+ rt2860_mcu_cmd(sc, 0x74, (tmp << 8 ) | rf, 0);
+
+ if (sc->mac_ver == 0x5390) {
+ if (chan <= 4)
+ rf = 0x73;
+ else if (chan >= 5 && chan <= 6)
+ rf = 0x63;
+ else if (chan >= 7 && chan <= 10)
+ rf = 0x53;
+ else
+ rf = 43;
+ rt3090_rf_write(sc, 55, rf);
+
+ if (chan == 1)
+ rf = 0x0c;
+ else if (chan == 2)
+ rf = 0x0b;
+ else if (chan == 3)
+ rf = 0x0a;
+ else if (chan >= 4 && chan <= 6)
+ rf = 0x09;
+ else if (chan >= 7 && chan <= 12)
+ rf = 0x08;
+ else if (chan == 13)
+ rf = 0x07;
+ else
+ rf = 0x06;
+ rt3090_rf_write(sc, 59, rf);
+ }
+
+ /* Tx/Rx h20M */
+ h20mhz = (sc->rf24_20mhz & 0x20) >> 5;
+ rf = rt3090_rf_read(sc, 30);
+ rf = (rf & ~0x06) | (h20mhz << 1) | (h20mhz << 2);
+ rt3090_rf_write(sc, 30, rf);
+
+ /* Rx BB filter VCM */
+ rf = rt3090_rf_read(sc, 30);
+ rf = (rf & ~0x18) | 0x10;
+ rt3090_rf_write(sc, 30, rf);
+
+ /* Initiate VCO calibration. */
+ rf = rt3090_rf_read(sc, 3);
+ rf |= RT3593_VCOCAL;
+ rt3090_rf_write(sc, 3, rf);
+}
+
+static void
rt3090_rf_init(struct rt2860_softc *sc)
{
uint32_t tmp;
@@ -2464,8 +2586,75 @@
rf = rt3090_rf_read(sc, 21);
rt3090_rf_write(sc, 21, rf & ~RT3070_RX_LO2);
-
- return 0;
+}
+
+static void
+rt5390_rf_init(struct rt2860_softc *sc)
+{
+ uint8_t rf, bbp;
+ int i;
+
+ rf = rt3090_rf_read(sc, 2);
+ /* Toggle RF R2 bit 7. */
+ rt3090_rf_write(sc, 2, rf | RT3593_RESCAL);
+ DELAY(1000);
+ rt3090_rf_write(sc, 2, rf & ~RT3593_RESCAL);
+
+ /* Initialize RF registers to default value. */
+ if (sc->mac_ver == 0x5392) {
+ for (i = 0; i < __arraycount(rt5392_def_rf); i++) {
+ rt3090_rf_write(sc, rt5392_def_rf[i].reg,
+ rt5392_def_rf[i].val);
+ }
+ } else {
+ for (i = 0; i < __arraycount(rt5390_def_rf); i++) {
+ rt3090_rf_write(sc, rt5390_def_rf[i].reg,
+ rt5390_def_rf[i].val);
+ }
+ }
+
+ sc->rf24_20mhz = 0x1f;
+ sc->rf24_40mhz = 0x2f;
+
+ if (sc->mac_rev < 0x0211)
+ rt3090_rf_write(sc, 27, 0x03);
+
+ /* Set led open drain enable. */
+ RAL_WRITE(sc, RT3070_OPT_14, RAL_READ(sc, RT3070_OPT_14) | 1);
+
+ RAL_WRITE(sc, RT2860_TX_SW_CFG1, 0);
+ RAL_WRITE(sc, RT2860_TX_SW_CFG2, 0);
+
+ if (sc->mac_ver == 0x5390)
+ rt3090_set_rx_antenna(sc, 0);
+
+ /* Patch RSSI inaccurate issue. */
Home |
Main Index |
Thread Index |
Old Index