// SPDX-License-Identifier: GPL-2.0-or-later
/* ZD1211 USB-WLAN driver for Linux
*
* Copyright (C) 2005-2007 Ulrich Kunitz <kune@deine-taler.de>
* Copyright (C) 2006-2007 Daniel Drake <dsd@gentoo.org>
*/
#include <linux/kernel.h>
#include "zd_rf.h"
#include "zd_usb.h"
#include "zd_chip.h"
#define IS_AL2230S(chip) ((chip)->al2230s_bit || (chip)->rf.type == AL2230S_RF)
static const u32 zd1211_al2230_table[][3 ] = {
RF_CHANNEL( 1 ) = { 0 x03f790, 0 x033331, 0 x00000d, },
RF_CHANNEL( 2 ) = { 0 x03f790, 0 x0b3331, 0 x00000d, },
RF_CHANNEL( 3 ) = { 0 x03e790, 0 x033331, 0 x00000d, },
RF_CHANNEL( 4 ) = { 0 x03e790, 0 x0b3331, 0 x00000d, },
RF_CHANNEL( 5 ) = { 0 x03f7a0, 0 x033331, 0 x00000d, },
RF_CHANNEL( 6 ) = { 0 x03f7a0, 0 x0b3331, 0 x00000d, },
RF_CHANNEL( 7 ) = { 0 x03e7a0, 0 x033331, 0 x00000d, },
RF_CHANNEL( 8 ) = { 0 x03e7a0, 0 x0b3331, 0 x00000d, },
RF_CHANNEL( 9 ) = { 0 x03f7b0, 0 x033331, 0 x00000d, },
RF_CHANNEL(10 ) = { 0 x03f7b0, 0 x0b3331, 0 x00000d, },
RF_CHANNEL(11 ) = { 0 x03e7b0, 0 x033331, 0 x00000d, },
RF_CHANNEL(12 ) = { 0 x03e7b0, 0 x0b3331, 0 x00000d, },
RF_CHANNEL(13 ) = { 0 x03f7c0, 0 x033331, 0 x00000d, },
RF_CHANNEL(14 ) = { 0 x03e7c0, 0 x066661, 0 x00000d, },
};
static const u32 zd1211b_al2230_table[][3 ] = {
RF_CHANNEL( 1 ) = { 0 x09efc0, 0 x8cccc0, 0 xb00000, },
RF_CHANNEL( 2 ) = { 0 x09efc0, 0 x8cccd0, 0 xb00000, },
RF_CHANNEL( 3 ) = { 0 x09e7c0, 0 x8cccc0, 0 xb00000, },
RF_CHANNEL( 4 ) = { 0 x09e7c0, 0 x8cccd0, 0 xb00000, },
RF_CHANNEL( 5 ) = { 0 x05efc0, 0 x8cccc0, 0 xb00000, },
RF_CHANNEL( 6 ) = { 0 x05efc0, 0 x8cccd0, 0 xb00000, },
RF_CHANNEL( 7 ) = { 0 x05e7c0, 0 x8cccc0, 0 xb00000, },
RF_CHANNEL( 8 ) = { 0 x05e7c0, 0 x8cccd0, 0 xb00000, },
RF_CHANNEL( 9 ) = { 0 x0defc0, 0 x8cccc0, 0 xb00000, },
RF_CHANNEL(10 ) = { 0 x0defc0, 0 x8cccd0, 0 xb00000, },
RF_CHANNEL(11 ) = { 0 x0de7c0, 0 x8cccc0, 0 xb00000, },
RF_CHANNEL(12 ) = { 0 x0de7c0, 0 x8cccd0, 0 xb00000, },
RF_CHANNEL(13 ) = { 0 x03efc0, 0 x8cccc0, 0 xb00000, },
RF_CHANNEL(14 ) = { 0 x03e7c0, 0 x866660, 0 xb00000, },
};
static const struct zd_ioreq16 zd1211b_ioreqs_shared_1[] = {
{ ZD_CR240, 0 x57 }, { ZD_CR9, 0 xe0 },
};
static const struct zd_ioreq16 ioreqs_init_al2230s[] = {
{ ZD_CR47, 0 x1e }, /* MARK_002 */
{ ZD_CR106, 0 x22 },
{ ZD_CR107, 0 x2a }, /* MARK_002 */
{ ZD_CR109, 0 x13 }, /* MARK_002 */
{ ZD_CR118, 0 xf8 }, /* MARK_002 */
{ ZD_CR119, 0 x12 }, { ZD_CR122, 0 xe0 },
{ ZD_CR128, 0 x10 }, /* MARK_001 from 0xe->0x10 */
{ ZD_CR129, 0 x0e }, /* MARK_001 from 0xd->0x0e */
{ ZD_CR130, 0 x10 }, /* MARK_001 from 0xb->0x0d */
};
static int zd1211b_al2230_finalize_rf(struct zd_chip *chip)
{
int r;
static const struct zd_ioreq16 ioreqs[] = {
{ ZD_CR80, 0 x30 }, { ZD_CR81, 0 x30 }, { ZD_CR79, 0 x58 },
{ ZD_CR12, 0 xf0 }, { ZD_CR77, 0 x1b }, { ZD_CR78, 0 x58 },
{ ZD_CR203, 0 x06 },
{ },
{ ZD_CR240, 0 x80 },
};
r = zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
if (r)
return r;
/* related to antenna selection? */
if (chip->new_phy_layout) {
r = zd_iowrite16_locked(chip, 0 xe1, ZD_CR9);
if (r)
return r;
}
return zd_iowrite16_locked(chip, 0 x06, ZD_CR203);
}
static int zd1211_al2230_init_hw(struct zd_rf *rf)
{
int r;
struct zd_chip *chip = zd_rf_to_chip(rf);
static const struct zd_ioreq16 ioreqs_init[] = {
{ ZD_CR15, 0 x20 }, { ZD_CR23, 0 x40 }, { ZD_CR24, 0 x20 },
{ ZD_CR26, 0 x11 }, { ZD_CR28, 0 x3e }, { ZD_CR29, 0 x00 },
{ ZD_CR44, 0 x33 }, { ZD_CR106, 0 x2a }, { ZD_CR107, 0 x1a },
{ ZD_CR109, 0 x09 }, { ZD_CR110, 0 x27 }, { ZD_CR111, 0 x2b },
{ ZD_CR112, 0 x2b }, { ZD_CR119, 0 x0a }, { ZD_CR10, 0 x89 },
/* for newest (3rd cut) AL2300 */
{ ZD_CR17, 0 x28 },
{ ZD_CR26, 0 x93 }, { ZD_CR34, 0 x30 },
/* for newest (3rd cut) AL2300 */
{ ZD_CR35, 0 x3e },
{ ZD_CR41, 0 x24 }, { ZD_CR44, 0 x32 },
/* for newest (3rd cut) AL2300 */
{ ZD_CR46, 0 x96 },
{ ZD_CR47, 0 x1e }, { ZD_CR79, 0 x58 }, { ZD_CR80, 0 x30 },
{ ZD_CR81, 0 x30 }, { ZD_CR87, 0 x0a }, { ZD_CR89, 0 x04 },
{ ZD_CR92, 0 x0a }, { ZD_CR99, 0 x28 }, { ZD_CR100, 0 x00 },
{ ZD_CR101, 0 x13 }, { ZD_CR102, 0 x27 }, { ZD_CR106, 0 x24 },
{ ZD_CR107, 0 x2a }, { ZD_CR109, 0 x09 }, { ZD_CR110, 0 x13 },
{ ZD_CR111, 0 x1f }, { ZD_CR112, 0 x1f }, { ZD_CR113, 0 x27 },
{ ZD_CR114, 0 x27 },
/* for newest (3rd cut) AL2300 */
{ ZD_CR115, 0 x24 },
{ ZD_CR116, 0 x24 }, { ZD_CR117, 0 xf4 }, { ZD_CR118, 0 xfc },
{ ZD_CR119, 0 x10 }, { ZD_CR120, 0 x4f }, { ZD_CR121, 0 x77 },
{ ZD_CR122, 0 xe0 }, { ZD_CR137, 0 x88 }, { ZD_CR252, 0 xff },
{ ZD_CR253, 0 xff },
};
static const struct zd_ioreq16 ioreqs_pll[] = {
/* shdnb(PLL_ON)=0 */
{ ZD_CR251, 0 x2f },
/* shdnb(PLL_ON)=1 */
{ ZD_CR251, 0 x3f },
{ ZD_CR138, 0 x28 }, { ZD_CR203, 0 x06 },
};
static const u32 rv1[] = {
/* Channel 1 */
0 x03f790,
0 x033331,
0 x00000d,
0 x0b3331,
0 x03b812,
0 x00fff3,
};
static const u32 rv2[] = {
0 x000da4,
0 x0f4dc5, /* fix freq shift, 0x04edc5 */
0 x0805b6,
0 x011687,
0 x000688,
0 x0403b9, /* external control TX power (ZD_CR31) */
0 x00dbba,
0 x00099b,
0 x0bdffc,
0 x00000d,
0 x00500f,
};
static const u32 rv3[] = {
0 x00d00f,
0 x004c0f,
0 x00540f,
0 x00700f,
0 x00500f,
};
r = zd_iowrite16a_locked(chip, ioreqs_init, ARRAY_SIZE(ioreqs_init));
if (r)
return r;
if (IS_AL2230S(chip)) {
r = zd_iowrite16a_locked(chip, ioreqs_init_al2230s,
ARRAY_SIZE(ioreqs_init_al2230s));
if (r)
return r;
}
r = zd_rfwritev_locked(chip, rv1, ARRAY_SIZE(rv1), RF_RV_BITS);
if (r)
return r;
/* improve band edge for AL2230S */
if (IS_AL2230S(chip))
r = zd_rfwrite_locked(chip, 0 x000824, RF_RV_BITS);
else
r = zd_rfwrite_locked(chip, 0 x0005a4, RF_RV_BITS);
if (r)
return r;
r = zd_rfwritev_locked(chip, rv2, ARRAY_SIZE(rv2), RF_RV_BITS);
if (r)
return r;
r = zd_iowrite16a_locked(chip, ioreqs_pll, ARRAY_SIZE(ioreqs_pll));
if (r)
return r;
r = zd_rfwritev_locked(chip, rv3, ARRAY_SIZE(rv3), RF_RV_BITS);
if (r)
return r;
return 0 ;
}
static int zd1211b_al2230_init_hw(struct zd_rf *rf)
{
int r;
struct zd_chip *chip = zd_rf_to_chip(rf);
static const struct zd_ioreq16 ioreqs1[] = {
{ ZD_CR10, 0 x89 }, { ZD_CR15, 0 x20 },
{ ZD_CR17, 0 x2B }, /* for newest(3rd cut) AL2230 */
{ ZD_CR23, 0 x40 }, { ZD_CR24, 0 x20 }, { ZD_CR26, 0 x93 },
{ ZD_CR28, 0 x3e }, { ZD_CR29, 0 x00 },
{ ZD_CR33, 0 x28 }, /* 5621 */
{ ZD_CR34, 0 x30 },
{ ZD_CR35, 0 x3e }, /* for newest(3rd cut) AL2230 */
{ ZD_CR41, 0 x24 }, { ZD_CR44, 0 x32 },
{ ZD_CR46, 0 x99 }, /* for newest(3rd cut) AL2230 */
{ ZD_CR47, 0 x1e },
/* ZD1211B 05.06.10 */
{ ZD_CR48, 0 x06 }, { ZD_CR49, 0 xf9 }, { ZD_CR51, 0 x01 },
{ ZD_CR52, 0 x80 }, { ZD_CR53, 0 x7e }, { ZD_CR65, 0 x00 },
{ ZD_CR66, 0 x00 }, { ZD_CR67, 0 x00 }, { ZD_CR68, 0 x00 },
{ ZD_CR69, 0 x28 },
{ ZD_CR79, 0 x58 }, { ZD_CR80, 0 x30 }, { ZD_CR81, 0 x30 },
{ ZD_CR87, 0 x0a }, { ZD_CR89, 0 x04 },
{ ZD_CR91, 0 x00 }, /* 5621 */
{ ZD_CR92, 0 x0a },
{ ZD_CR98, 0 x8d }, /* 4804, for 1212 new algorithm */
{ ZD_CR99, 0 x00 }, /* 5621 */
{ ZD_CR101, 0 x13 }, { ZD_CR102, 0 x27 },
{ ZD_CR106, 0 x24 }, /* for newest(3rd cut) AL2230 */
{ ZD_CR107, 0 x2a },
{ ZD_CR109, 0 x13 }, /* 4804, for 1212 new algorithm */
{ ZD_CR110, 0 x1f }, /* 4804, for 1212 new algorithm */
{ ZD_CR111, 0 x1f }, { ZD_CR112, 0 x1f }, { ZD_CR113, 0 x27 },
{ ZD_CR114, 0 x27 },
{ ZD_CR115, 0 x26 }, /* 24->26 at 4902 for newest(3rd cut)
* AL2230
*/
{ ZD_CR116, 0 x24 },
{ ZD_CR117, 0 xfa }, /* for 1211b */
{ ZD_CR118, 0 xfa }, /* for 1211b */
{ ZD_CR119, 0 x10 },
{ ZD_CR120, 0 x4f },
{ ZD_CR121, 0 x6c }, /* for 1211b */
{ ZD_CR122, 0 xfc }, /* E0->FC at 4902 */
{ ZD_CR123, 0 x57 }, /* 5623 */
{ ZD_CR125, 0 xad }, /* 4804, for 1212 new algorithm */
{ ZD_CR126, 0 x6c }, /* 5614 */
{ ZD_CR127, 0 x03 }, /* 4804, for 1212 new algorithm */
{ ZD_CR137, 0 x50 }, /* 5614 */
{ ZD_CR138, 0 xa8 },
{ ZD_CR144, 0 xac }, /* 5621 */
{ ZD_CR150, 0 x0d }, { ZD_CR252, 0 x34 }, { ZD_CR253, 0 x34 },
};
static const u32 rv1[] = {
0 x8cccd0,
0 x481dc0,
0 xcfff00,
0 x25a000,
};
static const u32 rv2[] = {
/* To improve AL2230 yield, improve phase noise, 4713 */
0 x25a000,
0 xa3b2f0,
0 x6da010, /* Reg6 update for MP versio */
0 xe36280, /* Modified by jxiao for Bor-Chin on 2004/08/02 */
0 x116000,
0 x9dc020, /* External control TX power (ZD_CR31) */
0 x5ddb00, /* RegA update for MP version */
0 xd99000, /* RegB update for MP version */
0 x3ffbd0, /* RegC update for MP version */
0 xb00000, /* RegD update for MP version */
/* improve phase noise and remove phase calibration,4713 */
0 xf01a00,
};
static const struct zd_ioreq16 ioreqs2[] = {
{ ZD_CR251, 0 x2f }, /* shdnb(PLL_ON)=0 */
{ ZD_CR251, 0 x7f }, /* shdnb(PLL_ON)=1 */
};
static const u32 rv3[] = {
/* To improve AL2230 yield, 4713 */
0 xf01b00,
0 xf01e00,
0 xf01a00,
};
static const struct zd_ioreq16 ioreqs3[] = {
/* related to 6M band edge patching, happens unconditionally */
{ ZD_CR128, 0 x14 }, { ZD_CR129, 0 x12 }, { ZD_CR130, 0 x10 },
};
r = zd_iowrite16a_locked(chip, zd1211b_ioreqs_shared_1,
ARRAY_SIZE(zd1211b_ioreqs_shared_1));
if (r)
return r;
r = zd_iowrite16a_locked(chip, ioreqs1, ARRAY_SIZE(ioreqs1));
if (r)
return r;
if (IS_AL2230S(chip)) {
r = zd_iowrite16a_locked(chip, ioreqs_init_al2230s,
ARRAY_SIZE(ioreqs_init_al2230s));
if (r)
return r;
}
r = zd_rfwritev_cr_locked(chip, zd1211b_al2230_table[0 ], 3 );
if (r)
return r;
r = zd_rfwritev_cr_locked(chip, rv1, ARRAY_SIZE(rv1));
if (r)
return r;
if (IS_AL2230S(chip))
r = zd_rfwrite_locked(chip, 0 x241000, RF_RV_BITS);
else
r = zd_rfwrite_locked(chip, 0 x25a000, RF_RV_BITS);
if (r)
return r;
r = zd_rfwritev_cr_locked(chip, rv2, ARRAY_SIZE(rv2));
if (r)
return r;
r = zd_iowrite16a_locked(chip, ioreqs2, ARRAY_SIZE(ioreqs2));
if (r)
return r;
r = zd_rfwritev_cr_locked(chip, rv3, ARRAY_SIZE(rv3));
if (r)
return r;
r = zd_iowrite16a_locked(chip, ioreqs3, ARRAY_SIZE(ioreqs3));
if (r)
return r;
return zd1211b_al2230_finalize_rf(chip);
}
static int zd1211_al2230_set_channel(struct zd_rf *rf, u8 channel)
{
int r;
const u32 *rv = zd1211_al2230_table[channel-1 ];
struct zd_chip *chip = zd_rf_to_chip(rf);
static const struct zd_ioreq16 ioreqs[] = {
{ ZD_CR138, 0 x28 },
{ ZD_CR203, 0 x06 },
};
r = zd_rfwritev_locked(chip, rv, 3 , RF_RV_BITS);
if (r)
return r;
return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
}
static int zd1211b_al2230_set_channel(struct zd_rf *rf, u8 channel)
{
int r;
const u32 *rv = zd1211b_al2230_table[channel-1 ];
struct zd_chip *chip = zd_rf_to_chip(rf);
r = zd_iowrite16a_locked(chip, zd1211b_ioreqs_shared_1,
ARRAY_SIZE(zd1211b_ioreqs_shared_1));
if (r)
return r;
r = zd_rfwritev_cr_locked(chip, rv, 3 );
if (r)
return r;
return zd1211b_al2230_finalize_rf(chip);
}
static int zd1211_al2230_switch_radio_on(struct zd_rf *rf)
{
struct zd_chip *chip = zd_rf_to_chip(rf);
static const struct zd_ioreq16 ioreqs[] = {
{ ZD_CR11, 0 x00 },
{ ZD_CR251, 0 x3f },
};
return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
}
static int zd1211b_al2230_switch_radio_on(struct zd_rf *rf)
{
struct zd_chip *chip = zd_rf_to_chip(rf);
static const struct zd_ioreq16 ioreqs[] = {
{ ZD_CR11, 0 x00 },
{ ZD_CR251, 0 x7f },
};
return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
}
static int al2230_switch_radio_off(struct zd_rf *rf)
{
struct zd_chip *chip = zd_rf_to_chip(rf);
static const struct zd_ioreq16 ioreqs[] = {
{ ZD_CR11, 0 x04 },
{ ZD_CR251, 0 x2f },
};
return zd_iowrite16a_locked(chip, ioreqs, ARRAY_SIZE(ioreqs));
}
int zd_rf_init_al2230(struct zd_rf *rf)
{
struct zd_chip *chip = zd_rf_to_chip(rf);
rf->switch_radio_off = al2230_switch_radio_off;
if (zd_chip_is_zd1211b(chip)) {
rf->init_hw = zd1211b_al2230_init_hw;
rf->set_channel = zd1211b_al2230_set_channel;
rf->switch_radio_on = zd1211b_al2230_switch_radio_on;
} else {
rf->init_hw = zd1211_al2230_init_hw;
rf->set_channel = zd1211_al2230_set_channel;
rf->switch_radio_on = zd1211_al2230_switch_radio_on;
}
rf->patch_6m_band_edge = zd_rf_generic_patch_6m;
rf->patch_cck_gain = 1 ;
return 0 ;
}
Messung V0.5 in Prozent C=96 H=91 G=93
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-07)
¤
*© Formatika GbR, Deutschland