2007-10-19 15:59:34 +04:00
|
|
|
/* $NetBSD: rtwphy.c,v 1.13 2007/10/19 12:00:00 ad Exp $ */
|
2004-09-26 06:29:15 +04:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2004, 2005 David Young. All rights reserved.
|
|
|
|
*
|
|
|
|
* Programmed for NetBSD by David Young.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of David Young may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior
|
|
|
|
* written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY David Young ``AS IS'' AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
|
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL David
|
|
|
|
* Young BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
|
|
|
* OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Control the Philips SA2400 RF front-end and the baseband processor
|
|
|
|
* built into the Realtek RTL8180.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2007-10-19 15:59:34 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: rtwphy.c,v 1.13 2007/10/19 12:00:00 ad Exp $");
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2007-10-19 15:59:34 +04:00
|
|
|
#include <sys/bus.h>
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
|
2005-06-22 10:14:51 +04:00
|
|
|
#include <net80211/ieee80211_netbsd.h>
|
2004-09-26 06:29:15 +04:00
|
|
|
#include <net80211/ieee80211_radiotap.h>
|
2005-06-22 10:14:51 +04:00
|
|
|
#include <net80211/ieee80211_var.h>
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
#include <dev/ic/rtwreg.h>
|
|
|
|
#include <dev/ic/max2820reg.h>
|
|
|
|
#include <dev/ic/sa2400reg.h>
|
|
|
|
#include <dev/ic/rtwvar.h>
|
|
|
|
#include <dev/ic/rtwphyio.h>
|
|
|
|
#include <dev/ic/rtwphy.h>
|
|
|
|
|
|
|
|
static int rtw_max2820_pwrstate(struct rtw_rf *, enum rtw_pwrstate);
|
|
|
|
static int rtw_sa2400_pwrstate(struct rtw_rf *, enum rtw_pwrstate);
|
|
|
|
|
2005-12-30 01:27:17 +03:00
|
|
|
#define GCT_WRITE(__gr, __addr, __val, __label) \
|
|
|
|
do { \
|
|
|
|
if (rtw_rfbus_write(&(__gr)->gr_bus, RTW_RFCHIPID_GCT, \
|
|
|
|
(__addr), (__val)) == -1) \
|
|
|
|
goto __label; \
|
|
|
|
} while(0)
|
|
|
|
|
2004-09-26 06:29:15 +04:00
|
|
|
static int
|
|
|
|
rtw_bbp_preinit(struct rtw_regs *regs, u_int antatten0, int dflantb,
|
|
|
|
u_int freq)
|
|
|
|
{
|
|
|
|
u_int antatten = antatten0;
|
|
|
|
if (dflantb)
|
|
|
|
antatten |= RTW_BBP_ANTATTEN_DFLANTB;
|
|
|
|
if (freq == 2484) /* channel 14 */
|
|
|
|
antatten |= RTW_BBP_ANTATTEN_CHAN14;
|
|
|
|
return rtw_bbp_write(regs, RTW_BBP_ANTATTEN, antatten);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rtw_bbp_init(struct rtw_regs *regs, struct rtw_bbpset *bb, int antdiv,
|
2005-01-02 07:23:03 +03:00
|
|
|
int dflantb, uint8_t cs_threshold, u_int freq)
|
2004-09-26 06:29:15 +04:00
|
|
|
{
|
|
|
|
int rc;
|
2005-01-02 07:23:03 +03:00
|
|
|
uint32_t sys2, sys3;
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
sys2 = bb->bb_sys2;
|
|
|
|
if (antdiv)
|
|
|
|
sys2 |= RTW_BBP_SYS2_ANTDIV;
|
|
|
|
sys3 = bb->bb_sys3 |
|
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).
Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.
Define __PRIxBIT and __PRIxBITS printf(3) format strings.
2006-08-31 23:24:37 +04:00
|
|
|
__SHIFTIN(cs_threshold, RTW_BBP_SYS3_CSTHRESH_MASK);
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
#define RTW_BBP_WRITE_OR_RETURN(reg, val) \
|
|
|
|
if ((rc = rtw_bbp_write(regs, reg, val)) != 0) \
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
RTW_BBP_WRITE_OR_RETURN(RTW_BBP_SYS1, bb->bb_sys1);
|
|
|
|
RTW_BBP_WRITE_OR_RETURN(RTW_BBP_TXAGC, bb->bb_txagc);
|
|
|
|
RTW_BBP_WRITE_OR_RETURN(RTW_BBP_LNADET, bb->bb_lnadet);
|
|
|
|
RTW_BBP_WRITE_OR_RETURN(RTW_BBP_IFAGCINI, bb->bb_ifagcini);
|
|
|
|
RTW_BBP_WRITE_OR_RETURN(RTW_BBP_IFAGCLIMIT, bb->bb_ifagclimit);
|
|
|
|
RTW_BBP_WRITE_OR_RETURN(RTW_BBP_IFAGCDET, bb->bb_ifagcdet);
|
|
|
|
|
|
|
|
if ((rc = rtw_bbp_preinit(regs, bb->bb_antatten, dflantb, freq)) != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
RTW_BBP_WRITE_OR_RETURN(RTW_BBP_TRL, bb->bb_trl);
|
|
|
|
RTW_BBP_WRITE_OR_RETURN(RTW_BBP_SYS2, sys2);
|
|
|
|
RTW_BBP_WRITE_OR_RETURN(RTW_BBP_SYS3, sys3);
|
|
|
|
RTW_BBP_WRITE_OR_RETURN(RTW_BBP_CHESTLIM, bb->bb_chestlim);
|
|
|
|
RTW_BBP_WRITE_OR_RETURN(RTW_BBP_CHSQLIM, bb->bb_chsqlim);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2005-01-02 07:23:03 +03:00
|
|
|
rtw_sa2400_txpower(struct rtw_rf *rf, uint8_t opaque_txpower)
|
2004-09-26 06:29:15 +04:00
|
|
|
{
|
|
|
|
struct rtw_sa2400 *sa = (struct rtw_sa2400 *)rf;
|
|
|
|
struct rtw_rfbus *bus = &sa->sa_bus;
|
|
|
|
|
|
|
|
return rtw_rfbus_write(bus, RTW_RFCHIPID_PHILIPS, SA2400_TX,
|
|
|
|
opaque_txpower);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* make sure we're using the same settings as the reference driver */
|
|
|
|
static void
|
2005-01-02 07:23:03 +03:00
|
|
|
verify_syna(u_int freq, uint32_t val)
|
2004-09-26 06:29:15 +04:00
|
|
|
{
|
2005-01-02 07:23:03 +03:00
|
|
|
uint32_t expected_val = ~val;
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
switch (freq) {
|
|
|
|
case 2412:
|
|
|
|
expected_val = 0x0000096c; /* ch 1 */
|
|
|
|
break;
|
|
|
|
case 2417:
|
|
|
|
expected_val = 0x00080970; /* ch 2 */
|
|
|
|
break;
|
|
|
|
case 2422:
|
|
|
|
expected_val = 0x00100974; /* ch 3 */
|
|
|
|
break;
|
|
|
|
case 2427:
|
|
|
|
expected_val = 0x00180978; /* ch 4 */
|
|
|
|
break;
|
|
|
|
case 2432:
|
|
|
|
expected_val = 0x00000980; /* ch 5 */
|
|
|
|
break;
|
|
|
|
case 2437:
|
|
|
|
expected_val = 0x00080984; /* ch 6 */
|
|
|
|
break;
|
|
|
|
case 2442:
|
|
|
|
expected_val = 0x00100988; /* ch 7 */
|
|
|
|
break;
|
|
|
|
case 2447:
|
|
|
|
expected_val = 0x0018098c; /* ch 8 */
|
|
|
|
break;
|
|
|
|
case 2452:
|
|
|
|
expected_val = 0x00000994; /* ch 9 */
|
|
|
|
break;
|
|
|
|
case 2457:
|
|
|
|
expected_val = 0x00080998; /* ch 10 */
|
|
|
|
break;
|
|
|
|
case 2462:
|
|
|
|
expected_val = 0x0010099c; /* ch 11 */
|
|
|
|
break;
|
|
|
|
case 2467:
|
|
|
|
expected_val = 0x001809a0; /* ch 12 */
|
|
|
|
break;
|
|
|
|
case 2472:
|
|
|
|
expected_val = 0x000009a8; /* ch 13 */
|
|
|
|
break;
|
|
|
|
case 2484:
|
|
|
|
expected_val = 0x000009b4; /* ch 14 */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
KASSERT(val == expected_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* freq is in MHz */
|
|
|
|
static int
|
|
|
|
rtw_sa2400_tune(struct rtw_rf *rf, u_int freq)
|
|
|
|
{
|
|
|
|
struct rtw_sa2400 *sa = (struct rtw_sa2400 *)rf;
|
|
|
|
struct rtw_rfbus *bus = &sa->sa_bus;
|
|
|
|
int rc;
|
2005-01-02 07:23:03 +03:00
|
|
|
uint32_t syna, synb, sync;
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
/* XO = 44MHz, R = 11, hence N is in units of XO / R = 4MHz.
|
|
|
|
*
|
|
|
|
* The channel spacing (5MHz) is not divisible by 4MHz, so
|
|
|
|
* we set the fractional part of N to compensate.
|
|
|
|
*/
|
|
|
|
int n = freq / 4, nf = (freq % 4) * 2;
|
|
|
|
|
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).
Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.
Define __PRIxBIT and __PRIxBITS printf(3) format strings.
2006-08-31 23:24:37 +04:00
|
|
|
syna = __SHIFTIN(nf, SA2400_SYNA_NF_MASK) | __SHIFTIN(n, SA2400_SYNA_N_MASK);
|
2004-09-26 06:29:15 +04:00
|
|
|
verify_syna(freq, syna);
|
|
|
|
|
|
|
|
/* Divide the 44MHz crystal down to 4MHz. Set the fractional
|
|
|
|
* compensation charge pump value to agree with the fractional
|
|
|
|
* modulus.
|
|
|
|
*/
|
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).
Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.
Define __PRIxBIT and __PRIxBITS printf(3) format strings.
2006-08-31 23:24:37 +04:00
|
|
|
synb = __SHIFTIN(11, SA2400_SYNB_R_MASK) | SA2400_SYNB_L_NORMAL |
|
2004-09-26 06:29:15 +04:00
|
|
|
SA2400_SYNB_ON | SA2400_SYNB_ONE |
|
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).
Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.
Define __PRIxBIT and __PRIxBITS printf(3) format strings.
2006-08-31 23:24:37 +04:00
|
|
|
__SHIFTIN(80, SA2400_SYNB_FC_MASK); /* agrees w/ SA2400_SYNA_FM = 0 */
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
sync = SA2400_SYNC_CP_NORMAL;
|
|
|
|
|
|
|
|
if ((rc = rtw_rfbus_write(bus, RTW_RFCHIPID_PHILIPS, SA2400_SYNA,
|
|
|
|
syna)) != 0)
|
|
|
|
return rc;
|
|
|
|
if ((rc = rtw_rfbus_write(bus, RTW_RFCHIPID_PHILIPS, SA2400_SYNB,
|
|
|
|
synb)) != 0)
|
|
|
|
return rc;
|
|
|
|
if ((rc = rtw_rfbus_write(bus, RTW_RFCHIPID_PHILIPS, SA2400_SYNC,
|
|
|
|
sync)) != 0)
|
|
|
|
return rc;
|
|
|
|
return rtw_rfbus_write(bus, RTW_RFCHIPID_PHILIPS, SA2400_SYND, 0x0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rtw_sa2400_pwrstate(struct rtw_rf *rf, enum rtw_pwrstate power)
|
|
|
|
{
|
|
|
|
struct rtw_sa2400 *sa = (struct rtw_sa2400 *)rf;
|
|
|
|
struct rtw_rfbus *bus = &sa->sa_bus;
|
2005-01-02 07:23:03 +03:00
|
|
|
uint32_t opmode;
|
Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.
Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.
Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.
Factor part of the chip-reset code into rtw_chip_reset1.
Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.
Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.
Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.
Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)
[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)
[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.
[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.
[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.
[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).
[] Call rtw_stop in rtw_detach.
2004-12-12 09:37:59 +03:00
|
|
|
opmode = SA2400_OPMODE_DEFAULTS;
|
2004-09-26 06:29:15 +04:00
|
|
|
switch (power) {
|
|
|
|
case RTW_ON:
|
|
|
|
opmode |= SA2400_OPMODE_MODE_TXRX;
|
|
|
|
break;
|
|
|
|
case RTW_SLEEP:
|
|
|
|
opmode |= SA2400_OPMODE_MODE_WAIT;
|
|
|
|
break;
|
|
|
|
case RTW_OFF:
|
|
|
|
opmode |= SA2400_OPMODE_MODE_SLEEP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sa->sa_digphy)
|
|
|
|
opmode |= SA2400_OPMODE_DIGIN;
|
|
|
|
|
|
|
|
return rtw_rfbus_write(bus, RTW_RFCHIPID_PHILIPS, SA2400_OPMODE,
|
|
|
|
opmode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rtw_sa2400_manrx_init(struct rtw_sa2400 *sa)
|
|
|
|
{
|
2005-01-02 07:23:03 +03:00
|
|
|
uint32_t manrx;
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
/* XXX we are not supposed to be in RXMGC mode when we do
|
|
|
|
* this?
|
|
|
|
*/
|
|
|
|
manrx = SA2400_MANRX_AHSN;
|
|
|
|
manrx |= SA2400_MANRX_TEN;
|
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).
Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.
Define __PRIxBIT and __PRIxBITS printf(3) format strings.
2006-08-31 23:24:37 +04:00
|
|
|
manrx |= __SHIFTIN(1023, SA2400_MANRX_RXGAIN_MASK);
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
return rtw_rfbus_write(&sa->sa_bus, RTW_RFCHIPID_PHILIPS, SA2400_MANRX,
|
|
|
|
manrx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rtw_sa2400_vcocal_start(struct rtw_sa2400 *sa, int start)
|
|
|
|
{
|
2005-01-02 07:23:03 +03:00
|
|
|
uint32_t opmode;
|
2004-09-26 06:29:15 +04:00
|
|
|
|
Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.
Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.
Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.
Factor part of the chip-reset code into rtw_chip_reset1.
Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.
Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.
Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.
Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)
[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)
[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.
[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.
[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.
[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).
[] Call rtw_stop in rtw_detach.
2004-12-12 09:37:59 +03:00
|
|
|
opmode = SA2400_OPMODE_DEFAULTS;
|
2004-09-26 06:29:15 +04:00
|
|
|
if (start)
|
|
|
|
opmode |= SA2400_OPMODE_MODE_VCOCALIB;
|
|
|
|
else
|
|
|
|
opmode |= SA2400_OPMODE_MODE_SLEEP;
|
|
|
|
|
|
|
|
if (sa->sa_digphy)
|
|
|
|
opmode |= SA2400_OPMODE_DIGIN;
|
|
|
|
|
|
|
|
return rtw_rfbus_write(&sa->sa_bus, RTW_RFCHIPID_PHILIPS, SA2400_OPMODE,
|
|
|
|
opmode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rtw_sa2400_vco_calibration(struct rtw_sa2400 *sa)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
/* calibrate VCO */
|
|
|
|
if ((rc = rtw_sa2400_vcocal_start(sa, 1)) != 0)
|
|
|
|
return rc;
|
|
|
|
DELAY(2200); /* 2.2 milliseconds */
|
|
|
|
/* XXX superfluous: SA2400 automatically entered SLEEP mode. */
|
|
|
|
return rtw_sa2400_vcocal_start(sa, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rtw_sa2400_filter_calibration(struct rtw_sa2400 *sa)
|
|
|
|
{
|
2005-01-02 07:23:03 +03:00
|
|
|
uint32_t opmode;
|
2004-09-26 06:29:15 +04:00
|
|
|
|
Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.
Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.
Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.
Factor part of the chip-reset code into rtw_chip_reset1.
Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.
Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.
Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.
Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)
[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)
[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.
[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.
[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.
[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).
[] Call rtw_stop in rtw_detach.
2004-12-12 09:37:59 +03:00
|
|
|
opmode = SA2400_OPMODE_DEFAULTS | SA2400_OPMODE_MODE_FCALIB;
|
2004-09-26 06:29:15 +04:00
|
|
|
if (sa->sa_digphy)
|
|
|
|
opmode |= SA2400_OPMODE_DIGIN;
|
|
|
|
|
|
|
|
return rtw_rfbus_write(&sa->sa_bus, RTW_RFCHIPID_PHILIPS, SA2400_OPMODE,
|
|
|
|
opmode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rtw_sa2400_dc_calibration(struct rtw_sa2400 *sa)
|
|
|
|
{
|
|
|
|
struct rtw_rf *rf = &sa->sa_rf;
|
|
|
|
int rc;
|
2005-01-02 07:23:03 +03:00
|
|
|
uint32_t dccal;
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
(*rf->rf_continuous_tx_cb)(rf->rf_continuous_tx_arg, 1);
|
|
|
|
|
Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.
Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.
Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.
Factor part of the chip-reset code into rtw_chip_reset1.
Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.
Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.
Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.
Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)
[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)
[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.
[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.
[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.
[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).
[] Call rtw_stop in rtw_detach.
2004-12-12 09:37:59 +03:00
|
|
|
dccal = SA2400_OPMODE_DEFAULTS | SA2400_OPMODE_MODE_TXRX;
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
rc = rtw_rfbus_write(&sa->sa_bus, RTW_RFCHIPID_PHILIPS, SA2400_OPMODE,
|
|
|
|
dccal);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
DELAY(5); /* DCALIB after being in Tx mode for 5
|
|
|
|
* microseconds
|
|
|
|
*/
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
dccal &= ~SA2400_OPMODE_MODE_MASK;
|
2004-09-26 06:29:15 +04:00
|
|
|
dccal |= SA2400_OPMODE_MODE_DCALIB;
|
|
|
|
|
|
|
|
rc = rtw_rfbus_write(&sa->sa_bus, RTW_RFCHIPID_PHILIPS, SA2400_OPMODE,
|
|
|
|
dccal);
|
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
DELAY(20); /* calibration takes at most 20 microseconds */
|
|
|
|
|
|
|
|
(*rf->rf_continuous_tx_cb)(rf->rf_continuous_tx_arg, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rtw_sa2400_agc_init(struct rtw_sa2400 *sa)
|
|
|
|
{
|
2005-01-02 07:23:03 +03:00
|
|
|
uint32_t agc;
|
2004-09-26 06:29:15 +04:00
|
|
|
|
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).
Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.
Define __PRIxBIT and __PRIxBITS printf(3) format strings.
2006-08-31 23:24:37 +04:00
|
|
|
agc = __SHIFTIN(25, SA2400_AGC_MAXGAIN_MASK);
|
|
|
|
agc |= __SHIFTIN(7, SA2400_AGC_BBPDELAY_MASK);
|
|
|
|
agc |= __SHIFTIN(15, SA2400_AGC_LNADELAY_MASK);
|
|
|
|
agc |= __SHIFTIN(27, SA2400_AGC_RXONDELAY_MASK);
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
return rtw_rfbus_write(&sa->sa_bus, RTW_RFCHIPID_PHILIPS, SA2400_AGC,
|
|
|
|
agc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rtw_sa2400_destroy(struct rtw_rf *rf)
|
|
|
|
{
|
|
|
|
struct rtw_sa2400 *sa = (struct rtw_sa2400 *)rf;
|
|
|
|
memset(sa, 0, sizeof(*sa));
|
|
|
|
free(sa, M_DEVBUF);
|
|
|
|
}
|
|
|
|
|
Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.
Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.
Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.
Factor part of the chip-reset code into rtw_chip_reset1.
Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.
Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.
Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.
Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)
[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)
[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.
[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.
[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.
[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).
[] Call rtw_stop in rtw_detach.
2004-12-12 09:37:59 +03:00
|
|
|
static int
|
|
|
|
rtw_sa2400_calibrate(struct rtw_rf *rf, u_int freq)
|
|
|
|
{
|
|
|
|
struct rtw_sa2400 *sa = (struct rtw_sa2400 *)rf;
|
|
|
|
int i, rc;
|
|
|
|
|
|
|
|
/* XXX reference driver calibrates VCO twice. Is it a bug? */
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if ((rc = rtw_sa2400_vco_calibration(sa)) != 0)
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
/* VCO calibration erases synthesizer registers, so re-tune */
|
|
|
|
if ((rc = rtw_sa2400_tune(rf, freq)) != 0)
|
|
|
|
return rc;
|
|
|
|
if ((rc = rtw_sa2400_filter_calibration(sa)) != 0)
|
|
|
|
return rc;
|
|
|
|
/* analog PHY needs DC calibration */
|
|
|
|
if (!sa->sa_digphy)
|
|
|
|
return rtw_sa2400_dc_calibration(sa);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-26 06:29:15 +04:00
|
|
|
static int
|
2005-01-02 07:23:03 +03:00
|
|
|
rtw_sa2400_init(struct rtw_rf *rf, u_int freq, uint8_t opaque_txpower,
|
2004-09-26 06:29:15 +04:00
|
|
|
enum rtw_pwrstate power)
|
|
|
|
{
|
|
|
|
struct rtw_sa2400 *sa = (struct rtw_sa2400 *)rf;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if ((rc = rtw_sa2400_txpower(rf, opaque_txpower)) != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* skip configuration if it's time to sleep or to power-down. */
|
|
|
|
if (power == RTW_SLEEP || power == RTW_OFF)
|
|
|
|
return rtw_sa2400_pwrstate(rf, power);
|
|
|
|
|
|
|
|
/* go to sleep for configuration */
|
|
|
|
if ((rc = rtw_sa2400_pwrstate(rf, RTW_SLEEP)) != 0)
|
|
|
|
return rc;
|
|
|
|
|
Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.
Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.
Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.
Factor part of the chip-reset code into rtw_chip_reset1.
Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.
Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.
Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.
Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)
[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)
[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.
[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.
[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.
[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).
[] Call rtw_stop in rtw_detach.
2004-12-12 09:37:59 +03:00
|
|
|
if ((rc = rtw_sa2400_tune(rf, freq)) != 0)
|
|
|
|
return rc;
|
2004-09-26 06:29:15 +04:00
|
|
|
if ((rc = rtw_sa2400_agc_init(sa)) != 0)
|
|
|
|
return rc;
|
|
|
|
if ((rc = rtw_sa2400_manrx_init(sa)) != 0)
|
|
|
|
return rc;
|
Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.
Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.
Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.
Factor part of the chip-reset code into rtw_chip_reset1.
Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.
Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.
Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.
Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)
[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)
[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.
[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.
[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.
[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).
[] Call rtw_stop in rtw_detach.
2004-12-12 09:37:59 +03:00
|
|
|
if ((rc = rtw_sa2400_calibrate(rf, freq)) != 0)
|
2004-09-26 06:29:15 +04:00
|
|
|
return rc;
|
Miscellaneous changes. Details below. Important changes flagged
with []. Using the driver with my Linksys WPC11 ver. 4, it seems
to be receiving packets for a change. The WPC11 ver. 4 has a Maxim
RF section. My no-name rtw with Philips RF section still does not
receive any packets.
Keep access-level (analog params > config[0123] registers > none)
in sc_access. Add rtw_set_access for changing the access level.
Make rtw_continuous_tx_enable and other subroutines use rtw_set_access
instead of rtw_config0123_enable and rtw_anaparm_enable.
Factor part of the chip-reset code into rtw_chip_reset1.
Change the 'struct foo (*bar)[N]'-style arguments to
'struct foo *bar'-style arguments.
Consolidate software/hardware Tx/Rx ring setup in rtw_hwring_setup,
rtw_swring_setup.
Add a new constant, SA2400_OPMODE_DEFAULTS, for the bits that we
*always* set in the SA2400 OPMODE register.
Factor some code out into rtw_sa2400_calibrate. (Inspired by the
Linux driver.)
[] When the receiver goes into underrun/overflow state, call a new
subroutine, rtw_kick() that stops the Rx/Tx processes, resets
the chip, reinitializes the Tx/Rx rings, and restarts Rx/Tx
processes. (Inspired by the Linux driver.)
[] In rtw_intr_rx, check for too-short packets before calling
ieee80211_find_rxnode. I believe this will prevent a repeat of
the MCHK exception I saw once on macppc.
[] Use seconds-elapased as well as microseconds-elapsed to set the
next "due date" for the timeout interrupt. This keeps the driver
from programming the timeout to expire too early.
[] In rtw_intr, read RTW_ISR at most 10 times, then get out. If
the interface is not enabled (RTW_F_ENABLED), then get out.
[] In rtw_stop, get out if the interface is not enabled (RTW_F_ENABLED).
Block IPL_NET interrupts. Don't read/write any registers if
the interface is invalid (RTW_F_INVALID).
[] Call rtw_stop in rtw_detach.
2004-12-12 09:37:59 +03:00
|
|
|
|
2004-09-26 06:29:15 +04:00
|
|
|
/* enter Tx/Rx mode */
|
|
|
|
return rtw_sa2400_pwrstate(rf, power);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct rtw_rf *
|
|
|
|
rtw_sa2400_create(struct rtw_regs *regs, rtw_rf_write_t rf_write, int digphy)
|
|
|
|
{
|
|
|
|
struct rtw_sa2400 *sa;
|
|
|
|
struct rtw_rfbus *bus;
|
|
|
|
struct rtw_rf *rf;
|
|
|
|
struct rtw_bbpset *bb;
|
|
|
|
|
|
|
|
sa = malloc(sizeof(*sa), M_DEVBUF, M_NOWAIT | M_ZERO);
|
|
|
|
if (sa == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
sa->sa_digphy = digphy;
|
|
|
|
|
|
|
|
rf = &sa->sa_rf;
|
|
|
|
bus = &sa->sa_bus;
|
|
|
|
|
|
|
|
rf->rf_init = rtw_sa2400_init;
|
|
|
|
rf->rf_destroy = rtw_sa2400_destroy;
|
|
|
|
rf->rf_txpower = rtw_sa2400_txpower;
|
|
|
|
rf->rf_tune = rtw_sa2400_tune;
|
|
|
|
rf->rf_pwrstate = rtw_sa2400_pwrstate;
|
|
|
|
bb = &rf->rf_bbpset;
|
|
|
|
|
|
|
|
/* XXX magic */
|
|
|
|
bb->bb_antatten = RTW_BBP_ANTATTEN_PHILIPS_MAGIC;
|
|
|
|
bb->bb_chestlim = 0x00;
|
|
|
|
bb->bb_chsqlim = 0xa0;
|
|
|
|
bb->bb_ifagcdet = 0x64;
|
|
|
|
bb->bb_ifagcini = 0x90;
|
|
|
|
bb->bb_ifagclimit = 0x1a;
|
|
|
|
bb->bb_lnadet = 0xe0;
|
|
|
|
bb->bb_sys1 = 0x98;
|
|
|
|
bb->bb_sys2 = 0x47;
|
|
|
|
bb->bb_sys3 = 0x90;
|
|
|
|
bb->bb_trl = 0x88;
|
|
|
|
bb->bb_txagc = 0x38;
|
|
|
|
|
|
|
|
bus->b_regs = regs;
|
|
|
|
bus->b_write = rf_write;
|
|
|
|
|
|
|
|
return &sa->sa_rf;
|
|
|
|
}
|
|
|
|
|
2005-12-30 01:27:17 +03:00
|
|
|
static int
|
|
|
|
rtw_grf5101_txpower(struct rtw_rf *rf, uint8_t opaque_txpower)
|
|
|
|
{
|
|
|
|
struct rtw_grf5101 *gr = (struct rtw_grf5101 *)rf;
|
|
|
|
|
|
|
|
GCT_WRITE(gr, 0x15, 0, err);
|
|
|
|
GCT_WRITE(gr, 0x06, opaque_txpower, err);
|
|
|
|
GCT_WRITE(gr, 0x15, 0x10, err);
|
|
|
|
GCT_WRITE(gr, 0x15, 0x00, err);
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rtw_grf5101_pwrstate(struct rtw_rf *rf, enum rtw_pwrstate power)
|
|
|
|
{
|
|
|
|
struct rtw_grf5101 *gr = (struct rtw_grf5101 *)rf;
|
|
|
|
switch (power) {
|
|
|
|
case RTW_OFF:
|
|
|
|
case RTW_SLEEP:
|
|
|
|
GCT_WRITE(gr, 0x07, 0x0000, err);
|
|
|
|
GCT_WRITE(gr, 0x1f, 0x0045, err);
|
|
|
|
GCT_WRITE(gr, 0x1f, 0x0005, err);
|
|
|
|
GCT_WRITE(gr, 0x00, 0x08e4, err);
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case RTW_ON:
|
|
|
|
GCT_WRITE(gr, 0x1f, 0x0001, err);
|
|
|
|
DELAY(10);
|
|
|
|
GCT_WRITE(gr, 0x1f, 0x0001, err);
|
|
|
|
DELAY(10);
|
|
|
|
GCT_WRITE(gr, 0x1f, 0x0041, err);
|
|
|
|
DELAY(10);
|
|
|
|
GCT_WRITE(gr, 0x1f, 0x0061, err);
|
|
|
|
DELAY(10);
|
|
|
|
GCT_WRITE(gr, 0x00, 0x0ae4, err);
|
|
|
|
DELAY(10);
|
|
|
|
GCT_WRITE(gr, 0x07, 0x1000, err);
|
|
|
|
DELAY(100);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rtw_grf5101_tune(struct rtw_rf *rf, u_int freq)
|
|
|
|
{
|
|
|
|
int channel;
|
|
|
|
struct rtw_grf5101 *gr = (struct rtw_grf5101 *)rf;
|
|
|
|
|
|
|
|
if (freq == 2484)
|
|
|
|
channel = 14;
|
|
|
|
else if ((channel = (freq - 2412) / 5 + 1) < 1 || channel > 13) {
|
|
|
|
RTW_DPRINTF(RTW_DEBUG_PHY,
|
|
|
|
("%s: invalid channel %d (freq %d)\n", __func__, channel,
|
|
|
|
freq));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
GCT_WRITE(gr, 0x07, 0, err);
|
|
|
|
GCT_WRITE(gr, 0x0b, channel - 1, err);
|
|
|
|
GCT_WRITE(gr, 0x07, 0x1000, err);
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rtw_grf5101_init(struct rtw_rf *rf, u_int freq, uint8_t opaque_txpower,
|
2006-11-16 04:32:37 +03:00
|
|
|
enum rtw_pwrstate power)
|
2005-12-30 01:27:17 +03:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct rtw_grf5101 *gr = (struct rtw_grf5101 *)rf;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These values have been derived from the rtl8180-sa2400
|
|
|
|
* Linux driver. It is unknown what they all do, GCT refuse
|
|
|
|
* to release any documentation so these are more than
|
|
|
|
* likely sub optimal settings
|
|
|
|
*/
|
|
|
|
|
|
|
|
GCT_WRITE(gr, 0x01, 0x1a23, err);
|
|
|
|
GCT_WRITE(gr, 0x02, 0x4971, err);
|
|
|
|
GCT_WRITE(gr, 0x03, 0x41de, err);
|
|
|
|
GCT_WRITE(gr, 0x04, 0x2d80, err);
|
|
|
|
|
|
|
|
GCT_WRITE(gr, 0x05, 0x61ff, err);
|
|
|
|
|
|
|
|
GCT_WRITE(gr, 0x06, 0x0, err);
|
|
|
|
|
|
|
|
GCT_WRITE(gr, 0x08, 0x7533, err);
|
|
|
|
GCT_WRITE(gr, 0x09, 0xc401, err);
|
|
|
|
GCT_WRITE(gr, 0x0a, 0x0, err);
|
|
|
|
GCT_WRITE(gr, 0x0c, 0x1c7, err);
|
|
|
|
GCT_WRITE(gr, 0x0d, 0x29d3, err);
|
|
|
|
GCT_WRITE(gr, 0x0e, 0x2e8, err);
|
|
|
|
GCT_WRITE(gr, 0x10, 0x192, err);
|
|
|
|
GCT_WRITE(gr, 0x11, 0x248, err);
|
|
|
|
GCT_WRITE(gr, 0x12, 0x0, err);
|
|
|
|
GCT_WRITE(gr, 0x13, 0x20c4, err);
|
|
|
|
GCT_WRITE(gr, 0x14, 0xf4fc, err);
|
|
|
|
GCT_WRITE(gr, 0x15, 0x0, err);
|
|
|
|
GCT_WRITE(gr, 0x16, 0x1500, err);
|
|
|
|
|
|
|
|
if ((rc = rtw_grf5101_txpower(rf, opaque_txpower)) != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if ((rc = rtw_grf5101_tune(rf, freq)) != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rtw_grf5101_destroy(struct rtw_rf *rf)
|
|
|
|
{
|
|
|
|
struct rtw_grf5101 *gr = (struct rtw_grf5101 *)rf;
|
|
|
|
memset(gr, 0, sizeof(*gr));
|
|
|
|
free(gr, M_DEVBUF);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct rtw_rf *
|
2006-10-12 05:30:41 +04:00
|
|
|
rtw_grf5101_create(struct rtw_regs *regs, rtw_rf_write_t rf_write,
|
2006-11-16 04:32:37 +03:00
|
|
|
int digphy)
|
2005-12-30 01:27:17 +03:00
|
|
|
{
|
|
|
|
struct rtw_grf5101 *gr;
|
|
|
|
struct rtw_rfbus *bus;
|
|
|
|
struct rtw_rf *rf;
|
|
|
|
struct rtw_bbpset *bb;
|
|
|
|
|
|
|
|
gr = malloc(sizeof(*gr), M_DEVBUF, M_NOWAIT | M_ZERO);
|
|
|
|
if (gr == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
rf = &gr->gr_rf;
|
|
|
|
bus = &gr->gr_bus;
|
|
|
|
|
|
|
|
rf->rf_init = rtw_grf5101_init;
|
|
|
|
rf->rf_destroy = rtw_grf5101_destroy;
|
|
|
|
rf->rf_txpower = rtw_grf5101_txpower;
|
|
|
|
rf->rf_tune = rtw_grf5101_tune;
|
|
|
|
rf->rf_pwrstate = rtw_grf5101_pwrstate;
|
|
|
|
bb = &rf->rf_bbpset;
|
|
|
|
|
|
|
|
/* XXX magic */
|
|
|
|
bb->bb_antatten = RTW_BBP_ANTATTEN_GCT_MAGIC;
|
|
|
|
bb->bb_chestlim = 0x00;
|
|
|
|
bb->bb_chsqlim = 0xa0;
|
|
|
|
bb->bb_ifagcdet = 0x64;
|
|
|
|
bb->bb_ifagcini = 0x90;
|
|
|
|
bb->bb_ifagclimit = 0x1e;
|
|
|
|
bb->bb_lnadet = 0xc0;
|
|
|
|
bb->bb_sys1 = 0xa8;
|
|
|
|
bb->bb_sys2 = 0x47;
|
|
|
|
bb->bb_sys3 = 0x9b;
|
|
|
|
bb->bb_trl = 0x88;
|
|
|
|
bb->bb_txagc = 0x08;
|
|
|
|
|
|
|
|
bus->b_regs = regs;
|
|
|
|
bus->b_write = rf_write;
|
|
|
|
|
|
|
|
return &gr->gr_rf;
|
|
|
|
}
|
|
|
|
|
2004-09-26 06:29:15 +04:00
|
|
|
/* freq is in MHz */
|
|
|
|
static int
|
|
|
|
rtw_max2820_tune(struct rtw_rf *rf, u_int freq)
|
|
|
|
{
|
|
|
|
struct rtw_max2820 *mx = (struct rtw_max2820 *)rf;
|
|
|
|
struct rtw_rfbus *bus = &mx->mx_bus;
|
|
|
|
|
|
|
|
if (freq < 2400 || freq > 2499)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return rtw_rfbus_write(bus, RTW_RFCHIPID_MAXIM, MAX2820_CHANNEL,
|
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).
Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.
Define __PRIxBIT and __PRIxBITS printf(3) format strings.
2006-08-31 23:24:37 +04:00
|
|
|
__SHIFTIN(freq - 2400, MAX2820_CHANNEL_CF_MASK));
|
2004-09-26 06:29:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
rtw_max2820_destroy(struct rtw_rf *rf)
|
|
|
|
{
|
|
|
|
struct rtw_max2820 *mx = (struct rtw_max2820 *)rf;
|
|
|
|
memset(mx, 0, sizeof(*mx));
|
|
|
|
free(mx, M_DEVBUF);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
rtw_max2820_init(struct rtw_rf *rf, u_int freq, uint8_t opaque_txpower,
|
2004-09-26 06:29:15 +04:00
|
|
|
enum rtw_pwrstate power)
|
|
|
|
{
|
|
|
|
struct rtw_max2820 *mx = (struct rtw_max2820 *)rf;
|
|
|
|
struct rtw_rfbus *bus = &mx->mx_bus;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if ((rc = rtw_rfbus_write(bus, RTW_RFCHIPID_MAXIM, MAX2820_TEST,
|
|
|
|
MAX2820_TEST_DEFAULT)) != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if ((rc = rtw_rfbus_write(bus, RTW_RFCHIPID_MAXIM, MAX2820_ENABLE,
|
|
|
|
MAX2820_ENABLE_DEFAULT)) != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* skip configuration if it's time to sleep or to power-down. */
|
|
|
|
if ((rc = rtw_max2820_pwrstate(rf, power)) != 0)
|
|
|
|
return rc;
|
|
|
|
else if (power == RTW_OFF || power == RTW_SLEEP)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if ((rc = rtw_rfbus_write(bus, RTW_RFCHIPID_MAXIM, MAX2820_SYNTH,
|
|
|
|
MAX2820_SYNTH_R_44MHZ)) != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
if ((rc = rtw_max2820_tune(rf, freq)) != 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* XXX The MAX2820 datasheet indicates that 1C and 2C should not
|
|
|
|
* be changed from 7, however, the reference driver sets them
|
|
|
|
* to 4 and 1, respectively.
|
|
|
|
*/
|
|
|
|
if ((rc = rtw_rfbus_write(bus, RTW_RFCHIPID_MAXIM, MAX2820_RECEIVE,
|
|
|
|
MAX2820_RECEIVE_DL_DEFAULT |
|
Per discussion on tech-kern and tech-userlevel, move the bit-twiddling
macros, __BIT, __BITS, SHIFTIN, SHIFTOUT, and __arraycount() from
lib/libkern/libkern.h to sys/cdefs.h. Add a __-prefix to SHIFTIN
and SHIFTOUT, and add a manual page for the bit-twiddling macros,
bits(3).
Make the __BIT and __BITS macros "widthless," as best I can, by
changing their type to uintmax_t from uint32_t. XXX The manual
page lags this change by a bit.
Define __PRIxBIT and __PRIxBITS printf(3) format strings.
2006-08-31 23:24:37 +04:00
|
|
|
__SHIFTIN(4, MAX2820A_RECEIVE_1C_MASK) |
|
|
|
|
__SHIFTIN(1, MAX2820A_RECEIVE_2C_MASK))) != 0)
|
2004-09-26 06:29:15 +04:00
|
|
|
return rc;
|
|
|
|
|
|
|
|
return rtw_rfbus_write(bus, RTW_RFCHIPID_MAXIM, MAX2820_TRANSMIT,
|
|
|
|
MAX2820_TRANSMIT_PA_DEFAULT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-11-16 04:32:37 +03:00
|
|
|
rtw_max2820_txpower(struct rtw_rf *rf, uint8_t opaque_txpower)
|
2004-09-26 06:29:15 +04:00
|
|
|
{
|
|
|
|
/* TBD */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
rtw_max2820_pwrstate(struct rtw_rf *rf, enum rtw_pwrstate power)
|
|
|
|
{
|
|
|
|
uint32_t enable;
|
|
|
|
struct rtw_max2820 *mx;
|
|
|
|
struct rtw_rfbus *bus;
|
|
|
|
|
|
|
|
mx = (struct rtw_max2820 *)rf;
|
|
|
|
bus = &mx->mx_bus;
|
|
|
|
|
|
|
|
switch (power) {
|
|
|
|
case RTW_OFF:
|
|
|
|
case RTW_SLEEP:
|
|
|
|
default:
|
|
|
|
enable = 0x0;
|
|
|
|
break;
|
|
|
|
case RTW_ON:
|
|
|
|
enable = MAX2820_ENABLE_DEFAULT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rtw_rfbus_write(bus, RTW_RFCHIPID_MAXIM, MAX2820_ENABLE, enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct rtw_rf *
|
|
|
|
rtw_max2820_create(struct rtw_regs *regs, rtw_rf_write_t rf_write, int is_a)
|
|
|
|
{
|
|
|
|
struct rtw_max2820 *mx;
|
|
|
|
struct rtw_rfbus *bus;
|
|
|
|
struct rtw_rf *rf;
|
|
|
|
struct rtw_bbpset *bb;
|
|
|
|
|
|
|
|
mx = malloc(sizeof(*mx), M_DEVBUF, M_NOWAIT | M_ZERO);
|
|
|
|
if (mx == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
mx->mx_is_a = is_a;
|
|
|
|
|
|
|
|
rf = &mx->mx_rf;
|
|
|
|
bus = &mx->mx_bus;
|
|
|
|
|
|
|
|
rf->rf_init = rtw_max2820_init;
|
|
|
|
rf->rf_destroy = rtw_max2820_destroy;
|
|
|
|
rf->rf_txpower = rtw_max2820_txpower;
|
|
|
|
rf->rf_tune = rtw_max2820_tune;
|
|
|
|
rf->rf_pwrstate = rtw_max2820_pwrstate;
|
|
|
|
bb = &rf->rf_bbpset;
|
|
|
|
|
|
|
|
/* XXX magic */
|
|
|
|
bb->bb_antatten = RTW_BBP_ANTATTEN_MAXIM_MAGIC;
|
|
|
|
bb->bb_chestlim = 0;
|
|
|
|
bb->bb_chsqlim = 159;
|
|
|
|
bb->bb_ifagcdet = 100;
|
|
|
|
bb->bb_ifagcini = 144;
|
|
|
|
bb->bb_ifagclimit = 26;
|
|
|
|
bb->bb_lnadet = 248;
|
|
|
|
bb->bb_sys1 = 136;
|
|
|
|
bb->bb_sys2 = 71;
|
|
|
|
bb->bb_sys3 = 155;
|
|
|
|
bb->bb_trl = 136;
|
|
|
|
bb->bb_txagc = 8;
|
|
|
|
|
|
|
|
bus->b_regs = regs;
|
|
|
|
bus->b_write = rf_write;
|
|
|
|
|
|
|
|
return &mx->mx_rf;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* freq is in MHz */
|
|
|
|
int
|
2005-01-02 07:23:03 +03:00
|
|
|
rtw_phy_init(struct rtw_regs *regs, struct rtw_rf *rf, uint8_t opaque_txpower,
|
|
|
|
uint8_t cs_threshold, u_int freq, int antdiv, int dflantb,
|
2004-09-26 06:29:15 +04:00
|
|
|
enum rtw_pwrstate power)
|
|
|
|
{
|
|
|
|
int rc;
|
2004-12-25 09:58:37 +03:00
|
|
|
RTW_DPRINTF(RTW_DEBUG_PHY,
|
|
|
|
("%s: txpower %u csthresh %u freq %u antdiv %u dflantb %u "
|
|
|
|
"pwrstate %s\n", __func__, opaque_txpower, cs_threshold, freq,
|
|
|
|
antdiv, dflantb, rtw_pwrstate_string(power)));
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
/* XXX is this really necessary? */
|
|
|
|
if ((rc = rtw_rf_txpower(rf, opaque_txpower)) != 0)
|
|
|
|
return rc;
|
|
|
|
if ((rc = rtw_bbp_preinit(regs, rf->rf_bbpset.bb_antatten, dflantb,
|
|
|
|
freq)) != 0)
|
|
|
|
return rc;
|
|
|
|
if ((rc = rtw_rf_tune(rf, freq)) != 0)
|
|
|
|
return rc;
|
|
|
|
/* initialize RF */
|
|
|
|
if ((rc = rtw_rf_init(rf, freq, opaque_txpower, power)) != 0)
|
|
|
|
return rc;
|
|
|
|
#if 0 /* what is this redundant tx power setting here for? */
|
|
|
|
if ((rc = rtw_rf_txpower(rf, opaque_txpower)) != 0)
|
|
|
|
return rc;
|
|
|
|
#endif
|
|
|
|
return rtw_bbp_init(regs, &rf->rf_bbpset, antdiv, dflantb,
|
|
|
|
cs_threshold, freq);
|
|
|
|
}
|