From patchwork Thu Sep 20 09:11:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607233 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5B3C21508 for ; Thu, 20 Sep 2018 09:27:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4945C2CC06 for ; Thu, 20 Sep 2018 09:27:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B9B52CDC1; Thu, 20 Sep 2018 09:27:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2248B2CDB7 for ; Thu, 20 Sep 2018 09:27:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=BcZoiFElU3MX2BwZpS6fas7wzkU4JL4ZgPO6KOWLT8g=; b=uVwfELkhUO63c6K9eQzk+Pv7Qg bgt0oWMD1Shlb45caVL1fDKWWHwtFwN7YD1uZ62fyFoKJq3kWTAYYceOqRqm8imllsaGyNrKAR7AM ewJ9EVqhwcBZidM5CSjHXybpmV/iZpBFtf19B9B9/pAoWFQ66Xs9H/a1vbEaVbFkihvGwNMJiTlXH mcYucyi+lWAERYKPEzqNUnLMp0s551i8XIz78O5+2RUNxLrwxGx9ybTW5q/TadQ3qx/8tDQwo5Hc5 RB6FdOdMqu2sBxEBXmWCyVqr+ibNq0jqxUDWmwMI2xNT+l6LqbRvDQBYJXw2XmxEN+yUqGFgBhQx1 h+F4Glwg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2vFX-0000I2-Ge; Thu, 20 Sep 2018 09:27:51 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2vE6-0007yC-Qb for linux-mediatek@bombadil.infradead.org; Thu, 20 Sep 2018 09:26:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=CHgh41U0YR4iIGUE1ZR/icGAqik8AGeV0Dg4TCU/Qu4=; b=N0eOI1YuJwlzPqoCwt5/YqDDJ w7I5CrcA9u82U1QYrsnPDNyvLy9il8D50xSrlMPQH0kPNjtEkxFCvV+lePPbN/p2hGmL6oYG5UtRi HLbJNeNDihvo8/uqATTsNg+qQ3xH+XC3STmq8naDochtZ4YqxSF5PS+o6FblKDjG1zGLMsVwoNiUk zdFeHTrPiqumW7fjVftdWw6UgziXANJiC2ip8/DxGuuQl2WWlNGcwY1CCfJK+nprsjG5trX8aXPm0 KHkQ4MmA+41KIF4z4RjWY1ubg1CuGz4q//Gx8T3FrTPVoXprtEPftv3Bpi0IWZmlHbhFokCbdxTIG vrfrBHGHQ==; Received: from mail-wm1-f67.google.com ([209.85.128.67]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2v0x-0000WG-Qw for linux-mediatek@lists.infradead.org; Thu, 20 Sep 2018 09:12:49 +0000 Received: by mail-wm1-f67.google.com with SMTP id c14-v6so9123722wmb.4 for ; Thu, 20 Sep 2018 02:12:37 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=CHgh41U0YR4iIGUE1ZR/icGAqik8AGeV0Dg4TCU/Qu4=; b=V8VGKVL6YZLVrg+5MdTT4d2x9wcIDsh5Pe8y5Ehh5V3Ij/DEJ0CzIvEXGzxaFAUN20 B7tKZkxBCuLKetSWPNevq/aWfJj2gkK7YpBtO27wJiVEsQyxUnqgBThaIJY1iHmvYLkN WFOKtQN1eaHrNTQH1rfIoZUqPhJBQfEXFZg0hIjOsekYbvErdJ7aPMV0H0eFpkHug0qQ avvAIwbMSyepor6w+36WKMbJrVyUvE0OtBrdBZSTHqC4SAWkQmeSxV2XcYNxLqJ2c8cm wUOwRtUHzm7jDHc7oJKY4RBKKeQ1IKgSxOF/CYY7UQJy35iZgTbXXCigUES2MTkO8PD7 lWog== X-Gm-Message-State: APzg51Dj7mA/6BBKOykc+Yjme8sIQzvKBAZUTsa0dP71hJ7UL5yeSUdZ KJ2AX8oU37YfYYvGSgZLoxOcNw== X-Google-Smtp-Source: ANB0VdYHtQaOiUFH/IjKox/ca3xI5BL7YSEZDKTikuR9glih1ebNrVdd2nVpiFzy12Rxzu5f9kBkOg== X-Received: by 2002:a1c:f913:: with SMTP id x19-v6mr1695881wmh.63.1537434755789; Thu, 20 Sep 2018 02:12:35 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id 34-v6sm35501691wra.20.2018.09.20.02.12.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:35 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Subject: [PATCH 11/20] mt76x0: unify lna_gain parsing Date: Thu, 20 Sep 2018 11:11:58 +0200 Message-Id: <697986870ee86c266689c8387b20803255bd5d5d.1537433365.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180920_051247_944889_215041A3 X-CRM114-Status: GOOD ( 14.68 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sgruszka@redhat.com, linux-mediatek@lists.infradead.org, linux-wireless@vger.kernel.org MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Unify lna gain parsing with mt76x2 driver using eeprom utility routines available in mt76x02-lib module Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/debugfs.c | 5 +--- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 26 +++++++------------ .../wireless/mediatek/mt76/mt76x0/eeprom.h | 7 +++-- .../wireless/mediatek/mt76/mt76x0/mt76x0.h | 2 ++ .../net/wireless/mediatek/mt76/mt76x0/phy.c | 24 +++++------------ 5 files changed, 24 insertions(+), 40 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index 932c0e41196c..566ed0b61035 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -109,10 +109,7 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data) dev->ee->rssi_offset_5ghz[0], dev->ee->rssi_offset_5ghz[1], dev->ee->rssi_offset_5ghz[2]); seq_printf(file, "Temperature offset: %hhx\n", dev->ee->temp_off); - seq_printf(file, "LNA gain 2Ghz: %hhx\n", dev->ee->lna_gain_2ghz); - seq_printf(file, "LNA gain 5Ghz: %hhx %hhx %hhx\n", - dev->ee->lna_gain_5ghz[0], dev->ee->lna_gain_5ghz[1], - dev->ee->lna_gain_5ghz[2]); + seq_printf(file, "LNA gain: %x\n", dev->caldata.lna_gain); val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0); seq_printf(file, "Power Amplifier type %lx\n", diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index 5d08a7bb16ce..20a9f8fb20da 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -122,25 +122,18 @@ mt76x0_set_rf_freq_off(struct mt76x0_dev *dev, u8 *eeprom) dev->ee->rf_freq_off += comp; } -static void -mt76x0_set_lna_gain(struct mt76x0_dev *dev, u8 *eeprom) +void mt76x0_read_rx_gain(struct mt76x0_dev *dev) { - u8 gain; - - dev->ee->lna_gain_2ghz = eeprom[MT_EE_LNA_GAIN]; - dev->ee->lna_gain_5ghz[0] = eeprom[MT_EE_LNA_GAIN + 1]; + struct ieee80211_channel *chan = dev->mt76.chandef.chan; + struct mt76x0_caldata *caldata = &dev->caldata; + s8 lna_5g[3], lna_2g; + u16 rssi_offset; - gain = eeprom[MT_EE_LNA_GAIN_5GHZ_1]; - if (gain == 0xff || gain == 0) - dev->ee->lna_gain_5ghz[1] = dev->ee->lna_gain_5ghz[0]; - else - dev->ee->lna_gain_5ghz[1] = gain; + mt76x02_get_rx_gain(&dev->mt76, chan->band, &rssi_offset, + &lna_2g, lna_5g); + caldata->lna_gain = mt76x02_get_lna_gain(&dev->mt76, &lna_2g, + lna_5g, chan); - gain = eeprom[MT_EE_LNA_GAIN_5GHZ_2]; - if (gain == 0xff || gain == 0) - dev->ee->lna_gain_5ghz[2] = dev->ee->lna_gain_5ghz[0]; - else - dev->ee->lna_gain_5ghz[2] = gain; } static void @@ -318,7 +311,6 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) mt76x0_set_chip_cap(dev, eeprom); mt76x0_set_rf_freq_off(dev, eeprom); mt76x0_set_temp_offset(dev, eeprom); - mt76x0_set_lna_gain(dev, eeprom); mt76x0_set_rssi_offset(dev, eeprom); dev->chainmask = 0x0101; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index dbfcbfa71291..e62c61d91505 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -28,13 +28,15 @@ struct reg_channel_bounds { u8 num; }; +struct mt76x0_caldata { + s8 lna_gain; +}; + struct mt76x0_eeprom_params { u8 rf_freq_off; s16 temp_off; s8 rssi_offset_2ghz[2]; s8 rssi_offset_5ghz[3]; - s8 lna_gain_2ghz; - s8 lna_gain_5ghz[3]; /* TX_PWR_CFG_* values from EEPROM for 20 and 40 Mhz bandwidths. */ u32 tx_pwr_cfg_2g[5][2]; @@ -44,6 +46,7 @@ struct mt76x0_eeprom_params { }; int mt76x0_eeprom_init(struct mt76x0_dev *dev); +void mt76x0_read_rx_gain(struct mt76x0_dev *dev); static inline u32 s6_validate(u32 reg) { diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h index 6aaa9a5b51db..99d48fa96fd9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h @@ -28,6 +28,7 @@ #include "../mt76.h" #include "../mt76x02_regs.h" #include "../mt76x02_mac.h" +#include "eeprom.h" #define MT_CALIBRATE_INTERVAL (4 * HZ) @@ -89,6 +90,7 @@ struct mt76x0_dev { const u16 *beacon_offsets; struct mt76x0_eeprom_params *ee; + struct mt76x0_caldata caldata; struct mutex reg_atomic_mutex; struct mutex hw_atomic_mutex; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index ba0e68b33ae7..08041ea70a1c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -228,18 +228,17 @@ mt76x0_bbp_set_ctrlch(struct mt76x0_dev *dev, enum nl80211_chan_width width, int mt76x0_phy_get_rssi(struct mt76x0_dev *dev, struct mt76x02_rxwi *rxwi) { - s8 lna_gain, rssi_offset; + struct mt76x0_caldata *caldata = &dev->caldata; + s8 rssi_offset; int val; if (dev->mt76.chandef.chan->band == NL80211_BAND_2GHZ) { - lna_gain = dev->ee->lna_gain_2ghz; rssi_offset = dev->ee->rssi_offset_2ghz[0]; } else { - lna_gain = dev->ee->lna_gain_5ghz[0]; rssi_offset = dev->ee->rssi_offset_5ghz[0]; } - val = rxwi->rssi[0] + rssi_offset - lna_gain; + val = rxwi->rssi[0] + rssi_offset - caldata->lna_gain; return val; } @@ -545,20 +544,10 @@ mt76x0_phy_set_chan_bbp_params(struct mt76x0_dev *dev, u8 channel, u16 rf_bw_ban if (pair->reg == MT_BBP(AGC, 8)) { u32 val = pair->value; - u8 gain = FIELD_GET(MT_BBP_AGC_GAIN, val); - - if (channel > 14) { - if (channel < 100) - gain -= dev->ee->lna_gain_5ghz[0]*2; - else if (channel < 137) - gain -= dev->ee->lna_gain_5ghz[1]*2; - else - gain -= dev->ee->lna_gain_5ghz[2]*2; - - } else { - gain -= dev->ee->lna_gain_2ghz*2; - } + u8 gain; + gain = FIELD_GET(MT_BBP_AGC_GAIN, val); + gain -= dev->caldata.lna_gain * 2; val &= ~MT_BBP_AGC_GAIN; val |= FIELD_PREP(MT_BBP_AGC_GAIN, gain); mt76_wr(dev, pair->reg, val); @@ -737,6 +726,7 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev, mt76x0_phy_set_band(dev, chandef->chan->band); mt76x0_phy_set_chan_rf_params(dev, channel, rf_bw_band); + mt76x0_read_rx_gain(dev); /* set Japan Tx filter at channel 14 */ val = mt76_rr(dev, MT_BBP(CORE, 1));