2016-10-09 17:35:33 +03:00
|
|
|
/* $NetBSD: rtwphyio.c,v 1.19 2016/10/09 14:42:30 christos 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.
|
|
|
|
*
|
|
|
|
* 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 input/output with the Philips SA2400 RF front-end and
|
|
|
|
* the baseband processor built into the Realtek RTL8180.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2016-10-09 17:35:33 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: rtwphyio.c,v 1.19 2016/10/09 14:42:30 christos Exp $");
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/types.h>
|
2008-03-03 15:30:57 +03:00
|
|
|
#include <sys/device.h>
|
2004-09-26 06:29:15 +04:00
|
|
|
|
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/si4136reg.h>
|
|
|
|
#include <dev/ic/rtwvar.h>
|
|
|
|
#include <dev/ic/rtwphyio.h>
|
|
|
|
#include <dev/ic/rtwphy.h>
|
|
|
|
|
|
|
|
static int rtw_macbangbits_timeout = 100;
|
|
|
|
|
2005-01-02 07:23:03 +03:00
|
|
|
uint8_t
|
2004-09-26 06:29:15 +04:00
|
|
|
rtw_bbp_read(struct rtw_regs *regs, u_int addr)
|
|
|
|
{
|
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
|
|
|
KASSERT((addr & ~__SHIFTOUT_MASK(RTW_BB_ADDR_MASK)) == 0);
|
2004-09-26 06:29:15 +04:00
|
|
|
RTW_WRITE(regs, RTW_BB,
|
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(addr, RTW_BB_ADDR_MASK) | RTW_BB_RD_MASK | RTW_BB_WR_MASK);
|
2004-09-26 06:29:15 +04:00
|
|
|
delay(10); /* XXX */
|
|
|
|
RTW_WBR(regs, RTW_BB, RTW_BB);
|
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
|
|
|
return __SHIFTOUT(RTW_READ(regs, RTW_BB), RTW_BB_RD_MASK);
|
2004-09-26 06:29:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
rtw_bbp_write(struct rtw_regs *regs, u_int addr, u_int val)
|
|
|
|
{
|
|
|
|
#define BBP_WRITE_ITERS 50
|
|
|
|
#define BBP_WRITE_DELAY 1
|
|
|
|
int i;
|
|
|
|
uint32_t wrbbp, rdbbp;
|
|
|
|
|
2004-12-25 09:58:37 +03:00
|
|
|
RTW_DPRINTF(RTW_DEBUG_PHYIO,
|
|
|
|
("%s: bbp[%u] <- %u\n", __func__, addr, val));
|
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
|
|
|
KASSERT((addr & ~__SHIFTOUT_MASK(RTW_BB_ADDR_MASK)) == 0);
|
|
|
|
KASSERT((val & ~__SHIFTOUT_MASK(RTW_BB_WR_MASK)) == 0);
|
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
|
|
|
wrbbp = __SHIFTIN(addr, RTW_BB_ADDR_MASK) | RTW_BB_WREN |
|
2016-10-09 17:35:33 +03:00
|
|
|
__SHIFTIN(val, RTW_BB_WR_MASK) | RTW_BB_RD_MASK;
|
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
|
|
|
rdbbp = __SHIFTIN(addr, RTW_BB_ADDR_MASK) |
|
2004-09-26 06:29:15 +04:00
|
|
|
RTW_BB_WR_MASK | RTW_BB_RD_MASK;
|
|
|
|
|
2004-12-25 09:58:37 +03:00
|
|
|
RTW_DPRINTF(RTW_DEBUG_PHYIO,
|
|
|
|
("%s: rdbbp = %#08x, wrbbp = %#08x\n", __func__, rdbbp, wrbbp));
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
for (i = BBP_WRITE_ITERS; --i >= 0; ) {
|
|
|
|
RTW_RBW(regs, RTW_BB, RTW_BB);
|
|
|
|
RTW_WRITE(regs, RTW_BB, wrbbp);
|
|
|
|
RTW_SYNC(regs, RTW_BB, RTW_BB);
|
|
|
|
RTW_WRITE(regs, RTW_BB, rdbbp);
|
|
|
|
RTW_SYNC(regs, RTW_BB, RTW_BB);
|
|
|
|
delay(BBP_WRITE_DELAY); /* 1 microsecond */
|
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
|
|
|
if (__SHIFTOUT(RTW_READ(regs, RTW_BB),
|
2004-09-26 06:29:15 +04:00
|
|
|
RTW_BB_RD_MASK) == val) {
|
2004-12-25 09:58:37 +03:00
|
|
|
RTW_DPRINTF(RTW_DEBUG_PHYIO,
|
|
|
|
("%s: finished in %dus\n", __func__,
|
2004-09-26 06:29:15 +04:00
|
|
|
BBP_WRITE_DELAY * (BBP_WRITE_ITERS - i)));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
delay(BBP_WRITE_DELAY); /* again */
|
|
|
|
}
|
|
|
|
printf("%s: timeout\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Help rtw_rf_hostwrite bang bits to RF over 3-wire interface. */
|
2005-12-24 23:27:29 +03:00
|
|
|
static inline void
|
2005-01-02 07:23:03 +03:00
|
|
|
rtw_rf_hostbangbits(struct rtw_regs *regs, uint32_t bits, int lo_to_hi,
|
2004-09-26 06:29:15 +04:00
|
|
|
u_int nbits)
|
|
|
|
{
|
|
|
|
int i;
|
2005-01-02 07:23:03 +03:00
|
|
|
uint32_t mask, reg;
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
KASSERT(nbits <= 32);
|
|
|
|
|
2004-12-25 09:58:37 +03:00
|
|
|
RTW_DPRINTF(RTW_DEBUG_PHYIO,
|
|
|
|
("%s: %u bits, %#08x, %s\n", __func__, nbits, bits,
|
2004-09-26 06:29:15 +04:00
|
|
|
(lo_to_hi) ? "lo to hi" : "hi to lo"));
|
|
|
|
|
|
|
|
reg = RTW_PHYCFG_HST;
|
|
|
|
RTW_WRITE(regs, RTW_PHYCFG, reg);
|
|
|
|
RTW_SYNC(regs, RTW_PHYCFG, RTW_PHYCFG);
|
|
|
|
|
|
|
|
if (lo_to_hi)
|
|
|
|
mask = 0x1;
|
|
|
|
else
|
|
|
|
mask = 1 << (nbits - 1);
|
|
|
|
|
|
|
|
for (i = 0; i < nbits; i++) {
|
2004-12-25 09:58:37 +03:00
|
|
|
RTW_DPRINTF(RTW_DEBUG_PHYBITIO,
|
|
|
|
("%s: bits %#08x mask %#08x -> bit %#08x\n",
|
2004-09-26 06:29:15 +04:00
|
|
|
__func__, bits, mask, bits & mask));
|
|
|
|
|
|
|
|
if ((bits & mask) != 0)
|
|
|
|
reg |= RTW_PHYCFG_HST_DATA;
|
|
|
|
else
|
|
|
|
reg &= ~RTW_PHYCFG_HST_DATA;
|
|
|
|
|
|
|
|
reg |= RTW_PHYCFG_HST_CLK;
|
|
|
|
RTW_WRITE(regs, RTW_PHYCFG, reg);
|
|
|
|
RTW_SYNC(regs, RTW_PHYCFG, RTW_PHYCFG);
|
|
|
|
|
|
|
|
DELAY(2); /* arbitrary delay */
|
|
|
|
|
|
|
|
reg &= ~RTW_PHYCFG_HST_CLK;
|
|
|
|
RTW_WRITE(regs, RTW_PHYCFG, reg);
|
|
|
|
RTW_SYNC(regs, RTW_PHYCFG, RTW_PHYCFG);
|
|
|
|
|
|
|
|
if (lo_to_hi)
|
|
|
|
mask <<= 1;
|
|
|
|
else
|
|
|
|
mask >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
reg |= RTW_PHYCFG_HST_EN;
|
|
|
|
KASSERT((reg & RTW_PHYCFG_HST_CLK) == 0);
|
|
|
|
RTW_WRITE(regs, RTW_PHYCFG, reg);
|
|
|
|
RTW_SYNC(regs, RTW_PHYCFG, RTW_PHYCFG);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Help rtw_rf_macwrite: tell MAC to bang bits to RF over the 3-wire
|
|
|
|
* interface.
|
|
|
|
*/
|
2005-12-24 23:27:29 +03:00
|
|
|
static inline int
|
2005-01-02 07:23:03 +03:00
|
|
|
rtw_rf_macbangbits(struct rtw_regs *regs, uint32_t reg)
|
2004-09-26 06:29:15 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2004-12-25 09:58:37 +03:00
|
|
|
RTW_DPRINTF(RTW_DEBUG_PHY, ("%s: %#08x\n", __func__, reg));
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
RTW_WRITE(regs, RTW_PHYCFG, RTW_PHYCFG_MAC_POLL | reg);
|
|
|
|
|
|
|
|
RTW_WBR(regs, RTW_PHYCFG, RTW_PHYCFG);
|
At last, I have rtw w/ Philips RF receiving packets.
I added some sysctls to aid debugging:
* hw.rtw.debug -- enable debugging
* hw.rtw.flush_rfio -- Linux voodoo: possibly makes the MAC
"flush" bits down the serial bus to the RF
* hw.rtw.host_rfio: force the host to bang bits to the RF, instead
of the MAC banging bits
* hw.rtw.rfio_delay: after telling the MAC to bang bits to the
RF front-end, delay rfio_delay microseconds.
* hw.rtw.rfprog_fallback: there is this notion of the "RF
programming method." I believe the choice influences the
polarity/timing of the serial bus used to program the RF
front-end. I know the correct choice for Intersil/RFMD/Philips
front-ends, only. For all other front-ends, I "fallback" to
rfprog_fallback.
Make rtw_txdac_enable take an rtw_softc argument. I will probably
revert this change.
Add some Linux voodoo to rtw_continuous_tx_enable. I will probably
revert this change.
Important: add rtw_set_rfprog, which sets the correct RF programming
method. This change and the following change are probably responsible
for making the Philips RF work.
Important: RTW_CONFIG1 is an 8-bit register, treat it that way!
Important: RTW_BRSR is 16-bit, RTW_CRCOUNT, RTW_PHYDELAY, and
RTW_MSR are 8-bit: treat them that way!
Vastly simplify rtw_resume_ticks.
Note to self: set the LED state to match the power state.
Hedge against the possibility that RTW_MSR is protected as
RTW_CONFIG[0123] are, meanwhile reworking that section of rtw_init
a little.
Add sc_anaparm, which isn't used, yet....
2004-12-13 03:48:02 +03:00
|
|
|
|
2004-09-26 06:29:15 +04:00
|
|
|
for (i = rtw_macbangbits_timeout; --i >= 0; delay(1)) {
|
|
|
|
if ((RTW_READ(regs, RTW_PHYCFG) & RTW_PHYCFG_MAC_POLL) == 0) {
|
2004-12-25 09:58:37 +03:00
|
|
|
RTW_DPRINTF(RTW_DEBUG_PHY,
|
|
|
|
("%s: finished in %dus\n", __func__,
|
2004-09-26 06:29:15 +04:00
|
|
|
rtw_macbangbits_timeout - i));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
RTW_RBR(regs, RTW_PHYCFG, RTW_PHYCFG); /* XXX paranoia? */
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s: RTW_PHYCFG_MAC_POLL still set.\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-01-02 07:23:03 +03:00
|
|
|
static uint32_t
|
2006-11-16 04:32:37 +03:00
|
|
|
rtw_grf5101_host_crypt(u_int addr, uint32_t val)
|
2004-09-26 06:29:15 +04:00
|
|
|
{
|
|
|
|
/* TBD */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-01-02 07:23:03 +03:00
|
|
|
static uint32_t
|
|
|
|
rtw_grf5101_mac_crypt(u_int addr, uint32_t val)
|
2004-09-26 06:29:15 +04:00
|
|
|
{
|
2005-01-02 07:23:03 +03:00
|
|
|
uint32_t data_and_addr;
|
2004-09-26 06:29:15 +04:00
|
|
|
#define EXTRACT_NIBBLE(d, which) (((d) >> (4 * (which))) & 0xf)
|
2005-01-02 07:23:03 +03:00
|
|
|
static uint8_t caesar[16] = {0x0, 0x8, 0x4, 0xc,
|
2004-09-26 06:29:15 +04:00
|
|
|
0x2, 0xa, 0x6, 0xe,
|
|
|
|
0x1, 0x9, 0x5, 0xd,
|
|
|
|
0x3, 0xb, 0x7, 0xf};
|
|
|
|
|
|
|
|
data_and_addr = caesar[EXTRACT_NIBBLE(val, 2)] |
|
|
|
|
(caesar[EXTRACT_NIBBLE(val, 1)] << 4) |
|
|
|
|
(caesar[EXTRACT_NIBBLE(val, 0)] << 8) |
|
|
|
|
(caesar[(addr >> 1) & 0xf] << 12) |
|
|
|
|
((addr & 0x1) << 16) |
|
|
|
|
(caesar[EXTRACT_NIBBLE(val, 3)] << 24);
|
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
|
|
|
return __SHIFTIN(data_and_addr,
|
2004-09-26 06:29:15 +04:00
|
|
|
RTW_PHYCFG_MAC_PHILIPS_ADDR_MASK|RTW_PHYCFG_MAC_PHILIPS_DATA_MASK);
|
|
|
|
#undef EXTRACT_NIBBLE
|
|
|
|
}
|
|
|
|
|
2013-09-14 17:09:18 +04:00
|
|
|
#ifdef RTW_DEBUG
|
2005-12-24 23:27:29 +03:00
|
|
|
static inline const char *
|
2004-09-26 06:29:15 +04:00
|
|
|
rtw_rfchipid_string(enum rtw_rfchipid rfchipid)
|
|
|
|
{
|
|
|
|
switch (rfchipid) {
|
|
|
|
case RTW_RFCHIPID_MAXIM:
|
|
|
|
return "Maxim";
|
|
|
|
case RTW_RFCHIPID_PHILIPS:
|
|
|
|
return "Philips";
|
|
|
|
case RTW_RFCHIPID_GCT:
|
|
|
|
return "GCT";
|
|
|
|
case RTW_RFCHIPID_RFMD:
|
|
|
|
return "RFMD";
|
|
|
|
case RTW_RFCHIPID_INTERSIL:
|
|
|
|
return "Intersil";
|
|
|
|
default:
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|
2013-09-14 17:09:18 +04:00
|
|
|
#endif
|
2004-09-26 06:29:15 +04:00
|
|
|
|
|
|
|
/* Bang bits over the 3-wire interface. */
|
|
|
|
int
|
|
|
|
rtw_rf_hostwrite(struct rtw_regs *regs, enum rtw_rfchipid rfchipid,
|
2005-01-02 07:23:03 +03:00
|
|
|
u_int addr, uint32_t val)
|
2004-09-26 06:29:15 +04:00
|
|
|
{
|
|
|
|
u_int nbits;
|
|
|
|
int lo_to_hi;
|
2005-01-02 07:23:03 +03:00
|
|
|
uint32_t bits;
|
2004-09-26 06:29:15 +04:00
|
|
|
|
2004-12-25 09:58:37 +03:00
|
|
|
RTW_DPRINTF(RTW_DEBUG_PHYIO, ("%s: %s[%u] <- %#08x\n", __func__,
|
2004-09-26 06:29:15 +04:00
|
|
|
rtw_rfchipid_string(rfchipid), addr, val));
|
|
|
|
|
|
|
|
switch (rfchipid) {
|
|
|
|
case RTW_RFCHIPID_MAXIM:
|
|
|
|
nbits = 16;
|
|
|
|
lo_to_hi = 0;
|
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
|
|
|
bits = __SHIFTIN(val, MAX2820_TWI_DATA_MASK) |
|
|
|
|
__SHIFTIN(addr, MAX2820_TWI_ADDR_MASK);
|
2004-09-26 06:29:15 +04:00
|
|
|
break;
|
|
|
|
case RTW_RFCHIPID_PHILIPS:
|
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
|
|
|
KASSERT((addr & ~__SHIFTOUT_MASK(SA2400_TWI_ADDR_MASK)) == 0);
|
|
|
|
KASSERT((val & ~__SHIFTOUT_MASK(SA2400_TWI_DATA_MASK)) == 0);
|
|
|
|
bits = __SHIFTIN(val, SA2400_TWI_DATA_MASK) |
|
|
|
|
__SHIFTIN(addr, SA2400_TWI_ADDR_MASK) | SA2400_TWI_WREN;
|
2004-09-26 06:29:15 +04:00
|
|
|
nbits = 32;
|
|
|
|
lo_to_hi = 1;
|
|
|
|
break;
|
|
|
|
case RTW_RFCHIPID_GCT:
|
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
|
|
|
KASSERT((addr & ~__SHIFTOUT_MASK(SI4126_TWI_ADDR_MASK)) == 0);
|
|
|
|
KASSERT((val & ~__SHIFTOUT_MASK(SI4126_TWI_DATA_MASK)) == 0);
|
2005-12-30 01:27:17 +03:00
|
|
|
bits = rtw_grf5101_host_crypt(addr, val);
|
|
|
|
nbits = 21;
|
|
|
|
lo_to_hi = 1;
|
|
|
|
break;
|
2004-09-26 06:29:15 +04:00
|
|
|
case RTW_RFCHIPID_RFMD:
|
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
|
|
|
KASSERT((addr & ~__SHIFTOUT_MASK(SI4126_TWI_ADDR_MASK)) == 0);
|
|
|
|
KASSERT((val & ~__SHIFTOUT_MASK(SI4126_TWI_DATA_MASK)) == 0);
|
|
|
|
bits = __SHIFTIN(val, SI4126_TWI_DATA_MASK) |
|
|
|
|
__SHIFTIN(addr, SI4126_TWI_ADDR_MASK);
|
2004-09-26 06:29:15 +04:00
|
|
|
nbits = 22;
|
|
|
|
lo_to_hi = 0;
|
|
|
|
break;
|
|
|
|
case RTW_RFCHIPID_INTERSIL:
|
|
|
|
default:
|
|
|
|
printf("%s: unknown rfchipid %d\n", __func__, rfchipid);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
rtw_rf_hostbangbits(regs, bits, lo_to_hi, nbits);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t
|
|
|
|
rtw_maxim_swizzle(u_int addr, uint32_t val)
|
|
|
|
{
|
|
|
|
uint32_t hidata, lodata;
|
|
|
|
|
|
|
|
KASSERT((val & ~(RTW_MAXIM_LODATA_MASK|RTW_MAXIM_HIDATA_MASK)) == 0);
|
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
|
|
|
lodata = __SHIFTOUT(val, RTW_MAXIM_LODATA_MASK);
|
|
|
|
hidata = __SHIFTOUT(val, RTW_MAXIM_HIDATA_MASK);
|
|
|
|
return __SHIFTIN(lodata, RTW_PHYCFG_MAC_MAXIM_LODATA_MASK) |
|
|
|
|
__SHIFTIN(hidata, RTW_PHYCFG_MAC_MAXIM_HIDATA_MASK) |
|
|
|
|
__SHIFTIN(addr, RTW_PHYCFG_MAC_MAXIM_ADDR_MASK);
|
2004-09-26 06:29:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Tell the MAC what to bang over the 3-wire interface. */
|
|
|
|
int
|
|
|
|
rtw_rf_macwrite(struct rtw_regs *regs, enum rtw_rfchipid rfchipid,
|
2005-01-02 07:23:03 +03:00
|
|
|
u_int addr, uint32_t val)
|
2004-09-26 06:29:15 +04:00
|
|
|
{
|
|
|
|
uint32_t reg;
|
|
|
|
|
2004-12-25 09:58:37 +03:00
|
|
|
RTW_DPRINTF(RTW_DEBUG_PHYIO, ("%s: %s[%u] <- %#08x\n", __func__,
|
2004-09-26 06:29:15 +04:00
|
|
|
rtw_rfchipid_string(rfchipid), addr, val));
|
|
|
|
|
|
|
|
switch (rfchipid) {
|
|
|
|
case RTW_RFCHIPID_GCT:
|
|
|
|
reg = rtw_grf5101_mac_crypt(addr, val);
|
|
|
|
break;
|
|
|
|
case RTW_RFCHIPID_MAXIM:
|
|
|
|
reg = rtw_maxim_swizzle(addr, val);
|
|
|
|
break;
|
|
|
|
default: /* XXX */
|
|
|
|
case RTW_RFCHIPID_PHILIPS:
|
|
|
|
KASSERT(
|
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
|
|
|
(addr & ~__SHIFTOUT_MASK(RTW_PHYCFG_MAC_PHILIPS_ADDR_MASK)) == 0);
|
2004-09-26 06:29:15 +04:00
|
|
|
KASSERT(
|
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
|
|
|
(val & ~__SHIFTOUT_MASK(RTW_PHYCFG_MAC_PHILIPS_DATA_MASK)) == 0);
|
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
|
|
|
reg = __SHIFTIN(addr, RTW_PHYCFG_MAC_PHILIPS_ADDR_MASK) |
|
|
|
|
__SHIFTIN(val, RTW_PHYCFG_MAC_PHILIPS_DATA_MASK);
|
2004-09-26 06:29:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (rfchipid) {
|
|
|
|
case RTW_RFCHIPID_GCT:
|
|
|
|
case RTW_RFCHIPID_MAXIM:
|
|
|
|
case RTW_RFCHIPID_RFMD:
|
|
|
|
reg |= RTW_PHYCFG_MAC_RFTYPE_RFMD;
|
|
|
|
break;
|
|
|
|
case RTW_RFCHIPID_INTERSIL:
|
|
|
|
reg |= RTW_PHYCFG_MAC_RFTYPE_INTERSIL;
|
|
|
|
break;
|
|
|
|
case RTW_RFCHIPID_PHILIPS:
|
|
|
|
reg |= RTW_PHYCFG_MAC_RFTYPE_PHILIPS;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("%s: unknown rfchipid %d\n", __func__, rfchipid);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rtw_rf_macbangbits(regs, reg);
|
|
|
|
}
|