162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 262306a36Sopenharmony_ci 362306a36Sopenharmony_ci/* 462306a36Sopenharmony_ci * Radio tuning for RTL8225 on RTL8180 562306a36Sopenharmony_ci * 662306a36Sopenharmony_ci * Copyright 2007 Michael Wu <flamingice@sourmilk.net> 762306a36Sopenharmony_ci * Copyright 2007 Andrea Merello <andrea.merello@gmail.com> 862306a36Sopenharmony_ci * 962306a36Sopenharmony_ci * Based on the r8180 driver, which is: 1062306a36Sopenharmony_ci * Copyright 2005 Andrea Merello <andrea.merello@gmail.com>, et al. 1162306a36Sopenharmony_ci * 1262306a36Sopenharmony_ci * Thanks to Realtek for their support! 1362306a36Sopenharmony_ci */ 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci#include <linux/pci.h> 1662306a36Sopenharmony_ci#include <linux/delay.h> 1762306a36Sopenharmony_ci#include <net/mac80211.h> 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#include "rtl8180.h" 2062306a36Sopenharmony_ci#include "rtl8225.h" 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_cistatic void rtl8225_write(struct ieee80211_hw *dev, u8 addr, u16 data) 2362306a36Sopenharmony_ci{ 2462306a36Sopenharmony_ci struct rtl8180_priv *priv = dev->priv; 2562306a36Sopenharmony_ci u16 reg80, reg84, reg82; 2662306a36Sopenharmony_ci u32 bangdata; 2762306a36Sopenharmony_ci int i; 2862306a36Sopenharmony_ci 2962306a36Sopenharmony_ci bangdata = (data << 4) | (addr & 0xf); 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci reg80 = rtl818x_ioread16(priv, &priv->map->RFPinsOutput) & 0xfff3; 3262306a36Sopenharmony_ci reg82 = rtl818x_ioread16(priv, &priv->map->RFPinsEnable); 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, reg82 | 0x7); 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci reg84 = rtl818x_ioread16(priv, &priv->map->RFPinsSelect); 3762306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, reg84 | 0x7 | 0x400); 3862306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 3962306a36Sopenharmony_ci udelay(10); 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80 | (1 << 2)); 4262306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 4362306a36Sopenharmony_ci udelay(2); 4462306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80); 4562306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 4662306a36Sopenharmony_ci udelay(10); 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci for (i = 15; i >= 0; i--) { 4962306a36Sopenharmony_ci u16 reg = reg80; 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci if (bangdata & (1 << i)) 5262306a36Sopenharmony_ci reg |= 1; 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci if (i & 1) 5562306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg); 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg | (1 << 1)); 5862306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg | (1 << 1)); 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci if (!(i & 1)) 6162306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg); 6262306a36Sopenharmony_ci } 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80 | (1 << 2)); 6562306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 6662306a36Sopenharmony_ci udelay(10); 6762306a36Sopenharmony_ci 6862306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80 | (1 << 2)); 6962306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, reg84 | 0x400); 7062306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF); 7162306a36Sopenharmony_ci} 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_cistatic u16 rtl8225_read(struct ieee80211_hw *dev, u8 addr) 7462306a36Sopenharmony_ci{ 7562306a36Sopenharmony_ci struct rtl8180_priv *priv = dev->priv; 7662306a36Sopenharmony_ci u16 reg80, reg82, reg84, out; 7762306a36Sopenharmony_ci int i; 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ci reg80 = rtl818x_ioread16(priv, &priv->map->RFPinsOutput); 8062306a36Sopenharmony_ci reg82 = rtl818x_ioread16(priv, &priv->map->RFPinsEnable); 8162306a36Sopenharmony_ci reg84 = rtl818x_ioread16(priv, &priv->map->RFPinsSelect) | 0x400; 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci reg80 &= ~0xF; 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, reg82 | 0x000F); 8662306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, reg84 | 0x000F); 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80 | (1 << 2)); 8962306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 9062306a36Sopenharmony_ci udelay(4); 9162306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg80); 9262306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 9362306a36Sopenharmony_ci udelay(5); 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci for (i = 4; i >= 0; i--) { 9662306a36Sopenharmony_ci u16 reg = reg80 | ((addr >> i) & 1); 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci if (!(i & 1)) { 9962306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg); 10062306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 10162306a36Sopenharmony_ci udelay(1); 10262306a36Sopenharmony_ci } 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 10562306a36Sopenharmony_ci reg | (1 << 1)); 10662306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 10762306a36Sopenharmony_ci udelay(2); 10862306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 10962306a36Sopenharmony_ci reg | (1 << 1)); 11062306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 11162306a36Sopenharmony_ci udelay(2); 11262306a36Sopenharmony_ci 11362306a36Sopenharmony_ci if (i & 1) { 11462306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, reg); 11562306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 11662306a36Sopenharmony_ci udelay(1); 11762306a36Sopenharmony_ci } 11862306a36Sopenharmony_ci } 11962306a36Sopenharmony_ci 12062306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x000E); 12162306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, 0x040E); 12262306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 12362306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 12462306a36Sopenharmony_ci reg80 | (1 << 3) | (1 << 1)); 12562306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 12662306a36Sopenharmony_ci udelay(2); 12762306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 12862306a36Sopenharmony_ci reg80 | (1 << 3)); 12962306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 13062306a36Sopenharmony_ci udelay(2); 13162306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 13262306a36Sopenharmony_ci reg80 | (1 << 3)); 13362306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 13462306a36Sopenharmony_ci udelay(2); 13562306a36Sopenharmony_ci 13662306a36Sopenharmony_ci out = 0; 13762306a36Sopenharmony_ci for (i = 11; i >= 0; i--) { 13862306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 13962306a36Sopenharmony_ci reg80 | (1 << 3)); 14062306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 14162306a36Sopenharmony_ci udelay(1); 14262306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 14362306a36Sopenharmony_ci reg80 | (1 << 3) | (1 << 1)); 14462306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 14562306a36Sopenharmony_ci udelay(2); 14662306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 14762306a36Sopenharmony_ci reg80 | (1 << 3) | (1 << 1)); 14862306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 14962306a36Sopenharmony_ci udelay(2); 15062306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 15162306a36Sopenharmony_ci reg80 | (1 << 3) | (1 << 1)); 15262306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 15362306a36Sopenharmony_ci udelay(2); 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_ci if (rtl818x_ioread16(priv, &priv->map->RFPinsInput) & (1 << 1)) 15662306a36Sopenharmony_ci out |= 1 << i; 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 15962306a36Sopenharmony_ci reg80 | (1 << 3)); 16062306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 16162306a36Sopenharmony_ci udelay(2); 16262306a36Sopenharmony_ci } 16362306a36Sopenharmony_ci 16462306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 16562306a36Sopenharmony_ci reg80 | (1 << 3) | (1 << 2)); 16662306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 16762306a36Sopenharmony_ci udelay(2); 16862306a36Sopenharmony_ci 16962306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, reg82); 17062306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, reg84); 17162306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 0x03A0); 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_ci return out; 17462306a36Sopenharmony_ci} 17562306a36Sopenharmony_ci 17662306a36Sopenharmony_cistatic const u16 rtl8225bcd_rxgain[] = { 17762306a36Sopenharmony_ci 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0408, 0x0409, 17862306a36Sopenharmony_ci 0x040a, 0x040b, 0x0502, 0x0503, 0x0504, 0x0505, 0x0540, 0x0541, 17962306a36Sopenharmony_ci 0x0542, 0x0543, 0x0544, 0x0545, 0x0580, 0x0581, 0x0582, 0x0583, 18062306a36Sopenharmony_ci 0x0584, 0x0585, 0x0588, 0x0589, 0x058a, 0x058b, 0x0643, 0x0644, 18162306a36Sopenharmony_ci 0x0645, 0x0680, 0x0681, 0x0682, 0x0683, 0x0684, 0x0685, 0x0688, 18262306a36Sopenharmony_ci 0x0689, 0x068a, 0x068b, 0x068c, 0x0742, 0x0743, 0x0744, 0x0745, 18362306a36Sopenharmony_ci 0x0780, 0x0781, 0x0782, 0x0783, 0x0784, 0x0785, 0x0788, 0x0789, 18462306a36Sopenharmony_ci 0x078a, 0x078b, 0x078c, 0x078d, 0x0790, 0x0791, 0x0792, 0x0793, 18562306a36Sopenharmony_ci 0x0794, 0x0795, 0x0798, 0x0799, 0x079a, 0x079b, 0x079c, 0x079d, 18662306a36Sopenharmony_ci 0x07a0, 0x07a1, 0x07a2, 0x07a3, 0x07a4, 0x07a5, 0x07a8, 0x07a9, 18762306a36Sopenharmony_ci 0x07aa, 0x07ab, 0x07ac, 0x07ad, 0x07b0, 0x07b1, 0x07b2, 0x07b3, 18862306a36Sopenharmony_ci 0x07b4, 0x07b5, 0x07b8, 0x07b9, 0x07ba, 0x07bb, 0x07bb 18962306a36Sopenharmony_ci}; 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_cistatic const u8 rtl8225_agc[] = { 19262306a36Sopenharmony_ci 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 19362306a36Sopenharmony_ci 0x9d, 0x9c, 0x9b, 0x9a, 0x99, 0x98, 0x97, 0x96, 19462306a36Sopenharmony_ci 0x95, 0x94, 0x93, 0x92, 0x91, 0x90, 0x8f, 0x8e, 19562306a36Sopenharmony_ci 0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x88, 0x87, 0x86, 19662306a36Sopenharmony_ci 0x85, 0x84, 0x83, 0x82, 0x81, 0x80, 0x3f, 0x3e, 19762306a36Sopenharmony_ci 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, 0x37, 0x36, 19862306a36Sopenharmony_ci 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, 0x2f, 0x2e, 19962306a36Sopenharmony_ci 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, 0x27, 0x26, 20062306a36Sopenharmony_ci 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, 0x1f, 0x1e, 20162306a36Sopenharmony_ci 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, 0x17, 0x16, 20262306a36Sopenharmony_ci 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e, 20362306a36Sopenharmony_ci 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06, 20462306a36Sopenharmony_ci 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x01, 0x01, 20562306a36Sopenharmony_ci 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 20662306a36Sopenharmony_ci 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 20762306a36Sopenharmony_ci 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 20862306a36Sopenharmony_ci}; 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_cistatic const u8 rtl8225_gain[] = { 21162306a36Sopenharmony_ci 0x23, 0x88, 0x7c, 0xa5, /* -82dbm */ 21262306a36Sopenharmony_ci 0x23, 0x88, 0x7c, 0xb5, /* -82dbm */ 21362306a36Sopenharmony_ci 0x23, 0x88, 0x7c, 0xc5, /* -82dbm */ 21462306a36Sopenharmony_ci 0x33, 0x80, 0x79, 0xc5, /* -78dbm */ 21562306a36Sopenharmony_ci 0x43, 0x78, 0x76, 0xc5, /* -74dbm */ 21662306a36Sopenharmony_ci 0x53, 0x60, 0x73, 0xc5, /* -70dbm */ 21762306a36Sopenharmony_ci 0x63, 0x58, 0x70, 0xc5, /* -66dbm */ 21862306a36Sopenharmony_ci}; 21962306a36Sopenharmony_ci 22062306a36Sopenharmony_cistatic const u8 rtl8225_threshold[] = { 22162306a36Sopenharmony_ci 0x8d, 0x8d, 0x8d, 0x8d, 0x9d, 0xad, 0xbd 22262306a36Sopenharmony_ci}; 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_cistatic const u8 rtl8225_tx_gain_cck_ofdm[] = { 22562306a36Sopenharmony_ci 0x02, 0x06, 0x0e, 0x1e, 0x3e, 0x7e 22662306a36Sopenharmony_ci}; 22762306a36Sopenharmony_ci 22862306a36Sopenharmony_cistatic const u8 rtl8225_tx_power_cck[] = { 22962306a36Sopenharmony_ci 0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02, 23062306a36Sopenharmony_ci 0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02, 23162306a36Sopenharmony_ci 0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02, 23262306a36Sopenharmony_ci 0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02, 23362306a36Sopenharmony_ci 0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03, 23462306a36Sopenharmony_ci 0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03 23562306a36Sopenharmony_ci}; 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_cistatic const u8 rtl8225_tx_power_cck_ch14[] = { 23862306a36Sopenharmony_ci 0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00, 23962306a36Sopenharmony_ci 0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00, 24062306a36Sopenharmony_ci 0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00, 24162306a36Sopenharmony_ci 0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00, 24262306a36Sopenharmony_ci 0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00, 24362306a36Sopenharmony_ci 0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00 24462306a36Sopenharmony_ci}; 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_cistatic const u8 rtl8225_tx_power_ofdm[] = { 24762306a36Sopenharmony_ci 0x80, 0x90, 0xa2, 0xb5, 0xcb, 0xe4 24862306a36Sopenharmony_ci}; 24962306a36Sopenharmony_ci 25062306a36Sopenharmony_cistatic const u32 rtl8225_chan[] = { 25162306a36Sopenharmony_ci 0x085c, 0x08dc, 0x095c, 0x09dc, 0x0a5c, 0x0adc, 0x0b5c, 25262306a36Sopenharmony_ci 0x0bdc, 0x0c5c, 0x0cdc, 0x0d5c, 0x0ddc, 0x0e5c, 0x0f72 25362306a36Sopenharmony_ci}; 25462306a36Sopenharmony_ci 25562306a36Sopenharmony_cistatic void rtl8225_rf_set_tx_power(struct ieee80211_hw *dev, int channel) 25662306a36Sopenharmony_ci{ 25762306a36Sopenharmony_ci struct rtl8180_priv *priv = dev->priv; 25862306a36Sopenharmony_ci u8 cck_power, ofdm_power; 25962306a36Sopenharmony_ci const u8 *tmp; 26062306a36Sopenharmony_ci u32 reg; 26162306a36Sopenharmony_ci int i; 26262306a36Sopenharmony_ci 26362306a36Sopenharmony_ci cck_power = priv->channels[channel - 1].hw_value & 0xFF; 26462306a36Sopenharmony_ci ofdm_power = priv->channels[channel - 1].hw_value >> 8; 26562306a36Sopenharmony_ci 26662306a36Sopenharmony_ci cck_power = min(cck_power, (u8)35); 26762306a36Sopenharmony_ci ofdm_power = min(ofdm_power, (u8)35); 26862306a36Sopenharmony_ci 26962306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->TX_GAIN_CCK, 27062306a36Sopenharmony_ci rtl8225_tx_gain_cck_ofdm[cck_power / 6] >> 1); 27162306a36Sopenharmony_ci 27262306a36Sopenharmony_ci if (channel == 14) 27362306a36Sopenharmony_ci tmp = &rtl8225_tx_power_cck_ch14[(cck_power % 6) * 8]; 27462306a36Sopenharmony_ci else 27562306a36Sopenharmony_ci tmp = &rtl8225_tx_power_cck[(cck_power % 6) * 8]; 27662306a36Sopenharmony_ci 27762306a36Sopenharmony_ci for (i = 0; i < 8; i++) 27862306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x44 + i, *tmp++); 27962306a36Sopenharmony_ci 28062306a36Sopenharmony_ci msleep(1); /* FIXME: optional? */ 28162306a36Sopenharmony_ci 28262306a36Sopenharmony_ci /* TODO: use set_anaparam2 dev.c_func*/ 28362306a36Sopenharmony_ci /* anaparam2 on */ 28462306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG); 28562306a36Sopenharmony_ci reg = rtl818x_ioread8(priv, &priv->map->CONFIG3); 28662306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg | RTL818X_CONFIG3_ANAPARAM_WRITE); 28762306a36Sopenharmony_ci rtl818x_iowrite32(priv, &priv->map->ANAPARAM2, RTL8225_ANAPARAM2_ON); 28862306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg & ~RTL818X_CONFIG3_ANAPARAM_WRITE); 28962306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL); 29062306a36Sopenharmony_ci 29162306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->TX_GAIN_OFDM, 29262306a36Sopenharmony_ci rtl8225_tx_gain_cck_ofdm[ofdm_power/6] >> 1); 29362306a36Sopenharmony_ci 29462306a36Sopenharmony_ci tmp = &rtl8225_tx_power_ofdm[ofdm_power % 6]; 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 5, *tmp); 29762306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 7, *tmp); 29862306a36Sopenharmony_ci 29962306a36Sopenharmony_ci msleep(1); 30062306a36Sopenharmony_ci} 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_cistatic void rtl8225_rf_init(struct ieee80211_hw *dev) 30362306a36Sopenharmony_ci{ 30462306a36Sopenharmony_ci struct rtl8180_priv *priv = dev->priv; 30562306a36Sopenharmony_ci int i; 30662306a36Sopenharmony_ci 30762306a36Sopenharmony_ci rtl8180_set_anaparam(priv, RTL8225_ANAPARAM_ON); 30862306a36Sopenharmony_ci 30962306a36Sopenharmony_ci /* host_pci_init */ 31062306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 0x0480); 31162306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF); 31262306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, 0x0488); 31362306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, 0); 31462306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 31562306a36Sopenharmony_ci msleep(200); /* FIXME: ehh?? */ 31662306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, 0xFF & ~(1 << 6)); 31762306a36Sopenharmony_ci 31862306a36Sopenharmony_ci rtl818x_iowrite32(priv, &priv->map->RF_TIMING, 0x000a8008); 31962306a36Sopenharmony_ci 32062306a36Sopenharmony_ci /* TODO: check if we need really to change BRSR to do RF config */ 32162306a36Sopenharmony_ci rtl818x_ioread16(priv, &priv->map->BRSR); 32262306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->BRSR, 0xFFFF); 32362306a36Sopenharmony_ci rtl818x_iowrite32(priv, &priv->map->RF_PARA, 0x00100044); 32462306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG); 32562306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->CONFIG3, 0x44); 32662306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL); 32762306a36Sopenharmony_ci 32862306a36Sopenharmony_ci rtl8225_write(dev, 0x0, 0x067); 32962306a36Sopenharmony_ci rtl8225_write(dev, 0x1, 0xFE0); 33062306a36Sopenharmony_ci rtl8225_write(dev, 0x2, 0x44D); 33162306a36Sopenharmony_ci rtl8225_write(dev, 0x3, 0x441); 33262306a36Sopenharmony_ci rtl8225_write(dev, 0x4, 0x8BE); 33362306a36Sopenharmony_ci rtl8225_write(dev, 0x5, 0xBF0); /* TODO: minipci */ 33462306a36Sopenharmony_ci rtl8225_write(dev, 0x6, 0xAE6); 33562306a36Sopenharmony_ci rtl8225_write(dev, 0x7, rtl8225_chan[0]); 33662306a36Sopenharmony_ci rtl8225_write(dev, 0x8, 0x01F); 33762306a36Sopenharmony_ci rtl8225_write(dev, 0x9, 0x334); 33862306a36Sopenharmony_ci rtl8225_write(dev, 0xA, 0xFD4); 33962306a36Sopenharmony_ci rtl8225_write(dev, 0xB, 0x391); 34062306a36Sopenharmony_ci rtl8225_write(dev, 0xC, 0x050); 34162306a36Sopenharmony_ci rtl8225_write(dev, 0xD, 0x6DB); 34262306a36Sopenharmony_ci rtl8225_write(dev, 0xE, 0x029); 34362306a36Sopenharmony_ci rtl8225_write(dev, 0xF, 0x914); msleep(1); 34462306a36Sopenharmony_ci 34562306a36Sopenharmony_ci rtl8225_write(dev, 0x2, 0xC4D); msleep(100); 34662306a36Sopenharmony_ci 34762306a36Sopenharmony_ci rtl8225_write(dev, 0x0, 0x127); 34862306a36Sopenharmony_ci 34962306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(rtl8225bcd_rxgain); i++) { 35062306a36Sopenharmony_ci rtl8225_write(dev, 0x1, i + 1); 35162306a36Sopenharmony_ci rtl8225_write(dev, 0x2, rtl8225bcd_rxgain[i]); 35262306a36Sopenharmony_ci } 35362306a36Sopenharmony_ci 35462306a36Sopenharmony_ci rtl8225_write(dev, 0x0, 0x027); 35562306a36Sopenharmony_ci rtl8225_write(dev, 0x0, 0x22F); 35662306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF); 35762306a36Sopenharmony_ci 35862306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(rtl8225_agc); i++) { 35962306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0xB, rtl8225_agc[i]); 36062306a36Sopenharmony_ci msleep(1); 36162306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0xA, 0x80 + i); 36262306a36Sopenharmony_ci msleep(1); 36362306a36Sopenharmony_ci } 36462306a36Sopenharmony_ci 36562306a36Sopenharmony_ci msleep(1); 36662306a36Sopenharmony_ci 36762306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x00, 0x01); msleep(1); 36862306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x01, 0x02); msleep(1); 36962306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x02, 0x62); msleep(1); 37062306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x03, 0x00); msleep(1); 37162306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x04, 0x00); msleep(1); 37262306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x05, 0x00); msleep(1); 37362306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x06, 0x00); msleep(1); 37462306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x07, 0x00); msleep(1); 37562306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x08, 0x00); msleep(1); 37662306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x09, 0xfe); msleep(1); 37762306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x0a, 0x09); msleep(1); 37862306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x0b, 0x80); msleep(1); 37962306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x0c, 0x01); msleep(1); 38062306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x0e, 0xd3); msleep(1); 38162306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x0f, 0x38); msleep(1); 38262306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x10, 0x84); msleep(1); 38362306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x11, 0x03); msleep(1); 38462306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x12, 0x20); msleep(1); 38562306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x13, 0x20); msleep(1); 38662306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x14, 0x00); msleep(1); 38762306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x15, 0x40); msleep(1); 38862306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x16, 0x00); msleep(1); 38962306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x17, 0x40); msleep(1); 39062306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x18, 0xef); msleep(1); 39162306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x19, 0x19); msleep(1); 39262306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x1a, 0x20); msleep(1); 39362306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x1b, 0x76); msleep(1); 39462306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x1c, 0x04); msleep(1); 39562306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x1e, 0x95); msleep(1); 39662306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x1f, 0x75); msleep(1); 39762306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x20, 0x1f); msleep(1); 39862306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x21, 0x27); msleep(1); 39962306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x22, 0x16); msleep(1); 40062306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x24, 0x46); msleep(1); 40162306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x25, 0x20); msleep(1); 40262306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x26, 0x90); msleep(1); 40362306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x27, 0x88); msleep(1); 40462306a36Sopenharmony_ci 40562306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x00, 0x98); msleep(1); 40662306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x03, 0x20); msleep(1); 40762306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x04, 0x7e); msleep(1); 40862306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x05, 0x12); msleep(1); 40962306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x06, 0xfc); msleep(1); 41062306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x07, 0x78); msleep(1); 41162306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x08, 0x2e); msleep(1); 41262306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x10, 0x93); msleep(1); 41362306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x11, 0x88); msleep(1); 41462306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x12, 0x47); msleep(1); 41562306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x13, 0xd0); 41662306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x19, 0x00); 41762306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x1a, 0xa0); 41862306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x1b, 0x08); 41962306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x40, 0x86); 42062306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x41, 0x8d); msleep(1); 42162306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x42, 0x15); msleep(1); 42262306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x43, 0x18); msleep(1); 42362306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x44, 0x1f); msleep(1); 42462306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x45, 0x1e); msleep(1); 42562306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x46, 0x1a); msleep(1); 42662306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x47, 0x15); msleep(1); 42762306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x48, 0x10); msleep(1); 42862306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x49, 0x0a); msleep(1); 42962306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x4a, 0x05); msleep(1); 43062306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x4b, 0x02); msleep(1); 43162306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x4c, 0x05); msleep(1); 43262306a36Sopenharmony_ci 43362306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->TESTR, 0x0D); msleep(1); 43462306a36Sopenharmony_ci 43562306a36Sopenharmony_ci rtl8225_rf_set_tx_power(dev, 1); 43662306a36Sopenharmony_ci 43762306a36Sopenharmony_ci /* RX antenna default to A */ 43862306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x10, 0x9b); msleep(1); /* B: 0xDB */ 43962306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x26, 0x90); msleep(1); /* B: 0x10 */ 44062306a36Sopenharmony_ci 44162306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->TX_ANTENNA, 0x03); /* B: 0x00 */ 44262306a36Sopenharmony_ci msleep(1); 44362306a36Sopenharmony_ci rtl818x_iowrite32(priv, (__le32 __iomem *)((void __iomem *)priv->map + 0x94), 0x15c00002); 44462306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF); 44562306a36Sopenharmony_ci 44662306a36Sopenharmony_ci rtl8225_write(dev, 0x0c, 0x50); 44762306a36Sopenharmony_ci /* set OFDM initial gain */ 44862306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x0d, rtl8225_gain[4 * 4]); 44962306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x23, rtl8225_gain[4 * 4 + 1]); 45062306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x1b, rtl8225_gain[4 * 4 + 2]); 45162306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x1d, rtl8225_gain[4 * 4 + 3]); 45262306a36Sopenharmony_ci /* set CCK threshold */ 45362306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x41, rtl8225_threshold[0]); 45462306a36Sopenharmony_ci} 45562306a36Sopenharmony_ci 45662306a36Sopenharmony_cistatic const u8 rtl8225z2_tx_power_cck_ch14[] = { 45762306a36Sopenharmony_ci 0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00 45862306a36Sopenharmony_ci}; 45962306a36Sopenharmony_ci 46062306a36Sopenharmony_cistatic const u8 rtl8225z2_tx_power_cck_B[] = { 46162306a36Sopenharmony_ci 0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x04 46262306a36Sopenharmony_ci}; 46362306a36Sopenharmony_ci 46462306a36Sopenharmony_cistatic const u8 rtl8225z2_tx_power_cck_A[] = { 46562306a36Sopenharmony_ci 0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04 46662306a36Sopenharmony_ci}; 46762306a36Sopenharmony_ci 46862306a36Sopenharmony_cistatic const u8 rtl8225z2_tx_power_cck[] = { 46962306a36Sopenharmony_ci 0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04 47062306a36Sopenharmony_ci}; 47162306a36Sopenharmony_ci 47262306a36Sopenharmony_cistatic void rtl8225z2_rf_set_tx_power(struct ieee80211_hw *dev, int channel) 47362306a36Sopenharmony_ci{ 47462306a36Sopenharmony_ci struct rtl8180_priv *priv = dev->priv; 47562306a36Sopenharmony_ci u8 cck_power, ofdm_power; 47662306a36Sopenharmony_ci const u8 *tmp; 47762306a36Sopenharmony_ci int i; 47862306a36Sopenharmony_ci 47962306a36Sopenharmony_ci cck_power = priv->channels[channel - 1].hw_value & 0xFF; 48062306a36Sopenharmony_ci ofdm_power = priv->channels[channel - 1].hw_value >> 8; 48162306a36Sopenharmony_ci 48262306a36Sopenharmony_ci if (channel == 14) 48362306a36Sopenharmony_ci tmp = rtl8225z2_tx_power_cck_ch14; 48462306a36Sopenharmony_ci else if (cck_power == 12) 48562306a36Sopenharmony_ci tmp = rtl8225z2_tx_power_cck_B; 48662306a36Sopenharmony_ci else if (cck_power == 13) 48762306a36Sopenharmony_ci tmp = rtl8225z2_tx_power_cck_A; 48862306a36Sopenharmony_ci else 48962306a36Sopenharmony_ci tmp = rtl8225z2_tx_power_cck; 49062306a36Sopenharmony_ci 49162306a36Sopenharmony_ci for (i = 0; i < 8; i++) 49262306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x44 + i, *tmp++); 49362306a36Sopenharmony_ci 49462306a36Sopenharmony_ci cck_power = min(cck_power, (u8)35); 49562306a36Sopenharmony_ci if (cck_power == 13 || cck_power == 14) 49662306a36Sopenharmony_ci cck_power = 12; 49762306a36Sopenharmony_ci if (cck_power >= 15) 49862306a36Sopenharmony_ci cck_power -= 2; 49962306a36Sopenharmony_ci 50062306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->TX_GAIN_CCK, cck_power); 50162306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->TX_GAIN_CCK); 50262306a36Sopenharmony_ci msleep(1); 50362306a36Sopenharmony_ci 50462306a36Sopenharmony_ci ofdm_power = min(ofdm_power, (u8)35); 50562306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->TX_GAIN_OFDM, ofdm_power); 50662306a36Sopenharmony_ci 50762306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 2, 0x62); 50862306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 5, 0x00); 50962306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 6, 0x40); 51062306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 7, 0x00); 51162306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 8, 0x40); 51262306a36Sopenharmony_ci 51362306a36Sopenharmony_ci msleep(1); 51462306a36Sopenharmony_ci} 51562306a36Sopenharmony_ci 51662306a36Sopenharmony_cistatic const u16 rtl8225z2_rxgain[] = { 51762306a36Sopenharmony_ci 0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0008, 0x0009, 51862306a36Sopenharmony_ci 0x000a, 0x000b, 0x0102, 0x0103, 0x0104, 0x0105, 0x0140, 0x0141, 51962306a36Sopenharmony_ci 0x0142, 0x0143, 0x0144, 0x0145, 0x0180, 0x0181, 0x0182, 0x0183, 52062306a36Sopenharmony_ci 0x0184, 0x0185, 0x0188, 0x0189, 0x018a, 0x018b, 0x0243, 0x0244, 52162306a36Sopenharmony_ci 0x0245, 0x0280, 0x0281, 0x0282, 0x0283, 0x0284, 0x0285, 0x0288, 52262306a36Sopenharmony_ci 0x0289, 0x028a, 0x028b, 0x028c, 0x0342, 0x0343, 0x0344, 0x0345, 52362306a36Sopenharmony_ci 0x0380, 0x0381, 0x0382, 0x0383, 0x0384, 0x0385, 0x0388, 0x0389, 52462306a36Sopenharmony_ci 0x038a, 0x038b, 0x038c, 0x038d, 0x0390, 0x0391, 0x0392, 0x0393, 52562306a36Sopenharmony_ci 0x0394, 0x0395, 0x0398, 0x0399, 0x039a, 0x039b, 0x039c, 0x039d, 52662306a36Sopenharmony_ci 0x03a0, 0x03a1, 0x03a2, 0x03a3, 0x03a4, 0x03a5, 0x03a8, 0x03a9, 52762306a36Sopenharmony_ci 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03b0, 0x03b1, 0x03b2, 0x03b3, 52862306a36Sopenharmony_ci 0x03b4, 0x03b5, 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bb 52962306a36Sopenharmony_ci}; 53062306a36Sopenharmony_ci 53162306a36Sopenharmony_cistatic void rtl8225z2_rf_init(struct ieee80211_hw *dev) 53262306a36Sopenharmony_ci{ 53362306a36Sopenharmony_ci struct rtl8180_priv *priv = dev->priv; 53462306a36Sopenharmony_ci int i; 53562306a36Sopenharmony_ci 53662306a36Sopenharmony_ci rtl8180_set_anaparam(priv, RTL8225_ANAPARAM_ON); 53762306a36Sopenharmony_ci 53862306a36Sopenharmony_ci /* host_pci_init */ 53962306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 0x0480); 54062306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF); 54162306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, 0x0488); 54262306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, 0); 54362306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 54462306a36Sopenharmony_ci msleep(200); /* FIXME: ehh?? */ 54562306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->GP_ENABLE, 0xFF & ~(1 << 6)); 54662306a36Sopenharmony_ci 54762306a36Sopenharmony_ci rtl818x_iowrite32(priv, &priv->map->RF_TIMING, 0x00088008); 54862306a36Sopenharmony_ci 54962306a36Sopenharmony_ci /* TODO: check if we need really to change BRSR to do RF config */ 55062306a36Sopenharmony_ci rtl818x_ioread16(priv, &priv->map->BRSR); 55162306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->BRSR, 0xFFFF); 55262306a36Sopenharmony_ci rtl818x_iowrite32(priv, &priv->map->RF_PARA, 0x00100044); 55362306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG); 55462306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->CONFIG3, 0x44); 55562306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL); 55662306a36Sopenharmony_ci 55762306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF); 55862306a36Sopenharmony_ci 55962306a36Sopenharmony_ci rtl8225_write(dev, 0x0, 0x0B7); msleep(1); 56062306a36Sopenharmony_ci rtl8225_write(dev, 0x1, 0xEE0); msleep(1); 56162306a36Sopenharmony_ci rtl8225_write(dev, 0x2, 0x44D); msleep(1); 56262306a36Sopenharmony_ci rtl8225_write(dev, 0x3, 0x441); msleep(1); 56362306a36Sopenharmony_ci rtl8225_write(dev, 0x4, 0x8C3); msleep(1); 56462306a36Sopenharmony_ci rtl8225_write(dev, 0x5, 0xC72); msleep(1); 56562306a36Sopenharmony_ci rtl8225_write(dev, 0x6, 0x0E6); msleep(1); 56662306a36Sopenharmony_ci rtl8225_write(dev, 0x7, 0x82A); msleep(1); 56762306a36Sopenharmony_ci rtl8225_write(dev, 0x8, 0x03F); msleep(1); 56862306a36Sopenharmony_ci rtl8225_write(dev, 0x9, 0x335); msleep(1); 56962306a36Sopenharmony_ci rtl8225_write(dev, 0xa, 0x9D4); msleep(1); 57062306a36Sopenharmony_ci rtl8225_write(dev, 0xb, 0x7BB); msleep(1); 57162306a36Sopenharmony_ci rtl8225_write(dev, 0xc, 0x850); msleep(1); 57262306a36Sopenharmony_ci rtl8225_write(dev, 0xd, 0xCDF); msleep(1); 57362306a36Sopenharmony_ci rtl8225_write(dev, 0xe, 0x02B); msleep(1); 57462306a36Sopenharmony_ci rtl8225_write(dev, 0xf, 0x114); msleep(100); 57562306a36Sopenharmony_ci 57662306a36Sopenharmony_ci if (!(rtl8225_read(dev, 6) & (1 << 7))) { 57762306a36Sopenharmony_ci rtl8225_write(dev, 0x02, 0x0C4D); 57862306a36Sopenharmony_ci msleep(200); 57962306a36Sopenharmony_ci rtl8225_write(dev, 0x02, 0x044D); 58062306a36Sopenharmony_ci msleep(100); 58162306a36Sopenharmony_ci /* TODO: readd calibration failure message when the calibration 58262306a36Sopenharmony_ci check works */ 58362306a36Sopenharmony_ci } 58462306a36Sopenharmony_ci 58562306a36Sopenharmony_ci rtl8225_write(dev, 0x0, 0x1B7); 58662306a36Sopenharmony_ci rtl8225_write(dev, 0x3, 0x002); 58762306a36Sopenharmony_ci rtl8225_write(dev, 0x5, 0x004); 58862306a36Sopenharmony_ci 58962306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(rtl8225z2_rxgain); i++) { 59062306a36Sopenharmony_ci rtl8225_write(dev, 0x1, i + 1); 59162306a36Sopenharmony_ci rtl8225_write(dev, 0x2, rtl8225z2_rxgain[i]); 59262306a36Sopenharmony_ci } 59362306a36Sopenharmony_ci 59462306a36Sopenharmony_ci rtl8225_write(dev, 0x0, 0x0B7); msleep(100); 59562306a36Sopenharmony_ci rtl8225_write(dev, 0x2, 0xC4D); 59662306a36Sopenharmony_ci 59762306a36Sopenharmony_ci msleep(200); 59862306a36Sopenharmony_ci rtl8225_write(dev, 0x2, 0x44D); 59962306a36Sopenharmony_ci msleep(100); 60062306a36Sopenharmony_ci 60162306a36Sopenharmony_ci rtl8225_write(dev, 0x00, 0x2BF); 60262306a36Sopenharmony_ci rtl8225_write(dev, 0xFF, 0xFFFF); 60362306a36Sopenharmony_ci 60462306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF); 60562306a36Sopenharmony_ci 60662306a36Sopenharmony_ci for (i = 0; i < ARRAY_SIZE(rtl8225_agc); i++) { 60762306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0xB, rtl8225_agc[i]); 60862306a36Sopenharmony_ci msleep(1); 60962306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0xA, 0x80 + i); 61062306a36Sopenharmony_ci msleep(1); 61162306a36Sopenharmony_ci } 61262306a36Sopenharmony_ci 61362306a36Sopenharmony_ci msleep(1); 61462306a36Sopenharmony_ci 61562306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x00, 0x01); msleep(1); 61662306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x01, 0x02); msleep(1); 61762306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x02, 0x62); msleep(1); 61862306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x03, 0x00); msleep(1); 61962306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x04, 0x00); msleep(1); 62062306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x05, 0x00); msleep(1); 62162306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x06, 0x40); msleep(1); 62262306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x07, 0x00); msleep(1); 62362306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x08, 0x40); msleep(1); 62462306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x09, 0xfe); msleep(1); 62562306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x0a, 0x09); msleep(1); 62662306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x18, 0xef); msleep(1); 62762306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x0b, 0x80); msleep(1); 62862306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x0c, 0x01); msleep(1); 62962306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x0d, 0x43); 63062306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x0e, 0xd3); msleep(1); 63162306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x0f, 0x38); msleep(1); 63262306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x10, 0x84); msleep(1); 63362306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x11, 0x06); msleep(1); 63462306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x12, 0x20); msleep(1); 63562306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x13, 0x20); msleep(1); 63662306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x14, 0x00); msleep(1); 63762306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x15, 0x40); msleep(1); 63862306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x16, 0x00); msleep(1); 63962306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x17, 0x40); msleep(1); 64062306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x18, 0xef); msleep(1); 64162306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x19, 0x19); msleep(1); 64262306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x1a, 0x20); msleep(1); 64362306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x1b, 0x11); msleep(1); 64462306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x1c, 0x04); msleep(1); 64562306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x1d, 0xc5); msleep(1); 64662306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x1e, 0xb3); msleep(1); 64762306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x1f, 0x75); msleep(1); 64862306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x20, 0x1f); msleep(1); 64962306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x21, 0x27); msleep(1); 65062306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x22, 0x16); msleep(1); 65162306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x23, 0x80); msleep(1); /* FIXME: not needed? */ 65262306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x24, 0x46); msleep(1); 65362306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x25, 0x20); msleep(1); 65462306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x26, 0x90); msleep(1); 65562306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x27, 0x88); msleep(1); 65662306a36Sopenharmony_ci 65762306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x00, 0x98); msleep(1); 65862306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x03, 0x20); msleep(1); 65962306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x04, 0x7e); msleep(1); 66062306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x05, 0x12); msleep(1); 66162306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x06, 0xfc); msleep(1); 66262306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x07, 0x78); msleep(1); 66362306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x08, 0x2e); msleep(1); 66462306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x10, 0x93); msleep(1); 66562306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x11, 0x88); msleep(1); 66662306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x12, 0x47); msleep(1); 66762306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x13, 0xd0); 66862306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x19, 0x00); 66962306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x1a, 0xa0); 67062306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x1b, 0x08); 67162306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x40, 0x86); 67262306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x41, 0x8a); msleep(1); 67362306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x42, 0x15); msleep(1); 67462306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x43, 0x18); msleep(1); 67562306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x44, 0x36); msleep(1); 67662306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x45, 0x35); msleep(1); 67762306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x46, 0x2e); msleep(1); 67862306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x47, 0x25); msleep(1); 67962306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x48, 0x1c); msleep(1); 68062306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x49, 0x12); msleep(1); 68162306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x4a, 0x09); msleep(1); 68262306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x4b, 0x04); msleep(1); 68362306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x4c, 0x05); msleep(1); 68462306a36Sopenharmony_ci 68562306a36Sopenharmony_ci rtl818x_iowrite8(priv, (u8 __iomem *)((void __iomem *)priv->map + 0x5B), 0x0D); msleep(1); 68662306a36Sopenharmony_ci 68762306a36Sopenharmony_ci rtl8225z2_rf_set_tx_power(dev, 1); 68862306a36Sopenharmony_ci 68962306a36Sopenharmony_ci /* RX antenna default to A */ 69062306a36Sopenharmony_ci rtl8225_write_phy_cck(dev, 0x10, 0x9b); msleep(1); /* B: 0xDB */ 69162306a36Sopenharmony_ci rtl8225_write_phy_ofdm(dev, 0x26, 0x90); msleep(1); /* B: 0x10 */ 69262306a36Sopenharmony_ci 69362306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->TX_ANTENNA, 0x03); /* B: 0x00 */ 69462306a36Sopenharmony_ci msleep(1); 69562306a36Sopenharmony_ci rtl818x_iowrite32(priv, (__le32 __iomem *)((void __iomem *)priv->map + 0x94), 0x15c00002); 69662306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF); 69762306a36Sopenharmony_ci} 69862306a36Sopenharmony_ci 69962306a36Sopenharmony_cistatic void rtl8225_rf_stop(struct ieee80211_hw *dev) 70062306a36Sopenharmony_ci{ 70162306a36Sopenharmony_ci struct rtl8180_priv *priv = dev->priv; 70262306a36Sopenharmony_ci u8 reg; 70362306a36Sopenharmony_ci 70462306a36Sopenharmony_ci rtl8225_write(dev, 0x4, 0x1f); msleep(1); 70562306a36Sopenharmony_ci 70662306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_CONFIG); 70762306a36Sopenharmony_ci reg = rtl818x_ioread8(priv, &priv->map->CONFIG3); 70862306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg | RTL818X_CONFIG3_ANAPARAM_WRITE); 70962306a36Sopenharmony_ci rtl818x_iowrite32(priv, &priv->map->ANAPARAM2, RTL8225_ANAPARAM2_OFF); 71062306a36Sopenharmony_ci rtl818x_iowrite32(priv, &priv->map->ANAPARAM, RTL8225_ANAPARAM_OFF); 71162306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->CONFIG3, reg & ~RTL818X_CONFIG3_ANAPARAM_WRITE); 71262306a36Sopenharmony_ci rtl818x_iowrite8(priv, &priv->map->EEPROM_CMD, RTL818X_EEPROM_CMD_NORMAL); 71362306a36Sopenharmony_ci} 71462306a36Sopenharmony_ci 71562306a36Sopenharmony_cistatic void rtl8225_rf_set_channel(struct ieee80211_hw *dev, 71662306a36Sopenharmony_ci struct ieee80211_conf *conf) 71762306a36Sopenharmony_ci{ 71862306a36Sopenharmony_ci struct rtl8180_priv *priv = dev->priv; 71962306a36Sopenharmony_ci int chan = 72062306a36Sopenharmony_ci ieee80211_frequency_to_channel(conf->chandef.chan->center_freq); 72162306a36Sopenharmony_ci 72262306a36Sopenharmony_ci if (priv->rf->init == rtl8225_rf_init) 72362306a36Sopenharmony_ci rtl8225_rf_set_tx_power(dev, chan); 72462306a36Sopenharmony_ci else 72562306a36Sopenharmony_ci rtl8225z2_rf_set_tx_power(dev, chan); 72662306a36Sopenharmony_ci 72762306a36Sopenharmony_ci rtl8225_write(dev, 0x7, rtl8225_chan[chan - 1]); 72862306a36Sopenharmony_ci msleep(10); 72962306a36Sopenharmony_ci} 73062306a36Sopenharmony_ci 73162306a36Sopenharmony_cistatic const struct rtl818x_rf_ops rtl8225_ops = { 73262306a36Sopenharmony_ci .name = "rtl8225", 73362306a36Sopenharmony_ci .init = rtl8225_rf_init, 73462306a36Sopenharmony_ci .stop = rtl8225_rf_stop, 73562306a36Sopenharmony_ci .set_chan = rtl8225_rf_set_channel, 73662306a36Sopenharmony_ci}; 73762306a36Sopenharmony_ci 73862306a36Sopenharmony_cistatic const struct rtl818x_rf_ops rtl8225z2_ops = { 73962306a36Sopenharmony_ci .name = "rtl8225z2", 74062306a36Sopenharmony_ci .init = rtl8225z2_rf_init, 74162306a36Sopenharmony_ci .stop = rtl8225_rf_stop, 74262306a36Sopenharmony_ci .set_chan = rtl8225_rf_set_channel, 74362306a36Sopenharmony_ci}; 74462306a36Sopenharmony_ci 74562306a36Sopenharmony_ciconst struct rtl818x_rf_ops * rtl8180_detect_rf(struct ieee80211_hw *dev) 74662306a36Sopenharmony_ci{ 74762306a36Sopenharmony_ci struct rtl8180_priv *priv = dev->priv; 74862306a36Sopenharmony_ci u16 reg8, reg9; 74962306a36Sopenharmony_ci 75062306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsOutput, 0x0480); 75162306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsSelect, 0x0488); 75262306a36Sopenharmony_ci rtl818x_iowrite16(priv, &priv->map->RFPinsEnable, 0x1FFF); 75362306a36Sopenharmony_ci rtl818x_ioread8(priv, &priv->map->EEPROM_CMD); 75462306a36Sopenharmony_ci msleep(100); 75562306a36Sopenharmony_ci 75662306a36Sopenharmony_ci rtl8225_write(dev, 0, 0x1B7); 75762306a36Sopenharmony_ci 75862306a36Sopenharmony_ci reg8 = rtl8225_read(dev, 8); 75962306a36Sopenharmony_ci reg9 = rtl8225_read(dev, 9); 76062306a36Sopenharmony_ci 76162306a36Sopenharmony_ci rtl8225_write(dev, 0, 0x0B7); 76262306a36Sopenharmony_ci 76362306a36Sopenharmony_ci if (reg8 != 0x588 || reg9 != 0x700) 76462306a36Sopenharmony_ci return &rtl8225_ops; 76562306a36Sopenharmony_ci 76662306a36Sopenharmony_ci return &rtl8225z2_ops; 76762306a36Sopenharmony_ci} 768