diff options
Diffstat (limited to 'sys/dev')
-rw-r--r-- | sys/dev/ic/bcw.c | 1022 | ||||
-rw-r--r-- | sys/dev/ic/bcwreg.h | 12 | ||||
-rw-r--r-- | sys/dev/ic/bcwvar.h | 26 |
3 files changed, 1035 insertions, 25 deletions
diff --git a/sys/dev/ic/bcw.c b/sys/dev/ic/bcw.c index 935f2dc6456..32e71b88799 100644 --- a/sys/dev/ic/bcw.c +++ b/sys/dev/ic/bcw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bcw.c,v 1.42 2007/02/18 16:03:33 mglocker Exp $ */ +/* $OpenBSD: bcw.c,v 1.43 2007/02/20 21:24:36 mglocker Exp $ */ /* * Copyright (c) 2006 Jon Simola <jsimola@gmail.com> @@ -63,7 +63,7 @@ #include <uvm/uvm_extern.h> -/* register routines */ +/* helper routines */ void bcw_shm_ctl_word(struct bcw_softc *, uint16_t, uint16_t); uint16_t bcw_shm_read16(struct bcw_softc *, uint16_t, uint16_t); void bcw_shm_write16(struct bcw_softc *, uint16_t, uint16_t, @@ -72,6 +72,9 @@ void bcw_radio_write16(struct bcw_softc *, uint16_t, uint16_t); int bcw_radio_read16(struct bcw_softc *, uint16_t); void bcw_phy_write16(struct bcw_softc *, uint16_t, uint16_t); int bcw_phy_read16(struct bcw_softc *, uint16_t); +struct bcw_lopair * + bcw_get_lopair(struct bcw_softc *sc, uint16_t radio_atten, + uint16_t baseband_atten); void bcw_reset(struct bcw_softc *); int bcw_init(struct ifnet *); @@ -116,23 +119,322 @@ int bcw_phy_init(struct bcw_softc *); void bcw_phy_initg(struct bcw_softc *); void bcw_phy_initb5(struct bcw_softc *); void bcw_phy_initb6(struct bcw_softc *); -void bcw_phy_set_baseband_attenuation(struct bcw_softc *, uint16_t); +void bcw_phy_inita(struct bcw_softc *); +void bcw_phy_setupa(struct bcw_softc *); +void bcw_phy_setupg(struct bcw_softc *); +void bcw_phy_calc_loopback_gain(struct bcw_softc *); +void bcw_phy_agcsetup(struct bcw_softc *); +void bcw_phy_init_noisescaletbl(struct bcw_softc *); +void bcw_phy_set_baseband_atten(struct bcw_softc *, uint16_t); +void bcw_phy_lo_g_measure(struct bcw_softc *); +void bcw_phy_lo_adjust(struct bcw_softc *, int fixed); +struct bcw_lopair * + bcw_phy_find_lopair(struct bcw_softc *, uint16_t, uint16_t, + uint16_t); +struct bcw_lopair * + bcw_phy_current_lopair(struct bcw_softc *); +void bcw_lowrite(struct bcw_softc *, struct bcw_lopair *); /* radio */ void bcw_radio_off(struct bcw_softc *); void bcw_radio_on(struct bcw_softc *); -void bcw_radio_txpower_bg(struct bcw_softc *, uint16_t, uint16_t, +void bcw_radio_nrssi_hw_write(struct bcw_softc *, uint16_t, int16_t); +void bcw_radio_set_txpower_bg(struct bcw_softc *, uint16_t, uint16_t, uint16_t); void bcw_radio_spw(struct bcw_softc *, uint8_t); int bcw_radio_channel(struct bcw_softc *, uint8_t, int ); int bcw_radio_chan2freq_bg(uint8_t); uint16_t bcw_radio_defaultbaseband(struct bcw_softc *); +/* ilt */ +void bcw_ilt_write(struct bcw_softc *, uint16_t, uint16_t); +uint16_t bcw_ilt_read(struct bcw_softc *, uint16_t); struct cfdriver bcw_cd = { NULL, "bcw", DV_IFNET }; /* - * Register routines + * ILT (Internal Lookup Table) + */ +const uint32_t bcw_ilt_rotor[BCW_ILT_ROTOR_SIZE] = { + 0xFEB93FFD, 0xFEC63FFD, /* 0 */ + 0xFED23FFD, 0xFEDF3FFD, + 0xFEEC3FFE, 0xFEF83FFE, + 0xFF053FFE, 0xFF113FFE, + 0xFF1E3FFE, 0xFF2A3FFF, /* 8 */ + 0xFF373FFF, 0xFF443FFF, + 0xFF503FFF, 0xFF5D3FFF, + 0xFF693FFF, 0xFF763FFF, + 0xFF824000, 0xFF8F4000, /* 16 */ + 0xFF9B4000, 0xFFA84000, + 0xFFB54000, 0xFFC14000, + 0xFFCE4000, 0xFFDA4000, + 0xFFE74000, 0xFFF34000, /* 24 */ + 0x00004000, 0x000D4000, + 0x00194000, 0x00264000, + 0x00324000, 0x003F4000, + 0x004B4000, 0x00584000, /* 32 */ + 0x00654000, 0x00714000, + 0x007E4000, 0x008A3FFF, + 0x00973FFF, 0x00A33FFF, + 0x00B03FFF, 0x00BC3FFF, /* 40 */ + 0x00C93FFF, 0x00D63FFF, + 0x00E23FFE, 0x00EF3FFE, + 0x00FB3FFE, 0x01083FFE, + 0x01143FFE, 0x01213FFD, /* 48 */ + 0x012E3FFD, 0x013A3FFD, + 0x01473FFD, +}; + +const uint16_t bcw_ilt_sigmasqr1[BCW_ILT_SIGMASQR_SIZE] = { + 0x007A, 0x0075, 0x0071, 0x006C, /* 0 */ + 0x0067, 0x0063, 0x005E, 0x0059, + 0x0054, 0x0050, 0x004B, 0x0046, + 0x0042, 0x003D, 0x003D, 0x003D, + 0x003D, 0x003D, 0x003D, 0x003D, /* 16 */ + 0x003D, 0x003D, 0x003D, 0x003D, + 0x003D, 0x003D, 0x0000, 0x003D, + 0x003D, 0x003D, 0x003D, 0x003D, + 0x003D, 0x003D, 0x003D, 0x003D, /* 32 */ + 0x003D, 0x003D, 0x003D, 0x003D, + 0x0042, 0x0046, 0x004B, 0x0050, + 0x0054, 0x0059, 0x005E, 0x0063, + 0x0067, 0x006C, 0x0071, 0x0075, /* 48 */ + 0x007A, +}; + +const uint16_t bcw_ilt_sigmasqr2[BCW_ILT_SIGMASQR_SIZE] = { + 0x00DE, 0x00DC, 0x00DA, 0x00D8, /* 0 */ + 0x00D6, 0x00D4, 0x00D2, 0x00CF, + 0x00CD, 0x00CA, 0x00C7, 0x00C4, + 0x00C1, 0x00BE, 0x00BE, 0x00BE, + 0x00BE, 0x00BE, 0x00BE, 0x00BE, /* 16 */ + 0x00BE, 0x00BE, 0x00BE, 0x00BE, + 0x00BE, 0x00BE, 0x0000, 0x00BE, + 0x00BE, 0x00BE, 0x00BE, 0x00BE, + 0x00BE, 0x00BE, 0x00BE, 0x00BE, /* 32 */ + 0x00BE, 0x00BE, 0x00BE, 0x00BE, + 0x00C1, 0x00C4, 0x00C7, 0x00CA, + 0x00CD, 0x00CF, 0x00D2, 0x00D4, + 0x00D6, 0x00D8, 0x00DA, 0x00DC, /* 48 */ + 0x00DE, +}; + +const uint32_t bcw_ilt_retard[BCW_ILT_RETARD_SIZE] = { + 0xDB93CB87, 0xD666CF64, /* 0 */ + 0xD1FDD358, 0xCDA6D826, + 0xCA38DD9F, 0xC729E2B4, + 0xC469E88E, 0xC26AEE2B, + 0xC0DEF46C, 0xC073FA62, /* 8 */ + 0xC01D00D5, 0xC0760743, + 0xC1560D1E, 0xC2E51369, + 0xC4ED18FF, 0xC7AC1ED7, + 0xCB2823B2, 0xCEFA28D9, /* 16 */ + 0xD2F62D3F, 0xD7BB3197, + 0xDCE53568, 0xE1FE3875, + 0xE7D13B35, 0xED663D35, + 0xF39B3EC4, 0xF98E3FA7, /* 24 */ + 0x00004000, 0x06723FA7, + 0x0C653EC4, 0x129A3D35, + 0x182F3B35, 0x1E023875, + 0x231B3568, 0x28453197, /* 32 */ + 0x2D0A2D3F, 0x310628D9, + 0x34D823B2, 0x38541ED7, + 0x3B1318FF, 0x3D1B1369, + 0x3EAA0D1E, 0x3F8A0743, /* 40 */ + 0x3FE300D5, 0x3F8DFA62, + 0x3F22F46C, 0x3D96EE2B, + 0x3B97E88E, 0x38D7E2B4, + 0x35C8DD9F, 0x325AD826, /* 48 */ + 0x2E03D358, 0x299ACF64, + 0x246DCB87, +}; + +const uint16_t bcw_ilt_finefreqa[BCW_ILT_FINEFREQA_SIZE] = { + 0x0082, 0x0082, 0x0102, 0x0182, /* 0 */ + 0x0202, 0x0282, 0x0302, 0x0382, + 0x0402, 0x0482, 0x0502, 0x0582, + 0x05E2, 0x0662, 0x06E2, 0x0762, + 0x07E2, 0x0842, 0x08C2, 0x0942, /* 16 */ + 0x09C2, 0x0A22, 0x0AA2, 0x0B02, + 0x0B82, 0x0BE2, 0x0C62, 0x0CC2, + 0x0D42, 0x0DA2, 0x0E02, 0x0E62, + 0x0EE2, 0x0F42, 0x0FA2, 0x1002, /* 32 */ + 0x1062, 0x10C2, 0x1122, 0x1182, + 0x11E2, 0x1242, 0x12A2, 0x12E2, + 0x1342, 0x13A2, 0x1402, 0x1442, + 0x14A2, 0x14E2, 0x1542, 0x1582, /* 48 */ + 0x15E2, 0x1622, 0x1662, 0x16C1, + 0x1701, 0x1741, 0x1781, 0x17E1, + 0x1821, 0x1861, 0x18A1, 0x18E1, + 0x1921, 0x1961, 0x19A1, 0x19E1, /* 64 */ + 0x1A21, 0x1A61, 0x1AA1, 0x1AC1, + 0x1B01, 0x1B41, 0x1B81, 0x1BA1, + 0x1BE1, 0x1C21, 0x1C41, 0x1C81, + 0x1CA1, 0x1CE1, 0x1D01, 0x1D41, /* 80 */ + 0x1D61, 0x1DA1, 0x1DC1, 0x1E01, + 0x1E21, 0x1E61, 0x1E81, 0x1EA1, + 0x1EE1, 0x1F01, 0x1F21, 0x1F41, + 0x1F81, 0x1FA1, 0x1FC1, 0x1FE1, /* 96 */ + 0x2001, 0x2041, 0x2061, 0x2081, + 0x20A1, 0x20C1, 0x20E1, 0x2101, + 0x2121, 0x2141, 0x2161, 0x2181, + 0x21A1, 0x21C1, 0x21E1, 0x2201, /* 112 */ + 0x2221, 0x2241, 0x2261, 0x2281, + 0x22A1, 0x22C1, 0x22C1, 0x22E1, + 0x2301, 0x2321, 0x2341, 0x2361, + 0x2361, 0x2381, 0x23A1, 0x23C1, /* 128 */ + 0x23E1, 0x23E1, 0x2401, 0x2421, + 0x2441, 0x2441, 0x2461, 0x2481, + 0x2481, 0x24A1, 0x24C1, 0x24C1, + 0x24E1, 0x2501, 0x2501, 0x2521, /* 144 */ + 0x2541, 0x2541, 0x2561, 0x2561, + 0x2581, 0x25A1, 0x25A1, 0x25C1, + 0x25C1, 0x25E1, 0x2601, 0x2601, + 0x2621, 0x2621, 0x2641, 0x2641, /* 160 */ + 0x2661, 0x2661, 0x2681, 0x2681, + 0x26A1, 0x26A1, 0x26C1, 0x26C1, + 0x26E1, 0x26E1, 0x2701, 0x2701, + 0x2721, 0x2721, 0x2740, 0x2740, /* 176 */ + 0x2760, 0x2760, 0x2780, 0x2780, + 0x2780, 0x27A0, 0x27A0, 0x27C0, + 0x27C0, 0x27E0, 0x27E0, 0x27E0, + 0x2800, 0x2800, 0x2820, 0x2820, /* 192 */ + 0x2820, 0x2840, 0x2840, 0x2840, + 0x2860, 0x2860, 0x2880, 0x2880, + 0x2880, 0x28A0, 0x28A0, 0x28A0, + 0x28C0, 0x28C0, 0x28C0, 0x28E0, /* 208 */ + 0x28E0, 0x28E0, 0x2900, 0x2900, + 0x2900, 0x2920, 0x2920, 0x2920, + 0x2940, 0x2940, 0x2940, 0x2960, + 0x2960, 0x2960, 0x2960, 0x2980, /* 224 */ + 0x2980, 0x2980, 0x29A0, 0x29A0, + 0x29A0, 0x29A0, 0x29C0, 0x29C0, + 0x29C0, 0x29E0, 0x29E0, 0x29E0, + 0x29E0, 0x2A00, 0x2A00, 0x2A00, /* 240 */ + 0x2A00, 0x2A20, 0x2A20, 0x2A20, + 0x2A20, 0x2A40, 0x2A40, 0x2A40, + 0x2A40, 0x2A60, 0x2A60, 0x2A60, +}; + +const uint16_t bcw_ilt_noisea2[BCW_ILT_NOISEA2_SIZE] = { + 0x0001, 0x0001, 0x0001, 0xFFFE, + 0xFFFE, 0x3FFF, 0x1000, 0x0393, +}; + +const uint16_t bcw_ilt_noisea3[BCW_ILT_NOISEA3_SIZE] = { + 0x4C4C, 0x4C4C, 0x4C4C, 0x2D36, + 0x4C4C, 0x4C4C, 0x4C4C, 0x2D36, +}; + +const uint16_t bcw_ilt_finefreqg[BCW_ILT_FINEFREQG_SIZE] = { + 0x0089, 0x02E9, 0x0409, 0x04E9, /* 0 */ + 0x05A9, 0x0669, 0x0709, 0x0789, + 0x0829, 0x08A9, 0x0929, 0x0989, + 0x0A09, 0x0A69, 0x0AC9, 0x0B29, + 0x0BA9, 0x0BE9, 0x0C49, 0x0CA9, /* 16 */ + 0x0D09, 0x0D69, 0x0DA9, 0x0E09, + 0x0E69, 0x0EA9, 0x0F09, 0x0F49, + 0x0FA9, 0x0FE9, 0x1029, 0x1089, + 0x10C9, 0x1109, 0x1169, 0x11A9, /* 32 */ + 0x11E9, 0x1229, 0x1289, 0x12C9, + 0x1309, 0x1349, 0x1389, 0x13C9, + 0x1409, 0x1449, 0x14A9, 0x14E9, + 0x1529, 0x1569, 0x15A9, 0x15E9, /* 48 */ + 0x1629, 0x1669, 0x16A9, 0x16E8, + 0x1728, 0x1768, 0x17A8, 0x17E8, + 0x1828, 0x1868, 0x18A8, 0x18E8, + 0x1928, 0x1968, 0x19A8, 0x19E8, /* 64 */ + 0x1A28, 0x1A68, 0x1AA8, 0x1AE8, + 0x1B28, 0x1B68, 0x1BA8, 0x1BE8, + 0x1C28, 0x1C68, 0x1CA8, 0x1CE8, + 0x1D28, 0x1D68, 0x1DC8, 0x1E08, /* 80 */ + 0x1E48, 0x1E88, 0x1EC8, 0x1F08, + 0x1F48, 0x1F88, 0x1FE8, 0x2028, + 0x2068, 0x20A8, 0x2108, 0x2148, + 0x2188, 0x21C8, 0x2228, 0x2268, /* 96 */ + 0x22C8, 0x2308, 0x2348, 0x23A8, + 0x23E8, 0x2448, 0x24A8, 0x24E8, + 0x2548, 0x25A8, 0x2608, 0x2668, + 0x26C8, 0x2728, 0x2787, 0x27E7, /* 112 */ + 0x2847, 0x28C7, 0x2947, 0x29A7, + 0x2A27, 0x2AC7, 0x2B47, 0x2BE7, + 0x2CA7, 0x2D67, 0x2E47, 0x2F67, + 0x3247, 0x3526, 0x3646, 0x3726, /* 128 */ + 0x3806, 0x38A6, 0x3946, 0x39E6, + 0x3A66, 0x3AE6, 0x3B66, 0x3BC6, + 0x3C45, 0x3CA5, 0x3D05, 0x3D85, + 0x3DE5, 0x3E45, 0x3EA5, 0x3EE5, /* 144 */ + 0x3F45, 0x3FA5, 0x4005, 0x4045, + 0x40A5, 0x40E5, 0x4145, 0x4185, + 0x41E5, 0x4225, 0x4265, 0x42C5, + 0x4305, 0x4345, 0x43A5, 0x43E5, /* 160 */ + 0x4424, 0x4464, 0x44C4, 0x4504, + 0x4544, 0x4584, 0x45C4, 0x4604, + 0x4644, 0x46A4, 0x46E4, 0x4724, + 0x4764, 0x47A4, 0x47E4, 0x4824, /* 176 */ + 0x4864, 0x48A4, 0x48E4, 0x4924, + 0x4964, 0x49A4, 0x49E4, 0x4A24, + 0x4A64, 0x4AA4, 0x4AE4, 0x4B23, + 0x4B63, 0x4BA3, 0x4BE3, 0x4C23, /* 192 */ + 0x4C63, 0x4CA3, 0x4CE3, 0x4D23, + 0x4D63, 0x4DA3, 0x4DE3, 0x4E23, + 0x4E63, 0x4EA3, 0x4EE3, 0x4F23, + 0x4F63, 0x4FC3, 0x5003, 0x5043, /* 208 */ + 0x5083, 0x50C3, 0x5103, 0x5143, + 0x5183, 0x51E2, 0x5222, 0x5262, + 0x52A2, 0x52E2, 0x5342, 0x5382, + 0x53C2, 0x5402, 0x5462, 0x54A2, /* 224 */ + 0x5502, 0x5542, 0x55A2, 0x55E2, + 0x5642, 0x5682, 0x56E2, 0x5722, + 0x5782, 0x57E1, 0x5841, 0x58A1, + 0x5901, 0x5961, 0x59C1, 0x5A21, /* 240 */ + 0x5AA1, 0x5B01, 0x5B81, 0x5BE1, + 0x5C61, 0x5D01, 0x5D80, 0x5E20, + 0x5EE0, 0x5FA0, 0x6080, 0x61C0, +}; + +const uint16_t bcw_ilt_noiseg1[BCW_ILT_NOISEG1_SIZE] = { + 0x013C, 0x01F5, 0x031A, 0x0631, + 0x0001, 0x0001, 0x0001, 0x0001, +}; + +const uint16_t bcw_ilt_noiseg2[BCW_ILT_NOISEG2_SIZE] = { + 0x5484, 0x3C40, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, +}; + +const uint16_t bcw_ilt_noisescaleg1[BCW_ILT_NOISESCALEG_SIZE] = { + 0x6C77, 0x5162, 0x3B40, 0x3335, /* 0 */ + 0x2F2D, 0x2A2A, 0x2527, 0x1F21, + 0x1A1D, 0x1719, 0x1616, 0x1414, + 0x1414, 0x1400, 0x1414, 0x1614, + 0x1716, 0x1A19, 0x1F1D, 0x2521, /* 16 */ + 0x2A27, 0x2F2A, 0x332D, 0x3B35, + 0x5140, 0x6C62, 0x0077, +}; + +const uint16_t bcw_ilt_noisescaleg3[BCW_ILT_NOISESCALEG_SIZE] = { + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4, /* 0 */ + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4, + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4, + 0xA4A4, 0xA400, 0xA4A4, 0xA4A4, + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4, /* 16 */ + 0xA4A4, 0xA4A4, 0xA4A4, 0xA4A4, + 0xA4A4, 0xA4A4, 0x00A4, +}; + +const uint16_t bcw_ilt_noisescaleg2[BCW_ILT_NOISESCALEG_SIZE] = { + 0xD8DD, 0xCBD4, 0xBCC0, 0XB6B7, /* 0 */ + 0xB2B0, 0xADAD, 0xA7A9, 0x9FA1, + 0x969B, 0x9195, 0x8F8F, 0x8A8A, + 0x8A8A, 0x8A00, 0x8A8A, 0x8F8A, + 0x918F, 0x9695, 0x9F9B, 0xA7A1, /* 16 */ + 0xADA9, 0xB2AD, 0xB6B0, 0xBCB7, + 0xCBC0, 0xD8D4, 0x00DD, +}; + +/* + * Helper routines */ void bcw_shm_ctl_word(struct bcw_softc *sc, uint16_t routing, uint16_t offset) @@ -228,6 +530,14 @@ bcw_phy_read16(struct bcw_softc *sc, uint16_t offset) return (BCW_READ16(sc, BCW_PHY_DATA)); } +struct bcw_lopair * +bcw_get_lopair(struct bcw_softc *sc, uint16_t radio_atten, + uint16_t baseband_atten) +{ + return (sc->sc_phy_lopairs + (radio_atten + 14 * + (baseband_atten / 2))); +} + void bcw_attach(struct bcw_softc *sc) { @@ -1257,6 +1567,8 @@ bcw_init(struct ifnet *ifp) //if ((error = bcw_phy_init(sc))) //return (error); + assert(0); + return (0); /* Cancel any pending I/O. */ @@ -2651,11 +2963,11 @@ bcw_phy_init(struct bcw_softc *sc) error = 0; break; case 5: - // bcw_phy_initb5(sc); + bcw_phy_initb5(sc); error = 0; break; case 6: - // bcw_phy_initb6(sc); + bcw_phy_initb6(sc); error = 0; break; } @@ -2675,10 +2987,54 @@ bcw_phy_init(struct bcw_softc *sc) void bcw_phy_initg(struct bcw_softc *sc) { + uint16_t tmp; + if (sc->sc_phy_rev == 1) bcw_phy_initb5(sc); else bcw_phy_initb6(sc); + if (sc->sc_phy_rev >= 2 || 1) /* XXX phy->connect */ + bcw_phy_inita(sc); + + if (sc->sc_phy_rev >= 2) { + bcw_phy_write16(sc, 0x0814, 0); + bcw_phy_write16(sc, 0x0815, 0); + if (sc->sc_phy_rev == 2) + bcw_phy_write16(sc, 0x0811, 0x0000); + else if (sc->sc_phy_rev >= 3) + bcw_phy_write16(sc, 0x0811, 0x0400); + bcw_phy_write16(sc, 0x0015, 0x00c0); + if (1) { /* XXX phy->connect */ + tmp = bcw_phy_read16(sc, 0x0400) & 0xff; + if (tmp < 6) { + bcw_phy_write16(sc, 0x04c2, 0x1816); + bcw_phy_write16(sc, 0x04c3, 0x8006); + if (tmp != 3) + bcw_phy_write16(sc, 0x04cc, + (bcw_phy_read16(sc, 0x04cc) & + 0x00ff) | 0x1f00); + } + } + } + + if (sc->sc_phy_rev < 3 && 1) /* XXX phy->connect */ + bcw_phy_write16(sc, 0x047e, 0x0078); + if (sc->sc_phy_rev >= 6 && sc->sc_phy_rev <= 8) { + bcw_phy_write16(sc, 0x0801, bcw_phy_read16(sc, 0x0801) | + 0x0080); + bcw_phy_write16(sc, 0x043e, bcw_phy_read16(sc, 0x043e) | + 0x0004); + } + if (sc->sc_phy_rev >= 2 && 1) /* XXX phy->connect */ + bcw_phy_calc_loopback_gain(sc); + if (sc->sc_radio_rev != 8) { + if (sc->sc_radio_initval == 0xffff) + sc->sc_radio_initval = 0; /* XXX bcw_radio_initval */ + else + bcw_radio_write16(sc, 0x0078, sc->sc_radio_initval); + } + if (sc->sc_radio_txctl2 == 0xffff) + bcw_phy_lo_g_measure(sc); } void @@ -2769,7 +3125,7 @@ bcw_phy_initb5(struct bcw_softc *sc) bcw_phy_write16(sc, 0x0032, 0x00ca); bcw_phy_write16(sc, 0x88a3, 0x002a); - /* TODO bcw_radio_set_tx_power() */ + bcw_radio_set_txpower_bg(sc, 0xffff, 0xffff, 0xffff); if (sc->sc_radio_rev == 0x2050) bcw_radio_write16(sc, 0x005d, 0x000d); @@ -2911,7 +3267,7 @@ bcw_phy_initb6(struct bcw_softc *sc) bcw_phy_write16(sc, 0x002a, 0x88c2); } bcw_phy_write16(sc, 0x0038, 0x0668); - /* TODO bcw_radio_set_tx_power() */ + bcw_radio_set_txpower_bg(sc, 0xffff, 0xffff, 0xffff); if (sc->sc_radio_ver == 0x2050) { if (sc->sc_radio_rev == 3 || sc->sc_radio_rev == 4 || sc->sc_radio_rev == 5) @@ -2937,28 +3293,604 @@ bcw_phy_initb6(struct bcw_softc *sc) } void -bcw_phy_set_baseband_attenuation(struct bcw_softc *sc, - uint16_t baseband_attenuation) +bcw_phy_inita(struct bcw_softc *sc) +{ + //uint16_t val; + + if (sc->sc_phy_type == BCW_PHY_TYPEA) + bcw_phy_setupa(sc); + else { + bcw_phy_setupg(sc); + if (sc->sc_boardflags & BCW_BF_PACTRL) + bcw_phy_write16(sc, 0x046e, 0x03cf); + return; + } +} + +void +bcw_phy_setupa(struct bcw_softc *sc) +{ + uint16_t i; + + switch (sc->sc_phy_rev) { + case 2: + bcw_phy_write16(sc, 0x008e, 0x3800); + bcw_phy_write16(sc, 0x0035, 0x03ff); + bcw_phy_write16(sc, 0x0036, 0x0400); + + bcw_ilt_write(sc, 0x3807, 0x0051); + + bcw_phy_write16(sc, 0x001c, 0x0ff9); + bcw_phy_write16(sc, 0x0020, bcw_phy_read16(sc, 0x0020) & + 0xff0f); + bcw_ilt_write(sc, 0x3c0c, 0x07bf); + bcw_radio_write16(sc, 0x0002, 0x07bf); + + bcw_phy_write16(sc, 0x0024, 0x4680); + bcw_phy_write16(sc, 0x0020, 0x0003); + bcw_phy_write16(sc, 0x001d, 0x0f40); + bcw_phy_write16(sc, 0x001f, 0x1c00); + + bcw_phy_write16(sc, 0x002a, (bcw_phy_read16(sc, 0x002a) & + 0x00ff) | 0x0400); + bcw_phy_write16(sc, 0x002b, bcw_phy_read16(sc, 0x002b) & + 0xfbff); + bcw_phy_write16(sc, 0x008e, 0x58c1); + + bcw_ilt_write(sc, 0x0803, 0x000f); + bcw_ilt_write(sc, 0x0804, 0x001f); + bcw_ilt_write(sc, 0x0805, 0x002a); + bcw_ilt_write(sc, 0x0805, 0x0030); + bcw_ilt_write(sc, 0x0807, 0x003a); + + bcw_ilt_write(sc, 0x0000, 0x0013); + bcw_ilt_write(sc, 0x0001, 0x0013); + bcw_ilt_write(sc, 0x0002, 0x0013); + bcw_ilt_write(sc, 0x0003, 0x0013); + bcw_ilt_write(sc, 0x0004, 0x0015); + bcw_ilt_write(sc, 0x0005, 0x0015); + bcw_ilt_write(sc, 0x0006, 0x0019); + + bcw_ilt_write(sc, 0x0404, 0x0003); + bcw_ilt_write(sc, 0x0405, 0x0003); + bcw_ilt_write(sc, 0x0406, 0x0007); + + for (i = 0; i < 16; i++) + bcw_ilt_write(sc, 0x4000 + i, (0x8 + i) & 0x000f); + + bcw_ilt_write(sc, 0x3003, 0x1044); + bcw_ilt_write(sc, 0x3004, 0x7201); + bcw_ilt_write(sc, 0x3006, 0x0040); + bcw_ilt_write(sc, 0x3001, (bcw_ilt_read(sc, 0x3001) & 0x0010) | + 0x0008); + + for (i = 0; i < BCW_ILT_FINEFREQA_SIZE; i++) + bcw_ilt_write(sc, 0x5800 + i, bcw_ilt_finefreqa[i]); + + for (i = 0; i < BCW_ILT_NOISEA2_SIZE; i++) + bcw_ilt_write(sc, 0x1800 + i, bcw_ilt_noisea2[i]); + + for (i = 0; i < BCW_ILT_ROTOR_SIZE; i++) + bcw_ilt_write(sc, 0x2000 + i, bcw_ilt_rotor[i]); + + bcw_phy_init_noisescaletbl(sc); + for (i = 0; i < BCW_ILT_RETARD_SIZE; i++) + bcw_ilt_write(sc, 0x2400 + i, bcw_ilt_retard[i]); + + break; + case 3: + for (i = 0; i< 64; i++) + bcw_ilt_write(sc, 0x4000 + i, i); + + bcw_ilt_write(sc, 0x3807, 0x0051); + + bcw_phy_write16(sc, 0x001c, 0x0ff9); + bcw_phy_write16(sc, 0x0020, bcw_phy_read16(sc, 0x0020) & + 0x0ff0f); + bcw_radio_write16(sc, 0x0002, 0x07bf); + + bcw_phy_write16(sc, 0x0024, 0x4680); + bcw_phy_write16(sc, 0x0020, 0x0003); + bcw_phy_write16(sc, 0x001d, 0x0f40); + bcw_phy_write16(sc, 0x001f, 0x1c00); + bcw_phy_write16(sc, 0x002a, (bcw_phy_read16(sc, 0x002a) & + 0x00ff) | 0x0400); + bcw_ilt_write(sc, 0x3001, (bcw_ilt_read(sc, 0x3001) & + 0x0010) | 0x0008); + for (i = 0; i < BCW_ILT_NOISEA3_SIZE; i++) + bcw_ilt_write(sc, 0x1800 + i, bcw_ilt_noisea3[i]); + + bcw_phy_init_noisescaletbl(sc); + for (i = 0; i < BCW_ILT_SIGMASQR_SIZE; i++) + bcw_ilt_write(sc, 0x5000 + i, bcw_ilt_sigmasqr1[i]); + + bcw_phy_write16(sc, 0x0003, 0x1808); + + bcw_ilt_write(sc, 0x0803, 0x000f); + bcw_ilt_write(sc, 0x0804, 0x001f); + bcw_ilt_write(sc, 0x0805, 0x002a); + bcw_ilt_write(sc, 0x0805, 0x0030); + bcw_ilt_write(sc, 0x0807, 0x003a); + + bcw_ilt_write(sc, 0x0000, 0x0013); + bcw_ilt_write(sc, 0x0001, 0x0013); + bcw_ilt_write(sc, 0x0002, 0x0013); + bcw_ilt_write(sc, 0x0003, 0x0013); + bcw_ilt_write(sc, 0x0004, 0x0015); + bcw_ilt_write(sc, 0x0005, 0x0015); + bcw_ilt_write(sc, 0x0006, 0x0019); + + bcw_ilt_write(sc, 0x0404, 0x0003); + bcw_ilt_write(sc, 0x0405, 0x0003); + bcw_ilt_write(sc, 0x0406, 0x0007); + + bcw_ilt_write(sc, 0x3c02, 0x000f); + bcw_ilt_write(sc, 0x3c03, 0x0014); + break; + default: + /* XXX assert? */ + break; + } +} + +void +bcw_phy_setupg(struct bcw_softc *sc) +{ + uint16_t i; + + /* XXX assert? */ + + if (sc->sc_phy_rev == 1) { + bcw_phy_write16(sc, 0x0406, 0x4f19); + bcw_phy_write16(sc, BCW_PHY_G_CRS, (bcw_phy_read16(sc, + BCW_PHY_G_CRS) & 0xfc3f) | 0x0340); + bcw_phy_write16(sc, 0x042c, 0x005a); + bcw_phy_write16(sc, 0x0427, 0x001a); + + for (i = 0; i < BCW_ILT_FINEFREQG_SIZE; i++) + bcw_ilt_write(sc, 0x5800 + i, bcw_ilt_finefreqg[i]); + + for (i = 0; i < BCW_ILT_NOISEG1_SIZE; i++) + bcw_ilt_write(sc, 0x1800 + i, bcw_ilt_noiseg1[i]); + + for (i = 0; i < BCW_ILT_ROTOR_SIZE; i++) + bcw_ilt_write(sc, 0x2000 + i, bcw_ilt_rotor[i]); + } else { + bcw_radio_nrssi_hw_write(sc, 0xba98, (int16_t) 0x7654); + + if (sc->sc_phy_type == 2) { + bcw_phy_write16(sc, 0x04c0, 0x1861); + bcw_phy_write16(sc, 0x04c1, 0x0271); + } else { + bcw_phy_write16(sc, 0x04c0, 0x0098); + bcw_phy_write16(sc, 0x04c1, 0x0070); + bcw_phy_write16(sc, 0x04c9, 0x0080); + } + bcw_phy_write16(sc, 0x042b, bcw_phy_read16(sc, 0x042b) | + 0x0800); + + for (i = 0; i < 64; i++) + bcw_ilt_write(sc, 0x4000 + i, i); + for (i = 0; i < BCW_ILT_NOISEG2_SIZE; i++) + bcw_ilt_write(sc, 0x1800 + i, bcw_ilt_noiseg2[i]); + } + + if (sc->sc_phy_rev <= 2) + for (i = 0; i < BCW_ILT_NOISESCALEG_SIZE; i++) + bcw_ilt_write(sc, 0x1400 + i, bcw_ilt_noisescaleg1[i]); + else if ((sc->sc_phy_rev >= 7) && (bcw_phy_read16(sc, 0x0449) & 0x0200)) + for (i = 0; i < BCW_ILT_NOISESCALEG_SIZE; i++) + bcw_ilt_write(sc, 0x1400 + i, bcw_ilt_noisescaleg3[i]); + else + for (i = 0; i < BCW_ILT_NOISESCALEG_SIZE; i++) + bcw_ilt_write(sc, 0x1400 + i, bcw_ilt_noisescaleg2[i]); + + if (sc->sc_phy_rev == 2) + for (i = 0; i < BCW_ILT_SIGMASQR_SIZE; i++) + bcw_ilt_write(sc, 0x5000 + i, bcw_ilt_sigmasqr1[i]); + else if ((sc->sc_phy_rev > 2) && (sc->sc_phy_rev <= 8)) + for (i = 0; i < BCW_ILT_SIGMASQR_SIZE; i++) + bcw_ilt_write(sc, 0x5000 + i, bcw_ilt_sigmasqr2[i]); + + if (sc->sc_phy_rev == 1) { + for (i = 0; i < BCW_ILT_RETARD_SIZE; i++) + bcw_ilt_write(sc, 0x2400 + i, bcw_ilt_retard[i]); + for (i = 0; i < 4; i++) { + bcw_ilt_write(sc, 0x5404 + i, 0x0020); + bcw_ilt_write(sc, 0x5408 + i, 0x0020); + bcw_ilt_write(sc, 0x540c + i, 0x0020); + bcw_ilt_write(sc, 0x5410 + i, 0x0020); + } + bcw_phy_agcsetup(sc); + + if (1) /* XXX board_vendor, board_type, board_revision */ + return; + + bcw_ilt_write(sc, 0x5001, 0x0002); + bcw_ilt_write(sc, 0x5002, 0x0001); + } else { + for (i = 0; i <= 0x2f; i++) + bcw_ilt_write(sc, 0x1000 + i, 0x0820); + bcw_phy_agcsetup(sc); + bcw_phy_read16(sc, 0x0400); + bcw_phy_write16(sc, 0x0403, 0x1000); + bcw_ilt_write(sc, 0x3c02, 0x000f); + bcw_ilt_write(sc, 0x3c03, 0x0014); + + if (1) /* XXX board_vendor, board_type, board_revision */ + return; + + bcw_ilt_write(sc, 0x0401, 0x0002); + bcw_ilt_write(sc, 0x0402, 0x0001); + } +} + +void +bcw_phy_calc_loopback_gain(struct bcw_softc *sc) +{ + uint16_t backup_phy[15]; + uint16_t backup_radio[3]; + uint16_t backup_bband; + uint16_t i; + uint16_t loop1_cnt, loop1_done, loop1_omitted; + uint16_t loop2_done; + + backup_phy[0] = bcw_phy_read16(sc, 0x0429); + backup_phy[1] = bcw_phy_read16(sc, 0x0001); + backup_phy[2] = bcw_phy_read16(sc, 0x0811); + backup_phy[3] = bcw_phy_read16(sc, 0x0812); + backup_phy[4] = bcw_phy_read16(sc, 0x0814); + backup_phy[5] = bcw_phy_read16(sc, 0x0815); + backup_phy[6] = bcw_phy_read16(sc, 0x005a); + backup_phy[7] = bcw_phy_read16(sc, 0x0059); + backup_phy[8] = bcw_phy_read16(sc, 0x0058); + backup_phy[9] = bcw_phy_read16(sc, 0x000a); + backup_phy[10] = bcw_phy_read16(sc, 0x0003); + backup_phy[11] = bcw_phy_read16(sc, 0x080f); + backup_phy[12] = bcw_phy_read16(sc, 0x0810); + backup_phy[13] = bcw_phy_read16(sc, 0x002b); + backup_phy[14] = bcw_phy_read16(sc, 0x0015); + bcw_phy_read16(sc, 0x002d); + backup_bband = sc->sc_radio_baseband_atten; + backup_radio[0] = bcw_radio_read16(sc, 0x0052); + backup_radio[1] = bcw_radio_read16(sc, 0x0043); + backup_radio[2] = bcw_radio_read16(sc, 0x007a); + + bcw_phy_write16(sc, 0x0429, bcw_phy_read16(sc, 0x0429) & 0x3fff); + bcw_phy_write16(sc, 0x0001, bcw_phy_read16(sc, 0x0001) & 0x8000); + bcw_phy_write16(sc, 0x0811, bcw_phy_read16(sc, 0x0811) & 0x0002); + bcw_phy_write16(sc, 0x0812, bcw_phy_read16(sc, 0x0812) & 0xfffd); + bcw_phy_write16(sc, 0x0811, bcw_phy_read16(sc, 0x0811) & 0x0001); + bcw_phy_write16(sc, 0x0812, bcw_phy_read16(sc, 0x0812) & 0xfffe); + bcw_phy_write16(sc, 0x0814, bcw_phy_read16(sc, 0x0814) & 0x0001); + bcw_phy_write16(sc, 0x0815, bcw_phy_read16(sc, 0x0815) & 0xfffe); + bcw_phy_write16(sc, 0x0814, bcw_phy_read16(sc, 0x0814) & 0x0002); + bcw_phy_write16(sc, 0x0815, bcw_phy_read16(sc, 0x0815) & 0xfffd); + bcw_phy_write16(sc, 0x0811, bcw_phy_read16(sc, 0x0811) & 0x000c); + bcw_phy_write16(sc, 0x0812, bcw_phy_read16(sc, 0x0812) & 0x000c); + + bcw_phy_write16(sc, 0x0811, (bcw_phy_read16(sc, 0x0811) & 0xffcf) | + 0x0030); + bcw_phy_write16(sc, 0x0812, (bcw_phy_read16(sc, 0x0812) & 0xffcf) | + 0x0010); + + bcw_phy_write16(sc, 0x005a, 0x0780); + bcw_phy_write16(sc, 0x0059, 0xc810); + bcw_phy_write16(sc, 0x0058, 0x000d); + if (sc->sc_phy_version == 9) + bcw_phy_write16(sc, 0x0003, 0x0122); + else + bcw_phy_write16(sc, 0x000a, bcw_phy_read16(sc, 0x000a) | + 0x2000); + bcw_phy_write16(sc, 0x0814, bcw_phy_read16(sc, 0x0814) | 0x0004); + bcw_phy_write16(sc, 0x0815, bcw_phy_read16(sc, 0x0815) & 0xfffb); + bcw_phy_write16(sc, 0x0003, (bcw_phy_read16(sc, 0x0003) & 0xff9f) | + 0x0040); + if (sc->sc_radio_ver == 0x2050 && sc->sc_radio_rev == 2) { + bcw_radio_write16(sc, 0x0052, 0x0000); + bcw_radio_write16(sc, 0x0043, (bcw_radio_read16(sc, 0x0043) & + 0xfff0) | 0x0009); + loop1_cnt = 9; + } else if (sc->sc_radio_rev == 8) { + bcw_radio_write16(sc, 0x0043, 0x000f); + loop1_cnt = 15; + } else + loop1_cnt = 0; + + bcw_phy_set_baseband_atten(sc, 11); + + if (sc->sc_phy_rev >= 3) + bcw_phy_write16(sc, 0x080f, 0xc020); + else + bcw_phy_write16(sc, 0x080f, 0x8020); + bcw_phy_write16(sc, 0x0810, 0x0000); + + bcw_phy_write16(sc, 0x002b, (bcw_phy_read16(sc, 0x002b) & 0xffc0) | + 0x0001); + bcw_phy_write16(sc, 0x002b, (bcw_phy_read16(sc, 0x002b) & 0xc0ff) | + 0x0800); + bcw_phy_write16(sc, 0x0811, bcw_phy_read16(sc, 0x0811) | 0x0100); + bcw_phy_write16(sc, 0x0812, bcw_phy_read16(sc, 0x0812) | 0xcfff); + if (sc->sc_boardflags & BCW_BF_EXTLNA) { + if (sc->sc_phy_rev >= 7) { + bcw_phy_write16(sc, 0x0811, bcw_phy_read16(sc, 0x0811) | + 0x0800); + bcw_phy_write16(sc, 0x0812, bcw_phy_read16(sc, 0x0812) | + 0x8000); + } + } + bcw_radio_write16(sc, 0x007a, bcw_radio_read16(sc, 0x007a) & 0x00f7); + + for (i = 0; i < loop1_cnt; i++) { + bcw_radio_write16(sc, 0x0043, loop1_cnt); + bcw_phy_write16(sc, 0x0812, (bcw_phy_read16(sc, 0x0812) & + 0xf0ff) | (i << 8)); + bcw_phy_write16(sc, 0x0015, (bcw_phy_read16(sc, 0x0015) & + 0x0fff) | 0xa000); + bcw_phy_write16(sc, 0x0015, (bcw_phy_read16(sc, 0x0015) & + 0x0fff) | 0xf000); + delay(20); + if (bcw_phy_read16(sc, 0x0002d) >= 0x0dfc) + break; + } + loop1_done = i; + loop1_omitted = loop1_cnt - loop1_done; + + loop2_done = 0; + if (loop1_done >= 8) { + bcw_phy_write16(sc, 0x0812, bcw_phy_read16(sc, 0x0812) | + 0x0030); + for (i = loop1_done - 8; i < 16; i++) { + bcw_phy_write16(sc, 0x0812, + (bcw_phy_read16(sc, 0x0812) & 0xf0ff) | (i << 8)); + bcw_phy_write16(sc, 0x0015, + (bcw_phy_read16(sc, 0x0015) & 0x0fff) | 0xa000); + bcw_phy_write16(sc, 0x0015, + (bcw_phy_read16(sc, 0x0015) & 0x0fff) | 0xf000); + delay(20); + if (bcw_phy_read16(sc, 0x002d) >= 0x0dfc) + break; + } + } + + bcw_phy_write16(sc, 0x0814, backup_phy[4]); + bcw_phy_write16(sc, 0x0815, backup_phy[5]); + bcw_phy_write16(sc, 0x005a, backup_phy[6]); + bcw_phy_write16(sc, 0x0059, backup_phy[7]); + bcw_phy_write16(sc, 0x0058, backup_phy[8]); + bcw_phy_write16(sc, 0x000a, backup_phy[9]); + bcw_phy_write16(sc, 0x0003, backup_phy[10]); + bcw_phy_write16(sc, 0x080f, backup_phy[11]); + bcw_phy_write16(sc, 0x0810, backup_phy[12]); + bcw_phy_write16(sc, 0x002b, backup_phy[13]); + bcw_phy_write16(sc, 0x0015, backup_phy[14]); + + bcw_phy_set_baseband_atten(sc, backup_bband); + + bcw_radio_write16(sc, 0x0052, backup_radio[0]); + bcw_radio_write16(sc, 0x0043, backup_radio[1]); + bcw_radio_write16(sc, 0x007a, backup_radio[2]); + + bcw_phy_write16(sc, 0x0811, backup_phy[2] | 0x0003); + delay(10); + bcw_phy_write16(sc, 0x0811, backup_phy[2]); + bcw_phy_write16(sc, 0x0812, backup_phy[3]); + bcw_phy_write16(sc, 0x0429, backup_phy[0]); + bcw_phy_write16(sc, 0x0001, backup_phy[1]); + + sc->sc_phy_loopback_gain[0] = ((loop1_done * 6) - (loop1_omitted * 4)) + - 11; + sc->sc_phy_loopback_gain[1] = (24 - (3 * loop2_done)) * 2; +} + +void +bcw_phy_agcsetup(struct bcw_softc *sc) +{ + uint16_t offset = 0; + + if (sc->sc_phy_rev == 1) + offset = 0x4c00; + + bcw_ilt_write(sc, offset, 0x00fe); + bcw_ilt_write(sc, offset + 1, 0x000d); + bcw_ilt_write(sc, offset + 2, 0x0013); + bcw_ilt_write(sc, offset + 3, 0x0019); + + if (sc->sc_phy_rev == 1) { + bcw_ilt_write(sc, 0x1800, 0x2710); + bcw_ilt_write(sc, 0x1801, 0x9b83); + bcw_ilt_write(sc, 0x1802, 0x9b83); + bcw_ilt_write(sc, 0x1803, 0x0f8d); + bcw_phy_write16(sc, 0x0455, 0x0004); + } + + bcw_phy_write16(sc, 0x04a5, (bcw_phy_read16(sc, 0x04a5) & 0x00ff) | + 0x5700); + bcw_phy_write16(sc, 0x041a, (bcw_phy_read16(sc, 0x041a) & 0xff80) | + 0x000f); + bcw_phy_write16(sc, 0x041a, (bcw_phy_read16(sc, 0x041a) & 0xc07f) | + 0x2b80); + bcw_phy_write16(sc, 0x048c, (bcw_phy_read16(sc, 0x048c) & 0xf0ff) | + 0x0300); + + bcw_radio_write16(sc, 0x007a, bcw_radio_read16(sc, 0x007a) | 0x0008); + + bcw_phy_write16(sc, 0x04a0, (bcw_phy_read16(sc, 0x04a0) & 0xfff0) | + 0x0008); + bcw_phy_write16(sc, 0x04a1, (bcw_phy_read16(sc, 0x04a1) & 0xf0ff) | + 0x0600); + bcw_phy_write16(sc, 0x04a2, (bcw_phy_read16(sc, 0x04a2) & 0xf0ff) | + 0x0700); + bcw_phy_write16(sc, 0x04a0, (bcw_phy_read16(sc, 0x04a0) & 0xf0ff) | + 0x0100); + + if (sc->sc_phy_rev == 1) + bcw_phy_write16(sc, 0x04a2, (bcw_phy_read16(sc, 0x4a2) & + 0xfff0) | 0x0007); + + bcw_phy_write16(sc, 0x0488, (bcw_phy_read16(sc, 0x0488) & 0xff00) | + 0x001c); + bcw_phy_write16(sc, 0x0488, (bcw_phy_read16(sc, 0x0488) & 0xc0ff) | + 0x0200); + bcw_phy_write16(sc, 0x0496, (bcw_phy_read16(sc, 0x0496) & 0xff00) | + 0x001c); + bcw_phy_write16(sc, 0x0489, (bcw_phy_read16(sc, 0x0489) & 0xff00) | + 0x0020); + bcw_phy_write16(sc, 0x0489, (bcw_phy_read16(sc, 0x0489) & 0xc0ff) | + 0x0200); + bcw_phy_write16(sc, 0x0482, (bcw_phy_read16(sc, 0x0482) & 0xff00) | + 0x001c); + bcw_phy_write16(sc, 0x0496, (bcw_phy_read16(sc, 0x0496) & 0x00ff) | + 0x1a00); + bcw_phy_write16(sc, 0x0481, (bcw_phy_read16(sc, 0x0481) & 0xff00) | + 0x0028); + bcw_phy_write16(sc, 0x0481, (bcw_phy_read16(sc, 0x0481) & 0x00ff) | + 0x2c00); + + if (sc->sc_phy_rev == 1) { + bcw_phy_write16(sc, 0x0430, 0x092b); + bcw_phy_write16(sc, 0x041b, (bcw_phy_read16(sc, 0x041b) & + 0xffe1) | 0x0002); + } else { + bcw_phy_write16(sc, 0x041b, bcw_phy_read16(sc, 0x41b) & + 0xffe1); + bcw_phy_write16(sc, 0x041f, 0x287a); + bcw_phy_write16(sc, 0x0420, (bcw_phy_read16(sc, 0x0420) & + 0xfff0) | 0x0004); + } + + if (sc->sc_phy_rev > 2) { + bcw_phy_write16(sc, 0x0422, 0x287a); + bcw_phy_write16(sc, 0x0420, (bcw_phy_read16(sc, 0x0420) & + 0x0fff) | 0x3000); + } + + bcw_phy_write16(sc, 0x04a8, (bcw_phy_read16(sc, 0x04a8) & 0x8080) | + 0x7874); + bcw_phy_write16(sc, 0x048e, 0x1c00); + + if (sc->sc_phy_rev == 1) { + bcw_phy_write16(sc, 0x04ab, (bcw_phy_read16(sc, 0x04ab) & + 0xf0ff) | 0x0600); + bcw_phy_write16(sc, 0x048b, 0x005e); + bcw_phy_write16(sc, 0x048c, (bcw_phy_read16(sc, 0x048c) & + 0xff00) | 0x001e); + bcw_phy_write16(sc, 0x048d, 0x0002); + } + + bcw_ilt_write(sc, offset + 0x0800, 0); + bcw_ilt_write(sc, offset + 0x0801, 7); + bcw_ilt_write(sc, offset + 0x0802, 16); + bcw_ilt_write(sc, offset + 0x0803, 28); +} + +void +bcw_phy_init_noisescaletbl(struct bcw_softc *sc) +{ + int i; + + bcw_phy_write16(sc, BCW_PHY_ILT_A_CTRL, 0x1400); + for (i = 0; i < 12; i++) { + if (sc->sc_phy_rev == 2) + bcw_phy_write16(sc, BCW_PHY_ILT_A_DATA1, 0x6767); + else + bcw_phy_write16(sc, BCW_PHY_ILT_A_DATA1, 0x2323); + } + + if (sc->sc_phy_rev == 2) + bcw_phy_write16(sc, BCW_PHY_ILT_A_DATA1, 0x6700); + else + bcw_phy_write16(sc, BCW_PHY_ILT_A_DATA1, 0x2300); + + for (i = 0; i < 11; i++) { + if (sc->sc_phy_rev == 2) + bcw_phy_write16(sc, BCW_PHY_ILT_A_DATA1, 0x6767); + else + bcw_phy_write16(sc, BCW_PHY_ILT_A_DATA1, 0x0023); + } + + if (sc->sc_phy_rev == 2) + bcw_phy_write16(sc, BCW_PHY_ILT_A_DATA1, 0x0067); + else + bcw_phy_write16(sc, BCW_PHY_ILT_A_DATA1, 0x0023); +} + +void +bcw_phy_set_baseband_atten(struct bcw_softc *sc, + uint16_t baseband_atten) { uint16_t val; if (sc->sc_phy_version == 0) { val = (BCW_READ16(sc, 0x03e6) & 0xfff0); - val |= (baseband_attenuation & 0x000f); + val |= (baseband_atten & 0x000f); BCW_WRITE16(sc, 0x03e6, val); return; } if (sc->sc_phy_version > 1) { val = bcw_phy_read16(sc, 0x0060) & ~0x003c; - val |= (baseband_attenuation << 2) & 0x003c; + val |= (baseband_atten << 2) & 0x003c; } else { val = bcw_phy_read16(sc, 0x0060) & ~0x0078; - val |= (baseband_attenuation << 3) & 0x0078; + val |= (baseband_atten << 3) & 0x0078; } bcw_phy_write16(sc, 0x0060, val); } +void +bcw_phy_lo_g_measure(struct bcw_softc *sc) +{ + +} + +void +bcw_phy_lo_adjust(struct bcw_softc *sc, int fixed) +{ + struct bcw_lopair *pair; + + if (fixed) + pair = bcw_phy_find_lopair(sc, 2, 3, 0); + else + pair = bcw_phy_current_lopair(sc); + + bcw_lowrite(sc, pair); +} + +struct bcw_lopair * +bcw_phy_find_lopair(struct bcw_softc *sc, uint16_t baseband_atten, + uint16_t radio_atten, uint16_t tx) +{ + static const uint8_t dict[10] = + { 11, 10, 11, 12, 13, 12, 13, 12, 13, 12 }; + + if (baseband_atten > 6) + baseband_atten = 6; + + if (tx == 3) + return (bcw_get_lopair(sc, radio_atten, baseband_atten)); + + return (bcw_get_lopair(sc, dict[radio_atten], baseband_atten)); +} + +struct bcw_lopair * +bcw_phy_current_lopair(struct bcw_softc *sc) +{ + return (bcw_phy_find_lopair(sc, sc->sc_radio_baseband_atten, + sc->sc_radio_radio_atten, sc->sc_radio_txctl1)); +} + +void +bcw_lowrite(struct bcw_softc *sc, struct bcw_lopair *pair) +{ + uint16_t val; + + val = (uint8_t)(pair->low); + val |= ((uint8_t)(pair->high)) << 8; + + bcw_phy_write16(sc, BCW_PHY_G_LO_CONTROL, val); +} + /* * Radio */ @@ -3014,22 +3946,39 @@ bcw_radio_on(struct bcw_softc *sc) } void -bcw_radio_txpower_bg(struct bcw_softc *sc, uint16_t baseband_attenuation, - uint16_t radio_attenuation, uint16_t txpower) +bcw_radio_nrssi_hw_write(struct bcw_softc *sc, uint16_t offset, int16_t val) { - //if (baseband_attenuation == 0xffff) - //if (radio_attenuation == 0xfff) - //if (txpower == 0xfff) + bcw_phy_write16(sc, BCW_PHY_NRSSILT_CTRL, offset); + bcw_phy_write16(sc, BCW_PHY_NRSSILT_DATA, (uint16_t)val); +} - bcw_phy_set_baseband_attenuation(sc, baseband_attenuation); - bcw_radio_write16(sc, 0x0043, radio_attenuation); - bcw_shm_write16(sc, BCW_SHM_CONTROL_SHARED, 0x0064, radio_attenuation); +void +bcw_radio_set_txpower_bg(struct bcw_softc *sc, uint16_t baseband_atten, + uint16_t radio_atten, uint16_t txpower) +{ + if (baseband_atten == 0xffff) + baseband_atten = sc->sc_radio_baseband_atten; + if (radio_atten == 0xfff) + radio_atten = sc->sc_radio_radio_atten; + if (txpower == 0xfff) + txpower = sc->sc_radio_txctl1; + + sc->sc_radio_baseband_atten = baseband_atten; + sc->sc_radio_radio_atten = radio_atten; + sc->sc_radio_txctl1 = txpower; + + /* XXX do we need that assert() mess here really? */ + + bcw_phy_set_baseband_atten(sc, baseband_atten); + bcw_radio_write16(sc, 0x0043, radio_atten); + bcw_shm_write16(sc, BCW_SHM_CONTROL_SHARED, 0x0064, radio_atten); if (sc->sc_radio_ver == 0x2050) bcw_radio_write16(sc, 0x0052, (bcw_radio_read16(sc, 0x0052) & ~0x0070) | ((txpower << 4) & 0x0070)); /* XXX unclear specs */ - //if (sc->sc_phy_type == BCW_PHY_TYPEG) + if (sc->sc_phy_type == BCW_PHY_TYPEG) + bcw_phy_lo_adjust(sc, 0); } void @@ -3136,3 +4085,30 @@ bcw_radio_defaultbaseband(struct bcw_softc *sc) return (2); } + +/* + * ILT + */ +void +bcw_ilt_write(struct bcw_softc *sc, uint16_t offset, uint16_t val) +{ + if (sc->sc_phy_type == BCW_PHY_TYPEA) { + bcw_phy_write16(sc, BCW_PHY_ILT_A_CTRL, offset); + bcw_phy_write16(sc, BCW_PHY_ILT_A_DATA1, val); + } else { + bcw_phy_write16(sc, BCW_PHY_ILT_G_CTRL, offset); + bcw_phy_write16(sc, BCW_PHY_ILT_G_DATA1, val); + } +} + +uint16_t +bcw_ilt_read(struct bcw_softc *sc, uint16_t offset) +{ + if (sc->sc_phy_type == BCW_PHY_TYPEA) { + bcw_phy_write16(sc, BCW_PHY_ILT_A_CTRL, offset); + return (bcw_phy_read16(sc, BCW_PHY_ILT_A_DATA1)); + } else { + bcw_phy_write16(sc, BCW_PHY_ILT_G_CTRL, offset); + return (bcw_phy_read16(sc, BCW_PHY_ILT_G_DATA1)); + } +} diff --git a/sys/dev/ic/bcwreg.h b/sys/dev/ic/bcwreg.h index 5cae7c380a9..e05cc0eb539 100644 --- a/sys/dev/ic/bcwreg.h +++ b/sys/dev/ic/bcwreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bcwreg.h,v 1.12 2007/02/18 09:37:21 mglocker Exp $ */ +/* $OpenBSD: bcwreg.h,v 1.13 2007/02/20 21:24:36 mglocker Exp $ */ /* * Copyright (c) 2006 Jon Simola <jsimola@gmail.com> @@ -344,6 +344,16 @@ /* LEDS */ #define BCW_NR_LEDS 4 +/* PHY registers */ +#define BCW_PHY_G_LO_CONTROL 0x0810 +#define BCW_PHY_ILT_A_CTRL 0x0072 +#define BCW_PHY_ILT_A_DATA1 0x0073 +#define BCW_PHY_ILT_G_CTRL 0x0472 +#define BCW_PHY_ILT_G_DATA1 0x0473 +#define BCW_PHY_G_CRS 0x0429 +#define BCW_PHY_NRSSILT_CTRL 0x0803 +#define BCW_PHY_NRSSILT_DATA 0x0804 + #define BCW_READ16(sc, reg) \ bus_space_read_2((sc)->sc_iot, (sc)->sc_ioh, (reg)) #define BCW_READ(sc, reg) \ diff --git a/sys/dev/ic/bcwvar.h b/sys/dev/ic/bcwvar.h index 6d5acaedf5b..7e547eca329 100644 --- a/sys/dev/ic/bcwvar.h +++ b/sys/dev/ic/bcwvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bcwvar.h,v 1.15 2007/02/18 09:37:21 mglocker Exp $ */ +/* $OpenBSD: bcwvar.h,v 1.16 2007/02/20 21:24:36 mglocker Exp $ */ /* * Copyright (c) 2006 Jon Simola <jsimola@gmail.com> @@ -139,12 +139,29 @@ struct bcw_dma_slot { uint32_t addr; }; +struct bcw_lopair { + int8_t low; + int8_t high; + uint8_t used:1; +}; + #define CTRL_BC_MASK 0x1fff /* buffer byte count */ #define CTRL_EOT 0x10000000 /* end of descriptor table */ #define CTRL_IOC 0x20000000 /* interrupt on completion */ #define CTRL_EOF 0x40000000 /* end of frame */ #define CTRL_SOF 0x80000000 /* start of frame */ +/* ilt */ +#define BCW_ILT_FINEFREQA_SIZE 256 +#define BCW_ILT_FINEFREQG_SIZE 256 +#define BCW_ILT_NOISEA2_SIZE 8 +#define BCW_ILT_NOISEA3_SIZE 8 +#define BCW_ILT_NOISEG1_SIZE 8 +#define BCW_ILT_NOISEG2_SIZE 8 +#define BCW_ILT_ROTOR_SIZE 53 +#define BCW_ILT_RETARD_SIZE 53 +#define BCW_ILT_SIGMASQR_SIZE 53 +#define BCW_ILT_NOISESCALEG_SIZE 27 #if 0 /* @@ -212,10 +229,13 @@ struct bcw_softc { uint16_t sc_phy_version; uint16_t sc_phy_type; uint16_t sc_phy_rev; + uint16_t sc_phy_loopback_gain[2]; + struct bcw_lopair *sc_phy_lopairs; // uint16_t sc_corerev; uint32_t sc_radio_mnf; uint16_t sc_radio_rev; uint16_t sc_radio_ver; + uint16_t sc_radio_initval; uint32_t sc_phyinfo; uint16_t sc_numcores; uint16_t sc_havecommon; @@ -228,6 +248,10 @@ struct bcw_softc { uint16_t sc_radio_pa1b0; uint16_t sc_radio_pa1b1; uint16_t sc_radio_pa1b2; + uint16_t sc_radio_baseband_atten; + uint16_t sc_radio_radio_atten; + uint16_t sc_radio_txctl1; + uint16_t sc_radio_txctl2; uint8_t sc_idletssi; uint8_t sc_spromrev; uint16_t sc_boardflags; |