// SPDX-License-Identifier: GPL-2.0-only
/*
* RTL8XXXU mac80211 USB driver - 8192e specific subdriver
*
* Copyright (c) 2014 - 2017 Jes Sorensen <Jes.Sorensen@gmail.com>
*
* Portions, notably calibration code:
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
*
* This driver was written as a replacement for the vendor provided
* rtl8723au driver. As the Realtek 8xxx chips are very similar in
* their programming interface, I have started adding support for
* additional 8xxx chips like the 8192cu, 8188cus, etc.
*/
#include "regs.h"
#include "rtl8xxxu.h"
static const struct rtl8xxxu_reg8val rtl8192e_mac_init_table[] = {
{0 x011, 0 xeb}, {0 x012, 0 x07}, {0 x014, 0 x75}, {0 x303, 0 xa7},
{0 x428, 0 x0a}, {0 x429, 0 x10}, {0 x430, 0 x00}, {0 x431, 0 x00},
{0 x432, 0 x00}, {0 x433, 0 x01}, {0 x434, 0 x04}, {0 x435, 0 x05},
{0 x436, 0 x07}, {0 x437, 0 x08}, {0 x43c, 0 x04}, {0 x43d, 0 x05},
{0 x43e, 0 x07}, {0 x43f, 0 x08}, {0 x440, 0 x5d}, {0 x441, 0 x01},
{0 x442, 0 x00}, {0 x444, 0 x10}, {0 x445, 0 x00}, {0 x446, 0 x00},
{0 x447, 0 x00}, {0 x448, 0 x00}, {0 x449, 0 xf0}, {0 x44a, 0 x0f},
{0 x44b, 0 x3e}, {0 x44c, 0 x10}, {0 x44d, 0 x00}, {0 x44e, 0 x00},
{0 x44f, 0 x00}, {0 x450, 0 x00}, {0 x451, 0 xf0}, {0 x452, 0 x0f},
{0 x453, 0 x00}, {0 x456, 0 x5e}, {0 x460, 0 x66}, {0 x461, 0 x66},
{0 x4c8, 0 xff}, {0 x4c9, 0 x08}, {0 x4cc, 0 xff}, {0 x4cd, 0 xff},
{0 x4ce, 0 x01}, {0 x500, 0 x26}, {0 x501, 0 xa2}, {0 x502, 0 x2f},
{0 x503, 0 x00}, {0 x504, 0 x28}, {0 x505, 0 xa3}, {0 x506, 0 x5e},
{0 x507, 0 x00}, {0 x508, 0 x2b}, {0 x509, 0 xa4}, {0 x50a, 0 x5e},
{0 x50b, 0 x00}, {0 x50c, 0 x4f}, {0 x50d, 0 xa4}, {0 x50e, 0 x00},
{0 x50f, 0 x00}, {0 x512, 0 x1c}, {0 x514, 0 x0a}, {0 x516, 0 x0a},
{0 x525, 0 x4f}, {0 x540, 0 x12}, {0 x541, 0 x64}, {0 x550, 0 x10},
{0 x551, 0 x10}, {0 x559, 0 x02}, {0 x55c, 0 x50}, {0 x55d, 0 xff},
{0 x605, 0 x30}, {0 x608, 0 x0e}, {0 x609, 0 x2a}, {0 x620, 0 xff},
{0 x621, 0 xff}, {0 x622, 0 xff}, {0 x623, 0 xff}, {0 x624, 0 xff},
{0 x625, 0 xff}, {0 x626, 0 xff}, {0 x627, 0 xff}, {0 x638, 0 x50},
{0 x63c, 0 x0a}, {0 x63d, 0 x0a}, {0 x63e, 0 x0e}, {0 x63f, 0 x0e},
{0 x640, 0 x40}, {0 x642, 0 x40}, {0 x643, 0 x00}, {0 x652, 0 xc8},
{0 x66e, 0 x05}, {0 x700, 0 x21}, {0 x701, 0 x43}, {0 x702, 0 x65},
{0 x703, 0 x87}, {0 x708, 0 x21}, {0 x709, 0 x43}, {0 x70a, 0 x65},
{0 x70b, 0 x87},
{0 xffff, 0 xff},
};
static const struct rtl8xxxu_reg32val rtl8192eu_phy_init_table[] = {
{0 x800, 0 x80040000}, {0 x804, 0 x00000003},
{0 x808, 0 x0000fc00}, {0 x80c, 0 x0000000a},
{0 x810, 0 x10001331}, {0 x814, 0 x020c3d10},
{0 x818, 0 x02220385}, {0 x81c, 0 x00000000},
{0 x820, 0 x01000100}, {0 x824, 0 x00390204},
{0 x828, 0 x01000100}, {0 x82c, 0 x00390204},
{0 x830, 0 x32323232}, {0 x834, 0 x30303030},
{0 x838, 0 x30303030}, {0 x83c, 0 x30303030},
{0 x840, 0 x00010000}, {0 x844, 0 x00010000},
{0 x848, 0 x28282828}, {0 x84c, 0 x28282828},
{0 x850, 0 x00000000}, {0 x854, 0 x00000000},
{0 x858, 0 x009a009a}, {0 x85c, 0 x01000014},
{0 x860, 0 x66f60000}, {0 x864, 0 x061f0000},
{0 x868, 0 x30303030}, {0 x86c, 0 x30303030},
{0 x870, 0 x00000000}, {0 x874, 0 x55004200},
{0 x878, 0 x08080808}, {0 x87c, 0 x00000000},
{0 x880, 0 xb0000c1c}, {0 x884, 0 x00000001},
{0 x888, 0 x00000000}, {0 x88c, 0 xcc0000c0},
{0 x890, 0 x00000800}, {0 x894, 0 xfffffffe},
{0 x898, 0 x40302010}, {0 x900, 0 x00000000},
{0 x904, 0 x00000023}, {0 x908, 0 x00000000},
{0 x90c, 0 x81121313}, {0 x910, 0 x806c0001},
{0 x914, 0 x00000001}, {0 x918, 0 x00000000},
{0 x91c, 0 x00010000}, {0 x924, 0 x00000001},
{0 x928, 0 x00000000}, {0 x92c, 0 x00000000},
{0 x930, 0 x00000000}, {0 x934, 0 x00000000},
{0 x938, 0 x00000000}, {0 x93c, 0 x00000000},
{0 x940, 0 x00000000}, {0 x944, 0 x00000000},
{0 x94c, 0 x00000008}, {0 xa00, 0 x00d0c7c8},
{0 xa04, 0 x81ff000c}, {0 xa08, 0 x8c838300},
{0 xa0c, 0 x2e68120f}, {0 xa10, 0 x95009b78},
{0 xa14, 0 x1114d028}, {0 xa18, 0 x00881117},
{0 xa1c, 0 x89140f00}, {0 xa20, 0 x1a1b0000},
{0 xa24, 0 x090e1317}, {0 xa28, 0 x00000204},
{0 xa2c, 0 x00d30000}, {0 xa70, 0 x101fff00},
{0 xa74, 0 x00000007}, {0 xa78, 0 x00000900},
{0 xa7c, 0 x225b0606}, {0 xa80, 0 x218075b1},
{0 xb38, 0 x00000000}, {0 xc00, 0 x48071d40},
{0 xc04, 0 x03a05633}, {0 xc08, 0 x000000e4},
{0 xc0c, 0 x6c6c6c6c}, {0 xc10, 0 x08800000},
{0 xc14, 0 x40000100}, {0 xc18, 0 x08800000},
{0 xc1c, 0 x40000100}, {0 xc20, 0 x00000000},
{0 xc24, 0 x00000000}, {0 xc28, 0 x00000000},
{0 xc2c, 0 x00000000}, {0 xc30, 0 x69e9ac47},
{0 xc34, 0 x469652af}, {0 xc38, 0 x49795994},
{0 xc3c, 0 x0a97971c}, {0 xc40, 0 x1f7c403f},
{0 xc44, 0 x000100b7}, {0 xc48, 0 xec020107},
{0 xc4c, 0 x007f037f},
#ifdef EXT_PA_8192EU
/* External PA or external LNA */
{0 xc50, 0 x00340220},
#else
{0 xc50, 0 x00340020},
#endif
{0 xc54, 0 x0080801f},
#ifdef EXT_PA_8192EU
/* External PA or external LNA */
{0 xc58, 0 x00000220},
#else
{0 xc58, 0 x00000020},
#endif
{0 xc5c, 0 x00248492}, {0 xc60, 0 x00000000},
{0 xc64, 0 x7112848b}, {0 xc68, 0 x47c00bff},
{0 xc6c, 0 x00000036}, {0 xc70, 0 x00000600},
{0 xc74, 0 x02013169}, {0 xc78, 0 x0000001f},
{0 xc7c, 0 x00b91612},
#ifdef EXT_PA_8192EU
/* External PA or external LNA */
{0 xc80, 0 x2d4000b5},
#else
{0 xc80, 0 x40000100},
#endif
{0 xc84, 0 x21f60000},
#ifdef EXT_PA_8192EU
/* External PA or external LNA */
{0 xc88, 0 x2d4000b5},
#else
{0 xc88, 0 x40000100},
#endif
{0 xc8c, 0 xa0e40000}, {0 xc90, 0 x00121820},
{0 xc94, 0 x00000000}, {0 xc98, 0 x00121820},
{0 xc9c, 0 x00007f7f}, {0 xca0, 0 x00000000},
{0 xca4, 0 x000300a0}, {0 xca8, 0 x00000000},
{0 xcac, 0 x00000000}, {0 xcb0, 0 x00000000},
{0 xcb4, 0 x00000000}, {0 xcb8, 0 x00000000},
{0 xcbc, 0 x28000000}, {0 xcc0, 0 x00000000},
{0 xcc4, 0 x00000000}, {0 xcc8, 0 x00000000},
{0 xccc, 0 x00000000}, {0 xcd0, 0 x00000000},
{0 xcd4, 0 x00000000}, {0 xcd8, 0 x64b22427},
{0 xcdc, 0 x00766932}, {0 xce0, 0 x00222222},
{0 xce4, 0 x00040000}, {0 xce8, 0 x77644302},
{0 xcec, 0 x2f97d40c}, {0 xd00, 0 x00080740},
{0 xd04, 0 x00020403}, {0 xd08, 0 x0000907f},
{0 xd0c, 0 x20010201}, {0 xd10, 0 xa0633333},
{0 xd14, 0 x3333bc43}, {0 xd18, 0 x7a8f5b6b},
{0 xd1c, 0 x0000007f}, {0 xd2c, 0 xcc979975},
{0 xd30, 0 x00000000}, {0 xd34, 0 x80608000},
{0 xd38, 0 x00000000}, {0 xd3c, 0 x00127353},
{0 xd40, 0 x00000000}, {0 xd44, 0 x00000000},
{0 xd48, 0 x00000000}, {0 xd4c, 0 x00000000},
{0 xd50, 0 x6437140a}, {0 xd54, 0 x00000000},
{0 xd58, 0 x00000282}, {0 xd5c, 0 x30032064},
{0 xd60, 0 x4653de68}, {0 xd64, 0 x04518a3c},
{0 xd68, 0 x00002101}, {0 xd6c, 0 x2a201c16},
{0 xd70, 0 x1812362e}, {0 xd74, 0 x322c2220},
{0 xd78, 0 x000e3c24}, {0 xd80, 0 x01081008},
{0 xd84, 0 x00000800}, {0 xd88, 0 xf0b50000},
{0 xe00, 0 x30303030}, {0 xe04, 0 x30303030},
{0 xe08, 0 x03903030}, {0 xe10, 0 x30303030},
{0 xe14, 0 x30303030}, {0 xe18, 0 x30303030},
{0 xe1c, 0 x30303030}, {0 xe28, 0 x00000000},
{0 xe30, 0 x1000dc1f}, {0 xe34, 0 x10008c1f},
{0 xe38, 0 x02140102}, {0 xe3c, 0 x681604c2},
{0 xe40, 0 x01007c00}, {0 xe44, 0 x01004800},
{0 xe48, 0 xfb000000}, {0 xe4c, 0 x000028d1},
{0 xe50, 0 x1000dc1f}, {0 xe54, 0 x10008c1f},
{0 xe58, 0 x02140102}, {0 xe5c, 0 x28160d05},
{0 xe60, 0 x00000008}, {0 xe68, 0 x0fc05656},
{0 xe6c, 0 x03c09696}, {0 xe70, 0 x03c09696},
{0 xe74, 0 x0c005656}, {0 xe78, 0 x0c005656},
{0 xe7c, 0 x0c005656}, {0 xe80, 0 x0c005656},
{0 xe84, 0 x03c09696}, {0 xe88, 0 x0c005656},
{0 xe8c, 0 x03c09696}, {0 xed0, 0 x03c09696},
{0 xed4, 0 x03c09696}, {0 xed8, 0 x03c09696},
{0 xedc, 0 x0000d6d6}, {0 xee0, 0 x0000d6d6},
{0 xeec, 0 x0fc01616}, {0 xee4, 0 xb0000c1c},
{0 xee8, 0 x00000001}, {0 xf14, 0 x00000003},
{0 xf4c, 0 x00000000}, {0 xf00, 0 x00000300},
{0 xffff, 0 xffffffff},
};
static const struct rtl8xxxu_reg32val rtl8xxx_agc_8192eu_std_table[] = {
{0 xc78, 0 xfb000001}, {0 xc78, 0 xfb010001},
{0 xc78, 0 xfb020001}, {0 xc78, 0 xfb030001},
{0 xc78, 0 xfb040001}, {0 xc78, 0 xfb050001},
{0 xc78, 0 xfa060001}, {0 xc78, 0 xf9070001},
{0 xc78, 0 xf8080001}, {0 xc78, 0 xf7090001},
{0 xc78, 0 xf60a0001}, {0 xc78, 0 xf50b0001},
{0 xc78, 0 xf40c0001}, {0 xc78, 0 xf30d0001},
{0 xc78, 0 xf20e0001}, {0 xc78, 0 xf10f0001},
{0 xc78, 0 xf0100001}, {0 xc78, 0 xef110001},
{0 xc78, 0 xee120001}, {0 xc78, 0 xed130001},
{0 xc78, 0 xec140001}, {0 xc78, 0 xeb150001},
{0 xc78, 0 xea160001}, {0 xc78, 0 xe9170001},
{0 xc78, 0 xe8180001}, {0 xc78, 0 xe7190001},
{0 xc78, 0 xc81a0001}, {0 xc78, 0 xc71b0001},
{0 xc78, 0 xc61c0001}, {0 xc78, 0 x071d0001},
{0 xc78, 0 x061e0001}, {0 xc78, 0 x051f0001},
{0 xc78, 0 x04200001}, {0 xc78, 0 x03210001},
{0 xc78, 0 xaa220001}, {0 xc78, 0 xa9230001},
{0 xc78, 0 xa8240001}, {0 xc78, 0 xa7250001},
{0 xc78, 0 xa6260001}, {0 xc78, 0 x85270001},
{0 xc78, 0 x84280001}, {0 xc78, 0 x83290001},
{0 xc78, 0 x252a0001}, {0 xc78, 0 x242b0001},
{0 xc78, 0 x232c0001}, {0 xc78, 0 x222d0001},
{0 xc78, 0 x672e0001}, {0 xc78, 0 x662f0001},
{0 xc78, 0 x65300001}, {0 xc78, 0 x64310001},
{0 xc78, 0 x63320001}, {0 xc78, 0 x62330001},
{0 xc78, 0 x61340001}, {0 xc78, 0 x45350001},
{0 xc78, 0 x44360001}, {0 xc78, 0 x43370001},
{0 xc78, 0 x42380001}, {0 xc78, 0 x41390001},
{0 xc78, 0 x403a0001}, {0 xc78, 0 x403b0001},
{0 xc78, 0 x403c0001}, {0 xc78, 0 x403d0001},
{0 xc78, 0 x403e0001}, {0 xc78, 0 x403f0001},
{0 xc78, 0 xfb400001}, {0 xc78, 0 xfb410001},
{0 xc78, 0 xfb420001}, {0 xc78, 0 xfb430001},
{0 xc78, 0 xfb440001}, {0 xc78, 0 xfb450001},
{0 xc78, 0 xfa460001}, {0 xc78, 0 xf9470001},
{0 xc78, 0 xf8480001}, {0 xc78, 0 xf7490001},
{0 xc78, 0 xf64a0001}, {0 xc78, 0 xf54b0001},
{0 xc78, 0 xf44c0001}, {0 xc78, 0 xf34d0001},
{0 xc78, 0 xf24e0001}, {0 xc78, 0 xf14f0001},
{0 xc78, 0 xf0500001}, {0 xc78, 0 xef510001},
{0 xc78, 0 xee520001}, {0 xc78, 0 xed530001},
{0 xc78, 0 xec540001}, {0 xc78, 0 xeb550001},
{0 xc78, 0 xea560001}, {0 xc78, 0 xe9570001},
{0 xc78, 0 xe8580001}, {0 xc78, 0 xe7590001},
{0 xc78, 0 xe65a0001}, {0 xc78, 0 xe55b0001},
{0 xc78, 0 xe45c0001}, {0 xc78, 0 xe35d0001},
{0 xc78, 0 xe25e0001}, {0 xc78, 0 xe15f0001},
{0 xc78, 0 x8a600001}, {0 xc78, 0 x89610001},
{0 xc78, 0 x88620001}, {0 xc78, 0 x87630001},
{0 xc78, 0 x86640001}, {0 xc78, 0 x85650001},
{0 xc78, 0 x84660001}, {0 xc78, 0 x83670001},
{0 xc78, 0 x82680001}, {0 xc78, 0 x6b690001},
{0 xc78, 0 x6a6a0001}, {0 xc78, 0 x696b0001},
{0 xc78, 0 x686c0001}, {0 xc78, 0 x676d0001},
{0 xc78, 0 x666e0001}, {0 xc78, 0 x656f0001},
{0 xc78, 0 x64700001}, {0 xc78, 0 x63710001},
{0 xc78, 0 x62720001}, {0 xc78, 0 x61730001},
{0 xc78, 0 x49740001}, {0 xc78, 0 x48750001},
{0 xc78, 0 x47760001}, {0 xc78, 0 x46770001},
{0 xc78, 0 x45780001}, {0 xc78, 0 x44790001},
{0 xc78, 0 x437a0001}, {0 xc78, 0 x427b0001},
{0 xc78, 0 x417c0001}, {0 xc78, 0 x407d0001},
{0 xc78, 0 x407e0001}, {0 xc78, 0 x407f0001},
{0 xc50, 0 x00040022}, {0 xc50, 0 x00040020},
{0 xffff, 0 xffffffff}
};
static const struct rtl8xxxu_reg32val rtl8xxx_agc_8192eu_highpa_table[] = {
{0 xc78, 0 xfa000001}, {0 xc78, 0 xf9010001},
{0 xc78, 0 xf8020001}, {0 xc78, 0 xf7030001},
{0 xc78, 0 xf6040001}, {0 xc78, 0 xf5050001},
{0 xc78, 0 xf4060001}, {0 xc78, 0 xf3070001},
{0 xc78, 0 xf2080001}, {0 xc78, 0 xf1090001},
{0 xc78, 0 xf00a0001}, {0 xc78, 0 xef0b0001},
{0 xc78, 0 xee0c0001}, {0 xc78, 0 xed0d0001},
{0 xc78, 0 xec0e0001}, {0 xc78, 0 xeb0f0001},
{0 xc78, 0 xea100001}, {0 xc78, 0 xe9110001},
{0 xc78, 0 xe8120001}, {0 xc78, 0 xe7130001},
{0 xc78, 0 xe6140001}, {0 xc78, 0 xe5150001},
{0 xc78, 0 xe4160001}, {0 xc78, 0 xe3170001},
{0 xc78, 0 xe2180001}, {0 xc78, 0 xe1190001},
{0 xc78, 0 x8a1a0001}, {0 xc78, 0 x891b0001},
{0 xc78, 0 x881c0001}, {0 xc78, 0 x871d0001},
{0 xc78, 0 x861e0001}, {0 xc78, 0 x851f0001},
{0 xc78, 0 x84200001}, {0 xc78, 0 x83210001},
{0 xc78, 0 x82220001}, {0 xc78, 0 x6a230001},
{0 xc78, 0 x69240001}, {0 xc78, 0 x68250001},
{0 xc78, 0 x67260001}, {0 xc78, 0 x66270001},
{0 xc78, 0 x65280001}, {0 xc78, 0 x64290001},
{0 xc78, 0 x632a0001}, {0 xc78, 0 x622b0001},
{0 xc78, 0 x612c0001}, {0 xc78, 0 x602d0001},
{0 xc78, 0 x472e0001}, {0 xc78, 0 x462f0001},
{0 xc78, 0 x45300001}, {0 xc78, 0 x44310001},
{0 xc78, 0 x43320001}, {0 xc78, 0 x42330001},
{0 xc78, 0 x41340001}, {0 xc78, 0 x40350001},
{0 xc78, 0 x40360001}, {0 xc78, 0 x40370001},
{0 xc78, 0 x40380001}, {0 xc78, 0 x40390001},
{0 xc78, 0 x403a0001}, {0 xc78, 0 x403b0001},
{0 xc78, 0 x403c0001}, {0 xc78, 0 x403d0001},
{0 xc78, 0 x403e0001}, {0 xc78, 0 x403f0001},
{0 xc78, 0 xfa400001}, {0 xc78, 0 xf9410001},
{0 xc78, 0 xf8420001}, {0 xc78, 0 xf7430001},
{0 xc78, 0 xf6440001}, {0 xc78, 0 xf5450001},
{0 xc78, 0 xf4460001}, {0 xc78, 0 xf3470001},
{0 xc78, 0 xf2480001}, {0 xc78, 0 xf1490001},
{0 xc78, 0 xf04a0001}, {0 xc78, 0 xef4b0001},
{0 xc78, 0 xee4c0001}, {0 xc78, 0 xed4d0001},
{0 xc78, 0 xec4e0001}, {0 xc78, 0 xeb4f0001},
{0 xc78, 0 xea500001}, {0 xc78, 0 xe9510001},
{0 xc78, 0 xe8520001}, {0 xc78, 0 xe7530001},
{0 xc78, 0 xe6540001}, {0 xc78, 0 xe5550001},
{0 xc78, 0 xe4560001}, {0 xc78, 0 xe3570001},
{0 xc78, 0 xe2580001}, {0 xc78, 0 xe1590001},
{0 xc78, 0 x8a5a0001}, {0 xc78, 0 x895b0001},
{0 xc78, 0 x885c0001}, {0 xc78, 0 x875d0001},
{0 xc78, 0 x865e0001}, {0 xc78, 0 x855f0001},
{0 xc78, 0 x84600001}, {0 xc78, 0 x83610001},
{0 xc78, 0 x82620001}, {0 xc78, 0 x6a630001},
{0 xc78, 0 x69640001}, {0 xc78, 0 x68650001},
{0 xc78, 0 x67660001}, {0 xc78, 0 x66670001},
{0 xc78, 0 x65680001}, {0 xc78, 0 x64690001},
{0 xc78, 0 x636a0001}, {0 xc78, 0 x626b0001},
{0 xc78, 0 x616c0001}, {0 xc78, 0 x606d0001},
{0 xc78, 0 x476e0001}, {0 xc78, 0 x466f0001},
{0 xc78, 0 x45700001}, {0 xc78, 0 x44710001},
{0 xc78, 0 x43720001}, {0 xc78, 0 x42730001},
{0 xc78, 0 x41740001}, {0 xc78, 0 x40750001},
{0 xc78, 0 x40760001}, {0 xc78, 0 x40770001},
{0 xc78, 0 x40780001}, {0 xc78, 0 x40790001},
{0 xc78, 0 x407a0001}, {0 xc78, 0 x407b0001},
{0 xc78, 0 x407c0001}, {0 xc78, 0 x407d0001},
{0 xc78, 0 x407e0001}, {0 xc78, 0 x407f0001},
{0 xc50, 0 x00040222}, {0 xc50, 0 x00040220},
{0 xffff, 0 xffffffff}
};
static const struct rtl8xxxu_rfregval rtl8192eu_radioa_init_table[] = {
{0 x7f, 0 x00000082}, {0 x81, 0 x0003fc00},
{0 x00, 0 x00030000}, {0 x08, 0 x00008400},
{0 x18, 0 x00000407}, {0 x19, 0 x00000012},
{0 x1b, 0 x00000064}, {0 x1e, 0 x00080009},
{0 x1f, 0 x00000880}, {0 x2f, 0 x0001a060},
{0 x3f, 0 x00000000}, {0 x42, 0 x000060c0},
{0 x57, 0 x000d0000}, {0 x58, 0 x000be180},
{0 x67, 0 x00001552}, {0 x83, 0 x00000000},
{0 xb0, 0 x000ff9f1}, {0 xb1, 0 x00055418},
{0 xb2, 0 x0008cc00}, {0 xb4, 0 x00043083},
{0 xb5, 0 x00008166}, {0 xb6, 0 x0000803e},
{0 xb7, 0 x0001c69f}, {0 xb8, 0 x0000407f},
{0 xb9, 0 x00080001}, {0 xba, 0 x00040001},
{0 xbb, 0 x00000400}, {0 xbf, 0 x000c0000},
{0 xc2, 0 x00002400}, {0 xc3, 0 x00000009},
{0 xc4, 0 x00040c91}, {0 xc5, 0 x00099999},
{0 xc6, 0 x000000a3}, {0 xc7, 0 x00088820},
{0 xc8, 0 x00076c06}, {0 xc9, 0 x00000000},
{0 xca, 0 x00080000}, {0 xdf, 0 x00000180},
{0 xef, 0 x000001a0}, {0 x51, 0 x00069545},
{0 x52, 0 x0007e45e}, {0 x53, 0 x00000071},
{0 x56, 0 x00051ff3}, {0 x35, 0 x000000a8},
{0 x35, 0 x000001e2}, {0 x35, 0 x000002a8},
{0 x36, 0 x00001c24}, {0 x36, 0 x00009c24},
{0 x36, 0 x00011c24}, {0 x36, 0 x00019c24},
{0 x18, 0 x00000c07}, {0 x5a, 0 x00048000},
{0 x19, 0 x000739d0},
#ifdef EXT_PA_8192EU
/* External PA or external LNA */
{0 x34, 0 x0000a093}, {0 x34, 0 x0000908f},
{0 x34, 0 x0000808c}, {0 x34, 0 x0000704d},
{0 x34, 0 x0000604a}, {0 x34, 0 x00005047},
{0 x34, 0 x0000400a}, {0 x34, 0 x00003007},
{0 x34, 0 x00002004}, {0 x34, 0 x00001001},
{0 x34, 0 x00000000},
#else
/* Regular */
{0 x34, 0 x0000add7}, {0 x34, 0 x00009dd4},
{0 x34, 0 x00008dd1}, {0 x34, 0 x00007dce},
{0 x34, 0 x00006dcb}, {0 x34, 0 x00005dc8},
{0 x34, 0 x00004dc5}, {0 x34, 0 x000034cc},
{0 x34, 0 x0000244f}, {0 x34, 0 x0000144c},
{0 x34, 0 x00000014},
#endif
{0 x00, 0 x00030159},
{0 x84, 0 x00068180},
{0 x86, 0 x0000014e},
{0 x87, 0 x00048e00},
{0 x8e, 0 x00065540},
{0 x8f, 0 x00088000},
{0 xef, 0 x000020a0},
#ifdef EXT_PA_8192EU
/* External PA or external LNA */
{0 x3b, 0 x000f07b0},
#else
{0 x3b, 0 x000f02b0},
#endif
{0 x3b, 0 x000ef7b0}, {0 x3b, 0 x000d4fb0},
{0 x3b, 0 x000cf060}, {0 x3b, 0 x000b0090},
{0 x3b, 0 x000a0080}, {0 x3b, 0 x00090080},
{0 x3b, 0 x0008f780},
#ifdef EXT_PA_8192EU
/* External PA or external LNA */
{0 x3b, 0 x000787b0},
#else
{0 x3b, 0 x00078730},
#endif
{0 x3b, 0 x00060fb0}, {0 x3b, 0 x0005ffa0},
{0 x3b, 0 x00040620}, {0 x3b, 0 x00037090},
{0 x3b, 0 x00020080}, {0 x3b, 0 x0001f060},
{0 x3b, 0 x0000ffb0}, {0 xef, 0 x000000a0},
{0 xfe, 0 x00000000}, {0 x18, 0 x0000fc07},
{0 xfe, 0 x00000000}, {0 xfe, 0 x00000000},
{0 xfe, 0 x00000000}, {0 xfe, 0 x00000000},
{0 x1e, 0 x00000001}, {0 x1f, 0 x00080000},
{0 x00, 0 x00033e70},
{0 xff, 0 xffffffff}
};
static const struct rtl8xxxu_rfregval rtl8192eu_radiob_init_table[] = {
{0 x7f, 0 x00000082}, {0 x81, 0 x0003fc00},
{0 x00, 0 x00030000}, {0 x08, 0 x00008400},
{0 x18, 0 x00000407}, {0 x19, 0 x00000012},
{0 x1b, 0 x00000064}, {0 x1e, 0 x00080009},
{0 x1f, 0 x00000880}, {0 x2f, 0 x0001a060},
{0 x3f, 0 x00000000}, {0 x42, 0 x000060c0},
{0 x57, 0 x000d0000}, {0 x58, 0 x000be180},
{0 x67, 0 x00001552}, {0 x7f, 0 x00000082},
{0 x81, 0 x0003f000}, {0 x83, 0 x00000000},
{0 xdf, 0 x00000180}, {0 xef, 0 x000001a0},
{0 x51, 0 x00069545}, {0 x52, 0 x0007e42e},
{0 x53, 0 x00000071}, {0 x56, 0 x00051ff3},
{0 x35, 0 x000000a8}, {0 x35, 0 x000001e0},
{0 x35, 0 x000002a8}, {0 x36, 0 x00001ca8},
{0 x36, 0 x00009c24}, {0 x36, 0 x00011c24},
{0 x36, 0 x00019c24}, {0 x18, 0 x00000c07},
{0 x5a, 0 x00048000}, {0 x19, 0 x000739d0},
#ifdef EXT_PA_8192EU
/* External PA or external LNA */
{0 x34, 0 x0000a093}, {0 x34, 0 x0000908f},
{0 x34, 0 x0000808c}, {0 x34, 0 x0000704d},
{0 x34, 0 x0000604a}, {0 x34, 0 x00005047},
{0 x34, 0 x0000400a}, {0 x34, 0 x00003007},
{0 x34, 0 x00002004}, {0 x34, 0 x00001001},
{0 x34, 0 x00000000},
#else
{0 x34, 0 x0000add7}, {0 x34, 0 x00009dd4},
{0 x34, 0 x00008dd1}, {0 x34, 0 x00007dce},
{0 x34, 0 x00006dcb}, {0 x34, 0 x00005dc8},
{0 x34, 0 x00004dc5}, {0 x34, 0 x000034cc},
{0 x34, 0 x0000244f}, {0 x34, 0 x0000144c},
{0 x34, 0 x00000014},
#endif
{0 x00, 0 x00030159}, {0 x84, 0 x00068180},
{0 x86, 0 x000000ce}, {0 x87, 0 x00048a00},
{0 x8e, 0 x00065540}, {0 x8f, 0 x00088000},
{0 xef, 0 x000020a0},
#ifdef EXT_PA_8192EU
/* External PA or external LNA */
{0 x3b, 0 x000f07b0},
#else
{0 x3b, 0 x000f02b0},
#endif
{0 x3b, 0 x000ef7b0}, {0 x3b, 0 x000d4fb0},
{0 x3b, 0 x000cf060}, {0 x3b, 0 x000b0090},
{0 x3b, 0 x000a0080}, {0 x3b, 0 x00090080},
{0 x3b, 0 x0008f780},
#ifdef EXT_PA_8192EU
/* External PA or external LNA */
{0 x3b, 0 x000787b0},
#else
{0 x3b, 0 x00078730},
#endif
{0 x3b, 0 x00060fb0}, {0 x3b, 0 x0005ffa0},
{0 x3b, 0 x00040620}, {0 x3b, 0 x00037090},
{0 x3b, 0 x00020080}, {0 x3b, 0 x0001f060},
{0 x3b, 0 x0000ffb0}, {0 xef, 0 x000000a0},
{0 x00, 0 x00010159}, {0 xfe, 0 x00000000},
{0 xfe, 0 x00000000}, {0 xfe, 0 x00000000},
{0 xfe, 0 x00000000}, {0 x1e, 0 x00000001},
{0 x1f, 0 x00080000}, {0 x00, 0 x00033e70},
{0 xff, 0 xffffffff}
};
static int rtl8192eu_identify_chip(struct rtl8xxxu_priv *priv)
{
struct device *dev = &priv->udev->dev;
u32 val32, bonding, sys_cfg, vendor;
int ret = 0 ;
sys_cfg = rtl8xxxu_read32(priv, REG_SYS_CFG);
priv->chip_cut = u32_get_bits(sys_cfg, SYS_CFG_CHIP_VERSION_MASK);
if (sys_cfg & SYS_CFG_TRP_VAUX_EN) {
dev_info(dev, "Unsupported test chip\n" );
ret = -ENOTSUPP;
goto out;
}
bonding = rtl8xxxu_read32(priv, REG_HPON_FSM);
bonding &= HPON_FSM_BONDING_MASK;
if (bonding == HPON_FSM_BONDING_1T2R) {
strscpy(priv->chip_name, "8191EU" , sizeof (priv->chip_name));
priv->tx_paths = 1 ;
priv->rtl_chip = RTL8191E;
} else {
strscpy(priv->chip_name, "8192EU" , sizeof (priv->chip_name));
priv->tx_paths = 2 ;
priv->rtl_chip = RTL8192E;
}
priv->rf_paths = 2 ;
priv->rx_paths = 2 ;
priv->has_wifi = 1 ;
vendor = sys_cfg & SYS_CFG_VENDOR_EXT_MASK;
rtl8xxxu_identify_vendor_2bits(priv, vendor);
val32 = rtl8xxxu_read32(priv, REG_GPIO_OUTSTS);
priv->rom_rev = u32_get_bits(val32, GPIO_RF_RL_ID);
rtl8xxxu_config_endpoints_sie(priv);
/*
* Fallback for devices that do not provide REG_NORMAL_SIE_EP_TX
*/
if (!priv->ep_tx_count)
ret = rtl8xxxu_config_endpoints_no_sie(priv);
out:
return ret;
}
static void
rtl8192e_set_tx_power(struct rtl8xxxu_priv *priv, int channel, bool ht40)
{
u32 val32, ofdm, mcs;
u8 cck, ofdmbase, mcsbase;
int group, tx_idx;
tx_idx = 0 ;
group = rtl8xxxu_gen2_channel_to_group(channel);
cck = priv->cck_tx_power_index_A[group];
val32 = rtl8xxxu_read32(priv, REG_TX_AGC_A_CCK1_MCS32);
val32 &= 0 xffff00ff;
val32 |= (cck << 8 );
rtl8xxxu_write32(priv, REG_TX_AGC_A_CCK1_MCS32, val32);
val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11);
val32 &= 0 xff;
val32 |= ((cck << 8 ) | (cck << 16 ) | (cck << 24 ));
rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32);
ofdmbase = priv->ht40_1s_tx_power_index_A[group];
ofdmbase += priv->ofdm_tx_power_diff[tx_idx].a;
ofdm = ofdmbase | ofdmbase << 8 | ofdmbase << 16 | ofdmbase << 24 ;
rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE18_06, ofdm);
rtl8xxxu_write32(priv, REG_TX_AGC_A_RATE54_24, ofdm);
mcsbase = priv->ht40_1s_tx_power_index_A[group];
if (ht40)
mcsbase += priv->ht40_tx_power_diff[tx_idx++].a;
else
mcsbase += priv->ht20_tx_power_diff[tx_idx++].a;
mcs = mcsbase | mcsbase << 8 | mcsbase << 16 | mcsbase << 24 ;
rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS03_MCS00, mcs);
rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS07_MCS04, mcs);
rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS11_MCS08, mcs);
rtl8xxxu_write32(priv, REG_TX_AGC_A_MCS15_MCS12, mcs);
if (priv->tx_paths > 1 ) {
cck = priv->cck_tx_power_index_B[group];
val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK1_55_MCS32);
val32 &= 0 xff;
val32 |= ((cck << 8 ) | (cck << 16 ) | (cck << 24 ));
rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK1_55_MCS32, val32);
val32 = rtl8xxxu_read32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11);
val32 &= 0 xffffff00;
val32 |= cck;
rtl8xxxu_write32(priv, REG_TX_AGC_B_CCK11_A_CCK2_11, val32);
ofdmbase = priv->ht40_1s_tx_power_index_B[group];
ofdmbase += priv->ofdm_tx_power_diff[tx_idx].b;
ofdm = ofdmbase | ofdmbase << 8 |
ofdmbase << 16 | ofdmbase << 24 ;
rtl8xxxu_write32(priv, REG_TX_AGC_B_RATE18_06, ofdm);
rtl8xxxu_write32(priv, REG_TX_AGC_B_RATE54_24, ofdm);
mcsbase = priv->ht40_1s_tx_power_index_B[group];
if (ht40)
mcsbase += priv->ht40_tx_power_diff[tx_idx++].b;
else
mcsbase += priv->ht20_tx_power_diff[tx_idx++].b;
mcs = mcsbase | mcsbase << 8 | mcsbase << 16 | mcsbase << 24 ;
rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS03_MCS00, mcs);
rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS07_MCS04, mcs);
rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS11_MCS08, mcs);
rtl8xxxu_write32(priv, REG_TX_AGC_B_MCS15_MCS12, mcs);
}
}
static int rtl8192eu_parse_efuse(struct rtl8xxxu_priv *priv)
{
struct rtl8192eu_efuse *efuse = &priv->efuse_wifi.efuse8192eu;
int i;
if (efuse->rtl_id != cpu_to_le16(0 x8129))
return -EINVAL;
ether_addr_copy(priv->mac_addr, efuse->mac_addr);
memcpy(priv->cck_tx_power_index_A, efuse->tx_power_index_A.cck_base,
sizeof (efuse->tx_power_index_A.cck_base));
memcpy(priv->cck_tx_power_index_B, efuse->tx_power_index_B.cck_base,
sizeof (efuse->tx_power_index_B.cck_base));
memcpy(priv->ht40_1s_tx_power_index_A,
efuse->tx_power_index_A.ht40_base,
sizeof (efuse->tx_power_index_A.ht40_base));
memcpy(priv->ht40_1s_tx_power_index_B,
efuse->tx_power_index_B.ht40_base,
sizeof (efuse->tx_power_index_B.ht40_base));
priv->ht20_tx_power_diff[0 ].a =
efuse->tx_power_index_A.ht20_ofdm_1s_diff.b;
priv->ht20_tx_power_diff[0 ].b =
efuse->tx_power_index_B.ht20_ofdm_1s_diff.b;
priv->ht40_tx_power_diff[0 ].a = 0 ;
priv->ht40_tx_power_diff[0 ].b = 0 ;
for (i = 1 ; i < RTL8723B_TX_COUNT; i++) {
priv->ofdm_tx_power_diff[i].a =
efuse->tx_power_index_A.pwr_diff[i - 1 ].ofdm;
priv->ofdm_tx_power_diff[i].b =
efuse->tx_power_index_B.pwr_diff[i - 1 ].ofdm;
priv->ht20_tx_power_diff[i].a =
efuse->tx_power_index_A.pwr_diff[i - 1 ].ht20;
priv->ht20_tx_power_diff[i].b =
efuse->tx_power_index_B.pwr_diff[i - 1 ].ht20;
priv->ht40_tx_power_diff[i].a =
efuse->tx_power_index_A.pwr_diff[i - 1 ].ht40;
priv->ht40_tx_power_diff[i].b =
efuse->tx_power_index_B.pwr_diff[i - 1 ].ht40;
}
priv->default_crystal_cap = priv->efuse_wifi.efuse8192eu.xtal_k & 0 x3f;
return 0 ;
}
static int rtl8192eu_load_firmware(struct rtl8xxxu_priv *priv)
{
const char *fw_name;
int ret;
fw_name = "rtlwifi/rtl8192eu_nic.bin" ;
ret = rtl8xxxu_load_firmware(priv, fw_name);
return ret;
}
static void rtl8192eu_init_phy_bb(struct rtl8xxxu_priv *priv)
{
u8 val8;
u16 val16;
val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
val16 |= SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB | SYS_FUNC_DIO_RF;
rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
/* 6. 0x1f[7:0] = 0x07 */
val8 = RF_ENABLE | RF_RSTB | RF_SDMRSTB;
rtl8xxxu_write8(priv, REG_RF_CTRL, val8);
val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
val16 |= (SYS_FUNC_USBA | SYS_FUNC_USBD | SYS_FUNC_DIO_RF |
SYS_FUNC_BB_GLB_RSTN | SYS_FUNC_BBRSTB);
rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
val8 = RF_ENABLE | RF_RSTB | RF_SDMRSTB;
rtl8xxxu_write8(priv, REG_RF_CTRL, val8);
rtl8xxxu_init_phy_regs(priv, rtl8192eu_phy_init_table);
if (priv->hi_pa)
rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_8192eu_highpa_table);
else
rtl8xxxu_init_phy_regs(priv, rtl8xxx_agc_8192eu_std_table);
}
static int rtl8192eu_init_phy_rf(struct rtl8xxxu_priv *priv)
{
int ret;
ret = rtl8xxxu_init_phy_rf(priv, rtl8192eu_radioa_init_table, RF_A);
if (ret)
goto exit ;
ret = rtl8xxxu_init_phy_rf(priv, rtl8192eu_radiob_init_table, RF_B);
exit :
return ret;
}
static int rtl8192eu_iqk_path_a(struct rtl8xxxu_priv *priv)
{
u32 reg_eac, reg_e94, reg_e9c;
int result = 0 ;
/*
* TX IQK
* PA/PAD controlled by 0x0
*/
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x00000000);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_GAIN_CCA, 0 x00180);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, 0 x800a0);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0 x20000);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0 x0000f);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0 x07f77);
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x80800000);
/* Path A IQK setting */
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0 x18008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0 x82140303);
rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0 x68160000);
/* LO calibration setting */
rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0 x00462911);
/* One shot, path A LOK & IQK */
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf9000000);
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf8000000);
mdelay(10 );
/* Check failed */
reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A);
reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A);
if (!(reg_eac & BIT(28 )) &&
((reg_e94 & 0 x03ff0000) != 0 x01420000) &&
((reg_e9c & 0 x03ff0000) != 0 x00420000))
result |= 0 x01;
return result;
}
static int rtl8192eu_rx_iqk_path_a(struct rtl8xxxu_priv *priv)
{
u32 reg_ea4, reg_eac, reg_e94, reg_e9c, val32;
int result = 0 ;
/* Leave IQK mode */
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x00);
/* Enable path A PA in TX IQK mode */
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, 0 x800a0);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0 x30000);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0 x0000f);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0 xf1173);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_WE_LUT, 0 x800a0);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_RCK_OS, 0 x30000);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_TXPA_G1, 0 x0000f);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_TXPA_G2, 0 xf1173);
/* PA/PAD control by 0x56, and set = 0x0 */
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_GAIN_CCA, 0 x00980);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_PAD_TXG, 0 x511e0);
/* Enter IQK mode */
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x80800000);
/* TX IQK setting */
rtl8xxxu_write32(priv, REG_TX_IQK, 0 x01007c00);
rtl8xxxu_write32(priv, REG_RX_IQK, 0 x01004800);
/* path-A IQK setting */
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0 x18008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0 x8216031f);
rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0 x6816031f);
/* LO calibration setting */
rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0 x0046a911);
/* One shot, path A LOK & IQK */
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf9000000);
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf8000000);
mdelay(10 );
/* Check failed */
reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
reg_e94 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_A);
reg_e9c = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_A);
if (!(reg_eac & BIT(28 )) &&
((reg_e94 & 0 x03ff0000) != 0 x01420000) &&
((reg_e9c & 0 x03ff0000) != 0 x00420000)) {
result |= 0 x01;
} else {
/* PA/PAD controlled by 0x0 */
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x00000000);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_GAIN_CCA, 0 x180);
goto out;
}
val32 = 0 x80007c00 |
(reg_e94 & 0 x03ff0000) | ((reg_e9c >> 16 ) & 0 x03ff);
rtl8xxxu_write32(priv, REG_TX_IQK, val32);
/* Modify RX IQK mode table */
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x00000000);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, 0 x800a0);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0 x30000);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0 x0000f);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0 xf7ff2);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_WE_LUT, 0 x800a0);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_RCK_OS, 0 x30000);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_TXPA_G1, 0 x0000f);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_TXPA_G2, 0 xf7ff2);
/* PA/PAD control by 0x56, and set = 0x0 */
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_GAIN_CCA, 0 x00980);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_PAD_TXG, 0 x510e0);
/* Enter IQK mode */
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x80800000);
/* IQK setting */
rtl8xxxu_write32(priv, REG_RX_IQK, 0 x01004800);
/* Path A IQK setting */
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0 x18008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0 x821608ff);
rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0 x281608ff);
/* LO calibration setting */
rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0 x0046a891);
/* One shot, path A LOK & IQK */
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf9000000);
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf8000000);
mdelay(10 );
reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
reg_ea4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_A_2);
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x00000000);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_GAIN_CCA, 0 x180);
if (!(reg_eac & BIT(27 )) &&
((reg_ea4 & 0 x03ff0000) != 0 x01320000) &&
((reg_eac & 0 x03ff0000) != 0 x00360000))
result |= 0 x02;
else
dev_warn(&priv->udev->dev, "%s: Path A RX IQK failed!\n" ,
__func__);
out:
return result;
}
static int rtl8192eu_iqk_path_b(struct rtl8xxxu_priv *priv)
{
u32 reg_eac, reg_eb4, reg_ebc;
int result = 0 ;
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x00000000);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_GAIN_CCA, 0 x00180);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_WE_LUT, 0 x800a0);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_RCK_OS, 0 x20000);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_TXPA_G1, 0 x0000f);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_TXPA_G2, 0 x07f77);
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x80800000);
/* Path B IQK setting */
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0 x18008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0 x82140303);
rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0 x68160000);
/* LO calibration setting */
rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0 x00462911);
/* One shot, path A LOK & IQK */
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xfa000000);
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf8000000);
mdelay(1 );
/* Check failed */
reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
reg_eb4 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
reg_ebc = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
if (!(reg_eac & BIT(31 )) &&
((reg_eb4 & 0 x03ff0000) != 0 x01420000) &&
((reg_ebc & 0 x03ff0000) != 0 x00420000))
result |= 0 x01;
else
dev_warn(&priv->udev->dev, "%s: Path B IQK failed!\n" ,
__func__);
return result;
}
static int rtl8192eu_rx_iqk_path_b(struct rtl8xxxu_priv *priv)
{
u32 reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc, val32;
int result = 0 ;
/* Leave IQK mode */
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x00000000);
/* Enable path A PA in TX IQK mode */
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_WE_LUT, 0 x800a0);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_RCK_OS, 0 x30000);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_TXPA_G1, 0 x0000f);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_TXPA_G2, 0 xf1173);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, 0 x800a0);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0 x30000);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0 x0000f);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0 xf1173);
/* PA/PAD control by 0x56, and set = 0x0 */
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_GAIN_CCA, 0 x00980);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_PAD_TXG, 0 x511e0);
/* Enter IQK mode */
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x80800000);
/* TX IQK setting */
rtl8xxxu_write32(priv, REG_TX_IQK, 0 x01007c00);
rtl8xxxu_write32(priv, REG_RX_IQK, 0 x01004800);
/* path-A IQK setting */
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0 x18008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_PI_B, 0 x8216031f);
rtl8xxxu_write32(priv, REG_RX_IQK_PI_B, 0 x6816031f);
/* LO calibration setting */
rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0 x0046a911);
/* One shot, path A LOK & IQK */
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xfa000000);
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf8000000);
mdelay(10 );
/* Check failed */
reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
reg_eb4 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
reg_ebc = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
if (!(reg_eac & BIT(31 )) &&
((reg_eb4 & 0 x03ff0000) != 0 x01420000) &&
((reg_ebc & 0 x03ff0000) != 0 x00420000)) {
result |= 0 x01;
} else {
/*
* PA/PAD controlled by 0x0
* Vendor driver restores RF_A here which I believe is a bug
*/
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x00000000);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_GAIN_CCA, 0 x180);
goto out;
}
val32 = 0 x80007c00 |
(reg_eb4 & 0 x03ff0000) | ((reg_ebc >> 16 ) & 0 x03ff);
rtl8xxxu_write32(priv, REG_TX_IQK, val32);
/* Modify RX IQK mode table */
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x00000000);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_WE_LUT, 0 x800a0);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_RCK_OS, 0 x30000);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_TXPA_G1, 0 x0000f);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_TXPA_G2, 0 xf7ff2);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_WE_LUT, 0 x800a0);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_RCK_OS, 0 x30000);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G1, 0 x0000f);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_TXPA_G2, 0 xf7ff2);
/* PA/PAD control by 0x56, and set = 0x0 */
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_GAIN_CCA, 0 x00980);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_PAD_TXG, 0 x510e0);
/* Enter IQK mode */
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x80800000);
/* IQK setting */
rtl8xxxu_write32(priv, REG_RX_IQK, 0 x01004800);
/* Path A IQK setting */
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_B, 0 x38008c1c);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_B, 0 x18008c1c);
rtl8xxxu_write32(priv, REG_TX_IQK_PI_A, 0 x821608ff);
rtl8xxxu_write32(priv, REG_RX_IQK_PI_A, 0 x281608ff);
/* LO calibration setting */
rtl8xxxu_write32(priv, REG_IQK_AGC_RSP, 0 x0046a891);
/* One shot, path A LOK & IQK */
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xfa000000);
rtl8xxxu_write32(priv, REG_IQK_AGC_PTS, 0 xf8000000);
mdelay(10 );
reg_eac = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_A_2);
reg_ec4 = rtl8xxxu_read32(priv, REG_RX_POWER_BEFORE_IQK_B_2);
reg_ecc = rtl8xxxu_read32(priv, REG_RX_POWER_AFTER_IQK_B_2);
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x00000000);
rtl8xxxu_write_rfreg(priv, RF_B, RF6052_REG_GAIN_CCA, 0 x180);
if (!(reg_eac & BIT(30 )) &&
((reg_ec4 & 0 x03ff0000) != 0 x01320000) &&
((reg_ecc & 0 x03ff0000) != 0 x00360000))
result |= 0 x02;
else
dev_warn(&priv->udev->dev, "%s: Path B RX IQK failed!\n" ,
__func__);
out:
return result;
}
static void rtl8192eu_phy_iqcalibrate(struct rtl8xxxu_priv *priv,
int result[][8 ], int t)
{
struct device *dev = &priv->udev->dev;
u32 i, val32;
int path_a_ok, path_b_ok;
int retry = 2 ;
static const u32 adda_regs[RTL8XXXU_ADDA_REGS] = {
REG_FPGA0_XCD_SWITCH_CTRL, REG_BLUETOOTH,
REG_RX_WAIT_CCA, REG_TX_CCK_RFON,
REG_TX_CCK_BBON, REG_TX_OFDM_RFON,
REG_TX_OFDM_BBON, REG_TX_TO_RX,
REG_TX_TO_TX, REG_RX_CCK,
REG_RX_OFDM, REG_RX_WAIT_RIFS,
REG_RX_TO_RX, REG_STANDBY,
REG_SLEEP, REG_PMPD_ANAEN
};
static const u32 iqk_mac_regs[RTL8XXXU_MAC_REGS] = {
REG_TXPAUSE, REG_BEACON_CTRL,
REG_BEACON_CTRL_1, REG_GPIO_MUXCFG
};
static const u32 iqk_bb_regs[RTL8XXXU_BB_REGS] = {
REG_OFDM0_TRX_PATH_ENABLE, REG_OFDM0_TR_MUX_PAR,
REG_FPGA0_XCD_RF_SW_CTRL, REG_CONFIG_ANT_A, REG_CONFIG_ANT_B,
REG_FPGA0_XAB_RF_SW_CTRL, REG_FPGA0_XA_RF_INT_OE,
REG_FPGA0_XB_RF_INT_OE, REG_CCK0_AFE_SETTING
};
u8 xa_agc = rtl8xxxu_read32(priv, REG_OFDM0_XA_AGC_CORE1) & 0 xff;
u8 xb_agc = rtl8xxxu_read32(priv, REG_OFDM0_XB_AGC_CORE1) & 0 xff;
/*
* Note: IQ calibration must be performed after loading
* PHY_REG.txt , and radio_a, radio_b.txt
*/
if (t == 0 ) {
/* Save ADDA parameters, turn Path A ADDA on */
rtl8xxxu_save_regs(priv, adda_regs, priv->adda_backup,
RTL8XXXU_ADDA_REGS);
rtl8xxxu_save_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
rtl8xxxu_save_regs(priv, iqk_bb_regs,
priv->bb_backup, RTL8XXXU_BB_REGS);
}
rtl8xxxu_path_adda_on(priv, adda_regs, true );
/* MAC settings */
rtl8xxxu_mac_calibration(priv, iqk_mac_regs, priv->mac_backup);
val32 = rtl8xxxu_read32(priv, REG_CCK0_AFE_SETTING);
val32 |= 0 x0f000000;
rtl8xxxu_write32(priv, REG_CCK0_AFE_SETTING, val32);
rtl8xxxu_write32(priv, REG_OFDM0_TRX_PATH_ENABLE, 0 x03a05600);
rtl8xxxu_write32(priv, REG_OFDM0_TR_MUX_PAR, 0 x000800e4);
rtl8xxxu_write32(priv, REG_FPGA0_XCD_RF_SW_CTRL, 0 x22208200);
val32 = rtl8xxxu_read32(priv, REG_FPGA0_XAB_RF_SW_CTRL);
val32 |= (FPGA0_RF_PAPE | (FPGA0_RF_PAPE << FPGA0_RF_BD_CTRL_SHIFT));
rtl8xxxu_write32(priv, REG_FPGA0_XAB_RF_SW_CTRL, val32);
val32 = rtl8xxxu_read32(priv, REG_FPGA0_XA_RF_INT_OE);
val32 |= BIT(10 );
rtl8xxxu_write32(priv, REG_FPGA0_XA_RF_INT_OE, val32);
val32 = rtl8xxxu_read32(priv, REG_FPGA0_XB_RF_INT_OE);
val32 |= BIT(10 );
rtl8xxxu_write32(priv, REG_FPGA0_XB_RF_INT_OE, val32);
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x80800000);
rtl8xxxu_write32(priv, REG_TX_IQK, 0 x01007c00);
rtl8xxxu_write32(priv, REG_RX_IQK, 0 x01004800);
for (i = 0 ; i < retry; i++) {
path_a_ok = rtl8192eu_iqk_path_a(priv);
if (path_a_ok == 0 x01) {
val32 = rtl8xxxu_read32(priv,
REG_TX_POWER_BEFORE_IQK_A);
result[t][0 ] = (val32 >> 16 ) & 0 x3ff;
val32 = rtl8xxxu_read32(priv,
REG_TX_POWER_AFTER_IQK_A);
result[t][1 ] = (val32 >> 16 ) & 0 x3ff;
break ;
}
}
if (!path_a_ok)
dev_dbg(dev, "%s: Path A TX IQK failed!\n" , __func__);
for (i = 0 ; i < retry; i++) {
path_a_ok = rtl8192eu_rx_iqk_path_a(priv);
if (path_a_ok == 0 x03) {
val32 = rtl8xxxu_read32(priv,
REG_RX_POWER_BEFORE_IQK_A_2);
result[t][2 ] = (val32 >> 16 ) & 0 x3ff;
val32 = rtl8xxxu_read32(priv,
REG_RX_POWER_AFTER_IQK_A_2);
result[t][3 ] = (val32 >> 16 ) & 0 x3ff;
break ;
}
}
if (!path_a_ok)
dev_dbg(dev, "%s: Path A RX IQK failed!\n" , __func__);
if (priv->rf_paths > 1 ) {
/* Path A into standby */
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x00000000);
rtl8xxxu_write_rfreg(priv, RF_A, RF6052_REG_AC, 0 x10000);
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x80800000);
/* Turn Path B ADDA on */
rtl8xxxu_path_adda_on(priv, adda_regs, false );
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x80800000);
rtl8xxxu_write32(priv, REG_TX_IQK, 0 x01007c00);
rtl8xxxu_write32(priv, REG_RX_IQK, 0 x01004800);
for (i = 0 ; i < retry; i++) {
path_b_ok = rtl8192eu_iqk_path_b(priv);
if (path_b_ok == 0 x01) {
val32 = rtl8xxxu_read32(priv, REG_TX_POWER_BEFORE_IQK_B);
result[t][4 ] = (val32 >> 16 ) & 0 x3ff;
val32 = rtl8xxxu_read32(priv, REG_TX_POWER_AFTER_IQK_B);
result[t][5 ] = (val32 >> 16 ) & 0 x3ff;
break ;
}
}
if (!path_b_ok)
dev_dbg(dev, "%s: Path B IQK failed!\n" , __func__);
for (i = 0 ; i < retry; i++) {
path_b_ok = rtl8192eu_rx_iqk_path_b(priv);
if (path_b_ok == 0 x03) {
val32 = rtl8xxxu_read32(priv,
REG_RX_POWER_BEFORE_IQK_B_2);
result[t][6 ] = (val32 >> 16 ) & 0 x3ff;
val32 = rtl8xxxu_read32(priv,
REG_RX_POWER_AFTER_IQK_B_2);
result[t][7 ] = (val32 >> 16 ) & 0 x3ff;
break ;
}
}
if (!path_b_ok)
dev_dbg(dev, "%s: Path B RX IQK failed!\n" , __func__);
}
/* Back to BB mode, load original value */
rtl8xxxu_write32(priv, REG_FPGA0_IQK, 0 x00000000);
if (t) {
/* Reload ADDA power saving parameters */
rtl8xxxu_restore_regs(priv, adda_regs, priv->adda_backup,
RTL8XXXU_ADDA_REGS);
/* Reload MAC parameters */
rtl8xxxu_restore_mac_regs(priv, iqk_mac_regs, priv->mac_backup);
/* Reload BB parameters */
rtl8xxxu_restore_regs(priv, iqk_bb_regs,
priv->bb_backup, RTL8XXXU_BB_REGS);
/* Restore RX initial gain */
val32 = rtl8xxxu_read32(priv, REG_OFDM0_XA_AGC_CORE1);
val32 &= 0 xffffff00;
rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, val32 | 0 x50);
rtl8xxxu_write32(priv, REG_OFDM0_XA_AGC_CORE1, val32 | xa_agc);
if (priv->rf_paths > 1 ) {
val32 = rtl8xxxu_read32(priv, REG_OFDM0_XB_AGC_CORE1);
val32 &= 0 xffffff00;
rtl8xxxu_write32(priv, REG_OFDM0_XB_AGC_CORE1,
val32 | 0 x50);
rtl8xxxu_write32(priv, REG_OFDM0_XB_AGC_CORE1,
val32 | xb_agc);
}
/* Load 0xe30 IQC default value */
rtl8xxxu_write32(priv, REG_TX_IQK_TONE_A, 0 x01008c00);
rtl8xxxu_write32(priv, REG_RX_IQK_TONE_A, 0 x01008c00);
}
}
static void rtl8192eu_phy_iq_calibrate(struct rtl8xxxu_priv *priv)
{
struct device *dev = &priv->udev->dev;
int result[4 ][8 ]; /* last is final result */
int i, candidate;
bool path_a_ok, path_b_ok;
u32 reg_e94, reg_e9c, reg_ea4, reg_eac;
u32 reg_eb4, reg_ebc, reg_ec4, reg_ecc;
bool simu;
memset(result, 0 , sizeof (result));
candidate = -1 ;
path_a_ok = false ;
path_b_ok = false ;
for (i = 0 ; i < 3 ; i++) {
rtl8192eu_phy_iqcalibrate(priv, result, i);
if (i == 1 ) {
simu = rtl8xxxu_gen2_simularity_compare(priv,
result, 0 , 1 );
if (simu) {
candidate = 0 ;
break ;
}
}
if (i == 2 ) {
simu = rtl8xxxu_gen2_simularity_compare(priv,
result, 0 , 2 );
if (simu) {
candidate = 0 ;
break ;
}
simu = rtl8xxxu_gen2_simularity_compare(priv,
result, 1 , 2 );
if (simu)
candidate = 1 ;
else
candidate = 3 ;
}
}
for (i = 0 ; i < 4 ; i++) {
reg_e94 = result[i][0 ];
reg_e9c = result[i][1 ];
reg_ea4 = result[i][2 ];
reg_eb4 = result[i][4 ];
reg_ebc = result[i][5 ];
reg_ec4 = result[i][6 ];
}
if (candidate >= 0 ) {
reg_e94 = result[candidate][0 ];
priv->rege94 = reg_e94;
reg_e9c = result[candidate][1 ];
priv->rege9c = reg_e9c;
reg_ea4 = result[candidate][2 ];
reg_eac = result[candidate][3 ];
reg_eb4 = result[candidate][4 ];
priv->regeb4 = reg_eb4;
reg_ebc = result[candidate][5 ];
priv->regebc = reg_ebc;
reg_ec4 = result[candidate][6 ];
reg_ecc = result[candidate][7 ];
dev_dbg(dev, "%s: candidate is %x\n" , __func__, candidate);
dev_dbg(dev,
"%s: e94 =%x e9c=%x ea4=%x eac=%x eb4=%x ebc=%x ec4=%x ecc=%x\n" ,
__func__, reg_e94, reg_e9c,
reg_ea4, reg_eac, reg_eb4, reg_ebc, reg_ec4, reg_ecc);
path_a_ok = true ;
path_b_ok = true ;
} else {
reg_e94 = reg_eb4 = priv->rege94 = priv->regeb4 = 0 x100;
reg_e9c = reg_ebc = priv->rege9c = priv->regebc = 0 x0;
}
if (reg_e94 && candidate >= 0 )
rtl8xxxu_fill_iqk_matrix_a(priv, path_a_ok, result,
candidate, (reg_ea4 == 0 ));
if (priv->rf_paths > 1 )
rtl8xxxu_fill_iqk_matrix_b(priv, path_b_ok, result,
candidate, (reg_ec4 == 0 ));
rtl8xxxu_save_regs(priv, rtl8xxxu_iqk_phy_iq_bb_reg,
priv->bb_recovery_backup, RTL8XXXU_BB_REGS);
}
/*
* This is needed for 8723bu as well, presumable
*/
static void rtl8192e_crystal_afe_adjust(struct rtl8xxxu_priv *priv)
{
u8 val8;
u32 val32;
/*
* 40Mhz crystal source, MAC 0x28[2]=0
*/
val8 = rtl8xxxu_read8(priv, REG_AFE_PLL_CTRL);
val8 &= 0 xfb;
rtl8xxxu_write8(priv, REG_AFE_PLL_CTRL, val8);
val32 = rtl8xxxu_read32(priv, REG_AFE_CTRL4);
val32 &= 0 xfffffc7f;
rtl8xxxu_write32(priv, REG_AFE_CTRL4, val32);
/*
* 92e AFE parameter
* AFE PLL KVCO selection, MAC 0x28[6]=1
*/
val8 = rtl8xxxu_read8(priv, REG_AFE_PLL_CTRL);
val8 &= 0 xbf;
rtl8xxxu_write8(priv, REG_AFE_PLL_CTRL, val8);
/*
* AFE PLL KVCO selection, MAC 0x78[21]=0
*/
val32 = rtl8xxxu_read32(priv, REG_AFE_CTRL4);
val32 &= 0 xffdfffff;
rtl8xxxu_write32(priv, REG_AFE_CTRL4, val32);
}
static void rtl8192e_disabled_to_emu(struct rtl8xxxu_priv *priv)
{
u8 val8;
/* Clear suspend enable and power down enable*/
val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1 );
val8 &= ~(BIT(3 ) | BIT(4 ));
rtl8xxxu_write8(priv, REG_APS_FSMCO + 1 , val8);
}
static int rtl8192e_emu_to_active(struct rtl8xxxu_priv *priv)
{
u8 val8;
u32 val32;
int count, ret = 0 ;
/* disable HWPDN 0x04[15]=0*/
val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1 );
val8 &= ~BIT(7 );
rtl8xxxu_write8(priv, REG_APS_FSMCO + 1 , val8);
/* disable SW LPS 0x04[10]= 0 */
val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1 );
val8 &= ~BIT(2 );
rtl8xxxu_write8(priv, REG_APS_FSMCO + 1 , val8);
/* disable WL suspend*/
val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1 );
val8 &= ~(BIT(3 ) | BIT(4 ));
rtl8xxxu_write8(priv, REG_APS_FSMCO + 1 , val8);
/* wait till 0x04[17] = 1 power ready*/
for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
if (val32 & BIT(17 ))
break ;
udelay(10 );
}
if (!count) {
ret = -EBUSY;
goto exit ;
}
/* We should be able to optimize the following three entries into one */
/* release WLON reset 0x04[16]= 1*/
val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 2 );
val8 |= BIT(0 );
rtl8xxxu_write8(priv, REG_APS_FSMCO + 2 , val8);
/* set, then poll until 0 */
val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
val32 |= APS_FSMCO_MAC_ENABLE;
rtl8xxxu_write32(priv, REG_APS_FSMCO, val32);
for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
val32 = rtl8xxxu_read32(priv, REG_APS_FSMCO);
if ((val32 & APS_FSMCO_MAC_ENABLE) == 0 ) {
ret = 0 ;
break ;
}
udelay(10 );
}
if (!count) {
ret = -EBUSY;
goto exit ;
}
exit :
return ret;
}
static int rtl8192eu_active_to_lps(struct rtl8xxxu_priv *priv)
{
struct device *dev = &priv->udev->dev;
u8 val8;
u16 val16;
u32 val32;
int retry, retval;
rtl8xxxu_write8(priv, REG_TXPAUSE, 0 xff);
retry = 100 ;
retval = -EBUSY;
/*
* Poll 32 bit wide 0x05f8 for 0x00000000 to ensure no TX is pending.
*/
do {
val32 = rtl8xxxu_read32(priv, REG_SCH_TX_CMD);
if (!val32) {
retval = 0 ;
break ;
}
} while (retry--);
if (!retry) {
dev_warn(dev, "Failed to flush TX queue\n" );
retval = -EBUSY;
goto out;
}
/* Disable CCK and OFDM, clock gated */
val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC);
val8 &= ~SYS_FUNC_BBRSTB;
rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
udelay(2 );
/* Reset whole BB */
val8 = rtl8xxxu_read8(priv, REG_SYS_FUNC);
val8 &= ~SYS_FUNC_BB_GLB_RSTN;
rtl8xxxu_write8(priv, REG_SYS_FUNC, val8);
/* Reset MAC TRX */
val16 = rtl8xxxu_read16(priv, REG_CR);
val16 &= 0 xff00;
val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE);
rtl8xxxu_write16(priv, REG_CR, val16);
val16 = rtl8xxxu_read16(priv, REG_CR);
val16 &= ~CR_SECURITY_ENABLE;
rtl8xxxu_write16(priv, REG_CR, val16);
val8 = rtl8xxxu_read8(priv, REG_DUAL_TSF_RST);
val8 |= DUAL_TSF_TX_OK;
rtl8xxxu_write8(priv, REG_DUAL_TSF_RST, val8);
out:
return retval;
}
static int rtl8192eu_active_to_emu(struct rtl8xxxu_priv *priv)
{
u8 val8;
int count, ret = 0 ;
/* Turn off RF */
val8 = rtl8xxxu_read8(priv, REG_RF_CTRL);
val8 &= ~RF_ENABLE;
rtl8xxxu_write8(priv, REG_RF_CTRL, val8);
/* Switch DPDT_SEL_P output from register 0x65[2] */
val8 = rtl8xxxu_read8(priv, REG_LEDCFG2);
val8 &= ~LEDCFG2_DPDT_SELECT;
rtl8xxxu_write8(priv, REG_LEDCFG2, val8);
/* 0x0005[1] = 1 turn off MAC by HW state machine*/
val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1 );
val8 |= BIT(1 );
rtl8xxxu_write8(priv, REG_APS_FSMCO + 1 , val8);
for (count = RTL8XXXU_MAX_REG_POLL; count; count--) {
val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1 );
if ((val8 & BIT(1 )) == 0 )
break ;
udelay(10 );
}
if (!count) {
dev_warn(&priv->udev->dev, "%s: Disabling MAC timed out\n" ,
__func__);
ret = -EBUSY;
goto exit ;
}
exit :
return ret;
}
static int rtl8192eu_emu_to_disabled(struct rtl8xxxu_priv *priv)
{
u8 val8;
/* 0x04[12:11] = 01 enable WL suspend */
val8 = rtl8xxxu_read8(priv, REG_APS_FSMCO + 1 );
val8 &= ~(BIT(3 ) | BIT(4 ));
val8 |= BIT(3 );
rtl8xxxu_write8(priv, REG_APS_FSMCO + 1 , val8);
return 0 ;
}
static int rtl8192eu_power_on(struct rtl8xxxu_priv *priv)
{
u16 val16;
u32 val32;
int ret;
val32 = rtl8xxxu_read32(priv, REG_SYS_CFG);
if (val32 & SYS_CFG_SPS_LDO_SEL) {
rtl8xxxu_write8(priv, REG_LDO_SW_CTRL, 0 xc3);
} else {
/*
* Raise 1.2V voltage
*/
val32 = rtl8xxxu_read32(priv, REG_8192E_LDOV12_CTRL);
val32 &= 0 xff0fffff;
val32 |= 0 x00500000;
rtl8xxxu_write32(priv, REG_8192E_LDOV12_CTRL, val32);
rtl8xxxu_write8(priv, REG_LDO_SW_CTRL, 0 x83);
}
/*
* Adjust AFE before enabling PLL
*/
rtl8192e_crystal_afe_adjust(priv);
rtl8192e_disabled_to_emu(priv);
ret = rtl8192e_emu_to_active(priv);
if (ret)
goto exit ;
rtl8xxxu_write16(priv, REG_CR, 0 x0000);
/*
* Enable MAC DMA/WMAC/SCHEDULE/SEC block
* Set CR bit10 to enable 32k calibration.
*/
val16 = rtl8xxxu_read16(priv, REG_CR);
val16 |= (CR_HCI_TXDMA_ENABLE | CR_HCI_RXDMA_ENABLE |
CR_TXDMA_ENABLE | CR_RXDMA_ENABLE |
CR_PROTOCOL_ENABLE | CR_SCHEDULE_ENABLE |
CR_MAC_TX_ENABLE | CR_MAC_RX_ENABLE |
CR_SECURITY_ENABLE | CR_CALTIMER_ENABLE);
rtl8xxxu_write16(priv, REG_CR, val16);
exit :
return ret;
}
static void rtl8192eu_power_off(struct rtl8xxxu_priv *priv)
{
u8 val8;
u16 val16;
rtl8xxxu_flush_fifo(priv);
val8 = rtl8xxxu_read8(priv, REG_TX_REPORT_CTRL);
val8 &= ~TX_REPORT_CTRL_TIMER_ENABLE;
rtl8xxxu_write8(priv, REG_TX_REPORT_CTRL, val8);
/* Turn off RF */
rtl8xxxu_write8(priv, REG_RF_CTRL, 0 x00);
rtl8192eu_active_to_lps(priv);
/* Reset Firmware if running in RAM */
if (rtl8xxxu_read8(priv, REG_MCU_FW_DL) & MCU_FW_RAM_SEL)
rtl8xxxu_firmware_self_reset(priv);
/* Reset MCU */
val16 = rtl8xxxu_read16(priv, REG_SYS_FUNC);
val16 &= ~SYS_FUNC_CPU_ENABLE;
rtl8xxxu_write16(priv, REG_SYS_FUNC, val16);
/* Reset MCU ready status */
rtl8xxxu_write8(priv, REG_MCU_FW_DL, 0 x00);
rtl8xxxu_reset_8051(priv);
rtl8192eu_active_to_emu(priv);
rtl8192eu_emu_to_disabled(priv);
}
static void rtl8192e_enable_rf(struct rtl8xxxu_priv *priv)
{
u32 val32;
u8 val8;
val32 = rtl8xxxu_read32(priv, REG_RX_WAIT_CCA);
val32 |= (BIT(22 ) | BIT(23 ));
rtl8xxxu_write32(priv, REG_RX_WAIT_CCA, val32);
val8 = rtl8xxxu_read8(priv, REG_GPIO_MUXCFG);
val8 |= BIT(5 );
rtl8xxxu_write8(priv, REG_GPIO_MUXCFG, val8);
/*
* WLAN action by PTA
*/
rtl8xxxu_write8(priv, REG_WLAN_ACT_CONTROL_8723B, 0 x04);
val32 = rtl8xxxu_read32(priv, REG_PWR_DATA);
val32 |= PWR_DATA_EEPRPAD_RFE_CTRL_EN;
rtl8xxxu_write32(priv, REG_PWR_DATA, val32);
val32 = rtl8xxxu_read32(priv, REG_RFE_BUFFER);
val32 |= (BIT(0 ) | BIT(1 ));
rtl8xxxu_write32(priv, REG_RFE_BUFFER, val32);
rtl8xxxu_write8(priv, REG_RFE_CTRL_ANTA_SRC, 0 x77);
val32 = rtl8xxxu_read32(priv, REG_LEDCFG0);
val32 &= ~BIT(24 );
val32 |= BIT(23 );
rtl8xxxu_write32(priv, REG_LEDCFG0, val32);
/*
* Fix external switch Main->S1, Aux->S0
*/
val8 = rtl8xxxu_read8(priv, REG_PAD_CTRL1);
val8 &= ~BIT(0 );
rtl8xxxu_write8(priv, REG_PAD_CTRL1, val8);
/*
* Fix transmission failure of rtl8192e.
*/
rtl8xxxu_write8(priv, REG_TXPAUSE, 0 x00);
}
static s8 rtl8192e_cck_rssi(struct rtl8xxxu_priv *priv, struct rtl8723au_phy_stats *phy_stats)
{
static const s8 lna_gain_table_0[8 ] = {15 , 9 , -10 , -21 , -23 , -27 , -43 , -44 };
static const s8 lna_gain_table_1[8 ] = {24 , 18 , 13 , -4 , -11 , -18 , -31 , -36 };
u8 cck_agc_rpt = phy_stats->cck_agc_rpt_ofdm_cfosho_a;
s8 rx_pwr_all = 0 x00;
u8 vga_idx, lna_idx;
s8 lna_gain = 0 ;
lna_idx = u8_get_bits(cck_agc_rpt, CCK_AGC_RPT_LNA_IDX_MASK);
vga_idx = u8_get_bits(cck_agc_rpt, CCK_AGC_RPT_VGA_IDX_MASK);
if (priv->cck_agc_report_type == 0 )
lna_gain = lna_gain_table_0[lna_idx];
else
lna_gain = lna_gain_table_1[lna_idx];
rx_pwr_all = lna_gain - (2 * vga_idx);
return rx_pwr_all;
}
static int rtl8192eu_led_brightness_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
struct rtl8xxxu_priv *priv = container_of(led_cdev,
struct rtl8xxxu_priv,
led_cdev);
u8 ledcfg = rtl8xxxu_read8(priv, REG_LEDCFG1);
if (brightness == LED_OFF) {
ledcfg &= ~LEDCFG1_HW_LED_CONTROL;
ledcfg |= LEDCFG1_LED_DISABLE;
} else if (brightness == LED_ON) {
ledcfg &= ~(LEDCFG1_HW_LED_CONTROL | LEDCFG1_LED_DISABLE);
} else if (brightness == RTL8XXXU_HW_LED_CONTROL) {
ledcfg &= ~LEDCFG1_LED_DISABLE;
ledcfg |= LEDCFG1_HW_LED_CONTROL;
}
rtl8xxxu_write8(priv, REG_LEDCFG1, ledcfg);
return 0 ;
}
struct rtl8xxxu_fileops rtl8192eu_fops = {
.identify_chip = rtl8192eu_identify_chip,
.parse_efuse = rtl8192eu_parse_efuse,
.load_firmware = rtl8192eu_load_firmware,
.power_on = rtl8192eu_power_on,
.power_off = rtl8192eu_power_off,
.read_efuse = rtl8xxxu_read_efuse,
.reset_8051 = rtl8xxxu_reset_8051,
.llt_init = rtl8xxxu_auto_llt_table,
.init_phy_bb = rtl8192eu_init_phy_bb,
.init_phy_rf = rtl8192eu_init_phy_rf,
.phy_lc_calibrate = rtl8723a_phy_lc_calibrate,
.phy_iq_calibrate = rtl8192eu_phy_iq_calibrate,
.config_channel = rtl8xxxu_gen2_config_channel,
.parse_rx_desc = rtl8xxxu_parse_rxdesc24,
.parse_phystats = rtl8723au_rx_parse_phystats,
.enable_rf = rtl8192e_enable_rf,
.disable_rf = rtl8xxxu_gen2_disable_rf,
.usb_quirks = rtl8xxxu_gen2_usb_quirks,
.set_tx_power = rtl8192e_set_tx_power,
.update_rate_mask = rtl8xxxu_gen2_update_rate_mask,
.report_connect = rtl8xxxu_gen2_report_connect,
.report_rssi = rtl8xxxu_gen2_report_rssi,
.fill_txdesc = rtl8xxxu_fill_txdesc_v2,
.set_crystal_cap = rtl8723a_set_crystal_cap,
.cck_rssi = rtl8192e_cck_rssi,
.led_classdev_brightness_set = rtl8192eu_led_brightness_set,
.writeN_block_size = 128 ,
.tx_desc_size = sizeof (struct rtl8xxxu_txdesc40),
.rx_desc_size = sizeof (struct rtl8xxxu_rxdesc24),
.has_s0s1 = 0 ,
.gen2_thermal_meter = 1 ,
.needs_full_init = 1 ,
.supports_ap = 1 ,
.max_macid_num = 128 ,
.max_sec_cam_num = 64 ,
.adda_1t_init = 0 x0fc01616,
.adda_1t_path_on = 0 x0fc01616,
.adda_2t_path_on_a = 0 x0fc01616,
.adda_2t_path_on_b = 0 x0fc01616,
.trxff_boundary = 0 x3cff,
.mactable = rtl8192e_mac_init_table,
.total_page_num = TX_TOTAL_PAGE_NUM_8192E,
.page_num_hi = TX_PAGE_NUM_HI_PQ_8192E,
.page_num_lo = TX_PAGE_NUM_LO_PQ_8192E,
.page_num_norm = TX_PAGE_NUM_NORM_PQ_8192E,
};
Messung V0.5 in Prozent C=96 H=92 G=93
¤ Dauer der Verarbeitung: 0.23 Sekunden
(vorverarbeitet am 2026-06-07)
¤
*© Formatika GbR, Deutschland