summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Bergamini <damien@cvs.openbsd.org>2006-11-03 19:34:57 +0000
committerDamien Bergamini <damien@cvs.openbsd.org>2006-11-03 19:34:57 +0000
commit94079122f3488a8efc9f94e814ac0d2b9b5ddf74 (patch)
treed5c6e1cf5f4d7e717c82e18b2d53865fbba919b5
parent0754ad9672a8765f576bdba8db1c9f1b9be901fa (diff)
add new code to handle the AL7230B radios.
code written by Florian Stoehr. not tested due to lack of hardware. if you happen to have an adapter with this radio please report success/ failure.
-rw-r--r--sys/dev/usb/if_zyd.c108
-rw-r--r--sys/dev/usb/if_zydreg.h72
2 files changed, 178 insertions, 2 deletions
diff --git a/sys/dev/usb/if_zyd.c b/sys/dev/usb/if_zyd.c
index b66aa51ab89..c9442c6c2ea 100644
--- a/sys/dev/usb/if_zyd.c
+++ b/sys/dev/usb/if_zyd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_zyd.c,v 1.34 2006/11/01 11:52:24 damien Exp $ */
+/* $OpenBSD: if_zyd.c,v 1.35 2006/11/03 19:34:56 damien Exp $ */
/*-
* Copyright (c) 2006 by Damien Bergamini <damien.bergamini@free.fr>
@@ -143,6 +143,9 @@ int zyd_rfmd_set_channel(struct zyd_rf *, uint8_t);
int zyd_al2230_init(struct zyd_rf *);
int zyd_al2230_switch_radio(struct zyd_rf *, int);
int zyd_al2230_set_channel(struct zyd_rf *, uint8_t);
+int zyd_al7230B_init(struct zyd_rf *);
+int zyd_al7230B_switch_radio(struct zyd_rf *, int);
+int zyd_al7230B_set_channel(struct zyd_rf *, uint8_t);
int zyd_rf_attach(struct zyd_softc *, uint8_t);
const char *zyd_rf_name(uint8_t);
int zyd_hw_init(struct zyd_softc *);
@@ -963,6 +966,104 @@ zyd_al2230_set_channel(struct zyd_rf *rf, uint8_t chan)
return 0;
}
+/*
+ * AL7230B RF methods.
+ */
+int
+zyd_al7230B_init(struct zyd_rf *rf)
+{
+#define N(a) (sizeof (a) / sizeof ((a)[0]))
+ struct zyd_softc *sc = rf->rf_sc;
+ static const struct zyd_phy_pair phyini_1[] = ZYD_AL7230B_PHY_1;
+ static const struct zyd_phy_pair phyini_2[] = ZYD_AL7230B_PHY_2;
+ static const struct zyd_phy_pair phyini_3[] = ZYD_AL7230B_PHY_3;
+ static const uint32_t rfini_1[] = ZYD_AL7230B_RF_1;
+ static const uint32_t rfini_2[] = ZYD_AL7230B_RF_2;
+ int i, error;
+
+ /* for AL7230B, PHY and RF need to be initialized in "phases" */
+
+ /* init RF-dependent PHY registers, part one */
+ for (i = 0; i < N(phyini_1); i++) {
+ error = zyd_write16(sc, phyini_1[i].reg, phyini_1[i].val);
+ if (error != 0)
+ return error;
+ }
+ /* init AL7230B radio, part one */
+ for (i = 0; i < N(rfini_1); i++) {
+ if ((error = zyd_rfwrite(sc, rfini_1[i])) != 0)
+ return error;
+ }
+ /* init RF-dependent PHY registers, part two */
+ for (i = 0; i < N(phyini_2); i++) {
+ error = zyd_write16(sc, phyini_2[i].reg, phyini_2[i].val);
+ if (error != 0)
+ return error;
+ }
+ /* init AL7230B radio, part two */
+ for (i = 0; i < N(rfini_2); i++) {
+ if ((error = zyd_rfwrite(sc, rfini_2[i])) != 0)
+ return error;
+ }
+ /* init RF-dependent PHY registers, part three */
+ for (i = 0; i < N(phyini_3); i++) {
+ error = zyd_write16(sc, phyini_3[i].reg, phyini_3[i].val);
+ if (error != 0)
+ return error;
+ }
+
+ return 0;
+#undef N
+}
+
+int
+zyd_al7230B_switch_radio(struct zyd_rf *rf, int on)
+{
+ struct zyd_softc *sc = rf->rf_sc;
+
+ (void)zyd_write16(sc, ZYD_CR11, on ? 0x00 : 0x04);
+ (void)zyd_write16(sc, ZYD_CR251, on ? 0x3f : 0x2f);
+
+ return 0;
+}
+
+int
+zyd_al7230B_set_channel(struct zyd_rf *rf, uint8_t chan)
+{
+#define N(a) (sizeof (a) / sizeof ((a)[0]))
+ struct zyd_softc *sc = rf->rf_sc;
+ static const struct {
+ uint32_t r1, r2;
+ } rfprog[] = ZYD_AL7230B_CHANTABLE;
+ static const uint32_t rfsc[] = ZYD_AL7230B_RF_SETCHANNEL;
+ int i, error;
+
+ (void)zyd_write16(sc, ZYD_CR240, 0x57);
+ (void)zyd_write16(sc, ZYD_CR251, 0x2f);
+
+ for (i = 0; i < N(rfsc); i++) {
+ if ((error = zyd_rfwrite(sc, rfsc[i])) != 0)
+ return error;
+ }
+
+ (void)zyd_write16(sc, ZYD_CR128, 0x14);
+ (void)zyd_write16(sc, ZYD_CR129, 0x12);
+ (void)zyd_write16(sc, ZYD_CR130, 0x10);
+ (void)zyd_write16(sc, ZYD_CR38, 0x38);
+ (void)zyd_write16(sc, ZYD_CR136, 0xdf);
+
+ (void)zyd_rfwrite(sc, rfprog[chan - 1].r1);
+ (void)zyd_rfwrite(sc, rfprog[chan - 1].r2);
+ (void)zyd_rfwrite(sc, 0x3c9000);
+
+ (void)zyd_write16(sc, ZYD_CR251, 0x3f);
+ (void)zyd_write16(sc, ZYD_CR203, 0x06);
+ (void)zyd_write16(sc, ZYD_CR240, 0x08);
+
+ return 0;
+#undef N
+}
+
int
zyd_rf_attach(struct zyd_softc *sc, uint8_t type)
{
@@ -983,6 +1084,11 @@ zyd_rf_attach(struct zyd_softc *sc, uint8_t type)
rf->set_channel = zyd_al2230_set_channel;
rf->width = 24; /* 24-bit RF values */
break;
+ case ZYD_RF_AL7230B:
+ rf->init = zyd_al7230B_init;
+ rf->switch_radio = zyd_al7230B_switch_radio;
+ rf->set_channel = zyd_al7230B_set_channel;
+ rf->width = 24; /* 24-bit RF values */
default:
printf("%s: sorry, radio \"%s\" is not supported yet\n",
USBDEVNAME(sc->sc_dev), zyd_rf_name(type));
diff --git a/sys/dev/usb/if_zydreg.h b/sys/dev/usb/if_zydreg.h
index 9419474f0df..365ba362602 100644
--- a/sys/dev/usb/if_zydreg.h
+++ b/sys/dev/usb/if_zydreg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_zydreg.h,v 1.13 2006/10/22 12:52:03 damien Exp $ */
+/* $OpenBSD: if_zydreg.h,v 1.14 2006/11/03 19:34:56 damien Exp $ */
/*-
* Copyright (c) 2006 by Damien Bergamini <damien.bergamini@free.fr>
@@ -601,6 +601,76 @@
{ 0x03e7c0, 0x066661, 0x00000d } \
}
+#define ZYD_AL7230B_PHY_1 \
+{ \
+ { ZYD_CR240, 0x57 }, { ZYD_CR15, 0x20 }, { ZYD_CR23, 0x40 }, \
+ { ZYD_CR24, 0x20 }, { ZYD_CR26, 0x11 }, { ZYD_CR28, 0x3e }, \
+ { ZYD_CR29, 0x00 }, { ZYD_CR44, 0x33 }, { ZYD_CR106, 0x22 }, \
+ { ZYD_CR107, 0x1a }, { ZYD_CR109, 0x09 }, { ZYD_CR110, 0x27 }, \
+ { ZYD_CR111, 0x2b }, { ZYD_CR112, 0x2b }, { ZYD_CR119, 0x0a }, \
+ { ZYD_CR122, 0xfc }, { ZYD_CR10, 0x89 }, { ZYD_CR17, 0x28 }, \
+ { ZYD_CR26, 0x93 }, { ZYD_CR34, 0x30 }, { ZYD_CR35, 0x3e }, \
+ { ZYD_CR41, 0x24 }, { ZYD_CR44, 0x32 }, { ZYD_CR46, 0x96 }, \
+ { ZYD_CR47, 0x1e }, { ZYD_CR79, 0x58 }, { ZYD_CR80, 0x30 }, \
+ { ZYD_CR81, 0x30 }, { ZYD_CR87, 0x0a }, { ZYD_CR89, 0x04 }, \
+ { ZYD_CR92, 0x0a }, { ZYD_CR99, 0x28 }, { ZYD_CR100, 0x02 }, \
+ { ZYD_CR101, 0x13 }, { ZYD_CR102, 0x27 }, { ZYD_CR106, 0x22 }, \
+ { ZYD_CR107, 0x3f }, { ZYD_CR109, 0x09 }, { ZYD_CR110, 0x1f }, \
+ { ZYD_CR111, 0x1f }, { ZYD_CR112, 0x1f }, { ZYD_CR113, 0x27 }, \
+ { ZYD_CR114, 0x27 }, { ZYD_CR115, 0x24 }, { ZYD_CR116, 0x3f }, \
+ { ZYD_CR117, 0xfa }, { ZYD_CR118, 0xfc }, { ZYD_CR119, 0x10 }, \
+ { ZYD_CR120, 0x4f }, { ZYD_CR121, 0x77 }, { ZYD_CR137, 0x88 }, \
+ { ZYD_CR138, 0xa8 }, { ZYD_CR252, 0x34 }, { ZYD_CR253, 0x34 }, \
+ { ZYD_CR251, 0x2f } \
+}
+
+#define ZYD_AL7230B_PHY_2 \
+{ \
+ { ZYD_CR251, 0x3f }, { ZYD_CR128, 0x14 }, { ZYD_CR129, 0x12 }, \
+ { ZYD_CR130, 0x10 }, { ZYD_CR38, 0x38 }, { ZYD_CR136, 0xdf } \
+}
+
+#define ZYD_AL7230B_PHY_3 \
+{ \
+ { ZYD_CR203, 0x06 }, { ZYD_CR240, 0x80 } \
+}
+
+#define ZYD_AL7230B_RF_1 \
+{ \
+ 0x09ec04, 0x8cccc8, 0x4ff821, 0xc5fbfc, 0x21ebfe, 0xafd401, \
+ 0x6cf56a, 0xe04073, 0x193d76, 0x9dd844, 0x500007, 0xd8c010, \
+ 0x3c9000, 0xbfffff, 0x700000, 0xf15d58 \
+}
+
+#define ZYD_AL7230B_RF_2 \
+{ \
+ 0xf15d59, 0xf15d5c, 0xf15d58 \
+}
+
+#define ZYD_AL7230B_RF_SETCHANNEL \
+{ \
+ 0x4ff821, 0xc5fbfc, 0x21ebfe, 0xafd401, 0x6cf56a, 0xe04073, \
+ 0x193d76, 0x9dd844, 0x500007, 0xd8c010, 0x3c9000, 0xf15d58 \
+}
+
+#define ZYD_AL7230B_CHANTABLE \
+{ \
+ { 0x09ec00, 0x8cccc8 }, \
+ { 0x09ec00, 0x8cccd8 }, \
+ { 0x09ec00, 0x8cccc0 }, \
+ { 0x09ec00, 0x8cccd0 }, \
+ { 0x05ec00, 0x8cccc8 }, \
+ { 0x05ec00, 0x8cccd8 }, \
+ { 0x05ec00, 0x8cccc0 }, \
+ { 0x05ec00, 0x8cccd0 }, \
+ { 0x0dec00, 0x8cccc8 }, \
+ { 0x0dec00, 0x8cccd8 }, \
+ { 0x0dec00, 0x8cccc0 }, \
+ { 0x0dec00, 0x8cccd0 }, \
+ { 0x03ec00, 0x8cccc8 }, \
+ { 0x03ec00, 0x866660 } \
+}
+
/*
* Control pipe requests.
*/